@tsed/schema 6.72.2 → 6.73.2

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.
@@ -1,5 +1,5 @@
1
1
  import { constantCase, pascalCase, camelCase } from 'change-case';
2
- import { Store, decoratorTypeOf, nameOf, isFunction, cleanObject, isPromise, isClass, isSymbol, isPrimitiveOrPrimitiveClass, isClassObject, isDate, isCollection, classOf, isArrowFn, primitiveOf, isArray, Hooks, uniq, isObject, uniqBy, deepMerge, toMap, Entity, DecoratorTypes, descriptorOf, Metadata, isPrimitiveClass, ancestorsOf, mergeReducerBuilder, UnsupportedDecoratorType, decorateMethodsOf, isString, isPlainObject, isNumber, useDecorators, StoreSet } from '@tsed/core';
2
+ import { Store, decoratorTypeOf, nameOf, isFunction, cleanObject, isPromise, isClass, isSymbol, isPrimitiveOrPrimitiveClass, isClassObject, isDate, isCollection, classOf, isArrowFn, primitiveOf, isArray, Hooks, uniq, isObject, uniqBy, deepMerge, toMap, Entity, DecoratorTypes, descriptorOf, Metadata, isPlainObject, isPrimitiveClass, ancestorsOf, mergeReducerBuilder, UnsupportedDecoratorType, decorateMethodsOf, isString, isNumber, useDecorators, StoreSet } from '@tsed/core';
3
3
  import micromatch from 'micromatch';
4
4
 
