@better-giving/schemas 1.2.0 → 1.2.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/index.d.mts +19 -11
- package/dist/index.mjs +29 -14
- package/package.json +1 -1
- package/src/index.mts +49 -18
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { type InferOutput } from "valibot";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const file_obj: import("valibot").ObjectSchema<{
|
|
3
3
|
readonly name: import("valibot").StringSchema<undefined>;
|
|
4
4
|
readonly publicUrl: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").UrlAction<string, undefined>]>;
|
|
5
5
|
}, undefined>;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export type OrgDesignation = InferOutput<typeof
|
|
9
|
-
export interface FileObject extends InferOutput<typeof
|
|
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"], undefined>;
|
|
8
|
+
export type OrgDesignation = InferOutput<typeof org_designation>;
|
|
9
|
+
export interface FileObject extends InferOutput<typeof file_obj> {
|
|
10
10
|
}
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export type UnSdgNum = InferOutput<typeof
|
|
11
|
+
export declare const unsdg_nums: readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17];
|
|
12
|
+
export declare const unsdg_num: import("valibot").PicklistSchema<readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], undefined>;
|
|
13
|
+
export type UnSdgNum = InferOutput<typeof unsdg_num>;
|
|
14
14
|
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
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export type DonateMethodId = InferOutput<typeof
|
|
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"], undefined>;
|
|
19
|
+
export type DonateMethodId = InferOutput<typeof donate_method_id>;
|
|
20
|
+
export declare const $: import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>;
|
|
21
|
+
export declare const $req: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>;
|
|
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<undefined>, 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 $req_num_gt0: import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").NumberSchema<"invalid number">, import("valibot").MinValueAction<number, 0, "must be > 0">, import("valibot").TransformAction<number, string>]>;
|
|
25
|
+
export declare const $num_gt0_fn: ({ required, }?: {
|
|
26
|
+
required?: boolean;
|
|
27
|
+
}) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]>, import("valibot").TransformAction<string, number>, import("valibot").NumberSchema<"invalid number">, import("valibot").MinValueAction<number, 0, "must be > 0">, import("valibot").TransformAction<number, string>]>>;
|
|
20
28
|
export declare const https_url: (non_empty: boolean) => import("valibot").LazySchema<import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").NonEmptyAction<string, "required">]> | import("valibot").SchemaWithPipe<[import("valibot").SchemaWithPipe<[import("valibot").StringSchema<undefined>, import("valibot").TrimAction]>, import("valibot").TransformAction<string, string>, import("valibot").UrlAction<string, "invalid url">]>>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
import { url, object, picklist, pipe, string,
|
|
2
|
-
export const
|
|
1
|
+
import { url, lazy, nonEmpty, object, picklist, pipe, string, transform, trim, number, minValue, integer, } from "valibot";
|
|
2
|
+
export const file_obj = object({
|
|
3
3
|
name: string(),
|
|
4
4
|
publicUrl: pipe(string(), url()),
|
|
5
5
|
});
|
|
6
|
-
export const
|
|
6
|
+
export const org_designations = [
|
|
7
7
|
"Charity",
|
|
8
8
|
"Religious Organization",
|
|
9
9
|
"University",
|
|
10
10
|
"Hospital",
|
|
11
11
|
"Other",
|
|
12
12
|
];
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
13
|
+
export const org_designation = picklist(org_designations);
|
|
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
|
];
|
|
17
|
-
export const
|
|
17
|
+
export const unsdg_num = picklist(unsdg_nums);
|
|
18
18
|
export const envs = ["staging", "production"];
|
|
19
19
|
export const env = picklist(envs);
|
|
20
|
-
export const
|
|
21
|
-
export const
|
|
22
|
-
const
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
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());
|
|
23
|
+
export const $req = pipe($, nonEmpty("required"));
|
|
24
|
+
export const int_gte1 = pipe(number(), integer(), minValue(1));
|
|
25
|
+
export const $int_gte1 = pipe($, transform((x) => +x), int_gte1);
|
|
26
|
+
export const $req_num_gt0 = pipe($req, transform((x) => +x), number("invalid number"), minValue(0, "must be > 0"), transform((x) => x.toString()));
|
|
27
|
+
export const $num_gt0_fn = ({ required = false, } = {}) => {
|
|
28
|
+
return lazy((x) => {
|
|
29
|
+
if (!x && required)
|
|
30
|
+
return $req;
|
|
31
|
+
if (!x)
|
|
32
|
+
return $;
|
|
33
|
+
return $req_num_gt0;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export const https_url = (non_empty) => {
|
|
37
|
+
return lazy((x) => {
|
|
38
|
+
if (!x)
|
|
39
|
+
return non_empty ? $req : $;
|
|
40
|
+
return pipe($, transform((x) => (x.startsWith("https://") ? x : `https://${x}`)), url("invalid url"));
|
|
41
|
+
});
|
|
42
|
+
};
|
package/package.json
CHANGED
package/src/index.mts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
url,
|
|
3
3
|
type InferOutput,
|
|
4
|
+
lazy,
|
|
5
|
+
nonEmpty,
|
|
4
6
|
object,
|
|
5
7
|
picklist,
|
|
6
8
|
pipe,
|
|
7
9
|
string,
|
|
8
|
-
lazy,
|
|
9
10
|
transform,
|
|
10
11
|
trim,
|
|
11
|
-
|
|
12
|
+
number,
|
|
13
|
+
minValue,
|
|
14
|
+
integer,
|
|
12
15
|
} from "valibot";
|
|
13
16
|
|
|
14
|
-
export const
|
|
17
|
+
export const file_obj = object({
|
|
15
18
|
name: string(),
|
|
16
19
|
publicUrl: pipe(string(), url()),
|
|
17
20
|
});
|
|
18
21
|
|
|
19
|
-
export const
|
|
22
|
+
export const org_designations = [
|
|
20
23
|
"Charity",
|
|
21
24
|
"Religious Organization",
|
|
22
25
|
"University",
|
|
@@ -24,33 +27,61 @@ export const orgDesignations = [
|
|
|
24
27
|
"Other",
|
|
25
28
|
] as const;
|
|
26
29
|
|
|
27
|
-
export const
|
|
28
|
-
export type OrgDesignation = InferOutput<typeof
|
|
30
|
+
export const org_designation = picklist(org_designations);
|
|
31
|
+
export type OrgDesignation = InferOutput<typeof org_designation>;
|
|
29
32
|
|
|
30
|
-
export interface FileObject extends InferOutput<typeof
|
|
33
|
+
export interface FileObject extends InferOutput<typeof file_obj> {}
|
|
31
34
|
|
|
32
|
-
export const
|
|
35
|
+
export const unsdg_nums = [
|
|
33
36
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
|
34
37
|
] as const;
|
|
35
38
|
|
|
36
|
-
export const
|
|
37
|
-
export type UnSdgNum = InferOutput<typeof
|
|
39
|
+
export const unsdg_num = picklist(unsdg_nums);
|
|
40
|
+
export type UnSdgNum = InferOutput<typeof unsdg_num>;
|
|
38
41
|
|
|
39
42
|
export const envs = ["staging", "production"] as const;
|
|
40
43
|
export const env = picklist(envs);
|
|
41
44
|
export type Environment = InferOutput<typeof env>;
|
|
42
45
|
|
|
43
|
-
export const
|
|
44
|
-
export const
|
|
45
|
-
export type DonateMethodId = InferOutput<typeof
|
|
46
|
+
export const donate_method_ids = ["stripe", "crypto", "daf", "stocks"] as const;
|
|
47
|
+
export const donate_method_id = picklist(donate_method_ids);
|
|
48
|
+
export type DonateMethodId = InferOutput<typeof donate_method_id>;
|
|
49
|
+
|
|
50
|
+
export const $ = pipe(string(), trim());
|
|
51
|
+
export const $req = pipe($, nonEmpty("required"));
|
|
52
|
+
|
|
53
|
+
export const int_gte1 = pipe(number(), integer(), minValue(1));
|
|
54
|
+
export const $int_gte1 = pipe(
|
|
55
|
+
$,
|
|
56
|
+
transform((x) => +x),
|
|
57
|
+
int_gte1
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export const $req_num_gt0 = pipe(
|
|
61
|
+
$req,
|
|
62
|
+
transform((x) => +x),
|
|
63
|
+
number("invalid number"),
|
|
64
|
+
minValue(0, "must be > 0"),
|
|
65
|
+
transform((x) => x.toString())
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const $num_gt0_fn = ({
|
|
69
|
+
required = false,
|
|
70
|
+
}: { required?: boolean } = {}) => {
|
|
71
|
+
return lazy((x) => {
|
|
72
|
+
if (!x && required) return $req;
|
|
73
|
+
if (!x) return $;
|
|
74
|
+
return $req_num_gt0;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
46
77
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!x) return non_empty ? pipe(str, nonEmpty("required")) : str;
|
|
78
|
+
export const https_url = (non_empty: boolean) => {
|
|
79
|
+
return lazy((x) => {
|
|
80
|
+
if (!x) return non_empty ? $req : $;
|
|
51
81
|
return pipe(
|
|
52
|
-
|
|
82
|
+
$,
|
|
53
83
|
transform((x) => (x.startsWith("https://") ? x : `https://${x}`)),
|
|
54
84
|
url("invalid url")
|
|
55
85
|
);
|
|
56
86
|
});
|
|
87
|
+
};
|