@nakanoaas/notion-valibot-schema 0.2.2 → 0.6.0

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.
Files changed (101) hide show
  1. package/README.md +33 -10
  2. package/dist/_virtual/_rolldown/runtime.cjs +7 -13
  3. package/dist/checkbox.cjs +3 -4
  4. package/dist/checkbox.cjs.map +1 -1
  5. package/dist/checkbox.mjs +1 -2
  6. package/dist/checkbox.mjs.map +1 -1
  7. package/dist/created-by.cjs +4 -5
  8. package/dist/created-by.cjs.map +1 -1
  9. package/dist/created-by.mjs +1 -2
  10. package/dist/created-by.mjs.map +1 -1
  11. package/dist/created-time.cjs +3 -4
  12. package/dist/created-time.cjs.map +1 -1
  13. package/dist/created-time.mjs +1 -2
  14. package/dist/created-time.mjs.map +1 -1
  15. package/dist/date.cjs +3 -4
  16. package/dist/date.cjs.map +1 -1
  17. package/dist/date.mjs +1 -2
  18. package/dist/date.mjs.map +1 -1
  19. package/dist/email.cjs +3 -4
  20. package/dist/email.cjs.map +1 -1
  21. package/dist/email.mjs +1 -2
  22. package/dist/email.mjs.map +1 -1
  23. package/dist/files.cjs +123 -14
  24. package/dist/files.cjs.map +1 -1
  25. package/dist/files.d.cts +132 -4
  26. package/dist/files.d.mts +132 -4
  27. package/dist/files.mjs +119 -12
  28. package/dist/files.mjs.map +1 -1
  29. package/dist/formula.cjs +123 -23
  30. package/dist/formula.cjs.map +1 -1
  31. package/dist/formula.d.cts +150 -41
  32. package/dist/formula.d.mts +150 -41
  33. package/dist/formula.mjs +118 -22
  34. package/dist/formula.mjs.map +1 -1
  35. package/dist/index.cjs +32 -26
  36. package/dist/index.d.cts +4 -4
  37. package/dist/index.d.mts +4 -4
  38. package/dist/index.mjs +4 -5
  39. package/dist/last-edited-by.cjs +4 -5
  40. package/dist/last-edited-by.cjs.map +1 -1
  41. package/dist/last-edited-by.mjs +1 -2
  42. package/dist/last-edited-by.mjs.map +1 -1
  43. package/dist/last-edited-time.cjs +3 -4
  44. package/dist/last-edited-time.cjs.map +1 -1
  45. package/dist/last-edited-time.mjs +1 -2
  46. package/dist/last-edited-time.mjs.map +1 -1
  47. package/dist/multi-select.cjs +3 -4
  48. package/dist/multi-select.cjs.map +1 -1
  49. package/dist/multi-select.mjs +1 -2
  50. package/dist/multi-select.mjs.map +1 -1
  51. package/dist/number.cjs +3 -4
  52. package/dist/number.cjs.map +1 -1
  53. package/dist/number.mjs +1 -2
  54. package/dist/number.mjs.map +1 -1
  55. package/dist/people.cjs +3 -4
  56. package/dist/people.cjs.map +1 -1
  57. package/dist/people.mjs +1 -2
  58. package/dist/people.mjs.map +1 -1
  59. package/dist/phone-number.cjs +3 -4
  60. package/dist/phone-number.cjs.map +1 -1
  61. package/dist/phone-number.mjs +1 -2
  62. package/dist/phone-number.mjs.map +1 -1
  63. package/dist/place.cjs +3 -4
  64. package/dist/place.cjs.map +1 -1
  65. package/dist/place.mjs +1 -2
  66. package/dist/place.mjs.map +1 -1
  67. package/dist/relation.cjs +3 -4
  68. package/dist/relation.cjs.map +1 -1
  69. package/dist/relation.mjs +1 -2
  70. package/dist/relation.mjs.map +1 -1
  71. package/dist/rollup.cjs +70 -5
  72. package/dist/rollup.cjs.map +1 -1
  73. package/dist/rollup.d.cts +70 -1
  74. package/dist/rollup.d.mts +70 -1
  75. package/dist/rollup.mjs +67 -3
  76. package/dist/rollup.mjs.map +1 -1
  77. package/dist/select.cjs +3 -4
  78. package/dist/select.cjs.map +1 -1
  79. package/dist/select.mjs +1 -2
  80. package/dist/select.mjs.map +1 -1
  81. package/dist/status.cjs +3 -4
  82. package/dist/status.cjs.map +1 -1
  83. package/dist/status.mjs +1 -2
  84. package/dist/status.mjs.map +1 -1
  85. package/dist/text.cjs +3 -4
  86. package/dist/text.cjs.map +1 -1
  87. package/dist/text.mjs +1 -2
  88. package/dist/text.mjs.map +1 -1
  89. package/dist/unique-id.cjs +3 -4
  90. package/dist/unique-id.cjs.map +1 -1
  91. package/dist/unique-id.mjs +1 -2
  92. package/dist/unique-id.mjs.map +1 -1
  93. package/dist/url.cjs +3 -4
  94. package/dist/url.cjs.map +1 -1
  95. package/dist/url.mjs +1 -2
  96. package/dist/url.mjs.map +1 -1
  97. package/dist/verification.cjs +5 -6
  98. package/dist/verification.cjs.map +1 -1
  99. package/dist/verification.mjs +1 -2
  100. package/dist/verification.mjs.map +1 -1
  101. package/package.json +4 -4
