@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.
Files changed (50) hide show
  1. package/README.md +95 -14
  2. package/dist/created-by.cjs +30 -26
  3. package/dist/created-by.cjs.map +1 -1
  4. package/dist/created-by.d.cts +35 -48
  5. package/dist/created-by.d.mts +35 -48
  6. package/dist/created-by.mjs +31 -27
  7. package/dist/created-by.mjs.map +1 -1
  8. package/dist/{file.cjs → files.cjs} +6 -6
  9. package/dist/files.cjs.map +1 -0
  10. package/dist/{file.d.cts → files.d.cts} +6 -6
  11. package/dist/{file.d.mts → files.d.mts} +6 -6
  12. package/dist/{file.mjs → files.mjs} +6 -6
  13. package/dist/files.mjs.map +1 -0
  14. package/dist/formula.cjs +120 -19
  15. package/dist/formula.cjs.map +1 -1
  16. package/dist/formula.d.cts +150 -41
  17. package/dist/formula.d.mts +150 -41
  18. package/dist/formula.mjs +117 -20
  19. package/dist/formula.mjs.map +1 -1
  20. package/dist/index.cjs +17 -4
  21. package/dist/index.d.cts +5 -5
  22. package/dist/index.d.mts +5 -5
  23. package/dist/index.mjs +5 -5
  24. package/dist/last-edited-by.cjs +27 -25
  25. package/dist/last-edited-by.cjs.map +1 -1
  26. package/dist/last-edited-by.d.cts +29 -44
  27. package/dist/last-edited-by.d.mts +29 -44
  28. package/dist/last-edited-by.mjs +28 -26
  29. package/dist/last-edited-by.mjs.map +1 -1
  30. package/dist/people.cjs +320 -38
  31. package/dist/people.cjs.map +1 -1
  32. package/dist/people.d.cts +331 -53
  33. package/dist/people.d.mts +331 -53
  34. package/dist/people.mjs +313 -39
  35. package/dist/people.mjs.map +1 -1
  36. package/dist/rollup.cjs +66 -0
  37. package/dist/rollup.cjs.map +1 -1
  38. package/dist/rollup.d.cts +70 -1
  39. package/dist/rollup.d.mts +70 -1
  40. package/dist/rollup.mjs +66 -1
  41. package/dist/rollup.mjs.map +1 -1
  42. package/dist/verification.cjs +7 -7
  43. package/dist/verification.cjs.map +1 -1
  44. package/dist/verification.d.cts +18 -12
  45. package/dist/verification.d.mts +18 -12
  46. package/dist/verification.mjs +8 -8
  47. package/dist/verification.mjs.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/file.cjs.map +0 -1
  50. package/dist/file.mjs.map +0 -1
package/README.md CHANGED
@@ -40,7 +40,8 @@ With `@nakanoaas/notion-valibot-schema`, you get this:
40
40
  {
41
41
  Status: "In Progress",
42
42
  Tags: ["Urgent", "Work"],
43
- DueDate: new Date("2023-12-25")
43
+ DueDate: new Date("2023-12-25"),
44
+ Assignee: ["user-id-1", "user-id-2"]
44
45
  }
45
46
  ```
46
47
 
@@ -87,6 +88,7 @@ import {
87
88
  MultiSelectSchema,
88
89
  NullableSingleDateSchema,
89
90
  CheckboxSchema,
91
+ PeopleIdSchema,
90
92
  } from "@nakanoaas/notion-valibot-schema";
91
93
 
92
94
  // 1. Define your schema based on your Data Source properties
@@ -110,6 +112,9 @@ const TaskPageSchema = v.object({
110
112
 
111
113
  // Map "IsUrgent" -> boolean
112
114
  IsUrgent: CheckboxSchema,
115
+
116
+ // Map "Assignee" -> string[] (User IDs)
117
+ Assignee: PeopleIdSchema,
113
118
  }),
114
119
  });
115
120
 
@@ -123,6 +128,7 @@ const task = v.parse(TaskPageSchema, page);
123
128
  console.log(task.properties.Name); // "Buy Milk" (string)
124
129
  console.log(task.properties.DueDate); // Date object or null
125
130
  console.log(task.properties.Tags); // ["Personal", "Shopping"] (string[])
131
+ console.log(task.properties.Assignee); // ["user-id-1", "user-id-2"] (string[])
126
132
  ```
