@tstdl/base 0.85.15 → 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.
Files changed (42) hide show
  1. package/data-structures/array-list.d.ts +1 -1
  2. package/data-structures/array-list.js +4 -4
  3. package/data-structures/circular-buffer.js +5 -2
  4. package/data-structures/distinct-collection.d.ts +24 -0
  5. package/data-structures/distinct-collection.js +77 -0
  6. package/data-structures/index.d.ts +2 -1
  7. package/data-structures/index.js +2 -1
  8. package/data-structures/list.js +13 -5
  9. package/data-structures/multi-key-map.d.ts +1 -1
  10. package/data-structures/multi-key-map.js +2 -0
  11. package/data-structures/multi-key-set.d.ts +19 -0
  12. package/data-structures/multi-key-set.js +81 -0
  13. package/data-structures/{set.d.ts → set-collection.d.ts} +3 -3
  14. package/data-structures/{set.js → set-collection.js} +7 -7
  15. package/data-structures/sorted-array-list.d.ts +1 -1
  16. package/data-structures/sorted-array-list.js +1 -4
  17. package/data-structures/weak-ref-map.js +4 -1
  18. package/injector/decorators.d.ts +75 -0
  19. package/injector/decorators.js +112 -0
  20. package/injector/inject.d.ts +80 -0
  21. package/injector/inject.js +94 -0
  22. package/injector/injector.d.ts +111 -0
  23. package/injector/injector.js +454 -0
  24. package/injector/interfaces.d.ts +14 -0
  25. package/injector/interfaces.js +26 -0
  26. package/injector/provider.d.ts +44 -0
  27. package/injector/provider.js +64 -0
  28. package/injector/resolve-chain.d.ts +31 -0
  29. package/injector/resolve-chain.js +113 -0
  30. package/injector/resolve.error.d.ts +5 -0
  31. package/injector/resolve.error.js +36 -0
  32. package/injector/symbols.d.ts +2 -0
  33. package/injector/symbols.js +26 -0
  34. package/injector/token.d.ts +18 -0
  35. package/injector/token.js +41 -0
  36. package/injector/type-info.d.ts +18 -0
  37. package/injector/type-info.js +16 -0
  38. package/injector/types.d.ts +43 -0
  39. package/injector/types.js +16 -0
  40. package/package.json +3 -3
  41. package/pool/pool.js +2 -2
  42. package/utils/type-guards.js +2 -2
