@wirestate/core 0.6.1 → 0.7.0-experimental.1

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 (167) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.md +186 -232
  3. package/cjs/development/index.js +325 -91
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/development/lib.js +1033 -248
  6. package/cjs/development/lib.js.map +1 -1
  7. package/cjs/development/test-utils.js +95 -32
  8. package/cjs/development/test-utils.js.map +1 -1
  9. package/cjs/production/index.js +1 -1
  10. package/cjs/production/index.js.map +1 -1
  11. package/cjs/production/lib.js +1 -1
  12. package/cjs/production/lib.js.map +1 -1
  13. package/cjs/production/test-utils.js +1 -1
  14. package/cjs/production/test-utils.js.map +1 -1
  15. package/esm/development/alias.js +10 -1
  16. package/esm/development/alias.js.map +1 -1
  17. package/esm/development/bind/bind-constant.js +25 -4
  18. package/esm/development/bind/bind-constant.js.map +1 -1
  19. package/esm/development/bind/bind-dynamic-value.js +27 -7
  20. package/esm/development/bind/bind-dynamic-value.js.map +1 -1
  21. package/esm/development/bind/bind-entry.js +50 -17
  22. package/esm/development/bind/bind-entry.js.map +1 -1
  23. package/esm/development/bind/bind-service.js +71 -19
  24. package/esm/development/bind/bind-service.js.map +1 -1
  25. package/esm/development/bind/get-entry-token.js +21 -5
  26. package/esm/development/bind/get-entry-token.js.map +1 -1
  27. package/esm/development/commands/command-bus.js +93 -46
  28. package/esm/development/commands/command-bus.js.map +1 -1
  29. package/esm/development/commands/command-optional.js +28 -5
  30. package/esm/development/commands/command-optional.js.map +1 -1
  31. package/esm/development/commands/command.js +26 -5
  32. package/esm/development/commands/command.js.map +1 -1
  33. package/esm/development/commands/get-command-handler-metadata.js +8 -3
  34. package/esm/development/commands/get-command-handler-metadata.js.map +1 -1
  35. package/esm/development/commands/on-command.js +19 -3
  36. package/esm/development/commands/on-command.js.map +1 -1
  37. package/esm/development/container/create-base-container.js +57 -0
  38. package/esm/development/container/create-base-container.js.map +1 -0
  39. package/esm/development/container/create-container.js +78 -0
  40. package/esm/development/container/create-container.js.map +1 -0
  41. package/esm/development/container/wire-scope.js +236 -54
  42. package/esm/development/container/wire-scope.js.map +1 -1
  43. package/esm/development/error/error-code.js +2 -1
  44. package/esm/development/error/error-code.js.map +1 -1
  45. package/esm/development/error/wirestate-error.js +25 -4
  46. package/esm/development/error/wirestate-error.js.map +1 -1
  47. package/esm/development/events/build-event-dispatcher.js +20 -2
  48. package/esm/development/events/build-event-dispatcher.js.map +1 -1
  49. package/esm/development/events/emit-event.js +18 -5
  50. package/esm/development/events/emit-event.js.map +1 -1
  51. package/esm/development/events/event-bus.js +58 -9
  52. package/esm/development/events/event-bus.js.map +1 -1
  53. package/esm/development/events/get-event-handler-metadata.js +19 -4
  54. package/esm/development/events/get-event-handler-metadata.js.map +1 -1
  55. package/esm/development/events/on-event.js +31 -2
  56. package/esm/development/events/on-event.js.map +1 -1
  57. package/esm/development/index.js +5 -4
  58. package/esm/development/index.js.map +1 -1
  59. package/esm/development/queries/get-query-handler-metadata.js +20 -4
  60. package/esm/development/queries/get-query-handler-metadata.js.map +1 -1
  61. package/esm/development/queries/on-query.js +24 -2
  62. package/esm/development/queries/on-query.js.map +1 -1
  63. package/esm/development/queries/query-bus.js +82 -31
  64. package/esm/development/queries/query-bus.js.map +1 -1
  65. package/esm/development/queries/query-optional.js +19 -5
  66. package/esm/development/queries/query-optional.js.map +1 -1
  67. package/esm/development/queries/query.js +25 -5
  68. package/esm/development/queries/query.js.map +1 -1
  69. package/esm/development/registry.js +81 -24
  70. package/esm/development/registry.js.map +1 -1
  71. package/esm/development/seeds/apply-seeds.js +19 -5
  72. package/esm/development/seeds/apply-seeds.js.map +1 -1
  73. package/esm/development/seeds/apply-shared-seed.js +16 -4
  74. package/esm/development/seeds/apply-shared-seed.js.map +1 -1
  75. package/esm/development/seeds/tokens.js +31 -0
  76. package/esm/development/seeds/tokens.js.map +1 -0
  77. package/esm/development/seeds/unapply-seeds.js +16 -5
  78. package/esm/development/seeds/unapply-seeds.js.map +1 -1
  79. package/esm/development/service/get-activated-handler-metadata.js +16 -4
  80. package/esm/development/service/get-activated-handler-metadata.js.map +1 -1
  81. package/esm/development/service/get-deactivation-handler-metadata.js +16 -4
  82. package/esm/development/service/get-deactivation-handler-metadata.js.map +1 -1
  83. package/esm/development/service/on-activated.js +22 -2
  84. package/esm/development/service/on-activated.js.map +1 -1
  85. package/esm/development/service/on-deactivation.js +22 -2
  86. package/esm/development/service/on-deactivation.js.map +1 -1
  87. package/esm/development/test-utils/mock-bind-entry.js +17 -7
  88. package/esm/development/test-utils/mock-bind-entry.js.map +1 -1
  89. package/esm/development/test-utils/mock-bind-service.js +17 -7
  90. package/esm/development/test-utils/mock-bind-service.js.map +1 -1
  91. package/esm/development/test-utils/mock-container.js +25 -8
  92. package/esm/development/test-utils/mock-container.js.map +1 -1
  93. package/esm/development/test-utils/mock-service.js +18 -5
  94. package/esm/development/test-utils/mock-service.js.map +1 -1
  95. package/esm/development/test-utils/mock-unbind-service.js +16 -3
  96. package/esm/development/test-utils/mock-unbind-service.js.map +1 -1
  97. package/esm/development/types/commands.js +6 -1
  98. package/esm/development/types/commands.js.map +1 -1
  99. package/esm/production/alias.js +1 -1
  100. package/esm/production/alias.js.map +1 -1
  101. package/esm/production/bind/bind-constant.js +1 -1
  102. package/esm/production/bind/bind-constant.js.map +1 -1
  103. package/esm/production/bind/bind-dynamic-value.js +1 -1
  104. package/esm/production/bind/bind-dynamic-value.js.map +1 -1
  105. package/esm/production/bind/bind-entry.js +1 -1
  106. package/esm/production/bind/bind-entry.js.map +1 -1
  107. package/esm/production/bind/bind-service.js.map +1 -1
  108. package/esm/production/bind/get-entry-token.js.map +1 -1
  109. package/esm/production/commands/command-bus.js +1 -1
  110. package/esm/production/commands/command-bus.js.map +1 -1
  111. package/esm/production/commands/command-optional.js.map +1 -1
  112. package/esm/production/commands/command.js.map +1 -1
  113. package/esm/production/commands/get-command-handler-metadata.js.map +1 -1
  114. package/esm/production/commands/on-command.js.map +1 -1
  115. package/esm/production/container/create-base-container.js +1 -0
  116. package/esm/production/container/create-base-container.js.map +1 -0
  117. package/esm/production/container/create-container.js +1 -0
  118. package/esm/production/container/create-container.js.map +1 -0
  119. package/esm/production/container/wire-scope.js +1 -1
  120. package/esm/production/container/wire-scope.js.map +1 -1
  121. package/esm/production/error/error-code.js +1 -1
  122. package/esm/production/error/error-code.js.map +1 -1
  123. package/esm/production/error/wirestate-error.js.map +1 -1
  124. package/esm/production/events/build-event-dispatcher.js.map +1 -1
  125. package/esm/production/events/emit-event.js.map +1 -1
  126. package/esm/production/events/event-bus.js +1 -1
  127. package/esm/production/events/event-bus.js.map +1 -1
  128. package/esm/production/events/get-event-handler-metadata.js.map +1 -1
  129. package/esm/production/events/on-event.js.map +1 -1
  130. package/esm/production/index.js +1 -1
  131. package/esm/production/queries/get-query-handler-metadata.js.map +1 -1
  132. package/esm/production/queries/on-query.js.map +1 -1
  133. package/esm/production/queries/query-bus.js +1 -1
  134. package/esm/production/queries/query-bus.js.map +1 -1
  135. package/esm/production/queries/query-optional.js.map +1 -1
  136. package/esm/production/queries/query.js.map +1 -1
  137. package/esm/production/registry.js +1 -1
  138. package/esm/production/registry.js.map +1 -1
  139. package/esm/production/seeds/apply-seeds.js +1 -1
  140. package/esm/production/seeds/apply-seeds.js.map +1 -1
  141. package/esm/production/seeds/apply-shared-seed.js +1 -1
  142. package/esm/production/seeds/apply-shared-seed.js.map +1 -1
  143. package/esm/production/seeds/tokens.js +1 -0
  144. package/esm/production/seeds/tokens.js.map +1 -0
  145. package/esm/production/seeds/unapply-seeds.js +1 -1
  146. package/esm/production/seeds/unapply-seeds.js.map +1 -1
  147. package/esm/production/service/get-activated-handler-metadata.js.map +1 -1
  148. package/esm/production/service/get-deactivation-handler-metadata.js.map +1 -1
  149. package/esm/production/service/on-activated.js.map +1 -1
  150. package/esm/production/service/on-deactivation.js.map +1 -1
  151. package/esm/production/test-utils/mock-bind-entry.js +1 -1
  152. package/esm/production/test-utils/mock-bind-entry.js.map +1 -1
  153. package/esm/production/test-utils/mock-bind-service.js +1 -1
  154. package/esm/production/test-utils/mock-bind-service.js.map +1 -1
  155. package/esm/production/test-utils/mock-container.js +1 -1
  156. package/esm/production/test-utils/mock-container.js.map +1 -1
  157. package/esm/production/test-utils/mock-service.js.map +1 -1
  158. package/esm/production/test-utils/mock-unbind-service.js.map +1 -1
  159. package/esm/production/types/commands.js.map +1 -1
  160. package/index.d.ts +1159 -229
  161. package/lib.d.ts +128 -9
  162. package/package.json +1 -2
  163. package/test-utils.d.ts +140 -40
  164. package/esm/development/container/create-ioc-container.js +0 -35
  165. package/esm/development/container/create-ioc-container.js.map +0 -1
  166. package/esm/production/container/create-ioc-container.js +0 -1
  167. package/esm/production/container/create-ioc-container.js.map +0 -1
