@opra/common 1.1.0 → 1.2.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/index.cjs +4 -4
- package/browser/index.mjs +4 -4
- package/cjs/document/data-type/api-field.js +4 -2
- package/cjs/document/data-type/complex-type.js +6 -5
- package/cjs/document/decorators/http-operation-entity.decorator.js +71 -0
- package/cjs/document/factory/data-type.factory.js +1 -0
- package/esm/document/data-type/api-field.js +4 -2
- package/esm/document/data-type/complex-type.js +6 -5
- package/esm/document/decorators/http-operation-entity.decorator.js +71 -0
- package/esm/document/factory/data-type.factory.js +1 -0
- package/package.json +1 -1
- package/types/document/data-type/api-field.d.ts +2 -1
- package/types/document/decorators/http-operation-entity.decorator.d.ts +9 -0
- package/types/schema/data-type/field.interface.d.ts +10 -6
|
@@ -35,7 +35,8 @@ exports.ApiField = function (...args) {
|
|
|
35
35
|
_this.fixed = initArgs.fixed;
|
|
36
36
|
_this.required = initArgs.required;
|
|
37
37
|
_this.exclusive = initArgs.exclusive;
|
|
38
|
-
_this.
|
|
38
|
+
_this.localisation = initArgs.localisation;
|
|
39
|
+
_this.keyField = initArgs.keyField;
|
|
39
40
|
_this.deprecated = initArgs.deprecated;
|
|
40
41
|
_this.readonly = initArgs.readonly;
|
|
41
42
|
_this.writeonly = initArgs.writeonly;
|
|
@@ -57,7 +58,8 @@ class ApiFieldClass extends document_element_js_1.DocumentElement {
|
|
|
57
58
|
fixed: this.fixed,
|
|
58
59
|
required: this.required || undefined,
|
|
59
60
|
exclusive: this.exclusive || undefined,
|
|
60
|
-
|
|
61
|
+
localisation: this.localisation || undefined,
|
|
62
|
+
keyField: this.keyField || undefined,
|
|
61
63
|
deprecated: this.deprecated || undefined,
|
|
62
64
|
readonly: this.readonly || undefined,
|
|
63
65
|
writeonly: this.writeonly || undefined,
|
|
@@ -24,8 +24,6 @@ exports.ComplexType = function (...args) {
|
|
|
24
24
|
complex_type_base_js_1.ComplexTypeBase.call(this, owner, initArgs, context);
|
|
25
25
|
const _this = (0, ts_gems_1.asMutable)(this);
|
|
26
26
|
_this.kind = index_js_2.OpraSchema.ComplexType.Kind;
|
|
27
|
-
_this.additionalFields = initArgs.additionalFields;
|
|
28
|
-
_this.keyField = initArgs.keyField;
|
|
29
27
|
if (initArgs.base) {
|
|
30
28
|
context.enter('.base', () => {
|
|
31
29
|
// noinspection SuspiciousTypeOfGuard
|
|
@@ -33,15 +31,18 @@ exports.ComplexType = function (...args) {
|
|
|
33
31
|
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
|
|
34
32
|
}
|
|
35
33
|
_this.base = initArgs.base;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
34
|
+
_this.additionalFields = _this.base.additionalFields;
|
|
35
|
+
_this.keyField = _this.base.keyField;
|
|
39
36
|
/** Copy fields from base */
|
|
40
37
|
for (const v of _this.base.fields.values()) {
|
|
41
38
|
this.fields.set(v.name, new api_field_js_1.ApiField(this, v));
|
|
42
39
|
}
|
|
43
40
|
});
|
|
44
41
|
}
|
|
42
|
+
if (initArgs.additionalFields !== undefined)
|
|
43
|
+
_this.additionalFields = initArgs.additionalFields;
|
|
44
|
+
if (initArgs.keyField !== undefined)
|
|
45
|
+
_this.keyField = initArgs.keyField;
|
|
45
46
|
_this.ctor = initArgs.ctor || _this.base?.ctor;
|
|
46
47
|
/** Add own fields */
|
|
47
48
|
if (initArgs.fields) {
|
|
@@ -331,6 +331,77 @@ http_operation_js_1.HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
331
331
|
});
|
|
332
332
|
return decorator;
|
|
333
333
|
};
|
|
334
|
+
/**
|
|
335
|
+
* HttpOperation.Entity.Replace
|
|
336
|
+
*/
|
|
337
|
+
http_operation_js_1.HttpOperation.Entity.Replace = function (arg0, arg1) {
|
|
338
|
+
let args;
|
|
339
|
+
if (typeof arg0 === 'object' && !arg0[constants_js_1.DATATYPE_METADATA]) {
|
|
340
|
+
args = arg0;
|
|
341
|
+
}
|
|
342
|
+
else
|
|
343
|
+
args = { ...arg1, type: arg0 };
|
|
344
|
+
/** Initialize the decorator and the chain */
|
|
345
|
+
const decoratorChain = [];
|
|
346
|
+
const decorator = (0, http_operation_decorator_js_1.HttpOperationDecoratorFactory)(decoratorChain, {
|
|
347
|
+
method: 'POST',
|
|
348
|
+
...args,
|
|
349
|
+
composition: 'Entity.Replace',
|
|
350
|
+
});
|
|
351
|
+
decorator
|
|
352
|
+
.QueryParam('projection', {
|
|
353
|
+
description: 'Determines fields projection',
|
|
354
|
+
type: new index_js_2.FieldPathType({
|
|
355
|
+
dataType: args.type,
|
|
356
|
+
allowSigns: 'each',
|
|
357
|
+
}),
|
|
358
|
+
isArray: true,
|
|
359
|
+
arraySeparator: ',',
|
|
360
|
+
})
|
|
361
|
+
.Response(index_js_1.HttpStatusCode.OK, {
|
|
362
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
|
|
363
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
364
|
+
type: args.type,
|
|
365
|
+
partial: 'deep',
|
|
366
|
+
})
|
|
367
|
+
.Response(index_js_1.HttpStatusCode.NO_CONTENT, {
|
|
368
|
+
description: 'Operation is successful but no resource found',
|
|
369
|
+
})
|
|
370
|
+
.Response(index_js_1.HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
371
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
372
|
+
contentType: index_js_1.MimeTypes.opra_response_json,
|
|
373
|
+
});
|
|
374
|
+
/**
|
|
375
|
+
*
|
|
376
|
+
*/
|
|
377
|
+
decorator.KeyParam = (name, prmOptions) => {
|
|
378
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
379
|
+
? {
|
|
380
|
+
name,
|
|
381
|
+
location: 'path',
|
|
382
|
+
type: prmOptions,
|
|
383
|
+
keyParam: true,
|
|
384
|
+
}
|
|
385
|
+
: {
|
|
386
|
+
...prmOptions,
|
|
387
|
+
name,
|
|
388
|
+
location: 'path',
|
|
389
|
+
keyParam: true,
|
|
390
|
+
};
|
|
391
|
+
decorator.PathParam(name, paramMeta);
|
|
392
|
+
decoratorChain.push((meta) => {
|
|
393
|
+
if (!meta.path?.includes(':' + name))
|
|
394
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
395
|
+
meta.mergePath = true;
|
|
396
|
+
});
|
|
397
|
+
return decorator;
|
|
398
|
+
};
|
|
399
|
+
decoratorChain.push((operationMeta) => {
|
|
400
|
+
const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
|
|
401
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
402
|
+
});
|
|
403
|
+
return decorator;
|
|
404
|
+
};
|
|
334
405
|
/**
|
|
335
406
|
* HttpOperation.Entity.UpdateMany
|
|
336
407
|
*/
|
|
@@ -284,6 +284,7 @@ class DataTypeFactory {
|
|
|
284
284
|
}
|
|
285
285
|
static async _prepareComplexTypeArgs(context, owner, initArgs, metadata) {
|
|
286
286
|
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
287
|
+
initArgs.keyField = metadata.keyField;
|
|
287
288
|
await context.enterAsync('.base', async () => {
|
|
288
289
|
let baseArgs;
|
|
289
290
|
if (metadata.base) {
|
|
@@ -32,7 +32,8 @@ export const ApiField = function (...args) {
|
|
|
32
32
|
_this.fixed = initArgs.fixed;
|
|
33
33
|
_this.required = initArgs.required;
|
|
34
34
|
_this.exclusive = initArgs.exclusive;
|
|
35
|
-
_this.
|
|
35
|
+
_this.localisation = initArgs.localisation;
|
|
36
|
+
_this.keyField = initArgs.keyField;
|
|
36
37
|
_this.deprecated = initArgs.deprecated;
|
|
37
38
|
_this.readonly = initArgs.readonly;
|
|
38
39
|
_this.writeonly = initArgs.writeonly;
|
|
@@ -54,7 +55,8 @@ class ApiFieldClass extends DocumentElement {
|
|
|
54
55
|
fixed: this.fixed,
|
|
55
56
|
required: this.required || undefined,
|
|
56
57
|
exclusive: this.exclusive || undefined,
|
|
57
|
-
|
|
58
|
+
localisation: this.localisation || undefined,
|
|
59
|
+
keyField: this.keyField || undefined,
|
|
58
60
|
deprecated: this.deprecated || undefined,
|
|
59
61
|
readonly: this.readonly || undefined,
|
|
60
62
|
writeonly: this.writeonly || undefined,
|
|
@@ -21,8 +21,6 @@ export const ComplexType = function (...args) {
|
|
|
21
21
|
ComplexTypeBase.call(this, owner, initArgs, context);
|
|
22
22
|
const _this = asMutable(this);
|
|
23
23
|
_this.kind = OpraSchema.ComplexType.Kind;
|
|
24
|
-
_this.additionalFields = initArgs.additionalFields;
|
|
25
|
-
_this.keyField = initArgs.keyField;
|
|
26
24
|
if (initArgs.base) {
|
|
27
25
|
context.enter('.base', () => {
|
|
28
26
|
// noinspection SuspiciousTypeOfGuard
|
|
@@ -30,15 +28,18 @@ export const ComplexType = function (...args) {
|
|
|
30
28
|
throw new TypeError(`"${initArgs.base.kind}" can't be set as base for a "${this.kind}"`);
|
|
31
29
|
}
|
|
32
30
|
_this.base = initArgs.base;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
31
|
+
_this.additionalFields = _this.base.additionalFields;
|
|
32
|
+
_this.keyField = _this.base.keyField;
|
|
36
33
|
/** Copy fields from base */
|
|
37
34
|
for (const v of _this.base.fields.values()) {
|
|
38
35
|
this.fields.set(v.name, new ApiField(this, v));
|
|
39
36
|
}
|
|
40
37
|
});
|
|
41
38
|
}
|
|
39
|
+
if (initArgs.additionalFields !== undefined)
|
|
40
|
+
_this.additionalFields = initArgs.additionalFields;
|
|
41
|
+
if (initArgs.keyField !== undefined)
|
|
42
|
+
_this.keyField = initArgs.keyField;
|
|
42
43
|
_this.ctor = initArgs.ctor || _this.base?.ctor;
|
|
43
44
|
/** Add own fields */
|
|
44
45
|
if (initArgs.fields) {
|
|
@@ -329,6 +329,77 @@ HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
|
329
329
|
});
|
|
330
330
|
return decorator;
|
|
331
331
|
};
|
|
332
|
+
/**
|
|
333
|
+
* HttpOperation.Entity.Replace
|
|
334
|
+
*/
|
|
335
|
+
HttpOperation.Entity.Replace = function (arg0, arg1) {
|
|
336
|
+
let args;
|
|
337
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
338
|
+
args = arg0;
|
|
339
|
+
}
|
|
340
|
+
else
|
|
341
|
+
args = { ...arg1, type: arg0 };
|
|
342
|
+
/** Initialize the decorator and the chain */
|
|
343
|
+
const decoratorChain = [];
|
|
344
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
345
|
+
method: 'POST',
|
|
346
|
+
...args,
|
|
347
|
+
composition: 'Entity.Replace',
|
|
348
|
+
});
|
|
349
|
+
decorator
|
|
350
|
+
.QueryParam('projection', {
|
|
351
|
+
description: 'Determines fields projection',
|
|
352
|
+
type: new FieldPathType({
|
|
353
|
+
dataType: args.type,
|
|
354
|
+
allowSigns: 'each',
|
|
355
|
+
}),
|
|
356
|
+
isArray: true,
|
|
357
|
+
arraySeparator: ',',
|
|
358
|
+
})
|
|
359
|
+
.Response(HttpStatusCode.OK, {
|
|
360
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
|
|
361
|
+
contentType: MimeTypes.opra_response_json,
|
|
362
|
+
type: args.type,
|
|
363
|
+
partial: 'deep',
|
|
364
|
+
})
|
|
365
|
+
.Response(HttpStatusCode.NO_CONTENT, {
|
|
366
|
+
description: 'Operation is successful but no resource found',
|
|
367
|
+
})
|
|
368
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
369
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
370
|
+
contentType: MimeTypes.opra_response_json,
|
|
371
|
+
});
|
|
372
|
+
/**
|
|
373
|
+
*
|
|
374
|
+
*/
|
|
375
|
+
decorator.KeyParam = (name, prmOptions) => {
|
|
376
|
+
const paramMeta = typeof prmOptions === 'string' || typeof prmOptions === 'function'
|
|
377
|
+
? {
|
|
378
|
+
name,
|
|
379
|
+
location: 'path',
|
|
380
|
+
type: prmOptions,
|
|
381
|
+
keyParam: true,
|
|
382
|
+
}
|
|
383
|
+
: {
|
|
384
|
+
...prmOptions,
|
|
385
|
+
name,
|
|
386
|
+
location: 'path',
|
|
387
|
+
keyParam: true,
|
|
388
|
+
};
|
|
389
|
+
decorator.PathParam(name, paramMeta);
|
|
390
|
+
decoratorChain.push((meta) => {
|
|
391
|
+
if (!meta.path?.includes(':' + name))
|
|
392
|
+
meta.path = (meta.path || '') + '@:' + name;
|
|
393
|
+
meta.mergePath = true;
|
|
394
|
+
});
|
|
395
|
+
return decorator;
|
|
396
|
+
};
|
|
397
|
+
decoratorChain.push((operationMeta) => {
|
|
398
|
+
const compositionOptions = (operationMeta.compositionOptions = operationMeta.compositionOptions || {});
|
|
399
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
400
|
+
});
|
|
401
|
+
return decorator;
|
|
402
|
+
};
|
|
332
403
|
/**
|
|
333
404
|
* HttpOperation.Entity.UpdateMany
|
|
334
405
|
*/
|
|
@@ -281,6 +281,7 @@ export class DataTypeFactory {
|
|
|
281
281
|
}
|
|
282
282
|
static async _prepareComplexTypeArgs(context, owner, initArgs, metadata) {
|
|
283
283
|
await this._prepareDataTypeArgs(context, initArgs, metadata);
|
|
284
|
+
initArgs.keyField = metadata.keyField;
|
|
284
285
|
await context.enterAsync('.base', async () => {
|
|
285
286
|
let baseArgs;
|
|
286
287
|
if (metadata.base) {
|
package/package.json
CHANGED
|
@@ -62,7 +62,8 @@ declare class ApiFieldClass extends DocumentElement {
|
|
|
62
62
|
readonly fixed?: any;
|
|
63
63
|
readonly required?: boolean;
|
|
64
64
|
readonly exclusive?: boolean;
|
|
65
|
-
readonly
|
|
65
|
+
readonly localisation?: boolean;
|
|
66
|
+
readonly keyField?: string;
|
|
66
67
|
readonly deprecated?: boolean | string;
|
|
67
68
|
readonly readonly?: boolean;
|
|
68
69
|
readonly writeonly?: boolean;
|
|
@@ -23,6 +23,8 @@ declare module '../http/http-operation.js' {
|
|
|
23
23
|
FindMany(args: HttpOperation.Entity.FindManyArgs): HttpOperation.Entity.FindManyDecorator;
|
|
24
24
|
Get(type: Type | string, options?: StrictOmit<HttpOperation.Entity.GetArgs, 'type'>): HttpOperation.Entity.GetDecorator;
|
|
25
25
|
Get(args: HttpOperation.Entity.GetArgs): HttpOperation.Entity.GetDecorator;
|
|
26
|
+
Replace(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateArgs, 'type'>): HttpOperation.Entity.ReplaceDecorator;
|
|
27
|
+
Replace(args: HttpOperation.Entity.ReplaceArgs): HttpOperation.Entity.ReplaceDecorator;
|
|
26
28
|
Update(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateArgs, 'type'>): HttpOperation.Entity.UpdateDecorator;
|
|
27
29
|
Update(args: HttpOperation.Entity.UpdateArgs): HttpOperation.Entity.UpdateDecorator;
|
|
28
30
|
UpdateMany(type: Type | string, options?: StrictOmit<HttpOperation.Entity.UpdateManyArgs, 'type'>): HttpOperation.Entity.UpdateManyDecorator;
|
|
@@ -73,6 +75,13 @@ declare module '../http/http-operation.js' {
|
|
|
73
75
|
interface GetArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
|
|
74
76
|
type: Type | string;
|
|
75
77
|
}
|
|
78
|
+
/** Replace */
|
|
79
|
+
interface ReplaceDecorator extends HttpOperationDecorator {
|
|
80
|
+
KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this;
|
|
81
|
+
}
|
|
82
|
+
interface ReplaceArgs extends StrictOmit<HttpOperation.Options, 'method' | 'requestBody'> {
|
|
83
|
+
type: Type | string;
|
|
84
|
+
}
|
|
76
85
|
/** Update */
|
|
77
86
|
interface UpdateDecorator extends HttpOperationDecorator {
|
|
78
87
|
KeyParam(name: string, optionsOrType?: StrictOmit<HttpParameter.Options, 'location'> | string | TypeThunkAsync): this;
|
|
@@ -9,10 +9,6 @@ export type Field = {
|
|
|
9
9
|
* Defines the description of the field
|
|
10
10
|
*/
|
|
11
11
|
description?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Indicates if the field value is an array
|
|
14
|
-
*/
|
|
15
|
-
isArray?: boolean;
|
|
16
12
|
/**
|
|
17
13
|
* Defines the default value of the field
|
|
18
14
|
*/
|
|
@@ -39,9 +35,17 @@ export type Field = {
|
|
|
39
35
|
*/
|
|
40
36
|
exclusive?: boolean;
|
|
41
37
|
/**
|
|
42
|
-
*
|
|
38
|
+
* Indicates if the field value is an array
|
|
39
|
+
*/
|
|
40
|
+
isArray?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Indicates key field when this field is a ComplexType array
|
|
43
|
+
*/
|
|
44
|
+
keyField?: string;
|
|
45
|
+
/**
|
|
46
|
+
* If true, this Field is a candidate for localisation
|
|
43
47
|
*/
|
|
44
|
-
|
|
48
|
+
localisation?: boolean;
|
|
45
49
|
/**
|
|
46
50
|
* Defines example values for the field
|
|
47
51
|
*/
|