@owlmeans/context 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,750 +1,92 @@
1
1
  # @owlmeans/context
2
2
 
3
- The **@owlmeans/context** package provides dependency management for OwlMeans Common libraries, specifically designed for fullstack microservices and microclients development.
3
+ Lightweight dependency injection and service lifecycle management for fullstack OwlMeans applications.
4
4
 
5
- ## Purpose
5
+ ## Overview
6
6
 
7
- This package serves as a foundational dependency injection and management system that enables:
7
+ - Context holds services, modules, and resources; passed top-down through the app
8
+ - Services are registered by alias and retrieved via `context.service(alias)`
9
+ - Supports layered contexts (System → Global → Service → Entity → User) for multi-tenant apps
10
+ - Route constants (`ROOT`, `HOME`, `GUEST`, `BASE`) are used by the module system across all packages
8
11
 
9
- - **Service Registration and Resolution**: Register and access services across different application layers
10
- - **Module Management**: Handle URL units that declare routes and nesting for both frontend and backend
11
- - **Resource Management**: Manage data sources and external resources with proper initialization
12
- - **Middleware System**: Apply cross-cutting concerns at different stages of the application lifecycle
13
- - **Multi-layer Architecture**: Support hierarchical layers (System, Global, Service, Entity, User) for complex applications
12
+ ## Installation
14
13
 
15
- ## Key Concepts
16
-
17
- ### Context
18
- A context acts as an application instance that manages the lifecycle and dependencies of services, modules, and resources. Multiple contexts can exist within one application with different capabilities.
19
-
20
- ### Layers
21
- The package supports a hierarchical layer system:
22
- - **System**: System-wide components
23
- - **Global**: Global application components
24
- - **Service**: Service-specific components
25
- - **Entity**: Entity-specific components
26
- - **User**: User-specific components
27
-
28
- ### Modules
29
- In the context of OwlMeans Common libraries, a "module" is not a programmatic module but a URL unit in the system. Modules allow you to:
30
- - Declare URLs and nesting structure
31
- - Transform URLs to routes and attach handlers on the backend
32
- - Specify which components to render on the frontend
33
- - Generate final URLs for navigation or API calls
34
- - Maintain a single source of truth for all possible routes
35
-
36
- ### Services
37
- Services are components that provide functionality and can be initialized either immediately or lazily.
38
-
39
- ### Resources
40
- Resources are components that provide data or external functionality and can be initialized when needed.
41
-
42
- ### Middlewares
43
- Middlewares are components that can be applied at different stages of the context lifecycle to provide cross-cutting functionality.
44
-
45
- ## API Reference
46
-
47
- ### Factory Functions
48
-
49
- The package uses factory functions instead of constructors for object creation:
50
-
51
- #### `makeBasicContext<C extends BasicConfig>(cfg: C): BasicContext<C>`
52
-
53
- Creates a basic context instance.
54
-
55
- ```typescript
56
- import { makeBasicContext, makeBasicConfig, AppType } from '@owlmeans/context'
57
-
58
- const config = makeBasicConfig(AppType.Backend, 'my-service')
59
- const context = makeBasicContext(config)
14
+ ```bash
15
+ bun add @owlmeans/context
60
16
  ```
61
17
 
62
- #### `makeBasicConfig<C extends BasicConfig>(type: AppType, service: string, cfg?: Partial<C>): C`
18
+ ## Usage
63
19
 
64
- Creates a basic configuration object.
65
-
66
- **Parameters:**
67
- - `type`: Application type (Frontend or Backend)
68
- - `service`: Service name
69
- - `cfg`: Additional configuration options
70
-
71
- ```typescript
72
- import { makeBasicConfig, AppType, Layer } from '@owlmeans/context'
73
-
74
- const config = makeBasicConfig(AppType.Frontend, 'web-client', {
75
- layer: Layer.Service,
76
- debug: { all: true }
77
- })
78
- ```
79
-
80
- #### `createService<S extends InitializedService>(alias: string, service: Partial<S>, init?: InitMethod<S>): S`
81
-
82
- Creates a service that initializes immediately.
20
+ Creating and registering a service:
83
21
 
84
22
  ```typescript
85
23
  import { createService } from '@owlmeans/context'
86
24
 
