@med1802/repository-manager 3.1.1 → 3.1.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 (42) hide show
  1. package/README.md +63 -63
  2. package/dist/core/messenger.d.ts +9 -0
  3. package/dist/core/messenger.d.ts.map +1 -0
  4. package/dist/core/messenger.js +40 -0
  5. package/dist/core/repository.d.ts +2 -2
  6. package/dist/core/repository.d.ts.map +1 -1
  7. package/dist/core/repository.js +8 -40
  8. package/dist/infrastructure/logger.d.ts +1 -1
  9. package/dist/infrastructure/logger.d.ts.map +1 -1
  10. package/dist/manager.d.ts.map +1 -1
  11. package/dist/manager.js +2 -3
  12. package/dist/types/observer.types.d.ts +5 -5
  13. package/dist/types/observer.types.d.ts.map +1 -1
  14. package/dist/types/repository.types.d.ts +7 -7
  15. package/dist/types/repository.types.d.ts.map +1 -1
  16. package/dist/types/workspace.types.d.ts +2 -2
  17. package/dist/types/workspace.types.d.ts.map +1 -1
  18. package/dist/workspace/client.d.ts +2 -2
  19. package/dist/workspace/client.d.ts.map +1 -1
  20. package/dist/workspace/client.js +1 -7
  21. package/dist/workspace/context.d.ts +8 -5
  22. package/dist/workspace/context.d.ts.map +1 -1
  23. package/dist/workspace/context.js +4 -21
  24. package/dist/workspace/index.d.ts +2 -0
  25. package/dist/workspace/index.d.ts.map +1 -1
  26. package/dist/workspace/index.js +2 -0
  27. package/dist/workspace/mount.d.ts +35 -1
  28. package/dist/workspace/mount.d.ts.map +1 -1
  29. package/dist/workspace/mount.js +26 -23
  30. package/package.json +1 -1
  31. package/src/core/messenger.ts +48 -0
  32. package/src/core/repository.ts +9 -41
  33. package/src/infrastructure/logger.ts +1 -1
  34. package/src/manager.ts +2 -3
  35. package/src/types/observer.types.ts +5 -5
  36. package/src/types/repository.types.ts +7 -7
  37. package/src/types/workspace.types.ts +2 -2
  38. package/src/workspace/client.ts +3 -10
  39. package/src/workspace/context.ts +12 -27
  40. package/src/workspace/index.ts +2 -0
  41. package/src/workspace/mount.ts +31 -28
  42. package/tsconfig.tsbuildinfo +1 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@ A lightweight, type-safe repository manager with dependency injection, event-dri
5
5
  ## ✨ Features
6
6
 
7
7
  - ✅ **Dependency Injection** - Inject dependencies into repositories
8
- - ✅ **Event-Driven Architecture** - Built-in observer pattern for inter-repository communication
8
+ - ✅ **Event-Driven Architecture** - Built-in messenger pattern for inter-repository communication
9
9
  - ✅ **Plugin System** - Define repositories as plugins
10
10
  - ✅ **Lifecycle Management** - Automatic connection/disconnection with reference counting
11
11
  - ✅ **Multi-Workspace Support** - Manage multiple isolated workspaces with different dependencies
@@ -15,7 +15,7 @@ A lightweight, type-safe repository manager with dependency injection, event-dri
15
15
  - ✅ **Logging** - Built-in logging with colored console output
16
16
  - ✅ **Memory Efficient** - Automatic cleanup when no connections remain
17
17
  - ✅ **Middleware Support** - Intercept and modify repository method calls
18
- - ✅ **Scoped Observer** - Hierarchical event system for organized communication
18
+ - ✅ **Fire and Forget Messaging** - Hierarchical event system for organized communication
19
19
 
20
20
  ## 📦 Installation
21
21
 
@@ -46,16 +46,16 @@ const dependencies = {
46
46
  },
47
47
  };
48
48
 
