@atscript/typescript 0.2.11 → 0.2.12
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/index.d.ts +1 -1
- package/dist/realm-runtime.js +13 -4
- package/dist/test-utils.d.ts +1 -1
- package/dist/utils.cjs +13 -4
- package/dist/utils.d.ts +4 -3
- package/dist/utils.mjs +13 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ import { buildJsonSchema } from '@atscript/typescript/utils'
|
|
|
38
38
|
import { User } from './schema/user.as'
|
|
39
39
|
|
|
40
40
|
User.validator().validate(inputData) // throws on failure
|
|
41
|
-
const schema = buildJsonSchema(User
|
|
41
|
+
const schema = buildJsonSchema(User)
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Features
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface TStrictProfile {
|
|
|
24
24
|
* Rewrites the `allOf` the schema builder writes: a `$ref` with notes beside it (a field's
|
|
25
25
|
* title, description, key counts) → the referenced schema inlined with them; several patterns
|
|
26
26
|
* → the first one (the rest dropped) when `allOf` itself is not allowed. Any other `allOf`
|
|
27
|
-
*
|
|
27
|
+
* (an intersection) throws, whatever the profile allows.
|
|
28
28
|
*/
|
|
29
29
|
collapseAllOf: boolean;
|
|
30
30
|
/** Appends each dropped constraint to the schema's `description`, in plain words. */
|
package/dist/realm-runtime.js
CHANGED
|
@@ -4841,8 +4841,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4841
4841
|
* Anthropic strict tool use / structured outputs: objects closed, an object root (a tool's
|
|
4842
4842
|
* `input_schema`), no recursion; simple patterns kept (no lookaround, backreferences, word
|
|
4843
4843
|
* boundaries or large `{n,m}`), `minItems` only `0` / `1`; numeric bounds, string lengths,
|
|
4844
|
-
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed
|
|
4845
|
-
*
|
|
4844
|
+
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed for several patterns
|
|
4845
|
+
* only (a `$ref` with notes is collapsed; an intersection throws). Optional properties stay
|
|
4846
|
+
* optional.
|
|
4846
4847
|
*/ const ANTHROPIC_STRICT = {
|
|
4847
4848
|
name: "anthropic",
|
|
4848
4849
|
keywords: {
|
|
@@ -4917,6 +4918,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4917
4918
|
const edges = edgesOf(defs);
|
|
4918
4919
|
return [...edges.keys()].find((name) => reachable(edges.get(name), edges).has(name));
|
|
4919
4920
|
}
|
|
4921
|
+
/** Whether `key` is the only key of `item`. */ function hasOnly(item, key) {
|
|
4922
|
+
const keys = Object.keys(item);
|
|
4923
|
+
return keys.length === 1 && keys[0] === key;
|
|
4924
|
+
}
|
|
4925
|
+
/** An `allOf` the schema builder writes besides an intersection: one `$ref`, or patterns only. */ function isNoteOrPatterns(allOf) {
|
|
4926
|
+
return allOf.length === 1 && hasOnly(allOf[0], "$ref") || allOf.every((item) => hasOnly(item, "pattern"));
|
|
4927
|
+
}
|
|
4920
4928
|
/** `n` `one`(s): `1 item`, `2 items`. */ function count(n, one, many = `${one}s`) {
|
|
4921
4929
|
return `${n} ${n === 1 ? one : many}`;
|
|
4922
4930
|
}
|
|
@@ -5031,6 +5039,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5031
5039
|
};
|
|
5032
5040
|
}
|
|
5033
5041
|
const where = at || "the root";
|
|
5042
|
+
if (Array.isArray(source.allOf) && !isNoteOrPatterns(source.allOf)) fail(`an intersection (at ${where}) has no strict schema`);
|
|
5034
5043
|
if (Array.isArray(source.items)) fail(`a tuple (at ${where}) has no strict schema`);
|
|
5035
5044
|
if (source.patternProperties !== void 0) fail(`a record (at ${where}) has no strict schema; use an array of key/value objects`);
|
|
5036
5045
|
if (!part && source.type === void 0 && source.anyOf === void 0 && source.allOf === void 0 && source.$ref === void 0 && source.not === void 0 && !("const" in source) && source.enum === void 0) fail(`a value of any type (at ${where}) has no strict schema`);
|
|
@@ -5072,7 +5081,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5072
5081
|
*/ const collapse = (s, dropped, entered) => {
|
|
5073
5082
|
if (!Array.isArray(s.allOf)) return s;
|
|
5074
5083
|
const { allOf, ...rest } = s;
|
|
5075
|
-
const ref = allOf.length === 1 &&
|
|
5084
|
+
const ref = allOf.length === 1 && hasOnly(allOf[0], "$ref") ? allOf[0].$ref : void 0;
|
|
5076
5085
|
if (typeof ref === "string") {
|
|
5077
5086
|
const name = refName(ref);
|
|
5078
5087
|
const target = defs[name];
|
|
@@ -5087,7 +5096,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5087
5096
|
...rest
|
|
5088
5097
|
}, dropped, entered);
|
|
5089
5098
|
}
|
|
5090
|
-
if (!allOf.every((item) =>
|
|
5099
|
+
if (!allOf.every((item) => hasOnly(item, "pattern"))) return s;
|
|
5091
5100
|
if (profile.keywords.allOf) {
|
|
5092
5101
|
const kept = allOf.filter((item) => {
|
|
5093
5102
|
if (allowed("pattern", item.pattern)) return true;
|
package/dist/test-utils.d.ts
CHANGED
|
@@ -501,7 +501,7 @@ interface TStrictProfile {
|
|
|
501
501
|
* Rewrites the `allOf` the schema builder writes: a `$ref` with notes beside it (a field's
|
|
502
502
|
* title, description, key counts) → the referenced schema inlined with them; several patterns
|
|
503
503
|
* → the first one (the rest dropped) when `allOf` itself is not allowed. Any other `allOf`
|
|
504
|
-
*
|
|
504
|
+
* (an intersection) throws, whatever the profile allows.
|
|
505
505
|
*/
|
|
506
506
|
collapseAllOf: boolean;
|
|
507
507
|
/** Appends each dropped constraint to the schema's `description`, in plain words. */
|
package/dist/utils.cjs
CHANGED
|
@@ -828,8 +828,9 @@ function collectLeaves(items, out) {
|
|
|
828
828
|
* Anthropic strict tool use / structured outputs: objects closed, an object root (a tool's
|
|
829
829
|
* `input_schema`), no recursion; simple patterns kept (no lookaround, backreferences, word
|
|
830
830
|
* boundaries or large `{n,m}`), `minItems` only `0` / `1`; numeric bounds, string lengths,
|
|
831
|
-
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed
|
|
832
|
-
*
|
|
831
|
+
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed for several patterns
|
|
832
|
+
* only (a `$ref` with notes is collapsed; an intersection throws). Optional properties stay
|
|
833
|
+
* optional.
|
|
833
834
|
*/ const ANTHROPIC_STRICT = {
|
|
834
835
|
name: "anthropic",
|
|
835
836
|
keywords: {
|
|
@@ -904,6 +905,13 @@ function collectLeaves(items, out) {
|
|
|
904
905
|
const edges = edgesOf(defs);
|
|
905
906
|
return [...edges.keys()].find((name) => reachable(edges.get(name), edges).has(name));
|
|
906
907
|
}
|
|
908
|
+
/** Whether `key` is the only key of `item`. */ function hasOnly(item, key) {
|
|
909
|
+
const keys = Object.keys(item);
|
|
910
|
+
return keys.length === 1 && keys[0] === key;
|
|
911
|
+
}
|
|
912
|
+
/** An `allOf` the schema builder writes besides an intersection: one `$ref`, or patterns only. */ function isNoteOrPatterns(allOf) {
|
|
913
|
+
return allOf.length === 1 && hasOnly(allOf[0], "$ref") || allOf.every((item) => hasOnly(item, "pattern"));
|
|
914
|
+
}
|
|
907
915
|
/** `n` `one`(s): `1 item`, `2 items`. */ function count(n, one, many = `${one}s`) {
|
|
908
916
|
return `${n} ${n === 1 ? one : many}`;
|
|
909
917
|
}
|
|
@@ -1018,6 +1026,7 @@ function collectLeaves(items, out) {
|
|
|
1018
1026
|
};
|
|
1019
1027
|
}
|
|
1020
1028
|
const where = at || "the root";
|
|
1029
|
+
if (Array.isArray(source.allOf) && !isNoteOrPatterns(source.allOf)) fail(`an intersection (at ${where}) has no strict schema`);
|
|
1021
1030
|
if (Array.isArray(source.items)) fail(`a tuple (at ${where}) has no strict schema`);
|
|
1022
1031
|
if (source.patternProperties !== void 0) fail(`a record (at ${where}) has no strict schema; use an array of key/value objects`);
|
|
1023
1032
|
if (!part && source.type === void 0 && source.anyOf === void 0 && source.allOf === void 0 && source.$ref === void 0 && source.not === void 0 && !("const" in source) && source.enum === void 0) fail(`a value of any type (at ${where}) has no strict schema`);
|
|
@@ -1059,7 +1068,7 @@ function collectLeaves(items, out) {
|
|
|
1059
1068
|
*/ const collapse = (s, dropped, entered) => {
|
|
1060
1069
|
if (!Array.isArray(s.allOf)) return s;
|
|
1061
1070
|
const { allOf, ...rest } = s;
|
|
1062
|
-
const ref = allOf.length === 1 &&
|
|
1071
|
+
const ref = allOf.length === 1 && hasOnly(allOf[0], "$ref") ? allOf[0].$ref : void 0;
|
|
1063
1072
|
if (typeof ref === "string") {
|
|
1064
1073
|
const name = refName(ref);
|
|
1065
1074
|
const target = defs[name];
|
|
@@ -1074,7 +1083,7 @@ function collectLeaves(items, out) {
|
|
|
1074
1083
|
...rest
|
|
1075
1084
|
}, dropped, entered);
|
|
1076
1085
|
}
|
|
1077
|
-
if (!allOf.every((item) =>
|
|
1086
|
+
if (!allOf.every((item) => hasOnly(item, "pattern"))) return s;
|
|
1078
1087
|
if (profile.keywords.allOf) {
|
|
1079
1088
|
const kept = allOf.filter((item) => {
|
|
1080
1089
|
if (allowed("pattern", item.pattern)) return true;
|
package/dist/utils.d.ts
CHANGED
|
@@ -780,7 +780,7 @@ interface TStrictProfile {
|
|
|
780
780
|
* Rewrites the `allOf` the schema builder writes: a `$ref` with notes beside it (a field's
|
|
781
781
|
* title, description, key counts) → the referenced schema inlined with them; several patterns
|
|
782
782
|
* → the first one (the rest dropped) when `allOf` itself is not allowed. Any other `allOf`
|
|
783
|
-
*
|
|
783
|
+
* (an intersection) throws, whatever the profile allows.
|
|
784
784
|
*/
|
|
785
785
|
collapseAllOf: boolean;
|
|
786
786
|
/** Appends each dropped constraint to the schema's `description`, in plain words. */
|
|
@@ -801,8 +801,9 @@ declare const OPENAI_STRICT: TStrictProfile;
|
|
|
801
801
|
* Anthropic strict tool use / structured outputs: objects closed, an object root (a tool's
|
|
802
802
|
* `input_schema`), no recursion; simple patterns kept (no lookaround, backreferences, word
|
|
803
803
|
* boundaries or large `{n,m}`), `minItems` only `0` / `1`; numeric bounds, string lengths,
|
|
804
|
-
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed
|
|
805
|
-
*
|
|
804
|
+
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed for several patterns
|
|
805
|
+
* only (a `$ref` with notes is collapsed; an intersection throws). Optional properties stay
|
|
806
|
+
* optional.
|
|
806
807
|
*/
|
|
807
808
|
declare const ANTHROPIC_STRICT: TStrictProfile;
|
|
808
809
|
|
package/dist/utils.mjs
CHANGED
|
@@ -827,8 +827,9 @@ function collectLeaves(items, out) {
|
|
|
827
827
|
* Anthropic strict tool use / structured outputs: objects closed, an object root (a tool's
|
|
828
828
|
* `input_schema`), no recursion; simple patterns kept (no lookaround, backreferences, word
|
|
829
829
|
* boundaries or large `{n,m}`), `minItems` only `0` / `1`; numeric bounds, string lengths,
|
|
830
|
-
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed
|
|
831
|
-
*
|
|
830
|
+
* `maxItems`, `uniqueItems` and key counts dropped. `allOf` is allowed for several patterns
|
|
831
|
+
* only (a `$ref` with notes is collapsed; an intersection throws). Optional properties stay
|
|
832
|
+
* optional.
|
|
832
833
|
*/ const ANTHROPIC_STRICT = {
|
|
833
834
|
name: "anthropic",
|
|
834
835
|
keywords: {
|
|
@@ -903,6 +904,13 @@ function collectLeaves(items, out) {
|
|
|
903
904
|
const edges = edgesOf(defs);
|
|
904
905
|
return [...edges.keys()].find((name) => reachable(edges.get(name), edges).has(name));
|
|
905
906
|
}
|
|
907
|
+
/** Whether `key` is the only key of `item`. */ function hasOnly(item, key) {
|
|
908
|
+
const keys = Object.keys(item);
|
|
909
|
+
return keys.length === 1 && keys[0] === key;
|
|
910
|
+
}
|
|
911
|
+
/** An `allOf` the schema builder writes besides an intersection: one `$ref`, or patterns only. */ function isNoteOrPatterns(allOf) {
|
|
912
|
+
return allOf.length === 1 && hasOnly(allOf[0], "$ref") || allOf.every((item) => hasOnly(item, "pattern"));
|
|
913
|
+
}
|
|
906
914
|
/** `n` `one`(s): `1 item`, `2 items`. */ function count(n, one, many = `${one}s`) {
|
|
907
915
|
return `${n} ${n === 1 ? one : many}`;
|
|
908
916
|
}
|
|
@@ -1017,6 +1025,7 @@ function collectLeaves(items, out) {
|
|
|
1017
1025
|
};
|
|
1018
1026
|
}
|
|
1019
1027
|
const where = at || "the root";
|
|
1028
|
+
if (Array.isArray(source.allOf) && !isNoteOrPatterns(source.allOf)) fail(`an intersection (at ${where}) has no strict schema`);
|
|
1020
1029
|
if (Array.isArray(source.items)) fail(`a tuple (at ${where}) has no strict schema`);
|
|
1021
1030
|
if (source.patternProperties !== void 0) fail(`a record (at ${where}) has no strict schema; use an array of key/value objects`);
|
|
1022
1031
|
if (!part && source.type === void 0 && source.anyOf === void 0 && source.allOf === void 0 && source.$ref === void 0 && source.not === void 0 && !("const" in source) && source.enum === void 0) fail(`a value of any type (at ${where}) has no strict schema`);
|
|
@@ -1058,7 +1067,7 @@ function collectLeaves(items, out) {
|
|
|
1058
1067
|
*/ const collapse = (s, dropped, entered) => {
|
|
1059
1068
|
if (!Array.isArray(s.allOf)) return s;
|
|
1060
1069
|
const { allOf, ...rest } = s;
|
|
1061
|
-
const ref = allOf.length === 1 &&
|
|
1070
|
+
const ref = allOf.length === 1 && hasOnly(allOf[0], "$ref") ? allOf[0].$ref : void 0;
|
|
1062
1071
|
if (typeof ref === "string") {
|
|
1063
1072
|
const name = refName(ref);
|
|
1064
1073
|
const target = defs[name];
|
|
@@ -1073,7 +1082,7 @@ function collectLeaves(items, out) {
|
|
|
1073
1082
|
...rest
|
|
1074
1083
|
}, dropped, entered);
|
|
1075
1084
|
}
|
|
1076
|
-
if (!allOf.every((item) =>
|
|
1085
|
+
if (!allOf.every((item) => hasOnly(item, "pattern"))) return s;
|
|
1077
1086
|
if (profile.keywords.allOf) {
|
|
1078
1087
|
const kept = allOf.filter((item) => {
|
|
1079
1088
|
if (allowed("pattern", item.pattern)) return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/typescript",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "Atscript: typescript-gen support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"moost": "^0.7.6"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@atscript/db": "^0.1.
|
|
70
|
+
"@atscript/db": "^0.1.175",
|
|
71
71
|
"@uniqu/core": "^0.2.2",
|
|
72
72
|
"ajv": "8.20.0",
|
|
73
73
|
"vitest": "4.1.12"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@atscript/db": "^0.1.159",
|
|
77
|
-
"@atscript/core": "^0.2.
|
|
77
|
+
"@atscript/core": "^0.2.12"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@atscript/db": {
|