@prismicio/types-internal 2.2.0-traverse.alpha-12 → 2.2.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.
Files changed (47) hide show
  1. package/lib/import/converters/Document.js +2 -0
  2. package/lib/import/converters/fields/Group.d.ts +4 -0
  3. package/lib/import/converters/fields/Group.js +14 -0
  4. package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
  5. package/lib/import/converters/fields/RepeatableZone.js +15 -0
  6. package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
  7. package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
  8. package/lib/import/converters/fields/Slices/SharedSliceContent.js +6 -41
  9. package/lib/import/converters/fields/index.d.ts +1 -0
  10. package/lib/import/converters/fields/index.js +1 -0
  11. package/lib/import/validators/fields/ImportField.d.ts +11 -1
  12. package/lib/import/validators/fields/ImportField.js +6 -1
  13. package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
  14. package/lib/import/validators/fields/ImportGroup.js +27 -0
  15. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +5 -3
  16. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +4 -4
  17. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +0 -1
  18. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +0 -1
  19. package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
  20. package/lib/import/validators/fields/RepeatableZone.js +14 -0
  21. package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
  22. package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
  23. package/lib/import/validators/fields/index.d.ts +2 -0
  24. package/lib/import/validators/fields/index.js +2 -0
  25. package/lib/import/validators/fields/nestable/Nestable.d.ts +60 -0
  26. package/lib/import/validators/fields/nestable/Nestable.js +32 -30
  27. package/package.json +1 -1
  28. package/src/import/converters/Document.ts +7 -1
  29. package/src/import/converters/fields/Group.ts +18 -0
  30. package/src/import/converters/fields/RepeatableZone.ts +19 -0
  31. package/src/import/converters/fields/RepeatableZoneItem.ts +32 -0
  32. package/src/import/converters/fields/Slices/SharedSliceContent.ts +9 -76
  33. package/src/import/converters/fields/index.ts +1 -0
  34. package/src/import/validators/fields/ImportField.ts +7 -2
  35. package/src/import/validators/fields/ImportGroup.ts +45 -0
  36. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +6 -18
  37. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +0 -1
  38. package/src/import/validators/fields/RepeatableZone.ts +21 -0
  39. package/src/import/validators/fields/RepeatableZoneItem.ts +64 -0
  40. package/src/import/validators/fields/index.ts +2 -0
  41. package/src/import/validators/fields/nestable/Nestable.ts +34 -31
  42. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +0 -64
  43. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +0 -100
  44. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +0 -10
  45. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +0 -2
  46. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +0 -1
  47. package/src/utils/io-ts.ts +0 -29
