@opra/sqb 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +5 -5
- package/cjs/augmentation/datatype-factory.augmentation.js +6 -2
- package/cjs/sqb-adapter.js +9 -4
- package/cjs/sqb-collection-service.js +71 -60
- package/cjs/sqb-entity-service.js +115 -101
- package/cjs/sqb-singleton-service.js +38 -31
- package/esm/adapter-utils/parse-filter.js +4 -4
- package/esm/augmentation/datatype-factory.augmentation.js +6 -2
- package/esm/sqb-adapter.js +9 -4
- package/esm/sqb-collection-service.js +71 -60
- package/esm/sqb-entity-service.js +115 -101
- package/esm/sqb-singleton-service.js +38 -31
- package/package.json +12 -8
- package/types/sqb-collection-service.d.ts +8 -8
- package/types/sqb-entity-service.d.ts +101 -87
- package/types/sqb-singleton-service.d.ts +5 -5
|
@@ -37,27 +37,29 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
37
37
|
* @throws {Error} if an unknown error occurs while creating the resource
|
|
38
38
|
*/
|
|
39
39
|
async create(input, options) {
|
|
40
|
-
const
|
|
40
|
+
const command = {
|
|
41
41
|
crud: 'create',
|
|
42
42
|
method: 'create',
|
|
43
43
|
byId: false,
|
|
44
44
|
input,
|
|
45
45
|
options,
|
|
46
46
|
};
|
|
47
|
-
return this.
|
|
47
|
+
return this._executeCommand(command, async () => {
|
|
48
48
|
const primaryFields = EntityMetadata.getPrimaryIndexColumns(this.entityMetadata);
|
|
49
|
-
const data = { ...input };
|
|
49
|
+
const data = { ...command.input };
|
|
50
50
|
if (primaryFields.length > 1) {
|
|
51
|
-
if (typeof primaryFields !== 'object')
|
|
51
|
+
if (typeof primaryFields !== 'object') {
|
|
52
52
|
throw new TypeError(`"${this.entityMetadata.name}" should has multiple primary key fields. So you should provide and object that contains key fields`);
|
|
53
|
+
}
|
|
53
54
|
for (const field of primaryFields) {
|
|
54
55
|
data[field.name] = this.id[field.name];
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
else
|
|
58
59
|
data[primaryFields[0].name] = this.id;
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
command.input = data;
|
|
61
|
+
return await this._create(command);
|
|
62
|
+
});
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
65
|
* Deletes the singleton record
|
|
@@ -66,17 +68,18 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
66
68
|
* @return {Promise<number>} - A Promise that resolves to the number of records deleted
|
|
67
69
|
*/
|
|
68
70
|
async delete(options) {
|
|
69
|
-
const
|
|
71
|
+
const command = {
|
|
70
72
|
crud: 'delete',
|
|
71
73
|
method: 'delete',
|
|
72
74
|
byId: true,
|
|
73
75
|
documentId: this.id,
|
|
74
76
|
options,
|
|
75
77
|
};
|
|
76
|
-
return this.
|
|
77
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return this._executeCommand(command, async () => {
|
|
79
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
80
|
+
command.options = { ...command.options, filter };
|
|
81
|
+
return this._delete(command);
|
|
82
|
+
});
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* Checks if the singleton record exists.
|
|
@@ -85,17 +88,18 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
85
88
|
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
86
89
|
*/
|
|
87
90
|
async exists(options) {
|
|
88
|
-
const
|
|
91
|
+
const command = {
|
|
89
92
|
crud: 'read',
|
|
90
93
|
method: 'exists',
|
|
91
94
|
byId: true,
|
|
92
95
|
documentId: this.id,
|
|
93
96
|
options,
|
|
94
97
|
};
|
|
95
|
-
return this.
|
|
96
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
return this._executeCommand(command, async () => {
|
|
99
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
100
|
+
command.options = { ...command.options, filter };
|
|
101
|
+
return this._exists(command);
|
|
102
|
+
});
|
|
99
103
|
}
|
|
100
104
|
/**
|
|
101
105
|
* Finds the singleton record. Returns `undefined` if not found
|
|
@@ -104,17 +108,18 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
104
108
|
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
105
109
|
*/
|
|
106
110
|
async find(options) {
|
|
107
|
-
const
|
|
111
|
+
const command = {
|
|
108
112
|
crud: 'read',
|
|
109
113
|
method: 'findById',
|
|
110
114
|
byId: true,
|
|
111
115
|
documentId: this.id,
|
|
112
116
|
options,
|
|
113
117
|
};
|
|
114
|
-
return this.
|
|
115
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
return this._executeCommand(command, async () => {
|
|
119
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
120
|
+
command.options = { ...command.options, filter };
|
|
121
|
+
return this._findById(command);
|
|
122
|
+
});
|
|
118
123
|
}
|
|
119
124
|
/**
|
|
120
125
|
* Retrieves the singleton record. Throws error if not found.
|
|
@@ -139,7 +144,7 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
139
144
|
* undefined if the document was not found.
|
|
140
145
|
*/
|
|
141
146
|
async update(input, options) {
|
|
142
|
-
const
|
|
147
|
+
const command = {
|
|
143
148
|
crud: 'update',
|
|
144
149
|
method: 'update',
|
|
145
150
|
documentId: this.id,
|
|
@@ -147,10 +152,11 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
147
152
|
input,
|
|
148
153
|
options,
|
|
149
154
|
};
|
|
150
|
-
return this.
|
|
151
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
return this._executeCommand(command, async () => {
|
|
156
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
157
|
+
command.options = { ...command.options, filter };
|
|
158
|
+
return this._update(command);
|
|
159
|
+
});
|
|
154
160
|
}
|
|
155
161
|
/**
|
|
156
162
|
* Updates the singleton and returns updated record count
|
|
@@ -160,7 +166,7 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
160
166
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
161
167
|
*/
|
|
162
168
|
async updateOnly(input, options) {
|
|
163
|
-
const
|
|
169
|
+
const command = {
|
|
164
170
|
crud: 'update',
|
|
165
171
|
method: 'update',
|
|
166
172
|
documentId: this.id,
|
|
@@ -168,9 +174,10 @@ export class SqbSingletonService extends SqbEntityService {
|
|
|
168
174
|
input,
|
|
169
175
|
options,
|
|
170
176
|
};
|
|
171
|
-
return this.
|
|
172
|
-
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
return this._executeCommand(command, async () => {
|
|
178
|
+
const filter = SQBAdapter.parseFilter([await this._getCommonFilter(command), command.options?.filter]);
|
|
179
|
+
command.options = { ...command.options, filter };
|
|
180
|
+
return this._updateOnly(command);
|
|
181
|
+
});
|
|
175
182
|
}
|
|
176
183
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,25 +17,29 @@
|
|
|
17
17
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
18
|
"postbuild": "cp README.md package.json ../../LICENSE ../../build/sqb && cp ../../package.cjs.json ../../build/sqb/cjs/package.json",
|
|
19
19
|
"lint": "eslint . --max-warnings=0",
|
|
20
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
20
21
|
"format": "prettier . --write --log-level=warn",
|
|
21
|
-
"test": "jest",
|
|
22
|
-
"cover": "jest --collect-coverage",
|
|
22
|
+
"test": "jest --passWithNoTests",
|
|
23
|
+
"cover": "jest --passWithNoTests --collect-coverage",
|
|
23
24
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
24
25
|
"clean:src": "ts-cleanup -s src --all",
|
|
25
26
|
"clean:test": "ts-cleanup -s test --all",
|
|
26
27
|
"clean:dist": "rimraf ../../build/client",
|
|
27
28
|
"clean:cover": "rimraf ../../coverage/client"
|
|
28
29
|
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"reflect-metadata": "^0.2.2"
|
|
32
|
+
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@faker-js/faker": "^8.4.1",
|
|
31
|
-
"@sqb/builder": "^4.12.
|
|
32
|
-
"@sqb/connect": "^4.12.
|
|
33
|
-
"@sqb/postgres": "^4.12.
|
|
34
|
-
"postgresql-client": "^2.
|
|
35
|
+
"@sqb/builder": "^4.12.1",
|
|
36
|
+
"@sqb/connect": "^4.12.1",
|
|
37
|
+
"@sqb/postgres": "^4.12.1",
|
|
38
|
+
"postgresql-client": "^2.12.0",
|
|
35
39
|
"ts-gems": "^3.4.0"
|
|
36
40
|
},
|
|
37
41
|
"peerDependencies": {
|
|
38
|
-
"@opra/core": "^1.0.0-alpha.
|
|
42
|
+
"@opra/core": "^1.0.0-alpha.21",
|
|
39
43
|
"@sqb/connect": ">= 4.10.6"
|
|
40
44
|
},
|
|
41
45
|
"type": "module",
|
|
@@ -7,7 +7,7 @@ import { SqbEntityService } from './sqb-entity-service.js';
|
|
|
7
7
|
export declare namespace SqbCollectionService {
|
|
8
8
|
interface Options extends SqbEntityService.Options {
|
|
9
9
|
defaultLimit?: SqbCollectionService<any>['defaultLimit'];
|
|
10
|
-
interceptor?: SqbCollectionService<any>['
|
|
10
|
+
interceptor?: SqbCollectionService<any>['interceptor'];
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Represents options for "create" operation
|
|
@@ -70,14 +70,14 @@ export declare namespace SqbCollectionService {
|
|
|
70
70
|
*
|
|
71
71
|
* @interface
|
|
72
72
|
*/
|
|
73
|
-
interface UpdateOptions extends SqbEntityService.
|
|
73
|
+
interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Represents options for "updateOnly" operation
|
|
77
77
|
*
|
|
78
78
|
* @interface
|
|
79
79
|
*/
|
|
80
|
-
interface UpdateOnlyOptions extends SqbEntityService.
|
|
80
|
+
interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Represents options for "updateMany" operation
|
|
@@ -163,11 +163,11 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
163
163
|
/**
|
|
164
164
|
* Finds a record by ID.
|
|
165
165
|
*
|
|
166
|
-
* @param {SQBAdapter.
|
|
166
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the record.
|
|
167
167
|
* @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
|
|
168
168
|
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
169
169
|
*/
|
|
170
|
-
findById(id: SQBAdapter.
|
|
170
|
+
findById(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
|
|
171
171
|
/**
|
|
172
172
|
* Finds a record in the collection that matches the specified options.
|
|
173
173
|
*
|
|
@@ -196,13 +196,13 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
196
196
|
/**
|
|
197
197
|
* Retrieves a records from the collection by its ID. Throws error if not found.
|
|
198
198
|
*
|
|
199
|
-
* @param {SQBAdapter.
|
|
199
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the document to retrieve.
|
|
200
200
|
* @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
|
|
201
201
|
* @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
|
|
202
202
|
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
203
203
|
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
204
204
|
*/
|
|
205
|
-
get(id: SQBAdapter.
|
|
205
|
+
get(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
|
|
206
206
|
/**
|
|
207
207
|
* Updates a record with the given id in the collection.
|
|
208
208
|
*
|
|
@@ -221,7 +221,7 @@ export declare abstract class SqbCollectionService<T extends object = object> ex
|
|
|
221
221
|
* @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
|
|
222
222
|
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
223
223
|
*/
|
|
224
|
-
updateOnly(id: SQBAdapter.
|
|
224
|
+
updateOnly(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
|
|
225
225
|
/**
|
|
226
226
|
* Updates multiple records in the collection based on the specified input and options.
|
|
227
227
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
2
|
-
import { IsObject } from 'valgen';
|
|
3
1
|
import { ComplexType } from '@opra/common';
|
|
4
2
|
import { ServiceBase } from '@opra/core';
|
|
5
3
|
import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
|
|
4
|
+
import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
|
|
5
|
+
import { IsObject } from 'valgen';
|
|
6
6
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
7
7
|
/**
|
|
8
8
|
* @namespace SqbEntityService
|
|
@@ -10,10 +10,10 @@ import { SQBAdapter } from './sqb-adapter.js';
|
|
|
10
10
|
export declare namespace SqbEntityService {
|
|
11
11
|
interface Options {
|
|
12
12
|
db?: SqbEntityService<any>['db'];
|
|
13
|
-
resourceName?: SqbEntityService<any>['
|
|
14
|
-
onError?: SqbEntityService<any>['
|
|
15
|
-
commonFilter?: SqbEntityService<any>['
|
|
16
|
-
interceptor?: SqbEntityService<any>['
|
|
13
|
+
resourceName?: SqbEntityService<any>['resourceName'];
|
|
14
|
+
onError?: SqbEntityService<any>['onError'];
|
|
15
|
+
commonFilter?: SqbEntityService<any>['commonFilter'];
|
|
16
|
+
interceptor?: SqbEntityService<any>['interceptor'];
|
|
17
17
|
}
|
|
18
18
|
type CrudOp = 'create' | 'read' | 'update' | 'delete';
|
|
19
19
|
interface CommandInfo {
|
|
@@ -85,14 +85,7 @@ export declare namespace SqbEntityService {
|
|
|
85
85
|
*
|
|
86
86
|
* @interface
|
|
87
87
|
*/
|
|
88
|
-
interface
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Represents options for "updateOnly" operation
|
|
92
|
-
*
|
|
93
|
-
* @interface
|
|
94
|
-
*/
|
|
95
|
-
interface UpdateOnlyOptions extends Repository.UpdateOptions {
|
|
88
|
+
interface UpdateOneOptions extends Repository.UpdateOptions {
|
|
96
89
|
}
|
|
97
90
|
/**
|
|
98
91
|
* Represents options for "updateMany" operation
|
|
@@ -101,6 +94,55 @@ export declare namespace SqbEntityService {
|
|
|
101
94
|
*/
|
|
102
95
|
interface UpdateManyOptions extends Repository.UpdateManyOptions {
|
|
103
96
|
}
|
|
97
|
+
interface CreateCommand extends StrictOmit<RequiredSome<CommandInfo, 'input'>, 'documentId'> {
|
|
98
|
+
crud: 'create';
|
|
99
|
+
options?: CreateOptions;
|
|
100
|
+
}
|
|
101
|
+
interface CountCommand extends StrictOmit<CommandInfo, 'documentId' | 'input'> {
|
|
102
|
+
crud: 'read';
|
|
103
|
+
options?: CountOptions;
|
|
104
|
+
}
|
|
105
|
+
interface DeleteOneCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
106
|
+
crud: 'delete';
|
|
107
|
+
options?: DeleteOptions;
|
|
108
|
+
}
|
|
109
|
+
interface DeleteManyCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
110
|
+
crud: 'delete';
|
|
111
|
+
options?: DeleteManyOptions;
|
|
112
|
+
}
|
|
113
|
+
interface ExistsCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
114
|
+
crud: 'read';
|
|
115
|
+
options?: ExistsOptions;
|
|
116
|
+
}
|
|
117
|
+
interface FindOneCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
118
|
+
crud: 'read';
|
|
119
|
+
options?: FindOneOptions;
|
|
120
|
+
}
|
|
121
|
+
interface FindManyCommand extends StrictOmit<CommandInfo, 'input'> {
|
|
122
|
+
crud: 'read';
|
|
123
|
+
options?: FindManyOptions;
|
|
124
|
+
}
|
|
125
|
+
interface UpdateOneCommand<T> extends CommandInfo {
|
|
126
|
+
crud: 'update';
|
|
127
|
+
input: PatchDTO<T>;
|
|
128
|
+
options?: UpdateOneOptions;
|
|
129
|
+
}
|
|
130
|
+
interface UpdateManyCommand<T> extends CommandInfo {
|
|
131
|
+
crud: 'update';
|
|
132
|
+
input: PatchDTO<T>;
|
|
133
|
+
options?: UpdateManyOptions;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export interface SqbEntityService {
|
|
137
|
+
/**
|
|
138
|
+
* Interceptor function for handling callback execution with provided arguments.
|
|
139
|
+
* @type Function
|
|
140
|
+
* @param next - The callback function to be intercepted.
|
|
141
|
+
* @param {SqbEntityService.CommandInfo} command - The arguments object containing the following properties:
|
|
142
|
+
* @param _this - The reference to the current object.
|
|
143
|
+
* @returns - The promise that resolves to the result of the callback execution.
|
|
144
|
+
*/
|
|
145
|
+
interceptor?(next: () => any, command: SqbEntityService.CommandInfo, _this: any): Promise<any>;
|
|
104
146
|
}
|
|
105
147
|
/**
|
|
106
148
|
* @class SqbEntityService
|
|
@@ -111,8 +153,8 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
111
153
|
protected _dataType: ComplexType;
|
|
112
154
|
protected _dataTypeClass?: Type;
|
|
113
155
|
protected _entityMetadata?: EntityMetadata;
|
|
114
|
-
protected
|
|
115
|
-
protected
|
|
156
|
+
protected _inputCodecs: Record<string, IsObject.Validator<T>>;
|
|
157
|
+
protected _outputCodecs: Record<string, IsObject.Validator<T>>;
|
|
116
158
|
/**
|
|
117
159
|
* Represents a SqbClient or SqbConnection object
|
|
118
160
|
*/
|
|
@@ -121,29 +163,20 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
121
163
|
* Represents the name of a resource.
|
|
122
164
|
* @type {string}
|
|
123
165
|
*/
|
|
124
|
-
|
|
166
|
+
resourceName?: string | ((_this: any) => string);
|
|
125
167
|
/**
|
|
126
168
|
* Represents a common filter function for a service.
|
|
127
169
|
*
|
|
128
170
|
* @type {SqbEntityService.Filter | Function}
|
|
129
171
|
*/
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Interceptor function for handling callback execution with provided arguments.
|
|
133
|
-
*
|
|
134
|
-
* @param {Function} callback - The callback function to be intercepted.
|
|
135
|
-
* @param {SqbEntityService.CommandInfo} info - The arguments object containing the following properties:
|
|
136
|
-
* @param {SqbEntityService} _this - The reference to the current object.
|
|
137
|
-
* @returns - The promise that resolves to the result of the callback execution.
|
|
138
|
-
*/
|
|
139
|
-
$interceptor?: (callback: () => any, info: SqbEntityService.CommandInfo, _this: any) => Promise<any>;
|
|
172
|
+
commonFilter?: SQBAdapter.FilterInput | ((args: SqbEntityService.CommandInfo, _this: this) => SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
|
|
140
173
|
/**
|
|
141
174
|
* Callback function for handling errors.
|
|
142
175
|
*
|
|
143
176
|
* @param {unknown} error - The error object.
|
|
144
177
|
* @param {SqbEntityService} _this - The context object.
|
|
145
178
|
*/
|
|
146
|
-
|
|
179
|
+
onError?: (error: unknown, _this: any) => void | Promise<void>;
|
|
147
180
|
/**
|
|
148
181
|
* Constructs a new instance
|
|
149
182
|
*
|
|
@@ -178,122 +211,110 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
178
211
|
*/
|
|
179
212
|
getResourceName(): string;
|
|
180
213
|
/**
|
|
181
|
-
* Retrieves the
|
|
214
|
+
* Retrieves the codec for the specified operation.
|
|
182
215
|
*
|
|
183
216
|
* @param operation - The operation to retrieve the encoder for. Valid values are 'create' and 'update'.
|
|
184
217
|
*/
|
|
185
|
-
|
|
218
|
+
getInputCodec(operation: string): IsObject.Validator<T>;
|
|
186
219
|
/**
|
|
187
|
-
* Retrieves the
|
|
220
|
+
* Retrieves the codec.
|
|
188
221
|
*/
|
|
189
|
-
|
|
222
|
+
getOutputCodec(operation: string): IsObject.Validator<T>;
|
|
190
223
|
/**
|
|
191
224
|
* Insert a new record into database
|
|
192
225
|
*
|
|
193
|
-
* @param
|
|
194
|
-
* @
|
|
195
|
-
* @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
|
|
196
|
-
* @throws {InternalServerError} if an unknown error occurs while creating the resource
|
|
226
|
+
* @param command
|
|
227
|
+
* @returns - A promise that resolves to the created resource
|
|
197
228
|
* @protected
|
|
198
229
|
*/
|
|
199
|
-
protected _create(
|
|
230
|
+
protected _create(command: SqbEntityService.CreateCommand): Promise<PartialDTO<T>>;
|
|
200
231
|
/**
|
|
201
232
|
* Returns the count of records based on the provided options
|
|
202
233
|
*
|
|
203
|
-
* @param
|
|
204
|
-
* @return
|
|
234
|
+
* @param command
|
|
235
|
+
* @return - A promise that resolves to the count of records
|
|
205
236
|
* @protected
|
|
206
237
|
*/
|
|
207
|
-
protected _count(
|
|
238
|
+
protected _count(command: SqbEntityService.CountCommand): Promise<number>;
|
|
208
239
|
/**
|
|
209
240
|
* Deletes a record from the collection.
|
|
210
241
|
*
|
|
211
|
-
* @param
|
|
212
|
-
* @
|
|
213
|
-
* @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
|
|
242
|
+
* @param command
|
|
243
|
+
* @return - A Promise that resolves to the number of documents deleted.
|
|
214
244
|
* @protected
|
|
215
245
|
*/
|
|
216
|
-
protected _delete(
|
|
246
|
+
protected _delete(command: SqbEntityService.DeleteOneCommand): Promise<number>;
|
|
217
247
|
/**
|
|
218
248
|
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
219
249
|
*
|
|
220
|
-
* @param
|
|
221
|
-
* @return
|
|
250
|
+
* @param command
|
|
251
|
+
* @return - A promise that resolves to the number of documents deleted.
|
|
222
252
|
* @protected
|
|
223
253
|
*/
|
|
224
|
-
protected _deleteMany(
|
|
254
|
+
protected _deleteMany(command: SqbEntityService.DeleteManyCommand): Promise<number>;
|
|
225
255
|
/**
|
|
226
256
|
* Checks if a record with the given id exists.
|
|
227
257
|
*
|
|
228
|
-
* @param
|
|
229
|
-
* @param {SqbEntityService.ExistsOptions} [options] - The options for the query (optional).
|
|
230
|
-
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
258
|
+
* @param command
|
|
231
259
|
* @protected
|
|
232
260
|
*/
|
|
233
|
-
protected _exists(
|
|
261
|
+
protected _exists(command: SqbEntityService.ExistsCommand): Promise<boolean>;
|
|
234
262
|
/**
|
|
235
263
|
* Checks if a record with the given arguments exists.
|
|
236
264
|
*
|
|
237
|
-
* @param
|
|
238
|
-
* @return
|
|
265
|
+
* @param command
|
|
266
|
+
* @return - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
239
267
|
* @protected
|
|
240
268
|
*/
|
|
241
|
-
protected _existsOne(
|
|
269
|
+
protected _existsOne(command: SqbEntityService.ExistsCommand): Promise<boolean>;
|
|
242
270
|
/**
|
|
243
271
|
* Finds a record by ID.
|
|
244
272
|
*
|
|
245
|
-
* @param
|
|
246
|
-
* @
|
|
247
|
-
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
273
|
+
* @param command
|
|
274
|
+
* @return - A promise resolving to the found document, or undefined if not found.
|
|
248
275
|
* @protected
|
|
249
276
|
*/
|
|
250
|
-
protected _findById(
|
|
277
|
+
protected _findById(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
|
|
251
278
|
/**
|
|
252
279
|
* Finds a record in the collection that matches the specified options.
|
|
253
280
|
*
|
|
254
|
-
* @param
|
|
255
|
-
* @return
|
|
281
|
+
* @param command
|
|
282
|
+
* @return - A promise that resolves with the found document or undefined if no document is found.
|
|
256
283
|
* @protected
|
|
257
284
|
*/
|
|
258
|
-
protected _findOne(
|
|
285
|
+
protected _findOne(command: SqbEntityService.FindOneCommand): Promise<PartialDTO<T> | undefined>;
|
|
259
286
|
/**
|
|
260
287
|
* Finds multiple records in collection.
|
|
261
288
|
*
|
|
262
|
-
* @param
|
|
263
|
-
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
289
|
+
* @param command
|
|
290
|
+
* @return - A Promise that resolves to an array of partial outputs of type T.
|
|
264
291
|
* @protected
|
|
265
292
|
*/
|
|
266
|
-
protected _findMany(
|
|
293
|
+
protected _findMany(command: SqbEntityService.FindManyCommand): Promise<PartialDTO<T>[]>;
|
|
267
294
|
/**
|
|
268
295
|
* Updates a record with the given id in the collection.
|
|
269
296
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @
|
|
272
|
-
* @param {SqbEntityService.UpdateOptions} [options] - The options for the update operation.
|
|
273
|
-
* @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
|
|
274
|
-
* undefined if the document was not found.
|
|
297
|
+
* @param command
|
|
298
|
+
* @returns A promise that resolves to the updated document or undefined if the document was not found.
|
|
275
299
|
* @protected
|
|
276
300
|
*/
|
|
277
|
-
protected _update(
|
|
301
|
+
protected _update(command: SqbEntityService.UpdateOneCommand<T>): Promise<PartialDTO<T> | undefined>;
|
|
278
302
|
/**
|
|
279
303
|
* Updates a record in the collection with the specified ID and returns updated record count
|
|
280
304
|
*
|
|
281
|
-
* @param
|
|
282
|
-
* @
|
|
283
|
-
* @param {SqbEntityService.UpdateOptions} options - The options for updating the document.
|
|
284
|
-
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
305
|
+
* @param command
|
|
306
|
+
* @returns - A promise that resolves to the number of documents modified.
|
|
285
307
|
* @protected
|
|
286
308
|
*/
|
|
287
|
-
protected _updateOnly(
|
|
309
|
+
protected _updateOnly(command: SqbEntityService.UpdateOneCommand<T>): Promise<boolean>;
|
|
288
310
|
/**
|
|
289
311
|
* Updates multiple records in the collection based on the specified input and options.
|
|
290
312
|
*
|
|
291
|
-
* @param
|
|
292
|
-
* @
|
|
293
|
-
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
313
|
+
* @param command
|
|
314
|
+
* @return - A promise that resolves to the number of documents matched and modified.
|
|
294
315
|
* @protected
|
|
295
316
|
*/
|
|
296
|
-
protected _updateMany(
|
|
317
|
+
protected _updateMany(command: SqbEntityService.UpdateOneCommand<T>): Promise<number>;
|
|
297
318
|
/**
|
|
298
319
|
* Acquires a connection and performs Repository.create operation
|
|
299
320
|
*
|
|
@@ -411,12 +432,5 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
411
432
|
input?: Object;
|
|
412
433
|
options?: Record<string, any>;
|
|
413
434
|
}): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
|
|
414
|
-
protected
|
|
415
|
-
crud: SqbEntityService.CrudOp;
|
|
416
|
-
method: string;
|
|
417
|
-
byId: boolean;
|
|
418
|
-
documentId?: any;
|
|
419
|
-
input?: Object;
|
|
420
|
-
options?: Record<string, any>;
|
|
421
|
-
}): Promise<any>;
|
|
435
|
+
protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
|
|
422
436
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
2
1
|
import { ColumnFieldMetadata } from '@sqb/connect';
|
|
2
|
+
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
3
3
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
4
4
|
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
5
|
/**
|
|
@@ -42,14 +42,14 @@ export declare namespace SqbSingletonService {
|
|
|
42
42
|
*
|
|
43
43
|
* @interface
|
|
44
44
|
*/
|
|
45
|
-
interface UpdateOptions extends SqbEntityService.
|
|
45
|
+
interface UpdateOptions extends SqbEntityService.UpdateOneOptions {
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Represents options for "updateOnly" operation
|
|
49
49
|
*
|
|
50
50
|
* @interface
|
|
51
51
|
*/
|
|
52
|
-
interface UpdateOnlyOptions extends SqbEntityService.
|
|
52
|
+
interface UpdateOnlyOptions extends SqbEntityService.UpdateOneOptions {
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -60,9 +60,9 @@ export declare abstract class SqbSingletonService<T extends object = object> ext
|
|
|
60
60
|
protected _primaryKeyFields?: ColumnFieldMetadata[];
|
|
61
61
|
/**
|
|
62
62
|
* Represents a unique identifier for singleton record
|
|
63
|
-
* @property {SQBAdapter.
|
|
63
|
+
* @property {SQBAdapter.IdOrIds}
|
|
64
64
|
*/
|
|
65
|
-
id: SQBAdapter.
|
|
65
|
+
id: SQBAdapter.IdOrIds;
|
|
66
66
|
/**
|
|
67
67
|
* Constructs a new instance
|
|
68
68
|
*
|