@prismicio/types-internal 3.12.0-alpha.0 → 3.12.0-alpha.2

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.
@@ -9,10 +9,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
9
9
  __TYPE__: t.LiteralC<"EmptyContent">;
10
10
  }>>, t.ExactC<t.TypeC<{
11
11
  __TYPE__: t.LiteralC<"BooleanContent">;
12
- value: t.BooleanC; /**
13
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
14
- * format used by Prismic DB, therefore, this function itself is not "legacy".
15
- */
12
+ value: t.BooleanC;
16
13
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
17
14
  embed_url: t.StringC;
18
15
  type: t.StringC;
@@ -786,10 +783,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
786
783
  __TYPE__: t.LiteralC<"EmptyContent">;
787
784
  }>>, t.ExactC<t.TypeC<{
788
785
  __TYPE__: t.LiteralC<"BooleanContent">;
789
- value: t.BooleanC; /**
790
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
791
- * format used by Prismic DB, therefore, this function itself is not "legacy".
792
- */
786
+ value: t.BooleanC;
793
787
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
794
788
  embed_url: t.StringC;
795
789
  type: t.StringC;
@@ -1556,10 +1550,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
1556
1550
  __TYPE__: t.LiteralC<"EmptyContent">;
1557
1551
  }>>, t.ExactC<t.TypeC<{
1558
1552
  __TYPE__: t.LiteralC<"BooleanContent">;
1559
- value: t.BooleanC; /**
1560
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
1561
- * format used by Prismic DB, therefore, this function itself is not "legacy".
1562
- */
1553
+ value: t.BooleanC;
1563
1554
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
1564
1555
  embed_url: t.StringC;
1565
1556
  type: t.StringC;
@@ -2327,10 +2318,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
2327
2318
  __TYPE__: t.LiteralC<"EmptyContent">;
2328
2319
  }>>, t.ExactC<t.TypeC<{
2329
2320
  __TYPE__: t.LiteralC<"BooleanContent">;
2330
- value: t.BooleanC; /**
2331
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
2332
- * format used by Prismic DB, therefore, this function itself is not "legacy".
2333
- */
2321
+ value: t.BooleanC;
2334
2322
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
2335
2323
  embed_url: t.StringC;
2336
2324
  type: t.StringC;
@@ -3097,10 +3085,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
3097
3085
  __TYPE__: t.LiteralC<"EmptyContent">;
3098
3086
  }>>, t.ExactC<t.TypeC<{
3099
3087
  __TYPE__: t.LiteralC<"BooleanContent">;
3100
- value: t.BooleanC; /**
3101
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
3102
- * format used by Prismic DB, therefore, this function itself is not "legacy".
3103
- */
3088
+ value: t.BooleanC;
3104
3089
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
3105
3090
  embed_url: t.StringC;
3106
3091
  type: t.StringC;
@@ -3865,10 +3850,7 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
3865
3850
  __TYPE__: t.LiteralC<"EmptyContent">;
3866
3851
  }>>, t.ExactC<t.TypeC<{
3867
3852
  __TYPE__: t.LiteralC<"BooleanContent">;
3868
- value: t.BooleanC; /**
3869
- * `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
3870
- * format used by Prismic DB, therefore, this function itself is not "legacy".
3871
- */
3853
+ value: t.BooleanC;
3872
3854
  }>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
3873
3855
  embed_url: t.StringC;
3874
3856
  type: t.StringC;
@@ -8,6 +8,7 @@ const function_1 = require("fp-ts/lib/function");
8
8
  const t = (0, tslib_1.__importStar)(require("io-ts"));
9
9
  const utils_1 = require("../_internal/utils");
10
10
  const common_1 = require("../common");
11
+ const UUID_1 = require("../common/UUID");
11
12
  const customtypes_1 = require("../customtypes");
12
13
  const fields_1 = require("./fields");
13
14
  const LegacyContentCtx_1 = require("./LegacyContentCtx");
@@ -55,7 +56,7 @@ function extractMetadata(data) {
55
56
  }
56
57
  }
