@opra/common 0.25.5 → 0.26.0
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/browser.js +1826 -1338
- package/cjs/document/api-document.js +16 -220
- package/cjs/document/data-type/complex-type-class.js +41 -19
- package/cjs/document/data-type/complex-type.js +1 -1
- package/cjs/document/data-type/data-type.js +2 -1
- package/cjs/document/data-type/enum-type-class.js +15 -12
- package/cjs/document/data-type/enum-type.js +28 -14
- package/cjs/document/data-type/field-class.js +21 -3
- package/cjs/document/data-type/field-decorator.js +0 -19
- package/cjs/document/data-type/mapped-type-class.js +8 -10
- package/cjs/document/data-type/mapped-type.js +1 -1
- package/cjs/document/data-type/simple-type-class.js +17 -8
- package/cjs/document/data-type/simple-type.js +1 -1
- package/cjs/document/data-type/union-type-class.js +15 -13
- package/cjs/document/document-base.js +24 -0
- package/cjs/document/factory/api-document-factory.js +231 -0
- package/cjs/document/factory/type-document-factory.js +324 -0
- package/cjs/document/index.js +7 -1
- package/cjs/document/resource/action-decorator.js +27 -0
- package/cjs/document/resource/collection-class.js +95 -44
- package/cjs/document/resource/collection-decorator.js +182 -0
- package/cjs/document/resource/collection.js +4 -4
- package/cjs/document/resource/container-class.js +82 -0
- package/cjs/document/resource/container-decorator.js +24 -0
- package/cjs/document/resource/container.js +29 -0
- package/cjs/document/resource/crud-resource.js +31 -0
- package/cjs/document/resource/endpoint.js +24 -22
- package/cjs/document/resource/operation-decorator.js +27 -0
- package/cjs/document/resource/parameter.js +51 -0
- package/cjs/document/{decorators/resource.decorator.js → resource/resource-decorator.js} +9 -14
- package/cjs/document/resource/resource.js +20 -5
- package/cjs/document/resource/singleton-class.js +60 -40
- package/cjs/document/resource/singleton-decorator.js +57 -0
- package/cjs/document/resource/singleton.js +4 -4
- package/cjs/document/resource/storage-class.js +11 -17
- package/cjs/document/resource/storage-decorator.js +66 -0
- package/cjs/document/resource/storage.js +3 -3
- package/cjs/document/type-document.js +195 -0
- package/cjs/exception/http-errors/internal-server.error.js +1 -0
- package/cjs/exception/wrap-exception.js +2 -1
- package/cjs/helpers/responsive-map.js +3 -3
- package/cjs/http/opra-url-path.js +2 -1
- package/cjs/schema/document/document-base.interface.js +2 -0
- package/cjs/schema/document/type-document.interface.js +2 -0
- package/cjs/schema/opra-schema.ns.js +3 -1
- package/cjs/schema/type-guards.js +3 -3
- package/esm/document/api-document.js +16 -220
- package/esm/document/data-type/complex-type-class.js +40 -19
- package/esm/document/data-type/complex-type.js +1 -1
- package/esm/document/data-type/data-type.js +2 -1
- package/esm/document/data-type/enum-type-class.js +15 -12
- package/esm/document/data-type/enum-type.js +26 -12
- package/esm/document/data-type/field-class.js +20 -3
- package/esm/document/data-type/field-decorator.js +0 -19
- package/esm/document/data-type/mapped-type-class.js +9 -11
- package/esm/document/data-type/mapped-type.js +1 -1
- package/esm/document/data-type/simple-type-class.js +15 -6
- package/esm/document/data-type/simple-type.js +1 -1
- package/esm/document/data-type/union-type-class.js +11 -9
- package/esm/document/document-base.js +20 -0
- package/esm/document/factory/api-document-factory.js +227 -0
- package/esm/document/factory/type-document-factory.js +320 -0
- package/esm/document/index.js +7 -1
- package/esm/document/resource/action-decorator.js +23 -0
- package/esm/document/resource/collection-class.js +95 -44
- package/esm/document/resource/collection-decorator.js +178 -0
- package/esm/document/resource/collection.js +4 -4
- package/esm/document/resource/container-class.js +78 -0
- package/esm/document/resource/container-decorator.js +20 -0
- package/esm/document/resource/container.js +25 -0
- package/esm/document/resource/crud-resource.js +27 -0
- package/esm/document/resource/endpoint.js +22 -20
- package/esm/document/resource/operation-decorator.js +23 -0
- package/esm/document/resource/parameter.js +46 -0
- package/esm/document/resource/resource-decorator.js +28 -0
- package/esm/document/resource/resource.js +20 -5
- package/esm/document/resource/singleton-class.js +58 -38
- package/esm/document/resource/singleton-decorator.js +53 -0
- package/esm/document/resource/singleton.js +4 -4
- package/esm/document/resource/storage-class.js +9 -15
- package/esm/document/resource/storage-decorator.js +62 -0
- package/esm/document/resource/storage.js +3 -3
- package/esm/document/type-document.js +191 -0
- package/esm/exception/http-errors/internal-server.error.js +1 -0
- package/esm/exception/wrap-exception.js +2 -1
- package/esm/helpers/responsive-map.js +3 -3
- package/esm/http/opra-url-path.js +1 -1
- package/esm/schema/document/document-base.interface.js +1 -0
- package/esm/schema/document/type-document.interface.js +1 -0
- package/esm/schema/opra-schema.ns.js +3 -1
- package/esm/schema/type-guards.js +1 -1
- package/package.json +2 -2
- package/types/document/api-document.d.ts +32 -73
- package/types/document/data-type/complex-type-class.d.ts +5 -5
- package/types/document/data-type/complex-type.d.ts +8 -3
- package/types/document/{decorators → data-type}/complex-type.decorator.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +11 -1
- package/types/document/data-type/enum-type-class.d.ts +6 -6
- package/types/document/data-type/enum-type.d.ts +12 -6
- package/types/document/data-type/field-class.d.ts +9 -1
- package/types/document/data-type/field-decorator.d.ts +1 -1
- package/types/document/data-type/field.d.ts +4 -3
- package/types/document/data-type/mapped-type-class.d.ts +5 -9
- package/types/document/data-type/mapped-type.d.ts +6 -7
- package/types/document/data-type/simple-type-class.d.ts +6 -3
- package/types/document/{decorators → data-type}/simple-type.decorator.d.ts +1 -1
- package/types/document/data-type/union-type-class.d.ts +2 -8
- package/types/document/data-type/union-type.d.ts +7 -6
- package/types/document/document-base.d.ts +10 -0
- package/types/document/factory/api-document-factory.d.ts +50 -0
- package/types/document/factory/type-document-factory.d.ts +56 -0
- package/types/document/index.d.ts +7 -1
- package/types/document/resource/action-decorator.d.ts +6 -0
- package/types/document/resource/collection-class.d.ts +17 -12
- package/types/document/resource/collection-decorator.d.ts +192 -0
- package/types/document/resource/collection.d.ts +11 -19
- package/types/document/resource/container-class.d.ts +66 -0
- package/types/document/resource/container-decorator.d.ts +37 -0
- package/types/document/resource/container.d.ts +25 -0
- package/types/document/resource/crud-resource.d.ts +16 -0
- package/types/document/resource/endpoint.d.ts +21 -21
- package/types/document/resource/operation-decorator.d.ts +6 -0
- package/types/document/resource/parameter.d.ts +35 -0
- package/types/document/resource/resource-decorator.d.ts +32 -0
- package/types/document/resource/resource.d.ts +15 -13
- package/types/document/resource/singleton-class.d.ts +15 -14
- package/types/document/resource/singleton-decorator.d.ts +125 -0
- package/types/document/resource/singleton.d.ts +11 -16
- package/types/document/resource/storage-class.d.ts +13 -6
- package/types/document/resource/storage-decorator.d.ts +98 -0
- package/types/document/resource/storage.d.ts +9 -12
- package/types/document/type-document.d.ts +68 -0
- package/types/http/opra-url-path.d.ts +1 -1
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/data-type/data-type.interface.d.ts +3 -3
- package/types/schema/data-type/enum-type.interface.d.ts +6 -7
- package/types/schema/data-type/mapped-type.interface.d.ts +4 -3
- package/types/schema/data-type/simple-type.interface.d.ts +3 -3
- package/types/schema/data-type/union-type.interface.d.ts +6 -4
- package/types/schema/document/api-document.interface.d.ts +11 -0
- package/types/schema/document/document-base.interface.d.ts +24 -0
- package/types/schema/document/type-document.interface.d.ts +6 -0
- package/types/schema/opra-schema.ns.d.ts +3 -1
- package/types/schema/resource/collection.interface.d.ts +31 -31
- package/types/schema/resource/container.interface.d.ts +4 -3
- package/types/schema/resource/resource.interface.d.ts +1 -1
- package/types/schema/resource/singleton.interface.d.ts +15 -10
- package/types/schema/resource/storage.interface.d.ts +49 -45
- package/types/schema/type-guards.d.ts +3 -2
- package/cjs/document/decorators/build-operation-decorator.js +0 -27
- package/cjs/document/decorators/collection-decorator.js +0 -30
- package/cjs/document/decorators/singleton.decorator.js +0 -25
- package/cjs/document/decorators/storage.decorator.js +0 -27
- package/cjs/document/factory/add-references.js +0 -20
- package/cjs/document/factory/create-document.js +0 -83
- package/cjs/document/factory/factory.js +0 -66
- package/cjs/document/factory/import-resource-class.js +0 -54
- package/cjs/document/factory/import-type-class.js +0 -146
- package/cjs/document/factory/index.js +0 -4
- package/cjs/document/factory/process-resources.js +0 -70
- package/cjs/document/factory/process-types.js +0 -191
- package/cjs/document/utils/generate-codec.js +0 -39
- package/esm/document/decorators/build-operation-decorator.js +0 -23
- package/esm/document/decorators/collection-decorator.js +0 -26
- package/esm/document/decorators/resource.decorator.js +0 -33
- package/esm/document/decorators/singleton.decorator.js +0 -21
- package/esm/document/decorators/storage.decorator.js +0 -23
- package/esm/document/factory/add-references.js +0 -16
- package/esm/document/factory/create-document.js +0 -77
- package/esm/document/factory/factory.js +0 -62
- package/esm/document/factory/import-resource-class.js +0 -48
- package/esm/document/factory/import-type-class.js +0 -136
- package/esm/document/factory/index.js +0 -1
- package/esm/document/factory/process-resources.js +0 -63
- package/esm/document/factory/process-types.js +0 -185
- package/esm/document/utils/generate-codec.js +0 -33
- package/types/document/decorators/build-operation-decorator.d.ts +0 -13
- package/types/document/decorators/collection-decorator.d.ts +0 -33
- package/types/document/decorators/resource.decorator.d.ts +0 -9
- package/types/document/decorators/singleton.decorator.d.ts +0 -25
- package/types/document/decorators/storage.decorator.d.ts +0 -25
- package/types/document/factory/add-references.d.ts +0 -4
- package/types/document/factory/create-document.d.ts +0 -12
- package/types/document/factory/factory.d.ts +0 -63
- package/types/document/factory/import-resource-class.d.ts +0 -10
- package/types/document/factory/import-type-class.d.ts +0 -17
- package/types/document/factory/index.d.ts +0 -1
- package/types/document/factory/process-resources.d.ts +0 -9
- package/types/document/factory/process-types.d.ts +0 -6
- package/types/document/utils/generate-codec.d.ts +0 -10
- package/types/schema/document.interface.d.ts +0 -34
- /package/cjs/document/{decorators → data-type}/complex-type.decorator.js +0 -0
- /package/cjs/document/{decorators → data-type}/simple-type.decorator.js +0 -0
- /package/cjs/schema/{document.interface.js → document/api-document.interface.js} +0 -0
- /package/esm/document/{decorators → data-type}/complex-type.decorator.js +0 -0
- /package/esm/document/{decorators → data-type}/simple-type.decorator.js +0 -0
- /package/esm/schema/{document.interface.js → document/api-document.interface.js} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createActionDecorator = void 0;
|
|
4
|
+
const constants_js_1 = require("../constants.js");
|
|
5
|
+
function createActionDecorator(options, bannedProperties, list) {
|
|
6
|
+
const decorator = ((target, propertyKey) => {
|
|
7
|
+
if (typeof propertyKey === 'string' && bannedProperties.includes(propertyKey))
|
|
8
|
+
throw new TypeError(`The "${propertyKey}" property is reserved for "${propertyKey}" operations and cannot be used as an action'`);
|
|
9
|
+
const resourceMetadata = (Reflect.getOwnMetadata(constants_js_1.RESOURCE_METADATA, target.constructor) || {});
|
|
10
|
+
resourceMetadata.actions = resourceMetadata.actions || {};
|
|
11
|
+
const actionMeta = { ...options };
|
|
12
|
+
resourceMetadata.actions[propertyKey] = actionMeta;
|
|
13
|
+
for (const fn of list)
|
|
14
|
+
fn(actionMeta);
|
|
15
|
+
Reflect.defineMetadata(constants_js_1.RESOURCE_METADATA, resourceMetadata, target.constructor);
|
|
16
|
+
});
|
|
17
|
+
decorator.Parameter = (name, arg0) => {
|
|
18
|
+
const parameterOptions = typeof arg0 === 'string' || typeof arg0 === 'function' ? { type: arg0 } : { ...arg0 };
|
|
19
|
+
list.push((operationMeta) => {
|
|
20
|
+
operationMeta.parameters = operationMeta.parameters || {};
|
|
21
|
+
operationMeta.parameters[name] = { ...parameterOptions };
|
|
22
|
+
});
|
|
23
|
+
return decorator;
|
|
24
|
+
};
|
|
25
|
+
return decorator;
|
|
26
|
+
}
|
|
27
|
+
exports.createActionDecorator = createActionDecorator;
|
|
@@ -5,20 +5,14 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const vg = tslib_1.__importStar(require("valgen"));
|
|
6
6
|
const index_js_1 = require("../../exception/index.js");
|
|
7
7
|
const index_js_2 = require("../../filter/index.js");
|
|
8
|
-
const object_utils_js_1 = require("../../helpers/object-utils.js");
|
|
9
8
|
const index_js_3 = require("../../i18n/index.js");
|
|
10
9
|
const index_js_4 = require("../../schema/index.js");
|
|
11
10
|
const simple_type_js_1 = require("../data-type/simple-type.js");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
super(document, init);
|
|
17
|
-
this._decoders = {};
|
|
18
|
-
this._encoders = {};
|
|
11
|
+
const crud_resource_js_1 = require("./crud-resource.js");
|
|
12
|
+
class CollectionClass extends crud_resource_js_1.CrudResource {
|
|
13
|
+
constructor(parent, init) {
|
|
14
|
+
super(parent, init);
|
|
19
15
|
this.kind = index_js_4.OpraSchema.Collection.Kind;
|
|
20
|
-
this.controller = init.controller;
|
|
21
|
-
this.operations = { ...init.operations };
|
|
22
16
|
const dataType = this.type = init.type;
|
|
23
17
|
// Validate key fields
|
|
24
18
|
this.primaryKey = init.primaryKey
|
|
@@ -31,15 +25,98 @@ class CollectionClass extends resource_js_1.Resource {
|
|
|
31
25
|
if (!(field?.type instanceof simple_type_js_1.SimpleType))
|
|
32
26
|
throw new TypeError(`Only Simple type allowed for primary keys but "${f}" is a ${field.type.kind}`);
|
|
33
27
|
});
|
|
28
|
+
// ------------------
|
|
29
|
+
let endpoint = this.operations.get('create');
|
|
30
|
+
if (endpoint) {
|
|
31
|
+
endpoint.returnType = this.type;
|
|
32
|
+
endpoint.decode = this.type.generateCodec('decode', {
|
|
33
|
+
partial: true,
|
|
34
|
+
pick: endpoint.inputPickFields,
|
|
35
|
+
omit: endpoint.inputOmitFields,
|
|
36
|
+
});
|
|
37
|
+
endpoint.encode = this.type.generateCodec('encode', {
|
|
38
|
+
partial: true,
|
|
39
|
+
pick: endpoint.outputPickFields,
|
|
40
|
+
omit: endpoint.outputOmitFields,
|
|
41
|
+
});
|
|
42
|
+
endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
|
|
43
|
+
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
44
|
+
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
45
|
+
}
|
|
46
|
+
// ------------------
|
|
47
|
+
endpoint = this.operations.get('deleteMany');
|
|
48
|
+
if (endpoint) {
|
|
49
|
+
endpoint.defineParameter('filter', { type: 'string', isBuiltin: true });
|
|
50
|
+
}
|
|
51
|
+
// ------------------
|
|
52
|
+
endpoint = this.operations.get('get');
|
|
53
|
+
if (endpoint) {
|
|
54
|
+
endpoint.returnType = this.type;
|
|
55
|
+
endpoint.encode = this.type.generateCodec('encode', {
|
|
56
|
+
partial: true,
|
|
57
|
+
pick: endpoint.outputPickFields,
|
|
58
|
+
omit: endpoint.outputOmitFields,
|
|
59
|
+
});
|
|
60
|
+
endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
|
|
61
|
+
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
62
|
+
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
63
|
+
}
|
|
64
|
+
// ------------------
|
|
65
|
+
endpoint = this.operations.get('findMany');
|
|
66
|
+
if (endpoint) {
|
|
67
|
+
endpoint.returnType = this.type;
|
|
68
|
+
endpoint.encode = vg.isArray(this.type.generateCodec('encode', {
|
|
69
|
+
partial: true,
|
|
70
|
+
pick: endpoint.outputPickFields,
|
|
71
|
+
omit: endpoint.outputOmitFields,
|
|
72
|
+
}));
|
|
73
|
+
endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
|
|
74
|
+
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
75
|
+
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
76
|
+
endpoint.defineParameter('sort', { type: 'string', isArray: true, isBuiltin: true });
|
|
77
|
+
endpoint.defineParameter('filter', { type: 'string', isBuiltin: true });
|
|
78
|
+
endpoint.defineParameter('limit', { type: 'integer', isBuiltin: true });
|
|
79
|
+
endpoint.defineParameter('skip', { type: 'integer', isBuiltin: true });
|
|
80
|
+
endpoint.defineParameter('distinct', { type: 'boolean', isBuiltin: true });
|
|
81
|
+
endpoint.defineParameter('count', { type: 'boolean', isBuiltin: true });
|
|
82
|
+
}
|
|
83
|
+
// ------------------
|
|
84
|
+
endpoint = this.operations.get('update');
|
|
85
|
+
if (endpoint) {
|
|
86
|
+
endpoint.returnType = this.type;
|
|
87
|
+
endpoint.decode = this.type.generateCodec('decode', {
|
|
88
|
+
pick: endpoint.inputPickFields,
|
|
89
|
+
omit: endpoint.inputOmitFields,
|
|
90
|
+
});
|
|
91
|
+
endpoint.encode = this.type.generateCodec('encode', {
|
|
92
|
+
partial: true,
|
|
93
|
+
pick: endpoint.outputPickFields,
|
|
94
|
+
omit: endpoint.outputOmitFields,
|
|
95
|
+
});
|
|
96
|
+
endpoint.defineParameter('pick', { type: 'string', isArray: true, isBuiltin: true });
|
|
97
|
+
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
98
|
+
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
99
|
+
}
|
|
100
|
+
// ------------------
|
|
101
|
+
endpoint = this.operations.get('updateMany');
|
|
102
|
+
if (endpoint) {
|
|
103
|
+
endpoint.decode = this.type.generateCodec('decode', {
|
|
104
|
+
pick: endpoint.inputPickFields,
|
|
105
|
+
omit: endpoint.inputOmitFields,
|
|
106
|
+
});
|
|
107
|
+
endpoint.defineParameter('filter', { type: 'string', isBuiltin: true });
|
|
108
|
+
}
|
|
34
109
|
}
|
|
35
|
-
|
|
110
|
+
getOperation(name) {
|
|
111
|
+
return super.getOperation(name);
|
|
112
|
+
}
|
|
113
|
+
exportSchema(options) {
|
|
36
114
|
return {
|
|
37
|
-
...super.exportSchema(),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
operations: this.operations,
|
|
115
|
+
...super.exportSchema(options),
|
|
116
|
+
type: this.type.name || 'object',
|
|
117
|
+
...{
|
|
41
118
|
primaryKey: this.primaryKey
|
|
42
|
-
}
|
|
119
|
+
}
|
|
43
120
|
};
|
|
44
121
|
}
|
|
45
122
|
parseKeyValue(value) {
|
|
@@ -83,7 +160,7 @@ class CollectionClass extends resource_js_1.Resource {
|
|
|
83
160
|
const normalized = this.type.normalizeFieldPath(fields);
|
|
84
161
|
if (!normalized)
|
|
85
162
|
return;
|
|
86
|
-
const findManyOp = this.
|
|
163
|
+
const findManyOp = this.getOperation('findMany');
|
|
87
164
|
const sortFields = findManyOp && findManyOp.sortFields;
|
|
88
165
|
(Array.isArray(normalized) ? normalized : [normalized]).forEach(field => {
|
|
89
166
|
if (!sortFields?.find(x => x === field))
|
|
@@ -102,7 +179,7 @@ class CollectionClass extends resource_js_1.Resource {
|
|
|
102
179
|
if (!(ast.left instanceof index_js_2.OpraFilter.QualifiedIdentifier && ast.left.field))
|
|
103
180
|
throw new TypeError(`Invalid filter query. Left side should be a data field.`);
|
|
104
181
|
// Check if filtering accepted for given field
|
|
105
|
-
const findManyOp = this.
|
|
182
|
+
const findManyOp = this.getOperation('findMany');
|
|
106
183
|
const fieldLower = ast.left.value.toLowerCase();
|
|
107
184
|
const filterDef = (findManyOp && findManyOp.filters || [])
|
|
108
185
|
.find(f => f.field.toLowerCase() === fieldLower);
|
|
@@ -144,31 +221,5 @@ class CollectionClass extends resource_js_1.Resource {
|
|
|
144
221
|
}
|
|
145
222
|
return ast;
|
|
146
223
|
}
|
|
147
|
-
getDecoder(endpoint) {
|
|
148
|
-
let decoder = this._decoders[endpoint];
|
|
149
|
-
if (decoder)
|
|
150
|
-
return decoder;
|
|
151
|
-
const options = {
|
|
152
|
-
partial: endpoint !== 'create'
|
|
153
|
-
};
|
|
154
|
-
if (endpoint !== 'create')
|
|
155
|
-
options.omit = [...this.primaryKey];
|
|
156
|
-
decoder = (0, generate_codec_js_1.generateCodec)(this.type, 'decode', options);
|
|
157
|
-
this._decoders[endpoint] = decoder;
|
|
158
|
-
return decoder;
|
|
159
|
-
}
|
|
160
|
-
getEncoder(endpoint) {
|
|
161
|
-
let encoder = this._encoders[endpoint];
|
|
162
|
-
if (encoder)
|
|
163
|
-
return encoder;
|
|
164
|
-
const options = {
|
|
165
|
-
partial: true
|
|
166
|
-
};
|
|
167
|
-
encoder = (0, generate_codec_js_1.generateCodec)(this.type, 'encode', options);
|
|
168
|
-
if (endpoint === 'findMany')
|
|
169
|
-
return vg.isArray(encoder);
|
|
170
|
-
this._encoders[endpoint] = encoder;
|
|
171
|
-
return encoder;
|
|
172
|
-
}
|
|
173
224
|
}
|
|
174
225
|
exports.CollectionClass = CollectionClass;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CollectionDecorator = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const index_js_2 = require("../../schema/index.js");
|
|
6
|
+
const action_decorator_js_1 = require("./action-decorator.js");
|
|
7
|
+
const operation_decorator_js_1 = require("./operation-decorator.js");
|
|
8
|
+
const resource_decorator_js_1 = require("./resource-decorator.js");
|
|
9
|
+
const operationProperties = ['create', 'delete', 'deleteMany', 'get', 'findMany', 'update', 'updateMany'];
|
|
10
|
+
function CollectionDecorator(type, options) {
|
|
11
|
+
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_2.OpraSchema.Collection.Kind, { ...options, type });
|
|
12
|
+
}
|
|
13
|
+
exports.CollectionDecorator = CollectionDecorator;
|
|
14
|
+
Object.assign(CollectionDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
15
|
+
/*
|
|
16
|
+
* Action PropertyDecorator
|
|
17
|
+
*/
|
|
18
|
+
(function (CollectionDecorator) {
|
|
19
|
+
/**
|
|
20
|
+
* Action PropertyDecorator
|
|
21
|
+
*/
|
|
22
|
+
function Action(options) {
|
|
23
|
+
const list = [];
|
|
24
|
+
return (0, action_decorator_js_1.createActionDecorator)(options, operationProperties, list);
|
|
25
|
+
}
|
|
26
|
+
CollectionDecorator.Action = Action;
|
|
27
|
+
function Create(options) {
|
|
28
|
+
const list = [];
|
|
29
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('create', options, list);
|
|
30
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
31
|
+
list.push(operationMeta => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
32
|
+
return decorator;
|
|
33
|
+
};
|
|
34
|
+
decorator.InputPickFields = (...fields) => {
|
|
35
|
+
list.push(operationMeta => operationMeta.inputPickFields = fields);
|
|
36
|
+
return decorator;
|
|
37
|
+
};
|
|
38
|
+
decorator.InputOmitFields = (...fields) => {
|
|
39
|
+
list.push(operationMeta => operationMeta.inputOmitFields = fields);
|
|
40
|
+
return decorator;
|
|
41
|
+
};
|
|
42
|
+
decorator.OutputPickFields = (...fields) => {
|
|
43
|
+
list.push(operationMeta => operationMeta.outputPickFields = fields);
|
|
44
|
+
return decorator;
|
|
45
|
+
};
|
|
46
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
47
|
+
list.push(operationMeta => operationMeta.outputOmitFields = fields);
|
|
48
|
+
return decorator;
|
|
49
|
+
};
|
|
50
|
+
return decorator;
|
|
51
|
+
}
|
|
52
|
+
CollectionDecorator.Create = Create;
|
|
53
|
+
function Delete(options) {
|
|
54
|
+
const list = [];
|
|
55
|
+
return (0, operation_decorator_js_1.createOperationDecorator)('delete', options, list);
|
|
56
|
+
}
|
|
57
|
+
CollectionDecorator.Delete = Delete;
|
|
58
|
+
function DeleteMany(options) {
|
|
59
|
+
const list = [];
|
|
60
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('deleteMany', options, list);
|
|
61
|
+
decorator.Filter = (field, operators, notes) => {
|
|
62
|
+
if (typeof operators === 'string')
|
|
63
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
64
|
+
list.push(operationMeta => {
|
|
65
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
66
|
+
operationMeta.filters.push((0, index_js_1.omitUndefined)({ field, operators, notes }));
|
|
67
|
+
});
|
|
68
|
+
return decorator;
|
|
69
|
+
};
|
|
70
|
+
return decorator;
|
|
71
|
+
}
|
|
72
|
+
CollectionDecorator.DeleteMany = DeleteMany;
|
|
73
|
+
function Get(options) {
|
|
74
|
+
const list = [];
|
|
75
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('get', options, list);
|
|
76
|
+
decorator.OutputPickFields = (...fields) => {
|
|
77
|
+
list.push(operationMeta => operationMeta.outputPickFields = fields);
|
|
78
|
+
return decorator;
|
|
79
|
+
};
|
|
80
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
81
|
+
list.push(operationMeta => operationMeta.outputOmitFields = fields);
|
|
82
|
+
return decorator;
|
|
83
|
+
};
|
|
84
|
+
return decorator;
|
|
85
|
+
}
|
|
86
|
+
CollectionDecorator.Get = Get;
|
|
87
|
+
function FindMany(options) {
|
|
88
|
+
const list = [];
|
|
89
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('findMany', options, list);
|
|
90
|
+
decorator.SortFields = (...fields) => {
|
|
91
|
+
list.push(operationMeta => operationMeta.sortFields = fields);
|
|
92
|
+
return decorator;
|
|
93
|
+
};
|
|
94
|
+
decorator.DefaultSort = (...fields) => {
|
|
95
|
+
list.push(operationMeta => operationMeta.defaultSort = fields);
|
|
96
|
+
return decorator;
|
|
97
|
+
};
|
|
98
|
+
decorator.Filter = (field, operators, notes) => {
|
|
99
|
+
if (typeof operators === 'string')
|
|
100
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
101
|
+
list.push(operationMeta => {
|
|
102
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
103
|
+
operationMeta.filters.push((0, index_js_1.omitUndefined)({ field, operators, notes }));
|
|
104
|
+
});
|
|
105
|
+
return decorator;
|
|
106
|
+
};
|
|
107
|
+
decorator.OutputPickFields = (...fields) => {
|
|
108
|
+
list.push(operationMeta => operationMeta.outputPickFields = fields);
|
|
109
|
+
return decorator;
|
|
110
|
+
};
|
|
111
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
112
|
+
list.push(operationMeta => operationMeta.outputOmitFields = fields);
|
|
113
|
+
return decorator;
|
|
114
|
+
};
|
|
115
|
+
return decorator;
|
|
116
|
+
}
|
|
117
|
+
CollectionDecorator.FindMany = FindMany;
|
|
118
|
+
})(CollectionDecorator || (exports.CollectionDecorator = CollectionDecorator = {}));
|
|
119
|
+
/*
|
|
120
|
+
* Update PropertyDecorator
|
|
121
|
+
*/
|
|
122
|
+
(function (CollectionDecorator) {
|
|
123
|
+
function Update(options) {
|
|
124
|
+
const list = [];
|
|
125
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('update', options, list);
|
|
126
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
127
|
+
list.push(operationMeta => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
128
|
+
return decorator;
|
|
129
|
+
};
|
|
130
|
+
decorator.InputPickFields = (...fields) => {
|
|
131
|
+
list.push(operationMeta => operationMeta.inputPickFields = fields);
|
|
132
|
+
return decorator;
|
|
133
|
+
};
|
|
134
|
+
decorator.InputOmitFields = (...fields) => {
|
|
135
|
+
list.push(operationMeta => operationMeta.inputOmitFields = fields);
|
|
136
|
+
return decorator;
|
|
137
|
+
};
|
|
138
|
+
decorator.OutputPickFields = (...fields) => {
|
|
139
|
+
list.push(operationMeta => operationMeta.outputPickFields = fields);
|
|
140
|
+
return decorator;
|
|
141
|
+
};
|
|
142
|
+
decorator.OutputOmitFields = (...fields) => {
|
|
143
|
+
list.push(operationMeta => operationMeta.outputOmitFields = fields);
|
|
144
|
+
return decorator;
|
|
145
|
+
};
|
|
146
|
+
return decorator;
|
|
147
|
+
}
|
|
148
|
+
CollectionDecorator.Update = Update;
|
|
149
|
+
})(CollectionDecorator || (exports.CollectionDecorator = CollectionDecorator = {}));
|
|
150
|
+
/*
|
|
151
|
+
* UpdateMany PropertyDecorator
|
|
152
|
+
*/
|
|
153
|
+
(function (CollectionDecorator) {
|
|
154
|
+
function UpdateMany(arg0) {
|
|
155
|
+
const list = [];
|
|
156
|
+
const options = typeof arg0 === 'string' ? { description: arg0 } : { ...arg0 };
|
|
157
|
+
const decorator = (0, operation_decorator_js_1.createOperationDecorator)('updateMany', options, list);
|
|
158
|
+
decorator.InputMaxContentSize = (sizeInBytes) => {
|
|
159
|
+
list.push(operationMeta => operationMeta.inputMaxContentSize = sizeInBytes);
|
|
160
|
+
return decorator;
|
|
161
|
+
};
|
|
162
|
+
decorator.InputPickFields = (...fields) => {
|
|
163
|
+
list.push(operationMeta => operationMeta.inputPickFields = fields);
|
|
164
|
+
return decorator;
|
|
165
|
+
};
|
|
166
|
+
decorator.InputOmitFields = (...fields) => {
|
|
167
|
+
list.push(operationMeta => operationMeta.inputOmitFields = fields);
|
|
168
|
+
return decorator;
|
|
169
|
+
};
|
|
170
|
+
decorator.Filter = (field, operators, notes) => {
|
|
171
|
+
if (typeof operators === 'string')
|
|
172
|
+
operators = operators.split(/\s*[,| ]\s*/);
|
|
173
|
+
list.push(operationMeta => {
|
|
174
|
+
operationMeta.filters = operationMeta.filters || [];
|
|
175
|
+
operationMeta.filters.push((0, index_js_1.omitUndefined)({ field, operators, notes }));
|
|
176
|
+
});
|
|
177
|
+
return decorator;
|
|
178
|
+
};
|
|
179
|
+
return decorator;
|
|
180
|
+
}
|
|
181
|
+
CollectionDecorator.UpdateMany = UpdateMany;
|
|
182
|
+
})(CollectionDecorator || (exports.CollectionDecorator = CollectionDecorator = {}));
|
|
@@ -4,21 +4,21 @@ exports.Collection = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
6
|
const constants_js_1 = require("../constants.js");
|
|
7
|
-
const collection_decorator_js_1 = require("../decorators/collection-decorator.js");
|
|
8
7
|
const collection_class_js_1 = require("./collection-class.js");
|
|
8
|
+
const collection_decorator_js_1 = require("./collection-decorator.js");
|
|
9
9
|
/**
|
|
10
10
|
* @class Collection
|
|
11
11
|
* @decorator Collection
|
|
12
12
|
*/
|
|
13
13
|
exports.Collection = function (...args) {
|
|
14
|
-
//
|
|
14
|
+
// ClassDecorator
|
|
15
15
|
if (!this) {
|
|
16
16
|
const [type, options] = args;
|
|
17
17
|
return exports.Collection[constants_js_1.DECORATOR].call(undefined, type, options);
|
|
18
18
|
}
|
|
19
19
|
// Constructor
|
|
20
|
-
const [
|
|
21
|
-
(0, putil_merge_1.default)(this, new collection_class_js_1.CollectionClass(
|
|
20
|
+
const [parent, init] = args;
|
|
21
|
+
(0, putil_merge_1.default)(this, new collection_class_js_1.CollectionClass(parent, init), { descriptor: true });
|
|
22
22
|
};
|
|
23
23
|
exports.Collection.prototype = collection_class_js_1.CollectionClass.prototype;
|
|
24
24
|
Object.assign(exports.Collection, collection_decorator_js_1.CollectionDecorator);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContainerClass = void 0;
|
|
4
|
+
const index_js_1 = require("../../exception/index.js");
|
|
5
|
+
const index_js_2 = require("../../helpers/index.js");
|
|
6
|
+
const index_js_3 = require("../../schema/index.js");
|
|
7
|
+
const resource_js_1 = require("./resource.js");
|
|
8
|
+
class ContainerClass extends resource_js_1.Resource {
|
|
9
|
+
constructor(owner, init) {
|
|
10
|
+
super(owner instanceof ContainerClass ? owner.document : owner, init);
|
|
11
|
+
this.kind = index_js_3.OpraSchema.Container.Kind;
|
|
12
|
+
this.resources = new index_js_2.ResponsiveMap();
|
|
13
|
+
this.parent = owner instanceof ContainerClass ? owner : undefined;
|
|
14
|
+
}
|
|
15
|
+
exportSchema(options) {
|
|
16
|
+
const schema = super.exportSchema(options);
|
|
17
|
+
if (this.resources.size) {
|
|
18
|
+
const resources = schema.resources = {};
|
|
19
|
+
for (const [name, r] of this.resources.entries()) {
|
|
20
|
+
resources[name] = r.exportSchema(options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return schema;
|
|
24
|
+
}
|
|
25
|
+
getResource(path, silent) {
|
|
26
|
+
let resource;
|
|
27
|
+
if (path.includes('/')) {
|
|
28
|
+
const arr = path.split('/');
|
|
29
|
+
let i;
|
|
30
|
+
const l = arr.length;
|
|
31
|
+
let container = this;
|
|
32
|
+
for (i = 0; i < l; i++) {
|
|
33
|
+
resource = container.resources.get(arr[i]);
|
|
34
|
+
if (resource instanceof ContainerClass)
|
|
35
|
+
container = resource;
|
|
36
|
+
else
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
// If no resource found or walking through path not completed
|
|
40
|
+
if (!resource || i < l - 1)
|
|
41
|
+
resource = undefined;
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
resource = this.resources.get(path);
|
|
45
|
+
if (resource || silent)
|
|
46
|
+
return resource;
|
|
47
|
+
throw new index_js_1.ResourceNotFoundError(path);
|
|
48
|
+
}
|
|
49
|
+
getContainer(path, silent) {
|
|
50
|
+
const t = this.getResource(path);
|
|
51
|
+
if (!t && silent)
|
|
52
|
+
return;
|
|
53
|
+
if (t && t.kind === index_js_3.OpraSchema.Container.Kind)
|
|
54
|
+
return t;
|
|
55
|
+
throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Container`);
|
|
56
|
+
}
|
|
57
|
+
getCollection(path, silent) {
|
|
58
|
+
const t = this.getResource(path);
|
|
59
|
+
if (!t && silent)
|
|
60
|
+
return;
|
|
61
|
+
if (t && t.kind === index_js_3.OpraSchema.Collection.Kind)
|
|
62
|
+
return t;
|
|
63
|
+
throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Collection`);
|
|
64
|
+
}
|
|
65
|
+
getSingleton(path, silent) {
|
|
66
|
+
const t = this.getResource(path);
|
|
67
|
+
if (!t && silent)
|
|
68
|
+
return;
|
|
69
|
+
if (t && t.kind === index_js_3.OpraSchema.Singleton.Kind)
|
|
70
|
+
return t;
|
|
71
|
+
throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Singleton`);
|
|
72
|
+
}
|
|
73
|
+
getStorage(path, silent) {
|
|
74
|
+
const t = this.getResource(path);
|
|
75
|
+
if (!t && silent)
|
|
76
|
+
return;
|
|
77
|
+
if (t && t.kind === index_js_3.OpraSchema.Storage.Kind)
|
|
78
|
+
return t;
|
|
79
|
+
throw new index_js_1.NotAcceptableError(`Resource type "${t.name}" is not a Storage`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ContainerClass = ContainerClass;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContainerDecorator = void 0;
|
|
4
|
+
const index_js_1 = require("../../schema/index.js");
|
|
5
|
+
const action_decorator_js_1 = require("./action-decorator.js");
|
|
6
|
+
const resource_decorator_js_1 = require("./resource-decorator.js");
|
|
7
|
+
function ContainerDecorator(options) {
|
|
8
|
+
return (0, resource_decorator_js_1.ResourceDecorator)(index_js_1.OpraSchema.Container.Kind, options);
|
|
9
|
+
}
|
|
10
|
+
exports.ContainerDecorator = ContainerDecorator;
|
|
11
|
+
Object.assign(ContainerDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
12
|
+
/*
|
|
13
|
+
* Action PropertyDecorator
|
|
14
|
+
*/
|
|
15
|
+
(function (ContainerDecorator) {
|
|
16
|
+
/**
|
|
17
|
+
* Action PropertyDecorator
|
|
18
|
+
*/
|
|
19
|
+
function Action(options) {
|
|
20
|
+
const list = [];
|
|
21
|
+
return (0, action_decorator_js_1.createActionDecorator)(options, [], list);
|
|
22
|
+
}
|
|
23
|
+
ContainerDecorator.Action = Action;
|
|
24
|
+
})(ContainerDecorator || (exports.ContainerDecorator = ContainerDecorator = {}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Container = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
6
|
+
const constants_js_1 = require("../constants.js");
|
|
7
|
+
const container_class_js_1 = require("./container-class.js");
|
|
8
|
+
const container_decorator_js_1 = require("./container-decorator.js");
|
|
9
|
+
/**
|
|
10
|
+
* @class Container
|
|
11
|
+
* @decorator Container
|
|
12
|
+
*/
|
|
13
|
+
exports.Container = function (...args) {
|
|
14
|
+
// ClassDecorator
|
|
15
|
+
if (!this) {
|
|
16
|
+
const [options] = args;
|
|
17
|
+
return exports.Container[constants_js_1.DECORATOR].call(undefined, options);
|
|
18
|
+
}
|
|
19
|
+
// Constructor
|
|
20
|
+
const [parent, init] = args;
|
|
21
|
+
(0, putil_merge_1.default)(this, new container_class_js_1.ContainerClass(parent, init), { descriptor: true });
|
|
22
|
+
if (init.resources) {
|
|
23
|
+
const container = this;
|
|
24
|
+
init.resources.forEach(r => container.resources.set(r.name, r));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.Container.prototype = container_class_js_1.ContainerClass.prototype;
|
|
28
|
+
Object.assign(exports.Container, container_decorator_js_1.ContainerDecorator);
|
|
29
|
+
exports.Container[constants_js_1.DECORATOR] = container_decorator_js_1.ContainerDecorator;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CrudResource = void 0;
|
|
4
|
+
const index_js_1 = require("../../helpers/index.js");
|
|
5
|
+
const endpoint_js_1 = require("./endpoint.js");
|
|
6
|
+
const resource_js_1 = require("./resource.js");
|
|
7
|
+
class CrudResource extends resource_js_1.Resource {
|
|
8
|
+
constructor(parent, init) {
|
|
9
|
+
super(parent, init);
|
|
10
|
+
this.operations = new index_js_1.ResponsiveMap();
|
|
11
|
+
if (init.operations) {
|
|
12
|
+
for (const [name, meta] of Object.entries(init.operations)) {
|
|
13
|
+
this.operations.set(name, new endpoint_js_1.Endpoint(this, name, meta));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getOperation(name) {
|
|
18
|
+
return this.operations.get(name);
|
|
19
|
+
}
|
|
20
|
+
exportSchema(options) {
|
|
21
|
+
const schema = super.exportSchema(options);
|
|
22
|
+
if (this.operations.size) {
|
|
23
|
+
schema.operations = {};
|
|
24
|
+
for (const operation of this.operations.values()) {
|
|
25
|
+
schema.operations[operation.name] = operation.exportSchema(options);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.CrudResource = CrudResource;
|
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Endpoint = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const vg = tslib_1.__importStar(require("valgen"));
|
|
4
6
|
const index_js_1 = require("../../helpers/index.js");
|
|
7
|
+
const data_type_js_1 = require("../data-type/data-type.js");
|
|
8
|
+
const parameter_js_1 = require("./parameter.js");
|
|
5
9
|
/**
|
|
6
10
|
*
|
|
7
11
|
* @class Endpoint
|
|
8
12
|
*/
|
|
9
13
|
class Endpoint {
|
|
10
|
-
constructor(init) {
|
|
14
|
+
constructor(resource, name, init) {
|
|
15
|
+
this.resource = resource;
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.decode = vg.isAny();
|
|
18
|
+
this.encode = vg.isAny();
|
|
11
19
|
Object.assign(this, init);
|
|
12
20
|
this.parameters = new index_js_1.ResponsiveMap();
|
|
13
21
|
if (init.parameters) {
|
|
14
22
|
for (const [n, p] of Object.entries(init.parameters)) {
|
|
15
|
-
this.
|
|
23
|
+
this.defineParameter(n, p);
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
26
|
}
|
|
19
|
-
|
|
27
|
+
defineParameter(name, init) {
|
|
28
|
+
const type = init.type && init.type instanceof data_type_js_1.DataType
|
|
29
|
+
? init.type : this.resource.document.getDataType(init.type || 'any');
|
|
30
|
+
const prm = new parameter_js_1.Parameter(name, {
|
|
31
|
+
...init,
|
|
32
|
+
type
|
|
33
|
+
});
|
|
34
|
+
this.parameters.set(prm.name, prm);
|
|
35
|
+
return prm;
|
|
36
|
+
}
|
|
37
|
+
exportSchema(options) {
|
|
20
38
|
const schema = (0, index_js_1.omitUndefined)({
|
|
21
39
|
description: this.description
|
|
22
40
|
});
|
|
23
41
|
if (this.parameters.size) {
|
|
24
42
|
schema.parameters = {};
|
|
25
43
|
for (const [name, param] of this.parameters.entries()) {
|
|
26
|
-
|
|
44
|
+
if (!param.isBuiltin)
|
|
45
|
+
schema.parameters[name] = param.exportSchema(options);
|
|
27
46
|
}
|
|
28
47
|
}
|
|
29
48
|
return schema;
|
|
30
49
|
}
|
|
31
50
|
}
|
|
32
51
|
exports.Endpoint = Endpoint;
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* @class EndpointParameter
|
|
36
|
-
*/
|
|
37
|
-
class EndpointParameter {
|
|
38
|
-
constructor(init) {
|
|
39
|
-
Object.assign(this, init);
|
|
40
|
-
}
|
|
41
|
-
exportSchema() {
|
|
42
|
-
return (0, index_js_1.omitUndefined)({
|
|
43
|
-
type: typeof this.type === 'string' ? this.type : this.type.exportSchema(),
|
|
44
|
-
description: this.description,
|
|
45
|
-
isArray: this.isArray
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.EndpointParameter = EndpointParameter;
|