prismic-ts-codegen 0.1.2 → 0.1.4

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/cli.mjs CHANGED
@@ -209,10 +209,18 @@ const pascalCase = (input) => pascalCase$1(input, {
209
209
  transform: pascalCaseTransformMerge
210
210
  });
211
211
 
212
- const buildSharedSliceInterfaceName = (config) => {
212
+ const buildSharedSliceInterfaceNamePart = (config) => {
213
213
  return pascalCase(`${config.id} Slice`);
214
214
  };
215
215
 
216
+ const buildTypeName = (...parts) => {
217
+ let name = pascalCase(parts.filter(Boolean).join(" "));
218
+ if (/^[0-9]/.test(name) ? "_" : "") {
219
+ name = `_${name}`;
220
+ }
221
+ return name;
222
+ };
223
+
216
224
  const addInterfacePropertyForField = (config) => {
217
225
  switch (config.model.type) {
218
226
  case "UID": {
@@ -262,12 +270,16 @@ const addInterfacePropertyForField = (config) => {
262
270
  if (config.fieldConfigs.embed?.providerTypes) {
263
271
  for (const providerType in config.fieldConfigs.embed?.providerTypes) {
264
272
  const configuredProviderType = config.fieldConfigs.embed?.providerTypes[providerType];
265
- providerTypes.push(`({ provider_name: "${providerType}" } & ${configuredProviderType})`);
273
+ providerTypes.push(
274
+ `({ provider_name: "${providerType}" } & ${configuredProviderType})`
275
+ );
266
276
  }
267
277
  }
268
278
  config.interface.addProperty({
269
279
  name: config.id,
270
- type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(" | ")})>` : "prismicT.EmbedField",
280
+ type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
281
+ " | "
282
+ )})>` : "prismicT.EmbedField",
271
283
  docs: buildFieldDocs({
272
284
  id: config.id,
273
285
  model: config.model,
@@ -471,7 +483,13 @@ const addInterfacePropertyForField = (config) => {
471
483
  }
472
484
  case "Group": {
473
485
  const itemInterface = config.sourceFile.addInterface({
474
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} Item`),
486
+ name: buildTypeName(
487
+ config.path[0].id,
488
+ "Document",
489
+ "Data",
490
+ config.id,
491
+ "Item"
492
+ ),
475
493
  docs: [
476
494
  {
477
495
  description: (writer) => {
@@ -523,12 +541,22 @@ const addInterfacePropertyForField = (config) => {
523
541
  for (const choiceId in config.model.config.choices) {
524
542
  const choice = config.model.config.choices[choiceId];
525
543
  if (choice.type === CustomTypeModelSliceType.SharedSlice) {
526
- choiceInterfaceNames.push(buildSharedSliceInterfaceName({ id: choiceId }));
544
+ choiceInterfaceNames.push(
545
+ buildSharedSliceInterfaceNamePart({ id: choiceId })
546
+ );
527
547
  } else if (choice.type === CustomTypeModelSliceType.Slice) {
528
548
  let primaryInterface;
529
549
  if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
530
550
  primaryInterface = config.sourceFile.addInterface({
531
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Primary`),
551
+ name: buildTypeName(
552
+ config.path[0].id,
553
+ "Document",
554
+ "Data",
555
+ config.id,
556
+ choiceId,
557
+ "Slice",
558
+ "Primary"
559
+ ),
532
560
  docs: [
533
561
  {
534
562
  description: (writer) => {
@@ -549,7 +577,9 @@ const addInterfacePropertyForField = (config) => {
549
577
  }
550
578
  ]
551
579
  });
552
- writer.writeLine(`Primary content in ${humanReadablePath}`);
580
+ writer.writeLine(
581
+ `Primary content in ${humanReadablePath}`
582
+ );
553
583
  }
554
584
  }
555
585
  ]
@@ -579,7 +609,15 @@ const addInterfacePropertyForField = (config) => {
579
609
  let itemInterface;
580
610
  if (choice.repeat && Object.keys(choice.repeat).length > 0) {
581
611
  itemInterface = config.sourceFile.addInterface({
582
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Item`),
612
+ name: buildTypeName(
613
+ config.path[0].id,
614
+ "Document",
615
+ "Data",
616
+ config.id,
617
+ choiceId,
618
+ "Slice",
619
+ "Item"
620
+ ),
583
621
  docs: [
584
622
  {
585
623
  description: (writer) => {
@@ -629,7 +667,14 @@ const addInterfacePropertyForField = (config) => {
629
667
  });
630
668
  }
631
669
  const sliceType = config.sourceFile.addTypeAlias({
632
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice`),
670
+ name: buildTypeName(
671
+ config.path[0].id,
672
+ "Document",
673
+ "Data",
674
+ config.id,
675
+ choiceId,
676
+ "Slice"
677
+ ),
633
678
  type: `prismicT.Slice<"${choiceId}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
634
679
  isExported: true
635
680
  });
@@ -638,7 +683,13 @@ const addInterfacePropertyForField = (config) => {
638
683
  }
639
684
  }
640
685
  const slicesType = config.sourceFile.addTypeAlias({
641
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} Slice`),
686
+ name: buildTypeName(
687
+ config.path[0].id,
688
+ "Document",
689
+ "Data",
690
+ config.id,
691
+ "Slice"
692
+ ),
642
693
  type: choiceInterfaceNames.length > 0 ? choiceInterfaceNames.join(" | ") : "never",
643
694
  docs: [
644
695
  {
@@ -709,7 +760,7 @@ const addTypeAliasForCustomType = ({
709
760
  let dataInterface;
710
761
  if (hasDataFields) {
711
762
  dataInterface = sourceFile.addInterface({
712
- name: pascalCase(`${model.id} Document Data`),
763
+ name: buildTypeName(model.id, "Document", "Data"),
713
764
  docs: [
714
765
  {
715
766
  description: `Content for ${model.label} documents`
@@ -734,7 +785,7 @@ const addTypeAliasForCustomType = ({
734
785
  }
735
786
  } else {
736
787
  dataInterface = sourceFile.addTypeAlias({
737
- name: pascalCase(`${model.id} Document Data`),
788
+ name: buildTypeName(model.id, "Document", "Data"),
738
789
  type: `Record<string, never>`,
739
790
  docs: [
740
791
  {
@@ -744,7 +795,7 @@ const addTypeAliasForCustomType = ({
744
795
  });
745
796
  }
746
797
  return sourceFile.addTypeAlias({
747
- name: pascalCase(`${model.id} Document`),
798
+ name: buildTypeName(model.id, "Document"),
748
799
  typeParameters: [
749
800
  {
750
801
  name: "Lang",
@@ -760,7 +811,9 @@ const addTypeAliasForCustomType = ({
760
811
  writer.blankLine();
761
812
  writer.writeLine(`- **API ID**: \`${model.id}\``);
762
813
  writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
763
- writer.writeLine(`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`);
814
+ writer.writeLine(
815
+ `- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`
816
+ );
764
817
  },
765
818
  tags: [
766
819
  {
@@ -780,7 +833,11 @@ const addTypeAliasForSharedSlice = (config) => {
780
833
  let primaryInterface;
781
834
  if (variation.primary && Object.keys(variation.primary).length > 0) {
782
835
  primaryInterface = config.sourceFile.addInterface({
783
- name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Primary`),
836
+ name: buildTypeName(
837
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
838
+ variation.id,
839
+ "Primary"
840
+ ),
784
841
  docs: [
785
842
  {
786
843
  description: (writer) => {
@@ -821,7 +878,11 @@ const addTypeAliasForSharedSlice = (config) => {
821
878
  let itemInterface;
822
879
  if (variation.items && Object.keys(variation.items).length > 0) {
823
880
  itemInterface = config.sourceFile.addInterface({
824
- name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Item`),
881
+ name: buildTypeName(
882
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
883
+ variation.id,
884
+ "Item"
885
+ ),
825
886
  docs: [
826
887
  {
827
888
  description: (writer) => {
@@ -861,18 +922,23 @@ const addTypeAliasForSharedSlice = (config) => {
861
922
  });
862
923
  }
863
924
  const variationType = config.sourceFile.addTypeAlias({
864
- name: pascalCase(`${buildSharedSliceInterfaceName({
865
- id: config.model.id
866
- })} ${variation.id}`),
925
+ name: buildTypeName(
926
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
927
+ variation.id
928
+ ),
867
929
  type: `prismicT.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
868
930
  docs: [
869
931
  {
870
932
  description: (writer) => {
871
- writer.writeLine(`${variation.name} variation for ${config.model.name} Slice`);
933
+ writer.writeLine(
934
+ `${variation.name} variation for ${config.model.name} Slice`
935
+ );
872
936
  writer.blankLine();
873
937
  writer.writeLine(`- **API ID**: \`${variation.id}\``);
874
938
  writer.writeLine(`- **Description**: \`${variation.description}\``);
875
- writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
939
+ writer.writeLine(
940
+ `- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
941
+ );
876
942
  }
877
943
  }
878
944
  ],
@@ -881,7 +947,7 @@ const addTypeAliasForSharedSlice = (config) => {
881
947
  variationTypeNames.push(variationType.getName());
882
948
  }
883
949
  const variationsType = config.sourceFile.addTypeAlias({
884
- name: pascalCase(`${config.model.id} Slice Variation`),
950
+ name: buildTypeName(config.model.id, "Slice", "Variation"),
885
951
  type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
886
952
  docs: [
887
953
  {
@@ -900,9 +966,9 @@ const addTypeAliasForSharedSlice = (config) => {
900
966
  ]
901
967
  });
902
968
  return config.sourceFile.addTypeAlias({
903
- name: pascalCase(buildSharedSliceInterfaceName({
904
- id: config.model.id
905
- })),
969
+ name: buildTypeName(
970
+ buildSharedSliceInterfaceNamePart({ id: config.model.id })
971
+ ),
906
972
  type: `prismicT.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
907
973
  docs: [
908
974
  {
@@ -910,8 +976,12 @@ const addTypeAliasForSharedSlice = (config) => {
910
976
  writer.writeLine(`${config.model.name} Shared Slice`);
911
977
  writer.blankLine();
912
978
  writer.writeLine(`- **API ID**: \`${config.model.id}\``);
913
- writer.writeLine(`- **Description**: \`${config.model.description}\``);
914
- writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
979
+ writer.writeLine(
980
+ `- **Description**: \`${config.model.description}\``
981
+ );
982
+ writer.writeLine(
983
+ `- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
984
+ );
915
985
  }
916
986
  }
917
987
  ],
@@ -957,7 +1027,9 @@ const generateTypes = (config = {}) => {
957
1027
  if (config.customTypeModels.length > 0) {
958
1028
  sourceFile.addTypeAlias({
959
1029
  name: "AllDocumentTypes",
960
- type: config.customTypeModels.map((customTypeModel) => pascalCase(`${customTypeModel.id} Document`)).join(" | "),
1030
+ type: config.customTypeModels.map(
1031
+ (customTypeModel) => buildTypeName(customTypeModel.id, "Document")
1032
+ ).join(" | "),
961
1033
  isExported: true
962
1034
  });
963
1035
  }
@@ -1019,17 +1091,26 @@ const configSchema = Joi.object({
1019
1091
  clientIntegration: Joi.object({
1020
1092
  includeCreateClientInterface: Joi.boolean()
1021
1093
  }),
1022
- locales: Joi.alternatives(Joi.array().items(Joi.string().required()), Joi.object({
1023
- ids: Joi.array().items(Joi.string().required()),
1024
- fetchFromRepository: Joi.boolean()
1025
- })),
1026
- models: Joi.alternatives(Joi.array().items(Joi.string()), Joi.object({
1027
- files: Joi.array().items(Joi.string()),
1028
- fetchFromRepository: Joi.boolean()
1029
- })),
1094
+ locales: Joi.alternatives(
1095
+ Joi.array().items(Joi.string().required()),
1096
+ Joi.object({
1097
+ ids: Joi.array().items(Joi.string().required()),
1098
+ fetchFromRepository: Joi.boolean()
1099
+ })
1100
+ ),
1101
+ models: Joi.alternatives(
1102
+ Joi.array().items(Joi.string()),
1103
+ Joi.object({
1104
+ files: Joi.array().items(Joi.string()),
1105
+ fetchFromRepository: Joi.boolean()
1106
+ })
1107
+ ),
1030
1108
  fields: Joi.object({
1031
1109
  embed: Joi.object({
1032
- providerTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
1110
+ providerTypes: Joi.object().pattern(
1111
+ Joi.string(),
1112
+ Joi.string().required()
1113
+ )
1033
1114
  }),
1034
1115
  integrationFields: Joi.object({
1035
1116
  catalogTypes: Joi.object().pattern(Joi.string(), Joi.string().required())
@@ -1108,6 +1189,10 @@ const loadModels = async (config) => {
1108
1189
  };
1109
1190
 
1110
1191
  const jiti = _jiti(process.cwd());
1192
+ const loadModuleWithJiti = (id) => {
1193
+ const mod = jiti(id);
1194
+ return "default" in mod ? mod.default : mod;
1195
+ };
1111
1196
  const DEFAULT_CONFIG_PATHS = [
1112
1197
  "prismicCodegen.config.ts",
1113
1198
  "prismicCodegen.config.js"
@@ -1115,22 +1200,22 @@ const DEFAULT_CONFIG_PATHS = [
1115
1200
  const loadConfig = (config) => {
1116
1201
  if (config.path) {
1117
1202
  if (existsSync(config.path)) {
1118
- return jiti(config.path);
1203
+ return loadModuleWithJiti(resolve(config.path));
1119
1204
  } else {
1120
1205
  throw new Error(`Config file does not exist: ${config.path}`);
1121
1206
  }
1122
1207
  } else {
1123
1208
  for (const configPath of DEFAULT_CONFIG_PATHS) {
1124
1209
  if (existsSync(configPath)) {
1125
- const mod = jiti(resolve(configPath));
1126
- return "default" in mod ? mod.default : mod;
1210
+ return loadModuleWithJiti(resolve(configPath));
1127
1211
  }
1128
1212
  }
1129
1213
  }
1130
1214
  return {};
1131
1215
  };
1132
1216
 
1133
- const cli = meow(`
1217
+ const cli = meow(
1218
+ `
1134
1219
  Usage:
1135
1220
  prismic-ts-codegen [options...]
1136
1221
  prismic-ts-codegen init [options...]
@@ -1140,16 +1225,18 @@ const cli = meow(`
1140
1225
 
1141
1226
  Options:
1142
1227
  -c, --config <path> Path to a prismic-ts-codegen configuration file.
1143
- `, {
1144
- importMeta: import.meta,
1145
- flags: {
1146
- config: {
1147
- type: "string",
1148
- alias: "c",
1149
- isRequired: false
1228
+ `,
1229
+ {
1230
+ importMeta: import.meta,
1231
+ flags: {
1232
+ config: {
1233
+ type: "string",
1234
+ alias: "c",
1235
+ isRequired: false
1236
+ }
1150
1237
  }
1151
1238
  }
1152
- });
1239
+ );
1153
1240
  const main = async () => {
1154
1241
  if (cli.input[0] === "init") {
1155
1242
  const configPath = cli.flags.config || "prismicCodegen.config.ts";
@@ -1211,7 +1298,9 @@ Created prismic-ts-codegen config file: ${configPath}`);
1211
1298
  }
1212
1299
  });
1213
1300
  if (config.clientIntegration?.includeCreateClientInterface && !hasCustomTypeModels) {
1214
- console.info("[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model.");
1301
+ console.info(
1302
+ "[INFO]: prismic-ts-codegen was configured to automatically integrate with `@prismicio/client`, but the integration was generated because no Custom Type models were found. Automatic integration requires at least one Custom Type model."
1303
+ );
1215
1304
  }
1216
1305
  if (config.output) {
1217
1306
  writeFileSync(resolve(config.output), types);
package/dist/index.cjs CHANGED
@@ -202,10 +202,18 @@ const pascalCase = (input) => pascalCase$1.pascalCase(input, {
202
202
  transform: pascalCase$1.pascalCaseTransformMerge
203
203
  });
204
204
 
205
- const buildSharedSliceInterfaceName = (config) => {
205
+ const buildSharedSliceInterfaceNamePart = (config) => {
206
206
  return pascalCase(`${config.id} Slice`);
207
207
  };
208
208
 
209
+ const buildTypeName = (...parts) => {
210
+ let name = pascalCase(parts.filter(Boolean).join(" "));
211
+ if (/^[0-9]/.test(name) ? "_" : "") {
212
+ name = `_${name}`;
213
+ }
214
+ return name;
215
+ };
216
+
209
217
  const addInterfacePropertyForField = (config) => {
210
218
  switch (config.model.type) {
211
219
  case "UID": {
@@ -255,12 +263,16 @@ const addInterfacePropertyForField = (config) => {
255
263
  if (config.fieldConfigs.embed?.providerTypes) {
256
264
  for (const providerType in config.fieldConfigs.embed?.providerTypes) {
257
265
  const configuredProviderType = config.fieldConfigs.embed?.providerTypes[providerType];
258
- providerTypes.push(`({ provider_name: "${providerType}" } & ${configuredProviderType})`);
266
+ providerTypes.push(
267
+ `({ provider_name: "${providerType}" } & ${configuredProviderType})`
268
+ );
259
269
  }
260
270
  }
261
271
  config.interface.addProperty({
262
272
  name: config.id,
263
- type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(" | ")})>` : "prismicT.EmbedField",
273
+ type: providerTypes.length > 0 ? `prismicT.EmbedField<prismicT.AnyOEmbed & prismicT.OEmbedExtra & (${providerTypes.join(
274
+ " | "
275
+ )})>` : "prismicT.EmbedField",
264
276
  docs: buildFieldDocs({
265
277
  id: config.id,
266
278
  model: config.model,
@@ -464,7 +476,13 @@ const addInterfacePropertyForField = (config) => {
464
476
  }
465
477
  case "Group": {
466
478
  const itemInterface = config.sourceFile.addInterface({
467
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} Item`),
479
+ name: buildTypeName(
480
+ config.path[0].id,
481
+ "Document",
482
+ "Data",
483
+ config.id,
484
+ "Item"
485
+ ),
468
486
  docs: [
469
487
  {
470
488
  description: (writer) => {
@@ -516,12 +534,22 @@ const addInterfacePropertyForField = (config) => {
516
534
  for (const choiceId in config.model.config.choices) {
517
535
  const choice = config.model.config.choices[choiceId];
518
536
  if (choice.type === types.CustomTypeModelSliceType.SharedSlice) {
519
- choiceInterfaceNames.push(buildSharedSliceInterfaceName({ id: choiceId }));
537
+ choiceInterfaceNames.push(
538
+ buildSharedSliceInterfaceNamePart({ id: choiceId })
539
+ );
520
540
  } else if (choice.type === types.CustomTypeModelSliceType.Slice) {
521
541
  let primaryInterface;
522
542
  if (choice["non-repeat"] && Object.keys(choice["non-repeat"]).length > 0) {
523
543
  primaryInterface = config.sourceFile.addInterface({
524
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Primary`),
544
+ name: buildTypeName(
545
+ config.path[0].id,
546
+ "Document",
547
+ "Data",
548
+ config.id,
549
+ choiceId,
550
+ "Slice",
551
+ "Primary"
552
+ ),
525
553
  docs: [
526
554
  {
527
555
  description: (writer) => {
@@ -542,7 +570,9 @@ const addInterfacePropertyForField = (config) => {
542
570
  }
543
571
  ]
544
572
  });
545
- writer.writeLine(`Primary content in ${humanReadablePath}`);
573
+ writer.writeLine(
574
+ `Primary content in ${humanReadablePath}`
575
+ );
546
576
  }
547
577
  }
548
578
  ]
@@ -572,7 +602,15 @@ const addInterfacePropertyForField = (config) => {
572
602
  let itemInterface;
573
603
  if (choice.repeat && Object.keys(choice.repeat).length > 0) {
574
604
  itemInterface = config.sourceFile.addInterface({
575
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice Item`),
605
+ name: buildTypeName(
606
+ config.path[0].id,
607
+ "Document",
608
+ "Data",
609
+ config.id,
610
+ choiceId,
611
+ "Slice",
612
+ "Item"
613
+ ),
576
614
  docs: [
577
615
  {
578
616
  description: (writer) => {
@@ -622,7 +660,14 @@ const addInterfacePropertyForField = (config) => {
622
660
  });
623
661
  }
624
662
  const sliceType = config.sourceFile.addTypeAlias({
625
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} ${choiceId} Slice`),
663
+ name: buildTypeName(
664
+ config.path[0].id,
665
+ "Document",
666
+ "Data",
667
+ config.id,
668
+ choiceId,
669
+ "Slice"
670
+ ),
626
671
  type: `prismicT.Slice<"${choiceId}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
627
672
  isExported: true
628
673
  });
@@ -631,7 +676,13 @@ const addInterfacePropertyForField = (config) => {
631
676
  }
632
677
  }
633
678
  const slicesType = config.sourceFile.addTypeAlias({
634
- name: pascalCase(`${config.path[0].id} Document Data ${config.id} Slice`),
679
+ name: buildTypeName(
680
+ config.path[0].id,
681
+ "Document",
682
+ "Data",
683
+ config.id,
684
+ "Slice"
685
+ ),
635
686
  type: choiceInterfaceNames.length > 0 ? choiceInterfaceNames.join(" | ") : "never",
636
687
  docs: [
637
688
  {
@@ -702,7 +753,7 @@ const addTypeAliasForCustomType = ({
702
753
  let dataInterface;
703
754
  if (hasDataFields) {
704
755
  dataInterface = sourceFile.addInterface({
705
- name: pascalCase(`${model.id} Document Data`),
756
+ name: buildTypeName(model.id, "Document", "Data"),
706
757
  docs: [
707
758
  {
708
759
  description: `Content for ${model.label} documents`
@@ -727,7 +778,7 @@ const addTypeAliasForCustomType = ({
727
778
  }
728
779
  } else {
729
780
  dataInterface = sourceFile.addTypeAlias({
730
- name: pascalCase(`${model.id} Document Data`),
781
+ name: buildTypeName(model.id, "Document", "Data"),
731
782
  type: `Record<string, never>`,
732
783
  docs: [
733
784
  {
@@ -737,7 +788,7 @@ const addTypeAliasForCustomType = ({
737
788
  });
738
789
  }
739
790
  return sourceFile.addTypeAlias({
740
- name: pascalCase(`${model.id} Document`),
791
+ name: buildTypeName(model.id, "Document"),
741
792
  typeParameters: [
742
793
  {
743
794
  name: "Lang",
@@ -753,7 +804,9 @@ const addTypeAliasForCustomType = ({
753
804
  writer.blankLine();
754
805
  writer.writeLine(`- **API ID**: \`${model.id}\``);
755
806
  writer.writeLine(`- **Repeatable**: \`${model.repeatable}\``);
756
- writer.writeLine(`- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`);
807
+ writer.writeLine(
808
+ `- **Documentation**: ${CUSTOM_TYPES_DOCUMENTATION_URL}`
809
+ );
757
810
  },
758
811
  tags: [
759
812
  {
@@ -773,7 +826,11 @@ const addTypeAliasForSharedSlice = (config) => {
773
826
  let primaryInterface;
774
827
  if (variation.primary && Object.keys(variation.primary).length > 0) {
775
828
  primaryInterface = config.sourceFile.addInterface({
776
- name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Primary`),
829
+ name: buildTypeName(
830
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
831
+ variation.id,
832
+ "Primary"
833
+ ),
777
834
  docs: [
778
835
  {
779
836
  description: (writer) => {
@@ -814,7 +871,11 @@ const addTypeAliasForSharedSlice = (config) => {
814
871
  let itemInterface;
815
872
  if (variation.items && Object.keys(variation.items).length > 0) {
816
873
  itemInterface = config.sourceFile.addInterface({
817
- name: pascalCase(`${buildSharedSliceInterfaceName({ id: config.model.id })} ${variation.id} Item`),
874
+ name: buildTypeName(
875
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
876
+ variation.id,
877
+ "Item"
878
+ ),
818
879
  docs: [
819
880
  {
820
881
  description: (writer) => {
@@ -854,18 +915,23 @@ const addTypeAliasForSharedSlice = (config) => {
854
915
  });
855
916
  }
856
917
  const variationType = config.sourceFile.addTypeAlias({
857
- name: pascalCase(`${buildSharedSliceInterfaceName({
858
- id: config.model.id
859
- })} ${variation.id}`),
918
+ name: buildTypeName(
919
+ buildSharedSliceInterfaceNamePart({ id: config.model.id }),
920
+ variation.id
921
+ ),
860
922
  type: `prismicT.SharedSliceVariation<"${variation.id}", ${primaryInterface ? `Simplify<${primaryInterface.getName()}>` : "Record<string, never>"}, ${itemInterface ? `Simplify<${itemInterface.getName()}>` : "never"}>`,
861
923
  docs: [
862
924
  {
863
925
  description: (writer) => {
864
- writer.writeLine(`${variation.name} variation for ${config.model.name} Slice`);
926
+ writer.writeLine(
927
+ `${variation.name} variation for ${config.model.name} Slice`
928
+ );
865
929
  writer.blankLine();
866
930
  writer.writeLine(`- **API ID**: \`${variation.id}\``);
867
931
  writer.writeLine(`- **Description**: \`${variation.description}\``);
868
- writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
932
+ writer.writeLine(
933
+ `- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
934
+ );
869
935
  }
870
936
  }
871
937
  ],
@@ -874,7 +940,7 @@ const addTypeAliasForSharedSlice = (config) => {
874
940
  variationTypeNames.push(variationType.getName());
875
941
  }
876
942
  const variationsType = config.sourceFile.addTypeAlias({
877
- name: pascalCase(`${config.model.id} Slice Variation`),
943
+ name: buildTypeName(config.model.id, "Slice", "Variation"),
878
944
  type: variationTypeNames.length > 0 ? variationTypeNames.join(" | ") : "never",
879
945
  docs: [
880
946
  {
@@ -893,9 +959,9 @@ const addTypeAliasForSharedSlice = (config) => {
893
959
  ]
894
960
  });
895
961
  return config.sourceFile.addTypeAlias({
896
- name: pascalCase(buildSharedSliceInterfaceName({
897
- id: config.model.id
898
- })),
962
+ name: buildTypeName(
963
+ buildSharedSliceInterfaceNamePart({ id: config.model.id })
964
+ ),
899
965
  type: `prismicT.SharedSlice<"${config.model.id}", ${variationsType.getName()}>`,
900
966
  docs: [
901
967
  {
@@ -903,8 +969,12 @@ const addTypeAliasForSharedSlice = (config) => {
903
969
  writer.writeLine(`${config.model.name} Shared Slice`);
904
970
  writer.blankLine();
905
971
  writer.writeLine(`- **API ID**: \`${config.model.id}\``);
906
- writer.writeLine(`- **Description**: \`${config.model.description}\``);
907
- writer.writeLine(`- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`);
972
+ writer.writeLine(
973
+ `- **Description**: \`${config.model.description}\``
974
+ );
975
+ writer.writeLine(
976
+ `- **Documentation**: ${SHARED_SLICES_DOCUMENTATION_URL}`
977
+ );
908
978
  }
909
979
  }
910
980
  ],
@@ -950,7 +1020,9 @@ const generateTypes = (config = {}) => {
950
1020
  if (config.customTypeModels.length > 0) {
951
1021
  sourceFile.addTypeAlias({
952
1022
  name: "AllDocumentTypes",
953
- type: config.customTypeModels.map((customTypeModel) => pascalCase(`${customTypeModel.id} Document`)).join(" | "),
1023
+ type: config.customTypeModels.map(
1024
+ (customTypeModel) => buildTypeName(customTypeModel.id, "Document")
1025
+ ).join(" | "),
954
1026
  isExported: true
955
1027
  });
956
1028
  }