package/lib.d.ts CHANGED
@@ -1,17 +1,136 @@
1
- import { ServiceIdentifier, bindingTypeValues, bindingScopeValues } from 'inversify';
1
+ import { bindingTypeValues, ServiceIdentifier, bindingScopeValues, Newable } from 'inversify';
2
2
 
3
+ /**
4
+ * Inversify binding strategy types.
5
+ *
6
+ * @group Bind
7
+ */
3
8
  type BindingType = (typeof bindingTypeValues)[keyof typeof bindingTypeValues];
9
+ /**
10
+ * Inversify scope strategy types.
11
+ *
12
+ * @group Bind
13
+ */
4
14
  type ScopeBindingType = (typeof bindingScopeValues)[keyof typeof bindingScopeValues];
15
+ /**
16
+ * Represents descriptor used by wirestate bind/provision APIs to describe how one injectable is resolved.
17
+ *
18
+ * @remarks
19
+ * This interface bridges standard Inversify binding options with Wirestate's simplified registration API.
20
+ * It is used by {@link bindConstant}, {@link bindDynamicValue}, and {@link bindEntry}.
21
+ *
22
+ * @group Bind
23
+ *
24
+ * @template T - Service type resolved from container by {@link id} or returned by {@link factory}.
25
+ * @template V - Value type used by constant/value-style bindings via {@link value}.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const descriptor: InjectableDescriptor<UserRepo> = {
30
+ * id: UserRepo,
31
+ * scopeBindingType: "Singleton"
32
+ * };
33
+ * ```
34
+ */
5
35
  interface InjectableDescriptor<T = unknown, V = unknown> {
6
- id: ServiceIdentifier<T>;
7
- value?: V;
8
- bindingType?: BindingType;
9
- scopeBindingType?: ScopeBindingType;
10
36
  /**
11
- * Factory function for dynamic value bindings.
12
- * Used when type is set to DynamicValue.
37
+ * Inversify binding strategy.
38
+ *
39
+ * @remarks
40
+ * Example values: `ConstantValue`, `DynamicValue`, `Factory`, `Provider`.
13
41
  */
14
- factory?: () => T;
42
+ readonly bindingType?: BindingType;
43
+ /**
44
+ * Factory function used by dynamic value bindings.
45
+ *
46
+ * @remarks
47
+ * Called by the {@link Container} to create a service instance of type T.
48
+ */
49
+ readonly factory?: () => T;
50
+ /**
51
+ * Unique service token used by Inversify to locate the injectable binding.
52
+ *
53
+ * @remarks
54
+ * Accepts class constructor, symbol, or string service identifier.
55
+ */
56
+ readonly id: ServiceIdentifier<T>;
57
+ /**
58
+ * Inversify scope strategy for created instances.
59
+ *
60
+ * @remarks
61
+ * Example values: `Singleton`, `Transient`, `Request`.
62
+ */
63
+ readonly scopeBindingType?: ScopeBindingType;
64
+ /**
65
+ * Prebuilt value for value-based bindings.
66
+ *
67
+ * @remarks
68
+ * Used when binding mode expects a direct value instance (e.g., constant values).
69
+ */
70
+ readonly value?: V;
15
71
  }
