@opra/common 0.28.0 → 0.29.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 +209 -99
- package/cjs/document/data-type/complex-type-class.js +36 -13
- package/cjs/document/data-type/field-class.js +8 -10
- package/cjs/document/factory/api-document-factory.js +26 -3
- package/cjs/document/factory/type-document-factory.js +6 -3
- package/cjs/document/index.js +1 -1
- package/cjs/document/resource/collection-class.js +31 -20
- package/cjs/document/resource/collection-decorator.js +61 -33
- package/cjs/document/resource/{operation-decorator.js → crud-operation-decorator.js} +3 -2
- package/cjs/document/resource/crud-operation.js +49 -0
- package/cjs/document/resource/crud-resource.js +2 -2
- package/cjs/document/resource/endpoint.js +11 -3
- package/cjs/document/resource/singleton-class.js +20 -10
- package/cjs/document/resource/storage-decorator.js +10 -10
- package/esm/document/data-type/complex-type-class.js +36 -13
- package/esm/document/data-type/field-class.js +8 -10
- package/esm/document/factory/api-document-factory.js +26 -3
- package/esm/document/factory/type-document-factory.js +6 -3
- package/esm/document/index.js +1 -1
- package/esm/document/resource/collection-class.js +31 -20
- package/esm/document/resource/collection-decorator.js +54 -26
- package/esm/document/resource/{operation-decorator.js → crud-operation-decorator.js} +3 -2
- package/esm/document/resource/crud-operation.js +44 -0
- package/esm/document/resource/crud-resource.js +2 -2
- package/esm/document/resource/endpoint.js +11 -3
- package/esm/document/resource/singleton-class.js +20 -10
- package/esm/document/resource/storage-decorator.js +7 -7
- package/package.json +4 -3
- package/types/document/data-type/complex-type-class.d.ts +1 -1
- package/types/document/data-type/complex-type.d.ts +7 -3
- package/types/document/data-type/data-type.d.ts +4 -0
- package/types/document/data-type/field-class.d.ts +2 -4
- package/types/document/index.d.ts +1 -1
- package/types/document/resource/collection-class.d.ts +0 -9
- package/types/document/resource/collection-decorator.d.ts +12 -0
- package/types/document/resource/crud-operation-decorator.d.ts +6 -0
- package/types/document/resource/{operation.d.ts → crud-operation.d.ts} +12 -4
- package/types/document/resource/crud-resource.d.ts +3 -3
- package/types/document/resource/endpoint.d.ts +1 -1
- package/types/document/resource/resource-decorator.d.ts +3 -2
- package/types/document/resource/resource.d.ts +2 -2
- package/types/document/resource/singleton-class.d.ts +5 -5
- package/types/document/resource/singleton-decorator.d.ts +6 -0
- package/types/document/resource/storage-class.d.ts +4 -4
- package/types/schema/data-type/complex-type.interface.d.ts +1 -1
- package/types/schema/data-type/field.interface.d.ts +2 -0
- package/types/schema/resource/collection.interface.d.ts +7 -7
- package/types/schema/resource/endpoint.interface.d.ts +2 -1
- package/types/schema/resource/singleton.interface.d.ts +0 -2
- package/cjs/document/resource/operation.js +0 -25
- package/esm/document/resource/operation.js +0 -20
- package/types/document/resource/operation-decorator.d.ts +0 -6
|
@@ -12,6 +12,7 @@ class Endpoint {
|
|
|
12
12
|
constructor(resource, name, init) {
|
|
13
13
|
this.resource = resource;
|
|
14
14
|
this.name = name;
|
|
15
|
+
this.options = {};
|
|
15
16
|
Object.assign(this, init);
|
|
16
17
|
this.parameters = new index_js_1.ResponsiveMap();
|
|
17
18
|
if (init.parameters) {
|
|
@@ -38,12 +39,19 @@ class Endpoint {
|
|
|
38
39
|
const schema = (0, index_js_1.omitUndefined)({
|
|
39
40
|
description: this.description
|
|
40
41
|
});
|
|
42
|
+
if (Object.keys(this.options).length)
|
|
43
|
+
schema.options = { ...this.options };
|
|
41
44
|
if (this.parameters.size) {
|
|
42
|
-
|
|
45
|
+
let i = 0;
|
|
46
|
+
const parameters = {};
|
|
43
47
|
for (const [name, param] of this.parameters.entries()) {
|
|
44
|
-
if (!param.isBuiltin)
|
|
45
|
-
|
|
48
|
+
if (!param.isBuiltin) {
|
|
49
|
+
parameters[name] = param.exportSchema(options);
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
46
52
|
}
|
|
53
|
+
if (i)
|
|
54
|
+
schema.parameters = parameters;
|
|
47
55
|
}
|
|
48
56
|
return schema;
|
|
49
57
|
}
|
|
@@ -16,14 +16,18 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
|
|
|
16
16
|
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
17
17
|
endpoint.decodeInput = this.type.generateCodec('decode', {
|
|
18
18
|
partial: true,
|
|
19
|
-
pick: endpoint.inputPickFields,
|
|
20
|
-
omit: endpoint.inputOmitFields,
|
|
19
|
+
pick: endpoint.options.inputPickFields,
|
|
20
|
+
omit: endpoint.options.inputOmitFields,
|
|
21
|
+
operation: 'write',
|
|
22
|
+
overwriteFields: endpoint.inputOverwriteFields
|
|
21
23
|
});
|
|
22
24
|
endpoint.returnType = this.type;
|
|
23
25
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
24
26
|
partial: true,
|
|
25
|
-
pick: endpoint.outputPickFields,
|
|
26
|
-
omit: endpoint.outputOmitFields,
|
|
27
|
+
pick: endpoint.options.outputPickFields,
|
|
28
|
+
omit: endpoint.options.outputOmitFields,
|
|
29
|
+
operation: 'read',
|
|
30
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
27
31
|
});
|
|
28
32
|
}
|
|
29
33
|
// ------------------
|
|
@@ -35,8 +39,10 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
|
|
|
35
39
|
endpoint.returnType = this.type;
|
|
36
40
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
37
41
|
partial: true,
|
|
38
|
-
pick: endpoint.outputPickFields,
|
|
39
|
-
omit: endpoint.outputOmitFields,
|
|
42
|
+
pick: endpoint.options.outputPickFields,
|
|
43
|
+
omit: endpoint.options.outputOmitFields,
|
|
44
|
+
operation: 'read',
|
|
45
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
40
46
|
});
|
|
41
47
|
}
|
|
42
48
|
// ------------------
|
|
@@ -46,14 +52,18 @@ class SingletonClass extends crud_resource_js_1.CrudResource {
|
|
|
46
52
|
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
47
53
|
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
48
54
|
endpoint.decodeInput = this.type.generateCodec('decode', {
|
|
49
|
-
pick: endpoint.inputPickFields,
|
|
50
|
-
omit: endpoint.inputOmitFields,
|
|
55
|
+
pick: endpoint.options.inputPickFields,
|
|
56
|
+
omit: endpoint.options.inputOmitFields,
|
|
57
|
+
operation: 'write',
|
|
58
|
+
overwriteFields: endpoint.inputOverwriteFields
|
|
51
59
|
});
|
|
52
60
|
endpoint.returnType = this.type;
|
|
53
61
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
54
62
|
partial: true,
|
|
55
|
-
pick: endpoint.outputPickFields,
|
|
56
|
-
omit: endpoint.outputOmitFields,
|
|
63
|
+
pick: endpoint.options.outputPickFields,
|
|
64
|
+
omit: endpoint.options.outputOmitFields,
|
|
65
|
+
operation: 'read',
|
|
66
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
69
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StorageDecorator = void 0;
|
|
4
4
|
const index_js_1 = require("../../schema/index.js");
|
|
5
5
|
const action_decorator_js_1 = require("./action-decorator.js");
|
|
6
|
-
const
|
|
6
|
+
const crud_operation_decorator_js_1 = require("./crud-operation-decorator.js");
|
|
7
7
|
const resource_decorator_js_1 = require("./resource-decorator.js");
|
|
8
8
|
const operationProperties = ['delete', 'get', 'post'];
|
|
9
9
|
function StorageDecorator(options) {
|
|
@@ -25,39 +25,39 @@ Object.assign(StorageDecorator, resource_decorator_js_1.ResourceDecorator);
|
|
|
25
25
|
StorageDecorator.Action = Action;
|
|
26
26
|
function Delete(options) {
|
|
27
27
|
const list = [];
|
|
28
|
-
return (0,
|
|
28
|
+
return (0, crud_operation_decorator_js_1.createOperationDecorator)('delete', options, list);
|
|
29
29
|
}
|
|
30
30
|
StorageDecorator.Delete = Delete;
|
|
31
31
|
function Get(options) {
|
|
32
32
|
const list = [];
|
|
33
|
-
return (0,
|
|
33
|
+
return (0, crud_operation_decorator_js_1.createOperationDecorator)('get', options, list);
|
|
34
34
|
}
|
|
35
35
|
StorageDecorator.Get = Get;
|
|
36
36
|
function Post(options) {
|
|
37
37
|
const list = [];
|
|
38
|
-
const decorator = (0,
|
|
38
|
+
const decorator = (0, crud_operation_decorator_js_1.createOperationDecorator)('post', options, list);
|
|
39
39
|
decorator.MaxFields = (amount) => {
|
|
40
|
-
list.push(operationMeta => operationMeta.maxFields = amount);
|
|
40
|
+
list.push(operationMeta => operationMeta.options.maxFields = amount);
|
|
41
41
|
return decorator;
|
|
42
42
|
};
|
|
43
43
|
decorator.MaxFieldSize = (amount) => {
|
|
44
|
-
list.push(operationMeta => operationMeta.maxFieldsSize = amount);
|
|
44
|
+
list.push(operationMeta => operationMeta.options.maxFieldsSize = amount);
|
|
45
45
|
return decorator;
|
|
46
46
|
};
|
|
47
47
|
decorator.MaxFiles = (amount) => {
|
|
48
|
-
list.push(operationMeta => operationMeta.maxFiles = amount);
|
|
48
|
+
list.push(operationMeta => operationMeta.options.maxFiles = amount);
|
|
49
49
|
return decorator;
|
|
50
50
|
};
|
|
51
51
|
decorator.MaxFileSize = (sizeInBytes) => {
|
|
52
|
-
list.push(operationMeta => operationMeta.maxFileSize = sizeInBytes);
|
|
52
|
+
list.push(operationMeta => operationMeta.options.maxFileSize = sizeInBytes);
|
|
53
53
|
return decorator;
|
|
54
54
|
};
|
|
55
55
|
decorator.MaxTotalFileSize = (sizeInBytes) => {
|
|
56
|
-
list.push(operationMeta => operationMeta.maxTotalFileSize = sizeInBytes);
|
|
56
|
+
list.push(operationMeta => operationMeta.options.maxTotalFileSize = sizeInBytes);
|
|
57
57
|
return decorator;
|
|
58
58
|
};
|
|
59
59
|
decorator.MinFileSize = (sizeInBytes) => {
|
|
60
|
-
list.push(operationMeta => operationMeta.minFileSize = sizeInBytes);
|
|
60
|
+
list.push(operationMeta => operationMeta.options.minFileSize = sizeInBytes);
|
|
61
61
|
return decorator;
|
|
62
62
|
};
|
|
63
63
|
return decorator;
|
|
@@ -11,6 +11,7 @@ export class ComplexTypeClass extends DataType {
|
|
|
11
11
|
constructor(document, init) {
|
|
12
12
|
super(document, init);
|
|
13
13
|
this.kind = OpraSchema.ComplexType.Kind;
|
|
14
|
+
this.fields = new ResponsiveMap();
|
|
14
15
|
const own = this.own = {};
|
|
15
16
|
own.ctor = init.ctor;
|
|
16
17
|
if (init.base) {
|
|
@@ -29,7 +30,6 @@ export class ComplexTypeClass extends DataType {
|
|
|
29
30
|
this.additionalFields = true;
|
|
30
31
|
else if (this.base?.additionalFields === 'error' && !this.additionalFields)
|
|
31
32
|
this.additionalFields = 'error';
|
|
32
|
-
this.fields = new ResponsiveMap();
|
|
33
33
|
if (this.base) {
|
|
34
34
|
if (this.base.fields)
|
|
35
35
|
for (const [k, el] of this.base.fields.entries()) {
|
|
@@ -130,7 +130,11 @@ export class ComplexTypeClass extends DataType {
|
|
|
130
130
|
base: this.base ?
|
|
131
131
|
(this.base.name ? this.base.name : this.base.exportSchema(options)) : undefined,
|
|
132
132
|
abstract: this.abstract,
|
|
133
|
-
additionalFields: this.own.additionalFields
|
|
133
|
+
additionalFields: this.own.additionalFields instanceof DataType
|
|
134
|
+
? (this.own.additionalFields.name
|
|
135
|
+
? this.own.additionalFields.name
|
|
136
|
+
: this.own.additionalFields.exportSchema(options))
|
|
137
|
+
: this.own.additionalFields
|
|
134
138
|
}));
|
|
135
139
|
if (this.own.fields.size) {
|
|
136
140
|
const fields = out.fields = {};
|
|
@@ -154,9 +158,12 @@ export class ComplexTypeClass extends DataType {
|
|
|
154
158
|
}
|
|
155
159
|
generateCodec(codec, options) {
|
|
156
160
|
const schema = this._generateCodecSchema(codec, options);
|
|
161
|
+
const additionalFields = this.additionalFields instanceof DataType
|
|
162
|
+
? this.additionalFields.generateCodec(codec, options)
|
|
163
|
+
: this.additionalFields;
|
|
157
164
|
return vg.isObject(schema, {
|
|
158
165
|
ctor: this.ctor,
|
|
159
|
-
additionalFields
|
|
166
|
+
additionalFields,
|
|
160
167
|
name: this.name,
|
|
161
168
|
caseInSensitive: !options?.caseSensitive
|
|
162
169
|
});
|
|
@@ -165,20 +172,36 @@ export class ComplexTypeClass extends DataType {
|
|
|
165
172
|
const schema = {};
|
|
166
173
|
const pickOption = (options?.pick || []).map(x => x.toLowerCase());
|
|
167
174
|
const omitOption = (options?.omit || []).map(x => x.toLowerCase());
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
175
|
+
const dedupedFieldNames = (options?.overwriteFields
|
|
176
|
+
? Array.from(new Set([...this.fields.keys(), ...options?.overwriteFields.keys()]))
|
|
177
|
+
: Array.from(this.fields.keys())).map(x => x.toLocaleString());
|
|
178
|
+
for (const nameLower of dedupedFieldNames) {
|
|
179
|
+
const overwriteField = options?.overwriteFields?.get(nameLower);
|
|
180
|
+
const field = this.fields.get(nameLower);
|
|
181
|
+
/* istanbul ignore next */
|
|
182
|
+
if (!(field || overwriteField))
|
|
171
183
|
continue;
|
|
172
|
-
if (
|
|
184
|
+
if (!overwriteField &&
|
|
185
|
+
(omitOption.find(x => x === nameLower) ||
|
|
186
|
+
(pickOption.length && !pickOption.find(x => x === nameLower || x.startsWith(nameLower + '.')))))
|
|
173
187
|
continue;
|
|
188
|
+
let f;
|
|
189
|
+
if (overwriteField) {
|
|
190
|
+
f = { ...overwriteField };
|
|
191
|
+
Object.setPrototypeOf(f, field || ApiField.prototype);
|
|
192
|
+
}
|
|
193
|
+
else
|
|
194
|
+
f = field;
|
|
174
195
|
schema[f.name] = f.generateCodec(codec, {
|
|
175
196
|
...options,
|
|
176
|
-
pick:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
197
|
+
pick: overwriteField ? [] :
|
|
198
|
+
pickOption
|
|
199
|
+
.filter(x => x.startsWith(nameLower + '.'))
|
|
200
|
+
.map(x => x.substring(x.indexOf('.') + 1)),
|
|
201
|
+
omit: overwriteField ? [] :
|
|
202
|
+
omitOption
|
|
203
|
+
.filter(x => x.startsWith(nameLower + '.'))
|
|
204
|
+
.map(x => x.substring(x.indexOf('.') + 1)),
|
|
182
205
|
});
|
|
183
206
|
}
|
|
184
207
|
return schema;
|
|
@@ -11,6 +11,8 @@ export class FieldClass {
|
|
|
11
11
|
this.default = init.default;
|
|
12
12
|
this.fixed = init.fixed;
|
|
13
13
|
this.required = init.required;
|
|
14
|
+
this.readonly = init.readonly;
|
|
15
|
+
this.writeonly = init.writeonly;
|
|
14
16
|
this.exclusive = init.exclusive;
|
|
15
17
|
this.deprecated = init.deprecated;
|
|
16
18
|
this.examples = init.examples;
|
|
@@ -23,22 +25,18 @@ export class FieldClass {
|
|
|
23
25
|
default: this.default,
|
|
24
26
|
fixed: this.fixed,
|
|
25
27
|
required: this.required,
|
|
28
|
+
readonly: this.readonly,
|
|
29
|
+
writeonly: this.writeonly,
|
|
26
30
|
exclusive: this.exclusive,
|
|
27
31
|
deprecated: this.deprecated,
|
|
28
32
|
examples: this.examples
|
|
29
33
|
});
|
|
30
34
|
}
|
|
31
|
-
getDecoder() {
|
|
32
|
-
if (!this._decoder)
|
|
33
|
-
this._decoder = this.generateCodec('decode');
|
|
34
|
-
return this._decoder;
|
|
35
|
-
}
|
|
36
|
-
getEncoder() {
|
|
37
|
-
if (!this._encoder)
|
|
38
|
-
this._encoder = this.generateCodec('encode');
|
|
39
|
-
return this._encoder;
|
|
40
|
-
}
|
|
41
35
|
generateCodec(codec, options) {
|
|
36
|
+
if (options?.operation === 'read' && this.writeonly)
|
|
37
|
+
return vg.isUndefined();
|
|
38
|
+
if (options?.operation === 'write' && this.readonly)
|
|
39
|
+
return vg.isUndefined();
|
|
42
40
|
let fn = this.type.generateCodec(codec, options);
|
|
43
41
|
if (this.isArray)
|
|
44
42
|
fn = vg.isArray(fn);
|
|
@@ -159,9 +159,9 @@ export class ApiDocumentFactory extends TypeDocumentFactory {
|
|
|
159
159
|
return;
|
|
160
160
|
const output = {};
|
|
161
161
|
for (const [kA, oA] of Object.entries(source)) {
|
|
162
|
-
|
|
162
|
+
const o = output[kA] = { ...oA };
|
|
163
163
|
if (oA.parameters) {
|
|
164
|
-
parameters = {};
|
|
164
|
+
const parameters = o.parameters = {};
|
|
165
165
|
for (const [kP, oP] of Object.entries(oA.parameters)) {
|
|
166
166
|
if (oP.enum) {
|
|
167
167
|
oP.type = EnumType(oP.enum, { name: kP + 'Enum' });
|
|
@@ -172,7 +172,30 @@ export class ApiDocumentFactory extends TypeDocumentFactory {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
if (oA.options?.inputOverwriteFields) {
|
|
176
|
+
const inputOverwriteFields = {};
|
|
177
|
+
for (const [kP, oP] of Object.entries(oA.options.inputOverwriteFields)) {
|
|
178
|
+
if (oP.enum) {
|
|
179
|
+
oP.type = EnumType(oP.enum, { name: kP + 'Enum' });
|
|
180
|
+
}
|
|
181
|
+
inputOverwriteFields[kP] = { ...oP, };
|
|
182
|
+
if (oP.type)
|
|
183
|
+
inputOverwriteFields[kP].type = await this.importDataType(oP.type);
|
|
184
|
+
}
|
|
185
|
+
o.options.inputOverwriteFields = inputOverwriteFields;
|
|
186
|
+
}
|
|
187
|
+
if (oA.options?.outputOverwriteFields) {
|
|
188
|
+
const outputOverwriteFields = {};
|
|
189
|
+
for (const [kP, oP] of Object.entries(oA.options.outputOverwriteFields)) {
|
|
190
|
+
if (oP.enum) {
|
|
191
|
+
oP.type = EnumType(oP.enum, { name: kP + 'Enum' });
|
|
192
|
+
}
|
|
193
|
+
outputOverwriteFields[kP] = { ...oP };
|
|
194
|
+
if (oP.type)
|
|
195
|
+
outputOverwriteFields[kP].type = await this.importDataType(oP.type);
|
|
196
|
+
}
|
|
197
|
+
o.options.outputOverwriteFields = outputOverwriteFields;
|
|
198
|
+
}
|
|
176
199
|
}
|
|
177
200
|
return output;
|
|
178
201
|
};
|
|
@@ -139,7 +139,7 @@ export class TypeDocumentFactory {
|
|
|
139
139
|
return dataType;
|
|
140
140
|
throw new TypeError(`Class "${thunk.name}" doesn't have a valid DataType metadata`);
|
|
141
141
|
}
|
|
142
|
-
name = metadata.name;
|
|
142
|
+
name = metadata.anonymous ? undefined : metadata.name;
|
|
143
143
|
initArguments = cloneObject(metadata);
|
|
144
144
|
ctor = thunk;
|
|
145
145
|
}
|
|
@@ -154,7 +154,7 @@ export class TypeDocumentFactory {
|
|
|
154
154
|
const metadata = thunk[DATATYPE_METADATA];
|
|
155
155
|
if (!metadata)
|
|
156
156
|
throw new TypeError(`No EnumType metadata found for object ${JSON.stringify(thunk).substring(0, 20)}...`);
|
|
157
|
-
name = metadata.name;
|
|
157
|
+
name = metadata.anonymous ? undefined : metadata.name;
|
|
158
158
|
initArguments = cloneObject(metadata);
|
|
159
159
|
initArguments.enumObject = thunk;
|
|
160
160
|
}
|
|
@@ -186,8 +186,11 @@ export class TypeDocumentFactory {
|
|
|
186
186
|
if (name)
|
|
187
187
|
this.document.types.set(name, instance);
|
|
188
188
|
await this.prepareDataTypeInitArguments(initArguments, ctor);
|
|
189
|
-
if (initArguments.kind === 'ComplexType')
|
|
189
|
+
if (initArguments.kind === 'ComplexType') {
|
|
190
|
+
if (typeof initArguments.additionalFields === 'function')
|
|
191
|
+
initArguments.additionalFields = await this.importDataType(initArguments.additionalFields);
|
|
190
192
|
ComplexType.apply(instance, [this.document, initArguments]);
|
|
193
|
+
}
|
|
191
194
|
else if (initArguments.kind === 'SimpleType')
|
|
192
195
|
SimpleType.apply(instance, [this.document, initArguments]);
|
|
193
196
|
else if (initArguments.kind === 'EnumType')
|
package/esm/document/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export * from './resource/collection.js';
|
|
|
16
16
|
export * from './resource/container.js';
|
|
17
17
|
export * from './resource/crud-resource.js';
|
|
18
18
|
export * from './resource/endpoint.js';
|
|
19
|
-
export * from './resource/operation.js';
|
|
19
|
+
export * from './resource/crud-operation.js';
|
|
20
20
|
export * from './resource/parameter.js';
|
|
21
21
|
export * from './resource/resource.js';
|
|
22
22
|
export * from './resource/singleton.js';
|
|
@@ -30,14 +30,18 @@ export class CollectionClass extends CrudResource {
|
|
|
30
30
|
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
31
31
|
endpoint.decodeInput = this.type.generateCodec('decode', {
|
|
32
32
|
partial: true,
|
|
33
|
-
pick: endpoint.inputPickFields,
|
|
34
|
-
omit: endpoint.inputOmitFields,
|
|
33
|
+
pick: endpoint.options.inputPickFields,
|
|
34
|
+
omit: endpoint.options.inputOmitFields,
|
|
35
|
+
operation: 'write',
|
|
36
|
+
overwriteFields: endpoint.inputOverwriteFields
|
|
35
37
|
});
|
|
36
38
|
endpoint.returnType = this.type;
|
|
37
39
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
38
40
|
partial: true,
|
|
39
|
-
pick: endpoint.outputPickFields,
|
|
40
|
-
omit: endpoint.outputOmitFields,
|
|
41
|
+
pick: endpoint.options.outputPickFields,
|
|
42
|
+
omit: endpoint.options.outputOmitFields,
|
|
43
|
+
operation: 'read',
|
|
44
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
// ------------------
|
|
@@ -56,8 +60,10 @@ export class CollectionClass extends CrudResource {
|
|
|
56
60
|
endpoint.returnType = this.type;
|
|
57
61
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
58
62
|
partial: true,
|
|
59
|
-
pick: endpoint.outputPickFields,
|
|
60
|
-
omit: endpoint.outputOmitFields,
|
|
63
|
+
pick: endpoint.options.outputPickFields,
|
|
64
|
+
omit: endpoint.options.outputOmitFields,
|
|
65
|
+
operation: 'read',
|
|
66
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
61
67
|
});
|
|
62
68
|
}
|
|
63
69
|
// ------------------
|
|
@@ -76,8 +82,10 @@ export class CollectionClass extends CrudResource {
|
|
|
76
82
|
endpoint.returnType = this.type;
|
|
77
83
|
endpoint.encodeReturning = vg.isArray(this.type.generateCodec('encode', {
|
|
78
84
|
partial: true,
|
|
79
|
-
pick: endpoint.outputPickFields,
|
|
80
|
-
omit: endpoint.outputOmitFields,
|
|
85
|
+
pick: endpoint.options.outputPickFields,
|
|
86
|
+
omit: endpoint.options.outputOmitFields,
|
|
87
|
+
operation: 'read',
|
|
88
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
81
89
|
}));
|
|
82
90
|
}
|
|
83
91
|
// ------------------
|
|
@@ -88,14 +96,18 @@ export class CollectionClass extends CrudResource {
|
|
|
88
96
|
endpoint.defineParameter('omit', { type: 'string', isArray: true, isBuiltin: true });
|
|
89
97
|
endpoint.defineParameter('include', { type: 'string', isArray: true, isBuiltin: true });
|
|
90
98
|
endpoint.decodeInput = this.type.generateCodec('decode', {
|
|
91
|
-
pick: endpoint.inputPickFields,
|
|
92
|
-
omit: endpoint.inputOmitFields,
|
|
99
|
+
pick: endpoint.options.inputPickFields,
|
|
100
|
+
omit: endpoint.options.inputOmitFields,
|
|
101
|
+
operation: 'write',
|
|
102
|
+
overwriteFields: endpoint.inputOverwriteFields
|
|
93
103
|
});
|
|
94
104
|
endpoint.returnType = this.type;
|
|
95
105
|
endpoint.encodeReturning = endpoint.returnType.generateCodec('encode', {
|
|
96
106
|
partial: true,
|
|
97
|
-
pick: endpoint.outputPickFields,
|
|
98
|
-
omit: endpoint.outputOmitFields,
|
|
107
|
+
pick: endpoint.options.outputPickFields,
|
|
108
|
+
omit: endpoint.options.outputOmitFields,
|
|
109
|
+
operation: 'read',
|
|
110
|
+
overwriteFields: endpoint.outputOverwriteFields
|
|
99
111
|
});
|
|
100
112
|
}
|
|
101
113
|
// ------------------
|
|
@@ -104,14 +116,13 @@ export class CollectionClass extends CrudResource {
|
|
|
104
116
|
// endpoint.defineParameter('metadata', {enum: MetadataMode, isBuiltin: true, default: 'minimal'});
|
|
105
117
|
endpoint.defineParameter('filter', { type: 'string', isBuiltin: true });
|
|
106
118
|
endpoint.decodeInput = this.type.generateCodec('decode', {
|
|
107
|
-
pick: endpoint.inputPickFields,
|
|
108
|
-
omit: endpoint.inputOmitFields,
|
|
119
|
+
pick: endpoint.options.inputPickFields,
|
|
120
|
+
omit: endpoint.options.inputOmitFields,
|
|
121
|
+
operation: 'write',
|
|
122
|
+
overwriteFields: endpoint.inputOverwriteFields
|
|
109
123
|
});
|
|
110
124
|
}
|
|
111
125
|
}
|
|
112
|
-
getOperation(name) {
|
|
113
|
-
return super.getOperation(name);
|
|
114
|
-
}
|
|
115
126
|
exportSchema(options) {
|
|
116
127
|
return {
|
|
117
128
|
...super.exportSchema(options),
|
|
@@ -163,7 +174,7 @@ export class CollectionClass extends CrudResource {
|
|
|
163
174
|
if (!normalized)
|
|
164
175
|
return;
|
|
165
176
|
const findManyOp = this.getOperation('findMany');
|
|
166
|
-
const sortFields = findManyOp && findManyOp.sortFields;
|
|
177
|
+
const sortFields = findManyOp && findManyOp.options.sortFields;
|
|
167
178
|
(Array.isArray(normalized) ? normalized : [normalized]).forEach(field => {
|
|
168
179
|
if (!sortFields?.find(x => x === field))
|
|
169
180
|
throw new BadRequestError({
|
|
@@ -183,7 +194,7 @@ export class CollectionClass extends CrudResource {
|
|
|
183
194
|
// Check if filtering accepted for given field
|
|
184
195
|
const findManyOp = this.getOperation('findMany');
|
|
185
196
|
const fieldLower = ast.left.value.toLowerCase();
|
|
186
|
-
const filterDef = (findManyOp && findManyOp.filters || [])
|
|
197
|
+
const filterDef = (findManyOp && findManyOp.options.filters || [])
|
|
187
198
|
.find(f => f.field.toLowerCase() === fieldLower);
|
|
188
199
|
if (!filterDef) {
|
|
189
200
|
throw new BadRequestError({
|
|
@@ -191,7 +202,7 @@ export class CollectionClass extends CrudResource {
|
|
|
191
202
|
});
|
|
192
203
|
}
|
|
193
204
|
// Check if filtering endpoint accepted for given field
|
|
194
|
-
if (!filterDef.operators
|
|
205
|
+
if (filterDef.operators && !filterDef.operators.includes(ast.op))
|
|
195
206
|
throw new BadRequestError({
|
|
196
207
|
message: translate('error:UNACCEPTED_FILTER_OPERATION', { field: ast.left.value }),
|
|
197
208
|
});
|