@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.
Files changed (101) hide show
  1. package/README.md +33 -10
  2. package/dist/_virtual/_rolldown/runtime.cjs +7 -13
  3. package/dist/checkbox.cjs +3 -4
  4. package/dist/checkbox.cjs.map +1 -1
  5. package/dist/checkbox.mjs +1 -2
  6. package/dist/checkbox.mjs.map +1 -1
  7. package/dist/created-by.cjs +4 -5
  8. package/dist/created-by.cjs.map +1 -1
  9. package/dist/created-by.mjs +1 -2
  10. package/dist/created-by.mjs.map +1 -1
  11. package/dist/created-time.cjs +3 -4
  12. package/dist/created-time.cjs.map +1 -1
  13. package/dist/created-time.mjs +1 -2
  14. package/dist/created-time.mjs.map +1 -1
  15. package/dist/date.cjs +3 -4
  16. package/dist/date.cjs.map +1 -1
  17. package/dist/date.mjs +1 -2
  18. package/dist/date.mjs.map +1 -1
  19. package/dist/email.cjs +3 -4
  20. package/dist/email.cjs.map +1 -1
  21. package/dist/email.mjs +1 -2
  22. package/dist/email.mjs.map +1 -1
  23. package/dist/files.cjs +123 -14
  24. package/dist/files.cjs.map +1 -1
  25. package/dist/files.d.cts +132 -4
  26. package/dist/files.d.mts +132 -4
  27. package/dist/files.mjs +119 -12
  28. package/dist/files.mjs.map +1 -1
  29. package/dist/formula.cjs +123 -23
  30. package/dist/formula.cjs.map +1 -1
  31. package/dist/formula.d.cts +150 -41
  32. package/dist/formula.d.mts +150 -41
  33. package/dist/formula.mjs +118 -22
  34. package/dist/formula.mjs.map +1 -1
  35. package/dist/index.cjs +32 -26
  36. package/dist/index.d.cts +4 -4
  37. package/dist/index.d.mts +4 -4
  38. package/dist/index.mjs +4 -5
  39. package/dist/last-edited-by.cjs +4 -5
  40. package/dist/last-edited-by.cjs.map +1 -1
  41. package/dist/last-edited-by.mjs +1 -2
  42. package/dist/last-edited-by.mjs.map +1 -1
  43. package/dist/last-edited-time.cjs +3 -4
  44. package/dist/last-edited-time.cjs.map +1 -1
  45. package/dist/last-edited-time.mjs +1 -2
  46. package/dist/last-edited-time.mjs.map +1 -1
  47. package/dist/multi-select.cjs +3 -4
  48. package/dist/multi-select.cjs.map +1 -1
  49. package/dist/multi-select.mjs +1 -2
  50. package/dist/multi-select.mjs.map +1 -1
  51. package/dist/number.cjs +3 -4
  52. package/dist/number.cjs.map +1 -1
  53. package/dist/number.mjs +1 -2
  54. package/dist/number.mjs.map +1 -1
  55. package/dist/people.cjs +3 -4
  56. package/dist/people.cjs.map +1 -1
  57. package/dist/people.mjs +1 -2
  58. package/dist/people.mjs.map +1 -1
  59. package/dist/phone-number.cjs +3 -4
  60. package/dist/phone-number.cjs.map +1 -1
  61. package/dist/phone-number.mjs +1 -2
  62. package/dist/phone-number.mjs.map +1 -1
  63. package/dist/place.cjs +3 -4
  64. package/dist/place.cjs.map +1 -1
  65. package/dist/place.mjs +1 -2
  66. package/dist/place.mjs.map +1 -1
  67. package/dist/relation.cjs +3 -4
  68. package/dist/relation.cjs.map +1 -1
  69. package/dist/relation.mjs +1 -2
  70. package/dist/relation.mjs.map +1 -1
  71. package/dist/rollup.cjs +70 -5
  72. package/dist/rollup.cjs.map +1 -1
  73. package/dist/rollup.d.cts +70 -1
  74. package/dist/rollup.d.mts +70 -1
  75. package/dist/rollup.mjs +67 -3
  76. package/dist/rollup.mjs.map +1 -1
  77. package/dist/select.cjs +3 -4
  78. package/dist/select.cjs.map +1 -1
  79. package/dist/select.mjs +1 -2
  80. package/dist/select.mjs.map +1 -1
  81. package/dist/status.cjs +3 -4
  82. package/dist/status.cjs.map +1 -1
  83. package/dist/status.mjs +1 -2
  84. package/dist/status.mjs.map +1 -1
  85. package/dist/text.cjs +3 -4
  86. package/dist/text.cjs.map +1 -1
  87. package/dist/text.mjs +1 -2
  88. package/dist/text.mjs.map +1 -1
  89. package/dist/unique-id.cjs +3 -4
  90. package/dist/unique-id.cjs.map +1 -1
  91. package/dist/unique-id.mjs +1 -2
  92. package/dist/unique-id.mjs.map +1 -1
  93. package/dist/url.cjs +3 -4
  94. package/dist/url.cjs.map +1 -1
  95. package/dist/url.mjs +1 -2
  96. package/dist/url.mjs.map +1 -1
  97. package/dist/verification.cjs +5 -6
  98. package/dist/verification.cjs.map +1 -1
  99. package/dist/verification.mjs +1 -2
  100. package/dist/verification.mjs.map +1 -1
  101. package/package.json +4 -4
