effect 3.17.7 → 3.17.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/cjs/ParseResult.js +3 -3
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schema.js +8 -8
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/SchemaAST.js +1 -1
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/internal/schema/util.js +64 -46
- package/dist/cjs/internal/schema/util.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/esm/ParseResult.js +3 -3
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schema.js +8 -8
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/SchemaAST.js +1 -1
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/internal/schema/util.js +58 -40
- package/dist/esm/internal/schema/util.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/ParseResult.ts +3 -3
- package/src/Schema.ts +8 -8
- package/src/SchemaAST.ts +1 -1
- package/src/internal/schema/util.ts +79 -53
- package/src/internal/version.ts +1 -1
|
@@ -19,16 +19,6 @@ export const getKeysForIndexSignature = (
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* JavaScript does not store the insertion order of properties in a way that
|
|
24
|
-
* combines both string and symbol keys. The internal order groups string keys
|
|
25
|
-
* and symbol keys separately. Hence concatenating the keys is fine.
|
|
26
|
-
*
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
export const ownKeys = (o: object): Array<PropertyKey> =>
|
|
30
|
-
(Object.keys(o) as Array<PropertyKey>).concat(Object.getOwnPropertySymbols(o))
|
|
31
|
-
|
|
32
22
|
/** @internal */
|
|
33
23
|
export const memoizeThunk = <A>(f: () => A): () => A => {
|
|
34
24
|
let done = false
|
|
@@ -52,58 +42,94 @@ export const formatDate = (date: Date): string => {
|
|
|
52
42
|
}
|
|
53
43
|
}
|
|
54
44
|
|
|
45
|
+
const CIRCULAR = "[Circular]"
|
|
46
|
+
|
|
55
47
|
/** @internal */
|
|
56
|
-
export
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return u["toString"]()
|
|
69
|
-
}
|
|
70
|
-
if (Predicate.isString(u)) {
|
|
71
|
-
return JSON.stringify(u)
|
|
72
|
-
}
|
|
73
|
-
if (
|
|
74
|
-
Predicate.isNumber(u)
|
|
75
|
-
|| u == null
|
|
76
|
-
|| Predicate.isBoolean(u)
|
|
77
|
-
|| Predicate.isSymbol(u)
|
|
78
|
-
) {
|
|
79
|
-
return String(u)
|
|
48
|
+
export function formatUnknown(input: unknown, whitespace: number | string | undefined = 0): string {
|
|
49
|
+
const seen = new WeakSet<object>()
|
|
50
|
+
const gap = !whitespace ? "" : (typeof whitespace === "number" ? " ".repeat(whitespace) : whitespace)
|
|
51
|
+
const ind = (d: number) => gap.repeat(d)
|
|
52
|
+
|
|
53
|
+
const safeToString = (x: any): string => {
|
|
54
|
+
try {
|
|
55
|
+
const s = x.toString()
|
|
56
|
+
return typeof s === "string" ? s : String(s)
|
|
57
|
+
} catch {
|
|
58
|
+
return "[toString threw]"
|
|
59
|
+
}
|
|
80
60
|
}
|
|
81
|
-
|
|
82
|
-
|
|
61
|
+
|
|
62
|
+
const wrap = (v: unknown, body: string): string => {
|
|
63
|
+
const ctor = (v as any)?.constructor
|
|
64
|
+
return ctor && ctor !== Object.prototype.constructor && ctor.name ? `${ctor.name}(${body})` : body
|
|
83
65
|
}
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
|
|
67
|
+
const ownKeys = (o: object): Array<PropertyKey> => {
|
|
68
|
+
try {
|
|
69
|
+
return Reflect.ownKeys(o)
|
|
70
|
+
} catch {
|
|
71
|
+
return ["[ownKeys threw]"]
|
|
72
|
+
}
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
|
|
75
|
+
function go(v: unknown, d = 0): string {
|
|
76
|
+
if (Array.isArray(v)) {
|
|
77
|
+
if (seen.has(v)) return CIRCULAR
|
|
78
|
+
seen.add(v)
|
|
79
|
+
if (!gap || v.length <= 1) return `[${v.map((x) => go(x, d)).join(",")}]`
|
|
80
|
+
const inner = v.map((x) => go(x, d + 1)).join(",\n" + ind(d + 1))
|
|
81
|
+
return `[\n${ind(d + 1)}${inner}\n${ind(d)}]`
|
|
90
82
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
return
|
|
83
|
+
|
|
84
|
+
if (Predicate.isDate(v)) return formatDate(v)
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
Predicate.hasProperty(v, "toString") &&
|
|
88
|
+
Predicate.isFunction((v as any)["toString"]) &&
|
|
89
|
+
(v as any)["toString"] !== Object.prototype.toString
|
|
90
|
+
) return safeToString(v)
|
|
91
|
+
|
|
92
|
+
if (Predicate.isString(v)) return JSON.stringify(v)
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
Predicate.isNumber(v) ||
|
|
96
|
+
v == null ||
|
|
97
|
+
Predicate.isBoolean(v) ||
|
|
98
|
+
Predicate.isSymbol(v)
|
|
99
|
+
) return String(v)
|
|
100
|
+
|
|
101
|
+
if (Predicate.isBigInt(v)) return String(v) + "n"
|
|
102
|
+
|
|
103
|
+
if (v instanceof Set || v instanceof Map) {
|
|
104
|
+
if (seen.has(v)) return CIRCULAR
|
|
105
|
+
seen.add(v)
|
|
106
|
+
return `${v.constructor.name}(${go(Array.from(v), d)})`
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Predicate.isObject(v)) {
|
|
110
|
+
if (seen.has(v)) return CIRCULAR
|
|
111
|
+
seen.add(v)
|
|
112
|
+
const keys = ownKeys(v)
|
|
113
|
+
if (!gap || keys.length <= 1) {
|
|
114
|
+
const body = `{${keys.map((k) => `${formatPropertyKey(k)}:${go((v as any)[k], d)}`).join(",")}}`
|
|
115
|
+
return wrap(v, body)
|
|
116
|
+
}
|
|
117
|
+
const body = `{\n${
|
|
118
|
+
keys.map((k) => `${ind(d + 1)}${formatPropertyKey(k)}: ${go((v as any)[k], d + 1)}`).join(",\n")
|
|
119
|
+
}\n${ind(d)}}`
|
|
120
|
+
return wrap(v, body)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return String(v)
|
|
101
124
|
}
|
|
125
|
+
|
|
126
|
+
return go(input, 0)
|
|
102
127
|
}
|
|
103
128
|
|
|
104
129
|
/** @internal */
|
|
105
|
-
export
|
|
106
|
-
|
|
130
|
+
export function formatPropertyKey(name: PropertyKey): string {
|
|
131
|
+
return Predicate.isString(name) ? JSON.stringify(name) : String(name)
|
|
132
|
+
}
|
|
107
133
|
|
|
108
134
|
/** @internal */
|
|
109
135
|
export type SingleOrArray<A> = A | ReadonlyArray<A>
|
package/src/internal/version.ts
CHANGED