@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/email.d.mts
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/email.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema to extract the `email` property from a Notion page property.
|
|
7
|
+
*
|
|
8
|
+
* **Input:**
|
|
9
|
+
* ```
|
|
10
|
+
* {
|
|
11
|
+
* email: string;
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* **Output:** `string`
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import * as v from "valibot";
|
|
20
|
+
* import { EmailSchema } from "@nakanoaas/notion-valibot-utils";
|
|
21
|
+
*
|
|
22
|
+
* const PageSchema = v.object({
|
|
23
|
+
* id: v.string(),
|
|
24
|
+
* properties: v.object({
|
|
25
|
+
* Email: EmailSchema,
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
30
|
+
* const parsed = v.parse(PageSchema, page);
|
|
31
|
+
* // parsed.properties.Email: string
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
4
34
|
declare const EmailSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
5
35
|
readonly email: v.StringSchema<undefined>;
|
|
6
36
|
}, undefined>, v.TransformAction<{
|
|
7
37
|
email: string;
|
|
8
38
|
}, string>]>;
|
|
39
|
+
/**
|
|
40
|
+
* Schema to extract the `email` property from a Notion page property or `null`.
|
|
41
|
+
*
|
|
42
|
+
* **Input:**
|
|
43
|
+
* ```
|
|
44
|
+
* {
|
|
45
|
+
* email: string | null;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* **Output:** `string | null`
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import * as v from "valibot";
|
|
54
|
+
* import { NullableEmailSchema } from "@nakanoaas/notion-valibot-utils";
|
|
55
|
+
*
|
|
56
|
+
* const PageSchema = v.object({
|
|
57
|
+
* id: v.string(),
|
|
58
|
+
* properties: v.object({
|
|
59
|
+
* Email: NullableEmailSchema,
|
|
60
|
+
* }),
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
64
|
+
* const parsed = v.parse(PageSchema, page);
|
|
65
|
+
* // parsed.properties.Email: string | null
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
9
68
|
declare const NullableEmailSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
10
69
|
readonly email: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
11
70
|
}, undefined>, v.TransformAction<{
|
package/dist/email.mjs
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/email.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema to extract the `email` property from a Notion page property.
|
|
6
|
+
*
|
|
7
|
+
* **Input:**
|
|
8
|
+
* ```
|
|
9
|
+
* {
|
|
10
|
+
* email: string;
|
|
11
|
+
* }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* **Output:** `string`
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import * as v from "valibot";
|
|
19
|
+
* import { EmailSchema } from "@nakanoaas/notion-valibot-utils";
|
|
20
|
+
*
|
|
21
|
+
* const PageSchema = v.object({
|
|
22
|
+
* id: v.string(),
|
|
23
|
+
* properties: v.object({
|
|
24
|
+
* Email: EmailSchema,
|
|
25
|
+
* }),
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
29
|
+
* const parsed = v.parse(PageSchema, page);
|
|
30
|
+
* // parsed.properties.Email: string
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
4
33
|
const EmailSchema = v.pipe(v.object({ email: v.string() }), v.transform((v$1) => v$1.email));
|
|
34
|
+
/**
|
|
35
|
+
* Schema to extract the `email` property from a Notion page property or `null`.
|
|
36
|
+
*
|
|
37
|
+
* **Input:**
|
|
38
|
+
* ```
|
|
39
|
+
* {
|
|
40
|
+
* email: string | null;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* **Output:** `string | null`
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import * as v from "valibot";
|
|
49
|
+
* import { NullableEmailSchema } from "@nakanoaas/notion-valibot-utils";
|
|
50
|
+
*
|
|
51
|
+
* const PageSchema = v.object({
|
|
52
|
+
* id: v.string(),
|
|
53
|
+
* properties: v.object({
|
|
54
|
+
* Email: NullableEmailSchema,
|
|
55
|
+
* }),
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
59
|
+
* const parsed = v.parse(PageSchema, page);
|
|
60
|
+
* // parsed.properties.Email: string | null
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
5
63
|
const NullableEmailSchema = v.pipe(v.object({ email: v.nullable(v.string()) }), v.transform((v$1) => v$1.email));
|
|
6
64
|
|
|
7
65
|
//#endregion
|
package/dist/email.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.mjs","names":["v"],"sources":["../src/email.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport const EmailSchema = v.pipe(\n\tv.object({\n\t\temail: v.string(),\n\t}),\n\tv.transform((v) => v.email),\n);\n\nexport const NullableEmailSchema = v.pipe(\n\tv.object({\n\t\temail: v.nullable(v.string()),\n\t}),\n\tv.transform((v) => v.email),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"email.mjs","names":["v"],"sources":["../src/email.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema to extract the `email` property from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * email: string;\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { EmailSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Email: EmailSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Email: string\n * ```\n */\nexport const EmailSchema = v.pipe(\n\tv.object({\n\t\temail: v.string(),\n\t}),\n\tv.transform((v) => v.email),\n);\n\n/**\n * Schema to extract the `email` property from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * email: string | null;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableEmailSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Email: NullableEmailSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Email: string | null\n * ```\n */\nexport const NullableEmailSchema = v.pipe(\n\tv.object({\n\t\temail: v.nullable(v.string()),\n\t}),\n\tv.transform((v) => v.email),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,cAAc,EAAE,KAC5B,EAAE,OAAO,EACR,OAAO,EAAE,QAAQ,EACjB,CAAC,EACF,EAAE,WAAW,QAAMA,IAAE,MAAM,CAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BD,MAAa,sBAAsB,EAAE,KACpC,EAAE,OAAO,EACR,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,EAC7B,CAAC,EACF,EAAE,WAAW,QAAMA,IAAE,MAAM,CAC3B"}
|
package/dist/files.cjs
CHANGED
|
@@ -3,6 +3,45 @@ let valibot = require("valibot");
|
|
|
3
3
|
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
4
4
|
|
|
5
5
|
//#region src/files.ts
|
|
6
|
+
/**
|
|
7
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
8
|
+
*
|
|
9
|
+
* **Input:**
|
|
10
|
+
* ```
|
|
11
|
+
* {
|
|
12
|
+
* files: Array<{
|
|
13
|
+
* type: "file";
|
|
14
|
+
* file: {
|
|
15
|
+
* url: string;
|
|
16
|
+
* };
|
|
17
|
+
* } | {
|
|
18
|
+
* type: "external";
|
|
19
|
+
* external: {
|
|
20
|
+
* url: string;
|
|
21
|
+
* };
|
|
22
|
+
* }>;
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* **Output:** `string[]`
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import * as v from "valibot";
|
|
31
|
+
* import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
|
|
32
|
+
*
|
|
33
|
+
* const PageSchema = v.object({
|
|
34
|
+
* id: v.string(),
|
|
35
|
+
* properties: v.object({
|
|
36
|
+
* Files: FilesSchema,
|
|
37
|
+
* }),
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
41
|
+
* const parsed = v.parse(PageSchema, page);
|
|
42
|
+
* // parsed.properties.Files: string[]
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
6
45
|
const FilesSchema = valibot.pipe(valibot.object({ files: valibot.array(valibot.variant("type", [valibot.object({
|
|
7
46
|
type: valibot.literal("file"),
|
|
8
47
|
file: valibot.object({ url: valibot.string() })
|
package/dist/files.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.cjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport const FilesSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(\n\t\t\tv.variant(\"type\", [\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"file\"),\n\t\t\t\t\tfile: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"external\"),\n\t\t\t\t\texternal: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.cjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FilesSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FilesSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FilesSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(\n\t\t\tv.variant(\"type\", [\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"file\"),\n\t\t\t\t\tfile: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"external\"),\n\t\t\t\t\texternal: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,cAAcA,QAAE,KAC5BA,QAAE,OAAO,EACR,OAAOA,QAAE,MACRA,QAAE,QAAQ,QAAQ,CACjBA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMA,QAAE,OAAO,EACd,KAAKA,QAAE,QAAQ,EACf,CAAC;CACF,CAAC,EACFA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,WAAW;CAC3B,UAAUA,QAAE,OAAO,EAClB,KAAKA,QAAE,QAAQ,EACf,CAAC;CACF,CAAC,CACF,CAAC,CACF,EACD,CAAC,EACFA,QAAE,WAAW,MACZ,EAAE,MAAM,KAAK,QAAOA,IAAE,SAAS,SAASA,IAAE,KAAK,MAAMA,IAAE,SAAS,IAAK,CACrE,CACD"}
|
package/dist/files.d.cts
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/files.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
7
|
+
*
|
|
8
|
+
* **Input:**
|
|
9
|
+
* ```
|
|
10
|
+
* {
|
|
11
|
+
* files: Array<{
|
|
12
|
+
* type: "file";
|
|
13
|
+
* file: {
|
|
14
|
+
* url: string;
|
|
15
|
+
* };
|
|
16
|
+
* } | {
|
|
17
|
+
* type: "external";
|
|
18
|
+
* external: {
|
|
19
|
+
* url: string;
|
|
20
|
+
* };
|
|
21
|
+
* }>;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **Output:** `string[]`
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import * as v from "valibot";
|
|
30
|
+
* import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
|
|
31
|
+
*
|
|
32
|
+
* const PageSchema = v.object({
|
|
33
|
+
* id: v.string(),
|
|
34
|
+
* properties: v.object({
|
|
35
|
+
* Files: FilesSchema,
|
|
36
|
+
* }),
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
40
|
+
* const parsed = v.parse(PageSchema, page);
|
|
41
|
+
* // parsed.properties.Files: string[]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
4
44
|
declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
5
45
|
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
6
46
|
readonly type: v.LiteralSchema<"file", undefined>;
|
package/dist/files.d.mts
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/files.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
7
|
+
*
|
|
8
|
+
* **Input:**
|
|
9
|
+
* ```
|
|
10
|
+
* {
|
|
11
|
+
* files: Array<{
|
|
12
|
+
* type: "file";
|
|
13
|
+
* file: {
|
|
14
|
+
* url: string;
|
|
15
|
+
* };
|
|
16
|
+
* } | {
|
|
17
|
+
* type: "external";
|
|
18
|
+
* external: {
|
|
19
|
+
* url: string;
|
|
20
|
+
* };
|
|
21
|
+
* }>;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **Output:** `string[]`
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import * as v from "valibot";
|
|
30
|
+
* import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
|
|
31
|
+
*
|
|
32
|
+
* const PageSchema = v.object({
|
|
33
|
+
* id: v.string(),
|
|
34
|
+
* properties: v.object({
|
|
35
|
+
* Files: FilesSchema,
|
|
36
|
+
* }),
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
40
|
+
* const parsed = v.parse(PageSchema, page);
|
|
41
|
+
* // parsed.properties.Files: string[]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
4
44
|
declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
5
45
|
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
6
46
|
readonly type: v.LiteralSchema<"file", undefined>;
|
package/dist/files.mjs
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/files.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
6
|
+
*
|
|
7
|
+
* **Input:**
|
|
8
|
+
* ```
|
|
9
|
+
* {
|
|
10
|
+
* files: Array<{
|
|
11
|
+
* type: "file";
|
|
12
|
+
* file: {
|
|
13
|
+
* url: string;
|
|
14
|
+
* };
|
|
15
|
+
* } | {
|
|
16
|
+
* type: "external";
|
|
17
|
+
* external: {
|
|
18
|
+
* url: string;
|
|
19
|
+
* };
|
|
20
|
+
* }>;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* **Output:** `string[]`
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as v from "valibot";
|
|
29
|
+
* import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
|
+
*
|
|
31
|
+
* const PageSchema = v.object({
|
|
32
|
+
* id: v.string(),
|
|
33
|
+
* properties: v.object({
|
|
34
|
+
* Files: FilesSchema,
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
39
|
+
* const parsed = v.parse(PageSchema, page);
|
|
40
|
+
* // parsed.properties.Files: string[]
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
4
43
|
const FilesSchema = v.pipe(v.object({ files: v.array(v.variant("type", [v.object({
|
|
5
44
|
type: v.literal("file"),
|
|
6
45
|
file: v.object({ url: v.string() })
|
package/dist/files.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.mjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport const FilesSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(\n\t\t\tv.variant(\"type\", [\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"file\"),\n\t\t\t\t\tfile: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"external\"),\n\t\t\t\t\texternal: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"files.mjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FilesSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FilesSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FilesSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(\n\t\t\tv.variant(\"type\", [\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"file\"),\n\t\t\t\t\tfile: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t\tv.object({\n\t\t\t\t\ttype: v.literal(\"external\"),\n\t\t\t\t\texternal: v.object({\n\t\t\t\t\t\turl: v.string(),\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t]),\n\t\t),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,cAAc,EAAE,KAC5B,EAAE,OAAO,EACR,OAAO,EAAE,MACR,EAAE,QAAQ,QAAQ,CACjB,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,OAAO;CACvB,MAAM,EAAE,OAAO,EACd,KAAK,EAAE,QAAQ,EACf,CAAC;CACF,CAAC,EACF,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,WAAW;CAC3B,UAAU,EAAE,OAAO,EAClB,KAAK,EAAE,QAAQ,EACf,CAAC;CACF,CAAC,CACF,CAAC,CACF,EACD,CAAC,EACF,EAAE,WAAW,QACZA,IAAE,MAAM,KAAK,QAAOA,IAAE,SAAS,SAASA,IAAE,KAAK,MAAMA,IAAE,SAAS,IAAK,CACrE,CACD"}
|
package/dist/formula.cjs
CHANGED
|
@@ -3,6 +3,78 @@ let valibot = require("valibot");
|
|
|
3
3
|
valibot = require_rolldown_runtime.__toESM(valibot);
|
|
4
4
|
|
|
5
5
|
//#region src/formula.ts
|
|
6
|
+
/**
|
|
7
|
+
* Schema factory to extract the `formula` property result 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 formula results. The formula property in Notion can return different
|
|
12
|
+
* types of values (string, number, boolean, or date) depending on the formula
|
|
13
|
+
* configuration.
|
|
14
|
+
*
|
|
15
|
+
* **Input:**
|
|
16
|
+
* ```
|
|
17
|
+
* {
|
|
18
|
+
* formula: {
|
|
19
|
+
* type: "string" | "number" | "boolean" | "date";
|
|
20
|
+
* string?: string | null;
|
|
21
|
+
* number?: number | null;
|
|
22
|
+
* boolean?: boolean | null;
|
|
23
|
+
* date?: {
|
|
24
|
+
* start: string;
|
|
25
|
+
* end: string | null;
|
|
26
|
+
* time_zone: string | null;
|
|
27
|
+
* } | null;
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
33
|
+
* For example, if `RichTextSchema` is passed, the output will be `string`.
|
|
34
|
+
*
|
|
35
|
+
* @param schema - A schema that validates the formula result type.
|
|
36
|
+
* Must accept one of: string, number, boolean, or date formula results.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import * as v from "valibot";
|
|
41
|
+
* import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
|
|
42
|
+
*
|
|
43
|
+
* const PageSchema = v.object({
|
|
44
|
+
* id: v.string(),
|
|
45
|
+
* properties: v.object({
|
|
46
|
+
* FormulaText: FormulaSchema(RichTextSchema),
|
|
47
|
+
* }),
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
51
|
+
* const parsed = v.parse(PageSchema, page);
|
|
52
|
+
* // parsed.properties.FormulaText: string
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import * as v from "valibot";
|
|
58
|
+
* import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
|
|
59
|
+
*
|
|
60
|
+
* // Custom schema for number formula
|
|
61
|
+
* const NumberFormulaSchema = v.object({
|
|
62
|
+
* type: v.literal("number"),
|
|
63
|
+
* number: v.nullable(v.number()),
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* const PageSchema = v.object({
|
|
67
|
+
* id: v.string(),
|
|
68
|
+
* properties: v.object({
|
|
69
|
+
* FormulaNumber: FormulaSchema(NumberFormulaSchema),
|
|
70
|
+
* }),
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
74
|
+
* const parsed = v.parse(PageSchema, page);
|
|
75
|
+
* // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
6
78
|
function FormulaSchema(schema) {
|
|
7
79
|
return valibot.pipe(valibot.object({ formula: schema }), valibot.transform((v) => v.formula));
|
|
8
80
|
}
|
package/dist/formula.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result 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 formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,cAed,QAAW;AACZ,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,SAAS,QACT,CAAC,EAEFA,QAAE,WAAW,MAAM,EAAE,QAAS,CAC9B"}
|
package/dist/formula.d.cts
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/formula.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema factory to extract the `formula` property result 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 formula results. The formula property in Notion can return different
|
|
11
|
+
* types of values (string, number, boolean, or date) depending on the formula
|
|
12
|
+
* configuration.
|
|
13
|
+
*
|
|
14
|
+
* **Input:**
|
|
15
|
+
* ```
|
|
16
|
+
* {
|
|
17
|
+
* formula: {
|
|
18
|
+
* type: "string" | "number" | "boolean" | "date";
|
|
19
|
+
* string?: string | null;
|
|
20
|
+
* number?: number | null;
|
|
21
|
+
* boolean?: boolean | null;
|
|
22
|
+
* date?: {
|
|
23
|
+
* start: string;
|
|
24
|
+
* end: string | null;
|
|
25
|
+
* time_zone: string | null;
|
|
26
|
+
* } | null;
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
32
|
+
* For example, if `RichTextSchema` is passed, the output will be `string`.
|
|
33
|
+
*
|
|
34
|
+
* @param schema - A schema that validates the formula result type.
|
|
35
|
+
* Must accept one of: string, number, boolean, or date formula results.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import * as v from "valibot";
|
|
40
|
+
* import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
|
|
41
|
+
*
|
|
42
|
+
* const PageSchema = v.object({
|
|
43
|
+
* id: v.string(),
|
|
44
|
+
* properties: v.object({
|
|
45
|
+
* FormulaText: FormulaSchema(RichTextSchema),
|
|
46
|
+
* }),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
50
|
+
* const parsed = v.parse(PageSchema, page);
|
|
51
|
+
* // parsed.properties.FormulaText: string
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import * as v from "valibot";
|
|
57
|
+
* import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
|
|
58
|
+
*
|
|
59
|
+
* // Custom schema for number formula
|
|
60
|
+
* const NumberFormulaSchema = v.object({
|
|
61
|
+
* type: v.literal("number"),
|
|
62
|
+
* number: v.nullable(v.number()),
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* const PageSchema = v.object({
|
|
66
|
+
* id: v.string(),
|
|
67
|
+
* properties: v.object({
|
|
68
|
+
* FormulaNumber: FormulaSchema(NumberFormulaSchema),
|
|
69
|
+
* }),
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
73
|
+
* const parsed = v.parse(PageSchema, page);
|
|
74
|
+
* // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
4
77
|
declare function FormulaSchema<S extends v.GenericSchema<{
|
|
5
78
|
type: "string";
|
|
6
79
|
string: string | null;
|
package/dist/formula.d.mts
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/formula.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Schema factory to extract the `formula` property result 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 formula results. The formula property in Notion can return different
|
|
11
|
+
* types of values (string, number, boolean, or date) depending on the formula
|
|
12
|
+
* configuration.
|
|
13
|
+
*
|
|
14
|
+
* **Input:**
|
|
15
|
+
* ```
|
|
16
|
+
* {
|
|
17
|
+
* formula: {
|
|
18
|
+
* type: "string" | "number" | "boolean" | "date";
|
|
19
|
+
* string?: string | null;
|
|
20
|
+
* number?: number | null;
|
|
21
|
+
* boolean?: boolean | null;
|
|
22
|
+
* date?: {
|
|
23
|
+
* start: string;
|
|
24
|
+
* end: string | null;
|
|
25
|
+
* time_zone: string | null;
|
|
26
|
+
* } | null;
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
32
|
+
* For example, if `RichTextSchema` is passed, the output will be `string`.
|
|
33
|
+
*
|
|
34
|
+
* @param schema - A schema that validates the formula result type.
|
|
35
|
+
* Must accept one of: string, number, boolean, or date formula results.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import * as v from "valibot";
|
|
40
|
+
* import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
|
|
41
|
+
*
|
|
42
|
+
* const PageSchema = v.object({
|
|
43
|
+
* id: v.string(),
|
|
44
|
+
* properties: v.object({
|
|
45
|
+
* FormulaText: FormulaSchema(RichTextSchema),
|
|
46
|
+
* }),
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
50
|
+
* const parsed = v.parse(PageSchema, page);
|
|
51
|
+
* // parsed.properties.FormulaText: string
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import * as v from "valibot";
|
|
57
|
+
* import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
|
|
58
|
+
*
|
|
59
|
+
* // Custom schema for number formula
|
|
60
|
+
* const NumberFormulaSchema = v.object({
|
|
61
|
+
* type: v.literal("number"),
|
|
62
|
+
* number: v.nullable(v.number()),
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* const PageSchema = v.object({
|
|
66
|
+
* id: v.string(),
|
|
67
|
+
* properties: v.object({
|
|
68
|
+
* FormulaNumber: FormulaSchema(NumberFormulaSchema),
|
|
69
|
+
* }),
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
73
|
+
* const parsed = v.parse(PageSchema, page);
|
|
74
|
+
* // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
4
77
|
declare function FormulaSchema<S extends v.GenericSchema<{
|
|
5
78
|
type: "string";
|
|
6
79
|
string: string | null;
|
package/dist/formula.mjs
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/formula.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema factory to extract the `formula` property result 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 formula results. The formula property in Notion can return different
|
|
10
|
+
* types of values (string, number, boolean, or date) depending on the formula
|
|
11
|
+
* configuration.
|
|
12
|
+
*
|
|
13
|
+
* **Input:**
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* formula: {
|
|
17
|
+
* type: "string" | "number" | "boolean" | "date";
|
|
18
|
+
* string?: string | null;
|
|
19
|
+
* number?: number | null;
|
|
20
|
+
* boolean?: boolean | null;
|
|
21
|
+
* date?: {
|
|
22
|
+
* start: string;
|
|
23
|
+
* end: string | null;
|
|
24
|
+
* time_zone: string | null;
|
|
25
|
+
* } | null;
|
|
26
|
+
* }
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
31
|
+
* For example, if `RichTextSchema` is passed, the output will be `string`.
|
|
32
|
+
*
|
|
33
|
+
* @param schema - A schema that validates the formula result type.
|
|
34
|
+
* Must accept one of: string, number, boolean, or date formula results.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import * as v from "valibot";
|
|
39
|
+
* import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
|
|
40
|
+
*
|
|
41
|
+
* const PageSchema = v.object({
|
|
42
|
+
* id: v.string(),
|
|
43
|
+
* properties: v.object({
|
|
44
|
+
* FormulaText: FormulaSchema(RichTextSchema),
|
|
45
|
+
* }),
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
49
|
+
* const parsed = v.parse(PageSchema, page);
|
|
50
|
+
* // parsed.properties.FormulaText: string
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import * as v from "valibot";
|
|
56
|
+
* import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
|
|
57
|
+
*
|
|
58
|
+
* // Custom schema for number formula
|
|
59
|
+
* const NumberFormulaSchema = v.object({
|
|
60
|
+
* type: v.literal("number"),
|
|
61
|
+
* number: v.nullable(v.number()),
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const PageSchema = v.object({
|
|
65
|
+
* id: v.string(),
|
|
66
|
+
* properties: v.object({
|
|
67
|
+
* FormulaNumber: FormulaSchema(NumberFormulaSchema),
|
|
68
|
+
* }),
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
72
|
+
* const parsed = v.parse(PageSchema, page);
|
|
73
|
+
* // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
4
76
|
function FormulaSchema(schema) {
|
|
5
77
|
return v.pipe(v.object({ formula: schema }), v.transform((v$1) => v$1.formula));
|
|
6
78
|
}
|