package/dist/files.cjs CHANGED
@@ -1,9 +1,35 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
2
  let valibot = require("valibot");
3
- valibot = require_runtime.__toESM(valibot);
4
-
3
+ valibot = require_runtime.__toESM(valibot, 1);
5
4
  //#region src/files.ts
6
5
  /**
6
+ * Schema for a Notion file object structure.
7
+ *
8
+ * **Input:**
9
+ * ```
10
+ * {
11
+ * type: "file";
12
+ * file: {
13
+ * url: string;
14
+ * };
15
+ * } | {
16
+ * type: "external";
17
+ * external: {
18
+ * url: string;
19
+ * };
20
+ * }
21
+ * ```
22
+ *
23
+ * @internal
24
+ */
25
+ const InnerFileSchema = valibot.variant("type", [valibot.object({
26
+ type: valibot.literal("file"),
27
+ file: valibot.object({ url: valibot.string() })
28
+ }), valibot.object({
29
+ type: valibot.literal("external"),
30
+ external: valibot.object({ url: valibot.string() })
31
+ })]);
32
+ /**
7
33
  * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
8
34
  *
9
35
  * **Input:**
@@ -28,12 +54,12 @@ valibot = require_runtime.__toESM(valibot);
28
54
  * @example
29
55
  * ```ts
30
56
  * import * as v from "valibot";
31
- * import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
57
+ * import { FileSchema } from "@nakanoaas/notion-valibot-utils";
32
58
  *
33
59
  * const PageSchema = v.object({
34
60
  * id: v.string(),
35
61
  * properties: v.object({
36
- * Files: FilesSchema,
62
+ * Files: FileSchema,
37
63
  * }),
38
64
  * });
39
65
  *
@@ -42,14 +68,97 @@ valibot = require_runtime.__toESM(valibot);
42
68
  * // parsed.properties.Files: string[]
43
69
  * ```
44
70
  */
