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

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 +13 -43
  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
package/README.md CHANGED
@@ -4,15 +4,15 @@ Lightweight dependency injection and service lifecycle management for fullstack
4
4
 
5
5
  ## Overview
6
6
 
7
- - Context holds services, modules, and resources; passed top-down through the app
7
+ - Context holds services, entrypoints, and resources in three flat registries keyed by alias; passed top-down through the app
8
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
9
+ - One context is built per process by a single factory and extended with idempotent `append*` mixins
10
+ - Route constants (`ROOT`, `HOME`, `GUEST`, `BASE`) are used by the entrypoint system across all packages
11
11
 
12
12
  ## Installation
13
13
 
14
14
  ```bash
15
- bun add @owlmeans/context
15
+ bun add @owlmeans/context@^0.1.18-rc.7
16
16
  ```
17
17
 
18
18
  ## Usage
@@ -66,10 +66,31 @@ Asserts that a context is defined; throws if not.
66
66
 
67
67
  Creates a context from a config object. Rarely used directly — prefer the higher-level `makeContext` from `@owlmeans/server-app` or `@owlmeans/client-context`.
68
68
 
69
+ A factory calls the factory of the layer below it, applies its own idempotent `append*` mixins, and returns that same context:
70
+
71
+ ```typescript
72
+ export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
73
+ const context = makeServerContext<C, T>(cfg)
74
+ appendMyService<C, T>(context)
75
+ return context
76
+ }
77
+ ```
78
+
79
+ Nothing is stored for re-creation — a service, a resource and an entrypoint each bind to exactly one context.
80
+
81
+ ### Registries
82
+
83
+ Three flat maps keyed by alias. Registering the same alias twice replaces the earlier entry.
84
+
85
+ ```typescript
86
+ context.registerService(service) // context.service(alias), context.hasService(alias)
87
+ context.registerResource(resource) // context.resource(alias), context.hasResource(alias)
88
+ context.registerEntrypoints(entrypoints) // context.entrypoint(protocol), context.entrypoints(), context.hasEntrypoint(alias)
89
+ ```
90
+
69
91
  ### Enums
70
92
 
71
93
  ```typescript
72
- enum Layer { System, Global, Service, Entity, User }
73
94
  enum AppType { Backend, Frontend }
74
95
  enum ContextStage { Configuration, Loading, Ready }
75
96
  ```
@@ -99,7 +120,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
99
120
  your project's skill store (`.agents/skills/`):
100
121
 
101
122
  ```sh
102
- npx @owlmeans/agent-skills
123
+ npx @owlmeans/agent-skills@^0.1.18-rc.15
103
124
  ```
104
125
 
105
126
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/context",
4
- "version": "0.1.18-rc.0",
5
- "generatedAt": "2026-08-16T22:20:50.516Z",
4
+ "version": "0.1.18-rc.11",
5
+ "generatedAt": "2026-09-12T08:39:52.737Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,53 +1,23 @@
1
1
  ---
2
2
  name: context
3
- description: How to use @owlmeans/context — base context (DI container) factory, registerService(), service<T>() lookups, entrypoint<ClientEntrypoint<T>>() resolution. Auto-invoked when importing context primitives or building a makeContext factory.
4
- user-invocable: false
3
+ description: Use OwlMeans context services, resources and typed entrypoint protocol references.
5
4
  ---
6
5
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
7
6
 
8
- # @owlmeans/context
7
+ # Context lookups
9
8
 
10
- **Layer:** Core
11
- **Install:** `"@owlmeans/context": "^0.1.18-rc.0"` in `dependencies`
9
+ Use a protocol declaration directly when obtaining an entrypoint. The declaration supplies the
10
+ registered entrypoint’s request and response types.
12
11
 
