@med1802/repository-manager 2.0.0 → 2.2.0

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 CHANGED
@@ -12,6 +12,7 @@ A lightweight, type-safe repository manager with dependency injection, lifecycle
12
12
  - ✅ **Imperative API** - Define workspaces and repositories as needed
13
13
  - ✅ **Logging** - Built-in logging with colored console output
14
14
  - ✅ **Memory Efficient** - Automatic cleanup when no connections remain
15
+ - ✅ **Middleware Support** - Intercept and modify repository method calls
15
16
 
16
17
  ## Installation
17
18
 
@@ -110,7 +111,7 @@ const { defineRepository } = manager.workspace(infrastructure, {
110
111
  });
111
112
  ```
112
113
 
113
- ### `defineRepository(id, factory)`
114
+ ### `defineRepository(id, factory, config?)`
114
115
 
115
116
  Defines a repository within the workspace.
116
117
 
@@ -118,6 +119,11 @@ Defines a repository within the workspace.
118
119
 
119
120
  - `id: string` - Unique identifier for the repository
120
121
  - `factory: (infrastructure: I) => R` - Factory function that receives infrastructure and returns repository instance
122
+ - `config?: IRepositoryConfig` - Optional repository configuration
123
+ - `lifecycle?: ILifeCycle` - Lifecycle hooks
124
+ - `onConnect?: () => void` - Called when repository is first connected (when connections go from 0 to 1)
125
+ - `onDisconnect?: () => void` - Called when repository is last disconnected (when connections go from 1 to 0)
126
+ - `middlewares?: Middleware[]` - Array of middleware functions to intercept method calls
121
127
 
122
128
  **Example:**
123
129
 
@@ -125,6 +131,24 @@ Defines a repository within the workspace.
125
131
  defineRepository("userRepo", (infrastructure) => ({
126
132
  getUsers: () => infrastructure.httpClient.get("/users"),
127
133
  }));
134
+
135
+ // With lifecycle hooks
136
+ defineRepository(
137
+ "userRepo",
138
+ (infrastructure) => ({
139
+ getUsers: () => infrastructure.httpClient.get("/users"),
140
+ }),
141
+ {
142
+ lifecycle: {
143
+ onConnect: () => {
144
+ console.log("User repository initialized");
145
+ },
146
+ onDisconnect: () => {
147
+ console.log("User repository cleaned up");
148
+ },
149
+ },
150
+ }
151
+ );
128
152
  ```
129
153
 
130
154
  ### `manager.query<R>(path)`
@@ -266,6 +290,182 @@ conn3.disconnect(); // Connections: 0 (instance destroyed)
266
290
  const conn4 = manager.query("app/userRepo"); // Connections: 1 (new instance)