45
- const FilesSchema = valibot.pipe(valibot.object({ files: valibot.array(valibot.variant("type", [valibot.object({
46
- type: valibot.literal("file"),
47
- file: valibot.object({ url: valibot.string() })
48
- }), valibot.object({
49
- type: valibot.literal("external"),
50
- external: valibot.object({ url: valibot.string() })
51
- })])) }), valibot.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
52
-
71
+ const FileSchema = valibot.pipe(valibot.object({ files: valibot.array(InnerFileSchema) }), valibot.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
72
+ /**
73
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL.
74
+ *
75
+ * **Input:**
76
+ * ```
77
+ * {
78
+ * files: [{
79
+ * type: "file";
80
+ * file: {
81
+ * url: string;
82
+ * };
83
+ * } | {
84
+ * type: "external";
85
+ * external: {
86
+ * url: string;
87
+ * };
88
+ * }];
89
+ * }
90
+ * ```
91
+ *
92
+ * **Output:** `string`
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import * as v from "valibot";
97
+ * import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
98
+ *
99
+ * const PageSchema = v.object({
100
+ * id: v.string(),
101
+ * properties: v.object({
102
+ * Attachment: SingleFileSchema,
103
+ * }),
104
+ * });
105
+ *
106
+ * const page = await notion.pages.retrieve({ page_id: "..." });
107
+ * const parsed = v.parse(PageSchema, page);
108
+ * // parsed.properties.Attachment: string
109
+ * ```
110
+ */
111
+ const SingleFileSchema = valibot.pipe(valibot.object({ files: valibot.tuple([InnerFileSchema]) }), valibot.transform((v) => {
112
+ const file = v.files[0];
113
+ return file.type === "file" ? file.file.url : file.external.url;
114
+ }));
115
+ /**
116
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
117
+ *
118
+ * **Input:**
119
+ * ```
120
+ * {
121
+ * files: Array<{
122
+ * type: "file";
123
+ * file: {
124
+ * url: string;
125
+ * };
126
+ * } | {
127
+ * type: "external";
128
+ * external: {
129
+ * url: string;
130
+ * };
131
+ * }>;
132
+ * }
133
+ * ```
134
+ *
135
+ * **Output:** `string | null`
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import * as v from "valibot";
140
+ * import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
141
+ *
142
+ * const PageSchema = v.object({
143
+ * id: v.string(),
144
+ * properties: v.object({
145
+ * Attachment: NullableSingleFileSchema,
146
+ * }),
147
+ * });
148
+ *
149
+ * const page = await notion.pages.retrieve({ page_id: "..." });
150
+ * const parsed = v.parse(PageSchema, page);
151
+ * // parsed.properties.Attachment: string | null
152
+ * ```
153
+ */
154
+ const NullableSingleFileSchema = valibot.pipe(valibot.object({ files: valibot.array(InnerFileSchema) }), valibot.transform((v) => {
155
+ const file = v.files[0];
156
+ if (!file) return null;
157
+ return file.type === "file" ? file.file.url : file.external.url;
158
+ }));
53
159
  //#endregion
54
- exports.FilesSchema = FilesSchema;
160
+ exports.FileSchema = FileSchema;
161
+ exports.NullableSingleFileSchema = NullableSingleFileSchema;
162
+ exports.SingleFileSchema = SingleFileSchema;
163
+
55
164
  //# sourceMappingURL=files.cjs.map
@@ -1 +1 @@
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,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,IAAK,CACrE,CACD"}
1
+ {"version":3,"file":"files.cjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\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 { FileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileSchema,\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 FileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\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\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\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 { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\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 | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkBA,QAAE,QAAQ,QAAQ,CACzCA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,OAAO,EACd,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,GACDA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,UAAU;CAC1B,UAAUA,QAAE,OAAO,EAClB,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,aAAaA,QAAE,KAC3BA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}
package/dist/files.d.cts CHANGED
@@ -26,12 +26,12 @@ import * as v from "valibot";
26
26
  * @example
27
27
  * ```ts
28
28
  * import * as v from "valibot";
29
- * import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
29
+ * import { FileSchema } from "@nakanoaas/notion-valibot-utils";
30
30
  *
31
31
  * const PageSchema = v.object({
32
32
  * id: v.string(),
33
33
  * properties: v.object({
34
- * Files: FilesSchema,
34
+ * Files: FileSchema,
35
35
  * }),
36
36
  * });
37
37
  *
@@ -40,7 +40,7 @@ import * as v from "valibot";
40
40
  * // parsed.properties.Files: string[]
41
41
  * ```
42
42
  */
43
- declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
43
+ declare const FileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
44
44
  readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
45
45
  readonly type: v.LiteralSchema<"file", undefined>;
46
46
  readonly file: v.ObjectSchema<{
@@ -65,6 +65,134 @@ declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
65
65
  };
66
66
  })[];
67
67
  }, string[]>]>;
