prismic-ts-codegen 0.1.26 → 0.1.27-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/_node_modules/@prismicio/client/dist/Client.cjs +2 -1
  2. package/dist/_node_modules/@prismicio/client/dist/Client.cjs.map +1 -1
  3. package/dist/_node_modules/@prismicio/client/dist/Client.js +2 -1
  4. package/dist/_node_modules/@prismicio/client/dist/Client.js.map +1 -1
  5. package/dist/_node_modules/@prismicio/client/dist/lib/throttledLog.cjs +17 -0
  6. package/dist/_node_modules/@prismicio/client/dist/lib/throttledLog.cjs.map +1 -0
  7. package/dist/_node_modules/@prismicio/client/dist/lib/throttledLog.js +17 -0
  8. package/dist/_node_modules/@prismicio/client/dist/lib/throttledLog.js.map +1 -0
  9. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs +1 -1
  10. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs.map +1 -1
  11. package/dist/_node_modules/@prismicio/client/dist/package.json.js +1 -1
  12. package/dist/_node_modules/@prismicio/client/dist/package.json.js.map +1 -1
  13. package/dist/_node_modules/map-obj/index.cjs +1 -1
  14. package/dist/_node_modules/map-obj/index.js +1 -1
  15. package/dist/_node_modules/minimist-options/index.cjs +1 -1
  16. package/dist/_node_modules/minimist-options/index.js +1 -1
  17. package/dist/_virtual/index2.cjs +2 -2
  18. package/dist/_virtual/index2.js +2 -2
  19. package/dist/_virtual/index3.cjs +2 -2
  20. package/dist/_virtual/index3.js +2 -2
  21. package/dist/generateTypes.cjs +44 -0
  22. package/dist/generateTypes.cjs.map +1 -1
  23. package/dist/generateTypes.js +44 -0
  24. package/dist/generateTypes.js.map +1 -1
  25. package/dist/lib/buildFieldProperties.cjs +7 -2
  26. package/dist/lib/buildFieldProperties.cjs.map +1 -1
  27. package/dist/lib/buildFieldProperties.js +7 -2
  28. package/dist/lib/buildFieldProperties.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/generateTypes.ts +48 -0
  31. package/src/lib/buildFieldProperties.ts +20 -6
