@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/dist/rollup.mjs CHANGED
@@ -2,6 +2,63 @@ import { DateObjectSchema } from "./date.mjs";
2
2
  import * as v from "valibot";
3
3
  //#region src/rollup.ts
4
4
  /**
5
+ * Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.
6
+ *
7
+ * This is a generic schema factory that accepts another schema as a parameter,
8
+ * allowing you to combine it with the number and date schemas in this library
9
+ * to extract typed rollup results (e.g. number or date rollups).
10
+ *
11
+ * **Input:**
12
+ * ```
13
+ * {
14
+ * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }
15
+ * }
16
+ * ```
17
+ *
18
+ * **Output:** The output type depends on the schema passed as a parameter.
19
+ * For example, if `NumberSchema` is passed, the output will be `number`.
20
+ *
21
+ * @param schema - A schema that validates the rollup value.
22
+ * Must accept an object with a `number` or `date` field.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import * as v from "valibot";
27
+ * import { RollupSimpleSchema, NumberSchema } from "@nakanoaas/notion-valibot-utils";
28
+ *
29
+ * const PageSchema = v.object({
30
+ * id: v.string(),
31
+ * properties: v.object({
32
+ * Sum: RollupSimpleSchema(NumberSchema),
33
+ * }),
34
+ * });
35
+ *
36
+ * const page = await notion.pages.retrieve({ page_id: "..." });
37
+ * const parsed = v.parse(PageSchema, page);
38
+ * // parsed.properties.Sum: number
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import * as v from "valibot";
44
+ * import { RollupSimpleSchema, SingleDateSchema } from "@nakanoaas/notion-valibot-utils";
45
+ *
46
+ * const PageSchema = v.object({
47
+ * id: v.string(),
48
+ * properties: v.object({
49
+ * LatestDate: RollupSimpleSchema(SingleDateSchema),
50
+ * }),
51
+ * });
52
+ *
53
+ * const page = await notion.pages.retrieve({ page_id: "..." });
54
+ * const parsed = v.parse(PageSchema, page);
55
+ * // parsed.properties.LatestDate: Date
56
+ * ```
57
+ */
58
+ function RollupSimpleSchema(schema) {
59
+ return v.pipe(v.object({ rollup: schema }), v.transform((v) => v.rollup));
60
+ }
61
+ /**
5
62
  * Schema to extract the `rollup` property with number type from a Notion page property or `null`.
6
63
  *
7
64
  * **Input:**
@@ -32,6 +89,8 @@ import * as v from "valibot";
32
89
  * const parsed = v.parse(PageSchema, page);
33
90
  * // parsed.properties.Sum: number | null
34
91
  * ```
92
+ *
93
+ * @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.
35
94
  */
36
95
  const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
37
96
  type: v.literal("number"),
