@prismicio/types-internal 3.10.1 → 3.10.2-alpha.1

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.
@@ -149,68 +149,89 @@ function traverseDocument({ document, customType, }) {
149
149
  ? simplifyCustomType(customType)
150
150
  : customType;
151
151
  return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => {
152
- const fieldModels = model &&
153
- Object.entries(model.fields).reduce((acc, [key, def]) => ({ ...acc, [key]: def }), {});
154
- return Object.entries(document).reduce((acc, [key, content]) => {
155
- const fieldModel = fieldModels && fieldModels[key];
156
- const path = utils_1.ContentPath.make([
157
- { key: model === null || model === void 0 ? void 0 : model.customTypeId, type: "CustomType" },
158
- { key, type: "Widget" },
159
- ]);
160
- const transformedWidget = (() => {
161
- switch (content.__TYPE__) {
162
- case "SliceContentType":
163
- return (0, fields_1.traverseSlices)({
164
- path,
165
- key,
166
- model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Slices" || (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Choice"
167
- ? fieldModel
168
- : undefined,
169
- content,
170
- })({ transformWidget, transformSlice });
171
- case "GroupContentType":
172
- return (0, fields_1.traverseGroupContent)({
173
- path,
174
- key,
175
- apiId: key,
176
- model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
177
- content,
178
- })(transformWidget);
179
- case "RepeatableContent":
180
- return (0, fields_1.traverseRepeatableContent)({
181
- path,
182
- key,
183
- apiId: key,
184
- model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" ? fieldModel : undefined,
185
- content,
186
- })(transformWidget);
187
- case "TableContent":
188
- return (0, fields_1.traverseTableContent)({
189
- path,
190
- key,
191
- apiId: key,
192
- model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Table" ? fieldModel : undefined,
193
- content,
194
- })(transformWidget);
195
- default:
196
- return transformWidget({
197
- path,
198
- key,
199
- apiId: key,
200
- model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Group" &&
201
- (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Slices" &&
202
- (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Choice"
203
- ? fieldModel
204
- : undefined,
205
- content,
206
- });
152
+ let fieldModels = undefined;
153
+ if (model) {
154
+ fieldModels = {};
155
+ const modelKeys = Object.keys(model.fields);
156
+ for (let i = 0; i < modelKeys.length; i++) {
157
+ const key = modelKeys[i];
158
+ if (key) {
159
+ const def = model.fields[key];
160
+ if (def) {
161
+ fieldModels[key] = def;
162
+ }
207
163
  }
208
- })();
209
- return {
210
- ...acc,
211
- ...(transformedWidget ? { [key]: transformedWidget } : {}),
212
- };
213
- }, {});
164
+ }
165
+ }
166
+ const result = {};
167
+ const documentKeys = Object.keys(document);
168
+ for (let i = 0; i < documentKeys.length; i++) {
169
+ const key = documentKeys[i];
170
+ if (key) {
171
+ const content = document[key];
172
+ if (content) {
173
+ const fieldModel = fieldModels && fieldModels[key];
174
+ const path = utils_1.ContentPath.make([
175
+ { key: model === null || model === void 0 ? void 0 : model.customTypeId, type: "CustomType" },
176
+ { key, type: "Widget" },
177
+ ]);
178
+ const transformedWidget = (() => {
179
+ switch (content.__TYPE__) {
180
+ case "SliceContentType":
181
+ return (0, fields_1.traverseSlices)({
182
+ path,
183
+ key,
184
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Slices" ||
185
+ (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Choice"
186
+ ? fieldModel
187
+ : undefined,
188
+ content,
189
+ })({ transformWidget, transformSlice });
190
+ case "GroupContentType":
191
+ return (0, fields_1.traverseGroupContent)({
192
+ path,
193
+ key,
194
+ apiId: key,
195
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Group" ? fieldModel : undefined,
196
+ content,
197
+ })(transformWidget);
198
+ case "RepeatableContent":
199
+ return (0, fields_1.traverseRepeatableContent)({
200
+ path,
201
+ key,
202
+ apiId: key,
203
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Link" ? fieldModel : undefined,
204
+ content,
205
+ })(transformWidget);
206
+ case "TableContent":
207
+ return (0, fields_1.traverseTableContent)({
208
+ path,
209
+ key,
210
+ apiId: key,
211
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) === "Table" ? fieldModel : undefined,
212
+ content,
213
+ })(transformWidget);
214
+ default:
215
+ return transformWidget({
216
+ path,
217
+ key,
218
+ apiId: key,
219
+ model: (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Group" &&
220
+ (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Slices" &&
221
+ (fieldModel === null || fieldModel === void 0 ? void 0 : fieldModel.type) !== "Choice"
222
+ ? fieldModel
223
+ : undefined,
224
+ content,
225
+ });
226
+ }
227
+ })();
228
+ if (transformedWidget) {
229
+ result[key] = transformedWidget;
230
+ }
231
+ }
232
+ }
233
+ }
234
+ return result;
214
235
  };
215
236
  }
216
237
  exports.traverseDocument = traverseDocument;
@@ -1,18 +1,90 @@
1
1
  import * as t from "io-ts";
2
2
  import type { ContentPath, TraverseWidgetContentFn } from "../../_internal/utils";
3
- import type { Link, NestableWidget } from "../../customtypes";
3
+ import { type Link, NestableFieldTypes, NestableWidget } from "../../customtypes";
4
4
  import type { LegacyContentCtx, WithTypes } from "../LegacyContentCtx";
5
+ export declare const RepeatableContentType: "RepeatableContent";
6
+ export declare const RepeatableFieldType: "Repeatable";
7
+ export declare const RepeatableItemContent: t.ExactC<t.TypeC<{
8
+ __TYPE__: t.LiteralC<"LinkContent">;
9
+ value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
10
+ __TYPE__: t.LiteralC<"ImageLink">;
11
+ }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
12
+ kind: t.StringC;
13
+ id: t.StringC;
14
+ url: t.StringC;
15
+ height: t.StringC;
16
+ width: t.StringC;
17
+ size: t.StringC;
18
+ name: t.StringC;
19
+ }>>, t.ExactC<t.PartialC<{
20
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
21
+ }>>]>, t.ExactC<t.PartialC<{
22
+ text: t.StringC;
23
+ }>>]>, t.ExactC<t.TypeC<{
24
+ kind: t.LiteralC<"image">;
25
+ text: t.StringC;
26
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
27
+ __TYPE__: t.LiteralC<"FileLink">;
28
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
29
+ kind: t.StringC;
30
+ id: t.StringC;
31
+ url: t.StringC;
32
+ name: t.StringC;
33
+ size: t.StringC;
34
+ }>, t.PartialC<{
35
+ date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
36
+ }>]>>, t.ExactC<t.PartialC<{
37
+ text: t.StringC;
38
+ }>>]>, t.ExactC<t.TypeC<{
39
+ kind: t.LiteralC<"file">;
40
+ text: t.StringC;
41
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
42
+ __TYPE__: t.LiteralC<"DocumentLink">;
43
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
44
+ id: t.Type<string, string, unknown>;
45
+ }>>, t.ExactC<t.PartialC<{
46
+ text: t.StringC;
47
+ }>>]>, t.ExactC<t.TypeC<{
48
+ kind: t.LiteralC<"document">;
49
+ text: t.StringC;
50
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
51
+ __TYPE__: t.LiteralC<"ExternalLink">;
52
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
53
+ url: t.StringC;
54
+ }>, t.PartialC<{
55
+ kind: t.LiteralC<"web">;
56
+ target: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
57
+ preview: t.UnionC<[t.Type<{
58
+ title?: string;
59
+ }, {
60
+ title?: string;
61
+ }, unknown>, t.NullC, t.UndefinedC]>;
62
+ }>]>>, t.ExactC<t.PartialC<{
63
+ text: t.StringC;
64
+ }>>]>, t.ExactC<t.TypeC<{
65
+ kind: t.LiteralC<"web">;
66
+ text: t.StringC;
67
+ }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
68
+ __TYPE__: t.LiteralC<"MediaLink">;
69
+ }>>, t.ExactC<t.TypeC<{
70
+ kind: t.LiteralC<"media">;
71
+ text: t.StringC;
72
+ }>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
73
+ __TYPE__: t.LiteralC<"AnyLink">;
74
+ }>>, t.ExactC<t.TypeC<{
75
+ text: t.StringC;
76
+ }>>]>]>;
77
+ }>>;
78
+ export declare type RepeatableItemContent = t.TypeOf<typeof RepeatableItemContent>;
5
79
  export declare const RepeatableContent: t.ExactC<t.TypeC<{
6
80
  __TYPE__: t.LiteralC<"RepeatableContent">;
7
- type: t.LiteralC<"Link">;
8
- value: t.ArrayC<t.IntersectionC<[t.ExactC<t.TypeC<{
9
- key: t.Type<string, string, unknown>;
10
- }>>, t.ExactC<t.TypeC<{
81
+ type: t.UnionC<[t.LiteralC<"Color">, t.LiteralC<"Boolean">, t.LiteralC<"Embed">, t.LiteralC<"GeoPoint">, t.LiteralC<"Date">, t.LiteralC<"Number">, t.LiteralC<"Range">, t.LiteralC<"StructuredText">, t.LiteralC<"Select">, t.LiteralC<"Separator">, t.LiteralC<"Text">, t.LiteralC<"Timestamp">, t.LiteralC<"Link">, t.LiteralC<"Image">, t.LiteralC<"IntegrationFields">]>;
82
+ value: t.ArrayC<t.ExactC<t.TypeC<{
11
83
  __TYPE__: t.LiteralC<"LinkContent">;
12
84
  value: t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
13
85
  __TYPE__: t.LiteralC<"ImageLink">;
14
- }>>, t.IntersectionC<[t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
15
- kind: t.Type<"image", "image", unknown>;
86
+ }>>, t.UnionC<[t.IntersectionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
87
+ kind: t.StringC;
16
88
  id: t.StringC;
17
89
  url: t.StringC;
18
90
  height: t.StringC;
@@ -21,35 +93,38 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
21
93
  name: t.StringC;
22
94
  }>>, t.ExactC<t.PartialC<{
23
95
  date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
96
+ }>>]>, t.ExactC<t.PartialC<{
97
+ text: t.StringC;
24
98
  }>>]>, t.ExactC<t.TypeC<{
25
99
  kind: t.LiteralC<"image">;
26
- }>>]>, t.ExactC<t.PartialC<{
27
100
  text: t.StringC;
28
101
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
29
102
  __TYPE__: t.LiteralC<"FileLink">;
30
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
31
- kind: t.Type<"file", "file", unknown>;
103
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
104
+ kind: t.StringC;
32
105
  id: t.StringC;
33
106
  url: t.StringC;
34
107
  name: t.StringC;
35
108
  size: t.StringC;
36
109
  }>, t.PartialC<{
37
110
  date: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
38
- }>]>>, t.ExactC<t.TypeC<{
111
+ }>]>>, t.ExactC<t.PartialC<{
112
+ text: t.StringC;
113
+ }>>]>, t.ExactC<t.TypeC<{
39
114
  kind: t.LiteralC<"file">;
40
- }>>]>, t.ExactC<t.PartialC<{
41
115
  text: t.StringC;
42
116
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
43
117
  __TYPE__: t.LiteralC<"DocumentLink">;
44
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.TypeC<{
118
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.TypeC<{
45
119
  id: t.Type<string, string, unknown>;
46
- }>>, t.ExactC<t.TypeC<{
120
+ }>>, t.ExactC<t.PartialC<{
121
+ text: t.StringC;
122
+ }>>]>, t.ExactC<t.TypeC<{
47
123
  kind: t.LiteralC<"document">;
48
- }>>]>, t.ExactC<t.PartialC<{
49
124
  text: t.StringC;
50
125
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
51
126
  __TYPE__: t.LiteralC<"ExternalLink">;
52
- }>>, t.IntersectionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
127
+ }>>, t.UnionC<[t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
53
128
  url: t.StringC;
54
129
  }>, t.PartialC<{
55
130
  kind: t.LiteralC<"web">;
@@ -59,37 +134,33 @@ export declare const RepeatableContent: t.ExactC<t.TypeC<{
59
134
  }, {
60
135
  title?: string;
61
136
  }, unknown>, t.NullC, t.UndefinedC]>;
