@owlmeans/context 0.1.18-rc.9 → 0.1.19-rc.0

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 (63) hide show
  1. package/README.md +248 -64
  2. package/agent-meta/manifest.json +6 -6
  3. package/agent-meta/skills/owlmeans-context/SKILL.md +25 -0
  4. package/build/consts.local.d.ts +5 -0
  5. package/build/consts.local.d.ts.map +1 -0
  6. package/build/consts.local.js +6 -0
  7. package/build/consts.local.js.map +1 -0
  8. package/build/context.d.ts.map +1 -1
  9. package/build/context.js +7 -7
  10. package/build/context.js.map +1 -1
  11. package/build/index.d.ts +2 -0
  12. package/build/index.d.ts.map +1 -1
  13. package/build/index.js +1 -0
  14. package/build/index.js.map +1 -1
  15. package/build/memo/types.d.ts +14 -0
  16. package/build/memo/types.d.ts.map +1 -0
  17. package/build/memo/types.js +2 -0
  18. package/build/memo/types.js.map +1 -0
  19. package/build/memo.d.ts +4 -0
  20. package/build/memo.d.ts.map +1 -0
  21. package/build/memo.js +25 -0
  22. package/build/memo.js.map +1 -0
  23. package/build/service.d.ts +1 -4
  24. package/build/service.d.ts.map +1 -1
  25. package/build/service.js +1 -5
  26. package/build/service.js.map +1 -1
  27. package/build/types.d.ts +3 -0
  28. package/build/types.d.ts.map +1 -1
  29. package/build/types.local.d.ts +6 -0
  30. package/build/types.local.d.ts.map +1 -0
  31. package/build/types.local.js +2 -0
  32. package/build/types.local.js.map +1 -0
  33. package/build/utils/index.d.ts +2 -1
  34. package/build/utils/index.d.ts.map +1 -1
  35. package/build/utils/index.js +1 -1
  36. package/build/utils/index.js.map +1 -1
  37. package/build/utils/middleware/types.d.ts +12 -0
  38. package/build/utils/middleware/types.d.ts.map +1 -0
  39. package/build/utils/middleware/types.js +2 -0
  40. package/build/utils/middleware/types.js.map +1 -0
  41. package/build/utils/middleware.d.ts +4 -0
  42. package/build/utils/middleware.d.ts.map +1 -0
  43. package/build/utils/middleware.js +8 -0
  44. package/build/utils/middleware.js.map +1 -0
  45. package/package.json +2 -2
  46. package/src/consts.local.ts +4 -0
  47. package/src/context.ts +9 -12
  48. package/src/index.ts +2 -0
  49. package/src/memo/types.ts +13 -0
  50. package/src/memo.ts +33 -0
  51. package/src/service.ts +3 -14
  52. package/src/types.local.ts +7 -0
  53. package/src/types.ts +4 -0
  54. package/src/utils/index.ts +2 -1
  55. package/src/utils/middleware/types.ts +18 -0
  56. package/src/utils/middleware.ts +23 -0
  57. package/tests/memo.spec.ts +27 -0
  58. package/agent-meta/skills/context/SKILL.md +0 -163
  59. package/build/utils/context.d.ts +0 -6
  60. package/build/utils/context.d.ts.map +0 -1
  61. package/build/utils/context.js +0 -4
  62. package/build/utils/context.js.map +0 -1
  63. package/src/utils/context.ts +0 -16
@@ -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,SACjD,MAAM,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,KACvD,CAAsE,CAAA;AAEzE,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,SAC9C,MAAM,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,KACvD,CAA+D,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,kBAAkB,EAAE,WAAW,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AA8BlG,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,kBAAkB,SACjD,MAAM,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,KACvD,CAAsE,CAAA;AAEzE,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,WAAW,SAC9C,MAAM,WAAW,OAAO,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,KACvD,CAA+D,CAAA"}
package/build/service.js CHANGED
@@ -1,9 +1,5 @@
1
1
  import { appendContextual } from './helper.js';
