@nakanoaas/notion-valibot-schema 0.0.4 → 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.
Files changed (133) hide show
  1. package/dist/checkbox.cjs +29 -0
  2. package/dist/checkbox.cjs.map +1 -1
  3. package/dist/checkbox.d.cts +30 -0
  4. package/dist/checkbox.d.mts +30 -0
  5. package/dist/checkbox.mjs +29 -0
  6. package/dist/checkbox.mjs.map +1 -1
  7. package/dist/created-by.cjs +75 -0
  8. package/dist/created-by.cjs.map +1 -1
  9. package/dist/created-by.d.cts +76 -0
  10. package/dist/created-by.d.mts +76 -0
  11. package/dist/created-by.mjs +75 -0
  12. package/dist/created-by.mjs.map +1 -1
  13. package/dist/created-time.cjs +27 -0
  14. package/dist/created-time.cjs.map +1 -1
  15. package/dist/created-time.d.cts +28 -0
  16. package/dist/created-time.d.mts +28 -0
  17. package/dist/created-time.mjs +27 -0
  18. package/dist/created-time.mjs.map +1 -1
  19. package/dist/date.cjs +188 -0
  20. package/dist/date.cjs.map +1 -1
  21. package/dist/date.d.cts +189 -0
  22. package/dist/date.d.mts +189 -0
  23. package/dist/date.mjs +188 -0
  24. package/dist/date.mjs.map +1 -1
  25. package/dist/email.cjs +58 -0
  26. package/dist/email.cjs.map +1 -1
  27. package/dist/email.d.cts +59 -0
  28. package/dist/email.d.mts +59 -0
  29. package/dist/email.mjs +58 -0
  30. package/dist/email.mjs.map +1 -1
  31. package/dist/files.cjs +39 -0
  32. package/dist/files.cjs.map +1 -1
  33. package/dist/files.d.cts +40 -0
  34. package/dist/files.d.mts +40 -0
  35. package/dist/files.mjs +39 -0
  36. package/dist/files.mjs.map +1 -1
  37. package/dist/formula.cjs +72 -0
  38. package/dist/formula.cjs.map +1 -1
  39. package/dist/formula.d.cts +73 -0
  40. package/dist/formula.d.mts +73 -0
  41. package/dist/formula.mjs +72 -0
  42. package/dist/formula.mjs.map +1 -1
  43. package/dist/last-edited-by.cjs +68 -0
  44. package/dist/last-edited-by.cjs.map +1 -1
  45. package/dist/last-edited-by.d.cts +69 -0
  46. package/dist/last-edited-by.d.mts +69 -0
  47. package/dist/last-edited-by.mjs +68 -0
  48. package/dist/last-edited-by.mjs.map +1 -1
  49. package/dist/last-edited-time.cjs +27 -0
  50. package/dist/last-edited-time.cjs.map +1 -1
  51. package/dist/last-edited-time.d.cts +28 -0
  52. package/dist/last-edited-time.d.mts +28 -0
  53. package/dist/last-edited-time.mjs +27 -0
  54. package/dist/last-edited-time.mjs.map +1 -1
  55. package/dist/multi-select.cjs +60 -0
  56. package/dist/multi-select.cjs.map +1 -1
  57. package/dist/multi-select.d.cts +61 -0
  58. package/dist/multi-select.d.mts +61 -0
  59. package/dist/multi-select.mjs +60 -0
  60. package/dist/multi-select.mjs.map +1 -1
  61. package/dist/number.cjs +58 -0
  62. package/dist/number.cjs.map +1 -1
  63. package/dist/number.d.cts +59 -0
  64. package/dist/number.d.mts +59 -0
  65. package/dist/number.mjs +58 -0
  66. package/dist/number.mjs.map +1 -1
  67. package/dist/people.cjs +84 -0
  68. package/dist/people.cjs.map +1 -1
  69. package/dist/people.d.cts +85 -0
  70. package/dist/people.d.mts +85 -0
  71. package/dist/people.mjs +84 -0
  72. package/dist/people.mjs.map +1 -1
  73. package/dist/phone-number.cjs +58 -0
  74. package/dist/phone-number.cjs.map +1 -1
  75. package/dist/phone-number.d.cts +59 -0
  76. package/dist/phone-number.d.mts +59 -0
  77. package/dist/phone-number.mjs +58 -0
  78. package/dist/phone-number.mjs.map +1 -1
  79. package/dist/place.cjs +128 -0
  80. package/dist/place.cjs.map +1 -1
  81. package/dist/place.d.cts +85 -0
  82. package/dist/place.d.mts +85 -0
  83. package/dist/place.mjs +128 -0
  84. package/dist/place.mjs.map +1 -1
  85. package/dist/relation.cjs +131 -0
  86. package/dist/relation.cjs.map +1 -1
  87. package/dist/relation.d.cts +94 -0
  88. package/dist/relation.d.mts +94 -0
  89. package/dist/relation.mjs +131 -0
  90. package/dist/relation.mjs.map +1 -1
  91. package/dist/rollup.cjs +200 -0
  92. package/dist/rollup.cjs.map +1 -1
  93. package/dist/rollup.d.cts +201 -0
  94. package/dist/rollup.d.mts +201 -0
  95. package/dist/rollup.mjs +200 -0
  96. package/dist/rollup.mjs.map +1 -1
  97. package/dist/select.cjs +120 -0
  98. package/dist/select.cjs.map +1 -1
  99. package/dist/select.d.cts +121 -0
  100. package/dist/select.d.mts +121 -0
  101. package/dist/select.mjs +120 -0
  102. package/dist/select.mjs.map +1 -1
  103. package/dist/status.cjs +120 -0
  104. package/dist/status.cjs.map +1 -1
  105. package/dist/status.d.cts +121 -0
  106. package/dist/status.d.mts +121 -0
  107. package/dist/status.mjs +120 -0
  108. package/dist/status.mjs.map +1 -1
  109. package/dist/text.cjs +100 -0
  110. package/dist/text.cjs.map +1 -1
  111. package/dist/text.d.cts +63 -0
  112. package/dist/text.d.mts +63 -0
  113. package/dist/text.mjs +100 -0
  114. package/dist/text.mjs.map +1 -1
  115. package/dist/unique-id.cjs +69 -0
  116. package/dist/unique-id.cjs.map +1 -1
  117. package/dist/unique-id.d.cts +70 -0
  118. package/dist/unique-id.d.mts +70 -0
  119. package/dist/unique-id.mjs +69 -0
  120. package/dist/unique-id.mjs.map +1 -1
  121. package/dist/url.cjs +58 -0
  122. package/dist/url.cjs.map +1 -1
  123. package/dist/url.d.cts +59 -0
  124. package/dist/url.d.mts +59 -0
  125. package/dist/url.mjs +58 -0
  126. package/dist/url.mjs.map +1 -1
  127. package/dist/verification.cjs +80 -0
  128. package/dist/verification.cjs.map +1 -1
  129. package/dist/verification.d.cts +81 -0
  130. package/dist/verification.d.mts +81 -0
  131. package/dist/verification.mjs +80 -0
  132. package/dist/verification.mjs.map +1 -1
  133. package/package.json +1 -1