62
- }>]>>, t.ExactC<t.TypeC<{
137
+ }>]>>, t.ExactC<t.PartialC<{
138
+ text: t.StringC;
139
+ }>>]>, t.ExactC<t.TypeC<{
63
140
  kind: t.LiteralC<"web">;
64
- }>>]>, t.ExactC<t.PartialC<{
65
141
  text: t.StringC;
66
142
  }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
67
143
  __TYPE__: t.LiteralC<"MediaLink">;
68
- }>>, t.IntersectionC<[t.ExactC<t.TypeC<{
144
+ }>>, t.ExactC<t.TypeC<{
69
145
  kind: t.LiteralC<"media">;
70
- }>>, t.ExactC<t.PartialC<{
71
146
  text: t.StringC;
72
- }>>]>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
147
+ }>>]>, t.IntersectionC<[t.ExactC<t.TypeC<{
73
148
  __TYPE__: t.LiteralC<"AnyLink">;
74
- }>>, t.ExactC<t.IntersectionC<[t.TypeC<{
75
- kind: t.LiteralC<"any">;
76
- }>, t.PartialC<{
149
+ }>>, t.ExactC<t.TypeC<{
77
150
  text: t.StringC;
78
- }>]>>]>]>;
79
- }>>]>>;
151
+ }>>]>]>;
152
+ }>>>;
80
153
  }>>;
