@nakanoaas/notion-valibot-schema 0.0.4 → 0.0.6

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 (134) hide show
  1. package/README.md +150 -81
  2. package/dist/checkbox.cjs +29 -0
  3. package/dist/checkbox.cjs.map +1 -1
  4. package/dist/checkbox.d.cts +30 -0
  5. package/dist/checkbox.d.mts +30 -0
  6. package/dist/checkbox.mjs +29 -0
  7. package/dist/checkbox.mjs.map +1 -1
  8. package/dist/created-by.cjs +75 -0
  9. package/dist/created-by.cjs.map +1 -1
  10. package/dist/created-by.d.cts +76 -0
  11. package/dist/created-by.d.mts +76 -0
  12. package/dist/created-by.mjs +75 -0
  13. package/dist/created-by.mjs.map +1 -1
  14. package/dist/created-time.cjs +27 -0
  15. package/dist/created-time.cjs.map +1 -1
  16. package/dist/created-time.d.cts +28 -0
  17. package/dist/created-time.d.mts +28 -0
  18. package/dist/created-time.mjs +27 -0
  19. package/dist/created-time.mjs.map +1 -1
  20. package/dist/date.cjs +188 -0
  21. package/dist/date.cjs.map +1 -1
  22. package/dist/date.d.cts +189 -0
  23. package/dist/date.d.mts +189 -0
  24. package/dist/date.mjs +188 -0
  25. package/dist/date.mjs.map +1 -1
  26. package/dist/email.cjs +58 -0
  27. package/dist/email.cjs.map +1 -1
  28. package/dist/email.d.cts +59 -0
  29. package/dist/email.d.mts +59 -0
  30. package/dist/email.mjs +58 -0
  31. package/dist/email.mjs.map +1 -1
  32. package/dist/files.cjs +39 -0
  33. package/dist/files.cjs.map +1 -1
  34. package/dist/files.d.cts +40 -0
  35. package/dist/files.d.mts +40 -0
  36. package/dist/files.mjs +39 -0
  37. package/dist/files.mjs.map +1 -1
  38. package/dist/formula.cjs +72 -0
  39. package/dist/formula.cjs.map +1 -1
  40. package/dist/formula.d.cts +73 -0
  41. package/dist/formula.d.mts +73 -0
  42. package/dist/formula.mjs +72 -0
  43. package/dist/formula.mjs.map +1 -1
  44. package/dist/last-edited-by.cjs +68 -0
  45. package/dist/last-edited-by.cjs.map +1 -1
  46. package/dist/last-edited-by.d.cts +69 -0
  47. package/dist/last-edited-by.d.mts +69 -0
  48. package/dist/last-edited-by.mjs +68 -0
  49. package/dist/last-edited-by.mjs.map +1 -1
  50. package/dist/last-edited-time.cjs +27 -0
  51. package/dist/last-edited-time.cjs.map +1 -1
  52. package/dist/last-edited-time.d.cts +28 -0
  53. package/dist/last-edited-time.d.mts +28 -0
  54. package/dist/last-edited-time.mjs +27 -0
  55. package/dist/last-edited-time.mjs.map +1 -1
  56. package/dist/multi-select.cjs +60 -0
  57. package/dist/multi-select.cjs.map +1 -1
  58. package/dist/multi-select.d.cts +79 -18
  59. package/dist/multi-select.d.mts +79 -18
  60. package/dist/multi-select.mjs +60 -0
  61. package/dist/multi-select.mjs.map +1 -1
  62. package/dist/number.cjs +58 -0
  63. package/dist/number.cjs.map +1 -1
  64. package/dist/number.d.cts +59 -0
  65. package/dist/number.d.mts +59 -0
  66. package/dist/number.mjs +58 -0
  67. package/dist/number.mjs.map +1 -1
  68. package/dist/people.cjs +84 -0
  69. package/dist/people.cjs.map +1 -1
  70. package/dist/people.d.cts +85 -0
  71. package/dist/people.d.mts +85 -0
  72. package/dist/people.mjs +84 -0
  73. package/dist/people.mjs.map +1 -1
  74. package/dist/phone-number.cjs +58 -0
  75. package/dist/phone-number.cjs.map +1 -1
  76. package/dist/phone-number.d.cts +59 -0
  77. package/dist/phone-number.d.mts +59 -0
  78. package/dist/phone-number.mjs +58 -0
  79. package/dist/phone-number.mjs.map +1 -1
  80. package/dist/place.cjs +128 -0
  81. package/dist/place.cjs.map +1 -1
  82. package/dist/place.d.cts +85 -0
  83. package/dist/place.d.mts +85 -0
  84. package/dist/place.mjs +128 -0
  85. package/dist/place.mjs.map +1 -1
  86. package/dist/relation.cjs +131 -0
  87. package/dist/relation.cjs.map +1 -1
  88. package/dist/relation.d.cts +94 -0
  89. package/dist/relation.d.mts +94 -0
  90. package/dist/relation.mjs +131 -0
  91. package/dist/relation.mjs.map +1 -1
  92. package/dist/rollup.cjs +200 -0
  93. package/dist/rollup.cjs.map +1 -1
  94. package/dist/rollup.d.cts +201 -0
  95. package/dist/rollup.d.mts +201 -0
  96. package/dist/rollup.mjs +200 -0
  97. package/dist/rollup.mjs.map +1 -1
  98. package/dist/select.cjs +120 -0
  99. package/dist/select.cjs.map +1 -1
  100. package/dist/select.d.cts +157 -36
  101. package/dist/select.d.mts +157 -36
  102. package/dist/select.mjs +120 -0
  103. package/dist/select.mjs.map +1 -1
  104. package/dist/status.cjs +120 -0
  105. package/dist/status.cjs.map +1 -1
  106. package/dist/status.d.cts +157 -36
  107. package/dist/status.d.mts +157 -36
  108. package/dist/status.mjs +120 -0
  109. package/dist/status.mjs.map +1 -1
  110. package/dist/text.cjs +100 -0
  111. package/dist/text.cjs.map +1 -1
  112. package/dist/text.d.cts +63 -0
  113. package/dist/text.d.mts +63 -0
  114. package/dist/text.mjs +100 -0
  115. package/dist/text.mjs.map +1 -1
  116. package/dist/unique-id.cjs +69 -0
  117. package/dist/unique-id.cjs.map +1 -1
  118. package/dist/unique-id.d.cts +70 -0
  119. package/dist/unique-id.d.mts +70 -0
  120. package/dist/unique-id.mjs +69 -0
  121. package/dist/unique-id.mjs.map +1 -1
  122. package/dist/url.cjs +58 -0
  123. package/dist/url.cjs.map +1 -1
  124. package/dist/url.d.cts +59 -0
  125. package/dist/url.d.mts +59 -0
  126. package/dist/url.mjs +58 -0
  127. package/dist/url.mjs.map +1 -1
  128. package/dist/verification.cjs +80 -0
  129. package/dist/verification.cjs.map +1 -1
  130. package/dist/verification.d.cts +81 -0
  131. package/dist/verification.d.mts +81 -0
  132. package/dist/verification.mjs +80 -0
  133. package/dist/verification.mjs.map +1 -1
  134. package/package.json +2 -2
