@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.
- package/README.md +150 -81
- package/dist/checkbox.cjs +29 -0
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.d.cts +30 -0
- package/dist/checkbox.d.mts +30 -0
- package/dist/checkbox.mjs +29 -0
- package/dist/checkbox.mjs.map +1 -1
- package/dist/created-by.cjs +75 -0
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.d.cts +76 -0
- package/dist/created-by.d.mts +76 -0
- package/dist/created-by.mjs +75 -0
- package/dist/created-by.mjs.map +1 -1
- package/dist/created-time.cjs +27 -0
- package/dist/created-time.cjs.map +1 -1
- package/dist/created-time.d.cts +28 -0
- package/dist/created-time.d.mts +28 -0
- package/dist/created-time.mjs +27 -0
- package/dist/created-time.mjs.map +1 -1
- package/dist/date.cjs +188 -0
- package/dist/date.cjs.map +1 -1
- package/dist/date.d.cts +189 -0
- package/dist/date.d.mts +189 -0
- package/dist/date.mjs +188 -0
- package/dist/date.mjs.map +1 -1
- package/dist/email.cjs +58 -0
- package/dist/email.cjs.map +1 -1
- package/dist/email.d.cts +59 -0
- package/dist/email.d.mts +59 -0
- package/dist/email.mjs +58 -0
- package/dist/email.mjs.map +1 -1
- package/dist/files.cjs +39 -0
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts +40 -0
- package/dist/files.d.mts +40 -0
- package/dist/files.mjs +39 -0
- package/dist/files.mjs.map +1 -1
- package/dist/formula.cjs +72 -0
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +73 -0
- package/dist/formula.d.mts +73 -0
- package/dist/formula.mjs +72 -0
- package/dist/formula.mjs.map +1 -1
- package/dist/last-edited-by.cjs +68 -0
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.d.cts +69 -0
- package/dist/last-edited-by.d.mts +69 -0
- package/dist/last-edited-by.mjs +68 -0
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/last-edited-time.cjs +27 -0
- package/dist/last-edited-time.cjs.map +1 -1
- package/dist/last-edited-time.d.cts +28 -0
- package/dist/last-edited-time.d.mts +28 -0
- package/dist/last-edited-time.mjs +27 -0
- package/dist/last-edited-time.mjs.map +1 -1
- package/dist/multi-select.cjs +60 -0
- package/dist/multi-select.cjs.map +1 -1
- package/dist/multi-select.d.cts +79 -18
- package/dist/multi-select.d.mts +79 -18
- package/dist/multi-select.mjs +60 -0
- package/dist/multi-select.mjs.map +1 -1
- package/dist/number.cjs +58 -0
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.cts +59 -0
- package/dist/number.d.mts +59 -0
- package/dist/number.mjs +58 -0
- package/dist/number.mjs.map +1 -1
- package/dist/people.cjs +84 -0
- package/dist/people.cjs.map +1 -1
- package/dist/people.d.cts +85 -0
- package/dist/people.d.mts +85 -0
- package/dist/people.mjs +84 -0
- package/dist/people.mjs.map +1 -1
- package/dist/phone-number.cjs +58 -0
- package/dist/phone-number.cjs.map +1 -1
- package/dist/phone-number.d.cts +59 -0
- package/dist/phone-number.d.mts +59 -0
- package/dist/phone-number.mjs +58 -0
- package/dist/phone-number.mjs.map +1 -1
- package/dist/place.cjs +128 -0
- package/dist/place.cjs.map +1 -1
- package/dist/place.d.cts +85 -0
- package/dist/place.d.mts +85 -0
- package/dist/place.mjs +128 -0
- package/dist/place.mjs.map +1 -1
- package/dist/relation.cjs +131 -0
- package/dist/relation.cjs.map +1 -1
- package/dist/relation.d.cts +94 -0
- package/dist/relation.d.mts +94 -0
- package/dist/relation.mjs +131 -0
- package/dist/relation.mjs.map +1 -1
- package/dist/rollup.cjs +200 -0
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +201 -0
- package/dist/rollup.d.mts +201 -0
- package/dist/rollup.mjs +200 -0
- package/dist/rollup.mjs.map +1 -1
- package/dist/select.cjs +120 -0
- package/dist/select.cjs.map +1 -1
- package/dist/select.d.cts +157 -36
- package/dist/select.d.mts +157 -36
- package/dist/select.mjs +120 -0
- package/dist/select.mjs.map +1 -1
- package/dist/status.cjs +120 -0
- package/dist/status.cjs.map +1 -1
- package/dist/status.d.cts +157 -36
- package/dist/status.d.mts +157 -36
- package/dist/status.mjs +120 -0
- package/dist/status.mjs.map +1 -1
- package/dist/text.cjs +100 -0
- package/dist/text.cjs.map +1 -1
- package/dist/text.d.cts +63 -0
- package/dist/text.d.mts +63 -0
- package/dist/text.mjs +100 -0
- package/dist/text.mjs.map +1 -1
- package/dist/unique-id.cjs +69 -0
- package/dist/unique-id.cjs.map +1 -1
- package/dist/unique-id.d.cts +70 -0
- package/dist/unique-id.d.mts +70 -0
- package/dist/unique-id.mjs +69 -0
- package/dist/unique-id.mjs.map +1 -1
- package/dist/url.cjs +58 -0
- package/dist/url.cjs.map +1 -1
- package/dist/url.d.cts +59 -0
- package/dist/url.d.mts +59 -0
- package/dist/url.mjs +58 -0
- package/dist/url.mjs.map +1 -1
- package/dist/verification.cjs +80 -0
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.d.cts +81 -0
- package/dist/verification.d.mts +81 -0
- package/dist/verification.mjs +80 -0
- package/dist/verification.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,28 +1,72 @@
|
|
|
1
1
|
# Notion Valibot Schema
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@nakanoaas/notion-valibot-schema)
|
|
3
|
+
[](https://www.npmjs.com/package/@nakanoaas/notion-valibot-schema)
|
|
4
|
+
[](https://jsr.io/@nakanoaas/notion-valibot-schema)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
**Turn Notion's nested API responses into clean, typed JavaScript values.**
|
|
6
8
|
|
|
7
|
-
It
|
|
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
|
-
##
|
|
11
|
+
## The Problem
|
|
10
12
|
|
|
11
|
-
|
|
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
|
-
```
|
|
14
|
-
|
|
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
|
-
|
|
62
|
+
npm install @nakanoaas/notion-valibot-schema valibot
|
|
19
63
|
```
|
|
20
64
|
|
|
21
65
|
```bash
|
|
22
|
-
|
|
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
|
-
###
|
|
77
|
+
### Basic Example
|
|
34
78
|
|
|
35
|
-
|
|
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
|
-
|
|
41
|
-
FilesSchema,
|
|
42
|
-
MultiSelectSchema,
|
|
43
|
-
NullableDateSchema,
|
|
44
|
-
NullableNumberSchema,
|
|
45
|
-
NullableUrlSchema,
|
|
46
|
-
RelationSchema,
|
|
84
|
+
TitleSchema,
|
|
47
85
|
RichTextSchema,
|
|
48
86
|
StatusSchema,
|
|
49
|
-
|
|
87
|
+
MultiSelectSchema,
|
|
88
|
+
NullableDateSchema,
|
|
89
|
+
CheckboxSchema,
|
|
50
90
|
} from "@nakanoaas/notion-valibot-schema";
|
|
51
91
|
|
|
52
|
-
//
|
|
53
|
-
const
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
70
|
-
|
|
116
|
+
// 2. Fetch data from Notion
|
|
117
|
+
const page = await notion.pages.retrieve({ page_id: "..." });
|
|
71
118
|
|
|
72
|
-
//
|
|
73
|
-
const task = v.parse(
|
|
119
|
+
// 3. Parse and transform
|
|
120
|
+
const task = v.parse(TaskPageSchema, page);
|
|
74
121
|
|
|
75
|
-
//
|
|
76
|
-
task.properties.Name;
|
|
77
|
-
task.properties.
|
|
78
|
-
task.properties.Tags;
|
|
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
|
-
###
|
|
128
|
+
### Handling Lists (Query Results)
|
|
129
|
+
|
|
130
|
+
To parse the results of a database query:
|
|
82
131
|
|
|
83
132
|
```ts
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
package/dist/checkbox.cjs.map
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/checkbox.d.cts
CHANGED
|
@@ -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.d.mts
CHANGED
|
@@ -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
|
package/dist/checkbox.mjs.map
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/created-by.cjs
CHANGED
|
@@ -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
|
package/dist/created-by.cjs.map
CHANGED
|
@@ -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":"
|
|
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"}
|
package/dist/created-by.d.cts
CHANGED
|
@@ -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>;
|