5
5
  const HTTP_STATUS_MESSAGES = {
@@ -78,6 +78,21 @@ function getStatusMessage(status) {
78
78
  return HTTP_STATUS_MESSAGES[status];
79
79
  }
80
80
 
81
+ const HTTP_METHODS = ["all", "checkout", "connect", "copy", "delete", "get", "head", "lock", "merge", "mkactivity", "mkcol", "move", "m-search", "notify", "options", "param", "patch", "post", "propfind", "propatch", "purge", "put", "report", "search", "subscribe", "trace", "unlock", "unsuscribe"];
82
+ var OperationMethods;
83
+
84
+ (function (OperationMethods) {
85
+ OperationMethods["ALL"] = "ALL";
86
+ OperationMethods["GET"] = "GET";
87
+ OperationMethods["POST"] = "POST";
88
+ OperationMethods["PUT"] = "PUT";
89
+ OperationMethods["PATCH"] = "PATCH";
90
+ OperationMethods["HEAD"] = "HEAD";
91
+ OperationMethods["DELETE"] = "DELETE";
92
+ OperationMethods["OPTIONS"] = "OPTIONS";
93
+ OperationMethods["CUSTOM"] = "CUSTOM";
94
+ })(OperationMethods || (OperationMethods = {}));
95
+
81
96
  function _extends() {
82
97
  _extends = Object.assign || function (target) {
83
98
  for (var i = 1; i < arguments.length; i++) {
@@ -2202,7 +2217,11 @@ class JsonEntityStore extends Entity {
2202
2217
  if (isCollection(type)) {
2203
2218
  this.collectionType = type;
2204
2219
  } else {
2205
- this._type = type;
2220
+ this._type = type; // issue #1534: Enum metadata stored as plain object instead of String (see: https://github.com/tsedio/tsed/issues/1534)
2221
+
2222
+ if (this._type && isPlainObject(this._type)) {
2223
+ this._type = String;
2224
+ }
2206
2225
  }
2207
2226
  }
2208
2227
 
@@ -4245,9 +4264,12 @@ function Consumes(...consumes) {
4245
4264
  */
4246
4265
 
4247
4266
  class DecoratorContext extends Map {
4248
- constructor() {
4249
- super(...arguments);
4267
+ constructor(opts = {}) {
4268
+ super();
4250
4269
  this.actions = [];
4270
+ Object.entries(opts).forEach(([key, value]) => {
4271
+ this.set(key, value);
4272
+ });
4251
4273
  }
4252
4274
 
4253
4275
  addAction(cb) {
@@ -4256,7 +4278,7 @@ class DecoratorContext extends Map {
4256
4278
  }
4257
4279
 
4258
4280
  build() {
4259
- const decorator = (...args) => this.onInit(args, decorator);
4281
+ const decorator = (...args) => this.bind(args, decorator);
4260
4282
 
4261
4283
  const wrap = cb => {
4262
4284
  return (...args) => {
@@ -4299,6 +4321,24 @@ class DecoratorContext extends Map {
4299
4321
  return _extends({}, defaultValue || {}, value);
4300
4322
  }
4301
4323
 
4324
+ bind(args, decorator) {
4325
+ this.entity = JsonEntityStore.from(...args);
4326
+ this.beforeInit();
4327
+ this.onInit(args, decorator);
4328
+ this.afterInit();
4329
+ this.clear();
4330
+ }
4331
+
4332
+ onInit(args, decorator) {
4333
+ this.forEach((value, key) => {
4334
+ this.onMapKey(key, value);
4335
+ });
4336
+ }
4337
+
4338
+ onMapKey(key, value) {
4339
+ this.entity.store.set(key, value);
4340
+ }
4341
+
4302
4342
  runActions() {
4303
4343
  this.actions.forEach(action => {
4304
4344
  action(this);
@@ -4306,6 +4346,10 @@ class DecoratorContext extends Map {
4306
4346
  return this;
4307
4347
  }
4308
4348
 
4349
+ beforeInit() {}
4350
+
4351
+ afterInit() {}
4352
+
4309
4353
  }
4310
4354
 
4311
4355
  /**
@@ -4467,9 +4511,9 @@ class ReturnDecoratorContext extends DecoratorContext {
4467
4511
 
4468
4512
  switch (type) {
4469
4513
  case DecoratorTypes.METHOD:
4470
- this.store = JsonEntityStore.from(...args);
4514
+ this.entity = JsonEntityStore.from(...args);
4471
4515
 
4472
- if (this.store.operation) {
4516
+ if (this.entity.operation) {
4473
4517
  this.map();
4474
4518
  }
4475
4519
 
@@ -4490,10 +4534,10 @@ class ReturnDecoratorContext extends DecoratorContext {
4490
4534
  map() {
4491
4535
  const model = this.get("model");
4492
4536
  const {
4493
- store,
4537
+ entity,
4494
4538
  decoratorType
4495
4539
  } = this;
4496
- const operation = this.store.operation;
4540
+ const operation = this.entity.operation;
4497
4541
  const currentStatus = this.getStatus();
4498
4542
  const response = operation.ensureResponseOf(currentStatus);
4499
4543
  const contentType = this.getContentType();
@@ -4516,7 +4560,7 @@ class ReturnDecoratorContext extends DecoratorContext {
4516
4560
 
4517
4561
  if (isSuccessStatus(this.get("status")) || currentStatus === "default") {
4518
4562
  if (model) {
4519
- store.type = model;
4563
+ entity.type = model;
4520
4564
  }
4521
4565
  } // additional info for OS2
4522
4566
 
@@ -4687,19 +4731,6 @@ function OperationId(operationId) {
4687
4731
  });
4688
4732
  }
4689
4733
 
4690
- var OperationMethods;
4691
-
4692
- (function (OperationMethods) {
4693
- OperationMethods["ALL"] = "ALL";
4694
- OperationMethods["GET"] = "GET";
4695
- OperationMethods["POST"] = "POST";
4696
- OperationMethods["PUT"] = "PUT";
4697
- OperationMethods["PATCH"] = "PATCH";
4698
- OperationMethods["HEAD"] = "HEAD";
4699
- OperationMethods["DELETE"] = "DELETE";
4700
- OperationMethods["OPTIONS"] = "OPTIONS";
4701
- OperationMethods["CUSTOM"] = "CUSTOM";
4702
- })(OperationMethods || (OperationMethods = {}));
4703
4734
  /**
4704
4735
  * Declare new Operation with his path and http method.
4705
4736
  *
@@ -4720,7 +4751,6 @@ var OperationMethods;
4720
4751
  * @operation
4721
4752
  */
4722
4753
 
4723
-
4724
4754
  function OperationPath(method, path = "/") {
4725
4755
  return JsonEntityFn((store, args) => {
4726
4756
  if (store.decoratorType !== DecoratorTypes.METHOD) {
@@ -5228,6 +5258,228 @@ function Location(location, meta) {
5228
5258
  return Returns().Location(location, meta);
5229
5259
  }
5230
5260
 
5261
+ function mapRouteOptions(args) {
5262
+ let method = undefined;
5263
+ let path = undefined;
5264
+ const handlers = args.filter(arg => {
5265
+ if (typeof arg === "string" && HTTP_METHODS.includes(arg.toLowerCase())) {
5266
+ method = arg.toLocaleUpperCase();
5267
+ return false;
5268
+ }
5269
+
5270
+ if (typeof arg === "string" || arg instanceof RegExp) {
5271
+ path = arg || "/";
5272
+ return false;
5273
+ }
5274
+
5275
+ return !!arg;
5276
+ });
5277
+ return {
5278
+ path,
5279
+ method,
5280
+ handlers
5281
+ };
5282
+ }
5283
+
5284
+ class RouteDecoratorContext extends DecoratorContext {
5285
+ constructor() {
5286
+ super(...arguments);
5287
+ this.methods = ["name", "description", "summary", "method", "id", "handlers"];
5288
+ }
5289
+
5290
+ beforeInit() {
5291
+ const path = this.get("path");
5292
+ const method = OperationMethods[this.get("method")] || OperationMethods.CUSTOM;
5293
+ path && this.entity.operation.addOperationPath(method, path);
5294
+ }
5295
+
5296
+ onMapKey(key, value) {
5297
+ switch (key) {
5298
+ case "name":
5299
+ case "id":
5300
+ this.entity.operation.operationId(value);
5301
+ return;
5302
+
5303
+ case "summary":
5304
+ this.entity.operation.summary(value);
5305
+ return;
5306
+
5307
+ case "description":
5308
+ this.entity.operation.description(value);
5309
+ return;
5310
+
5311
+ case "handlers":
5312
+ if (isFunction(this.entity.use)) {
5313
+ this.entity.use(value);
5314
+ return;
5315
+ }
5316
+
5317
+ break;
5318
+ }
5319
+
5320
+ return super.onMapKey(key, value);
5321
+ }
5322
+
5323
+ }
5324
+
5325
+ function Route(...args) {
5326
+ const routeOptions = mapRouteOptions(args);
5327
+ const context = new RouteDecoratorContext(routeOptions);
5328
+ return context.build();
5329
+ }
5330
+ /**
5331
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5332
+ *
5333
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5334
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5335
+ * all routes from that point on would require authentication, and automatically load a user.
5336
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5337
+ * to continue matching subsequent routes.
5338
+ * @param path
5339
+ * @param args
5340
+ * @returns {Function}
5341
+ * @decorator
5342
+ * @operation
5343
+ * @httpMethod
5344
+ */
5345
+
5346
+ function All(path = "/", ...args) {
5347
+ return Route(...[OperationMethods.ALL, path].concat(args));
5348
+ }
5349
+ /**
5350
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5351
+ *
5352
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5353
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5354
+ * all routes from that point on would require authentication, and automatically load a user.
5355
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5356
+ * to continue matching subsequent routes.
5357
+ * @param path
5358
+ * @param args
5359
+ * @returns {Function}
5360
+ * @decorator
5361
+ * @operation
5362
+ * @httpMethod
5363
+ */
5364
+
5365
+ function Get(path = "/", ...args) {
5366
+ return Route(...[OperationMethods.GET, path].concat(args));
5367
+ }
5368
+ /**
5369
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5370
+ *
5371
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5372
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5373
+ * all routes from that point on would require authentication, and automatically load a user.
5374
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5375
+ * to continue matching subsequent routes.
5376
+ * @param path
5377
+ * @param args
5378
+ * @returns {Function}
5379
+ * @decorator
5380
+ * @operation
5381
+ * @httpMethod
5382
+ */
5383
+
5384
+ function Post(path = "/", ...args) {
5385
+ return Route(...[OperationMethods.POST, path].concat(args));
5386
+ }
5387
+ /**
5388
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5389
+ *
5390
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5391
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5392
+ * all routes from that point on would require authentication, and automatically load a user.
5393
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5394
+ * to continue matching subsequent routes.
5395
+ * @param path
5396
+ * @param args
5397
+ * @returns {Function}
5398
+ * @decorator
5399
+ * @operation
5400
+ * @httpMethod
5401
+ */
5402
+
5403
+ function Put(path = "/", ...args) {
5404
+ return Route(...[OperationMethods.PUT, path].concat(args));
5405
+ }
5406
+ /**
5407
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5408
+ *
5409
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5410
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5411
+ * all routes from that point on would require authentication, and automatically load a user.
5412
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5413
+ * to continue matching subsequent routes.
5414
+ * @param path
5415
+ * @param args
5416
+ * @returns {Function}
5417
+ * @decorator
5418
+ * @operation
5419
+ * @httpMethod
5420
+ */
5421
+
5422
+ function Delete(path = "/", ...args) {
5423
+ return Route(...[OperationMethods.DELETE, path].concat(args));
5424
+ }
5425
+ /**
5426
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5427
+ *
5428
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5429
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5430
+ * all routes from that point on would require authentication, and automatically load a user.
5431
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5432
+ * to continue matching subsequent routes.
5433
+ * @param path
5434
+ * @param args
5435
+ * @returns {Function}
5436
+ * @decorator
5437
+ * @operation
5438
+ * @httpMethod
5439
+ */
5440
+
5441
+ function Head(path = "/", ...args) {
5442
+ return Route(...[OperationMethods.HEAD, path].concat(args));
5443
+ }
5444
+ /**
5445
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5446
+ *
5447
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5448
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5449
+ * all routes from that point on would require authentication, and automatically load a user.
5450
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5451
+ * to continue matching subsequent routes.
5452
+ * @param path
5453
+ * @param args
5454
+ * @returns {Function}
5455
+ * @decorator
5456
+ * @operation
5457
+ * @httpMethod
5458
+ */
5459
+
5460
+ function Patch(path = "/", ...args) {
5461
+ return Route(...[OperationMethods.PATCH, path].concat(args));
5462
+ }
5463
+ /**
5464
+ * This method is just like the `router.METHOD()` methods, except that it matches all HTTP methods (verbs).
5465
+ *
5466
+ * This method is extremely useful for mapping “global” logic for specific path prefixes or arbitrary matches.
5467
+ * For example, if you placed the following route at the top of all other route definitions, it would require that
5468
+ * all routes from that point on would require authentication, and automatically load a user.
5469
+ * Keep in mind that these callbacks do not have to act as end points; loadUser can perform a task, then call next()
5470
+ * to continue matching subsequent routes.
5471
+ * @param path
5472
+ * @param args
5473
+ * @returns {Function}
5474
+ * @decorator
5475
+ * @operation
5476
+ * @httpMethod
5477
+ */
5478
+
5479
+ function Options(path = "/", ...args) {
5480
+ return Route(...[OperationMethods.OPTIONS, path].concat(args));
5481
+ }
5482
+
5231
5483
  /**
5232
5484
  * Accept unknown properties on the deserialized model.
5233
5485
  *
@@ -7491,5 +7743,5 @@ function JsonEntityComponent(type) {
7491
7743
  };
7492
7744
  }
7493
7745
 
7494
- export { AdditionalProperties, AllOf, Allow, Any, AnyOf, ArrayOf, CollectionContains, CollectionOf, Const, Consumes, ContentType, CustomKey, CustomKeys, DateFormat, DateTime, Default, Deprecated, Description, Email, Enum, Example, ExclusiveMaximum, ExclusiveMinimum, For, Format, ForwardGroups, GenericOf, Generics, Groups, HTTP_STATUS_MESSAGES, 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, Partial, Path, Pattern, Produces, Property, ReadOnly, Redirect, Required, RequiredGroups, Returns, 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 };
7746
+ export { AdditionalProperties, All, AllOf, Allow, Any, AnyOf, ArrayOf, CollectionContains, CollectionOf, Const, Consumes, ContentType, CustomKey, CustomKeys, DateFormat, DateTime, Default, Delete, Deprecated, Description, Email, Enum, Example, 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 };
7495
7747
  //# sourceMappingURL=index.modern.js.map