package/dist/rollup.cjs CHANGED
@@ -4,22 +4,222 @@ let valibot = require("valibot");
4
4
  valibot = require_rolldown_runtime.__toESM(valibot);
5
5
 
6
6
  //#region src/rollup.ts
7
+ /**
8
+ * Schema to extract the `rollup` property with number type from a Notion page property or `null`.
9
+ *
10
+ * **Input:**
11
+ * ```
12
+ * {
13
+ * rollup: {
14
+ * type: "number";
15
+ * number: number | null;
16
+ * };
17
+ * }
18
+ * ```
19
+ *
20
+ * **Output:** `number | null`
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import * as v from "valibot";
25
+ * import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
26
+ *
27
+ * const PageSchema = v.object({
28
+ * id: v.string(),
29
+ * properties: v.object({
30
+ * Sum: NullableRollupNumberSchema,
31
+ * }),
32
+ * });
33
+ *
34
+ * const page = await notion.pages.retrieve({ page_id: "..." });
35
+ * const parsed = v.parse(PageSchema, page);
36
+ * // parsed.properties.Sum: number | null
37
+ * ```
38
+ */
7
39
  const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
8
40
  type: valibot.literal("number"),
9
41
  number: valibot.nullable(valibot.number())
10
42
  }) }), valibot.transform((v) => v.rollup.number));
