@syntrologie/adapt-content 2.55.1 → 2.56.0
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/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +7 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -1
- package/dist/schema.js +4483 -308
- package/dist/schema.js.map +4 -4
- package/package.json +1 -4
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-PZ5AY32C.js";
|
|
4
|
+
|
|
1
5
|
// ../../../node_modules/@lit/context/lib/create-context.js
|
|
2
6
|
function n(n2) {
|
|
3
7
|
return n2;
|
|
@@ -6,6 +10,234 @@ function n(n2) {
|
|
|
6
10
|
// ../../sdk-contracts/dist/canvas-context.js
|
|
7
11
|
var canvasRuntimeContext = n("syntrologie:canvas-runtime");
|
|
8
12
|
|
|
13
|
+
// ../../sdk-contracts/dist/telemetry-events.js
|
|
14
|
+
var entry = (e2) => e2;
|
|
15
|
+
var TELEMETRY_EVENTS = {
|
|
16
|
+
// --- intervention metrics (April 2026) — wire names unchanged, all plan-scope
|
|
17
|
+
syntro_config_served: entry({
|
|
18
|
+
subject: "config",
|
|
19
|
+
verb: "served",
|
|
20
|
+
scope: "plan",
|
|
21
|
+
props: ["tiles", "actions"]
|
|
22
|
+
}),
|
|
23
|
+
syntro_intervention_seen: entry({
|
|
24
|
+
subject: "intervention",
|
|
25
|
+
verb: "seen",
|
|
26
|
+
scope: "plan",
|
|
27
|
+
props: ["intervention_id", "intervention_kind"]
|
|
28
|
+
}),
|
|
29
|
+
syntro_intervention_triggered: entry({
|
|
30
|
+
subject: "intervention",
|
|
31
|
+
verb: "triggered",
|
|
32
|
+
scope: "plan",
|
|
33
|
+
props: ["intervention_id", "intervention_kind"]
|
|
34
|
+
}),
|
|
35
|
+
syntro_intervention_interacted: entry({
|
|
36
|
+
subject: "intervention",
|
|
37
|
+
verb: "interacted",
|
|
38
|
+
scope: "plan",
|
|
39
|
+
props: ["intervention_id", "intervention_kind", "interaction_type"]
|
|
40
|
+
}),
|
|
41
|
+
// --- concierge (FEAT-1789150184) ---------------------------------------
|
|
42
|
+
syntro_concierge_opened: entry({
|
|
43
|
+
subject: "concierge",
|
|
44
|
+
verb: "opened",
|
|
45
|
+
scope: "open",
|
|
46
|
+
props: ["trigger", "page_path"]
|
|
47
|
+
// trigger: ConciergeOpenTrigger
|
|
48
|
+
}),
|
|
49
|
+
syntro_concierge_closed: entry({
|
|
50
|
+
subject: "concierge",
|
|
51
|
+
verb: "closed",
|
|
52
|
+
scope: "open",
|
|
53
|
+
props: ["duration_ms", "reason", "messages_sent", "tiles_dismissed", "pages_viewed"]
|
|
54
|
+
// reason: ConciergeCloseReason
|
|
55
|
+
}),
|
|
56
|
+
/**
|
|
57
|
+
* The shopper asked to leave the canvas by a link. Emitted on intent, before
|
|
58
|
+
* the host answers, so refused or denied opens are counted too (parity with
|
|
59
|
+
* syntro_concierge_closed reason navigation).
|
|
60
|
+
*
|
|
61
|
+
* On a merchant's own page a link tap closes the canvas, and
|
|
62
|
+
* `syntro_concierge_closed { reason: 'navigation' }` is the row that
|
|
63
|
+
* records it. Inside a chat app's card the frame is sandboxed: the canvas
|
|
64
|
+
* cannot navigate, does not close, and asks the host to open the link
|
|
65
|
+
* instead, so that close row never fires. This is its counterpart, and it
|
|
66
|
+
* carries the same `reason` so one query covers both surfaces.
|
|
67
|
+
*/
|
|
68
|
+
syntro_link_opened: entry({
|
|
69
|
+
subject: "link",
|
|
70
|
+
verb: "opened",
|
|
71
|
+
scope: "open",
|
|
72
|
+
props: ["kind", "reason"]
|
|
73
|
+
// kind: LinkOpenKind, reason: ConciergeCloseReason
|
|
74
|
+
}),
|
|
75
|
+
/**
|
|
76
|
+
* A store's product page opened inside a chat-app card instead of leaving
|
|
77
|
+
* through the host (the card's product view). `product` is the store's
|
|
78
|
+
* handle, never the display name; a rail switch is a new open. Its
|
|
79
|
+
* counterpart when the shopper goes back to the conversation's picks is
|
|
80
|
+
* syntro_product_view_closed.
|
|
81
|
+
*
|
|
82
|
+
* Plan scope, like the card's own syntro_card_lifecycle_seen: an inline
|
|
83
|
+
* card holds an open scope only while the host has it fullscreen, and a
|
|
84
|
+
* view opened from a tile fires before the host answers that request (or
|
|
85
|
+
* after it refused), so an open-scope row here would be dropped. The core
|
|
86
|
+
* still stamps surface and open_id whenever an open is live.
|
|
87
|
+
*/
|
|
88
|
+
syntro_product_view_opened: entry({
|
|
89
|
+
subject: "product_view",
|
|
90
|
+
verb: "opened",
|
|
91
|
+
scope: "plan",
|
|
92
|
+
props: ["product", "from"]
|
|
93
|
+
// from: ProductViewOpenSource
|
|
94
|
+
}),
|
|
95
|
+
syntro_product_view_closed: entry({
|
|
96
|
+
subject: "product_view",
|
|
97
|
+
verb: "closed",
|
|
98
|
+
scope: "plan",
|
|
99
|
+
props: ["product"]
|
|
100
|
+
}),
|
|
101
|
+
syntro_deck_paged: entry({
|
|
102
|
+
subject: "deck",
|
|
103
|
+
verb: "paged",
|
|
104
|
+
scope: "open",
|
|
105
|
+
props: ["from_index", "to_index", "method"]
|
|
106
|
+
// method: DeckPageMethod
|
|
107
|
+
}),
|
|
108
|
+
syntro_tile_dismissed: entry({
|
|
109
|
+
subject: "tile",
|
|
110
|
+
verb: "dismissed",
|
|
111
|
+
scope: "open",
|
|
112
|
+
props: ["tile_id", "tile_kind", "visible_ms"]
|
|
113
|
+
}),
|
|
114
|
+
// A tile's own data load finished: the network wait between the concierge
|
|
115
|
+
// mounting a tile and the shopper seeing its content (BUG-1784767817 was a
|
|
116
|
+
// 30 s reviews hang here). `outcome` is 'ok' | 'error'; `requested` is how
|
|
117
|
+
// many items the tile asked for, `received` how many came back.
|
|
118
|
+
syntro_tile_data_received: entry({
|
|
119
|
+
subject: "tile_data",
|
|
120
|
+
verb: "received",
|
|
121
|
+
scope: "open",
|
|
122
|
+
props: ["tile_id", "tile_kind", "total_ms", "outcome", "requested", "received"]
|
|
123
|
+
}),
|
|
124
|
+
// The three chat atoms are OPEN-scope: they carry `surface` / `open_id` and
|
|
125
|
+
// only make sense inside a concierge open. An INLINE chat bar (no concierge)
|
|
126
|
+
// still dispatches them on every turn, and the core drops each one and
|
|
127
|
+
// increments the `telemetry_dropped` health counter. That is EXPECTED on an
|
|
128
|
+
// inline-chat host page, not a bug — `telemetry_dropped` there mixes "real
|
|
129
|
+
// defect" with "inline chat has no open scope", so do not alert on it alone.
|
|
130
|
+
syntro_chat_message_sent: entry({
|
|
131
|
+
subject: "chat_message",
|
|
132
|
+
verb: "sent",
|
|
133
|
+
scope: "open",
|
|
134
|
+
props: ["turn", "chars", "via"]
|
|
135
|
+
// via: ChatSendVia
|
|
136
|
+
}),
|
|
137
|
+
syntro_chat_reply_received: entry({
|
|
138
|
+
subject: "chat_reply",
|
|
139
|
+
verb: "received",
|
|
140
|
+
scope: "open",
|
|
141
|
+
// mount_tools: the mount_* tool name of every mount this reply fired, in order (two product cards appear twice).
|
|
142
|
+
props: ["turn", "ttft_ms", "total_ms", "mounts", "cards", "mount_tools"]
|
|
143
|
+
}),
|
|
144
|
+
syntro_chat_interrupted: entry({
|
|
145
|
+
subject: "chat",
|
|
146
|
+
verb: "interrupted",
|
|
147
|
+
scope: "open",
|
|
148
|
+
props: ["turn", "after_ms"]
|
|
149
|
+
}),
|
|
150
|
+
syntro_chat_maximize_toggled: entry({
|
|
151
|
+
subject: "chat_maximize",
|
|
152
|
+
verb: "toggled",
|
|
153
|
+
scope: "open",
|
|
154
|
+
props: ["maximized"]
|
|
155
|
+
}),
|
|
156
|
+
syntro_chat_takeover_triggered: entry({
|
|
157
|
+
subject: "chat_takeover",
|
|
158
|
+
verb: "triggered",
|
|
159
|
+
scope: "open",
|
|
160
|
+
props: ["turn"]
|
|
161
|
+
}),
|
|
162
|
+
// --- search takeover (2026-09-17) ---------------------------------------
|
|
163
|
+
// All plan-scope: the search interceptor fires before any concierge open
|
|
164
|
+
// exists. No prop here ever carries query text (SEE the contract test's
|
|
165
|
+
// no-text-prop rule) — classification/signal_hits are the interceptor's
|
|
166
|
+
// own derived signals, never the string itself.
|
|
167
|
+
syntro_search_sent: entry({
|
|
168
|
+
subject: "search",
|
|
169
|
+
verb: "sent",
|
|
170
|
+
scope: "plan",
|
|
171
|
+
props: ["classification", "word_count", "signal_hits", "entry_point", "platform"]
|
|
172
|
+
// classification: SearchClassification, entry_point: SearchEntryPoint
|
|
173
|
+
}),
|
|
174
|
+
// `ms_to_skeleton` is intentionally the only timing prop: it is always
|
|
175
|
+
// knowable the instant the surface mounts. `ms_to_first_content` is NOT
|
|
176
|
+
// declared here (revision 1 defect) because a surface that never painted
|
|
177
|
+
// content still fires this event, and a required prop it cannot supply
|
|
178
|
+
// would make TelemetryCore.emit drop exactly the row worth measuring.
|
|
179
|
+
syntro_search_surface_seen: entry({
|
|
180
|
+
subject: "search_surface",
|
|
181
|
+
verb: "seen",
|
|
182
|
+
scope: "plan",
|
|
183
|
+
props: ["variant", "classification", "result_count", "ms_to_skeleton"]
|
|
184
|
+
// variant: SearchVariant, classification: SearchClassification
|
|
185
|
+
}),
|
|
186
|
+
syntro_search_result_tapped: entry({
|
|
187
|
+
subject: "search_result",
|
|
188
|
+
verb: "tapped",
|
|
189
|
+
scope: "plan",
|
|
190
|
+
props: ["variant", "region_id", "module", "position"]
|
|
191
|
+
// variant: SearchVariant
|
|
192
|
+
}),
|
|
193
|
+
syntro_search_followup_sent: entry({
|
|
194
|
+
subject: "search_followup",
|
|
195
|
+
verb: "sent",
|
|
196
|
+
scope: "plan",
|
|
197
|
+
props: ["delta_kind", "variant"]
|
|
198
|
+
// delta_kind: SearchDeltaKind, variant: SearchVariant
|
|
199
|
+
}),
|
|
200
|
+
// Declares `ms_since_boot` (not a "since surface mounted" timing prop) so a
|
|
201
|
+
// not-ready fallback the takeover never rendered is still measurable —
|
|
202
|
+
// revision 1 emitted nothing on this path.
|
|
203
|
+
syntro_search_native_served: entry({
|
|
204
|
+
subject: "search_native",
|
|
205
|
+
verb: "served",
|
|
206
|
+
scope: "plan",
|
|
207
|
+
props: ["reason", "platform", "ms_since_boot"]
|
|
208
|
+
// reason: SearchFallbackReason
|
|
209
|
+
}),
|
|
210
|
+
syntro_search_takeover_dismissed: entry({
|
|
211
|
+
subject: "search_takeover",
|
|
212
|
+
verb: "dismissed",
|
|
213
|
+
scope: "plan",
|
|
214
|
+
props: ["variant", "reason"]
|
|
215
|
+
// variant: SearchVariant, reason: SearchDismissReason
|
|
216
|
+
}),
|
|
217
|
+
// --- chat-app card lifecycle (2026-09-24) --------------------------------
|
|
218
|
+
// One row per stage a card reached, from `reportCardStage` in
|
|
219
|
+
// card-lifecycle.ts. Plan scope: most stages happen before a config is
|
|
220
|
+
// served and none happen inside a concierge open. `stage` is a
|
|
221
|
+
// CardLifecycleStage; `since_shell_ms` is the card shell's own clock, so a
|
|
222
|
+
// card's rows order themselves from the first byte of the page. The same
|
|
223
|
+
// stages reach the connector through the shell's beacon, which is the only
|
|
224
|
+
// record of a card whose SDK never booted.
|
|
225
|
+
syntro_card_lifecycle_seen: entry({
|
|
226
|
+
subject: "card_lifecycle",
|
|
227
|
+
verb: "seen",
|
|
228
|
+
scope: "plan",
|
|
229
|
+
props: ["stage", "since_shell_ms"]
|
|
230
|
+
// stage: CardLifecycleStage
|
|
231
|
+
})
|
|
232
|
+
};
|
|
233
|
+
var TELEMETRY_EVENT_NAMES = Object.keys(TELEMETRY_EVENTS);
|
|
234
|
+
|
|
235
|
+
// ../../sdk-contracts/dist/card-lifecycle.js
|
|
236
|
+
var MCP_APP_SURFACE_ATTRIBUTES = Object.freeze({
|
|
237
|
+
surface_type: "mcp-app",
|
|
238
|
+
surface: "personal_agent"
|
|
239
|
+
});
|
|
240
|
+
|
|
9
241
|
// ../../sdk-contracts/dist/detector-events.js
|
|
10
242
|
var DETECTOR_EVENT_NAMES = [
|
|
11
243
|
"ui.hover",
|
|
@@ -120,342 +352,4285 @@ function normalizeRoute(path) {
|
|
|
120
352
|
return s4;
|
|
121
353
|
}
|
|
122
354
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
355
|
+
// ../../../node_modules/zod/v3/external.js
|
|
356
|
+
var external_exports = {};
|
|
357
|
+
__export(external_exports, {
|
|
358
|
+
BRAND: () => BRAND,
|
|
359
|
+
DIRTY: () => DIRTY,
|
|
360
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
361
|
+
INVALID: () => INVALID,
|
|
362
|
+
NEVER: () => NEVER,
|
|
363
|
+
OK: () => OK,
|
|
364
|
+
ParseStatus: () => ParseStatus,
|
|
365
|
+
Schema: () => ZodType,
|
|
366
|
+
ZodAny: () => ZodAny,
|
|
367
|
+
ZodArray: () => ZodArray,
|
|
368
|
+
ZodBigInt: () => ZodBigInt,
|
|
369
|
+
ZodBoolean: () => ZodBoolean,
|
|
370
|
+
ZodBranded: () => ZodBranded,
|
|
371
|
+
ZodCatch: () => ZodCatch,
|
|
372
|
+
ZodDate: () => ZodDate,
|
|
373
|
+
ZodDefault: () => ZodDefault,
|
|
374
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
375
|
+
ZodEffects: () => ZodEffects,
|
|
376
|
+
ZodEnum: () => ZodEnum,
|
|
377
|
+
ZodError: () => ZodError,
|
|
378
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
379
|
+
ZodFunction: () => ZodFunction,
|
|
380
|
+
ZodIntersection: () => ZodIntersection,
|
|
381
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
382
|
+
ZodLazy: () => ZodLazy,
|
|
383
|
+
ZodLiteral: () => ZodLiteral,
|
|
384
|
+
ZodMap: () => ZodMap,
|
|
385
|
+
ZodNaN: () => ZodNaN,
|
|
386
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
387
|
+
ZodNever: () => ZodNever,
|
|
388
|
+
ZodNull: () => ZodNull,
|
|
389
|
+
ZodNullable: () => ZodNullable,
|
|
390
|
+
ZodNumber: () => ZodNumber,
|
|
391
|
+
ZodObject: () => ZodObject,
|
|
392
|
+
ZodOptional: () => ZodOptional,
|
|
393
|
+
ZodParsedType: () => ZodParsedType,
|
|
394
|
+
ZodPipeline: () => ZodPipeline,
|
|
395
|
+
ZodPromise: () => ZodPromise,
|
|
396
|
+
ZodReadonly: () => ZodReadonly,
|
|
397
|
+
ZodRecord: () => ZodRecord,
|
|
398
|
+
ZodSchema: () => ZodType,
|
|
399
|
+
ZodSet: () => ZodSet,
|
|
400
|
+
ZodString: () => ZodString,
|
|
401
|
+
ZodSymbol: () => ZodSymbol,
|
|
402
|
+
ZodTransformer: () => ZodEffects,
|
|
403
|
+
ZodTuple: () => ZodTuple,
|
|
404
|
+
ZodType: () => ZodType,
|
|
405
|
+
ZodUndefined: () => ZodUndefined,
|
|
406
|
+
ZodUnion: () => ZodUnion,
|
|
407
|
+
ZodUnknown: () => ZodUnknown,
|
|
408
|
+
ZodVoid: () => ZodVoid,
|
|
409
|
+
addIssueToContext: () => addIssueToContext,
|
|
410
|
+
any: () => anyType,
|
|
411
|
+
array: () => arrayType,
|
|
412
|
+
bigint: () => bigIntType,
|
|
413
|
+
boolean: () => booleanType,
|
|
414
|
+
coerce: () => coerce,
|
|
415
|
+
custom: () => custom,
|
|
416
|
+
date: () => dateType,
|
|
417
|
+
datetimeRegex: () => datetimeRegex,
|
|
418
|
+
defaultErrorMap: () => en_default,
|
|
419
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
420
|
+
effect: () => effectsType,
|
|
421
|
+
enum: () => enumType,
|
|
422
|
+
function: () => functionType,
|
|
423
|
+
getErrorMap: () => getErrorMap,
|
|
424
|
+
getParsedType: () => getParsedType,
|
|
425
|
+
instanceof: () => instanceOfType,
|
|
426
|
+
intersection: () => intersectionType,
|
|
427
|
+
isAborted: () => isAborted,
|
|
428
|
+
isAsync: () => isAsync,
|
|
429
|
+
isDirty: () => isDirty,
|
|
430
|
+
isValid: () => isValid,
|
|
431
|
+
late: () => late,
|
|
432
|
+
lazy: () => lazyType,
|
|
433
|
+
literal: () => literalType,
|
|
434
|
+
makeIssue: () => makeIssue,
|
|
435
|
+
map: () => mapType,
|
|
436
|
+
nan: () => nanType,
|
|
437
|
+
nativeEnum: () => nativeEnumType,
|
|
438
|
+
never: () => neverType,
|
|
439
|
+
null: () => nullType,
|
|
440
|
+
nullable: () => nullableType,
|
|
441
|
+
number: () => numberType,
|
|
442
|
+
object: () => objectType,
|
|
443
|
+
objectUtil: () => objectUtil,
|
|
444
|
+
oboolean: () => oboolean,
|
|
445
|
+
onumber: () => onumber,
|
|
446
|
+
optional: () => optionalType,
|
|
447
|
+
ostring: () => ostring,
|
|
448
|
+
pipeline: () => pipelineType,
|
|
449
|
+
preprocess: () => preprocessType,
|
|
450
|
+
promise: () => promiseType,
|
|
451
|
+
quotelessJson: () => quotelessJson,
|
|
452
|
+
record: () => recordType,
|
|
453
|
+
set: () => setType,
|
|
454
|
+
setErrorMap: () => setErrorMap,
|
|
455
|
+
strictObject: () => strictObjectType,
|
|
456
|
+
string: () => stringType,
|
|
457
|
+
symbol: () => symbolType,
|
|
458
|
+
transformer: () => effectsType,
|
|
459
|
+
tuple: () => tupleType,
|
|
460
|
+
undefined: () => undefinedType,
|
|
461
|
+
union: () => unionType,
|
|
462
|
+
unknown: () => unknownType,
|
|
463
|
+
util: () => util,
|
|
464
|
+
void: () => voidType
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// ../../../node_modules/zod/v3/helpers/util.js
|
|
468
|
+
var util;
|
|
469
|
+
(function(util2) {
|
|
470
|
+
util2.assertEqual = (_) => {
|
|
471
|
+
};
|
|
472
|
+
function assertIs(_arg) {
|
|
473
|
+
}
|
|
474
|
+
util2.assertIs = assertIs;
|
|
475
|
+
function assertNever(_x) {
|
|
476
|
+
throw new Error();
|
|
477
|
+
}
|
|
478
|
+
util2.assertNever = assertNever;
|
|
479
|
+
util2.arrayToEnum = (items) => {
|
|
480
|
+
const obj = {};
|
|
481
|
+
for (const item of items) {
|
|
482
|
+
obj[item] = item;
|
|
483
|
+
}
|
|
484
|
+
return obj;
|
|
485
|
+
};
|
|
486
|
+
util2.getValidEnumValues = (obj) => {
|
|
487
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
488
|
+
const filtered = {};
|
|
489
|
+
for (const k of validKeys) {
|
|
490
|
+
filtered[k] = obj[k];
|
|
491
|
+
}
|
|
492
|
+
return util2.objectValues(filtered);
|
|
493
|
+
};
|
|
494
|
+
util2.objectValues = (obj) => {
|
|
495
|
+
return util2.objectKeys(obj).map(function(e2) {
|
|
496
|
+
return obj[e2];
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
500
|
+
const keys = [];
|
|
501
|
+
for (const key in object) {
|
|
502
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
503
|
+
keys.push(key);
|
|
147
504
|
}
|
|
148
505
|
}
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var ViewportConditionZ = z.object({
|
|
202
|
-
type: z.literal("viewport"),
|
|
203
|
-
minWidth: z.number().optional().describe("Minimum viewport width in pixels"),
|
|
204
|
-
maxWidth: z.number().optional().describe("Maximum viewport width in pixels"),
|
|
205
|
-
minHeight: z.number().optional().describe("Minimum viewport height in pixels"),
|
|
206
|
-
maxHeight: z.number().optional().describe("Maximum viewport height in pixels")
|
|
207
|
-
}).describe('Fires based on viewport (screen) size. Use for responsive behavior. Example: {"type": "viewport", "minWidth": 768} \u2014 fires on tablet and larger.');
|
|
208
|
-
var SessionMetricConditionZ = z.object({
|
|
209
|
-
type: z.literal("session_metric"),
|
|
210
|
-
key: SessionMetricKeyZ,
|
|
211
|
-
operator: z.enum(["gte", "lte", "eq", "gt", "lt"]),
|
|
212
|
-
threshold: z.number().describe("Numeric threshold to compare against")
|
|
213
|
-
}).describe('Fires when a session metric crosses a threshold. Valid keys: "time_on_page" (seconds), "page_views" (count), "scroll_depth" (0-100). Example: {"type": "session_metric", "key": "time_on_page", "operator": "gte", "threshold": 30}');
|
|
214
|
-
var DismissedConditionZ = z.object({
|
|
215
|
-
type: z.literal("dismissed"),
|
|
216
|
-
key: z.string().describe("Dismissal key (usually a tile or action ID)"),
|
|
217
|
-
inverted: z.boolean().optional().describe("When true, fires if NOT dismissed (default behavior)")
|
|
218
|
-
}).describe("Checks if an item has been dismissed by the user. Use with inverted: true to show only if not dismissed.");
|
|
219
|
-
var CooldownActiveConditionZ = z.object({
|
|
220
|
-
type: z.literal("cooldown_active"),
|
|
221
|
-
key: z.string().describe("Cooldown key"),
|
|
222
|
-
inverted: z.boolean().optional().describe("When true, fires if cooldown is NOT active")
|
|
223
|
-
}).describe("Checks if a cooldown timer is currently active. Use to prevent showing the same intervention too frequently.");
|
|
224
|
-
var FrequencyLimitConditionZ = z.object({
|
|
225
|
-
type: z.literal("frequency_limit"),
|
|
226
|
-
key: z.string().describe("Frequency counter key"),
|
|
227
|
-
limit: z.number().describe("Maximum allowed count"),
|
|
228
|
-
inverted: z.boolean().optional().describe("When true, fires if limit NOT reached")
|
|
229
|
-
}).describe("Checks if a frequency limit has been reached. Use to cap how many times an action fires per session.");
|
|
230
|
-
var MatchOpZ = z.object({
|
|
231
|
-
equals: z.union([z.string(), z.number(), z.boolean()]).optional(),
|
|
232
|
-
contains: z.string().optional()
|
|
233
|
-
}).refine((operator) => Number(operator.equals !== void 0) + Number(operator.contains !== void 0) === 1, {
|
|
234
|
-
message: "Exactly one of equals or contains must be specified."
|
|
235
|
-
}).describe("Match operator for counter filters. Exactly one of equals or contains must be specified.");
|
|
236
|
-
var CounterDefZ = z.object({
|
|
237
|
-
events: z.array(CountableEventZ).min(1).describe("Event names to count. Use values from the countable events enum."),
|
|
238
|
-
match: z.record(z.string(), MatchOpZ).optional().describe("Property filters. Keys are event prop names or element-chain fields (tag_name, $el_text, attr__*). All entries AND together.")
|
|
239
|
-
}).describe("Defines what events to count. Registered as an accumulator predicate at config-load time.");
|
|
240
|
-
var EventCountConditionZ = z.object({
|
|
241
|
-
type: z.literal("event_count"),
|
|
242
|
-
key: z.string().describe("Unique key for this counter (used for accumulator registration)"),
|
|
243
|
-
operator: z.enum(["gte", "lte", "eq", "gt", "lt"]),
|
|
244
|
-
count: z.number().int().min(0).describe("Target count threshold"),
|
|
245
|
-
withinMs: z.number().positive().optional().describe("Time window in ms. Omit = count across entire session."),
|
|
246
|
-
counter: CounterDefZ.optional().describe("Inline counter definition. Defines what events to count.")
|
|
247
|
-
}).describe('Fires when accumulated event count crosses a threshold. Most powerful trigger type. Example: {"type": "event_count", "key": "pricing-clicks", "operator": "gte", "count": 3, "counter": {"events": ["ui.click"], "match": {"attr__data-cta": {"contains": "pricing"}}}}');
|
|
248
|
-
var ConditionZ = z.discriminatedUnion("type", [
|
|
249
|
-
PageUrlConditionZ,
|
|
250
|
-
RouteConditionZ,
|
|
251
|
-
AnchorVisibleConditionZ,
|
|
252
|
-
EventOccurredConditionZ,
|
|
253
|
-
StateEqualsConditionZ,
|
|
254
|
-
ViewportConditionZ,
|
|
255
|
-
SessionMetricConditionZ,
|
|
256
|
-
DismissedConditionZ,
|
|
257
|
-
CooldownActiveConditionZ,
|
|
258
|
-
FrequencyLimitConditionZ,
|
|
259
|
-
EventCountConditionZ
|
|
506
|
+
return keys;
|
|
507
|
+
};
|
|
508
|
+
util2.find = (arr, checker) => {
|
|
509
|
+
for (const item of arr) {
|
|
510
|
+
if (checker(item))
|
|
511
|
+
return item;
|
|
512
|
+
}
|
|
513
|
+
return void 0;
|
|
514
|
+
};
|
|
515
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
516
|
+
function joinValues(array, separator = " | ") {
|
|
517
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
518
|
+
}
|
|
519
|
+
util2.joinValues = joinValues;
|
|
520
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
521
|
+
if (typeof value === "bigint") {
|
|
522
|
+
return value.toString();
|
|
523
|
+
}
|
|
524
|
+
return value;
|
|
525
|
+
};
|
|
526
|
+
})(util || (util = {}));
|
|
527
|
+
var objectUtil;
|
|
528
|
+
(function(objectUtil2) {
|
|
529
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
530
|
+
return {
|
|
531
|
+
...first,
|
|
532
|
+
...second
|
|
533
|
+
// second overwrites first
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
})(objectUtil || (objectUtil = {}));
|
|
537
|
+
var ZodParsedType = util.arrayToEnum([
|
|
538
|
+
"string",
|
|
539
|
+
"nan",
|
|
540
|
+
"number",
|
|
541
|
+
"integer",
|
|
542
|
+
"float",
|
|
543
|
+
"boolean",
|
|
544
|
+
"date",
|
|
545
|
+
"bigint",
|
|
546
|
+
"symbol",
|
|
547
|
+
"function",
|
|
548
|
+
"undefined",
|
|
549
|
+
"null",
|
|
550
|
+
"array",
|
|
551
|
+
"object",
|
|
552
|
+
"unknown",
|
|
553
|
+
"promise",
|
|
554
|
+
"void",
|
|
555
|
+
"never",
|
|
556
|
+
"map",
|
|
557
|
+
"set"
|
|
260
558
|
]);
|
|
261
|
-
var
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
559
|
+
var getParsedType = (data) => {
|
|
560
|
+
const t2 = typeof data;
|
|
561
|
+
switch (t2) {
|
|
562
|
+
case "undefined":
|
|
563
|
+
return ZodParsedType.undefined;
|
|
564
|
+
case "string":
|
|
565
|
+
return ZodParsedType.string;
|
|
566
|
+
case "number":
|
|
567
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
568
|
+
case "boolean":
|
|
569
|
+
return ZodParsedType.boolean;
|
|
570
|
+
case "function":
|
|
571
|
+
return ZodParsedType.function;
|
|
572
|
+
case "bigint":
|
|
573
|
+
return ZodParsedType.bigint;
|
|
574
|
+
case "symbol":
|
|
575
|
+
return ZodParsedType.symbol;
|
|
576
|
+
case "object":
|
|
577
|
+
if (Array.isArray(data)) {
|
|
578
|
+
return ZodParsedType.array;
|
|
579
|
+
}
|
|
580
|
+
if (data === null) {
|
|
581
|
+
return ZodParsedType.null;
|
|
582
|
+
}
|
|
583
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
584
|
+
return ZodParsedType.promise;
|
|
585
|
+
}
|
|
586
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
587
|
+
return ZodParsedType.map;
|
|
588
|
+
}
|
|
589
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
590
|
+
return ZodParsedType.set;
|
|
591
|
+
}
|
|
592
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
593
|
+
return ZodParsedType.date;
|
|
594
|
+
}
|
|
595
|
+
return ZodParsedType.object;
|
|
596
|
+
default:
|
|
597
|
+
return ZodParsedType.unknown;
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// ../../../node_modules/zod/v3/ZodError.js
|
|
602
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
603
|
+
"invalid_type",
|
|
604
|
+
"invalid_literal",
|
|
605
|
+
"custom",
|
|
606
|
+
"invalid_union",
|
|
607
|
+
"invalid_union_discriminator",
|
|
608
|
+
"invalid_enum_value",
|
|
609
|
+
"unrecognized_keys",
|
|
610
|
+
"invalid_arguments",
|
|
611
|
+
"invalid_return_type",
|
|
612
|
+
"invalid_date",
|
|
613
|
+
"invalid_string",
|
|
614
|
+
"too_small",
|
|
615
|
+
"too_big",
|
|
616
|
+
"invalid_intersection_types",
|
|
617
|
+
"not_multiple_of",
|
|
618
|
+
"not_finite"
|
|
296
619
|
]);
|
|
297
|
-
var
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
620
|
+
var quotelessJson = (obj) => {
|
|
621
|
+
const json = JSON.stringify(obj, null, 2);
|
|
622
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
623
|
+
};
|
|
624
|
+
var ZodError = class _ZodError extends Error {
|
|
625
|
+
get errors() {
|
|
626
|
+
return this.issues;
|
|
627
|
+
}
|
|
628
|
+
constructor(issues) {
|
|
629
|
+
super();
|
|
630
|
+
this.issues = [];
|
|
631
|
+
this.addIssue = (sub) => {
|
|
632
|
+
this.issues = [...this.issues, sub];
|
|
633
|
+
};
|
|
634
|
+
this.addIssues = (subs = []) => {
|
|
635
|
+
this.issues = [...this.issues, ...subs];
|
|
636
|
+
};
|
|
637
|
+
const actualProto = new.target.prototype;
|
|
638
|
+
if (Object.setPrototypeOf) {
|
|
639
|
+
Object.setPrototypeOf(this, actualProto);
|
|
640
|
+
} else {
|
|
641
|
+
this.__proto__ = actualProto;
|
|
642
|
+
}
|
|
643
|
+
this.name = "ZodError";
|
|
644
|
+
this.issues = issues;
|
|
645
|
+
}
|
|
646
|
+
format(_mapper) {
|
|
647
|
+
const mapper = _mapper || function(issue) {
|
|
648
|
+
return issue.message;
|
|
649
|
+
};
|
|
650
|
+
const fieldErrors = { _errors: [] };
|
|
651
|
+
const processError = (error) => {
|
|
652
|
+
for (const issue of error.issues) {
|
|
653
|
+
if (issue.code === "invalid_union") {
|
|
654
|
+
issue.unionErrors.map(processError);
|
|
655
|
+
} else if (issue.code === "invalid_return_type") {
|
|
656
|
+
processError(issue.returnTypeError);
|
|
657
|
+
} else if (issue.code === "invalid_arguments") {
|
|
658
|
+
processError(issue.argumentsError);
|
|
659
|
+
} else if (issue.path.length === 0) {
|
|
660
|
+
fieldErrors._errors.push(mapper(issue));
|
|
661
|
+
} else {
|
|
662
|
+
let curr = fieldErrors;
|
|
663
|
+
let i2 = 0;
|
|
664
|
+
while (i2 < issue.path.length) {
|
|
665
|
+
const el = issue.path[i2];
|
|
666
|
+
const terminal = i2 === issue.path.length - 1;
|
|
667
|
+
if (!terminal) {
|
|
668
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
669
|
+
} else {
|
|
670
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
671
|
+
curr[el]._errors.push(mapper(issue));
|
|
672
|
+
}
|
|
673
|
+
curr = curr[el];
|
|
674
|
+
i2++;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
processError(this);
|
|
680
|
+
return fieldErrors;
|
|
681
|
+
}
|
|
682
|
+
static assert(value) {
|
|
683
|
+
if (!(value instanceof _ZodError)) {
|
|
684
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
toString() {
|
|
688
|
+
return this.message;
|
|
689
|
+
}
|
|
690
|
+
get message() {
|
|
691
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
692
|
+
}
|
|
693
|
+
get isEmpty() {
|
|
694
|
+
return this.issues.length === 0;
|
|
695
|
+
}
|
|
696
|
+
flatten(mapper = (issue) => issue.message) {
|
|
697
|
+
const fieldErrors = {};
|
|
698
|
+
const formErrors = [];
|
|
699
|
+
for (const sub of this.issues) {
|
|
700
|
+
if (sub.path.length > 0) {
|
|
701
|
+
const firstEl = sub.path[0];
|
|
702
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
703
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
704
|
+
} else {
|
|
705
|
+
formErrors.push(mapper(sub));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return { formErrors, fieldErrors };
|
|
709
|
+
}
|
|
710
|
+
get formErrors() {
|
|
711
|
+
return this.flatten();
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
ZodError.create = (issues) => {
|
|
715
|
+
const error = new ZodError(issues);
|
|
716
|
+
return error;
|
|
717
|
+
};
|
|
308
718
|
|
|
309
|
-
//
|
|
310
|
-
var
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
719
|
+
// ../../../node_modules/zod/v3/locales/en.js
|
|
720
|
+
var errorMap = (issue, _ctx) => {
|
|
721
|
+
let message;
|
|
722
|
+
switch (issue.code) {
|
|
723
|
+
case ZodIssueCode.invalid_type:
|
|
724
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
725
|
+
message = "Required";
|
|
726
|
+
} else {
|
|
727
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
728
|
+
}
|
|
729
|
+
break;
|
|
730
|
+
case ZodIssueCode.invalid_literal:
|
|
731
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
732
|
+
break;
|
|
733
|
+
case ZodIssueCode.unrecognized_keys:
|
|
734
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
735
|
+
break;
|
|
736
|
+
case ZodIssueCode.invalid_union:
|
|
737
|
+
message = `Invalid input`;
|
|
738
|
+
break;
|
|
739
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
740
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
741
|
+
break;
|
|
742
|
+
case ZodIssueCode.invalid_enum_value:
|
|
743
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
744
|
+
break;
|
|
745
|
+
case ZodIssueCode.invalid_arguments:
|
|
746
|
+
message = `Invalid function arguments`;
|
|
747
|
+
break;
|
|
748
|
+
case ZodIssueCode.invalid_return_type:
|
|
749
|
+
message = `Invalid function return type`;
|
|
750
|
+
break;
|
|
751
|
+
case ZodIssueCode.invalid_date:
|
|
752
|
+
message = `Invalid date`;
|
|
753
|
+
break;
|
|
754
|
+
case ZodIssueCode.invalid_string:
|
|
755
|
+
if (typeof issue.validation === "object") {
|
|
756
|
+
if ("includes" in issue.validation) {
|
|
757
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
758
|
+
if (typeof issue.validation.position === "number") {
|
|
759
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
760
|
+
}
|
|
761
|
+
} else if ("startsWith" in issue.validation) {
|
|
762
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
763
|
+
} else if ("endsWith" in issue.validation) {
|
|
764
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
765
|
+
} else {
|
|
766
|
+
util.assertNever(issue.validation);
|
|
767
|
+
}
|
|
768
|
+
} else if (issue.validation !== "regex") {
|
|
769
|
+
message = `Invalid ${issue.validation}`;
|
|
770
|
+
} else {
|
|
771
|
+
message = "Invalid";
|
|
772
|
+
}
|
|
773
|
+
break;
|
|
774
|
+
case ZodIssueCode.too_small:
|
|
775
|
+
if (issue.type === "array")
|
|
776
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
777
|
+
else if (issue.type === "string")
|
|
778
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
779
|
+
else if (issue.type === "number")
|
|
780
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
781
|
+
else if (issue.type === "bigint")
|
|
782
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
783
|
+
else if (issue.type === "date")
|
|
784
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
785
|
+
else
|
|
786
|
+
message = "Invalid input";
|
|
787
|
+
break;
|
|
788
|
+
case ZodIssueCode.too_big:
|
|
789
|
+
if (issue.type === "array")
|
|
790
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
791
|
+
else if (issue.type === "string")
|
|
792
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
793
|
+
else if (issue.type === "number")
|
|
794
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
795
|
+
else if (issue.type === "bigint")
|
|
796
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
797
|
+
else if (issue.type === "date")
|
|
798
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
799
|
+
else
|
|
800
|
+
message = "Invalid input";
|
|
801
|
+
break;
|
|
802
|
+
case ZodIssueCode.custom:
|
|
803
|
+
message = `Invalid input`;
|
|
804
|
+
break;
|
|
805
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
806
|
+
message = `Intersection results could not be merged`;
|
|
807
|
+
break;
|
|
808
|
+
case ZodIssueCode.not_multiple_of:
|
|
809
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
810
|
+
break;
|
|
811
|
+
case ZodIssueCode.not_finite:
|
|
812
|
+
message = "Number must be finite";
|
|
813
|
+
break;
|
|
814
|
+
default:
|
|
815
|
+
message = _ctx.defaultError;
|
|
816
|
+
util.assertNever(issue);
|
|
817
|
+
}
|
|
818
|
+
return { message };
|
|
819
|
+
};
|
|
820
|
+
var en_default = errorMap;
|
|
821
|
+
|
|
822
|
+
// ../../../node_modules/zod/v3/errors.js
|
|
823
|
+
var overrideErrorMap = en_default;
|
|
824
|
+
function setErrorMap(map) {
|
|
825
|
+
overrideErrorMap = map;
|
|
826
|
+
}
|
|
827
|
+
function getErrorMap() {
|
|
828
|
+
return overrideErrorMap;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// ../../../node_modules/zod/v3/helpers/parseUtil.js
|
|
832
|
+
var makeIssue = (params) => {
|
|
833
|
+
const { data, path, errorMaps, issueData } = params;
|
|
834
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
835
|
+
const fullIssue = {
|
|
836
|
+
...issueData,
|
|
837
|
+
path: fullPath
|
|
838
|
+
};
|
|
839
|
+
if (issueData.message !== void 0) {
|
|
840
|
+
return {
|
|
841
|
+
...issueData,
|
|
842
|
+
path: fullPath,
|
|
843
|
+
message: issueData.message
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
let errorMessage = "";
|
|
847
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
848
|
+
for (const map of maps) {
|
|
849
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
...issueData,
|
|
853
|
+
path: fullPath,
|
|
854
|
+
message: errorMessage
|
|
855
|
+
};
|
|
856
|
+
};
|
|
857
|
+
var EMPTY_PATH = [];
|
|
858
|
+
function addIssueToContext(ctx, issueData) {
|
|
859
|
+
const overrideMap = getErrorMap();
|
|
860
|
+
const issue = makeIssue({
|
|
861
|
+
issueData,
|
|
862
|
+
data: ctx.data,
|
|
863
|
+
path: ctx.path,
|
|
864
|
+
errorMaps: [
|
|
865
|
+
ctx.common.contextualErrorMap,
|
|
866
|
+
// contextual error map is first priority
|
|
867
|
+
ctx.schemaErrorMap,
|
|
868
|
+
// then schema-bound map if available
|
|
869
|
+
overrideMap,
|
|
870
|
+
// then global override map
|
|
871
|
+
overrideMap === en_default ? void 0 : en_default
|
|
872
|
+
// then global default map
|
|
873
|
+
].filter((x) => !!x)
|
|
874
|
+
});
|
|
875
|
+
ctx.common.issues.push(issue);
|
|
876
|
+
}
|
|
877
|
+
var ParseStatus = class _ParseStatus {
|
|
878
|
+
constructor() {
|
|
879
|
+
this.value = "valid";
|
|
880
|
+
}
|
|
881
|
+
dirty() {
|
|
882
|
+
if (this.value === "valid")
|
|
883
|
+
this.value = "dirty";
|
|
884
|
+
}
|
|
885
|
+
abort() {
|
|
886
|
+
if (this.value !== "aborted")
|
|
887
|
+
this.value = "aborted";
|
|
888
|
+
}
|
|
889
|
+
static mergeArray(status, results) {
|
|
890
|
+
const arrayValue = [];
|
|
891
|
+
for (const s4 of results) {
|
|
892
|
+
if (s4.status === "aborted")
|
|
893
|
+
return INVALID;
|
|
894
|
+
if (s4.status === "dirty")
|
|
895
|
+
status.dirty();
|
|
896
|
+
arrayValue.push(s4.value);
|
|
897
|
+
}
|
|
898
|
+
return { status: status.value, value: arrayValue };
|
|
899
|
+
}
|
|
900
|
+
static async mergeObjectAsync(status, pairs) {
|
|
901
|
+
const syncPairs = [];
|
|
902
|
+
for (const pair of pairs) {
|
|
903
|
+
const key = await pair.key;
|
|
904
|
+
const value = await pair.value;
|
|
905
|
+
syncPairs.push({
|
|
906
|
+
key,
|
|
907
|
+
value
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
911
|
+
}
|
|
912
|
+
static mergeObjectSync(status, pairs) {
|
|
913
|
+
const finalObject = {};
|
|
914
|
+
for (const pair of pairs) {
|
|
915
|
+
const { key, value } = pair;
|
|
916
|
+
if (key.status === "aborted")
|
|
917
|
+
return INVALID;
|
|
918
|
+
if (value.status === "aborted")
|
|
919
|
+
return INVALID;
|
|
920
|
+
if (key.status === "dirty")
|
|
921
|
+
status.dirty();
|
|
922
|
+
if (value.status === "dirty")
|
|
923
|
+
status.dirty();
|
|
924
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
925
|
+
finalObject[key.value] = value.value;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return { status: status.value, value: finalObject };
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
var INVALID = Object.freeze({
|
|
932
|
+
status: "aborted"
|
|
933
|
+
});
|
|
934
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
935
|
+
var OK = (value) => ({ status: "valid", value });
|
|
936
|
+
var isAborted = (x) => x.status === "aborted";
|
|
937
|
+
var isDirty = (x) => x.status === "dirty";
|
|
938
|
+
var isValid = (x) => x.status === "valid";
|
|
939
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
940
|
+
|
|
941
|
+
// ../../../node_modules/zod/v3/helpers/errorUtil.js
|
|
942
|
+
var errorUtil;
|
|
943
|
+
(function(errorUtil2) {
|
|
944
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
945
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
946
|
+
})(errorUtil || (errorUtil = {}));
|
|
947
|
+
|
|
948
|
+
// ../../../node_modules/zod/v3/types.js
|
|
949
|
+
var ParseInputLazyPath = class {
|
|
950
|
+
constructor(parent, value, path, key) {
|
|
951
|
+
this._cachedPath = [];
|
|
952
|
+
this.parent = parent;
|
|
953
|
+
this.data = value;
|
|
954
|
+
this._path = path;
|
|
955
|
+
this._key = key;
|
|
956
|
+
}
|
|
957
|
+
get path() {
|
|
958
|
+
if (!this._cachedPath.length) {
|
|
959
|
+
if (Array.isArray(this._key)) {
|
|
960
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
961
|
+
} else {
|
|
962
|
+
this._cachedPath.push(...this._path, this._key);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return this._cachedPath;
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
var handleResult = (ctx, result) => {
|
|
969
|
+
if (isValid(result)) {
|
|
970
|
+
return { success: true, data: result.value };
|
|
971
|
+
} else {
|
|
972
|
+
if (!ctx.common.issues.length) {
|
|
973
|
+
throw new Error("Validation failed but no issues detected.");
|
|
974
|
+
}
|
|
975
|
+
return {
|
|
976
|
+
success: false,
|
|
977
|
+
get error() {
|
|
978
|
+
if (this._error)
|
|
979
|
+
return this._error;
|
|
980
|
+
const error = new ZodError(ctx.common.issues);
|
|
981
|
+
this._error = error;
|
|
982
|
+
return this._error;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
function processCreateParams(params) {
|
|
988
|
+
if (!params)
|
|
989
|
+
return {};
|
|
990
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
991
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
992
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
993
|
+
}
|
|
994
|
+
if (errorMap2)
|
|
995
|
+
return { errorMap: errorMap2, description };
|
|
996
|
+
const customMap = (iss, ctx) => {
|
|
997
|
+
const { message } = params;
|
|
998
|
+
if (iss.code === "invalid_enum_value") {
|
|
999
|
+
return { message: message ?? ctx.defaultError };
|
|
1000
|
+
}
|
|
1001
|
+
if (typeof ctx.data === "undefined") {
|
|
1002
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
1003
|
+
}
|
|
1004
|
+
if (iss.code !== "invalid_type")
|
|
1005
|
+
return { message: ctx.defaultError };
|
|
1006
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
1007
|
+
};
|
|
1008
|
+
return { errorMap: customMap, description };
|
|
1009
|
+
}
|
|
1010
|
+
var ZodType = class {
|
|
1011
|
+
get description() {
|
|
1012
|
+
return this._def.description;
|
|
1013
|
+
}
|
|
1014
|
+
_getType(input) {
|
|
1015
|
+
return getParsedType(input.data);
|
|
1016
|
+
}
|
|
1017
|
+
_getOrReturnCtx(input, ctx) {
|
|
1018
|
+
return ctx || {
|
|
1019
|
+
common: input.parent.common,
|
|
1020
|
+
data: input.data,
|
|
1021
|
+
parsedType: getParsedType(input.data),
|
|
1022
|
+
schemaErrorMap: this._def.errorMap,
|
|
1023
|
+
path: input.path,
|
|
1024
|
+
parent: input.parent
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
_processInputParams(input) {
|
|
1028
|
+
return {
|
|
1029
|
+
status: new ParseStatus(),
|
|
1030
|
+
ctx: {
|
|
1031
|
+
common: input.parent.common,
|
|
1032
|
+
data: input.data,
|
|
1033
|
+
parsedType: getParsedType(input.data),
|
|
1034
|
+
schemaErrorMap: this._def.errorMap,
|
|
1035
|
+
path: input.path,
|
|
1036
|
+
parent: input.parent
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
_parseSync(input) {
|
|
1041
|
+
const result = this._parse(input);
|
|
1042
|
+
if (isAsync(result)) {
|
|
1043
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
1044
|
+
}
|
|
1045
|
+
return result;
|
|
1046
|
+
}
|
|
1047
|
+
_parseAsync(input) {
|
|
1048
|
+
const result = this._parse(input);
|
|
1049
|
+
return Promise.resolve(result);
|
|
1050
|
+
}
|
|
1051
|
+
parse(data, params) {
|
|
1052
|
+
const result = this.safeParse(data, params);
|
|
1053
|
+
if (result.success)
|
|
1054
|
+
return result.data;
|
|
1055
|
+
throw result.error;
|
|
1056
|
+
}
|
|
1057
|
+
safeParse(data, params) {
|
|
1058
|
+
const ctx = {
|
|
1059
|
+
common: {
|
|
1060
|
+
issues: [],
|
|
1061
|
+
async: params?.async ?? false,
|
|
1062
|
+
contextualErrorMap: params?.errorMap
|
|
1063
|
+
},
|
|
1064
|
+
path: params?.path || [],
|
|
1065
|
+
schemaErrorMap: this._def.errorMap,
|
|
1066
|
+
parent: null,
|
|
1067
|
+
data,
|
|
1068
|
+
parsedType: getParsedType(data)
|
|
1069
|
+
};
|
|
1070
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
1071
|
+
return handleResult(ctx, result);
|
|
1072
|
+
}
|
|
1073
|
+
"~validate"(data) {
|
|
1074
|
+
const ctx = {
|
|
1075
|
+
common: {
|
|
1076
|
+
issues: [],
|
|
1077
|
+
async: !!this["~standard"].async
|
|
1078
|
+
},
|
|
1079
|
+
path: [],
|
|
1080
|
+
schemaErrorMap: this._def.errorMap,
|
|
1081
|
+
parent: null,
|
|
1082
|
+
data,
|
|
1083
|
+
parsedType: getParsedType(data)
|
|
1084
|
+
};
|
|
1085
|
+
if (!this["~standard"].async) {
|
|
1086
|
+
try {
|
|
1087
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
1088
|
+
return isValid(result) ? {
|
|
1089
|
+
value: result.value
|
|
1090
|
+
} : {
|
|
1091
|
+
issues: ctx.common.issues
|
|
1092
|
+
};
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
1095
|
+
this["~standard"].async = true;
|
|
1096
|
+
}
|
|
1097
|
+
ctx.common = {
|
|
1098
|
+
issues: [],
|
|
1099
|
+
async: true
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
1104
|
+
value: result.value
|
|
1105
|
+
} : {
|
|
1106
|
+
issues: ctx.common.issues
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
async parseAsync(data, params) {
|
|
1110
|
+
const result = await this.safeParseAsync(data, params);
|
|
1111
|
+
if (result.success)
|
|
1112
|
+
return result.data;
|
|
1113
|
+
throw result.error;
|
|
1114
|
+
}
|
|
1115
|
+
async safeParseAsync(data, params) {
|
|
1116
|
+
const ctx = {
|
|
1117
|
+
common: {
|
|
1118
|
+
issues: [],
|
|
1119
|
+
contextualErrorMap: params?.errorMap,
|
|
1120
|
+
async: true
|
|
1121
|
+
},
|
|
1122
|
+
path: params?.path || [],
|
|
1123
|
+
schemaErrorMap: this._def.errorMap,
|
|
1124
|
+
parent: null,
|
|
1125
|
+
data,
|
|
1126
|
+
parsedType: getParsedType(data)
|
|
1127
|
+
};
|
|
1128
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
1129
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
1130
|
+
return handleResult(ctx, result);
|
|
1131
|
+
}
|
|
1132
|
+
refine(check, message) {
|
|
1133
|
+
const getIssueProperties = (val) => {
|
|
1134
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
1135
|
+
return { message };
|
|
1136
|
+
} else if (typeof message === "function") {
|
|
1137
|
+
return message(val);
|
|
1138
|
+
} else {
|
|
1139
|
+
return message;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
return this._refinement((val, ctx) => {
|
|
1143
|
+
const result = check(val);
|
|
1144
|
+
const setError = () => ctx.addIssue({
|
|
1145
|
+
code: ZodIssueCode.custom,
|
|
1146
|
+
...getIssueProperties(val)
|
|
1147
|
+
});
|
|
1148
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
1149
|
+
return result.then((data) => {
|
|
1150
|
+
if (!data) {
|
|
1151
|
+
setError();
|
|
1152
|
+
return false;
|
|
1153
|
+
} else {
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
if (!result) {
|
|
1159
|
+
setError();
|
|
1160
|
+
return false;
|
|
1161
|
+
} else {
|
|
1162
|
+
return true;
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
refinement(check, refinementData) {
|
|
1167
|
+
return this._refinement((val, ctx) => {
|
|
1168
|
+
if (!check(val)) {
|
|
1169
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
1170
|
+
return false;
|
|
1171
|
+
} else {
|
|
1172
|
+
return true;
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
_refinement(refinement) {
|
|
1177
|
+
return new ZodEffects({
|
|
1178
|
+
schema: this,
|
|
1179
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1180
|
+
effect: { type: "refinement", refinement }
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
superRefine(refinement) {
|
|
1184
|
+
return this._refinement(refinement);
|
|
1185
|
+
}
|
|
1186
|
+
constructor(def) {
|
|
1187
|
+
this.spa = this.safeParseAsync;
|
|
1188
|
+
this._def = def;
|
|
1189
|
+
this.parse = this.parse.bind(this);
|
|
1190
|
+
this.safeParse = this.safeParse.bind(this);
|
|
1191
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
1192
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
1193
|
+
this.spa = this.spa.bind(this);
|
|
1194
|
+
this.refine = this.refine.bind(this);
|
|
1195
|
+
this.refinement = this.refinement.bind(this);
|
|
1196
|
+
this.superRefine = this.superRefine.bind(this);
|
|
1197
|
+
this.optional = this.optional.bind(this);
|
|
1198
|
+
this.nullable = this.nullable.bind(this);
|
|
1199
|
+
this.nullish = this.nullish.bind(this);
|
|
1200
|
+
this.array = this.array.bind(this);
|
|
1201
|
+
this.promise = this.promise.bind(this);
|
|
1202
|
+
this.or = this.or.bind(this);
|
|
1203
|
+
this.and = this.and.bind(this);
|
|
1204
|
+
this.transform = this.transform.bind(this);
|
|
1205
|
+
this.brand = this.brand.bind(this);
|
|
1206
|
+
this.default = this.default.bind(this);
|
|
1207
|
+
this.catch = this.catch.bind(this);
|
|
1208
|
+
this.describe = this.describe.bind(this);
|
|
1209
|
+
this.pipe = this.pipe.bind(this);
|
|
1210
|
+
this.readonly = this.readonly.bind(this);
|
|
1211
|
+
this.isNullable = this.isNullable.bind(this);
|
|
1212
|
+
this.isOptional = this.isOptional.bind(this);
|
|
1213
|
+
this["~standard"] = {
|
|
1214
|
+
version: 1,
|
|
1215
|
+
vendor: "zod",
|
|
1216
|
+
validate: (data) => this["~validate"](data)
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
optional() {
|
|
1220
|
+
return ZodOptional.create(this, this._def);
|
|
1221
|
+
}
|
|
1222
|
+
nullable() {
|
|
1223
|
+
return ZodNullable.create(this, this._def);
|
|
1224
|
+
}
|
|
1225
|
+
nullish() {
|
|
1226
|
+
return this.nullable().optional();
|
|
1227
|
+
}
|
|
1228
|
+
array() {
|
|
1229
|
+
return ZodArray.create(this);
|
|
1230
|
+
}
|
|
1231
|
+
promise() {
|
|
1232
|
+
return ZodPromise.create(this, this._def);
|
|
1233
|
+
}
|
|
1234
|
+
or(option) {
|
|
1235
|
+
return ZodUnion.create([this, option], this._def);
|
|
1236
|
+
}
|
|
1237
|
+
and(incoming) {
|
|
1238
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
1239
|
+
}
|
|
1240
|
+
transform(transform) {
|
|
1241
|
+
return new ZodEffects({
|
|
1242
|
+
...processCreateParams(this._def),
|
|
1243
|
+
schema: this,
|
|
1244
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1245
|
+
effect: { type: "transform", transform }
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
default(def) {
|
|
1249
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1250
|
+
return new ZodDefault({
|
|
1251
|
+
...processCreateParams(this._def),
|
|
1252
|
+
innerType: this,
|
|
1253
|
+
defaultValue: defaultValueFunc,
|
|
1254
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
brand() {
|
|
1258
|
+
return new ZodBranded({
|
|
1259
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1260
|
+
type: this,
|
|
1261
|
+
...processCreateParams(this._def)
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
catch(def) {
|
|
1265
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1266
|
+
return new ZodCatch({
|
|
1267
|
+
...processCreateParams(this._def),
|
|
1268
|
+
innerType: this,
|
|
1269
|
+
catchValue: catchValueFunc,
|
|
1270
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
describe(description) {
|
|
1274
|
+
const This = this.constructor;
|
|
1275
|
+
return new This({
|
|
1276
|
+
...this._def,
|
|
1277
|
+
description
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
pipe(target) {
|
|
1281
|
+
return ZodPipeline.create(this, target);
|
|
1282
|
+
}
|
|
1283
|
+
readonly() {
|
|
1284
|
+
return ZodReadonly.create(this);
|
|
1285
|
+
}
|
|
1286
|
+
isOptional() {
|
|
1287
|
+
return this.safeParse(void 0).success;
|
|
1288
|
+
}
|
|
1289
|
+
isNullable() {
|
|
1290
|
+
return this.safeParse(null).success;
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1294
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1295
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1296
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
1297
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1298
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1299
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1300
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1301
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1302
|
+
var emojiRegex;
|
|
1303
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1304
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
1305
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1306
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1307
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1308
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1309
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1310
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1311
|
+
function timeRegexSource(args) {
|
|
1312
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1313
|
+
if (args.precision) {
|
|
1314
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1315
|
+
} else if (args.precision == null) {
|
|
1316
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1317
|
+
}
|
|
1318
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1319
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1320
|
+
}
|
|
1321
|
+
function timeRegex(args) {
|
|
1322
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1323
|
+
}
|
|
1324
|
+
function datetimeRegex(args) {
|
|
1325
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1326
|
+
const opts = [];
|
|
1327
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1328
|
+
if (args.offset)
|
|
1329
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1330
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1331
|
+
return new RegExp(`^${regex}$`);
|
|
1332
|
+
}
|
|
1333
|
+
function isValidIP(ip, version) {
|
|
1334
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1335
|
+
return true;
|
|
1336
|
+
}
|
|
1337
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
return false;
|
|
1341
|
+
}
|
|
1342
|
+
function isValidJWT(jwt, alg) {
|
|
1343
|
+
if (!jwtRegex.test(jwt))
|
|
1344
|
+
return false;
|
|
1345
|
+
try {
|
|
1346
|
+
const [header] = jwt.split(".");
|
|
1347
|
+
if (!header)
|
|
1348
|
+
return false;
|
|
1349
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1350
|
+
const decoded = JSON.parse(atob(base64));
|
|
1351
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1352
|
+
return false;
|
|
1353
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1354
|
+
return false;
|
|
1355
|
+
if (!decoded.alg)
|
|
1356
|
+
return false;
|
|
1357
|
+
if (alg && decoded.alg !== alg)
|
|
1358
|
+
return false;
|
|
1359
|
+
return true;
|
|
1360
|
+
} catch {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function isValidCidr(ip, version) {
|
|
1365
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1366
|
+
return true;
|
|
1367
|
+
}
|
|
1368
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1369
|
+
return true;
|
|
1370
|
+
}
|
|
1371
|
+
return false;
|
|
1372
|
+
}
|
|
1373
|
+
var ZodString = class _ZodString extends ZodType {
|
|
1374
|
+
_parse(input) {
|
|
1375
|
+
if (this._def.coerce) {
|
|
1376
|
+
input.data = String(input.data);
|
|
1377
|
+
}
|
|
1378
|
+
const parsedType = this._getType(input);
|
|
1379
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1380
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1381
|
+
addIssueToContext(ctx2, {
|
|
1382
|
+
code: ZodIssueCode.invalid_type,
|
|
1383
|
+
expected: ZodParsedType.string,
|
|
1384
|
+
received: ctx2.parsedType
|
|
1385
|
+
});
|
|
1386
|
+
return INVALID;
|
|
1387
|
+
}
|
|
1388
|
+
const status = new ParseStatus();
|
|
1389
|
+
let ctx = void 0;
|
|
1390
|
+
for (const check of this._def.checks) {
|
|
1391
|
+
if (check.kind === "min") {
|
|
1392
|
+
if (input.data.length < check.value) {
|
|
1393
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1394
|
+
addIssueToContext(ctx, {
|
|
1395
|
+
code: ZodIssueCode.too_small,
|
|
1396
|
+
minimum: check.value,
|
|
1397
|
+
type: "string",
|
|
1398
|
+
inclusive: true,
|
|
1399
|
+
exact: false,
|
|
1400
|
+
message: check.message
|
|
1401
|
+
});
|
|
1402
|
+
status.dirty();
|
|
1403
|
+
}
|
|
1404
|
+
} else if (check.kind === "max") {
|
|
1405
|
+
if (input.data.length > check.value) {
|
|
1406
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1407
|
+
addIssueToContext(ctx, {
|
|
1408
|
+
code: ZodIssueCode.too_big,
|
|
1409
|
+
maximum: check.value,
|
|
1410
|
+
type: "string",
|
|
1411
|
+
inclusive: true,
|
|
1412
|
+
exact: false,
|
|
1413
|
+
message: check.message
|
|
1414
|
+
});
|
|
1415
|
+
status.dirty();
|
|
1416
|
+
}
|
|
1417
|
+
} else if (check.kind === "length") {
|
|
1418
|
+
const tooBig = input.data.length > check.value;
|
|
1419
|
+
const tooSmall = input.data.length < check.value;
|
|
1420
|
+
if (tooBig || tooSmall) {
|
|
1421
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1422
|
+
if (tooBig) {
|
|
1423
|
+
addIssueToContext(ctx, {
|
|
1424
|
+
code: ZodIssueCode.too_big,
|
|
1425
|
+
maximum: check.value,
|
|
1426
|
+
type: "string",
|
|
1427
|
+
inclusive: true,
|
|
1428
|
+
exact: true,
|
|
1429
|
+
message: check.message
|
|
1430
|
+
});
|
|
1431
|
+
} else if (tooSmall) {
|
|
1432
|
+
addIssueToContext(ctx, {
|
|
1433
|
+
code: ZodIssueCode.too_small,
|
|
1434
|
+
minimum: check.value,
|
|
1435
|
+
type: "string",
|
|
1436
|
+
inclusive: true,
|
|
1437
|
+
exact: true,
|
|
1438
|
+
message: check.message
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
status.dirty();
|
|
1442
|
+
}
|
|
1443
|
+
} else if (check.kind === "email") {
|
|
1444
|
+
if (!emailRegex.test(input.data)) {
|
|
1445
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1446
|
+
addIssueToContext(ctx, {
|
|
1447
|
+
validation: "email",
|
|
1448
|
+
code: ZodIssueCode.invalid_string,
|
|
1449
|
+
message: check.message
|
|
1450
|
+
});
|
|
1451
|
+
status.dirty();
|
|
1452
|
+
}
|
|
1453
|
+
} else if (check.kind === "emoji") {
|
|
1454
|
+
if (!emojiRegex) {
|
|
1455
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1456
|
+
}
|
|
1457
|
+
if (!emojiRegex.test(input.data)) {
|
|
1458
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1459
|
+
addIssueToContext(ctx, {
|
|
1460
|
+
validation: "emoji",
|
|
1461
|
+
code: ZodIssueCode.invalid_string,
|
|
1462
|
+
message: check.message
|
|
1463
|
+
});
|
|
1464
|
+
status.dirty();
|
|
1465
|
+
}
|
|
1466
|
+
} else if (check.kind === "uuid") {
|
|
1467
|
+
if (!uuidRegex.test(input.data)) {
|
|
1468
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1469
|
+
addIssueToContext(ctx, {
|
|
1470
|
+
validation: "uuid",
|
|
1471
|
+
code: ZodIssueCode.invalid_string,
|
|
1472
|
+
message: check.message
|
|
1473
|
+
});
|
|
1474
|
+
status.dirty();
|
|
1475
|
+
}
|
|
1476
|
+
} else if (check.kind === "nanoid") {
|
|
1477
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1478
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1479
|
+
addIssueToContext(ctx, {
|
|
1480
|
+
validation: "nanoid",
|
|
1481
|
+
code: ZodIssueCode.invalid_string,
|
|
1482
|
+
message: check.message
|
|
1483
|
+
});
|
|
1484
|
+
status.dirty();
|
|
1485
|
+
}
|
|
1486
|
+
} else if (check.kind === "cuid") {
|
|
1487
|
+
if (!cuidRegex.test(input.data)) {
|
|
1488
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1489
|
+
addIssueToContext(ctx, {
|
|
1490
|
+
validation: "cuid",
|
|
1491
|
+
code: ZodIssueCode.invalid_string,
|
|
1492
|
+
message: check.message
|
|
1493
|
+
});
|
|
1494
|
+
status.dirty();
|
|
1495
|
+
}
|
|
1496
|
+
} else if (check.kind === "cuid2") {
|
|
1497
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1498
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1499
|
+
addIssueToContext(ctx, {
|
|
1500
|
+
validation: "cuid2",
|
|
1501
|
+
code: ZodIssueCode.invalid_string,
|
|
1502
|
+
message: check.message
|
|
1503
|
+
});
|
|
1504
|
+
status.dirty();
|
|
1505
|
+
}
|
|
1506
|
+
} else if (check.kind === "ulid") {
|
|
1507
|
+
if (!ulidRegex.test(input.data)) {
|
|
1508
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1509
|
+
addIssueToContext(ctx, {
|
|
1510
|
+
validation: "ulid",
|
|
1511
|
+
code: ZodIssueCode.invalid_string,
|
|
1512
|
+
message: check.message
|
|
1513
|
+
});
|
|
1514
|
+
status.dirty();
|
|
1515
|
+
}
|
|
1516
|
+
} else if (check.kind === "url") {
|
|
1517
|
+
try {
|
|
1518
|
+
new URL(input.data);
|
|
1519
|
+
} catch {
|
|
1520
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1521
|
+
addIssueToContext(ctx, {
|
|
1522
|
+
validation: "url",
|
|
1523
|
+
code: ZodIssueCode.invalid_string,
|
|
1524
|
+
message: check.message
|
|
1525
|
+
});
|
|
1526
|
+
status.dirty();
|
|
1527
|
+
}
|
|
1528
|
+
} else if (check.kind === "regex") {
|
|
1529
|
+
check.regex.lastIndex = 0;
|
|
1530
|
+
const testResult = check.regex.test(input.data);
|
|
1531
|
+
if (!testResult) {
|
|
1532
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1533
|
+
addIssueToContext(ctx, {
|
|
1534
|
+
validation: "regex",
|
|
1535
|
+
code: ZodIssueCode.invalid_string,
|
|
1536
|
+
message: check.message
|
|
1537
|
+
});
|
|
1538
|
+
status.dirty();
|
|
1539
|
+
}
|
|
1540
|
+
} else if (check.kind === "trim") {
|
|
1541
|
+
input.data = input.data.trim();
|
|
1542
|
+
} else if (check.kind === "includes") {
|
|
1543
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1544
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1545
|
+
addIssueToContext(ctx, {
|
|
1546
|
+
code: ZodIssueCode.invalid_string,
|
|
1547
|
+
validation: { includes: check.value, position: check.position },
|
|
1548
|
+
message: check.message
|
|
1549
|
+
});
|
|
1550
|
+
status.dirty();
|
|
1551
|
+
}
|
|
1552
|
+
} else if (check.kind === "toLowerCase") {
|
|
1553
|
+
input.data = input.data.toLowerCase();
|
|
1554
|
+
} else if (check.kind === "toUpperCase") {
|
|
1555
|
+
input.data = input.data.toUpperCase();
|
|
1556
|
+
} else if (check.kind === "startsWith") {
|
|
1557
|
+
if (!input.data.startsWith(check.value)) {
|
|
1558
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1559
|
+
addIssueToContext(ctx, {
|
|
1560
|
+
code: ZodIssueCode.invalid_string,
|
|
1561
|
+
validation: { startsWith: check.value },
|
|
1562
|
+
message: check.message
|
|
1563
|
+
});
|
|
1564
|
+
status.dirty();
|
|
1565
|
+
}
|
|
1566
|
+
} else if (check.kind === "endsWith") {
|
|
1567
|
+
if (!input.data.endsWith(check.value)) {
|
|
1568
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1569
|
+
addIssueToContext(ctx, {
|
|
1570
|
+
code: ZodIssueCode.invalid_string,
|
|
1571
|
+
validation: { endsWith: check.value },
|
|
1572
|
+
message: check.message
|
|
1573
|
+
});
|
|
1574
|
+
status.dirty();
|
|
1575
|
+
}
|
|
1576
|
+
} else if (check.kind === "datetime") {
|
|
1577
|
+
const regex = datetimeRegex(check);
|
|
1578
|
+
if (!regex.test(input.data)) {
|
|
1579
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1580
|
+
addIssueToContext(ctx, {
|
|
1581
|
+
code: ZodIssueCode.invalid_string,
|
|
1582
|
+
validation: "datetime",
|
|
1583
|
+
message: check.message
|
|
1584
|
+
});
|
|
1585
|
+
status.dirty();
|
|
1586
|
+
}
|
|
1587
|
+
} else if (check.kind === "date") {
|
|
1588
|
+
const regex = dateRegex;
|
|
1589
|
+
if (!regex.test(input.data)) {
|
|
1590
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1591
|
+
addIssueToContext(ctx, {
|
|
1592
|
+
code: ZodIssueCode.invalid_string,
|
|
1593
|
+
validation: "date",
|
|
1594
|
+
message: check.message
|
|
1595
|
+
});
|
|
1596
|
+
status.dirty();
|
|
1597
|
+
}
|
|
1598
|
+
} else if (check.kind === "time") {
|
|
1599
|
+
const regex = timeRegex(check);
|
|
1600
|
+
if (!regex.test(input.data)) {
|
|
1601
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1602
|
+
addIssueToContext(ctx, {
|
|
1603
|
+
code: ZodIssueCode.invalid_string,
|
|
1604
|
+
validation: "time",
|
|
1605
|
+
message: check.message
|
|
1606
|
+
});
|
|
1607
|
+
status.dirty();
|
|
1608
|
+
}
|
|
1609
|
+
} else if (check.kind === "duration") {
|
|
1610
|
+
if (!durationRegex.test(input.data)) {
|
|
1611
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1612
|
+
addIssueToContext(ctx, {
|
|
1613
|
+
validation: "duration",
|
|
1614
|
+
code: ZodIssueCode.invalid_string,
|
|
1615
|
+
message: check.message
|
|
1616
|
+
});
|
|
1617
|
+
status.dirty();
|
|
1618
|
+
}
|
|
1619
|
+
} else if (check.kind === "ip") {
|
|
1620
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1621
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1622
|
+
addIssueToContext(ctx, {
|
|
1623
|
+
validation: "ip",
|
|
1624
|
+
code: ZodIssueCode.invalid_string,
|
|
1625
|
+
message: check.message
|
|
1626
|
+
});
|
|
1627
|
+
status.dirty();
|
|
1628
|
+
}
|
|
1629
|
+
} else if (check.kind === "jwt") {
|
|
1630
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1631
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1632
|
+
addIssueToContext(ctx, {
|
|
1633
|
+
validation: "jwt",
|
|
1634
|
+
code: ZodIssueCode.invalid_string,
|
|
1635
|
+
message: check.message
|
|
1636
|
+
});
|
|
1637
|
+
status.dirty();
|
|
1638
|
+
}
|
|
1639
|
+
} else if (check.kind === "cidr") {
|
|
1640
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1641
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1642
|
+
addIssueToContext(ctx, {
|
|
1643
|
+
validation: "cidr",
|
|
1644
|
+
code: ZodIssueCode.invalid_string,
|
|
1645
|
+
message: check.message
|
|
1646
|
+
});
|
|
1647
|
+
status.dirty();
|
|
1648
|
+
}
|
|
1649
|
+
} else if (check.kind === "base64") {
|
|
1650
|
+
if (!base64Regex.test(input.data)) {
|
|
1651
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1652
|
+
addIssueToContext(ctx, {
|
|
1653
|
+
validation: "base64",
|
|
1654
|
+
code: ZodIssueCode.invalid_string,
|
|
1655
|
+
message: check.message
|
|
1656
|
+
});
|
|
1657
|
+
status.dirty();
|
|
1658
|
+
}
|
|
1659
|
+
} else if (check.kind === "base64url") {
|
|
1660
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1661
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1662
|
+
addIssueToContext(ctx, {
|
|
1663
|
+
validation: "base64url",
|
|
1664
|
+
code: ZodIssueCode.invalid_string,
|
|
1665
|
+
message: check.message
|
|
1666
|
+
});
|
|
1667
|
+
status.dirty();
|
|
1668
|
+
}
|
|
1669
|
+
} else {
|
|
1670
|
+
util.assertNever(check);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
return { status: status.value, value: input.data };
|
|
1674
|
+
}
|
|
1675
|
+
_regex(regex, validation, message) {
|
|
1676
|
+
return this.refinement((data) => regex.test(data), {
|
|
1677
|
+
validation,
|
|
1678
|
+
code: ZodIssueCode.invalid_string,
|
|
1679
|
+
...errorUtil.errToObj(message)
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
_addCheck(check) {
|
|
1683
|
+
return new _ZodString({
|
|
1684
|
+
...this._def,
|
|
1685
|
+
checks: [...this._def.checks, check]
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
email(message) {
|
|
1689
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1690
|
+
}
|
|
1691
|
+
url(message) {
|
|
1692
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1693
|
+
}
|
|
1694
|
+
emoji(message) {
|
|
1695
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1696
|
+
}
|
|
1697
|
+
uuid(message) {
|
|
1698
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1699
|
+
}
|
|
1700
|
+
nanoid(message) {
|
|
1701
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1702
|
+
}
|
|
1703
|
+
cuid(message) {
|
|
1704
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1705
|
+
}
|
|
1706
|
+
cuid2(message) {
|
|
1707
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1708
|
+
}
|
|
1709
|
+
ulid(message) {
|
|
1710
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1711
|
+
}
|
|
1712
|
+
base64(message) {
|
|
1713
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1714
|
+
}
|
|
1715
|
+
base64url(message) {
|
|
1716
|
+
return this._addCheck({
|
|
1717
|
+
kind: "base64url",
|
|
1718
|
+
...errorUtil.errToObj(message)
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
jwt(options) {
|
|
1722
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1723
|
+
}
|
|
1724
|
+
ip(options) {
|
|
1725
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1726
|
+
}
|
|
1727
|
+
cidr(options) {
|
|
1728
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1729
|
+
}
|
|
1730
|
+
datetime(options) {
|
|
1731
|
+
if (typeof options === "string") {
|
|
1732
|
+
return this._addCheck({
|
|
1733
|
+
kind: "datetime",
|
|
1734
|
+
precision: null,
|
|
1735
|
+
offset: false,
|
|
1736
|
+
local: false,
|
|
1737
|
+
message: options
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
return this._addCheck({
|
|
1741
|
+
kind: "datetime",
|
|
1742
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1743
|
+
offset: options?.offset ?? false,
|
|
1744
|
+
local: options?.local ?? false,
|
|
1745
|
+
...errorUtil.errToObj(options?.message)
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
date(message) {
|
|
1749
|
+
return this._addCheck({ kind: "date", message });
|
|
1750
|
+
}
|
|
1751
|
+
time(options) {
|
|
1752
|
+
if (typeof options === "string") {
|
|
1753
|
+
return this._addCheck({
|
|
1754
|
+
kind: "time",
|
|
1755
|
+
precision: null,
|
|
1756
|
+
message: options
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
return this._addCheck({
|
|
1760
|
+
kind: "time",
|
|
1761
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1762
|
+
...errorUtil.errToObj(options?.message)
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
duration(message) {
|
|
1766
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1767
|
+
}
|
|
1768
|
+
regex(regex, message) {
|
|
1769
|
+
return this._addCheck({
|
|
1770
|
+
kind: "regex",
|
|
1771
|
+
regex,
|
|
1772
|
+
...errorUtil.errToObj(message)
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
includes(value, options) {
|
|
1776
|
+
return this._addCheck({
|
|
1777
|
+
kind: "includes",
|
|
1778
|
+
value,
|
|
1779
|
+
position: options?.position,
|
|
1780
|
+
...errorUtil.errToObj(options?.message)
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
startsWith(value, message) {
|
|
1784
|
+
return this._addCheck({
|
|
1785
|
+
kind: "startsWith",
|
|
1786
|
+
value,
|
|
1787
|
+
...errorUtil.errToObj(message)
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
endsWith(value, message) {
|
|
1791
|
+
return this._addCheck({
|
|
1792
|
+
kind: "endsWith",
|
|
1793
|
+
value,
|
|
1794
|
+
...errorUtil.errToObj(message)
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
min(minLength, message) {
|
|
1798
|
+
return this._addCheck({
|
|
1799
|
+
kind: "min",
|
|
1800
|
+
value: minLength,
|
|
1801
|
+
...errorUtil.errToObj(message)
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
max(maxLength, message) {
|
|
1805
|
+
return this._addCheck({
|
|
1806
|
+
kind: "max",
|
|
1807
|
+
value: maxLength,
|
|
1808
|
+
...errorUtil.errToObj(message)
|
|
1809
|
+
});
|
|
1810
|
+
}
|
|
1811
|
+
length(len, message) {
|
|
1812
|
+
return this._addCheck({
|
|
1813
|
+
kind: "length",
|
|
1814
|
+
value: len,
|
|
1815
|
+
...errorUtil.errToObj(message)
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Equivalent to `.min(1)`
|
|
1820
|
+
*/
|
|
1821
|
+
nonempty(message) {
|
|
1822
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1823
|
+
}
|
|
1824
|
+
trim() {
|
|
1825
|
+
return new _ZodString({
|
|
1826
|
+
...this._def,
|
|
1827
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
toLowerCase() {
|
|
1831
|
+
return new _ZodString({
|
|
1832
|
+
...this._def,
|
|
1833
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
toUpperCase() {
|
|
1837
|
+
return new _ZodString({
|
|
1838
|
+
...this._def,
|
|
1839
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
get isDatetime() {
|
|
1843
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1844
|
+
}
|
|
1845
|
+
get isDate() {
|
|
1846
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1847
|
+
}
|
|
1848
|
+
get isTime() {
|
|
1849
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1850
|
+
}
|
|
1851
|
+
get isDuration() {
|
|
1852
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1853
|
+
}
|
|
1854
|
+
get isEmail() {
|
|
1855
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1856
|
+
}
|
|
1857
|
+
get isURL() {
|
|
1858
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1859
|
+
}
|
|
1860
|
+
get isEmoji() {
|
|
1861
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1862
|
+
}
|
|
1863
|
+
get isUUID() {
|
|
1864
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1865
|
+
}
|
|
1866
|
+
get isNANOID() {
|
|
1867
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1868
|
+
}
|
|
1869
|
+
get isCUID() {
|
|
1870
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1871
|
+
}
|
|
1872
|
+
get isCUID2() {
|
|
1873
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1874
|
+
}
|
|
1875
|
+
get isULID() {
|
|
1876
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1877
|
+
}
|
|
1878
|
+
get isIP() {
|
|
1879
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1880
|
+
}
|
|
1881
|
+
get isCIDR() {
|
|
1882
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1883
|
+
}
|
|
1884
|
+
get isBase64() {
|
|
1885
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1886
|
+
}
|
|
1887
|
+
get isBase64url() {
|
|
1888
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1889
|
+
}
|
|
1890
|
+
get minLength() {
|
|
1891
|
+
let min = null;
|
|
1892
|
+
for (const ch of this._def.checks) {
|
|
1893
|
+
if (ch.kind === "min") {
|
|
1894
|
+
if (min === null || ch.value > min)
|
|
1895
|
+
min = ch.value;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
return min;
|
|
1899
|
+
}
|
|
1900
|
+
get maxLength() {
|
|
1901
|
+
let max = null;
|
|
1902
|
+
for (const ch of this._def.checks) {
|
|
1903
|
+
if (ch.kind === "max") {
|
|
1904
|
+
if (max === null || ch.value < max)
|
|
1905
|
+
max = ch.value;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return max;
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
ZodString.create = (params) => {
|
|
1912
|
+
return new ZodString({
|
|
1913
|
+
checks: [],
|
|
1914
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1915
|
+
coerce: params?.coerce ?? false,
|
|
1916
|
+
...processCreateParams(params)
|
|
1917
|
+
});
|
|
1918
|
+
};
|
|
1919
|
+
function floatSafeRemainder(val, step) {
|
|
1920
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1921
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1922
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1923
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1924
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1925
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1926
|
+
}
|
|
1927
|
+
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1928
|
+
constructor() {
|
|
1929
|
+
super(...arguments);
|
|
1930
|
+
this.min = this.gte;
|
|
1931
|
+
this.max = this.lte;
|
|
1932
|
+
this.step = this.multipleOf;
|
|
1933
|
+
}
|
|
1934
|
+
_parse(input) {
|
|
1935
|
+
if (this._def.coerce) {
|
|
1936
|
+
input.data = Number(input.data);
|
|
1937
|
+
}
|
|
1938
|
+
const parsedType = this._getType(input);
|
|
1939
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1940
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1941
|
+
addIssueToContext(ctx2, {
|
|
1942
|
+
code: ZodIssueCode.invalid_type,
|
|
1943
|
+
expected: ZodParsedType.number,
|
|
1944
|
+
received: ctx2.parsedType
|
|
1945
|
+
});
|
|
1946
|
+
return INVALID;
|
|
1947
|
+
}
|
|
1948
|
+
let ctx = void 0;
|
|
1949
|
+
const status = new ParseStatus();
|
|
1950
|
+
for (const check of this._def.checks) {
|
|
1951
|
+
if (check.kind === "int") {
|
|
1952
|
+
if (!util.isInteger(input.data)) {
|
|
1953
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1954
|
+
addIssueToContext(ctx, {
|
|
1955
|
+
code: ZodIssueCode.invalid_type,
|
|
1956
|
+
expected: "integer",
|
|
1957
|
+
received: "float",
|
|
1958
|
+
message: check.message
|
|
1959
|
+
});
|
|
1960
|
+
status.dirty();
|
|
1961
|
+
}
|
|
1962
|
+
} else if (check.kind === "min") {
|
|
1963
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1964
|
+
if (tooSmall) {
|
|
1965
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1966
|
+
addIssueToContext(ctx, {
|
|
1967
|
+
code: ZodIssueCode.too_small,
|
|
1968
|
+
minimum: check.value,
|
|
1969
|
+
type: "number",
|
|
1970
|
+
inclusive: check.inclusive,
|
|
1971
|
+
exact: false,
|
|
1972
|
+
message: check.message
|
|
1973
|
+
});
|
|
1974
|
+
status.dirty();
|
|
1975
|
+
}
|
|
1976
|
+
} else if (check.kind === "max") {
|
|
1977
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1978
|
+
if (tooBig) {
|
|
1979
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1980
|
+
addIssueToContext(ctx, {
|
|
1981
|
+
code: ZodIssueCode.too_big,
|
|
1982
|
+
maximum: check.value,
|
|
1983
|
+
type: "number",
|
|
1984
|
+
inclusive: check.inclusive,
|
|
1985
|
+
exact: false,
|
|
1986
|
+
message: check.message
|
|
1987
|
+
});
|
|
1988
|
+
status.dirty();
|
|
1989
|
+
}
|
|
1990
|
+
} else if (check.kind === "multipleOf") {
|
|
1991
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1992
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1993
|
+
addIssueToContext(ctx, {
|
|
1994
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1995
|
+
multipleOf: check.value,
|
|
1996
|
+
message: check.message
|
|
1997
|
+
});
|
|
1998
|
+
status.dirty();
|
|
1999
|
+
}
|
|
2000
|
+
} else if (check.kind === "finite") {
|
|
2001
|
+
if (!Number.isFinite(input.data)) {
|
|
2002
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2003
|
+
addIssueToContext(ctx, {
|
|
2004
|
+
code: ZodIssueCode.not_finite,
|
|
2005
|
+
message: check.message
|
|
2006
|
+
});
|
|
2007
|
+
status.dirty();
|
|
2008
|
+
}
|
|
2009
|
+
} else {
|
|
2010
|
+
util.assertNever(check);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return { status: status.value, value: input.data };
|
|
2014
|
+
}
|
|
2015
|
+
gte(value, message) {
|
|
2016
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2017
|
+
}
|
|
2018
|
+
gt(value, message) {
|
|
2019
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2020
|
+
}
|
|
2021
|
+
lte(value, message) {
|
|
2022
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2023
|
+
}
|
|
2024
|
+
lt(value, message) {
|
|
2025
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2026
|
+
}
|
|
2027
|
+
setLimit(kind, value, inclusive, message) {
|
|
2028
|
+
return new _ZodNumber({
|
|
2029
|
+
...this._def,
|
|
2030
|
+
checks: [
|
|
2031
|
+
...this._def.checks,
|
|
2032
|
+
{
|
|
2033
|
+
kind,
|
|
2034
|
+
value,
|
|
2035
|
+
inclusive,
|
|
2036
|
+
message: errorUtil.toString(message)
|
|
2037
|
+
}
|
|
2038
|
+
]
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
_addCheck(check) {
|
|
2042
|
+
return new _ZodNumber({
|
|
2043
|
+
...this._def,
|
|
2044
|
+
checks: [...this._def.checks, check]
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
int(message) {
|
|
2048
|
+
return this._addCheck({
|
|
2049
|
+
kind: "int",
|
|
2050
|
+
message: errorUtil.toString(message)
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
positive(message) {
|
|
2054
|
+
return this._addCheck({
|
|
2055
|
+
kind: "min",
|
|
2056
|
+
value: 0,
|
|
2057
|
+
inclusive: false,
|
|
2058
|
+
message: errorUtil.toString(message)
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
negative(message) {
|
|
2062
|
+
return this._addCheck({
|
|
2063
|
+
kind: "max",
|
|
2064
|
+
value: 0,
|
|
2065
|
+
inclusive: false,
|
|
2066
|
+
message: errorUtil.toString(message)
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
nonpositive(message) {
|
|
2070
|
+
return this._addCheck({
|
|
2071
|
+
kind: "max",
|
|
2072
|
+
value: 0,
|
|
2073
|
+
inclusive: true,
|
|
2074
|
+
message: errorUtil.toString(message)
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
nonnegative(message) {
|
|
2078
|
+
return this._addCheck({
|
|
2079
|
+
kind: "min",
|
|
2080
|
+
value: 0,
|
|
2081
|
+
inclusive: true,
|
|
2082
|
+
message: errorUtil.toString(message)
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
multipleOf(value, message) {
|
|
2086
|
+
return this._addCheck({
|
|
2087
|
+
kind: "multipleOf",
|
|
2088
|
+
value,
|
|
2089
|
+
message: errorUtil.toString(message)
|
|
2090
|
+
});
|
|
2091
|
+
}
|
|
2092
|
+
finite(message) {
|
|
2093
|
+
return this._addCheck({
|
|
2094
|
+
kind: "finite",
|
|
2095
|
+
message: errorUtil.toString(message)
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
safe(message) {
|
|
2099
|
+
return this._addCheck({
|
|
2100
|
+
kind: "min",
|
|
2101
|
+
inclusive: true,
|
|
2102
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
2103
|
+
message: errorUtil.toString(message)
|
|
2104
|
+
})._addCheck({
|
|
2105
|
+
kind: "max",
|
|
2106
|
+
inclusive: true,
|
|
2107
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
2108
|
+
message: errorUtil.toString(message)
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
get minValue() {
|
|
2112
|
+
let min = null;
|
|
2113
|
+
for (const ch of this._def.checks) {
|
|
2114
|
+
if (ch.kind === "min") {
|
|
2115
|
+
if (min === null || ch.value > min)
|
|
2116
|
+
min = ch.value;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
return min;
|
|
2120
|
+
}
|
|
2121
|
+
get maxValue() {
|
|
2122
|
+
let max = null;
|
|
2123
|
+
for (const ch of this._def.checks) {
|
|
2124
|
+
if (ch.kind === "max") {
|
|
2125
|
+
if (max === null || ch.value < max)
|
|
2126
|
+
max = ch.value;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
return max;
|
|
2130
|
+
}
|
|
2131
|
+
get isInt() {
|
|
2132
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
2133
|
+
}
|
|
2134
|
+
get isFinite() {
|
|
2135
|
+
let max = null;
|
|
2136
|
+
let min = null;
|
|
2137
|
+
for (const ch of this._def.checks) {
|
|
2138
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
2139
|
+
return true;
|
|
2140
|
+
} else if (ch.kind === "min") {
|
|
2141
|
+
if (min === null || ch.value > min)
|
|
2142
|
+
min = ch.value;
|
|
2143
|
+
} else if (ch.kind === "max") {
|
|
2144
|
+
if (max === null || ch.value < max)
|
|
2145
|
+
max = ch.value;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
ZodNumber.create = (params) => {
|
|
2152
|
+
return new ZodNumber({
|
|
2153
|
+
checks: [],
|
|
2154
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2155
|
+
coerce: params?.coerce || false,
|
|
2156
|
+
...processCreateParams(params)
|
|
2157
|
+
});
|
|
2158
|
+
};
|
|
2159
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
2160
|
+
constructor() {
|
|
2161
|
+
super(...arguments);
|
|
2162
|
+
this.min = this.gte;
|
|
2163
|
+
this.max = this.lte;
|
|
2164
|
+
}
|
|
2165
|
+
_parse(input) {
|
|
2166
|
+
if (this._def.coerce) {
|
|
2167
|
+
try {
|
|
2168
|
+
input.data = BigInt(input.data);
|
|
2169
|
+
} catch {
|
|
2170
|
+
return this._getInvalidInput(input);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
const parsedType = this._getType(input);
|
|
2174
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
2175
|
+
return this._getInvalidInput(input);
|
|
2176
|
+
}
|
|
2177
|
+
let ctx = void 0;
|
|
2178
|
+
const status = new ParseStatus();
|
|
2179
|
+
for (const check of this._def.checks) {
|
|
2180
|
+
if (check.kind === "min") {
|
|
2181
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2182
|
+
if (tooSmall) {
|
|
2183
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2184
|
+
addIssueToContext(ctx, {
|
|
2185
|
+
code: ZodIssueCode.too_small,
|
|
2186
|
+
type: "bigint",
|
|
2187
|
+
minimum: check.value,
|
|
2188
|
+
inclusive: check.inclusive,
|
|
2189
|
+
message: check.message
|
|
2190
|
+
});
|
|
2191
|
+
status.dirty();
|
|
2192
|
+
}
|
|
2193
|
+
} else if (check.kind === "max") {
|
|
2194
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2195
|
+
if (tooBig) {
|
|
2196
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2197
|
+
addIssueToContext(ctx, {
|
|
2198
|
+
code: ZodIssueCode.too_big,
|
|
2199
|
+
type: "bigint",
|
|
2200
|
+
maximum: check.value,
|
|
2201
|
+
inclusive: check.inclusive,
|
|
2202
|
+
message: check.message
|
|
2203
|
+
});
|
|
2204
|
+
status.dirty();
|
|
2205
|
+
}
|
|
2206
|
+
} else if (check.kind === "multipleOf") {
|
|
2207
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
2208
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2209
|
+
addIssueToContext(ctx, {
|
|
2210
|
+
code: ZodIssueCode.not_multiple_of,
|
|
2211
|
+
multipleOf: check.value,
|
|
2212
|
+
message: check.message
|
|
2213
|
+
});
|
|
2214
|
+
status.dirty();
|
|
2215
|
+
}
|
|
2216
|
+
} else {
|
|
2217
|
+
util.assertNever(check);
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
return { status: status.value, value: input.data };
|
|
2221
|
+
}
|
|
2222
|
+
_getInvalidInput(input) {
|
|
2223
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2224
|
+
addIssueToContext(ctx, {
|
|
2225
|
+
code: ZodIssueCode.invalid_type,
|
|
2226
|
+
expected: ZodParsedType.bigint,
|
|
2227
|
+
received: ctx.parsedType
|
|
2228
|
+
});
|
|
2229
|
+
return INVALID;
|
|
2230
|
+
}
|
|
2231
|
+
gte(value, message) {
|
|
2232
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2233
|
+
}
|
|
2234
|
+
gt(value, message) {
|
|
2235
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2236
|
+
}
|
|
2237
|
+
lte(value, message) {
|
|
2238
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2239
|
+
}
|
|
2240
|
+
lt(value, message) {
|
|
2241
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2242
|
+
}
|
|
2243
|
+
setLimit(kind, value, inclusive, message) {
|
|
2244
|
+
return new _ZodBigInt({
|
|
2245
|
+
...this._def,
|
|
2246
|
+
checks: [
|
|
2247
|
+
...this._def.checks,
|
|
2248
|
+
{
|
|
2249
|
+
kind,
|
|
2250
|
+
value,
|
|
2251
|
+
inclusive,
|
|
2252
|
+
message: errorUtil.toString(message)
|
|
2253
|
+
}
|
|
2254
|
+
]
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
_addCheck(check) {
|
|
2258
|
+
return new _ZodBigInt({
|
|
2259
|
+
...this._def,
|
|
2260
|
+
checks: [...this._def.checks, check]
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
positive(message) {
|
|
2264
|
+
return this._addCheck({
|
|
2265
|
+
kind: "min",
|
|
2266
|
+
value: BigInt(0),
|
|
2267
|
+
inclusive: false,
|
|
2268
|
+
message: errorUtil.toString(message)
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
negative(message) {
|
|
2272
|
+
return this._addCheck({
|
|
2273
|
+
kind: "max",
|
|
2274
|
+
value: BigInt(0),
|
|
2275
|
+
inclusive: false,
|
|
2276
|
+
message: errorUtil.toString(message)
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
nonpositive(message) {
|
|
2280
|
+
return this._addCheck({
|
|
2281
|
+
kind: "max",
|
|
2282
|
+
value: BigInt(0),
|
|
2283
|
+
inclusive: true,
|
|
2284
|
+
message: errorUtil.toString(message)
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
nonnegative(message) {
|
|
2288
|
+
return this._addCheck({
|
|
2289
|
+
kind: "min",
|
|
2290
|
+
value: BigInt(0),
|
|
2291
|
+
inclusive: true,
|
|
2292
|
+
message: errorUtil.toString(message)
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
multipleOf(value, message) {
|
|
2296
|
+
return this._addCheck({
|
|
2297
|
+
kind: "multipleOf",
|
|
2298
|
+
value,
|
|
2299
|
+
message: errorUtil.toString(message)
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
get minValue() {
|
|
2303
|
+
let min = null;
|
|
2304
|
+
for (const ch of this._def.checks) {
|
|
2305
|
+
if (ch.kind === "min") {
|
|
2306
|
+
if (min === null || ch.value > min)
|
|
2307
|
+
min = ch.value;
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
return min;
|
|
2311
|
+
}
|
|
2312
|
+
get maxValue() {
|
|
2313
|
+
let max = null;
|
|
2314
|
+
for (const ch of this._def.checks) {
|
|
2315
|
+
if (ch.kind === "max") {
|
|
2316
|
+
if (max === null || ch.value < max)
|
|
2317
|
+
max = ch.value;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
return max;
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
ZodBigInt.create = (params) => {
|
|
2324
|
+
return new ZodBigInt({
|
|
2325
|
+
checks: [],
|
|
2326
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2327
|
+
coerce: params?.coerce ?? false,
|
|
2328
|
+
...processCreateParams(params)
|
|
2329
|
+
});
|
|
2330
|
+
};
|
|
2331
|
+
var ZodBoolean = class extends ZodType {
|
|
2332
|
+
_parse(input) {
|
|
2333
|
+
if (this._def.coerce) {
|
|
2334
|
+
input.data = Boolean(input.data);
|
|
2335
|
+
}
|
|
2336
|
+
const parsedType = this._getType(input);
|
|
2337
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2338
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2339
|
+
addIssueToContext(ctx, {
|
|
2340
|
+
code: ZodIssueCode.invalid_type,
|
|
2341
|
+
expected: ZodParsedType.boolean,
|
|
2342
|
+
received: ctx.parsedType
|
|
2343
|
+
});
|
|
2344
|
+
return INVALID;
|
|
2345
|
+
}
|
|
2346
|
+
return OK(input.data);
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
ZodBoolean.create = (params) => {
|
|
2350
|
+
return new ZodBoolean({
|
|
2351
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2352
|
+
coerce: params?.coerce || false,
|
|
2353
|
+
...processCreateParams(params)
|
|
2354
|
+
});
|
|
2355
|
+
};
|
|
2356
|
+
var ZodDate = class _ZodDate extends ZodType {
|
|
2357
|
+
_parse(input) {
|
|
2358
|
+
if (this._def.coerce) {
|
|
2359
|
+
input.data = new Date(input.data);
|
|
2360
|
+
}
|
|
2361
|
+
const parsedType = this._getType(input);
|
|
2362
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2363
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2364
|
+
addIssueToContext(ctx2, {
|
|
2365
|
+
code: ZodIssueCode.invalid_type,
|
|
2366
|
+
expected: ZodParsedType.date,
|
|
2367
|
+
received: ctx2.parsedType
|
|
2368
|
+
});
|
|
2369
|
+
return INVALID;
|
|
2370
|
+
}
|
|
2371
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2372
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2373
|
+
addIssueToContext(ctx2, {
|
|
2374
|
+
code: ZodIssueCode.invalid_date
|
|
2375
|
+
});
|
|
2376
|
+
return INVALID;
|
|
2377
|
+
}
|
|
2378
|
+
const status = new ParseStatus();
|
|
2379
|
+
let ctx = void 0;
|
|
2380
|
+
for (const check of this._def.checks) {
|
|
2381
|
+
if (check.kind === "min") {
|
|
2382
|
+
if (input.data.getTime() < check.value) {
|
|
2383
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2384
|
+
addIssueToContext(ctx, {
|
|
2385
|
+
code: ZodIssueCode.too_small,
|
|
2386
|
+
message: check.message,
|
|
2387
|
+
inclusive: true,
|
|
2388
|
+
exact: false,
|
|
2389
|
+
minimum: check.value,
|
|
2390
|
+
type: "date"
|
|
2391
|
+
});
|
|
2392
|
+
status.dirty();
|
|
2393
|
+
}
|
|
2394
|
+
} else if (check.kind === "max") {
|
|
2395
|
+
if (input.data.getTime() > check.value) {
|
|
2396
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2397
|
+
addIssueToContext(ctx, {
|
|
2398
|
+
code: ZodIssueCode.too_big,
|
|
2399
|
+
message: check.message,
|
|
2400
|
+
inclusive: true,
|
|
2401
|
+
exact: false,
|
|
2402
|
+
maximum: check.value,
|
|
2403
|
+
type: "date"
|
|
2404
|
+
});
|
|
2405
|
+
status.dirty();
|
|
2406
|
+
}
|
|
2407
|
+
} else {
|
|
2408
|
+
util.assertNever(check);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
return {
|
|
2412
|
+
status: status.value,
|
|
2413
|
+
value: new Date(input.data.getTime())
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
_addCheck(check) {
|
|
2417
|
+
return new _ZodDate({
|
|
2418
|
+
...this._def,
|
|
2419
|
+
checks: [...this._def.checks, check]
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
min(minDate, message) {
|
|
2423
|
+
return this._addCheck({
|
|
2424
|
+
kind: "min",
|
|
2425
|
+
value: minDate.getTime(),
|
|
2426
|
+
message: errorUtil.toString(message)
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
max(maxDate, message) {
|
|
2430
|
+
return this._addCheck({
|
|
2431
|
+
kind: "max",
|
|
2432
|
+
value: maxDate.getTime(),
|
|
2433
|
+
message: errorUtil.toString(message)
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
get minDate() {
|
|
2437
|
+
let min = null;
|
|
2438
|
+
for (const ch of this._def.checks) {
|
|
2439
|
+
if (ch.kind === "min") {
|
|
2440
|
+
if (min === null || ch.value > min)
|
|
2441
|
+
min = ch.value;
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
return min != null ? new Date(min) : null;
|
|
2445
|
+
}
|
|
2446
|
+
get maxDate() {
|
|
2447
|
+
let max = null;
|
|
2448
|
+
for (const ch of this._def.checks) {
|
|
2449
|
+
if (ch.kind === "max") {
|
|
2450
|
+
if (max === null || ch.value < max)
|
|
2451
|
+
max = ch.value;
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
return max != null ? new Date(max) : null;
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
ZodDate.create = (params) => {
|
|
2458
|
+
return new ZodDate({
|
|
2459
|
+
checks: [],
|
|
2460
|
+
coerce: params?.coerce || false,
|
|
2461
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2462
|
+
...processCreateParams(params)
|
|
2463
|
+
});
|
|
2464
|
+
};
|
|
2465
|
+
var ZodSymbol = class extends ZodType {
|
|
2466
|
+
_parse(input) {
|
|
2467
|
+
const parsedType = this._getType(input);
|
|
2468
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2469
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2470
|
+
addIssueToContext(ctx, {
|
|
2471
|
+
code: ZodIssueCode.invalid_type,
|
|
2472
|
+
expected: ZodParsedType.symbol,
|
|
2473
|
+
received: ctx.parsedType
|
|
2474
|
+
});
|
|
2475
|
+
return INVALID;
|
|
2476
|
+
}
|
|
2477
|
+
return OK(input.data);
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
ZodSymbol.create = (params) => {
|
|
2481
|
+
return new ZodSymbol({
|
|
2482
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2483
|
+
...processCreateParams(params)
|
|
2484
|
+
});
|
|
2485
|
+
};
|
|
2486
|
+
var ZodUndefined = class extends ZodType {
|
|
2487
|
+
_parse(input) {
|
|
2488
|
+
const parsedType = this._getType(input);
|
|
2489
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2490
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2491
|
+
addIssueToContext(ctx, {
|
|
2492
|
+
code: ZodIssueCode.invalid_type,
|
|
2493
|
+
expected: ZodParsedType.undefined,
|
|
2494
|
+
received: ctx.parsedType
|
|
2495
|
+
});
|
|
2496
|
+
return INVALID;
|
|
2497
|
+
}
|
|
2498
|
+
return OK(input.data);
|
|
2499
|
+
}
|
|
2500
|
+
};
|
|
2501
|
+
ZodUndefined.create = (params) => {
|
|
2502
|
+
return new ZodUndefined({
|
|
2503
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2504
|
+
...processCreateParams(params)
|
|
2505
|
+
});
|
|
2506
|
+
};
|
|
2507
|
+
var ZodNull = class extends ZodType {
|
|
2508
|
+
_parse(input) {
|
|
2509
|
+
const parsedType = this._getType(input);
|
|
2510
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2511
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2512
|
+
addIssueToContext(ctx, {
|
|
2513
|
+
code: ZodIssueCode.invalid_type,
|
|
2514
|
+
expected: ZodParsedType.null,
|
|
2515
|
+
received: ctx.parsedType
|
|
2516
|
+
});
|
|
2517
|
+
return INVALID;
|
|
2518
|
+
}
|
|
2519
|
+
return OK(input.data);
|
|
2520
|
+
}
|
|
2521
|
+
};
|
|
2522
|
+
ZodNull.create = (params) => {
|
|
2523
|
+
return new ZodNull({
|
|
2524
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2525
|
+
...processCreateParams(params)
|
|
2526
|
+
});
|
|
2527
|
+
};
|
|
2528
|
+
var ZodAny = class extends ZodType {
|
|
2529
|
+
constructor() {
|
|
2530
|
+
super(...arguments);
|
|
2531
|
+
this._any = true;
|
|
2532
|
+
}
|
|
2533
|
+
_parse(input) {
|
|
2534
|
+
return OK(input.data);
|
|
2535
|
+
}
|
|
2536
|
+
};
|
|
2537
|
+
ZodAny.create = (params) => {
|
|
2538
|
+
return new ZodAny({
|
|
2539
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2540
|
+
...processCreateParams(params)
|
|
2541
|
+
});
|
|
2542
|
+
};
|
|
2543
|
+
var ZodUnknown = class extends ZodType {
|
|
2544
|
+
constructor() {
|
|
2545
|
+
super(...arguments);
|
|
2546
|
+
this._unknown = true;
|
|
2547
|
+
}
|
|
2548
|
+
_parse(input) {
|
|
2549
|
+
return OK(input.data);
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
ZodUnknown.create = (params) => {
|
|
2553
|
+
return new ZodUnknown({
|
|
2554
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2555
|
+
...processCreateParams(params)
|
|
2556
|
+
});
|
|
2557
|
+
};
|
|
2558
|
+
var ZodNever = class extends ZodType {
|
|
2559
|
+
_parse(input) {
|
|
2560
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2561
|
+
addIssueToContext(ctx, {
|
|
2562
|
+
code: ZodIssueCode.invalid_type,
|
|
2563
|
+
expected: ZodParsedType.never,
|
|
2564
|
+
received: ctx.parsedType
|
|
2565
|
+
});
|
|
2566
|
+
return INVALID;
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
ZodNever.create = (params) => {
|
|
2570
|
+
return new ZodNever({
|
|
2571
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2572
|
+
...processCreateParams(params)
|
|
2573
|
+
});
|
|
2574
|
+
};
|
|
2575
|
+
var ZodVoid = class extends ZodType {
|
|
2576
|
+
_parse(input) {
|
|
2577
|
+
const parsedType = this._getType(input);
|
|
2578
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2579
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2580
|
+
addIssueToContext(ctx, {
|
|
2581
|
+
code: ZodIssueCode.invalid_type,
|
|
2582
|
+
expected: ZodParsedType.void,
|
|
2583
|
+
received: ctx.parsedType
|
|
2584
|
+
});
|
|
2585
|
+
return INVALID;
|
|
2586
|
+
}
|
|
2587
|
+
return OK(input.data);
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
ZodVoid.create = (params) => {
|
|
2591
|
+
return new ZodVoid({
|
|
2592
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2593
|
+
...processCreateParams(params)
|
|
2594
|
+
});
|
|
2595
|
+
};
|
|
2596
|
+
var ZodArray = class _ZodArray extends ZodType {
|
|
2597
|
+
_parse(input) {
|
|
2598
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2599
|
+
const def = this._def;
|
|
2600
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2601
|
+
addIssueToContext(ctx, {
|
|
2602
|
+
code: ZodIssueCode.invalid_type,
|
|
2603
|
+
expected: ZodParsedType.array,
|
|
2604
|
+
received: ctx.parsedType
|
|
2605
|
+
});
|
|
2606
|
+
return INVALID;
|
|
2607
|
+
}
|
|
2608
|
+
if (def.exactLength !== null) {
|
|
2609
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2610
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2611
|
+
if (tooBig || tooSmall) {
|
|
2612
|
+
addIssueToContext(ctx, {
|
|
2613
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2614
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2615
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2616
|
+
type: "array",
|
|
2617
|
+
inclusive: true,
|
|
2618
|
+
exact: true,
|
|
2619
|
+
message: def.exactLength.message
|
|
2620
|
+
});
|
|
2621
|
+
status.dirty();
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
if (def.minLength !== null) {
|
|
2625
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2626
|
+
addIssueToContext(ctx, {
|
|
2627
|
+
code: ZodIssueCode.too_small,
|
|
2628
|
+
minimum: def.minLength.value,
|
|
2629
|
+
type: "array",
|
|
2630
|
+
inclusive: true,
|
|
2631
|
+
exact: false,
|
|
2632
|
+
message: def.minLength.message
|
|
2633
|
+
});
|
|
2634
|
+
status.dirty();
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
if (def.maxLength !== null) {
|
|
2638
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2639
|
+
addIssueToContext(ctx, {
|
|
2640
|
+
code: ZodIssueCode.too_big,
|
|
2641
|
+
maximum: def.maxLength.value,
|
|
2642
|
+
type: "array",
|
|
2643
|
+
inclusive: true,
|
|
2644
|
+
exact: false,
|
|
2645
|
+
message: def.maxLength.message
|
|
2646
|
+
});
|
|
2647
|
+
status.dirty();
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
if (ctx.common.async) {
|
|
2651
|
+
return Promise.all([...ctx.data].map((item, i2) => {
|
|
2652
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i2));
|
|
2653
|
+
})).then((result2) => {
|
|
2654
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2655
|
+
});
|
|
2656
|
+
}
|
|
2657
|
+
const result = [...ctx.data].map((item, i2) => {
|
|
2658
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i2));
|
|
2659
|
+
});
|
|
2660
|
+
return ParseStatus.mergeArray(status, result);
|
|
2661
|
+
}
|
|
2662
|
+
get element() {
|
|
2663
|
+
return this._def.type;
|
|
2664
|
+
}
|
|
2665
|
+
min(minLength, message) {
|
|
2666
|
+
return new _ZodArray({
|
|
2667
|
+
...this._def,
|
|
2668
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
max(maxLength, message) {
|
|
2672
|
+
return new _ZodArray({
|
|
2673
|
+
...this._def,
|
|
2674
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2675
|
+
});
|
|
2676
|
+
}
|
|
2677
|
+
length(len, message) {
|
|
2678
|
+
return new _ZodArray({
|
|
2679
|
+
...this._def,
|
|
2680
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2681
|
+
});
|
|
2682
|
+
}
|
|
2683
|
+
nonempty(message) {
|
|
2684
|
+
return this.min(1, message);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
ZodArray.create = (schema, params) => {
|
|
2688
|
+
return new ZodArray({
|
|
2689
|
+
type: schema,
|
|
2690
|
+
minLength: null,
|
|
2691
|
+
maxLength: null,
|
|
2692
|
+
exactLength: null,
|
|
2693
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2694
|
+
...processCreateParams(params)
|
|
2695
|
+
});
|
|
2696
|
+
};
|
|
2697
|
+
function deepPartialify(schema) {
|
|
2698
|
+
if (schema instanceof ZodObject) {
|
|
2699
|
+
const newShape = {};
|
|
2700
|
+
for (const key in schema.shape) {
|
|
2701
|
+
const fieldSchema = schema.shape[key];
|
|
2702
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2703
|
+
}
|
|
2704
|
+
return new ZodObject({
|
|
2705
|
+
...schema._def,
|
|
2706
|
+
shape: () => newShape
|
|
2707
|
+
});
|
|
2708
|
+
} else if (schema instanceof ZodArray) {
|
|
2709
|
+
return new ZodArray({
|
|
2710
|
+
...schema._def,
|
|
2711
|
+
type: deepPartialify(schema.element)
|
|
2712
|
+
});
|
|
2713
|
+
} else if (schema instanceof ZodOptional) {
|
|
2714
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2715
|
+
} else if (schema instanceof ZodNullable) {
|
|
2716
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2717
|
+
} else if (schema instanceof ZodTuple) {
|
|
2718
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2719
|
+
} else {
|
|
2720
|
+
return schema;
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
var ZodObject = class _ZodObject extends ZodType {
|
|
2724
|
+
constructor() {
|
|
2725
|
+
super(...arguments);
|
|
2726
|
+
this._cached = null;
|
|
2727
|
+
this.nonstrict = this.passthrough;
|
|
2728
|
+
this.augment = this.extend;
|
|
2729
|
+
}
|
|
2730
|
+
_getCached() {
|
|
2731
|
+
if (this._cached !== null)
|
|
2732
|
+
return this._cached;
|
|
2733
|
+
const shape = this._def.shape();
|
|
2734
|
+
const keys = util.objectKeys(shape);
|
|
2735
|
+
this._cached = { shape, keys };
|
|
2736
|
+
return this._cached;
|
|
2737
|
+
}
|
|
2738
|
+
_parse(input) {
|
|
2739
|
+
const parsedType = this._getType(input);
|
|
2740
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2741
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2742
|
+
addIssueToContext(ctx2, {
|
|
2743
|
+
code: ZodIssueCode.invalid_type,
|
|
2744
|
+
expected: ZodParsedType.object,
|
|
2745
|
+
received: ctx2.parsedType
|
|
2746
|
+
});
|
|
2747
|
+
return INVALID;
|
|
2748
|
+
}
|
|
2749
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2750
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2751
|
+
const extraKeys = [];
|
|
2752
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2753
|
+
for (const key in ctx.data) {
|
|
2754
|
+
if (!shapeKeys.includes(key)) {
|
|
2755
|
+
extraKeys.push(key);
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
const pairs = [];
|
|
2760
|
+
for (const key of shapeKeys) {
|
|
2761
|
+
const keyValidator = shape[key];
|
|
2762
|
+
const value = ctx.data[key];
|
|
2763
|
+
pairs.push({
|
|
2764
|
+
key: { status: "valid", value: key },
|
|
2765
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2766
|
+
alwaysSet: key in ctx.data
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2770
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2771
|
+
if (unknownKeys === "passthrough") {
|
|
2772
|
+
for (const key of extraKeys) {
|
|
2773
|
+
pairs.push({
|
|
2774
|
+
key: { status: "valid", value: key },
|
|
2775
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
} else if (unknownKeys === "strict") {
|
|
2779
|
+
if (extraKeys.length > 0) {
|
|
2780
|
+
addIssueToContext(ctx, {
|
|
2781
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2782
|
+
keys: extraKeys
|
|
2783
|
+
});
|
|
2784
|
+
status.dirty();
|
|
2785
|
+
}
|
|
2786
|
+
} else if (unknownKeys === "strip") {
|
|
2787
|
+
} else {
|
|
2788
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2789
|
+
}
|
|
2790
|
+
} else {
|
|
2791
|
+
const catchall = this._def.catchall;
|
|
2792
|
+
for (const key of extraKeys) {
|
|
2793
|
+
const value = ctx.data[key];
|
|
2794
|
+
pairs.push({
|
|
2795
|
+
key: { status: "valid", value: key },
|
|
2796
|
+
value: catchall._parse(
|
|
2797
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2798
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2799
|
+
),
|
|
2800
|
+
alwaysSet: key in ctx.data
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
if (ctx.common.async) {
|
|
2805
|
+
return Promise.resolve().then(async () => {
|
|
2806
|
+
const syncPairs = [];
|
|
2807
|
+
for (const pair of pairs) {
|
|
2808
|
+
const key = await pair.key;
|
|
2809
|
+
const value = await pair.value;
|
|
2810
|
+
syncPairs.push({
|
|
2811
|
+
key,
|
|
2812
|
+
value,
|
|
2813
|
+
alwaysSet: pair.alwaysSet
|
|
2814
|
+
});
|
|
2815
|
+
}
|
|
2816
|
+
return syncPairs;
|
|
2817
|
+
}).then((syncPairs) => {
|
|
2818
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2819
|
+
});
|
|
2820
|
+
} else {
|
|
2821
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
get shape() {
|
|
2825
|
+
return this._def.shape();
|
|
2826
|
+
}
|
|
2827
|
+
strict(message) {
|
|
2828
|
+
errorUtil.errToObj;
|
|
2829
|
+
return new _ZodObject({
|
|
2830
|
+
...this._def,
|
|
2831
|
+
unknownKeys: "strict",
|
|
2832
|
+
...message !== void 0 ? {
|
|
2833
|
+
errorMap: (issue, ctx) => {
|
|
2834
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2835
|
+
if (issue.code === "unrecognized_keys")
|
|
2836
|
+
return {
|
|
2837
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2838
|
+
};
|
|
2839
|
+
return {
|
|
2840
|
+
message: defaultError
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
} : {}
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
strip() {
|
|
2847
|
+
return new _ZodObject({
|
|
2848
|
+
...this._def,
|
|
2849
|
+
unknownKeys: "strip"
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
passthrough() {
|
|
2853
|
+
return new _ZodObject({
|
|
2854
|
+
...this._def,
|
|
2855
|
+
unknownKeys: "passthrough"
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
// const AugmentFactory =
|
|
2859
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2860
|
+
// <Augmentation extends ZodRawShape>(
|
|
2861
|
+
// augmentation: Augmentation
|
|
2862
|
+
// ): ZodObject<
|
|
2863
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2864
|
+
// Def["unknownKeys"],
|
|
2865
|
+
// Def["catchall"]
|
|
2866
|
+
// > => {
|
|
2867
|
+
// return new ZodObject({
|
|
2868
|
+
// ...def,
|
|
2869
|
+
// shape: () => ({
|
|
2870
|
+
// ...def.shape(),
|
|
2871
|
+
// ...augmentation,
|
|
2872
|
+
// }),
|
|
2873
|
+
// }) as any;
|
|
2874
|
+
// };
|
|
2875
|
+
extend(augmentation) {
|
|
2876
|
+
return new _ZodObject({
|
|
2877
|
+
...this._def,
|
|
2878
|
+
shape: () => ({
|
|
2879
|
+
...this._def.shape(),
|
|
2880
|
+
...augmentation
|
|
2881
|
+
})
|
|
2882
|
+
});
|
|
2883
|
+
}
|
|
2884
|
+
/**
|
|
2885
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2886
|
+
* inferred type of merged objects. Please
|
|
2887
|
+
* upgrade if you are experiencing issues.
|
|
2888
|
+
*/
|
|
2889
|
+
merge(merging) {
|
|
2890
|
+
const merged = new _ZodObject({
|
|
2891
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2892
|
+
catchall: merging._def.catchall,
|
|
2893
|
+
shape: () => ({
|
|
2894
|
+
...this._def.shape(),
|
|
2895
|
+
...merging._def.shape()
|
|
2896
|
+
}),
|
|
2897
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2898
|
+
});
|
|
2899
|
+
return merged;
|
|
2900
|
+
}
|
|
2901
|
+
// merge<
|
|
2902
|
+
// Incoming extends AnyZodObject,
|
|
2903
|
+
// Augmentation extends Incoming["shape"],
|
|
2904
|
+
// NewOutput extends {
|
|
2905
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2906
|
+
// ? Augmentation[k]["_output"]
|
|
2907
|
+
// : k extends keyof Output
|
|
2908
|
+
// ? Output[k]
|
|
2909
|
+
// : never;
|
|
2910
|
+
// },
|
|
2911
|
+
// NewInput extends {
|
|
2912
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2913
|
+
// ? Augmentation[k]["_input"]
|
|
2914
|
+
// : k extends keyof Input
|
|
2915
|
+
// ? Input[k]
|
|
2916
|
+
// : never;
|
|
2917
|
+
// }
|
|
2918
|
+
// >(
|
|
2919
|
+
// merging: Incoming
|
|
2920
|
+
// ): ZodObject<
|
|
2921
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2922
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2923
|
+
// Incoming["_def"]["catchall"],
|
|
2924
|
+
// NewOutput,
|
|
2925
|
+
// NewInput
|
|
2926
|
+
// > {
|
|
2927
|
+
// const merged: any = new ZodObject({
|
|
2928
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2929
|
+
// catchall: merging._def.catchall,
|
|
2930
|
+
// shape: () =>
|
|
2931
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2932
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2933
|
+
// }) as any;
|
|
2934
|
+
// return merged;
|
|
2935
|
+
// }
|
|
2936
|
+
setKey(key, schema) {
|
|
2937
|
+
return this.augment({ [key]: schema });
|
|
2938
|
+
}
|
|
2939
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2940
|
+
// merging: Incoming
|
|
2941
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2942
|
+
// ZodObject<
|
|
2943
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2944
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2945
|
+
// Incoming["_def"]["catchall"]
|
|
2946
|
+
// > {
|
|
2947
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2948
|
+
// // this._def.shape(),
|
|
2949
|
+
// // merging._def.shape()
|
|
2950
|
+
// // );
|
|
2951
|
+
// const merged: any = new ZodObject({
|
|
2952
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2953
|
+
// catchall: merging._def.catchall,
|
|
2954
|
+
// shape: () =>
|
|
2955
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2956
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2957
|
+
// }) as any;
|
|
2958
|
+
// return merged;
|
|
2959
|
+
// }
|
|
2960
|
+
catchall(index) {
|
|
2961
|
+
return new _ZodObject({
|
|
2962
|
+
...this._def,
|
|
2963
|
+
catchall: index
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
pick(mask) {
|
|
2967
|
+
const shape = {};
|
|
2968
|
+
for (const key of util.objectKeys(mask)) {
|
|
2969
|
+
if (mask[key] && this.shape[key]) {
|
|
2970
|
+
shape[key] = this.shape[key];
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
return new _ZodObject({
|
|
2974
|
+
...this._def,
|
|
2975
|
+
shape: () => shape
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
omit(mask) {
|
|
2979
|
+
const shape = {};
|
|
2980
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2981
|
+
if (!mask[key]) {
|
|
2982
|
+
shape[key] = this.shape[key];
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
return new _ZodObject({
|
|
2986
|
+
...this._def,
|
|
2987
|
+
shape: () => shape
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
/**
|
|
2991
|
+
* @deprecated
|
|
2992
|
+
*/
|
|
2993
|
+
deepPartial() {
|
|
2994
|
+
return deepPartialify(this);
|
|
2995
|
+
}
|
|
2996
|
+
partial(mask) {
|
|
2997
|
+
const newShape = {};
|
|
2998
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2999
|
+
const fieldSchema = this.shape[key];
|
|
3000
|
+
if (mask && !mask[key]) {
|
|
3001
|
+
newShape[key] = fieldSchema;
|
|
3002
|
+
} else {
|
|
3003
|
+
newShape[key] = fieldSchema.optional();
|
|
3004
|
+
}
|
|
3005
|
+
}
|
|
3006
|
+
return new _ZodObject({
|
|
3007
|
+
...this._def,
|
|
3008
|
+
shape: () => newShape
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
required(mask) {
|
|
3012
|
+
const newShape = {};
|
|
3013
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
3014
|
+
if (mask && !mask[key]) {
|
|
3015
|
+
newShape[key] = this.shape[key];
|
|
3016
|
+
} else {
|
|
3017
|
+
const fieldSchema = this.shape[key];
|
|
3018
|
+
let newField = fieldSchema;
|
|
3019
|
+
while (newField instanceof ZodOptional) {
|
|
3020
|
+
newField = newField._def.innerType;
|
|
3021
|
+
}
|
|
3022
|
+
newShape[key] = newField;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
return new _ZodObject({
|
|
3026
|
+
...this._def,
|
|
3027
|
+
shape: () => newShape
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
keyof() {
|
|
3031
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
ZodObject.create = (shape, params) => {
|
|
3035
|
+
return new ZodObject({
|
|
3036
|
+
shape: () => shape,
|
|
3037
|
+
unknownKeys: "strip",
|
|
3038
|
+
catchall: ZodNever.create(),
|
|
3039
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3040
|
+
...processCreateParams(params)
|
|
3041
|
+
});
|
|
3042
|
+
};
|
|
3043
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
3044
|
+
return new ZodObject({
|
|
3045
|
+
shape: () => shape,
|
|
3046
|
+
unknownKeys: "strict",
|
|
3047
|
+
catchall: ZodNever.create(),
|
|
3048
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3049
|
+
...processCreateParams(params)
|
|
3050
|
+
});
|
|
3051
|
+
};
|
|
3052
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
3053
|
+
return new ZodObject({
|
|
3054
|
+
shape,
|
|
3055
|
+
unknownKeys: "strip",
|
|
3056
|
+
catchall: ZodNever.create(),
|
|
3057
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3058
|
+
...processCreateParams(params)
|
|
3059
|
+
});
|
|
3060
|
+
};
|
|
3061
|
+
var ZodUnion = class extends ZodType {
|
|
3062
|
+
_parse(input) {
|
|
3063
|
+
const { ctx } = this._processInputParams(input);
|
|
3064
|
+
const options = this._def.options;
|
|
3065
|
+
function handleResults(results) {
|
|
3066
|
+
for (const result of results) {
|
|
3067
|
+
if (result.result.status === "valid") {
|
|
3068
|
+
return result.result;
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
for (const result of results) {
|
|
3072
|
+
if (result.result.status === "dirty") {
|
|
3073
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
3074
|
+
return result.result;
|
|
3075
|
+
}
|
|
3076
|
+
}
|
|
3077
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
3078
|
+
addIssueToContext(ctx, {
|
|
3079
|
+
code: ZodIssueCode.invalid_union,
|
|
3080
|
+
unionErrors
|
|
3081
|
+
});
|
|
3082
|
+
return INVALID;
|
|
3083
|
+
}
|
|
3084
|
+
if (ctx.common.async) {
|
|
3085
|
+
return Promise.all(options.map(async (option) => {
|
|
3086
|
+
const childCtx = {
|
|
3087
|
+
...ctx,
|
|
3088
|
+
common: {
|
|
3089
|
+
...ctx.common,
|
|
3090
|
+
issues: []
|
|
3091
|
+
},
|
|
3092
|
+
parent: null
|
|
3093
|
+
};
|
|
3094
|
+
return {
|
|
3095
|
+
result: await option._parseAsync({
|
|
3096
|
+
data: ctx.data,
|
|
3097
|
+
path: ctx.path,
|
|
3098
|
+
parent: childCtx
|
|
3099
|
+
}),
|
|
3100
|
+
ctx: childCtx
|
|
3101
|
+
};
|
|
3102
|
+
})).then(handleResults);
|
|
3103
|
+
} else {
|
|
3104
|
+
let dirty = void 0;
|
|
3105
|
+
const issues = [];
|
|
3106
|
+
for (const option of options) {
|
|
3107
|
+
const childCtx = {
|
|
3108
|
+
...ctx,
|
|
3109
|
+
common: {
|
|
3110
|
+
...ctx.common,
|
|
3111
|
+
issues: []
|
|
3112
|
+
},
|
|
3113
|
+
parent: null
|
|
3114
|
+
};
|
|
3115
|
+
const result = option._parseSync({
|
|
3116
|
+
data: ctx.data,
|
|
3117
|
+
path: ctx.path,
|
|
3118
|
+
parent: childCtx
|
|
3119
|
+
});
|
|
3120
|
+
if (result.status === "valid") {
|
|
3121
|
+
return result;
|
|
3122
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
3123
|
+
dirty = { result, ctx: childCtx };
|
|
3124
|
+
}
|
|
3125
|
+
if (childCtx.common.issues.length) {
|
|
3126
|
+
issues.push(childCtx.common.issues);
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
if (dirty) {
|
|
3130
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
3131
|
+
return dirty.result;
|
|
3132
|
+
}
|
|
3133
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
3134
|
+
addIssueToContext(ctx, {
|
|
3135
|
+
code: ZodIssueCode.invalid_union,
|
|
3136
|
+
unionErrors
|
|
3137
|
+
});
|
|
3138
|
+
return INVALID;
|
|
3139
|
+
}
|
|
3140
|
+
}
|
|
3141
|
+
get options() {
|
|
3142
|
+
return this._def.options;
|
|
3143
|
+
}
|
|
3144
|
+
};
|
|
3145
|
+
ZodUnion.create = (types, params) => {
|
|
3146
|
+
return new ZodUnion({
|
|
3147
|
+
options: types,
|
|
3148
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
3149
|
+
...processCreateParams(params)
|
|
3150
|
+
});
|
|
3151
|
+
};
|
|
3152
|
+
var getDiscriminator = (type) => {
|
|
3153
|
+
if (type instanceof ZodLazy) {
|
|
3154
|
+
return getDiscriminator(type.schema);
|
|
3155
|
+
} else if (type instanceof ZodEffects) {
|
|
3156
|
+
return getDiscriminator(type.innerType());
|
|
3157
|
+
} else if (type instanceof ZodLiteral) {
|
|
3158
|
+
return [type.value];
|
|
3159
|
+
} else if (type instanceof ZodEnum) {
|
|
3160
|
+
return type.options;
|
|
3161
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
3162
|
+
return util.objectValues(type.enum);
|
|
3163
|
+
} else if (type instanceof ZodDefault) {
|
|
3164
|
+
return getDiscriminator(type._def.innerType);
|
|
3165
|
+
} else if (type instanceof ZodUndefined) {
|
|
3166
|
+
return [void 0];
|
|
3167
|
+
} else if (type instanceof ZodNull) {
|
|
3168
|
+
return [null];
|
|
3169
|
+
} else if (type instanceof ZodOptional) {
|
|
3170
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
|
3171
|
+
} else if (type instanceof ZodNullable) {
|
|
3172
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
3173
|
+
} else if (type instanceof ZodBranded) {
|
|
3174
|
+
return getDiscriminator(type.unwrap());
|
|
3175
|
+
} else if (type instanceof ZodReadonly) {
|
|
3176
|
+
return getDiscriminator(type.unwrap());
|
|
3177
|
+
} else if (type instanceof ZodCatch) {
|
|
3178
|
+
return getDiscriminator(type._def.innerType);
|
|
3179
|
+
} else {
|
|
3180
|
+
return [];
|
|
3181
|
+
}
|
|
3182
|
+
};
|
|
3183
|
+
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3184
|
+
_parse(input) {
|
|
3185
|
+
const { ctx } = this._processInputParams(input);
|
|
3186
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3187
|
+
addIssueToContext(ctx, {
|
|
3188
|
+
code: ZodIssueCode.invalid_type,
|
|
3189
|
+
expected: ZodParsedType.object,
|
|
3190
|
+
received: ctx.parsedType
|
|
3191
|
+
});
|
|
3192
|
+
return INVALID;
|
|
3193
|
+
}
|
|
3194
|
+
const discriminator = this.discriminator;
|
|
3195
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
3196
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
3197
|
+
if (!option) {
|
|
3198
|
+
addIssueToContext(ctx, {
|
|
3199
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
3200
|
+
options: Array.from(this.optionsMap.keys()),
|
|
3201
|
+
path: [discriminator]
|
|
3202
|
+
});
|
|
3203
|
+
return INVALID;
|
|
3204
|
+
}
|
|
3205
|
+
if (ctx.common.async) {
|
|
3206
|
+
return option._parseAsync({
|
|
3207
|
+
data: ctx.data,
|
|
3208
|
+
path: ctx.path,
|
|
3209
|
+
parent: ctx
|
|
3210
|
+
});
|
|
3211
|
+
} else {
|
|
3212
|
+
return option._parseSync({
|
|
3213
|
+
data: ctx.data,
|
|
3214
|
+
path: ctx.path,
|
|
3215
|
+
parent: ctx
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
get discriminator() {
|
|
3220
|
+
return this._def.discriminator;
|
|
3221
|
+
}
|
|
3222
|
+
get options() {
|
|
3223
|
+
return this._def.options;
|
|
3224
|
+
}
|
|
3225
|
+
get optionsMap() {
|
|
3226
|
+
return this._def.optionsMap;
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3230
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3231
|
+
* have a different value for each object in the union.
|
|
3232
|
+
* @param discriminator the name of the discriminator property
|
|
3233
|
+
* @param types an array of object schemas
|
|
3234
|
+
* @param params
|
|
3235
|
+
*/
|
|
3236
|
+
static create(discriminator, options, params) {
|
|
3237
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
3238
|
+
for (const type of options) {
|
|
3239
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3240
|
+
if (!discriminatorValues.length) {
|
|
3241
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3242
|
+
}
|
|
3243
|
+
for (const value of discriminatorValues) {
|
|
3244
|
+
if (optionsMap.has(value)) {
|
|
3245
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3246
|
+
}
|
|
3247
|
+
optionsMap.set(value, type);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
return new _ZodDiscriminatedUnion({
|
|
3251
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3252
|
+
discriminator,
|
|
3253
|
+
options,
|
|
3254
|
+
optionsMap,
|
|
3255
|
+
...processCreateParams(params)
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
function mergeValues(a, b) {
|
|
3260
|
+
const aType = getParsedType(a);
|
|
3261
|
+
const bType = getParsedType(b);
|
|
3262
|
+
if (a === b) {
|
|
3263
|
+
return { valid: true, data: a };
|
|
3264
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3265
|
+
const bKeys = util.objectKeys(b);
|
|
3266
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3267
|
+
const newObj = { ...a, ...b };
|
|
3268
|
+
for (const key of sharedKeys) {
|
|
3269
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
3270
|
+
if (!sharedValue.valid) {
|
|
3271
|
+
return { valid: false };
|
|
3272
|
+
}
|
|
3273
|
+
newObj[key] = sharedValue.data;
|
|
3274
|
+
}
|
|
3275
|
+
return { valid: true, data: newObj };
|
|
3276
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
3277
|
+
if (a.length !== b.length) {
|
|
3278
|
+
return { valid: false };
|
|
3279
|
+
}
|
|
3280
|
+
const newArray = [];
|
|
3281
|
+
for (let index = 0; index < a.length; index++) {
|
|
3282
|
+
const itemA = a[index];
|
|
3283
|
+
const itemB = b[index];
|
|
3284
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
3285
|
+
if (!sharedValue.valid) {
|
|
3286
|
+
return { valid: false };
|
|
3287
|
+
}
|
|
3288
|
+
newArray.push(sharedValue.data);
|
|
3289
|
+
}
|
|
3290
|
+
return { valid: true, data: newArray };
|
|
3291
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3292
|
+
return { valid: true, data: a };
|
|
3293
|
+
} else {
|
|
3294
|
+
return { valid: false };
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
var ZodIntersection = class extends ZodType {
|
|
3298
|
+
_parse(input) {
|
|
3299
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3300
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3301
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3302
|
+
return INVALID;
|
|
3303
|
+
}
|
|
3304
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3305
|
+
if (!merged.valid) {
|
|
3306
|
+
addIssueToContext(ctx, {
|
|
3307
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
3308
|
+
});
|
|
3309
|
+
return INVALID;
|
|
3310
|
+
}
|
|
3311
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3312
|
+
status.dirty();
|
|
3313
|
+
}
|
|
3314
|
+
return { status: status.value, value: merged.data };
|
|
3315
|
+
};
|
|
3316
|
+
if (ctx.common.async) {
|
|
3317
|
+
return Promise.all([
|
|
3318
|
+
this._def.left._parseAsync({
|
|
3319
|
+
data: ctx.data,
|
|
3320
|
+
path: ctx.path,
|
|
3321
|
+
parent: ctx
|
|
3322
|
+
}),
|
|
3323
|
+
this._def.right._parseAsync({
|
|
3324
|
+
data: ctx.data,
|
|
3325
|
+
path: ctx.path,
|
|
3326
|
+
parent: ctx
|
|
3327
|
+
})
|
|
3328
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
3329
|
+
} else {
|
|
3330
|
+
return handleParsed(this._def.left._parseSync({
|
|
3331
|
+
data: ctx.data,
|
|
3332
|
+
path: ctx.path,
|
|
3333
|
+
parent: ctx
|
|
3334
|
+
}), this._def.right._parseSync({
|
|
3335
|
+
data: ctx.data,
|
|
3336
|
+
path: ctx.path,
|
|
3337
|
+
parent: ctx
|
|
3338
|
+
}));
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3343
|
+
return new ZodIntersection({
|
|
3344
|
+
left,
|
|
3345
|
+
right,
|
|
3346
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3347
|
+
...processCreateParams(params)
|
|
3348
|
+
});
|
|
3349
|
+
};
|
|
3350
|
+
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3351
|
+
_parse(input) {
|
|
3352
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3353
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3354
|
+
addIssueToContext(ctx, {
|
|
3355
|
+
code: ZodIssueCode.invalid_type,
|
|
3356
|
+
expected: ZodParsedType.array,
|
|
3357
|
+
received: ctx.parsedType
|
|
3358
|
+
});
|
|
3359
|
+
return INVALID;
|
|
3360
|
+
}
|
|
3361
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3362
|
+
addIssueToContext(ctx, {
|
|
3363
|
+
code: ZodIssueCode.too_small,
|
|
3364
|
+
minimum: this._def.items.length,
|
|
3365
|
+
inclusive: true,
|
|
3366
|
+
exact: false,
|
|
3367
|
+
type: "array"
|
|
3368
|
+
});
|
|
3369
|
+
return INVALID;
|
|
3370
|
+
}
|
|
3371
|
+
const rest = this._def.rest;
|
|
3372
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3373
|
+
addIssueToContext(ctx, {
|
|
3374
|
+
code: ZodIssueCode.too_big,
|
|
3375
|
+
maximum: this._def.items.length,
|
|
3376
|
+
inclusive: true,
|
|
3377
|
+
exact: false,
|
|
3378
|
+
type: "array"
|
|
3379
|
+
});
|
|
3380
|
+
status.dirty();
|
|
3381
|
+
}
|
|
3382
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3383
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3384
|
+
if (!schema)
|
|
3385
|
+
return null;
|
|
3386
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3387
|
+
}).filter((x) => !!x);
|
|
3388
|
+
if (ctx.common.async) {
|
|
3389
|
+
return Promise.all(items).then((results) => {
|
|
3390
|
+
return ParseStatus.mergeArray(status, results);
|
|
3391
|
+
});
|
|
3392
|
+
} else {
|
|
3393
|
+
return ParseStatus.mergeArray(status, items);
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
get items() {
|
|
3397
|
+
return this._def.items;
|
|
3398
|
+
}
|
|
3399
|
+
rest(rest) {
|
|
3400
|
+
return new _ZodTuple({
|
|
3401
|
+
...this._def,
|
|
3402
|
+
rest
|
|
3403
|
+
});
|
|
3404
|
+
}
|
|
402
3405
|
};
|
|
403
|
-
|
|
3406
|
+
ZodTuple.create = (schemas, params) => {
|
|
3407
|
+
if (!Array.isArray(schemas)) {
|
|
3408
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3409
|
+
}
|
|
3410
|
+
return new ZodTuple({
|
|
3411
|
+
items: schemas,
|
|
3412
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3413
|
+
rest: null,
|
|
3414
|
+
...processCreateParams(params)
|
|
3415
|
+
});
|
|
3416
|
+
};
|
|
3417
|
+
var ZodRecord = class _ZodRecord extends ZodType {
|
|
3418
|
+
get keySchema() {
|
|
3419
|
+
return this._def.keyType;
|
|
3420
|
+
}
|
|
3421
|
+
get valueSchema() {
|
|
3422
|
+
return this._def.valueType;
|
|
3423
|
+
}
|
|
3424
|
+
_parse(input) {
|
|
3425
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3426
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3427
|
+
addIssueToContext(ctx, {
|
|
3428
|
+
code: ZodIssueCode.invalid_type,
|
|
3429
|
+
expected: ZodParsedType.object,
|
|
3430
|
+
received: ctx.parsedType
|
|
3431
|
+
});
|
|
3432
|
+
return INVALID;
|
|
3433
|
+
}
|
|
3434
|
+
const pairs = [];
|
|
3435
|
+
const keyType = this._def.keyType;
|
|
3436
|
+
const valueType = this._def.valueType;
|
|
3437
|
+
for (const key in ctx.data) {
|
|
3438
|
+
pairs.push({
|
|
3439
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3440
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3441
|
+
alwaysSet: key in ctx.data
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
if (ctx.common.async) {
|
|
3445
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3446
|
+
} else {
|
|
3447
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
get element() {
|
|
3451
|
+
return this._def.valueType;
|
|
3452
|
+
}
|
|
3453
|
+
static create(first, second, third) {
|
|
3454
|
+
if (second instanceof ZodType) {
|
|
3455
|
+
return new _ZodRecord({
|
|
3456
|
+
keyType: first,
|
|
3457
|
+
valueType: second,
|
|
3458
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3459
|
+
...processCreateParams(third)
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
return new _ZodRecord({
|
|
3463
|
+
keyType: ZodString.create(),
|
|
3464
|
+
valueType: first,
|
|
3465
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3466
|
+
...processCreateParams(second)
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
};
|
|
3470
|
+
var ZodMap = class extends ZodType {
|
|
3471
|
+
get keySchema() {
|
|
3472
|
+
return this._def.keyType;
|
|
3473
|
+
}
|
|
3474
|
+
get valueSchema() {
|
|
3475
|
+
return this._def.valueType;
|
|
3476
|
+
}
|
|
3477
|
+
_parse(input) {
|
|
3478
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3479
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3480
|
+
addIssueToContext(ctx, {
|
|
3481
|
+
code: ZodIssueCode.invalid_type,
|
|
3482
|
+
expected: ZodParsedType.map,
|
|
3483
|
+
received: ctx.parsedType
|
|
3484
|
+
});
|
|
3485
|
+
return INVALID;
|
|
3486
|
+
}
|
|
3487
|
+
const keyType = this._def.keyType;
|
|
3488
|
+
const valueType = this._def.valueType;
|
|
3489
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3490
|
+
return {
|
|
3491
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3492
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3493
|
+
};
|
|
3494
|
+
});
|
|
3495
|
+
if (ctx.common.async) {
|
|
3496
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3497
|
+
return Promise.resolve().then(async () => {
|
|
3498
|
+
for (const pair of pairs) {
|
|
3499
|
+
const key = await pair.key;
|
|
3500
|
+
const value = await pair.value;
|
|
3501
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3502
|
+
return INVALID;
|
|
3503
|
+
}
|
|
3504
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3505
|
+
status.dirty();
|
|
3506
|
+
}
|
|
3507
|
+
finalMap.set(key.value, value.value);
|
|
3508
|
+
}
|
|
3509
|
+
return { status: status.value, value: finalMap };
|
|
3510
|
+
});
|
|
3511
|
+
} else {
|
|
3512
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3513
|
+
for (const pair of pairs) {
|
|
3514
|
+
const key = pair.key;
|
|
3515
|
+
const value = pair.value;
|
|
3516
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3517
|
+
return INVALID;
|
|
3518
|
+
}
|
|
3519
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3520
|
+
status.dirty();
|
|
3521
|
+
}
|
|
3522
|
+
finalMap.set(key.value, value.value);
|
|
3523
|
+
}
|
|
3524
|
+
return { status: status.value, value: finalMap };
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3527
|
+
};
|
|
3528
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3529
|
+
return new ZodMap({
|
|
3530
|
+
valueType,
|
|
3531
|
+
keyType,
|
|
3532
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3533
|
+
...processCreateParams(params)
|
|
3534
|
+
});
|
|
3535
|
+
};
|
|
3536
|
+
var ZodSet = class _ZodSet extends ZodType {
|
|
3537
|
+
_parse(input) {
|
|
3538
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3539
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3540
|
+
addIssueToContext(ctx, {
|
|
3541
|
+
code: ZodIssueCode.invalid_type,
|
|
3542
|
+
expected: ZodParsedType.set,
|
|
3543
|
+
received: ctx.parsedType
|
|
3544
|
+
});
|
|
3545
|
+
return INVALID;
|
|
3546
|
+
}
|
|
3547
|
+
const def = this._def;
|
|
3548
|
+
if (def.minSize !== null) {
|
|
3549
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3550
|
+
addIssueToContext(ctx, {
|
|
3551
|
+
code: ZodIssueCode.too_small,
|
|
3552
|
+
minimum: def.minSize.value,
|
|
3553
|
+
type: "set",
|
|
3554
|
+
inclusive: true,
|
|
3555
|
+
exact: false,
|
|
3556
|
+
message: def.minSize.message
|
|
3557
|
+
});
|
|
3558
|
+
status.dirty();
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
if (def.maxSize !== null) {
|
|
3562
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3563
|
+
addIssueToContext(ctx, {
|
|
3564
|
+
code: ZodIssueCode.too_big,
|
|
3565
|
+
maximum: def.maxSize.value,
|
|
3566
|
+
type: "set",
|
|
3567
|
+
inclusive: true,
|
|
3568
|
+
exact: false,
|
|
3569
|
+
message: def.maxSize.message
|
|
3570
|
+
});
|
|
3571
|
+
status.dirty();
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
const valueType = this._def.valueType;
|
|
3575
|
+
function finalizeSet(elements2) {
|
|
3576
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3577
|
+
for (const element of elements2) {
|
|
3578
|
+
if (element.status === "aborted")
|
|
3579
|
+
return INVALID;
|
|
3580
|
+
if (element.status === "dirty")
|
|
3581
|
+
status.dirty();
|
|
3582
|
+
parsedSet.add(element.value);
|
|
3583
|
+
}
|
|
3584
|
+
return { status: status.value, value: parsedSet };
|
|
3585
|
+
}
|
|
3586
|
+
const elements = [...ctx.data.values()].map((item, i2) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i2)));
|
|
3587
|
+
if (ctx.common.async) {
|
|
3588
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3589
|
+
} else {
|
|
3590
|
+
return finalizeSet(elements);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
min(minSize, message) {
|
|
3594
|
+
return new _ZodSet({
|
|
3595
|
+
...this._def,
|
|
3596
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3597
|
+
});
|
|
3598
|
+
}
|
|
3599
|
+
max(maxSize, message) {
|
|
3600
|
+
return new _ZodSet({
|
|
3601
|
+
...this._def,
|
|
3602
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3603
|
+
});
|
|
3604
|
+
}
|
|
3605
|
+
size(size, message) {
|
|
3606
|
+
return this.min(size, message).max(size, message);
|
|
3607
|
+
}
|
|
3608
|
+
nonempty(message) {
|
|
3609
|
+
return this.min(1, message);
|
|
3610
|
+
}
|
|
3611
|
+
};
|
|
3612
|
+
ZodSet.create = (valueType, params) => {
|
|
3613
|
+
return new ZodSet({
|
|
3614
|
+
valueType,
|
|
3615
|
+
minSize: null,
|
|
3616
|
+
maxSize: null,
|
|
3617
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3618
|
+
...processCreateParams(params)
|
|
3619
|
+
});
|
|
3620
|
+
};
|
|
3621
|
+
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3622
|
+
constructor() {
|
|
3623
|
+
super(...arguments);
|
|
3624
|
+
this.validate = this.implement;
|
|
3625
|
+
}
|
|
3626
|
+
_parse(input) {
|
|
3627
|
+
const { ctx } = this._processInputParams(input);
|
|
3628
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3629
|
+
addIssueToContext(ctx, {
|
|
3630
|
+
code: ZodIssueCode.invalid_type,
|
|
3631
|
+
expected: ZodParsedType.function,
|
|
3632
|
+
received: ctx.parsedType
|
|
3633
|
+
});
|
|
3634
|
+
return INVALID;
|
|
3635
|
+
}
|
|
3636
|
+
function makeArgsIssue(args, error) {
|
|
3637
|
+
return makeIssue({
|
|
3638
|
+
data: args,
|
|
3639
|
+
path: ctx.path,
|
|
3640
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3641
|
+
issueData: {
|
|
3642
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3643
|
+
argumentsError: error
|
|
3644
|
+
}
|
|
3645
|
+
});
|
|
3646
|
+
}
|
|
3647
|
+
function makeReturnsIssue(returns, error) {
|
|
3648
|
+
return makeIssue({
|
|
3649
|
+
data: returns,
|
|
3650
|
+
path: ctx.path,
|
|
3651
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3652
|
+
issueData: {
|
|
3653
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3654
|
+
returnTypeError: error
|
|
3655
|
+
}
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3659
|
+
const fn = ctx.data;
|
|
3660
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3661
|
+
const me = this;
|
|
3662
|
+
return OK(async function(...args) {
|
|
3663
|
+
const error = new ZodError([]);
|
|
3664
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
|
|
3665
|
+
error.addIssue(makeArgsIssue(args, e2));
|
|
3666
|
+
throw error;
|
|
3667
|
+
});
|
|
3668
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3669
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
|
|
3670
|
+
error.addIssue(makeReturnsIssue(result, e2));
|
|
3671
|
+
throw error;
|
|
3672
|
+
});
|
|
3673
|
+
return parsedReturns;
|
|
3674
|
+
});
|
|
3675
|
+
} else {
|
|
3676
|
+
const me = this;
|
|
3677
|
+
return OK(function(...args) {
|
|
3678
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3679
|
+
if (!parsedArgs.success) {
|
|
3680
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3681
|
+
}
|
|
3682
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3683
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3684
|
+
if (!parsedReturns.success) {
|
|
3685
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3686
|
+
}
|
|
3687
|
+
return parsedReturns.data;
|
|
3688
|
+
});
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
parameters() {
|
|
3692
|
+
return this._def.args;
|
|
3693
|
+
}
|
|
3694
|
+
returnType() {
|
|
3695
|
+
return this._def.returns;
|
|
3696
|
+
}
|
|
3697
|
+
args(...items) {
|
|
3698
|
+
return new _ZodFunction({
|
|
3699
|
+
...this._def,
|
|
3700
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3701
|
+
});
|
|
3702
|
+
}
|
|
3703
|
+
returns(returnType) {
|
|
3704
|
+
return new _ZodFunction({
|
|
3705
|
+
...this._def,
|
|
3706
|
+
returns: returnType
|
|
3707
|
+
});
|
|
3708
|
+
}
|
|
3709
|
+
implement(func) {
|
|
3710
|
+
const validatedFunc = this.parse(func);
|
|
3711
|
+
return validatedFunc;
|
|
3712
|
+
}
|
|
3713
|
+
strictImplement(func) {
|
|
3714
|
+
const validatedFunc = this.parse(func);
|
|
3715
|
+
return validatedFunc;
|
|
3716
|
+
}
|
|
3717
|
+
static create(args, returns, params) {
|
|
3718
|
+
return new _ZodFunction({
|
|
3719
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3720
|
+
returns: returns || ZodUnknown.create(),
|
|
3721
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3722
|
+
...processCreateParams(params)
|
|
3723
|
+
});
|
|
3724
|
+
}
|
|
3725
|
+
};
|
|
3726
|
+
var ZodLazy = class extends ZodType {
|
|
3727
|
+
get schema() {
|
|
3728
|
+
return this._def.getter();
|
|
3729
|
+
}
|
|
3730
|
+
_parse(input) {
|
|
3731
|
+
const { ctx } = this._processInputParams(input);
|
|
3732
|
+
const lazySchema = this._def.getter();
|
|
3733
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3734
|
+
}
|
|
3735
|
+
};
|
|
3736
|
+
ZodLazy.create = (getter, params) => {
|
|
3737
|
+
return new ZodLazy({
|
|
3738
|
+
getter,
|
|
3739
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3740
|
+
...processCreateParams(params)
|
|
3741
|
+
});
|
|
3742
|
+
};
|
|
3743
|
+
var ZodLiteral = class extends ZodType {
|
|
3744
|
+
_parse(input) {
|
|
3745
|
+
if (input.data !== this._def.value) {
|
|
3746
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3747
|
+
addIssueToContext(ctx, {
|
|
3748
|
+
received: ctx.data,
|
|
3749
|
+
code: ZodIssueCode.invalid_literal,
|
|
3750
|
+
expected: this._def.value
|
|
3751
|
+
});
|
|
3752
|
+
return INVALID;
|
|
3753
|
+
}
|
|
3754
|
+
return { status: "valid", value: input.data };
|
|
3755
|
+
}
|
|
3756
|
+
get value() {
|
|
3757
|
+
return this._def.value;
|
|
3758
|
+
}
|
|
3759
|
+
};
|
|
3760
|
+
ZodLiteral.create = (value, params) => {
|
|
3761
|
+
return new ZodLiteral({
|
|
3762
|
+
value,
|
|
3763
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3764
|
+
...processCreateParams(params)
|
|
3765
|
+
});
|
|
3766
|
+
};
|
|
3767
|
+
function createZodEnum(values, params) {
|
|
3768
|
+
return new ZodEnum({
|
|
3769
|
+
values,
|
|
3770
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3771
|
+
...processCreateParams(params)
|
|
3772
|
+
});
|
|
3773
|
+
}
|
|
3774
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3775
|
+
_parse(input) {
|
|
3776
|
+
if (typeof input.data !== "string") {
|
|
3777
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3778
|
+
const expectedValues = this._def.values;
|
|
3779
|
+
addIssueToContext(ctx, {
|
|
3780
|
+
expected: util.joinValues(expectedValues),
|
|
3781
|
+
received: ctx.parsedType,
|
|
3782
|
+
code: ZodIssueCode.invalid_type
|
|
3783
|
+
});
|
|
3784
|
+
return INVALID;
|
|
3785
|
+
}
|
|
3786
|
+
if (!this._cache) {
|
|
3787
|
+
this._cache = new Set(this._def.values);
|
|
3788
|
+
}
|
|
3789
|
+
if (!this._cache.has(input.data)) {
|
|
3790
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3791
|
+
const expectedValues = this._def.values;
|
|
3792
|
+
addIssueToContext(ctx, {
|
|
3793
|
+
received: ctx.data,
|
|
3794
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3795
|
+
options: expectedValues
|
|
3796
|
+
});
|
|
3797
|
+
return INVALID;
|
|
3798
|
+
}
|
|
3799
|
+
return OK(input.data);
|
|
3800
|
+
}
|
|
3801
|
+
get options() {
|
|
3802
|
+
return this._def.values;
|
|
3803
|
+
}
|
|
3804
|
+
get enum() {
|
|
3805
|
+
const enumValues = {};
|
|
3806
|
+
for (const val of this._def.values) {
|
|
3807
|
+
enumValues[val] = val;
|
|
3808
|
+
}
|
|
3809
|
+
return enumValues;
|
|
3810
|
+
}
|
|
3811
|
+
get Values() {
|
|
3812
|
+
const enumValues = {};
|
|
3813
|
+
for (const val of this._def.values) {
|
|
3814
|
+
enumValues[val] = val;
|
|
3815
|
+
}
|
|
3816
|
+
return enumValues;
|
|
3817
|
+
}
|
|
3818
|
+
get Enum() {
|
|
3819
|
+
const enumValues = {};
|
|
3820
|
+
for (const val of this._def.values) {
|
|
3821
|
+
enumValues[val] = val;
|
|
3822
|
+
}
|
|
3823
|
+
return enumValues;
|
|
3824
|
+
}
|
|
3825
|
+
extract(values, newDef = this._def) {
|
|
3826
|
+
return _ZodEnum.create(values, {
|
|
3827
|
+
...this._def,
|
|
3828
|
+
...newDef
|
|
3829
|
+
});
|
|
3830
|
+
}
|
|
3831
|
+
exclude(values, newDef = this._def) {
|
|
3832
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3833
|
+
...this._def,
|
|
3834
|
+
...newDef
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
3837
|
+
};
|
|
3838
|
+
ZodEnum.create = createZodEnum;
|
|
3839
|
+
var ZodNativeEnum = class extends ZodType {
|
|
3840
|
+
_parse(input) {
|
|
3841
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3842
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3843
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3844
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3845
|
+
addIssueToContext(ctx, {
|
|
3846
|
+
expected: util.joinValues(expectedValues),
|
|
3847
|
+
received: ctx.parsedType,
|
|
3848
|
+
code: ZodIssueCode.invalid_type
|
|
3849
|
+
});
|
|
3850
|
+
return INVALID;
|
|
3851
|
+
}
|
|
3852
|
+
if (!this._cache) {
|
|
3853
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3854
|
+
}
|
|
3855
|
+
if (!this._cache.has(input.data)) {
|
|
3856
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3857
|
+
addIssueToContext(ctx, {
|
|
3858
|
+
received: ctx.data,
|
|
3859
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3860
|
+
options: expectedValues
|
|
3861
|
+
});
|
|
3862
|
+
return INVALID;
|
|
3863
|
+
}
|
|
3864
|
+
return OK(input.data);
|
|
3865
|
+
}
|
|
3866
|
+
get enum() {
|
|
3867
|
+
return this._def.values;
|
|
3868
|
+
}
|
|
3869
|
+
};
|
|
3870
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3871
|
+
return new ZodNativeEnum({
|
|
3872
|
+
values,
|
|
3873
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3874
|
+
...processCreateParams(params)
|
|
3875
|
+
});
|
|
3876
|
+
};
|
|
3877
|
+
var ZodPromise = class extends ZodType {
|
|
3878
|
+
unwrap() {
|
|
3879
|
+
return this._def.type;
|
|
3880
|
+
}
|
|
3881
|
+
_parse(input) {
|
|
3882
|
+
const { ctx } = this._processInputParams(input);
|
|
3883
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3884
|
+
addIssueToContext(ctx, {
|
|
3885
|
+
code: ZodIssueCode.invalid_type,
|
|
3886
|
+
expected: ZodParsedType.promise,
|
|
3887
|
+
received: ctx.parsedType
|
|
3888
|
+
});
|
|
3889
|
+
return INVALID;
|
|
3890
|
+
}
|
|
3891
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3892
|
+
return OK(promisified.then((data) => {
|
|
3893
|
+
return this._def.type.parseAsync(data, {
|
|
3894
|
+
path: ctx.path,
|
|
3895
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3896
|
+
});
|
|
3897
|
+
}));
|
|
3898
|
+
}
|
|
3899
|
+
};
|
|
3900
|
+
ZodPromise.create = (schema, params) => {
|
|
3901
|
+
return new ZodPromise({
|
|
3902
|
+
type: schema,
|
|
3903
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3904
|
+
...processCreateParams(params)
|
|
3905
|
+
});
|
|
3906
|
+
};
|
|
3907
|
+
var ZodEffects = class extends ZodType {
|
|
3908
|
+
innerType() {
|
|
3909
|
+
return this._def.schema;
|
|
3910
|
+
}
|
|
3911
|
+
sourceType() {
|
|
3912
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3913
|
+
}
|
|
3914
|
+
_parse(input) {
|
|
3915
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3916
|
+
const effect = this._def.effect || null;
|
|
3917
|
+
const checkCtx = {
|
|
3918
|
+
addIssue: (arg) => {
|
|
3919
|
+
addIssueToContext(ctx, arg);
|
|
3920
|
+
if (arg.fatal) {
|
|
3921
|
+
status.abort();
|
|
3922
|
+
} else {
|
|
3923
|
+
status.dirty();
|
|
3924
|
+
}
|
|
3925
|
+
},
|
|
3926
|
+
get path() {
|
|
3927
|
+
return ctx.path;
|
|
3928
|
+
}
|
|
3929
|
+
};
|
|
3930
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3931
|
+
if (effect.type === "preprocess") {
|
|
3932
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3933
|
+
if (ctx.common.async) {
|
|
3934
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3935
|
+
if (status.value === "aborted")
|
|
3936
|
+
return INVALID;
|
|
3937
|
+
const result = await this._def.schema._parseAsync({
|
|
3938
|
+
data: processed2,
|
|
3939
|
+
path: ctx.path,
|
|
3940
|
+
parent: ctx
|
|
3941
|
+
});
|
|
3942
|
+
if (result.status === "aborted")
|
|
3943
|
+
return INVALID;
|
|
3944
|
+
if (result.status === "dirty")
|
|
3945
|
+
return DIRTY(result.value);
|
|
3946
|
+
if (status.value === "dirty")
|
|
3947
|
+
return DIRTY(result.value);
|
|
3948
|
+
return result;
|
|
3949
|
+
});
|
|
3950
|
+
} else {
|
|
3951
|
+
if (status.value === "aborted")
|
|
3952
|
+
return INVALID;
|
|
3953
|
+
const result = this._def.schema._parseSync({
|
|
3954
|
+
data: processed,
|
|
3955
|
+
path: ctx.path,
|
|
3956
|
+
parent: ctx
|
|
3957
|
+
});
|
|
3958
|
+
if (result.status === "aborted")
|
|
3959
|
+
return INVALID;
|
|
3960
|
+
if (result.status === "dirty")
|
|
3961
|
+
return DIRTY(result.value);
|
|
3962
|
+
if (status.value === "dirty")
|
|
3963
|
+
return DIRTY(result.value);
|
|
3964
|
+
return result;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
if (effect.type === "refinement") {
|
|
3968
|
+
const executeRefinement = (acc) => {
|
|
3969
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3970
|
+
if (ctx.common.async) {
|
|
3971
|
+
return Promise.resolve(result);
|
|
3972
|
+
}
|
|
3973
|
+
if (result instanceof Promise) {
|
|
3974
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3975
|
+
}
|
|
3976
|
+
return acc;
|
|
3977
|
+
};
|
|
3978
|
+
if (ctx.common.async === false) {
|
|
3979
|
+
const inner = this._def.schema._parseSync({
|
|
3980
|
+
data: ctx.data,
|
|
3981
|
+
path: ctx.path,
|
|
3982
|
+
parent: ctx
|
|
3983
|
+
});
|
|
3984
|
+
if (inner.status === "aborted")
|
|
3985
|
+
return INVALID;
|
|
3986
|
+
if (inner.status === "dirty")
|
|
3987
|
+
status.dirty();
|
|
3988
|
+
executeRefinement(inner.value);
|
|
3989
|
+
return { status: status.value, value: inner.value };
|
|
3990
|
+
} else {
|
|
3991
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3992
|
+
if (inner.status === "aborted")
|
|
3993
|
+
return INVALID;
|
|
3994
|
+
if (inner.status === "dirty")
|
|
3995
|
+
status.dirty();
|
|
3996
|
+
return executeRefinement(inner.value).then(() => {
|
|
3997
|
+
return { status: status.value, value: inner.value };
|
|
3998
|
+
});
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
}
|
|
4002
|
+
if (effect.type === "transform") {
|
|
4003
|
+
if (ctx.common.async === false) {
|
|
4004
|
+
const base = this._def.schema._parseSync({
|
|
4005
|
+
data: ctx.data,
|
|
4006
|
+
path: ctx.path,
|
|
4007
|
+
parent: ctx
|
|
4008
|
+
});
|
|
4009
|
+
if (!isValid(base))
|
|
4010
|
+
return INVALID;
|
|
4011
|
+
const result = effect.transform(base.value, checkCtx);
|
|
4012
|
+
if (result instanceof Promise) {
|
|
4013
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
4014
|
+
}
|
|
4015
|
+
return { status: status.value, value: result };
|
|
4016
|
+
} else {
|
|
4017
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
4018
|
+
if (!isValid(base))
|
|
4019
|
+
return INVALID;
|
|
4020
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
4021
|
+
status: status.value,
|
|
4022
|
+
value: result
|
|
4023
|
+
}));
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
}
|
|
4027
|
+
util.assertNever(effect);
|
|
4028
|
+
}
|
|
4029
|
+
};
|
|
4030
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
4031
|
+
return new ZodEffects({
|
|
4032
|
+
schema,
|
|
4033
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4034
|
+
effect,
|
|
4035
|
+
...processCreateParams(params)
|
|
4036
|
+
});
|
|
4037
|
+
};
|
|
4038
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
4039
|
+
return new ZodEffects({
|
|
4040
|
+
schema,
|
|
4041
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
4042
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4043
|
+
...processCreateParams(params)
|
|
4044
|
+
});
|
|
4045
|
+
};
|
|
4046
|
+
var ZodOptional = class extends ZodType {
|
|
4047
|
+
_parse(input) {
|
|
4048
|
+
const parsedType = this._getType(input);
|
|
4049
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
4050
|
+
return OK(void 0);
|
|
4051
|
+
}
|
|
4052
|
+
return this._def.innerType._parse(input);
|
|
4053
|
+
}
|
|
4054
|
+
unwrap() {
|
|
4055
|
+
return this._def.innerType;
|
|
4056
|
+
}
|
|
4057
|
+
};
|
|
4058
|
+
ZodOptional.create = (type, params) => {
|
|
4059
|
+
return new ZodOptional({
|
|
4060
|
+
innerType: type,
|
|
4061
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
4062
|
+
...processCreateParams(params)
|
|
4063
|
+
});
|
|
4064
|
+
};
|
|
4065
|
+
var ZodNullable = class extends ZodType {
|
|
4066
|
+
_parse(input) {
|
|
4067
|
+
const parsedType = this._getType(input);
|
|
4068
|
+
if (parsedType === ZodParsedType.null) {
|
|
4069
|
+
return OK(null);
|
|
4070
|
+
}
|
|
4071
|
+
return this._def.innerType._parse(input);
|
|
4072
|
+
}
|
|
4073
|
+
unwrap() {
|
|
4074
|
+
return this._def.innerType;
|
|
4075
|
+
}
|
|
4076
|
+
};
|
|
4077
|
+
ZodNullable.create = (type, params) => {
|
|
4078
|
+
return new ZodNullable({
|
|
4079
|
+
innerType: type,
|
|
4080
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
4081
|
+
...processCreateParams(params)
|
|
4082
|
+
});
|
|
4083
|
+
};
|
|
4084
|
+
var ZodDefault = class extends ZodType {
|
|
4085
|
+
_parse(input) {
|
|
4086
|
+
const { ctx } = this._processInputParams(input);
|
|
4087
|
+
let data = ctx.data;
|
|
4088
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
4089
|
+
data = this._def.defaultValue();
|
|
4090
|
+
}
|
|
4091
|
+
return this._def.innerType._parse({
|
|
4092
|
+
data,
|
|
4093
|
+
path: ctx.path,
|
|
4094
|
+
parent: ctx
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4097
|
+
removeDefault() {
|
|
4098
|
+
return this._def.innerType;
|
|
4099
|
+
}
|
|
4100
|
+
};
|
|
4101
|
+
ZodDefault.create = (type, params) => {
|
|
4102
|
+
return new ZodDefault({
|
|
4103
|
+
innerType: type,
|
|
4104
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4105
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4106
|
+
...processCreateParams(params)
|
|
4107
|
+
});
|
|
4108
|
+
};
|
|
4109
|
+
var ZodCatch = class extends ZodType {
|
|
4110
|
+
_parse(input) {
|
|
4111
|
+
const { ctx } = this._processInputParams(input);
|
|
4112
|
+
const newCtx = {
|
|
4113
|
+
...ctx,
|
|
4114
|
+
common: {
|
|
4115
|
+
...ctx.common,
|
|
4116
|
+
issues: []
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
const result = this._def.innerType._parse({
|
|
4120
|
+
data: newCtx.data,
|
|
4121
|
+
path: newCtx.path,
|
|
4122
|
+
parent: {
|
|
4123
|
+
...newCtx
|
|
4124
|
+
}
|
|
4125
|
+
});
|
|
4126
|
+
if (isAsync(result)) {
|
|
4127
|
+
return result.then((result2) => {
|
|
4128
|
+
return {
|
|
4129
|
+
status: "valid",
|
|
4130
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
4131
|
+
get error() {
|
|
4132
|
+
return new ZodError(newCtx.common.issues);
|
|
4133
|
+
},
|
|
4134
|
+
input: newCtx.data
|
|
4135
|
+
})
|
|
4136
|
+
};
|
|
4137
|
+
});
|
|
4138
|
+
} else {
|
|
4139
|
+
return {
|
|
4140
|
+
status: "valid",
|
|
4141
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
4142
|
+
get error() {
|
|
4143
|
+
return new ZodError(newCtx.common.issues);
|
|
4144
|
+
},
|
|
4145
|
+
input: newCtx.data
|
|
4146
|
+
})
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
removeCatch() {
|
|
4151
|
+
return this._def.innerType;
|
|
4152
|
+
}
|
|
4153
|
+
};
|
|
4154
|
+
ZodCatch.create = (type, params) => {
|
|
4155
|
+
return new ZodCatch({
|
|
4156
|
+
innerType: type,
|
|
4157
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
4158
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
4159
|
+
...processCreateParams(params)
|
|
4160
|
+
});
|
|
4161
|
+
};
|
|
4162
|
+
var ZodNaN = class extends ZodType {
|
|
4163
|
+
_parse(input) {
|
|
4164
|
+
const parsedType = this._getType(input);
|
|
4165
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
4166
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4167
|
+
addIssueToContext(ctx, {
|
|
4168
|
+
code: ZodIssueCode.invalid_type,
|
|
4169
|
+
expected: ZodParsedType.nan,
|
|
4170
|
+
received: ctx.parsedType
|
|
4171
|
+
});
|
|
4172
|
+
return INVALID;
|
|
4173
|
+
}
|
|
4174
|
+
return { status: "valid", value: input.data };
|
|
4175
|
+
}
|
|
4176
|
+
};
|
|
4177
|
+
ZodNaN.create = (params) => {
|
|
4178
|
+
return new ZodNaN({
|
|
4179
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
4180
|
+
...processCreateParams(params)
|
|
4181
|
+
});
|
|
4182
|
+
};
|
|
4183
|
+
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
4184
|
+
var ZodBranded = class extends ZodType {
|
|
4185
|
+
_parse(input) {
|
|
4186
|
+
const { ctx } = this._processInputParams(input);
|
|
4187
|
+
const data = ctx.data;
|
|
4188
|
+
return this._def.type._parse({
|
|
4189
|
+
data,
|
|
4190
|
+
path: ctx.path,
|
|
4191
|
+
parent: ctx
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
unwrap() {
|
|
4195
|
+
return this._def.type;
|
|
4196
|
+
}
|
|
4197
|
+
};
|
|
4198
|
+
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4199
|
+
_parse(input) {
|
|
4200
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4201
|
+
if (ctx.common.async) {
|
|
4202
|
+
const handleAsync = async () => {
|
|
4203
|
+
const inResult = await this._def.in._parseAsync({
|
|
4204
|
+
data: ctx.data,
|
|
4205
|
+
path: ctx.path,
|
|
4206
|
+
parent: ctx
|
|
4207
|
+
});
|
|
4208
|
+
if (inResult.status === "aborted")
|
|
4209
|
+
return INVALID;
|
|
4210
|
+
if (inResult.status === "dirty") {
|
|
4211
|
+
status.dirty();
|
|
4212
|
+
return DIRTY(inResult.value);
|
|
4213
|
+
} else {
|
|
4214
|
+
return this._def.out._parseAsync({
|
|
4215
|
+
data: inResult.value,
|
|
4216
|
+
path: ctx.path,
|
|
4217
|
+
parent: ctx
|
|
4218
|
+
});
|
|
4219
|
+
}
|
|
4220
|
+
};
|
|
4221
|
+
return handleAsync();
|
|
4222
|
+
} else {
|
|
4223
|
+
const inResult = this._def.in._parseSync({
|
|
4224
|
+
data: ctx.data,
|
|
4225
|
+
path: ctx.path,
|
|
4226
|
+
parent: ctx
|
|
4227
|
+
});
|
|
4228
|
+
if (inResult.status === "aborted")
|
|
4229
|
+
return INVALID;
|
|
4230
|
+
if (inResult.status === "dirty") {
|
|
4231
|
+
status.dirty();
|
|
4232
|
+
return {
|
|
4233
|
+
status: "dirty",
|
|
4234
|
+
value: inResult.value
|
|
4235
|
+
};
|
|
4236
|
+
} else {
|
|
4237
|
+
return this._def.out._parseSync({
|
|
4238
|
+
data: inResult.value,
|
|
4239
|
+
path: ctx.path,
|
|
4240
|
+
parent: ctx
|
|
4241
|
+
});
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
static create(a, b) {
|
|
4246
|
+
return new _ZodPipeline({
|
|
4247
|
+
in: a,
|
|
4248
|
+
out: b,
|
|
4249
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4250
|
+
});
|
|
4251
|
+
}
|
|
4252
|
+
};
|
|
4253
|
+
var ZodReadonly = class extends ZodType {
|
|
4254
|
+
_parse(input) {
|
|
4255
|
+
const result = this._def.innerType._parse(input);
|
|
4256
|
+
const freeze = (data) => {
|
|
4257
|
+
if (isValid(data)) {
|
|
4258
|
+
data.value = Object.freeze(data.value);
|
|
4259
|
+
}
|
|
4260
|
+
return data;
|
|
4261
|
+
};
|
|
4262
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
4263
|
+
}
|
|
4264
|
+
unwrap() {
|
|
4265
|
+
return this._def.innerType;
|
|
4266
|
+
}
|
|
4267
|
+
};
|
|
4268
|
+
ZodReadonly.create = (type, params) => {
|
|
4269
|
+
return new ZodReadonly({
|
|
4270
|
+
innerType: type,
|
|
4271
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
4272
|
+
...processCreateParams(params)
|
|
4273
|
+
});
|
|
4274
|
+
};
|
|
4275
|
+
function cleanParams(params, data) {
|
|
4276
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
4277
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4278
|
+
return p2;
|
|
4279
|
+
}
|
|
4280
|
+
function custom(check, _params = {}, fatal) {
|
|
4281
|
+
if (check)
|
|
4282
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
4283
|
+
const r = check(data);
|
|
4284
|
+
if (r instanceof Promise) {
|
|
4285
|
+
return r.then((r2) => {
|
|
4286
|
+
if (!r2) {
|
|
4287
|
+
const params = cleanParams(_params, data);
|
|
4288
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4289
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4290
|
+
}
|
|
4291
|
+
});
|
|
4292
|
+
}
|
|
4293
|
+
if (!r) {
|
|
4294
|
+
const params = cleanParams(_params, data);
|
|
4295
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4296
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4297
|
+
}
|
|
4298
|
+
return;
|
|
4299
|
+
});
|
|
4300
|
+
return ZodAny.create();
|
|
4301
|
+
}
|
|
4302
|
+
var late = {
|
|
4303
|
+
object: ZodObject.lazycreate
|
|
4304
|
+
};
|
|
4305
|
+
var ZodFirstPartyTypeKind;
|
|
4306
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
4307
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4308
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4309
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4310
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4311
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4312
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4313
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4314
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4315
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4316
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4317
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4318
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4319
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4320
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4321
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4322
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4323
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4324
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4325
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4326
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4327
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4328
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4329
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4330
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4331
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4332
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4333
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4334
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4335
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4336
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4337
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4338
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4339
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4340
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4341
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4342
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4343
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4344
|
+
var instanceOfType = (cls, params = {
|
|
4345
|
+
message: `Input not instance of ${cls.name}`
|
|
4346
|
+
}) => custom((data) => data instanceof cls, params);
|
|
4347
|
+
var stringType = ZodString.create;
|
|
4348
|
+
var numberType = ZodNumber.create;
|
|
4349
|
+
var nanType = ZodNaN.create;
|
|
4350
|
+
var bigIntType = ZodBigInt.create;
|
|
4351
|
+
var booleanType = ZodBoolean.create;
|
|
4352
|
+
var dateType = ZodDate.create;
|
|
4353
|
+
var symbolType = ZodSymbol.create;
|
|
4354
|
+
var undefinedType = ZodUndefined.create;
|
|
4355
|
+
var nullType = ZodNull.create;
|
|
4356
|
+
var anyType = ZodAny.create;
|
|
4357
|
+
var unknownType = ZodUnknown.create;
|
|
4358
|
+
var neverType = ZodNever.create;
|
|
4359
|
+
var voidType = ZodVoid.create;
|
|
4360
|
+
var arrayType = ZodArray.create;
|
|
4361
|
+
var objectType = ZodObject.create;
|
|
4362
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4363
|
+
var unionType = ZodUnion.create;
|
|
4364
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4365
|
+
var intersectionType = ZodIntersection.create;
|
|
4366
|
+
var tupleType = ZodTuple.create;
|
|
4367
|
+
var recordType = ZodRecord.create;
|
|
4368
|
+
var mapType = ZodMap.create;
|
|
4369
|
+
var setType = ZodSet.create;
|
|
4370
|
+
var functionType = ZodFunction.create;
|
|
4371
|
+
var lazyType = ZodLazy.create;
|
|
4372
|
+
var literalType = ZodLiteral.create;
|
|
4373
|
+
var enumType = ZodEnum.create;
|
|
4374
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4375
|
+
var promiseType = ZodPromise.create;
|
|
4376
|
+
var effectsType = ZodEffects.create;
|
|
4377
|
+
var optionalType = ZodOptional.create;
|
|
4378
|
+
var nullableType = ZodNullable.create;
|
|
4379
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4380
|
+
var pipelineType = ZodPipeline.create;
|
|
4381
|
+
var ostring = () => stringType().optional();
|
|
4382
|
+
var onumber = () => numberType().optional();
|
|
4383
|
+
var oboolean = () => booleanType().optional();
|
|
4384
|
+
var coerce = {
|
|
4385
|
+
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4386
|
+
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
4387
|
+
boolean: ((arg) => ZodBoolean.create({
|
|
4388
|
+
...arg,
|
|
4389
|
+
coerce: true
|
|
4390
|
+
})),
|
|
4391
|
+
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4392
|
+
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4393
|
+
};
|
|
4394
|
+
var NEVER = INVALID;
|
|
4395
|
+
|
|
4396
|
+
// ../../sdk-contracts/dist/schemas.js
|
|
4397
|
+
var NO_CSS_BREAKOUT_PATTERN = /^[^{}]*$/;
|
|
4398
|
+
var AnchorIdZ = external_exports.object({
|
|
4399
|
+
selector: external_exports.string().regex(NO_CSS_BREAKOUT_PATTERN, {
|
|
4400
|
+
message: 'selector must not contain "{" or "}" \u2014 not valid CSS selector syntax, and content:hideBySelector injects this value directly into a <style> element where these characters would break out of the generated rule.'
|
|
4401
|
+
}).describe("CSS selector for the target element"),
|
|
4402
|
+
route: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).superRefine((value, ctx) => {
|
|
4403
|
+
for (const route of Array.isArray(value) ? value : [value]) {
|
|
4404
|
+
let canonical;
|
|
4405
|
+
try {
|
|
4406
|
+
canonical = normalizeRoute(route);
|
|
4407
|
+
} catch (err) {
|
|
4408
|
+
ctx.addIssue({
|
|
4409
|
+
code: external_exports.ZodIssueCode.custom,
|
|
4410
|
+
message: `route must be an absolute path starting with "/" (got ${JSON.stringify(route)}): ${err instanceof Error ? err.message : String(err)}`
|
|
4411
|
+
});
|
|
4412
|
+
continue;
|
|
4413
|
+
}
|
|
4414
|
+
if (canonical !== route) {
|
|
4415
|
+
ctx.addIssue({
|
|
4416
|
+
code: external_exports.ZodIssueCode.custom,
|
|
4417
|
+
message: `route ${JSON.stringify(route)} is not canonical \u2014 use ${JSON.stringify(canonical)} (this must match what the backend's RouteCanonicalityCheck accepts)`
|
|
4418
|
+
});
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
}).describe("URL path(s) where this element exists")
|
|
4422
|
+
}).strict().describe("DOM element target. selector = CSS selector, route = URL path(s) where the element exists.");
|
|
4423
|
+
var AuthoringFieldsZ = {
|
|
4424
|
+
id: external_exports.string().optional().describe('Stable action identifier (e.g. "act_3db6a14d2ab0").'),
|
|
4425
|
+
title: external_exports.string().max(200).optional().describe("Authoring-only: short label shown on the action plan dashboard. Stripped before serving to the runtime SDK."),
|
|
4426
|
+
description: external_exports.string().max(1e3).optional().describe("Authoring-only: one-sentence explanation of what this action does and why. Stripped before serving to the runtime SDK."),
|
|
4427
|
+
validation: external_exports.array(external_exports.string().max(500)).max(10).optional().describe("Authoring-only: ordered steps a reviewer can follow to trigger this action and visually confirm it works. Each entry is one step. Stripped before serving to the runtime SDK.")
|
|
4428
|
+
};
|
|
4429
|
+
var COUNTABLE_EVENTS = [
|
|
4430
|
+
// User interactions (from PostHog autocapture normalization)
|
|
4431
|
+
"ui.click",
|
|
4432
|
+
"ui.scroll",
|
|
4433
|
+
"ui.input",
|
|
4434
|
+
"ui.change",
|
|
4435
|
+
"ui.submit",
|
|
4436
|
+
// Behavioral detectors (from event-processor)
|
|
4437
|
+
"ui.hover",
|
|
4438
|
+
"ui.idle",
|
|
4439
|
+
"ui.scroll_thrash",
|
|
4440
|
+
"ui.focus_bounce",
|
|
4441
|
+
"ui.hesitate",
|
|
4442
|
+
"ui.rage_click",
|
|
4443
|
+
// Navigation
|
|
4444
|
+
"nav.page_view",
|
|
4445
|
+
"nav.page_leave"
|
|
4446
|
+
];
|
|
4447
|
+
var CountableEventZ = external_exports.enum(COUNTABLE_EVENTS).describe("Event name to count. ui.* = user interactions and behavioral detectors (hesitate, rage_click, scroll_thrash, focus_bounce, idle, hover); nav.* = page navigation.");
|
|
4448
|
+
var SESSION_METRIC_KEYS = ["time_on_page", "page_views", "scroll_depth"];
|
|
4449
|
+
var SessionMetricKeyZ = external_exports.enum(SESSION_METRIC_KEYS).describe("Session metric key. time_on_page = seconds on current page, page_views = pages visited this session, scroll_depth = 0-100 percentage.");
|
|
4450
|
+
var PageUrlConditionZ = external_exports.object({
|
|
4451
|
+
type: external_exports.literal("page_url"),
|
|
4452
|
+
url: external_exports.string().describe('URL path to match (e.g. "/pricing", "/dashboard")')
|
|
4453
|
+
}).describe('Fires when the current page URL matches. Use for page-specific actions. Example: {"type": "page_url", "url": "/pricing"}');
|
|
4454
|
+
var RouteConditionZ = external_exports.object({
|
|
4455
|
+
type: external_exports.literal("route"),
|
|
4456
|
+
routeId: external_exports.string().describe("Named route ID from the route filter")
|
|
4457
|
+
}).describe("Fires when the current route matches a named route ID.");
|
|
4458
|
+
var AnchorVisibleConditionZ = external_exports.object({
|
|
4459
|
+
type: external_exports.literal("anchor_visible"),
|
|
4460
|
+
anchorId: external_exports.string().describe("CSS selector of the anchor element"),
|
|
4461
|
+
state: external_exports.enum(["visible", "present", "absent"]).describe('"visible" = in viewport, "present" = in DOM, "absent" = not in DOM')
|
|
4462
|
+
}).describe(`Fires based on a DOM element's visibility state. Example: {"type": "anchor_visible", "anchorId": "#cta-button", "state": "visible"}`);
|
|
4463
|
+
var EventOccurredConditionZ = external_exports.object({
|
|
4464
|
+
type: external_exports.literal("event_occurred"),
|
|
4465
|
+
eventName: external_exports.string().describe('Event name (e.g. "ui.click", "$pageview")'),
|
|
4466
|
+
withinMs: external_exports.number().optional().describe("Time window in ms. Omit = any time this session.")
|
|
4467
|
+
}).describe('Fires when a specific event has occurred during this session. Example: {"type": "event_occurred", "eventName": "ui.click", "withinMs": 5000}');
|
|
4468
|
+
var StateEqualsConditionZ = external_exports.object({
|
|
4469
|
+
type: external_exports.literal("state_equals"),
|
|
4470
|
+
key: external_exports.string().describe("Key in the SDK persistent state store (localStorage). Only valid for keys the host app explicitly sets via syntro.state.set()."),
|
|
4471
|
+
value: external_exports.unknown().describe("Expected value to match against")
|
|
4472
|
+
}).describe("Checks the SDK persistent state store (localStorage). ONLY for host-app state set via syntro.state.set() \u2014 NOT for user attributes like region, device, or UTM params (those are handled by segment targeting). Do NOT use this for targeting. If you do not know the valid state keys, do not use this condition type.");
|
|
4473
|
+
var ViewportConditionZ = external_exports.object({
|
|
4474
|
+
type: external_exports.literal("viewport"),
|
|
4475
|
+
minWidth: external_exports.number().optional().describe("Minimum viewport width in pixels"),
|
|
4476
|
+
maxWidth: external_exports.number().optional().describe("Maximum viewport width in pixels"),
|
|
4477
|
+
minHeight: external_exports.number().optional().describe("Minimum viewport height in pixels"),
|
|
4478
|
+
maxHeight: external_exports.number().optional().describe("Maximum viewport height in pixels")
|
|
4479
|
+
}).describe('Fires based on viewport (screen) size. Use for responsive behavior. Example: {"type": "viewport", "minWidth": 768} \u2014 fires on tablet and larger.');
|
|
4480
|
+
var SessionMetricConditionZ = external_exports.object({
|
|
4481
|
+
type: external_exports.literal("session_metric"),
|
|
4482
|
+
key: SessionMetricKeyZ,
|
|
4483
|
+
operator: external_exports.enum(["gte", "lte", "eq", "gt", "lt"]),
|
|
4484
|
+
threshold: external_exports.number().describe("Numeric threshold to compare against")
|
|
4485
|
+
}).describe('Fires when a session metric crosses a threshold. Valid keys: "time_on_page" (seconds), "page_views" (count), "scroll_depth" (0-100). Example: {"type": "session_metric", "key": "time_on_page", "operator": "gte", "threshold": 30}');
|
|
4486
|
+
var DismissedConditionZ = external_exports.object({
|
|
4487
|
+
type: external_exports.literal("dismissed"),
|
|
4488
|
+
key: external_exports.string().describe("Dismissal key (usually a tile or action ID)"),
|
|
4489
|
+
inverted: external_exports.boolean().optional().describe("When true, fires if NOT dismissed (default behavior)")
|
|
4490
|
+
}).describe("Checks if an item has been dismissed by the user. Use with inverted: true to show only if not dismissed.");
|
|
4491
|
+
var CooldownActiveConditionZ = external_exports.object({
|
|
4492
|
+
type: external_exports.literal("cooldown_active"),
|
|
4493
|
+
key: external_exports.string().describe("Cooldown key"),
|
|
4494
|
+
inverted: external_exports.boolean().optional().describe("When true, fires if cooldown is NOT active")
|
|
4495
|
+
}).describe("Checks if a cooldown timer is currently active. Use to prevent showing the same intervention too frequently.");
|
|
4496
|
+
var FrequencyLimitConditionZ = external_exports.object({
|
|
4497
|
+
type: external_exports.literal("frequency_limit"),
|
|
4498
|
+
key: external_exports.string().describe("Frequency counter key"),
|
|
4499
|
+
limit: external_exports.number().describe("Maximum allowed count"),
|
|
4500
|
+
inverted: external_exports.boolean().optional().describe("When true, fires if limit NOT reached")
|
|
4501
|
+
}).describe("Checks if a frequency limit has been reached. Use to cap how many times an action fires per session.");
|
|
4502
|
+
var MatchOpZ = external_exports.object({
|
|
4503
|
+
equals: external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()]).optional(),
|
|
4504
|
+
contains: external_exports.string().optional()
|
|
4505
|
+
}).refine((operator) => Number(operator.equals !== void 0) + Number(operator.contains !== void 0) === 1, {
|
|
4506
|
+
message: "Exactly one of equals or contains must be specified."
|
|
4507
|
+
}).describe("Match operator for counter filters. Exactly one of equals or contains must be specified.");
|
|
4508
|
+
var CounterDefZ = external_exports.object({
|
|
4509
|
+
events: external_exports.array(CountableEventZ).min(1).describe("Event names to count. Use values from the countable events enum."),
|
|
4510
|
+
match: external_exports.record(external_exports.string(), MatchOpZ).optional().describe("Property filters. Keys are event prop names or element-chain fields (tag_name, $el_text, attr__*). All entries AND together.")
|
|
4511
|
+
}).describe("Defines what events to count. Registered as an accumulator predicate at config-load time.");
|
|
4512
|
+
var EventCountConditionZ = external_exports.object({
|
|
4513
|
+
type: external_exports.literal("event_count"),
|
|
4514
|
+
key: external_exports.string().describe("Unique key for this counter (used for accumulator registration)"),
|
|
4515
|
+
operator: external_exports.enum(["gte", "lte", "eq", "gt", "lt"]),
|
|
4516
|
+
count: external_exports.number().int().min(0).describe("Target count threshold"),
|
|
4517
|
+
withinMs: external_exports.number().positive().optional().describe("Time window in ms. Omit = count across entire session."),
|
|
4518
|
+
counter: CounterDefZ.optional().describe("Inline counter definition. Defines what events to count.")
|
|
4519
|
+
}).describe('Fires when accumulated event count crosses a threshold. Most powerful trigger type. Example: {"type": "event_count", "key": "pricing-clicks", "operator": "gte", "count": 3, "counter": {"events": ["ui.click"], "match": {"attr__data-cta": {"contains": "pricing"}}}}');
|
|
4520
|
+
var ConditionZ = external_exports.discriminatedUnion("type", [
|
|
4521
|
+
PageUrlConditionZ,
|
|
4522
|
+
RouteConditionZ,
|
|
4523
|
+
AnchorVisibleConditionZ,
|
|
4524
|
+
EventOccurredConditionZ,
|
|
4525
|
+
StateEqualsConditionZ,
|
|
4526
|
+
ViewportConditionZ,
|
|
4527
|
+
SessionMetricConditionZ,
|
|
4528
|
+
DismissedConditionZ,
|
|
4529
|
+
CooldownActiveConditionZ,
|
|
4530
|
+
FrequencyLimitConditionZ,
|
|
4531
|
+
EventCountConditionZ
|
|
4532
|
+
]);
|
|
4533
|
+
var RuleZ = external_exports.object({
|
|
4534
|
+
conditions: external_exports.array(ConditionZ).describe("Array of conditions \u2014 ALL must match (AND logic) for this rule to fire."),
|
|
4535
|
+
value: external_exports.unknown().describe("Value returned when all conditions match. For triggerWhen: true = fire the action.")
|
|
4536
|
+
}).describe("A single rule. ALL conditions must match (AND logic). Rules in a strategy are evaluated top-to-bottom \u2014 first rule where all conditions match wins and returns its value.");
|
|
4537
|
+
var RuleStrategyZ = external_exports.object({
|
|
4538
|
+
type: external_exports.literal("rules"),
|
|
4539
|
+
rules: external_exports.array(RuleZ).describe("Ordered list of rules. Evaluated top-to-bottom \u2014 first match wins."),
|
|
4540
|
+
default: external_exports.unknown().describe("Fallback value when no rule matches. For triggerWhen: false = do not fire by default.")
|
|
4541
|
+
}).describe("Rule-based strategy. Evaluates rules top-to-bottom. First rule where ALL conditions match returns its value. If no rule matches, returns default. For triggerWhen: set value=true on matching rules, default=false.");
|
|
4542
|
+
var ScoreStrategyZ = external_exports.object({
|
|
4543
|
+
type: external_exports.literal("score"),
|
|
4544
|
+
field: external_exports.string(),
|
|
4545
|
+
threshold: external_exports.number(),
|
|
4546
|
+
above: external_exports.unknown(),
|
|
4547
|
+
below: external_exports.unknown()
|
|
4548
|
+
}).describe("Score-based strategy. Compares a field value against a threshold.");
|
|
4549
|
+
var ModelStrategyZ = external_exports.object({
|
|
4550
|
+
type: external_exports.literal("model"),
|
|
4551
|
+
modelId: external_exports.string(),
|
|
4552
|
+
inputs: external_exports.array(external_exports.string()),
|
|
4553
|
+
outputMapping: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
4554
|
+
default: external_exports.unknown()
|
|
4555
|
+
}).describe("ML model strategy. Sends inputs to a model and maps outputs.");
|
|
4556
|
+
var ExternalStrategyZ = external_exports.object({
|
|
4557
|
+
type: external_exports.literal("external"),
|
|
4558
|
+
endpoint: external_exports.string(),
|
|
4559
|
+
method: external_exports.enum(["GET", "POST"]).optional(),
|
|
4560
|
+
default: external_exports.unknown(),
|
|
4561
|
+
timeoutMs: external_exports.number().optional()
|
|
4562
|
+
}).describe("External API strategy. Calls an endpoint to determine the value.");
|
|
4563
|
+
var DecisionStrategyZ = external_exports.discriminatedUnion("type", [
|
|
4564
|
+
RuleStrategyZ,
|
|
4565
|
+
ScoreStrategyZ,
|
|
4566
|
+
ModelStrategyZ,
|
|
4567
|
+
ExternalStrategyZ
|
|
4568
|
+
]);
|
|
4569
|
+
var TriggerWhenZ = DecisionStrategyZ.nullable().optional();
|
|
4570
|
+
var EventScopeZ = external_exports.object({
|
|
4571
|
+
events: external_exports.array(external_exports.string()),
|
|
4572
|
+
urlContains: external_exports.string().optional(),
|
|
4573
|
+
props: external_exports.record(external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean()])).optional()
|
|
4574
|
+
});
|
|
4575
|
+
var NotifyZ = external_exports.object({
|
|
4576
|
+
title: external_exports.string().optional().describe("Notification title"),
|
|
4577
|
+
body: external_exports.string().optional().describe("Notification body text"),
|
|
4578
|
+
icon: external_exports.string().optional().describe("Notification icon (emoji or URL)")
|
|
4579
|
+
}).describe("Optional toast notification shown when this action triggers.").nullable().optional();
|
|
404
4580
|
|
|
405
4581
|
// src/schema.ts
|
|
406
|
-
|
|
407
|
-
var configSchema = z2.object({
|
|
4582
|
+
var configSchema = external_exports.object({
|
|
408
4583
|
/** Text replacements */
|
|
409
|
-
textReplacements:
|
|
410
|
-
|
|
4584
|
+
textReplacements: external_exports.array(
|
|
4585
|
+
external_exports.object({
|
|
411
4586
|
anchorId: AnchorIdZ.describe(
|
|
412
4587
|
"Route and CSS selector identifying the element whose text content to replace."
|
|
413
4588
|
),
|
|
414
|
-
summary:
|
|
4589
|
+
summary: external_exports.string().describe(
|
|
415
4590
|
"Human-readable description of this change, used for logging and debugging."
|
|
416
4591
|
),
|
|
417
|
-
text:
|
|
4592
|
+
text: external_exports.string().describe("New text content to set on the element (replaces existing text).")
|
|
418
4593
|
}).describe("A single text replacement: replaces the text content of a matched element.")
|
|
419
4594
|
).optional().describe(
|
|
420
4595
|
"Replaces the visible text of DOM elements. Use for copy changes, headline personalization, or CTA label swaps."
|
|
421
4596
|
),
|
|
422
4597
|
/** Attribute modifications */
|
|
423
|
-
attributeChanges:
|
|
424
|
-
|
|
4598
|
+
attributeChanges: external_exports.array(
|
|
4599
|
+
external_exports.object({
|
|
425
4600
|
anchorId: AnchorIdZ.describe(
|
|
426
4601
|
"Route and CSS selector identifying the element whose attribute to set."
|
|
427
4602
|
),
|
|
428
|
-
summary:
|
|
4603
|
+
summary: external_exports.string().describe(
|
|
429
4604
|
"Human-readable description of this change, used for logging and debugging."
|
|
430
4605
|
),
|
|
431
|
-
attr:
|
|
4606
|
+
attr: external_exports.string().min(
|
|
432
4607
|
1,
|
|
433
4608
|
'Attribute name must not be empty \u2014 setAttribute("", ...) throws InvalidCharacterError in all browsers.'
|
|
434
4609
|
).describe(
|
|
435
4610
|
'HTML attribute name to set (e.g. "href", "src", "data-experiment"). Event handler attributes are blocked.'
|
|
436
4611
|
),
|
|
437
|
-
value:
|
|
4612
|
+
value: external_exports.string().describe("New attribute value to apply.")
|
|
438
4613
|
}).describe("A single attribute change: sets one HTML attribute on a matched element.")
|
|
439
4614
|
).optional().describe(
|
|
440
4615
|
"Sets HTML attributes on DOM elements. Use for href swaps, src changes, or adding data-* experiment markers. Event handlers (onclick, onerror, etc.) are blocked."
|
|
441
4616
|
),
|
|
442
4617
|
/** Style modifications */
|
|
443
|
-
styleChanges:
|
|
444
|
-
|
|
4618
|
+
styleChanges: external_exports.array(
|
|
4619
|
+
external_exports.object({
|
|
445
4620
|
anchorId: AnchorIdZ.describe(
|
|
446
4621
|
"Route and CSS selector identifying the element to restyle."
|
|
447
4622
|
),
|
|
448
|
-
summary:
|
|
4623
|
+
summary: external_exports.string().describe(
|
|
449
4624
|
"Human-readable description of this change, used for logging and debugging."
|
|
450
4625
|
),
|
|
451
|
-
styles:
|
|
4626
|
+
styles: external_exports.record(
|
|
452
4627
|
// CSS property names must be kebab-case — `element.style.setProperty()`
|
|
453
4628
|
// silently drops camelCase keys at runtime. (BUG-1779388834)
|
|
454
|
-
|
|
4629
|
+
external_exports.string().regex(
|
|
455
4630
|
/^(?:-?[a-z][a-z0-9-]*|--[a-zA-Z0-9_-]+)$/,
|
|
456
4631
|
"Invalid CSS property name. Use kebab-case (e.g. 'font-size', not 'fontSize')."
|
|
457
4632
|
),
|
|
458
|
-
|
|
4633
|
+
external_exports.string()
|
|
459
4634
|
).describe(
|
|
460
4635
|
'Map of CSS property \u2192 value pairs applied as inline styles (e.g. {"background-color": "#1e40af", "padding": "2rem"}).'
|
|
461
4636
|
)
|
|
@@ -464,26 +4639,26 @@ var configSchema = z2.object({
|
|
|
464
4639
|
"Sets inline CSS styles on DOM elements. Use for color, spacing, or visibility changes without modifying the stylesheet."
|
|
465
4640
|
),
|
|
466
4641
|
/** HTML insertions */
|
|
467
|
-
htmlInsertions:
|
|
468
|
-
|
|
4642
|
+
htmlInsertions: external_exports.array(
|
|
4643
|
+
external_exports.object({
|
|
469
4644
|
anchorId: AnchorIdZ.describe(
|
|
470
4645
|
"Route and CSS selector identifying the reference element for the insertion."
|
|
471
4646
|
),
|
|
472
|
-
summary:
|
|
4647
|
+
summary: external_exports.string().describe(
|
|
473
4648
|
"Human-readable description of this change, used for logging and debugging."
|
|
474
4649
|
),
|
|
475
|
-
html:
|
|
4650
|
+
html: external_exports.string().min(
|
|
476
4651
|
1,
|
|
477
4652
|
'HTML string must not be empty \u2014 an empty html with position "replace" silently swaps the anchor element for an empty div.'
|
|
478
4653
|
).describe(
|
|
479
4654
|
"HTML string to insert. The SDK sanitizes it before injection \u2014 no script tags or event handlers (onclick, onerror, etc.). NEVER embed JavaScript \u2014 use deepLink for canvas navigation instead."
|
|
480
4655
|
),
|
|
481
|
-
position:
|
|
4656
|
+
position: external_exports.enum(["before", "after", "prepend", "append", "replace"]).describe(
|
|
482
4657
|
'"before"/"after" inserts adjacent to the element; "prepend"/"append" inserts inside at the start/end; "replace" swaps the entire element.'
|
|
483
4658
|
),
|
|
484
|
-
deepLink:
|
|
485
|
-
tileId:
|
|
486
|
-
itemId:
|
|
4659
|
+
deepLink: external_exports.object({
|
|
4660
|
+
tileId: external_exports.string().describe("ID of the canvas tile to open when the inserted element is clicked."),
|
|
4661
|
+
itemId: external_exports.string().optional().describe(
|
|
487
4662
|
"Optional specific item within the tile (e.g. a FAQ question ID) to scroll to after opening."
|
|
488
4663
|
)
|
|
489
4664
|
}).optional().describe(
|
|
@@ -496,15 +4671,15 @@ var configSchema = z2.object({
|
|
|
496
4671
|
"Inserts sanitized HTML fragments relative to DOM elements. Use for adding badges, banners, or supplementary content. Do NOT embed JavaScript \u2014 use deepLink for canvas navigation."
|
|
497
4672
|
),
|
|
498
4673
|
/** Class additions */
|
|
499
|
-
classAdditions:
|
|
500
|
-
|
|
4674
|
+
classAdditions: external_exports.array(
|
|
4675
|
+
external_exports.object({
|
|
501
4676
|
anchorId: AnchorIdZ.describe(
|
|
502
4677
|
"Route and CSS selector identifying the element to add the class to."
|
|
503
4678
|
),
|
|
504
|
-
summary:
|
|
4679
|
+
summary: external_exports.string().describe(
|
|
505
4680
|
"Human-readable description of this change, used for logging and debugging."
|
|
506
4681
|
),
|
|
507
|
-
className:
|
|
4682
|
+
className: external_exports.string().min(
|
|
508
4683
|
1,
|
|
509
4684
|
'Class name must not be empty \u2014 classList.add("") throws DOMException in all browsers.'
|
|
510
4685
|
).describe(
|
|
@@ -515,15 +4690,15 @@ var configSchema = z2.object({
|
|
|
515
4690
|
"Adds CSS classes to DOM elements. Use to toggle visibility, apply highlight styles, or trigger CSS animations already defined in the host stylesheet."
|
|
516
4691
|
),
|
|
517
4692
|
/** Class removals */
|
|
518
|
-
classRemovals:
|
|
519
|
-
|
|
4693
|
+
classRemovals: external_exports.array(
|
|
4694
|
+
external_exports.object({
|
|
520
4695
|
anchorId: AnchorIdZ.describe(
|
|
521
4696
|
"Route and CSS selector identifying the element to remove the class from."
|
|
522
4697
|
),
|
|
523
|
-
summary:
|
|
4698
|
+
summary: external_exports.string().describe(
|
|
524
4699
|
"Human-readable description of this change, used for logging and debugging."
|
|
525
4700
|
),
|
|
526
|
-
className:
|
|
4701
|
+
className: external_exports.string().min(
|
|
527
4702
|
1,
|
|
528
4703
|
'Class name must not be empty \u2014 classList.remove("") throws DOMException in all browsers.'
|
|
529
4704
|
).describe(
|