@tstdl/base 0.92.130 → 0.92.132
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/ai/ai.service.js +4 -4
- package/api/server/api-controller.js +1 -2
- package/document-management/api/document-management.api.d.ts +9 -37
- package/document-management/api/document-management.api.js +9 -18
- package/document-management/models/document-request-collection-assignment.model.d.ts +7 -0
- package/document-management/models/{document-request-collection.model.js → document-request-collection-assignment.model.js} +6 -6
- package/document-management/models/index.d.ts +1 -1
- package/document-management/models/index.js +1 -1
- package/document-management/server/api/document-management.api.d.ts +26 -0
- package/document-management/server/api/document-management.api.js +169 -0
- package/document-management/server/api/index.d.ts +1 -0
- package/document-management/server/api/index.js +1 -0
- package/document-management/server/drizzle/{0000_cool_victor_mancha.sql → 0000_magical_madame_hydra.sql} +128 -96
- package/document-management/server/drizzle/meta/0000_snapshot.json +768 -492
- package/document-management/server/drizzle/meta/_journal.json +2 -9
- package/document-management/server/index.d.ts +1 -0
- package/document-management/server/index.js +1 -0
- package/document-management/server/schemas.d.ts +3 -2
- package/document-management/server/schemas.js +3 -2
- package/document-management/server/services/document-category-type.service.d.ts +2 -0
- package/document-management/server/services/document-category-type.service.js +26 -15
- package/document-management/server/services/document-collection.service.js +13 -2
- package/document-management/server/services/document-file.service.js +15 -4
- package/document-management/server/services/document-management-ai.service.js +19 -8
- package/document-management/server/services/document-management-ancillary.service.d.ts +21 -40
- package/document-management/server/services/document-management-ancillary.service.js +25 -14
- package/document-management/server/services/document-management.service.d.ts +1 -1
- package/document-management/server/services/document-management.service.js +53 -34
- package/document-management/server/services/document-property.service.d.ts +2 -34
- package/document-management/server/services/document-property.service.js +20 -8
- package/document-management/server/services/document-request.service.js +11 -11
- package/document-management/server/services/document-validation.service.js +15 -4
- package/document-management/server/services/document-workflow.service.js +27 -16
- package/document-management/server/services/document.service.d.ts +8 -2
- package/document-management/server/services/document.service.js +47 -7
- package/document-management/server/services/index.d.ts +1 -0
- package/document-management/server/services/index.js +1 -0
- package/document-management/server/services/singleton.d.ts +4 -0
- package/document-management/server/services/singleton.js +12 -0
- package/document-management/service-models/enriched/enriched-document-management-data.view.d.ts +2 -1
- package/document-management/service-models/enriched/enriched-document-management-data.view.js +10 -2
- package/eslint.config.js +1 -0
- package/examples/document-management/categories-and-types.d.ts +324 -0
- package/examples/document-management/categories-and-types.js +363 -0
- package/examples/document-management/main.d.ts +7 -8
- package/examples/document-management/main.js +86 -27
- package/injector/decorators.d.ts +1 -0
- package/injector/decorators.js +41 -12
- package/injector/inject.d.ts +12 -2
- package/injector/injector.d.ts +3 -2
- package/injector/injector.js +87 -36
- package/injector/symbols.d.ts +1 -0
- package/injector/symbols.js +1 -0
- package/module/modules/web-server.module.js +4 -4
- package/orm/server/database.d.ts +0 -4
- package/orm/server/database.js +0 -4
- package/orm/server/drizzle/schema-converter.js +5 -4
- package/orm/server/module.d.ts +0 -4
- package/orm/server/module.js +0 -2
- package/orm/server/query-converter.js +11 -38
- package/orm/server/repository.d.ts +3 -2
- package/orm/server/repository.js +2 -2
- package/orm/server/transaction.d.ts +5 -4
- package/orm/server/transaction.js +8 -3
- package/orm/server/transactional.js +3 -3
- package/orm/sqls.d.ts +4 -1
- package/orm/sqls.js +4 -1
- package/package.json +4 -4
- package/reflection/registry.js +6 -6
- package/document-management/models/document-request-collection.model.d.ts +0 -7
- package/document-management/server/drizzle/0001_concerned_quentin_quire.sql +0 -2
- package/document-management/server/drizzle/meta/0001_snapshot.json +0 -1932
package/injector/inject.d.ts
CHANGED
|
@@ -9,7 +9,13 @@ export type InjectArgumentOptions = {
|
|
|
9
9
|
export type InjectionContext = {
|
|
10
10
|
injector: Injector;
|
|
11
11
|
argument: unknown;
|
|
12
|
-
inject<T, A>(token: InjectionToken<T, A>, argument
|
|
12
|
+
inject<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument: ResolveArgument<T, A>, options: InjectOptions<T, A> & {
|
|
13
|
+
optional: true;
|
|
14
|
+
}): T | undefined;
|
|
15
|
+
inject<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A> & {
|
|
16
|
+
optional?: false;
|
|
17
|
+
}): T;
|
|
18
|
+
inject<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): T | undefined;
|
|
13
19
|
injectAll<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): T[];
|
|
14
20
|
injectMany<T extends InjectManyItem<any, any>[]>(...tokens: T): InjectManyReturnType<T>;
|
|
15
21
|
injectAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): Promise<T>;
|
|
@@ -31,6 +37,7 @@ export declare function inject<T = unknown, A = unknown>(token: InjectionToken<T
|
|
|
31
37
|
export declare function inject<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A> & {
|
|
32
38
|
optional?: false;
|
|
33
39
|
}): T;
|
|
40
|
+
export declare function inject<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): T | undefined;
|
|
34
41
|
/**
|
|
35
42
|
* Resolves tokens using the {@link Injector} of the current injection context
|
|
36
43
|
*
|
|
@@ -47,7 +54,10 @@ export declare function injectMany<T extends InjectManyItem<any, any>[]>(...toke
|
|
|
47
54
|
export declare function injectAsync<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument: ResolveArgument<T, A>, options: InjectOptions<T, A> & {
|
|
48
55
|
optional: true;
|
|
49
56
|
}): Promise<T | undefined>;
|
|
50
|
-
export declare function injectAsync<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>
|
|
57
|
+
export declare function injectAsync<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A> & {
|
|
58
|
+
optional?: false;
|
|
59
|
+
}): Promise<T>;
|
|
60
|
+
export declare function injectAsync<T = unknown, A = unknown>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: InjectOptions<T, A>): Promise<T | undefined>;
|
|
51
61
|
/**
|
|
52
62
|
* Resolves tokens using the {@link Injector} of the current injection context
|
|
53
63
|
*
|
package/injector/injector.d.ts
CHANGED
|
@@ -59,14 +59,14 @@ export declare class Injector implements AsyncDisposable {
|
|
|
59
59
|
* @param provider provider used to resolve the token
|
|
60
60
|
* @param options registration options
|
|
61
61
|
*/
|
|
62
|
-
register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>):
|
|
62
|
+
register<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: RegistrationOptions<T, A, C>): this;
|
|
63
63
|
/**
|
|
64
64
|
* Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
65
65
|
* @param token token to register
|
|
66
66
|
* @param provider provider used to resolve the token
|
|
67
67
|
* @param options registration options
|
|
68
68
|
*/
|
|
69
|
-
registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>):
|
|
69
|
+
registerSingleton<T, A = any, C extends Record = Record>(token: InjectionToken<T, A>, providers: OneOrMany<Provider<T, A, C>>, options?: TypedOmit<RegistrationOptions<T, A, C>, 'lifecycle'>): this;
|
|
70
70
|
/**
|
|
71
71
|
* Check if token has a registered provider
|
|
72
72
|
* @param token token check
|
|
@@ -94,6 +94,7 @@ export declare class Injector implements AsyncDisposable {
|
|
|
94
94
|
resolveAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): Promise<T>;
|
|
95
95
|
resolveAllAsync<T, A>(token: InjectionToken<T, A>, argument?: ResolveArgument<T, A>, options?: ResolveOptions<T, A>): Promise<T[]>;
|
|
96
96
|
resolveManyAsync<T extends ResolveManyItem<any, any>[]>(...tokens: T): Promise<ResolveManyReturnType<T>>;
|
|
97
|
+
private _resolveManyTokens;
|
|
97
98
|
private _resolve;
|
|
98
99
|
private _resolveAll;
|
|
99
100
|
private _resolveRegistration;
|
package/injector/injector.js
CHANGED
|
@@ -8,7 +8,7 @@ import { toArray } from '../utils/array/array.js';
|
|
|
8
8
|
import { FactoryMap } from '../utils/factory-map.js';
|
|
9
9
|
import { ForwardRef } from '../utils/object/forward-ref.js';
|
|
10
10
|
import { objectEntries } from '../utils/object/object.js';
|
|
11
|
-
import { assert, isArray, isBoolean, isDefined, isFunction, isNotNull, isNull, isPromise, isUndefined } from '../utils/type-guards.js';
|
|
11
|
+
import { assert, isArray, isBoolean, isDefined, isFunction, isNotNull, isNotObject, isNull, isPromise, isUndefined } from '../utils/type-guards.js';
|
|
12
12
|
import { setCurrentInjectionContext } from './inject.js';
|
|
13
13
|
import { afterResolve } from './interfaces.js';
|
|
14
14
|
import { isClassProvider, isFactoryProvider, isProviderWithInitializer, isTokenProvider, isValueProvider } from './provider.js';
|
|
@@ -61,7 +61,7 @@ export class Injector {
|
|
|
61
61
|
token,
|
|
62
62
|
provider,
|
|
63
63
|
providers: options.providers ?? [],
|
|
64
|
-
options: { multi, ...options }
|
|
64
|
+
options: { multi, ...options },
|
|
65
65
|
};
|
|
66
66
|
addRegistration(Injector.#globalRegistrations, registration);
|
|
67
67
|
}
|
|
@@ -103,10 +103,11 @@ export class Injector {
|
|
|
103
103
|
provider,
|
|
104
104
|
providers: options.providers ?? [],
|
|
105
105
|
options: { multi, ...options },
|
|
106
|
-
resolutions: new Map()
|
|
106
|
+
resolutions: new Map(),
|
|
107
107
|
};
|
|
108
108
|
addRegistration(this.#registrations, registration);
|
|
109
109
|
}
|
|
110
|
+
return this;
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
113
|
* Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
|
|
@@ -116,6 +117,7 @@ export class Injector {
|
|
|
116
117
|
*/
|
|
117
118
|
registerSingleton(token, providers, options) {
|
|
118
119
|
this.register(token, providers, { ...options, lifecycle: 'singleton' });
|
|
120
|
+
return this;
|
|
119
121
|
}
|
|
120
122
|
/**
|
|
121
123
|
* Check if token has a registered provider
|
|
@@ -162,48 +164,101 @@ export class Injector {
|
|
|
162
164
|
resolve(token, argument, options = {}) {
|
|
163
165
|
const context = newInternalResolveContext();
|
|
164
166
|
const value = this._resolve(token, argument, options, context, ResolveChain.startWith(token));
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
try {
|
|
168
|
+
postProcess(context);
|
|
169
|
+
context.$done.resolve();
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
if (context.forwardRefs.has(value)) {
|
|
176
|
+
return ForwardRef.deref(value);
|
|
177
|
+
}
|
|
167
178
|
return value;
|
|
168
179
|
}
|
|
169
180
|
resolveAll(token, argument, options = {}) {
|
|
170
181
|
const context = newInternalResolveContext();
|
|
171
182
|
const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(token));
|
|
172
|
-
|
|
173
|
-
|
|
183
|
+
try {
|
|
184
|
+
postProcess(context);
|
|
185
|
+
context.$done.resolve();
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
if (context.forwardRefs.has(values)) {
|
|
192
|
+
return ForwardRef.deref(values);
|
|
193
|
+
}
|
|
174
194
|
return values;
|
|
175
195
|
}
|
|
176
196
|
resolveMany(...tokens) {
|
|
177
197
|
const context = newInternalResolveContext();
|
|
178
|
-
const values =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
198
|
+
const values = this._resolveManyTokens(tokens, context);
|
|
199
|
+
try {
|
|
200
|
+
postProcess(context);
|
|
201
|
+
context.$done.resolve();
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
return values.map((value) => context.forwardRefs.has(value)
|
|
208
|
+
? ForwardRef.deref(value)
|
|
209
|
+
: value);
|
|
184
210
|
}
|
|
185
211
|
async resolveAsync(token, argument, options = {}) {
|
|
186
212
|
const context = newInternalResolveContext();
|
|
187
213
|
const value = this._resolve(token, argument, options, context, ResolveChain.startWith(token));
|
|
188
|
-
|
|
189
|
-
|
|
214
|
+
try {
|
|
215
|
+
await postProcessAsync(context);
|
|
216
|
+
context.$done.resolve();
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
if (context.forwardRefs.has(value)) {
|
|
223
|
+
return ForwardRef.deref(value);
|
|
224
|
+
}
|
|
190
225
|
return value;
|
|
191
226
|
}
|
|
192
227
|
async resolveAllAsync(token, argument, options = {}) {
|
|
193
228
|
const context = newInternalResolveContext();
|
|
194
229
|
const values = this._resolveAll(token, argument, options, context, ResolveChain.startWith(token));
|
|
195
|
-
|
|
196
|
-
|
|
230
|
+
try {
|
|
231
|
+
await postProcessAsync(context);
|
|
232
|
+
context.$done.resolve();
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
if (context.forwardRefs.has(values)) {
|
|
239
|
+
return ForwardRef.deref(values);
|
|
240
|
+
}
|
|
197
241
|
return values;
|
|
198
242
|
}
|
|
199
243
|
async resolveManyAsync(...tokens) {
|
|
200
244
|
const context = newInternalResolveContext();
|
|
201
|
-
const values =
|
|
245
|
+
const values = this._resolveManyTokens(tokens, context);
|
|
246
|
+
try {
|
|
247
|
+
await postProcessAsync(context);
|
|
248
|
+
context.$done.resolve();
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
context.$done.reject(error); // eslint-disable-line @typescript-eslint/prefer-promise-reject-errors
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
return values.map((value) => context.forwardRefs.has(value)
|
|
255
|
+
? ForwardRef.deref(value)
|
|
256
|
+
: value);
|
|
257
|
+
}
|
|
258
|
+
_resolveManyTokens(tokens, context) {
|
|
259
|
+
return tokens.map((token) => (isArray(token)
|
|
202
260
|
? this._resolve(token[0], token[1], token[2] ?? {}, context, ResolveChain.startWith(token[0]))
|
|
203
261
|
: this._resolve(token, undefined, {}, context, ResolveChain.startWith(token))));
|
|
204
|
-
await postProcessAsync(context);
|
|
205
|
-
context.$done.resolve();
|
|
206
|
-
return values;
|
|
207
262
|
}
|
|
208
263
|
_resolve(token, argument, options, context, chain) {
|
|
209
264
|
this.assertNotDisposed();
|
|
@@ -259,7 +314,7 @@ export class Injector {
|
|
|
259
314
|
_resolveRegistration(registration, argument, options, context, chain) {
|
|
260
315
|
checkOverflow(chain, context);
|
|
261
316
|
const { token, providers } = registration;
|
|
262
|
-
const injector =
|
|
317
|
+
const injector = this.fork('ResolutionInjector');
|
|
263
318
|
for (const nestedProvider of providers) {
|
|
264
319
|
injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
265
320
|
}
|
|
@@ -282,7 +337,7 @@ export class Injector {
|
|
|
282
337
|
return registration.resolutions.get(argumentIdentity);
|
|
283
338
|
}
|
|
284
339
|
const resolutionContext = {
|
|
285
|
-
afterResolveRegistrations: []
|
|
340
|
+
afterResolveRegistrations: [],
|
|
286
341
|
};
|
|
287
342
|
const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain);
|
|
288
343
|
const resolution = {
|
|
@@ -292,7 +347,7 @@ export class Injector {
|
|
|
292
347
|
argument: injectionContext.argument,
|
|
293
348
|
afterResolveRegistrations: resolutionContext.afterResolveRegistrations,
|
|
294
349
|
afterResolveContext: injector.getAfterResolveContext(resolutionTag, context),
|
|
295
|
-
chain
|
|
350
|
+
chain,
|
|
296
351
|
};
|
|
297
352
|
context.resolutions.push(resolution);
|
|
298
353
|
if (resolutionScoped) {
|
|
@@ -377,13 +432,9 @@ export class Injector {
|
|
|
377
432
|
}
|
|
378
433
|
const parameterResolveArgument = injectMetadata.forwardArgumentMapper?.(resolveArgument) ?? injectMetadata.resolveArgumentProvider?.(this.getResolveContext(resolutionTag, context, getChain(injectToken)));
|
|
379
434
|
const { forwardRef } = injectMetadata;
|
|
380
|
-
if (isDefined(forwardRef)) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (isDefined(injectMetadata.mapper)) {
|
|
384
|
-
throw new ResolveError('Cannot use inject mapper with forwardRef.', getChain(forwardToken));
|
|
385
|
-
}
|
|
386
|
-
});
|
|
435
|
+
if (isDefined(forwardRef) && isDefined(injectMetadata.mapper)) {
|
|
436
|
+
const forwardToken = isFunction(forwardRef) ? forwardRef() : isBoolean(forwardRef) ? injectToken : forwardRef;
|
|
437
|
+
throw new ResolveError('Cannot use inject mapper with forwardRef.', getChain(forwardToken));
|
|
387
438
|
}
|
|
388
439
|
const resolveFn = (injectMetadata.resolveAll == true) ? '_resolveAll' : '_resolve';
|
|
389
440
|
const resolved = this[resolveFn](injectToken, parameterResolveArgument, { optional: injectMetadata.optional, forwardRef, forwardRefTypeHint: injectMetadata.forwardRefTypeHint }, context, getChain(injectToken));
|
|
@@ -413,7 +464,7 @@ export class Injector {
|
|
|
413
464
|
addDisposeHandler: this.#addDisposeHandler,
|
|
414
465
|
get data() {
|
|
415
466
|
return resolveContext.resolutionContextData.get(resolutionTag);
|
|
416
|
-
}
|
|
467
|
+
},
|
|
417
468
|
};
|
|
418
469
|
return context;
|
|
419
470
|
}
|
|
@@ -423,7 +474,7 @@ export class Injector {
|
|
|
423
474
|
addDisposeHandler: this.#addDisposeHandler,
|
|
424
475
|
get data() {
|
|
425
476
|
return resolveContext.resolutionContextData.get(resolutionTag);
|
|
426
|
-
}
|
|
477
|
+
},
|
|
427
478
|
};
|
|
428
479
|
return context;
|
|
429
480
|
}
|
|
@@ -437,7 +488,7 @@ export class Injector {
|
|
|
437
488
|
injectMany: (...tokens) => this.resolveMany(...tokens),
|
|
438
489
|
injectAsync: async (token, argument, options) => this.resolveInjectionAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
|
|
439
490
|
injectAllAsync: async (token, argument, options) => this.resolveInjectionAllAsync(token, argument, options ?? {}, resolveContext, injectIndex++, chain),
|
|
440
|
-
injectManyAsync: async (...tokens) => this.resolveManyAsync(...tokens)
|
|
491
|
+
injectManyAsync: async (...tokens) => this.resolveManyAsync(...tokens),
|
|
441
492
|
};
|
|
442
493
|
return context;
|
|
443
494
|
}
|
|
@@ -480,7 +531,7 @@ function newInternalResolveContext() {
|
|
|
480
531
|
resolutionContextData: new FactoryMap(() => ({})),
|
|
481
532
|
forwardRefQueue: new CircularBuffer(),
|
|
482
533
|
forwardRefs: new Set(),
|
|
483
|
-
$done: new DeferredPromise()
|
|
534
|
+
$done: new DeferredPromise(),
|
|
484
535
|
};
|
|
485
536
|
}
|
|
486
537
|
function postProcess(context) {
|
|
@@ -554,7 +605,7 @@ function checkOverflow(chain, context) {
|
|
|
554
605
|
}
|
|
555
606
|
function derefForwardRefs(context) {
|
|
556
607
|
for (const resolution of context.resolutions.values()) {
|
|
557
|
-
if (
|
|
608
|
+
if (isNotObject(resolution.value)) {
|
|
558
609
|
continue;
|
|
559
610
|
}
|
|
560
611
|
for (const [key, value] of objectEntries(resolution.value)) {
|
package/injector/symbols.d.ts
CHANGED
package/injector/symbols.js
CHANGED
|
@@ -15,7 +15,7 @@ import { inject, injectArgument } from '../../injector/inject.js';
|
|
|
15
15
|
import { ModuleBase } from '../module-base.js';
|
|
16
16
|
import { ModuleMetricType } from '../module.js';
|
|
17
17
|
export const webServerModuleConfiguration = {
|
|
18
|
-
port: 8000
|
|
18
|
+
port: 8000,
|
|
19
19
|
};
|
|
20
20
|
let WebServerModule = class WebServerModule extends ModuleBase {
|
|
21
21
|
config = injectArgument(this);
|
|
@@ -26,8 +26,8 @@ let WebServerModule = class WebServerModule extends ModuleBase {
|
|
|
26
26
|
metrics = {
|
|
27
27
|
connectedSockets: {
|
|
28
28
|
type: ModuleMetricType.Gauge,
|
|
29
|
-
getValue: () => this.httpServer.connectedSocketsCount
|
|
30
|
-
}
|
|
29
|
+
getValue: () => this.httpServer.connectedSocketsCount,
|
|
30
|
+
},
|
|
31
31
|
};
|
|
32
32
|
constructor() {
|
|
33
33
|
super('WebServer');
|
|
@@ -55,7 +55,7 @@ let WebServerModule = class WebServerModule extends ModuleBase {
|
|
|
55
55
|
};
|
|
56
56
|
WebServerModule = __decorate([
|
|
57
57
|
Singleton({
|
|
58
|
-
defaultArgumentProvider: () => webServerModuleConfiguration
|
|
58
|
+
defaultArgumentProvider: () => webServerModuleConfiguration,
|
|
59
59
|
}),
|
|
60
60
|
__metadata("design:paramtypes", [])
|
|
61
61
|
], WebServerModule);
|
package/orm/server/database.d.ts
CHANGED
|
@@ -20,8 +20,4 @@ export type DatabaseArgument = PoolConfig;
|
|
|
20
20
|
export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
|
|
21
21
|
readonly [resolveArgumentType]?: DatabaseArgument;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Re-exports the `migrate` function from `drizzle-orm/node-postgres/migrator`
|
|
25
|
-
* for running database migrations.
|
|
26
|
-
*/
|
|
27
23
|
export { migrate };
|
package/orm/server/database.js
CHANGED
|
@@ -68,7 +68,8 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
68
68
|
const indexFn = (data.options?.unique == true) ? uniqueIndex : index;
|
|
69
69
|
let builder = indexFn(data.name ?? getIndexName(tableName, columns, { naming: data.options?.naming })).using(data.options?.using ?? 'btree', ...columns);
|
|
70
70
|
if (isDefined(data.options?.where)) {
|
|
71
|
-
|
|
71
|
+
const query = convertQuery(data.options.where(table), table, columnDefinitionsMap);
|
|
72
|
+
builder = builder.where(query.inlineParams());
|
|
72
73
|
}
|
|
73
74
|
return builder;
|
|
74
75
|
}
|
|
@@ -76,7 +77,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
76
77
|
const columns = primaryKeyColumnDefinitions.map((columnDefinition) => getColumn(table, columnDefinition.name));
|
|
77
78
|
return primaryKey({
|
|
78
79
|
name: mergedTableReflectionData.compundPrimaryKeyName ?? getPrimaryKeyName(tableName, columns, { naming: mergedTableReflectionData.compundPrimaryKeyNaming }),
|
|
79
|
-
columns
|
|
80
|
+
columns,
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
const primaryKeyColumnDefinitions = columnDefinitions.filter((columnDefinition) => columnDefinition.reflectionData?.primaryKey == true);
|
|
@@ -102,7 +103,7 @@ export function _getDrizzleTableFromType(type, fallbackSchemaName) {
|
|
|
102
103
|
return constraint;
|
|
103
104
|
}),
|
|
104
105
|
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.index).filter(isDefined).map((data) => buildIndex(table, data)),
|
|
105
|
-
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table)))
|
|
106
|
+
...tableReflectionDatas.flatMap((tableReflectionData) => tableReflectionData.checks).filter(isDefined).map((data) => check(data.name, data.builder(table))),
|
|
106
107
|
]);
|
|
107
108
|
drizzleSchema[columnDefinitionsSymbol] = columnDefinitions;
|
|
108
109
|
drizzleSchema[columnDefinitionsMapSymbol] = columnDefinitionsMap;
|
|
@@ -144,7 +145,7 @@ function getPostgresColumnEntries(type, dbSchema, tableName, path = new JsonPath
|
|
|
144
145
|
buildType: (options) => getPostgresColumn(tableName, toSnakeCase(prefixedColumnName), dbSchema, schema, columnReflectionData ?? {}, options, { type, property }),
|
|
145
146
|
dereferenceObjectPath: compileDereferencer(objectPath, { optional: true }),
|
|
146
147
|
toDatabase,
|
|
147
|
-
fromDatabase
|
|
148
|
+
fromDatabase,
|
|
148
149
|
}];
|
|
149
150
|
});
|
|
150
151
|
return entries;
|
package/orm/server/module.d.ts
CHANGED
|
@@ -8,19 +8,15 @@ import type { PoolConfig } from 'pg';
|
|
|
8
8
|
import { EntityRepositoryConfig } from './repository.js';
|
|
9
9
|
/**
|
|
10
10
|
* Configuration class for the database connection.
|
|
11
|
-
* Holds the `pg.PoolConfig`.
|
|
12
11
|
*/
|
|
13
12
|
export declare class DatabaseConfig {
|
|
14
|
-
/** Optional PostgreSQL pool configuration. */
|
|
15
13
|
connection?: PoolConfig;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Options for configuring the ORM module using `configureOrm`.
|
|
19
17
|
*/
|
|
20
18
|
export type OrmModuleOptions = {
|
|
21
|
-
/** Optional PostgreSQL pool configuration. */
|
|
22
19
|
connection?: PoolConfig;
|
|
23
|
-
/** Optional configuration for entity repositories. */
|
|
24
20
|
repositoryConfig?: EntityRepositoryConfig;
|
|
25
21
|
};
|
|
26
22
|
/**
|
package/orm/server/module.js
CHANGED
|
@@ -4,10 +4,8 @@ import { EntityRepositoryConfig } from './repository.js';
|
|
|
4
4
|
import { ENCRYPTION_SECRET } from './tokens.js';
|
|
5
5
|
/**
|
|
6
6
|
* Configuration class for the database connection.
|
|
7
|
-
* Holds the `pg.PoolConfig`.
|
|
8
7
|
*/
|
|
9
8
|
export class DatabaseConfig {
|
|
10
|
-
/** Optional PostgreSQL pool configuration. */
|
|
11
9
|
connection;
|
|
12
10
|
}
|
|
13
11
|
/**
|
|
@@ -8,7 +8,6 @@ import { and, eq, gt, gte, inArray, isNotNull, isNull, isSQLWrapper, lt, lte, ne
|
|
|
8
8
|
import { NotSupportedError } from '../../errors/not-supported.error.js';
|
|
9
9
|
import { hasOwnProperty, objectEntries } from '../../utils/object/object.js';
|
|
10
10
|
import { assertDefinedPass, isPrimitive, isRegExp, isString, isUndefined } from '../../utils/type-guards.js';
|
|
11
|
-
/** SQL fragment representing `true`. */
|
|
12
11
|
const sqlTrue = sql `true`;
|
|
13
12
|
/**
|
|
14
13
|
* Converts a query object into a Drizzle SQL condition.
|
|
@@ -22,65 +21,53 @@ const sqlTrue = sql `true`;
|
|
|
22
21
|
* @throws {Error} If an unsupported query type is encountered.
|
|
23
22
|
*/
|
|
24
23
|
export function convertQuery(query, table, columnDefinitionsMap) {
|
|
25
|
-
// If the query is already a Drizzle SQL object, return it directly.
|
|
26
24
|
if (query instanceof SQL) {
|
|
27
25
|
return query;
|
|
28
26
|
}
|
|
29
|
-
// If the query is a SQLWrapper, convert it to a Drizzle SQL object.
|
|
30
27
|
if (isSQLWrapper(query)) {
|
|
31
28
|
return sql `${query}`;
|
|
32
29
|
}
|
|
33
30
|
const queryEntries = objectEntries(query);
|
|
34
|
-
// If the query object is empty, return true.
|
|
35
31
|
if (queryEntries.length == 0) {
|
|
36
32
|
return sqlTrue;
|
|
37
33
|
}
|
|
38
34
|
const conditions = [];
|
|
39
35
|
for (const [property, value] of queryEntries) {
|
|
40
|
-
// Handle logical AND operator
|
|
41
36
|
if (property == '$and') {
|
|
42
37
|
if (queryEntries.length > 1) {
|
|
43
38
|
throw new Error('only one logical operator per level allowed');
|
|
44
39
|
}
|
|
45
40
|
const andQuery = and(...query.$and.map((item) => convertQuery(item, table, columnDefinitionsMap)));
|
|
46
|
-
// If $and array is empty or results in no conditions, return true.
|
|
47
41
|
if (isUndefined(andQuery)) {
|
|
48
42
|
return sqlTrue;
|
|
49
43
|
}
|
|
50
44
|
return andQuery;
|
|
51
45
|
}
|
|
52
|
-
// Handle logical OR operator
|
|
53
46
|
if (property == '$or') {
|
|
54
47
|
if (queryEntries.length > 1) {
|
|
55
48
|
throw new Error('only one logical operator per level allowed');
|
|
56
49
|
}
|
|
57
50
|
const orQuery = or(...query.$or.map((item) => convertQuery(item, table, columnDefinitionsMap)));
|
|
58
|
-
// If $or array is empty or results in no conditions, return true.
|
|
59
51
|
if (isUndefined(orQuery)) {
|
|
60
52
|
return sqlTrue;
|
|
61
53
|
}
|
|
62
54
|
return orQuery;
|
|
63
55
|
}
|
|
64
|
-
// Handle logical NOR operator
|
|
65
56
|
if (property == '$nor') {
|
|
66
57
|
if (queryEntries.length > 1) {
|
|
67
58
|
throw new Error('only one logical operator per level allowed');
|
|
68
59
|
}
|
|
69
60
|
const orQuery = or(...query.$nor.map((item) => convertQuery(item, table, columnDefinitionsMap)));
|
|
70
|
-
// If $nor array is empty or results in no conditions, return true (NOT false -> true).
|
|
71
61
|
if (isUndefined(orQuery)) {
|
|
72
62
|
return sqlTrue;
|
|
73
63
|
}
|
|
74
64
|
return not(orQuery);
|
|
75
65
|
}
|
|
76
|
-
// Map property name to column definition and get the Drizzle column object.
|
|
77
66
|
const columnDef = assertDefinedPass(columnDefinitionsMap.get(property), `Could not map property ${property} to column.`);
|
|
78
67
|
const column = table[columnDef.name];
|
|
79
|
-
// Get the condition for the current property and value.
|
|
80
68
|
const condition = getCondition(property, value, column);
|
|
81
69
|
conditions.push(condition);
|
|
82
70
|
}
|
|
83
|
-
// Combine all conditions with AND.
|
|
84
71
|
return and(...conditions);
|
|
85
72
|
}
|
|
86
73
|
/**
|
|
@@ -95,79 +82,65 @@ export function convertQuery(query, table, columnDefinitionsMap) {
|
|
|
95
82
|
*/
|
|
96
83
|
function getCondition(property, value, column) {
|
|
97
84
|
const isPrimitiveValue = isPrimitive(value);
|
|
98
|
-
// Handle equality ($eq or direct primitive value)
|
|
99
85
|
if (isPrimitiveValue || hasOwnProperty(value, '$eq')) {
|
|
100
86
|
const queryValue = isPrimitiveValue ? value : value.$eq;
|
|
101
87
|
if (queryValue === null) {
|
|
102
|
-
return isNull(column);
|
|
88
|
+
return isNull(column);
|
|
103
89
|
}
|
|
104
|
-
return eq(column, queryValue);
|
|
90
|
+
return eq(column, queryValue);
|
|
105
91
|
}
|
|
106
|
-
// Handle inequality ($neq)
|
|
107
92
|
if (hasOwnProperty(value, '$neq')) {
|
|
108
93
|
const queryValue = value.$neq;
|
|
109
94
|
if (queryValue === null) {
|
|
110
|
-
return isNotNull(column);
|
|
95
|
+
return isNotNull(column);
|
|
111
96
|
}
|
|
112
|
-
return ne(column, queryValue);
|
|
97
|
+
return ne(column, queryValue);
|
|
113
98
|
}
|
|
114
99
|
// $exists is not supported
|
|
115
100
|
if (hasOwnProperty(value, '$exists')) {
|
|
116
101
|
throw new NotSupportedError('$exists is not supported.');
|
|
117
102
|
}
|
|
118
|
-
// Handle $in operator
|
|
119
103
|
if (hasOwnProperty(value, '$in')) {
|
|
120
104
|
const queryValue = value.$in;
|
|
121
|
-
return inArray(column, queryValue);
|
|
105
|
+
return inArray(column, queryValue);
|
|
122
106
|
}
|
|
123
|
-
// Handle $nin operator
|
|
124
107
|
if (hasOwnProperty(value, '$nin')) {
|
|
125
108
|
const queryValue = value.$nin;
|
|
126
|
-
return notInArray(column, queryValue);
|
|
109
|
+
return notInArray(column, queryValue);
|
|
127
110
|
}
|
|
128
|
-
// Handle $lt operator
|
|
129
111
|
if (hasOwnProperty(value, '$lt')) {
|
|
130
112
|
const queryValue = value.$lt;
|
|
131
|
-
return lt(column, queryValue);
|
|
113
|
+
return lt(column, queryValue);
|
|
132
114
|
}
|
|
133
|
-
// Handle $lte operator
|
|
134
115
|
if (hasOwnProperty(value, '$lte')) {
|
|
135
116
|
const queryValue = value.$lte;
|
|
136
|
-
return lte(column, queryValue);
|
|
117
|
+
return lte(column, queryValue);
|
|
137
118
|
}
|
|
138
|
-
// Handle $gt operator
|
|
139
119
|
if (hasOwnProperty(value, '$gt')) {
|
|
140
120
|
const queryValue = value.$gt;
|
|
141
|
-
return gt(column, queryValue);
|
|
121
|
+
return gt(column, queryValue);
|
|
142
122
|
}
|
|
143
|
-
// Handle $gte operator
|
|
144
123
|
if (hasOwnProperty(value, '$gte')) {
|
|
145
124
|
const queryValue = value.$gte;
|
|
146
|
-
return gte(column, queryValue);
|
|
125
|
+
return gte(column, queryValue);
|
|
147
126
|
}
|
|
148
|
-
// Handle $regex operator (using PostgreSQL regexp_like)
|
|
149
127
|
if (hasOwnProperty(value, '$regex')) {
|
|
150
128
|
const queryValue = value.$regex;
|
|
151
|
-
// Normalize RegExp or string input
|
|
152
129
|
const regexp = isString(queryValue)
|
|
153
130
|
? ({ value: queryValue })
|
|
154
131
|
: isRegExp(queryValue)
|
|
155
132
|
? ({ flags: queryValue.flags, value: queryValue.source })
|
|
156
133
|
: ({ flags: queryValue.flags, value: queryValue.pattern });
|
|
157
|
-
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
134
|
+
return sql `regexp_like(${column}, ${regexp.value}, ${regexp.flags})`;
|
|
158
135
|
}
|
|
159
|
-
// $text is not supported
|
|
160
136
|
if (hasOwnProperty(value, '$text')) {
|
|
161
137
|
throw new NotSupportedError('$text is not supported.');
|
|
162
138
|
}
|
|
163
|
-
// $geoShape is not supported
|
|
164
139
|
if (hasOwnProperty(value, '$geoShape')) {
|
|
165
140
|
throw new NotSupportedError('$geoShape is not supported.');
|
|
166
141
|
}
|
|
167
|
-
// $geoDistance is not supported
|
|
168
142
|
if (hasOwnProperty(value, '$geoDistance')) {
|
|
169
143
|
throw new NotSupportedError('$geoDistance is not supported.');
|
|
170
144
|
}
|
|
171
|
-
// Throw if the query structure is unrecognized
|
|
172
145
|
throw new Error(`Unsupported query type "${property}".`);
|
|
173
146
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
2
|
import type { PgColumn, PgInsertValue, PgUpdateSetSource } from 'drizzle-orm/pg-core';
|
|
3
|
+
import { type InjectOptions } from '../../injector/inject.js';
|
|
3
4
|
import { type Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
4
|
-
import type { DeepPartial, OneOrMany, Paths, Type } from '../../types.js';
|
|
5
|
+
import type { DeepPartial, OneOrMany, Paths, Type, TypedOmit } from '../../types.js';
|
|
5
6
|
import type { UntaggedDeep } from '../../types/index.js';
|
|
6
7
|
import { Entity, type EntityMetadataAttributes, type EntityType, type EntityWithoutMetadata } from '../entity.js';
|
|
7
8
|
import type { Query } from '../query.js';
|
|
@@ -476,7 +477,7 @@ export declare class EntityRepository<T extends Entity | EntityWithoutMetadata =
|
|
|
476
477
|
* @param type The entity type.
|
|
477
478
|
* @returns An EntityRepository instance for the specified type.
|
|
478
479
|
*/
|
|
479
|
-
export declare function injectRepository<T extends Entity | EntityWithoutMetadata>(type: EntityType<T>): EntityRepository<T>;
|
|
480
|
+
export declare function injectRepository<T extends Entity | EntityWithoutMetadata>(type: EntityType<T>, options?: TypedOmit<InjectOptions<EntityRepository<T>, undefined>, 'optional'>): EntityRepository<T>;
|
|
480
481
|
/**
|
|
481
482
|
* Gets or creates a singleton EntityRepository class for the specified entity type.
|
|
482
483
|
* @template T The entity type.
|
package/orm/server/repository.js
CHANGED
|
@@ -860,8 +860,8 @@ export { EntityRepository };
|
|
|
860
860
|
* @param type The entity type.
|
|
861
861
|
* @returns An EntityRepository instance for the specified type.
|
|
862
862
|
*/
|
|
863
|
-
export function injectRepository(type) {
|
|
864
|
-
return inject((EntityRepository), type);
|
|
863
|
+
export function injectRepository(type, options) {
|
|
864
|
+
return inject((EntityRepository), type, options);
|
|
865
865
|
}
|
|
866
866
|
/**
|
|
867
867
|
* Gets or creates a singleton EntityRepository class for the specified entity type.
|
|
@@ -4,19 +4,20 @@ import type { Record } from '../../types.js';
|
|
|
4
4
|
import type { Database } from './database.js';
|
|
5
5
|
export type PgTransaction = DrizzlePgTransaction<PgQueryResultHKT, Record, Record>;
|
|
6
6
|
export type TransactionConfig = PgTransactionConfig;
|
|
7
|
-
export declare abstract class Transaction {
|
|
7
|
+
export declare abstract class Transaction implements AsyncDisposable {
|
|
8
8
|
#private;
|
|
9
9
|
readonly afterCommit$: import("rxjs").Observable<void>;
|
|
10
10
|
manualCommit: boolean;
|
|
11
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
11
12
|
withManualCommit(): void;
|
|
12
13
|
/**
|
|
13
14
|
* Enters automatic transaction handling. Transaction will be commited when all use-calls are done or rolled back when one throws.
|
|
14
15
|
*/
|
|
15
16
|
use<T>(handler: () => Promise<T>): Promise<T>;
|
|
16
17
|
commit(): Promise<void>;
|
|
17
|
-
rollback(): void
|
|
18
|
-
protected abstract _commit(): Promise<void>;
|
|
19
|
-
protected abstract _rollback(): void
|
|
18
|
+
rollback(): Promise<void>;
|
|
19
|
+
protected abstract _commit(): void | Promise<void>;
|
|
20
|
+
protected abstract _rollback(): void | Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
export declare class DrizzleTransaction extends Transaction {
|
|
22
23
|
readonly pgTransaction: PgTransaction;
|