16
72
 
17
- export type { InjectableDescriptor as I };
73
+ /**
74
+ * Generic object with string or symbol keys and any value.
75
+ *
76
+ * @group general-types
77
+ */
78
+ type AnyObject = Record<string | symbol, any>;
79
+ /**
80
+ * Represents a value that can be null.
81
+ *
82
+ * @template T - The base type.
83
+ * @group general-types
84
+ */
85
+ type Optional<T> = T | null;
86
+ /**
87
+ * Represents a value that can be a T or a Promise resolving to T.
88
+ *
89
+ * @template T - The base type.
90
+ * @group general-types
91
+ */
92
+ type MaybePromise<T> = T | Promise<T>;
93
+
94
+ /**
95
+ * Represents a lookup key for service seeds.
96
+ *
97
+ * @remarks
98
+ * Supports class constructors (for targeted seeds), strings, or symbols.
99
+ *
100
+ * @group Seeds
101
+ */
102
+ type SeedKey = Newable | string | symbol;
103
+ /**
104
+ * Represents a key-value map for targeted seeds.
105
+ *
106
+ * @remarks
107
+ * Used to store initial state values that are injected into services
108
+ * based on their class constructor or a custom token.
109
+ *
110
+ * @group Seeds
111
+ *
112
+ * @template T - The type of values stored in the map.
113
+ */
114
+ type SeedsMap<T = unknown> = Map<SeedKey, T>;
115
+ /**
116
+ * Represents a single service-to-seed mapping entry.
117
+ *
118
+ * @remarks
119
+ * Represented as a readonly tuple of `[SeedKey, T]`.
120
+ *
121
+ * @group Seeds
122
+ *
123
+ * @template T - The type of the seed value.
124
+ */
125
+ type SeedEntry<T = unknown> = readonly [SeedKey, T];
126
+ /**
127
+ * Represents a collection of seed entries.
128
+ *
129
+ * @remarks
130
+ * Used during container initialization to populate the {@link SeedsMap}.
131
+ *
132
+ * @group Seeds
133
+ */
134
+ type SeedEntries = ReadonlyArray<SeedEntry>;
135
+
136
+ export type { AnyObject as A, InjectableDescriptor as I, MaybePromise as M, Optional as O, SeedEntries as S, SeedKey as a, SeedEntry as b, SeedsMap as c };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirestate/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.0-experimental.1",
4
4
  "description": "Store management library core based on inversify",
