@tstdl/base 0.87.9 → 0.87.11

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.
@@ -38,7 +38,7 @@ function configureAuthenticationClient(config, injector = (0, import_inject.getC
38
38
  if ((0, import_type_guards.isDefined)(config.registerMiddleware)) {
39
39
  (injector ?? import_injector.Injector).register(import_tokens.HTTP_CLIENT_MIDDLEWARE, {
40
40
  useFactory(_, context) {
41
- const authenticationService = context.resolve(import_authentication_service.AuthenticationService, void 0, { forwardRef: true });
41
+ const authenticationService = context.resolve(import_authentication_service.AuthenticationService, void 0, { forwardRef: true, forwardRefTypeHint: "object" });
42
42
  return (0, import_http_client_middleware.waitForAuthenticationCredentialsMiddleware)(authenticationService);
43
43
  }
44
44
  }, { multi: true });
@@ -2,6 +2,7 @@ import type { Decorator } from '../reflection/index.js';
2
2
  import type { Constructor, OneOrMany, Record, Simplify, TypedOmit } from '../types.js';
3
3
  import type { Provider } from './provider.js';
4
4
  import type { InjectionToken } from './token.js';
5
+ import type { InjectMetadata } from './type-info.js';
5
6
  import type { ArgumentProvider, ForwardRefInjectionToken, Mapper, RegistrationOptions } from './types.js';
6
7
  export type InjectDecorator = Decorator<'accessor' | 'constructorParameter'>;
7
8
  export type InjectableOptions<T, A, C extends Record = Record> = RegistrationOptions<T, A, C> & {
@@ -78,4 +79,4 @@ export declare function Optional(): InjectDecorator;
78
79
  * @param token token to resolve
79
80
  * @param argument resolve argument
80
81
  */
81
- export declare function ForwardRef<T extends object, A>(token?: ForwardRefInjectionToken<T>, argument?: A): InjectDecorator;
82
+ export declare function ForwardRef<T extends object, A>(token?: ForwardRefInjectionToken<T>, argument?: A, options?: Pick<InjectMetadata, 'forwardRefTypeHint'>): InjectDecorator;
@@ -106,9 +106,10 @@ function ForwardArg(mapper = (value) => value) {
106
106
  function Optional() {
107
107
  return createInjectDecorator({ optional: true });
108
108
  }
109
- function ForwardRef(token, argument) {
109
+ function ForwardRef(token, argument, options) {
110
110
  const injectMetadata = {
111
- forwardRef: token ?? true
111
+ forwardRef: token ?? true,
112
+ forwardRefTypeHint: options?.forwardRefTypeHint
112
113
  };
113
114
  if ((0, import_type_guards.isDefined)(argument)) {
114
115
  injectMetadata.resolveArgumentProvider = () => argument;
@@ -229,7 +229,7 @@ class Injector {
229
229
  _resolveAll(token, argument, options, context, chain) {
230
230
  this.assertNotDisposed();
231
231
  if ((0, import_type_guards.isDefined)(options.forwardRef) && options.forwardRef != false) {
232
- const forwardRef = import_forward_ref.ForwardRef.create();
232
+ const forwardRef = import_forward_ref.ForwardRef.create({ typeHint: options.forwardRefTypeHint });
233
233
  const forwardToken = (0, import_type_guards.isFunction)(options.forwardRef) ? options.forwardRef() : token;
234
234
  context.forwardRefQueue.add(() => import_forward_ref.ForwardRef.setRef(forwardRef, this._resolveAll(forwardToken, argument, { ...options, forwardRef: false }, context, chain.markAsForwardRef(forwardToken))));
235
235
  context.forwardRefs.add(forwardRef);
@@ -359,7 +359,7 @@ class Injector {
359
359
  });
360
360
  }
361
361
  const resolveFn = injectMetadata.resolveAll == true ? "_resolveAll" : "_resolve";
362
- const resolved = this[resolveFn](injectToken, parameterResolveArgument, { optional: injectMetadata.optional, forwardRef }, context, getChain(injectToken));
362
+ const resolved = this[resolveFn](injectToken, parameterResolveArgument, { optional: injectMetadata.optional, forwardRef, forwardRefTypeHint: injectMetadata.forwardRefTypeHint }, context, getChain(injectToken));
363
363
  return (0, import_type_guards.isDefined)(injectMetadata.mapper) ? injectMetadata.mapper(resolved) : resolved;
364
364
  }
365
365
  resolveInjection(token, argument, options, context, injectIndex, chain) {
@@ -1,3 +1,4 @@
1
+ import type { ForwardRefTypeHint } from '../utils/object/forward-ref.js';
1
2
  import type { InjectionToken } from './token.js';
2
3
  import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
3
4
  export type InjectMetadata = {
@@ -5,6 +6,7 @@ export type InjectMetadata = {
5
6
  injectToken?: InjectionToken;
6
7
  /** if defined, resolve the token or ForwardRefToken using ForwardRef strategy instead of resolving the token directly */
7
8
  forwardRef?: boolean | ForwardRefInjectionToken;
9
+ forwardRefTypeHint?: ForwardRefTypeHint;
8
10
  /** whether injection is optional if token is not registered. Set by optional decorator */
9
11
  optional?: boolean;
10
12
  /** whether injection should resolve all providers */
@@ -1,6 +1,7 @@
1
1
  import type { CancellationSignal } from '../cancellation/index.js';
2
2
  import type { AsyncDisposeHandler } from '../disposable/async-disposer.js';
3
3
  import type { Record } from '../types.js';
4
+ import type { ForwardRefTypeHint } from '../utils/object/forward-ref.js';
4
5
  import type { Injector } from './injector.js';
5
6
  import type { ResolveArgument } from './interfaces.js';
6
7
  import type { InjectionToken } from './token.js';
@@ -30,6 +31,7 @@ export type ResolveOptions<T, A> = {
30
31
  onlySelf?: boolean;
31
32
  /** If defined, resolve the token using ForwardRef strategy instead of resolving the token directly can be used to circumvent circular dependency problems */
32
33
  forwardRef?: boolean | ForwardRefInjectionToken<T, A>;
34
+ forwardRefTypeHint?: ForwardRefTypeHint;
33
35
  };
34
36
  /**
35
37
  * data to store between different stages like resolve and afterResolve
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.87.9",
3
+ "version": "0.87.11",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -30,6 +30,7 @@ __export(dynamic_text_model_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(dynamic_text_model_exports);
32
32
  var import_rxjs = require("rxjs");
33
+ var import_core = require("../core.js");
33
34
  var import_inject = require("../injector/inject.js");
34
35
  var import_api = require("../signals/api.js");
35
36
  var import_switch_map = require("../signals/switch-map.js");
@@ -37,7 +38,7 @@ var import_untracked_operator = require("../signals/untracked-operator.js");
37
38
  var import_type_guards = require("../utils/type-guards.js");
38
39
  var import_localization_service = require("./localization.service.js");
39
40
  const missingLocalizationKeyText = "[MISSING LOCALIZATION KEY]";
40
- function resolveDynamicText(text, localizationService = (0, import_inject.inject)(import_localization_service.LocalizationService)) {
41
+ function resolveDynamicText(text, localizationService = (0, import_inject.inject)(import_localization_service.LocalizationService, void 0, { optional: true }) ?? (0, import_core.getGlobalInjector)().resolve(import_localization_service.LocalizationService)) {
41
42
  const localizableTextSignal = (0, import_api.isSignal)(text) ? text : (0, import_rxjs.isObservable)(text) ? (0, import_api.toSignal)(text.pipe((0, import_untracked_operator.runInUntracked)()), { initialValue: missingLocalizationKeyText }) : (0, import_api.computed)(() => text);
42
43
  return (0, import_switch_map.switchMap)(() => {
43
44
  const localizableText = localizableTextSignal();
@@ -1,7 +1,10 @@
1
1
  declare const isForwardRef: unique symbol;
2
+ export type ForwardRefTypeHint = 'object' | 'function';
2
3
  export type ForwardRefOptions<T extends object = object> = {
3
4
  reference?: T;
4
5
  initializer?: () => T;
6
+ /** Due to limitations of Proxy, there can be some issues if proxy is created with a target of the "wrong" type. If possible, you should specify the type is forward ref is going to forward to. */
7
+ typeHint?: ForwardRefTypeHint;
5
8
  };
6
9
  export type ForwardRef<T extends object = object> = T & {
7
10
  [isForwardRef]: true;
@@ -54,8 +54,8 @@ const ForwardRef = {
54
54
  }
55
55
  };
56
56
  function getForwardRefProxy(context) {
57
- function forwardRef() {
58
- }
57
+ const target = context.typeHint == "function" ? function forwardRef() {
58
+ } : { forwardRef: true };
59
59
  const handler = {};
60
60
  for (const method of import_proxy.reflectMethods) {
61
61
  handler[method] = {
@@ -68,7 +68,7 @@ function getForwardRefProxy(context) {
68
68
  }
69
69
  }[method];
70
70
  }
71
- return new Proxy(forwardRef, handler);
71
+ return new Proxy(target, handler);
72
72
  }
73
73
  function getContext(options) {
74
74
  const reference = (0, import_type_guards.isDefined)(options?.reference) ? { value: options?.reference } : (0, import_type_guards.isDefined)(options?.initializer) ? { initializer: options?.initializer } : { value: void 0 };