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.
@@ -26,9 +26,10 @@ type AddInterfacePropertyFromFieldConfig = {
26
26
  ...PathElement<CustomTypeModelField | CustomTypeModelSlice>[],
27
27
  ];
28
28
  fieldConfigs: FieldConfigs;
29
+ tabName?: string;
29
30
  };
30
31
 
31
- const addInterfacePropertyFromField = (
32
+ const addInterfacePropertyForField = (
32
33
  config: AddInterfacePropertyFromFieldConfig,
33
34
  ) => {
34
35
  switch (config.model.type) {
@@ -45,6 +46,7 @@ const addInterfacePropertyFromField = (
45
46
  id: config.id,
46
47
  model: config.model,
47
48
  path: config.path,
49
+ tabName: config.tabName,
48
50
  }),
49
51
  });
50
52
 
@@ -59,6 +61,7 @@ const addInterfacePropertyFromField = (
59
61
  id: config.id,
60
62
  model: config.model,
61
63
  path: config.path,
64
+ tabName: config.tabName,
62
65
  }),
63
66
  });
64
67
 
@@ -73,6 +76,7 @@ const addInterfacePropertyFromField = (
73
76
  id: config.id,
74
77
  model: config.model,
75
78
  path: config.path,
79
+ tabName: config.tabName,
76
80
  }),
77
81
  });
78
82
 
@@ -105,6 +109,7 @@ const addInterfacePropertyFromField = (
105
109
  id: config.id,
106
110
  model: config.model,
107
111
  path: config.path,
112
+ tabName: config.tabName,
108
113
  }),
109
114
  });
110
115
 
@@ -119,6 +124,7 @@ const addInterfacePropertyFromField = (
119
124
  id: config.id,
120
125
  model: config.model,
121
126
  path: config.path,
127
+ tabName: config.tabName,
122
128
  }),
123
129
  });
124
130
 
@@ -138,6 +144,7 @@ const addInterfacePropertyFromField = (
138
144
  id: config.id,
139
145
  model: config.model,
140
146
  path: config.path,
147
+ tabName: config.tabName,
141
148
  }),
142
149
  });
143
150
  } else {
@@ -148,6 +155,7 @@ const addInterfacePropertyFromField = (
148
155
  id: config.id,
149
156
  model: config.model,
150
157
  path: config.path,
158
+ tabName: config.tabName,
151
159
  }),
152
160
  });
153
161
  }
@@ -170,6 +178,7 @@ const addInterfacePropertyFromField = (
170
178
  id: config.id,
171
179
  model: config.model,
172
180
  path: config.path,
181
+ tabName: config.tabName,
173
182
  }),
174
183
  });
175
184
 
@@ -192,6 +201,7 @@ const addInterfacePropertyFromField = (
192
201
  id: config.id,
193
202
  model: config.model,
194
203
  path: config.path,
204
+ tabName: config.tabName,
195
205
  }),
196
206
  });
197
207
 
@@ -206,6 +216,7 @@ const addInterfacePropertyFromField = (
206
216
  id: config.id,
207
217
  model: config.model,
208
218
  path: config.path,
219
+ tabName: config.tabName,
209
220
  }),
210
221
  });
211
222
 
@@ -220,6 +231,7 @@ const addInterfacePropertyFromField = (
220
231
  id: config.id,
221
232
  model: config.model,
222
233
  path: config.path,
234
+ tabName: config.tabName,
223
235
  }),
224
236
  });
225
237
  }
@@ -236,6 +248,7 @@ const addInterfacePropertyFromField = (
236
248
  id: config.id,
237
249
  model: config.model,
238
250
  path: config.path,
251
+ tabName: config.tabName,
239
252
  }),
240
253
  });
241
254
 
@@ -257,6 +270,7 @@ const addInterfacePropertyFromField = (
257
270
  id: config.id,
258
271
  model: config.model,
259
272
  path: config.path,
273
+ tabName: config.tabName,
260
274
  }),
261
275
  });
262
276
  } else {
@@ -267,6 +281,7 @@ const addInterfacePropertyFromField = (
267
281
  id: config.id,
268
282
  model: config.model,
269
283
  path: config.path,
284
+ tabName: config.tabName,
270
285
  }),
271
286
  });
272
287
  }
@@ -288,6 +303,7 @@ const addInterfacePropertyFromField = (
288
303
  id: config.id,
289
304
  model: config.model,
290
305
  path: config.path,
306
+ tabName: config.tabName,
291
307
  }),
292
308
  });
293
309
  } else {
@@ -298,6 +314,7 @@ const addInterfacePropertyFromField = (
298
314
  id: config.id,
299
315
  model: config.model,
300
316
  path: config.path,
317
+ tabName: config.tabName,
301
318
  }),
302
319
  });
303
320
  }