5
5
  "sideEffects": false,
6
6
  "author": "Syrotenko Igor",
@@ -54,7 +54,6 @@
54
54
  "inversify": "^8.1.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "reflect-metadata": ">=0.2.0",
58
57
  "tslib": ">=2.5.0"
59
58
  },
60
59
  "optionalDependencies": {}
package/test-utils.d.ts CHANGED
@@ -1,107 +1,207 @@
1
1
  import { Container as Container$1, Newable, ServiceIdentifier } from 'inversify';
2
- import { I as InjectableDescriptor } from './lib.js';
2
+ import { I as InjectableDescriptor, A as AnyObject, S as SeedEntries } from './lib.js';
3
3
 
4
4
  /**
5
- * Options for {@link mockBindService}.
5
+ * Represents options for {@link mockBindService}.
6
+ *
7
+ * @group Test-utils
6
8
  */
7
9
  interface MockBindServiceOptions {
8
10
  /**
9
11
  * Whether to skip the activation lifecycle for the service.
10
- * If true, `OnActivated` and `OnDeactivation` hooks will not be triggered.
12
+ *
13
+ * @remarks
14
+ * If true, `@OnActivated` and `@OnDeactivation` hooks will not be triggered.
15
+ *
16
+ * @default false
11
17
  */
12
18
  skipLifecycle?: boolean;
13
19
  }
