@opra/sqb 0.13.0 → 0.15.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/cjs/augmentation/document-factory.augmentation.js +112 -0
- package/cjs/augmentation/mapped-type.augmentation.js +14 -0
- package/cjs/augmentation/union-type.augmentation.js +9 -0
- package/cjs/convert-filter.js +3 -2
- package/cjs/index.js +6 -6
- package/cjs/sqb-adapter.js +198 -109
- package/cjs/sqb-collection-resource.js +95 -0
- package/cjs/{base-entity-service.js → sqb-entity-service.js} +57 -43
- package/cjs/sqb-singleton-resource.js +54 -0
- package/esm/augmentation/document-factory.augmentation.d.ts +1 -0
- package/esm/augmentation/document-factory.augmentation.js +110 -0
- package/esm/augmentation/mapped-type.augmentation.d.ts +1 -0
- package/esm/augmentation/mapped-type.augmentation.js +12 -0
- package/esm/augmentation/union-type.augmentation.d.ts +1 -0
- package/esm/augmentation/union-type.augmentation.js +7 -0
- package/esm/convert-filter.js +3 -2
- package/esm/index.d.ts +6 -7
- package/esm/index.js +6 -6
- package/esm/sqb-adapter.d.ts +60 -6
- package/esm/sqb-adapter.js +198 -109
- package/esm/sqb-collection-resource.d.ts +14 -0
- package/esm/sqb-collection-resource.js +91 -0
- package/esm/sqb-entity-service.d.ts +21 -0
- package/esm/{base-entity-service.js → sqb-entity-service.js} +55 -41
- package/esm/sqb-singleton-resource.d.ts +11 -0
- package/esm/sqb-singleton-resource.js +50 -0
- package/package.json +10 -10
- package/cjs/base-entity-resource.js +0 -39
- package/esm/base-entity-resource.d.ts +0 -13
- package/esm/base-entity-resource.js +0 -35
- package/esm/base-entity-service.d.ts +0 -30
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@opra/common");
|
|
4
|
+
const connect_1 = require("@sqb/connect");
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const _extractFieldSchema = common_1.DocumentFactory.prototype.extractFieldSchema;
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
common_1.DocumentFactory.prototype.extractFieldSchema = async function (target, ctor, metadata, name) {
|
|
9
|
+
await _extractFieldSchema.call(this, target, ctor, metadata, name);
|
|
10
|
+
const sqbMeta = connect_1.EntityMetadata.get(ctor);
|
|
11
|
+
const sqbField = sqbMeta && connect_1.EntityMetadata.getField(sqbMeta, name);
|
|
12
|
+
if (!sqbField)
|
|
13
|
+
return;
|
|
14
|
+
const detectType = !metadata.type;
|
|
15
|
+
if ((0, connect_1.isAssociationField)(sqbField)) {
|
|
16
|
+
if (!sqbField.association.returnsMany())
|
|
17
|
+
delete target.isArray;
|
|
18
|
+
if (!target.type) {
|
|
19
|
+
const trg = await sqbField.association.resolveTarget();
|
|
20
|
+
if (trg) {
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
target.type = await this.importTypeClass(trg.ctor);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (sqbField.kind === 'column') {
|
|
27
|
+
if (sqbField.type && Reflect.hasMetadata(common_1.METADATA_KEY, sqbField.type)) {
|
|
28
|
+
target.type = sqbField.type;
|
|
29
|
+
}
|
|
30
|
+
switch (sqbField.dataType) {
|
|
31
|
+
case connect_1.DataType.GUID:
|
|
32
|
+
if (!target.type || (detectType && target.type === 'string'))
|
|
33
|
+
target.type = 'guid';
|
|
34
|
+
break;
|
|
35
|
+
case connect_1.DataType.JSON:
|
|
36
|
+
if (!target.type || (detectType && target.type === 'any'))
|
|
37
|
+
target.type = 'object';
|
|
38
|
+
break;
|
|
39
|
+
case connect_1.DataType.INTEGER:
|
|
40
|
+
case connect_1.DataType.SMALLINT:
|
|
41
|
+
if (!target.type || (detectType && target.type === 'number'))
|
|
42
|
+
target.type = 'integer';
|
|
43
|
+
break;
|
|
44
|
+
case connect_1.DataType.BIGINT:
|
|
45
|
+
if (!target.type || (detectType && target.type === 'number'))
|
|
46
|
+
target.type = 'bigint';
|
|
47
|
+
break;
|
|
48
|
+
case connect_1.DataType.DATE:
|
|
49
|
+
if (!target.type || (detectType && (target.type === 'timestamp' || target.type === 'string')))
|
|
50
|
+
target.type = 'date';
|
|
51
|
+
break;
|
|
52
|
+
case connect_1.DataType.TIMESTAMPTZ:
|
|
53
|
+
if (!target.type || (detectType && (target.type === 'timestamp' || target.type === 'string')))
|
|
54
|
+
target.type = 'timestamptz';
|
|
55
|
+
break;
|
|
56
|
+
case connect_1.DataType.TIME:
|
|
57
|
+
if (!target.type || (detectType && (target.type === 'timestamp' || target.type === 'string')))
|
|
58
|
+
target.type = 'time';
|
|
59
|
+
break;
|
|
60
|
+
case connect_1.DataType.BINARY:
|
|
61
|
+
if (!target.type || (detectType && target.type === 'string'))
|
|
62
|
+
target.type = 'base64';
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
if (!target.type) {
|
|
66
|
+
switch (sqbField.dataType) {
|
|
67
|
+
case connect_1.DataType.BOOL:
|
|
68
|
+
target.type = 'boolean';
|
|
69
|
+
break;
|
|
70
|
+
case connect_1.DataType.CHAR:
|
|
71
|
+
case connect_1.DataType.VARCHAR:
|
|
72
|
+
case connect_1.DataType.TEXT:
|
|
73
|
+
target.type = 'string';
|
|
74
|
+
break;
|
|
75
|
+
case connect_1.DataType.FLOAT:
|
|
76
|
+
case connect_1.DataType.DOUBLE:
|
|
77
|
+
case connect_1.DataType.NUMBER:
|
|
78
|
+
target.type = 'number';
|
|
79
|
+
break;
|
|
80
|
+
case connect_1.DataType.TIMESTAMP:
|
|
81
|
+
target.type = 'timestamp';
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (sqbField.notNull && target.required === undefined)
|
|
86
|
+
target.required = sqbField.notNull;
|
|
87
|
+
if (sqbField.exclusive && target.exclusive === undefined)
|
|
88
|
+
target.exclusive = sqbField.exclusive;
|
|
89
|
+
if (sqbField.default !== undefined && target.default === undefined)
|
|
90
|
+
target.default = sqbField.default;
|
|
91
|
+
}
|
|
92
|
+
if (sqbField.exclusive && target.exclusive === undefined)
|
|
93
|
+
target.exclusive = sqbField.exclusive;
|
|
94
|
+
};
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
const _createCollection = common_1.DocumentFactory.prototype.createCollection;
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
common_1.DocumentFactory.prototype.createCollection = async function (name, schema) {
|
|
99
|
+
const { document } = this;
|
|
100
|
+
const dataType = document.getComplexType(schema.type);
|
|
101
|
+
// Determine primaryKey if not defined
|
|
102
|
+
if (!schema.primaryKey && dataType.ctor) {
|
|
103
|
+
const entityMetadata = connect_1.EntityMetadata.get(dataType.ctor);
|
|
104
|
+
if (entityMetadata?.indexes) {
|
|
105
|
+
const primaryIndex = entityMetadata.indexes.find(x => x.primary);
|
|
106
|
+
if (primaryIndex) {
|
|
107
|
+
schema.primaryKey = primaryIndex.columns;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return await _createCollection.call(this, name, schema);
|
|
112
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@opra/common");
|
|
4
|
+
const connect_1 = require("@sqb/connect");
|
|
5
|
+
const _applyMixin = common_1.MappedType._applyMixin;
|
|
6
|
+
common_1.MappedType._applyMixin = function (target, source, options) {
|
|
7
|
+
_applyMixin.call(null, target, source, options);
|
|
8
|
+
const srcMeta = connect_1.Entity.getMetadata(source);
|
|
9
|
+
if (srcMeta) {
|
|
10
|
+
const trgMeta = connect_1.EntityMetadata.define(target);
|
|
11
|
+
const { isInheritedPredicate } = options;
|
|
12
|
+
connect_1.EntityMetadata.mixin(trgMeta, srcMeta, k => isInheritedPredicate(k));
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@opra/common");
|
|
4
|
+
const connect_1 = require("@sqb/connect");
|
|
5
|
+
const _applyMixin = common_1.UnionType._applyMixin;
|
|
6
|
+
common_1.UnionType._applyMixin = function (target, ...sources) {
|
|
7
|
+
_applyMixin.call(null, target, ...sources);
|
|
8
|
+
connect_1.Entity.mixin(target, ...sources);
|
|
9
|
+
};
|
package/cjs/convert-filter.js
CHANGED
|
@@ -10,7 +10,8 @@ function convertFilter(str) {
|
|
|
10
10
|
return;
|
|
11
11
|
if (ast instanceof common_1.ComparisonExpression) {
|
|
12
12
|
const left = ast.left instanceof common_1.QualifiedIdentifier
|
|
13
|
-
? ast.left.value
|
|
13
|
+
? sqb.Field(ast.left.value)
|
|
14
|
+
: convertFilter(ast.left);
|
|
14
15
|
const right = convertFilter(ast.right);
|
|
15
16
|
switch (ast.op) {
|
|
16
17
|
case '=':
|
|
@@ -42,7 +43,7 @@ function convertFilter(str) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
if (ast instanceof common_1.QualifiedIdentifier) {
|
|
45
|
-
return
|
|
46
|
+
return ast.value;
|
|
46
47
|
}
|
|
47
48
|
if (ast instanceof common_1.NumberLiteral ||
|
|
48
49
|
ast instanceof common_1.StringLiteral ||
|
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
4
|
+
require("./augmentation/document-factory.augmentation.js");
|
|
5
|
+
require("./augmentation/mapped-type.augmentation.js");
|
|
6
|
+
require("./augmentation/union-type.augmentation.js");
|
|
5
7
|
tslib_1.__exportStar(require("./sqb-adapter.js"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./
|
|
7
|
-
tslib_1.__exportStar(require("./
|
|
8
|
-
|
|
9
|
-
globalThis[optionalsSymbol] = globalThis[optionalsSymbol] || {};
|
|
10
|
-
globalThis[optionalsSymbol].SqbConnect = _SqbConnect;
|
|
8
|
+
tslib_1.__exportStar(require("./sqb-collection-resource.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./sqb-entity-service.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./sqb-singleton-resource.js"), exports);
|
package/cjs/sqb-adapter.js
CHANGED
|
@@ -7,117 +7,206 @@ const lodash_omitby_1 = tslib_1.__importDefault(require("lodash.omitby"));
|
|
|
7
7
|
const convert_filter_js_1 = require("./convert-filter.js");
|
|
8
8
|
var SQBAdapter;
|
|
9
9
|
(function (SQBAdapter) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
10
|
+
SQBAdapter.parseFilter = convert_filter_js_1.convertFilter;
|
|
11
|
+
function parseCollectionCreateRequest(request) {
|
|
12
|
+
/* istanbul ignore next */
|
|
13
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'create'))
|
|
14
|
+
throw new TypeError('"Request" is not a "CollectionCreateRequest"');
|
|
15
|
+
const { args } = request;
|
|
16
|
+
return {
|
|
17
|
+
method: 'create',
|
|
18
|
+
data: args.data,
|
|
19
|
+
options: (0, lodash_omitby_1.default)({
|
|
20
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
21
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
22
|
+
include: args.include?.length ? args.include : undefined,
|
|
23
|
+
}, lodash_isnil_1.default)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
SQBAdapter.parseCollectionCreateRequest = parseCollectionCreateRequest;
|
|
27
|
+
function parseCollectionDeleteRequest(request) {
|
|
28
|
+
/* istanbul ignore next */
|
|
29
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'delete'))
|
|
30
|
+
throw new TypeError('"Request" is not a "CollectionDeleteRequest"');
|
|
31
|
+
const { args } = request;
|
|
32
|
+
return {
|
|
33
|
+
method: 'destroy',
|
|
34
|
+
key: args.key,
|
|
35
|
+
options: {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
SQBAdapter.parseCollectionDeleteRequest = parseCollectionDeleteRequest;
|
|
39
|
+
function parseCollectionDeleteManyRequest(request) {
|
|
40
|
+
/* istanbul ignore next */
|
|
41
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'deleteMany'))
|
|
42
|
+
throw new TypeError('"Request" is not a "CollectionDeleteManyRequest"');
|
|
43
|
+
const { args } = request;
|
|
44
|
+
return {
|
|
45
|
+
method: 'destroyAll',
|
|
46
|
+
options: (0, lodash_omitby_1.default)({
|
|
47
|
+
filter: SQBAdapter.parseFilter(args.filter)
|
|
48
|
+
}, lodash_isnil_1.default)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
SQBAdapter.parseCollectionDeleteManyRequest = parseCollectionDeleteManyRequest;
|
|
52
|
+
function parseCollectionGetRequest(request) {
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'get'))
|
|
55
|
+
throw new TypeError('"Request" is not a "CollectionGetRequest"');
|
|
56
|
+
const { args } = request;
|
|
57
|
+
return {
|
|
58
|
+
method: 'findByPk',
|
|
59
|
+
key: args.key,
|
|
60
|
+
options: (0, lodash_omitby_1.default)({
|
|
61
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
62
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
63
|
+
include: args.include?.length ? args.include : undefined,
|
|
64
|
+
}, lodash_isnil_1.default)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
SQBAdapter.parseCollectionGetRequest = parseCollectionGetRequest;
|
|
68
|
+
function parseCollectionUpdateRequest(request) {
|
|
69
|
+
/* istanbul ignore next */
|
|
70
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'update'))
|
|
71
|
+
throw new TypeError('"Request" is not a "CollectionUpdateRequest"');
|
|
72
|
+
const { args } = request;
|
|
73
|
+
return {
|
|
74
|
+
method: 'update',
|
|
75
|
+
key: args.key,
|
|
76
|
+
data: args.data,
|
|
77
|
+
options: (0, lodash_omitby_1.default)({
|
|
78
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
79
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
80
|
+
include: args.include?.length ? args.include : undefined,
|
|
81
|
+
}, lodash_isnil_1.default)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
SQBAdapter.parseCollectionUpdateRequest = parseCollectionUpdateRequest;
|
|
85
|
+
function parseCollectionUpdateManyRequest(request) {
|
|
86
|
+
/* istanbul ignore next */
|
|
87
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'updateMany'))
|
|
88
|
+
throw new TypeError('"Request" is not a "CollectionUpdateManyRequest"');
|
|
89
|
+
const { args } = request;
|
|
90
|
+
return {
|
|
91
|
+
method: 'updateAll',
|
|
92
|
+
data: args.data,
|
|
93
|
+
options: (0, lodash_omitby_1.default)({
|
|
94
|
+
filter: SQBAdapter.parseFilter(args.filter)
|
|
95
|
+
}, lodash_isnil_1.default)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
SQBAdapter.parseCollectionUpdateManyRequest = parseCollectionUpdateManyRequest;
|
|
99
|
+
function parseCollectionSearchRequest(request) {
|
|
100
|
+
/* istanbul ignore next */
|
|
101
|
+
if (!(request.resourceKind === 'Collection' && request.operation === 'search'))
|
|
102
|
+
throw new TypeError('"Request" is not a "CollectionSearchRequest"');
|
|
103
|
+
const { args } = request;
|
|
104
|
+
return {
|
|
105
|
+
method: 'findAll',
|
|
106
|
+
options: (0, lodash_omitby_1.default)({
|
|
107
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
108
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
109
|
+
include: args.include?.length ? args.include : undefined,
|
|
110
|
+
sort: args.sort?.length ? args.sort : undefined,
|
|
111
|
+
limit: args.limit,
|
|
112
|
+
offset: args.skip,
|
|
113
|
+
distinct: args.distinct,
|
|
114
|
+
count: args.count,
|
|
115
|
+
filter: SQBAdapter.parseFilter(args.filter)
|
|
116
|
+
}, lodash_isnil_1.default)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
SQBAdapter.parseCollectionSearchRequest = parseCollectionSearchRequest;
|
|
120
|
+
function parseSingletonGetRequest(request) {
|
|
121
|
+
/* istanbul ignore next */
|
|
122
|
+
if (!(request.resourceKind === 'Singleton' && request.operation === 'get'))
|
|
123
|
+
throw new TypeError('"Request" is not a "SingletonGetRequest"');
|
|
124
|
+
const { args } = request;
|
|
125
|
+
return {
|
|
126
|
+
method: 'findOne',
|
|
127
|
+
options: (0, lodash_omitby_1.default)({
|
|
128
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
129
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
130
|
+
include: args.include?.length ? args.include : undefined,
|
|
131
|
+
}, lodash_isnil_1.default)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
SQBAdapter.parseSingletonGetRequest = parseSingletonGetRequest;
|
|
135
|
+
function parseSingletonCreateRequest(request) {
|
|
136
|
+
/* istanbul ignore next */
|
|
137
|
+
if (!(request.resourceKind === 'Singleton' && request.operation === 'create'))
|
|
138
|
+
throw new TypeError('"Request" is not a "SingletonCreateRequest"');
|
|
139
|
+
const { args } = request;
|
|
140
|
+
return {
|
|
141
|
+
method: 'create',
|
|
142
|
+
data: args.data,
|
|
143
|
+
options: (0, lodash_omitby_1.default)({
|
|
144
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
145
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
146
|
+
include: args.include?.length ? args.include : undefined,
|
|
147
|
+
}, lodash_isnil_1.default)
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
SQBAdapter.parseSingletonCreateRequest = parseSingletonCreateRequest;
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
152
|
+
function parseSingletonDeleteRequest(request) {
|
|
153
|
+
/* istanbul ignore next */
|
|
154
|
+
if (!(request.resourceKind === 'Singleton' && request.operation === 'delete'))
|
|
155
|
+
throw new TypeError('"Request" is not a "SingletonDeleteRequest"');
|
|
156
|
+
return {
|
|
157
|
+
method: 'destroyAll',
|
|
158
|
+
options: {},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
SQBAdapter.parseSingletonDeleteRequest = parseSingletonDeleteRequest;
|
|
162
|
+
function parseSingletonUpdateRequest(request) {
|
|
163
|
+
/* istanbul ignore next */
|
|
164
|
+
if (!(request.resourceKind === 'Singleton' && request.operation === 'update'))
|
|
165
|
+
throw new TypeError('"Request" is not a "SingletonUpdateRequest"');
|
|
166
|
+
const { args } = request;
|
|
167
|
+
return {
|
|
168
|
+
method: 'updateAll',
|
|
169
|
+
data: args.data,
|
|
170
|
+
options: (0, lodash_omitby_1.default)({
|
|
171
|
+
pick: args.pick?.length ? args.pick : undefined,
|
|
172
|
+
omit: args.omit?.length ? args.omit : undefined,
|
|
173
|
+
include: args.include?.length ? args.include : undefined,
|
|
174
|
+
}, lodash_isnil_1.default)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
SQBAdapter.parseSingletonUpdateRequest = parseSingletonUpdateRequest;
|
|
178
|
+
function parseRequest(request) {
|
|
179
|
+
if (request.resourceKind === 'Collection') {
|
|
180
|
+
switch (request.operation) {
|
|
181
|
+
case 'create':
|
|
182
|
+
return parseCollectionCreateRequest(request);
|
|
183
|
+
case 'get':
|
|
184
|
+
return parseCollectionGetRequest(request);
|
|
185
|
+
case 'delete':
|
|
186
|
+
return parseCollectionDeleteRequest(request);
|
|
187
|
+
case 'deleteMany':
|
|
188
|
+
return parseCollectionDeleteManyRequest(request);
|
|
189
|
+
case 'update':
|
|
190
|
+
return parseCollectionUpdateRequest(request);
|
|
191
|
+
case 'updateMany':
|
|
192
|
+
return parseCollectionUpdateManyRequest(request);
|
|
193
|
+
case 'search':
|
|
194
|
+
return parseCollectionSearchRequest(request);
|
|
108
195
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
196
|
+
}
|
|
197
|
+
else if (request.resourceKind === 'Singleton') {
|
|
198
|
+
switch (request.operation) {
|
|
199
|
+
case 'create':
|
|
200
|
+
return parseSingletonCreateRequest(request);
|
|
201
|
+
case 'delete':
|
|
202
|
+
return parseSingletonDeleteRequest(request);
|
|
203
|
+
case 'get':
|
|
204
|
+
return parseSingletonGetRequest(request);
|
|
205
|
+
case 'update':
|
|
206
|
+
return parseSingletonUpdateRequest(request);
|
|
118
207
|
}
|
|
119
208
|
}
|
|
120
|
-
throw new Error(`Unimplemented
|
|
209
|
+
throw new Error(`Unimplemented request method "${request.method}"`);
|
|
121
210
|
}
|
|
122
|
-
SQBAdapter.
|
|
211
|
+
SQBAdapter.parseRequest = parseRequest;
|
|
123
212
|
})(SQBAdapter = exports.SQBAdapter || (exports.SQBAdapter = {}));
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SqbCollectionResource = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@opra/common");
|
|
6
|
+
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
7
|
+
class SqbCollectionResource {
|
|
8
|
+
async create(ctx) {
|
|
9
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionCreateRequest(ctx.request);
|
|
10
|
+
const service = await this.getService(ctx);
|
|
11
|
+
return service.create(ctx, prepared.data, prepared.options);
|
|
12
|
+
}
|
|
13
|
+
async delete(ctx) {
|
|
14
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionDeleteRequest(ctx.request);
|
|
15
|
+
const service = await this.getService(ctx);
|
|
16
|
+
return service.destroy(ctx, prepared.key, prepared.options);
|
|
17
|
+
}
|
|
18
|
+
async deleteMany(ctx) {
|
|
19
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionDeleteManyRequest(ctx.request);
|
|
20
|
+
const service = await this.getService(ctx);
|
|
21
|
+
return service.destroyAll(ctx, prepared.options);
|
|
22
|
+
}
|
|
23
|
+
async get(ctx) {
|
|
24
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionGetRequest(ctx.request);
|
|
25
|
+
const service = await this.getService(ctx);
|
|
26
|
+
return service.findByPk(ctx, prepared.key, prepared.options);
|
|
27
|
+
}
|
|
28
|
+
async update(ctx) {
|
|
29
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionUpdateRequest(ctx.request);
|
|
30
|
+
const service = await this.getService(ctx);
|
|
31
|
+
return service.update(ctx, prepared.key, prepared.data, prepared.options);
|
|
32
|
+
}
|
|
33
|
+
async updateMany(ctx) {
|
|
34
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionUpdateManyRequest(ctx.request);
|
|
35
|
+
const service = await this.getService(ctx);
|
|
36
|
+
return service.updateAll(ctx, prepared.data, prepared.options);
|
|
37
|
+
}
|
|
38
|
+
async search(ctx) {
|
|
39
|
+
const prepared = sqb_adapter_js_1.SQBAdapter.parseCollectionSearchRequest(ctx.request);
|
|
40
|
+
const service = await this.getService(ctx);
|
|
41
|
+
if (prepared.options.count) {
|
|
42
|
+
const [items, count] = await Promise.all([
|
|
43
|
+
service.findAll(prepared.options),
|
|
44
|
+
service.count(prepared.options)
|
|
45
|
+
]);
|
|
46
|
+
ctx.response.count = count;
|
|
47
|
+
return items;
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
return service.findAll(ctx, prepared.options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
tslib_1.__decorate([
|
|
54
|
+
common_1.Collection.CreateOperation(),
|
|
55
|
+
tslib_1.__metadata("design:type", Function),
|
|
56
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
57
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
58
|
+
], SqbCollectionResource.prototype, "create", null);
|
|
59
|
+
tslib_1.__decorate([
|
|
60
|
+
common_1.Collection.DeleteOperation(),
|
|
61
|
+
tslib_1.__metadata("design:type", Function),
|
|
62
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
63
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
64
|
+
], SqbCollectionResource.prototype, "delete", null);
|
|
65
|
+
tslib_1.__decorate([
|
|
66
|
+
common_1.Collection.DeleteManyOperation(),
|
|
67
|
+
tslib_1.__metadata("design:type", Function),
|
|
68
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
69
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
70
|
+
], SqbCollectionResource.prototype, "deleteMany", null);
|
|
71
|
+
tslib_1.__decorate([
|
|
72
|
+
common_1.Collection.GetOperation(),
|
|
73
|
+
tslib_1.__metadata("design:type", Function),
|
|
74
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
75
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
76
|
+
], SqbCollectionResource.prototype, "get", null);
|
|
77
|
+
tslib_1.__decorate([
|
|
78
|
+
common_1.Collection.UpdateOperation(),
|
|
79
|
+
tslib_1.__metadata("design:type", Function),
|
|
80
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
81
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
82
|
+
], SqbCollectionResource.prototype, "update", null);
|
|
83
|
+
tslib_1.__decorate([
|
|
84
|
+
common_1.Collection.UpdateManyOperation(),
|
|
85
|
+
tslib_1.__metadata("design:type", Function),
|
|
86
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
87
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
88
|
+
], SqbCollectionResource.prototype, "updateMany", null);
|
|
89
|
+
tslib_1.__decorate([
|
|
90
|
+
common_1.Collection.SearchOperation(),
|
|
91
|
+
tslib_1.__metadata("design:type", Function),
|
|
92
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
93
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
94
|
+
], SqbCollectionResource.prototype, "search", null);
|
|
95
|
+
exports.SqbCollectionResource = SqbCollectionResource;
|