effect 3.19.2 → 3.19.3
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/Inspectable.js +86 -4
- package/dist/cjs/Inspectable.js.map +1 -1
- package/dist/cjs/ParseResult.js +1 -1
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Pretty.js +4 -3
- package/dist/cjs/Pretty.js.map +1 -1
- package/dist/cjs/Schema.js +15 -14
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/SchemaAST.js +4 -3
- package/dist/cjs/SchemaAST.js.map +1 -1
- package/dist/cjs/internal/config.js +10 -9
- package/dist/cjs/internal/config.js.map +1 -1
- package/dist/cjs/internal/schema/errors.js +6 -5
- package/dist/cjs/internal/schema/errors.js.map +1 -1
- package/dist/cjs/internal/schema/util.js +3 -77
- package/dist/cjs/internal/schema/util.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Inspectable.d.ts.map +1 -1
- package/dist/dts/Pretty.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/SchemaAST.d.ts.map +1 -1
- package/dist/esm/Inspectable.js +79 -2
- package/dist/esm/Inspectable.js.map +1 -1
- package/dist/esm/ParseResult.js +1 -1
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Pretty.js +4 -3
- package/dist/esm/Pretty.js.map +1 -1
- package/dist/esm/Schema.js +15 -14
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/SchemaAST.js +4 -3
- package/dist/esm/SchemaAST.js.map +1 -1
- package/dist/esm/internal/config.js +10 -9
- package/dist/esm/internal/config.js.map +1 -1
- package/dist/esm/internal/schema/errors.js +6 -5
- package/dist/esm/internal/schema/errors.js.map +1 -1
- package/dist/esm/internal/schema/util.js +2 -72
- 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/Inspectable.ts +115 -2
- package/src/ParseResult.ts +1 -1
- package/src/Pretty.ts +4 -3
- package/src/Schema.ts +18 -14
- package/src/SchemaAST.ts +4 -3
- package/src/internal/config.ts +15 -9
- package/src/internal/schema/errors.ts +12 -5
- package/src/internal/schema/util.ts +2 -100
- package/src/internal/version.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NonEmptyReadonlyArray } from "../../Array.js"
|
|
2
|
+
import * as Inspectable from "../../Inspectable.js"
|
|
2
3
|
import type * as ParseResult from "../../ParseResult.js"
|
|
3
|
-
import * as Predicate from "../../Predicate.js"
|
|
4
4
|
import type * as AST from "../../SchemaAST.js"
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
@@ -33,104 +33,6 @@ export const memoizeThunk = <A>(f: () => A): () => A => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** @internal */
|
|
37
|
-
export const formatDate = (date: Date): string => {
|
|
38
|
-
try {
|
|
39
|
-
return date.toISOString()
|
|
40
|
-
} catch {
|
|
41
|
-
return String(date)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const CIRCULAR = "[Circular]"
|
|
46
|
-
|
|
47
|
-
/** @internal */
|
|
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
|
-
}
|
|
60
|
-
}
|
|
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
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const ownKeys = (o: object): Array<PropertyKey> => {
|
|
68
|
-
try {
|
|
69
|
-
return Reflect.ownKeys(o)
|
|
70
|
-
} catch {
|
|
71
|
-
return ["[ownKeys threw]"]
|
|
72
|
-
}
|
|
73
|
-
}
|
|
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)}]`
|
|
82
|
-
}
|
|
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)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return go(input, 0)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** @internal */
|
|
130
|
-
export function formatPropertyKey(name: PropertyKey): string {
|
|
131
|
-
return Predicate.isString(name) ? JSON.stringify(name) : String(name)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
36
|
/** @internal */
|
|
135
37
|
export type SingleOrArray<A> = A | ReadonlyArray<A>
|
|
136
38
|
|
|
@@ -141,7 +43,7 @@ export const isNonEmpty = <A>(x: ParseResult.SingleOrNonEmpty<A>): x is NonEmpty
|
|
|
141
43
|
export const isSingle = <A>(x: A | ReadonlyArray<A>): x is A => !Array.isArray(x)
|
|
142
44
|
|
|
143
45
|
/** @internal */
|
|
144
|
-
export const formatPathKey = (key: PropertyKey): string => `[${formatPropertyKey(key)}]`
|
|
46
|
+
export const formatPathKey = (key: PropertyKey): string => `[${Inspectable.formatPropertyKey(key)}]`
|
|
145
47
|
|
|
146
48
|
/** @internal */
|
|
147
49
|
export const formatPath = (path: ParseResult.Path): string =>
|
package/src/internal/version.ts
CHANGED