81
154
  export declare type RepeatableContent = t.TypeOf<typeof RepeatableContent>;
82
155
  export declare const isRepeatableContent: t.Is<{
83
156
  __TYPE__: "RepeatableContent";
84
- type: "Link";
85
- value: ({
86
- key: string;
87
- } & {
157
+ type: "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp";
158
+ value: {
88
159
  __TYPE__: "LinkContent";
89
160
  value: ({
90
161
  __TYPE__: "ImageLink";
91
- } & ((({
92
- kind: "image";
162
+ } & (({
163
+ kind: string;
93
164
  id: string;
94
165
  url: string;
95
166
  height: string;
@@ -98,41 +169,43 @@ export declare const isRepeatableContent: t.Is<{
98
169
  name: string;
99
170
  } & {
100
171
  date?: string | null | undefined;
172
+ } & {
173
+ text?: string;
101
174
  }) | {
102
175
  kind: "image";
103
- }) & {
104
- text?: string;
176
+ text: string;
105
177
  })) | ({
106
178
  __TYPE__: "FileLink";
107
- } & ((({
108
- kind: "file";
179
+ } & (({
180
+ kind: string;
109
181
  id: string;
110
182
  url: string;
111
183
  name: string;
112
184
  size: string;
113
185
  } & {
114
186
  date?: string | null | undefined;
187
+ } & {
188
+ text?: string;
115
189
  }) | {
116
190
  kind: "file";
117
- }) & {
118
- text?: string;
191
+ text: string;
119
192
  })) | ({
120
193
  __TYPE__: "MediaLink";
121
194
  } & {
122
195
  kind: "media";
123
- } & {
124
- text?: string;
196
+ text: string;
125
197
  }) | ({
126
198
  __TYPE__: "DocumentLink";
127
199
  } & (({
128
200
  id: string;
129
- } | {
130
- kind: "document";
131
- }) & {
201
+ } & {
132
202
  text?: string;
203
+ }) | {
204
+ kind: "document";
205
+ text: string;
133
206
  })) | ({
134
207
  __TYPE__: "ExternalLink";
135
- } & ((({
208
+ } & (({
136
209
  url: string;
137
210
  } & {
138
211
  kind?: "web";
@@ -140,20 +213,19 @@ export declare const isRepeatableContent: t.Is<{
140
213
  preview?: {
141
214
  title?: string;
142
215
  } | null | undefined;
216
+ } & {
217
+ text?: string;
143
218
  }) | {
144
219
  kind: "web";
145
- }) & {
146
- text?: string;
220
+ text: string;
147
221
  })) | ({
148
222
  __TYPE__: "AnyLink";
149
223
  } & {
150
- kind: "any";
151
- } & {
152
- text?: string;
224
+ text: string;
153
225
  });
154
- })[];
226
+ }[];
155
227
  }>;
156
- export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: "Link") => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
228
+ export declare const RepeatableLegacy: (ctx: LegacyContentCtx, fieldType: NestableFieldTypes) => t.Type<RepeatableContent, WithTypes<Array<unknown>>, unknown>;
157
229
  export declare type RepeatableCustomType = Link;
158
230
  export declare function traverseRepeatableContent({ path, key, apiId, model, content, }: {
159
231
  path: ContentPath;
@@ -1,21 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = void 0;
3
+ exports.traverseRepeatableContent = exports.RepeatableLegacy = exports.isRepeatableContent = exports.RepeatableContent = exports.RepeatableItemContent = exports.RepeatableFieldType = exports.RepeatableContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
7
7
  const function_1 = require("fp-ts/lib/function");
8
8
  const t = (0, tslib_1.__importStar)(require("io-ts"));
9
+ const customtypes_1 = require("../../customtypes");
9
10
  const nestable_1 = require("./nestable");
11
+ exports.RepeatableContentType = "RepeatableContent";
12
+ exports.RepeatableFieldType = "Repeatable";
13
+ exports.RepeatableItemContent = nestable_1.LinkContent;
10
14
  exports.RepeatableContent = t.strict({
11
- __TYPE__: t.literal("RepeatableContent"),
12
- type: t.literal("Link"),
13
- value: t.array(nestable_1.LinkContent),
15
+ __TYPE__: t.literal(exports.RepeatableContentType),
16
+ type: customtypes_1.NestableFieldTypes,
17
+ // TODO: How to ensure it's an array of only one type
18
+ value: t.array(exports.RepeatableItemContent),
14
19
  });
15
20
  exports.isRepeatableContent = exports.RepeatableContent.is;
16
21
  const RepeatableLegacy = (ctx, fieldType) => {
22
+ const codecDecode = t.array(t.unknown);
23
+ const codecEncode = t.array(exports.RepeatableItemContent);
17
24
  return new t.Type("RepeatableLegacy", exports.isRepeatableContent, (items) => {
18
- const parsed = (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.map((items) => {
25
+ const parsed = (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((items) => {
19
26
  const parsedItems = items.reduce((acc, item) => {
20
27
  let result;
21
28
  switch (fieldType) {
@@ -32,12 +39,12 @@ const RepeatableLegacy = (ctx, fieldType) => {
32
39
  return {
33
40
  value: parsedItems,
34
41
  type: fieldType,
35
- __TYPE__: "RepeatableContent",
42
+ __TYPE__: exports.RepeatableContentType,
36
43
  };
37
44
  }));
38
45
  return parsed;
39
46
  }, (r) => {
40
- const res = t.array(nestable_1.LinkContent).encode(r.value);
47
+ const res = codecEncode.encode(r.value);
41
48
  const encodedItems = res.reduce((acc, item) => {
42
49
  let encoded;
43
50
  switch (item.__TYPE__) {
@@ -72,9 +79,6 @@ function traverseRepeatableContent({ path, key, apiId, model, content, }) {
72
79
  // Can happen if the transform function returns undefined to filter out a field
73
80
  if (!transformedField)
74
81
  return acc;
75
- // If the transformed field is not a link content, we don't include it
76
- if (!(0, nestable_1.isLinkContent)(transformedField))
77
- return acc;
78
82
  return acc.concat(transformedField);
79
83
  }, []);
80
84
  return transform({
@@ -165,16 +165,23 @@ function collectSharedSlices(customType) {
165
165
  exports.collectSharedSlices = collectSharedSlices;
166
166
  function traverseCustomType(args) {
167
167
  const { customType, onField } = args;
168
- return {
169
- ...customType,
170
- json: Object.entries(customType.json).reduce((acc, [key, section]) => {
171
- acc[key] = (0, Section_1.traverseSection)({
172
- path: [key],
173
- section,
174
- onField,
175
- });
176
- return acc;
177
- }, {}),
178
- };
168
+ const result = { ...customType };
169
+ const newJson = {};
170
+ const keys = Object.keys(customType.json);
171
+ for (let i = 0; i < keys.length; i++) {
172
+ const key = keys[i];
173
+ if (key) {
174
+ const section = customType.json[key];
175
+ if (section) {
176
+ newJson[key] = (0, Section_1.traverseSection)({
177
+ path: [key],
178
+ section,
179
+ onField,
180
+ });
181
+ }
182
+ }
183
+ }
184
+ result.json = newJson;
185
+ return result;
179
186
  }
180
187
  exports.traverseCustomType = traverseCustomType;
@@ -22,39 +22,47 @@ exports.Sections = {
22
22
  };
23
23
  function traverseSection(args) {
24
24
  const { path: prevPath, section, onField } = args;
25
- return Object.entries(section).reduce((acc, [key, prevModel]) => {
26
- const path = prevPath.concat(key);
27
- let model;
28
- switch (prevModel.type) {
29
- case "Choice":
30
- case "Slices":
31
- model = (0, widgets_1.traverseSlices)({
32
- path,
33
- slices: prevModel,
34
- onField: onField,
35
- });
36
- break;
37
- case "Group":
38
- model = onField({
39
- path,
40
- key,
41
- field: (0, widgets_1.traverseGroup)({
42
- path,
43
- group: prevModel,
44
- onField: onField,
45
- }),
46
- });
47
- break;
48
- default:
49
- model = onField({
50
- path,
51
- key,
52
- field: prevModel,
53
- });
54
- break;
25
+ const result = {};
26
+ const keys = Object.keys(section);
27
+ for (let i = 0; i < keys.length; i++) {
28
+ const key = keys[i];
29
+ if (key) {
30
+ const prevModel = section[key];
31
+ if (prevModel) {
32
+ const path = [...prevPath, key];
33
+ let model;
34
+ switch (prevModel.type) {
35
+ case "Choice":
36
+ case "Slices":
37
+ model = (0, widgets_1.traverseSlices)({
38
+ path,
39
+ slices: prevModel,
40
+ onField: onField,
41
+ });
42
+ break;
43
+ case "Group":
44
+ model = onField({
45
+ path,
46
+ key,
47
+ field: (0, widgets_1.traverseGroup)({
48
+ path,
49
+ group: prevModel,
50
+ onField: onField,
51
+ }),
52
+ });
53
+ break;
54
+ default:
55
+ model = onField({
56
+ path,
57
+ key,
58
+ field: prevModel,
59
+ });
60
+ break;
61
+ }
62
+ result[key] = model;
63
+ }
55
64
  }
56
- acc[key] = model;
57
- return acc;
58
- }, {});
65
+ }
66
+ return result;
59
67
  }
60
68
  exports.traverseSection = traverseSection;