@tachybase/di 1.3.43

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 (65) hide show
  1. package/LICENSE +201 -0
  2. package/lib/container-instance.class.d.ts +111 -0
  3. package/lib/container-instance.class.js +343 -0
  4. package/lib/container-registry.class.d.ts +51 -0
  5. package/lib/container-registry.class.js +95 -0
  6. package/lib/decorators/inject-many.decorator.d.ts +8 -0
  7. package/lib/decorators/inject-many.decorator.js +56 -0
  8. package/lib/decorators/inject.decorator.d.ts +9 -0
  9. package/lib/decorators/inject.decorator.js +56 -0
  10. package/lib/decorators/service.decorator.d.ts +6 -0
  11. package/lib/decorators/service.decorator.js +49 -0
  12. package/lib/decorators.d.ts +16 -0
  13. package/lib/decorators.js +86 -0
  14. package/lib/empty.const.d.ts +6 -0
  15. package/lib/empty.const.js +27 -0
  16. package/lib/error/cannot-inject-value.error.d.ts +11 -0
  17. package/lib/error/cannot-inject-value.error.js +40 -0
  18. package/lib/error/cannot-instantiate-value.error.d.ts +11 -0
  19. package/lib/error/cannot-instantiate-value.error.js +49 -0
  20. package/lib/error/service-not-found.error.d.ts +11 -0
  21. package/lib/error/service-not-found.error.js +49 -0
  22. package/lib/index.d.ts +15 -0
  23. package/lib/index.js +50 -0
  24. package/lib/interfaces/container-options.interface.d.ts +45 -0
  25. package/lib/interfaces/container-options.interface.js +15 -0
  26. package/lib/interfaces/handler.interface.d.ts +27 -0
  27. package/lib/interfaces/handler.interface.js +15 -0
  28. package/lib/interfaces/service-metadata.interface.d.ts +53 -0
  29. package/lib/interfaces/service-metadata.interface.js +15 -0
  30. package/lib/interfaces/service-options.interface.d.ts +6 -0
  31. package/lib/interfaces/service-options.interface.js +15 -0
  32. package/lib/token.class.d.ts +11 -0
  33. package/lib/token.class.js +37 -0
  34. package/lib/types/abstract-constructable.type.d.ts +9 -0
  35. package/lib/types/abstract-constructable.type.js +15 -0
  36. package/lib/types/container-identifier.type.d.ts +4 -0
  37. package/lib/types/container-identifier.type.js +15 -0
  38. package/lib/types/container-scope.type.d.ts +1 -0
  39. package/lib/types/container-scope.type.js +15 -0
  40. package/lib/types/service-identifier.type.d.ts +8 -0
  41. package/lib/types/service-identifier.type.js +15 -0
  42. package/lib/utils/resolve-to-type-wrapper.util.d.ts +15 -0
  43. package/lib/utils/resolve-to-type-wrapper.util.js +39 -0
  44. package/package.json +11 -0
  45. package/src/container-instance.class.ts +487 -0
  46. package/src/container-registry.class.ts +92 -0
  47. package/src/decorators/inject-many.decorator.ts +48 -0
  48. package/src/decorators/inject.decorator.ts +46 -0
  49. package/src/decorators/service.decorator.ts +34 -0
  50. package/src/decorators.ts +70 -0
  51. package/src/empty.const.ts +6 -0
  52. package/src/error/cannot-inject-value.error.ts +22 -0
  53. package/src/error/cannot-instantiate-value.error.ts +34 -0
  54. package/src/error/service-not-found.error.ts +33 -0
  55. package/src/index.ts +21 -0
  56. package/src/interfaces/container-options.interface.ts +48 -0
  57. package/src/interfaces/handler.interface.ts +32 -0
  58. package/src/interfaces/service-metadata.interface.ts +62 -0
  59. package/src/interfaces/service-options.interface.ts +10 -0
  60. package/src/token.class.ts +11 -0
  61. package/src/types/abstract-constructable.type.ts +7 -0
  62. package/src/types/container-identifier.type.ts +4 -0
  63. package/src/types/container-scope.type.ts +1 -0
  64. package/src/types/service-identifier.type.ts +15 -0
  65. package/src/utils/resolve-to-type-wrapper.util.ts +44 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { Container } from './container-instance.class';
