@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.
Files changed (138) hide show
  1. package/README.md +26 -24
  2. package/dist/checkbox.cjs +29 -0
  3. package/dist/checkbox.cjs.map +1 -1
  4. package/dist/checkbox.d.cts +30 -0
  5. package/dist/checkbox.d.mts +30 -0
  6. package/dist/checkbox.mjs +29 -0
  7. package/dist/checkbox.mjs.map +1 -1
  8. package/dist/created-by.cjs +75 -0
  9. package/dist/created-by.cjs.map +1 -1
  10. package/dist/created-by.d.cts +76 -0
  11. package/dist/created-by.d.mts +76 -0
  12. package/dist/created-by.mjs +75 -0
  13. package/dist/created-by.mjs.map +1 -1
  14. package/dist/created-time.cjs +27 -0
  15. package/dist/created-time.cjs.map +1 -1
  16. package/dist/created-time.d.cts +28 -0
  17. package/dist/created-time.d.mts +28 -0
  18. package/dist/created-time.mjs +27 -0
  19. package/dist/created-time.mjs.map +1 -1
  20. package/dist/date.cjs +203 -13
  21. package/dist/date.cjs.map +1 -1
  22. package/dist/date.d.cts +214 -6
  23. package/dist/date.d.mts +214 -6
  24. package/dist/date.mjs +201 -12
  25. package/dist/date.mjs.map +1 -1
  26. package/dist/email.cjs +58 -0
  27. package/dist/email.cjs.map +1 -1
  28. package/dist/email.d.cts +59 -0
  29. package/dist/email.d.mts +59 -0
  30. package/dist/email.mjs +58 -0
  31. package/dist/email.mjs.map +1 -1
  32. package/dist/files.cjs +39 -0
  33. package/dist/files.cjs.map +1 -1
  34. package/dist/files.d.cts +40 -0
  35. package/dist/files.d.mts +40 -0
  36. package/dist/files.mjs +39 -0
  37. package/dist/files.mjs.map +1 -1
  38. package/dist/formula.cjs +72 -0
  39. package/dist/formula.cjs.map +1 -1
  40. package/dist/formula.d.cts +73 -0
  41. package/dist/formula.d.mts +73 -0
  42. package/dist/formula.mjs +72 -0
  43. package/dist/formula.mjs.map +1 -1
  44. package/dist/index.cjs +7 -3
  45. package/dist/index.d.cts +4 -4
  46. package/dist/index.d.mts +4 -4
  47. package/dist/index.mjs +4 -4
  48. package/dist/last-edited-by.cjs +68 -0
  49. package/dist/last-edited-by.cjs.map +1 -1
  50. package/dist/last-edited-by.d.cts +69 -0
  51. package/dist/last-edited-by.d.mts +69 -0
  52. package/dist/last-edited-by.mjs +68 -0
  53. package/dist/last-edited-by.mjs.map +1 -1
  54. package/dist/last-edited-time.cjs +27 -0
  55. package/dist/last-edited-time.cjs.map +1 -1
  56. package/dist/last-edited-time.d.cts +28 -0
  57. package/dist/last-edited-time.d.mts +28 -0
  58. package/dist/last-edited-time.mjs +27 -0
  59. package/dist/last-edited-time.mjs.map +1 -1
  60. package/dist/multi-select.cjs +60 -0
  61. package/dist/multi-select.cjs.map +1 -1
  62. package/dist/multi-select.d.cts +61 -0
  63. package/dist/multi-select.d.mts +61 -0
  64. package/dist/multi-select.mjs +60 -0
  65. package/dist/multi-select.mjs.map +1 -1
  66. package/dist/number.cjs +58 -0
  67. package/dist/number.cjs.map +1 -1
  68. package/dist/number.d.cts +59 -0
  69. package/dist/number.d.mts +59 -0
  70. package/dist/number.mjs +58 -0
  71. package/dist/number.mjs.map +1 -1
  72. package/dist/people.cjs +84 -0
  73. package/dist/people.cjs.map +1 -1
  74. package/dist/people.d.cts +85 -0
  75. package/dist/people.d.mts +85 -0
  76. package/dist/people.mjs +84 -0
  77. package/dist/people.mjs.map +1 -1
  78. package/dist/phone-number.cjs +58 -0
  79. package/dist/phone-number.cjs.map +1 -1
  80. package/dist/phone-number.d.cts +59 -0
  81. package/dist/phone-number.d.mts +59 -0
  82. package/dist/phone-number.mjs +58 -0
  83. package/dist/phone-number.mjs.map +1 -1
  84. package/dist/place.cjs +128 -0
  85. package/dist/place.cjs.map +1 -1
  86. package/dist/place.d.cts +85 -0
  87. package/dist/place.d.mts +85 -0
  88. package/dist/place.mjs +128 -0
  89. package/dist/place.mjs.map +1 -1
  90. package/dist/relation.cjs +137 -1
  91. package/dist/relation.cjs.map +1 -1
  92. package/dist/relation.d.cts +113 -1
  93. package/dist/relation.d.mts +113 -1
  94. package/dist/relation.mjs +136 -2
  95. package/dist/relation.mjs.map +1 -1
  96. package/dist/rollup.cjs +203 -10
  97. package/dist/rollup.cjs.map +1 -1
  98. package/dist/rollup.d.cts +201 -0
  99. package/dist/rollup.d.mts +201 -0
  100. package/dist/rollup.mjs +203 -10
  101. package/dist/rollup.mjs.map +1 -1
  102. package/dist/select.cjs +120 -0
  103. package/dist/select.cjs.map +1 -1
  104. package/dist/select.d.cts +121 -0
  105. package/dist/select.d.mts +121 -0
  106. package/dist/select.mjs +120 -0
  107. package/dist/select.mjs.map +1 -1
  108. package/dist/status.cjs +120 -0
  109. package/dist/status.cjs.map +1 -1
  110. package/dist/status.d.cts +121 -0
  111. package/dist/status.d.mts +121 -0
  112. package/dist/status.mjs +120 -0
  113. package/dist/status.mjs.map +1 -1
  114. package/dist/text.cjs +103 -3
  115. package/dist/text.cjs.map +1 -1
  116. package/dist/text.d.cts +73 -10
  117. package/dist/text.d.mts +73 -10
  118. package/dist/text.mjs +103 -3
  119. package/dist/text.mjs.map +1 -1
  120. package/dist/unique-id.cjs +73 -2
  121. package/dist/unique-id.cjs.map +1 -1
  122. package/dist/unique-id.d.cts +81 -2
  123. package/dist/unique-id.d.mts +81 -2
  124. package/dist/unique-id.mjs +72 -2
  125. package/dist/unique-id.mjs.map +1 -1
  126. package/dist/url.cjs +58 -0
  127. package/dist/url.cjs.map +1 -1
  128. package/dist/url.d.cts +59 -0
  129. package/dist/url.d.mts +59 -0
  130. package/dist/url.mjs +58 -0
  131. package/dist/url.mjs.map +1 -1
  132. package/dist/verification.cjs +82 -5
  133. package/dist/verification.cjs.map +1 -1
  134. package/dist/verification.d.cts +81 -0
  135. package/dist/verification.d.mts +81 -0
  136. package/dist/verification.mjs +82 -5
  137. package/dist/verification.mjs.map +1 -1
  138. package/package.json +1 -1
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<{
package/dist/rollup.d.mts 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<{
package/dist/rollup.mjs CHANGED
@@ -1,30 +1,223 @@
1
+ import { DateObjectSchema } from "./date.mjs";
1
2
  import * as v from "valibot";
2
3
 
3
4
  //#region src/rollup.ts
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
  const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
5
38
  type: v.literal("number"),
6
39
  number: v.nullable(v.number())
7
40
  }) }), v.transform((v$1) => v$1.rollup.number));