127
133
 
128
134
  ### Handling Lists (Query Results)
@@ -153,33 +159,57 @@ const tasks = v.parse(TaskListSchema, results);
153
159
  | **Date** (Full) | `FullDateSchema` / `NullableFullDateSchema` | `{ start: Date; end: Date \| null; time_zone: string \| null }` / `{ start: Date; end: Date \| null; time_zone: string \| null } \| null` |
154
160
  | **Relation** | `RelationSchema` | `string[]` (Page IDs) |
155
161
  | **Relation** (Single) | `SingleRelationSchema` | `string` (Page ID) |
162
+ | **Rollup** (Simple) | `RollupSimpleSchema(schema)` | `Inferred<schema>` |
156
163
  | **Rollup** (Array) | `RollupArraySchema(schema)` | `Inferred<schema>[]` |
157
164
  | **Rollup** (Single) | `SingleRollupArraySchema(schema)` | `Inferred<schema>` |
158
165
  | **Rollup** (Single, Nullable) | `NullableSingleRollupArraySchema(schema)` | `Inferred<schema> \| null` |
166
+ | **Formula** | `FormulaSchema(schema)` | `Inferred<schema>` |
159
167
  | **URL** | `UrlSchema` | `string` |
160
168
  | **Email** | `EmailSchema` | `string` |
161
169
  | **Phone** | `PhoneNumberSchema` | `string` |
162
- | **Files** | `FileArraySchema` | `string[]` (URLs) |
170
+ | **Files** | `FileSchema` | `string[]` (URLs) |
163
171
  | **Files** (Single) | `SingleFileSchema` / `NullableSingleFileSchema` | `string` (URL) / `string \| null` |
164
- | **Created/Edited By** | `CreatedBySchema` / `LastEditedBySchema` | `string` (User ID) |
172
+ | **People** (building blocks) | `UserOrGroupIdSchema` / `UserOrGroupSchema` / `UserSchema` / `PersonSchema` / `BotSchema` | Building-block object types |
173
+ | **People** (generic) | `PeopleSchema(schema)` / `SinglePeopleSchema(schema)` / `NullableSinglePeopleSchema(schema)` | `Inferred<schema>[]` / `Inferred<schema>` / `Inferred<schema> \| null` |
174
+ | **People** (convenience) | `PeopleIdSchema` / `SinglePeopleIdSchema` / `NullableSinglePeopleIdSchema` | `string[]` / `string` / `string \| null` |
175
+ | **Created/Edited By** (generic) | `CreatedBySchema(schema)` / `LastEditedBySchema(schema)` | `Inferred<schema>` |
176
+ | **Created/Edited By** (convenience) | `CreatedByIdSchema` / `NullableCreatedByNameSchema` / `LastEditedByIdSchema` / `NullableLastEditedByNameSchema` | `string` / `string \| null` |
165
177
  | **Created/Edited Time**| `CreatedTimeSchema` / `LastEditedTimeSchema` | `Date` |
166
- | **People** | `PeopleSchema` / `PeopleIdSchema` | `Array<{ id: string; object: "user" \| "bot" \| "group"; name: string \| null }>` / `string[]` |
167
178
  | **Place** | `PlaceSchema` / `NullablePlaceSchema` | `{ lat: number; lon: number; name?: string \| null; address?: string \| null }` / `{ lat: number; lon: number; name?: string \| null; address?: string \| null } \| null` |
168
179
  | **Unique ID** | `UniqueIdNumberSchema` / `NullableUniqueIdSchema` | `number` / `{ prefix: string \| null; number: number \| null }` |