49
- // Create workspace with plugins
49
+ // Create workspace with repositories
50
50
  const { queryRepository } = manager.createWorkspace({
51
51
  id: "app",
52
52
  logging: true,
53
53
  dependencies,
54
- plugins: () => [
54
+ repositories: () => [
55
55
  {
56
56
  id: "user-repo",
57
57
  install({ instance }): IUserRepository {
58
- const { dependencies, observer } = instance;
58
+ const { dependencies, messenger } = instance;
59
59
  return {
60
60
  async getUsers() {
61
61
  return dependencies.httpClient.get("/api/users");
@@ -63,7 +63,7 @@ const { queryRepository } = manager.createWorkspace({
63
63
  async createUser(user) {
64
64
  const result = await dependencies.httpClient.post("/api/users", user);
65
65
  // Notify other repositories about new user
66
- observer.dispatch({
66
+ messenger.dispatch({
67
67
  type: "user.created",
68
68
  repositoryId: "user-repo",
69
69
  message: result,
@@ -101,10 +101,10 @@ Repository Manager follows a hierarchical pattern:
101
101
  const manager = repositoryManager(); // Global manager
102
102
  const workspace = manager.createWorkspace({ // Workspace instance
103
103
  id: "app",
104
- infrastructure,
105
- logging: true
104
+ dependencies,
105
+ logging: true,
106
+ repositories: () => [...] // Define repositories
106
107
  });
107
- workspace.defineRepository({...}); // Define repositories
108
108
  workspace.queryRepository("repo-id"); // Query repositories
109
109
  ```
110
110
 
@@ -113,8 +113,8 @@ workspace.queryRepository("repo-id"); // Query repositories
113
113
  Workspace is the **entry point** for all operations. It encapsulates:
114
114
 
115
115
  - Dependencies (shared services/infrastructure)
116
- - Plugin definitions (repositories)
117
- - Observer system for events
116
+ - Repository definitions
117
+ - Messenger system for events
118
118
  - Logging configuration
119
119
 
120
120
  ```typescript
@@ -125,31 +125,31 @@ const { queryRepository } = manager.createWorkspace({
125
125
  httpClient: myHttpClient,
126
126
  cache: myCache,
127
127
  },
128
- plugins: () => [
129
- // Repository plugins defined here
128
+ repositories: () => [
129
+ // Repository definitions here
130
130
  ],
131
131
  });
132
132
  ```
133
133
 
134
- ### 3. Observer System
134
+ ### 3. Messenger System
135
135
 
136
- The built-in observer enables **event-driven inter-repository communication**:
136
+ The built-in messenger enables **fire-and-forget inter-repository communication**:
137
137
 
138
138
  ```typescript
139
139
  const { queryRepository } = manager.createWorkspace({
140
140
  id: "app",
141
141
  dependencies,
142
- plugins: () => [
142
+ repositories: () => [
143
143
  // Repository that dispatches events
144
144
  {
145
145
  id: "user-repo",
146
146
  install({ instance }) {
147
- const { observer } = instance;
147
+ const { messenger } = instance;
148
148
  return {
149
149
  async createUser(user) {
150
150
  const result = await saveUser(user);
151
151
  // Notify other repositories
152
- observer.dispatch({
152
+ messenger.dispatch({
153
153
  type: "user.created",
154
154
  repositoryId: "user-repo",
155
155
  message: result,
@@ -163,10 +163,10 @@ const { queryRepository } = manager.createWorkspace({
163
163
  {
164
164
  id: "notification-repo",
165
165
  install({ instance }) {
166
- const { observer } = instance;
166
+ const { messenger } = instance;
167
167
 
168
168
  // Subscribe to user events
169
- observer.subscribe((payload) => {
169
+ messenger.subscribe((payload) => {
170
170
  if (payload.type === "user.created") {
171
171
  console.log("New user:", payload.message);
172
172
  // Send welcome email, etc.
@@ -205,7 +205,7 @@ Creates a workspace with dependencies and plugins.
205
205
  - `config: IWorkspaceConfig<D>`
206
206
  - `id: string` - Unique identifier for the workspace
207
207
  - `dependencies: D` - Dependencies to inject into repositories
208
- - `plugins: () => IPlugin[]` - Function that returns array of repository plugins
208
+ - `repositories: () => IRepositoryConfig[]` - Function that returns array of repository configs
209
209
  - `logging?: boolean` - Enable/disable logging (default: `false`)
210
210
 
211
211
  **Returns:** Object with workspace methods:
@@ -221,7 +221,7 @@ const { queryRepository } = manager.createWorkspace({
221
221
  httpClient: myHttpClient,
222
222
  database: myDb,
223
223
  },
224
- plugins: () => [
224
+ repositories: () => [
225
225
  {
226
226
  id: "user-repo",
227
227
  install({ instance }) {
@@ -233,17 +233,17 @@ const { queryRepository } = manager.createWorkspace({
233
233
  });
234
234
  ```
235
235
 
236
- ### Plugin Definition
236
+ ### Repository Definition
237
237
 
238
- Defines a repository plugin within the workspace.
238
+ Defines a repository within the workspace.
239
239
 
240
- **Plugin Structure:**
240
+ **Repository Structure:**
241
241
 
242
- - `IPlugin<D, R>`
242
+ - `IRepositoryConfig<D, R>`
243
243
  - `id: string` - Unique identifier for the repository
244
244
  - `install: ({ instance }) => R` - Factory function that returns repository instance
245
245
  - `instance.dependencies` - Injected dependencies
246
- - `instance.observer` - Observer for event-driven communication
246
+ - `instance.messenger` - Messenger for fire-and-forget communication
247
247
  - `onConnect?: () => void` - Called when repository is first connected
248
248
  - `onDisconnect?: () => void` - Called when repository is last disconnected
249
249
  - `middlewares?: Middleware[]` - Array of middleware functions
@@ -251,14 +251,14 @@ Defines a repository plugin within the workspace.
251
251
  **Example:**
252
252
 
253
253
  ```typescript
254
- plugins: () => [
254
+ repositories: () => [
255
255
  {
256
256
  id: "user-repo",
257
257
  install({ instance }): IUserRepository {
258
- const { dependencies, observer } = instance;
258
+ const { dependencies, messenger } = instance;
259
259
 
260
260
  // Subscribe to events
261
- observer.subscribe((payload) => {
261
+ messenger.subscribe((payload) => {
262
262
  console.log("Event received:", payload);
263
263
  });
264
264
 
@@ -266,7 +266,7 @@ plugins: () => [
266
266
  async createUser(user) {
267
267
  const result = await dependencies.httpClient.post("/users", user);
268
268
  // Dispatch event
269
- observer.dispatch({
269
+ messenger.dispatch({
270
270
  type: "user.created",
271
271
  repositoryId: "user-repo",
272
272
  message: result,
@@ -305,34 +305,34 @@ await repository.getUsers();
305
305
  disconnect();
306
306
  ```
307
307
 
308
- ### `observer.dispatch<P>(payload)`
308
+ ### `messenger.dispatch<P>(payload)`
309
309
 
310
- Dispatch an event to notify other repositories.
310
+ Dispatch an event to notify other repositories (fire-and-forget).
311
311
 
312
312
  **Parameters:**
313
313
 
314
- - `payload: IObserverDispatch<P>`
314
+ - `payload: IMessengerDispatch<P>`
315
315
  - `type: string` - Event type identifier
316
- - `repositoryId: string` - Source repository identifier
316
+ - `repositoryId: string` - Target repository identifier
317
317
  - `message?: P` - Optional payload data
318
318
 
319
319
  **Example:**
320
320
 
321
321
  ```typescript
322
- observer.dispatch({
322
+ messenger.dispatch({
323
323
  type: "user.created",
324
- repositoryId: "user-repo",
324
+ repositoryId: "notification-repo",
325
325
  message: { userId: "123", email: "user@example.com" },
326
326
  });
327
327
  ```
328
328
 
329
- ### `observer.subscribe<P>(callback)`
329
+ ### `messenger.subscribe<P>(callback)`
330
330
 
331
331
  Subscribe to events from other repositories.
332
332
 
333
333
  **Parameters:**
334
334
 
335
- - `callback: (payload: IObserverSubscribePayload<P>) => void` - Callback function
335
+ - `callback: (payload: IMessengerSubscribePayload<P>) => void` - Callback function
336
336
  - `payload.type: string` - Event type
337
337
  - `payload.source: string` - Source repository
338
338
  - `payload.message: P` - Event payload
@@ -340,7 +340,7 @@ Subscribe to events from other repositories.
340
340
  **Example:**
341
341
 
342
342
  ```typescript
343
- observer.subscribe((payload) => {
343
+ messenger.subscribe((payload) => {
344
344
  if (payload.type === "user.created") {
345
345
  console.log("User created:", payload.message);
346
346
  console.log("From repository:", payload.source);
@@ -350,9 +350,9 @@ observer.subscribe((payload) => {
350
350
 
351
351
  ## 🎯 Advanced Usage
352
352
 
353
- ### Observer System Benefits
353
+ ### Messenger System Benefits
354
354
 
355
- The built-in observer system enables decoupled communication between repositories:
355
+ The built-in messenger system enables decoupled communication between repositories:
356
356
 
357
357
  **Benefits:**
358
358
 
@@ -372,7 +372,7 @@ The built-in observer system enables decoupled communication between repositorie
372
372
 
373
373
  ### Event-Driven Communication
374
374
 
375
- Repositories can communicate through the observer system:
375
+ Repositories can communicate through the messenger system:
376
376
 
377
377
  ```typescript
378
378
  const { queryRepository } = manager.createWorkspace({
@@ -381,27 +381,27 @@ const { queryRepository } = manager.createWorkspace({
381
381
  httpClient: myHttpClient,
382
382
  emailService: myEmailService,
383
383
  },
384
- plugins: () => [
384
+ repositories: () => [
385
385
  // User repository dispatches events
386
386
  {
387
387
  id: "user-repo",
388
388
  install({ instance }) {
389
- const { dependencies, observer } = instance;
389
+ const { dependencies, messenger } = instance;
390
390
  return {
391
391
  async createUser(user) {
392
392
  const result = await dependencies.httpClient.post("/users", user);
393
- observer.dispatch({
393
+ messenger.dispatch({
394
394
  type: "user.created",
395
- repositoryId: "user-repo",
395
+ repositoryId: "notification-repo",
396
396
  message: result,
397
397
  });
398
398
  return result;
399
399
  },
400
400
  async deleteUser(userId) {
401
401
  await dependencies.httpClient.delete(`/users/${userId}`);
402
- observer.dispatch({
402
+ messenger.dispatch({
403
403
  type: "user.deleted",
404
- repositoryId: "user-repo",
404
+ repositoryId: "notification-repo",
405
405
  message: { userId },
406
406
  });
407
407
  },
@@ -412,9 +412,9 @@ const { queryRepository } = manager.createWorkspace({
412
412
  {
413
413
  id: "notification-repo",
414
414
  install({ instance }) {
415
- const { observer, dependencies } = instance;
415
+ const { messenger, dependencies } = instance;
416
416
 
417
- observer.subscribe((payload) => {
417
+ messenger.subscribe((payload) => {
418
418
  if (payload.type === "user.created") {
419
419
  dependencies.emailService.send({
420
420
  to: payload.message.email,
@@ -435,9 +435,9 @@ const { queryRepository } = manager.createWorkspace({
435
435
  {
436
436
  id: "analytics-repo",
437
437
  install({ instance }) {
438
- const { observer } = instance;
438
+ const { messenger } = instance;
439
439
 
440
- observer.subscribe((payload) => {
440
+ messenger.subscribe((payload) => {
441
441
  if (payload.type === "user.created") {
442
442
  console.log("Track new user:", payload.message);
443
443
  }
@@ -464,8 +464,8 @@ const apiWorkspace = manager.createWorkspace({
464
464
  httpClient: apiClient,
465
465
  cache: redisCache,
466
466
  },
467
- plugins: () => [
468
- // API repository plugins
467
+ repositories: () => [
468
+ // API repositories
469
469
  ],
470
470
  logging: true,
471
471
  });
@@ -477,13 +477,13 @@ const dbWorkspace = manager.createWorkspace({
477
477
  db: postgresClient,
478
478
  logger: winstonLogger,
479
479
  },
480
- plugins: () => [
481
- // Database repository plugins
480
+ repositories: () => [
481
+ // Database repositories
482
482
  ],
483
483
  logging: false,
484
484
  });
485
485
 
486
- // Each workspace has isolated repositories and observers
486
+ // Each workspace has isolated repositories and messengers
487
487
  ```
488
488
 
489
489
  ### TypeScript Best Practices
@@ -508,7 +508,7 @@ interface IUserRepository {
508
508
  const { queryRepository } = manager.createWorkspace<IDependencies>({
509
509
  id: "app",
510
510
  dependencies,
511
- plugins: () => [
511
+ repositories: () => [
512
512
  {
513
513
  id: "user-repo",
514
514
  install({ instance }): IUserRepository {
@@ -577,7 +577,7 @@ const cacheMiddleware: Middleware = (method, args, next) => {
577
577
 
578
578
  const { queryRepository } = manager.createWorkspace({
579
579
  dependencies,
580
- plugins: () => [
580
+ repositories: () => [
581
581
  {
582
582
  id: "user-repo",
583
583
  install({ instance }) {
@@ -608,8 +608,8 @@ Enable logging to see connection lifecycle and events:
608
608
  const { queryRepository } = manager.createWorkspace({
609
609
  id: "app",
610
610
  dependencies,
611
- plugins: () => [
612
- // plugins here
611
+ repositories: () => [
612
+ // repositories here
613
613
  ],
614
614
  logging: true, // Enables colored console output
615
615
  });
@@ -623,6 +623,6 @@ This library implements several design patterns:
623
623
  - **Factory Pattern** - Repositories are created using factory functions
624
624
  - **Singleton Pattern** - Each repository is a singleton per workspace (with reference counting)
625
625
  - **Repository Pattern** - Abstracts data access logic
626
- - **Observer Pattern** - Event-driven communication between repositories
626
+ - **Messenger Pattern** - Fire-and-forget communication between repositories
627
627
  - **Workspace Pattern** - Clean API for managing dependencies and lifecycle
628
628
  - **Pub/Sub Pattern** - Repositories can publish and subscribe to events
@@ -0,0 +1,9 @@
1
+ import type { scopedObserverType } from "../infrastructure";
2
+ import type { IMessenger, IRepositoryConfig } from "../types";
3
+ declare function createMessenger(config: {
4
+ observer: scopedObserverType;
5
+ subscriptions: (() => void)[];
6
+ repositoryConfig: IRepositoryConfig;
7
+ }): IMessenger;
8
+ export { createMessenger };
9
+ //# sourceMappingURL=messenger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messenger.d.ts","sourceRoot":"","sources":["../../src/core/messenger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE9D,iBAAS,eAAe,CAAE,MAAM,EAAE;IAC9B,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,aAAa,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAC9B,gBAAgB,EAAE,iBAAiB,CAAC;CACvC,GAAG,UAAU,CAsCX;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,40 @@
1
+ function createMessenger(config) {
2
+ const { observer, subscriptions, repositoryConfig } = config;
3
+ return {
4
+ dispatch({ repositoryId, type, message }) {
5
+ if (repositoryId === repositoryConfig.id) {
6
+ console.warn("WARNING: DISPATCHING TO SELF");
7
+ return;
8
+ }
9
+ observer.dispatch({
10
+ scope: repositoryId,
11
+ eventName: "dispatch",
12
+ payload: {
13
+ type,
14
+ message,
15
+ source: repositoryConfig.id,
16
+ },
17
+ });
18
+ },
19
+ subscribe(handler) {
20
+ if (subscriptions.length > 0) {
21
+ console.warn("WARNING: SUBSCRIBED ALREADY");
22
+ return;
23
+ }
24
+ const unsubscribe = observer.subscribe({
25
+ scope: repositoryConfig.id,
26
+ eventName: "dispatch",
27
+ callback({ payload }) {
28
+ const { type, message, source } = payload;
29
+ handler({
30
+ type,
31
+ message: message !== null && message !== void 0 ? message : undefined,
32
+ source,
33
+ });
34
+ },
35
+ });
36
+ subscriptions.push(unsubscribe);
37
+ },
38
+ };
39
+ }
40
+ export { createMessenger };
@@ -1,6 +1,6 @@
1
1
  import type { scopedObserverType } from "../infrastructure";
2
- import type { IPlugin } from "../types";
3
- declare function createRepository<D>(dependencies: D, plugin: IPlugin<D, any>, observer: scopedObserverType): {
2
+ import type { IRepositoryConfig } from "../types";
3
+ declare function createRepository<D>(dependencies: D, repositoryConfig: IRepositoryConfig<D, any>, observer: scopedObserverType): {
4
4
  readonly repository: unknown;
5
5
  readonly connections: number;
6
6
  connect(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/core/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxC,iBAAS,gBAAgB,CAAC,CAAC,EACzB,YAAY,EAAE,CAAC,EACf,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,EACvB,QAAQ,EAAE,kBAAkB;;;;;EAgF7B;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/core/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlD,iBAAS,gBAAgB,CAAC,CAAC,EACzB,YAAY,EAAE,CAAC,EACf,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,EAC3C,QAAQ,EAAE,kBAAkB;;;;;EA+C7B;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,6 +1,7 @@
1
+ import { createMessenger } from "./messenger";
1
2
  import { applyMiddleware } from "./middleware";
2
- function createRepository(dependencies, plugin, observer) {
3
- const { install, middlewares, onConnect, onDisconnect } = plugin;
3
+ function createRepository(dependencies, repositoryConfig, observer) {
4
+ const { install, middlewares, onConnect, onDisconnect } = repositoryConfig;
4
5
  let repository = undefined;
5
6
  let connections = 0;
6
7
  let subscriptions = [];
@@ -16,44 +17,11 @@ function createRepository(dependencies, plugin, observer) {
16
17
  const rawRepository = install({
17
18
  instance: {
18
19
  dependencies,
19
- observer: (() => {
20
- return {
21
- dispatch: ({ repositoryId, type, message }) => {
22
- if (repository === plugin.id) {
23
- console.warn("WARNING: DISPATCHING TO SELF");
24
- return;
25
- }
26
- observer.dispatch({
27
- scope: repositoryId,
28
- eventName: "dispatch",
29
- payload: {
30
- type,
31
- message,
32
- source: plugin.id,
33
- },
34
- });
35
- },
36
- subscribe: (handler) => {
37
- if (subscriptions.length > 0) {
38
- console.warn("WARNING: SUBSCRIBED ALREADY");
39
- return;
40
- }
41
- const unsubscribe = observer.subscribe({
42
- scope: plugin.id,
43
- eventName: "dispatch",
44
- callback({ payload }) {
45
- const { type, message, source } = payload;
46
- handler({
47
- type,
48
- message: message !== null && message !== void 0 ? message : undefined,
49
- source,
50
- });
51
- },
52
- });
53
- subscriptions.push(unsubscribe);
54
- },
55
- };
56
- })(),
20
+ messenger: createMessenger({
21
+ observer,
22
+ subscriptions,
23
+ repositoryConfig,
24
+ }),
57
25
  },
58
26
  });
59
27
  repository = middlewares
@@ -1,5 +1,5 @@
1
1
  import type { IWorkspaceConfig } from "../types";
2
- declare const createLogger: (config: Omit<IWorkspaceConfig, "dependencies" | "plugins">) => {
2
+ declare const createLogger: (config: Omit<IWorkspaceConfig, "dependencies" | "repositories">) => {
3
3
  log: (callback: () => void, { type, scope, metadata, }: {
4
4
  type: string;
5
5
  scope: string;
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/infrastructure/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,QAAA,MAAM,YAAY,GAChB,QAAQ,IAAI,CAAC,gBAAgB,EAAE,cAAc,GAAG,SAAS,CAAC;oBAK5C,MAAM,IAAI,8BAKjB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,CAAA;KAAE;CAgC5D,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/infrastructure/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,QAAA,MAAM,YAAY,GAChB,QAAQ,IAAI,CAAC,gBAAgB,EAAE,cAAc,GAAG,cAAc,CAAC;oBAKjD,MAAM,IAAI,8BAKjB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,CAAA;KAAE;CAgC5D,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIhD,QAAA,MAAM,iBAAiB;oBAEH,CAAC,UAAU,gBAAgB,CAAC,CAAC,CAAC;;;;;;CAQjD,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhD,QAAA,MAAM,iBAAiB;oBAEH,CAAC,UAAU,gBAAgB,CAAC,CAAC,CAAC;;;;;;CAQjD,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/dist/manager.js CHANGED
@@ -1,10 +1,9 @@
1
- import { createWorkspaceContext } from "./workspace";
2
- import { createWorkspaceClient } from "./workspace/client";
1
+ import { workspaceProvider, mountWorkspace, createWorkspaceClient } from "./workspace";
3
2
  const repositoryManager = () => {
4
3
  return {
5
4
  createWorkspace(config) {
6
5
  let client = undefined;
7
- createWorkspaceContext(config, () => {
6
+ workspaceProvider(mountWorkspace(config), () => {
8
7
  client = createWorkspaceClient();
9
8
  });
10
9
  return client;
@@ -1,15 +1,15 @@
1
- export type IObserverDispatch<P = any> = {
1
+ export type IMessengerDispatch<P = any> = {
2
2
  type: string;
3
3
  repositoryId: string;
4
4
  message?: P;
5
5
  };
6
- export type IObserverSubscribePayload<P = any> = {
6
+ export type IMessengerSubscribePayload<P = any> = {
7
7
  type: string;
8
8
  source: string;
9
9
  message: P;
10
10
  };
11
- export type IObserver = {
12
- dispatch<P = any>(payload: IObserverDispatch<P>): void;
13
- subscribe<P = any>(callback: (payload: IObserverSubscribePayload<P>) => void): void;
11
+ export type IMessenger = {
12
+ dispatch<P = any>(payload: IMessengerDispatch<P>): void;
13
+ subscribe<P = any>(callback: (payload: IMessengerSubscribePayload<P>) => void): void;
14
14
  };
15
15
  //# sourceMappingURL=observer.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"observer.types.d.ts","sourceRoot":"","sources":["../../src/types/observer.types.ts"],"names":[],"mappings":"AAAA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I,CAAC;CACT,CAAC"}
@@ -1,21 +1,21 @@
1
- import type { IObserver } from "./observer.types";
2
- export interface IPlugin<D = any, R = any> {
1
+ import type { IMessenger } from "./observer.types";
2
+ export interface IRepositoryConfig<D = any, R = any> {
3
3
  id: string;
4
- install: pluginType<D, R>;
4
+ install: repositoryType<D, R>;
5
5
  middlewares?: Middleware[];
6
6
  onConnect?: () => void;
7
7
  onDisconnect?: () => void;
8
8
  }
9
- export type pluginType<D = any, R = any> = (obj: {
9
+ export type repositoryType<D = any, R = any> = (obj: {
10
10
  instance: {
11
11
  dependencies: D;
12
- observer: IObserver;
12
+ messenger: IMessenger;
13
13
  };
14
14
  }) => R;
15
- export interface IRepository<R = any> {
15
+ export interface IRepositoryInstance<R = any> {
16
16
  connect(): void;
17
17
  disconnect(): void;
18
- repository: ReturnType<pluginType<any, R>> | undefined;
18
+ repository: ReturnType<repositoryType<any, R>> | undefined;
19
19
  connections: number;
20
20
  }
21
21
  export type Middleware = (method: string, args: any[], next: (...nextArgs: any[]) => any) => any;
@@ -1 +1 @@
1
- {"version":3,"file":"repository.types.d.ts","sourceRoot":"","sources":["../../src/types/repository.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IAC/C,QAAQ,EAAE;QACR,YAAY,EAAE,CAAC,CAAC;QACh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AE,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,UAAU,GAAG,CACvB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAAE,EACX,IAAI,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE,KAAK,GAAG,KAC9B,GAAG,CAAC"}
@@ -1,8 +1,8 @@
1
- import type { IPlugin } from "./repository.types";
1
+ import type { IRepositoryConfig } from "./repository.types";
2
2
  export interface IWorkspaceConfig<D = any> {
3
3
  id: string;
4
4
  logging?: boolean;
5
5
  dependencies: D;
6
- plugins: () => IPlugin<D, any>[];
6
+ repositories: () => IRepositoryConfig<D, any>[];
7
7
  }
8
8
  //# sourceMappingURL=workspace.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.types.d.ts","sourceRoot":"","sources":["../../src/types/workspace.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,CAAC,CAAC;IAChB,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;CAClC"}
1
+ {"version":3,"file":"workspace.types.d.ts","sourceRoot":"","sources":["../../src/types/workspace.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,CAAC,CAAC;IAChB,YAAY,EAAE,MAAM,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;CACjD"}
@@ -1,7 +1,7 @@
1
- import type { pluginType } from "../types";
1
+ import type { repositoryType } from "../types";
2
2
  declare function createWorkspaceClient<I>(): {
3
3
  queryRepository: <R = any>(id: string) => {
4
- repository: ReturnType<pluginType<I, R>>;
4
+ repository: ReturnType<repositoryType<I, R>>;
5
5
  disconnect(): void;
6
6
  };
7
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/workspace/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,iBAAS,qBAAqB,CAAC,CAAC;sBAUL,CAAC,YAAY,MAAM;oBAgBd,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;;EAS3D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/workspace/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,iBAAS,qBAAqB,CAAC,CAAC;sBAGL,CAAC,YAAY,MAAM;oBAgBd,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;;;EAS/D;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}