@tsed/schema 6.97.0 → 6.98.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.
- package/jest.config.js +14 -0
- package/lib/cjs/components/objectMapper.js +6 -3
- package/lib/cjs/components/objectMapper.js.map +1 -1
- package/lib/cjs/components/schemaMapper.js +1 -1
- package/lib/cjs/components/schemaMapper.js.map +1 -1
- package/lib/cjs/decorators/index.js +2 -0
- package/lib/cjs/decorators/index.js.map +1 -1
- package/lib/cjs/decorators/operations/acceptMime.js +28 -0
- package/lib/cjs/decorators/operations/acceptMime.js.map +1 -0
- package/lib/cjs/decorators/operations/view.js +31 -0
- package/lib/cjs/decorators/operations/view.js.map +1 -0
- package/lib/cjs/domain/JsonMethodStore.js +37 -1
- package/lib/cjs/domain/JsonMethodStore.js.map +1 -1
- package/lib/cjs/domain/JsonOperation.js +5 -9
- package/lib/cjs/domain/JsonOperation.js.map +1 -1
- package/lib/cjs/domain/JsonOperationRoute.js +7 -0
- package/lib/cjs/domain/JsonOperationRoute.js.map +1 -1
- package/lib/cjs/domain/JsonParameterStore.js +13 -4
- package/lib/cjs/domain/JsonParameterStore.js.map +1 -1
- package/lib/cjs/domain/JsonPropertyStore.js +5 -1
- package/lib/cjs/domain/JsonPropertyStore.js.map +1 -1
- package/lib/cjs/domain/JsonSchema.js +78 -60
- package/lib/cjs/domain/JsonSchema.js.map +1 -1
- package/lib/cjs/domain/SpecTypes.js +3 -0
- package/lib/cjs/domain/SpecTypes.js.map +1 -1
- package/lib/cjs/utils/getOperationsRoutes.js.map +1 -1
- package/lib/cjs/utils/getSpec.js +3 -3
- package/lib/cjs/utils/getSpec.js.map +1 -1
- package/lib/cjs/utils/mapNullableType.js +30 -11
- package/lib/cjs/utils/mapNullableType.js.map +1 -1
- package/lib/cjs/utils/ref.js +13 -10
- package/lib/cjs/utils/ref.js.map +1 -1
- package/lib/esm/components/objectMapper.js +6 -3
- package/lib/esm/components/objectMapper.js.map +1 -1
- package/lib/esm/components/schemaMapper.js +1 -1
- package/lib/esm/components/schemaMapper.js.map +1 -1
- package/lib/esm/decorators/index.js +2 -0
- package/lib/esm/decorators/index.js.map +1 -1
- package/lib/esm/decorators/operations/acceptMime.js +24 -0
- package/lib/esm/decorators/operations/acceptMime.js.map +1 -0
- package/lib/esm/decorators/operations/view.js +27 -0
- package/lib/esm/decorators/operations/view.js.map +1 -0
- package/lib/esm/domain/JsonMethodStore.js +37 -1
- package/lib/esm/domain/JsonMethodStore.js.map +1 -1
- package/lib/esm/domain/JsonOperation.js +5 -9
- package/lib/esm/domain/JsonOperation.js.map +1 -1
- package/lib/esm/domain/JsonOperationRoute.js +7 -0
- package/lib/esm/domain/JsonOperationRoute.js.map +1 -1
- package/lib/esm/domain/JsonParameterStore.js +13 -4
- package/lib/esm/domain/JsonParameterStore.js.map +1 -1
- package/lib/esm/domain/JsonPropertyStore.js +4 -0
- package/lib/esm/domain/JsonPropertyStore.js.map +1 -1
- package/lib/esm/domain/JsonSchema.js +78 -60
- package/lib/esm/domain/JsonSchema.js.map +1 -1
- package/lib/esm/domain/SpecTypes.js +3 -0
- package/lib/esm/domain/SpecTypes.js.map +1 -1
- package/lib/esm/utils/getOperationsRoutes.js.map +1 -1
- package/lib/esm/utils/getSpec.js +3 -3
- package/lib/esm/utils/getSpec.js.map +1 -1
- package/lib/esm/utils/mapNullableType.js +31 -12
- package/lib/esm/utils/mapNullableType.js.map +1 -1
- package/lib/esm/utils/ref.js +13 -10
- package/lib/esm/utils/ref.js.map +1 -1
- package/lib/types/decorators/index.d.ts +2 -0
- package/lib/types/decorators/operations/acceptMime.d.ts +19 -0
- package/lib/types/decorators/operations/view.d.ts +23 -0
- package/lib/types/domain/JsonMethodStore.d.ts +48 -0
- package/lib/types/domain/JsonOperationRoute.d.ts +5 -3
- package/lib/types/domain/JsonParameterStore.d.ts +23 -1
- package/lib/types/domain/JsonPropertyStore.d.ts +7 -0
- package/lib/types/domain/JsonSchema.d.ts +5 -11
- package/lib/types/domain/SpecTypes.d.ts +3 -0
- package/lib/types/utils/getOperationsRoutes.d.ts +2 -2
- package/lib/types/utils/mapNullableType.d.ts +1 -1
- package/package.json +6 -6
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
- package/lib/cjs/utils/isJsonClass.js +0 -12
- package/lib/cjs/utils/isJsonClass.js.map +0 -1
- package/lib/esm/utils/isJsonClass.js +0 -8
- package/lib/esm/utils/isJsonClass.js.map +0 -1
- package/lib/types/utils/isJsonClass.d.ts +0 -4
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { ancestorsOf, DecoratorTypes, isClass, isCollection, isMethodDescriptor, Metadata, prototypeOf } from "@tsed/core";
|
|
3
3
|
import { JsonEntityStore } from "./JsonEntityStore";
|
|
4
4
|
import { JsonParameter } from "./JsonParameter";
|
|
5
5
|
import { JsonSchema } from "./JsonSchema";
|
|
6
6
|
import { JsonEntityComponent } from "../decorators/config/jsonEntityComponent";
|
|
7
7
|
let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
8
|
-
constructor() {
|
|
9
|
-
super(
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
10
|
/**
|
|
11
11
|
* Ref to JsonParameter when the decorated object is a parameter.
|
|
12
12
|
*/
|
|
13
13
|
this.parameter = new JsonParameter();
|
|
14
14
|
this.parent = JsonEntityStore.fromMethod(this.target, this.propertyKey);
|
|
15
|
+
this.pipes = options.pipes || [];
|
|
16
|
+
this.paramType = options.paramType || this.paramType;
|
|
17
|
+
this.expression = options.expression || this.expression;
|
|
18
|
+
this.dataPath = options.dataPath || this.dataPath;
|
|
15
19
|
}
|
|
16
20
|
get nestedGenerics() {
|
|
17
21
|
return this.parameter.nestedGenerics;
|
|
@@ -47,6 +51,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
|
47
51
|
}
|
|
48
52
|
return [];
|
|
49
53
|
}
|
|
54
|
+
static get(target, propertyKey, index) {
|
|
55
|
+
return JsonEntityStore.from(prototypeOf(target), propertyKey, index);
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
58
|
* Check precondition between value, required and allowedRequiredValues to know if the entity is required.
|
|
52
59
|
* @param value
|
|
@@ -81,7 +88,9 @@ let JsonParameterStore = class JsonParameterStore extends JsonEntityStore {
|
|
|
81
88
|
}
|
|
82
89
|
};
|
|
83
90
|
JsonParameterStore = __decorate([
|
|
84
|
-
JsonEntityComponent(DecoratorTypes.PARAM)
|
|
91
|
+
JsonEntityComponent(DecoratorTypes.PARAM),
|
|
92
|
+
__metadata("design:paramtypes", [Object])
|
|
85
93
|
], JsonParameterStore);
|
|
86
94
|
export { JsonParameterStore };
|
|
95
|
+
export const ParamMetadata = JsonParameterStore;
|
|
87
96
|
//# sourceMappingURL=JsonParameterStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"JsonParameterStore.js","sourceRoot":"","sources":["../../../src/domain/JsonParameterStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,EAAO,MAAM,YAAY,CAAC;AAC/H,OAAO,EAAC,eAAe,EAAyB,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,mBAAmB,EAAC,MAAM,0CAA0C,CAAC;AAa7E,IAAa,kBAAkB,GAA/B,MAAa,kBAAmB,SAAQ,eAAe;IAcrD,YAAY,OAAkC;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAPjB;;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C,SAAS,CAAC,IAAI,CAAC,CAAC;SACtB;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAM,EAAE,IAAI,CAAC,CAAC;YAE5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;YAEhE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEpC,IAAI,IAAI,CAAC,cAAc,EAAE;gBACvB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;aACpD;YAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,KAAe,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;SAC1E;IACH,CAAC;CACF,CAAA;AAhHY,kBAAkB;IAD9B,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC;;GAC7B,kBAAkB,CAgH9B;SAhHY,kBAAkB;AAsH/B,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC","sourcesContent":["import {ancestorsOf, DecoratorTypes, isClass, isCollection, isMethodDescriptor, Metadata, prototypeOf, Type} from \"@tsed/core\";\nimport {JsonEntityStore, JsonEntityStoreOptions} from \"./JsonEntityStore\";\nimport type {JsonMethodStore} from \"./JsonMethodStore\";\nimport {JsonParameter} from \"./JsonParameter\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\n\nexport interface JsonParameterStoreOptions extends JsonEntityStoreOptions {\n dataPath?: string;\n paramType?: string;\n expression?: string;\n}\n\nexport interface PipeMethods<T = any, R = any> {\n transform(value: T, metadata: JsonParameterStore): R;\n}\n\n@JsonEntityComponent(DecoratorTypes.PARAM)\nexport class JsonParameterStore extends JsonEntityStore {\n public paramType: string;\n public expression: string;\n public dataPath: string;\n /**\n * Define pipes can be called by the framework to transform input parameter\n */\n public pipes: Type<PipeMethods>[];\n /**\n * Ref to JsonParameter when the decorated object is a parameter.\n */\n readonly parameter: JsonParameter = new JsonParameter();\n readonly parent: JsonMethodStore = JsonEntityStore.fromMethod(this.target, this.propertyKey);\n\n constructor(options: JsonParameterStoreOptions) {\n super(options);\n this.pipes = options.pipes || [];\n this.paramType = options.paramType || this.paramType;\n this.expression = options.expression || this.expression;\n this.dataPath = options.dataPath || this.dataPath;\n }\n\n get nestedGenerics(): Type<any>[][] {\n return this.parameter.nestedGenerics;\n }\n\n set nestedGenerics(nestedGenerics: Type<any>[][]) {\n this.parameter.nestedGenerics = nestedGenerics;\n }\n\n /**\n * Return the required state.\n * @returns {boolean}\n */\n get required(): boolean {\n return !!this.parameter.get(\"required\");\n }\n\n set required(value: boolean) {\n this.parameter.required(value);\n }\n\n get allowedRequiredValues() {\n return this.schema.$allow;\n }\n\n static getParams<T extends JsonParameterStore = JsonParameterStore>(target: Type<any>, propertyKey: string | symbol): T[] {\n const params: T[] = [];\n\n const klass = ancestorsOf(target)\n .reverse()\n .find((target) => {\n return isMethodDescriptor(target, propertyKey) && JsonEntityStore.fromMethod(target, propertyKey).children.size;\n });\n\n if (klass) {\n JsonEntityStore.fromMethod(klass, propertyKey).children.forEach((param: T, index) => {\n params[+index] = param;\n });\n\n return params;\n }\n\n return [];\n }\n\n static get(target: Type<any>, propertyKey: string | symbol, index: number) {\n return JsonEntityStore.from<JsonParameterStore>(prototypeOf(target), propertyKey, index);\n }\n\n /**\n * Check precondition between value, required and allowedRequiredValues to know if the entity is required.\n * @param value\n * @returns {boolean}\n */\n isRequired(value: any): boolean {\n return this.required && [undefined, null, \"\"].includes(value) && !this.allowedRequiredValues.includes(value);\n }\n\n protected getSchema(type: any) {\n if (isCollection(type) || !isClass(type)) {\n return JsonSchema.from({\n type\n });\n }\n\n return JsonEntityStore.from(type).schema;\n }\n\n protected build() {\n if (!this._type) {\n const type: any = Metadata.getParamTypes(prototypeOf(this.target), this.propertyKey)[this.index!];\n\n this.buildType(type);\n }\n\n this._type = this._type || Object;\n\n if (!this._schema) {\n this.parent.children.set(this.index!, this);\n\n this._schema = this.getSchema(this.collectionType || this.type);\n\n this.parameter.schema(this._schema);\n\n if (this.collectionType) {\n this._schema.itemSchema(this.getSchema(this.type));\n }\n\n this.parent.operation.addParameter(this.index as number, this.parameter);\n }\n }\n}\n\n/**\n * @alias JsonParameterStore\n */\nexport type ParamMetadata = JsonParameterStore;\nexport const ParamMetadata = JsonParameterStore;\n"]}
|
|
@@ -57,9 +57,13 @@ let JsonPropertyStore = class JsonPropertyStore extends JsonEntityStore {
|
|
|
57
57
|
this.parent.schema.addProperty(this.propertyName, schema);
|
|
58
58
|
this._schema = schema;
|
|
59
59
|
}
|
|
60
|
+
static get(target, propertyKey) {
|
|
61
|
+
return JsonEntityStore.from(prototypeOf(target), propertyKey);
|
|
62
|
+
}
|
|
60
63
|
};
|
|
61
64
|
JsonPropertyStore = __decorate([
|
|
62
65
|
JsonEntityComponent(DecoratorTypes.PROP)
|
|
63
66
|
], JsonPropertyStore);
|
|
64
67
|
export { JsonPropertyStore };
|
|
68
|
+
export const PropertyMetadata = JsonPropertyStore;
|
|
65
69
|
//# sourceMappingURL=JsonPropertyStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAE,QAAQ,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"JsonPropertyStore.js","sourceRoot":"","sources":["../../../src/domain/JsonPropertyStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,cAAc,EAAE,QAAQ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C,CAAC;SAC9E;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC;QAElC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,MAAM,GAAe,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEvD,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;YAElD,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC;gBACvB,IAAI,EAAE,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI;aACvC,CAAC,CAAC;YAEH,IAAI,IAAI,CAAC,cAAc,EAAE;gBACvB,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9B;SACF;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAE1D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,MAAiB,EAAE,WAA4B;QACxD,OAAO,eAAe,CAAC,IAAI,CAAoB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;IACnF,CAAC;CACF,CAAA;AAnEY,iBAAiB;IAD7B,mBAAmB,CAAC,cAAc,CAAC,IAAI,CAAC;GAC5B,iBAAiB,CAmE7B;SAnEY,iBAAiB;AAyE9B,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC","sourcesContent":["import {DecoratorTypes, Metadata, prototypeOf, Type} from \"@tsed/core\";\nimport {JsonEntityStore} from \"./JsonEntityStore\";\nimport {JsonSchema} from \"./JsonSchema\";\nimport {JsonEntityComponent} from \"../decorators/config/jsonEntityComponent\";\nimport type {JsonClassStore} from \"./JsonClassStore\";\n\n@JsonEntityComponent(DecoratorTypes.PROP)\nexport class JsonPropertyStore extends JsonEntityStore {\n readonly parent: JsonClassStore = JsonEntityStore.from(this.target);\n\n /**\n * Return the required state.\n * @returns {boolean}\n */\n get required(): boolean {\n return this.parent.schema.isRequired(this.propertyKey as string);\n }\n\n /**\n * Change the state of the required data.\n * @param value\n */\n set required(value: boolean) {\n if (value) {\n this.parent.schema.addRequired(this.propertyKey as string);\n } else {\n this.parent.schema.removeRequired(this.propertyKey as string);\n }\n }\n\n get allowedRequiredValues() {\n return this.schema.$allow;\n }\n\n /**\n * Check precondition between value, required and allowedRequiredValues to know if the entity is required.\n * @param value\n * @returns {boolean}\n */\n isRequired(value: any): boolean {\n return this.required && [undefined, null, \"\"].includes(value) && !this.allowedRequiredValues.includes(value);\n }\n\n protected build() {\n if (!this._type) {\n this.buildType(Metadata.getType(prototypeOf(this.target), this.propertyKey));\n }\n\n this._type = this._type || Object;\n\n const properties = this.parent.schema.get(\"properties\");\n\n let schema: JsonSchema = properties[this.propertyName];\n\n if (!schema) {\n this.parent.children.set(this.propertyName, this);\n\n schema = JsonSchema.from({\n type: this.collectionType || this.type\n });\n\n if (this.collectionType) {\n schema.itemSchema(this.type);\n }\n }\n\n this.parent.schema.addProperty(this.propertyName, schema);\n\n this._schema = schema;\n }\n\n static get(target: Type<any>, propertyKey: string | symbol) {\n return JsonEntityStore.from<JsonPropertyStore>(prototypeOf(target), propertyKey);\n }\n}\n\n/**\n * @alias JsonPropertyStore\n */\nexport type PropertyMetadata = JsonPropertyStore;\nexport const PropertyMetadata = JsonPropertyStore;\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var _JsonSchema_nullable, _JsonSchema_genericLabels, _JsonSchema_nestedGenerics, _JsonSchema_alias, _JsonSchema_itemSchema, _JsonSchema_target, _JsonSchema_isGeneric, _JsonSchema_isCollection, _JsonSchema_ref;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
1
3
|
import { classOf, Hooks, isArray, isClass, isFunction, isObject, nameOf, uniq } from "@tsed/core";
|
|
2
4
|
import { execMapper } from "../registries/JsonSchemaMapperContainer";
|
|
3
5
|
import { getComputedType } from "../utils/getComputedType";
|
|
@@ -10,7 +12,7 @@ function mapProperties(properties) {
|
|
|
10
12
|
return properties;
|
|
11
13
|
}
|
|
12
14
|
return Object.entries(properties).reduce((properties, [key, schema]) => {
|
|
13
|
-
properties[toJsonRegex(key)] =
|
|
15
|
+
properties[toJsonRegex(key)] = mapToJsonSchema(schema);
|
|
14
16
|
return properties;
|
|
15
17
|
}, {});
|
|
16
18
|
}
|
|
@@ -30,7 +32,6 @@ function mapToJsonSchema(item) {
|
|
|
30
32
|
return item;
|
|
31
33
|
}
|
|
32
34
|
export class JsonSchema extends Map {
|
|
33
|
-
// protected _specs: Map<SpecTypes, any> = new Map();
|
|
34
35
|
constructor(obj = {}) {
|
|
35
36
|
super();
|
|
36
37
|
this.isJsonSchema = true;
|
|
@@ -38,51 +39,48 @@ export class JsonSchema extends Map {
|
|
|
38
39
|
this.$required = new Set();
|
|
39
40
|
this.$allow = [];
|
|
40
41
|
this.$forwardGroups = false;
|
|
41
|
-
this
|
|
42
|
-
this
|
|
43
|
-
this
|
|
44
|
-
this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
42
|
+
_JsonSchema_nullable.set(this, false);
|
|
43
|
+
_JsonSchema_genericLabels.set(this, void 0);
|
|
44
|
+
_JsonSchema_nestedGenerics.set(this, []);
|
|
45
|
+
_JsonSchema_alias.set(this, new Map());
|
|
46
|
+
_JsonSchema_itemSchema.set(this, void 0);
|
|
47
|
+
_JsonSchema_target.set(this, void 0);
|
|
48
|
+
_JsonSchema_isGeneric.set(this, false);
|
|
49
|
+
_JsonSchema_isCollection.set(this, false);
|
|
50
|
+
_JsonSchema_ref.set(this, false);
|
|
47
51
|
if (obj) {
|
|
48
52
|
this.assign(obj);
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
get alias() {
|
|
52
|
-
return this
|
|
56
|
+
return __classPrivateFieldGet(this, _JsonSchema_alias, "f");
|
|
53
57
|
}
|
|
54
58
|
get nestedGenerics() {
|
|
55
|
-
return this
|
|
59
|
+
return __classPrivateFieldGet(this, _JsonSchema_nestedGenerics, "f");
|
|
56
60
|
}
|
|
57
61
|
set nestedGenerics(value) {
|
|
58
|
-
this
|
|
62
|
+
__classPrivateFieldSet(this, _JsonSchema_nestedGenerics, value, "f");
|
|
59
63
|
}
|
|
60
64
|
get genericLabels() {
|
|
61
|
-
return this
|
|
65
|
+
return __classPrivateFieldGet(this, _JsonSchema_genericLabels, "f");
|
|
62
66
|
}
|
|
63
67
|
set genericLabels(value) {
|
|
64
|
-
this
|
|
65
|
-
}
|
|
66
|
-
get nullable() {
|
|
67
|
-
return this._nullable || this.$allow.includes(null);
|
|
68
|
-
}
|
|
69
|
-
set nullable(value) {
|
|
70
|
-
this._nullable = value;
|
|
68
|
+
__classPrivateFieldSet(this, _JsonSchema_genericLabels, value, "f");
|
|
71
69
|
}
|
|
72
70
|
get isClass() {
|
|
73
|
-
return isClass(this.class) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this
|
|
71
|
+
return isClass(this.class) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(__classPrivateFieldGet(this, _JsonSchema_target, "f"));
|
|
74
72
|
}
|
|
75
73
|
/**
|
|
76
74
|
* Current schema is a collection
|
|
77
75
|
*/
|
|
78
76
|
get isCollection() {
|
|
79
|
-
return this
|
|
77
|
+
return __classPrivateFieldGet(this, _JsonSchema_isCollection, "f");
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
80
|
* Current schema is a generic
|
|
83
81
|
*/
|
|
84
82
|
get isGeneric() {
|
|
85
|
-
return this
|
|
83
|
+
return __classPrivateFieldGet(this, _JsonSchema_isGeneric, "f");
|
|
86
84
|
}
|
|
87
85
|
/**
|
|
88
86
|
* Current schema has generics items
|
|
@@ -97,28 +95,40 @@ export class JsonSchema extends Map {
|
|
|
97
95
|
return this.getComputedType();
|
|
98
96
|
}
|
|
99
97
|
get canRef() {
|
|
100
|
-
return this
|
|
98
|
+
return __classPrivateFieldGet(this, _JsonSchema_ref, "f");
|
|
99
|
+
}
|
|
100
|
+
get isNullable() {
|
|
101
|
+
return __classPrivateFieldGet(this, _JsonSchema_nullable, "f") || this.$allow.includes(null);
|
|
102
|
+
}
|
|
103
|
+
get isReadOnly() {
|
|
104
|
+
return this.get("readOnly");
|
|
105
|
+
}
|
|
106
|
+
get isWriteOnly() {
|
|
107
|
+
return this.get("writeOnly");
|
|
101
108
|
}
|
|
102
109
|
static from(obj = {}) {
|
|
103
110
|
return new JsonSchema(obj);
|
|
104
111
|
}
|
|
112
|
+
nullable(value) {
|
|
113
|
+
__classPrivateFieldSet(this, _JsonSchema_nullable, value, "f");
|
|
114
|
+
}
|
|
105
115
|
itemSchema(obj = {}) {
|
|
106
|
-
this
|
|
107
|
-
this.
|
|
108
|
-
return this
|
|
116
|
+
__classPrivateFieldSet(this, _JsonSchema_itemSchema, __classPrivateFieldGet(this, _JsonSchema_itemSchema, "f") || mapToJsonSchema(obj), "f");
|
|
117
|
+
__classPrivateFieldGet(this, _JsonSchema_itemSchema, "f").assign(obj);
|
|
118
|
+
return __classPrivateFieldGet(this, _JsonSchema_itemSchema, "f");
|
|
109
119
|
}
|
|
110
120
|
getAliasOf(property) {
|
|
111
|
-
return this.
|
|
121
|
+
return __classPrivateFieldGet(this, _JsonSchema_alias, "f").get(property);
|
|
112
122
|
}
|
|
113
123
|
addAlias(property, alias) {
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
124
|
+
__classPrivateFieldGet(this, _JsonSchema_alias, "f").set(property, alias);
|
|
125
|
+
__classPrivateFieldGet(this, _JsonSchema_alias, "f").set(alias, property);
|
|
116
126
|
return this;
|
|
117
127
|
}
|
|
118
128
|
removeAlias(property) {
|
|
119
|
-
const alias = this.
|
|
120
|
-
alias && this.
|
|
121
|
-
this.
|
|
129
|
+
const alias = __classPrivateFieldGet(this, _JsonSchema_alias, "f").get(property);
|
|
130
|
+
alias && __classPrivateFieldGet(this, _JsonSchema_alias, "f").delete(alias);
|
|
131
|
+
__classPrivateFieldGet(this, _JsonSchema_alias, "f").delete(property);
|
|
122
132
|
return this;
|
|
123
133
|
}
|
|
124
134
|
$id($id) {
|
|
@@ -138,7 +148,7 @@ export class JsonSchema extends Map {
|
|
|
138
148
|
* @param name
|
|
139
149
|
*/
|
|
140
150
|
label(name) {
|
|
141
|
-
this
|
|
151
|
+
__classPrivateFieldSet(this, _JsonSchema_ref, true, "f");
|
|
142
152
|
super.set("name", name);
|
|
143
153
|
return this;
|
|
144
154
|
}
|
|
@@ -222,7 +232,7 @@ export class JsonSchema extends Map {
|
|
|
222
232
|
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.9
|
|
223
233
|
*/
|
|
224
234
|
items(items) {
|
|
225
|
-
super.set("items", (this
|
|
235
|
+
super.set("items", (__classPrivateFieldSet(this, _JsonSchema_itemSchema, mapToJsonSchema(items), "f")));
|
|
226
236
|
return this;
|
|
227
237
|
}
|
|
228
238
|
/**
|
|
@@ -516,24 +526,24 @@ export class JsonSchema extends Map {
|
|
|
516
526
|
switch (type) {
|
|
517
527
|
case Map:
|
|
518
528
|
super.set("type", getJsonType(type));
|
|
519
|
-
this
|
|
520
|
-
this
|
|
529
|
+
__classPrivateFieldSet(this, _JsonSchema_target, type, "f");
|
|
530
|
+
__classPrivateFieldSet(this, _JsonSchema_isCollection, true, "f");
|
|
521
531
|
if (!this.has("additionalProperties")) {
|
|
522
532
|
super.set("additionalProperties", this.itemSchema({}));
|
|
523
533
|
}
|
|
524
534
|
break;
|
|
525
535
|
case Array:
|
|
526
536
|
super.set("type", getJsonType(type));
|
|
527
|
-
this
|
|
528
|
-
this
|
|
537
|
+
__classPrivateFieldSet(this, _JsonSchema_target, type, "f");
|
|
538
|
+
__classPrivateFieldSet(this, _JsonSchema_isCollection, true, "f");
|
|
529
539
|
if (!this.has("items")) {
|
|
530
540
|
super.set("items", this.itemSchema({}));
|
|
531
541
|
}
|
|
532
542
|
break;
|
|
533
543
|
case Set:
|
|
534
544
|
super.set("type", getJsonType(type));
|
|
535
|
-
this
|
|
536
|
-
this
|
|
545
|
+
__classPrivateFieldSet(this, _JsonSchema_target, type, "f");
|
|
546
|
+
__classPrivateFieldSet(this, _JsonSchema_isCollection, true, "f");
|
|
537
547
|
this.uniqueItems(true);
|
|
538
548
|
if (!this.has("items")) {
|
|
539
549
|
super.set("items", this.itemSchema({}));
|
|
@@ -549,7 +559,7 @@ export class JsonSchema extends Map {
|
|
|
549
559
|
case Number:
|
|
550
560
|
case String:
|
|
551
561
|
super.set("type", getJsonType(type));
|
|
552
|
-
this
|
|
562
|
+
__classPrivateFieldSet(this, _JsonSchema_target, type, "f");
|
|
553
563
|
if (!this.has("properties")) {
|
|
554
564
|
super.set("properties", {});
|
|
555
565
|
}
|
|
@@ -557,7 +567,7 @@ export class JsonSchema extends Map {
|
|
|
557
567
|
default:
|
|
558
568
|
if (isClass(type) || isFunction(type)) {
|
|
559
569
|
super.set("type", undefined);
|
|
560
|
-
this
|
|
570
|
+
__classPrivateFieldSet(this, _JsonSchema_target, type, "f");
|
|
561
571
|
if (!this.has("properties")) {
|
|
562
572
|
super.set("properties", {});
|
|
563
573
|
}
|
|
@@ -565,7 +575,7 @@ export class JsonSchema extends Map {
|
|
|
565
575
|
else {
|
|
566
576
|
const jsonType = getJsonType(type);
|
|
567
577
|
if (jsonType === "generic") {
|
|
568
|
-
this
|
|
578
|
+
__classPrivateFieldSet(this, _JsonSchema_isGeneric, true, "f");
|
|
569
579
|
super.set("$ref", type);
|
|
570
580
|
}
|
|
571
581
|
else {
|
|
@@ -578,9 +588,9 @@ export class JsonSchema extends Map {
|
|
|
578
588
|
any(...types) {
|
|
579
589
|
const hasClasses = types.filter((type) => isClass(type));
|
|
580
590
|
if (hasClasses.length >= 2) {
|
|
581
|
-
this.
|
|
591
|
+
this.oneOf(types.filter((value) => {
|
|
582
592
|
if (value !== null) {
|
|
583
|
-
this.nullable
|
|
593
|
+
this.nullable(true);
|
|
584
594
|
return true;
|
|
585
595
|
}
|
|
586
596
|
return false;
|
|
@@ -588,9 +598,16 @@ export class JsonSchema extends Map {
|
|
|
588
598
|
}
|
|
589
599
|
else {
|
|
590
600
|
// TODO when OS3 will the only minimal supported version, we'll can remove this code
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
601
|
+
if (types.length) {
|
|
602
|
+
types = uniq(types).map(getJsonType);
|
|
603
|
+
if (types.includes("null")) {
|
|
604
|
+
this.nullable(true);
|
|
605
|
+
types = types.filter((o) => o !== "null");
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
types = ["integer", "number", "string", "boolean", "array", "object"];
|
|
610
|
+
this.nullable(true);
|
|
594
611
|
}
|
|
595
612
|
this.type(types.length === 1 ? types[0] : types);
|
|
596
613
|
}
|
|
@@ -647,14 +664,14 @@ export class JsonSchema extends Map {
|
|
|
647
664
|
obj.$required.forEach((key) => {
|
|
648
665
|
this.$required.add(key);
|
|
649
666
|
});
|
|
650
|
-
this
|
|
651
|
-
this
|
|
652
|
-
obj
|
|
653
|
-
this
|
|
654
|
-
this
|
|
655
|
-
this
|
|
656
|
-
this
|
|
657
|
-
this
|
|
667
|
+
__classPrivateFieldSet(this, _JsonSchema_ref, __classPrivateFieldGet(obj, _JsonSchema_ref, "f"), "f");
|
|
668
|
+
__classPrivateFieldSet(this, _JsonSchema_alias, new Map(__classPrivateFieldGet(this, _JsonSchema_alias, "f").entries()), "f");
|
|
669
|
+
__classPrivateFieldGet(obj, _JsonSchema_genericLabels, "f") && (__classPrivateFieldSet(this, _JsonSchema_genericLabels, [...__classPrivateFieldGet(obj, _JsonSchema_genericLabels, "f")], "f"));
|
|
670
|
+
__classPrivateFieldSet(this, _JsonSchema_nestedGenerics, __classPrivateFieldGet(obj, _JsonSchema_nestedGenerics, "f").map((item) => [...item]), "f");
|
|
671
|
+
__classPrivateFieldSet(this, _JsonSchema_target, __classPrivateFieldGet(obj, _JsonSchema_target, "f"), "f");
|
|
672
|
+
__classPrivateFieldSet(this, _JsonSchema_isGeneric, __classPrivateFieldGet(obj, _JsonSchema_isGeneric, "f"), "f");
|
|
673
|
+
__classPrivateFieldSet(this, _JsonSchema_isCollection, __classPrivateFieldGet(obj, _JsonSchema_isCollection, "f"), "f");
|
|
674
|
+
__classPrivateFieldSet(this, _JsonSchema_ref, __classPrivateFieldGet(obj, _JsonSchema_ref, "f"), "f");
|
|
658
675
|
super.set("type", obj.get("type"));
|
|
659
676
|
}
|
|
660
677
|
return this;
|
|
@@ -674,10 +691,10 @@ export class JsonSchema extends Map {
|
|
|
674
691
|
* the function will be called to get the right type.
|
|
675
692
|
*/
|
|
676
693
|
getComputedType() {
|
|
677
|
-
return getComputedType(this
|
|
694
|
+
return getComputedType(__classPrivateFieldGet(this, _JsonSchema_target, "f"));
|
|
678
695
|
}
|
|
679
696
|
getComputedItemType() {
|
|
680
|
-
return this
|
|
697
|
+
return __classPrivateFieldGet(this, _JsonSchema_itemSchema, "f") ? __classPrivateFieldGet(this, _JsonSchema_itemSchema, "f").getComputedType() : this.getComputedType();
|
|
681
698
|
}
|
|
682
699
|
/**
|
|
683
700
|
* Return the Json type as string
|
|
@@ -686,16 +703,17 @@ export class JsonSchema extends Map {
|
|
|
686
703
|
return this.get("type") || getJsonType(this.getComputedType());
|
|
687
704
|
}
|
|
688
705
|
getTarget() {
|
|
689
|
-
return this
|
|
706
|
+
return __classPrivateFieldGet(this, _JsonSchema_target, "f");
|
|
690
707
|
}
|
|
691
708
|
/**
|
|
692
709
|
* Get the symbolic name of the entity
|
|
693
710
|
*/
|
|
694
711
|
getName() {
|
|
695
|
-
return this.get("name") || (this
|
|
712
|
+
return this.get("name") || (__classPrivateFieldGet(this, _JsonSchema_target, "f") ? nameOf(classOf(this.getComputedType())) : "");
|
|
696
713
|
}
|
|
697
714
|
clone() {
|
|
698
715
|
return new JsonSchema(this);
|
|
699
716
|
}
|
|
700
717
|
}
|
|
718
|
+
_JsonSchema_nullable = new WeakMap(), _JsonSchema_genericLabels = new WeakMap(), _JsonSchema_nestedGenerics = new WeakMap(), _JsonSchema_alias = new WeakMap(), _JsonSchema_itemSchema = new WeakMap(), _JsonSchema_target = new WeakMap(), _JsonSchema_isGeneric = new WeakMap(), _JsonSchema_isCollection = new WeakMap(), _JsonSchema_ref = new WeakMap();
|
|
701
719
|
//# sourceMappingURL=JsonSchema.js.map
|