@tsed/schema 6.97.0 → 6.97.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 +1 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/utils/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,SAAS,OAAO,CAAC,OAA0B;IACzC,MAAM,EAAC,IAAI,GAAG,KAAK,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,aAAa,EAAE,EAAC,GAAG,OAAO,CAAC;IAEvG,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAA0B;IACpE,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;QAC3C,OAAO,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAC1D;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,MAAkB,EAAE,OAA0B;IACpF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,MAAM,GAAG,GAAG;QACV,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE;KACxB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEjE,IAAI,QAAQ,IAAI,QAAQ,EAAE;QACxB,QAAQ,OAAO,CAAC,QAAQ,EAAE;YACxB,KAAK,SAAS,CAAC,OAAO;gBACpB,OAAO,WAAW,CAAC;oBACjB,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBACrC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;oBACrC,KAAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;YACL,KAAK,SAAS,CAAC,IAAI;gBACjB,OAAO,WAAW,CAAC;oBACjB,QAAQ;oBACR,KAAK,EAAE,CAAC,QAAQ,IAAI,EAAC,IAAI,EAAE,MAAM,EAAC,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;iBACzD,CAAC,CAAC;YACL,KAAK,SAAS,CAAC,OAAO,EAAE,cAAc;gBACpC,IAAI,QAAQ,EAAE;oBACZ,OAAO;wBACL,QAAQ;wBACR,KAAK,EAAE,CAAC,GAAG,CAAC;qBACb,CAAC;iBACH;gBACD,MAAM;SACT;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAiB,EAAE,MAAW,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3C,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import {pascalCase} from \"pascal-case\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {cleanObject} from \"@tsed/core\";\n\n/**\n * ignore\n * @param options\n */\nfunction getHost(options: JsonSchemaOptions) {\n const {host = `#/${options.specType === \"openapi3\" ? \"components/schemas\" : \"definitions\"}`} = options;\n\n return host;\n}\n\n/**\n * @ignore\n */\nexport function createRefName(name: string, options: JsonSchemaOptions) {\n if (options.groups && options.groups.length) {\n return pascalCase(`${name} ${options.groups.join(\" \")}`);\n }\n\n return name;\n}\n\n/**\n * @ignore\n */\nexport function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {\n const host = getHost(options);\n const ref = {\n $ref: `${host}/${name}`\n };\n\n const nullable = schema.nullable;\n const readOnly = schema.get ? schema.get(\"readOnly\") : undefined;\n\n if (nullable || readOnly) {\n switch (options.specType) {\n case SpecTypes.OPENAPI:\n return cleanObject({\n nullable: nullable ? true : undefined,\n readOnly: readOnly ? true : undefined,\n allOf: [ref]\n });\n case SpecTypes.JSON:\n return cleanObject({\n readOnly,\n oneOf: [nullable && {type: \"null\"}, ref].filter(Boolean)\n });\n case SpecTypes.SWAGGER: // unsupported\n if (readOnly) {\n return {\n readOnly,\n allOf: [ref]\n };\n }\n break;\n }\n }\n\n return ref;\n}\n\n/**\n * @ignore\n */\nexport function toRef(value: JsonSchema, schema: any, options: JsonSchemaOptions) {\n const name = createRefName(value.getName(), options);\n\n options.schemas![value.getName()] = schema;\n\n return createRef(name, value, options);\n}\n"]}
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/utils/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAEvC;;;GAGG;AACH,SAAS,OAAO,CAAC,OAA0B;IACzC,MAAM,EAAC,IAAI,GAAG,KAAK,OAAO,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,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AAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;YACL,KAAK,SAAS,CAAC,OAAO,EAAE,2BAA2B;gBACjD,IAAI,QAAQ,IAAI,SAAS,EAAE;oBACzB,OAAO,WAAW,CAAC;wBACjB,QAAQ;wBACR,SAAS;wBACT,KAAK,EAAE,CAAC,GAAG,CAAC;qBACb,CAAC,CAAC;iBACJ;SACJ;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAiB,EAAE,MAAW,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3C,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import {pascalCase} from \"pascal-case\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {cleanObject} from \"@tsed/core\";\n\n/**\n * ignore\n * @param options\n */\nfunction getHost(options: JsonSchemaOptions) {\n const {host = `#/${options.specType === \"openapi3\" ? \"components/schemas\" : \"definitions\"}`} = options;\n\n return host;\n}\n\n/**\n * @ignore\n */\nexport function createRefName(name: string, options: JsonSchemaOptions) {\n if (options.groups && options.groups.length) {\n return pascalCase(`${name} ${options.groups.join(\" \")}`);\n }\n\n return name;\n}\n\n/**\n * @ignore\n */\nexport function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {\n const host = getHost(options);\n const ref = {\n $ref: `${host}/${name}`\n };\n\n const nullable = schema.isNullable;\n const readOnly = schema.isReadOnly;\n const writeOnly = schema.isWriteOnly;\n\n if (nullable || readOnly || writeOnly) {\n switch (options.specType) {\n case SpecTypes.OPENAPI:\n return cleanObject({\n nullable: nullable ? true : undefined,\n readOnly: readOnly ? true : undefined,\n writeOnly: writeOnly ? true : undefined,\n oneOf: [ref]\n });\n case SpecTypes.JSON:\n return cleanObject({\n readOnly,\n writeOnly,\n oneOf: [ref]\n });\n case SpecTypes.SWAGGER: // TODO unsupported feature\n if (readOnly || writeOnly) {\n return cleanObject({\n readOnly,\n writeOnly,\n allOf: [ref]\n });\n }\n }\n }\n\n return ref;\n}\n\n/**\n * @ignore\n */\nexport function toRef(value: JsonSchema, schema: any, options: JsonSchemaOptions) {\n const name = createRefName(value.getName(), options);\n\n options.schemas![value.getName()] = schema;\n\n return createRef(name, value, options);\n}\n"]}
@@ -14,29 +14,19 @@ export interface JsonSchemaObject extends JSONSchema6, Record<string, any> {
14
14
  }
