@orkestrel/contract 0.0.10 → 0.0.11
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/src/core/index.cjs +61 -17
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +51 -10
- package/dist/src/core/index.d.ts +51 -10
- package/dist/src/core/index.js +61 -18
- package/dist/src/core/index.js.map +1 -1
- package/package.json +2 -2
package/dist/src/core/index.cjs
CHANGED
|
@@ -363,14 +363,21 @@ var CLONE_NODE_LIMIT = 262144;
|
|
|
363
363
|
*/
|
|
364
364
|
var GENERATION_ATTEMPT_LIMIT = 32;
|
|
365
365
|
/**
|
|
366
|
-
* The
|
|
367
|
-
* frozen.
|
|
366
|
+
* The maximum object/array nesting depth {@link valueToSchema} walks, frozen.
|
|
368
367
|
*
|
|
369
368
|
* @remarks
|
|
370
369
|
* Bounds inference against adversarial or cyclic runtime input — once the
|
|
371
370
|
* remaining depth budget reaches zero, inference stops descending and emits
|
|
372
371
|
* the empty accept-anything schema `{}` for that branch instead of recursing
|
|
373
|
-
* further.
|
|
372
|
+
* further. LOWERABLE per call via {@link ValueToSchemaOptions.maxDepth}; a
|
|
373
|
+
* higher value is held here.
|
|
374
|
+
*
|
|
375
|
+
* A ceiling rather than a default, because the walk recurses: what a deeper
|
|
376
|
+
* walk spends is the JavaScript call stack rather than this budget, and that
|
|
377
|
+
* stack is not a fixed quantity. The survivable depth measured on one host rose
|
|
378
|
+
* across repeated calls within a single process as the engine optimized, and
|
|
379
|
+
* fell to roughly this number under a reduced stack size. Any larger constant
|
|
380
|
+
* therefore has a host where it fails, which is why none is published.
|
|
374
381
|
*/
|
|
375
382
|
var INFER_DEPTH_LIMIT = 32;
|
|
376
383
|
/**
|
|
@@ -3004,6 +3011,35 @@ function sanitizeBudget(value, fallback) {
|
|
|
3004
3011
|
}, "sanitizeBudget");
|
|
3005
3012
|
}
|
|
3006
3013
|
/**
|
|
3014
|
+
* Resolve a caller's depth budget to one the traversal can actually survive.
|
|
3015
|
+
*
|
|
3016
|
+
* @remarks
|
|
3017
|
+
* {@link sanitizeBudget} decides the SHAPE of a budget and deliberately lets any
|
|
3018
|
+
* finite non-negative integer through, because it must never read a fallback a
|
|
3019
|
+
* hostile caller supplied. That left the depth axis unbounded from above, and
|
|
3020
|
+
* depth is the axis that recurses: `1e9` is a valid integer, so the walk descended
|
|
3021
|
+
* until the call STACK failed, at a depth that varied between runs, and the
|
|
3022
|
+
* refusal surfaced as an unreadable value rather than as the exhaustion the guard
|
|
3023
|
+
* promises. Breadth needs no such ceiling — its loop is already bounded by the
|
|
3024
|
+
* entries actually present.
|
|
3025
|
+
*
|
|
3026
|
+
* So {@link INFER_DEPTH_LIMIT} is the ceiling as well as the default, and
|
|
3027
|
+
* `maxDepth` narrows the walk rather than widening it. One bound, and the same
|
|
3028
|
+
* answer on every host.
|
|
3029
|
+
*
|
|
3030
|
+
* @param value - The candidate depth budget
|
|
3031
|
+
* @returns A finite non-negative integer no greater than `INFER_DEPTH_LIMIT`
|
|
3032
|
+
*
|
|
3033
|
+
* @example
|
|
3034
|
+
* ```ts
|
|
3035
|
+
* sanitizeDepth(4) // 4
|
|
3036
|
+
* sanitizeDepth(1e9) // 32
|
|
3037
|
+
* ```
|
|
3038
|
+
*/
|
|
3039
|
+
function sanitizeDepth(value) {
|
|
3040
|
+
return INTRINSICS.min(sanitizeBudget(value, 32), 32);
|
|
3041
|
+
}
|
|
3042
|
+
/**
|
|
3007
3043
|
* Render a short, safe, TOTAL preview of an unknown value for a {@link Fault}'s
|
|
3008
3044
|
* `received` field.
|
|
3009
3045
|
*
|
|
@@ -8820,7 +8856,7 @@ function inferValue(value, depth, breadth, closed, format, visited, memo) {
|
|
|
8820
8856
|
*/
|
|
8821
8857
|
function inferArray(value, depth, breadth, closed, format, visited, memo) {
|
|
8822
8858
|
return contain(() => {
|
|
8823
|
-
const maxDepth =
|
|
8859
|
+
const maxDepth = sanitizeDepth(depth);
|
|
8824
8860
|
const maxBreadth = sanitizeBudget(breadth, 256);
|
|
8825
8861
|
return readValue(() => {
|
|
8826
8862
|
if (!(maxDepth > 0) || matchesVisited(visited, value)) return {};
|
|
@@ -8901,9 +8937,10 @@ function inferArray(value, depth, breadth, closed, format, visited, memo) {
|
|
|
8901
8937
|
function inferObject(value, depth, breadth, closed, format, visited, memo) {
|
|
8902
8938
|
return contain(() => {
|
|
8903
8939
|
const maxBreadth = sanitizeBudget(breadth, 256);
|
|
8940
|
+
const maxDepth = sanitizeDepth(depth);
|
|
8904
8941
|
return readValue(() => {
|
|
8905
|
-
if (!(
|
|
8906
|
-
const cached = INTRINSICS.apply(INTRINSICS.recall, memo, [value])?.get(
|
|
8942
|
+
if (!(maxDepth > 0) || matchesVisited(visited, value)) return {};
|
|
8943
|
+
const cached = INTRINSICS.apply(INTRINSICS.recall, memo, [value])?.get(maxDepth);
|
|
8907
8944
|
if (cached) return cached;
|
|
8908
8945
|
admitVisited(visited, value);
|
|
8909
8946
|
const outcome = attempt(() => {
|
|
@@ -8923,7 +8960,7 @@ function inferObject(value, depth, breadth, closed, format, visited, memo) {
|
|
|
8923
8960
|
dropped = true;
|
|
8924
8961
|
continue;
|
|
8925
8962
|
}
|
|
8926
|
-
properties[key] = inferValue(propertyValue,
|
|
8963
|
+
properties[key] = inferValue(propertyValue, maxDepth - 1, maxBreadth, closed, format, visited, memo);
|
|
8927
8964
|
required[required.length] = key;
|
|
8928
8965
|
}
|
|
8929
8966
|
return {
|
|
@@ -8943,7 +8980,7 @@ function inferObject(value, depth, breadth, closed, format, visited, memo) {
|
|
|
8943
8980
|
...required.length > 0 ? { required } : {},
|
|
8944
8981
|
additionalProperties: partial ? true : !closed
|
|
8945
8982
|
};
|
|
8946
|
-
retainDepth(memo, value,
|
|
8983
|
+
retainDepth(memo, value, maxDepth, schema);
|
|
8947
8984
|
return schema;
|
|
8948
8985
|
}, "inferObject");
|
|
8949
8986
|
}, "inferObject");
|
|
@@ -8966,11 +9003,16 @@ function inferObject(value, depth, breadth, closed, format, visited, memo) {
|
|
|
8966
9003
|
* expect an object-shaped `inputSchema`; wrap a non-object payload with
|
|
8967
9004
|
* {@link schemaToObject} before advertising it as a tool's parameters.
|
|
8968
9005
|
*
|
|
8969
|
-
* `
|
|
8970
|
-
*
|
|
8971
|
-
*
|
|
8972
|
-
*
|
|
8973
|
-
*
|
|
9006
|
+
* `maxProperties` is sanitized via {@link sanitizeBudget} to a finite
|
|
9007
|
+
* non-negative integer, falling back to {@link INFER_BREADTH_LIMIT} for anything
|
|
9008
|
+
* else (`NaN`, `Infinity`, negative, fractional), so a malformed breadth cannot
|
|
9009
|
+
* corrupt the sampled key/element list.
|
|
9010
|
+
*
|
|
9011
|
+
* `maxDepth` goes through {@link sanitizeDepth}, which does the same and then caps
|
|
9012
|
+
* at {@link INFER_DEPTH_LIMIT}, so the option NARROWS the walk and cannot widen
|
|
9013
|
+
* it. The cap is what makes the depth guard unbreakable: depth is the recursing
|
|
9014
|
+
* axis, and a large-but-valid budget used to descend until the call STACK failed
|
|
9015
|
+
* rather than until the guard said stop.
|
|
8974
9016
|
*
|
|
8975
9017
|
* @param value - The value to infer a schema from
|
|
8976
9018
|
* @param options - Optional `maxDepth` / `maxProperties` / `closed` / `format` bounds
|
|
@@ -8994,7 +9036,7 @@ function valueToSchema(value, options) {
|
|
|
8994
9036
|
"format",
|
|
8995
9037
|
"enum"
|
|
8996
9038
|
], "valueToSchema", "schema");
|
|
8997
|
-
const maxDepth =
|
|
9039
|
+
const maxDepth = sanitizeDepth(optionsSnapshot?.maxDepth);
|
|
8998
9040
|
const maxProperties = sanitizeBudget(optionsSnapshot?.maxProperties, 256);
|
|
8999
9041
|
const closed = optionsSnapshot?.closed ?? true;
|
|
9000
9042
|
const format = optionsSnapshot?.format ?? false;
|
|
@@ -9230,8 +9272,9 @@ function inferRecordSamples(samples, depth, breadth, closed, format, enumOn, mem
|
|
|
9230
9272
|
* and `enum` (both default `false`) opt a low-cardinality/unanimous-format
|
|
9231
9273
|
* slot into the corresponding keyword — see {@link inferSamples} for the
|
|
9232
9274
|
* precedence and the multi-sample format-disabling seam. `maxDepth` /
|
|
9233
|
-
* `maxProperties` are
|
|
9234
|
-
* {@link
|
|
9275
|
+
* `maxProperties` are resolved exactly as {@link valueToSchema} resolves them —
|
|
9276
|
+
* breadth through {@link sanitizeBudget}, depth through {@link sanitizeDepth},
|
|
9277
|
+
* which also caps at {@link INFER_DEPTH_LIMIT}; see there for why.
|
|
9235
9278
|
*
|
|
9236
9279
|
* @param samples - The example values to infer a schema from
|
|
9237
9280
|
* @param options - Optional `maxDepth` / `maxProperties` / `closed` / `format` / `enum` bounds
|
|
@@ -9255,7 +9298,7 @@ function samplesToSchema(samples, options) {
|
|
|
9255
9298
|
"format",
|
|
9256
9299
|
"enum"
|
|
9257
9300
|
], "samplesToSchema", "schema");
|
|
9258
|
-
const maxDepth =
|
|
9301
|
+
const maxDepth = sanitizeDepth(optionsSnapshot?.maxDepth);
|
|
9259
9302
|
const maxProperties = sanitizeBudget(optionsSnapshot?.maxProperties, 256);
|
|
9260
9303
|
const closed = optionsSnapshot?.closed ?? true;
|
|
9261
9304
|
const format = optionsSnapshot?.format ?? false;
|
|
@@ -10512,6 +10555,7 @@ exports.retainDepth = retainDepth;
|
|
|
10512
10555
|
exports.samplesToFormat = samplesToFormat;
|
|
10513
10556
|
exports.samplesToSchema = samplesToSchema;
|
|
10514
10557
|
exports.sanitizeBudget = sanitizeBudget;
|
|
10558
|
+
exports.sanitizeDepth = sanitizeDepth;
|
|
10515
10559
|
exports.schemaNodeToShape = schemaNodeToShape;
|
|
10516
10560
|
exports.schemaToObject = schemaToObject;
|
|
10517
10561
|
exports.schemaToParameters = schemaToParameters;
|