@tsed/schema 7.0.0-beta.12 → 7.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/jest.config.js +3 -3
  2. package/lib/cjs/components/lazyRefMapper.js +1 -2
  3. package/lib/cjs/components/lazyRefMapper.js.map +1 -1
  4. package/lib/cjs/components/objectMapper.js +1 -1
  5. package/lib/cjs/components/objectMapper.js.map +1 -1
  6. package/lib/cjs/constants/httpStatusMessages.js +2 -4
  7. package/lib/cjs/constants/httpStatusMessages.js.map +1 -1
  8. package/lib/cjs/decorators/collections/collectionOf.js +3 -4
  9. package/lib/cjs/decorators/collections/collectionOf.js.map +1 -1
  10. package/lib/cjs/decorators/common/description.js +1 -2
  11. package/lib/cjs/decorators/common/description.js.map +1 -1
  12. package/lib/cjs/decorators/operations/redirect.js +1 -2
  13. package/lib/cjs/decorators/operations/redirect.js.map +1 -1
  14. package/lib/cjs/decorators/operations/returns.js +20 -20
  15. package/lib/cjs/decorators/operations/returns.js.map +1 -1
  16. package/lib/cjs/decorators/operations/route.js +1 -4
  17. package/lib/cjs/decorators/operations/route.js.map +1 -1
  18. package/lib/cjs/domain/DecoratorContext.js +6 -3
  19. package/lib/cjs/domain/DecoratorContext.js.map +1 -1
  20. package/lib/cjs/domain/JsonClassStore.js +4 -7
  21. package/lib/cjs/domain/JsonClassStore.js.map +1 -1
  22. package/lib/cjs/domain/JsonEntityStore.js +40 -1
  23. package/lib/cjs/domain/JsonEntityStore.js.map +1 -1
  24. package/lib/cjs/domain/JsonLazyRef.js +2 -1
  25. package/lib/cjs/domain/JsonLazyRef.js.map +1 -1
  26. package/lib/cjs/domain/JsonMethodStore.js +12 -12
  27. package/lib/cjs/domain/JsonMethodStore.js.map +1 -1
  28. package/lib/cjs/domain/JsonOperation.js +12 -16
  29. package/lib/cjs/domain/JsonOperation.js.map +1 -1
  30. package/lib/cjs/domain/JsonOperationPathsMap.js +1 -4
  31. package/lib/cjs/domain/JsonOperationPathsMap.js.map +1 -1
  32. package/lib/cjs/domain/JsonOperationRoute.js +8 -6
  33. package/lib/cjs/domain/JsonOperationRoute.js.map +1 -1
  34. package/lib/cjs/domain/JsonParameter.js +4 -4
  35. package/lib/cjs/domain/JsonParameter.js.map +1 -1
  36. package/lib/cjs/domain/JsonParameterStore.js +12 -5
  37. package/lib/cjs/domain/JsonParameterStore.js.map +1 -1
  38. package/lib/cjs/domain/JsonPropertyStore.js +1 -4
  39. package/lib/cjs/domain/JsonPropertyStore.js.map +1 -1
  40. package/lib/cjs/domain/JsonResponse.js +3 -6
  41. package/lib/cjs/domain/JsonResponse.js.map +1 -1
  42. package/lib/cjs/domain/JsonSchema.js +58 -60
  43. package/lib/cjs/domain/JsonSchema.js.map +1 -1
  44. package/lib/cjs/hooks/alterIgnore.js +2 -3
  45. package/lib/cjs/hooks/alterIgnore.js.map +1 -1
  46. package/lib/cjs/hooks/alterRequiredGroups.js +1 -2
  47. package/lib/cjs/hooks/alterRequiredGroups.js.map +1 -1
  48. package/lib/cjs/utils/concatPath.js +16 -1
  49. package/lib/cjs/utils/concatPath.js.map +1 -1
  50. package/lib/cjs/utils/getJsonSchema.js +4 -5
  51. package/lib/cjs/utils/getJsonSchema.js.map +1 -1
  52. package/lib/cjs/utils/getRequiredProperties.js +3 -3
  53. package/lib/cjs/utils/getRequiredProperties.js.map +1 -1
  54. package/lib/cjs/utils/mapNullableType.js +1 -1
  55. package/lib/cjs/utils/mapNullableType.js.map +1 -1
  56. package/lib/cjs/utils/mergeOperation.js +1 -2
  57. package/lib/cjs/utils/mergeOperation.js.map +1 -1
  58. package/lib/cjs/utils/operationIdFormatter.js +3 -3
  59. package/lib/cjs/utils/operationIdFormatter.js.map +1 -1
  60. package/lib/cjs/utils/ref.js +2 -2
  61. package/lib/cjs/utils/ref.js.map +1 -1
  62. package/lib/cjs/utils/transformToOS2.js +2 -2
  63. package/lib/cjs/utils/transformToOS2.js.map +1 -1
  64. package/lib/esm/components/lazyRefMapper.js +1 -2
  65. package/lib/esm/components/lazyRefMapper.js.map +1 -1
  66. package/lib/esm/components/objectMapper.js +1 -1
  67. package/lib/esm/components/objectMapper.js.map +1 -1
  68. package/lib/esm/constants/httpStatusMessages.js +2 -4
  69. package/lib/esm/constants/httpStatusMessages.js.map +1 -1
  70. package/lib/esm/decorators/collections/collectionOf.js +3 -4
  71. package/lib/esm/decorators/collections/collectionOf.js.map +1 -1
  72. package/lib/esm/decorators/common/description.js +1 -2
  73. package/lib/esm/decorators/common/description.js.map +1 -1
  74. package/lib/esm/decorators/operations/redirect.js +1 -2
  75. package/lib/esm/decorators/operations/redirect.js.map +1 -1
  76. package/lib/esm/decorators/operations/returns.js +20 -20
  77. package/lib/esm/decorators/operations/returns.js.map +1 -1
  78. package/lib/esm/decorators/operations/route.js +1 -4
  79. package/lib/esm/decorators/operations/route.js.map +1 -1
  80. package/lib/esm/domain/DecoratorContext.js +5 -2
  81. package/lib/esm/domain/DecoratorContext.js.map +1 -1
  82. package/lib/esm/domain/JsonClassStore.js +4 -7
  83. package/lib/esm/domain/JsonClassStore.js.map +1 -1
  84. package/lib/esm/domain/JsonEntityStore.js +40 -1
  85. package/lib/esm/domain/JsonEntityStore.js.map +1 -1
  86. package/lib/esm/domain/JsonLazyRef.js +2 -1
  87. package/lib/esm/domain/JsonLazyRef.js.map +1 -1
  88. package/lib/esm/domain/JsonMethodStore.js +12 -12
  89. package/lib/esm/domain/JsonMethodStore.js.map +1 -1
  90. package/lib/esm/domain/JsonOperation.js +12 -16
  91. package/lib/esm/domain/JsonOperation.js.map +1 -1
  92. package/lib/esm/domain/JsonOperationPathsMap.js +1 -4
  93. package/lib/esm/domain/JsonOperationPathsMap.js.map +1 -1
  94. package/lib/esm/domain/JsonOperationRoute.js +8 -6
  95. package/lib/esm/domain/JsonOperationRoute.js.map +1 -1
  96. package/lib/esm/domain/JsonParameter.js +4 -4
  97. package/lib/esm/domain/JsonParameter.js.map +1 -1
  98. package/lib/esm/domain/JsonParameterStore.js +12 -5
  99. package/lib/esm/domain/JsonParameterStore.js.map +1 -1
  100. package/lib/esm/domain/JsonPropertyStore.js +1 -4
  101. package/lib/esm/domain/JsonPropertyStore.js.map +1 -1
  102. package/lib/esm/domain/JsonResponse.js +3 -6
  103. package/lib/esm/domain/JsonResponse.js.map +1 -1
  104. package/lib/esm/domain/JsonSchema.js +58 -60
  105. package/lib/esm/domain/JsonSchema.js.map +1 -1
  106. package/lib/esm/hooks/alterIgnore.js +2 -3
  107. package/lib/esm/hooks/alterIgnore.js.map +1 -1
  108. package/lib/esm/hooks/alterRequiredGroups.js +1 -2
  109. package/lib/esm/hooks/alterRequiredGroups.js.map +1 -1
  110. package/lib/esm/utils/concatPath.js +16 -1
  111. package/lib/esm/utils/concatPath.js.map +1 -1
  112. package/lib/esm/utils/getJsonSchema.js +4 -5
  113. package/lib/esm/utils/getJsonSchema.js.map +1 -1
  114. package/lib/esm/utils/getRequiredProperties.js +3 -3
  115. package/lib/esm/utils/getRequiredProperties.js.map +1 -1
  116. package/lib/esm/utils/mapNullableType.js +1 -1
  117. package/lib/esm/utils/mapNullableType.js.map +1 -1
  118. package/lib/esm/utils/mergeOperation.js +1 -2
  119. package/lib/esm/utils/mergeOperation.js.map +1 -1
  120. package/lib/esm/utils/operationIdFormatter.js +1 -1
  121. package/lib/esm/utils/operationIdFormatter.js.map +1 -1
  122. package/lib/esm/utils/ref.js +1 -1
  123. package/lib/esm/utils/ref.js.map +1 -1
  124. package/lib/esm/utils/transformToOS2.js +2 -2
  125. package/lib/esm/utils/transformToOS2.js.map +1 -1
  126. package/lib/types/domain/JsonEntityStore.d.ts +1 -0
  127. package/lib/types/domain/JsonOperationRoute.d.ts +2 -2
  128. package/lib/types/utils/concatPath.d.ts +1 -1
  129. package/lib/types/utils/getJsonSchema.d.ts +1 -1
  130. package/package.json +8 -9
  131. package/readme.md +1 -1
  132. package/tsconfig.compile.esm.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":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,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE3B,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IACF,SAAS,CAAC,aAAa,GAAG,CAAC,aAAqB,EAAE,EAAE;QAClD,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC;QAErC,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,SAAS,CAAC,aAAa,GAAG,CAAC,aAAqB,EAAE,EAAE;QAClD,MAAM,CAAC,aAAa,GAAG,aAAa,CAAC;QAErC,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,SAAS,CAAC,QAAQ,GAAG,GAAG,EAAE;QACxB,QAAQ,GAAG,IAAI,CAAC;QAEhB,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,SAAS,CAAC,WAAW,GAAG,CAAC,WAAW,GAAG,IAAI,EAAE,EAAE;QAC7C,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;QAEjC,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,IAAS;IAC/B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,IAAS;IAC7B,OAAO,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\n\nexport interface ArrayOfChainedDecorators {\n (...args: any): any;\n\n /**\n * An array instance is valid against `minItems` if its size is greater than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value `minItems` MUST be a non-negative integer.\n * :::\n *\n * ::: tip\n * Omitting this keyword has the same behavior as a value of 0.\n * :::\n */\n MinItems(minItems: number): this;\n\n /**\n * The value `maxItems` MUST be a non-negative integer.\n *\n * An array instance is valid against `maxItems` if its size is less than, or equal to, the value of this keyword.\n *\n * :: warning\n * The value `maxItems` MUST be a non-negative integer.\n * :::\n */\n MaxItems(maxItems: number): this;\n\n /**\n * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...\n *\n * The array instance will be valid against \"contains\" if at least one of its elements is valid against the given schema.\n */\n Contains(): this;\n\n /**\n * If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.\n */\n UniqueItems(uniqueItems?: boolean): this;\n}\n\nexport interface MapOfChainedDecorators {\n (...args: any): any;\n\n /**\n * An object instance is valid against `minProperties` if its number of properties is less than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value of this keyword MUST be a non-negative integer.\n * :::\n */\n MinProperties(minProperties: number): this;\n\n /**\n * An object instance is valid against `maxProperties` if its number of properties is less than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value of this keyword MUST be a non-negative integer.\n * :::\n */\n MaxProperties(maxProperties: number): this;\n}\n\nexport interface CollectionOfChainedDecorators extends MapOfChainedDecorators, ArrayOfChainedDecorators {}\n\n/**\n * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...\n *\n * ```typescript\n * class Model {\n * @CollectionOf(String).MinLength(0).MaxLength(0)\n * property: string[];\n * }\n * ```\n * ::: warning\n * You mustn't use the `type Type = string | number` as parameters Type.\n *\n * This example doesn't work:\n *\n * ```typescript\n * type Type = \"string\" | \"number\"\n * class Model {\n * @CollectionOf(Type)\n * property: Type[];\n * }\n * ```\n * :::\n *\n * @param {Type<any>} type\n * @param collectionType\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @collections\n */\nexport function CollectionOf(type: any, collectionType?: any): CollectionOfChainedDecorators {\n const schema: any = {};\n let contains: boolean = false;\n\n const decorator = (...args: any) => {\n const store = JsonEntityStore.from(...args);\n // const itemSchema = store.itemSchema.toJSON();\n\n if (collectionType) {\n store.collectionType = collectionType;\n store.schema.type(collectionType);\n }\n\n store.type = type;\n // console.log(type);\n store.itemSchema.type(type);\n // console.log(store.itemSchema.getComputedType(), schema);\n // store.itemSchema.assign({...itemSchema, type});\n store.schema.assign(schema);\n\n if (store.isArray && contains) {\n store.schema.set(\"contains\", store.schema.get(\"items\"));\n store.schema.delete(\"items\");\n }\n };\n\n decorator.MinItems = (minItems: number) => {\n schema.minItems = minItems;\n\n return decorator;\n };\n\n decorator.MaxItems = (maxItems: number) => {\n schema.maxItems = maxItems;\n\n return decorator;\n };\n decorator.MinProperties = (minProperties: number) => {\n schema.minProperties = minProperties;\n\n return decorator;\n };\n\n decorator.MaxProperties = (maxProperties: number) => {\n schema.maxProperties = maxProperties;\n\n return decorator;\n };\n\n decorator.Contains = () => {\n contains = true;\n\n return decorator;\n };\n\n decorator.UniqueItems = (uniqueItems = true) => {\n schema.uniqueItems = uniqueItems;\n\n return decorator;\n };\n\n return decorator;\n}\n\n/**\n * Alias of @@GenericOf@@ decorator.\n * @param type\n * @decorator\n */\nexport function ArrayOf(type: any): ArrayOfChainedDecorators {\n return CollectionOf(type, Array);\n}\n\n/**\n * Alias of @@GenericOf@@ decorator.\n * @param type\n * @decorator\n */\nexport function MapOf(type: any): MapOfChainedDecorators {\n return CollectionOf(type, Map);\n}\n"]}
