@nulladrift/core 0.6.2 → 0.7.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/{chunk-NDE6WVMW.js → chunk-2BZR6CAV.js} +5 -3
- package/dist/chunk-2BZR6CAV.js.map +1 -0
- package/dist/{chunk-3WQMGWBE.js → chunk-6WXMFDJM.js} +2 -2
- package/dist/diff/index.js +2 -2
- package/dist/diff/schema.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-NDE6WVMW.js.map +0 -1
- /package/dist/{chunk-3WQMGWBE.js.map → chunk-6WXMFDJM.js.map} +0 -0
|
@@ -37,8 +37,9 @@ function collectFacts(schema) {
|
|
|
37
37
|
const properties = asObject(object["properties"]);
|
|
38
38
|
if (properties) {
|
|
39
39
|
const requiredList = Array.isArray(object["required"]) ? object["required"].filter((entry) => typeof entry === "string") : [];
|
|
40
|
+
const requiredSet = new Set(requiredList);
|
|
40
41
|
for (const [name, child] of Object.entries(properties)) {
|
|
41
|
-
visit(child, path === "" ? name : `${path}.${name}`,
|
|
42
|
+
visit(child, path === "" ? name : `${path}.${name}`, requiredSet.has(name), depth + 1);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
const items = object["items"];
|
|
@@ -51,7 +52,8 @@ function collectFacts(schema) {
|
|
|
51
52
|
return facts;
|
|
52
53
|
}
|
|
53
54
|
function isSuperset(next, previous) {
|
|
54
|
-
|
|
55
|
+
const members = new Set(next);
|
|
56
|
+
return previous.every((entry) => members.has(entry));
|
|
55
57
|
}
|
|
56
58
|
function classifySchemaChange(before, after) {
|
|
57
59
|
if (stableKey(before) === stableKey(after)) return "same";
|
|
@@ -122,4 +124,4 @@ function classifySchemaChange(before, after) {
|
|
|
122
124
|
export {
|
|
123
125
|
classifySchemaChange
|
|
124
126
|
};
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
127
|
+
//# sourceMappingURL=chunk-2BZR6CAV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/diff/schema.ts"],"sourcesContent":["/**\n * Labelling a JSON Schema change as a widening or a narrowing.\n *\n * Deciding whether one schema accepts a superset of another is not tractable in general, so this\n * is a heuristic over the keywords that carry almost all real changes. It is used only to rank\n * and describe a finding: every schema change fails `check` regardless of the label. A heuristic\n * is fine for sorting a list; it would not be fine for deciding whether CI goes green.\n */\nimport { canonicalize, stableKey } from \"../lock/canonical\";\nimport { alternatives, asObject, effectiveSchema, MAX_FACTS, MAX_VISIT_DEPTH } from \"../lock/jsonschema\";\nimport type { JsonObject, JsonValue } from \"../lock/types\";\n\nexport type SchemaVerdict = \"widened\" | \"narrowed\" | \"changed\" | \"same\";\n\ninterface Facts {\n required: boolean;\n additionalProperties?: boolean;\n enumMembers?: string[];\n types?: string[];\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n}\n\nfunction numberAt(node: JsonObject, key: string): number | undefined {\n const value = node[key];\n return typeof value === \"number\" ? value : undefined;\n}\n\n/**\n * Flattens a schema into per-path facts.\n *\n * `$ref` and `allOf` are resolved before a node is read, so a schema that keeps its properties\n * in `$defs` is compared on the same terms as one that inlines them. Alternation branches get\n * their own path segment (`arg|anyOf[1]`), which makes an added branch show up as new facts --\n * a widening -- and a removed one as a narrowing, without special-casing either.\n */\nfunction collectFacts(schema: JsonValue): Map<string, Facts> {\n const facts = new Map<string, Facts>();\n\n const visit = (node: JsonValue, path: string, required: boolean, depth: number): void => {\n if (depth > MAX_VISIT_DEPTH || facts.size >= MAX_FACTS) return;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n\n const typeValue = object[\"type\"];\n const types =\n typeof typeValue === \"string\"\n ? [typeValue]\n : Array.isArray(typeValue)\n ? typeValue.filter((entry): entry is string => typeof entry === \"string\").sort()\n : undefined;\n const enumValue = object[\"enum\"];\n\n facts.set(path, {\n required,\n additionalProperties: typeof object[\"additionalProperties\"] === \"boolean\" ? object[\"additionalProperties\"] : undefined,\n enumMembers: Array.isArray(enumValue) ? enumValue.map((entry) => canonicalize(entry)).sort() : undefined,\n types,\n minimum: numberAt(object, \"minimum\"),\n maximum: numberAt(object, \"maximum\"),\n minLength: numberAt(object, \"minLength\"),\n maxLength: numberAt(object, \"maxLength\"),\n });\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n const requiredList = Array.isArray(object[\"required\"])\n ? (object[\"required\"] as JsonValue[]).filter((entry): entry is string => typeof entry === \"string\")\n : [];\n const requiredSet = new Set(requiredList);\n for (const [name, child] of Object.entries(properties)) {\n visit(child, path === \"\" ? name : `${path}.${name}`, requiredSet.has(name), depth + 1);\n }\n }\n\n const items = object[\"items\"];\n if (items !== undefined) visit(items, `${path}[]`, false, depth + 1);\n\n const prefixItems = object[\"prefixItems\"];\n if (Array.isArray(prefixItems)) prefixItems.forEach((entry, index) => visit(entry, `${path}[${index}]`, false, depth + 1));\n\n for (const branch of alternatives(object)) visit(branch.schema, `${path}|${branch.label}`, false, depth + 1);\n };\n\n visit(schema, \"\", true, 0);\n return facts;\n}\n\n/**\n * Whether every member of `previous` is in `next`. A set, not `includes` in a loop: that was\n * quadratic, and a server's own schema decides the length, so one enum of a few hundred thousand\n * members held whatever compared it -- the CLI, or a control plane serving every tenant from one\n * thread -- for minutes.\n */\nfunction isSuperset(next: readonly string[], previous: readonly string[]): boolean {\n const members = new Set(next);\n return previous.every((entry) => members.has(entry));\n}\n\nexport function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict {\n if (stableKey(before) === stableKey(after)) return \"same\";\n\n const previous = collectFacts(before);\n const next = collectFacts(after);\n\n let widened = false;\n let narrowed = false;\n\n for (const path of new Set([...previous.keys(), ...next.keys()])) {\n const a = previous.get(path);\n const b = next.get(path);\n\n // A new property is a widening even when it is optional: it enlarges what the agent may be\n // induced to send.\n if (!a && b) { widened = true; continue; }\n if (a && !b) { narrowed = true; continue; }\n if (!a || !b) continue;\n\n if (a.required && !b.required) widened = true;\n if (!a.required && b.required) narrowed = true;\n\n const beforeAdditional = a.additionalProperties ?? true;\n const afterAdditional = b.additionalProperties ?? true;\n if (!beforeAdditional && afterAdditional) widened = true;\n if (beforeAdditional && !afterAdditional) narrowed = true;\n\n if (a.enumMembers && b.enumMembers) {\n if (isSuperset(b.enumMembers, a.enumMembers) && b.enumMembers.length > a.enumMembers.length) widened = true;\n else if (isSuperset(a.enumMembers, b.enumMembers) && a.enumMembers.length > b.enumMembers.length) narrowed = true;\n else if (canonicalize(a.enumMembers) !== canonicalize(b.enumMembers)) { widened = true; narrowed = true; }\n } else if (a.enumMembers && !b.enumMembers) widened = true;\n else if (!a.enumMembers && b.enumMembers) narrowed = true;\n\n if (a.types && b.types) {\n if (isSuperset(b.types, a.types) && b.types.length > a.types.length) widened = true;\n else if (isSuperset(a.types, b.types) && a.types.length > b.types.length) narrowed = true;\n else if (canonicalize(a.types) !== canonicalize(b.types)) { widened = true; narrowed = true; }\n } else if (a.types && !b.types) widened = true;\n else if (!a.types && b.types) narrowed = true;\n\n // A bound that disappears loosens; one that appears tightens.\n const lowerBounds = [[\"minimum\", a.minimum, b.minimum] as const, [\"minLength\", a.minLength, b.minLength] as const];\n for (const [, before_, after_] of lowerBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ < before_) widened = true;\n if (after_ > before_) narrowed = true;\n }\n }\n const upperBounds = [[\"maximum\", a.maximum, b.maximum] as const, [\"maxLength\", a.maxLength, b.maxLength] as const];\n for (const [, before_, after_] of upperBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ > before_) widened = true;\n if (after_ < before_) narrowed = true;\n }\n }\n }\n\n if (widened && !narrowed) return \"widened\";\n if (narrowed && !widened) return \"narrowed\";\n // Both directions at once, or a change in a keyword this heuristic does not model.\n return \"chang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AAC,EAAE,SAAS,MAAM,KAAK,aAAa;AAC7C,UAAI,YAAY,UAAa,WAAW,OAAW,WAAU;AAAA,eACpD,YAAY,UAAa,WAAW,OAAW,YAAW;AAAA,eAC1D,YAAY,UAAa,WAAW,QAAW;AACtD,YAAI,SAAS,QAAS,WAAU;AAChC,YAAI,SAAS,QAAS,YAAW;AAAA,MACnC;AAAA,IACF;AACA,UAAM,cAAc,CAAC,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,GAAY,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,CAAU;AACjH,eAAW,CAAC,EAAE,SAAS,MAAM,KAAK,aAAa;AAC7C,UAAI,YAAY,UAAa,WAAW,OAAW,WAAU;AAAA,eACpD,YAAY,UAAa,WAAW,OAAW,YAAW;AAAA,eAC1D,YAAY,UAAa,WAAW,QAAW;AACtD,YAAI,SAAS,QAAS,WAAU;AAChC,YAAI,SAAS,QAAS,YAAW;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAEA,MAAI,WAAW,CAAC,SAAU,QAAO;AACjC,MAAI,YAAY,CAAC,QAAS,QAAO;AAEjC,SAAO;AACT;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-TBVL7XVR.js";
|
|
4
4
|
import {
|
|
5
5
|
classifySchemaChange
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2BZR6CAV.js";
|
|
7
7
|
import {
|
|
8
8
|
SEVERITY,
|
|
9
9
|
sortChanges
|
|
@@ -432,4 +432,4 @@ export {
|
|
|
432
432
|
surfaceCapabilities,
|
|
433
433
|
diffLockfiles
|
|
434
434
|
};
|
|
435
|
-
//# sourceMappingURL=chunk-
|
|
435
|
+
//# sourceMappingURL=chunk-6WXMFDJM.js.map
|
package/dist/diff/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
diffLockfiles
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-6WXMFDJM.js";
|
|
4
4
|
import "../chunk-TBVL7XVR.js";
|
|
5
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-2BZR6CAV.js";
|
|
6
6
|
import "../chunk-ALHOTOM6.js";
|
|
7
7
|
import "../chunk-JCJXSMBS.js";
|
|
8
8
|
import "../chunk-SZKRNTJP.js";
|
package/dist/diff/schema.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
stringOr,
|
|
15
15
|
surfaceCapabilities,
|
|
16
16
|
toolCapabilities
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-6WXMFDJM.js";
|
|
18
18
|
import {
|
|
19
19
|
extractHeaderParams,
|
|
20
20
|
isEscalation,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from "./chunk-TBVL7XVR.js";
|
|
26
26
|
import {
|
|
27
27
|
classifySchemaChange
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-2BZR6CAV.js";
|
|
29
29
|
import "./chunk-ALHOTOM6.js";
|
|
30
30
|
import {
|
|
31
31
|
CHANGE_KINDS,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/diff/schema.ts"],"sourcesContent":["/**\n * Labelling a JSON Schema change as a widening or a narrowing.\n *\n * Deciding whether one schema accepts a superset of another is not tractable in general, so this\n * is a heuristic over the keywords that carry almost all real changes. It is used only to rank\n * and describe a finding: every schema change fails `check` regardless of the label. A heuristic\n * is fine for sorting a list; it would not be fine for deciding whether CI goes green.\n */\nimport { canonicalize, stableKey } from \"../lock/canonical\";\nimport { alternatives, asObject, effectiveSchema, MAX_FACTS, MAX_VISIT_DEPTH } from \"../lock/jsonschema\";\nimport type { JsonObject, JsonValue } from \"../lock/types\";\n\nexport type SchemaVerdict = \"widened\" | \"narrowed\" | \"changed\" | \"same\";\n\ninterface Facts {\n required: boolean;\n additionalProperties?: boolean;\n enumMembers?: string[];\n types?: string[];\n minimum?: number;\n maximum?: number;\n minLength?: number;\n maxLength?: number;\n}\n\nfunction numberAt(node: JsonObject, key: string): number | undefined {\n const value = node[key];\n return typeof value === \"number\" ? value : undefined;\n}\n\n/**\n * Flattens a schema into per-path facts.\n *\n * `$ref` and `allOf` are resolved before a node is read, so a schema that keeps its properties\n * in `$defs` is compared on the same terms as one that inlines them. Alternation branches get\n * their own path segment (`arg|anyOf[1]`), which makes an added branch show up as new facts --\n * a widening -- and a removed one as a narrowing, without special-casing either.\n */\nfunction collectFacts(schema: JsonValue): Map<string, Facts> {\n const facts = new Map<string, Facts>();\n\n const visit = (node: JsonValue, path: string, required: boolean, depth: number): void => {\n if (depth > MAX_VISIT_DEPTH || facts.size >= MAX_FACTS) return;\n const object = effectiveSchema(node, schema);\n if (!object) return;\n\n const typeValue = object[\"type\"];\n const types =\n typeof typeValue === \"string\"\n ? [typeValue]\n : Array.isArray(typeValue)\n ? typeValue.filter((entry): entry is string => typeof entry === \"string\").sort()\n : undefined;\n const enumValue = object[\"enum\"];\n\n facts.set(path, {\n required,\n additionalProperties: typeof object[\"additionalProperties\"] === \"boolean\" ? object[\"additionalProperties\"] : undefined,\n enumMembers: Array.isArray(enumValue) ? enumValue.map((entry) => canonicalize(entry)).sort() : undefined,\n types,\n minimum: numberAt(object, \"minimum\"),\n maximum: numberAt(object, \"maximum\"),\n minLength: numberAt(object, \"minLength\"),\n maxLength: numberAt(object, \"maxLength\"),\n });\n\n const properties = asObject(object[\"properties\"]);\n if (properties) {\n const requiredList = Array.isArray(object[\"required\"])\n ? (object[\"required\"] as JsonValue[]).filter((entry): entry is string => typeof entry === \"string\")\n : [];\n for (const [name, child] of Object.entries(properties)) {\n visit(child, path === \"\" ? name : `${path}.${name}`, requiredList.includes(name), depth + 1);\n }\n }\n\n const items = object[\"items\"];\n if (items !== undefined) visit(items, `${path}[]`, false, depth + 1);\n\n const prefixItems = object[\"prefixItems\"];\n if (Array.isArray(prefixItems)) prefixItems.forEach((entry, index) => visit(entry, `${path}[${index}]`, false, depth + 1));\n\n for (const branch of alternatives(object)) visit(branch.schema, `${path}|${branch.label}`, false, depth + 1);\n };\n\n visit(schema, \"\", true, 0);\n return facts;\n}\n\nfunction isSuperset(next: readonly string[], previous: readonly string[]): boolean {\n return previous.every((entry) => next.includes(entry));\n}\n\nexport function classifySchemaChange(before: JsonValue, after: JsonValue): SchemaVerdict {\n if (stableKey(before) === stableKey(after)) return \"same\";\n\n const previous = collectFacts(before);\n const next = collectFacts(after);\n\n let widened = false;\n let narrowed = false;\n\n for (const path of new Set([...previous.keys(), ...next.keys()])) {\n const a = previous.get(path);\n const b = next.get(path);\n\n // A new property is a widening even when it is optional: it enlarges what the agent may be\n // induced to send.\n if (!a && b) { widened = true; continue; }\n if (a && !b) { narrowed = true; continue; }\n if (!a || !b) continue;\n\n if (a.required && !b.required) widened = true;\n if (!a.required && b.required) narrowed = true;\n\n const beforeAdditional = a.additionalProperties ?? true;\n const afterAdditional = b.additionalProperties ?? true;\n if (!beforeAdditional && afterAdditional) widened = true;\n if (beforeAdditional && !afterAdditional) narrowed = true;\n\n if (a.enumMembers && b.enumMembers) {\n if (isSuperset(b.enumMembers, a.enumMembers) && b.enumMembers.length > a.enumMembers.length) widened = true;\n else if (isSuperset(a.enumMembers, b.enumMembers) && a.enumMembers.length > b.enumMembers.length) narrowed = true;\n else if (canonicalize(a.enumMembers) !== canonicalize(b.enumMembers)) { widened = true; narrowed = true; }\n } else if (a.enumMembers && !b.enumMembers) widened = true;\n else if (!a.enumMembers && b.enumMembers) narrowed = true;\n\n if (a.types && b.types) {\n if (isSuperset(b.types, a.types) && b.types.length > a.types.length) widened = true;\n else if (isSuperset(a.types, b.types) && a.types.length > b.types.length) narrowed = true;\n else if (canonicalize(a.types) !== canonicalize(b.types)) { widened = true; narrowed = true; }\n } else if (a.types && !b.types) widened = true;\n else if (!a.types && b.types) narrowed = true;\n\n // A bound that disappears loosens; one that appears tightens.\n const lowerBounds = [[\"minimum\", a.minimum, b.minimum] as const, [\"minLength\", a.minLength, b.minLength] as const];\n for (const [, before_, after_] of lowerBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ < before_) widened = true;\n if (after_ > before_) narrowed = true;\n }\n }\n const upperBounds = [[\"maximum\", a.maximum, b.maximum] as const, [\"maxLength\", a.maxLength, b.maxLength] as const];\n for (const [, before_, after_] of upperBounds) {\n if (before_ !== undefined && after_ === undefined) widened = true;\n else if (before_ === undefined && after_ !== undefined) narrowed = true;\n else if (before_ !== undefined && after_ !== undefined) {\n if (after_ > before_) widened = true;\n if (after_ < before_) narrowed = true;\n }\n }\n }\n\n if (widened && !narrowed) return \"widened\";\n if (narrowed && !widened) return \"narrowed\";\n // Both directions at once, or a change in a keyword this heuristic does not model.\n return \"changed\";\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAS,SAAS,MAAkB,KAAiC;AACnE,QAAM,QAAQ,KAAK,GAAG;AACtB,SAAO,OAAO,UAAU,WAAW,QAAQ;AAC7C;AAUA,SAAS,aAAa,QAAuC;AAC3D,QAAM,QAAQ,oBAAI,IAAmB;AAErC,QAAM,QAAQ,CAAC,MAAiB,MAAc,UAAmB,UAAwB;AACvF,QAAI,QAAQ,mBAAmB,MAAM,QAAQ,UAAW;AACxD,UAAM,SAAS,gBAAgB,MAAM,MAAM;AAC3C,QAAI,CAAC,OAAQ;AAEb,UAAM,YAAY,OAAO,MAAM;AAC/B,UAAM,QACJ,OAAO,cAAc,WACjB,CAAC,SAAS,IACV,MAAM,QAAQ,SAAS,IACrB,UAAU,OAAO,CAAC,UAA2B,OAAO,UAAU,QAAQ,EAAE,KAAK,IAC7E;AACR,UAAM,YAAY,OAAO,MAAM;AAE/B,UAAM,IAAI,MAAM;AAAA,MACd;AAAA,MACA,sBAAsB,OAAO,OAAO,sBAAsB,MAAM,YAAY,OAAO,sBAAsB,IAAI;AAAA,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