@better-giving/schemas 2.0.2 → 2.0.4
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/index.d.mts +13 -2
- package/dist/index.mjs +18 -3
- package/package.json +4 -1
- package/src/index.mts +40 -2
package/dist/index.d.mts
CHANGED
|
@@ -26,9 +26,20 @@ export declare const $req_num_gt0: import("valibot").SchemaWithPipe<[import("val
|
|
|
26
26
|
export declare const $num_gt0_fn: ({ required, }?: {
|
|
27
27
|
required?: boolean;
|
|
28
28
|
}) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>>;
|
|
29
|
-
export declare const https_url: (
|
|
30
|
-
required?: boolean
|
|
29
|
+
export declare const https_url: (opts?: {
|
|
30
|
+
required?: boolean;
|
|
31
31
|
}) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").TransformAction<string, string>, import("valibot").UrlAction<string, "invalid url">]>>;
|
|
32
32
|
export declare const segment_max_chars = 30;
|
|
33
33
|
export declare const segment: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 30, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 30>) => string>, import("valibot").RegexAction<string, "should not be an id">, import("valibot").RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, import("valibot").ExcludesAction<string, "..", "should not contain double periods">, import("valibot").CustomSchema<string, "should not start with dot">, import("valibot").CustomSchema<string, "should not end with dot">]>;
|
|
34
34
|
export declare const slug: import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 30, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 30>) => string>, import("valibot").RegexAction<string, "should not be an id">, import("valibot").RegexAction<string, "allowed: numbers | letters | - | . | _ | ~">, import("valibot").ExcludesAction<string, "..", "should not contain double periods">, import("valibot").CustomSchema<string, "should not start with dot">, import("valibot").CustomSchema<string, "should not end with dot">]>>;
|
|
35
|
+
export declare const increment_label_max_chars = 60;
|
|
36
|
+
export declare const MAX_NUM_INCREMENTS = 4;
|
|
37
|
+
export declare const increment_label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
|
|
38
|
+
export declare const increment_val: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
|
|
39
|
+
export declare const increment: import("valibot").ObjectSchema<{
|
|
40
|
+
readonly value: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>, import("valibot").TransformAction<number, string>]>, import("valibot").TransformAction<string, string>]>;
|
|
41
|
+
readonly label: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").MaxLengthAction<string, 60, ({ requirement: r }: import("valibot").MaxLengthIssue<string, 60>) => string>]>;
|
|
42
|
+
}, undefined>;
|
|
43
|
+
export interface IIncrement extends InferOutput<typeof increment> {
|
|
44
|
+
}
|
|
45
|
+
export declare const target: import("valibot").UnionSchema<[import("valibot").LiteralSchema<"smart", undefined>, import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TransformAction<string, number>, import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, undefined>, import("valibot").TransformAction<number, string>]>], undefined>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { url, custom, excludes, integer, lazy, maxLength, minValue, nonEmpty, number, object, picklist, pipe, regex, string, transform, trim, } from "valibot";
|
|
1
|
+
import { url, custom, excludes, integer, lazy, maxLength, minValue, nonEmpty, number, object, picklist, pipe, regex, string, transform, trim, union, literal, } from "valibot";
|
|
2
2
|
export const file_obj = object({
|
|
3
3
|
name: string(),
|
|
4
4
|
publicUrl: pipe(string(), url()),
|
|
@@ -34,10 +34,10 @@ export const $num_gt0_fn = ({ required = false, } = {}) => {
|
|
|
34
34
|
return $req_num_gt0;
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
export const https_url = (
|
|
37
|
+
export const https_url = (opts) => {
|
|
38
38
|
return lazy((x) => {
|
|
39
39
|
if (!x)
|
|
40
|
-
return required ? $req : $;
|
|
40
|
+
return (opts?.required ?? false) ? $req : $;
|
|
41
41
|
return pipe($, transform((x) => (x.startsWith("https://") ? x : `https://${x}`)), url("invalid url"));
|
|
42
42
|
});
|
|
43
43
|
};
|
|
@@ -48,3 +48,18 @@ regex(/^(?!^\d+$)/, "should not be an id"),
|
|
|
48
48
|
//valid characters
|
|
49
49
|
regex(/^[a-zA-Z0-9-._~]+$/, "allowed: numbers | letters | - | . | _ | ~"), excludes("..", "should not contain double periods"), custom((x) => !x.startsWith("."), "should not start with dot"), custom((x) => !x.endsWith("."), "should not end with dot"));
|
|
50
50
|
export const slug = lazy((x) => (x ? segment : $));
|
|
51
|
+
export const increment_label_max_chars = 60;
|
|
52
|
+
export const MAX_NUM_INCREMENTS = 4;
|
|
53
|
+
export const increment_label = pipe($, maxLength(increment_label_max_chars, ({ requirement: r }) => `cannot exceed ${r} characters`));
|
|
54
|
+
export const increment_val = pipe($req_num_gt0,
|
|
55
|
+
//parsed output
|
|
56
|
+
transform((x) => x.toString()));
|
|
57
|
+
export const increment = object({
|
|
58
|
+
value: increment_val,
|
|
59
|
+
label: increment_label,
|
|
60
|
+
});
|
|
61
|
+
export const target = union([
|
|
62
|
+
literal("smart"),
|
|
63
|
+
// "0" - none, `${number}` - fixed
|
|
64
|
+
pipe(string(), transform((v) => +v), number(), minValue(0), transform((v) => v.toString())),
|
|
65
|
+
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-giving/schemas",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@better-giving/config": "1.1.2"
|
|
6
6
|
},
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"peerDependencies": {
|
|
12
12
|
"valibot": "0.42.0"
|
|
13
13
|
},
|
|
14
|
+
"optionalDependencies": {
|
|
15
|
+
"date-fns": "4.1.0"
|
|
16
|
+
},
|
|
14
17
|
"exports": {
|
|
15
18
|
".": "./dist/index.mjs",
|
|
16
19
|
"./*": "./dist/*.mjs"
|
package/src/index.mts
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
string,
|
|
17
17
|
transform,
|
|
18
18
|
trim,
|
|
19
|
+
union,
|
|
20
|
+
literal,
|
|
19
21
|
} from "valibot";
|
|
20
22
|
|
|
21
23
|
export const file_obj = object({
|
|
@@ -80,9 +82,9 @@ export const $num_gt0_fn = ({
|
|
|
80
82
|
});
|
|
81
83
|
};
|
|
82
84
|
|
|
83
|
-
export const https_url = ({ required
|
|
85
|
+
export const https_url = (opts?: { required?: boolean }) => {
|
|
84
86
|
return lazy((x) => {
|
|
85
|
-
if (!x) return required ? $req : $;
|
|
87
|
+
if (!x) return (opts?.required ?? false) ? $req : $;
|
|
86
88
|
return pipe(
|
|
87
89
|
$,
|
|
88
90
|
transform((x) => (x.startsWith("https://") ? x : `https://${x}`)),
|
|
@@ -108,3 +110,39 @@ export const segment = pipe(
|
|
|
108
110
|
);
|
|
109
111
|
|
|
110
112
|
export const slug = lazy((x) => (x ? segment : $));
|
|
113
|
+
|
|
114
|
+
export const increment_label_max_chars = 60;
|
|
115
|
+
export const MAX_NUM_INCREMENTS = 4;
|
|
116
|
+
|
|
117
|
+
export const increment_label = pipe(
|
|
118
|
+
$,
|
|
119
|
+
maxLength(
|
|
120
|
+
increment_label_max_chars,
|
|
121
|
+
({ requirement: r }) => `cannot exceed ${r} characters`
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export const increment_val = pipe(
|
|
126
|
+
$req_num_gt0,
|
|
127
|
+
//parsed output
|
|
128
|
+
transform((x) => x.toString())
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
export const increment = object({
|
|
132
|
+
value: increment_val,
|
|
133
|
+
label: increment_label,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export interface IIncrement extends InferOutput<typeof increment> {}
|
|
137
|
+
|
|
138
|
+
export const target = union([
|
|
139
|
+
literal("smart"),
|
|
140
|
+
// "0" - none, `${number}` - fixed
|
|
141
|
+
pipe(
|
|
142
|
+
string(),
|
|
143
|
+
transform((v) => +v),
|
|
144
|
+
number(),
|
|
145
|
+
minValue(0),
|
|
146
|
+
transform((v) => v.toString())
|
|
147
|
+
),
|
|
148
|
+
]);
|