267
291
  ```
268
292
 
293
+ ### Lifecycle Hooks
294
+
295
+ You can define lifecycle hooks that are called at specific points in the repository lifecycle:
296
+
297
+ - **`onConnect`** - Called only when the repository is first connected (when connections go from 0 to 1)
298
+ - **`onDisconnect`** - Called only when the repository is last disconnected (when connections go from 1 to 0)
299
+
300
+ **Example:**
301
+
302
+ ```typescript
303
+ defineRepository(
304
+ "userRepo",
305
+ (infrastructure) => ({
306
+ getUsers: () => infrastructure.httpClient.get("/api/users"),
307
+ }),
308
+ {
309
+ lifecycle: {
310
+ onConnect: () => {
311
+ console.log("User repository initialized");
312
+ // Perform initialization tasks (e.g., setup cache, establish connection)
313
+ },
314
+ onDisconnect: () => {
315
+ console.log("User repository cleaned up");
316
+ // Perform cleanup tasks (e.g., clear cache, close connections)
317
+ },
318
+ },
319
+ }
320
+ );
321
+
322
+ // Usage
323
+ const conn1 = manager.query("app/userRepo"); // onConnect called (first connection)
324
+ const conn2 = manager.query("app/userRepo"); // onConnect NOT called (reusing instance)
325
+
326
+ conn1.disconnect(); // onDisconnect NOT called (still has connections)
327
+ conn2.disconnect(); // onDisconnect called (last connection removed)
328
+ ```
329
+
330
+ **Use Cases:**
331
+
332
+ - **Initialization**: Setup cache, establish database connections, initialize state
333
+ - **Cleanup**: Clear cache, close connections, release resources
334
+ - **Analytics**: Track repository usage and lifecycle events
335
+ - **Debugging**: Monitor when repositories are created and destroyed
336
+
337
+ ### Middleware
338
+
339
+ Middleware allows you to intercept and modify repository method calls before and after execution. Middleware functions are executed in sequence, allowing you to add cross-cutting concerns like logging, caching, validation, and more.
340
+
341
+ **Middleware Signature:**
342
+
343
+ ```typescript
344
+ type Middleware = (
345
+ method: string,
346
+ args: any[],
347
+ next: (...nextArgs: any[]) => any
348
+ ) => any;
349
+ ```
350
+
351
+ **Parameters:**
352
+
353
+ - `method: string` - The name of the method being called
354
+ - `args: any[]` - The arguments passed to the method
355
+ - `next: (...nextArgs: any[]) => any` - Function to call the next middleware or the original method
356
+
357
+ **Example:**
358
+
359
+ ```typescript
360
+ // Define middleware functions
361
+ const loggingMiddleware: Middleware = (method, args, next) => {
362
+ console.log(`[${new Date().toISOString()}] Calling ${method}`, args);
363
+ const result = next();
364
+ console.log(`[${new Date().toISOString()}] ${method} returned:`, result);
365
+ return result;
366
+ };
367
+
368
+ const performanceMiddleware: Middleware = (method, args, next) => {
369
+ const start = performance.now();
370
+ const result = next();
371
+ const duration = performance.now() - start;
372
+
373
+ if (duration > 1000) {
374
+ console.warn(`Slow call: ${method} took ${duration}ms`);
375
+ }
376
+
377
+ return result;
378
+ };
379
+
380
+ // Apply middleware to repository
381
+ defineRepository(
382
+ "userRepo",
383
+ (infrastructure) => ({
384
+ getUsers: () => infrastructure.httpClient.get("/api/users"),
385
+ createUser: (user) => infrastructure.httpClient.post("/api/users", user),
386
+ }),
387
+ {
388
+ middlewares: [loggingMiddleware, performanceMiddleware],
389
+ }
390
+ );
391
+
392
+ // When you call repository methods, middleware intercepts them
393
+ const { repository } = manager.query("app/userRepo");
394
+ await repository.getUsers(); // Middleware logs and measures performance
395
+ ```
396
+
397
+ **Middleware Execution Flow:**
398
+
399
+ ```typescript
400
+ // When you call: repository.getUsers("filter")
401
+ // 1. loggingMiddleware - logs "Calling getUsers"
402
+ // 2. performanceMiddleware - starts timer
403
+ // 3. repository.getUsers("filter") - original method executes
404
+ // 4. performanceMiddleware - ends timer, logs if slow
405
+ // 5. loggingMiddleware - logs result
406
+ // 6. Returns result to caller
407
+ ```
408
+
409
+ **Common Use Cases:**
410
+
411
+ - **Logging**: Log all method calls and their results
412
+ - **Performance Monitoring**: Measure execution time and warn about slow calls
413
+ - **Caching**: Cache method results to avoid redundant calls
414
+ - **Validation**: Validate arguments before method execution
415
+ - **Error Handling**: Centralized error handling and retry logic
416
+ - **Data Transformation**: Transform arguments or results
417
+ - **Authentication**: Check permissions before method execution
418
+ - **Rate Limiting**: Limit the number of calls per method
419
+
420
+ **Example: Caching Middleware**
421
+
422
+ ```typescript
423
+ const cache = new Map<string, any>();
424
+
425
+ const cacheMiddleware: Middleware = (method, args, next) => {
426
+ const cacheKey = `${method}-${JSON.stringify(args)}`;
427
+
428
+ if (cache.has(cacheKey)) {
429
+ return cache.get(cacheKey); // Return cached result, skip method execution
430
+ }
431
+
432
+ const result = next(); // Execute method
433
+ cache.set(cacheKey, result); // Cache result
434
+ return result;
435
+ };
436
+
437
+ defineRepository(
438
+ "userRepo",
439
+ (infrastructure) => ({
440
+ getUsers: () => infrastructure.httpClient.get("/api/users"),
441
+ }),
442
+ {
443
+ middlewares: [cacheMiddleware],
444
+ }
445
+ );
446
+ ```
447
+
448
+ **Example: Validation Middleware**
449
+
450
+ ```typescript
451
+ const validationMiddleware: Middleware = (method, args, next) => {
452
+ if (method === "createUser" && (!args[0] || typeof args[0] !== "object")) {
453
+ throw new Error("Invalid user data");
454
+ }
455
+ return next();
456
+ };
457
+
458
+ defineRepository(
459
+ "userRepo",
460
+ (infrastructure) => ({
461
+ createUser: (user) => infrastructure.httpClient.post("/api/users", user),
462
+ }),
463
+ {
464
+ middlewares: [validationMiddleware],
465
+ }
466
+ );
467
+ ```
468
+
269
469
  ### Using with React
270
470
 
271
471
  ```typescript
