@temelyos/zod 1.0.0 → 1.0.1

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.
Files changed (50) hide show
  1. package/dist/bounded-number.d.ts +8 -0
  2. package/dist/bounded-number.js +36 -0
  3. package/dist/codec-parts.d.ts +8 -0
  4. package/dist/codec-parts.js +21 -0
  5. package/dist/currency-code.d.ts +5 -0
  6. package/dist/currency-code.js +11 -0
  7. package/dist/field-paths.d.ts +54 -0
  8. package/dist/field-paths.js +67 -0
  9. package/dist/field-settings.d.ts +119 -0
  10. package/dist/field-settings.js +219 -0
  11. package/dist/format-template.d.ts +3 -0
  12. package/dist/format-template.js +8 -0
  13. package/dist/hex-string-24.d.ts +45 -0
  14. package/dist/hex-string-24.js +32 -0
  15. package/dist/index.d.ts +25 -501
  16. package/dist/index.js +23 -992
  17. package/dist/iso-date.d.ts +25 -0
  18. package/dist/iso-date.js +108 -0
  19. package/dist/json-text.d.ts +3 -0
  20. package/dist/json-text.js +6 -0
  21. package/dist/labelled.d.ts +17 -0
  22. package/dist/labelled.js +22 -0
  23. package/dist/language-code.d.ts +10 -0
  24. package/dist/language-code.js +15 -0
  25. package/dist/localized-string.d.ts +75 -0
  26. package/dist/localized-string.js +80 -0
  27. package/dist/merge.d.ts +14 -0
  28. package/dist/merge.js +26 -0
  29. package/dist/nullish.d.ts +2 -0
  30. package/dist/nullish.js +7 -0
  31. package/dist/positional-paths.d.ts +22 -0
  32. package/dist/positional-paths.js +99 -0
  33. package/dist/reg-exp-pattern.d.ts +2 -0
  34. package/dist/reg-exp-pattern.js +5 -0
  35. package/dist/slug.d.ts +5 -0
  36. package/dist/slug.js +15 -0
  37. package/dist/strip-empty-fields.d.ts +2 -0
  38. package/dist/strip-empty-fields.js +46 -0
  39. package/dist/strip-to-schema.d.ts +7 -0
  40. package/dist/strip-to-schema.js +35 -0
  41. package/dist/time-zone.d.ts +15 -0
  42. package/dist/time-zone.js +20 -0
  43. package/dist/to-json-schema.d.ts +40 -0
  44. package/dist/to-json-schema.js +44 -0
  45. package/dist/types.d.ts +4 -0
  46. package/dist/utilities.d.ts +39 -0
  47. package/dist/utilities.js +116 -0
  48. package/dist/whole-number.d.ts +2 -0
  49. package/dist/whole-number.js +11 -0
  50. package/package.json +5 -2
