@better-giving/schemas 2.0.0 → 2.0.2
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/date.d.mts +4 -0
- package/dist/date.mjs +11 -0
- package/dist/index.d.mts +13 -10
- package/dist/index.mjs +7 -6
- package/package.json +3 -2
- package/src/date.mts +20 -0
- package/src/index.mts +8 -7
package/dist/date.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { endOfDay } from "date-fns";
|
|
2
|
+
export { startOfDay, endOfDay } from "date-fns";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
export declare const iso_date: (formatter: typeof endOfDay, required?: "required") => v.LazySchema<v.StringSchema<undefined> | v.SchemaWithPipe<[v.StringSchema<undefined>, v.NonEmptyAction<string, "required">]> | v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, Date>, v.DateSchema<"invalid date">, v.MaxValueAction<Date, Date, "can't be later than today">, v.TransformAction<Date, string>]>>;
|
package/dist/date.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { endOfDay } from "date-fns";
|
|
2
|
+
export { startOfDay, endOfDay } from "date-fns";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
export const iso_date = (formatter, required) => v.lazy((x) => {
|
|
5
|
+
if (!x) {
|
|
6
|
+
return required === "required"
|
|
7
|
+
? v.pipe(v.string(), v.nonEmpty("required"))
|
|
8
|
+
: v.string();
|
|
9
|
+
}
|
|
10
|
+
return v.pipe(v.string(), v.transform((v) => new Date(v)), v.date("invalid date"), v.maxValue(endOfDay(new Date()), "can't be later than today"), v.transform((x) => formatter(x).toISOString()));
|
|
11
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const file_obj: import("valibot").ObjectSchema<{
|
|
|
4
4
|
readonly publicUrl: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UrlAction<string, undefined>]>;
|
|
5
5
|
}, undefined>;
|
|
6
6
|
export declare const org_designations: readonly ["Charity", "Religious Organization", "University", "Hospital", "Other"];
|
|
7
|
-
export declare const org_designation: import("valibot").PicklistSchema<readonly ["Charity", "Religious Organization", "University", "Hospital", "Other"],
|
|
7
|
+
export declare const org_designation: import("valibot").PicklistSchema<readonly ["Charity", "Religious Organization", "University", "Hospital", "Other"], "required">;
|
|
8
8
|
export type OrgDesignation = InferOutput<typeof org_designation>;
|
|
9
9
|
export interface FileObject extends InferOutput<typeof file_obj> {
|
|
10
10
|
}
|
|
@@ -15,17 +15,20 @@ export declare const envs: readonly ["staging", "production"];
|
|
|
15
15
|
export declare const env: import("valibot").PicklistSchema<readonly ["staging", "production"], undefined>;
|
|
16
16
|
export type Environment = InferOutput<typeof env>;
|
|
17
17
|
export declare const donate_method_ids: readonly ["stripe", "crypto", "daf", "stocks"];
|
|
18
|
-
export declare const donate_method_id: import("valibot").PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"],
|
|
18
|
+
export declare const donate_method_id: import("valibot").PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], "required">;
|
|
19
19
|
export type DonateMethodId = InferOutput<typeof donate_method_id>;
|
|
20
|
-
export declare const $: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
21
|
-
export declare const $req: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
20
|
+
export declare const $: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>;
|
|
21
|
+
export declare const $req: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>;
|
|
22
22
|
export declare const int_gte1: import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").IntegerAction<number, undefined>, import("valibot").MinValueAction<number, 1, undefined>]>;
|
|
23
|
-
export declare const $int_gte1: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
24
|
-
export declare const
|
|
23
|
+
export declare const $int_gte1: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<"required">, import("valibot").TrimAction]>, import("valibot").TransformAction<string, number>, import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").IntegerAction<number, undefined>, import("valibot").MinValueAction<number, 1, undefined>]>]>;
|
|
24
|
+
export declare const num_gt0: import("valibot").SchemaWithPipe<[import("valibot").NumberSchema<undefined>, import("valibot").MinValueAction<number, 0, "must be > 0">]>;
|
|
25
|
+
export declare const $req_num_gt0: 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>]>;
|
|
25
26
|
export declare const $num_gt0_fn: ({ required, }?: {
|
|
26
27
|
required?: boolean;
|
|
27
|
-
}) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
28
|
-
export declare const https_url: (
|
|
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: ({ required }: {
|
|
30
|
+
required?: boolean | undefined;
|
|
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">]>>;
|
|
29
32
|
export declare const segment_max_chars = 30;
|
|
30
|
-
export declare const segment: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
31
|
-
export declare const slug: import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<
|
|
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
|
+
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">]>>;
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export const org_designations = [
|
|
|
10
10
|
"Hospital",
|
|
11
11
|
"Other",
|
|
12
12
|
];
|
|
13
|
-
export const org_designation = picklist(org_designations);
|
|
13
|
+
export const org_designation = picklist(org_designations, "required");
|
|
14
14
|
export const unsdg_nums = [
|
|
15
15
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
|
16
16
|
];
|
|
@@ -18,12 +18,13 @@ export const unsdg_num = picklist(unsdg_nums);
|
|
|
18
18
|
export const envs = ["staging", "production"];
|
|
19
19
|
export const env = picklist(envs);
|
|
20
20
|
export const donate_method_ids = ["stripe", "crypto", "daf", "stocks"];
|
|
21
|
-
export const donate_method_id = picklist(donate_method_ids);
|
|
22
|
-
export const $ = pipe(string(), trim());
|
|
21
|
+
export const donate_method_id = picklist(donate_method_ids, "required");
|
|
22
|
+
export const $ = pipe(string("required"), trim());
|
|
23
23
|
export const $req = pipe($, nonEmpty("required"));
|
|
24
24
|
export const int_gte1 = pipe(number(), integer(), minValue(1));
|
|
25
25
|
export const $int_gte1 = pipe($, transform((x) => +x), int_gte1);
|
|
26
|
-
export const
|
|
26
|
+
export const num_gt0 = pipe(number(), minValue(0, "must be > 0"));
|
|
27
|
+
export const $req_num_gt0 = pipe($req, transform((x) => +x), num_gt0, transform((x) => x.toString()));
|
|
27
28
|
export const $num_gt0_fn = ({ required = false, } = {}) => {
|
|
28
29
|
return lazy((x) => {
|
|
29
30
|
if (!x && required)
|
|
@@ -33,10 +34,10 @@ export const $num_gt0_fn = ({ required = false, } = {}) => {
|
|
|
33
34
|
return $req_num_gt0;
|
|
34
35
|
});
|
|
35
36
|
};
|
|
36
|
-
export const https_url = (
|
|
37
|
+
export const https_url = ({ required = false }) => {
|
|
37
38
|
return lazy((x) => {
|
|
38
39
|
if (!x)
|
|
39
|
-
return
|
|
40
|
+
return required ? $req : $;
|
|
40
41
|
return pipe($, transform((x) => (x.startsWith("https://") ? x : `https://${x}`)), url("invalid url"));
|
|
41
42
|
});
|
|
42
43
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-giving/schemas",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@better-giving/config": "1.1.2"
|
|
6
6
|
},
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"valibot": "0.42.0"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
|
-
".": "./dist/index.mjs"
|
|
15
|
+
".": "./dist/index.mjs",
|
|
16
|
+
"./*": "./dist/*.mjs"
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
18
19
|
"build": "tsc --outDir dist"
|
package/src/date.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { endOfDay } from "date-fns";
|
|
2
|
+
export { startOfDay, endOfDay } from "date-fns";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
|
|
5
|
+
export const iso_date = (formatter: typeof endOfDay, required?: "required") =>
|
|
6
|
+
v.lazy((x) => {
|
|
7
|
+
if (!x) {
|
|
8
|
+
return required === "required"
|
|
9
|
+
? v.pipe(v.string(), v.nonEmpty("required"))
|
|
10
|
+
: v.string();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return v.pipe(
|
|
14
|
+
v.string(),
|
|
15
|
+
v.transform((v) => new Date(v)),
|
|
16
|
+
v.date("invalid date"),
|
|
17
|
+
v.maxValue(endOfDay(new Date()), "can't be later than today"),
|
|
18
|
+
v.transform((x) => formatter(x).toISOString())
|
|
19
|
+
);
|
|
20
|
+
});
|
package/src/index.mts
CHANGED
|
@@ -31,7 +31,7 @@ export const org_designations = [
|
|
|
31
31
|
"Other",
|
|
32
32
|
] as const;
|
|
33
33
|
|
|
34
|
-
export const org_designation = picklist(org_designations);
|
|
34
|
+
export const org_designation = picklist(org_designations, "required");
|
|
35
35
|
export type OrgDesignation = InferOutput<typeof org_designation>;
|
|
36
36
|
|
|
37
37
|
export interface FileObject extends InferOutput<typeof file_obj> {}
|
|
@@ -48,10 +48,10 @@ export const env = picklist(envs);
|
|
|
48
48
|
export type Environment = InferOutput<typeof env>;
|
|
49
49
|
|
|
50
50
|
export const donate_method_ids = ["stripe", "crypto", "daf", "stocks"] as const;
|
|
51
|
-
export const donate_method_id = picklist(donate_method_ids);
|
|
51
|
+
export const donate_method_id = picklist(donate_method_ids, "required");
|
|
52
52
|
export type DonateMethodId = InferOutput<typeof donate_method_id>;
|
|
53
53
|
|
|
54
|
-
export const $ = pipe(string(), trim());
|
|
54
|
+
export const $ = pipe(string("required"), trim());
|
|
55
55
|
export const $req = pipe($, nonEmpty("required"));
|
|
56
56
|
|
|
57
57
|
export const int_gte1 = pipe(number(), integer(), minValue(1));
|
|
@@ -61,11 +61,12 @@ export const $int_gte1 = pipe(
|
|
|
61
61
|
int_gte1
|
|
62
62
|
);
|
|
63
63
|
|
|
64
|
+
export const num_gt0 = pipe(number(), minValue(0, "must be > 0"));
|
|
65
|
+
|
|
64
66
|
export const $req_num_gt0 = pipe(
|
|
65
67
|
$req,
|
|
66
68
|
transform((x) => +x),
|
|
67
|
-
|
|
68
|
-
minValue(0, "must be > 0"),
|
|
69
|
+
num_gt0,
|
|
69
70
|
transform((x) => x.toString())
|
|
70
71
|
);
|
|
71
72
|
|
|
@@ -79,9 +80,9 @@ export const $num_gt0_fn = ({
|
|
|
79
80
|
});
|
|
80
81
|
};
|
|
81
82
|
|
|
82
|
-
export const https_url = (
|
|
83
|
+
export const https_url = ({ required = false }) => {
|
|
83
84
|
return lazy((x) => {
|
|
84
|
-
if (!x) return
|
|
85
|
+
if (!x) return required ? $req : $;
|
|
85
86
|
return pipe(
|
|
86
87
|
$,
|
|
87
88
|
transform((x) => (x.startsWith("https://") ? x : `https://${x}`)),
|