@prismicio/types-internal 1.1.0 → 1.2.0-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.
- package/lib/customtypes/Comparators/Changes.d.ts +17 -0
- package/lib/customtypes/Comparators/Changes.js +9 -0
- package/lib/customtypes/Comparators/SharedSlice.d.ts +679 -0
- package/lib/customtypes/Comparators/SharedSlice.js +55 -0
- package/lib/customtypes/Comparators/Variation.d.ts +662 -0
- package/lib/customtypes/Comparators/Variation.js +75 -0
- package/lib/customtypes/Comparators/index.d.ts +3 -0
- package/lib/customtypes/Comparators/index.js +6 -0
- package/lib/customtypes/CustomType.d.ts +932 -932
- package/lib/customtypes/Format.d.ts +4 -0
- package/lib/customtypes/Format.js +8 -0
- package/lib/customtypes/Section.d.ts +932 -932
- package/lib/customtypes/comp/Changes.d.ts +17 -0
- package/lib/customtypes/comp/Changes.js +9 -0
- package/lib/customtypes/comp/SharedSlice.d.ts +679 -0
- package/lib/customtypes/comp/SharedSlice.js +55 -0
- package/lib/customtypes/comp/Variation.d.ts +662 -0
- package/lib/customtypes/comp/Variation.js +76 -0
- package/lib/customtypes/comp/index.d.ts +3 -0
- package/lib/customtypes/comp/index.js +6 -0
- package/lib/customtypes/index.d.ts +1 -0
- package/lib/customtypes/index.js +2 -1
- package/lib/customtypes/utils/Comparator.d.ts +1353 -0
- package/lib/customtypes/utils/Comparator.js +59 -0
- package/lib/customtypes/utils/index.d.ts +1 -0
- package/lib/customtypes/utils/index.js +4 -0
- package/lib/customtypes/widgets/Widget.d.ts +664 -664
- package/lib/customtypes/widgets/slices/Slices.d.ts +792 -792
- package/lib/documents/widgets/index.js +1 -1
- package/lib/documents/widgets/nestable/EmbedContent.d.ts +4 -4
- package/lib/documents/widgets/nestable/ImageContent.d.ts +14 -14
- package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +4 -4
- package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +2 -2
- package/lib/documents/widgets/nestable/Link/index.d.ts +4 -4
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +8 -8
- package/lib/utils/Arrays.d.ts +1 -0
- package/lib/utils/Arrays.js +13 -0
- package/lib/utils/Objects.d.ts +5 -0
- package/lib/utils/Objects.js +21 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +6 -0
- package/package.json +2 -2
- package/src/customtypes/comparators/Changes.ts +21 -0
- package/src/customtypes/comparators/SharedSlice.ts +77 -0
- package/src/customtypes/comparators/Variation.ts +101 -0
- package/src/customtypes/comparators/index.ts +3 -0
- package/src/customtypes/index.ts +1 -0
- package/src/documents/widgets/index.ts +4 -2
- package/src/utils/Arrays.ts +12 -0
- package/src/utils/Objects.ts +24 -0
- package/src/utils/index.ts +2 -0
- package/CHANGELOG.md +0 -13
|
@@ -26,7 +26,7 @@ exports.WidgetTypes = {
|
|
|
26
26
|
slices: slices_1.SlicesContentType,
|
|
27
27
|
};
|
|
28
28
|
const widgetKeyRegex = new RegExp("^[^<>]+$");
|
|
29
|
-
exports.WidgetKey = (0, function_1.refineType)(t.string, "WidgetKey", (s) => widgetKeyRegex.test(s));
|
|
29
|
+
exports.WidgetKey = (0, function_1.refineType)(t.string, "WidgetKey", (s) => s.length === 0 || widgetKeyRegex.test(s));
|
|
30
30
|
exports.Widget = {
|
|
31
31
|
fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions) {
|
|
32
32
|
const fieldType = widgetTypes.get(widgetKey);
|
|
@@ -11,13 +11,13 @@ declare const EmbedContentC: t.Type<{
|
|
|
11
11
|
embed_url: string;
|
|
12
12
|
type: string;
|
|
13
13
|
} & {
|
|
14
|
-
version?: string | number | null;
|
|
14
|
+
version?: string | number | null | undefined;
|
|
15
15
|
title?: string | null | undefined;
|
|
16
16
|
author_name?: string | null | undefined;
|
|
17
17
|
author_url?: string | null | undefined;
|
|
18
18
|
provider_name?: string | null | undefined;
|
|
19
19
|
provider_url?: string | null | undefined;
|
|
20
|
-
cache_age?: string | number | null;
|
|
20
|
+
cache_age?: string | number | null | undefined;
|
|
21
21
|
thumbnail_url?: string | null | undefined;
|
|
22
22
|
thumbnail_width?: number | null | undefined;
|
|
23
23
|
thumbnail_height?: number | null | undefined;
|
|
@@ -26,13 +26,13 @@ declare const EmbedContentC: t.Type<{
|
|
|
26
26
|
embed_url: string;
|
|
27
27
|
type: string;
|
|
28
28
|
} & {
|
|
29
|
-
version?: string | number | null;
|
|
29
|
+
version?: string | number | null | undefined;
|
|
30
30
|
title?: string | null | undefined;
|
|
31
31
|
author_name?: string | null | undefined;
|
|
32
32
|
author_url?: string | null | undefined;
|
|
33
33
|
provider_name?: string | null | undefined;
|
|
34
34
|
provider_url?: string | null | undefined;
|
|
35
|
-
cache_age?: string | number | null;
|
|
35
|
+
cache_age?: string | number | null | undefined;
|
|
36
36
|
thumbnail_url?: string | null | undefined;
|
|
37
37
|
thumbnail_width?: number | null | undefined;
|
|
38
38
|
thumbnail_height?: number | null | undefined;
|
|
@@ -42,9 +42,9 @@ export declare const ImageContent: t.Type<{
|
|
|
42
42
|
background: string;
|
|
43
43
|
};
|
|
44
44
|
} & {
|
|
45
|
-
url?: string;
|
|
46
|
-
credits?: string | null;
|
|
47
|
-
alt?: string | null;
|
|
45
|
+
url?: string | undefined;
|
|
46
|
+
credits?: string | null | undefined;
|
|
47
|
+
alt?: string | null | undefined;
|
|
48
48
|
provider?: string | null | undefined;
|
|
49
49
|
} & {
|
|
50
50
|
thumbnails?: {
|
|
@@ -66,12 +66,12 @@ export declare const ImageContent: t.Type<{
|
|
|
66
66
|
background: string;
|
|
67
67
|
};
|
|
68
68
|
} & {
|
|
69
|
-
url?: string;
|
|
70
|
-
credits?: string | null;
|
|
71
|
-
alt?: string | null;
|
|
69
|
+
url?: string | undefined;
|
|
70
|
+
credits?: string | null | undefined;
|
|
71
|
+
alt?: string | null | undefined;
|
|
72
72
|
provider?: string | null | undefined;
|
|
73
73
|
};
|
|
74
|
-
};
|
|
74
|
+
} | undefined;
|
|
75
75
|
}, {
|
|
76
76
|
origin: {
|
|
77
77
|
id: string;
|
|
@@ -90,9 +90,9 @@ export declare const ImageContent: t.Type<{
|
|
|
90
90
|
background: string;
|
|
91
91
|
};
|
|
92
92
|
} & {
|
|
93
|
-
url?: string;
|
|
94
|
-
credits?: string | null;
|
|
95
|
-
alt?: string | null;
|
|
93
|
+
url?: string | undefined;
|
|
94
|
+
credits?: string | null | undefined;
|
|
95
|
+
alt?: string | null | undefined;
|
|
96
96
|
provider?: string | null | undefined;
|
|
97
97
|
} & {
|
|
98
98
|
thumbnails?: {
|
|
@@ -114,12 +114,12 @@ export declare const ImageContent: t.Type<{
|
|
|
114
114
|
background: string;
|
|
115
115
|
};
|
|
116
116
|
} & {
|
|
117
|
-
url?: string;
|
|
118
|
-
credits?: string | null;
|
|
119
|
-
alt?: string | null;
|
|
117
|
+
url?: string | undefined;
|
|
118
|
+
credits?: string | null | undefined;
|
|
119
|
+
alt?: string | null | undefined;
|
|
120
120
|
provider?: string | null | undefined;
|
|
121
121
|
};
|
|
122
|
-
};
|
|
122
|
+
} | undefined;
|
|
123
123
|
} & {
|
|
124
124
|
__TYPE__: "ImageContent";
|
|
125
125
|
}, unknown>;
|
|
@@ -3,18 +3,18 @@ export declare const ExternalLinkType = "ExternalLink";
|
|
|
3
3
|
export declare const ExternalLink: t.Type<{
|
|
4
4
|
url: string;
|
|
5
5
|
} & {
|
|
6
|
-
kind?: "web";
|
|
6
|
+
kind?: "web" | undefined;
|
|
7
7
|
target?: string | null | undefined;
|
|
8
8
|
preview?: {
|
|
9
|
-
title?: string;
|
|
9
|
+
title?: string | undefined;
|
|
10
10
|
} | null | undefined;
|
|
11
11
|
}, {
|
|
12
12
|
url: string;
|
|
13
13
|
} & {
|
|
14
|
-
kind?: "web";
|
|
14
|
+
kind?: "web" | undefined;
|
|
15
15
|
target?: string | null | undefined;
|
|
16
16
|
preview?: {
|
|
17
|
-
title?: string;
|
|
17
|
+
title?: string | undefined;
|
|
18
18
|
} | null | undefined;
|
|
19
19
|
} & {
|
|
20
20
|
__TYPE__: "ExternalLink";
|
|
@@ -10,10 +10,10 @@ export declare const LinkContent: t.Type<LinkContent, {
|
|
|
10
10
|
} | ({
|
|
11
11
|
url: string;
|
|
12
12
|
} & {
|
|
13
|
-
kind?: "web";
|
|
13
|
+
kind?: "web" | undefined;
|
|
14
14
|
target?: string | null | undefined;
|
|
15
15
|
preview?: {
|
|
16
|
-
title?: string;
|
|
16
|
+
title?: string | undefined;
|
|
17
17
|
} | null | undefined;
|
|
18
18
|
}) | ({
|
|
19
19
|
id: string;
|
|
@@ -50,18 +50,18 @@ export declare const Link: t.UnionC<[t.Type<{
|
|
|
50
50
|
}, unknown>, t.Type<{
|
|
51
51
|
url: string;
|
|
52
52
|
} & {
|
|
53
|
-
kind?: "web";
|
|
53
|
+
kind?: "web" | undefined;
|
|
54
54
|
target?: string | null | undefined;
|
|
55
55
|
preview?: {
|
|
56
|
-
title?: string;
|
|
56
|
+
title?: string | undefined;
|
|
57
57
|
} | null | undefined;
|
|
58
58
|
}, {
|
|
59
59
|
url: string;
|
|
60
60
|
} & {
|
|
61
|
-
kind?: "web";
|
|
61
|
+
kind?: "web" | undefined;
|
|
62
62
|
target?: string | null | undefined;
|
|
63
63
|
preview?: {
|
|
64
|
-
title?: string;
|
|
64
|
+
title?: string | undefined;
|
|
65
65
|
} | null | undefined;
|
|
66
66
|
} & {
|
|
67
67
|
__TYPE__: "ExternalLink";
|
|
@@ -92,10 +92,10 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
92
92
|
} | ({
|
|
93
93
|
url: string;
|
|
94
94
|
} & {
|
|
95
|
-
kind?: "web";
|
|
95
|
+
kind?: "web" | undefined;
|
|
96
96
|
target?: string | null | undefined;
|
|
97
97
|
preview?: {
|
|
98
|
-
title?: string;
|
|
98
|
+
title?: string | undefined;
|
|
99
99
|
} | null | undefined;
|
|
100
100
|
}) | ({
|
|
101
101
|
id: string;
|
|
@@ -122,10 +122,10 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
122
122
|
}) | ({
|
|
123
123
|
url: string;
|
|
124
124
|
} & {
|
|
125
|
-
kind?: "web";
|
|
125
|
+
kind?: "web" | undefined;
|
|
126
126
|
target?: string | null | undefined;
|
|
127
127
|
preview?: {
|
|
128
|
-
title?: string;
|
|
128
|
+
title?: string | undefined;
|
|
129
129
|
} | null | undefined;
|
|
130
130
|
} & {
|
|
131
131
|
__TYPE__: "ExternalLink";
|
|
@@ -220,10 +220,10 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
220
220
|
} | ({
|
|
221
221
|
url: string;
|
|
222
222
|
} & {
|
|
223
|
-
kind?: "web";
|
|
223
|
+
kind?: "web" | undefined;
|
|
224
224
|
target?: string | null | undefined;
|
|
225
225
|
preview?: {
|
|
226
|
-
title?: string;
|
|
226
|
+
title?: string | undefined;
|
|
227
227
|
} | null | undefined;
|
|
228
228
|
}) | ({
|
|
229
229
|
id: string;
|
|
@@ -250,10 +250,10 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
250
250
|
}) | ({
|
|
251
251
|
url: string;
|
|
252
252
|
} & {
|
|
253
|
-
kind?: "web";
|
|
253
|
+
kind?: "web" | undefined;
|
|
254
254
|
target?: string | null | undefined;
|
|
255
255
|
preview?: {
|
|
256
|
-
title?: string;
|
|
256
|
+
title?: string | undefined;
|
|
257
257
|
} | null | undefined;
|
|
258
258
|
} & {
|
|
259
259
|
__TYPE__: "ExternalLink";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toRecord<A extends object>(arr: ReadonlyArray<A>, key: (obj: A) => string): {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRecord = void 0;
|
|
4
|
+
function toRecord(arr, key) {
|
|
5
|
+
return arr.reduce((acc, entry) => {
|
|
6
|
+
const k = key(entry);
|
|
7
|
+
return {
|
|
8
|
+
...acc,
|
|
9
|
+
[k]: entry,
|
|
10
|
+
};
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
exports.toRecord = toRecord;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNotEmpty = exports.zipObjects = void 0;
|
|
4
|
+
function zipObjects(objLeft, objRight) {
|
|
5
|
+
const allKeys = [
|
|
6
|
+
...new Set(Object.keys(objLeft || {}).concat(Object.keys(objRight || {}))),
|
|
7
|
+
];
|
|
8
|
+
return allKeys.reduce((acc, key) => {
|
|
9
|
+
const left = objLeft === null || objLeft === void 0 ? void 0 : objLeft[key];
|
|
10
|
+
const right = objRight === null || objRight === void 0 ? void 0 : objRight[key];
|
|
11
|
+
return {
|
|
12
|
+
...acc,
|
|
13
|
+
[key]: { left, right },
|
|
14
|
+
};
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
exports.zipObjects = zipObjects;
|
|
18
|
+
function isNotEmpty(obj) {
|
|
19
|
+
return Boolean(Object.keys(obj).length);
|
|
20
|
+
}
|
|
21
|
+
exports.isNotEmpty = isNotEmpty;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Objects = exports.Arrays = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.Arrays = (0, tslib_1.__importStar)(require("./Arrays"));
|
|
6
|
+
exports.Objects = (0, tslib_1.__importStar)(require("./Objects"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/types-internal",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.0",
|
|
4
4
|
"description": "Prismic types for Custom Types and Prismic Data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"io-ts-types": "^0.5.16",
|
|
56
56
|
"jest": "^27.5.1",
|
|
57
57
|
"nyc": "^15.1.0",
|
|
58
|
-
"prettier": "^2.
|
|
58
|
+
"prettier": "^2.7.1",
|
|
59
59
|
"prettier-plugin-jsdoc": "^0.3.30",
|
|
60
60
|
"standard-version": "^9.3.2",
|
|
61
61
|
"ts-eager": "^2.0.2",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export enum DiffOperation {
|
|
2
|
+
Added = "added",
|
|
3
|
+
Removed = "removed",
|
|
4
|
+
Updated = "updated",
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type AddChange<A> = {
|
|
8
|
+
op: DiffOperation.Added
|
|
9
|
+
value: A
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type RemovedChange = {
|
|
13
|
+
op: DiffOperation.Removed
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type UpdatedChange<A> = {
|
|
17
|
+
op: DiffOperation.Updated
|
|
18
|
+
value: A
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type DiffChange<A, U> = AddChange<A> | UpdatedChange<U> | RemovedChange
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Arrays, Objects } from "../../utils"
|
|
2
|
+
import type { SharedSlice, Variation } from "../widgets/slices"
|
|
3
|
+
import { type DiffChange, DiffOperation } from "./Changes"
|
|
4
|
+
import { VariationComparator, VariationDiff } from "./Variation"
|
|
5
|
+
|
|
6
|
+
type SliceMetadata = Omit<SharedSlice, "variations">
|
|
7
|
+
type SliceDiff = DiffChange<
|
|
8
|
+
SharedSlice,
|
|
9
|
+
Partial<
|
|
10
|
+
SliceMetadata & {
|
|
11
|
+
variations?: Partial<Record<string, VariationDiff>>
|
|
12
|
+
}
|
|
13
|
+
>
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
function compareSliceMeta(
|
|
17
|
+
sliceA?: SharedSlice,
|
|
18
|
+
sliceB?: SharedSlice,
|
|
19
|
+
): Partial<SliceMetadata> {
|
|
20
|
+
const zippedSlices = Objects.zipObjects(sliceA, sliceB)
|
|
21
|
+
|
|
22
|
+
return Object.entries(zippedSlices).reduce((acc, [key, value]) => {
|
|
23
|
+
if (key === `variations`) return acc
|
|
24
|
+
|
|
25
|
+
if (value?.left === value?.right) return acc
|
|
26
|
+
return { ...acc, [key]: value?.right }
|
|
27
|
+
}, {})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const SliceComparator = {
|
|
31
|
+
compare(sliceA?: SharedSlice, sliceB?: SharedSlice): SliceDiff | undefined {
|
|
32
|
+
if (!sliceA && sliceB)
|
|
33
|
+
return {
|
|
34
|
+
op: DiffOperation.Added,
|
|
35
|
+
value: sliceB,
|
|
36
|
+
}
|
|
37
|
+
if (sliceA && !sliceB)
|
|
38
|
+
return {
|
|
39
|
+
op: DiffOperation.Removed,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const diffMeta = compareSliceMeta(sliceA, sliceB)
|
|
43
|
+
|
|
44
|
+
const zippedSlices = Objects.zipObjects<Variation>(
|
|
45
|
+
sliceA && Arrays.toRecord(sliceA.variations, (v) => v.id),
|
|
46
|
+
sliceB && Arrays.toRecord(sliceB.variations, (v) => v.id),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
const diffVariations = Object.entries(zippedSlices).reduce<
|
|
50
|
+
Partial<Record<string, VariationDiff>>
|
|
51
|
+
>((acc, [variationId, value]) => {
|
|
52
|
+
if (!value) return acc
|
|
53
|
+
|
|
54
|
+
const vDiff = VariationComparator.compare(value.left, value.right)
|
|
55
|
+
if (!vDiff) return acc
|
|
56
|
+
return {
|
|
57
|
+
...acc,
|
|
58
|
+
[variationId]: vDiff,
|
|
59
|
+
}
|
|
60
|
+
}, {})
|
|
61
|
+
|
|
62
|
+
const diffSlice = {
|
|
63
|
+
...diffMeta,
|
|
64
|
+
...(Objects.isNotEmpty(diffVariations)
|
|
65
|
+
? { variations: diffVariations }
|
|
66
|
+
: {}),
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (Objects.isNotEmpty(diffSlice)) {
|
|
70
|
+
return {
|
|
71
|
+
op: DiffOperation.Updated,
|
|
72
|
+
value: diffSlice,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return undefined
|
|
76
|
+
},
|
|
77
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Objects } from "../../utils"
|
|
2
|
+
import type { NestableWidget } from "../widgets/nestable"
|
|
3
|
+
import type { Variation } from "../widgets/slices"
|
|
4
|
+
import { type DiffChange, DiffOperation } from "./Changes"
|
|
5
|
+
|
|
6
|
+
type VariationMetadata = Omit<Variation, "primary" | "items">
|
|
7
|
+
export type VariationDiff = DiffChange<Variation, Partial<VariationMetadata>>
|
|
8
|
+
|
|
9
|
+
function compareVariationMeta(
|
|
10
|
+
variationA?: Variation,
|
|
11
|
+
variationB?: Variation,
|
|
12
|
+
): Partial<VariationMetadata> {
|
|
13
|
+
const zippedVariations = Objects.zipObjects(variationA, variationB)
|
|
14
|
+
|
|
15
|
+
return Object.entries(zippedVariations).reduce((acc, [key, value]) => {
|
|
16
|
+
if (key === `primary` || key === "items") return acc
|
|
17
|
+
|
|
18
|
+
if (value?.left === value?.right) return acc
|
|
19
|
+
return { ...acc, [key]: value?.right }
|
|
20
|
+
}, {})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function compareWidgets(
|
|
24
|
+
widgetsA?: { [key: string]: NestableWidget },
|
|
25
|
+
widgetsB?: { [key: string]: NestableWidget },
|
|
26
|
+
): Record<string, DiffChange<NestableWidget, NestableWidget>> | undefined {
|
|
27
|
+
const zippedWidgets = Objects.zipObjects(widgetsA, widgetsB)
|
|
28
|
+
|
|
29
|
+
const diffWidgets = Object.entries(zippedWidgets).reduce(
|
|
30
|
+
(acc, [widgetKey, widgetValue]) => {
|
|
31
|
+
if (
|
|
32
|
+
JSON.stringify(widgetValue?.left) === JSON.stringify(widgetValue?.right)
|
|
33
|
+
)
|
|
34
|
+
return acc
|
|
35
|
+
|
|
36
|
+
const changes = (() => {
|
|
37
|
+
if (!widgetValue?.left && !widgetValue?.right) return
|
|
38
|
+
if (widgetValue?.left && !widgetValue.right)
|
|
39
|
+
return {
|
|
40
|
+
op: DiffOperation.Removed,
|
|
41
|
+
}
|
|
42
|
+
if (!widgetValue?.left && widgetValue?.right)
|
|
43
|
+
return {
|
|
44
|
+
op: DiffOperation.Added,
|
|
45
|
+
value: widgetValue.right,
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
op: DiffOperation.Updated,
|
|
49
|
+
value: widgetValue.right,
|
|
50
|
+
}
|
|
51
|
+
})()
|
|
52
|
+
|
|
53
|
+
if (!changes) return acc
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...acc,
|
|
57
|
+
[widgetKey]: changes,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return Objects.isNotEmpty(diffWidgets) ? diffWidgets : undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const VariationComparator = {
|
|
67
|
+
compare(
|
|
68
|
+
variationA?: Variation,
|
|
69
|
+
variationB?: Variation,
|
|
70
|
+
): VariationDiff | undefined {
|
|
71
|
+
if (variationA && !variationB)
|
|
72
|
+
return {
|
|
73
|
+
op: DiffOperation.Removed,
|
|
74
|
+
}
|
|
75
|
+
if (!variationA && variationB) {
|
|
76
|
+
return {
|
|
77
|
+
op: DiffOperation.Added,
|
|
78
|
+
value: variationB,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const diffMeta = compareVariationMeta(variationA, variationB)
|
|
83
|
+
|
|
84
|
+
const diffPrimary = compareWidgets(variationA?.primary, variationB?.primary)
|
|
85
|
+
const diffItems = compareWidgets(variationA?.items, variationB?.items)
|
|
86
|
+
|
|
87
|
+
const diffVariation = {
|
|
88
|
+
...diffMeta,
|
|
89
|
+
...(diffPrimary ? { primary: diffPrimary } : {}),
|
|
90
|
+
...(diffItems ? { items: diffItems } : {}),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (Objects.isNotEmpty(diffVariation)) {
|
|
94
|
+
return {
|
|
95
|
+
op: DiffOperation.Updated,
|
|
96
|
+
value: diffVariation,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined
|
|
100
|
+
},
|
|
101
|
+
}
|
package/src/customtypes/index.ts
CHANGED
|
@@ -31,8 +31,10 @@ export type WidgetTypes = typeof WidgetTypes[keyof typeof WidgetTypes]
|
|
|
31
31
|
|
|
32
32
|
const widgetKeyRegex = new RegExp("^[^<>]+$")
|
|
33
33
|
|
|
34
|
-
export const WidgetKey = refineType(
|
|
35
|
-
|
|
34
|
+
export const WidgetKey = refineType(
|
|
35
|
+
t.string,
|
|
36
|
+
"WidgetKey",
|
|
37
|
+
(s: string) => s.length === 0 || widgetKeyRegex.test(s),
|
|
36
38
|
)
|
|
37
39
|
|
|
38
40
|
export type WidgetKey = t.TypeOf<typeof WidgetKey>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function zipObjects<A, B = A>(
|
|
2
|
+
objLeft?: Partial<Record<string, A>>,
|
|
3
|
+
objRight?: Partial<Record<string, B>>,
|
|
4
|
+
): Partial<Record<string, { left?: A; right?: B }>> {
|
|
5
|
+
const allKeys = [
|
|
6
|
+
...new Set(Object.keys(objLeft || {}).concat(Object.keys(objRight || {}))),
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
return allKeys.reduce<Record<string, { left?: A; right?: B } | undefined>>(
|
|
10
|
+
(acc, key) => {
|
|
11
|
+
const left = objLeft?.[key]
|
|
12
|
+
const right = objRight?.[key]
|
|
13
|
+
return {
|
|
14
|
+
...acc,
|
|
15
|
+
[key]: { left, right },
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
{},
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isNotEmpty<A extends object>(obj: A): boolean {
|
|
23
|
+
return Boolean(Object.keys(obj).length)
|
|
24
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
-
|
|
5
|
-
### [0.3.1](https://github.com/prismicio/prismic-types-internal/compare/v0.3.1-beta.0...v0.3.1) (2022-07-06)
|
|
6
|
-
|
|
7
|
-
### [0.3.1-beta.0](https://github.com/prismicio/prismic-types-internal/compare/v0.3.0...v0.3.1-beta.0) (2022-06-23)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Bug Fixes
|
|
11
|
-
|
|
12
|
-
* test StructuredTextContent ([62405b5](https://github.com/prismicio/prismic-types-internal/commit/62405b538e7db959f79fa6933129bb7f9ca008e1))
|
|
13
|
-
* validate widget id format ([fe0fbec](https://github.com/prismicio/prismic-types-internal/commit/fe0fbec5287178b9d7ae5f97c4b4c3edbf364c21))
|