@nakanoaas/notion-valibot-schema 0.3.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -14
- package/dist/created-by.cjs +30 -26
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.d.cts +35 -48
- package/dist/created-by.d.mts +35 -48
- package/dist/created-by.mjs +31 -27
- package/dist/created-by.mjs.map +1 -1
- package/dist/{file.cjs → files.cjs} +6 -6
- package/dist/files.cjs.map +1 -0
- package/dist/{file.d.cts → files.d.cts} +6 -6
- package/dist/{file.d.mts → files.d.mts} +6 -6
- package/dist/{file.mjs → files.mjs} +6 -6
- package/dist/files.mjs.map +1 -0
- package/dist/formula.cjs +120 -19
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +150 -41
- package/dist/formula.d.mts +150 -41
- package/dist/formula.mjs +117 -20
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +17 -4
- package/dist/index.d.cts +5 -5
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +5 -5
- package/dist/last-edited-by.cjs +27 -25
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.d.cts +29 -44
- package/dist/last-edited-by.d.mts +29 -44
- package/dist/last-edited-by.mjs +28 -26
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/people.cjs +320 -38
- package/dist/people.cjs.map +1 -1
- package/dist/people.d.cts +331 -53
- package/dist/people.d.mts +331 -53
- package/dist/people.mjs +313 -39
- package/dist/people.mjs.map +1 -1
- package/dist/rollup.cjs +66 -0
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +70 -1
- package/dist/rollup.d.mts +70 -1
- package/dist/rollup.mjs +66 -1
- package/dist/rollup.mjs.map +1 -1
- package/dist/verification.cjs +7 -7
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.d.cts +18 -12
- package/dist/verification.d.mts +18 -12
- package/dist/verification.mjs +8 -8
- package/dist/verification.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/file.cjs.map +0 -1
- package/dist/file.mjs.map +0 -1
package/dist/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
|
package/dist/created-by.mjs
CHANGED
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserOrGroupIdSchema, UserOrGroupSchema } from "./people.mjs";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
//#region src/created-by.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
|
-
const
|
|
38
|
+
const CreatedByIdSchema = v.pipe(v.object({ created_by: UserOrGroupIdSchema }), v.transform((v) => v.created_by.id));
|
|
46
39
|
/**
|
|
47
40
|
* Schema to extract the `created_by` person name from a Notion page.
|
|
48
41
|
*
|
|
@@ -51,7 +44,7 @@ const CreatedBySchema = v.pipe(v.object({ created_by: PersonSchema }), v.transfo
|
|
|
51
44
|
* {
|
|
52
45
|
* created_by: {
|
|
53
46
|
* id: string;
|
|
54
|
-
* object: "user" | "
|
|
47
|
+
* object: "user" | "group";
|
|
55
48
|
* name: string | null;
|
|
56
49
|
* ...
|
|
57
50
|
* }
|
|
@@ -68,51 +61,62 @@ const CreatedBySchema = v.pipe(v.object({ created_by: PersonSchema }), v.transfo
|
|
|
68
61
|
* const PageSchema = v.object({
|
|
69
62
|
* id: v.string(),
|
|
70
63
|
* properties: v.object({
|
|
71
|
-
*
|
|
64
|
+
* "Created By": NullableCreatedByNameSchema,
|
|
72
65
|
* }),
|
|
73
66
|
* });
|
|
74
67
|
*
|
|
75
68
|
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
76
69
|
* const parsed = v.parse(PageSchema, page);
|
|
77
|
-
* // parsed.properties
|
|
70
|
+
* // parsed.properties["Created By"]: string | null
|
|
78
71
|
* ```
|
|
79
72
|
*/
|
|
80
|
-
const NullableCreatedByNameSchema = v.pipe(v.object({ created_by:
|
|
73
|
+
const NullableCreatedByNameSchema = v.pipe(v.object({ created_by: UserOrGroupSchema }), v.transform((v) => v.created_by.name));
|
|
81
74
|
/**
|
|
82
|
-
* Schema to extract the `created_by` person
|
|
75
|
+
* Schema factory to extract the `created_by` person object from a Notion page.
|
|
76
|
+
*
|
|
77
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
78
|
+
* allowing you to combine it with building-block schemas such as
|
|
79
|
+
* `UserOrGroupSchema`, `UserSchema`, or `PersonSchema`.
|
|
83
80
|
*
|
|
84
81
|
* **Input:**
|
|
85
82
|
* ```
|
|
86
83
|
* {
|
|
87
84
|
* created_by: {
|
|
88
85
|
* id: string;
|
|
89
|
-
* object: "user" | "
|
|
90
|
-
* name
|
|
86
|
+
* object: "user" | "group";
|
|
87
|
+
* name?: string | null;
|
|
91
88
|
* ...
|
|
92
89
|
* }
|
|
93
90
|
* }
|
|
94
91
|
* ```
|
|
95
92
|
*
|
|
96
|
-
* **Output:**
|
|
93
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
94
|
+
*
|
|
95
|
+
* @param schema - A schema that validates the `created_by` user or group object.
|
|
97
96
|
*
|
|
98
97
|
* @example
|
|
99
98
|
* ```ts
|
|
100
99
|
* import * as v from "valibot";
|
|
101
|
-
* import {
|
|
100
|
+
* import {
|
|
101
|
+
* CreatedBySchema,
|
|
102
|
+
* UserOrGroupSchema,
|
|
103
|
+
* } from "@nakanoaas/notion-valibot-schema";
|
|
102
104
|
*
|
|
103
105
|
* const PageSchema = v.object({
|
|
104
106
|
* id: v.string(),
|
|
105
107
|
* properties: v.object({
|
|
106
|
-
*
|
|
108
|
+
* "Created By": CreatedBySchema(UserOrGroupSchema),
|
|
107
109
|
* }),
|
|
108
110
|
* });
|
|
109
111
|
*
|
|
110
112
|
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
111
113
|
* const parsed = v.parse(PageSchema, page);
|
|
112
|
-
* // parsed.properties
|
|
114
|
+
* // parsed.properties["Created By"]: { id: string; object: "user" | "group"; name: string | null }
|
|
113
115
|
* ```
|
|
114
116
|
*/
|
|
115
|
-
|
|
117
|
+
function CreatedBySchema(schema) {
|
|
118
|
+
return v.pipe(v.object({ created_by: schema }), v.transform((v) => v.created_by));
|
|
119
|
+
}
|
|
116
120
|
//#endregion
|
|
117
121
|
export { CreatedByIdSchema, CreatedBySchema, NullableCreatedByNameSchema };
|
|
118
122
|
|
package/dist/created-by.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"created-by.mjs","names":[],"sources":["../src/created-by.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"created-by.mjs","names":[],"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,oBAAoB,EAAE,KAClC,EAAE,OAAO,EACR,YAAY,oBACb,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,WAAW,EAAE,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,8BAA8B,EAAE,KAC5C,EAAE,OAAO,EACR,YAAY,kBACb,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,WAAW,IAAI,CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,gBAGf,QACqE;CACrE,OAAO,EAAE,KACR,EAAE,OAAO,EACR,YAAY,OACb,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,UAAU,CAChC;AACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let valibot = require("valibot");
|
|
3
3
|
valibot = require_runtime.__toESM(valibot, 1);
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/files.ts
|
|
5
5
|
/**
|
|
6
6
|
* Schema for a Notion file object structure.
|
|
7
7
|
*
|
|
@@ -54,12 +54,12 @@ const InnerFileSchema = valibot.variant("type", [valibot.object({
|
|
|
54
54
|
* @example
|
|
55
55
|
* ```ts
|
|
56
56
|
* import * as v from "valibot";
|
|
57
|
-
* import {
|
|
57
|
+
* import { FileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
58
58
|
*
|
|
59
59
|
* const PageSchema = v.object({
|
|
60
60
|
* id: v.string(),
|
|
61
61
|
* properties: v.object({
|
|
62
|
-
* Files:
|
|
62
|
+
* Files: FileSchema,
|
|
63
63
|
* }),
|
|
64
64
|
* });
|
|
65
65
|
*
|
|
@@ -68,7 +68,7 @@ const InnerFileSchema = valibot.variant("type", [valibot.object({
|
|
|
68
68
|
* // parsed.properties.Files: string[]
|
|
69
69
|
* ```
|
|
70
70
|
*/
|
|
71
|
-
const
|
|
71
|
+
const FileSchema = valibot.pipe(valibot.object({ files: valibot.array(InnerFileSchema) }), valibot.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
|
|
72
72
|
/**
|
|
73
73
|
* Schema to extract the `files` property from a Notion page property and transform it to a single URL.
|
|
74
74
|
*
|
|
@@ -157,8 +157,8 @@ const NullableSingleFileSchema = valibot.pipe(valibot.object({ files: valibot.ar
|
|
|
157
157
|
return file.type === "file" ? file.file.url : file.external.url;
|
|
158
158
|
}));
|
|
159
159
|
//#endregion
|
|
160
|
-
exports.
|
|
160
|
+
exports.FileSchema = FileSchema;
|
|
161
161
|
exports.NullableSingleFileSchema = NullableSingleFileSchema;
|
|
162
162
|
exports.SingleFileSchema = SingleFileSchema;
|
|
163
163
|
|
|
164
|
-
//# sourceMappingURL=
|
|
164
|
+
//# sourceMappingURL=files.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.cjs","names":["v"],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkBA,QAAE,QAAQ,QAAQ,CACzCA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,OAAO,EACd,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,GACDA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,UAAU;CAC1B,UAAUA,QAAE,OAAO,EAClB,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,aAAaA,QAAE,KAC3BA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/files.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
6
6
|
*
|
|
@@ -26,12 +26,12 @@ import * as v from "valibot";
|
|
|
26
26
|
* @example
|
|
27
27
|
* ```ts
|
|
28
28
|
* import * as v from "valibot";
|
|
29
|
-
* import {
|
|
29
|
+
* import { FileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
30
|
*
|
|
31
31
|
* const PageSchema = v.object({
|
|
32
32
|
* id: v.string(),
|
|
33
33
|
* properties: v.object({
|
|
34
|
-
* Files:
|
|
34
|
+
* Files: FileSchema,
|
|
35
35
|
* }),
|
|
36
36
|
* });
|
|
37
37
|
*
|
|
@@ -40,7 +40,7 @@ import * as v from "valibot";
|
|
|
40
40
|
* // parsed.properties.Files: string[]
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
declare const
|
|
43
|
+
declare const FileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
44
44
|
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
45
45
|
readonly type: v.LiteralSchema<"file", undefined>;
|
|
46
46
|
readonly file: v.ObjectSchema<{
|
|
@@ -194,5 +194,5 @@ declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchem
|
|
|
194
194
|
})[];
|
|
195
195
|
}, string | null>]>;
|
|
196
196
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=
|
|
197
|
+
export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
|
|
198
|
+
//# sourceMappingURL=files.d.cts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/files.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
6
6
|
*
|
|
@@ -26,12 +26,12 @@ import * as v from "valibot";
|
|
|
26
26
|
* @example
|
|
27
27
|
* ```ts
|
|
28
28
|
* import * as v from "valibot";
|
|
29
|
-
* import {
|
|
29
|
+
* import { FileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
30
|
*
|
|
31
31
|
* const PageSchema = v.object({
|
|
32
32
|
* id: v.string(),
|
|
33
33
|
* properties: v.object({
|
|
34
|
-
* Files:
|
|
34
|
+
* Files: FileSchema,
|
|
35
35
|
* }),
|
|
36
36
|
* });
|
|
37
37
|
*
|
|
@@ -40,7 +40,7 @@ import * as v from "valibot";
|
|
|
40
40
|
* // parsed.properties.Files: string[]
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
declare const
|
|
43
|
+
declare const FileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
44
44
|
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
45
45
|
readonly type: v.LiteralSchema<"file", undefined>;
|
|
46
46
|
readonly file: v.ObjectSchema<{
|
|
@@ -194,5 +194,5 @@ declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchem
|
|
|
194
194
|
})[];
|
|
195
195
|
}, string | null>]>;
|
|
196
196
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=
|
|
197
|
+
export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
|
|
198
|
+
//# sourceMappingURL=files.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
//#region src/
|
|
2
|
+
//#region src/files.ts
|
|
3
3
|
/**
|
|
4
4
|
* Schema for a Notion file object structure.
|
|
5
5
|
*
|
|
@@ -52,12 +52,12 @@ const InnerFileSchema = v.variant("type", [v.object({
|
|
|
52
52
|
* @example
|
|
53
53
|
* ```ts
|
|
54
54
|
* import * as v from "valibot";
|
|
55
|
-
* import {
|
|
55
|
+
* import { FileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
56
56
|
*
|
|
57
57
|
* const PageSchema = v.object({
|
|
58
58
|
* id: v.string(),
|
|
59
59
|
* properties: v.object({
|
|
60
|
-
* Files:
|
|
60
|
+
* Files: FileSchema,
|
|
61
61
|
* }),
|
|
62
62
|
* });
|
|
63
63
|
*
|
|
@@ -66,7 +66,7 @@ const InnerFileSchema = v.variant("type", [v.object({
|
|
|
66
66
|
* // parsed.properties.Files: string[]
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
const
|
|
69
|
+
const FileSchema = v.pipe(v.object({ files: v.array(InnerFileSchema) }), v.transform((v) => v.files.map((v) => v.type === "file" ? v.file.url : v.external.url)));
|
|
70
70
|
/**
|
|
71
71
|
* Schema to extract the `files` property from a Notion page property and transform it to a single URL.
|
|
72
72
|
*
|
|
@@ -155,6 +155,6 @@ const NullableSingleFileSchema = v.pipe(v.object({ files: v.array(InnerFileSchem
|
|
|
155
155
|
return file.type === "file" ? file.file.url : file.external.url;
|
|
156
156
|
}));
|
|
157
157
|
//#endregion
|
|
158
|
-
export {
|
|
158
|
+
export { FileSchema, NullableSingleFileSchema, SingleFileSchema };
|
|
159
159
|
|
|
160
|
-
//# sourceMappingURL=
|
|
160
|
+
//# sourceMappingURL=files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.mjs","names":[],"sources":["../src/files.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB,EAAE,QAAQ,QAAQ,CACzC,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,OAAO,EACd,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,GACD,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU,EAAE,OAAO,EAClB,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,aAAa,EAAE,KAC3B,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}
|