@tstdl/base 0.93.16 → 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.
@@ -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
- registrationOptions.afterResolve?.(instance, argument, context);
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,
@@ -320,32 +320,34 @@ export class Injector {
320
320
  }
321
321
  _resolveRegistration(registration, argument, options, context, chain) {
322
322
  checkOverflow(chain, context);
323
- const { token, providers } = registration;
324
- const injector = this.fork('ResolutionInjector');
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
+ }
342
+ // A new scope is only needed if we are instantiating a class, running a factory, or if the registration explicitly defines scoped providers.
343
+ const needsNewScope = isClassProvider(provider) || isFactoryProvider(provider) || (providers.length > 0);
344
+ const injector = needsNewScope ? this.fork('ResolutionInjector') : this;
325
345
  for (const nestedProvider of providers) {
326
346
  injector.registerSingleton(nestedProvider.provide, nestedProvider, { multi: nestedProvider.multi });
327
347
  }
328
- const injectionContext = injector.getInjectionContext(context, argument, chain);
348
+ const injectionContext = injector.getInjectionContext(context, resolveArgument, chain);
329
349
  const previousInjectionContext = setCurrentInjectionContext(injectionContext);
330
- const resolutionTag = Symbol('ResolutionTag');
331
350
  try {
332
- const resolutionScoped = registration.options.lifecycle == 'resolution';
333
- const injectorScoped = registration.options.lifecycle == 'injector';
334
- const singletonScoped = registration.options.lifecycle == 'singleton';
335
- let resolveArgument = argument ?? registration.options.defaultArgument;
336
- if (isUndefined(resolveArgument) && isFunction(registration.options.defaultArgumentProvider)) {
337
- resolveArgument = wrapInResolveError(() => registration.options.defaultArgumentProvider(injector.getResolveContext(resolutionTag, context, chain)), 'Error in defaultArgumentProvider', chain);
338
- }
339
- const argumentIdentity = resolveArgumentIdentity(registration, resolveArgument, chain);
340
- if (resolutionScoped && context.resolutionScopedResolutions.hasFlat(token, argumentIdentity)) {
341
- return context.resolutionScopedResolutions.getFlat(token, argumentIdentity).value;
342
- }
343
- else if (injectorScoped && this.#injectorScopedResolutions.hasFlat(token, argumentIdentity)) {
344
- return this.#injectorScopedResolutions.getFlat(token, argumentIdentity).value;
345
- }
346
- else if (singletonScoped && registration.resolutions.has(argumentIdentity)) {
347
- return registration.resolutions.get(argumentIdentity);
348
- }
349
351
  const resolutionContext = { afterResolveRegistrations: [] };
350
352
  const value = injector._resolveProvider(resolutionTag, registration, resolveArgument, options, context, resolutionContext, injectionContext, chain);
351
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, numericDateToDate } from '../../utils/date-time.js';
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
- return numericDateToDate(value).toISOString();
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.16",
3
+ "version": "0.93.18",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"