@prismicio/types-internal 3.11.1 → 3.11.2-alpha.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.
@@ -166,16 +166,17 @@ exports.collectSharedSlices = collectSharedSlices;
166
166
  function traverseCustomType(args) {
167
167
  const { customType, onField } = args;
168
168
  const json = {};
169
+ let changed = false;
169
170
  for (const [key, section] of Object.entries(customType.json)) {
170
- json[key] = (0, Section_1.traverseSection)({
171
+ const newSection = (0, Section_1.traverseSection)({
171
172
  path: [key],
172
173
  section,
173
174
  onField,
174
175
  });
176
+ if (!changed && newSection !== section)
177
+ changed = true;
178
+ json[key] = newSection;
175
179
  }
176
- return {
177
- ...customType,
178
- json,
179
- };
180
+ return changed ? { ...customType, json } : customType;
180
181
  }
181
182
  exports.traverseCustomType = traverseCustomType;
@@ -22,7 +22,8 @@ exports.Sections = {
22
22
  };
23
23
  function traverseSection(args) {
24
24
  const { path: prevPath, section: prevSection, onField } = args;
25
- const section = { ...prevSection };
25
+ const section = {};
26
+ let changed = false;
26
27
  for (const [key, prevModel] of Object.entries(prevSection)) {
27
28
  const path = [...prevPath, key];
28
29
  let model;
@@ -54,8 +55,10 @@ function traverseSection(args) {
54
55
  });
55
56
  break;
56
57
  }
58
+ if (!changed && model !== prevModel)
59
+ changed = true;
57
60
  section[key] = model;
58
61
  }
59
- return section;
62
+ return changed ? section : prevSection;
60
63
  }
61
64
  exports.traverseSection = traverseSection;
