prismic-ts-codegen 0.0.3 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -147,6 +147,9 @@ const writeFieldDocsDescription = (config) => {
147
147
  if (config.apiIDPath) {
148
148
  config.writer.writeLine(`- **API ID Path**: ${config.apiIDPath}`);
149
149
  }
150
+ if (config.tabName) {
151
+ config.writer.writeLine(`- **Tab**: ${config.tabName}`);
152
+ }
150
153
  if (config.documentationURL) {
151
154
  config.writer.writeLine(`- **Documentation**: ${config.documentationURL}`);
152
155
  }
@@ -178,6 +181,7 @@ const buildFieldDocs = (config) => {
178
181
  placeholder,
179
182
  defaultValue,
180
183
  apiIDPath,
184
+ tabName: config.tabName,
181
185
  documentationURL: getFieldDocumentationURL({ model: config.model })
182
186
  });
183
187
  }
@@ -193,7 +197,7 @@ const buildSharedSliceInterfaceName = (config) => {
193
197
  return pascalCase(`${config.id} Slice`);
194
198
  };
195
199
 
196
- const addInterfacePropertyFromField = (config) => {
200
+ const addInterfacePropertyForField = (config) => {
197
201
  switch (config.model.type) {
198
202
  case "UID": {
199
203
  break;
@@ -205,7 +209,8 @@ const addInterfacePropertyFromField = (config) => {
205
209
  docs: buildFieldDocs({
206
210
  id: config.id,
207
211
  model: config.model,
208
- path: config.path
212
+ path: config.path,
213
+ tabName: config.tabName
209
214
  })
210
215
  });
211
216
  break;
@@ -217,7 +222,8 @@ const addInterfacePropertyFromField = (config) => {
217
222
  docs: buildFieldDocs({
218
223
  id: config.id,
219
224
  model: config.model,
220
- path: config.path
225
+ path: config.path,
226
+ tabName: config.tabName
221
227
  })
222
228
  });
223
229
  break;
@@ -229,7 +235,8 @@ const addInterfacePropertyFromField = (config) => {
229
235
  docs: buildFieldDocs({
230
236
  id: config.id,
231
237
  model: config.model,
232
- path: config.path
238
+ path: config.path,
239
+ tabName: config.tabName
233
240
  })
234
241
  });
235
242
  break;
@@ -248,7 +255,8 @@ const addInterfacePropertyFromField = (config) => {
248
255
  docs: buildFieldDocs({
249
256
  id: config.id,
250
257
  model: config.model,
251
- path: config.path
258
+ path: config.path,
259
+ tabName: config.tabName
252
260
  })
253
261
  });
254
262
  break;
@@ -260,7 +268,8 @@ const addInterfacePropertyFromField = (config) => {
260
268
  docs: buildFieldDocs({
261
269
  id: config.id,
262
270
  model: config.model,
263
- path: config.path
271
+ path: config.path,
272
+ tabName: config.tabName
264
273
  })
265
274
  });
266
275
  break;
@@ -274,7 +283,8 @@ const addInterfacePropertyFromField = (config) => {
274
283
  docs: buildFieldDocs({
275
284
  id: config.id,
276
285
  model: config.model,
277
- path: config.path
286
+ path: config.path,
287
+ tabName: config.tabName
278
288
  })
279
289
  });
280
290
  } else {
@@ -284,7 +294,8 @@ const addInterfacePropertyFromField = (config) => {
284
294
  docs: buildFieldDocs({
285
295
  id: config.id,
286
296
  model: config.model,
287
- path: config.path
297
+ path: config.path,
298
+ tabName: config.tabName
288
299
  })
289
300
  });
290
301
  }
@@ -298,7 +309,8 @@ const addInterfacePropertyFromField = (config) => {
298
309
  docs: buildFieldDocs({
299
310
  id: config.id,
300
311
  model: config.model,
301
- path: config.path
312
+ path: config.path,
313
+ tabName: config.tabName
302
314
  })
303
315
  });
304
316
  break;
