2019-01-24 23:54:56 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const SerializerMiddleware = require("./SerializerMiddleware");
|
|
|
|
|
2025-03-07 21:12:22 +08:00
|
|
|
/** @typedef {import("./SerializerMiddleware").Context} Context */
|
|
|
|
|
|
|
|
/** @typedef {any} DeserializedType */
|
|
|
|
/** @typedef {any[]} SerializedType */
|
|
|
|
|
2019-01-24 23:54:56 +08:00
|
|
|
/**
|
2025-03-07 21:12:22 +08:00
|
|
|
* @extends {SerializerMiddleware<DeserializedType, SerializedType>}
|
2019-01-24 23:54:56 +08:00
|
|
|
*/
|
|
|
|
class SingleItemMiddleware extends SerializerMiddleware {
|
|
|
|
/**
|
|
|
|
* @param {DeserializedType} data data
|
2025-03-07 21:12:22 +08:00
|
|
|
* @param {Context} context context object
|
|
|
|
* @returns {SerializedType | Promise<SerializedType>} serialized data
|
2019-01-24 23:54:56 +08:00
|
|
|
*/
|
|
|
|
serialize(data, context) {
|
|
|
|
return [data];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {SerializedType} data data
|
2025-03-07 21:12:22 +08:00
|
|
|
* @param {Context} context context object
|
|
|
|
* @returns {DeserializedType | Promise<DeserializedType>} deserialized data
|
2019-01-24 23:54:56 +08:00
|
|
|
*/
|
|
|
|
deserialize(data, context) {
|
|
|
|
return data[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SingleItemMiddleware;
|