@opra/sqb 1.20.0 → 1.22.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.
Files changed (34) hide show
  1. package/package.json +10 -27
  2. package/{types/sqb-collection-service.d.ts → sqb-collection-service.d.ts} +1 -1
  3. package/{esm/sqb-collection-service.js → sqb-collection-service.js} +4 -0
  4. package/{esm/sqb-entity-service.js → sqb-entity-service.js} +29 -2
  5. package/{esm/sqb-service-base.js → sqb-service-base.js} +4 -0
  6. package/{types/sqb-singleton-service.d.ts → sqb-singleton-service.d.ts} +1 -1
  7. package/{esm/sqb-singleton-service.js → sqb-singleton-service.js} +5 -0
  8. package/cjs/adapter-utils/prepare-filter.js +0 -108
  9. package/cjs/augmentation/datatype-factory.augmentation.js +0 -90
  10. package/cjs/augmentation/mapped-type.augmentation.js +0 -14
  11. package/cjs/augmentation/mixin-type.augmentation.js +0 -11
  12. package/cjs/index.js +0 -11
  13. package/cjs/package.json +0 -3
  14. package/cjs/sqb-adapter.js +0 -130
  15. package/cjs/sqb-collection-service.js +0 -355
  16. package/cjs/sqb-entity-service.js +0 -642
  17. package/cjs/sqb-service-base.js +0 -88
  18. package/cjs/sqb-singleton-service.js +0 -172
  19. package/esm/package.json +0 -3
  20. package/types/index.d.cts +0 -8
  21. /package/{types/adapter-utils → adapter-utils}/prepare-filter.d.ts +0 -0
  22. /package/{esm/adapter-utils → adapter-utils}/prepare-filter.js +0 -0
  23. /package/{types/augmentation → augmentation}/datatype-factory.augmentation.d.ts +0 -0
  24. /package/{esm/augmentation → augmentation}/datatype-factory.augmentation.js +0 -0
  25. /package/{types/augmentation → augmentation}/mapped-type.augmentation.d.ts +0 -0
  26. /package/{esm/augmentation → augmentation}/mapped-type.augmentation.js +0 -0
  27. /package/{types/augmentation → augmentation}/mixin-type.augmentation.d.ts +0 -0
  28. /package/{esm/augmentation → augmentation}/mixin-type.augmentation.js +0 -0
  29. /package/{types/index.d.ts → index.d.ts} +0 -0
  30. /package/{esm/index.js → index.js} +0 -0
  31. /package/{types/sqb-adapter.d.ts → sqb-adapter.d.ts} +0 -0
  32. /package/{esm/sqb-adapter.js → sqb-adapter.js} +0 -0
  33. /package/{types/sqb-entity-service.d.ts → sqb-entity-service.d.ts} +0 -0
  34. /package/{types/sqb-service-base.d.ts → sqb-service-base.d.ts} +0 -0