14
20
  /**
15
21
  * Binds a service class to the IoC container for testing purposes.
16
- * This utility uses {@link bindService} internally to ensure the service is correctly registered
17
- * with the appropriate scope and metadata.
18
22
  *
19
- * @param container - the IoC container to bind the service to
20
- * @param ServiceClass - the service class to bind
21
- * @param options - optional binding configuration
22
- * @returns void
23
+ * @remarks
24
+ * This utility is a testing wrapper for {@link bindService}.
25
+ * It ensures the service is correctly registered with singleton scope and lifecycle metadata.
26
+ *
27
+ * @group Test-utils
28
+ *
29
+ * @template T - The type of the service being bound.
30
+ *
31
+ * @param container - The Inversify {@link Container} to bind the service to.
32
+ * @param ServiceClass - The service class constructor to bind.
33
+ * @param options - Configuration options for the mock binding.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * mockBindService(container, AnalyticsService);
38
+ * ```
23
39
  */
24
40
  declare function mockBindService<T extends object>(container: Container$1, ServiceClass: Newable<T>, options?: MockBindServiceOptions): void;
25
41
 
26
42
  /**
27
- * Options for {@link mockBindEntry}.
43
+ * Represents options for {@link mockBindEntry}.
44
+ *
45
+ * @group Test-utils
28
46
  */
29
47
  interface MockBindEntryOptions {
30
48
  /**
31
49
  * Whether to skip the activation lifecycle for the entry.
32
- * If true, `OnActivated` and `OnDeactivation` hooks will not be triggered.
33
- * Note: This only applies when the entry is a service class or an instance binding.
50
+ *
51
+ * @remarks
52
+ * If true, `@OnActivated` and `@OnDeactivation` hooks will not be triggered.
53
+ * This only applies when the entry is a service class or an instance binding.
54
+ *
55
+ * @default false
34
56
  */
35
57
  skipLifecycle?: boolean;
36
58
  }
37
59
  /**
38
60
  * Binds a service entry to the IoC container for testing purposes.
39
- * This utility uses {@link bindEntry} internally.
40
- * It supports both service classes and injectable descriptors (constants, dynamic values, etc.).
41
61
  *
42
- * @param container - the IoC container to bind the entry to
43
- * @param entry - the service class or injectable descriptor to bind
44
- * @param options - optional binding configuration
45
- * @returns void
62
+ * @remarks
63
+ * This utility is a testing wrapper for {@link bindEntry}.
64
+ * It supports both service classes and {@link InjectableDescriptor} objects.
65
+ *
66
+ * @group Test-utils
67
+ *
68
+ * @template T - The type of the service being bound.
69
+ *
70
+ * @param container - The Inversify {@link Container} to bind the entry to.
71
+ * @param entry - The service class constructor or {@link InjectableDescriptor} to bind.
72
+ * @param options - Configuration options for the mock binding.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * mockBindEntry(container, UserService, { skipLifecycle: true });
77
+ * ```
46
78
  */
