@warlock.js/context 4.0.171 → 4.1.1

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 (42) hide show
  1. package/cjs/index.cjs +239 -0
  2. package/cjs/index.cjs.map +1 -0
  3. package/esm/base-context.d.mts +99 -0
  4. package/esm/base-context.d.mts.map +1 -0
  5. package/esm/base-context.mjs +110 -0
  6. package/esm/base-context.mjs.map +1 -0
  7. package/esm/context-manager.d.mts +106 -0
  8. package/esm/context-manager.d.mts.map +1 -0
  9. package/esm/context-manager.mjs +128 -0
  10. package/esm/context-manager.mjs.map +1 -0
  11. package/esm/index.d.mts +3 -0
  12. package/esm/index.mjs +4 -0
  13. package/llms-full.txt +404 -0
  14. package/llms.txt +11 -0
  15. package/package.json +42 -30
  16. package/skills/define-context/SKILL.md +158 -0
  17. package/skills/orchestrate-contexts/SKILL.md +161 -0
  18. package/skills/overview/SKILL.md +67 -0
  19. package/cjs/base-context.d.ts +0 -96
  20. package/cjs/base-context.d.ts.map +0 -1
  21. package/cjs/base-context.js +0 -105
  22. package/cjs/base-context.js.map +0 -1
  23. package/cjs/context-manager.d.ts +0 -102
  24. package/cjs/context-manager.d.ts.map +0 -1
  25. package/cjs/context-manager.js +0 -132
  26. package/cjs/context-manager.js.map +0 -1
  27. package/cjs/index.d.ts +0 -3
  28. package/cjs/index.d.ts.map +0 -1
  29. package/cjs/index.js +0 -1
  30. package/cjs/index.js.map +0 -1
  31. package/esm/base-context.d.ts +0 -96
  32. package/esm/base-context.d.ts.map +0 -1
  33. package/esm/base-context.js +0 -105
  34. package/esm/base-context.js.map +0 -1
  35. package/esm/context-manager.d.ts +0 -102
  36. package/esm/context-manager.d.ts.map +0 -1
  37. package/esm/context-manager.js +0 -132
  38. package/esm/context-manager.js.map +0 -1
  39. package/esm/index.d.ts +0 -3
  40. package/esm/index.d.ts.map +0 -1
  41. package/esm/index.js +0 -1
  42. package/esm/index.js.map +0 -1
@@ -1,132 +0,0 @@
1
- /**
2
- * Context Manager - Orchestrates multiple contexts together
3
- *
4
- * Allows running multiple AsyncLocalStorage contexts in a single operation,
5
- * making it easy to link request, storage, database, and other contexts.
6
- *
7
- * @example
8
- * ```typescript
9
- * // Register contexts
10
- * contextManager
11
- * .register('request', requestContext)
12
- * .register('storage', storageDriverContext)
13
- * .register('database', databaseDataSourceContext);
14
- *
15
- * // Run all contexts together
16
- * await contextManager.runAll({
17
- * request: { request, response, user },
18
- * storage: { driver, metadata: { tenantId: '123' } },
19
- * database: { dataSource: 'primary' },
20
- * }, async () => {
21
- * // All contexts active!
22
- * await handleRequest();
23
- * });
24
- * ```
25
- */
26
- class ContextManager {
27
- contexts = new Map();
28
- /**
29
- * Register a context
30
- *
31
- * @param name - Unique context name
32
- * @param context - Context instance
33
- * @returns This instance for chaining
34
- */
35
- register(name, context) {
36
- this.contexts.set(name, context);
37
- return this;
38
- }
39
- /**
40
- * Run all registered contexts together
41
- *
42
- * Nests all context.run() calls, ensuring all contexts are active
43
- * for the duration of the callback.
44
- *
45
- * @param stores - Context stores keyed by context name
46
- * @param callback - Async function to execute
47
- * @returns Result of the callback
48
- */
49
- async runAll(stores, callback) {
50
- const entries = Array.from(this.contexts.entries());
51
- // Build nested context runners
52
- const runner = entries.reduceRight((next, [name, context]) => {
53
- return () => context.run(stores[name] || {}, next);
54
- }, callback);
55
- return runner();
56
- }
57
- /**
58
- * Enter all contexts at once (for middleware)
59
- *
60
- * @param stores - Context stores keyed by context name
61
- */
62
- enterAll(stores) {
63
- for (const [name, context] of this.contexts.entries()) {
64
- if (stores[name]) {
65
- context.enter(stores[name]);
66
- }
67
- }
68
- }
69
- /**
70
- * Clear all contexts
71
- */
72
- clearAll() {
73
- for (const context of this.contexts.values()) {
74
- context.clear();
75
- }
76
- }
77
- /**
78
- * Get a specific registered context
79
- *
80
- * @param name - Context name
81
- * @returns Context instance or undefined
82
- */
83
- getContext(name) {
84
- return this.contexts.get(name);
85
- }
86
- /**
87
- * Check if a context is registered
88
- *
89
- * @param name - Context name
90
- * @returns True if context is registered
91
- */
92
- hasContext(name) {
93
- return this.contexts.has(name);
94
- }
95
- /**
96
- * Build all context stores by calling each context's buildStore() method
97
- *
98
- * This is the immutable pattern - returns a new record of stores.
99
- * Each context defines its own initialization logic.
100
- *
101
- * @param payload - Payload passed to each buildStore() (e.g., { request, response })
102
- * @returns Record of context name -> store data
103
- *
104
- * @example
105
- * ```typescript
106
- * const httpContextStore = contextManager.buildStores({ request, response });
107
- * await contextManager.runAll(httpContextStore, async () => { ... });
108
- * ```
109
- */
110
- buildStores(payload) {
111
- const stores = {};
112
- for (const [name, context] of this.contexts.entries()) {
113
- stores[name] = context.buildStore(payload) ?? {};
114
- }
115
- return stores;
116
- }
117
- /**
118
- * Unregister a context
119
- *
120
- * @param name - Context name to remove
121
- * @returns True if context was removed
122
- */
123
- unregister(name) {
124
- return this.contexts.delete(name);
125
- }
126
- }
127
- /**
128
- * Global context manager instance
129
- *
130
- * Use this singleton to register and manage all framework contexts.
131
- */
132
- const contextManager = new ContextManager();export{ContextManager,contextManager};//# sourceMappingURL=context-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-manager.js","sources":["../src/context-manager.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;MACU,cAAc,CAAA;AACjB,IAAA,QAAQ,GAAG,IAAI,GAAG,EAAwB,CAAC;AAEnD;;;;;;AAMG;IACI,QAAQ,CAAC,IAAY,EAAE,OAAqB,EAAA;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACjC,QAAA,OAAO,IAAI,CAAC;KACb;AAED;;;;;;;;;AASG;AACI,IAAA,MAAM,MAAM,CAAI,MAA2B,EAAE,QAA0B,EAAA;AAC5E,QAAA,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,C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AI,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;AAClD,SAAA;AAED,QAAA,OAAO,MAAM,CAAC;KACf;AAED;;;;;AAKG;AACI,IAAA,UAAU,CAAC,IAAY,EAAA;QAC5B,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KACnC;AACF,CAAA;AAED;;;;AAIG;AACU,MAAA,cAAc,GAAG,IAAI,cAAc"}
package/esm/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./base-context";
2
- export * from "./context-manager";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
package/esm/index.js DELETED
@@ -1 +0,0 @@
1
- export{Context}from'./base-context.js';export{ContextManager,contextManager}from'./context-manager.js';//# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}