@better-giving/schemas 1.1.3 → 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 CHANGED
@@ -1,20 +1,28 @@
1
1
  import { type InferOutput } from "valibot";
2
- export declare const fileObject: import("valibot").ObjectSchema<{
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 orgDesignations: readonly ["Charity", "Religious Organization", "University", "Hospital", "Other"];
7
- export declare const orgDesignation: import("valibot").PicklistSchema<readonly ["Charity", "Religious Organization", "University", "Hospital", "Other"], undefined>;
8
- export type OrgDesignation = InferOutput<typeof orgDesignation>;
9
- export interface FileObject extends InferOutput<typeof fileObject> {
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 unSdgNums: readonly [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17];
12
- export declare const unSdgNum: 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 unSdgNum>;
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 donateMethodIds: readonly ["stripe", "crypto", "daf", "stocks"];
18
- export declare const donateMethodId: import("valibot").PicklistSchema<readonly ["stripe", "crypto", "daf", "stocks"], undefined>;
19
- export type DonateMethodId = InferOutput<typeof donateMethodId>;
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, lazy, transform, trim, nonEmpty, } from "valibot";
2
- export const fileObject = object({
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 orgDesignations = [
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 orgDesignation = picklist(orgDesignations);
14
- export const unSdgNums = [
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 unSdgNum = picklist(unSdgNums);
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 donateMethodIds = ["stripe", "crypto", "daf", "stocks"];
21
- export const donateMethodId = picklist(donateMethodIds);
22
- const str = pipe(string(), trim());
23
- export const https_url = (non_empty) => lazy((x) => {
24
- if (!x)
25
- return non_empty ? pipe(str, nonEmpty("required")) : str;
26
- return pipe(str, transform((x) => (x.startsWith("https://") ? x : `https://${x}`)), url("invalid url"));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-giving/schemas",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "devDependencies": {
5
5
  "@better-giving/config": "1.1.2"
6
6
  },
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
- nonEmpty,
12
+ number,
13
+ minValue,
14
+ integer,
12
15
  } from "valibot";
13
16
 
14
- export const fileObject = object({
17
+ export const file_obj = object({
15
18
  name: string(),
16
19
  publicUrl: pipe(string(), url()),
17
20
  });
18
21
 
19
- export const orgDesignations = [
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 orgDesignation = picklist(orgDesignations);
28
- export type OrgDesignation = InferOutput<typeof orgDesignation>;
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 fileObject> {}
33
+ export interface FileObject extends InferOutput<typeof file_obj> {}
31
34
 
32
- export const unSdgNums = [
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 unSdgNum = picklist(unSdgNums);
37
- export type UnSdgNum = InferOutput<typeof unSdgNum>;
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 donateMethodIds = ["stripe", "crypto", "daf", "stocks"] as const;
44
- export const donateMethodId = picklist(donateMethodIds);
45
- export type DonateMethodId = InferOutput<typeof donateMethodId>;
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 str = pipe(string(), trim());
48
- export const https_url = (non_empty: boolean) =>
49
- lazy((x) => {
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
- str,
82
+ $,
53
83
  transform((x) => (x.startsWith("https://") ? x : `https://${x}`)),
54
84
  url("invalid url")
55
85
  );
56
86
  });
87
+ };