15
15
  export declare type AnyJsonSchema = Partial<JsonSchemaObject> | JsonSchema | JsonLazyRef | any;
16
16
  export declare class JsonSchema extends Map<string, any> implements NestedGenerics {
17
+ #private;
17
18
  readonly isJsonSchema = true;
18
19
  readonly $hooks: Hooks;
19
20
  readonly $required: Set<string>;
20
21
  readonly $allow: any[];
21
22
  $selfRequired: boolean;
22
23
  $forwardGroups: boolean;
23
- protected _nullable: boolean;
24
- protected _genericLabels: string[];
25
- protected _nestedGenerics: Type<any>[][];
26
- protected _alias: AliasMap;
27
- protected _itemSchema: JsonSchema;
28
- protected _target: Type<any>;
29
- protected _isGeneric: boolean;
30
- protected _isCollection: boolean;
31
- protected _ref: boolean;
32
24
  constructor(obj?: JsonSchema | Partial<JsonSchemaObject>);
33
25
  get alias(): AliasMap;
34
26
  get nestedGenerics(): any[];
35
27
  set nestedGenerics(value: any[]);
36
28
  get genericLabels(): string[];
37
29
  set genericLabels(value: string[]);
38
- get nullable(): boolean;
39
- set nullable(value: boolean);
40
30
  get isClass(): boolean;
41
31
  /**
42
32
  * Current schema is a collection
@@ -53,7 +43,11 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
53
43
  get genericType(): string;
54
44
  get class(): any;
55
45
  get canRef(): boolean;
46
+ get isNullable(): boolean;
47
+ get isReadOnly(): any;
48
+ get isWriteOnly(): any;
56
49
  static from(obj?: Partial<JsonSchemaObject>): JsonSchema;
50
+ nullable(value: boolean): void;
57
51
  itemSchema(obj?: AnyJsonSchema): JsonSchema;
58
52
  getAliasOf(property: AliasType): AliasType | undefined;
59
53
  addAlias(property: AliasType, alias: AliasType): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/schema",
3
- "version": "6.97.0",
3
+ "version": "6.97.1",
4
4
  "description": "JsonSchema module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -29,8 +29,8 @@
29
29
  "tsed"
30
30
  ],
31
31
  "dependencies": {
32
- "@tsed/core": "6.97.0",
33
- "@tsed/openspec": "6.97.0",
32
+ "@tsed/core": "6.97.1",
33
+ "@tsed/openspec": "6.97.1",
34
34
  "camel-case": "4.1.2",
35
35
  "json-schema": "0.4.0",
36
36
  "micromatch": "4.0.2",
@@ -45,8 +45,8 @@
45
45
  "fs-extra": "9.0.1"
46
46
  },
47
47
  "peerDependencies": {
48
- "@tsed/core": "^6.97.0",
49
- "@tsed/openspec": "^6.97.0"
48
+ "@tsed/core": "^6.97.1",
49
+ "@tsed/openspec": "^6.97.1"
50
50
  },
51
51
  "repository": "https://github.com/tsedio/tsed",
52
52
  "bugs": {
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isJsonClass = void 0;
4
- const core_1 = require("@tsed/core");
5
- /**
6
- * @ignore
7
- */
8
- function isJsonClass(type) {
9
- return (0, core_1.isClass)(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target);
10
- }
11
- exports.isJsonClass = isJsonClass;
12
- //# sourceMappingURL=isJsonClass.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isJsonClass.js","sourceRoot":"","sources":["../../../src/utils/isJsonClass.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAEnC;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAS;IACnC,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAc,CAAC,CAAC;AAClH,CAAC;AAFD,kCAEC","sourcesContent":["import {isClass} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function isJsonClass(type: any) {\n return isClass(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target as any);\n}\n"]}
@@ -1,8 +0,0 @@
1
- import { isClass } from "@tsed/core";
2
- /**
3
- * @ignore
4
- */
5
- export function isJsonClass(type) {
6
- return isClass(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target);
7
- }
8
- //# sourceMappingURL=isJsonClass.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isJsonClass.js","sourceRoot":"","sources":["../../../src/utils/isJsonClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAS;IACnC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAc,CAAC,CAAC;AAClH,CAAC","sourcesContent":["import {isClass} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function isJsonClass(type: any) {\n return isClass(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target as any);\n}\n"]}
@@ -1,4 +0,0 @@
1
- /**
2
- * @ignore
3
- */
4
- export declare function isJsonClass(type: any): boolean;