169
- | **Verification** | `VerificationSchema` / `NullableVerificationSchema` | `{ state: "unverified" \| "verified" \| "expired"; date: DateObject \| null; verified_by: Person \| null }` / `{ state: "unverified" \| "verified" \| "expired"; date: DateObject \| null; verified_by: Person \| null } \| null` |
180
+ | **Verification** | `VerificationSchema` / `NullableVerificationSchema` | `{ state: "unverified" \| "verified" \| "expired"; date: DateObject \| null; verified_by: { id: string; object: "user"; name: string \| null; avatar_url: string \| null } \| null }` / same \| `null` |
170
181
 
171
182
  ### Advanced Schemas
172
183
 
173
184
  #### Formulas
174
- Formulas in Notion can return different types (string, number, boolean, date). Use `FormulaSchema` with a specific inner schema to handle this.
185
+ Formulas in Notion can return different types (string, number, boolean, date). Use `FormulaSchema` with the matching inner schema for each formula property.
175
186
 
176
187
  ```ts
177
- import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-schema";
188
+ import * as v from "valibot";
189
+ import {
190
+ BooleanFormulaSchema,
191
+ FormulaSchema,
192
+ NumberSchema,
193
+ SingleDateSchema,
194
+ StringFormulaSchema,
195
+ } from "@nakanoaas/notion-valibot-schema";
178
196
 
179
- const MySchema = v.object({
180
- // If your formula returns text
181
- MyFormula: FormulaSchema(RichTextSchema),
197
+ const PageSchema = v.object({
198
+ id: v.string(),
199
+ properties: v.object({
200
+ FormulaText: FormulaSchema(StringFormulaSchema),
201
+ FormulaNumber: FormulaSchema(NumberSchema),
202
+ FormulaBoolean: FormulaSchema(BooleanFormulaSchema),
203
+ FormulaDate: FormulaSchema(SingleDateSchema),
204
+ }),
182
205
  });
206
+
207
+ const page = await notion.pages.retrieve({ page_id: "..." });
208
+ const parsed = v.parse(PageSchema, page);
209
+ // parsed.properties.FormulaText: string
210
+ // parsed.properties.FormulaNumber: number
211
+ // parsed.properties.FormulaBoolean: boolean
212
+ // parsed.properties.FormulaDate: Date
183
213
  ```
184
214
 
185
215
  #### Rollups
@@ -187,19 +217,20 @@ Rollups are powerful but complex. We provide helpers for common rollup types.
187
217
 
188
218
  ```ts
189
219
  import {
190
- RollupNumberSchema,
191
- RollupDateSchema,
220
+ RollupSimpleSchema,
192
221
  RollupArraySchema,
193
222
  SingleRollupArraySchema,
194
223
  NullableSingleRollupArraySchema,
224
+ NumberSchema,
225
+ SingleDateSchema,
195
226
  } from "@nakanoaas/notion-valibot-schema";
196
227
 
197
228
  const MySchema = v.object({
198
229
  // Sum/Average rollup (returns number)
199
- TotalCost: RollupNumberSchema,
230
+ TotalCost: RollupSimpleSchema(NumberSchema),
200
231
 
201
232
  // Date rollup (returns Date)
202
- LatestMeeting: RollupDateSchema,
233
+ LatestMeeting: RollupSimpleSchema(SingleDateSchema),
203
234
 
204
235
  // Array rollup (e.g., pulling tags from related items)
205
236
  AllTags: RollupArraySchema(v.string()),
@@ -212,6 +243,56 @@ const MySchema = v.object({
212
243
  });
213
244
  ```
214
245
 