package/dist/formula.cjs CHANGED
@@ -1,16 +1,13 @@
1
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
2
  let valibot = require("valibot");
3
- valibot = require_runtime.__toESM(valibot);
4
-
3
+ valibot = require_runtime.__toESM(valibot, 1);
5
4
  //#region src/formula.ts
6
5
  /**
7
6
  * Schema factory to extract the `formula` property result from a Notion page property.
8
7
  *
9
8
  * This is a generic schema factory that accepts another schema as a parameter,
10
- * allowing you to combine it with other schemas in this library to extract
11
- * typed formula results. The formula property in Notion can return different
12
- * types of values (string, number, boolean, or date) depending on the formula
13
- * configuration.
9
+ * allowing you to combine it with the formula, number, and date schemas in this library
10
+ * to extract typed formula results (e.g. string, number, boolean, or date formulas).
14
11
  *
15
12
  * **Input:**
16
13
  * ```
@@ -30,55 +27,158 @@ valibot = require_runtime.__toESM(valibot);
30
27
  * ```
31
28
  *
32
29
  * **Output:** The output type depends on the schema passed as a parameter.
33
- * For example, if `RichTextSchema` is passed, the output will be `string`.
30
+ * For example, if `StringFormulaSchema` is passed, the output will be `string`.
34
31
  *
35
- * @param schema - A schema that validates the formula result type.
36
- * Must accept one of: string, number, boolean, or date formula results.
32
+ * @param schema - A schema that validates the formula result object.
33
+ * Use the pre-built `*FormulaSchema` helpers for string and boolean,
34
+ * `NumberSchema` / `NullableNumberSchema` for number,
35
+ * or the date schemas from this library for date formulas.
37
36
  *
38
37
  * @example
39
38
  * ```ts
40
39
  * import * as v from "valibot";
41
- * import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
40
+ * import {
41
+ * BooleanFormulaSchema,
42
+ * FormulaSchema,
43
+ * NumberSchema,
44
+ * SingleDateSchema,
45
+ * StringFormulaSchema,
46
+ * } from "@nakanoaas/notion-valibot-schema";
42
47
  *
43
48
  * const PageSchema = v.object({
44
49
  * id: v.string(),
45
50
  * properties: v.object({
46
- * FormulaText: FormulaSchema(RichTextSchema),
51
+ * FormulaText: FormulaSchema(StringFormulaSchema),
52
+ * FormulaNumber: FormulaSchema(NumberSchema),
53
+ * FormulaBoolean: FormulaSchema(BooleanFormulaSchema),
54
+ * FormulaDate: FormulaSchema(SingleDateSchema),
47
55
  * }),
48
56
  * });
49
57
  *
50
58
  * const page = await notion.pages.retrieve({ page_id: "..." });
51
59
  * const parsed = v.parse(PageSchema, page);
52
60
  * // parsed.properties.FormulaText: string
61
+ * // parsed.properties.FormulaNumber: number
62
+ * // parsed.properties.FormulaBoolean: boolean
63
+ * // parsed.properties.FormulaDate: Date
53
64
  * ```
65
+ */
66
+ function FormulaSchema(schema) {
67
+ return valibot.pipe(valibot.object({ formula: schema }), valibot.transform((v) => v.formula));
68
+ }
69
+ /**
70
+ * Pre-built inner schema for a non-nullable string formula result.
71
+ *
72
+ * Validates `{ string: string }` and extracts the `string` value.
73
+ * Use with {@link FormulaSchema} when the formula is guaranteed to return a string.
74
+ *
75
+ * **Input:** `{ string: string }`
76
+ * **Output:** `string`
54
77
  *
55
78
  * @example
56
79
  * ```ts
57
80
  * import * as v from "valibot";
58
- * import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
81
+ * import { FormulaSchema, StringFormulaSchema } from "@nakanoaas/notion-valibot-schema";
59
82
  *
60
- * // Custom schema for number formula
61
- * const NumberFormulaSchema = v.object({
62
- * type: v.literal("number"),
63
- * number: v.nullable(v.number()),
83
+ * const PageSchema = v.object({
84
+ * id: v.string(),
85
+ * properties: v.object({
86
+ * MyFormula: FormulaSchema(StringFormulaSchema),
87
+ * }),
64
88
  * });
65
89
  *
90
+ * const page = await notion.pages.retrieve({ page_id: "..." });
91
+ * const parsed = v.parse(PageSchema, page);
92
+ * // parsed.properties.MyFormula: string
93
+ * ```
94
+ */
95
+ const StringFormulaSchema = valibot.pipe(valibot.object({ string: valibot.string() }), valibot.transform((v) => v.string));
96
+ /**
97
+ * Pre-built inner schema for a nullable string formula result.
98
+ *
99
+ * Validates `{ string: string | null }` and extracts the `string` value.
100
+ * Use with {@link FormulaSchema} when the string formula result may be null.
101
+ *
102
+ * **Input:** `{ string: string | null }`
103
+ * **Output:** `string | null`
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import * as v from "valibot";
108
+ * import { FormulaSchema, NullableStringFormulaSchema } from "@nakanoaas/notion-valibot-schema";
109
+ *
66
110
  * const PageSchema = v.object({
67
111
  * id: v.string(),
68
112
  * properties: v.object({
69
- * FormulaNumber: FormulaSchema(NumberFormulaSchema),
113
+ * MyFormula: FormulaSchema(NullableStringFormulaSchema),
70
114
  * }),
71
115
  * });
72
116
  *
73
117
  * const page = await notion.pages.retrieve({ page_id: "..." });
74
118
  * const parsed = v.parse(PageSchema, page);
75
- * // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
119
+ * // parsed.properties.MyFormula: string | null
76
120
  * ```
77
121
  */