43
+ /**
44
+ * Schema to extract the `rollup` property with number type from a Notion page property.
45
+ *
46
+ * **Input:**
47
+ * ```
48
+ * {
49
+ * rollup: {
50
+ * type: "number";
51
+ * number: number;
52
+ * };
53
+ * }
54
+ * ```
55
+ *
56
+ * **Output:** `number`
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import * as v from "valibot";
61
+ * import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
62
+ *
63
+ * const PageSchema = v.object({
64
+ * id: v.string(),
65
+ * properties: v.object({
66
+ * Sum: RollupNumberSchema,
67
+ * }),
68
+ * });
69
+ *
70
+ * const page = await notion.pages.retrieve({ page_id: "..." });
71
+ * const parsed = v.parse(PageSchema, page);
72
+ * // parsed.properties.Sum: number
73
+ * ```
74
+ */
11
75
  const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
12
76
  type: valibot.literal("number"),
13
77
  number: valibot.number()
14
78
  }) }), valibot.transform((v) => v.rollup.number));
79
+ /**
80
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
81
+ *
82
+ * **Input:**
83
+ * ```
84
+ * {
85
+ * rollup: {
86
+ * type: "date";
87
+ * date: {
88
+ * start: string;
89
+ * end: string | null;
90
+ * time_zone: string | null;
91
+ * } | null;
92
+ * };
93
+ * }
94
+ * ```
95
+ *
96
+ * **Output:** `Date | null`
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import * as v from "valibot";
101
+ * import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
102
+ *
103
+ * const PageSchema = v.object({
104
+ * id: v.string(),
105
+ * properties: v.object({
106
+ * LatestDate: NullableRollupDateSchema,
107
+ * }),
108
+ * });
109
+ *
110
+ * const page = await notion.pages.retrieve({ page_id: "..." });
111
+ * const parsed = v.parse(PageSchema, page);
112
+ * // parsed.properties.LatestDate: Date | null
113
+ * ```
114
+ */
15
115
  const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
16
116
  type: valibot.literal("date"),
17
117
  date: valibot.nullable(require_date.DateObjectSchema)
18
118
  }) }), valibot.transform((v) => v.rollup.date ? new Date(v.rollup.date.start) : null));
119
+ /**
120
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
121
+ *
122
+ * **Input:**
123
+ * ```
124
+ * {
125
+ * rollup: {
126
+ * type: "date";
127
+ * date: {
128
+ * start: string;
129
+ * end: string | null;
130
+ * time_zone: string | null;
131
+ * };
132
+ * };
133
+ * }
134
+ * ```
135
+ *
136
+ * **Output:** `Date`
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import * as v from "valibot";
141
+ * import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
142
+ *
143
+ * const PageSchema = v.object({
144
+ * id: v.string(),
145
+ * properties: v.object({
146
+ * LatestDate: RollupDateSchema,
147
+ * }),
148
+ * });
149
+ *
150
+ * const page = await notion.pages.retrieve({ page_id: "..." });
151
+ * const parsed = v.parse(PageSchema, page);
152
+ * // parsed.properties.LatestDate: Date
153
+ * ```
154
+ */
19
155
  const RollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
20
156
  type: valibot.literal("date"),
21
157
  date: require_date.DateObjectSchema