246
+ #### People & Created/Edited By
247
+
248
+ People-related schemas are organized into **building blocks**, **generic factories**, and **convenience schemas**:
249
+
250
+ - **Building blocks** (`UserOrGroupIdSchema`, `UserOrGroupSchema`, `UserSchema`, `PersonSchema`, `BotSchema`) validate individual user/group objects.
251
+ - **Generic factories** (`PeopleSchema`, `SinglePeopleSchema`, `NullableSinglePeopleSchema`, `CreatedBySchema`, `LastEditedBySchema`) accept a building-block schema and extract the property value.
252
+ - **Convenience schemas** (`PeopleIdSchema`, `CreatedByIdSchema`, etc.) require no generic parameter and extract common primitives like IDs or names.
253
+
254
+ ```ts
255
+ import * as v from "valibot";
256
+ import {
257
+ CreatedByIdSchema,
258
+ CreatedBySchema,
259
+ PeopleIdSchema,
260
+ PeopleSchema,
261
+ PersonSchema,
262
+ UserOrGroupSchema,
263
+ UserSchema,
264
+ } from "@nakanoaas/notion-valibot-schema";
265
+
266
+ const PageSchema = v.object({
267
+ id: v.string(),
268
+ properties: v.object({
269
+ // Full person details
270
+ People: PeopleSchema(PersonSchema),
271
+
272
+ // IDs only (no generic needed)
273
+ AssigneeIds: PeopleIdSchema,
274
+
275
+ // created_by ID extraction
276
+ CreatedById: CreatedByIdSchema,
277
+
278
+ // Custom user schema
279
+ CreatedBy: CreatedBySchema(UserSchema),
280
+ }),
281
+ });
282
+ ```
283
+
284
+ ### Migration Guide (Breaking Changes)
285
+
286
+ The following schemas changed from constants to generic factories:
287
+
288
+ | Before | After |
289
+ | :--- | :--- |
290
+ | `PeopleSchema` | `PeopleSchema(UserOrGroupSchema)` or `PeopleSchema(PersonSchema)` |
291
+ | `CreatedBySchema` | `CreatedBySchema(UserOrGroupSchema)` |
292
+ | `LastEditedBySchema` | `LastEditedBySchema(UserOrGroupSchema)` |
293
+
294
+ For ID-only extraction, use the convenience schemas instead: `PeopleIdSchema`, `CreatedByIdSchema`, `LastEditedByIdSchema`.
295
+
215
296
  ## License
216
297
 