41
+ /**
42
+ * Schema to extract the `rollup` property with number type from a Notion page property.
43
+ *
44
+ * **Input:**
45
+ * ```
46
+ * {
47
+ * rollup: {
48
+ * type: "number";
49
+ * number: number;
50
+ * };
51
+ * }
52
+ * ```
53
+ *
54
+ * **Output:** `number`
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import * as v from "valibot";
59
+ * import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
60
+ *
61
+ * const PageSchema = v.object({
62
+ * id: v.string(),
63
+ * properties: v.object({
64
+ * Sum: RollupNumberSchema,
65
+ * }),
66
+ * });
67
+ *
68
+ * const page = await notion.pages.retrieve({ page_id: "..." });
69
+ * const parsed = v.parse(PageSchema, page);
70
+ * // parsed.properties.Sum: number
71
+ * ```
72
+ */
8
73
  const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
9
74
  type: v.literal("number"),
10
75
  number: v.number()
11
76
  }) }), v.transform((v$1) => v$1.rollup.number));
77
+ /**
78
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
79
+ *
80
+ * **Input:**
81
+ * ```
82
+ * {
83
+ * rollup: {
84
+ * type: "date";
85
+ * date: {
86
+ * start: string;
87
+ * end: string | null;
88
+ * time_zone: string | null;
89
+ * } | null;
90
+ * };
91
+ * }
92
+ * ```
93
+ *
94
+ * **Output:** `Date | null`
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import * as v from "valibot";
99
+ * import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
100
+ *
101
+ * const PageSchema = v.object({
102
+ * id: v.string(),
103
+ * properties: v.object({
104
+ * LatestDate: NullableRollupDateSchema,
105
+ * }),
106
+ * });
107
+ *
108
+ * const page = await notion.pages.retrieve({ page_id: "..." });
109
+ * const parsed = v.parse(PageSchema, page);
110
+ * // parsed.properties.LatestDate: Date | null
111
+ * ```
112
+ */
12
113
  const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
