@nakanoaas/notion-valibot-schema 0.2.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -10
- package/dist/_virtual/_rolldown/runtime.cjs +7 -13
- package/dist/checkbox.cjs +3 -4
- package/dist/checkbox.cjs.map +1 -1
- package/dist/checkbox.mjs +1 -2
- package/dist/checkbox.mjs.map +1 -1
- package/dist/created-by.cjs +4 -5
- package/dist/created-by.cjs.map +1 -1
- package/dist/created-by.mjs +1 -2
- package/dist/created-by.mjs.map +1 -1
- package/dist/created-time.cjs +3 -4
- package/dist/created-time.cjs.map +1 -1
- package/dist/created-time.mjs +1 -2
- package/dist/created-time.mjs.map +1 -1
- package/dist/date.cjs +3 -4
- package/dist/date.cjs.map +1 -1
- package/dist/date.mjs +1 -2
- package/dist/date.mjs.map +1 -1
- package/dist/email.cjs +3 -4
- package/dist/email.cjs.map +1 -1
- package/dist/email.mjs +1 -2
- package/dist/email.mjs.map +1 -1
- package/dist/files.cjs +123 -14
- package/dist/files.cjs.map +1 -1
- package/dist/files.d.cts +132 -4
- package/dist/files.d.mts +132 -4
- package/dist/files.mjs +119 -12
- package/dist/files.mjs.map +1 -1
- package/dist/formula.cjs +123 -23
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +150 -41
- package/dist/formula.d.mts +150 -41
- package/dist/formula.mjs +118 -22
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +32 -26
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -5
- package/dist/last-edited-by.cjs +4 -5
- package/dist/last-edited-by.cjs.map +1 -1
- package/dist/last-edited-by.mjs +1 -2
- package/dist/last-edited-by.mjs.map +1 -1
- package/dist/last-edited-time.cjs +3 -4
- package/dist/last-edited-time.cjs.map +1 -1
- package/dist/last-edited-time.mjs +1 -2
- package/dist/last-edited-time.mjs.map +1 -1
- package/dist/multi-select.cjs +3 -4
- package/dist/multi-select.cjs.map +1 -1
- package/dist/multi-select.mjs +1 -2
- package/dist/multi-select.mjs.map +1 -1
- package/dist/number.cjs +3 -4
- package/dist/number.cjs.map +1 -1
- package/dist/number.mjs +1 -2
- package/dist/number.mjs.map +1 -1
- package/dist/people.cjs +3 -4
- package/dist/people.cjs.map +1 -1
- package/dist/people.mjs +1 -2
- package/dist/people.mjs.map +1 -1
- package/dist/phone-number.cjs +3 -4
- package/dist/phone-number.cjs.map +1 -1
- package/dist/phone-number.mjs +1 -2
- package/dist/phone-number.mjs.map +1 -1
- package/dist/place.cjs +3 -4
- package/dist/place.cjs.map +1 -1
- package/dist/place.mjs +1 -2
- package/dist/place.mjs.map +1 -1
- package/dist/relation.cjs +3 -4
- package/dist/relation.cjs.map +1 -1
- package/dist/relation.mjs +1 -2
- package/dist/relation.mjs.map +1 -1
- package/dist/rollup.cjs +70 -5
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +70 -1
- package/dist/rollup.d.mts +70 -1
- package/dist/rollup.mjs +67 -3
- package/dist/rollup.mjs.map +1 -1
- package/dist/select.cjs +3 -4
- package/dist/select.cjs.map +1 -1
- package/dist/select.mjs +1 -2
- package/dist/select.mjs.map +1 -1
- package/dist/status.cjs +3 -4
- package/dist/status.cjs.map +1 -1
- package/dist/status.mjs +1 -2
- package/dist/status.mjs.map +1 -1
- package/dist/text.cjs +3 -4
- package/dist/text.cjs.map +1 -1
- package/dist/text.mjs +1 -2
- package/dist/text.mjs.map +1 -1
- package/dist/unique-id.cjs +3 -4
- package/dist/unique-id.cjs.map +1 -1
- package/dist/unique-id.mjs +1 -2
- package/dist/unique-id.mjs.map +1 -1
- package/dist/url.cjs +3 -4
- package/dist/url.cjs.map +1 -1
- package/dist/url.mjs +1 -2
- package/dist/url.mjs.map +1 -1
- package/dist/verification.cjs +5 -6
- package/dist/verification.cjs.map +1 -1
- package/dist/verification.mjs +1 -2
- package/dist/verification.mjs.map +1 -1
- package/package.json +4 -4
package/dist/relation.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.mjs","names":[],"sources":["../src/relation.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion relation object structure.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * }\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { InnerRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Relation: v.object({\n * relation: v.array(InnerRelationSchema),\n * }),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Relation.relation: Array<{ id: string }>\n * ```\n *\n * @internal\n */\nconst InnerRelationSchema = v.object({ id: v.string() });\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to an array of page IDs.\n *\n * **Input:**\n * ```\n * {\n * relation: Array<{\n * id: string;\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RelatedPages: RelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RelatedPages: string[]\n * ```\n */\nexport const RelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.array(InnerRelationSchema),\n\t}),\n\tv.transform((v) => v.relation.map((r) => r.id)),\n);\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to a single page ID.\n *\n * **Input:**\n * ```\n * {\n * relation: [{\n * id: string;\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * ParentPage: SingleRelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.ParentPage: string\n * ```\n */\nexport const SingleRelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.tuple([InnerRelationSchema]),\n\t}),\n\tv.transform((v) => v.relation[0].id),\n);\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to a single page ID or `null`.\n *\n * **Input:**\n * ```\n * {\n * relation: Array<{\n * id: string;\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * ParentPage: NullableSingleRelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.ParentPage: string | null\n * ```\n */\nexport const NullableSingleRelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.array(InnerRelationSchema),\n\t}),\n\tv.transform((v) => v.relation[0]?.id ?? null),\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"relation.mjs","names":[],"sources":["../src/relation.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion relation object structure.\n *\n * **Input:**\n * ```\n * {\n * id: string;\n * }\n * ```\n *\n * **Output:**\n * ```\n * {\n * id: string;\n * }\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { InnerRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Relation: v.object({\n * relation: v.array(InnerRelationSchema),\n * }),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Relation.relation: Array<{ id: string }>\n * ```\n *\n * @internal\n */\nconst InnerRelationSchema = v.object({ id: v.string() });\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to an array of page IDs.\n *\n * **Input:**\n * ```\n * {\n * relation: Array<{\n * id: string;\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RelatedPages: RelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RelatedPages: string[]\n * ```\n */\nexport const RelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.array(InnerRelationSchema),\n\t}),\n\tv.transform((v) => v.relation.map((r) => r.id)),\n);\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to a single page ID.\n *\n * **Input:**\n * ```\n * {\n * relation: [{\n * id: string;\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * ParentPage: SingleRelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.ParentPage: string\n * ```\n */\nexport const SingleRelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.tuple([InnerRelationSchema]),\n\t}),\n\tv.transform((v) => v.relation[0].id),\n);\n\n/**\n * Schema to extract the `relation` property from a Notion page property and transform it to a single page ID or `null`.\n *\n * **Input:**\n * ```\n * {\n * relation: Array<{\n * id: string;\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRelationSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * ParentPage: NullableSingleRelationSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.ParentPage: string | null\n * ```\n */\nexport const NullableSingleRelationSchema = v.pipe(\n\tv.object({\n\t\trelation: v.array(InnerRelationSchema),\n\t}),\n\tv.transform((v) => v.relation[0]?.id ?? null),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,sBAAsB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCvD,MAAa,iBAAiB,EAAE,KAC/B,EAAE,OAAO,EACR,UAAU,EAAE,MAAM,mBAAmB,EACtC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,SAAS,KAAK,MAAM,EAAE,EAAE,CAAC,CAC/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,uBAAuB,EAAE,KACrC,EAAE,OAAO,EACR,UAAU,EAAE,MAAM,CAAC,mBAAmB,CAAC,EACxC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,CACpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,+BAA+B,EAAE,KAC7C,EAAE,OAAO,EACR,UAAU,EAAE,MAAM,mBAAmB,EACtC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,IAAI,CAC7C"}
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,10 +1,66 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
2
|
-
const require_date = require(
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_date = require("./date.cjs");
|
|
3
3
|
let valibot = require("valibot");
|
|
4
|
-
valibot = require_runtime.__toESM(valibot);
|
|
5
|
-
|
|
4
|
+
valibot = require_runtime.__toESM(valibot, 1);
|
|
6
5
|
//#region src/rollup.ts
|
|
7
6
|
/**
|
|
7
|
+
* Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
|
|
8
|
+
*
|
|
9
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
10
|
+
* allowing you to combine it with the number and date schemas in this library
|
|
11
|
+
* to extract typed rollup results (e.g. number or date rollups).
|
|
12
|
+
*
|
|
13
|
+
* **Input:**
|
|
14
|
+
* ```
|
|
15
|
+
* {
|
|
16
|
+
* rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
21
|
+
* For example, if `NumberSchema` is passed, the output will be `number`.
|
|
22
|
+
*
|
|
23
|
+
* @param schema - A schema that validates the rollup value.
|
|
24
|
+
* Must accept an object with a `number` or `date` field.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import * as v from "valibot";
|
|
29
|
+
* import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
30
|
+
*
|
|
31
|
+
* const PageSchema = v.object({
|
|
32
|
+
* id: v.string(),
|
|
33
|
+
* properties: v.object({
|
|
34
|
+
* Sum: RollupSimpleSchema(NumberSchema),
|
|
35
|
+
* }),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
39
|
+
* const parsed = v.parse(PageSchema, page);
|
|
40
|
+
* // parsed.properties.Sum: number
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import * as v from "valibot";
|
|
46
|
+
* import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
47
|
+
*
|
|
48
|
+
* const PageSchema = v.object({
|
|
49
|
+
* id: v.string(),
|
|
50
|
+
* properties: v.object({
|
|
51
|
+
* LatestDate: RollupSimpleSchema(SingleDateSchema),
|
|
52
|
+
* }),
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
56
|
+
* const parsed = v.parse(PageSchema, page);
|
|
57
|
+
* // parsed.properties.LatestDate: Date
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function RollupSimpleSchema(schema) {
|
|
61
|
+
return valibot.pipe(valibot.object({ rollup: schema }), valibot.transform((v) => v.rollup));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
8
64
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
9
65
|
*
|
|
10
66
|
* **Input:**
|
|
@@ -35,6 +91,8 @@ valibot = require_runtime.__toESM(valibot);
|
|
|
35
91
|
* const parsed = v.parse(PageSchema, page);
|
|
36
92
|
* // parsed.properties.Sum: number | null
|
|
37
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
38
96
|
*/
|
|
39
97
|
const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
40
98
|
type: valibot.literal("number"),
|
|
@@ -71,6 +129,8 @@ const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot
|
|
|
71
129
|
* const parsed = v.parse(PageSchema, page);
|
|
72
130
|
* // parsed.properties.Sum: number
|
|
73
131
|
* ```
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
74
134
|
*/
|
|
75
135
|
const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
76
136
|
type: valibot.literal("number"),
|
|
@@ -111,6 +171,8 @@ const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object(
|
|
|
111
171
|
* const parsed = v.parse(PageSchema, page);
|
|
112
172
|
* // parsed.properties.LatestDate: Date | null
|
|
113
173
|
* ```
|
|
174
|
+
*
|
|
175
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
114
176
|
*/
|
|
115
177
|
const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
116
178
|
type: valibot.literal("date"),
|
|
@@ -151,6 +213,8 @@ const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.o
|
|
|
151
213
|
* const parsed = v.parse(PageSchema, page);
|
|
152
214
|
* // parsed.properties.LatestDate: Date
|
|
153
215
|
* ```
|
|
216
|
+
*
|
|
217
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
154
218
|
*/
|
|
155
219
|
const RollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
156
220
|
type: valibot.literal("date"),
|
|
@@ -361,7 +425,6 @@ function NullableSingleRollupArraySchema(schema) {
|
|
|
361
425
|
array: valibot.array(schema)
|
|
362
426
|
}) }), valibot.transform((v) => v.rollup.array[0] ?? null));
|
|
363
427
|
}
|
|
364
|
-
|
|
365
428
|
//#endregion
|
|
366
429
|
exports.NullableRollupDateSchema = NullableRollupDateSchema;
|
|
367
430
|
exports.NullableRollupNumberSchema = NullableRollupNumberSchema;
|
|
@@ -369,5 +432,7 @@ exports.NullableSingleRollupArraySchema = NullableSingleRollupArraySchema;
|
|
|
369
432
|
exports.RollupArraySchema = RollupArraySchema;
|
|
370
433
|
exports.RollupDateSchema = RollupDateSchema;
|
|
371
434
|
exports.RollupNumberSchema = RollupNumberSchema;
|
|
435
|
+
exports.RollupSimpleSchema = RollupSimpleSchema;
|
|
372
436
|
exports.SingleRollupArraySchema = SingleRollupArraySchema;
|
|
437
|
+
|
|
373
438
|
//# sourceMappingURL=rollup.cjs.map
|
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 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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6BA,QAAE,KAC3CA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,SAASA,QAAE,QAAQ,CAAC;CAC9B,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCD,MAAa,qBAAqBA,QAAE,KACnCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,SAAS;CACzB,QAAQA,QAAE,QAAQ;CAClB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMA,QAAE,SAASC,8BAAiB;CAClC,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,KAAM,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,OAAO;CACvB,MAAMC;CACN,CAAC,EACF,CAAC,EACFD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkED,SAAgB,kBACf,QACC;AACD,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,QAAQ;EACxB,OAAOA,QAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEF,SAAgB,wBAGf,QASC;AACD,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,QAAQ;EACxB,OAAOA,QAAE,MAAM,CAAC,OAAO,CAAC;EACxB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,GAAG,CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEF,SAAgB,gCAGf,QASC;AACD,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,QAAQ;EACxB,OAAOA,QAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACFA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,KAAiC,CAC1E"}
|
|
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"}
|
package/dist/rollup.d.cts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/rollup.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
|
|
6
|
+
*
|
|
7
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
8
|
+
* allowing you to combine it with the number and date schemas in this library
|
|
9
|
+
* to extract typed rollup results (e.g. number or date rollups).
|
|
10
|
+
*
|
|
11
|
+
* **Input:**
|
|
12
|
+
* ```
|
|
13
|
+
* {
|
|
14
|
+
* rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
19
|
+
* For example, if `NumberSchema` is passed, the output will be `number`.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - A schema that validates the rollup value.
|
|
22
|
+
* Must accept an object with a `number` or `date` field.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import * as v from "valibot";
|
|
27
|
+
* import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
28
|
+
*
|
|
29
|
+
* const PageSchema = v.object({
|
|
30
|
+
* id: v.string(),
|
|
31
|
+
* properties: v.object({
|
|
32
|
+
* Sum: RollupSimpleSchema(NumberSchema),
|
|
33
|
+
* }),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
37
|
+
* const parsed = v.parse(PageSchema, page);
|
|
38
|
+
* // parsed.properties.Sum: number
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import * as v from "valibot";
|
|
44
|
+
* import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
45
|
+
*
|
|
46
|
+
* const PageSchema = v.object({
|
|
47
|
+
* id: v.string(),
|
|
48
|
+
* properties: v.object({
|
|
49
|
+
* LatestDate: RollupSimpleSchema(SingleDateSchema),
|
|
50
|
+
* }),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
54
|
+
* const parsed = v.parse(PageSchema, page);
|
|
55
|
+
* // parsed.properties.LatestDate: Date
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function RollupSimpleSchema<S extends v.GenericSchema<{
|
|
59
|
+
number: unknown;
|
|
60
|
+
} | {
|
|
61
|
+
date: unknown;
|
|
62
|
+
}, unknown>>(schema: S): v.GenericSchema<{
|
|
63
|
+
rollup: v.InferInput<S>;
|
|
64
|
+
}, v.InferOutput<S>>;
|
|
4
65
|
/**
|
|
5
66
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
6
67
|
*
|
|
@@ -32,6 +93,8 @@ import * as v from "valibot";
|
|
|
32
93
|
* const parsed = v.parse(PageSchema, page);
|
|
33
94
|
* // parsed.properties.Sum: number | null
|
|
34
95
|
* ```
|
|
96
|
+
*
|
|
97
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
35
98
|
*/
|
|
36
99
|
declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
37
100
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -75,6 +138,8 @@ declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSch
|
|
|
75
138
|
* const parsed = v.parse(PageSchema, page);
|
|
76
139
|
* // parsed.properties.Sum: number
|
|
77
140
|
* ```
|
|
141
|
+
*
|
|
142
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
78
143
|
*/
|
|
79
144
|
declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
80
145
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -122,6 +187,8 @@ declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
122
187
|
* const parsed = v.parse(PageSchema, page);
|
|
123
188
|
* // parsed.properties.LatestDate: Date | null
|
|
124
189
|
* ```
|
|
190
|
+
*
|
|
191
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
125
192
|
*/
|
|
126
193
|
declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
127
194
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -177,6 +244,8 @@ declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchem
|
|
|
177
244
|
* const parsed = v.parse(PageSchema, page);
|
|
178
245
|
* // parsed.properties.LatestDate: Date
|
|
179
246
|
* ```
|
|
247
|
+
*
|
|
248
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
180
249
|
*/
|
|
181
250
|
declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
182
251
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -408,5 +477,5 @@ declare function NullableSingleRollupArraySchema<S extends v.GenericSchema<objec
|
|
|
408
477
|
};
|
|
409
478
|
}, v.InferOutput<S> | null>;
|
|
410
479
|
//#endregion
|
|
411
|
-
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema };
|
|
480
|
+
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
412
481
|
//# sourceMappingURL=rollup.d.cts.map
|
package/dist/rollup.d.mts
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
|
|
3
3
|
//#region src/rollup.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
|
|
6
|
+
*
|
|
7
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
8
|
+
* allowing you to combine it with the number and date schemas in this library
|
|
9
|
+
* to extract typed rollup results (e.g. number or date rollups).
|
|
10
|
+
*
|
|
11
|
+
* **Input:**
|
|
12
|
+
* ```
|
|
13
|
+
* {
|
|
14
|
+
* rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
19
|
+
* For example, if `NumberSchema` is passed, the output will be `number`.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - A schema that validates the rollup value.
|
|
22
|
+
* Must accept an object with a `number` or `date` field.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import * as v from "valibot";
|
|
27
|
+
* import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
28
|
+
*
|
|
29
|
+
* const PageSchema = v.object({
|
|
30
|
+
* id: v.string(),
|
|
31
|
+
* properties: v.object({
|
|
32
|
+
* Sum: RollupSimpleSchema(NumberSchema),
|
|
33
|
+
* }),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
37
|
+
* const parsed = v.parse(PageSchema, page);
|
|
38
|
+
* // parsed.properties.Sum: number
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import * as v from "valibot";
|
|
44
|
+
* import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
45
|
+
*
|
|
46
|
+
* const PageSchema = v.object({
|
|
47
|
+
* id: v.string(),
|
|
48
|
+
* properties: v.object({
|
|
49
|
+
* LatestDate: RollupSimpleSchema(SingleDateSchema),
|
|
50
|
+
* }),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
54
|
+
* const parsed = v.parse(PageSchema, page);
|
|
55
|
+
* // parsed.properties.LatestDate: Date
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function RollupSimpleSchema<S extends v.GenericSchema<{
|
|
59
|
+
number: unknown;
|
|
60
|
+
} | {
|
|
61
|
+
date: unknown;
|
|
62
|
+
}, unknown>>(schema: S): v.GenericSchema<{
|
|
63
|
+
rollup: v.InferInput<S>;
|
|
64
|
+
}, v.InferOutput<S>>;
|
|
4
65
|
/**
|
|
5
66
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
6
67
|
*
|
|
@@ -32,6 +93,8 @@ import * as v from "valibot";
|
|
|
32
93
|
* const parsed = v.parse(PageSchema, page);
|
|
33
94
|
* // parsed.properties.Sum: number | null
|
|
34
95
|
* ```
|
|
96
|
+
*
|
|
97
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
35
98
|
*/
|
|
36
99
|
declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
37
100
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -75,6 +138,8 @@ declare const NullableRollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSch
|
|
|
75
138
|
* const parsed = v.parse(PageSchema, page);
|
|
76
139
|
* // parsed.properties.Sum: number
|
|
77
140
|
* ```
|
|
141
|
+
*
|
|
142
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
78
143
|
*/
|
|
79
144
|
declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
80
145
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -122,6 +187,8 @@ declare const RollupNumberSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
|
122
187
|
* const parsed = v.parse(PageSchema, page);
|
|
123
188
|
* // parsed.properties.LatestDate: Date | null
|
|
124
189
|
* ```
|
|
190
|
+
*
|
|
191
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
125
192
|
*/
|
|
126
193
|
declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
127
194
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -177,6 +244,8 @@ declare const NullableRollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchem
|
|
|
177
244
|
* const parsed = v.parse(PageSchema, page);
|
|
178
245
|
* // parsed.properties.LatestDate: Date
|
|
179
246
|
* ```
|
|
247
|
+
*
|
|
248
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
180
249
|
*/
|
|
181
250
|
declare const RollupDateSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
|
|
182
251
|
readonly rollup: v.ObjectSchema<{
|
|
@@ -408,5 +477,5 @@ declare function NullableSingleRollupArraySchema<S extends v.GenericSchema<objec
|
|
|
408
477
|
};
|
|
409
478
|
}, v.InferOutput<S> | null>;
|
|
410
479
|
//#endregion
|
|
411
|
-
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema };
|
|
480
|
+
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
412
481
|
//# sourceMappingURL=rollup.d.mts.map
|
package/dist/rollup.mjs
CHANGED
|
@@ -1,8 +1,64 @@
|
|
|
1
1
|
import { DateObjectSchema } from "./date.mjs";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
|
|
4
3
|
//#region src/rollup.ts
|
|
5
4
|
/**
|
|
5
|
+
* Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
|
|
6
|
+
*
|
|
7
|
+
* This is a generic schema factory that accepts another schema as a parameter,
|
|
8
|
+
* allowing you to combine it with the number and date schemas in this library
|
|
9
|
+
* to extract typed rollup results (e.g. number or date rollups).
|
|
10
|
+
*
|
|
11
|
+
* **Input:**
|
|
12
|
+
* ```
|
|
13
|
+
* {
|
|
14
|
+
* rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* **Output:** The output type depends on the schema passed as a parameter.
|
|
19
|
+
* For example, if `NumberSchema` is passed, the output will be `number`.
|
|
20
|
+
*
|
|
21
|
+
* @param schema - A schema that validates the rollup value.
|
|
22
|
+
* Must accept an object with a `number` or `date` field.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import * as v from "valibot";
|
|
27
|
+
* import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
|
|
28
|
+
*
|
|
29
|
+
* const PageSchema = v.object({
|
|
30
|
+
* id: v.string(),
|
|
31
|
+
* properties: v.object({
|
|
32
|
+
* Sum: RollupSimpleSchema(NumberSchema),
|
|
33
|
+
* }),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
37
|
+
* const parsed = v.parse(PageSchema, page);
|
|
38
|
+
* // parsed.properties.Sum: number
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import * as v from "valibot";
|
|
44
|
+
* import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
|
|
45
|
+
*
|
|
46
|
+
* const PageSchema = v.object({
|
|
47
|
+
* id: v.string(),
|
|
48
|
+
* properties: v.object({
|
|
49
|
+
* LatestDate: RollupSimpleSchema(SingleDateSchema),
|
|
50
|
+
* }),
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const page = await notion.pages.retrieve({ page_id: "..." });
|
|
54
|
+
* const parsed = v.parse(PageSchema, page);
|
|
55
|
+
* // parsed.properties.LatestDate: Date
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function RollupSimpleSchema(schema) {
|
|
59
|
+
return v.pipe(v.object({ rollup: schema }), v.transform((v) => v.rollup));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
6
62
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
7
63
|
*
|
|
8
64
|
* **Input:**
|
|
@@ -33,6 +89,8 @@ import * as v from "valibot";
|
|
|
33
89
|
* const parsed = v.parse(PageSchema, page);
|
|
34
90
|
* // parsed.properties.Sum: number | null
|
|
35
91
|
* ```
|
|
92
|
+
*
|
|
93
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
36
94
|
*/
|
|
37
95
|
const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
38
96
|
type: v.literal("number"),
|
|
@@ -69,6 +127,8 @@ const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
|
69
127
|
* const parsed = v.parse(PageSchema, page);
|
|
70
128
|
* // parsed.properties.Sum: number
|
|
71
129
|
* ```
|
|
130
|
+
*
|
|
131
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
72
132
|
*/
|
|
73
133
|
const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
74
134
|
type: v.literal("number"),
|
|
@@ -109,6 +169,8 @@ const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
|
|
|
109
169
|
* const parsed = v.parse(PageSchema, page);
|
|
110
170
|
* // parsed.properties.LatestDate: Date | null
|
|
111
171
|
* ```
|
|
172
|
+
*
|
|
173
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
112
174
|
*/
|
|
113
175
|
const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
|
|
114
176
|
type: v.literal("date"),
|
|
@@ -149,6 +211,8 @@ const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
|
|
|
149
211
|
* const parsed = v.parse(PageSchema, page);
|
|
150
212
|
* // parsed.properties.LatestDate: Date
|
|
151
213
|
* ```
|
|
214
|
+
*
|
|
215
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
152
216
|
*/
|
|
153
217
|
const RollupDateSchema = v.pipe(v.object({ rollup: v.object({
|
|
154
218
|
type: v.literal("date"),
|
|
@@ -359,7 +423,7 @@ function NullableSingleRollupArraySchema(schema) {
|
|
|
359
423
|
array: v.array(schema)
|
|
360
424
|
}) }), v.transform((v) => v.rollup.array[0] ?? null));
|
|
361
425
|
}
|
|
362
|
-
|
|
363
426
|
//#endregion
|
|
364
|
-
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema };
|
|
427
|
+
export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema };
|
|
428
|
+
|
|
365
429
|
//# 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 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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6B,EAAE,KAC3C,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,SAAS;CACzB,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC;CAC9B,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCD,MAAa,qBAAqB,EAAE,KACnC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,SAAS;CACzB,QAAQ,EAAE,QAAQ;CAClB,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAM,EAAE,OAAO,OAAO,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,OAAO;CACvB,MAAM,EAAE,SAAS,iBAAiB;CAClC,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,KAAM,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCD,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,OAAO;CACvB,MAAM;CACN,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkED,SAAgB,kBACf,QACC;AACD,QAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,QAAQ;EACxB,OAAO,EAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CAClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEF,SAAgB,wBAGf,QASC;AACD,QAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,QAAQ;EACxB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;EACxB,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,GAAG,CACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEF,SAAgB,gCAGf,QASC;AACD,QAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,QAAQ;EACxB,OAAO,EAAE,MAAM,OAAO;EACtB,CAAC,EACF,CAAC,EACF,EAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,KAAiC,CAC1E"}
|
|
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"}
|
package/dist/select.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const require_runtime = require(
|
|
1
|
+
const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let valibot = require("valibot");
|
|
3
|
-
valibot = require_runtime.__toESM(valibot);
|
|
4
|
-
|
|
3
|
+
valibot = require_runtime.__toESM(valibot, 1);
|
|
5
4
|
//#region src/select.ts
|
|
6
5
|
/**
|
|
7
6
|
* Schema factory to extract the `select` property from a Notion page property.
|
|
@@ -129,8 +128,8 @@ function SelectSchema(schema) {
|
|
|
129
128
|
function NullableSelectSchema(schema) {
|
|
130
129
|
return valibot.pipe(valibot.object({ select: valibot.nullable(valibot.object({ name: schema })) }), valibot.transform((v) => v.select?.name ?? null));
|
|
131
130
|
}
|
|
132
|
-
|
|
133
131
|
//#endregion
|
|
134
132
|
exports.NullableSelectSchema = NullableSelectSchema;
|
|
135
133
|
exports.SelectSchema = SelectSchema;
|
|
134
|
+
|
|
136
135
|
//# sourceMappingURL=select.cjs.map
|