prismic-ts-codegen 0.1.30-pr.82.96148f3 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/configSchema.d.mts +4 -2
- package/dist/cli/configSchema.d.mts.map +1 -1
- package/dist/cli/configSchema.mjs +2 -126
- package/dist/cli/configSchema.mjs.map +1 -1
- package/dist/cli/constants.d.mts +2 -1
- package/dist/cli/constants.d.mts.map +1 -1
- package/dist/cli/loadConfig.mjs +9 -9
- package/dist/cli/loadConfig.mjs.map +1 -1
- package/dist/cli/loadLocaleIDs.mjs +1 -0
- package/dist/cli/loadLocaleIDs.mjs.map +1 -1
- package/dist/cli/loadModels.mjs +10 -13
- package/dist/cli/loadModels.mjs.map +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +16 -41
- package/dist/cli.mjs.map +1 -1
- package/dist/constants.mjs.map +1 -1
- package/dist/detectTypesProvider.d.mts +4 -2
- package/dist/detectTypesProvider.d.mts.map +1 -1
- package/dist/detectTypesProvider.mjs.map +1 -1
- package/dist/generateTypes.d.mts +5 -3
- package/dist/generateTypes.d.mts.map +1 -1
- package/dist/generateTypes.mjs +12 -15
- package/dist/generateTypes.mjs.map +1 -1
- package/dist/lib/addBlankLine.mjs.map +1 -1
- package/dist/lib/addLine.mjs.map +1 -1
- package/dist/lib/addSection.mjs.map +1 -1
- package/dist/lib/addTrailingNewLine.mjs.map +1 -1
- package/dist/lib/buildCustomTypeDataType.mjs +2 -2
- package/dist/lib/buildCustomTypeDataType.mjs.map +1 -1
- package/dist/lib/buildCustomTypeType.mjs +2 -2
- package/dist/lib/buildCustomTypeType.mjs.map +1 -1
- package/dist/lib/buildFieldDocs.mjs +4 -9
- package/dist/lib/buildFieldDocs.mjs.map +1 -1
- package/dist/lib/buildFieldProperties.mjs +14 -18
- package/dist/lib/buildFieldProperties.mjs.map +1 -1
- package/dist/lib/buildSharedSliceType.mjs +10 -10
- package/dist/lib/buildSharedSliceType.mjs.map +1 -1
- package/dist/lib/buildTypeName.mjs +2 -2
- package/dist/lib/buildTypeName.mjs.map +1 -1
- package/dist/lib/buildUnion.mjs.map +1 -1
- package/dist/lib/checkHasUIDFIeld.mjs.map +1 -1
- package/dist/lib/getAPIIDPath.mjs.map +1 -1
- package/dist/lib/getCacheKey.mjs.map +1 -1
- package/dist/lib/getHumanReadableModelName.mjs.map +1 -1
- package/dist/lib/getHumanReadablePath.mjs.map +1 -1
- package/dist/types.d.mts +3 -1
- package/dist/types.d.mts.map +1 -1
- package/package.json +22 -18
- package/src/cli/index.ts +22 -38
- package/src/cli/loadConfig.ts +9 -7
- package/src/cli/loadLocaleIDs.ts +1 -0
- package/src/cli/loadModels.ts +12 -30
- package/src/generateTypes.ts +3 -3
- package/src/lib/buildCustomTypeDataType.ts +2 -2
- package/src/lib/buildCustomTypeType.ts +6 -6
- package/src/lib/buildFieldProperties.ts +7 -7
- package/src/lib/buildSharedSliceType.ts +33 -22
- package/src/lib/buildTypeName.ts +4 -9
- package/dist/lib/dedent.mjs +0 -12
- package/dist/lib/dedent.mjs.map +0 -1
- package/dist/package.mjs +0 -7
- package/dist/package.mjs.map +0 -1
- package/src/lib/dedent.ts +0 -14
package/dist/generateTypes.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { addLine } from "./lib/addLine.mjs";
|
|
2
2
|
import { addSection } from "./lib/addSection.mjs";
|
|
3
3
|
import { buildUnion } from "./lib/buildUnion.mjs";
|
|
4
|
-
import { dedent } from "./lib/dedent.mjs";
|
|
5
4
|
import { buildCustomTypeType } from "./lib/buildCustomTypeType.mjs";
|
|
6
5
|
import { buildSharedSliceType } from "./lib/buildSharedSliceType.mjs";
|
|
6
|
+
import { source } from "common-tags";
|
|
7
7
|
import QuickLRU from "quick-lru";
|
|
8
8
|
//#region src/generateTypes.ts
|
|
9
9
|
const cache = new QuickLRU({ maxSize: 1e3 });
|
|
@@ -83,8 +83,7 @@ type ContentRelationshipFieldWithData<
|
|
|
83
83
|
}
|
|
84
84
|
if (config.customTypeModels.length > 0) {
|
|
85
85
|
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
86
|
-
|
|
87
|
-
code = addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
|
|
86
|
+
code = addSection(`export type ${allDocumentTypesUnionName} = ${buildUnion(allDocumentTypesTypeNames)};`, code);
|
|
88
87
|
contentTypeNames.push(allDocumentTypesUnionName);
|
|
89
88
|
}
|
|
90
89
|
}
|
|
@@ -101,37 +100,35 @@ type ContentRelationshipFieldWithData<
|
|
|
101
100
|
}
|
|
102
101
|
if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) {
|
|
103
102
|
let clientModuleCode = "";
|
|
104
|
-
if (config.clientIntegration.includeCreateClientInterface) {
|
|
105
|
-
|
|
106
|
-
clientModuleCode = addSection(`interface CreateClient {
|
|
103
|
+
if (config.clientIntegration.includeCreateClientInterface) if ((config.customTypeModels?.length || 0) > 0) {
|
|
104
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
107
105
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
|
|
108
106
|
}`, clientModuleCode);
|
|
109
|
-
|
|
107
|
+
clientModuleCode = addSection(`interface CreateWriteClient {
|
|
110
108
|
(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;
|
|
111
109
|
}`, clientModuleCode);
|
|
112
|
-
|
|
110
|
+
clientModuleCode = addSection(`interface CreateMigration {
|
|
113
111
|
(): ${clientImportName}.Migration<AllDocumentTypes>;
|
|
114
112
|
}`, clientModuleCode);
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
} else {
|
|
114
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
117
115
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
|
|
118
116
|
}`, clientModuleCode);
|
|
119
|
-
|
|
117
|
+
clientModuleCode = addSection(`interface CreateWriteClient {
|
|
120
118
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;
|
|
121
119
|
}`, clientModuleCode);
|
|
122
|
-
|
|
120
|
+
clientModuleCode = addSection(`interface CreateMigration {
|
|
123
121
|
(): ${clientImportName}.Migration;
|
|
124
122
|
}`, clientModuleCode);
|
|
125
|
-
}
|
|
126
123
|
}
|
|
127
|
-
if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(
|
|
124
|
+
if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(source`
|
|
128
125
|
namespace Content {
|
|
129
126
|
export type {
|
|
130
127
|
${contentTypeNames.join(",\n")}
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
130
|
`, clientModuleCode);
|
|
134
|
-
code = addSection(
|
|
131
|
+
code = addSection(source`
|
|
135
132
|
declare module "@prismicio/client" {
|
|
136
133
|
${clientModuleCode}
|
|
137
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.mjs","names":[],"sources":["../src/generateTypes.ts"],"sourcesContent":["import type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\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\";\nimport
|
|
1
|
+
{"version":3,"file":"generateTypes.mjs","names":[],"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\";\nimport type { 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(`import type * as ${clientImportName} from \"@prismicio/client\";`, code);\n\t\t}\n\t}\n\n\tcode = addSection(`type Simplify<T> = { [KeyType in keyof T]: T[KeyType] };`, code);\n\n\tcode = addSection(\n\t\t`\ntype PickContentRelationshipFieldData<\n\tTRelationship extends prismic.CustomTypeModelFetchCustomTypeLevel1 | prismic.CustomTypeModelFetchCustomTypeLevel2 | prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2,\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.CustomTypeModelFetchContentRelationshipLevel1\n\t\t> as TSubRelationship[\"id\"]]:\n\t\t\tContentRelationshipFieldWithData<TSubRelationship[\"customtypes\"], TLang>;\n\t} &\n\t// Group\n\t{\n\t\t[TGroup in Extract<\n\t\t\tTRelationship[\"fields\"][number], prismic.CustomTypeModelFetchGroupLevel1 | prismic.CustomTypeModelFetchGroupLevel2\n\t\t> as TGroup[\"id\"]]:\n\t\t\tTData[TGroup[\"id\"]] extends prismic.GroupField<infer TGroupData>\n\t\t\t\t? prismic.GroupField<PickContentRelationshipFieldData<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 ContentRelationshipFieldWithData<\n\tTCustomType extends readonly (prismic.CustomTypeModelFetchCustomTypeLevel1 | string)[] | readonly (prismic.CustomTypeModelFetchCustomTypeLevel2 | 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\tPickContentRelationshipFieldData<\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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IlD,KAAI,OAAO,kBACV,MAAK,MAAM,SAAS,OAAO,mBAAmB;EAC7C,MAAM,kBAAkB,qBAAqB;GAC5C;GACA;GACA,OAAO,iBAAiB,QAAQ,KAAA;GAChC,CAAC;AAEF,OAAK,MAAM,iBAAiB,gBAAgB,eAC3C,QAAO,WAAW,cAAc,MAAM,KAAK;AAG5C,SAAO,WAAW,gBAAgB,MAAM,KAAK;AAE7C,mBAAiB,KAAK,gBAAgB,KAAK;AAC3C,mBAAiB,KAAK,GAAG,gBAAgB,iBAAiB;;AAI5D,KACC,OAAO,mBAAmB,gCAC1B,OAAO,mBAAmB,yBACzB;EACD,IAAI,mBAAmB;AAEvB,MAAI,OAAO,kBAAkB,6BAC5B,MAAK,OAAO,kBAAkB,UAAU,KAAK,GAAG;AAC/C,sBAAmB,WAClB;gDAC2C,iBAAiB,kBAAkB,iBAAiB;IAE/F,iBACA;AACD,sBAAmB,WAClB;+CAC0C,iBAAiB,uBAAuB,iBAAiB;IAEnG,iBACA;AACD,sBAAmB,WAClB;OACE,iBAAiB;IAEnB,iBACA;SACK;AACN,sBAAmB,WAClB;gDAC2C,iBAAiB,kBAAkB,iBAAiB;IAE/F,iBACA;AACD,sBAAmB,WAClB;gDAC2C,iBAAiB,uBAAuB,iBAAiB;IAEpG,iBACA;AACD,sBAAmB,WAClB;OACE,iBAAiB;IAEnB,iBACA;;AAIH,MAAI,OAAO,kBAAkB,wBAC5B,oBAAmB,WAClB,MAAM;;;SAGD,iBAAiB,KAAK,MAAM,CAAC;;;OAIlC,iBACA;AAGF,SAAO,WACN,MAAM;;OAEF,iBAAiB;;MAGrB,KACA;;AAGF,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addBlankLine.mjs","names":[],"sources":["../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,OAAe,QAAqC;
|
|
1
|
+
{"version":3,"file":"addBlankLine.mjs","names":[],"sources":["../../src/lib/addBlankLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\ntype AddBlankLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addBlankLine(state: string, config?: AddBlankLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn addTrailingNewLine(state) + \"\\n\";\n\t}\n}\n"],"mappings":";;AAMA,SAAgB,aAAa,OAAe,QAAqC;AAChF,MAAK,CAAC,SAAS,MAAM,SAAS,OAAO,KAAK,CAAC,QAAQ,MAClD,QAAO;KAEP,QAAO,mBAAmB,MAAM,GAAG"}
|
package/dist/lib/addLine.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addLine.mjs","names":[],"sources":["../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string): string {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"mappings":";;AAEA,SAAgB,QAAQ,MAAc,OAAuB;
|
|
1
|
+
{"version":3,"file":"addLine.mjs","names":[],"sources":["../../src/lib/addLine.ts"],"sourcesContent":["import { addTrailingNewLine } from \"./addTrailingNewLine\";\n\nexport function addLine(line: string, state: string): string {\n\treturn addTrailingNewLine(state) + line;\n}\n"],"mappings":";;AAEA,SAAgB,QAAQ,MAAc,OAAuB;AAC5D,QAAO,mBAAmB,MAAM,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addSection.mjs","names":[],"sources":["../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string): string {\n\treturn addBlankLine(state) + section;\n}\n"],"mappings":";;AAEA,SAAgB,WAAW,SAAiB,OAAuB;
|
|
1
|
+
{"version":3,"file":"addSection.mjs","names":[],"sources":["../../src/lib/addSection.ts"],"sourcesContent":["import { addBlankLine } from \"./addBlankLine\";\n\nexport function addSection(section: string, state: string): string {\n\treturn addBlankLine(state) + section;\n}\n"],"mappings":";;AAEA,SAAgB,WAAW,SAAiB,OAAuB;AAClE,QAAO,aAAa,MAAM,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addTrailingNewLine.mjs","names":[],"sources":["../../src/lib/addTrailingNewLine.ts"],"sourcesContent":["type AddTrailingNewLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addTrailingNewLine(state: string, config?: AddTrailingNewLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn state + \"\\n\";\n\t}\n}\n"],"mappings":";AAIA,SAAgB,mBAAmB,OAAe,QAA2C;
|
|
1
|
+
{"version":3,"file":"addTrailingNewLine.mjs","names":[],"sources":["../../src/lib/addTrailingNewLine.ts"],"sourcesContent":["type AddTrailingNewLineConfig = {\n\tforce?: boolean;\n};\n\nexport function addTrailingNewLine(state: string, config?: AddTrailingNewLineConfig): string {\n\tif ((!state || state.endsWith(\"\\n\")) && !config?.force) {\n\t\treturn state;\n\t} else {\n\t\treturn state + \"\\n\";\n\t}\n}\n"],"mappings":";AAIA,SAAgB,mBAAmB,OAAe,QAA2C;AAC5F,MAAK,CAAC,SAAS,MAAM,SAAS,KAAK,KAAK,CAAC,QAAQ,MAChD,QAAO;KAEP,QAAO,QAAQ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildTypeName } from "./buildTypeName.mjs";
|
|
2
2
|
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
3
|
-
import { dedent } from "./dedent.mjs";
|
|
4
3
|
import { buildFieldProperties } from "./buildFieldProperties.mjs";
|
|
4
|
+
import { source } from "common-tags";
|
|
5
5
|
//#region src/lib/buildCustomTypeDataType.ts
|
|
6
6
|
function buildCustomTypeDataType(args) {
|
|
7
7
|
let code = "";
|
|
@@ -28,7 +28,7 @@ function buildCustomTypeDataType(args) {
|
|
|
28
28
|
auxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);
|
|
29
29
|
contentTypeNames.push(...tabFieldProperties.contentTypeNames);
|
|
30
30
|
}
|
|
31
|
-
if (fieldProperties) code =
|
|
31
|
+
if (fieldProperties) code = source`
|
|
32
32
|
/**
|
|
33
33
|
* Content for ${humanReadableName} documents
|
|
34
34
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeDataType.mjs","names":[],"sources":["../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport {
|
|
1
|
+
{"version":3,"file":"buildCustomTypeDataType.mjs","names":[],"sources":["../../src/lib/buildCustomTypeDataType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\n\nimport { buildTypeName } from \"../lib/buildTypeName\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeDataTypeArgs = {\n\tmodel: CustomTypeModel;\n\tfieldConfigs: FieldConfigs;\n};\n\ntype BuildCustomTypeDataTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeDataType(\n\targs: BuildCustomTypeDataTypeArgs,\n): BuildCustomTypeDataTypeReturnValue {\n\tlet code = \"\";\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\", \"Data\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tlet fieldProperties = \"\";\n\n\tfor (const tabName in args.model.json) {\n\t\tconst { uid: _uid, ...fields } = args.model.json[tabName];\n\n\t\tconst tabFieldProperties = buildFieldProperties({\n\t\t\tfields,\n\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\tpath: [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t],\n\t\t\ttabName,\n\t\t});\n\n\t\tfieldProperties += tabFieldProperties.code;\n\n\t\tauxiliaryTypes.push(...tabFieldProperties.auxiliaryTypes);\n\t\tcontentTypeNames.push(...tabFieldProperties.contentTypeNames);\n\t}\n\n\tif (fieldProperties) {\n\t\tcode = source`\n\t\t\t/**\n\t\t\t * Content for ${humanReadableName} documents\n\t\t\t */\n\t\t\tinterface ${name} {\n\t\t\t\t${fieldProperties}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcode = `interface ${name} {}`;\n\t}\n\n\treturn {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n}\n"],"mappings":";;;;;AAoBA,SAAgB,wBACf,MACqC;CACrC,IAAI,OAAO;CACX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,YAAY,OAAO;CAC7D,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;EACZ,CAAC;CAEF,IAAI,kBAAkB;AAEtB,MAAK,MAAM,WAAW,KAAK,MAAM,MAAM;EACtC,MAAM,EAAE,KAAK,MAAM,GAAG,WAAW,KAAK,MAAM,KAAK;EAEjD,MAAM,qBAAqB,qBAAqB;GAC/C;GACA,cAAc,KAAK;GACnB,MAAM,CACL;IACC,MAAM,KAAK,MAAM;IACjB,OAAO,KAAK;IACZ,CACD;GACD;GACA,CAAC;AAEF,qBAAmB,mBAAmB;AAEtC,iBAAe,KAAK,GAAG,mBAAmB,eAAe;AACzD,mBAAiB,KAAK,GAAG,mBAAmB,iBAAiB;;AAG9D,KAAI,gBACH,QAAO,MAAM;;oBAEK,kBAAkB;;eAEvB,KAAK;MACd,gBAAgB;;;KAIpB,QAAO,aAAa,KAAK;AAG1B,QAAO;EACN;EACA;EACA;EACA;EACA"}
|
|
@@ -3,10 +3,10 @@ import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants.mjs";
|
|
|
3
3
|
import { buildTypeName } from "./buildTypeName.mjs";
|
|
4
4
|
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
5
5
|
import { buildUnion } from "./buildUnion.mjs";
|
|
6
|
-
import { dedent } from "./dedent.mjs";
|
|
7
6
|
import { buildCustomTypeDataType } from "./buildCustomTypeDataType.mjs";
|
|
8
7
|
import { checkHasUIDField } from "./checkHasUIDFIeld.mjs";
|
|
9
8
|
import { getCacheKey } from "./getCacheKey.mjs";
|
|
9
|
+
import { source } from "common-tags";
|
|
10
10
|
//#region src/lib/buildCustomTypeType.ts
|
|
11
11
|
function buildCustomTypeType(args) {
|
|
12
12
|
if (args.cache) {
|
|
@@ -32,7 +32,7 @@ function buildCustomTypeType(args) {
|
|
|
32
32
|
contentTypeNames.push(dataType.name);
|
|
33
33
|
contentTypeNames.push(...dataType.contentTypeNames);
|
|
34
34
|
code = addSection(dataType.code, code);
|
|
35
|
-
code = addSection(
|
|
35
|
+
code = addSection(source`
|
|
36
36
|
/**
|
|
37
37
|
* ${humanReadableName} document from Prismic
|
|
38
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildCustomTypeType.mjs","names":[],"sources":["../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport {
|
|
1
|
+
{"version":3,"file":"buildCustomTypeType.mjs","names":[],"sources":["../../src/lib/buildCustomTypeType.ts"],"sourcesContent":["import type { CustomTypeModel } from \"@prismicio/client\";\nimport { source } from \"common-tags\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { CUSTOM_TYPES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildCustomTypeDataType } from \"./buildCustomTypeDataType\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { checkHasUIDField } from \"./checkHasUIDFIeld\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\n\ntype BuildCustomTypeTypesArgs = {\n\tmodel: CustomTypeModel;\n\tlocaleIDs?: string[];\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildCustomTypeTypeReturnValue = {\n\tname: string;\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildCustomTypeType(\n\targs: BuildCustomTypeTypesArgs\n): BuildCustomTypeTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildCustomTypeTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Document\");\n\tconst langDefault =\n\t\targs.localeIDs && args.localeIDs.length > 0\n\t\t\t? buildUnion(args.localeIDs.map((localeID) => `\"${localeID}\"`))\n\t\t\t: \"string\";\n\tconst baseDocumentType = checkHasUIDField(args.model)\n\t\t? \"PrismicDocumentWithUID\"\n\t\t: \"PrismicDocumentWithoutUID\";\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst dataType = buildCustomTypeDataType({\n\t\tmodel: args.model,\n\t\tfieldConfigs: args.fieldConfigs,\n\t});\n\n\tauxiliaryTypes.push(...dataType.auxiliaryTypes);\n\tcontentTypeNames.push(dataType.name);\n\tcontentTypeNames.push(...dataType.contentTypeNames);\n\n\tcode = addSection(dataType.code, code);\n\n\tcode = addSection(\n\t\tsource`\n\t\t\t/**\n\t\t\t * ${humanReadableName} document from Prismic\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Repeatable**: \\`${args.model.repeatable.toString()}\\`\n\t\t\t * - **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}\n\t\t\t *\n\t\t\t * @typeParam Lang - Language API ID of the document.\n\t\t\t */\n\t\t\texport type ${name}<Lang extends string = ${langDefault}> = prismic.${baseDocumentType}<Simplify<${\n\t\t\tdataType.name\n\t\t}>, \"${args.model.id}\", Lang>;\n\t\t`,\n\t\tcode\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey(args.model);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,oBACf,MACiC;AACjC,KAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,KAAK,MAAM;EACnC,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI;AAElC,MAAI,OACH,QAAO;;CAIT,IAAI,OAAO;CAEX,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,WAAW;CACrD,MAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvC,WAAW,KAAK,UAAU,KAAK,aAAa,IAAI,SAAS,GAAG,CAAC,GAC7D;CACJ,MAAM,mBAAmB,iBAAiB,KAAK,MAAM,GAClD,2BACA;CACH,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;EACZ,CAAC;CAEF,MAAM,WAAW,wBAAwB;EACxC,OAAO,KAAK;EACZ,cAAc,KAAK;EACnB,CAAC;AAEF,gBAAe,KAAK,GAAG,SAAS,eAAe;AAC/C,kBAAiB,KAAK,SAAS,KAAK;AACpC,kBAAiB,KAAK,GAAG,SAAS,iBAAiB;AAEnD,QAAO,WAAW,SAAS,MAAM,KAAK;AAEtC,QAAO,WACN,MAAM;;QAEA,kBAAkB;;wBAEF,KAAK,MAAM,GAAG;4BACV,KAAK,MAAM,WAAW,UAAU,CAAC;6BAChC,+BAA+B;;;;iBAI3C,KAAK,yBAAyB,YAAY,cAAc,iBAAiB,YACvF,SAAS,KACT,MAAM,KAAK,MAAM,GAAG;KAErB,KACA;CAED,MAAM,SAAS;EACd;EACA;EACA;EACA;EACA;AAED,KAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,KAAK,MAAM;AAEnC,OAAK,MAAM,IAAI,KAAK,OAAO;;AAG5B,QAAO"}
|
|
@@ -47,18 +47,13 @@ function buildFieldDocs(args) {
|
|
|
47
47
|
result = addLine(` * ${humanReadableName} field in *${humanReadablePath}*`, result);
|
|
48
48
|
result = addLine(" *", result);
|
|
49
49
|
result = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);
|
|
50
|
-
|
|
51
|
-
result = addLine(` * - **Placeholder**: ${placeholder}`, result);
|
|
50
|
+
result = addLine(` * - **Placeholder**: ${args.field.config && "placeholder" in args.field.config && args.field.config.placeholder || `*None*`}`, result);
|
|
52
51
|
const defaultValue = args.field.config && "default_value" in args.field.config ? args.field.config.default_value : void 0;
|
|
53
|
-
if (defaultValue !== void 0) {
|
|
54
|
-
|
|
55
|
-
result = addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);
|
|
56
|
-
}
|
|
57
|
-
const apiIDPath = getAPIIDPath({ path: [...args.path, {
|
|
52
|
+
if (defaultValue !== void 0) result = addLine(` * - **Default Value**: ${typeof defaultValue === "boolean" ? `${defaultValue}` : defaultValue}`, result);
|
|
53
|
+
result = addLine(` * - **API ID Path**: ${getAPIIDPath({ path: [...args.path, {
|
|
58
54
|
name: args.name,
|
|
59
55
|
model: args.field
|
|
60
|
-
}] });
|
|
61
|
-
result = addLine(` * - **API ID Path**: ${apiIDPath}`, result);
|
|
56
|
+
}] })}`, result);
|
|
62
57
|
if (args.tabName) result = addLine(` * - **Tab**: ${args.tabName}`, result);
|
|
63
58
|
const documentationURL = getDocumentationURL({ field: args.field });
|
|
64
59
|
if (documentationURL) result = addLine(` * - **Documentation**: ${documentationURL}`, result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFieldDocs.mjs","names":[],"sources":["../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import type { CustomTypeModelField } from \"@prismicio/client\";\n\nimport { FIELD_DOCUMENTATION_URLS } from \"../constants\";\nimport type { FieldPath } from \"../types\";\nimport { addLine } from \"./addLine\";\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype GetFieldHumanReadableTypeArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getHumanReadableFieldType(args: GetFieldHumanReadableTypeArgs): string {\n\tswitch (args.field.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn \"Rich Text\";\n\t\t}\n\n\t\tcase \"IntegrationFields\": {\n\t\t\tconst catalog = args.field.config?.catalog;\n\n\t\t\treturn `Integration Fields (Catalog: ${catalog ? `\\`${catalog}\\`` : \"*unknown*\"})`;\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn \"Content Relationship\";\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn \"Link to Media\";\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn \"Link\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\treturn \"Slice Zone\";\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn args.field.type;\n\t\t}\n\t}\n}\n\ntype getDocumentationURLArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getDocumentationURL(args: getDocumentationURLArgs) {\n\tswitch (args.field.type) {\n\t\tcase \"Link\": {\n\t\t\tconst urls = FIELD_DOCUMENTATION_URLS.Link;\n\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn urls.contentRelationship;\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn urls.linkToMedia;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn urls.link;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdefault: {\n\t\t\tconst url =\n\t\t\t\tFIELD_DOCUMENTATION_URLS[args.field.type as keyof typeof FIELD_DOCUMENTATION_URLS];\n\n\t\t\tif (typeof url === \"string\") {\n\t\t\t\treturn url;\n\t\t\t}\n\t\t}\n\t}\n}\n\ntype BuildFieldDocsArgs = {\n\tname: string;\n\tfield: CustomTypeModelField;\n\tpath: FieldPath;\n\ttabName?: string;\n};\n\nexport function buildFieldDocs(args: BuildFieldDocsArgs): string {\n\tlet result = \"/**\";\n\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tmodel: args.field,\n\t\tname: args.name,\n\t});\n\tconst humanReadablePath = getHumanReadablePath({ path: args.path });\n\tconst humanReadableFieldType = getHumanReadableFieldType({\n\t\tfield: args.field,\n\t});\n\n\tresult = addLine(` * ${humanReadableName} field in *${humanReadablePath}*`, result);\n\n\tresult = addLine(\" *\", result);\n\n\tresult = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);\n\n\tconst placeholder =\n\t\t(args.field.config && \"placeholder\" in args.field.config && args.field.config.placeholder) ||\n\t\t`*None*`;\n\tresult = addLine(` * - **Placeholder**: ${placeholder}`, result);\n\n\tconst defaultValue =\n\t\targs.field.config && \"default_value\" in args.field.config\n\t\t\t? args.field.config.default_value\n\t\t\t: undefined;\n\tif (defaultValue !== undefined) {\n\t\tconst stringifiedDefaultValue =\n\t\t\ttypeof defaultValue === \"boolean\" ? `${defaultValue}` : defaultValue;\n\n\t\tresult = addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);\n\t}\n\n\tconst apiIDPath = getAPIIDPath({\n\t\tpath: [...args.path, { name: args.name, model: args.field }],\n\t});\n\tresult = addLine(` * - **API ID Path**: ${apiIDPath}`, result);\n\n\tif (args.tabName) {\n\t\tresult = addLine(` * - **Tab**: ${args.tabName}`, result);\n\t}\n\n\tconst documentationURL = getDocumentationURL({ field: args.field });\n\tif (documentationURL) {\n\t\tresult = addLine(` * - **Documentation**: ${documentationURL}`, result);\n\t}\n\n\tresult = addLine(\" */\", result);\n\n\treturn result;\n}\n"],"mappings":";;;;;;AAaA,SAAS,0BAA0B,MAA6C;
|
|
1
|
+
{"version":3,"file":"buildFieldDocs.mjs","names":[],"sources":["../../src/lib/buildFieldDocs.ts"],"sourcesContent":["import type { CustomTypeModelField } from \"@prismicio/client\";\n\nimport { FIELD_DOCUMENTATION_URLS } from \"../constants\";\nimport type { FieldPath } from \"../types\";\nimport { addLine } from \"./addLine\";\nimport { getAPIIDPath } from \"./getAPIIDPath\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype GetFieldHumanReadableTypeArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getHumanReadableFieldType(args: GetFieldHumanReadableTypeArgs): string {\n\tswitch (args.field.type) {\n\t\tcase \"StructuredText\": {\n\t\t\treturn \"Rich Text\";\n\t\t}\n\n\t\tcase \"IntegrationFields\": {\n\t\t\tconst catalog = args.field.config?.catalog;\n\n\t\t\treturn `Integration Fields (Catalog: ${catalog ? `\\`${catalog}\\`` : \"*unknown*\"})`;\n\t\t}\n\n\t\tcase \"Link\": {\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn \"Content Relationship\";\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn \"Link to Media\";\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn \"Link\";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tcase \"Slices\": {\n\t\t\treturn \"Slice Zone\";\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn args.field.type;\n\t\t}\n\t}\n}\n\ntype getDocumentationURLArgs = {\n\tfield: CustomTypeModelField;\n};\n\nfunction getDocumentationURL(args: getDocumentationURLArgs) {\n\tswitch (args.field.type) {\n\t\tcase \"Link\": {\n\t\t\tconst urls = FIELD_DOCUMENTATION_URLS.Link;\n\n\t\t\tswitch (args.field.config?.select) {\n\t\t\t\tcase \"document\": {\n\t\t\t\t\treturn urls.contentRelationship;\n\t\t\t\t}\n\n\t\t\t\tcase \"media\": {\n\t\t\t\t\treturn urls.linkToMedia;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn urls.link;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdefault: {\n\t\t\tconst url =\n\t\t\t\tFIELD_DOCUMENTATION_URLS[args.field.type as keyof typeof FIELD_DOCUMENTATION_URLS];\n\n\t\t\tif (typeof url === \"string\") {\n\t\t\t\treturn url;\n\t\t\t}\n\t\t}\n\t}\n}\n\ntype BuildFieldDocsArgs = {\n\tname: string;\n\tfield: CustomTypeModelField;\n\tpath: FieldPath;\n\ttabName?: string;\n};\n\nexport function buildFieldDocs(args: BuildFieldDocsArgs): string {\n\tlet result = \"/**\";\n\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tmodel: args.field,\n\t\tname: args.name,\n\t});\n\tconst humanReadablePath = getHumanReadablePath({ path: args.path });\n\tconst humanReadableFieldType = getHumanReadableFieldType({\n\t\tfield: args.field,\n\t});\n\n\tresult = addLine(` * ${humanReadableName} field in *${humanReadablePath}*`, result);\n\n\tresult = addLine(\" *\", result);\n\n\tresult = addLine(` * - **Field Type**: ${humanReadableFieldType}`, result);\n\n\tconst placeholder =\n\t\t(args.field.config && \"placeholder\" in args.field.config && args.field.config.placeholder) ||\n\t\t`*None*`;\n\tresult = addLine(` * - **Placeholder**: ${placeholder}`, result);\n\n\tconst defaultValue =\n\t\targs.field.config && \"default_value\" in args.field.config\n\t\t\t? args.field.config.default_value\n\t\t\t: undefined;\n\tif (defaultValue !== undefined) {\n\t\tconst stringifiedDefaultValue =\n\t\t\ttypeof defaultValue === \"boolean\" ? `${defaultValue}` : defaultValue;\n\n\t\tresult = addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);\n\t}\n\n\tconst apiIDPath = getAPIIDPath({\n\t\tpath: [...args.path, { name: args.name, model: args.field }],\n\t});\n\tresult = addLine(` * - **API ID Path**: ${apiIDPath}`, result);\n\n\tif (args.tabName) {\n\t\tresult = addLine(` * - **Tab**: ${args.tabName}`, result);\n\t}\n\n\tconst documentationURL = getDocumentationURL({ field: args.field });\n\tif (documentationURL) {\n\t\tresult = addLine(` * - **Documentation**: ${documentationURL}`, result);\n\t}\n\n\tresult = addLine(\" */\", result);\n\n\treturn result;\n}\n"],"m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K,MAAM,SAChD,KAAK,MAAM,OAAO,gBAClB,KAAA;AACJ,KAAI,iBAAiB,KAAA,EAIpB,UAAS,QAAQ,2BAFhB,OAAO,iBAAiB,YAAY,GAAG,iBAAiB,gBAEc,OAAO;AAM/E,UAAS,QAAQ,yBAHC,aAAa,EAC9B,MAAM,CAAC,GAAG,KAAK,MAAM;EAAE,MAAM,KAAK;EAAM,OAAO,KAAK;EAAO,CAAC,EAC5D,CAAC,IACqD,OAAO;AAE9D,KAAI,KAAK,QACR,UAAS,QAAQ,iBAAiB,KAAK,WAAW,OAAO;CAG1D,MAAM,mBAAmB,oBAAoB,EAAE,OAAO,KAAK,OAAO,CAAC;AACnE,KAAI,iBACH,UAAS,QAAQ,2BAA2B,oBAAoB,OAAO;AAGxE,UAAS,QAAQ,OAAO,OAAO;AAE/B,QAAO"}
|
|
@@ -4,7 +4,7 @@ import { buildTypeName } from "./buildTypeName.mjs";
|
|
|
4
4
|
import { getHumanReadablePath } from "./getHumanReadablePath.mjs";
|
|
5
5
|
import { buildFieldDocs } from "./buildFieldDocs.mjs";
|
|
6
6
|
import { buildUnion } from "./buildUnion.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { source, stripIndent } from "common-tags";
|
|
8
8
|
import { CustomTypeModelFieldType } from "@prismicio/client";
|
|
9
9
|
//#region src/lib/buildFieldProperties.ts
|
|
10
10
|
function buildFieldProperty(args) {
|
|
@@ -42,10 +42,8 @@ function buildFieldProperty(args) {
|
|
|
42
42
|
code = addLine(`${name}: prismic.GeoPointField;`, code);
|
|
43
43
|
break;
|
|
44
44
|
case "Image":
|
|
45
|
-
if (args.field.config?.thumbnails && args.field.config.thumbnails.length > 0) {
|
|
46
|
-
|
|
47
|
-
code = addLine(`${name}: prismic.ImageField<${thumbnailNames}>;`, code);
|
|
48
|
-
} else code = addLine(`${name}: prismic.ImageField<never>;`, code);
|
|
45
|
+
if (args.field.config?.thumbnails && args.field.config.thumbnails.length > 0) code = addLine(`${name}: prismic.ImageField<${buildUnion(args.field.config.thumbnails.map((thumb) => `"${thumb.name}"`))}>;`, code);
|
|
46
|
+
else code = addLine(`${name}: prismic.ImageField<never>;`, code);
|
|
49
47
|
break;
|
|
50
48
|
case "IntegrationFields": {
|
|
51
49
|
const catalogType = args.field.config?.catalog ? args.fieldConfigs.integrationFields?.catalogTypes?.[args.field.config.catalog] : void 0;
|
|
@@ -57,13 +55,11 @@ function buildFieldProperty(args) {
|
|
|
57
55
|
const variants = args.field.config && "variants" in args.field.config && Array.isArray(args.field.config.variants) && args.field.config.variants.length > 0 ? args.field.config.variants.map((variant) => `"${variant.replace(/"/g, "\\\"")}"`).join(" | ") : "never";
|
|
58
56
|
switch (args.field.config?.select) {
|
|
59
57
|
case "document":
|
|
60
|
-
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
code = addLine(`${name}: ${contentRelationshipUnion};`, code);
|
|
66
|
-
} else code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
|
|
58
|
+
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) code = addLine(`${name}: ${buildUnion(args.field.config.customtypes.map((type) => {
|
|
59
|
+
if (typeof type === "string") return `prismic.ContentRelationshipField<"${type}">`;
|
|
60
|
+
return `ContentRelationshipFieldWithData<${JSON.stringify([type])}>`;
|
|
61
|
+
}))};`, code);
|
|
62
|
+
else code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
|
|
67
63
|
break;
|
|
68
64
|
case "media":
|
|
69
65
|
code = addLine(`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`, code);
|
|
@@ -121,7 +117,7 @@ function buildFieldProperty(args) {
|
|
|
121
117
|
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
122
118
|
auxiliaryTypes.push({
|
|
123
119
|
name: itemName,
|
|
124
|
-
code:
|
|
120
|
+
code: source`
|
|
125
121
|
/**
|
|
126
122
|
* Item in *${humanReadablePath}*
|
|
127
123
|
*/
|
|
@@ -168,12 +164,12 @@ function buildFieldProperty(args) {
|
|
|
168
164
|
});
|
|
169
165
|
auxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);
|
|
170
166
|
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
171
|
-
let primaryCode =
|
|
167
|
+
let primaryCode = stripIndent`
|
|
172
168
|
/**
|
|
173
169
|
* Primary content in *${humanReadablePath}*
|
|
174
170
|
*/
|
|
175
171
|
`;
|
|
176
|
-
primaryCode = primaryFieldProperties.code ? addLine(
|
|
172
|
+
primaryCode = primaryFieldProperties.code ? addLine(source`
|
|
177
173
|
export interface ${primaryInterfaceName} {
|
|
178
174
|
${primaryFieldProperties.code}
|
|
179
175
|
}
|
|
@@ -210,12 +206,12 @@ function buildFieldProperty(args) {
|
|
|
210
206
|
});
|
|
211
207
|
auxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);
|
|
212
208
|
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
213
|
-
let itemCode =
|
|
209
|
+
let itemCode = stripIndent`
|
|
214
210
|
/**
|
|
215
211
|
* Item content in *${humanReadablePath}*
|
|
216
212
|
*/
|
|
217
213
|
`;
|
|
218
|
-
itemCode = itemFieldProperties.code ? addLine(
|
|
214
|
+
itemCode = itemFieldProperties.code ? addLine(source`
|
|
219
215
|
export interface ${itemInterfaceName} {
|
|
220
216
|
${itemFieldProperties.code}
|
|
221
217
|
}
|
|
@@ -228,7 +224,7 @@ function buildFieldProperty(args) {
|
|
|
228
224
|
}
|
|
229
225
|
auxiliaryTypes.push({
|
|
230
226
|
name: sliceName,
|
|
231
|
-
code:
|
|
227
|
+
code: stripIndent`
|
|
232
228
|
/**
|
|
233
229
|
* Slice for *${getHumanReadablePath({ path: [...args.path, {
|
|
234
230
|
name: args.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFieldProperties.mjs","names":[],"sources":["../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import { type CustomTypeModelField, CustomTypeModelFieldType } from \"@prismicio/client\";\n\nimport type { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\nimport { addLine } from \"./addLine\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldDocs } from \"./buildFieldDocs\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { dedent } from \"./dedent\";\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(args: BuildFieldPropertyArgs): 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(\"-\") || args.name.includes(\":\") || /^[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 = args.fieldConfigs.embed?.providerTypes[providerType];\n\n\t\t\t\t\tproviderTypes.push(`({ provider_name: \"${providerType}\" } & ${configuredProviderType})`);\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\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 (args.field.config?.thumbnails && args.field.config.thumbnails.length > 0) {\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?.[args.field.config.catalog]\n\t\t\t\t: undefined;\n\n\t\t\tif (catalogType) {\n\t\t\t\tcode = addLine(`${name}: prismic.IntegrationField<${catalogType}>;`, code);\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 contentRelationshipUnion = buildUnion(\n\t\t\t\t\t\t\targs.field.config.customtypes.map((type) => {\n\t\t\t\t\t\t\t\tif (typeof type === \"string\") {\n\t\t\t\t\t\t\t\t\treturn `prismic.ContentRelationshipField<\"${type}\">`;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn `ContentRelationshipFieldWithData<${JSON.stringify([type])}>`;\n\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[] = args.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(`${name}: prismic.SelectField<${optionsType}, \"filled\">;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.SelectField${options.length > 0 ? `<${optionsType}>` : \"\"};`,\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: dedent`\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(`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(`${name}: prismic.GroupField<Simplify<${itemName}>>;`, code);\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 (choice[\"non-repeat\"] && Object.keys(choice[\"non-repeat\"]).length > 0) {\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 = dedent`\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\tdedent`\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\t)\n\t\t\t\t\t\t\t\t: addLine(`export interface ${primaryInterfaceName} {}`, primaryCode);\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 = dedent`\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\tdedent`\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\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: dedent`\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\t\tprimaryInterfaceName\n\t\t\t\t\t\t\t\t\t\t? `Simplify<${primaryInterfaceName}>`\n\t\t\t\t\t\t\t\t\t\t: `Record<string, never>`\n\t\t\t\t\t\t\t\t}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>\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.contentTypeN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AAgB;CACxD;CAEA,OAAO;EACN;EACA;EACA;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"buildFieldProperties.mjs","names":[],"sources":["../../src/lib/buildFieldProperties.ts"],"sourcesContent":["import { type CustomTypeModelField, CustomTypeModelFieldType } from \"@prismicio/client\";\nimport { source, stripIndent } from \"common-tags\";\n\nimport type { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\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(args: BuildFieldPropertyArgs): 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(\"-\") || args.name.includes(\":\") || /^[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 = args.fieldConfigs.embed?.providerTypes[providerType];\n\n\t\t\t\t\tproviderTypes.push(`({ provider_name: \"${providerType}\" } & ${configuredProviderType})`);\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\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 (args.field.config?.thumbnails && args.field.config.thumbnails.length > 0) {\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?.[args.field.config.catalog]\n\t\t\t\t: undefined;\n\n\t\t\tif (catalogType) {\n\t\t\t\tcode = addLine(`${name}: prismic.IntegrationField<${catalogType}>;`, code);\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 contentRelationshipUnion = buildUnion(\n\t\t\t\t\t\t\targs.field.config.customtypes.map((type) => {\n\t\t\t\t\t\t\t\tif (typeof type === \"string\") {\n\t\t\t\t\t\t\t\t\treturn `prismic.ContentRelationshipField<\"${type}\">`;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn `ContentRelationshipFieldWithData<${JSON.stringify([type])}>`;\n\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[] = args.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(`${name}: prismic.SelectField<${optionsType}, \"filled\">;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(\n\t\t\t\t\t`${name}: prismic.SelectField${options.length > 0 ? `<${optionsType}>` : \"\"};`,\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(`${name}: prismic.NestedGroupField<Simplify<${itemName}>>;`, code);\n\t\t\t} else {\n\t\t\t\tcode = addLine(`${name}: prismic.GroupField<Simplify<${itemName}>>;`, code);\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 (choice[\"non-repeat\"] && Object.keys(choice[\"non-repeat\"]).length > 0) {\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\t)\n\t\t\t\t\t\t\t\t: addLine(`export interface ${primaryInterfaceName} {}`, primaryCode);\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\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\t\tprimaryInterfaceName\n\t\t\t\t\t\t\t\t\t\t? `Simplify<${primaryInterfaceName}>`\n\t\t\t\t\t\t\t\t\t\t: `Record<string, never>`\n\t\t\t\t\t\t\t\t}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>\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"],"mappings":";;;;;;;;;AAyBA,SAAS,mBAAmB,MAA4D;CACvF,IAAI,OAAO,eAAe;EACzB,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,MAAM,KAAK;EACX,SAAS,KAAK;EACd,CAAC;CAEF,MAAM,iBAAkC,EAAE;CAC1C,MAAM,mBAA6B,EAAE;CAErC,MAAM,OACL,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,SAAS,KAAK,KAAK,KAAK,GAC3E,IAAI,KAAK,KAAK,KACd,KAAK;AAET,SAAQ,KAAK,MAAM,MAAnB;EACC,KAAK,MAEJ;EAGD,KAAK;AACJ,UAAO,QAAQ,GAAG,KAAK,0BAA0B,KAAK;AAEtD;EAGD,KAAK;AACJ,UAAO,QAAQ,GAAG,KAAK,wBAAwB,KAAK;AAEpD;EAGD,KAAK;AACJ,UAAO,QAAQ,GAAG,KAAK,uBAAuB,KAAK;AAEnD;EAGD,KAAK,SAAS;GACb,MAAM,gBAA0B,EAAE;AAElC,OAAI,KAAK,aAAa,OAAO,cAC5B,MAAK,MAAM,gBAAgB,KAAK,aAAa,OAAO,eAAe;IAClE,MAAM,yBAAyB,KAAK,aAAa,OAAO,cAAc;AAEtE,kBAAc,KAAK,sBAAsB,aAAa,QAAQ,uBAAuB,GAAG;;GAI1F,MAAM,qBAAqB,WAAW,cAAc;AAEpD,UACC,cAAc,SAAS,IACpB,QACA,GAAG,KAAK,kEAAkE,mBAAmB,KAC7F,KACA,GACA,QAAQ,GAAG,KAAK,uBAAuB,KAAK;AAEhD;;EAGD,KAAK;AACJ,UAAO,QAAQ,GAAG,KAAK,2BAA2B,KAAK;AAEvD;EAGD,KAAK;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+4,9 @@ import { buildTypeName } from "./buildTypeName.mjs";
|
|
|
4
4
|
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
5
5
|
import { getHumanReadablePath } from "./getHumanReadablePath.mjs";
|
|
6
6
|
import { buildUnion } from "./buildUnion.mjs";
|
|
7
|
-
import { dedent } from "./dedent.mjs";
|
|
8
7
|
import { buildFieldProperties } from "./buildFieldProperties.mjs";
|
|
9
8
|
import { getCacheKey } from "./getCacheKey.mjs";
|
|
9
|
+
import { source, stripIndent } from "common-tags";
|
|
10
10
|
//#region src/lib/buildSharedSliceType.ts
|
|
11
11
|
function buildSharedSliceType(args) {
|
|
12
12
|
if (args.cache) {
|
|
@@ -51,17 +51,17 @@ function buildSharedSliceType(args) {
|
|
|
51
51
|
auxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);
|
|
52
52
|
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
53
53
|
contentTypeNames.push(primaryInterfaceName);
|
|
54
|
-
const docs =
|
|
54
|
+
const docs = stripIndent`
|
|
55
55
|
/**
|
|
56
56
|
* Primary content in *${humanReadablePath}*
|
|
57
57
|
*/
|
|
58
58
|
`;
|
|
59
|
-
code = addSection(primaryFieldProperties.code ?
|
|
59
|
+
code = addSection(primaryFieldProperties.code ? source`
|
|
60
60
|
${docs}
|
|
61
61
|
export interface ${primaryInterfaceName} {
|
|
62
62
|
${primaryFieldProperties.code}
|
|
63
63
|
}
|
|
64
|
-
` :
|
|
64
|
+
` : source`
|
|
65
65
|
${docs}
|
|
66
66
|
export interface ${primaryInterfaceName} {}
|
|
67
67
|
`, code);
|
|
@@ -85,22 +85,22 @@ function buildSharedSliceType(args) {
|
|
|
85
85
|
auxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);
|
|
86
86
|
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
87
87
|
contentTypeNames.push(itemInterfaceName);
|
|
88
|
-
const docs =
|
|
88
|
+
const docs = stripIndent`
|
|
89
89
|
/**
|
|
90
90
|
* Primary content in *${humanReadablePath}*
|
|
91
91
|
*/
|
|
92
92
|
`;
|
|
93
|
-
code = addSection(itemFieldProperties.code ?
|
|
93
|
+
code = addSection(itemFieldProperties.code ? source`
|
|
94
94
|
${docs}
|
|
95
95
|
export interface ${itemInterfaceName} {
|
|
96
96
|
${itemFieldProperties.code}
|
|
97
97
|
}
|
|
98
|
-
` :
|
|
98
|
+
` : source`
|
|
99
99
|
${docs}
|
|
100
100
|
export interface ${itemInterfaceName} {}
|
|
101
101
|
`, code);
|
|
102
102
|
}
|
|
103
|
-
code = addSection(
|
|
103
|
+
code = addSection(source`
|
|
104
104
|
/**
|
|
105
105
|
* ${variationModel.name} variation for ${humanReadableName} Slice
|
|
106
106
|
*
|
|
@@ -116,13 +116,13 @@ function buildSharedSliceType(args) {
|
|
|
116
116
|
const variationsUnion = buildUnion(variationNames);
|
|
117
117
|
contentTypeNames.push(variationUnionName);
|
|
118
118
|
contentTypeNames.push(...variationNames);
|
|
119
|
-
code = addSection(
|
|
119
|
+
code = addSection(source`
|
|
120
120
|
/**
|
|
121
121
|
* Slice variation for *${humanReadableName}*
|
|
122
122
|
*/
|
|
123
123
|
type ${variationUnionName} = ${variationNames.length > 0 ? variationsUnion : "never"}
|
|
124
124
|
`, code);
|
|
125
|
-
code = addSection(
|
|
125
|
+
code = addSection(source`
|
|
126
126
|
/**
|
|
127
127
|
* ${humanReadableName} Shared Slice
|
|
128
128
|
*
|