@prismicio/types-internal 3.11.2 → 3.12.0-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.
- package/CHANGELOG.md +764 -0
- package/lib/content/Document.d.ts +32 -7
- package/lib/content/Document.js +22 -8
- package/lib/content/LegacyContentCtx.d.ts +25 -3
- package/lib/content/LegacyContentCtx.js +67 -5
- package/lib/content/fields/GroupContent.d.ts +4 -2
- package/lib/content/fields/GroupContent.js +40 -17
- package/lib/content/fields/UIDContent.js +1 -0
- package/lib/content/fields/WidgetContent.d.ts +6 -0
- package/lib/content/fields/nestable/BooleanContent.js +1 -0
- package/lib/content/fields/nestable/EmbedContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/ColorContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/DateContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/NumberContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/RangeContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/TextContent.js +1 -0
- package/lib/content/fields/nestable/FieldContent/TimestampContent.js +1 -0
- package/lib/content/fields/nestable/GeoPointContent.js +1 -0
- package/lib/content/fields/nestable/ImageContent.js +1 -0
- package/lib/content/fields/nestable/IntegrationFieldContent.js +1 -0
- package/lib/content/fields/nestable/LinkContent.js +2 -0
- package/lib/content/fields/nestable/RepeatableContent.js +1 -0
- package/lib/content/fields/nestable/RichTextContent/index.js +1 -0
- package/lib/content/fields/nestable/SeparatorContent.js +1 -0
- package/lib/content/fields/nestable/TableContent.js +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +3 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +19 -5
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -4
- package/lib/content/fields/slices/Slice/RepeatableContent.js +2 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +3 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -19
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +1 -0
- package/lib/content/fields/slices/Slice/index.d.ts +4 -0
- package/lib/content/fields/slices/SliceItem.d.ts +12 -0
- package/lib/content/fields/slices/SliceItem.js +11 -2
- package/lib/content/fields/slices/SlicesContent.d.ts +6 -0
- package/lib/content/fields/slices/SlicesContent.js +1 -0
- package/lib/customtypes/CustomType.js +6 -9
- package/lib/customtypes/Section.js +3 -8
- package/lib/customtypes/widgets/Group.js +20 -20
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.d.ts +3 -0
- package/lib/customtypes/widgets/nestable/NestableWidgetZ.js +29 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +9 -22
- package/lib/customtypes/widgets/slices/SharedSlice.js +18 -37
- package/lib/customtypes/widgets/slices/SharedSliceZ.d.ts +16 -0
- package/lib/customtypes/widgets/slices/SharedSliceZ.js +39 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.d.ts +3 -0
- package/lib/customtypes/widgets/slices/SlicePrimaryWidgetZ.js +6 -0
- package/lib/customtypes/widgets/slices/Slices.js +9 -16
- package/package.json +1 -1
- package/src/content/Document.ts +31 -8
- package/src/content/LegacyContentCtx.ts +72 -16
- package/src/content/fields/GroupContent.ts +58 -16
- package/src/content/fields/UIDContent.ts +1 -0
- package/src/content/fields/nestable/BooleanContent.ts +1 -0
- package/src/content/fields/nestable/EmbedContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/ColorContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/DateContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/NumberContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/RangeContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/TextContent.ts +1 -0
- package/src/content/fields/nestable/FieldContent/TimestampContent.ts +1 -0
- package/src/content/fields/nestable/GeoPointContent.ts +1 -0
- package/src/content/fields/nestable/ImageContent.ts +1 -0
- package/src/content/fields/nestable/IntegrationFieldContent.ts +1 -0
- package/src/content/fields/nestable/LinkContent.ts +2 -0
- package/src/content/fields/nestable/RepeatableContent.ts +4 -0
- package/src/content/fields/nestable/RichTextContent/index.ts +1 -0
- package/src/content/fields/nestable/SeparatorContent.ts +1 -0
- package/src/content/fields/nestable/TableContent.ts +1 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +19 -5
- package/src/content/fields/slices/Slice/RepeatableContent.ts +7 -2
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +26 -19
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +1 -0
- package/src/content/fields/slices/SliceItem.ts +12 -3
- package/src/content/fields/slices/SlicesContent.ts +4 -1
- package/src/customtypes/CustomType.ts +6 -9
- package/src/customtypes/Section.ts +3 -9
- package/src/customtypes/widgets/Group.ts +20 -21
- package/src/customtypes/widgets/slices/CompositeSlice.ts +9 -22
- package/src/customtypes/widgets/slices/SharedSlice.ts +23 -38
- package/src/customtypes/widgets/slices/Slices.ts +9 -15
- package/lib/content/fields/RepeatableContent.d.ts +0 -162
- package/lib/content/fields/RepeatableContent.js +0 -93
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
- package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
|
@@ -9,7 +9,10 @@ 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;
|
|
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
|
+
*/
|
|
13
16
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
14
17
|
embed_url: t.StringC;
|
|
15
18
|
type: t.StringC;
|
|
@@ -783,7 +786,10 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
|
|
|
783
786
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
784
787
|
}>>, t.ExactC<t.TypeC<{
|
|
785
788
|
__TYPE__: t.LiteralC<"BooleanContent">;
|
|
786
|
-
value: t.BooleanC;
|
|
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
|
+
*/
|
|
787
793
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
788
794
|
embed_url: t.StringC;
|
|
789
795
|
type: t.StringC;
|
|
@@ -1544,12 +1550,16 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
|
|
|
1544
1550
|
}>>]>>;
|
|
1545
1551
|
repeat: t.ArrayC<t.ExactC<t.TypeC<{
|
|
1546
1552
|
__TYPE__: t.LiteralC<"GroupItemContent">;
|
|
1553
|
+
key: t.StringC;
|
|
1547
1554
|
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
1548
1555
|
type: t.StringC;
|
|
1549
1556
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
1550
1557
|
}>>, t.ExactC<t.TypeC<{
|
|
1551
1558
|
__TYPE__: t.LiteralC<"BooleanContent">;
|
|
1552
|
-
value: t.BooleanC;
|
|
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
1563
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
1554
1564
|
embed_url: t.StringC;
|
|
1555
1565
|
type: t.StringC;
|
|
@@ -2317,7 +2327,10 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
|
|
|
2317
2327
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
2318
2328
|
}>>, t.ExactC<t.TypeC<{
|
|
2319
2329
|
__TYPE__: t.LiteralC<"BooleanContent">;
|
|
2320
|
-
value: t.BooleanC;
|
|
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
2334
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
2322
2335
|
embed_url: t.StringC;
|
|
2323
2336
|
type: t.StringC;
|
|
@@ -3078,12 +3091,16 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
|
|
|
3078
3091
|
}>>]>, t.Type<import("./fields").GroupContent, import("./fields").GroupContent, unknown>]>>;
|
|
3079
3092
|
items: t.ArrayC<t.ExactC<t.TypeC<{
|
|
3080
3093
|
__TYPE__: t.LiteralC<"GroupItemContent">;
|
|
3094
|
+
key: t.StringC;
|
|
3081
3095
|
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
3082
3096
|
type: t.StringC;
|
|
3083
3097
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
3084
3098
|
}>>, t.ExactC<t.TypeC<{
|
|
3085
3099
|
__TYPE__: t.LiteralC<"BooleanContent">;
|
|
3086
|
-
value: t.BooleanC;
|
|
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
|
+
*/
|
|
3087
3104
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3088
3105
|
embed_url: t.StringC;
|
|
3089
3106
|
type: t.StringC;
|
|
@@ -3848,7 +3865,10 @@ export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.Unio
|
|
|
3848
3865
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
3849
3866
|
}>>, t.ExactC<t.TypeC<{
|
|
3850
3867
|
__TYPE__: t.LiteralC<"BooleanContent">;
|
|
3851
|
-
value: t.BooleanC;
|
|
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
|
+
*/
|
|
3852
3872
|
}>>, t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3853
3873
|
embed_url: t.StringC;
|
|
3854
3874
|
type: t.StringC;
|
|
@@ -4617,6 +4637,7 @@ declare function extractMetadata(data: {
|
|
|
4617
4637
|
}): {
|
|
4618
4638
|
types: Map<string, FieldOrSliceType>;
|
|
4619
4639
|
widgets: Partial<Record<WidgetKey, unknown>>;
|
|
4640
|
+
keys: Map<string, string>;
|
|
4620
4641
|
slugs: ReadonlyArray<string>;
|
|
4621
4642
|
uid: string | undefined;
|
|
4622
4643
|
};
|
|
@@ -4626,7 +4647,7 @@ declare function parseLegacyDocument(legacyDoc: unknown, customType: StaticCusto
|
|
|
4626
4647
|
}): Document | undefined;
|
|
4627
4648
|
declare function encodeToLegacyDocument(document: Document): DocumentLegacy;
|
|
4628
4649
|
export declare const DocumentLegacy: {
|
|
4629
|
-
_codec: (allTypes?: Map<string, "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Table" | "Text" | "Timestamp" | "Group" | "UID" | "Slice" | "SharedSlice" | "Choice" | "Slices" | "Repeatable.Link"> | undefined) => t.Type<{
|
|
4650
|
+
_codec: (allTypes?: Map<string, "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Table" | "Text" | "Timestamp" | "Group" | "UID" | "Slice" | "SharedSlice" | "Choice" | "Slices" | "Repeatable.Link"> | undefined, allKeys?: Map<string, string> | undefined) => t.Type<{
|
|
4630
4651
|
[x: string]: {
|
|
4631
4652
|
type: string;
|
|
4632
4653
|
__TYPE__: "EmptyContent";
|
|
@@ -6410,6 +6431,7 @@ export declare const DocumentLegacy: {
|
|
|
6410
6431
|
};
|
|
6411
6432
|
repeat: {
|
|
6412
6433
|
__TYPE__: "GroupItemContent";
|
|
6434
|
+
key: string;
|
|
6413
6435
|
value: [string, {
|
|
6414
6436
|
type: string;
|
|
6415
6437
|
__TYPE__: "EmptyContent";
|
|
@@ -7598,6 +7620,7 @@ export declare const DocumentLegacy: {
|
|
|
7598
7620
|
};
|
|
7599
7621
|
items: {
|
|
7600
7622
|
__TYPE__: "GroupItemContent";
|
|
7623
|
+
key: string;
|
|
7601
7624
|
value: [string, {
|
|
7602
7625
|
type: string;
|
|
7603
7626
|
__TYPE__: "EmptyContent";
|
|
@@ -10010,6 +10033,7 @@ export declare function migrateDocument(document: Document, customType: StaticCu
|
|
|
10010
10033
|
};
|
|
10011
10034
|
repeat: {
|
|
10012
10035
|
__TYPE__: "GroupItemContent";
|
|
10036
|
+
key: string;
|
|
10013
10037
|
value: [string, {
|
|
10014
10038
|
type: string;
|
|
10015
10039
|
__TYPE__: "EmptyContent";
|
|
@@ -11198,6 +11222,7 @@ export declare function migrateDocument(document: Document, customType: StaticCu
|
|
|
11198
11222
|
};
|
|
11199
11223
|
items: {
|
|
11200
11224
|
__TYPE__: "GroupItemContent";
|
|
11225
|
+
key: string;
|
|
11201
11226
|
value: [string, {
|
|
11202
11227
|
type: string;
|
|
11203
11228
|
__TYPE__: "EmptyContent";
|
package/lib/content/Document.js
CHANGED
|
@@ -17,11 +17,11 @@ const legacyDocReader = t.record(common_1.WidgetKey, t.unknown);
|
|
|
17
17
|
* `DocumentLegacyCodec` handles decoding and encoding documents to the legacy
|
|
18
18
|
* format used by Prismic DB, therefore, this function itself is not "legacy".
|
|
19
19
|
*/
|
|
20
|
-
const DocumentLegacyCodec = (allTypes) => {
|
|
20
|
+
const DocumentLegacyCodec = (allTypes, allKeys) => {
|
|
21
21
|
return new t.Type("Document", (u) => !!u && typeof u === "object", (doc) => {
|
|
22
22
|
return (0, function_1.pipe)(legacyDocReader.decode(doc), fp_ts_1.either.map((parsedDoc) => {
|
|
23
23
|
return Object.entries(parsedDoc).reduce((acc, [widgetKey, widgetValue]) => {
|
|
24
|
-
const widgetCtx = (0, LegacyContentCtx_1.defaultCtx)(widgetKey, allTypes);
|
|
24
|
+
const widgetCtx = (0, LegacyContentCtx_1.defaultCtx)(widgetKey, allTypes, allKeys);
|
|
25
25
|
const parsedW = (0, fields_1.WidgetLegacy)(widgetCtx).decode(widgetValue);
|
|
26
26
|
if (!parsedW || (0, Either_1.isLeft)(parsedW))
|
|
27
27
|
return acc;
|
|
@@ -37,13 +37,14 @@ const DocumentLegacyCodec = (allTypes) => {
|
|
|
37
37
|
return {
|
|
38
38
|
content: { ...acc.content, [key]: result.content },
|
|
39
39
|
types: { ...acc.types, ...result.types },
|
|
40
|
+
keys: { ...acc.keys, ...result.keys },
|
|
40
41
|
};
|
|
41
|
-
}, { content: {}, types: {} });
|
|
42
|
+
}, { content: {}, types: {}, keys: {} });
|
|
42
43
|
});
|
|
43
44
|
};
|
|
44
45
|
function extractMetadata(data) {
|
|
45
46
|
const fields = Object.entries(data);
|
|
46
|
-
const { types, widgets } = fields.reduce((acc, [k, v]) => {
|
|
47
|
+
const { types, widgets, keys } = fields.reduce((acc, [k, v]) => {
|
|
47
48
|
if (k.endsWith("_TYPE")) {
|
|
48
49
|
const decodedValue = LegacyContentCtx_1.FieldOrSliceType.decode(v);
|
|
49
50
|
if ((0, Either_1.isRight)(decodedValue)) {
|
|
@@ -53,7 +54,18 @@ function extractMetadata(data) {
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
|
-
if (
|
|
57
|
+
if (k.endsWith("_KEY")) {
|
|
58
|
+
const decodedValue = t.string.decode(v);
|
|
59
|
+
if ((0, Either_1.isRight)(decodedValue)) {
|
|
60
|
+
return {
|
|
61
|
+
...acc,
|
|
62
|
+
keys: acc.keys.set(k.substring(0, k.length - 4), decodedValue.right),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!k.endsWith("_POSITION") &&
|
|
67
|
+
!k.endsWith("_TYPE") &&
|
|
68
|
+
!k.endsWith("_KEY")) {
|
|
57
69
|
return {
|
|
58
70
|
...acc,
|
|
59
71
|
widgets: {
|
|
@@ -66,12 +78,14 @@ function extractMetadata(data) {
|
|
|
66
78
|
}, {
|
|
67
79
|
types: new Map(),
|
|
68
80
|
widgets: {},
|
|
81
|
+
keys: new Map(),
|
|
69
82
|
});
|
|
70
83
|
const slugs = data["slugs_INTERNAL"] || [];
|
|
71
84
|
const uid = data["uid"];
|
|
72
85
|
return {
|
|
73
86
|
widgets,
|
|
74
87
|
types,
|
|
88
|
+
keys,
|
|
75
89
|
uid,
|
|
76
90
|
slugs,
|
|
77
91
|
};
|
|
@@ -81,15 +95,15 @@ function parseLegacyDocument(legacyDoc, customType) {
|
|
|
81
95
|
// ensure it's the right document format first
|
|
82
96
|
t.record(common_1.WidgetKey, t.unknown).decode(legacyDoc), fp_ts_1.either.chain((doc) => {
|
|
83
97
|
// extract all metadata, meaning all _TYPES keys from legacy format + the widgets as unknown
|
|
84
|
-
const { types, widgets } = extractMetadata(doc);
|
|
98
|
+
const { types, widgets, keys } = extractMetadata(doc);
|
|
85
99
|
// parse the actual widgets
|
|
86
|
-
return DocumentLegacyCodec(types).decode(widgets);
|
|
100
|
+
return DocumentLegacyCodec(types, keys).decode(widgets);
|
|
87
101
|
}));
|
|
88
102
|
return (0, Either_1.isLeft)(result) ? undefined : migrateDocument(result.right, customType);
|
|
89
103
|
}
|
|
90
104
|
function encodeToLegacyDocument(document) {
|
|
91
105
|
const encoded = DocumentLegacyCodec().encode(document);
|
|
92
|
-
return { ...encoded.content, ...encoded.types };
|
|
106
|
+
return { ...encoded.content, ...encoded.types, ...encoded.keys };
|
|
93
107
|
}
|
|
94
108
|
exports.DocumentLegacy = {
|
|
95
109
|
_codec: DocumentLegacyCodec,
|
|
@@ -25,18 +25,40 @@ export declare const FieldOrSliceType: t.UnionC<[t.UnionC<[t.KeyofC<{
|
|
|
25
25
|
SharedSlice: null;
|
|
26
26
|
}>]>, t.LiteralC<"Repeatable.Link">]>;
|
|
27
27
|
export declare type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType>;
|
|
28
|
+
interface LegacyContentCtxParams {
|
|
29
|
+
fieldKey: string;
|
|
30
|
+
contentKey?: string;
|
|
31
|
+
fieldPath?: Array<string>;
|
|
32
|
+
contentPath?: Array<string>;
|
|
33
|
+
allTypes?: Map<string, FieldOrSliceType>;
|
|
34
|
+
allKeys?: Map<string, string>;
|
|
35
|
+
}
|
|
28
36
|
export declare class LegacyContentCtx {
|
|
29
37
|
fieldKey: string;
|
|
30
38
|
prefixedKey: string;
|
|
31
39
|
keyOfType: string;
|
|
40
|
+
keyOfKey: string;
|
|
32
41
|
fieldPath: Array<string>;
|
|
33
42
|
fieldType?: FieldOrSliceType | undefined;
|
|
34
43
|
allTypes: Map<string, FieldOrSliceType>;
|
|
35
|
-
|
|
44
|
+
allKeys: Map<string, string>;
|
|
45
|
+
contentKey: string;
|
|
46
|
+
contentPath: Array<string>;
|
|
47
|
+
fieldContentKey: string;
|
|
48
|
+
constructor({ fieldKey, contentKey, contentPath, fieldPath, allTypes, allKeys, }: LegacyContentCtxParams);
|
|
49
|
+
withContentKey(contentKey: string): LegacyContentCtx;
|
|
50
|
+
}
|
|
51
|
+
interface GetFieldCtxParams {
|
|
52
|
+
fieldKey: string;
|
|
53
|
+
contentKey?: string;
|
|
54
|
+
ctx: LegacyContentCtx;
|
|
55
|
+
prefixes?: Array<string>;
|
|
36
56
|
}
|
|
37
|
-
export declare function getFieldCtx(fieldKey:
|
|
38
|
-
export declare function defaultCtx(key: string, allTypes?: Map<string, FieldOrSliceType>): LegacyContentCtx;
|
|
57
|
+
export declare function getFieldCtx({ fieldKey, contentKey: contentKeyParam, ctx, prefixes, }: GetFieldCtxParams): LegacyContentCtx;
|
|
58
|
+
export declare function defaultCtx(key: string, allTypes?: Map<string, FieldOrSliceType>, allKeys?: Map<string, string>): LegacyContentCtx;
|
|
39
59
|
export declare type WithTypes<T> = {
|
|
60
|
+
keys: Record<string, string>;
|
|
40
61
|
types: Record<string, FieldOrSliceType>;
|
|
41
62
|
content: T;
|
|
42
63
|
};
|
|
64
|
+
export {};
|
|
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defaultCtx = exports.getFieldCtx = exports.LegacyContentCtx = exports.FieldOrSliceType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
6
7
|
const widgets_1 = require("../customtypes/widgets");
|
|
7
8
|
exports.FieldOrSliceType = t.union([
|
|
8
9
|
t.union([widgets_1.FieldType, widgets_1.SlicesTypes]),
|
|
9
10
|
t.literal("Repeatable.Link"),
|
|
10
11
|
]);
|
|
11
12
|
class LegacyContentCtx {
|
|
12
|
-
constructor(fieldKey, fieldPath, allTypes) {
|
|
13
|
+
constructor({ fieldKey, contentKey, contentPath, fieldPath, allTypes, allKeys, }) {
|
|
14
|
+
var _a;
|
|
13
15
|
Object.defineProperty(this, "fieldKey", {
|
|
14
16
|
enumerable: true,
|
|
15
17
|
configurable: true,
|
|
@@ -28,6 +30,12 @@ class LegacyContentCtx {
|
|
|
28
30
|
writable: true,
|
|
29
31
|
value: void 0
|
|
30
32
|
});
|
|
33
|
+
Object.defineProperty(this, "keyOfKey", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
31
39
|
Object.defineProperty(this, "fieldPath", {
|
|
32
40
|
enumerable: true,
|
|
33
41
|
configurable: true,
|
|
@@ -46,23 +54,77 @@ class LegacyContentCtx {
|
|
|
46
54
|
writable: true,
|
|
47
55
|
value: void 0
|
|
48
56
|
});
|
|
57
|
+
Object.defineProperty(this, "allKeys", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(this, "contentKey", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "contentPath", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
configurable: true,
|
|
72
|
+
writable: true,
|
|
73
|
+
value: void 0
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(this, "fieldContentKey", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
49
81
|
this.fieldKey = fieldKey;
|
|
82
|
+
this.contentKey = contentKey || fieldKey;
|
|
50
83
|
this.fieldPath = fieldPath || [];
|
|
84
|
+
this.contentPath = contentPath || [];
|
|
51
85
|
this.allTypes = allTypes || new Map();
|
|
86
|
+
this.allKeys = allKeys || new Map();
|
|
52
87
|
const prefixedKey = Array.of(this.fieldPath, [this.fieldKey])
|
|
53
88
|
.flat()
|
|
54
89
|
.join(".");
|
|
90
|
+
const prefixedContentKey = Array.of(this.contentPath, [this.contentKey])
|
|
91
|
+
.flat()
|
|
92
|
+
.join(".");
|
|
55
93
|
this.prefixedKey = prefixedKey;
|
|
56
94
|
this.keyOfType = `${prefixedKey}_TYPE`;
|
|
95
|
+
this.keyOfKey = `${prefixedContentKey}_KEY`;
|
|
57
96
|
this.fieldType = this.allTypes.get(this.prefixedKey);
|
|
97
|
+
this.fieldContentKey = (_a = this.allKeys.get(prefixedContentKey)) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)();
|
|
98
|
+
}
|
|
99
|
+
withContentKey(contentKey) {
|
|
100
|
+
return new LegacyContentCtx({
|
|
101
|
+
...this,
|
|
102
|
+
contentPath: [...this.contentPath, this.contentKey],
|
|
103
|
+
contentKey,
|
|
104
|
+
});
|
|
58
105
|
}
|
|
59
106
|
}
|
|
60
107
|
exports.LegacyContentCtx = LegacyContentCtx;
|
|
61
|
-
function getFieldCtx(fieldKey, ctx, prefixes) {
|
|
62
|
-
|
|
108
|
+
function getFieldCtx({ fieldKey, contentKey: contentKeyParam, ctx, prefixes, }) {
|
|
109
|
+
const contentKey = contentKeyParam || fieldKey;
|
|
110
|
+
return new LegacyContentCtx({
|
|
111
|
+
fieldKey,
|
|
112
|
+
contentKey,
|
|
113
|
+
contentPath: [...ctx.contentPath, ctx.contentKey, ...(prefixes || [])],
|
|
114
|
+
fieldPath: [...ctx.fieldPath, ctx.fieldKey, ...(prefixes || [])],
|
|
115
|
+
allTypes: ctx.allTypes,
|
|
116
|
+
allKeys: ctx.allKeys,
|
|
117
|
+
});
|
|
63
118
|
}
|
|
64
119
|
exports.getFieldCtx = getFieldCtx;
|
|
65
|
-
function defaultCtx(key, allTypes = new Map()) {
|
|
66
|
-
return new LegacyContentCtx(
|
|
120
|
+
function defaultCtx(key, allTypes = new Map(), allKeys = new Map()) {
|
|
121
|
+
return new LegacyContentCtx({
|
|
122
|
+
fieldKey: key,
|
|
123
|
+
contentKey: key,
|
|
124
|
+
contentPath: [],
|
|
125
|
+
fieldPath: [],
|
|
126
|
+
allTypes,
|
|
127
|
+
allKeys,
|
|
128
|
+
});
|
|
67
129
|
}
|
|
68
130
|
exports.defaultCtx = defaultCtx;
|
|
@@ -8,6 +8,7 @@ export declare const GroupContentType: "GroupContentType";
|
|
|
8
8
|
export declare const GroupItemContent: t.Type<GroupItemContent>;
|
|
9
9
|
export declare type GroupItemContent = {
|
|
10
10
|
__TYPE__: typeof GroupItemContentType;
|
|
11
|
+
key: string;
|
|
11
12
|
value: [string, NestableContent | GroupContent][];
|
|
12
13
|
};
|
|
13
14
|
export declare const GroupContent: t.Type<GroupContent>;
|
|
@@ -18,10 +19,11 @@ export declare type GroupContent = {
|
|
|
18
19
|
export declare const isGroupContent: (u: unknown) => u is GroupContent;
|
|
19
20
|
export declare const GroupContentDefaultValue: GroupContent;
|
|
20
21
|
declare const itemLegacyReader: t.RecordC<t.StringC, t.UnknownC>;
|
|
21
|
-
declare type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>;
|
|
22
|
-
export declare const GroupItemLegacy: (ctx: LegacyContentCtx) => t.Type<GroupItemContent, WithTypes<{
|
|
22
|
+
export declare type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>;
|
|
23
|
+
export declare const GroupItemLegacy: (ctx: LegacyContentCtx, index: number) => t.Type<GroupItemContent, WithTypes<{
|
|
23
24
|
[x: string]: unknown;
|
|
24
25
|
}>, unknown>;
|
|
26
|
+
export declare function arrayWithIndexCodec<T, O>(f: (index: number) => t.Type<T, O, unknown>): t.Type<Array<T>, O[], unknown>;
|
|
25
27
|
declare type GroupLegacy = Array<GroupItemLegacy>;
|
|
26
28
|
export declare const GroupLegacy: (ctx: LegacyContentCtx) => t.Type<GroupContent, WithTypes<GroupLegacy>, unknown>;
|
|
27
29
|
export declare function groupContentWithDefaultValues(customType: Group, content: GroupContent): GroupContent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupContentDefaultValue = exports.isGroupContent = exports.GroupContent = exports.GroupItemContent = exports.GroupContentType = exports.GroupItemContentType = void 0;
|
|
3
|
+
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupLegacy = exports.arrayWithIndexCodec = exports.GroupItemLegacy = exports.GroupContentDefaultValue = exports.isGroupContent = exports.GroupContent = exports.GroupItemContent = exports.GroupContentType = exports.GroupItemContentType = 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");
|
|
@@ -15,6 +15,7 @@ exports.GroupItemContentType = "GroupItemContent";
|
|
|
15
15
|
exports.GroupContentType = "GroupContentType";
|
|
16
16
|
exports.GroupItemContent = t.recursion("GroupItemContent", () => t.strict({
|
|
17
17
|
__TYPE__: t.literal(exports.GroupItemContentType),
|
|
18
|
+
key: t.string,
|
|
18
19
|
value: t.array(t.tuple([t.string, t.union([nestable_1.NestableContent, exports.GroupContent])])),
|
|
19
20
|
}));
|
|
20
21
|
exports.GroupContent = t.recursion("GroupContent", () => t.strict({
|
|
@@ -28,11 +29,16 @@ exports.GroupContentDefaultValue = {
|
|
|
28
29
|
value: [],
|
|
29
30
|
};
|
|
30
31
|
const itemLegacyReader = t.record(t.string, t.unknown);
|
|
31
|
-
const GroupItemLegacy = (ctx) => {
|
|
32
|
+
const GroupItemLegacy = (ctx, index) => {
|
|
32
33
|
return new t.Type("GroupItemLegacy", (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.GroupItemContentType, (u) => {
|
|
33
34
|
const parsed = (0, function_1.pipe)(itemLegacyReader.decode(u), fp_ts_1.either.map((items) => {
|
|
35
|
+
const groupItemCtx = ctx.withContentKey(`${index}`);
|
|
34
36
|
const parsedItems = Object.entries(items).reduce((acc, [itemKey, itemValue]) => {
|
|
35
|
-
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(
|
|
37
|
+
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)({
|
|
38
|
+
fieldKey: itemKey,
|
|
39
|
+
contentKey: itemKey,
|
|
40
|
+
ctx: groupItemCtx,
|
|
41
|
+
});
|
|
36
42
|
const result = itemCtx.fieldType === customtypes_1.GroupFieldType
|
|
37
43
|
? (0, exports.GroupLegacy)(itemCtx).decode(itemValue)
|
|
38
44
|
: (0, nestable_1.NestableLegacy)(itemCtx).decode(itemValue);
|
|
@@ -45,12 +51,14 @@ const GroupItemLegacy = (ctx) => {
|
|
|
45
51
|
return {
|
|
46
52
|
value: parsedItems,
|
|
47
53
|
__TYPE__: exports.GroupItemContentType,
|
|
54
|
+
key: groupItemCtx.fieldContentKey,
|
|
48
55
|
};
|
|
49
56
|
}));
|
|
50
57
|
return parsed;
|
|
51
58
|
}, (item) => {
|
|
59
|
+
const groupItemCtx = ctx.withContentKey(`${index}`);
|
|
52
60
|
return item.value.reduce((acc, [key, value]) => {
|
|
53
|
-
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(key, ctx);
|
|
61
|
+
const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)({ fieldKey: key, ctx });
|
|
54
62
|
const encoded = (0, exports.isGroupContent)(value)
|
|
55
63
|
? (0, exports.GroupLegacy)(itemCtx).encode(value)
|
|
56
64
|
: (0, nestable_1.NestableLegacy)(itemCtx).encode(value);
|
|
@@ -59,34 +67,48 @@ const GroupItemLegacy = (ctx) => {
|
|
|
59
67
|
return {
|
|
60
68
|
content: { ...acc.content, [key]: encoded.content },
|
|
61
69
|
types: { ...acc.types, ...encoded.types },
|
|
70
|
+
keys: { ...acc.keys, ...encoded.keys },
|
|
62
71
|
};
|
|
63
|
-
}, { content: {}, types: {} });
|
|
72
|
+
}, { content: {}, types: {}, keys: { [groupItemCtx.keyOfKey]: item.key } });
|
|
64
73
|
});
|
|
65
74
|
};
|
|
66
75
|
exports.GroupItemLegacy = GroupItemLegacy;
|
|
76
|
+
function arrayWithIndexCodec(f) {
|
|
77
|
+
return new t.Type("ArrayWithIndexCodec", (u) => Array.isArray(u), (items) => (0, function_1.pipe)(t.array(t.unknown).decode(items), fp_ts_1.either.chain((validItems) => {
|
|
78
|
+
const decodedItems = validItems.map((item, index) => {
|
|
79
|
+
return f(index).decode(item);
|
|
80
|
+
});
|
|
81
|
+
return fp_ts_1.array.sequence(fp_ts_1.either.Applicative)(decodedItems);
|
|
82
|
+
})), (items) => items.map((item, index) => f(index).encode(item)));
|
|
83
|
+
}
|
|
84
|
+
exports.arrayWithIndexCodec = arrayWithIndexCodec;
|
|
67
85
|
const GroupLegacy = (ctx) => {
|
|
68
|
-
const codecDecode =
|
|
69
|
-
const codecEncode =
|
|
86
|
+
const codecDecode = arrayWithIndexCodec((index) => t.union([(0, exports.GroupItemLegacy)(ctx, index), t.null]));
|
|
87
|
+
const codecEncode = (items) => items.map((item, index) => (0, exports.GroupItemLegacy)(ctx, index).encode(item));
|
|
70
88
|
return new t.Type("GroupLegacy", exports.isGroupContent, (items) => {
|
|
71
89
|
return (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((parsedItems) => {
|
|
90
|
+
const value = parsedItems.map((i, index) => {
|
|
91
|
+
if (i === null) {
|
|
92
|
+
const key = ctx.withContentKey(`${index}`).fieldContentKey;
|
|
93
|
+
return { __TYPE__: exports.GroupItemContentType, key, value: [] };
|
|
94
|
+
}
|
|
95
|
+
return i;
|
|
96
|
+
});
|
|
72
97
|
return {
|
|
73
|
-
value
|
|
74
|
-
if (i === null) {
|
|
75
|
-
return { __TYPE__: exports.GroupItemContentType, value: [] };
|
|
76
|
-
}
|
|
77
|
-
else
|
|
78
|
-
return i;
|
|
79
|
-
}),
|
|
98
|
+
value,
|
|
80
99
|
__TYPE__: exports.GroupContentType,
|
|
81
100
|
};
|
|
82
101
|
}));
|
|
83
102
|
}, (g) => {
|
|
84
|
-
const res = codecEncode
|
|
103
|
+
const res = codecEncode(g.value);
|
|
85
104
|
return {
|
|
86
105
|
content: res.map((block) => block.content),
|
|
87
106
|
types: res.reduce((acc, block) => {
|
|
88
107
|
return { ...acc, ...block.types };
|
|
89
108
|
}, { [ctx.keyOfType]: customtypes_1.GroupFieldType }),
|
|
109
|
+
keys: res.reduce((acc, block) => {
|
|
110
|
+
return { ...acc, ...block.keys };
|
|
111
|
+
}, {}),
|
|
90
112
|
};
|
|
91
113
|
});
|
|
92
114
|
};
|
|
@@ -125,9 +147,9 @@ function traverseGroupContent({ path, key, apiId, model, content, }) {
|
|
|
125
147
|
exports.traverseGroupContent = traverseGroupContent;
|
|
126
148
|
function traverseGroupItemsContent({ path, model, content, }) {
|
|
127
149
|
return (transform) => {
|
|
128
|
-
return content.map((groupItem
|
|
150
|
+
return content.map((groupItem) => {
|
|
129
151
|
const groupItemPath = path.concat([
|
|
130
|
-
{ key:
|
|
152
|
+
{ key: groupItem.key, type: "GroupItem" },
|
|
131
153
|
]);
|
|
132
154
|
const groupItemFields = groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
133
155
|
const fieldDef = model === null || model === void 0 ? void 0 : model[fieldKey];
|
|
@@ -177,6 +199,7 @@ function traverseGroupItemsContent({ path, model, content, }) {
|
|
|
177
199
|
}, []);
|
|
178
200
|
return {
|
|
179
201
|
__TYPE__: groupItem.__TYPE__,
|
|
202
|
+
key: groupItem.key,
|
|
180
203
|
value: groupItemFields,
|
|
181
204
|
};
|
|
182
205
|
});
|
|
@@ -1541,6 +1541,7 @@ export declare const WidgetContent: t.UnionC<[t.Type<GroupContent, GroupContent,
|
|
|
1541
1541
|
}>>]>>;
|
|
1542
1542
|
repeat: t.ArrayC<t.ExactC<t.TypeC<{
|
|
1543
1543
|
__TYPE__: t.LiteralC<"GroupItemContent">;
|
|
1544
|
+
key: t.StringC;
|
|
1544
1545
|
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
1545
1546
|
type: t.StringC;
|
|
1546
1547
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
@@ -3075,6 +3076,7 @@ export declare const WidgetContent: t.UnionC<[t.Type<GroupContent, GroupContent,
|
|
|
3075
3076
|
}>>]>, t.Type<GroupContent, GroupContent, unknown>]>>;
|
|
3076
3077
|
items: t.ArrayC<t.ExactC<t.TypeC<{
|
|
3077
3078
|
__TYPE__: t.LiteralC<"GroupItemContent">;
|
|
3079
|
+
key: t.StringC;
|
|
3078
3080
|
value: t.ArrayC<t.TupleC<[t.StringC, t.UnionC<[t.UnionC<[t.ExactC<t.TypeC<{
|
|
3079
3081
|
type: t.StringC;
|
|
3080
3082
|
__TYPE__: t.LiteralC<"EmptyContent">;
|
|
@@ -6389,6 +6391,7 @@ export declare const isWidgetContent: (u: unknown) => u is {
|
|
|
6389
6391
|
};
|
|
6390
6392
|
repeat: {
|
|
6391
6393
|
__TYPE__: "GroupItemContent";
|
|
6394
|
+
key: string;
|
|
6392
6395
|
value: [string, {
|
|
6393
6396
|
type: string;
|
|
6394
6397
|
__TYPE__: "EmptyContent";
|
|
@@ -7577,6 +7580,7 @@ export declare const isWidgetContent: (u: unknown) => u is {
|
|
|
7577
7580
|
};
|
|
7578
7581
|
items: {
|
|
7579
7582
|
__TYPE__: "GroupItemContent";
|
|
7583
|
+
key: string;
|
|
7580
7584
|
value: [string, {
|
|
7581
7585
|
type: string;
|
|
7582
7586
|
__TYPE__: "EmptyContent";
|
|
@@ -9957,6 +9961,7 @@ export declare const WidgetLegacy: (ctx: LegacyContentCtx) => {
|
|
|
9957
9961
|
};
|
|
9958
9962
|
repeat: {
|
|
9959
9963
|
__TYPE__: "GroupItemContent";
|
|
9964
|
+
key: string;
|
|
9960
9965
|
value: [string, {
|
|
9961
9966
|
type: string;
|
|
9962
9967
|
__TYPE__: "EmptyContent";
|
|
@@ -11145,6 +11150,7 @@ export declare const WidgetLegacy: (ctx: LegacyContentCtx) => {
|
|
|
11145
11150
|
};
|
|
11146
11151
|
items: {
|
|
11147
11152
|
__TYPE__: "GroupItemContent";
|
|
11153
|
+
key: string;
|
|
11148
11154
|
value: [string, {
|
|
11149
11155
|
type: string;
|
|
11150
11156
|
__TYPE__: "EmptyContent";
|