@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.
- package/README.md +63 -63
- package/dist/core/messenger.d.ts +9 -0
- package/dist/core/messenger.d.ts.map +1 -0
- package/dist/core/messenger.js +40 -0
- package/dist/core/repository.d.ts +2 -2
- package/dist/core/repository.d.ts.map +1 -1
- package/dist/core/repository.js +8 -40
- package/dist/infrastructure/logger.d.ts +1 -1
- package/dist/infrastructure/logger.d.ts.map +1 -1
- package/dist/manager.d.ts.map +1 -1
- package/dist/manager.js +2 -3
- package/dist/types/observer.types.d.ts +5 -5
- package/dist/types/observer.types.d.ts.map +1 -1
- package/dist/types/repository.types.d.ts +7 -7
- package/dist/types/repository.types.d.ts.map +1 -1
- package/dist/types/workspace.types.d.ts +2 -2
- package/dist/types/workspace.types.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +2 -2
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/client.js +1 -7
- package/dist/workspace/context.d.ts +8 -5
- package/dist/workspace/context.d.ts.map +1 -1
- package/dist/workspace/context.js +4 -21
- package/dist/workspace/index.d.ts +2 -0
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/mount.d.ts +35 -1
- package/dist/workspace/mount.d.ts.map +1 -1
- package/dist/workspace/mount.js +26 -23
- package/package.json +1 -1
- package/src/core/messenger.ts +48 -0
- package/src/core/repository.ts +9 -41
- package/src/infrastructure/logger.ts +1 -1
- package/src/manager.ts +2 -3
- package/src/types/observer.types.ts +5 -5
- package/src/types/repository.types.ts +7 -7
- package/src/types/workspace.types.ts +2 -2
- package/src/workspace/client.ts +3 -10
- package/src/workspace/context.ts +12 -27
- package/src/workspace/index.ts +2 -0
- package/src/workspace/mount.ts +31 -28
- 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
|
|
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
|
-
- ✅ **
|
|
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
|
|
49
|
+
// Create workspace with repositories
|
|
50
50
|
const { queryRepository } = manager.createWorkspace({
|
|
51
51
|
id: "app",
|
|
52
52
|
logging: true,
|
|
53
53
|
dependencies,
|
|
54
|
-
|
|
54
|
+
repositories: () => [
|
|
55
55
|
{
|
|
56
56
|
id: "user-repo",
|
|
57
57
|
install({ instance }): IUserRepository {
|
|
58
|
-
const { dependencies,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
117
|
-
-
|
|
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
|
-
|
|
129
|
-
// Repository
|
|
128
|
+
repositories: () => [
|
|
129
|
+
// Repository definitions here
|
|
130
130
|
],
|
|
131
131
|
});
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
-
### 3.
|
|
134
|
+
### 3. Messenger System
|
|
135
135
|
|
|
136
|
-
The built-in
|
|
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
|
-
|
|
142
|
+
repositories: () => [
|
|
143
143
|
// Repository that dispatches events
|
|
144
144
|
{
|
|
145
145
|
id: "user-repo",
|
|
146
146
|
install({ instance }) {
|
|
147
|
-
const {
|
|
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
|
-
|
|
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 {
|
|
166
|
+
const { messenger } = instance;
|
|
167
167
|
|
|
168
168
|
// Subscribe to user events
|
|
169
|
-
|
|
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
|
-
- `
|
|
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
|
-
|
|
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
|
-
###
|
|
236
|
+
### Repository Definition
|
|
237
237
|
|
|
238
|
-
Defines a repository
|
|
238
|
+
Defines a repository within the workspace.
|
|
239
239
|
|
|
240
|
-
**
|
|
240
|
+
**Repository Structure:**
|
|
241
241
|
|
|
242
|
-
- `
|
|
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.
|
|
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
|
-
|
|
254
|
+
repositories: () => [
|
|
255
255
|
{
|
|
256
256
|
id: "user-repo",
|
|
257
257
|
install({ instance }): IUserRepository {
|
|
258
|
-
const { dependencies,
|
|
258
|
+
const { dependencies, messenger } = instance;
|
|
259
259
|
|
|
260
260
|
// Subscribe to events
|
|
261
|
-
|
|
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
|
-
|
|
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
|
-
### `
|
|
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:
|
|
314
|
+
- `payload: IMessengerDispatch<P>`
|
|
315
315
|
- `type: string` - Event type identifier
|
|
316
|
-
- `repositoryId: string` -
|
|
316
|
+
- `repositoryId: string` - Target repository identifier
|
|
317
317
|
- `message?: P` - Optional payload data
|
|
318
318
|
|
|
319
319
|
**Example:**
|
|
320
320
|
|
|
321
321
|
```typescript
|
|
322
|
-
|
|
322
|
+
messenger.dispatch({
|
|
323
323
|
type: "user.created",
|
|
324
|
-
repositoryId: "
|
|
324
|
+
repositoryId: "notification-repo",
|
|
325
325
|
message: { userId: "123", email: "user@example.com" },
|
|
326
326
|
});
|
|
327
327
|
```
|
|
328
328
|
|
|
329
|
-
### `
|
|
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:
|
|
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
|
-
|
|
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
|
-
###
|
|
353
|
+
### Messenger System Benefits
|
|
354
354
|
|
|
355
|
-
The built-in
|
|
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
|
|
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
|
-
|
|
384
|
+
repositories: () => [
|
|
385
385
|
// User repository dispatches events
|
|
386
386
|
{
|
|
387
387
|
id: "user-repo",
|
|
388
388
|
install({ instance }) {
|
|
389
|
-
const { dependencies,
|
|
389
|
+
const { dependencies, messenger } = instance;
|
|
390
390
|
return {
|
|
391
391
|
async createUser(user) {
|
|
392
392
|
const result = await dependencies.httpClient.post("/users", user);
|
|
393
|
-
|
|
393
|
+
messenger.dispatch({
|
|
394
394
|
type: "user.created",
|
|
395
|
-
repositoryId: "
|
|
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
|
-
|
|
402
|
+
messenger.dispatch({
|
|
403
403
|
type: "user.deleted",
|
|
404
|
-
repositoryId: "
|
|
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 {
|
|
415
|
+
const { messenger, dependencies } = instance;
|
|
416
416
|
|
|
417
|
-
|
|
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 {
|
|
438
|
+
const { messenger } = instance;
|
|
439
439
|
|
|
440
|
-
|
|
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
|
-
|
|
468
|
-
// API
|
|
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
|
-
|
|
481
|
-
// Database
|
|
480
|
+
repositories: () => [
|
|
481
|
+
// Database repositories
|
|
482
482
|
],
|
|
483
483
|
logging: false,
|
|
484
484
|
});
|
|
485
485
|
|
|
486
|
-
// Each workspace has isolated repositories and
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
612
|
-
//
|
|
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
|
-
- **
|
|
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 {
|
|
3
|
-
declare function createRepository<D>(dependencies: D,
|
|
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,
|
|
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"}
|
package/dist/core/repository.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { createMessenger } from "./messenger";
|
|
1
2
|
import { applyMiddleware } from "./middleware";
|
|
2
|
-
function createRepository(dependencies,
|
|
3
|
-
const { install, middlewares, onConnect, onDisconnect } =
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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" | "
|
|
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,
|
|
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"}
|
package/dist/manager.d.ts.map
CHANGED
|
@@ -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;
|
|
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 {
|
|
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
|
-
|
|
6
|
+
workspaceProvider(mountWorkspace(config), () => {
|
|
8
7
|
client = createWorkspaceClient();
|
|
9
8
|
});
|
|
10
9
|
return client;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type IMessengerDispatch<P = any> = {
|
|
2
2
|
type: string;
|
|
3
3
|
repositoryId: string;
|
|
4
4
|
message?: P;
|
|
5
5
|
};
|
|
6
|
-
export type
|
|
6
|
+
export type IMessengerSubscribePayload<P = any> = {
|
|
7
7
|
type: string;
|
|
8
8
|
source: string;
|
|
9
9
|
message: P;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
12
|
-
dispatch<P = any>(payload:
|
|
13
|
-
subscribe<P = any>(callback: (payload:
|
|
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,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"observer.types.d.ts","sourceRoot":"","sources":["../../src/types/observer.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAAI;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACxD,SAAS,CAAC,CAAC,GAAG,GAAG,EACf,QAAQ,EAAE,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,KAAK,IAAI,GACzD,IAAI,CAAC;CACT,CAAC"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface
|
|
1
|
+
import type { IMessenger } from "./observer.types";
|
|
2
|
+
export interface IRepositoryConfig<D = any, R = any> {
|
|
3
3
|
id: string;
|
|
4
|
-
install:
|
|
4
|
+
install: repositoryType<D, R>;
|
|
5
5
|
middlewares?: Middleware[];
|
|
6
6
|
onConnect?: () => void;
|
|
7
7
|
onDisconnect?: () => void;
|
|
8
8
|
}
|
|
9
|
-
export type
|
|
9
|
+
export type repositoryType<D = any, R = any> = (obj: {
|
|
10
10
|
instance: {
|
|
11
11
|
dependencies: D;
|
|
12
|
-
|
|
12
|
+
messenger: IMessenger;
|
|
13
13
|
};
|
|
14
14
|
}) => R;
|
|
15
|
-
export interface
|
|
15
|
+
export interface IRepositoryInstance<R = any> {
|
|
16
16
|
connect(): void;
|
|
17
17
|
disconnect(): void;
|
|
18
|
-
repository: ReturnType<
|
|
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,
|
|
1
|
+
{"version":3,"file":"repository.types.d.ts","sourceRoot":"","sources":["../../src/types/repository.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACnD,QAAQ,EAAE;QACR,YAAY,EAAE,CAAC,CAAC;QAChB,SAAS,EAAE,UAAU,CAAC;KACvB,CAAC;CACH,KAAK,CAAC,CAAC;AAER,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,GAAG;IAC1C,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,IAAI,CAAC;IACnB,UAAU,EAAE,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 {
|
|
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
|
-
|
|
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,
|
|
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 {
|
|
1
|
+
import type { repositoryType } from "../types";
|
|
2
2
|
declare function createWorkspaceClient<I>(): {
|
|
3
3
|
queryRepository: <R = any>(id: string) => {
|
|
4
|
-
repository: ReturnType<
|
|
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,
|
|
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"}
|