@orkestrel/contract 0.0.8 → 0.0.9
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 +217 -0
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +70 -6
- package/dist/src/core/index.d.ts +70 -6
- package/dist/src/core/index.js +216 -1
- package/dist/src/core/index.js.map +1 -1
- package/package.json +4 -3
|
@@ -348,6 +348,54 @@ export declare function canonicalizeValue(value: unknown, ancestors: WeakSet<obj
|
|
|
348
348
|
*/
|
|
349
349
|
export declare function canonicalStringify(value: unknown): string | undefined;
|
|
350
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Deep-clone an exact JSON object record into an owned frozen snapshot.
|
|
353
|
+
*
|
|
354
|
+
* @remarks
|
|
355
|
+
* Adds a record-root boundary to {@link cloneJSONValue}. The output is a
|
|
356
|
+
* deeply frozen null-prototype record, and repeated noncyclic aliases are
|
|
357
|
+
* duplicated as independent JSON tree branches.
|
|
358
|
+
*
|
|
359
|
+
* @param value - The unknown record value to validate and snapshot
|
|
360
|
+
* @returns A deeply cloned and frozen JSON record
|
|
361
|
+
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal fails
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* cloneJSONRecord({ attempt: 1 }) // frozen null-prototype record
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
export declare function cloneJSONRecord(value: unknown): JSONRecord;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Deep-clone exact JSON data into an owned frozen snapshot.
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* Traverses iteratively so deeply nested input cannot exhaust the call stack.
|
|
375
|
+
* Repeated noncyclic aliases are duplicated because JSON persistence represents
|
|
376
|
+
* a tree, while a structural back-edge on the active path is rejected as a
|
|
377
|
+
* cycle. Arrays are rebuilt as standard dense arrays and records as
|
|
378
|
+
* null-prototype objects; every produced node is frozen after its children are
|
|
379
|
+
* wired. Array keys must be exactly `length` plus every canonical index.
|
|
380
|
+
* Writable and configurable index flags are normalized rather than treated as
|
|
381
|
+
* JSON data, so frozen arrays remain valid. Property descriptors are inspected
|
|
382
|
+
* without reading values through accessors, and every hostile reflective
|
|
383
|
+
* operation is contained before a new clone-coded error is exposed.
|
|
384
|
+
*
|
|
385
|
+
* @param value - The unknown value to validate and snapshot
|
|
386
|
+
* @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
|
|
387
|
+
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const source = { settings: { enabled: true } }
|
|
392
|
+
* const clone = cloneJSONValue(source)
|
|
393
|
+
* source.settings.enabled = false
|
|
394
|
+
* clone // { settings: { enabled: true } }
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export declare function cloneJSONValue(value: unknown): JSONValue;
|
|
398
|
+
|
|
351
399
|
/**
|
|
352
400
|
* Deep-clone a JSON Schema graph into an owned frozen snapshot.
|
|
353
401
|
*
|
|
@@ -2322,12 +2370,30 @@ export declare const JSON_SCHEMA_TYPES: readonly JSONSchemaType[];
|
|
|
2322
2370
|
*
|
|
2323
2371
|
* @remarks
|
|
2324
2372
|
* The recursive {@link JSONValue} tree type is shipped for consumers that need a
|
|
2325
|
-
* reusable JSON metadata contract.
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2373
|
+
* reusable JSON metadata contract. {@link JSONRecord} supplies the record-root
|
|
2374
|
+
* contract needed by persistence and metadata consumers; a dedicated
|
|
2375
|
+
* `JSONArray` alias remains unnecessary because `readonly JSONValue[]` already
|
|
2376
|
+
* expresses that branch directly.
|
|
2328
2377
|
*/
|
|
2329
2378
|
export declare type JSONPrimitive = string | number | boolean | null;
|
|
2330
2379
|
|
|
2380
|
+
/**
|
|
2381
|
+
* A readonly string-keyed JSON object record.
|
|
2382
|
+
*
|
|
2383
|
+
* @remarks
|
|
2384
|
+
* Runtime ownership through
|
|
2385
|
+
* {@link import('./cloners.js').cloneJSONRecord} normalizes records to a frozen
|
|
2386
|
+
* null-prototype object after exact descriptor validation.
|
|
2387
|
+
*
|
|
2388
|
+
* @example
|
|
2389
|
+
* ```ts
|
|
2390
|
+
* const metadata: JSONRecord = { attempt: 1, labels: ['ready'] }
|
|
2391
|
+
* ```
|
|
2392
|
+
*/
|
|
2393
|
+
export declare type JSONRecord = {
|
|
2394
|
+
readonly [key: string]: JSONValue;
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2331
2397
|
/**
|
|
2332
2398
|
* A JSON Schema fragment — the subset of keywords the contract compiler emits
|
|
2333
2399
|
* and {@link RawShape} embeds.
|
|
@@ -2416,9 +2482,7 @@ export declare interface JSONShapeOptions {
|
|
|
2416
2482
|
* const value: JSONValue = { nested: [1, 'x', null] }
|
|
2417
2483
|
* ```
|
|
2418
2484
|
*/
|
|
2419
|
-
export declare type JSONValue = JSONPrimitive | readonly JSONValue[] |
|
|
2420
|
-
readonly [key: string]: JSONValue;
|
|
2421
|
-
};
|
|
2485
|
+
export declare type JSONValue = JSONPrimitive | readonly JSONValue[] | JSONRecord;
|
|
2422
2486
|
|
|
2423
2487
|
/**
|
|
2424
2488
|
* Build a guard that accepts values that are own keys of the provided object.
|
package/dist/src/core/index.d.ts
CHANGED
|
@@ -348,6 +348,54 @@ export declare function canonicalizeValue(value: unknown, ancestors: WeakSet<obj
|
|
|
348
348
|
*/
|
|
349
349
|
export declare function canonicalStringify(value: unknown): string | undefined;
|
|
350
350
|
|
|
351
|
+
/**
|
|
352
|
+
* Deep-clone an exact JSON object record into an owned frozen snapshot.
|
|
353
|
+
*
|
|
354
|
+
* @remarks
|
|
355
|
+
* Adds a record-root boundary to {@link cloneJSONValue}. The output is a
|
|
356
|
+
* deeply frozen null-prototype record, and repeated noncyclic aliases are
|
|
357
|
+
* duplicated as independent JSON tree branches.
|
|
358
|
+
*
|
|
359
|
+
* @param value - The unknown record value to validate and snapshot
|
|
360
|
+
* @returns A deeply cloned and frozen JSON record
|
|
361
|
+
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal fails
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* cloneJSONRecord({ attempt: 1 }) // frozen null-prototype record
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
export declare function cloneJSONRecord(value: unknown): JSONRecord;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Deep-clone exact JSON data into an owned frozen snapshot.
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* Traverses iteratively so deeply nested input cannot exhaust the call stack.
|
|
375
|
+
* Repeated noncyclic aliases are duplicated because JSON persistence represents
|
|
376
|
+
* a tree, while a structural back-edge on the active path is rejected as a
|
|
377
|
+
* cycle. Arrays are rebuilt as standard dense arrays and records as
|
|
378
|
+
* null-prototype objects; every produced node is frozen after its children are
|
|
379
|
+
* wired. Array keys must be exactly `length` plus every canonical index.
|
|
380
|
+
* Writable and configurable index flags are normalized rather than treated as
|
|
381
|
+
* JSON data, so frozen arrays remain valid. Property descriptors are inspected
|
|
382
|
+
* without reading values through accessors, and every hostile reflective
|
|
383
|
+
* operation is contained before a new clone-coded error is exposed.
|
|
384
|
+
*
|
|
385
|
+
* @param value - The unknown value to validate and snapshot
|
|
386
|
+
* @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
|
|
387
|
+
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const source = { settings: { enabled: true } }
|
|
392
|
+
* const clone = cloneJSONValue(source)
|
|
393
|
+
* source.settings.enabled = false
|
|
394
|
+
* clone // { settings: { enabled: true } }
|
|
395
|
+
* ```
|
|
396
|
+
*/
|
|
397
|
+
export declare function cloneJSONValue(value: unknown): JSONValue;
|
|
398
|
+
|
|
351
399
|
/**
|
|
352
400
|
* Deep-clone a JSON Schema graph into an owned frozen snapshot.
|
|
353
401
|
*
|
|
@@ -2322,12 +2370,30 @@ export declare const JSON_SCHEMA_TYPES: readonly JSONSchemaType[];
|
|
|
2322
2370
|
*
|
|
2323
2371
|
* @remarks
|
|
2324
2372
|
* The recursive {@link JSONValue} tree type is shipped for consumers that need a
|
|
2325
|
-
* reusable JSON metadata contract.
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2373
|
+
* reusable JSON metadata contract. {@link JSONRecord} supplies the record-root
|
|
2374
|
+
* contract needed by persistence and metadata consumers; a dedicated
|
|
2375
|
+
* `JSONArray` alias remains unnecessary because `readonly JSONValue[]` already
|
|
2376
|
+
* expresses that branch directly.
|
|
2328
2377
|
*/
|
|
2329
2378
|
export declare type JSONPrimitive = string | number | boolean | null;
|
|
2330
2379
|
|
|
2380
|
+
/**
|
|
2381
|
+
* A readonly string-keyed JSON object record.
|
|
2382
|
+
*
|
|
2383
|
+
* @remarks
|
|
2384
|
+
* Runtime ownership through
|
|
2385
|
+
* {@link import('./cloners.js').cloneJSONRecord} normalizes records to a frozen
|
|
2386
|
+
* null-prototype object after exact descriptor validation.
|
|
2387
|
+
*
|
|
2388
|
+
* @example
|
|
2389
|
+
* ```ts
|
|
2390
|
+
* const metadata: JSONRecord = { attempt: 1, labels: ['ready'] }
|
|
2391
|
+
* ```
|
|
2392
|
+
*/
|
|
2393
|
+
export declare type JSONRecord = {
|
|
2394
|
+
readonly [key: string]: JSONValue;
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2331
2397
|
/**
|
|
2332
2398
|
* A JSON Schema fragment — the subset of keywords the contract compiler emits
|
|
2333
2399
|
* and {@link RawShape} embeds.
|
|
@@ -2416,9 +2482,7 @@ export declare interface JSONShapeOptions {
|
|
|
2416
2482
|
* const value: JSONValue = { nested: [1, 'x', null] }
|
|
2417
2483
|
* ```
|
|
2418
2484
|
*/
|
|
2419
|
-
export declare type JSONValue = JSONPrimitive | readonly JSONValue[] |
|
|
2420
|
-
readonly [key: string]: JSONValue;
|
|
2421
|
-
};
|
|
2485
|
+
export declare type JSONValue = JSONPrimitive | readonly JSONValue[] | JSONRecord;
|
|
2422
2486
|
|
|
2423
2487
|
/**
|
|
2424
2488
|
* Build a guard that accepts values that are own keys of the provided object.
|
package/dist/src/core/index.js
CHANGED
|
@@ -1474,6 +1474,221 @@ function shapeToKind(shape) {
|
|
|
1474
1474
|
//#endregion
|
|
1475
1475
|
//#region src/core/cloners.ts
|
|
1476
1476
|
/**
|
|
1477
|
+
* Deep-clone exact JSON data into an owned frozen snapshot.
|
|
1478
|
+
*
|
|
1479
|
+
* @remarks
|
|
1480
|
+
* Traverses iteratively so deeply nested input cannot exhaust the call stack.
|
|
1481
|
+
* Repeated noncyclic aliases are duplicated because JSON persistence represents
|
|
1482
|
+
* a tree, while a structural back-edge on the active path is rejected as a
|
|
1483
|
+
* cycle. Arrays are rebuilt as standard dense arrays and records as
|
|
1484
|
+
* null-prototype objects; every produced node is frozen after its children are
|
|
1485
|
+
* wired. Array keys must be exactly `length` plus every canonical index.
|
|
1486
|
+
* Writable and configurable index flags are normalized rather than treated as
|
|
1487
|
+
* JSON data, so frozen arrays remain valid. Property descriptors are inspected
|
|
1488
|
+
* without reading values through accessors, and every hostile reflective
|
|
1489
|
+
* operation is contained before a new clone-coded error is exposed.
|
|
1490
|
+
*
|
|
1491
|
+
* @param value - The unknown value to validate and snapshot
|
|
1492
|
+
* @returns The primitive unchanged, or a deeply cloned and frozen JSON graph
|
|
1493
|
+
* @throws {ContractError} When the value is not exact acyclic JSON data or traversal fails
|
|
1494
|
+
*
|
|
1495
|
+
* @example
|
|
1496
|
+
* ```ts
|
|
1497
|
+
* const source = { settings: { enabled: true } }
|
|
1498
|
+
* const clone = cloneJSONValue(source)
|
|
1499
|
+
* source.settings.enabled = false
|
|
1500
|
+
* clone // { settings: { enabled: true } }
|
|
1501
|
+
* ```
|
|
1502
|
+
*/
|
|
1503
|
+
function cloneJSONValue(value) {
|
|
1504
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
1505
|
+
if (typeof value === "number") {
|
|
1506
|
+
if (Number.isFinite(value)) return value;
|
|
1507
|
+
throw new ContractError("cloneJSONValue: number is not finite", {
|
|
1508
|
+
code: "clone",
|
|
1509
|
+
context: { shape: "json" }
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1512
|
+
if (typeof value !== "object") throw new ContractError("cloneJSONValue: value is not JSON data", {
|
|
1513
|
+
code: "clone",
|
|
1514
|
+
context: { shape: "json" }
|
|
1515
|
+
});
|
|
1516
|
+
const arrayOutcome = attempt(() => Array.isArray(value));
|
|
1517
|
+
if (!arrayOutcome.success) throw new ContractError("cloneJSONValue: value brand could not be inspected", {
|
|
1518
|
+
code: "clone",
|
|
1519
|
+
context: { shape: "json" }
|
|
1520
|
+
});
|
|
1521
|
+
let root;
|
|
1522
|
+
if (arrayOutcome.value) root = [];
|
|
1523
|
+
else if (isRecord(value)) root = Object.create(null);
|
|
1524
|
+
else throw new ContractError("cloneJSONValue: object is not a plain record", {
|
|
1525
|
+
code: "clone",
|
|
1526
|
+
context: { shape: "json" }
|
|
1527
|
+
});
|
|
1528
|
+
const active = /* @__PURE__ */ new WeakSet();
|
|
1529
|
+
active.add(value);
|
|
1530
|
+
const pending = [{
|
|
1531
|
+
source: value,
|
|
1532
|
+
clone: root,
|
|
1533
|
+
array: arrayOutcome.value,
|
|
1534
|
+
entries: void 0,
|
|
1535
|
+
index: 0
|
|
1536
|
+
}];
|
|
1537
|
+
while (pending.length > 0) {
|
|
1538
|
+
const frame = pending[pending.length - 1];
|
|
1539
|
+
if (frame === void 0) continue;
|
|
1540
|
+
if (frame.entries === void 0) {
|
|
1541
|
+
const keysOutcome = attempt(() => Reflect.ownKeys(frame.source));
|
|
1542
|
+
if (!keysOutcome.success) throw new ContractError("cloneJSONValue: own keys could not be inspected", {
|
|
1543
|
+
code: "clone",
|
|
1544
|
+
context: { shape: "json" }
|
|
1545
|
+
});
|
|
1546
|
+
const keys = keysOutcome.value;
|
|
1547
|
+
const entries = [];
|
|
1548
|
+
if (frame.array) {
|
|
1549
|
+
const lengthOutcome = attempt(() => Reflect.getOwnPropertyDescriptor(frame.source, "length"));
|
|
1550
|
+
if (!lengthOutcome.success) throw new ContractError("cloneJSONValue: array length could not be inspected", {
|
|
1551
|
+
code: "clone",
|
|
1552
|
+
context: { shape: "json" }
|
|
1553
|
+
});
|
|
1554
|
+
const lengthDescriptor = lengthOutcome.value;
|
|
1555
|
+
if (lengthDescriptor === void 0 || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number" || !Number.isInteger(lengthDescriptor.value) || lengthDescriptor.value < 0 || lengthDescriptor.value > 4294967295 || lengthDescriptor.enumerable !== false || lengthDescriptor.configurable !== false) throw new ContractError("cloneJSONValue: array is not intrinsic and dense", {
|
|
1556
|
+
code: "clone",
|
|
1557
|
+
context: { shape: "json" }
|
|
1558
|
+
});
|
|
1559
|
+
const remaining = new Set(keys);
|
|
1560
|
+
if (!remaining.delete("length")) throw new ContractError("cloneJSONValue: array own keys are not exact", {
|
|
1561
|
+
code: "clone",
|
|
1562
|
+
context: { shape: "json" }
|
|
1563
|
+
});
|
|
1564
|
+
for (let index = 0; index < lengthDescriptor.value; index += 1) {
|
|
1565
|
+
const key = String(index);
|
|
1566
|
+
if (!remaining.delete(key)) throw new ContractError("cloneJSONValue: array own keys are not exact", {
|
|
1567
|
+
code: "clone",
|
|
1568
|
+
context: { shape: "json" }
|
|
1569
|
+
});
|
|
1570
|
+
const descriptorOutcome = attempt(() => Reflect.getOwnPropertyDescriptor(frame.source, key));
|
|
1571
|
+
if (!descriptorOutcome.success) throw new ContractError("cloneJSONValue: array index could not be inspected", {
|
|
1572
|
+
code: "clone",
|
|
1573
|
+
context: { shape: "json" }
|
|
1574
|
+
});
|
|
1575
|
+
const descriptor = descriptorOutcome.value;
|
|
1576
|
+
if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) throw new ContractError("cloneJSONValue: array index is not enumerable data", {
|
|
1577
|
+
code: "clone",
|
|
1578
|
+
context: { shape: "json" }
|
|
1579
|
+
});
|
|
1580
|
+
entries.push([key, descriptor.value]);
|
|
1581
|
+
}
|
|
1582
|
+
if (remaining.size !== 0) throw new ContractError("cloneJSONValue: array own keys are not exact", {
|
|
1583
|
+
code: "clone",
|
|
1584
|
+
context: { shape: "json" }
|
|
1585
|
+
});
|
|
1586
|
+
} else for (const key of keys) {
|
|
1587
|
+
if (typeof key !== "string") throw new ContractError("cloneJSONValue: record has a symbol property", {
|
|
1588
|
+
code: "clone",
|
|
1589
|
+
context: { shape: "json" }
|
|
1590
|
+
});
|
|
1591
|
+
const descriptorOutcome = attempt(() => Reflect.getOwnPropertyDescriptor(frame.source, key));
|
|
1592
|
+
if (!descriptorOutcome.success) throw new ContractError("cloneJSONValue: record property could not be inspected", {
|
|
1593
|
+
code: "clone",
|
|
1594
|
+
context: { shape: "json" }
|
|
1595
|
+
});
|
|
1596
|
+
const descriptor = descriptorOutcome.value;
|
|
1597
|
+
if (descriptor === void 0 || !("value" in descriptor) || descriptor.enumerable !== true) throw new ContractError("cloneJSONValue: record property is not enumerable data", {
|
|
1598
|
+
code: "clone",
|
|
1599
|
+
context: { shape: "json" }
|
|
1600
|
+
});
|
|
1601
|
+
entries.push([key, descriptor.value]);
|
|
1602
|
+
}
|
|
1603
|
+
frame.entries = entries;
|
|
1604
|
+
}
|
|
1605
|
+
const entry = frame.entries[frame.index];
|
|
1606
|
+
if (entry === void 0) {
|
|
1607
|
+
Object.freeze(frame.clone);
|
|
1608
|
+
active.delete(frame.source);
|
|
1609
|
+
pending.pop();
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
frame.index += 1;
|
|
1613
|
+
const key = entry[0];
|
|
1614
|
+
const source = entry[1];
|
|
1615
|
+
let clone;
|
|
1616
|
+
if (source === null || typeof source === "string" || typeof source === "boolean") clone = source;
|
|
1617
|
+
else if (typeof source === "number") {
|
|
1618
|
+
if (!Number.isFinite(source)) throw new ContractError("cloneJSONValue: number is not finite", {
|
|
1619
|
+
code: "clone",
|
|
1620
|
+
context: { shape: "json" }
|
|
1621
|
+
});
|
|
1622
|
+
clone = source;
|
|
1623
|
+
} else if (typeof source === "object") {
|
|
1624
|
+
if (active.has(source)) throw new ContractError("cloneJSONValue: cycle detected", {
|
|
1625
|
+
code: "clone",
|
|
1626
|
+
context: { shape: "json" }
|
|
1627
|
+
});
|
|
1628
|
+
const childArrayOutcome = attempt(() => Array.isArray(source));
|
|
1629
|
+
if (!childArrayOutcome.success) throw new ContractError("cloneJSONValue: value brand could not be inspected", {
|
|
1630
|
+
code: "clone",
|
|
1631
|
+
context: { shape: "json" }
|
|
1632
|
+
});
|
|
1633
|
+
let child;
|
|
1634
|
+
if (childArrayOutcome.value) child = [];
|
|
1635
|
+
else if (isRecord(source)) child = Object.create(null);
|
|
1636
|
+
else throw new ContractError("cloneJSONValue: object is not a plain record", {
|
|
1637
|
+
code: "clone",
|
|
1638
|
+
context: { shape: "json" }
|
|
1639
|
+
});
|
|
1640
|
+
clone = child;
|
|
1641
|
+
active.add(source);
|
|
1642
|
+
pending.push({
|
|
1643
|
+
source,
|
|
1644
|
+
clone: child,
|
|
1645
|
+
array: childArrayOutcome.value,
|
|
1646
|
+
entries: void 0,
|
|
1647
|
+
index: 0
|
|
1648
|
+
});
|
|
1649
|
+
} else throw new ContractError("cloneJSONValue: property is not JSON data", {
|
|
1650
|
+
code: "clone",
|
|
1651
|
+
context: { shape: "json" }
|
|
1652
|
+
});
|
|
1653
|
+
Object.defineProperty(frame.clone, key, {
|
|
1654
|
+
value: clone,
|
|
1655
|
+
enumerable: true,
|
|
1656
|
+
configurable: true,
|
|
1657
|
+
writable: true
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
return root;
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Deep-clone an exact JSON object record into an owned frozen snapshot.
|
|
1664
|
+
*
|
|
1665
|
+
* @remarks
|
|
1666
|
+
* Adds a record-root boundary to {@link cloneJSONValue}. The output is a
|
|
1667
|
+
* deeply frozen null-prototype record, and repeated noncyclic aliases are
|
|
1668
|
+
* duplicated as independent JSON tree branches.
|
|
1669
|
+
*
|
|
1670
|
+
* @param value - The unknown record value to validate and snapshot
|
|
1671
|
+
* @returns A deeply cloned and frozen JSON record
|
|
1672
|
+
* @throws {ContractError} When the root is not a record, nested data is inexact, or traversal fails
|
|
1673
|
+
*
|
|
1674
|
+
* @example
|
|
1675
|
+
* ```ts
|
|
1676
|
+
* cloneJSONRecord({ attempt: 1 }) // frozen null-prototype record
|
|
1677
|
+
* ```
|
|
1678
|
+
*/
|
|
1679
|
+
function cloneJSONRecord(value) {
|
|
1680
|
+
if (!isRecord(value)) throw new ContractError("cloneJSONRecord: value is not a plain record", {
|
|
1681
|
+
code: "clone",
|
|
1682
|
+
context: { shape: "json" }
|
|
1683
|
+
});
|
|
1684
|
+
const clone = cloneJSONValue(value);
|
|
1685
|
+
if (!isRecord(clone)) throw new ContractError("cloneJSONRecord: cloned value is not a record", {
|
|
1686
|
+
code: "clone",
|
|
1687
|
+
context: { shape: "json" }
|
|
1688
|
+
});
|
|
1689
|
+
return clone;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1477
1692
|
* Deep-clone a JSON Schema graph into an owned frozen snapshot.
|
|
1478
1693
|
*
|
|
1479
1694
|
* @remarks
|
|
@@ -5026,6 +5241,6 @@ function schemaToShape(schema) {
|
|
|
5026
5241
|
return schemaNodeToShape(schema, 32, /* @__PURE__ */ new WeakSet(), /* @__PURE__ */ new WeakMap());
|
|
5027
5242
|
}
|
|
5028
5243
|
//#endregion
|
|
5029
|
-
export { COMPILE_DEPTH_LIMIT, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildShapeFromNode, canonicalStringify, canonicalizeValue, cloneSchema, cloneShape, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, createContract, deriveLengthBounds, deriveRangeBounds, drawRandom, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, literalOf, literalShape, mapOf, matchOf, matchesJSONValue, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pickOf, preview, rawShape, recordOf, recordShape, resolveField, samplesToFormat, samplesToSchema, sanitizeBudget, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, setOf, shapeToKind, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, validateShapeDepth, valueToSchema, whereOf };
|
|
5244
|
+
export { COMPILE_DEPTH_LIMIT, ContractError, FAULT_LIMIT, FORMAT_MAX_LENGTH, FORMAT_PATTERNS, GENERATION_ATTEMPT_LIMIT, GUARD_DEPTH_LIMIT, INFER_BREADTH_LIMIT, INFER_DEPTH_LIMIT, INFER_ENUM_LIMIT, JSON_SCHEMA_TYPES, PREVIEW_LIMIT, andOf, arrayOf, arrayShape, attempt, booleanShape, boundsOf, buildObjectShape, buildShapeFromNode, canonicalStringify, canonicalizeValue, cloneJSONRecord, cloneJSONValue, cloneSchema, cloneShape, compileGenerator, compileGuard, compileParser, compileReporter, compileSchema, complementOf, createContract, deriveLengthBounds, deriveRangeBounds, drawRandom, enumOf, enumerableKeys, enumerableSymbolCount, holds, inferArray, inferObject, inferPrimitiveEnum, inferRecordSamples, inferSamples, inferValue, instanceOf, integerShape, intersectionOf, isArray, isArrayBuffer, isArrayBufferView, isAsyncFunction, isAsyncGeneratorFunction, isAsyncIterable, isBigInt, isBigInt64Array, isBigUint64Array, isBoolean, isConstructor, isContractError, isDataView, isDate, isDefined, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isError, isFalse, isFiniteNumber, isFloat32Array, isFloat64Array, isFunction, isGeneratorFunction, isInstance, isInt16Array, isInt32Array, isInt8Array, isInteger, isIterable, isJSONPrimitive, isJSONValue, isMap, isNonEmptyArray, isNonEmptyMap, isNonEmptyObject, isNonEmptySet, isNonEmptyString, isNull, isNullableBoolean, isNullableNumber, isNullableString, isNumber, isObject, isPromise, isPromiseLike, isRecord, isRegExp, isSet, isSharedArrayBuffer, isString, isSymbol, isTrue, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, isValidISOInstant, isWeakMap, isWeakSet, isZeroArg, isZeroArgAsync, isZeroArgAsyncGenerator, isZeroArgGenerator, jsonShape, keyOf, lazyOf, literalOf, literalShape, mapOf, matchOf, matchesJSONValue, notOf, nullShape, nullableOf, nullableShape, numberShape, objectShape, omitOf, oneOfShape, optionalOf, optionalShape, orOf, ownShape, parseArray, parseArrayField, parseBoolean, parseBooleanField, parseEnum, parseEnumField, parseInteger, parseIntegerField, parseJSON, parseJSONAs, parseJSONValue, parseJSONValueField, parseNull, parseNullField, parseNumber, parseNumberField, parseRecord, parseRecordField, parseString, parseStringField, pickOf, preview, rawShape, recordOf, recordShape, resolveField, samplesToFormat, samplesToSchema, sanitizeBudget, schemaNodeToShape, schemaToObject, schemaToParameters, schemaToShape, seededRandom, setOf, shapeToKind, stringOf, stringShape, stringToFormat, transformOf, tupleOf, unifySchemas, unionOf, unionShape, validateShape, validateShapeDepth, valueToSchema, whereOf };
|
|
5030
5245
|
|
|
5031
5246
|
//# sourceMappingURL=index.js.map
|