toolcraft-openapi 0.0.548 → 0.0.550

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.
@@ -33,12 +33,12 @@
33
33
  },
34
34
  {
35
35
  "name": "toolcraft-openapi",
36
- "version": "0.0.548",
36
+ "version": "0.0.550",
37
37
  "license": "MIT"
38
38
  },
39
39
  {
40
40
  "name": "toolcraft-schema",
41
- "version": "0.0.548",
41
+ "version": "0.0.550",
42
42
  "license": "MIT"
43
43
  },
44
44
  {
@@ -10,59 +10,72 @@ export function isJsonValue(value, options = {}) {
10
10
  const maxDepth = options.maxDepth ?? 64;
11
11
  if (maxNodes !== Infinity && (!Number.isSafeInteger(maxNodes) || maxNodes < 1))
12
12
  throw new Error("maxNodes must be a positive safe integer");
13
- if (!Number.isSafeInteger(maxDepth) || maxDepth < 0 || maxDepth > 256)
14
- throw new Error("maxDepth must be an integer between 0 and 256");
13
+ if (maxDepth !== Infinity && (!Number.isSafeInteger(maxDepth) || maxDepth < 0))
14
+ throw new Error("maxDepth must be a nonnegative safe integer");
15
15
  const ancestors = new Set();
16
+ const stack = [];
17
+ function* properties(item) {
18
+ if (Array.isArray(item)) {
19
+ for (let index = 0; index < item.length; index++)
20
+ yield Object.getOwnPropertyDescriptor(item, String(index));
21
+ }
22
+ else
23
+ for (const key in item) {
24
+ const property = Object.getOwnPropertyDescriptor(item, key);
25
+ if (property !== undefined)
26
+ yield property;
27
+ }
28
+ }
16
29
  let nodes = 0;
17
- const visit = (item, depth) => {
30
+ let item = value, depth = 0;
31
+ while (true) {
18
32
  if (++nodes > maxNodes || depth > maxDepth)
19
33
  return false;
20
- if (item === null || typeof item === "string" || typeof item === "boolean")
21
- return true;
22
- if (typeof item === "number")
23
- return Number.isFinite(item);
24
- if (typeof item !== "object" || ancestors.has(item))
25
- return false;
26
- if (!Array.isArray(item) && Object.getPrototypeOf(item) !== Object.prototype &&
27
- Object.getPrototypeOf(item) !== null)
28
- return false;
29
- let hookOwner = item;
30
- let prototypeDepth = 0;
31
- while (hookOwner !== null) {
32
- if (++prototypeDepth > 64)
33
- return false;
34
- const serializationHook = Object.getOwnPropertyDescriptor(hookOwner, "toJSON");
35
- if (serializationHook !== undefined) {
36
- if (!("value" in serializationHook) || typeof serializationHook.value === "function")
34
+ if (item !== null && typeof item !== "string" && typeof item !== "boolean") {
35
+ if (typeof item === "number") {
36
+ if (!Number.isFinite(item))
37
37
  return false;
38
- break;
39
38
  }
40
- hookOwner = Object.getPrototypeOf(hookOwner);
41
- }
42
- ancestors.add(item);
43
- let valid = true;
44
- if (Array.isArray(item)) {
45
- if (item.length > maxNodes)
46
- valid = false;
47
- else
48
- for (let index = 0; index < item.length; index++) {
49
- const property = Object.getOwnPropertyDescriptor(item, String(index));
50
- if (property === undefined || !("value" in property) || !visit(property.value, depth + 1)) {
51
- valid = false;
39
+ else {
40
+ if (typeof item !== "object" || ancestors.has(item))
41
+ return false;
42
+ if (!Array.isArray(item) && Object.getPrototypeOf(item) !== Object.prototype &&
43
+ Object.getPrototypeOf(item) !== null)
44
+ return false;
45
+ let hookOwner = item;
46
+ let prototypeDepth = 0;
47
+ while (hookOwner !== null) {
48
+ if (++prototypeDepth > 64)
49
+ return false;
50
+ const serializationHook = Object.getOwnPropertyDescriptor(hookOwner, "toJSON");
51
+ if (serializationHook !== undefined) {
52
+ if (!("value" in serializationHook) || typeof serializationHook.value === "function")
53
+ return false;
52
54
  break;
53
55
  }
56
+ hookOwner = Object.getPrototypeOf(hookOwner);
54
57
  }
58
+ if (Array.isArray(item) && item.length > maxNodes)
59
+ return false;
60
+ ancestors.add(item);
61
+ stack.push({ owner: item, children: properties(item), depth });
62
+ }
55
63
  }
56
- else
57
- for (const key in item) {
58
- const property = Object.getOwnPropertyDescriptor(item, key);
59
- if (property !== undefined && (!("value" in property) || !visit(property.value, depth + 1))) {
60
- valid = false;
61
- break;
62
- }
64
+ let next;
65
+ while (stack.length) {
66
+ const frame = stack[stack.length - 1];
67
+ next = frame.children.next();
68
+ if (!next.done) {
69
+ if (next.value === undefined || !("value" in next.value))
70
+ return false;
71
+ item = next.value.value;
72
+ depth = frame.depth + 1;
73
+ break;
63
74
  }
64
- ancestors.delete(item);
65
- return valid;
66
- };
67
- return visit(value, 0);
75
+ ancestors.delete(frame.owner);
76
+ stack.pop();
77
+ }
78
+ if (!stack.length)
79
+ return true;
80
+ }
68
81
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.548",
3
+ "version": "0.0.550",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-openapi",
3
- "version": "0.0.548",
3
+ "version": "0.0.550",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "toolcraft-openapi-generate": "dist/bin/generate.js"
31
31
  },
32
32
  "dependencies": {
33
- "toolcraft": "0.0.548",
33
+ "toolcraft": "0.0.550",
34
34
  "fast-string-width": "^3.0.2",
35
35
  "fast-wrap-ansi": "^0.2.0",
36
36
  "sisteransi": "^1.0.5",
@@ -45,7 +45,7 @@
45
45
  "directory": "packages/toolcraft-openapi"
46
46
  },
47
47
  "optionalDependencies": {
48
- "toolcraft-schema": "0.0.548",
48
+ "toolcraft-schema": "0.0.550",
49
49
  "toolcraft-design": "*",
50
50
  "@poe-code/frontmatter": "*"
51
51
  },