@@ -312,7 +324,8 @@ const addInterfacePropertyFromField = (config) => {
312
324
  docs: buildFieldDocs({
313
325
  id: config.id,
314
326
  model: config.model,
315
- path: config.path
327
+ path: config.path,
328
+ tabName: config.tabName
316
329
  })
317
330
  });
318
331
  break;
@@ -324,7 +337,8 @@ const addInterfacePropertyFromField = (config) => {
324
337
  docs: buildFieldDocs({
325
338
  id: config.id,
326
339
  model: config.model,
327
- path: config.path
340
+ path: config.path,
341
+ tabName: config.tabName
328
342
  })
329
343
  });
330
344
  break;
@@ -336,7 +350,8 @@ const addInterfacePropertyFromField = (config) => {
336
350
  docs: buildFieldDocs({
337
351
  id: config.id,
338
352
  model: config.model,
339
- path: config.path
353
+ path: config.path,
354
+ tabName: config.tabName
340
355
  })
341
356
  });
342
357
  }
@@ -350,7 +365,8 @@ const addInterfacePropertyFromField = (config) => {
350
365
  docs: buildFieldDocs({
351
366
  id: config.id,
352
367
  model: config.model,
353
- path: config.path
368
+ path: config.path,
369
+ tabName: config.tabName
354
370
  })
355
371
  });
356
372
  break;
@@ -364,7 +380,8 @@ const addInterfacePropertyFromField = (config) => {
364
380
  docs: buildFieldDocs({
365
381
  id: config.id,
366
382
  model: config.model,
367
- path: config.path
383
+ path: config.path,
384
+ tabName: config.tabName
368
385
  })
369
386
  });
370
387
  } else {
@@ -374,7 +391,8 @@ const addInterfacePropertyFromField = (config) => {
374
391
  docs: buildFieldDocs({
375
392
  id: config.id,
376
393
  model: config.model,
377
- path: config.path
394
+ path: config.path,
395
+ tabName: config.tabName
378
396
  })
379
397
  });
380
398
  }
@@ -390,7 +408,8 @@ const addInterfacePropertyFromField = (config) => {
390
408
  docs: buildFieldDocs({
391
409
  id: config.id,
392
410
  model: config.model,
393
- path: config.path
411
+ path: config.path,
412
+ tabName: config.tabName
394
413
  })
395
414
  });
396
415
  } else {
@@ -400,7 +419,8 @@ const addInterfacePropertyFromField = (config) => {
400
419
  docs: buildFieldDocs({
401
420
  id: config.id,
402
421
  model: config.model,
403
- path: config.path
422
+ path: config.path,
423
+ tabName: config.tabName
404
424
  })
405
425
  });
406
426
  }
@@ -413,7 +433,8 @@ const addInterfacePropertyFromField = (config) => {
413
433
  docs: buildFieldDocs({
414
434
  id: config.id,
415
435
  model: config.model,
416
- path: config.path
436
+ path: config.path,
437
+ tabName: config.tabName
417
438
  })
418
439
  });
419
440
  break;
@@ -425,7 +446,8 @@ const addInterfacePropertyFromField = (config) => {
425
446
  docs: buildFieldDocs({
426
447
  id: config.id,
427
448
  model: config.model,
428
- path: config.path
449
+ path: config.path,
450
+ tabName: config.tabName
429
451
  })
430
452
  });
431
453
  break;
@@ -470,7 +492,8 @@ const addInterfacePropertyFromField = (config) => {
470
492
  docs: buildFieldDocs({
471
493
  id: config.id,
472
494
  model: config.model,
473
- path: config.path
495
+ path: config.path,
496
+ tabName: config.tabName
474
497
  })
475
498
  });
476
499
  break;
@@ -619,7 +642,8 @@ const addInterfacePropertyFromField = (config) => {
619
642
  docs: buildFieldDocs({
620
643
  id: config.id,
621
644
  model: config.model,
622
- path: config.path
645
+ path: config.path,
646
+ tabName: config.tabName
623
647
  })
624
648
  });