package/dist/index.d.ts CHANGED
@@ -1,501 +1,25 @@
1
- import { ZodArray, ZodCatch, ZodCodec, ZodDate, ZodDefault, ZodEnum, ZodFile, ZodIntersection, ZodLazy, ZodNonOptional, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodPipe, ZodPromise, ZodRawShape, ZodRecord, ZodString, ZodSuccess, ZodTransform, ZodType, ZodUnion, ZodUnknown, core, z } from "zod";
2
- export interface NumberBounds {
3
- integer?: boolean;
4
- max?: number;
5
- min?: number;
6
- }
7
- /** A number, optionally whole and bounded; a refusal names its bounds as the message's `{0}` and `{1}`. */
8
- export declare function boundedNumber({ integer, max, min }: NumberBounds): z.ZodNumber;
9
- /** The schemas {@link withCodecParts} named for a codec; undefined for any other schema. */
10
- export declare function codecParts(schema: ZodType): readonly ZodType[] | undefined;
11
- /**
12
- * A codec that builds its schemas at run time (from a model's fields, or a result's columns),
13
- * with those schemas named, so a reader can check what it encodes and decodes its values by.
14
- */
15
- export declare function withCodecParts<T extends ZodType>(codec: T, schemas: readonly ZodType[]): T;
16
- /** A lower-case ISO 4217 code: `usd`, never `USD` or `$`. */
17
- export declare const CurrencyCodePattern: RegExp;
18
- /** A field that takes a lower-case ISO 4217 code. `missing` is the caller's, for a field nobody filled in. */
19
- export declare function currencyCode(missing: string, invalid?: string): z.ZodString;
20
- export interface GetZodFieldPathsOptions {
21
- /**
22
- * When `true`, arrays are treated as terminal leaves and NOT descended (no
23
- * `items.token`-style paths are emitted). Defaults to `false` — arrays are
24
- * descended via their element type, matching how `getPathValues` fans out
25
- * across arrays at runtime.
26
- *
27
- * Callers whose downstream path-consumer cannot fan out across arrays — e.g.
28
- * `getSensitivePaths`, whose redact step (`splitSensitive`) walks plain objects
29
- * only and would silently skip an array-borne path — should set this to `true`.
30
- */
31
- skipArrays?: boolean;
32
- }
33
- export interface ZodFieldPath {
34
- /** The field's schema as its object declares it, wrappers kept: what says whether it may be absent. */
35
- declared: ZodType;
36
- /** Dotted path to the field within the schema, e.g. `auth.apiKey`. */
37
- path: string;
38
- /** The field's schema with wrapper types (see `unwrapField`) removed. A codec is left whole: ask `isDateSchema` what it holds. */
39
- schema: ZodType;
40
- }
41
- /**
42
- * Enumerates the dotted paths of every field reachable by descending `ZodObject`
43
- * shapes and the branches of `ZodUnion` / `ZodDiscriminatedUnion` (Zod v4 reports
44
- * both as `def.type === 'union'`). A field declared in more than one union branch
45
- * is reported once per branch — callers that need uniqueness should dedupe by
46
- * `path`.
47
- *
48
- * Wrapper types (optional/nullable/default/catch/nonoptional/prefault/readonly/lazy) are always unwrapped.
49
- * Arrays are descended via their element type by default (emitting non-indexed
50
- * paths like `items.token`, the way `getPathValues` fans out at runtime); pass
51
- * `{ skipArrays: true }` to stop at arrays instead. Records and other leaves are
52
- * never descended. Each field is reported with its unwrapped `schema`, which lets
53
- * callers read per-field metadata (e.g. `sensitive()` markers) without re-walking
54
- * wrappers, and as its object `declared` it, wrappers kept, which says whether it
55
- * may be absent (`isOptionalOutput`).
56
- *
57
- * The schema-space analogue of `getPathValues` (which extracts values at a path
58
- * from a runtime object).
59
- */
60
- export declare function getZodFieldPaths(schema: ZodType, options?: GetZodFieldPathsOptions): ZodFieldPath[];
61
- /**
62
- * Unwraps optional/nullable/default/catch/nonoptional/prefault/readonly/lazy wrappers. Unlike `getInnerType`,
63
- * arrays are unwrapped to their element type only when `shouldSkipArrays` is
64
- * false; when true it stops at arrays, leaving them terminal.
65
- *
66
- * A wrapper chain that closes on itself (`const Self = z.lazy(() => Self.array())`
67
- * unwraps lazy → array → lazy → …) stops at the node that repeats — it has no
68
- * inner type left to reach. The guard has to live here: `collectFieldPaths`'s own
69
- * one is only consulted after unwrapping has already returned. `seen` is per
70
- * top-level call, so it never suppresses an unrelated sibling.
71
- */
72
- export declare function unwrapField(schema: ZodType, shouldSkipArrays: boolean, seen?: Set<ZodType>): ZodType;
73
- export type Mutable<T> = { -readonly [P in keyof T]: T[P]; };
74
- export type UnwrapZodType<T> = T extends ZodOptional<infer U> ? UnwrapZodType<U> : T extends ZodNullable<infer U> ? UnwrapZodType<U> : T extends ZodDefault<infer U> ? UnwrapZodType<U> : T extends ZodCatch<infer U> ? UnwrapZodType<U> : T extends ZodLazy<infer U> ? UnwrapZodType<U> : T extends ZodArray<infer U> ? ZodArray<UnwrapZodType<U>> : T;
75
- export type ZodWrapper = ZodCatch | ZodDefault | ZodLazy | ZodNonOptional | ZodNullable | ZodOptional | ZodPromise | ZodSuccess;
76
- interface BaseFieldSettings<T> {
77
- default?: T;
78
- isOptional?: boolean;
79
- isVisible?: boolean;
80
- label?: string;
81
- }
82
- declare const stringFieldSettingsSchema: ZodObject<{
83
- default: z.ZodOptional<ZodString>;
84
- isOptional: z.ZodOptional<z.ZodBoolean>;
85
- isVisible: z.ZodOptional<z.ZodBoolean>;
86
- label: z.ZodOptional<ZodString>;
87
- maxLength: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
88
- message: ZodString;
89
- value: ZodNumber;
90
- }, core.$strip>]>>;
91
- minLength: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
92
- message: ZodString;
93
- value: ZodNumber;
94
- }, core.$strip>]>>;
95
- regExp: z.ZodOptional<z.ZodUnion<readonly [z.ZodInstanceOf<RegExp>, ZodObject<{
96
- message: ZodString;
97
- value: z.ZodInstanceOf<RegExp>;
98
- }, core.$strip>]>>;
99
- }, core.$strip>;
100
- type StringFieldSettings = z.infer<typeof stringFieldSettingsSchema>;
101
- declare const numberFieldSettingsSchema: ZodObject<{
102
- default: z.ZodOptional<ZodNumber>;
103
- isOptional: z.ZodOptional<z.ZodBoolean>;
104
- isVisible: z.ZodOptional<z.ZodBoolean>;
105
- label: z.ZodOptional<ZodString>;
106
- max: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
107
- message: ZodString;
108
- value: ZodNumber;
109
- }, core.$strip>]>>;
110
- min: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
111
- message: ZodString;
112
- value: ZodNumber;
113
- }, core.$strip>]>>;
114
- }, core.$strip>;
115
- type NumberFieldSettings = z.infer<typeof numberFieldSettingsSchema>;
116
- declare const fileFieldSettingsSchema: ZodObject<{
117
- default: z.ZodOptional<z.ZodInstanceOf<File>>;
118
- isOptional: z.ZodOptional<z.ZodBoolean>;
119
- isVisible: z.ZodOptional<z.ZodBoolean>;
120
- label: z.ZodOptional<ZodString>;
121
- maxBytes: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
122
- message: ZodString;
123
- value: ZodNumber;
124
- }, core.$strip>]>>;
125
- minBytes: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
126
- message: ZodString;
127
- value: ZodNumber;
128
- }, core.$strip>]>>;
129
- }, core.$strip>;
130
- type FileFieldSettings = z.infer<typeof fileFieldSettingsSchema>;
131
- declare const dropdownFieldSettingsSchema: ZodObject<{
132
- default: z.ZodOptional<ZodString>;
133
- isOptional: z.ZodOptional<z.ZodBoolean>;
134
- isVisible: z.ZodOptional<z.ZodBoolean>;
135
- label: z.ZodOptional<ZodString>;
136
- values: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<ZodString>, z.ZodRecord<ZodString, z.ZodUnion<readonly [ZodString, ZodNumber]>>]>>;
137
- }, core.$strip>;
138
- type DropdownFieldSettings = z.infer<typeof dropdownFieldSettingsSchema>;
139
- export declare const AnyFieldSettingsSchema: z.ZodUnion<readonly [ZodObject<{
140
- default: z.ZodOptional<ZodString>;
141
- isOptional: z.ZodOptional<z.ZodBoolean>;
142
- isVisible: z.ZodOptional<z.ZodBoolean>;
143
- label: z.ZodOptional<ZodString>;
144
- maxLength: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
145
- message: ZodString;
146
- value: ZodNumber;
147
- }, core.$strip>]>>;
148
- minLength: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
149
- message: ZodString;
150
- value: ZodNumber;
151
- }, core.$strip>]>>;
152
- regExp: z.ZodOptional<z.ZodUnion<readonly [z.ZodInstanceOf<RegExp>, ZodObject<{
153
- message: ZodString;
154
- value: z.ZodInstanceOf<RegExp>;
155
- }, core.$strip>]>>;
156
- }, core.$strip>, ZodObject<{
157
- default: z.ZodOptional<ZodNumber>;
158
- isOptional: z.ZodOptional<z.ZodBoolean>;
159
- isVisible: z.ZodOptional<z.ZodBoolean>;
160
- label: z.ZodOptional<ZodString>;
161
- max: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
162
- message: ZodString;
163
- value: ZodNumber;
164
- }, core.$strip>]>>;
165
- min: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
166
- message: ZodString;
167
- value: ZodNumber;
168
- }, core.$strip>]>>;
169
- }, core.$strip>, ZodObject<{
170
- default: z.ZodOptional<z.ZodInstanceOf<File>>;
171
- isOptional: z.ZodOptional<z.ZodBoolean>;
172
- isVisible: z.ZodOptional<z.ZodBoolean>;
173
- label: z.ZodOptional<ZodString>;
174
- maxBytes: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
175
- message: ZodString;
176
- value: ZodNumber;
177
- }, core.$strip>]>>;
178
- minBytes: z.ZodOptional<z.ZodUnion<readonly [ZodNumber, ZodObject<{
179
- message: ZodString;
180
- value: ZodNumber;
181
- }, core.$strip>]>>;
182
- }, core.$strip>, ZodObject<{
183
- default: z.ZodOptional<ZodString>;
184
- isOptional: z.ZodOptional<z.ZodBoolean>;
185
- isVisible: z.ZodOptional<z.ZodBoolean>;
186
- label: z.ZodOptional<ZodString>;
187
- values: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<ZodString>, z.ZodRecord<ZodString, z.ZodUnion<readonly [ZodString, ZodNumber]>>]>>;
188
- }, core.$strip>]>;
189
- type AnyFieldSettings = z.infer<typeof AnyFieldSettingsSchema>;
190
- type FieldSettings<T extends ZodObject<ZodRawShape>> = { [K in keyof T['shape']]?: UnwrapZodType<T['shape'][K]> extends ZodString ? StringFieldSettings : UnwrapZodType<T['shape'][K]> extends ZodNumber ? NumberFieldSettings : UnwrapZodType<T['shape'][K]> extends ZodEnum<any> ? DropdownFieldSettings : UnwrapZodType<T['shape'][K]> extends ZodFile ? FileFieldSettings : BaseFieldSettings<z.infer<T['shape'][K]>>; };
191
- export declare function applyFieldSettings<T extends ZodRawShape>(schema: ZodObject<T>, fields?: FieldSettings<ZodObject<T>>): ZodObject<T>;
192
- /** Text whose every `{token}` names one of `keys`, with no stray braces. */
193
- export declare function formatTemplate(keys: readonly string[]): z.ZodString;
194
- /**
195
- * Twenty-four lower-case hex characters: the shape of every id on the wire and in a zod model.
196
- *
197
- * Named for the shape rather than for Mongo, because the shape is all a model can see — the
198
- * Mingo driver mints the same ids without Mongo anywhere near them. Lower case only, which is
199
- * what every driver here produces, so anything else is a value nothing in the platform minted.
200
- */
201
- export declare const HexString24Pattern: RegExp;
202
- /** What an id field says when nothing was chosen, and when what came is not an id. */
203
- export interface HexString24Messages {
204
- /** Defaults to "Invalid id.". */
205
- invalid?: string;
206
- /** `false` when nothing chosen is an answer: absent, `null` and `''` then all read as unset. */
207
- missing: false | string;
208
- }
209
- /**
210
- * A field holding one id.
211
- *
212
- * The message is the CALLER's, as `timeZone`'s is: "Select an owner." belongs to the form asking
213
- * for an owner, not here. It answers for nothing chosen: absent, `null`, or the empty string a
214
- * cleared select sends. A value that is there but is not an id says "Invalid id.", or `invalid`
215
- * when the caller names one. Left out entirely, zod says what it says about a pattern, which is
216
- * unreadable, and the reason a request schema should pass one.
217
- *
218
- * `{ missing: false }`, or `false` for short, is the field that may be left unset: absent, `null`
219
- * and `''` pass through as they came, so the repository can tell a clear (`''`) from a field left
220
- * alone.
221
- */
222
- export declare function hexString24(messages?: string | {
223
- invalid?: string;
224
- missing: string;
225
- }): z.ZodString;
226
- export declare function hexString24(messages: false | {
227
- invalid?: string;
228
- missing: false;
229
- }): z.ZodOptional<z.ZodNullable<z.ZodString>>;
230
- /**
231
- * An id with nothing said about whose it is.
232
- *
233
- * For a stored model, where the field is a shape rather than a question put to a person: a
234
- * polymorphic subject's `id`, a join's `_id`. A request that a person fills in wants
235
- * `hexString24(message)` instead, so a mistyped id reads as something other than a regex.
236
- */
237
- export declare const HexString24: z.ZodString;
238
- /** Whether a field holds a date: `z.date()`, an {@link isoDate} or an {@link isoDay}, under any wrappers. */
239
- export declare function isDateSchema(schema: ZodType): boolean;
240
- /**
241
- * A date field that also takes its ISO date-time string, as a value that came through JSON
242
- * arrives.
243
- *
244
- * Typed `Date` on both sides although it accepts a string at runtime: a form validator is a
245
- * `StandardSchemaV1<FormValues>`, and `z.input` reading `string | Date` would fail it. The cost
246
- * is `z.encode`, whose declared result is `Date` but which returns the ISO string, which only
247
- * matters where a value is about to be serialized.
248
- *
249
- * A factory, so each field has its own instance to describe, wrap and default. A `message`
250
- * replaces the refusal's, as `z.date(message)` does.
251
- */
252
- export declare function isoDate(message?: string): z.ZodCodec<z.ZodCustom<Date, Date>, z.ZodDate>;
253
- /**
254
- * A calendar day: `YYYY-MM-DD` on the wire, that day's UTC midnight as a `Date`, and the UTC day
255
- * again when encoded. Typed `Date` on both sides, as {@link isoDate} is, and marked `dateOnly`,
256
- * the metadata a date-only field carries.
257
- *
258
- * Refuses anything else (a date-time, a day no calendar has, a `Date` with a time of day) with
259
- * the issue `z.date()` raises, or `message`.
260
- */
261
- export declare function isoDay(message?: string): z.ZodCodec<z.ZodCustom<Date, Date>, z.ZodDate>;
262
- /** JSON held as text, strict or loose (`parseLooseJson`). A blank value is left to the field's own required rule. */
263
- export declare const JsonText: z.ZodString;
264
- /** The values of an enum field, or of the elements of an array of one. */
265
- type EnumValue<T extends z.ZodType> = Extract<z.output<T> extends readonly (infer TElement)[] ? TElement : z.output<T>, string>;
266
- /** How a field is named where the product names fields generically, such as the workflow criteria editor. */
267
- export interface FieldLabel<TValue extends string = string> {
268
- /** A dictionary key naming each value of an enum field, by value. */
269
- options?: Record<TValue, string>;
270
- /** The kind of record the value is the id of, such as `users`; the editor offers a search of that kind for it. */
271
- reference?: string;
272
- /** A dictionary key naming the field. */
273
- title: string;
274
- }
275
- /** The label a field carries, read through the optional/nullable/default wrappers declared around it. */
276
- export declare function fieldLabel(schema: z.ZodType): FieldLabel | undefined;
277
- /** A field, labelled. The label carries into the JSON Schema; validation is unchanged. */
278
- export declare function labelled<T extends z.ZodType>(schema: T, label: FieldLabel<EnumValue<T>>): T;
279
- /**
280
- * A field that takes an ISO 639-1 language, optionally with its region (`fr`, `fr-CA`), that
281
- * this runtime can name.
282
- *
283
- * The message is the caller's, as `timeZone`'s is: the i18n extractor harvests a plain zod
284
- * message where it is written. `whenEmpty` is separate for a form that distinguishes a field
285
- * nobody filled in from one filled in wrongly; left out, one message answers for both.
286
- */
287
- export declare function languageCode(message: string, whenEmpty?: string): z.ZodString;
288
- /** Text in each language, by language code: `{ en: 'Sales', fr: 'Ventes' }`. */
289
- export type LocalizedString = Record<string, string>;
290
- export type LocalizedStringArray = Record<string, string[]>;
291
- /**
292
- * A localized value with nothing said about it: any record of language → text, blank included.
293
- *
294
- * For a stored model, where a row saved before a rule must still read. A field a person fills
295
- * in wants `localizedString(messages)` instead, so a blank one is refused in words.
296
- */
297
- export declare const LocalizedString: z.ZodRecord<z.ZodString, z.ZodString>;
298
- export declare const LocalizedStringArray: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
299
- /** As {@link LocalizedString}, or a plain string — what a write model takes for a localized field. */
300
- export declare const LocalizedStringInput: z.ZodUnion<readonly [z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>]>;
301
- export declare const LocalizedStringArrayInput: z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>]>;
302
- export type LocalizedStringArrayInput = z.infer<typeof LocalizedStringArrayInput>;
303
- export type LocalizedStringInput = z.infer<typeof LocalizedStringInput>;
304
- /** What a localized field says when it has no text, and when what came is not text at all. */
305
- export interface LocalizedStringMessages {
306
- invalid: string;
307
- /** `false` when no text is an answer: absent, `null` and blank then all read as unset. */
308
- missing: false | string;
309
- }
310
- /**
311
- * Whether a localized value has text: a string that isn't blank, or text in at least one
312
- * language. `undefined`, `null`, `''`, `' '`, `{}` and `{ en: '', fr: ' ' }` have none.
313
- */
314
- export declare function hasLocalizedText(value: unknown): boolean;
315
- /** Whether a localized value is at most `max` characters, as a string or in every language it names. */
316
- export declare function isLocalizedTextWithin(value: unknown, max: number): boolean;
317
- /**
318
- * A form's localized field — a record, one entry per language — that needs text in some language.
319
- *
320
- * The messages are the CALLER's, as `hexString24`'s are: "Name is required." belongs to the form
321
- * asking for a name.
322
- *
323
- * One message answers for every case. `{ missing, invalid }` tells them apart: `missing` for no
324
- * text at all — absent, `null`, or blank in every language — and `invalid` for a value that is
325
- * there but is not text.
326
- *
327
- * `{ missing: false, invalid }` is the field that may be left empty: absent, `null` and blank
328
- * pass through as they came, so the repository can tell a clear from a field left alone.
329
- */
330
- export declare function localizedString(messages?: string | {
331
- invalid: string;
332
- missing: string;
333
- }): typeof LocalizedString;
334
- export declare function localizedString(messages: {
335
- invalid: string;
336
- missing: false;
337
- }): z.ZodOptional<z.ZodNullable<typeof LocalizedString>>;
338
- /**
339
- * A model's localized field — a record or a plain string — that needs text in some language, with
340
- * {@link localizedString}'s forms and messages; on a `partial()` update model, whenever it is sent.
341
- * The refine guards the endpoint only: repository writes skip refines.
342
- */
343
- export declare function localizedStringInput(messages?: string | {
344
- invalid: string;
345
- missing: string;
346
- }): typeof LocalizedStringInput;
347
- export declare function localizedStringInput(messages: {
348
- invalid: string;
349
- missing: false;
350
- }): z.ZodOptional<z.ZodNullable<typeof LocalizedStringInput>>;
351
- /**
352
- * The write-model fields that let a required localized name through blank — for a guard spec to
353
- * assert is empty.
354
- *
355
- * For every exported model `X` with an `AddX` or `UpdateX` beside it: a field `X` requires, and
356
- * that takes both a string and a locale record, is a required localized name. Its write models
357
- * must refuse `''` and `{ en: '' }`, which {@link localizedStringInput} does. Returns
358
- * `UpdateRole.name`-style paths for each one that doesn't. Read from the schemas rather than the
359
- * source, so it sees what a write actually accepts.
360
- */
361
- export declare function findUncheckedLocalizedFields(models: Record<string, unknown>): string[];
362
- /**
363
- * Recursively merges two ZodRawShape objects into a single shape,
364
- * combining overlapping keys into unions where applicable.
365
- */
366
- export type ZodMergeShapes<T extends ZodRawShape, U extends ZodRawShape> = { [K in keyof T | keyof U]: K extends keyof T & keyof U ? T[K] extends ZodObject<ZodRawShape> ? U[K] extends ZodObject<ZodRawShape> ? ZodObject<ZodMergeShapes<T[K]['shape'], U[K]['shape']>> : T[K] | U[K] : T[K] | U[K] : K extends keyof T ? T[K] : K extends keyof U ? U[K] : never; };
367
- /**
368
- * Adds a Zod type to an existing ZodUnion.
369
- */
370
- export declare function addToUnion<TUnion extends ZodUnion, TAny extends ZodType>(union: TUnion, object: TAny): ZodUnion;
371
- /**
372
- * Deeply merges two ZodRawShape objects into one.
373
- */
374
- export declare function mergeShapes<T extends ZodRawShape, U extends ZodRawShape>(shapeA: T, shapeB: U): ZodMergeShapes<T, U>;
375
- export declare function nullish<TShape extends Record<string, z.ZodType>>(fields: z.ZodObject<TShape>): z.ZodObject<{ -readonly [P in keyof { [TKey in keyof TShape]: z.ZodOptional<z.ZodNullable<TShape[TKey]>>; }]: { [TKey in keyof TShape]: z.ZodOptional<z.ZodNullable<TShape[TKey]>>; }[P]; }, z.core.$strip>;
376
- /**
377
- * Whether {@link toFieldPath} can follow `path` through `schema`: every segment is reached through objects and
378
- * arrays (and the wrappers and unions around them), with no pipe, transform, intersection, tuple, record or loose
379
- * (`any`, `unknown`, `custom`) node before the last. The path may end at one.
380
- */
381
- export declare function isFollowablePath(schema: ZodType, path: string): boolean;
382
- /**
383
- * `path` with `.$[]` after every segment that `schema` types as an array, except the last:
384
- * `settings.pages.defaultAccessLevels` -> `settings.pages.$[].defaultAccessLevels`. Returns
385
- * `path` unchanged when no segment before the last is an array.
386
- *
387
- * At a union, every arm is followed; a segment is an array when any arm types it as one.
388
- */
389
- export declare function toAllPositionalPath(schema: ZodType, path: string): string;
390
- /**
391
- * The field path `path` names in `schema`, its array positions left out:
392
- * `lines.0.attachments.$[].title` -> `lines.attachments.title`. A numeric segment is dropped
393
- * only where `schema` has an array, so a record's key stays: `budgets.2026` is unchanged.
394
- * `$`, `$[]` and `$[id]` are always positions.
395
- */
396
- export declare function toFieldPath(schema: ZodType, path: string): string;
397
- export declare const RegExpPattern: z.ZodString;
398
- /** A key, identifier or channel in {@link SlugPattern}. `missing` is the field's own message for an empty value, and the only one an empty value gets. */
399
- export declare function slug(missing?: string): z.ZodString;
400
- /** A slug with nothing said about an empty value beyond what any other wrong value gets. */
401
- export declare const Slug: z.ZodString;
402
- export declare function stripEmptyFields<T extends ZodType>(schema: T, values: z.input<T>): z.infer<T>;
403
- /**
404
- * `value` cut down to the fields `schema` declares, at every depth: through arrays, optionals, nullables, defaults,
405
- * catches, lazies and the objects of a union or an intersection, merged. Nothing is parsed, so no checks, codecs or defaults run, and a
406
- * value that doesn't fit its field is copied as it is. `value` itself is picked by its keys, whatever its prototype.
407
- */
408
- export declare function stripToSchema<T extends z.ZodObject>(schema: T, value: object): z.output<T>;
409
- /**
410
- * A field that takes an IANA zone this runtime can actually format in.
411
- *
412
- * The check belongs at the write boundary: an unsupported zone is stored happily and then
413
- * throws a `RangeError` inside `Intl` on every later read, far from whatever put it there.
414
- *
415
- * The message is the CALLER's, as `objectId`'s is, for two reasons. A domain says what it
416
- * wants in its own words — "Select a valid time zone." on a form, "Invalid time zone." on a
417
- * public booking — and the i18n extractor harvests a plain zod message where it is written,
418
- * so a sentence buried in here would reach no dictionary. `whenEmpty` is separate for a form
419
- * that distinguishes a field nobody filled in from one filled in wrongly; left out, one
420
- * message answers for both.
421
- */
422
- export declare function timeZone(message: string, whenEmpty?: string): z.ZodString;
423
- /**
424
- * A JSON Schema document, as {@link toJsonSchema} produces.
425
- *
426
- * An object rather than `unknown` because these schemas exist to be READ: an editor
427
- * walks `properties` to build its field pickers. As `unknown`, every consumer casts
428
- * before it can index - at exactly the boundary that was supposed to describe the value.
429
- *
430
- * Deliberately not modelled more precisely than "a JSON object". JSON Schema is
431
- * recursive and open-ended, and restating its grammar here would be a second, worse
432
- * copy of a specification we do not own.
433
- */
434
- export declare const JsonSchemaDocument: z.ZodRecord<z.ZodString, z.ZodUnknown>;
435
- export type JsonSchemaDocument = z.infer<typeof JsonSchemaDocument>;
436
- export interface ToJsonSchemaOptions {
437
- /** Describe what the schema accepts (`input`) or what it produces (`output`, the default). */
438
- io?: 'input' | 'output';
439
- /**
440
- * What to do with a type JSON Schema cannot describe (bigint, Map, a transform...).
441
- * `throw`, the default, fails the conversion; `any` describes it as `{}`, for a
442
- * consumer that would rather offer a loose schema than none.
443
- */
444
- unrepresentable?: 'any' | 'throw';
445
- }
446
- /**
447
- * `z.toJSONSchema`, with dates described rather than refused.
448
- *
449
- * zod has no JSON Schema for `z.date()` and throws on it by default, so one date field
450
- * anywhere in a schema fails the whole conversion - which is how one event with a
451
- * `startAt` blanked the workflow editor, and why every domain model's schema endpoint
452
- * answered 500. Here a date is `{ type: 'string', format: 'date-time' }`, the node
453
- * `z.iso.datetime()` produces, so a reader sees the same field either way, and an
454
- * `isoDate()` reads the same as `z.date()` on either side; an `isoDay()` is a `format: 'date'`
455
- * string on either side. The value
456
- * itself is untouched: a schema that takes a `Date` still takes a `Date`.
457
- *
458
- * Use this rather than `z.toJSONSchema`; the lint rule `no-restricted-properties`
459
- * points there.
460
- */
461
- export declare function toJsonSchema(schema: z.ZodType, options?: ToJsonSchemaOptions): JsonSchemaDocument;
462
- export declare const ZOD_WRAPPER_TYPES: string[];
463
- export declare function getInnerType(schema: ZodType): ZodType;
464
- export declare function isFieldNullable(schema: ZodType): boolean;
465
- /**
466
- * Whether `schema` is declared `.optional()`, looking only through `.optional()` and `.nullable()`: what a form or a
467
- * write may leave empty. For whether a parsed value may lack the field, through any wrapper, use {@link isOptionalOutput}.
468
- */
469
- export declare function isFieldOptional(schema: ZodType): boolean;
470
- /**
471
- * Whether a value typed by what `schema` outputs may lack the field: optional through any wrapper (lazy, readonly, a
472
- * union with an optional member), as zod decides it, not filled by a default; and `any` or `unknown`, whose type takes
473
- * `undefined` already. What a read typed by the schema may lack; for a field declared `.optional()`, {@link isFieldOptional}.
474
- */
475
- export declare function isOptionalOutput(schema: ZodType): boolean;
476
- export declare function isZodAny(obj: unknown): obj is ZodType;
477
- export declare function isZodArray(obj: unknown): obj is ZodArray<ZodType>;
478
- export declare function isZodCatch<T extends ZodType>(obj: unknown): obj is ZodCatch<T>;
479
- /** A codec, as `z.codec` builds: a pipe that can also run backwards. Read it as its `out`, what it decodes to. */
480
- export declare function isZodCodec(obj: unknown): obj is ZodCodec;
481
- export declare function isZodDate(obj: unknown): obj is ZodDate;
482
- export declare function isZodDefault(obj: unknown): obj is ZodDefault;
483
- export declare function isZodEnum(obj: unknown): obj is ZodEnum;
484
- export declare function isZodIntersection(obj: unknown): obj is ZodIntersection<ZodType, ZodType>;
485
- export declare function isZodLazy(obj: unknown): obj is ZodLazy;
486
- export declare function isZodNullable(obj: unknown): obj is ZodNullable<ZodType>;
487
- export declare function isZodNumber(obj: unknown): obj is ZodNumber;
488
- export declare function isZodObject(obj: unknown, isLoose?: boolean): obj is ZodObject;
489
- export declare function isZodObjectLoose(obj: ZodObject): boolean;
490
- export declare function isZodOptional(obj: unknown): obj is ZodOptional<ZodType>;
491
- export declare function isZodPipe(obj: unknown): obj is ZodPipe;
492
- export declare function isZodRecord(obj: unknown): obj is ZodRecord;
493
- export declare function isZodString(obj: unknown): obj is ZodString;
494
- export declare function isZodTransform(obj: unknown): obj is ZodTransform;
495
- export declare function isZodType(obj: unknown): obj is ZodType;
496
- export declare function isZodUnion(obj: unknown): obj is ZodUnion<ZodType[]>;
497
- export declare function isZodUnknown(obj: unknown): obj is ZodUnknown;
498
- export declare function isZodWrapper(obj: unknown): obj is ZodWrapper;
499
- export declare const NonNegativeInteger: import("zod").ZodNumber;
500
- export declare const PositiveInteger: import("zod").ZodNumber;
501
- export type { AnyFieldSettings, DropdownFieldSettings, FieldSettings, NumberFieldSettings, StringFieldSettings };
1
+ import { NumberBounds, boundedNumber } from "./bounded-number.js";
2
+ import { codecParts, withCodecParts } from "./codec-parts.js";
3
+ import { CurrencyCodePattern, currencyCode } from "./currency-code.js";
4
+ import { GetZodFieldPathsOptions, ZodFieldPath, getZodFieldPaths, unwrapField } from "./field-paths.js";
5
+ import { AnyFieldSettings, AnyFieldSettingsSchema, DropdownFieldSettings, FieldSettings, NumberFieldSettings, StringFieldSettings, applyFieldSettings } from "./field-settings.js";
6
+ import { formatTemplate } from "./format-template.js";
7
+ import { HexString24, HexString24Messages, HexString24Pattern, hexString24 } from "./hex-string-24.js";
8
+ import { isDateSchema, isoDate, isoDay } from "./iso-date.js";
9
+ import { JsonText } from "./json-text.js";
10
+ import { FieldLabel, fieldLabel, labelled } from "./labelled.js";
11
+ import { languageCode } from "./language-code.js";
12
+ import { LocalizedString, LocalizedStringArray, LocalizedStringArrayInput, LocalizedStringInput, LocalizedStringMessages, findUncheckedLocalizedFields, hasLocalizedText, isLocalizedTextWithin, localizedString, localizedStringInput } from "./localized-string.js";
13
+ import { ZodMergeShapes, addToUnion, mergeShapes } from "./merge.js";
14
+ import { nullish } from "./nullish.js";
15
+ import { isFollowablePath, toAllPositionalPath, toFieldPath } from "./positional-paths.js";
16
+ import { RegExpPattern } from "./reg-exp-pattern.js";
17
+ import { Slug, slug } from "./slug.js";
18
+ import { stripEmptyFields } from "./strip-empty-fields.js";
19
+ import { stripToSchema } from "./strip-to-schema.js";
20
+ import { timeZone } from "./time-zone.js";
21
+ import { JsonSchemaDocument, ToJsonSchemaOptions, toJsonSchema } from "./to-json-schema.js";
22
+ import { Mutable, UnwrapZodType, ZodWrapper } from "./types.js";
23
+ import { ZOD_WRAPPER_TYPES, getInnerType, isFieldNullable, isFieldOptional, isOptionalOutput, isZodAny, isZodArray, isZodCatch, isZodCodec, isZodDate, isZodDefault, isZodEnum, isZodIntersection, isZodLazy, isZodNullable, isZodNumber, isZodObject, isZodObjectLoose, isZodOptional, isZodPipe, isZodRecord, isZodString, isZodTransform, isZodType, isZodUnion, isZodUnknown, isZodWrapper } from "./utilities.js";
24
+ import { NonNegativeInteger, PositiveInteger } from "./whole-number.js";
25
+ export { type AnyFieldSettings, AnyFieldSettingsSchema, CurrencyCodePattern, type DropdownFieldSettings, FieldLabel, type FieldSettings, GetZodFieldPathsOptions, HexString24, HexString24Messages, HexString24Pattern, JsonSchemaDocument, JsonText, LocalizedString, LocalizedStringArray, LocalizedStringArrayInput, LocalizedStringInput, LocalizedStringMessages, Mutable, NonNegativeInteger, NumberBounds, type NumberFieldSettings, PositiveInteger, RegExpPattern, Slug, type StringFieldSettings, ToJsonSchemaOptions, UnwrapZodType, ZOD_WRAPPER_TYPES, ZodFieldPath, ZodMergeShapes, ZodWrapper, addToUnion, applyFieldSettings, boundedNumber, codecParts, currencyCode, fieldLabel, findUncheckedLocalizedFields, formatTemplate, getInnerType, getZodFieldPaths, hasLocalizedText, hexString24, isDateSchema, isFieldNullable, isFieldOptional, isFollowablePath, isLocalizedTextWithin, isOptionalOutput, isZodAny, isZodArray, isZodCatch, isZodCodec, isZodDate, isZodDefault, isZodEnum, isZodIntersection, isZodLazy, isZodNullable, isZodNumber, isZodObject, isZodObjectLoose, isZodOptional, isZodPipe, isZodRecord, isZodString, isZodTransform, isZodType, isZodUnion, isZodUnknown, isZodWrapper, isoDate, isoDay, labelled, languageCode, localizedString, localizedStringInput, mergeShapes, nullish, slug, stripEmptyFields, stripToSchema, timeZone, toAllPositionalPath, toFieldPath, toJsonSchema, unwrapField, withCodecParts };