@opra/sqb 0.33.13 → 1.0.0-alpha.2
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/{transform-filter.js → adapter-utils/parse-filter.js} +37 -12
- package/cjs/augmentation/datatype-factory.augmentation.js +75 -0
- package/cjs/augmentation/mixin-type.augmentation.js +5 -3
- package/cjs/index.js +3 -4
- package/cjs/sqb-adapter.js +66 -100
- package/cjs/sqb-collection-service.js +297 -0
- package/cjs/sqb-entity-service.js +444 -25
- package/cjs/sqb-singleton-service.js +180 -0
- package/esm/{transform-filter.js → adapter-utils/parse-filter.js} +36 -11
- package/esm/augmentation/datatype-factory.augmentation.js +73 -0
- package/esm/augmentation/mapped-type.augmentation.js +1 -1
- package/esm/augmentation/mixin-type.augmentation.js +6 -4
- package/esm/index.js +3 -4
- package/esm/sqb-adapter.js +66 -100
- package/esm/sqb-collection-service.js +293 -0
- package/esm/sqb-entity-service.js +444 -25
- package/esm/sqb-singleton-service.js +176 -0
- package/package.json +10 -9
- package/types/adapter-utils/parse-filter.d.ts +10 -0
- package/types/index.d.ts +3 -4
- package/types/sqb-adapter.d.ts +10 -8
- package/types/sqb-collection-service.d.ts +233 -0
- package/types/sqb-entity-service.d.ts +418 -18
- package/types/sqb-singleton-service.d.ts +137 -0
- package/cjs/augmentation/api-document-factory.augmentation.js +0 -20
- package/cjs/augmentation/type-document-factory.augmentation.js +0 -99
- package/cjs/sqb-collection.js +0 -80
- package/cjs/sqb-entity-service-base.js +0 -170
- package/cjs/sqb-singleton.js +0 -44
- package/cjs/transform-key-values.js +0 -14
- package/esm/augmentation/api-document-factory.augmentation.js +0 -18
- package/esm/augmentation/type-document-factory.augmentation.js +0 -97
- package/esm/sqb-collection.js +0 -76
- package/esm/sqb-entity-service-base.js +0 -166
- package/esm/sqb-singleton.js +0 -40
- package/esm/transform-key-values.js +0 -11
- package/types/augmentation/type-document-factory.augmentation.d.ts +0 -1
- package/types/sqb-collection.d.ts +0 -31
- package/types/sqb-entity-service-base.d.ts +0 -31
- package/types/sqb-singleton.d.ts +0 -18
- package/types/transform-filter.d.ts +0 -3
- package/types/transform-key-values.d.ts +0 -3
- /package/types/augmentation/{api-document-factory.augmentation.d.ts → datatype-factory.augmentation.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,7 @@
|
|
|
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
|
+
"format": "prettier . --write --log-level=warn",
|
|
20
21
|
"test": "jest",
|
|
21
22
|
"cover": "jest --collect-coverage",
|
|
22
23
|
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
@@ -26,15 +27,15 @@
|
|
|
26
27
|
"clean:cover": "rimraf ../../coverage/client"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
|
-
"@faker-js/faker": "^8.4.
|
|
30
|
-
"@sqb/builder": "^4.
|
|
31
|
-
"@sqb/connect": "^4.
|
|
32
|
-
"@sqb/postgres": "^4.
|
|
33
|
-
"postgresql-client": "^2.
|
|
34
|
-
"ts-gems": "^3.
|
|
30
|
+
"@faker-js/faker": "^8.4.1",
|
|
31
|
+
"@sqb/builder": "^4.12.0",
|
|
32
|
+
"@sqb/connect": "^4.12.0",
|
|
33
|
+
"@sqb/postgres": "^4.12.0",
|
|
34
|
+
"postgresql-client": "^2.11.0",
|
|
35
|
+
"ts-gems": "^3.4.0"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
|
-
"@opra/core": "^0.
|
|
38
|
+
"@opra/core": "^1.0.0-alpha.2",
|
|
38
39
|
"@sqb/connect": ">= 4.10.6"
|
|
39
40
|
},
|
|
40
41
|
"type": "module",
|
|
@@ -58,4 +59,4 @@
|
|
|
58
59
|
"sqb",
|
|
59
60
|
"adapter"
|
|
60
61
|
]
|
|
61
|
-
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import '@opra/core';
|
|
2
|
+
import type { SQBAdapter } from '../sqb-adapter.js';
|
|
3
|
+
/**
|
|
4
|
+
* Prepare the SQB filter based on the provided filters and options.
|
|
5
|
+
*
|
|
6
|
+
* @param {SQBAdapter.FilterInput|SQBAdapter.FilterInput[]} filters - The filter(s) to be applied.
|
|
7
|
+
*
|
|
8
|
+
* @returns {Expression} - The prepared SQB Expression.
|
|
9
|
+
*/
|
|
10
|
+
export default function parseFilter(filters: SQBAdapter.FilterInput | SQBAdapter.FilterInput[]): any;
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import './augmentation/
|
|
2
|
-
import './augmentation/api-document-factory.augmentation.js';
|
|
1
|
+
import './augmentation/datatype-factory.augmentation.js';
|
|
3
2
|
import './augmentation/mapped-type.augmentation.js';
|
|
4
3
|
import './augmentation/mixin-type.augmentation.js';
|
|
5
4
|
export * from './sqb-adapter.js';
|
|
6
|
-
export * from './sqb-collection.js';
|
|
5
|
+
export * from './sqb-collection-service.js';
|
|
7
6
|
export * from './sqb-entity-service.js';
|
|
8
|
-
export * from './sqb-singleton.js';
|
|
7
|
+
export * from './sqb-singleton-service.js';
|
package/types/sqb-adapter.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import type { OpraFilter } from '@opra/common';
|
|
2
|
+
import type { HttpContext } from '@opra/core';
|
|
3
|
+
import { type Repository } from '@sqb/connect';
|
|
4
|
+
import _parseFilter from './adapter-utils/parse-filter.js';
|
|
4
5
|
export declare namespace SQBAdapter {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
type Id = string | number | boolean | Date;
|
|
7
|
+
type IdOrIds = Id | Record<string, Id>;
|
|
8
|
+
type FilterInput = OpraFilter.Expression | Repository.FindManyOptions['filter'] | string | undefined;
|
|
9
|
+
const parseFilter: typeof _parseFilter;
|
|
7
10
|
interface TransformedRequest {
|
|
8
|
-
method: 'create' | 'delete' | 'deleteMany' | '
|
|
11
|
+
method: 'create' | 'delete' | 'deleteMany' | 'get' | 'findMany' | 'update' | 'updateMany';
|
|
9
12
|
key?: any;
|
|
10
13
|
data?: any;
|
|
11
14
|
options: any;
|
|
12
|
-
args: any[];
|
|
13
15
|
}
|
|
14
|
-
function
|
|
16
|
+
function parseRequest(context: HttpContext): Promise<TransformedRequest>;
|
|
15
17
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { PartialDTO, PatchDTO, Type } from 'ts-gems';
|
|
2
|
+
import { SQBAdapter } from './sqb-adapter.js';
|
|
3
|
+
import { SqbEntityService } from './sqb-entity-service.js';
|
|
4
|
+
/**
|
|
5
|
+
* @namespace SqbCollectionService
|
|
6
|
+
*/
|
|
7
|
+
export declare namespace SqbCollectionService {
|
|
8
|
+
interface Options extends SqbEntityService.Options {
|
|
9
|
+
defaultLimit?: SqbCollectionService<any>['defaultLimit'];
|
|
10
|
+
interceptor?: SqbCollectionService<any>['$interceptor'];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Represents options for "create" operation
|
|
14
|
+
*
|
|
15
|
+
* @interface
|
|
16
|
+
*/
|
|
17
|
+
interface CreateOptions extends SqbEntityService.CreateOptions {
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents options for "count" operation
|
|
21
|
+
*
|
|
22
|
+
* @interface
|
|
23
|
+
*/
|
|
24
|
+
interface CountOptions extends SqbEntityService.CountOptions {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Represents options for "delete" operation
|
|
28
|
+
*
|
|
29
|
+
* @interface
|
|
30
|
+
*/
|
|
31
|
+
interface DeleteOptions extends SqbEntityService.DeleteOptions {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents options for "deleteMany" operation
|
|
35
|
+
*
|
|
36
|
+
* @interface
|
|
37
|
+
*/
|
|
38
|
+
interface DeleteManyOptions extends SqbEntityService.DeleteManyOptions {
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents options for "exists" operation
|
|
42
|
+
*
|
|
43
|
+
* @interface
|
|
44
|
+
*/
|
|
45
|
+
interface ExistsOptions extends SqbEntityService.ExistsOptions {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Represents options for "existsOne" operation
|
|
49
|
+
*
|
|
50
|
+
* @interface
|
|
51
|
+
*/
|
|
52
|
+
interface ExistsOneOptions extends SqbEntityService.ExistsOptions {
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Represents options for "findOne" operation
|
|
56
|
+
*
|
|
57
|
+
* @interface
|
|
58
|
+
*/
|
|
59
|
+
interface FindOneOptions extends SqbEntityService.FindOneOptions {
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Represents options for "findMany" operation
|
|
63
|
+
*
|
|
64
|
+
* @interface
|
|
65
|
+
*/
|
|
66
|
+
interface FindManyOptions extends SqbEntityService.FindManyOptions {
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Represents options for "update" operation
|
|
70
|
+
*
|
|
71
|
+
* @interface
|
|
72
|
+
*/
|
|
73
|
+
interface UpdateOptions extends SqbEntityService.UpdateOptions {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Represents options for "updateOnly" operation
|
|
77
|
+
*
|
|
78
|
+
* @interface
|
|
79
|
+
*/
|
|
80
|
+
interface UpdateOnlyOptions extends SqbEntityService.UpdateOptions {
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Represents options for "updateMany" operation
|
|
84
|
+
*
|
|
85
|
+
* @interface
|
|
86
|
+
*/
|
|
87
|
+
interface UpdateManyOptions extends SqbEntityService.UpdateManyOptions {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @class SqbCollectionService
|
|
92
|
+
* @template T - The data type class type of the resource
|
|
93
|
+
*/
|
|
94
|
+
export declare abstract class SqbCollectionService<T extends object = object> extends SqbEntityService {
|
|
95
|
+
/**
|
|
96
|
+
* Represents default limit for findMany operation
|
|
97
|
+
*/
|
|
98
|
+
defaultLimit: number;
|
|
99
|
+
/**
|
|
100
|
+
* Constructs a new instance
|
|
101
|
+
*
|
|
102
|
+
* @param {Type | string} dataType - The data type of the array elements.
|
|
103
|
+
* @param {SqbCollectionService.Options} [options] - The options for the array service.
|
|
104
|
+
* @constructor
|
|
105
|
+
*/
|
|
106
|
+
constructor(dataType: Type<T> | string, options?: SqbCollectionService.Options);
|
|
107
|
+
/**
|
|
108
|
+
* Asserts the existence of a resource with the given ID.
|
|
109
|
+
* Throws a ResourceNotFoundError if the resource does not exist.
|
|
110
|
+
*
|
|
111
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the resource to assert.
|
|
112
|
+
* @param {SqbCollectionService.ExistsOptions} [options] - Optional options for checking the existence.
|
|
113
|
+
* @returns {Promise<void>} - A Promise that resolves when the resource exists.
|
|
114
|
+
* @throws {ResourceNotAvailableError} - If the resource does not exist.
|
|
115
|
+
*/
|
|
116
|
+
assert(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.ExistsOptions): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new resource
|
|
119
|
+
*
|
|
120
|
+
* @param {PartialDTO<T>} input - The input data
|
|
121
|
+
* @param {SqbCollectionService.CreateOptions} [options] - The options object
|
|
122
|
+
* @returns {Promise<PartialDTO<T>>} A promise that resolves to the created resource
|
|
123
|
+
* @throws {Error} if an unknown error occurs while creating the resource
|
|
124
|
+
*/
|
|
125
|
+
create(input: PartialDTO<T>, options?: SqbCollectionService.CreateOptions): Promise<PartialDTO<T>>;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the count of records based on the provided options
|
|
128
|
+
*
|
|
129
|
+
* @param {SqbCollectionService.CountOptions} options - The options for the count operation.
|
|
130
|
+
* @return {Promise<number>} - A promise that resolves to the count of records
|
|
131
|
+
*/
|
|
132
|
+
count(options?: SqbCollectionService.CountOptions): Promise<number>;
|
|
133
|
+
/**
|
|
134
|
+
* Deletes a record from the collection.
|
|
135
|
+
*
|
|
136
|
+
* @param {SQBAdapter.IdOrIds} id - The ID of the document to delete.
|
|
137
|
+
* @param {SqbCollectionService.DeleteOptions} [options] - Optional delete options.
|
|
138
|
+
* @return {Promise<number>} - A Promise that resolves to the number of documents deleted.
|
|
139
|
+
*/
|
|
140
|
+
delete(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.DeleteOptions): Promise<number>;
|
|
141
|
+
/**
|
|
142
|
+
* Deletes multiple documents from the collection that meet the specified filter criteria.
|
|
143
|
+
*
|
|
144
|
+
* @param {SqbCollectionService.DeleteManyOptions} options - The options for the delete operation.
|
|
145
|
+
* @return {Promise<number>} - A promise that resolves to the number of documents deleted.
|
|
146
|
+
*/
|
|
147
|
+
deleteMany(options?: SqbCollectionService.DeleteManyOptions): Promise<number>;
|
|
148
|
+
/**
|
|
149
|
+
* Checks if a record with the given id exists.
|
|
150
|
+
*
|
|
151
|
+
* @param {SQBAdapter.IdOrIds} id - The id of the object to check.
|
|
152
|
+
* @param {SqbCollectionService.ExistsOptions} [options] - The options for the query (optional).
|
|
153
|
+
* @return {Promise<boolean>} - A Promise that resolves to a boolean indicating whether the record exists or not.
|
|
154
|
+
*/
|
|
155
|
+
exists(id: SQBAdapter.IdOrIds, options?: SqbCollectionService.ExistsOptions): Promise<boolean>;
|
|
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
|
+
existsOne(options?: SqbCollectionService.ExistsOneOptions): Promise<boolean>;
|
|
163
|
+
/**
|
|
164
|
+
* Finds a record by ID.
|
|
165
|
+
*
|
|
166
|
+
* @param {SQBAdapter.Id} id - The ID of the record.
|
|
167
|
+
* @param {SqbCollectionService.FindOneOptions} [options] - The options for the find query.
|
|
168
|
+
* @return {Promise<PartialDTO<T | undefined>>} - A promise resolving to the found document, or undefined if not found.
|
|
169
|
+
*/
|
|
170
|
+
findById(id: SQBAdapter.Id, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
|
|
171
|
+
/**
|
|
172
|
+
* Finds a record in the collection that matches the specified options.
|
|
173
|
+
*
|
|
174
|
+
* @param {SqbCollectionService.FindOneOptions} options - The options for the query.
|
|
175
|
+
* @return {Promise<PartialDTO<T> | undefined>} A promise that resolves with the found document or undefined if no document is found.
|
|
176
|
+
*/
|
|
177
|
+
findOne(options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T> | undefined>;
|
|
178
|
+
/**
|
|
179
|
+
* Finds multiple records in collection.
|
|
180
|
+
*
|
|
181
|
+
* @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
|
|
182
|
+
* @return A Promise that resolves to an array of partial outputs of type T.
|
|
183
|
+
*/
|
|
184
|
+
findMany(options?: SqbCollectionService.FindManyOptions): Promise<PartialDTO<T>[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Finds multiple records in the collection and returns both records (max limit)
|
|
187
|
+
* and total count that matched the given criteria
|
|
188
|
+
*
|
|
189
|
+
* @param {SqbCollectionService.FindManyOptions} options - The options for the find operation.
|
|
190
|
+
* @return A Promise that resolves to an array of partial outputs of type T and total count.
|
|
191
|
+
*/
|
|
192
|
+
findManyWithCount(options?: SqbCollectionService.FindManyOptions): Promise<{
|
|
193
|
+
count: number;
|
|
194
|
+
items: PartialDTO<T>[];
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* Retrieves a records from the collection by its ID. Throws error if not found.
|
|
198
|
+
*
|
|
199
|
+
* @param {SQBAdapter.Id} id - The ID of the document to retrieve.
|
|
200
|
+
* @param {SqbCollectionService.FindOneOptions} [options] - Optional options for the findOne operation.
|
|
201
|
+
* @returns {Promise<PartialDTO<T>>} - A promise that resolves to the retrieved document,
|
|
202
|
+
* or rejects with a ResourceNotFoundError if the document does not exist.
|
|
203
|
+
* @throws {ResourceNotAvailableError} - If the document with the specified ID does not exist.
|
|
204
|
+
*/
|
|
205
|
+
get(id: SQBAdapter.Id, options?: SqbCollectionService.FindOneOptions): Promise<PartialDTO<T>>;
|
|
206
|
+
/**
|
|
207
|
+
* Updates a record with the given id in the collection.
|
|
208
|
+
*
|
|
209
|
+
* @param {SQBAdapter.IdOrIds} id - The id of the document to update.
|
|
210
|
+
* @param {PatchDTO<T>} input - The partial input object containing the fields to update.
|
|
211
|
+
* @param {SqbCollectionService.UpdateOptions} [options] - The options for the update operation.
|
|
212
|
+
* @returns {Promise<PartialDTO<T> | undefined>} A promise that resolves to the updated document or
|
|
213
|
+
* undefined if the document was not found.
|
|
214
|
+
*/
|
|
215
|
+
update(id: SQBAdapter.IdOrIds, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOptions): Promise<PartialDTO<T> | undefined>;
|
|
216
|
+
/**
|
|
217
|
+
* Updates a record in the collection with the specified ID and returns updated record count
|
|
218
|
+
*
|
|
219
|
+
* @param {any} id - The ID of the document to update.
|
|
220
|
+
* @param {PatchDTO<T>} input - The partial input data to update the document with.
|
|
221
|
+
* @param {SqbCollectionService.UpdateOptions} options - The options for updating the document.
|
|
222
|
+
* @returns {Promise<number>} - A promise that resolves to the number of documents modified.
|
|
223
|
+
*/
|
|
224
|
+
updateOnly(id: SQBAdapter.Id, input: PatchDTO<T>, options?: SqbCollectionService.UpdateOnlyOptions): Promise<number>;
|
|
225
|
+
/**
|
|
226
|
+
* Updates multiple records in the collection based on the specified input and options.
|
|
227
|
+
*
|
|
228
|
+
* @param {PatchDTO<T>} input - The partial input to update the documents with.
|
|
229
|
+
* @param {SqbCollectionService.UpdateManyOptions} options - The options for updating the documents.
|
|
230
|
+
* @return {Promise<number>} - A promise that resolves to the number of documents matched and modified.
|
|
231
|
+
*/
|
|
232
|
+
updateMany(input: PatchDTO<T>, options?: SqbCollectionService.UpdateManyOptions): Promise<number>;
|
|
233
|
+
}
|