@opra/common 1.8.0 → 1.9.1
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/enum-type.js +2 -2
- 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 +86 -525
- package/cjs/document/http/http-parameter.js +1 -0
- package/cjs/document/index.js +9 -1
- package/cjs/filter/filter-rules.js +2 -1
- package/esm/document/data-type/enum-type.js +2 -2
- 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 +82 -525
- package/esm/document/http/http-parameter.js +1 -0
- package/esm/document/index.js +9 -1
- package/esm/filter/filter-rules.js +2 -1
- package/package.json +1 -1
- package/types/document/data-type/enum-type.d.ts +3 -3
- 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/ast/expressions/comparison-expression.d.ts +9 -0
- package/types/filter/filter-rules.d.ts +2 -1
|
@@ -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;
|
|
@@ -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
|
+
};
|