2
+ export * from './decorators/inject-many.decorator';
3
+ export * from './decorators/inject.decorator';
4
+ export * from './decorators/service.decorator';
5
+ export * from './error/cannot-inject-value.error';
6
+ export * from './error/cannot-instantiate-value.error';
7
+ export * from './error/service-not-found.error';
8
+ export type { Handler } from './interfaces/handler.interface';
9
+ export type { ServiceMetadata } from './interfaces/service-metadata.interface';
10
+ export type { ServiceOptions } from './interfaces/service-options.interface';
11
+ export type { ServiceIdentifier } from './types/service-identifier.type';
12
+ export { ContainerInstance, Container } from './container-instance.class';
13
+ export { Token } from './token.class';
14
+ export default Container;
15
+ export * from './decorators';
package/lib/index.js ADDED
@@ -0,0 +1,50 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var index_exports = {};
20
+ __export(index_exports, {
21
+ Container: () => import_container_instance2.Container,
22
+ ContainerInstance: () => import_container_instance2.ContainerInstance,
23
+ Token: () => import_token.Token,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_container_instance = require("./container-instance.class");
28
+ __reExport(index_exports, require("./decorators/inject-many.decorator"), module.exports);
29
+ __reExport(index_exports, require("./decorators/inject.decorator"), module.exports);
30
+ __reExport(index_exports, require("./decorators/service.decorator"), module.exports);
31
+ __reExport(index_exports, require("./error/cannot-inject-value.error"), module.exports);
32
+ __reExport(index_exports, require("./error/cannot-instantiate-value.error"), module.exports);
33
+ __reExport(index_exports, require("./error/service-not-found.error"), module.exports);
34
+ var import_container_instance2 = require("./container-instance.class");
35
+ var import_token = require("./token.class");
36
+ __reExport(index_exports, require("./decorators"), module.exports);
37
+ var index_default = import_container_instance.Container;
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ Container,
41
+ ContainerInstance,
42
+ Token,
43
+ ...require("./decorators/inject-many.decorator"),
44
+ ...require("./decorators/inject.decorator"),
45
+ ...require("./decorators/service.decorator"),
46
+ ...require("./error/cannot-inject-value.error"),
47
+ ...require("./error/cannot-instantiate-value.error"),
48
+ ...require("./error/service-not-found.error"),
49
+ ...require("./decorators")
50
+ });
@@ -0,0 +1,45 @@
1
+ export interface ContainerOptions {
2
+ /**
3
+ * Controls the behavior when a service is already registered with the same ID. The following values are allowed:
4
+ *
5
+ * - `throw` - a `ContainerCannotBeCreatedError` error is raised
6
+ * - `overwrite` - the previous container is disposed and a new one is created
7
+ * - `returnExisting` - returns the existing container or raises a `ContainerCannotBeCreatedError` error if the
8
+ * specified options differ from the options of the existing container
9
+ *
10
+ * The default value is `returnExisting`.
11
+ */
12
+ onConflict: 'throw' | 'overwrite' | 'returnExisting';
13
+ /**
14
+ * Controls the behavior when a requested type doesn't exists in the current container. The following values are allowed:
15
+ *
16
+ * - `allowLookup` - the parent container will be checked for the dependency
17
+ * - `localOnly` - a `ServiceNotFoundError` error is raised
18
+ *
19
+ * The default value is `allowLookup`.
20
+ */
21
+ lookupStrategy: 'allowLookup' | 'localOnly';
22
+ /**
23
+ * Enables the lookup for global (singleton) services before checking in the current container. By default every
24
+ * type is first checked in the default container to return singleton services. This check bypasses the lookup strategy,
25
+ * set in the container so if this behavior is not desired it can be disabled via this flag.
26
+ *
27
+ * The default value is `true`.
28
+ */
29
+ allowSingletonLookup: boolean;
30
+ /**
31
+ * Controls how the child container inherits the service definitions from it's parent. The following values are allowed:
32
+ *
33
+ * - `none` - no metadata is inherited
34
+ * - `definitionOnly` - only metadata is inherited, a new instance will be created for each class
35
+ * - eager classes created as soon as the container is created
36
+ * - non-eager classes are created the first time they are requested
37
+ * - `definitionWithValues` - both metadata and service instances are inherited
38
+ * - when parent class is disposed the instances in this container are preserved
39
+ * - if a service is registered but not created yet, it will be shared when created between the two container
40
+ * - newly registered services won't be shared between the two container
41
+ *
42
+ * The default value is `none`.
43
+ */
44
+ inheritanceStrategy: 'none' | 'definitionOnly' | 'definitionWithValues';
45
+ }
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var container_options_interface_exports = {};
15
+ module.exports = __toCommonJS(container_options_interface_exports);
@@ -0,0 +1,27 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ import { ContainerInstance } from '../container-instance.class';
3
+ /**
4
+ * Used to register special "handler" which will be executed on a service class during its initialization.
5
+ * It can be used to create custom decorators and set/replace service class properties and constructor parameters.
6
+ */
7
+ export interface Handler<T = unknown> {
8
+ /**
9
+ * Service object used to apply handler to.
10
+ */
11
+ object: Constructable<T>;
12
+ /**
13
+ * Class property name to set/replace value of.
14
+ * Used if handler is applied on a class property.
15
+ */
16
+ propertyName?: string;
17
+ /**
18
+ * Parameter index to set/replace value of.
19
+ * Used if handler is applied on a constructor parameter.
20
+ */
21
+ index?: number;
22
+ /**
23
+ * Factory function that produces value that will be set to class property or constructor parameter.
24
+ * Accepts container instance which requested the value.
25
+ */
26
+ value: (container: ContainerInstance) => any;
27
+ }
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var handler_interface_exports = {};
15
+ module.exports = __toCommonJS(handler_interface_exports);
@@ -0,0 +1,53 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ import { ContainerInstance } from '../container-instance.class';
3
+ import { ContainerIdentifier } from '../types/container-identifier.type';
4
+ import { ContainerScope } from '../types/container-scope.type';
5
+ import { ServiceIdentifier } from '../types/service-identifier.type';
6
+ /**
7
+ * Service metadata is used to initialize service and store its state.
8
+ */
9
+ export interface ServiceMetadata<Type = unknown> {
10
+ /** Unique identifier of the referenced service. */
11
+ id: ServiceIdentifier;
12
+ /**
13
+ * The injection scope for the service.
14
+ * - a `singleton` service always will be created in the default container regardless of who registering it
15
+ * - a `container` scoped service will be created once when requested from the given container
16
+ * - a `transient` service will be created each time it is requested
17
+ */
18
+ scope: ContainerScope;
19
+ /**
20
+ * Class definition of the service what is used to initialize given service.
21
+ * This property maybe null if the value of the service is set manually.
22
+ * If id is not set then it serves as service id.
23
+ */
24
+ type: Constructable<Type> | null;
25
+ /**
26
+ * Factory function used to initialize this service.
27
+ * Can be regular function ("createCar" for example),
28
+ * or other service which produces this instance ([CarFactory, "createCar"] for example).
29
+ */
30
+ factory: [Constructable<unknown>, string] | CallableFunction | undefined;
31
+ /**
32
+ * Instance of the target class.
33
+ */
34
+ value: unknown | symbol;
35
+ /**
36
+ * Allows to setup multiple instances the different classes under a single service id string or token.
37
+ */
38
+ multiple: boolean;
39
+ /**
40
+ * Indicates whether a new instance should be created as soon as the class is registered.
41
+ * By default the registered classes are only instantiated when they are requested from the container.
42
+ *
43
+ * _Note: This option is ignored for transient services._
44
+ */
45
+ eager: boolean;
46
+ /**
47
+ * Map of containers referencing this metadata. This is used when a container
48
+ * is inheriting it's parents definitions and values to track the lifecycle of
49
+ * the metadata. Namely, a service can be disposed only if it's only referenced
50
+ * by the container being disposed.
51
+ */
52
+ referencedBy: Map<ContainerIdentifier, ContainerInstance>;
53
+ }
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var service_metadata_interface_exports = {};
15
+ module.exports = __toCommonJS(service_metadata_interface_exports);
@@ -0,0 +1,6 @@
1
+ import { ServiceMetadata } from './service-metadata.interface';
2
+ /**
3
+ * The public ServiceOptions is partial object of ServiceMetadata and either one
4
+ * of the following is set: `type`, `factory`, `value` but not more than one.
5
+ */
6
+ export type ServiceOptions<T = unknown> = Omit<Partial<ServiceMetadata<T>>, 'referencedBy' | 'type' | 'factory'> | Omit<Partial<ServiceMetadata<T>>, 'referencedBy' | 'value' | 'factory'> | Omit<Partial<ServiceMetadata<T>>, 'referencedBy' | 'value' | 'type'>;
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var service_options_interface_exports = {};
15
+ module.exports = __toCommonJS(service_options_interface_exports);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Used to create unique typed service identifier.
3
+ * Useful when service has only interface, but don't have a class.
4
+ */
5
+ export declare class Token<T> {
6
+ name?: string;
7
+ /**
8
+ * @param name Token name, optional and only used for debugging purposes.
9
+ */
10
+ constructor(name?: string);
11
+ }
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 token_class_exports = {};
20
+ __export(token_class_exports, {
21
+ Token: () => Token
22
+ });
23
+ module.exports = __toCommonJS(token_class_exports);
24
+ const _Token = class _Token {
25
+ /**
26
+ * @param name Token name, optional and only used for debugging purposes.
27
+ */
28
+ constructor(name) {
29
+ this.name = name;
30
+ }
31
+ };
32
+ __name(_Token, "Token");
33
+ let Token = _Token;
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ Token
37
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generic type for abstract class definitions.
3
+ *
4
+ * Explanation: This describes a newable Function with a prototype Which is
5
+ * what an abstract class is - no constructor, just the prototype.
6
+ */
7
+ export type AbstractConstructable<T> = NewableFunction & {
8
+ prototype: T;
9
+ };
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var abstract_constructable_type_exports = {};
15
+ module.exports = __toCommonJS(abstract_constructable_type_exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * A container identifier. This value must be unique across all containers.
3
+ */
4
+ export type ContainerIdentifier = string | symbol;
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var container_identifier_type_exports = {};
15
+ module.exports = __toCommonJS(container_identifier_type_exports);
@@ -0,0 +1 @@
1
+ export type ContainerScope = 'singleton' | 'container' | 'transient';
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var container_scope_type_exports = {};
15
+ module.exports = __toCommonJS(container_scope_type_exports);
@@ -0,0 +1,8 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ import { Token } from '../token.class';
3
+ import { AbstractConstructable } from './abstract-constructable.type';
4
+ /**
5
+ * Unique service identifier.
6
+ * Can be some class type, or string id, or instance of Token.
7
+ */
8
+ export type ServiceIdentifier<T = unknown> = Constructable<T> | AbstractConstructable<T> | CallableFunction | Token<T> | string;
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var service_identifier_type_exports = {};
15
+ module.exports = __toCommonJS(service_identifier_type_exports);
@@ -0,0 +1,15 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ import { ServiceIdentifier } from '../types/service-identifier.type';
3
+ /**
4
+ * Helper function used in inject decorators to resolve the received identifier to
5
+ * an eager type when possible or to a lazy type when cyclic dependencies are possibly involved.
6
+ *
7
+ * @param typeOrIdentifier a service identifier or a function returning a type acting as service identifier or nothing
8
+ * @param target the class definition of the target of the decorator
9
+ * @param propertyName the name of the property in case of a PropertyDecorator
10
+ * @param index the index of the parameter in the constructor in case of ParameterDecorator
11
+ */
12
+ export declare function resolveToTypeWrapper(typeOrIdentifier: ((type?: never) => Constructable<unknown>) | ServiceIdentifier<unknown> | undefined, target: object, propertyName: string | symbol, index?: number): {
13
+ eagerType: ServiceIdentifier | null;
14
+ lazyType: (type?: never) => ServiceIdentifier;
15
+ };
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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 resolve_to_type_wrapper_util_exports = {};
20
+ __export(resolve_to_type_wrapper_util_exports, {
21
+ resolveToTypeWrapper: () => resolveToTypeWrapper
22
+ });
23
+ module.exports = __toCommonJS(resolve_to_type_wrapper_util_exports);
24
+ var import_token = require("../token.class");
25
+ function resolveToTypeWrapper(typeOrIdentifier, target, propertyName, index) {
26
+ let typeWrapper;
27
+ if (typeOrIdentifier && typeof typeOrIdentifier === "string" || typeOrIdentifier instanceof import_token.Token) {
28
+ typeWrapper = { eagerType: typeOrIdentifier, lazyType: /* @__PURE__ */ __name(() => typeOrIdentifier, "lazyType") };
29
+ }
30
+ if (typeOrIdentifier && typeof typeOrIdentifier === "function") {
31
+ typeWrapper = { eagerType: null, lazyType: /* @__PURE__ */ __name(() => typeOrIdentifier(), "lazyType") };
32
+ }
33
+ return typeWrapper;
34
+ }
35
+ __name(resolveToTypeWrapper, "resolveToTypeWrapper");
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ resolveToTypeWrapper
39
+ });
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@tachybase/di",
3
+ "version": "1.3.43",
4
+ "description": "",
5
+ "license": "Apache-2.0",
6
+ "main": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "dependencies": {
9
+ "@tachybase/utils": "^1.3.42"
10
+ }
11
+ }