47
79
  declare function mockBindEntry<T extends object>(container: Container$1, entry: Newable<T> | InjectableDescriptor, options?: MockBindEntryOptions): void;
48
80
 
49
81
  /**
50
82
  * Unbinds a service from the IoC container.
51
- * This is useful in tests to reset or override specific service registrations.
52
83
  *
53
- * @param container - the IoC container to unbind the service from
54
- * @param ServiceClass - the service class to unbind
84
+ * @remarks
85
+ * This is a convenience wrapper for `container.unbind`.
86
+ * It is useful in tests to reset or override specific service registrations
87
+ * between test cases.
88
+ *
89
+ * @group Test-utils
90
+ *
91
+ * @template T - The type of the service to unbind.
92
+ *
93
+ * @param container - The Inversify {@link Container} to unbind from.
94
+ * @param ServiceClass - The service class constructor to unbind.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * mockUnbindService(container, LegacyService);
99
+ * ```
55
100
  */
56
101
  declare function mockUnbindService<T extends object>(container: Container$1, ServiceClass: Newable<T>): void;
57
102
 
58
103
  /**
59
- * Options for {@link mockContainer}.
104
+ * Represents options for {@link mockContainer}.
105
+ *
106
+ * @group Test-utils
60
107
  */
61
108
  interface MockContainerOptions {
109
+ /**
110
+ * Optional parent container.
111
+ * Enables hierarchical resolution and sharing of bindings.
112
+ */
113
+ readonly parent?: Container$1;
114
+ /**
115
+ * Initial data for the root seed.
116
+ */
117
+ readonly seed?: AnyObject;
118
+ /**
119
+ * Targeted seeds bound to specific injectables or tokens.
120
+ */
121
+ readonly seeds?: SeedEntries;
62
122
  /**
63
123
  * List of services or injectable descriptors to bind to the container.
124
+ *
125
+ * @remarks
126
+ * Accepts class constructors or {@link InjectableDescriptor} objects.
64
127
  */
65
- entries?: Array<Newable<object> | InjectableDescriptor>;
128
+ readonly entries?: Array<Newable<object> | InjectableDescriptor>;
66
129
  /**
67
130
  * List of injection identifiers to immediately activate after binding.
68
- * All identifiers must correspond to entries provided in the `services` list.
131
+ *
132
+ * @remarks
133
+ * Activating a service triggers its resolution and `@OnActivated` hooks.
134
+ * All identifiers must correspond to entries provided in the `entries` list.
69
135
  */
70
- activate?: Array<ServiceIdentifier>;
136
+ readonly activate?: Array<ServiceIdentifier>;
71
137
  /**
72
138
  * Whether to skip the activation lifecycle for all bound services.
73
- * If true, `OnActivated` and `OnDeactivation` hooks will not be triggered.
139
+ *
140
+ * @remarks
141
+ * If true, `@OnActivated` and `@OnDeactivation` hooks will not be triggered.
142
+ *
143
+ * @default false
74
144
  */
75
- skipLifecycle?: boolean;
145
+ readonly skipLifecycle?: boolean;
76
146
  }
77
147
  /**
78
- * Creates and configures a mock IoC container for testing.
79
- * This utility initializes a new container and binds the provided services or descriptors using {@link mockBindEntry}.
80
- * It also supports optional immediate activation of services.
148
+ * Mocks and configures an Inversify {@link Container} for testing.
149
+ *
150
+ * @remarks
151
+ * This utility initializes a new container via {@link createContainer} and
152
+ * binds the provided `entries` using {@link mockBindEntry}. It can also
153
+ * automatically resolve (activate) a subset of services.
81
154
  *
82
- * @param options - configuration options for the mock container
83
- * @returns a configured InversifyJS {@link Container}
155
+ * @group Test-utils
84
156
  *
85
- * @throws {WirestateError} if an identifier in `activate` is not found in `services`
157
+ * @param options - Configuration options for the mock container.
158
+ * @returns A configured Inversify {@link Container}.
159
+ *
160
+ * @throws {WirestateError} If an identifier in `activate` is not found in `entries`.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * const container: Container = mockContainer({
165
+ * entries: [UserService, AuthService],
166
+ * activate: [AuthService]
167
+ * });
168
+ * ```
86
169
  */
