@naturalcycles/js-lib 15.22.1 → 15.24.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.
|
@@ -18,8 +18,13 @@ export type ValidationFunction<T, ERR extends AppError> = (input: T, opt?: Valid
|
|
|
18
18
|
export type ValidationFunctionResult<T, ERR extends AppError> = [err: ERR | null, output: T];
|
|
19
19
|
export interface ValidationFunctionOptions {
|
|
20
20
|
/**
|
|
21
|
-
* Defaults to
|
|
22
|
-
*
|
|
21
|
+
* Defaults to undefined.
|
|
22
|
+
*
|
|
23
|
+
* Undefined means that it's up for the underlying validation library (implementation)
|
|
24
|
+
* to mutate or not.
|
|
25
|
+
* E.g joi and zod would deep-clone, while ajv would mutate.
|
|
26
|
+
*
|
|
27
|
+
* False means that the ValidationFunction IS NOT ALLOWED to mutate the input.
|
|
23
28
|
* If set to true - the ValidationFunction HAS TO mutate the input
|
|
24
29
|
* if it needs to apply transformations, such as:
|
|
25
30
|
* - stripping unknown properties
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodString } from 'zod';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js';
|
|
3
|
+
import type { IANATimezone, IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js';
|
|
4
4
|
type ZodBranded<T, B> = T & Record<'_zod', Record<'output', number & B>>;
|
|
5
5
|
export type ZodBrandedString<B> = ZodBranded<z.ZodString, B>;
|
|
6
6
|
export type ZodBrandedInt<B> = ZodBranded<z.ZodInt, B>;
|
|
@@ -20,7 +20,7 @@ declare function jwt(): z.ZodString;
|
|
|
20
20
|
* "Slug" - a valid URL, filename, etc.
|
|
21
21
|
*/
|
|
22
22
|
declare function slug(): z.ZodString;
|
|
23
|
-
declare function ianaTimezone():
|
|
23
|
+
declare function ianaTimezone(): ZodBrandedString<IANATimezone>;
|
|
24
24
|
type BaseDBEntityZodShape = {
|
|
25
25
|
id: ZodString;
|
|
26
26
|
created: ZodBrandedInt<UnixTimestamp>;
|
|
@@ -76,9 +76,10 @@ function slug() {
|
|
|
76
76
|
.describe('Slug');
|
|
77
77
|
}
|
|
78
78
|
function ianaTimezone() {
|
|
79
|
-
return
|
|
79
|
+
return z
|
|
80
80
|
// UTC is added to assist unit-testing, which uses UTC by default (not technically a valid Iana timezone identifier)
|
|
81
|
-
.enum([...Intl.supportedValuesOf('timeZone'), 'UTC'])
|
|
81
|
+
.enum([...Intl.supportedValuesOf('timeZone'), 'UTC'])
|
|
82
|
+
.describe('IANATimezone');
|
|
82
83
|
}
|
|
83
84
|
const baseDBEntitySchema = z.object({
|
|
84
85
|
id: z.string(),
|
package/package.json
CHANGED
|
@@ -24,8 +24,13 @@ export type ValidationFunctionResult<T, ERR extends AppError> = [err: ERR | null
|
|
|
24
24
|
|
|
25
25
|
export interface ValidationFunctionOptions {
|
|
26
26
|
/**
|
|
27
|
-
* Defaults to
|
|
28
|
-
*
|
|
27
|
+
* Defaults to undefined.
|
|
28
|
+
*
|
|
29
|
+
* Undefined means that it's up for the underlying validation library (implementation)
|
|
30
|
+
* to mutate or not.
|
|
31
|
+
* E.g joi and zod would deep-clone, while ajv would mutate.
|
|
32
|
+
*
|
|
33
|
+
* False means that the ValidationFunction IS NOT ALLOWED to mutate the input.
|
|
29
34
|
* If set to true - the ValidationFunction HAS TO mutate the input
|
|
30
35
|
* if it needs to apply transformations, such as:
|
|
31
36
|
* - stripping unknown properties
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodString } from 'zod'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
-
import type { IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js'
|
|
3
|
+
import type { IANATimezone, IsoDate, UnixTimestamp, UnixTimestampMillis } from '../types.js'
|
|
4
4
|
|
|
5
5
|
type ZodBranded<T, B> = T & Record<'_zod', Record<'output', number & B>>
|
|
6
6
|
export type ZodBrandedString<B> = ZodBranded<z.ZodString, B>
|
|
@@ -98,11 +98,12 @@ function slug(): z.ZodString {
|
|
|
98
98
|
.describe('Slug')
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function ianaTimezone():
|
|
101
|
+
function ianaTimezone(): ZodBrandedString<IANATimezone> {
|
|
102
102
|
return (
|
|
103
103
|
z
|
|
104
104
|
// UTC is added to assist unit-testing, which uses UTC by default (not technically a valid Iana timezone identifier)
|
|
105
105
|
.enum([...Intl.supportedValuesOf('timeZone'), 'UTC'])
|
|
106
|
+
.describe('IANATimezone') as unknown as ZodBrandedString<IANATimezone>
|
|
106
107
|
)
|
|
107
108
|
}
|
|
108
109
|
|