@naturalcycles/js-lib 15.44.0 → 15.45.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/validation/validation.d.ts +2 -2
- package/dist/zod/zod.shared.schemas.d.ts +0 -2
- package/dist/zod/zod.shared.schemas.js +0 -4
- package/dist/zod/zod.util.d.ts +1 -1
- package/package.json +2 -2
- package/src/json-schema/jsonSchemaBuilder.ts +0 -3
- package/src/validation/validation.ts +4 -4
- package/src/zod/zod.shared.schemas.ts +0 -5
- package/src/zod/zod.util.ts +1 -1
|
@@ -14,8 +14,8 @@ import type { AppError } from '../error/error.util.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @experimental
|
|
16
16
|
*/
|
|
17
|
-
export type ValidationFunction<
|
|
18
|
-
export type ValidationFunctionResult<
|
|
17
|
+
export type ValidationFunction<IN, OUT, ERR extends AppError> = (input: IN, opt?: ValidationFunctionOptions) => ValidationFunctionResult<OUT, ERR>;
|
|
18
|
+
export type ValidationFunctionResult<OUT, ERR extends AppError> = [err: ERR | null, output: OUT];
|
|
19
19
|
export interface ValidationFunctionOptions {
|
|
20
20
|
/**
|
|
21
21
|
* Defaults to undefined.
|
|
@@ -12,7 +12,6 @@ declare function unixTimestampMillis(): ZodBranded<z.ZodNumber, UnixTimestampMil
|
|
|
12
12
|
declare function unixTimestampMillis2000(): ZodBrandedInt<UnixTimestampMillis>;
|
|
13
13
|
declare function semVer(): z.ZodString;
|
|
14
14
|
declare function isoDate(): ZodBrandedString<IsoDate>;
|
|
15
|
-
declare function email(): z.ZodEmail;
|
|
16
15
|
declare function base62(): z.ZodString;
|
|
17
16
|
declare function base64(): z.ZodString;
|
|
18
17
|
declare function base64Url(): z.ZodString;
|
|
@@ -34,7 +33,6 @@ export declare const customZodSchemas: {
|
|
|
34
33
|
base64: typeof base64;
|
|
35
34
|
base64Url: typeof base64Url;
|
|
36
35
|
dbEntity: typeof dbEntity;
|
|
37
|
-
email: typeof email;
|
|
38
36
|
ianaTimezone: typeof ianaTimezone;
|
|
39
37
|
isoDate: typeof isoDate;
|
|
40
38
|
jwt: typeof jwt;
|
|
@@ -45,9 +45,6 @@ function isoDate() {
|
|
|
45
45
|
.regex(/^\d{4}-\d{2}-\d{2}$/, { error: 'Must be a YYYY-MM-DD string' })
|
|
46
46
|
.describe('IsoDate');
|
|
47
47
|
}
|
|
48
|
-
function email() {
|
|
49
|
-
return z.email().describe('Email');
|
|
50
|
-
}
|
|
51
48
|
const BASE62_REGEX = /^[a-zA-Z0-9]+$/;
|
|
52
49
|
const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
53
50
|
const BASE64URL_REGEX = /^[\w\-/]+$/;
|
|
@@ -92,7 +89,6 @@ export const customZodSchemas = {
|
|
|
92
89
|
base64,
|
|
93
90
|
base64Url,
|
|
94
91
|
dbEntity,
|
|
95
|
-
email,
|
|
96
92
|
ianaTimezone,
|
|
97
93
|
isoDate,
|
|
98
94
|
jwt,
|
package/dist/zod/zod.util.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { ZodError, ZodType } from 'zod';
|
|
|
2
2
|
import type { ErrorData } from '../error/error.model.js';
|
|
3
3
|
import { AppError } from '../error/error.util.js';
|
|
4
4
|
import type { ValidationFunction, ValidationFunctionResult } from '../validation/validation.js';
|
|
5
|
-
export declare function getZodValidationFunction<T>(schema: ZodType<T>): ValidationFunction<T, ZodValidationError>;
|
|
5
|
+
export declare function getZodValidationFunction<T>(schema: ZodType<T>): ValidationFunction<T, T, ZodValidationError>;
|
|
6
6
|
export declare function zIsValid<T>(value: T, schema: ZodType<T>): boolean;
|
|
7
7
|
export declare function zValidate<T>(value: T, schema: ZodType<T>): T;
|
|
8
8
|
export declare function zSafeValidate<T>(input: T, schema: ZodType<T>): ValidationFunctionResult<T, ZodValidationError>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.45.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"undici": "^7",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@types/semver": "^7",
|
|
14
14
|
"crypto-js": "^4",
|
|
15
15
|
"dayjs": "^1",
|
|
16
|
-
"@naturalcycles/dev-lib": "
|
|
16
|
+
"@naturalcycles/dev-lib": "18.4.2"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./dist/index.js",
|
|
@@ -15,12 +15,12 @@ import type { AppError } from '../error/error.util.js'
|
|
|
15
15
|
*
|
|
16
16
|
* @experimental
|
|
17
17
|
*/
|
|
18
|
-
export type ValidationFunction<
|
|
19
|
-
input:
|
|
18
|
+
export type ValidationFunction<IN, OUT, ERR extends AppError> = (
|
|
19
|
+
input: IN,
|
|
20
20
|
opt?: ValidationFunctionOptions,
|
|
21
|
-
) => ValidationFunctionResult<
|
|
21
|
+
) => ValidationFunctionResult<OUT, ERR>
|
|
22
22
|
|
|
23
|
-
export type ValidationFunctionResult<
|
|
23
|
+
export type ValidationFunctionResult<OUT, ERR extends AppError> = [err: ERR | null, output: OUT]
|
|
24
24
|
|
|
25
25
|
export interface ValidationFunctionOptions {
|
|
26
26
|
/**
|
|
@@ -61,10 +61,6 @@ function isoDate(): ZodBrandedString<IsoDate> {
|
|
|
61
61
|
.describe('IsoDate') as ZodBrandedString<IsoDate>
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
function email(): z.ZodEmail {
|
|
65
|
-
return z.email().describe('Email')
|
|
66
|
-
}
|
|
67
|
-
|
|
68
64
|
const BASE62_REGEX = /^[a-zA-Z0-9]+$/
|
|
69
65
|
const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/
|
|
70
66
|
const BASE64URL_REGEX = /^[\w\-/]+$/
|
|
@@ -131,7 +127,6 @@ export const customZodSchemas = {
|
|
|
131
127
|
base64,
|
|
132
128
|
base64Url,
|
|
133
129
|
dbEntity,
|
|
134
|
-
email,
|
|
135
130
|
ianaTimezone,
|
|
136
131
|
isoDate,
|
|
137
132
|
jwt,
|
package/src/zod/zod.util.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { ValidationFunction, ValidationFunctionResult } from '../validation
|
|
|
7
7
|
|
|
8
8
|
export function getZodValidationFunction<T>(
|
|
9
9
|
schema: ZodType<T>,
|
|
10
|
-
): ValidationFunction<T, ZodValidationError> {
|
|
10
|
+
): ValidationFunction<T, T, ZodValidationError> {
|
|
11
11
|
return (input, opt) => {
|
|
12
12
|
_assert(!opt?.mutateInput, 'mutateInput=true is not yet supported with Zod')
|
|
13
13
|
return zSafeValidate(input, schema)
|