apcore-js 0.5.0 → 0.6.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.
- package/dist/acl.d.ts +27 -0
- package/dist/acl.d.ts.map +1 -0
- package/dist/acl.js +175 -0
- package/dist/acl.js.map +1 -0
- package/dist/async-task.d.ts +90 -0
- package/dist/async-task.d.ts.map +1 -0
- package/dist/async-task.js +215 -0
- package/dist/async-task.js.map +1 -0
- package/dist/bindings.d.ts +12 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +185 -0
- package/dist/bindings.js.map +1 -0
- package/dist/cancel.d.ts +14 -0
- package/dist/cancel.d.ts.map +1 -0
- package/dist/cancel.js +27 -0
- package/dist/cancel.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +87 -0
- package/dist/context.js.map +1 -0
- package/dist/decorator.d.ts +57 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +74 -0
- package/dist/decorator.js.map +1 -0
- package/dist/errors.d.ts +215 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +246 -0
- package/dist/errors.js.map +1 -0
- package/dist/executor.d.ts +67 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +372 -0
- package/dist/executor.js.map +1 -0
- package/dist/extensions.d.ts +58 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +220 -0
- package/dist/extensions.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +3 -62
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/adapters.d.ts +18 -0
- package/dist/middleware/adapters.d.ts.map +1 -0
- package/dist/middleware/adapters.js +25 -0
- package/dist/middleware/adapters.js.map +1 -0
- package/dist/middleware/base.d.ts +10 -0
- package/dist/middleware/base.d.ts.map +1 -0
- package/dist/middleware/base.js +15 -0
- package/dist/middleware/base.js.map +1 -0
- package/{src/middleware/index.ts → dist/middleware/index.d.ts} +1 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/logging.d.ts +25 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +64 -0
- package/dist/middleware/logging.js.map +1 -0
- package/dist/middleware/manager.d.ts +21 -0
- package/dist/middleware/manager.d.ts.map +1 -0
- package/dist/middleware/manager.js +77 -0
- package/dist/middleware/manager.js.map +1 -0
- package/dist/module.d.ts +31 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +12 -0
- package/dist/module.js.map +1 -0
- package/dist/observability/context-logger.d.ts +54 -0
- package/dist/observability/context-logger.d.ts.map +1 -0
- package/dist/observability/context-logger.js +151 -0
- package/dist/observability/context-logger.js.map +1 -0
- package/{src/observability/index.ts → dist/observability/index.d.ts} +1 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +4 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/metrics.d.ts +30 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +177 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/tracing.d.ts +62 -0
- package/dist/observability/tracing.d.ts.map +1 -0
- package/dist/observability/tracing.js +184 -0
- package/dist/observability/tracing.js.map +1 -0
- package/dist/registry/dependencies.d.ts +6 -0
- package/dist/registry/dependencies.d.ts.map +1 -0
- package/dist/registry/dependencies.js +83 -0
- package/dist/registry/dependencies.js.map +1 -0
- package/dist/registry/entry-point.d.ts +6 -0
- package/dist/registry/entry-point.d.ts.map +1 -0
- package/dist/registry/entry-point.js +55 -0
- package/dist/registry/entry-point.js.map +1 -0
- package/{src/registry/index.ts → dist/registry/index.d.ts} +1 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/metadata.d.ts +9 -0
- package/dist/registry/metadata.d.ts.map +1 -0
- package/dist/registry/metadata.js +105 -0
- package/dist/registry/metadata.js.map +1 -0
- package/dist/registry/registry.d.ts +102 -0
- package/dist/registry/registry.d.ts.map +1 -0
- package/dist/registry/registry.js +534 -0
- package/dist/registry/registry.js.map +1 -0
- package/dist/registry/scanner.d.ts +7 -0
- package/dist/registry/scanner.d.ts.map +1 -0
- package/dist/registry/scanner.js +164 -0
- package/dist/registry/scanner.js.map +1 -0
- package/dist/registry/schema-export.d.ts +9 -0
- package/dist/registry/schema-export.d.ts.map +1 -0
- package/dist/registry/schema-export.js +132 -0
- package/dist/registry/schema-export.js.map +1 -0
- package/dist/registry/types.d.ts +29 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +5 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/registry/validation.d.ts +9 -0
- package/dist/registry/validation.d.ts.map +1 -0
- package/dist/registry/validation.js +33 -0
- package/dist/registry/validation.js.map +1 -0
- package/dist/schema/annotations.d.ts +8 -0
- package/dist/schema/annotations.d.ts.map +1 -0
- package/dist/schema/annotations.js +52 -0
- package/dist/schema/annotations.js.map +1 -0
- package/dist/schema/exporter.d.ts +13 -0
- package/dist/schema/exporter.d.ts.map +1 -0
- package/dist/schema/exporter.js +71 -0
- package/dist/schema/exporter.js.map +1 -0
- package/dist/schema/index.d.ts +9 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/{src/schema/index.ts → dist/schema/index.js} +1 -7
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/loader.d.ts +30 -0
- package/dist/schema/loader.d.ts.map +1 -0
- package/dist/schema/loader.js +260 -0
- package/dist/schema/loader.js.map +1 -0
- package/dist/schema/ref-resolver.d.ts +19 -0
- package/dist/schema/ref-resolver.d.ts.map +1 -0
- package/dist/schema/ref-resolver.js +212 -0
- package/dist/schema/ref-resolver.js.map +1 -0
- package/dist/schema/strict.d.ts +7 -0
- package/dist/schema/strict.d.ts.map +1 -0
- package/dist/schema/strict.js +127 -0
- package/dist/schema/strict.js.map +1 -0
- package/dist/schema/types.d.ts +53 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +31 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/schema/validator.d.ts +16 -0
- package/dist/schema/validator.d.ts.map +1 -0
- package/dist/schema/validator.js +71 -0
- package/dist/schema/validator.js.map +1 -0
- package/dist/trace-context.d.ts +35 -0
- package/dist/trace-context.d.ts.map +1 -0
- package/dist/trace-context.js +86 -0
- package/dist/trace-context.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +32 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pattern.d.ts +5 -0
- package/dist/utils/pattern.d.ts.map +1 -0
- package/dist/utils/pattern.js +31 -0
- package/dist/utils/pattern.js.map +1 -0
- package/package.json +8 -2
- package/.claude/settings.local.json +0 -12
- package/.github/workflows/ci.yml +0 -39
- package/.gitmessage +0 -60
- package/.pre-commit-config.yaml +0 -28
- package/CHANGELOG.md +0 -214
- package/CLAUDE.md +0 -68
- package/apcore-logo.svg +0 -79
- package/planning/acl-system/overview.md +0 -54
- package/planning/acl-system/plan.md +0 -92
- package/planning/acl-system/state.json +0 -76
- package/planning/acl-system/tasks/acl-core.md +0 -226
- package/planning/acl-system/tasks/acl-rule.md +0 -92
- package/planning/acl-system/tasks/conditional-rules.md +0 -259
- package/planning/acl-system/tasks/pattern-matching.md +0 -152
- package/planning/acl-system/tasks/yaml-loading.md +0 -271
- package/planning/core-executor/overview.md +0 -53
- package/planning/core-executor/plan.md +0 -88
- package/planning/core-executor/state.json +0 -76
- package/planning/core-executor/tasks/async-support.md +0 -106
- package/planning/core-executor/tasks/execution-pipeline.md +0 -113
- package/planning/core-executor/tasks/redaction.md +0 -85
- package/planning/core-executor/tasks/safety-checks.md +0 -65
- package/planning/core-executor/tasks/setup.md +0 -75
- package/planning/decorator-bindings/overview.md +0 -62
- package/planning/decorator-bindings/plan.md +0 -104
- package/planning/decorator-bindings/state.json +0 -87
- package/planning/decorator-bindings/tasks/binding-directory.md +0 -79
- package/planning/decorator-bindings/tasks/binding-loader.md +0 -148
- package/planning/decorator-bindings/tasks/explicit-schemas.md +0 -85
- package/planning/decorator-bindings/tasks/function-module.md +0 -127
- package/planning/decorator-bindings/tasks/module-factory.md +0 -89
- package/planning/decorator-bindings/tasks/schema-modes.md +0 -142
- package/planning/middleware-system/overview.md +0 -48
- package/planning/middleware-system/plan.md +0 -102
- package/planning/middleware-system/state.json +0 -65
- package/planning/middleware-system/tasks/adapters.md +0 -170
- package/planning/middleware-system/tasks/base.md +0 -115
- package/planning/middleware-system/tasks/logging-middleware.md +0 -304
- package/planning/middleware-system/tasks/manager.md +0 -313
- package/planning/observability/overview.md +0 -53
- package/planning/observability/plan.md +0 -119
- package/planning/observability/state.json +0 -98
- package/planning/observability/tasks/context-logger.md +0 -201
- package/planning/observability/tasks/exporters.md +0 -121
- package/planning/observability/tasks/metrics-collector.md +0 -162
- package/planning/observability/tasks/metrics-middleware.md +0 -141
- package/planning/observability/tasks/obs-logging-middleware.md +0 -179
- package/planning/observability/tasks/span-model.md +0 -120
- package/planning/observability/tasks/tracing-middleware.md +0 -179
- package/planning/overview.md +0 -81
- package/planning/registry-system/overview.md +0 -57
- package/planning/registry-system/plan.md +0 -114
- package/planning/registry-system/state.json +0 -109
- package/planning/registry-system/tasks/dependencies.md +0 -157
- package/planning/registry-system/tasks/entry-point.md +0 -148
- package/planning/registry-system/tasks/metadata.md +0 -198
- package/planning/registry-system/tasks/registry-core.md +0 -323
- package/planning/registry-system/tasks/scanner.md +0 -172
- package/planning/registry-system/tasks/schema-export.md +0 -261
- package/planning/registry-system/tasks/types.md +0 -124
- package/planning/registry-system/tasks/validation.md +0 -177
- package/planning/schema-system/overview.md +0 -56
- package/planning/schema-system/plan.md +0 -121
- package/planning/schema-system/state.json +0 -98
- package/planning/schema-system/tasks/exporter.md +0 -153
- package/planning/schema-system/tasks/loader.md +0 -106
- package/planning/schema-system/tasks/ref-resolver.md +0 -133
- package/planning/schema-system/tasks/strict-mode.md +0 -140
- package/planning/schema-system/tasks/typebox-generation.md +0 -133
- package/planning/schema-system/tasks/types-and-annotations.md +0 -160
- package/planning/schema-system/tasks/validator.md +0 -149
- package/src/acl.ts +0 -200
- package/src/async-task.ts +0 -267
- package/src/bindings.ts +0 -207
- package/src/cancel.ts +0 -32
- package/src/config.ts +0 -24
- package/src/context.ts +0 -160
- package/src/decorator.ts +0 -110
- package/src/errors.ts +0 -429
- package/src/executor.ts +0 -493
- package/src/extensions.ts +0 -265
- package/src/middleware/adapters.ts +0 -54
- package/src/middleware/base.ts +0 -33
- package/src/middleware/logging.ts +0 -103
- package/src/middleware/manager.ts +0 -105
- package/src/module.ts +0 -43
- package/src/observability/context-logger.ts +0 -203
- package/src/observability/metrics.ts +0 -214
- package/src/observability/tracing.ts +0 -252
- package/src/registry/dependencies.ts +0 -99
- package/src/registry/entry-point.ts +0 -64
- package/src/registry/metadata.ts +0 -111
- package/src/registry/registry.ts +0 -580
- package/src/registry/scanner.ts +0 -168
- package/src/registry/schema-export.ts +0 -181
- package/src/registry/types.ts +0 -32
- package/src/registry/validation.ts +0 -38
- package/src/schema/annotations.ts +0 -68
- package/src/schema/exporter.ts +0 -90
- package/src/schema/loader.ts +0 -273
- package/src/schema/ref-resolver.ts +0 -244
- package/src/schema/strict.ts +0 -136
- package/src/schema/types.ts +0 -73
- package/src/schema/validator.ts +0 -82
- package/src/trace-context.ts +0 -102
- package/src/utils/index.ts +0 -5
- package/src/utils/pattern.ts +0 -30
- package/tests/async-task.test.ts +0 -335
- package/tests/helpers.ts +0 -30
- package/tests/integration/test-acl-safety.test.ts +0 -269
- package/tests/integration/test-binding-executor.test.ts +0 -194
- package/tests/integration/test-e2e-flow.test.ts +0 -117
- package/tests/integration/test-error-propagation.test.ts +0 -259
- package/tests/integration/test-middleware-chain.test.ts +0 -120
- package/tests/integration/test-observability-integration.test.ts +0 -438
- package/tests/observability/test-context-logger.test.ts +0 -123
- package/tests/observability/test-metrics.test.ts +0 -186
- package/tests/observability/test-tracing.test.ts +0 -303
- package/tests/registry/test-dependencies.test.ts +0 -70
- package/tests/registry/test-entry-point.test.ts +0 -133
- package/tests/registry/test-metadata.test.ts +0 -265
- package/tests/registry/test-registry.test.ts +0 -1397
- package/tests/registry/test-scanner.test.ts +0 -257
- package/tests/registry/test-schema-export.test.ts +0 -355
- package/tests/registry/test-validation.test.ts +0 -75
- package/tests/schema/test-annotations.test.ts +0 -137
- package/tests/schema/test-exporter.test.ts +0 -172
- package/tests/schema/test-loader.test.ts +0 -461
- package/tests/schema/test-ref-resolver.test.ts +0 -530
- package/tests/schema/test-strict.test.ts +0 -348
- package/tests/schema/test-validator.test.ts +0 -64
- package/tests/test-acl.test.ts +0 -423
- package/tests/test-bindings.test.ts +0 -227
- package/tests/test-cancel.test.ts +0 -71
- package/tests/test-config.test.ts +0 -76
- package/tests/test-context.test.ts +0 -266
- package/tests/test-decorator.test.ts +0 -173
- package/tests/test-errors.test.ts +0 -647
- package/tests/test-executor-stream.test.ts +0 -208
- package/tests/test-executor.test.ts +0 -252
- package/tests/test-extensions.test.ts +0 -310
- package/tests/test-logging-middleware.test.ts +0 -150
- package/tests/test-middleware-manager.test.ts +0 -185
- package/tests/test-middleware.test.ts +0 -86
- package/tests/test-trace-context.test.ts +0 -251
- package/tests/utils/test-pattern.test.ts +0 -109
- package/tsconfig.build.json +0 -8
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -18
package/src/extensions.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extension point framework for apcore.
|
|
3
|
-
*
|
|
4
|
-
* Provides a centralized mechanism to register, query, and wire custom
|
|
5
|
-
* extensions (discoverers, middleware, ACL providers, span exporters, and
|
|
6
|
-
* module validators) into the apcore runtime.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { ACL } from './acl.js';
|
|
10
|
-
import type { Executor } from './executor.js';
|
|
11
|
-
import { Middleware } from './middleware/index.js';
|
|
12
|
-
import { TracingMiddleware } from './observability/tracing.js';
|
|
13
|
-
import type { Span, SpanExporter } from './observability/tracing.js';
|
|
14
|
-
import type { Discoverer, ModuleValidator, Registry } from './registry/registry.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Delegates span export to multiple underlying exporters.
|
|
18
|
-
*/
|
|
19
|
-
class CompositeExporter implements SpanExporter {
|
|
20
|
-
private _exporters: SpanExporter[];
|
|
21
|
-
|
|
22
|
-
constructor(exporters: SpanExporter[]) {
|
|
23
|
-
this._exporters = exporters;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export(span: Span): void {
|
|
27
|
-
for (const exp of this._exporters) {
|
|
28
|
-
try {
|
|
29
|
-
exp.export(span);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
console.warn('[apcore:extensions] Span exporter failed:', e);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Describes a named slot where extensions can be registered.
|
|
39
|
-
*/
|
|
40
|
-
export interface ExtensionPoint {
|
|
41
|
-
readonly name: string;
|
|
42
|
-
readonly description: string;
|
|
43
|
-
readonly multiple: boolean;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Type guard: checks if value has a `discover` method. */
|
|
47
|
-
function isDiscoverer(value: unknown): value is Discoverer {
|
|
48
|
-
return typeof value === 'object' && value !== null && typeof (value as Record<string, unknown>)['discover'] === 'function';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Type guard: checks if value has a `validate` method. */
|
|
52
|
-
function isModuleValidator(value: unknown): value is ModuleValidator {
|
|
53
|
-
return typeof value === 'object' && value !== null && typeof (value as Record<string, unknown>)['validate'] === 'function';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Type guard: checks if value has at least one middleware method (before, after, onError). */
|
|
57
|
-
function isMiddleware(value: unknown): value is Middleware {
|
|
58
|
-
if (typeof value !== 'object' || value === null) return false;
|
|
59
|
-
const obj = value as Record<string, unknown>;
|
|
60
|
-
return typeof obj['before'] === 'function' || typeof obj['after'] === 'function' || typeof obj['onError'] === 'function';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Type guard: checks if value has a `check` method (ACL). */
|
|
64
|
-
function isACL(value: unknown): value is ACL {
|
|
65
|
-
return typeof value === 'object' && value !== null && typeof (value as Record<string, unknown>)['check'] === 'function';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Type guard: checks if value has an `export` method (SpanExporter). */
|
|
69
|
-
function isSpanExporter(value: unknown): value is SpanExporter {
|
|
70
|
-
return typeof value === 'object' && value !== null && typeof (value as Record<string, unknown>)['export'] === 'function';
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type TypeChecker = (value: unknown) => boolean;
|
|
74
|
-
|
|
75
|
-
interface InternalExtensionPoint extends ExtensionPoint {
|
|
76
|
-
readonly typeCheck: TypeChecker;
|
|
77
|
-
readonly typeName: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function builtInPoints(): Map<string, InternalExtensionPoint> {
|
|
81
|
-
return new Map<string, InternalExtensionPoint>([
|
|
82
|
-
['discoverer', {
|
|
83
|
-
name: 'discoverer',
|
|
84
|
-
description: 'Custom module discovery strategy',
|
|
85
|
-
multiple: false,
|
|
86
|
-
typeCheck: isDiscoverer,
|
|
87
|
-
typeName: 'Discoverer',
|
|
88
|
-
}],
|
|
89
|
-
['middleware', {
|
|
90
|
-
name: 'middleware',
|
|
91
|
-
description: 'Execution middleware',
|
|
92
|
-
multiple: true,
|
|
93
|
-
typeCheck: isMiddleware,
|
|
94
|
-
typeName: 'Middleware',
|
|
95
|
-
}],
|
|
96
|
-
['acl', {
|
|
97
|
-
name: 'acl',
|
|
98
|
-
description: 'Access control provider',
|
|
99
|
-
multiple: false,
|
|
100
|
-
typeCheck: isACL,
|
|
101
|
-
typeName: 'ACL',
|
|
102
|
-
}],
|
|
103
|
-
['span_exporter', {
|
|
104
|
-
name: 'span_exporter',
|
|
105
|
-
description: 'Tracing span exporter',
|
|
106
|
-
multiple: true,
|
|
107
|
-
typeCheck: isSpanExporter,
|
|
108
|
-
typeName: 'SpanExporter',
|
|
109
|
-
}],
|
|
110
|
-
['module_validator', {
|
|
111
|
-
name: 'module_validator',
|
|
112
|
-
description: 'Custom module validation',
|
|
113
|
-
multiple: false,
|
|
114
|
-
typeCheck: isModuleValidator,
|
|
115
|
-
typeName: 'ModuleValidator',
|
|
116
|
-
}],
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Manages extension points and their registered implementations.
|
|
122
|
-
*
|
|
123
|
-
* Pre-registers five built-in extension points: discoverer, middleware,
|
|
124
|
-
* acl, span_exporter, and module_validator.
|
|
125
|
-
*/
|
|
126
|
-
export class ExtensionManager {
|
|
127
|
-
private _points: Map<string, InternalExtensionPoint>;
|
|
128
|
-
private _extensions: Map<string, unknown[]>;
|
|
129
|
-
|
|
130
|
-
constructor() {
|
|
131
|
-
this._points = builtInPoints();
|
|
132
|
-
this._extensions = new Map<string, unknown[]>();
|
|
133
|
-
for (const name of this._points.keys()) {
|
|
134
|
-
this._extensions.set(name, []);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Register an extension for the given extension point.
|
|
140
|
-
*
|
|
141
|
-
* @throws Error if point_name is unknown.
|
|
142
|
-
* @throws Error if extension does not satisfy the type constraint.
|
|
143
|
-
*/
|
|
144
|
-
register(pointName: string, extension: unknown): void {
|
|
145
|
-
const point = this._points.get(pointName);
|
|
146
|
-
if (point === undefined) {
|
|
147
|
-
throw new Error(
|
|
148
|
-
`Unknown extension point: '${pointName}'. Available: ${[...this._points.keys()].sort().join(', ')}`,
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!point.typeCheck(extension)) {
|
|
153
|
-
throw new TypeError(
|
|
154
|
-
`Extension for '${pointName}' must satisfy the ${point.typeName} interface`,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (point.multiple) {
|
|
159
|
-
this._extensions.get(pointName)!.push(extension);
|
|
160
|
-
} else {
|
|
161
|
-
this._extensions.set(pointName, [extension]);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Return the single extension for a non-multiple point, or null.
|
|
167
|
-
*/
|
|
168
|
-
get(pointName: string): unknown | null {
|
|
169
|
-
if (!this._points.has(pointName)) {
|
|
170
|
-
throw new Error(`Unknown extension point: '${pointName}'`);
|
|
171
|
-
}
|
|
172
|
-
const exts = this._extensions.get(pointName)!;
|
|
173
|
-
return exts.length > 0 ? exts[0] : null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Return all extensions for a multiple-type point.
|
|
178
|
-
*/
|
|
179
|
-
getAll(pointName: string): unknown[] {
|
|
180
|
-
if (!this._points.has(pointName)) {
|
|
181
|
-
throw new Error(`Unknown extension point: '${pointName}'`);
|
|
182
|
-
}
|
|
183
|
-
return [...this._extensions.get(pointName)!];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Remove a specific extension from an extension point.
|
|
188
|
-
* Returns true if found and removed, false otherwise.
|
|
189
|
-
*/
|
|
190
|
-
unregister(pointName: string, extension: unknown): boolean {
|
|
191
|
-
if (!this._points.has(pointName)) {
|
|
192
|
-
throw new Error(`Unknown extension point: '${pointName}'`);
|
|
193
|
-
}
|
|
194
|
-
const exts = this._extensions.get(pointName)!;
|
|
195
|
-
const idx = exts.indexOf(extension);
|
|
196
|
-
if (idx === -1) return false;
|
|
197
|
-
exts.splice(idx, 1);
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Return all registered extension points.
|
|
203
|
-
*/
|
|
204
|
-
listPoints(): ExtensionPoint[] {
|
|
205
|
-
return [...this._points.values()].map(({ name, description, multiple }) => ({
|
|
206
|
-
name,
|
|
207
|
-
description,
|
|
208
|
-
multiple,
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Wire all registered extensions into the given registry and executor.
|
|
214
|
-
*/
|
|
215
|
-
apply(registry: Registry, executor: Executor): void {
|
|
216
|
-
// Discoverer
|
|
217
|
-
const discoverer = this.get('discoverer') as Discoverer | null;
|
|
218
|
-
if (discoverer !== null) {
|
|
219
|
-
registry.setDiscoverer(discoverer);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// Module validator
|
|
223
|
-
const validator = this.get('module_validator') as ModuleValidator | null;
|
|
224
|
-
if (validator !== null) {
|
|
225
|
-
registry.setValidator(validator);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// ACL
|
|
229
|
-
const acl = this.get('acl') as ACL | null;
|
|
230
|
-
if (acl !== null) {
|
|
231
|
-
executor.setAcl(acl);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Middleware
|
|
235
|
-
for (const mw of this.getAll('middleware')) {
|
|
236
|
-
executor.use(mw as Middleware);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Span exporters: find existing TracingMiddleware and set exporter(s)
|
|
240
|
-
const exporters = this.getAll('span_exporter') as SpanExporter[];
|
|
241
|
-
if (exporters.length > 0) {
|
|
242
|
-
const tracingMw = this._findTracingMiddleware(executor);
|
|
243
|
-
if (tracingMw !== null) {
|
|
244
|
-
if (exporters.length === 1) {
|
|
245
|
-
tracingMw.setExporter(exporters[0]);
|
|
246
|
-
} else {
|
|
247
|
-
tracingMw.setExporter(new CompositeExporter(exporters));
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
console.warn(
|
|
251
|
-
'[apcore:extensions] span_exporter extensions registered but no TracingMiddleware found in executor middleware chain',
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private _findTracingMiddleware(executor: Executor): TracingMiddleware | null {
|
|
258
|
-
for (const mw of executor.middlewares) {
|
|
259
|
-
if (mw instanceof TracingMiddleware) {
|
|
260
|
-
return mw;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Function adapter classes for the middleware system.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Context } from '../context.js';
|
|
6
|
-
import { Middleware } from './base.js';
|
|
7
|
-
|
|
8
|
-
export type BeforeCallback = (
|
|
9
|
-
moduleId: string,
|
|
10
|
-
inputs: Record<string, unknown>,
|
|
11
|
-
context: Context,
|
|
12
|
-
) => Record<string, unknown> | null;
|
|
13
|
-
|
|
14
|
-
export type AfterCallback = (
|
|
15
|
-
moduleId: string,
|
|
16
|
-
inputs: Record<string, unknown>,
|
|
17
|
-
output: Record<string, unknown>,
|
|
18
|
-
context: Context,
|
|
19
|
-
) => Record<string, unknown> | null;
|
|
20
|
-
|
|
21
|
-
export class BeforeMiddleware extends Middleware {
|
|
22
|
-
private _callback: BeforeCallback;
|
|
23
|
-
|
|
24
|
-
constructor(callback: BeforeCallback) {
|
|
25
|
-
super();
|
|
26
|
-
this._callback = callback;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override before(
|
|
30
|
-
moduleId: string,
|
|
31
|
-
inputs: Record<string, unknown>,
|
|
32
|
-
context: Context,
|
|
33
|
-
): Record<string, unknown> | null {
|
|
34
|
-
return this._callback(moduleId, inputs, context);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class AfterMiddleware extends Middleware {
|
|
39
|
-
private _callback: AfterCallback;
|
|
40
|
-
|
|
41
|
-
constructor(callback: AfterCallback) {
|
|
42
|
-
super();
|
|
43
|
-
this._callback = callback;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override after(
|
|
47
|
-
moduleId: string,
|
|
48
|
-
inputs: Record<string, unknown>,
|
|
49
|
-
output: Record<string, unknown>,
|
|
50
|
-
context: Context,
|
|
51
|
-
): Record<string, unknown> | null {
|
|
52
|
-
return this._callback(moduleId, inputs, output, context);
|
|
53
|
-
}
|
|
54
|
-
}
|
package/src/middleware/base.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Middleware base class for apcore.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Context } from '../context.js';
|
|
6
|
-
|
|
7
|
-
export class Middleware {
|
|
8
|
-
before(
|
|
9
|
-
_moduleId: string,
|
|
10
|
-
_inputs: Record<string, unknown>,
|
|
11
|
-
_context: Context,
|
|
12
|
-
): Record<string, unknown> | null {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
after(
|
|
17
|
-
_moduleId: string,
|
|
18
|
-
_inputs: Record<string, unknown>,
|
|
19
|
-
_output: Record<string, unknown>,
|
|
20
|
-
_context: Context,
|
|
21
|
-
): Record<string, unknown> | null {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
onError(
|
|
26
|
-
_moduleId: string,
|
|
27
|
-
_inputs: Record<string, unknown>,
|
|
28
|
-
_error: Error,
|
|
29
|
-
_context: Context,
|
|
30
|
-
): Record<string, unknown> | null {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LoggingMiddleware for structured module call logging.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Context } from '../context.js';
|
|
6
|
-
import { Middleware } from './base.js';
|
|
7
|
-
|
|
8
|
-
export interface Logger {
|
|
9
|
-
info(message: string, extra?: Record<string, unknown>): void;
|
|
10
|
-
error(message: string, extra?: Record<string, unknown>): void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const defaultLogger: Logger = {
|
|
14
|
-
info(message: string, extra?: Record<string, unknown>) {
|
|
15
|
-
console.info(message, extra ?? '');
|
|
16
|
-
},
|
|
17
|
-
error(message: string, extra?: Record<string, unknown>) {
|
|
18
|
-
console.error(message, extra ?? '');
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export class LoggingMiddleware extends Middleware {
|
|
23
|
-
private _logger: Logger;
|
|
24
|
-
private _logInputs: boolean;
|
|
25
|
-
private _logOutputs: boolean;
|
|
26
|
-
private _logErrors: boolean;
|
|
27
|
-
|
|
28
|
-
constructor(options?: {
|
|
29
|
-
logger?: Logger;
|
|
30
|
-
logInputs?: boolean;
|
|
31
|
-
logOutputs?: boolean;
|
|
32
|
-
logErrors?: boolean;
|
|
33
|
-
}) {
|
|
34
|
-
super();
|
|
35
|
-
this._logger = options?.logger ?? defaultLogger;
|
|
36
|
-
this._logInputs = options?.logInputs ?? true;
|
|
37
|
-
this._logOutputs = options?.logOutputs ?? true;
|
|
38
|
-
this._logErrors = options?.logErrors ?? true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
override before(
|
|
42
|
-
moduleId: string,
|
|
43
|
-
inputs: Record<string, unknown>,
|
|
44
|
-
context: Context,
|
|
45
|
-
): null {
|
|
46
|
-
context.data['_logging_mw_start'] = performance.now();
|
|
47
|
-
|
|
48
|
-
if (this._logInputs) {
|
|
49
|
-
const redacted = context.redactedInputs ?? inputs;
|
|
50
|
-
this._logger.info(`[${context.traceId}] START ${moduleId}`, {
|
|
51
|
-
traceId: context.traceId,
|
|
52
|
-
moduleId,
|
|
53
|
-
callerId: context.callerId,
|
|
54
|
-
inputs: redacted,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
override after(
|
|
62
|
-
moduleId: string,
|
|
63
|
-
_inputs: Record<string, unknown>,
|
|
64
|
-
output: Record<string, unknown>,
|
|
65
|
-
context: Context,
|
|
66
|
-
): null {
|
|
67
|
-
const startTime = (context.data['_logging_mw_start'] as number) ?? performance.now();
|
|
68
|
-
const durationMs = performance.now() - startTime;
|
|
69
|
-
|
|
70
|
-
if (this._logOutputs) {
|
|
71
|
-
this._logger.info(
|
|
72
|
-
`[${context.traceId}] END ${moduleId} (${durationMs.toFixed(2)}ms)`,
|
|
73
|
-
{
|
|
74
|
-
traceId: context.traceId,
|
|
75
|
-
moduleId,
|
|
76
|
-
durationMs,
|
|
77
|
-
output,
|
|
78
|
-
},
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
override onError(
|
|
86
|
-
moduleId: string,
|
|
87
|
-
inputs: Record<string, unknown>,
|
|
88
|
-
error: Error,
|
|
89
|
-
context: Context,
|
|
90
|
-
): null {
|
|
91
|
-
if (this._logErrors) {
|
|
92
|
-
const redacted = context.redactedInputs ?? inputs;
|
|
93
|
-
this._logger.error(`[${context.traceId}] ERROR ${moduleId}: ${error}`, {
|
|
94
|
-
traceId: context.traceId,
|
|
95
|
-
moduleId,
|
|
96
|
-
error: String(error),
|
|
97
|
-
inputs: redacted,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MiddlewareManager -- onion model execution engine for the middleware pipeline.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { Context } from '../context.js';
|
|
6
|
-
import { ModuleError } from '../errors.js';
|
|
7
|
-
import { Middleware } from './base.js';
|
|
8
|
-
|
|
9
|
-
export class MiddlewareChainError extends ModuleError {
|
|
10
|
-
readonly original: Error;
|
|
11
|
-
readonly executedMiddlewares: Middleware[];
|
|
12
|
-
|
|
13
|
-
constructor(original: Error, executedMiddlewares: Middleware[]) {
|
|
14
|
-
super('MIDDLEWARE_CHAIN_ERROR', String(original), undefined, original);
|
|
15
|
-
this.name = 'MiddlewareChainError';
|
|
16
|
-
this.original = original;
|
|
17
|
-
this.executedMiddlewares = executedMiddlewares;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class MiddlewareManager {
|
|
22
|
-
private _middlewares: Middleware[] = [];
|
|
23
|
-
|
|
24
|
-
add(middleware: Middleware): void {
|
|
25
|
-
this._middlewares.push(middleware);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
remove(middleware: Middleware): boolean {
|
|
29
|
-
for (let i = 0; i < this._middlewares.length; i++) {
|
|
30
|
-
if (this._middlewares[i] === middleware) {
|
|
31
|
-
this._middlewares.splice(i, 1);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
snapshot(): Middleware[] {
|
|
39
|
-
return [...this._middlewares];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
executeBefore(
|
|
43
|
-
moduleId: string,
|
|
44
|
-
inputs: Record<string, unknown>,
|
|
45
|
-
context: Context,
|
|
46
|
-
): [Record<string, unknown>, Middleware[]] {
|
|
47
|
-
let currentInputs = inputs;
|
|
48
|
-
const executedMiddlewares: Middleware[] = [];
|
|
49
|
-
const middlewares = this.snapshot();
|
|
50
|
-
|
|
51
|
-
for (const mw of middlewares) {
|
|
52
|
-
executedMiddlewares.push(mw);
|
|
53
|
-
try {
|
|
54
|
-
const result = mw.before(moduleId, currentInputs, context);
|
|
55
|
-
if (result !== null) {
|
|
56
|
-
currentInputs = result;
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
throw new MiddlewareChainError(e as Error, executedMiddlewares);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return [currentInputs, executedMiddlewares];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
executeAfter(
|
|
67
|
-
moduleId: string,
|
|
68
|
-
inputs: Record<string, unknown>,
|
|
69
|
-
output: Record<string, unknown>,
|
|
70
|
-
context: Context,
|
|
71
|
-
): Record<string, unknown> {
|
|
72
|
-
let currentOutput = output;
|
|
73
|
-
const middlewares = this.snapshot();
|
|
74
|
-
|
|
75
|
-
for (let i = middlewares.length - 1; i >= 0; i--) {
|
|
76
|
-
const result = middlewares[i].after(moduleId, inputs, currentOutput, context);
|
|
77
|
-
if (result !== null) {
|
|
78
|
-
currentOutput = result;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return currentOutput;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
executeOnError(
|
|
86
|
-
moduleId: string,
|
|
87
|
-
inputs: Record<string, unknown>,
|
|
88
|
-
error: Error,
|
|
89
|
-
context: Context,
|
|
90
|
-
executedMiddlewares: Middleware[],
|
|
91
|
-
): Record<string, unknown> | null {
|
|
92
|
-
for (let i = executedMiddlewares.length - 1; i >= 0; i--) {
|
|
93
|
-
try {
|
|
94
|
-
const result = executedMiddlewares[i].onError(moduleId, inputs, error, context);
|
|
95
|
-
if (result !== null) {
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
|
-
} catch (e) {
|
|
99
|
-
console.warn('[apcore:middleware] Error in onError handler, continuing:', e);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
}
|
package/src/module.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Module interface and related data types.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { TSchema } from '@sinclair/typebox';
|
|
6
|
-
import type { Context } from './context.js';
|
|
7
|
-
|
|
8
|
-
export interface ModuleAnnotations {
|
|
9
|
-
readonly readonly: boolean;
|
|
10
|
-
readonly destructive: boolean;
|
|
11
|
-
readonly idempotent: boolean;
|
|
12
|
-
readonly requiresApproval: boolean;
|
|
13
|
-
readonly openWorld: boolean;
|
|
14
|
-
readonly streaming: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const DEFAULT_ANNOTATIONS: ModuleAnnotations = Object.freeze({
|
|
18
|
-
readonly: false,
|
|
19
|
-
destructive: false,
|
|
20
|
-
idempotent: false,
|
|
21
|
-
requiresApproval: false,
|
|
22
|
-
openWorld: true,
|
|
23
|
-
streaming: false,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export interface ModuleExample {
|
|
27
|
-
title: string;
|
|
28
|
-
inputs: Record<string, unknown>;
|
|
29
|
-
output: Record<string, unknown>;
|
|
30
|
-
description?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ValidationResult {
|
|
34
|
-
valid: boolean;
|
|
35
|
-
errors: Array<Record<string, string>>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface Module {
|
|
39
|
-
inputSchema: TSchema;
|
|
40
|
-
outputSchema: TSchema;
|
|
41
|
-
description: string;
|
|
42
|
-
execute(inputs: Record<string, unknown>, context: Context): Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
43
|
-
}
|