prismic-ts-codegen 0.0.3 → 0.0.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
@@ -154,6 +154,9 @@ const writeFieldDocsDescription = (config) => {
154
154
  if (config.apiIDPath) {
155
155
  config.writer.writeLine(`- **API ID Path**: ${config.apiIDPath}`);
156
156
  }
157
+ if (config.tabName) {
158
+ config.writer.writeLine(`- **Tab**: ${config.tabName}`);
159
+ }
157
160
  if (config.documentationURL) {
158
161
  config.writer.writeLine(`- **Documentation**: ${config.documentationURL}`);
159
162
  }
@@ -185,6 +188,7 @@ const buildFieldDocs = (config) => {
185
188
  placeholder,
186
189
  defaultValue,
187
190
  apiIDPath,
191
+ tabName: config.tabName,
188
192
  documentationURL: getFieldDocumentationURL({ model: config.model })
189
193
  });
190
194
  }
@@ -200,7 +204,7 @@ const buildSharedSliceInterfaceName = (config) => {
200
204
  return pascalCase(`${config.id} Slice`);
201
205
  };
202
206
 
203
- const addInterfacePropertyFromField = (config) => {
207
+ const addInterfacePropertyForField = (config) => {
204
208
  switch (config.model.type) {
205
209
  case "UID": {
206
210
  break;
@@ -212,7 +216,8 @@ const addInterfacePropertyFromField = (config) => {
212
216
  docs: buildFieldDocs({
213
217
  id: config.id,
214
218
  model: config.model,
215
- path: config.path
219
+ path: config.path,
220
+ tabName: config.tabName
216
221
  })
217
222
  });
218
223
  break;
@@ -224,7 +229,8 @@ const addInterfacePropertyFromField = (config) => {
224
229
  docs: buildFieldDocs({
225
230
  id: config.id,
226
231
  model: config.model,
227
- path: config.path
232
+ path: config.path,
233
+ tabName: config.tabName
228
234
  })
229
235
  });
230
236
  break;
@@ -236,7 +242,8 @@ const addInterfacePropertyFromField = (config) => {
236
242
  docs: buildFieldDocs({
237
243
  id: config.id,
238
244
  model: config.model,
239
- path: config.path
245
+ path: config.path,
246
+ tabName: config.tabName
240
247
  })
241
248
  });
242
249
  break;
@@ -255,7 +262,8 @@ const addInterfacePropertyFromField = (config) => {
255
262
  docs: buildFieldDocs({
256
263
  id: config.id,
257
264
  model: config.model,
258
- path: config.path
265
+ path: config.path,
266
+ tabName: config.tabName
259
267
  })
260
268
  });
261
269
  break;
@@ -267,7 +275,8 @@ const addInterfacePropertyFromField = (config) => {
267
275
  docs: buildFieldDocs({
268
276
  id: config.id,
269
277
  model: config.model,
270
- path: config.path
278
+ path: config.path,
279
+ tabName: config.tabName
271
280
  })
272
281
  });
273
282
  break;
@@ -281,7 +290,8 @@ const addInterfacePropertyFromField = (config) => {
281
290
  docs: buildFieldDocs({
282
291
  id: config.id,
283
292
  model: config.model,
284
- path: config.path
293
+ path: config.path,
294
+ tabName: config.tabName
285
295
  })
286
296
  });
287
297
  } else {
@@ -291,7 +301,8 @@ const addInterfacePropertyFromField = (config) => {
291
301
  docs: buildFieldDocs({
292
302
  id: config.id,
293
303
  model: config.model,
294
- path: config.path
304
+ path: config.path,
305
+ tabName: config.tabName
295
306
  })
296
307
  });
297
308
  }
@@ -305,7 +316,8 @@ const addInterfacePropertyFromField = (config) => {
305
316
  docs: buildFieldDocs({
306
317
  id: config.id,
307
318
  model: config.model,
308
- path: config.path
319
+ path: config.path,
320
+ tabName: config.tabName
309
321
  })
310
322
  });
311
323
  break;
@@ -319,7 +331,8 @@ const addInterfacePropertyFromField = (config) => {
319
331
  docs: buildFieldDocs({
320
332
  id: config.id,
321
333
  model: config.model,
322
- path: config.path
334
+ path: config.path,
335
+ tabName: config.tabName
323
336
  })
324
337
  });
325
338
  break;
@@ -331,7 +344,8 @@ const addInterfacePropertyFromField = (config) => {
331
344
  docs: buildFieldDocs({
332
345
  id: config.id,
333
346
  model: config.model,
334
- path: config.path
347
+ path: config.path,
348
+ tabName: config.tabName
335
349
  })
336
350
  });
337
351
  break;
@@ -343,7 +357,8 @@ const addInterfacePropertyFromField = (config) => {
343
357
  docs: buildFieldDocs({
344
358
  id: config.id,
345
359
  model: config.model,
346
- path: config.path
360
+ path: config.path,
361
+ tabName: config.tabName
347
362
  })
348
363
  });
