@prismicio/client 7.21.2 → 7.21.3-pr.431.23cc5c6
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/iac/customType.cjs +54 -0
- package/dist/iac/customType.cjs.map +1 -0
- package/dist/iac/customType.d.cts +43 -0
- package/dist/iac/customType.d.cts.map +1 -0
- package/dist/iac/customType.d.ts +43 -0
- package/dist/iac/customType.d.ts.map +1 -0
- package/dist/iac/customType.js +53 -0
- package/dist/iac/customType.js.map +1 -0
- package/dist/iac/fields/boolean.cjs +38 -0
- package/dist/iac/fields/boolean.cjs.map +1 -0
- package/dist/iac/fields/boolean.d.cts +22 -0
- package/dist/iac/fields/boolean.d.cts.map +1 -0
- package/dist/iac/fields/boolean.d.ts +22 -0
- package/dist/iac/fields/boolean.d.ts.map +1 -0
- package/dist/iac/fields/boolean.js +38 -0
- package/dist/iac/fields/boolean.js.map +1 -0
- package/dist/iac/fields/color.cjs +29 -0
- package/dist/iac/fields/color.cjs.map +1 -0
- package/dist/iac/fields/color.d.cts +11 -0
- package/dist/iac/fields/color.d.cts.map +1 -0
- package/dist/iac/fields/color.d.ts +11 -0
- package/dist/iac/fields/color.d.ts.map +1 -0
- package/dist/iac/fields/color.js +29 -0
- package/dist/iac/fields/color.js.map +1 -0
- package/dist/iac/fields/contentRelationship.cjs +50 -0
- package/dist/iac/fields/contentRelationship.cjs.map +1 -0
- package/dist/iac/fields/contentRelationship.d.cts +23 -0
- package/dist/iac/fields/contentRelationship.d.cts.map +1 -0
- package/dist/iac/fields/contentRelationship.d.ts +23 -0
- package/dist/iac/fields/contentRelationship.d.ts.map +1 -0
- package/dist/iac/fields/contentRelationship.js +50 -0
- package/dist/iac/fields/contentRelationship.js.map +1 -0
- package/dist/iac/fields/date.cjs +29 -0
- package/dist/iac/fields/date.cjs.map +1 -0
- package/dist/iac/fields/date.d.cts +11 -0
- package/dist/iac/fields/date.d.cts.map +1 -0
- package/dist/iac/fields/date.d.ts +11 -0
- package/dist/iac/fields/date.d.ts.map +1 -0
- package/dist/iac/fields/date.js +29 -0
- package/dist/iac/fields/date.js.map +1 -0
- package/dist/iac/fields/embed.cjs +29 -0
- package/dist/iac/fields/embed.cjs.map +1 -0
- package/dist/iac/fields/embed.d.cts +11 -0
- package/dist/iac/fields/embed.d.cts.map +1 -0
- package/dist/iac/fields/embed.d.ts +11 -0
- package/dist/iac/fields/embed.d.ts.map +1 -0
- package/dist/iac/fields/embed.js +29 -0
- package/dist/iac/fields/embed.js.map +1 -0
- package/dist/iac/fields/geoPoint.cjs +26 -0
- package/dist/iac/fields/geoPoint.cjs.map +1 -0
- package/dist/iac/fields/geoPoint.d.cts +10 -0
- package/dist/iac/fields/geoPoint.d.cts.map +1 -0
- package/dist/iac/fields/geoPoint.d.ts +10 -0
- package/dist/iac/fields/geoPoint.d.ts.map +1 -0
- package/dist/iac/fields/geoPoint.js +26 -0
- package/dist/iac/fields/geoPoint.js.map +1 -0
- package/dist/iac/fields/group.cjs +38 -0
- package/dist/iac/fields/group.cjs.map +1 -0
- package/dist/iac/fields/group.d.cts +17 -0
- package/dist/iac/fields/group.d.cts.map +1 -0
- package/dist/iac/fields/group.d.ts +17 -0
- package/dist/iac/fields/group.d.ts.map +1 -0
- package/dist/iac/fields/group.js +38 -0
- package/dist/iac/fields/group.js.map +1 -0
- package/dist/iac/fields/image.cjs +48 -0
- package/dist/iac/fields/image.cjs.map +1 -0
- package/dist/iac/fields/image.d.cts +21 -0
- package/dist/iac/fields/image.d.cts.map +1 -0
- package/dist/iac/fields/image.d.ts +21 -0
- package/dist/iac/fields/image.d.ts.map +1 -0
- package/dist/iac/fields/image.js +48 -0
- package/dist/iac/fields/image.js.map +1 -0
- package/dist/iac/fields/integration.cjs +33 -0
- package/dist/iac/fields/integration.cjs.map +1 -0
- package/dist/iac/fields/integration.d.cts +15 -0
- package/dist/iac/fields/integration.d.cts.map +1 -0
- package/dist/iac/fields/integration.d.ts +15 -0
- package/dist/iac/fields/integration.d.ts.map +1 -0
- package/dist/iac/fields/integration.js +33 -0
- package/dist/iac/fields/integration.js.map +1 -0
- package/dist/iac/fields/link.cjs +45 -0
- package/dist/iac/fields/link.cjs.map +1 -0
- package/dist/iac/fields/link.d.cts +39 -0
- package/dist/iac/fields/link.d.cts.map +1 -0
- package/dist/iac/fields/link.d.ts +39 -0
- package/dist/iac/fields/link.d.ts.map +1 -0
- package/dist/iac/fields/link.js +45 -0
- package/dist/iac/fields/link.js.map +1 -0
- package/dist/iac/fields/linkToMedia.cjs +31 -0
- package/dist/iac/fields/linkToMedia.cjs.map +1 -0
- package/dist/iac/fields/linkToMedia.d.cts +11 -0
- package/dist/iac/fields/linkToMedia.d.cts.map +1 -0
- package/dist/iac/fields/linkToMedia.d.ts +11 -0
- package/dist/iac/fields/linkToMedia.d.ts.map +1 -0
- package/dist/iac/fields/linkToMedia.js +31 -0
- package/dist/iac/fields/linkToMedia.js.map +1 -0
- package/dist/iac/fields/number.cjs +29 -0
- package/dist/iac/fields/number.cjs.map +1 -0
- package/dist/iac/fields/number.d.cts +11 -0
- package/dist/iac/fields/number.d.cts.map +1 -0
- package/dist/iac/fields/number.d.ts +11 -0
- package/dist/iac/fields/number.d.ts.map +1 -0
- package/dist/iac/fields/number.js +29 -0
- package/dist/iac/fields/number.js.map +1 -0
- package/dist/iac/fields/richText.cjs +49 -0
- package/dist/iac/fields/richText.cjs.map +1 -0
- package/dist/iac/fields/richText.d.cts +33 -0
- package/dist/iac/fields/richText.d.cts.map +1 -0
- package/dist/iac/fields/richText.d.ts +33 -0
- package/dist/iac/fields/richText.d.ts.map +1 -0
- package/dist/iac/fields/richText.js +49 -0
- package/dist/iac/fields/richText.js.map +1 -0
- package/dist/iac/fields/select.cjs +46 -0
- package/dist/iac/fields/select.cjs.map +1 -0
- package/dist/iac/fields/select.d.cts +15 -0
- package/dist/iac/fields/select.d.cts.map +1 -0
- package/dist/iac/fields/select.d.ts +15 -0
- package/dist/iac/fields/select.d.ts.map +1 -0
- package/dist/iac/fields/select.js +46 -0
- package/dist/iac/fields/select.js.map +1 -0
- package/dist/iac/fields/sliceZone.cjs +37 -0
- package/dist/iac/fields/sliceZone.cjs.map +1 -0
- package/dist/iac/fields/sliceZone.d.cts +30 -0
- package/dist/iac/fields/sliceZone.d.cts.map +1 -0
- package/dist/iac/fields/sliceZone.d.ts +30 -0
- package/dist/iac/fields/sliceZone.d.ts.map +1 -0
- package/dist/iac/fields/sliceZone.js +37 -0
- package/dist/iac/fields/sliceZone.js.map +1 -0
- package/dist/iac/fields/table.cjs +26 -0
- package/dist/iac/fields/table.cjs.map +1 -0
- package/dist/iac/fields/table.d.cts +10 -0
- package/dist/iac/fields/table.d.cts.map +1 -0
- package/dist/iac/fields/table.d.ts +10 -0
- package/dist/iac/fields/table.d.ts.map +1 -0
- package/dist/iac/fields/table.js +26 -0
- package/dist/iac/fields/table.js.map +1 -0
- package/dist/iac/fields/text.cjs +29 -0
- package/dist/iac/fields/text.cjs.map +1 -0
- package/dist/iac/fields/text.d.cts +11 -0
- package/dist/iac/fields/text.d.cts.map +1 -0
- package/dist/iac/fields/text.d.ts +11 -0
- package/dist/iac/fields/text.d.ts.map +1 -0
- package/dist/iac/fields/text.js +29 -0
- package/dist/iac/fields/text.js.map +1 -0
- package/dist/iac/fields/timestamp.cjs +29 -0
- package/dist/iac/fields/timestamp.cjs.map +1 -0
- package/dist/iac/fields/timestamp.d.cts +11 -0
- package/dist/iac/fields/timestamp.d.cts.map +1 -0
- package/dist/iac/fields/timestamp.d.ts +11 -0
- package/dist/iac/fields/timestamp.d.ts.map +1 -0
- package/dist/iac/fields/timestamp.js +29 -0
- package/dist/iac/fields/timestamp.js.map +1 -0
- package/dist/iac/fields/uid.cjs +29 -0
- package/dist/iac/fields/uid.cjs.map +1 -0
- package/dist/iac/fields/uid.d.cts +11 -0
- package/dist/iac/fields/uid.d.cts.map +1 -0
- package/dist/iac/fields/uid.d.ts +11 -0
- package/dist/iac/fields/uid.d.ts.map +1 -0
- package/dist/iac/fields/uid.js +29 -0
- package/dist/iac/fields/uid.js.map +1 -0
- package/dist/iac/sharedSlice.cjs +54 -0
- package/dist/iac/sharedSlice.cjs.map +1 -0
- package/dist/iac/sharedSlice.d.cts +28 -0
- package/dist/iac/sharedSlice.d.cts.map +1 -0
- package/dist/iac/sharedSlice.d.ts +28 -0
- package/dist/iac/sharedSlice.d.ts.map +1 -0
- package/dist/iac/sharedSlice.js +54 -0
- package/dist/iac/sharedSlice.js.map +1 -0
- package/dist/iac/variation.cjs +45 -0
- package/dist/iac/variation.cjs.map +1 -0
- package/dist/iac/variation.d.cts +46 -0
- package/dist/iac/variation.d.cts.map +1 -0
- package/dist/iac/variation.d.ts +46 -0
- package/dist/iac/variation.d.ts.map +1 -0
- package/dist/iac/variation.js +44 -0
- package/dist/iac/variation.js.map +1 -0
- package/dist/iac.cjs +86 -0
- package/dist/iac.cjs.map +1 -0
- package/dist/iac.d.cts +109 -0
- package/dist/iac.d.cts.map +1 -0
- package/dist/iac.d.ts +110 -0
- package/dist/iac.d.ts.map +1 -0
- package/dist/iac.js +86 -0
- package/dist/iac.js.map +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/package.cjs +1 -1
- package/dist/package.cjs.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/dist/types/model/types.d.cts +2 -2
- package/dist/types/model/types.d.ts +2 -2
- package/package.json +9 -2
- package/src/iac/customType.ts +98 -0
- package/src/iac/fields/boolean.ts +55 -0
- package/src/iac/fields/color.ts +33 -0
- package/src/iac/fields/contentRelationship.ts +74 -0
- package/src/iac/fields/date.ts +33 -0
- package/src/iac/fields/embed.ts +33 -0
- package/src/iac/fields/geoPoint.ts +33 -0
- package/src/iac/fields/group.ts +58 -0
- package/src/iac/fields/image.ts +65 -0
- package/src/iac/fields/index.ts +62 -0
- package/src/iac/fields/integration.ts +43 -0
- package/src/iac/fields/link.ts +79 -0
- package/src/iac/fields/linkToMedia.ts +37 -0
- package/src/iac/fields/number.ts +35 -0
- package/src/iac/fields/richText.ts +84 -0
- package/src/iac/fields/select.ts +63 -0
- package/src/iac/fields/sliceZone.ts +82 -0
- package/src/iac/fields/table.ts +31 -0
- package/src/iac/fields/text.ts +33 -0
- package/src/iac/fields/timestamp.ts +35 -0
- package/src/iac/fields/uid.ts +33 -0
- package/src/iac/index.ts +122 -0
- package/src/iac/sharedSlice.ts +81 -0
- package/src/iac/variation.ts +107 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomTypeModelRichTextField,
|
|
3
|
+
CustomTypeModelRichTextMultiField,
|
|
4
|
+
CustomTypeModelRichTextSingleField,
|
|
5
|
+
} from "../../types/model/richText"
|
|
6
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for a rich text field.
|
|
10
|
+
*
|
|
11
|
+
* Use `single` for title-style fields (single block).
|
|
12
|
+
* Use `multi` for multi-block rich text content.
|
|
13
|
+
*/
|
|
14
|
+
export interface RichTextFieldConfig {
|
|
15
|
+
label?: string | null
|
|
16
|
+
placeholder?: string
|
|
17
|
+
allowTargetBlank?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* Allowed block types for single-block mode (title-style).
|
|
20
|
+
*
|
|
21
|
+
* @example "heading1"
|
|
22
|
+
* @example "heading1,heading2,heading3"
|
|
23
|
+
*/
|
|
24
|
+
single?: string
|
|
25
|
+
/**
|
|
26
|
+
* Allowed block types for multi-block mode.
|
|
27
|
+
*
|
|
28
|
+
* @example "paragraph,strong,em,hyperlink"
|
|
29
|
+
* @example "paragraph,heading1,heading2,strong,em,hyperlink,list-item,o-list-item"
|
|
30
|
+
*/
|
|
31
|
+
multi?: string
|
|
32
|
+
/**
|
|
33
|
+
* Custom labels for text styling.
|
|
34
|
+
*/
|
|
35
|
+
labels?: readonly string[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a rich text field model.
|
|
40
|
+
*
|
|
41
|
+
* Use the `single` config option for title-style fields (single block).
|
|
42
|
+
* Use the `multi` config option for multi-block rich text content.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Multi-block rich text (default)
|
|
48
|
+
* model.richText({ label: "Description", multi: "paragraph,strong,em" })
|
|
49
|
+
*
|
|
50
|
+
* // Single-block title-style
|
|
51
|
+
* model.richText({ label: "Heading", single: "heading1" })
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param config - Configuration for the field.
|
|
55
|
+
*
|
|
56
|
+
* @returns A rich text field model.
|
|
57
|
+
*/
|
|
58
|
+
export const richText = (
|
|
59
|
+
config?: RichTextFieldConfig,
|
|
60
|
+
): CustomTypeModelRichTextField => {
|
|
61
|
+
if (config?.single !== undefined) {
|
|
62
|
+
return {
|
|
63
|
+
type: CustomTypeModelFieldType.StructuredText,
|
|
64
|
+
config: {
|
|
65
|
+
label: config?.label ?? null,
|
|
66
|
+
placeholder: config?.placeholder,
|
|
67
|
+
allowTargetBlank: config?.allowTargetBlank,
|
|
68
|
+
single: config.single,
|
|
69
|
+
labels: config?.labels,
|
|
70
|
+
},
|
|
71
|
+
} satisfies CustomTypeModelRichTextSingleField
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
type: CustomTypeModelFieldType.StructuredText,
|
|
76
|
+
config: {
|
|
77
|
+
label: config?.label ?? null,
|
|
78
|
+
placeholder: config?.placeholder,
|
|
79
|
+
allowTargetBlank: config?.allowTargetBlank,
|
|
80
|
+
multi: config?.multi,
|
|
81
|
+
labels: config?.labels,
|
|
82
|
+
},
|
|
83
|
+
} satisfies CustomTypeModelRichTextMultiField
|
|
84
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CustomTypeModelSelectField } from "../../types/model/select"
|
|
2
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a select field.
|
|
6
|
+
*/
|
|
7
|
+
export interface SelectFieldConfig<
|
|
8
|
+
Option extends string,
|
|
9
|
+
DefaultValue extends Option = Option,
|
|
10
|
+
> {
|
|
11
|
+
label?: string | null
|
|
12
|
+
placeholder?: string
|
|
13
|
+
/**
|
|
14
|
+
* Default selected option.
|
|
15
|
+
*/
|
|
16
|
+
default_value?: DefaultValue
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a select field model.
|
|
21
|
+
*
|
|
22
|
+
* Options are passed as the first argument for better type inference.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* // Basic select
|
|
28
|
+
* model.select(["draft", "published", "archived"] as const, {
|
|
29
|
+
* label: "Status"
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* // With default value (type-safe)
|
|
33
|
+
* model.select(["small", "medium", "large"] as const, {
|
|
34
|
+
* label: "Size",
|
|
35
|
+
* default_value: "medium"
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @typeParam Option - Option value literals for type inference.
|
|
40
|
+
* @typeParam DefaultValue - Default value literal for type inference.
|
|
41
|
+
*
|
|
42
|
+
* @param options - Array of select options.
|
|
43
|
+
* @param config - Configuration for the field.
|
|
44
|
+
*
|
|
45
|
+
* @returns A select field model.
|
|
46
|
+
*/
|
|
47
|
+
export const select = <
|
|
48
|
+
Option extends string,
|
|
49
|
+
DefaultValue extends Option = Option,
|
|
50
|
+
>(
|
|
51
|
+
options: readonly Option[],
|
|
52
|
+
config?: SelectFieldConfig<Option, DefaultValue>,
|
|
53
|
+
): CustomTypeModelSelectField<Option, DefaultValue> => {
|
|
54
|
+
return {
|
|
55
|
+
type: CustomTypeModelFieldType.Select,
|
|
56
|
+
config: {
|
|
57
|
+
label: config?.label ?? null,
|
|
58
|
+
placeholder: config?.placeholder,
|
|
59
|
+
options,
|
|
60
|
+
default_value: config?.default_value,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomTypeModelSliceZoneField,
|
|
3
|
+
CustomTypeModelSliceLabel,
|
|
4
|
+
CustomTypeModelSharedSlice,
|
|
5
|
+
} from "../../types/model/sliceZone"
|
|
6
|
+
import type {
|
|
7
|
+
CustomTypeModelSlice,
|
|
8
|
+
CustomTypeModelLegacySlice,
|
|
9
|
+
} from "../../types/model/slice"
|
|
10
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for a slice zone field.
|
|
14
|
+
*/
|
|
15
|
+
export interface SliceZoneFieldConfig<
|
|
16
|
+
Slices extends Record<
|
|
17
|
+
string,
|
|
18
|
+
CustomTypeModelSlice | CustomTypeModelSharedSlice | CustomTypeModelLegacySlice
|
|
19
|
+
> = Record<
|
|
20
|
+
string,
|
|
21
|
+
CustomTypeModelSlice | CustomTypeModelSharedSlice | CustomTypeModelLegacySlice
|
|
22
|
+
>,
|
|
23
|
+
> {
|
|
24
|
+
/**
|
|
25
|
+
* Slice choices available in this slice zone.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* choices: {
|
|
31
|
+
* hero: { type: "SharedSlice" },
|
|
32
|
+
* text_block: { type: "SharedSlice" }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
choices?: Slices
|
|
37
|
+
/**
|
|
38
|
+
* Labels for slices.
|
|
39
|
+
*/
|
|
40
|
+
labels?: Record<string, readonly CustomTypeModelSliceLabel[]> | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Creates a slice zone field model.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* model.sliceZone({
|
|
50
|
+
* choices: {
|
|
51
|
+
* hero: { type: "SharedSlice" },
|
|
52
|
+
* text_block: { type: "SharedSlice" },
|
|
53
|
+
* image_gallery: { type: "SharedSlice" }
|
|
54
|
+
* }
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @typeParam Slices - Slice definitions for type inference.
|
|
59
|
+
*
|
|
60
|
+
* @param config - Configuration for the field.
|
|
61
|
+
*
|
|
62
|
+
* @returns A slice zone field model.
|
|
63
|
+
*/
|
|
64
|
+
export const sliceZone = <
|
|
65
|
+
Slices extends Record<
|
|
66
|
+
string,
|
|
67
|
+
CustomTypeModelSlice | CustomTypeModelSharedSlice | CustomTypeModelLegacySlice
|
|
68
|
+
> = Record<
|
|
69
|
+
string,
|
|
70
|
+
CustomTypeModelSlice | CustomTypeModelSharedSlice | CustomTypeModelLegacySlice
|
|
71
|
+
>,
|
|
72
|
+
>(
|
|
73
|
+
config?: SliceZoneFieldConfig<Slices>,
|
|
74
|
+
): CustomTypeModelSliceZoneField<Slices> => {
|
|
75
|
+
return {
|
|
76
|
+
type: CustomTypeModelFieldType.Slices,
|
|
77
|
+
config: {
|
|
78
|
+
choices: config?.choices,
|
|
79
|
+
labels: config?.labels,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CustomTypeModelTableField } from "../../types/model/table"
|
|
2
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a table field.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableFieldConfig {
|
|
8
|
+
label?: string | null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a table field model.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* model.table({ label: "Data Table" })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param config - Configuration for the field.
|
|
21
|
+
*
|
|
22
|
+
* @returns A table field model.
|
|
23
|
+
*/
|
|
24
|
+
export const table = (config?: TableFieldConfig): CustomTypeModelTableField => {
|
|
25
|
+
return {
|
|
26
|
+
type: CustomTypeModelFieldType.Table,
|
|
27
|
+
config: {
|
|
28
|
+
label: config?.label ?? null,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CustomTypeModelKeyTextField } from "../../types/model/keyText"
|
|
2
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a text field.
|
|
6
|
+
*/
|
|
7
|
+
export interface TextFieldConfig {
|
|
8
|
+
label?: string | null
|
|
9
|
+
placeholder?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a text field model (key text).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* model.text({ label: "Title" })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param config - Configuration for the field.
|
|
22
|
+
*
|
|
23
|
+
* @returns A text field model.
|
|
24
|
+
*/
|
|
25
|
+
export const text = (config?: TextFieldConfig): CustomTypeModelKeyTextField => {
|
|
26
|
+
return {
|
|
27
|
+
type: CustomTypeModelFieldType.Text,
|
|
28
|
+
config: {
|
|
29
|
+
label: config?.label ?? null,
|
|
30
|
+
placeholder: config?.placeholder,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CustomTypeModelTimestampField } from "../../types/model/timestamp"
|
|
2
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a timestamp field.
|
|
6
|
+
*/
|
|
7
|
+
export interface TimestampFieldConfig {
|
|
8
|
+
label?: string | null
|
|
9
|
+
placeholder?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a timestamp field model.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* model.timestamp({ label: "Event Time" })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param config - Configuration for the field.
|
|
22
|
+
*
|
|
23
|
+
* @returns A timestamp field model.
|
|
24
|
+
*/
|
|
25
|
+
export const timestamp = (
|
|
26
|
+
config?: TimestampFieldConfig,
|
|
27
|
+
): CustomTypeModelTimestampField => {
|
|
28
|
+
return {
|
|
29
|
+
type: CustomTypeModelFieldType.Timestamp,
|
|
30
|
+
config: {
|
|
31
|
+
label: config?.label ?? null,
|
|
32
|
+
placeholder: config?.placeholder,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CustomTypeModelUIDField } from "../../types/model/uid"
|
|
2
|
+
import { CustomTypeModelFieldType } from "../../types/model/types"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for a UID field.
|
|
6
|
+
*/
|
|
7
|
+
export interface UIDFieldConfig {
|
|
8
|
+
label?: string | null
|
|
9
|
+
placeholder?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Creates a UID field model.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* model.uid({ label: "UID" })
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param config - Configuration for the field.
|
|
22
|
+
*
|
|
23
|
+
* @returns A UID field model.
|
|
24
|
+
*/
|
|
25
|
+
export const uid = (config?: UIDFieldConfig): CustomTypeModelUIDField => {
|
|
26
|
+
return {
|
|
27
|
+
type: CustomTypeModelFieldType.UID,
|
|
28
|
+
config: {
|
|
29
|
+
label: config?.label ?? null,
|
|
30
|
+
placeholder: config?.placeholder,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/iac/index.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infrastructure as Code (IaC) factories for Prismic models.
|
|
3
|
+
*
|
|
4
|
+
* Provides type-safe factory functions to programmatically create
|
|
5
|
+
* Custom Types and Shared Slices.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { model } from "@prismicio/client/iac"
|
|
11
|
+
*
|
|
12
|
+
* const blogPost = model.customType({
|
|
13
|
+
* id: "blog_post",
|
|
14
|
+
* label: "Blog Post",
|
|
15
|
+
* repeatable: true,
|
|
16
|
+
* json: {
|
|
17
|
+
* Main: {
|
|
18
|
+
* uid: model.uid({ label: "UID" }),
|
|
19
|
+
* title: model.richText({ label: "Title", single: "heading1" }),
|
|
20
|
+
* body: model.sliceZone({
|
|
21
|
+
* choices: {
|
|
22
|
+
* hero: { type: "SharedSlice" }
|
|
23
|
+
* }
|
|
24
|
+
* })
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Field factories
|
|
32
|
+
import { boolean } from "./fields/boolean"
|
|
33
|
+
import { color } from "./fields/color"
|
|
34
|
+
import { date } from "./fields/date"
|
|
35
|
+
import { timestamp } from "./fields/timestamp"
|
|
36
|
+
import { number } from "./fields/number"
|
|
37
|
+
import { geoPoint } from "./fields/geoPoint"
|
|
38
|
+
import { embed } from "./fields/embed"
|
|
39
|
+
import { table } from "./fields/table"
|
|
40
|
+
import { text } from "./fields/text"
|
|
41
|
+
import { richText } from "./fields/richText"
|
|
42
|
+
import { image } from "./fields/image"
|
|
43
|
+
import { linkToMedia } from "./fields/linkToMedia"
|
|
44
|
+
import { link } from "./fields/link"
|
|
45
|
+
import { contentRelationship } from "./fields/contentRelationship"
|
|
46
|
+
import { select } from "./fields/select"
|
|
47
|
+
import { uid } from "./fields/uid"
|
|
48
|
+
import { integration } from "./fields/integration"
|
|
49
|
+
import { group } from "./fields/group"
|
|
50
|
+
import { sliceZone } from "./fields/sliceZone"
|
|
51
|
+
|
|
52
|
+
// Structure factories
|
|
53
|
+
import { customType } from "./customType"
|
|
54
|
+
import { sharedSlice } from "./sharedSlice"
|
|
55
|
+
import { variation } from "./variation"
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Model factory namespace.
|
|
59
|
+
*
|
|
60
|
+
* Contains all factory functions for creating Prismic model definitions.
|
|
61
|
+
*/
|
|
62
|
+
export const model = {
|
|
63
|
+
// Simple fields
|
|
64
|
+
boolean,
|
|
65
|
+
color,
|
|
66
|
+
date,
|
|
67
|
+
timestamp,
|
|
68
|
+
number,
|
|
69
|
+
geoPoint,
|
|
70
|
+
embed,
|
|
71
|
+
table,
|
|
72
|
+
|
|
73
|
+
// Text fields
|
|
74
|
+
text,
|
|
75
|
+
richText,
|
|
76
|
+
|
|
77
|
+
// Media fields
|
|
78
|
+
image,
|
|
79
|
+
linkToMedia,
|
|
80
|
+
|
|
81
|
+
// Link fields
|
|
82
|
+
link,
|
|
83
|
+
contentRelationship,
|
|
84
|
+
|
|
85
|
+
// Special fields
|
|
86
|
+
select,
|
|
87
|
+
uid,
|
|
88
|
+
integration,
|
|
89
|
+
|
|
90
|
+
// Structural fields
|
|
91
|
+
group,
|
|
92
|
+
sliceZone,
|
|
93
|
+
|
|
94
|
+
// Structure factories
|
|
95
|
+
customType,
|
|
96
|
+
sharedSlice,
|
|
97
|
+
variation,
|
|
98
|
+
} as const
|
|
99
|
+
|
|
100
|
+
// Re-export types for convenience
|
|
101
|
+
export type { BooleanFieldConfig } from "./fields/boolean"
|
|
102
|
+
export type { ColorFieldConfig } from "./fields/color"
|
|
103
|
+
export type { DateFieldConfig } from "./fields/date"
|
|
104
|
+
export type { TimestampFieldConfig } from "./fields/timestamp"
|
|
105
|
+
export type { NumberFieldConfig } from "./fields/number"
|
|
106
|
+
export type { GeoPointFieldConfig } from "./fields/geoPoint"
|
|
107
|
+
export type { EmbedFieldConfig } from "./fields/embed"
|
|
108
|
+
export type { TableFieldConfig } from "./fields/table"
|
|
109
|
+
export type { TextFieldConfig } from "./fields/text"
|
|
110
|
+
export type { RichTextFieldConfig } from "./fields/richText"
|
|
111
|
+
export type { ImageFieldConfig } from "./fields/image"
|
|
112
|
+
export type { LinkToMediaFieldConfig } from "./fields/linkToMedia"
|
|
113
|
+
export type { LinkFieldConfig } from "./fields/link"
|
|
114
|
+
export type { ContentRelationshipFieldConfig } from "./fields/contentRelationship"
|
|
115
|
+
export type { SelectFieldConfig } from "./fields/select"
|
|
116
|
+
export type { UIDFieldConfig } from "./fields/uid"
|
|
117
|
+
export type { IntegrationFieldConfig } from "./fields/integration"
|
|
118
|
+
export type { GroupFieldConfig } from "./fields/group"
|
|
119
|
+
export type { SliceZoneFieldConfig } from "./fields/sliceZone"
|
|
120
|
+
export type { CustomTypeConfig } from "./customType"
|
|
121
|
+
export type { SharedSliceConfig } from "./sharedSlice"
|
|
122
|
+
export type { VariationConfig } from "./variation"
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { SharedSliceModel } from "../types/model/sharedSlice"
|
|
2
|
+
import type { SharedSliceModelVariation } from "../types/model/sharedSliceVariation"
|
|
3
|
+
import { CustomTypeModelSliceType } from "../types/model/sliceZone"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for a shared slice.
|
|
7
|
+
*/
|
|
8
|
+
export interface SharedSliceConfig<
|
|
9
|
+
ID extends string = string,
|
|
10
|
+
Variation extends SharedSliceModelVariation = SharedSliceModelVariation,
|
|
11
|
+
> {
|
|
12
|
+
/**
|
|
13
|
+
* The API ID of the shared slice.
|
|
14
|
+
*/
|
|
15
|
+
id: ID
|
|
16
|
+
/**
|
|
17
|
+
* The human-readable name of the shared slice.
|
|
18
|
+
*/
|
|
19
|
+
name: string
|
|
20
|
+
/**
|
|
21
|
+
* Description of the shared slice.
|
|
22
|
+
*/
|
|
23
|
+
description?: string
|
|
24
|
+
/**
|
|
25
|
+
* Variations of the shared slice.
|
|
26
|
+
*/
|
|
27
|
+
variations: readonly Variation[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Creates a shared slice model.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const hero = model.sharedSlice({
|
|
37
|
+
* id: "hero",
|
|
38
|
+
* name: "Hero",
|
|
39
|
+
* description: "A hero banner with title and image",
|
|
40
|
+
* variations: [
|
|
41
|
+
* model.variation({
|
|
42
|
+
* id: "default",
|
|
43
|
+
* name: "Default",
|
|
44
|
+
* primary: {
|
|
45
|
+
* title: model.richText({ label: "Title", single: "heading1" }),
|
|
46
|
+
* image: model.image({ label: "Background Image" })
|
|
47
|
+
* }
|
|
48
|
+
* }),
|
|
49
|
+
* model.variation({
|
|
50
|
+
* id: "withVideo",
|
|
51
|
+
* name: "With Video",
|
|
52
|
+
* primary: {
|
|
53
|
+
* title: model.richText({ label: "Title", single: "heading1" }),
|
|
54
|
+
* video: model.embed({ label: "Video" })
|
|
55
|
+
* }
|
|
56
|
+
* })
|
|
57
|
+
* ]
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @typeParam ID - Slice ID literal for type inference.
|
|
62
|
+
* @typeParam Variation - Variation types for type inference.
|
|
63
|
+
*
|
|
64
|
+
* @param config - Configuration for the shared slice.
|
|
65
|
+
*
|
|
66
|
+
* @returns A shared slice model.
|
|
67
|
+
*/
|
|
68
|
+
export const sharedSlice = <
|
|
69
|
+
ID extends string,
|
|
70
|
+
Variation extends SharedSliceModelVariation,
|
|
71
|
+
>(
|
|
72
|
+
config: SharedSliceConfig<ID, Variation>,
|
|
73
|
+
): SharedSliceModel<ID, Variation> => {
|
|
74
|
+
return {
|
|
75
|
+
type: CustomTypeModelSliceType.SharedSlice,
|
|
76
|
+
id: config.id,
|
|
77
|
+
name: config.name,
|
|
78
|
+
description: config.description,
|
|
79
|
+
variations: config.variations,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { SharedSliceModelVariation } from "../types/model/sharedSliceVariation"
|
|
2
|
+
import type {
|
|
3
|
+
CustomTypeModelFieldForNestedGroup,
|
|
4
|
+
CustomTypeModelFieldForSlicePrimary,
|
|
5
|
+
} from "../types/model/types"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for a slice variation.
|
|
9
|
+
*/
|
|
10
|
+
export interface VariationConfig<
|
|
11
|
+
ID extends string = string,
|
|
12
|
+
PrimaryFields extends Record<
|
|
13
|
+
string,
|
|
14
|
+
CustomTypeModelFieldForSlicePrimary
|
|
15
|
+
> = Record<string, CustomTypeModelFieldForSlicePrimary>,
|
|
16
|
+
ItemFields extends Record<
|
|
17
|
+
string,
|
|
18
|
+
CustomTypeModelFieldForNestedGroup
|
|
19
|
+
> = Record<string, CustomTypeModelFieldForNestedGroup>,
|
|
20
|
+
> {
|
|
21
|
+
/**
|
|
22
|
+
* The API ID of the variation.
|
|
23
|
+
*/
|
|
24
|
+
id: ID
|
|
25
|
+
/**
|
|
26
|
+
* The human-readable name of the variation.
|
|
27
|
+
*/
|
|
28
|
+
name: string
|
|
29
|
+
/**
|
|
30
|
+
* Description of the variation.
|
|
31
|
+
*/
|
|
32
|
+
description?: string
|
|
33
|
+
/**
|
|
34
|
+
* Documentation URL for the variation.
|
|
35
|
+
*/
|
|
36
|
+
docURL?: string
|
|
37
|
+
/**
|
|
38
|
+
* Version of the variation.
|
|
39
|
+
*
|
|
40
|
+
* @defaultValue `"initial"`
|
|
41
|
+
*/
|
|
42
|
+
version?: string
|
|
43
|
+
/**
|
|
44
|
+
* Screenshot URL for the variation.
|
|
45
|
+
*/
|
|
46
|
+
imageUrl?: string
|
|
47
|
+
/**
|
|
48
|
+
* Non-repeatable fields (primary zone).
|
|
49
|
+
*/
|
|
50
|
+
primary?: PrimaryFields
|
|
51
|
+
/**
|
|
52
|
+
* Repeatable fields (items zone).
|
|
53
|
+
*/
|
|
54
|
+
items?: ItemFields
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a slice variation model.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* model.variation({
|
|
64
|
+
* id: "default",
|
|
65
|
+
* name: "Default",
|
|
66
|
+
* primary: {
|
|
67
|
+
* title: model.richText({ label: "Title", single: "heading1" }),
|
|
68
|
+
* description: model.richText({ label: "Description" })
|
|
69
|
+
* },
|
|
70
|
+
* items: {
|
|
71
|
+
* image: model.image({ label: "Image" })
|
|
72
|
+
* }
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @typeParam ID - Variation ID literal for type inference.
|
|
77
|
+
* @typeParam PrimaryFields - Primary fields definition for type inference.
|
|
78
|
+
* @typeParam ItemFields - Item fields definition for type inference.
|
|
79
|
+
*
|
|
80
|
+
* @param config - Configuration for the variation.
|
|
81
|
+
*
|
|
82
|
+
* @returns A slice variation model.
|
|
83
|
+
*/
|
|
84
|
+
export const variation = <
|
|
85
|
+
ID extends string,
|
|
86
|
+
PrimaryFields extends Record<
|
|
87
|
+
string,
|
|
88
|
+
CustomTypeModelFieldForSlicePrimary
|
|
89
|
+
> = Record<string, CustomTypeModelFieldForSlicePrimary>,
|
|
90
|
+
ItemFields extends Record<
|
|
91
|
+
string,
|
|
92
|
+
CustomTypeModelFieldForNestedGroup
|
|
93
|
+
> = Record<string, CustomTypeModelFieldForNestedGroup>,
|
|
94
|
+
>(
|
|
95
|
+
config: VariationConfig<ID, PrimaryFields, ItemFields>,
|
|
96
|
+
): SharedSliceModelVariation<ID, PrimaryFields, ItemFields> => {
|
|
97
|
+
return {
|
|
98
|
+
id: config.id,
|
|
99
|
+
name: config.name,
|
|
100
|
+
description: config.description ?? config.name,
|
|
101
|
+
docURL: config.docURL ?? "",
|
|
102
|
+
version: config.version ?? "initial",
|
|
103
|
+
imageUrl: config.imageUrl ?? "",
|
|
104
|
+
primary: config.primary,
|
|
105
|
+
items: config.items,
|
|
106
|
+
}
|
|
107
|
+
}
|