apcore-js 0.5.0 → 0.7.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 (319) hide show
  1. package/README.md +1 -1
  2. package/dist/acl.d.ts +27 -0
  3. package/dist/acl.d.ts.map +1 -0
  4. package/dist/acl.js +175 -0
  5. package/dist/acl.js.map +1 -0
  6. package/dist/approval.d.ts +85 -0
  7. package/dist/approval.d.ts.map +1 -0
  8. package/dist/approval.js +73 -0
  9. package/dist/approval.js.map +1 -0
  10. package/dist/async-task.d.ts +90 -0
  11. package/dist/async-task.d.ts.map +1 -0
  12. package/dist/async-task.js +215 -0
  13. package/dist/async-task.js.map +1 -0
  14. package/dist/bindings.d.ts +12 -0
  15. package/dist/bindings.d.ts.map +1 -0
  16. package/dist/bindings.js +185 -0
  17. package/dist/bindings.js.map +1 -0
  18. package/dist/cancel.d.ts +14 -0
  19. package/dist/cancel.d.ts.map +1 -0
  20. package/dist/cancel.js +27 -0
  21. package/dist/cancel.js.map +1 -0
  22. package/dist/config.d.ts +9 -0
  23. package/dist/config.d.ts.map +1 -0
  24. package/dist/config.js +23 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/context.d.ts +50 -0
  27. package/dist/context.d.ts.map +1 -0
  28. package/dist/context.js +87 -0
  29. package/dist/context.js.map +1 -0
  30. package/dist/decorator.d.ts +57 -0
  31. package/dist/decorator.d.ts.map +1 -0
  32. package/dist/decorator.js +74 -0
  33. package/dist/decorator.js.map +1 -0
  34. package/dist/errors.d.ts +204 -0
  35. package/dist/errors.d.ts.map +1 -0
  36. package/dist/errors.js +364 -0
  37. package/dist/errors.js.map +1 -0
  38. package/dist/executor.d.ts +82 -0
  39. package/dist/executor.d.ts.map +1 -0
  40. package/dist/executor.js +489 -0
  41. package/dist/executor.js.map +1 -0
  42. package/dist/extensions.d.ts +58 -0
  43. package/dist/extensions.d.ts.map +1 -0
  44. package/dist/extensions.js +239 -0
  45. package/dist/extensions.js.map +1 -0
  46. package/{src/index.ts → dist/index.d.ts} +6 -63
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +45 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/middleware/adapters.d.ts +18 -0
  51. package/dist/middleware/adapters.d.ts.map +1 -0
  52. package/dist/middleware/adapters.js +25 -0
  53. package/dist/middleware/adapters.js.map +1 -0
  54. package/dist/middleware/base.d.ts +10 -0
  55. package/dist/middleware/base.d.ts.map +1 -0
  56. package/dist/middleware/base.js +15 -0
  57. package/dist/middleware/base.js.map +1 -0
  58. package/{src/middleware/index.ts → dist/middleware/index.d.ts} +1 -0
  59. package/dist/middleware/index.d.ts.map +1 -0
  60. package/dist/middleware/index.js +5 -0
  61. package/dist/middleware/index.js.map +1 -0
  62. package/dist/middleware/logging.d.ts +25 -0
  63. package/dist/middleware/logging.d.ts.map +1 -0
  64. package/dist/middleware/logging.js +64 -0
  65. package/dist/middleware/logging.js.map +1 -0
  66. package/dist/middleware/manager.d.ts +21 -0
  67. package/dist/middleware/manager.d.ts.map +1 -0
  68. package/dist/middleware/manager.js +77 -0
  69. package/dist/middleware/manager.js.map +1 -0
  70. package/dist/module.d.ts +31 -0
  71. package/dist/module.d.ts.map +1 -0
  72. package/dist/module.js +12 -0
  73. package/dist/module.js.map +1 -0
  74. package/dist/observability/context-logger.d.ts +54 -0
  75. package/dist/observability/context-logger.d.ts.map +1 -0
  76. package/dist/observability/context-logger.js +151 -0
  77. package/dist/observability/context-logger.js.map +1 -0
  78. package/{src/observability/index.ts → dist/observability/index.d.ts} +1 -0
  79. package/dist/observability/index.d.ts.map +1 -0
  80. package/dist/observability/index.js +4 -0
  81. package/dist/observability/index.js.map +1 -0
  82. package/dist/observability/metrics.d.ts +30 -0
  83. package/dist/observability/metrics.d.ts.map +1 -0
  84. package/dist/observability/metrics.js +177 -0
  85. package/dist/observability/metrics.js.map +1 -0
  86. package/dist/observability/tracing.d.ts +62 -0
  87. package/dist/observability/tracing.d.ts.map +1 -0
  88. package/dist/observability/tracing.js +184 -0
  89. package/dist/observability/tracing.js.map +1 -0
  90. package/dist/registry/dependencies.d.ts +6 -0
  91. package/dist/registry/dependencies.d.ts.map +1 -0
  92. package/dist/registry/dependencies.js +83 -0
  93. package/dist/registry/dependencies.js.map +1 -0
  94. package/dist/registry/entry-point.d.ts +6 -0
  95. package/dist/registry/entry-point.d.ts.map +1 -0
  96. package/dist/registry/entry-point.js +55 -0
  97. package/dist/registry/entry-point.js.map +1 -0
  98. package/{src/registry/index.ts → dist/registry/index.d.ts} +1 -0
  99. package/dist/registry/index.d.ts.map +1 -0
  100. package/dist/registry/index.js +8 -0
  101. package/dist/registry/index.js.map +1 -0
  102. package/dist/registry/metadata.d.ts +9 -0
  103. package/dist/registry/metadata.d.ts.map +1 -0
  104. package/dist/registry/metadata.js +105 -0
  105. package/dist/registry/metadata.js.map +1 -0
  106. package/dist/registry/registry.d.ts +102 -0
  107. package/dist/registry/registry.d.ts.map +1 -0
  108. package/dist/registry/registry.js +534 -0
  109. package/dist/registry/registry.js.map +1 -0
  110. package/dist/registry/scanner.d.ts +7 -0
  111. package/dist/registry/scanner.d.ts.map +1 -0
  112. package/dist/registry/scanner.js +164 -0
  113. package/dist/registry/scanner.js.map +1 -0
  114. package/dist/registry/schema-export.d.ts +9 -0
  115. package/dist/registry/schema-export.d.ts.map +1 -0
  116. package/dist/registry/schema-export.js +132 -0
  117. package/dist/registry/schema-export.js.map +1 -0
  118. package/dist/registry/types.d.ts +29 -0
  119. package/dist/registry/types.d.ts.map +1 -0
  120. package/dist/registry/types.js +5 -0
  121. package/dist/registry/types.js.map +1 -0
  122. package/dist/registry/validation.d.ts +9 -0
  123. package/dist/registry/validation.d.ts.map +1 -0
  124. package/dist/registry/validation.js +33 -0
  125. package/dist/registry/validation.js.map +1 -0
  126. package/dist/schema/annotations.d.ts +8 -0
  127. package/dist/schema/annotations.d.ts.map +1 -0
  128. package/dist/schema/annotations.js +52 -0
  129. package/dist/schema/annotations.js.map +1 -0
  130. package/dist/schema/exporter.d.ts +13 -0
  131. package/dist/schema/exporter.d.ts.map +1 -0
  132. package/dist/schema/exporter.js +71 -0
  133. package/dist/schema/exporter.js.map +1 -0
  134. package/dist/schema/index.d.ts +9 -0
  135. package/dist/schema/index.d.ts.map +1 -0
  136. package/{src/schema/index.ts → dist/schema/index.js} +1 -7
  137. package/dist/schema/index.js.map +1 -0
  138. package/dist/schema/loader.d.ts +30 -0
  139. package/dist/schema/loader.d.ts.map +1 -0
  140. package/dist/schema/loader.js +260 -0
  141. package/dist/schema/loader.js.map +1 -0
  142. package/dist/schema/ref-resolver.d.ts +19 -0
  143. package/dist/schema/ref-resolver.d.ts.map +1 -0
  144. package/dist/schema/ref-resolver.js +212 -0
  145. package/dist/schema/ref-resolver.js.map +1 -0
  146. package/dist/schema/strict.d.ts +7 -0
  147. package/dist/schema/strict.d.ts.map +1 -0
  148. package/dist/schema/strict.js +127 -0
  149. package/dist/schema/strict.js.map +1 -0
  150. package/dist/schema/types.d.ts +53 -0
  151. package/dist/schema/types.d.ts.map +1 -0
  152. package/dist/schema/types.js +31 -0
  153. package/dist/schema/types.js.map +1 -0
  154. package/dist/schema/validator.d.ts +16 -0
  155. package/dist/schema/validator.d.ts.map +1 -0
  156. package/dist/schema/validator.js +71 -0
  157. package/dist/schema/validator.js.map +1 -0
  158. package/dist/trace-context.d.ts +35 -0
  159. package/dist/trace-context.d.ts.map +1 -0
  160. package/dist/trace-context.js +86 -0
  161. package/dist/trace-context.js.map +1 -0
  162. package/dist/utils/index.d.ts +11 -0
  163. package/dist/utils/index.d.ts.map +1 -0
  164. package/dist/utils/index.js +32 -0
  165. package/dist/utils/index.js.map +1 -0
  166. package/dist/utils/pattern.d.ts +5 -0
  167. package/dist/utils/pattern.d.ts.map +1 -0
  168. package/dist/utils/pattern.js +31 -0
  169. package/dist/utils/pattern.js.map +1 -0
  170. package/package.json +24 -3
  171. package/.claude/settings.local.json +0 -12
  172. package/.github/workflows/ci.yml +0 -39
  173. package/.gitmessage +0 -60
  174. package/.pre-commit-config.yaml +0 -28
  175. package/CHANGELOG.md +0 -214
  176. package/CLAUDE.md +0 -68
  177. package/apcore-logo.svg +0 -79
  178. package/planning/acl-system/overview.md +0 -54
  179. package/planning/acl-system/plan.md +0 -92
  180. package/planning/acl-system/state.json +0 -76
  181. package/planning/acl-system/tasks/acl-core.md +0 -226
  182. package/planning/acl-system/tasks/acl-rule.md +0 -92
  183. package/planning/acl-system/tasks/conditional-rules.md +0 -259
  184. package/planning/acl-system/tasks/pattern-matching.md +0 -152
  185. package/planning/acl-system/tasks/yaml-loading.md +0 -271
  186. package/planning/core-executor/overview.md +0 -53
  187. package/planning/core-executor/plan.md +0 -88
  188. package/planning/core-executor/state.json +0 -76
  189. package/planning/core-executor/tasks/async-support.md +0 -106
  190. package/planning/core-executor/tasks/execution-pipeline.md +0 -113
  191. package/planning/core-executor/tasks/redaction.md +0 -85
  192. package/planning/core-executor/tasks/safety-checks.md +0 -65
  193. package/planning/core-executor/tasks/setup.md +0 -75
  194. package/planning/decorator-bindings/overview.md +0 -62
  195. package/planning/decorator-bindings/plan.md +0 -104
  196. package/planning/decorator-bindings/state.json +0 -87
  197. package/planning/decorator-bindings/tasks/binding-directory.md +0 -79
  198. package/planning/decorator-bindings/tasks/binding-loader.md +0 -148
  199. package/planning/decorator-bindings/tasks/explicit-schemas.md +0 -85
  200. package/planning/decorator-bindings/tasks/function-module.md +0 -127
  201. package/planning/decorator-bindings/tasks/module-factory.md +0 -89
  202. package/planning/decorator-bindings/tasks/schema-modes.md +0 -142
  203. package/planning/middleware-system/overview.md +0 -48
  204. package/planning/middleware-system/plan.md +0 -102
  205. package/planning/middleware-system/state.json +0 -65
  206. package/planning/middleware-system/tasks/adapters.md +0 -170
  207. package/planning/middleware-system/tasks/base.md +0 -115
  208. package/planning/middleware-system/tasks/logging-middleware.md +0 -304
  209. package/planning/middleware-system/tasks/manager.md +0 -313
  210. package/planning/observability/overview.md +0 -53
  211. package/planning/observability/plan.md +0 -119
  212. package/planning/observability/state.json +0 -98
  213. package/planning/observability/tasks/context-logger.md +0 -201
  214. package/planning/observability/tasks/exporters.md +0 -121
  215. package/planning/observability/tasks/metrics-collector.md +0 -162
  216. package/planning/observability/tasks/metrics-middleware.md +0 -141
  217. package/planning/observability/tasks/obs-logging-middleware.md +0 -179
  218. package/planning/observability/tasks/span-model.md +0 -120
  219. package/planning/observability/tasks/tracing-middleware.md +0 -179
  220. package/planning/overview.md +0 -81
  221. package/planning/registry-system/overview.md +0 -57
  222. package/planning/registry-system/plan.md +0 -114
  223. package/planning/registry-system/state.json +0 -109
  224. package/planning/registry-system/tasks/dependencies.md +0 -157
  225. package/planning/registry-system/tasks/entry-point.md +0 -148
  226. package/planning/registry-system/tasks/metadata.md +0 -198
  227. package/planning/registry-system/tasks/registry-core.md +0 -323
  228. package/planning/registry-system/tasks/scanner.md +0 -172
  229. package/planning/registry-system/tasks/schema-export.md +0 -261
  230. package/planning/registry-system/tasks/types.md +0 -124
  231. package/planning/registry-system/tasks/validation.md +0 -177
  232. package/planning/schema-system/overview.md +0 -56
  233. package/planning/schema-system/plan.md +0 -121
  234. package/planning/schema-system/state.json +0 -98
  235. package/planning/schema-system/tasks/exporter.md +0 -153
  236. package/planning/schema-system/tasks/loader.md +0 -106
  237. package/planning/schema-system/tasks/ref-resolver.md +0 -133
  238. package/planning/schema-system/tasks/strict-mode.md +0 -140
  239. package/planning/schema-system/tasks/typebox-generation.md +0 -133
  240. package/planning/schema-system/tasks/types-and-annotations.md +0 -160
  241. package/planning/schema-system/tasks/validator.md +0 -149
  242. package/src/acl.ts +0 -200
  243. package/src/async-task.ts +0 -267
  244. package/src/bindings.ts +0 -207
  245. package/src/cancel.ts +0 -32
  246. package/src/config.ts +0 -24
  247. package/src/context.ts +0 -160
  248. package/src/decorator.ts +0 -110
  249. package/src/errors.ts +0 -429
  250. package/src/executor.ts +0 -493
  251. package/src/extensions.ts +0 -265
  252. package/src/middleware/adapters.ts +0 -54
  253. package/src/middleware/base.ts +0 -33
  254. package/src/middleware/logging.ts +0 -103
  255. package/src/middleware/manager.ts +0 -105
  256. package/src/module.ts +0 -43
  257. package/src/observability/context-logger.ts +0 -203
  258. package/src/observability/metrics.ts +0 -214
  259. package/src/observability/tracing.ts +0 -252
  260. package/src/registry/dependencies.ts +0 -99
  261. package/src/registry/entry-point.ts +0 -64
  262. package/src/registry/metadata.ts +0 -111
  263. package/src/registry/registry.ts +0 -580
  264. package/src/registry/scanner.ts +0 -168
  265. package/src/registry/schema-export.ts +0 -181
  266. package/src/registry/types.ts +0 -32
  267. package/src/registry/validation.ts +0 -38
  268. package/src/schema/annotations.ts +0 -68
  269. package/src/schema/exporter.ts +0 -90
  270. package/src/schema/loader.ts +0 -273
  271. package/src/schema/ref-resolver.ts +0 -244
  272. package/src/schema/strict.ts +0 -136
  273. package/src/schema/types.ts +0 -73
  274. package/src/schema/validator.ts +0 -82
  275. package/src/trace-context.ts +0 -102
  276. package/src/utils/index.ts +0 -5
  277. package/src/utils/pattern.ts +0 -30
  278. package/tests/async-task.test.ts +0 -335
  279. package/tests/helpers.ts +0 -30
  280. package/tests/integration/test-acl-safety.test.ts +0 -269
  281. package/tests/integration/test-binding-executor.test.ts +0 -194
  282. package/tests/integration/test-e2e-flow.test.ts +0 -117
  283. package/tests/integration/test-error-propagation.test.ts +0 -259
  284. package/tests/integration/test-middleware-chain.test.ts +0 -120
  285. package/tests/integration/test-observability-integration.test.ts +0 -438
  286. package/tests/observability/test-context-logger.test.ts +0 -123
  287. package/tests/observability/test-metrics.test.ts +0 -186
  288. package/tests/observability/test-tracing.test.ts +0 -303
  289. package/tests/registry/test-dependencies.test.ts +0 -70
  290. package/tests/registry/test-entry-point.test.ts +0 -133
  291. package/tests/registry/test-metadata.test.ts +0 -265
  292. package/tests/registry/test-registry.test.ts +0 -1397
  293. package/tests/registry/test-scanner.test.ts +0 -257
  294. package/tests/registry/test-schema-export.test.ts +0 -355
  295. package/tests/registry/test-validation.test.ts +0 -75
  296. package/tests/schema/test-annotations.test.ts +0 -137
  297. package/tests/schema/test-exporter.test.ts +0 -172
  298. package/tests/schema/test-loader.test.ts +0 -461
  299. package/tests/schema/test-ref-resolver.test.ts +0 -530
  300. package/tests/schema/test-strict.test.ts +0 -348
  301. package/tests/schema/test-validator.test.ts +0 -64
  302. package/tests/test-acl.test.ts +0 -423
  303. package/tests/test-bindings.test.ts +0 -227
  304. package/tests/test-cancel.test.ts +0 -71
  305. package/tests/test-config.test.ts +0 -76
  306. package/tests/test-context.test.ts +0 -266
  307. package/tests/test-decorator.test.ts +0 -173
  308. package/tests/test-errors.test.ts +0 -647
  309. package/tests/test-executor-stream.test.ts +0 -208
  310. package/tests/test-executor.test.ts +0 -252
  311. package/tests/test-extensions.test.ts +0 -310
  312. package/tests/test-logging-middleware.test.ts +0 -150
  313. package/tests/test-middleware-manager.test.ts +0 -185
  314. package/tests/test-middleware.test.ts +0 -86
  315. package/tests/test-trace-context.test.ts +0 -251
  316. package/tests/utils/test-pattern.test.ts +0 -109
  317. package/tsconfig.build.json +0 -8
  318. package/tsconfig.json +0 -20
  319. package/vitest.config.ts +0 -18
