@wirestate/core 0.6.3 → 0.7.0-experimental.2

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 +27 -1
  2. package/README.md +48 -37
  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/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## Unreleased
2
+
3
+ - Add `useScope` in `@wirestate/react`
4
+ - New lit elements modules - `@wirestate/lit` and `@wirestate/lit-signals`
5
+ - `EventBus`: add `unsubscribe` method for explicit handler removal by reference
6
+ - `QueryBus`: add `unregister` method for explicit handler removal by type and reference
7
+ - `CommandBus`: add `unregister` method for explicit handler removal by type and reference
8
+ - `WireScope`: add new event/command/query subscribe-unsubscribe methods
9
+ - Export more alias / methods from `@wirestate/core`
10
+ - Export more alias / methods from `@wirestate/react-mobx`
11
+ - Export missing methods typing for `@wirestate/core`
12
+ - Extensive JSDoc coverage for wirestate packages
13
+ - `createIocContainer`: Removed in favor of `createContainer`
14
+ - `createContainer`: Added ability to instantly provide and activate entries, targeted seeds
15
+ - `createInjectablesProvider`: Removed.
16
+ - `IocProvider`: Removed
17
+ - `useRootContainer`: Added separate hook for store management in React tree
18
+ - `ContainerProvider`: Simpler provider for containers.
19
+ - `SubContainerProvider`: Added component solving problems of removed `createInjectablesProvider`
20
+ - `ContainerActivator`: Added separate activation component
21
+ - Replace IoC-context provision APIs with `ContainerContext`, `containerProvide`, `ContainerProvider`, and `useContainerProvision`
22
+ - Replace injectables-provider APIs with `subContainerProvide`, `SubContainerProvider`, and `useSubContainerProvider`
23
+ - Provide plain `Container` values through Lit context instead of wrapper objects
24
+ - Recreate managed child containers when the parent container context changes
25
+ - Add `useContainer` and `useScope` consumers in `@wirestate/lit`
26
+
1
27
  ## 0.6.3
2
28
 
3
29
  - Update readme files for each module
@@ -59,6 +85,6 @@
59
85
  - useService -> useInjection
60
86
  - AbstractService::getService -> AbstractService::resolve
61
87
 
62
- ## 0.1.1
88
+ ## 0.1.0
63
89
 
