apcore-js 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acl-file.d.ts +12 -0
- package/dist/acl-file.d.ts.map +1 -0
- package/dist/acl-file.js +46 -0
- package/dist/acl-file.js.map +1 -0
- package/dist/acl.d.ts.map +1 -1
- package/dist/acl.js +20 -37
- package/dist/acl.js.map +1 -1
- package/dist/bindings.d.ts.map +1 -1
- package/dist/bindings.js +2 -21
- package/dist/bindings.js.map +1 -1
- package/dist/browser/index.d.ts +77 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +78 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/builtin-steps.js +2 -2
- package/dist/builtin-steps.js.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +12 -4
- package/dist/client.js.map +1 -1
- package/dist/config-defaults.d.ts +30 -0
- package/dist/config-defaults.d.ts.map +1 -0
- package/dist/config-defaults.js +83 -0
- package/dist/config-defaults.js.map +1 -0
- package/dist/config.d.ts +12 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +27 -125
- package/dist/config.js.map +1 -1
- package/dist/executor.d.ts.map +1 -1
- package/dist/executor.js +39 -1
- package/dist/executor.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/tracing-otel-default.d.ts +16 -0
- package/dist/middleware/tracing-otel-default.d.ts.map +1 -0
- package/dist/middleware/tracing-otel-default.js +25 -0
- package/dist/middleware/tracing-otel-default.js.map +1 -0
- package/dist/middleware/tracing.d.ts.map +1 -1
- package/dist/middleware/tracing.js +9 -10
- package/dist/middleware/tracing.js.map +1 -1
- package/dist/module.d.ts +94 -2
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +99 -2
- package/dist/module.js.map +1 -1
- package/dist/registry/metadata-pure.d.ts +13 -0
- package/dist/registry/metadata-pure.d.ts.map +1 -0
- package/dist/registry/metadata-pure.js +67 -0
- package/dist/registry/metadata-pure.js.map +1 -0
- package/dist/registry/metadata.d.ts +8 -4
- package/dist/registry/metadata.d.ts.map +1 -1
- package/dist/registry/metadata.js +9 -70
- package/dist/registry/metadata.js.map +1 -1
- package/dist/registry/multi-class.d.ts +14 -31
- package/dist/registry/multi-class.d.ts.map +1 -1
- package/dist/registry/multi-class.js.map +1 -1
- package/dist/registry/registry.d.ts +149 -4
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/registry.js +318 -19
- package/dist/registry/registry.js.map +1 -1
- package/dist/registry/scanner.d.ts.map +1 -1
- package/dist/registry/scanner.js +3 -15
- package/dist/registry/scanner.js.map +1 -1
- package/dist/schema/annotations.d.ts.map +1 -1
- package/dist/schema/annotations.js +1 -0
- package/dist/schema/annotations.js.map +1 -1
- package/dist/schema/loader-pure.d.ts +24 -0
- package/dist/schema/loader-pure.d.ts.map +1 -0
- package/dist/schema/loader-pure.js +153 -0
- package/dist/schema/loader-pure.js.map +1 -0
- package/dist/schema/loader.d.ts +14 -30
- package/dist/schema/loader.d.ts.map +1 -1
- package/dist/schema/loader.js +20 -201
- package/dist/schema/loader.js.map +1 -1
- package/dist/schema/ref-resolver.d.ts.map +1 -1
- package/dist/schema/ref-resolver.js +5 -19
- package/dist/schema/ref-resolver.js.map +1 -1
- package/dist/sys-modules/control.d.ts +0 -78
- package/dist/sys-modules/control.d.ts.map +1 -1
- package/dist/sys-modules/health.d.ts +0 -138
- package/dist/sys-modules/health.d.ts.map +1 -1
- package/dist/sys-modules/install.d.ts +12 -0
- package/dist/sys-modules/install.d.ts.map +1 -0
- package/dist/sys-modules/install.js +14 -0
- package/dist/sys-modules/install.js.map +1 -0
- package/dist/sys-modules/manifest.d.ts +1 -141
- package/dist/sys-modules/manifest.d.ts.map +1 -1
- package/dist/sys-modules/overrides-file.d.ts +14 -0
- package/dist/sys-modules/overrides-file.d.ts.map +1 -0
- package/dist/sys-modules/overrides-file.js +31 -0
- package/dist/sys-modules/overrides-file.js.map +1 -0
- package/dist/sys-modules/registration.d.ts.map +1 -1
- package/dist/sys-modules/registration.js +41 -12
- package/dist/sys-modules/registration.js.map +1 -1
- package/dist/sys-modules/toggle.d.ts +0 -70
- package/dist/sys-modules/toggle.d.ts.map +1 -1
- package/dist/sys-modules/usage.d.ts +1 -132
- package/dist/sys-modules/usage.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -11
- package/dist/utils/index.js.map +1 -1
- package/package.json +17 -5
package/dist/registry/scanner.js
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directory scanner for discovering TypeScript/JavaScript extension modules.
|
|
3
3
|
*/
|
|
4
|
+
import { statSync, readdirSync, lstatSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { resolve, relative, join, extname, basename, sep } from 'node:path';
|
|
4
6
|
import { ConfigError, ConfigNotFoundError } from '../errors.js';
|
|
5
|
-
// Lazy-load Node.js built-in modules for browser compatibility
|
|
6
|
-
let _nodeFs = null;
|
|
7
|
-
let _nodePath = null;
|
|
8
|
-
try {
|
|
9
|
-
_nodeFs = await import('node:fs');
|
|
10
|
-
}
|
|
11
|
-
catch { /* browser environment */ }
|
|
12
|
-
try {
|
|
13
|
-
_nodePath = await import('node:path');
|
|
14
|
-
}
|
|
15
|
-
catch { /* browser environment */ }
|
|
16
7
|
const SKIP_DIR_NAMES = new Set(['node_modules', '__pycache__']);
|
|
17
8
|
const VALID_EXTENSIONS = new Set(['.ts', '.js']);
|
|
18
9
|
const SKIP_SUFFIXES = ['.d.ts', '.test.ts', '.test.js', '.spec.ts', '.spec.js'];
|
|
19
10
|
function existsAndIsDir(p) {
|
|
20
11
|
try {
|
|
21
|
-
return
|
|
12
|
+
return statSync(p).isDirectory();
|
|
22
13
|
}
|
|
23
14
|
catch {
|
|
24
15
|
return false;
|
|
25
16
|
}
|
|
26
17
|
}
|
|
27
18
|
export function scanExtensions(root, maxDepth = 8, followSymlinks = false) {
|
|
28
|
-
const { readdirSync, statSync, lstatSync, realpathSync } = _nodeFs;
|
|
29
|
-
const { resolve, relative, join, extname, basename, sep } = _nodePath;
|
|
30
19
|
const rootResolved = resolve(root);
|
|
31
20
|
if (!existsAndIsDir(rootResolved)) {
|
|
32
21
|
throw new ConfigNotFoundError(rootResolved);
|
|
@@ -141,7 +130,6 @@ export function scanExtensions(root, maxDepth = 8, followSymlinks = false) {
|
|
|
141
130
|
return results;
|
|
142
131
|
}
|
|
143
132
|
export function scanMultiRoot(roots, maxDepth = 8, followSymlinks = false) {
|
|
144
|
-
const { basename } = _nodePath;
|
|
145
133
|
const allResults = [];
|
|
146
134
|
const seenNamespaces = new Set();
|
|
147
135
|
const resolved = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/registry/scanner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../../src/registry/scanner.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGhE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,KAA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KAAK,CAAC,WAAW,CAAY,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvE,IAAI,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,WAAW,CAAC,yBAAyB,SAAS,GAAG,CAAC,CAAC;QAC/D,CAAC;QACD,cAAc,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;QACnE,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,UAAU,CAAC,IAAI,CAAC;gBACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,WAAW,EAAE,GAAG,SAAS,IAAI,CAAC,CAAC,WAAW,EAAE;gBAC5C,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,SAAS;aACV,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/schema/annotations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/schema/annotations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAmBrE,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG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AC3B,MAAM,EAAG,CAAC,CAAC,QAAQ,CAA6B,IAAI,EAAE;YACtD,MAAM,EAAG,CAAC,CAAC,QAAQ,CAA6B,IAAI,EAAE;YACtD,WAAW,EAAE,CAAC,CAAC,aAAa,CAAuB;SACpD,CAAC,CAAC,CAAC;IACN,CAAC;IACD,IAAI,YAAY,IAAI,IAAI;QAAE,OAAO,YAAY,CAAC;IAC9C,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,YAAwD,EACxD,YAAwD;IAExD,MAAM,MAAM,GAAG,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/D,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe portion of the schema loader.
|
|
3
|
+
*
|
|
4
|
+
* Contains the runtime-neutral pieces — JSON-Schema-to-TypeBox conversion and
|
|
5
|
+
* canonical-form async hashing — used by both the Node-side `SchemaLoader` and
|
|
6
|
+
* the browser entry point.
|
|
7
|
+
*
|
|
8
|
+
* No `node:*` imports may be added here. The transitive import graph is
|
|
9
|
+
* audited by `tests/browser-entry.test.ts`.
|
|
10
|
+
*/
|
|
11
|
+
import { type TSchema } from '@sinclair/typebox';
|
|
12
|
+
export declare function sortedKeysStringify(obj: unknown): string;
|
|
13
|
+
/**
|
|
14
|
+
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
15
|
+
* schema using the WebCrypto SubtleCrypto API. Output matches `contentHash`
|
|
16
|
+
* (Node-only sync variant) and the Python/Rust SDKs (sync finding A-D-033).
|
|
17
|
+
*/
|
|
18
|
+
export declare function contentHashAsync(schema: unknown): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Convert a JSON Schema dict to a TypeBox TSchema.
|
|
21
|
+
* Supports recursive schemas via $id + $ref: "#", and oneOf/anyOf/allOf/not.
|
|
22
|
+
*/
|
|
23
|
+
export declare function jsonSchemaToTypeBox(schema: Record<string, unknown>): TSchema;
|
|
24
|
+
//# sourceMappingURL=loader-pure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-pure.d.ts","sourceRoot":"","sources":["../../src/schema/loader-pure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAQ,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAOvD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQxD;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBvE;AAMD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAM5E"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe portion of the schema loader.
|
|
3
|
+
*
|
|
4
|
+
* Contains the runtime-neutral pieces — JSON-Schema-to-TypeBox conversion and
|
|
5
|
+
* canonical-form async hashing — used by both the Node-side `SchemaLoader` and
|
|
6
|
+
* the browser entry point.
|
|
7
|
+
*
|
|
8
|
+
* No `node:*` imports may be added here. The transitive import graph is
|
|
9
|
+
* audited by `tests/browser-entry.test.ts`.
|
|
10
|
+
*/
|
|
11
|
+
import { Type } from '@sinclair/typebox';
|
|
12
|
+
import { ONEOF_MARKER } from './constants.js';
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// Canonical-form serialization (used for content hashing)
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
export function sortedKeysStringify(obj) {
|
|
17
|
+
if (obj === null || typeof obj !== 'object')
|
|
18
|
+
return JSON.stringify(obj);
|
|
19
|
+
if (Array.isArray(obj))
|
|
20
|
+
return `[${obj.map(sortedKeysStringify).join(',')}]`;
|
|
21
|
+
const sorted = Object.keys(obj).sort();
|
|
22
|
+
const pairs = sorted.map((k) => `${JSON.stringify(k)}:${sortedKeysStringify(obj[k])}`);
|
|
23
|
+
return `{${pairs.join(',')}}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
27
|
+
* schema using the WebCrypto SubtleCrypto API. Output matches `contentHash`
|
|
28
|
+
* (Node-only sync variant) and the Python/Rust SDKs (sync finding A-D-033).
|
|
29
|
+
*/
|
|
30
|
+
export async function contentHashAsync(schema) {
|
|
31
|
+
const canonical = sortedKeysStringify(schema);
|
|
32
|
+
const subtle = typeof globalThis !== 'undefined'
|
|
33
|
+
? globalThis.crypto?.subtle
|
|
34
|
+
: undefined;
|
|
35
|
+
if (!subtle) {
|
|
36
|
+
throw new Error('contentHashAsync(): no WebCrypto SubtleCrypto available in this runtime.');
|
|
37
|
+
}
|
|
38
|
+
const data = new TextEncoder().encode(canonical);
|
|
39
|
+
const digest = await subtle.digest('SHA-256', data);
|
|
40
|
+
const bytes = new Uint8Array(digest);
|
|
41
|
+
let hex = '';
|
|
42
|
+
for (const b of bytes) {
|
|
43
|
+
hex += b.toString(16).padStart(2, '0');
|
|
44
|
+
}
|
|
45
|
+
return hex;
|
|
46
|
+
}
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// JSON Schema → TypeBox conversion
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
/**
|
|
51
|
+
* Convert a JSON Schema dict to a TypeBox TSchema.
|
|
52
|
+
* Supports recursive schemas via $id + $ref: "#", and oneOf/anyOf/allOf/not.
|
|
53
|
+
*/
|
|
54
|
+
export function jsonSchemaToTypeBox(schema) {
|
|
55
|
+
if ('$id' in schema && typeof schema['$id'] === 'string') {
|
|
56
|
+
const $id = schema['$id'];
|
|
57
|
+
return Type.Recursive((self) => _convert(schema, self, $id), { $id });
|
|
58
|
+
}
|
|
59
|
+
return _convert(schema, undefined, undefined);
|
|
60
|
+
}
|
|
61
|
+
function _convert(schema, self, selfId) {
|
|
62
|
+
if ('$ref' in schema) {
|
|
63
|
+
const ref = schema['$ref'];
|
|
64
|
+
if (self !== undefined && (ref === '#' || ref === selfId)) {
|
|
65
|
+
return self;
|
|
66
|
+
}
|
|
67
|
+
return Type.Unknown();
|
|
68
|
+
}
|
|
69
|
+
const schemaType = schema['type'];
|
|
70
|
+
let result;
|
|
71
|
+
if (schemaType === 'object')
|
|
72
|
+
result = _convertObject(schema, self, selfId);
|
|
73
|
+
else if (schemaType === 'array')
|
|
74
|
+
result = _convertArray(schema, self, selfId);
|
|
75
|
+
else if (schemaType === 'string')
|
|
76
|
+
result = _convertString(schema);
|
|
77
|
+
else if (schemaType === 'integer')
|
|
78
|
+
result = _convertNumeric(schema, Type.Integer);
|
|
79
|
+
else if (schemaType === 'number')
|
|
80
|
+
result = _convertNumeric(schema, Type.Number);
|
|
81
|
+
else if (schemaType === 'boolean')
|
|
82
|
+
result = Type.Boolean();
|
|
83
|
+
else if (schemaType === 'null')
|
|
84
|
+
result = Type.Null();
|
|
85
|
+
else
|
|
86
|
+
result = _convertCombinator(schema, self, selfId);
|
|
87
|
+
if (typeof schema['description'] === 'string')
|
|
88
|
+
result['description'] = schema['description'];
|
|
89
|
+
if (typeof schema['title'] === 'string')
|
|
90
|
+
result['title'] = schema['title'];
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
function _convertObject(schema, self, selfId) {
|
|
94
|
+
const properties = schema['properties'];
|
|
95
|
+
const required = new Set(schema['required'] ?? []);
|
|
96
|
+
if (properties) {
|
|
97
|
+
const typeboxProps = {};
|
|
98
|
+
for (const [name, propSchema] of Object.entries(properties)) {
|
|
99
|
+
const propType = _convert(propSchema, self, selfId);
|
|
100
|
+
typeboxProps[name] = required.has(name) ? propType : Type.Optional(propType);
|
|
101
|
+
}
|
|
102
|
+
return Type.Object(typeboxProps);
|
|
103
|
+
}
|
|
104
|
+
return Type.Record(Type.String(), Type.Unknown());
|
|
105
|
+
}
|
|
106
|
+
function _convertArray(schema, self, selfId) {
|
|
107
|
+
const items = schema['items'];
|
|
108
|
+
return items ? Type.Array(_convert(items, self, selfId)) : Type.Array(Type.Unknown());
|
|
109
|
+
}
|
|
110
|
+
function _convertString(schema) {
|
|
111
|
+
const opts = {};
|
|
112
|
+
for (const key of ['minLength', 'maxLength', 'pattern', 'format']) {
|
|
113
|
+
if (key in schema)
|
|
114
|
+
opts[key] = schema[key];
|
|
115
|
+
}
|
|
116
|
+
return Type.String(opts);
|
|
117
|
+
}
|
|
118
|
+
function _convertNumeric(schema, factory) {
|
|
119
|
+
const opts = {};
|
|
120
|
+
for (const key of ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf']) {
|
|
121
|
+
if (key in schema)
|
|
122
|
+
opts[key] = schema[key];
|
|
123
|
+
}
|
|
124
|
+
return factory(opts);
|
|
125
|
+
}
|
|
126
|
+
function _convertCombinator(schema, self, selfId) {
|
|
127
|
+
if ('enum' in schema) {
|
|
128
|
+
const values = schema['enum'];
|
|
129
|
+
return Type.Union(values.map((v) => v === null ? Type.Null() : Type.Literal(v)));
|
|
130
|
+
}
|
|
131
|
+
if ('const' in schema) {
|
|
132
|
+
const value = schema['const'];
|
|
133
|
+
return value === null ? Type.Null() : Type.Literal(value);
|
|
134
|
+
}
|
|
135
|
+
if ('oneOf' in schema) {
|
|
136
|
+
const branches = schema['oneOf'].map((s) => _convert(s, self, selfId));
|
|
137
|
+
const result = Type.Union(branches);
|
|
138
|
+
result[ONEOF_MARKER] = 'oneOf';
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
if ('anyOf' in schema) {
|
|
142
|
+
return Type.Union(schema['anyOf'].map((s) => _convert(s, self, selfId)));
|
|
143
|
+
}
|
|
144
|
+
if ('allOf' in schema) {
|
|
145
|
+
return Type.Intersect(schema['allOf'].map((s) => _convert(s, self, selfId)));
|
|
146
|
+
}
|
|
147
|
+
if ('not' in schema) {
|
|
148
|
+
const inner = _convert(schema['not'], self, selfId);
|
|
149
|
+
return Type.Not(inner);
|
|
150
|
+
}
|
|
151
|
+
return Type.Unknown();
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=loader-pure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader-pure.js","sourceRoot":"","sources":["../../src/schema/loader-pure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,IAAI,EAAgB,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,8EAA8E;AAC9E,0DAA0D;AAC1D,8EAA8E;AAE9E,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC9C,IAAI,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxE,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC7E,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAa,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CACtB,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAE,GAA+B,CAAC,CAAC,CAAC,CAAC,EAAE,CAC1F,CAAC;IACF,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAChC,CAAC;AAED;;;;GA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,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC"}
|
package/dist/schema/loader.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SchemaLoader — primary entry point for the schema system.
|
|
2
|
+
* SchemaLoader — primary entry point for the Node-side schema system.
|
|
3
3
|
*
|
|
4
|
-
* Uses TypeBox for schema representation. Since TypeBox schemas ARE JSON
|
|
5
|
-
* the conversion layer is minimal.
|
|
4
|
+
* Uses TypeBox for schema representation. Since TypeBox schemas ARE JSON
|
|
5
|
+
* Schema, the conversion layer is minimal.
|
|
6
|
+
*
|
|
7
|
+
* Browser-safe pieces (`jsonSchemaToTypeBox`, `contentHashAsync`) live in
|
|
8
|
+
* `./loader-pure.ts` and are re-exported here so existing imports keep
|
|
9
|
+
* working from the Node entry. Code that must run in the browser should
|
|
10
|
+
* import them from `./loader-pure.ts` (or from the package `./browser`
|
|
11
|
+
* entry) directly.
|
|
6
12
|
*/
|
|
7
|
-
import {
|
|
13
|
+
import type { TSchema } from '@sinclair/typebox';
|
|
8
14
|
import type { Config } from '../config.js';
|
|
9
15
|
import type { ResolvedSchema, SchemaDefinition } from './types.js';
|
|
16
|
+
export { jsonSchemaToTypeBox, contentHashAsync, sortedKeysStringify, } from './loader-pure.js';
|
|
10
17
|
export declare class SchemaLoader {
|
|
11
18
|
private _config;
|
|
12
19
|
private _schemasDir;
|
|
@@ -23,32 +30,9 @@ export declare class SchemaLoader {
|
|
|
23
30
|
clearCache(): void;
|
|
24
31
|
}
|
|
25
32
|
/**
|
|
26
|
-
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Sync API — Node.js only. In environments without `node:crypto` (browsers,
|
|
30
|
-
* some edge runtimes), this throws so callers cannot accidentally consume a
|
|
31
|
-
* different hash than apcore-python / apcore-rust would produce. Spec
|
|
32
|
-
* §schema-system §4.15.5 requires sha256 of canonical JSON; a non-sha256
|
|
33
|
-
* fallback collides with cross-language cache keys (sync finding A-D-033).
|
|
34
|
-
*
|
|
35
|
-
* Use {@link contentHashAsync} in browsers — it uses WebCrypto SubtleCrypto
|
|
36
|
-
* to compute the same SHA-256 digest asynchronously.
|
|
33
|
+
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
34
|
+
* schema. Sync — Node-only. Use {@link contentHashAsync} from the browser
|
|
35
|
+
* entry (or this file) for the WebCrypto-backed equivalent.
|
|
37
36
|
*/
|
|
38
37
|
export declare function contentHash(schema: unknown): string;
|
|
39
|
-
/**
|
|
40
|
-
* Compute the SHA-256 hex digest of the canonical JSON serialization of a schema
|
|
41
|
-
* — async, runtime-portable variant.
|
|
42
|
-
*
|
|
43
|
-
* Uses Node's `node:crypto` when available, otherwise falls back to the
|
|
44
|
-
* WebCrypto `crypto.subtle.digest('SHA-256', ...)` API present in modern
|
|
45
|
-
* browsers and edge runtimes. Output is identical across all paths and
|
|
46
|
-
* matches the Python/Rust SDKs (sync finding A-D-033).
|
|
47
|
-
*/
|
|
48
|
-
export declare function contentHashAsync(schema: unknown): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
* Convert a JSON Schema dict to a TypeBox TSchema.
|
|
51
|
-
* Supports recursive schemas via $id + $ref: "#", and oneOf/anyOf/allOf/not.
|
|
52
|
-
*/
|
|
53
|
-
export declare function jsonSchemaToTypeBox(schema: Record<string, unknown>): TSchema;
|
|
54
38
|
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema/loader.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/schema/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAInE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,aAAa,CAA4D;gBAErE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAWtD,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB;IAkDxC,OAAO,CAAC,SAAS,EAAE,gBAAgB,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC;IAsBtE,SAAS,CACP,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,OAAO,GAAG,IAAI,EAClC,kBAAkB,CAAC,EAAE,OAAO,GAAG,IAAI,GAClC,CAAC,cAAc,EAAE,cAAc,CAAC;IAkDnC,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,WAAW;IAoBnB,UAAU,IAAI,IAAI;CAMnB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAGnD"}
|
package/dist/schema/loader.js
CHANGED
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SchemaLoader — primary entry point for the schema system.
|
|
2
|
+
* SchemaLoader — primary entry point for the Node-side schema system.
|
|
3
3
|
*
|
|
4
|
-
* Uses TypeBox for schema representation. Since TypeBox schemas ARE JSON
|
|
5
|
-
* the conversion layer is minimal.
|
|
4
|
+
* Uses TypeBox for schema representation. Since TypeBox schemas ARE JSON
|
|
5
|
+
* Schema, the conversion layer is minimal.
|
|
6
|
+
*
|
|
7
|
+
* Browser-safe pieces (`jsonSchemaToTypeBox`, `contentHashAsync`) live in
|
|
8
|
+
* `./loader-pure.ts` and are re-exported here so existing imports keep
|
|
9
|
+
* working from the Node entry. Code that must run in the browser should
|
|
10
|
+
* import them from `./loader-pure.ts` (or from the package `./browser`
|
|
11
|
+
* entry) directly.
|
|
6
12
|
*/
|
|
7
|
-
import {
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import { join, resolve } from 'node:path';
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
16
|
import yaml from 'js-yaml';
|
|
9
17
|
import { SchemaNotFoundError, SchemaParseError } from '../errors.js';
|
|
10
18
|
import { RefResolver } from './ref-resolver.js';
|
|
11
19
|
import { SchemaStrategy } from './types.js';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
let _nodeFs = null;
|
|
15
|
-
let _nodePath = null;
|
|
16
|
-
let _nodeCrypto = null;
|
|
17
|
-
try {
|
|
18
|
-
_nodeFs = await import('node:fs');
|
|
19
|
-
}
|
|
20
|
-
catch { /* browser environment */ }
|
|
21
|
-
try {
|
|
22
|
-
_nodePath = await import('node:path');
|
|
23
|
-
}
|
|
24
|
-
catch { /* browser environment */ }
|
|
25
|
-
try {
|
|
26
|
-
_nodeCrypto = await import('node:crypto');
|
|
27
|
-
}
|
|
28
|
-
catch { /* browser environment */ }
|
|
20
|
+
import { jsonSchemaToTypeBox, sortedKeysStringify } from './loader-pure.js';
|
|
21
|
+
export { jsonSchemaToTypeBox, contentHashAsync, sortedKeysStringify, } from './loader-pure.js';
|
|
29
22
|
export class SchemaLoader {
|
|
30
23
|
_config;
|
|
31
24
|
_schemasDir;
|
|
32
25
|
_resolver;
|
|
33
26
|
_schemaCache = new Map();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
_contentCache = new Map(); // sha256hex → model
|
|
27
|
+
_pathIndex = new Map();
|
|
28
|
+
_contentCache = new Map();
|
|
37
29
|
constructor(config, schemasDir) {
|
|
38
|
-
const { resolve } = _nodePath;
|
|
39
30
|
this._config = config;
|
|
40
31
|
if (schemasDir != null) {
|
|
41
32
|
this._schemasDir = resolve(schemasDir);
|
|
@@ -50,8 +41,6 @@ export class SchemaLoader {
|
|
|
50
41
|
const cached = this._schemaCache.get(moduleId);
|
|
51
42
|
if (cached)
|
|
52
43
|
return cached;
|
|
53
|
-
const { existsSync, readFileSync } = _nodeFs;
|
|
54
|
-
const { join } = _nodePath;
|
|
55
44
|
const filePath = join(this._schemasDir, moduleId.replace(/\./g, '/') + '.schema.yaml');
|
|
56
45
|
if (!existsSync(filePath)) {
|
|
57
46
|
throw new SchemaNotFoundError(moduleId);
|
|
@@ -117,7 +106,6 @@ export class SchemaLoader {
|
|
|
117
106
|
yaml_only: SchemaStrategy.YAML_ONLY,
|
|
118
107
|
};
|
|
119
108
|
const strategy = strategyMap[rawStrategy] ?? SchemaStrategy.YAML_FIRST;
|
|
120
|
-
// Check path index first
|
|
121
109
|
const pathKey = `${moduleId}:${strategy}`;
|
|
122
110
|
const cachedHash = this._pathIndex.get(pathKey);
|
|
123
111
|
if (cachedHash) {
|
|
@@ -151,8 +139,6 @@ export class SchemaLoader {
|
|
|
151
139
|
if (result === null) {
|
|
152
140
|
throw new SchemaNotFoundError(moduleId);
|
|
153
141
|
}
|
|
154
|
-
// Store in two-level cache — hash BOTH schemas to avoid cross-module collision
|
|
155
|
-
// when two distinct modules share an identical input schema but differ in output.
|
|
156
142
|
const digest = contentHash({ input: result[0].jsonSchema, output: result[1].jsonSchema });
|
|
157
143
|
if (!this._contentCache.has(digest)) {
|
|
158
144
|
this._contentCache.set(digest, result);
|
|
@@ -186,180 +172,13 @@ export class SchemaLoader {
|
|
|
186
172
|
this._resolver.clearCache();
|
|
187
173
|
}
|
|
188
174
|
}
|
|
189
|
-
// ---------------------------------------------------------------------------
|
|
190
|
-
// Content-addressable hashing (Issue #44 §5)
|
|
191
|
-
// ---------------------------------------------------------------------------
|
|
192
|
-
function sortedKeysStringify(obj) {
|
|
193
|
-
if (obj === null || typeof obj !== 'object')
|
|
194
|
-
return JSON.stringify(obj);
|
|
195
|
-
if (Array.isArray(obj))
|
|
196
|
-
return `[${obj.map(sortedKeysStringify).join(',')}]`;
|
|
197
|
-
const sorted = Object.keys(obj).sort();
|
|
198
|
-
const pairs = sorted.map((k) => `${JSON.stringify(k)}:${sortedKeysStringify(obj[k])}`);
|
|
199
|
-
return `{${pairs.join(',')}}`;
|
|
200
|
-
}
|
|
201
175
|
/**
|
|
202
|
-
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* Sync API — Node.js only. In environments without `node:crypto` (browsers,
|
|
206
|
-
* some edge runtimes), this throws so callers cannot accidentally consume a
|
|
207
|
-
* different hash than apcore-python / apcore-rust would produce. Spec
|
|
208
|
-
* §schema-system §4.15.5 requires sha256 of canonical JSON; a non-sha256
|
|
209
|
-
* fallback collides with cross-language cache keys (sync finding A-D-033).
|
|
210
|
-
*
|
|
211
|
-
* Use {@link contentHashAsync} in browsers — it uses WebCrypto SubtleCrypto
|
|
212
|
-
* to compute the same SHA-256 digest asynchronously.
|
|
176
|
+
* Compute the SHA-256 hex digest of the canonical JSON serialization of a
|
|
177
|
+
* schema. Sync — Node-only. Use {@link contentHashAsync} from the browser
|
|
178
|
+
* entry (or this file) for the WebCrypto-backed equivalent.
|
|
213
179
|
*/
|
|
214
180
|
export function contentHash(schema) {
|
|
215
181
|
const canonical = sortedKeysStringify(schema);
|
|
216
|
-
|
|
217
|
-
return _nodeCrypto.createHash('sha256').update(canonical).digest('hex');
|
|
218
|
-
}
|
|
219
|
-
throw new Error('contentHash() requires node:crypto for synchronous SHA-256. ' +
|
|
220
|
-
'In browser/edge environments, call contentHashAsync() instead — ' +
|
|
221
|
-
'it uses the WebCrypto SubtleCrypto API to produce the spec-compliant digest.');
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Compute the SHA-256 hex digest of the canonical JSON serialization of a schema
|
|
225
|
-
* — async, runtime-portable variant.
|
|
226
|
-
*
|
|
227
|
-
* Uses Node's `node:crypto` when available, otherwise falls back to the
|
|
228
|
-
* WebCrypto `crypto.subtle.digest('SHA-256', ...)` API present in modern
|
|
229
|
-
* browsers and edge runtimes. Output is identical across all paths and
|
|
230
|
-
* matches the Python/Rust SDKs (sync finding A-D-033).
|
|
231
|
-
*/
|
|
232
|
-
export async function contentHashAsync(schema) {
|
|
233
|
-
const canonical = sortedKeysStringify(schema);
|
|
234
|
-
if (_nodeCrypto) {
|
|
235
|
-
return _nodeCrypto.createHash('sha256').update(canonical).digest('hex');
|
|
236
|
-
}
|
|
237
|
-
const subtle = (typeof globalThis !== 'undefined'
|
|
238
|
-
? globalThis.crypto?.subtle
|
|
239
|
-
: undefined);
|
|
240
|
-
if (!subtle) {
|
|
241
|
-
throw new Error('contentHashAsync(): no SHA-256 implementation available — neither node:crypto nor WebCrypto SubtleCrypto is present in this runtime.');
|
|
242
|
-
}
|
|
243
|
-
const data = new TextEncoder().encode(canonical);
|
|
244
|
-
const digest = await subtle.digest('SHA-256', data);
|
|
245
|
-
const bytes = new Uint8Array(digest);
|
|
246
|
-
let hex = '';
|
|
247
|
-
for (const b of bytes) {
|
|
248
|
-
hex += b.toString(16).padStart(2, '0');
|
|
249
|
-
}
|
|
250
|
-
return hex;
|
|
251
|
-
}
|
|
252
|
-
// ---------------------------------------------------------------------------
|
|
253
|
-
// JSON Schema → TypeBox conversion
|
|
254
|
-
// ---------------------------------------------------------------------------
|
|
255
|
-
/**
|
|
256
|
-
* Convert a JSON Schema dict to a TypeBox TSchema.
|
|
257
|
-
* Supports recursive schemas via $id + $ref: "#", and oneOf/anyOf/allOf/not.
|
|
258
|
-
*/
|
|
259
|
-
export function jsonSchemaToTypeBox(schema) {
|
|
260
|
-
// Recursive schema: $id present → wrap in Type.Recursive to support self-references
|
|
261
|
-
if ('$id' in schema && typeof schema['$id'] === 'string') {
|
|
262
|
-
const $id = schema['$id'];
|
|
263
|
-
return Type.Recursive((self) => _convert(schema, self, $id), { $id });
|
|
264
|
-
}
|
|
265
|
-
return _convert(schema, undefined, undefined);
|
|
266
|
-
}
|
|
267
|
-
function _convert(schema, self, selfId) {
|
|
268
|
-
// Handle $ref — may be a self-reference in a recursive schema
|
|
269
|
-
if ('$ref' in schema) {
|
|
270
|
-
const ref = schema['$ref'];
|
|
271
|
-
if (self !== undefined && (ref === '#' || ref === selfId)) {
|
|
272
|
-
return self;
|
|
273
|
-
}
|
|
274
|
-
// Unresolved external $ref (should have been inlined by RefResolver)
|
|
275
|
-
return Type.Unknown();
|
|
276
|
-
}
|
|
277
|
-
const schemaType = schema['type'];
|
|
278
|
-
let result;
|
|
279
|
-
if (schemaType === 'object')
|
|
280
|
-
result = _convertObject(schema, self, selfId);
|
|
281
|
-
else if (schemaType === 'array')
|
|
282
|
-
result = _convertArray(schema, self, selfId);
|
|
283
|
-
else if (schemaType === 'string')
|
|
284
|
-
result = _convertString(schema);
|
|
285
|
-
else if (schemaType === 'integer')
|
|
286
|
-
result = _convertNumeric(schema, Type.Integer);
|
|
287
|
-
else if (schemaType === 'number')
|
|
288
|
-
result = _convertNumeric(schema, Type.Number);
|
|
289
|
-
else if (schemaType === 'boolean')
|
|
290
|
-
result = Type.Boolean();
|
|
291
|
-
else if (schemaType === 'null')
|
|
292
|
-
result = Type.Null();
|
|
293
|
-
else
|
|
294
|
-
result = _convertCombinator(schema, self, selfId);
|
|
295
|
-
// Preserve JSON Schema metadata
|
|
296
|
-
if (typeof schema['description'] === 'string')
|
|
297
|
-
result['description'] = schema['description'];
|
|
298
|
-
if (typeof schema['title'] === 'string')
|
|
299
|
-
result['title'] = schema['title'];
|
|
300
|
-
return result;
|
|
301
|
-
}
|
|
302
|
-
function _convertObject(schema, self, selfId) {
|
|
303
|
-
const properties = schema['properties'];
|
|
304
|
-
const required = new Set(schema['required'] ?? []);
|
|
305
|
-
if (properties) {
|
|
306
|
-
const typeboxProps = {};
|
|
307
|
-
for (const [name, propSchema] of Object.entries(properties)) {
|
|
308
|
-
const propType = _convert(propSchema, self, selfId);
|
|
309
|
-
typeboxProps[name] = required.has(name) ? propType : Type.Optional(propType);
|
|
310
|
-
}
|
|
311
|
-
return Type.Object(typeboxProps);
|
|
312
|
-
}
|
|
313
|
-
return Type.Record(Type.String(), Type.Unknown());
|
|
314
|
-
}
|
|
315
|
-
function _convertArray(schema, self, selfId) {
|
|
316
|
-
const items = schema['items'];
|
|
317
|
-
return items
|
|
318
|
-
? Type.Array(_convert(items, self, selfId))
|
|
319
|
-
: Type.Array(Type.Unknown());
|
|
320
|
-
}
|
|
321
|
-
function _convertString(schema) {
|
|
322
|
-
const opts = {};
|
|
323
|
-
for (const key of ['minLength', 'maxLength', 'pattern', 'format']) {
|
|
324
|
-
if (key in schema)
|
|
325
|
-
opts[key] = schema[key];
|
|
326
|
-
}
|
|
327
|
-
return Type.String(opts);
|
|
328
|
-
}
|
|
329
|
-
function _convertNumeric(schema, factory) {
|
|
330
|
-
const opts = {};
|
|
331
|
-
for (const key of ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum', 'multipleOf']) {
|
|
332
|
-
if (key in schema)
|
|
333
|
-
opts[key] = schema[key];
|
|
334
|
-
}
|
|
335
|
-
return factory(opts);
|
|
336
|
-
}
|
|
337
|
-
function _convertCombinator(schema, self, selfId) {
|
|
338
|
-
if ('enum' in schema) {
|
|
339
|
-
const values = schema['enum'];
|
|
340
|
-
return Type.Union(values.map((v) => v === null ? Type.Null() : Type.Literal(v)));
|
|
341
|
-
}
|
|
342
|
-
if ('const' in schema) {
|
|
343
|
-
const value = schema['const'];
|
|
344
|
-
return value === null ? Type.Null() : Type.Literal(value);
|
|
345
|
-
}
|
|
346
|
-
if ('oneOf' in schema) {
|
|
347
|
-
const branches = schema['oneOf'].map((s) => _convert(s, self, selfId));
|
|
348
|
-
// Mark with ONEOF_MARKER so SchemaValidator can apply exhaustive oneOf semantics
|
|
349
|
-
const result = Type.Union(branches);
|
|
350
|
-
result[ONEOF_MARKER] = 'oneOf';
|
|
351
|
-
return result;
|
|
352
|
-
}
|
|
353
|
-
if ('anyOf' in schema) {
|
|
354
|
-
return Type.Union(schema['anyOf'].map((s) => _convert(s, self, selfId)));
|
|
355
|
-
}
|
|
356
|
-
if ('allOf' in schema) {
|
|
357
|
-
return Type.Intersect(schema['allOf'].map((s) => _convert(s, self, selfId)));
|
|
358
|
-
}
|
|
359
|
-
if ('not' in schema) {
|
|
360
|
-
const inner = _convert(schema['not'], self, selfId);
|
|
361
|
-
return Type.Not(inner);
|
|
362
|
-
}
|
|
363
|
-
return Type.Unknown();
|
|
182
|
+
return createHash('sha256').update(canonical).digest('hex');
|
|
364
183
|
}
|
|
365
184
|
//# sourceMappingURL=loader.js.map
|