349
364
  }
@@ -357,7 +372,8 @@ const addInterfacePropertyFromField = (config) => {
357
372
  docs: buildFieldDocs({
358
373
  id: config.id,
359
374
  model: config.model,
360
- path: config.path
375
+ path: config.path,
376
+ tabName: config.tabName
361
377
  })
362
378
  });
363
379
  break;
@@ -371,7 +387,8 @@ const addInterfacePropertyFromField = (config) => {
371
387
  docs: buildFieldDocs({
372
388
  id: config.id,
373
389
  model: config.model,
374
- path: config.path
390
+ path: config.path,
391
+ tabName: config.tabName
375
392
  })
376
393
  });
377
394
  } else {
@@ -381,7 +398,8 @@ const addInterfacePropertyFromField = (config) => {
381
398
  docs: buildFieldDocs({
382
399
  id: config.id,
383
400
  model: config.model,
384
- path: config.path
401
+ path: config.path,
402
+ tabName: config.tabName
385
403
  })
386
404
  });
387
405
  }
@@ -397,7 +415,8 @@ const addInterfacePropertyFromField = (config) => {
397
415
  docs: buildFieldDocs({
398
416
  id: config.id,
399
417
  model: config.model,
400
- path: config.path
418
+ path: config.path,
419
+ tabName: config.tabName
401
420
  })
402
421
  });
403
422
  } else {
@@ -407,7 +426,8 @@ const addInterfacePropertyFromField = (config) => {
407
426
  docs: buildFieldDocs({
408
427
  id: config.id,
409
428
  model: config.model,
410
- path: config.path
429
+ path: config.path,
430
+ tabName: config.tabName
411
431
  })
412
432
  });
413
433
  }
@@ -420,7 +440,8 @@ const addInterfacePropertyFromField = (config) => {
420
440
  docs: buildFieldDocs({
421
441
  id: config.id,
422
442
  model: config.model,
423
- path: config.path
443
+ path: config.path,
444
+ tabName: config.tabName
424
445
  })
425
446
  });
426
447
  break;
@@ -432,7 +453,8 @@ const addInterfacePropertyFromField = (config) => {
432
453
  docs: buildFieldDocs({
433
454
  id: config.id,
434
455
  model: config.model,
435
- path: config.path
456
+ path: config.path,
457
+ tabName: config.tabName
436
458
  })
437
459
  });
438
460
  break;
@@ -477,7 +499,8 @@ const addInterfacePropertyFromField = (config) => {
477
499
  docs: buildFieldDocs({
478
500
  id: config.id,
479
501
  model: config.model,
480
- path: config.path
502
+ path: config.path,
503
+ tabName: config.tabName
481
504
  })
482
505
  });
483
506
  break;
@@ -626,7 +649,8 @@ const addInterfacePropertyFromField = (config) => {
626
649
  docs: buildFieldDocs({
627
650
  id: config.id,
628
651
  model: config.model,
629
- path: config.path
652
+ path: config.path,
653
+ tabName: config.tabName
630
654
  })
631
655
  });
632
656
  break;
@@ -638,7 +662,8 @@ const addInterfacePropertyFromField = (config) => {
638
662
  docs: buildFieldDocs({
639
663
  id: config.id,
640
664
  model: config.model,
641
- path: config.path
665
+ path: config.path,
666
+ tabName: config.tabName
642
667
  })
643
668
  });
644
669
  }
@@ -646,10 +671,11 @@ const addInterfacePropertyFromField = (config) => {
646
671
  };
647
672
  const addInterfacePropertiesForFields = (config) => {
648
673
  for (const name in config.fields) {
649
- addInterfacePropertyFromField({
674
+ addInterfacePropertyForField({
650
675
  ...config,
651
676
  id: name.includes("-") ? `"${name}"` : name,
652
- model: config.fields[name]
677
+ model: config.fields[name],
678
+ tabName: config.tabName
653
679
  });
654
680
  }
655
681
  };
@@ -676,18 +702,22 @@ const addTypeAliasForCustomType = ({
676
702
  }
677
703
  ]
678
704
  });
679
- addInterfacePropertiesForFields({
680
- fields,
681
- interface: dataInterface,
682
- sourceFile,
683
- path: [
684
- {
685
- id: model.id,
686
- model
687
- }
688
- ],
689
- fieldConfigs
690
- });
705
+ for (const tabName in model.json) {
706
+ const { uid: _uidField, ...tabFields } = model.json[tabName];
707
+ addInterfacePropertiesForFields({
708
+ fields: tabFields,
709
+ interface: dataInterface,
710
+ sourceFile,
711
+ path: [
712
+ {
713
+ id: model.id,
714
+ model
715
+ }
716
+ ],
717
+ fieldConfigs,
718
+ tabName
719
+ });
720
+ }
691
721
  } else {
692
722
  dataInterface = sourceFile.addTypeAlias({
693
723
  name: pascalCase(`${model.id} Document Data`),
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`),