@@ -0,0 +1,345 @@
1
+ import * as t from "io-ts";
2
+ export declare const ImportGroupValue: (groupCustomType?: ({
3
+ type: "Group";
4
+ } & {
5
+ fieldset?: string | null | undefined;
6
+ icon?: string;
7
+ description?: string;
8
+ config?: {
9
+ label?: string | null | undefined;
10
+ repeat?: boolean;
11
+ fields?: {
12
+ [x: string]: ({
13
+ type: "Boolean";
14
+ } & {
15
+ config?: {
16
+ label?: string | null | undefined;
17
+ default_value?: boolean;
18
+ placeholder_true?: string;
19
+ placeholder_false?: string;
20
+ };
21
+ }) | ({
22
+ type: "Color";
23
+ } & {
24
+ fieldset?: string | null | undefined;
25
+ config?: {
26
+ label?: string | null | undefined;
27
+ placeholder?: string;
28
+ };
29
+ }) | ({
30
+ type: "Date";
31
+ } & {
32
+ fieldset?: string | null | undefined;
33
+ config?: {
34
+ label?: string | null | undefined;
35
+ placeholder?: string;
36
+ default?: string;
37
+ };
38
+ }) | ({
39
+ type: "Embed";
40
+ } & {
41
+ fieldset?: string | null | undefined;
42
+ config?: {
43
+ label?: string | null | undefined;
44
+ placeholder?: string;
45
+ useAsTitle?: boolean;
46
+ };
47
+ }) | ({
48
+ type: "GeoPoint";
49
+ } & {
50
+ fieldset?: string | null | undefined;
51
+ config?: {
52
+ label?: string | null | undefined;
53
+ };
54
+ }) | ({
55
+ type: "Image";
56
+ } & {
57
+ fieldset?: string | null | undefined;
58
+ config?: {
59
+ label?: string | null | undefined;
60
+ placeholder?: string;
61
+ constraint?: {
62
+ width?: number | null;
63
+ height?: number | null;
64
+ };
65
+ thumbnails?: readonly ({
66
+ name: string;
67
+ } & {
68
+ width?: number | null;
69
+ height?: number | null;
70
+ })[];
71
+ };
72
+ }) | ({
73
+ type: "IntegrationFields";
74
+ } & {
75
+ fieldset?: string | null | undefined;
76
+ config?: {
77
+ label?: string | null | undefined;
78
+ placeholder?: string;
79
+ catalog?: string;
80
+ };
81
+ }) | ({
82
+ type: "Link";
83
+ } & {
84
+ fieldset?: string | null | undefined;
85
+ config?: {
86
+ label?: string | null | undefined;
87
+ useAsTitle?: boolean;
88
+ placeholder?: string;
89
+ select?: "media" | "document" | "web" | null;
90
+ customtypes?: readonly string[];
91
+ masks?: readonly string[];
92
+ tags?: readonly string[];
93
+ allowTargetBlank?: boolean;
94
+ };
95
+ }) | ({
96
+ type: "Number";
97
+ } & {
98
+ fieldset?: string | null | undefined;
99
+ config?: {
100
+ label?: string | null | undefined;
101
+ placeholder?: string;
102
+ min?: number;
103
+ max?: number;
104
+ step?: number;
105
+ };
106
+ }) | ({
107
+ type: "Range";
108
+ } & {
109
+ fieldset?: string | null | undefined;
110
+ config?: {
111
+ label?: string | null | undefined;
112
+ placeholder?: string;
113
+ min?: number;
114
+ max?: number;
115
+ step?: number;
116
+ };
117
+ }) | ({
118
+ type: "StructuredText";
119
+ } & {
120
+ fieldset?: string | null | undefined;
121
+ config?: {
122
+ label?: string | null | undefined;
123
+ placeholder?: string;
124
+ useAsTitle?: boolean;
125
+ single?: string;
126
+ multi?: string;
127
+ imageConstraint?: {
128
+ width?: number | null;
129
+ height?: number | null;
130
+ };
131
+ labels?: readonly string[];
132
+ allowTargetBlank?: boolean;
133
+ };
134
+ }) | ({
135
+ type: "Select";
136
+ } & {
137
+ fieldset?: string | null | undefined;
138
+ config?: {
139
+ label?: string | null | undefined;
140
+ placeholder?: string;
141
+ default_value?: string;
142
+ options?: readonly string[];
143
+ };
144
+ }) | ({
145
+ type: "Separator";
146
+ } & {
147
+ config?: {
148
+ label?: string | null | undefined;
149
+ };
150
+ }) | ({
151
+ type: "Text";
152
+ } & {
153
+ fieldset?: string | null | undefined;
154
+ config?: {
155
+ label?: string | null | undefined;
156
+ useAsTitle?: boolean;
157
+ placeholder?: string;
158
+ };
159
+ }) | ({
160
+ type: "Timestamp";
161
+ } & {
162
+ fieldset?: string | null | undefined;
163
+ config?: {
164
+ label?: string | null | undefined;
165
+ placeholder?: string;
166
+ default?: string;
167
+ };
168
+ });
169
+ };
170
+ };
171
+ }) | undefined) => t.Type<import("./RepeatableZoneItem").RepeatableZoneItem[], import("./RepeatableZoneItem").RepeatableZoneItem[], unknown>;
172
+ export declare const ImportGroup: (groupCustomType?: ({
173
+ type: "Group";
174
+ } & {
175
+ fieldset?: string | null | undefined;
176
+ icon?: string;
177
+ description?: string;
178
+ config?: {
179
+ label?: string | null | undefined;
180
+ repeat?: boolean;
181
+ fields?: {
182
+ [x: string]: ({
183
+ type: "Boolean";
184
+ } & {
185
+ config?: {
186
+ label?: string | null | undefined;
187
+ default_value?: boolean;
188
+ placeholder_true?: string;
189
+ placeholder_false?: string;
190
+ };
191
+ }) | ({
192
+ type: "Color";
193
+ } & {
194
+ fieldset?: string | null | undefined;
195
+ config?: {
196
+ label?: string | null | undefined;
197
+ placeholder?: string;
198
+ };
199
+ }) | ({
200
+ type: "Date";
201
+ } & {
202
+ fieldset?: string | null | undefined;
203
+ config?: {
204
+ label?: string | null | undefined;
205
+ placeholder?: string;
206
+ default?: string;
207
+ };
208
+ }) | ({
209
+ type: "Embed";
210
+ } & {
211
+ fieldset?: string | null | undefined;
212
+ config?: {
213
+ label?: string | null | undefined;
214
+ placeholder?: string;
215
+ useAsTitle?: boolean;
216
+ };
217
+ }) | ({
218
+ type: "GeoPoint";
219
+ } & {
220
+ fieldset?: string | null | undefined;
221
+ config?: {
222
+ label?: string | null | undefined;
223
+ };
224
+ }) | ({
225
+ type: "Image";
226
+ } & {
227
+ fieldset?: string | null | undefined;
228
+ config?: {
229
+ label?: string | null | undefined;
230
+ placeholder?: string;
231
+ constraint?: {
232
+ width?: number | null;
233
+ height?: number | null;
234
+ };
235
+ thumbnails?: readonly ({
236
+ name: string;
237
+ } & {
238
+ width?: number | null;
239
+ height?: number | null;
240
+ })[];
241
+ };
242
+ }) | ({
243
+ type: "IntegrationFields";
244
+ } & {
245
+ fieldset?: string | null | undefined;
246
+ config?: {
247
+ label?: string | null | undefined;
248
+ placeholder?: string;
249
+ catalog?: string;
250
+ };
251
+ }) | ({
252
+ type: "Link";
253
+ } & {
254
+ fieldset?: string | null | undefined;
255
+ config?: {
256
+ label?: string | null | undefined;
257
+ useAsTitle?: boolean;
258
+ placeholder?: string;
259
+ select?: "media" | "document" | "web" | null;
260
+ customtypes?: readonly string[];
261
+ masks?: readonly string[];
262
+ tags?: readonly string[];
263
+ allowTargetBlank?: boolean;
264
+ };
265
+ }) | ({
266
+ type: "Number";
267
+ } & {
268
+ fieldset?: string | null | undefined;
269
+ config?: {
270
+ label?: string | null | undefined;
271
+ placeholder?: string;
272
+ min?: number;
273
+ max?: number;
274
+ step?: number;
275
+ };
276
+ }) | ({
277
+ type: "Range";
278
+ } & {
279
+ fieldset?: string | null | undefined;
280
+ config?: {
281
+ label?: string | null | undefined;
282
+ placeholder?: string;
283
+ min?: number;
284
+ max?: number;
285
+ step?: number;
286
+ };
287
+ }) | ({
288
+ type: "StructuredText";
289
+ } & {
290
+ fieldset?: string | null | undefined;
291
+ config?: {
292
+ label?: string | null | undefined;
293
+ placeholder?: string;
294
+ useAsTitle?: boolean;
295
+ single?: string;
296
+ multi?: string;
297
+ imageConstraint?: {
298
+ width?: number | null;
299
+ height?: number | null;
300
+ };
301
+ labels?: readonly string[];
302
+ allowTargetBlank?: boolean;
303
+ };
304
+ }) | ({
305
+ type: "Select";
306
+ } & {
307
+ fieldset?: string | null | undefined;
308
+ config?: {
309
+ label?: string | null | undefined;
310
+ placeholder?: string;
311
+ default_value?: string;
312
+ options?: readonly string[];
313
+ };
314
+ }) | ({
315
+ type: "Separator";
316
+ } & {
317
+ config?: {
318
+ label?: string | null | undefined;
319
+ };
320
+ }) | ({
321
+ type: "Text";
322
+ } & {
323
+ fieldset?: string | null | undefined;
324
+ config?: {
325
+ label?: string | null | undefined;
326
+ useAsTitle?: boolean;
327
+ placeholder?: string;
328
+ };
329
+ }) | ({
330
+ type: "Timestamp";
331
+ } & {
332
+ fieldset?: string | null | undefined;
333
+ config?: {
334
+ label?: string | null | undefined;
335
+ placeholder?: string;
336
+ default?: string;
337
+ };
338
+ });
339
+ };
340
+ };
341
+ }) | undefined) => t.Type<{
342
+ type: "Group";
343
+ value: import("./RepeatableZoneItem").RepeatableZoneItem[] | null;
344
+ }, import("./RepeatableZoneItem").RepeatableZoneItem[] | undefined, unknown>;
345
+ export declare type ImportGroup = t.TypeOf<ReturnType<typeof ImportGroup>>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportGroup = exports.ImportGroupValue = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const validators_1 = require("../../../validators");
9
+ const function_2 = require("../../../validators/function");
10
+ const ImportContent_1 = require("./ImportContent");
11
+ const RepeatableZone_1 = require("./RepeatableZone");
12
+ const ImportGroupValue = (groupCustomType) => {
13
+ var _a, _b;
14
+ const fieldsModel = (_b = (_a = groupCustomType === null || groupCustomType === void 0 ? void 0 : groupCustomType.config) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : {};
15
+ const groupArrayCodec = (0, RepeatableZone_1.RepeatableZone)(fieldsModel);
16
+ return (0, function_2.withCustomError)(new t.Type(groupArrayCodec.name, groupArrayCodec.is, (u, c) => (0, function_1.pipe)(groupArrayCodec.validate(u, c), E.chain((groups) => {
17
+ var _a;
18
+ if (((_a = groupCustomType === null || groupCustomType === void 0 ? void 0 : groupCustomType.config) === null || _a === void 0 ? void 0 : _a.repeat) === false &&
19
+ groups.length > 1) {
20
+ return t.failure(groups, c, "The custom type for this group field does not allow multiple group items");
21
+ }
22
+ return t.success(groups);
23
+ })), t.identity), () => "The group field value must be an array");
24
+ };
25
+ exports.ImportGroupValue = ImportGroupValue;
26
+ const ImportGroup = (groupCustomType) => (0, ImportContent_1.ImportContent)("Group", (0, validators_1.EmptyArrayOrElse)((0, exports.ImportGroupValue)(groupCustomType)));
27
+ exports.ImportGroup = ImportGroup;
@@ -1,13 +1,15 @@
1
1
  import * as t from "io-ts";
2
2
  import type { SharedSlice as SharedSliceCustomType } from "../../../../../customtypes";
3
- import { SharedSliceContent, SharedSliceId } from "./fields";
3
+ import { RepeatableZone } from "../../RepeatableZone";
4
+ import { RepeatableZoneItem } from "../../RepeatableZoneItem";
5
+ import { SharedSliceId } from "./fields";
4
6
  export declare type SharedSlice = {
5
7
  id: SharedSliceId | null | undefined;
6
8
  slice_type: string;
7
9
  name: string;
8
10
  variation: string;
9
- primary: SharedSliceContent | null | undefined;
10
- items: SharedSliceContent[] | null | undefined;
11
+ primary: RepeatableZoneItem | null | undefined;
12
+ items: RepeatableZone | null | undefined;
11
13
  slice_label: string | null | undefined;
12
14
  version: string | null | undefined;
13
15
  };
@@ -6,7 +6,8 @@ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
6
  const function_1 = require("fp-ts/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
8
  const validators_1 = require("../../../../../validators");
9
- const function_2 = require("../../../../../validators/function");
9
+ const RepeatableZone_1 = require("../../RepeatableZone");
10
+ const RepeatableZoneItem_1 = require("../../RepeatableZoneItem");
10
11
  const fields_1 = require("./fields");
11
12
  const SharedSliceShape = t.strict({
12
13
  id: fields_1.OptionalSharedSliceId,
@@ -43,9 +44,8 @@ t
43
44
  // We validate the 'primary' and 'items' content fields, for which we need the Variation custom type retrieved in the previous step
44
45
  t
45
46
  .partial({
46
- primary: (0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "primary", (_a = decoded.variation.data.primary) !== null && _a !== void 0 ? _a : {}),
47
- // We need to use this wrapper codec instead of using t.array(SharedSliceContent) directly in order to get proper custom error messages
48
- items: (0, function_2.withCustomError)(t.array((0, fields_1.SharedSliceContent)(decoded.slice_type.slice_type, "items", (_b = decoded.variation.data.items) !== null && _b !== void 0 ? _b : {})), () => "The value must be an array"),
47
+ primary: (0, RepeatableZoneItem_1.RepeatableZoneItem)((_a = decoded.variation.data.primary) !== null && _a !== void 0 ? _a : {}),
48
+ items: (0, RepeatableZone_1.RepeatableZone)((_b = decoded.variation.data.items) !== null && _b !== void 0 ? _b : {}),
49
49
  })
50
50
  .validate(u, c), E.map(({ primary, items }) => ({ ...decoded, primary, items })));
51
51
  }), E.map(({ id, slice_type, variation, primary, items, slice_label, version, }) => ({
@@ -1,5 +1,4 @@
1
1
  export * from "./OptionalSharedSliceId";
2
- export * from "./SharedSliceContent";
3
2
  export * from "./SharedSliceId";
4
3
  export * from "./SharedSliceType";
5
4
  export * from "./SharedSliceVariation";
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./OptionalSharedSliceId"), exports);
5
- (0, tslib_1.__exportStar)(require("./SharedSliceContent"), exports);
6
5
  (0, tslib_1.__exportStar)(require("./SharedSliceId"), exports);
7
6
  (0, tslib_1.__exportStar)(require("./SharedSliceType"), exports);
8
7
  (0, tslib_1.__exportStar)(require("./SharedSliceVariation"), exports);
@@ -0,0 +1,11 @@
1
+ import * as t from "io-ts";
2
+ import type { WidgetKey } from "../../../common";
3
+ import type { NestableWidget } from "../../../customtypes";
4
+ import { RepeatableZoneItem } from "./RepeatableZoneItem";
5
+ export declare type RepeatableZone = t.TypeOf<ReturnType<typeof RepeatableZone>>;
6
+ /**
7
+ * A custom type for a repeatable zone. This type of structure can be found 'items' field of a slice or in the group field.
8
+ *
9
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
10
+ */
11
+ export declare const RepeatableZone: (fieldModels: Record<WidgetKey, NestableWidget>) => t.ArrayC<t.Type<RepeatableZoneItem, RepeatableZoneItem, unknown>>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepeatableZone = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../../../validators/function");
7
+ const RepeatableZoneItem_1 = require("./RepeatableZoneItem");
8
+ /**
9
+ * A custom type for a repeatable zone. This type of structure can be found 'items' field of a slice or in the group field.
10
+ *
11
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
12
+ */
13
+ const RepeatableZone = (fieldModels) => (0, function_1.withCustomError)(t.array((0, RepeatableZoneItem_1.RepeatableZoneItem)(fieldModels)), () => "The repeatable zone value must be an array");
14
+ exports.RepeatableZone = RepeatableZone;
@@ -0,0 +1,11 @@
1
+ import * as t from "io-ts";
2
+ import { WidgetKey } from "../../../common";
3
+ import type { NestableWidget } from "../../../customtypes";
4
+ import { ImportNestable } from "./nestable";
5
+ export declare type RepeatableZoneItem = Record<WidgetKey, ImportNestable>;
6
+ /**
7
+ * A custom type for an item of a repeatable zone. This type of structure can be found in the 'primary' and 'items' fields of a slice or in the group field.
8
+ *
9
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
10
+ */
11
+ export declare const RepeatableZoneItem: (fieldModels: Record<WidgetKey, NestableWidget>) => t.Type<RepeatableZoneItem, RepeatableZoneItem, unknown>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RepeatableZoneItem = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const common_1 = require("../../../common");
9
+ const function_2 = require("../../../validators/function");
10
+ const nestable_1 = require("./nestable");
11
+ /**
12
+ * A custom type for an item of a repeatable zone. This type of structure can be found in the 'primary' and 'items' fields of a slice or in the group field.
13
+ *
14
+ * @param fieldModels a record of all nestable widgets that can be used in the zone
15
+ */
16
+ const RepeatableZoneItem = (fieldModels) => new t.Type("RepeatableZoneItem", (u) => t.record(common_1.WidgetKey, t.unknown).is(u) &&
17
+ Object.values(u).reduce((acc, value) => acc && nestable_1.ImportNestable.is(value), true), (u, c) => {
18
+ const codecEntries = Object.entries(fieldModels).map(([key, model]) => [key, nestable_1.ImportNestable.getCodec(model)]);
19
+ const groupCodec = (0, function_2.withCustomError)(t.partial({
20
+ ...Object.fromEntries(codecEntries),
21
+ }), () => "The value must be an object");
22
+ return (0, function_1.pipe)(groupCodec.validate(u, c), E.chain((decodedContent) => {
23
+ // Validate if all fields are present in the model
24
+ const keys = Object.keys(decodedContent);
25
+ const errors = keys.flatMap((key) => fieldModels[key]
26
+ ? []
27
+ : [
28
+ {
29
+ value: decodedContent[key],
30
+ context: c,
31
+ message: `The field '${key}' is not defined in the custom type`,
32
+ },
33
+ ]);
34
+ return errors.length > 0
35
+ ? t.failures(errors)
36
+ : t.success(decodedContent); // We can never have a key with decoded value 'undefined' so we can ignore the type derived from t.partial
37
+ }));
38
+ }, t.identity);
39
+ exports.RepeatableZoneItem = RepeatableZoneItem;
@@ -1,2 +1,4 @@
1
1
  export * from "./nestable";
2
+ export * from "./RepeatableZone";
3
+ export * from "./RepeatableZoneItem";
2
4
  export * from "./UID";
@@ -2,4 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  (0, tslib_1.__exportStar)(require("./nestable"), exports);
5
+ (0, tslib_1.__exportStar)(require("./RepeatableZone"), exports);
6
+ (0, tslib_1.__exportStar)(require("./RepeatableZoneItem"), exports);
5
7
  (0, tslib_1.__exportStar)(require("./UID"), exports);
@@ -129,4 +129,64 @@ export declare const ImportNestable: {
129
129
  value: boolean | null;
130
130
  }>;
131
131
  };
132
+ getCodec: (field: NestableWidget) => import("io-ts").Type<{
133
+ type: "Boolean";
134
+ value: boolean | null;
135
+ }, boolean | undefined, unknown> | import("io-ts").Type<{
136
+ type: "Color";
137
+ value: `#${string}` | null;
138
+ }, string | undefined, unknown> | import("io-ts").Type<{
139
+ type: "Date";
140
+ value: Date | null;
141
+ }, Date | undefined, unknown> | import("io-ts").Type<{
142
+ type: "Embed";
143
+ value: {
144
+ embed_url: string;
145
+ } | null;
146
+ }, {
147
+ embed_url: string;
148
+ } | undefined, unknown> | import("io-ts").Type<{
149
+ type: "GeoPoint";
150
+ value: {
151
+ latitude: number;
152
+ longitude: number;
153
+ } | null;
154
+ }, {
155
+ latitude: number;
156
+ longitude: number;
157
+ } | undefined, unknown> | import("io-ts").Type<{
158
+ type: "Image";
159
+ value: import("./Image").ImageFieldWithThumbnails | null;
160
+ }, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
161
+ type: "Link";
162
+ value: ({
163
+ link_type: "Web";
164
+ url: string;
165
+ } & {
166
+ target?: string;
167
+ }) | {
168
+ link_type: "Document";
169
+ id: string;
170
+ } | {
171
+ link_type: "Media";
172
+ id: string;
173
+ } | null;
174
+ }, {
175
+ link_type: "Document" | "Web" | "Media";
176
+ } | undefined, unknown> | import("io-ts").Type<{
177
+ type: "StructuredText";
178
+ value: import("./ImportRichText").ImportBlock[] | null;
179
+ }, import("./ImportRichText").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
180
+ type: "Number";
181
+ value: number | null;
182
+ }, number | undefined, unknown> | import("io-ts").Type<{
183
+ type: "Select";
184
+ value: string | null;
185
+ }, string | undefined, unknown> | import("io-ts").Type<{
186
+ type: "Text";
187
+ value: string | null;
188
+ }, string | undefined, unknown> | import("io-ts").Type<{
189
+ type: "Timestamp";
190
+ value: Date | null;
191
+ }, Date | undefined, unknown>;
132
192
  };