13
114
  type: v.literal("date"),
14
- date: v.nullable(v.object({
15
- start: v.string(),
16
- end: v.nullable(v.string()),
17
- time_zone: v.nullable(v.string())
18
- }))
115
+ date: v.nullable(DateObjectSchema)
19
116
  }) }), v.transform((v$1) => v$1.rollup.date ? new Date(v$1.rollup.date.start) : null));
117
+ /**
118
+ * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
119
+ *
120
+ * **Input:**
121
+ * ```
122
+ * {
123
+ * rollup: {
124
+ * type: "date";
125
+ * date: {
126
+ * start: string;
127
+ * end: string | null;
128
+ * time_zone: string | null;
129
+ * };
130
+ * };
131
+ * }
132
+ * ```
133
+ *
134
+ * **Output:** `Date`
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import * as v from "valibot";
139
+ * import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
140
+ *
141
+ * const PageSchema = v.object({
142
+ * id: v.string(),
143
+ * properties: v.object({
144
+ * LatestDate: RollupDateSchema,
145
+ * }),
146
+ * });
147
+ *
148
+ * const page = await notion.pages.retrieve({ page_id: "..." });
149
+ * const parsed = v.parse(PageSchema, page);
150
+ * // parsed.properties.LatestDate: Date
151
+ * ```
152
+ */
20
153
  const RollupDateSchema = v.pipe(v.object({ rollup: v.object({
21
154
  type: v.literal("date"),
22
- date: v.object({
23
- start: v.string(),
24
- end: v.nullable(v.string()),
25
- time_zone: v.nullable(v.string())
26
- })
155
+ date: DateObjectSchema
27
156
  }) }), v.transform((v$1) => new Date(v$1.rollup.date.start)));
157
+ /**
158
+ * Schema factory to extract the `rollup` property with array type from a Notion page property.
159
+ *
160
+ * This is a generic schema factory that accepts another schema as a parameter,
161
+ * allowing you to combine it with other schemas in this library to extract
162
+ * typed rollup array results. The rollup property in Notion can return an
163
+ * array of different types of values depending on the rollup configuration.
164
+ *
165
+ * **Input:**
166
+ * ```
167
+ * {
168
+ * rollup: {
169
+ * type: "array";
170
+ * array: Array<{ type: string; ... }>;
171
+ * };
172
+ * }
173
+ * ```
174
+ *
175
+ * **Output:** The output type depends on the schema passed as a parameter.
176
+ * For example, if a schema for number properties is passed, the output will be `Array<number>`.
177
+ *
178
+ * @param schema - A schema that validates each element in the rollup array.
179
+ * Must accept an object with a `type` field.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * import * as v from "valibot";
184
+ * import { RollupArraySchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
185
+ *
186
+ * const PageSchema = v.object({
187
+ * id: v.string(),
188
+ * properties: v.object({
189
+ * RollupNumbers: RollupArraySchema(NumberSchema),
190
+ * }),
191
+ * });
192
+ *
193
+ * const page = await notion.pages.retrieve({ page_id: "..." });
194
+ * const parsed = v.parse(PageSchema, page);
195
+ * // parsed.properties.RollupNumbers: number[]
196
+ * ```
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * import * as v from "valibot";
201
+ * import { RollupArraySchema } from "@nakanoaas/notion-valibot-utils";
202
+ *
203
+ * // Custom schema for relation rollup
204
+ * const RelationItemSchema = v.object({
205
+ * type: v.literal("relation"),
206
+ * relation: v.array(v.object({ id: v.string() })),
207
+ * });
208
+ *
209
+ * const PageSchema = v.object({
210
+ * id: v.string(),
211
+ * properties: v.object({
212
+ * RollupRelations: RollupArraySchema(RelationItemSchema),
213
+ * }),
214
+ * });
215
+ *
216
+ * const page = await notion.pages.retrieve({ page_id: "..." });
217
+ * const parsed = v.parse(PageSchema, page);
218
+ * // parsed.properties.RollupRelations: Array<{ type: "relation"; relation: Array<{ id: string }> }>
219
+ * ```
220
+ */
28
221
  function RollupArraySchema(schema) {
29
222
  return v.pipe(v.object({ rollup: v.object({
30
223
  type: v.literal("array"),