@@ -0,0 +1,3 @@
1
+ import type { Middleware } from "./types";
2
+ export declare function applyMiddleware(repository: any, middlewares: Middleware[]): any;
3
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,wBAAgB,eAAe,CAC7B,UAAU,EAAE,GAAG,EACf,WAAW,EAAE,UAAU,EAAE,OAmC1B"}
@@ -0,0 +1,24 @@
1
+ export function applyMiddleware(repository, middlewares) {
2
+ if (!middlewares || middlewares.length === 0) {
3
+ return repository;
4
+ }
5
+ return new Proxy(repository, {
6
+ get(target, prop) {
7
+ if (typeof target[prop] === "function") {
8
+ const originalMethod = target[prop];
9
+ return (...args) => {
10
+ let index = 0;
11
+ const next = (...nextArgs) => {
12
+ if (index >= middlewares.length) {
13
+ return originalMethod.apply(target, nextArgs.length > 0 ? nextArgs : args);
14
+ }
15
+ const middleware = middlewares[index++];
16
+ return middleware(prop, nextArgs.length > 0 ? nextArgs : args, next);
17
+ };
18
+ return next();
19
+ };
20
+ }
21
+ return target[prop];
22
+ },
23
+ });
24
+ }
@@ -1,4 +1,5 @@
1
- declare function createRepositoryAccessor<I extends Record<string, any>>(definition: (infrastructure: I) => unknown, infrastructure: I): {
1
+ import type { IRepositoryConfig } from "./types";
2
+ declare function createRepositoryAccessor<I extends Record<string, any>>(definition: (infrastructure: I) => unknown, infrastructure: I, config?: IRepositoryConfig): {
2
3
  readonly repository: unknown;
3
4
  readonly connections: number;
4
5
  connect(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"repositoryAccessor.d.ts","sourceRoot":"","sources":["../src/repositoryAccessor.ts"],"names":[],"mappings":"AAAA,iBAAS,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7D,UAAU,EAAE,CAAC,cAAc,EAAE,CAAC,KAAK,OAAO,EAC1C,cAAc,EAAE,CAAC;;;;;EAyBlB;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"repositoryAccessor.d.ts","sourceRoot":"","sources":["../src/repositoryAccessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGjD,iBAAS,wBAAwB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7D,UAAU,EAAE,CAAC,cAAc,EAAE,CAAC,KAAK,OAAO,EAC1C,cAAc,EAAE,CAAC,EACjB,MAAM,CAAC,EAAE,iBAAiB;;;;;EAqC3B;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,7 +1,8 @@
1
- function createRepositoryAccessor(definition, infrastructure) {
1
+ import { applyMiddleware } from "./middleware";
2
+ function createRepositoryAccessor(definition, infrastructure, config) {
2
3
  let repository = undefined;
3
4
  let connections = 0;
4
- return {
5
+ const obj = {
5
6
  get repository() {
6
7
  return repository;
7
8
  },
@@ -9,19 +10,31 @@ function createRepositoryAccessor(definition, infrastructure) {
9
10
  return connections;
10
11
  },
11
12
  connect() {
13
+ var _a;
12
14
  if (connections === 0) {
13
- repository = definition(infrastructure);
15
+ const rawRepository = definition(infrastructure);
16
+ repository = (config === null || config === void 0 ? void 0 : config.middlewares)
17
+ ? applyMiddleware(rawRepository, config.middlewares)
18
+ : rawRepository;
19
+ if ((_a = config === null || config === void 0 ? void 0 : config.lifecycle) === null || _a === void 0 ? void 0 : _a.onConnect) {
20
+ config.lifecycle.onConnect();
21
+ }
14
22
  }
15
23
  connections += 1;
16
24
  },
17
25
  disconnect() {
26
+ var _a;
18
27
  if (connections === 0)
19
28
  return;
20
29
  connections -= 1;
21
30
  if (connections === 0) {
22
31
  repository = undefined;
32
+ if ((_a = config === null || config === void 0 ? void 0 : config.lifecycle) === null || _a === void 0 ? void 0 : _a.onDisconnect) {
33
+ config.lifecycle.onDisconnect();
34
+ }
23
35
  }
24
36
  },
25
37
  };
38
+ return obj;
26
39
  }
27
40
  export { createRepositoryAccessor };
package/dist/types.d.ts CHANGED
@@ -16,4 +16,13 @@ export interface IRepositoryInstance<R = any> {
16
16
  repository: ReturnType<repositoryType<any, R>> | undefined;
17
17
  connections: number;
18
18
  }
19
+ export interface ILifeCycle {
20
+ onConnect?: () => void;
21
+ onDisconnect?: () => void;
22
+ }
23
+ export type Middleware = (method: string, args: any[], next: (...nextArgs: any[]) => any) => any;
24
+ export interface IRepositoryConfig {
25
+ lifecycle?: ILifeCycle;
26
+ middlewares?: Middleware[];
27
+ }
19
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;AAExE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IAC1C,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IACrE,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG;QAC3B,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,UAAU,IAAI,IAAI,CAAC;KACpB,CAAC;CACH;AAED,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"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC;AAExE,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IAC1C,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IACrE,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG;QAC3B,UAAU,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7C,UAAU,IAAI,IAAI,CAAC;KACpB,CAAC;CACH;AAED,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,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;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;AAET,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B"}
@@ -1,6 +1,6 @@
1
- import type { IConfiguration, repositoryType } from "./types";
1
+ import type { IConfiguration, IRepositoryConfig, repositoryType } from "./types";
2
2
  declare function createWorkspace<I extends Record<string, any>>(infrastructure: I, config: IConfiguration): {
3
- defineRepository: (id: string, repository: repositoryType<I, any>) => void;
3
+ defineRepository: (id: string, repository: repositoryType<I, any>, config?: IRepositoryConfig) => void;
4
4
  queryRepository: (id: string) => {
5
5
  repository: any;
6
6
  disconnect(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EAEd,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,iBAAS,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpD,cAAc,EAAE,CAAC,EACjB,MAAM,EAAE,cAAc;2BAeQ,MAAM,cAAc,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC;0BAuB3C,MAAM;;;;EA2BpC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../src/workspace.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EAEd,iBAAiB,EAEjB,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB,iBAAS,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpD,cAAc,EAAE,CAAC,EACjB,MAAM,EAAE,cAAc;2BAgBhB,MAAM,cACE,cAAc,CAAC,CAAC,EAAE,GAAG,CAAC,WACzB,iBAAiB;0BAwBC,MAAM;;;;EA2BpC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
package/dist/workspace.js CHANGED
@@ -14,11 +14,11 @@ function createWorkspace(infrastructure, config) {
14
14
  repository: id,
15
15
  connections: repository.connections,
16
16
  }));
17
- const defineRepository = (id, repository) => {
17
+ const defineRepository = (id, repository, config) => {
18
18
  if (hasRepository(id))
19
19
  return;
20
20
  logger.log(() => {
21
- store.setState(id, createRepositoryAccessor(repository, infrastructure));
21
+ store.setState(id, createRepositoryAccessor(repository, infrastructure, config));
22
22
  }, {
23
23
  type: "repository.define",
24
24
  scope: id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@med1802/repository-manager",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -0,0 +1,41 @@
1
+ import type { Middleware } from "./types";
2
+
3
+ export function applyMiddleware(
4
+ repository: any,
5
+ middlewares: Middleware[]
6
+ ) {
7
+ if (!middlewares || middlewares.length === 0) {
8
+ return repository;
9
+ }
10
+
11
+ return new Proxy(repository, {
12
+ get(target, prop) {
13
+ if (typeof target[prop as keyof typeof target] === "function") {
14
+ const originalMethod = target[prop as keyof typeof target] as (
15
+ ...args: any[]
16
+ ) => any;
17
+
18
+ return (...args: any[]) => {
19
+ let index = 0;
20
+ const next = (...nextArgs: any[]) => {
21
+ if (index >= middlewares.length) {
22
+ return originalMethod.apply(
23
+ target,
24
+ nextArgs.length > 0 ? nextArgs : args
25
+ );
26
+ }
27
+ const middleware = middlewares[index++];
28
+ return middleware(
29
+ prop as string,
30
+ nextArgs.length > 0 ? nextArgs : args,
31
+ next
32
+ );
33
+ };
34
+ return next();
35
+ };
36
+ }
37
+ return target[prop as keyof typeof target];
38
+ },
39
+ });
40
+ }
41
+
@@ -1,10 +1,15 @@
1
+ import type { IRepositoryConfig } from "./types";
2
+ import { applyMiddleware } from "./middleware";
3
+
1
4
  function createRepositoryAccessor<I extends Record<string, any>>(
2
5
  definition: (infrastructure: I) => unknown,
3
- infrastructure: I
6
+ infrastructure: I,
7
+ config?: IRepositoryConfig
4
8
  ) {
5
9
  let repository = undefined as unknown;
6
10
  let connections = 0;
7
- return {
11
+
12
+ const obj = {
8
13
  get repository() {
9
14
  return repository;
10
15
  },
@@ -13,7 +18,13 @@ function createRepositoryAccessor<I extends Record<string, any>>(
13
18
  },
14
19
  connect() {
15
20
  if (connections === 0) {
16
- repository = definition(infrastructure);
21
+ const rawRepository = definition(infrastructure);
22
+ repository = config?.middlewares
23
+ ? applyMiddleware(rawRepository, config.middlewares)
24
+ : rawRepository;
25
+ if (config?.lifecycle?.onConnect) {
26
+ config.lifecycle.onConnect();
27
+ }
17
28
  }
18
29
  connections += 1;
19
30
  },
@@ -22,9 +33,14 @@ function createRepositoryAccessor<I extends Record<string, any>>(
22
33
  connections -= 1;
23
34
  if (connections === 0) {
24
35
  repository = undefined;
36
+ if (config?.lifecycle?.onDisconnect) {
37
+ config.lifecycle.onDisconnect();
38
+ }
25
39
  }
26
40
  },
27
41
  };
42
+
43
+ return obj;
28
44
  }
29
45
 
30
46
  export { createRepositoryAccessor };
package/src/types.ts CHANGED
@@ -19,3 +19,19 @@ export interface IRepositoryInstance<R = any> {
19
19
  repository: ReturnType<repositoryType<any, R>> | undefined;
20
20
  connections: number;
21
21
  }
22
+
23
+ export interface ILifeCycle {
24
+ onConnect?: () => void;
25
+ onDisconnect?: () => void;
26
+ }
27
+
28
+ export type Middleware = (
29
+ method: string,
30
+ args: any[],
31
+ next: (...nextArgs: any[]) => any
32
+ ) => any;
33
+
34
+ export interface IRepositoryConfig {
35
+ lifecycle?: ILifeCycle;
36
+ middlewares?: Middleware[];
37
+ }
package/src/workspace.ts CHANGED
@@ -3,6 +3,8 @@ import { createRepositoryAccessor } from "./repositoryAccessor";
3
3
  import { createStore } from "./store";
4
4
  import type {
5
5
  IConfiguration,
6
+ ILifeCycle,
7
+ IRepositoryConfig,
6
8
  IRepositoryInstance,
7
9
  repositoryType,
8
10
  } from "./types";
@@ -24,13 +26,17 @@ function createWorkspace<I extends Record<string, any>>(
24
26
  connections: repository.connections,
25
27
  }));
26
28
 
27
- const defineRepository = (id: string, repository: repositoryType<I, any>) => {
29
+ const defineRepository = (
30
+ id: string,
31
+ repository: repositoryType<I, any>,
32
+ config?: IRepositoryConfig
33
+ ) => {
28
34
  if (hasRepository(id)) return;
29
35
  logger.log(
30
36
  () => {
31
37
  store.setState(
32
38
  id,
33
- createRepositoryAccessor(repository, infrastructure)
39
+ createRepositoryAccessor(repository, infrastructure, config)
34
40
  );
35
41
  },
36
42
  {
@@ -1 +1 @@
1
- {"fileNames":["../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.scripthost.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.full.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/global.d.ts","../../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../../node_modules/.pnpm/@types+prop-types@15.7.15/node_modules/@types/prop-types/index.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/index.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/jsx-runtime.d.ts","./src/store.ts","./src/types.ts","./src/logger.ts","./src/repositoryaccessor.ts","./src/workspace.ts","./src/index.ts","../../node_modules/.pnpm/@types+react-dom@18.3.7_@types+react@18.3.23/node_modules/@types/react-dom/index.d.ts"],"fileIdsList":[[47,48,49,52],[47,49],[47],[47,48,49,50,51],[46],[43,44,45]],"fileInfos":[{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedFormat":1},{"version":"07f073f19d67f74d732b1adea08e1dc66b1b58d77cb5b43931dee3d798a2fd53","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7a3c8b952931daebdfc7a2897c53c0a1c73624593fa070e46bd537e64dcd20a","affectsGlobalScope":true,"impliedFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"fef8cfad2e2dc5f5b3d97a6f4f2e92848eb1b88e897bb7318cef0e2820bceaab","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"08f6861df84fba9719c14d5adc3ba40be9f0c687639e6c4df3c05b9301b8ff94","impliedFormat":1},{"version":"eb5b19b86227ace1d29ea4cf81387279d04bb34051e944bc53df69f58914b788","affectsGlobalScope":true,"impliedFormat":1},{"version":"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","impliedFormat":1},{"version":"87d9d29dbc745f182683f63187bf3d53fd8673e5fca38ad5eaab69798ed29fbc","impliedFormat":1},{"version":"472f5aab7edc498a0a761096e8e254c5bc3323d07a1e7f5f8b8ec0d6395b60a0","affectsGlobalScope":true,"impliedFormat":1},{"version":"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","impliedFormat":1},{"version":"29f45bbe2abf2b552bc0816403ae39e7650bb21f28f43c3f5d6478fafa919469","signature":"b276ce62679f7f22b60b5138be9978d1bac7a631573eb734fa9dd8bc1519fad5"},{"version":"fb7a01b7c700e3e7acf97129366f7c5c7af0c38f5878f555788b2e29dcbecc0c","signature":"1be6a60484d09dd55b282a2742cbd7e7184d3a6cfc9b0bb1aa86cab8d3167853"},{"version":"492c075c93e7422319653338cad79622e19a08cc9269f62600805c1fb52b1a36","signature":"935c0760e874c9d96997126152eb9b3b8d7104025b942bf0a92202583276ddbd"},{"version":"bfc13d274c957851e358328fe3b6426dca102255a728b82f75ac080ee1639fc4","signature":"de9f36d1627208b72b4f18de5bb32ba5632cc4047c7300795e54ebaed9b3e379"},{"version":"f68271bf7ba0cb8862a38a1bc95abc22fc50666b4ccd9fce2cab6ebb45999f81","signature":"3ac28bf1517465765a387c8bf6fccbe15bbe804493e3e90aee9647dfecf5d8f2"},{"version":"60b550dcc5ed595cb1c6f8eb2e23f89c310d26fe35c6232c6378d9cb98a4e81d","signature":"044f56994ad4db06a91a53092997198f161ecdec1b3255bc831776b7493d1e7d"},{"version":"17ed71200119e86ccef2d96b73b02ce8854b76ad6bd21b5021d4269bec527b5f","impliedFormat":1}],"root":[[48,53]],"options":{"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"jsx":4,"module":99,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"strict":true,"target":6},"referencedMap":[[53,1],[50,2],[51,3],[48,3],[49,3],[52,4],[54,5],[46,6],[47,5]],"latestChangedDtsFile":"./dist/index.d.ts","version":"5.8.3"}
1
+ {"fileNames":["../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.dom.asynciterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.scripthost.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../../node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/lib/lib.es2019.full.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/global.d.ts","../../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../../node_modules/.pnpm/@types+prop-types@15.7.15/node_modules/@types/prop-types/index.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/index.d.ts","../../node_modules/.pnpm/@types+react@18.3.23/node_modules/@types/react/jsx-runtime.d.ts","./src/types.ts","./src/logger.ts","./src/middleware.ts","./src/repositoryaccessor.ts","./src/store.ts","./src/workspace.ts","../../node_modules/.pnpm/@types+react-dom@18.3.7_@types+react@18.3.23/node_modules/@types/react-dom/index.d.ts"],"fileIdsList":[[47,48],[47,48,50],[47],[47,48,49,51,52],[46],[43,44,45]],"fileInfos":[{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedFormat":1},{"version":"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","impliedFormat":1},{"version":"3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","impliedFormat":1},{"version":"e44bb8bbac7f10ecc786703fe0a6a4b952189f908707980ba8f3c8975a760962","impliedFormat":1},{"version":"5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","impliedFormat":1},{"version":"68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","impliedFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedFormat":1},{"version":"07f073f19d67f74d732b1adea08e1dc66b1b58d77cb5b43931dee3d798a2fd53","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7a3c8b952931daebdfc7a2897c53c0a1c73624593fa070e46bd537e64dcd20a","affectsGlobalScope":true,"impliedFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedFormat":1},{"version":"c57796738e7f83dbc4b8e65132f11a377649c00dd3eee333f672b8f0a6bea671","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true,"impliedFormat":1},{"version":"515d0b7b9bea2e31ea4ec968e9edd2c39d3eebf4a2d5cbd04e88639819ae3b71","affectsGlobalScope":true,"impliedFormat":1},{"version":"0559b1f683ac7505ae451f9a96ce4c3c92bdc71411651ca6ddb0e88baaaad6a3","affectsGlobalScope":true,"impliedFormat":1},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true,"impliedFormat":1},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true,"impliedFormat":1},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true,"impliedFormat":1},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true,"impliedFormat":1},{"version":"936e80ad36a2ee83fc3caf008e7c4c5afe45b3cf3d5c24408f039c1d47bdc1df","affectsGlobalScope":true,"impliedFormat":1},{"version":"d15bea3d62cbbdb9797079416b8ac375ae99162a7fba5de2c6c505446486ac0a","affectsGlobalScope":true,"impliedFormat":1},{"version":"68d18b664c9d32a7336a70235958b8997ebc1c3b8505f4f1ae2b7e7753b87618","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb3d66c8327153d8fa7dd03f9c58d351107fe824c79e9b56b462935176cdf12a","affectsGlobalScope":true,"impliedFormat":1},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true,"impliedFormat":1},{"version":"69ab18c3b76cd9b1be3d188eaf8bba06112ebbe2f47f6c322b5105a6fbc45a2e","affectsGlobalScope":true,"impliedFormat":1},{"version":"fef8cfad2e2dc5f5b3d97a6f4f2e92848eb1b88e897bb7318cef0e2820bceaab","affectsGlobalScope":true,"impliedFormat":1},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true,"impliedFormat":1},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true,"impliedFormat":1},{"version":"954296b30da6d508a104a3a0b5d96b76495c709785c1d11610908e63481ee667","affectsGlobalScope":true,"impliedFormat":1},{"version":"ac9538681b19688c8eae65811b329d3744af679e0bdfa5d842d0e32524c73e1c","affectsGlobalScope":true,"impliedFormat":1},{"version":"0a969edff4bd52585473d24995c5ef223f6652d6ef46193309b3921d65dd4376","affectsGlobalScope":true,"impliedFormat":1},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true,"impliedFormat":1},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true,"impliedFormat":1},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true,"impliedFormat":1},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true,"impliedFormat":1},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true,"impliedFormat":1},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true,"impliedFormat":1},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true,"impliedFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedFormat":1},{"version":"08f6861df84fba9719c14d5adc3ba40be9f0c687639e6c4df3c05b9301b8ff94","impliedFormat":1},{"version":"eb5b19b86227ace1d29ea4cf81387279d04bb34051e944bc53df69f58914b788","affectsGlobalScope":true,"impliedFormat":1},{"version":"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","impliedFormat":1},{"version":"87d9d29dbc745f182683f63187bf3d53fd8673e5fca38ad5eaab69798ed29fbc","impliedFormat":1},{"version":"472f5aab7edc498a0a761096e8e254c5bc3323d07a1e7f5f8b8ec0d6395b60a0","affectsGlobalScope":true,"impliedFormat":1},{"version":"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","impliedFormat":1},{"version":"86901944a9b0d237f115a4ae069a3ef055260d69b17ecf8a2dcaf01001f86455","signature":"fb11810698ea0c7c66dbb29163444931f974c6186efafb23af972ee107e537c0"},{"version":"492c075c93e7422319653338cad79622e19a08cc9269f62600805c1fb52b1a36","signature":"935c0760e874c9d96997126152eb9b3b8d7104025b942bf0a92202583276ddbd"},{"version":"19cb5c884ecfda109b6f6cb2bf56e45dd6e35182d8f2132c4dfa512d37ae61b3","signature":"012d5c7d926b3fbf88a4ca2e4deab2467b2bb6516716831b86a80e41388649a0"},{"version":"8873c824a140b5367ea45a9fd86fe1d646d4eda1a895927d1c8be7b99255d448","signature":"d1852188e1eadd0541bc395045b0d4a0a63f781d9af56bae6b77a935f585b329"},{"version":"29f45bbe2abf2b552bc0816403ae39e7650bb21f28f43c3f5d6478fafa919469","signature":"b276ce62679f7f22b60b5138be9978d1bac7a631573eb734fa9dd8bc1519fad5"},{"version":"5550d9209d5fceb65657e4873eaf7654b8b405af7b084ce6660ff1bd7b9ea5a9","signature":"1ba3345545c1c84fd774bc2cf92d594a32f487cc580ef7d66c2537fea2ef025e"},{"version":"17ed71200119e86ccef2d96b73b02ce8854b76ad6bd21b5021d4269bec527b5f","impliedFormat":1}],"root":[[48,53]],"options":{"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"jsx":4,"module":99,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"strict":true,"target":6},"referencedMap":[[49,1],[50,1],[51,2],[52,3],[48,3],[53,4],[54,5],[46,6],[47,5]],"latestChangedDtsFile":"./dist/workspace.d.ts","version":"5.8.3"}
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import type { IConfiguration } from "./types";
2
- declare const repositoryManager: () => {
3
- workspace<I extends Record<string, any>>(infrastructure: I, config: IConfiguration): {
4
- defineRepository: (id: string, repository: import("./types").repositoryType<I, any>) => void;
5
- };
6
- query<R = any>(path: string): {
7
- repository: R;
8
- disconnect(): void;
9
- };
10
- };
11
- export { repositoryManager };
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,SAAS,CAAC;AAG1D,QAAA,MAAM,iBAAiB;cAGT,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,kBACrB,CAAC,UACT,cAAc;;;UAQlB,CAAC,cAAc,MAAM;;;;CAa9B,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- import { createStore } from "./store";
2
- import { createWorkspace } from "./workspace";
3
- const repositoryManager = () => {
4
- const store = createStore();
5
- return {
6
- workspace(infrastructure, config) {
7
- const workspace = createWorkspace(infrastructure, config);
8
- store.setState(config.id, workspace);
9
- return {
10
- defineRepository: workspace.defineRepository,
11
- };
12
- },
13
- query(path) {
14
- const [containerId, repositoryId] = path.split("/");
15
- const container = store.getState(containerId);
16
- if (!container) {
17
- throw new Error(`Container ${containerId} not found`);
18
- }
19
- const queryRepository = container.queryRepository;
20
- return queryRepository(repositoryId);
21
- },
22
- };
23
- };
24
- export { repositoryManager };
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- import { createStore } from "./store";
2
- import type { IConfiguration, IWorkspace } from "./types";
3
- import { createWorkspace } from "./workspace";
4
-
5
- const repositoryManager = () => {
6
- const store = createStore<IWorkspace<any>>();
7
- return {
8
- workspace<I extends Record<string, any>>(
9
- infrastructure: I,
10
- config: IConfiguration
11
- ) {
12
- const workspace = createWorkspace(infrastructure, config);
13
- store.setState(config.id, workspace);
14
- return {
15
- defineRepository: workspace.defineRepository,
16
- };
17
- },
18
- query<R = any>(path: string) {
19
- const [containerId, repositoryId] = path.split("/");
20
- const container = store.getState(containerId);
21
- if (!container) {
22
- throw new Error(`Container ${containerId} not found`);
23
- }
24
- const queryRepository = container.queryRepository as IWorkspace<
25
- any,
26
- R
27
- >["queryRepository"];
28
- return queryRepository(repositoryId);
29
- },
30
- };
31
- };
32
-
33
- export { repositoryManager };