@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.
Files changed (52) hide show
  1. package/lib/customtypes/Comparators/Changes.d.ts +17 -0
  2. package/lib/customtypes/Comparators/Changes.js +9 -0
  3. package/lib/customtypes/Comparators/SharedSlice.d.ts +679 -0
  4. package/lib/customtypes/Comparators/SharedSlice.js +55 -0
  5. package/lib/customtypes/Comparators/Variation.d.ts +662 -0
  6. package/lib/customtypes/Comparators/Variation.js +75 -0
  7. package/lib/customtypes/Comparators/index.d.ts +3 -0
  8. package/lib/customtypes/Comparators/index.js +6 -0
  9. package/lib/customtypes/CustomType.d.ts +932 -932
  10. package/lib/customtypes/Format.d.ts +4 -0
  11. package/lib/customtypes/Format.js +8 -0
  12. package/lib/customtypes/Section.d.ts +932 -932
  13. package/lib/customtypes/comp/Changes.d.ts +17 -0
  14. package/lib/customtypes/comp/Changes.js +9 -0
  15. package/lib/customtypes/comp/SharedSlice.d.ts +679 -0
  16. package/lib/customtypes/comp/SharedSlice.js +55 -0
  17. package/lib/customtypes/comp/Variation.d.ts +662 -0
  18. package/lib/customtypes/comp/Variation.js +76 -0
  19. package/lib/customtypes/comp/index.d.ts +3 -0
  20. package/lib/customtypes/comp/index.js +6 -0
  21. package/lib/customtypes/index.d.ts +1 -0
  22. package/lib/customtypes/index.js +2 -1
  23. package/lib/customtypes/utils/Comparator.d.ts +1353 -0
  24. package/lib/customtypes/utils/Comparator.js +59 -0
  25. package/lib/customtypes/utils/index.d.ts +1 -0
  26. package/lib/customtypes/utils/index.js +4 -0
  27. package/lib/customtypes/widgets/Widget.d.ts +664 -664
  28. package/lib/customtypes/widgets/slices/Slices.d.ts +792 -792
  29. package/lib/documents/widgets/index.js +1 -1
  30. package/lib/documents/widgets/nestable/EmbedContent.d.ts +4 -4
  31. package/lib/documents/widgets/nestable/ImageContent.d.ts +14 -14
  32. package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +4 -4
  33. package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +2 -2
  34. package/lib/documents/widgets/nestable/Link/index.d.ts +4 -4
  35. package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +8 -8
  36. package/lib/utils/Arrays.d.ts +1 -0
  37. package/lib/utils/Arrays.js +13 -0
  38. package/lib/utils/Objects.d.ts +5 -0
  39. package/lib/utils/Objects.js +21 -0
  40. package/lib/utils/index.d.ts +2 -0
  41. package/lib/utils/index.js +6 -0
  42. package/package.json +2 -2
  43. package/src/customtypes/comparators/Changes.ts +21 -0
  44. package/src/customtypes/comparators/SharedSlice.ts +77 -0
  45. package/src/customtypes/comparators/Variation.ts +101 -0
  46. package/src/customtypes/comparators/index.ts +3 -0
  47. package/src/customtypes/index.ts +1 -0
  48. package/src/documents/widgets/index.ts +4 -2
  49. package/src/utils/Arrays.ts +12 -0
  50. package/src/utils/Objects.ts +24 -0
  51. package/src/utils/index.ts +2 -0
  52. package/CHANGELOG.md +0 -13
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SliceComparator = exports.DiffOperation = void 0;
4
+ const utils_1 = require("../../utils");
5
+ var DiffOperation;
6
+ (function (DiffOperation) {
7
+ DiffOperation["Added"] = "added";
8
+ DiffOperation["Removed"] = "removed";
9
+ DiffOperation["Updated"] = "updated";
10
+ })(DiffOperation = exports.DiffOperation || (exports.DiffOperation = {}));
11
+ function compareSliceMeta(sliceA, sliceB) {
12
+ const zippedSlices = utils_1.Objects.zipObjects(sliceA, sliceB);
13
+ return Object.entries(zippedSlices).reduce((acc, [key, value]) => {
14
+ if (key === `variations`)
15
+ return acc;
16
+ if ((value === null || value === void 0 ? void 0 : value.left) === (value === null || value === void 0 ? void 0 : value.right))
17
+ return acc;
18
+ return { ...acc, [key]: value === null || value === void 0 ? void 0 : value.right };
19
+ }, {});
20
+ }
21
+ exports.SliceComparator = {
22
+ compare(sliceA, sliceB) {
23
+ if (!sliceA && sliceB)
24
+ return {
25
+ op: DiffOperation.Added,
26
+ value: sliceB,
27
+ };
28
+ if (sliceA && !sliceB)
29
+ return {
30
+ op: DiffOperation.Removed,
31
+ };
32
+ const diffMeta = compareSliceMeta(sliceA, sliceB);
33
+ const zippedSlices = utils_1.Objects.zipObjects(sliceA && utils_1.Arrays.toRecord(sliceA.variations, (v) => v.id), sliceB && utils_1.Arrays.toRecord(sliceB.variations, (v) => v.id));
34
+ const diffVariations = Object.entries(zippedSlices).reduce((acc, [variationId, value]) => {
35
+ if (!value)
36
+ return acc;
37
+ const vDiff = VariationComparator.compare(value.left, value.right);
38
+ if (!vDiff)
39
+ return acc;
40
+ return {
41
+ ...acc,
42
+ [variationId]: vDiff,
43
+ };
44
+ }, {});
45
+ const diffSlice = {
46
+ ...diffMeta,
47
+ ...(utils_1.Objects.isNotEmpty(diffVariations)
48
+ ? { variations: diffVariations }
49
+ : {}),
50
+ };
51
+ if (utils_1.Objects.isNotEmpty(diffSlice)) {
52
+ return {
53
+ op: DiffOperation.Updated,
54
+ value: diffSlice,
55
+ };
56
+ }
57
+ return undefined;
58
+ },
59
+ };
@@ -0,0 +1 @@
1
+ export * from "./Comparator";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./Comparator"), exports);