@nakanoaas/notion-valibot-schema 0.7.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/dist/index.cjs +0 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- 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/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,8 +46,6 @@ exports.NullablePhoneNumberSchema = require_phone_number.NullablePhoneNumberSche
|
|
|
46
46
|
exports.NullablePlaceSchema = require_place.NullablePlaceSchema;
|
|
47
47
|
exports.NullableRangeDateSchema = require_date.NullableRangeDateSchema;
|
|
48
48
|
exports.NullableRichTextSchema = require_text.NullableRichTextSchema;
|
|
49
|
-
exports.NullableRollupDateSchema = require_rollup.NullableRollupDateSchema;
|
|
50
|
-
exports.NullableRollupNumberSchema = require_rollup.NullableRollupNumberSchema;
|
|
51
49
|
exports.NullableSelectSchema = require_select.NullableSelectSchema;
|
|
52
50
|
exports.NullableSingleDateSchema = require_date.NullableSingleDateSchema;
|
|
53
51
|
exports.NullableSingleFileSchema = require_files.NullableSingleFileSchema;
|
|
@@ -71,8 +69,6 @@ exports.RangeDateSchema = require_date.RangeDateSchema;
|
|
|
71
69
|
exports.RelationSchema = require_relation.RelationSchema;
|
|
72
70
|
exports.RichTextSchema = require_text.RichTextSchema;
|
|
73
71
|
exports.RollupArraySchema = require_rollup.RollupArraySchema;
|
|
74
|
-
exports.RollupDateSchema = require_rollup.RollupDateSchema;
|
|
75
|
-
exports.RollupNumberSchema = require_rollup.RollupNumberSchema;
|
|
76
72
|
exports.RollupSimpleSchema = require_rollup.RollupSimpleSchema;
|
|
77
73
|
exports.SelectSchema = require_select.SelectSchema;
|
|
78
74
|
exports.SingleDateSchema = require_date.SingleDateSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -13,11 +13,11 @@ import { BotSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, Pe
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.cjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.cjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.cjs";
|
|
16
|
-
import {
|
|
16
|
+
import { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.cjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.cjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.cjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.cjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.cjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.cjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.cjs";
|
|
23
|
-
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema,
|
|
23
|
+
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SinglePeopleIdSchema, SinglePeopleSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, UserOrGroupIdSchema, UserOrGroupSchema, UserSchema, VerificationSchema };
|
package/dist/index.d.mts
CHANGED
|
@@ -13,11 +13,11 @@ import { BotSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, Pe
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.mjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.mjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.mjs";
|
|
16
|
-
import {
|
|
16
|
+
import { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.mjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.mjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.mjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.mjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.mjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.mjs";
|
|
23
|
-
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema,
|
|
23
|
+
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SinglePeopleIdSchema, SinglePeopleSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, UserOrGroupIdSchema, UserOrGroupSchema, UserSchema, VerificationSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -13,11 +13,11 @@ import { NullableNumberSchema, NumberSchema } from "./number.mjs";
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.mjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.mjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.mjs";
|
|
16
|
-
import {
|
|
16
|
+
import { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.mjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.mjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.mjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.mjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.mjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.mjs";
|
|
23
|
-
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema,
|
|
23
|
+
export { BooleanFormulaSchema, BotSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSinglePeopleIdSchema, NullableSinglePeopleSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SinglePeopleIdSchema, SinglePeopleSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, UserOrGroupIdSchema, UserOrGroupSchema, UserSchema, VerificationSchema };
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_date = require("./date.cjs");
|
|
3
2
|
let valibot = require("valibot");
|
|
4
3
|
valibot = require_runtime.__toESM(valibot, 1);
|
|
5
4
|
//#region src/rollup.ts
|
|
@@ -61,166 +60,6 @@ function RollupSimpleSchema(schema) {
|
|
|
61
60
|
return valibot.pipe(valibot.object({ rollup: schema }), valibot.transform((v) => v.rollup));
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
|
-
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
65
|
-
*
|
|
66
|
-
* **Input:**
|
|
67
|
-
* ```
|
|
68
|
-
* {
|
|
69
|
-
* rollup: {
|
|
70
|
-
* type: "number";
|
|
71
|
-
* number: number | null;
|
|
72
|
-
* };
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* **Output:** `number | null`
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* import * as v from "valibot";
|
|
81
|
-
* import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
82
|
-
*
|
|
83
|
-
* const PageSchema = v.object({
|
|
84
|
-
* id: v.string(),
|
|
85
|
-
* properties: v.object({
|
|
86
|
-
* Sum: NullableRollupNumberSchema,
|
|
87
|
-
* }),
|
|
88
|
-
* });
|
|
89
|
-
*
|
|
90
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
91
|
-
* const parsed = v.parse(PageSchema, page);
|
|
92
|
-
* // parsed.properties.Sum: number | null
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
96
|
-
*/
|
|
97
|
-
const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
98
|
-
type: valibot.literal("number"),
|
|
99
|
-
number: valibot.nullable(valibot.number())
|
|
100
|
-
}) }), valibot.transform((v) => v.rollup.number));
|
|
101
|
-
/**
|
|
102
|
-
* Schema to extract the `rollup` property with number type from a Notion page property.
|
|
103
|
-
*
|
|
104
|
-
* **Input:**
|
|
105
|
-
* ```
|
|
106
|
-
* {
|
|
107
|
-
* rollup: {
|
|
108
|
-
* type: "number";
|
|
109
|
-
* number: number;
|
|
110
|
-
* };
|
|
111
|
-
* }
|
|
112
|
-
* ```
|
|
113
|
-
*
|
|
114
|
-
* **Output:** `number`
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* import * as v from "valibot";
|
|
119
|
-
* import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
120
|
-
*
|
|
121
|
-
* const PageSchema = v.object({
|
|
122
|
-
* id: v.string(),
|
|
123
|
-
* properties: v.object({
|
|
124
|
-
* Sum: RollupNumberSchema,
|
|
125
|
-
* }),
|
|
126
|
-
* });
|
|
127
|
-
*
|
|
128
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
129
|
-
* const parsed = v.parse(PageSchema, page);
|
|
130
|
-
* // parsed.properties.Sum: number
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
134
|
-
*/
|
|
135
|
-
const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
136
|
-
type: valibot.literal("number"),
|
|
137
|
-
number: valibot.number()
|
|
138
|
-
}) }), valibot.transform((v) => v.rollup.number));
|
|
139
|
-
/**
|
|
140
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
|
|
141
|
-
*
|
|
142
|
-
* **Input:**
|
|
143
|
-
* ```
|
|
144
|
-
* {
|
|
145
|
-
* rollup: {
|
|
146
|
-
* type: "date";
|
|
147
|
-
* date: {
|
|
148
|
-
* start: string;
|
|
149
|
-
* end: string | null;
|
|
150
|
-
* time_zone: string | null;
|
|
151
|
-
* } | null;
|
|
152
|
-
* };
|
|
153
|
-
* }
|
|
154
|
-
* ```
|
|
155
|
-
*
|
|
156
|
-
* **Output:** `Date | null`
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import * as v from "valibot";
|
|
161
|
-
* import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
162
|
-
*
|
|
163
|
-
* const PageSchema = v.object({
|
|
164
|
-
* id: v.string(),
|
|
165
|
-
* properties: v.object({
|
|
166
|
-
* LatestDate: NullableRollupDateSchema,
|
|
167
|
-
* }),
|
|
168
|
-
* });
|
|
169
|
-
*
|
|
170
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
171
|
-
* const parsed = v.parse(PageSchema, page);
|
|
172
|
-
* // parsed.properties.LatestDate: Date | null
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
176
|
-
*/
|
|
177
|
-
const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
178
|
-
type: valibot.literal("date"),
|
|
179
|
-
date: valibot.nullable(require_date.DateObjectSchema)
|
|
180
|
-
}) }), valibot.transform((v) => v.rollup.date ? new Date(v.rollup.date.start) : null));
|
|
181
|
-
/**
|
|
182
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
|
|
183
|
-
*
|
|
184
|
-
* **Input:**
|
|
185
|
-
* ```
|
|
186
|
-
* {
|
|
187
|
-
* rollup: {
|
|
188
|
-
* type: "date";
|
|
189
|
-
* date: {
|
|
190
|
-
* start: string;
|
|
191
|
-
* end: string | null;
|
|
192
|
-
* time_zone: string | null;
|
|
193
|
-
* };
|
|
194
|
-
* };
|
|
195
|
-
* }
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* **Output:** `Date`
|
|
199
|
-
*
|
|
200
|
-
* @example
|
|
201
|
-
* ```ts
|
|
202
|
-
* import * as v from "valibot";
|
|
203
|
-
* import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
204
|
-
*
|
|
205
|
-
* const PageSchema = v.object({
|
|
206
|
-
* id: v.string(),
|
|
207
|
-
* properties: v.object({
|
|
208
|
-
* LatestDate: RollupDateSchema,
|
|
209
|
-
* }),
|
|
210
|
-
* });
|
|
211
|
-
*
|
|
212
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
213
|
-
* const parsed = v.parse(PageSchema, page);
|
|
214
|
-
* // parsed.properties.LatestDate: Date
|
|
215
|
-
* ```
|
|
216
|
-
*
|
|
217
|
-
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
218
|
-
*/
|
|
219
|
-
const RollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
220
|
-
type: valibot.literal("date"),
|
|
221
|
-
date: require_date.DateObjectSchema
|
|
222
|
-
}) }), valibot.transform((v) => new Date(v.rollup.date.start)));
|
|
223
|
-
/**
|
|
224
63
|
* Schema factory to extract the `rollup` property with array type from a Notion page property.
|
|
225
64
|
*
|
|
226
65
|
* This is a generic schema factory that accepts another schema as a parameter,
|
|
@@ -426,12 +265,8 @@ function NullableSingleRollupArraySchema(schema) {
|
|
|
426
265
|
}) }), valibot.transform((v) => v.rollup.array[0] ?? null));
|
|
427
266
|
}
|
|
428
267
|
//#endregion
|
|
429
|
-
exports.NullableRollupDateSchema = NullableRollupDateSchema;
|
|
430
|
-
exports.NullableRollupNumberSchema = NullableRollupNumberSchema;
|
|
431
268
|
exports.NullableSingleRollupArraySchema = NullableSingleRollupArraySchema;
|
|
432
269
|
exports.RollupArraySchema = RollupArraySchema;
|
|
433
|
-
exports.RollupDateSchema = RollupDateSchema;
|
|
434
|
-
exports.RollupNumberSchema = RollupNumberSchema;
|
|
435
270
|
exports.RollupSimpleSchema = RollupSimpleSchema;
|
|
436
271
|
exports.SingleRollupArraySchema = SingleRollupArraySchema;
|
|
437
272
|
|
package/dist/rollup.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.cjs","names":["v","DateObjectSchema"],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\n/**\n * Schema factory to extract the `rollup` property with a simple (non-array) type 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 the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number | null;\n * };\n * }\n * ```\n *\n * **Output:** `number | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: NullableRollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.\n */\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number;\n * };\n * }\n * ```\n *\n * **Output:** `number`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.\n */\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * };\n * }\n * ```\n *\n * **Output:** `Date | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: NullableRollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.\n */\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * };\n * };\n * }\n * ```\n *\n * **Output:** `Date`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.\n */\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\n/**\n * Schema factory to extract the `rollup` property with array type 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 rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAGf,QAMC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,SAASA,QAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,QAAQ;CACxB,QAAQA,QAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,SAASC,aAAAA,gBAAgB;AAClC,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMC,aAAAA;AACP,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|
|
1
|
+
{"version":3,"file":"rollup.cjs","names":["v"],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `rollup` property with a simple (non-array) type 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 the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\n\n/**\n * Schema factory to extract the `rollup` property with array type 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 rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,mBAGf,QAMC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|
package/dist/rollup.d.cts
CHANGED
|
@@ -62,210 +62,6 @@ declare function RollupSimpleSchema<S extends v.GenericSchema<{
|
|
|
62
62
|
}, unknown>>(schema: S): v.GenericSchema<{
|
|
63
63
|
rollup: v.InferInput<S>;
|
|
64
64
|
}, v.InferOutput<S>>;
|
|
65
|
-
/**
|
|
66
|
-
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
67
|
-
*
|
|
68
|
-
* **Input:**
|
|
69
|
-
* ```
|
|
70
|
-
* {
|
|
71
|
-
* rollup: {
|
|
72
|
-
* type: "number";
|
|
73
|
-
* number: number | null;
|
|
74
|
-
* };
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* **Output:** `number | null`
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* import * as v from "valibot";
|
|
83
|
-
* import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
84
|
-
*
|
|
85
|
-
* const PageSchema = v.object({
|
|
86
|
-
* id: v.string(),
|
|
87
|
-
* properties: v.object({
|
|
88
|
-
* Sum: NullableRollupNumberSchema,
|
|
89
|
-
* }),
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
93
|
-
* const parsed = v.parse(PageSchema, page);
|
|
94
|
-
* // parsed.properties.Sum: number | null
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
98
|
-
*/
|
|
99
|
-
declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
100
|
-
readonly rollup: v.ObjectSchema<{
|
|
101
|
-
readonly type: v.LiteralSchema<"number", undefined>;
|
|
102
|
-
readonly number: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
103
|
-
}, undefined>;
|
|
104
|
-
}, undefined>, v.TransformAction<{
|
|
105
|
-
rollup: {
|
|
106
|
-
type: "number";
|
|
107
|
-
number: number | null;
|
|
108
|
-
};
|
|
109
|
-
}, number | null>]>;
|
|
110
|
-
/**
|
|
111
|
-
* Schema to extract the `rollup` property with number type from a Notion page property.
|
|
112
|
-
*
|
|
113
|
-
* **Input:**
|
|
114
|
-
* ```
|
|
115
|
-
* {
|
|
116
|
-
* rollup: {
|
|
117
|
-
* type: "number";
|
|
118
|
-
* number: number;
|
|
119
|
-
* };
|
|
120
|
-
* }
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
* **Output:** `number`
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* import * as v from "valibot";
|
|
128
|
-
* import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
129
|
-
*
|
|
130
|
-
* const PageSchema = v.object({
|
|
131
|
-
* id: v.string(),
|
|
132
|
-
* properties: v.object({
|
|
133
|
-
* Sum: RollupNumberSchema,
|
|
134
|
-
* }),
|
|
135
|
-
* });
|
|
136
|
-
*
|
|
137
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
138
|
-
* const parsed = v.parse(PageSchema, page);
|
|
139
|
-
* // parsed.properties.Sum: number
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
143
|
-
*/
|
|
144
|
-
declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
145
|
-
readonly rollup: v.ObjectSchema<{
|
|
146
|
-
readonly type: v.LiteralSchema<"number", undefined>;
|
|
147
|
-
readonly number: v.NumberSchema<undefined>;
|
|
148
|
-
}, undefined>;
|
|
149
|
-
}, undefined>, v.TransformAction<{
|
|
150
|
-
rollup: {
|
|
151
|
-
type: "number";
|
|
152
|
-
number: number;
|
|
153
|
-
};
|
|
154
|
-
}, number>]>;
|
|
155
|
-
/**
|
|
156
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
|
|
157
|
-
*
|
|
158
|
-
* **Input:**
|
|
159
|
-
* ```
|
|
160
|
-
* {
|
|
161
|
-
* rollup: {
|
|
162
|
-
* type: "date";
|
|
163
|
-
* date: {
|
|
164
|
-
* start: string;
|
|
165
|
-
* end: string | null;
|
|
166
|
-
* time_zone: string | null;
|
|
167
|
-
* } | null;
|
|
168
|
-
* };
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* **Output:** `Date | null`
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* import * as v from "valibot";
|
|
177
|
-
* import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
178
|
-
*
|
|
179
|
-
* const PageSchema = v.object({
|
|
180
|
-
* id: v.string(),
|
|
181
|
-
* properties: v.object({
|
|
182
|
-
* LatestDate: NullableRollupDateSchema,
|
|
183
|
-
* }),
|
|
184
|
-
* });
|
|
185
|
-
*
|
|
186
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
187
|
-
* const parsed = v.parse(PageSchema, page);
|
|
188
|
-
* // parsed.properties.LatestDate: Date | null
|
|
189
|
-
* ```
|
|
190
|
-
*
|
|
191
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
192
|
-
*/
|
|
193
|
-
declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
194
|
-
readonly rollup: v.ObjectSchema<{
|
|
195
|
-
readonly type: v.LiteralSchema<"date", undefined>;
|
|
196
|
-
readonly date: v.NullableSchema<v.ObjectSchema<{
|
|
197
|
-
readonly start: v.StringSchema<undefined>;
|
|
198
|
-
readonly end: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
199
|
-
readonly time_zone: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
200
|
-
}, undefined>, undefined>;
|
|
201
|
-
}, undefined>;
|
|
202
|
-
}, undefined>, v.TransformAction<{
|
|
203
|
-
rollup: {
|
|
204
|
-
type: "date";
|
|
205
|
-
date: {
|
|
206
|
-
start: string;
|
|
207
|
-
end: string | null;
|
|
208
|
-
time_zone: string | null;
|
|
209
|
-
} | null;
|
|
210
|
-
};
|
|
211
|
-
}, Date | null>]>;
|
|
212
|
-
/**
|
|
213
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
|
|
214
|
-
*
|
|
215
|
-
* **Input:**
|
|
216
|
-
* ```
|
|
217
|
-
* {
|
|
218
|
-
* rollup: {
|
|
219
|
-
* type: "date";
|
|
220
|
-
* date: {
|
|
221
|
-
* start: string;
|
|
222
|
-
* end: string | null;
|
|
223
|
-
* time_zone: string | null;
|
|
224
|
-
* };
|
|
225
|
-
* };
|
|
226
|
-
* }
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* **Output:** `Date`
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```ts
|
|
233
|
-
* import * as v from "valibot";
|
|
234
|
-
* import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
235
|
-
*
|
|
236
|
-
* const PageSchema = v.object({
|
|
237
|
-
* id: v.string(),
|
|
238
|
-
* properties: v.object({
|
|
239
|
-
* LatestDate: RollupDateSchema,
|
|
240
|
-
* }),
|
|
241
|
-
* });
|
|
242
|
-
*
|
|
243
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
244
|
-
* const parsed = v.parse(PageSchema, page);
|
|
245
|
-
* // parsed.properties.LatestDate: Date
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
249
|
-
*/
|
|
250
|
-
declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
251
|
-
readonly rollup: v.ObjectSchema<{
|
|
252
|
-
readonly type: v.LiteralSchema<"date", undefined>;
|
|
253
|
-
readonly date: v.ObjectSchema<{
|
|
254
|
-
readonly start: v.StringSchema<undefined>;
|
|
255
|
-
readonly end: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
256
|
-
readonly time_zone: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
257
|
-
}, undefined>;
|
|
258
|
-
}, undefined>;
|
|
259
|
-
}, undefined>, v.TransformAction<{
|
|
260
|
-
rollup: {
|
|
261
|
-
type: "date";
|
|
262
|
-
date: {
|
|
263
|
-
start: string;
|
|
264
|
-
end: string | null;
|
|
265
|
-
time_zone: string | null;
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
}, Date>]>;
|
|
269
65
|
/**
|
|
270
66
|
* Schema factory to extract the `rollup` property with array type from a Notion page property.
|
|
271
67
|
*
|
|
@@ -477,5 +273,5 @@ declare function NullableSingleRollupArraySchema<S extends v.GenericSchema<objec
|
|
|
477
273
|
};
|
|
478
274
|
}, v.InferOutput<S> | null>;
|
|
479
275
|
//#endregion
|
|
480
|
-
export {
|
|
276
|
+
export { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
481
277
|
//# sourceMappingURL=rollup.d.cts.map
|
package/dist/rollup.d.mts
CHANGED
|
@@ -62,210 +62,6 @@ declare function RollupSimpleSchema<S extends v.GenericSchema<{
|
|
|
62
62
|
}, unknown>>(schema: S): v.GenericSchema<{
|
|
63
63
|
rollup: v.InferInput<S>;
|
|
64
64
|
}, v.InferOutput<S>>;
|
|
65
|
-
/**
|
|
66
|
-
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
67
|
-
*
|
|
68
|
-
* **Input:**
|
|
69
|
-
* ```
|
|
70
|
-
* {
|
|
71
|
-
* rollup: {
|
|
72
|
-
* type: "number";
|
|
73
|
-
* number: number | null;
|
|
74
|
-
* };
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*
|
|
78
|
-
* **Output:** `number | null`
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* import * as v from "valibot";
|
|
83
|
-
* import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
84
|
-
*
|
|
85
|
-
* const PageSchema = v.object({
|
|
86
|
-
* id: v.string(),
|
|
87
|
-
* properties: v.object({
|
|
88
|
-
* Sum: NullableRollupNumberSchema,
|
|
89
|
-
* }),
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
93
|
-
* const parsed = v.parse(PageSchema, page);
|
|
94
|
-
* // parsed.properties.Sum: number | null
|
|
95
|
-
* ```
|
|
96
|
-
*
|
|
97
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
98
|
-
*/
|
|
99
|
-
declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
100
|
-
readonly rollup: v.ObjectSchema<{
|
|
101
|
-
readonly type: v.LiteralSchema<"number", undefined>;
|
|
102
|
-
readonly number: v.NullableSchema<v.NumberSchema<undefined>, undefined>;
|
|
103
|
-
}, undefined>;
|
|
104
|
-
}, undefined>, v.TransformAction<{
|
|
105
|
-
rollup: {
|
|
106
|
-
type: "number";
|
|
107
|
-
number: number | null;
|
|
108
|
-
};
|
|
109
|
-
}, number | null>]>;
|
|
110
|
-
/**
|
|
111
|
-
* Schema to extract the `rollup` property with number type from a Notion page property.
|
|
112
|
-
*
|
|
113
|
-
* **Input:**
|
|
114
|
-
* ```
|
|
115
|
-
* {
|
|
116
|
-
* rollup: {
|
|
117
|
-
* type: "number";
|
|
118
|
-
* number: number;
|
|
119
|
-
* };
|
|
120
|
-
* }
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
|
-
* **Output:** `number`
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* import * as v from "valibot";
|
|
128
|
-
* import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
129
|
-
*
|
|
130
|
-
* const PageSchema = v.object({
|
|
131
|
-
* id: v.string(),
|
|
132
|
-
* properties: v.object({
|
|
133
|
-
* Sum: RollupNumberSchema,
|
|
134
|
-
* }),
|
|
135
|
-
* });
|
|
136
|
-
*
|
|
137
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
138
|
-
* const parsed = v.parse(PageSchema, page);
|
|
139
|
-
* // parsed.properties.Sum: number
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
143
|
-
*/
|
|
144
|
-
declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
145
|
-
readonly rollup: v.ObjectSchema<{
|
|
146
|
-
readonly type: v.LiteralSchema<"number", undefined>;
|
|
147
|
-
readonly number: v.NumberSchema<undefined>;
|
|
148
|
-
}, undefined>;
|
|
149
|
-
}, undefined>, v.TransformAction<{
|
|
150
|
-
rollup: {
|
|
151
|
-
type: "number";
|
|
152
|
-
number: number;
|
|
153
|
-
};
|
|
154
|
-
}, number>]>;
|
|
155
|
-
/**
|
|
156
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
|
|
157
|
-
*
|
|
158
|
-
* **Input:**
|
|
159
|
-
* ```
|
|
160
|
-
* {
|
|
161
|
-
* rollup: {
|
|
162
|
-
* type: "date";
|
|
163
|
-
* date: {
|
|
164
|
-
* start: string;
|
|
165
|
-
* end: string | null;
|
|
166
|
-
* time_zone: string | null;
|
|
167
|
-
* } | null;
|
|
168
|
-
* };
|
|
169
|
-
* }
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
* **Output:** `Date | null`
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* ```ts
|
|
176
|
-
* import * as v from "valibot";
|
|
177
|
-
* import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
178
|
-
*
|
|
179
|
-
* const PageSchema = v.object({
|
|
180
|
-
* id: v.string(),
|
|
181
|
-
* properties: v.object({
|
|
182
|
-
* LatestDate: NullableRollupDateSchema,
|
|
183
|
-
* }),
|
|
184
|
-
* });
|
|
185
|
-
*
|
|
186
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
187
|
-
* const parsed = v.parse(PageSchema, page);
|
|
188
|
-
* // parsed.properties.LatestDate: Date | null
|
|
189
|
-
* ```
|
|
190
|
-
*
|
|
191
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
192
|
-
*/
|
|
193
|
-
declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
194
|
-
readonly rollup: v.ObjectSchema<{
|
|
195
|
-
readonly type: v.LiteralSchema<"date", undefined>;
|
|
196
|
-
readonly date: v.NullableSchema<v.ObjectSchema<{
|
|
197
|
-
readonly start: v.StringSchema<undefined>;
|
|
198
|
-
readonly end: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
199
|
-
readonly time_zone: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
200
|
-
}, undefined>, undefined>;
|
|
201
|
-
}, undefined>;
|
|
202
|
-
}, undefined>, v.TransformAction<{
|
|
203
|
-
rollup: {
|
|
204
|
-
type: "date";
|
|
205
|
-
date: {
|
|
206
|
-
start: string;
|
|
207
|
-
end: string | null;
|
|
208
|
-
time_zone: string | null;
|
|
209
|
-
} | null;
|
|
210
|
-
};
|
|
211
|
-
}, Date | null>]>;
|
|
212
|
-
/**
|
|
213
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
|
|
214
|
-
*
|
|
215
|
-
* **Input:**
|
|
216
|
-
* ```
|
|
217
|
-
* {
|
|
218
|
-
* rollup: {
|
|
219
|
-
* type: "date";
|
|
220
|
-
* date: {
|
|
221
|
-
* start: string;
|
|
222
|
-
* end: string | null;
|
|
223
|
-
* time_zone: string | null;
|
|
224
|
-
* };
|
|
225
|
-
* };
|
|
226
|
-
* }
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* **Output:** `Date`
|
|
230
|
-
*
|
|
231
|
-
* @example
|
|
232
|
-
* ```ts
|
|
233
|
-
* import * as v from "valibot";
|
|
234
|
-
* import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
235
|
-
*
|
|
236
|
-
* const PageSchema = v.object({
|
|
237
|
-
* id: v.string(),
|
|
238
|
-
* properties: v.object({
|
|
239
|
-
* LatestDate: RollupDateSchema,
|
|
240
|
-
* }),
|
|
241
|
-
* });
|
|
242
|
-
*
|
|
243
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
244
|
-
* const parsed = v.parse(PageSchema, page);
|
|
245
|
-
* // parsed.properties.LatestDate: Date
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
249
|
-
*/
|
|
250
|
-
declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
251
|
-
readonly rollup: v.ObjectSchema<{
|
|
252
|
-
readonly type: v.LiteralSchema<"date", undefined>;
|
|
253
|
-
readonly date: v.ObjectSchema<{
|
|
254
|
-
readonly start: v.StringSchema<undefined>;
|
|
255
|
-
readonly end: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
256
|
-
readonly time_zone: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
257
|
-
}, undefined>;
|
|
258
|
-
}, undefined>;
|
|
259
|
-
}, undefined>, v.TransformAction<{
|
|
260
|
-
rollup: {
|
|
261
|
-
type: "date";
|
|
262
|
-
date: {
|
|
263
|
-
start: string;
|
|
264
|
-
end: string | null;
|
|
265
|
-
time_zone: string | null;
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
}, Date>]>;
|
|
269
65
|
/**
|
|
270
66
|
* Schema factory to extract the `rollup` property with array type from a Notion page property.
|
|
271
67
|
*
|
|
@@ -477,5 +273,5 @@ declare function NullableSingleRollupArraySchema<S extends v.GenericSchema<objec
|
|
|
477
273
|
};
|
|
478
274
|
}, v.InferOutput<S> | null>;
|
|
479
275
|
//#endregion
|
|
480
|
-
export {
|
|
276
|
+
export { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
481
277
|
//# sourceMappingURL=rollup.d.mts.map
|
package/dist/rollup.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DateObjectSchema } from "./date.mjs";
|
|
2
1
|
import * as v from "valibot";
|
|
3
2
|
//#region src/rollup.ts
|
|
4
3
|
/**
|
|
@@ -59,166 +58,6 @@ function RollupSimpleSchema(schema) {
|
|
|
59
58
|
return v.pipe(v.object({ rollup: schema }), v.transform((v) => v.rollup));
|
|
60
59
|
}
|
|
61
60
|
/**
|
|
62
|
-
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
63
|
-
*
|
|
64
|
-
* **Input:**
|
|
65
|
-
* ```
|
|
66
|
-
* {
|
|
67
|
-
* rollup: {
|
|
68
|
-
* type: "number";
|
|
69
|
-
* number: number | null;
|
|
70
|
-
* };
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*
|
|
74
|
-
* **Output:** `number | null`
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* import * as v from "valibot";
|
|
79
|
-
* import { NullableRollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
80
|
-
*
|
|
81
|
-
* const PageSchema = v.object({
|
|
82
|
-
* id: v.string(),
|
|
83
|
-
* properties: v.object({
|
|
84
|
-
* Sum: NullableRollupNumberSchema,
|
|
85
|
-
* }),
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
89
|
-
* const parsed = v.parse(PageSchema, page);
|
|
90
|
-
* // parsed.properties.Sum: number | null
|
|
91
|
-
* ```
|
|
92
|
-
*
|
|
93
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
94
|
-
*/
|
|
95
|
-
const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
96
|
-
type: v.literal("number"),
|
|
97
|
-
number: v.nullable(v.number())
|
|
98
|
-
}) }), v.transform((v) => v.rollup.number));
|
|
99
|
-
/**
|
|
100
|
-
* Schema to extract the `rollup` property with number type from a Notion page property.
|
|
101
|
-
*
|
|
102
|
-
* **Input:**
|
|
103
|
-
* ```
|
|
104
|
-
* {
|
|
105
|
-
* rollup: {
|
|
106
|
-
* type: "number";
|
|
107
|
-
* number: number;
|
|
108
|
-
* };
|
|
109
|
-
* }
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* **Output:** `number`
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```ts
|
|
116
|
-
* import * as v from "valibot";
|
|
117
|
-
* import { RollupNumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
118
|
-
*
|
|
119
|
-
* const PageSchema = v.object({
|
|
120
|
-
* id: v.string(),
|
|
121
|
-
* properties: v.object({
|
|
122
|
-
* Sum: RollupNumberSchema,
|
|
123
|
-
* }),
|
|
124
|
-
* });
|
|
125
|
-
*
|
|
126
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
127
|
-
* const parsed = v.parse(PageSchema, page);
|
|
128
|
-
* // parsed.properties.Sum: number
|
|
129
|
-
* ```
|
|
130
|
-
*
|
|
131
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
132
|
-
*/
|
|
133
|
-
const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
134
|
-
type: v.literal("number"),
|
|
135
|
-
number: v.number()
|
|
136
|
-
}) }), v.transform((v) => v.rollup.number));
|
|
137
|
-
/**
|
|
138
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.
|
|
139
|
-
*
|
|
140
|
-
* **Input:**
|
|
141
|
-
* ```
|
|
142
|
-
* {
|
|
143
|
-
* rollup: {
|
|
144
|
-
* type: "date";
|
|
145
|
-
* date: {
|
|
146
|
-
* start: string;
|
|
147
|
-
* end: string | null;
|
|
148
|
-
* time_zone: string | null;
|
|
149
|
-
* } | null;
|
|
150
|
-
* };
|
|
151
|
-
* }
|
|
152
|
-
* ```
|
|
153
|
-
*
|
|
154
|
-
* **Output:** `Date | null`
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* import * as v from "valibot";
|
|
159
|
-
* import { NullableRollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
160
|
-
*
|
|
161
|
-
* const PageSchema = v.object({
|
|
162
|
-
* id: v.string(),
|
|
163
|
-
* properties: v.object({
|
|
164
|
-
* LatestDate: NullableRollupDateSchema,
|
|
165
|
-
* }),
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
169
|
-
* const parsed = v.parse(PageSchema, page);
|
|
170
|
-
* // parsed.properties.LatestDate: Date | null
|
|
171
|
-
* ```
|
|
172
|
-
*
|
|
173
|
-
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
174
|
-
*/
|
|
175
|
-
const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
|
|
176
|
-
type: v.literal("date"),
|
|
177
|
-
date: v.nullable(DateObjectSchema)
|
|
178
|
-
}) }), v.transform((v) => v.rollup.date ? new Date(v.rollup.date.start) : null));
|
|
179
|
-
/**
|
|
180
|
-
* Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.
|
|
181
|
-
*
|
|
182
|
-
* **Input:**
|
|
183
|
-
* ```
|
|
184
|
-
* {
|
|
185
|
-
* rollup: {
|
|
186
|
-
* type: "date";
|
|
187
|
-
* date: {
|
|
188
|
-
* start: string;
|
|
189
|
-
* end: string | null;
|
|
190
|
-
* time_zone: string | null;
|
|
191
|
-
* };
|
|
192
|
-
* };
|
|
193
|
-
* }
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* **Output:** `Date`
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```ts
|
|
200
|
-
* import * as v from "valibot";
|
|
201
|
-
* import { RollupDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
202
|
-
*
|
|
203
|
-
* const PageSchema = v.object({
|
|
204
|
-
* id: v.string(),
|
|
205
|
-
* properties: v.object({
|
|
206
|
-
* LatestDate: RollupDateSchema,
|
|
207
|
-
* }),
|
|
208
|
-
* });
|
|
209
|
-
*
|
|
210
|
-
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
211
|
-
* const parsed = v.parse(PageSchema, page);
|
|
212
|
-
* // parsed.properties.LatestDate: Date
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
216
|
-
*/
|
|
217
|
-
const RollupDateSchema = v.pipe(v.object({ rollup: v.object({
|
|
218
|
-
type: v.literal("date"),
|
|
219
|
-
date: DateObjectSchema
|
|
220
|
-
}) }), v.transform((v) => new Date(v.rollup.date.start)));
|
|
221
|
-
/**
|
|
222
61
|
* Schema factory to extract the `rollup` property with array type from a Notion page property.
|
|
223
62
|
*
|
|
224
63
|
* This is a generic schema factory that accepts another schema as a parameter,
|
|
@@ -424,6 +263,6 @@ function NullableSingleRollupArraySchema(schema) {
|
|
|
424
263
|
}) }), v.transform((v) => v.rollup.array[0] ?? null));
|
|
425
264
|
}
|
|
426
265
|
//#endregion
|
|
427
|
-
export {
|
|
266
|
+
export { NullableSingleRollupArraySchema, RollupArraySchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
428
267
|
|
|
429
268
|
//# sourceMappingURL=rollup.mjs.map
|
package/dist/rollup.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.mjs","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\n/**\n * Schema factory to extract the `rollup` property with a simple (non-array) type 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 the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number | null;\n * };\n * }\n * ```\n *\n * **Output:** `number | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: NullableRollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.\n */\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number;\n * };\n * }\n * ```\n *\n * **Output:** `number`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.\n */\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * };\n * }\n * ```\n *\n * **Output:** `Date | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: NullableRollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.\n */\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * };\n * };\n * }\n * ```\n *\n * **Output:** `Date`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.\n */\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\n/**\n * Schema factory to extract the `rollup` property with array type 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 rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAGf,QAMC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6B,EAAE,KAC3C,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,qBAAqB,EAAE,KACnC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,SAAS,gBAAgB;AAClC,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM;AACP,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|
|
1
|
+
{"version":3,"file":"rollup.mjs","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `rollup` property with a simple (non-array) type 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 the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\n\n/**\n * Schema factory to extract the `rollup` property with array type 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 rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,SAAgB,mBAGf,QAMC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|