68
+ /**
69
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL.
70
+ *
71
+ * **Input:**
72
+ * ```
73
+ * {
74
+ * files: [{
75
+ * type: "file";
76
+ * file: {
77
+ * url: string;
78
+ * };
79
+ * } | {
80
+ * type: "external";
81
+ * external: {
82
+ * url: string;
83
+ * };
84
+ * }];
85
+ * }
86
+ * ```
87
+ *
88
+ * **Output:** `string`
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import * as v from "valibot";
93
+ * import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
94
+ *
95
+ * const PageSchema = v.object({
96
+ * id: v.string(),
97
+ * properties: v.object({
98
+ * Attachment: SingleFileSchema,
99
+ * }),
100
+ * });
101
+ *
102
+ * const page = await notion.pages.retrieve({ page_id: "..." });
103
+ * const parsed = v.parse(PageSchema, page);
104
+ * // parsed.properties.Attachment: string
105
+ * ```
106
+ */
107
+ declare const SingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
108
+ readonly files: v.TupleSchema<[v.VariantSchema<"type", [v.ObjectSchema<{
109
+ readonly type: v.LiteralSchema<"file", undefined>;
110
+ readonly file: v.ObjectSchema<{
111
+ readonly url: v.StringSchema<undefined>;
112
+ }, undefined>;
113
+ }, undefined>, v.ObjectSchema<{
114
+ readonly type: v.LiteralSchema<"external", undefined>;
115
+ readonly external: v.ObjectSchema<{
116
+ readonly url: v.StringSchema<undefined>;
117
+ }, undefined>;
118
+ }, undefined>], undefined>], undefined>;
119
+ }, undefined>, v.TransformAction<{
120
+ files: [{
121
+ type: "file";
122
+ file: {
123
+ url: string;
124
+ };
125
+ } | {
126
+ type: "external";
127
+ external: {
128
+ url: string;
129
+ };
130
+ }];
131
+ }, string>]>;
132
+ /**
133
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
134
+ *
135
+ * **Input:**
136
+ * ```
137
+ * {
138
+ * files: Array<{
139
+ * type: "file";
140
+ * file: {
141
+ * url: string;
142
+ * };
143
+ * } | {
144
+ * type: "external";
145
+ * external: {
146
+ * url: string;
147
+ * };
148
+ * }>;
149
+ * }
150
+ * ```
151
+ *
152
+ * **Output:** `string | null`
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * import * as v from "valibot";
157
+ * import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
158
+ *
159
+ * const PageSchema = v.object({
160
+ * id: v.string(),
161
+ * properties: v.object({
162
+ * Attachment: NullableSingleFileSchema,
163
+ * }),
164
+ * });
165
+ *
166
+ * const page = await notion.pages.retrieve({ page_id: "..." });
167
+ * const parsed = v.parse(PageSchema, page);
168
+ * // parsed.properties.Attachment: string | null
169
+ * ```
170
+ */
171
+ declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
172
+ readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
173
+ readonly type: v.LiteralSchema<"file", undefined>;
174
+ readonly file: v.ObjectSchema<{
175
+ readonly url: v.StringSchema<undefined>;
176
+ }, undefined>;
177
+ }, undefined>, v.ObjectSchema<{
178
+ readonly type: v.LiteralSchema<"external", undefined>;
179
+ readonly external: v.ObjectSchema<{
180
+ readonly url: v.StringSchema<undefined>;
181
+ }, undefined>;
182
+ }, undefined>], undefined>, undefined>;
183
+ }, undefined>, v.TransformAction<{
184
+ files: ({
185
+ type: "file";
186
+ file: {
187
+ url: string;
188
+ };
189
+ } | {
190
+ type: "external";
191
+ external: {
192
+ url: string;
193
+ };
194
+ })[];
195
+ }, string | null>]>;
68
196
  //#endregion
69
- export { FilesSchema };
197
+ export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
70
198
  //# sourceMappingURL=files.d.cts.map
package/dist/files.d.mts CHANGED
@@ -26,12 +26,12 @@ import * as v from "valibot";
26
26
  * @example
27
27
  * ```ts
28
28
  * import * as v from "valibot";
29
- * import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
29
+ * import { FileSchema } from "@nakanoaas/notion-valibot-utils";
30
30
  *
31
31
  * const PageSchema = v.object({
32
32
  * id: v.string(),
33
33
  * properties: v.object({
34
- * Files: FilesSchema,
34
+ * Files: FileSchema,
35
35
  * }),
36
36
  * });
37
37
  *
@@ -40,7 +40,7 @@ import * as v from "valibot";
40
40
  * // parsed.properties.Files: string[]
41
41
  * ```
42
42
  */
43
- declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
43
+ declare const FileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
44
44
  readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
45
45
  readonly type: v.LiteralSchema<"file", undefined>;
46
46
  readonly file: v.ObjectSchema<{
@@ -65,6 +65,134 @@ declare const FilesSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
65
65
  };
66
66
  })[];
67
67
  }, string[]>]>;