@@ -13,6 +13,36 @@ const Number_1 = require("./Number");
13
13
  const Select_1 = require("./Select");
14
14
  const Text_1 = require("./Text");
15
15
  const Timestamp_1 = require("./Timestamp");
16
+ const getCodecOrThrow = (field) => {
17
+ switch (field.type) {
18
+ case "Boolean":
19
+ return Boolean_1.ImportBoolean;
20
+ case "Color":
21
+ return Color_1.ImportColor;
22
+ case "Number":
23
+ return (0, Number_1.ImportNumber)(field);
24
+ case "Select":
25
+ return (0, Select_1.ImportSelect)(field);
26
+ case "Text":
27
+ return Text_1.ImportText;
28
+ case "Date":
29
+ return Date_1.ImportDate;
30
+ case "Timestamp":
31
+ return Timestamp_1.ImportTimestamp;
32
+ case "Embed":
33
+ return Embed_1.ImportEmbed;
34
+ case "Link":
35
+ return Link_1.ImportLink;
36
+ case "Image":
37
+ return (0, Image_1.ImportImage)(field);
38
+ case "GeoPoint":
39
+ return GeoPoint_1.ImportGeoPoint;
40
+ case "StructuredText":
41
+ return (0, ImportRichText_1.ImportRichText)(field);
42
+ default:
43
+ throw new Error(`Unsupported type of nestable field ${field.type}`);
44
+ }
45
+ };
16
46
  exports.ImportNestable = {
17
47
  is(u) {
18
48
  return (Boolean_1.ImportBoolean.is(u) ||
@@ -30,40 +60,12 @@ exports.ImportNestable = {
30
60
  },
31
61
  decode: (field) => {
32
62
  return (content) => {
33
- const codec = (() => {
34
- switch (field.type) {
35
- case "Boolean":
36
- return Boolean_1.ImportBoolean;
37
- case "Color":
38
- return Color_1.ImportColor;
39
- case "Number":
40
- return (0, Number_1.ImportNumber)(field);
41
- case "Select":
42
- return (0, Select_1.ImportSelect)(field);
43
- case "Text":
44
- return Text_1.ImportText;
45
- case "Date":
46
- return Date_1.ImportDate;
47
- case "Timestamp":
48
- return Timestamp_1.ImportTimestamp;
49
- case "Embed":
50
- return Embed_1.ImportEmbed;
51
- case "Link":
52
- return Link_1.ImportLink;
53
- case "Image":
54
- return (0, Image_1.ImportImage)(field);
55
- case "GeoPoint":
56
- return GeoPoint_1.ImportGeoPoint;
57
- case "StructuredText":
58
- return (0, ImportRichText_1.ImportRichText)(field);
59
- default:
60
- throw new Error(`Unsupported type of nestable field ${field.type}`);
61
- }
62
- })();
63
+ const codec = getCodecOrThrow(field);
63
64
  return {
64
65
  codec,
65
66
  result: codec.decode(content),
66
67
  };
67
68
  };
68
69
  },
70
+ getCodec: getCodecOrThrow,
69
71
  };