@med1802/repository-manager 1.0.0 → 2.1.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 +353 -67
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -59
- package/dist/repositoryAccessor.d.ts +9 -0
- package/dist/repositoryAccessor.d.ts.map +1 -0
- package/dist/repositoryAccessor.js +35 -0
- package/dist/store.d.ts +6 -7
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +6 -6
- package/dist/types.d.ts +19 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/workspace.d.ts +10 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +61 -0
- package/package.json +1 -1
- package/src/index.ts +21 -73
- package/src/repositoryAccessor.ts +40 -0
- package/src/store.ts +8 -9
- package/src/types.ts +23 -3
- package/src/workspace.ts +85 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/repositoryInstance.d.ts +0 -8
- package/dist/repositoryInstance.d.ts.map +0 -1
- package/dist/repositoryInstance.js +0 -27
- package/src/repositoryInstance.ts +0 -30
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# 🔄 Repository Manager
|
|
2
2
|
|
|
3
|
-
A lightweight, type-safe repository manager with dependency injection
|
|
3
|
+
A lightweight, type-safe repository manager with dependency injection, lifecycle management, and multi-workspace support for TypeScript/JavaScript applications.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- ✅ **Dependency Injection** - Inject infrastructure dependencies into repositories
|
|
8
8
|
- ✅ **Lifecycle Management** - Automatic connection/disconnection with reference counting
|
|
9
|
+
- ✅ **Multi-Workspace Support** - Manage multiple isolated workspaces with different dependencies
|
|
9
10
|
- ✅ **Type Safety** - Full TypeScript support with generics
|
|
10
11
|
- ✅ **Lazy Initialization** - Repository instances are created only when needed
|
|
12
|
+
- ✅ **Imperative API** - Define workspaces and repositories as needed
|
|
11
13
|
- ✅ **Logging** - Built-in logging with colored console output
|
|
12
14
|
- ✅ **Memory Efficient** - Automatic cleanup when no connections remain
|
|
13
15
|
|
|
@@ -22,155 +24,439 @@ npm install @med1802/repository-manager
|
|
|
22
24
|
```typescript
|
|
23
25
|
import { repositoryManager } from "@med1802/repository-manager";
|
|
24
26
|
|
|
25
|
-
// Define your
|
|
26
|
-
interface
|
|
27
|
+
// Define your dependencies interface
|
|
28
|
+
interface IDependencies {
|
|
27
29
|
httpClient: {
|
|
28
30
|
get(url: string): Promise<any>;
|
|
29
31
|
post(url: string, data: any): Promise<any>;
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
// Create
|
|
35
|
+
// Create manager instance
|
|
34
36
|
const manager = repositoryManager();
|
|
35
|
-
|
|
37
|
+
|
|
38
|
+
// Define infrastructure dependencies
|
|
39
|
+
const infrastructure: IDependencies = {
|
|
36
40
|
httpClient: {
|
|
37
41
|
get: async (url) => fetch(url).then((r) => r.json()),
|
|
38
42
|
post: async (url, data) =>
|
|
39
43
|
fetch(url, { method: "POST", body: JSON.stringify(data) }),
|
|
40
44
|
},
|
|
41
|
-
}
|
|
45
|
+
};
|
|
42
46
|
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return infrastructure.httpClient.get("/api/users");
|
|
48
|
-
},
|
|
49
|
-
async createUser(user: any) {
|
|
50
|
-
return infrastructure.httpClient.post("/api/users", user);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
47
|
+
// Create a workspace and define repositories
|
|
48
|
+
const { defineRepository } = manager.workspace(infrastructure, {
|
|
49
|
+
id: "app",
|
|
50
|
+
logging: true,
|
|
53
51
|
});
|
|
54
52
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// Define repositories
|
|
54
|
+
defineRepository("userRepo", (infrastructure) => ({
|
|
55
|
+
async getUsers() {
|
|
56
|
+
return infrastructure.httpClient.get("/api/users");
|
|
57
|
+
},
|
|
58
|
+
async createUser(user: any) {
|
|
59
|
+
return infrastructure.httpClient.post("/api/users", user);
|
|
60
|
+
},
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
defineRepository("postRepo", (infrastructure) => ({
|
|
64
|
+
async getPosts() {
|
|
65
|
+
return infrastructure.httpClient.get("/api/posts");
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// Use repositories with path format: "workspaceId/repositoryId"
|
|
70
|
+
const { repository: userRepo, disconnect } = manager.query("app/userRepo");
|
|
71
|
+
const users = await userRepo.getUsers();
|
|
58
72
|
|
|
59
73
|
// Cleanup when done
|
|
60
74
|
disconnect();
|
|
61
75
|
```
|
|
62
76
|
|
|
63
|
-
## API
|
|
77
|
+
## API Reference
|
|
64
78
|
|
|
65
79
|
### `repositoryManager()`
|
|
66
80
|
|
|
67
|
-
Creates a
|
|
81
|
+
Creates a repository manager instance.
|
|
82
|
+
|
|
83
|
+
**Returns:** Manager object with `workspace` and `query` methods
|
|
84
|
+
|
|
85
|
+
**Example:**
|
|
68
86
|
|
|
69
87
|
```typescript
|
|
70
88
|
const manager = repositoryManager();
|
|
71
89
|
```
|
|
72
90
|
|
|
73
|
-
### `
|
|
91
|
+
### `manager.workspace<I>(infrastructure, config)`
|
|
74
92
|
|
|
75
|
-
Creates a
|
|
93
|
+
Creates a workspace with infrastructure dependencies and returns a `defineRepository` function.
|
|
76
94
|
|
|
77
95
|
**Parameters:**
|
|
78
96
|
|
|
79
|
-
- `infrastructure` -
|
|
80
|
-
- `config` -
|
|
97
|
+
- `infrastructure: I` - Infrastructure dependencies to inject into repositories
|
|
98
|
+
- `config: IConfiguration` - Workspace configuration
|
|
99
|
+
- `id: string` - Unique identifier for the workspace
|
|
81
100
|
- `logging?: boolean` - Enable/disable logging (default: `false`)
|
|
82
101
|
|
|
83
|
-
**Returns:**
|
|
102
|
+
**Returns:** Object with `defineRepository` method
|
|
84
103
|
|
|
85
|
-
|
|
104
|
+
**Example:**
|
|
86
105
|
|
|
87
|
-
|
|
106
|
+
```typescript
|
|
107
|
+
const { defineRepository } = manager.workspace(infrastructure, {
|
|
108
|
+
id: "app",
|
|
109
|
+
logging: true,
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### `defineRepository(id, factory, config?)`
|
|
114
|
+
|
|
115
|
+
Defines a repository within the workspace.
|
|
88
116
|
|
|
89
117
|
**Parameters:**
|
|
90
118
|
|
|
91
|
-
- `id` - Unique identifier for the repository
|
|
92
|
-
- `
|
|
119
|
+
- `id: string` - Unique identifier for the repository
|
|
120
|
+
- `factory: (infrastructure: I) => R` - Factory function that receives infrastructure and returns repository instance
|
|
121
|
+
- `config?: IRepositoryConfig` - Optional repository configuration
|
|
122
|
+
- `lifecycle?: ILifeCycle` - Lifecycle hooks
|
|
123
|
+
- `onConnect?: () => void` - Called when repository is first connected (when connections go from 0 to 1)
|
|
124
|
+
- `onDisconnect?: () => void` - Called when repository is last disconnected (when connections go from 1 to 0)
|
|
125
|
+
|
|
126
|
+
**Example:**
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
defineRepository("userRepo", (infrastructure) => ({
|
|
130
|
+
getUsers: () => infrastructure.httpClient.get("/users"),
|
|
131
|
+
}));
|
|
132
|
+
|
|
133
|
+
// With lifecycle hooks
|
|
134
|
+
defineRepository(
|
|
135
|
+
"userRepo",
|
|
136
|
+
(infrastructure) => ({
|
|
137
|
+
getUsers: () => infrastructure.httpClient.get("/users"),
|
|
138
|
+
}),
|
|
139
|
+
{
|
|
140
|
+
lifecycle: {
|
|
141
|
+
onConnect: () => {
|
|
142
|
+
console.log("User repository initialized");
|
|
143
|
+
},
|
|
144
|
+
onDisconnect: () => {
|
|
145
|
+
console.log("User repository cleaned up");
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
```
|
|
93
151
|
|
|
94
|
-
### `
|
|
152
|
+
### `manager.query<R>(path)`
|
|
95
153
|
|
|
96
|
-
Queries a repository
|
|
154
|
+
Queries a repository from a workspace using path format: `"workspaceId/repositoryId"`.
|
|
97
155
|
|
|
98
156
|
**Parameters:**
|
|
99
157
|
|
|
100
|
-
- `
|
|
158
|
+
- `path: string` - Path to repository in format `"workspaceId/repositoryId"`
|
|
101
159
|
|
|
102
160
|
**Returns:** Object with:
|
|
103
161
|
|
|
104
|
-
- `repository:
|
|
105
|
-
- `disconnect: () => void` -
|
|
162
|
+
- `repository: R` - The repository instance
|
|
163
|
+
- `disconnect: () => void` - Function to disconnect and cleanup
|
|
106
164
|
|
|
107
|
-
|
|
165
|
+
**Throws:** `Error` if workspace or repository is not found
|
|
108
166
|
|
|
109
|
-
|
|
167
|
+
**Example:**
|
|
110
168
|
|
|
111
169
|
```typescript
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
170
|
+
const { repository, disconnect } = manager.query<IUserRepo>("app/userRepo");
|
|
171
|
+
await repository.getUsers();
|
|
172
|
+
disconnect();
|
|
115
173
|
```
|
|
116
174
|
|
|
117
|
-
|
|
175
|
+
## Advanced Usage
|
|
176
|
+
|
|
177
|
+
### Multiple Workspaces
|
|
178
|
+
|
|
179
|
+
You can create multiple isolated workspaces with different dependencies:
|
|
118
180
|
|
|
119
181
|
```typescript
|
|
120
|
-
|
|
182
|
+
const manager = repositoryManager();
|
|
183
|
+
|
|
184
|
+
// API workspace
|
|
185
|
+
const { defineRepository: defineApiRepo } = manager.workspace(
|
|
186
|
+
{
|
|
187
|
+
httpClient: apiHttpClient,
|
|
188
|
+
cache: redisCache,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "api",
|
|
192
|
+
logging: true,
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
defineApiRepo("userRepo", (infrastructure) => ({
|
|
121
197
|
getUsers: () => infrastructure.httpClient.get("/users"),
|
|
122
198
|
}));
|
|
123
199
|
|
|
124
|
-
|
|
125
|
-
|
|
200
|
+
// Database workspace
|
|
201
|
+
const { defineRepository: defineDbRepo } = manager.workspace(
|
|
202
|
+
{
|
|
203
|
+
db: postgresClient,
|
|
204
|
+
logger: winstonLogger,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: "database",
|
|
208
|
+
logging: false,
|
|
209
|
+
}
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
defineDbRepo("orderRepo", (infrastructure) => ({
|
|
213
|
+
getOrders: () => infrastructure.db.query("SELECT * FROM orders"),
|
|
126
214
|
}));
|
|
127
215
|
|
|
128
|
-
|
|
129
|
-
const
|
|
216
|
+
// Access repositories from different workspaces
|
|
217
|
+
const { repository: userRepo } = manager.query("api/userRepo");
|
|
218
|
+
const { repository: orderRepo } = manager.query("database/orderRepo");
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### TypeScript Interfaces
|
|
222
|
+
|
|
223
|
+
Define clear interfaces for better type safety:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
interface IUserRepo {
|
|
227
|
+
getUsers(): Promise<User[]>;
|
|
228
|
+
createUser(user: User): Promise<User>;
|
|
229
|
+
updateUser(id: string, user: Partial<User>): Promise<User>;
|
|
230
|
+
deleteUser(id: string): Promise<void>;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
interface IDependencies {
|
|
234
|
+
httpClient: IHttpClient;
|
|
235
|
+
cache: ICache;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const manager = repositoryManager();
|
|
239
|
+
|
|
240
|
+
const { defineRepository } = manager.workspace<IDependencies>(
|
|
241
|
+
{
|
|
242
|
+
httpClient: myHttpClient,
|
|
243
|
+
cache: myCache,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: "app",
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
defineRepository<IUserRepo>(
|
|
251
|
+
"userRepo",
|
|
252
|
+
(infrastructure): IUserRepo => ({
|
|
253
|
+
async getUsers() {
|
|
254
|
+
/* ... */
|
|
255
|
+
},
|
|
256
|
+
async createUser(user) {
|
|
257
|
+
/* ... */
|
|
258
|
+
},
|
|
259
|
+
async updateUser(id, user) {
|
|
260
|
+
/* ... */
|
|
261
|
+
},
|
|
262
|
+
async deleteUser(id) {
|
|
263
|
+
/* ... */
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// TypeScript knows the exact return type
|
|
269
|
+
const { repository } = manager.query<IUserRepo>("app/userRepo");
|
|
270
|
+
// repository has all IUserRepo methods with correct types
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Lifecycle Management with Reference Counting
|
|
274
|
+
|
|
275
|
+
Repositories use reference counting for automatic lifecycle management:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
// First query creates the repository instance
|
|
279
|
+
const conn1 = manager.query("app/userRepo"); // Connections: 1
|
|
280
|
+
const conn2 = manager.query("app/userRepo"); // Connections: 2 (reuses instance)
|
|
281
|
+
const conn3 = manager.query("app/userRepo"); // Connections: 3 (reuses instance)
|
|
282
|
+
|
|
283
|
+
conn1.disconnect(); // Connections: 2 (still active)
|
|
284
|
+
conn2.disconnect(); // Connections: 1 (still active)
|
|
285
|
+
conn3.disconnect(); // Connections: 0 (instance destroyed)
|
|
286
|
+
|
|
287
|
+
// Next query will create a new instance
|
|
288
|
+
const conn4 = manager.query("app/userRepo"); // Connections: 1 (new instance)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Lifecycle Hooks
|
|
292
|
+
|
|
293
|
+
You can define lifecycle hooks that are called at specific points in the repository lifecycle:
|
|
294
|
+
|
|
295
|
+
- **`onConnect`** - Called only when the repository is first connected (when connections go from 0 to 1)
|
|
296
|
+
- **`onDisconnect`** - Called only when the repository is last disconnected (when connections go from 1 to 0)
|
|
297
|
+
|
|
298
|
+
**Example:**
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
defineRepository(
|
|
302
|
+
"userRepo",
|
|
303
|
+
(infrastructure) => ({
|
|
304
|
+
getUsers: () => infrastructure.httpClient.get("/api/users"),
|
|
305
|
+
}),
|
|
306
|
+
{
|
|
307
|
+
lifecycle: {
|
|
308
|
+
onConnect: () => {
|
|
309
|
+
console.log("User repository initialized");
|
|
310
|
+
// Perform initialization tasks (e.g., setup cache, establish connection)
|
|
311
|
+
},
|
|
312
|
+
onDisconnect: () => {
|
|
313
|
+
console.log("User repository cleaned up");
|
|
314
|
+
// Perform cleanup tasks (e.g., clear cache, close connections)
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
// Usage
|
|
321
|
+
const conn1 = manager.query("app/userRepo"); // onConnect called (first connection)
|
|
322
|
+
const conn2 = manager.query("app/userRepo"); // onConnect NOT called (reusing instance)
|
|
323
|
+
|
|
324
|
+
conn1.disconnect(); // onDisconnect NOT called (still has connections)
|
|
325
|
+
conn2.disconnect(); // onDisconnect called (last connection removed)
|
|
130
326
|
```
|
|
131
327
|
|
|
132
|
-
|
|
328
|
+
**Use Cases:**
|
|
329
|
+
|
|
330
|
+
- **Initialization**: Setup cache, establish database connections, initialize state
|
|
331
|
+
- **Cleanup**: Clear cache, close connections, release resources
|
|
332
|
+
- **Analytics**: Track repository usage and lifecycle events
|
|
333
|
+
- **Debugging**: Monitor when repositories are created and destroyed
|
|
133
334
|
|
|
134
|
-
|
|
335
|
+
### Using with React
|
|
135
336
|
|
|
136
337
|
```typescript
|
|
137
|
-
|
|
138
|
-
const repo2 = app.queryRepository("user-repo"); // Reuses instance
|
|
139
|
-
const repo3 = app.queryRepository("user-repo"); // Reuses instance
|
|
338
|
+
import { useEffect } from "react";
|
|
140
339
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
340
|
+
function UserList() {
|
|
341
|
+
useEffect(() => {
|
|
342
|
+
const { repository, disconnect } = manager.query<IUserRepo>("app/userRepo");
|
|
343
|
+
|
|
344
|
+
repository.getUsers().then(setUsers);
|
|
345
|
+
|
|
346
|
+
// Cleanup on unmount
|
|
347
|
+
return disconnect;
|
|
348
|
+
}, []);
|
|
349
|
+
|
|
350
|
+
return <div>{/* ... */}</div>;
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Logging
|
|
355
|
+
|
|
356
|
+
Enable logging to see connection lifecycle:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
const manager = repositoryManager();
|
|
360
|
+
|
|
361
|
+
const { defineRepository } = manager.workspace(infrastructure, {
|
|
362
|
+
id: "app",
|
|
363
|
+
logging: true, // Enables colored console output
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Console output will show:
|
|
367
|
+
// repository.connect (app/userRepo)
|
|
368
|
+
// ┌─────────┬──────────┬─────────────┐
|
|
369
|
+
// │ (index) │ id │ connections │
|
|
370
|
+
// ├─────────┼──────────┼─────────────┤
|
|
371
|
+
// │ 0 │ userRepo │ 1 │
|
|
372
|
+
// └─────────┴──────────┴─────────────┘
|
|
144
373
|
```
|
|
145
374
|
|
|
146
375
|
## Dependency Injection Pattern
|
|
147
376
|
|
|
148
|
-
This package follows the Dependency Inversion Principle (DIP)
|
|
377
|
+
This package follows the **Dependency Inversion Principle (DIP)**:
|
|
149
378
|
|
|
150
|
-
- **High-level modules** (repositories) depend on abstractions (
|
|
379
|
+
- **High-level modules** (repositories) depend on abstractions (dependencies interface)
|
|
151
380
|
- **Low-level modules** (infrastructure implementations) are injected
|
|
152
|
-
- Easy to test with mock
|
|
381
|
+
- Easy to test with mock dependencies
|
|
153
382
|
- Easy to swap implementations
|
|
154
383
|
|
|
155
384
|
```typescript
|
|
156
|
-
// Define
|
|
157
|
-
interface
|
|
385
|
+
// Define abstractions
|
|
386
|
+
interface IDatabase {
|
|
387
|
+
query(sql: string): Promise<any>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
interface ICache {
|
|
391
|
+
get(key: string): Promise<any>;
|
|
392
|
+
set(key: string, value: any): Promise<void>;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
interface IDependencies {
|
|
158
396
|
database: IDatabase;
|
|
159
397
|
cache: ICache;
|
|
160
398
|
}
|
|
161
399
|
|
|
162
400
|
// Inject concrete implementations
|
|
163
|
-
const
|
|
164
|
-
database: new PostgreSQL(),
|
|
165
|
-
cache: new RedisCache(),
|
|
166
|
-
});
|
|
401
|
+
const manager = repositoryManager();
|
|
167
402
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
403
|
+
const { defineRepository } = manager.workspace<IDependencies>(
|
|
404
|
+
{
|
|
405
|
+
database: new PostgreSQLClient(),
|
|
406
|
+
cache: new RedisCache(),
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
id: "prod",
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// Easy to test with mocks
|
|
414
|
+
const { defineRepository: defineTestRepo } = manager.workspace<IDependencies>(
|
|
415
|
+
{
|
|
416
|
+
database: new MockDatabase(),
|
|
417
|
+
cache: new MockCache(),
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
id: "test",
|
|
421
|
+
}
|
|
422
|
+
);
|
|
172
423
|
```
|
|
173
424
|
|
|
425
|
+
## Design Patterns
|
|
426
|
+
|
|
427
|
+
This library implements several design patterns:
|
|
428
|
+
|
|
429
|
+
- **Dependency Injection** - Dependencies are injected into repositories
|
|
430
|
+
- **Factory Pattern** - Repositories are created using factory functions
|
|
431
|
+
- **Singleton Pattern** - Each repository is a singleton per workspace (with reference counting)
|
|
432
|
+
- **Repository Pattern** - Abstracts data access logic
|
|
433
|
+
- **Workspace Pattern** - Manages dependencies and lifecycle
|
|
434
|
+
|
|
435
|
+
## Error Handling
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
try {
|
|
439
|
+
const { repository } = manager.query("non-existent/repo");
|
|
440
|
+
} catch (error) {
|
|
441
|
+
console.error(error.message); // Container "non-existent" not found
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
const { repository } = manager.query("app/non-existent");
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error(error.message); // Repository "non-existent" not found
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Best Practices
|
|
452
|
+
|
|
453
|
+
1. **Define interfaces for dependencies and repositories** - Better type safety
|
|
454
|
+
2. **Use one workspace per context** - Separate API, database, etc.
|
|
455
|
+
3. **Always call disconnect** - Proper cleanup prevents memory leaks
|
|
456
|
+
4. **Enable logging during development** - Helps debug lifecycle issues
|
|
457
|
+
5. **Keep repositories focused** - Single responsibility principle
|
|
458
|
+
6. **Use dependency interfaces, not concrete classes** - Easier to test and swap
|
|
459
|
+
|
|
174
460
|
## License
|
|
175
461
|
|
|
176
462
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { IConfiguration } from "./types";
|
|
2
2
|
declare const repositoryManager: () => {
|
|
3
|
-
|
|
4
|
-
defineRepository(id: string,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
workspace<I extends Record<string, any>>(infrastructure: I, config: IConfiguration): {
|
|
4
|
+
defineRepository: (id: string, repository: import("./types").repositoryType<I, any>, config?: import("./types").IRepositoryConfig) => void;
|
|
5
|
+
};
|
|
6
|
+
query<R = any>(path: string): {
|
|
7
|
+
repository: R;
|
|
8
|
+
disconnect(): void;
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export { repositoryManager };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -1,68 +1,24 @@
|
|
|
1
|
-
import { createRepositoryInstance } from "./repositoryInstance";
|
|
2
1
|
import { createStore } from "./store";
|
|
3
|
-
import {
|
|
2
|
+
import { createWorkspace } from "./workspace";
|
|
4
3
|
const repositoryManager = () => {
|
|
4
|
+
const store = createStore();
|
|
5
5
|
return {
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
...config,
|
|
10
|
-
};
|
|
11
|
-
const store = createStore();
|
|
12
|
-
const logger = createLogger(defaultConfig);
|
|
13
|
-
const getRepository = (id) => store.getRepository(id);
|
|
14
|
-
const hasRepository = (id) => store.hasRepository(id);
|
|
15
|
-
const allRepositories = () => Array.from(store.entries()).map(([id, repository]) => ({
|
|
16
|
-
repository: id,
|
|
17
|
-
connections: repository.getConnections(),
|
|
18
|
-
}));
|
|
6
|
+
workspace(infrastructure, config) {
|
|
7
|
+
const workspace = createWorkspace(infrastructure, config);
|
|
8
|
+
store.setState(config.id, workspace);
|
|
19
9
|
return {
|
|
20
|
-
defineRepository
|
|
21
|
-
if (hasRepository(id))
|
|
22
|
-
return;
|
|
23
|
-
logger.log(() => {
|
|
24
|
-
store.setRepository(id, createRepositoryInstance(repositoryDefinition, infrastructure));
|
|
25
|
-
}, {
|
|
26
|
-
type: "repository.define",
|
|
27
|
-
scope: id,
|
|
28
|
-
metadata: () => {
|
|
29
|
-
return {
|
|
30
|
-
repositories: allRepositories().map(({ repository }) => ({
|
|
31
|
-
repository,
|
|
32
|
-
})),
|
|
33
|
-
};
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
queryRepository(id) {
|
|
38
|
-
const repository = getRepository(id);
|
|
39
|
-
if (!repository) {
|
|
40
|
-
throw new Error(`Repository "${id}" not found`);
|
|
41
|
-
}
|
|
42
|
-
logger.log(() => repository.connect(), {
|
|
43
|
-
type: "repository.connect",
|
|
44
|
-
scope: id,
|
|
45
|
-
metadata: () => {
|
|
46
|
-
return {
|
|
47
|
-
connections: allRepositories(),
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
repository: repository.getReference(),
|
|
53
|
-
disconnect: () => logger.log(() => repository.disconnect(), {
|
|
54
|
-
type: "repository.disconnect",
|
|
55
|
-
scope: id,
|
|
56
|
-
metadata: () => {
|
|
57
|
-
return {
|
|
58
|
-
connections: allRepositories(),
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
}),
|
|
62
|
-
};
|
|
63
|
-
},
|
|
10
|
+
defineRepository: workspace.defineRepository,
|
|
64
11
|
};
|
|
65
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
|
+
},
|
|
66
22
|
};
|
|
67
23
|
};
|
|
68
24
|
export { repositoryManager };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IRepositoryConfig } from "./types";
|
|
2
|
+
declare function createRepositoryAccessor<I extends Record<string, any>>(definition: (infrastructure: I) => unknown, infrastructure: I, config?: IRepositoryConfig): {
|
|
3
|
+
readonly repository: unknown;
|
|
4
|
+
readonly connections: number;
|
|
5
|
+
connect(): void;
|
|
6
|
+
disconnect(): void;
|
|
7
|
+
};
|
|
8
|
+
export { createRepositoryAccessor };
|
|
9
|
+
//# sourceMappingURL=repositoryAccessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repositoryAccessor.d.ts","sourceRoot":"","sources":["../src/repositoryAccessor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,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;;;;;EAgC3B;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
function createRepositoryAccessor(definition, infrastructure, config) {
|
|
2
|
+
let repository = undefined;
|
|
3
|
+
let connections = 0;
|
|
4
|
+
return {
|
|
5
|
+
get repository() {
|
|
6
|
+
return repository;
|
|
7
|
+
},
|
|
8
|
+
get connections() {
|
|
9
|
+
return connections;
|
|
10
|
+
},
|
|
11
|
+
connect() {
|
|
12
|
+
var _a;
|
|
13
|
+
if (connections === 0) {
|
|
14
|
+
repository = definition(infrastructure);
|
|
15
|
+
if ((_a = config === null || config === void 0 ? void 0 : config.lifecycle) === null || _a === void 0 ? void 0 : _a.onConnect) {
|
|
16
|
+
config.lifecycle.onConnect();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
connections += 1;
|
|
20
|
+
},
|
|
21
|
+
disconnect() {
|
|
22
|
+
var _a;
|
|
23
|
+
if (connections === 0)
|
|
24
|
+
return;
|
|
25
|
+
connections -= 1;
|
|
26
|
+
if (connections === 0) {
|
|
27
|
+
repository = undefined;
|
|
28
|
+
if ((_a = config === null || config === void 0 ? void 0 : config.lifecycle) === null || _a === void 0 ? void 0 : _a.onDisconnect) {
|
|
29
|
+
config.lifecycle.onDisconnect();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { createRepositoryAccessor };
|
package/dist/store.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
entries(): MapIterator<[string, IRepositoryInstance]>;
|
|
1
|
+
declare function createStore<S>(): {
|
|
2
|
+
setState(id: string, item: S): void;
|
|
3
|
+
getState(id: string): S | undefined;
|
|
4
|
+
hasState(id: string): boolean;
|
|
5
|
+
deleteState(id: string): void;
|
|
6
|
+
getEntries(): MapIterator<[string, S]>;
|
|
8
7
|
};
|
|
9
8
|
export { createStore };
|
|
10
9
|
//# sourceMappingURL=store.d.ts.map
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,CAAC;iBAGL,MAAM,QAAQ,CAAC;iBAGf,MAAM;iBAGN,MAAM;oBAGH,MAAM;;EAOzB;AACD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/store.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
function createStore() {
|
|
2
2
|
const state = new Map();
|
|
3
3
|
return {
|
|
4
|
-
|
|
5
|
-
state.set(id,
|
|
4
|
+
setState(id, item) {
|
|
5
|
+
state.set(id, item);
|
|
6
6
|
},
|
|
7
|
-
|
|
7
|
+
getState(id) {
|
|
8
8
|
return state.get(id);
|
|
9
9
|
},
|
|
10
|
-
|
|
10
|
+
hasState(id) {
|
|
11
11
|
return state.has(id);
|
|
12
12
|
},
|
|
13
|
-
|
|
13
|
+
deleteState(id) {
|
|
14
14
|
state.delete(id);
|
|
15
15
|
},
|
|
16
|
-
|
|
16
|
+
getEntries() {
|
|
17
17
|
return state.entries();
|
|
18
18
|
},
|
|
19
19
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
export type repositoryType<I = any, R = any> = (infrastructure: I) => R;
|
|
1
2
|
export interface IConfiguration {
|
|
3
|
+
id: string;
|
|
2
4
|
logging?: boolean;
|
|
3
5
|
}
|
|
4
|
-
export interface
|
|
6
|
+
export interface IWorkspace<I = any, R = any> {
|
|
7
|
+
defineRepository(id: string, repository: repositoryType<I, R>): void;
|
|
8
|
+
queryRepository(id: string): {
|
|
9
|
+
repository: ReturnType<repositoryType<I, R>>;
|
|
10
|
+
disconnect(): void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface IRepositoryInstance<R = any> {
|
|
5
14
|
connect(): void;
|
|
6
15
|
disconnect(): void;
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
repository: ReturnType<repositoryType<any, R>> | undefined;
|
|
17
|
+
connections: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ILifeCycle {
|
|
20
|
+
onConnect?: () => void;
|
|
21
|
+
onDisconnect?: () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface IRepositoryConfig {
|
|
24
|
+
lifecycle?: ILifeCycle;
|
|
9
25
|
}
|
|
10
26
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;
|
|
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,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,UAAU,CAAC;CACxB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IConfiguration, IRepositoryConfig, repositoryType } from "./types";
|
|
2
|
+
declare function createWorkspace<I extends Record<string, any>>(infrastructure: I, config: IConfiguration): {
|
|
3
|
+
defineRepository: (id: string, repository: repositoryType<I, any>, config?: IRepositoryConfig) => void;
|
|
4
|
+
queryRepository: (id: string) => {
|
|
5
|
+
repository: any;
|
|
6
|
+
disconnect(): void;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export { createWorkspace };
|
|
10
|
+
//# sourceMappingURL=workspace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createLogger } from "./logger";
|
|
2
|
+
import { createRepositoryAccessor } from "./repositoryAccessor";
|
|
3
|
+
import { createStore } from "./store";
|
|
4
|
+
function createWorkspace(infrastructure, config) {
|
|
5
|
+
var _a;
|
|
6
|
+
const defaultConfig = {
|
|
7
|
+
id: config.id,
|
|
8
|
+
logging: (_a = config.logging) !== null && _a !== void 0 ? _a : false,
|
|
9
|
+
};
|
|
10
|
+
const logger = createLogger(defaultConfig);
|
|
11
|
+
const store = createStore();
|
|
12
|
+
const hasRepository = (id) => store.hasState(id);
|
|
13
|
+
const allRepositories = () => Array.from(store.getEntries()).map(([id, repository]) => ({
|
|
14
|
+
repository: id,
|
|
15
|
+
connections: repository.connections,
|
|
16
|
+
}));
|
|
17
|
+
const defineRepository = (id, repository, config) => {
|
|
18
|
+
if (hasRepository(id))
|
|
19
|
+
return;
|
|
20
|
+
logger.log(() => {
|
|
21
|
+
store.setState(id, createRepositoryAccessor(repository, infrastructure, config));
|
|
22
|
+
}, {
|
|
23
|
+
type: "repository.define",
|
|
24
|
+
scope: id,
|
|
25
|
+
metadata() {
|
|
26
|
+
return {
|
|
27
|
+
repositories: allRepositories().map(({ repository }) => ({
|
|
28
|
+
repository,
|
|
29
|
+
})),
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const queryRepository = (id) => {
|
|
35
|
+
const entity = store.getState(id);
|
|
36
|
+
if (!entity) {
|
|
37
|
+
throw new Error(`Repository "${id}" not found`);
|
|
38
|
+
}
|
|
39
|
+
logger.log(() => entity.connect(), {
|
|
40
|
+
type: "repository.connect",
|
|
41
|
+
scope: id,
|
|
42
|
+
metadata: () => {
|
|
43
|
+
return {
|
|
44
|
+
connections: allRepositories(),
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const { repository } = entity;
|
|
49
|
+
return {
|
|
50
|
+
repository,
|
|
51
|
+
disconnect() {
|
|
52
|
+
entity.disconnect();
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
defineRepository,
|
|
58
|
+
queryRepository,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export { createWorkspace };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,84 +1,32 @@
|
|
|
1
|
-
import { createRepositoryInstance } from "./repositoryInstance";
|
|
2
1
|
import { createStore } from "./store";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import type { IConfiguration, IWorkspace } from "./types";
|
|
3
|
+
import { createWorkspace } from "./workspace";
|
|
4
|
+
|
|
5
5
|
const repositoryManager = () => {
|
|
6
|
+
const store = createStore<IWorkspace<any>>();
|
|
6
7
|
return {
|
|
7
|
-
|
|
8
|
+
workspace<I extends Record<string, any>>(
|
|
8
9
|
infrastructure: I,
|
|
9
|
-
config
|
|
10
|
+
config: IConfiguration
|
|
10
11
|
) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
...config,
|
|
14
|
-
};
|
|
15
|
-
const store = createStore();
|
|
16
|
-
const logger = createLogger(defaultConfig);
|
|
17
|
-
|
|
18
|
-
const getRepository = (id: string) => store.getRepository(id);
|
|
19
|
-
const hasRepository = (id: string) => store.hasRepository(id);
|
|
20
|
-
const allRepositories = () =>
|
|
21
|
-
Array.from(store.entries()).map(([id, repository]) => ({
|
|
22
|
-
repository: id,
|
|
23
|
-
connections: repository.getConnections(),
|
|
24
|
-
}));
|
|
25
|
-
|
|
12
|
+
const workspace = createWorkspace(infrastructure, config);
|
|
13
|
+
store.setState(config.id, workspace);
|
|
26
14
|
return {
|
|
27
|
-
defineRepository
|
|
28
|
-
id: string,
|
|
29
|
-
repositoryDefinition: (infrastructure: I) => void
|
|
30
|
-
) {
|
|
31
|
-
if (hasRepository(id)) return;
|
|
32
|
-
logger.log(
|
|
33
|
-
() => {
|
|
34
|
-
store.setRepository(
|
|
35
|
-
id,
|
|
36
|
-
createRepositoryInstance(repositoryDefinition, infrastructure)
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
type: "repository.define",
|
|
41
|
-
scope: id,
|
|
42
|
-
metadata: () => {
|
|
43
|
-
return {
|
|
44
|
-
repositories: allRepositories().map(({ repository }) => ({
|
|
45
|
-
repository,
|
|
46
|
-
})),
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
queryRepository<R = any>(id: string) {
|
|
53
|
-
const repository = getRepository(id);
|
|
54
|
-
if (!repository) {
|
|
55
|
-
throw new Error(`Repository "${id}" not found`);
|
|
56
|
-
}
|
|
57
|
-
logger.log(() => repository.connect(), {
|
|
58
|
-
type: "repository.connect",
|
|
59
|
-
scope: id,
|
|
60
|
-
metadata: () => {
|
|
61
|
-
return {
|
|
62
|
-
connections: allRepositories(),
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
repository: repository.getReference() as R,
|
|
68
|
-
disconnect: () =>
|
|
69
|
-
logger.log(() => repository.disconnect(), {
|
|
70
|
-
type: "repository.disconnect",
|
|
71
|
-
scope: id,
|
|
72
|
-
metadata: () => {
|
|
73
|
-
return {
|
|
74
|
-
connections: allRepositories(),
|
|
75
|
-
};
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
};
|
|
79
|
-
},
|
|
15
|
+
defineRepository: workspace.defineRepository,
|
|
80
16
|
};
|
|
81
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
|
+
},
|
|
82
30
|
};
|
|
83
31
|
};
|
|
84
32
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { IRepositoryConfig } from "./types";
|
|
2
|
+
|
|
3
|
+
function createRepositoryAccessor<I extends Record<string, any>>(
|
|
4
|
+
definition: (infrastructure: I) => unknown,
|
|
5
|
+
infrastructure: I,
|
|
6
|
+
config?: IRepositoryConfig
|
|
7
|
+
) {
|
|
8
|
+
let repository = undefined as unknown;
|
|
9
|
+
let connections = 0;
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
get repository() {
|
|
13
|
+
return repository;
|
|
14
|
+
},
|
|
15
|
+
get connections() {
|
|
16
|
+
return connections;
|
|
17
|
+
},
|
|
18
|
+
connect() {
|
|
19
|
+
if (connections === 0) {
|
|
20
|
+
repository = definition(infrastructure);
|
|
21
|
+
if (config?.lifecycle?.onConnect) {
|
|
22
|
+
config.lifecycle.onConnect();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
connections += 1;
|
|
26
|
+
},
|
|
27
|
+
disconnect() {
|
|
28
|
+
if (connections === 0) return;
|
|
29
|
+
connections -= 1;
|
|
30
|
+
if (connections === 0) {
|
|
31
|
+
repository = undefined;
|
|
32
|
+
if (config?.lifecycle?.onDisconnect) {
|
|
33
|
+
config.lifecycle.onDisconnect();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { createRepositoryAccessor };
|
package/src/store.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const state = new Map<string, IRepositoryInstance>();
|
|
1
|
+
function createStore<S>() {
|
|
2
|
+
const state = new Map<string, S>();
|
|
4
3
|
return {
|
|
5
|
-
|
|
6
|
-
state.set(id,
|
|
4
|
+
setState(id: string, item: S) {
|
|
5
|
+
state.set(id, item);
|
|
7
6
|
},
|
|
8
|
-
|
|
7
|
+
getState(id: string) {
|
|
9
8
|
return state.get(id);
|
|
10
9
|
},
|
|
11
|
-
|
|
10
|
+
hasState(id: string) {
|
|
12
11
|
return state.has(id);
|
|
13
12
|
},
|
|
14
|
-
|
|
13
|
+
deleteState(id: string) {
|
|
15
14
|
state.delete(id);
|
|
16
15
|
},
|
|
17
|
-
|
|
16
|
+
getEntries() {
|
|
18
17
|
return state.entries();
|
|
19
18
|
},
|
|
20
19
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
export type repositoryType<I = any, R = any> = (infrastructure: I) => R;
|
|
2
|
+
|
|
1
3
|
export interface IConfiguration {
|
|
4
|
+
id: string;
|
|
2
5
|
logging?: boolean;
|
|
3
6
|
}
|
|
4
7
|
|
|
5
|
-
export interface
|
|
8
|
+
export interface IWorkspace<I = any, R = any> {
|
|
9
|
+
defineRepository(id: string, repository: repositoryType<I, R>): void;
|
|
10
|
+
queryRepository(id: string): {
|
|
11
|
+
repository: ReturnType<repositoryType<I, R>>;
|
|
12
|
+
disconnect(): void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IRepositoryInstance<R = any> {
|
|
6
17
|
connect(): void;
|
|
7
18
|
disconnect(): void;
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
repository: ReturnType<repositoryType<any, R>> | undefined;
|
|
20
|
+
connections: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ILifeCycle {
|
|
24
|
+
onConnect?: () => void;
|
|
25
|
+
onDisconnect?: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface IRepositoryConfig {
|
|
29
|
+
lifecycle?: ILifeCycle;
|
|
10
30
|
}
|
package/src/workspace.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createLogger } from "./logger";
|
|
2
|
+
import { createRepositoryAccessor } from "./repositoryAccessor";
|
|
3
|
+
import { createStore } from "./store";
|
|
4
|
+
import type {
|
|
5
|
+
IConfiguration,
|
|
6
|
+
ILifeCycle,
|
|
7
|
+
IRepositoryConfig,
|
|
8
|
+
IRepositoryInstance,
|
|
9
|
+
repositoryType,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
function createWorkspace<I extends Record<string, any>>(
|
|
13
|
+
infrastructure: I,
|
|
14
|
+
config: IConfiguration
|
|
15
|
+
) {
|
|
16
|
+
const defaultConfig: IConfiguration = {
|
|
17
|
+
id: config.id,
|
|
18
|
+
logging: config.logging ?? false,
|
|
19
|
+
};
|
|
20
|
+
const logger = createLogger(defaultConfig);
|
|
21
|
+
const store = createStore<IRepositoryInstance<any>>();
|
|
22
|
+
const hasRepository = (id: string) => store.hasState(id);
|
|
23
|
+
const allRepositories = () =>
|
|
24
|
+
Array.from(store.getEntries()).map(([id, repository]) => ({
|
|
25
|
+
repository: id,
|
|
26
|
+
connections: repository.connections,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const defineRepository = (
|
|
30
|
+
id: string,
|
|
31
|
+
repository: repositoryType<I, any>,
|
|
32
|
+
config?: IRepositoryConfig
|
|
33
|
+
) => {
|
|
34
|
+
if (hasRepository(id)) return;
|
|
35
|
+
logger.log(
|
|
36
|
+
() => {
|
|
37
|
+
store.setState(
|
|
38
|
+
id,
|
|
39
|
+
createRepositoryAccessor(repository, infrastructure, config)
|
|
40
|
+
);
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "repository.define",
|
|
44
|
+
scope: id,
|
|
45
|
+
metadata() {
|
|
46
|
+
return {
|
|
47
|
+
repositories: allRepositories().map(({ repository }) => ({
|
|
48
|
+
repository,
|
|
49
|
+
})),
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const queryRepository = (id: string) => {
|
|
57
|
+
const entity = store.getState(id);
|
|
58
|
+
if (!entity) {
|
|
59
|
+
throw new Error(`Repository "${id}" not found`);
|
|
60
|
+
}
|
|
61
|
+
logger.log(() => entity.connect(), {
|
|
62
|
+
type: "repository.connect",
|
|
63
|
+
scope: id,
|
|
64
|
+
metadata: () => {
|
|
65
|
+
return {
|
|
66
|
+
connections: allRepositories(),
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const { repository } = entity;
|
|
71
|
+
return {
|
|
72
|
+
repository,
|
|
73
|
+
disconnect() {
|
|
74
|
+
entity.disconnect();
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
defineRepository,
|
|
81
|
+
queryRepository,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { createWorkspace };
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -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/repositoryinstance.ts","./src/types.ts","./src/store.ts","./src/logger.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,50,51],[47,49],[47],[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":"ace4a119abe4ca7ea58ca5e0b89420d791a9c68ff5fcb3d32187ffa495f47d36","signature":"9aad1a780fa42fe11f3209e60c109f32b00cd0661629e4faa909c43b80850a82"},{"version":"f3d695638d86fc0e49aa2923963c5491b0bef20f8fb1b582ff813364d3a22dfb","signature":"abbe52d6fc94ab7de123cc0eaf9c83a8b9b0b63d55e24c83188ccd145860cc6e"},{"version":"f5067e271313e63a819ff1c077910638e1475cc4f6be4fcf690d1b928fcf582c","signature":"c15a174d71579221241c22ceb238a46fcad2df8b873dc5c9450fd545f6416dfe"},{"version":"492c075c93e7422319653338cad79622e19a08cc9269f62600805c1fb52b1a36","signature":"935c0760e874c9d96997126152eb9b3b8d7104025b942bf0a92202583276ddbd"},{"version":"82f94351ad2096c90d036a069c887c8e08dce7f118d977eab88034d4a264c219","signature":"29a079aacb8d621cdf086d8325c3c6c92783dcc0119ef27893e9ba1486effd7e"},{"version":"17ed71200119e86ccef2d96b73b02ce8854b76ad6bd21b5021d4269bec527b5f","impliedFormat":1}],"root":[[48,52]],"options":{"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"jsx":4,"module":99,"outDir":"./dist","rootDir":"./src","skipLibCheck":true,"strict":true,"target":6},"referencedMap":[[52,1],[51,2],[48,3],[50,2],[49,3],[53,4],[46,5],[47,4]],"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/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":"3d9bffb72cfd6deda0597a25766c153c037d8fdacf8a55f65127726b048b3379","signature":"2d4c6e2014ffef491a520689c99c29e344509136bf7a60835eda2e106416131f"},{"version":"492c075c93e7422319653338cad79622e19a08cc9269f62600805c1fb52b1a36","signature":"935c0760e874c9d96997126152eb9b3b8d7104025b942bf0a92202583276ddbd"},{"version":"cb0b0288da6d546cf32f619a10b47ba52c217fcca3df9280d8410ff2998ac090","signature":"d1852188e1eadd0541bc395045b0d4a0a63f781d9af56bae6b77a935f585b329"},{"version":"5550d9209d5fceb65657e4873eaf7654b8b405af7b084ce6660ff1bd7b9ea5a9","signature":"1ba3345545c1c84fd774bc2cf92d594a32f487cc580ef7d66c2537fea2ef025e"},{"version":"60b550dcc5ed595cb1c6f8eb2e23f89c310d26fe35c6232c6378d9cb98a4e81d","signature":"d2e3a73d925b494d1b011f967d6bd39af7493b5b9bc9d0f092405ba1afc67612"},{"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,2],[48,3],[49,3],[52,4],[54,5],[46,6],[47,5]],"latestChangedDtsFile":"./dist/index.d.ts","version":"5.8.3"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
declare function createRepositoryInstance<I extends Record<string, any>>(definition: (infrastructure: I) => unknown, infrastructure: I): {
|
|
2
|
-
connect(): void;
|
|
3
|
-
disconnect(): void;
|
|
4
|
-
getReference(): unknown;
|
|
5
|
-
getConnections(): number;
|
|
6
|
-
};
|
|
7
|
-
export { createRepositoryInstance };
|
|
8
|
-
//# sourceMappingURL=repositoryInstance.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"repositoryInstance.d.ts","sourceRoot":"","sources":["../src/repositoryInstance.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,27 +0,0 @@
|
|
|
1
|
-
function createRepositoryInstance(definition, infrastructure) {
|
|
2
|
-
let reference = undefined;
|
|
3
|
-
let connections = 0;
|
|
4
|
-
return {
|
|
5
|
-
connect() {
|
|
6
|
-
if (connections === 0) {
|
|
7
|
-
reference = definition(infrastructure);
|
|
8
|
-
}
|
|
9
|
-
connections += 1;
|
|
10
|
-
},
|
|
11
|
-
disconnect() {
|
|
12
|
-
if (connections === 0)
|
|
13
|
-
return;
|
|
14
|
-
connections -= 1;
|
|
15
|
-
if (connections === 0) {
|
|
16
|
-
reference = undefined;
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
getReference() {
|
|
20
|
-
return reference;
|
|
21
|
-
},
|
|
22
|
-
getConnections() {
|
|
23
|
-
return connections;
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
export { createRepositoryInstance };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
function createRepositoryInstance<I extends Record<string, any>>(
|
|
2
|
-
definition: (infrastructure: I) => unknown,
|
|
3
|
-
infrastructure: I
|
|
4
|
-
) {
|
|
5
|
-
let reference = undefined as unknown;
|
|
6
|
-
let connections = 0;
|
|
7
|
-
return {
|
|
8
|
-
connect() {
|
|
9
|
-
if (connections === 0) {
|
|
10
|
-
reference = definition(infrastructure);
|
|
11
|
-
}
|
|
12
|
-
connections += 1;
|
|
13
|
-
},
|
|
14
|
-
disconnect() {
|
|
15
|
-
if (connections === 0) return;
|
|
16
|
-
connections -= 1;
|
|
17
|
-
if (connections === 0) {
|
|
18
|
-
reference = undefined;
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
getReference() {
|
|
22
|
-
return reference;
|
|
23
|
-
},
|
|
24
|
-
getConnections() {
|
|
25
|
-
return connections;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { createRepositoryInstance };
|