@@ -68,6 +127,8 @@ const NullableRollupNumberSchema = v.pipe(v.object({ rollup: v.object({
68
127
  * const parsed = v.parse(PageSchema, page);
69
128
  * // parsed.properties.Sum: number
70
129
  * ```
130
+ *
131
+ * @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.
71
132
  */
72
133
  const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
73
134
  type: v.literal("number"),
@@ -108,6 +169,8 @@ const RollupNumberSchema = v.pipe(v.object({ rollup: v.object({
108
169
  * const parsed = v.parse(PageSchema, page);
109
170
  * // parsed.properties.LatestDate: Date | null
110
171
  * ```
172
+ *
173
+ * @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.
111
174
  */
112
175
  const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
113
176
  type: v.literal("date"),
@@ -148,6 +211,8 @@ const NullableRollupDateSchema = v.pipe(v.object({ rollup: v.object({
148
211
  * const parsed = v.parse(PageSchema, page);
149
212
  * // parsed.properties.LatestDate: Date
150
213
  * ```
214
+ *
215
+ * @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.
151
216
  */
152
217
  const RollupDateSchema = v.pipe(v.object({ rollup: v.object({
153
218
  type: v.literal("date"),
@@ -359,6 +424,6 @@ function NullableSingleRollupArraySchema(schema) {
359
424
  }) }), v.transform((v) => v.rollup.array[0] ?? null));
360
425
  }
361
426
  //#endregion
362
- export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, SingleRollupArraySchema };
427
+ export { NullableRollupDateSchema, NullableRollupNumberSchema, NullableSingleRollupArraySchema, RollupArraySchema, RollupDateSchema, RollupNumberSchema, RollupSimpleSchema, SingleRollupArraySchema };
363
428
 
364
429
  //# sourceMappingURL=rollup.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.mjs","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number | null;\n * };\n * }\n * ```\n *\n * **Output:** `number | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: NullableRollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number | null\n * ```\n */\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number;\n * };\n * }\n * ```\n *\n * **Output:** `number`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n */\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * };\n * }\n * ```\n *\n * **Output:** `Date | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: NullableRollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date | null\n * ```\n */\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * };\n * };\n * }\n * ```\n *\n * **Output:** `Date`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\n/**\n * Schema factory to extract the `rollup` property with array type from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6B,EAAE,KAC3C,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,qBAAqB,EAAE,KACnC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,SAAS,gBAAgB;AAClC,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM;AACP,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
1
+ {"version":3,"file":"rollup.mjs","names":[],"sources":["../src/rollup.ts"],"sourcesContent":["import * as v from \"valibot\";\n\nimport { DateObjectSchema } from \"./date\";\n\n/**\n * Schema factory to extract the `rollup` property with a simple (non-array) type from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with the number and date schemas in this library\n * to extract typed rollup results (e.g. number or date rollups).\n *\n * **Input:**\n * ```\n * {\n * rollup: InferInput<S>; // e.g. { number: number } or { date: { start: string; ... } }\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if `NumberSchema` is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the rollup value.\n * Must accept an object with a `number` or `date` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupSimpleSchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupSimpleSchema, SingleDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupSimpleSchema(SingleDateSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n */\nexport function RollupSimpleSchema<\n\tS extends v.GenericSchema<{ number: unknown } | { date: unknown }, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: v.InferInput<S>;\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: schema,\n\t\t}),\n\t\tv.transform((v) => v.rollup),\n\t) as v.GenericSchema<{ rollup: v.InferInput<S> }, v.InferOutput<S>>;\n}\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number | null;\n * };\n * }\n * ```\n *\n * **Output:** `number | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: NullableRollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableNumberSchema` instead: `RollupSimpleSchema(NullableNumberSchema)`.\n */\nexport const NullableRollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.nullable(v.number()),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with number type from a Notion page property.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"number\";\n * number: number;\n * };\n * }\n * ```\n *\n * **Output:** `number`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupNumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Sum: RollupNumberSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Sum: number\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NumberSchema` instead: `RollupSimpleSchema(NumberSchema)`.\n */\nexport const RollupNumberSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"number\"),\n\t\t\tnumber: v.number(),\n\t\t}),\n\t}),\n\tv.transform((v) => v.rollup.number),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object or `null`.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * } | null;\n * };\n * }\n * ```\n *\n * **Output:** `Date | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableRollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: NullableRollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date | null\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `NullableSingleDateSchema` instead: `RollupSimpleSchema(NullableSingleDateSchema)`.\n */\nexport const NullableRollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: v.nullable(DateObjectSchema),\n\t\t}),\n\t}),\n\tv.transform((v) => (v.rollup.date ? new Date(v.rollup.date.start) : null)),\n);\n\n/**\n * Schema to extract the `rollup` property with date type from a Notion page property and transform it to a `Date` object.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"date\";\n * date: {\n * start: string;\n * end: string | null;\n * time_zone: string | null;\n * };\n * };\n * }\n * ```\n *\n * **Output:** `Date`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupDateSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * LatestDate: RollupDateSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.LatestDate: Date\n * ```\n *\n * @deprecated Use {@link RollupSimpleSchema} with `SingleDateSchema` instead: `RollupSimpleSchema(SingleDateSchema)`.\n */\nexport const RollupDateSchema = v.pipe(\n\tv.object({\n\t\trollup: v.object({\n\t\t\ttype: v.literal(\"date\"),\n\t\t\tdate: DateObjectSchema,\n\t\t}),\n\t}),\n\tv.transform((v) => new Date(v.rollup.date.start)),\n);\n\n/**\n * Schema factory to extract the `rollup` property with array type from a Notion page property.\n *\n * This is a generic schema factory that accepts another schema as a parameter,\n * allowing you to combine it with other schemas in this library to extract\n * typed rollup array results. The rollup property in Notion can return an\n * array of different types of values depending on the rollup configuration.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<{ type: string; ... }>;\n * };\n * }\n * ```\n *\n * **Output:** The output type depends on the schema passed as a parameter.\n * For example, if a schema for number properties is passed, the output will be `Array<number>`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupNumbers: RollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupNumbers: number[]\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { RollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * // Custom schema for relation rollup\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * RollupRelations: RollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.RollupRelations: Array<{ type: \"relation\"; relation: Array<{ id: string }> }>\n * ```\n */\nexport function RollupArraySchema<S extends v.GenericSchema<object, unknown>>(\n\tschema: S,\n) {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type.\n *\n * This is similar to {@link RollupArraySchema} but expects exactly one element in the array\n * and returns that element directly instead of an array. Useful when the rollup is configured\n * to return a single value (e.g., `show_unique_values` with one relation).\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: [T]; // exactly one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter (single element, not array).\n * For example, if a schema for number properties is passed, the output will be `number`.\n *\n * @param schema - A schema that validates the single element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: SingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: SingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> }\n * ```\n */\nexport function SingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S>\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.tuple([schema]),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => v.rollup.array[0]),\n\t);\n}\n\n/**\n * Schema factory to extract the single element from the `rollup` property with array type, or `null` when the array is empty.\n *\n * This is similar to {@link SingleRollupArraySchema} but accepts empty arrays and returns `null` instead of requiring\n * exactly one element. Useful when the rollup may return zero or one value.\n *\n * **Input:**\n * ```\n * {\n * rollup: {\n * type: \"array\";\n * array: Array<T>; // zero or one element\n * };\n * }\n * ```\n *\n * **Output:** The output type of the schema passed as a parameter, or `null`.\n * For example, if a schema for number properties is passed, the output will be `number | null`.\n *\n * @param schema - A schema that validates each element in the rollup array.\n * Must accept an object with a `type` field.\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema, NumberSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRollupNumber: NullableSingleRollupArraySchema(NumberSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRollupNumber: number | null\n * ```\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleRollupArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const RelationItemSchema = v.object({\n * type: v.literal(\"relation\"),\n * relation: v.array(v.object({ id: v.string() })),\n * });\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * SingleRelation: NullableSingleRollupArraySchema(RelationItemSchema),\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.SingleRelation: { type: \"relation\"; relation: Array<{ id: string }> } | null\n * ```\n */\nexport function NullableSingleRollupArraySchema<\n\tS extends v.GenericSchema<object, unknown>,\n>(\n\tschema: S,\n): v.GenericSchema<\n\t{\n\t\trollup: {\n\t\t\ttype: \"array\";\n\t\t\tarray: v.InferInput<S>[];\n\t\t};\n\t},\n\tv.InferOutput<S> | null\n> {\n\treturn v.pipe(\n\t\tv.object({\n\t\t\trollup: v.object({\n\t\t\t\ttype: v.literal(\"array\"),\n\t\t\t\tarray: v.array(schema),\n\t\t\t}),\n\t\t}),\n\t\tv.transform((v) => (v.rollup.array[0] ?? null) as v.InferOutput<S> | null),\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAGf,QAMC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,OACT,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,MAAM,CAC5B;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,6BAA6B,EAAE,KAC3C,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;AAC9B,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,qBAAqB,EAAE,KACnC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,QAAQ;CACxB,QAAQ,EAAE,OAAO;AAClB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,CACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,SAAS,gBAAgB;AAClC,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,OAAO,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAK,CAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;CAChB,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM;AACP,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,IAAI,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC,CACjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,kBACf,QACC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,KAAK,CAClC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,wBAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC;CACxB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,EAAE,CACrC;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,SAAgB,gCAGf,QASC;CACD,OAAO,EAAE,KACR,EAAE,OAAO,EACR,QAAQ,EAAE,OAAO;EAChB,MAAM,EAAE,QAAQ,OAAO;EACvB,OAAO,EAAE,MAAM,MAAM;CACtB,CAAC,EACF,CAAC,GACD,EAAE,WAAW,MAAO,EAAE,OAAO,MAAM,MAAM,IAAgC,CAC1E;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakanoaas/notion-valibot-schema",
3
- "version": "0.3.0",
3
+ "version": "0.6.0",
4
4
  "description": "Turn Notion's nested API responses into clean, typed JavaScript values.",
5
5
  "author": "Nakano as a Service",
6
6
  "license": "MIT",
@@ -42,9 +42,9 @@
42
42
  "devDependencies": {
43
43
  "@biomejs/biome": "^2.3.7",
44
44
  "@notionhq/client": "^5.6.0",
45
- "@types/node": "^24.10.1",
45
+ "@types/node": "^25.9.2",
46
46
  "tsdown": "^0.22.2",
47
- "typescript": "^5.9.3",
47
+ "typescript": "^6.0.3",
48
48
  "vitest": "^4.0.16"
49
49
  },
50
50
  "scripts": {
package/dist/file.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.cjs","names":["v"],"sources":["../src/file.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FileArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileArraySchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FileArraySchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkBA,QAAE,QAAQ,QAAQ,CACzCA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,MAAM;CACtB,MAAMA,QAAE,OAAO,EACd,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,GACDA,QAAE,OAAO;CACR,MAAMA,QAAE,QAAQ,UAAU;CAC1B,UAAUA,QAAE,OAAO,EAClB,KAAKA,QAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,kBAAkBA,QAAE,KAChCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmBA,QAAE,KACjCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2BA,QAAE,KACzCA,QAAE,OAAO,EACR,OAAOA,QAAE,MAAM,eAAe,EAC/B,CAAC,GACDA,QAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}
package/dist/file.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"file.mjs","names":[],"sources":["../src/file.ts"],"sourcesContent":["import * as v from \"valibot\";\n\n/**\n * Schema for a Notion file object structure.\n *\n * **Input:**\n * ```\n * {\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }\n * ```\n *\n * @internal\n */\nconst InnerFileSchema = v.variant(\"type\", [\n\tv.object({\n\t\ttype: v.literal(\"file\"),\n\t\tfile: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n\tv.object({\n\t\ttype: v.literal(\"external\"),\n\t\texternal: v.object({\n\t\t\turl: v.string(),\n\t\t}),\n\t}),\n]);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to an array of URLs.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string[]`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { FileArraySchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Files: FileArraySchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Files: string[]\n * ```\n */\nexport const FileArraySchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) =>\n\t\tv.files.map((v) => (v.type === \"file\" ? v.file.url : v.external.url)),\n\t),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL.\n *\n * **Input:**\n * ```\n * {\n * files: [{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }];\n * }\n * ```\n *\n * **Output:** `string`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { SingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: SingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string\n * ```\n */\nexport const SingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.tuple([InnerFileSchema]),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n\n/**\n * Schema to extract the `files` property from a Notion page property and transform it to a single URL or `null`.\n *\n * **Input:**\n * ```\n * {\n * files: Array<{\n * type: \"file\";\n * file: {\n * url: string;\n * };\n * } | {\n * type: \"external\";\n * external: {\n * url: string;\n * };\n * }>;\n * }\n * ```\n *\n * **Output:** `string | null`\n *\n * @example\n * ```ts\n * import * as v from \"valibot\";\n * import { NullableSingleFileSchema } from \"@nakanoaas/notion-valibot-utils\";\n *\n * const PageSchema = v.object({\n * id: v.string(),\n * properties: v.object({\n * Attachment: NullableSingleFileSchema,\n * }),\n * });\n *\n * const page = await notion.pages.retrieve({ page_id: \"...\" });\n * const parsed = v.parse(PageSchema, page);\n * // parsed.properties.Attachment: string | null\n * ```\n */\nexport const NullableSingleFileSchema = v.pipe(\n\tv.object({\n\t\tfiles: v.array(InnerFileSchema),\n\t}),\n\tv.transform((v) => {\n\t\tconst file = v.files[0];\n\t\tif (!file) {\n\t\t\treturn null;\n\t\t}\n\t\treturn file.type === \"file\" ? file.file.url : file.external.url;\n\t}),\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAM,kBAAkB,EAAE,QAAQ,QAAQ,CACzC,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,MAAM;CACtB,MAAM,EAAE,OAAO,EACd,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,GACD,EAAE,OAAO;CACR,MAAM,EAAE,QAAQ,UAAU;CAC1B,UAAU,EAAE,OAAO,EAClB,KAAK,EAAE,OAAO,EACf,CAAC;AACF,CAAC,CACF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCD,MAAa,kBAAkB,EAAE,KAChC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MACZ,EAAE,MAAM,KAAK,MAAO,EAAE,SAAS,SAAS,EAAE,KAAK,MAAM,EAAE,SAAS,GAAI,CACrE,CACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,mBAAmB,EAAE,KACjC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,CAAC,eAAe,CAAC,EACjC,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,2BAA2B,EAAE,KACzC,EAAE,OAAO,EACR,OAAO,EAAE,MAAM,eAAe,EAC/B,CAAC,GACD,EAAE,WAAW,MAAM;CAClB,MAAM,OAAO,EAAE,MAAM;CACrB,IAAI,CAAC,MACJ,OAAO;CAER,OAAO,KAAK,SAAS,SAAS,KAAK,KAAK,MAAM,KAAK,SAAS;AAC7D,CAAC,CACF"}