1
+ {"version":3,"file":"collectionOf.js","sourceRoot":"","sources":["../../../../src/decorators/collections/collectionOf.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAkE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,YAAY,CAAC,IAAS,EAAE,cAAoB;IAC1D,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CACb,iJAAiJ,CAClJ,CAAC;KACH;IAED,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,IAAI,QAAQ,GAAY,KAAK,CAAC;IAE9B,MAAM,SAAS,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;QACjC,MAAM,KAAK,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AI,CAAC;QAEhB,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,SAAS,CAAC,WAAW,GAAG,CAAC,WAAW,GAAG,IAAI,EAAE,EAAE;QAC7C,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;QAEjC,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,IAAS;IAC/B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,IAAS;IAC7B,OAAO,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import {Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\n\nexport interface ArrayOfChainedDecorators {\n (...args: any): any;\n\n /**\n * An array instance is valid against `minItems` if its size is greater than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value `minItems` MUST be a non-negative integer.\n * :::\n *\n * ::: tip\n * Omitting this keyword has the same behavior as a value of 0.\n * :::\n */\n MinItems(minItems: number): this;\n\n /**\n * The value `maxItems` MUST be a non-negative integer.\n *\n * An array instance is valid against `maxItems` if its size is less than, or equal to, the value of this keyword.\n *\n * :: warning\n * The value `maxItems` MUST be a non-negative integer.\n * :::\n */\n MaxItems(maxItems: number): this;\n\n /**\n * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...\n *\n * The array instance will be valid against \"contains\" if at least one of its elements is valid against the given schema.\n */\n Contains(): this;\n\n /**\n * If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.\n */\n UniqueItems(uniqueItems?: boolean): this;\n}\n\nexport interface MapOfChainedDecorators {\n (...args: any): any;\n\n /**\n * An object instance is valid against `minProperties` if its number of properties is less than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value of this keyword MUST be a non-negative integer.\n * :::\n */\n MinProperties(minProperties: number): this;\n\n /**\n * An object instance is valid against `maxProperties` if its number of properties is less than, or equal to, the value of this keyword.\n *\n * ::: warning\n * The value of this keyword MUST be a non-negative integer.\n * :::\n */\n MaxProperties(maxProperties: number): this;\n}\n\nexport interface CollectionOfChainedDecorators extends MapOfChainedDecorators, ArrayOfChainedDecorators {}\n\n/**\n * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...\n *\n * ```typescript\n * class Model {\n * @CollectionOf(String).MinLength(0).MaxLength(0)\n * property: string[];\n * }\n * ```\n * ::: warning\n * You mustn't use the `type Type = string | number` as parameters Type.\n *\n * This example doesn't work:\n *\n * ```typescript\n * type Type = \"string\" | \"number\"\n * class Model {\n * @CollectionOf(Type)\n * property: Type[];\n * }\n * ```\n * :::\n *\n * @param {Type<any>} type\n * @param collectionType\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @collections\n */\nexport function CollectionOf(type: any, collectionType?: any): CollectionOfChainedDecorators {\n if (!type) {\n throw new Error(\n \"A type is required on `@CollectionOf(type)` decorator. Please give a type or wrap it inside an arrow function if you have a circular reference.\"\n );\n }\n\n const schema: any = {};\n let contains: boolean = false;\n\n const decorator = (...args: any) => {\n const store = JsonEntityStore.from(...args);\n\n if (collectionType) {\n store.collectionType = collectionType;\n store.schema.type(collectionType);\n }\n\n store.type = type;\n store.itemSchema.type(type);\n\n store.schema.assign(schema);\n\n if (store.isArray && contains) {\n store.schema.set(\"contains\", store.schema.get(\"items\"));\n store.schema.delete(\"items\");\n }\n };\n\n decorator.MinItems = (minItems: number) => {\n schema.minItems = minItems;\n\n return decorator;\n };\n\n decorator.MaxItems = (maxItems: number) => {\n schema.maxItems = maxItems;\n\n return decorator;\n };\n decorator.MinProperties = (minProperties: number) => {\n schema.minProperties = minProperties;\n\n return decorator;\n };\n\n decorator.MaxProperties = (maxProperties: number) => {\n schema.maxProperties = maxProperties;\n\n return decorator;\n };\n\n decorator.Contains = () => {\n contains = true;\n\n return decorator;\n };\n\n decorator.UniqueItems = (uniqueItems = true) => {\n schema.uniqueItems = uniqueItems;\n\n return decorator;\n };\n\n return decorator;\n}\n\n/**\n * Alias of @@GenericOf@@ decorator.\n * @param type\n * @decorator\n */\nexport function ArrayOf(type: any): ArrayOfChainedDecorators {\n return CollectionOf(type, Array);\n}\n\n/**\n * Alias of @@GenericOf@@ decorator.\n * @param type\n * @decorator\n */\nexport function MapOf(type: any): MapOfChainedDecorators {\n return CollectionOf(type, Map);\n}\n"]}
@@ -54,7 +54,6 @@ import { JsonEntityFn } from "./jsonEntityFn.js";
54
54
  */
