@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.
- package/dist/bounded-number.d.ts +8 -0
- package/dist/bounded-number.js +36 -0
- package/dist/codec-parts.d.ts +8 -0
- package/dist/codec-parts.js +21 -0
- package/dist/currency-code.d.ts +5 -0
- package/dist/currency-code.js +11 -0
- package/dist/field-paths.d.ts +54 -0
- package/dist/field-paths.js +67 -0
- package/dist/field-settings.d.ts +119 -0
- package/dist/field-settings.js +219 -0
- package/dist/format-template.d.ts +3 -0
- package/dist/format-template.js +8 -0
- package/dist/hex-string-24.d.ts +45 -0
- package/dist/hex-string-24.js +32 -0
- package/dist/index.d.ts +25 -501
- package/dist/index.js +23 -992
- package/dist/iso-date.d.ts +25 -0
- package/dist/iso-date.js +108 -0
- package/dist/json-text.d.ts +3 -0
- package/dist/json-text.js +6 -0
- package/dist/labelled.d.ts +17 -0
- package/dist/labelled.js +22 -0
- package/dist/language-code.d.ts +10 -0
- package/dist/language-code.js +15 -0
- package/dist/localized-string.d.ts +75 -0
- package/dist/localized-string.js +80 -0
- package/dist/merge.d.ts +14 -0
- package/dist/merge.js +26 -0
- package/dist/nullish.d.ts +2 -0
- package/dist/nullish.js +7 -0
- package/dist/positional-paths.d.ts +22 -0
- package/dist/positional-paths.js +99 -0
- package/dist/reg-exp-pattern.d.ts +2 -0
- package/dist/reg-exp-pattern.js +5 -0
- package/dist/slug.d.ts +5 -0
- package/dist/slug.js +15 -0
- package/dist/strip-empty-fields.d.ts +2 -0
- package/dist/strip-empty-fields.js +46 -0
- package/dist/strip-to-schema.d.ts +7 -0
- package/dist/strip-to-schema.js +35 -0
- package/dist/time-zone.d.ts +15 -0
- package/dist/time-zone.js +20 -0
- package/dist/to-json-schema.d.ts +40 -0
- package/dist/to-json-schema.js +44 -0
- package/dist/types.d.ts +4 -0
- package/dist/utilities.d.ts +39 -0
- package/dist/utilities.js +116 -0
- package/dist/whole-number.d.ts +2 -0
- package/dist/whole-number.js +11 -0
- package/package.json +5 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { unwrapField } from "./field-paths.js";
|
|
2
|
+
import { isZodArray, isZodIntersection, isZodObject, isZodUnion } from "./utilities.js";
|
|
3
|
+
import { isPlainObject } from "@temelyos/core/object";
|
|
4
|
+
// src/strip-to-schema.ts
|
|
5
|
+
function pick(schemas, value) {
|
|
6
|
+
const fields = schemas.flatMap(variantsOf);
|
|
7
|
+
if (Array.isArray(value)) {
|
|
8
|
+
const elements = fields.filter(isZodArray).map((field) => field.element);
|
|
9
|
+
return elements.length === 0 ? value : value.map((item) => pick(elements, item));
|
|
10
|
+
}
|
|
11
|
+
const shapes = fields.flatMap((field) => isZodObject(field) ? [field.shape] : []);
|
|
12
|
+
return shapes.length === 0 || !isPlainObject(value) ? value : pickFields(shapes, value);
|
|
13
|
+
}
|
|
14
|
+
/** The fields of `value` that any of `shapes` declares, each picked by every shape that declares it. */
|
|
15
|
+
function pickFields(shapes, value) {
|
|
16
|
+
const record = value;
|
|
17
|
+
const picked = {};
|
|
18
|
+
for (const key of new Set(shapes.flatMap((shape) => Object.keys(shape)))) if (Object.hasOwn(record, key) && record[key] !== void 0) picked[key] = pick(shapes.flatMap((shape) => Object.hasOwn(shape, key) ? [shape[key]] : []), record[key]);
|
|
19
|
+
return picked;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `value` cut down to the fields `schema` declares, at every depth: through arrays, optionals, nullables, defaults,
|
|
23
|
+
* catches, lazies and the objects of a union or an intersection, merged. Nothing is parsed, so no checks, codecs or defaults run, and a
|
|
24
|
+
* value that doesn't fit its field is copied as it is. `value` itself is picked by its keys, whatever its prototype.
|
|
25
|
+
*/
|
|
26
|
+
function stripToSchema(schema, value) {
|
|
27
|
+
return pickFields([schema.shape], value);
|
|
28
|
+
}
|
|
29
|
+
/** What `schema` holds a value as, through wrappers and lazies: each option of a union, each side of an intersection, or itself. */
|
|
30
|
+
function variantsOf(schema) {
|
|
31
|
+
const field = unwrapField(schema, true);
|
|
32
|
+
if (isZodIntersection(field)) return [...variantsOf(field.def.left), ...variantsOf(field.def.right)];
|
|
33
|
+
return isZodUnion(field) ? field.options.flatMap(variantsOf) : [field];
|
|
34
|
+
}
|
|
35
|
+
export { stripToSchema };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A field that takes an IANA zone this runtime can actually format in.
|
|
4
|
+
*
|
|
5
|
+
* The check belongs at the write boundary: an unsupported zone is stored happily and then
|
|
6
|
+
* throws a `RangeError` inside `Intl` on every later read, far from whatever put it there.
|
|
7
|
+
*
|
|
8
|
+
* The message is the CALLER's, as `objectId`'s is, for two reasons. A domain says what it
|
|
9
|
+
* wants in its own words — "Select a valid time zone." on a form, "Invalid time zone." on a
|
|
10
|
+
* public booking — and the i18n extractor harvests a plain zod message where it is written,
|
|
11
|
+
* so a sentence buried in here would reach no dictionary. `whenEmpty` is separate for a form
|
|
12
|
+
* that distinguishes a field nobody filled in from one filled in wrongly; left out, one
|
|
13
|
+
* message answers for both.
|
|
14
|
+
*/
|
|
15
|
+
export declare function timeZone(message: string, whenEmpty?: string): z.ZodString;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isSupportedTimezone } from "@temelyos/core/time-zone";
|
|
3
|
+
// src/time-zone.ts
|
|
4
|
+
/**
|
|
5
|
+
* A field that takes an IANA zone this runtime can actually format in.
|
|
6
|
+
*
|
|
7
|
+
* The check belongs at the write boundary: an unsupported zone is stored happily and then
|
|
8
|
+
* throws a `RangeError` inside `Intl` on every later read, far from whatever put it there.
|
|
9
|
+
*
|
|
10
|
+
* The message is the CALLER's, as `objectId`'s is, for two reasons. A domain says what it
|
|
11
|
+
* wants in its own words — "Select a valid time zone." on a form, "Invalid time zone." on a
|
|
12
|
+
* public booking — and the i18n extractor harvests a plain zod message where it is written,
|
|
13
|
+
* so a sentence buried in here would reach no dictionary. `whenEmpty` is separate for a form
|
|
14
|
+
* that distinguishes a field nobody filled in from one filled in wrongly; left out, one
|
|
15
|
+
* message answers for both.
|
|
16
|
+
*/
|
|
17
|
+
function timeZone(message, whenEmpty = message) {
|
|
18
|
+
return z.string().min(1, whenEmpty).refine(isSupportedTimezone, message);
|
|
19
|
+
}
|
|
20
|
+
export { timeZone };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* A JSON Schema document, as {@link toJsonSchema} produces.
|
|
4
|
+
*
|
|
5
|
+
* An object rather than `unknown` because these schemas exist to be READ: an editor
|
|
6
|
+
* walks `properties` to build its field pickers. As `unknown`, every consumer casts
|
|
7
|
+
* before it can index - at exactly the boundary that was supposed to describe the value.
|
|
8
|
+
*
|
|
9
|
+
* Deliberately not modelled more precisely than "a JSON object". JSON Schema is
|
|
10
|
+
* recursive and open-ended, and restating its grammar here would be a second, worse
|
|
11
|
+
* copy of a specification we do not own.
|
|
12
|
+
*/
|
|
13
|
+
export declare const JsonSchemaDocument: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
14
|
+
export type JsonSchemaDocument = z.infer<typeof JsonSchemaDocument>;
|
|
15
|
+
export interface ToJsonSchemaOptions {
|
|
16
|
+
/** Describe what the schema accepts (`input`) or what it produces (`output`, the default). */
|
|
17
|
+
io?: 'input' | 'output';
|
|
18
|
+
/**
|
|
19
|
+
* What to do with a type JSON Schema cannot describe (bigint, Map, a transform...).
|
|
20
|
+
* `throw`, the default, fails the conversion; `any` describes it as `{}`, for a
|
|
21
|
+
* consumer that would rather offer a loose schema than none.
|
|
22
|
+
*/
|
|
23
|
+
unrepresentable?: 'any' | 'throw';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `z.toJSONSchema`, with dates described rather than refused.
|
|
27
|
+
*
|
|
28
|
+
* zod has no JSON Schema for `z.date()` and throws on it by default, so one date field
|
|
29
|
+
* anywhere in a schema fails the whole conversion - which is how one event with a
|
|
30
|
+
* `startAt` blanked the workflow editor, and why every domain model's schema endpoint
|
|
31
|
+
* answered 500. Here a date is `{ type: 'string', format: 'date-time' }`, the node
|
|
32
|
+
* `z.iso.datetime()` produces, so a reader sees the same field either way, and an
|
|
33
|
+
* `isoDate()` reads the same as `z.date()` on either side; an `isoDay()` is a `format: 'date'`
|
|
34
|
+
* string on either side. The value
|
|
35
|
+
* itself is untouched: a schema that takes a `Date` still takes a `Date`.
|
|
36
|
+
*
|
|
37
|
+
* Use this rather than `z.toJSONSchema`; the lint rule `no-restricted-properties`
|
|
38
|
+
* points there.
|
|
39
|
+
*/
|
|
40
|
+
export declare function toJsonSchema(schema: z.ZodType, options?: ToJsonSchemaOptions): JsonSchemaDocument;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { dateFormat } from "./iso-date.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/to-json-schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* A JSON Schema document, as {@link toJsonSchema} produces.
|
|
6
|
+
*
|
|
7
|
+
* An object rather than `unknown` because these schemas exist to be READ: an editor
|
|
8
|
+
* walks `properties` to build its field pickers. As `unknown`, every consumer casts
|
|
9
|
+
* before it can index - at exactly the boundary that was supposed to describe the value.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately not modelled more precisely than "a JSON object". JSON Schema is
|
|
12
|
+
* recursive and open-ended, and restating its grammar here would be a second, worse
|
|
13
|
+
* copy of a specification we do not own.
|
|
14
|
+
*/
|
|
15
|
+
const JsonSchemaDocument = z.record(z.string(), z.unknown());
|
|
16
|
+
/**
|
|
17
|
+
* `z.toJSONSchema`, with dates described rather than refused.
|
|
18
|
+
*
|
|
19
|
+
* zod has no JSON Schema for `z.date()` and throws on it by default, so one date field
|
|
20
|
+
* anywhere in a schema fails the whole conversion - which is how one event with a
|
|
21
|
+
* `startAt` blanked the workflow editor, and why every domain model's schema endpoint
|
|
22
|
+
* answered 500. Here a date is `{ type: 'string', format: 'date-time' }`, the node
|
|
23
|
+
* `z.iso.datetime()` produces, so a reader sees the same field either way, and an
|
|
24
|
+
* `isoDate()` reads the same as `z.date()` on either side; an `isoDay()` is a `format: 'date'`
|
|
25
|
+
* string on either side. The value
|
|
26
|
+
* itself is untouched: a schema that takes a `Date` still takes a `Date`.
|
|
27
|
+
*
|
|
28
|
+
* Use this rather than `z.toJSONSchema`; the lint rule `no-restricted-properties`
|
|
29
|
+
* points there.
|
|
30
|
+
*/
|
|
31
|
+
function toJsonSchema(schema, options = {}) {
|
|
32
|
+
const otherwise = options.unrepresentable ?? "throw";
|
|
33
|
+
return z.toJSONSchema(schema, {
|
|
34
|
+
io: options.io,
|
|
35
|
+
unrepresentable: ({ zodSchema }) => {
|
|
36
|
+
const format = dateFormat(zodSchema) ?? (zodSchema._zod.def.type === "date" ? "date-time" : void 0);
|
|
37
|
+
return format ? {
|
|
38
|
+
format,
|
|
39
|
+
type: "string"
|
|
40
|
+
} : otherwise;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export { JsonSchemaDocument, toJsonSchema };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ZodArray, ZodCatch, ZodDefault, ZodLazy, ZodNonOptional, ZodNullable, ZodOptional, ZodPromise, ZodSuccess } from "zod";
|
|
2
|
+
export type Mutable<T> = { -readonly [P in keyof T]: T[P]; };
|
|
3
|
+
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;
|
|
4
|
+
export type ZodWrapper = ZodCatch | ZodDefault | ZodLazy | ZodNonOptional | ZodNullable | ZodOptional | ZodPromise | ZodSuccess;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ZodWrapper } from "./types.js";
|
|
2
|
+
import { ZodArray, ZodCatch, ZodCodec, ZodDate, ZodDefault, ZodEnum, ZodIntersection, ZodLazy, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodPipe, ZodRecord, ZodString, ZodTransform, ZodType, ZodUnion, ZodUnknown } from "zod";
|
|
3
|
+
export declare const ZOD_WRAPPER_TYPES: string[];
|
|
4
|
+
export declare function getInnerType(schema: ZodType): ZodType;
|
|
5
|
+
export declare function isFieldNullable(schema: ZodType): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether `schema` is declared `.optional()`, looking only through `.optional()` and `.nullable()`: what a form or a
|
|
8
|
+
* write may leave empty. For whether a parsed value may lack the field, through any wrapper, use {@link isOptionalOutput}.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isFieldOptional(schema: ZodType): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a value typed by what `schema` outputs may lack the field: optional through any wrapper (lazy, readonly, a
|
|
13
|
+
* union with an optional member), as zod decides it, not filled by a default; and `any` or `unknown`, whose type takes
|
|
14
|
+
* `undefined` already. What a read typed by the schema may lack; for a field declared `.optional()`, {@link isFieldOptional}.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isOptionalOutput(schema: ZodType): boolean;
|
|
17
|
+
export declare function isZodAny(obj: unknown): obj is ZodType;
|
|
18
|
+
export declare function isZodArray(obj: unknown): obj is ZodArray<ZodType>;
|
|
19
|
+
export declare function isZodCatch<T extends ZodType>(obj: unknown): obj is ZodCatch<T>;
|
|
20
|
+
/** A codec, as `z.codec` builds: a pipe that can also run backwards. Read it as its `out`, what it decodes to. */
|
|
21
|
+
export declare function isZodCodec(obj: unknown): obj is ZodCodec;
|
|
22
|
+
export declare function isZodDate(obj: unknown): obj is ZodDate;
|
|
23
|
+
export declare function isZodDefault(obj: unknown): obj is ZodDefault;
|
|
24
|
+
export declare function isZodEnum(obj: unknown): obj is ZodEnum;
|
|
25
|
+
export declare function isZodIntersection(obj: unknown): obj is ZodIntersection<ZodType, ZodType>;
|
|
26
|
+
export declare function isZodLazy(obj: unknown): obj is ZodLazy;
|
|
27
|
+
export declare function isZodNullable(obj: unknown): obj is ZodNullable<ZodType>;
|
|
28
|
+
export declare function isZodNumber(obj: unknown): obj is ZodNumber;
|
|
29
|
+
export declare function isZodObject(obj: unknown, isLoose?: boolean): obj is ZodObject;
|
|
30
|
+
export declare function isZodObjectLoose(obj: ZodObject): boolean;
|
|
31
|
+
export declare function isZodOptional(obj: unknown): obj is ZodOptional<ZodType>;
|
|
32
|
+
export declare function isZodPipe(obj: unknown): obj is ZodPipe;
|
|
33
|
+
export declare function isZodRecord(obj: unknown): obj is ZodRecord;
|
|
34
|
+
export declare function isZodString(obj: unknown): obj is ZodString;
|
|
35
|
+
export declare function isZodTransform(obj: unknown): obj is ZodTransform;
|
|
36
|
+
export declare function isZodType(obj: unknown): obj is ZodType;
|
|
37
|
+
export declare function isZodUnion(obj: unknown): obj is ZodUnion<ZodType[]>;
|
|
38
|
+
export declare function isZodUnknown(obj: unknown): obj is ZodUnknown;
|
|
39
|
+
export declare function isZodWrapper(obj: unknown): obj is ZodWrapper;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { ZodArray, ZodCatch, ZodDefault, ZodLazy, ZodNullable, ZodOptional } from "zod";
|
|
2
|
+
// src/utilities.ts
|
|
3
|
+
const ZOD_WRAPPER_TYPES = [
|
|
4
|
+
"catch",
|
|
5
|
+
"default",
|
|
6
|
+
"lazy",
|
|
7
|
+
"nonoptional",
|
|
8
|
+
"nullable",
|
|
9
|
+
"optional",
|
|
10
|
+
"promise",
|
|
11
|
+
"success"
|
|
12
|
+
];
|
|
13
|
+
function getInnerType(schema) {
|
|
14
|
+
if (schema instanceof ZodOptional || schema instanceof ZodNullable || schema instanceof ZodDefault || schema instanceof ZodCatch) return getInnerType(schema.def.innerType);
|
|
15
|
+
if (schema instanceof ZodLazy) return getInnerType(schema.def.getter());
|
|
16
|
+
if (schema instanceof ZodArray) return getInnerType(schema.def.element);
|
|
17
|
+
return schema;
|
|
18
|
+
}
|
|
19
|
+
function isFieldNullable(schema) {
|
|
20
|
+
let current = schema;
|
|
21
|
+
while (isZodOptional(current) || isZodNullable(current)) {
|
|
22
|
+
if (isZodNullable(current)) return true;
|
|
23
|
+
current = current.def.innerType;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether `schema` is declared `.optional()`, looking only through `.optional()` and `.nullable()`: what a form or a
|
|
29
|
+
* write may leave empty. For whether a parsed value may lack the field, through any wrapper, use {@link isOptionalOutput}.
|
|
30
|
+
*/
|
|
31
|
+
function isFieldOptional(schema) {
|
|
32
|
+
let current = schema;
|
|
33
|
+
while (isZodOptional(current) || isZodNullable(current)) {
|
|
34
|
+
if (isZodOptional(current)) return true;
|
|
35
|
+
current = current.def.innerType;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a value typed by what `schema` outputs may lack the field: optional through any wrapper (lazy, readonly, a
|
|
41
|
+
* union with an optional member), as zod decides it, not filled by a default; and `any` or `unknown`, whose type takes
|
|
42
|
+
* `undefined` already. What a read typed by the schema may lack; for a field declared `.optional()`, {@link isFieldOptional}.
|
|
43
|
+
*/
|
|
44
|
+
function isOptionalOutput(schema) {
|
|
45
|
+
return schema._zod.optout === "optional" || schema.def.type === "any" || schema.def.type === "unknown";
|
|
46
|
+
}
|
|
47
|
+
function isZodAny(obj) {
|
|
48
|
+
return isZodType(obj) && obj.def.type === "any";
|
|
49
|
+
}
|
|
50
|
+
function isZodArray(obj) {
|
|
51
|
+
return isZodType(obj) && obj.def.type === "array";
|
|
52
|
+
}
|
|
53
|
+
function isZodCatch(obj) {
|
|
54
|
+
return isZodType(obj) && obj.def.type === "catch";
|
|
55
|
+
}
|
|
56
|
+
/** A codec, as `z.codec` builds: a pipe that can also run backwards. Read it as its `out`, what it decodes to. */
|
|
57
|
+
function isZodCodec(obj) {
|
|
58
|
+
return isZodPipe(obj) && "reverseTransform" in obj.def;
|
|
59
|
+
}
|
|
60
|
+
function isZodDate(obj) {
|
|
61
|
+
return isZodType(obj) && obj.def.type === "date";
|
|
62
|
+
}
|
|
63
|
+
function isZodDefault(obj) {
|
|
64
|
+
return isZodType(obj) && obj.def.type === "default";
|
|
65
|
+
}
|
|
66
|
+
function isZodEnum(obj) {
|
|
67
|
+
return isZodType(obj) && obj.def.type === "enum";
|
|
68
|
+
}
|
|
69
|
+
function isZodIntersection(obj) {
|
|
70
|
+
return isZodType(obj) && obj.def.type === "intersection";
|
|
71
|
+
}
|
|
72
|
+
function isZodLazy(obj) {
|
|
73
|
+
return isZodType(obj) && obj.def.type === "lazy";
|
|
74
|
+
}
|
|
75
|
+
function isZodNullable(obj) {
|
|
76
|
+
return isZodType(obj) && obj.def.type === "nullable";
|
|
77
|
+
}
|
|
78
|
+
function isZodNumber(obj) {
|
|
79
|
+
return isZodType(obj) && obj.def.type === "number";
|
|
80
|
+
}
|
|
81
|
+
function isZodObject(obj, isLoose) {
|
|
82
|
+
if (!isZodType(obj) || obj.def.type !== "object") return false;
|
|
83
|
+
if (typeof isLoose === "undefined") return true;
|
|
84
|
+
return isLoose === isZodObjectLoose(obj);
|
|
85
|
+
}
|
|
86
|
+
function isZodObjectLoose(obj) {
|
|
87
|
+
return !!isZodUnknown(obj.def.catchall);
|
|
88
|
+
}
|
|
89
|
+
function isZodOptional(obj) {
|
|
90
|
+
return isZodType(obj) && obj.def.type === "optional";
|
|
91
|
+
}
|
|
92
|
+
function isZodPipe(obj) {
|
|
93
|
+
return isZodType(obj) && obj.def.type === "pipe";
|
|
94
|
+
}
|
|
95
|
+
function isZodRecord(obj) {
|
|
96
|
+
return isZodType(obj) && obj.def.type === "record";
|
|
97
|
+
}
|
|
98
|
+
function isZodString(obj) {
|
|
99
|
+
return isZodType(obj) && obj.def.type === "string";
|
|
100
|
+
}
|
|
101
|
+
function isZodTransform(obj) {
|
|
102
|
+
return isZodType(obj) && obj.def.type === "transform";
|
|
103
|
+
}
|
|
104
|
+
function isZodType(obj) {
|
|
105
|
+
return typeof obj === "object" && obj !== null && "def" in obj && "safeParse" in obj && typeof obj.safeParse === "function";
|
|
106
|
+
}
|
|
107
|
+
function isZodUnion(obj) {
|
|
108
|
+
return isZodType(obj) && obj.def.type === "union";
|
|
109
|
+
}
|
|
110
|
+
function isZodUnknown(obj) {
|
|
111
|
+
return isZodType(obj) && obj.def.type === "unknown";
|
|
112
|
+
}
|
|
113
|
+
function isZodWrapper(obj) {
|
|
114
|
+
return isZodType(obj) && ZOD_WRAPPER_TYPES.includes(obj.def.type);
|
|
115
|
+
}
|
|
116
|
+
export { 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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { boundedNumber } from "./bounded-number.js";
|
|
2
|
+
// src/whole-number.ts
|
|
3
|
+
const NonNegativeInteger = boundedNumber({
|
|
4
|
+
integer: true,
|
|
5
|
+
min: 0
|
|
6
|
+
});
|
|
7
|
+
const PositiveInteger = boundedNumber({
|
|
8
|
+
integer: true,
|
|
9
|
+
min: 1
|
|
10
|
+
});
|
|
11
|
+
export { NonNegativeInteger, PositiveInteger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temelyos/zod",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Zod schemas and helpers for Temelyos: ids, ISO dates and days, localized strings, field settings, JSON Schema conversion, and schema merging and stripping.",
|
|
5
5
|
"author": "Secure Data Systems",
|
|
6
6
|
"license": "ISC",
|
|
@@ -30,11 +30,14 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"zod": "^4.6.7",
|
|
34
33
|
"@temelyos/core": "^1.0.1"
|
|
35
34
|
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"zod": "^4.6.7"
|
|
37
|
+
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"tsdown": "^0.23.3",
|
|
40
|
+
"zod": "^4.6.7",
|
|
38
41
|
"@temelyos/tsdown-config": "^0.0.0",
|
|
39
42
|
"@temelyos/typescript-config": "^0.0.0"
|
|
40
43
|
},
|