78
- function FormulaSchema(schema) {
79
- return valibot.pipe(valibot.object({ formula: schema }), valibot.transform((v) => v.formula));
80
- }
81
-
122
+ const NullableStringFormulaSchema = valibot.pipe(valibot.object({ string: valibot.nullable(valibot.string()) }), valibot.transform((v) => v.string));
123
+ /**
124
+ * Pre-built inner schema for a non-nullable boolean formula result.
125
+ *
126
+ * Validates `{ boolean: boolean }` and extracts the `boolean` value.
127
+ * Use with {@link FormulaSchema} when the formula is guaranteed to return a boolean.
128
+ *
129
+ * **Input:** `{ boolean: boolean }`
130
+ * **Output:** `boolean`
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import * as v from "valibot";
135
+ * import { FormulaSchema, BooleanFormulaSchema } from "@nakanoaas/notion-valibot-schema";
136
+ *
137
+ * const PageSchema = v.object({
138
+ * id: v.string(),
139
+ * properties: v.object({
140
+ * MyFormula: FormulaSchema(BooleanFormulaSchema),
141
+ * }),
142
+ * });
143
+ *
144
+ * const page = await notion.pages.retrieve({ page_id: "..." });
145
+ * const parsed = v.parse(PageSchema, page);
146
+ * // parsed.properties.MyFormula: boolean
147
+ * ```
148
+ */
149
+ const BooleanFormulaSchema = valibot.pipe(valibot.object({ boolean: valibot.boolean() }), valibot.transform((v) => v.boolean));
150
+ /**
151
+ * Pre-built inner schema for a nullable boolean formula result.
152
+ *
153
+ * Validates `{ boolean: boolean | null }` and extracts the `boolean` value.
154
+ * Use with {@link FormulaSchema} when the boolean formula result may be null.
155
+ *
156
+ * **Input:** `{ boolean: boolean | null }`
157
+ * **Output:** `boolean | null`
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * import * as v from "valibot";
162
+ * import { FormulaSchema, NullableBooleanFormulaSchema } from "@nakanoaas/notion-valibot-schema";
163
+ *
164
+ * const PageSchema = v.object({
165
+ * id: v.string(),
166
+ * properties: v.object({
167
+ * MyFormula: FormulaSchema(NullableBooleanFormulaSchema),
168
+ * }),
169
+ * });
170
+ *
171
+ * const page = await notion.pages.retrieve({ page_id: "..." });
172
+ * const parsed = v.parse(PageSchema, page);
173
+ * // parsed.properties.MyFormula: boolean | null
174
+ * ```
175
+ */
176
+ const NullableBooleanFormulaSchema = valibot.pipe(valibot.object({ boolean: valibot.nullable(valibot.boolean()) }), valibot.transform((v) => v.boolean));
82
177
  //#endregion
