@prismicio/types-internal 1.1.1 → 1.2.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/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/Format.d.ts +4 -0
- package/lib/customtypes/Format.js +8 -0
- 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/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 +23 -0
- package/src/utils/index.ts +2 -0
- package/CHANGELOG.md +0 -13
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VariationComparator = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const Changes_1 = require("./Changes");
|
|
6
|
+
function compareVariationMeta(variationA, variationB) {
|
|
7
|
+
const zippedVariations = utils_1.Objects.zipObjects(variationA, variationB);
|
|
8
|
+
return Object.entries(zippedVariations).reduce((acc, [key, value]) => {
|
|
9
|
+
if (key === `primary` || key === 'items')
|
|
10
|
+
return acc;
|
|
11
|
+
if ((value === null || value === void 0 ? void 0 : value.left) === (value === null || value === void 0 ? void 0 : value.right))
|
|
12
|
+
return acc;
|
|
13
|
+
return { ...acc, [key]: value === null || value === void 0 ? void 0 : value.right };
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
function compareWidgets(widgetsA, widgetsB) {
|
|
17
|
+
const zippedWidgets = utils_1.Objects.zipObjects(widgetsA, widgetsB);
|
|
18
|
+
const diffWidgets = Object.entries(zippedWidgets).reduce((acc, [widgetKey, widgetValue]) => {
|
|
19
|
+
if (JSON.stringify(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) ===
|
|
20
|
+
JSON.stringify(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
|
|
21
|
+
return acc;
|
|
22
|
+
const changes = (() => {
|
|
23
|
+
if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
|
|
24
|
+
return;
|
|
25
|
+
if ((widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !widgetValue.right)
|
|
26
|
+
return {
|
|
27
|
+
op: Changes_1.DiffOperation.Removed,
|
|
28
|
+
};
|
|
29
|
+
if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && (widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
|
|
30
|
+
return {
|
|
31
|
+
op: Changes_1.DiffOperation.Added,
|
|
32
|
+
value: widgetValue.right,
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
op: Changes_1.DiffOperation.Updated,
|
|
36
|
+
value: widgetValue.right,
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
if (!changes)
|
|
40
|
+
return acc;
|
|
41
|
+
return {
|
|
42
|
+
...acc,
|
|
43
|
+
[widgetKey]: changes,
|
|
44
|
+
};
|
|
45
|
+
}, {});
|
|
46
|
+
return utils_1.Objects.isNotEmpty(diffWidgets) ? diffWidgets : undefined;
|
|
47
|
+
}
|
|
48
|
+
exports.VariationComparator = {
|
|
49
|
+
compare(variationA, variationB) {
|
|
50
|
+
if (variationA && !variationB)
|
|
51
|
+
return {
|
|
52
|
+
op: Changes_1.DiffOperation.Removed,
|
|
53
|
+
};
|
|
54
|
+
if (!variationA && variationB) {
|
|
55
|
+
return {
|
|
56
|
+
op: Changes_1.DiffOperation.Added,
|
|
57
|
+
value: variationB,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const diffMeta = compareVariationMeta(variationA, variationB);
|
|
61
|
+
const diffPrimary = compareWidgets(variationA === null || variationA === void 0 ? void 0 : variationA.primary, variationB === null || variationB === void 0 ? void 0 : variationB.primary);
|
|
62
|
+
const diffItems = compareWidgets(variationA === null || variationA === void 0 ? void 0 : variationA.items, variationB === null || variationB === void 0 ? void 0 : variationB.items);
|
|
63
|
+
const diffVariation = {
|
|
64
|
+
...diffMeta,
|
|
65
|
+
...(diffPrimary ? { primary: diffPrimary } : {}),
|
|
66
|
+
...(diffItems ? { items: diffItems } : {}),
|
|
67
|
+
};
|
|
68
|
+
if (utils_1.Objects.isNotEmpty(diffVariation)) {
|
|
69
|
+
return {
|
|
70
|
+
op: Changes_1.DiffOperation.Updated,
|
|
71
|
+
value: diffVariation,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./Changes"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./SharedSlice"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./Variation"), exports);
|
package/lib/customtypes/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Widgets = exports.Section = void 0;
|
|
3
|
+
exports.Widgets = exports.Section = exports.Comparators = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
exports.Comparators = (0, tslib_1.__importStar)(require("./comparators"));
|
|
5
6
|
(0, tslib_1.__exportStar)(require("./CustomType"), exports);
|
|
6
7
|
exports.Section = (0, tslib_1.__importStar)(require("./Section"));
|
|
7
8
|
exports.Widgets = (0, tslib_1.__importStar)(require("./widgets"));
|