prismic-ts-codegen 0.1.15 → 0.1.16
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/generateTypes.cjs +2 -3
- package/dist/generateTypes.cjs.map +1 -1
- package/dist/generateTypes.js +2 -3
- package/dist/generateTypes.js.map +1 -1
- package/dist/lib/buildCustomTypeDataType.cjs +4 -1
- package/dist/lib/buildCustomTypeDataType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeDataType.d.ts +1 -0
- package/dist/lib/buildCustomTypeDataType.js +4 -1
- package/dist/lib/buildCustomTypeDataType.js.map +1 -1
- package/dist/lib/buildCustomTypeType.cjs +5 -2
- package/dist/lib/buildCustomTypeType.cjs.map +1 -1
- package/dist/lib/buildCustomTypeType.d.ts +1 -1
- package/dist/lib/buildCustomTypeType.js +5 -2
- package/dist/lib/buildCustomTypeType.js.map +1 -1
- package/dist/lib/buildFieldProperties.cjs +8 -2
- package/dist/lib/buildFieldProperties.cjs.map +1 -1
- package/dist/lib/buildFieldProperties.d.ts +1 -0
- package/dist/lib/buildFieldProperties.js +8 -2
- package/dist/lib/buildFieldProperties.js.map +1 -1
- package/dist/lib/buildSharedSliceType.cjs +7 -2
- package/dist/lib/buildSharedSliceType.cjs.map +1 -1
- package/dist/lib/buildSharedSliceType.d.ts +1 -1
- package/dist/lib/buildSharedSliceType.js +7 -2
- package/dist/lib/buildSharedSliceType.js.map +1 -1
- package/package.json +1 -1
- package/src/generateTypes.ts +2 -3
- package/src/lib/buildCustomTypeDataType.ts +4 -0
- package/src/lib/buildCustomTypeType.ts +5 -2
- package/src/lib/buildFieldProperties.ts +8 -0
- package/src/lib/buildSharedSliceType.ts +10 -2
package/dist/generateTypes.cjs
CHANGED
|
@@ -39,7 +39,7 @@ function generateTypes(config = {}) {
|
|
|
39
39
|
code = addSection.addSection(customTypeType.code, code);
|
|
40
40
|
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
41
41
|
contentTypeNames.push(customTypeType.name);
|
|
42
|
-
contentTypeNames.push(customTypeType.
|
|
42
|
+
contentTypeNames.push(...customTypeType.contentTypeNames);
|
|
43
43
|
}
|
|
44
44
|
if (config.customTypeModels.length > 0) {
|
|
45
45
|
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
@@ -57,8 +57,7 @@ function generateTypes(config = {}) {
|
|
|
57
57
|
});
|
|
58
58
|
code = addSection.addSection(sharedSliceType.code, code);
|
|
59
59
|
contentTypeNames.push(sharedSliceType.name);
|
|
60
|
-
contentTypeNames.push(sharedSliceType.
|
|
61
|
-
contentTypeNames.push(...sharedSliceType.variationNames);
|
|
60
|
+
contentTypeNames.push(...sharedSliceType.contentTypeNames);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.
|
|
1
|
+
{"version":3,"file":"generateTypes.cjs","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(...customTypeType.contentTypeNames);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(...sharedSliceType.contentTypeNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\t}\n\n\treturn code;\n}\n"],"names":["QuickLRU","addLine","addSection","buildCustomTypeType","buildUnion","buildSharedSliceType","source"],"mappings":";;;;;;;;;AAcA,MAAM,QAAQ,IAAIA,MAA0B,EAAE,SAAS,IAAM,CAAA;AAe7C,SAAA,cAAc,SAA8B,IAAE;;AACvD,QAAA,eAAe,OAAO,gBAAgB;AACtC,QAAA,iBAAiB,OAAO,SAAS;AAEvC,MAAI,OAAO;AAEL,QAAA,gBAAgB,OAAO,iBAAiB;AAC9C,MAAI,mBAAmB;AAEhB,SAAAC,QAAA,QAAQ,kCAAkC,mBAAmB,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAIZ,aAAAA,QAAA,QACN,o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A8B;AAC1D,aAAK,YAAO,qBAAP,mBAAyB,WAAU,KAAK,GAAG;AAC/C,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmBA,WAClB,WAAA;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmBA,WAClB,WAAAI;;;SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAOJ,WACN,WAAAI;;OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;;"}
|
package/dist/generateTypes.js
CHANGED
|
@@ -37,7 +37,7 @@ function generateTypes(config = {}) {
|
|
|
37
37
|
code = addSection(customTypeType.code, code);
|
|
38
38
|
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
39
39
|
contentTypeNames.push(customTypeType.name);
|
|
40
|
-
contentTypeNames.push(customTypeType.
|
|
40
|
+
contentTypeNames.push(...customTypeType.contentTypeNames);
|
|
41
41
|
}
|
|
42
42
|
if (config.customTypeModels.length > 0) {
|
|
43
43
|
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
@@ -55,8 +55,7 @@ function generateTypes(config = {}) {
|
|
|
55
55
|
});
|
|
56
56
|
code = addSection(sharedSliceType.code, code);
|
|
57
57
|
contentTypeNames.push(sharedSliceType.name);
|
|
58
|
-
contentTypeNames.push(sharedSliceType.
|
|
59
|
-
contentTypeNames.push(...sharedSliceType.variationNames);
|
|
58
|
+
contentTypeNames.push(...sharedSliceType.contentTypeNames);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
if (((_c = config.clientIntegration) == null ? void 0 : _c.includeCreateClientInterface) || ((_d = config.clientIntegration) == null ? void 0 : _d.includeContentNamespace)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(customTypeType.
|
|
1
|
+
{"version":3,"file":"generateTypes.js","sources":["../../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { addLine } from \"./lib/addLine\";\nimport { addSection } from \"./lib/addSection\";\nimport { buildCustomTypeType } from \"./lib/buildCustomTypeType\";\nimport { buildSharedSliceType } from \"./lib/buildSharedSliceType\";\nimport { buildUnion } from \"./lib/buildUnion\";\n\nimport { FieldConfigs } from \"./types\";\n\nexport type TypesProvider = \"@prismicio/client\" | \"@prismicio/types\";\n\nconst cache = new QuickLRU<string, unknown>({ maxSize: 1000 });\n\nexport type GenerateTypesConfig = {\n\tcustomTypeModels?: CustomTypeModel[];\n\tsharedSliceModels?: SharedSliceModel[];\n\tlocaleIDs?: string[];\n\tfieldConfigs?: FieldConfigs;\n\ttypesProvider?: TypesProvider;\n\tclientIntegration?: {\n\t\tincludeCreateClientInterface?: boolean;\n\t\tincludeContentNamespace?: boolean;\n\t};\n\tcache?: boolean;\n};\n\nexport function generateTypes(config: GenerateTypesConfig = {}): string {\n\tconst fieldConfigs = config.fieldConfigs || {};\n\tconst shouldUseCache = config.cache ?? true;\n\n\tlet code = \"\";\n\n\tconst typesProvider = config.typesProvider || \"@prismicio/types\";\n\tlet clientImportName = \"prismic\";\n\n\tcode = addLine(`import type * as prismic from \"${typesProvider}\";`, code);\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tif (typesProvider !== \"@prismicio/client\") {\n\t\t\tclientImportName = \"prismicClient\";\n\n\t\t\t// This import declaration would be a duplicate if the types\n\t\t\t// provider is @prismicio/client.\n\t\t\tcode = addLine(\n\t\t\t\t`import type * as ${clientImportName} from \"@prismicio/client\";`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\t}\n\n\tcode = addSection(\n\t\t`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`,\n\t\tcode,\n\t);\n\n\tconst contentTypeNames: string[] = [];\n\n\tif (config.customTypeModels) {\n\t\tconst allDocumentTypesTypeNames: string[] = [];\n\n\t\tfor (const model of config.customTypeModels) {\n\t\t\tconst customTypeType = buildCustomTypeType({\n\t\t\t\tmodel,\n\t\t\t\tlocaleIDs: config.localeIDs,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tfor (const auxiliaryType of customTypeType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\n\t\t\t}\n\n\t\t\tcode = addSection(customTypeType.code, code);\n\n\t\t\tallDocumentTypesTypeNames.push(customTypeType.name);\n\n\t\t\tcontentTypeNames.push(customTypeType.name);\n\t\t\tcontentTypeNames.push(...customTypeType.contentTypeNames);\n\t\t}\n\n\t\tif (config.customTypeModels.length > 0) {\n\t\t\tconst allDocumentTypesUnionName = \"AllDocumentTypes\";\n\t\t\tconst allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);\n\n\t\t\tcode = addSection(\n\t\t\t\t`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`,\n\t\t\t\tcode,\n\t\t\t);\n\n\t\t\tcontentTypeNames.push(allDocumentTypesUnionName);\n\t\t}\n\t}\n\n\tif (config.sharedSliceModels) {\n\t\tfor (const model of config.sharedSliceModels) {\n\t\t\tconst sharedSliceType = buildSharedSliceType({\n\t\t\t\tmodel,\n\t\t\t\tfieldConfigs,\n\t\t\t\tcache: shouldUseCache ? cache : undefined,\n\t\t\t});\n\n\t\t\tcode = addSection(sharedSliceType.code, code);\n\n\t\t\tcontentTypeNames.push(sharedSliceType.name);\n\t\t\tcontentTypeNames.push(...sharedSliceType.contentTypeNames);\n\t\t}\n\t}\n\n\tif (\n\t\tconfig.clientIntegration?.includeCreateClientInterface ||\n\t\tconfig.clientIntegration?.includeContentNamespace\n\t) {\n\t\tlet clientModuleCode = \"\";\n\n\t\tif (config.clientIntegration.includeCreateClientInterface) {\n\t\t\tif ((config.customTypeModels?.length || 0) > 0) {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (config.clientIntegration.includeContentNamespace) {\n\t\t\tclientModuleCode = addSection(\n\t\t\t\tsource`\n\t\t\t\t\tnamespace Content {\n\t\t\t\t\t\texport type {\n\t\t\t\t\t\t\t${contentTypeNames.join(\",\\n\")}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t`,\n\t\t\t\tclientModuleCode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\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,+BAA+B,0BAC9C,IAAI;AAGL,uBAAiB,KAAK,yBAAyB;AAAA,IAC/C;AAAA,EACD;AAED,MAAI,OAAO,mBAAmB;AAClB,eAAA,SAAS,OAAO,mBAAmB;AAC7C,YAAM,kBAAkB,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEM,aAAA,WAAW,gBAAgB,MAAM,IAAI;AAE3B,uBAAA,KAAK,gBAAgB,IAAI;AACzB,uBAAA,KAAK,GAAG,gBAAgB,gBAAgB;AAAA,IACzD;AAAA,EACD;AAED,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,mBAAmB;AAEnB,QAAA,OAAO,kBAAkB,8BAA8B;AAC1D,aAAK,YAAO,qBAAP,mBAAyB,WAAU,KAAK,GAAG;AAC/C,2BAAmB,WAClB;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmB,WAClB;AAAA,gDAC2C,mCAAmC;AAAA,IAE9E,gBAAgB;AAAA,MAEjB;AAAA,IACD;AAEG,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmB,WAClB;AAAA;AAAA;AAAA,SAGK,iBAAiB,KAAK,KAAK;AAAA;AAAA;AAAA,OAIhC,gBAAgB;AAAA,IAEjB;AAED,WAAO,WACN;AAAA;AAAA,OAEI;AAAA;AAAA,MAGJ,IAAI;AAAA,EAEL;AAEM,SAAA;AACR;"}
|
|
@@ -7,6 +7,7 @@ const getHumanReadableModelName = require("./getHumanReadableModelName.cjs");
|
|
|
7
7
|
function buildCustomTypeDataType(args) {
|
|
8
8
|
let code = "";
|
|
9
9
|
const auxiliaryTypes = [];
|
|
10
|
+
const contentTypeNames = [];
|
|
10
11
|
const name = buildTypeName.buildTypeName(args.model.id, "Document", "Data");
|
|
11
12
|
const humanReadableName = getHumanReadableModelName.getHumanReadableModelName({
|
|
12
13
|
name: args.model.id,
|
|
@@ -28,6 +29,7 @@ function buildCustomTypeDataType(args) {
|
|
|
28
29
|
});
|
|
29
30
|
fieldProperties += tabFieldProperties.code;
|
|
30
31
|
auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
|
|
32
|
+
contentTypeNames.push(...tabFieldProperties.contentTypeNames);
|
|
31
33
|
}
|
|
32
34
|
if (fieldProperties) {
|
|
33
35
|
code = commonTags.source`
|
|
@@ -44,7 +46,8 @@ function buildCustomTypeDataType(args) {
|
|
|
44
46
|
return {
|
|
45
47
|
name,
|
|
46
48
|
code,
|
|
47
|
-
auxiliaryTypes
|
|
49
|
+
auxiliaryTypes,
|
|
50
|
+
contentTypeNames
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
53
|
exports.buildCustomTypeDataType = buildCustomTypeDataType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.cjs","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":["buildTypeName","getHumanReadableModelName","buildFieldProperties","source"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"buildCustomTypeDataType.cjs","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t\tcontentTypeNames.push(...tabFieldProperties.contentTypeNames);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"names":["buildTypeName","getHumanReadableModelName","buildFieldProperties","source"],"mappings":";;;;;;AAsBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAEnC,QAAM,OAAOA,cAAAA,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqBC,qBAAAA,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AACvC,qBAAA,KAAK,GAAG,mBAAmB,gBAAgB;AAAA,EAC5D;AAED,MAAI,iBAAiB;AACb,WAAAC,WAAAA;AAAAA;AAAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -8,6 +8,7 @@ type BuildCustomTypeDataTypeReturnValue = {
|
|
|
8
8
|
name: string;
|
|
9
9
|
code: string;
|
|
10
10
|
auxiliaryTypes: AuxiliaryType[];
|
|
11
|
+
contentTypeNames: string[];
|
|
11
12
|
};
|
|
12
13
|
export declare function buildCustomTypeDataType(args: BuildCustomTypeDataTypeArgs): BuildCustomTypeDataTypeReturnValue;
|
|
13
14
|
export {};
|
|
@@ -5,6 +5,7 @@ import { getHumanReadableModelName } from "./getHumanReadableModelName.js";
|
|
|
5
5
|
function buildCustomTypeDataType(args) {
|
|
6
6
|
let code = "";
|
|
7
7
|
const auxiliaryTypes = [];
|
|
8
|
+
const contentTypeNames = [];
|
|
8
9
|
const name = buildTypeName(args.model.id, "Document", "Data");
|
|
9
10
|
const humanReadableName = getHumanReadableModelName({
|
|
10
11
|
name: args.model.id,
|
|
@@ -26,6 +27,7 @@ function buildCustomTypeDataType(args) {
|
|
|
26
27
|
});
|
|
27
28
|
fieldProperties += tabFieldProperties.code;
|
|
28
29
|
auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
|
|
30
|
+
contentTypeNames.push(...tabFieldProperties.contentTypeNames);
|
|
29
31
|
}
|
|
30
32
|
if (fieldProperties) {
|
|
31
33
|
code = source`
|
|
@@ -42,7 +44,8 @@ function buildCustomTypeDataType(args) {
|
|
|
42
44
|
return {
|
|
43
45
|
name,
|
|
44
46
|
code,
|
|
45
|
-
auxiliaryTypes
|
|
47
|
+
auxiliaryTypes,
|
|
48
|
+
contentTypeNames
|
|
46
49
|
};
|
|
47
50
|
}
|
|
48
51
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.js","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t};\n}\n"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"buildCustomTypeDataType.js","sources":["../../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t\tcontentTypeNames.push(...tabFieldProperties.contentTypeNames);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"names":[],"mappings":";;;;AAsBM,SAAU,wBACf,MAAiC;AAEjC,MAAI,OAAO;AACX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAEnC,QAAM,OAAO,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;AAC5D,QAAM,oBAAoB,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,MAAI,kBAAkB;AAEX,aAAA,WAAW,KAAK,MAAM,MAAM;AAChC,UAAA,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK,OAAO;AAExD,UAAM,qBAAqB,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc,KAAK;AAAA,MACnB,MAAM;AAAA,QACL;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,MACD;AAAA,MACD;AAAA,IAAA,CACA;AAED,uBAAmB,mBAAmB;AAEvB,mBAAA,KAAK,GAAG,mBAAmB,cAAc;AACvC,qBAAA,KAAK,GAAG,mBAAmB,gBAAgB;AAAA,EAC5D;AAED,MAAI,iBAAiB;AACb,WAAA;AAAA;AAAA,oBAEW;AAAA;AAAA,eAEL;AAAA,MACT;AAAA;AAAA;AAAA,EAAA,OAGE;AACN,WAAO,aAAa;AAAA,EACpB;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
@@ -19,6 +19,7 @@ function buildCustomTypeType(args) {
|
|
|
19
19
|
}
|
|
20
20
|
let code = "";
|
|
21
21
|
const auxiliaryTypes = [];
|
|
22
|
+
const contentTypeNames = [];
|
|
22
23
|
const name = buildTypeName.buildTypeName(args.model.id, "Document");
|
|
23
24
|
const langDefault = args.localeIDs && args.localeIDs.length > 0 ? buildUnion.buildUnion(args.localeIDs.map((localeID) => `"${localeID}"`)) : "string";
|
|
24
25
|
const baseDocumentType = checkHasUIDFIeld.checkHasUIDField(args.model) ? "PrismicDocumentWithUID" : "PrismicDocumentWithoutUID";
|
|
@@ -31,6 +32,8 @@ function buildCustomTypeType(args) {
|
|
|
31
32
|
fieldConfigs: args.fieldConfigs
|
|
32
33
|
});
|
|
33
34
|
auxiliaryTypes.push(...dataType.auxiliaryTypes);
|
|
35
|
+
contentTypeNames.push(dataType.name);
|
|
36
|
+
contentTypeNames.push(...dataType.contentTypeNames);
|
|
34
37
|
code = addSection.addSection(dataType.code, code);
|
|
35
38
|
code = addSection.addSection(commonTags.source`
|
|
36
39
|
/**
|
|
@@ -46,9 +49,9 @@ function buildCustomTypeType(args) {
|
|
|
46
49
|
`, code);
|
|
47
50
|
const result = {
|
|
48
51
|
name,
|
|
49
|
-
dataName: dataType.name,
|
|
50
52
|
code,
|
|
51
|
-
auxiliaryTypes
|
|
53
|
+
auxiliaryTypes,
|
|
54
|
+
contentTypeNames
|
|
52
55
|
};
|
|
53
56
|
if (args.cache) {
|
|
54
57
|
const key = getCacheKey.getCacheKey(args.model);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeType.cjs","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\
|
|
1
|
+
{"version":3,"file":"buildCustomTypeType.cjs","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs,\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":["getCacheKey","buildTypeName","buildUnion","checkHasUIDField","getHumanReadableModelName","buildCustomTypeDataType","addSection","source","CUSTOM_TYPES_DOCUMENTATION_URL"],"mappings":";;;;;;;;;;;AA8BM,SAAU,oBACf,MAA8B;AAE9B,MAAI,KAAK,OAAO;AACT,UAAA,MAAMA,YAAAA,YAAY,KAAK,KAAK;AAClC,UAAM,SAAS,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,QAAQ;AACJ,aAAA;AAAA,IACP;AAAA,EACD;AAED,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAEnC,QAAM,OAAOC,cAAAA,cAAc,KAAK,MAAM,IAAI,UAAU;AACpD,QAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvCC,sBAAW,KAAK,UAAU,IAAI,CAAC,aAAa,IAAI,WAAW,CAAC,IAC5D;AACJ,QAAM,mBAAmBC,iBAAAA,iBAAiB,KAAK,KAAK,IACjD,2BACA;AACH,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,QAAM,WAAWC,wBAAAA,wBAAwB;AAAA,IACxC,OAAO,KAAK;AAAA,IACZ,cAAc,KAAK;AAAA,EAAA,CACnB;AAEc,iBAAA,KAAK,GAAG,SAAS,cAAc;AAC7B,mBAAA,KAAK,SAAS,IAAI;AAClB,mBAAA,KAAK,GAAG,SAAS,gBAAgB;AAE3C,SAAAC,WAAAA,WAAW,SAAS,MAAM,IAAI;AAErC,SAAOA,WACN,WAAAC;;QAEM;AAAA;AAAA,wBAEgB,KAAK,MAAM;AAAA,4BACP,KAAK,MAAM,WAAW,SAAU;AAAA,6BAC/BC;;;;iBAIZ,8BAA8B,0BAA0B,6BACtE,SAAS,WACH,KAAK,MAAM;AAAA,KAElB,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACT,UAAA,MAAMR,YAAAA,YAAY,KAAK,KAAK;AAE7B,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;;"}
|
|
@@ -9,9 +9,9 @@ type BuildCustomTypeTypesArgs = {
|
|
|
9
9
|
};
|
|
10
10
|
type BuildCustomTypeTypeReturnValue = {
|
|
11
11
|
name: string;
|
|
12
|
-
dataName: string;
|
|
13
12
|
code: string;
|
|
14
13
|
auxiliaryTypes: AuxiliaryType[];
|
|
14
|
+
contentTypeNames: string[];
|
|
15
15
|
};
|
|
16
16
|
export declare function buildCustomTypeType(args: BuildCustomTypeTypesArgs): BuildCustomTypeTypeReturnValue;
|
|
17
17
|
export {};
|
|
@@ -17,6 +17,7 @@ function buildCustomTypeType(args) {
|
|
|
17
17
|
}
|
|
18
18
|
let code = "";
|
|
19
19
|
const auxiliaryTypes = [];
|
|
20
|
+
const contentTypeNames = [];
|
|
20
21
|
const name = buildTypeName(args.model.id, "Document");
|
|
21
22
|
const langDefault = args.localeIDs && args.localeIDs.length > 0 ? buildUnion(args.localeIDs.map((localeID) => `"${localeID}"`)) : "string";
|
|
22
23
|
const baseDocumentType = checkHasUIDField(args.model) ? "PrismicDocumentWithUID" : "PrismicDocumentWithoutUID";
|
|
@@ -29,6 +30,8 @@ function buildCustomTypeType(args) {
|
|
|
29
30
|
fieldConfigs: args.fieldConfigs
|
|
30
31
|
});
|
|
31
32
|
auxiliaryTypes.push(...dataType.auxiliaryTypes);
|
|
33
|
+
contentTypeNames.push(dataType.name);
|
|
34
|
+
contentTypeNames.push(...dataType.contentTypeNames);
|
|
32
35
|
code = addSection(dataType.code, code);
|
|
33
36
|
code = addSection(source`
|
|
34
37
|
/**
|
|
@@ -44,9 +47,9 @@ function buildCustomTypeType(args) {
|
|
|
44
47
|
`, code);
|
|
45
48
|
const result = {
|
|
46
49
|
name,
|
|
47
|
-
dataName: dataType.name,
|
|
48
50
|
code,
|
|
49
|
-
auxiliaryTypes
|
|
51
|
+
auxiliaryTypes,
|
|
52
|
+
contentTypeNames
|
|
50
53
|
};
|
|
51
54
|
if (args.cache) {
|
|
52
55
|
const key = getCacheKey(args.model);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeType.js","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\
|
|
1
|
+
{"version":3,"file":"buildCustomTypeType.js","sources":["../../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { AuxiliaryType, FieldConfigs } from \"../types\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs,\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":[],"mappings":";;;;;;;;;AA8BM,SAAU,oBACf,MAA8B;AAE9B,MAAI,KAAK,OAAO;AACT,UAAA,MAAM,YAAY,KAAK,KAAK;AAClC,UAAM,SAAS,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,QAAQ;AACJ,aAAA;AAAA,IACP;AAAA,EACD;AAED,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAEnC,QAAM,OAAO,cAAc,KAAK,MAAM,IAAI,UAAU;AACpD,QAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvC,WAAW,KAAK,UAAU,IAAI,CAAC,aAAa,IAAI,WAAW,CAAC,IAC5D;AACJ,QAAM,mBAAmB,iBAAiB,KAAK,KAAK,IACjD,2BACA;AACH,QAAM,oBAAoB,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,QAAM,WAAW,wBAAwB;AAAA,IACxC,OAAO,KAAK;AAAA,IACZ,cAAc,KAAK;AAAA,EAAA,CACnB;AAEc,iBAAA,KAAK,GAAG,SAAS,cAAc;AAC7B,mBAAA,KAAK,SAAS,IAAI;AAClB,mBAAA,KAAK,GAAG,SAAS,gBAAgB;AAE3C,SAAA,WAAW,SAAS,MAAM,IAAI;AAErC,SAAO,WACN;AAAA;AAAA,QAEM;AAAA;AAAA,wBAEgB,KAAK,MAAM;AAAA,4BACP,KAAK,MAAM,WAAW,SAAU;AAAA,6BAC/B;AAAA;AAAA;AAAA;AAAA,iBAIZ,8BAA8B,0BAA0B,6BACtE,SAAS,WACH,KAAK,MAAM;AAAA,KAElB,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACT,UAAA,MAAM,YAAY,KAAK,KAAK;AAE7B,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;"}
|
|
@@ -16,6 +16,7 @@ function buildFieldProperty(args) {
|
|
|
16
16
|
tabName: args.tabName
|
|
17
17
|
});
|
|
18
18
|
const auxiliaryTypes = [];
|
|
19
|
+
const contentTypeNames = [];
|
|
19
20
|
const name = args.name.includes("-") || args.name.includes(":") || /^[0-9]/.test(args.name) ? `"${args.name}"` : args.name;
|
|
20
21
|
switch (args.field.type) {
|
|
21
22
|
case "UID": {
|
|
@@ -263,6 +264,7 @@ function buildFieldProperty(args) {
|
|
|
263
264
|
name: choiceUnionName,
|
|
264
265
|
code: `type ${choiceUnionName} = ${choiceUnion}`
|
|
265
266
|
});
|
|
267
|
+
contentTypeNames.push(choiceUnionName);
|
|
266
268
|
code = addLine.addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);
|
|
267
269
|
break;
|
|
268
270
|
}
|
|
@@ -272,12 +274,14 @@ function buildFieldProperty(args) {
|
|
|
272
274
|
}
|
|
273
275
|
return {
|
|
274
276
|
code,
|
|
275
|
-
auxiliaryTypes
|
|
277
|
+
auxiliaryTypes,
|
|
278
|
+
contentTypeNames
|
|
276
279
|
};
|
|
277
280
|
}
|
|
278
281
|
function buildFieldProperties(args) {
|
|
279
282
|
let code = "";
|
|
280
283
|
const auxiliaryTypes = [];
|
|
284
|
+
const contentTypeNames = [];
|
|
281
285
|
for (const name in args.fields) {
|
|
282
286
|
const field = args.fields[name];
|
|
283
287
|
const fieldProperty = buildFieldProperty({
|
|
@@ -289,10 +293,12 @@ function buildFieldProperties(args) {
|
|
|
289
293
|
});
|
|
290
294
|
code = addSection.addSection(fieldProperty.code, code);
|
|
291
295
|
auxiliaryTypes.push(...fieldProperty.auxiliaryTypes);
|
|
296
|
+
contentTypeNames.push(...fieldProperty.contentTypeNames);
|
|
292
297
|
}
|
|
293
298
|
return {
|
|
294
299
|
code,
|
|
295
|
-
auxiliaryTypes
|
|
300
|
+
auxiliaryTypes,
|
|
301
|
+
contentTypeNames
|
|
296
302
|
};
|
|
297
303
|
}
|
|
298
304
|
exports.buildFieldProperties = buildFieldProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFieldProperties.cjs","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import type { CustomTypeModelField } 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 \"UID\": {\n\t\t\t// UID fields are not included in Data.\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Boolean\": {\n\t\t\tcode = addLine(`${name}: prismic.BooleanField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Color\": {\n\t\t\tcode = addLine(`${name}: prismic.ColorField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Date\": {\n\t\t\tcode = addLine(`${name}: prismic.DateField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"GeoPoint\": {\n\t\t\tcode = addLine(`${name}: prismic.GeoPointField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"IntegrationFields\": {\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 \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"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 \"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 \"Number\": {\n\t\t\tcode = addLine(`${name}: prismic.NumberField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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 \"Text\": {\n\t\t\tcode = addLine(`${name}: prismic.KeyTextField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Timestamp\": {\n\t\t\tcode = addLine(`${name}: prismic.TimestampField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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","addLine","buildUnion","buildTypeName","getHumanReadablePath","source","stripIndent","addSection"],"mappings":";;;;;;;;;AAyBA,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,KAAK,OAAO;AAEX;A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B,YAAY,uBAAuB;AAAA;AAAA,YAAA,CAGxD;AAED,wBAAY,KAAK,SAAS;AAAA,UAC1B;AAAA,QACD;AAAA,MACD;AAEK,YAAA,kBAAkBD,cACvB,cAAA,KAAK,KAAK,CAAC,EAAE,MACb,YACA,QACA,KAAK,MACL,OAAO;AAEF,YAAA,cAAcD,sBAAW,WAAW;AAC1C,qBAAe,KAAK;AAAA,QACnB,MAAM;AAAA,QACN,MAAM,QAAQ,qBAAqB;AAAA,MAAA,CACnC;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,WAAAM,WAAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAAA,EACnD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
1
|
+
{"version":3,"file":"buildFieldProperties.cjs","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import type { CustomTypeModelField } 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\tcontentTypeNames: string[];\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\tconst contentTypeNames: string[] = [];\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 \"UID\": {\n\t\t\t// UID fields are not included in Data.\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Boolean\": {\n\t\t\tcode = addLine(`${name}: prismic.BooleanField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Color\": {\n\t\t\tcode = addLine(`${name}: prismic.ColorField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Date\": {\n\t\t\tcode = addLine(`${name}: prismic.DateField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"GeoPoint\": {\n\t\t\tcode = addLine(`${name}: prismic.GeoPointField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"IntegrationFields\": {\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 \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"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 \"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 \"Number\": {\n\t\t\tcode = addLine(`${name}: prismic.NumberField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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 \"Text\": {\n\t\t\tcode = addLine(`${name}: prismic.KeyTextField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Timestamp\": {\n\t\t\tcode = addLine(`${name}: prismic.TimestampField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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\t\t\tcontentTypeNames.push(choiceUnionName);\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\tcontentTypeNames,\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\tcontentTypeNames: string[];\n};\n\nexport function buildFieldProperties(\n\targs: BuildFieldPropertiesArgs,\n): BuildFieldPropertiesReturnType {\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\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\tcontentTypeNames.push(...fieldProperty.contentTypeNames);\n\t}\n\n\treturn {\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"names":["buildFieldDocs","addLine","buildUnion","buildTypeName","getHumanReadablePath","source","stripIndent","addSection"],"mappings":";;;;;;;;;AA0BA,SAAS,mBACR,MAA4B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,KAAK;AAAA,IAAA,CACd;AAEM,WAAAM,WAAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAClC,qBAAA,KAAK,GAAG,cAAc,gBAAgB;AAAA,EACvD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -9,6 +9,7 @@ type BuildFieldPropertiesArgs = {
|
|
|
9
9
|
type BuildFieldPropertiesReturnType = {
|
|
10
10
|
code: string;
|
|
11
11
|
auxiliaryTypes: AuxiliaryType[];
|
|
12
|
+
contentTypeNames: string[];
|
|
12
13
|
};
|
|
13
14
|
export declare function buildFieldProperties(args: BuildFieldPropertiesArgs): BuildFieldPropertiesReturnType;
|
|
14
15
|
export {};
|
|
@@ -14,6 +14,7 @@ function buildFieldProperty(args) {
|
|
|
14
14
|
tabName: args.tabName
|
|
15
15
|
});
|
|
16
16
|
const auxiliaryTypes = [];
|
|
17
|
+
const contentTypeNames = [];
|
|
17
18
|
const name = args.name.includes("-") || args.name.includes(":") || /^[0-9]/.test(args.name) ? `"${args.name}"` : args.name;
|
|
18
19
|
switch (args.field.type) {
|
|
19
20
|
case "UID": {
|
|
@@ -261,6 +262,7 @@ function buildFieldProperty(args) {
|
|
|
261
262
|
name: choiceUnionName,
|
|
262
263
|
code: `type ${choiceUnionName} = ${choiceUnion}`
|
|
263
264
|
});
|
|
265
|
+
contentTypeNames.push(choiceUnionName);
|
|
264
266
|
code = addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);
|
|
265
267
|
break;
|
|
266
268
|
}
|
|
@@ -270,12 +272,14 @@ function buildFieldProperty(args) {
|
|
|
270
272
|
}
|
|
271
273
|
return {
|
|
272
274
|
code,
|
|
273
|
-
auxiliaryTypes
|
|
275
|
+
auxiliaryTypes,
|
|
276
|
+
contentTypeNames
|
|
274
277
|
};
|
|
275
278
|
}
|
|
276
279
|
function buildFieldProperties(args) {
|
|
277
280
|
let code = "";
|
|
278
281
|
const auxiliaryTypes = [];
|
|
282
|
+
const contentTypeNames = [];
|
|
279
283
|
for (const name in args.fields) {
|
|
280
284
|
const field = args.fields[name];
|
|
281
285
|
const fieldProperty = buildFieldProperty({
|
|
@@ -287,10 +291,12 @@ function buildFieldProperties(args) {
|
|
|
287
291
|
});
|
|
288
292
|
code = addSection(fieldProperty.code, code);
|
|
289
293
|
auxiliaryTypes.push(...fieldProperty.auxiliaryTypes);
|
|
294
|
+
contentTypeNames.push(...fieldProperty.contentTypeNames);
|
|
290
295
|
}
|
|
291
296
|
return {
|
|
292
297
|
code,
|
|
293
|
-
auxiliaryTypes
|
|
298
|
+
auxiliaryTypes,
|
|
299
|
+
contentTypeNames
|
|
294
300
|
};
|
|
295
301
|
}
|
|
296
302
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFieldProperties.js","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import type { CustomTypeModelField } 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 \"UID\": {\n\t\t\t// UID fields are not included in Data.\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Boolean\": {\n\t\t\tcode = addLine(`${name}: prismic.BooleanField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Color\": {\n\t\t\tcode = addLine(`${name}: prismic.ColorField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Date\": {\n\t\t\tcode = addLine(`${name}: prismic.DateField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"GeoPoint\": {\n\t\t\tcode = addLine(`${name}: prismic.GeoPointField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"IntegrationFields\": {\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 \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"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 \"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 \"Number\": {\n\t\t\tcode = addLine(`${name}: prismic.NumberField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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 \"Text\": {\n\t\t\tcode = addLine(`${name}: prismic.KeyTextField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Timestamp\": {\n\t\t\tcode = addLine(`${name}: prismic.TimestampField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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":[],"mappings":";;;;;;;AAyBA,SAAS,mBACR,MAA4B;;AAE5B,MAAI,OAAO,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,KAAK,OAAO;AAEX;AAAA,IACA;AAAA,IAED,KAAK,WAAW;AACR,aAAA,QAAQ,GAAG,+BAA+B,IAAI;AAErD;AAAA,IACA;AAAA,IAED,KAAK,SAAS;AACN,aAAA,QAAQ,GAAG,6BAA6B,IAAI;AAEnD;AAAA,IACA;AAAA,IAED,KAAK,QAAQ;AACL,aAAA,QAAQ,GAAG,4BAA4B,IAAI;AAElD;AAAA,IACA;AAAA,IAED,KAAK,SAAS;AACb,YAAM,gBAA0B,CAAA;AAE5B,WAAA,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAC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,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,IAAA,CACd;AAEM,WAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAAA,EACnD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
1
|
+
{"version":3,"file":"buildFieldProperties.js","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import type { CustomTypeModelField } 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\tcontentTypeNames: string[];\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\tconst contentTypeNames: string[] = [];\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 \"UID\": {\n\t\t\t// UID fields are not included in Data.\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Boolean\": {\n\t\t\tcode = addLine(`${name}: prismic.BooleanField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Color\": {\n\t\t\tcode = addLine(`${name}: prismic.ColorField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Date\": {\n\t\t\tcode = addLine(`${name}: prismic.DateField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"GeoPoint\": {\n\t\t\tcode = addLine(`${name}: prismic.GeoPointField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"IntegrationFields\": {\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 \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"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 \"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 \"Number\": {\n\t\t\tcode = addLine(`${name}: prismic.NumberField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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 \"Text\": {\n\t\t\tcode = addLine(`${name}: prismic.KeyTextField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"Timestamp\": {\n\t\t\tcode = addLine(`${name}: prismic.TimestampField;`, code);\n\n\t\t\tbreak;\n\t\t}\n\n\t\tcase \"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 \"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\t\t\tcontentTypeNames.push(choiceUnionName);\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\tcontentTypeNames,\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\tcontentTypeNames: string[];\n};\n\nexport function buildFieldProperties(\n\targs: BuildFieldPropertiesArgs,\n): BuildFieldPropertiesReturnType {\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\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\tcontentTypeNames.push(...fieldProperty.contentTypeNames);\n\t}\n\n\treturn {\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"names":[],"mappings":";;;;;;;AA0BA,SAAS,mBACR,MAA4B;;AAE5B,MAAI,OAAO,eAAe;AAAA,IACzB,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,EAAA,CACd;AAED,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAEnC,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,KAAK,OAAO;AAEX;AAAA,IACA;AAAA,IAED,KAAK,WAAW;AACR,aAAA,QAAQ,GAAG,+BAA+B,IAAI;AAErD;AAAA,IACA;AAAA,IAED,KAAK,SAAS;AACN,aAAA,QAAQ,GAAG,6BAA6B,IAAI;AAEnD;AAAA,IACA;AAAA,IAED,KAAK,QAAQ;AACL,aAAA,QAAQ,GAAG,4BAA4B,IAAI;AAElD;AAAA,IACA;AAAA,IAED,KAAK,SAAS;AACb,YAAM,gBAA0B,CAAA;AAE5B,WAAA,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAC3C,mBAAW,iBAAgB,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AACl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;AAAA,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,IAAA,CACd;AAEM,WAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAClC,qBAAA,KAAK,GAAG,cAAc,gBAAgB;AAAA,EACvD;AAEM,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
@@ -18,6 +18,7 @@ function buildSharedSliceType(args) {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
let code = "";
|
|
21
|
+
const contentTypeNames = [];
|
|
21
22
|
const name = buildTypeName.buildTypeName(args.model.id, "Slice");
|
|
22
23
|
const humanReadableName = getHumanReadableModelName.getHumanReadableModelName({
|
|
23
24
|
name: args.model.id,
|
|
@@ -45,6 +46,7 @@ function buildSharedSliceType(args) {
|
|
|
45
46
|
fieldConfigs: args.fieldConfigs,
|
|
46
47
|
path
|
|
47
48
|
});
|
|
49
|
+
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
48
50
|
const docs = commonTags.stripIndent`
|
|
49
51
|
/**
|
|
50
52
|
* Primary content in *${humanReadablePath}*
|
|
@@ -79,6 +81,7 @@ function buildSharedSliceType(args) {
|
|
|
79
81
|
fieldConfigs: args.fieldConfigs,
|
|
80
82
|
path
|
|
81
83
|
});
|
|
84
|
+
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
82
85
|
const docs = commonTags.stripIndent`
|
|
83
86
|
/**
|
|
84
87
|
* Primary content in *${humanReadablePath}*
|
|
@@ -108,6 +111,8 @@ function buildSharedSliceType(args) {
|
|
|
108
111
|
}
|
|
109
112
|
const variationUnionName = buildTypeName.buildTypeName(name, "Variation");
|
|
110
113
|
const variationsUnion = buildUnion.buildUnion(variationNames);
|
|
114
|
+
contentTypeNames.push(variationUnionName);
|
|
115
|
+
contentTypeNames.push(...variationNames);
|
|
111
116
|
code = addSection.addSection(commonTags.source`
|
|
112
117
|
/**
|
|
113
118
|
* Slice variation for *${humanReadableName}*
|
|
@@ -126,9 +131,9 @@ function buildSharedSliceType(args) {
|
|
|
126
131
|
`, code);
|
|
127
132
|
const result = {
|
|
128
133
|
name,
|
|
129
|
-
variationUnionName,
|
|
130
134
|
variationNames,
|
|
131
|
-
code
|
|
135
|
+
code,
|
|
136
|
+
contentTypeNames
|
|
132
137
|
};
|
|
133
138
|
if (args.cache) {
|
|
134
139
|
const key = getCacheKey.getCacheKey([args.model, args.fieldConfigs]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSharedSliceType.cjs","sources":["../../../src/lib/buildSharedSliceType.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { FieldConfigs, FieldPath } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildSharedSliceTypeArgs = {\n\tmodel: SharedSliceModel;\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildSharedSliceTypeReturnValue = {\n\tname: string;\n\
|
|
1
|
+
{"version":3,"file":"buildSharedSliceType.cjs","sources":["../../../src/lib/buildSharedSliceType.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { FieldConfigs, FieldPath } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildSharedSliceTypeArgs = {\n\tmodel: SharedSliceModel;\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildSharedSliceTypeReturnValue = {\n\tname: string;\n\tvariationNames: string[];\n\tcode: string;\n\tcontentTypeNames: string[];\n};\n\nexport function buildSharedSliceType(\n\targs: BuildSharedSliceTypeArgs,\n): BuildSharedSliceTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildSharedSliceTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Slice\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst variationNames: string[] = [];\n\tfor (const variationModel of args.model.variations) {\n\t\tconst variationName = buildTypeName(name, variationModel.id);\n\n\t\tlet primaryInterfaceName: string | undefined;\n\t\tif (\n\t\t\tvariationModel.primary &&\n\t\t\tObject.keys(variationModel.primary).length > 0\n\t\t) {\n\t\t\tprimaryInterfaceName = buildTypeName(variationName, \"Primary\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"primary\",\n\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\tconst primaryFieldProperties = buildFieldProperties({\n\t\t\t\tfields: variationModel.primary,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\n\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\n\n\t\t\tconst docs = stripIndent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\tprimaryFieldProperties.code\n\t\t\t\t\t? source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {\n\t\t\t\t\t\t\t${primaryFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tlet itemInterfaceName: string | undefined;\n\t\tif (variationModel.items && Object.keys(variationModel.items).length > 0) {\n\t\t\titemInterfaceName = buildTypeName(variationName, \"Item\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"items\",\n\t\t\t\t\tlabel: \"Items\",\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: variationModel.items,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\n\n\t\t\tconst docs = stripIndent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\titemFieldProperties.code\n\t\t\t\t\t? source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {\n\t\t\t\t\t\t\t${itemFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\t/**\n\t\t\t\t * ${variationModel.name} variation for ${humanReadableName} Slice\n\t\t\t\t *\n\t\t\t\t * - **API ID**: \\`${variationModel.id}\\`\n\t\t\t\t * - **Description**: ${variationModel.description || \"*None*\"}\n\t\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t\t */\n\t\t\t\texport type ${variationName} = prismic.SharedSliceVariation<\"${\n\t\t\t\tvariationModel.id\n\t\t\t}\", ${\n\t\t\t\tprimaryInterfaceName\n\t\t\t\t\t? `Simplify<${primaryInterfaceName}>`\n\t\t\t\t\t: `Record<string, never>`\n\t\t\t}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\n\t\tvariationNames.push(variationName);\n\t}\n\n\tconst variationUnionName = buildTypeName(name, \"Variation\");\n\tconst variationsUnion = buildUnion(variationNames);\n\n\tcontentTypeNames.push(variationUnionName);\n\tcontentTypeNames.push(...variationNames);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * Slice variation for *${humanReadableName}*\n\t\t\t */\n\t\t\ttype ${variationUnionName} = ${\n\t\t\tvariationNames.length > 0 ? variationsUnion : \"never\"\n\t\t}\n\t\t`,\n\t\tcode,\n\t);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} Shared Slice\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Description**: ${args.model.description || \"*None*\"}\n\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t */\n\t\t\texport type ${name} = prismic.SharedSlice<\"${\n\t\t\targs.model.id\n\t\t}\", ${variationUnionName}>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tvariationNames,\n\t\tcode,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":["getCacheKey","buildTypeName","getHumanReadableModelName","getHumanReadablePath","buildFieldProperties","stripIndent","addSection","source","SHARED_SLICES_DOCUMENTATION_URL","buildUnion"],"mappings":";;;;;;;;;;;AA6BM,SAAU,qBACf,MAA8B;AAE9B,MAAI,KAAK,OAAO;AACf,UAAM,MAAMA,YAAAA,YAAY,CAAC,KAAK,OAAO,KAAK,YAAY,CAAC;AACvD,UAAM,SAAS,KAAK,MAAM,IAAI,GAAG;AAEjC,QAAI,QAAQ;AACJ,aAAA;AAAA,IACP;AAAA,EACD;AAED,MAAI,OAAO;AACX,QAAM,mBAA6B,CAAA;AAEnC,QAAM,OAAOC,cAAAA,cAAc,KAAK,MAAM,IAAI,OAAO;AACjD,QAAM,oBAAoBC,0BAAAA,0BAA0B;AAAA,IACnD,MAAM,KAAK,MAAM;AAAA,IACjB,OAAO,KAAK;AAAA,EAAA,CACZ;AAED,QAAM,iBAA2B,CAAA;AACtB,aAAA,kBAAkB,KAAK,MAAM,YAAY;AACnD,UAAM,gBAAgBD,cAAA,cAAc,MAAM,eAAe,EAAE;AAEvD,QAAA;AAEH,QAAA,eAAe,WACf,OAAO,KAAK,eAAe,OAAO,EAAE,SAAS,GAC5C;AACsB,6BAAAA,cAAA,cAAc,eAAe,SAAS;AAE7D,YAAM,OAAkB;AAAA,QACvB;AAAA,UACC,MAAM,KAAK,MAAM;AAAA,UACjB,OAAO,KAAK;AAAA,QACZ;AAAA,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,IAAI;AAAA,IAEL;AAED,WAAOD,WACN,WAAAC;;SAEM,eAAe,sBAAsB;AAAA;AAAA,yBAErB,eAAe;AAAA,4BACZ,eAAe,eAAe;AAAA,8BAC5BC;;kBAEZ,iDACd,eAAe,QAEf,uBACG,YAAY,0BACZ,4BACC,oBAAoB,YAAY,uBAAuB;AAAA,MAE5D,IAAI;AAGL,mBAAe,KAAK,aAAa;AAAA,EACjC;AAEK,QAAA,qBAAqBP,cAAAA,cAAc,MAAM,WAAW;AACpD,QAAA,kBAAkBQ,sBAAW,cAAc;AAEjD,mBAAiB,KAAK,kBAAkB;AACvB,mBAAA,KAAK,GAAG,cAAc;AAEvC,SAAOH,WACN,WAAAC;;6BAE2B;AAAA;AAAA,UAEnB,wBACP,eAAe,SAAS,IAAI,kBAAkB;AAAA,KAG/C,IAAI;AAGL,SAAOD,WACN,WAAAC;;QAEM;AAAA;AAAA,wBAEgB,KAAK,MAAM;AAAA,2BACR,KAAK,MAAM,eAAe;AAAA,6BACxBC;;iBAEZ,+BACd,KAAK,MAAM,QACN;AAAA,KAEN,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACf,UAAM,MAAMR,YAAAA,YAAY,CAAC,KAAK,OAAO,KAAK,YAAY,CAAC;AAElD,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;;"}
|
|
@@ -8,9 +8,9 @@ type BuildSharedSliceTypeArgs = {
|
|
|
8
8
|
};
|
|
9
9
|
type BuildSharedSliceTypeReturnValue = {
|
|
10
10
|
name: string;
|
|
11
|
-
variationUnionName: string;
|
|
12
11
|
variationNames: string[];
|
|
13
12
|
code: string;
|
|
13
|
+
contentTypeNames: string[];
|
|
14
14
|
};
|
|
15
15
|
export declare function buildSharedSliceType(args: BuildSharedSliceTypeArgs): BuildSharedSliceTypeReturnValue;
|
|
16
16
|
export {};
|
|
@@ -16,6 +16,7 @@ function buildSharedSliceType(args) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
let code = "";
|
|
19
|
+
const contentTypeNames = [];
|
|
19
20
|
const name = buildTypeName(args.model.id, "Slice");
|
|
20
21
|
const humanReadableName = getHumanReadableModelName({
|
|
21
22
|
name: args.model.id,
|
|
@@ -43,6 +44,7 @@ function buildSharedSliceType(args) {
|
|
|
43
44
|
fieldConfigs: args.fieldConfigs,
|
|
44
45
|
path
|
|
45
46
|
});
|
|
47
|
+
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
46
48
|
const docs = stripIndent`
|
|
47
49
|
/**
|
|
48
50
|
* Primary content in *${humanReadablePath}*
|
|
@@ -77,6 +79,7 @@ function buildSharedSliceType(args) {
|
|
|
77
79
|
fieldConfigs: args.fieldConfigs,
|
|
78
80
|
path
|
|
79
81
|
});
|
|
82
|
+
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
80
83
|
const docs = stripIndent`
|
|
81
84
|
/**
|
|
82
85
|
* Primary content in *${humanReadablePath}*
|
|
@@ -106,6 +109,8 @@ function buildSharedSliceType(args) {
|
|
|
106
109
|
}
|
|
107
110
|
const variationUnionName = buildTypeName(name, "Variation");
|
|
108
111
|
const variationsUnion = buildUnion(variationNames);
|
|
112
|
+
contentTypeNames.push(variationUnionName);
|
|
113
|
+
contentTypeNames.push(...variationNames);
|
|
109
114
|
code = addSection(source`
|
|
110
115
|
/**
|
|
111
116
|
* Slice variation for *${humanReadableName}*
|
|
@@ -124,9 +129,9 @@ function buildSharedSliceType(args) {
|
|
|
124
129
|
`, code);
|
|
125
130
|
const result = {
|
|
126
131
|
name,
|
|
127
|
-
variationUnionName,
|
|
128
132
|
variationNames,
|
|
129
|
-
code
|
|
133
|
+
code,
|
|
134
|
+
contentTypeNames
|
|
130
135
|
};
|
|
131
136
|
if (args.cache) {
|
|
132
137
|
const key = getCacheKey([args.model, args.fieldConfigs]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildSharedSliceType.js","sources":["../../../src/lib/buildSharedSliceType.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { FieldConfigs, FieldPath } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildSharedSliceTypeArgs = {\n\tmodel: SharedSliceModel;\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildSharedSliceTypeReturnValue = {\n\tname: string;\n\
|
|
1
|
+
{"version":3,"file":"buildSharedSliceType.js","sources":["../../../src/lib/buildSharedSliceType.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\nimport QuickLRU from \"quick-lru\";\n\nimport { FieldConfigs, FieldPath } from \"../types\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\n\nimport { addSection } from \"./addSection\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildSharedSliceTypeArgs = {\n\tmodel: SharedSliceModel;\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildSharedSliceTypeReturnValue = {\n\tname: string;\n\tvariationNames: string[];\n\tcode: string;\n\tcontentTypeNames: string[];\n};\n\nexport function buildSharedSliceType(\n\targs: BuildSharedSliceTypeArgs,\n): BuildSharedSliceTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildSharedSliceTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Slice\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst variationNames: string[] = [];\n\tfor (const variationModel of args.model.variations) {\n\t\tconst variationName = buildTypeName(name, variationModel.id);\n\n\t\tlet primaryInterfaceName: string | undefined;\n\t\tif (\n\t\t\tvariationModel.primary &&\n\t\t\tObject.keys(variationModel.primary).length > 0\n\t\t) {\n\t\t\tprimaryInterfaceName = buildTypeName(variationName, \"Primary\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"primary\",\n\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\tconst primaryFieldProperties = buildFieldProperties({\n\t\t\t\tfields: variationModel.primary,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\n\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\n\n\t\t\tconst docs = stripIndent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\tprimaryFieldProperties.code\n\t\t\t\t\t? source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {\n\t\t\t\t\t\t\t${primaryFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tlet itemInterfaceName: string | undefined;\n\t\tif (variationModel.items && Object.keys(variationModel.items).length > 0) {\n\t\t\titemInterfaceName = buildTypeName(variationName, \"Item\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"items\",\n\t\t\t\t\tlabel: \"Items\",\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: variationModel.items,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\n\n\t\t\tconst docs = stripIndent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\titemFieldProperties.code\n\t\t\t\t\t? source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {\n\t\t\t\t\t\t\t${itemFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: source`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tsource`\n\t\t\t\t/**\n\t\t\t\t * ${variationModel.name} variation for ${humanReadableName} Slice\n\t\t\t\t *\n\t\t\t\t * - **API ID**: \\`${variationModel.id}\\`\n\t\t\t\t * - **Description**: ${variationModel.description || \"*None*\"}\n\t\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t\t */\n\t\t\t\texport type ${variationName} = prismic.SharedSliceVariation<\"${\n\t\t\t\tvariationModel.id\n\t\t\t}\", ${\n\t\t\t\tprimaryInterfaceName\n\t\t\t\t\t? `Simplify<${primaryInterfaceName}>`\n\t\t\t\t\t: `Record<string, never>`\n\t\t\t}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\n\t\tvariationNames.push(variationName);\n\t}\n\n\tconst variationUnionName = buildTypeName(name, \"Variation\");\n\tconst variationsUnion = buildUnion(variationNames);\n\n\tcontentTypeNames.push(variationUnionName);\n\tcontentTypeNames.push(...variationNames);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * Slice variation for *${humanReadableName}*\n\t\t\t */\n\t\t\ttype ${variationUnionName} = ${\n\t\t\tvariationNames.length > 0 ? variationsUnion : \"never\"\n\t\t}\n\t\t`,\n\t\tcode,\n\t);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} Shared Slice\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Description**: ${args.model.description || \"*None*\"}\n\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t */\n\t\t\texport type ${name} = prismic.SharedSlice<\"${\n\t\t\targs.model.id\n\t\t}\", ${variationUnionName}>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tvariationNames,\n\t\tcode,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"names":[],"mappings":";;;;;;;;;AA6BM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AA,iBAEZ,+BACd,KAAK,MAAM,QACN;AAAA,KAEN,IAAI;AAGL,QAAM,SAAS;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAGD,MAAI,KAAK,OAAO;AACf,UAAM,MAAM,YAAY,CAAC,KAAK,OAAO,KAAK,YAAY,CAAC;AAElD,SAAA,MAAM,IAAI,KAAK,MAAM;AAAA,EAC1B;AAEM,SAAA;AACR;"}
|
package/package.json
CHANGED
package/src/generateTypes.ts
CHANGED
|
@@ -81,7 +81,7 @@ export function generateTypes(config: GenerateTypesConfig = {}): string {
|
|
|
81
81
|
allDocumentTypesTypeNames.push(customTypeType.name);
|
|
82
82
|
|
|
83
83
|
contentTypeNames.push(customTypeType.name);
|
|
84
|
-
contentTypeNames.push(customTypeType.
|
|
84
|
+
contentTypeNames.push(...customTypeType.contentTypeNames);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
if (config.customTypeModels.length > 0) {
|
|
@@ -108,8 +108,7 @@ export function generateTypes(config: GenerateTypesConfig = {}): string {
|
|
|
108
108
|
code = addSection(sharedSliceType.code, code);
|
|
109
109
|
|
|
110
110
|
contentTypeNames.push(sharedSliceType.name);
|
|
111
|
-
contentTypeNames.push(sharedSliceType.
|
|
112
|
-
contentTypeNames.push(...sharedSliceType.variationNames);
|
|
111
|
+
contentTypeNames.push(...sharedSliceType.contentTypeNames);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -17,6 +17,7 @@ type BuildCustomTypeDataTypeReturnValue = {
|
|
|
17
17
|
name: string;
|
|
18
18
|
code: string;
|
|
19
19
|
auxiliaryTypes: AuxiliaryType[];
|
|
20
|
+
contentTypeNames: string[];
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export function buildCustomTypeDataType(
|
|
@@ -24,6 +25,7 @@ export function buildCustomTypeDataType(
|
|
|
24
25
|
): BuildCustomTypeDataTypeReturnValue {
|
|
25
26
|
let code = "";
|
|
26
27
|
const auxiliaryTypes: AuxiliaryType[] = [];
|
|
28
|
+
const contentTypeNames: string[] = [];
|
|
27
29
|
|
|
28
30
|
const name = buildTypeName(args.model.id, "Document", "Data");
|
|
29
31
|
const humanReadableName = getHumanReadableModelName({
|
|
@@ -51,6 +53,7 @@ export function buildCustomTypeDataType(
|
|
|
51
53
|
fieldProperties += tabFieldProperties.code;
|
|
52
54
|
|
|
53
55
|
auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
|
|
56
|
+
contentTypeNames.push(...tabFieldProperties.contentTypeNames);
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
if (fieldProperties) {
|
|
@@ -70,5 +73,6 @@ export function buildCustomTypeDataType(
|
|
|
70
73
|
name,
|
|
71
74
|
code,
|
|
72
75
|
auxiliaryTypes,
|
|
76
|
+
contentTypeNames,
|
|
73
77
|
};
|
|
74
78
|
}
|
|
@@ -23,9 +23,9 @@ type BuildCustomTypeTypesArgs = {
|
|
|
23
23
|
|
|
24
24
|
type BuildCustomTypeTypeReturnValue = {
|
|
25
25
|
name: string;
|
|
26
|
-
dataName: string;
|
|
27
26
|
code: string;
|
|
28
27
|
auxiliaryTypes: AuxiliaryType[];
|
|
28
|
+
contentTypeNames: string[];
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export function buildCustomTypeType(
|
|
@@ -43,6 +43,7 @@ export function buildCustomTypeType(
|
|
|
43
43
|
let code = "";
|
|
44
44
|
|
|
45
45
|
const auxiliaryTypes: AuxiliaryType[] = [];
|
|
46
|
+
const contentTypeNames: string[] = [];
|
|
46
47
|
|
|
47
48
|
const name = buildTypeName(args.model.id, "Document");
|
|
48
49
|
const langDefault =
|
|
@@ -63,6 +64,8 @@ export function buildCustomTypeType(
|
|
|
63
64
|
});
|
|
64
65
|
|
|
65
66
|
auxiliaryTypes.push(...dataType.auxiliaryTypes);
|
|
67
|
+
contentTypeNames.push(dataType.name);
|
|
68
|
+
contentTypeNames.push(...dataType.contentTypeNames);
|
|
66
69
|
|
|
67
70
|
code = addSection(dataType.code, code);
|
|
68
71
|
|
|
@@ -86,9 +89,9 @@ export function buildCustomTypeType(
|
|
|
86
89
|
|
|
87
90
|
const result = {
|
|
88
91
|
name,
|
|
89
|
-
dataName: dataType.name,
|
|
90
92
|
code,
|
|
91
93
|
auxiliaryTypes,
|
|
94
|
+
contentTypeNames,
|
|
92
95
|
};
|
|
93
96
|
|
|
94
97
|
if (args.cache) {
|
|
@@ -21,6 +21,7 @@ type BuildFieldPropertyArgs = Pick<
|
|
|
21
21
|
type BuildFieldPropertyReturnType = {
|
|
22
22
|
code: string;
|
|
23
23
|
auxiliaryTypes: AuxiliaryType[];
|
|
24
|
+
contentTypeNames: string[];
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
function buildFieldProperty(
|
|
@@ -34,6 +35,7 @@ function buildFieldProperty(
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
const auxiliaryTypes: AuxiliaryType[] = [];
|
|
38
|
+
const contentTypeNames: string[] = [];
|
|
37
39
|
|
|
38
40
|
const name =
|
|
39
41
|
args.name.includes("-") ||
|
|
@@ -450,6 +452,7 @@ function buildFieldProperty(
|
|
|
450
452
|
name: choiceUnionName,
|
|
451
453
|
code: `type ${choiceUnionName} = ${choiceUnion}`,
|
|
452
454
|
});
|
|
455
|
+
contentTypeNames.push(choiceUnionName);
|
|
453
456
|
|
|
454
457
|
code = addLine(`${name}: prismic.SliceZone<${choiceUnionName}>;`, code);
|
|
455
458
|
|
|
@@ -464,6 +467,7 @@ function buildFieldProperty(
|
|
|
464
467
|
return {
|
|
465
468
|
code,
|
|
466
469
|
auxiliaryTypes,
|
|
470
|
+
contentTypeNames,
|
|
467
471
|
};
|
|
468
472
|
}
|
|
469
473
|
|
|
@@ -477,6 +481,7 @@ type BuildFieldPropertiesArgs = {
|
|
|
477
481
|
type BuildFieldPropertiesReturnType = {
|
|
478
482
|
code: string;
|
|
479
483
|
auxiliaryTypes: AuxiliaryType[];
|
|
484
|
+
contentTypeNames: string[];
|
|
480
485
|
};
|
|
481
486
|
|
|
482
487
|
export function buildFieldProperties(
|
|
@@ -485,6 +490,7 @@ export function buildFieldProperties(
|
|
|
485
490
|
let code = "";
|
|
486
491
|
|
|
487
492
|
const auxiliaryTypes: AuxiliaryType[] = [];
|
|
493
|
+
const contentTypeNames: string[] = [];
|
|
488
494
|
|
|
489
495
|
for (const name in args.fields) {
|
|
490
496
|
const field = args.fields[name];
|
|
@@ -500,10 +506,12 @@ export function buildFieldProperties(
|
|
|
500
506
|
code = addSection(fieldProperty.code, code);
|
|
501
507
|
|
|
502
508
|
auxiliaryTypes.push(...fieldProperty.auxiliaryTypes);
|
|
509
|
+
contentTypeNames.push(...fieldProperty.contentTypeNames);
|
|
503
510
|
}
|
|
504
511
|
|
|
505
512
|
return {
|
|
506
513
|
code,
|
|
507
514
|
auxiliaryTypes,
|
|
515
|
+
contentTypeNames,
|
|
508
516
|
};
|
|
509
517
|
}
|
|
@@ -22,9 +22,9 @@ type BuildSharedSliceTypeArgs = {
|
|
|
22
22
|
|
|
23
23
|
type BuildSharedSliceTypeReturnValue = {
|
|
24
24
|
name: string;
|
|
25
|
-
variationUnionName: string;
|
|
26
25
|
variationNames: string[];
|
|
27
26
|
code: string;
|
|
27
|
+
contentTypeNames: string[];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export function buildSharedSliceType(
|
|
@@ -40,6 +40,7 @@ export function buildSharedSliceType(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
let code = "";
|
|
43
|
+
const contentTypeNames: string[] = [];
|
|
43
44
|
|
|
44
45
|
const name = buildTypeName(args.model.id, "Slice");
|
|
45
46
|
const humanReadableName = getHumanReadableModelName({
|
|
@@ -76,6 +77,8 @@ export function buildSharedSliceType(
|
|
|
76
77
|
path,
|
|
77
78
|
});
|
|
78
79
|
|
|
80
|
+
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
81
|
+
|
|
79
82
|
const docs = stripIndent`
|
|
80
83
|
/**
|
|
81
84
|
* Primary content in *${humanReadablePath}*
|
|
@@ -120,6 +123,8 @@ export function buildSharedSliceType(
|
|
|
120
123
|
path,
|
|
121
124
|
});
|
|
122
125
|
|
|
126
|
+
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
127
|
+
|
|
123
128
|
const docs = stripIndent`
|
|
124
129
|
/**
|
|
125
130
|
* Primary content in *${humanReadablePath}*
|
|
@@ -168,6 +173,9 @@ export function buildSharedSliceType(
|
|
|
168
173
|
const variationUnionName = buildTypeName(name, "Variation");
|
|
169
174
|
const variationsUnion = buildUnion(variationNames);
|
|
170
175
|
|
|
176
|
+
contentTypeNames.push(variationUnionName);
|
|
177
|
+
contentTypeNames.push(...variationNames);
|
|
178
|
+
|
|
171
179
|
code = addSection(
|
|
172
180
|
source`
|
|
173
181
|
/**
|
|
@@ -198,9 +206,9 @@ export function buildSharedSliceType(
|
|
|
198
206
|
|
|
199
207
|
const result = {
|
|
200
208
|
name,
|
|
201
|
-
variationUnionName,
|
|
202
209
|
variationNames,
|
|
203
210
|
code,
|
|
211
|
+
contentTypeNames,
|
|
204
212
|
};
|
|
205
213
|
|
|
206
214
|
if (args.cache) {
|