@owlmeans/context 0.1.18-rc.5 → 0.1.18-rc.7
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 +25 -4
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/context/SKILL.md +8 -5
- package/build/config.d.ts.map +1 -1
- package/build/config.js +0 -2
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +1 -9
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +0 -9
- package/build/consts.js.map +1 -1
- package/build/context.d.ts.map +1 -1
- package/build/context.js +24 -108
- package/build/context.js.map +1 -1
- package/build/helper.d.ts +0 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +4 -13
- package/build/helper.js.map +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/types.d.ts +7 -23
- package/build/types.d.ts.map +1 -1
- package/build/utils/context.d.ts +2 -7
- package/build/utils/context.d.ts.map +1 -1
- package/build/utils/context.js +0 -11
- package/build/utils/context.js.map +1 -1
- package/build/utils/index.d.ts +0 -1
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +0 -1
- package/build/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +1 -2
- package/src/consts.ts +1 -10
- package/src/context.ts +28 -133
- package/src/helper.ts +4 -18
- package/src/types.ts +8 -27
- package/src/utils/context.ts +2 -20
- package/src/utils/index.ts +0 -1
- package/tests/context.ts +1 -2
- package/tests/service.spec.ts +1 -1
- package/build/.gitkeep +0 -0
- package/build/utils/layer.d.ts +0 -6
- package/build/utils/layer.d.ts.map +0 -1
- package/build/utils/layer.js +0 -12
- package/build/utils/layer.js.map +0 -1
- package/src/utils/layer.ts +0 -17
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@ Lightweight dependency injection and service lifecycle management for fullstack
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- Context holds services,
|
|
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
|
-
-
|
|
10
|
-
- Route constants (`ROOT`, `HOME`, `GUEST`, `BASE`) are used by the
|
|
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
|
|
|
@@ -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(alias), 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
|
```
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/context",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.7",
|
|
5
|
+
"generatedAt": "2026-09-01T16:28:56.997Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/context
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/context": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/context": "^0.1.18-rc.7"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
@@ -24,15 +24,18 @@ user-invocable: false
|
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
A context is created ONCE per process by ONE factory. Extend a layer-specific factory
|
|
28
|
+
(`@owlmeans/server-context`, `@owlmeans/web-panel`, etc.) rather than calling the basic factory
|
|
29
|
+
directly: your factory calls the factory below it, applies its own idempotent `append*(context)`
|
|
30
|
+
mixins and service registrations, and returns that same context. Nothing is stored for re-creation —
|
|
31
|
+
a service, a resource and an entrypoint each bind to exactly one context.
|
|
28
32
|
|
|
29
33
|
```typescript
|
|
30
|
-
import {
|
|
34
|
+
import { makeServerContext } from '@owlmeans/server-context'
|
|
31
35
|
|
|
32
36
|
export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
|
|
33
|
-
const context =
|
|
37
|
+
const context = makeServerContext<C, T>(cfg)
|
|
34
38
|
context.registerService(makeMyService())
|
|
35
|
-
context.makeContext = makeContext as typeof context.makeContext
|
|
36
39
|
return context
|
|
37
40
|
}
|
|
38
41
|
```
|
package/build/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
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,EAAE,MAAM,OAAO,EAAE,SAAS,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,CAYzG,CAAA"}
|
package/build/config.js
CHANGED
package/build/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
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]";
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,oBAAY,
|
|
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]';
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,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,eAIX;AAJD,WAAY,eAAe;IACzB,kDAA+B,CAAA;IAC/B,sCAAmB,CAAA;IACnB,kCAAe,CAAA;AACjB,CAAC,EAJW,eAAe,KAAf,eAAe,QAI1B;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,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA;AAC5B;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAA;AAC1B;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA"}
|
package/build/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAuD,MAAM,YAAY,CAAA;AAKhH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,KAAK,CAAC,KAAG,YAAY,CAAC,CAAC,CAsK9E,CAAA"}
|
package/build/context.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { ContextStage,
|
|
2
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
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) {
|
|
@@ -139,75 +109,21 @@ export const makeBasicContext = (cfg) => {
|
|
|
139
109
|
return _service;
|
|
140
110
|
},
|
|
141
111
|
entrypoint: (alias) => {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
return entrypoints[context.cfg.layer][id][alias];
|
|
112
|
+
if (entrypoints[alias] != null) {
|
|
113
|
+
return entrypoints[alias];
|
|
145
114
|
}
|
|
146
115
|
throw new SyntaxError(`Entrypoint ${alias} not found`);
|
|
147
116
|
},
|
|
148
|
-
/** @deprecated use entrypoint */
|
|
149
|
-
module: (alias) => context.entrypoint(alias),
|
|
150
117
|
resource: (alias) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const resource = resources[context.cfg.layer][id][alias];
|
|
154
|
-
return resource;
|
|
118
|
+
if (resources[alias] != null) {
|
|
119
|
+
return resources[alias];
|
|
155
120
|
}
|
|
156
121
|
throw new SyntaxError(`Resource ${alias} not found`);
|
|
157
122
|
},
|
|
158
|
-
entrypoints: () =>
|
|
159
|
-
|
|
160
|
-
|
|
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),
|
|
123
|
+
entrypoints: () => Object.values(entrypoints),
|
|
124
|
+
hasResource: alias => resources[alias] != null,
|
|
125
|
+
hasService: alias => services[alias] != null,
|
|
126
|
+
hasEntrypoint: alias => entrypoints[alias] != null,
|
|
211
127
|
};
|
|
212
128
|
return context;
|
|
213
129
|
};
|
package/build/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAIxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAwB,GAAM,EAAmB,EAAE;IACjF;;;;OAIG;IACH,MAAM,QAAQ,GAA4B,EAAE,CAAA;IAC5C,MAAM,WAAW,GAA+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AAM,IAAI,WAAW,CAAC,YAAY,KAAK,YAAY,CAAC,CAAA;QACtD,CAAC;QAED,WAAW,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
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"
|
|
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,EAAE,OAAO,MAAM,EAAE,YAAY,OAAO,CAAC,CAAC,CAAC,KAAG,CAgB9F,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,YAAY,CAAC,WAAW,CAAC,GAAG,SAAS,EAAE,WAAW,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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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
|
//# sourceMappingURL=helper.js.map
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"
|
|
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/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,kBAAkB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAOtF,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,OAAO;IAC3C,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAgCD,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,kBAAkB,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,kBAAkB,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAOtF,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,OAAO;IAC3C,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC;AAgCD,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,kBAAkB,EACxD,OAAO,MAAM,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,KACvD,CAAsE,CAAA;AAEzE,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,EACrD,OAAO,MAAM,EAAE,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,UAAU,CAAC,CAAC,CAAC,KACvD,CAA+D,CAAA"}
|
package/build/types.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { AppType, ContextStage,
|
|
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,8 @@ export interface LazyService extends Service {
|
|
|
44
40
|
}
|
|
45
41
|
export interface BasicEntrypoint extends Contextual {
|
|
46
42
|
_entrypoint: true;
|
|
47
|
-
_module: true;
|
|
48
|
-
}
|
|
49
|
-
/** @deprecated use BasicEntrypoint */
|
|
50
|
-
export interface BasicModule extends Contextual {
|
|
51
|
-
_module: true;
|
|
52
43
|
}
|
|
53
44
|
export interface BasicResource extends Contextual {
|
|
54
|
-
layers?: Layer[];
|
|
55
45
|
init?: () => Promise<void>;
|
|
56
46
|
}
|
|
57
47
|
export interface Middleware {
|
|
@@ -59,6 +49,12 @@ export interface Middleware {
|
|
|
59
49
|
stage: MiddlewareStage;
|
|
60
50
|
apply: <C extends BasicConfig, T extends BasicContext<C>>(context: T, args?: Record<string, string | undefined>) => Promise<void>;
|
|
61
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* The DI container. One context is built per process by one factory: a layer specific
|
|
54
|
+
* factory composes the layer below it and then `append*` mixins register what the
|
|
55
|
+
* application needs. There is no child context and nothing is stored for re-creation —
|
|
56
|
+
* a service, a resource and an entrypoint each bind to exactly one context.
|
|
57
|
+
*/
|
|
62
58
|
export interface BasicContext<C extends BasicConfig> {
|
|
63
59
|
cfg: C;
|
|
64
60
|
stage: ContextStage;
|
|
@@ -66,7 +62,6 @@ export interface BasicContext<C extends BasicConfig> {
|
|
|
66
62
|
waitForInitialized: () => Promise<boolean>;
|
|
67
63
|
configure: <T extends BasicContext<C>>() => T;
|
|
68
64
|
init: <T extends BasicContext<C>>() => Promise<T>;
|
|
69
|
-
updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>;
|
|
70
65
|
registerService: <T extends BasicContext<C>>(service: Service) => T;
|
|
71
66
|
registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T;
|
|
72
67
|
registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T;
|
|
@@ -80,17 +75,6 @@ export interface BasicContext<C extends BasicConfig> {
|
|
|
80
75
|
hasService: (alias: string) => boolean;
|
|
81
76
|
hasEntrypoint: (alias: string) => boolean;
|
|
82
77
|
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
78
|
}
|
|
95
79
|
export {};
|
|
96
80
|
//# sourceMappingURL=types.d.ts.map
|
package/build/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAExG,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,OAAO,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asicConfig, BasicContext, Middleware
|
|
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,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExE,eAAO,MAAM,iBAAiB,GAAI,YAAY,UAAU,WAA2D,CAAA;AAEnH,eAAO,MAAM,mBAAmB,GAAI,MAAM,cAAc,EAAE,OAAO,eAAe,WAAuB,CAAA;AAEvG,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAC/E,SAAS,CAAC,EACV,aAAa,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,EACzC,MAAM,cAAc,EACpB,OAAO,eAAe,EACtB,OAAO,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,oBAG1C,CAAA"}
|
package/build/utils/context.js
CHANGED
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAGA,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,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"}
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
package/build/utils/index.js
CHANGED
package/build/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { AppType
|
|
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,19 @@
|
|
|
1
|
-
import { ContextStage,
|
|
2
|
-
import type { BasicConfig, BasicContext, Middleware, BasicEntrypoint,
|
|
3
|
-
|
|
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 { BasicConfig, BasicContext, Middleware, BasicEntrypoint, BasicResource, Service } from './types.js'
|
|
3
|
+
import { applyMiddlewares, getMiddlerwareKey } from './utils/context.js'
|
|
6
4
|
|
|
7
5
|
type Entrypoint = BasicEntrypoint
|
|
8
6
|
|
|
9
7
|
export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C> => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
/**
|
|
9
|
+
* One flat registry per kind, keyed by alias. Registering an alias twice replaces the
|
|
10
|
+
* earlier entry — application entrypoint lists are routinely spread together and the
|
|
11
|
+
* later declaration is the one the app means.
|
|
12
|
+
*/
|
|
13
|
+
const services: Record<string, Service> = {}
|
|
14
|
+
const entrypoints: Record<string, Entrypoint> = {}
|
|
15
|
+
const resources: Record<string, BasicResource> = {}
|
|
13
16
|
const middlewares: Record<string, Middleware[]> = {}
|
|
14
|
-
const allServices: Record<string, Service> = {}
|
|
15
|
-
const allEntrypoints: Record<string, Entrypoint> = {}
|
|
16
|
-
const allResources: Record<string, BasicResource> = {}
|
|
17
17
|
|
|
18
18
|
let configure: (res: boolean) => void
|
|
19
19
|
let initialize: (resv: boolean) => void
|
|
@@ -21,8 +21,6 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
21
21
|
const configured = new Promise<boolean>(resolve => { configure = resolve })
|
|
22
22
|
const initialized = new Promise<boolean>(resolve => { initialize = resolve })
|
|
23
23
|
|
|
24
|
-
// const contexts: Record<string, BasicContext<C>> = {}
|
|
25
|
-
|
|
26
24
|
const inLazyInit = new Set<Service>()
|
|
27
25
|
|
|
28
26
|
const context: BasicContext<C> = {
|
|
@@ -59,7 +57,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
59
57
|
|
|
60
58
|
await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration)
|
|
61
59
|
|
|
62
|
-
await
|
|
60
|
+
await Object.values(services).reduce(
|
|
63
61
|
async (previous, service) => {
|
|
64
62
|
await previous
|
|
65
63
|
if (!service.initialized) {
|
|
@@ -75,12 +73,9 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
75
73
|
|
|
76
74
|
await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading)
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
await Object.values(resources[context.cfg.layer][id]).reduce(async (previous, resource) => {
|
|
76
|
+
await Object.values(resources).reduce(async (previous, resource) => {
|
|
80
77
|
await previous
|
|
81
|
-
|
|
82
|
-
await resource.init?.()
|
|
83
|
-
}
|
|
78
|
+
await resource.init?.()
|
|
84
79
|
}, Promise.resolve())
|
|
85
80
|
|
|
86
81
|
await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading)
|
|
@@ -95,24 +90,13 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
95
90
|
},
|
|
96
91
|
|
|
97
92
|
registerService: <T>(service: Service) => {
|
|
98
|
-
|
|
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
|
|
93
|
+
services[service.alias] = service.registerContext(context)
|
|
105
94
|
|
|
106
95
|
return context as T
|
|
107
96
|
},
|
|
108
97
|
|
|
109
98
|
registerEntrypoint: <T>(entrypoint: Entrypoint) => {
|
|
110
|
-
|
|
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
|
|
99
|
+
entrypoints[entrypoint.alias] = entrypoint.registerContext(context)
|
|
116
100
|
|
|
117
101
|
return context as T
|
|
118
102
|
},
|
|
@@ -122,19 +106,8 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
122
106
|
return context as T
|
|
123
107
|
},
|
|
124
108
|
|
|
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
109
|
registerResource: <T>(resource: BasicResource) => {
|
|
132
|
-
|
|
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
|
|
110
|
+
resources[resource.alias] = resource.registerContext(context)
|
|
138
111
|
|
|
139
112
|
return context as T
|
|
140
113
|
},
|
|
@@ -154,15 +127,9 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
154
127
|
},
|
|
155
128
|
|
|
156
129
|
service: <T>(alias: string) => {
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
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}`)
|
|
130
|
+
const _service = services[alias]
|
|
131
|
+
if (_service == null) {
|
|
132
|
+
throw new SyntaxError(`Service ${alias} not found`)
|
|
166
133
|
}
|
|
167
134
|
if (!_service.initialized) {
|
|
168
135
|
if (_service.lazyInit != null) {
|
|
@@ -180,98 +147,26 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
|
|
|
180
147
|
},
|
|
181
148
|
|
|
182
149
|
entrypoint: <T extends Entrypoint>(alias: string) => {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return entrypoints[context.cfg.layer][id][alias] as T
|
|
150
|
+
if (entrypoints[alias] != null) {
|
|
151
|
+
return entrypoints[alias] as T
|
|
186
152
|
}
|
|
187
153
|
throw new SyntaxError(`Entrypoint ${alias} not found`)
|
|
188
154
|
},
|
|
189
155
|
|
|
190
|
-
/** @deprecated use entrypoint */
|
|
191
|
-
module: <T>(alias: string) => context.entrypoint<any>(alias) as T,
|
|
192
|
-
|
|
193
156
|
resource: <T extends BasicResource>(alias: string) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const resource = resources[context.cfg.layer][id][alias] as T
|
|
197
|
-
|
|
198
|
-
return resource
|
|
157
|
+
if (resources[alias] != null) {
|
|
158
|
+
return resources[alias] as T
|
|
199
159
|
}
|
|
200
160
|
throw new SyntaxError(`Resource ${alias} not found`)
|
|
201
161
|
},
|
|
202
162
|
|
|
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,
|
|
163
|
+
entrypoints: <T extends Entrypoint>() => Object.values(entrypoints) as T[],
|
|
268
164
|
|
|
269
|
-
|
|
165
|
+
hasResource: alias => resources[alias] != null,
|
|
270
166
|
|
|
271
|
-
|
|
167
|
+
hasService: alias => services[alias] != null,
|
|
272
168
|
|
|
273
|
-
|
|
274
|
-
hasModule: alias => context.hasEntrypoint(alias),
|
|
169
|
+
hasEntrypoint: alias => entrypoints[alias] != null,
|
|
275
170
|
}
|
|
276
171
|
|
|
277
172
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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,
|
|
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,10 @@ export interface LazyService extends Service {
|
|
|
56
52
|
|
|
57
53
|
export interface BasicEntrypoint extends Contextual {
|
|
58
54
|
_entrypoint: true
|
|
59
|
-
_module: true
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** @deprecated use BasicEntrypoint */
|
|
63
|
-
export interface BasicModule extends Contextual {
|
|
64
|
-
_module: true
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
export interface BasicResource extends Contextual {
|
|
68
|
-
|
|
69
|
-
init?: () => Promise<void> // After context switch the resource should be able to reinitialize
|
|
58
|
+
init?: () => Promise<void>
|
|
70
59
|
}
|
|
71
60
|
|
|
72
61
|
export interface Middleware {
|
|
@@ -75,6 +64,12 @@ export interface Middleware {
|
|
|
75
64
|
apply: <C extends BasicConfig, T extends BasicContext<C>>(context: T, args?: Record<string, string | undefined>) => Promise<void>
|
|
76
65
|
}
|
|
77
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The DI container. One context is built per process by one factory: a layer specific
|
|
69
|
+
* factory composes the layer below it and then `append*` mixins register what the
|
|
70
|
+
* application needs. There is no child context and nothing is stored for re-creation —
|
|
71
|
+
* a service, a resource and an entrypoint each bind to exactly one context.
|
|
72
|
+
*/
|
|
78
73
|
export interface BasicContext<C extends BasicConfig> {
|
|
79
74
|
cfg: C
|
|
80
75
|
stage: ContextStage
|
|
@@ -82,7 +77,6 @@ export interface BasicContext<C extends BasicConfig> {
|
|
|
82
77
|
waitForInitialized: () => Promise<boolean>
|
|
83
78
|
configure: <T extends BasicContext<C>>() => T
|
|
84
79
|
init: <T extends BasicContext<C>>() => Promise<T>
|
|
85
|
-
updateContext: <T extends BasicContext<C>>(id?: string, to?: Layer) => Promise<T>
|
|
86
80
|
registerService: <T extends BasicContext<C>>(service: Service) => T
|
|
87
81
|
registerEntrypoint: <T extends BasicContext<C>>(entrypoint: BasicEntrypoint) => T
|
|
88
82
|
registerEntrypoints: <T extends BasicContext<C>>(entrypoints: BasicEntrypoint[]) => T
|
|
@@ -98,17 +92,4 @@ export interface BasicContext<C extends BasicConfig> {
|
|
|
98
92
|
hasEntrypoint: (alias: string) => boolean
|
|
99
93
|
|
|
100
94
|
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
95
|
}
|
package/src/utils/context.ts
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BasicConfig, BasicContext, Middleware
|
|
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
|
|
|
5
4
|
export const getMiddlerwareKey = (middleware: Middleware) => createMiddlewareKey(middleware.type, middleware.stage)
|
|
6
5
|
|
|
7
6
|
export const createMiddlewareKey = (type: MiddlewareType, stage: MiddlewareStage) => `${type}:${stage}`
|
|
8
7
|
|
|
9
|
-
export const isLayerIherited = (current: Layer, parent: Layer): boolean =>
|
|
10
|
-
(current === parent) || (layersOrder.indexOf(parent) > layersOrder.indexOf(current))
|
|
11
|
-
|
|
12
|
-
export const isResourceAvailable = (resource: BasicResource, layer: Layer) =>
|
|
13
|
-
resource.layers == null || resource.layers.some(_layer => isLayerIherited(_layer, layer))
|
|
14
|
-
|
|
15
|
-
export const layersOrder = [
|
|
16
|
-
Layer.System,
|
|
17
|
-
Layer.Global,
|
|
18
|
-
Layer.Service,
|
|
19
|
-
Layer.Entity,
|
|
20
|
-
Layer.User
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
export const getAllServices = (services: InLayer<Record<string, Service>>, layer: Layer, id: string) =>
|
|
24
|
-
services?.[layer]?.[id] != null ? Object.values(services[layer][id]) : []
|
|
25
|
-
|
|
26
8
|
export const applyMiddlewares = <C extends BasicConfig, T extends BasicContext<C>>(
|
|
27
9
|
context: T,
|
|
28
10
|
middlewares: Record<string, Middleware[]>,
|
package/src/utils/index.ts
CHANGED
package/tests/context.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { AppType,
|
|
1
|
+
import { AppType, makeBasicContext } from '@owlmeans/context'
|
|
2
2
|
import type { BasicConfig, BasicContext } from '@owlmeans/context'
|
|
3
3
|
|
|
4
4
|
const baseConfig = (): BasicConfig => ({
|
|
5
5
|
ready: false,
|
|
6
6
|
service: 'test-context',
|
|
7
|
-
layer: Layer.Service,
|
|
8
7
|
type: AppType.Backend,
|
|
9
8
|
})
|
|
10
9
|
|
package/tests/service.spec.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { makeTestCtx } from './context.js'
|
|
|
5
5
|
describe('@owlmeans/context — service registration', () => {
|
|
6
6
|
test('registers a service and resolves it by alias after initialization', async () => {
|
|
7
7
|
const ctx = makeTestCtx()
|
|
8
|
-
const stub = createService('alpha', {
|
|
8
|
+
const stub = createService('alpha', {})
|
|
9
9
|
ctx.registerService(stub)
|
|
10
10
|
expect(ctx.hasService('alpha')).toBe(true)
|
|
11
11
|
ctx.configure()
|
package/build/.gitkeep
DELETED
|
File without changes
|
package/build/utils/layer.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Layer } from '../consts';
|
|
2
|
-
export interface InLayer<T> extends Record<Layer, Record<string, T>> {
|
|
3
|
-
}
|
|
4
|
-
export declare const initializeLayer: <T>(inLayer: InLayer<T>, layer: Layer, id: string | undefined) => string;
|
|
5
|
-
export declare const DEFAULT = "default";
|
|
6
|
-
//# sourceMappingURL=layer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"layer.d.ts","sourceRoot":"","sources":["../../src/utils/layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAEjC,MAAM,WAAW,OAAO,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;CAAI;AAExE,eAAO,MAAM,eAAe,GAAI,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,KAAK,MAAM,MAAM,GAAG,SAAS,KAAG,MAU9F,CAAA;AAED,eAAO,MAAM,OAAO,YAAY,CAAA"}
|
package/build/utils/layer.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const initializeLayer = (inLayer, layer, id) => {
|
|
2
|
-
if (inLayer[layer] == null) {
|
|
3
|
-
inLayer[layer] = {};
|
|
4
|
-
}
|
|
5
|
-
id = id ?? DEFAULT;
|
|
6
|
-
if (inLayer[layer][id] == null) {
|
|
7
|
-
inLayer[layer][id] = {};
|
|
8
|
-
}
|
|
9
|
-
return id;
|
|
10
|
-
};
|
|
11
|
-
export const DEFAULT = 'default';
|
|
12
|
-
//# sourceMappingURL=layer.js.map
|
package/build/utils/layer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"layer.js","sourceRoot":"","sources":["../../src/utils/layer.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,OAAmB,EAAE,KAAY,EAAE,EAAsB,EAAU,EAAE;IACtG,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAA;IACrB,CAAC;IACD,EAAE,GAAG,EAAE,IAAI,OAAO,CAAA;IAClB,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC/B,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAO,CAAA;IAC9B,CAAC;IAED,OAAO,EAAE,CAAA;AACX,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAA"}
|
package/src/utils/layer.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Layer } from '../consts'
|
|
2
|
-
|
|
3
|
-
export interface InLayer<T> extends Record<Layer, Record<string, T>> { }
|
|
4
|
-
|
|
5
|
-
export const initializeLayer = <T>(inLayer: InLayer<T>, layer: Layer, id: string | undefined): string => {
|
|
6
|
-
if (inLayer[layer] == null) {
|
|
7
|
-
inLayer[layer] = {}
|
|
8
|
-
}
|
|
9
|
-
id = id ?? DEFAULT
|
|
10
|
-
if (inLayer[layer][id] == null) {
|
|
11
|
-
inLayer[layer][id] = {} as T
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return id
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const DEFAULT = 'default'
|