87
170
  declare function mockContainer(options?: MockContainerOptions): Container$1;
88
171
 
89
172
  /**
90
- * Options for {@link mockService}.
173
+ * Represents options for {@link mockService}.
174
+ *
175
+ * @group Test-utils
91
176
  */
92
177
  interface MockServiceOptions {
93
178
  /**
94
- * If true, skips the lifecycle hooks (e.g., OnActivated) during service binding and instantiation.
179
+ * If true, skips lifecycle hooks (e.g., `@OnActivated`) during binding and instantiation.
180
+ *
181
+ * @default false
95
182
  */
96
183
  skipLifecycle?: boolean;
97
184
  }
98
185
  /**
99
- * Mocks a service by binding it to an IoC container and returning its instance.
186
+ * Mocks a service by binding it to an IoC container and returning its resolved instance.
187
+ *
188
+ * @remarks
189
+ * This is a high-level utility that combines {@link mockContainer} and {@link mockBindService}.
190
+ * If no container is provided, a fresh one is created.
191
+ *
192
+ * @group Test-utils
193
+ *
194
+ * @template T - The type of the service being mocked.
195
+ *
196
+ * @param service - The service class constructor to mock.
197
+ * @param container - The Inversify container to use (defaults to a new mock container).
198
+ * @param options - Additional options for mocking.
199
+ * @returns The resolved service instance.
100
200
  *
101
- * @param service - the service class to mock
102
- * @param container - the IoC container to use, defaults to a new {@link mockContainer}
103
- * @param options - additional options for mocking
104
- * @returns the instantiated service instance
201
+ * @example
202
+ * ```typescript
203
+ * const service: MyService = mockService(MyService);
204
+ * ```
105
205
  */
106
206
  declare function mockService<T extends object>(service: Newable<T>, container?: Container, options?: MockServiceOptions): T;
107
207
 
