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.
- package/README.md +1 -1
- 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/approval.d.ts +85 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +73 -0
- package/dist/approval.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 +204 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +364 -0
- package/dist/errors.js.map +1 -0
- package/dist/executor.d.ts +82 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +489 -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 +239 -0
- package/dist/extensions.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +6 -63
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -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 +24 -3
- 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/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
|
-
}
|