@@ -21,7 +21,7 @@ export declare class ArrayList<T> extends List<T, ArrayList<T>> {
21
21
  protected _set(index: number, item: T): void;
22
22
  remove(item: T): boolean;
23
23
  protected _removeAt(index: number): T;
24
- protected _removeManyAt(index: number, count?: number): T[];
24
+ protected _removeManyAt(index: number, count: number): T[];
25
25
  clone(): ArrayList<T>;
26
26
  items(): IterableIterator<T>;
27
27
  itemsReverse(): IterableIterator<T>;
@@ -40,7 +40,6 @@ class ArrayList extends import_list.List {
40
40
  return arrayList;
41
41
  }
42
42
  _at(index) {
43
- this.ensureBounds(index);
44
43
  return this.backingArray[index];
45
44
  }
46
45
  _indexOf(item, fromIndex) {
@@ -88,7 +87,6 @@ class ArrayList extends import_list.List {
88
87
  this.updateSize();
89
88
  }
90
89
  _set(index, item) {
91
- this.ensureBounds(index);
92
90
  this.backingArray[index] = item;
93
91
  this.emitChange();
94
92
  }
@@ -101,10 +99,12 @@ class ArrayList extends import_list.List {
101
99
  return true;
102
100
  }
103
101
  _removeAt(index) {
102
+ if (index == 0) {
103
+ return this.backingArray.shift();
104
+ }
104
105
  return this.removeManyAt(index, 1)[0];
105
106
  }
106
- _removeManyAt(index, count = this.size - index) {
107
- this.ensureBounds(index, count);
107
+ _removeManyAt(index, count) {
108
108
  const removed = this.backingArray.splice(index, count);
109
109
  this.updateSize();
110
110
  return removed;
@@ -182,7 +182,8 @@ class CircularBuffer extends import_collection.Collection {
182
182
  }
183
183
  }
184
184
  _clear() {
185
- this.backingArray = new Array(2);
185
+ this.backingArray = [];
186
+ this.backingArray.length = 2;
186
187
  this.writeIndex = 0;
187
188
  this.readIndex = 0;
188
189
  }
@@ -199,7 +200,7 @@ class CircularBuffer extends import_collection.Collection {
199
200
  if (size < this.size) {
200
201
  throw new Error("buffer has more items than it would have capacity after resize");
201
202
  }
202
- let newBackingArray = [];
203
+ let newBackingArray;
203
204
  if (this.size > 0) {
204
205
  if (this.readIndex < this.writeIndex) {
205
206
  newBackingArray = this.backingArray.slice(this.readIndex, this.writeIndex);
@@ -208,6 +209,8 @@ class CircularBuffer extends import_collection.Collection {
208
209
  const end = this.backingArray.slice(0, this.writeIndex);
209
210
  newBackingArray = start.concat(end);
210
211
  }
212
+ } else {
213
+ newBackingArray = [];
211
214
  }
212
215
  newBackingArray.length = size;
213
216
  this.backingArray = newBackingArray;
@@ -0,0 +1,24 @@
1
+ import { Collection } from './collection.js';
2
+ export declare abstract class DistinctCollection<T, TThis extends DistinctCollection<T, TThis> = DistinctCollection<T, any>> extends Collection<T, TThis> {
3
+ /** Creates a new map and copies the items */
4
+ toSet(): Set<T>;
5
+ /** Returns an adapter that has the same interface as {@link Set}. No copying of data involved. */
6
+ asSet(): Set<T>;
7
+ abstract has(value: T): boolean;
8
+ abstract delete(value: T): boolean;
9
+ }
10
+ export declare class SetAdapter<T> implements Set<T> {
11
+ private readonly collection;
12
+ readonly [Symbol.toStringTag] = "SetAdapter";
13
+ get size(): number;
14
+ constructor(set: DistinctCollection<T, any>);
15
+ add(value: T): this;
16
+ clear(): void;
17
+ delete(value: T): boolean;
18
+ forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: any): void;
19
+ has(value: T): boolean;
20
+ entries(): IterableIterator<[T, T]>;
21
+ keys(): IterableIterator<T>;
22
+ values(): IterableIterator<T>;
23
+ [Symbol.iterator](): IterableIterator<T>;
24
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var distinct_collection_exports = {};
20
+ __export(distinct_collection_exports, {
21
+ DistinctCollection: () => DistinctCollection,
22
+ SetAdapter: () => SetAdapter
23
+ });
24
+ module.exports = __toCommonJS(distinct_collection_exports);
25
+ var import_collection = require("./collection.js");
26
+ class DistinctCollection extends import_collection.Collection {
27
+ /** Creates a new map and copies the items */
28
+ toSet() {
29
+ return new Set(this);
30
+ }
31
+ /** Returns an adapter that has the same interface as {@link Set}. No copying of data involved. */
32
+ asSet() {
33
+ return new SetAdapter(this);
34
+ }
35
+ }
36
+ class SetAdapter {
37
+ collection;
38
+ [Symbol.toStringTag] = "SetAdapter";
39
+ get size() {
40
+ return this.collection.size;
41
+ }
42
+ constructor(set) {
43
+ this.collection = set;
44
+ }
45
+ add(value) {
46
+ this.collection.add(value);
47
+ return this;
48
+ }
49
+ clear() {
50
+ this.collection.clear();
51
+ }
52
+ delete(value) {
53
+ return this.collection.delete(value);
54
+ }
55
+ forEach(callbackfn, thisArg) {
56
+ for (const value of this.collection) {
57
+ callbackfn.call(thisArg, value, value, this);
58
+ }
59
+ }
60
+ has(value) {
61
+ return this.collection.has(value);
62
+ }
63
+ *entries() {
64
+ for (const item of this.collection) {
65
+ yield [item, item];
66
+ }
67
+ }
68
+ keys() {
69
+ return this.collection.items();
70
+ }
71
+ values() {
72
+ return this.collection.items();
73
+ }
74
+ [Symbol.iterator]() {
75
+ return this.collection[Symbol.iterator]();
76
+ }
77
+ }
@@ -10,6 +10,7 @@ export * from './linked-list.js';
10
10
  export * from './list.js';
11
11
  export * from './map-dictionary.js';
12
12
  export * from './multi-key-map.js';
13
- export * from './set.js';
13
+ export * from './multi-key-set.js';
14
+ export * from './set-collection.js';
14
15
  export * from './sorted-array-list.js';
15
16
  export * from './weak-ref-map.js';
@@ -27,6 +27,7 @@ __reExport(data_structures_exports, require("./linked-list.js"), module.exports)
27
27
  __reExport(data_structures_exports, require("./list.js"), module.exports);
28
28
  __reExport(data_structures_exports, require("./map-dictionary.js"), module.exports);
29
29
  __reExport(data_structures_exports, require("./multi-key-map.js"), module.exports);
30
- __reExport(data_structures_exports, require("./set.js"), module.exports);
30
+ __reExport(data_structures_exports, require("./multi-key-set.js"), module.exports);
31
+ __reExport(data_structures_exports, require("./set-collection.js"), module.exports);
31
32
  __reExport(data_structures_exports, require("./sorted-array-list.js"), module.exports);
32
33
  __reExport(data_structures_exports, require("./weak-ref-map.js"), module.exports);
@@ -27,7 +27,9 @@ var import_index_out_of_bounds_error = require("./index-out-of-bounds.error.js")
27
27
  class List extends import_collection.Collection {
28
28
  /** get item at index */
29
29
  at(index) {
30
- return this._at(this.normalizeIndex(index));
30
+ const normalizedIndex = this.normalizeIndex(index);
31
+ this.ensureBounds(normalizedIndex);
32
+ return this._at(normalizedIndex);
31
33
  }
32
34
  /**
33
35
  * find index of first occurrence of item
@@ -48,11 +50,15 @@ class List extends import_collection.Collection {
48
50
  }
49
51
  /** set item at index */
50
52
  set(index, item) {
51
- this._set(this.normalizeIndex(index), item);
53
+ const normalizedIndex = this.normalizeIndex(index);
54
+ this.ensureBounds(normalizedIndex);
55
+ this._set(normalizedIndex, item);
52
56
  }
53
57
  /** remove item at index */
54
58
  removeAt(index) {
55
- return this._removeAt(this.normalizeIndex(index));
59
+ const normalizedIndex = this.normalizeIndex(index);
60
+ this.ensureBounds(normalizedIndex);
61
+ return this._removeAt(normalizedIndex);
56
62
  }
57
63
  /** remove first item */
58
64
  removeFirst() {
@@ -67,8 +73,10 @@ class List extends import_collection.Collection {
67
73
  * @param index index to start removing at
68
74
  * @param count how many items to remove. If not defined, all items starting at `index` are removed
69
75
  */
70
- removeManyAt(index, count) {
71
- return this._removeManyAt(this.normalizeIndex(index), count);
76
+ removeManyAt(index, count = this.size - index) {
77
+ const normalizedIndex = this.normalizeIndex(index);
78
+ this.ensureBounds(normalizedIndex, count);
79
+ return this._removeManyAt(normalizedIndex, count);
72
80
  }
73
81
  /**
74
82
  * remove range of items at `fromIndex` to `toIndex`
@@ -6,7 +6,7 @@ type Node = {
6
6
  hasValue: boolean;
7
7
  value: any;
8
8
  };
9
- type NewMapProvider = () => Map<any, Node>;
9
+ export type NewMapProvider = () => Map<any, Node>;
10
10
  export declare class MultiKeyMap<K extends any[], V> extends Dictionary<K, V, MultiKeyMap<K, V>> {
11
11
  private readonly newMapProvider;
12
12
  private rootNode;
@@ -57,6 +57,8 @@ class MultiKeyMap extends import_dictionary.Dictionary {
57
57
  if (!node.hasValue) {
58
58
  node.hasValue = true;
59
59
  this.incrementSize();
60
+ } else {
61
+ this.emitChange();
60
62
  }
61
63
  }
62
64
  hasFlat(...key) {
@@ -0,0 +1,19 @@
1
+ import { DistinctCollection } from './distinct-collection.js';
2
+ import { NewMapProvider } from './multi-key-map.js';
3
+ export declare class MultiKeySet<T extends any[]> extends DistinctCollection<T> {
4
+ #private;
5
+ readonly [Symbol.toStringTag]: string;
6
+ constructor(newMapProvider?: NewMapProvider);
7
+ includes(value: T): boolean;
8
+ addFlat(...value: T): void;
9
+ add(value: T): void;
10
+ addMany(values: Iterable<T>): void;
11
+ hasFlat(...value: T): boolean;
12
+ has(value: T): boolean;
13
+ deleteFlat(...value: T): boolean;
14
+ delete(value: T): boolean;
15
+ clone(): MultiKeySet<T>;
16
+ items(): IterableIterator<T>;
17
+ protected _clear(): void;
18
+ private updateSize;
19
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var multi_key_set_exports = {};
20
+ __export(multi_key_set_exports, {
21
+ MultiKeySet: () => MultiKeySet
22
+ });
23
+ module.exports = __toCommonJS(multi_key_set_exports);
24
+ var import_distinct_collection = require("./distinct-collection.js");
25
+ var import_multi_key_map = require("./multi-key-map.js");
26
+ class MultiKeySet extends import_distinct_collection.DistinctCollection {
27
+ #map;
28
+ [Symbol.toStringTag] = "MultiKeySet";
29
+ constructor(newMapProvider) {
30
+ super();
31
+ this.#map = new import_multi_key_map.MultiKeyMap(newMapProvider);
32
+ }
33
+ includes(value) {
34
+ return this.#map.has(value);
35
+ }
36
+ addFlat(...value) {
37
+ this.#map.set(value, true);
38
+ this.updateSize();
39
+ }
40
+ add(value) {
41
+ this.#map.set(value, true);
42
+ this.updateSize();
43
+ }
44
+ addMany(values) {
45
+ for (const value of values) {
46
+ this.#map.set(value, true);
47
+ }
48
+ this.updateSize();
49
+ }
50
+ hasFlat(...value) {
51
+ return this.#map.has(value);
52
+ }
53
+ has(value) {
54
+ return this.#map.has(value);
55
+ }
56
+ deleteFlat(...value) {
57
+ const deleted = this.#map.delete(value);
58
+ this.updateSize();
59
+ return deleted;
60
+ }
61
+ delete(value) {
62
+ const deleted = this.#map.delete(value);
63
+ this.updateSize();
64
+ return deleted;
65
+ }
66
+ clone() {
67
+ const clone = new MultiKeySet();
68
+ clone.addMany(this);
69
+ return clone;
70
+ }
71
+ items() {
72
+ return this.#map.keys();
73
+ }
74
+ _clear() {
75
+ this.#map.clear();
76
+ this.updateSize();
77
+ }
78
+ updateSize() {
79
+ this.setSize(this.#map.size);
80
+ }
81
+ }
@@ -1,12 +1,12 @@
1
- import { Collection } from './collection.js';
2
- export declare class Set<T> extends Collection<T, Set<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>);
6
6
  includes(item: T): boolean;
7
7
  add(item: T): this;
8
8
  addMany(items: Iterable<T>): void;
9
- clone(): Set<T>;
9
+ clone(): SetCollection<T>;
10
10
  items(): IterableIterator<T>;
11
11
  delete(item: T): boolean;
12
12
  forEach(callbackfn: (value: T, value2: T, set: globalThis.Set<T>) => void, thisArg?: any): void;
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var set_exports = {};
20
- __export(set_exports, {
21
- Set: () => Set
19
+ var set_collection_exports = {};
20
+ __export(set_collection_exports, {
21
+ SetCollection: () => SetCollection
22
22
  });
23
- module.exports = __toCommonJS(set_exports);
24
- var import_collection = require("./collection.js");
25
- class Set extends import_collection.Collection {
23
+ module.exports = __toCommonJS(set_collection_exports);
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) {
@@ -45,7 +45,7 @@ class Set extends import_collection.Collection {
45
45
  this.updateSize();
46
46
  }
47
47
  clone() {
48
- return new Set(this);
48
+ return new SetCollection(this);
49
49
  }
50
50
  items() {
51
51
  return this.backingSet.values();
@@ -34,7 +34,7 @@ export declare class SortedArrayList<T extends TComparator, TComparator = T> ext
34
34
  protected _set(index: number, item: T): void;
35
35
  remove(item: T): boolean;
36
36
  protected _removeAt(index: number): T;
37
- protected _removeManyAt(index: number, count?: number): T[];
37
+ protected _removeManyAt(index: number, count: number): T[];
38
38
  /**
39
39
  * remove items
40
40
  * @param from
@@ -72,7 +72,6 @@ let SortedArrayList = SortedArrayList_1 = class SortedArrayList2 extends import_
72
72
  return SortedArrayList_1.fromSortedArray(data);
73
73
  }
74
74
  _at(index) {
75
- this.ensureBounds(index);
76
75
  return this.backingArray[index];
77
76
  }
78
77
  /** find index of item, can be any occurrence of it */
@@ -122,7 +121,6 @@ let SortedArrayList = SortedArrayList_1 = class SortedArrayList2 extends import_
122
121
  }
123
122
  /** same as `removeAt(index); add(item);` as it is sorted */
124
123
  _set(index, item) {
125
- this.ensureBounds(index);
126
124
  this.backingArray.splice(index, 1);
127
125
  this.add(item);
128
126
  }
@@ -137,8 +135,7 @@ let SortedArrayList = SortedArrayList_1 = class SortedArrayList2 extends import_
137
135
  _removeAt(index) {
138
136
  return this.removeManyAt(index, 1)[0];
139
137
  }
140
- _removeManyAt(index, count = this.size - index) {
141
- this.ensureBounds(index, count);
138
+ _removeManyAt(index, count) {
142
139
  const removed = this.backingArray.splice(index, count);
143
140
  this.updateSize();
144
141
  return removed;
@@ -75,8 +75,11 @@ class WeakRefMap extends import_collection.Collection {
75
75
  }
76
76
  set(key, value) {
77
77
  const has = this.has(key);
78
+ if (this.has(key)) {
79
+ this.finalizationRegistry.unregister(this.get(key));
80
+ }
78
81
  this.backingMap.set(key, new WeakRef(value));
79
- this.finalizationRegistry.register(value, key);
82
+ this.finalizationRegistry.register(value, key, value);
80
83
  if (!has) {
81
84
  this.incrementSize();
82
85
  }
@@ -0,0 +1,75 @@
1
+ import type { Decorator } from '../reflection/index.js';
2
+ import type { Constructor, OneOrMany, Simplify, TypedOmit } from '../types.js';
3
+ import type { Provider } from './provider.js';
4
+ import type { InjectionToken } from './token.js';
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
+ };
13
+ export type InjectableOptionsWithoutLifecycle<T, A> = Simplify<TypedOmit<InjectableOptions<T, A>, 'lifecycle'>>;
14
+ /**
15
+ * Helper decorator to replace a class definition with an other
16
+ * can be used for example to type external classes with the {@link Resolvable} interface
17
+ * @param constructor class to replace with
18
+ */
19
+ export declare function ReplaceClass<T>(constructor: Constructor<T>): ClassDecorator;
20
+ /**
21
+ * Globally registers the class for injection
22
+ * @param options registration options
23
+ */
24
+ export declare function Injectable<T = any, A = any>(options?: InjectableOptions<T, A>): ClassDecorator;
25
+ /**
26
+ * registers the class in the global container with singleton lifecycle. Decorated class is not modified in any way
27
+ * @param options registration options
28
+ */
29
+ export declare function Singleton<T = any, A = any>(options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
30
+ /**
31
+ * registers the class in the global container with scoped lifecycle. Decorated class is not modified in any way
32
+ * @param options registration options
33
+ */
34
+ export declare function Scoped<T = any, A = any>(lifecycle: 'resolution' | 'injector', options?: InjectableOptionsWithoutLifecycle<T, A>): ClassDecorator;
35
+ /**
36
+ * sets the token used to resolve the parameter
37
+ * @param token token used for resolving
38
+ * @param argument resolve argument
39
+ * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
40
+ */
41
+ export declare function Inject<T, A>(token?: InjectionToken<T, A>, argument?: A, mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
42
+ /**
43
+ * sets the argument used for resolving the parameter
44
+ * @param argument
45
+ */
46
+ export declare function ResolveArg<T>(argument: T): InjectDecorator;
47
+ /**
48
+ * sets the argument provider used for resolving the parameter
49
+ * @param argumentProvider
50
+ */
51
+ export declare function ResolveArgProvider<T>(argumentProvider: ArgumentProvider<T>): InjectDecorator;
52
+ /**
53
+ * injects the argument used for resolving the class instead of resolving the parameter
54
+ * @param argument
55
+ * @param mapperOrKey map the resolved value. If {@link PropertyKey} is provided, that property of the resolved value will be injected
56
+ */
57
+ export declare function InjectArg<T>(mapperOrKey?: Mapper<T> | keyof T): InjectDecorator;
58
+ /**
59
+ * sets the argument used for resolving the decorated parameter to the the argument provided for parent resolve
60
+ * @param mapper map the argument (for example to select a property instead of forwarding the whole object)
61
+ */
62
+ export declare function ForwardArg(): InjectDecorator;
63
+ export declare function ForwardArg<T, U>(mapper: Mapper<T, U>): InjectDecorator;
64
+ /**
65
+ * marks the argument as optional
66
+ * @param argument
67
+ */
68
+ export declare function Optional(): InjectDecorator;
69
+ /**
70
+ * resolve using ForwardRef to handle circular dependencies. Resolve logic derefs all ForwardRefs which are direct properties of resolved instances automatically
71
+ * @param token token to resolve
72
+ * @param argument resolve argument
73
+ */
74
+ export declare function ForwardRef<T extends object, A>(token: ForwardRefInjectionToken<T>, argument?: A): InjectDecorator;
75
+ export {};
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var decorators_exports = {};
20
+ __export(decorators_exports, {
21
+ ForwardArg: () => ForwardArg,
22
+ ForwardRef: () => ForwardRef,
23
+ Inject: () => Inject,
24
+ InjectArg: () => InjectArg,
25
+ Injectable: () => Injectable,
26
+ Optional: () => Optional,
27
+ ReplaceClass: () => ReplaceClass,
28
+ ResolveArg: () => ResolveArg,
29
+ ResolveArgProvider: () => ResolveArgProvider,
30
+ Scoped: () => Scoped,
31
+ Singleton: () => Singleton
32
+ });
33
+ module.exports = __toCommonJS(decorators_exports);
34
+ var import_reflection = require("../reflection/index.js");
35
+ var import_array = require("../utils/array/array.js");
36
+ var import_type_guards = require("../utils/type-guards.js");
37
+ var import_injector = require("./injector.js");
38
+ var import_symbols = require("./symbols.js");
39
+ function ReplaceClass(constructor) {
40
+ return (0, import_reflection.createClassDecorator)({ handler: () => constructor });
41
+ }
42
+ function Injectable(options = {}) {
43
+ return (0, import_reflection.createClassDecorator)({
44
+ data: { [import_symbols.injectableMetadataSymbol]: {} },
45
+ mergeData: true,
46
+ handler: (data) => {
47
+ const { alias: aliases, provider, ...registrationOptions } = options;
48
+ const token = data.constructor;
49
+ const targetProvider = provider ?? { useClass: token };
50
+ import_injector.Injector.register(token, targetProvider, registrationOptions);
51
+ if ((0, import_type_guards.isDefined)(aliases)) {
52
+ for (const alias of (0, import_array.toArray)(aliases)) {
53
+ import_injector.Injector.register(alias, { useToken: token }, registrationOptions);
54
+ }
55
+ }
56
+ }
57
+ });
58
+ }
59
+ function Singleton(options = {}) {
60
+ return Injectable({ ...options, lifecycle: "singleton" });
61
+ }
62
+ function Scoped(lifecycle, options = {}) {
63
+ return Injectable({ ...options, lifecycle });
64
+ }
65
+ function Inject(token, argument, mapperOrKey) {
66
+ const injectMetadata = {};
67
+ if ((0, import_type_guards.isDefined)(token)) {
68
+ injectMetadata.injectToken = token;
69
+ }
70
+ if ((0, import_type_guards.isDefined)(argument)) {
71
+ injectMetadata.resolveArgumentProvider = () => argument;
72
+ }
73
+ if ((0, import_type_guards.isDefined)(mapperOrKey)) {
74
+ injectMetadata.mapper = (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (value) => value[mapperOrKey];
75
+ }
76
+ return createInjectDecorator(injectMetadata);
77
+ }
78
+ function ResolveArg(argument) {
79
+ return ResolveArgProvider(() => argument);
80
+ }
81
+ function ResolveArgProvider(argumentProvider) {
82
+ return createInjectDecorator({ resolveArgumentProvider: argumentProvider });
83
+ }
84
+ function InjectArg(mapperOrKey) {
85
+ return createInjectDecorator({
86
+ injectArgumentMapper: (0, import_type_guards.isFunction)(mapperOrKey) ? mapperOrKey : (0, import_type_guards.isDefined)(mapperOrKey) ? (value) => value[mapperOrKey] : (value) => value
87
+ });
88
+ }
89
+ function ForwardArg(mapper = (value) => value) {
90
+ return createInjectDecorator({ forwardArgumentMapper: mapper });
91
+ }
92
+ function Optional() {
93
+ return createInjectDecorator({ optional: true });
94
+ }
95
+ function ForwardRef(token, argument) {
96
+ const injectMetadata = {
97
+ forwardRefToken: token
98
+ };
99
+ if ((0, import_type_guards.isDefined)(argument)) {
100
+ injectMetadata.resolveArgumentProvider = () => argument;
101
+ }
102
+ return createInjectDecorator(injectMetadata);
103
+ }
104
+ function createInjectDecorator(metadata) {
105
+ return (0, import_reflection.createDecorator)({
106
+ property: true,
107
+ accessor: true,
108
+ constructorParameter: true,
109
+ data: { [import_symbols.injectMetadataSymbol]: metadata },
110
+ mergeData: true
111
+ });
112
+ }