package/src/config.ts DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * Configuration accessor with dot-path key support.
3
- */
4
-
5
- export class Config {
6
- private _data: Record<string, unknown>;
7
-
8
- constructor(data?: Record<string, unknown>) {
9
- this._data = data ?? {};
10
- }
11
-
12
- get(key: string, defaultValue?: unknown): unknown {
13
- const parts = key.split('.');
14
- let current: unknown = this._data;
15
- for (const part of parts) {
16
- if (current !== null && typeof current === 'object' && part in (current as Record<string, unknown>)) {
17
- current = (current as Record<string, unknown>)[part];
18
- } else {
19
- return defaultValue;
20
- }
21
- }
22
- return current;
23
- }
24
- }
package/src/context.ts DELETED
@@ -1,160 +0,0 @@
1
-
2
- import { v4 as uuidv4 } from 'uuid';
3
- import type { CancelToken } from './cancel.js';
4
- import type { TraceParent } from './trace-context.js';
5
-
6
- /**
7
- * Execution context, identity, and context creation.
8
- */
9
-
10
- export interface Identity {
11
- readonly id: string;
12
- readonly type: string;
13
- readonly roles: readonly string[];
14
- readonly attrs: Readonly<Record<string, unknown>>;
15
- }
16
-
17
- export function createIdentity(
18
- id: string,
19
- type: string = 'user',
20
- roles: string[] = [],
21
- attrs: Record<string, unknown> = {},
22
- ): Identity {
23
- return Object.freeze({ id, type, roles: Object.freeze([...roles]), attrs: Object.freeze({ ...attrs }) });
24
- }
25
-
26
- export class Context {
27
- readonly traceId: string;
28
- readonly callerId: string | null;
29
- readonly callChain: readonly string[];
30
- readonly executor: unknown;
31
- readonly identity: Identity | null;
32
- redactedInputs: Record<string, unknown> | null;
33
- readonly data: Record<string, unknown>;
34
- readonly cancelToken: CancelToken | null;
35
-
36
- constructor(
37
- traceId: string,
38
- callerId: string | null = null,
39
- callChain: string[] = [],
40
- executor: unknown = null,
41
- identity: Identity | null = null,
42
- redactedInputs: Record<string, unknown> | null = null,
43
- data: Record<string, unknown> = {},
44
- cancelToken: CancelToken | null = null,
45
- ) {
46
- this.traceId = traceId;
47
- this.callerId = callerId;
48
- this.callChain = Object.freeze([...callChain]);
49
- this.executor = executor;
50
- this.identity = identity;
51
- this.redactedInputs = redactedInputs;
52
- this.data = data;
53
- this.cancelToken = cancelToken;
54
- }
55
-
56
- /**
57
- * Create a new top-level Context with a generated UUID v4 traceId.
58
- *
59
- * When `traceParent` is provided, its `traceId` (32 hex chars) is
60
- * converted to UUID format (8-4-4-4-12) and used instead of generating
61
- * a new one.
62
- */
63
- static create(
64
- executor: unknown = null,
65
- identity: Identity | null = null,
66
- data?: Record<string, unknown>,
67
- traceParent?: TraceParent | null,
68
- ): Context {
69
- let traceId: string;
70
- if (traceParent) {
71
- const h = traceParent.traceId;
72
- traceId = `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
73
- } else {
74
- traceId = uuidv4();
75
- }
76
- return new Context(
77
- traceId,
78
- null,
79
- [],
80
- executor,
81
- identity,
82
- null,
83
- data ?? {},
84
- );
85
- }
86
-
87
- toJSON(): Record<string, unknown> {
88
- const publicData: Record<string, unknown> = {};
89
- for (const [key, value] of Object.entries(this.data)) {
90
- if (!key.startsWith('_')) {
91
- publicData[key] = value;
92
- }
93
- }
94
- return {
95
- traceId: this.traceId,
96
- callerId: this.callerId,
97
- callChain: [...this.callChain],
98
- identity: this.identity ? {
99
- id: this.identity.id,
100
- type: this.identity.type,
101
- roles: [...this.identity.roles],
102
- attrs: { ...this.identity.attrs },
103
- } : null,
104
- redactedInputs: this.redactedInputs ? { ...this.redactedInputs } : null,
105
- data: publicData,
106
- };
107
- }
108
-
109
- static fromJSON(data: Record<string, unknown>, executor?: unknown): Context {
110
- const identityData = data.identity as Record<string, unknown> | null;
111
- const identity = identityData ? {
112
- id: identityData.id as string,
113
- type: (identityData.type as string) ?? 'user',
114
- roles: Object.freeze([...(Array.isArray(identityData.roles) ? identityData.roles : [])]),
115
- attrs: Object.freeze((identityData.attrs && typeof identityData.attrs === 'object' ? identityData.attrs : {}) as Record<string, unknown>),
116
- } : null;
117
- return new Context(
118
- data.traceId as string,
119
- (data.callerId as string) ?? null,
120
- (data.callChain as string[]) ?? [],
121
- executor ?? null,
122
- identity,
123
- (data.redactedInputs as Record<string, unknown>) ?? null,
124
- data.data ? { ...(data.data as Record<string, unknown>) } : {},
125
- );
126
- }
127
-
128
- get logger(): { debug: (...args: unknown[]) => void; info: (...args: unknown[]) => void; warn: (...args: unknown[]) => void; error: (...args: unknown[]) => void } {
129
- const prefix = `[apcore:${this.callerId ?? 'unknown'}]`;
130
- return {
131
- debug: (...args: unknown[]) => console.debug(prefix, ...args),
132
- info: (...args: unknown[]) => console.info(prefix, ...args),
133
- warn: (...args: unknown[]) => console.warn(prefix, ...args),
134
- error: (...args: unknown[]) => console.error(prefix, ...args),
135
- };
136
- }
137
-
138
- child(targetModuleId: string): Context {
139
- return new Context(
140
- this.traceId,
141
- this.callChain.length > 0 ? this.callChain[this.callChain.length - 1] : null,
142
- [...this.callChain, targetModuleId],
143
- this.executor,
144
- this.identity,
145
- null,
146
- this.data, // shared reference
147
- this.cancelToken,
148
- );
149
- }
150
- }
151
-
152
- /**
153
- * Interface for creating Context from framework-specific requests.
154
- *
155
- * Web framework integrations should implement this to extract Identity
156
- * from HTTP requests (e.g., Express request, JWT tokens, API keys).
157
- */
158
- export interface ContextFactory {
159
- createContext(request: unknown): Context;
160
- }
package/src/decorator.ts DELETED
@@ -1,110 +0,0 @@
1
- /**
2
- * Module factory, FunctionModule wrapper.
3
- *
4
- * TypeScript version uses explicit TypeBox schemas instead of runtime type inference.
5
- */
6
-
7
- import type { TSchema } from '@sinclair/typebox';
8
- import type { Context } from './context.js';
9
- import type { ModuleAnnotations, ModuleExample } from './module.js';
10
-
11
- export function normalizeResult(result: unknown): Record<string, unknown> {
12
- if (result === null || result === undefined) return {};
13
- if (typeof result === 'object' && !Array.isArray(result)) return result as Record<string, unknown>;
14
- return { result };
15
- }
16
-
17
- export class FunctionModule {
18
- readonly moduleId: string;
19
- readonly inputSchema: TSchema;
20
- readonly outputSchema: TSchema;
21
- readonly description: string;
22
- readonly documentation: string | null;
23
- readonly tags: string[] | null;
24
- readonly version: string;
25
- readonly annotations: ModuleAnnotations | null;
26
- readonly metadata: Record<string, unknown> | null;
27
- readonly examples: ModuleExample[] | null;
28
-
29
- private _executeFn: (inputs: Record<string, unknown>, context: Context) => Promise<Record<string, unknown>> | Record<string, unknown>;
30
-
31
- constructor(options: {
32
- execute: (inputs: Record<string, unknown>, context: Context) => Promise<Record<string, unknown>> | Record<string, unknown>;
33
- moduleId: string;
34
- inputSchema: TSchema;
35
- outputSchema: TSchema;
36
- description?: string;
37
- documentation?: string | null;
38
- tags?: string[] | null;
39
- version?: string;
40
- annotations?: ModuleAnnotations | null;
41
- metadata?: Record<string, unknown> | null;
42
- examples?: ModuleExample[] | null;
43
- }) {
44
- this.moduleId = options.moduleId;
45
- this.inputSchema = options.inputSchema;
46
- this.outputSchema = options.outputSchema;
47
- this.description = options.description ?? `Module ${options.moduleId}`;
48
- this.documentation = options.documentation ?? null;
49
- this.tags = options.tags ?? null;
50
- this.version = options.version ?? '1.0.0';
51
- this.annotations = options.annotations ?? null;
52
- this.metadata = options.metadata ?? null;
53
- this.examples = options.examples ?? null;
54
- this._executeFn = options.execute;
55
- }
56
-
57
- async execute(inputs: Record<string, unknown>, context: Context): Promise<Record<string, unknown>> {
58
- const result = await this._executeFn(inputs, context);
59
- return normalizeResult(result);
60
- }
61
- }
62
-
63
- export function makeAutoId(name: string): string {
64
- let raw = name.toLowerCase();
65
- raw = raw.replace(/[^a-z0-9_.]/g, '_');
66
- const segments = raw.split('.');
67
- return segments
68
- .map((s) => (s && s[0] >= '0' && s[0] <= '9' ? '_' + s : s))
69
- .join('.');
70
- }
71
-
72
- /**
73
- * Create a FunctionModule from options. TypeScript version requires explicit schemas.
74
- */
75
- export function module(options: {
76
- id?: string;
77
- inputSchema: TSchema;
78
- outputSchema: TSchema;
79
- description?: string;
80
- documentation?: string | null;
81
- annotations?: ModuleAnnotations | null;
82
- tags?: string[] | null;
83
- version?: string;
84
- metadata?: Record<string, unknown> | null;
85
- examples?: ModuleExample[] | null;
86
- execute: (inputs: Record<string, unknown>, context: Context) => Promise<Record<string, unknown>> | Record<string, unknown>;
87
- registry?: { register(moduleId: string, module: unknown): void } | null;
88
- }): FunctionModule {
89
- const moduleId = options.id ?? makeAutoId('anonymous');
90
-
91
- const fm = new FunctionModule({
92
- execute: options.execute,
93
- moduleId,
94
- inputSchema: options.inputSchema,
95
- outputSchema: options.outputSchema,
96
- description: options.description,
97
- documentation: options.documentation,
98
- tags: options.tags,
99
- version: options.version,
100
- annotations: options.annotations,
101
- metadata: options.metadata,
102
- examples: options.examples,
103
- });
104
-
105
- if (options.registry) {
106
- options.registry.register(fm.moduleId, fm);
107
- }
108
-
109
- return fm;
110
- }