57
58
  if (k.endsWith("_KEY")) {
58
- const decodedValue = t.string.decode(v);
59
+ const decodedValue = UUID_1.UUID.decode(v);
59
60
  if ((0, Either_1.isRight)(decodedValue)) {
60
61
  return {
61
62
  ...acc,
@@ -147,9 +147,9 @@ function traverseGroupContent({ path, key, apiId, model, content, }) {
147
147
  exports.traverseGroupContent = traverseGroupContent;
148
148
  function traverseGroupItemsContent({ path, model, content, }) {
149
149
  return (transform) => {
150
- return content.map((groupItem, index) => {
150
+ return content.map((groupItem) => {
151
151
  const groupItemPath = path.concat([
152
- { key: index.toString(), type: "GroupItem" },
152
+ { key: groupItem.key, type: "GroupItem" },
153
153
  ]);
154
154
  const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
155
155
  const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
@@ -3865,7 +3865,7 @@ declare const itemLegacyReader: t.ExactC<t.IntersectionC<[t.TypeC<{
3865
3865
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
3866
3866
  }>]>>;
3867
3867
  export declare type SliceItemLegacy = t.TypeOf<typeof itemLegacyReader>;
3868
- export declare const SlicesItemLegacy: (ctx: LegacyContentCtx, index: number) => t.Type<{
3868
+ export declare const SlicesItemLegacy: (ctx: LegacyContentCtx) => t.Type<{
3869
3869
  key: string;
3870
3870
  name: string;
3871
3871
  maybeLabel: string | undefined;
@@ -64,19 +64,18 @@ const itemLegacyReader = t.exact(t.intersection([
64
64
  label: (0, function_2.nullable)(t.string),
65
65
  }),
66
66
  ]));
67
- const SlicesItemLegacy = (ctx, index) => {
67
+ const SlicesItemLegacy = (ctx) => {
68
68
  return new t.Type("SlicesItemLegacy", (u) => ((0, SharedSliceContent_1.isSharedSliceContent)(u.widget),
69
69
  (0, CompositeSliceContent_1.isCompositeSliceContent)(u.widget),
70
70
  (0, SimpleSliceContent_1.isSimpleSliceContent)(u.widget)), (sliceItem, context) => {
71
71
  return (0, function_1.pipe)(itemLegacyReader.decode(sliceItem), fp_ts_1.either.chain((parsedSlice) => {
72
72
  var _a;
73
- const sliceItemCtx = ctx.withContentKey(`${index}`);
74
73
  const stopIdx = parsedSlice.key.indexOf("$");
75
74
  const sliceName = parsedSlice.key.substring(0, stopIdx > 0 ? stopIdx : undefined);
76
75
  const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)({
77
76
  fieldKey: sliceName,
78
77
  contentKey: parsedSlice.key,
79
- ctx: sliceItemCtx,
78
+ ctx,
80
79
  });
81
80
  const item = (0, Slice_1.SliceLegacy)(itemCtx).decode(parsedSlice.value);
82
81
  if (!item || (0, Either_1.isLeft)(item))
@@ -89,11 +88,10 @@ const SlicesItemLegacy = (ctx, index) => {
89
88
  });
90
89
  }));
91
90
  }, (sItem) => {
92
- const sliceItemCtx = ctx.withContentKey(`${index}`);
93
91
  const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)({
94
92
  fieldKey: sItem.name,
95
93
  contentKey: sItem.key,
96
- ctx: sliceItemCtx,
94
+ ctx,
97
95
  });
98
96
  const result = (0, Slice_1.SliceLegacy)(itemCtx).encode(sItem.widget);
99
97
  return {
@@ -275,7 +275,7 @@ export declare const isSlicesContent: (u: unknown) => u is {
275
275
  variant?: string;
276
276
  });
277
277
  })[];
278
- } | import("../GroupContent").GroupContent | {
278
+ } | import("..").GroupContent | {
279
279
  __TYPE__: "StructuredTextContent";
280
280
  value: (({
281
281
  type: "image";
@@ -1461,7 +1461,7 @@ export declare const isSlicesContent: (u: unknown) => u is {
1461
1461
  variant?: string;
1462
1462
  });
1463
1463
  })[];
1464
- } | import("../GroupContent").GroupContent | {
1464
+ } | import("..").GroupContent | {
1465
1465
  __TYPE__: "StructuredTextContent";
1466
1466
  value: (({
1467
1467
  type: "image";
@@ -2056,7 +2056,7 @@ export declare const isSlicesContent: (u: unknown) => u is {
2056
2056
  variant?: string;
2057
2057
  });
2058
2058
  })[];
2059
- } | import("../GroupContent").GroupContent | {
2059
+ } | import("..").GroupContent | {
2060
2060
  __TYPE__: "StructuredTextContent";
2061
2061
  value: (({
2062
2062
  type: "image";
@@ -2650,7 +2650,7 @@ export declare const isSlicesContent: (u: unknown) => u is {
2650
2650
  variant?: string;
2651
2651
  });
2652
2652
  })[];
2653
- } | import("../GroupContent").GroupContent | {
2653
+ } | import("..").GroupContent | {
2654
2654
  __TYPE__: "StructuredTextContent";
2655
2655
  value: (({
2656
2656
  type: "image";
@@ -3251,7 +3251,7 @@ export declare const SlicesLegacy: (ctx: LegacyContentCtx) => t.Type<{
3251
3251
  variant?: string;
3252
3252
  });
3253
3253
  })[];
3254
- } | import("../GroupContent").GroupContent | {
3254
+ } | import("..").GroupContent | {
3255
3255
  __TYPE__: "StructuredTextContent";
3256
3256
  value: (({
3257
3257
  type: "image";
@@ -4437,7 +4437,7 @@ export declare const SlicesLegacy: (ctx: LegacyContentCtx) => t.Type<{
4437
4437
  variant?: string;
4438
4438
  });
4439
4439
  })[];
4440
- } | import("../GroupContent").GroupContent | {
4440
+ } | import("..").GroupContent | {
4441
4441
  __TYPE__: "StructuredTextContent";
4442
4442
  value: (({
4443
4443
  type: "image";
@@ -5032,7 +5032,7 @@ export declare const SlicesLegacy: (ctx: LegacyContentCtx) => t.Type<{
5032
5032
  variant?: string;
5033
5033
  });
5034
5034
  })[];
5035
- } | import("../GroupContent").GroupContent | {
5035
+ } | import("..").GroupContent | {
5036
5036
  __TYPE__: "StructuredTextContent";
5037
5037
  value: (({
5038
5038
  type: "image";
@@ -5626,7 +5626,7 @@ export declare const SlicesLegacy: (ctx: LegacyContentCtx) => t.Type<{
5626
5626
  variant?: string;
5627
5627
  });
5628
5628
  })[];
5629
- } | import("../GroupContent").GroupContent | {
5629
+ } | import("..").GroupContent | {
5630
5630
  __TYPE__: "StructuredTextContent";
5631
5631
  value: (({
5632
5632
  type: "image";
@@ -7492,7 +7492,7 @@ export declare const SlicesContent: t.TypeC<{
7492
7492
  variant: t.StringC;
7493
7493
  }>]>>]>]>;
7494
7494
  }>>]>>;
7495
- }>>]>, t.Type<import("../GroupContent").GroupContent, import("../GroupContent").GroupContent, unknown>]>]>>;
7495
+ }>>]>, t.Type<import("..").GroupContent, import("..").GroupContent, unknown>]>]>>;
7496
7496
  }>>>;
