@opra/common 1.7.4 → 1.9.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 +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/data-type/api-field.js +2 -0
- package/cjs/document/data-type/enum-type.js +2 -2
- package/cjs/document/decorators/api-field-decorator.js +1 -0
- package/cjs/document/decorators/http-operation-entity-create.decorator.js +58 -0
- package/cjs/document/decorators/http-operation-entity-delete-many.decorator.js +41 -0
- package/cjs/document/decorators/http-operation-entity-delete.decorator.js +41 -0
- package/cjs/document/decorators/http-operation-entity-find-many.decorator.js +85 -0
- package/cjs/document/decorators/http-operation-entity-get.decorator.js +56 -0
- package/cjs/document/decorators/http-operation-entity-replace.decorator.js +56 -0
- package/cjs/document/decorators/http-operation-entity-update-many.decorator.js +50 -0
- package/cjs/document/decorators/http-operation-entity-update.decorator.js +66 -0
- package/cjs/document/decorators/http-operation-entity.decorator.js +83 -525
- package/cjs/document/http/http-parameter.js +1 -0
- package/cjs/document/index.js +9 -1
- package/cjs/filter/antlr/OpraFilterLexer.js +212 -347
- package/cjs/filter/antlr/OpraFilterListener.js +1 -1
- package/cjs/filter/antlr/OpraFilterParser.js +198 -227
- package/cjs/filter/antlr/OpraFilterVisitor.js +1 -1
- package/cjs/filter/ast/index.js +1 -0
- package/cjs/filter/ast/terms/date-time-literal.js +27 -0
- package/cjs/filter/build.js +3 -1
- package/cjs/filter/filter-rules.js +2 -1
- package/cjs/filter/filter-tree-visitor.js +1 -1
- package/esm/document/data-type/api-field.js +2 -0
- package/esm/document/data-type/enum-type.js +2 -2
- package/esm/document/decorators/api-field-decorator.js +1 -0
- package/esm/document/decorators/http-operation-entity-create.decorator.js +56 -0
- package/esm/document/decorators/http-operation-entity-delete-many.decorator.js +39 -0
- package/esm/document/decorators/http-operation-entity-delete.decorator.js +39 -0
- package/esm/document/decorators/http-operation-entity-find-many.decorator.js +83 -0
- package/esm/document/decorators/http-operation-entity-get.decorator.js +54 -0
- package/esm/document/decorators/http-operation-entity-replace.decorator.js +54 -0
- package/esm/document/decorators/http-operation-entity-update-many.decorator.js +48 -0
- package/esm/document/decorators/http-operation-entity-update.decorator.js +64 -0
- package/esm/document/decorators/http-operation-entity.decorator.js +79 -525
- package/esm/document/http/http-parameter.js +1 -0
- package/esm/document/index.js +9 -1
- package/esm/filter/antlr/OpraFilterLexer.js +213 -348
- package/esm/filter/antlr/OpraFilterListener.js +2 -2
- package/esm/filter/antlr/OpraFilterParser.js +198 -227
- package/esm/filter/antlr/OpraFilterVisitor.js +1 -1
- package/esm/filter/ast/index.js +1 -0
- package/esm/filter/ast/terms/date-time-literal.js +23 -0
- package/esm/filter/build.js +3 -1
- package/esm/filter/filter-rules.js +2 -1
- package/esm/filter/filter-tree-visitor.js +2 -2
- package/package.json +2 -2
- package/types/document/data-type/api-field.d.ts +2 -1
- package/types/document/data-type/enum-type.d.ts +3 -3
- package/types/document/decorators/api-field-decorator.d.ts +2 -2
- package/types/document/decorators/http-operation-entity-create.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-delete-many.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-delete.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-find-many.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-get.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-replace.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-update-many.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity-update.decorator.d.ts +1 -0
- package/types/document/decorators/http-operation-entity.decorator.d.ts +32 -4
- package/types/document/http/http-parameter.d.ts +3 -0
- package/types/document/index.d.ts +9 -1
- package/types/filter/antlr/OpraFilterLexer.d.ts +1 -1
- package/types/filter/antlr/OpraFilterListener.d.ts +36 -10
- package/types/filter/antlr/OpraFilterParser.d.ts +1 -1
- package/types/filter/antlr/OpraFilterVisitor.d.ts +31 -5
- package/types/filter/ast/expressions/comparison-expression.d.ts +1 -0
- package/types/filter/ast/index.d.ts +1 -0
- package/types/filter/ast/terms/date-time-literal.d.ts +6 -0
- package/types/filter/filter-rules.d.ts +1 -0
- package/types/filter/filter-tree-visitor.d.ts +2 -2
- package/types/schema/data-type/field.interface.d.ts +16 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.
|
|
2
|
+
// Generated from ./src/filter/antlr/OpraFilter.g4 by ANTLR 4.13.2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const antlr4_1 = require("@browsery/antlr4");
|
|
5
5
|
/**
|
package/cjs/filter/ast/index.js
CHANGED
|
@@ -13,6 +13,7 @@ tslib_1.__exportStar(require("./expressions/negative-expression.js"), exports);
|
|
|
13
13
|
tslib_1.__exportStar(require("./expressions/parenthesized-expression.js"), exports);
|
|
14
14
|
tslib_1.__exportStar(require("./terms/boolean-literal.js"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./terms/date-literal.js"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./terms/date-time-literal.js"), exports);
|
|
16
17
|
tslib_1.__exportStar(require("./terms/null-literal.js"), exports);
|
|
17
18
|
tslib_1.__exportStar(require("./terms/number-literal.js"), exports);
|
|
18
19
|
tslib_1.__exportStar(require("./terms/qualified-identifier.js"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateTimeLiteral = void 0;
|
|
4
|
+
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
+
const errors_js_1 = require("../../errors.js");
|
|
6
|
+
const utils_js_1 = require("../../utils.js");
|
|
7
|
+
const literal_js_1 = require("../abstract/literal.js");
|
|
8
|
+
const NullDate = new Date(0);
|
|
9
|
+
class DateTimeLiteral extends literal_js_1.Literal {
|
|
10
|
+
constructor(value) {
|
|
11
|
+
super('');
|
|
12
|
+
if (value instanceof Date) {
|
|
13
|
+
this.value = value.toISOString();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// noinspection SuspiciousTypeOfGuard
|
|
17
|
+
if (typeof value === 'string' && (0, putil_varhelpers_1.toDateDef)(value, NullDate) !== NullDate) {
|
|
18
|
+
this.value = value;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
throw new errors_js_1.FilterValidationError(`Invalid date-time value "${value}"`);
|
|
22
|
+
}
|
|
23
|
+
toString() {
|
|
24
|
+
return (0, utils_js_1.quoteFilterString)(this.value);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DateTimeLiteral = DateTimeLiteral;
|
package/cjs/filter/build.js
CHANGED
|
@@ -104,7 +104,9 @@ function $arithmetic(n) {
|
|
|
104
104
|
return exp;
|
|
105
105
|
}
|
|
106
106
|
function comparisonExpression(op, left, right) {
|
|
107
|
-
const lex =
|
|
107
|
+
const lex = typeof left === 'string'
|
|
108
|
+
? new index_js_1.QualifiedIdentifier(left)
|
|
109
|
+
: wrapEntryValue(left);
|
|
108
110
|
const rex = wrapEntryValue(right);
|
|
109
111
|
return new index_js_1.ComparisonExpression({ op, left: lex, right: rex });
|
|
110
112
|
}
|
|
@@ -44,7 +44,6 @@ class FilterRules {
|
|
|
44
44
|
throw new TypeError(`Invalid filter query. Left side should be a data field.`);
|
|
45
45
|
}
|
|
46
46
|
// Check if filtering accepted for given field
|
|
47
|
-
// const findManyOp = this.getOperation('findMany');
|
|
48
47
|
const rule = this._rules.get(ast.left.value);
|
|
49
48
|
if (!rule) {
|
|
50
49
|
throw new index_js_1.OpraException({
|
|
@@ -70,6 +69,8 @@ class FilterRules {
|
|
|
70
69
|
},
|
|
71
70
|
});
|
|
72
71
|
}
|
|
72
|
+
if (rule.prepare)
|
|
73
|
+
ast.prepare = rule.prepare;
|
|
73
74
|
this.normalizeFilterAst(ast.right, stack, currentType);
|
|
74
75
|
stack.pop();
|
|
75
76
|
return ast;
|
|
@@ -85,7 +85,7 @@ class FilterTreeVisitor extends antlr4_1.ParseTreeVisitor {
|
|
|
85
85
|
return new index_js_1.DateLiteral((0, utils_js_1.unquoteFilterString)(ctx.getText()));
|
|
86
86
|
}
|
|
87
87
|
visitDateTimeLiteral(ctx) {
|
|
88
|
-
return new index_js_1.
|
|
88
|
+
return new index_js_1.DateTimeLiteral((0, utils_js_1.unquoteFilterString)(ctx.getText()));
|
|
89
89
|
}
|
|
90
90
|
visitTimeLiteral(ctx) {
|
|
91
91
|
return new index_js_1.TimeLiteral((0, utils_js_1.unquoteFilterString)(ctx.getText()));
|
|
@@ -33,6 +33,7 @@ export const ApiField = function (...args) {
|
|
|
33
33
|
_this.type = initArgs.type || owner.node.getDataType('any');
|
|
34
34
|
_this.description = initArgs.description;
|
|
35
35
|
_this.isArray = initArgs.isArray;
|
|
36
|
+
_this.isNestedEntity = initArgs.isNestedEntity;
|
|
36
37
|
_this.default = initArgs.default;
|
|
37
38
|
_this.fixed = initArgs.fixed;
|
|
38
39
|
_this.required = initArgs.required;
|
|
@@ -93,6 +94,7 @@ class ApiFieldClass extends DocumentElement {
|
|
|
93
94
|
type: typeName ? typeName : this.type?.toJSON(options),
|
|
94
95
|
description: this.description,
|
|
95
96
|
isArray: this.isArray || undefined,
|
|
97
|
+
isNestedEntity: this.isNestedEntity || undefined,
|
|
96
98
|
default: this.default,
|
|
97
99
|
fixed: this.fixed,
|
|
98
100
|
required: this.required || undefined,
|
|
@@ -105,8 +105,8 @@ function EnumTypeFactory(enumSource, ...args) {
|
|
|
105
105
|
const metadata = {
|
|
106
106
|
kind: OpraSchema.EnumType.Kind,
|
|
107
107
|
attributes,
|
|
108
|
-
base: options
|
|
109
|
-
name: options
|
|
108
|
+
base: options?.base,
|
|
109
|
+
name: options?.name,
|
|
110
110
|
description: options?.description,
|
|
111
111
|
};
|
|
112
112
|
Object.defineProperty(enumSource, DATATYPE_METADATA, {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { FieldPathType } from '../data-type/extended-types/index.js';
|
|
4
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
5
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
6
|
+
import { getDataTypeName } from './http-operation-entity.decorator.js';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
HttpOperation.Entity.Create = function (arg0, arg1) {
|
|
11
|
+
let args;
|
|
12
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
13
|
+
args = arg0;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
args = { ...arg1, type: arg0 };
|
|
17
|
+
/** Initialize the decorator and the chain */
|
|
18
|
+
const decoratorChain = [];
|
|
19
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
...args,
|
|
22
|
+
composition: 'Entity.Create',
|
|
23
|
+
requestBody: {
|
|
24
|
+
immediateFetch: true,
|
|
25
|
+
...args.requestBody,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
decorator
|
|
30
|
+
.QueryParam('projection', {
|
|
31
|
+
description: 'Determines fields projection',
|
|
32
|
+
type: new FieldPathType({
|
|
33
|
+
dataType: args.type,
|
|
34
|
+
allowSigns: 'each',
|
|
35
|
+
}),
|
|
36
|
+
isArray: true,
|
|
37
|
+
arraySeparator: ',',
|
|
38
|
+
})
|
|
39
|
+
.RequestContent(args.requestBody?.type || args.type)
|
|
40
|
+
.Response(HttpStatusCode.CREATED, {
|
|
41
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the created resource.',
|
|
42
|
+
contentType: MimeTypes.opra_response_json,
|
|
43
|
+
type: args.type,
|
|
44
|
+
partial: 'deep',
|
|
45
|
+
})
|
|
46
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
47
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
48
|
+
contentType: MimeTypes.opra_response_json,
|
|
49
|
+
});
|
|
50
|
+
decoratorChain.push((operationMeta) => {
|
|
51
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
52
|
+
operationMeta.compositionOptions || {});
|
|
53
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
54
|
+
});
|
|
55
|
+
return decorator;
|
|
56
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
4
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
5
|
+
import { createFilterDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
6
|
+
/**
|
|
7
|
+
* HttpOperation.Entity.DeleteMany
|
|
8
|
+
*/
|
|
9
|
+
HttpOperation.Entity.DeleteMany = function (arg0, arg1) {
|
|
10
|
+
let args;
|
|
11
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
12
|
+
args = arg0;
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
args = { ...arg1, type: arg0 };
|
|
16
|
+
/** Initialize the decorator and the chain */
|
|
17
|
+
const decoratorChain = [];
|
|
18
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
19
|
+
method: 'DELETE',
|
|
20
|
+
...args,
|
|
21
|
+
composition: 'Entity.DeleteMany',
|
|
22
|
+
});
|
|
23
|
+
decorator
|
|
24
|
+
.Response(HttpStatusCode.OK, {
|
|
25
|
+
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
26
|
+
contentType: MimeTypes.opra_response_json,
|
|
27
|
+
})
|
|
28
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
29
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
30
|
+
contentType: MimeTypes.opra_response_json,
|
|
31
|
+
});
|
|
32
|
+
decoratorChain.push((operationMeta) => {
|
|
33
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
34
|
+
operationMeta.compositionOptions || {});
|
|
35
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
36
|
+
});
|
|
37
|
+
decorator.Filter = createFilterDecorator(decorator, decoratorChain, args.type);
|
|
38
|
+
return decorator;
|
|
39
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
4
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
5
|
+
import { createKeyParamDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
6
|
+
/**
|
|
7
|
+
* HttpOperation.Entity.Delete
|
|
8
|
+
*/
|
|
9
|
+
HttpOperation.Entity.Delete = function (arg0, arg1) {
|
|
10
|
+
let args;
|
|
11
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
12
|
+
args = arg0;
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
args = { ...arg1, type: arg0 };
|
|
16
|
+
/** Initialize the decorator and the chain */
|
|
17
|
+
const decoratorChain = [];
|
|
18
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
19
|
+
method: 'DELETE',
|
|
20
|
+
...args,
|
|
21
|
+
composition: 'Entity.Delete',
|
|
22
|
+
});
|
|
23
|
+
decorator
|
|
24
|
+
.Response(HttpStatusCode.OK, {
|
|
25
|
+
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
26
|
+
contentType: MimeTypes.opra_response_json,
|
|
27
|
+
})
|
|
28
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
29
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
30
|
+
contentType: MimeTypes.opra_response_json,
|
|
31
|
+
});
|
|
32
|
+
decoratorChain.push((operationMeta) => {
|
|
33
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
34
|
+
operationMeta.compositionOptions || {});
|
|
35
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
36
|
+
});
|
|
37
|
+
decorator.KeyParam = createKeyParamDecorator(decorator, decoratorChain);
|
|
38
|
+
return decorator;
|
|
39
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { FieldPathType } from '../data-type/extended-types/index.js';
|
|
4
|
+
import { IntegerType } from '../data-type/primitive-types/index.js';
|
|
5
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
6
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
7
|
+
import { createFilterDecorator, createSortFieldsDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
8
|
+
/**
|
|
9
|
+
* HttpOperation.Entity.FindMany
|
|
10
|
+
*/
|
|
11
|
+
HttpOperation.Entity.FindMany = function (arg0, arg1) {
|
|
12
|
+
let args;
|
|
13
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
14
|
+
args = arg0;
|
|
15
|
+
}
|
|
16
|
+
else
|
|
17
|
+
args = { ...arg1, type: arg0 };
|
|
18
|
+
/** Initialize the decorator and the chain */
|
|
19
|
+
const decoratorChain = [];
|
|
20
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
21
|
+
method: 'GET',
|
|
22
|
+
...args,
|
|
23
|
+
composition: 'Entity.FindMany',
|
|
24
|
+
});
|
|
25
|
+
decorator
|
|
26
|
+
.Response(HttpStatusCode.OK, {
|
|
27
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains list of resources.',
|
|
28
|
+
contentType: MimeTypes.opra_response_json,
|
|
29
|
+
type: args.type,
|
|
30
|
+
partial: 'deep',
|
|
31
|
+
isArray: true,
|
|
32
|
+
})
|
|
33
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
34
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
35
|
+
contentType: MimeTypes.opra_response_json,
|
|
36
|
+
})
|
|
37
|
+
.QueryParam('limit', {
|
|
38
|
+
description: 'Determines number of returning instances',
|
|
39
|
+
type: new IntegerType({ minValue: 1, maxValue: args.maxLimit }),
|
|
40
|
+
})
|
|
41
|
+
.QueryParam('skip', {
|
|
42
|
+
description: 'Determines number of returning instances',
|
|
43
|
+
type: new IntegerType({ minValue: 1 }),
|
|
44
|
+
})
|
|
45
|
+
.QueryParam('count', {
|
|
46
|
+
description: 'Counts all matching instances if enabled',
|
|
47
|
+
type: Boolean,
|
|
48
|
+
})
|
|
49
|
+
.QueryParam('projection', {
|
|
50
|
+
description: 'Determines fields projection',
|
|
51
|
+
type: new FieldPathType({
|
|
52
|
+
dataType: args.type,
|
|
53
|
+
allowSigns: 'each',
|
|
54
|
+
}),
|
|
55
|
+
isArray: true,
|
|
56
|
+
arraySeparator: ',',
|
|
57
|
+
});
|
|
58
|
+
decoratorChain.push((operationMeta) => {
|
|
59
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
60
|
+
operationMeta.compositionOptions || {});
|
|
61
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
62
|
+
if (args.defaultLimit)
|
|
63
|
+
compositionOptions.defaultLimit = args.defaultLimit;
|
|
64
|
+
if (args.defaultProjection)
|
|
65
|
+
compositionOptions.defaultProjection = args.defaultProjection;
|
|
66
|
+
if (args.maxLimit)
|
|
67
|
+
compositionOptions.maxLimit = args.maxLimit;
|
|
68
|
+
});
|
|
69
|
+
decorator.Filter = createFilterDecorator(decorator, decoratorChain, args.type);
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
decorator.DefaultSort = (...fields) => {
|
|
74
|
+
decoratorChain.push((operationMeta) => {
|
|
75
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
76
|
+
operationMeta.compositionOptions || {});
|
|
77
|
+
compositionOptions.defaultSort = fields;
|
|
78
|
+
});
|
|
79
|
+
return decorator;
|
|
80
|
+
};
|
|
81
|
+
decorator.SortFields = createSortFieldsDecorator(decorator, decoratorChain);
|
|
82
|
+
return decorator;
|
|
83
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { FieldPathType } from '../data-type/extended-types/index.js';
|
|
4
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
5
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
6
|
+
import { createKeyParamDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
7
|
+
/**
|
|
8
|
+
* HttpOperation.Entity.Get
|
|
9
|
+
*/
|
|
10
|
+
HttpOperation.Entity.Get = function (arg0, arg1) {
|
|
11
|
+
let args;
|
|
12
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
13
|
+
args = arg0;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
args = { ...arg1, type: arg0 };
|
|
17
|
+
/** Initialize the decorator and the chain */
|
|
18
|
+
const decoratorChain = [];
|
|
19
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
...args,
|
|
22
|
+
composition: 'Entity.Get',
|
|
23
|
+
});
|
|
24
|
+
decorator
|
|
25
|
+
.QueryParam('projection', {
|
|
26
|
+
description: 'Determines fields projection',
|
|
27
|
+
type: new FieldPathType({
|
|
28
|
+
dataType: args.type,
|
|
29
|
+
allowSigns: 'each',
|
|
30
|
+
}),
|
|
31
|
+
isArray: true,
|
|
32
|
+
arraySeparator: ',',
|
|
33
|
+
})
|
|
34
|
+
.Response(HttpStatusCode.OK, {
|
|
35
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
|
|
36
|
+
contentType: MimeTypes.opra_response_json,
|
|
37
|
+
type: args.type,
|
|
38
|
+
partial: 'deep',
|
|
39
|
+
})
|
|
40
|
+
.Response(HttpStatusCode.NO_CONTENT, {
|
|
41
|
+
description: 'Operation is successful but no resource found',
|
|
42
|
+
})
|
|
43
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
44
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
45
|
+
contentType: MimeTypes.opra_response_json,
|
|
46
|
+
});
|
|
47
|
+
decoratorChain.push((operationMeta) => {
|
|
48
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
49
|
+
operationMeta.compositionOptions || {});
|
|
50
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
51
|
+
});
|
|
52
|
+
decorator.KeyParam = createKeyParamDecorator(decorator, decoratorChain);
|
|
53
|
+
return decorator;
|
|
54
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { FieldPathType } from '../data-type/extended-types/index.js';
|
|
4
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
5
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
6
|
+
import { createKeyParamDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
7
|
+
/**
|
|
8
|
+
* HttpOperation.Entity.Replace
|
|
9
|
+
*/
|
|
10
|
+
HttpOperation.Entity.Replace = function (arg0, arg1) {
|
|
11
|
+
let args;
|
|
12
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
13
|
+
args = arg0;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
args = { ...arg1, type: arg0 };
|
|
17
|
+
/** Initialize the decorator and the chain */
|
|
18
|
+
const decoratorChain = [];
|
|
19
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
...args,
|
|
22
|
+
composition: 'Entity.Replace',
|
|
23
|
+
});
|
|
24
|
+
decorator
|
|
25
|
+
.QueryParam('projection', {
|
|
26
|
+
description: 'Determines fields projection',
|
|
27
|
+
type: new FieldPathType({
|
|
28
|
+
dataType: args.type,
|
|
29
|
+
allowSigns: 'each',
|
|
30
|
+
}),
|
|
31
|
+
isArray: true,
|
|
32
|
+
arraySeparator: ',',
|
|
33
|
+
})
|
|
34
|
+
.Response(HttpStatusCode.OK, {
|
|
35
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains the resource asked for.',
|
|
36
|
+
contentType: MimeTypes.opra_response_json,
|
|
37
|
+
type: args.type,
|
|
38
|
+
partial: 'deep',
|
|
39
|
+
})
|
|
40
|
+
.Response(HttpStatusCode.NO_CONTENT, {
|
|
41
|
+
description: 'Operation is successful but no resource found',
|
|
42
|
+
})
|
|
43
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
44
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
45
|
+
contentType: MimeTypes.opra_response_json,
|
|
46
|
+
});
|
|
47
|
+
decoratorChain.push((operationMeta) => {
|
|
48
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
49
|
+
operationMeta.compositionOptions || {});
|
|
50
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
51
|
+
});
|
|
52
|
+
decorator.KeyParam = createKeyParamDecorator(decorator, decoratorChain);
|
|
53
|
+
return decorator;
|
|
54
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
4
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
5
|
+
import { createFilterDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
6
|
+
/**
|
|
7
|
+
* HttpOperation.Entity.UpdateMany
|
|
8
|
+
*/
|
|
9
|
+
HttpOperation.Entity.UpdateMany = function (arg0, arg1) {
|
|
10
|
+
let args;
|
|
11
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
12
|
+
args = arg0;
|
|
13
|
+
}
|
|
14
|
+
else
|
|
15
|
+
args = { ...arg1, type: arg0 };
|
|
16
|
+
/** Initialize the decorator and the chain */
|
|
17
|
+
const decoratorChain = [];
|
|
18
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
19
|
+
method: 'PATCH',
|
|
20
|
+
...args,
|
|
21
|
+
composition: 'Entity.UpdateMany',
|
|
22
|
+
requestBody: {
|
|
23
|
+
immediateFetch: true,
|
|
24
|
+
partial: 'deep',
|
|
25
|
+
allowPatchOperators: true,
|
|
26
|
+
keepKeyFields: true,
|
|
27
|
+
...args.requestBody,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
decorator
|
|
32
|
+
.RequestContent(args.requestBody?.type || args.type)
|
|
33
|
+
.Response(HttpStatusCode.OK, {
|
|
34
|
+
description: 'Operation is successful. Returns OperationResult with "affected" field.',
|
|
35
|
+
contentType: MimeTypes.opra_response_json,
|
|
36
|
+
})
|
|
37
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
38
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
39
|
+
contentType: MimeTypes.opra_response_json,
|
|
40
|
+
});
|
|
41
|
+
decoratorChain.push((operationMeta) => {
|
|
42
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
43
|
+
operationMeta.compositionOptions || {});
|
|
44
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
45
|
+
});
|
|
46
|
+
decorator.Filter = createFilterDecorator(decorator, decoratorChain, args.type);
|
|
47
|
+
return decorator;
|
|
48
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { HttpStatusCode, MimeTypes } from '../../enums/index.js';
|
|
2
|
+
import { DATATYPE_METADATA } from '../constants.js';
|
|
3
|
+
import { FieldPathType } from '../data-type/extended-types/index.js';
|
|
4
|
+
import { HttpOperation } from '../http/http-operation.js';
|
|
5
|
+
import { HttpOperationDecoratorFactory } from './http-operation.decorator.js';
|
|
6
|
+
import { createFilterDecorator, createKeyParamDecorator, getDataTypeName, } from './http-operation-entity.decorator.js';
|
|
7
|
+
/**
|
|
8
|
+
* HttpOperation.Entity.Update
|
|
9
|
+
*/
|
|
10
|
+
HttpOperation.Entity.Update = function (arg0, arg1) {
|
|
11
|
+
let args;
|
|
12
|
+
if (typeof arg0 === 'object' && !arg0[DATATYPE_METADATA]) {
|
|
13
|
+
args = arg0;
|
|
14
|
+
}
|
|
15
|
+
else
|
|
16
|
+
args = { ...arg1, type: arg0 };
|
|
17
|
+
/** Initialize the decorator and the chain */
|
|
18
|
+
const decoratorChain = [];
|
|
19
|
+
const decorator = HttpOperationDecoratorFactory(decoratorChain, {
|
|
20
|
+
method: 'PATCH',
|
|
21
|
+
...args,
|
|
22
|
+
composition: 'Entity.Update',
|
|
23
|
+
requestBody: {
|
|
24
|
+
partial: 'deep',
|
|
25
|
+
immediateFetch: true,
|
|
26
|
+
allowPatchOperators: true,
|
|
27
|
+
keepKeyFields: true,
|
|
28
|
+
...args.requestBody,
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
decorator
|
|
33
|
+
.QueryParam('projection', {
|
|
34
|
+
description: 'Determines fields projection',
|
|
35
|
+
type: new FieldPathType({
|
|
36
|
+
dataType: args.type,
|
|
37
|
+
allowSigns: 'each',
|
|
38
|
+
}),
|
|
39
|
+
isArray: true,
|
|
40
|
+
arraySeparator: ',',
|
|
41
|
+
})
|
|
42
|
+
.RequestContent(args.requestBody?.type || args.type)
|
|
43
|
+
.Response(HttpStatusCode.OK, {
|
|
44
|
+
description: 'Operation is successful. Returns OperationResult with "payload" field that contains updated resource.',
|
|
45
|
+
contentType: MimeTypes.opra_response_json,
|
|
46
|
+
type: args.type,
|
|
47
|
+
partial: 'deep',
|
|
48
|
+
})
|
|
49
|
+
.Response(HttpStatusCode.NO_CONTENT, {
|
|
50
|
+
description: 'Operation is successful but no resource found',
|
|
51
|
+
})
|
|
52
|
+
.Response(HttpStatusCode.UNPROCESSABLE_ENTITY, {
|
|
53
|
+
description: 'The request was well-formed but was unable to process operation due to one or many errors.',
|
|
54
|
+
contentType: MimeTypes.opra_response_json,
|
|
55
|
+
});
|
|
56
|
+
decoratorChain.push((operationMeta) => {
|
|
57
|
+
const compositionOptions = (operationMeta.compositionOptions =
|
|
58
|
+
operationMeta.compositionOptions || {});
|
|
59
|
+
compositionOptions.type = getDataTypeName(args.type);
|
|
60
|
+
});
|
|
61
|
+
decorator.KeyParam = createKeyParamDecorator(decorator, decoratorChain);
|
|
62
|
+
decorator.Filter = createFilterDecorator(decorator, decoratorChain, args.type);
|
|
63
|
+
return decorator;
|
|
64
|
+
};
|