@nakanoaas/notion-valibot-schema 0.3.0 → 0.7.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.
- package/README.md +95 -14
- package/dist/created-by.cjs +30 -26
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.d.cts +35 -48
- package/dist/created-by.d.mts +35 -48
- package/dist/created-by.mjs +31 -27
- package/dist/created-by.mjs.map +1 -1
- package/dist/{file.cjs → files.cjs} +6 -6
- package/dist/files.cjs.map +1 -0
- package/dist/{file.d.cts → files.d.cts} +6 -6
- package/dist/{file.d.mts → files.d.mts} +6 -6
- package/dist/{file.mjs → files.mjs} +6 -6
- package/dist/files.mjs.map +1 -0
- package/dist/formula.cjs +120 -19
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +150 -41
- package/dist/formula.d.mts +150 -41
- package/dist/formula.mjs +117 -20
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +17 -4
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +5 -5
- package/dist/last-edited-by.cjs +27 -25
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.d.cts +29 -44
- package/dist/last-edited-by.d.mts +29 -44
- package/dist/last-edited-by.mjs +28 -26
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/people.cjs +320 -38
- package/dist/people.cjs.map +1 -1
- package/dist/people.d.cts +331 -53
- package/dist/people.d.mts +331 -53
- package/dist/people.mjs +313 -39
- package/dist/people.mjs.map +1 -1
- package/dist/rollup.cjs +66 -0
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +70 -1
- package/dist/rollup.d.mts +70 -1
- package/dist/rollup.mjs +66 -1
- package/dist/rollup.mjs.map +1 -1
- package/dist/verification.cjs +7 -7
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.d.cts +18 -12
- package/dist/verification.d.mts +18 -12
- package/dist/verification.mjs +8 -8
- package/dist/verification.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/file.cjs.map +0 -1
- package/dist/file.mjs.map +0 -1
package/dist/people.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
//#region src/people.ts
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Minimal schema for a Notion user or group ID.
|
|
5
|
+
*
|
|
6
|
+
* Use this when only the `id` field is needed, such as in ID-extraction
|
|
7
|
+
* convenience schemas (`PeopleIdSchema`, `CreatedByIdSchema`, etc.).
|
|
5
8
|
*
|
|
6
9
|
* **Input:**
|
|
7
10
|
* ```
|
|
8
11
|
* {
|
|
9
12
|
* id: string;
|
|
10
|
-
* object: "user" | "bot" | "group";
|
|
11
|
-
* name: string | null;
|
|
12
13
|
* ...
|
|
13
14
|
* }
|
|
14
15
|
* ```
|
|
@@ -17,7 +18,32 @@ import * as v from "valibot";
|
|
|
17
18
|
* ```
|
|
18
19
|
* {
|
|
19
20
|
* id: string;
|
|
20
|
-
*
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const UserOrGroupIdSchema = v.object({ id: v.string() });
|
|
25
|
+
/**
|
|
26
|
+
* Schema for a Notion user or group object.
|
|
27
|
+
*
|
|
28
|
+
* Validates `id`, `object` (`"user"` | `"group"`), and `name`.
|
|
29
|
+
* Bots in the Notion API use `object: "user"` with `type: "bot"`, so they
|
|
30
|
+
* are accepted by this schema as well.
|
|
31
|
+
*
|
|
32
|
+
* **Input:**
|
|
33
|
+
* ```
|
|
34
|
+
* {
|
|
35
|
+
* id: string;
|
|
36
|
+
* object: "user" | "group";
|
|
37
|
+
* name?: string | null;
|
|
38
|
+
* ...
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* **Output:**
|
|
43
|
+
* ```
|
|
44
|
+
* {
|
|
45
|
+
* id: string;
|
|
46
|
+
* object: "user" | "group";
|
|
21
47
|
* name: string | null;
|
|
22
48
|
* }
|
|
23
49
|
* ```
|
|
@@ -25,75 +51,152 @@ import * as v from "valibot";
|
|
|
25
51
|
* @example
|
|
26
52
|
* ```ts
|
|
27
53
|
* import * as v from "valibot";
|
|
28
|
-
* import {
|
|
54
|
+
* import { PeopleSchema, UserOrGroupSchema } from "@nakanoaas/notion-valibot-schema";
|
|
29
55
|
*
|
|
30
56
|
* const PageSchema = v.object({
|
|
31
57
|
* id: v.string(),
|
|
32
|
-
*
|
|
58
|
+
* properties: v.object({
|
|
59
|
+
* Assignees: PeopleSchema(UserOrGroupSchema),
|
|
60
|
+
* }),
|
|
33
61
|
* });
|
|
34
62
|
*
|
|
35
63
|
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
36
64
|
* const parsed = v.parse(PageSchema, page);
|
|
37
|
-
* // parsed.
|
|
65
|
+
* // parsed.properties.Assignees: Array<{ id: string; object: "user" | "group"; name: string | null }>
|
|
38
66
|
* ```
|
|
39
|
-
*
|
|
40
|
-
* @internal
|
|
41
67
|
*/
|
|
42
|
-
const
|
|
68
|
+
const UserOrGroupSchema = v.object({
|
|
43
69
|
id: v.string(),
|
|
44
|
-
object: v.picklist([
|
|
45
|
-
"user",
|
|
46
|
-
"bot",
|
|
47
|
-
"group"
|
|
48
|
-
]),
|
|
70
|
+
object: v.picklist(["user", "group"]),
|
|
49
71
|
name: v.nullish(v.string(), null)
|
|
50
72
|
});
|
|
51
73
|
/**
|
|
52
|
-
* Schema
|
|
74
|
+
* Schema for a Notion user object.
|
|
53
75
|
*
|
|
54
76
|
* **Input:**
|
|
55
77
|
* ```
|
|
56
78
|
* {
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* ...
|
|
63
|
-
* }
|
|
64
|
-
* ]
|
|
79
|
+
* id: string;
|
|
80
|
+
* object: "user";
|
|
81
|
+
* name?: string | null;
|
|
82
|
+
* avatar_url?: string | null;
|
|
83
|
+
* ...
|
|
65
84
|
* }
|
|
66
85
|
* ```
|
|
67
86
|
*
|
|
68
87
|
* **Output:**
|
|
69
88
|
* ```
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
89
|
+
* {
|
|
90
|
+
* id: string;
|
|
91
|
+
* object: "user";
|
|
92
|
+
* name: string | null;
|
|
93
|
+
* avatar_url: string | null;
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
const UserSchema = v.object({
|
|
98
|
+
id: v.string(),
|
|
99
|
+
object: v.literal("user"),
|
|
100
|
+
name: v.nullish(v.string(), null),
|
|
101
|
+
avatar_url: v.nullish(v.string(), null)
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Schema for a Notion person user object.
|
|
105
|
+
*
|
|
106
|
+
* Validates a user with `type: "person"` and the nested `person.email` field.
|
|
107
|
+
* Use with `PeopleSchema`, `SinglePeopleSchema`, or `CreatedBySchema` when
|
|
108
|
+
* full person details are needed.
|
|
109
|
+
*
|
|
110
|
+
* **Input:**
|
|
111
|
+
* ```
|
|
112
|
+
* {
|
|
113
|
+
* id: string;
|
|
114
|
+
* object: "user";
|
|
115
|
+
* name?: string | null;
|
|
116
|
+
* avatar_url?: string | null;
|
|
117
|
+
* type: "person";
|
|
118
|
+
* person: {
|
|
119
|
+
* email?: string;
|
|
120
|
+
* };
|
|
121
|
+
* ...
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* **Output:**
|
|
126
|
+
* ```
|
|
127
|
+
* {
|
|
128
|
+
* id: string;
|
|
129
|
+
* object: "user";
|
|
130
|
+
* name: string | null;
|
|
131
|
+
* avatar_url: string | null;
|
|
132
|
+
* type: "person";
|
|
133
|
+
* person: {
|
|
134
|
+
* email?: string;
|
|
135
|
+
* };
|
|
136
|
+
* }
|
|
77
137
|
* ```
|
|
78
138
|
*
|
|
79
139
|
* @example
|
|
80
140
|
* ```ts
|
|
81
141
|
* import * as v from "valibot";
|
|
82
|
-
* import { PeopleSchema } from "@nakanoaas/notion-valibot-schema";
|
|
142
|
+
* import { PeopleSchema, PersonSchema } from "@nakanoaas/notion-valibot-schema";
|
|
83
143
|
*
|
|
84
144
|
* const PageSchema = v.object({
|
|
85
145
|
* id: v.string(),
|
|
86
146
|
* properties: v.object({
|
|
87
|
-
* People: PeopleSchema,
|
|
147
|
+
* People: PeopleSchema(PersonSchema),
|
|
88
148
|
* }),
|
|
89
149
|
* });
|
|
90
150
|
*
|
|
91
151
|
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
92
152
|
* const parsed = v.parse(PageSchema, page);
|
|
93
|
-
* // parsed.properties.People: Array<{ id: string; object: "user"
|
|
153
|
+
* // parsed.properties.People: Array<{ id: string; object: "user"; name: string | null; ... }>
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
const PersonSchema = v.object({
|
|
157
|
+
id: v.string(),
|
|
158
|
+
object: v.literal("user"),
|
|
159
|
+
name: v.nullish(v.string(), null),
|
|
160
|
+
avatar_url: v.nullish(v.string(), null),
|
|
161
|
+
type: v.literal("person"),
|
|
162
|
+
person: v.object({ email: v.optional(v.string()) })
|
|
163
|
+
});
|
|
164
|
+
/**
|
|
165
|
+
* Schema for a Notion bot user object.
|
|
166
|
+
*
|
|
167
|
+
* **Input:**
|
|
168
|
+
* ```
|
|
169
|
+
* {
|
|
170
|
+
* id: string;
|
|
171
|
+
* object: "bot";
|
|
172
|
+
* name?: string | null;
|
|
173
|
+
* avatar_url?: string | null;
|
|
174
|
+
* type: "bot";
|
|
175
|
+
* bot: unknown;
|
|
176
|
+
* ...
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* **Output:**
|
|
181
|
+
* ```
|
|
182
|
+
* {
|
|
183
|
+
* id: string;
|
|
184
|
+
* object: "bot";
|
|
185
|
+
* name: string | null;
|
|
186
|
+
* avatar_url: string | null;
|
|
187
|
+
* type: "bot";
|
|
188
|
+
* bot: unknown;
|
|
189
|
+
* }
|
|
94
190
|
* ```
|
|
95
191
|
*/
|
|
96
|
-
const
|
|
192
|
+
const BotSchema = v.object({
|
|
193
|
+
id: v.string(),
|
|
194
|
+
object: v.literal("bot"),
|
|
195
|
+
name: v.nullish(v.string(), null),
|
|
196
|
+
avatar_url: v.nullish(v.string(), null),
|
|
197
|
+
type: v.literal("bot"),
|
|
198
|
+
bot: v.any()
|
|
199
|
+
});
|
|
97
200
|
/**
|
|
98
201
|
* Schema to extract the `people` array of IDs from a Notion property.
|
|
99
202
|
*
|
|
@@ -103,8 +206,6 @@ const PeopleSchema = v.pipe(v.object({ people: v.array(PersonSchema) }), v.trans
|
|
|
103
206
|
* people: [
|
|
104
207
|
* {
|
|
105
208
|
* id: string;
|
|
106
|
-
* object: "user" | "bot" | "group";
|
|
107
|
-
* name: string | null;
|
|
108
209
|
* ...
|
|
109
210
|
* }
|
|
110
211
|
* ]
|
|
@@ -133,8 +234,181 @@ const PeopleSchema = v.pipe(v.object({ people: v.array(PersonSchema) }), v.trans
|
|
|
133
234
|
* // parsed.properties.People: [string]
|
|
134
235
|
* ```
|
|
135
236
|
*/
|
|
136
|
-
const PeopleIdSchema = v.pipe(v.object({ people: v.array(
|
|
237
|
+
const PeopleIdSchema = v.pipe(v.object({ people: v.array(UserOrGroupIdSchema) }), v.transform((v) => v.people.map((p) => p.id)));
|
|
238
|
+
/**
|
|
239
|
+
* Schema to extract a single person ID from a Notion `people` property.
|
|
240
|
+
*
|
|
241
|
+
* Expects exactly one entry in the `people` array.
|
|
242
|
+
*
|
|
243
|
+
* **Input:**
|
|
244
|
+
* ```
|
|
245
|
+
* {
|
|
246
|
+
* people: [{ id: string; ... }]
|
|
247
|
+
* }
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* **Output:** `string`
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* import * as v from "valibot";
|
|
255
|
+
* import { SinglePeopleIdSchema } from "@nakanoaas/notion-valibot-schema";
|
|
256
|
+
*
|
|
257
|
+
* const PageSchema = v.object({
|
|
258
|
+
* id: v.string(),
|
|
259
|
+
* properties: v.object({
|
|
260
|
+
* Owner: SinglePeopleIdSchema,
|
|
261
|
+
* }),
|
|
262
|
+
* });
|
|
263
|
+
*
|
|
264
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
265
|
+
* const parsed = v.parse(PageSchema, page);
|
|
266
|
+
* // parsed.properties.Owner: string
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
const SinglePeopleIdSchema = v.pipe(v.object({ people: v.tuple([UserOrGroupIdSchema]) }), v.transform((v) => v.people[0].id));
|
|
270
|
+
/**
|
|
271
|
+
* Schema to extract a single person ID or `null` from a Notion `people` property.
|
|
272
|
+
*
|
|
273
|
+
* Returns the first entry's ID, or `null` when the array is empty.
|
|
274
|
+
*
|
|
275
|
+
* **Input:**
|
|
276
|
+
* ```
|
|
277
|
+
* {
|
|
278
|
+
* people: Array<{ id: string; ... }>
|
|
279
|
+
* }
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* **Output:** `string | null`
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```ts
|
|
286
|
+
* import * as v from "valibot";
|
|
287
|
+
* import { NullableSinglePeopleIdSchema } from "@nakanoaas/notion-valibot-schema";
|
|
288
|
+
*
|
|
289
|
+
* const PageSchema = v.object({
|
|
290
|
+
* id: v.string(),
|
|
291
|
+
* properties: v.object({
|
|
292
|
+
* Owner: NullableSinglePeopleIdSchema,
|
|
293
|
+
* }),
|
|
294
|
+
* });
|
|
295
|
+
*
|
|
296
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
297
|
+
* const parsed = v.parse(PageSchema, page);
|
|
298
|
+
* // parsed.properties.Owner: string | null
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
const NullableSinglePeopleIdSchema = v.pipe(v.object({ people: v.array(UserOrGroupIdSchema) }), v.transform((v) => v.people[0]?.id ?? null));
|
|
302
|
+
/**
|
|
303
|
+
* Schema factory to extract the `people` array from a Notion property.
|
|
304
|
+
*
|
|
305
|
+
* **Input:**
|
|
306
|
+
* ```
|
|
307
|
+
* {
|
|
308
|
+
* people: Array<InferredInput<schema>>
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* **Output:** `InferredOutput<schema>[]`
|
|
313
|
+
*
|
|
314
|
+
* @param schema - A schema that validates each person object in the `people` array.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* import * as v from "valibot";
|
|
319
|
+
* import { PeopleSchema, PersonSchema } from "@nakanoaas/notion-valibot-schema";
|
|
320
|
+
*
|
|
321
|
+
* const PageSchema = v.object({
|
|
322
|
+
* id: v.string(),
|
|
323
|
+
* properties: v.object({
|
|
324
|
+
* People: PeopleSchema(PersonSchema),
|
|
325
|
+
* }),
|
|
326
|
+
* });
|
|
327
|
+
*
|
|
328
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
329
|
+
* const parsed = v.parse(PageSchema, page);
|
|
330
|
+
* // parsed.properties.People: InferredOutput<typeof PersonSchema>[]
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
function PeopleSchema(schema) {
|
|
334
|
+
return v.pipe(v.object({ people: v.array(schema) }), v.transform((v) => v.people));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Schema factory to extract a single person from a Notion `people` property.
|
|
338
|
+
*
|
|
339
|
+
* Expects exactly one entry in the `people` array.
|
|
340
|
+
*
|
|
341
|
+
* **Input:**
|
|
342
|
+
* ```
|
|
343
|
+
* {
|
|
344
|
+
* people: [InferredInput<schema>]
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* **Output:** `InferredOutput<schema>`
|
|
349
|
+
*
|
|
350
|
+
* @param schema - A schema that validates the person object in the `people` array.
|
|
351
|
+
*
|
|
352
|
+
* @example
|
|
353
|
+
* ```ts
|
|
354
|
+
* import * as v from "valibot";
|
|
355
|
+
* import { PersonSchema, SinglePeopleSchema } from "@nakanoaas/notion-valibot-schema";
|
|
356
|
+
*
|
|
357
|
+
* const PageSchema = v.object({
|
|
358
|
+
* id: v.string(),
|
|
359
|
+
* properties: v.object({
|
|
360
|
+
* Owner: SinglePeopleSchema(PersonSchema),
|
|
361
|
+
* }),
|
|
362
|
+
* });
|
|
363
|
+
*
|
|
364
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
365
|
+
* const parsed = v.parse(PageSchema, page);
|
|
366
|
+
* // parsed.properties.Owner: InferredOutput<typeof PersonSchema>
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
function SinglePeopleSchema(schema) {
|
|
370
|
+
return v.pipe(v.object({ people: v.tuple([schema]) }), v.transform((v) => v.people[0]));
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Schema factory to extract a single person or `null` from a Notion `people` property.
|
|
374
|
+
*
|
|
375
|
+
* Returns the first entry, or `null` when the array is empty.
|
|
376
|
+
*
|
|
377
|
+
* **Input:**
|
|
378
|
+
* ```
|
|
379
|
+
* {
|
|
380
|
+
* people: Array<InferredInput<schema>>
|
|
381
|
+
* }
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* **Output:** `InferredOutput<schema> | null`
|
|
385
|
+
*
|
|
386
|
+
* @param schema - A schema that validates each person object in the `people` array.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* import * as v from "valibot";
|
|
391
|
+
* import {
|
|
392
|
+
* NullableSinglePeopleSchema,
|
|
393
|
+
* UserOrGroupSchema,
|
|
394
|
+
* } from "@nakanoaas/notion-valibot-schema";
|
|
395
|
+
*
|
|
396
|
+
* const PageSchema = v.object({
|
|
397
|
+
* id: v.string(),
|
|
398
|
+
* properties: v.object({
|
|
399
|
+
* Owner: NullableSinglePeopleSchema(UserOrGroupSchema),
|
|
400
|
+
* }),
|
|
401
|
+
* });
|
|
402
|
+
*
|
|
403
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
404
|
+
* const parsed = v.parse(PageSchema, page);
|
|
405
|
+
* // parsed.properties.Owner: { id: string; object: "user" | "group"; name: string | null } | null
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
function NullableSinglePeopleSchema(schema) {
|
|
409
|
+
return v.pipe(v.object({ people: v.array(schema) }), v.transform((v) => v.people[0] ?? null));
|
|
410
|
+
}
|
|
137
411
|
//#endregion
|
|
138
|
-
export { PeopleIdSchema, PeopleSchema, PersonSchema };
|
|
412
|
+
export { BotSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, PeopleIdSchema, PeopleSchema, PersonSchema, SinglePeopleIdSchema, SinglePeopleSchema, UserOrGroupIdSchema, UserOrGroupSchema, UserSchema };
|
|
139
413
|
|
|
140
414
|
//# sourceMappingURL=people.mjs.map
|
package/dist/people.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"people.mjs","names":[],"sources":["../src/people.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion person object (user, bot, or group).\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * }\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PersonSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * created_by: PersonSchema,\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.created_by: { id: string; object: \"user\" | \"bot\" | \"group\"; name: string | null }\n * ```\n *\n * @internal\n */\nexport const PersonSchema = v.object({\n\tid: v.string(),\n\tobject: v.picklist([\"user\", \"bot\", \"group\"]),\n\tname: v.nullish(v.string(), null),\n});\n\n/**\n * Schema to extract the `people` array from a Notion property.\n *\n * **Input:**\n * ```\n * {\n * people: [\n * {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\n * }\n * ]\n * }\n * ```\n *\n * **Output:**\n * ```\n * [\n * {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * }\n * ]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * People: PeopleSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.People: Array<{ id: string; object: \"user\" | \"bot\" | \"group\"; name: string | null }>\n * ```\n */\nexport const PeopleSchema = v.pipe(\n\tv.object({\n\t\tpeople: v.array(PersonSchema),\n\t}),\n\tv.transform((v) => v.people),\n);\n\n/**\n * Schema to extract the `people` array of IDs from a Notion property.\n *\n * **Input:**\n * ```\n * {\n * people: [\n * {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\n * }\n * ]\n * }\n * ```\n *\n * **Output:**\n * ```\n * [string]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * People: PeopleIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.People: [string]\n * ```\n */\nexport const PeopleIdSchema = v.pipe(\n\tv.object({\n\t\tpeople: v.array(PersonSchema),\n\t}),\n\tv.transform((v) => v.people.map((p) => p.id)),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,eAAe,EAAE,OAAO;CACpC,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,SAAS;EAAC;EAAQ;EAAO;CAAO,CAAC;CAC3C,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;AACjC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CD,MAAa,eAAe,EAAE,KAC7B,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,YAAY,EAC7B,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,iBAAiB,EAAE,KAC/B,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,YAAY,EAC7B,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,MAAM,EAAE,EAAE,CAAC,CAC7C"}
|
|
1
|
+
{"version":3,"file":"people.mjs","names":[],"sources":["../src/people.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Minimal schema for a Notion user or group ID.\n *\n * Use this when only the `id` field is needed, such as in ID-extraction\n * convenience schemas (`PeopleIdSchema`, `CreatedByIdSchema`, etc.).\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * }\n * ```\n */\nexport const UserOrGroupIdSchema = v.object({\n\tid: v.string(),\n});\n\n/**\n * Schema for a Notion user or group object.\n *\n * Validates `id`, `object` (`\"user\"` | `\"group\"`), and `name`.\n * Bots in the Notion API use `object: \"user\"` with `type: \"bot\"`, so they\n * are accepted by this schema as well.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * object: \"user\" | \"group\";\n * name?: string | null;\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * object: \"user\" | \"group\";\n * name: string | null;\n * }\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleSchema, UserOrGroupSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Assignees: PeopleSchema(UserOrGroupSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Assignees: Array<{ id: string; object: \"user\" | \"group\"; name: string | null }>\n * ```\n */\nexport const UserOrGroupSchema = v.object({\n\tid: v.string(),\n\tobject: v.picklist([\"user\", \"group\"]),\n\tname: v.nullish(v.string(), null),\n});\n\n/**\n * Schema for a Notion user object.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * object: \"user\";\n * name?: string | null;\n * avatar_url?: string | null;\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * object: \"user\";\n * name: string | null;\n * avatar_url: string | null;\n * }\n * ```\n */\nexport const UserSchema = v.object({\n\tid: v.string(),\n\tobject: v.literal(\"user\"),\n\tname: v.nullish(v.string(), null),\n\tavatar_url: v.nullish(v.string(), null),\n});\n\n/**\n * Schema for a Notion person user object.\n *\n * Validates a user with `type: \"person\"` and the nested `person.email` field.\n * Use with `PeopleSchema`, `SinglePeopleSchema`, or `CreatedBySchema` when\n * full person details are needed.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * object: \"user\";\n * name?: string | null;\n * avatar_url?: string | null;\n * type: \"person\";\n * person: {\n * email?: string;\n * };\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * object: \"user\";\n * name: string | null;\n * avatar_url: string | null;\n * type: \"person\";\n * person: {\n * email?: string;\n * };\n * }\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleSchema, PersonSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * People: PeopleSchema(PersonSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.People: Array<{ id: string; object: \"user\"; name: string | null; ... }>\n * ```\n */\nexport const PersonSchema = v.object({\n\tid: v.string(),\n\tobject: v.literal(\"user\"),\n\tname: v.nullish(v.string(), null),\n\tavatar_url: v.nullish(v.string(), null),\n\n\ttype: v.literal(\"person\"),\n\tperson: v.object({\n\t\temail: v.optional(v.string()),\n\t}),\n});\n\n/**\n * Schema for a Notion bot user object.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * object: \"bot\";\n * name?: string | null;\n * avatar_url?: string | null;\n * type: \"bot\";\n * bot: unknown;\n * ...\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * object: \"bot\";\n * name: string | null;\n * avatar_url: string | null;\n * type: \"bot\";\n * bot: unknown;\n * }\n * ```\n */\nexport const BotSchema = v.object({\n\tid: v.string(),\n\tobject: v.literal(\"bot\"),\n\tname: v.nullish(v.string(), null),\n\tavatar_url: v.nullish(v.string(), null),\n\n\ttype: v.literal(\"bot\"),\n\tbot: v.any(),\n});\n\n/**\n * Schema to extract the `people` array of IDs from a Notion property.\n *\n * **Input:**\n * ```\n * {\n * people: [\n * {\n * id: string;\n * ...\n * }\n * ]\n * }\n * ```\n *\n * **Output:**\n * ```\n * [string]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * People: PeopleIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.People: [string]\n * ```\n */\nexport const PeopleIdSchema = v.pipe(\n\tv.object({\n\t\tpeople: v.array(UserOrGroupIdSchema),\n\t}),\n\tv.transform((v) => v.people.map((p) => p.id)),\n);\n\n/**\n * Schema to extract a single person ID from a Notion `people` property.\n *\n * Expects exactly one entry in the `people` array.\n *\n * **Input:**\n * ```\n * {\n * people: [{ id: string; ... }]\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SinglePeopleIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Owner: SinglePeopleIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Owner: string\n * ```\n */\nexport const SinglePeopleIdSchema = v.pipe(\n\tv.object({\n\t\tpeople: v.tuple([UserOrGroupIdSchema]),\n\t}),\n\tv.transform((v) => v.people[0].id),\n);\n\n/**\n * Schema to extract a single person ID or `null` from a Notion `people` property.\n *\n * Returns the first entry's ID, or `null` when the array is empty.\n *\n * **Input:**\n * ```\n * {\n * people: Array<{ id: string; ... }>\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSinglePeopleIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Owner: NullableSinglePeopleIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Owner: string | null\n * ```\n */\nexport const NullableSinglePeopleIdSchema = v.pipe(\n\tv.object({\n\t\tpeople: v.array(UserOrGroupIdSchema),\n\t}),\n\tv.transform((v) => v.people[0]?.id ?? null),\n);\n\n/**\n * Schema factory to extract the `people` array from a Notion property.\n *\n * **Input:**\n * ```\n * {\n * people: Array<InferredInput<schema>>\n * }\n * ```\n *\n * **Output:** `InferredOutput<schema>[]`\n *\n * @param schema - A schema that validates each person object in the `people` array.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PeopleSchema, PersonSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * People: PeopleSchema(PersonSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.People: InferredOutput<typeof PersonSchema>[]\n * ```\n */\nexport function PeopleSchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n): v.GenericSchema<{ people: v.InferInput<S>[] }, v.InferOutput<S>[]> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tpeople: v.array(schema),\n\t\t}),\n\t\tv.transform((v) => v.people),\n\t);\n}\n\n/**\n * Schema factory to extract a single person from a Notion `people` property.\n *\n * Expects exactly one entry in the `people` array.\n *\n * **Input:**\n * ```\n * {\n * people: [InferredInput<schema>]\n * }\n * ```\n *\n * **Output:** `InferredOutput<schema>`\n *\n * @param schema - A schema that validates the person object in the `people` array.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { PersonSchema, SinglePeopleSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Owner: SinglePeopleSchema(PersonSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Owner: InferredOutput<typeof PersonSchema>\n * ```\n */\nexport function SinglePeopleSchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n): v.GenericSchema<{ people: [v.InferInput<S>] }, v.InferOutput<S>> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tpeople: v.tuple([schema]),\n\t\t}),\n\t\tv.transform((v) => v.people[0]),\n\t);\n}\n\n/**\n * Schema factory to extract a single person or `null` from a Notion `people` property.\n *\n * Returns the first entry, or `null` when the array is empty.\n *\n * **Input:**\n * ```\n * {\n * people: Array<InferredInput<schema>>\n * }\n * ```\n *\n * **Output:** `InferredOutput<schema> | null`\n *\n * @param schema - A schema that validates each person object in the `people` array.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import {\n * NullableSinglePeopleSchema,\n * UserOrGroupSchema,\n * } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Owner: NullableSinglePeopleSchema(UserOrGroupSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Owner: { id: string; object: \"user\" | \"group\"; name: string | null } | null\n * ```\n */\nexport function NullableSinglePeopleSchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<{ people: v.InferInput<S>[] }, v.InferOutput<S> | null> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tpeople: v.array(schema),\n\t\t}),\n\t\tv.transform((v) => v.people[0] ?? null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,sBAAsB,EAAE,OAAO,EAC3C,IAAI,EAAE,OAAO,EACd,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CD,MAAa,oBAAoB,EAAE,OAAO;CACzC,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,SAAS,CAAC,QAAQ,OAAO,CAAC;CACpC,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;AACjC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BD,MAAa,aAAa,EAAE,OAAO;CAClC,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,QAAQ,MAAM;CACxB,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAChC,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;AACvC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDD,MAAa,eAAe,EAAE,OAAO;CACpC,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,QAAQ,MAAM;CACxB,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAChC,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAEtC,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,EAC7B,CAAC;AACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BD,MAAa,YAAY,EAAE,OAAO;CACjC,IAAI,EAAE,OAAO;CACb,QAAQ,EAAE,QAAQ,KAAK;CACvB,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAChC,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAEtC,MAAM,EAAE,QAAQ,KAAK;CACrB,KAAK,EAAE,IAAI;AACZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCD,MAAa,iBAAiB,EAAE,KAC/B,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,mBAAmB,EACpC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,MAAM,EAAE,EAAE,CAAC,CAC7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,uBAAuB,EAAE,KACrC,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,CAAC,mBAAmB,CAAC,EACtC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,+BAA+B,EAAE,KAC7C,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,mBAAmB,EACpC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,EAAE,EAAE,MAAM,IAAI,CAC3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAgB,aACf,QACqE;CACrE,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,MAAM,EACvB,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,mBACf,QACmE;CACnE,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EACzB,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,EAAE,CAC/B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,2BAGf,QAC0E;CAC1E,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,MAAM,MAAM,EACvB,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,IAAI,CACvC;AACD"}
|
package/dist/rollup.cjs
CHANGED
|
@@ -4,6 +4,63 @@ let valibot = require("valibot");
|
|
|
4
4
|
valibot = require_runtime.__toESM(valibot, 1);
|
|
5
5
|
//#region src/rollup.ts
|
|
6
6
|
/**
|
|
7
|
+
* Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
|
|
8
|
+
*
|
|
9
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
10
|
+
* allowing you to combine it with the number and date schemas in this library
|
|
11
|
+
* to extract typed rollup results (e.g. number or date rollups).
|
|
12
|
+
*
|
|
13
|
+
* **Input:**
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
21
|
+
* For example, if `NumberSchema` is passed, the output will be `number`.
|
|
22
|
+
*
|
|
23
|
+
* @param schema - A schema that validates the rollup value.
|
|
24
|
+
* Must accept an object with a `number` or `date` field.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as v from "valibot";
|
|
29
|
+
* import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
|
+
*
|
|
31
|
+
* const PageSchema = v.object({
|
|
32
|
+
* id: v.string(),
|
|
33
|
+
* properties: v.object({
|
|
34
|
+
* Sum: RollupSimpleSchema(NumberSchema),
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
39
|
+
* const parsed = v.parse(PageSchema, page);
|
|
40
|
+
* // parsed.properties.Sum: number
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import * as v from "valibot";
|
|
46
|
+
* import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
47
|
+
*
|
|
48
|
+
* const PageSchema = v.object({
|
|
49
|
+
* id: v.string(),
|
|
50
|
+
* properties: v.object({
|
|
51
|
+
* LatestDate: RollupSimpleSchema(SingleDateSchema),
|
|
52
|
+
* }),
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
56
|
+
* const parsed = v.parse(PageSchema, page);
|
|
57
|
+
* // parsed.properties.LatestDate: Date
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function RollupSimpleSchema(schema) {
|
|
61
|
+
return valibot.pipe(valibot.object({ rollup: schema }), valibot.transform((v) => v.rollup));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
7
64
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
8
65
|
*
|
|
9
66
|
* **Input:**
|
|
@@ -34,6 +91,8 @@ valibot = require_runtime.__toESM(valibot, 1);
|
|
|
34
91
|
* const parsed = v.parse(PageSchema, page);
|
|
35
92
|
* // parsed.properties.Sum: number | null
|
|
36
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
37
96
|
*/
|
|
38
97
|
const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
39
98
|
type: valibot.literal("number"),
|
|
@@ -70,6 +129,8 @@ const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot
|
|
|
70
129
|
* const parsed = v.parse(PageSchema, page);
|
|
71
130
|
* // parsed.properties.Sum: number
|
|
72
131
|
* ```
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
73
134
|
*/
|
|
74
135
|
const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
75
136
|
type: valibot.literal("number"),
|
|
@@ -110,6 +171,8 @@ const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object(
|
|
|
110
171
|
* const parsed = v.parse(PageSchema, page);
|
|
111
172
|
* // parsed.properties.LatestDate: Date | null
|
|
112
173
|
* ```
|
|
174
|
+
*
|
|
175
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
113
176
|
*/
|
|
114
177
|
const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
115
178
|
type: valibot.literal("date"),
|
|
@@ -150,6 +213,8 @@ const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.o
|
|
|
150
213
|
* const parsed = v.parse(PageSchema, page);
|
|
151
214
|
* // parsed.properties.LatestDate: Date
|
|
152
215
|
* ```
|
|
216
|
+
*
|
|
217
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
153
218
|
*/
|
|
154
219
|
const RollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
155
220
|
type: valibot.literal("date"),
|
|
@@ -367,6 +432,7 @@ exports.NullableSingleRollupArraySchema = NullableSingleRollupArraySchema;
|
|
|
367
432
|
exports.RollupArraySchema = RollupArraySchema;
|
|
368
433
|
exports.RollupDateSchema = RollupDateSchema;
|
|
369
434
|
exports.RollupNumberSchema = RollupNumberSchema;
|
|
435
|
+
exports.RollupSimpleSchema = RollupSimpleSchema;
|
|
370
436
|
exports.SingleRollupArraySchema = SingleRollupArraySchema;
|
|
371
437
|
|
|
372
438
|
//# sourceMappingURL=rollup.cjs.map
|
package/dist/rollup.cjs.map
CHANGED
|
@@ -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\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<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\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\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single 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 { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\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 * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\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.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\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 { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\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 * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\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[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,SAASA,QAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,SAASC,aAAAA,gBAAgB;AAClC,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMC,aAAAA;AACP,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|
|
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 factory to extract the `rollup` property with a simple (non-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 the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\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 *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\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 function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\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 *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.\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 *\n * @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.\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 *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.\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 *\n * @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.\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<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\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\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single 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 { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\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 * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\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.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\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 { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\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 * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\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[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAGf,QAMC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,SAASA,QAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,SAASC,aAAAA,gBAAgB;AAClC,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMC,aAAAA;AACP,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|