7497
7497
  }>>, t.ExactC<t.TypeC<{
7498
7498
  __TYPE__: t.LiteralC<"SharedSliceContent">;
@@ -8260,7 +8260,7 @@ export declare const SlicesContent: t.TypeC<{
8260
8260
  variant: t.StringC;
8261
8261
  }>]>>]>]>;
8262
8262
  }>>]>>;
8263
- }>>]>, t.Type<import("../GroupContent").GroupContent, import("../GroupContent").GroupContent, unknown>]>>;
8263
+ }>>]>, t.Type<import("..").GroupContent, import("..").GroupContent, unknown>]>>;
8264
8264
  items: t.ArrayC<t.ExactC<t.TypeC<{
8265
8265
  __TYPE__: t.LiteralC<"GroupItemContent">;
8266
8266
  key: t.StringC;
@@ -9027,7 +9027,7 @@ export declare const SlicesContent: t.TypeC<{
9027
9027
  variant: t.StringC;
9028
9028
  }>]>>]>]>;
9029
9029
  }>>]>>;
9030
- }>>]>, t.Type<import("../GroupContent").GroupContent, import("../GroupContent").GroupContent, unknown>]>]>>;
9030
+ }>>]>, t.Type<import("..").GroupContent, import("..").GroupContent, unknown>]>]>>;
9031
9031
  }>>>;