@@ -37,21 +37,27 @@ function traverseNestedGroup(args) {
37
37
  if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
38
38
  return group;
39
39
  const fields = {};
40
- for (const [key, prevField] of Object.entries(group.config.fields)) {
40
+ let changed = false;
41
+ for (const [key, field] of Object.entries(group.config.fields)) {
41
42
  const path = [...prevPath, key];
42
- fields[key] = onField({
43
+ const newField = onField({
43
44
  path,
44
45
  key,
45
- field: prevField,
46
+ field,
46
47
  });
48
+ if (!changed && field !== newField)
49
+ changed = true;
50
+ fields[key] = newField;
47
51
  }
48
- return {
49
- ...group,
50
- config: {
51
- ...group.config,
52
- fields,
53
- },
54
- };
52
+ return changed
53
+ ? {
54
+ ...group,
55
+ config: {
56
+ ...group.config,
57
+ fields,
58
+ },
59
+ }
60
+ : group;
55
61
  }
56
62
  exports.traverseNestedGroup = traverseNestedGroup;
57
63
  function traverseGroup(args) {
@@ -60,6 +66,7 @@ function traverseGroup(args) {
60
66
  if (!((_a = group.config) === null || _a === void 0 ? void 0 : _a.fields))
61
67
  return group;
62
68
  const fields = {};
69
+ let changed = false;
63
70
  for (const [key, prevField] of Object.entries(group.config.fields)) {
64
71
  const path = [...prevPath, key];
65
72
  let field;
@@ -75,18 +82,23 @@ function traverseGroup(args) {
75
82
  field = prevField;
76
83
  break;
77
84
  }
78
- fields[key] = onField({
85
+ const newField = onField({
79
86
  path,
80
87
  key,
81
88
  field,
82
89
  });
90
+ if (!changed && field !== newField)
91
+ changed = true;
92
+ fields[key] = newField;
83
93
  }
84
- return {
85
- ...group,
86
- config: {
87
- ...group.config,
88
- fields,
89
- },
90
- };
94
+ return changed
95
+ ? {
96
+ ...group,
97
+ config: {
98
+ ...group.config,
99
+ fields,
100
+ },
101
+ }
102
+ : group;
91
103
  }
92
104
  exports.traverseGroup = traverseGroup;
@@ -32,19 +32,29 @@ function traverseCompositeSlice(args) {
32
32
  var _a, _b;
33
33
  const { path: prevPath, slice, onField } = args;
34
34
  const nonRepeat = {};
35
+ let nonRepeatChanged = false;
35
36
  for (const [key, field] of Object.entries((_a = slice["non-repeat"]) !== null && _a !== void 0 ? _a : {})) {
36
37
  const path = [...prevPath, "non-repeat", key];
37
- nonRepeat[key] = onField({ path, key, field });
38
+ const newField = onField({ path, key, field });
39
+ if (!nonRepeatChanged && field !== newField)
40
+ nonRepeatChanged = true;
41
+ nonRepeat[key] = newField;
38
42
  }
39
43
  const repeat = {};
44
+ let repeatChanged = false;
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 (!repeatChanged && field !== newField)
49
+ repeatChanged = true;
50
+ repeat[key] = newField;
43
51
  }
44
- return {
45
- ...slice,
46
- ...(slice["non-repeat"] && { "non-repeat": nonRepeat }),
47
- ...(slice.repeat && { repeat }),
48
- };
52
+ return nonRepeatChanged || repeatChanged
53
+ ? {
54
+ ...slice,
55
+ ...(nonRepeatChanged && { "non-repeat": nonRepeat }),
56
+ ...(repeatChanged && { repeat }),
57
+ }
58
+ : slice;
49
59
  }
50
60
  exports.traverseCompositeSlice = traverseCompositeSlice;
@@ -51,6 +51,7 @@ function traverseVariation(args) {
51
51
  var _a, _b;
52
52
  const { path: prevPath, variation, onField } = args;
53
53
  const primary = {};
54
+ let primaryChanged = false;
54
55
  for (const [key, prevField] of Object.entries((_a = variation.primary) !== null && _a !== void 0 ? _a : {})) {
55
56
  const path = [...prevPath, "primary", key];
56
57
  let field;
@@ -66,34 +67,53 @@ function traverseVariation(args) {
66
67
  field = prevField;
67
68
  break;
68
69
  }
69
- primary[key] = onField({ path, key, field });
70
+ const newField = onField({ path, key, field });
71
+ if (!primaryChanged && field !== newField)
72
+ primaryChanged = true;
73
+ primary[key] = newField;
70
74
  }
71
75
  const items = {};
72
- for (const [key, field] of Object.entries((_b = variation.items) !== null && _b !== void 0 ? _b : {})) {
76
+ let itemsChanged = false;
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 (!itemsChanged && prevField !== newField)
85
+ itemsChanged = true;
86
+ items[key] = newField;
75
87
  }
76
- return {
77
- ...variation,
78
- ...(variation.primary && { primary }),
79
- ...(variation.items && { items }),
80
- };
88
+ return primaryChanged || itemsChanged
89
+ ? {
90
+ ...variation,
91
+ ...(primaryChanged && { primary }),
92
+ ...(itemsChanged && { items }),
93
+ }
94
+ : variation;
81
95
  }
82
96
  exports.traverseVariation = traverseVariation;
83
97
  function traverseSharedSlice(args) {
84
98
  const { path: prevPath, slice, onField } = args;
85
99
  const variations = [];
100
+ let changed = false;
86
101
  for (const variation of slice.variations) {
87
102
  const path = [...prevPath, variation.id];
88
- variations.push(traverseVariation({
103
+ const newVariation = traverseVariation({
89
104
  path,
90
105
  variation,
91
106
  onField,
92
- }));
107
+ });
108
+ if (!changed && newVariation !== variation)
109
+ changed = true;
110
+ variations.push(newVariation);
93
111
  }
94
- return {
95
- ...slice,
96
- variations,
97
- };
112
+ return changed
113
+ ? {
114
+ ...slice,
115
+ variations,
116
+ }
117
+ : slice;
98
118
  }
99
119
  exports.traverseSharedSlice = traverseSharedSlice;
@@ -85,6 +85,7 @@ function traverseSlices(args) {
85
85
  if (!((_a = slices.config) === null || _a === void 0 ? void 0 : _a.choices))
86
86
  return slices;
87
87
  const choices = {};
88
+ let changed = false;
88
89
  for (const [key, prevModel] of Object.entries(slices.config.choices)) {
89
90
  const path = [...prevPath, key];
90
91
  let model;
@@ -126,14 +127,18 @@ function traverseSlices(args) {
126
127
  });
127
128
  break;
128
129
  }
130
+ if (!changed && model !== prevModel)
131
+ changed = true;
129
132
  choices[key] = model;
130
133
  }
131
- return {
132
- ...slices,
133
- config: {
134
- ...slices.config,
135
- choices,
136
- },
137
- };
134
+ return changed
135
+ ? {
136
+ ...slices,
137
+ config: {
138
+ ...slices.config,
139
+ choices,
140
+ },
141
+ }
142
+ : slices;
138
143
  }
139
144
  exports.traverseSlices = traverseSlices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "3.11.1",
3
+ "version": "3.11.2-alpha.0",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -262,16 +262,16 @@ export function traverseCustomType<
262
262
  const { customType, onField } = args
263
263
 
264
264
  const json: Record<string, typeof customType.json[string]> = {}
265
+ let changed = false
265
266
  for (const [key, section] of Object.entries(customType.json)) {
266
- json[key] = traverseSection({
267
+ const newSection = traverseSection({
267
268
  path: [key],
268
269
  section,
269
270
  onField,
270
271
  })
272
+ if (!changed && newSection !== section) changed = true
273
+ json[key] = newSection
271
274
  }
272
275
 
273
- return {
274
- ...customType,
275
- json,
276
- }
276
+ return changed ? { ...customType, json } : customType
277
277
  }
@@ -52,7 +52,8 @@ export function traverseSection<
52
52
  }): T {
53
53
  const { path: prevPath, section: prevSection, onField } = args
54
54
 
55
- const section = { ...prevSection }
55
+ const section: T = {} as T
56
+ let changed = false
56
57
  for (const [key, prevModel] of Object.entries(prevSection)) {
57
58
  const path = [...prevPath, key]
58
59
  let model
@@ -84,7 +85,9 @@ export function traverseSection<
84
85
  })
85
86
  break
86
87
  }
88
+ if (!changed && model !== prevModel) changed = true
87
89
  section[key] = model
88
90
  }