178
+ exports.BooleanFormulaSchema = BooleanFormulaSchema;
83
179
  exports.FormulaSchema = FormulaSchema;
180
+ exports.NullableBooleanFormulaSchema = NullableBooleanFormulaSchema;
181
+ exports.NullableStringFormulaSchema = NullableStringFormulaSchema;
182
+ exports.StringFormulaSchema = StringFormulaSchema;
183
+
84
184
  //# sourceMappingURL=formula.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed formula results. The formula property in Notion can return different\n * types of values (string, number, boolean, or date) depending on the formula\n * configuration.\n *\n * **Input:**\n * ```\n * {\n * formula: {\n * type: \"string\" | \"number\" | \"boolean\" | \"date\";\n * string?: string | null;\n * number?: number | null;\n * boolean?: boolean | null;\n * date?: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `RichTextSchema` is passed, the output will be `string`.\n *\n * @param schema - A schema that validates the formula result type.\n * Must accept one of: string, number, boolean, or date formula results.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema, RichTextSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaText: FormulaSchema(RichTextSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaText: string\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FormulaSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for number formula\n * const NumberFormulaSchema = v.object({\n * type: v.literal(\"number\"),\n * number: v.nullable(v.number()),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * FormulaNumber: FormulaSchema(NumberFormulaSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.FormulaNumber: { type: \"number\"; number: number | null }\n * ```\n */\nexport function FormulaSchema<\n\tS extends v.GenericSchema<\n\t\t| { type: \"string\"; string: string | null }\n\t\t| { type: \"number\"; number: number | null }\n\t\t| { type: \"boolean\"; boolean: boolean | null }\n\t\t| {\n\t\t\t\ttype: \"date\";\n\t\t\t\tdate: {\n\t\t\t\t\tstart: string;\n\t\t\t\t\tend: string | null;\n\t\t\t\t\ttime_zone: string | null;\n\t\t\t\t} | null;\n\t\t },\n\t\tunknown\n\t>,\n>(schema: S) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\tformula: schema,\n\t\t}),\n\t\t// biome-ignore lint/style/noNonNullAssertion: valibot inference is not working correctly\n\t\tv.transform((v) => v.formula!),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EA,SAAgB,cAed,QAAW;AACZ,QAAOA,QAAE,KACRA,QAAE,OAAO,EACR,SAAS,QACT,CAAC,EAEFA,QAAE,WAAW,MAAM,EAAE,QAAS,CAC9B"}
