typesea 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +320 -0
- package/dist/adapters/index.d.ts +152 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +396 -0
- package/dist/aot/index.d.ts +33 -0
- package/dist/aot/index.d.ts.map +1 -0
- package/dist/aot/index.js +295 -0
- package/dist/async/index.d.ts +111 -0
- package/dist/async/index.d.ts.map +1 -0
- package/dist/async/index.js +221 -0
- package/dist/builders/composite.d.ts +31 -0
- package/dist/builders/composite.d.ts.map +1 -0
- package/dist/builders/composite.js +165 -0
- package/dist/builders/index.d.ts +11 -0
- package/dist/builders/index.d.ts.map +1 -0
- package/dist/builders/index.js +9 -0
- package/dist/builders/modifier.d.ts +26 -0
- package/dist/builders/modifier.d.ts.map +1 -0
- package/dist/builders/modifier.js +67 -0
- package/dist/builders/object/guard.d.ts +62 -0
- package/dist/builders/object/guard.d.ts.map +1 -0
- package/dist/builders/object/guard.js +113 -0
- package/dist/builders/object/index.d.ts +7 -0
- package/dist/builders/object/index.d.ts.map +1 -0
- package/dist/builders/object/index.js +5 -0
- package/dist/builders/object/schema.d.ts +44 -0
- package/dist/builders/object/schema.d.ts.map +1 -0
- package/dist/builders/object/schema.js +257 -0
- package/dist/builders/object/types.d.ts +63 -0
- package/dist/builders/object/types.d.ts.map +1 -0
- package/dist/builders/object/types.js +5 -0
- package/dist/builders/scalar.d.ts +39 -0
- package/dist/builders/scalar.d.ts.map +1 -0
- package/dist/builders/scalar.js +63 -0
- package/dist/builders/table.d.ts +53 -0
- package/dist/builders/table.d.ts.map +1 -0
- package/dist/builders/table.js +48 -0
- package/dist/builders/types.d.ts +26 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/builders/types.js +5 -0
- package/dist/compile/check-composite.d.ts +34 -0
- package/dist/compile/check-composite.d.ts.map +1 -0
- package/dist/compile/check-composite.js +117 -0
- package/dist/compile/check-scalar.d.ts +24 -0
- package/dist/compile/check-scalar.d.ts.map +1 -0
- package/dist/compile/check-scalar.js +73 -0
- package/dist/compile/check.d.ts +15 -0
- package/dist/compile/check.d.ts.map +1 -0
- package/dist/compile/check.js +98 -0
- package/dist/compile/context.d.ts +35 -0
- package/dist/compile/context.d.ts.map +1 -0
- package/dist/compile/context.js +72 -0
- package/dist/compile/graph-predicate.d.ts +19 -0
- package/dist/compile/graph-predicate.d.ts.map +1 -0
- package/dist/compile/graph-predicate.js +460 -0
- package/dist/compile/guard.d.ts +41 -0
- package/dist/compile/guard.d.ts.map +1 -0
- package/dist/compile/guard.js +180 -0
- package/dist/compile/index.d.ts +8 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +6 -0
- package/dist/compile/issue.d.ts +18 -0
- package/dist/compile/issue.d.ts.map +1 -0
- package/dist/compile/issue.js +28 -0
- package/dist/compile/names.d.ts +16 -0
- package/dist/compile/names.d.ts.map +1 -0
- package/dist/compile/names.js +82 -0
- package/dist/compile/predicate.d.ts +23 -0
- package/dist/compile/predicate.d.ts.map +1 -0
- package/dist/compile/predicate.js +317 -0
- package/dist/compile/runtime.d.ts +55 -0
- package/dist/compile/runtime.d.ts.map +1 -0
- package/dist/compile/runtime.js +63 -0
- package/dist/compile/source.d.ts +11 -0
- package/dist/compile/source.d.ts.map +1 -0
- package/dist/compile/source.js +51 -0
- package/dist/compile/types.d.ts +52 -0
- package/dist/compile/types.d.ts.map +1 -0
- package/dist/compile/types.js +5 -0
- package/dist/decoder/index.d.ts +106 -0
- package/dist/decoder/index.d.ts.map +1 -0
- package/dist/decoder/index.js +262 -0
- package/dist/evaluate/check-composite.d.ts +39 -0
- package/dist/evaluate/check-composite.d.ts.map +1 -0
- package/dist/evaluate/check-composite.js +184 -0
- package/dist/evaluate/check-scalar.d.ts +20 -0
- package/dist/evaluate/check-scalar.d.ts.map +1 -0
- package/dist/evaluate/check-scalar.js +81 -0
- package/dist/evaluate/check.d.ts +11 -0
- package/dist/evaluate/check.d.ts.map +1 -0
- package/dist/evaluate/check.js +126 -0
- package/dist/evaluate/index.d.ts +7 -0
- package/dist/evaluate/index.d.ts.map +1 -0
- package/dist/evaluate/index.js +6 -0
- package/dist/evaluate/issue.d.ts +10 -0
- package/dist/evaluate/issue.d.ts.map +1 -0
- package/dist/evaluate/issue.js +11 -0
- package/dist/evaluate/predicate.d.ts +26 -0
- package/dist/evaluate/predicate.d.ts.map +1 -0
- package/dist/evaluate/predicate.js +37 -0
- package/dist/evaluate/shared.d.ts +59 -0
- package/dist/evaluate/shared.d.ts.map +1 -0
- package/dist/evaluate/shared.js +96 -0
- package/dist/evaluate/state.d.ts +65 -0
- package/dist/evaluate/state.d.ts.map +1 -0
- package/dist/evaluate/state.js +66 -0
- package/dist/guard/base.d.ts +72 -0
- package/dist/guard/base.d.ts.map +1 -0
- package/dist/guard/base.js +136 -0
- package/dist/guard/error.d.ts +19 -0
- package/dist/guard/error.d.ts.map +1 -0
- package/dist/guard/error.js +22 -0
- package/dist/guard/index.d.ts +10 -0
- package/dist/guard/index.d.ts.map +1 -0
- package/dist/guard/index.js +8 -0
- package/dist/guard/number.d.ts +32 -0
- package/dist/guard/number.d.ts.map +1 -0
- package/dist/guard/number.js +71 -0
- package/dist/guard/props.d.ts +18 -0
- package/dist/guard/props.d.ts.map +1 -0
- package/dist/guard/props.js +35 -0
- package/dist/guard/read.d.ts +42 -0
- package/dist/guard/read.d.ts.map +1 -0
- package/dist/guard/read.js +114 -0
- package/dist/guard/registry.d.ts +15 -0
- package/dist/guard/registry.d.ts.map +1 -0
- package/dist/guard/registry.js +21 -0
- package/dist/guard/string.d.ts +36 -0
- package/dist/guard/string.d.ts.map +1 -0
- package/dist/guard/string.js +95 -0
- package/dist/guard/types.d.ts +103 -0
- package/dist/guard/types.d.ts.map +1 -0
- package/dist/guard/types.js +5 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/internal/index.d.ts +34 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +56 -0
- package/dist/ir/builder.d.ts +173 -0
- package/dist/ir/builder.d.ts.map +1 -0
- package/dist/ir/builder.js +481 -0
- package/dist/ir/freeze.d.ts +10 -0
- package/dist/ir/freeze.d.ts.map +1 -0
- package/dist/ir/freeze.js +102 -0
- package/dist/ir/index.d.ts +9 -0
- package/dist/ir/index.d.ts.map +1 -0
- package/dist/ir/index.js +7 -0
- package/dist/ir/regexp.d.ts +6 -0
- package/dist/ir/regexp.d.ts.map +1 -0
- package/dist/ir/regexp.js +12 -0
- package/dist/ir/types.d.ts +215 -0
- package/dist/ir/types.d.ts.map +1 -0
- package/dist/ir/types.js +5 -0
- package/dist/ir/validate.d.ts +10 -0
- package/dist/ir/validate.d.ts.map +1 -0
- package/dist/ir/validate.js +271 -0
- package/dist/issue/index.d.ts +44 -0
- package/dist/issue/index.d.ts.map +1 -0
- package/dist/issue/index.js +152 -0
- package/dist/json-schema/emit-combinator.d.ts +28 -0
- package/dist/json-schema/emit-combinator.d.ts.map +1 -0
- package/dist/json-schema/emit-combinator.js +96 -0
- package/dist/json-schema/emit-composite.d.ts +28 -0
- package/dist/json-schema/emit-composite.d.ts.map +1 -0
- package/dist/json-schema/emit-composite.js +127 -0
- package/dist/json-schema/emit-scalar.d.ts +25 -0
- package/dist/json-schema/emit-scalar.d.ts.map +1 -0
- package/dist/json-schema/emit-scalar.js +104 -0
- package/dist/json-schema/emit-types.d.ts +12 -0
- package/dist/json-schema/emit-types.d.ts.map +1 -0
- package/dist/json-schema/emit-types.js +5 -0
- package/dist/json-schema/emit.d.ts +12 -0
- package/dist/json-schema/emit.d.ts.map +1 -0
- package/dist/json-schema/emit.js +62 -0
- package/dist/json-schema/freeze.d.ts +14 -0
- package/dist/json-schema/freeze.d.ts.map +1 -0
- package/dist/json-schema/freeze.js +114 -0
- package/dist/json-schema/index.d.ts +20 -0
- package/dist/json-schema/index.d.ts.map +1 -0
- package/dist/json-schema/index.js +76 -0
- package/dist/json-schema/issue.d.ts +11 -0
- package/dist/json-schema/issue.d.ts.map +1 -0
- package/dist/json-schema/issue.js +14 -0
- package/dist/json-schema/read.d.ts +29 -0
- package/dist/json-schema/read.d.ts.map +1 -0
- package/dist/json-schema/read.js +87 -0
- package/dist/json-schema/types.d.ts +106 -0
- package/dist/json-schema/types.d.ts.map +1 -0
- package/dist/json-schema/types.js +5 -0
- package/dist/kind/index.d.ts +119 -0
- package/dist/kind/index.d.ts.map +1 -0
- package/dist/kind/index.js +94 -0
- package/dist/lower/index.d.ts +7 -0
- package/dist/lower/index.d.ts.map +1 -0
- package/dist/lower/index.js +199 -0
- package/dist/message/index.d.ts +51 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/index.js +269 -0
- package/dist/optimize/compact.d.ts +10 -0
- package/dist/optimize/compact.d.ts.map +1 -0
- package/dist/optimize/compact.js +60 -0
- package/dist/optimize/fold-boolean.d.ts +15 -0
- package/dist/optimize/fold-boolean.d.ts.map +1 -0
- package/dist/optimize/fold-boolean.js +75 -0
- package/dist/optimize/fold-common.d.ts +45 -0
- package/dist/optimize/fold-common.d.ts.map +1 -0
- package/dist/optimize/fold-common.js +71 -0
- package/dist/optimize/fold-scalar.d.ts +59 -0
- package/dist/optimize/fold-scalar.d.ts.map +1 -0
- package/dist/optimize/fold-scalar.js +174 -0
- package/dist/optimize/fold.d.ts +10 -0
- package/dist/optimize/fold.d.ts.map +1 -0
- package/dist/optimize/fold.js +103 -0
- package/dist/optimize/index.d.ts +10 -0
- package/dist/optimize/index.d.ts.map +1 -0
- package/dist/optimize/index.js +23 -0
- package/dist/optimize/map-node.d.ts +21 -0
- package/dist/optimize/map-node.d.ts.map +1 -0
- package/dist/optimize/map-node.js +222 -0
- package/dist/optimize/remap.d.ts +30 -0
- package/dist/optimize/remap.d.ts.map +1 -0
- package/dist/optimize/remap.js +46 -0
- package/dist/optimize/rewrite.d.ts +22 -0
- package/dist/optimize/rewrite.d.ts.map +1 -0
- package/dist/optimize/rewrite.js +34 -0
- package/dist/plan/cache.d.ts +20 -0
- package/dist/plan/cache.d.ts.map +1 -0
- package/dist/plan/cache.js +122 -0
- package/dist/plan/index.d.ts +8 -0
- package/dist/plan/index.d.ts.map +1 -0
- package/dist/plan/index.js +6 -0
- package/dist/plan/predicate.d.ts +27 -0
- package/dist/plan/predicate.d.ts.map +1 -0
- package/dist/plan/predicate.js +415 -0
- package/dist/plan/schema-predicate.d.ts +15 -0
- package/dist/plan/schema-predicate.d.ts.map +1 -0
- package/dist/plan/schema-predicate.js +277 -0
- package/dist/plan/types.d.ts +18 -0
- package/dist/plan/types.d.ts.map +1 -0
- package/dist/plan/types.js +5 -0
- package/dist/result/index.d.ts +27 -0
- package/dist/result/index.d.ts.map +1 -0
- package/dist/result/index.js +20 -0
- package/dist/schema/common.d.ts +30 -0
- package/dist/schema/common.d.ts.map +1 -0
- package/dist/schema/common.js +102 -0
- package/dist/schema/freeze.d.ts +10 -0
- package/dist/schema/freeze.d.ts.map +1 -0
- package/dist/schema/freeze.js +163 -0
- package/dist/schema/index.d.ts +11 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +9 -0
- package/dist/schema/lazy.d.ts +10 -0
- package/dist/schema/lazy.d.ts.map +1 -0
- package/dist/schema/lazy.js +25 -0
- package/dist/schema/literal.d.ts +10 -0
- package/dist/schema/literal.d.ts.map +1 -0
- package/dist/schema/literal.js +17 -0
- package/dist/schema/types.d.ts +243 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +9 -0
- package/dist/schema/validate.d.ts +10 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +268 -0
- package/docs/api.md +301 -0
- package/docs/engine-notes.md +153 -0
- package/docs/index.html +1242 -0
- package/package.json +68 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Result } from "../result/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @brief path segment.
|
|
4
|
+
*/
|
|
5
|
+
export type PathSegment = string | number;
|
|
6
|
+
/**
|
|
7
|
+
* @brief issue code.
|
|
8
|
+
*/
|
|
9
|
+
export type IssueCode = "expected_string" | "expected_number" | "expected_bigint" | "expected_symbol" | "expected_boolean" | "expected_never" | "expected_literal" | "expected_array" | "expected_tuple" | "expected_tuple_length" | "expected_object" | "expected_record" | "expected_integer" | "expected_min_length" | "expected_max_length" | "expected_pattern" | "expected_gte" | "expected_lte" | "expected_required_key" | "expected_union" | "expected_discriminant" | "expected_refinement" | "expected_depth_limit" | "unrecognized_key";
|
|
10
|
+
/**
|
|
11
|
+
* @brief issue.
|
|
12
|
+
*/
|
|
13
|
+
export interface Issue {
|
|
14
|
+
readonly path: readonly PathSegment[];
|
|
15
|
+
readonly code: IssueCode;
|
|
16
|
+
readonly expected: string | undefined;
|
|
17
|
+
readonly actual: string | undefined;
|
|
18
|
+
readonly message: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @brief check result.
|
|
22
|
+
*/
|
|
23
|
+
export type CheckResult<TValue> = Result<TValue, readonly Issue[]>;
|
|
24
|
+
/**
|
|
25
|
+
* @brief make issue.
|
|
26
|
+
*/
|
|
27
|
+
export declare function makeIssue(path: readonly PathSegment[], code: IssueCode, expected: string | undefined, actual: string | undefined, message: string | undefined): Issue;
|
|
28
|
+
/**
|
|
29
|
+
* @brief copy issue array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function copyIssueArray(value: unknown): readonly Issue[];
|
|
32
|
+
/**
|
|
33
|
+
* @brief finalize issue array.
|
|
34
|
+
*/
|
|
35
|
+
export declare function finalizeIssueArray(value: unknown): readonly Issue[];
|
|
36
|
+
/**
|
|
37
|
+
* @brief freeze issue array.
|
|
38
|
+
*/
|
|
39
|
+
export declare function freezeIssueArray(issues: readonly Issue[]): readonly Issue[];
|
|
40
|
+
/**
|
|
41
|
+
* @brief is issue code value.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isIssueCodeValue(value: unknown): value is IssueCode;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/issue/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,GAChB,uBAAuB,GACvB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,qBAAqB,GACrB,qBAAqB,GACrB,kBAAkB,GAClB,cAAc,GACd,cAAc,GACd,uBAAuB,GACvB,gBAAgB,GAChB,uBAAuB,GACvB,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC,CAAC;AAOnE;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,SAAS,WAAW,EAAE,EAC5B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,KAAK,CAQP;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,KAAK,EAAE,CAS/D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,KAAK,EAAE,CAQnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,CAS3E;AAkDD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CA8BnE"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @brief empty issues.
|
|
3
|
+
*/
|
|
4
|
+
const EMPTY_ISSUES = Object.freeze([]);
|
|
5
|
+
/**
|
|
6
|
+
* @brief make issue.
|
|
7
|
+
*/
|
|
8
|
+
export function makeIssue(path, code, expected, actual, message) {
|
|
9
|
+
return {
|
|
10
|
+
path,
|
|
11
|
+
code,
|
|
12
|
+
expected,
|
|
13
|
+
actual,
|
|
14
|
+
message
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @brief copy issue array.
|
|
19
|
+
*/
|
|
20
|
+
export function copyIssueArray(value) {
|
|
21
|
+
if (!isUnknownArray(value)) {
|
|
22
|
+
throw new TypeError("issues must be an array");
|
|
23
|
+
}
|
|
24
|
+
const copied = new Array(value.length);
|
|
25
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
26
|
+
copied[index] = copyIssue(value[index]);
|
|
27
|
+
}
|
|
28
|
+
return freezeIssueArray(copied);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @brief finalize issue array.
|
|
32
|
+
*/
|
|
33
|
+
export function finalizeIssueArray(value) {
|
|
34
|
+
if (!isUnknownArray(value)) {
|
|
35
|
+
throw new TypeError("issues must be an array");
|
|
36
|
+
}
|
|
37
|
+
if (value.length === 0) {
|
|
38
|
+
return EMPTY_ISSUES;
|
|
39
|
+
}
|
|
40
|
+
return copyIssueArray(value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @brief freeze issue array.
|
|
44
|
+
*/
|
|
45
|
+
export function freezeIssueArray(issues) {
|
|
46
|
+
for (let index = 0; index < issues.length; index += 1) {
|
|
47
|
+
const issue = issues[index];
|
|
48
|
+
if (issue !== undefined) {
|
|
49
|
+
Object.freeze(issue.path);
|
|
50
|
+
Object.freeze(issue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Object.freeze(issues);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @brief copy issue.
|
|
57
|
+
*/
|
|
58
|
+
function copyIssue(value) {
|
|
59
|
+
if (!isRecord(value)) {
|
|
60
|
+
throw new TypeError("issue must be an object");
|
|
61
|
+
}
|
|
62
|
+
const path = copyPath(value["path"]);
|
|
63
|
+
const code = value["code"];
|
|
64
|
+
const expected = value["expected"];
|
|
65
|
+
const actual = value["actual"];
|
|
66
|
+
const message = value["message"];
|
|
67
|
+
if (!isIssueCodeValue(code)) {
|
|
68
|
+
throw new TypeError("issue code is invalid");
|
|
69
|
+
}
|
|
70
|
+
if (!isOptionalString(expected) ||
|
|
71
|
+
!isOptionalString(actual) ||
|
|
72
|
+
!isOptionalString(message)) {
|
|
73
|
+
throw new TypeError("issue text fields must be strings or undefined");
|
|
74
|
+
}
|
|
75
|
+
return makeIssue(path, code, expected, actual, message);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @brief copy path.
|
|
79
|
+
*/
|
|
80
|
+
function copyPath(value) {
|
|
81
|
+
if (!isUnknownArray(value)) {
|
|
82
|
+
throw new TypeError("issue path must be an array");
|
|
83
|
+
}
|
|
84
|
+
const copied = new Array(value.length);
|
|
85
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
86
|
+
const segment = value[index];
|
|
87
|
+
if (typeof segment === "string") {
|
|
88
|
+
copied[index] = segment;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (typeof segment === "number" &&
|
|
92
|
+
Number.isInteger(segment) &&
|
|
93
|
+
segment >= 0) {
|
|
94
|
+
copied[index] = segment;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
throw new TypeError("issue path segment must be a string or non-negative integer");
|
|
98
|
+
}
|
|
99
|
+
return copied;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @brief is issue code value.
|
|
103
|
+
*/
|
|
104
|
+
export function isIssueCodeValue(value) {
|
|
105
|
+
switch (value) {
|
|
106
|
+
case "expected_string":
|
|
107
|
+
case "expected_number":
|
|
108
|
+
case "expected_bigint":
|
|
109
|
+
case "expected_symbol":
|
|
110
|
+
case "expected_boolean":
|
|
111
|
+
case "expected_never":
|
|
112
|
+
case "expected_literal":
|
|
113
|
+
case "expected_array":
|
|
114
|
+
case "expected_tuple":
|
|
115
|
+
case "expected_tuple_length":
|
|
116
|
+
case "expected_object":
|
|
117
|
+
case "expected_record":
|
|
118
|
+
case "expected_integer":
|
|
119
|
+
case "expected_min_length":
|
|
120
|
+
case "expected_max_length":
|
|
121
|
+
case "expected_pattern":
|
|
122
|
+
case "expected_gte":
|
|
123
|
+
case "expected_lte":
|
|
124
|
+
case "expected_required_key":
|
|
125
|
+
case "expected_union":
|
|
126
|
+
case "expected_discriminant":
|
|
127
|
+
case "expected_refinement":
|
|
128
|
+
case "expected_depth_limit":
|
|
129
|
+
case "unrecognized_key":
|
|
130
|
+
return true;
|
|
131
|
+
default:
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @brief is optional string.
|
|
137
|
+
*/
|
|
138
|
+
function isOptionalString(value) {
|
|
139
|
+
return value === undefined || typeof value === "string";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @brief is record.
|
|
143
|
+
*/
|
|
144
|
+
function isRecord(value) {
|
|
145
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @brief is unknown array.
|
|
149
|
+
*/
|
|
150
|
+
function isUnknownArray(value) {
|
|
151
|
+
return Array.isArray(value);
|
|
152
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-combinator.ts
|
|
3
|
+
* @brief Combinator TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import type { PathSegment } from "../issue/index.js";
|
|
7
|
+
import type { Schema } from "../schema/index.js";
|
|
8
|
+
import type { JsonSchemaEmitter } from "./emit-types.js";
|
|
9
|
+
import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* @brief emit union.
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitUnion(options: readonly Schema[], path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @brief emit intersection.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitIntersection(left: Schema, right: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* @brief emit discriminated union.
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitDiscriminatedUnion(cases: Extract<Schema, {
|
|
22
|
+
readonly tag: typeof SchemaTag.DiscriminatedUnion;
|
|
23
|
+
}>["cases"], path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* @brief emit nullable.
|
|
26
|
+
*/
|
|
27
|
+
export declare function emitNullable(inner: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
28
|
+
//# sourceMappingURL=emit-combinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-combinator.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-combinator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAyBxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAuBxB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE;IACrB,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,kBAAkB,CAAA;CAClD,CAAC,CAAC,OAAO,CAAC,EACX,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CASxB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAiBxB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-combinator.ts
|
|
3
|
+
* @brief Combinator TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import { pushJsonSchemaIssue } from "./issue.js";
|
|
7
|
+
/**
|
|
8
|
+
* @brief emit union.
|
|
9
|
+
*/
|
|
10
|
+
export function emitUnion(options, path, issues, emitChild, dialect) {
|
|
11
|
+
const emitted = new Array(options.length);
|
|
12
|
+
let failed = false;
|
|
13
|
+
for (let index = 0; index < options.length; index += 1) {
|
|
14
|
+
const option = options[index];
|
|
15
|
+
if (option === undefined) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
path.push(index);
|
|
19
|
+
const child = emitChild(option, path, issues, dialect);
|
|
20
|
+
if (child === undefined) {
|
|
21
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Union option schema is unsupported");
|
|
22
|
+
failed = true;
|
|
23
|
+
path.pop();
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
path.pop();
|
|
27
|
+
emitted[index] = child;
|
|
28
|
+
}
|
|
29
|
+
if (failed) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
anyOf: emitted
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @brief emit intersection.
|
|
38
|
+
*/
|
|
39
|
+
export function emitIntersection(left, right, path, issues, emitChild, dialect) {
|
|
40
|
+
path.push("left");
|
|
41
|
+
const leftSchema = emitChild(left, path, issues, dialect);
|
|
42
|
+
if (leftSchema === undefined) {
|
|
43
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Intersection left schema is unsupported");
|
|
44
|
+
path.pop();
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
path.pop();
|
|
48
|
+
path.push("right");
|
|
49
|
+
const rightSchema = emitChild(right, path, issues, dialect);
|
|
50
|
+
if (rightSchema === undefined) {
|
|
51
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Intersection right schema is unsupported");
|
|
52
|
+
path.pop();
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
path.pop();
|
|
56
|
+
return {
|
|
57
|
+
allOf: [
|
|
58
|
+
leftSchema,
|
|
59
|
+
rightSchema
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @brief emit discriminated union.
|
|
65
|
+
*/
|
|
66
|
+
export function emitDiscriminatedUnion(cases, path, issues, emitChild, dialect) {
|
|
67
|
+
const options = new Array(cases.length);
|
|
68
|
+
for (let index = 0; index < cases.length; index += 1) {
|
|
69
|
+
const unionCase = cases[index];
|
|
70
|
+
if (unionCase !== undefined) {
|
|
71
|
+
options[index] = unionCase.schema;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return emitUnion(options, path, issues, emitChild, dialect);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @brief emit nullable.
|
|
78
|
+
*/
|
|
79
|
+
export function emitNullable(inner, path, issues, emitChild, dialect) {
|
|
80
|
+
path.push("nullable");
|
|
81
|
+
const emitted = emitChild(inner, path, issues, dialect);
|
|
82
|
+
if (emitted === undefined) {
|
|
83
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Nullable inner schema is unsupported");
|
|
84
|
+
path.pop();
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
path.pop();
|
|
88
|
+
return {
|
|
89
|
+
anyOf: [
|
|
90
|
+
emitted,
|
|
91
|
+
{
|
|
92
|
+
type: "null"
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-composite.ts
|
|
3
|
+
* @brief Container TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import type { PathSegment } from "../issue/index.js";
|
|
7
|
+
import type { Schema } from "../schema/index.js";
|
|
8
|
+
import type { JsonSchemaEmitter } from "./emit-types.js";
|
|
9
|
+
import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* @brief emit array.
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitArray(item: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @brief emit tuple.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitTuple(items: readonly Schema[], path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* @brief emit record.
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitRecord(value: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* @brief emit object.
|
|
24
|
+
*/
|
|
25
|
+
export declare function emitObject(schema: Extract<Schema, {
|
|
26
|
+
readonly tag: typeof SchemaTag.Object;
|
|
27
|
+
}>, path: PathSegment[], issues: JsonSchemaExportIssue[], emitChild: JsonSchemaEmitter, dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
28
|
+
//# sourceMappingURL=emit-composite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-composite.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-composite.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,SAAS,EACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAaxB;AAED;;GAEG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAqCxB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAaxB;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,SAAS,EAAE,iBAAiB,EAC5B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CAoCxB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-composite.ts
|
|
3
|
+
* @brief Container TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { ObjectModeTag, PresenceTag, SchemaTag } from "../kind/index.js";
|
|
6
|
+
import { pushJsonSchemaIssue } from "./issue.js";
|
|
7
|
+
/**
|
|
8
|
+
* @brief emit array.
|
|
9
|
+
*/
|
|
10
|
+
export function emitArray(item, path, issues, emitChild, dialect) {
|
|
11
|
+
path.push("items");
|
|
12
|
+
const emitted = emitChild(item, path, issues, dialect);
|
|
13
|
+
if (emitted === undefined) {
|
|
14
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Array item schema is unsupported");
|
|
15
|
+
path.pop();
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
path.pop();
|
|
19
|
+
return {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: emitted
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @brief emit tuple.
|
|
26
|
+
*/
|
|
27
|
+
export function emitTuple(items, path, issues, emitChild, dialect) {
|
|
28
|
+
const emitted = new Array(items.length);
|
|
29
|
+
let failed = false;
|
|
30
|
+
for (let index = 0; index < items.length; index += 1) {
|
|
31
|
+
const item = items[index];
|
|
32
|
+
if (item === undefined) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
path.push(index);
|
|
36
|
+
const child = emitChild(item, path, issues, dialect);
|
|
37
|
+
if (child === undefined) {
|
|
38
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Tuple item schema is unsupported");
|
|
39
|
+
failed = true;
|
|
40
|
+
path.pop();
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
path.pop();
|
|
44
|
+
emitted[index] = child;
|
|
45
|
+
}
|
|
46
|
+
if (failed) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (dialect === "2020-12") {
|
|
50
|
+
return {
|
|
51
|
+
type: "array",
|
|
52
|
+
prefixItems: emitted,
|
|
53
|
+
minItems: items.length,
|
|
54
|
+
maxItems: items.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: emitted,
|
|
60
|
+
additionalItems: false,
|
|
61
|
+
minItems: items.length,
|
|
62
|
+
maxItems: items.length
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @brief emit record.
|
|
67
|
+
*/
|
|
68
|
+
export function emitRecord(value, path, issues, emitChild, dialect) {
|
|
69
|
+
path.push("additionalProperties");
|
|
70
|
+
const emitted = emitChild(value, path, issues, dialect);
|
|
71
|
+
if (emitted === undefined) {
|
|
72
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Record value schema is unsupported");
|
|
73
|
+
path.pop();
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
path.pop();
|
|
77
|
+
return {
|
|
78
|
+
type: "object",
|
|
79
|
+
additionalProperties: emitted
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @brief emit object.
|
|
84
|
+
*/
|
|
85
|
+
export function emitObject(schema, path, issues, emitChild, dialect) {
|
|
86
|
+
const properties = makeJsonSchemaProperties();
|
|
87
|
+
const required = [];
|
|
88
|
+
const entries = schema.entries;
|
|
89
|
+
let failed = false;
|
|
90
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
91
|
+
const entry = entries[index];
|
|
92
|
+
if (entry === undefined) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
path.push(entry.key);
|
|
96
|
+
const emitted = emitChild(entry.schema, path, issues, dialect);
|
|
97
|
+
if (emitted === undefined) {
|
|
98
|
+
pushJsonSchemaIssue(path, issues, "unsupported_child", "Object property schema is unsupported");
|
|
99
|
+
failed = true;
|
|
100
|
+
path.pop();
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
path.pop();
|
|
104
|
+
properties[entry.key] = emitted;
|
|
105
|
+
if (entry.presence === PresenceTag.Required) {
|
|
106
|
+
required.push(entry.key);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (failed) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const result = {
|
|
113
|
+
type: "object",
|
|
114
|
+
properties,
|
|
115
|
+
additionalProperties: schema.mode !== ObjectModeTag.Strict
|
|
116
|
+
};
|
|
117
|
+
if (required.length !== 0) {
|
|
118
|
+
result.required = required;
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @brief make json schema properties.
|
|
124
|
+
*/
|
|
125
|
+
function makeJsonSchemaProperties() {
|
|
126
|
+
return Object.create(null);
|
|
127
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-scalar.ts
|
|
3
|
+
* @brief Scalar TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { SchemaTag } from "../kind/index.js";
|
|
6
|
+
import type { PathSegment } from "../issue/index.js";
|
|
7
|
+
import { type LiteralValue, type Schema } from "../schema/index.js";
|
|
8
|
+
import type { JsonSchema, JsonSchemaExportIssue } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* @brief emit string.
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitString(schema: Extract<Schema, {
|
|
13
|
+
readonly tag: typeof SchemaTag.String;
|
|
14
|
+
}>, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema;
|
|
15
|
+
/**
|
|
16
|
+
* @brief emit number.
|
|
17
|
+
*/
|
|
18
|
+
export declare function emitNumber(schema: Extract<Schema, {
|
|
19
|
+
readonly tag: typeof SchemaTag.Number;
|
|
20
|
+
}>, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* @brief emit literal.
|
|
23
|
+
*/
|
|
24
|
+
export declare function emitLiteral(value: LiteralValue, path: PathSegment[], issues: JsonSchemaExportIssue[]): JsonSchema | undefined;
|
|
25
|
+
//# sourceMappingURL=emit-scalar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-scalar.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-scalar.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAEL,SAAS,EAEV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,MAAM,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,UAAU,EACV,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,CAkCZ;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,OAAO,SAAS,CAAC,MAAM,CAAA;CAAE,CAAC,EAClE,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,GAAG,SAAS,CAiCxB;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,GAC9B,UAAU,GAAG,SAAS,CAyBxB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-scalar.ts
|
|
3
|
+
* @brief Scalar TypeSea schema to JSON Schema emitters.
|
|
4
|
+
*/
|
|
5
|
+
import { NumberCheckTag, SchemaTag, StringCheckTag } from "../kind/index.js";
|
|
6
|
+
import { UUID_PATTERN } from "../schema/index.js";
|
|
7
|
+
import { pushJsonSchemaIssue } from "./issue.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief emit string.
|
|
10
|
+
*/
|
|
11
|
+
export function emitString(schema, path, issues) {
|
|
12
|
+
const result = { type: "string" };
|
|
13
|
+
const checks = schema.checks;
|
|
14
|
+
for (let index = 0; index < checks.length; index += 1) {
|
|
15
|
+
const check = checks[index];
|
|
16
|
+
if (check === undefined) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
switch (check.tag) {
|
|
20
|
+
case StringCheckTag.Min:
|
|
21
|
+
result.minLength = check.value;
|
|
22
|
+
break;
|
|
23
|
+
case StringCheckTag.Max:
|
|
24
|
+
result.maxLength = check.value;
|
|
25
|
+
break;
|
|
26
|
+
case StringCheckTag.Regex:
|
|
27
|
+
if (check.regex.flags.length !== 0) {
|
|
28
|
+
pushJsonSchemaIssue(path, issues, "unsupported_regex_flags", "JSON Schema pattern cannot preserve RegExp flags");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
result.pattern = check.regex.source;
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case StringCheckTag.Uuid:
|
|
35
|
+
result.format = "uuid";
|
|
36
|
+
result.pattern = UUID_PATTERN.source;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @brief emit number.
|
|
44
|
+
*/
|
|
45
|
+
export function emitNumber(schema, path, issues) {
|
|
46
|
+
const before = issues.length;
|
|
47
|
+
const result = { type: "number" };
|
|
48
|
+
const checks = schema.checks;
|
|
49
|
+
for (let index = 0; index < checks.length; index += 1) {
|
|
50
|
+
const check = checks[index];
|
|
51
|
+
if (check === undefined) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
switch (check.tag) {
|
|
55
|
+
case NumberCheckTag.Integer:
|
|
56
|
+
result.type = "integer";
|
|
57
|
+
break;
|
|
58
|
+
case NumberCheckTag.Gte:
|
|
59
|
+
if (!Number.isFinite(check.value)) {
|
|
60
|
+
pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result.minimum = check.value;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case NumberCheckTag.Lte:
|
|
67
|
+
if (!Number.isFinite(check.value)) {
|
|
68
|
+
pushJsonSchemaIssue(path, issues, "unsupported_number_bound", "Number bounds must be finite");
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
result.maximum = check.value;
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (issues.length !== before) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @brief emit literal.
|
|
83
|
+
*/
|
|
84
|
+
export function emitLiteral(value, path, issues) {
|
|
85
|
+
if (value === undefined) {
|
|
86
|
+
pushJsonSchemaIssue(path, issues, "unsupported_undefined", "JSON Schema has no undefined literal");
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
if (typeof value === "bigint") {
|
|
90
|
+
pushJsonSchemaIssue(path, issues, "unsupported_bigint", "JSON Schema has no bigint literal");
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === "symbol") {
|
|
94
|
+
pushJsonSchemaIssue(path, issues, "unsupported_symbol", "JSON Schema has no symbol literal");
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "number") {
|
|
98
|
+
if (!Number.isFinite(value) || Object.is(value, -0)) {
|
|
99
|
+
pushJsonSchemaIssue(path, issues, "unsupported_number_literal", "JSON Schema number literals must be finite and cannot preserve negative zero");
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { const: value };
|
|
104
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit-types.ts
|
|
3
|
+
* @brief Internal JSON Schema emitter contracts.
|
|
4
|
+
*/
|
|
5
|
+
import type { PathSegment } from "../issue/index.js";
|
|
6
|
+
import type { Schema } from "../schema/index.js";
|
|
7
|
+
import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief json schema emitter.
|
|
10
|
+
*/
|
|
11
|
+
export type JsonSchemaEmitter = (schema: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], dialect: JsonSchemaDialect) => JsonSchema | undefined;
|
|
12
|
+
//# sourceMappingURL=emit-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-types.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,KACvB,UAAU,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file emit.ts
|
|
3
|
+
* @brief TypeSea schema to JSON Schema emitter dispatcher.
|
|
4
|
+
*/
|
|
5
|
+
import type { PathSegment } from "../issue/index.js";
|
|
6
|
+
import type { Schema } from "../schema/index.js";
|
|
7
|
+
import type { JsonSchema, JsonSchemaDialect, JsonSchemaExportIssue } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* @brief emit schema.
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitSchema(schema: Schema, path: PathSegment[], issues: JsonSchemaExportIssue[], dialect: JsonSchemaDialect): JsonSchema | undefined;
|
|
12
|
+
//# sourceMappingURL=emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../../src/json-schema/emit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAmBjD,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,EAAE,EACnB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,OAAO,EAAE,iBAAiB,GACzB,UAAU,GAAG,SAAS,CA2DxB"}
|