@tsed/schema 6.75.12 → 6.76.0

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.
@@ -2011,11 +2011,6 @@ class JsonEntityStore extends Entity {
2011
2011
  */
2012
2012
 
2013
2013
  this.children = new Map();
2014
- /**
2015
- * Path used to generate open spec.
2016
- */
2017
-
2018
- this.path = "/";
2019
2014
  this.store = options.store;
2020
2015
  /* istanbul ignore next */
2021
2016
 
@@ -2025,6 +2020,14 @@ class JsonEntityStore extends Entity {
2025
2020
 
2026
2021
  this.build();
2027
2022
  }
2023
+
2024
+ get path() {
2025
+ return this.store.get("path", "/");
2026
+ }
2027
+
2028
+ set path(path) {
2029
+ this.store.set("path", path);
2030
+ }
2028
2031
  /**
2029
2032
  * Return the JsonSchema
2030
2033
  */
@@ -2183,6 +2186,10 @@ class JsonEntityStore extends Entity {
2183
2186
  return this.from(target, propertyKey, descriptorOf(target, propertyKey));
2184
2187
  }
2185
2188
 
2189
+ get(key, defaultValue) {
2190
+ return this.store.get(key, defaultValue);
2191
+ }
2192
+
2186
2193
  getResponseOptions(status, contentType = "application/json") {
2187
2194
  var _this$operation, _this$operation$getRe;
2188
2195
 
@@ -2927,6 +2934,35 @@ function getProperties(target, options = {}) {
2927
2934
  return map;
2928
2935
  }
2929
2936
 
2937
+ class JsonOperationPathsMap extends Map {
2938
+ constructor() {
2939
+ super(...arguments);
2940
+
2941
+ this.getKey = (method, path) => `${method}-${path}`;
2942
+ }
2943
+
2944
+ setOperationPath(operationPath) {
2945
+ if (operationPath.method !== OperationMethods.CUSTOM) {
2946
+ const key = this.getKey(operationPath.method, operationPath.path);
2947
+ this.updateFinalRouteState(key);
2948
+ this.updateFinalRouteState(this.getKey(OperationMethods.ALL, operationPath.path));
2949
+ this.setFinalRoute(key, operationPath);
2950
+ }
2951
+ }
2952
+
2953
+ updateFinalRouteState(key) {
2954
+ if (this.has(key)) {
2955
+ this.get(key).isFinal = false;
2956
+ }
2957
+ }
2958
+
2959
+ setFinalRoute(key, operationPath) {
2960
+ this.set(key, operationPath);
2961
+ operationPath.isFinal = true;
2962
+ }
2963
+
2964
+ }
2965
+
2930
2966
  /**
2931
2967
  * @ignore
2932
2968
  */
@@ -2936,6 +2972,7 @@ function getOperationsStores(target) {
2936
2972
 
2937
2973
  if (!store.$operations) {
2938
2974
  const stores = getInheritedStores(store);
2975
+ const operationPaths = new JsonOperationPathsMap();
2939
2976
  store.$operations = new Map();
2940
2977
  stores.forEach(currentStore => {
2941
2978
  currentStore.children.forEach(propStore => {
@@ -2944,11 +2981,94 @@ function getOperationsStores(target) {
2944
2981
  }
2945
2982
  });
2946
2983
  });
2984
+ store.$operations.forEach(store => {
2985
+ var _store$operation;
2986
+
2987
+ (_store$operation = store.operation) == null ? void 0 : _store$operation.operationPaths.forEach(operationPath => {
2988
+ operationPaths.setOperationPath(operationPath);
2989
+ });
2990
+ });
2991
+ operationPaths.clear();
2947
2992
  }
2948
2993
 
2949
2994
  return store.$operations;
2950
2995
  }
2951
2996
 
2997
+ function concatPath(basePath, path) {
2998
+ return ((basePath || "") + (path || "")).replace(/\/\//gi, "/");
2999
+ }
3000
+
3001
+ class JsonOperationRoute {
3002
+ constructor(options) {
3003
+ Object.assign(this, options);
3004
+ }
3005
+
3006
+ get path() {
3007
+ var _this$operationPath;
3008
+
3009
+ return (_this$operationPath = this.operationPath) == null ? void 0 : _this$operationPath.path;
3010
+ }
3011
+
3012
+ get fullPath() {
3013
+ return concatPath(this.basePath, this.path);
3014
+ }
3015
+
3016
+ get method() {
3017
+ var _this$operationPath2;
3018
+
3019
+ return ((_this$operationPath2 = this.operationPath) == null ? void 0 : _this$operationPath2.method) || "USE";
3020
+ }
3021
+
3022
+ get isFinal() {
3023
+ var _this$operationPath3;
3024
+
3025
+ return !!((_this$operationPath3 = this.operationPath) != null && _this$operationPath3.isFinal);
3026
+ }
3027
+
3028
+ get propertyKey() {
3029
+ return this.endpoint.propertyKey;
3030
+ }
3031
+
3032
+ get store() {
3033
+ return this.endpoint.store;
3034
+ }
3035
+
3036
+ }
3037
+
3038
+ function getOperationsRoutes(token, options = {}) {
3039
+ const store = token.isStore ? token : getJsonEntityStore(token);
3040
+ const basePath = ((options.basePath || "") + (store.path || "")).replace(/\/\//gi, "/");
3041
+ let operationsRoutes = [];
3042
+
3043
+ if (options.withChildren) {
3044
+ const children = store.get("childrenControllers", []);
3045
+ operationsRoutes = children.reduce((operationsRoutes, token) => {
3046
+ return operationsRoutes.concat(getOperationsRoutes(token, _extends({}, options, {
3047
+ basePath
3048
+ })));
3049
+ }, operationsRoutes);
3050
+ }
3051
+
3052
+ return [...getOperationsStores(token).values()].reduce((routes, endpoint) => {
3053
+ const {
3054
+ operation
3055
+ } = endpoint;
3056
+
3057
+ if (operation) {
3058
+ operation.operationPaths.forEach(operationPath => {
3059
+ routes.push(new JsonOperationRoute({
3060
+ basePath,
3061
+ token,
3062
+ endpoint,
3063
+ operationPath
3064
+ }));
3065
+ });
3066
+ }
3067
+
3068
+ return routes;
3069
+ }, operationsRoutes);
3070
+ }
3071
+
2952
3072
  /**
2953
3073
  * Return a sanitized path
2954
3074
  * @param path
@@ -3589,6 +3709,54 @@ function getStatusModel(status) {
3589
3709
  return statusesModel.get(status);
3590
3710
  }
3591
3711
 
3712
+ /**
3713
+ * Decorator util to compose another decorator. See @@Description@@ decorator implementation for more details.
3714
+ *
3715
+ * ## Usage
3716
+ *
3717
+ * ```typescript
3718
+ * export function Description(description: any) {
3719
+ * return JsonEntityFn((entity: JsonEntityStore, args: DecoratorParameters) => {
3720
+ * entity.itemSchema.description(description)
3721
+ * });
3722
+ * }
3723
+ * ```
3724
+ *
3725
+ * @param fn
3726
+ * @decorator
3727
+ * @utils
3728
+ * @model
3729
+ */
3730
+
3731
+ function JsonEntityFn(fn) {
3732
+ return (...parameters) => {
3733
+ const result = fn(getJsonEntityStore(...parameters), parameters);
3734
+
3735
+ if (typeof result === "function") {
3736
+ result(...parameters);
3737
+ }
3738
+ };
3739
+ }
3740
+
3741
+ /**
3742
+ * Add Children class to compose routes
3743
+ *
3744
+ * @decorator
3745
+ * @swagger
3746
+ * @schema
3747
+ * @classDecorator
3748
+ * @param children
3749
+ */
3750
+
3751
+ function Children(...children) {
3752
+ return JsonEntityFn(store => {
3753
+ store.store.set("childrenControllers", children);
3754
+ children.forEach(childToken => {
3755
+ Store.from(childToken).set("parentController", store.token);
3756
+ });
3757
+ });
3758
+ }
3759
+
3592
3760
  /**
3593
3761
  * Set the type of the item collection. The possible value is String, Boolean, Number, Date, Object, Class, etc...
3594
3762
  *
@@ -3723,35 +3891,6 @@ function CollectionContains(type) {
3723
3891
  return CollectionOf(type).Contains();
3724
3892
  }
3725
3893
 
3726
- /**
3727
- * Decorator util to compose another decorator. See @@Description@@ decorator implementation for more details.
3728
- *
3729
- * ## Usage
3730
- *
3731
- * ```typescript
3732
- * export function Description(description: any) {
3733
- * return JsonEntityFn((entity: JsonEntityStore, args: DecoratorParameters) => {
3734
- * entity.itemSchema.description(description)
3735
- * });
3736
- * }
3737
- * ```
3738
- *
3739
- * @param fn
3740
- * @decorator
3741
- * @utils
3742
- * @model
3743
- */
3744
-
3745
- function JsonEntityFn(fn) {
3746
- return (...parameters) => {
3747
- const result = fn(getJsonEntityStore(...parameters), parameters);
3748
-
3749
- if (typeof result === "function") {
3750
- result(...parameters);
3751
- }
3752
- };
3753
- }
3754
-
3755
3894
  /**
3756
3895
  * The value `maxItems` MUST be a non-negative integer.
3757
3896
  *
@@ -7778,5 +7917,5 @@ function JsonEntityComponent(type) {
7778
7917
  };
7779
7918
  }
7780
7919
 
7781
- export { AdditionalProperties, All, AllOf, Allow, Any, AnyOf, ArrayOf, CollectionContains, CollectionOf, Const, Consumes, ContentType, CustomKey, CustomKeys, DateFormat, DateTime, Default, Delete, Deprecated, Description, Email, Enum, Example, Examples, ExclusiveMaximum, ExclusiveMinimum, For, Format, ForwardGroups, GenericOf, Generics, Get, Groups, HTTP_METHODS, HTTP_STATUS_MESSAGES, Head, Header, Hidden, Ignore, In, Integer, JSON_TYPES, JsonEntityComponent, JsonEntityFn, JsonEntityStore, JsonFormatTypes, JsonLazyRef, JsonMap, JsonMedia, JsonOperation, JsonParameter, JsonParameterTypes, JsonRequestBody, JsonResponse, JsonSchema, Location, MapOf, Max, MaxItems, MaxLength, MaxProperties, Maximum, Min, MinItems, MinLength, MinProperties, Minimum, MultipleOf, Name, Nullable, OneOf, OperationId, OperationMethods, OperationPath, Optional, Options, Partial, Patch, Path, Pattern, Post, Produces, Property, Put, ReadOnly, Redirect, Required, RequiredGroups, Returns, Route, Schema, Security, SpecTypes, Status, Summary, Tags, TimeFormat, Title, UniqueItems, Uri, Url, WriteOnly, allOf, alterIgnore, any, anyOf, array, boolean, date, datetime, defineStatusModel, email, formatParameterType, from, getGenericsMap, getJsonSchema, getJsonType, getOperationsStores, getProperties, getPropertiesStores, getSpec, getStatusConstant, getStatusMessage, getStatusModel, integer, isParameterType, isRedirectionStatus, isSuccessStatus, lazyRef, map, mapGenericsOptions, mapHeaders, mergeSpec, number, object, oneOf, parameters, popGenerics, schemesReducer, security, set, string, tagsReducer, time, uri, url };
7920
+ export { AdditionalProperties, All, AllOf, Allow, Any, AnyOf, ArrayOf, Children, CollectionContains, CollectionOf, Const, Consumes, ContentType, CustomKey, CustomKeys, DateFormat, DateTime, Default, Delete, Deprecated, Description, Email, Enum, Example, Examples, ExclusiveMaximum, ExclusiveMinimum, For, Format, ForwardGroups, GenericOf, Generics, Get, Groups, HTTP_METHODS, HTTP_STATUS_MESSAGES, Head, Header, Hidden, Ignore, In, Integer, JSON_TYPES, JsonEntityComponent, JsonEntityFn, JsonEntityStore, JsonFormatTypes, JsonLazyRef, JsonMap, JsonMedia, JsonOperation, JsonOperationRoute, JsonParameter, JsonParameterTypes, JsonRequestBody, JsonResponse, JsonSchema, Location, MapOf, Max, MaxItems, MaxLength, MaxProperties, Maximum, Min, MinItems, MinLength, MinProperties, Minimum, MultipleOf, Name, Nullable, OneOf, OperationId, OperationMethods, OperationPath, Optional, Options, Partial, Patch, Path, Pattern, Post, Produces, Property, Put, ReadOnly, Redirect, Required, RequiredGroups, Returns, Route, Schema, Security, SpecTypes, Status, Summary, Tags, TimeFormat, Title, UniqueItems, Uri, Url, WriteOnly, allOf, alterIgnore, any, anyOf, array, boolean, concatPath, date, datetime, defineStatusModel, email, formatParameterType, from, getGenericsMap, getJsonSchema, getJsonType, getOperationsRoutes, getOperationsStores, getProperties, getPropertiesStores, getSpec, getStatusConstant, getStatusMessage, getStatusModel, integer, isParameterType, isRedirectionStatus, isSuccessStatus, lazyRef, map, mapGenericsOptions, mapHeaders, mergeSpec, number, object, oneOf, parameters, popGenerics, schemesReducer, security, set, string, tagsReducer, time, uri, url };
7782
7921
  //# sourceMappingURL=index.modern.js.map