64
90
  - Initial release
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @wirestate/core
1
+ # @wirestate/core [[monorepo](https://github.com/Neloreck/wirestate)] [[docs](https://neloreck.github.io/wirestate/)]
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@wirestate/core.svg?style=flat-square)](https://www.npmjs.com/package/@wirestate/core)
4
4
  [![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/Neloreck/wirestate/blob/master/LICENSE)
@@ -16,7 +16,7 @@ npm install @wirestate/core reflect-metadata
16
16
  Import `reflect-metadata` once at your application entry point, before any wirestate imports:
17
17
 
18
18
  ```ts
19
- import 'reflect-metadata';
19
+ import "reflect-metadata";
20
20
  ```
21
21
 
22
22
  ## Services
@@ -24,15 +24,13 @@ import 'reflect-metadata';
24
24
  Services are plain classes decorated with `@Injectable`. Each service may inject a `WireScope` which provides access to the event, command, and query buses and to other services in the container.
25
25
 
26
26
  ```ts
27
- import { Injectable, Inject, WireScope } from '@wirestate/core';
27
+ import { Injectable, Inject, WireScope } from "@wirestate/core";
28
28
 
29
29
  @Injectable()
30
30
  export class CounterService {
31
31
  public count = 0;
32
32
 
33
- public constructor(
34
- @Inject(WireScope) private scope: WireScope
35
- ) {}
33
+ public constructor(@Inject(WireScope) private scope: WireScope) {}
36
34
 
37
35
  public increment(): void {
38
36
  this.count++;
@@ -43,13 +41,17 @@ export class CounterService {
43
41
  ## Container
44
42
 
45
43
  ```ts
46
- import { createIocContainer, bindService } from '@wirestate/core';
44
+ import { createContainer, bindService } from "@wirestate/core";
47
45
 
48
- const container = createIocContainer();
46
+ const container = createContainer({
47
+ seed: { baseUrl: "https://example.com" },
48
+ entries: [CounterService],
49
+ });
49
50
 
50
- bindService(container, CounterService);
51
+ bindService(container, AnotherService);
51
52
 
52
- const service = container.get(CounterService);
53
+ const counterService = container.get(CounterService);
54
+ const anotherService = container.get(AnotherService);
53
55
  ```
54
56
 
55
57
  `bindService` binds a class in singleton scope by default.
@@ -60,20 +62,20 @@ Use `bindConstant` to bind a value, `bindEntry` to bind under a custom token.
60
62
  Events are fire-and-forget messages. Any service can emit or subscribe.
61
63
 
62
64
  ```ts
63
- import { OnEvent, WireScope, Inject } from '@wirestate/core';
65
+ import { OnEvent, WireScope, Inject } from "@wirestate/core";
64
66
 
65
67
  @Injectable()
66
68
  export class SenderService {
67
69
  public constructor(@Inject(WireScope) private scope: WireScope) {}
68
70
 
69
71
  public notify(): void {
70
- this.scope.emitEvent('USER_LOGGED_OUT');
72
+ this.scope.emitEvent("USER_LOGGED_OUT");
71
73
  }
72
74
  }
73
75
 
74
76
  @Injectable()
75
77
  export class ReceiverService {
76
- @OnEvent('USER_LOGGED_OUT')
78
+ @OnEvent("USER_LOGGED_OUT")
77
79
  public onLogout(): void {
78
80
  // handle logout
79
81
  }
@@ -87,11 +89,11 @@ export class ReceiverService {
87
89
  Commands are write operations dispatched by token. A single handler is expected per command type.
88
90
 
89
91
  ```ts
90
- import { OnCommand, WireScope, Inject } from '@wirestate/core';
92
+ import { OnCommand, WireScope, Inject } from "@wirestate/core";
91
93
 
92
94
  @Injectable()
93
95
  export class AuthService {
94
- @OnCommand('LOGIN')
96
+ @OnCommand("LOGIN")
95
97
  public async onLogin(payload: { username: string }): Promise<void> {
96
98
  // perform login
97
99
  }
@@ -102,7 +104,7 @@ export class AnotherService {
102
104
  public constructor(@Inject(WireScope) private scope: WireScope) {}
103
105
 
104
106
  public async login(): Promise<void> {
105
- await this.scope.executeCommand('LOGIN').task;
107
+ await this.scope.executeCommand("LOGIN").task;
106
108
  }
107
109
  }
108
110
  ```
@@ -114,13 +116,13 @@ Use `commandOptional` when a handler may not be registered — returns `null` in
114
116
  Queries are request-response operations. A single handler is expected per query type.
115
117
 
116
118
  ```ts
117
- import { OnQuery, WireScope, Inject } from '@wirestate/core';
119
+ import { OnQuery, WireScope, Inject } from "@wirestate/core";
118
120
 
119
121
  @Injectable()
120
122
  export class StoreService {
121
123
  private items: Array<string> = [];
122
124
 
123
- @OnQuery('STORE_ITEMS')
125
+ @OnQuery("STORE_ITEMS")
124
126
  public onGetItems(): Array<string> {
125
127
  return this.items;
126
128
  }
@@ -131,8 +133,8 @@ export class AnotherService {
131
133
  public constructor(@Inject(WireScope) private scope: WireScope) {}
132
134
 
133
135
  public async someActionRequiringItems(): Promise<void> {
134
- const asyncItems: Array<string> = await this.scope.queryData('STORE_ITEMS');
135
- const syncItems: Array<string> = await this.scope.queryData('STORE_ITEMS');
136
+ const asyncItems: Array<string> = await this.scope.queryData("STORE_ITEMS");
137
+ const syncItems: Array<string> = await this.scope.queryData("STORE_ITEMS");
136
138
  }
137
139
  }
138
140
  ```
@@ -142,7 +144,7 @@ export class AnotherService {
142
144
  Seeds pass initial data to services when they are activated.
143
145
 
144
146
  ```ts
145
- import { SEED, Injectable, Inject } from '@wirestate/core';
147
+ import { SEED, Injectable, Inject } from "@wirestate/core";
146
148
 
147
149
  // Shared seed — same object injected into all services in the tree:
148
150
  @Injectable()
@@ -165,7 +167,7 @@ In React, pass them as `seed` or `seeds` props to the provider — see `@wiresta
165
167
  ## Lifecycle
166
168
 
167
169
  ```ts
168
- import { OnActivated, OnDeactivation } from '@wirestate/core';
170
+ import { OnActivated, OnDeactivation } from "@wirestate/core";
169
171
 
170
172
  @Injectable()
171
173
  export class PollingService {
@@ -173,7 +175,7 @@ export class PollingService {
173
175
 
174
176
  @OnActivated()
175
177
  public onActivated(): void {
176
- this.timer = setInterval(() => console.info('interval execution'), 5000);
178
+ this.timer = setInterval(() => console.info("interval execution"), 5000);
177
179
  }
178
180
 
179
181
  @OnDeactivation()
@@ -190,14 +192,23 @@ export class PollingService {
190
192
 
191
193
  `WireScope` is injected per-service and exposes:
192
194
 
193
- | Method | Description |
194
- |---|---|
195
- | `getContainer()` | Access the raw IoC container |
196
- | `resolve(token)` | Resolve a service or value by token |
197
- | `getSeed(token)` | Get the per-service seed for a given token |
198
- | `emitEvent(type, payload?)` | Emit an event |
199
- | `command(type)` | Get a caller for a command |
200
- | `query(type)` | Get a caller for a query |
195
+ | Method | Description |
196
+ | ----------------------------------------- | --------------------------------------------------------------- |
197
+ | `getContainer()` | Access the raw IoC container |
198
+ | `resolve(token)` | Resolve a service or value by token |
199
+ | `resolveOptional(token)` | Resolve a service or value, returns `null` if not bound |
200
+ | `getSeed(token?)` | Get the per-service or shared seed |
201
+ | `emitEvent(type, payload?, from?)` | Emit an event |
202
+ | `subscribeToEvent(handler)` | Subscribe a handler to all events; returns unsubscribe function |
203
+ | `unsubscribeFromEvent(handler)` | Remove a specific event subscription by handler reference |
204
+ | `queryData(type, data?)` | Dispatch a query and return the result |
205
+ | `queryOptionalData(type, data?)` | Dispatch a query; returns `null` if no handler is registered |
206
+ | `registerQueryHandler(type, handler)` | Register a query handler; returns unregister function |
207
+ | `unregisterQueryHandler(type, handler)` | Remove a specific query handler by type and reference |
208
+ | `executeCommand(type, data?)` | Dispatch a command and return a descriptor |
209
+ | `executeOptionalCommand(type, data?)` | Dispatch a command; returns `null` if no handler is registered |
210
+ | `registerCommandHandler(type, handler)` | Register a command handler; returns unregister function |
211
+ | `unregisterCommandHandler(type, handler)` | Remove a specific command handler by type and reference |
201
212
 
202
213
  ## Test utilities
203
214
 
@@ -210,18 +221,18 @@ import {
210
221
  mockBindService,
211
222
  mockBindEntry,
212
223
  mockUnbindService,
213
- } from '@wirestate/core/test-utils';
224
+ } from "@wirestate/core/test-utils";
214
225
  ```
215
226
 
216
227
  ### `mockContainer(options?)`
217
228
 
218
229
  Creates a configured IoC container for testing. Accepts an optional object:
219
230
 
220
- | Option | Type | Description |
221
- |---|---|---|
222
- | `entries` | `Array<Newable \| InjectableDescriptor>` | Services or descriptors to bind |
223
- | `activate` | `Array<ServiceIdentifier>` | Tokens to resolve immediately after binding |
224
- | `skipLifecycle` | `boolean` | Skip `@OnActivated` / `@OnDeactivation` hooks |
231
+ | Option | Type | Description |
232
+ | --------------- | ---------------------------------------- | --------------------------------------------- |
233
+ | `entries` | `Array<Newable \| InjectableDescriptor>` | Services or descriptors to bind |
234
+ | `activate` | `Array<ServiceIdentifier>` | Tokens to resolve immediately after binding |
235
+ | `skipLifecycle` | `boolean` | Skip `@OnActivated` / `@OnDeactivation` hooks |
225
236
 
226
237
  ```ts
227
238
  const container = mockContainer({