toolcraft-schema 0.0.307 → 0.0.309

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 CHANGED
@@ -94,6 +94,13 @@ validate the complete object to enforce branch-dependent and combined constraint
94
94
  Both functions accept a `registry` for external schema documents without network
95
95
  fetching.
96
96
 
97
+ `isJsonValue(value, options)` checks JSON data without invoking getters or
98
+ serialization hooks. It rejects cycles, sparse arrays, non-finite numbers and
99
+ non-JSON prototypes. Defaults bound the tree to 10,000 nodes and depth 64.
100
+ Use `maxNodes` for larger bounded documents, or `maxDepth` (0–256) to choose a
101
+ depth budget. Shared objects count once for each occurrence in the JSON tree;
102
+ options never change other calls' budgets.
103
+
97
104
  ## Environment Variables
98
105
 
99
106
  This package exposes no environment variables.
package/dist/index.d.ts CHANGED
@@ -182,6 +182,7 @@ export declare function toJsonSchema(schema: AnySchema): JsonSchema;
182
182
  export declare function toJsonSchemaDocument(schema: AnySchema, options?: JsonSchemaDocumentOptions): JsonSchemaDocument;
183
183
  export { Json, OneOf, RecordBuilder as Record, Union, isPlainRecord, validate };
184
184
  export { isJsonValue } from "./json.js";
185
+ export type { JsonValueValidationOptions } from "./json.js";
185
186
  export { cloneDefaultValue } from "./clone-default.js";
186
187
  export { unicodeLength } from "./json-schema/utils.js";
187
188
  export { compileJsonSchema, formatIssues } from "./json-schema/index.js";
package/dist/json.d.ts CHANGED
@@ -9,5 +9,9 @@ export interface JsonValueSchema extends SchemaBase<"json", JsonValue> {
9
9
  readonly enum?: readonly JsonValue[];
10
10
  }
11
11
  export declare function Json(options?: Omit<JsonValueSchema, "kind">): JsonValueSchema;
12
- export declare function isJsonValue(value: unknown): boolean;
12
+ export interface JsonValueValidationOptions {
13
+ readonly maxNodes?: number;
14
+ readonly maxDepth?: number;
15
+ }
16
+ export declare function isJsonValue(value: unknown, options?: JsonValueValidationOptions): boolean;
13
17
  export {};
package/dist/json.js CHANGED
@@ -4,11 +4,17 @@ export function Json(options = {}) {
4
4
  ...options,
5
5
  };
6
6
  }
7
- export function isJsonValue(value) {
7
+ export function isJsonValue(value, options = {}) {
8
+ const maxNodes = options.maxNodes ?? 10_000;
9
+ const maxDepth = options.maxDepth ?? 64;
10
+ if (!Number.isSafeInteger(maxNodes) || maxNodes < 1)
11
+ throw new Error("maxNodes must be a positive safe integer");
12
+ if (!Number.isSafeInteger(maxDepth) || maxDepth < 0 || maxDepth > 256)
13
+ throw new Error("maxDepth must be an integer between 0 and 256");
8
14
  const ancestors = new Set();
9
15
  let nodes = 0;
10
16
  const visit = (item, depth) => {
11
- if (++nodes > 10_000 || depth > 64)
17
+ if (++nodes > maxNodes || depth > maxDepth)
12
18
  return false;
13
19
  if (item === null || typeof item === "string" || typeof item === "boolean")
14
20
  return true;
@@ -35,7 +41,7 @@ export function isJsonValue(value) {
35
41
  ancestors.add(item);
36
42
  let valid = true;
37
43
  if (Array.isArray(item)) {
38
- if (item.length > 10_000)
44
+ if (item.length > maxNodes)
39
45
  valid = false;
40
46
  else
41
47
  for (let index = 0; index < item.length; index++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.307",
3
+ "version": "0.0.309",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",