@@ -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.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\tfor (const auxiliaryType of sharedSliceType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration<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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration;\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":[],"mappings":";;;;;;;AAcA,MAAM,QAAQ,IAAI,SAA0B,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;AAEvB,SAAO,QAAQ,kCAAkC,aAAa,MAAM,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAInB,aAAO,QACN,oBAAoB,gBAAgB,8BACpC,IAAI;AAAA,IAEN;AAAA,EACD;AAEO,SAAA,WACN,4DACA,IAAI;AAGL,QAAM,mBAA6B,CAAA;AAEnC,MAAI,OAAO,kBAAkB;AAC5B,UAAM,4BAAsC,CAAA;AAEjC,eAAA,SAAS,OAAO,kBAAkB;AAC5C,YAAM,iBAAiB,oBAAoB;AAAA,QAC1C;AAAA,QACA,WAAW,OAAO;AAAA,QAClB;AAAA,QACA,OAAO,iBAAiB,QAAQ;AAAA,MAAA,CAChC;AAEU,iBAAA,iBAAiB,eAAe,gBAAgB;AACnD,eAAA,WAAW,cAAc,MAAM,IAAI;AAAA,MAC3C;AAEO,aAAA,WAAW,eAAe,MAA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BAAmB,WAClB;AAAA,gDAC2C,gBAAgB,wBAAwB,gBAAgB;AAAA,IAEnG,gBAAgB;AAEjB,2BAAmB,WAClB;AAAA,OACE,gBAAgB;AAAA,IAElB,gBAAgB;AAAA,MAElB;AAAA,IACD;AAEI,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmB,WAClB;AAAA;AAAA;AAAA,SAGK,iBAAiB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA,OAIjC,gBAAgB;AAAA,IAElB;AAEA,WAAO,WACN;AAAA;AAAA,OAEI,gBAAgB;AAAA;AAAA,MAGpB,IAAI;AAAA,EAEN;AAEO,SAAA;AACR;"}
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\tcode = addSection(\n\t\t`\ntype PickNewContentRelationshipFieldData<\n\tTRelationship extends prismic.CustomTypeLevel1 | prismic.CustomTypeLevel2 | prismic.GroupLevel1 | prismic.GroupLevel2,\n\tTData extends Record<string, prismic.AnyRegularField | prismic.GroupField | prismic.NestedGroupField | prismic.SliceZone>,\n\tTLang extends string\n> = |\n\t// Content relationship fields\n\t{\n\t\t[TSubRelationship in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.ContentRelationshipLevel1\n\t\t> as TSubRelationship[\"id\"]]:\n\t\t\tNewContentRelationshipField<TSubRelationship[\"customtypes\"], TLang>;\n\t} &\n\t// Group\n\t{\n\t\t[TGroup in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.GroupLevel1 | prismic.GroupLevel2\n\t\t> as TGroup[\"id\"]]:\n\t\t\tTData[TGroup[\"id\"]] extends prismic.GroupField<infer TGroupData>\n\t\t\t\t? prismic.GroupField<PickNewContentRelationshipFieldData<TGroup, TGroupData, TLang>>\n\t\t\t\t: never\n\t} &\n\t// Other fields\n\t{\n\t\t[TFieldKey in Extract<TRelationship[\"fields\"][number], string>]:\n\t\t\tTFieldKey extends keyof TData ? TData[TFieldKey] : never;\n\t};\n\ntype NewContentRelationshipField<\n\tTCustomType extends readonly (prismic.CustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeLevel2 | string)[],\n\tTLang extends string = string\n> = {\n\t[ID in Exclude<TCustomType[number], string>[\"id\"]]:\n\t\tprismic.ContentRelationshipField<\n\t\t\tID,\n\t\t\tTLang,\n\t\t\tPickNewContentRelationshipFieldData<\n\t\t\t\tExtract<TCustomType[number], { id: ID }>,\n\t\t\t\tExtract<prismic.Content.AllDocumentTypes, { type: ID }>[\"data\"],\n\t\t\t\tTLang\n\t\t\t>\n\t\t>\n}[Exclude<TCustomType[number], string>[\"id\"]];\n`,\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\tfor (const auxiliaryType of sharedSliceType.auxiliaryTypes) {\n\t\t\t\tcode = addSection(auxiliaryType.code, code);\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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration<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\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateWriteClient {\n\t(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;\n}`,\n\t\t\t\t\tclientModuleCode,\n\t\t\t\t);\n\t\t\t\tclientModuleCode = addSection(\n\t\t\t\t\t`interface CreateMigration {\n\t(): ${clientImportName}.Migration;\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":[],"mappings":";;;;;;;AAcA,MAAM,QAAQ,IAAI,SAA0B,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;AAEvB,SAAO,QAAQ,kCAAkC,aAAa,MAAM,IAAI;AAExE,QACC,YAAO,sBAAP,mBAA0B,mCAC1B,YAAO,sBAAP,mBAA0B,0BACzB;AACD,QAAI,kBAAkB,qBAAqB;AACvB,yBAAA;AAInB,aAAO,QACN,oBAAoB,gBAAgB,8BACpC,IAAI;AAAA,IAEN;AAAA,EACD;AAEO,SAAA,WACN,4DACA,IAAI;AAGL,SAAO,WACN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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A,KAAK,GAAG,gBAAgB,gBAAgB;AAAA,IAC1D;AAAA,EACD;AAEA,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,gBAAgB,mBAAmB,gBAAgB;AAAA,IAE9F,gBAAgB;AAEjB,2BAAmB,WAClB;AAAA,+CAC0C,gBAAgB,wBAAwB,gBAAgB;AAAA,IAElG,gBAAgB;AAEjB,2BAAmB,WAClB;AAAA,OACE,gBAAgB;AAAA,IAElB,gBAAgB;AAAA,MAAA,OAEX;AACN,2BAAmB,WAClB;AAAA,gDAC2C,gBAAgB,mBAAmB,gBAAgB;AAAA,IAE9F,gBAAgB;AAEjB,2BAAmB,WAClB;AAAA,gDAC2C,gBAAgB,wBAAwB,gBAAgB;AAAA,IAEnG,gBAAgB;AAEjB,2BAAmB,WAClB;AAAA,OACE,gBAAgB;AAAA,IAElB,gBAAgB;AAAA,MAElB;AAAA,IACD;AAEI,QAAA,OAAO,kBAAkB,yBAAyB;AACrD,yBAAmB,WAClB;AAAA;AAAA;AAAA,SAGK,iBAAiB,KAAK,KAAK,CAAC;AAAA;AAAA;AAAA,OAIjC,gBAAgB;AAAA,IAElB;AAEA,WAAO,WACN;AAAA;AAAA,OAEI,gBAAgB;AAAA;AAAA,MAGpB,IAAI;AAAA,EAEN;AAEO,SAAA;AACR;"}
@@ -74,8 +74,13 @@ function buildFieldProperty(args) {
74
74
  switch ((_h = args.field.config) == null ? void 0 : _h.select) {
75
75
  case "document": {
76
76
  if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
77
- const customTypeIDsUnion = buildUnion.buildUnion(args.field.config.customtypes.map((type) => `"${type}"`));
78
- code = addLine.addLine(`${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`, code);
77
+ const customTypeIDs = args.field.config.customtypes.filter((type) => typeof type === "string").map((type) => `"${type}"`);
78
+ const customTypeObjects = args.field.config.customtypes.filter((type) => typeof type !== "string");
79
+ const contentRelationshipUnion = buildUnion.buildUnion([
80
+ customTypeIDs.length ? `prismic.ContentRelationshipField<${buildUnion.buildUnion(customTypeIDs)}>` : "",
81
+ customTypeObjects.length ? `NewContentRelationshipField<${JSON.stringify(customTypeObjects)}>` : ""
82
+ ]);
83
+ code = addLine.addLine(`${name}: ${contentRelationshipUnion};`, code);
79
84
  } else {
80
85
  code = addLine.addLine(`${name}: prismic.ContentRelationshipField;`, code);
81
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"buildFieldProperties.cjs","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import {\n\ttype CustomTypeModelField,\n\tCustomTypeModelFieldType,\n} from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\n\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildFieldPropertyArgs = Pick<\n\tBuildFieldPropertiesArgs,\n\t\"path\" | \"fieldConfigs\" | \"tabName\"\n> & {\n\tname: string;\n\tfield: CustomTypeModelField;\n};\n\ntype BuildFieldPropertyReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\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\tconst variants =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"variants\" in args.field.config &&\n\t\t\t\tArray.isArray(args.field.config.variants) &&\n\t\t\t\targs.field.config.variants.length > 0\n\t\t\t\t\t? args.field.config.variants\n\t\t\t\t\t\t\t.map((variant) => `\"${variant.replace(/\\\"/g, '\\\\\"')}\"`)\n\t\t\t\t\t\t\t.join(\" | \")\n\t\t\t\t\t: \"never\";\n\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(\n\t\t\t\t\t\t`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tlet type = `prismic.LinkField<string, string, unknown, prismic.FieldState, ${variants}>`;\n\n\t\t\t\t\tif (args.field.config?.repeat) {\n\t\t\t\t\t\ttype = `prismic.Repeatable<${type}>`;\n\t\t\t\t\t}\n\n\t\t\t\t\tcode = addLine(`${name}: ${type};`, code);\n\t\t\t\t\tbreak;\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\tcode = addLine(`${name}: prismic.RichTextField;`, code);\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 \"Table\": {\n\t\t\tcode = addLine(`${name}: prismic.TableField;`, code);\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 groupPathParts = args.path.filter(\n\t\t\t\t(part) =>\n\t\t\t\t\tpart.model !== undefined &&\n\t\t\t\t\t\"type\" in part.model &&\n\t\t\t\t\tpart.model.type === CustomTypeModelFieldType.Group,\n\t\t\t);\n\t\t\tconst isNestedGroup = groupPathParts.length > 0;\n\n\t\t\tlet itemName;\n\t\t\tif (\n\t\t\t\targs.path[0].model &&\n\t\t\t\t\"type\" in args.path[0].model &&\n\t\t\t\targs.path[0].model.type === \"SharedSlice\"\n\t\t\t) {\n\t\t\t\tconst [slicePathPart, variationPathPart, zonePathPart] = args.path;\n\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\tslicePathPart.name,\n\t\t\t\t\t\"Slice\",\n\t\t\t\t\tvariationPathPart.name,\n\t\t\t\t\tzonePathPart.name,\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\targs.path[0].name,\n\t\t\t\t\t\"Document\",\n\t\t\t\t\t\"Data\",\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\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\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\t\t\tcontentTypeNames.push(itemName);\n\n\t\t\tif (isNestedGroup) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`,\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.GroupField<Simplify<${itemName}>>;`,\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 \"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\t\t\t\t\t\t\tauxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(primaryInterfaceName);\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\t\t\t\t\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(itemInterfaceName);\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","CustomTypeModelFieldType","buildTypeName","getHumanReadablePath","source","stripIndent","addSection"],"mappings":";;;;;;;;;;AA6BA,SAAS,mBACR,MAA4B;;AAE5B,MAAI,OAAOA,eAAAA,eAAe;AAAA,IACzB,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,EA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;AAEX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAExB,aAAA,QAAQ,KAAK,QAAQ;AACzB,UAAA,QAAQ,KAAK,OAAO,IAAI;AAE9B,UAAM,gBAAgB,mBAAmB;AAAA,MACxC;AAAA,MACA;AAAA,MACA,MAAM,KAAK;AAAA,MACX,cAAc,KAAK;AAAA,MACnB,SAAS,KAAK;AAAA,IAAA,CACd;AAEM,WAAAO,WAAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAClC,qBAAA,KAAK,GAAG,cAAc,gBAAgB;AAAA,EACxD;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;;"}
1
+ {"version":3,"file":"buildFieldProperties.cjs","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import {\n\ttype CustomTypeModelField,\n\tCustomTypeModelFieldType,\n} from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\n\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildFieldPropertyArgs = Pick<\n\tBuildFieldPropertiesArgs,\n\t\"path\" | \"fieldConfigs\" | \"tabName\"\n> & {\n\tname: string;\n\tfield: CustomTypeModelField;\n};\n\ntype BuildFieldPropertyReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\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\tconst variants =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"variants\" in args.field.config &&\n\t\t\t\tArray.isArray(args.field.config.variants) &&\n\t\t\t\targs.field.config.variants.length > 0\n\t\t\t\t\t? args.field.config.variants\n\t\t\t\t\t\t\t.map((variant) => `\"${variant.replace(/\\\"/g, '\\\\\"')}\"`)\n\t\t\t\t\t\t\t.join(\" | \")\n\t\t\t\t\t: \"never\";\n\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 customTypeIDs = args.field.config.customtypes\n\t\t\t\t\t\t\t.filter((type) => typeof type === \"string\")\n\t\t\t\t\t\t\t.map((type) => `\"${type}\"`);\n\n\t\t\t\t\t\tconst customTypeObjects = args.field.config.customtypes.filter(\n\t\t\t\t\t\t\t(type) => typeof type !== \"string\",\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst contentRelationshipUnion = buildUnion([\n\t\t\t\t\t\t\tcustomTypeIDs.length\n\t\t\t\t\t\t\t\t? `prismic.ContentRelationshipField<${buildUnion(\n\t\t\t\t\t\t\t\t\t\tcustomTypeIDs,\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\tcustomTypeObjects.length\n\t\t\t\t\t\t\t\t? `NewContentRelationshipField<${JSON.stringify(\n\t\t\t\t\t\t\t\t\t\tcustomTypeObjects,\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]);\n\n\t\t\t\t\t\tcode = addLine(`${name}: ${contentRelationshipUnion};`, code);\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(\n\t\t\t\t\t\t`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tlet type = `prismic.LinkField<string, string, unknown, prismic.FieldState, ${variants}>`;\n\n\t\t\t\t\tif (args.field.config?.repeat) {\n\t\t\t\t\t\ttype = `prismic.Repeatable<${type}>`;\n\t\t\t\t\t}\n\n\t\t\t\t\tcode = addLine(`${name}: ${type};`, code);\n\t\t\t\t\tbreak;\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\tcode = addLine(`${name}: prismic.RichTextField;`, code);\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 \"Table\": {\n\t\t\tcode = addLine(`${name}: prismic.TableField;`, code);\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 groupPathParts = args.path.filter(\n\t\t\t\t(part) =>\n\t\t\t\t\tpart.model !== undefined &&\n\t\t\t\t\t\"type\" in part.model &&\n\t\t\t\t\tpart.model.type === CustomTypeModelFieldType.Group,\n\t\t\t);\n\t\t\tconst isNestedGroup = groupPathParts.length > 0;\n\n\t\t\tlet itemName;\n\t\t\tif (\n\t\t\t\targs.path[0].model &&\n\t\t\t\t\"type\" in args.path[0].model &&\n\t\t\t\targs.path[0].model.type === \"SharedSlice\"\n\t\t\t) {\n\t\t\t\tconst [slicePathPart, variationPathPart, zonePathPart] = args.path;\n\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\tslicePathPart.name,\n\t\t\t\t\t\"Slice\",\n\t\t\t\t\tvariationPathPart.name,\n\t\t\t\t\tzonePathPart.name,\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\targs.path[0].name,\n\t\t\t\t\t\"Document\",\n\t\t\t\t\t\"Data\",\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\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\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\t\t\tcontentTypeNames.push(itemName);\n\n\t\t\tif (isNestedGroup) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`,\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.GroupField<Simplify<${itemName}>>;`,\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 \"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\t\t\t\t\t\t\tauxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(primaryInterfaceName);\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\t\t\t\t\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(itemInterfaceName);\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","CustomTypeModelFieldType","buildTypeName","getHumanReadablePath","source","stripIndent","addSection"],"mappings":";;;;;;;;;;AA6BA,SAAS,mBACR,MAA4B;;AAE5B,MAAI,OAAOA,eAAAA,eAAe;AAAA,IACzB,MAAM,KAAK;AAAA,IACX,OAAO,KAAK;AAAA,IACZ,MAAM,KAAK;AAAA,IACX,SAAS,KAAK;AAAA,EAAA,CACd;AAED,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAE7B,QAAA,OACL,KAAK,KAAK,SAAS,GAAG,KACtB,KAAK,KAAK,SAAS,GAAG,KACtB,SAAS,KAAK,KAAK,IAAI,IACpB,IAAI,KAAK,IAAI,MACb,KAAK;AAED,UAAA,KAAK,MAAM,MAAM;AAAA,IACxB,KAAK,OAAO;AAEX;AAAA,IACD;AAAA,IAEA,KAAK,WAAW;AACf,aAAOC,QAAQ,QAAA,GAAG,IAAI,2BAA2B,IAAI;AAErD;AAAA,IACD;AAAA,IAEA,KAAK,SAAS;AACb,aAAOA,QAAQ,QAAA,GAAG,IAAI,yBAAyB,IAAI;AAEnD;AAAA,IACD;AAAA,IAEA,KAAK,QAAQ;AACZ,aAAOA,QAAQ,QAAA,GAAG,IAAI,wBAAwB,IAAI;AAElD;AAAA,IACD;AAAA,IAEA,KAAK,SAAS;AACb,YAAM,gBAA0B,CAAA;AAE5B,WAAA,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAC3C,mBAAW,iBAAgB,UAAK,aAAa,UAAlB,mBAAyB,eAAe;AAClE,gBAAM,0BACL,UAAK,aAAa,UAAlB,mBAAyB,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@@ -72,8 +72,13 @@ function buildFieldProperty(args) {
72
72
  switch ((_h = args.field.config) == null ? void 0 : _h.select) {
73
73
  case "document": {
74
74
  if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
75
- const customTypeIDsUnion = buildUnion(args.field.config.customtypes.map((type) => `"${type}"`));
76
- code = addLine(`${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`, code);
75
+ const customTypeIDs = args.field.config.customtypes.filter((type) => typeof type === "string").map((type) => `"${type}"`);
76
+ const customTypeObjects = args.field.config.customtypes.filter((type) => typeof type !== "string");
77
+ const contentRelationshipUnion = buildUnion([
78
+ customTypeIDs.length ? `prismic.ContentRelationshipField<${buildUnion(customTypeIDs)}>` : "",
79
+ customTypeObjects.length ? `NewContentRelationshipField<${JSON.stringify(customTypeObjects)}>` : ""
80
+ ]);
81
+ code = addLine(`${name}: ${contentRelationshipUnion};`, code);
77
82
  } else {
78
83
  code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
79
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"buildFieldProperties.js","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import {\n\ttype CustomTypeModelField,\n\tCustomTypeModelFieldType,\n} from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\n\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildFieldPropertyArgs = Pick<\n\tBuildFieldPropertiesArgs,\n\t\"path\" | \"fieldConfigs\" | \"tabName\"\n> & {\n\tname: string;\n\tfield: CustomTypeModelField;\n};\n\ntype BuildFieldPropertyReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\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\tconst variants =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"variants\" in args.field.config &&\n\t\t\t\tArray.isArray(args.field.config.variants) &&\n\t\t\t\targs.field.config.variants.length > 0\n\t\t\t\t\t? args.field.config.variants\n\t\t\t\t\t\t\t.map((variant) => `\"${variant.replace(/\\\"/g, '\\\\\"')}\"`)\n\t\t\t\t\t\t\t.join(\" | \")\n\t\t\t\t\t: \"never\";\n\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(\n\t\t\t\t\t\t`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tlet type = `prismic.LinkField<string, string, unknown, prismic.FieldState, ${variants}>`;\n\n\t\t\t\t\tif (args.field.config?.repeat) {\n\t\t\t\t\t\ttype = `prismic.Repeatable<${type}>`;\n\t\t\t\t\t}\n\n\t\t\t\t\tcode = addLine(`${name}: ${type};`, code);\n\t\t\t\t\tbreak;\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\tcode = addLine(`${name}: prismic.RichTextField;`, code);\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 \"Table\": {\n\t\t\tcode = addLine(`${name}: prismic.TableField;`, code);\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 groupPathParts = args.path.filter(\n\t\t\t\t(part) =>\n\t\t\t\t\tpart.model !== undefined &&\n\t\t\t\t\t\"type\" in part.model &&\n\t\t\t\t\tpart.model.type === CustomTypeModelFieldType.Group,\n\t\t\t);\n\t\t\tconst isNestedGroup = groupPathParts.length > 0;\n\n\t\t\tlet itemName;\n\t\t\tif (\n\t\t\t\targs.path[0].model &&\n\t\t\t\t\"type\" in args.path[0].model &&\n\t\t\t\targs.path[0].model.type === \"SharedSlice\"\n\t\t\t) {\n\t\t\t\tconst [slicePathPart, variationPathPart, zonePathPart] = args.path;\n\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\tslicePathPart.name,\n\t\t\t\t\t\"Slice\",\n\t\t\t\t\tvariationPathPart.name,\n\t\t\t\t\tzonePathPart.name,\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\targs.path[0].name,\n\t\t\t\t\t\"Document\",\n\t\t\t\t\t\"Data\",\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\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\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\t\t\tcontentTypeNames.push(itemName);\n\n\t\t\tif (isNestedGroup) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`,\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.GroupField<Simplify<${itemName}>>;`,\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 \"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\t\t\t\t\t\t\tauxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(primaryInterfaceName);\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\t\t\t\t\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(itemInterfaceName);\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":";;;;;;;;AA6BA,SAAS,mBACR,MAA4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CACd;AAEM,WAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAClC,qBAAA,KAAK,GAAG,cAAc,gBAAgB;AAAA,EACxD;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"buildFieldProperties.js","sources":["../../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import {\n\ttype CustomTypeModelField,\n\tCustomTypeModelFieldType,\n} from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\n\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildFieldPropertyArgs = Pick<\n\tBuildFieldPropertiesArgs,\n\t\"path\" | \"fieldConfigs\" | \"tabName\"\n> & {\n\tname: string;\n\tfield: CustomTypeModelField;\n};\n\ntype BuildFieldPropertyReturnType = {\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\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\tconst variants =\n\t\t\t\targs.field.config &&\n\t\t\t\t\"variants\" in args.field.config &&\n\t\t\t\tArray.isArray(args.field.config.variants) &&\n\t\t\t\targs.field.config.variants.length > 0\n\t\t\t\t\t? args.field.config.variants\n\t\t\t\t\t\t\t.map((variant) => `\"${variant.replace(/\\\"/g, '\\\\\"')}\"`)\n\t\t\t\t\t\t\t.join(\" | \")\n\t\t\t\t\t: \"never\";\n\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 customTypeIDs = args.field.config.customtypes\n\t\t\t\t\t\t\t.filter((type) => typeof type === \"string\")\n\t\t\t\t\t\t\t.map((type) => `\"${type}\"`);\n\n\t\t\t\t\t\tconst customTypeObjects = args.field.config.customtypes.filter(\n\t\t\t\t\t\t\t(type) => typeof type !== \"string\",\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst contentRelationshipUnion = buildUnion([\n\t\t\t\t\t\t\tcustomTypeIDs.length\n\t\t\t\t\t\t\t\t? `prismic.ContentRelationshipField<${buildUnion(\n\t\t\t\t\t\t\t\t\t\tcustomTypeIDs,\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\tcustomTypeObjects.length\n\t\t\t\t\t\t\t\t? `NewContentRelationshipField<${JSON.stringify(\n\t\t\t\t\t\t\t\t\t\tcustomTypeObjects,\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]);\n\n\t\t\t\t\t\tcode = addLine(`${name}: ${contentRelationshipUnion};`, code);\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(\n\t\t\t\t\t\t`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`,\n\t\t\t\t\t\tcode,\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tlet type = `prismic.LinkField<string, string, unknown, prismic.FieldState, ${variants}>`;\n\n\t\t\t\t\tif (args.field.config?.repeat) {\n\t\t\t\t\t\ttype = `prismic.Repeatable<${type}>`;\n\t\t\t\t\t}\n\n\t\t\t\t\tcode = addLine(`${name}: ${type};`, code);\n\t\t\t\t\tbreak;\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\tcode = addLine(`${name}: prismic.RichTextField;`, code);\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 \"Table\": {\n\t\t\tcode = addLine(`${name}: prismic.TableField;`, code);\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 groupPathParts = args.path.filter(\n\t\t\t\t(part) =>\n\t\t\t\t\tpart.model !== undefined &&\n\t\t\t\t\t\"type\" in part.model &&\n\t\t\t\t\tpart.model.type === CustomTypeModelFieldType.Group,\n\t\t\t);\n\t\t\tconst isNestedGroup = groupPathParts.length > 0;\n\n\t\t\tlet itemName;\n\t\t\tif (\n\t\t\t\targs.path[0].model &&\n\t\t\t\t\"type\" in args.path[0].model &&\n\t\t\t\targs.path[0].model.type === \"SharedSlice\"\n\t\t\t) {\n\t\t\t\tconst [slicePathPart, variationPathPart, zonePathPart] = args.path;\n\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\tslicePathPart.name,\n\t\t\t\t\t\"Slice\",\n\t\t\t\t\tvariationPathPart.name,\n\t\t\t\t\tzonePathPart.name,\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\titemName = buildTypeName(\n\t\t\t\t\targs.path[0].name,\n\t\t\t\t\t\"Document\",\n\t\t\t\t\t\"Data\",\n\t\t\t\t\t...groupPathParts.map((part) => part.name),\n\t\t\t\t\targs.name,\n\t\t\t\t\t\"Item\",\n\t\t\t\t);\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\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\t\t\tcontentTypeNames.push(itemName);\n\n\t\t\tif (isNestedGroup) {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`,\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.GroupField<Simplify<${itemName}>>;`,\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 \"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\t\t\t\t\t\t\tauxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(primaryInterfaceName);\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\t\t\t\t\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\t\t\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\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\tcontentTypeNames.push(itemInterfaceName);\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":";;;;;;;;AA6BA,SAAS,mBACR,MAA4B;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B,MAAI,OAAO;AAEX,QAAM,iBAAkC,CAAA;AACxC,QAAM,mBAA6B,CAAA;AAExB,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,WAAA,WAAW,cAAc,MAAM,IAAI;AAE3B,mBAAA,KAAK,GAAG,cAAc,cAAc;AAClC,qBAAA,KAAK,GAAG,cAAc,gBAAgB;AAAA,EACxD;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prismic-ts-codegen",
3
- "version": "0.1.26",
3
+ "version": "0.1.27-alpha.1",
4
4
  "description": "An experimental Prismic model-to-TypeScript-type generator",
5
5
  "keywords": [
6
6
  "typescript",
@@ -60,7 +60,7 @@
60
60
  "quick-lru": "^6.1.2"
61
61
  },
62
62
  "devDependencies": {
63
- "@prismicio/client": "7.16.1",
63
+ "@prismicio/client": "7.18.0-alpha.0",
64
64
  "@prismicio/mock": "0.7.1",
65
65
  "@size-limit/preset-small-lib": "^8.2.6",
66
66
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
@@ -59,6 +59,54 @@ export function generateTypes(config: GenerateTypesConfig = {}): string {
59
59
  code,
60
60
  );
61
61
 
62
+ code = addSection(
63
+ `
64
+ type PickNewContentRelationshipFieldData<
65
+ TRelationship extends prismic.CustomTypeLevel1 | prismic.CustomTypeLevel2 | prismic.GroupLevel1 | prismic.GroupLevel2,
66
+ TData extends Record<string, prismic.AnyRegularField | prismic.GroupField | prismic.NestedGroupField | prismic.SliceZone>,
67
+ TLang extends string
68
+ > = |
69
+ // Content relationship fields
70
+ {
71
+ [TSubRelationship in Extract<
72
+ TRelationship["fields"][number], prismic.ContentRelationshipLevel1
73
+ > as TSubRelationship["id"]]:
74
+ NewContentRelationshipField<TSubRelationship["customtypes"], TLang>;
75
+ } &
76
+ // Group
77
+ {
78
+ [TGroup in Extract<
79
+ TRelationship["fields"][number], prismic.GroupLevel1 | prismic.GroupLevel2
80
+ > as TGroup["id"]]:
81
+ TData[TGroup["id"]] extends prismic.GroupField<infer TGroupData>
82
+ ? prismic.GroupField<PickNewContentRelationshipFieldData<TGroup, TGroupData, TLang>>
83
+ : never
84
+ } &
85
+ // Other fields
86
+ {
87
+ [TFieldKey in Extract<TRelationship["fields"][number], string>]:
88
+ TFieldKey extends keyof TData ? TData[TFieldKey] : never;
89
+ };
90
+
91
+ type NewContentRelationshipField<
92
+ TCustomType extends readonly (prismic.CustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeLevel2 | string)[],
93
+ TLang extends string = string
94
+ > = {
95
+ [ID in Exclude<TCustomType[number], string>["id"]]:
96
+ prismic.ContentRelationshipField<
97
+ ID,
98
+ TLang,
99
+ PickNewContentRelationshipFieldData<
100
+ Extract<TCustomType[number], { id: ID }>,
101
+ Extract<prismic.Content.AllDocumentTypes, { type: ID }>["data"],
102
+ TLang
103
+ >
104
+ >
105
+ }[Exclude<TCustomType[number], string>["id"]];
106
+ `,
107
+ code,
108
+ );
109
+
62
110
  const contentTypeNames: string[] = [];
63
111
 
64
112
  if (config.customTypeModels) {
@@ -158,14 +158,28 @@ function buildFieldProperty(
158
158
  args.field.config.customtypes &&
159
159
  args.field.config.customtypes.length > 0
160
160
  ) {
161
- const customTypeIDsUnion = buildUnion(
162
- args.field.config.customtypes.map((type) => `"${type}"`),
163
- );
161
+ const customTypeIDs = args.field.config.customtypes
162
+ .filter((type) => typeof type === "string")
163
+ .map((type) => `"${type}"`);
164
164
 
165
- code = addLine(
166
- `${name}: prismic.ContentRelationshipField<${customTypeIDsUnion}>;`,
167
- code,
165
+ const customTypeObjects = args.field.config.customtypes.filter(
166
+ (type) => typeof type !== "string",
168
167
  );
168
+
169
+ const contentRelationshipUnion = buildUnion([
170
+ customTypeIDs.length
171
+ ? `prismic.ContentRelationshipField<${buildUnion(
172
+ customTypeIDs,
173
+ )}>`
174
+ : "",
175
+ customTypeObjects.length
176
+ ? `NewContentRelationshipField<${JSON.stringify(
177
+ customTypeObjects,
178
+ )}>`
179
+ : "",
180
+ ]);
181
+
182
+ code = addLine(`${name}: ${contentRelationshipUnion};`, code);
169
183
  } else {
170
184
  code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
171
185
  }