217
298
  MIT © [Nakano as a Service](https://github.com/nakanoasaservice)
@@ -4,47 +4,40 @@ let valibot = require("valibot");
4
4
  valibot = require_runtime.__toESM(valibot, 1);
5
5
  //#region src/created-by.ts
6
6
  /**
7
- * Schema to extract the `created_by` person object from a Notion page.
7
+ * Schema to extract the `created_by` person ID from a Notion page.
8
8
  *
9
9
  * **Input:**
10
10
  * ```
11
11
  * {
12
12
  * created_by: {
13
13
  * id: string;
14
- * object: "user" | "bot" | "group";
14
+ * object: "user" | "group";
15
15
  * name: string | null;
16
16
  * ...
17
17
  * }
18
18
  * }
19
19
  * ```
20
20
  *
21
- * **Output:**
22
- * ```
23
- * {
24
- * id: string;
25
- * object: "user" | "bot" | "group";
26
- * name: string | null;
27
- * }
28
- * ```
21
+ * **Output:** `string`
29
22
  *
30
23
  * @example
31
24
  * ```ts
32
25
  * import * as v from "valibot";
33
- * import { CreatedBySchema } from "@nakanoaas/notion-valibot-schema";
26
+ * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
34
27
  *
35
28
  * const PageSchema = v.object({
36
29
  * id: v.string(),
37
30
  * properties: v.object({
38
- * CreatedBy: CreatedBySchema,
31
+ * "Created By": CreatedByIdSchema,
39
32
  * }),
40
33
  * });
41
34
  *
42
35
  * const page = await notion.pages.retrieve({ page_id: "..." });
43
36
  * const parsed = v.parse(PageSchema, page);
44
- * // parsed.properties.CreatedBy: { id: string; object: "user" | "bot" | "group"; name: string | null }
37
+ * // parsed.properties["Created By"]: string
45
38
  * ```
46
39
  */
47
- const CreatedBySchema = valibot.pipe(valibot.object({ created_by: require_people.PersonSchema }), valibot.transform((v) => v.created_by));
40
+ const CreatedByIdSchema = valibot.pipe(valibot.object({ created_by: require_people.UserOrGroupIdSchema }), valibot.transform((v) => v.created_by.id));
48
41
  /**
49
42
  * Schema to extract the `created_by` person name from a Notion page.
50
43
  *
@@ -53,7 +46,7 @@ const CreatedBySchema = valibot.pipe(valibot.object({ created_by: require_people
53
46
  * {
54
47
  * created_by: {
55
48
  * id: string;
56
- * object: "user" | "bot" | "group";
49
+ * object: "user" | "group";
57
50
  * name: string | null;
58
51
  * ...
59
52
  * }
@@ -70,51 +63,62 @@ const CreatedBySchema = valibot.pipe(valibot.object({ created_by: require_people
70
63
  * const PageSchema = v.object({
71
64
  * id: v.string(),
72
65
  * properties: v.object({
73
- * CreatedByName: NullableCreatedByNameSchema,
66
+ * "Created By": NullableCreatedByNameSchema,
74
67
  * }),
75
68
  * });
76
69
  *
77
70
  * const page = await notion.pages.retrieve({ page_id: "..." });
78
71
  * const parsed = v.parse(PageSchema, page);
79
- * // parsed.properties.CreatedByName: string | null
72
+ * // parsed.properties["Created By"]: string | null
80
73
  * ```
81
74
  */
82
- const NullableCreatedByNameSchema = valibot.pipe(valibot.object({ created_by: require_people.PersonSchema }), valibot.transform((v) => v.created_by.name));
75
+ const NullableCreatedByNameSchema = valibot.pipe(valibot.object({ created_by: require_people.UserOrGroupSchema }), valibot.transform((v) => v.created_by.name));
83
76
  /**
84
- * Schema to extract the `created_by` person ID from a Notion page.
77
+ * Schema factory to extract the `created_by` person object from a Notion page.
78
+ *
79
+ * This is a generic schema factory that accepts another schema as a parameter,
80
+ * allowing you to combine it with building-block schemas such as
81
+ * `UserOrGroupSchema`, `UserSchema`, or `PersonSchema`.
85
82
  *
86
83
  * **Input:**
87
84
  * ```
88
85
  * {
89
86
  * created_by: {
90
87
  * id: string;
91
- * object: "user" | "bot" | "group";
92
- * name: string | null;
88
+ * object: "user" | "group";
89
+ * name?: string | null;
93
90
  * ...
94
91
  * }
95
92
  * }
96
93
  * ```
97
94
  *
98
- * **Output:** `string`
95
+ * **Output:** The output type depends on the schema passed as a parameter.
96
+ *
97
+ * @param schema - A schema that validates the `created_by` user or group object.
99
98
  *
100
99
  * @example
101
100
  * ```ts
102
101
  * import * as v from "valibot";
103
- * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
102
+ * import {
103
+ * CreatedBySchema,
104
+ * UserOrGroupSchema,
105
+ * } from "@nakanoaas/notion-valibot-schema";
104
106
  *
105
107
  * const PageSchema = v.object({
106
108
  * id: v.string(),
107
109
  * properties: v.object({
108
- * CreatedById: CreatedByIdSchema,
110
+ * "Created By": CreatedBySchema(UserOrGroupSchema),
109
111
  * }),
110
112
  * });
111
113
  *
112
114
  * const page = await notion.pages.retrieve({ page_id: "..." });
113
115
  * const parsed = v.parse(PageSchema, page);
114
- * // parsed.properties.CreatedById: string
116
+ * // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
115
117
  * ```
116
118
  */
117
- const CreatedByIdSchema = valibot.pipe(valibot.object({ created_by: require_people.PersonSchema }), valibot.transform((v) => v.created_by.id));
119
+ function CreatedBySchema(schema) {
120
+ return valibot.pipe(valibot.object({ created_by: schema }), valibot.transform((v) => v.created_by));
121
+ }
118
122
  //#endregion
119
123
  exports.CreatedByIdSchema = CreatedByIdSchema;
120
124
  exports.CreatedBySchema = CreatedBySchema;
@@ -1 +1 @@
1
- {"version":3,"file":"created-by.cjs","names":["v","PersonSchema"],"sources":["../src/created-by.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { PersonSchema } from \"./people\";\n\n/**\n * Schema to extract the `created_by` person object from a Notion page.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\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 { CreatedBySchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * CreatedBy: CreatedBySchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.CreatedBy: { id: string; object: \"user\" | \"bot\" | \"group\"; name: string | null }\n * ```\n */\nexport const CreatedBySchema = v.pipe(\n\tv.object({\n\t\tcreated_by: PersonSchema,\n\t}),\n\tv.transform((v) => v.created_by),\n);\n\n/**\n * Schema to extract the `created_by` person name from a Notion page.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\n * }\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableCreatedByNameSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * CreatedByName: NullableCreatedByNameSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.CreatedByName: string | null\n * ```\n */\nexport const NullableCreatedByNameSchema = v.pipe(\n\tv.object({\n\t\tcreated_by: PersonSchema,\n\t}),\n\tv.transform((v) => v.created_by.name),\n);\n\n/**\n * Schema to extract the `created_by` person ID from a Notion page.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"bot\" | \"group\";\n * name: string | null;\n * ...\n * }\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { CreatedByIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * CreatedById: CreatedByIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.CreatedById: string\n * ```\n */\nexport const CreatedByIdSchema = v.pipe(\n\tv.object({\n\t\tcreated_by: PersonSchema,\n\t}),\n\tv.transform((v) => v.created_by.id),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,kBAAkBA,QAAE,KAChCA,QAAE,OAAO,EACR,YAAYC,eAAAA,aACb,CAAC,GACDD,QAAE,WAAW,MAAM,EAAE,UAAU,CAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,8BAA8BA,QAAE,KAC5CA,QAAE,OAAO,EACR,YAAYC,eAAAA,aACb,CAAC,GACDD,QAAE,WAAW,MAAM,EAAE,WAAW,IAAI,CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,oBAAoBA,QAAE,KAClCA,QAAE,OAAO,EACR,YAAYC,eAAAA,aACb,CAAC,GACDD,QAAE,WAAW,MAAM,EAAE,WAAW,EAAE,CACnC"}
1
+ {"version":3,"file":"created-by.cjs","names":["v","UserOrGroupIdSchema","UserOrGroupSchema"],"sources":["../src/created-by.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { UserOrGroupIdSchema, UserOrGroupSchema } from \"./people\";\n\n/**\n * Schema to extract the `created_by` person ID from a Notion page.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"group\";\n * name: string | null;\n * ...\n * }\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { CreatedByIdSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * \"Created By\": CreatedByIdSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties[\"Created By\"]: string\n * ```\n */\nexport const CreatedByIdSchema = v.pipe(\n\tv.object({\n\t\tcreated_by: UserOrGroupIdSchema,\n\t}),\n\tv.transform((v) => v.created_by.id),\n);\n\n/**\n * Schema to extract the `created_by` person name from a Notion page.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"group\";\n * name: string | null;\n * ...\n * }\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableCreatedByNameSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * \"Created By\": NullableCreatedByNameSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties[\"Created By\"]: string | null\n * ```\n */\nexport const NullableCreatedByNameSchema = v.pipe(\n\tv.object({\n\t\tcreated_by: UserOrGroupSchema,\n\t}),\n\tv.transform((v) => v.created_by.name),\n);\n\n/**\n * Schema factory to extract the `created_by` person object from a Notion page.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with building-block schemas such as\n * `UserOrGroupSchema`, `UserSchema`, or `PersonSchema`.\n *\n * **Input:**\n * ```\n * {\n * created_by: {\n * id: string;\n * object: \"user\" | \"group\";\n * name?: string | null;\n * ...\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n *\n * @param schema - A schema that validates the `created_by` user or group object.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import {\n * CreatedBySchema,\n * UserOrGroupSchema,\n * } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * \"Created By\": CreatedBySchema(UserOrGroupSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties[\"Created By\"]: { id: string; object: \"user\" | \"group\"; name: string | null }\n * ```\n */\nexport function CreatedBySchema<\n\tS extends v.GenericSchema<{ id: string; object: \"user\" | \"group\" }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<{ created_by: v.InferInput<S> }, v.InferOutput<S>> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tcreated_by: schema,\n\t\t}),\n\t\tv.transform((v) => v.created_by),\n\t) as v.GenericSchema<{ created_by: v.InferInput<S> }, v.InferOutput<S>>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,oBAAoBA,QAAE,KAClCA,QAAE,OAAO,EACR,YAAYC,eAAAA,oBACb,CAAC,GACDD,QAAE,WAAW,MAAM,EAAE,WAAW,EAAE,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,8BAA8BA,QAAE,KAC5CA,QAAE,OAAO,EACR,YAAYE,eAAAA,kBACb,CAAC,GACDF,QAAE,WAAW,MAAM,EAAE,WAAW,IAAI,CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,gBAGf,QACqE;CACrE,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,YAAY,OACb,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,UAAU,CAChC;AACD"}
@@ -2,63 +2,48 @@ import * as v from "valibot";
2
2
 
3
3
  //#region src/created-by.d.ts
4
4
  /**
5
- * Schema to extract the `created_by` person object from a Notion page.
5
+ * Schema to extract the `created_by` person ID from a Notion page.
6
6
  *
7
7
  * **Input:**
8
8
  * ```
9
9
  * {
10
10
  * created_by: {
11
11
  * id: string;
12
- * object: "user" | "bot" | "group";
12
+ * object: "user" | "group";
13
13
  * name: string | null;
14
14
  * ...
15
15
  * }
16
16
  * }
17
17
  * ```
18
18
  *
19
- * **Output:**
20
- * ```
21
- * {
22
- * id: string;
23
- * object: "user" | "bot" | "group";
24
- * name: string | null;
25
- * }
26
- * ```
19
+ * **Output:** `string`
27
20
  *
28
21
  * @example
29
22
  * ```ts
30
23
  * import * as v from "valibot";
31
- * import { CreatedBySchema } from "@nakanoaas/notion-valibot-schema";
24
+ * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
32
25
  *
33
26
  * const PageSchema = v.object({
34
27
  * id: v.string(),
35
28
  * properties: v.object({
36
- * CreatedBy: CreatedBySchema,
29
+ * "Created By": CreatedByIdSchema,
37
30
  * }),
38
31
  * });
39
32
  *
40
33
  * const page = await notion.pages.retrieve({ page_id: "..." });
41
34
  * const parsed = v.parse(PageSchema, page);
42
- * // parsed.properties.CreatedBy: { id: string; object: "user" | "bot" | "group"; name: string | null }
35
+ * // parsed.properties["Created By"]: string
43
36
  * ```
44
37
  */
45
- declare const CreatedBySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
38
+ declare const CreatedByIdSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
46
39
  readonly created_by: v.ObjectSchema<{
47
40
  readonly id: v.StringSchema<undefined>;
48
- readonly object: v.PicklistSchema<["user", "bot", "group"], undefined>;
49
- readonly name: v.NullishSchema<v.StringSchema<undefined>, null>;
50
41
  }, undefined>;
51
42
  }, undefined>, v.TransformAction<{
52
43
  created_by: {
53
44
  id: string;
54
- object: "user" | "bot" | "group";
55
- name: string | null;
56
45
  };
57
- }, {
58
- id: string;
59
- object: "user" | "bot" | "group";
60
- name: string | null;
61
- }>]>;
46
+ }, string>]>;
62
47
  /**
63
48
  * Schema to extract the `created_by` person name from a Notion page.
64
49
  *
@@ -67,7 +52,7 @@ declare const CreatedBySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
67
52
  * {
68
53
  * created_by: {
69
54
  * id: string;
70
- * object: "user" | "bot" | "group";
55
+ * object: "user" | "group";
71
56
  * name: string | null;
72
57
  * ...
73
58
  * }
@@ -84,75 +69,77 @@ declare const CreatedBySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
84
69
  * const PageSchema = v.object({
85
70
  * id: v.string(),
86
71
  * properties: v.object({
87
- * CreatedByName: NullableCreatedByNameSchema,
72
+ * "Created By": NullableCreatedByNameSchema,
88
73
  * }),
89
74
  * });
90
75
  *
91
76
  * const page = await notion.pages.retrieve({ page_id: "..." });
92
77
  * const parsed = v.parse(PageSchema, page);
93
- * // parsed.properties.CreatedByName: string | null
78
+ * // parsed.properties["Created By"]: string | null
94
79
  * ```
95
80
  */
