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
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { toStrictSchema, applyLlmDescriptions, stripExtensions } from '../../src/schema/strict.js';
|
|
3
|
-
|
|
4
|
-
describe('toStrictSchema', () => {
|
|
5
|
-
it('adds additionalProperties: false', () => {
|
|
6
|
-
const schema = {
|
|
7
|
-
type: 'object',
|
|
8
|
-
properties: {
|
|
9
|
-
name: { type: 'string' },
|
|
10
|
-
},
|
|
11
|
-
required: ['name'],
|
|
12
|
-
};
|
|
13
|
-
const strict = toStrictSchema(schema);
|
|
14
|
-
expect(strict['additionalProperties']).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('makes all properties required', () => {
|
|
18
|
-
const schema = {
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
name: { type: 'string' },
|
|
22
|
-
age: { type: 'integer' },
|
|
23
|
-
},
|
|
24
|
-
required: ['name'],
|
|
25
|
-
};
|
|
26
|
-
const strict = toStrictSchema(schema);
|
|
27
|
-
expect(strict['required']).toEqual(['age', 'name']);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('makes optional properties nullable', () => {
|
|
31
|
-
const schema = {
|
|
32
|
-
type: 'object',
|
|
33
|
-
properties: {
|
|
34
|
-
name: { type: 'string' },
|
|
35
|
-
age: { type: 'integer' },
|
|
36
|
-
},
|
|
37
|
-
required: ['name'],
|
|
38
|
-
};
|
|
39
|
-
const strict = toStrictSchema(schema);
|
|
40
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
41
|
-
expect(props['age']['type']).toEqual(['integer', 'null']);
|
|
42
|
-
expect(props['name']['type']).toBe('string');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('does not modify original schema', () => {
|
|
46
|
-
const schema: Record<string, unknown> = {
|
|
47
|
-
type: 'object',
|
|
48
|
-
properties: { name: { type: 'string' } },
|
|
49
|
-
};
|
|
50
|
-
toStrictSchema(schema);
|
|
51
|
-
expect(schema['additionalProperties']).toBeUndefined();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('strips x- extensions', () => {
|
|
55
|
-
const schema = {
|
|
56
|
-
type: 'object',
|
|
57
|
-
'x-sensitive': true,
|
|
58
|
-
properties: {
|
|
59
|
-
name: { type: 'string', 'x-llm-description': 'Name field' },
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
const strict = toStrictSchema(schema);
|
|
63
|
-
expect(strict['x-sensitive']).toBeUndefined();
|
|
64
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
65
|
-
expect(props['name']['x-llm-description']).toBeUndefined();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('strips default values', () => {
|
|
69
|
-
const schema = {
|
|
70
|
-
type: 'object',
|
|
71
|
-
properties: {
|
|
72
|
-
name: { type: 'string', default: 'world' },
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
const strict = toStrictSchema(schema);
|
|
76
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
77
|
-
expect(props['name']['default']).toBeUndefined();
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('applyLlmDescriptions', () => {
|
|
82
|
-
it('replaces description with x-llm-description', () => {
|
|
83
|
-
const schema = {
|
|
84
|
-
description: 'Original',
|
|
85
|
-
'x-llm-description': 'LLM version',
|
|
86
|
-
properties: {
|
|
87
|
-
name: {
|
|
88
|
-
type: 'string',
|
|
89
|
-
description: 'Name',
|
|
90
|
-
'x-llm-description': 'User name for LLM',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
applyLlmDescriptions(schema);
|
|
95
|
-
expect(schema['description']).toBe('LLM version');
|
|
96
|
-
expect((schema['properties'] as Record<string, Record<string, unknown>>)['name']['description']).toBe('User name for LLM');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('does not modify without x-llm-description', () => {
|
|
100
|
-
const schema = { description: 'Original' };
|
|
101
|
-
applyLlmDescriptions(schema);
|
|
102
|
-
expect(schema['description']).toBe('Original');
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('toStrictSchema - definitions and combinators', () => {
|
|
107
|
-
it('recurses into definitions block', () => {
|
|
108
|
-
const schema = {
|
|
109
|
-
type: 'object',
|
|
110
|
-
properties: {
|
|
111
|
-
name: { type: 'string' },
|
|
112
|
-
},
|
|
113
|
-
required: ['name'],
|
|
114
|
-
definitions: {
|
|
115
|
-
Address: {
|
|
116
|
-
type: 'object',
|
|
117
|
-
properties: {
|
|
118
|
-
city: { type: 'string' },
|
|
119
|
-
zip: { type: 'string' },
|
|
120
|
-
},
|
|
121
|
-
required: ['city'],
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
const strict = toStrictSchema(schema);
|
|
126
|
-
const defs = strict['definitions'] as Record<string, Record<string, unknown>>;
|
|
127
|
-
expect(defs['Address']['additionalProperties']).toBe(false);
|
|
128
|
-
const addrProps = defs['Address']['properties'] as Record<string, Record<string, unknown>>;
|
|
129
|
-
expect(addrProps['zip']['type']).toEqual(['string', 'null']);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('recurses into $defs block', () => {
|
|
133
|
-
const schema = {
|
|
134
|
-
type: 'object',
|
|
135
|
-
properties: { x: { type: 'string' } },
|
|
136
|
-
$defs: {
|
|
137
|
-
Inner: {
|
|
138
|
-
type: 'object',
|
|
139
|
-
properties: {
|
|
140
|
-
a: { type: 'integer' },
|
|
141
|
-
b: { type: 'string' },
|
|
142
|
-
},
|
|
143
|
-
required: ['a'],
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
const strict = toStrictSchema(schema);
|
|
148
|
-
const defs = strict['$defs'] as Record<string, Record<string, unknown>>;
|
|
149
|
-
expect(defs['Inner']['additionalProperties']).toBe(false);
|
|
150
|
-
const innerProps = defs['Inner']['properties'] as Record<string, Record<string, unknown>>;
|
|
151
|
-
expect(innerProps['b']['type']).toEqual(['string', 'null']);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('recurses into oneOf/anyOf/allOf variants', () => {
|
|
155
|
-
const schema = {
|
|
156
|
-
type: 'object',
|
|
157
|
-
properties: {
|
|
158
|
-
value: {
|
|
159
|
-
oneOf: [
|
|
160
|
-
{
|
|
161
|
-
type: 'object',
|
|
162
|
-
properties: { a: { type: 'string' } },
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
const strict = toStrictSchema(schema);
|
|
169
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
170
|
-
const oneOf = props['value']['oneOf'] as Record<string, unknown>[];
|
|
171
|
-
expect(oneOf[0]['additionalProperties']).toBe(false);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('appends null to existing oneOf for optional property', () => {
|
|
175
|
-
const schema = {
|
|
176
|
-
type: 'object',
|
|
177
|
-
properties: {
|
|
178
|
-
value: {
|
|
179
|
-
oneOf: [
|
|
180
|
-
{ type: 'string' },
|
|
181
|
-
{ type: 'number' },
|
|
182
|
-
],
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
required: [],
|
|
186
|
-
};
|
|
187
|
-
const strict = toStrictSchema(schema);
|
|
188
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
189
|
-
const oneOf = props['value']['oneOf'] as Record<string, unknown>[];
|
|
190
|
-
expect(oneOf).toHaveLength(3);
|
|
191
|
-
expect(oneOf[2]).toEqual({ type: 'null' });
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('appends null to existing anyOf for optional property', () => {
|
|
195
|
-
const schema = {
|
|
196
|
-
type: 'object',
|
|
197
|
-
properties: {
|
|
198
|
-
value: {
|
|
199
|
-
anyOf: [
|
|
200
|
-
{ type: 'string' },
|
|
201
|
-
{ type: 'integer' },
|
|
202
|
-
],
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
required: [],
|
|
206
|
-
};
|
|
207
|
-
const strict = toStrictSchema(schema);
|
|
208
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
209
|
-
const anyOf = props['value']['anyOf'] as Record<string, unknown>[];
|
|
210
|
-
expect(anyOf).toHaveLength(3);
|
|
211
|
-
expect(anyOf[2]).toEqual({ type: 'null' });
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('does not double-add null to oneOf that already has null', () => {
|
|
215
|
-
const schema = {
|
|
216
|
-
type: 'object',
|
|
217
|
-
properties: {
|
|
218
|
-
value: {
|
|
219
|
-
oneOf: [
|
|
220
|
-
{ type: 'string' },
|
|
221
|
-
{ type: 'null' },
|
|
222
|
-
],
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
required: [],
|
|
226
|
-
};
|
|
227
|
-
const strict = toStrictSchema(schema);
|
|
228
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
229
|
-
const oneOf = props['value']['oneOf'] as Record<string, unknown>[];
|
|
230
|
-
expect(oneOf).toHaveLength(2);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('does not add null to already-nullable type array', () => {
|
|
234
|
-
const schema = {
|
|
235
|
-
type: 'object',
|
|
236
|
-
properties: {
|
|
237
|
-
value: { type: ['string', 'null'] },
|
|
238
|
-
},
|
|
239
|
-
required: [],
|
|
240
|
-
};
|
|
241
|
-
const strict = toStrictSchema(schema);
|
|
242
|
-
const props = strict['properties'] as Record<string, Record<string, unknown>>;
|
|
243
|
-
expect(props['value']['type']).toEqual(['string', 'null']);
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe('applyLlmDescriptions - definitions and combinators', () => {
|
|
248
|
-
it('recurses into definitions block', () => {
|
|
249
|
-
const schema: Record<string, unknown> = {
|
|
250
|
-
definitions: {
|
|
251
|
-
Foo: { description: 'old', 'x-llm-description': 'new' },
|
|
252
|
-
},
|
|
253
|
-
};
|
|
254
|
-
applyLlmDescriptions(schema);
|
|
255
|
-
const defs = schema['definitions'] as Record<string, Record<string, unknown>>;
|
|
256
|
-
expect(defs['Foo']['description']).toBe('new');
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('recurses into $defs block', () => {
|
|
260
|
-
const schema: Record<string, unknown> = {
|
|
261
|
-
$defs: {
|
|
262
|
-
Bar: { description: 'old', 'x-llm-description': 'updated' },
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
applyLlmDescriptions(schema);
|
|
266
|
-
const defs = schema['$defs'] as Record<string, Record<string, unknown>>;
|
|
267
|
-
expect(defs['Bar']['description']).toBe('updated');
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('recurses into items', () => {
|
|
271
|
-
const schema: Record<string, unknown> = {
|
|
272
|
-
type: 'array',
|
|
273
|
-
items: { 'x-llm-description': 'item desc' },
|
|
274
|
-
};
|
|
275
|
-
applyLlmDescriptions(schema);
|
|
276
|
-
const items = schema['items'] as Record<string, unknown>;
|
|
277
|
-
expect(items['description']).toBe('item desc');
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it('recurses into oneOf/anyOf/allOf', () => {
|
|
281
|
-
const schema: Record<string, unknown> = {
|
|
282
|
-
oneOf: [
|
|
283
|
-
{ 'x-llm-description': 'variant A' },
|
|
284
|
-
{ 'x-llm-description': 'variant B' },
|
|
285
|
-
],
|
|
286
|
-
};
|
|
287
|
-
applyLlmDescriptions(schema);
|
|
288
|
-
const oneOf = schema['oneOf'] as Record<string, unknown>[];
|
|
289
|
-
expect(oneOf[0]['description']).toBe('variant A');
|
|
290
|
-
expect(oneOf[1]['description']).toBe('variant B');
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('sets description even when no prior description exists', () => {
|
|
294
|
-
const schema: Record<string, unknown> = {
|
|
295
|
-
'x-llm-description': 'brand new',
|
|
296
|
-
};
|
|
297
|
-
applyLlmDescriptions(schema);
|
|
298
|
-
expect(schema['description']).toBe('brand new');
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
describe('stripExtensions', () => {
|
|
303
|
-
it('removes x- prefixed keys', () => {
|
|
304
|
-
const schema: Record<string, unknown> = {
|
|
305
|
-
type: 'string',
|
|
306
|
-
'x-custom': 'value',
|
|
307
|
-
'x-another': 123,
|
|
308
|
-
};
|
|
309
|
-
stripExtensions(schema);
|
|
310
|
-
expect(schema['x-custom']).toBeUndefined();
|
|
311
|
-
expect(schema['x-another']).toBeUndefined();
|
|
312
|
-
expect(schema['type']).toBe('string');
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('removes default key', () => {
|
|
316
|
-
const schema: Record<string, unknown> = {
|
|
317
|
-
type: 'string',
|
|
318
|
-
default: 'hello',
|
|
319
|
-
};
|
|
320
|
-
stripExtensions(schema);
|
|
321
|
-
expect(schema['default']).toBeUndefined();
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
it('handles nested structures', () => {
|
|
325
|
-
const schema: Record<string, unknown> = {
|
|
326
|
-
type: 'object',
|
|
327
|
-
properties: {
|
|
328
|
-
name: { type: 'string', 'x-sensitive': true },
|
|
329
|
-
},
|
|
330
|
-
};
|
|
331
|
-
stripExtensions(schema);
|
|
332
|
-
const props = schema['properties'] as Record<string, Record<string, unknown>>;
|
|
333
|
-
expect(props['name']['x-sensitive']).toBeUndefined();
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('recurses into arrays', () => {
|
|
337
|
-
const schema: Record<string, unknown> = {
|
|
338
|
-
oneOf: [
|
|
339
|
-
{ type: 'string', 'x-remove': true },
|
|
340
|
-
{ type: 'number', default: 0 },
|
|
341
|
-
],
|
|
342
|
-
};
|
|
343
|
-
stripExtensions(schema);
|
|
344
|
-
const oneOf = schema['oneOf'] as Record<string, unknown>[];
|
|
345
|
-
expect(oneOf[0]['x-remove']).toBeUndefined();
|
|
346
|
-
expect(oneOf[1]['default']).toBeUndefined();
|
|
347
|
-
});
|
|
348
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Type } from '@sinclair/typebox';
|
|
3
|
-
import { SchemaValidator } from '../../src/schema/validator.js';
|
|
4
|
-
import { SchemaValidationError } from '../../src/errors.js';
|
|
5
|
-
|
|
6
|
-
describe('SchemaValidator', () => {
|
|
7
|
-
it('validates correct data', () => {
|
|
8
|
-
const validator = new SchemaValidator();
|
|
9
|
-
const schema = Type.Object({ name: Type.String() });
|
|
10
|
-
const result = validator.validate({ name: 'Alice' }, schema);
|
|
11
|
-
expect(result.valid).toBe(true);
|
|
12
|
-
expect(result.errors).toHaveLength(0);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('rejects invalid data', () => {
|
|
16
|
-
const validator = new SchemaValidator();
|
|
17
|
-
const schema = Type.Object({ name: Type.String() });
|
|
18
|
-
const result = validator.validate({ name: 123 }, schema);
|
|
19
|
-
expect(result.valid).toBe(false);
|
|
20
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('validates without coercion', () => {
|
|
24
|
-
const validator = new SchemaValidator(false);
|
|
25
|
-
const schema = Type.Object({ x: Type.Number() });
|
|
26
|
-
const result = validator.validate({ x: 42 }, schema);
|
|
27
|
-
expect(result.valid).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('validateInput returns data on valid input', () => {
|
|
31
|
-
const validator = new SchemaValidator();
|
|
32
|
-
const schema = Type.Object({ x: Type.Number() });
|
|
33
|
-
const data = validator.validateInput({ x: 42 }, schema);
|
|
34
|
-
expect(data['x']).toBe(42);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('validateInput throws on invalid input', () => {
|
|
38
|
-
const validator = new SchemaValidator();
|
|
39
|
-
const schema = Type.Object({ x: Type.Number() });
|
|
40
|
-
expect(() => validator.validateInput({ x: 'not-a-number' }, schema)).toThrow(SchemaValidationError);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('validateOutput returns data on valid output', () => {
|
|
44
|
-
const validator = new SchemaValidator();
|
|
45
|
-
const schema = Type.Object({ result: Type.String() });
|
|
46
|
-
const data = validator.validateOutput({ result: 'ok' }, schema);
|
|
47
|
-
expect(data['result']).toBe('ok');
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('validateOutput throws on invalid output', () => {
|
|
51
|
-
const validator = new SchemaValidator();
|
|
52
|
-
const schema = Type.Object({ result: Type.String() });
|
|
53
|
-
expect(() => validator.validateOutput({ result: 123 }, schema)).toThrow(SchemaValidationError);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('error details include path and message', () => {
|
|
57
|
-
const validator = new SchemaValidator();
|
|
58
|
-
const schema = Type.Object({ nested: Type.Object({ x: Type.Number() }) });
|
|
59
|
-
const result = validator.validate({ nested: { x: 'bad' } }, schema);
|
|
60
|
-
expect(result.valid).toBe(false);
|
|
61
|
-
expect(result.errors[0].path).toBeDefined();
|
|
62
|
-
expect(result.errors[0].message).toBeDefined();
|
|
63
|
-
});
|
|
64
|
-
});
|