1
+ {"version":3,"file":"formula.cjs","names":["v"],"sources":["../src/formula.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema factory to extract the `formula` property result from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with 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,OAAOA,QAAE,KACRA,QAAE,OAAO,EACR,SAAS,OACV,CAAC,GAEDA,QAAE,WAAW,MAAM,EAAE,OAAQ,CAC9B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,sBAAsBA,QAAE,KACpCA,QAAE,OAAO,EACR,QAAQA,QAAE,OAAO,EAClB,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,8BAA8BA,QAAE,KAC5CA,QAAE,OAAO,EACR,QAAQA,QAAE,SAASA,QAAE,OAAO,CAAC,EAC9B,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,uBAAuBA,QAAE,KACrCA,QAAE,OAAO,EACR,SAASA,QAAE,QAAQ,EACpB,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,+BAA+BA,QAAE,KAC7CA,QAAE,OAAO,EACR,SAASA,QAAE,SAASA,QAAE,QAAQ,CAAC,EAChC,CAAC,GACDA,QAAE,WAAW,MAAM,EAAE,OAAO,CAC7B"}
@@ -5,10 +5,8 @@ import * as v from "valibot";
5
5
  * Schema factory to extract the `formula` property result from a Notion page property.
6
6
  *
7
7
  * This is a generic schema factory that accepts another schema as a parameter,
8
- * allowing you to combine it with other schemas in this library to extract
9
- * typed formula results. The formula property in Notion can return different
10
- * types of values (string, number, boolean, or date) depending on the formula
11
- * configuration.
8
+ * allowing you to combine it with the formula, number, and date schemas in this library
9
+ * to extract typed formula results (e.g. string, number, boolean, or date formulas).
12
10
  *
13
11
  * **Input:**
14
12
  * ```
@@ -28,67 +26,54 @@ import * as v from "valibot";
28
26
  * ```
29
27
  *
30
28
  * **Output:** The output type depends on the schema passed as a parameter.
31
- * For example, if `RichTextSchema` is passed, the output will be `string`.
29
+ * For example, if `StringFormulaSchema` is passed, the output will be `string`.
32
30
  *
33
- * @param schema - A schema that validates the formula result type.
34
- * Must accept one of: string, number, boolean, or date formula results.
31
+ * @param schema - A schema that validates the formula result object.
32
+ * Use the pre-built `*FormulaSchema` helpers for string and boolean,
33
+ * `NumberSchema` / `NullableNumberSchema` for number,
34
+ * or the date schemas from this library for date formulas.
35
35
  *
36
36
  * @example
37
37
  * ```ts
38
38
  * import * as v from "valibot";
39
- * import { FormulaSchema, RichTextSchema } from "@nakanoaas/notion-valibot-utils";
39
+ * import {
40
+ * BooleanFormulaSchema,
41
+ * FormulaSchema,
42
+ * NumberSchema,
43
+ * SingleDateSchema,
44
+ * StringFormulaSchema,
45
+ * } from "@nakanoaas/notion-valibot-schema";
40
46
  *
41
47
  * const PageSchema = v.object({
42
48
  * id: v.string(),
43
49
  * properties: v.object({
44
- * FormulaText: FormulaSchema(RichTextSchema),
50
+ * FormulaText: FormulaSchema(StringFormulaSchema),
51
+ * FormulaNumber: FormulaSchema(NumberSchema),
52
+ * FormulaBoolean: FormulaSchema(BooleanFormulaSchema),
53
+ * FormulaDate: FormulaSchema(SingleDateSchema),
45
54
  * }),
46
55
  * });
47
56
  *
48
57
  * const page = await notion.pages.retrieve({ page_id: "..." });
49
58
  * const parsed = v.parse(PageSchema, page);
50
59
  * // parsed.properties.FormulaText: string
51
- * ```
52
- *
53
- * @example
54
- * ```ts
55
- * import * as v from "valibot";
56
- * import { FormulaSchema } from "@nakanoaas/notion-valibot-utils";
57
- *
58
- * // Custom schema for number formula
59
- * const NumberFormulaSchema = v.object({
60
- * type: v.literal("number"),
61
- * number: v.nullable(v.number()),
62
- * });
63
- *
64
- * const PageSchema = v.object({
65
- * id: v.string(),
66
- * properties: v.object({
67
- * FormulaNumber: FormulaSchema(NumberFormulaSchema),
68
- * }),
69
- * });
70
- *
71
- * const page = await notion.pages.retrieve({ page_id: "..." });
72
- * const parsed = v.parse(PageSchema, page);
73
- * // parsed.properties.FormulaNumber: { type: "number"; number: number | null }
60
+ * // parsed.properties.FormulaNumber: number
61
+ * // parsed.properties.FormulaBoolean: boolean
62
+ * // parsed.properties.FormulaDate: Date
74
63
  * ```
75
64
  */
76
65
  declare function FormulaSchema<S extends v.GenericSchema<{
77
- type: "string";
78
- string: string | null;
79
- } | {
80
- type: "number";
81
- number: number | null;
82
- } | {
83
- type: "boolean";
84
66
  boolean: boolean | null;
85
67
  } | {
86
- type: "date";
87
68
  date: {
88
69
  start: string;
89
70
  end: string | null;
90
71
  time_zone: string | null;
91
72
  } | null;
73
+ } | {
74
+ number: number | null;
75
+ } | {
76
+ string: string | null;
92
77
  }, unknown>>(schema: S): v.SchemaWithPipe<readonly [v.ObjectSchema<{
93
78
  readonly formula: S;
94
79
  }, undefined>, v.TransformAction<Readonly<{
@@ -116,6 +101,130 @@ declare function FormulaSchema<S extends v.GenericSchema<{
116
101
  }, S extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends S["default"] ? "formula" : never : never> & Partial<Pick<{
117
102
  formula: v.InferOutput<S>;
118
103
  }, S extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends S["default"] ? "formula" : never : never>>, Exclude<"formula", S extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "formula" : never : never> | Exclude<S extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends S["default"] ? "formula" : never : never, S extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "formula" : never : never> | Exclude<Exclude<"formula", S extends (v.ExactOptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, unknown>) | (v.ExactOptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.NullishSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown> | v.OptionalSchemaAsync<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, unknown>) ? undefined extends S["default"] ? "formula" : never : never>, S extends v.SchemaWithPipe<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> | v.SchemaWithPipeAsync<infer TPipe extends readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, ...v.PipeItem<any, unknown, v.BaseIssue<unknown>>[]] & readonly [v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> | v.BaseSchemaAsync<unknown, unknown, v.BaseIssue<unknown>>, ...(v.PipeItem<any, unknown, v.BaseIssue<unknown>> | v.PipeItemAsync<any, unknown, v.BaseIssue<unknown>>)[]]> ? v.ReadonlyAction<any> extends TPipe[number] ? "formula" : never : never>>)["formula"]>>]>;