package/README.md CHANGED
@@ -1,28 +1,72 @@
1
1
  # Notion Valibot Schema
2
2
 
3
- [![npm](https://img.shields.io/npm/v/%40nakanoaas%2Fnotion-valibot-schema)](https://www.npmjs.com/package/@nakanoaas/notion-valibot-schema) [![JSR](https://jsr.io/badges/@nakanoaas/notion-valibot-schema)](https://jsr.io/@nakanoaas/notion-valibot-schema)
3
+ [![npm version](https://img.shields.io/npm/v/%40nakanoaas%2Fnotion-valibot-schema)](https://www.npmjs.com/package/@nakanoaas/notion-valibot-schema)
4
+ [![JSR version](https://jsr.io/badges/@nakanoaas/notion-valibot-schema)](https://jsr.io/@nakanoaas/notion-valibot-schema)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
6
 
5
- A small collection of **[Valibot](https://github.com/fabian-hiller/valibot)** schemas for the Notion API.
7
+ **Turn Notion's nested API responses into clean, typed JavaScript values.**
6
8
 
7
- It helps you **validate and transform** Notion `properties` into plain JavaScript values (e.g. `string`, `number`, `Date`, `string[]`) so you can work with the results without dealing with Notion’s nested property shapes.
9
+ This library provides a collection of [Valibot](https://github.com/fabian-hiller/valibot) schemas specifically designed to handle Notion API objects. It doesn't just validate; it **transforms** deeply nested Notion properties into simple, usable primitives like `string`, `number`, `Date`, and `boolean`.
8
10
 
9
- ## Install
11
+ ## The Problem
10
12
 
11
- ### npm / pnpm / yarn
13
+ When you fetch a page from Notion, properties are deeply nested. To access them type-safely, you end up writing **verbose type guards for every single property**.
12
14
 
13
- ```bash
14
- npm i @nakanoaas/notion-valibot-schema valibot
15
+ ```ts
16
+ // 😫 The "Native" Way (Boilerplate Hell)
17
+
18
+ // 1. Get the property
19
+ const statusProp = page.properties["Status"];
20
+
21
+ // 2. Check if it exists and has the correct type
22
+ if (statusProp?.type === "status" && statusProp.status) {
23
+ // 3. Finally access the value
24
+ console.log(statusProp.status.name); // "In Progress"
25
+ }
26
+
27
+ // Repeat this for every property...
28
+ const tagsProp = page.properties["Tags"];
29
+ if (tagsProp?.type === "multi_select") {
30
+ console.log(tagsProp.multi_select.map(t => t.name));
31
+ }
15
32
  ```
16
33
 
34
+ ## The Solution
35
+
36
+ With `@nakanoaas/notion-valibot-schema`, you get this:
37
+
38
+ ```ts
39
+ // After parsing
40
+ {
41
+ Status: "In Progress",
42
+ Tags: ["Urgent", "Work"],
43
+ DueDate: new Date("2023-12-25")
44
+ }
45
+ ```
46
+
47
+ No more checking for `property.type === 'date'`, handling `null`, or digging through 3 layers of objects just to get a string.
48
+
49
+ ## Features
50
+
51
+ - 🧩 **Composable**: Works seamlessly with standard Valibot schemas (`v.object`, `v.array`, etc.).
52
+ - ✨ **Transformative**: Automatically extracts values (e.g., `RichText[]` -> `string`).
53
+ - 🔒 **Type-Safe**: Full TypeScript support with inferred types.
54
+ - ✅ **Well Tested**: Backed by a comprehensive test suite covering edge cases.
55
+ - 🛠 **Comprehensive**: Supports complex properties like Rollups, Formulas, and Relations.
56
+
57
+ ## Installation
58
+
59
+ ### Node.js (npm / pnpm / yarn / bun)
60
+
17
61
  ```bash
18
- pnpm add @nakanoaas/notion-valibot-schema valibot
62
+ npm install @nakanoaas/notion-valibot-schema valibot
19
63
  ```
20
64
 
21
65
  ```bash
22
- yarn add @nakanoaas/notion-valibot-schema valibot
66
+ pnpm add @nakanoaas/notion-valibot-schema valibot
23
67
  ```
24
68
 
25
- ### JSR
69
+ ### Deno / JSR
26
70
 
27
71
  ```bash
28
72
  deno add @nakanoaas/notion-valibot-schema @valibot/valibot
@@ -30,101 +74,126 @@ deno add @nakanoaas/notion-valibot-schema @valibot/valibot
30
74
 
31
75
  ## Usage
32
76
 
33
- ### Parse a Notion database page (common pattern)
77
+ ### Basic Example
34
78
 
35
- This example shows how to parse a page returned by `notion.pages.retrieve()` (or an item from `notion.dataSources.query().results`) and turn its `properties` into plain values.
79
+ Here is how to validate and transform a Notion page retrieved from the API.
36
80
 
37
81
  ```ts
38
82
  import * as v from "valibot";
39
83
  import {
40
- CheckboxSchema,
41
- FilesSchema,
42
- MultiSelectSchema,
43
- NullableDateSchema,
44
- NullableNumberSchema,
45
- NullableUrlSchema,
46
- RelationSchema,
84
+ TitleSchema,
47
85
  RichTextSchema,
48
86
  StatusSchema,
49
- TitleSchema,
87
+ MultiSelectSchema,
88
+ NullableDateSchema,
89
+ CheckboxSchema,
50
90
  } from "@nakanoaas/notion-valibot-schema";
51
91
 
52
- // Property keys must match your database property names exactly.
53
- const NotionTaskPageSchema = v.object({
92
+ // 1. Define your schema based on your Database properties
93
+ const TaskPageSchema = v.object({
54
94
  id: v.string(),
55
95
  properties: v.object({
56
- Name: TitleSchema, // -> string
57
- Notes: RichTextSchema, // -> string
58
- Status: StatusSchema(v.picklist(["ToDo", "In Progress", "Done"])), // -> "ToDo" | "In Progress" | "Done"
59
- Tags: MultiSelectSchema(v.string()), // -> string[]
60
- Due: NullableDateSchema, // -> Date | null
61
- Points: NullableNumberSchema, // -> number | null
62
- Done: CheckboxSchema, // -> boolean
63
- Website: NullableUrlSchema, // -> string | null
64
- Attachments: FilesSchema, // -> string[] (URLs)
65
- Related: RelationSchema, // -> string[] (page IDs)
96
+ // Map "Name" property -> string
97
+ Name: TitleSchema,
98
+
99
+ // Map "Description" property -> string
100
+ Description: RichTextSchema,
101
+
102
+ // Map "Status" property -> "ToDo" | "Doing" | "Done"
103
+ Status: StatusSchema(v.picklist(["ToDo", "Doing", "Done"])),
104
+
105
+ // Map "Tags" -> string[]
106
+ Tags: MultiSelectSchema(v.string()),
107
+
108
+ // Map "Due Date" -> Date | null
109
+ DueDate: NullableDateSchema,
110
+
111
+ // Map "IsUrgent" -> boolean
112
+ IsUrgent: CheckboxSchema,
66
113
  }),
67
114
  });
68
115
 
69
- // Fetch a page with the Notion SDK
70
- // const page = await notion.pages.retrieve({ page_id: "..." });
116
+ // 2. Fetch data from Notion
117
+ const page = await notion.pages.retrieve({ page_id: "..." });
71
118
 
72
- // Validate + transform
73
- const task = v.parse(NotionTaskPageSchema, page);
119
+ // 3. Parse and transform
120
+ const task = v.parse(TaskPageSchema, page);
74
121
 
75
- // task.properties is now easy to use
76
- task.properties.Name; // string
77
- task.properties.Due; // Date | null
78
- task.properties.Tags; // string[]
122
+ // 4. Use your clean data
123
+ console.log(task.properties.Name); // "Buy Milk" (string)
124
+ console.log(task.properties.DueDate); // Date object or null
125
+ console.log(task.properties.Tags); // ["Personal", "Shopping"] (string[])
79
126
  ```
80
127
 
81
- ### Parse query results
128
+ ### Handling Lists (Query Results)
129
+
130
+ To parse the results of a database query:
82
131
 
83
132
  ```ts
84
- import * as v from "valibot";
133
+ const TaskListSchema = v.array(TaskPageSchema);
134
+
135
+ const { results } = await notion.databases.query({ database_id: "..." });
136
+ const tasks = v.parse(TaskListSchema, results);
137
+ ```
85
138
 
86
- const NotionTaskListSchema = v.array(NotionTaskPageSchema);
139
+ ## Schema Reference
140
+
141
+ > 📚 **For complete API documentation, including all available schemas and types, please visit the [JSR Documentation](https://jsr.io/@nakanoaas/notion-valibot-schema/doc).**
142
+
143
+ | Notion Property | Schema | Transformed Output (Type) |
144
+ | :--- | :--- | :--- |
145
+ | **Text** / Title | `TitleSchema` / `RichTextSchema` | `string` |
146
+ | **Number** | `NumberSchema` / `NullableNumberSchema` | `number` / `number \| null` |
147
+ | **Checkbox** | `CheckboxSchema` | `boolean` |
148
+ | **Select** | `SelectSchema(schema)` | `Inferred<schema>` |
149
+ | **Multi-Select** | `MultiSelectSchema(schema)` | `Inferred<schema>[]` |
150
+ | **Status** | `StatusSchema(schema)` | `Inferred<schema>` |
151
+ | **Date** | `DateSchema` / `NullableDateSchema` | `Date` / `Date \| null` |
152
+ | **Relation** | `RelationSchema` | `string[]` (Page IDs) |
153
+ | **Relation** (Single) | `SingleRelationSchema` | `string` (Page ID) |
154
+ | **URL** | `UrlSchema` | `string` |
155
+ | **Email** | `EmailSchema` | `string` |
156
+ | **Phone** | `PhoneNumberSchema` | `string` |
157
+ | **Files** | `FilesSchema` | `string[]` (URLs) |
158
+ | **Created/Edited By** | `CreatedBySchema` / `LastEditedBySchema` | `string` (User ID) |
159
+ | **Created/Edited Time**| `CreatedTimeSchema` / `LastEditedTimeSchema` | `Date` |
160
+
161
+ ### Advanced Schemas
162
+
163
+ #### Formulas
164
+ Formulas in Notion can return different types (string, number, boolean, date). Use `FormulaSchema` with a specific inner schema to handle this.
87
165
 
88
- // const { results } = await notion.dataSources.query({ data_source_id: "..." });
89
- const tasks = v.parse(NotionTaskListSchema, results);
166
+ ```ts
167
+ import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-schema";
168
+
169
+ const MySchema = v.object({
170
+ // If your formula returns text
171
+ MyFormula: FormulaSchema(RichTextSchema),
172
+ });
90
173
  ```
91
174
 
92
- ## Exports
93
-
94
- This package re-exports all schemas from `src/index.ts`.
95
-
96
- - **Text**
97
- - `TitleSchema`: `{ title: RichText[] }` → `string`
98
- - `RichTextSchema`: `{ rich_text: RichText[] }` → `string`
99
- - **Numbers**
100
- - `NumberSchema`: `{ number: number }` `number`
101
- - `NullableNumberSchema`: `{ number: number | null }` → `number | null`
102
- - **Dates**
103
- - `DateSchema`: `{ date: { start: string } }` → `Date`
104
- - `NullableDateSchema`: `{ date: { start: string } | null }` → `Date | null`
105
- - `FullDateSchema`: `{ date: { start: string; end: string } }` → `{ start: Date; end: Date }`
106
- - `NullableFullDateSchema`: `{ date: { start: string; end: string | null } | null }` → `{ start: Date; end: Date | null } | null`
107
- - **Select-like**
108
- - `SelectSchema(schema)`: `{ select: { name: ... } }` → inferred
109
- - `NullableSelectSchema(schema)`: `{ select: { name: ... } | null }` → inferred | `null`
110
- - `StatusSchema(schema)`: `{ status: { name: ... } }` → inferred
111
- - `NullableStatusSchema(schema)`: `{ status: { name: ... } | null }` → inferred | `null`
112
- - `MultiSelectSchema(schema)`: `{ multi_select: { name: ... }[] }` → inferred[]
113
- - **Other common property types**
114
- - `CheckboxSchema`: `{ checkbox: boolean }` → `boolean`
115
- - `EmailSchema` / `NullableEmailSchema`
116
- - `PhoneNumberSchema` / `NullablePhoneNumberSchema`
117
- - `UrlSchema` / `NullableUrlSchema`
118
- - `RelationSchema`: `{ relation: { id: string }[] }` → `string[]`
119
- - `FilesSchema`: `{ files: (file | external)[] }` → `string[]` (URLs)
120
-
121
- And more: created/last-edited fields, rollup, formula, unique_id, people, place, verification, etc.
122
-
123
- ## Notes
124
-
125
- - **Property names are user-defined** in Notion. In your schema, keys like `Name` / `Status` must match the names in your database.
126
- - These schemas focus on **parsing property values**, so you can embed them in your own page/database schemas.
175
+ #### Rollups
176
+ Rollups are powerful but complex. We provide helpers for common rollup types.
177
+
178
+ ```ts
179
+ import {
180
+ RollupNumberSchema,
181
+ RollupDateSchema,
182
+ RollupArraySchema
183
+ } from "@nakanoaas/notion-valibot-schema";
184
+
185
+ const MySchema = v.object({
186
+ // Sum/Average rollup (returns number)
187
+ TotalCost: RollupNumberSchema,
188
+
189
+ // Date rollup (returns Date)
190
+ LatestMeeting: RollupDateSchema,
191
+
192
+ // Array rollup (e.g., pulling tags from related items)
193
+ AllTags: RollupArraySchema(v.string())
194
+ });
195
+ ```
127
196
 
128
197
  ## License
129
198
 
130
- MIT
199
+ MIT © [Nakano as a Service](https://github.com/nakanoasaservice)
package/dist/checkbox.cjs CHANGED
@@ -3,6 +3,35 @@ let valibot = require("valibot");
3
3
  valibot = require_rolldown_runtime.__toESM(valibot);
4
4
 
5
5
  //#region src/checkbox.ts
6
+ /**
7
+ * Schema to extract the `checkbox` property from a Notion page property.
8
+ *
9
+ * **Input:**
10
+ * ```
11
+ * {
12
+ * checkbox: boolean;
13
+ * }
14
+ * ```
15
+ *
16
+ * **Output:** `boolean`
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import * as v from "valibot";
21
+ * import { CheckboxSchema } from "@nakanoaas/notion-valibot-utils";
22
+ *
23
+ * const PageSchema = v.object({
24
+ * id: v.string(),
25
+ * properties: v.object({
26
+ * Checkbox: CheckboxSchema,
27
+ * }),
28
+ * });
29
+ *
30
+ * const page = await notion.pages.retrieve({ page_id: "..." });
31
+ * const parsed = v.parse(PageSchema, page);
32
+ * // parsed.properties.Checkbox: boolean
33
+ * ```
34
+ */
6
35
  const CheckboxSchema = valibot.pipe(valibot.object({ checkbox: valibot.boolean() }), valibot.transform((v) => v.checkbox));
7
36
 
8
37
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.cjs","names":["v"],"sources":["../src/checkbox.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport const CheckboxSchema = v.pipe(\n\tv.object({\n\t\tcheckbox: v.boolean(),\n\t}),\n\tv.transform((v) => v.checkbox),\n);\n"],"mappings":";;;;;AAEA,MAAa,iBAAiBA,QAAE,KAC/BA,QAAE,OAAO,EACR,UAAUA,QAAE,SAAS,EACrB,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,SAAS,CAC9B"}
1
+ {"version":3,"file":"checkbox.cjs","names":["v"],"sources":["../src/checkbox.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema to extract the `checkbox` property from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * checkbox: boolean;\n * }\n * ```\n *\n * **Output:** `boolean`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { CheckboxSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Checkbox: CheckboxSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Checkbox: boolean\n * ```\n */\nexport const CheckboxSchema = v.pipe(\n\tv.object({\n\t\tcheckbox: v.boolean(),\n\t}),\n\tv.transform((v) => v.checkbox),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,iBAAiBA,QAAE,KAC/BA,QAAE,OAAO,EACR,UAAUA,QAAE,SAAS,EACrB,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,SAAS,CAC9B"}
@@ -1,6 +1,36 @@
1
1
  import * as v from "valibot";
2
2
 
3
3
  //#region src/checkbox.d.ts
4
+
5
+ /**
6
+ * Schema to extract the `checkbox` property from a Notion page property.
7
+ *
8
+ * **Input:**
9
+ * ```
10
+ * {
11
+ * checkbox: boolean;
12
+ * }
13
+ * ```
14
+ *
15
+ * **Output:** `boolean`
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import * as v from "valibot";
20
+ * import { CheckboxSchema } from "@nakanoaas/notion-valibot-utils";
21
+ *
22
+ * const PageSchema = v.object({
23
+ * id: v.string(),
24
+ * properties: v.object({
25
+ * Checkbox: CheckboxSchema,
26
+ * }),
27
+ * });
28
+ *
29
+ * const page = await notion.pages.retrieve({ page_id: "..." });
30
+ * const parsed = v.parse(PageSchema, page);
31
+ * // parsed.properties.Checkbox: boolean
32
+ * ```
33
+ */
4
34
  declare const CheckboxSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
5
35
  readonly checkbox: v.BooleanSchema<undefined>;
6
36
  }, undefined>, v.TransformAction<{
@@ -1,6 +1,36 @@
1
1
  import * as v from "valibot";
2
2
 
3
3
  //#region src/checkbox.d.ts
4
+
5
+ /**
6
+ * Schema to extract the `checkbox` property from a Notion page property.
7
+ *
8
+ * **Input:**
9
+ * ```
10
+ * {
11
+ * checkbox: boolean;
12
+ * }
13
+ * ```
14
+ *
15
+ * **Output:** `boolean`
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import * as v from "valibot";
20
+ * import { CheckboxSchema } from "@nakanoaas/notion-valibot-utils";
21
+ *
22
+ * const PageSchema = v.object({
23
+ * id: v.string(),
24
+ * properties: v.object({
25
+ * Checkbox: CheckboxSchema,
26
+ * }),
27
+ * });
28
+ *
29
+ * const page = await notion.pages.retrieve({ page_id: "..." });
30
+ * const parsed = v.parse(PageSchema, page);
31
+ * // parsed.properties.Checkbox: boolean
32
+ * ```
33
+ */
4
34
  declare const CheckboxSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
5
35
  readonly checkbox: v.BooleanSchema<undefined>;
6
36
  }, undefined>, v.TransformAction<{
package/dist/checkbox.mjs CHANGED
@@ -1,6 +1,35 @@
1
1
  import * as v from "valibot";
2
2
 
3
3
  //#region src/checkbox.ts
4
+ /**
5
+ * Schema to extract the `checkbox` property from a Notion page property.
6
+ *
7
+ * **Input:**
8
+ * ```
9
+ * {
10
+ * checkbox: boolean;
11
+ * }
12
+ * ```
13
+ *
14
+ * **Output:** `boolean`
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import * as v from "valibot";
19
+ * import { CheckboxSchema } from "@nakanoaas/notion-valibot-utils";
20
+ *
21
+ * const PageSchema = v.object({
22
+ * id: v.string(),
23
+ * properties: v.object({
24
+ * Checkbox: CheckboxSchema,
25
+ * }),
26
+ * });
27
+ *
28
+ * const page = await notion.pages.retrieve({ page_id: "..." });
29
+ * const parsed = v.parse(PageSchema, page);
30
+ * // parsed.properties.Checkbox: boolean
31
+ * ```
32
+ */
4
33
  const CheckboxSchema = v.pipe(v.object({ checkbox: v.boolean() }), v.transform((v$1) => v$1.checkbox));
5
34
 
6
35
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"checkbox.mjs","names":["v"],"sources":["../src/checkbox.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nexport const CheckboxSchema = v.pipe(\n\tv.object({\n\t\tcheckbox: v.boolean(),\n\t}),\n\tv.transform((v) => v.checkbox),\n);\n"],"mappings":";;;AAEA,MAAa,iBAAiB,EAAE,KAC/B,EAAE,OAAO,EACR,UAAU,EAAE,SAAS,EACrB,CAAC,EACF,EAAE,WAAW,QAAMA,IAAE,SAAS,CAC9B"}
1
+ {"version":3,"file":"checkbox.mjs","names":["v"],"sources":["../src/checkbox.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema to extract the `checkbox` property from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * checkbox: boolean;\n * }\n * ```\n *\n * **Output:** `boolean`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { CheckboxSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Checkbox: CheckboxSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Checkbox: boolean\n * ```\n */\nexport const CheckboxSchema = v.pipe(\n\tv.object({\n\t\tcheckbox: v.boolean(),\n\t}),\n\tv.transform((v) => v.checkbox),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,iBAAiB,EAAE,KAC/B,EAAE,OAAO,EACR,UAAU,EAAE,SAAS,EACrB,CAAC,EACF,EAAE,WAAW,QAAMA,IAAE,SAAS,CAC9B"}
@@ -4,7 +4,82 @@ let valibot = require("valibot");
4
4
  valibot = require_rolldown_runtime.__toESM(valibot);
5
5
 
6
6
  //#region src/created-by.ts
7
+ /**
8
+ * Schema to extract the `created_by` person object from a Notion page.
9
+ *
10
+ * **Input:**
11
+ * ```
12
+ * {
13
+ * created_by: {
14
+ * id: string;
15
+ * object: "user" | "bot" | "group";
16
+ * name: string | null;
17
+ * ...
18
+ * }
19
+ * }
20
+ * ```
21
+ *
22
+ * **Output:**
23
+ * ```
24
+ * {
25
+ * id: string;
26
+ * object: "user" | "bot" | "group";
27
+ * name: string | null;
28
+ * }
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import * as v from "valibot";
34
+ * import { CreatedBySchema } from "@nakanoaas/notion-valibot-schema";
35
+ *
36
+ * const PageSchema = v.object({
37
+ * id: v.string(),
38
+ * properties: v.object({
39
+ * CreatedBy: CreatedBySchema,
40
+ * }),
41
+ * });
42
+ *
43
+ * const page = await notion.pages.retrieve({ page_id: "..." });
44
+ * const parsed = v.parse(PageSchema, page);
45
+ * // parsed.properties.CreatedBy: { id: string; object: "user" | "bot" | "group"; name: string | null }
46
+ * ```
47
+ */
7
48
  const CreatedBySchema = valibot.pipe(valibot.object({ created_by: require_people.PersonSchema }), valibot.transform((v) => v.created_by));
49
+ /**
50
+ * Schema to extract the `created_by` person ID from a Notion page.
51
+ *
52
+ * **Input:**
53
+ * ```
54
+ * {
55
+ * created_by: {
56
+ * id: string;
57
+ * object: "user" | "bot" | "group";
58
+ * name: string | null;
59
+ * ...
60
+ * }
61
+ * }
62
+ * ```
63
+ *
64
+ * **Output:** `string`
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import * as v from "valibot";
69
+ * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
70
+ *
71
+ * const PageSchema = v.object({
72
+ * id: v.string(),
73
+ * properties: v.object({
74
+ * CreatedById: CreatedByIdSchema,
75
+ * }),
76
+ * });
77
+ *
78
+ * const page = await notion.pages.retrieve({ page_id: "..." });
79
+ * const parsed = v.parse(PageSchema, page);
80
+ * // parsed.properties.CreatedById: string
81
+ * ```
82
+ */
8
83
  const CreatedByIdSchema = valibot.pipe(valibot.object({ created_by: require_people.PersonSchema }), valibot.transform((v) => v.created_by.id));
9
84
 
10
85
  //#endregion
@@ -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\nexport const CreatedBySchema = v.pipe(\n\tv.object({\n\t\tcreated_by: PersonSchema,\n\t}),\n\tv.transform((v) => v.created_by),\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":";;;;;;AAIA,MAAa,kBAAkBA,QAAE,KAChCA,QAAE,OAAO,EACR,YAAYC,6BACZ,CAAC,EACFD,QAAE,WAAW,MAAM,EAAE,WAAW,CAChC;AAED,MAAa,oBAAoBA,QAAE,KAClCA,QAAE,OAAO,EACR,YAAYC,6BACZ,CAAC,EACFD,QAAE,WAAW,MAAM,EAAE,WAAW,GAAG,CACnC"}
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 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,6BACZ,CAAC,EACFD,QAAE,WAAW,MAAM,EAAE,WAAW,CAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCD,MAAa,oBAAoBA,QAAE,KAClCA,QAAE,OAAO,EACR,YAAYC,6BACZ,CAAC,EACFD,QAAE,WAAW,MAAM,EAAE,WAAW,GAAG,CACnC"}
@@ -1,6 +1,48 @@
1
1
  import * as v from "valibot";
2
2
 
3
3
  //#region src/created-by.d.ts
4
+
5
+ /**
6
+ * Schema to extract the `created_by` person object from a Notion page.
7
+ *
8
+ * **Input:**
9
+ * ```
10
+ * {
11
+ * created_by: {
12
+ * id: string;
13
+ * object: "user" | "bot" | "group";
14
+ * name: string | null;
15
+ * ...
16
+ * }
17
+ * }
18
+ * ```
19
+ *
20
+ * **Output:**
21
+ * ```
22
+ * {
23
+ * id: string;
24
+ * object: "user" | "bot" | "group";
25
+ * name: string | null;
26
+ * }
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import * as v from "valibot";
32
+ * import { CreatedBySchema } from "@nakanoaas/notion-valibot-schema";
33
+ *
34
+ * const PageSchema = v.object({
35
+ * id: v.string(),
36
+ * properties: v.object({
37
+ * CreatedBy: CreatedBySchema,
38
+ * }),
39
+ * });
40
+ *
41
+ * const page = await notion.pages.retrieve({ page_id: "..." });
42
+ * const parsed = v.parse(PageSchema, page);
43
+ * // parsed.properties.CreatedBy: { id: string; object: "user" | "bot" | "group"; name: string | null }
44
+ * ```
45
+ */
4
46
  declare const CreatedBySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
5
47
  readonly created_by: v.ObjectSchema<{
6
48
  readonly id: v.StringSchema<undefined>;
@@ -18,6 +60,40 @@ declare const CreatedBySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
18
60
  object: "user" | "bot" | "group";
19
61
  name: string | null;
20
62
  }>]>;
63
+ /**
64
+ * Schema to extract the `created_by` person ID from a Notion page.
65
+ *
66
+ * **Input:**
67
+ * ```
68
+ * {
69
+ * created_by: {
70
+ * id: string;
71
+ * object: "user" | "bot" | "group";
72
+ * name: string | null;
73
+ * ...
74
+ * }
75
+ * }
76
+ * ```
77
+ *
78
+ * **Output:** `string`
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * import * as v from "valibot";
83
+ * import { CreatedByIdSchema } from "@nakanoaas/notion-valibot-schema";
84
+ *
85
+ * const PageSchema = v.object({
86
+ * id: v.string(),
87
+ * properties: v.object({
88
+ * CreatedById: CreatedByIdSchema,
89
+ * }),
90
+ * });
91
+ *
92
+ * const page = await notion.pages.retrieve({ page_id: "..." });
93
+ * const parsed = v.parse(PageSchema, page);
94
+ * // parsed.properties.CreatedById: string
95
+ * ```
96
+ */
21
97
  declare const CreatedByIdSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
22
98
  readonly created_by: v.ObjectSchema<{
23
99
  readonly id: v.StringSchema<undefined>;