2
- var TypeToMethod;
3
- (function (TypeToMethod) {
4
- TypeToMethod["Lazy"] = "lazyInit";
5
- TypeToMethod["Initialized"] = "init";
6
- })(TypeToMethod || (TypeToMethod = {}));
2
+ import { TypeToMethod } from './consts.local.js';
7
3
  const _createService = (type) => (alias, service, init) => {
8
4
  if (service.registerContext == null) {
9
5
  appendContextual(alias, service);
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAG9C,IAAK,YAGJ;AAHD,WAAK,YAAY;IACf,iCAAiB,CAAA;IACjB,oCAAoB,CAAA;AACtB,CAAC,EAHI,YAAY,KAAZ,YAAY,QAGhB;AAUD,MAAM,cAAc,GAAG,CAAoB,IAAkB,EAAoB,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAC3G,IAAI,OAAO,CAAC,eAAe,IAAI,IAAI,EAAE,CAAC;QACpC,gBAAgB,CAAC,KAAK,EAAE,OAAqB,CAAC,CAAA;IAChD,CAAC;IAED,IAAI,UAAkC,CAAA;IACtC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAU,OAAO,CAAC,EAAE,GAAG,UAAU,GAAG,OAAO,CAAA,CAAC,CAAC,CAAC,CAAA;IAEvE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;IAErB,OAAO,CAAC,WAAW,GAAG,KAAK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CAAC,EAAE,GAAG,UAAU,GAAG,OAAO,CAAA,CAAC,CAAC,CAAC,CAAA;IAEvE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;IAErB,OAAO,CAAC,WAAW,GAAG,KAAK,CAAA;IAE3B,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE;QAC/B,OAAO,CAAC,WAAW,GAAG,IAAI,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE;QACzB,MAAM,IAAI,CAAC,OAAY,CAAC,EAAE,CAAA;QAC1B,UAAU,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC,CAAA;IAED,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,KAAK,CAAA;IAE3B,OAAO,OAAY,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAa,EAAE,OAAmB,EAAE,IAAoB,EACrD,EAAE,CAAC,cAAc,CAAI,YAAY,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AAEzE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAAa,EAAE,OAAmB,EAAE,IAAoB,EACrD,EAAE,CAAC,cAAc,CAAI,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA"}
package/build/types.d.ts CHANGED
@@ -90,5 +90,8 @@ export interface BasicContext<C extends BasicConfig> {
90
90
  hasEntrypoint: (alias: string) => boolean;
91
91
  entrypoints: <T extends BasicEntrypoint>() => T[];
92
92
  }
93
+ export interface InitMethod<S extends Service> {
94
+ (service: S): () => Promise<void>;
95
+ }
93
96
  export {};
94
97
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA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,CAAA;IAC3E,kBAAkB,EAAE,CAAC,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,KAAK,CAAC,CAAA;IAE5E,IAAI,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAA;IACxB,OAAO,EAAE,CAAC,CAAC,SAAS,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;IAChD,UAAU,EAAE;QACV,CAAC,CAAC,SAAS,eAAe,EAAE,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;QACjE,CAAC,CAAC,SAAS,eAAe,EAAE,SAAS,EAAE,mBAAmB,GAAG,MAAM,GAAG,CAAC,CAAA;KACxE,CAAA;IACD,QAAQ,EAAE,CAAC,CAAC,SAAS,aAAa,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;IACvD,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACvC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IACtC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;IAEzC,WAAW,EAAE,CAAC,CAAC,SAAS,eAAe,OAAO,CAAC,EAAE,CAAA;CAClD;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,OAAO;IAC3C,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC"}
@@ -0,0 +1,6 @@
1
+ import type { BasicEntrypoint, Service, InitMethod } from './types.js';
2
+ export type Entrypoint = BasicEntrypoint;
3
+ export interface CreateService<S extends Service> {
4
+ (alias: string, service: Partial<S>, init?: InitMethod<S>): S;
5
+ }
6
+ //# sourceMappingURL=types.local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.d.ts","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEtE,MAAM,MAAM,UAAU,GAAG,eAAe,CAAA;AAExC,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,OAAO;IAC9C,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;CAC9D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.local.js","sourceRoot":"","sources":["../src/types.local.ts"],"names":[],"mappings":""}
@@ -1,2 +1,3 @@
1
- export * from './context.js';
1
+ export type * from './middleware/types.js';
2
+ export * from './middleware.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,mBAAmB,uBAAuB,CAAA;AAC1C,cAAc,iBAAiB,CAAA"}
@@ -1,2 +1,2 @@
1
- export * from './context.js';
1
+ export * from './middleware.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,12 @@
1
+ import type { MiddlewareStage, MiddlewareType } from '../../consts.js';
2
+ import type { BasicConfig, BasicContext, Middleware } from '../../types.js';
3
+ /** The middleware registry keys and the staged application of the middlewares a context holds. */
4
+ export interface MiddlewareUtils {
5
+ /** The registry key a middleware is filed under: its type and stage. */
6
+ getMiddlerwareKey: (middleware: Middleware) => string;
7
+ /** The registry key of one middleware type at one stage. */
8
+ createMiddlewareKey: (type: MiddlewareType, stage: MiddlewareStage) => string;
9
+ /** Applies, in parallel, every middleware registered for the type at the stage. */
10
+ 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
+ }
12
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/middleware/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3E,kGAAkG;AAClG,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,iBAAiB,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAA;IACrD,4DAA4D;IAC5D,mBAAmB,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,KAAK,MAAM,CAAA;IAC7E,mFAAmF;IACnF,gBAAgB,EAAE,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,EACjE,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,EACzC,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KACtC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;CACrB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/middleware/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { MiddlewareUtils } from './middleware/types.js';
2
+ export declare const createMiddlewareUtils: () => MiddlewareUtils;
3
+ export declare const middlewareUtils: MiddlewareUtils;
4
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/utils/middleware.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,eAAO,MAAM,qBAAqB,QAAO,eAgBxC,CAAA;AAED,eAAO,MAAM,eAAe,iBAA0B,CAAA"}
@@ -0,0 +1,8 @@
1
+ export const createMiddlewareUtils = () => {
2
+ const createMiddlewareKey = (type, stage) => `${type}:${stage}`;
3
+ const getMiddlerwareKey = (middleware) => createMiddlewareKey(middleware.type, middleware.stage);
4
+ const applyMiddlewares = (context, middlewares, type, stage, args) => Promise.all(middlewares[createMiddlewareKey(type, stage)]?.map(async (middleware) => middleware.apply(context, args)) ?? []);
5
+ return { getMiddlerwareKey, createMiddlewareKey, applyMiddlewares };
6
+ };
7
+ export const middlewareUtils = createMiddlewareUtils();
8
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/utils/middleware.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAoB,EAAE;IACzD,MAAM,mBAAmB,GAAG,CAAC,IAAoB,EAAE,KAAsB,EAAU,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAA;IAExG,MAAM,iBAAiB,GAAG,CAAC,UAAsB,EAAU,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IAEpH,MAAM,gBAAgB,GAAG,CACvB,OAAU,EACV,WAAyC,EACzC,IAAoB,EACpB,KAAsB,EACtB,IAAyC,EACxB,EAAE,CAAC,OAAO,CAAC,GAAG,CAC/B,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;IAED,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,CAAA;AACrE,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,qBAAqB,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/context",
3
- "version": "0.1.18-rc.9",
3
+ "version": "0.1.19-rc.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  }
23
23
  },
24
24
  "devDependencies": {
25
- "@owlmeans/dep-config": "workspace:*",
25
+ "@owlmeans/dep-config": "^0.1.19-rc.0",
26
26
  "nodemon": "^3.1.14",
27
27
  "typescript": "^7.0.2"
28
28
  },
@@ -0,0 +1,4 @@
1
+ export enum TypeToMethod {
2
+ Lazy = 'lazyInit',
3
+ Initialized = 'init'
4
+ }
package/src/context.ts CHANGED
@@ -1,10 +1,7 @@
1
1
  import { ContextStage, MiddlewareStage, MiddlewareType } from './consts.js'
2
- import type {
3
- BasicConfig, BasicContext, Middleware, BasicEntrypoint, BasicResource, EntrypointReference, Service
4
- } from './types.js'
5
- import { applyMiddlewares, getMiddlerwareKey } from './utils/context.js'
6
-
7
- type Entrypoint = BasicEntrypoint
2
+ import type { BasicConfig, BasicContext, Middleware, BasicResource, EntrypointReference, Service } from './types.js'
3
+ import { middlewareUtils } from './utils/middleware.js'
4
+ import type { Entrypoint } from './types.local.js'
8
5
 
9
6
  export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C> => {
10
7
  /**
@@ -41,7 +38,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
41
38
  }
42
39
 
43
40
  void (async () => {
44
- await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Configuration)
41
+ await middlewareUtils.applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Configuration)
45
42
 
46
43
  context.stage = ContextStage.Loading
47
44
  configure(true)
@@ -57,7 +54,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
57
54
  return context as T
58
55
  }
59
56
 
60
- await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration)
57
+ await middlewareUtils.applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Configuration)
61
58
 
62
59
  await Object.values(services).reduce(
63
60
  async (previous, service) => {
@@ -73,20 +70,20 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
73
70
  }
74
71
  , Promise.resolve())
75
72
 
76
- await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading)
73
+ await middlewareUtils.applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Config, MiddlewareStage.Loading)
77
74
 
78
75
  await Object.values(resources).reduce(async (previous, resource) => {
79
76
  await previous
80
77
  await resource.init?.()
81
78
  }, Promise.resolve())
82
79
 
83
- await applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading)
80
+ await middlewareUtils.applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Loading)
84
81
 
85
82
  context.stage = ContextStage.Ready
86
83
  context.cfg.ready = true
87
84
  initialize(true)
88
85
 
89
- void applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Ready)
86
+ void middlewareUtils.applyMiddlewares<C, BasicContext<C>>(context, middlewares, MiddlewareType.Context, MiddlewareStage.Ready)
90
87
 
91
88
  return context as T
92
89
  },
@@ -115,7 +112,7 @@ export const makeBasicContext = <C extends BasicConfig>(cfg: C): BasicContext<C>
115
112
  },
116
113
 
117
114
  registerMiddleware: <T>(middleware: Middleware) => {
118
- const key = getMiddlerwareKey(middleware)
115
+ const key = middlewareUtils.getMiddlerwareKey(middleware)
119
116
  if (!(key in middlewares)) {
120
117
  middlewares[key] = []
121
118
  }
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
 
2
2
  export type * from './types.js'
3
+ export type * from './memo/types.js'
3
4
  export * from './consts.js'
4
5
  export * from './context.js'
5
6
  export * from './service.js'
6
7
  export * from './helper.js'
7
8
  export * from './config.js'
9
+ export * from './memo.js'
@@ -0,0 +1,13 @@
1
+ /** Lazy, memoized construction — the seam bound objects are reached through. */
2
+ export interface MemoHelper {
3
+ /**
4
+ * A thunk that builds its value on the first call and answers the same value after. A flag, not
5
+ * `undefined`, marks it built, so a builder that returns `undefined` still runs once.
6
+ */
7
+ once: <T>(build: () => T) => () => T
8
+ /**
9
+ * One `make(target)` per target object: built on first use for that target and released with it
10
+ * (a WeakMap), so a context, a request or a collaborator gets exactly one bound object.
11
+ */
12
+ oncePer: <K extends object, T>(make: (target: K) => T) => (target: K) => T
13
+ }
package/src/memo.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { MemoHelper } from './memo/types.js'
2
+
3
+ export const createMemoHelper = (): MemoHelper => {
4
+ const once = <T>(build: () => T): (() => T) => {
5
+ let built = false
6
+ let value: T | undefined
7
+
8
+ return () => {
9
+ if (!built) {
10
+ value = build()
11
+ built = true
12
+ }
13
+
14
+ return value as T
15
+ }
16
+ }
17
+
18
+ const oncePer = <K extends object, T>(make: (target: K) => T): ((target: K) => T) => {
19
+ const made = new WeakMap<K, T>()
20
+
21
+ return target => {
22
+ if (!made.has(target)) {
23
+ made.set(target, make(target))
24
+ }
25
+
26
+ return made.get(target) as T
27
+ }
28
+ }
29
+
30
+ return { once, oncePer }
31
+ }
32
+
33
+ export const memoHelper = createMemoHelper()
package/src/service.ts CHANGED
@@ -1,18 +1,7 @@
1
1
  import { appendContextual } from './helper.js'
2
- import type { Contextual, InitializedService, LazyService, Service } from './types.js'
3
-
4
- enum TypeToMethod {
5
- Lazy = 'lazyInit',
6
- Initialized = 'init'
7
- }
8
-
9
- export interface InitMethod<S extends Service> {
10
- (service: S): () => Promise<void>
11
- }
12
-
13
- interface CreateService<S extends Service> {
14
- (alias: string, service: Partial<S>, init?: InitMethod<S>): S
15
- }
2
+ import type { Contextual, InitializedService, LazyService, Service, InitMethod } from './types.js'
3
+ import { TypeToMethod } from './consts.local.js'
4
+ import type { CreateService } from './types.local.js'
16
5
 
17
6
  const _createService = <S extends Service>(type: TypeToMethod): CreateService<S> => (alias, service, init) => {
18
7
  if (service.registerContext == null) {
@@ -0,0 +1,7 @@
1
+ import type { BasicEntrypoint, Service, InitMethod } from './types.js'
2
+
3
+ export type Entrypoint = BasicEntrypoint
4
+
5
+ export interface CreateService<S extends Service> {
6
+ (alias: string, service: Partial<S>, init?: InitMethod<S>): S
7
+ }
package/src/types.ts CHANGED
@@ -108,3 +108,7 @@ export interface BasicContext<C extends BasicConfig> {
108
108
 
109
109
  entrypoints: <T extends BasicEntrypoint>() => T[]
110
110
  }
111
+
112
+ export interface InitMethod<S extends Service> {
113
+ (service: S): () => Promise<void>
114
+ }
@@ -1,2 +1,3 @@
1
1
 
2
- export * from './context.js'
2
+ export type * from './middleware/types.js'
3
+ export * from './middleware.js'
@@ -0,0 +1,18 @@
1
+ import type { MiddlewareStage, MiddlewareType } from '../../consts.js'
2
+ import type { BasicConfig, BasicContext, Middleware } from '../../types.js'
3
+
4
+ /** The middleware registry keys and the staged application of the middlewares a context holds. */
5
+ export interface MiddlewareUtils {
6
+ /** The registry key a middleware is filed under: its type and stage. */
7
+ getMiddlerwareKey: (middleware: Middleware) => string
8
+ /** The registry key of one middleware type at one stage. */
9
+ createMiddlewareKey: (type: MiddlewareType, stage: MiddlewareStage) => string
10
+ /** Applies, in parallel, every middleware registered for the type at the stage. */
11
+ applyMiddlewares: <C extends BasicConfig, T extends BasicContext<C>>(
12
+ context: T,
13
+ middlewares: Record<string, Middleware[]>,
14
+ type: MiddlewareType,
15
+ stage: MiddlewareStage,
16
+ args?: Record<string, string | undefined>
17
+ ) => Promise<void[]>
18
+ }
@@ -0,0 +1,23 @@
1
+ import type { MiddlewareStage, MiddlewareType } from '../consts.js'
2
+ import type { BasicConfig, BasicContext, Middleware } from '../types.js'
3
+ import type { MiddlewareUtils } from './middleware/types.js'
4
+
5
+ export const createMiddlewareUtils = (): MiddlewareUtils => {
6
+ const createMiddlewareKey = (type: MiddlewareType, stage: MiddlewareStage): string => `${type}:${stage}`
7
+
8
+ const getMiddlerwareKey = (middleware: Middleware): string => createMiddlewareKey(middleware.type, middleware.stage)
9
+
10
+ const applyMiddlewares = <C extends BasicConfig, T extends BasicContext<C>>(
11
+ context: T,
12
+ middlewares: Record<string, Middleware[]>,
13
+ type: MiddlewareType,
14
+ stage: MiddlewareStage,
15
+ args?: Record<string, string | undefined>
16
+ ): Promise<void[]> => Promise.all(
17
+ middlewares[createMiddlewareKey(type, stage)]?.map(async middleware => middleware.apply<C, T>(context, args)) ?? []
18
+ )
19
+
20
+ return { getMiddlerwareKey, createMiddlewareKey, applyMiddlewares }
21
+ }
22
+
23
+ export const middlewareUtils = createMiddlewareUtils()
@@ -0,0 +1,27 @@
1
+ import { describe, expect, test } from 'bun:test'
2
+ import { createMemoHelper, memoHelper } from '../src/memo.js'
3
+
4
+ describe('@owlmeans/context — memoHelper', () => {
5
+ test('once builds on the first call only, even when the value is undefined', () => {
6
+ let builds = 0
7
+ const lazy = memoHelper.once(() => { builds++; return undefined })
8
+ expect(builds).toBe(0)
9
+ lazy(); lazy(); lazy()
10
+ expect(builds).toBe(1)
11
+ })
12
+
13
+ test('once answers the same object every time', () => {
14
+ const lazy = memoHelper.once(() => ({ id: Math.random() }))
15
+ expect(lazy()).toBe(lazy())
16
+ })
17
+
18
+ test('oncePer builds one value per target and keeps targets apart', () => {
19
+ let builds = 0
20
+ const helperOf = createMemoHelper().oncePer((ctx: { name: string }) => { builds++; return { owner: ctx.name } })
21
+ const a = { name: 'a' }
22
+ const b = { name: 'b' }
23
+ expect(helperOf(a)).toBe(helperOf(a))
24
+ expect(helperOf(b).owner).toBe('b')
25
+ expect(builds).toBe(2)
26
+ })
27
+ })
@@ -1,163 +0,0 @@
1
- ---
2
- name: context
3
- description: How to use @owlmeans/context — the DI container behind every OwlMeans app, its service/resource/entrypoint registries, the configure/init lifecycle, createService and createLazyService, middlewares, and the shared route-alias constants. Auto-invoked when importing context primitives, registering a service, or building a makeContext factory.
4
- user-invocable: false
5
- ---
6
- <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
7
-
8
- # @owlmeans/context
9
-
10
- **Layer:** Core
11
- **Install:** `"@owlmeans/context": "^0.1.18-rc.9"` in `dependencies`
12
-
13
- ## Key Exports
14
-
15
- | Export | Description |
16
- |--------|-------------|
17
- | `makeBasicContext(cfg)` | Low-level factory — extend a layer-specific factory instead |
18
- | `BasicContext<C>` | The container interface, typed by its config |
19
- | `BasicConfig` | `{ ready, service, alias?, type, services?, records?, debug? }` — what every config extends |
20
- | `makeBasicConfig(type, service, cfg?)` | Build the base config object a layer factory then fills in |
21
- | `createService(alias, impl, init?)` | Build a service initialized during `context.init()` |
22
- | `createLazyService(alias, impl, init?)` | Build a service initialized on first `context.service()` |
23
- | `appendContextual(alias, obj)` | Give any object `alias` / `registerContext` / `assertCtx` |
24
- | `assertContext(ctx, location?)` | Return the context or throw `SyntaxError` when it is absent |
25
- | `Service` / `InitializedService` / `LazyService` | The three service shapes |
26
- | `BasicResource` / `BasicEntrypoint` / `Contextual` | The other registrable shapes |
27
- | `Middleware`, `MiddlewareType`, `MiddlewareStage` | Hooks that run inside `configure()` / `init()` |
28
- | `AppType` | `Backend` / `Frontend` |
29
- | `ContextStage` | `Configuration` → `Loading` → `Ready` |
30
- | `CONFIG_RECORD` (`'records'`), `ConfigRecord` | The config-record array key, and a record in it |
31
- | `ROOT`, `HOME`, `GUEST`, `BASE`, `CRASH` | Route-alias idioms every layer reuses |
32
-
33
- ## One context per process
34
-
35
- A context is created ONCE by ONE factory. Extend a layer-specific factory
36
- (`@owlmeans/server-context`, `@owlmeans/web-panel`, …) rather than calling the basic factory
37
- directly: your factory calls the factory below it, applies its own idempotent `append*(context)`
38
- mixins and service registrations, and returns that same context. There are no layered or child
39
- contexts and nothing is stored for re-creation — a service, a resource and an entrypoint each bind
40
- to exactly one context, the first that registers them.
41
-
42
- ```typescript
43
- import { makeServerContext } from '@owlmeans/server-context'
44
-
45
- export const makeContext = <C extends Config, T extends Context<C>>(cfg: C): T => {
46
- const context = makeServerContext<C, T>(cfg)
47
- context.registerService(makeMyService())
48
- return context
49
- }
50
- ```
51
-
52
- ## Registries
53
-
54
- Three flat maps keyed by alias. Registering the same alias twice **replaces** the earlier entry —
55
- entrypoint lists are routinely spread together and the later declaration is the one the app means.
56
-
57
- ```typescript
58
- context.registerService(service) // service(alias), hasService(alias)
59
- context.registerResource(resource) // resource(alias), hasResource(alias)
60
- context.registerEntrypoints(entrypoints) // entrypoint(alias), entrypoints(), hasEntrypoint(alias)
61
- ```
62
-
63
- Every lookup throws `SyntaxError` when the alias is unknown. Resolve a service and call another
64
- service's entrypoint from a handler:
65
-
66
- ```typescript
67
- const someService = ctx.service<MyService>(MY_SERVICE_ALIAS)
68
-
69
- const response = await ctx.entrypoint<ClientEntrypoint<ResponseType>>(
70
- externalService.action.alias
71
- ).call({ body: { ... } }) // call() resolves to the value; invoke() gives { value, outcome }
72
- ```
73
-
74
- ## Lifecycle
75
-
76
- `configure()` runs the `Config` + `Configuration` middlewares and moves the context to `Loading`;
77
- `init()` awaits that, then initializes every service, then the resources, then flips to `Ready` and
78
- sets `cfg.ready`. `waitForConfigured()` and `waitForInitialized()` resolve at those two points, and
79
- `await ctx.config` yields the config once configuration is done. Both calls are safe to repeat — a
80
- context already past the stage returns itself unchanged.
81
-
82
- `configure()` is **not** async: it returns the context straight away and its middlewares run
83
- detached, so the stage flips to `Loading` only when they settle. Anything that must see a configured
84
- context awaits `waitForConfigured()` or `init()`, never the return of `configure()`.
85
-
86
- ## Services
87
-
88
- `createService` and `createLazyService` differ only in **when** the init function runs.
89
-
90
- - `createService` — `init()` is awaited during `context.init()`, in registration order. Asking for
91
- an uninitialized one throws `SyntaxError`.
92
- - `createLazyService` — `lazyInit()` fires on the first `context.service(alias)` and the service is
93
- returned immediately, before that promise settles. Choose lazy when the service must be reachable
94
- while the context is still `Loading` — from an app's `makeContext`, or from another package's
95
- `append*` helper — **not** because it has no async work; most lazy services do plenty of it.
96
-
97
- ```typescript
98
- import { createService } from '@owlmeans/context'
99
-
100
- export const makeMyService = (alias = MY_SERVICE) => createService<MyService>(alias, {
101
- doWork: async () => { /* ... */ }
102
- }, service => async () => {
103
- await connect()
104
- service.initialized = true
105
- })
106
- ```
107
-
108
- The init function is a factory: it receives the service and returns the actual initializer, which
109
- must set `service.initialized = true`. Omit it and the service is simply marked initialized. Inside
110
- any method use `service.assertCtx<Config, Context>()` to reach the context it was registered on.
111
-
112
- ### `ready()`
113
-
114
- Both factories give the service a `ready(): Promise<boolean>` that resolves once its init function
115
- has finished, and both `InitializedService` and `LazyService` declare it. It is how you wait for a
116
- lazy service: the container hands the service back before `lazyInit()` settles, so anything the init
117
- prepared — a database client, a loaded config, a socket — is only safe to touch after `ready()`.
118
-
119
- ```typescript
120
- const mongo = ctx.service<MongoService>(MONGO_ALIAS) // this call is what triggers lazyInit
121
- await mongo.ready()
122
- ```
123
-
124
- A lazy service's init runs only when someone resolves it through `context.service(alias)`, so
125
- `ready()` on a reference obtained any other way never settles.
126
-
127
- ## Middlewares
128
-
129
- A middleware declares a `type` (`Config` or `Context`) and a `stage` (`Configuration`, `Loading` or
130
- `Ready`), and that pair — not the stage alone — decides where it runs. Exactly five pairs are ever
131
- applied, in this order:
132
-
133
- | Type + stage | Where it runs |
134
- |--------------|---------------|
135
- | `Config` + `Configuration` | inside `configure()`, before the stage becomes `Loading` — the only hook that sees `cfg` before anything else does |
136
- | `Context` + `Configuration` | first thing inside `init()` |
137
- | `Config` + `Loading` | inside `init()`, **after every service has been initialized** and before the resources |
138
- | `Context` + `Loading` | inside `init()`, after the resources |
139
- | `Context` + `Ready` | after the stage flips to `Ready`; started but **not awaited**, so `init()` resolves without waiting for it |
140
-
141
- `Config` + `Ready` is never applied at all — a middleware registered under that pair silently never
142
- runs. All middlewares sharing a pair are applied with `Promise.all`, so they run concurrently and
143
- registration order does not sequence them.
144
-
145
- Pick the pair by what the work needs. `Config` + `Configuration` is for config that stands on its
146
- own — mounted secrets, hosts read from the environment. `Config` + `Loading` is for config that has
147
- to be resolved *through a running service*, because services are already initialized by then; that
148
- is the stage a cluster- or vault-backed value resolver registers at, and it can `await
149
- service.ready()` on the service it depends on. `Context` middlewares register or adjust what the
150
- container holds.
151
-
152
- ```typescript
153
- context.registerMiddleware({
154
- type: MiddlewareType.Config,
155
- stage: MiddlewareStage.Loading, // services are up — resolve cfg values through one of them
156
- apply: async ctx => { /* mutate ctx.cfg */ }
157
- })
158
- ```
159
-
160
- ## Depends On
161
-
162
- - Nothing. This is the root package — `@owlmeans/config` layers the application config on top of
163
- `BasicConfig`, and `@owlmeans/entrypoint` layers URL units on top of `BasicEntrypoint`.
@@ -1,6 +0,0 @@
1
- import type { MiddlewareStage, MiddlewareType } from '../consts.js';
2
- import type { BasicConfig, BasicContext, Middleware } from '../types.js';
3
- export declare const getMiddlerwareKey: (middleware: Middleware) => string;
4
- export declare const createMiddlewareKey: (type: MiddlewareType, stage: MiddlewareStage) => string;
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[]>;
6
- //# sourceMappingURL=context.d.ts.map
@@ -1 +0,0 @@
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,eAAgB,UAAU,WAA2D,CAAA;AAEnH,eAAO,MAAM,mBAAmB,SAAU,cAAc,SAAS,eAAe,WAAuB,CAAA;AAEvG,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,YAAY,CAAC,CAAC,CAAC,WACtE,CAAC,eACG,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,QACnC,cAAc,SACb,eAAe,SACf,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,oBAG1C,CAAA"}
@@ -1,4 +0,0 @@
1
- export const getMiddlerwareKey = (middleware) => createMiddlewareKey(middleware.type, middleware.stage);
2
- export const createMiddlewareKey = (type, stage) => `${type}:${stage}`;
3
- export const applyMiddlewares = (context, middlewares, type, stage, args) => Promise.all(middlewares[createMiddlewareKey(type, stage)]?.map(async (middleware) => middleware.apply(context, args)) ?? []);
4
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
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"}
@@ -1,16 +0,0 @@
1
- import type { MiddlewareStage, MiddlewareType } from '../consts.js'
2
- import type { BasicConfig, BasicContext, Middleware } from '../types.js'
3
-
4
- export const getMiddlerwareKey = (middleware: Middleware) => createMiddlewareKey(middleware.type, middleware.stage)
5
-
6
- export const createMiddlewareKey = (type: MiddlewareType, stage: MiddlewareStage) => `${type}:${stage}`
7
-
8
- export const applyMiddlewares = <C extends BasicConfig, T extends BasicContext<C>>(
9
- context: T,
10
- middlewares: Record<string, Middleware[]>,
11
- type: MiddlewareType,
12
- stage: MiddlewareStage,
13
- args?: Record<string, string | undefined>
14
- ) => Promise.all(
15
- middlewares[createMiddlewareKey(type, stage)]?.map(async middleware => middleware.apply<C, T>(context, args)) ?? []
16
- )