13
- ## Key Exports
14
-
15
- | Export | Description |
16
- |--------|-------------|
17
- | `Context<C>` types | Generic context interface (typed by Config) |
18
- | `makeBasicContext` | Low-level factory — usually you extend a layer-specific factory instead |
19
- | `registerService` (method) | Add a service to the DI container |
20
- | `service<T>(alias)` (method) | Resolve a service by alias |
21
- | `entrypoint<ClientEntrypoint<T>>(alias)` (method) | Resolve an entrypoint to call cross-service |
22
- | `Service` types | Service interface and lifecycle |
23
- | Constants | Built-in service/entrypoint aliases |
24
-
25
- ## Usage
26
-
27
- Always extend a layer-specific factory (`@owlmeans/server-context`, `@owlmeans/web-panel`, etc.) rather than calling the basic factory directly. Always reassign `context.makeContext` so child contexts inherit the typed factory:
28
-
29
- ```typescript
30
- import { makeBackendContext } from '@owlmeans/server-context'
31
-
32
- export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
33
- const context = makeBackendContext<C, T>(cfg)
34
- context.registerService(makeMyService())
35
- context.makeContext = makeContext as typeof context.makeContext
36
- return context
37
- }
38
- ```
39
-
40
- Resolve services and call cross-service entrypoints from a handler:
41
-
42
- ```typescript
43
- const someService = ctx.service<MyService>(MY_SERVICE_ALIAS)
44
-
45
- const [response] = await ctx.entrypoint<ClientEntrypoint<ResponseType>>(
46
- externalService.action.alias
47
- ).call({ body: { ... } })
12
+ ```ts
13
+ const project = await context.entrypoint(projectEntrypoints.get).call({
14
+ params: { id },
15
+ })
48
16
  ```
49
17
 
50
- ## Depends On
18
+ Use `context.service(alias)` for registered services and context resource APIs for data access.
19
+ Protocol declarations are shared immutable values; context registration receives local server or
20
+ client entrypoints created with `bind()`, `bindAll()` or `bindScreen()`.
51
21
 
52
- - `@owlmeans/config` — context is parameterized by a Config
53
- - `@owlmeans/entrypoint` — `ClientEntrypoint<T>` type for cross-service calls
22
+ Keep organization entity addressing on the wire as `entitySlug`. Resolve the stable `entityId`
23
+ inside the context before persisting relations or calling third parties.
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,QAAQ,OAAO,WAAW,MAAM,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAG,CAazG,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,WAAW,QAAQ,OAAO,WAAW,MAAM,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAG,CAYzG,CAAA"}
package/build/config.js CHANGED
@@ -1,9 +1,7 @@
1
- import { AppType, Layer } from './consts.js';
2
1
  export const makeBasicConfig = (type, service, cfg) => {
3
2
  const config = {
4
3
  ready: false,
5
4
  service,
6
- layer: type === AppType.Frontend ? Layer.Service : Layer.System,
7
5
  type,
8
6
  debug: {},
9
7
  services: {},
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAG5C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,IAAa,EAAE,OAAe,EAAE,GAAgB,EAAK,EAAE;IAC5G,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,KAAK;QACZ,OAAO;QACP,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;QAC/D,IAAI;QACJ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,GAAG,GAAG;KACF,CAAA;IAEN,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,IAAa,EAAE,OAAe,EAAE,GAAgB,EAAK,EAAE;IAC5G,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,KAAK;QACZ,OAAO;QACP,IAAI;QACJ,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,EAAE;QACX,GAAG,GAAG;KACF,CAAA;IAEN,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
package/build/consts.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- export declare enum Layer {
2
- System = "system",
3
- Global = "global",
4
- Service = "service",
5
- Entity = "entity",
6
- User = "user"
7
- }
8
1
  export declare enum AppType {
9
2
  Backend = "backend",
10
3
  Frontend = "frontend"
@@ -21,8 +14,7 @@ export declare enum ContextStage {
21
14
  export declare enum MiddlewareStage {
22
15
  Configuration = "configuration",
23
16
  Loading = "loading",
24
- Ready = "ready",
25
- Switching = "switching"
17
+ Ready = "ready"
26
18
  }
27
19
  export declare const CONFIG_RECORD = "records";
28
20
  export declare const EMPTY_ENTITY = "[UNDEFINED_ENTITY]";
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,KAAK;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,cAAc;IACxB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,oBAAY,YAAY;IACtB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,oBAAY,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,SAAS,cAAc;CACxB;AAED,eAAO,MAAM,aAAa,YAAY,CAAA;AAEtC,eAAO,MAAM,YAAY,uBAAuB,CAAA;AAChD,eAAO,MAAM,aAAa,wBAAwB,CAAA;AAGlD;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA;AAC5B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA"}
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,OAAO;IACjB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,cAAc;IACxB,MAAM,WAAW;IACjB,OAAO,YAAY;CACpB;AAED,oBAAY,YAAY;IACtB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,oBAAY,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,aAAa,YAAY,CAAA;AAEtC,eAAO,MAAM,YAAY,uBAAuB,CAAA;AAChD,eAAO,MAAM,aAAa,wBAAwB,CAAA;AAGlD;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA;AAC5B;;GAEG;AACH,eAAO,MAAM,IAAI,SAAS,CAAA;AAC1B;;GAEG;AACH,eAAO,MAAM,KAAK,UAAU,CAAA"}
package/build/consts.js CHANGED
@@ -1,11 +1,3 @@
1
- export var Layer;
2
- (function (Layer) {
3
- Layer["System"] = "system";
4
- Layer["Global"] = "global";
5
- Layer["Service"] = "service";
6
- Layer["Entity"] = "entity";
7
- Layer["User"] = "user";
8
- })(Layer || (Layer = {}));
9
1
  export var AppType;
10
2
  (function (AppType) {
11
3
  AppType["Backend"] = "backend";
@@ -27,7 +19,6 @@ export var MiddlewareStage;
27
19
  MiddlewareStage["Configuration"] = "configuration";
28
20
  MiddlewareStage["Loading"] = "loading";
29
21
  MiddlewareStage["Ready"] = "ready";
30
- MiddlewareStage["Switching"] = "switching";
31
22
  })(MiddlewareStage || (MiddlewareStage = {}));
32
23
  export const CONFIG_RECORD = 'records';
33
24
  export const EMPTY_ENTITY = '[UNDEFINED_ENTITY]';
@@ -1 +1 @@
1
- {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,KAMX;AAND,WAAY,KAAK;IACf,0BAAiB,CAAA;IACjB,0BAAiB,CAAA;IACjB,4BAAmB,CAAA;IACnB,0BAAiB,CAAA;IACjB,sBAAa,CAAA;AACf,CAAC,EANW,KAAK,KAAL,KAAK,QAMhB;AAED,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACjB,8BAAmB,CAAA;IACnB,gCAAqB,CAAA;AACvB,CAAC,EAHW,OAAO,KAAP,OAAO,QAGlB;AAED,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,qCAAmB,CAAA;AACrB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,+CAA+B,CAAA;IAC/B,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACjB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,kDAA+B,CAAA;IAC/B,sCAAmB,CAAA;IACnB,kCAAe,CAAA;IACf,0CAAuB,CAAA;AACzB,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAA;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAA;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,qBAAqB,CAAA;AAElD,wBAAwB;AACxB;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,M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AC,MAAM,KAAK,GAAG,OAAO,CAAA"}
@@ -1 +1 @@
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,OAAO,CAAC,KAAG,YAAY,CAAC,CAAC,CA6Q9E,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EAAE,YAAY,EAC1B,MAAM,YAAY,CAAA;AAKnB,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,OAAO,CAAC,KAAG,YAAY,CAAC,CAAC,CAuK9E,CAAA"}
package/build/context.js CHANGED
@@ -1,20 +1,19 @@
1
- import { ContextStage, Layer, MiddlewareStage, MiddlewareType } from './consts.js';
2
- // import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable, layersOrder } from './utils/context.js'
3
- import { applyMiddlewares, getAllServices, getMiddlerwareKey, isResourceAvailable } from './utils/context.js';
4
- import { DEFAULT, initializeLayer } from './utils/layer.js';
1
+ import { ContextStage, MiddlewareStage, MiddlewareType } from './consts.js';
2
+ import { applyMiddlewares, getMiddlerwareKey } from './utils/context.js';
5
3
  export const makeBasicContext = (cfg) => {
4
+ /**
5
+ * One flat registry per kind, keyed by alias. Registering an alias twice replaces the
6
+ * earlier entry — application entrypoint lists are routinely spread together and the
7
+ * later declaration is the one the app means.
8
+ */
6
9
  const services = {};
7
10
  const entrypoints = {};
8
11
  const resources = {};
9
12
  const middlewares = {};
10
- const allServices = {};
11
- const allEntrypoints = {};
12
- const allResources = {};
13
13
  let configure;
14
14
  let initialize;
15
15
  const configured = new Promise(resolve => { configure = resolve; });
16
16
  const initialized = new Promise(resolve => { initialize = resolve; });
17
- // const contexts: Record<string, BasicContext<C>> = {}
18
17
  const inLazyInit = new Set();
19
18
  const context = {
20
19
  cfg,
@@ -39,7 +38,7 @@ export const makeBasicContext = (cfg) => {
39
38
  return context;
40
39
  }
41
40
  await applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration);
42
- await getAllServices(services, context.cfg.layer, context.cfg.layerId ?? DEFAULT).reduce(async (previous, service) => {
41
+ await Object.values(services).reduce(async (previous, service) => {
43
42
  await previous;
44
43
  if (!service.initialized) {
45
44
  if (service.init != null) {
@@ -51,12 +50,9 @@ export const makeBasicContext = (cfg) => {
51
50
  }
52
51
  }, Promise.resolve());
53
52
  await applyMiddlewares(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading);
54
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId ?? DEFAULT);
55
- await Object.values(resources[context.cfg.layer][id]).reduce(async (previous, resource) => {
53
+ await Object.values(resources).reduce(async (previous, resource) => {
56
54
  await previous;
57
- if (isResourceAvailable(resource, context.cfg.layer)) {
58
- await resource.init?.();
59
- }
55
+ await resource.init?.();
60
56
  }, Promise.resolve());
61
57
  await applyMiddlewares(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading);
62
58
  context.stage = ContextStage.Ready;
@@ -66,38 +62,19 @@ export const makeBasicContext = (cfg) => {
66
62
  return context;
67
63
  },
68
64
  registerService: (service) => {
69
- const id = initializeLayer(services, context.cfg.layer, context.cfg.layerId);
70
- service = service.registerContext(context);
71
- if (allServices[service.alias] == null) {
72
- allServices[service.alias] = service;
73
- }
74
- services[context.cfg.layer][id][service.alias] = service;
65
+ services[service.alias] = service.registerContext(context);
75
66
  return context;
76
67
  },
77
68
  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
- }
83
- entrypoints[context.cfg.layer][id][entrypoint.alias] = entrypoint;
69
+ entrypoints[entrypoint.alias] = entrypoint.registerContext(context);
84
70
  return context;
85
71
  },
86
72
  registerEntrypoints: (eps) => {
87
73
  eps.forEach(ep => context.registerEntrypoint(ep));
88
74
  return context;
89
75
  },
90
- /** @deprecated use registerEntrypoint */
91
- registerModule: (module) => context.registerEntrypoint(module),
92
- /** @deprecated use registerEntrypoints */
93
- registerModules: (mods) => context.registerEntrypoints(mods),
94
76
  registerResource: (resource) => {
95
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId);
96
- resource = resource.registerContext(context);
97
- if (allResources[resource.alias] == null) {
98
- allResources[resource.alias] = resource;
99
- }
100
- resources[context.cfg.layer][id][resource.alias] = resource;
77
+ resources[resource.alias] = resource.registerContext(context);
101
78
  return context;
102
79
  },
103
80
  registerMiddleware: (middleware) => {
@@ -112,16 +89,9 @@ export const makeBasicContext = (cfg) => {
112
89
  return configured.then(() => context.cfg);
113
90
  },
114
91
  service: (alias) => {
115
- const id = initializeLayer(services, context.cfg.layer, context.cfg.layerId);
116
- let _service;
117
- if (services[context.cfg.layer]?.[id]?.[alias] != null) {
118
- _service = services[context.cfg.layer][id][alias];
119
- }
120
- else if (services[Layer.Global]?.[id]?.[alias] != null) {
121
- _service = services[context.cfg.layer][id][alias];
122
- }
123
- else {
124
- throw new SyntaxError(`Service ${alias} not found in layer ${context.cfg.layer}`);
92
+ const _service = services[alias];
93
+ if (_service == null) {
94
+ throw new SyntaxError(`Service ${alias} not found`);
125
95
  }
126
96
  if (!_service.initialized) {
127
97
  if (_service.lazyInit != null) {
@@ -138,76 +108,23 @@ export const makeBasicContext = (cfg) => {
138
108
  }
139
109
  return _service;
140
110
  },
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];
111
+ entrypoint: (reference) => {
112
+ const alias = typeof reference === 'string' ? reference : reference.alias;
113
+ if (entrypoints[alias] != null) {
114
+ return entrypoints[alias];
145
115
  }
146
116
  throw new SyntaxError(`Entrypoint ${alias} not found`);
147
117
  },
148
- /** @deprecated use entrypoint */
149
- module: (alias) => context.entrypoint(alias),
150
118
  resource: (alias) => {
151
- const id = initializeLayer(resources, context.cfg.layer, context.cfg.layerId);
152
- if (resources[context.cfg.layer][id][alias] != null) {
153
- const resource = resources[context.cfg.layer][id][alias];
154
- return resource;
119
+ if (resources[alias] != null) {
120
+ return resources[alias];
155
121
  }
156
122
  throw new SyntaxError(`Resource ${alias} not found`);
157
123
  },
158
- entrypoints: () => {
159
- const id = initializeLayer(entrypoints, context.cfg.layer, context.cfg.layerId);
160
- return Object.values(entrypoints[context.cfg.layer][id]);
161
- },
162
- /** @deprecated use entrypoints */
163
- modules: () => context.entrypoints(),
164
- /**
165
- * @TODO Unfortunatly module cloning between contexts is quite unstable.
166
- * And it looks like in some cases it relies on modules that aren't really clonned.
167
- * The problem is that the not cloned modules are changing their context accross all context
168
- * layers and we can't rely on such behaviour.
169
- * So we disabled context update as a whole and all functionality that relies on it
170
- * cause in curent release mixed tenancy is not in use in any project and it looks like
171
- * there is no short term plans to use it some way.
172
- */
173
- updateContext: async (_id, _layer) => {
174
- return context;
175
- // const index = layersOrder.indexOf(context.cfg.layer)
176
- // layer = layer ?? (layersOrder[index + 1] != null ? layersOrder[index + 1] : undefined)
177
- // if (layer == null) {
178
- // throw new SyntaxError("There is no next layer to switch to")
179
- // }
180
- // if ([Layer.Entity, Layer.User].includes(layer) && id == null) {
181
- // throw new SyntaxError(`Cannot switch to layer ${layer} without id`)
182
- // }
183
- // id = initializeLayer(resources, layer, id)
184
- // // Cache initalized context layers
185
- // const key = `${layer}:${id}`
186
- // if (key in contexts) {
187
- // return contexts[key] as T
188
- // }
189
- // const _config: C = JSON.parse(JSON.stringify(context.cfg))
190
- // _config.layer = layer
191
- // _config.ready = false
192
- // _config.layerId = id
193
- // // @TODO we need to make a rule to store all makeContext methods after they are applied
194
- // const _context = context.makeContext != null ? context.makeContext(_config) : makeBasicContext(_config)
195
- // Object.values(middlewares).flatMap(middlewares => middlewares)
196
- // .forEach(middleware => _context.registerMiddleware(middleware))
197
- // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Config, MiddlewareStage.Switching, { layer, id })
198
- // Object.values(allServices).forEach(service => _context.registerService(service))
199
- // Object.values(allEntrypoints).forEach(ep => _context.registerEntrypoint(ep))
200
- // Object.values(allResources).forEach(resource => _context.registerResource(resource))
201
- // await applyMiddlewares<C, BasicContext<C>>(_context, middlewares, MiddlewareType.Context, MiddlewareStage.Switching, { layer, id })
202
- // _context.stage = ContextStage.Loading
203
- // await _context.configure().init()
204
- // return (contexts[key] = _context) as T
205
- },
206
- hasResource: alias => allResources[alias] != null,
207
- hasService: alias => allServices[alias] != null,
208
- hasEntrypoint: alias => allEntrypoints[alias] != null,
209
- /** @deprecated use hasEntrypoint */
210
- hasModule: alias => context.hasEntrypoint(alias),
124
+ entrypoints: () => Object.values(entrypoints),
125
+ hasResource: alias => resources[alias] != null,
126
+ hasService: alias => services[alias] != null,
127
+ hasEntrypoint: alias => entrypoints[alias] != null,
211
128
  };
212
129
  return context;
213
130
  };
@@ -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,WAAW,GAAG,EAAyC,CAAA;IAC7D,MAAM,S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AAW,EAAE,GAAyB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAQ;QAE1E,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,IAAI;QAE9C,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI;QAE5C,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,IAAI;KACnD,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
package/build/helper.d.ts CHANGED
@@ -4,5 +4,4 @@ export declare const appendContextual: <T extends Contextual>(alias: string, con
4
4
  * @throws {SyntaxError}
5
5
  */
6
6
  export declare const assertContext: <C extends BasicConfig, T extends BasicContext<C>>(ctx: T | BasicContext<BasicConfig> | undefined, location?: string) => T;
7
- export declare const isContextWithoutIds: <C extends BasicConfig, T extends BasicContext<C>>(context: T) => boolean;
8
7
  //# sourceMappingURL=helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEvE,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,UAAU,SAAS,MAAM,cAAc,OAAO,CAAC,CAAC,CAAC,KAAG,CAsB9F,CAAA;AAMD;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,SAAS,aAAa,MAAM,KAAG,CAKnJ,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,KAAG,OAC1B,CAAA"}
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEvE,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,UAAU,SAAS,MAAM,cAAc,OAAO,CAAC,CAAC,CAAC,KAAG,CAgB9F,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,SAAS,aAAa,MAAM,KAAG,CAKnJ,CAAA"}
package/build/helper.js CHANGED
@@ -1,23 +1,15 @@
1
- import { Layer } from './consts.js';
2
1
  export const appendContextual = (alias, contextual) => {
3
2
  contextual.alias = alias;
4
3
  contextual.registerContext = (context) => {
5
- const _contextual = contextual.ctx == null
6
- ? contextual
7
- : contextual.reinitializeContext != null
8
- ? contextual.reinitializeContext(context) : contextual;
9
- // We do NOT update context when it's the same contextual with already set context
10
- // Actuall we just do not need to switch context in many on the level of context consumer
11
- if (_contextual.ctx == null) {
12
- _contextual.ctx = context;
4
+ // A contextual binds to exactly one context — the first one that registers it.
5
+ if (contextual.ctx == null) {
6
+ contextual.ctx = context;
13
7
  }
14
- return _contextual;
8
+ return contextual;
15
9
  };
16
10
  contextual.assertCtx = (location => assertContext(contextual.ctx, location ?? contextual.alias));
17
11
  return contextual;
18
12
  };
19
- // export type UpdContextType<C extends Config, T extends Context<C>, ExtraType> = T & ExtraType
20
- // export type UpdConfigType<T extends Config, ExtraType> = T & ExtraType
21
13
  /**
22
14
  * @throws {SyntaxError}
23
15
  */
@@ -27,5 +19,4 @@ export const assertContext = (ctx, location) => {
27
19
  }
28
20
  return ctx;
29
21
  };
30
- export const isContextWithoutIds = (context) => [Layer.System, Layer.Global, Layer.Service].includes(context.cfg.layer);
31
22
  //# sourceMapping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,EAAW,EAAE,CAC3G,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,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