@nakanoaas/notion-valibot-schema 0.0.3 → 0.0.5
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/README.md +26 -24
- package/dist/checkbox.cjs +29 -0
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.d.cts +30 -0
- package/dist/checkbox.d.mts +30 -0
- package/dist/checkbox.mjs +29 -0
- package/dist/checkbox.mjs.map +1 -1
- package/dist/created-by.cjs +75 -0
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.d.cts +76 -0
- package/dist/created-by.d.mts +76 -0
- package/dist/created-by.mjs +75 -0
- package/dist/created-by.mjs.map +1 -1
- package/dist/created-time.cjs +27 -0
- package/dist/created-time.cjs.map +1 -1
- package/dist/created-time.d.cts +28 -0
- package/dist/created-time.d.mts +28 -0
- package/dist/created-time.mjs +27 -0
- package/dist/created-time.mjs.map +1 -1
- package/dist/date.cjs +203 -13
- package/dist/date.cjs.map +1 -1
- package/dist/date.d.cts +214 -6
- package/dist/date.d.mts +214 -6
- package/dist/date.mjs +201 -12
- package/dist/date.mjs.map +1 -1
- package/dist/email.cjs +58 -0
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +59 -0
- package/dist/email.d.mts +59 -0
- package/dist/email.mjs +58 -0
- package/dist/email.mjs.map +1 -1
- package/dist/files.cjs +39 -0
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts +40 -0
- package/dist/files.d.mts +40 -0
- package/dist/files.mjs +39 -0
- package/dist/files.mjs.map +1 -1
- package/dist/formula.cjs +72 -0
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +73 -0
- package/dist/formula.d.mts +73 -0
- package/dist/formula.mjs +72 -0
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +7 -3
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/last-edited-by.cjs +68 -0
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.d.cts +69 -0
- package/dist/last-edited-by.d.mts +69 -0
- package/dist/last-edited-by.mjs +68 -0
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/last-edited-time.cjs +27 -0
- package/dist/last-edited-time.cjs.map +1 -1
- package/dist/last-edited-time.d.cts +28 -0
- package/dist/last-edited-time.d.mts +28 -0
- package/dist/last-edited-time.mjs +27 -0
- package/dist/last-edited-time.mjs.map +1 -1
- package/dist/multi-select.cjs +60 -0
- package/dist/multi-select.cjs.map +1 -1
- package/dist/multi-select.d.cts +61 -0
- package/dist/multi-select.d.mts +61 -0
- package/dist/multi-select.mjs +60 -0
- package/dist/multi-select.mjs.map +1 -1
- package/dist/number.cjs +58 -0
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.cts +59 -0
- package/dist/number.d.mts +59 -0
- package/dist/number.mjs +58 -0
- package/dist/number.mjs.map +1 -1
- package/dist/people.cjs +84 -0
- package/dist/people.cjs.map +1 -1
- package/dist/people.d.cts +85 -0
- package/dist/people.d.mts +85 -0
- package/dist/people.mjs +84 -0
- package/dist/people.mjs.map +1 -1
- package/dist/phone-number.cjs +58 -0
- package/dist/phone-number.cjs.map +1 -1
- package/dist/phone-number.d.cts +59 -0
- package/dist/phone-number.d.mts +59 -0
- package/dist/phone-number.mjs +58 -0
- package/dist/phone-number.mjs.map +1 -1
- package/dist/place.cjs +128 -0
- package/dist/place.cjs.map +1 -1
- package/dist/place.d.cts +85 -0
- package/dist/place.d.mts +85 -0
- package/dist/place.mjs +128 -0
- package/dist/place.mjs.map +1 -1
- package/dist/relation.cjs +137 -1
- package/dist/relation.cjs.map +1 -1
- package/dist/relation.d.cts +113 -1
- package/dist/relation.d.mts +113 -1
- package/dist/relation.mjs +136 -2
- package/dist/relation.mjs.map +1 -1
- package/dist/rollup.cjs +203 -10
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +201 -0
- package/dist/rollup.d.mts +201 -0
- package/dist/rollup.mjs +203 -10
- package/dist/rollup.mjs.map +1 -1
- package/dist/select.cjs +120 -0
- package/dist/select.cjs.map +1 -1
- package/dist/select.d.cts +121 -0
- package/dist/select.d.mts +121 -0
- package/dist/select.mjs +120 -0
- package/dist/select.mjs.map +1 -1
- package/dist/status.cjs +120 -0
- package/dist/status.cjs.map +1 -1
- package/dist/status.d.cts +121 -0
- package/dist/status.d.mts +121 -0
- package/dist/status.mjs +120 -0
- package/dist/status.mjs.map +1 -1
- package/dist/text.cjs +103 -3
- package/dist/text.cjs.map +1 -1
- package/dist/text.d.cts +73 -10
- package/dist/text.d.mts +73 -10
- package/dist/text.mjs +103 -3
- package/dist/text.mjs.map +1 -1
- package/dist/unique-id.cjs +73 -2
- package/dist/unique-id.cjs.map +1 -1
- package/dist/unique-id.d.cts +81 -2
- package/dist/unique-id.d.mts +81 -2
- package/dist/unique-id.mjs +72 -2
- package/dist/unique-id.mjs.map +1 -1
- package/dist/url.cjs +58 -0
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.cts +59 -0
- package/dist/url.d.mts +59 -0
- package/dist/url.mjs +58 -0
- package/dist/url.mjs.map +1 -1
- package/dist/verification.cjs +82 -5
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.d.cts +81 -0
- package/dist/verification.d.mts +81 -0
- package/dist/verification.mjs +82 -5
- package/dist/verification.mjs.map +1 -1
- package/package.json +1 -1
package/dist/status.cjs
CHANGED
|
@@ -3,9 +3,129 @@ let valibot = require("valibot");
|
|
|
3
3
|
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
4
4
|
|
|
5
5
|
//#region src/status.ts
|
|
6
|
+
/**
|
|
7
|
+
* Schema factory to extract the `status` property from a Notion page property.
|
|
8
|
+
*
|
|
9
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
10
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
11
|
+
* typed status values. The status property in Notion contains an object with
|
|
12
|
+
* a `name` field that can be validated using the provided schema.
|
|
13
|
+
*
|
|
14
|
+
* **Input:**
|
|
15
|
+
* ```
|
|
16
|
+
* {
|
|
17
|
+
* status: {
|
|
18
|
+
* name: string;
|
|
19
|
+
* };
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
24
|
+
* For example, if `v.string()` is passed, the output will be `string`.
|
|
25
|
+
*
|
|
26
|
+
* @param schema - A schema that validates the status option name.
|
|
27
|
+
* Must accept a string value.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import * as v from "valibot";
|
|
32
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
33
|
+
*
|
|
34
|
+
* const PageSchema = v.object({
|
|
35
|
+
* id: v.string(),
|
|
36
|
+
* properties: v.object({
|
|
37
|
+
* Status: StatusSchema(v.string()),
|
|
38
|
+
* }),
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
42
|
+
* const parsed = v.parse(PageSchema, page);
|
|
43
|
+
* // parsed.properties.Status: string
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import * as v from "valibot";
|
|
49
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
50
|
+
*
|
|
51
|
+
* // Custom schema for enum values
|
|
52
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
53
|
+
*
|
|
54
|
+
* const PageSchema = v.object({
|
|
55
|
+
* id: v.string(),
|
|
56
|
+
* properties: v.object({
|
|
57
|
+
* Status: StatusSchema(StatusOptionSchema),
|
|
58
|
+
* }),
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
62
|
+
* const parsed = v.parse(PageSchema, page);
|
|
63
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed"
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
6
66
|
function StatusSchema(schema) {
|
|
7
67
|
return valibot.pipe(valibot.object({ status: valibot.object({ name: schema }) }), valibot.transform((v) => v.status.name));
|
|
8
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Schema factory to extract the `status` property from a Notion page property or `null`.
|
|
71
|
+
*
|
|
72
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
73
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
74
|
+
* typed status values. The status property in Notion contains an object with
|
|
75
|
+
* a `name` field that can be validated using the provided schema, or `null` if not set.
|
|
76
|
+
*
|
|
77
|
+
* **Input:**
|
|
78
|
+
* ```
|
|
79
|
+
* {
|
|
80
|
+
* status: {
|
|
81
|
+
* name: string;
|
|
82
|
+
* } | null;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* **Output:** The output type depends on the schema passed as a parameter, or `null`.
|
|
87
|
+
* For example, if `v.string()` is passed, the output will be `string | null`.
|
|
88
|
+
*
|
|
89
|
+
* @param schema - A schema that validates the status option name.
|
|
90
|
+
* Must accept a string value.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import * as v from "valibot";
|
|
95
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
96
|
+
*
|
|
97
|
+
* const PageSchema = v.object({
|
|
98
|
+
* id: v.string(),
|
|
99
|
+
* properties: v.object({
|
|
100
|
+
* Status: NullableStatusSchema(v.string()),
|
|
101
|
+
* }),
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
105
|
+
* const parsed = v.parse(PageSchema, page);
|
|
106
|
+
* // parsed.properties.Status: string | null
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import * as v from "valibot";
|
|
112
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
113
|
+
*
|
|
114
|
+
* // Custom schema for enum values
|
|
115
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
116
|
+
*
|
|
117
|
+
* const PageSchema = v.object({
|
|
118
|
+
* id: v.string(),
|
|
119
|
+
* properties: v.object({
|
|
120
|
+
* Status: NullableStatusSchema(StatusOptionSchema),
|
|
121
|
+
* }),
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
125
|
+
* const parsed = v.parse(PageSchema, page);
|
|
126
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed" | null
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
9
129
|
function NullableStatusSchema(schema) {
|
|
10
130
|
return valibot.pipe(valibot.object({ status: valibot.nullable(valibot.object({ name: schema })) }), valibot.transform((v) => v.status?.name ?? null));
|
|
11
131
|
}
|
package/dist/status.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.cjs","names":["v"],"sources":["../src/status.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport function StatusSchema<T extends v.GenericSchema<string>>(schema: T) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.object({\n\t\t\t\tname: schema,\n\t\t\t}),\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.status.name!),\n\t);\n}\n\nexport function NullableStatusSchema<T extends v.GenericSchema<string>>(\n\tschema: T,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.nullable(\n\t\t\t\tv.object({\n\t\t\t\t\tname: schema,\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tv.transform((v) => v.status?.name ?? null),\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"status.cjs","names":["v"],"sources":["../src/status.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `status` property from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed status values. The status property in Notion contains an object with\n * a `name` field that can be validated using the provided schema.\n *\n * **Input:**\n * ```\n * {\n * status: {\n * name: string;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `v.string()` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the status option name.\n * Must accept a string value.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { StatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: StatusSchema(v.string()),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { StatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for enum values\n * const StatusOptionSchema = v.picklist([\"not-started\", \"in-progress\", \"completed\"]);\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: StatusSchema(StatusOptionSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: \"not-started\" | \"in-progress\" | \"completed\"\n * ```\n */\nexport function StatusSchema<T extends v.GenericSchema<string>>(schema: T) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.object({\n\t\t\t\tname: schema,\n\t\t\t}),\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.status.name!),\n\t);\n}\n\n/**\n * Schema factory to extract the `status` property from a Notion page property or `null`.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed status values. The status property in Notion contains an object with\n * a `name` field that can be validated using the provided schema, or `null` if not set.\n *\n * **Input:**\n * ```\n * {\n * status: {\n * name: string;\n * } | null;\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter, or `null`.\n * For example, if `v.string()` is passed, the output will be `string | null`.\n *\n * @param schema - A schema that validates the status option name.\n * Must accept a string value.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableStatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: NullableStatusSchema(v.string()),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: string | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableStatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for enum values\n * const StatusOptionSchema = v.picklist([\"not-started\", \"in-progress\", \"completed\"]);\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: NullableStatusSchema(StatusOptionSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: \"not-started\" | \"in-progress\" | \"completed\" | null\n * ```\n */\nexport function NullableStatusSchema<T extends v.GenericSchema<string>>(\n\tschema: T,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.nullable(\n\t\t\t\tv.object({\n\t\t\t\t\tname: schema,\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tv.transform((v) => v.status?.name ?? null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,aAAgD,QAAW;AAC1E,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO,EAChB,MAAM,QACN,CAAC,EACF,CAAC,EAEFA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAM,CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DF,SAAgB,qBACf,QACC;AACD,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,SACTA,QAAE,OAAO,EACR,MAAM,QACN,CAAC,CACF,EACD,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,QAAQ,QAAQ,KAAK,CAC1C"}
|
package/dist/status.d.cts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/status.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema factory to extract the `status` property from a Notion page property.
|
|
7
|
+
*
|
|
8
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
9
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
10
|
+
* typed status values. The status property in Notion contains an object with
|
|
11
|
+
* a `name` field that can be validated using the provided schema.
|
|
12
|
+
*
|
|
13
|
+
* **Input:**
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* status: {
|
|
17
|
+
* name: string;
|
|
18
|
+
* };
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
23
|
+
* For example, if `v.string()` is passed, the output will be `string`.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - A schema that validates the status option name.
|
|
26
|
+
* Must accept a string value.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import * as v from "valibot";
|
|
31
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
32
|
+
*
|
|
33
|
+
* const PageSchema = v.object({
|
|
34
|
+
* id: v.string(),
|
|
35
|
+
* properties: v.object({
|
|
36
|
+
* Status: StatusSchema(v.string()),
|
|
37
|
+
* }),
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
41
|
+
* const parsed = v.parse(PageSchema, page);
|
|
42
|
+
* // parsed.properties.Status: string
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import * as v from "valibot";
|
|
48
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
49
|
+
*
|
|
50
|
+
* // Custom schema for enum values
|
|
51
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
52
|
+
*
|
|
53
|
+
* const PageSchema = v.object({
|
|
54
|
+
* id: v.string(),
|
|
55
|
+
* properties: v.object({
|
|
56
|
+
* Status: StatusSchema(StatusOptionSchema),
|
|
57
|
+
* }),
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
61
|
+
* const parsed = v.parse(PageSchema, page);
|
|
62
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed"
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
4
65
|
declare function StatusSchema<T extends v.GenericSchema<string>>(schema: T): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
5
66
|
readonly status: v.ObjectSchema<{
|
|
6
67
|
readonly name: T;
|
|
@@ -32,6 +93,66 @@ declare function StatusSchema<T extends v.GenericSchema<string>>(schema: T): v.S
|
|
|
32
93
|
}, T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never> & Partial<Pick<{
|
|
33
94
|
name: v.InferOutput<T>;
|
|
34
95
|
}, T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never>>, Exclude<"name", T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never> | Exclude<T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never, T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never> | Exclude<Exclude<"name", T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never>, T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never>>)["name"]>]>;
|
|
96
|
+
/**
|
|
97
|
+
* Schema factory to extract the `status` property from a Notion page property or `null`.
|
|
98
|
+
*
|
|
99
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
100
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
101
|
+
* typed status values. The status property in Notion contains an object with
|
|
102
|
+
* a `name` field that can be validated using the provided schema, or `null` if not set.
|
|
103
|
+
*
|
|
104
|
+
* **Input:**
|
|
105
|
+
* ```
|
|
106
|
+
* {
|
|
107
|
+
* status: {
|
|
108
|
+
* name: string;
|
|
109
|
+
* } | null;
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* **Output:** The output type depends on the schema passed as a parameter, or `null`.
|
|
114
|
+
* For example, if `v.string()` is passed, the output will be `string | null`.
|
|
115
|
+
*
|
|
116
|
+
* @param schema - A schema that validates the status option name.
|
|
117
|
+
* Must accept a string value.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import * as v from "valibot";
|
|
122
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
123
|
+
*
|
|
124
|
+
* const PageSchema = v.object({
|
|
125
|
+
* id: v.string(),
|
|
126
|
+
* properties: v.object({
|
|
127
|
+
* Status: NullableStatusSchema(v.string()),
|
|
128
|
+
* }),
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
132
|
+
* const parsed = v.parse(PageSchema, page);
|
|
133
|
+
* // parsed.properties.Status: string | null
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import * as v from "valibot";
|
|
139
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
140
|
+
*
|
|
141
|
+
* // Custom schema for enum values
|
|
142
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
143
|
+
*
|
|
144
|
+
* const PageSchema = v.object({
|
|
145
|
+
* id: v.string(),
|
|
146
|
+
* properties: v.object({
|
|
147
|
+
* Status: NullableStatusSchema(StatusOptionSchema),
|
|
148
|
+
* }),
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
152
|
+
* const parsed = v.parse(PageSchema, page);
|
|
153
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed" | null
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
35
156
|
declare function NullableStatusSchema<T extends v.GenericSchema<string>>(schema: T): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
36
157
|
readonly status: v.NullableSchema<v.ObjectSchema<{
|
|
37
158
|
readonly name: T;
|
package/dist/status.d.mts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/status.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema factory to extract the `status` property from a Notion page property.
|
|
7
|
+
*
|
|
8
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
9
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
10
|
+
* typed status values. The status property in Notion contains an object with
|
|
11
|
+
* a `name` field that can be validated using the provided schema.
|
|
12
|
+
*
|
|
13
|
+
* **Input:**
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* status: {
|
|
17
|
+
* name: string;
|
|
18
|
+
* };
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
23
|
+
* For example, if `v.string()` is passed, the output will be `string`.
|
|
24
|
+
*
|
|
25
|
+
* @param schema - A schema that validates the status option name.
|
|
26
|
+
* Must accept a string value.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import * as v from "valibot";
|
|
31
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
32
|
+
*
|
|
33
|
+
* const PageSchema = v.object({
|
|
34
|
+
* id: v.string(),
|
|
35
|
+
* properties: v.object({
|
|
36
|
+
* Status: StatusSchema(v.string()),
|
|
37
|
+
* }),
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
41
|
+
* const parsed = v.parse(PageSchema, page);
|
|
42
|
+
* // parsed.properties.Status: string
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import * as v from "valibot";
|
|
48
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
49
|
+
*
|
|
50
|
+
* // Custom schema for enum values
|
|
51
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
52
|
+
*
|
|
53
|
+
* const PageSchema = v.object({
|
|
54
|
+
* id: v.string(),
|
|
55
|
+
* properties: v.object({
|
|
56
|
+
* Status: StatusSchema(StatusOptionSchema),
|
|
57
|
+
* }),
|
|
58
|
+
* });
|
|
59
|
+
*
|
|
60
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
61
|
+
* const parsed = v.parse(PageSchema, page);
|
|
62
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed"
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
4
65
|
declare function StatusSchema<T extends v.GenericSchema<string>>(schema: T): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
5
66
|
readonly status: v.ObjectSchema<{
|
|
6
67
|
readonly name: T;
|
|
@@ -32,6 +93,66 @@ declare function StatusSchema<T extends v.GenericSchema<string>>(schema: T): v.S
|
|
|
32
93
|
}, T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never> & Partial<Pick<{
|
|
33
94
|
name: v.InferOutput<T>;
|
|
34
95
|
}, T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never>>, Exclude<"name", T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never> | Exclude<T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never, T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never> | Exclude<Exclude<"name", T extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends T["default"] ? "name" : never : never>, T extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "name" : never : never>>)["name"]>]>;
|
|
96
|
+
/**
|
|
97
|
+
* Schema factory to extract the `status` property from a Notion page property or `null`.
|
|
98
|
+
*
|
|
99
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
100
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
101
|
+
* typed status values. The status property in Notion contains an object with
|
|
102
|
+
* a `name` field that can be validated using the provided schema, or `null` if not set.
|
|
103
|
+
*
|
|
104
|
+
* **Input:**
|
|
105
|
+
* ```
|
|
106
|
+
* {
|
|
107
|
+
* status: {
|
|
108
|
+
* name: string;
|
|
109
|
+
* } | null;
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* **Output:** The output type depends on the schema passed as a parameter, or `null`.
|
|
114
|
+
* For example, if `v.string()` is passed, the output will be `string | null`.
|
|
115
|
+
*
|
|
116
|
+
* @param schema - A schema that validates the status option name.
|
|
117
|
+
* Must accept a string value.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import * as v from "valibot";
|
|
122
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
123
|
+
*
|
|
124
|
+
* const PageSchema = v.object({
|
|
125
|
+
* id: v.string(),
|
|
126
|
+
* properties: v.object({
|
|
127
|
+
* Status: NullableStatusSchema(v.string()),
|
|
128
|
+
* }),
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
132
|
+
* const parsed = v.parse(PageSchema, page);
|
|
133
|
+
* // parsed.properties.Status: string | null
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import * as v from "valibot";
|
|
139
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
140
|
+
*
|
|
141
|
+
* // Custom schema for enum values
|
|
142
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
143
|
+
*
|
|
144
|
+
* const PageSchema = v.object({
|
|
145
|
+
* id: v.string(),
|
|
146
|
+
* properties: v.object({
|
|
147
|
+
* Status: NullableStatusSchema(StatusOptionSchema),
|
|
148
|
+
* }),
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
152
|
+
* const parsed = v.parse(PageSchema, page);
|
|
153
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed" | null
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
35
156
|
declare function NullableStatusSchema<T extends v.GenericSchema<string>>(schema: T): v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
36
157
|
readonly status: v.NullableSchema<v.ObjectSchema<{
|
|
37
158
|
readonly name: T;
|
package/dist/status.mjs
CHANGED
|
@@ -1,9 +1,129 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/status.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema factory to extract the `status` property from a Notion page property.
|
|
6
|
+
*
|
|
7
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
8
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
9
|
+
* typed status values. The status property in Notion contains an object with
|
|
10
|
+
* a `name` field that can be validated using the provided schema.
|
|
11
|
+
*
|
|
12
|
+
* **Input:**
|
|
13
|
+
* ```
|
|
14
|
+
* {
|
|
15
|
+
* status: {
|
|
16
|
+
* name: string;
|
|
17
|
+
* };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
22
|
+
* For example, if `v.string()` is passed, the output will be `string`.
|
|
23
|
+
*
|
|
24
|
+
* @param schema - A schema that validates the status option name.
|
|
25
|
+
* Must accept a string value.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import * as v from "valibot";
|
|
30
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
31
|
+
*
|
|
32
|
+
* const PageSchema = v.object({
|
|
33
|
+
* id: v.string(),
|
|
34
|
+
* properties: v.object({
|
|
35
|
+
* Status: StatusSchema(v.string()),
|
|
36
|
+
* }),
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
40
|
+
* const parsed = v.parse(PageSchema, page);
|
|
41
|
+
* // parsed.properties.Status: string
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import * as v from "valibot";
|
|
47
|
+
* import { StatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
48
|
+
*
|
|
49
|
+
* // Custom schema for enum values
|
|
50
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
51
|
+
*
|
|
52
|
+
* const PageSchema = v.object({
|
|
53
|
+
* id: v.string(),
|
|
54
|
+
* properties: v.object({
|
|
55
|
+
* Status: StatusSchema(StatusOptionSchema),
|
|
56
|
+
* }),
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
60
|
+
* const parsed = v.parse(PageSchema, page);
|
|
61
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed"
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
4
64
|
function StatusSchema(schema) {
|
|
5
65
|
return v.pipe(v.object({ status: v.object({ name: schema }) }), v.transform((v$1) => v$1.status.name));
|
|
6
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Schema factory to extract the `status` property from a Notion page property or `null`.
|
|
69
|
+
*
|
|
70
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
71
|
+
* allowing you to combine it with other schemas in this library to extract
|
|
72
|
+
* typed status values. The status property in Notion contains an object with
|
|
73
|
+
* a `name` field that can be validated using the provided schema, or `null` if not set.
|
|
74
|
+
*
|
|
75
|
+
* **Input:**
|
|
76
|
+
* ```
|
|
77
|
+
* {
|
|
78
|
+
* status: {
|
|
79
|
+
* name: string;
|
|
80
|
+
* } | null;
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* **Output:** The output type depends on the schema passed as a parameter, or `null`.
|
|
85
|
+
* For example, if `v.string()` is passed, the output will be `string | null`.
|
|
86
|
+
*
|
|
87
|
+
* @param schema - A schema that validates the status option name.
|
|
88
|
+
* Must accept a string value.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import * as v from "valibot";
|
|
93
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
94
|
+
*
|
|
95
|
+
* const PageSchema = v.object({
|
|
96
|
+
* id: v.string(),
|
|
97
|
+
* properties: v.object({
|
|
98
|
+
* Status: NullableStatusSchema(v.string()),
|
|
99
|
+
* }),
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
103
|
+
* const parsed = v.parse(PageSchema, page);
|
|
104
|
+
* // parsed.properties.Status: string | null
|
|
105
|
+
* ```
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import * as v from "valibot";
|
|
110
|
+
* import { NullableStatusSchema } from "@nakanoaas/notion-valibot-utils";
|
|
111
|
+
*
|
|
112
|
+
* // Custom schema for enum values
|
|
113
|
+
* const StatusOptionSchema = v.picklist(["not-started", "in-progress", "completed"]);
|
|
114
|
+
*
|
|
115
|
+
* const PageSchema = v.object({
|
|
116
|
+
* id: v.string(),
|
|
117
|
+
* properties: v.object({
|
|
118
|
+
* Status: NullableStatusSchema(StatusOptionSchema),
|
|
119
|
+
* }),
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
123
|
+
* const parsed = v.parse(PageSchema, page);
|
|
124
|
+
* // parsed.properties.Status: "not-started" | "in-progress" | "completed" | null
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
7
127
|
function NullableStatusSchema(schema) {
|
|
8
128
|
return v.pipe(v.object({ status: v.nullable(v.object({ name: schema })) }), v.transform((v$1) => v$1.status?.name ?? null));
|
|
9
129
|
}
|
package/dist/status.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.mjs","names":["v"],"sources":["../src/status.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport function StatusSchema<T extends v.GenericSchema<string>>(schema: T) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.object({\n\t\t\t\tname: schema,\n\t\t\t}),\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.status.name!),\n\t);\n}\n\nexport function NullableStatusSchema<T extends v.GenericSchema<string>>(\n\tschema: T,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.nullable(\n\t\t\t\tv.object({\n\t\t\t\t\tname: schema,\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tv.transform((v) => v.status?.name ?? null),\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"status.mjs","names":["v"],"sources":["../src/status.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `status` property from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed status values. The status property in Notion contains an object with\n * a `name` field that can be validated using the provided schema.\n *\n * **Input:**\n * ```\n * {\n * status: {\n * name: string;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `v.string()` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the status option name.\n * Must accept a string value.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { StatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: StatusSchema(v.string()),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { StatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for enum values\n * const StatusOptionSchema = v.picklist([\"not-started\", \"in-progress\", \"completed\"]);\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: StatusSchema(StatusOptionSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: \"not-started\" | \"in-progress\" | \"completed\"\n * ```\n */\nexport function StatusSchema<T extends v.GenericSchema<string>>(schema: T) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.object({\n\t\t\t\tname: schema,\n\t\t\t}),\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.status.name!),\n\t);\n}\n\n/**\n * Schema factory to extract the `status` property from a Notion page property or `null`.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed status values. The status property in Notion contains an object with\n * a `name` field that can be validated using the provided schema, or `null` if not set.\n *\n * **Input:**\n * ```\n * {\n * status: {\n * name: string;\n * } | null;\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter, or `null`.\n * For example, if `v.string()` is passed, the output will be `string | null`.\n *\n * @param schema - A schema that validates the status option name.\n * Must accept a string value.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableStatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: NullableStatusSchema(v.string()),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: string | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableStatusSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for enum values\n * const StatusOptionSchema = v.picklist([\"not-started\", \"in-progress\", \"completed\"]);\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Status: NullableStatusSchema(StatusOptionSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Status: \"not-started\" | \"in-progress\" | \"completed\" | null\n * ```\n */\nexport function NullableStatusSchema<T extends v.GenericSchema<string>>(\n\tschema: T,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tstatus: v.nullable(\n\t\t\t\tv.object({\n\t\t\t\t\tname: schema,\n\t\t\t\t}),\n\t\t\t),\n\t\t}),\n\t\tv.transform((v) => v.status?.name ?? null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,aAAgD,QAAW;AAC1E,QAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO,EAChB,MAAM,QACN,CAAC,EACF,CAAC,EAEF,EAAE,WAAW,QAAMA,IAAE,OAAO,KAAM,CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DF,SAAgB,qBACf,QACC;AACD,QAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,SACT,EAAE,OAAO,EACR,MAAM,QACN,CAAC,CACF,EACD,CAAC,EACF,EAAE,WAAW,QAAMA,IAAE,QAAQ,QAAQ,KAAK,CAC1C"}
|