96
81
  declare const NullableCreatedByNameSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
97
82
  readonly created_by: v.ObjectSchema<{
98
83
  readonly id: v.StringSchema<undefined>;
99
- readonly object: v.PicklistSchema<["user", "bot", "group"], undefined>;
84
+ readonly object: v.PicklistSchema<["user", "group"], undefined>;
100
85
  readonly name: v.NullishSchema<v.StringSchema<undefined>, null>;
101
86
  }, undefined>;
102
87
  }, undefined>, v.TransformAction<{
103
88
  created_by: {
104
89
  id: string;
105
- object: "user" | "bot" | "group";
90
+ object: "user" | "group";
106
91
  name: string | null;
107
92
  };
108
93
  }, string | null>]>;
109
94
  /**
110
- * Schema to extract the `created_by` person ID from a Notion page.
95
+ * Schema factory to extract the `created_by` person object from a Notion page.
96
+ *
97
+ * This is a generic schema factory that accepts another schema as a parameter,
98
+ * allowing you to combine it with building-block schemas such as
99
+ * `UserOrGroupSchema`, `UserSchema`, or `PersonSchema`.
111
100
  *
112
101
  * **Input:**
113
102
  * ```
114
103
  * {
115
104
  * created_by: {
116
105
  * id: string;
117
- * object: "user" | "bot" | "group";
118
- * name: string | null;
106
+ * object: "user" | "group";
107
+ * name?: string | null;
119
108
  * ...
120
109
  * }
121
110
  * }
122
111
  * ```
123
112
  *
124
- * **Output:** `string`
113
+ * **Output:** The output type depends on the schema passed as a parameter.
114
+ *
115
+ * @param schema - A schema that validates the `created_by` user or group object.
125
116
  *
126
117
  * @example
127
118
  * ```ts
128
119
  * import * as v from "valibot";
129
- * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
120
+ * import {
121
+ * CreatedBySchema,
122
+ * UserOrGroupSchema,
123
+ * } from "@nakanoaas/notion-valibot-schema";
130
124
  *
131
125
  * const PageSchema = v.object({
132
126
  * id: v.string(),
133
127
  * properties: v.object({
134
- * CreatedById: CreatedByIdSchema,
128
+ * "Created By": CreatedBySchema(UserOrGroupSchema),
135
129
  * }),
136
130
  * });
137
131
  *
138
132
  * const page = await notion.pages.retrieve({ page_id: "..." });
139
133
  * const parsed = v.parse(PageSchema, page);
140
- * // parsed.properties.CreatedById: string
134
+ * // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
141
135
  * ```
142
136
  */
143
- declare const CreatedByIdSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
144
- readonly created_by: v.ObjectSchema<{
145
- readonly id: v.StringSchema<undefined>;
146
- readonly object: v.PicklistSchema<["user", "bot", "group"], undefined>;
147
- readonly name: v.NullishSchema<v.StringSchema<undefined>, null>;
148
- }, undefined>;
149
- }, undefined>, v.TransformAction<{
150
- created_by: {
151
- id: string;
152
- object: "user" | "bot" | "group";
153
- name: string | null;
154
- };
155
- }, string>]>;
137
+ declare function CreatedBySchema<S extends v.GenericSchema<{
138
+ id: string;
139
+ object: "user" | "group";
140
+ }, unknown>>(schema: S): v.GenericSchema<{
141
+ created_by: v.InferInput<S>;
142
+ }, v.InferOutput<S>>;
156
143
  //#endregion
157
144
  export { CreatedByIdSchema, CreatedBySchema, NullableCreatedByNameSchema };
158
145
  //# sourceMappingURL=created-by.d.cts.map