55
55
  export function Description(description) {
56
56
  return JsonEntityFn((store, args) => {
57
- var _a;
58
57
  switch (decoratorTypeOf(args)) {
59
58
  case DecoratorTypes.PROP:
60
59
  case DecoratorTypes.CLASS:
@@ -64,7 +63,7 @@ export function Description(description) {
64
63
  store.parameter.description(description);
65
64
  break;
66
65
  case DecoratorTypes.METHOD:
67
- (_a = store.operation) === null || _a === void 0 ? void 0 : _a.description(description);
66
+ store.operation?.description(description);
68
67
  break;
69
68
  }
70
69
  });
@@ -1 +1 @@
1
- {"version":3,"file":"description.js","sourceRoot":"","sources":["../../../../src/decorators/common/description.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,WAAW,CAAC,WAAgB;IAC1C,OAAO,YAAY,CAAC,CAAC,KAAsB,EAAE,IAAyB,EAAE,EAAE;;QACxE,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,IAAI,CAAC;YACzB,KAAK,cAAc,CAAC,KAAK;gBACvB,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBACtC,MAAM;YAER,KAAK,cAAc,CAAC,KAAK;gBACtB,KAA4B,CAAC,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBACjE,MAAM;YAER,KAAK,cAAc,CAAC,MAAM;gBACxB,MAAC,KAAyB,CAAC,SAAS,0CAAE,WAAW,CAAC,WAAW,CAAC,CAAC;gBAC/D,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorParameters, decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\nimport type {JsonMethodStore} from \"../../domain/JsonMethodStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\n\n/**\n * Add a description to the class, method or property\n *\n * ## Examples\n * ### On class\n *\n * ```typescript\n * @Description(\"description\")\n * class Model {\n *\n * }\n * ```\n *\n * ### On method\n *\n * ```typescript\n * @Controller(\"/\")\n * class ModelCtrl {\n * @Description(\"description\")\n * async method() {}\n * }\n * ```\n *\n * ### On parameter\n *\n * ```typescript\n * @Controller(\"/\")\n * class ModelCtrl {\n * async method(@Description(\"description\") @PathParam(\"id\") id: string) {}\n * }\n * ```\n *\n * ### On property\n *\n * ```typescript\n * class Model {\n * @Description(\"description\")\n * id: string;\n * }\n * ```\n *\n * @param {string} description\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @classDecorator\n * @methodDecorator\n * @propertyDecorator\n * @parameterDecorator\n */\nexport function Description(description: any) {\n return JsonEntityFn((store: JsonEntityStore, args: DecoratorParameters) => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.PROP:\n case DecoratorTypes.CLASS:\n store.schema.description(description);\n break;\n\n case DecoratorTypes.PARAM:\n (store as JsonParameterStore).parameter.description(description);\n break;\n\n case DecoratorTypes.METHOD:\n (store as JsonMethodStore).operation?.description(description);\n break;\n }\n });\n}\n"]}
1
+ {"version":3,"file":"description.js","sourceRoot":"","sources":["../../../../src/decorators/common/description.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAEhF,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,UAAU,WAAW,CAAC,WAAgB;IAC1C,OAAO,YAAY,CAAC,CAAC,KAAsB,EAAE,IAAyB,EAAE,EAAE;QACxE,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,cAAc,CAAC,IAAI,CAAC;YACzB,KAAK,cAAc,CAAC,KAAK;gBACvB,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBACtC,MAAM;YAER,KAAK,cAAc,CAAC,KAAK;gBACtB,KAA4B,CAAC,SAAS,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;gBACjE,MAAM;YAER,KAAK,cAAc,CAAC,MAAM;gBACvB,KAAyB,CAAC,SAAS,EAAE,WAAW,CAAC,WAAW,CAAC,CAAC;gBAC/D,MAAM;SACT;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {DecoratorParameters, decoratorTypeOf, DecoratorTypes} from \"@tsed/core\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonEntityFn} from \"./jsonEntityFn\";\nimport type {JsonMethodStore} from \"../../domain/JsonMethodStore\";\nimport type {JsonParameterStore} from \"../../domain/JsonParameterStore\";\n\n/**\n * Add a description to the class, method or property\n *\n * ## Examples\n * ### On class\n *\n * ```typescript\n * @Description(\"description\")\n * class Model {\n *\n * }\n * ```\n *\n * ### On method\n *\n * ```typescript\n * @Controller(\"/\")\n * class ModelCtrl {\n * @Description(\"description\")\n * async method() {}\n * }\n * ```\n *\n * ### On parameter\n *\n * ```typescript\n * @Controller(\"/\")\n * class ModelCtrl {\n * async method(@Description(\"description\") @PathParam(\"id\") id: string) {}\n * }\n * ```\n *\n * ### On property\n *\n * ```typescript\n * class Model {\n * @Description(\"description\")\n * id: string;\n * }\n * ```\n *\n * @param {string} description\n * @decorator\n * @validation\n * @swagger\n * @schema\n * @input\n * @classDecorator\n * @methodDecorator\n * @propertyDecorator\n * @parameterDecorator\n */\nexport function Description(description: any) {\n return JsonEntityFn((store: JsonEntityStore, args: DecoratorParameters) => {\n switch (decoratorTypeOf(args)) {\n case DecoratorTypes.PROP:\n case DecoratorTypes.CLASS:\n store.schema.description(description);\n break;\n\n case DecoratorTypes.PARAM:\n (store as JsonParameterStore).parameter.description(description);\n break;\n\n case DecoratorTypes.METHOD:\n (store as JsonMethodStore).operation?.description(description);\n break;\n }\n });\n}\n"]}
@@ -15,8 +15,7 @@ export function Redirect(...args) {
15
15
  return options;
16
16
  }, { status: 302, url: "", meta: {} });
17
17
  return useDecorators(Returns(status).Location(url, meta), JsonEntityFn((entity) => {
18
- var _a;
19
- (_a = entity.operation) === null || _a === void 0 ? void 0 : _a.setRedirection(status);
18
+ entity.operation?.setRedirection(status);
20
19
  }));
21
20
  }
22
21
  //# sourceMappingURL=redirect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../../../src/decorators/operations/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAqDlC,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAW;IACrC,MAAM,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,MAAM,CACrC,CAAC,OAAY,EAAE,KAAU,EAAE,EAAE;QAC3B,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;YACvB,OAAO,OAAO,CAAC;SAChB;QAED,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC;YACpB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;QACrB,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CACjC,CAAC;IACF,OAAO,aAAa,CAClB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EACnC,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE;;QACtB,MAAA,MAAM,CAAC,SAAS,0CAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {isNumber, isString, useDecorators} from \"@tsed/core\";\nimport {JsonHeader} from \"../../interfaces/JsonOpenSpec\";\nimport {JsonEntityFn} from \"../common/jsonEntityFn\";\nimport {Returns} from \"./returns\";\n\n/**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.\n *\n * ```typescript\n * @Redirect('/foo/bar')\n * @Redirect(301, 'http://example.com').Type(Model)\n * private myMethod() {}\n * ```\n * Redirects can be a fully-qualified URL for redirecting to a different site:\n *\n * ```typescript\n * @Redirect('http://google.com');\n * private myMethod() {}\n * ```\n *\n * Redirects can be relative to the root of the host name. For example, if the application is on http://example.com/admin/post/new, the following would redirect to the URL http://example.com/admin:\n *\n * ```typescript\n * @Redirect('/admin');\n * ```\n * Redirects can be relative to the current URL. For example, from http://example.com/blog/admin/ (notice the trailing slash), the following would redirect to the URL http://example.com/blog/admin/post/new.\n *\n * ```typescript\n * @Redirect('post/new');\n * ```\n *\n * Redirecting to post/new from http://example.com/blog/admin (no trailing slash), will redirect to http://example.com/blog/post/new.\n *\n * If you found the above behavior confusing, think of path segments as directories (with trailing slashes) and files, it will start to make sense.\n *\n * Path-relative redirects are also possible. If you were on http://example.com/admin/post/new, the following would redirect to http//example.com/admin/post:\n *\n * ```typescript\n * @Redirect('..');\n * ``\n *\n * A back redirection redirects the request back to the referer, defaulting to / when the referer is missing.\n *\n * ```typescript\n * @Redirect('back');\n * ```\n *\n * @param url\n * @param meta\n * @decorator\n * @operation\n * @response\n * @headers\n */\nexport function Redirect(url: string, meta?: JsonHeader): Function;\nexport function Redirect(status: number, url: string, meta?: JsonHeader): Function;\nexport function Redirect(...args: any[]): Function {\n const {status, url, meta} = args.reduce(\n (options: any, value: any) => {\n if (isNumber(value)) {\n options.status = value;\n return options;\n }\n\n if (isString(value)) {\n options.url = value;\n return options;\n }\n\n options.meta = value;\n return options;\n },\n {status: 302, url: \"\", meta: {}}\n );\n return useDecorators(\n Returns(status).Location(url, meta),\n JsonEntityFn((entity) => {\n entity.operation?.setRedirection(status);\n })\n );\n}\n"]}