22
158
  }) }), valibot.transform((v) => new Date(v.rollup.date.start)));
159
+ /**
160
+ * Schema factory to extract the `rollup` property with array type from a Notion page property.
161
+ *
162
+ * This is a generic schema factory that accepts another schema as a parameter,
163
+ * allowing you to combine it with other schemas in this library to extract
164
+ * typed rollup array results. The rollup property in Notion can return an
165
+ * array of different types of values depending on the rollup configuration.
166
+ *
167
+ * **Input:**
168
+ * ```
169
+ * {
170
+ * rollup: {
171
+ * type: "array";
172
+ * array: Array<{ type: string; ... }>;
173
+ * };
174
+ * }
175
+ * ```
176
+ *
177
+ * **Output:** The output type depends on the schema passed as a parameter.
178
+ * For example, if a schema for number properties is passed, the output will be `Array<number>`.
179
+ *
180
+ * @param schema - A schema that validates each element in the rollup array.
181
+ * Must accept an object with a `type` field.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import * as v from "valibot";
186
+ * import { RollupArraySchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
187
+ *
188
+ * const PageSchema = v.object({
189
+ * id: v.string(),
190
+ * properties: v.object({
191
+ * RollupNumbers: RollupArraySchema(NumberSchema),
192
+ * }),
193
+ * });
194
+ *
195
+ * const page = await notion.pages.retrieve({ page_id: "..." });
196
+ * const parsed = v.parse(PageSchema, page);
197
+ * // parsed.properties.RollupNumbers: number[]
198
+ * ```
199
+ *
200
+ * @example
201
+ * ```ts
202
+ * import * as v from "valibot";
203
+ * import { RollupArraySchema } from "@nakanoaas/notion-valibot-utils";
204
+ *
205
+ * // Custom schema for relation rollup
206
+ * const RelationItemSchema = v.object({
207
+ * type: v.literal("relation"),
208
+ * relation: v.array(v.object({ id: v.string() })),
209
+ * });
210
+ *
211
+ * const PageSchema = v.object({
212
+ * id: v.string(),
213
+ * properties: v.object({
214
+ * RollupRelations: RollupArraySchema(RelationItemSchema),
215
+ * }),
216
+ * });
217
+ *
218
+ * const page = await notion.pages.retrieve({ page_id: "..." });
219
+ * const parsed = v.parse(PageSchema, page);
220
+ * // parsed.properties.RollupRelations: Array<{ type: "relation"; relation: Array<{ id: string }> }>
221
+ * ```
222
+ */
23
223
  function RollupArraySchema(schema) {
24
224
  return valibot.pipe(valibot.object({ rollup: valibot.object({
25
225
  type: valibot.literal("array"),
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.cjs","names":["v","DateObjectSchema"],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\nexport function RollupArraySchema<\n\tS extends v.GenericSchema<{ type: string }, unknown>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n"],"mappings":";;;;;;AAIA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,SAASA,QAAE,QAAQ,CAAC;CAC9B,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;AAED,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,QAAQ;CAClB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;AAED,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMA,QAAE,SAASC,8BAAiB;CAClC,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,KAAM,CAC1E;AAED,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMC;CACN,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CACjD;AAED,SAAgB,kBAEd,QAAW;AACZ,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,QAAQ;EACxB,OAAOA,QAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CAClC"}
1
+ {"version":3,"file":"rollup.cjs","names":["v","DateObjectSchema"],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number | null;\n * };\n * }\n * ```\n *\n * **Output:** `number | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: NullableRollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number | null\n * ```\n */\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number;\n * };\n * }\n * ```\n *\n * **Output:** `number`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n */\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * };\n * }\n * ```\n *\n * **Output:** `Date | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: NullableRollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date | null\n * ```\n */\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * };\n * };\n * }\n * ```\n *\n * **Output:** `Date`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\n/**\n * Schema factory to extract the `rollup` property with array type 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 rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<\n\tS extends v.GenericSchema<{ type: string }, unknown>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,SAASA,QAAE,QAAQ,CAAC;CAC9B,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCD,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,QAAQ;CAClB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMA,QAAE,SAASC,8BAAiB;CAClC,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,KAAM,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMC;CACN,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkED,SAAgB,kBAEd,QAAW;AACZ,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,QAAQ;EACxB,OAAOA,QAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CAClC"}
package/dist/rollup.d.cts CHANGED
@@ -1,6 +1,39 @@
1
1
  import * as v from "valibot";
2
2
 
3
3
  //#region src/rollup.d.ts
4
+
5
+ /**
6
+ * Schema to extract the `rollup` property with number type from a Notion page property or `null`.
7
+ *
8
+ * **Input:**
9
+ * ```
10
+ * {
11
+ * rollup: {
12
+ * type: "number";
13
+ * number: number | null;
14
+ * };
15
+ * }
16
+ * ```
17
+ *
18
+ * **Output:** `number | null`
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import * as v from "valibot";
23
+ * import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
24
+ *
25
+ * const PageSchema = v.object({
26
+ * id: v.string(),
27
+ * properties: v.object({
28
+ * Sum: NullableRollupNumberSchema,
29
+ * }),
30
+ * });
31
+ *
32
+ * const page = await notion.pages.retrieve({ page_id: "..." });
33
+ * const parsed = v.parse(PageSchema, page);
34
+ * // parsed.properties.Sum: number | null
35
+ * ```
36
+ */
4
37
  declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
5
38
  readonly rollup: v.ObjectSchema<{
6
39
  readonly type: v.LiteralSchema<"number", undefined>;
@@ -12,6 +45,38 @@ declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSch
12
45
  number: number | null;
13
46
  };
14
47
  }, number | null>]>;
