@nakanoaas/notion-valibot-schema 0.3.0 → 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 +32 -10
- package/dist/{file.cjs → files.cjs} +6 -6
- package/dist/files.cjs.map +1 -0
- package/dist/{file.d.cts → files.d.cts} +6 -6
- package/dist/{file.d.mts → files.d.mts} +6 -6
- package/dist/{file.mjs → files.mjs} +6 -6
- package/dist/files.mjs.map +1 -0
- package/dist/formula.cjs +120 -19
- package/dist/formula.cjs.map +1 -1
- package/dist/formula.d.cts +150 -41
- package/dist/formula.d.mts +150 -41
- package/dist/formula.mjs +117 -20
- package/dist/formula.mjs.map +1 -1
- package/dist/index.cjs +9 -4
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/rollup.cjs +66 -0
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +70 -1
- package/dist/rollup.d.mts +70 -1
- package/dist/rollup.mjs +66 -1
- package/dist/rollup.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/file.cjs.map +0 -1
- package/dist/file.mjs.map +0 -1
package/dist/formula.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formula.mjs","names":[],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with
|
|
1
|
+
{"version":3,"file":"formula.mjs","names":[],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with the formula, number, and date schemas in this library\n * to extract typed formula results (e.g. string, number, boolean, or date formulas).\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `StringFormulaSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result object.\n * Use the pre-built `*FormulaSchema` helpers for string and boolean,\n * `NumberSchema` / `NullableNumberSchema` for number,\n * or the date schemas from this library for date formulas.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import {\n * BooleanFormulaSchema,\n * FormulaSchema,\n * NumberSchema,\n * SingleDateSchema,\n * StringFormulaSchema,\n * } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(StringFormulaSchema),\n * FormulaNumber: FormulaSchema(NumberSchema),\n * FormulaBoolean: FormulaSchema(BooleanFormulaSchema),\n * FormulaDate: FormulaSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * // parsed.properties.FormulaNumber: number\n * // parsed.properties.FormulaBoolean: boolean\n * // parsed.properties.FormulaDate: Date\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { boolean: boolean | null }\n\t\t| {\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t }\n\t\t| { number: number | null }\n\t\t| { string: string | null },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n\n/**\n * Pre-built inner schema for a non-nullable string formula result.\n *\n * Validates `{ string: string }` and extracts the `string` value.\n * Use with {@link FormulaSchema} when the formula is guaranteed to return a string.\n *\n * **Input:** `{ string: string }`\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, StringFormulaSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * MyFormula: FormulaSchema(StringFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.MyFormula: string\n * ```\n */\nexport const StringFormulaSchema = v.pipe(\n\tv.object({\n\t\tstring: v.string(),\n\t}),\n\tv.transform((v) => v.string),\n);\n\n/**\n * Pre-built inner schema for a nullable string formula result.\n *\n * Validates `{ string: string | null }` and extracts the `string` value.\n * Use with {@link FormulaSchema} when the string formula result may be null.\n *\n * **Input:** `{ string: string | null }`\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, NullableStringFormulaSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * MyFormula: FormulaSchema(NullableStringFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.MyFormula: string | null\n * ```\n */\nexport const NullableStringFormulaSchema = v.pipe(\n\tv.object({\n\t\tstring: v.nullable(v.string()),\n\t}),\n\tv.transform((v) => v.string),\n);\n\n/**\n * Pre-built inner schema for a non-nullable boolean formula result.\n *\n * Validates `{ boolean: boolean }` and extracts the `boolean` value.\n * Use with {@link FormulaSchema} when the formula is guaranteed to return a boolean.\n *\n * **Input:** `{ boolean: boolean }`\n * **Output:** `boolean`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, BooleanFormulaSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * MyFormula: FormulaSchema(BooleanFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.MyFormula: boolean\n * ```\n */\nexport const BooleanFormulaSchema = v.pipe(\n\tv.object({\n\t\tboolean: v.boolean(),\n\t}),\n\tv.transform((v) => v.boolean),\n);\n\n/**\n * Pre-built inner schema for a nullable boolean formula result.\n *\n * Validates `{ boolean: boolean | null }` and extracts the `boolean` value.\n * Use with {@link FormulaSchema} when the boolean formula result may be null.\n *\n * **Input:** `{ boolean: boolean | null }`\n * **Output:** `boolean | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, NullableBooleanFormulaSchema } from \"@nakanoaas/notion-valibot-schema\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * MyFormula: FormulaSchema(NullableBooleanFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.MyFormula: boolean | null\n * ```\n */\nexport const NullableBooleanFormulaSchema = v.pipe(\n\tv.object({\n\t\tboolean: v.nullable(v.boolean()),\n\t}),\n\tv.transform((v) => v.boolean),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,cAcd,QAAW;CACZ,OAAO,EAAE,KACR,EAAE,OAAO,EACR,SAAS,OACV,CAAC,GAED,EAAE,WAAW,MAAM,EAAE,OAAQ,CAC9B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,sBAAsB,EAAE,KACpC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO,EAClB,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,8BAA8B,EAAE,KAC5C,EAAE,OAAO,EACR,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,EAC9B,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,uBAAuB,EAAE,KACrC,EAAE,OAAO,EACR,SAAS,EAAE,QAAQ,EACpB,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,+BAA+B,EAAE,KAC7C,EAAE,OAAO,EACR,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,EAChC,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,CAC7B"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ const require_created_by = require("./created-by.cjs");
|
|
|
5
5
|
const require_created_time = require("./created-time.cjs");
|
|
6
6
|
const require_date = require("./date.cjs");
|
|
7
7
|
const require_email = require("./email.cjs");
|
|
8
|
-
const
|
|
8
|
+
const require_files = require("./files.cjs");
|
|
9
9
|
const require_formula = require("./formula.cjs");
|
|
10
10
|
const require_last_edited_by = require("./last-edited-by.cjs");
|
|
11
11
|
const require_last_edited_time = require("./last-edited-time.cjs");
|
|
@@ -21,19 +21,21 @@ const require_text = require("./text.cjs");
|
|
|
21
21
|
const require_unique_id = require("./unique-id.cjs");
|
|
22
22
|
const require_url = require("./url.cjs");
|
|
23
23
|
const require_verification = require("./verification.cjs");
|
|
24
|
+
exports.BooleanFormulaSchema = require_formula.BooleanFormulaSchema;
|
|
24
25
|
exports.CheckboxSchema = require_checkbox.CheckboxSchema;
|
|
25
26
|
exports.CreatedByIdSchema = require_created_by.CreatedByIdSchema;
|
|
26
27
|
exports.CreatedBySchema = require_created_by.CreatedBySchema;
|
|
27
28
|
exports.CreatedTimeSchema = require_created_time.CreatedTimeSchema;
|
|
28
29
|
exports.DateObjectSchema = require_date.DateObjectSchema;
|
|
29
30
|
exports.EmailSchema = require_email.EmailSchema;
|
|
30
|
-
exports.
|
|
31
|
+
exports.FileSchema = require_files.FileSchema;
|
|
31
32
|
exports.FormulaSchema = require_formula.FormulaSchema;
|
|
32
33
|
exports.FullDateSchema = require_date.FullDateSchema;
|
|
33
34
|
exports.LastEditedByIdSchema = require_last_edited_by.LastEditedByIdSchema;
|
|
34
35
|
exports.LastEditedBySchema = require_last_edited_by.LastEditedBySchema;
|
|
35
36
|
exports.LastEditedTimeSchema = require_last_edited_time.LastEditedTimeSchema;
|
|
36
37
|
exports.MultiSelectSchema = require_multi_select.MultiSelectSchema;
|
|
38
|
+
exports.NullableBooleanFormulaSchema = require_formula.NullableBooleanFormulaSchema;
|
|
37
39
|
exports.NullableCreatedByNameSchema = require_created_by.NullableCreatedByNameSchema;
|
|
38
40
|
exports.NullableEmailSchema = require_email.NullableEmailSchema;
|
|
39
41
|
exports.NullableFullDateSchema = require_date.NullableFullDateSchema;
|
|
@@ -47,10 +49,11 @@ exports.NullableRollupDateSchema = require_rollup.NullableRollupDateSchema;
|
|
|
47
49
|
exports.NullableRollupNumberSchema = require_rollup.NullableRollupNumberSchema;
|
|
48
50
|
exports.NullableSelectSchema = require_select.NullableSelectSchema;
|
|
49
51
|
exports.NullableSingleDateSchema = require_date.NullableSingleDateSchema;
|
|
50
|
-
exports.NullableSingleFileSchema =
|
|
52
|
+
exports.NullableSingleFileSchema = require_files.NullableSingleFileSchema;
|
|
51
53
|
exports.NullableSingleRelationSchema = require_relation.NullableSingleRelationSchema;
|
|
52
54
|
exports.NullableSingleRollupArraySchema = require_rollup.NullableSingleRollupArraySchema;
|
|
53
55
|
exports.NullableStatusSchema = require_status.NullableStatusSchema;
|
|
56
|
+
exports.NullableStringFormulaSchema = require_formula.NullableStringFormulaSchema;
|
|
54
57
|
exports.NullableTitleSchema = require_text.NullableTitleSchema;
|
|
55
58
|
exports.NullableUniqueIdSchema = require_unique_id.NullableUniqueIdSchema;
|
|
56
59
|
exports.NullableUrlSchema = require_url.NullableUrlSchema;
|
|
@@ -67,12 +70,14 @@ exports.RichTextSchema = require_text.RichTextSchema;
|
|
|
67
70
|
exports.RollupArraySchema = require_rollup.RollupArraySchema;
|
|
68
71
|
exports.RollupDateSchema = require_rollup.RollupDateSchema;
|
|
69
72
|
exports.RollupNumberSchema = require_rollup.RollupNumberSchema;
|
|
73
|
+
exports.RollupSimpleSchema = require_rollup.RollupSimpleSchema;
|
|
70
74
|
exports.SelectSchema = require_select.SelectSchema;
|
|
71
75
|
exports.SingleDateSchema = require_date.SingleDateSchema;
|
|
72
|
-
exports.SingleFileSchema =
|
|
76
|
+
exports.SingleFileSchema = require_files.SingleFileSchema;
|
|
73
77
|
exports.SingleRelationSchema = require_relation.SingleRelationSchema;
|
|
74
78
|
exports.SingleRollupArraySchema = require_rollup.SingleRollupArraySchema;
|
|
75
79
|
exports.StatusSchema = require_status.StatusSchema;
|
|
80
|
+
exports.StringFormulaSchema = require_formula.StringFormulaSchema;
|
|
76
81
|
exports.TitleSchema = require_text.TitleSchema;
|
|
77
82
|
exports.UniqueIdNumberSchema = require_unique_id.UniqueIdNumberSchema;
|
|
78
83
|
exports.UrlSchema = require_url.UrlSchema;
|
package/dist/index.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import { CreatedByIdSchema, CreatedBySchema, NullableCreatedByNameSchema } from
|
|
|
3
3
|
import { CreatedTimeSchema } from "./created-time.cjs";
|
|
4
4
|
import { DateObjectSchema, FullDateSchema, NullableFullDateSchema, NullableRangeDateSchema, NullableSingleDateSchema, RangeDateSchema, SingleDateSchema } from "./date.cjs";
|
|
5
5
|
import { EmailSchema, NullableEmailSchema } from "./email.cjs";
|
|
6
|
-
import {
|
|
7
|
-
import { FormulaSchema } from "./formula.cjs";
|
|
6
|
+
import { FileSchema, NullableSingleFileSchema, SingleFileSchema } from "./files.cjs";
|
|
7
|
+
import { BooleanFormulaSchema, FormulaSchema, NullableBooleanFormulaSchema, NullableStringFormulaSchema, StringFormulaSchema } from "./formula.cjs";
|
|
8
8
|
import { LastEditedByIdSchema, LastEditedBySchema, NullableLastEditedByNameSchema } from "./last-edited-by.cjs";
|
|
9
9
|
import { LastEditedTimeSchema } from "./last-edited-time.cjs";
|
|
10
10
|
import { MultiSelectSchema } from "./multi-select.cjs";
|
|
@@ -13,11 +13,11 @@ import { PeopleIdSchema, PeopleSchema, PersonSchema } from "./people.cjs";
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.cjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.cjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.cjs";
|
|
16
|
-
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema } from "./rollup.cjs";
|
|
16
|
+
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.cjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.cjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.cjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.cjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.cjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.cjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.cjs";
|
|
23
|
-
export { CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema,
|
|
23
|
+
export { BooleanFormulaSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableRollupDateSchema, NullableRollupNumberSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, VerificationSchema };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import { CreatedByIdSchema, CreatedBySchema, NullableCreatedByNameSchema } from
|
|
|
3
3
|
import { CreatedTimeSchema } from "./created-time.mjs";
|
|
4
4
|
import { DateObjectSchema, FullDateSchema, NullableFullDateSchema, NullableRangeDateSchema, NullableSingleDateSchema, RangeDateSchema, SingleDateSchema } from "./date.mjs";
|
|
5
5
|
import { EmailSchema, NullableEmailSchema } from "./email.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { FormulaSchema } from "./formula.mjs";
|
|
6
|
+
import { FileSchema, NullableSingleFileSchema, SingleFileSchema } from "./files.mjs";
|
|
7
|
+
import { BooleanFormulaSchema, FormulaSchema, NullableBooleanFormulaSchema, NullableStringFormulaSchema, StringFormulaSchema } from "./formula.mjs";
|
|
8
8
|
import { LastEditedByIdSchema, LastEditedBySchema, NullableLastEditedByNameSchema } from "./last-edited-by.mjs";
|
|
9
9
|
import { LastEditedTimeSchema } from "./last-edited-time.mjs";
|
|
10
10
|
import { MultiSelectSchema } from "./multi-select.mjs";
|
|
@@ -13,11 +13,11 @@ import { PeopleIdSchema, PeopleSchema, PersonSchema } from "./people.mjs";
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.mjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.mjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.mjs";
|
|
16
|
-
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
16
|
+
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.mjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.mjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.mjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.mjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.mjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.mjs";
|
|
23
|
-
export { CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema,
|
|
23
|
+
export { BooleanFormulaSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableRollupDateSchema, NullableRollupNumberSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, VerificationSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import { CreatedByIdSchema, CreatedBySchema, NullableCreatedByNameSchema } from
|
|
|
4
4
|
import { CreatedTimeSchema } from "./created-time.mjs";
|
|
5
5
|
import { DateObjectSchema, FullDateSchema, NullableFullDateSchema, NullableRangeDateSchema, NullableSingleDateSchema, RangeDateSchema, SingleDateSchema } from "./date.mjs";
|
|
6
6
|
import { EmailSchema, NullableEmailSchema } from "./email.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import { FormulaSchema } from "./formula.mjs";
|
|
7
|
+
import { FileSchema, NullableSingleFileSchema, SingleFileSchema } from "./files.mjs";
|
|
8
|
+
import { BooleanFormulaSchema, FormulaSchema, NullableBooleanFormulaSchema, NullableStringFormulaSchema, StringFormulaSchema } from "./formula.mjs";
|
|
9
9
|
import { LastEditedByIdSchema, LastEditedBySchema, NullableLastEditedByNameSchema } from "./last-edited-by.mjs";
|
|
10
10
|
import { LastEditedTimeSchema } from "./last-edited-time.mjs";
|
|
11
11
|
import { MultiSelectSchema } from "./multi-select.mjs";
|
|
@@ -13,11 +13,11 @@ import { NullableNumberSchema, NumberSchema } from "./number.mjs";
|
|
|
13
13
|
import { NullablePhoneNumberSchema, PhoneNumberSchema } from "./phone-number.mjs";
|
|
14
14
|
import { NullablePlaceSchema, PlaceSchema } from "./place.mjs";
|
|
15
15
|
import { NullableSingleRelationSchema, RelationSchema, SingleRelationSchema } from "./relation.mjs";
|
|
16
|
-
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
16
|
+
import { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema } from "./rollup.mjs";
|
|
17
17
|
import { NullableSelectSchema, SelectSchema } from "./select.mjs";
|
|
18
18
|
import { NullableStatusSchema, StatusSchema } from "./status.mjs";
|
|
19
19
|
import { NullableRichTextSchema, NullableTitleSchema, RichTextSchema, TitleSchema } from "./text.mjs";
|
|
20
20
|
import { NullableUniqueIdSchema, UniqueIdNumberSchema } from "./unique-id.mjs";
|
|
21
21
|
import { NullableUrlSchema, UrlSchema } from "./url.mjs";
|
|
22
22
|
import { NullableVerificationSchema, VerificationSchema } from "./verification.mjs";
|
|
23
|
-
export { CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema,
|
|
23
|
+
export { BooleanFormulaSchema, CheckboxSchema, CreatedByIdSchema, CreatedBySchema, CreatedTimeSchema, DateObjectSchema, EmailSchema, FileSchema, FormulaSchema, FullDateSchema, LastEditedByIdSchema, LastEditedBySchema, LastEditedTimeSchema, MultiSelectSchema, NullableBooleanFormulaSchema, NullableCreatedByNameSchema, NullableEmailSchema, NullableFullDateSchema, NullableLastEditedByNameSchema, NullableNumberSchema, NullablePhoneNumberSchema, NullablePlaceSchema, NullableRangeDateSchema, NullableRichTextSchema, NullableRollupDateSchema, NullableRollupNumberSchema, NullableSelectSchema, NullableSingleDateSchema, NullableSingleFileSchema, NullableSingleRelationSchema, NullableSingleRollupArraySchema, NullableStatusSchema, NullableStringFormulaSchema, NullableTitleSchema, NullableUniqueIdSchema, NullableUrlSchema, NullableVerificationSchema, NumberSchema, PeopleIdSchema, PeopleSchema, PersonSchema, PhoneNumberSchema, PlaceSchema, RangeDateSchema, RelationSchema, RichTextSchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SelectSchema, SingleDateSchema, SingleFileSchema, SingleRelationSchema, SingleRollupArraySchema, StatusSchema, StringFormulaSchema, TitleSchema, UniqueIdNumberSchema, UrlSchema, VerificationSchema };
|
package/dist/rollup.cjs
CHANGED
|
@@ -4,6 +4,63 @@ let valibot = require("valibot");
|
|
|
4
4
|
valibot = require_runtime.__toESM(valibot, 1);
|
|
5
5
|
//#region src/rollup.ts
|
|
6
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
|
+
/**
|
|
7
64
|
* Schema to extract the `rollup` property with number type from a Notion page property or `null`.
|
|
8
65
|
*
|
|
9
66
|
* **Input:**
|
|
@@ -34,6 +91,8 @@ valibot = require_runtime.__toESM(valibot, 1);
|
|
|
34
91
|
* const parsed = v.parse(PageSchema, page);
|
|
35
92
|
* // parsed.properties.Sum: number | null
|
|
36
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
|
|
37
96
|
*/
|
|
38
97
|
const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
39
98
|
type: valibot.literal("number"),
|
|
@@ -70,6 +129,8 @@ const NullableRollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot
|
|
|
70
129
|
* const parsed = v.parse(PageSchema, page);
|
|
71
130
|
* // parsed.properties.Sum: number
|
|
72
131
|
* ```
|
|
132
|
+
*
|
|
133
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
|
|
73
134
|
*/
|
|
74
135
|
const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
75
136
|
type: valibot.literal("number"),
|
|
@@ -110,6 +171,8 @@ const RollupNumberSchema = valibot.pipe(valibot.object({ rollup: valibot.object(
|
|
|
110
171
|
* const parsed = v.parse(PageSchema, page);
|
|
111
172
|
* // parsed.properties.LatestDate: Date | null
|
|
112
173
|
* ```
|
|
174
|
+
*
|
|
175
|
+
* @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
|
|
113
176
|
*/
|
|
114
177
|
const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
115
178
|
type: valibot.literal("date"),
|
|
@@ -150,6 +213,8 @@ const NullableRollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.o
|
|
|
150
213
|
* const parsed = v.parse(PageSchema, page);
|
|
151
214
|
* // parsed.properties.LatestDate: Date
|
|
152
215
|
* ```
|
|
216
|
+
*
|
|
217
|
+
* @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
|
|
153
218
|
*/
|
|
154
219
|
const RollupDateSchema = valibot.pipe(valibot.object({ rollup: valibot.object({
|
|
155
220
|
type: valibot.literal("date"),
|
|
@@ -367,6 +432,7 @@ exports.NullableSingleRollupArraySchema = NullableSingleRollupArraySchema;
|
|
|
367
432
|
exports.RollupArraySchema = RollupArraySchema;
|
|
368
433
|
exports.RollupDateSchema = RollupDateSchema;
|
|
369
434
|
exports.RollupNumberSchema = RollupNumberSchema;
|
|
435
|
+
exports.RollupSimpleSchema = RollupSimpleSchema;
|
|
370
436
|
exports.SingleRollupArraySchema = SingleRollupArraySchema;
|
|
371
437
|
|
|
372
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,QAAQ;CACxB,QAAQA,QAAE,SAASA,QAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;CAChB,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMC,aAAAA;AACP,CAAC,EACF,CAAC,GACDD,QAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO;EAChB,MAAMA,QAAE,QAAQ,OAAO;EACvB,OAAOA,QAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACDA,QAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
|
|
1
|
+
{"version":3,"file":"rollup.cjs","names":["v","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
|