@nakanoaas/notion-valibot-schema 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -4
- package/dist/created-by.cjs +30 -26
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.d.cts +35 -48
- package/dist/created-by.d.mts +35 -48
- package/dist/created-by.mjs +31 -27
- package/dist/created-by.mjs.map +1 -1
- package/dist/index.cjs +8 -4
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/last-edited-by.cjs +27 -25
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.d.cts +29 -44
- package/dist/last-edited-by.d.mts +29 -44
- package/dist/last-edited-by.mjs +28 -26
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/people.cjs +320 -38
- package/dist/people.cjs.map +1 -1
- package/dist/people.d.cts +331 -53
- package/dist/people.d.mts +331 -53
- package/dist/people.mjs +313 -39
- package/dist/people.mjs.map +1 -1
- package/dist/rollup.cjs +0 -165
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +1 -205
- package/dist/rollup.d.mts +1 -205
- package/dist/rollup.mjs +1 -162
- package/dist/rollup.mjs.map +1 -1
- package/dist/verification.cjs +7 -7
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.d.cts +18 -12
- package/dist/verification.d.mts +18 -12
- package/dist/verification.mjs +8 -8
- package/dist/verification.mjs.map +1 -1
- package/package.json +1 -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)
|
|
@@ -163,12 +169,15 @@ const tasks = v.parse(TaskListSchema, results);
|
|
|
163
169
|
| **Phone** | `PhoneNumberSchema` | `string` |
|
|
164
170
|
| **Files** | `FileSchema` | `string[]` (URLs) |
|
|
165
171
|
| **Files** (Single) | `SingleFileSchema` / `NullableSingleFileSchema` | `string` (URL) / `string \| null` |
|
|
166
|
-
| **
|
|
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` |
|
|
167
177
|
| **Created/Edited Time**| `CreatedTimeSchema` / `LastEditedTimeSchema` | `Date` |
|
|
168
|
-
| **People** | `PeopleSchema` / `PeopleIdSchema` | `Array<{ id: string; object: "user" \| "bot" \| "group"; name: string \| null }>` / `string[]` |
|
|
169
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` |
|
|
170
179
|
| **Unique ID** | `UniqueIdNumberSchema` / `NullableUniqueIdSchema` | `number` / `{ prefix: string \| null; number: number \| null }` |
|
|
171
|
-
| **Verification** | `VerificationSchema` / `NullableVerificationSchema` | `{ state: "unverified" \| "verified" \| "expired"; date: DateObject \| null; verified_by:
|
|
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` |
|
|
172
181
|
|
|
173
182
|
### Advanced Schemas
|
|
174
183
|
|
|
@@ -234,6 +243,56 @@ const MySchema = v.object({
|
|
|
234
243
|
});
|
|
235
244
|
```
|
|
236
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
|
+
|
|
237
296
|
## License
|
|
238
297
|
|
|
239
298
|
MIT © [Nakano as a Service](https://github.com/nakanoasaservice)
|
package/dist/created-by.cjs
CHANGED
|
@@ -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
|
|
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" | "
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
37
|
+
* // parsed.properties["Created By"]: string
|
|
45
38
|
* ```
|
|
46
39
|
*/
|
|
47
|
-
const
|
|
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" | "
|
|
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
|
-
*
|
|
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
|
|
72
|
+
* // parsed.properties["Created By"]: string | null
|
|
80
73
|
* ```
|
|
81
74
|
*/
|
|
82
|
-
const NullableCreatedByNameSchema = valibot.pipe(valibot.object({ created_by: require_people.
|
|
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
|
|
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" | "
|
|
92
|
-
* name
|
|
88
|
+
* object: "user" | "group";
|
|
89
|
+
* name?: string | null;
|
|
93
90
|
* ...
|
|
94
91
|
* }
|
|
95
92
|
* }
|
|
96
93
|
* ```
|
|
97
94
|
*
|
|
98
|
-
* **Output:**
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
116
|
+
* // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
|
|
115
117
|
* ```
|
|
116
118
|
*/
|
|
117
|
-
|
|
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;
|
package/dist/created-by.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created-by.cjs","names":["v","
|
|
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"}
|
package/dist/created-by.d.cts
CHANGED
|
@@ -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
|
|
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" | "
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
35
|
+
* // parsed.properties["Created By"]: string
|
|
43
36
|
* ```
|
|
44
37
|
*/
|
|
45
|
-
declare const
|
|
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" | "
|
|
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
|
-
*
|
|
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
|
|
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", "
|
|
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" | "
|
|
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
|
|
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" | "
|
|
118
|
-
* name
|
|
106
|
+
* object: "user" | "group";
|
|
107
|
+
* name?: string | null;
|
|
119
108
|
* ...
|
|
120
109
|
* }
|
|
121
110
|
* }
|
|
122
111
|
* ```
|
|
123
112
|
*
|
|
124
|
-
* **Output:**
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
134
|
+
* // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
|
|
141
135
|
* ```
|
|
142
136
|
*/
|
|
143
|
-
declare
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
package/dist/created-by.d.mts
CHANGED
|
@@ -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
|
|
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" | "
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
35
|
+
* // parsed.properties["Created By"]: string
|
|
43
36
|
* ```
|
|
44
37
|
*/
|
|
45
|
-
declare const
|
|
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" | "
|
|
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
|
-
*
|
|
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
|
|
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", "
|
|
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" | "
|
|
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
|
|
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" | "
|
|
118
|
-
* name
|
|
106
|
+
* object: "user" | "group";
|
|
107
|
+
* name?: string | null;
|
|
119
108
|
* ...
|
|
120
109
|
* }
|
|
121
110
|
* }
|
|
122
111
|
* ```
|
|
123
112
|
*
|
|
124
|
-
* **Output:**
|
|
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 {
|
|
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
|
-
*
|
|
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
|
|
134
|
+
* // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
|
|
141
135
|
* ```
|
|
142
136
|
*/
|
|
143
|
-
declare
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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.mts.map
|