prismic-ts-codegen 0.1.29 → 0.1.30-pr.82.96148f3
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/bin/prismic-ts-codegen.js +1 -1
- package/dist/cli/{configSchema.d.ts → configSchema.d.mts} +3 -5
- package/dist/cli/configSchema.d.mts.map +1 -0
- package/dist/cli/configSchema.mjs +154 -0
- package/dist/cli/configSchema.mjs.map +1 -0
- package/dist/cli/constants.d.mts +4 -0
- package/dist/cli/constants.d.mts.map +1 -0
- package/dist/cli/{constants.js → constants.mjs} +1 -1
- package/dist/cli/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/cli/loadConfig.mjs +20 -0
- package/dist/cli/loadConfig.mjs.map +1 -0
- package/dist/cli/{loadLocaleIDs.js → loadLocaleIDs.mjs} +1 -2
- package/dist/cli/loadLocaleIDs.mjs.map +1 -0
- package/dist/cli/{loadModels.js → loadModels.mjs} +14 -11
- package/dist/cli/loadModels.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{cli.js → cli.mjs} +51 -25
- package/dist/cli.mjs.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/{constants.cjs.map → constants.mjs.map} +1 -1
- package/dist/detectTypesProvider.d.mts +15 -0
- package/dist/detectTypesProvider.d.mts.map +1 -0
- package/dist/{detectTypesProvider.js → detectTypesProvider.mjs} +1 -1
- package/dist/{detectTypesProvider.cjs.map → detectTypesProvider.mjs.map} +1 -1
- package/dist/{generateTypes.d.ts → generateTypes.d.mts} +5 -7
- package/dist/generateTypes.d.mts.map +1 -0
- package/dist/{generateTypes.js → generateTypes.mjs} +21 -18
- package/dist/generateTypes.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +4 -4
- package/dist/index.mjs +4 -0
- package/dist/lib/{addBlankLine.js → addBlankLine.mjs} +2 -2
- package/dist/lib/addBlankLine.mjs.map +1 -0
- package/dist/lib/{addLine.js → addLine.mjs} +2 -2
- package/dist/lib/addLine.mjs.map +1 -0
- package/dist/lib/{addSection.js → addSection.mjs} +2 -2
- package/dist/lib/addSection.mjs.map +1 -0
- package/dist/lib/{addTrailingNewLine.js → addTrailingNewLine.mjs} +1 -1
- package/dist/lib/{addTrailingNewLine.cjs.map → addTrailingNewLine.mjs.map} +1 -1
- package/dist/lib/{buildCustomTypeDataType.js → buildCustomTypeDataType.mjs} +6 -6
- package/dist/lib/buildCustomTypeDataType.mjs.map +1 -0
- package/dist/lib/{buildCustomTypeType.js → buildCustomTypeType.mjs} +11 -11
- package/dist/lib/buildCustomTypeType.mjs.map +1 -0
- package/dist/lib/{buildFieldDocs.js → buildFieldDocs.mjs} +15 -10
- package/dist/lib/buildFieldDocs.mjs.map +1 -0
- package/dist/lib/{buildFieldProperties.js → buildFieldProperties.mjs} +25 -21
- package/dist/lib/buildFieldProperties.mjs.map +1 -0
- package/dist/lib/{buildSharedSliceType.js → buildSharedSliceType.mjs} +19 -19
- package/dist/lib/buildSharedSliceType.mjs.map +1 -0
- package/dist/lib/buildTypeName.mjs +11 -0
- package/dist/lib/buildTypeName.mjs.map +1 -0
- package/dist/lib/{buildUnion.js → buildUnion.mjs} +1 -1
- package/dist/lib/{buildUnion.cjs.map → buildUnion.mjs.map} +1 -1
- package/dist/lib/{checkHasUIDFIeld.js → checkHasUIDFIeld.mjs} +1 -1
- package/dist/lib/{checkHasUIDFIeld.cjs.map → checkHasUIDFIeld.mjs.map} +1 -1
- package/dist/lib/dedent.mjs +12 -0
- package/dist/lib/dedent.mjs.map +1 -0
- package/dist/lib/{getAPIIDPath.js → getAPIIDPath.mjs} +1 -1
- package/dist/lib/{getAPIIDPath.cjs.map → getAPIIDPath.mjs.map} +1 -1
- package/dist/lib/{getCacheKey.js → getCacheKey.mjs} +1 -1
- package/dist/lib/getCacheKey.mjs.map +1 -0
- package/dist/lib/{getHumanReadableModelName.js → getHumanReadableModelName.mjs} +1 -1
- package/dist/lib/{getHumanReadableModelName.cjs.map → getHumanReadableModelName.mjs.map} +1 -1
- package/dist/lib/{getHumanReadablePath.js → getHumanReadablePath.mjs} +2 -2
- package/dist/lib/getHumanReadablePath.mjs.map +1 -0
- package/dist/package.mjs +7 -0
- package/dist/package.mjs.map +1 -0
- package/dist/{types.d.ts → types.d.mts} +2 -4
- package/dist/types.d.mts.map +1 -0
- package/package.json +19 -29
- package/src/cli/index.ts +38 -22
- package/src/cli/loadConfig.ts +7 -9
- package/src/cli/loadLocaleIDs.ts +0 -1
- package/src/cli/loadModels.ts +30 -12
- 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 +22 -33
- package/src/lib/buildTypeName.ts +9 -4
- package/src/lib/dedent.ts +14 -0
- package/dist/_virtual/_rolldown/runtime.cjs +0 -23
- package/dist/cli/configSchema.cjs +0 -31
- package/dist/cli/configSchema.cjs.map +0 -1
- package/dist/cli/configSchema.d.cts +0 -39
- package/dist/cli/configSchema.d.cts.map +0 -1
- package/dist/cli/configSchema.d.ts.map +0 -1
- package/dist/cli/configSchema.js +0 -30
- package/dist/cli/configSchema.js.map +0 -1
- package/dist/cli/constants.cjs +0 -6
- package/dist/cli/constants.d.cts +0 -5
- package/dist/cli/constants.d.cts.map +0 -1
- package/dist/cli/constants.d.ts +0 -5
- package/dist/cli/constants.d.ts.map +0 -1
- package/dist/cli/constants.js.map +0 -1
- package/dist/cli/loadConfig.cjs +0 -22
- package/dist/cli/loadConfig.cjs.map +0 -1
- package/dist/cli/loadConfig.js +0 -20
- package/dist/cli/loadConfig.js.map +0 -1
- package/dist/cli/loadLocaleIDs.cjs +0 -21
- package/dist/cli/loadLocaleIDs.cjs.map +0 -1
- package/dist/cli/loadLocaleIDs.js.map +0 -1
- package/dist/cli/loadModels.cjs +0 -54
- package/dist/cli/loadModels.cjs.map +0 -1
- package/dist/cli/loadModels.js.map +0 -1
- package/dist/cli.cjs +0 -110
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/constants.cjs +0 -33
- package/dist/constants.js.map +0 -1
- package/dist/detectTypesProvider.cjs +0 -25
- package/dist/detectTypesProvider.d.cts +0 -17
- package/dist/detectTypesProvider.d.cts.map +0 -1
- package/dist/detectTypesProvider.d.ts +0 -17
- package/dist/detectTypesProvider.d.ts.map +0 -1
- package/dist/detectTypesProvider.js.map +0 -1
- package/dist/generateTypes.cjs +0 -144
- package/dist/generateTypes.cjs.map +0 -1
- package/dist/generateTypes.d.cts +0 -21
- package/dist/generateTypes.d.cts.map +0 -1
- package/dist/generateTypes.d.ts.map +0 -1
- package/dist/generateTypes.js.map +0 -1
- package/dist/index.cjs +0 -7
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -4
- package/dist/lib/addBlankLine.cjs +0 -10
- package/dist/lib/addBlankLine.cjs.map +0 -1
- package/dist/lib/addBlankLine.js.map +0 -1
- package/dist/lib/addLine.cjs +0 -9
- package/dist/lib/addLine.cjs.map +0 -1
- package/dist/lib/addLine.js.map +0 -1
- package/dist/lib/addSection.cjs +0 -9
- package/dist/lib/addSection.cjs.map +0 -1
- package/dist/lib/addSection.js.map +0 -1
- package/dist/lib/addTrailingNewLine.cjs +0 -9
- package/dist/lib/addTrailingNewLine.js.map +0 -1
- package/dist/lib/buildCustomTypeDataType.cjs +0 -51
- package/dist/lib/buildCustomTypeDataType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDataType.js.map +0 -1
- package/dist/lib/buildCustomTypeType.cjs +0 -63
- package/dist/lib/buildCustomTypeType.cjs.map +0 -1
- package/dist/lib/buildCustomTypeType.js.map +0 -1
- package/dist/lib/buildFieldDocs.cjs +0 -66
- package/dist/lib/buildFieldDocs.cjs.map +0 -1
- package/dist/lib/buildFieldDocs.js.map +0 -1
- package/dist/lib/buildFieldProperties.cjs +0 -285
- package/dist/lib/buildFieldProperties.cjs.map +0 -1
- package/dist/lib/buildFieldProperties.js.map +0 -1
- package/dist/lib/buildSharedSliceType.cjs +0 -152
- package/dist/lib/buildSharedSliceType.cjs.map +0 -1
- package/dist/lib/buildSharedSliceType.js.map +0 -1
- package/dist/lib/buildTypeName.cjs +0 -12
- package/dist/lib/buildTypeName.cjs.map +0 -1
- package/dist/lib/buildTypeName.js +0 -11
- package/dist/lib/buildTypeName.js.map +0 -1
- package/dist/lib/buildUnion.cjs +0 -8
- package/dist/lib/buildUnion.js.map +0 -1
- package/dist/lib/checkHasUIDFIeld.cjs +0 -8
- package/dist/lib/checkHasUIDFIeld.js.map +0 -1
- package/dist/lib/getAPIIDPath.cjs +0 -24
- package/dist/lib/getAPIIDPath.js.map +0 -1
- package/dist/lib/getCacheKey.cjs +0 -17
- package/dist/lib/getCacheKey.cjs.map +0 -1
- package/dist/lib/getCacheKey.js.map +0 -1
- package/dist/lib/getHumanReadableModelName.cjs +0 -15
- package/dist/lib/getHumanReadableModelName.js.map +0 -1
- package/dist/lib/getHumanReadablePath.cjs +0 -16
- package/dist/lib/getHumanReadablePath.cjs.map +0 -1
- package/dist/lib/getHumanReadablePath.js.map +0 -1
- package/dist/types.d.cts +0 -14
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { addLine } from "./lib/addLine.
|
|
2
|
-
import { addSection } from "./lib/addSection.
|
|
3
|
-
import { buildUnion } from "./lib/buildUnion.
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { addLine } from "./lib/addLine.mjs";
|
|
2
|
+
import { addSection } from "./lib/addSection.mjs";
|
|
3
|
+
import { buildUnion } from "./lib/buildUnion.mjs";
|
|
4
|
+
import { dedent } from "./lib/dedent.mjs";
|
|
5
|
+
import { buildCustomTypeType } from "./lib/buildCustomTypeType.mjs";
|
|
6
|
+
import { buildSharedSliceType } from "./lib/buildSharedSliceType.mjs";
|
|
7
7
|
import QuickLRU from "quick-lru";
|
|
8
8
|
//#region src/generateTypes.ts
|
|
9
9
|
const cache = new QuickLRU({ maxSize: 1e3 });
|
|
@@ -83,7 +83,8 @@ type ContentRelationshipFieldWithData<
|
|
|
83
83
|
}
|
|
84
84
|
if (config.customTypeModels.length > 0) {
|
|
85
85
|
const allDocumentTypesUnionName = "AllDocumentTypes";
|
|
86
|
-
|
|
86
|
+
const allDocumentTypesUnion = buildUnion(allDocumentTypesTypeNames);
|
|
87
|
+
code = addSection(`export type ${allDocumentTypesUnionName} = ${allDocumentTypesUnion};`, code);
|
|
87
88
|
contentTypeNames.push(allDocumentTypesUnionName);
|
|
88
89
|
}
|
|
89
90
|
}
|
|
@@ -100,35 +101,37 @@ type ContentRelationshipFieldWithData<
|
|
|
100
101
|
}
|
|
101
102
|
if (config.clientIntegration?.includeCreateClientInterface || config.clientIntegration?.includeContentNamespace) {
|
|
102
103
|
let clientModuleCode = "";
|
|
103
|
-
if (config.clientIntegration.includeCreateClientInterface)
|
|
104
|
-
|
|
104
|
+
if (config.clientIntegration.includeCreateClientInterface) {
|
|
105
|
+
if ((config.customTypeModels?.length || 0) > 0) {
|
|
106
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
105
107
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client<AllDocumentTypes>;
|
|
106
108
|
}`, clientModuleCode);
|
|
107
|
-
|
|
109
|
+
clientModuleCode = addSection(`interface CreateWriteClient {
|
|
108
110
|
(repositoryNameOrEndpoint: string, options: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient<AllDocumentTypes>;
|
|
109
111
|
}`, clientModuleCode);
|
|
110
|
-
|
|
112
|
+
clientModuleCode = addSection(`interface CreateMigration {
|
|
111
113
|
(): ${clientImportName}.Migration<AllDocumentTypes>;
|
|
112
114
|
}`, clientModuleCode);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
} else {
|
|
116
|
+
clientModuleCode = addSection(`interface CreateClient {
|
|
115
117
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.ClientConfig): ${clientImportName}.Client;
|
|
116
118
|
}`, clientModuleCode);
|
|
117
|
-
|
|
119
|
+
clientModuleCode = addSection(`interface CreateWriteClient {
|
|
118
120
|
(repositoryNameOrEndpoint: string, options?: ${clientImportName}.WriteClientConfig): ${clientImportName}.WriteClient;
|
|
119
121
|
}`, clientModuleCode);
|
|
120
|
-
|
|
122
|
+
clientModuleCode = addSection(`interface CreateMigration {
|
|
121
123
|
(): ${clientImportName}.Migration;
|
|
122
124
|
}`, clientModuleCode);
|
|
125
|
+
}
|
|
123
126
|
}
|
|
124
|
-
if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(
|
|
127
|
+
if (config.clientIntegration.includeContentNamespace) clientModuleCode = addSection(dedent`
|
|
125
128
|
namespace Content {
|
|
126
129
|
export type {
|
|
127
130
|
${contentTypeNames.join(",\n")}
|
|
128
131
|
}
|
|
129
132
|
}
|
|
130
133
|
`, clientModuleCode);
|
|
131
|
-
code = addSection(
|
|
134
|
+
code = addSection(dedent`
|
|
132
135
|
declare module "@prismicio/client" {
|
|
133
136
|
${clientModuleCode}
|
|
134
137
|
}
|
|
@@ -139,4 +142,4 @@ type ContentRelationshipFieldWithData<
|
|
|
139
142
|
//#endregion
|
|
140
143
|
export { generateTypes };
|
|
141
144
|
|
|
142
|
-
//# sourceMappingURL=generateTypes.
|
|
145
|
+
//# sourceMappingURL=generateTypes.mjs.map
|
|
@@ -0,0 +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 { dedent } from \"./lib/dedent\";\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\tdedent`\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\tdedent`\n\t\t\t\tdeclare module \"@prismicio/client\" {\n\t\t\t\t\t${clientModuleCode}\n\t\t\t\t}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A,iBAAiB,KAAK,yBAAyB;EAChD;CACD;CAEA,IAAI,OAAO,mBACV,KAAK,MAAM,SAAS,OAAO,mBAAmB;EAC7C,MAAM,kBAAkB,qBAAqB;GAC5C;GACA;GACA,OAAO,iBAAiB,QAAQ,KAAA;EACjC,CAAC;EAED,KAAK,MAAM,iBAAiB,gBAAgB,gBAC3C,OAAO,WAAW,cAAc,MAAM,IAAI;EAG3C,OAAO,WAAW,gBAAgB,MAAM,IAAI;EAE5C,iBAAiB,KAAK,gBAAgB,IAAI;EAC1C,iBAAiB,KAAK,GAAG,gBAAgB,gBAAgB;CAC1D;CAGD,IACC,OAAO,mBAAmB,gCAC1B,OAAO,mBAAmB,yBACzB;EACD,IAAI,mBAAmB;EAEvB,IAAI,OAAO,kBAAkB,8BAA8B;GAC1D,KAAK,OAAO,kBAAkB,UAAU,KAAK,GAAG;IAC/C,mBAAmB,WAClB;gDAC2C,iBAAiB,kBAAkB,iBAAiB;IAE/F,gBACD;IACA,mBAAmB,WAClB;+CAC0C,iBAAiB,uBAAuB,iBAAiB;IAEnG,gBACD;IACA,mBAAmB,WAClB;OACE,iBAAiB;IAEnB,gBACD;GACD,OAAO;IACN,mBAAmB,WAClB;gDAC2C,iBAAiB,kBAAkB,iBAAiB;IAE/F,gBACD;IACA,mBAAmB,WAClB;gDAC2C,iBAAiB,uBAAuB,iBAAiB;IAEpG,gBACD;IACA,mBAAmB,WAClB;OACE,iBAAiB;IAEnB,gBACD;GACD;EACD;EAEA,IAAI,OAAO,kBAAkB,yBAC5B,mBAAmB,WAClB,MAAM;;;SAGD,iBAAiB,KAAK,KAAK,EAAE;;;OAIlC,gBACD;EAGD,OAAO,WACN,MAAM;;OAEF,iBAAiB;;MAGrB,IACD;CACD;CAEA,OAAO;AACR"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenerateTypesConfig, TypesProvider, generateTypes } from "./generateTypes.
|
|
2
|
-
import { DetectTypesProviderConfig, detectTypesProvider } from "./detectTypesProvider.
|
|
3
|
-
import { Config } from "./cli/configSchema.
|
|
4
|
-
import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.
|
|
1
|
+
import { GenerateTypesConfig, TypesProvider, generateTypes } from "./generateTypes.mjs";
|
|
2
|
+
import { DetectTypesProviderConfig, detectTypesProvider } from "./detectTypesProvider.mjs";
|
|
3
|
+
import { Config } from "./cli/configSchema.mjs";
|
|
4
|
+
import { NON_EDITABLE_FILE_HEADER } from "./cli/constants.mjs";
|
|
5
5
|
export { type Config, type DetectTypesProviderConfig, type GenerateTypesConfig, NON_EDITABLE_FILE_HEADER, type TypesProvider, detectTypesProvider, generateTypes };
|
package/dist/index.mjs
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingNewLine } from "./addTrailingNewLine.
|
|
1
|
+
import { addTrailingNewLine } from "./addTrailingNewLine.mjs";
|
|
2
2
|
//#region src/lib/addBlankLine.ts
|
|
3
3
|
function addBlankLine(state, config) {
|
|
4
4
|
if ((!state || state.endsWith("\n\n")) && !config?.force) return state;
|
|
@@ -7,4 +7,4 @@ function addBlankLine(state, config) {
|
|
|
7
7
|
//#endregion
|
|
8
8
|
export { addBlankLine };
|
|
9
9
|
|
|
10
|
-
//# sourceMappingURL=addBlankLine.
|
|
10
|
+
//# sourceMappingURL=addBlankLine.mjs.map
|
|
@@ -0,0 +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;CAChF,KAAK,CAAC,SAAS,MAAM,SAAS,MAAM,MAAM,CAAC,QAAQ,OAClD,OAAO;MAEP,OAAO,mBAAmB,KAAK,IAAI;AAErC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTrailingNewLine } from "./addTrailingNewLine.
|
|
1
|
+
import { addTrailingNewLine } from "./addTrailingNewLine.mjs";
|
|
2
2
|
//#region src/lib/addLine.ts
|
|
3
3
|
function addLine(line, state) {
|
|
4
4
|
return addTrailingNewLine(state) + line;
|
|
@@ -6,4 +6,4 @@ function addLine(line, state) {
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { addLine };
|
|
8
8
|
|
|
9
|
-
//# sourceMappingURL=addLine.
|
|
9
|
+
//# sourceMappingURL=addLine.mjs.map
|
|
@@ -0,0 +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;CAC5D,OAAO,mBAAmB,KAAK,IAAI;AACpC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addBlankLine } from "./addBlankLine.
|
|
1
|
+
import { addBlankLine } from "./addBlankLine.mjs";
|
|
2
2
|
//#region src/lib/addSection.ts
|
|
3
3
|
function addSection(section, state) {
|
|
4
4
|
return addBlankLine(state) + section;
|
|
@@ -6,4 +6,4 @@ function addSection(section, state) {
|
|
|
6
6
|
//#endregion
|
|
7
7
|
export { addSection };
|
|
8
8
|
|
|
9
|
-
//# sourceMappingURL=addSection.
|
|
9
|
+
//# sourceMappingURL=addSection.mjs.map
|
|
@@ -0,0 +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;CAClE,OAAO,aAAa,KAAK,IAAI;AAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addTrailingNewLine.
|
|
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;CAC5F,KAAK,CAAC,SAAS,MAAM,SAAS,IAAI,MAAM,CAAC,QAAQ,OAChD,OAAO;MAEP,OAAO,QAAQ;AAEjB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { buildTypeName } from "./buildTypeName.
|
|
2
|
-
import { getHumanReadableModelName } from "./getHumanReadableModelName.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { buildTypeName } from "./buildTypeName.mjs";
|
|
2
|
+
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
3
|
+
import { dedent } from "./dedent.mjs";
|
|
4
|
+
import { buildFieldProperties } from "./buildFieldProperties.mjs";
|
|
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 = dedent`
|
|
32
32
|
/**
|
|
33
33
|
* Content for ${humanReadableName} documents
|
|
34
34
|
*/
|
|
@@ -47,4 +47,4 @@ function buildCustomTypeDataType(args) {
|
|
|
47
47
|
//#endregion
|
|
48
48
|
export { buildCustomTypeDataType };
|
|
49
49
|
|
|
50
|
-
//# sourceMappingURL=buildCustomTypeDataType.
|
|
50
|
+
//# sourceMappingURL=buildCustomTypeDataType.mjs.map
|
|
@@ -0,0 +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 { dedent } from \"./dedent\";\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 = dedent`\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,CAAC;CACzC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,YAAY,MAAM;CAC5D,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;CACb,CAAC;CAED,IAAI,kBAAkB;CAEtB,KAAK,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;GACb,CACD;GACA;EACD,CAAC;EAED,mBAAmB,mBAAmB;EAEtC,eAAe,KAAK,GAAG,mBAAmB,cAAc;EACxD,iBAAiB,KAAK,GAAG,mBAAmB,gBAAgB;CAC7D;CAEA,IAAI,iBACH,OAAO,MAAM;;oBAEK,kBAAkB;;eAEvB,KAAK;MACd,gBAAgB;;;MAIpB,OAAO,aAAa,KAAK;CAG1B,OAAO;EACN;EACA;EACA;EACA;CACD;AACD"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { addSection } from "./addSection.
|
|
2
|
-
import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants.
|
|
3
|
-
import { buildTypeName } from "./buildTypeName.
|
|
4
|
-
import { getHumanReadableModelName } from "./getHumanReadableModelName.
|
|
5
|
-
import { buildUnion } from "./buildUnion.
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import { addSection } from "./addSection.mjs";
|
|
2
|
+
import { CUSTOM_TYPES_DOCUMENTATION_URL } from "../constants.mjs";
|
|
3
|
+
import { buildTypeName } from "./buildTypeName.mjs";
|
|
4
|
+
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
5
|
+
import { buildUnion } from "./buildUnion.mjs";
|
|
6
|
+
import { dedent } from "./dedent.mjs";
|
|
7
|
+
import { buildCustomTypeDataType } from "./buildCustomTypeDataType.mjs";
|
|
8
|
+
import { checkHasUIDField } from "./checkHasUIDFIeld.mjs";
|
|
9
|
+
import { getCacheKey } from "./getCacheKey.mjs";
|
|
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(dedent`
|
|
36
36
|
/**
|
|
37
37
|
* ${humanReadableName} document from Prismic
|
|
38
38
|
*
|
|
@@ -59,4 +59,4 @@ function buildCustomTypeType(args) {
|
|
|
59
59
|
//#endregion
|
|
60
60
|
export { buildCustomTypeType };
|
|
61
61
|
|
|
62
|
-
//# sourceMappingURL=buildCustomTypeType.
|
|
62
|
+
//# sourceMappingURL=buildCustomTypeType.mjs.map
|
|
@@ -0,0 +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 { dedent } from \"./dedent\";\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\tdedent`\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\t\tdataType.name\n\t\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;CACjC,IAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,KAAK,KAAK;EAClC,MAAM,SAAS,KAAK,MAAM,IAAI,GAAG;EAEjC,IAAI,QACH,OAAO;CAET;CAEA,IAAI,OAAO;CAEX,MAAM,iBAAkC,CAAC;CACzC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,UAAU;CACpD,MAAM,cACL,KAAK,aAAa,KAAK,UAAU,SAAS,IACvC,WAAW,KAAK,UAAU,KAAK,aAAa,IAAI,SAAS,EAAE,CAAC,IAC5D;CACJ,MAAM,mBAAmB,iBAAiB,KAAK,KAAK,IACjD,2BACA;CACH,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;CACb,CAAC;CAED,MAAM,WAAW,wBAAwB;EACxC,OAAO,KAAK;EACZ,cAAc,KAAK;CACpB,CAAC;CAED,eAAe,KAAK,GAAG,SAAS,cAAc;CAC9C,iBAAiB,KAAK,SAAS,IAAI;CACnC,iBAAiB,KAAK,GAAG,SAAS,gBAAgB;CAElD,OAAO,WAAW,SAAS,MAAM,IAAI;CAErC,OAAO,WACN,MAAM;;QAEA,kBAAkB;;wBAEF,KAAK,MAAM,GAAG;4BACV,KAAK,MAAM,WAAW,SAAS,EAAE;6BAChC,+BAA+B;;;;iBAI3C,KAAK,yBAAyB,YAAY,cAAc,iBAAiB,YACtF,SAAS,KACT,MAAM,KAAK,MAAM,GAAG;KAEtB,IACD;CAEA,MAAM,SAAS;EACd;EACA;EACA;EACA;CACD;CAEA,IAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,KAAK,KAAK;EAElC,KAAK,MAAM,IAAI,KAAK,MAAM;CAC3B;CAEA,OAAO;AACR"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { addLine } from "./addLine.
|
|
2
|
-
import { FIELD_DOCUMENTATION_URLS } from "../constants.
|
|
3
|
-
import { getAPIIDPath } from "./getAPIIDPath.
|
|
4
|
-
import { getHumanReadableModelName } from "./getHumanReadableModelName.
|
|
5
|
-
import { getHumanReadablePath } from "./getHumanReadablePath.
|
|
1
|
+
import { addLine } from "./addLine.mjs";
|
|
2
|
+
import { FIELD_DOCUMENTATION_URLS } from "../constants.mjs";
|
|
3
|
+
import { getAPIIDPath } from "./getAPIIDPath.mjs";
|
|
4
|
+
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
5
|
+
import { getHumanReadablePath } from "./getHumanReadablePath.mjs";
|
|
6
6
|
//#region src/lib/buildFieldDocs.ts
|
|
7
7
|
function getHumanReadableFieldType(args) {
|
|
8
8
|
switch (args.field.type) {
|
|
@@ -47,13 +47,18 @@ 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
|
-
|
|
50
|
+
const placeholder = args.field.config && "placeholder" in args.field.config && args.field.config.placeholder || `*None*`;
|
|
51
|
+
result = addLine(` * - **Placeholder**: ${placeholder}`, result);
|
|
51
52
|
const defaultValue = args.field.config && "default_value" in args.field.config ? args.field.config.default_value : void 0;
|
|
52
|
-
if (defaultValue !== void 0)
|
|
53
|
-
|
|
53
|
+
if (defaultValue !== void 0) {
|
|
54
|
+
const stringifiedDefaultValue = typeof defaultValue === "boolean" ? `${defaultValue}` : defaultValue;
|
|
55
|
+
result = addLine(` * - **Default Value**: ${stringifiedDefaultValue}`, result);
|
|
56
|
+
}
|
|
57
|
+
const apiIDPath = getAPIIDPath({ path: [...args.path, {
|
|
54
58
|
name: args.name,
|
|
55
59
|
model: args.field
|
|
56
|
-
}] })
|
|
60
|
+
}] });
|
|
61
|
+
result = addLine(` * - **API ID Path**: ${apiIDPath}`, result);
|
|
57
62
|
if (args.tabName) result = addLine(` * - **Tab**: ${args.tabName}`, result);
|
|
58
63
|
const documentationURL = getDocumentationURL({ field: args.field });
|
|
59
64
|
if (documentationURL) result = addLine(` * - **Documentation**: ${documentationURL}`, result);
|
|
@@ -63,4 +68,4 @@ function buildFieldDocs(args) {
|
|
|
63
68
|
//#endregion
|
|
64
69
|
export { buildFieldDocs };
|
|
65
70
|
|
|
66
|
-
//# sourceMappingURL=buildFieldDocs.
|
|
71
|
+
//# sourceMappingURL=buildFieldDocs.mjs.map
|
|
@@ -0,0 +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(` * - **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,MAAM,UAAU,KAAK,MAAM,OAAO,eAC9E;CACD,SAAS,QAAQ,yBAAyB,eAAe,MAAM;CAE/D,MAAM,eACL,KAAK,MAAM,UAAU,mBAAmB,KAAK,MAAM,SAChD,KAAK,MAAM,OAAO,gBAClB,KAAA;CACJ,IAAI,iBAAiB,KAAA,GAAW;EAC/B,MAAM,0BACL,OAAO,iBAAiB,YAAY,GAAG,iBAAiB;EAEzD,SAAS,QAAQ,2BAA2B,2BAA2B,MAAM;CAC9E;CAEA,MAAM,YAAY,aAAa,EAC9B,MAAM,CAAC,GAAG,KAAK,MAAM;EAAE,MAAM,KAAK;EAAM,OAAO,KAAK;CAAM,CAAC,EAC5D,CAAC;CACD,SAAS,QAAQ,yBAAyB,aAAa,MAAM;CAE7D,IAAI,KAAK,SACR,SAAS,QAAQ,iBAAiB,KAAK,WAAW,MAAM;CAGzD,MAAM,mBAAmB,oBAAoB,EAAE,OAAO,KAAK,MAAM,CAAC;CAClE,IAAI,kBACH,SAAS,QAAQ,2BAA2B,oBAAoB,MAAM;CAGvE,SAAS,QAAQ,OAAO,MAAM;CAE9B,OAAO;AACR"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { addLine } from "./addLine.
|
|
2
|
-
import { addSection } from "./addSection.
|
|
3
|
-
import { buildTypeName } from "./buildTypeName.
|
|
4
|
-
import { getHumanReadablePath } from "./getHumanReadablePath.
|
|
5
|
-
import { buildFieldDocs } from "./buildFieldDocs.
|
|
6
|
-
import { buildUnion } from "./buildUnion.
|
|
7
|
-
import {
|
|
1
|
+
import { addLine } from "./addLine.mjs";
|
|
2
|
+
import { addSection } from "./addSection.mjs";
|
|
3
|
+
import { buildTypeName } from "./buildTypeName.mjs";
|
|
4
|
+
import { getHumanReadablePath } from "./getHumanReadablePath.mjs";
|
|
5
|
+
import { buildFieldDocs } from "./buildFieldDocs.mjs";
|
|
6
|
+
import { buildUnion } from "./buildUnion.mjs";
|
|
7
|
+
import { dedent } from "./dedent.mjs";
|
|
8
8
|
import { CustomTypeModelFieldType } from "@prismicio/client";
|
|
9
9
|
//#region src/lib/buildFieldProperties.ts
|
|
10
10
|
function buildFieldProperty(args) {
|
|
@@ -42,8 +42,10 @@ 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
|
-
|
|
45
|
+
if (args.field.config?.thumbnails && args.field.config.thumbnails.length > 0) {
|
|
46
|
+
const thumbnailNames = buildUnion(args.field.config.thumbnails.map((thumb) => `"${thumb.name}"`));
|
|
47
|
+
code = addLine(`${name}: prismic.ImageField<${thumbnailNames}>;`, code);
|
|
48
|
+
} else code = addLine(`${name}: prismic.ImageField<never>;`, code);
|
|
47
49
|
break;
|
|
48
50
|
case "IntegrationFields": {
|
|
49
51
|
const catalogType = args.field.config?.catalog ? args.fieldConfigs.integrationFields?.catalogTypes?.[args.field.config.catalog] : void 0;
|
|
@@ -55,11 +57,13 @@ function buildFieldProperty(args) {
|
|
|
55
57
|
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";
|
|
56
58
|
switch (args.field.config?.select) {
|
|
57
59
|
case "document":
|
|
58
|
-
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if ("customtypes" in args.field.config && args.field.config.customtypes && args.field.config.customtypes.length > 0) {
|
|
61
|
+
const contentRelationshipUnion = buildUnion(args.field.config.customtypes.map((type) => {
|
|
62
|
+
if (typeof type === "string") return `prismic.ContentRelationshipField<"${type}">`;
|
|
63
|
+
return `ContentRelationshipFieldWithData<${JSON.stringify([type])}>`;
|
|
64
|
+
}));
|
|
65
|
+
code = addLine(`${name}: ${contentRelationshipUnion};`, code);
|
|
66
|
+
} else code = addLine(`${name}: prismic.ContentRelationshipField;`, code);
|
|
63
67
|
break;
|
|
64
68
|
case "media":
|
|
65
69
|
code = addLine(`${name}: prismic.LinkToMediaField<prismic.FieldState, ${variants}>;`, code);
|
|
@@ -117,7 +121,7 @@ function buildFieldProperty(args) {
|
|
|
117
121
|
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
118
122
|
auxiliaryTypes.push({
|
|
119
123
|
name: itemName,
|
|
120
|
-
code:
|
|
124
|
+
code: dedent`
|
|
121
125
|
/**
|
|
122
126
|
* Item in *${humanReadablePath}*
|
|
123
127
|
*/
|
|
@@ -164,12 +168,12 @@ function buildFieldProperty(args) {
|
|
|
164
168
|
});
|
|
165
169
|
auxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);
|
|
166
170
|
contentTypeNames.push(...primaryFieldProperties.contentTypeNames);
|
|
167
|
-
let primaryCode =
|
|
171
|
+
let primaryCode = dedent`
|
|
168
172
|
/**
|
|
169
173
|
* Primary content in *${humanReadablePath}*
|
|
170
174
|
*/
|
|
171
175
|
`;
|
|
172
|
-
primaryCode = primaryFieldProperties.code ? addLine(
|
|
176
|
+
primaryCode = primaryFieldProperties.code ? addLine(dedent`
|
|
173
177
|
export interface ${primaryInterfaceName} {
|
|
174
178
|
${primaryFieldProperties.code}
|
|
175
179
|
}
|
|
@@ -206,12 +210,12 @@ function buildFieldProperty(args) {
|
|
|
206
210
|
});
|
|
207
211
|
auxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);
|
|
208
212
|
contentTypeNames.push(...itemFieldProperties.contentTypeNames);
|
|
209
|
-
let itemCode =
|
|
213
|
+
let itemCode = dedent`
|
|
210
214
|
/**
|
|
211
215
|
* Item content in *${humanReadablePath}*
|
|
212
216
|
*/
|
|
213
217
|
`;
|
|
214
|
-
itemCode = itemFieldProperties.code ? addLine(
|
|
218
|
+
itemCode = itemFieldProperties.code ? addLine(dedent`
|
|
215
219
|
export interface ${itemInterfaceName} {
|
|
216
220
|
${itemFieldProperties.code}
|
|
217
221
|
}
|
|
@@ -224,7 +228,7 @@ function buildFieldProperty(args) {
|
|
|
224
228
|
}
|
|
225
229
|
auxiliaryTypes.push({
|
|
226
230
|
name: sliceName,
|
|
227
|
-
code:
|
|
231
|
+
code: dedent`
|
|
228
232
|
/**
|
|
229
233
|
* Slice for *${getHumanReadablePath({ path: [...args.path, {
|
|
230
234
|
name: args.name,
|
|
@@ -281,4 +285,4 @@ function buildFieldProperties(args) {
|
|
|
281
285
|
//#endregion
|
|
282
286
|
export { buildFieldProperties };
|
|
283
287
|
|
|
284
|
-
//# sourceMappingURL=buildFieldProperties.
|
|
288
|
+
//# sourceMappingURL=buildFieldProperties.mjs.map
|
|
@@ -0,0 +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.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;CACf,CAAC;CAED,MAAM,iBAAkC,CAAC;CACzC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,OACL,KAAK,KAAK,SAAS,GAAG,KAAK,KAAK,KAAK,SAAS,GAAG,KAAK,SAAS,KAAK,KAAK,IAAI,IAC1E,IAAI,KAAK,KAAK,KACd,KAAK;CAET,QAAQ,KAAK,MAAM,MAAnB;EACC,KAAK,OAEJ;EAGD,KAAK;GACJ,OAAO,QAAQ,GAAG,KAAK,0BAA0B,IAAI;GAErD;EAGD,KAAK;GACJ,OAAO,QAAQ,GAAG,KAAK,wBAAwB,IAAI;GAEnD;EAGD,KAAK;GACJ,OAAO,QAAQ,GAAG,KAAK,uBAAuB,IAAI;GAElD;EAGD,KAAK,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,KAAK,eAAe;GAErC,OAAO,QAAQ,GAAG,KAAK,sBAAsB,gBAAgB,KAAK,IAAI;GAEtE;EACD;EAEA,SACC,OAAO,QAAQ,GAAG,KAAK,aAAa,IAAI;CAE1C;CAEA,OAAO;EACN;EACA;EACA;CACD;AACD;AAeA,SAAgB,qBACf,MACiC;CACjC,IAAI,OAAO;CAEX,MAAM,iBAAkC,CAAC;CACzC,MAAM,mBAA6B,CAAC;CAEpC,KAAK,MAAM,QAAQ,KAAK,QAAQ;EAC/B,MAAM,QAAQ,KAAK,OAAO;EAE1B,MAAM,gBAAgB,mBAAmB;GACxC;GACA;GACA,MAAM,KAAK;GACX,cAAc,KAAK;GACnB,SAAS,KAAK;EACf,CAAC;EAED,OAAO,WAAW,cAAc,MAAM,IAAI;EAE1C,eAAe,KAAK,GAAG,cAAc,cAAc;EACnD,iBAAiB,KAAK,GAAG,cAAc,gBAAgB;CACxD;CAEA,OAAO;EACN;EACA;EACA;CACD;AACD"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { addSection } from "./addSection.
|
|
2
|
-
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants.
|
|
3
|
-
import { buildTypeName } from "./buildTypeName.
|
|
4
|
-
import { getHumanReadableModelName } from "./getHumanReadableModelName.
|
|
5
|
-
import { getHumanReadablePath } from "./getHumanReadablePath.
|
|
6
|
-
import { buildUnion } from "./buildUnion.
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import { addSection } from "./addSection.mjs";
|
|
2
|
+
import { SHARED_SLICES_DOCUMENTATION_URL } from "../constants.mjs";
|
|
3
|
+
import { buildTypeName } from "./buildTypeName.mjs";
|
|
4
|
+
import { getHumanReadableModelName } from "./getHumanReadableModelName.mjs";
|
|
5
|
+
import { getHumanReadablePath } from "./getHumanReadablePath.mjs";
|
|
6
|
+
import { buildUnion } from "./buildUnion.mjs";
|
|
7
|
+
import { dedent } from "./dedent.mjs";
|
|
8
|
+
import { buildFieldProperties } from "./buildFieldProperties.mjs";
|
|
9
|
+
import { getCacheKey } from "./getCacheKey.mjs";
|
|
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 = dedent`
|
|
55
55
|
/**
|
|
56
56
|
* Primary content in *${humanReadablePath}*
|
|
57
57
|
*/
|
|
58
58
|
`;
|
|
59
|
-
code = addSection(primaryFieldProperties.code ?
|
|
59
|
+
code = addSection(primaryFieldProperties.code ? dedent`
|
|
60
60
|
${docs}
|
|
61
61
|
export interface ${primaryInterfaceName} {
|
|
62
62
|
${primaryFieldProperties.code}
|
|
63
63
|
}
|
|
64
|
-
` :
|
|
64
|
+
` : dedent`
|
|
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 = dedent`
|
|
89
89
|
/**
|
|
90
90
|
* Primary content in *${humanReadablePath}*
|
|
91
91
|
*/
|
|
92
92
|
`;
|
|
93
|
-
code = addSection(itemFieldProperties.code ?
|
|
93
|
+
code = addSection(itemFieldProperties.code ? dedent`
|
|
94
94
|
${docs}
|
|
95
95
|
export interface ${itemInterfaceName} {
|
|
96
96
|
${itemFieldProperties.code}
|
|
97
97
|
}
|
|
98
|
-
` :
|
|
98
|
+
` : dedent`
|
|
99
99
|
${docs}
|
|
100
100
|
export interface ${itemInterfaceName} {}
|
|
101
101
|
`, code);
|
|
102
102
|
}
|
|
103
|
-
code = addSection(
|
|
103
|
+
code = addSection(dedent`
|
|
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(dedent`
|
|
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(dedent`
|
|
126
126
|
/**
|
|
127
127
|
* ${humanReadableName} Shared Slice
|
|
128
128
|
*
|
|
@@ -148,4 +148,4 @@ function buildSharedSliceType(args) {
|
|
|
148
148
|
//#endregion
|
|
149
149
|
export { buildSharedSliceType };
|
|
150
150
|
|
|
151
|
-
//# sourceMappingURL=buildSharedSliceType.
|
|
151
|
+
//# sourceMappingURL=buildSharedSliceType.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSharedSliceType.mjs","names":[],"sources":["../../src/lib/buildSharedSliceType.ts"],"sourcesContent":["import type { SharedSliceModel } from \"@prismicio/client\";\nimport type QuickLRU from \"quick-lru\";\n\nimport { SHARED_SLICES_DOCUMENTATION_URL } from \"../constants\";\nimport type { AuxiliaryType, FieldConfigs, FieldPath } from \"../types\";\nimport { addSection } from \"./addSection\";\nimport { buildFieldProperties } from \"./buildFieldProperties\";\nimport { buildTypeName } from \"./buildTypeName\";\nimport { buildUnion } from \"./buildUnion\";\nimport { dedent } from \"./dedent\";\nimport { getCacheKey } from \"./getCacheKey\";\nimport { getHumanReadableModelName } from \"./getHumanReadableModelName\";\nimport { getHumanReadablePath } from \"./getHumanReadablePath\";\n\ntype BuildSharedSliceTypeArgs = {\n\tmodel: SharedSliceModel;\n\tfieldConfigs: FieldConfigs;\n\tcache?: QuickLRU<string, unknown>;\n};\n\ntype BuildSharedSliceTypeReturnValue = {\n\tname: string;\n\tvariationNames: string[];\n\tcode: string;\n\tauxiliaryTypes: AuxiliaryType[];\n\tcontentTypeNames: string[];\n};\n\nexport function buildSharedSliceType(\n\targs: BuildSharedSliceTypeArgs,\n): BuildSharedSliceTypeReturnValue {\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\t\tconst cached = args.cache.get(key);\n\n\t\tif (cached) {\n\t\t\treturn cached as BuildSharedSliceTypeReturnValue;\n\t\t}\n\t}\n\n\tlet code = \"\";\n\n\tconst auxiliaryTypes: AuxiliaryType[] = [];\n\tconst contentTypeNames: string[] = [];\n\n\tconst name = buildTypeName(args.model.id, \"Slice\");\n\tconst humanReadableName = getHumanReadableModelName({\n\t\tname: args.model.id,\n\t\tmodel: args.model,\n\t});\n\n\tconst variationNames: string[] = [];\n\tfor (const variationModel of args.model.variations) {\n\t\tconst variationName = buildTypeName(name, variationModel.id);\n\n\t\tlet primaryInterfaceName: string | undefined;\n\t\tif (variationModel.primary && Object.keys(variationModel.primary).length > 0) {\n\t\t\tprimaryInterfaceName = buildTypeName(variationName, \"Primary\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: variationModel.id,\n\t\t\t\t\tlabel: variationModel.name,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"primary\",\n\t\t\t\t\tlabel: \"Primary\",\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\tconst primaryFieldProperties = buildFieldProperties({\n\t\t\t\tfields: variationModel.primary,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\t\t\tauxiliaryTypes.push(...primaryFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...primaryFieldProperties.contentTypeNames);\n\n\t\t\tcontentTypeNames.push(primaryInterfaceName);\n\n\t\t\tconst docs = dedent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\tprimaryFieldProperties.code\n\t\t\t\t\t? dedent`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {\n\t\t\t\t\t\t\t${primaryFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: dedent`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${primaryInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tlet itemInterfaceName: string | undefined;\n\t\tif (variationModel.items && Object.keys(variationModel.items).length > 0) {\n\t\t\titemInterfaceName = buildTypeName(variationName, \"Item\");\n\n\t\t\tconst path: FieldPath = [\n\t\t\t\t{\n\t\t\t\t\tname: args.model.id,\n\t\t\t\t\tmodel: args.model,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tname: \"items\",\n\t\t\t\t\tlabel: \"Items\",\n\t\t\t\t},\n\t\t\t];\n\t\t\tconst humanReadablePath = getHumanReadablePath({ path });\n\n\t\t\tconst itemFieldProperties = buildFieldProperties({\n\t\t\t\tfields: variationModel.items,\n\t\t\t\tfieldConfigs: args.fieldConfigs,\n\t\t\t\tpath,\n\t\t\t});\n\t\t\tauxiliaryTypes.push(...itemFieldProperties.auxiliaryTypes);\n\t\t\tcontentTypeNames.push(...itemFieldProperties.contentTypeNames);\n\n\t\t\tcontentTypeNames.push(itemInterfaceName);\n\n\t\t\tconst docs = dedent`\n\t\t\t\t/**\n\t\t\t\t * Primary content in *${humanReadablePath}*\n\t\t\t\t */\n\t\t\t`;\n\n\t\t\tcode = addSection(\n\t\t\t\titemFieldProperties.code\n\t\t\t\t\t? dedent`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {\n\t\t\t\t\t\t\t${itemFieldProperties.code}\n\t\t\t\t\t\t}\n\t\t\t\t\t`\n\t\t\t\t\t: dedent`\n\t\t\t\t\t\t${docs}\n\t\t\t\t\t\texport interface ${itemInterfaceName} {}\n\t\t\t\t\t`,\n\t\t\t\tcode,\n\t\t\t);\n\t\t}\n\n\t\tcode = addSection(\n\t\t\tdedent`\n\t\t\t\t/**\n\t\t\t\t * ${variationModel.name} variation for ${humanReadableName} Slice\n\t\t\t\t *\n\t\t\t\t * - **API ID**: \\`${variationModel.id}\\`\n\t\t\t\t * - **Description**: ${variationModel.description || \"*None*\"}\n\t\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t\t */\n\t\t\t\texport type ${variationName} = prismic.SharedSliceVariation<\"${variationModel.id}\", ${\n\t\t\t\t\tprimaryInterfaceName ? `Simplify<${primaryInterfaceName}>` : `Record<string, never>`\n\t\t\t\t}, ${itemInterfaceName ? `Simplify<${itemInterfaceName}>` : `never`}>;\n\t\t\t`,\n\t\t\tcode,\n\t\t);\n\n\t\tvariationNames.push(variationName);\n\t}\n\n\tconst variationUnionName = buildTypeName(name, \"Variation\");\n\tconst variationsUnion = buildUnion(variationNames);\n\n\tcontentTypeNames.push(variationUnionName);\n\tcontentTypeNames.push(...variationNames);\n\n\tcode = addSection(\n\t\tdedent`\n\t\t\t/**\n\t\t\t * Slice variation for *${humanReadableName}*\n\t\t\t */\n\t\t\ttype ${variationUnionName} = ${variationNames.length > 0 ? variationsUnion : \"never\"}\n\t\t`,\n\t\tcode,\n\t);\n\n\tcode = addSection(\n\t\tdedent`\n\t\t\t/**\n\t\t\t * ${humanReadableName} Shared Slice\n\t\t\t *\n\t\t\t * - **API ID**: \\`${args.model.id}\\`\n\t\t\t * - **Description**: ${args.model.description || \"*None*\"}\n\t\t\t * - **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}\n\t\t\t */\n\t\t\texport type ${name} = prismic.SharedSlice<\"${args.model.id}\", ${variationUnionName}>;\n\t\t`,\n\t\tcode,\n\t);\n\n\tconst result = {\n\t\tname,\n\t\tvariationNames,\n\t\tcode,\n\t\tauxiliaryTypes,\n\t\tcontentTypeNames,\n\t};\n\n\tif (args.cache) {\n\t\tconst key = getCacheKey([args.model, args.fieldConfigs]);\n\n\t\targs.cache.set(key, result);\n\t}\n\n\treturn result;\n}\n"],"mappings":";;;;;;;;;;AA4BA,SAAgB,qBACf,MACkC;CAClC,IAAI,KAAK,OAAO;EACf,MAAM,MAAM,YAAY,CAAC,KAAK,OAAO,KAAK,YAAY,CAAC;EACvD,MAAM,SAAS,KAAK,MAAM,IAAI,GAAG;EAEjC,IAAI,QACH,OAAO;CAET;CAEA,IAAI,OAAO;CAEX,MAAM,iBAAkC,CAAC;CACzC,MAAM,mBAA6B,CAAC;CAEpC,MAAM,OAAO,cAAc,KAAK,MAAM,IAAI,OAAO;CACjD,MAAM,oBAAoB,0BAA0B;EACnD,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK;CACb,CAAC;CAED,MAAM,iBAA2B,CAAC;CAClC,KAAK,MAAM,kBAAkB,KAAK,MAAM,YAAY;EACnD,MAAM,gBAAgB,cAAc,MAAM,eAAe,EAAE;EAE3D,IAAI;EACJ,IAAI,eAAe,WAAW,OAAO,KAAK,eAAe,OAAO,CAAC,CAAC,SAAS,GAAG;GAC7E,uBAAuB,cAAc,eAAe,SAAS;GAE7D,MAAM,OAAkB;IACvB;KACC,MAAM,KAAK,MAAM;KACjB,OAAO,KAAK;IACb;IACA;KACC,MAAM,eAAe;KACrB,OAAO,eAAe;IACvB;IACA;K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