@owlmeans/context 0.1.18-rc.1 → 0.1.18-rc.10

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 (43) hide show
  1. package/README.md +27 -6
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/context/SKILL.md +129 -19
  4. package/build/config.d.ts.map +1 -1
  5. package/build/config.js +0 -2
  6. package/build/config.js.map +1 -1
  7. package/build/consts.d.ts +1 -9
  8. package/build/consts.d.ts.map +1 -1
  9. package/build/consts.js +0 -9
  10. package/build/consts.js.map +1 -1
  11. package/build/context.d.ts.map +1 -1
  12. package/build/context.js +26 -109
  13. package/build/context.js.map +1 -1
  14. package/build/helper.d.ts +0 -1
  15. package/build/helper.d.ts.map +1 -1
  16. package/build/helper.js +4 -13
  17. package/build/helper.js.map +1 -1
  18. package/build/types.d.ts +21 -23
  19. package/build/types.d.ts.map +1 -1
  20. package/build/utils/context.d.ts +2 -7
  21. package/build/utils/context.d.ts.map +1 -1
  22. package/build/utils/context.js +0 -11
  23. package/build/utils/context.js.map +1 -1
  24. package/build/utils/index.d.ts +0 -1
  25. package/build/utils/index.d.ts.map +1 -1
  26. package/build/utils/index.js +0 -1
  27. package/build/utils/index.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/config.ts +1 -2
  30. package/src/consts.ts +1 -10
  31. package/src/context.ts +32 -134
  32. package/src/helper.ts +4 -18
  33. package/src/types.ts +22 -26
  34. package/src/utils/context.ts +2 -20
  35. package/src/utils/index.ts +0 -1
  36. package/tests/context.ts +1 -2
  37. package/tests/service.spec.ts +1 -1
  38. package/build/.gitkeep +0 -0
  39. package/build/utils/layer.d.ts +0 -6
  40. package/build/utils/layer.d.ts.map +0 -1
  41. package/build/utils/layer.js +0 -12
  42. package/build/utils/layer.js.map +0 -1
  43. package/src/utils/layer.ts +0 -17
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"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AC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA"}
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAuB,KAAa,EAAE,UAAsB,EAAK,EAAE;IACjG,UAAU,CAAC,KAAK,GAAG,KAAK,CAAA;IACxB,UAAU,CAAC,eAAe,GAAG,CAA2B,OAAwB,EAAE,EAAE;QAClF,+EAA+E;QAC/E,IAAI,UAAU,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,GAAG,GAAG,OAAO,CAAA;QAC1B,CAAC;QAED,OAAO,UAAe,CAAA;IACxB,CAAC,CAAA;IAED,UAAU,CAAC,SAAS,GAAG,CACrB,QAAQ,CAAC,EAAE,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,IAAI,UAAU,CAAC,KAAK,CAAC,CACzC,CAAA;IAEhC,OAAO,UAAe,CAAA;AACxB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAmD,GAA8C,EAAE,QAAiB,EAAK,EAAE;IACtJ,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,MAAM,IAAI,WAAW,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,GAAQ,CAAA;AACjB,CAAC,CAAA"}
package/build/types.d.ts CHANGED
@@ -1,11 +1,9 @@
1
- import type { AppType, ContextStage, Layer, MiddlewareStage, MiddlewareType, CONFIG_RECORD } from './consts.js';
1
+ import type { AppType, ContextStage, MiddlewareStage, MiddlewareType, CONFIG_RECORD } from './consts.js';
2
2
  export interface BasicConfig {
3
3
  ready: boolean;
4
4
  service: string;
5
5
  alias?: string;
6
- layer: Layer;
7
6
  type: AppType;
8
- layerId?: string;
9
7
  services?: Record<string, Object>;
10
8
  [CONFIG_RECORD]?: ConfigRecord[];
11
9
  debug?: {
@@ -23,12 +21,10 @@ interface ConfigRecordItem extends Record<string, MaybeArray<ConfigRecordItem |
23
21
  export interface Contextual {
24
22
  ctx?: BasicContext<any>;
25
23
  alias: string;
26
- reinitializeContext?: <T extends Contextual>(context: BasicContext<any>) => T;
27
24
  registerContext: <T extends Contextual, C extends BasicConfig>(context: BasicContext<C>) => T;
28
25
  assertCtx: <C extends BasicConfig, T extends BasicContext<C>>(location?: string) => T;
29
26
  }
30
27
  export interface Service extends Contextual {
31
- layers?: Layer[];
32
28
  initialized: boolean;
33
29
  init?: () => Promise<void>;
34
30
  lazyInit?: () => Promise<void>;
@@ -44,14 +40,19 @@ export interface LazyService extends Service {
44
40
  }
45
41
  export interface BasicEntrypoint extends Contextual {
46
42
  _entrypoint: true;
47
- _module: true;
48
43
  }
49
- /** @deprecated use BasicEntrypoint */
50
- export interface BasicModule extends Contextual {
51
- _module: true;
44
+ /**
45
+ * A stable reference to an entrypoint registered in a context.
46
+ *
47
+ * Contract packages use this instead of exporting raw alias strings. The optional type member is
48
+ * deliberately phantom: it lets `context.entrypoint(protocol)` infer the context-bound module
49
+ * without changing the wire alias or adding registry-wide declaration merging.
50
+ */
51
+ export interface EntrypointReference<T extends BasicEntrypoint = BasicEntrypoint> {
52
+ readonly alias: string;
53
+ readonly entrypointType?: T;
52
54
  }
53
55
  export interface BasicResource extends Contextual {
54
- layers?: Layer[];
55
56
  init?: () => Promise<void>;
56
57
  }
57
58
  export interface Middleware {
@@ -59,6 +60,12 @@ export interface Middleware {
59
60
  stage: MiddlewareStage;
60
61
  apply: <C extends BasicConfig, T extends BasicContext<C>>(context: T, args?: Record<string, string | undefined>) => Promise<void>;
61
62
  }
63
+ /**
64
+ * The DI container. One context is built per process by one factory: a layer specific
65
+ * factory composes the layer below it and then `append*` mixins register what the
66
+ * application needs. There is no child context and nothing is stored for re-creation —
67
+ * a service, a resource and an entrypoint each bind to exactly one context.
68
+ */
62
69
  export interface BasicContext<C extends BasicConfig> {
63
70
  cfg: C;
64
71
  stage: ContextStage;
@@ -66,7 +73,6 @@ export interface BasicContext<C extends BasicConfig> {
66
73
  waitForInitialized: () => Promise<boolean>;
67
74
  configure: <T extends BasicContext<C>>() => T;
68
75
  init: <T extends BasicContext<C>>() => Promise<T>;
69
- updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>;
70
76
  registerService: <T extends BasicContext<C>>(service: Service) => T;
71
77
  registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T;
72
78
  registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T;
@@ -74,23 +80,15 @@ export interface BasicContext<C extends BasicConfig> {
74
80
  registerMiddleware: <T extends BasicContext<C>>(middleware: Middleware) => T;
75
81
  get config(): Promise<C>;
76
82
  service: <T extends Service>(alias: string) => T;
77
- entrypoint: <T extends BasicEntrypoint>(alias: string) => T;
83
+ entrypoint: {
84
+ <T extends BasicEntrypoint>(reference: EntrypointReference<T>): T;
85
+ <T extends BasicEntrypoint>(reference: EntrypointReference | string): T;
86
+ };
78
87
  resource: <T extends BasicResource>(alias: string) => T;
79
88
  hasResource: (alias: string) => boolean;
80
89
  hasService: (alias: string) => boolean;
81
90
  hasEntrypoint: (alias: string) => boolean;
82
91
  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 */
90
- hasModule: (alias: string) => boolean;
91
- /** @deprecated use entrypoints */
92
- modules: <T extends BasicModule>() => T[];
93
- makeContext?: <T extends BasicContext<C>>(cfg: C) => T;
94
92
  }
95
93
  export {};
96
94
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
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C,CAAC,CAAC,GAAG,CAAC,CAAA;QACjE,CAAC,CAAC,SAAS,eAAe,EAAE,SAAS,EAAE,mBAAmB,GAAG,MAAM,GAAG,CAAC,CAAA;KACxE,CAAA;IACD,QAAQ,EAAE,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;IACvD,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACvC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACtC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IAEzC,WAAW,EAAE,CAAC,CAAC,SAAS,eAAe,OAAO,CAAC,EAAE,CAAA;CAClD"}
@@ -1,11 +1,6 @@
1
- import { Layer, MiddlewareStage, MiddlewareType } from '../consts.js';
2
- import type { BasicConfig, BasicContext, Middleware, BasicResource, Service } from '../types.js';
3
- import type { InLayer } from './layer.js';
1
+ import type { MiddlewareStage, MiddlewareType } from '../consts.js';
2
+ import type { BasicConfig, BasicContext, Middleware } from '../types.js';
4
3
  export declare const getMiddlerwareKey: (middleware: Middleware) => string;
5
4
  export declare const createMiddlewareKey: (type: MiddlewareType, stage: MiddlewareStage) => string;
6
- export declare const isLayerIherited: (current: Layer, parent: Layer) => boolean;
7
- export declare const isResourceAvailable: (resource: BasicResource, layer: Layer) => boolean;
8
- export declare const layersOrder: Layer[];
9
- export declare const getAllServices: (services: InLayer<Record<string, Service>>, layer: Layer, id: string) => Service[];
10
5
  export declare const applyMiddlewares: <C extends BasicConfig, T extends BasicContext<C>>(context: T, middlewares: Record<string, Middleware[]>, type: MiddlewareType, stage: MiddlewareStage, args?: Record<string, string | undefined>) => Promise<void[]>;
11
6
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,eAA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EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WACtE,CAAC,eACG,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,QACnC,cAAc,SACb,eAAe,SACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,oBAG1C,CAAA"}
@@ -1,15 +1,4 @@
1
- import { Layer } from '../consts.js';
2
1
  export const getMiddlerwareKey = (middleware) => createMiddlewareKey(middleware.type, middleware.stage);
3
2
  export const createMiddlewareKey = (type, stage) => `${type}:${stage}`;
4
- export const isLayerIherited = (current, parent) => (current === parent) || (layersOrder.indexOf(parent) > layersOrder.indexOf(current));
5
- export const isResourceAvailable = (resource, layer) => resource.layers == null || resource.layers.some(_layer => isLayerIherited(_layer, layer));
6
- export const layersOrder = [
7
- Layer.System,
8
- Layer.Global,
9
- Layer.Service,
10
- Layer.Entity,
11
- Layer.User
12
- ];
13
- export const getAllServices = (services, layer, id) => services?.[layer]?.[id] != null ? Object.values(services[layer][id]) : [];
14
3
  export const applyMiddlewares = (context, middlewares, type, stage, args) => Promise.all(middlewares[createMiddlewareKey(type, stage)]?.map(async (middleware) => middleware.apply(context, args)) ?? []);
15
4
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmC,MAAM,cAAc,CAAA;AAIrE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,UAAsB,EAAE,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;AAEnH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAoB,EAAE,KAAsB,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAA;AAEvG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAc,EAAE,MAAa,EAAW,EAAE,CACxE,CAAC,O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AAiB,GAAG,CAAC,UAAsB,EAAE,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;AAEnH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAoB,EAAE,KAAsB,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAA;AAEvG,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,OAAU,EACV,WAAyC,EACzC,IAAoB,EACpB,KAAsB,EACtB,IAAyC,EACzC,EAAE,CAAC,OAAO,CAAC,GAAG,CACd,WAAW,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,EAAC,UAAU,EAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAO,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,CACpH,CAAA"}
@@ -1,3 +1,2 @@
1
1
  export * from './context.js';
2
- export * from './layer.js';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
@@ -1,3 +1,2 @@
1
1
  export * from './context.js';
2
- export * from './layer.js';
3
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/context",
3
- "version": "0.1.18-rc.1",
3
+ "version": "0.1.18-rc.10",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/config.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { AppType, Layer } from './consts.js'
1
+ import { AppType } from './consts.js'
2
2
  import type { BasicConfig } from './types.js'
3
3
 
4
4
  export const makeBasicConfig = <C extends BasicConfig>(type: AppType, service: string, cfg?: Partial<C>): C => {
5
5
  const config = {
6
6
  ready: false,
7
7
  service,
8
- layer: type === AppType.Frontend ? Layer.Service : Layer.System,
9
8
  type,
10
9
  debug: {},
11
10
  services: {},
package/src/consts.ts CHANGED
@@ -1,12 +1,4 @@
1
1
 
2
- export enum Layer {
3
- System = 'system',
4
- Global = 'global',
5
- Service = 'service',
6
- Entity = 'entity',
7
- User = 'user'
8
- }
9
-
10
2
  export enum AppType {
11
3
  Backend = 'backend',
12
4
  Frontend = 'frontend',
@@ -26,8 +18,7 @@ export enum ContextStage {
26
18
  export enum MiddlewareStage {
27
19
  Configuration = 'configuration',
28
20
  Loading = 'loading',
29
- Ready = 'ready',
30
- Switching = 'switching'
21
+ Ready = 'ready'
31
22
  }
32
23
 
33
24
  export const CONFIG_RECORD = 'records'
package/src/context.ts CHANGED
@@ -1,19 +1,21 @@
1
- import { ContextStage, Layer, MiddlewareStage, MiddlewareType } from './consts.js'
2
- import type { BasicConfig, BasicContext, Middleware, BasicEntrypoint, BasicModule, BasicResource, Service } from './types.js'
3
- // import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable, layersOrder } from './utils/context.js'
4
- import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable } from './utils/context.js'
5
- import { DEFAULT, InLayer, initializeLayer } from './utils/layer.js'
1
+ import { ContextStage, MiddlewareStage, MiddlewareType } from './consts.js'
2
+ import type {
3
+ BasicConfig, BasicContext, Middleware, BasicEntrypoint, BasicResource, EntrypointReference, Service
4
+ } from './types.js'
5
+ import { applyMiddlewares, getMiddlerwareKey } from './utils/context.js'
6
6
 
7
7
  type Entrypoint = BasicEntrypoint
8
8
 
9
9
  export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C> => {
10
- const services = {} as InLayer<Record<string, Service>>
11
- const entrypoints = {} as InLayer<Record<string, Entrypoint>>
12
- const resources = {} as InLayer<Record<string, BasicResource>>
10
+ /**
11
+ * One flat registry per kind, keyed by alias. Registering an alias twice replaces the
12
+ * earlier entry — application entrypoint lists are routinely spread together and the
13
+ * later declaration is the one the app means.
14
+ */
15
+ const services: Record<string, Service> = {}
16
+ const entrypoints: Record<string, Entrypoint> = {}
17
+ const resources: Record<string, BasicResource> = {}
13
18
  const middlewares: Record<string, Middleware[]> = {}
14
- const allServices: Record<string, Service> = {}
15
- const allEntrypoints: Record<string, Entrypoint> = {}
16
- const allResources: Record<string, BasicResource> = {}
17
19
 
18
20
  let configure: (res: boolean) => void
19
21
  let initialize: (resv: boolean) => void
@@ -21,8 +23,6 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
21
23
  const configured = new Promise<boolean>(resolve => { configure = resolve })
22
24
  const initialized = new Promise<boolean>(resolve => { initialize = resolve })
23
25
 
24
- // const contexts: Record<string, BasicContext<C>> = {}
25
-
26
26
  const inLazyInit = new Set<Service>()
27
27
 
28
28
  const context: BasicContext<C> = {
@@ -59,7 +59,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
59
59
 
60
60
  await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration)
61
61
 
62
- await getAllServices(services, context.cfg.layer, context.cfg.layerId ?? DEFAULT).reduce(
62
+ await Object.values(services).reduce(
63
63
  async (previous, service) => {
64
64
  await previous
65
65
  if (!service.initialized) {
@@ -75,12 +75,9 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
75
75
 
76
76
  await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading)
77
77
 
78
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId ?? DEFAULT)
79
- await Object.values(resources[context.cfg.layer][id]).reduce(async (previous, resource) => {
78
+ await Object.values(resources).reduce(async (previous, resource) => {
80
79
  await previous
81
- if (isResourceAvailable(resource, context.cfg.layer)) {
82
- await resource.init?.()
83
- }
80
+ await resource.init?.()
84
81
  }, Promise.resolve())
85
82
 
86
83
  await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading)
@@ -95,24 +92,13 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
95
92
  },
96
93
 
97
94
  registerService: <T>(service: Service) => {
98
- const id = initializeLayer(services, context.cfg.layer, context.cfg.layerId)
99
- service = service.registerContext(context)
100
-
101
- if (allServices[service.alias] == null) {
102
- allServices[service.alias] = service
103
- }
104
- services[context.cfg.layer][id][service.alias] = service
95
+ services[service.alias] = service.registerContext(context)
105
96
 
106
97
  return context as T
107
98
  },
108
99
 
109
100
  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
- }
115
- entrypoints[context.cfg.layer][id][entrypoint.alias] = entrypoint
101
+ entrypoints[entrypoint.alias] = entrypoint.registerContext(context)
116
102
 
117
103
  return context as T
118
104
  },
@@ -122,19 +108,8 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
122
108
  return context as T
123
109
  },
124
110
 
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
-
131
111
  registerResource: <T>(resource: BasicResource) => {
132
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId)
133
- resource = resource.registerContext(context)
134
- if (allResources[resource.alias] == null) {
135
- allResources[resource.alias] = resource
136
- }
137
- resources[context.cfg.layer][id][resource.alias] = resource
112
+ resources[resource.alias] = resource.registerContext(context)
138
113
 
139
114
  return context as T
140
115
  },
@@ -154,15 +129,9 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
154
129
  },
155
130
 
156
131
  service: <T>(alias: string) => {
157
- const id = initializeLayer(services, context.cfg.layer, context.cfg.layerId)
158
-
159
- let _service: Service
160
- if (services[context.cfg.layer]?.[id]?.[alias] != null) {
161
- _service = services[context.cfg.layer][id][alias]
162
- } else if (services[Layer.Global]?.[id]?.[alias] != null) {
163
- _service = services[context.cfg.layer][id][alias]
164
- } else {
165
- throw new SyntaxError(`Service ${alias} not found in layer ${context.cfg.layer}`)
132
+ const _service = services[alias]
133
+ if (_service == null) {
134
+ throw new SyntaxError(`Service ${alias} not found`)
166
135
  }
167
136
  if (!_service.initialized) {
168
137
  if (_service.lazyInit != null) {
@@ -179,99 +148,28 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
179
148
  return _service as T
180
149
  },
181
150
 
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
151
+ entrypoint: <T extends Entrypoint>(reference: EntrypointReference<T> | string) => {
152
+ const alias = typeof reference === 'string' ? reference : reference.alias
153
+ if (entrypoints[alias] != null) {
154
+ return entrypoints[alias] as T
186
155
  }
187
156
  throw new SyntaxError(`Entrypoint ${alias} not found`)
188
157
  },
189
158
 
190
- /** @deprecated use entrypoint */
191
- module: <T>(alias: string) => context.entrypoint<any>(alias) as T,
192
-
193
159
  resource: <T extends BasicResource>(alias: string) => {
194
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId)
195
- if (resources[context.cfg.layer][id][alias] != null) {
196
- const resource = resources[context.cfg.layer][id][alias] as T
197
-
198
- return resource
160
+ if (resources[alias] != null) {
161
+ return resources[alias] as T
199
162
  }
200
163
  throw new SyntaxError(`Resource ${alias} not found`)
201
164
  },
202
165
 
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[]
206
- },
207
-
208
- /** @deprecated use entrypoints */
209
- modules: <T>() => context.entrypoints<any>() as T[],
210
-
211
- /**
212
- * @TODO Unfortunatly module cloning between contexts is quite unstable.
213
- * And it looks like in some cases it relies on modules that aren't really clonned.
214
- * The problem is that the not cloned modules are changing their context accross all context
215
- * layers and we can't rely on such behaviour.
216
- * So we disabled context update as a whole and all functionality that relies on it
217
- * cause in curent release mixed tenancy is not in use in any project and it looks like
218
- * there is no short term plans to use it some way.
219
- */
220
- updateContext: async <T>(_id?: string, _layer?: Layer) => {
221
- return context as T
222
-
223
- // const index = layersOrder.indexOf(context.cfg.layer)
224
- // layer = layer ?? (layersOrder[index + 1] != null ? layersOrder[index + 1] : undefined)
225
- // if (layer == null) {
226
- // throw new SyntaxError("There is no next layer to switch to")
227
- // }
228
-
229
- // if ([Layer.Entity, Layer.User].includes(layer) && id == null) {
230
- // throw new SyntaxError(`Cannot switch to layer ${layer} without id`)
231
- // }
232
-
233
- // id = initializeLayer(resources, layer, id)
234
-
235
- // // Cache initalized context layers
236
- // const key = `${layer}:${id}`
237
- // if (key in contexts) {
238
- // return contexts[key] as T
239
- // }
240
-
241
- // const _config: C = JSON.parse(JSON.stringify(context.cfg))
242
- // _config.layer = layer
243
- // _config.ready = false
244
- // _config.layerId = id
245
- // // @TODO we need to make a rule to store all makeContext methods after they are applied
246
- // const _context = context.makeContext != null ? context.makeContext(_config) : makeBasicContext(_config)
247
-
248
- // Object.values(middlewares).flatMap(middlewares => middlewares)
249
- // .forEach(middleware => _context.registerMiddleware(middleware))
250
-
251
- // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Config, MiddlewareStage.Switching, { layer, id })
252
-
253
- // Object.values(allServices).forEach(service => _context.registerService(service))
254
-
255
- // Object.values(allEntrypoints).forEach(ep => _context.registerEntrypoint(ep))
256
-
257
- // Object.values(allResources).forEach(resource => _context.registerResource(resource))
258
-
259
- // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Context, MiddlewareStage.Switching, { layer, id })
260
-
261
- // _context.stage = ContextStage.Loading
262
- // await _context.configure().init()
263
-
264
- // return (contexts[key] = _context) as T
265
- },
266
-
267
- hasResource: alias => allResources[alias] != null,
166
+ entrypoints: <T extends Entrypoint>() => Object.values(entrypoints) as T[],
268
167
 
269
- hasService: alias => allServices[alias] != null,
168
+ hasResource: alias => resources[alias] != null,
270
169
 
271
- hasEntrypoint: alias => allEntrypoints[alias] != null,
170
+ hasService: alias => services[alias] != null,
272
171
 
273
- /** @deprecated use hasEntrypoint */
274
- hasModule: alias => context.hasEntrypoint(alias),
172
+ hasEntrypoint: alias => entrypoints[alias] != null,
275
173
  }
276
174
 
277
175
  return context
package/src/helper.ts CHANGED
@@ -1,21 +1,14 @@
1
- import { Layer } from './consts.js'
2
1
  import type { Contextual, BasicContext, BasicConfig } from './types.js'
3
2
 
4
3
  export const appendContextual = <T extends Contextual>(alias: string, contextual: Partial<T>): T => {
5
4
  contextual.alias = alias
6
5
  contextual.registerContext = <T, C extends BasicConfig>(context: BasicContext<C>) => {
7
- const _contextual = contextual.ctx == null
8
- ? contextual
9
- : contextual.reinitializeContext != null
10
- ? contextual.reinitializeContext(context) : contextual
11
-
12
- // We do NOT update context when it's the same contextual with already set context
13
- // Actuall we just do not need to switch context in many on the level of context consumer
14
- if (_contextual.ctx == null) {
15
- _contextual.ctx = context
6
+ // A contextual binds to exactly one context — the first one that registers it.
7
+ if (contextual.ctx == null) {
8
+ contextual.ctx = context
16
9
  }
17
10
 
18
- return _contextual as T
11
+ return contextual as T
19
12
  }
20
13
 
21
14
  contextual.assertCtx = (
@@ -25,10 +18,6 @@ export const appendContextual = <T extends Contextual>(alias: string, contextual
25
18
  return contextual as T
26
19
  }
27
20
 
28
- // export type UpdContextType<C extends Config, T extends Context<C>, ExtraType> = T & ExtraType
29
-
30
- // export type UpdConfigType<T extends Config, ExtraType> = T & ExtraType
31
-
32
21
  /**
33
22
  * @throws {SyntaxError}
34
23
  */
@@ -38,6 +27,3 @@ export const assertContext = <C extends BasicConfig, T extends BasicContext<C>>(
38
27
  }
39
28
  return ctx as T
40
29
  }
41
-
42
- export const isContextWithoutIds = <C extends BasicConfig, T extends BasicContext<C>>(context: T): boolean =>
43
- [Layer.System, Layer.Global, Layer.Service].includes(context.cfg.layer)
package/src/types.ts CHANGED
@@ -1,13 +1,11 @@
1
- import type { AppType, ContextStage, Layer, MiddlewareStage, MiddlewareType, CONFIG_RECORD } from './consts.js'
1
+ import type { AppType, ContextStage, MiddlewareStage, MiddlewareType, CONFIG_RECORD } from './consts.js'
2
2
 
3
3
  export interface BasicConfig {
4
4
  ready: boolean
5
5
  service: string
6
6
  // Is used as username of the service (e.g. for looking up for autehntication keys)
7
7
  alias?: string
8
- layer: Layer
9
8
  type: AppType
10
- layerId?: string
11
9
  services?: Record<string, Object>
12
10
  [CONFIG_RECORD]?: ConfigRecord[]
13
11
  debug?: {
@@ -31,13 +29,11 @@ interface ConfigRecordItem extends Record<
31
29
  export interface Contextual {
32
30
  ctx?: BasicContext<any>
33
31
  alias: string
34
- reinitializeContext?: <T extends Contextual>(context: BasicContext<any>) => T // This method is a fix to replace context inside closed scope
35
32
  registerContext: <T extends Contextual, C extends BasicConfig>(context: BasicContext<C>) => T
36
33
  assertCtx: <C extends BasicConfig, T extends BasicContext<C>>(location?: string) => T
37
34
  }
38
35
 
39
36
  export interface Service extends Contextual {
40
- layers?: Layer[]
41
37
  initialized: boolean
42
38
  init?: () => Promise<void>
43
39
  lazyInit?: () => Promise<void>
@@ -56,17 +52,22 @@ export interface LazyService extends Service {
56
52
 
57
53
  export interface BasicEntrypoint extends Contextual {
58
54
  _entrypoint: true
59
- _module: true
60
55
  }
61
56
 
62
- /** @deprecated use BasicEntrypoint */
63
- export interface BasicModule extends Contextual {
64
- _module: true
57
+ /**
58
+ * A stable reference to an entrypoint registered in a context.
59
+ *
60
+ * Contract packages use this instead of exporting raw alias strings. The optional type member is
61
+ * deliberately phantom: it lets `context.entrypoint(protocol)` infer the context-bound module
62
+ * without changing the wire alias or adding registry-wide declaration merging.
63
+ */
64
+ export interface EntrypointReference<T extends BasicEntrypoint = BasicEntrypoint> {
65
+ readonly alias: string
66
+ readonly entrypointType?: T
65
67
  }
66
68
 
67
69
  export interface BasicResource extends Contextual {
68
- layers?: Layer[]
69
- init?: () => Promise<void> // After context switch the resource should be able to reinitialize
70
+ init?: () => Promise<void>
70
71
  }
71
72
 
72
73
  export interface Middleware {
@@ -75,6 +76,12 @@ export interface Middleware {
75
76
  apply: <C extends BasicConfig, T extends BasicContext<C>>(context: T, args?: Record<string, string | undefined>) => Promise<void>
76
77
  }
77
78
 
79
+ /**
80
+ * The DI container. One context is built per process by one factory: a layer specific
81
+ * factory composes the layer below it and then `append*` mixins register what the
82
+ * application needs. There is no child context and nothing is stored for re-creation —
83
+ * a service, a resource and an entrypoint each bind to exactly one context.
84
+ */
78
85
  export interface BasicContext<C extends BasicConfig> {
79
86
  cfg: C
80
87
  stage: ContextStage
@@ -82,7 +89,6 @@ export interface BasicContext<C extends BasicConfig> {
82
89
  waitForInitialized: () => Promise<boolean>
83
90
  configure: <T extends BasicContext<C>>() => T
84
91
  init: <T extends BasicContext<C>>() => Promise<T>
85
- updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>
86
92
  registerService: <T extends BasicContext<C>>(service: Service) => T
87
93
  registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T
88
94
  registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T
@@ -91,24 +97,14 @@ export interface BasicContext<C extends BasicConfig> {
91
97
 
92
98
  get config(): Promise<C>
93
99
  service: <T extends Service>(alias: string) => T
94
- entrypoint: <T extends BasicEntrypoint>(alias: string) => T
100
+ entrypoint: {
101
+ <T extends BasicEntrypoint>(reference: EntrypointReference<T>): T
102
+ <T extends BasicEntrypoint>(reference: EntrypointReference | string): T
103
+ }
95
104
  resource: <T extends BasicResource>(alias: string) => T
96
105
  hasResource: (alias: string) => boolean
97
106
  hasService: (alias: string) => boolean
98
107
  hasEntrypoint: (alias: string) => boolean
99
108
 
100
109
  entrypoints: <T extends BasicEntrypoint>() => T[]
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 */
111
- modules: <T extends BasicModule>() => T[]
112
-
113
- makeContext?: <T extends BasicContext<C>>(cfg: C) => T
114
110
  }