@@ -313,6 +330,7 @@ const addInterfacePropertyFromField = (
313
330
  id: config.id,
314
331
  model: config.model,
315
332
  path: config.path,
333
+ tabName: config.tabName,
316
334
  }),
317
335
  });
318
336
 
@@ -327,6 +345,7 @@ const addInterfacePropertyFromField = (
327
345
  id: config.id,
328
346
  model: config.model,
329
347
  path: config.path,
348
+ tabName: config.tabName,
330
349
  }),
331
350
  });
332
351
 
@@ -378,6 +397,7 @@ const addInterfacePropertyFromField = (
378
397
  id: config.id,
379
398
  model: config.model,
380
399
  path: config.path,
400
+ tabName: config.tabName,
381
401
  }),
382
402
  });
383
403
 
@@ -558,6 +578,7 @@ const addInterfacePropertyFromField = (
558
578
  id: config.id,
559
579
  model: config.model,
560
580
  path: config.path,
581
+ tabName: config.tabName,
561
582
  }),
562
583
  });
563
584
 
@@ -572,6 +593,7 @@ const addInterfacePropertyFromField = (
572
593
  id: config.id,
573
594
  model: config.model,
574
595
  path: config.path,
596
+ tabName: config.tabName,
575
597
  }),
576
598
  });
577
599
  }
@@ -583,16 +605,18 @@ type AddInterfacePropertiesForFieldsConfig = Omit<
583
605
  "id" | "model"
584
606
  > & {
585
607
  fields: Record<string, AddInterfacePropertyFromFieldConfig["model"]>;
608
+ tabName?: string;
586
609
  };
587
610
 
588
611
  export const addInterfacePropertiesForFields = (
589
612
  config: AddInterfacePropertiesForFieldsConfig,
590
613
  ) => {
591
614
  for (const name in config.fields) {
592
- addInterfacePropertyFromField({
615
+ addInterfacePropertyForField({
593
616
  ...config,
594
617
  id: name.includes("-") ? `"${name}"` : name,
595
618
  model: config.fields[name],
619
+ tabName: config.tabName,
596
620
  });
597
621
  }
598
622
  };
@@ -43,18 +43,26 @@ export const addTypeAliasForCustomType = ({
43
43
  },
44
44
  ],
45
45
  });
46
- addInterfacePropertiesForFields({
47
- fields,
48
- interface: dataInterface,
49
- sourceFile: sourceFile,
50
- path: [
51
- {
52
- id: model.id,
53
- model: model,
54
- },
55
- ],
56
- fieldConfigs,
57
- });
46
+
47
+ for (const tabName in model.json) {
48
+ // This is destructured to ensure the UID field is
49
+ // ignored.
50
+ const { uid: _uidField, ...tabFields } = model.json[tabName];
51
+
52
+ addInterfacePropertiesForFields({
53
+ fields: tabFields,
54
+ interface: dataInterface,
55
+ sourceFile: sourceFile,
56
+ path: [
57
+ {
58
+ id: model.id,
59
+ model: model,
60
+ },
61
+ ],
62
+ fieldConfigs,
63
+ tabName,
64
+ });
65
+ }
58
66
  } else {
59
67
  dataInterface = sourceFile.addTypeAlias({
60
68
  name: pascalCase(`${model.id} Document Data`),
@@ -21,6 +21,7 @@ type BuildFieldDocsConfig = {
21
21
  PathElement<CustomTypeModel | SharedSliceModel>,
22
22
  ...PathElement<CustomTypeModelField | CustomTypeModelSlice>[],
23
23
  ];
24
+ tabName?: string;
24
25
  };
25
26
 
26
27
  export const buildFieldDocs = (
@@ -63,6 +64,7 @@ export const buildFieldDocs = (
63
64
  placeholder,
64
65
  defaultValue,
65
66
  apiIDPath,
67
+ tabName: config.tabName,
66
68
  documentationURL: getFieldDocumentationURL({ model: config.model }),
67
69
  });
68
70
  },
@@ -7,6 +7,7 @@ type BuildFieldDocsConfig = {
7
7
  defaultValue?: string | boolean;
8
8
  placeholder?: string;
9
9
  apiIDPath?: string;
10
+ tabName?: string;
10
11
  documentationURL?: string;
11
12
  };
12
13
 
@@ -40,6 +41,10 @@ export const writeFieldDocsDescription = (
40
41
  config.writer.writeLine(`- **API ID Path**: ${config.apiIDPath}`);
41
42
  }
42
43
 
44
+ if (config.tabName) {
45
+ config.writer.writeLine(`- **Tab**: ${config.tabName}`);
46
+ }
47
+
43
48
  if (config.documentationURL) {
44
49
  config.writer.writeLine(`- **Documentation**: ${config.documentationURL}`);
45
50
  }