prismic-ts-codegen 0.1.11 → 0.1.13
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/_node_modules/quick-lru/index.cjs +234 -0
- package/dist/_node_modules/quick-lru/index.cjs.map +1 -0
- package/dist/_node_modules/quick-lru/index.js +235 -0
- package/dist/_node_modules/quick-lru/index.js.map +1 -0
- package/dist/constants.cjs +19 -21
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.ts +2 -3
- package/dist/constants.js +19 -21
- package/dist/constants.js.map +1 -1
- package/dist/generateTypes.cjs +71 -90
- package/dist/generateTypes.cjs.map +1 -1
- package/dist/generateTypes.d.ts +2 -1
- package/dist/generateTypes.js +71 -90
- package/dist/generateTypes.js.map +1 -1
- package/dist/lib/addBlankLine.cjs +12 -0
- package/dist/lib/addBlankLine.cjs.map +1 -0
- package/dist/lib/addBlankLine.d.ts +5 -0
- package/dist/lib/addBlankLine.js +12 -0
- package/dist/lib/addBlankLine.js.map +1 -0
- package/dist/lib/addLine.cjs +8 -0
- package/dist/lib/addLine.cjs.map +1 -0
- package/dist/lib/addLine.d.ts +1 -0
- package/dist/lib/addLine.js +8 -0
- package/dist/lib/addLine.js.map +1 -0
- package/dist/lib/addSection.cjs +8 -0
- package/dist/lib/addSection.cjs.map +1 -0
- package/dist/lib/addSection.d.ts +1 -0
- package/dist/lib/addSection.js +8 -0
- package/dist/lib/addSection.js.map +1 -0
- package/dist/lib/addTrailingNewLine.cjs +11 -0
- package/dist/lib/addTrailingNewLine.cjs.map +1 -0
- package/dist/lib/addTrailingNewLine.d.ts +5 -0
- package/dist/lib/addTrailingNewLine.js +11 -0
- package/dist/lib/addTrailingNewLine.js.map +1 -0
- package/dist/lib/buildCustomTypeDataType.cjs +51 -0
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeDataType.d.ts +13 -0
- package/dist/lib/buildCustomTypeDataType.js +51 -0
- package/dist/lib/buildCustomTypeDataType.js.map +1 -0
- package/dist/lib/buildCustomTypeType.cjs +60 -0
- package/dist/lib/buildCustomTypeType.cjs.map +1 -0
- package/dist/lib/buildCustomTypeType.d.ts +17 -0
- package/dist/lib/buildCustomTypeType.js +60 -0
- package/dist/lib/buildCustomTypeType.js.map +1 -0
- package/dist/lib/buildFieldDocs.cjs +67 -35
- package/dist/lib/buildFieldDocs.cjs.map +1 -1
- package/dist/lib/buildFieldDocs.d.ts +7 -11
- package/dist/lib/buildFieldDocs.js +67 -35
- package/dist/lib/buildFieldDocs.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +300 -0
- package/dist/lib/buildFieldProperties.cjs.map +1 -0
- package/dist/lib/buildFieldProperties.d.ts +14 -0
- package/dist/lib/buildFieldProperties.js +300 -0
- package/dist/lib/buildFieldProperties.js.map +1 -0
- package/dist/lib/buildSharedSliceType.cjs +140 -0
- package/dist/lib/buildSharedSliceType.cjs.map +1 -0
- package/dist/lib/buildSharedSliceType.d.ts +16 -0
- package/dist/lib/buildSharedSliceType.js +140 -0
- package/dist/lib/buildSharedSliceType.js.map +1 -0
- package/dist/lib/buildTypeName.cjs +4 -2
- package/dist/lib/buildTypeName.cjs.map +1 -1
- package/dist/lib/buildTypeName.js +4 -2
- package/dist/lib/buildTypeName.js.map +1 -1
- package/dist/lib/buildUnion.cjs +7 -0
- package/dist/lib/buildUnion.cjs.map +1 -0
- package/dist/lib/buildUnion.d.ts +1 -0
- package/dist/lib/buildUnion.js +7 -0
- package/dist/lib/buildUnion.js.map +1 -0
- package/dist/lib/checkHasUIDFIeld.cjs +7 -0
- package/dist/lib/checkHasUIDFIeld.cjs.map +1 -0
- package/dist/lib/checkHasUIDFIeld.d.ts +2 -0
- package/dist/lib/checkHasUIDFIeld.js +7 -0
- package/dist/lib/checkHasUIDFIeld.js.map +1 -0
- package/dist/lib/getAPIIDPath.cjs +18 -14
- package/dist/lib/getAPIIDPath.cjs.map +1 -1
- package/dist/lib/getAPIIDPath.d.ts +4 -8
- package/dist/lib/getAPIIDPath.js +18 -14
- package/dist/lib/getAPIIDPath.js.map +1 -1
- package/dist/lib/getCacheKey.cjs +25 -0
- package/dist/lib/getCacheKey.cjs.map +1 -0
- package/dist/lib/getCacheKey.d.ts +9 -0
- package/dist/lib/getCacheKey.js +8 -0
- package/dist/lib/getCacheKey.js.map +1 -0
- package/dist/lib/getHumanReadableModelName.cjs +13 -17
- package/dist/lib/getHumanReadableModelName.cjs.map +1 -1
- package/dist/lib/getHumanReadableModelName.d.ts +3 -3
- package/dist/lib/getHumanReadableModelName.js +13 -17
- package/dist/lib/getHumanReadableModelName.js.map +1 -1
- package/dist/lib/{getHumanReadableFieldPath.cjs → getHumanReadablePath.cjs} +8 -8
- package/dist/lib/getHumanReadablePath.cjs.map +1 -0
- package/dist/lib/getHumanReadablePath.d.ts +6 -0
- package/dist/lib/{getHumanReadableFieldPath.js → getHumanReadablePath.js} +8 -8
- package/dist/lib/getHumanReadablePath.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/package.json +18 -17
- package/src/constants.ts +19 -22
- package/src/generateTypes.ts +109 -108
- package/src/lib/addBlankLine.ts +13 -0
- package/src/lib/addLine.ts +5 -0
- package/src/lib/addSection.ts +5 -0
- package/src/lib/addTrailingNewLine.ts +14 -0
- package/src/lib/buildCustomTypeDataType.ts +74 -0
- package/src/lib/buildCustomTypeType.ts +101 -0
- package/src/lib/buildFieldDocs.ts +128 -68
- package/src/lib/buildFieldProperties.ts +513 -0
- package/src/lib/buildSharedSliceType.ts +213 -0
- package/src/lib/buildTypeName.ts +4 -2
- package/src/lib/buildUnion.ts +3 -0
- package/src/lib/checkHasUIDFIeld.ts +5 -0
- package/src/lib/getAPIIDPath.ts +40 -41
- package/src/lib/getCacheKey.ts +13 -0
- package/src/lib/getHumanReadableModelName.ts +23 -20
- package/src/lib/getHumanReadablePath.ts +24 -0
- package/src/types.ts +11 -1
- package/dist/lib/addInterfacePropertiesForFields.cjs +0 -489
- package/dist/lib/addInterfacePropertiesForFields.cjs.map +0 -1
- package/dist/lib/addInterfacePropertiesForFields.d.ts +0 -21
- package/dist/lib/addInterfacePropertiesForFields.js +0 -489
- package/dist/lib/addInterfacePropertiesForFields.js.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.cjs +0 -81
- package/dist/lib/addTypeAliasForCustomType.cjs.map +0 -1
- package/dist/lib/addTypeAliasForCustomType.d.ts +0 -11
- package/dist/lib/addTypeAliasForCustomType.js +0 -81
- package/dist/lib/addTypeAliasForCustomType.js.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.cjs +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.cjs.map +0 -1
- package/dist/lib/addTypeAliasForSharedSlice.d.ts +0 -10
- package/dist/lib/addTypeAliasForSharedSlice.js +0 -149
- package/dist/lib/addTypeAliasForSharedSlice.js.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.cjs.map +0 -1
- package/dist/lib/buildSharedSliceInterfaceNamePart.d.ts +0 -5
- package/dist/lib/buildSharedSliceInterfaceNamePart.js +0 -8
- package/dist/lib/buildSharedSliceInterfaceNamePart.js.map +0 -1
- package/dist/lib/getFieldDocumentationURL.cjs +0 -8
- package/dist/lib/getFieldDocumentationURL.cjs.map +0 -1
- package/dist/lib/getFieldDocumentationURL.d.ts +0 -6
- package/dist/lib/getFieldDocumentationURL.js +0 -8
- package/dist/lib/getFieldDocumentationURL.js.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldPath.d.ts +0 -10
- package/dist/lib/getHumanReadableFieldPath.js.map +0 -1
- package/dist/lib/getHumanReadableFieldType.cjs +0 -36
- package/dist/lib/getHumanReadableFieldType.cjs.map +0 -1
- package/dist/lib/getHumanReadableFieldType.d.ts +0 -6
- package/dist/lib/getHumanReadableFieldType.js +0 -36
- package/dist/lib/getHumanReadableFieldType.js.map +0 -1
- package/dist/lib/getSourceFileText.cjs +0 -9
- package/dist/lib/getSourceFileText.cjs.map +0 -1
- package/dist/lib/getSourceFileText.d.ts +0 -2
- package/dist/lib/getSourceFileText.js +0 -9
- package/dist/lib/getSourceFileText.js.map +0 -1
- package/dist/lib/hasOwnProperty.cjs +0 -7
- package/dist/lib/hasOwnProperty.cjs.map +0 -1
- package/dist/lib/hasOwnProperty.d.ts +0 -10
- package/dist/lib/hasOwnProperty.js +0 -7
- package/dist/lib/hasOwnProperty.js.map +0 -1
- package/dist/lib/isCustomTypeModel.cjs +0 -7
- package/dist/lib/isCustomTypeModel.cjs.map +0 -1
- package/dist/lib/isCustomTypeModel.d.ts +0 -2
- package/dist/lib/isCustomTypeModel.js +0 -7
- package/dist/lib/isCustomTypeModel.js.map +0 -1
- package/dist/lib/isCustomTypeModelField.cjs +0 -7
- package/dist/lib/isCustomTypeModelField.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelField.d.ts +0 -2
- package/dist/lib/isCustomTypeModelField.js +0 -7
- package/dist/lib/isCustomTypeModelField.js.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.cjs +0 -8
- package/dist/lib/isCustomTypeModelSlice.cjs.map +0 -1
- package/dist/lib/isCustomTypeModelSlice.d.ts +0 -2
- package/dist/lib/isCustomTypeModelSlice.js +0 -8
- package/dist/lib/isCustomTypeModelSlice.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -8
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -2
- package/dist/lib/isSharedSliceModel.js +0 -8
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -8
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -1
- package/dist/lib/pascalCase.js +0 -8
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/lib/writeFieldDocsDescription.cjs +0 -29
- package/dist/lib/writeFieldDocsDescription.cjs.map +0 -1
- package/dist/lib/writeFieldDocsDescription.d.ts +0 -13
- package/dist/lib/writeFieldDocsDescription.js +0 -29
- package/dist/lib/writeFieldDocsDescription.js.map +0 -1
- package/src/lib/addInterfacePropertiesForFields.ts +0 -665
- package/src/lib/addTypeAliasForCustomType.ts +0 -120
- package/src/lib/addTypeAliasForSharedSlice.ts +0 -201
- package/src/lib/buildSharedSliceInterfaceNamePart.ts +0 -11
- package/src/lib/getFieldDocumentationURL.ts +0 -15
- package/src/lib/getHumanReadableFieldPath.ts +0 -36
- package/src/lib/getHumanReadableFieldType.ts +0 -55
- package/src/lib/getSourceFileText.ts +0 -14
- package/src/lib/hasOwnProperty.ts +0 -15
- package/src/lib/isCustomTypeModel.ts +0 -5
- package/src/lib/isCustomTypeModelField.ts +0 -7
- package/src/lib/isCustomTypeModelSlice.ts +0 -14
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/pascalCase.ts +0 -9
- package/src/lib/writeFieldDocsDescription.ts +0 -51
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const prismic = require("@prismicio/client");
|
|
4
|
+
const commonTags = require("common-tags");
|
|
5
|
+
const addLine = require("./addLine.cjs");
|
|
6
|
+
const addSection = require("./addSection.cjs");
|
|
7
|
+
const buildFieldDocs = require("./buildFieldDocs.cjs");
|
|
8
|
+
const buildTypeName = require("./buildTypeName.cjs");
|
|
9
|
+
const buildUnion = require("./buildUnion.cjs");
|
|
10
|
+
const getHumanReadablePath = require("./getHumanReadablePath.cjs");
|
|
11
|
+
function buildFieldProperty(args) {
|
|
12
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
13
|
+
let code = buildFieldDocs.buildFieldDocs({
|
|
14
|
+
name: args.name,
|
|
15
|
+
field: args.field,
|
|
16
|
+
path: args.path,
|
|
17
|
+
tabName: args.tabName
|
|
18
|
+
});
|
|
19
|
+
const auxiliaryTypes = [];
|
|
20
|
+
const name = args.name.includes("-") || args.name.includes(":") || /^[0-9]/.test(args.name) ? `"${args.name}"` : args.name;
|
|
21
|
+
switch (args.field.type) {
|
|
22
|
+
case prismic.CustomTypeModelFieldType.UID: {
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case prismic.CustomTypeModelFieldType.Boolean: {
|
|
26
|
+
code = addLine.addLine(`${name}: prismic.BooleanField;`, code);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case prismic.CustomTypeModelFieldType.Color: {
|
|
30
|
+
code = addLine.addLine(`${name}: prismic.ColorField;`, code);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case prismic.CustomTypeModelFieldType.Date: {
|
|
34
|
+
code = addLine.addLine(`${name}: prismic.DateField;`, code);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case prismic.CustomTypeModelFieldType.Embed: {
|
|
38
|
+
const providerTypes = [];
|
|
39
|
+
if ((_a = args.fieldConfigs.embed) == null ? void 0 : _a.providerTypes) {
|
|
40
|
+
for (const providerType in (_b = args.fieldConfigs.embed) == null ? void 0 : _b.providerTypes) {
|
|
41
|
+
const configuredProviderType = (_c = args.fieldConfigs.embed) == null ? void 0 : _c.providerTypes[providerType];
|
|
42
|
+
providerTypes.push(`({ provider_name: "${providerType}" } & ${configuredProviderType})`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const providerTypesUnion = buildUnion.buildUnion(providerTypes);
|
|
46
|
+
code = providerTypes.length > 0 ? addLine.addLine(`${name}: prismic.EmbedField<prismic.AnyOEmbed & prismic.OEmbedExtra & (${providerTypesUnion})>`, code) : addLine.addLine(`${name}: prismic.EmbedField`, code);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case prismic.CustomTypeModelFieldType.GeoPoint: {
|
|
50
|
+
code = addLine.addLine(`${name}: prismic.GeoPointField;`, code);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case prismic.CustomTypeModelFieldType.Image: {
|
|
54
|
+
if (((_d = args.field.config) == null ? void 0 : _d.thumbnails) && args.field.config.thumbnails.length > 0) {
|
|
55
|
+
const thumbnailNames = buildUnion.buildUnion(args.field.config.thumbnails.map((thumb) => `"${thumb.name}"`));
|
|
56
|
+
code = addLine.addLine(`${name}: prismic.ImageField<${thumbnailNames}>;`, code);
|
|
57
|
+
} else {
|
|
58
|
+
code = addLine.addLine(`${name}: prismic.ImageField<never>;`, code);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case prismic.CustomTypeModelFieldType.Integration: {
|
|
63
|
+
const catalogType = ((_e = args.field.config) == null ? void 0 : _e.catalog) ? (_g = (_f = args.fieldConfigs.integrationFields) == null ? void 0 : _f.catalogTypes) == null ? void 0 : _g[args.field.config.catalog] : void 0;
|
|
64
|
+
if (catalogType) {
|
|
65
|
+
code = addLine.addLine(`${name}: prismic.IntegrationField<${catalogType}>;`, code);
|
|
66
|
+
} else {
|
|
67
|
+
code = addLine.addLine(`${name}: prismic.IntegrationField;`, code);
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case prismic.CustomTypeModelFieldType.Link: {
|
|
72
|
+
switch ((_h = args.field.config) == null ? void 0 : _h.select) {
|
|
73
|
+
case prismic.CustomTypeModelLinkSelectType.Document: {
|
|
74
|
+
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
|
|
75
|
+
const customTypeIDsUnion = buildUnion.buildUnion(args.field.config.customtypes.map((type) => `"${type}"`));
|
|
76
|
+
code = addLine.addLine(`${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`, code);
|
|
77
|
+
} else {
|
|
78
|
+
code = addLine.addLine(`${name}: prismic.ContentRelationshipField;`, code);
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case prismic.CustomTypeModelLinkSelectType.Media: {
|
|
83
|
+
code = addLine.addLine(`${name}: prismic.LinkToMediaField;`, code);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
default: {
|
|
87
|
+
code = addLine.addLine(`${name}: prismic.LinkField;`, code);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case prismic.CustomTypeModelFieldType.Number: {
|
|
93
|
+
code = addLine.addLine(`${name}: prismic.NumberField;`, code);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case prismic.CustomTypeModelFieldType.StructuredText: {
|
|
97
|
+
const isTitleField = args.field.config && "single" in args.field.config && args.field.config.single && args.field.config.single.split(",").every((blockType) => /heading/.test(blockType));
|
|
98
|
+
if (isTitleField) {
|
|
99
|
+
code = addLine.addLine(`${name}: prismic.TitleField;`, code);
|
|
100
|
+
} else {
|
|
101
|
+
code = addLine.addLine(`${name}: prismic.RichTextField;`, code);
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case prismic.CustomTypeModelFieldType.Select: {
|
|
106
|
+
const options = ((_j = (_i = args.field.config) == null ? void 0 : _i.options) == null ? void 0 : _j.map((option) => `"${option}"`)) || [];
|
|
107
|
+
const optionsType = options.length ? buildUnion.buildUnion(options) : "string";
|
|
108
|
+
const hasDefault = Boolean((_k = args.field.config) == null ? void 0 : _k.default_value);
|
|
109
|
+
if (hasDefault) {
|
|
110
|
+
code = addLine.addLine(`${name}: prismic.SelectField<${optionsType}, "filled">;`, code);
|
|
111
|
+
} else {
|
|
112
|
+
code = addLine.addLine(`${name}: prismic.SelectField${options.length > 0 ? `<${optionsType}>` : ""};`, code);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case prismic.CustomTypeModelFieldType.Text: {
|
|
117
|
+
code = addLine.addLine(`${name}: prismic.KeyTextField;`, code);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case prismic.CustomTypeModelFieldType.Timestamp: {
|
|
121
|
+
code = addLine.addLine(`${name}: prismic.TimestampField;`, code);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case prismic.CustomTypeModelFieldType.Group: {
|
|
125
|
+
const itemName = buildTypeName.buildTypeName(args.path[0].name, "Document", "Data", args.name, "Item");
|
|
126
|
+
const path = [
|
|
127
|
+
...args.path,
|
|
128
|
+
{
|
|
129
|
+
name,
|
|
130
|
+
model: args.field
|
|
131
|
+
}
|
|
132
|
+
];
|
|
133
|
+
const humanReadablePath = getHumanReadablePath.getHumanReadablePath({ path });
|
|
134
|
+
const itemFieldProperties = buildFieldProperties({
|
|
135
|
+
fields: ((_l = args.field.config) == null ? void 0 : _l.fields) || {},
|
|
136
|
+
fieldConfigs: args.fieldConfigs,
|
|
137
|
+
path
|
|
138
|
+
});
|
|
139
|
+
auxiliaryTypes.push({
|
|
140
|
+
name: itemName,
|
|
141
|
+
code: commonTags.source`
|
|
142
|
+
/**
|
|
143
|
+
* Item in *${humanReadablePath}*
|
|
144
|
+
*/
|
|
145
|
+
export interface ${itemName} {
|
|
146
|
+
${itemFieldProperties.code}
|
|
147
|
+
}
|
|
148
|
+
`
|
|
149
|
+
});
|
|
150
|
+
code = addLine.addLine(`${name}: prismic.GroupField<Simplify<${itemName}>>;`, code);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case prismic.CustomTypeModelFieldType.Slices: {
|
|
154
|
+
const choiceNames = [];
|
|
155
|
+
if ((_m = args.field.config) == null ? void 0 : _m.choices) {
|
|
156
|
+
for (const choiceID in args.field.config.choices) {
|
|
157
|
+
const choice = args.field.config.choices[choiceID];
|
|
158
|
+
if (choice.type === "SharedSlice") {
|
|
159
|
+
choiceNames.push(buildTypeName.buildTypeName(choiceID, "Slice"));
|
|
160
|
+
} else if (choice.type === "Slice") {
|
|
161
|
+
const sliceName = buildTypeName.buildTypeName(args.path[0].name, "Document", "Data", args.name, choiceID, "Slice");
|
|
162
|
+
let primaryInterfaceName;
|
|
163
|
+
if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
|
|
164
|
+
primaryInterfaceName = buildTypeName.buildTypeName(sliceName, "Primary");
|
|
165
|
+
const path = [
|
|
166
|
+
...args.path,
|
|
167
|
+
{
|
|
168
|
+
name: args.name,
|
|
169
|
+
model: args.field
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: choiceID,
|
|
173
|
+
model: choice
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "primary",
|
|
177
|
+
label: "Primary"
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
const humanReadablePath = getHumanReadablePath.getHumanReadablePath({ path });
|
|
181
|
+
const primaryFieldProperties = buildFieldProperties({
|
|
182
|
+
fields: choice["non-repeat"],
|
|
183
|
+
fieldConfigs: args.fieldConfigs,
|
|
184
|
+
path
|
|
185
|
+
});
|
|
186
|
+
let primaryCode = commonTags.stripIndent`
|
|
187
|
+
/**
|
|
188
|
+
* Primary content in *${humanReadablePath}*
|
|
189
|
+
*/
|
|
190
|
+
`;
|
|
191
|
+
primaryCode = primaryFieldProperties.code ? addLine.addLine(commonTags.source`
|
|
192
|
+
export interface ${primaryInterfaceName} {
|
|
193
|
+
${primaryFieldProperties.code}
|
|
194
|
+
}
|
|
195
|
+
`, primaryCode) : addLine.addLine(`export interface ${primaryInterfaceName} {}`, primaryCode);
|
|
196
|
+
auxiliaryTypes.push({
|
|
197
|
+
name: primaryInterfaceName,
|
|
198
|
+
code: primaryCode
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
let itemInterfaceName;
|
|
202
|
+
if (choice.repeat && Object.keys(choice.repeat).length > 0) {
|
|
203
|
+
itemInterfaceName = buildTypeName.buildTypeName(sliceName, "Item");
|
|
204
|
+
const path = [
|
|
205
|
+
...args.path,
|
|
206
|
+
{
|
|
207
|
+
name: args.name,
|
|
208
|
+
model: args.field
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: choiceID,
|
|
212
|
+
model: choice
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "items",
|
|
216
|
+
label: "Items"
|
|
217
|
+
}
|
|
218
|
+
];
|
|
219
|
+
const humanReadablePath = getHumanReadablePath.getHumanReadablePath({ path });
|
|
220
|
+
const itemFieldProperties = buildFieldProperties({
|
|
221
|
+
fields: choice.repeat,
|
|
222
|
+
fieldConfigs: args.fieldConfigs,
|
|
223
|
+
path
|
|
224
|
+
});
|
|
225
|
+
let itemCode = commonTags.stripIndent`
|
|
226
|
+
/**
|
|
227
|
+
* Item content in *${humanReadablePath}*
|
|
228
|
+
*/
|
|
229
|
+
`;
|
|
230
|
+
itemCode = itemFieldProperties.code ? addLine.addLine(commonTags.source`
|
|
231
|
+
export interface ${itemInterfaceName} {
|
|
232
|
+
${itemFieldProperties.code}
|
|
233
|
+
}
|
|
234
|
+
`, itemCode) : addLine.addLine(`export interface ${itemInterfaceName} {}`, itemCode);
|
|
235
|
+
auxiliaryTypes.push({
|
|
236
|
+
name: itemInterfaceName,
|
|
237
|
+
code: itemCode
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
auxiliaryTypes.push({
|
|
241
|
+
name: sliceName,
|
|
242
|
+
code: commonTags.stripIndent`
|
|
243
|
+
/**
|
|
244
|
+
* Slice for *${getHumanReadablePath.getHumanReadablePath({
|
|
245
|
+
path: [
|
|
246
|
+
...args.path,
|
|
247
|
+
{
|
|
248
|
+
name: args.name,
|
|
249
|
+
model: args.field
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
})}*
|
|
253
|
+
*/
|
|
254
|
+
export type ${sliceName} = prismic.Slice<"${choiceID}", ${primaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>
|
|
255
|
+
`
|
|
256
|
+
});
|
|
257
|
+
choiceNames.push(sliceName);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const choiceUnionName = buildTypeName.buildTypeName(args.path[0].name, "Document", "Data", args.name, "Slice");
|
|
262
|
+
const choiceUnion = buildUnion.buildUnion(choiceNames);
|
|
263
|
+
auxiliaryTypes.push({
|
|
264
|
+
name: choiceUnionName,
|
|
265
|
+
code: `type ${choiceUnionName} = ${choiceUnion}`
|
|
266
|
+
});
|
|
267
|
+
code = addLine.addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
default: {
|
|
271
|
+
code = addLine.addLine(`${name}: unknown;`, code);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
code,
|
|
276
|
+
auxiliaryTypes
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function buildFieldProperties(args) {
|
|
280
|
+
let code = "";
|
|
281
|
+
const auxiliaryTypes = [];
|
|
282
|
+
for (const name in args.fields) {
|
|
283
|
+
const field = args.fields[name];
|
|
284
|
+
const fieldProperty = buildFieldProperty({
|
|
285
|
+
name,
|
|
286
|
+
field,
|
|
287
|
+
path: args.path,
|
|
288
|
+
fieldConfigs: args.fieldConfigs,
|
|
289
|
+
tabName: args.tabName
|
|
290
|
+
});
|
|
291
|
+
code = addSection.addSection(fieldProperty.code, code);
|
|
292
|
+
auxiliaryTypes.push(...fieldProperty.auxiliaryTypes);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
code,
|
|
296
|
+
auxiliaryTypes
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
exports.buildFieldProperties = buildFieldProperties;
|
|
300
|
+
//# sourceMappingURL=buildFieldProperties.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildFieldProperties.cjs","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import {\n\tCustomTypeModelField,\n\tCustomTypeModelFieldType,\n\tCustomTypeModelLinkSelectType,\n} from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\n\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildFieldPropertyArgs = Pick<\n\tBuildFieldPropertiesArgs,\n\t\"path\" | \"fieldConfigs\" | \"tabName\"\n> & {\n\tname: string;\n\tfield: CustomTypeModelField;\n};\n\ntype BuildFieldPropertyReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nfunction buildFieldProperty(\n\targs: BuildFieldPropertyArgs,\n): BuildFieldPropertyReturnType {\n\tlet code = buildFieldDocs({\n\t\tname: args.name,\n\t\tfield: args.field,\n\t\tpath: args.path,\n\t\ttabName: args.tabName,\n\t});\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name =\n\t\targs.name.includes(\"-\") ||\n\t\targs.name.includes(\":\") ||\n\t\t/^[0-9]/.test(args.name)\n\t\t\t? `\"${args.name}\"`\n\t\t\t: args.name;\n\n\tswitch (args.field.type) {\n\t\tcase CustomTypeModelFieldType.UID: {\n\t\t\t// UID fields are not included in Data.\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Boolean: {\n\t\t\tcode = addLine(`${name}: prismic.BooleanField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Color: {\n\t\t\tcode = addLine(`${name}: prismic.ColorField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Date: {\n\t\t\tcode = addLine(`${name}: prismic.DateField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Embed: {\n\t\t\tconst providerTypes: string[] = [];\n\n\t\t\tif (args.fieldConfigs.embed?.providerTypes) {\n\t\t\t\tfor (const providerType in args.fieldConfigs.embed?.providerTypes) {\n\t\t\t\t\tconst configuredProviderType =\n\t\t\t\t\t\targs.fieldConfigs.embed?.providerTypes[providerType];\n\n\t\t\t\t\tproviderTypes.push(\n\t\t\t\t\t\t`({ provider_name: \"${providerType}\" } & ${configuredProviderType})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst providerTypesUnion = buildUnion(providerTypes);\n\n\t\t\tcode =\n\t\t\t\tproviderTypes.length > 0\n\t\t\t\t\t? addLine(\n\t\t\t\t\t\t\t`${name}: prismic.EmbedField<prismic.AnyOEmbed & prismic.OEmbedExtra & (${providerTypesUnion})>`,\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t )\n\t\t\t\t\t: addLine(`${name}: prismic.EmbedField`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.GeoPoint: {\n\t\t\tcode = addLine(`${name}: prismic.GeoPointField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Image: {\n\t\t\tif (\n\t\t\t\targs.field.config?.thumbnails &&\n\t\t\t\targs.field.config.thumbnails.length > 0\n\t\t\t) {\n\t\t\t\tconst thumbnailNames = buildUnion(\n\t\t\t\t\targs.field.config.thumbnails.map((thumb) => `\"${thumb.name}\"`),\n\t\t\t\t);\n\n\t\t\t\tcode = addLine(`${name}: prismic.ImageField<${thumbnailNames}>;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(`${name}: prismic.ImageField<never>;`, code);\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Integration: {\n\t\t\tconst catalogType = args.field.config?.catalog\n\t\t\t\t? args.fieldConfigs.integrationFields?.catalogTypes?.[\n\t\t\t\t\t\targs.field.config.catalog\n\t\t\t\t ]\n\t\t\t\t: undefined;\n\n\t\t\tif (catalogType) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.IntegrationField<${catalogType}>;`,\n\t\t\t\t\tcode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tcode = addLine(`${name}: prismic.IntegrationField;`, code);\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Link: {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase CustomTypeModelLinkSelectType.Document: {\n\t\t\t\t\tif (\n\t\t\t\t\t\t\"customtypes\" in args.field.config &&\n\t\t\t\t\t\targs.field.config.customtypes &&\n\t\t\t\t\t\targs.field.config.customtypes.length > 0\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst customTypeIDsUnion = buildUnion(\n\t\t\t\t\t\t\targs.field.config.customtypes.map((type) => `\"${type}\"`),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tcode = addLine(\n\t\t\t\t\t\t\t`${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`,\n\t\t\t\t\t\t\tcode,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcode = addLine(`${name}: prismic.ContentRelationshipField;`, code);\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase CustomTypeModelLinkSelectType.Media: {\n\t\t\t\t\tcode = addLine(`${name}: prismic.LinkToMediaField;`, code);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tcode = addLine(`${name}: prismic.LinkField;`, code);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Number: {\n\t\t\tcode = addLine(`${name}: prismic.NumberField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.StructuredText: {\n\t\t\tconst isTitleField =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"single\" in args.field.config &&\n\t\t\t\targs.field.config.single &&\n\t\t\t\targs.field.config.single\n\t\t\t\t\t.split(\",\")\n\t\t\t\t\t.every((blockType) => /heading/.test(blockType));\n\n\t\t\tif (isTitleField) {\n\t\t\t\tcode = addLine(`${name}: prismic.TitleField;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(`${name}: prismic.RichTextField;`, code);\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Select: {\n\t\t\tconst options: string[] =\n\t\t\t\targs.field.config?.options?.map((option) => `\"${option}\"`) || [];\n\t\t\tconst optionsType = options.length ? buildUnion(options) : \"string\";\n\n\t\t\tconst hasDefault = Boolean(args.field.config?.default_value);\n\n\t\t\tif (hasDefault) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.SelectField<${optionsType}, \"filled\">;`,\n\t\t\t\t\tcode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.SelectField${\n\t\t\t\t\t\toptions.length > 0 ? `<${optionsType}>` : \"\"\n\t\t\t\t\t};`,\n\t\t\t\t\tcode,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Text: {\n\t\t\tcode = addLine(`${name}: prismic.KeyTextField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Timestamp: {\n\t\t\tcode = addLine(`${name}: prismic.TimestampField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Group: {\n\t\t\tconst itemName = buildTypeName(\n\t\t\t\targs.path[0].name,\n\t\t\t\t\"Document\",\n\t\t\t\t\"Data\",\n\t\t\t\targs.name,\n\t\t\t\t\"Item\",\n\t\t\t);\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t...args.path,\n\t\t\t\t{\n\t\t\t\t\tname: name,\n\t\t\t\t\tmodel: args.field,\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\tconst itemFieldProperties = buildFieldProperties({\n\t\t\t\tfields: args.field.config?.fields || {},\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\n\t\t\tauxiliaryTypes.push({\n\t\t\t\tname: itemName,\n\t\t\t\tcode: source`\n\t\t\t\t\t/**\n\t\t\t\t\t * Item in *${humanReadablePath}*\n\t\t\t\t\t */\n\t\t\t\t\texport interface ${itemName} {\n\t\t\t\t\t\t${itemFieldProperties.code}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t});\n\n\t\t\tcode = addLine(\n\t\t\t\t`${name}: prismic.GroupField<Simplify<${itemName}>>;`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CustomTypeModelFieldType.Slices: {\n\t\t\tconst choiceNames: string[] = [];\n\n\t\t\tif (args.field.config?.choices) {\n\t\t\t\tfor (const choiceID in args.field.config.choices) {\n\t\t\t\t\tconst choice = args.field.config.choices[choiceID];\n\n\t\t\t\t\tif (choice.type === \"SharedSlice\") {\n\t\t\t\t\t\t// TODO: Verify that the Shared Slice\n\t\t\t\t\t\t// is provided to the global\n\t\t\t\t\t\t// `sharedSlices` array. If it is not,\n\t\t\t\t\t\t// the type won't exist, so we can't\n\t\t\t\t\t\t// add it to the union. We should\n\t\t\t\t\t\t// probably throw an error if we reach\n\t\t\t\t\t\t// that state, or maybe the input can\n\t\t\t\t\t\t// be validated early so we don't\n\t\t\t\t\t\t// generate any code using invalid\n\t\t\t\t\t\t// models.\n\t\t\t\t\t\tchoiceNames.push(buildTypeName(choiceID, \"Slice\"));\n\t\t\t\t\t} else if (choice.type === \"Slice\") {\n\t\t\t\t\t\tconst sliceName = buildTypeName(\n\t\t\t\t\t\t\targs.path[0].name,\n\t\t\t\t\t\t\t\"Document\",\n\t\t\t\t\t\t\t\"Data\",\n\t\t\t\t\t\t\targs.name,\n\t\t\t\t\t\t\tchoiceID,\n\t\t\t\t\t\t\t\"Slice\",\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tlet primaryInterfaceName: string | undefined;\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tchoice[\"non-repeat\"] &&\n\t\t\t\t\t\t\tObject.keys(choice[\"non-repeat\"]).length > 0\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tprimaryInterfaceName = buildTypeName(sliceName, \"Primary\");\n\n\t\t\t\t\t\t\tconst path: FieldPath = [\n\t\t\t\t\t\t\t\t...args.path,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: args.name,\n\t\t\t\t\t\t\t\t\tmodel: args.field,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: choiceID,\n\t\t\t\t\t\t\t\t\tmodel: choice,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: \"primary\",\n\t\t\t\t\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\t\t\t\t\tconst primaryFieldProperties = buildFieldProperties({\n\t\t\t\t\t\t\t\tfields: choice[\"non-repeat\"],\n\t\t\t\t\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tlet primaryCode = stripIndent`\n\t\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\t`;\n\t\t\t\t\t\t\tprimaryCode = primaryFieldProperties.code\n\t\t\t\t\t\t\t\t? addLine(\n\t\t\t\t\t\t\t\t\t\tsource`\n\t\t\t\t\t\t\t\t\t\t\texport interface ${primaryInterfaceName} {\n\t\t\t\t\t\t\t\t\t\t\t\t${primaryFieldProperties.code}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t`,\n\t\t\t\t\t\t\t\t\t\tprimaryCode,\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: addLine(\n\t\t\t\t\t\t\t\t\t\t`export interface ${primaryInterfaceName} {}`,\n\t\t\t\t\t\t\t\t\t\tprimaryCode,\n\t\t\t\t\t\t\t\t );\n\n\t\t\t\t\t\t\tauxiliaryTypes.push({\n\t\t\t\t\t\t\t\tname: primaryInterfaceName,\n\t\t\t\t\t\t\t\tcode: primaryCode,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet itemInterfaceName: string | undefined;\n\t\t\t\t\t\tif (choice.repeat && Object.keys(choice.repeat).length > 0) {\n\t\t\t\t\t\t\titemInterfaceName = buildTypeName(sliceName, \"Item\");\n\n\t\t\t\t\t\t\tconst path: FieldPath = [\n\t\t\t\t\t\t\t\t...args.path,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: args.name,\n\t\t\t\t\t\t\t\t\tmodel: args.field,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: choiceID,\n\t\t\t\t\t\t\t\t\tmodel: choice,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tname: \"items\",\n\t\t\t\t\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\t\t\t\t\tconst itemFieldProperties = buildFieldProperties({\n\t\t\t\t\t\t\t\tfields: choice.repeat,\n\t\t\t\t\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\tlet itemCode = stripIndent`\n\t\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t\t * Item content in *${humanReadablePath}*\n\t\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\t`;\n\t\t\t\t\t\t\titemCode = itemFieldProperties.code\n\t\t\t\t\t\t\t\t? addLine(\n\t\t\t\t\t\t\t\t\t\tsource`\n\t\t\t\t\t\t\t\t\t\t\texport interface ${itemInterfaceName} {\n\t\t\t\t\t\t\t\t\t\t\t\t${itemFieldProperties.code}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t`,\n\t\t\t\t\t\t\t\t\t\titemCode,\n\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t: addLine(`export interface ${itemInterfaceName} {}`, itemCode);\n\n\t\t\t\t\t\t\tauxiliaryTypes.push({\n\t\t\t\t\t\t\t\tname: itemInterfaceName,\n\t\t\t\t\t\t\t\tcode: itemCode,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tauxiliaryTypes.push({\n\t\t\t\t\t\t\tname: sliceName,\n\t\t\t\t\t\t\tcode: stripIndent`\n\t\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t\t * Slice for *${getHumanReadablePath({\n\t\t\t\t\t\t\t\t\t\tpath: [\n\t\t\t\t\t\t\t\t\t\t\t...args.path,\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tname: args.name,\n\t\t\t\t\t\t\t\t\t\t\t\tmodel: args.field,\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t})}*\n\t\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\t\texport type ${sliceName} = prismic.Slice<\"${choiceID}\", ${\n\t\t\t\t\t\t\t\tprimaryInterfaceName\n\t\t\t\t\t\t\t\t\t? `Simplify<${primaryInterfaceName}>`\n\t\t\t\t\t\t\t\t\t: `Record<string, never>`\n\t\t\t\t\t\t\t}, ${\n\t\t\t\t\t\t\t\titemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`\n\t\t\t\t\t\t\t}>\n\t\t\t\t\t\t\t`,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tchoiceNames.push(sliceName);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst choiceUnionName = buildTypeName(\n\t\t\t\targs.path[0].name,\n\t\t\t\t\"Document\",\n\t\t\t\t\"Data\",\n\t\t\t\targs.name,\n\t\t\t\t\"Slice\",\n\t\t\t);\n\t\t\tconst choiceUnion = buildUnion(choiceNames);\n\t\t\tauxiliaryTypes.push({\n\t\t\t\tname: choiceUnionName,\n\t\t\t\tcode: `type ${choiceUnionName} = ${choiceUnion}`,\n\t\t\t});\n\n\t\t\tcode = addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tcode = addLine(`${name}: unknown;`, code);\n\t\t}\n\t}\n\n\treturn {\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n\ntype BuildFieldPropertiesArgs = {\n\tfields: Record<string, CustomTypeModelField>;\n\tpath: FieldPath;\n\tfieldConfigs: FieldConfigs;\n\ttabName?: string;\n};\n\ntype BuildFieldPropertiesReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildFieldProperties(\n\targs: BuildFieldPropertiesArgs,\n): BuildFieldPropertiesReturnType {\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tfor (const name in args.fields) {\n\t\tconst field = args.fields[name];\n\n\t\tconst fieldProperty = buildFieldProperty({\n\t\t\tname,\n\t\t\tfield,\n\t\t\tpath: args.path,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\ttabName: args.tabName,\n\t\t});\n\n\t\tcode = addSection(fieldProperty.code, code);\n\n\t\tauxiliaryTypes.push(...fieldProperty.auxiliaryTypes);\n\t}\n\n\treturn {\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":["buildFieldDocs","CustomTypeModelFieldType","addLine","buildUnion","CustomTypeModelLinkSelectType","buildTypeName","getHumanReadablePath","source","stripIndent","addSection"],"mappings":";;;;;;;;;;AA6BA,SAAS,mBACR,MAA4B;;AAE5B,MAAI,OAAOA,eAAAA,eAAe;AAAA,IACzB,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,EAAA,CACd;AAED,QAAM,iBAAkC,CAAA;AAExC,QAAM,OACL,KAAK,KAAK,SAAS,GAAG,KACtB,KAAK,KAAK,SAAS,GAAG,KACtB,SAAS,KAAK,KAAK,IAAI,IACpB,IAAI,KAAK,UACT,KAAK;AAED,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAKC,QAAAA,yBAAyB,KAAK;AAElC;AAAA,IACA;AAAA,IAED,KAAKA,QAAAA,yBAAyB,SAAS;AAC/B,aAAAC,QAAA,QAAQ,GAAG,+BAA+B,IAAI;AAErD;AAAA,IACA;AAAA,IAED,KAAKD,QAAAA,yBAAyB,OAAO;AAC7B,aAAAC,QAAA,QAAQ,GAAG,6BAA6B,IAAI;AAEnD;AAAA,IACA;AAAA,IAED,KAAKD,QAAAA,yBAAyB,MAAM;AAC5B,aAAAC,QAAA,QAAQ,GAAG,4BAA4B,IAAI;AAElD;AAAA,IACA;AAAA,IAED,KAAKD,QAAAA,yBAAyB,OAAO;AACpC,YAAM,gBAA0B,CAAA;AAE5B,WAAA,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAC3C,mBAAW,iBAAgB,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAClE,gBAAM,0BACL,UAAK,aAAa,UAAlB,mBAAyB,cAAc;AAE1B,wBAAA,KACb,sBAAsB,qBAAqB,yBAAyB;AAAA,QAErE;AAAA,MACD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ACnC;AAED,aAAOD,QAAAA,QAAQ,GAAG,2BAA2B,qBAAqB,IAAI;AAEtE;AAAA,IACA;AAAA,IAED,SAAS;AACD,aAAAA,QAAA,QAAQ,GAAG,kBAAkB,IAAI;AAAA,IACxC;AAAA,EACD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;AAcM,SAAU,qBACf,MAA8B;AAE9B,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AAE7B,aAAA,QAAQ,KAAK,QAAQ;AACzB,UAAA,QAAQ,KAAK,OAAO,IAAI;AAE9B,UAAM,gBAAgB,mBAAmB;AAAA,MACxC;AAAA,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,IAAA,CACd;AAEM,WAAAO,WAAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAAA,EACnD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CustomTypeModelField } from "@prismicio/client";
|
|
2
|
+
import { AuxiliaryType, FieldConfigs, FieldPath } from "../types";
|
|
3
|
+
type BuildFieldPropertiesArgs = {
|
|
4
|
+
fields: Record<string, CustomTypeModelField>;
|
|
5
|
+
path: FieldPath;
|
|
6
|
+
fieldConfigs: FieldConfigs;
|
|
7
|
+
tabName?: string;
|
|
8
|
+
};
|
|
9
|
+
type BuildFieldPropertiesReturnType = {
|
|
10
|
+
code: string;
|
|
11
|
+
auxiliaryTypes: AuxiliaryType[];
|
|
12
|
+
};
|
|
13
|
+
export declare function buildFieldProperties(args: BuildFieldPropertiesArgs): BuildFieldPropertiesReturnType;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { CustomTypeModelFieldType, CustomTypeModelLinkSelectType } from "@prismicio/client";
|
|
2
|
+
import { stripIndent, source } from "common-tags";
|
|
3
|
+
import { addLine } from "./addLine.js";
|
|
4
|
+
import { addSection } from "./addSection.js";
|
|
5
|
+
import { buildFieldDocs } from "./buildFieldDocs.js";
|
|
6
|
+
import { buildTypeName } from "./buildTypeName.js";
|
|
7
|
+
import { buildUnion } from "./buildUnion.js";
|
|
8
|
+
import { getHumanReadablePath } from "./getHumanReadablePath.js";
|
|
9
|
+
function buildFieldProperty(args) {
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
11
|
+
let code = buildFieldDocs({
|
|
12
|
+
name: args.name,
|
|
13
|
+
field: args.field,
|
|
14
|
+
path: args.path,
|
|
15
|
+
tabName: args.tabName
|
|
16
|
+
});
|
|
17
|
+
const auxiliaryTypes = [];
|
|
18
|
+
const name = args.name.includes("-") || args.name.includes(":") || /^[0-9]/.test(args.name) ? `"${args.name}"` : args.name;
|
|
19
|
+
switch (args.field.type) {
|
|
20
|
+
case CustomTypeModelFieldType.UID: {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case CustomTypeModelFieldType.Boolean: {
|
|
24
|
+
code = addLine(`${name}: prismic.BooleanField;`, code);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case CustomTypeModelFieldType.Color: {
|
|
28
|
+
code = addLine(`${name}: prismic.ColorField;`, code);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
case CustomTypeModelFieldType.Date: {
|
|
32
|
+
code = addLine(`${name}: prismic.DateField;`, code);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case CustomTypeModelFieldType.Embed: {
|
|
36
|
+
const providerTypes = [];
|
|
37
|
+
if ((_a = args.fieldConfigs.embed) == null ? void 0 : _a.providerTypes) {
|
|
38
|
+
for (const providerType in (_b = args.fieldConfigs.embed) == null ? void 0 : _b.providerTypes) {
|
|
39
|
+
const configuredProviderType = (_c = args.fieldConfigs.embed) == null ? void 0 : _c.providerTypes[providerType];
|
|
40
|
+
providerTypes.push(`({ provider_name: "${providerType}" } & ${configuredProviderType})`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const providerTypesUnion = buildUnion(providerTypes);
|
|
44
|
+
code = providerTypes.length > 0 ? addLine(`${name}: prismic.EmbedField<prismic.AnyOEmbed & prismic.OEmbedExtra & (${providerTypesUnion})>`, code) : addLine(`${name}: prismic.EmbedField`, code);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case CustomTypeModelFieldType.GeoPoint: {
|
|
48
|
+
code = addLine(`${name}: prismic.GeoPointField;`, code);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case CustomTypeModelFieldType.Image: {
|
|
52
|
+
if (((_d = args.field.config) == null ? void 0 : _d.thumbnails) && args.field.config.thumbnails.length > 0) {
|
|
53
|
+
const thumbnailNames = buildUnion(args.field.config.thumbnails.map((thumb) => `"${thumb.name}"`));
|
|
54
|
+
code = addLine(`${name}: prismic.ImageField<${thumbnailNames}>;`, code);
|
|
55
|
+
} else {
|
|
56
|
+
code = addLine(`${name}: prismic.ImageField<never>;`, code);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case CustomTypeModelFieldType.Integration: {
|
|
61
|
+
const catalogType = ((_e = args.field.config) == null ? void 0 : _e.catalog) ? (_g = (_f = args.fieldConfigs.integrationFields) == null ? void 0 : _f.catalogTypes) == null ? void 0 : _g[args.field.config.catalog] : void 0;
|
|
62
|
+
if (catalogType) {
|
|
63
|
+
code = addLine(`${name}: prismic.IntegrationField<${catalogType}>;`, code);
|
|
64
|
+
} else {
|
|
65
|
+
code = addLine(`${name}: prismic.IntegrationField;`, code);
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case CustomTypeModelFieldType.Link: {
|
|
70
|
+
switch ((_h = args.field.config) == null ? void 0 : _h.select) {
|
|
71
|
+
case CustomTypeModelLinkSelectType.Document: {
|
|
72
|
+
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
|
|
73
|
+
const customTypeIDsUnion = buildUnion(args.field.config.customtypes.map((type) => `"${type}"`));
|
|
74
|
+
code = addLine(`${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`, code);
|
|
75
|
+
} else {
|
|
76
|
+
code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case CustomTypeModelLinkSelectType.Media: {
|
|
81
|
+
code = addLine(`${name}: prismic.LinkToMediaField;`, code);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
default: {
|
|
85
|
+
code = addLine(`${name}: prismic.LinkField;`, code);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case CustomTypeModelFieldType.Number: {
|
|
91
|
+
code = addLine(`${name}: prismic.NumberField;`, code);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case CustomTypeModelFieldType.StructuredText: {
|
|
95
|
+
const isTitleField = args.field.config && "single" in args.field.config && args.field.config.single && args.field.config.single.split(",").every((blockType) => /heading/.test(blockType));
|
|
96
|
+
if (isTitleField) {
|
|
97
|
+
code = addLine(`${name}: prismic.TitleField;`, code);
|
|
98
|
+
} else {
|
|
99
|
+
code = addLine(`${name}: prismic.RichTextField;`, code);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case CustomTypeModelFieldType.Select: {
|
|
104
|
+
const options = ((_j = (_i = args.field.config) == null ? void 0 : _i.options) == null ? void 0 : _j.map((option) => `"${option}"`)) || [];
|
|
105
|
+
const optionsType = options.length ? buildUnion(options) : "string";
|
|
106
|
+
const hasDefault = Boolean((_k = args.field.config) == null ? void 0 : _k.default_value);
|
|
107
|
+
if (hasDefault) {
|
|
108
|
+
code = addLine(`${name}: prismic.SelectField<${optionsType}, "filled">;`, code);
|
|
109
|
+
} else {
|
|
110
|
+
code = addLine(`${name}: prismic.SelectField${options.length > 0 ? `<${optionsType}>` : ""};`, code);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case CustomTypeModelFieldType.Text: {
|
|
115
|
+
code = addLine(`${name}: prismic.KeyTextField;`, code);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case CustomTypeModelFieldType.Timestamp: {
|
|
119
|
+
code = addLine(`${name}: prismic.TimestampField;`, code);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case CustomTypeModelFieldType.Group: {
|
|
123
|
+
const itemName = buildTypeName(args.path[0].name, "Document", "Data", args.name, "Item");
|
|
124
|
+
const path = [
|
|
125
|
+
...args.path,
|
|
126
|
+
{
|
|
127
|
+
name,
|
|
128
|
+
model: args.field
|
|
129
|
+
}
|
|
130
|
+
];
|
|
131
|
+
const humanReadablePath = getHumanReadablePath({ path });
|
|
132
|
+
const itemFieldProperties = buildFieldProperties({
|
|
133
|
+
fields: ((_l = args.field.config) == null ? void 0 : _l.fields) || {},
|
|
134
|
+
fieldConfigs: args.fieldConfigs,
|
|
135
|
+
path
|
|
136
|
+
});
|
|
137
|
+
auxiliaryTypes.push({
|
|
138
|
+
name: itemName,
|
|
139
|
+
code: source`
|
|
140
|
+
/**
|
|
141
|
+
* Item in *${humanReadablePath}*
|
|
142
|
+
*/
|
|
143
|
+
export interface ${itemName} {
|
|
144
|
+
${itemFieldProperties.code}
|
|
145
|
+
}
|
|
146
|
+
`
|
|
147
|
+
});
|
|
148
|
+
code = addLine(`${name}: prismic.GroupField<Simplify<${itemName}>>;`, code);
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case CustomTypeModelFieldType.Slices: {
|
|
152
|
+
const choiceNames = [];
|
|
153
|
+
if ((_m = args.field.config) == null ? void 0 : _m.choices) {
|
|
154
|
+
for (const choiceID in args.field.config.choices) {
|
|
155
|
+
const choice = args.field.config.choices[choiceID];
|
|
156
|
+
if (choice.type === "SharedSlice") {
|
|
157
|
+
choiceNames.push(buildTypeName(choiceID, "Slice"));
|
|
158
|
+
} else if (choice.type === "Slice") {
|
|
159
|
+
const sliceName = buildTypeName(args.path[0].name, "Document", "Data", args.name, choiceID, "Slice");
|
|
160
|
+
let primaryInterfaceName;
|
|
161
|
+
if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
|
|
162
|
+
primaryInterfaceName = buildTypeName(sliceName, "Primary");
|
|
163
|
+
const path = [
|
|
164
|
+
...args.path,
|
|
165
|
+
{
|
|
166
|
+
name: args.name,
|
|
167
|
+
model: args.field
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: choiceID,
|
|
171
|
+
model: choice
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "primary",
|
|
175
|
+
label: "Primary"
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
const humanReadablePath = getHumanReadablePath({ path });
|
|
179
|
+
const primaryFieldProperties = buildFieldProperties({
|
|
180
|
+
fields: choice["non-repeat"],
|
|
181
|
+
fieldConfigs: args.fieldConfigs,
|
|
182
|
+
path
|
|
183
|
+
});
|
|
184
|
+
let primaryCode = stripIndent`
|
|
185
|
+
/**
|
|
186
|
+
* Primary content in *${humanReadablePath}*
|
|
187
|
+
*/
|
|
188
|
+
`;
|
|
189
|
+
primaryCode = primaryFieldProperties.code ? addLine(source`
|
|
190
|
+
export interface ${primaryInterfaceName} {
|
|
191
|
+
${primaryFieldProperties.code}
|
|
192
|
+
}
|
|
193
|
+
`, primaryCode) : addLine(`export interface ${primaryInterfaceName} {}`, primaryCode);
|
|
194
|
+
auxiliaryTypes.push({
|
|
195
|
+
name: primaryInterfaceName,
|
|
196
|
+
code: primaryCode
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
let itemInterfaceName;
|
|
200
|
+
if (choice.repeat && Object.keys(choice.repeat).length > 0) {
|
|
201
|
+
itemInterfaceName = buildTypeName(sliceName, "Item");
|
|
202
|
+
const path = [
|
|
203
|
+
...args.path,
|
|
204
|
+
{
|
|
205
|
+
name: args.name,
|
|
206
|
+
model: args.field
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
name: choiceID,
|
|
210
|
+
model: choice
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "items",
|
|
214
|
+
label: "Items"
|
|
215
|
+
}
|
|
216
|
+
];
|
|
217
|
+
const humanReadablePath = getHumanReadablePath({ path });
|
|
218
|
+
const itemFieldProperties = buildFieldProperties({
|
|
219
|
+
fields: choice.repeat,
|
|
220
|
+
fieldConfigs: args.fieldConfigs,
|
|
221
|
+
path
|
|
222
|
+
});
|
|
223
|
+
let itemCode = stripIndent`
|
|
224
|
+
/**
|
|
225
|
+
* Item content in *${humanReadablePath}*
|
|
226
|
+
*/
|
|
227
|
+
`;
|
|
228
|
+
itemCode = itemFieldProperties.code ? addLine(source`
|
|
229
|
+
export interface ${itemInterfaceName} {
|
|
230
|
+
${itemFieldProperties.code}
|
|
231
|
+
}
|
|
232
|
+
`, itemCode) : addLine(`export interface ${itemInterfaceName} {}`, itemCode);
|
|
233
|
+
auxiliaryTypes.push({
|
|
234
|
+
name: itemInterfaceName,
|
|
235
|
+
code: itemCode
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
auxiliaryTypes.push({
|
|
239
|
+
name: sliceName,
|
|
240
|
+
code: stripIndent`
|
|
241
|
+
/**
|
|
242
|
+
* Slice for *${getHumanReadablePath({
|
|
243
|
+
path: [
|
|
244
|
+
...args.path,
|
|
245
|
+
{
|
|
246
|
+
name: args.name,
|
|
247
|
+
model: args.field
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
})}*
|
|
251
|
+
*/
|
|
252
|
+
export type ${sliceName} = prismic.Slice<"${choiceID}", ${primaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>
|
|
253
|
+
`
|
|
254
|
+
});
|
|
255
|
+
choiceNames.push(sliceName);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const choiceUnionName = buildTypeName(args.path[0].name, "Document", "Data", args.name, "Slice");
|
|
260
|
+
const choiceUnion = buildUnion(choiceNames);
|
|
261
|
+
auxiliaryTypes.push({
|
|
262
|
+
name: choiceUnionName,
|
|
263
|
+
code: `type ${choiceUnionName} = ${choiceUnion}`
|
|
264
|
+
});
|
|
265
|
+
code = addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
default: {
|
|
269
|
+
code = addLine(`${name}: unknown;`, code);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
code,
|
|
274
|
+
auxiliaryTypes
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function buildFieldProperties(args) {
|
|
278
|
+
let code = "";
|
|
279
|
+
const auxiliaryTypes = [];
|
|
280
|
+
for (const name in args.fields) {
|
|
281
|
+
const field = args.fields[name];
|
|
282
|
+
const fieldProperty = buildFieldProperty({
|
|
283
|
+
name,
|
|
284
|
+
field,
|
|
285
|
+
path: args.path,
|
|
286
|
+
fieldConfigs: args.fieldConfigs,
|
|
287
|
+
tabName: args.tabName
|
|
288
|
+
});
|
|
289
|
+
code = addSection(fieldProperty.code, code);
|
|
290
|
+
auxiliaryTypes.push(...fieldProperty.auxiliaryTypes);
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
code,
|
|
294
|
+
auxiliaryTypes
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
export {
|
|
298
|
+
buildFieldProperties
|
|
299
|
+
};
|
|
300
|
+
//# sourceMappingURL=buildFieldProperties.js.map
|