@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.
- package/package.json +4 -4
- package/API.md +0 -62
- package/GETTING_STARTED.md +0 -69
- package/build.js +0 -38
- package/docs/README.md +0 -74
- package/docs/TIMING_NODE_OPTIMIZATION.md +0 -207
- package/docs/TIMING_README.md +0 -170
- package/docs/docs.config.ts +0 -114
- package/docs/index.html +0 -26
- package/docs/package-lock.json +0 -5129
- package/docs/package.json +0 -34
- package/docs/public/404.html +0 -53
- package/docs/public/GETTING_STARTED.md +0 -69
- package/docs/public/README.md +0 -623
- package/docs/public/TIMING_NODE_OPTIMIZATION.md +0 -207
- package/docs/public/api.md +0 -62
- package/docs/public/client-api-overview.md +0 -137
- package/docs/public/configuration.md +0 -759
- package/docs/public/error-handling/README.md +0 -356
- package/docs/public/error-handling/network-errors.md +0 -485
- package/docs/public/examples/coordinates-example.ts +0 -253
- package/docs/public/examples/multi-level-keys.ts +0 -374
- package/docs/public/examples/registry-hub-coordinates-example.ts +0 -370
- package/docs/public/examples/registry-hub-types.ts +0 -437
- package/docs/public/examples/simple-example.ts +0 -250
- package/docs/public/examples-README.md +0 -241
- package/docs/public/fjell-icon.svg +0 -1
- package/docs/public/icon.png +0 -0
- package/docs/public/icon2.png +0 -0
- package/docs/public/memory-overhead.svg +0 -120
- package/docs/public/memory.md +0 -430
- package/docs/public/operations/README.md +0 -121
- package/docs/public/operations/all.md +0 -325
- package/docs/public/operations/create.md +0 -415
- package/docs/public/operations/get.md +0 -389
- package/docs/public/package.json +0 -63
- package/docs/public/pano.png +0 -0
- package/docs/public/pano2.png +0 -0
- package/docs/public/timing-range.svg +0 -176
- package/docs/public/timing.md +0 -483
- package/docs/timing-range.svg +0 -174
- package/docs/vitest.config.ts +0 -14
- package/examples/README.md +0 -241
- package/examples/coordinates-example.ts +0 -253
- package/examples/multi-level-keys.ts +0 -382
- package/examples/registry-hub-coordinates-example.ts +0 -370
- package/examples/registry-hub-types.ts +0 -437
- package/examples/registry-statistics-example.ts +0 -264
- package/examples/simple-example.ts +0 -250
- package/tsconfig.docs.json +0 -28
- package/vitest.config.ts +0 -22
package/examples/README.md
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
# Registry Examples
|
|
2
|
-
|
|
3
|
-
This directory contains examples demonstrating how to use the Registry with different key patterns and configurations.
|
|
4
|
-
|
|
5
|
-
## Examples
|
|
6
|
-
|
|
7
|
-
### 1. `simple-example.ts` ā **Start Here!**
|
|
8
|
-
**Perfect for beginners!** Demonstrates the simplest possible way to use the Registry:
|
|
9
|
-
- **No RegistryHub required** - just call `createRegistry()`
|
|
10
|
-
- **No scopes needed** - pass empty array `[]` or omit entirely
|
|
11
|
-
- **Basic dependency injection** - register and retrieve services
|
|
12
|
-
- **Service dependencies** - shows how services can depend on each other
|
|
13
|
-
|
|
14
|
-
Great for simple applications that just need basic dependency injection without complexity.
|
|
15
|
-
|
|
16
|
-
### 2. `multi-level-keys.ts`
|
|
17
|
-
**Advanced usage with scopes and multi-level keys!** Demonstrates how Registry supports hierarchical key type arrays:
|
|
18
|
-
- **Single level**: `['user']`, `['task']` - SQL vs NoSQL implementations
|
|
19
|
-
- **Two levels**: `['user', 'profile']` - S3 vs Local storage implementations
|
|
20
|
-
- **Three levels**: `['user', 'profile', 'preference']` - Redis implementation
|
|
21
|
-
- **Real scopes**: Production vs development environments
|
|
22
|
-
- **Multiple implementations**: Same interface, different backends
|
|
23
|
-
|
|
24
|
-
Shows how each key path maps to different implementations via scopes using the real library.
|
|
25
|
-
|
|
26
|
-
### 3. `registry-hub-types.ts` šļø **Enterprise Architecture**
|
|
27
|
-
**Large-scale application with service organization!** Demonstrates how RegistryHub manages multiple registries for different service types:
|
|
28
|
-
- **Service Categories**: Business logic, data access, infrastructure, communication
|
|
29
|
-
- **Type-based Organization**: Services organized by purpose and responsibility
|
|
30
|
-
- **Cross-Registry Workflows**: Services from different registries working together
|
|
31
|
-
- **Environment Configuration**: Production vs development implementations
|
|
32
|
-
- **Centralized Discovery**: Single hub for all service types
|
|
33
|
-
|
|
34
|
-
Perfect for enterprise applications that need clean separation of concerns and organized service architecture.
|
|
35
|
-
|
|
36
|
-
### 4. `registry-statistics-example.ts` š **Usage Analytics**
|
|
37
|
-
**Track and monitor registry usage patterns with scope-aware analytics!** Demonstrates advanced statistics tracking:
|
|
38
|
-
- **Scope-Aware Tracking**: Separate statistics for each kta + scopes combination
|
|
39
|
-
- **Total Call Monitoring**: Track overall `get()` method usage
|
|
40
|
-
- **Detailed Coordinate Records**: Individual tracking for each service/scope pair
|
|
41
|
-
- **Environment Analysis**: Aggregate statistics by environment (prod/dev)
|
|
42
|
-
- **Most/Least Used Services**: Identify usage patterns and bottlenecks
|
|
43
|
-
- **Immutable Statistics**: Safe access to tracking data without affecting internal state
|
|
44
|
-
- **Normalized Scope Handling**: Consistent tracking regardless of scope order
|
|
45
|
-
|
|
46
|
-
Perfect for monitoring, optimization, understanding service usage patterns, and analyzing environment-specific behavior in production applications.
|
|
47
|
-
|
|
48
|
-
## Key Concepts Demonstrated
|
|
49
|
-
|
|
50
|
-
### Simple Usage (simple-example.ts)
|
|
51
|
-
```typescript
|
|
52
|
-
// Import the real registry functionality
|
|
53
|
-
import { createRegistry, createInstance } from '../src/Registry';
|
|
54
|
-
|
|
55
|
-
// Create a registry - no RegistryHub needed!
|
|
56
|
-
const registry = createRegistry('app');
|
|
57
|
-
|
|
58
|
-
// Register a service - no scopes needed!
|
|
59
|
-
registry.createInstance(['logger'], [], (coordinate, context) => {
|
|
60
|
-
const service = new LoggerService();
|
|
61
|
-
const instance = createInstance(context.registry, coordinate);
|
|
62
|
-
(instance as any).log = service.log.bind(service);
|
|
63
|
-
return instance;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Get the service - no scopes needed!
|
|
67
|
-
const logger = registry.get(['logger']);
|
|
68
|
-
logger.log('Hello from the registry!');
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Multi-Level Key Arrays
|
|
72
|
-
```typescript
|
|
73
|
-
// Different key path levels
|
|
74
|
-
['user'] // ā UserService implementation
|
|
75
|
-
['user', 'profile'] // ā UserProfileService implementation
|
|
76
|
-
['user', 'profile', 'preference'] // ā UserPreferenceService implementation
|
|
77
|
-
['task'] // ā TaskService implementation
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### RegistryHub Usage (registry-hub-types.ts)
|
|
81
|
-
```typescript
|
|
82
|
-
// Import RegistryHub functionality
|
|
83
|
-
import { createRegistryHub } from '../src/RegistryHub';
|
|
84
|
-
import { createRegistry } from '../src/Registry';
|
|
85
|
-
|
|
86
|
-
// Create a hub to manage multiple registries
|
|
87
|
-
const hub = createRegistryHub();
|
|
88
|
-
|
|
89
|
-
// Create specialized registries for different service types
|
|
90
|
-
const servicesRegistry = createRegistry('services'); // Business logic
|
|
91
|
-
const dataRegistry = createRegistry('data'); // Data access
|
|
92
|
-
const infraRegistry = createRegistry('infrastructure'); // Infrastructure
|
|
93
|
-
const commRegistry = createRegistry('communication'); // External services
|
|
94
|
-
|
|
95
|
-
// Register all registries in the hub
|
|
96
|
-
hub.registerRegistry(servicesRegistry);
|
|
97
|
-
hub.registerRegistry(dataRegistry);
|
|
98
|
-
hub.registerRegistry(infraRegistry);
|
|
99
|
-
hub.registerRegistry(commRegistry);
|
|
100
|
-
|
|
101
|
-
// Register services by type and scope
|
|
102
|
-
servicesRegistry.createInstance(['auth'], ['prod'], (coordinate, context) => {
|
|
103
|
-
// JWT implementation for production
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
dataRegistry.createInstance(['user'], ['sql'], (coordinate, context) => {
|
|
107
|
-
// PostgreSQL implementation
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Retrieve services by type and scope through the hub
|
|
111
|
-
const prodAuth = hub.get('services', ['auth'], { scopes: ['prod'] });
|
|
112
|
-
const sqlUser = hub.get('data', ['user'], { scopes: ['sql'] });
|
|
113
|
-
const cache = hub.get('infrastructure', ['cache'], { scopes: ['dev'] });
|
|
114
|
-
const email = hub.get('communication', ['email'], { scopes: ['prod'] });
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### Scope-Based Implementation Selection
|
|
118
|
-
- Multiple implementations per key path
|
|
119
|
-
- Runtime selection via scopes
|
|
120
|
-
- Environment-based switching (prod/dev/test)
|
|
121
|
-
- Feature flags and A/B testing support
|
|
122
|
-
|
|
123
|
-
### Real-World Use Cases
|
|
124
|
-
- **Database Abstraction**: Different implementations for PostgreSQL, MongoDB, etc.
|
|
125
|
-
- **Environment Selection**: Different implementations for prod/dev
|
|
126
|
-
- **Testing**: Mock implementations with 'test' scope
|
|
127
|
-
- **Microservices**: Each key path represents a different service
|
|
128
|
-
- **Multi-Region**: Different implementations across regions
|
|
129
|
-
|
|
130
|
-
## Using the Registry
|
|
131
|
-
|
|
132
|
-
The registry provides a centralized way to manage instances in your application. Here are the main operations you can perform:
|
|
133
|
-
|
|
134
|
-
### Getting All Coordinates
|
|
135
|
-
|
|
136
|
-
You can retrieve a list of all coordinates currently registered in the registry:
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
import { createRegistry } from '@fjell/registry';
|
|
140
|
-
|
|
141
|
-
const registry = createRegistry('myRegistry');
|
|
142
|
-
|
|
143
|
-
// Register some instances...
|
|
144
|
-
registry.createInstance(['service'], ['production'], factory1);
|
|
145
|
-
registry.createInstance(['cache', 'redis'], ['development'], factory2);
|
|
146
|
-
|
|
147
|
-
// Get all coordinates
|
|
148
|
-
const coordinates = registry.getCoordinates();
|
|
149
|
-
console.log(`Found ${coordinates.length} registered coordinates:`);
|
|
150
|
-
coordinates.forEach(coord => {
|
|
151
|
-
console.log(`- ${coord.toString()}`);
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
This is useful for debugging, monitoring, or implementing discovery mechanisms in your application.
|
|
156
|
-
|
|
157
|
-
### Basic Instance Management
|
|
158
|
-
|
|
159
|
-
## Running Examples
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
# Start with the simple example (recommended)
|
|
163
|
-
npx tsx examples/simple-example.ts
|
|
164
|
-
|
|
165
|
-
# Run the multi-level keys example
|
|
166
|
-
npx tsx examples/multi-level-keys.ts
|
|
167
|
-
|
|
168
|
-
# Run the RegistryHub with service types example
|
|
169
|
-
npx tsx examples/registry-hub-types.ts
|
|
170
|
-
|
|
171
|
-
# Run the coordinate discovery and introspection example
|
|
172
|
-
npx tsx examples/coordinates-example.ts
|
|
173
|
-
|
|
174
|
-
# Run the RegistryHub cross-registry coordinate discovery example
|
|
175
|
-
npx tsx examples/registry-hub-coordinates-example.ts
|
|
176
|
-
|
|
177
|
-
# Run the registry statistics tracking example
|
|
178
|
-
npx tsx examples/registry-statistics-example.ts
|
|
179
|
-
|
|
180
|
-
# Or in Node.js
|
|
181
|
-
node -r esbuild-register examples/simple-example.ts
|
|
182
|
-
node -r esbuild-register examples/multi-level-keys.ts
|
|
183
|
-
node -r esbuild-register examples/registry-hub-types.ts
|
|
184
|
-
node -r esbuild-register examples/coordinates-example.ts
|
|
185
|
-
node -r esbuild-register examples/registry-hub-coordinates-example.ts
|
|
186
|
-
node -r esbuild-register examples/registry-statistics-example.ts
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Integration with Real Fjell Registry
|
|
190
|
-
|
|
191
|
-
Both examples now use the real library! In actual usage with the built package:
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
import { createRegistry, createInstance } from '@fjell/registry';
|
|
195
|
-
|
|
196
|
-
// Simple usage - no RegistryHub, no scopes
|
|
197
|
-
const registry = createRegistry('app');
|
|
198
|
-
|
|
199
|
-
registry.createInstance(['user'], [], (coordinate, context) => {
|
|
200
|
-
const service = new UserService();
|
|
201
|
-
const instance = createInstance(context.registry, coordinate);
|
|
202
|
-
(instance as any).save = service.save.bind(service);
|
|
203
|
-
return instance;
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
const user = registry.get(['user']);
|
|
207
|
-
|
|
208
|
-
// Advanced usage - with scopes for multiple implementations
|
|
209
|
-
registry.createInstance(['user'], ['sql', 'prod'], (coordinate, context) => {
|
|
210
|
-
const service = new SqlUserService();
|
|
211
|
-
const instance = createInstance(context.registry, coordinate);
|
|
212
|
-
(instance as any).save = service.save.bind(service);
|
|
213
|
-
return instance;
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const prodUser = registry.get(['user'], { scopes: ['prod'] });
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## When to Use What
|
|
220
|
-
|
|
221
|
-
**Use `simple-example.ts` approach when:**
|
|
222
|
-
- You're just getting started
|
|
223
|
-
- You have a simple application
|
|
224
|
-
- You don't need multiple implementations per service
|
|
225
|
-
- You want basic dependency injection
|
|
226
|
-
|
|
227
|
-
**Use `multi-level-keys.ts` approach when:**
|
|
228
|
-
- You need multiple implementations (prod/dev/test)
|
|
229
|
-
- You have complex service hierarchies
|
|
230
|
-
- You need environment-based switching
|
|
231
|
-
- You're building a large, complex application
|
|
232
|
-
|
|
233
|
-
**Use `registry-hub-types.ts` approach when:**
|
|
234
|
-
- You're building enterprise-scale applications
|
|
235
|
-
- You need to organize services by type/category
|
|
236
|
-
- You have multiple teams working on different service layers
|
|
237
|
-
- You want clean separation between business logic, data, and infrastructure
|
|
238
|
-
- You need centralized service discovery across service types
|
|
239
|
-
- You're implementing microservices or modular architecture
|
|
240
|
-
|
|
241
|
-
This approach provides the foundation for the Fjell library's architecture pattern with swappable implementations and enterprise-scale service organization.
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coordinates Discovery Example
|
|
3
|
-
*
|
|
4
|
-
* This example demonstrates how to use the getCoordinates() method to:
|
|
5
|
-
* - Discover all registered instances in a registry
|
|
6
|
-
* - Inspect coordinates and their scopes
|
|
7
|
-
* - Monitor registry state for debugging
|
|
8
|
-
* - Implement discovery mechanisms
|
|
9
|
-
*
|
|
10
|
-
* Run this example with: npx tsx examples/coordinates-example.ts
|
|
11
|
-
*
|
|
12
|
-
* Note: In a real application, import from the built package:
|
|
13
|
-
* import { createRegistry, createInstance } from '@fjell/registry';
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// Import the actual registry functionality
|
|
17
|
-
import { createRegistry } from '../src/Registry';
|
|
18
|
-
import { createInstance } from '../src/Instance';
|
|
19
|
-
|
|
20
|
-
// ===== Service Examples =====
|
|
21
|
-
|
|
22
|
-
class DatabaseService {
|
|
23
|
-
constructor(private type: string, private environment: string) { }
|
|
24
|
-
|
|
25
|
-
connect() {
|
|
26
|
-
console.log(`Connected to ${this.type} database in ${this.environment}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
getInfo() {
|
|
30
|
-
return `${this.type} (${this.environment})`;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class CacheService {
|
|
35
|
-
constructor(private type: string) { }
|
|
36
|
-
|
|
37
|
-
get(key: string) {
|
|
38
|
-
console.log(`Getting ${key} from ${this.type} cache`);
|
|
39
|
-
return `cached_${key}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getInfo() {
|
|
43
|
-
return this.type;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
class LoggingService {
|
|
48
|
-
constructor(private level: string) { }
|
|
49
|
-
|
|
50
|
-
log(message: string) {
|
|
51
|
-
console.log(`[${this.level.toUpperCase()}] ${message}`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getInfo() {
|
|
55
|
-
return `Logging at ${this.level} level`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// ===== Main Example =====
|
|
60
|
-
|
|
61
|
-
async function runCoordinatesExample() {
|
|
62
|
-
console.log('š Registry Coordinates Discovery Example\n');
|
|
63
|
-
|
|
64
|
-
// Step 1: Create a registry
|
|
65
|
-
console.log('1. Creating registry...');
|
|
66
|
-
const registry = createRegistry('services');
|
|
67
|
-
console.log(' ā
Registry created\n');
|
|
68
|
-
|
|
69
|
-
// Step 2: Register multiple instances with different scopes
|
|
70
|
-
console.log('2. Registering instances with various configurations...\n');
|
|
71
|
-
|
|
72
|
-
// Database services for different environments
|
|
73
|
-
registry.createInstance(
|
|
74
|
-
['database'],
|
|
75
|
-
['production', 'postgres'],
|
|
76
|
-
(coordinate, context) => {
|
|
77
|
-
const service = new DatabaseService('PostgreSQL', 'production');
|
|
78
|
-
const instance = createInstance(context.registry, coordinate);
|
|
79
|
-
(instance as any).connect = service.connect.bind(service);
|
|
80
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
81
|
-
return instance;
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
console.log(' ā
PostgreSQL database (production) registered');
|
|
85
|
-
|
|
86
|
-
registry.createInstance(
|
|
87
|
-
['database'],
|
|
88
|
-
['development', 'sqlite'],
|
|
89
|
-
(coordinate, context) => {
|
|
90
|
-
const service = new DatabaseService('SQLite', 'development');
|
|
91
|
-
const instance = createInstance(context.registry, coordinate);
|
|
92
|
-
(instance as any).connect = service.connect.bind(service);
|
|
93
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
94
|
-
return instance;
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
console.log(' ā
SQLite database (development) registered');
|
|
98
|
-
|
|
99
|
-
// Cache services
|
|
100
|
-
registry.createInstance(
|
|
101
|
-
['cache', 'redis'],
|
|
102
|
-
['production'],
|
|
103
|
-
(coordinate, context) => {
|
|
104
|
-
const service = new CacheService('Redis');
|
|
105
|
-
const instance = createInstance(context.registry, coordinate);
|
|
106
|
-
(instance as any).get = service.get.bind(service);
|
|
107
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
108
|
-
return instance;
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
console.log(' ā
Redis cache (production) registered');
|
|
112
|
-
|
|
113
|
-
registry.createInstance(
|
|
114
|
-
['cache', 'memory'],
|
|
115
|
-
['development', 'testing'],
|
|
116
|
-
(coordinate, context) => {
|
|
117
|
-
const service = new CacheService('In-Memory');
|
|
118
|
-
const instance = createInstance(context.registry, coordinate);
|
|
119
|
-
(instance as any).get = service.get.bind(service);
|
|
120
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
121
|
-
return instance;
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
console.log(' ā
Memory cache (development/testing) registered');
|
|
125
|
-
|
|
126
|
-
// Logging services
|
|
127
|
-
registry.createInstance(
|
|
128
|
-
['logging'],
|
|
129
|
-
['production'],
|
|
130
|
-
(coordinate, context) => {
|
|
131
|
-
const service = new LoggingService('error');
|
|
132
|
-
const instance = createInstance(context.registry, coordinate);
|
|
133
|
-
(instance as any).log = service.log.bind(service);
|
|
134
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
135
|
-
return instance;
|
|
136
|
-
}
|
|
137
|
-
);
|
|
138
|
-
console.log(' ā
Error logging (production) registered');
|
|
139
|
-
|
|
140
|
-
registry.createInstance(
|
|
141
|
-
['logging'],
|
|
142
|
-
['development'],
|
|
143
|
-
(coordinate, context) => {
|
|
144
|
-
const service = new LoggingService('debug');
|
|
145
|
-
const instance = createInstance(context.registry, coordinate);
|
|
146
|
-
(instance as any).log = service.log.bind(service);
|
|
147
|
-
(instance as any).getInfo = service.getInfo.bind(service);
|
|
148
|
-
return instance;
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
console.log(' ā
Debug logging (development) registered\n');
|
|
152
|
-
|
|
153
|
-
// Step 3: Demonstrate getCoordinates functionality
|
|
154
|
-
console.log('3. Discovering all registered coordinates...\n');
|
|
155
|
-
|
|
156
|
-
const coordinates = registry.getCoordinates();
|
|
157
|
-
console.log(`š Total registered coordinates: ${coordinates.length}\n`);
|
|
158
|
-
|
|
159
|
-
// Display all coordinates with their details
|
|
160
|
-
console.log('š Registered Coordinates:');
|
|
161
|
-
console.log('ā'.repeat(60));
|
|
162
|
-
coordinates.forEach((coord, index) => {
|
|
163
|
-
console.log(`${index + 1}. ${coord.toString()}`);
|
|
164
|
-
console.log(` Key Path: [${coord.kta.join(' ā ')}]`);
|
|
165
|
-
console.log(` Scopes: ${coord.scopes.length > 0 ? coord.scopes.join(', ') : 'none'}`);
|
|
166
|
-
console.log('');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
// Step 4: Demonstrate filtering and analysis
|
|
170
|
-
console.log('4. Analyzing coordinate patterns...\n');
|
|
171
|
-
|
|
172
|
-
// Group by environment
|
|
173
|
-
const byEnvironment = {
|
|
174
|
-
production: coordinates.filter(c => c.scopes.includes('production')),
|
|
175
|
-
development: coordinates.filter(c => c.scopes.includes('development')),
|
|
176
|
-
testing: coordinates.filter(c => c.scopes.includes('testing')),
|
|
177
|
-
unscoped: coordinates.filter(c => c.scopes.length === 0)
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
console.log('š¢ Coordinates by Environment:');
|
|
181
|
-
Object.entries(byEnvironment).forEach(([env, coords]) => {
|
|
182
|
-
if (coords.length > 0) {
|
|
183
|
-
console.log(` ${env}: ${coords.length} instance(s)`);
|
|
184
|
-
coords.forEach(coord => {
|
|
185
|
-
console.log(` - ${coord.kta.join('.')}`);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
// Group by service type (first element of kta)
|
|
191
|
-
const byServiceType = coordinates.reduce((acc, coord) => {
|
|
192
|
-
const serviceType = coord.kta[0];
|
|
193
|
-
if (!acc[serviceType]) acc[serviceType] = [];
|
|
194
|
-
acc[serviceType].push(coord);
|
|
195
|
-
return acc;
|
|
196
|
-
}, {} as Record<string, typeof coordinates>);
|
|
197
|
-
|
|
198
|
-
console.log('\nš§ Coordinates by Service Type:');
|
|
199
|
-
Object.entries(byServiceType).forEach(([type, coords]) => {
|
|
200
|
-
console.log(` ${type}: ${coords.length} instance(s)`);
|
|
201
|
-
coords.forEach(coord => {
|
|
202
|
-
const scopeInfo = coord.scopes.length > 0 ? ` (${coord.scopes.join(', ')})` : '';
|
|
203
|
-
console.log(` - ${coord.kta.join('.')}${scopeInfo}`);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// Step 5: Demonstrate practical usage scenarios
|
|
208
|
-
console.log('\n5. Practical usage scenarios...\n');
|
|
209
|
-
|
|
210
|
-
// Scenario 1: Health check - verify all expected services are registered
|
|
211
|
-
console.log('š„ Health Check Example:');
|
|
212
|
-
const expectedServices = ['database', 'cache', 'logging'];
|
|
213
|
-
const registeredServices = [...new Set(coordinates.map(c => c.kta[0]))];
|
|
214
|
-
|
|
215
|
-
expectedServices.forEach(service => {
|
|
216
|
-
const isRegistered = registeredServices.includes(service);
|
|
217
|
-
console.log(` ${service}: ${isRegistered ? 'ā
Registered' : 'ā Missing'}`);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Scenario 2: Environment validation
|
|
221
|
-
console.log('\nš Environment Validation:');
|
|
222
|
-
const productionServices = coordinates.filter(c => c.scopes.includes('production'));
|
|
223
|
-
const developmentServices = coordinates.filter(c => c.scopes.includes('development'));
|
|
224
|
-
|
|
225
|
-
console.log(` Production environment has ${productionServices.length} service(s) registered`);
|
|
226
|
-
console.log(` Development environment has ${developmentServices.length} service(s) registered`);
|
|
227
|
-
|
|
228
|
-
// Scenario 3: Discovery mechanism
|
|
229
|
-
console.log('\nš Service Discovery Example:');
|
|
230
|
-
console.log(' Available cache services:');
|
|
231
|
-
coordinates
|
|
232
|
-
.filter(c => c.kta.includes('cache'))
|
|
233
|
-
.forEach(coord => {
|
|
234
|
-
console.log(` - ${coord.kta.join('.')} (${coord.scopes.join(', ') || 'any scope'})`);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
console.log('\n⨠Coordinates discovery example completed!');
|
|
238
|
-
|
|
239
|
-
return {
|
|
240
|
-
totalCoordinates: coordinates.length,
|
|
241
|
-
coordinates: coordinates,
|
|
242
|
-
byEnvironment,
|
|
243
|
-
byServiceType
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// Export for testing
|
|
248
|
-
export { runCoordinatesExample };
|
|
249
|
-
|
|
250
|
-
// Run the example if this file is executed directly
|
|
251
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
252
|
-
runCoordinatesExample().catch(console.error);
|
|
253
|
-
}
|