@@ -1,35 +0,0 @@
1
- import { Container } from 'inversify';
2
- import { CommandBus } from '../commands/command-bus.js';
3
- import { EventBus } from '../events/event-bus.js';
4
- import { QueryBus } from '../queries/query-bus.js';
5
- import { SEEDS_TOKEN, SEED_TOKEN } from '../registry.js';
6
- import { WireScope } from './wire-scope.js';
7
-
8
- /**
9
- * Creates an IoC container with framework essentials.
10
- *
11
- * @param options - container configuration
12
- * @returns new IoC container
13
- */
14
- function createIocContainer(options) {
15
- var _a;
16
- if (options === void 0) {
17
- options = {};
18
- }
19
- var container = new Container({
20
- defaultScope: "Singleton",
21
- parent: options.parent
22
- });
23
- container.bind(EventBus).toConstantValue(new EventBus());
24
- container.bind(QueryBus).toConstantValue(new QueryBus());
25
- container.bind(CommandBus).toConstantValue(new CommandBus());
26
- container.bind(SEEDS_TOKEN).toConstantValue(new Map());
27
- container.bind(SEED_TOKEN).toConstantValue((_a = options.seed) !== null && _a !== void 0 ? _a : {});
28
- container.bind(WireScope).toResolvedValue(function () {
29
- return new WireScope(container);
30
- }).inTransientScope();
31
- return container;
32
- }
33
-
34
- export { createIocContainer };
35
- //# sourceMappingURL=create-ioc-container.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-ioc-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-ioc-container.ts"],"sourcesContent":[null],"names":["createIocContainer","options","container","Container","defaultScope","parent","bind","EventBus","toConstantValue","QueryBus","CommandBus","SEEDS_TOKEN","Map","SEED_TOKEN","_a","seed","WireScope","toResolvedValue","inTransientScope"],"mappings":";;;;;;;AAyBA;;;;;AAKG;AACG,SAAUA,kBAAkBA,CAACC,OAAuC,EAAA;;AAAvC,EAAA,IAAAA,OAAA,KAAA,MAAA,EAAA;IAAAA,OAAA,GAAA,EAAuC;AAAA,EAAA;AAGxE,EAAA,IAAMC,SAAS,GAAc,IAAIC,SAAS,CAAC;AACzCC,IAAAA,YAAY,EAAE,WAAW;IACzBC,MAAM,EAAEJ,OAAO,CAACI;AACjB,GAAA,CAAC;AAEFH,EAAAA,SAAS,CAACI,IAAI,CAACC,QAAQ,CAAC,CAACC,eAAe,CAAC,IAAID,QAAQ,EAAE,CAAC;AACxDL,EAAAA,SAAS,CAACI,IAAI,CAACG,QAAQ,CAAC,CAACD,eAAe,CAAC,IAAIC,QAAQ,EAAE,CAAC;AACxDP,EAAAA,SAAS,CAACI,IAAI,CAACI,UAAU,CAAC,CAACF,eAAe,CAAC,IAAIE,UAAU,EAAE,CAAC;AAC5DR,EAAAA,SAAS,CAACI,IAAI,CAACK,WAAW,CAAC,CAACH,eAAe,CAAC,IAAII,GAAG,EAAc,CAAC;EAClEV,SAAS,CAACI,IAAI,CAACO,UAAU,CAAC,CAACL,eAAe,CAAC,CAAAM,EAAA,GAAAb,OAAO,CAACc,IAAI,MAAA,IAAA,IAAAD,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,EAAE,CAAC;EAE9DZ,SAAS,CACNI,IAAI,CAACU,SAAS,CAAC,CACfC,eAAe,CAAC,YAAA;AAAiB,IAAA,OAAA,IAAID,SAAS,CAACd,SAAS,CAAC;AAAxB,EAAA,CAAwB,CAAC,CAC1DgB,gBAAgB,EAAE;AAIrB,EAAA,OAAOhB,SAAS;AAClB;;;;"}
@@ -1 +0,0 @@
1
- import{Container as n}from"inversify";import{CommandBus as e}from"../commands/command-bus.js";import{EventBus as o}from"../events/event-bus.js";import{QueryBus as t}from"../queries/query-bus.js";import{SEEDS_TOKEN as r,SEED_TOKEN as i}from"../registry.js";import{WireScope as s}from"./wire-scope.js";function a(a){var u;void 0===a&&(a={});var m=new n({defaultScope:"Singleton",parent:a.parent});return m.bind(o).toConstantValue(new o),m.bind(t).toConstantValue(new t),m.bind(e).toConstantValue(new e),m.bind(r).toConstantValue(new Map),m.bind(i).toConstantValue(null!==(u=a.seed)&&void 0!==u?u:{}),m.bind(s).toResolvedValue((function(){return new s(m)})).inTransientScope(),m}export{a as createIocContainer};//# sourceMappingURL=create-ioc-container.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-ioc-container.js","sources":["../../../../../../../../src/wirestate-core/container/create-ioc-container.ts"],"sourcesContent":[null],"names":["Container","CommandBus","EventBus","QueryBus","SEEDS_TOKEN","SEED_TOKEN","WireScope","createIocContainer","options","container","defaultScope","parent","bind","toConstantValue","Map","_a","seed","toResolvedValue","inTransientScope"],"mappings":"oBAyBAA,MAAA,iCAAAC,MAAA,gDAAAC,MAAA,4CAAAC,MAAA,gDAAAC,gBAAAC,MAAA,qCAAAC,MAAA,kBAMM,SAAUC,EAAmBC,cAAA,IAAAA,IAAAA,EAAA,CAAA,GAGjC,IAAMC,EAAuB,IAAIT,EAAU,CACzCU,aAAc,YACdC,OAAQH,EAAQG,SAgBlB,OAbAF,EAAUG,KAAKV,GAAUW,gBAAgB,IAAIX,GAC7CO,EAAUG,KAAKT,GAAUU,gBAAgB,IAAIV,GAC7CM,EAAUG,KAAKX,GAAYY,gBAAgB,IAAIZ,GAC/CQ,EAAUG,KAAKR,GAAaS,gBAAgB,IAAIC,KAChDL,EAAUG,KAAKP,GAAYQ,gBAA4B,QAAZE,EAAAP,EAAQQ,YAAI,IAAAD,EAAAA,EAAI,CAAA,GAE3DN,EACGG,KAAKN,GACLW,iBAAgB,WAAiB,OAAA,IAAIX,EAAUG,EAAd,IACjCS,mBAIIT,CACT,QAAAF"}