48
+ /**
49
+ * Schema to extract the `rollup` property with number type from a Notion page property.
50
+ *
51
+ * **Input:**
52
+ * ```
53
+ * {
54
+ * rollup: {
55
+ * type: "number";
56
+ * number: number;
57
+ * };
58
+ * }
59
+ * ```
60
+ *
61
+ * **Output:** `number`
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import * as v from "valibot";
66
+ * import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
67
+ *
68
+ * const PageSchema = v.object({
69
+ * id: v.string(),
70
+ * properties: v.object({
71
+ * Sum: RollupNumberSchema,
72
+ * }),
73
+ * });
74
+ *
75
+ * const page = await notion.pages.retrieve({ page_id: "..." });
76
+ * const parsed = v.parse(PageSchema, page);
77
+ * // parsed.properties.Sum: number
78
+ * ```
79
+ */
15
80
  declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
16
81
  readonly rollup: v.ObjectSchema<{
17
82
  readonly type: v.LiteralSchema<"number", undefined>;
@@ -23,6 +88,42 @@ declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
23
88
  number: number;
24
89
  };
25
90
  }, number>]>;
91
+ /**
92
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
93
+ *
94
+ * **Input:**
95
+ * ```
96
+ * {
97
+ * rollup: {
98
+ * type: "date";
99
+ * date: {
100
+ * start: string;
101
+ * end: string | null;
102
+ * time_zone: string | null;
103
+ * } | null;
104
+ * };
105
+ * }
106
+ * ```
107
+ *
108
+ * **Output:** `Date | null`
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import * as v from "valibot";
113
+ * import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
114
+ *
115
+ * const PageSchema = v.object({
116
+ * id: v.string(),
117
+ * properties: v.object({
118
+ * LatestDate: NullableRollupDateSchema,
119
+ * }),
120
+ * });
121
+ *
122
+ * const page = await notion.pages.retrieve({ page_id: "..." });
123
+ * const parsed = v.parse(PageSchema, page);
124
+ * // parsed.properties.LatestDate: Date | null
125
+ * ```
126
+ */
26
127
  declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
