@tsed/schema 6.114.8 → 6.114.9

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.
@@ -35,20 +35,19 @@ const JsonEntityStore_1 = require("../../domain/JsonEntityStore");
35
35
  * @collections
36
36
  */
37
37
  function CollectionOf(type, collectionType) {
38
+ if (!type) {
39
+ throw new Error("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.");
40
+ }
38
41
  const schema = {};
39
42
  let contains = false;
40
43
  const decorator = (...args) => {
41
44
  const store = JsonEntityStore_1.JsonEntityStore.from(...args);
42
- // const itemSchema = store.itemSchema.toJSON();
43
45
  if (collectionType) {
44
46
  store.collectionType = collectionType;
45
47
  store.schema.type(collectionType);
46
48
  }
47
49
  store.type = type;
48
- // console.log(type);
49
50
  store.itemSchema.type(type);
50
- // console.log(store.itemSchema.getComputedType(), schema);
51
- // store.itemSchema.assign({...itemSchema, type});
52
51
  store.schema.assign(schema);
53
52
  if (store.isArray && contains) {
54
53
  store.schema.set("contains", store.schema.get("items"));
@@ -1 +1 @@
1
- {"version":3,"file":"collectionOf.js","sourceRoot":"","sources":["../../../../src/decorators/collections/collectionOf.ts"],"names":[],"mappings":";;;AACA,kEAA6D;AAkE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,YAAY,CAAC,IAAS,EAAE,cAAoB;IAC1D,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,IAAI,QAAQ,GAAY,KAAK,CAAC;IAE9B,MAAM,SAAS,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;QACjC,MAAM,KAAK,GAAG,iCAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5C,gDAAgD;QAEhD,IAAI,cAAc,EAAE;YAClB,KAAK,CAAC,cAAc,GAAG,cAAc,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;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,WAAW,GAAG,WAAW,CAAC;QAEjC,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC;AA9DD,oCA8DC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,IAAS;IAC/B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAFD,0BAEC;AAED;;;;GAIG;AACH,SAAgB,KAAK,CAAC,IAAS;IAC7B,OAAO,YAAY,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC;AAFD,sBAEC","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,kEAA6D;AAkE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,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,GAAG,iCAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAE5C,IAAI,cAAc,EAAE;YAClB,KAAK,CAAC,cAAc,GAAG,cAAc,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACnC;QAED,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAE5B,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE5B,IAAI,KAAK,CAAC,OAAO,IAAI,QAAQ,EAAE;YAC7B,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YACxD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAA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ityStore\";\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"]}
@@ -32,20 +32,19 @@ import { JsonEntityStore } from "../../domain/JsonEntityStore.js";
32
32
  * @collections
33
33
  */
34
34
  export function CollectionOf(type, collectionType) {
35
+ if (!type) {
36
+ throw new Error("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.");
37
+ }
35
38
  const schema = {};
36
39
  let contains = false;
37
40
  const decorator = (...args) => {
38
41
  const store = JsonEntityStore.from(...args);
39
- // const itemSchema = store.itemSchema.toJSON();
40
42
  if (collectionType) {
41
43
  store.collectionType = collectionType;
42
44
  store.schema.type(collectionType);
43
45
  }
44
46
  store.type = type;
45
- // console.log(type);
46
47
  store.itemSchema.type(type);
47
- // console.log(store.itemSchema.getComputedType(), schema);
48
- // store.itemSchema.assign({...itemSchema, type});
49
48
  store.schema.assign(schema);
50
49
  if (store.isArray && contains) {
51
50
  store.schema.set("contains", store.schema.get("items"));
@@ -1 +1 @@
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,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,IAAI,QAAQ,GAAY,KAAK,CAAC;IAE9B,MAAM,SAAS,GAAG,CAAC,GAAG,IAAS,EAAE,EAAE;QACjC,MAAM,KAAK,GAAG,eAAe,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QAC5C,gDAAgD;QAEhD,IAAI,cAAc,EAAE;YAClB,KAAK,CAAC,cAAc,GAAG,cAAc,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACnC;QAED,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,qBAAqB;QACrB,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5B,2DAA2D;QAC3D,kDAAkD;QAClD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE5B,IAAI,KAAK,CAAC,OAAO,IAAI,QAAQ,EAAE;YAC7B,KAAK,CAAC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O,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":[],"m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;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 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/schema",
3
- "version": "6.114.8",
3
+ "version": "6.114.9",
4
4
  "description": "JsonSchema module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -32,7 +32,7 @@
32
32
  "tsed"
33
33
  ],
34
34
  "dependencies": {
35
- "@tsed/openspec": "6.114.8",
35
+ "@tsed/openspec": "6.114.9",
36
36
  "camel-case": "4.1.2",
37
37
  "fs-extra": "^10.0.1",
38
38
  "json-schema": "0.4.0",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@apidevtools/swagger-parser": "10.0.3",
46
- "@tsed/core": "6.114.8",
47
- "@tsed/openspec": "6.114.8",
46
+ "@tsed/core": "6.114.9",
47
+ "@tsed/openspec": "6.114.9",
48
48
  "@types/fs-extra": "9.0.13",
49
49
  "@types/json-schema": "7.0.11",
50
50
  "@types/micromatch": "4.0.2",
@@ -52,8 +52,8 @@
52
52
  "api-spec-converter": "2.12.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "@tsed/core": "^6.114.8",
56
- "@tsed/openspec": "^6.114.8"
55
+ "@tsed/core": "^6.114.9",
56
+ "@tsed/openspec": "^6.114.9"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@tsed/openspec": {