@tstdl/base 0.85.16 → 0.85.17

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.
@@ -1,5 +1,5 @@
1
- import { Collection } from './collection.js';
2
- export declare class SetCollection<T> extends Collection<T, SetCollection<T>> implements globalThis.Set<T> {
1
+ import { DistinctCollection } from './distinct-collection.js';
2
+ export declare class SetCollection<T> extends DistinctCollection<T, SetCollection<T>> implements globalThis.Set<T> {
3
3
  private readonly backingSet;
4
4
  readonly [Symbol.toStringTag]: string;
5
5
  constructor(items?: Iterable<T>);
@@ -21,8 +21,8 @@ __export(set_collection_exports, {
21
21
  SetCollection: () => SetCollection
22
22
  });
23
23
  module.exports = __toCommonJS(set_collection_exports);
24
- var import_collection = require("./collection.js");
25
- class SetCollection extends import_collection.Collection {
24
+ var import_distinct_collection = require("./distinct-collection.js");
25
+ class SetCollection extends import_distinct_collection.DistinctCollection {
26
26
  backingSet;
27
27
  [Symbol.toStringTag] = "Set";
28
28
  constructor(items) {
@@ -1,10 +1,15 @@
1
1
  import type { Decorator } from '../reflection/index.js';
2
- import type { Constructor, Simplify, TypedOmit } from '../types.js';
2
+ import type { Constructor, OneOrMany, Simplify, TypedOmit } from '../types.js';
3
+ import type { Provider } from './provider.js';
3
4
  import type { InjectionToken } from './token.js';
4
- import type { InjectableMetadata } from './type-info.js';
5
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
6
- type InjectDecorator = Decorator<'property' | 'accessor' | 'constructorParameter'>;
7
- export type InjectableOptions<T, A> = InjectableMetadata<T, A>;
5
+ import type { ArgumentProvider, ForwardRefInjectionToken, Mapper, RegistrationOptions } from './types.js';
6
+ type InjectDecorator = Decorator<'accessor' | 'constructorParameter'>;
7
+ export type InjectableOptions<T, A> = RegistrationOptions<T, A> & {
8
+ /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
9
+ alias?: OneOrMany<InjectionToken>;
10
+ /** custom provider. Useful for example if initialization is required */
11
+ provider?: Provider<T, A>;
12
+ };
8
13
  export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<InjectableOptions<T, A>, 'lifecycle'>>;
9
14
  /**
10
15
  * Helper decorator to replace a class definition with an other
@@ -13,7 +18,7 @@ export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<Injecta
13
18
  */
14
19
  export declare function ReplaceClass<T>(constructor: Constructor<T>): ClassDecorator;
15
20
  /**
16
- * registers the class in the global container. Decorated class is not modified in any way
21
+ * Globally registers the class for injection
17
22
  * @param options registration options
18
23
  */
19
24
  export declare function Injectable<T = any, A = any>(options?: InjectableOptions<T, A>): ClassDecorator;
@@ -41,16 +41,16 @@ function ReplaceClass(constructor) {
41
41
  }
42
42
  function Injectable(options = {}) {
43
43
  return (0, import_reflection.createClassDecorator)({
44
- data: { [import_symbols.injectableMetadataSymbol]: options },
44
+ data: { [import_symbols.injectableMetadataSymbol]: {} },
45
45
  mergeData: true,
46
46
  handler: (data) => {
47
47
  const { alias: aliases, provider, ...registrationOptions } = options;
48
48
  const token = data.constructor;
49
49
  const targetProvider = provider ?? { useClass: token };
50
- import_injector.Injector.registerGlobal(token, targetProvider, registrationOptions);
50
+ import_injector.Injector.register(token, targetProvider, registrationOptions);
51
51
  if ((0, import_type_guards.isDefined)(aliases)) {
52
52
  for (const alias of (0, import_array.toArray)(aliases)) {
53
- import_injector.Injector.registerGlobal(alias, { useToken: token }, registrationOptions);
53
+ import_injector.Injector.register(alias, { useToken: token }, registrationOptions);
54
54
  }
55
55
  }
56
56
  }
@@ -43,19 +43,19 @@ export declare class Injector {
43
43
  readonly name: string;
44
44
  constructor(name: string, parent?: Injector | null);
45
45
  /**
46
- * Register a provider for a token
46
+ * Globally register a provider for a token
47
47
  * @param token token to register
48
48
  * @param provider provider used to resolve the token
49
49
  * @param options registration options
50
50
  */
51
- static registerGlobal<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
51
+ static register<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: RegistrationOptions<T, A>): void;
52
52
  /**
53
- * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
53
+ * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
54
54
  * @param token token to register
55
55
  * @param provider provider used to resolve the token
56
56
  * @param options registration options
57
57
  */
58
- static registerGlobalSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
58
+ static registerSingleton<T, A = any>(token: InjectionToken<T, A>, provider: Provider<T, A>, options?: TypedOmit<RegistrationOptions<T, A>, 'lifecycle'>): void;
59
59
  fork(name: string): Injector;
60
60
  /**
61
61
  * Register a provider for a token
@@ -48,12 +48,12 @@ class Injector {
48
48
  this.register(Injector, { useValue: this });
49
49
  }
50
50
  /**
51
- * Register a provider for a token
51
+ * Globally register a provider for a token
52
52
  * @param token token to register
53
53
  * @param provider provider used to resolve the token
54
54
  * @param options registration options
55
55
  */
56
- static registerGlobal(token, provider, options = {}) {
56
+ static register(token, provider, options = {}) {
57
57
  const registration = {
58
58
  token,
59
59
  provider,
@@ -62,13 +62,13 @@ class Injector {
62
62
  addRegistration(Injector.#globalRegistrations, registration);
63
63
  }
64
64
  /**
65
- * Register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
65
+ * Globally register a provider for a token as a singleton. Alias for {@link register} with `singleton` lifecycle
66
66
  * @param token token to register
67
67
  * @param provider provider used to resolve the token
68
68
  * @param options registration options
69
69
  */
70
- static registerGlobalSingleton(token, provider, options) {
71
- Injector.registerGlobal(token, provider, { ...options, lifecycle: "singleton" });
70
+ static registerSingleton(token, provider, options) {
71
+ Injector.register(token, provider, { ...options, lifecycle: "singleton" });
72
72
  }
73
73
  fork(name) {
74
74
  return new Injector(name, this);
@@ -1,13 +1,5 @@
1
- import type { OneOrMany } from '../types.js';
2
- import type { Provider } from './provider.js';
3
1
  import type { InjectionToken } from './token.js';
4
- import type { ArgumentProvider, ForwardRefInjectionToken, Mapper, RegistrationOptions } from './types.js';
5
- export type InjectableMetadata<T, A> = RegistrationOptions<T, A> & {
6
- /** aliases (tokens) for the class. Useful for example for circular dependencies when you can't use the class itself as a token */
7
- alias?: OneOrMany<InjectionToken>;
8
- /** custom provider. Useful for example if initialization is required */
9
- provider?: Provider<T, A>;
10
- };
2
+ import type { ArgumentProvider, ForwardRefInjectionToken, Mapper } from './types.js';
11
3
  export type InjectMetadata = {
12
4
  /** token overwrite by inject decorator */
13
5
  injectToken?: InjectionToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.85.16",
3
+ "version": "0.85.17",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"