@fjell/registry 4.4.52 โ†’ 4.4.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +4 -4
  2. package/API.md +0 -62
  3. package/GETTING_STARTED.md +0 -69
  4. package/build.js +0 -38
  5. package/docs/README.md +0 -74
  6. package/docs/TIMING_NODE_OPTIMIZATION.md +0 -207
  7. package/docs/TIMING_README.md +0 -170
  8. package/docs/docs.config.ts +0 -114
  9. package/docs/index.html +0 -26
  10. package/docs/package-lock.json +0 -5129
  11. package/docs/package.json +0 -34
  12. package/docs/public/404.html +0 -53
  13. package/docs/public/GETTING_STARTED.md +0 -69
  14. package/docs/public/README.md +0 -623
  15. package/docs/public/TIMING_NODE_OPTIMIZATION.md +0 -207
  16. package/docs/public/api.md +0 -62
  17. package/docs/public/client-api-overview.md +0 -137
  18. package/docs/public/configuration.md +0 -759
  19. package/docs/public/error-handling/README.md +0 -356
  20. package/docs/public/error-handling/network-errors.md +0 -485
  21. package/docs/public/examples/coordinates-example.ts +0 -253
  22. package/docs/public/examples/multi-level-keys.ts +0 -374
  23. package/docs/public/examples/registry-hub-coordinates-example.ts +0 -370
  24. package/docs/public/examples/registry-hub-types.ts +0 -437
  25. package/docs/public/examples/simple-example.ts +0 -250
  26. package/docs/public/examples-README.md +0 -241
  27. package/docs/public/fjell-icon.svg +0 -1
  28. package/docs/public/icon.png +0 -0
  29. package/docs/public/icon2.png +0 -0
  30. package/docs/public/memory-overhead.svg +0 -120
  31. package/docs/public/memory.md +0 -430
  32. package/docs/public/operations/README.md +0 -121
  33. package/docs/public/operations/all.md +0 -325
  34. package/docs/public/operations/create.md +0 -415
  35. package/docs/public/operations/get.md +0 -389
  36. package/docs/public/package.json +0 -63
  37. package/docs/public/pano.png +0 -0
  38. package/docs/public/pano2.png +0 -0
  39. package/docs/public/timing-range.svg +0 -176
  40. package/docs/public/timing.md +0 -483
  41. package/docs/timing-range.svg +0 -174
  42. package/docs/vitest.config.ts +0 -14
  43. package/examples/README.md +0 -241
  44. package/examples/coordinates-example.ts +0 -253
  45. package/examples/multi-level-keys.ts +0 -382
  46. package/examples/registry-hub-coordinates-example.ts +0 -370
  47. package/examples/registry-hub-types.ts +0 -437
  48. package/examples/registry-statistics-example.ts +0 -264
  49. package/examples/simple-example.ts +0 -250
  50. package/tsconfig.docs.json +0 -28
  51. package/vitest.config.ts +0 -22
