@avytrix/nestjs-drizzle-crud 0.0.0-stage → 3.6.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.
- package/AGENT.md +513 -0
- package/AGENTS.template.md +31 -0
- package/CHANGELOG.md +565 -0
- package/CLAUDE.template.md +18 -0
- package/LICENSE +21 -0
- package/README.md +1307 -2
- package/dist/controller/crud-controller.factory.d.ts +28 -0
- package/dist/controller/crud-controller.factory.js +279 -0
- package/dist/controller/crud-controller.factory.js.map +1 -0
- package/dist/core/abstract/sql-base-crud.service.d.ts +230 -0
- package/dist/core/abstract/sql-base-crud.service.js +2899 -0
- package/dist/core/abstract/sql-base-crud.service.js.map +1 -0
- package/dist/core/context/crud-context.d.ts +6 -0
- package/dist/core/context/crud-context.js +27 -0
- package/dist/core/context/crud-context.js.map +1 -0
- package/dist/core/events/crud-event-bus.d.ts +7 -0
- package/dist/core/events/crud-event-bus.js +30 -0
- package/dist/core/events/crud-event-bus.js.map +1 -0
- package/dist/core/interfaces/crud-service.interface.d.ts +54 -0
- package/dist/core/interfaces/crud-service.interface.js +3 -0
- package/dist/core/interfaces/crud-service.interface.js.map +1 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.d.ts +39 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.js +3 -0
- package/dist/core/interfaces/drizzle-crud-config.interface.js.map +1 -0
- package/dist/core/interfaces/events.interface.d.ts +39 -0
- package/dist/core/interfaces/events.interface.js +3 -0
- package/dist/core/interfaces/events.interface.js.map +1 -0
- package/dist/core/interfaces/query.interface.d.ts +112 -0
- package/dist/core/interfaces/query.interface.js +3 -0
- package/dist/core/interfaces/query.interface.js.map +1 -0
- package/dist/core/interfaces/scope.interface.d.ts +3 -0
- package/dist/core/interfaces/scope.interface.js +3 -0
- package/dist/core/interfaces/scope.interface.js.map +1 -0
- package/dist/core/interfaces/sql-crud-config.interface.d.ts +87 -0
- package/dist/core/interfaces/sql-crud-config.interface.js +3 -0
- package/dist/core/interfaces/sql-crud-config.interface.js.map +1 -0
- package/dist/core/types/sql.types.d.ts +7 -0
- package/dist/core/types/sql.types.js +3 -0
- package/dist/core/types/sql.types.js.map +1 -0
- package/dist/core/utils/cursor.d.ts +2 -0
- package/dist/core/utils/cursor.js +44 -0
- package/dist/core/utils/cursor.js.map +1 -0
- package/dist/core/utils/merge-config.d.ts +2 -0
- package/dist/core/utils/merge-config.js +22 -0
- package/dist/core/utils/merge-config.js.map +1 -0
- package/dist/core/utils/query-parser.d.ts +4 -0
- package/dist/core/utils/query-parser.js +538 -0
- package/dist/core/utils/query-parser.js.map +1 -0
- package/dist/decorators/crud-service.decorator.d.ts +4 -0
- package/dist/decorators/crud-service.decorator.js +10 -0
- package/dist/decorators/crud-service.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +1 -0
- package/dist/decorators/index.js +6 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/exceptions/crud.exceptions.d.ts +46 -0
- package/dist/exceptions/crud.exceptions.js +93 -0
- package/dist/exceptions/crud.exceptions.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +8 -0
- package/dist/mcp/server.js +236 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/modules/drizzle-connection.d.ts +12 -0
- package/dist/modules/drizzle-connection.js +73 -0
- package/dist/modules/drizzle-connection.js.map +1 -0
- package/dist/modules/drizzle-crud.module.d.ts +11 -0
- package/dist/modules/drizzle-crud.module.js +165 -0
- package/dist/modules/drizzle-crud.module.js.map +1 -0
- package/dist/openapi/api-crud.decorators.d.ts +10 -0
- package/dist/openapi/api-crud.decorators.js +216 -0
- package/dist/openapi/api-crud.decorators.js.map +1 -0
- package/dist/test-utils/base-crud.spec-helper.d.ts +64 -0
- package/dist/test-utils/base-crud.spec-helper.js +119 -0
- package/dist/test-utils/base-crud.spec-helper.js.map +1 -0
- package/dist/test-utils/index.d.ts +2 -0
- package/dist/test-utils/index.js +8 -0
- package/dist/test-utils/index.js.map +1 -0
- package/dist/test-utils/test-factory.d.ts +29 -0
- package/dist/test-utils/test-factory.js +81 -0
- package/dist/test-utils/test-factory.js.map +1 -0
- package/package.json +110 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Type, type ValidationPipeOptions } from "@nestjs/common";
|
|
2
|
+
import type { SqlBaseCrudService } from "../core/abstract/sql-base-crud.service";
|
|
3
|
+
import type { ParseCrudQueryOptions } from "../core/interfaces/query.interface";
|
|
4
|
+
import { type ApiCrudSource } from "../openapi/api-crud.decorators";
|
|
5
|
+
export type CrudRouteName = "list" | "trash" | "get" | "create" | "update" | "delete" | "softDelete" | "restore" | "bulkCreate" | "bulkUpdate" | "bulkDelete" | "bulkRestore";
|
|
6
|
+
export interface CrudRouteOptions {
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
decorators?: MethodDecorator[];
|
|
9
|
+
}
|
|
10
|
+
export interface CrudControllerOptions {
|
|
11
|
+
path?: string;
|
|
12
|
+
idType?: "int" | "uuid" | "string";
|
|
13
|
+
dto?: {
|
|
14
|
+
create?: Type<unknown>;
|
|
15
|
+
update?: Type<unknown>;
|
|
16
|
+
};
|
|
17
|
+
validation?: ValidationPipeOptions;
|
|
18
|
+
query?: ParseCrudQueryOptions;
|
|
19
|
+
routes?: Partial<Record<CrudRouteName, boolean | CrudRouteOptions>>;
|
|
20
|
+
decorators?: MethodDecorator[];
|
|
21
|
+
classDecorators?: ClassDecorator[];
|
|
22
|
+
deleteMode?: "hard" | "soft";
|
|
23
|
+
openapi?: true | ApiCrudSource;
|
|
24
|
+
}
|
|
25
|
+
export interface CrudControllerInstance<S> {
|
|
26
|
+
readonly service: S;
|
|
27
|
+
}
|
|
28
|
+
export declare function createCrudController<S extends SqlBaseCrudService<any, any, any, any>>(service: Type<S>, options?: CrudControllerOptions): Type<CrudControllerInstance<S>>;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCrudController = createCrudController;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const crud_exceptions_1 = require("../exceptions/crud.exceptions");
|
|
6
|
+
const api_crud_decorators_1 = require("../openapi/api-crud.decorators");
|
|
7
|
+
const BULK_ROUTES = new Set([
|
|
8
|
+
"bulkCreate",
|
|
9
|
+
"bulkUpdate",
|
|
10
|
+
"bulkDelete",
|
|
11
|
+
"bulkRestore",
|
|
12
|
+
]);
|
|
13
|
+
class BulkUpdateBodyPipe {
|
|
14
|
+
dto;
|
|
15
|
+
pipe;
|
|
16
|
+
constructor(dto, options) {
|
|
17
|
+
this.dto = dto;
|
|
18
|
+
this.pipe = new common_1.ValidationPipe(options);
|
|
19
|
+
}
|
|
20
|
+
async transform(body) {
|
|
21
|
+
if (!body?.data || typeof body.data !== "object")
|
|
22
|
+
return body;
|
|
23
|
+
const data = await this.pipe.transform(body.data, {
|
|
24
|
+
type: "body",
|
|
25
|
+
metatype: this.dto,
|
|
26
|
+
});
|
|
27
|
+
return { ...body, data };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function idsOf(service, body) {
|
|
31
|
+
const ids = body?.ids;
|
|
32
|
+
if (!Array.isArray(ids) || ids.length === 0) {
|
|
33
|
+
throw new common_1.BadRequestException("ids must be a non-empty array");
|
|
34
|
+
}
|
|
35
|
+
return Promise.all(ids.map((id) => service.parseId(id)));
|
|
36
|
+
}
|
|
37
|
+
function createCrudController(service, options = {}) {
|
|
38
|
+
const routeOptions = (name) => {
|
|
39
|
+
const value = options.routes?.[name];
|
|
40
|
+
const enabled = typeof value === "boolean"
|
|
41
|
+
? value
|
|
42
|
+
: (value?.enabled ?? !BULK_ROUTES.has(name));
|
|
43
|
+
if (!enabled)
|
|
44
|
+
return undefined;
|
|
45
|
+
return typeof value === "object" ? value : {};
|
|
46
|
+
};
|
|
47
|
+
const idPipe = options.idType === "int"
|
|
48
|
+
? common_1.ParseIntPipe
|
|
49
|
+
: options.idType === "uuid"
|
|
50
|
+
? common_1.ParseUUIDPipe
|
|
51
|
+
: undefined;
|
|
52
|
+
const queryOptions = options.query ?? {};
|
|
53
|
+
const readOptions = (svc, query) => {
|
|
54
|
+
const picked = {};
|
|
55
|
+
for (const key of ["with", "fields", "counts"]) {
|
|
56
|
+
if (query?.[key] !== undefined)
|
|
57
|
+
picked[key] = query[key];
|
|
58
|
+
}
|
|
59
|
+
return svc.parseQuery(picked, queryOptions).options;
|
|
60
|
+
};
|
|
61
|
+
const softDeleteOn = (svc) => {
|
|
62
|
+
const softDelete = svc.config?.softDelete;
|
|
63
|
+
if (!softDelete?.enabled) {
|
|
64
|
+
throw new common_1.NotFoundException("This resource has no trash");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
class CrudController {
|
|
68
|
+
service;
|
|
69
|
+
constructor(service) {
|
|
70
|
+
this.service = service;
|
|
71
|
+
}
|
|
72
|
+
async id(raw) {
|
|
73
|
+
return idPipe ? raw : this.service.parseId(raw);
|
|
74
|
+
}
|
|
75
|
+
list(query) {
|
|
76
|
+
const q = this.service.parseQuery(query, queryOptions);
|
|
77
|
+
return q.isCursor
|
|
78
|
+
? this.service.findByCursor(q.filters, q.pagination, q.options)
|
|
79
|
+
: this.service.findAll(q.filters, q.pagination, q.options);
|
|
80
|
+
}
|
|
81
|
+
trash(query) {
|
|
82
|
+
softDeleteOn(this.service);
|
|
83
|
+
const q = this.service.parseQuery(query, {
|
|
84
|
+
...queryOptions,
|
|
85
|
+
allowTrash: false,
|
|
86
|
+
});
|
|
87
|
+
const opts = { ...q.options, onlyDeleted: true };
|
|
88
|
+
return q.isCursor
|
|
89
|
+
? this.service.findByCursor(q.filters, q.pagination, opts)
|
|
90
|
+
: this.service.findAll(q.filters, q.pagination, opts);
|
|
91
|
+
}
|
|
92
|
+
bulkCreate(body, query) {
|
|
93
|
+
if (!Array.isArray(body)) {
|
|
94
|
+
throw new common_1.BadRequestException("The body must be an array");
|
|
95
|
+
}
|
|
96
|
+
return this.service.massCreate(body, readOptions(this.service, query));
|
|
97
|
+
}
|
|
98
|
+
async bulkUpdate(body, query) {
|
|
99
|
+
if (!body?.data || typeof body.data !== "object") {
|
|
100
|
+
throw new common_1.BadRequestException("data must be an object");
|
|
101
|
+
}
|
|
102
|
+
return this.service.massUpdate(await idsOf(this.service, body), body.data, readOptions(this.service, query));
|
|
103
|
+
}
|
|
104
|
+
async bulkDelete(body) {
|
|
105
|
+
const ids = await idsOf(this.service, body);
|
|
106
|
+
return options.deleteMode === "soft"
|
|
107
|
+
? this.service.massSoftDelete(ids)
|
|
108
|
+
: this.service.massDelete(ids);
|
|
109
|
+
}
|
|
110
|
+
async bulkRestore(body, query) {
|
|
111
|
+
softDeleteOn(this.service);
|
|
112
|
+
return this.service.massRestore(await idsOf(this.service, body), readOptions(this.service, query));
|
|
113
|
+
}
|
|
114
|
+
async get(rawId, query) {
|
|
115
|
+
const id = await this.id(rawId);
|
|
116
|
+
const row = await this.service.find(id, readOptions(this.service, query));
|
|
117
|
+
if (!row) {
|
|
118
|
+
throw new crud_exceptions_1.EntityNotFoundException(this.service.getEntityName(), id);
|
|
119
|
+
}
|
|
120
|
+
return row;
|
|
121
|
+
}
|
|
122
|
+
create(body, query) {
|
|
123
|
+
return this.service.create(body, readOptions(this.service, query));
|
|
124
|
+
}
|
|
125
|
+
async update(rawId, body, query) {
|
|
126
|
+
return this.service.update(await this.id(rawId), body, readOptions(this.service, query));
|
|
127
|
+
}
|
|
128
|
+
async delete(rawId) {
|
|
129
|
+
const id = await this.id(rawId);
|
|
130
|
+
return options.deleteMode === "soft"
|
|
131
|
+
? this.service.softDelete(id)
|
|
132
|
+
: this.service.delete(id);
|
|
133
|
+
}
|
|
134
|
+
async softDelete(rawId) {
|
|
135
|
+
softDeleteOn(this.service);
|
|
136
|
+
return this.service.softDelete(await this.id(rawId));
|
|
137
|
+
}
|
|
138
|
+
async restore(rawId, query) {
|
|
139
|
+
softDeleteOn(this.service);
|
|
140
|
+
return this.service.restore(await this.id(rawId), readOptions(this.service, query));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
(0, common_1.Inject)(service)(CrudController, undefined, 0);
|
|
144
|
+
Reflect.defineMetadata("design:paramtypes", [service], CrudController);
|
|
145
|
+
const proto = CrudController.prototype;
|
|
146
|
+
const idParam = () => (idPipe ? (0, common_1.Param)("id", idPipe) : (0, common_1.Param)("id"));
|
|
147
|
+
const openapi = options.openapi === true ? service : (options.openapi ?? undefined);
|
|
148
|
+
const routes = [
|
|
149
|
+
{
|
|
150
|
+
name: "list",
|
|
151
|
+
http: (0, common_1.Get)(),
|
|
152
|
+
params: [(0, common_1.Query)()],
|
|
153
|
+
types: [Object],
|
|
154
|
+
extra: openapi ? [(0, api_crud_decorators_1.ApiCrudList)(openapi)] : [],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "trash",
|
|
158
|
+
http: (0, common_1.Get)("trash"),
|
|
159
|
+
params: [(0, common_1.Query)()],
|
|
160
|
+
types: [Object],
|
|
161
|
+
extra: openapi ? [(0, api_crud_decorators_1.ApiCrudList)(openapi, { trash: true })] : [],
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "bulkCreate",
|
|
165
|
+
http: (0, common_1.Post)("bulk"),
|
|
166
|
+
params: [
|
|
167
|
+
options.dto?.create
|
|
168
|
+
? (0, common_1.Body)(new common_1.ParseArrayPipe({
|
|
169
|
+
...options.validation,
|
|
170
|
+
items: options.dto.create,
|
|
171
|
+
}))
|
|
172
|
+
: (0, common_1.Body)(),
|
|
173
|
+
(0, common_1.Query)(),
|
|
174
|
+
],
|
|
175
|
+
types: [Array, Object],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "bulkUpdate",
|
|
179
|
+
http: (0, common_1.Patch)("bulk"),
|
|
180
|
+
params: [
|
|
181
|
+
options.dto?.update
|
|
182
|
+
? (0, common_1.Body)(new BulkUpdateBodyPipe(options.dto.update, options.validation))
|
|
183
|
+
: (0, common_1.Body)(),
|
|
184
|
+
(0, common_1.Query)(),
|
|
185
|
+
],
|
|
186
|
+
types: [Object, Object],
|
|
187
|
+
extra: [(0, common_1.HttpCode)(200)],
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "bulkDelete",
|
|
191
|
+
http: (0, common_1.Post)("bulk-delete"),
|
|
192
|
+
params: [(0, common_1.Body)()],
|
|
193
|
+
types: [Object],
|
|
194
|
+
extra: [(0, common_1.HttpCode)(200)],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: "bulkRestore",
|
|
198
|
+
http: (0, common_1.Post)("bulk-restore"),
|
|
199
|
+
params: [(0, common_1.Body)(), (0, common_1.Query)()],
|
|
200
|
+
types: [Object, Object],
|
|
201
|
+
extra: [(0, common_1.HttpCode)(200)],
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "get",
|
|
205
|
+
http: (0, common_1.Get)(":id"),
|
|
206
|
+
params: [idParam(), (0, common_1.Query)()],
|
|
207
|
+
types: [Object, Object],
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "create",
|
|
211
|
+
http: (0, common_1.Post)(),
|
|
212
|
+
params: [(0, common_1.Body)(), (0, common_1.Query)()],
|
|
213
|
+
types: [options.dto?.create ?? Object, Object],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "update",
|
|
217
|
+
http: (0, common_1.Patch)(":id"),
|
|
218
|
+
params: [idParam(), (0, common_1.Body)(), (0, common_1.Query)()],
|
|
219
|
+
types: [Object, options.dto?.update ?? Object, Object],
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
name: "delete",
|
|
223
|
+
http: (0, common_1.Delete)(":id"),
|
|
224
|
+
params: [idParam()],
|
|
225
|
+
types: [Object],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "softDelete",
|
|
229
|
+
http: (0, common_1.Post)(":id/soft-delete"),
|
|
230
|
+
params: [idParam()],
|
|
231
|
+
types: [Object],
|
|
232
|
+
extra: [(0, common_1.HttpCode)(200)],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "restore",
|
|
236
|
+
http: (0, common_1.Post)(":id/restore"),
|
|
237
|
+
params: [idParam(), (0, common_1.Query)()],
|
|
238
|
+
types: [Object, Object],
|
|
239
|
+
extra: [(0, common_1.HttpCode)(200)],
|
|
240
|
+
},
|
|
241
|
+
];
|
|
242
|
+
const handlers = new Map(routes.map((route) => [route.name, proto[route.name]]));
|
|
243
|
+
for (const route of routes)
|
|
244
|
+
delete proto[route.name];
|
|
245
|
+
for (const route of routes) {
|
|
246
|
+
const settings = routeOptions(route.name);
|
|
247
|
+
if (!settings)
|
|
248
|
+
continue;
|
|
249
|
+
Object.defineProperty(proto, route.name, {
|
|
250
|
+
value: handlers.get(route.name),
|
|
251
|
+
writable: true,
|
|
252
|
+
configurable: true,
|
|
253
|
+
enumerable: false,
|
|
254
|
+
});
|
|
255
|
+
let descriptor = Object.getOwnPropertyDescriptor(proto, route.name);
|
|
256
|
+
route.params.forEach((decorate, index) => {
|
|
257
|
+
decorate(proto, route.name, index);
|
|
258
|
+
});
|
|
259
|
+
Reflect.defineMetadata("design:paramtypes", route.types, proto, route.name);
|
|
260
|
+
const decorators = [
|
|
261
|
+
route.http,
|
|
262
|
+
...(route.extra ?? []),
|
|
263
|
+
...(settings.decorators ?? []),
|
|
264
|
+
...(options.decorators ?? []),
|
|
265
|
+
];
|
|
266
|
+
for (const decorate of decorators.reverse()) {
|
|
267
|
+
descriptor =
|
|
268
|
+
decorate(proto, route.name, descriptor) ?? descriptor;
|
|
269
|
+
}
|
|
270
|
+
Object.defineProperty(proto, route.name, descriptor);
|
|
271
|
+
}
|
|
272
|
+
for (const decorate of options.classDecorators ?? []) {
|
|
273
|
+
decorate(CrudController);
|
|
274
|
+
}
|
|
275
|
+
if (options.path !== undefined)
|
|
276
|
+
(0, common_1.Controller)(options.path)(CrudController);
|
|
277
|
+
return CrudController;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=crud-controller.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud-controller.factory.js","sourceRoot":"","sources":["../../src/controller/crud-controller.factory.ts"],"names":[],"mappings":";;;AAAA,2CAoBwB;AAIxB,mEAAwE;AACxE,wEAGwC;AAgFxC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAgB;IAC1C,YAAY;IACZ,YAAY;IACZ,YAAY;IACZ,aAAa;CACb,CAAC,CAAC;AAQH,MAAM,kBAAkB;IAIL,GAAG;IAHJ,IAAI,CAAiB;IAEtC,YACkB,GAAkB,EACnC,OAA+B;mBADd,GAAG;QAGpB,IAAI,CAAC,IAAI,GAAG,IAAI,uBAAc,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAmD;QAClE,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC9D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE;YACjD,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,IAAI,CAAC,GAAG;SAClB,CAAC,CAAC;QACH,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;CACD;AAID,KAAK,UAAU,KAAK,CACnB,OAAoD,EACpD,IAAyB;IAEzB,MAAM,GAAG,GAAG,IAAI,EAAE,GAAG,CAAC;IACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,4BAAmB,CAAC,+BAA+B,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,C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AE,EAAE,CAAC;QACtD,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC1B,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;QAAE,IAAA,mBAAU,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC;IACzE,OAAO,cAAc,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { DuplicateEntityException, ForeignKeyViolationException, ValidationFailedException } from "../../exceptions/crud.exceptions";
|
|
2
|
+
import type { ICrudService, PaginationOptions } from "../interfaces/crud-service.interface";
|
|
3
|
+
import type { CrudWriteOperation } from "../interfaces/events.interface";
|
|
4
|
+
import type { CountByRow, CrudAllowlists, CrudPage, CursorPage, CursorPaginationOptions, ParseCrudQueryOptions, ParsedCrudQuery, RelationCounts, SortInput, UncountedCrudPage, UpsertOptions } from "../interfaces/query.interface";
|
|
5
|
+
import type { CrudScopeValues } from "../interfaces/scope.interface";
|
|
6
|
+
import type { RelationConfig, RelationNode, RelationsConfig, RelationType, SelectTree, SqlCrudConfig, SqlOperationOptions } from "../interfaces/sql-crud-config.interface";
|
|
7
|
+
import type { SortOrder } from "../types/sql.types";
|
|
8
|
+
interface SortSpec {
|
|
9
|
+
key: string;
|
|
10
|
+
column: any;
|
|
11
|
+
order: SortOrder;
|
|
12
|
+
relation?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare abstract class SqlBaseCrudService<T extends Record<string, any>, CreateDto, UpdateDto, FilterDto> implements ICrudService<T, CreateDto, UpdateDto, FilterDto> {
|
|
15
|
+
protected readonly config: SqlCrudConfig;
|
|
16
|
+
protected readonly defaultConfig: SqlCrudConfig;
|
|
17
|
+
protected buildSelectFields(select: string[]): Record<string, any> | undefined;
|
|
18
|
+
protected wasAffected(result: any): boolean;
|
|
19
|
+
protected buildWhereConditionsFromPartial(where: Partial<T>): any[];
|
|
20
|
+
protected columnOf(table: any, name: string): any | undefined;
|
|
21
|
+
protected primaryKeyOf(table: any): string;
|
|
22
|
+
protected isTextColumn(column: any): boolean;
|
|
23
|
+
protected coerceFilterValue(column: any, value: any): any;
|
|
24
|
+
private static readonly ALLOWLIST_LABELS;
|
|
25
|
+
protected assertAllowed(list: keyof CrudAllowlists, path: string, options?: SqlOperationOptions): void;
|
|
26
|
+
protected checkReadOptions(options?: SqlOperationOptions): void;
|
|
27
|
+
protected rowScope(options?: SqlOperationOptions): any[];
|
|
28
|
+
protected resolveScope(options?: SqlOperationOptions): CrudScopeValues | null;
|
|
29
|
+
protected scopeConditions(options?: SqlOperationOptions, table?: any): any[];
|
|
30
|
+
protected relatedRowScope(target: any, options?: SqlOperationOptions): any[];
|
|
31
|
+
protected relatedScopeConditions(target: any, options?: SqlOperationOptions): any[];
|
|
32
|
+
protected applyScopeToRow(row: Record<string, any>, options?: SqlOperationOptions): void;
|
|
33
|
+
protected softDeleteScope(options?: SqlOperationOptions): any | undefined;
|
|
34
|
+
protected managedColumns(operation: "create" | "update"): string[];
|
|
35
|
+
protected filterWritable(entity: Record<string, any>, operation: "create" | "update", options?: SqlOperationOptions): Record<string, any>;
|
|
36
|
+
protected keyOf(value: unknown): string;
|
|
37
|
+
constructor(config: SqlCrudConfig);
|
|
38
|
+
private validateConfiguration;
|
|
39
|
+
private validateColumns;
|
|
40
|
+
private validateRelations;
|
|
41
|
+
protected validateCreate(_data: CreateDto): Promise<void>;
|
|
42
|
+
protected validateUpdate(_id: any, _data: UpdateDto): Promise<void>;
|
|
43
|
+
protected mapCreateDtoToEntity(data: CreateDto): Record<string, any>;
|
|
44
|
+
protected mapUpdateDtoToEntity(data: UpdateDto): Record<string, any>;
|
|
45
|
+
protected beforeCreate(data: CreateDto): Promise<CreateDto>;
|
|
46
|
+
protected afterCreate(_entity: T): Promise<void>;
|
|
47
|
+
protected beforeUpdate(_id: any, data: UpdateDto): Promise<UpdateDto>;
|
|
48
|
+
protected afterUpdate(_entity: T): Promise<void>;
|
|
49
|
+
protected beforeDelete(_id: any): Promise<void>;
|
|
50
|
+
protected afterDelete(_id: any): Promise<void>;
|
|
51
|
+
protected beforeSoftDelete(_id: any): Promise<void>;
|
|
52
|
+
protected afterSoftDelete(_id: any): Promise<void>;
|
|
53
|
+
protected beforeRestore(_id: any): Promise<void>;
|
|
54
|
+
protected afterRestore(_entity: T): Promise<void>;
|
|
55
|
+
protected relationType(relation: RelationConfig): RelationType;
|
|
56
|
+
protected isCollection(relation: RelationConfig): boolean;
|
|
57
|
+
protected eagerRelations(relations: string[]): string[];
|
|
58
|
+
protected relationTree(paths: string[], configured?: RelationsConfig): RelationNode[];
|
|
59
|
+
protected parseSelect(select?: string[]): SelectTree;
|
|
60
|
+
protected selectFor(select: SelectTree, name: string): SelectTree;
|
|
61
|
+
protected keysForChildren(nodes: RelationNode[], hostTable?: any): string[];
|
|
62
|
+
protected parentKeyOf(relation: RelationConfig, hostTable?: any): string;
|
|
63
|
+
protected withRequiredKeys(base: string[], nodes: RelationNode[]): string[];
|
|
64
|
+
protected buildSelection(base: string[], joined: RelationNode[], select?: SelectTree): Record<string, any>;
|
|
65
|
+
protected startSelect(db: any, base: string[], joined: RelationNode[], hasJoins?: boolean, select?: SelectTree): any;
|
|
66
|
+
protected planJoins(nodes: RelationNode[]): RelationNode[];
|
|
67
|
+
protected collectionOrderBy(relation: RelationConfig): any[];
|
|
68
|
+
protected softDeleteCondition(table: any): any | undefined;
|
|
69
|
+
protected relationProjection(table: any, wanted: string[], requiredKeys: string[]): Record<string, any> | undefined;
|
|
70
|
+
protected loadRelations(db: any, hosts: any[], nodes: RelationNode[], select?: SelectTree, hostTable?: any, options?: SqlOperationOptions): Promise<void>;
|
|
71
|
+
protected loadBelongsTo(db: any, hosts: any[], node: RelationNode, select: SelectTree, options?: SqlOperationOptions): Promise<void>;
|
|
72
|
+
protected loadHasMany(db: any, hosts: any[], node: RelationNode, select: SelectTree, hostTable?: any, options?: SqlOperationOptions): Promise<void>;
|
|
73
|
+
protected loadManyToMany(db: any, hosts: any[], node: RelationNode, select: SelectTree, hostTable?: any, options?: SqlOperationOptions): Promise<void>;
|
|
74
|
+
private groupCollection;
|
|
75
|
+
protected applyJoins(query: any, relationNames: string[], options?: SqlOperationOptions): any;
|
|
76
|
+
protected normalizeRelations(rows: any[], eager: string[]): any[];
|
|
77
|
+
protected buildOrderBy(sortBy?: SortInput, sortOrder?: SortOrder): any[];
|
|
78
|
+
protected orderOf(spec: SortSpec): any;
|
|
79
|
+
protected resolveSort(sortBy?: SortInput, sortOrder?: SortOrder, options?: SqlOperationOptions): SortSpec[];
|
|
80
|
+
private sortEntries;
|
|
81
|
+
protected resolveSortColumn(key: string, order: SortOrder): SortSpec;
|
|
82
|
+
protected resolvePagination(page?: number, limit?: number): {
|
|
83
|
+
page: number;
|
|
84
|
+
limit: number;
|
|
85
|
+
offset: number;
|
|
86
|
+
};
|
|
87
|
+
protected isUniqueViolation(error: any): boolean;
|
|
88
|
+
protected toDuplicateException(error: any): DuplicateEntityException;
|
|
89
|
+
private static readonly DATA_ERRORS;
|
|
90
|
+
protected isDataException(error: any): boolean;
|
|
91
|
+
protected toDataException(error: any): ValidationFailedException;
|
|
92
|
+
protected toClientError(error: any, operation?: "read" | "write" | "delete"): unknown;
|
|
93
|
+
protected runRead<R>(query: PromiseLike<R>): Promise<R>;
|
|
94
|
+
protected isForeignKeyViolation(error: any): boolean;
|
|
95
|
+
protected toForeignKeyException(error: any): ForeignKeyViolationException;
|
|
96
|
+
protected applyLock(query: any, options?: SqlOperationOptions): any;
|
|
97
|
+
protected buildSearchCondition(search?: SqlOperationOptions["search"]): any;
|
|
98
|
+
protected caseInsensitiveLike(column: any, pattern: string): any;
|
|
99
|
+
parseQuery(query: Record<string, unknown> | null | undefined, options?: ParseCrudQueryOptions): ParsedCrudQuery;
|
|
100
|
+
idKind(): "int" | "bigint" | "uuid" | "string";
|
|
101
|
+
parseId(raw: unknown): Promise<unknown>;
|
|
102
|
+
private findForGuard;
|
|
103
|
+
protected assertVersion(id: any, actual: unknown, expected: unknown): void;
|
|
104
|
+
protected writeWhere(ids: any[], options?: SqlOperationOptions, table?: any): any;
|
|
105
|
+
protected withVersionBump(set: Record<string, any>): Record<string, any>;
|
|
106
|
+
find(id: any, options?: SqlOperationOptions): Promise<T | null>;
|
|
107
|
+
findOne(where: Partial<T>, options?: SqlOperationOptions): Promise<T | null>;
|
|
108
|
+
private findFirst;
|
|
109
|
+
private planList;
|
|
110
|
+
private listConditions;
|
|
111
|
+
private buildCountQuery;
|
|
112
|
+
findAll(filters: FilterDto | undefined, pagination: PaginationOptions & {
|
|
113
|
+
withCount: false;
|
|
114
|
+
}, options?: SqlOperationOptions): Promise<UncountedCrudPage<T>>;
|
|
115
|
+
findAll(filters?: FilterDto, pagination?: PaginationOptions & {
|
|
116
|
+
withCount?: true;
|
|
117
|
+
}, options?: SqlOperationOptions): Promise<CrudPage<T>>;
|
|
118
|
+
findAll(filters?: FilterDto, pagination?: PaginationOptions, options?: SqlOperationOptions): Promise<CrudPage<T, number | null>>;
|
|
119
|
+
findByCursor(filters?: FilterDto, pagination?: CursorPaginationOptions, options?: SqlOperationOptions): Promise<CursorPage<T>>;
|
|
120
|
+
protected cursorField(column: any): any;
|
|
121
|
+
private compareCursor;
|
|
122
|
+
protected keysetCondition(specs: SortSpec[], values: unknown[]): any;
|
|
123
|
+
private afterCursor;
|
|
124
|
+
protected emitEvent(phase: "before" | "after", operation: CrudWriteOperation, bulk: boolean, payload: {
|
|
125
|
+
ids?: unknown[];
|
|
126
|
+
input?: unknown;
|
|
127
|
+
rows?: T[];
|
|
128
|
+
transaction?: unknown;
|
|
129
|
+
}, options?: SqlOperationOptions): Promise<void>;
|
|
130
|
+
private idsOf;
|
|
131
|
+
protected loadWriteRelations(db: any, rows: T[], options?: SqlOperationOptions): Promise<void>;
|
|
132
|
+
private expectedVersionOf;
|
|
133
|
+
protected prepareCreate(data: CreateDto, options?: SqlOperationOptions): Promise<Record<string, any>>;
|
|
134
|
+
private insertOne;
|
|
135
|
+
create(data: CreateDto, options?: SqlOperationOptions): Promise<T>;
|
|
136
|
+
private takeNested;
|
|
137
|
+
private insertNested;
|
|
138
|
+
private relatedRow;
|
|
139
|
+
private linkTargets;
|
|
140
|
+
attach(id: any, relation: string, relatedIds: unknown[], options?: SqlOperationOptions): Promise<T>;
|
|
141
|
+
detach(id: any, relation: string, relatedIds?: unknown[], options?: SqlOperationOptions): Promise<T>;
|
|
142
|
+
sync(id: any, relation: string, relatedIds: unknown[], options?: SqlOperationOptions): Promise<T>;
|
|
143
|
+
private changeLinks;
|
|
144
|
+
private valueKey;
|
|
145
|
+
private uniqueValues;
|
|
146
|
+
private tableName;
|
|
147
|
+
protected prepareUpdate(data: UpdateDto, options?: SqlOperationOptions): Record<string, any>;
|
|
148
|
+
update(id: any, data: UpdateDto, options?: SqlOperationOptions): Promise<T>;
|
|
149
|
+
private updateWhereIn;
|
|
150
|
+
private fetchByIds;
|
|
151
|
+
private inIdOrder;
|
|
152
|
+
softDelete(id: any, options?: SqlOperationOptions): Promise<boolean>;
|
|
153
|
+
private softDeleteSet;
|
|
154
|
+
restore(id: any, options?: SqlOperationOptions): Promise<T>;
|
|
155
|
+
delete(id: any, options?: SqlOperationOptions): Promise<boolean>;
|
|
156
|
+
forceDelete(id: any, options?: SqlOperationOptions): Promise<boolean>;
|
|
157
|
+
upsert(data: CreateDto, upsert?: UpsertOptions, options?: SqlOperationOptions): Promise<T>;
|
|
158
|
+
massUpsert(data: CreateDto[], upsert?: UpsertOptions, options?: SqlOperationOptions): Promise<T[]>;
|
|
159
|
+
private conflictKeys;
|
|
160
|
+
private conflictValue;
|
|
161
|
+
private upsertRows;
|
|
162
|
+
private excludedValue;
|
|
163
|
+
massCreate(data: CreateDto[], options?: SqlOperationOptions): Promise<T[]>;
|
|
164
|
+
private insertMany;
|
|
165
|
+
private assertAllWritten;
|
|
166
|
+
massUpdate(ids: any[], data: UpdateDto, options?: SqlOperationOptions): Promise<T[]>;
|
|
167
|
+
private runKeyed;
|
|
168
|
+
massSoftDelete(ids: any[], options?: SqlOperationOptions): Promise<boolean>;
|
|
169
|
+
massRestore(ids: any[], options?: SqlOperationOptions): Promise<T[]>;
|
|
170
|
+
massDelete(ids: any[], options?: SqlOperationOptions): Promise<boolean>;
|
|
171
|
+
massForceDelete(ids: any[], options?: SqlOperationOptions): Promise<boolean>;
|
|
172
|
+
private uniqueIds;
|
|
173
|
+
private fingerprint;
|
|
174
|
+
private assertAllExist;
|
|
175
|
+
private eachItem;
|
|
176
|
+
private itemRef;
|
|
177
|
+
protected runSet<R>(tx: any, message: string, statement: (sp: any) => Promise<R>, items: Array<{
|
|
178
|
+
index?: number;
|
|
179
|
+
id?: any;
|
|
180
|
+
run: (sp: any) => Promise<unknown>;
|
|
181
|
+
}>, operation: "write" | "delete"): Promise<R>;
|
|
182
|
+
private diagnose;
|
|
183
|
+
private massCreatePerItem;
|
|
184
|
+
private massUpdatePerItem;
|
|
185
|
+
private massSoftDeletePerItem;
|
|
186
|
+
private massRestorePerItem;
|
|
187
|
+
private massDeletePerItem;
|
|
188
|
+
protected savepoint<R>(tx: any, run: (sp: any) => Promise<R>): Promise<R>;
|
|
189
|
+
exists(id: any, options?: SqlOperationOptions): Promise<boolean>;
|
|
190
|
+
count(filters?: FilterDto, options?: SqlOperationOptions): Promise<number>;
|
|
191
|
+
countBy<V = unknown>(column: string, filters?: FilterDto, options?: SqlOperationOptions): Promise<CountByRow<V>[]>;
|
|
192
|
+
private resolveGroupColumn;
|
|
193
|
+
protected countNames(counts?: RelationCounts): string[];
|
|
194
|
+
protected withCountKeys(base: string[], counts?: RelationCounts): string[];
|
|
195
|
+
protected loadCounts(db: any, rows: any[], counts: RelationCounts | undefined, options?: SqlOperationOptions): Promise<void>;
|
|
196
|
+
private countQuery;
|
|
197
|
+
protected pushColumnCondition(conditions: any[], column: any, value: any, caseInsensitive?: boolean): void;
|
|
198
|
+
protected buildCollectionFilter(relation: RelationConfig, value: Record<string, any>, db?: any, name?: string, options?: SqlOperationOptions): any | undefined;
|
|
199
|
+
private collectionCondition;
|
|
200
|
+
private quantifiedCollection;
|
|
201
|
+
private belongsToExists;
|
|
202
|
+
private rootHost;
|
|
203
|
+
private relationHost;
|
|
204
|
+
protected buildFilterConditions(filters?: any, db?: any, options?: SqlOperationOptions): {
|
|
205
|
+
conditions: any[];
|
|
206
|
+
relations: string[];
|
|
207
|
+
};
|
|
208
|
+
private isGroupKey;
|
|
209
|
+
private compileFilterAt;
|
|
210
|
+
private compileRelationFilter;
|
|
211
|
+
private compileGroup;
|
|
212
|
+
protected buildWhereConditions(filters?: any): any[];
|
|
213
|
+
private parseFlag;
|
|
214
|
+
private expectArray;
|
|
215
|
+
static readonly MAX_BATCH_PARAMETERS = 60000;
|
|
216
|
+
protected assertBatchSize(parameters: number): void;
|
|
217
|
+
protected insertParameters(rows: unknown[]): number;
|
|
218
|
+
private requirePostgres;
|
|
219
|
+
private patternCondition;
|
|
220
|
+
protected applyComplexFilter(conditions: any[], column: any, filterObj: any): void;
|
|
221
|
+
protected executeSqlTransaction<R>(operation: (tx: any) => Promise<R>, existingTransaction?: any): Promise<R>;
|
|
222
|
+
protected getEntityName(): string;
|
|
223
|
+
fullTextSearch(searchTerm: string, searchColumns: string[], pagination?: PaginationOptions, options?: SqlOperationOptions): Promise<{
|
|
224
|
+
data: T[];
|
|
225
|
+
total: number;
|
|
226
|
+
page: number;
|
|
227
|
+
limit: number;
|
|
228
|
+
}>;
|
|
229
|
+
}
|
|
230
|
+
export {};
|