87
- const myService = createService('my-service', {
88
- // service implementation
89
- }, (service) => async () => {
90
- // initialization logic
91
- console.log('Service initialized')
92
- service.initialized = true
93
- })
94
- ```
95
-
96
- #### `createLazyService<S extends LazyService>(alias: string, service: Partial<S>, init?: InitMethod<S>): S`
97
-
98
- Creates a service that initializes only when first accessed.
99
-
100
- ```typescript
101
- import { createLazyService } from '@owlmeans/context'
102
-
103
- const lazyService = createLazyService('lazy-service', {
104
- // service implementation
105
- }, (service) => async () => {
106
- // lazy initialization logic
107
- console.log('Lazy service initialized')
108
- service.initialized = true
109
- })
110
- ```
111
-
112
- #### `appendContextual<T extends Contextual>(alias: string, contextual: Partial<T>): T`
113
-
114
- Helps make objects contextual by adding context management capabilities.
115
-
116
- ```typescript
117
- import { appendContextual } from '@owlmeans/context'
118
-
119
- const contextualObject = appendContextual('my-object', {
120
- // object implementation
121
- })
122
- ```
123
-
124
- ### Core Interfaces
125
-
126
- #### `BasicContext<C extends BasicConfig>`
127
-
128
- The main context interface that provides comprehensive dependency management. Each method serves a specific purpose in the context lifecycle and dependency resolution:
129
-
130
- ```typescript
131
- interface BasicContext<C extends BasicConfig> {
132
- cfg: C
133
- stage: ContextStage
134
-
135
- // Lifecycle methods
136
- waitForConfigured(): Promise<boolean>
137
- waitForInitialized(): Promise<boolean>
138
- configure<T extends BasicContext<C>>(): T
139
- init<T extends BasicContext<C>>(): Promise<T>
140
-
141
- // Registration methods
142
- registerService<T extends BasicContext<C>>(service: Service): T
143
- registerModule<T extends BasicContext<C>>(module: BasicModule): T
144
- registerModules<T extends BasicContext<C>>(modules: BasicModule[]): T
145
- registerResource<T extends BasicContext<C>>(resource: BasicResource): T
146
- registerMiddleware<T extends BasicContext<C>>(middleware: Middleware): T
147
-
148
- // Access methods
149
- service<T extends Service>(alias: string): T
150
- module<T extends BasicModule>(alias: string): T
151
- resource<T extends BasicResource>(alias: string): T
152
- modules<T extends BasicModule>(): T[]
153
-
154
- // Utility methods
155
- hasResource(alias: string): boolean
156
- hasService(alias: string): boolean
157
-
158
- get config(): Promise<C>
159
- }
160
- ```
161
-
162
- ### Context Methods Detailed Reference
163
-
164
- #### Lifecycle Methods
165
-
166
- **`waitForConfigured(): Promise<boolean>`**
167
- - **Purpose**: Returns a promise that resolves when the context has completed its configuration stage
168
- - **Usage**: Useful for waiting for configuration to complete before proceeding
169
- - **Returns**: Promise that resolves to `true` when configuration is complete
170
-
171
- **`waitForInitialized(): Promise<boolean>`**
172
- - **Purpose**: Returns a promise that resolves when the context has completed initialization and reached the Ready stage
173
- - **Usage**: Essential for ensuring all services and resources are initialized before use
174
- - **Returns**: Promise that resolves to `true` when initialization is complete
175
-
176
- **`configure<T extends BasicContext<C>>(): T`**
177
- - **Purpose**: Transitions the context from Configuration stage to Loading stage
178
- - **Behavior**: Applies configuration middlewares and prepares the context for initialization
179
- - **Usage**: Must be called after registering all components and before `init()`
180
- - **Returns**: The context instance for method chaining
181
-
182
- **`init<T extends BasicContext<C>>(): Promise<T>`**
183
- - **Purpose**: Initializes all registered services and resources, transitioning context to Ready stage
184
- - **Behavior**:
185
- - Executes `init()` methods on all registered services
186
- - Initializes all resources according to their layer availability
187
- - Applies loading and ready stage middlewares
188
- - Marks context as ready for use
189
- - **Usage**: Must be called after `configure()` to make the context operational
190
- - **Returns**: Promise that resolves to the initialized context instance
191
-
192
- #### Registration Methods
193
-
194
- **`registerService<T extends BasicContext<C>>(service: Service): T`**
195
- - **Purpose**: Registers a service with the context for dependency injection
196
- - **Behavior**:
197
- - Associates the service with the current context
198
- - Stores the service in the appropriate layer
199
- - Makes the service available for retrieval via `service()`
200
- - **Usage**: Call during configuration stage to register services
201
- - **Returns**: The context instance for method chaining
202
-
203
- **`registerModule<T extends BasicContext<C>>(module: BasicModule): T`**
204
- - **Purpose**: Registers a module (URL unit) with the context
205
- - **Behavior**:
206
- - Associates the module with the current context
207
- - Makes the module available for route resolution and navigation
208
- - **Usage**: Register modules that define URL structures and routing
209
- - **Returns**: The context instance for method chaining
210
-
211
- **`registerModules<T extends BasicContext<C>>(modules: BasicModule[]): T`**
212
- - **Purpose**: Convenience method to register multiple modules at once
213
- - **Behavior**: Iterates through the array and registers each module
214
- - **Usage**: Efficient way to register multiple modules simultaneously
215
- - **Returns**: The context instance for method chaining
216
-
217
- **`registerResource<T extends BasicContext<C>>(resource: BasicResource): T`**
218
- - **Purpose**: Registers a resource (data source or external service) with the context
219
- - **Behavior**:
220
- - Associates the resource with the current context
221
- - Resources are initialized during context initialization based on layer availability
222
- - **Usage**: Register resources that provide data or external functionality
223
- - **Returns**: The context instance for method chaining
224
-
225
- **`registerMiddleware<T extends BasicContext<C>>(middleware: Middleware): T`**
226
- - **Purpose**: Registers middleware for cross-cutting concerns during context lifecycle
227
- - **Behavior**:
228
- - Middleware is applied at specific stages (Configuration, Loading, Ready, Switching)
229
- - Multiple middlewares can be registered for the same stage
230
- - **Usage**: Register middleware for logging, validation, or other cross-cutting functionality
231
- - **Returns**: The context instance for method chaining
232
-
233
- #### Access Methods
234
-
235
- **`service<T extends Service>(alias: string): T`**
236
- - **Purpose**: Retrieves a registered service by its alias
237
- - **Behavior**:
238
- - Looks up the service in the current layer and falls back to Global layer
239
- - Handles lazy initialization if the service is not yet initialized
240
- - Throws `SyntaxError` if service is not found or not initialized
241
- - **Usage**: Primary way to access services for dependency injection
242
- - **Returns**: The requested service instance
243
- - **Throws**: `SyntaxError` if service not found or not initialized
244
-
245
- **`module<T extends BasicModule>(alias: string): T`**
246
- - **Purpose**: Retrieves a registered module by its alias
247
- - **Behavior**:
248
- - Looks up the module in the current layer
249
- - Throws `SyntaxError` if module is not found
250
- - **Usage**: Access modules for route resolution and navigation
251
- - **Returns**: The requested module instance
252
- - **Throws**: `SyntaxError` if module not found
253
-
254
- **`resource<T extends BasicResource>(alias: string): T`**
255
- - **Purpose**: Retrieves a registered resource by its alias
256
- - **Behavior**:
257
- - Looks up the resource in the current layer
258
- - Throws `SyntaxError` if resource is not found
259
- - **Usage**: Access resources for data operations or external service calls
260
- - **Returns**: The requested resource instance
261
- - **Throws**: `SyntaxError` if resource not found
262
-
263
- **`modules<T extends BasicModule>(): T[]`**
264
- - **Purpose**: Retrieves all registered modules as an array
265
- - **Behavior**: Returns all modules registered in the current layer
266
- - **Usage**: Useful for iterating over all available modules
267
- - **Returns**: Array of all registered modules
268
-
269
- #### Utility Methods
270
-
271
- **`hasResource(alias: string): boolean`**
272
- - **Purpose**: Checks if a resource with the given alias exists
273
- - **Behavior**: Searches across all layers for the resource
274
- - **Usage**: Defensive programming to check resource availability before access
275
- - **Returns**: `true` if resource exists, `false` otherwise
276
-
277
- **`hasService(alias: string): boolean`**
278
- - **Purpose**: Checks if a service with the given alias exists
279
- - **Behavior**: Searches across all layers for the service
280
- - **Usage**: Defensive programming to check service availability before access
281
- - **Returns**: `true` if service exists, `false` otherwise
282
-
283
- #### Configuration Access
284
-
285
- **`get config(): Promise<C>`**
286
- - **Purpose**: Provides access to the context configuration after it's been configured
287
- - **Behavior**: Returns a promise that resolves to the configuration object once context is configured
288
- - **Usage**: Access configuration settings after context setup
289
- - **Returns**: Promise that resolves to the configuration object
290
-
291
- #### Properties
292
-
293
- **`cfg: C`**
294
- - **Purpose**: Direct access to the context configuration object
295
- - **Usage**: Access configuration settings synchronously
296
- - **Type**: The configuration object of type `C extends BasicConfig`
297
-
298
- **`stage: ContextStage`**
299
- - **Purpose**: Indicates the current lifecycle stage of the context
300
- - **Values**: `Configuration`, `Loading`, or `Ready`
301
- - **Usage**: Check context readiness before performing operations
302
-
303
- #### `BasicConfig`
304
-
305
- Configuration interface for contexts:
306
-
307
- ```typescript
308
- interface BasicConfig {
309
- ready: boolean
310
- service: string
311
- alias?: string
312
- layer: Layer
313
- type: AppType
314
- layerId?: string
315
- services?: Record<string, Object>
316
- debug?: {
317
- all?: boolean
318
- [section: string]: boolean | undefined
319
- }
320
- }
321
- ```
322
-
323
- #### `Service`
324
-
325
- Interface for services:
326
-
327
- ```typescript
328
- interface Service extends Contextual {
329
- layers?: Layer[]
330
- initialized: boolean
331
- init?: () => Promise<void>
332
- lazyInit?: () => Promise<void>
333
- ready?: () => Promise<boolean>
334
- }
335
- ```
336
-
337
- #### `BasicModule`
338
-
339
- Interface for modules:
340
-
341
- ```typescript
342
- interface BasicModule extends Contextual {
343
- _module: true
344
- }
345
- ```
346
-
347
- #### `BasicResource`
348
-
349
- Interface for resources:
350
-
351
- ```typescript
352
- interface BasicResource extends Contextual {
353
- layers?: Layer[]
354
- init?: () => Promise<void>
355
- }
356
- ```
357
-
358
- #### `Middleware`
359
-
360
- Interface for middlewares:
361
-
362
- ```typescript
363
- interface Middleware {
364
- type: MiddlewareType
365
- stage: MiddlewareStage
366
- apply: <C extends BasicConfig, T extends BasicContext<C>>(
367
- context: T,
368
- args?: Record<string, string | undefined>
369
- ) => Promise<void>
25
+ export const makeIamService = (alias: string = IAM_SERVICE) => {
26
+ const service = createService<IamService>(alias, {
27
+ getEntityAdminConfig: async (entityId) => {
28
+ const ctx = service.assertCtx<Config, Context>()
29
+ return ctx.service<KeycloakService>(KC_SERVICE).getConfig(entityId)
30
+ }
31
+ })
32
+ return service
370
33
  }
371
34
  ```
372
35
 
373
- ### Enums
374
-
375
- #### `Layer`
376
- ```typescript
377
- enum Layer {
378
- System = 'system',
379
- Global = 'global',
380
- Service = 'service',
381
- Entity = 'entity',
382
- User = 'user'
383
- }
384
- ```
385
-
386
- #### `AppType`
387
- ```typescript
388
- enum AppType {
389
- Backend = 'backend',
390
- Frontend = 'frontend'
391
- }
392
- ```
36
+ Registering and retrieving services from context:
393
37
 
394
- #### `ContextStage`
395
38
  ```typescript
396
- enum ContextStage {
397
- Configuration = 'configuration',
398
- Loading = 'loading',
399
- Ready = 'ready'
400
- }
401
- ```
402
-
403
- #### `MiddlewareType`
404
- ```typescript
405
- enum MiddlewareType {
406
- Config = 'config',
407
- Context = 'context'
408
- }
409
- ```
410
-
411
- #### `MiddlewareStage`
412
- ```typescript
413
- enum MiddlewareStage {
414
- Configuration = 'configuration',
415
- Loading = 'loading',
416
- Ready = 'ready',
417
- Switching = 'switching'
418
- }
419
- ```
420
-
421
- ## Usage Examples
422
-
423
- ### Basic Usage
424
-
425
- ```typescript
426
- import {
427
- makeBasicContext,
428
- makeBasicConfig,
429
- createService,
430
- AppType,
431
- Layer
432
- } from '@owlmeans/context'
433
-
434
- // Create configuration
435
- const config = makeBasicConfig(AppType.Backend, 'my-app', {
436
- layer: Layer.System,
437
- debug: { all: true }
438
- })
439
-
440
- // Create context
441
- const context = makeBasicContext(config)
442
-
443
- // Create and register a service
444
- const myService = createService('database', {
445
- connect: () => console.log('Connected to database')
446
- }, (service) => async () => {
447
- // Initialize the service
448
- service.connect()
449
- service.initialized = true
450
- })
451
-
452
- context.registerService(myService)
453
-
454
- // Configure and initialize context
455
- const configuredContext = context.configure()
456
- await configuredContext.init()
457
-
458
- // Use the service
459
- const dbService = context.service('database')
460
- ```
461
-
462
- ### Advanced Context Method Usage
463
-
464
- ```typescript
465
- import {
466
- makeBasicContext,
467
- makeBasicConfig,
468
- createService,
469
- createLazyService,
470
- AppType,
471
- Layer,
472
- ContextStage
473
- } from '@owlmeans/context'
474
-
475
- const config = makeBasicConfig(AppType.Backend, 'advanced-app')
476
39
  const context = makeBasicContext(config)
40
+ context.registerService(makeIamService())
477
41
 
478
- // Register multiple services
479
- const cacheService = createService('cache', {
480
- get: (key: string) => `cached-${key}`,
481
- set: (key: string, value: any) => console.log(`Set ${key}=${value}`)
482
- })
483
-
484
- const logService = createLazyService('logger', {
485
- log: (message: string) => console.log(`[LOG] ${message}`)
486
- }, (service) => async () => {
487
- console.log('Logger initialized lazily')
488
- service.initialized = true
489
- })
490
-
491
- context.registerService(cacheService)
492
- context.registerService(logService)
493
-
494
- // Check service availability before use
495
- if (context.hasService('cache')) {
496
- console.log('Cache service is available')
497
- }
498
-
499
- // Wait for specific lifecycle stages
500
- await context.waitForConfigured()
501
- console.log('Context configured')
502
-
503
- // Configure and initialize
504
- context.configure()
505
- await context.init()
506
-
507
- // Check current stage
508
- console.log('Current stage:', context.stage) // ContextStage.Ready
509
-
510
- // Access configuration after initialization
511
- const finalConfig = await context.config
512
- console.log('Final config:', finalConfig.service)
513
-
514
- // Service access - cache service is already initialized
515
- const cache = context.service('cache')
516
- cache.set('key1', 'value1')
517
-
518
- // Lazy service access - will initialize on first access
519
- const logger = context.service('logger') // Triggers lazy initialization
520
- logger.log('Application ready')
521
- ```
522
-
523
- ### Method Chaining and Error Handling
524
-
525
- ```typescript
526
- import {
527
- makeBasicContext,
528
- makeBasicConfig,
529
- createService,
530
- appendContextual,
531
- AppType
532
- } from '@owlmeans/context'
533
-
534
- const config = makeBasicConfig(AppType.Backend, 'chaining-example')
535
- const context = makeBasicContext(config)
536
-
537
- // Method chaining for registration
538
- const service1 = createService('service1', { value: 1 })
539
- const service2 = createService('service2', { value: 2 })
540
- const module1 = appendContextual('module1', { _module: true, routes: {} })
541
- const resource1 = appendContextual('resource1', { data: 'test' })
542
-
543
- // Chain multiple registrations
544
- context
545
- .registerService(service1)
546
- .registerService(service2)
547
- .registerModule(module1)
548
- .registerResource(resource1)
549
-
550
- // Error handling for service access
551
- try {
552
- const nonExistentService = context.service('non-existent')
553
- } catch (error) {
554
- console.error('Service not found:', error.message)
555
- // Output: Service non-existent not found in layer service
556
- }
557
-
558
- // Safe service access using hasService
559
- if (context.hasService('service1')) {
560
- const service = context.service('service1')
561
- console.log('Service value:', service.value)
562
- }
563
-
564
- // Error handling for uninitialized services
565
42
  await context.configure().init()
566
43
 
567
- // Now services are accessible
568
- const service = context.service('service1')
569
- console.log('Service accessible after init:', service.value)
44
+ const iamService = context.service<IamService>(IAM_SERVICE)
570
45
  ```
571
46
 
572
- ### Context Lifecycle Management
47
+ ## API
573
48
 
574
- ```typescript
575
- const context = makeBasicContext(config)
49
+ ### `createService<S>(alias, implementation): S`
576
50
 
577
- // Register components during Configuration stage
578
- console.log('Stage:', context.stage) // ContextStage.Configuration
51
+ Creates a service registered under `alias`. Inside method implementations, call `service.assertCtx()` to get the current context.
579
52
 
580
- context.registerService(myService)
581
- context.registerModule(myModule)
53
+ ### `createLazyService<S>(alias, implementation): S`
582
54
 
583
- // Move to Loading stage
584
- context.configure()
585
- console.log('Stage:', context.stage) // ContextStage.Loading
55
+ Like `createService` but initialized on first access via `lazyInit()`.
586
56
 
587
- // Move to Ready stage
588
- await context.init()
589
- console.log('Stage:', context.stage) // ContextStage.Ready
57
+ ### `appendContextual(alias, obj): Contextual`
590
58
 
591
- // Context lifecycle promises
592
- const configuredPromise = context.waitForConfigured()
593
- const initializedPromise = context.waitForInitialized()
59
+ Wraps a plain object as a contextual entity (adds `registerContext`, `assertCtx`, etc.).
594
60
 
595
- // Both promises resolve immediately if context is already ready
596
- await configuredPromise // Resolves to true
597
- await initializedPromise // Resolves to true
598
- ```
61
+ ### `assertContext(ctx, location?): T`
599
62
 
600
- ### Module Registration
63
+ Asserts that a context is defined; throws if not.
601
64
 
602
- ```typescript
603
- import { appendContextual } from '@owlmeans/context'
604
-
605
- // Create a module
606
- const userModule = appendContextual('user', {
607
- _module: true,
608
- routes: {
609
- login: '/login',
610
- profile: '/profile'
611
- }
612
- })
613
-
614
- // Register the module
615
- context.registerModule(userModule)
616
-
617
- // Access the module
618
- const module = context.module('user')
619
- ```
620
-
621
- ### Resource Management
622
-
623
- ```typescript
624
- const dbResource = appendContextual('db-connection', {
625
- connection: null,
626
- init: async () => {
627
- // Initialize database connection
628
- console.log('Database connection initialized')
629
- }
630
- })
631
-
632
- context.registerResource(dbResource)
633
-
634
- // Resource will be initialized during context initialization
635
- await context.init()
636
-
637
- // Access the resource
638
- const db = context.resource('db-connection')
639
- ```
640
-
641
- ### Middleware Usage
65
+ ### `makeBasicContext<C>(cfg): BasicContext<C>`
642
66
 
643
- ```typescript
644
- const loggingMiddleware = {
645
- type: MiddlewareType.Context,
646
- stage: MiddlewareStage.Ready,
647
- apply: async (context) => {
648
- console.log(`Context ${context.cfg.service} is ready`)
649
- }
650
- }
651
-
652
- context.registerMiddleware(loggingMiddleware)
653
- ```
654
-
655
- ## Context Lifecycle
656
-
657
- 1. **Configuration Stage**: Register services, modules, resources, and middlewares
658
- 2. **Loading Stage**: Initialize services and resources
659
- 3. **Ready Stage**: Context is ready for use
660
-
661
- ```typescript
662
- // Configuration stage
663
- const context = makeBasicContext(config)
664
- context.registerService(myService)
665
- context.registerModule(myModule)
666
-
667
- // Move to loading stage
668
- context.configure()
669
-
670
- // Initialize and move to ready stage
671
- await context.init()
672
-
673
- // Context is now ready
674
- console.log(context.stage) // ContextStage.Ready
675
- ```
67
+ Creates a context from a config object. Rarely used directly — prefer the higher-level `makeContext` from `@owlmeans/server-app` or `@owlmeans/client-context`.
676
68
 
677
- ## Integration with Other Packages
678
-
679
- The context package integrates seamlessly with other OwlMeans packages:
680
-
681
- ```typescript
682
- import { makeServerContext } from '@owlmeans/server-context'
683
- import { makeClientContext } from '@owlmeans/client-context'
684
-
685
- // Server-side context with additional capabilities
686
- const serverContext = makeServerContext(serverConfig)
687
-
688
- // Client-side context with additional capabilities
689
- const clientContext = makeClientContext(clientConfig)
690
- ```
691
-
692
- ## Helper Functions
693
-
694
- ### `assertContext<C extends BasicConfig, T extends BasicContext<C>>(ctx: T | undefined, location?: string): T`
695
-
696
- Asserts that a context is defined and throws an error if not.
69
+ ### Enums
697
70
 
698
71
  ```typescript
699
- import { assertContext } from '@owlmeans/context'
700
-
701
- const context = assertContext(maybeContext, 'MyService')
72
+ enum Layer { System, Global, Service, Entity, User }
73
+ enum AppType { Backend, Frontend }
74
+ enum ContextStage { Configuration, Loading, Ready }
702
75
  ```
703
76
 
704
- ### `isContextWithoutIds<C extends BasicConfig, T extends BasicContext<C>>(context: T): boolean`
705
-
706
- Checks if a context operates without IDs (System, Global, or Service layers).
77
+ ### Route Constants
707
78
 
708
79
  ```typescript
709
- import { isContextWithoutIds } from '@owlmeans/context'
710
-
711
- const needsIds = !isContextWithoutIds(context)
80
+ ROOT // intermediate base route
81
+ HOME // default/home route
82
+ GUEST // unauthenticated area
83
+ BASE // authenticated area
84
+ CRASH // error fallback screen
712
85
  ```
713
86
 
714
- ## Error Handling
715
-
716
- The package throws `SyntaxError` for common issues:
717
-
718
- - Service not found: When accessing an unregistered service
719
- - Module not found: When accessing an unregistered module
720
- - Resource not found: When accessing an unregistered resource
721
- - Context not found: When context is undefined in a contextual object
722
- - Service not initialized: When accessing a non-initialized service
723
-
724
- ## Best Practices
725
-
726
- 1. **Use Factory Functions**: Always use the provided factory functions instead of constructors
727
- 2. **Layer Organization**: Organize your components by appropriate layers
728
- 3. **Service Initialization**: Choose between immediate and lazy initialization based on your needs
729
- 4. **Error Handling**: Always handle potential errors when accessing services, modules, or resources
730
- 5. **Context Lifecycle**: Respect the context lifecycle stages
731
- 6. **Middleware Order**: Be mindful of middleware execution order and stages
732
-
733
- ## TypeScript Support
734
-
735
- The package is written in TypeScript and provides full type safety:
736
-
737
- ```typescript
738
- import type { BasicContext, BasicConfig, Service } from '@owlmeans/context'
739
-
740
- interface MyConfig extends BasicConfig {
741
- customOption: string
742
- }
743
-
744
- interface MyService extends Service {
745
- customMethod(): void
746
- }
87
+ ## Related Packages
747
88
 
748
- const context: BasicContext<MyConfig> = makeBasicContext(config)
749
- const service: MyService = context.service('my-service')
750
- ```
89
+ - [`@owlmeans/config`](../config) — configuration builder used with context
90
+ - [`@owlmeans/server-context`](../server-context) — server-side context extension
91
+ - [`@owlmeans/client-context`](../client-context) — client-side context extension
92
+ - [`@owlmeans/server-app`](../server-app) — top-level server context factory
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAmD,MAAM,YAAY,CAAA;AAO5G,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,CAAC,KAAG,YAAY,CAAC,CAAC,CA8P9E,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAoE,MAAM,YAAY,CAAA;AAO7H,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,CAAC,KAAG,YAAY,CAAC,CAAC,CA6Q9E,CAAA"}
package/build/context.js CHANGED
@@ -4,11 +4,11 @@ import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailabl
4
4
  import { DEFAULT, initializeLayer } from './utils/layer.js';
5
5
  export const makeBasicContext = (cfg) => {
6
6
  const services = {};
7
- const modules = {};
7
+ const entrypoints = {};
8
8
  const resources = {};
9
9
  const middlewares = {};
10
10
  const allServices = {};
11
- const allModules = {};
11
+ const allEntrypoints = {};
12
12
  const allResources = {};
13
13
  let configure;
14
14
  let initialize;
@@ -74,19 +74,23 @@ export const makeBasicContext = (cfg) => {
74
74
  services[context.cfg.layer][id][service.alias] = service;
75
75
  return context;
76
76
  },
77
- registerModule: (module) => {
78
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId);
79
- module = module.registerContext(context);
80
- if (allModules[module.alias] == null) {
81
- allModules[module.alias] = module;
77
+ registerEntrypoint: (entrypoint) => {
78
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId);
79
+ entrypoint = entrypoint.registerContext(context);
80
+ if (allEntrypoints[entrypoint.alias] == null) {
81
+ allEntrypoints[entrypoint.alias] = entrypoint;
82
82
  }
83
- modules[context.cfg.layer][id][module.alias] = module;
83
+ entrypoints[context.cfg.layer][id][entrypoint.alias] = entrypoint;
84
84
  return context;
85
85
  },
86
- registerModules: (modules) => {
87
- modules.forEach(module => context.registerModule(module));
86
+ registerEntrypoints: (eps) => {
87
+ eps.forEach(ep => context.registerEntrypoint(ep));
88
88
  return context;
89
89
  },
90
+ /** @deprecated use registerEntrypoint */
91
+ registerModule: (module) => context.registerEntrypoint(module),
92
+ /** @deprecated use registerEntrypoints */
93
+ registerModules: (mods) => context.registerEntrypoints(mods),
90
94
  registerResource: (resource) => {
91
95
  const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId);
92
96
  resource = resource.registerContext(context);
@@ -134,13 +138,15 @@ export const makeBasicContext = (cfg) => {
134
138
  }
135
139
  return _service;
136
140
  },
137
- module: (alias) => {
138
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId);
139
- if (modules[context.cfg.layer][id][alias] != null) {
140
- return modules[context.cfg.layer][id][alias];
141
+ entrypoint: (alias) => {
142
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId);
143
+ if (entrypoints[context.cfg.layer][id][alias] != null) {
144
+ return entrypoints[context.cfg.layer][id][alias];
141
145
  }
142
- throw new SyntaxError(`Module ${alias} not found`);
146
+ throw new SyntaxError(`Entrypoint ${alias} not found`);
143
147
  },
148
+ /** @deprecated use entrypoint */
149
+ module: (alias) => context.entrypoint(alias),
144
150
  resource: (alias) => {
145
151
  const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId);
146
152
  if (resources[context.cfg.layer][id][alias] != null) {
@@ -149,10 +155,12 @@ export const makeBasicContext = (cfg) => {
149
155
  }
150
156
  throw new SyntaxError(`Resource ${alias} not found`);
151
157
  },
152
- modules: () => {
153
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId);
154
- return Object.values(modules[context.cfg.layer][id]);
158
+ entrypoints: () => {
159
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId);
160
+ return Object.values(entrypoints[context.cfg.layer][id]);
155
161
  },
162
+ /** @deprecated use entrypoints */
163
+ modules: () => context.entrypoints(),
156
164
  /**
157
165
  * @TODO Unfortunatly module cloning between contexts is quite unstable.
158
166
  * And it looks like in some cases it relies on modules that aren't really clonned.
@@ -188,7 +196,7 @@ export const makeBasicContext = (cfg) => {
188
196
  // .forEach(middleware => _context.registerMiddleware(middleware))
189
197
  // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Config, MiddlewareStage.Switching, { layer, id })
190
198
  // Object.values(allServices).forEach(service => _context.registerService(service))
191
- // Object.values(allModules).forEach(module => _context.registerModule(module))
199
+ // Object.values(allEntrypoints).forEach(ep => _context.registerEntrypoint(ep))
192
200
  // Object.values(allResources).forEach(resource => _context.registerResource(resource))
193
201
  // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Context, MiddlewareStage.Switching, { layer, id })
194
202
  // _context.stage = ContextStage.Loading
@@ -197,7 +205,9 @@ export const makeBasicContext = (cfg) => {
197
205
  },
198
206
  hasResource: alias => allResources[alias] != null,
199
207
  hasService: alias => allServices[alias] != null,
200
- hasModule: alias => allModules[alias] != null,
208
+ hasEntrypoint: alias => allEntrypoints[alias] != null,
209
+ /** @deprecated use hasEntrypoint */
210
+ hasModule: alias => context.hasEntrypoint(alias),
201
211
  };
202
212
  return context;
203
213
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAElF,6HAA6H;AAC7H,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC7G,OAAO,EAAE,OAAO,EAAW,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAIpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAwB,GAAM,EAAmB,EAAE;IACjF,MAAM,QAAQ,GAAG,EAAsC,CAAA;IACvD,MAAM,OAAO,GAAG,EAAqC,CAAA;IACrD,MAAM,SAAS,GAAG,EAA4C,CAAA;IAC9D,MAAM,WAAW,GAAiC,EAAE,CAAA;IACpD,MAAM,WAAW,GAA4B,EAAE,CAAA;IAC/C,MAAM,UAAU,GAA2B,EAAE,CAAA;IAC7C,MAAM,YAAY,GAAkC,EAAE,CAAA;IAEtD,IAAI,SAAiC,CAAA;IACrC,IAAI,UAAmC,CAAA;IAEvC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAU,OAAO,CAAC,EAAE,GAAG,SAAS,GAAG,OAAO,CAAA,CAAC,CAAC,CAAC,CAAA;IAC3E,MAAM,WAAW,GAAG,IAAI,OAAO,CAAU,OAAO,CAAC,EAAE,GAAG,UAAU,GAAG,OAAO,CAAA,CAAC,CAAC,CAAC,CAAA;IAE7E,uDAAuD;IAEvD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAW,CAAA;IAErC,MAAM,OAAO,GAAoB;QAC/B,GAAG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AAyF;YACzF,uBAAuB;YACvB,iEAAiE;YACjE,IAAI;YAEJ,kEAAkE;YAClE,wEAAwE;YACxE,IAAI;YAEJ,6CAA6C;YAE7C,qCAAqC;YACrC,+BAA+B;YAC/B,yBAAyB;YACzB,8BAA8B;YAC9B,IAAI;YAEJ,6DAA6D;YAC7D,wBAAwB;YACxB,wBAAwB;YACxB,uBAAuB;YACvB,0FAA0F;YAC1F,0GAA0G;YAE1G,iEAAiE;YACjE,oEAAoE;YAEpE,qIAAqI;YAErI,mFAAmF;YAEnF,+EAA+E;YAE/E,uFAAuF;YAEvF,sIAAsI;YAEtI,wCAAwC;YACxC,oCAAoC;YAEpC,yCAAyC;QAC3C,CAAC;QAED,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,IAAI;QAEjD,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,IAAI;QAE/C,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,IAAI;QAErD,oCAAoC;QACpC,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC;KACjD,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
package/build/types.d.ts CHANGED
@@ -42,6 +42,11 @@ export interface LazyService extends Service {
42
42
  lazyInit: () => Promise<void>;
43
43
  ready: () => Promise<boolean>;
44
44
  }
45
+ export interface BasicEntrypoint extends Contextual {
46
+ _entrypoint: true;
47
+ _module: true;
48
+ }
49
+ /** @deprecated use BasicEntrypoint */
45
50
  export interface BasicModule extends Contextual {
46
51
  _module: true;
47
52
  }
@@ -63,17 +68,27 @@ export interface BasicContext<C extends BasicConfig> {
63
68
  init: <T extends BasicContext<C>>() => Promise<T>;
64
69
  updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>;
65
70
  registerService: <T extends BasicContext<C>>(service: Service) => T;
66
- registerModule: <T extends BasicContext<C>>(module: BasicModule) => T;
67
- registerModules: <T extends BasicContext<C>>(module: BasicModule[]) => T;
71
+ registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T;
72
+ registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T;
68
73
  registerResource: <T extends BasicContext<C>>(resource: BasicResource) => T;
69
74
  registerMiddleware: <T extends BasicContext<C>>(middleware: Middleware) => T;
70
75
  get config(): Promise<C>;
71
76
  service: <T extends Service>(alias: string) => T;
72
- module: <T extends BasicModule>(alias: string) => T;
77
+ entrypoint: <T extends BasicEntrypoint>(alias: string) => T;
73
78
  resource: <T extends BasicResource>(alias: string) => T;
74
79
  hasResource: (alias: string) => boolean;
75
80
  hasService: (alias: string) => boolean;
81
+ hasEntrypoint: (alias: string) => boolean;
82
+ entrypoints: <T extends BasicEntrypoint>() => T[];
83
+ /** @deprecated use registerEntrypoint */
84
+ registerModule: <T extends BasicContext<C>>(module: BasicModule) => T;
85
+ /** @deprecated use registerEntrypoints */
86
+ registerModules: <T extends BasicContext<C>>(modules: BasicModule[]) => T;
87
+ /** @deprecated use entrypoint */
88
+ module: <T extends BasicModule>(alias: string) => T;
89
+ /** @deprecated use hasEntrypoint */
76
90
  hasModule: (alias: string) => boolean;
91
+ /** @deprecated use entrypoints */
77
92
  modules: <T extends BasicModule>() => T[];
78
93
  makeContext?: <T extends BasicContext<C>>(cfg: C) => T;
79
94
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE/G,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IAEf,KAAK,CAAC,EAAE,MAAM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EAAE,KAAK,CAAC,CAAA;IACzE,iCAAiC;IACjC,MAAM,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;IACnD,oCAAoC;IACpC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACrC,kCAAkC;IAClC,OAAO,EAAE,CAAC,CAAC,SAAS,WAAW,OAAO,CAAC,EAAE,CAAA;IAEzC,WAAW,CAAC,EAAE,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;CACvD"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@owlmeans/context",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "build": "tsc -b",
8
8
  "dev": "sleep 150 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
9
- "watch": "tsc -b -w --preserveWatchOutput --pretty"
9
+ "watch": "tsc -b -w --preserveWatchOutput --pretty",
10
+ "test": "bun test ./tests"
10
11
  },
11
12
  "main": "build/index.js",
12
13
  "module": "build/index.js",
@@ -21,9 +22,10 @@
21
22
  }
22
23
  },
23
24
  "devDependencies": {
25
+ "@owlmeans/dep-config": "workspace:*",
24
26
  "nodemon": "^3.1.11",
25
27
  "npm-check": "^6.0.1",
26
- "typescript": "^5.8.3"
28
+ "typescript": "^6.0.2"
27
29
  },
28
30
  "publishConfig": {
29
31
  "access": "public"
package/src/context.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import { ContextStage, Layer, MiddlewareStage, MiddlewareType } from './consts.js'
2
- import type { BasicConfig, BasicContext, Middleware, BasicModule, BasicResource, Service } from './types.js'
2
+ import type { BasicConfig, BasicContext, Middleware, BasicEntrypoint, BasicModule, BasicResource, Service } from './types.js'
3
3
  // import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable, layersOrder } from './utils/context.js'
4
4
  import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable } from './utils/context.js'
5
5
  import { DEFAULT, InLayer, initializeLayer } from './utils/layer.js'
6
6
 
7
- type Module = BasicModule
7
+ type Entrypoint = BasicEntrypoint
8
8
 
9
9
  export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C> => {
10
10
  const services = {} as InLayer<Record<string, Service>>
11
- const modules = {} as InLayer<Record<string, Module>>
11
+ const entrypoints = {} as InLayer<Record<string, Entrypoint>>
12
12
  const resources = {} as InLayer<Record<string, BasicResource>>
13
13
  const middlewares: Record<string, Middleware[]> = {}
14
14
  const allServices: Record<string, Service> = {}
15
- const allModules: Record<string, Module> = {}
15
+ const allEntrypoints: Record<string, Entrypoint> = {}
16
16
  const allResources: Record<string, BasicResource> = {}
17
17
 
18
18
  let configure: (res: boolean) => void
@@ -106,22 +106,28 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
106
106
  return context as T
107
107
  },
108
108
 
109
- registerModule: <T>(module: Module) => {
110
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId)
111
- module = module.registerContext(context)
112
- if (allModules[module.alias] == null) {
113
- allModules[module.alias] = module
109
+ registerEntrypoint: <T>(entrypoint: Entrypoint) => {
110
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId)
111
+ entrypoint = entrypoint.registerContext(context)
112
+ if (allEntrypoints[entrypoint.alias] == null) {
113
+ allEntrypoints[entrypoint.alias] = entrypoint
114
114
  }
115
- modules[context.cfg.layer][id][module.alias] = module
115
+ entrypoints[context.cfg.layer][id][entrypoint.alias] = entrypoint
116
116
 
117
117
  return context as T
118
118
  },
119
119
 
120
- registerModules: <T>(modules: Module[]) => {
121
- modules.forEach(module => context.registerModule(module))
120
+ registerEntrypoints: <T>(eps: Entrypoint[]) => {
121
+ eps.forEach(ep => context.registerEntrypoint(ep))
122
122
  return context as T
123
123
  },
124
124
 
125
+ /** @deprecated use registerEntrypoint */
126
+ registerModule: <T>(module: BasicModule) => context.registerEntrypoint(module as unknown as Entrypoint) as T,
127
+
128
+ /** @deprecated use registerEntrypoints */
129
+ registerModules: <T>(mods: BasicModule[]) => context.registerEntrypoints(mods as unknown as Entrypoint[]) as T,
130
+
125
131
  registerResource: <T>(resource: BasicResource) => {
126
132
  const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId)
127
133
  resource = resource.registerContext(context)
@@ -173,14 +179,17 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
173
179
  return _service as T
174
180
  },
175
181
 
176
- module: <T>(alias: string) => {
177
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId)
178
- if (modules[context.cfg.layer][id][alias] != null) {
179
- return modules[context.cfg.layer][id][alias] as T
182
+ entrypoint: <T extends Entrypoint>(alias: string) => {
183
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId)
184
+ if (entrypoints[context.cfg.layer][id][alias] != null) {
185
+ return entrypoints[context.cfg.layer][id][alias] as T
180
186
  }
181
- throw new SyntaxError(`Module ${alias} not found`)
187
+ throw new SyntaxError(`Entrypoint ${alias} not found`)
182
188
  },
183
189
 
190
+ /** @deprecated use entrypoint */
191
+ module: <T>(alias: string) => context.entrypoint<any>(alias) as T,
192
+
184
193
  resource: <T extends BasicResource>(alias: string) => {
185
194
  const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId)
186
195
  if (resources[context.cfg.layer][id][alias] != null) {
@@ -191,11 +200,14 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
191
200
  throw new SyntaxError(`Resource ${alias} not found`)
192
201
  },
193
202
 
194
- modules: <T>() => {
195
- const id = initializeLayer(modules, context.cfg.layer, context.cfg.layerId)
196
- return Object.values(modules[context.cfg.layer][id]) as T[]
203
+ entrypoints: <T extends Entrypoint>() => {
204
+ const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId)
205
+ return Object.values(entrypoints[context.cfg.layer][id]) as T[]
197
206
  },
198
207
 
208
+ /** @deprecated use entrypoints */
209
+ modules: <T>() => context.entrypoints<any>() as T[],
210
+
199
211
  /**
200
212
  * @TODO Unfortunatly module cloning between contexts is quite unstable.
201
213
  * And it looks like in some cases it relies on modules that aren't really clonned.
@@ -240,7 +252,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
240
252
 
241
253
  // Object.values(allServices).forEach(service => _context.registerService(service))
242
254
 
243
- // Object.values(allModules).forEach(module => _context.registerModule(module))
255
+ // Object.values(allEntrypoints).forEach(ep => _context.registerEntrypoint(ep))
244
256
 
245
257
  // Object.values(allResources).forEach(resource => _context.registerResource(resource))
246
258
 
@@ -256,7 +268,10 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
256
268
 
257
269
  hasService: alias => allServices[alias] != null,
258
270
 
259
- hasModule: alias => allModules[alias] != null,
271
+ hasEntrypoint: alias => allEntrypoints[alias] != null,
272
+
273
+ /** @deprecated use hasEntrypoint */
274
+ hasModule: alias => context.hasEntrypoint(alias),
260
275
  }
261
276
 
262
277
  return context
package/src/types.ts CHANGED
@@ -54,6 +54,12 @@ export interface LazyService extends Service {
54
54
  ready: () => Promise<boolean>
55
55
  }
56
56
 
57
+ export interface BasicEntrypoint extends Contextual {
58
+ _entrypoint: true
59
+ _module: true
60
+ }
61
+
62
+ /** @deprecated use BasicEntrypoint */
57
63
  export interface BasicModule extends Contextual {
58
64
  _module: true
59
65
  }
@@ -78,19 +84,30 @@ export interface BasicContext<C extends BasicConfig> {
78
84
  init: <T extends BasicContext<C>>() => Promise<T>
79
85
  updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>
80
86
  registerService: <T extends BasicContext<C>>(service: Service) => T
81
- registerModule: <T extends BasicContext<C>>(module: BasicModule) => T
82
- registerModules: <T extends BasicContext<C>>(module: BasicModule[]) => T
87
+ registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T
88
+ registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T
83
89
  registerResource: <T extends BasicContext<C>>(resource: BasicResource) => T
84
90
  registerMiddleware: <T extends BasicContext<C>>(middleware: Middleware) => T
85
91
 
86
92
  get config(): Promise<C>
87
93
  service: <T extends Service>(alias: string) => T
88
- module: <T extends BasicModule>(alias: string) => T
94
+ entrypoint: <T extends BasicEntrypoint>(alias: string) => T
89
95
  resource: <T extends BasicResource>(alias: string) => T
90
96
  hasResource: (alias: string) => boolean
91
97
  hasService: (alias: string) => boolean
92
- hasModule: (alias: string) => boolean
98
+ hasEntrypoint: (alias: string) => boolean
99
+
100
+ entrypoints: <T extends BasicEntrypoint>() => T[]
93
101
 
102
+ /** @deprecated use registerEntrypoint */
103
+ registerModule: <T extends BasicContext<C>>(module: BasicModule) => T
104
+ /** @deprecated use registerEntrypoints */
105
+ registerModules: <T extends BasicContext<C>>(modules: BasicModule[]) => T
106
+ /** @deprecated use entrypoint */
107
+ module: <T extends BasicModule>(alias: string) => T
108
+ /** @deprecated use hasEntrypoint */
109
+ hasModule: (alias: string) => boolean
110
+ /** @deprecated use entrypoints */
94
111
  modules: <T extends BasicModule>() => T[]
95
112
 
96
113
  makeContext?: <T extends BasicContext<C>>(cfg: C) => T
@@ -0,0 +1,18 @@
1
+ import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
2
+ import type { BasicConfig, BasicContext } from '@owlmeans/context'
3
+
4
+ const baseConfig = (): BasicConfig => ({
5
+ ready: false,
6
+ service: 'test-context',
7
+ layer: Layer.Service,
8
+ type: AppType.Backend,
9
+ })
10
+
11
+ /**
12
+ * Build a fresh real context for each spec. `@owlmeans/context` is the
13
+ * lowest layer in the framework — its tests use no mocks and no test-auth
14
+ * helpers. Provisioning the context is the only shared setup; specs test
15
+ * its public API directly.
16
+ */
17
+ export const makeTestCtx = (overrides: Partial<BasicConfig> = {}): BasicContext<BasicConfig> =>
18
+ makeBasicContext({ ...baseConfig(), ...overrides })
@@ -0,0 +1,20 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { createService } from '@owlmeans/context'
3
+ import { makeTestCtx } from './context.js'
4
+
5
+ describe('@owlmeans/context — service registration', () => {
6
+ test('registers a service and resolves it by alias after initialization', async () => {
7
+ const ctx = makeTestCtx()
8
+ const stub = createService('alpha', { layers: [] })
9
+ ctx.registerService(stub)
10
+ expect(ctx.hasService('alpha')).toBe(true)
11
+ ctx.configure()
12
+ await ctx.init()
13
+ expect(ctx.service('alpha')).toBe(stub)
14
+ })
15
+
16
+ test('hasService is false for an alias that was never registered', () => {
17
+ const ctx = makeTestCtx()
18
+ expect(ctx.hasService('missing')).toBe(false)
19
+ })
20
+ })
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
2
  "extends": [
3
- "../tsconfig.default.json",
3
+ "@owlmeans/dep-config/tsconfig.base.json"
4
4
  ],
5
5
  "compilerOptions": {
6
- "rootDir": "./src/", /* Specify the root folder within your source files. */
7
- "outDir": "./build/", /* Specify an output folder for all emitted files. */
6
+ "rootDir": "./src/",
7
+ "outDir": "./build/"
8
8
  },
9
- "exclude": [
10
- "./dist/**/*",
11
- "./build/**/*",
12
- "./*.ts"
13
- ]
14
- }
9
+ "exclude": ["./dist/**/*", "./build/**/*", "./tests/**/*", "./*.ts"]
10
+ }