@opra/sqb 1.0.0-alpha.17 → 1.0.0-alpha.19
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/adapter-utils/parse-filter.js +1 -1
- package/cjs/sqb-collection-service.js +71 -60
- package/cjs/sqb-entity-service.js +83 -71
- package/cjs/sqb-singleton-service.js +36 -30
- package/esm/sqb-collection-service.js +71 -60
- package/esm/sqb-entity-service.js +83 -71
- package/esm/sqb-singleton-service.js +36 -30
- package/package.json +3 -3
- package/types/sqb-collection-service.d.ts +8 -8
- package/types/sqb-entity-service.d.ts +94 -80
- package/types/sqb-singleton-service.d.ts +4 -4
|
@@ -40,16 +40,16 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
40
40
|
* @throws {Error} if an unknown error occurs while creating the resource
|
|
41
41
|
*/
|
|
42
42
|
async create(input, options) {
|
|
43
|
-
const
|
|
43
|
+
const command = {
|
|
44
44
|
crud: 'create',
|
|
45
45
|
method: 'create',
|
|
46
46
|
byId: false,
|
|
47
47
|
input,
|
|
48
48
|
options,
|
|
49
49
|
};
|
|
50
|
-
return this.
|
|
50
|
+
return this._executeCommand(command, async () => {
|
|
51
51
|
const primaryFields = connect_1.EntityMetadata.getPrimaryIndexColumns(this.entityMetadata);
|
|
52
|
-
const data = { ...input };
|
|
52
|
+
const data = { ...command.input };
|
|
53
53
|
if (primaryFields.length > 1) {
|
|
54
54
|
if (typeof primaryFields !== 'object') {
|
|
55
55
|
throw new TypeError(`"${this.entityMetadata.name}" should has multiple primary key fields. So you should provide and object that contains key fields`);
|
|
@@ -60,8 +60,9 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
60
60
|
}
|
|
61
61
|
else
|
|
62
62
|
data[primaryFields[0].name] = this.id;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
command.input = data;
|
|
64
|
+
return await this._create(command);
|
|
65
|
+
});
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Deletes the singleton record
|
|
@@ -70,17 +71,18 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
70
71
|
* @return {Promise<number>} - A Promise that resolves to the number of records deleted
|
|
71
72
|
*/
|
|
72
73
|
async delete(options) {
|
|
73
|
-
const
|
|
74
|
+
const command = {
|
|
74
75
|
crud: 'delete',
|
|
75
76
|
method: 'delete',
|
|
76
77
|
byId: true,
|
|
77
78
|
documentId: this.id,
|
|
78
79
|
options,
|
|
79
80
|
};
|
|
80
|
-
return this.
|
|
81
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
return this._executeCommand(command, async () => {
|
|
82
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
83
|
+
command.options = { ...command.options, filter };
|
|
84
|
+
return this._delete(command);
|
|
85
|
+
});
|
|
84
86
|
}
|
|
85
87
|
/**
|
|
86
88
|
* Checks if the singleton record exists.
|
|
@@ -89,17 +91,18 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
89
91
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
90
92
|
*/
|
|
91
93
|
async exists(options) {
|
|
92
|
-
const
|
|
94
|
+
const command = {
|
|
93
95
|
crud: 'read',
|
|
94
96
|
method: 'exists',
|
|
95
97
|
byId: true,
|
|
96
98
|
documentId: this.id,
|
|
97
99
|
options,
|
|
98
100
|
};
|
|
99
|
-
return this.
|
|
100
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
return this._executeCommand(command, async () => {
|
|
102
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
103
|
+
command.options = { ...command.options, filter };
|
|
104
|
+
return this._exists(command);
|
|
105
|
+
});
|
|
103
106
|
}
|
|
104
107
|
/**
|
|
105
108
|
* Finds the singleton record. Returns `undefined` if not found
|
|
@@ -108,17 +111,18 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
108
111
|
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
109
112
|
*/
|
|
110
113
|
async find(options) {
|
|
111
|
-
const
|
|
114
|
+
const command = {
|
|
112
115
|
crud: 'read',
|
|
113
116
|
method: 'findById',
|
|
114
117
|
byId: true,
|
|
115
118
|
documentId: this.id,
|
|
116
119
|
options,
|
|
117
120
|
};
|
|
118
|
-
return this.
|
|
119
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
return this._executeCommand(command, async () => {
|
|
122
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
123
|
+
command.options = { ...command.options, filter };
|
|
124
|
+
return this._findById(command);
|
|
125
|
+
});
|
|
122
126
|
}
|
|
123
127
|
/**
|
|
124
128
|
* Retrieves the singleton record. Throws error if not found.
|
|
@@ -143,7 +147,7 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
143
147
|
* undefined if the document was not found.
|
|
144
148
|
*/
|
|
145
149
|
async update(input, options) {
|
|
146
|
-
const
|
|
150
|
+
const command = {
|
|
147
151
|
crud: 'update',
|
|
148
152
|
method: 'update',
|
|
149
153
|
documentId: this.id,
|
|
@@ -151,10 +155,11 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
151
155
|
input,
|
|
152
156
|
options,
|
|
153
157
|
};
|
|
154
|
-
return this.
|
|
155
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
return this._executeCommand(command, async () => {
|
|
159
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
160
|
+
command.options = { ...command.options, filter };
|
|
161
|
+
return this._update(command);
|
|
162
|
+
});
|
|
158
163
|
}
|
|
159
164
|
/**
|
|
160
165
|
* Updates the singleton and returns updated record count
|
|
@@ -164,7 +169,7 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
164
169
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
165
170
|
*/
|
|
166
171
|
async updateOnly(input, options) {
|
|
167
|
-
const
|
|
172
|
+
const command = {
|
|
168
173
|
crud: 'update',
|
|
169
174
|
method: 'update',
|
|
170
175
|
documentId: this.id,
|
|
@@ -172,10 +177,11 @@ class SqbSingletonService extends sqb_entity_service_js_1.SqbEntityService {
|
|
|
172
177
|
input,
|
|
173
178
|
options,
|
|
174
179
|
};
|
|
175
|
-
return this.
|
|
176
|
-
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
return this._executeCommand(command, async () => {
|
|
181
|
+
const filter = sqb_adapter_js_1.SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
182
|
+
command.options = { ...command.options, filter };
|
|
183
|
+
return this._updateOnly(command);
|
|
184
|
+
});
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
exports.SqbSingletonService = SqbSingletonService;
|
|
@@ -39,14 +39,14 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
39
39
|
* @throws {Error} if an unknown error occurs while creating the resource
|
|
40
40
|
*/
|
|
41
41
|
async create(input, options) {
|
|
42
|
-
const
|
|
42
|
+
const command = {
|
|
43
43
|
crud: 'create',
|
|
44
44
|
method: 'create',
|
|
45
45
|
byId: false,
|
|
46
46
|
input,
|
|
47
47
|
options,
|
|
48
48
|
};
|
|
49
|
-
return this.
|
|
49
|
+
return this._executeCommand(command, () => this._create(command));
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Returns the count of records based on the provided options
|
|
@@ -55,16 +55,17 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
55
55
|
* @return {Promise<number>} - A promise that resolves to the count of records
|
|
56
56
|
*/
|
|
57
57
|
async count(options) {
|
|
58
|
-
const
|
|
58
|
+
const command = {
|
|
59
59
|
crud: 'read',
|
|
60
60
|
method: 'count',
|
|
61
61
|
byId: false,
|
|
62
62
|
options,
|
|
63
63
|
};
|
|
64
|
-
return this.
|
|
65
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
return this._executeCommand(command, async () => {
|
|
65
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
66
|
+
command.options = { ...command.options, filter };
|
|
67
|
+
return this._count(command);
|
|
68
|
+
});
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
* Deletes a record from the collection.
|
|
@@ -74,17 +75,18 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
74
75
|
* @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
|
|
75
76
|
*/
|
|
76
77
|
async delete(id, options) {
|
|
77
|
-
const
|
|
78
|
+
const command = {
|
|
78
79
|
crud: 'delete',
|
|
79
80
|
method: 'delete',
|
|
80
81
|
byId: true,
|
|
81
82
|
documentId: id,
|
|
82
83
|
options,
|
|
83
84
|
};
|
|
84
|
-
return this.
|
|
85
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
return this._executeCommand(command, async () => {
|
|
86
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
87
|
+
command.options = { ...command.options, filter };
|
|
88
|
+
return this._delete(command);
|
|
89
|
+
});
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
92
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
@@ -93,16 +95,17 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
93
95
|
* @return {Promise<number>} - A promise that resolves to the number of documents deleted.
|
|
94
96
|
*/
|
|
95
97
|
async deleteMany(options) {
|
|
96
|
-
const
|
|
98
|
+
const command = {
|
|
97
99
|
crud: 'delete',
|
|
98
100
|
method: 'deleteMany',
|
|
99
101
|
byId: false,
|
|
100
102
|
options,
|
|
101
103
|
};
|
|
102
|
-
return this.
|
|
103
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
return this._executeCommand(command, async () => {
|
|
105
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
106
|
+
command.options = { ...command.options, filter };
|
|
107
|
+
return this._deleteMany(command);
|
|
108
|
+
});
|
|
106
109
|
}
|
|
107
110
|
/**
|
|
108
111
|
* Checks if a record with the given id exists.
|
|
@@ -112,17 +115,18 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
112
115
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
113
116
|
*/
|
|
114
117
|
async exists(id, options) {
|
|
115
|
-
const
|
|
118
|
+
const command = {
|
|
116
119
|
crud: 'read',
|
|
117
120
|
method: 'exists',
|
|
118
121
|
byId: true,
|
|
119
122
|
documentId: id,
|
|
120
123
|
options,
|
|
121
124
|
};
|
|
122
|
-
return this.
|
|
123
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
return this._executeCommand(command, async () => {
|
|
126
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
127
|
+
command.options = { ...command.options, filter };
|
|
128
|
+
return this._exists(command);
|
|
129
|
+
});
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Checks if a record with the given arguments exists.
|
|
@@ -131,37 +135,39 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
131
135
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
132
136
|
*/
|
|
133
137
|
async existsOne(options) {
|
|
134
|
-
const
|
|
138
|
+
const command = {
|
|
135
139
|
crud: 'read',
|
|
136
140
|
method: 'existsOne',
|
|
137
141
|
byId: false,
|
|
138
142
|
options,
|
|
139
143
|
};
|
|
140
|
-
return this.
|
|
141
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
return this._executeCommand(command, async () => {
|
|
145
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
146
|
+
command.options = { ...command.options, filter };
|
|
147
|
+
return this._existsOne(command);
|
|
148
|
+
});
|
|
144
149
|
}
|
|
145
150
|
/**
|
|
146
151
|
* Finds a record by ID.
|
|
147
152
|
*
|
|
148
|
-
* @param {SQBAdapter.
|
|
153
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the record.
|
|
149
154
|
* @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
|
|
150
155
|
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
151
156
|
*/
|
|
152
157
|
async findById(id, options) {
|
|
153
|
-
const
|
|
158
|
+
const command = {
|
|
154
159
|
crud: 'read',
|
|
155
160
|
method: 'findById',
|
|
156
161
|
byId: true,
|
|
157
162
|
documentId: id,
|
|
158
163
|
options,
|
|
159
164
|
};
|
|
160
|
-
return this.
|
|
161
|
-
const documentFilter = await this._getCommonFilter(
|
|
162
|
-
const filter = SQBAdapter.parseFilter([documentFilter, options?.filter]);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
return this._executeCommand(command, async () => {
|
|
166
|
+
const documentFilter = await this._getCommonFilter(command);
|
|
167
|
+
const filter = SQBAdapter.parseFilter([documentFilter, command.options?.filter]);
|
|
168
|
+
command.options = { ...command.options, filter };
|
|
169
|
+
return this._findById(command);
|
|
170
|
+
});
|
|
165
171
|
}
|
|
166
172
|
/**
|
|
167
173
|
* Finds a record in the collection that matches the specified options.
|
|
@@ -170,16 +176,17 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
170
176
|
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
171
177
|
*/
|
|
172
178
|
async findOne(options) {
|
|
173
|
-
const
|
|
179
|
+
const command = {
|
|
174
180
|
crud: 'read',
|
|
175
181
|
method: 'findOne',
|
|
176
182
|
byId: false,
|
|
177
183
|
options,
|
|
178
184
|
};
|
|
179
|
-
return this.
|
|
180
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
181
|
-
|
|
182
|
-
|
|
185
|
+
return this._executeCommand(command, async () => {
|
|
186
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
187
|
+
command.options = { ...command.options, filter };
|
|
188
|
+
return this._findOne(command);
|
|
189
|
+
});
|
|
183
190
|
}
|
|
184
191
|
/**
|
|
185
192
|
* Finds multiple records in collection.
|
|
@@ -188,16 +195,17 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
188
195
|
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
189
196
|
*/
|
|
190
197
|
async findMany(options) {
|
|
191
|
-
const
|
|
198
|
+
const command = {
|
|
192
199
|
crud: 'read',
|
|
193
200
|
method: 'findMany',
|
|
194
201
|
byId: false,
|
|
195
202
|
options,
|
|
196
203
|
};
|
|
197
|
-
return this.
|
|
198
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
return this._executeCommand(command, async () => {
|
|
205
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
206
|
+
command.options = { ...command.options, filter };
|
|
207
|
+
return this._findMany(command);
|
|
208
|
+
});
|
|
201
209
|
}
|
|
202
210
|
/**
|
|
203
211
|
* Finds multiple records in the collection and returns both records (max limit)
|
|
@@ -213,7 +221,7 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
213
221
|
/**
|
|
214
222
|
* Retrieves a records from the collection by its ID. Throws error if not found.
|
|
215
223
|
*
|
|
216
|
-
* @param {SQBAdapter.
|
|
224
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
|
|
217
225
|
* @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
|
|
218
226
|
* @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
|
|
219
227
|
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
@@ -235,7 +243,7 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
235
243
|
* undefined if the document was not found.
|
|
236
244
|
*/
|
|
237
245
|
async update(id, input, options) {
|
|
238
|
-
const
|
|
246
|
+
const command = {
|
|
239
247
|
crud: 'update',
|
|
240
248
|
method: 'update',
|
|
241
249
|
documentId: id,
|
|
@@ -243,10 +251,11 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
243
251
|
input,
|
|
244
252
|
options,
|
|
245
253
|
};
|
|
246
|
-
return this.
|
|
247
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
return this._executeCommand(command, async () => {
|
|
255
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
256
|
+
command.options = { ...command.options, filter };
|
|
257
|
+
return this._update(command);
|
|
258
|
+
});
|
|
250
259
|
}
|
|
251
260
|
/**
|
|
252
261
|
* Updates a record in the collection with the specified ID and returns updated record count
|
|
@@ -257,7 +266,7 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
257
266
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
258
267
|
*/
|
|
259
268
|
async updateOnly(id, input, options) {
|
|
260
|
-
const
|
|
269
|
+
const command = {
|
|
261
270
|
crud: 'update',
|
|
262
271
|
method: 'update',
|
|
263
272
|
documentId: id,
|
|
@@ -265,10 +274,11 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
265
274
|
input,
|
|
266
275
|
options,
|
|
267
276
|
};
|
|
268
|
-
return this.
|
|
269
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
270
|
-
|
|
271
|
-
|
|
277
|
+
return this._executeCommand(command, async () => {
|
|
278
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
279
|
+
command.options = { ...command.options, filter };
|
|
280
|
+
return this._updateOnly(command);
|
|
281
|
+
});
|
|
272
282
|
}
|
|
273
283
|
/**
|
|
274
284
|
* Updates multiple records in the collection based on the specified input and options.
|
|
@@ -278,16 +288,17 @@ export class SqbCollectionService extends SqbEntityService {
|
|
|
278
288
|
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
279
289
|
*/
|
|
280
290
|
async updateMany(input, options) {
|
|
281
|
-
const
|
|
291
|
+
const command = {
|
|
282
292
|
crud: 'update',
|
|
283
293
|
method: 'updateMany',
|
|
284
294
|
byId: false,
|
|
285
295
|
input,
|
|
286
296
|
options,
|
|
287
297
|
};
|
|
288
|
-
return this.
|
|
289
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
290
|
-
|
|
291
|
-
|
|
298
|
+
return this._executeCommand(command, async () => {
|
|
299
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
300
|
+
command.options = { ...command.options, filter };
|
|
301
|
+
return this._updateMany(command);
|
|
302
|
+
});
|
|
292
303
|
}
|
|
293
304
|
}
|