27
128
  readonly rollup: v.ObjectSchema<{
28
129
  readonly type: v.LiteralSchema<"date", undefined>;
@@ -42,6 +143,42 @@ declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchem
42
143
  } | null;
43
144
  };
44
145
  }, Date | null>]>;
146
+ /**
147
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
148
+ *
149
+ * **Input:**
150
+ * ```
151
+ * {
152
+ * rollup: {
153
+ * type: "date";
154
+ * date: {
155
+ * start: string;
156
+ * end: string | null;
157
+ * time_zone: string | null;
158
+ * };
159
+ * };
160
+ * }
161
+ * ```
162
+ *
163
+ * **Output:** `Date`
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * import * as v from "valibot";
168
+ * import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
169
+ *
170
+ * const PageSchema = v.object({
171
+ * id: v.string(),
172
+ * properties: v.object({
173
+ * LatestDate: RollupDateSchema,
174
+ * }),
175
+ * });
176
+ *
177
+ * const page = await notion.pages.retrieve({ page_id: "..." });
178
+ * const parsed = v.parse(PageSchema, page);
179
+ * // parsed.properties.LatestDate: Date
180
+ * ```
181
+ */
45
182
  declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
46
183
  readonly rollup: v.ObjectSchema<{
47
184
  readonly type: v.LiteralSchema<"date", undefined>;
@@ -61,6 +198,70 @@ declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
61
198
  };
62
199
  };
63
200
  }, Date>]>;
201
+ /**
202
+ * Schema factory to extract the `rollup` property with array type from a Notion page property.
203
+ *
204
+ * This is a generic schema factory that accepts another schema as a parameter,
205
+ * allowing you to combine it with other schemas in this library to extract
206
+ * typed rollup array results. The rollup property in Notion can return an
207
+ * array of different types of values depending on the rollup configuration.
208
+ *
209
+ * **Input:**
210
+ * ```
211
+ * {
212
+ * rollup: {
213
+ * type: "array";
214
+ * array: Array<{ type: string; ... }>;
215
+ * };
216
+ * }
217
+ * ```
218
+ *
219
+ * **Output:** The output type depends on the schema passed as a parameter.
220
+ * For example, if a schema for number properties is passed, the output will be `Array<number>`.
221
+ *
222
+ * @param schema - A schema that validates each element in the rollup array.
223
+ * Must accept an object with a `type` field.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * import * as v from "valibot";
228
+ * import { RollupArraySchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
229
+ *
230
+ * const PageSchema = v.object({
231
+ * id: v.string(),
232
+ * properties: v.object({
233
+ * RollupNumbers: RollupArraySchema(NumberSchema),
234
+ * }),
235
+ * });
236
+ *
237
+ * const page = await notion.pages.retrieve({ page_id: "..." });
238
+ * const parsed = v.parse(PageSchema, page);
239
+ * // parsed.properties.RollupNumbers: number[]
240
+ * ```
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * import * as v from "valibot";
245
+ * import { RollupArraySchema } from "@nakanoaas/notion-valibot-utils";
246
+ *
247
+ * // Custom schema for relation rollup
248
+ * const RelationItemSchema = v.object({
249
+ * type: v.literal("relation"),
250
+ * relation: v.array(v.object({ id: v.string() })),
251
+ * });
252
+ *
253
+ * const PageSchema = v.object({
254
+ * id: v.string(),
255
+ * properties: v.object({
256
+ * RollupRelations: RollupArraySchema(RelationItemSchema),
257
+ * }),
258
+ * });
259
+ *
260
+ * const page = await notion.pages.retrieve({ page_id: "..." });
261
+ * const parsed = v.parse(PageSchema, page);
262
+ * // parsed.properties.RollupRelations: Array<{ type: "relation"; relation: Array<{ id: string }> }>
263
+ * ```
264
+ */
64
265
  declare function RollupArraySchema<S extends v.GenericSchema<{
65
266
  type: string;
66
267
  }, unknown>>(schema: S): v.SchemaWithPipe<readonly [v.ObjectSchema<{