You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
806 B

3 months ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. const SerializerMiddleware = require("./SerializerMiddleware");
  6. /**
  7. * @typedef {any} DeserializedType
  8. * @typedef {any[]} SerializedType
  9. * @extends {SerializerMiddleware<any, any[]>}
  10. */
  11. class SingleItemMiddleware extends SerializerMiddleware {
  12. /**
  13. * @param {DeserializedType} data data
  14. * @param {object} context context object
  15. * @returns {SerializedType|Promise<SerializedType>} serialized data
  16. */
  17. serialize(data, context) {
  18. return [data];
  19. }
  20. /**
  21. * @param {SerializedType} data data
  22. * @param {object} context context object
  23. * @returns {DeserializedType|Promise<DeserializedType>} deserialized data
  24. */
  25. deserialize(data, context) {
  26. return data[0];
  27. }
  28. }
  29. module.exports = SingleItemMiddleware;