1
+ {"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../../../src/decorators/operations/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAE7D,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAqDlC,MAAM,UAAU,QAAQ,CAAC,GAAG,IAAW;IACrC,MAAM,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,MAAM,CACrC,CAAC,OAAY,EAAE,KAAU,EAAE,EAAE;QAC3B,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;YACvB,OAAO,OAAO,CAAC;SAChB;QAED,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;YACnB,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC;YACpB,OAAO,OAAO,CAAC;SAChB;QAED,OAAO,CAAC,IAAI,GAAG,KAAK,CAAC;QACrB,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,EAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CACjC,CAAC;IACF,OAAO,aAAa,CAClB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EACnC,YAAY,CAAC,CAAC,MAAM,EAAE,EAAE;QACtB,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {isNumber, isString, useDecorators} from \"@tsed/core\";\nimport {JsonHeader} from \"../../interfaces/JsonOpenSpec\";\nimport {JsonEntityFn} from \"../common/jsonEntityFn\";\nimport {Returns} from \"./returns\";\n\n/**\n * Redirects to the URL derived from the specified path, with specified status, a positive integer that corresponds to an HTTP status code . If not specified, status defaults to “302 “Found”.\n *\n * ```typescript\n * @Redirect('/foo/bar')\n * @Redirect(301, 'http://example.com').Type(Model)\n * private myMethod() {}\n * ```\n * Redirects can be a fully-qualified URL for redirecting to a different site:\n *\n * ```typescript\n * @Redirect('http://google.com');\n * private myMethod() {}\n * ```\n *\n * Redirects can be relative to the root of the host name. For example, if the application is on http://example.com/admin/post/new, the following would redirect to the URL http://example.com/admin:\n *\n * ```typescript\n * @Redirect('/admin');\n * ```\n * Redirects can be relative to the current URL. For example, from http://example.com/blog/admin/ (notice the trailing slash), the following would redirect to the URL http://example.com/blog/admin/post/new.\n *\n * ```typescript\n * @Redirect('post/new');\n * ```\n *\n * Redirecting to post/new from http://example.com/blog/admin (no trailing slash), will redirect to http://example.com/blog/post/new.\n *\n * If you found the above behavior confusing, think of path segments as directories (with trailing slashes) and files, it will start to make sense.\n *\n * Path-relative redirects are also possible. If you were on http://example.com/admin/post/new, the following would redirect to http//example.com/admin/post:\n *\n * ```typescript\n * @Redirect('..');\n * ``\n *\n * A back redirection redirects the request back to the referer, defaulting to / when the referer is missing.\n *\n * ```typescript\n * @Redirect('back');\n * ```\n *\n * @param url\n * @param meta\n * @decorator\n * @operation\n * @response\n * @headers\n */\nexport function Redirect(url: string, meta?: JsonHeader): Function;\nexport function Redirect(status: number, url: string, meta?: JsonHeader): Function;\nexport function Redirect(...args: any[]): Function {\n const {status, url, meta} = args.reduce(\n (options: any, value: any) => {\n if (isNumber(value)) {\n options.status = value;\n return options;\n }\n\n if (isString(value)) {\n options.url = value;\n return options;\n }\n\n options.meta = value;\n return options;\n },\n {status: 302, url: \"\", meta: {}}\n );\n return useDecorators(\n Returns(status).Location(url, meta),\n JsonEntityFn((entity) => {\n entity.operation?.setRedirection(status);\n })\n );\n}\n"]}
@@ -25,26 +25,26 @@ function mapGenerics(types) {
25
25
  * @ignore
26
26
  */
27
27
  class ReturnDecoratorContext extends DecoratorContext {
28
+ methods = [
29
+ "contentType",
30
+ "description",
31
+ "examples",
32
+ "type",
33
+ "status",
34
+ "of",
35
+ "oneOf",
36
+ "allOf",
37
+ "anyOf",
38
+ "nested",
39
+ "header",
40
+ "headers",
41
+ "schema",
42
+ "title",
43
+ "groups",
44
+ "location"
45
+ ];
28
46
  constructor({ status, model }) {
29
47
  super();
30
- this.methods = [
31
- "contentType",
32
- "description",
33
- "examples",
34
- "type",
35
- "status",
36
- "of",
37
- "oneOf",
38
- "allOf",
39
- "anyOf",
40
- "nested",
41
- "header",
42
- "headers",
43
- "schema",
44
- "title",
45
- "groups",
46
- "location"
47
- ];
48
48
  this.model(model);
49
49
  this.status(status);
50
50
  }
@@ -103,10 +103,10 @@ class ReturnDecoratorContext extends DecoratorContext {
103
103
  this.addAction(() => {
104
104
  const schema = this.get("schema");
105
105
  if (isCollection(model)) {
106
- schema === null || schema === void 0 ? void 0 : schema.itemSchema({ type: types[0] });
106
+ schema?.itemSchema({ type: types[0] });
107
107
  }
108
108
  else {
109
- schema === null || schema === void 0 ? void 0 : schema.nestedGenerics.push(mapGenerics(types));
109
+ schema?.nestedGenerics.push(mapGenerics(types));
110
110
  }
111
111
  });
112
112
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,2BAA2B,EAC3B,QAAQ,EAET,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,gBAAgB,EAAuB,MAAM,oCAAoC,CAAC;AAC1F,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAC,UAAU,EAAmB,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAgHlD;;GAEG;AACH,SAAS,MAAM,CAAC,IAAS;IACvB,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,KAAqB;IACxC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE;YAChB,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC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,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,WAAW,IAAI,KAAK,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAI,UAAU,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC;QAEpE,IAAI,KAAK,EAAE;YACT,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;gBAClB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC;aAC7C;iBAAM;gBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACpB;SACF;QAED,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE3B,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAErB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEtC,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC1B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA+JD,MAAM,UAAU,OAAO,CAAC,MAAwB,EAAE,KAAqC;IACrF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n decoratorTypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage, HTTP_STATUS_MESSAGES} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n *\n * @param groups\n * @constructor\n */\n Groups(...groups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(...groups: string[]) {\n this.set(\"groups\", groups);\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({oneOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n allOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({allOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({anyOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = this.get(\"groups\");\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
1
+ {"version":3,"file":"returns.js","sourceRoot":"","sources":["../../../../src/decorators/operations/returns.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,2BAA2B,EAC3B,QAAQ,EAET,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAC,gBAAgB,EAAuB,MAAM,oCAAoC,CAAC;AAC1F,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,M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,CAAC,CAAC;QAErB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAEtC,IAAI,QAAQ,EAAE;YACZ,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;SAC1B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA+JD,MAAM,UAAU,OAAO,CAAC,MAAwB,EAAE,KAAqC;IACrF,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM;QACN,KAAK;KACN,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n decorateMethodsOf,\n decoratorTypeOf,\n DecoratorTypes,\n isArray,\n isCollection,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n isString,\n Type\n} from \"@tsed/core\";\nimport {OS3Example} from \"@tsed/openspec\";\nimport {getStatusMessage, HTTP_STATUS_MESSAGES} from \"../../constants/httpStatusMessages\";\nimport {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {JsonEntityStore} from \"../../domain/JsonEntityStore\";\nimport {JsonResponse} from \"../../domain/JsonResponse\";\nimport {JsonSchema, JsonSchemaObject} from \"../../domain/JsonSchema\";\nimport {JsonHeader, JsonHeaders} from \"../../interfaces/JsonOpenSpec\";\nimport {getStatusModel} from \"../../utils/defineStatusModel\";\nimport {string} from \"../../utils/from\";\nimport {GenericValue} from \"../../utils/generics\";\nimport {isSuccessStatus} from \"../../utils/isSuccessStatus\";\nimport {mapHeaders} from \"../../utils/mapHeaders\";\n\nexport interface ReturnsChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n (target: Function): void;\n\n /**\n * Set a Content-Type for the current response\n * @param value\n * @constructor\n */\n ContentType(value: string): this;\n\n /**\n * Add a description\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Add examples\n * @param examples\n */\n Examples(examples: Record<string, OS3Example>): this;\n\n Examples(examples: Record<string, any>): this;\n\n Examples(examples: any): this;\n\n /**\n * Change the model type\n * @param type\n */\n Type(type: Type<any> | any): this;\n\n /**\n * Change the status\n * @param status\n * @constructor\n */\n Status(status: string | number): this;\n\n /**\n * Add the nested types\n * @param types\n */\n Of(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n OneOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AllOf(...types: GenericValue[]): this;\n\n /**\n * Add the nested types\n * @param types\n */\n AnyOf(...types: GenericValue[]): this;\n\n /**\n * Declare a nested generic models\n * @param generics\n */\n Nested(...generics: GenericValue[]): this;\n\n /**\n * Add header.\n * @param key\n * @param value\n */\n Header(key: string, value: number | string | (JsonHeader & {value?: string | number | boolean})): this;\n\n /**\n * Add headers\n */\n Headers(headers: JsonHeaders): this;\n\n /**\n * Add location hea\n */\n Location(location: string, meta?: JsonHeader): this;\n\n /**\n * Assign partial schema\n * @param schema\n */\n Schema(schema: Partial<JsonSchemaObject> | JsonSchema): this;\n\n /**\n * Add an inline title for the return model.\n * @param title\n */\n Title(title: string): this;\n\n /**\n *\n * @param groups\n * @constructor\n */\n Groups(...groups: string[]): this;\n\n [key: string]: any;\n}\n\n/**\n * @ignore\n */\nfunction isEnum(type: any) {\n return isObject(type) && !(\"toJSON\" in type);\n}\n\nfunction mapGenerics(types: GenericValue[]) {\n return types.map((type) => {\n if (isEnum(type)) {\n return string().enum(Object.values(type));\n }\n return type;\n });\n}\n\n/**\n * @ignore\n */\nclass ReturnDecoratorContext extends DecoratorContext<ReturnsChainedDecorators> {\n readonly methods: string[] = [\n \"contentType\",\n \"description\",\n \"examples\",\n \"type\",\n \"status\",\n \"of\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"nested\",\n \"header\",\n \"headers\",\n \"schema\",\n \"title\",\n \"groups\",\n \"location\"\n ];\n\n constructor({status, model}: any) {\n super();\n\n this.model(model);\n this.status(status);\n }\n\n type(model: any) {\n return this.model(model);\n }\n\n model(model: any) {\n model && this.set(\"model\", model);\n return this;\n }\n\n status(status: number | string) {\n this.set(\"status\", status);\n\n if (status && getStatusMessage(status) && !this.get(\"description\")) {\n this.set(\"description\", getStatusMessage(status));\n\n if (!this.get(\"model\")) {\n this.model(getStatusModel(+status));\n }\n }\n\n return this;\n }\n\n headers(headers: JsonHeaders) {\n this.set(\"headers\", {\n ...(this.get(\"headers\") || {}),\n ...mapHeaders(headers)\n });\n\n return this;\n }\n\n header(key: string, value: string | JsonHeader) {\n return this.headers({[key]: value});\n }\n\n location(path: string, meta: JsonHeaders = {}) {\n this.headers({\n Location: {\n ...meta,\n value: path\n }\n });\n\n return this;\n }\n\n groups(...groups: string[]) {\n this.set(\"groups\", groups);\n return this;\n }\n\n nested(...generics: GenericValue[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n this.checkCollection(model);\n\n this.addAction((ctx) => {\n (this.get(\"schema\") as JsonSchema).nestedGenerics.push(mapGenerics(generics));\n });\n\n return this;\n }\n\n of(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n this.checkPrimitive(model);\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n if (isCollection(model)) {\n schema?.itemSchema({type: types[0]});\n } else {\n schema?.nestedGenerics.push(mapGenerics(types));\n }\n });\n\n return this;\n }\n\n oneOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({oneOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n allOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({allOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n anyOf(...types: (Type<any> | any)[]) {\n const model = this.get(\"model\");\n\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n schema.type(model);\n schema.itemSchema({anyOf: types.map((type) => ({type}))});\n });\n\n return this;\n }\n\n schema(partial: Partial<JsonSchemaObject>) {\n this.addAction(() => {\n const schema = this.get(\"schema\") as JsonSchema;\n\n schema!.assign(partial);\n });\n\n return this;\n }\n\n examples(examples: any) {\n this.set(\"examples\", isString(examples) ? [examples] : examples);\n return this;\n }\n\n title(title: string) {\n return this.schema({title});\n }\n\n protected checkPrimitive(model: any) {\n if (isPrimitiveOrPrimitiveClass(model)) {\n throw new Error(\"Returns.Of cannot be used with the following primitive classes: String, Number, Boolean\");\n }\n }\n\n protected checkCollection(model: any) {\n if (isCollection(model)) {\n throw new Error(\"Returns.Nested cannot be used with the following classes: Map, Set, Array, String, Number, Boolean\");\n }\n }\n\n protected getContentType() {\n const model = this.get(\"model\");\n let contentType = this.get(\"contentType\");\n\n if (model && !isPlainObject(model) && !isPrimitiveOrPrimitiveClass(model)) {\n contentType = contentType || \"application/json\";\n }\n\n return contentType;\n }\n\n protected getStatus() {\n return this.get(\"status\") || \"default\";\n }\n\n protected onInit(args: any[], decorator: any) {\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.METHOD:\n this.entity = JsonEntityStore.from(...args);\n if (this.entity.operation) {\n this.map();\n }\n break;\n case DecoratorTypes.CLASS:\n this.decoratorType = DecoratorTypes.CLASS;\n decorateMethodsOf(args[0], decorator);\n break;\n }\n }\n\n protected map() {\n const model = this.get(\"model\");\n const {entity, decoratorType} = this;\n const operation = this.entity.operation!;\n const currentStatus = this.getStatus();\n const response = operation.ensureResponseOf(currentStatus);\n const contentType = this.getContentType();\n\n let {description = response.get(\"description\")} = this.toObject();\n\n if (description) {\n description = decoratorType === DecoratorTypes.CLASS ? response.get(\"description\") || description : description;\n response.description(description);\n }\n\n const headers = this.getMergedKey(\"headers\", response.get(\"headers\"));\n\n if (headers) {\n response.headers(headers);\n }\n\n this.mapMedia(response);\n\n if (isSuccessStatus(this.get(\"status\")) || currentStatus === \"default\") {\n if (model) {\n entity.type = model;\n }\n }\n\n // additional info for OS2\n contentType && operation.addProduce(contentType);\n\n // run additional actions\n return this.runActions();\n }\n\n protected mapMedia(response: JsonResponse) {\n const contentType = this.getContentType();\n const model = this.get(\"model\");\n const media = response.getMedia(contentType || \"*/*\");\n const schema = media.get(\"schema\") || new JsonSchema({type: model});\n\n if (model) {\n if (isArray(model)) {\n schema.oneOf(model.map((type) => ({type})));\n } else {\n schema.type(model);\n }\n }\n\n this.set(\"schema\", schema);\n\n media.schema(schema);\n\n media.groups = this.get(\"groups\");\n\n const examples = this.get(\"examples\");\n\n if (examples) {\n media.examples(examples);\n }\n\n return media;\n }\n}\n\n/**\n * Add responses documentation for a specific status code.\n *\n * ## Usage\n *\n * Ts.ED v5/v6 API introducing the chaining decorator concept. Now a decorator like Returns can be used with another decorators like Description.\n *\n * ::: warning\n * v5 has a basic support of the chaining decorator to facilitate the migration to v6!\n * :::\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @Returns(404, String).Description(\"Not Found\")\n * @Returns(200, Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ::: tip\n * TypeScript and your IDE will discover automatically the chained decorators. But for more details you can look on @@ReturnsChainedDecorators@@ interface, to know\n * what chained decorators are available under Returns decorator.\n * :::\n *\n * This example will produce this documentation in swagger:\n *\n * ```json\n * {\n * \"responses\": {\n * \"404\": {\n * \"description\": \"Description\",\n * \"schema\": {\"type\": \"string\"}\n * },\n * \"2OO\": {\n * \"description\": \"Description\",\n * \"schema\": {\"$ref\": \"...\"}\n * }\n * }\n * }\n * ```\n *\n * ## Declaring an Array\n *\n * Use chained decorators to declare an array with model as following:\n *\n * ```typescript\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/models\")\n * class ModelCtrl {\n * @Get(\"/\")\n * @Returns(200, Array).Of(Model).Description(\"Success\")\n * async myMethod(): Promise<Model> {\n * }\n * }\n * ```\n *\n * Deprecated version:\n *\n * ```typescript\n * import {ReturnsArray} from \"@tsed/common\";\n * import {Returns} from \"@tsed/schema\";\n *\n * @Controller(\"/\")\n * class MyController {\n * @ReturnsArray(200, Model) // deprecated\n * async myMethod(): Promise<Model> {}\n * }\n * ```\n *\n * ### Declaring a generic model <Badge text=\"6+\"/>\n *\n * Sometime, it might be useful to use generic models. TypeScript doesn't store the generic type in the metadata. This is why we need to\n * declare explicitly the generic models with the decorators.\n *\n * One of the generic's usage, can be a paginated list. With Returns decorator it's now possible to declare generic type and generate the appropriate OpenSpec documentation.\n *\n * Starting with the pagination model, by using @@Generics@@ and @@CollectionOf@@:\n *\n * ```typescript\n * @Generics(\"T\")\n * class Pagination<T> {\n * @CollectionOf(\"T\")\n * data: T[];\n *\n * @Property()\n * totalCount: number;\n * }\n * ```\n *\n * Now, we need a model to be used with the generic Pagination model:\n *\n * ```typescript\n * class Product {\n * @Property()\n * id: string;\n *\n * @Property()\n * title: string;\n * }\n * ```\n *\n * Finally, we can use our models on a method as following:\n *\n * ```typescript\n * class Controller {\n * @OperationPath(\"POST\", \"/\")\n * @Returns(200, Pagination).Of(Product).Description(\"description\")\n * async method(): Promise<Pagination<Product> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * ### Declaring a nested generics models <Badge text=\"6+\"/>\n *\n * It's also possible to declare a nested generics models in order to have this type `Pagination<Submission<Product>>`:\n *\n * ```typescript\n * import {Generics, Property, Returns} from \"@tsed/schema\";\n * import {Post} from \"@tsed/common\";\n *\n * class Controller {\n * @Post(\"/\")\n * @Returns(200, Pagination).Of(Submission).Nested(Product).Description(\"description\")\n * async method(): Promise<Pagination<Submission<Product>> | null> {\n * return null;\n * }\n * }\n * ```\n *\n * And here is the Submission model:\n *\n * ```typescript\n * import {Generics, Property} from \"@tsed/schema\";\n *\n * @Generics(\"T\")\n * class Submission<T> {\n * @Property()\n * _id: string;\n * @Property(\"T\")\n * data: T;\n * }\n * ```\n *\n * @param status\n * @param model\n * @decorator\n * @swagger\n * @schema\n * @response\n * @operation\n */\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[]): ReturnsChainedDecorators;\nexport function Returns(status?: string | number, model?: Type<any> | Type<any>[] | any): ReturnsChainedDecorators {\n const context = new ReturnDecoratorContext({\n status,\n model\n });\n\n return context.build();\n}\n"]}
@@ -2,10 +2,7 @@ import { DecoratorContext } from "../../domain/DecoratorContext.js";
2
2
  import { mapRouteOptions } from "../../utils/mapRouteOptions.js";
3
3
  import { OperationMethods } from "../../constants/httpMethods.js";
4
4
  class RouteDecoratorContext extends DecoratorContext {
5
- constructor() {
6
- super(...arguments);
7
- this.methods = ["name", "description", "summary", "method", "id", "use", "useAfter", "useBefore"];
8
- }
5
+ methods = ["name", "description", "summary", "method", "id", "use", "useAfter", "useBefore"];
9
6
  beforeInit() {
10
7
  const path = this.get("path");
11
8
  const method = OperationMethods[this.get("method")] || OperationMethods.CUSTOM;
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../src/decorators/operations/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAkD7D,MAAM,qBAAsB,SAAQ,gBAAwC;IAA5E;;QACW,YAAO,GAAa,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAmClH,CAAC;IAhCW,UAAU;QAClB,MAAM,IAAI,GAAW,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,MAAM,GAAW,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ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,UAAU,KAAK,CAAC,OAA8B,GAAG,EAAE,GAAG,IAAW;IACrE,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,OAAO,CAAC,OAA8B,GAAG,EAAE,GAAG,IAAW;IACvE,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {mapRouteOptions} from \"../../utils/mapRouteOptions\";\nimport {OperationMethods} from \"../../constants/httpMethods\";\nimport {JsonMethodStore} from \"../../domain/JsonMethodStore\";\n\nexport interface RouteChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n /**\n * @param string\n * @constructor\n */\n Path(string: string): this;\n\n /**\n * Set the operation method\n * @param method\n */\n Method(method: OperationMethods | string): this;\n\n /**\n * Set the operation id\n * @param id\n */\n Id(id: string): this;\n\n /**\n * Set the operation id\n * @param name\n */\n Name(name: string): this;\n\n /**\n *\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Summary\n * @constructor\n * @param Summary\n */\n Summary(Summary: string): this;\n\n Use(...args: any[]): this;\n\n UseAfter(...args: any[]): this;\n\n UseBefore(...args: any[]): this;\n}\n\nclass RouteDecoratorContext extends DecoratorContext<RouteChainedDecorators> {\n readonly methods: string[] = [\"name\", \"description\", \"summary\", \"method\", \"id\", \"use\", \"useAfter\", \"useBefore\"];\n protected entity: JsonMethodStore;\n\n protected beforeInit() {\n const path: string = this.get(\"path\");\n const method: string = OperationMethods[this.get(\"method\") as OperationMethods] || OperationMethods.CUSTOM;\n\n path && this.entity.operation.addOperationPath(method, path);\n }\n\n protected onMapKey(key: string, value: any) {\n switch (key) {\n case \"name\":\n case \"id\":\n this.entity.operation.operationId(value);\n return;\n case \"summary\":\n this.entity.operation.summary(value);\n return;\n case \"description\":\n this.entity.operation.description(value);\n return;\n case \"use\":\n this.entity.use(value);\n return;\n case \"useAfter\":\n this.entity.after(value);\n return;\n case \"useBefore\":\n this.entity.before(value);\n return;\n }\n\n return super.onMapKey(key, value);\n }\n}\n\n/**\n * Describe a new route with a method and path.\n *\n * ```typescript\n * @Controller('/')\n * export class Ctrl {\n *\n * @Route('GET', '/')\n * get() { }\n * }\n *\n * ```\n *\n * @returns {Function}\n * @param method\n * @param path\n * @param args\n * @decorator\n * @operation\n */\nexport function Route(method: string, path: string, ...args: any[]): RouteChainedDecorators;\nexport function Route(...args: any[]): RouteChainedDecorators;\nexport function Route(...args: any[]): RouteChainedDecorators {\n const routeOptions = mapRouteOptions(args);\n\n const context = new RouteDecoratorContext(routeOptions);\n\n return context.build();\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function All(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.ALL, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Get(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.GET, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Post(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.POST, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Put(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.PUT, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Delete(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.DELETE, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Head(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.HEAD, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Patch(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.PATCH, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Options(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.OPTIONS, path].concat(args));\n}\n"]}
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../src/decorators/operations/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAC,eAAe,EAAC,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EA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,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,IAAI,CAAC,OAA8B,GAAG,EAAE,GAAG,IAAW;IACpE,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,KAAK,CAAC,OAA8B,GAAG,EAAE,GAAG,IAAW;IACrE,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,OAAO,CAAC,OAA8B,GAAG,EAAE,GAAG,IAAW;IACvE,OAAO,KAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import {DecoratorContext} from \"../../domain/DecoratorContext\";\nimport {mapRouteOptions} from \"../../utils/mapRouteOptions\";\nimport {OperationMethods} from \"../../constants/httpMethods\";\nimport {JsonMethodStore} from \"../../domain/JsonMethodStore\";\n\nexport interface RouteChainedDecorators {\n <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>): TypedPropertyDescriptor<T> | void;\n\n /**\n * @param string\n * @constructor\n */\n Path(string: string): this;\n\n /**\n * Set the operation method\n * @param method\n */\n Method(method: OperationMethods | string): this;\n\n /**\n * Set the operation id\n * @param id\n */\n Id(id: string): this;\n\n /**\n * Set the operation id\n * @param name\n */\n Name(name: string): this;\n\n /**\n *\n * @param description\n */\n Description(description: string): this;\n\n /**\n * Summary\n * @constructor\n * @param Summary\n */\n Summary(Summary: string): this;\n\n Use(...args: any[]): this;\n\n UseAfter(...args: any[]): this;\n\n UseBefore(...args: any[]): this;\n}\n\nclass RouteDecoratorContext extends DecoratorContext<RouteChainedDecorators> {\n readonly methods: string[] = [\"name\", \"description\", \"summary\", \"method\", \"id\", \"use\", \"useAfter\", \"useBefore\"];\n protected declare entity: JsonMethodStore;\n\n protected beforeInit() {\n const path: string = this.get(\"path\");\n const method: string = OperationMethods[this.get(\"method\") as OperationMethods] || OperationMethods.CUSTOM;\n\n path && this.entity.operation.addOperationPath(method, path);\n }\n\n protected onMapKey(key: string, value: any) {\n switch (key) {\n case \"name\":\n case \"id\":\n this.entity.operation.operationId(value);\n return;\n case \"summary\":\n this.entity.operation.summary(value);\n return;\n case \"description\":\n this.entity.operation.description(value);\n return;\n case \"use\":\n this.entity.use(value);\n return;\n case \"useAfter\":\n this.entity.after(value);\n return;\n case \"useBefore\":\n this.entity.before(value);\n return;\n }\n\n return super.onMapKey(key, value);\n }\n}\n\n/**\n * Describe a new route with a method and path.\n *\n * ```typescript\n * @Controller('/')\n * export class Ctrl {\n *\n * @Route('GET', '/')\n * get() { }\n * }\n *\n * ```\n *\n * @returns {Function}\n * @param method\n * @param path\n * @param args\n * @decorator\n * @operation\n */\nexport function Route(method: string, path: string, ...args: any[]): RouteChainedDecorators;\nexport function Route(...args: any[]): RouteChainedDecorators;\nexport function Route(...args: any[]): RouteChainedDecorators {\n const routeOptions = mapRouteOptions(args);\n\n const context = new RouteDecoratorContext(routeOptions);\n\n return context.build();\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function All(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.ALL, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Get(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.GET, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Post(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.POST, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Put(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.PUT, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Delete(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.DELETE, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Head(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.HEAD, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Patch(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.PATCH, path].concat(args));\n}\n\n/**\n * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).\n *\n * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.\n * For example, if you placed the following route at the top of all other route definitions, it would require that\n * all routes from that point on would require authentication, and automatically load a user.\n * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()\n * to continue matching subsequent routes.\n * @param path\n * @param args\n * @returns {Function}\n * @decorator\n * @operation\n * @httpMethod\n */\nexport function Options(path: string | RegExp | any = \"/\", ...args: any[]) {\n return Route(...[OperationMethods.OPTIONS, path].concat(args));\n}\n"]}
@@ -1,13 +1,16 @@
1
1
  import { DecoratorTypes } from "@tsed/core";
2
- import { pascalCase } from "pascal-case";
2
+ import { pascalCase } from "change-case";
3
3
  import { JsonEntityStore } from "./JsonEntityStore.js";
4
4
  /**
5
5
  * @ignore
6
6
  */
7
7
  export class DecoratorContext extends Map {
8
+ methods;
9
+ decoratorType;
10
+ entity;
11
+ actions = [];
8
12
  constructor(opts = {}) {
9
13
  super();
10
- this.actions = [];
11
14
  Object.entries(opts).forEach(([key, value]) => {
12
15
  this.set(key, value);
13
16
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DecoratorContext.js","sourceRoot":"","sources":["../../../src/domain/DecoratorContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAC,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AASlD;;GAEG;AACH,MAAM,OAAgB,gBAA0B,SAAQ,GAAgB;IAMtE,YAAY,OAAY,EAAE;QACxB,KAAK,EAAE,CAAC;QAHA,YAAO,GAA6B,EAAE,CAAC;QAK/C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5C,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,EAA0B;QAClC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK;QACH,MAAM,SAAS,GAAQ,CAAC,GAAG,IAAyB,EAAE,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QAED,IAAI,IAAI,CAAC,aAAa,KAAK,cAAc,CAAC,KAAK,EAAE;YAC/C,KAAK,GAAG;gBACN,GAAG,KAAK;gBACR,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;aACxB,CAAC;SACH;QAED,OAAO;YACL,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;YACvB,GAAG,KAAK;SACT,CAAC;IACJ,CAAC;IAES,IAAI,CAAC,IAAyB,EAAE,SAAc;QACtD,IAAI,CAAC,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAE5C,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC7B,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAES,MAAM,CAAC,IAAyB,EAAE,SAAc;QACxD,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;IAES,QAAQ,CAAC,GAAW,EAAE,KAAU;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IAES,UAAU;QAClB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;YACnC,MAAM,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAES,UAAU,KAAI,CAAC;IAEf,SAAS,KAAI,CAAC;CACzB","sourcesContent":["import {DecoratorParameters, DecoratorTypes} from \"@tsed/core\";\nimport {pascalCase} from \"pascal-case\";\nimport {JsonEntityStore} from \"./JsonEntityStore\";\n\n/**\n * @ignore\n */\nexport interface DecoratorActionHandler {\n (ctx: Map<string, any>): void;\n}\n\n/**\n * @ignore\n */\nexport abstract class DecoratorContext<T = any> extends Map<string, any> {\n readonly methods: string[];\n protected decoratorType: DecoratorTypes;\n protected entity: JsonEntityStore;\n protected actions: DecoratorActionHandler[] = [];\n\n constructor(opts: any = {}) {\n super();\n\n Object.entries(opts).forEach(([key, value]) => {\n this.set(key, value);\n });\n }\n\n addAction(cb: DecoratorActionHandler) {\n this.actions.push(cb);\n return this;\n }\n\n build(): T {\n const decorator: any = (...args: DecoratorParameters) => this.bind(args, decorator);\n\n const wrap = (cb: any) => {\n return (...args: any[]) => {\n cb(...args);\n return decorator;\n };\n };\n\n const wrapKey = (key: string) => {\n return wrap((...values: any[]) => {\n key in this ? (this as any)[key](...values) : this.set(key, values[0]);\n });\n };\n\n this.methods.forEach((name) => {\n decorator[pascalCase(name)] = wrapKey(name);\n });\n\n return decorator as unknown as T;\n }\n\n toObject(): any {\n return [...this.entries()].reduce((obj, [key, value]) => {\n return {\n ...obj,\n [key]: value\n };\n }, {});\n }\n\n getMergedKey(key: string, defaultValue: any) {\n let value = this.get(key) || defaultValue;\n\n if (!value) {\n return;\n }\n\n if (this.decoratorType === DecoratorTypes.CLASS) {\n value = {\n ...value,\n ...(defaultValue || {})\n };\n }\n\n return {\n ...(defaultValue || {}),\n ...value\n };\n }\n\n protected bind(args: DecoratorParameters, decorator: any) {\n this.entity = JsonEntityStore.from(...args);\n\n this.beforeInit();\n this.onInit(args, decorator);\n this.afterInit();\n }\n\n protected onInit(args: DecoratorParameters, decorator: any): void {\n this.forEach((value, key) => {\n this.onMapKey(key, value);\n });\n }\n\n protected onMapKey(key: string, value: any): void {\n this.entity.set(key, value);\n }\n\n protected runActions() {\n this.actions.forEach((action: any) => {\n action(this);\n });\n\n return this;\n }\n\n protected beforeInit() {}\n\n protected afterInit() {}\n}\n"]}
1
+ {"version":3,"file":"DecoratorContext.js","sourceRoot":"","sources":["../../../src/domain/DecoratorContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAC,MAAM,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;QACxD,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;IAES,QAAQ,CAAC,GAAW,EAAE,KAAU;QACxC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IAES,UAAU;QAClB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE;YACnC,MAAM,CAAC,IAAI,CAAC,CAAC;QACf,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAES,UAAU,KAAI,CAAC;IAEf,SAAS,KAAI,CAAC;CACzB","sourcesContent":["import {DecoratorParameters, DecoratorTypes} from \"@tsed/core\";\nimport {pascalCase} from \"change-case\";\nimport {JsonEntityStore} from \"./JsonEntityStore\";\n\n/**\n * @ignore\n */\nexport interface DecoratorActionHandler {\n (ctx: Map<string, any>): void;\n}\n\n/**\n * @ignore\n */\nexport abstract class DecoratorContext<T = any> extends Map<string, any> {\n readonly methods: string[];\n protected decoratorType: DecoratorTypes;\n protected entity: JsonEntityStore;\n protected actions: DecoratorActionHandler[] = [];\n\n constructor(opts: any = {}) {\n super();\n\n Object.entries(opts).forEach(([key, value]) => {\n this.set(key, value);\n });\n }\n\n addAction(cb: DecoratorActionHandler) {\n this.actions.push(cb);\n return this;\n }\n\n build(): T {\n const decorator: any = (...args: DecoratorParameters) => this.bind(args, decorator);\n\n const wrap = (cb: any) => {\n return (...args: any[]) => {\n cb(...args);\n return decorator;\n };\n };\n\n const wrapKey = (key: string) => {\n return wrap((...values: any[]) => {\n key in this ? (this as any)[key](...values) : this.set(key, values[0]);\n });\n };\n\n this.methods.forEach((name) => {\n decorator[pascalCase(name)] = wrapKey(name);\n });\n\n return decorator as unknown as T;\n }\n\n toObject(): any {\n return [...this.entries()].reduce((obj, [key, value]) => {\n return {\n ...obj,\n [key]: value\n };\n }, {});\n }\n\n getMergedKey(key: string, defaultValue: any) {\n let value = this.get(key) || defaultValue;\n\n if (!value) {\n return;\n }\n\n if (this.decoratorType === DecoratorTypes.CLASS) {\n value = {\n ...value,\n ...(defaultValue || {})\n };\n }\n\n return {\n ...(defaultValue || {}),\n ...value\n };\n }\n\n protected bind(args: DecoratorParameters, decorator: any) {\n this.entity = JsonEntityStore.from(...args);\n\n this.beforeInit();\n this.onInit(args, decorator);\n this.afterInit();\n }\n\n protected onInit(args: DecoratorParameters, decorator: any): void {\n this.forEach((value, key) => {\n this.onMapKey(key, value);\n });\n }\n\n protected onMapKey(key: string, value: any): void {\n this.entity.set(key, value);\n }\n\n protected runActions() {\n this.actions.forEach((action: any) => {\n action(this);\n });\n\n return this;\n }\n\n protected beforeInit() {}\n\n protected afterInit() {}\n}\n"]}
@@ -4,13 +4,10 @@ import { JsonEntityStore } from "./JsonEntityStore.js";
4
4
  import { JsonSchema } from "./JsonSchema.js";
5
5
  import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
6
6
  let JsonClassStore = class JsonClassStore extends JsonEntityStore {
7
- constructor() {
8
- super(...arguments);
9
- /**
10
- * List of children JsonEntityStore (properties or methods or params)
11
- */
12
- this.children = new Map();
13
- }
7
+ /**
8
+ * List of children JsonEntityStore (properties or methods or params)
9
+ */
10
+ children = new Map();
14
11
  get path() {
15
12
  return this.store.get("path", "/");
16
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"JsonClassStore.js","sourceRoot":"","sources":["../../../src/domain/JsonClassStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAC,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAG7E,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,eAAe;IAAnD;;QACE;;WAEG;QACM,aAAQ,GAA8D,IAAI,GAAG,EAAE,CAAC;IAqB3F,CAAC;IAnBC,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,IAAI,CAAC,IAAY;QACnB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAES,KAAK;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC7B;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAzBY,cAAc;IAD1B,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC;GAC7B,cAAc,CAyB1B;SAzBY,cAAc","sourcesContent":["import {DecoratorTypes} from \"@tsed/core\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport type {JsonPropertyStore} from \"./JsonPropertyStore\";\nimport {JsonEntityStore, JsonEntityStoreOptions} from \"./JsonEntityStore\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\n\n@JsonEntityComponent(DecoratorTypes.CLASS)\nexport class JsonClassStore extends JsonEntityStore {\n /**\n * List of children JsonEntityStore (properties or methods or params)\n */\n readonly children: Map<string | number, JsonMethodStore | JsonPropertyStore> = new Map();\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\n }\n\n protected build() {\n if (!this._type) {\n this.buildType(this.target);\n }\n\n this._type = this._type || Object;\n\n this._schema = JsonSchema.from({\n type: this.type\n });\n }\n}\n"]}
1
+ {"version":3,"file":"JsonClassStore.js","sourceRoot":"","sources":["../../../src/domain/JsonClassStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAC;AAG1C,OAAO,EAAC,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAG7E,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,eAAe;IACjD;;OAEG;IACM,QAAQ,GAA8D,IAAI,GAAG,EAAE,CAAC;IAEzF,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,IAAI,CAAC,IAAY;QACnB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAES,KAAK;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACf,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC7B;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAzBY,cAAc;IAD1B,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC;GAC7B,cAAc,CAyB1B;SAzBY,cAAc","sourcesContent":["import {DecoratorTypes} from \"@tsed/core\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport type {JsonPropertyStore} from \"./JsonPropertyStore\";\nimport {JsonEntityStore, JsonEntityStoreOptions} from \"./JsonEntityStore\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\n\n@JsonEntityComponent(DecoratorTypes.CLASS)\nexport class JsonClassStore extends JsonEntityStore {\n /**\n * List of children JsonEntityStore (properties or methods or params)\n */\n readonly children: Map<string | number, JsonMethodStore | JsonPropertyStore> = new Map();\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\n }\n\n protected build() {\n if (!this._type) {\n this.buildType(this.target);\n }\n\n this._type = this._type || Object;\n\n this._schema = JsonSchema.from({\n type: this.type\n });\n }\n}\n"]}
@@ -4,8 +4,44 @@ import { classOf, decoratorTypeOf, descriptorOf, isArrayOrArrayClass, isClass, i
4
4
  */
5
5
  export const JsonEntitiesContainer = new Map();
6
6
  export class JsonEntityStore {
7
+ /**
8
+ * Original property key decorated by the decorator
9
+ */
10
+ propertyKey;
11
+ /**
12
+ * Alias of the property
13
+ */
14
+ propertyName;
15
+ /**
16
+ * Parameter index
17
+ */
18
+ index;
19
+ /**
20
+ * Method's descriptor
21
+ */
22
+ descriptor;
23
+ /**
24
+ * Decorator type used to declare the JsonSchemaStore.
25
+ */
26
+ decoratorType;
27
+ /**
28
+ * Type of the collection (Array, Map, Set, etc...)
29
+ */
30
+ collectionType;
31
+ token;
32
+ store;
33
+ isStore = true;
34
+ parent;
35
+ target;
36
+ /**
37
+ *
38
+ */
39
+ _type;
40
+ /**
41
+ * Ref to JsonSchema
42
+ */
43
+ _schema;
7
44
  constructor(options) {
8
- this.isStore = true;
9
45
  const { target, propertyKey, descriptor, index, decoratorType } = options;
10
46
  this.target = target;
11
47
  this.propertyKey = propertyKey;
@@ -155,6 +191,9 @@ export class JsonEntityStore {
155
191
  }
156
192
  }
157
193
  }
194
+ toString() {
195
+ return [this.targetName, this.propertyName, this.index].filter((o) => o !== undefined).join(":");
196
+ }
158
197
  static get(target, propertyKey, descriptor) {
159
198
  return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);
160
199
  }
@@ -1 +1 @@
1
- {"version":3,"file":"JsonEntityStore.js","sourceRoot":"","sources":["../../../src/domain/JsonEntityStore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EAEf,YAAY,EACZ,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,aAAa,EACb,2BAA2B,EAC3B,MAAM,EACN,WAAW,EACX,KAAK,EAEN,MAAM,YAAY,CAAC;AAOpB;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAyC,CAAC;AAiBtF,MAAM,OAAgB,eAAe;IAyCnC,YAAY,OAA+B;QAdlC,YAAO,GAAG,IAAI,CAAC;QAetB,MAAM,EAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAC,GAAG,OAAO,CAAC;QACxE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,WAAY,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAM,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,UAAU;QACZ,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACH,IAAI,YAAY;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;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AC/C;QAED,OAAO,KAAK,CAAC,GAAG,CAAI,iBAAiB,CAAE,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,UAAU,CAA8C,MAAW,EAAE,WAA4B;QACtG,OAAO,IAAI,CAAC,IAAI,CAAI,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,GAAG,CAAU,GAAW,EAAE,YAAkB;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAI,GAAG,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAW;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAIS,SAAS,CAAC,IAAS;QAC3B,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE;YACtB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAElB,wHAAwH;YACxH,IAAI,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBAC3C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;aACrB;SACF;IACH,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAAiB,EAAE,WAA4B,EAAE,UAAgB;QAC1E,OAAO,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC5E,CAAC;CACF","sourcesContent":["import {\n classOf,\n decoratorTypeOf,\n DecoratorTypes,\n descriptorOf,\n isArrayOrArrayClass,\n isClass,\n isCollection,\n isDate,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n nameOf,\n prototypeOf,\n Store,\n Type\n} from \"@tsed/core\";\nimport type {JsonSchema} from \"./JsonSchema\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport type {JsonClassStore} from \"./JsonClassStore\";\nimport type {JsonPropertyStore} from \"./JsonPropertyStore\";\nimport type {JsonParameterStore} from \"./JsonParameterStore\";\n\n/**\n * @ignore\n */\nexport const JsonEntitiesContainer = new Map<DecoratorTypes, Type<JsonEntityStore>>();\n\nexport interface JsonEntityStoreOptions {\n decoratorType: DecoratorTypes;\n target: Type<any>;\n propertyKey?: string | symbol;\n index?: number;\n descriptor?: any;\n type?: Type<any>;\n collectionType?: Type<any>;\n beforeMiddlewares?: Function[];\n middlewares?: Function[];\n afterMiddlewares?: Function[];\n\n [key: string]: any;\n}\n\nexport abstract class JsonEntityStore implements JsonEntityStoreOptions {\n /**\n * Original property key decorated by the decorator\n */\n readonly propertyKey: string | symbol;\n /**\n * Alias of the property\n */\n readonly propertyName: string;\n /**\n * Parameter index\n */\n readonly index: number;\n /**\n * Method's descriptor\n */\n readonly descriptor: number;\n /**\n * Decorator type used to declare the JsonSchemaStore.\n */\n readonly decoratorType: DecoratorTypes;\n /**\n * Type of the collection (Array, Map, Set, etc...)\n */\n public collectionType: Type<any>;\n public token: Type<any>;\n readonly store: Store;\n readonly isStore = true;\n readonly parent: JsonEntityStore;\n readonly target: Type<any>;\n /**\n *\n */\n protected _type: Type<any>;\n /**\n * Ref to JsonSchema\n */\n protected _schema: JsonSchema;\n\n [key: string]: any;\n\n constructor(options: JsonEntityStoreOptions) {\n const {target, propertyKey, descriptor, index, decoratorType} = options;\n this.target = target;\n this.propertyKey = propertyKey!;\n this.propertyName = String(propertyKey);\n this.descriptor = descriptor;\n this.index = index!;\n this.decoratorType = decoratorType;\n this.token = target;\n this.store = options.store;\n this.parent = this;\n }\n\n /**\n * Return the class name of the entity.\n * @returns {string}\n */\n get targetName(): string {\n return nameOf(this.token);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isCollection(): boolean {\n return !!this.collectionType;\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isArray() {\n return isArrayOrArrayClass(this.collectionType);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isPrimitive() {\n return isPrimitiveOrPrimitiveClass(this._type);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isDate() {\n return isDate(this.computedType);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isObject() {\n return isObject(this.computedType);\n }\n\n /**\n *\n */\n get isClass() {\n return isClass(this.computedType);\n }\n\n /**\n * Return the JsonSchema\n */\n get schema(): JsonSchema {\n return this._schema;\n }\n\n get nestedGenerics(): Type<any>[][] {\n return this.schema.nestedGenerics;\n }\n\n set nestedGenerics(nestedGenerics: Type<any>[][]) {\n this.schema.nestedGenerics = nestedGenerics;\n }\n\n /**\n *\n * @returns {Type<any>}\n */\n get type(): Type<any> | any {\n return this._type;\n }\n\n /**\n * Get original type without transformation\n * @param value\n */\n set type(value: Type<any> | any) {\n this._type = value;\n this.build();\n }\n\n /**\n * Return the itemSchema computed type. if the type is a function used for recursive model, the function will be called to\n * get the right type.\n */\n get computedType() {\n return this.itemSchema.getComputedType();\n }\n\n get itemSchema(): JsonSchema {\n return this.isCollection ? this.schema.itemSchema() : this.schema;\n }\n\n get parentSchema(): JsonSchema {\n return this.parent.schema;\n }\n\n /**\n *\n * @param target\n */\n static from<T extends JsonClassStore = JsonClassStore>(target: Type<any>): T;\n static from<T extends JsonPropertyStore = JsonPropertyStore>(target: Type<any> | any, propertyKey: string | symbol): T;\n static from<T extends JsonParameterStore = JsonParameterStore>(target: Type<any> | any, propertyKey: string | symbol, index: number): T;\n static from<T extends JsonMethodStore = JsonMethodStore>(\n target: Type<any> | any,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor\n ): T;\n static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T;\n static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T {\n if (args[0].isStore) {\n return args[0] as T;\n }\n\n const target = args[0];\n\n if (args.length > 1) {\n args[0] = prototypeOf(args[0]);\n }\n\n const store = Store.from(...args);\n\n if (!store.has(\"JsonEntityStore\")) {\n const decoratorType = decoratorTypeOf(args);\n const entityStore = JsonEntitiesContainer.get(decoratorType);\n\n // istanbul ignore next\n if (!entityStore) {\n throw Error(\"Unsupported json entity type\");\n }\n\n const jsonSchemaStore = new entityStore({\n store,\n decoratorType,\n target: classOf(target),\n propertyKey: args[1],\n index: typeof args[2] === \"number\" ? args[2] : undefined,\n descriptor: typeof args[2] === \"object\" ? args[2] : undefined\n });\n\n jsonSchemaStore.build();\n\n store.set(\"JsonEntityStore\", jsonSchemaStore);\n }\n\n return store.get<T>(\"JsonEntityStore\")!;\n }\n\n static fromMethod<T extends JsonMethodStore = JsonMethodStore>(target: any, propertyKey: string | symbol) {\n return this.from<T>(target, propertyKey, descriptorOf(target, propertyKey));\n }\n\n get<T = any>(key: string, defaultValue?: any) {\n return this.store.get<T>(key, defaultValue);\n }\n\n set(key: string, value?: any) {\n return this.store.set(key, value);\n }\n\n protected abstract build(): void;\n\n protected buildType(type: any) {\n if (isCollection(type)) {\n this.collectionType = type;\n } else {\n this._type = type;\n\n // issue #1534: Enum metadata stored as plain object instead of String (see: https://github.com/tsedio/tsed/issues/1534)\n if (this._type && isPlainObject(this._type)) {\n this._type = String;\n }\n }\n }\n\n static get(target: Type<any>, propertyKey: string | symbol, descriptor?: any) {\n return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);\n }\n}\n"]}
1
+ {"version":3,"file":"JsonEntityStore.js","sourceRoot":"","sources":["../../../src/domain/JsonEntityStore.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EAEf,YAAY,EACZ,mBAAmB,EACnB,OAAO,EACP,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,aAAa,EACb,2BAA2B,EAC3B,MAAM,EACN,WAAW,EACX,KAAK,EAEN,MAAM,YAAY,CAAC;AAOpB;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAyC,CAAC;AAiBtF,MAAM,OAAgB,eAAe;IAC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tG,OAAO,IAAI,CAAC,IAAI,CAAI,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,GAAG,CAAU,GAAW,EAAE,YAAkB;QAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAI,GAAG,EAAE,YAAY,CAAC,CAAC;IAC9C,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KAAW;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAIS,SAAS,CAAC,IAAS;QAC3B,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE;YACtB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;SAC5B;aAAM;YACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAElB,wHAAwH;YACxH,IAAI,IAAI,CAAC,KAAK,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;gBAC3C,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC;aACrB;SACF;IACH,CAAC;IAED,QAAQ;QACN,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnG,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAAiB,EAAE,WAA4B,EAAE,UAAgB;QAC1E,OAAO,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;IAC5E,CAAC;CACF","sourcesContent":["import {\n classOf,\n decoratorTypeOf,\n DecoratorTypes,\n descriptorOf,\n isArrayOrArrayClass,\n isClass,\n isCollection,\n isDate,\n isObject,\n isPlainObject,\n isPrimitiveOrPrimitiveClass,\n nameOf,\n prototypeOf,\n Store,\n Type\n} from \"@tsed/core\";\nimport type {JsonSchema} from \"./JsonSchema\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport type {JsonClassStore} from \"./JsonClassStore\";\nimport type {JsonPropertyStore} from \"./JsonPropertyStore\";\nimport type {JsonParameterStore} from \"./JsonParameterStore\";\n\n/**\n * @ignore\n */\nexport const JsonEntitiesContainer = new Map<DecoratorTypes, Type<JsonEntityStore>>();\n\nexport interface JsonEntityStoreOptions {\n decoratorType: DecoratorTypes;\n target: Type<any>;\n propertyKey?: string | symbol;\n index?: number;\n descriptor?: any;\n type?: Type<any>;\n collectionType?: Type<any>;\n beforeMiddlewares?: Function[];\n middlewares?: Function[];\n afterMiddlewares?: Function[];\n\n [key: string]: any;\n}\n\nexport abstract class JsonEntityStore implements JsonEntityStoreOptions {\n /**\n * Original property key decorated by the decorator\n */\n readonly propertyKey: string | symbol;\n /**\n * Alias of the property\n */\n readonly propertyName: string;\n /**\n * Parameter index\n */\n readonly index: number;\n /**\n * Method's descriptor\n */\n readonly descriptor: number;\n /**\n * Decorator type used to declare the JsonSchemaStore.\n */\n readonly decoratorType: DecoratorTypes;\n /**\n * Type of the collection (Array, Map, Set, etc...)\n */\n public collectionType: Type<any>;\n public token: Type<any>;\n readonly store: Store;\n readonly isStore = true;\n readonly parent: JsonEntityStore;\n readonly target: Type<any>;\n /**\n *\n */\n protected _type: Type<any>;\n /**\n * Ref to JsonSchema\n */\n protected _schema: JsonSchema;\n\n [key: string]: any;\n\n constructor(options: JsonEntityStoreOptions) {\n const {target, propertyKey, descriptor, index, decoratorType} = options;\n this.target = target;\n this.propertyKey = propertyKey!;\n this.propertyName = String(propertyKey);\n this.descriptor = descriptor;\n this.index = index!;\n this.decoratorType = decoratorType;\n this.token = target;\n this.store = options.store;\n this.parent = this;\n }\n\n /**\n * Return the class name of the entity.\n * @returns {string}\n */\n get targetName(): string {\n return nameOf(this.token);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isCollection(): boolean {\n return !!this.collectionType;\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isArray() {\n return isArrayOrArrayClass(this.collectionType);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isPrimitive() {\n return isPrimitiveOrPrimitiveClass(this._type);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isDate() {\n return isDate(this.computedType);\n }\n\n /**\n *\n * @returns {boolean}\n */\n get isObject() {\n return isObject(this.computedType);\n }\n\n /**\n *\n */\n get isClass() {\n return isClass(this.computedType);\n }\n\n /**\n * Return the JsonSchema\n */\n get schema(): JsonSchema {\n return this._schema;\n }\n\n get nestedGenerics(): Type<any>[][] {\n return this.schema.nestedGenerics;\n }\n\n set nestedGenerics(nestedGenerics: Type<any>[][]) {\n this.schema.nestedGenerics = nestedGenerics;\n }\n\n /**\n *\n * @returns {Type<any>}\n */\n get type(): Type<any> | any {\n return this._type;\n }\n\n /**\n * Get original type without transformation\n * @param value\n */\n set type(value: Type<any> | any) {\n this._type = value;\n this.build();\n }\n\n /**\n * Return the itemSchema computed type. if the type is a function used for recursive model, the function will be called to\n * get the right type.\n */\n get computedType() {\n return this.itemSchema.getComputedType();\n }\n\n get itemSchema(): JsonSchema {\n return this.isCollection ? this.schema.itemSchema() : this.schema;\n }\n\n get parentSchema(): JsonSchema {\n return this.parent.schema;\n }\n\n /**\n *\n * @param target\n */\n static from<T extends JsonClassStore = JsonClassStore>(target: Type<any>): T;\n static from<T extends JsonPropertyStore = JsonPropertyStore>(target: Type<any> | any, propertyKey: string | symbol): T;\n static from<T extends JsonParameterStore = JsonParameterStore>(target: Type<any> | any, propertyKey: string | symbol, index: number): T;\n static from<T extends JsonMethodStore = JsonMethodStore>(\n target: Type<any> | any,\n propertyKey: string | symbol,\n descriptor: PropertyDescriptor\n ): T;\n static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T;\n static from<T extends JsonEntityStore = JsonEntityStore>(...args: any[]): T {\n if (args[0].isStore) {\n return args[0] as T;\n }\n\n const target = args[0];\n\n if (args.length > 1) {\n args[0] = prototypeOf(args[0]);\n }\n\n const store = Store.from(...args);\n\n if (!store.has(\"JsonEntityStore\")) {\n const decoratorType = decoratorTypeOf(args);\n const entityStore = JsonEntitiesContainer.get(decoratorType);\n\n // istanbul ignore next\n if (!entityStore) {\n throw Error(\"Unsupported json entity type\");\n }\n\n const jsonSchemaStore = new entityStore({\n store,\n decoratorType,\n target: classOf(target),\n propertyKey: args[1],\n index: typeof args[2] === \"number\" ? args[2] : undefined,\n descriptor: typeof args[2] === \"object\" ? args[2] : undefined\n });\n\n jsonSchemaStore.build();\n\n store.set(\"JsonEntityStore\", jsonSchemaStore);\n }\n\n return store.get<T>(\"JsonEntityStore\")!;\n }\n\n static fromMethod<T extends JsonMethodStore = JsonMethodStore>(target: any, propertyKey: string | symbol) {\n return this.from<T>(target, propertyKey, descriptorOf(target, propertyKey));\n }\n\n get<T = any>(key: string, defaultValue?: any) {\n return this.store.get<T>(key, defaultValue);\n }\n\n set(key: string, value?: any) {\n return this.store.set(key, value);\n }\n\n protected abstract build(): void;\n\n protected buildType(type: any) {\n if (isCollection(type)) {\n this.collectionType = type;\n } else {\n this._type = type;\n\n // issue #1534: Enum metadata stored as plain object instead of String (see: https://github.com/tsedio/tsed/issues/1534)\n if (this._type && isPlainObject(this._type)) {\n this._type = String;\n }\n }\n }\n\n toString() {\n return [this.targetName, this.propertyName, this.index].filter((o) => o !== undefined).join(\":\");\n }\n\n static get(target: Type<any>, propertyKey: string | symbol, descriptor?: any) {\n return JsonEntityStore.from(prototypeOf(target), propertyKey, descriptor);\n }\n}\n"]}
@@ -2,9 +2,10 @@ import { nameOf } from "@tsed/core";
2
2
  import { execMapper } from "../registries/JsonSchemaMapperContainer.js";
3
3
  import { getJsonEntityStore } from "../utils/getJsonEntityStore.js";
4
4
  export class JsonLazyRef {
5
+ getType;
6
+ isLazyRef = true;
5
7
  constructor(getType) {
6
8
  this.getType = getType;
7
- this.isLazyRef = true;
8
9
  }
9
10
  get target() {
10
11
  return this.getType();
@@ -1 +1 @@
1
- {"version":3,"file":"JsonLazyRef.js","sourceRoot":"","sources":["../../../src/domain/JsonLazyRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AAExC,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,WAAW;IAGtB,YAAqB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAFpC,cAAS,GAAG,IAAI,CAAC;IAEsB,CAAC;IAEjD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;IACnD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,OAA2B;QAChC,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {getJsonEntityStore} from \"../utils/getJsonEntityStore\";\n\nexport class JsonLazyRef {\n readonly isLazyRef = true;\n\n constructor(readonly getType: () => Type<any>) {}\n\n get target() {\n return this.getType();\n }\n\n get schema() {\n return getJsonEntityStore(this.getType()).schema;\n }\n\n get name() {\n return nameOf(this.getType());\n }\n\n toJSON(options?: JsonSchemaOptions) {\n return this.getType() && execMapper(\"schema\", this.schema, options);\n }\n}\n"]}
1
+ {"version":3,"file":"JsonLazyRef.js","sourceRoot":"","sources":["../../../src/domain/JsonLazyRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAO,MAAM,YAAY,CAAC;AAExC,OAAO,EAAC,UAAU,EAAC,MAAM,yCAAyC,CAAC;AACnE,OAAO,EAAC,kBAAkB,EAAC,MAAM,6BAA6B,CAAC;AAE/D,MAAM,OAAO,WAAW;IAGD;IAFZ,SAAS,GAAG,IAAI,CAAC;IAE1B,YAAqB,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAEjD,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC;IACnD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAC,OAA2B;QAChC,OAAO,IAAI,CAAC,OAAO,EAAE,IAAI,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC;CACF","sourcesContent":["import {nameOf, Type} from \"@tsed/core\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {execMapper} from \"../registries/JsonSchemaMapperContainer\";\nimport {getJsonEntityStore} from \"../utils/getJsonEntityStore\";\n\nexport class JsonLazyRef {\n readonly isLazyRef = true;\n\n constructor(readonly getType: () => Type<any>) {}\n\n get target() {\n return this.getType();\n }\n\n get schema() {\n return getJsonEntityStore(this.getType()).schema;\n }\n\n get name() {\n return nameOf(this.getType());\n }\n\n toJSON(options?: JsonSchemaOptions) {\n return this.getType() && execMapper(\"schema\", this.schema, options);\n }\n}\n"]}
@@ -5,24 +5,24 @@ import { JsonOperation } from "./JsonOperation.js";
5
5
  import { JsonSchema } from "./JsonSchema.js";
6
6
  import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent.js";
7
7
  let JsonMethodStore = class JsonMethodStore extends JsonEntityStore {
8
+ parent = JsonEntityStore.from(this.target);
9
+ middlewares = [];
10
+ beforeMiddlewares = [];
11
+ afterMiddlewares = [];
12
+ /**
13
+ * Ref to JsonOperation when the decorated object is a method.
14
+ */
15
+ operation = new JsonOperation();
16
+ /**
17
+ * List of children JsonEntityStore (properties or methods or params)
18
+ */
19
+ children = new Map();
8
20
  constructor(options) {
9
21
  super({
10
22
  store: Store.fromMethod(options.target, options.propertyKey),
11
23
  descriptor: descriptorOf(options.target, options.propertyKey),
12
24
  ...options
13
25
  });
14
- this.parent = JsonEntityStore.from(this.target);
15
- this.middlewares = [];
16
- this.beforeMiddlewares = [];
17
- this.afterMiddlewares = [];
18
- /**
19
- * Ref to JsonOperation when the decorated object is a method.
20
- */
21
- this.operation = new JsonOperation();
22
- /**
23
- * List of children JsonEntityStore (properties or methods or params)
24
- */
25
- this.children = new Map();
26
26
  const { beforeMiddlewares = [], middlewares = [], afterMiddlewares = [] } = options;
27
27
  this.after(afterMiddlewares);
28
28
  this.before(beforeMiddlewares);