@opra/sqb 1.4.3 → 1.4.4
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/datatype-factory.augmentation.js +11 -3
- package/cjs/sqb-adapter.js +41 -12
- package/cjs/sqb-collection-service.js +48 -12
- package/cjs/sqb-entity-service.js +89 -31
- package/cjs/sqb-singleton-service.js +20 -5
- package/esm/augmentation/datatype-factory.augmentation.js +13 -5
- package/esm/sqb-adapter.js +41 -12
- package/esm/sqb-collection-service.js +48 -12
- package/esm/sqb-entity-service.js +89 -31
- package/esm/sqb-singleton-service.js +20 -5
- package/package.json +3 -3
|
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const common_1 = require("@opra/common");
|
|
4
4
|
const connect_1 = require("@sqb/connect");
|
|
5
5
|
var DataTypeFactory = common_1.classes.DataTypeFactory;
|
|
6
|
-
const _prepareComplexTypeArgs = DataTypeFactory
|
|
6
|
+
const _prepareComplexTypeArgs = DataTypeFactory
|
|
7
|
+
._prepareComplexTypeArgs;
|
|
7
8
|
DataTypeFactory._prepareComplexTypeArgs = async function (context, owner, initArgs, metadata) {
|
|
8
9
|
let sqbMeta;
|
|
9
|
-
if (initArgs.ctor &&
|
|
10
|
+
if (initArgs.ctor &&
|
|
11
|
+
metadata.fields &&
|
|
12
|
+
(sqbMeta = connect_1.EntityMetadata.get(initArgs.ctor))) {
|
|
10
13
|
metadata = (0, common_1.cloneObject)(metadata);
|
|
11
14
|
for (const [fieldName, fieldSchema] of Object.entries(metadata.fields)) {
|
|
12
15
|
const sqbField = sqbMeta && connect_1.EntityMetadata.getField(sqbMeta, fieldName);
|
|
@@ -75,5 +78,10 @@ DataTypeFactory._prepareComplexTypeArgs = async function (context, owner, initAr
|
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
return _prepareComplexTypeArgs.apply(DataTypeFactory, [
|
|
81
|
+
return _prepareComplexTypeArgs.apply(DataTypeFactory, [
|
|
82
|
+
context,
|
|
83
|
+
owner,
|
|
84
|
+
initArgs,
|
|
85
|
+
metadata,
|
|
86
|
+
]);
|
|
79
87
|
};
|
package/cjs/sqb-adapter.js
CHANGED
|
@@ -13,7 +13,8 @@ var SQBAdapter;
|
|
|
13
13
|
}
|
|
14
14
|
const ctx = context;
|
|
15
15
|
const { operation } = ctx;
|
|
16
|
-
if (operation?.composition?.startsWith('Entity.') &&
|
|
16
|
+
if (operation?.composition?.startsWith('Entity.') &&
|
|
17
|
+
operation.compositionOptions?.type) {
|
|
17
18
|
const dataType = ctx.document.node.getComplexType(operation.compositionOptions?.type);
|
|
18
19
|
const entityMetadata = connect_1.EntityMetadata.get(dataType.ctor);
|
|
19
20
|
if (!entityMetadata)
|
|
@@ -25,15 +26,24 @@ var SQBAdapter;
|
|
|
25
26
|
const options = {
|
|
26
27
|
projection: ctx.queryParams.projection,
|
|
27
28
|
};
|
|
28
|
-
return {
|
|
29
|
+
return {
|
|
30
|
+
method: 'create',
|
|
31
|
+
data,
|
|
32
|
+
options,
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
35
|
case 'Entity.Delete': {
|
|
31
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
36
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
37
|
+
controller.parameters.find(p => p.keyParam);
|
|
32
38
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
33
39
|
const options = {
|
|
34
40
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
35
41
|
};
|
|
36
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
method: 'delete',
|
|
44
|
+
key,
|
|
45
|
+
options,
|
|
46
|
+
};
|
|
37
47
|
}
|
|
38
48
|
case 'Entity.DeleteMany': {
|
|
39
49
|
const options = {
|
|
@@ -45,15 +55,18 @@ var SQBAdapter;
|
|
|
45
55
|
const options = {
|
|
46
56
|
count: ctx.queryParams.count,
|
|
47
57
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
48
|
-
projection: ctx.queryParams.projection ||
|
|
49
|
-
|
|
58
|
+
projection: ctx.queryParams.projection ||
|
|
59
|
+
operation.compositionOptions.defaultProjection,
|
|
60
|
+
limit: ctx.queryParams.limit ||
|
|
61
|
+
operation.compositionOptions.defaultLimit,
|
|
50
62
|
skip: ctx.queryParams.skip,
|
|
51
63
|
sort: ctx.queryParams.sort || operation.compositionOptions.defaultSort,
|
|
52
64
|
};
|
|
53
65
|
return { method: 'findMany', options };
|
|
54
66
|
}
|
|
55
67
|
case 'Entity.Get': {
|
|
56
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
68
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
69
|
+
controller.parameters.find(p => p.keyParam);
|
|
57
70
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
58
71
|
const options = {
|
|
59
72
|
projection: ctx.queryParams.projection,
|
|
@@ -63,30 +76,46 @@ var SQBAdapter;
|
|
|
63
76
|
}
|
|
64
77
|
case 'Entity.Replace': {
|
|
65
78
|
const data = await ctx.getBody();
|
|
66
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
79
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
80
|
+
controller.parameters.find(p => p.keyParam);
|
|
67
81
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
68
82
|
const options = {
|
|
69
83
|
projection: ctx.queryParams.projection,
|
|
70
84
|
filter: ctx.queryParams.filter,
|
|
71
85
|
};
|
|
72
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
method: 'replace',
|
|
88
|
+
key,
|
|
89
|
+
data,
|
|
90
|
+
options,
|
|
91
|
+
};
|
|
73
92
|
}
|
|
74
93
|
case 'Entity.Update': {
|
|
75
94
|
const data = await ctx.getBody();
|
|
76
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
95
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
96
|
+
controller.parameters.find(p => p.keyParam);
|
|
77
97
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
78
98
|
const options = {
|
|
79
99
|
projection: ctx.queryParams.projection,
|
|
80
100
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
81
101
|
};
|
|
82
|
-
return {
|
|
102
|
+
return {
|
|
103
|
+
method: 'update',
|
|
104
|
+
key,
|
|
105
|
+
data,
|
|
106
|
+
options,
|
|
107
|
+
};
|
|
83
108
|
}
|
|
84
109
|
case 'Entity.UpdateMany': {
|
|
85
110
|
const data = await ctx.getBody();
|
|
86
111
|
const options = {
|
|
87
112
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
88
113
|
};
|
|
89
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
method: 'updateMany',
|
|
116
|
+
data,
|
|
117
|
+
options,
|
|
118
|
+
};
|
|
90
119
|
}
|
|
91
120
|
default:
|
|
92
121
|
break;
|
|
@@ -75,7 +75,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
75
75
|
options,
|
|
76
76
|
};
|
|
77
77
|
return this._executeCommand(command, async () => {
|
|
78
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
78
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
79
|
+
await this._getCommonFilter(command),
|
|
80
|
+
command.options?.filter,
|
|
81
|
+
]);
|
|
79
82
|
command.options = { ...command.options, filter };
|
|
80
83
|
return this._count(command);
|
|
81
84
|
});
|
|
@@ -96,7 +99,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
96
99
|
options,
|
|
97
100
|
};
|
|
98
101
|
return this._executeCommand(command, async () => {
|
|
99
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
102
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
103
|
+
await this._getCommonFilter(command),
|
|
104
|
+
command.options?.filter,
|
|
105
|
+
]);
|
|
100
106
|
command.options = { ...command.options, filter };
|
|
101
107
|
return this._delete(command);
|
|
102
108
|
});
|
|
@@ -115,7 +121,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
115
121
|
options,
|
|
116
122
|
};
|
|
117
123
|
return this._executeCommand(command, async () => {
|
|
118
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
124
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
125
|
+
await this._getCommonFilter(command),
|
|
126
|
+
command.options?.filter,
|
|
127
|
+
]);
|
|
119
128
|
command.options = { ...command.options, filter };
|
|
120
129
|
return this._deleteMany(command);
|
|
121
130
|
});
|
|
@@ -136,7 +145,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
136
145
|
options,
|
|
137
146
|
};
|
|
138
147
|
return this._executeCommand(command, async () => {
|
|
139
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
148
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
149
|
+
await this._getCommonFilter(command),
|
|
150
|
+
command.options?.filter,
|
|
151
|
+
]);
|
|
140
152
|
command.options = { ...command.options, filter };
|
|
141
153
|
return this._exists(command);
|
|
142
154
|
});
|
|
@@ -155,7 +167,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
155
167
|
options,
|
|
156
168
|
};
|
|
157
169
|
return this._executeCommand(command, async () => {
|
|
158
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
170
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
171
|
+
await this._getCommonFilter(command),
|
|
172
|
+
command.options?.filter,
|
|
173
|
+
]);
|
|
159
174
|
command.options = { ...command.options, filter };
|
|
160
175
|
return this._existsOne(command);
|
|
161
176
|
});
|
|
@@ -177,7 +192,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
177
192
|
};
|
|
178
193
|
return this._executeCommand(command, async () => {
|
|
179
194
|
const documentFilter = await this._getCommonFilter(command);
|
|
180
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
195
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
196
|
+
documentFilter,
|
|
197
|
+
command.options?.filter,
|
|
198
|
+
]);
|
|
181
199
|
command.options = { ...command.options, filter };
|
|
182
200
|
return this._findById(command);
|
|
183
201
|
});
|
|
@@ -196,7 +214,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
196
214
|
options,
|
|
197
215
|
};
|
|
198
216
|
return this._executeCommand(command, async () => {
|
|
199
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
217
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
218
|
+
await this._getCommonFilter(command),
|
|
219
|
+
command.options?.filter,
|
|
220
|
+
]);
|
|
200
221
|
command.options = { ...command.options, filter };
|
|
201
222
|
return this._findOne(command);
|
|
202
223
|
});
|
|
@@ -215,7 +236,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
215
236
|
options,
|
|
216
237
|
};
|
|
217
238
|
return this._executeCommand(command, async () => {
|
|
218
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
239
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
240
|
+
await this._getCommonFilter(command),
|
|
241
|
+
command.options?.filter,
|
|
242
|
+
]);
|
|
219
243
|
const limit = command.options?.limit || this.defaultLimit;
|
|
220
244
|
command.options = { ...command.options, filter, limit };
|
|
221
245
|
return this._findMany(command);
|
|
@@ -229,7 +253,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
229
253
|
* @return A Promise that resolves to an array of partial outputs of type T and total count.
|
|
230
254
|
*/
|
|
231
255
|
async findManyWithCount(options) {
|
|
232
|
-
const [items, count] = await Promise.all([
|
|
256
|
+
const [items, count] = await Promise.all([
|
|
257
|
+
this.findMany(options),
|
|
258
|
+
this.count(options),
|
|
259
|
+
]);
|
|
233
260
|
return { count, items };
|
|
234
261
|
}
|
|
235
262
|
/**
|
|
@@ -266,7 +293,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
266
293
|
options,
|
|
267
294
|
};
|
|
268
295
|
return this._executeCommand(command, async () => {
|
|
269
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
296
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
297
|
+
await this._getCommonFilter(command),
|
|
298
|
+
command.options?.filter,
|
|
299
|
+
]);
|
|
270
300
|
command.options = { ...command.options, filter };
|
|
271
301
|
return this._update(command);
|
|
272
302
|
});
|
|
@@ -289,7 +319,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
289
319
|
options,
|
|
290
320
|
};
|
|
291
321
|
return this._executeCommand(command, async () => {
|
|
292
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
322
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
323
|
+
await this._getCommonFilter(command),
|
|
324
|
+
command.options?.filter,
|
|
325
|
+
]);
|
|
293
326
|
command.options = { ...command.options, filter };
|
|
294
327
|
return this._updateOnly(command);
|
|
295
328
|
});
|
|
@@ -310,7 +343,10 @@ class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
310
343
|
options,
|
|
311
344
|
};
|
|
312
345
|
return this._executeCommand(command, async () => {
|
|
313
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
346
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
347
|
+
await this._getCommonFilter(command),
|
|
348
|
+
command.options?.filter,
|
|
349
|
+
]);
|
|
314
350
|
command.options = { ...command.options, filter };
|
|
315
351
|
return this._updateMany(command);
|
|
316
352
|
});
|
|
@@ -66,10 +66,12 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
66
66
|
for(context, overwriteProperties, overwriteContext) {
|
|
67
67
|
if (overwriteProperties?.commonFilter && this.commonFilter) {
|
|
68
68
|
overwriteProperties.commonFilter = [
|
|
69
|
-
...(Array.isArray(this.commonFilter)
|
|
69
|
+
...(Array.isArray(this.commonFilter)
|
|
70
|
+
? this.commonFilter
|
|
71
|
+
: [this.commonFilter]),
|
|
70
72
|
...(Array.isArray(overwriteProperties?.commonFilter)
|
|
71
|
-
? overwriteProperties
|
|
72
|
-
: [overwriteProperties
|
|
73
|
+
? overwriteProperties.commonFilter
|
|
74
|
+
: [overwriteProperties.commonFilter]),
|
|
73
75
|
];
|
|
74
76
|
}
|
|
75
77
|
return super.for(context, overwriteProperties, overwriteContext);
|
|
@@ -81,7 +83,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
81
83
|
* @throws {Error} If the collection name is not defined.
|
|
82
84
|
*/
|
|
83
85
|
getResourceName() {
|
|
84
|
-
const out = typeof this.resourceName === 'function'
|
|
86
|
+
const out = typeof this.resourceName === 'function'
|
|
87
|
+
? this.resourceName(this)
|
|
88
|
+
: this.resourceName || this.dataType.name;
|
|
85
89
|
if (out)
|
|
86
90
|
return out;
|
|
87
91
|
throw new Error('resourceName is not defined');
|
|
@@ -110,7 +114,10 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
110
114
|
let validator = this._outputCodecs[operation];
|
|
111
115
|
if (validator)
|
|
112
116
|
return validator;
|
|
113
|
-
const options = {
|
|
117
|
+
const options = {
|
|
118
|
+
projection: '*',
|
|
119
|
+
partial: 'deep',
|
|
120
|
+
};
|
|
114
121
|
const dataType = this.dataType;
|
|
115
122
|
validator = dataType.generateCodec('decode', options);
|
|
116
123
|
this._outputCodecs[operation] = validator;
|
|
@@ -160,7 +167,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
160
167
|
* @protected
|
|
161
168
|
*/
|
|
162
169
|
async _count(command) {
|
|
163
|
-
const filter = command.options?.filter
|
|
170
|
+
const filter = command.options?.filter
|
|
171
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
172
|
+
: undefined;
|
|
164
173
|
return this._dbCount({ ...command.options, filter });
|
|
165
174
|
}
|
|
166
175
|
/**
|
|
@@ -172,7 +181,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
172
181
|
*/
|
|
173
182
|
async _delete(command) {
|
|
174
183
|
(0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
|
|
175
|
-
const filter = command.options?.filter
|
|
184
|
+
const filter = command.options?.filter
|
|
185
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
186
|
+
: undefined;
|
|
176
187
|
return this._dbDelete(command.documentId, { ...command.options, filter });
|
|
177
188
|
}
|
|
178
189
|
/**
|
|
@@ -183,7 +194,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
183
194
|
* @protected
|
|
184
195
|
*/
|
|
185
196
|
async _deleteMany(command) {
|
|
186
|
-
const filter = command.options?.filter
|
|
197
|
+
const filter = command.options?.filter
|
|
198
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
199
|
+
: undefined;
|
|
187
200
|
return await this._dbDeleteMany({ ...command.options, filter });
|
|
188
201
|
}
|
|
189
202
|
/**
|
|
@@ -194,8 +207,13 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
194
207
|
*/
|
|
195
208
|
async _exists(command) {
|
|
196
209
|
(0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
|
|
197
|
-
const filter = command.options?.filter
|
|
198
|
-
|
|
210
|
+
const filter = command.options?.filter
|
|
211
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
212
|
+
: undefined;
|
|
213
|
+
return await this._dbExists(command.documentId, {
|
|
214
|
+
...command.options,
|
|
215
|
+
filter,
|
|
216
|
+
});
|
|
199
217
|
}
|
|
200
218
|
/**
|
|
201
219
|
* Checks if a record with the given arguments exists.
|
|
@@ -205,7 +223,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
205
223
|
* @protected
|
|
206
224
|
*/
|
|
207
225
|
async _existsOne(command) {
|
|
208
|
-
const filter = command.options?.filter
|
|
226
|
+
const filter = command.options?.filter
|
|
227
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
228
|
+
: undefined;
|
|
209
229
|
return await this._dbExistsOne({ ...command.options, filter });
|
|
210
230
|
}
|
|
211
231
|
/**
|
|
@@ -218,8 +238,13 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
218
238
|
async _findById(command) {
|
|
219
239
|
(0, valgen_1.isNotNullish)(command.documentId, { label: 'documentId' });
|
|
220
240
|
const decode = this.getOutputCodec('find');
|
|
221
|
-
const filter = command.options?.filter
|
|
222
|
-
|
|
241
|
+
const filter = command.options?.filter
|
|
242
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
243
|
+
: undefined;
|
|
244
|
+
const out = await this._dbFindById(command.documentId, {
|
|
245
|
+
...command.options,
|
|
246
|
+
filter,
|
|
247
|
+
});
|
|
223
248
|
return out ? decode(out) : undefined;
|
|
224
249
|
}
|
|
225
250
|
/**
|
|
@@ -231,7 +256,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
231
256
|
*/
|
|
232
257
|
async _findOne(command) {
|
|
233
258
|
const decode = this.getOutputCodec('find');
|
|
234
|
-
const filter = command.options?.filter
|
|
259
|
+
const filter = command.options?.filter
|
|
260
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
261
|
+
: undefined;
|
|
235
262
|
const out = await this._dbFindOne({ ...command.options, filter });
|
|
236
263
|
return out ? decode(out) : undefined;
|
|
237
264
|
}
|
|
@@ -244,7 +271,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
244
271
|
*/
|
|
245
272
|
async _findMany(command) {
|
|
246
273
|
const decode = this.getOutputCodec('find');
|
|
247
|
-
const filter = command.options?.filter
|
|
274
|
+
const filter = command.options?.filter
|
|
275
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
276
|
+
: undefined;
|
|
248
277
|
const out = await this._dbFindMany({ ...command.options, filter });
|
|
249
278
|
if (out?.length) {
|
|
250
279
|
return out.map(x => decode(x));
|
|
@@ -264,7 +293,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
264
293
|
const { documentId, input, options } = command;
|
|
265
294
|
const inputCodec = this.getInputCodec('update');
|
|
266
295
|
const data = inputCodec(input);
|
|
267
|
-
const filter = command.options?.filter
|
|
296
|
+
const filter = command.options?.filter
|
|
297
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
298
|
+
: undefined;
|
|
268
299
|
const out = await this._dbUpdate(documentId, data, { ...options, filter });
|
|
269
300
|
const outputCodec = this.getOutputCodec('update');
|
|
270
301
|
if (out)
|
|
@@ -283,7 +314,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
283
314
|
const { documentId, input, options } = command;
|
|
284
315
|
const inputCodec = this.getInputCodec('update');
|
|
285
316
|
const data = inputCodec(input);
|
|
286
|
-
const filter = command.options?.filter
|
|
317
|
+
const filter = command.options?.filter
|
|
318
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
319
|
+
: undefined;
|
|
287
320
|
return await this._dbUpdateOnly(documentId, data, { ...options, filter });
|
|
288
321
|
}
|
|
289
322
|
/**
|
|
@@ -297,7 +330,9 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
297
330
|
(0, valgen_1.isNotNullish)(command.input, { label: 'input' });
|
|
298
331
|
const inputCodec = this.getInputCodec('update');
|
|
299
332
|
const data = inputCodec(command.input);
|
|
300
|
-
const filter = command.options?.filter
|
|
333
|
+
const filter = command.options?.filter
|
|
334
|
+
? sqb_adapter_js_1.SQBAdapter.parseFilter(command.options.filter)
|
|
335
|
+
: undefined;
|
|
301
336
|
return await this._dbUpdateMany(data, { ...command.options, filter });
|
|
302
337
|
}
|
|
303
338
|
/**
|
|
@@ -472,8 +507,10 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
472
507
|
* that resolves to the common filter, or undefined if not available.
|
|
473
508
|
*/
|
|
474
509
|
_getCommonFilter(command) {
|
|
475
|
-
const commonFilter = Array.isArray(this.commonFilter)
|
|
476
|
-
|
|
510
|
+
const commonFilter = Array.isArray(this.commonFilter)
|
|
511
|
+
? this.commonFilter
|
|
512
|
+
: [this.commonFilter];
|
|
513
|
+
const mapped = commonFilter.map(f => typeof f === 'function' ? f(command, this) : f);
|
|
477
514
|
return mapped.length > 1 ? builder_1.op.and(...mapped) : mapped[0];
|
|
478
515
|
}
|
|
479
516
|
async _executeCommand(command, commandFn) {
|
|
@@ -481,7 +518,8 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
481
518
|
const next = async () => {
|
|
482
519
|
proto = proto ? Object.getPrototypeOf(proto) : this;
|
|
483
520
|
while (proto) {
|
|
484
|
-
if (proto.interceptor &&
|
|
521
|
+
if (proto.interceptor &&
|
|
522
|
+
Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
|
|
485
523
|
return await proto.interceptor.call(this, next, command, this);
|
|
486
524
|
}
|
|
487
525
|
proto = Object.getPrototypeOf(proto);
|
|
@@ -531,44 +569,64 @@ class SqbEntityService extends sqb_service_base_js_1.SqbServiceBase {
|
|
|
531
569
|
throw e;
|
|
532
570
|
}
|
|
533
571
|
}
|
|
572
|
+
async _beforeCreate(
|
|
534
573
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
535
|
-
|
|
574
|
+
command) {
|
|
536
575
|
// Do nothing
|
|
537
576
|
}
|
|
577
|
+
async _beforeUpdate(
|
|
538
578
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
539
|
-
|
|
579
|
+
command) {
|
|
540
580
|
// Do nothing
|
|
541
581
|
}
|
|
582
|
+
async _beforeUpdateMany(
|
|
542
583
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
543
|
-
|
|
584
|
+
command) {
|
|
544
585
|
// Do nothing
|
|
545
586
|
}
|
|
587
|
+
async _beforeDelete(
|
|
546
588
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
547
|
-
|
|
589
|
+
command) {
|
|
548
590
|
// Do nothing
|
|
549
591
|
}
|
|
592
|
+
async _beforeDeleteMany(
|
|
550
593
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
551
|
-
|
|
594
|
+
command) {
|
|
552
595
|
// Do nothing
|
|
553
596
|
}
|
|
597
|
+
async _afterCreate(
|
|
598
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
599
|
+
command,
|
|
554
600
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
555
|
-
|
|
601
|
+
result) {
|
|
556
602
|
// Do nothing
|
|
557
603
|
}
|
|
604
|
+
async _afterUpdate(
|
|
605
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
606
|
+
command,
|
|
558
607
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
559
|
-
|
|
608
|
+
result) {
|
|
560
609
|
// Do nothing
|
|
561
610
|
}
|
|
611
|
+
async _afterUpdateMany(
|
|
562
612
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
563
|
-
|
|
613
|
+
command,
|
|
614
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
615
|
+
affected) {
|
|
564
616
|
// Do nothing
|
|
565
617
|
}
|
|
618
|
+
async _afterDelete(
|
|
619
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
620
|
+
command,
|
|
566
621
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
567
|
-
|
|
622
|
+
affected) {
|
|
568
623
|
// Do nothing
|
|
569
624
|
}
|
|
625
|
+
async _afterDeleteMany(
|
|
626
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
627
|
+
command,
|
|
570
628
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
571
|
-
|
|
629
|
+
affected) {
|
|
572
630
|
// Do nothing
|
|
573
631
|
}
|
|
574
632
|
}
|
|
@@ -71,7 +71,10 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
71
71
|
options,
|
|
72
72
|
};
|
|
73
73
|
return this._executeCommand(command, async () => {
|
|
74
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
74
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
75
|
+
await this._getCommonFilter(command),
|
|
76
|
+
command.options?.filter,
|
|
77
|
+
]);
|
|
75
78
|
command.options = { ...command.options, filter };
|
|
76
79
|
return this._delete(command);
|
|
77
80
|
});
|
|
@@ -91,7 +94,10 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
91
94
|
options,
|
|
92
95
|
};
|
|
93
96
|
return this._executeCommand(command, async () => {
|
|
94
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
97
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
98
|
+
await this._getCommonFilter(command),
|
|
99
|
+
command.options?.filter,
|
|
100
|
+
]);
|
|
95
101
|
command.options = { ...command.options, filter };
|
|
96
102
|
return this._exists(command);
|
|
97
103
|
});
|
|
@@ -105,7 +111,10 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
105
111
|
options,
|
|
106
112
|
};
|
|
107
113
|
return this._executeCommand(command, async () => {
|
|
108
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
114
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
115
|
+
await this._getCommonFilter(command),
|
|
116
|
+
command.options?.filter,
|
|
117
|
+
]);
|
|
109
118
|
command.options = { ...command.options, filter };
|
|
110
119
|
return this._findById(command);
|
|
111
120
|
});
|
|
@@ -126,7 +135,10 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
126
135
|
options,
|
|
127
136
|
};
|
|
128
137
|
return this._executeCommand(command, async () => {
|
|
129
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
138
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
139
|
+
await this._getCommonFilter(command),
|
|
140
|
+
command.options?.filter,
|
|
141
|
+
]);
|
|
130
142
|
command.options = { ...command.options, filter };
|
|
131
143
|
return this._update(command);
|
|
132
144
|
});
|
|
@@ -148,7 +160,10 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
148
160
|
options,
|
|
149
161
|
};
|
|
150
162
|
return this._executeCommand(command, async () => {
|
|
151
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
163
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
|
|
164
|
+
await this._getCommonFilter(command),
|
|
165
|
+
command.options?.filter,
|
|
166
|
+
]);
|
|
152
167
|
command.options = { ...command.options, filter };
|
|
153
168
|
return this._updateOnly(command);
|
|
154
169
|
});
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { classes, cloneObject } from '@opra/common';
|
|
2
|
-
import { DataType as SqbDataType, EntityMetadata, isAssociationField, isColumnField } from '@sqb/connect';
|
|
1
|
+
import { classes, cloneObject, } from '@opra/common';
|
|
2
|
+
import { DataType as SqbDataType, EntityMetadata, isAssociationField, isColumnField, } from '@sqb/connect';
|
|
3
3
|
var DataTypeFactory = classes.DataTypeFactory;
|
|
4
|
-
const _prepareComplexTypeArgs = DataTypeFactory
|
|
4
|
+
const _prepareComplexTypeArgs = DataTypeFactory
|
|
5
|
+
._prepareComplexTypeArgs;
|
|
5
6
|
DataTypeFactory._prepareComplexTypeArgs = async function (context, owner, initArgs, metadata) {
|
|
6
7
|
let sqbMeta;
|
|
7
|
-
if (initArgs.ctor &&
|
|
8
|
+
if (initArgs.ctor &&
|
|
9
|
+
metadata.fields &&
|
|
10
|
+
(sqbMeta = EntityMetadata.get(initArgs.ctor))) {
|
|
8
11
|
metadata = cloneObject(metadata);
|
|
9
12
|
for (const [fieldName, fieldSchema] of Object.entries(metadata.fields)) {
|
|
10
13
|
const sqbField = sqbMeta && EntityMetadata.getField(sqbMeta, fieldName);
|
|
@@ -73,5 +76,10 @@ DataTypeFactory._prepareComplexTypeArgs = async function (context, owner, initAr
|
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
return _prepareComplexTypeArgs.apply(DataTypeFactory, [
|
|
79
|
+
return _prepareComplexTypeArgs.apply(DataTypeFactory, [
|
|
80
|
+
context,
|
|
81
|
+
owner,
|
|
82
|
+
initArgs,
|
|
83
|
+
metadata,
|
|
84
|
+
]);
|
|
77
85
|
};
|
package/esm/sqb-adapter.js
CHANGED
|
@@ -9,7 +9,8 @@ export var SQBAdapter;
|
|
|
9
9
|
}
|
|
10
10
|
const ctx = context;
|
|
11
11
|
const { operation } = ctx;
|
|
12
|
-
if (operation?.composition?.startsWith('Entity.') &&
|
|
12
|
+
if (operation?.composition?.startsWith('Entity.') &&
|
|
13
|
+
operation.compositionOptions?.type) {
|
|
13
14
|
const dataType = ctx.document.node.getComplexType(operation.compositionOptions?.type);
|
|
14
15
|
const entityMetadata = EntityMetadata.get(dataType.ctor);
|
|
15
16
|
if (!entityMetadata)
|
|
@@ -21,15 +22,24 @@ export var SQBAdapter;
|
|
|
21
22
|
const options = {
|
|
22
23
|
projection: ctx.queryParams.projection,
|
|
23
24
|
};
|
|
24
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
method: 'create',
|
|
27
|
+
data,
|
|
28
|
+
options,
|
|
29
|
+
};
|
|
25
30
|
}
|
|
26
31
|
case 'Entity.Delete': {
|
|
27
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
32
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
33
|
+
controller.parameters.find(p => p.keyParam);
|
|
28
34
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
29
35
|
const options = {
|
|
30
36
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
31
37
|
};
|
|
32
|
-
return {
|
|
38
|
+
return {
|
|
39
|
+
method: 'delete',
|
|
40
|
+
key,
|
|
41
|
+
options,
|
|
42
|
+
};
|
|
33
43
|
}
|
|
34
44
|
case 'Entity.DeleteMany': {
|
|
35
45
|
const options = {
|
|
@@ -41,15 +51,18 @@ export var SQBAdapter;
|
|
|
41
51
|
const options = {
|
|
42
52
|
count: ctx.queryParams.count,
|
|
43
53
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
44
|
-
projection: ctx.queryParams.projection ||
|
|
45
|
-
|
|
54
|
+
projection: ctx.queryParams.projection ||
|
|
55
|
+
operation.compositionOptions.defaultProjection,
|
|
56
|
+
limit: ctx.queryParams.limit ||
|
|
57
|
+
operation.compositionOptions.defaultLimit,
|
|
46
58
|
skip: ctx.queryParams.skip,
|
|
47
59
|
sort: ctx.queryParams.sort || operation.compositionOptions.defaultSort,
|
|
48
60
|
};
|
|
49
61
|
return { method: 'findMany', options };
|
|
50
62
|
}
|
|
51
63
|
case 'Entity.Get': {
|
|
52
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
64
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
65
|
+
controller.parameters.find(p => p.keyParam);
|
|
53
66
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
54
67
|
const options = {
|
|
55
68
|
projection: ctx.queryParams.projection,
|
|
@@ -59,30 +72,46 @@ export var SQBAdapter;
|
|
|
59
72
|
}
|
|
60
73
|
case 'Entity.Replace': {
|
|
61
74
|
const data = await ctx.getBody();
|
|
62
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
75
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
76
|
+
controller.parameters.find(p => p.keyParam);
|
|
63
77
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
64
78
|
const options = {
|
|
65
79
|
projection: ctx.queryParams.projection,
|
|
66
80
|
filter: ctx.queryParams.filter,
|
|
67
81
|
};
|
|
68
|
-
return {
|
|
82
|
+
return {
|
|
83
|
+
method: 'replace',
|
|
84
|
+
key,
|
|
85
|
+
data,
|
|
86
|
+
options,
|
|
87
|
+
};
|
|
69
88
|
}
|
|
70
89
|
case 'Entity.Update': {
|
|
71
90
|
const data = await ctx.getBody();
|
|
72
|
-
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
91
|
+
const keyParam = operation.parameters.find(p => p.keyParam) ||
|
|
92
|
+
controller.parameters.find(p => p.keyParam);
|
|
73
93
|
const key = keyParam && ctx.pathParams[String(keyParam.name)];
|
|
74
94
|
const options = {
|
|
75
95
|
projection: ctx.queryParams.projection,
|
|
76
96
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
77
97
|
};
|
|
78
|
-
return {
|
|
98
|
+
return {
|
|
99
|
+
method: 'update',
|
|
100
|
+
key,
|
|
101
|
+
data,
|
|
102
|
+
options,
|
|
103
|
+
};
|
|
79
104
|
}
|
|
80
105
|
case 'Entity.UpdateMany': {
|
|
81
106
|
const data = await ctx.getBody();
|
|
82
107
|
const options = {
|
|
83
108
|
filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
|
|
84
109
|
};
|
|
85
|
-
return {
|
|
110
|
+
return {
|
|
111
|
+
method: 'updateMany',
|
|
112
|
+
data,
|
|
113
|
+
options,
|
|
114
|
+
};
|
|
86
115
|
}
|
|
87
116
|
default:
|
|
88
117
|
break;
|
|
@@ -72,7 +72,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
72
72
|
options,
|
|
73
73
|
};
|
|
74
74
|
return this._executeCommand(command, async () => {
|
|
75
|
-
const filter = SQBAdapter.parseFilter([
|
|
75
|
+
const filter = SQBAdapter.parseFilter([
|
|
76
|
+
await this._getCommonFilter(command),
|
|
77
|
+
command.options?.filter,
|
|
78
|
+
]);
|
|
76
79
|
command.options = { ...command.options, filter };
|
|
77
80
|
return this._count(command);
|
|
78
81
|
});
|
|
@@ -93,7 +96,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
93
96
|
options,
|
|
94
97
|
};
|
|
95
98
|
return this._executeCommand(command, async () => {
|
|
96
|
-
const filter = SQBAdapter.parseFilter([
|
|
99
|
+
const filter = SQBAdapter.parseFilter([
|
|
100
|
+
await this._getCommonFilter(command),
|
|
101
|
+
command.options?.filter,
|
|
102
|
+
]);
|
|
97
103
|
command.options = { ...command.options, filter };
|
|
98
104
|
return this._delete(command);
|
|
99
105
|
});
|
|
@@ -112,7 +118,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
112
118
|
options,
|
|
113
119
|
};
|
|
114
120
|
return this._executeCommand(command, async () => {
|
|
115
|
-
const filter = SQBAdapter.parseFilter([
|
|
121
|
+
const filter = SQBAdapter.parseFilter([
|
|
122
|
+
await this._getCommonFilter(command),
|
|
123
|
+
command.options?.filter,
|
|
124
|
+
]);
|
|
116
125
|
command.options = { ...command.options, filter };
|
|
117
126
|
return this._deleteMany(command);
|
|
118
127
|
});
|
|
@@ -133,7 +142,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
133
142
|
options,
|
|
134
143
|
};
|
|
135
144
|
return this._executeCommand(command, async () => {
|
|
136
|
-
const filter = SQBAdapter.parseFilter([
|
|
145
|
+
const filter = SQBAdapter.parseFilter([
|
|
146
|
+
await this._getCommonFilter(command),
|
|
147
|
+
command.options?.filter,
|
|
148
|
+
]);
|
|
137
149
|
command.options = { ...command.options, filter };
|
|
138
150
|
return this._exists(command);
|
|
139
151
|
});
|
|
@@ -152,7 +164,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
152
164
|
options,
|
|
153
165
|
};
|
|
154
166
|
return this._executeCommand(command, async () => {
|
|
155
|
-
const filter = SQBAdapter.parseFilter([
|
|
167
|
+
const filter = SQBAdapter.parseFilter([
|
|
168
|
+
await this._getCommonFilter(command),
|
|
169
|
+
command.options?.filter,
|
|
170
|
+
]);
|
|
156
171
|
command.options = { ...command.options, filter };
|
|
157
172
|
return this._existsOne(command);
|
|
158
173
|
});
|
|
@@ -174,7 +189,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
174
189
|
};
|
|
175
190
|
return this._executeCommand(command, async () => {
|
|
176
191
|
const documentFilter = await this._getCommonFilter(command);
|
|
177
|
-
const filter = SQBAdapter.parseFilter([
|
|
192
|
+
const filter = SQBAdapter.parseFilter([
|
|
193
|
+
documentFilter,
|
|
194
|
+
command.options?.filter,
|
|
195
|
+
]);
|
|
178
196
|
command.options = { ...command.options, filter };
|
|
179
197
|
return this._findById(command);
|
|
180
198
|
});
|
|
@@ -193,7 +211,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
193
211
|
options,
|
|
194
212
|
};
|
|
195
213
|
return this._executeCommand(command, async () => {
|
|
196
|
-
const filter = SQBAdapter.parseFilter([
|
|
214
|
+
const filter = SQBAdapter.parseFilter([
|
|
215
|
+
await this._getCommonFilter(command),
|
|
216
|
+
command.options?.filter,
|
|
217
|
+
]);
|
|
197
218
|
command.options = { ...command.options, filter };
|
|
198
219
|
return this._findOne(command);
|
|
199
220
|
});
|
|
@@ -212,7 +233,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
212
233
|
options,
|
|
213
234
|
};
|
|
214
235
|
return this._executeCommand(command, async () => {
|
|
215
|
-
const filter = SQBAdapter.parseFilter([
|
|
236
|
+
const filter = SQBAdapter.parseFilter([
|
|
237
|
+
await this._getCommonFilter(command),
|
|
238
|
+
command.options?.filter,
|
|
239
|
+
]);
|
|
216
240
|
const limit = command.options?.limit || this.defaultLimit;
|
|
217
241
|
command.options = { ...command.options, filter, limit };
|
|
218
242
|
return this._findMany(command);
|
|
@@ -226,7 +250,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
226
250
|
* @return A Promise that resolves to an array of partial outputs of type T and total count.
|
|
227
251
|
*/
|
|
228
252
|
async findManyWithCount(options) {
|
|
229
|
-
const [items, count] = await Promise.all([
|
|
253
|
+
const [items, count] = await Promise.all([
|
|
254
|
+
this.findMany(options),
|
|
255
|
+
this.count(options),
|
|
256
|
+
]);
|
|
230
257
|
return { count, items };
|
|
231
258
|
}
|
|
232
259
|
/**
|
|
@@ -263,7 +290,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
263
290
|
options,
|
|
264
291
|
};
|
|
265
292
|
return this._executeCommand(command, async () => {
|
|
266
|
-
const filter = SQBAdapter.parseFilter([
|
|
293
|
+
const filter = SQBAdapter.parseFilter([
|
|
294
|
+
await this._getCommonFilter(command),
|
|
295
|
+
command.options?.filter,
|
|
296
|
+
]);
|
|
267
297
|
command.options = { ...command.options, filter };
|
|
268
298
|
return this._update(command);
|
|
269
299
|
});
|
|
@@ -286,7 +316,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
286
316
|
options,
|
|
287
317
|
};
|
|
288
318
|
return this._executeCommand(command, async () => {
|
|
289
|
-
const filter = SQBAdapter.parseFilter([
|
|
319
|
+
const filter = SQBAdapter.parseFilter([
|
|
320
|
+
await this._getCommonFilter(command),
|
|
321
|
+
command.options?.filter,
|
|
322
|
+
]);
|
|
290
323
|
command.options = { ...command.options, filter };
|
|
291
324
|
return this._updateOnly(command);
|
|
292
325
|
});
|
|
@@ -307,7 +340,10 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
307
340
|
options,
|
|
308
341
|
};
|
|
309
342
|
return this._executeCommand(command, async () => {
|
|
310
|
-
const filter = SQBAdapter.parseFilter([
|
|
343
|
+
const filter = SQBAdapter.parseFilter([
|
|
344
|
+
await this._getCommonFilter(command),
|
|
345
|
+
command.options?.filter,
|
|
346
|
+
]);
|
|
311
347
|
command.options = { ...command.options, filter };
|
|
312
348
|
return this._updateMany(command);
|
|
313
349
|
});
|
|
@@ -63,10 +63,12 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
63
63
|
for(context, overwriteProperties, overwriteContext) {
|
|
64
64
|
if (overwriteProperties?.commonFilter && this.commonFilter) {
|
|
65
65
|
overwriteProperties.commonFilter = [
|
|
66
|
-
...(Array.isArray(this.commonFilter)
|
|
66
|
+
...(Array.isArray(this.commonFilter)
|
|
67
|
+
? this.commonFilter
|
|
68
|
+
: [this.commonFilter]),
|
|
67
69
|
...(Array.isArray(overwriteProperties?.commonFilter)
|
|
68
|
-
? overwriteProperties
|
|
69
|
-
: [overwriteProperties
|
|
70
|
+
? overwriteProperties.commonFilter
|
|
71
|
+
: [overwriteProperties.commonFilter]),
|
|
70
72
|
];
|
|
71
73
|
}
|
|
72
74
|
return super.for(context, overwriteProperties, overwriteContext);
|
|
@@ -78,7 +80,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
78
80
|
* @throws {Error} If the collection name is not defined.
|
|
79
81
|
*/
|
|
80
82
|
getResourceName() {
|
|
81
|
-
const out = typeof this.resourceName === 'function'
|
|
83
|
+
const out = typeof this.resourceName === 'function'
|
|
84
|
+
? this.resourceName(this)
|
|
85
|
+
: this.resourceName || this.dataType.name;
|
|
82
86
|
if (out)
|
|
83
87
|
return out;
|
|
84
88
|
throw new Error('resourceName is not defined');
|
|
@@ -107,7 +111,10 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
107
111
|
let validator = this._outputCodecs[operation];
|
|
108
112
|
if (validator)
|
|
109
113
|
return validator;
|
|
110
|
-
const options = {
|
|
114
|
+
const options = {
|
|
115
|
+
projection: '*',
|
|
116
|
+
partial: 'deep',
|
|
117
|
+
};
|
|
111
118
|
const dataType = this.dataType;
|
|
112
119
|
validator = dataType.generateCodec('decode', options);
|
|
113
120
|
this._outputCodecs[operation] = validator;
|
|
@@ -157,7 +164,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
157
164
|
* @protected
|
|
158
165
|
*/
|
|
159
166
|
async _count(command) {
|
|
160
|
-
const filter = command.options?.filter
|
|
167
|
+
const filter = command.options?.filter
|
|
168
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
169
|
+
: undefined;
|
|
161
170
|
return this._dbCount({ ...command.options, filter });
|
|
162
171
|
}
|
|
163
172
|
/**
|
|
@@ -169,7 +178,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
169
178
|
*/
|
|
170
179
|
async _delete(command) {
|
|
171
180
|
isNotNullish(command.documentId, { label: 'documentId' });
|
|
172
|
-
const filter = command.options?.filter
|
|
181
|
+
const filter = command.options?.filter
|
|
182
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
183
|
+
: undefined;
|
|
173
184
|
return this._dbDelete(command.documentId, { ...command.options, filter });
|
|
174
185
|
}
|
|
175
186
|
/**
|
|
@@ -180,7 +191,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
180
191
|
* @protected
|
|
181
192
|
*/
|
|
182
193
|
async _deleteMany(command) {
|
|
183
|
-
const filter = command.options?.filter
|
|
194
|
+
const filter = command.options?.filter
|
|
195
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
196
|
+
: undefined;
|
|
184
197
|
return await this._dbDeleteMany({ ...command.options, filter });
|
|
185
198
|
}
|
|
186
199
|
/**
|
|
@@ -191,8 +204,13 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
191
204
|
*/
|
|
192
205
|
async _exists(command) {
|
|
193
206
|
isNotNullish(command.documentId, { label: 'documentId' });
|
|
194
|
-
const filter = command.options?.filter
|
|
195
|
-
|
|
207
|
+
const filter = command.options?.filter
|
|
208
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
209
|
+
: undefined;
|
|
210
|
+
return await this._dbExists(command.documentId, {
|
|
211
|
+
...command.options,
|
|
212
|
+
filter,
|
|
213
|
+
});
|
|
196
214
|
}
|
|
197
215
|
/**
|
|
198
216
|
* Checks if a record with the given arguments exists.
|
|
@@ -202,7 +220,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
202
220
|
* @protected
|
|
203
221
|
*/
|
|
204
222
|
async _existsOne(command) {
|
|
205
|
-
const filter = command.options?.filter
|
|
223
|
+
const filter = command.options?.filter
|
|
224
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
225
|
+
: undefined;
|
|
206
226
|
return await this._dbExistsOne({ ...command.options, filter });
|
|
207
227
|
}
|
|
208
228
|
/**
|
|
@@ -215,8 +235,13 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
215
235
|
async _findById(command) {
|
|
216
236
|
isNotNullish(command.documentId, { label: 'documentId' });
|
|
217
237
|
const decode = this.getOutputCodec('find');
|
|
218
|
-
const filter = command.options?.filter
|
|
219
|
-
|
|
238
|
+
const filter = command.options?.filter
|
|
239
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
240
|
+
: undefined;
|
|
241
|
+
const out = await this._dbFindById(command.documentId, {
|
|
242
|
+
...command.options,
|
|
243
|
+
filter,
|
|
244
|
+
});
|
|
220
245
|
return out ? decode(out) : undefined;
|
|
221
246
|
}
|
|
222
247
|
/**
|
|
@@ -228,7 +253,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
228
253
|
*/
|
|
229
254
|
async _findOne(command) {
|
|
230
255
|
const decode = this.getOutputCodec('find');
|
|
231
|
-
const filter = command.options?.filter
|
|
256
|
+
const filter = command.options?.filter
|
|
257
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
258
|
+
: undefined;
|
|
232
259
|
const out = await this._dbFindOne({ ...command.options, filter });
|
|
233
260
|
return out ? decode(out) : undefined;
|
|
234
261
|
}
|
|
@@ -241,7 +268,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
241
268
|
*/
|
|
242
269
|
async _findMany(command) {
|
|
243
270
|
const decode = this.getOutputCodec('find');
|
|
244
|
-
const filter = command.options?.filter
|
|
271
|
+
const filter = command.options?.filter
|
|
272
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
273
|
+
: undefined;
|
|
245
274
|
const out = await this._dbFindMany({ ...command.options, filter });
|
|
246
275
|
if (out?.length) {
|
|
247
276
|
return out.map(x => decode(x));
|
|
@@ -261,7 +290,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
261
290
|
const { documentId, input, options } = command;
|
|
262
291
|
const inputCodec = this.getInputCodec('update');
|
|
263
292
|
const data = inputCodec(input);
|
|
264
|
-
const filter = command.options?.filter
|
|
293
|
+
const filter = command.options?.filter
|
|
294
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
295
|
+
: undefined;
|
|
265
296
|
const out = await this._dbUpdate(documentId, data, { ...options, filter });
|
|
266
297
|
const outputCodec = this.getOutputCodec('update');
|
|
267
298
|
if (out)
|
|
@@ -280,7 +311,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
280
311
|
const { documentId, input, options } = command;
|
|
281
312
|
const inputCodec = this.getInputCodec('update');
|
|
282
313
|
const data = inputCodec(input);
|
|
283
|
-
const filter = command.options?.filter
|
|
314
|
+
const filter = command.options?.filter
|
|
315
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
316
|
+
: undefined;
|
|
284
317
|
return await this._dbUpdateOnly(documentId, data, { ...options, filter });
|
|
285
318
|
}
|
|
286
319
|
/**
|
|
@@ -294,7 +327,9 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
294
327
|
isNotNullish(command.input, { label: 'input' });
|
|
295
328
|
const inputCodec = this.getInputCodec('update');
|
|
296
329
|
const data = inputCodec(command.input);
|
|
297
|
-
const filter = command.options?.filter
|
|
330
|
+
const filter = command.options?.filter
|
|
331
|
+
? SQBAdapter.parseFilter(command.options.filter)
|
|
332
|
+
: undefined;
|
|
298
333
|
return await this._dbUpdateMany(data, { ...command.options, filter });
|
|
299
334
|
}
|
|
300
335
|
/**
|
|
@@ -469,8 +504,10 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
469
504
|
* that resolves to the common filter, or undefined if not available.
|
|
470
505
|
*/
|
|
471
506
|
_getCommonFilter(command) {
|
|
472
|
-
const commonFilter = Array.isArray(this.commonFilter)
|
|
473
|
-
|
|
507
|
+
const commonFilter = Array.isArray(this.commonFilter)
|
|
508
|
+
? this.commonFilter
|
|
509
|
+
: [this.commonFilter];
|
|
510
|
+
const mapped = commonFilter.map(f => typeof f === 'function' ? f(command, this) : f);
|
|
474
511
|
return mapped.length > 1 ? op.and(...mapped) : mapped[0];
|
|
475
512
|
}
|
|
476
513
|
async _executeCommand(command, commandFn) {
|
|
@@ -478,7 +515,8 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
478
515
|
const next = async () => {
|
|
479
516
|
proto = proto ? Object.getPrototypeOf(proto) : this;
|
|
480
517
|
while (proto) {
|
|
481
|
-
if (proto.interceptor &&
|
|
518
|
+
if (proto.interceptor &&
|
|
519
|
+
Object.prototype.hasOwnProperty.call(proto, 'interceptor')) {
|
|
482
520
|
return await proto.interceptor.call(this, next, command, this);
|
|
483
521
|
}
|
|
484
522
|
proto = Object.getPrototypeOf(proto);
|
|
@@ -528,44 +566,64 @@ export class SqbEntityService extends SqbServiceBase {
|
|
|
528
566
|
throw e;
|
|
529
567
|
}
|
|
530
568
|
}
|
|
569
|
+
async _beforeCreate(
|
|
531
570
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
532
|
-
|
|
571
|
+
command) {
|
|
533
572
|
// Do nothing
|
|
534
573
|
}
|
|
574
|
+
async _beforeUpdate(
|
|
535
575
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
536
|
-
|
|
576
|
+
command) {
|
|
537
577
|
// Do nothing
|
|
538
578
|
}
|
|
579
|
+
async _beforeUpdateMany(
|
|
539
580
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
540
|
-
|
|
581
|
+
command) {
|
|
541
582
|
// Do nothing
|
|
542
583
|
}
|
|
584
|
+
async _beforeDelete(
|
|
543
585
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
544
|
-
|
|
586
|
+
command) {
|
|
545
587
|
// Do nothing
|
|
546
588
|
}
|
|
589
|
+
async _beforeDeleteMany(
|
|
547
590
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
548
|
-
|
|
591
|
+
command) {
|
|
549
592
|
// Do nothing
|
|
550
593
|
}
|
|
594
|
+
async _afterCreate(
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
596
|
+
command,
|
|
551
597
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
552
|
-
|
|
598
|
+
result) {
|
|
553
599
|
// Do nothing
|
|
554
600
|
}
|
|
601
|
+
async _afterUpdate(
|
|
602
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
603
|
+
command,
|
|
555
604
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
556
|
-
|
|
605
|
+
result) {
|
|
557
606
|
// Do nothing
|
|
558
607
|
}
|
|
608
|
+
async _afterUpdateMany(
|
|
559
609
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
560
|
-
|
|
610
|
+
command,
|
|
611
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
612
|
+
affected) {
|
|
561
613
|
// Do nothing
|
|
562
614
|
}
|
|
615
|
+
async _afterDelete(
|
|
616
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
617
|
+
command,
|
|
563
618
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
564
|
-
|
|
619
|
+
affected) {
|
|
565
620
|
// Do nothing
|
|
566
621
|
}
|
|
622
|
+
async _afterDeleteMany(
|
|
623
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
624
|
+
command,
|
|
567
625
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
568
|
-
|
|
626
|
+
affected) {
|
|
569
627
|
// Do nothing
|
|
570
628
|
}
|
|
571
629
|
}
|
|
@@ -68,7 +68,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
68
68
|
options,
|
|
69
69
|
};
|
|
70
70
|
return this._executeCommand(command, async () => {
|
|
71
|
-
const filter = SQBAdapter.parseFilter([
|
|
71
|
+
const filter = SQBAdapter.parseFilter([
|
|
72
|
+
await this._getCommonFilter(command),
|
|
73
|
+
command.options?.filter,
|
|
74
|
+
]);
|
|
72
75
|
command.options = { ...command.options, filter };
|
|
73
76
|
return this._delete(command);
|
|
74
77
|
});
|
|
@@ -88,7 +91,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
88
91
|
options,
|
|
89
92
|
};
|
|
90
93
|
return this._executeCommand(command, async () => {
|
|
91
|
-
const filter = SQBAdapter.parseFilter([
|
|
94
|
+
const filter = SQBAdapter.parseFilter([
|
|
95
|
+
await this._getCommonFilter(command),
|
|
96
|
+
command.options?.filter,
|
|
97
|
+
]);
|
|
92
98
|
command.options = { ...command.options, filter };
|
|
93
99
|
return this._exists(command);
|
|
94
100
|
});
|
|
@@ -102,7 +108,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
102
108
|
options,
|
|
103
109
|
};
|
|
104
110
|
return this._executeCommand(command, async () => {
|
|
105
|
-
const filter = SQBAdapter.parseFilter([
|
|
111
|
+
const filter = SQBAdapter.parseFilter([
|
|
112
|
+
await this._getCommonFilter(command),
|
|
113
|
+
command.options?.filter,
|
|
114
|
+
]);
|
|
106
115
|
command.options = { ...command.options, filter };
|
|
107
116
|
return this._findById(command);
|
|
108
117
|
});
|
|
@@ -123,7 +132,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
123
132
|
options,
|
|
124
133
|
};
|
|
125
134
|
return this._executeCommand(command, async () => {
|
|
126
|
-
const filter = SQBAdapter.parseFilter([
|
|
135
|
+
const filter = SQBAdapter.parseFilter([
|
|
136
|
+
await this._getCommonFilter(command),
|
|
137
|
+
command.options?.filter,
|
|
138
|
+
]);
|
|
127
139
|
command.options = { ...command.options, filter };
|
|
128
140
|
return this._update(command);
|
|
129
141
|
});
|
|
@@ -145,7 +157,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
145
157
|
options,
|
|
146
158
|
};
|
|
147
159
|
return this._executeCommand(command, async () => {
|
|
148
|
-
const filter = SQBAdapter.parseFilter([
|
|
160
|
+
const filter = SQBAdapter.parseFilter([
|
|
161
|
+
await this._getCommonFilter(command),
|
|
162
|
+
command.options?.filter,
|
|
163
|
+
]);
|
|
149
164
|
command.options = { ...command.options, filter };
|
|
150
165
|
return this._updateOnly(command);
|
|
151
166
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"valgen": "^5.12.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@opra/core": "^1.4.
|
|
14
|
-
"@opra/http": "^1.4.
|
|
13
|
+
"@opra/core": "^1.4.4",
|
|
14
|
+
"@opra/http": "^1.4.4",
|
|
15
15
|
"@sqb/connect": ">= 4.19.1"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|