@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
@@ -0,0 +1,51 @@
1
+ import { ContainerInstance } from './container-instance.class';
2
+ import { ContainerIdentifier } from './types/container-identifier.type';
3
+ /**
4
+ * The container registry is responsible for holding the default and every
5
+ * created container instance for later access.
6
+ *
7
+ * _Note: This class is for internal use and it's API may break in minor or
8
+ * patch releases without warning._
9
+ */
10
+ export declare class ContainerRegistry {
11
+ /**
12
+ * The list of all known container. Created containers are automatically added
13
+ * to this list. Two container cannot be registered with the same ID.
14
+ *
15
+ * This map doesn't contains the default container.
16
+ */
17
+ private static readonly containerMap;
18
+ /**
19
+ * Registers the given container instance or throws an error.
20
+ *
21
+ * _Note: This function is auto-called when a Container instance is created,
22
+ * it doesn't need to be called manually!_
23
+ *
24
+ * @param container the container to add to the registry
25
+ */
26
+ static registerContainer(container: ContainerInstance): void;
27
+ /**
28
+ * Returns true if a container exists with the given ID or false otherwise.
29
+ *
30
+ * @param container the ID of the container
31
+ */
32
+ static hasContainer(id: ContainerIdentifier): boolean;
33
+ /**
34
+ * Returns the container for requested ID or throws an error if no container
35
+ * is registered with the given ID.
36
+ *
37
+ * @param container the ID of the container
38
+ */
39
+ static getContainer(id: ContainerIdentifier): ContainerInstance;
40
+ /**
41
+ * Removes the given container from the registry and disposes all services
42
+ * registered only in this container.
43
+ *
44
+ * This function throws an error if no
45
+ * - container exists with the given ID
46
+ * - any of the registered services threw an error during it's disposal
47
+ *
48
+ * @param container the container to remove from the registry
49
+ */
50
+ static removeContainer(container: ContainerInstance): Promise<void>;
51
+ }
@@ -0,0 +1,95 @@
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 container_registry_class_exports = {};
20
+ __export(container_registry_class_exports, {
21
+ ContainerRegistry: () => ContainerRegistry
22
+ });
23
+ module.exports = __toCommonJS(container_registry_class_exports);
24
+ var import_container_instance = require("./container-instance.class");
25
+ const _ContainerRegistry = class _ContainerRegistry {
26
+ /**
27
+ * Registers the given container instance or throws an error.
28
+ *
29
+ * _Note: This function is auto-called when a Container instance is created,
30
+ * it doesn't need to be called manually!_
31
+ *
32
+ * @param container the container to add to the registry
33
+ */
34
+ static registerContainer(container) {
35
+ if (container instanceof import_container_instance.ContainerInstance === false) {
36
+ throw new Error("Only ContainerInstance instances can be registered.");
37
+ }
38
+ if (_ContainerRegistry.containerMap.has(container.id)) {
39
+ throw new Error("Cannot register container with same ID.");
40
+ }
41
+ _ContainerRegistry.containerMap.set(container.id, container);
42
+ }
43
+ /**
44
+ * Returns true if a container exists with the given ID or false otherwise.
45
+ *
46
+ * @param container the ID of the container
47
+ */
48
+ static hasContainer(id) {
49
+ return _ContainerRegistry.containerMap.has(id);
50
+ }
51
+ /**
52
+ * Returns the container for requested ID or throws an error if no container
53
+ * is registered with the given ID.
54
+ *
55
+ * @param container the ID of the container
56
+ */
57
+ static getContainer(id) {
58
+ const registeredContainer = this.containerMap.get(id);
59
+ if (registeredContainer === void 0) {
60
+ throw new Error("No container is registered with the given ID.");
61
+ }
62
+ return registeredContainer;
63
+ }
64
+ /**
65
+ * Removes the given container from the registry and disposes all services
66
+ * registered only in this container.
67
+ *
68
+ * This function throws an error if no
69
+ * - container exists with the given ID
70
+ * - any of the registered services threw an error during it's disposal
71
+ *
72
+ * @param container the container to remove from the registry
73
+ */
74
+ static async removeContainer(container) {
75
+ const registeredContainer = _ContainerRegistry.containerMap.get(container.id);
76
+ if (registeredContainer === void 0) {
77
+ throw new Error("No container is registered with the given ID.");
78
+ }
79
+ _ContainerRegistry.containerMap.delete(container.id);
80
+ await registeredContainer.dispose();
81
+ }
82
+ };
83
+ __name(_ContainerRegistry, "ContainerRegistry");
84
+ /**
85
+ * The list of all known container. Created containers are automatically added
86
+ * to this list. Two container cannot be registered with the same ID.
87
+ *
88
+ * This map doesn't contains the default container.
89
+ */
90
+ _ContainerRegistry.containerMap = /* @__PURE__ */ new Map();
91
+ let ContainerRegistry = _ContainerRegistry;
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ ContainerRegistry
95
+ });
@@ -0,0 +1,8 @@
1
+ import { Token } from '../token.class';
2
+ /**
3
+ * Injects a list of services into a class property or constructor parameter.
4
+ */
5
+ export declare function InjectMany(): Function;
6
+ export declare function InjectMany(type?: (type?: any) => Function): Function;
7
+ export declare function InjectMany(serviceName?: string): Function;
8
+ export declare function InjectMany(token: Token<any>): Function;
@@ -0,0 +1,56 @@
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 inject_many_decorator_exports = {};
20
+ __export(inject_many_decorator_exports, {
21
+ InjectMany: () => InjectMany
22
+ });
23
+ module.exports = __toCommonJS(inject_many_decorator_exports);
24
+ var import_container_instance = require("../container-instance.class");
25
+ var import_cannot_inject_value = require("../error/cannot-inject-value.error");
26
+ var import_resolve_to_type_wrapper = require("../utils/resolve-to-type-wrapper.util");
27
+ function InjectMany(typeOrIdentifier) {
28
+ return function(_, context) {
29
+ if (!context.metadata.injects) {
30
+ context.metadata.injects = [];
31
+ }
32
+ context.metadata.injects.push((target) => {
33
+ const propertyName = context.name;
34
+ const typeWrapper = (0, import_resolve_to_type_wrapper.resolveToTypeWrapper)(typeOrIdentifier, target, propertyName);
35
+ if (typeWrapper === void 0 || typeWrapper.eagerType === void 0 || typeWrapper.eagerType === Object) {
36
+ throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
37
+ }
38
+ import_container_instance.ContainerInstance.default.registerHandler({
39
+ object: target,
40
+ propertyName,
41
+ value: /* @__PURE__ */ __name((containerInstance) => {
42
+ const evaluatedLazyType = typeWrapper.lazyType();
43
+ if (evaluatedLazyType === void 0 || evaluatedLazyType === Object) {
44
+ throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
45
+ }
46
+ return containerInstance.getMany(evaluatedLazyType);
47
+ }, "value")
48
+ });
49
+ });
50
+ };
51
+ }
52
+ __name(InjectMany, "InjectMany");
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ InjectMany
56
+ });
@@ -0,0 +1,9 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ import { Token } from '../token.class';
3
+ /**
4
+ * Injects a service into a class property or constructor parameter.
5
+ */
6
+ export declare function Inject(): Function;
7
+ export declare function Inject(typeFn: (type?: never) => Constructable<unknown>): Function;
8
+ export declare function Inject(serviceName?: string): Function;
9
+ export declare function Inject(token: Token<unknown>): Function;
@@ -0,0 +1,56 @@
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 inject_decorator_exports = {};
20
+ __export(inject_decorator_exports, {
21
+ Inject: () => Inject
22
+ });
23
+ module.exports = __toCommonJS(inject_decorator_exports);
24
+ var import_container_instance = require("../container-instance.class");
25
+ var import_cannot_inject_value = require("../error/cannot-inject-value.error");
26
+ var import_resolve_to_type_wrapper = require("../utils/resolve-to-type-wrapper.util");
27
+ function Inject(typeOrIdentifier) {
28
+ return function(_, context) {
29
+ if (!context.metadata.injects) {
30
+ context.metadata.injects = [];
31
+ }
32
+ context.metadata.injects.push((target) => {
33
+ const propertyName = context.name;
34
+ const typeWrapper = (0, import_resolve_to_type_wrapper.resolveToTypeWrapper)(typeOrIdentifier, target, propertyName);
35
+ if (typeWrapper === void 0 || typeWrapper.eagerType === void 0 || typeWrapper.eagerType === Object) {
36
+ throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
37
+ }
38
+ import_container_instance.ContainerInstance.default.registerHandler({
39
+ object: target,
40
+ propertyName,
41
+ value: /* @__PURE__ */ __name((containerInstance) => {
42
+ const evaluatedLazyType = typeWrapper.lazyType();
43
+ if (evaluatedLazyType === void 0 || evaluatedLazyType === Object) {
44
+ throw new import_cannot_inject_value.CannotInjectValueError(target, propertyName);
45
+ }
46
+ return containerInstance.get(evaluatedLazyType);
47
+ }, "value")
48
+ });
49
+ });
50
+ };
51
+ }
52
+ __name(Inject, "Inject");
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ Inject
56
+ });
@@ -0,0 +1,6 @@
1
+ import { ServiceOptions } from '../interfaces/service-options.interface';
2
+ /**
3
+ * Marks class as a service that can be injected using Container.
4
+ */
5
+ export declare function Service<T = unknown>(): Function;
6
+ export declare function Service<T = unknown>(options: ServiceOptions<T>): Function;
@@ -0,0 +1,49 @@
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 service_decorator_exports = {};
20
+ __export(service_decorator_exports, {
21
+ Service: () => Service
22
+ });
23
+ module.exports = __toCommonJS(service_decorator_exports);
24
+ var import_container_instance = require("../container-instance.class");
25
+ var import_empty = require("../empty.const");
26
+ function Service(options = {}) {
27
+ return (target, context) => {
28
+ const serviceMetadata = {
29
+ id: options.id || target,
30
+ type: target,
31
+ factory: options.factory || void 0,
32
+ multiple: options.multiple || false,
33
+ eager: options.eager || false,
34
+ scope: options.scope || "container",
35
+ referencedBy: (/* @__PURE__ */ new Map()).set(import_container_instance.ContainerInstance.default.id, import_container_instance.ContainerInstance.default),
36
+ value: import_empty.EMPTY_VALUE
37
+ };
38
+ (context.metadata.injects || []).forEach((inject) => {
39
+ inject(target);
40
+ });
41
+ import_container_instance.ContainerInstance.default.set(serviceMetadata);
42
+ return target;
43
+ };
44
+ }
45
+ __name(Service, "Service");
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ Service
49
+ });
@@ -0,0 +1,16 @@
1
+ export interface ActionDef {
2
+ type: string;
3
+ resourceName?: string;
4
+ actionName?: string;
5
+ method?: string;
6
+ options?: {
7
+ acl?: 'loggedIn' | 'public' | 'private';
8
+ };
9
+ }
10
+ export declare function App(): Function;
11
+ export declare function Db(): Function;
12
+ export declare function InjectLog(): Function;
13
+ export declare function Controller(name: string): (target: any, context: ClassDecoratorContext) => void;
14
+ export declare function Action(name: string, options?: {
15
+ acl?: 'loggedIn' | 'public' | 'private';
16
+ }): (_: any, context: ClassMethodDecoratorContext) => void;
@@ -0,0 +1,86 @@
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 decorators_exports = {};
20
+ __export(decorators_exports, {
21
+ Action: () => Action,
22
+ App: () => App,
23
+ Controller: () => Controller,
24
+ Db: () => Db,
25
+ InjectLog: () => InjectLog
26
+ });
27
+ module.exports = __toCommonJS(decorators_exports);
28
+ var import_container_instance = require("./container-instance.class");
29
+ var import_inject = require("./decorators/inject.decorator");
30
+ var import_service = require("./decorators/service.decorator");
31
+ import_container_instance.Container.set({ id: "actions", value: /* @__PURE__ */ new Map() });
32
+ function App() {
33
+ return (0, import_inject.Inject)("app");
34
+ }
35
+ __name(App, "App");
36
+ function Db() {
37
+ return (0, import_inject.Inject)("db");
38
+ }
39
+ __name(Db, "Db");
40
+ function InjectLog() {
41
+ return (0, import_inject.Inject)("logger");
42
+ }
43
+ __name(InjectLog, "InjectLog");
44
+ function Controller(name) {
45
+ return function(target, context) {
46
+ const serviceOptions = { id: "controller", multiple: true };
47
+ (0, import_service.Service)(serviceOptions)(target, context);
48
+ const actions = import_container_instance.Container.get("actions");
49
+ if (!actions.has(target)) {
50
+ actions.set(target, []);
51
+ }
52
+ actions.get(target).push({
53
+ type: "resource",
54
+ resourceName: name
55
+ });
56
+ };
57
+ }
58
+ __name(Controller, "Controller");
59
+ function Action(name, options) {
60
+ return function(_, context) {
61
+ if (!context.metadata.injects) {
62
+ context.metadata.injects = [];
63
+ }
64
+ context.metadata.injects.push((target) => {
65
+ const actions = import_container_instance.Container.get("actions");
66
+ if (!actions.has(target)) {
67
+ actions.set(target, []);
68
+ }
69
+ actions.get(target).push({
70
+ type: "action",
71
+ method: String(context.name),
72
+ actionName: name,
73
+ options: options || { acl: "private" }
74
+ });
75
+ });
76
+ };
77
+ }
78
+ __name(Action, "Action");
79
+ // Annotate the CommonJS export names for ESM import in node:
80
+ 0 && (module.exports = {
81
+ Action,
82
+ App,
83
+ Controller,
84
+ Db,
85
+ InjectLog
86
+ });
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Indicates that a service has not been initialized yet.
3
+ *
4
+ * _Note: This value is for internal use only._
5
+ */
6
+ export declare const EMPTY_VALUE: unique symbol;
@@ -0,0 +1,27 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var empty_const_exports = {};
19
+ __export(empty_const_exports, {
20
+ EMPTY_VALUE: () => EMPTY_VALUE
21
+ });
22
+ module.exports = __toCommonJS(empty_const_exports);
23
+ const EMPTY_VALUE = Symbol("EMPTY_VALUE");
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ EMPTY_VALUE
27
+ });
@@ -0,0 +1,11 @@
1
+ import { Constructable } from '@tachybase/utils';
2
+ /**
3
+ * Thrown when DI cannot inject value into property decorated by @Inject decorator.
4
+ */
5
+ export declare class CannotInjectValueError extends Error {
6
+ private target;
7
+ private propertyName;
8
+ name: string;
9
+ get message(): string;
10
+ constructor(target: Constructable<unknown>, propertyName: string);
11
+ }
@@ -0,0 +1,40 @@
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 cannot_inject_value_error_exports = {};
20
+ __export(cannot_inject_value_error_exports, {
21
+ CannotInjectValueError: () => CannotInjectValueError
22
+ });
23
+ module.exports = __toCommonJS(cannot_inject_value_error_exports);
24
+ const _CannotInjectValueError = class _CannotInjectValueError extends Error {
25
+ constructor(target, propertyName) {
26
+ super();
27
+ this.target = target;
28
+ this.propertyName = propertyName;
29
+ this.name = "CannotInjectValueError";
30
+ }
31
+ get message() {
32
+ return `Cannot inject value into "${this.target.constructor.name}.${this.propertyName}". Please make sure you setup reflect-metadata properly and you don't use interfaces without service tokens as injection value.`;
33
+ }
34
+ };
35
+ __name(_CannotInjectValueError, "CannotInjectValueError");
36
+ let CannotInjectValueError = _CannotInjectValueError;
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ CannotInjectValueError
40
+ });
@@ -0,0 +1,11 @@
1
+ import { ServiceIdentifier } from '../types/service-identifier.type';
2
+ /**
3
+ * Thrown when DI cannot inject value into property decorated by @Inject decorator.
4
+ */
5
+ export declare class CannotInstantiateValueError extends Error {
6
+ name: string;
7
+ /** Normalized identifier name used in the error message. */
8
+ private normalizedIdentifier;
9
+ get message(): string;
10
+ constructor(identifier: ServiceIdentifier);
11
+ }
@@ -0,0 +1,49 @@
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 cannot_instantiate_value_error_exports = {};
20
+ __export(cannot_instantiate_value_error_exports, {
21
+ CannotInstantiateValueError: () => CannotInstantiateValueError
22
+ });
23
+ module.exports = __toCommonJS(cannot_instantiate_value_error_exports);
24
+ var import_token = require("../token.class");
25
+ const _CannotInstantiateValueError = class _CannotInstantiateValueError extends Error {
26
+ constructor(identifier) {
27
+ var _a, _b;
28
+ super();
29
+ this.name = "CannotInstantiateValueError";
30
+ /** Normalized identifier name used in the error message. */
31
+ this.normalizedIdentifier = "<UNKNOWN_IDENTIFIER>";
32
+ if (typeof identifier === "string") {
33
+ this.normalizedIdentifier = identifier;
34
+ } else if (identifier instanceof import_token.Token) {
35
+ this.normalizedIdentifier = `Token<${identifier.name || "UNSET_NAME"}>`;
36
+ } else if (identifier && (identifier.name || ((_a = identifier.prototype) == null ? void 0 : _a.name))) {
37
+ this.normalizedIdentifier = identifier.name ? `MaybeConstructable<${identifier.name}>` : `MaybeConstructable<${(_b = identifier.prototype) == null ? void 0 : _b.name}>`;
38
+ }
39
+ }
40
+ get message() {
41
+ return `Cannot instantiate the requested value for the "${this.normalizedIdentifier}" identifier. The related metadata doesn't contain a factory or a type to instantiate.`;
42
+ }
43
+ };
44
+ __name(_CannotInstantiateValueError, "CannotInstantiateValueError");
45
+ let CannotInstantiateValueError = _CannotInstantiateValueError;
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ CannotInstantiateValueError
49
+ });
@@ -0,0 +1,11 @@
1
+ import { ServiceIdentifier } from '../types/service-identifier.type';
2
+ /**
3
+ * Thrown when requested service was not found.
4
+ */
5
+ export declare class ServiceNotFoundError extends Error {
6
+ name: string;
7
+ /** Normalized identifier name used in the error message. */
8
+ private normalizedIdentifier;
9
+ get message(): string;
10
+ constructor(identifier: ServiceIdentifier);
11
+ }
@@ -0,0 +1,49 @@
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 service_not_found_error_exports = {};
20
+ __export(service_not_found_error_exports, {
21
+ ServiceNotFoundError: () => ServiceNotFoundError
22
+ });
23
+ module.exports = __toCommonJS(service_not_found_error_exports);
24
+ var import_token = require("../token.class");
25
+ const _ServiceNotFoundError = class _ServiceNotFoundError extends Error {
26
+ constructor(identifier) {
27
+ var _a, _b;
28
+ super();
29
+ this.name = "ServiceNotFoundError";
30
+ /** Normalized identifier name used in the error message. */
31
+ this.normalizedIdentifier = "<UNKNOWN_IDENTIFIER>";
32
+ if (typeof identifier === "string") {
33
+ this.normalizedIdentifier = identifier;
34
+ } else if (identifier instanceof import_token.Token) {
35
+ this.normalizedIdentifier = `Token<${identifier.name || "UNSET_NAME"}>`;
36
+ } else if (identifier && (identifier.name || ((_a = identifier.prototype) == null ? void 0 : _a.name))) {
37
+ this.normalizedIdentifier = identifier.name ? `MaybeConstructable<${identifier.name}>` : `MaybeConstructable<${(_b = identifier.prototype) == null ? void 0 : _b.name}>`;
38
+ }
39
+ }
40
+ get message() {
41
+ return `Service with "${this.normalizedIdentifier}" identifier was not found in the container. Register it before usage via explicitly calling the "Container.set" function or using the "@Service()" decorator.`;
42
+ }
43
+ };
44
+ __name(_ServiceNotFoundError, "ServiceNotFoundError");
45
+ let ServiceNotFoundError = _ServiceNotFoundError;
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ ServiceNotFoundError
49
+ });