625
649
  break;
@@ -631,7 +655,8 @@ const addInterfacePropertyFromField = (config) => {
631
655
  docs: buildFieldDocs({
632
656
  id: config.id,
633
657
  model: config.model,
634
- path: config.path
658
+ path: config.path,
659
+ tabName: config.tabName
635
660
  })
636
661
  });
637
662
  }
@@ -639,10 +664,11 @@ const addInterfacePropertyFromField = (config) => {
639
664
  };
640
665
  const addInterfacePropertiesForFields = (config) => {
641
666
  for (const name in config.fields) {
642
- addInterfacePropertyFromField({
667
+ addInterfacePropertyForField({
643
668
  ...config,
644
669
  id: name.includes("-") ? `"${name}"` : name,
645
- model: config.fields[name]
670
+ model: config.fields[name],
671
+ tabName: config.tabName
646
672
  });
647
673
  }
648
674
  };
@@ -669,18 +695,22 @@ const addTypeAliasForCustomType = ({
669
695
  }
670
696
  ]
671
697
  });
672
- addInterfacePropertiesForFields({
673
- fields,
674
- interface: dataInterface,
675
- sourceFile,
676
- path: [
677
- {
678
- id: model.id,
679
- model
680
- }
681
- ],
682
- fieldConfigs
683
- });
698
+ for (const tabName in model.json) {
699
+ const { uid: _uidField, ...tabFields } = model.json[tabName];
700
+ addInterfacePropertiesForFields({
701
+ fields: tabFields,
702
+ interface: dataInterface,
703
+ sourceFile,
704
+ path: [
705
+ {
706
+ id: model.id,
707
+ model
708
+ }
709
+ ],
710
+ fieldConfigs,
711
+ tabName
712
+ });
713
+ }
684
714
  } else {
685
715
  dataInterface = sourceFile.addTypeAlias({
686
716
  name: pascalCase(`${model.id} Document Data`),
@@ -903,6 +933,13 @@ const generateTypes = (config = {}) => {
903
933
  fieldConfigs: config.fieldConfigs || {}
904
934
  });
905
935
  }
936
+ if (config.customTypeModels.length > 0) {
937
+ sourceFile.addTypeAlias({
938
+ name: "AllDocumentTypes",
939
+ type: config.customTypeModels.map((customTypeModel) => pascalCase(`${customTypeModel.id} Document`)).join(" | "),
940
+ isExported: true
941
+ });
942
+ }
906
943
  }
907
944
  if (config.sharedSliceModels) {
908
945
  for (const model of config.sharedSliceModels) {
@@ -913,6 +950,37 @@ const generateTypes = (config = {}) => {
913
950
  });
914
951
  }
915
952
  }
953
+ if (config.clientIntegration?.includeCreateClientInterface) {
954
+ sourceFile.addImportDeclaration({
955
+ moduleSpecifier: "@prismicio/client",
956
+ namespaceImport: "prismic",
957
+ isTypeOnly: true
958
+ });
959
+ const clientModuleDeclaration = sourceFile.addModule({
960
+ name: '"@prismicio/client"',
961
+ hasDeclareKeyword: true,
962
+ declarationKind: tsMorph.ModuleDeclarationKind.Module
963
+ });
964
+ clientModuleDeclaration.addInterface({
965
+ name: "CreateClient",
966
+ callSignatures: [
967
+ {
968
+ parameters: [
969
+ {
970
+ name: "repositoryNameOrEndpoint",
971
+ type: "string"
972
+ },
973
+ {
974
+ name: "options",
975
+ type: "prismic.ClientConfig",
976
+ hasQuestionToken: true
977
+ }
978
+ ],
979
+ returnType: (config.customTypeModels?.length || 0) > 0 ? "prismic.Client<AllDocumentTypes>" : "prismic.Client"
980
+ }
981
+ ]
982
+ });
983
+ }
916
984
  return getSourceFileText(sourceFile);
917
985
  };
918
986