@prismicio/types-internal 2.4.0-alpha.6 → 2.4.0

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.
@@ -120,7 +120,7 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
120
120
  var _a, _b;
121
121
  const fieldDef = (_b = (_a = model === null || model === void 0 ? void 0 : model.fields) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b[fieldKey];
122
122
  const transformedField = (() => {
123
- if ((0, GroupContent_1.isGroupContent)(fieldContent) && (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType) {
123
+ if ((0, GroupContent_1.isGroupContent)(fieldContent)) {
124
124
  return (0, GroupContent_1.traverseGroupContent)({
125
125
  path: path.concat([
126
126
  { key: "primary", type: "primary" },
@@ -129,7 +129,7 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
129
129
  key: fieldKey,
130
130
  apiId: fieldKey,
131
131
  content: fieldContent,
132
- model: fieldDef,
132
+ model: (fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.type) === customtypes_1.GroupFieldType ? fieldDef : undefined,
133
133
  })(transformWidget);
134
134
  }
135
135
  else if ((0, nestable_1.isNestableContent)(fieldContent)) {
@@ -145,13 +145,15 @@ function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content,
145
145
  });
146
146
  }
147
147
  else {
148
- console.warn(`Warn: Non nestable content or group (content and model) with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
149
- return;
148
+ return undefined;
150
149
  }
151
150
  })();
152
151
  // Can happen if the transform function returns undefined to filter out a field
153
152
  if (!transformedField)
154
153
  return acc;
154
+ if (!(0, SlicePrimaryContent_1.isSlicePrimaryContent)(transformedField)) {
155
+ console.warn(`Warn: Non nestable or group content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`);
156
+ }
155
157
  return {
156
158
  ...acc,
157
159
  [fieldKey]: transformedField,
@@ -325,3 +325,329 @@ export declare const SlicePrimaryWidget: t.UnionC<[t.UnionC<[t.ExactC<t.Intersec
325
325
  }>]>>]>;
326
326
  export declare type SlicePrimaryWidget = t.TypeOf<typeof SlicePrimaryWidget>;
327
327
  export declare type SlicePrimaryFieldTypes = SlicePrimaryWidget["type"];
328
+ export declare const isSlicePrimaryWidget: (u: unknown) => u is ({
329
+ type: "Boolean";
330
+ } & {
331
+ config?: {
332
+ label?: string | null | undefined;
333
+ default_value?: boolean;
334
+ placeholder_true?: string;
335
+ placeholder_false?: string;
336
+ };
337
+ }) | ({
338
+ type: "Color";
339
+ } & {
340
+ fieldset?: string | null | undefined;
341
+ config?: {
342
+ label?: string | null | undefined;
343
+ placeholder?: string;
344
+ };
345
+ }) | ({
346
+ type: "Date";
347
+ } & {
348
+ fieldset?: string | null | undefined;
349
+ config?: {
350
+ label?: string | null | undefined;
351
+ placeholder?: string;
352
+ default?: string;
353
+ };
354
+ }) | ({
355
+ type: "Embed";
356
+ } & {
357
+ fieldset?: string | null | undefined;
358
+ config?: {
359
+ label?: string | null | undefined;
360
+ placeholder?: string;
361
+ useAsTitle?: boolean;
362
+ };
363
+ }) | ({
364
+ type: "GeoPoint";
365
+ } & {
366
+ fieldset?: string | null | undefined;
367
+ config?: {
368
+ label?: string | null | undefined;
369
+ };
370
+ }) | ({
371
+ type: "Image";
372
+ } & {
373
+ fieldset?: string | null | undefined;
374
+ config?: {
375
+ label?: string | null | undefined;
376
+ placeholder?: string;
377
+ constraint?: {
378
+ width?: number | null;
379
+ height?: number | null;
380
+ };
381
+ thumbnails?: readonly ({
382
+ name: string;
383
+ } & {
384
+ width?: number | null;
385
+ height?: number | null;
386
+ })[];
387
+ };
388
+ }) | ({
389
+ type: "IntegrationFields";
390
+ } & {
391
+ fieldset?: string | null | undefined;
392
+ config?: {
393
+ label?: string | null | undefined;
394
+ placeholder?: string;
395
+ catalog?: string;
396
+ };
397
+ }) | ({
398
+ type: "Link";
399
+ } & {
400
+ fieldset?: string | null | undefined;
401
+ config?: {
402
+ label?: string | null | undefined;
403
+ useAsTitle?: boolean;
404
+ placeholder?: string;
405
+ select?: "media" | "document" | "web" | null;
406
+ customtypes?: readonly string[];
407
+ masks?: readonly string[];
408
+ tags?: readonly string[];
409
+ allowTargetBlank?: boolean;
410
+ };
411
+ }) | ({
412
+ type: "Number";
413
+ } & {
414
+ fieldset?: string | null | undefined;
415
+ config?: {
416
+ label?: string | null | undefined;
417
+ placeholder?: string;
418
+ min?: number;
419
+ max?: number;
420
+ step?: number;
421
+ };
422
+ }) | ({
423
+ type: "Range";
424
+ } & {
425
+ fieldset?: string | null | undefined;
426
+ config?: {
427
+ label?: string | null | undefined;
428
+ placeholder?: string;
429
+ min?: number;
430
+ max?: number;
431
+ step?: number;
432
+ };
433
+ }) | ({
434
+ type: "StructuredText";
435
+ } & {
436
+ fieldset?: string | null | undefined;
437
+ config?: {
438
+ label?: string | null | undefined;
439
+ placeholder?: string;
440
+ useAsTitle?: boolean;
441
+ single?: string;
442
+ multi?: string;
443
+ imageConstraint?: {
444
+ width?: number | null;
445
+ height?: number | null;
446
+ };
447
+ labels?: readonly string[];
448
+ allowTargetBlank?: boolean;
449
+ };
450
+ }) | ({
451
+ type: "Select";
452
+ } & {
453
+ fieldset?: string | null | undefined;
454
+ config?: {
455
+ label?: string | null | undefined;
456
+ placeholder?: string;
457
+ default_value?: string;
458
+ options?: readonly string[];
459
+ };
460
+ }) | ({
461
+ type: "Separator";
462
+ } & {
463
+ config?: {
464
+ label?: string | null | undefined;
465
+ };
466
+ }) | ({
467
+ type: "Text";
468
+ } & {
469
+ fieldset?: string | null | undefined;
470
+ config?: {
471
+ label?: string | null | undefined;
472
+ useAsTitle?: boolean;
473
+ placeholder?: string;
474
+ };
475
+ }) | ({
476
+ type: "Timestamp";
477
+ } & {
478
+ fieldset?: string | null | undefined;
479
+ config?: {
480
+ label?: string | null | undefined;
481
+ placeholder?: string;
482
+ default?: string;
483
+ };
484
+ }) | ({
485
+ type: "Group";
486
+ } & {
487
+ fieldset?: string | null | undefined;
488
+ icon?: string;
489
+ description?: string;
490
+ config?: {
491
+ label?: string | null | undefined;
492
+ repeat?: boolean;
493
+ fields?: {
494
+ [x: string]: ({
495
+ type: "Boolean";
496
+ } & {
497
+ config?: {
498
+ label?: string | null | undefined;
499
+ default_value?: boolean;
500
+ placeholder_true?: string;
501
+ placeholder_false?: string;
502
+ };
503
+ }) | ({
504
+ type: "Color";
505
+ } & {
506
+ fieldset?: string | null | undefined;
507
+ config?: {
508
+ label?: string | null | undefined;
509
+ placeholder?: string;
510
+ };
511
+ }) | ({
512
+ type: "Date";
513
+ } & {
514
+ fieldset?: string | null | undefined;
515
+ config?: {
516
+ label?: string | null | undefined;
517
+ placeholder?: string;
518
+ default?: string;
519
+ };
520
+ }) | ({
521
+ type: "Embed";
522
+ } & {
523
+ fieldset?: string | null | undefined;
524
+ config?: {
525
+ label?: string | null | undefined;
526
+ placeholder?: string;
527
+ useAsTitle?: boolean;
528
+ };
529
+ }) | ({
530
+ type: "GeoPoint";
531
+ } & {
532
+ fieldset?: string | null | undefined;
533
+ config?: {
534
+ label?: string | null | undefined;
535
+ };
536
+ }) | ({
537
+ type: "Image";
538
+ } & {
539
+ fieldset?: string | null | undefined;
540
+ config?: {
541
+ label?: string | null | undefined;
542
+ placeholder?: string;
543
+ constraint?: {
544
+ width?: number | null;
545
+ height?: number | null;
546
+ };
547
+ thumbnails?: readonly ({
548
+ name: string;
549
+ } & {
550
+ width?: number | null;
551
+ height?: number | null;
552
+ })[];
553
+ };
554
+ }) | ({
555
+ type: "IntegrationFields";
556
+ } & {
557
+ fieldset?: string | null | undefined;
558
+ config?: {
559
+ label?: string | null | undefined;
560
+ placeholder?: string;
561
+ catalog?: string;
562
+ };
563
+ }) | ({
564
+ type: "Link";
565
+ } & {
566
+ fieldset?: string | null | undefined;
567
+ config?: {
568
+ label?: string | null | undefined;
569
+ useAsTitle?: boolean;
570
+ placeholder?: string;
571
+ select?: "media" | "document" | "web" | null;
572
+ customtypes?: readonly string[];
573
+ masks?: readonly string[];
574
+ tags?: readonly string[];
575
+ allowTargetBlank?: boolean;
576
+ };
577
+ }) | ({
578
+ type: "Number";
579
+ } & {
580
+ fieldset?: string | null | undefined;
581
+ config?: {
582
+ label?: string | null | undefined;
583
+ placeholder?: string;
584
+ min?: number;
585
+ max?: number;
586
+ step?: number;
587
+ };
588
+ }) | ({
589
+ type: "Range";
590
+ } & {
591
+ fieldset?: string | null | undefined;
592
+ config?: {
593
+ label?: string | null | undefined;
594
+ placeholder?: string;
595
+ min?: number;
596
+ max?: number;
597
+ step?: number;
598
+ };
599
+ }) | ({
600
+ type: "StructuredText";
601
+ } & {
602
+ fieldset?: string | null | undefined;
603
+ config?: {
604
+ label?: string | null | undefined;
605
+ placeholder?: string;
606
+ useAsTitle?: boolean;
607
+ single?: string;
608
+ multi?: string;
609
+ imageConstraint?: {
610
+ width?: number | null;
611
+ height?: number | null;
612
+ };
613
+ labels?: readonly string[];
614
+ allowTargetBlank?: boolean;
615
+ };
616
+ }) | ({
617
+ type: "Select";
618
+ } & {
619
+ fieldset?: string | null | undefined;
620
+ config?: {
621
+ label?: string | null | undefined;
622
+ placeholder?: string;
623
+ default_value?: string;
624
+ options?: readonly string[];
625
+ };
626
+ }) | ({
627
+ type: "Separator";
628
+ } & {
629
+ config?: {
630
+ label?: string | null | undefined;
631
+ };
632
+ }) | ({
633
+ type: "Text";
634
+ } & {
635
+ fieldset?: string | null | undefined;
636
+ config?: {
637
+ label?: string | null | undefined;
638
+ useAsTitle?: boolean;
639
+ placeholder?: string;
640
+ };
641
+ }) | ({
642
+ type: "Timestamp";
643
+ } & {
644
+ fieldset?: string | null | undefined;
645
+ config?: {
646
+ label?: string | null | undefined;
647
+ placeholder?: string;
648
+ default?: string;
649
+ };
650
+ });
651
+ };
652
+ };
653
+ });
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlicePrimaryWidget = void 0;
3
+ exports.isSlicePrimaryWidget = exports.SlicePrimaryWidget = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const Group_1 = require("../Group");
7
7
  const nestable_1 = require("../nestable");
8
8
  exports.SlicePrimaryWidget = t.union([nestable_1.NestableWidget, Group_1.Group]);
9
+ const isSlicePrimaryWidget = (u) => nestable_1.NestableWidget.is(u) || Group_1.Group.is(u);
10
+ exports.isSlicePrimaryWidget = isSlicePrimaryWidget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.4.0-alpha.6",
3
+ "version": "2.4.0",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -32,7 +32,11 @@ import {
32
32
  } from "../../withDefaultValues"
33
33
  import type { SharedSliceItemContent } from "../SliceItem"
34
34
  import { RepeatableWidgets, RepeatableWidgetsLegacy } from "./RepeatableContent"
35
- import { SlicePrimaryContent, SlicePrimaryLegacy } from "./SlicePrimaryContent"
35
+ import {
36
+ isSlicePrimaryContent,
37
+ SlicePrimaryContent,
38
+ SlicePrimaryLegacy,
39
+ } from "./SlicePrimaryContent"
36
40
 
37
41
  export const SharedSliceContentType = "SharedSliceContent"
38
42
 
@@ -200,7 +204,7 @@ export function traverseSharedSliceContent({
200
204
  const fieldDef = model?.fields?.primary?.[fieldKey]
201
205
 
202
206
  const transformedField = (() => {
203
- if (isGroupContent(fieldContent) && fieldDef?.type === GroupFieldType) {
207
+ if (isGroupContent(fieldContent)) {
204
208
  return traverseGroupContent({
205
209
  path: path.concat([
206
210
  { key: "primary", type: "primary" },
@@ -209,7 +213,7 @@ export function traverseSharedSliceContent({
209
213
  key: fieldKey,
210
214
  apiId: fieldKey,
211
215
  content: fieldContent,
212
- model: fieldDef,
216
+ model: fieldDef?.type === GroupFieldType ? fieldDef : undefined,
213
217
  })(transformWidget)
214
218
  } else if (isNestableContent(fieldContent)) {
215
219
  return transformWidget({
@@ -223,15 +227,17 @@ export function traverseSharedSliceContent({
223
227
  content: fieldContent,
224
228
  })
225
229
  } else {
226
- console.warn(
227
- `Warn: Non nestable content or group (content and model) with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
228
- )
229
- return
230
+ return undefined
230
231
  }
231
232
  })()
232
233
 
233
234
  // Can happen if the transform function returns undefined to filter out a field
234
235
  if (!transformedField) return acc
236
+ if (!isSlicePrimaryContent(transformedField)) {
237
+ console.warn(
238
+ `Warn: Non nestable or group content with key [${fieldKey}] detected in a shared slice [${sliceName}] with key [${sliceKey}]`,
239
+ )
240
+ }
235
241
 
236
242
  return {
237
243
  ...acc,
@@ -7,3 +7,6 @@ export const SlicePrimaryWidget = t.union([NestableWidget, Group])
7
7
 
8
8
  export type SlicePrimaryWidget = t.TypeOf<typeof SlicePrimaryWidget>
9
9
  export type SlicePrimaryFieldTypes = SlicePrimaryWidget["type"]
10
+
11
+ export const isSlicePrimaryWidget = (u: unknown): u is SlicePrimaryWidget =>
12
+ NestableWidget.is(u) || Group.is(u)