104
+ /**
105
+ * Pre-built inner schema for a non-nullable string formula result.
106
+ *
107
+ * Validates `{ string: string }` and extracts the `string` value.
108
+ * Use with {@link FormulaSchema} when the formula is guaranteed to return a string.
109
+ *
110
+ * **Input:** `{ string: string }`
111
+ * **Output:** `string`
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import * as v from "valibot";
116
+ * import { FormulaSchema, StringFormulaSchema } from "@nakanoaas/notion-valibot-schema";
117
+ *
118
+ * const PageSchema = v.object({
119
+ * id: v.string(),
120
+ * properties: v.object({
121
+ * MyFormula: FormulaSchema(StringFormulaSchema),
122
+ * }),
123
+ * });
124
+ *
125
+ * const page = await notion.pages.retrieve({ page_id: "..." });
126
+ * const parsed = v.parse(PageSchema, page);
127
+ * // parsed.properties.MyFormula: string
128
+ * ```
129
+ */
130
+ declare const StringFormulaSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
131
+ readonly string: v.StringSchema<undefined>;
132
+ }, undefined>, v.TransformAction<{
133
+ string: string;
134
+ }, string>]>;
135
+ /**
136
+ * Pre-built inner schema for a nullable string formula result.
137
+ *
138
+ * Validates `{ string: string | null }` and extracts the `string` value.
139
+ * Use with {@link FormulaSchema} when the string formula result may be null.
140
+ *
141
+ * **Input:** `{ string: string | null }`
142
+ * **Output:** `string | null`
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import * as v from "valibot";
147
+ * import { FormulaSchema, NullableStringFormulaSchema } from "@nakanoaas/notion-valibot-schema";
148
+ *
149
+ * const PageSchema = v.object({
150
+ * id: v.string(),
151
+ * properties: v.object({
152
+ * MyFormula: FormulaSchema(NullableStringFormulaSchema),
153
+ * }),
154
+ * });
155
+ *
156
+ * const page = await notion.pages.retrieve({ page_id: "..." });
157
+ * const parsed = v.parse(PageSchema, page);
158
+ * // parsed.properties.MyFormula: string | null
159
+ * ```
160
+ */
161
+ declare const NullableStringFormulaSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
162
+ readonly string: v.NullableSchema<v.StringSchema<undefined>, undefined>;
163
+ }, undefined>, v.TransformAction<{
164
+ string: string | null;
165
+ }, string | null>]>;
166
+ /**
167
+ * Pre-built inner schema for a non-nullable boolean formula result.
168
+ *
169
+ * Validates `{ boolean: boolean }` and extracts the `boolean` value.
170
+ * Use with {@link FormulaSchema} when the formula is guaranteed to return a boolean.
171
+ *
172
+ * **Input:** `{ boolean: boolean }`
173
+ * **Output:** `boolean`
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * import * as v from "valibot";
178
+ * import { FormulaSchema, BooleanFormulaSchema } from "@nakanoaas/notion-valibot-schema";
179
+ *
180
+ * const PageSchema = v.object({
181
+ * id: v.string(),
182
+ * properties: v.object({
183
+ * MyFormula: FormulaSchema(BooleanFormulaSchema),
184
+ * }),
185
+ * });
186
+ *
187
+ * const page = await notion.pages.retrieve({ page_id: "..." });
188
+ * const parsed = v.parse(PageSchema, page);
189
+ * // parsed.properties.MyFormula: boolean
190
+ * ```
191
+ */
192
+ declare const BooleanFormulaSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
193
+ readonly boolean: v.BooleanSchema<undefined>;
194
+ }, undefined>, v.TransformAction<{
195
+ boolean: boolean;
196
+ }, boolean>]>;
197
+ /**
198
+ * Pre-built inner schema for a nullable boolean formula result.
199
+ *
200
+ * Validates `{ boolean: boolean | null }` and extracts the `boolean` value.
201
+ * Use with {@link FormulaSchema} when the boolean formula result may be null.
202
+ *
203
+ * **Input:** `{ boolean: boolean | null }`
204
+ * **Output:** `boolean | null`
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * import * as v from "valibot";
209
+ * import { FormulaSchema, NullableBooleanFormulaSchema } from "@nakanoaas/notion-valibot-schema";
210
+ *
211
+ * const PageSchema = v.object({
212
+ * id: v.string(),
213
+ * properties: v.object({
214
+ * MyFormula: FormulaSchema(NullableBooleanFormulaSchema),
215
+ * }),
216
+ * });
217
+ *
218
+ * const page = await notion.pages.retrieve({ page_id: "..." });
219
+ * const parsed = v.parse(PageSchema, page);
220
+ * // parsed.properties.MyFormula: boolean | null
221
+ * ```
222
+ */
223
+ declare const NullableBooleanFormulaSchema: v.SchemaWithPipe<readonly [v.ObjectSchema<{
224
+ readonly boolean: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
225
+ }, undefined>, v.TransformAction<{
226
+ boolean: boolean | null;
227
+ }, boolean | null>]>;
119
228
  //#endregion
120
- export { FormulaSchema };
229
+ export { BooleanFormulaSchema, FormulaSchema, NullableBooleanFormulaSchema, NullableStringFormulaSchema, StringFormulaSchema };
121
230
  //# sourceMappingURL=formula.d.cts.map