89
- return section
91
+
92
+ return changed ? section : prevSection
90
93
  }
@@ -59,22 +59,28 @@ export function traverseNestedGroup(args: {
59
59
  if (!group.config?.fields) return group
60
60
 
61
61
  const fields: Record<string, NestableWidget> = {}
62
- for (const [key, prevField] of Object.entries(group.config.fields)) {
62
+ let changed = false
63
+ for (const [key, field] of Object.entries(group.config.fields)) {
63
64
  const path = [...prevPath, key]
64
- fields[key] = onField({
65
+ const newField = onField({
65
66
  path,
66
67
  key,
67
- field: prevField,
68
+ field,
68
69
  })
69
- }
70
70
 
71
- return {
72
- ...group,
73
- config: {
74
- ...group.config,
75
- fields,
76
- },
71
+ if (!changed && field !== newField) changed = true
72
+ fields[key] = newField
77
73
  }
74
+
75
+ return changed
76
+ ? {
77
+ ...group,
78
+ config: {
79
+ ...group.config,
80
+ fields,
81
+ },
82
+ }
83
+ : group
78
84
  }
79
85
 
80
86
  export function traverseGroup(args: {
@@ -87,6 +93,7 @@ export function traverseGroup(args: {
87
93
  if (!group.config?.fields) return group
88
94
 
89
95
  const fields: Record<string, NestableWidget | NestedGroup> = {}
96
+ let changed = false
90
97
  for (const [key, prevField] of Object.entries(group.config.fields)) {
91
98
  const path = [...prevPath, key]
92
99
  let field
@@ -102,18 +109,23 @@ export function traverseGroup(args: {
102
109
  field = prevField
103
110
  break
104
111
  }
105
- fields[key] = onField({
112
+
113
+ const newField = onField({
106
114
  path,
107
115
  key,
108
116
  field,
109
117
  })
118
+ if (!changed && field !== newField) changed = true
119
+ fields[key] = newField
110
120
  }
111
121
 
112
- return {
113
- ...group,
114
- config: {
115
- ...group.config,
116
- fields,
117
- },
118
- }
122
+ return changed
123
+ ? {
124
+ ...group,
125
+ config: {
126
+ ...group.config,
127
+ fields,
128
+ },
129
+ }
130
+ : group
119
131
  }
@@ -47,20 +47,30 @@ export function traverseCompositeSlice(args: {
47
47
  const { path: prevPath, slice, onField } = args
48
48
 
49
49
  const nonRepeat: Record<string, NestableWidget> = {}
50
+ let nonRepeatChanged = false
50
51
  for (const [key, field] of Object.entries(slice["non-repeat"] ?? {})) {
51
52
  const path = [...prevPath, "non-repeat", key]
52
- nonRepeat[key] = onField({ path, key, field })
53
+ const newField = onField({ path, key, field })
54
+
55
+ if (!nonRepeatChanged && field !== newField) nonRepeatChanged = true
56
+ nonRepeat[key] = newField
53
57
  }
54
58
 
55
59
  const repeat: Record<string, NestableWidget> = {}
60
+ let repeatChanged = false
56
61
  for (const [key, field] of Object.entries(slice.repeat ?? {})) {
57
62
  const path = [...prevPath, "repeat", key]
58
- repeat[key] = onField({ path, key, field })
59
- }
63
+ const newField = onField({ path, key, field })
60
64
 
61
- return {
62
- ...slice,
63
- ...(slice["non-repeat"] && { "non-repeat": nonRepeat }),
64
- ...(slice.repeat && { repeat }),
65
+ if (!repeatChanged && field !== newField) repeatChanged = true
66
+ repeat[key] = newField
65
67
  }
68
+
69
+ return nonRepeatChanged || repeatChanged
70
+ ? {
71
+ ...slice,
72
+ ...(nonRepeatChanged && { "non-repeat": nonRepeat }),
73
+ ...(repeatChanged && { repeat }),
74
+ }
75
+ : slice
66
76
  }
@@ -80,6 +80,7 @@ export function traverseVariation(args: {
80
80
  const { path: prevPath, variation, onField } = args
81
81
 
82
82
  const primary: Record<string, NestableWidget | Group> = {}
83
+ let primaryChanged = false
83
84
  for (const [key, prevField] of Object.entries(variation.primary ?? {})) {
84
85
  const path = [...prevPath, "primary", key]
85
86
  let field
@@ -95,20 +96,32 @@ export function traverseVariation(args: {
95
96
  field = prevField
96
97
  break
97
98
  }
98
- primary[key] = onField({ path, key, field })
99
+
100
+ const newField = onField({ path, key, field })
101
+ if (!primaryChanged && field !== newField) primaryChanged = true
102
+ primary[key] = newField
99
103
  }
100
104
 
101
105
  const items: Record<string, NestableWidget> = {}
102
- for (const [key, field] of Object.entries(variation.items ?? {})) {
106
+ let itemsChanged = false
107
+ for (const [key, prevField] of Object.entries(variation.items ?? {})) {
103
108
  const path = [...prevPath, "items", key]
104
- items[key] = (onField as OnFieldFn<NestableWidget>)({ path, key, field })
109
+ const newField = (onField as OnFieldFn<NestableWidget>)({
110
+ path,
111
+ key,
112
+ field: prevField,
113
+ })
114
+ if (!itemsChanged && prevField !== newField) itemsChanged = true
115
+ items[key] = newField
105
116
  }
106
117
 
107
- return {
108
- ...variation,
109
- ...(variation.primary && { primary }),
110
- ...(variation.items && { items }),
111
- }
118
+ return primaryChanged || itemsChanged
119
+ ? {
120
+ ...variation,
121
+ ...(primaryChanged && { primary }),
122
+ ...(itemsChanged && { items }),
123
+ }
124
+ : variation
112
125
  }
113
126
 
114
127
  export function traverseSharedSlice(args: {
@@ -119,19 +132,23 @@ export function traverseSharedSlice(args: {
119
132
  const { path: prevPath, slice, onField } = args
120
133
 
121
134
  const variations: Variation[] = []
135
+ let changed = false
122
136
  for (const variation of slice.variations) {
123
137
  const path = [...prevPath, variation.id]
124
- variations.push(
125
- traverseVariation({
126
- path,
127
- variation,
128
- onField,
129
- }),
130
- )
138
+ const newVariation = traverseVariation({
139
+ path,
140
+ variation,
141
+ onField,
142
+ })
143
+
144
+ if (!changed && newVariation !== variation) changed = true
145
+ variations.push(newVariation)
131
146
  }
132
147
 
133
- return {
134
- ...slice,
135
- variations,
136
- }
148
+ return changed
149
+ ? {
150
+ ...slice,
151
+ variations,
152
+ }
153
+ : slice
137
154
  }
@@ -124,6 +124,7 @@ export function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
124
124
  if (!slices.config?.choices) return slices
125
125
 
126
126
  const choices: Record<string, typeof slices.config.choices[string]> = {}
127
+ let changed = false
127
128
  for (const [key, prevModel] of Object.entries(slices.config.choices)) {
128
129
  const path = [...prevPath, key]
129
130
  let model
@@ -165,14 +166,17 @@ export function traverseSlices<T extends DynamicSlices | StaticSlices>(args: {
165
166
  break
166
167
  }
167
168
 
169
+ if (!changed && model !== prevModel) changed = true
168
170
  choices[key] = model as typeof slices.config.choices[string]
169
171
  }
170
172
 
171
- return {
172
- ...slices,
173
- config: {
174
- ...slices.config,
175
- choices,
176
- },
177
- }
173
+ return changed
174
+ ? {
175
+ ...slices,
176
+ config: {
177
+ ...slices.config,
178
+ choices,
179
+ },
180
+ }
181
+ : slices
178
182
  }