@nakanoaas/notion-valibot-schema 0.2.1 → 0.3.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 +2 -1
- package/dist/_virtual/_rolldown/runtime.cjs +7 -13
- package/dist/checkbox.cjs +3 -4
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.mjs +1 -2
- package/dist/checkbox.mjs.map +1 -1
- package/dist/created-by.cjs +4 -5
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.mjs +1 -2
- package/dist/created-by.mjs.map +1 -1
- package/dist/created-time.cjs +3 -4
- package/dist/created-time.cjs.map +1 -1
- package/dist/created-time.mjs +1 -2
- package/dist/created-time.mjs.map +1 -1
- package/dist/date.cjs +3 -4
- package/dist/date.cjs.map +1 -1
- package/dist/date.mjs +1 -2
- package/dist/date.mjs.map +1 -1
- package/dist/email.cjs +3 -4
- package/dist/email.cjs.map +1 -1
- package/dist/email.mjs +1 -2
- package/dist/email.mjs.map +1 -1
- package/dist/file.cjs +164 -0
- package/dist/file.cjs.map +1 -0
- package/dist/file.d.cts +198 -0
- package/dist/file.d.mts +198 -0
- package/dist/file.mjs +160 -0
- package/dist/file.mjs.map +1 -0
- package/dist/formula.cjs +3 -4
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.mjs +1 -2
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +27 -26
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -3
- package/dist/last-edited-by.cjs +4 -5
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.mjs +1 -2
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/last-edited-time.cjs +3 -4
- package/dist/last-edited-time.cjs.map +1 -1
- package/dist/last-edited-time.mjs +1 -2
- package/dist/last-edited-time.mjs.map +1 -1
- package/dist/multi-select.cjs +3 -4
- package/dist/multi-select.cjs.map +1 -1
- package/dist/multi-select.mjs +1 -2
- package/dist/multi-select.mjs.map +1 -1
- package/dist/number.cjs +4 -8
- package/dist/number.cjs.map +1 -1
- package/dist/number.d.cts +0 -2
- package/dist/number.d.mts +0 -2
- package/dist/number.mjs +2 -6
- package/dist/number.mjs.map +1 -1
- package/dist/people.cjs +3 -4
- package/dist/people.cjs.map +1 -1
- package/dist/people.mjs +1 -2
- package/dist/people.mjs.map +1 -1
- package/dist/phone-number.cjs +3 -4
- package/dist/phone-number.cjs.map +1 -1
- package/dist/phone-number.mjs +1 -2
- package/dist/phone-number.mjs.map +1 -1
- package/dist/place.cjs +3 -4
- package/dist/place.cjs.map +1 -1
- package/dist/place.mjs +1 -2
- package/dist/place.mjs.map +1 -1
- package/dist/relation.cjs +3 -4
- package/dist/relation.cjs.map +1 -1
- package/dist/relation.mjs +1 -2
- package/dist/relation.mjs.map +1 -1
- package/dist/rollup.cjs +5 -6
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.mjs +2 -3
- package/dist/rollup.mjs.map +1 -1
- package/dist/select.cjs +3 -4
- package/dist/select.cjs.map +1 -1
- package/dist/select.mjs +1 -2
- package/dist/select.mjs.map +1 -1
- package/dist/status.cjs +3 -4
- package/dist/status.cjs.map +1 -1
- package/dist/status.mjs +1 -2
- package/dist/status.mjs.map +1 -1
- package/dist/text.cjs +3 -4
- package/dist/text.cjs.map +1 -1
- package/dist/text.mjs +1 -2
- package/dist/text.mjs.map +1 -1
- package/dist/unique-id.cjs +3 -4
- package/dist/unique-id.cjs.map +1 -1
- package/dist/unique-id.mjs +1 -2
- package/dist/unique-id.mjs.map +1 -1
- package/dist/url.cjs +3 -4
- package/dist/url.cjs.map +1 -1
- package/dist/url.mjs +1 -2
- package/dist/url.mjs.map +1 -1
- package/dist/verification.cjs +5 -6
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.mjs +1 -2
- package/dist/verification.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/files.cjs +0 -55
- package/dist/files.cjs.map +0 -1
- package/dist/files.d.cts +0 -70
- package/dist/files.d.mts +0 -70
- package/dist/files.mjs +0 -53
- package/dist/files.mjs.map +0 -1
package/dist/file.d.cts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/file.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
6
|
+
*
|
|
7
|
+
* **Input:**
|
|
8
|
+
* ```
|
|
9
|
+
* {
|
|
10
|
+
* files: Array<{
|
|
11
|
+
* type: "file";
|
|
12
|
+
* file: {
|
|
13
|
+
* url: string;
|
|
14
|
+
* };
|
|
15
|
+
* } | {
|
|
16
|
+
* type: "external";
|
|
17
|
+
* external: {
|
|
18
|
+
* url: string;
|
|
19
|
+
* };
|
|
20
|
+
* }>;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* **Output:** `string[]`
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as v from "valibot";
|
|
29
|
+
* import { FileArraySchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
|
+
*
|
|
31
|
+
* const PageSchema = v.object({
|
|
32
|
+
* id: v.string(),
|
|
33
|
+
* properties: v.object({
|
|
34
|
+
* Files: FileArraySchema,
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
39
|
+
* const parsed = v.parse(PageSchema, page);
|
|
40
|
+
* // parsed.properties.Files: string[]
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare const FileArraySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
44
|
+
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
45
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
46
|
+
readonly file: v.ObjectSchema<{
|
|
47
|
+
readonly url: v.StringSchema<undefined>;
|
|
48
|
+
}, undefined>;
|
|
49
|
+
}, undefined>, v.ObjectSchema<{
|
|
50
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
51
|
+
readonly external: v.ObjectSchema<{
|
|
52
|
+
readonly url: v.StringSchema<undefined>;
|
|
53
|
+
}, undefined>;
|
|
54
|
+
}, undefined>], undefined>, undefined>;
|
|
55
|
+
}, undefined>, v.TransformAction<{
|
|
56
|
+
files: ({
|
|
57
|
+
type: "file";
|
|
58
|
+
file: {
|
|
59
|
+
url: string;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
type: "external";
|
|
63
|
+
external: {
|
|
64
|
+
url: string;
|
|
65
|
+
};
|
|
66
|
+
})[];
|
|
67
|
+
}, string[]>]>;
|
|
68
|
+
/**
|
|
69
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL.
|
|
70
|
+
*
|
|
71
|
+
* **Input:**
|
|
72
|
+
* ```
|
|
73
|
+
* {
|
|
74
|
+
* files: [{
|
|
75
|
+
* type: "file";
|
|
76
|
+
* file: {
|
|
77
|
+
* url: string;
|
|
78
|
+
* };
|
|
79
|
+
* } | {
|
|
80
|
+
* type: "external";
|
|
81
|
+
* external: {
|
|
82
|
+
* url: string;
|
|
83
|
+
* };
|
|
84
|
+
* }];
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* **Output:** `string`
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import * as v from "valibot";
|
|
93
|
+
* import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
94
|
+
*
|
|
95
|
+
* const PageSchema = v.object({
|
|
96
|
+
* id: v.string(),
|
|
97
|
+
* properties: v.object({
|
|
98
|
+
* Attachment: SingleFileSchema,
|
|
99
|
+
* }),
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
103
|
+
* const parsed = v.parse(PageSchema, page);
|
|
104
|
+
* // parsed.properties.Attachment: string
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const SingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
108
|
+
readonly files: v.TupleSchema<[v.VariantSchema<"type", [v.ObjectSchema<{
|
|
109
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
110
|
+
readonly file: v.ObjectSchema<{
|
|
111
|
+
readonly url: v.StringSchema<undefined>;
|
|
112
|
+
}, undefined>;
|
|
113
|
+
}, undefined>, v.ObjectSchema<{
|
|
114
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
115
|
+
readonly external: v.ObjectSchema<{
|
|
116
|
+
readonly url: v.StringSchema<undefined>;
|
|
117
|
+
}, undefined>;
|
|
118
|
+
}, undefined>], undefined>], undefined>;
|
|
119
|
+
}, undefined>, v.TransformAction<{
|
|
120
|
+
files: [{
|
|
121
|
+
type: "file";
|
|
122
|
+
file: {
|
|
123
|
+
url: string;
|
|
124
|
+
};
|
|
125
|
+
} | {
|
|
126
|
+
type: "external";
|
|
127
|
+
external: {
|
|
128
|
+
url: string;
|
|
129
|
+
};
|
|
130
|
+
}];
|
|
131
|
+
}, string>]>;
|
|
132
|
+
/**
|
|
133
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
|
|
134
|
+
*
|
|
135
|
+
* **Input:**
|
|
136
|
+
* ```
|
|
137
|
+
* {
|
|
138
|
+
* files: Array<{
|
|
139
|
+
* type: "file";
|
|
140
|
+
* file: {
|
|
141
|
+
* url: string;
|
|
142
|
+
* };
|
|
143
|
+
* } | {
|
|
144
|
+
* type: "external";
|
|
145
|
+
* external: {
|
|
146
|
+
* url: string;
|
|
147
|
+
* };
|
|
148
|
+
* }>;
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* **Output:** `string | null`
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import * as v from "valibot";
|
|
157
|
+
* import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
158
|
+
*
|
|
159
|
+
* const PageSchema = v.object({
|
|
160
|
+
* id: v.string(),
|
|
161
|
+
* properties: v.object({
|
|
162
|
+
* Attachment: NullableSingleFileSchema,
|
|
163
|
+
* }),
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
167
|
+
* const parsed = v.parse(PageSchema, page);
|
|
168
|
+
* // parsed.properties.Attachment: string | null
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
172
|
+
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
173
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
174
|
+
readonly file: v.ObjectSchema<{
|
|
175
|
+
readonly url: v.StringSchema<undefined>;
|
|
176
|
+
}, undefined>;
|
|
177
|
+
}, undefined>, v.ObjectSchema<{
|
|
178
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
179
|
+
readonly external: v.ObjectSchema<{
|
|
180
|
+
readonly url: v.StringSchema<undefined>;
|
|
181
|
+
}, undefined>;
|
|
182
|
+
}, undefined>], undefined>, undefined>;
|
|
183
|
+
}, undefined>, v.TransformAction<{
|
|
184
|
+
files: ({
|
|
185
|
+
type: "file";
|
|
186
|
+
file: {
|
|
187
|
+
url: string;
|
|
188
|
+
};
|
|
189
|
+
} | {
|
|
190
|
+
type: "external";
|
|
191
|
+
external: {
|
|
192
|
+
url: string;
|
|
193
|
+
};
|
|
194
|
+
})[];
|
|
195
|
+
}, string | null>]>;
|
|
196
|
+
//#endregion
|
|
197
|
+
export { FileArraySchema, NullableSingleFileSchema, SingleFileSchema };
|
|
198
|
+
//# sourceMappingURL=file.d.cts.map
|
package/dist/file.d.mts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/file.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
6
|
+
*
|
|
7
|
+
* **Input:**
|
|
8
|
+
* ```
|
|
9
|
+
* {
|
|
10
|
+
* files: Array<{
|
|
11
|
+
* type: "file";
|
|
12
|
+
* file: {
|
|
13
|
+
* url: string;
|
|
14
|
+
* };
|
|
15
|
+
* } | {
|
|
16
|
+
* type: "external";
|
|
17
|
+
* external: {
|
|
18
|
+
* url: string;
|
|
19
|
+
* };
|
|
20
|
+
* }>;
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* **Output:** `string[]`
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as v from "valibot";
|
|
29
|
+
* import { FileArraySchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
|
+
*
|
|
31
|
+
* const PageSchema = v.object({
|
|
32
|
+
* id: v.string(),
|
|
33
|
+
* properties: v.object({
|
|
34
|
+
* Files: FileArraySchema,
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
39
|
+
* const parsed = v.parse(PageSchema, page);
|
|
40
|
+
* // parsed.properties.Files: string[]
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare const FileArraySchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
44
|
+
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
45
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
46
|
+
readonly file: v.ObjectSchema<{
|
|
47
|
+
readonly url: v.StringSchema<undefined>;
|
|
48
|
+
}, undefined>;
|
|
49
|
+
}, undefined>, v.ObjectSchema<{
|
|
50
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
51
|
+
readonly external: v.ObjectSchema<{
|
|
52
|
+
readonly url: v.StringSchema<undefined>;
|
|
53
|
+
}, undefined>;
|
|
54
|
+
}, undefined>], undefined>, undefined>;
|
|
55
|
+
}, undefined>, v.TransformAction<{
|
|
56
|
+
files: ({
|
|
57
|
+
type: "file";
|
|
58
|
+
file: {
|
|
59
|
+
url: string;
|
|
60
|
+
};
|
|
61
|
+
} | {
|
|
62
|
+
type: "external";
|
|
63
|
+
external: {
|
|
64
|
+
url: string;
|
|
65
|
+
};
|
|
66
|
+
})[];
|
|
67
|
+
}, string[]>]>;
|
|
68
|
+
/**
|
|
69
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL.
|
|
70
|
+
*
|
|
71
|
+
* **Input:**
|
|
72
|
+
* ```
|
|
73
|
+
* {
|
|
74
|
+
* files: [{
|
|
75
|
+
* type: "file";
|
|
76
|
+
* file: {
|
|
77
|
+
* url: string;
|
|
78
|
+
* };
|
|
79
|
+
* } | {
|
|
80
|
+
* type: "external";
|
|
81
|
+
* external: {
|
|
82
|
+
* url: string;
|
|
83
|
+
* };
|
|
84
|
+
* }];
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* **Output:** `string`
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import * as v from "valibot";
|
|
93
|
+
* import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
94
|
+
*
|
|
95
|
+
* const PageSchema = v.object({
|
|
96
|
+
* id: v.string(),
|
|
97
|
+
* properties: v.object({
|
|
98
|
+
* Attachment: SingleFileSchema,
|
|
99
|
+
* }),
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
103
|
+
* const parsed = v.parse(PageSchema, page);
|
|
104
|
+
* // parsed.properties.Attachment: string
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const SingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
108
|
+
readonly files: v.TupleSchema<[v.VariantSchema<"type", [v.ObjectSchema<{
|
|
109
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
110
|
+
readonly file: v.ObjectSchema<{
|
|
111
|
+
readonly url: v.StringSchema<undefined>;
|
|
112
|
+
}, undefined>;
|
|
113
|
+
}, undefined>, v.ObjectSchema<{
|
|
114
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
115
|
+
readonly external: v.ObjectSchema<{
|
|
116
|
+
readonly url: v.StringSchema<undefined>;
|
|
117
|
+
}, undefined>;
|
|
118
|
+
}, undefined>], undefined>], undefined>;
|
|
119
|
+
}, undefined>, v.TransformAction<{
|
|
120
|
+
files: [{
|
|
121
|
+
type: "file";
|
|
122
|
+
file: {
|
|
123
|
+
url: string;
|
|
124
|
+
};
|
|
125
|
+
} | {
|
|
126
|
+
type: "external";
|
|
127
|
+
external: {
|
|
128
|
+
url: string;
|
|
129
|
+
};
|
|
130
|
+
}];
|
|
131
|
+
}, string>]>;
|
|
132
|
+
/**
|
|
133
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
|
|
134
|
+
*
|
|
135
|
+
* **Input:**
|
|
136
|
+
* ```
|
|
137
|
+
* {
|
|
138
|
+
* files: Array<{
|
|
139
|
+
* type: "file";
|
|
140
|
+
* file: {
|
|
141
|
+
* url: string;
|
|
142
|
+
* };
|
|
143
|
+
* } | {
|
|
144
|
+
* type: "external";
|
|
145
|
+
* external: {
|
|
146
|
+
* url: string;
|
|
147
|
+
* };
|
|
148
|
+
* }>;
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* **Output:** `string | null`
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import * as v from "valibot";
|
|
157
|
+
* import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
158
|
+
*
|
|
159
|
+
* const PageSchema = v.object({
|
|
160
|
+
* id: v.string(),
|
|
161
|
+
* properties: v.object({
|
|
162
|
+
* Attachment: NullableSingleFileSchema,
|
|
163
|
+
* }),
|
|
164
|
+
* });
|
|
165
|
+
*
|
|
166
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
167
|
+
* const parsed = v.parse(PageSchema, page);
|
|
168
|
+
* // parsed.properties.Attachment: string | null
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare const NullableSingleFileSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
172
|
+
readonly files: v.ArraySchema<v.VariantSchema<"type", [v.ObjectSchema<{
|
|
173
|
+
readonly type: v.LiteralSchema<"file", undefined>;
|
|
174
|
+
readonly file: v.ObjectSchema<{
|
|
175
|
+
readonly url: v.StringSchema<undefined>;
|
|
176
|
+
}, undefined>;
|
|
177
|
+
}, undefined>, v.ObjectSchema<{
|
|
178
|
+
readonly type: v.LiteralSchema<"external", undefined>;
|
|
179
|
+
readonly external: v.ObjectSchema<{
|
|
180
|
+
readonly url: v.StringSchema<undefined>;
|
|
181
|
+
}, undefined>;
|
|
182
|
+
}, undefined>], undefined>, undefined>;
|
|
183
|
+
}, undefined>, v.TransformAction<{
|
|
184
|
+
files: ({
|
|
185
|
+
type: "file";
|
|
186
|
+
file: {
|
|
187
|
+
url: string;
|
|
188
|
+
};
|
|
189
|
+
} | {
|
|
190
|
+
type: "external";
|
|
191
|
+
external: {
|
|
192
|
+
url: string;
|
|
193
|
+
};
|
|
194
|
+
})[];
|
|
195
|
+
}, string | null>]>;
|
|
196
|
+
//#endregion
|
|
197
|
+
export { FileArraySchema, NullableSingleFileSchema, SingleFileSchema };
|
|
198
|
+
//# sourceMappingURL=file.d.mts.map
|
package/dist/file.mjs
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/file.ts
|
|
3
|
+
/**
|
|
4
|
+
* Schema for a Notion file object structure.
|
|
5
|
+
*
|
|
6
|
+
* **Input:**
|
|
7
|
+
* ```
|
|
8
|
+
* {
|
|
9
|
+
* type: "file";
|
|
10
|
+
* file: {
|
|
11
|
+
* url: string;
|
|
12
|
+
* };
|
|
13
|
+
* } | {
|
|
14
|
+
* type: "external";
|
|
15
|
+
* external: {
|
|
16
|
+
* url: string;
|
|
17
|
+
* };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
const InnerFileSchema = v.variant("type", [v.object({
|
|
24
|
+
type: v.literal("file"),
|
|
25
|
+
file: v.object({ url: v.string() })
|
|
26
|
+
}), v.object({
|
|
27
|
+
type: v.literal("external"),
|
|
28
|
+
external: v.object({ url: v.string() })
|
|
29
|
+
})]);
|
|
30
|
+
/**
|
|
31
|
+
* Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.
|
|
32
|
+
*
|
|
33
|
+
* **Input:**
|
|
34
|
+
* ```
|
|
35
|
+
* {
|
|
36
|
+
* files: Array<{
|
|
37
|
+
* type: "file";
|
|
38
|
+
* file: {
|
|
39
|
+
* url: string;
|
|
40
|
+
* };
|
|
41
|
+
* } | {
|
|
42
|
+
* type: "external";
|
|
43
|
+
* external: {
|
|
44
|
+
* url: string;
|
|
45
|
+
* };
|
|
46
|
+
* }>;
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* **Output:** `string[]`
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import * as v from "valibot";
|
|
55
|
+
* import { FileArraySchema } from "@nakanoaas/notion-valibot-utils";
|
|
56
|
+
*
|
|
57
|
+
* const PageSchema = v.object({
|
|
58
|
+
* id: v.string(),
|
|
59
|
+
* properties: v.object({
|
|
60
|
+
* Files: FileArraySchema,
|
|
61
|
+
* }),
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
65
|
+
* const parsed = v.parse(PageSchema, page);
|
|
66
|
+
* // parsed.properties.Files: string[]
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
const FileArraySchema = 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
|
+
/**
|
|
71
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL.
|
|
72
|
+
*
|
|
73
|
+
* **Input:**
|
|
74
|
+
* ```
|
|
75
|
+
* {
|
|
76
|
+
* files: [{
|
|
77
|
+
* type: "file";
|
|
78
|
+
* file: {
|
|
79
|
+
* url: string;
|
|
80
|
+
* };
|
|
81
|
+
* } | {
|
|
82
|
+
* type: "external";
|
|
83
|
+
* external: {
|
|
84
|
+
* url: string;
|
|
85
|
+
* };
|
|
86
|
+
* }];
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* **Output:** `string`
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import * as v from "valibot";
|
|
95
|
+
* import { SingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
96
|
+
*
|
|
97
|
+
* const PageSchema = v.object({
|
|
98
|
+
* id: v.string(),
|
|
99
|
+
* properties: v.object({
|
|
100
|
+
* Attachment: SingleFileSchema,
|
|
101
|
+
* }),
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
105
|
+
* const parsed = v.parse(PageSchema, page);
|
|
106
|
+
* // parsed.properties.Attachment: string
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
const SingleFileSchema = v.pipe(v.object({ files: v.tuple([InnerFileSchema]) }), v.transform((v) => {
|
|
110
|
+
const file = v.files[0];
|
|
111
|
+
return file.type === "file" ? file.file.url : file.external.url;
|
|
112
|
+
}));
|
|
113
|
+
/**
|
|
114
|
+
* Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.
|
|
115
|
+
*
|
|
116
|
+
* **Input:**
|
|
117
|
+
* ```
|
|
118
|
+
* {
|
|
119
|
+
* files: Array<{
|
|
120
|
+
* type: "file";
|
|
121
|
+
* file: {
|
|
122
|
+
* url: string;
|
|
123
|
+
* };
|
|
124
|
+
* } | {
|
|
125
|
+
* type: "external";
|
|
126
|
+
* external: {
|
|
127
|
+
* url: string;
|
|
128
|
+
* };
|
|
129
|
+
* }>;
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* **Output:** `string | null`
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import * as v from "valibot";
|
|
138
|
+
* import { NullableSingleFileSchema } from "@nakanoaas/notion-valibot-utils";
|
|
139
|
+
*
|
|
140
|
+
* const PageSchema = v.object({
|
|
141
|
+
* id: v.string(),
|
|
142
|
+
* properties: v.object({
|
|
143
|
+
* Attachment: NullableSingleFileSchema,
|
|
144
|
+
* }),
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
148
|
+
* const parsed = v.parse(PageSchema, page);
|
|
149
|
+
* // parsed.properties.Attachment: string | null
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
const NullableSingleFileSchema = v.pipe(v.object({ files: v.array(InnerFileSchema) }), v.transform((v) => {
|
|
153
|
+
const file = v.files[0];
|
|
154
|
+
if (!file) return null;
|
|
155
|
+
return file.type === "file" ? file.file.url : file.external.url;
|
|
156
|
+
}));
|
|
157
|
+
//#endregion
|
|
158
|
+
export { FileArraySchema, NullableSingleFileSchema, SingleFileSchema };
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.mjs","names":[],"sources":["../src/file.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 { FileArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileArraySchema,\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 FileArraySchema = 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,kBAAkB,EAAE,KAChC,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"}
|
package/dist/formula.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let valibot = require("valibot");
|
|
3
|
-
valibot = require_runtime.__toESM(valibot);
|
|
4
|
-
|
|
3
|
+
valibot = require_runtime.__toESM(valibot, 1);
|
|
5
4
|
//#region src/formula.ts
|
|
6
5
|
/**
|
|
7
6
|
* Schema factory to extract the `formula` property result from a Notion page property.
|
|
@@ -78,7 +77,7 @@ valibot = require_runtime.__toESM(valibot);
|
|
|
78
77
|
function FormulaSchema(schema) {
|
|
79
78
|
return valibot.pipe(valibot.object({ formula: schema }), valibot.transform((v) => v.formula));
|
|
80
79
|
}
|
|
81
|
-
|
|
82
80
|
//#endregion
|
|
83
81
|
exports.FormulaSchema = FormulaSchema;
|
|
82
|
+
|
|
84
83
|
//# sourceMappingURL=formula.cjs.map
|
package/dist/formula.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,cAed,QAAW;CACZ,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,SAAS,OACV,CAAC,GAEDA,QAAE,WAAW,MAAM,EAAE,OAAQ,CAC9B;AACD"}
|
package/dist/formula.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
-
|
|
3
2
|
//#region src/formula.ts
|
|
4
3
|
/**
|
|
5
4
|
* Schema factory to extract the `formula` property result from a Notion page property.
|
|
@@ -76,7 +75,7 @@ import * as v from "valibot";
|
|
|
76
75
|
function FormulaSchema(schema) {
|
|
77
76
|
return v.pipe(v.object({ formula: schema }), v.transform((v) => v.formula));
|
|
78
77
|
}
|
|
79
|
-
|
|
80
78
|
//#endregion
|
|
81
79
|
export { FormulaSchema };
|
|
80
|
+
|
|
82
81
|
//# sourceMappingURL=formula.mjs.map
|
package/dist/formula.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula.mjs","names":[],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"formula.mjs","names":[],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,cAed,QAAW;CACZ,OAAO,EAAE,KACR,EAAE,OAAO,EACR,SAAS,OACV,CAAC,GAED,EAAE,WAAW,MAAM,EAAE,OAAQ,CAC9B;AACD"}
|