9032
9032
  }>>, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
9033
9033
  type: t.StringC;
@@ -9792,7 +9792,7 @@ export declare const SlicesContent: t.TypeC<{
9792
9792
  variant: t.StringC;
9793
9793
  }>]>>]>]>;
9794
9794
  }>>]>>;
9795
- }>>]>, t.Type<import("../GroupContent").GroupContent, import("../GroupContent").GroupContent, unknown>]>]>;
9795
+ }>>]>, t.Type<import("..").GroupContent, import("..").GroupContent, unknown>]>]>;
9796
9796
  }>>;
9797
9797
  }>;
9798
9798
  export declare type SlicesContent = t.TypeOf<typeof SlicesContent>;
@@ -8,7 +8,6 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
8
  const utils_1 = require("../../../_internal/utils");
9
9
  const customtypes_1 = require("../../../customtypes");
10
10
  const utils_2 = require("../../utils");
11
- const GroupContent_1 = require("../GroupContent");
12
11
  const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
13
12
  const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
14
13
  const SimpleSliceContent_1 = require("./Slice/SimpleSliceContent");
@@ -17,7 +16,7 @@ exports.SlicesContentType = "SliceContentType";
17
16
  const isSlicesContent = (u) => (0, utils_2.hasContentType)(u) && u.__TYPE__ === exports.SlicesContentType;
18
17
  exports.isSlicesContent = isSlicesContent;
