@tstdl/base 0.93.17 → 0.93.18
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/injector/decorators.js +6 -3
- package/injector/injector.js +19 -19
- package/orm/data-types/numeric-date.js +6 -2
- package/package.json +1 -1
package/injector/decorators.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createClassDecorator, createDecorator, reflectionRegistry } from '../reflection/index.js';
|
|
3
3
|
import { toArray } from '../utils/array/array.js';
|
|
4
4
|
import { filterObject } from '../utils/object/object.js';
|
|
5
|
-
import { isArray, isDefined, isFunction, isNotNull } from '../utils/type-guards.js';
|
|
5
|
+
import { isArray, isDefined, isFunction, isNotNull, isPromise } from '../utils/type-guards.js';
|
|
6
6
|
import { Injector } from './injector.js';
|
|
7
7
|
import { injectMetadataSymbol, injectableMetadataSymbol, injectableOptionsSymbol } from './symbols.js';
|
|
8
8
|
/**
|
|
@@ -46,8 +46,11 @@ export function Injectable(options = {}) {
|
|
|
46
46
|
...registrationOptions,
|
|
47
47
|
providers: [...(optionsToInherit.providers ?? []), ...(registrationOptions.providers ?? [])],
|
|
48
48
|
afterResolve: (instance, argument, context) => {
|
|
49
|
-
optionsToInherit.afterResolve?.(instance, argument, context);
|
|
50
|
-
|
|
49
|
+
const result1 = optionsToInherit.afterResolve?.(instance, argument, context);
|
|
50
|
+
if (isPromise(result1)) {
|
|
51
|
+
return result1.then(async () => await registrationOptions.afterResolve?.(instance, argument, context)); // eslint-disable-line @typescript-eslint/no-unsafe-return
|
|
52
|
+
}
|
|
53
|
+
return registrationOptions.afterResolve?.(instance, argument, context);
|
|
51
54
|
},
|
|
52
55
|
metadata: {
|
|
53
56
|
...optionsToInherit.metadata,
|
package/injector/injector.js
CHANGED
|
@@ -321,33 +321,33 @@ export class Injector {
|
|
|
321
321
|
_resolveRegistration(registration, argument, options, context, chain) {
|
|
322
322
|
checkOverflow(chain, context);
|
|
323
323
|
const { token, provider, providers } = registration;
|
|
324
|
+
const resolutionTag = Symbol('ResolutionTag');
|
|
325
|
+
const resolutionScoped = registration.options.lifecycle == 'resolution';
|
|
326
|
+
const injectorScoped = registration.options.lifecycle == 'injector';
|
|
327
|
+
const singletonScoped = registration.options.lifecycle == 'singleton';
|
|
328
|
+
let resolveArgument = argument ?? registration.options.defaultArgument;
|
|
329
|
+
if (isUndefined(resolveArgument) && isFunction(registration.options.defaultArgumentProvider)) {
|
|
330
|
+
resolveArgument = wrapInResolveError(() => registration.options.defaultArgumentProvider(this.getResolveContext(resolutionTag, context, chain)), 'Error in defaultArgumentProvider', chain);
|
|
331
|
+
}
|
|
332
|
+
const argumentIdentity = resolveArgumentIdentity(registration, resolveArgument, chain);
|
|
333
|
+
if (resolutionScoped && context.resolutionScopedResolutions.hasFlat(token, argumentIdentity)) {
|
|
334
|
+
return context.resolutionScopedResolutions.getFlat(token, argumentIdentity).value;
|
|
335
|
+
}
|
|
336
|
+
else if (injectorScoped && this.#injectorScopedResolutions.hasFlat(token, argumentIdentity)) {
|
|
337
|
+
return this.#injectorScopedResolutions.getFlat(token, argumentIdentity).value;
|
|
338
|
+
}
|
|
339
|
+
else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
|
|
340
|
+
return registration.resolutions.get(argumentIdentity);
|
|
341
|
+
}
|
|
324
342
|
// A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
|
|
325
343
|
const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
|
|
326
344
|
const injector = needsNewScope ? this.fork('ResolutionInjector') : this;
|
|
327
345
|
for (const nestedProvider of providers) {
|
|
328
346
|
injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
|
|
329
347
|
}
|
|
330
|
-
const injectionContext = injector.getInjectionContext(context,
|
|
348
|
+
const injectionContext = injector.getInjectionContext(context, resolveArgument, chain);
|
|
331
349
|
const previousInjectionContext = setCurrentInjectionContext(injectionContext);
|
|
332
|
-
const resolutionTag = Symbol('ResolutionTag');
|
|
333
350
|
try {
|
|
334
|
-
const resolutionScoped = registration.options.lifecycle == 'resolution';
|
|
335
|
-
const injectorScoped = registration.options.lifecycle == 'injector';
|
|
336
|
-
const singletonScoped = registration.options.lifecycle == 'singleton';
|
|
337
|
-
let resolveArgument = argument ?? registration.options.defaultArgument;
|
|
338
|
-
if (isUndefined(resolveArgument) && isFunction(registration.options.defaultArgumentProvider)) {
|
|
339
|
-
resolveArgument = wrapInResolveError(() => registration.options.defaultArgumentProvider(injector.getResolveContext(resolutionTag, context, chain)), 'Error in defaultArgumentProvider', chain);
|
|
340
|
-
}
|
|
341
|
-
const argumentIdentity = resolveArgumentIdentity(registration, resolveArgument, chain);
|
|
342
|
-
if (resolutionScoped && context.resolutionScopedResolutions.hasFlat(token, argumentIdentity)) {
|
|
343
|
-
return context.resolutionScopedResolutions.getFlat(token, argumentIdentity).value;
|
|
344
|
-
}
|
|
345
|
-
else if (injectorScoped && this.#injectorScopedResolutions.hasFlat(token, argumentIdentity)) {
|
|
346
|
-
return this.#injectorScopedResolutions.getFlat(token, argumentIdentity).value;
|
|
347
|
-
}
|
|
348
|
-
else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
|
|
349
|
-
return registration.resolutions.get(argumentIdentity);
|
|
350
|
-
}
|
|
351
351
|
const resolutionContext = { afterResolveRegistrations: [] };
|
|
352
352
|
const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain);
|
|
353
353
|
const resolution = {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* using numeric representation (YYYYMMDD).
|
|
5
5
|
*/
|
|
6
6
|
import { customType } from 'drizzle-orm/pg-core';
|
|
7
|
-
import { dateToNumericDate,
|
|
7
|
+
import { dateToNumericDate, numericDateToDateObject } from '../../utils/date-time.js';
|
|
8
8
|
/**
|
|
9
9
|
* Custom Drizzle type for PostgreSQL `date` columns, storing dates as numeric values (YYYYMMDD).
|
|
10
10
|
* Converts between JavaScript `number` (YYYYMMDD) and database `date` (ISO string).
|
|
@@ -14,7 +14,11 @@ export const numericDate = customType({
|
|
|
14
14
|
return 'date';
|
|
15
15
|
},
|
|
16
16
|
toDriver(value) {
|
|
17
|
-
|
|
17
|
+
const { year, month, day } = numericDateToDateObject(value);
|
|
18
|
+
const yearString = year.toString().padStart(4, '0');
|
|
19
|
+
const monthString = month.toString().padStart(2, '0');
|
|
20
|
+
const dayString = day.toString().padStart(2, '0');
|
|
21
|
+
return `${yearString}-${monthString}-${dayString}`;
|
|
18
22
|
},
|
|
19
23
|
fromDriver(value) {
|
|
20
24
|
const date = new Date(value);
|