@opra/common 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +253 -78
- package/cjs/document/data-type/api-field.js +4 -0
- package/cjs/document/data-type/complex-type-base.js +4 -0
- package/cjs/document/data-type/complex-type.js +2 -0
- package/cjs/document/data-type/enum-type.js +2 -0
- package/cjs/document/data-type/extended-types/base64.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +4 -0
- package/cjs/document/data-type/extended-types/date.type.js +4 -0
- package/cjs/document/data-type/extended-types/email.type.js +4 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +4 -0
- package/cjs/document/data-type/extended-types/filter.type.js +4 -0
- package/cjs/document/data-type/extended-types/object-id.type.js +4 -0
- package/cjs/document/data-type/extended-types/time.type.js +4 -0
- package/cjs/document/data-type/extended-types/url.type.js +4 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +4 -0
- package/cjs/document/data-type/mapped-type.js +3 -0
- package/cjs/document/data-type/mixin-type.js +3 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +4 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +4 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +4 -0
- package/cjs/document/data-type/primitive-types/null.type.js +4 -0
- package/cjs/document/data-type/primitive-types/number.type.js +4 -0
- package/cjs/document/data-type/primitive-types/string.type.js +4 -0
- package/cjs/document/data-type/simple-type.js +8 -1
- package/cjs/document/decorators/http-controller.decorator.js +25 -0
- package/cjs/document/decorators/http-operation-entity.decorator.js +55 -19
- package/cjs/document/factory/data-type.factory.js +61 -38
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +6 -6
- package/cjs/document/http/http-parameter.js +2 -0
- package/esm/document/data-type/api-field.js +4 -0
- package/esm/document/data-type/complex-type-base.js +4 -0
- package/esm/document/data-type/complex-type.js +2 -0
- package/esm/document/data-type/enum-type.js +2 -0
- package/esm/document/data-type/extended-types/base64.type.js +4 -0
- package/esm/document/data-type/extended-types/date-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +4 -0
- package/esm/document/data-type/extended-types/date-time.type.js +4 -0
- package/esm/document/data-type/extended-types/date.type.js +4 -0
- package/esm/document/data-type/extended-types/email.type.js +4 -0
- package/esm/document/data-type/extended-types/field-path.type.js +4 -0
- package/esm/document/data-type/extended-types/filter.type.js +4 -0
- package/esm/document/data-type/extended-types/object-id.type.js +4 -0
- package/esm/document/data-type/extended-types/time.type.js +4 -0
- package/esm/document/data-type/extended-types/url.type.js +4 -0
- package/esm/document/data-type/extended-types/uuid.type.js +4 -0
- package/esm/document/data-type/mapped-type.js +3 -0
- package/esm/document/data-type/mixin-type.js +3 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +4 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +4 -0
- package/esm/document/data-type/primitive-types/integer.type.js +4 -0
- package/esm/document/data-type/primitive-types/null.type.js +4 -0
- package/esm/document/data-type/primitive-types/number.type.js +4 -0
- package/esm/document/data-type/primitive-types/string.type.js +4 -0
- package/esm/document/data-type/simple-type.js +8 -1
- package/esm/document/decorators/http-controller.decorator.js +25 -0
- package/esm/document/decorators/http-operation-entity.decorator.js +55 -19
- package/esm/document/factory/data-type.factory.js +61 -38
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +6 -6
- package/esm/document/http/http-parameter.js +2 -0
- package/package.json +3 -3
- package/types/document/data-type/api-field.d.ts +2 -0
- package/types/document/data-type/complex-type.d.ts +1 -1
- package/types/document/data-type/data-type.d.ts +4 -2
- package/types/document/data-type/enum-type.d.ts +2 -2
- package/types/document/data-type/mapped-type.d.ts +2 -2
- package/types/document/data-type/mixin-type.d.ts +2 -2
- package/types/document/data-type/simple-type.d.ts +4 -2
- package/types/document/decorators/http-controller.decorator.d.ts +1 -0
- package/types/document/factory/data-type.factory.d.ts +5 -0
- package/types/document/http/http-parameter.d.ts +2 -0
- package/types/schema/data-type/simple-type.interface.d.ts +4 -0
- package/types/schema/http/http-parameter.interface.d.ts +4 -0
|
@@ -21,8 +21,8 @@ HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
|
21
21
|
/** Initialize the decorator and the chain */
|
|
22
22
|
const decoratorChain = [];
|
|
23
23
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
24
|
-
description: args.description,
|
|
25
24
|
method: 'POST',
|
|
25
|
+
...args,
|
|
26
26
|
composition: 'Entity.Create',
|
|
27
27
|
requestBody: {
|
|
28
28
|
immediateFetch: true,
|
|
@@ -72,8 +72,8 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
72
72
|
/** Initialize the decorator and the chain */
|
|
73
73
|
const decoratorChain = [];
|
|
74
74
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
75
|
-
description: args.description,
|
|
76
75
|
method: 'DELETE',
|
|
76
|
+
...args,
|
|
77
77
|
composition: 'Entity.Delete',
|
|
78
78
|
}));
|
|
79
79
|
decorator
|
|
@@ -91,11 +91,23 @@ HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
|
91
91
|
*
|
|
92
92
|
*/
|
|
93
93
|
decorator.KeyParam = (name, prmOptions) => {
|
|
94
|
-
|
|
94
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
95
|
+
? {
|
|
96
|
+
name,
|
|
97
|
+
location: 'path',
|
|
98
|
+
type: prmOptions,
|
|
99
|
+
keyParam: true,
|
|
100
|
+
}
|
|
101
|
+
: {
|
|
102
|
+
...prmOptions,
|
|
103
|
+
name,
|
|
104
|
+
location: 'path',
|
|
105
|
+
keyParam: true,
|
|
106
|
+
};
|
|
107
|
+
decorator.PathParam(name, paramMeta);
|
|
95
108
|
decoratorChain.push((meta) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
meta.compositionOptions.keyParameter = name;
|
|
109
|
+
if (!meta.path?.includes(':' + name))
|
|
110
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
99
111
|
});
|
|
100
112
|
return decorator;
|
|
101
113
|
};
|
|
@@ -121,8 +133,8 @@ HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
|
121
133
|
const filterType = new FilterType({ dataType: args.type });
|
|
122
134
|
filterType.rules = {};
|
|
123
135
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
124
|
-
description: args.description,
|
|
125
136
|
method: 'DELETE',
|
|
137
|
+
...args,
|
|
126
138
|
composition: 'Entity.DeleteMany',
|
|
127
139
|
}));
|
|
128
140
|
decorator
|
|
@@ -169,8 +181,8 @@ HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
|
169
181
|
const filterType = new FilterType({ dataType: args.type });
|
|
170
182
|
filterType.rules = {};
|
|
171
183
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
172
|
-
description: args.description,
|
|
173
184
|
method: 'GET',
|
|
185
|
+
...args,
|
|
174
186
|
composition: 'Entity.FindMany',
|
|
175
187
|
}));
|
|
176
188
|
decorator
|
|
@@ -261,8 +273,8 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
261
273
|
/** Initialize the decorator and the chain */
|
|
262
274
|
const decoratorChain = [];
|
|
263
275
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
264
|
-
description: args.description,
|
|
265
276
|
method: 'GET',
|
|
277
|
+
...args,
|
|
266
278
|
composition: 'Entity.Get',
|
|
267
279
|
}));
|
|
268
280
|
decorator
|
|
@@ -294,11 +306,23 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
294
306
|
*
|
|
295
307
|
*/
|
|
296
308
|
decorator.KeyParam = (name, prmOptions) => {
|
|
297
|
-
|
|
309
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
310
|
+
? {
|
|
311
|
+
name,
|
|
312
|
+
location: 'path',
|
|
313
|
+
type: prmOptions,
|
|
314
|
+
keyParam: true,
|
|
315
|
+
}
|
|
316
|
+
: {
|
|
317
|
+
...prmOptions,
|
|
318
|
+
name,
|
|
319
|
+
location: 'path',
|
|
320
|
+
keyParam: true,
|
|
321
|
+
};
|
|
322
|
+
decorator.PathParam(name, paramMeta);
|
|
298
323
|
decoratorChain.push((meta) => {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
meta.compositionOptions.keyParameter = name;
|
|
324
|
+
if (!meta.path?.includes(':' + name))
|
|
325
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
302
326
|
});
|
|
303
327
|
return decorator;
|
|
304
328
|
};
|
|
@@ -324,8 +348,8 @@ HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
|
324
348
|
filterType.rules = {};
|
|
325
349
|
const filterRules = new FilterRules();
|
|
326
350
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
327
|
-
description: args.description,
|
|
328
351
|
method: 'PATCH',
|
|
352
|
+
...args,
|
|
329
353
|
composition: 'Entity.UpdateMany',
|
|
330
354
|
requestBody: {
|
|
331
355
|
immediateFetch: true,
|
|
@@ -379,8 +403,8 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
379
403
|
const filterType = new FilterType({ dataType: args.type });
|
|
380
404
|
filterType.rules = {};
|
|
381
405
|
const decorator = HttpOperationDecoratorFactory(decoratorChain, omitUndefined({
|
|
382
|
-
description: args.description,
|
|
383
406
|
method: 'PATCH',
|
|
407
|
+
...args,
|
|
384
408
|
composition: 'Entity.Update',
|
|
385
409
|
requestBody: {
|
|
386
410
|
partial: 'deep',
|
|
@@ -423,11 +447,23 @@ HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
|
423
447
|
*
|
|
424
448
|
*/
|
|
425
449
|
decorator.KeyParam = (name, prmOptions) => {
|
|
426
|
-
|
|
450
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
451
|
+
? {
|
|
452
|
+
name,
|
|
453
|
+
location: 'path',
|
|
454
|
+
type: prmOptions,
|
|
455
|
+
keyParam: true,
|
|
456
|
+
}
|
|
457
|
+
: {
|
|
458
|
+
...prmOptions,
|
|
459
|
+
name,
|
|
460
|
+
location: 'path',
|
|
461
|
+
keyParam: true,
|
|
462
|
+
};
|
|
463
|
+
decorator.PathParam(name, paramMeta);
|
|
427
464
|
decoratorChain.push((meta) => {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
meta.compositionOptions.keyParameter = name;
|
|
465
|
+
if (!meta.path?.includes(':' + name))
|
|
466
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
431
467
|
});
|
|
432
468
|
return decorator;
|
|
433
469
|
};
|
|
@@ -4,6 +4,7 @@ import { DocumentInitContext } from '../common/document-init-context.js';
|
|
|
4
4
|
import { DATATYPE_METADATA, DECODER, ENCODER, kCtorMap, kDataTypeMap } from '../constants.js';
|
|
5
5
|
import { ComplexType } from '../data-type/complex-type.js';
|
|
6
6
|
import { ComplexTypeBase } from '../data-type/complex-type-base.js';
|
|
7
|
+
import { DataType } from '../data-type/data-type.js';
|
|
7
8
|
import { EnumType } from '../data-type/enum-type.js';
|
|
8
9
|
import { MappedType } from '../data-type/mapped-type.js';
|
|
9
10
|
import { MixinType } from '../data-type/mixin-type.js';
|
|
@@ -130,7 +131,7 @@ export class DataTypeFactory {
|
|
|
130
131
|
const { importQueue, initArgsMap } = context;
|
|
131
132
|
// Check if data type already exist (maybe a builtin type or already imported)
|
|
132
133
|
const dataType = owner.node.findDataType(thunk);
|
|
133
|
-
if (dataType)
|
|
134
|
+
if (dataType instanceof DataType)
|
|
134
135
|
return dataType.name;
|
|
135
136
|
let metadata;
|
|
136
137
|
let ctor;
|
|
@@ -209,11 +210,15 @@ export class DataTypeFactory {
|
|
|
209
210
|
/** Mark "out" object as initializing. This will help us to detect circular dependencies */
|
|
210
211
|
out[initializingSymbol] = true;
|
|
211
212
|
try {
|
|
212
|
-
if (out.name
|
|
213
|
-
|
|
213
|
+
if (out.name) {
|
|
214
|
+
if (importQueue?.has(out.name)) {
|
|
215
|
+
initArgsMap?.set(metadata.name, out);
|
|
216
|
+
out._instance = { name: metadata.name };
|
|
217
|
+
out[kDataTypeMap] = owner.node[kDataTypeMap];
|
|
218
|
+
}
|
|
219
|
+
else
|
|
220
|
+
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
214
221
|
}
|
|
215
|
-
else if (out.name)
|
|
216
|
-
return context.addError(`Data Type (${out.name}) must be explicitly added to type list in the document scope`);
|
|
217
222
|
switch (out.kind) {
|
|
218
223
|
case OpraSchema.ComplexType.Kind:
|
|
219
224
|
out.ctor = ctor;
|
|
@@ -329,6 +334,7 @@ export class DataTypeFactory {
|
|
|
329
334
|
initArgs.ctor = initArgs.ctor || baseArgs.ctor;
|
|
330
335
|
});
|
|
331
336
|
initArgs.properties = metadata.properties;
|
|
337
|
+
initArgs.nameMappings = metadata.nameMappings;
|
|
332
338
|
if (!initArgs.properties && initArgs.ctor)
|
|
333
339
|
initArgs.properties = new initArgs.ctor();
|
|
334
340
|
if (metadata.attributes)
|
|
@@ -381,27 +387,40 @@ export class DataTypeFactory {
|
|
|
381
387
|
});
|
|
382
388
|
}
|
|
383
389
|
static _createDataType(context, owner, args) {
|
|
390
|
+
let dataType = owner.node.findDataType(typeof args === 'string' ? args : args.name || '');
|
|
391
|
+
if (dataType instanceof DataType)
|
|
392
|
+
return dataType;
|
|
384
393
|
const initArgs = typeof args === 'string' ? context.initArgsMap?.get(args) : args;
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
394
|
+
if (initArgs) {
|
|
395
|
+
const dataTypeMap = initArgs[kDataTypeMap];
|
|
396
|
+
if (!dataTypeMap)
|
|
397
|
+
delete initArgs._instance;
|
|
398
|
+
dataType = initArgs._instance;
|
|
399
|
+
if (dataType?.name && dataTypeMap) {
|
|
400
|
+
dataTypeMap.set(dataType.name, dataType);
|
|
401
|
+
}
|
|
402
|
+
switch (initArgs?.kind) {
|
|
403
|
+
case OpraSchema.ComplexType.Kind:
|
|
404
|
+
return this._createComplexType(context, owner, initArgs);
|
|
405
|
+
case OpraSchema.EnumType.Kind:
|
|
406
|
+
return this._createEnumType(context, owner, initArgs);
|
|
407
|
+
case OpraSchema.MappedType.Kind:
|
|
408
|
+
return this._createMappedType(context, owner, initArgs);
|
|
409
|
+
case OpraSchema.MixinType.Kind:
|
|
410
|
+
return this._createMixinType(context, owner, initArgs);
|
|
411
|
+
case OpraSchema.SimpleType.Kind:
|
|
412
|
+
return this._createSimpleType(context, owner, initArgs);
|
|
413
|
+
}
|
|
396
414
|
}
|
|
397
415
|
context.addError(`Unknown data type (${String(args)})`);
|
|
398
416
|
}
|
|
399
417
|
static _createComplexType(context, owner, args) {
|
|
418
|
+
const dataType = args._instance || {};
|
|
419
|
+
Object.setPrototypeOf(dataType, ComplexType.prototype);
|
|
400
420
|
const initArgs = cloneObject(args);
|
|
401
421
|
if (args.base) {
|
|
402
422
|
context.enter('.base', () => {
|
|
403
|
-
initArgs.base = (owner
|
|
404
|
-
this._createDataType(context, owner, args.base));
|
|
423
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
405
424
|
});
|
|
406
425
|
}
|
|
407
426
|
/** Set additionalFields */
|
|
@@ -410,14 +429,7 @@ export class DataTypeFactory {
|
|
|
410
429
|
if (typeof args.additionalFields === 'boolean' || Array.isArray(args.additionalFields))
|
|
411
430
|
initArgs.additionalFields = args.additionalFields;
|
|
412
431
|
else {
|
|
413
|
-
|
|
414
|
-
initArgs.additionalFields =
|
|
415
|
-
owner.node.findDataType(args.additionalFields) ||
|
|
416
|
-
this._createDataType(context, owner, args.additionalFields);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
420
|
-
}
|
|
432
|
+
initArgs.additionalFields = this._createDataType(context, owner, args.additionalFields);
|
|
421
433
|
}
|
|
422
434
|
});
|
|
423
435
|
}
|
|
@@ -427,7 +439,7 @@ export class DataTypeFactory {
|
|
|
427
439
|
context.enter('.fields', () => {
|
|
428
440
|
for (const [k, v] of Object.entries(args.fields)) {
|
|
429
441
|
context.enter(`[${k}]`, () => {
|
|
430
|
-
const type =
|
|
442
|
+
const type = this._createDataType(context, owner, v.type);
|
|
431
443
|
if (type)
|
|
432
444
|
initArgs.fields[k] = {
|
|
433
445
|
...v,
|
|
@@ -438,29 +450,37 @@ export class DataTypeFactory {
|
|
|
438
450
|
}
|
|
439
451
|
});
|
|
440
452
|
}
|
|
441
|
-
|
|
453
|
+
ComplexType.apply(dataType, [owner, initArgs]);
|
|
454
|
+
return dataType;
|
|
442
455
|
}
|
|
443
456
|
static _createEnumType(context, owner, args) {
|
|
457
|
+
const dataType = args._instance || {};
|
|
458
|
+
Object.setPrototypeOf(dataType, EnumType.prototype);
|
|
444
459
|
const initArgs = cloneObject(args);
|
|
445
460
|
if (args.base) {
|
|
446
461
|
context.enter('.base', () => {
|
|
447
|
-
initArgs.base = (owner
|
|
448
|
-
this._createDataType(context, owner, args.base));
|
|
462
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
449
463
|
});
|
|
450
464
|
}
|
|
451
465
|
initArgs.attributes = args.attributes;
|
|
452
|
-
|
|
466
|
+
EnumType.apply(dataType, [owner, initArgs]);
|
|
467
|
+
return dataType;
|
|
453
468
|
}
|
|
454
469
|
static _createMappedType(context, owner, args) {
|
|
470
|
+
const dataType = args._instance || {};
|
|
471
|
+
Object.setPrototypeOf(dataType, MappedType.prototype);
|
|
455
472
|
const initArgs = cloneObject(args);
|
|
456
473
|
if (args.base) {
|
|
457
474
|
context.enter('.base', () => {
|
|
458
|
-
initArgs.base =
|
|
475
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
459
476
|
});
|
|
460
477
|
}
|
|
461
|
-
|
|
478
|
+
MappedType.apply(dataType, [owner, initArgs]);
|
|
479
|
+
return dataType;
|
|
462
480
|
}
|
|
463
481
|
static _createMixinType(context, owner, args) {
|
|
482
|
+
const dataType = args._instance || {};
|
|
483
|
+
Object.setPrototypeOf(dataType, MixinType.prototype);
|
|
464
484
|
const initArgs = cloneObject(args);
|
|
465
485
|
if (args.types) {
|
|
466
486
|
context.enter('.types', () => {
|
|
@@ -468,7 +488,7 @@ export class DataTypeFactory {
|
|
|
468
488
|
let i = 0;
|
|
469
489
|
for (const t of args.types) {
|
|
470
490
|
context.enter(`[${i++}]`, () => {
|
|
471
|
-
const base =
|
|
491
|
+
const base = this._createDataType(context, owner, t);
|
|
472
492
|
if (!(base instanceof ComplexTypeBase))
|
|
473
493
|
throw new TypeError(`"${base?.kind}" can't be set as base for a "${initArgs.kind}"`);
|
|
474
494
|
initArgs.types.push(base);
|
|
@@ -476,17 +496,20 @@ export class DataTypeFactory {
|
|
|
476
496
|
}
|
|
477
497
|
});
|
|
478
498
|
}
|
|
479
|
-
|
|
499
|
+
MixinType.apply(dataType, [owner, initArgs]);
|
|
500
|
+
return dataType;
|
|
480
501
|
}
|
|
481
502
|
static _createSimpleType(context, owner, args) {
|
|
503
|
+
const dataType = args._instance || {};
|
|
504
|
+
Object.setPrototypeOf(dataType, SimpleType.prototype);
|
|
482
505
|
const initArgs = cloneObject(args);
|
|
483
506
|
if (args.base) {
|
|
484
507
|
context.enter('.base', () => {
|
|
485
|
-
initArgs.base = (owner
|
|
486
|
-
this._createDataType(context, owner, args.base));
|
|
508
|
+
initArgs.base = this._createDataType(context, owner, args.base);
|
|
487
509
|
});
|
|
488
510
|
}
|
|
489
|
-
|
|
511
|
+
SimpleType.apply(dataType, [owner, initArgs]);
|
|
512
|
+
return dataType;
|
|
490
513
|
}
|
|
491
514
|
}
|
|
492
515
|
function preferName(initArgs) {
|
|
@@ -28,8 +28,8 @@ export class HttpApi extends ApiBase {
|
|
|
28
28
|
url: this.url,
|
|
29
29
|
controllers: {},
|
|
30
30
|
};
|
|
31
|
-
for (const
|
|
32
|
-
out.controllers[name] = v.toJSON();
|
|
31
|
+
for (const v of this.controllers.values()) {
|
|
32
|
+
out.controllers[v.name] = v.toJSON();
|
|
33
33
|
}
|
|
34
34
|
return out;
|
|
35
35
|
}
|
|
@@ -106,20 +106,20 @@ class HttpControllerClass extends DocumentElement {
|
|
|
106
106
|
});
|
|
107
107
|
if (this.operations.size) {
|
|
108
108
|
out.operations = {};
|
|
109
|
-
for (const
|
|
110
|
-
out.operations[name] = v.toJSON();
|
|
109
|
+
for (const v of this.operations.values()) {
|
|
110
|
+
out.operations[v.name] = v.toJSON();
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
if (this.controllers.size) {
|
|
114
114
|
out.controllers = {};
|
|
115
|
-
for (const
|
|
116
|
-
out.controllers[name] = v.toJSON();
|
|
115
|
+
for (const v of this.controllers.values()) {
|
|
116
|
+
out.controllers[v.name] = v.toJSON();
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
if (this.types.size) {
|
|
120
120
|
out.types = {};
|
|
121
|
-
for (const
|
|
122
|
-
out.types[name] = v.toJSON();
|
|
121
|
+
for (const v of this.types.values()) {
|
|
122
|
+
out.types[v.name] = v.toJSON();
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
if (this.parameters.length) {
|
|
@@ -22,6 +22,7 @@ export const HttpParameter = function (owner, initArgs) {
|
|
|
22
22
|
_this.deprecated = initArgs.deprecated;
|
|
23
23
|
_this.required = initArgs.required;
|
|
24
24
|
_this.arraySeparator = initArgs.arraySeparator;
|
|
25
|
+
_this.keyParam = initArgs.keyParam;
|
|
25
26
|
};
|
|
26
27
|
/**
|
|
27
28
|
* @class HttpParameter
|
|
@@ -33,6 +34,7 @@ class HttpParameterClass extends Value {
|
|
|
33
34
|
name: this.name,
|
|
34
35
|
location: this.location,
|
|
35
36
|
arraySeparator: this.arraySeparator,
|
|
37
|
+
keyParam: this.keyParam,
|
|
36
38
|
required: this.required,
|
|
37
39
|
deprecated: this.deprecated,
|
|
38
40
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/common",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.5",
|
|
4
4
|
"description": "Opra common package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"lint": "eslint . --max-warnings=0",
|
|
26
26
|
"check": "madge --circular src/**",
|
|
27
27
|
"format": "prettier . --write --log-level=warn",
|
|
28
|
-
"test": "jest",
|
|
29
|
-
"cover": "jest --collect-coverage",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"cover": "jest --passWithNoTests --collect-coverage",
|
|
30
30
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
31
31
|
"clean:src": "ts-cleanup -s src --all",
|
|
32
32
|
"clean:test": "ts-cleanup -s test --all",
|
|
@@ -59,6 +59,8 @@ declare class ApiFieldClass extends DocumentElement {
|
|
|
59
59
|
readonly exclusive?: boolean;
|
|
60
60
|
readonly translatable?: boolean;
|
|
61
61
|
readonly deprecated?: boolean | string;
|
|
62
|
+
readonly readonly?: boolean;
|
|
63
|
+
readonly writeonly?: boolean;
|
|
62
64
|
readonly examples?: any[] | Record<string, any>;
|
|
63
65
|
toJSON(): OpraSchema.Field;
|
|
64
66
|
}
|
|
@@ -71,7 +71,7 @@ declare abstract class ComplexTypeClass extends ComplexTypeBase {
|
|
|
71
71
|
readonly kind: OpraSchema.ComplexType.Kind;
|
|
72
72
|
readonly base?: ComplexType | MappedType | MixinType;
|
|
73
73
|
readonly ctor?: Type;
|
|
74
|
-
extendsFrom(baseType: DataType): boolean;
|
|
74
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
75
75
|
toJSON(): OpraSchema.ComplexType;
|
|
76
76
|
}
|
|
77
77
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StrictOmit } from 'ts-gems';
|
|
1
|
+
import { StrictOmit, Type } from 'ts-gems';
|
|
2
2
|
import { ValidationOptions, Validator } from 'valgen';
|
|
3
3
|
import { FieldsProjection } from '../../helpers/index.js';
|
|
4
4
|
import type { DataTypeBase } from '../../schema/data-type/data-type.interface.js';
|
|
@@ -23,6 +23,8 @@ export declare namespace DataType {
|
|
|
23
23
|
caseInSensitive?: boolean;
|
|
24
24
|
partial?: boolean | 'deep';
|
|
25
25
|
projection?: string[] | FieldsProjection | '*';
|
|
26
|
+
ignoreReadonlyFields?: boolean;
|
|
27
|
+
ignoreWriteonlyFields?: boolean;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
interface DataTypeStatic {
|
|
@@ -52,7 +54,7 @@ declare abstract class DataTypeClass extends DocumentElement {
|
|
|
52
54
|
readonly examples?: OpraSchema.DataTypeExample[];
|
|
53
55
|
abstract generateCodec(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions): Validator;
|
|
54
56
|
get embedded(): any;
|
|
55
|
-
abstract extendsFrom(baseType: DataType): boolean;
|
|
57
|
+
abstract extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
56
58
|
toJSON(): OpraSchema.DataType;
|
|
57
59
|
toString(): string;
|
|
58
60
|
[nodeInspectCustom](): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import { Combine } from 'ts-gems';
|
|
2
|
+
import { Combine, Type } from 'ts-gems';
|
|
3
3
|
import { Validator } from 'valgen';
|
|
4
4
|
import { OpraSchema } from '../../schema/index.js';
|
|
5
5
|
import type { DocumentElement } from '../common/document-element.js';
|
|
@@ -63,7 +63,7 @@ declare class EnumTypeClass extends DataType {
|
|
|
63
63
|
readonly instance?: object;
|
|
64
64
|
readonly attributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
|
|
65
65
|
readonly ownAttributes: Record<string | number, OpraSchema.EnumType.ValueInfo>;
|
|
66
|
-
extendsFrom(baseType: DataType): boolean;
|
|
66
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
67
67
|
generateCodec(): Validator;
|
|
68
68
|
toJSON(): OpraSchema.EnumType;
|
|
69
69
|
}
|
|
@@ -5,7 +5,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
5
5
|
import { DocumentElement } from '../common/document-element.js';
|
|
6
6
|
import type { ComplexType } from './complex-type.js';
|
|
7
7
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
8
|
-
import
|
|
8
|
+
import { DataType } from './data-type.js';
|
|
9
9
|
import type { MixinType } from './mixin-type';
|
|
10
10
|
/**
|
|
11
11
|
* @namespace MappedType
|
|
@@ -67,7 +67,7 @@ declare class MappedTypeClass extends ComplexTypeBase {
|
|
|
67
67
|
readonly pick?: Field.Name[];
|
|
68
68
|
readonly partial?: Field.Name[] | boolean;
|
|
69
69
|
readonly required?: Field.Name[] | boolean;
|
|
70
|
-
extendsFrom(baseType: DataType): boolean;
|
|
70
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
71
71
|
toJSON(): OpraSchema.MappedType;
|
|
72
72
|
}
|
|
73
73
|
export {};
|
|
@@ -4,7 +4,7 @@ import { OpraSchema } from '../../schema/index.js';
|
|
|
4
4
|
import type { DocumentElement } from '../common/document-element.js';
|
|
5
5
|
import type { ComplexType } from './complex-type.js';
|
|
6
6
|
import { ComplexTypeBase } from './complex-type-base.js';
|
|
7
|
-
import
|
|
7
|
+
import { DataType } from './data-type.js';
|
|
8
8
|
import type { MappedType } from './mapped-type.js';
|
|
9
9
|
/**
|
|
10
10
|
* @namespace MixinType
|
|
@@ -76,7 +76,7 @@ export declare const MixinType: MixinTypeStatic;
|
|
|
76
76
|
declare class MixinTypeClass extends ComplexTypeBase {
|
|
77
77
|
readonly kind: OpraSchema.MixinType.Kind;
|
|
78
78
|
readonly types: (ComplexType | MixinType | MappedType)[];
|
|
79
|
-
extendsFrom(baseType: DataType): boolean;
|
|
79
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
80
80
|
toJSON(): OpraSchema.MixinType;
|
|
81
81
|
}
|
|
82
82
|
export {};
|
|
@@ -14,7 +14,7 @@ export declare namespace SimpleType {
|
|
|
14
14
|
kind: OpraSchema.SimpleType.Kind;
|
|
15
15
|
}, DataType.Metadata, OpraSchema.SimpleType> {
|
|
16
16
|
}
|
|
17
|
-
interface Options extends DataType.Options {
|
|
17
|
+
interface Options extends Combine<Pick<OpraSchema.SimpleType, 'nameMappings'>, DataType.Options> {
|
|
18
18
|
}
|
|
19
19
|
interface InitArguments extends Combine<{
|
|
20
20
|
kind: OpraSchema.SimpleType.Kind;
|
|
@@ -64,11 +64,13 @@ declare abstract class SimpleTypeClass extends DataType {
|
|
|
64
64
|
readonly kind: OpraSchema.SimpleType.Kind;
|
|
65
65
|
readonly base?: SimpleType;
|
|
66
66
|
readonly attributes: Record<string, SimpleType.Attribute>;
|
|
67
|
+
readonly nameMappings: Record<string, string>;
|
|
67
68
|
readonly ownAttributes: Record<string, SimpleType.Attribute>;
|
|
69
|
+
readonly ownNameMappings: Record<string, string>;
|
|
68
70
|
protected _generateDecoder?: SimpleType.ValidatorGenerator;
|
|
69
71
|
protected _generateEncoder?: SimpleType.ValidatorGenerator;
|
|
70
72
|
properties?: any;
|
|
71
|
-
extendsFrom(baseType: DataType): boolean;
|
|
73
|
+
extendsFrom(baseType: DataType | string | Type | object): boolean;
|
|
72
74
|
generateCodec<T extends Record<string, any> | object = object>(codec: 'encode' | 'decode', options?: DataType.GenerateCodecOptions | null, properties?: Partial<T>): Validator;
|
|
73
75
|
toJSON(): OpraSchema.SimpleType;
|
|
74
76
|
}
|
|
@@ -6,6 +6,7 @@ export interface HttpControllerDecorator<T extends HttpControllerDecorator<any>
|
|
|
6
6
|
Header(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
7
7
|
QueryParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
8
8
|
PathParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
9
|
+
KeyParam(name: string | RegExp, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync | false): T;
|
|
9
10
|
UseType(...type: TypeThunkAsync[]): T;
|
|
10
11
|
}
|
|
11
12
|
export interface HttpControllerDecoratorFactory {
|
|
@@ -18,24 +18,29 @@ export declare namespace DataTypeFactory {
|
|
|
18
18
|
type DataTypeSources = ThunkAsync<Type | EnumType.EnumObject | EnumType.EnumArray | object>[] | Record<string, OpraSchema.DataType>;
|
|
19
19
|
type DataTypeThunk = Type | EnumType.EnumObject | EnumType.EnumArray | object;
|
|
20
20
|
interface ComplexTypeInit extends Combine<{
|
|
21
|
+
_instance?: ComplexType;
|
|
21
22
|
base?: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
|
|
22
23
|
fields?: Record<string, ApiFieldInit>;
|
|
23
24
|
additionalFields?: boolean | string | DataTypeFactory.DataTypeInitArguments | ['error'] | ['error', string];
|
|
24
25
|
}, ComplexType.InitArguments> {
|
|
25
26
|
}
|
|
26
27
|
interface EnumTypeInit extends Combine<{
|
|
28
|
+
_instance?: MappedType;
|
|
27
29
|
base?: string | EnumTypeInit;
|
|
28
30
|
}, EnumType.InitArguments> {
|
|
29
31
|
}
|
|
30
32
|
interface MappedTypeInit extends Combine<{
|
|
33
|
+
_instance?: MappedType;
|
|
31
34
|
base: string | ComplexTypeInit | MappedTypeInit | MixinTypeInit;
|
|
32
35
|
}, MappedType.InitArguments> {
|
|
33
36
|
}
|
|
34
37
|
interface MixinTypeInit extends Combine<{
|
|
38
|
+
_instance?: MixinType;
|
|
35
39
|
types: (string | ComplexTypeInit | MappedTypeInit | MixinTypeInit)[];
|
|
36
40
|
}, MixinType.InitArguments> {
|
|
37
41
|
}
|
|
38
42
|
interface SimpleTypeInit extends Combine<{
|
|
43
|
+
_instance?: SimpleType;
|
|
39
44
|
base?: string | SimpleTypeInit;
|
|
40
45
|
}, SimpleType.InitArguments> {
|
|
41
46
|
}
|
|
@@ -12,6 +12,7 @@ export declare namespace HttpParameter {
|
|
|
12
12
|
interface Metadata extends StrictOmit<OpraSchema.HttpParameter, 'type'> {
|
|
13
13
|
name: string | RegExp;
|
|
14
14
|
type?: string | TypeThunkAsync | EnumType.EnumObject | EnumType.EnumArray | object;
|
|
15
|
+
keyParam?: boolean;
|
|
15
16
|
}
|
|
16
17
|
interface Options extends Partial<StrictOmit<Metadata, 'type'>> {
|
|
17
18
|
type?: string | TypeThunkAsync | object;
|
|
@@ -41,6 +42,7 @@ export declare const HttpParameter: HttpParameterStatic;
|
|
|
41
42
|
*/
|
|
42
43
|
declare class HttpParameterClass extends Value {
|
|
43
44
|
readonly owner: DocumentElement;
|
|
45
|
+
keyParam?: boolean;
|
|
44
46
|
deprecated?: boolean | string;
|
|
45
47
|
required?: boolean;
|
|
46
48
|
arraySeparator?: string;
|
|
@@ -9,6 +9,10 @@ export interface SimpleType extends StrictOmit<DataTypeBase, 'kind'> {
|
|
|
9
9
|
base?: DataType.Name;
|
|
10
10
|
attributes?: Record<string, Attribute>;
|
|
11
11
|
properties?: Record<string, any>;
|
|
12
|
+
/**
|
|
13
|
+
* Naming alternatives across software languages
|
|
14
|
+
*/
|
|
15
|
+
nameMappings?: Record<string, string>;
|
|
12
16
|
}
|
|
13
17
|
export declare namespace SimpleType {
|
|
14
18
|
const Kind = "SimpleType";
|
|
@@ -13,6 +13,10 @@ export interface HttpParameter extends Value {
|
|
|
13
13
|
* Name of the parameter. RegExp pattern can be used matching parameter name
|
|
14
14
|
*/
|
|
15
15
|
name: string | RegExp;
|
|
16
|
+
/**
|
|
17
|
+
* Determines if parameter is key
|
|
18
|
+
*/
|
|
19
|
+
keyParam?: boolean;
|
|
16
20
|
/**
|
|
17
21
|
* Defines array separator
|
|
18
22
|
*/
|