68
+ /**
69
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL.
70
+ *
71
+ * **Input:**
72
+ * ```
73
+ * {
74
+ * files: [{
75
+ * type: "file";
76
+ * file: {
77
+ * url: string;
78
+ * };
79
+ * } | {
80
+ * type: "external";
81
+ * external: {
82
+ * url: string;
83
+ * };
84
+ * }];
85
+ * }
86
+ * ```
87
+ *
88
+ * **Output:** `string`
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * import * as v from "valibot";
93
+ * import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
94
+ *
95
+ * const PageSchema = v.object({
96
+ * id: v.string(),
97
+ * properties: v.object({
98
+ * Attachment: SingleFileSchema,
99
+ * }),
100
+ * });
101
+ *
102
+ * const page = await notion.pages.retrieve({ page_id: "..." });
103
+ * const parsed = v.parse(PageSchema, page);
104
+ * // parsed.properties.Attachment: string
105
+ * ```
106
+ */
107
+ declare const SingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
108
+ readonly files: v.TupleSchema<[v.VariantSchema<"type", [v.ObjectSchema<{
109
+ readonly type: v.LiteralSchema<"file", undefined>;
110
+ readonly file: v.ObjectSchema<{
111
+ readonly url: v.StringSchema<undefined>;
112
+ }, undefined>;
113
+ }, undefined>, v.ObjectSchema<{
114
+ readonly type: v.LiteralSchema<"external", undefined>;
115
+ readonly external: v.ObjectSchema<{
116
+ readonly url: v.StringSchema<undefined>;
117
+ }, undefined>;
118
+ }, undefined>], undefined>], undefined>;
119
+ }, undefined>, v.TransformAction<{
120
+ files: [{
121
+ type: "file";
122
+ file: {
123
+ url: string;
124
+ };
125
+ } | {
126
+ type: "external";
127
+ external: {
128
+ url: string;
129
+ };
130
+ }];
131
+ }, string>]>;
132
+ /**
133
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
134
+ *
135
+ * **Input:**
136
+ * ```
137
+ * {
138
+ * files: Array<{
139
+ * type: "file";
140
+ * file: {
141
+ * url: string;
142
+ * };
143
+ * } | {
144
+ * type: "external";
145
+ * external: {
146
+ * url: string;
147
+ * };
148
+ * }>;
149
+ * }
150
+ * ```
151
+ *
152
+ * **Output:** `string | null`
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * import * as v from "valibot";
157
+ * import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
158
+ *
159
+ * const PageSchema = v.object({
160
+ * id: v.string(),
161
+ * properties: v.object({
162
+ * Attachment: NullableSingleFileSchema,
163
+ * }),
164
+ * });
165
+ *
166
+ * const page = await notion.pages.retrieve({ page_id: "..." });
167
+ * const parsed = v.parse(PageSchema, page);
168
+ * // parsed.properties.Attachment: string | null
169
+ * ```
170
+ */
171
+ declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
172
+ readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
173
+ readonly type: v.LiteralSchema<"file", undefined>;
174
+ readonly file: v.ObjectSchema<{
175
+ readonly url: v.StringSchema<undefined>;
176
+ }, undefined>;
177
+ }, undefined>, v.ObjectSchema<{
178
+ readonly type: v.LiteralSchema<"external", undefined>;
179
+ readonly external: v.ObjectSchema<{
180
+ readonly url: v.StringSchema<undefined>;
181
+ }, undefined>;
182
+ }, undefined>], undefined>, undefined>;
183
+ }, undefined>, v.TransformAction<{
184
+ files: ({
185
+ type: "file";
186
+ file: {
187
+ url: string;
188
+ };
189
+ } | {
190
+ type: "external";
191
+ external: {
192
+ url: string;
193
+ };
194
+ })[];
195
+ }, string | null>]>;
68
196
  //#endregion
69
- export { FilesSchema };
197
+ export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
70
198
  //# sourceMappingURL=files.d.mts.map
package/dist/files.mjs CHANGED
@@ -1,7 +1,33 @@
1
1
  import * as v from "valibot";
2
-
3
2
  //#region src/files.ts
