@tsed/schema 6.70.0 → 6.71.1

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, 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, isPrimitiveClass, ancestorsOf, mergeReducerBuilder, UnsupportedDecoratorType, decorateMethodsOf, isString, isPlainObject, isNumber, useDecorators, StoreSet } from '@tsed/core';
3
3
  import micromatch from 'micromatch';
4
4
 
5
5
  const HTTP_STATUS_MESSAGES = {
@@ -74,6 +74,9 @@ const HTTP_STATUS_MESSAGES = {
74
74
  function getStatusConstant(status) {
75
75
  return constantCase(HTTP_STATUS_MESSAGES[status]);
76
76
  }
77
+ function getStatusMessage(status) {
78
+ return HTTP_STATUS_MESSAGES[status];
79
+ }
77
80
 
78
81
  function _extends() {
79
82
  _extends = Object.assign || function (target) {
@@ -108,6 +111,20 @@ function _objectWithoutPropertiesLoose(source, excluded) {
108
111
  return target;
109
112
  }
110
113
 
114
+ var id = 0;
115
+
116
+ function _classPrivateFieldLooseKey(name) {
117
+ return "__private_" + id++ + "_" + name;
118
+ }
119
+
120
+ function _classPrivateFieldLooseBase(receiver, privateKey) {
121
+ if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
122
+ throw new TypeError("attempted to use private field on non-instance");
123
+ }
124
+
125
+ return receiver;
126
+ }
127
+
111
128
  /**
112
129
  * @ignore
113
130
  */
@@ -327,6 +344,7 @@ function anyMapper(input, options = {}) {
327
344
  registerJsonSchemaMapper("any", anyMapper);
328
345
 
329
346
  const isSuccessStatus = code => Number(code) && 200 <= Number(code) && Number(code) < 300;
347
+ const isRedirectionStatus = code => Number(code) && 300 <= Number(code) && Number(code) < 400;
330
348
 
331
349
  class JsonMap extends Map {
332
350
  constructor(obj = {}) {
@@ -1471,13 +1489,27 @@ class JsonSchema extends Map {
1471
1489
  }
1472
1490
 
1473
1491
  const _excluded$6 = ["schema", "in"];
1492
+
1493
+ var _status = /*#__PURE__*/_classPrivateFieldLooseKey("status");
1494
+
1495
+ var _redirection = /*#__PURE__*/_classPrivateFieldLooseKey("redirection");
1496
+
1474
1497
  class JsonOperation extends JsonMap {
1475
1498
  constructor(obj = {}) {
1476
1499
  super(_extends({
1477
1500
  parameters: [],
1478
1501
  responses: new JsonMap()
1479
1502
  }, obj));
1503
+ Object.defineProperty(this, _status, {
1504
+ writable: true,
1505
+ value: void 0
1506
+ });
1507
+ Object.defineProperty(this, _redirection, {
1508
+ writable: true,
1509
+ value: void 0
1510
+ });
1480
1511
  this.operationPaths = new Map();
1512
+ _classPrivateFieldLooseBase(this, _redirection)[_redirection] = false;
1481
1513
  }
1482
1514
 
1483
1515
  get response() {
@@ -1485,7 +1517,7 @@ class JsonOperation extends JsonMap {
1485
1517
  }
1486
1518
 
1487
1519
  get status() {
1488
- return this._status;
1520
+ return _classPrivateFieldLooseBase(this, _status)[_status];
1489
1521
  }
1490
1522
 
1491
1523
  tags(tags) {
@@ -1514,15 +1546,32 @@ class JsonOperation extends JsonMap {
1514
1546
  }
1515
1547
 
1516
1548
  defaultStatus(status) {
1517
- this._status = status;
1549
+ _classPrivateFieldLooseBase(this, _status)[_status] = status;
1550
+ return this;
1518
1551
  }
1519
1552
 
1520
1553
  getStatus() {
1521
- return this._status || 200;
1554
+ return _classPrivateFieldLooseBase(this, _status)[_status] || 200;
1555
+ }
1556
+
1557
+ setRedirection(status = 302) {
1558
+ _classPrivateFieldLooseBase(this, _redirection)[_redirection] = true;
1559
+ _classPrivateFieldLooseBase(this, _status)[_status] = status;
1560
+ return this;
1561
+ }
1562
+
1563
+ isRedirection(status) {
1564
+ if (_classPrivateFieldLooseBase(this, _redirection)[_redirection]) {
1565
+ if (status) {
1566
+ return isRedirectionStatus(status);
1567
+ }
1568
+ }
1569
+
1570
+ return _classPrivateFieldLooseBase(this, _redirection)[_redirection];
1522
1571
  }
1523
1572
 
1524
1573
  addResponse(statusCode, response) {
1525
- if (isSuccessStatus(statusCode) && !this._status) {
1574
+ if ((isSuccessStatus(statusCode) || isRedirectionStatus(statusCode)) && !_classPrivateFieldLooseBase(this, _status)[_status]) {
1526
1575
  const res = this.getResponseOf(200);
1527
1576
  this.getResponses().set(statusCode.toString(), res).delete("200");
1528
1577
  this.defaultStatus(Number(statusCode));
@@ -4287,17 +4336,9 @@ class ReturnDecoratorContext extends DecoratorContext {
4287
4336
  model
4288
4337
  }) {
4289
4338
  super();
4290
- this.methods = ["contentType", "description", "examples", "type", "status", "of", "nested", "header", "headers", "schema", "title", "groups"];
4291
- this.set("status", status);
4292
- this.set("model", model);
4293
-
4294
- if (status && HTTP_STATUS_MESSAGES[status]) {
4295
- this.set("description", HTTP_STATUS_MESSAGES[status]);
4296
-
4297
- if (!model) {
4298
- this.model(getStatusModel(+status));
4299
- }
4300
- }
4339
+ this.methods = ["contentType", "description", "examples", "type", "status", "of", "nested", "header", "headers", "schema", "title", "groups", "location"];
4340
+ this.model(model);
4341
+ this.status(status);
4301
4342
  }
4302
4343
 
4303
4344
  type(model) {
@@ -4305,12 +4346,21 @@ class ReturnDecoratorContext extends DecoratorContext {
4305
4346
  }
4306
4347
 
4307
4348
  model(model) {
4308
- this.set("model", model);
4349
+ model && this.set("model", model);
4309
4350
  return this;
4310
4351
  }
4311
4352
 
4312
4353
  status(status) {
4313
4354
  this.set("status", status);
4355
+
4356
+ if (status && HTTP_STATUS_MESSAGES[status] && !this.get("description")) {
4357
+ this.set("description", HTTP_STATUS_MESSAGES[status]);
4358
+
4359
+ if (!this.get("model")) {
4360
+ this.model(getStatusModel(+status));
4361
+ }
4362
+ }
4363
+
4314
4364
  return this;
4315
4365
  }
4316
4366
 
@@ -4325,6 +4375,15 @@ class ReturnDecoratorContext extends DecoratorContext {
4325
4375
  });
4326
4376
  }
4327
4377
 
4378
+ location(path, meta = {}) {
4379
+ this.headers({
4380
+ Location: _extends({}, meta, {
4381
+ value: path
4382
+ })
4383
+ });
4384
+ return this;
4385
+ }
4386
+
4328
4387
  groups(...groups) {
4329
4388
  this.set("groups", groups);
4330
4389
  return this;
@@ -4424,6 +4483,8 @@ class ReturnDecoratorContext extends DecoratorContext {
4424
4483
  default:
4425
4484
  throw new UnsupportedDecoratorType(Returns, args);
4426
4485
  }
4486
+
4487
+ this.clear();
4427
4488
  }
4428
4489
 
4429
4490
  map() {
@@ -5112,6 +5173,61 @@ function Partial() {
5112
5173
  return Groups("partial");
5113
5174
  }
5114
5175
 
5176
+ function Redirect(...args) {
5177
+ const {
5178
+ status,
5179
+ url,
5180
+ meta
5181
+ } = args.reduce((options, value) => {
5182
+ if (isNumber(value)) {
5183
+ options.status = value;
5184
+ return options;
5185
+ }
5186
+
5187
+ if (isString(value)) {
5188
+ options.url = value;
5189
+ return options;
5190
+ }
5191
+
5192
+ options.meta = value;
5193
+ return options;
5194
+ }, {
5195
+ status: 302,
5196
+ url: "",
5197
+ meta: {}
5198
+ });
5199
+ return useDecorators(Returns(status).Location(url, meta), JsonEntityFn(entity => {
5200
+ var _entity$operation;
5201
+
5202
+ (_entity$operation = entity.operation) == null ? void 0 : _entity$operation.setRedirection(status);
5203
+ }));
5204
+ }
5205
+
5206
+ /**
5207
+ * Sets the response Location HTTP header to the specified path parameter.
5208
+ *
5209
+ * ```typescript
5210
+ * @Location('/foo/bar', {description: 'Location to the next step'})
5211
+ * @Location('http://example.com')
5212
+ * @Location('back')
5213
+ * private myMethod() {
5214
+ *
5215
+ * }
5216
+ * ```
5217
+ *
5218
+ * A path value of “back” has a special meaning, it refers to the URL specified in the `Referer` header of the request. If the `Referer` header was not specified, it refers to “/”.
5219
+ *
5220
+ * @param location
5221
+ * @param meta
5222
+ * @returns {Function}
5223
+ * @decorator
5224
+ * @operation
5225
+ */
5226
+
5227
+ function Location(location, meta) {
5228
+ return Returns().Location(location, meta);
5229
+ }
5230
+
5115
5231
  /**
5116
5232
  * Accept unknown properties on the deserialized model.
5117
5233
  *
@@ -7375,5 +7491,5 @@ function JsonEntityComponent(type) {
7375
7491
  };
7376
7492
  }
7377
7493
 
7378
- 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, 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, 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, getStatusModel, integer, isParameterType, isSuccessStatus, lazyRef, map, mapGenericsOptions, mapHeaders, mergeSpec, number, object, oneOf, parameters, popGenerics, schemesReducer, security, set, string, tagsReducer, time, uri, url };
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 };
7379
7495
  //# sourceMappingURL=index.modern.js.map