@@ -1,355 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqbCollectionService = void 0;
4
- const common_1 = require("@opra/common");
5
- const sqb_adapter_js_1 = require("./sqb-adapter.js");
6
- const sqb_entity_service_js_1 = require("./sqb-entity-service.js");
7
- /**
8
- * @class SqbCollectionService
9
- * @template T - The data type class type of the resource
10
- */
11
- class SqbCollectionService extends sqb_entity_service_js_1.SqbEntityService {
12
- /**
13
- * Constructs a new instance
14
- *
15
- * @param {Type | string} dataType - The data type of the array elements.
16
- * @param {SqbCollectionService.Options} [options] - The options for the array service.
17
- * @constructor
18
- */
19
- constructor(dataType, options) {
20
- super(dataType, options);
21
- this.defaultLimit = options?.defaultLimit || 100;
22
- }
23
- /**
24
- * Asserts the existence of a resource with the given ID.
25
- * Throws a ResourceNotFoundError if the resource does not exist.
26
- *
27
- * @param {SQBAdapter.IdOrIds} id - The ID of the resource to assert.
28
- * @param {SqbCollectionService.ExistsOptions} [options] - Optional options for checking the existence.
29
- * @returns {Promise<void>} - A Promise that resolves when the resource exists.
30
- * @throws {ResourceNotAvailableError} - If the resource does not exist.
31
- */
32
- async assert(id, options) {
33
- if (!(await this.exists(id, options)))
34
- throw new common_1.ResourceNotAvailableError(this.getResourceName(), id);
35
- }
36
- async create(input, options) {
37
- const command = {
38
- crud: 'create',
39
- method: 'create',
40
- byId: false,
41
- input,
42
- options,
43
- };
44
- return this._executeCommand(command, () => this._create(command));
45
- }
46
- /**
47
- * Creates a new resource
48
- *
49
- * @param {PartialDTO<T>} input - The input data
50
- * @param {SqbCollectionService.CreateOptions} [options] - The options object
51
- * @returns {Promise<void>} A promise that resolves create operation result
52
- * @throws {Error} if an unknown error occurs while creating the resource
53
- */
54
- async createOnly(input, options) {
55
- const command = {
56
- crud: 'create',
57
- method: 'createOnly',
58
- byId: false,
59
- input,
60
- options,
61
- };
62
- return this._executeCommand(command, () => this._createOnly(command));
63
- }
64
- /**
65
- * Returns the count of records based on the provided options
66
- *
67
- * @param {SqbCollectionService.CountOptions} options - The options for the count operation.
68
- * @return {Promise<number>} - A promise that resolves to the count of records
69
- */
70
- async count(options) {
71
- const command = {
72
- crud: 'read',
73
- method: 'count',
74
- byId: false,
75
- options,
76
- };
77
- return this._executeCommand(command, async () => {
78
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
79
- await this._getCommonFilter(command),
80
- command.options?.filter,
81
- ]);
82
- command.options = { ...command.options, filter };
83
- return this._count(command);
84
- });
85
- }
86
- /**
87
- * Deletes a record from the collection.
88
- *
89
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to delete.
90
- * @param {SqbCollectionService.DeleteOptions} [options] - Optional delete options.
91
- * @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
92
- */
93
- async delete(id, options) {
94
- const command = {
95
- crud: 'delete',
96
- method: 'delete',
97
- byId: true,
98
- documentId: id,
99
- options,
100
- };
101
- return this._executeCommand(command, async () => {
102
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
103
- await this._getCommonFilter(command),
104
- command.options?.filter,
105
- ]);
106
- command.options = { ...command.options, filter };
107
- return this._delete(command);
108
- });
109
- }
110
- /**
111
- * Deletes multiple documents from the collection that meet the specified filter criteria.
112
- *
113
- * @param {SqbCollectionService.DeleteManyOptions} options - The options for the delete operation.
114
- * @return {Promise<number>} - A promise that resolves to the number of documents deleted.
115
- */
116
- async deleteMany(options) {
117
- const command = {
118
- crud: 'delete',
119
- method: 'deleteMany',
120
- byId: false,
121
- options,
122
- };
123
- return this._executeCommand(command, async () => {
124
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
125
- await this._getCommonFilter(command),
126
- command.options?.filter,
127
- ]);
128
- command.options = { ...command.options, filter };
129
- return this._deleteMany(command);
130
- });
131
- }
132
- /**
133
- * Checks if a record with the given id exists.
134
- *
135
- * @param {SQBAdapter.IdOrIds} id - The id of the object to check.
136
- * @param {SqbCollectionService.ExistsOptions} [options] - The options for the query (optional).
137
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
138
- */
139
- async exists(id, options) {
140
- const command = {
141
- crud: 'read',
142
- method: 'exists',
143
- byId: true,
144
- documentId: id,
145
- options,
146
- };
147
- return this._executeCommand(command, async () => {
148
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
149
- await this._getCommonFilter(command),
150
- command.options?.filter,
151
- ]);
152
- command.options = { ...command.options, filter };
153
- return this._exists(command);
154
- });
155
- }
156
- /**
157
- * Checks if a record with the given arguments exists.
158
- *
159
- * @param {SqbCollectionService.ExistsOneOptions} [options] - The options for the query (optional).
160
- * @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
161
- */
162
- async existsOne(options) {
163
- const command = {
164
- crud: 'read',
165
- method: 'existsOne',
166
- byId: false,
167
- options,
168
- };
169
- return this._executeCommand(command, async () => {
170
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
171
- await this._getCommonFilter(command),
172
- command.options?.filter,
173
- ]);
174
- command.options = { ...command.options, filter };
175
- return this._existsOne(command);
176
- });
177
- }
178
- /**
179
- * Finds a record by ID.
180
- *
181
- * @param {SQBAdapter.IdOrIds} id - The ID of the record.
182
- * @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
183
- * @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
184
- */
185
- async findById(id, options) {
186
- const command = {
187
- crud: 'read',
188
- method: 'findById',
189
- byId: true,
190
- documentId: id,
191
- options,
192
- };
193
- return this._executeCommand(command, async () => {
194
- const documentFilter = await this._getCommonFilter(command);
195
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
196
- documentFilter,
197
- command.options?.filter,
198
- ]);
199
- command.options = { ...command.options, filter };
200
- return this._findById(command);
201
- });
202
- }
203
- /**
204
- * Finds a record in the collection that matches the specified options.
205
- *
206
- * @param {SqbCollectionService.FindOneOptions} options - The options for the query.
207
- * @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
208
- */
209
- async findOne(options) {
210
- const command = {
211
- crud: 'read',
212
- method: 'findOne',
213
- byId: false,
214
- options,
215
- };
216
- return this._executeCommand(command, async () => {
217
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
218
- await this._getCommonFilter(command),
219
- command.options?.filter,
220
- ]);
221
- command.options = { ...command.options, filter };
222
- return this._findOne(command);
223
- });
224
- }
225
- /**
226
- * Finds multiple records in collection.
227
- *
228
- * @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
229
- * @return A Promise that resolves to an array of partial outputs of type T.
230
- */
231
- async findMany(options) {
232
- const command = {
233
- crud: 'read',
234
- method: 'findMany',
235
- byId: false,
236
- options,
237
- };
238
- return this._executeCommand(command, async () => {
239
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
240
- await this._getCommonFilter(command),
241
- command.options?.filter,
242
- ]);
243
- const limit = command.options?.limit || this.defaultLimit;
244
- command.options = { ...command.options, filter, limit };
245
- return this._findMany(command);
246
- });
247
- }
248
- /**
249
- * Finds multiple records in the collection and returns both records (max limit)
250
- * and total count that matched the given criteria
251
- *
252
- * @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
253
- * @return A Promise that resolves to an array of partial outputs of type T and total count.
254
- */
255
- async findManyWithCount(options) {
256
- const [items, count] = await Promise.all([
257
- this.findMany(options),
258
- this.count(options),
259
- ]);
260
- return { count, items };
261
- }
262
- /**
263
- * Retrieves a records from the collection by its ID. Throws error if not found.
264
- *
265
- * @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
266
- * @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
267
- * @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
268
- * or rejects with a ResourceNotFoundError if the document does not exist.
269
- * @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
270
- */
271
- async get(id, options) {
272
- const out = await this.findById(id, options);
273
- if (!out)
274
- throw new common_1.ResourceNotAvailableError(this.getResourceName(), id);
275
- return out;
276
- }
277
- /**
278
- * Updates a record with the given id in the collection.
279
- *
280
- * @param {SQBAdapter.IdOrIds} id - The id of the document to update.
281
- * @param {PatchDTO<T>} input - The partial input object containing the fields to update.
282
- * @param {SqbCollectionService.UpdateOptions} [options] - The options for the update operation.
283
- * @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
284
- * undefined if the document was not found.
285
- */
286
- async update(id, input, options) {
287
- const command = {
288
- crud: 'update',
289
- method: 'update',
290
- documentId: id,
291
- byId: true,
292
- input,
293
- options,
294
- };
295
- return this._executeCommand(command, async () => {
296
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
297
- await this._getCommonFilter(command),
298
- command.options?.filter,
299
- ]);
300
- command.options = { ...command.options, filter };
301
- return this._update(command);
302
- });
303
- }
304
- /**
305
- * Updates a record in the collection with the specified ID and returns updated record count
306
- *
307
- * @param {any} id - The ID of the document to update.
308
- * @param {PatchDTO<T>} input - The partial input data to update the document with.
309
- * @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
310
- * @returns {Promise<number>} - A promise that resolves to the number of documents modified.
311
- */
312
- async updateOnly(id, input, options) {
313
- const command = {
314
- crud: 'update',
315
- method: 'update',
316
- documentId: id,
317
- byId: true,
318
- input,
319
- options,
320
- };
321
- return this._executeCommand(command, async () => {
322
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
323
- await this._getCommonFilter(command),
324
- command.options?.filter,
325
- ]);
326
- command.options = { ...command.options, filter };
327
- return this._updateOnly(command);
328
- });
329
- }
330
- /**
331
- * Updates multiple records in the collection based on the specified input and options.
332
- *
333
- * @param {PatchDTO<T>} input - The partial input to update the documents with.
334
- * @param {SqbCollectionService.UpdateManyOptions} options - The options for updating the documents.
335
- * @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
336
- */
337
- async updateMany(input, options) {
338
- const command = {
339
- crud: 'update',
340
- method: 'updateMany',
341
- byId: false,
342
- input,
343
- options,
344
- };
345
- return this._executeCommand(command, async () => {
346
- const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([
347
- await this._getCommonFilter(command),
348
- command.options?.filter,
349
- ]);
350
- command.options = { ...command.options, filter };
351
- return this._updateMany(command);
352
- });
353
- }
354
- }
355
- exports.SqbCollectionService = SqbCollectionService;