@@ -1,437 +0,0 @@
1
- #!/usr/bin/env npx tsx
2
-
3
- /**
4
- * RegistryHub with Different Service Types Example
5
- *
6
- * This example demonstrates how to use a RegistryHub to organize and retrieve
7
- * services of different types. Perfect for large applications that need to
8
- * categorize services by their purpose (data access, business logic, infrastructure, etc.)
9
- */
10
-
11
- import { createRegistryHub } from '../src/RegistryHub';
12
- import { createRegistry } from '../src/Registry';
13
- import { createInstance } from '../src/Instance';
14
-
15
- // ===================================================================
16
- // Service Interfaces - Different types of services
17
- // ===================================================================
18
-
19
- interface AuthService {
20
- login(username: string, password: string): Promise<string>;
21
- logout(token: string): Promise<void>;
22
- validateToken(token: string): boolean;
23
- }
24
-
25
- interface UserRepository {
26
- findById(id: string): Promise<any>;
27
- save(user: any): Promise<void>;
28
- delete(id: string): Promise<void>;
29
- }
30
-
31
- interface CacheService {
32
- get(key: string): Promise<any>;
33
- set(key: string, value: any, ttl?: number): Promise<void>;
34
- invalidate(key: string): Promise<void>;
35
- }
36
-
37
- interface EmailService {
38
- sendEmail(to: string, subject: string, body: string): Promise<boolean>;
39
- sendTemplate(template: string, data: any): Promise<boolean>;
40
- }
41
-
42
- interface LoggerService {
43
- info(message: string): void;
44
- error(message: string, error?: Error): void;
45
- debug(message: string): void;
46
- }
47
-
48
- // ===================================================================
49
- // Service Implementations - Multiple implementations per type
50
- // ===================================================================
51
-
52
- class JwtAuthService implements AuthService {
53
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
54
- async login(username: string, password: string): Promise<string> {
55
- console.log(`๐Ÿ” JWT Auth: Logging in ${username}`);
56
- return `jwt-token-${username}-${Date.now()}`;
57
- }
58
-
59
- async logout(token: string): Promise<void> {
60
- console.log(`๐Ÿ” JWT Auth: Logging out token ${token.substring(0, 10)}...`);
61
- }
62
-
63
- validateToken(token: string): boolean {
64
- console.log(`๐Ÿ” JWT Auth: Validating token ${token.substring(0, 10)}...`);
65
- return token.startsWith('jwt-token-');
66
- }
67
- }
68
-
69
- class OAuth2AuthService implements AuthService {
70
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
- async login(username: string, password: string): Promise<string> {
72
- console.log(`๐Ÿ”’ OAuth2 Auth: Logging in ${username}`);
73
- return `oauth2-token-${username}-${Date.now()}`;
74
- }
75
-
76
- async logout(token: string): Promise<void> {
77
- console.log(`๐Ÿ”’ OAuth2 Auth: Logging out token ${token.substring(0, 10)}...`);
78
- }
79
-
80
- validateToken(token: string): boolean {
81
- console.log(`๐Ÿ”’ OAuth2 Auth: Validating token ${token.substring(0, 10)}...`);
82
- return token.startsWith('oauth2-token-');
83
- }
84
- }
85
-
86
- class PostgreSqlUserRepository implements UserRepository {
87
- async findById(id: string): Promise<any> {
88
- console.log(`๐Ÿ˜ PostgreSQL: Finding user ${id}`);
89
- return { id, name: `User ${id}`, source: 'postgresql' };
90
- }
91
-
92
- async save(user: any): Promise<void> {
93
- console.log(`๐Ÿ˜ PostgreSQL: Saving user ${user.id}`);
94
- }
95
-
96
- async delete(id: string): Promise<void> {
97
- console.log(`๐Ÿ˜ PostgreSQL: Deleting user ${id}`);
98
- }
99
- }
100
-
101
- class MongoUserRepository implements UserRepository {
102
- async findById(id: string): Promise<any> {
103
- console.log(`๐Ÿƒ MongoDB: Finding user ${id}`);
104
- return { id, name: `User ${id}`, source: 'mongodb' };
105
- }
106
-
107
- async save(user: any): Promise<void> {
108
- console.log(`๐Ÿƒ MongoDB: Saving user ${user.id}`);
109
- }
110
-
111
- async delete(id: string): Promise<void> {
112
- console.log(`๐Ÿƒ MongoDB: Deleting user ${id}`);
113
- }
114
- }
115
-
116
- class RedisCacheService implements CacheService {
117
- async get(key: string): Promise<any> {
118
- console.log(`๐Ÿ”ด Redis Cache: Getting ${key}`);
119
- return `cached-value-${key}`;
120
- }
121
-
122
- async set(key: string, value: any, ttl?: number): Promise<void> {
123
- console.log(`๐Ÿ”ด Redis Cache: Setting ${key} (TTL: ${ttl || 'none'})`);
124
- }
125
-
126
- async invalidate(key: string): Promise<void> {
127
- console.log(`๐Ÿ”ด Redis Cache: Invalidating ${key}`);
128
- }
129
- }
130
-
131
- class MemoryCacheService implements CacheService {
132
- private cache = new Map<string, any>();
133
-
134
- async get(key: string): Promise<any> {
135
- console.log(`๐Ÿ’พ Memory Cache: Getting ${key}`);
136
- return this.cache.get(key) || null;
137
- }
138
-
139
- async set(key: string, value: any, ttl?: number): Promise<void> {
140
- console.log(`๐Ÿ’พ Memory Cache: Setting ${key} (TTL: ${ttl || 'none'})`);
141
- this.cache.set(key, value);
142
- }
143
-
144
- async invalidate(key: string): Promise<void> {
145
- console.log(`๐Ÿ’พ Memory Cache: Invalidating ${key}`);
146
- this.cache.delete(key);
147
- }
148
- }
149
-
150
- class SmtpEmailService implements EmailService {
151
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
152
- async sendEmail(to: string, subject: string, body: string): Promise<boolean> {
153
- console.log(`๐Ÿ“ง SMTP Email: Sending to ${to} - ${subject}`);
154
- return true;
155
- }
156
-
157
- async sendTemplate(template: string, data: any): Promise<boolean> {
158
- console.log(`๐Ÿ“ง SMTP Email: Sending template ${template} with data:`, data);
159
- return true;
160
- }
161
- }
162
-
163
- class SendGridEmailService implements EmailService {
164
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
165
- async sendEmail(to: string, subject: string, body: string): Promise<boolean> {
166
- console.log(`๐Ÿ“จ SendGrid Email: Sending to ${to} - ${subject}`);
167
- return true;
168
- }
169
-
170
- async sendTemplate(template: string, data: any): Promise<boolean> {
171
- console.log(`๐Ÿ“จ SendGrid Email: Sending template ${template} with data:`, data);
172
- return true;
173
- }
174
- }
175
-
176
- class ConsoleLoggerService implements LoggerService {
177
- info(message: string): void {
178
- console.log(`โ„น๏ธ INFO: ${message}`);
179
- }
180
-
181
- error(message: string, error?: Error): void {
182
- console.log(`โŒ ERROR: ${message}`, error);
183
- }
184
-
185
- debug(message: string): void {
186
- console.log(`๐Ÿ› DEBUG: ${message}`);
187
- }
188
- }
189
-
190
- class FileLoggerService implements LoggerService {
191
- info(message: string): void {
192
- console.log(`๐Ÿ“ FILE INFO: ${message}`);
193
- }
194
-
195
- error(message: string, error?: Error): void {
196
- console.log(`๐Ÿ“ FILE ERROR: ${message}`, error);
197
- }
198
-
199
- debug(message: string): void {
200
- console.log(`๐Ÿ“ FILE DEBUG: ${message}`);
201
- }
202
- }
203
-
204
- // ===================================================================
205
- // Main Example
206
- // ===================================================================
207
-
208
- async function demonstrateRegistryHub() {
209
- console.log('๐Ÿš€ Registry Hub with Different Service Types Example\n');
210
-
211
- // ================================================================
212
- // Step 1: Create the RegistryHub
213
- // ================================================================
214
- console.log('1๏ธโƒฃ Creating RegistryHub...');
215
- const hub = createRegistryHub();
216
-
217
- // ================================================================
218
- // Step 2: Create different registries for different service types
219
- // ================================================================
220
- console.log('\n2๏ธโƒฃ Creating specialized registries...');
221
-
222
- // Business logic services
223
- const servicesRegistry = createRegistry('services');
224
- hub.registerRegistry(servicesRegistry);
225
-
226
- // Data access layer
227
- const dataRegistry = createRegistry('data');
228
- hub.registerRegistry(dataRegistry);
229
-
230
- // Infrastructure services
231
- const infraRegistry = createRegistry('infrastructure');
232
- hub.registerRegistry(infraRegistry);
233
-
234
- // Communication services
235
- const communicationRegistry = createRegistry('communication');
236
- hub.registerRegistry(communicationRegistry);
237
-
238
- console.log('โœ… Created registries:', hub.getRegisteredTypes().join(', '));
239
-
240
- // ================================================================
241
- // Step 3: Register services in their appropriate registries
242
- // ================================================================
243
- console.log('\n3๏ธโƒฃ Registering services by type and scope...');
244
-
245
- // SERVICES REGISTRY - Business logic with different implementations by environment
246
- servicesRegistry.createInstance(['auth'], ['prod'], (coordinate, context) => {
247
- const service = new JwtAuthService();
248
- const instance = createInstance(context.registry, coordinate);
249
- (instance as any).login = service.login.bind(service);
250
- (instance as any).logout = service.logout.bind(service);
251
- (instance as any).validateToken = service.validateToken.bind(service);
252
- return instance;
253
- });
254
-
255
- servicesRegistry.createInstance(['auth'], ['dev'], (coordinate, context) => {
256
- const service = new OAuth2AuthService();
257
- const instance = createInstance(context.registry, coordinate);
258
- (instance as any).login = service.login.bind(service);
259
- (instance as any).logout = service.logout.bind(service);
260
- (instance as any).validateToken = service.validateToken.bind(service);
261
- return instance;
262
- });
263
-
264
- // DATA REGISTRY - Data access with different backends
265
- dataRegistry.createInstance(['user'], ['sql'], (coordinate, context) => {
266
- const service = new PostgreSqlUserRepository();
267
- const instance = createInstance(context.registry, coordinate);
268
- (instance as any).findById = service.findById.bind(service);
269
- (instance as any).save = service.save.bind(service);
270
- (instance as any).delete = service.delete.bind(service);
271
- return instance;
272
- });
273
-
274
- dataRegistry.createInstance(['user'], ['nosql'], (coordinate, context) => {
275
- const service = new MongoUserRepository();
276
- const instance = createInstance(context.registry, coordinate);
277
- (instance as any).findById = service.findById.bind(service);
278
- (instance as any).save = service.save.bind(service);
279
- (instance as any).delete = service.delete.bind(service);
280
- return instance;
281
- });
282
-
283
- // INFRASTRUCTURE REGISTRY - Infrastructure services
284
- infraRegistry.createInstance(['cache'], ['prod'], (coordinate, context) => {
285
- const service = new RedisCacheService();
286
- const instance = createInstance(context.registry, coordinate);
287
- (instance as any).get = service.get.bind(service);
288
- (instance as any).set = service.set.bind(service);
289
- (instance as any).invalidate = service.invalidate.bind(service);
290
- return instance;
291
- });
292
-
293
- infraRegistry.createInstance(['cache'], ['dev'], (coordinate, context) => {
294
- const service = new MemoryCacheService();
295
- const instance = createInstance(context.registry, coordinate);
296
- (instance as any).get = service.get.bind(service);
297
- (instance as any).set = service.set.bind(service);
298
- (instance as any).invalidate = service.invalidate.bind(service);
299
- return instance;
300
- });
301
-
302
- infraRegistry.createInstance(['logger'], ['prod'], (coordinate, context) => {
303
- const service = new FileLoggerService();
304
- const instance = createInstance(context.registry, coordinate);
305
- (instance as any).info = service.info.bind(service);
306
- (instance as any).error = service.error.bind(service);
307
- (instance as any).debug = service.debug.bind(service);
308
- return instance;
309
- });
310
-
311
- infraRegistry.createInstance(['logger'], ['dev'], (coordinate, context) => {
312
- const service = new ConsoleLoggerService();
313
- const instance = createInstance(context.registry, coordinate);
314
- (instance as any).info = service.info.bind(service);
315
- (instance as any).error = service.error.bind(service);
316
- (instance as any).debug = service.debug.bind(service);
317
- return instance;
318
- });
319
-
320
- // COMMUNICATION REGISTRY - External communication services
321
- communicationRegistry.createInstance(['email'], ['prod'], (coordinate, context) => {
322
- const service = new SendGridEmailService();
323
- const instance = createInstance(context.registry, coordinate);
324
- (instance as any).sendEmail = service.sendEmail.bind(service);
325
- (instance as any).sendTemplate = service.sendTemplate.bind(service);
326
- return instance;
327
- });
328
-
329
- communicationRegistry.createInstance(['email'], ['dev'], (coordinate, context) => {
330
- const service = new SmtpEmailService();
331
- const instance = createInstance(context.registry, coordinate);
332
- (instance as any).sendEmail = service.sendEmail.bind(service);
333
- (instance as any).sendTemplate = service.sendTemplate.bind(service);
334
- return instance;
335
- });
336
-
337
- console.log('โœ… All services registered successfully');
338
-
339
- // ================================================================
340
- // Step 4: Retrieve services by type and demonstrate usage
341
- // ================================================================
342
- console.log('\n4๏ธโƒฃ Retrieving services by type...\n');
343
-
344
- // Production environment setup
345
- console.log('๐Ÿญ PRODUCTION ENVIRONMENT:');
346
- console.log('โ”€'.repeat(50));
347
-
348
- const prodAuth = hub.get('services', ['auth'], { scopes: ['prod'] }) as any;
349
- const sqlUserRepo = hub.get('data', ['user'], { scopes: ['sql'] }) as any;
350
- const prodCache = hub.get('infrastructure', ['cache'], { scopes: ['prod'] }) as any;
351
- const prodLogger = hub.get('infrastructure', ['logger'], { scopes: ['prod'] }) as any;
352
- const prodEmail = hub.get('communication', ['email'], { scopes: ['prod'] }) as any;
353
-
354
- // Demonstrate production workflow
355
- const token = await prodAuth.login('john_doe', 'password123');
356
- console.log(`โœ… Production token received: ${token.substring(0, 20)}...`);
357
- const user = await sqlUserRepo.findById('user123');
358
- await prodCache.set('user:user123', user, 3600);
359
- prodLogger.info('User logged in successfully');
360
- await prodEmail.sendEmail('john@example.com', 'Welcome!', 'Welcome to our service!');
361
-
362
- console.log('\n๐Ÿงช DEVELOPMENT ENVIRONMENT:');
363
- console.log('โ”€'.repeat(50));
364
-
365
- const devAuth = hub.get('services', ['auth'], { scopes: ['dev'] }) as any;
366
- const mongoUserRepo = hub.get('data', ['user'], { scopes: ['nosql'] }) as any;
367
- const devCache = hub.get('infrastructure', ['cache'], { scopes: ['dev'] }) as any;
368
- const devLogger = hub.get('infrastructure', ['logger'], { scopes: ['dev'] }) as any;
369
- const devEmail = hub.get('communication', ['email'], { scopes: ['dev'] }) as any;
370
-
371
- // Demonstrate development workflow
372
- const devToken = await devAuth.login('jane_doe', 'devpassword');
373
- console.log(`โœ… Development token received: ${devToken.substring(0, 20)}...`);
374
- const devUser = await mongoUserRepo.findById('user456');
375
- await devCache.set('user:user456', devUser);
376
- devLogger.debug('Development user logged in');
377
- await devEmail.sendTemplate('welcome', { name: 'Jane', email: 'jane@example.com' });
378
-
379
- // ================================================================
380
- // Step 5: Demonstrate cross-registry service interactions
381
- // ================================================================
382
- console.log('\n5๏ธโƒฃ Cross-registry service interactions...\n');
383
-
384
- // Get services from different registries and show they can work together
385
- const logger = hub.get('infrastructure', ['logger'], { scopes: ['dev'] }) as any;
386
- const cache = hub.get('infrastructure', ['cache'], { scopes: ['dev'] }) as any;
387
- const userRepo = hub.get('data', ['user'], { scopes: ['nosql'] }) as any;
388
- const auth = hub.get('services', ['auth'], { scopes: ['dev'] }) as any;
389
-
390
- logger.info('Starting complex workflow...');
391
-
392
- // Simulate a complex workflow using services from different registries
393
- const workflowToken = await auth.login('workflow_user', 'workflow_pass');
394
- logger.info(`User authenticated for workflow with token: ${workflowToken.substring(0, 15)}...`);
395
-
396
- const workflowUser = await userRepo.findById('workflow123');
397
- logger.info('User data retrieved');
398
-
399
- await cache.set('workflow:user123', workflowUser, 1800);
400
- logger.info('User data cached');
401
-
402
- const cachedUser = await cache.get('workflow:user123');
403
- logger.info(`Retrieved user from cache: ${JSON.stringify(cachedUser).substring(0, 50)}...`);
404
-
405
- // ================================================================
406
- // Step 6: Show registry type management
407
- // ================================================================
408
- console.log('\n6๏ธโƒฃ Registry management...\n');
409
-
410
- console.log('๐Ÿ“‹ Available registry types:', hub.getRegisteredTypes());
411
-
412
- // Get specific registries for direct access if needed
413
- const servicesReg = hub.getRegistry('services');
414
- const dataReg = hub.getRegistry('data');
415
-
416
- console.log('๐Ÿ”ง Direct registry access available for:',
417
- servicesReg ? 'services' : 'none',
418
- dataReg ? 'data' : 'none'
419
- );
420
-
421
- console.log('\nโœจ RegistryHub example completed successfully!');
422
- console.log('\n๐Ÿ“š Key Benefits Demonstrated:');
423
- console.log(' โ€ข Service organization by type/category');
424
- console.log(' โ€ข Environment-specific implementations');
425
- console.log(' โ€ข Clean separation of concerns');
426
- console.log(' โ€ข Centralized service discovery');
427
- console.log(' โ€ข Easy testing with different implementations');
428
- }
429
-
430
- // Run the example when executed directly
431
- if (typeof process !== 'undefined' && process.argv?.[1]?.includes('registry-hub-types')) {
432
- demonstrateRegistryHub().catch(console.error);
433
- }
434
-
435
- export default {
436
- demonstrateRegistryHub
437
- };