19
18
  const SlicesLegacy = (ctx) => {
20
- const codec = (0, GroupContent_1.arrayWithIndexCodec)((index) => (0, SliceItem_1.SlicesItemLegacy)(ctx, index));
19
+ const codec = t.array((0, SliceItem_1.SlicesItemLegacy)(ctx));
21
20
  return new t.Type("SlicesLegacy", exports.isSlicesContent, (items) => {
22
21
  return (0, function_1.pipe)(codec.decode(items), fp_ts_1.either.map((parsedSlices) => {
23
22
  return {
@@ -165,17 +165,20 @@ function collectSharedSlices(customType) {
165
165
  exports.collectSharedSlices = collectSharedSlices;
166
166
  function traverseCustomType(args) {
167
167
  const { customType, onField } = args;
168
- const json = {};
168
+ let json;
169
169
  for (const [key, section] of Object.entries(customType.json)) {
170
- json[key] = (0, Section_1.traverseSection)({
170
+ const newSection = (0, Section_1.traverseSection)({
171
171
  path: [key],
172
172
  section,
173
173
  onField,
174
174
  });
175
+ if (newSection !== section) {
176
+ if (!json)
177
+ json = { ...customType.json };
178
+ json[key] = newSection;
179
+ }
175
180
  }
176
- return {
177
- ...customType,
178
- json,
179
- };
181
+ // returns the traversed model instead of a new one if it didn't change
182
+ return json ? { ...customType, json } : customType;
180
183
  }
181
184
  exports.traverseCustomType = traverseCustomType;
@@ -22,7 +22,7 @@ exports.Sections = {
22
22
  };
23
23
  function traverseSection(args) {
24
24
  const { path: prevPath, section: prevSection, onField } = args;
25
- const section = { ...prevSection };
25
+ let section;
26
26
  for (const [key, prevModel] of Object.entries(prevSection)) {
27
27
  const path = [...prevPath, key];
28
28
  let model;
@@ -54,8 +54,13 @@ function traverseSection(args) {
54
54
  });
55
55
  break;
56
56
  }
57
- section[key] = model;
57
+ if (model !== prevModel) {
58
+ if (!section)
59
+ section = { ...prevSection };
60
+ section[key] = model;
61
+ }
58
62
  }
59
- return section;
63
+ // returns the traversed model instead of a new one if it didn't change
64
+ return section !== null && section !== void 0 ? section : prevSection;
60
65
  }
61
66
  exports.traverseSection = traverseSection;
@@ -36,22 +36,22 @@ function traverseNestedGroup(args) {
36
36
  const { path: prevPath, group, onField } = args;
37
37
  if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
38
38
  return group;
39
- const fields = {};
40
- for (const [key, prevField] of Object.entries(group.config.fields)) {
39
+ let fields;
40
+ for (const [key, field] of Object.entries(group.config.fields)) {
41
41
  const path = [...prevPath, key];
42
- fields[key] = onField({
42
+ const newField = onField({
43
43
  path,
44
44
  key,
45
- field: prevField,
45
+ field,
46
46
  });
47
+ if (field !== newField) {
48
+ if (!fields)
49
+ fields = { ...group.config.fields };
50
+ fields[key] = newField;
51
+ }
47
52
  }
48
- return {
49
- ...group,
50
- config: {
51
- ...group.config,
52
- fields,
53
- },
54
- };
53
+ // returns the traversed model instead of a new one if it didn't change
54
+ return fields ? { ...group, config: { ...group.config, fields } } : group;
55
55
  }
56
56
  exports.traverseNestedGroup = traverseNestedGroup;
57
57
  function traverseGroup(args) {
@@ -59,7 +59,7 @@ function traverseGroup(args) {
59
59
  const { path: prevPath, group, onField } = args;
60
60
  if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
61
61
  return group;
62
- const fields = {};
62
+ let fields;
63
63
  for (const [key, prevField] of Object.entries(group.config.fields)) {
64
64
  const path = [...prevPath, key];
65
65
  let field;
@@ -75,18 +75,18 @@ function traverseGroup(args) {
75
75
  field = prevField;
76
76
  break;
77
77
  }
78
- fields[key] = onField({
78
+ const newField = onField({
79
79
  path,
80
80
  key,
81
81
  field,
82
82
  });
83
+ if (field !== newField) {
84
+ if (!fields)
85
+ fields = { ...group.config.fields };
86
+ fields[key] = newField;
87
+ }
83
88
  }
84
- return {
85
- ...group,
86
- config: {
87
- ...group.config,
88
- fields,
89
- },
90
- };
89
+ // returns the traversed model instead of a new one if it didn't change
90
+ return fields ? { ...group, config: { ...group.config, fields } } : group;
91
91
  }
92
92
  exports.traverseGroup = traverseGroup;
@@ -31,20 +31,33 @@ exports.isCompositeSlice = isCompositeSlice;
31
31
  function traverseCompositeSlice(args) {
32
32
  var _a, _b;
33
33
  const { path: prevPath, slice, onField } = args;
34
- const nonRepeat = {};
34
+ let nonRepeat;
35
35
  for (const [key, field] of Object.entries((_a = slice["non-repeat"]) !== null && _a !== void 0 ? _a : {})) {
36
36
  const path = [...prevPath, "non-repeat", key];
37
- nonRepeat[key] = onField({ path, key, field });
37
+ const newField = onField({ path, key, field });
38
+ if (field !== newField) {
39
+ if (!nonRepeat)
40
+ nonRepeat = { ...slice["non-repeat"] };
41
+ nonRepeat[key] = newField;
42
+ }
38
43
  }
39
- const repeat = {};
44
+ let repeat;
40
45
  for (const [key, field] of Object.entries((_b = slice.repeat) !== null && _b !== void 0 ? _b : {})) {
41
46
  const path = [...prevPath, "repeat", key];
42
- repeat[key] = onField({ path, key, field });
47
+ const newField = onField({ path, key, field });
48
+ if (field !== newField) {
49
+ if (!repeat)
50
+ repeat = { ...slice.repeat };
51
+ repeat[key] = newField;
52
+ }
43
53
  }
44
- return {
45
- ...slice,
46
- ...(slice["non-repeat"] && { "non-repeat": nonRepeat }),
47
- ...(slice.repeat && { repeat }),
48
- };
54
+ // returns the traversed model instead of a new one if it didn't change
55
+ return repeat || nonRepeat
56
+ ? {
57
+ ...slice,
58
+ ...(nonRepeat && { "non-repeat": nonRepeat }),
59
+ ...(repeat && { repeat }),
60
+ }
61
+ : slice;
49
62
  }
50
63
  exports.traverseCompositeSlice = traverseCompositeSlice;
@@ -50,7 +50,7 @@ exports.isDynamicSharedSlice = isDynamicSharedSlice;
50
50
  function traverseVariation(args) {
51
51
  var _a, _b;
52
52
  const { path: prevPath, variation, onField } = args;
53
- const primary = {};
53
+ let primary;
54
54
  for (const [key, prevField] of Object.entries((_a = variation.primary) !== null && _a !== void 0 ? _a : {})) {
55
55
  const path = [...prevPath, "primary", key];
56
56
  let field;
@@ -66,34 +66,53 @@ function traverseVariation(args) {
66
66
  field = prevField;
67
67
  break;
68
68
  }
69
- primary[key] = onField({ path, key, field });
69
+ const newField = onField({ path, key, field });
70
+ if (field !== newField) {
71
+ if (!primary)
72
+ primary = { ...variation.primary };
73
+ primary[key] = newField;
74
+ }
70
75
  }
71
- const items = {};
72
- for (const [key, field] of Object.entries((_b = variation.items) !== null && _b !== void 0 ? _b : {})) {
76
+ let items;
77
+ for (const [key, prevField] of Object.entries((_b = variation.items) !== null && _b !== void 0 ? _b : {})) {
73
78
  const path = [...prevPath, "items", key];
74
- items[key] = onField({ path, key, field });
79
+ const newField = onField({
80
+ path,
81
+ key,
82
+ field: prevField,
83
+ });
84
+ if (prevField !== newField) {
85
+ if (!items)
86
+ items = { ...variation.items };
87
+ items[key] = newField;
88
+ }
75
89
  }
76
- return {
77
- ...variation,
78
- ...(variation.primary && { primary }),
79
- ...(variation.items && { items }),
80
- };
90
+ // returns the traversed model instead of a new one if it didn't change
91
+ return primary || items
92
+ ? { ...variation, ...(primary && { primary }), ...(items && { items }) }
93
+ : variation;
81
94
  }
82
95
  exports.traverseVariation = traverseVariation;
83
96
  function traverseSharedSlice(args) {
84
97
  const { path: prevPath, slice, onField } = args;
85
- const variations = [];
86
- for (const variation of slice.variations) {
98
+ let variations;
99
+ for (let i = 0; i < slice.variations.length; i++) {
100
+ const variation = slice.variations[i];
101
+ if (!variation)
102
+ continue;
87
103
  const path = [...prevPath, variation.id];
88
- variations.push(traverseVariation({
104
+ const newVariation = traverseVariation({
89
105
  path,
90
106
  variation,
91
107
  onField,
92
- }));
108
+ });
109
+ if (newVariation !== variation) {
110
+ if (!variations)
111
+ variations = [...slice.variations];
112
+ variations[i] = newVariation;
113
+ }
93
114
  }
94
- return {
95
- ...slice,
96
- variations,
97
- };
115
+ // returns the traversed model instead of a new one if it didn't change
116
+ return variations ? { ...slice, variations } : slice;
98
117
  }
99
118
  exports.traverseSharedSlice = traverseSharedSlice;
@@ -84,7 +84,7 @@ function traverseSlices(args) {
84
84
  const { path: prevPath, slices, onField } = args;
85
85
  if (!((_a = slices.config) === null || _a === void 0 ? void 0 : _a.choices))
86
86
  return slices;
87
- const choices = {};
87
+ let choices;
88
88
  for (const [key, prevModel] of Object.entries(slices.config.choices)) {
89
89
  const path = [...prevPath, key];
90
90
  let model;
@@ -126,14 +126,21 @@ function traverseSlices(args) {
126
126
  });
127
127
  break;
128
128
  }
129
- choices[key] = model;
129
+ if (model !== prevModel) {
130
+ if (!choices)
131
+ choices = { ...slices.config.choices };
132
+ choices[key] = model;
133
+ }
130
134
  }
131
- return {
132
- ...slices,
133
- config: {
134
- ...slices.config,
135
- choices,
136
- },
137
- };
135
+ // returns the traversed model instead of a new one if it didn't change
136
+ return choices
137
+ ? {
138
+ ...slices,
139
+ config: {
140
+ ...slices.config,
141
+ choices,
142
+ },
143
+ }
144
+ : slices;
138
145
  }
139
146
  exports.traverseSlices = traverseSlices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "3.12.0-alpha.0",
3
+ "version": "3.12.0-alpha.2",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -9,6 +9,7 @@ import {
9
9
  TraverseWidgetContentFn,
10
10
  } from "../_internal/utils"
11
11
  import { WidgetKey } from "../common"
12
+ import { UUID } from "../common/UUID"
12
13
  import {
13
14
  type StaticWidget,
14
15
  collectSharedSlices,
@@ -114,7 +115,7 @@ function extractMetadata(data: { [p: string]: unknown }): {
114
115
  }
115
116
  }
116
117
  if (k.endsWith("_KEY")) {
117
- const decodedValue = t.string.decode(v)
118
+ const decodedValue = UUID.decode(v)
118
119
  if (isRight(decodedValue)) {
119
120
  return {
120
121
  ...acc,
@@ -264,9 +264,9 @@ export function traverseGroupItemsContent({
264
264
  model?: Record<string, Group | NestableWidget> | undefined
265
265
  }) {
266
266
  return (transform: TraverseWidgetContentFn): Array<GroupItemContent> => {
267
- return content.map((groupItem, index) => {
267
+ return content.map((groupItem) => {
268
268
  const groupItemPath = path.concat([
269
- { key: index.toString(), type: "GroupItem" },
269
+ { key: groupItem.key, type: "GroupItem" },
270
270
  ])
271
271
 
272
272
  const groupItemFields = groupItem.value.reduce<GroupItemContent["value"]>(
@@ -117,7 +117,7 @@ const itemLegacyReader = t.exact(
117
117
 
118
118
  export type SliceItemLegacy = t.TypeOf<typeof itemLegacyReader>
119
119
 
120
- export const SlicesItemLegacy = (ctx: LegacyContentCtx, index: number) => {
120
+ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
121
121
  return new t.Type<SliceItemContent, WithTypes<SliceItemLegacy>, unknown>(
122
122
  "SlicesItemLegacy",
123
123
  (u): u is SliceItemContent => (
@@ -129,7 +129,6 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx, index: number) => {
129
129
  return pipe(
130
130
  itemLegacyReader.decode(sliceItem),
131
131
  either.chain((parsedSlice) => {
132
- const sliceItemCtx = ctx.withContentKey(`${index}`)
133
132
  const stopIdx = parsedSlice.key.indexOf("$")
134
133
  const sliceName = parsedSlice.key.substring(
135
134
  0,
@@ -138,7 +137,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx, index: number) => {
138
137
  const itemCtx = getFieldCtx({
139
138
  fieldKey: sliceName,
140
139
  contentKey: parsedSlice.key,
141
- ctx: sliceItemCtx,
140
+ ctx,
142
141
  })
143
142
  const item = SliceLegacy(itemCtx).decode(parsedSlice.value)
144
143
  if (!item || isLeft(item)) return t.failure(sliceItem, context)
@@ -153,11 +152,10 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx, index: number) => {
153
152
  )
154
153
  },
155
154
  (sItem: SliceItemContent) => {
156
- const sliceItemCtx = ctx.withContentKey(`${index}`)
157
155
  const itemCtx = getFieldCtx({
158
156
  fieldKey: sItem.name,
159
157
  contentKey: sItem.key,
160
- ctx: sliceItemCtx,
158
+ ctx,
161
159
  })
162
160
  const result = SliceLegacy(itemCtx).encode(sItem.widget)
163
161