4
3
  /**
4
+ * Schema for a Notion file object structure.
5
+ *
6
+ * **Input:**
7
+ * ```
8
+ * {
9
+ * type: "file";
10
+ * file: {
11
+ * url: string;
12
+ * };
13
+ * } | {
14
+ * type: "external";
15
+ * external: {
16
+ * url: string;
17
+ * };
18
+ * }
19
+ * ```
20
+ *
21
+ * @internal
22
+ */
23
+ const InnerFileSchema = v.variant("type", [v.object({
24
+ type: v.literal("file"),
25
+ file: v.object({ url: v.string() })
26
+ }), v.object({
27
+ type: v.literal("external"),
28
+ external: v.object({ url: v.string() })
29
+ })]);
30
+ /**
5
31
  * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
6
32
  *
7
33
  * **Input:**
@@ -26,12 +52,12 @@ import * as v from "valibot";
26
52
  * @example
27
53
  * ```ts
28
54
  * import * as v from "valibot";
29
- * import { FilesSchema } from "@nakanoaas/notion-valibot-utils";
55
+ * import { FileSchema } from "@nakanoaas/notion-valibot-utils";
30
56
  *
31
57
  * const PageSchema = v.object({
32
58
  * id: v.string(),
33
59
  * properties: v.object({
34
- * Files: FilesSchema,
60
+ * Files: FileSchema,
35
61
  * }),
36
62
  * });
37
63
  *
@@ -40,14 +66,95 @@ import * as v from "valibot";
40
66
  * // parsed.properties.Files: string[]
41
67
  * ```
42
68
  */
43
- const FilesSchema = v.pipe(v.object({ files: v.array(v.variant("type", [v.object({
44
- type: v.literal("file"),
45
- file: v.object({ url: v.string() })
46
- }), v.object({
47
- type: v.literal("external"),
48
- external: v.object({ url: v.string() })
49
- })])) }), v.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
50
-
69
+ const FileSchema = v.pipe(v.object({ files: v.array(InnerFileSchema) }), v.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
70
+ /**
71
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL.
72
+ *
73
+ * **Input:**
74
+ * ```
75
+ * {
76
+ * files: [{
77
+ * type: "file";
78
+ * file: {
79
+ * url: string;
80
+ * };
81
+ * } | {
82
+ * type: "external";
83
+ * external: {
84
+ * url: string;
85
+ * };
86
+ * }];
87
+ * }
88
+ * ```
89
+ *
90
+ * **Output:** `string`
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import * as v from "valibot";
95
+ * import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
96
+ *
97
+ * const PageSchema = v.object({
98
+ * id: v.string(),
99
+ * properties: v.object({
100
+ * Attachment: SingleFileSchema,
101
+ * }),
102
+ * });
103
+ *
104
+ * const page = await notion.pages.retrieve({ page_id: "..." });
105
+ * const parsed = v.parse(PageSchema, page);
106
+ * // parsed.properties.Attachment: string
107
+ * ```
108
+ */
109
+ const SingleFileSchema = v.pipe(v.object({ files: v.tuple([InnerFileSchema]) }), v.transform((v) => {
110
+ const file = v.files[0];
111
+ return file.type === "file" ? file.file.url : file.external.url;
112
+ }));
113
+ /**
114
+ * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
115
+ *
116
+ * **Input:**
117
+ * ```
118
+ * {
119
+ * files: Array<{
120
+ * type: "file";
121
+ * file: {
122
+ * url: string;
123
+ * };
124
+ * } | {
125
+ * type: "external";
126
+ * external: {
127
+ * url: string;
128
+ * };
129
+ * }>;
130
+ * }
131
+ * ```
132
+ *
133
+ * **Output:** `string | null`
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import * as v from "valibot";
138
+ * import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
139
+ *
140
+ * const PageSchema = v.object({
141
+ * id: v.string(),
142
+ * properties: v.object({
143
+ * Attachment: NullableSingleFileSchema,
144
+ * }),
145
+ * });
146
+ *
147
+ * const page = await notion.pages.retrieve({ page_id: "..." });
148
+ * const parsed = v.parse(PageSchema, page);
149
+ * // parsed.properties.Attachment: string | null
150
+ * ```
151
+ */
152
+ const NullableSingleFileSchema = v.pipe(v.object({ files: v.array(InnerFileSchema) }), v.transform((v) => {
153
+ const file = v.files[0];
154
+ if (!file) return null;
155
+ return file.type === "file" ? file.file.url : file.external.url;
156
+ }));
51
157
  //#endregion
52
- export { FilesSchema };
158
+ export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
159
+
53
160
  //# sourceMappingURL=files.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.mjs","names":[],"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,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,IAAK,CACrE,CACD"}
1
+ {"version":3,"file":"files.mjs","names":[],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\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 { FileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileSchema,\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 FileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\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\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\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 { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\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 | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB,EAAE,QAAQ,QAAQ,CACzC,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,OAAO,EACd,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,GACD,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU,EAAE,OAAO,EAClB,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,aAAa,EAAE,KAC3B,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}