@prismicio/types-internal 1.4.0 → 1.5.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 (43) hide show
  1. package/lib/content/CustomType.d.ts +2964 -0
  2. package/lib/content/CustomType.js +15 -0
  3. package/lib/content/fields/UIDContent.d.ts +6 -0
  4. package/lib/content/fields/UIDContent.js +10 -0
  5. package/lib/content/fields/index.d.ts +1 -0
  6. package/lib/content/fields/index.js +1 -0
  7. package/lib/content/fields/slices/CompositeSliceContent.d.ts +739 -0
  8. package/lib/content/fields/slices/CompositeSliceContent.js +12 -0
  9. package/lib/content/fields/slices/SharedSliceContent.d.ts +343 -346
  10. package/lib/content/fields/slices/SharedSliceContent.js +1 -2
  11. package/lib/content/fields/slices/SimpleSliceContent.d.ts +741 -0
  12. package/lib/content/fields/slices/SimpleSliceContent.js +8 -0
  13. package/lib/content/fields/slices/SlicesContent.d.ts +4440 -0
  14. package/lib/content/fields/slices/SlicesContent.js +23 -0
  15. package/lib/content/fields/slices/index.d.ts +3 -0
  16. package/lib/content/fields/slices/index.js +3 -0
  17. package/lib/content/index.d.ts +1 -0
  18. package/lib/content/index.js +1 -0
  19. package/lib/customtypes/diff/Changes.d.ts +17 -0
  20. package/lib/customtypes/diff/Changes.js +9 -0
  21. package/lib/customtypes/diff/SharedSlice.d.ts +679 -0
  22. package/lib/customtypes/diff/SharedSlice.js +55 -0
  23. package/lib/customtypes/diff/Variation.d.ts +662 -0
  24. package/lib/customtypes/diff/Variation.js +75 -0
  25. package/lib/customtypes/diff/index.d.ts +3 -0
  26. package/lib/customtypes/diff/index.js +6 -0
  27. package/lib/customtypes/index.d.ts +1 -1
  28. package/lib/customtypes/index.js +1 -1
  29. package/package.json +2 -1
  30. package/src/content/CustomType.ts +20 -0
  31. package/src/content/fields/UIDContent.ts +10 -0
  32. package/src/content/fields/index.ts +1 -0
  33. package/src/content/fields/slices/CompositeSliceContent.ts +12 -0
  34. package/src/content/fields/slices/SharedSliceContent.ts +1 -2
  35. package/src/content/fields/slices/SimpleSliceContent.ts +7 -0
  36. package/src/content/fields/slices/SlicesContent.ts +26 -0
  37. package/src/content/fields/slices/index.ts +3 -0
  38. package/src/content/index.ts +1 -0
  39. package/src/customtypes/{comparators → diff}/Changes.ts +0 -0
  40. package/src/customtypes/{comparators → diff}/SharedSlice.ts +0 -0
  41. package/src/customtypes/{comparators → diff}/Variation.ts +0 -0
  42. package/src/customtypes/{comparators → diff}/index.ts +0 -0
  43. package/src/customtypes/index.ts +1 -1
@@ -0,0 +1,75 @@
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) === JSON.stringify(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
20
+ return acc;
21
+ const changes = (() => {
22
+ if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
23
+ return;
24
+ if ((widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !widgetValue.right)
25
+ return {
26
+ op: Changes_1.DiffOperation.Removed,
27
+ };
28
+ if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && (widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
29
+ return {
30
+ op: Changes_1.DiffOperation.Added,
31
+ value: widgetValue.right,
32
+ };
33
+ return {
34
+ op: Changes_1.DiffOperation.Updated,
35
+ value: widgetValue.right,
36
+ };
37
+ })();
38
+ if (!changes)
39
+ return acc;
40
+ return {
41
+ ...acc,
42
+ [widgetKey]: changes,
43
+ };
44
+ }, {});
45
+ return utils_1.Objects.isNotEmpty(diffWidgets) ? diffWidgets : undefined;
46
+ }
47
+ exports.VariationComparator = {
48
+ compare(variationA, variationB) {
49
+ if (variationA && !variationB)
50
+ return {
51
+ op: Changes_1.DiffOperation.Removed,
52
+ };
53
+ if (!variationA && variationB) {
54
+ return {
55
+ op: Changes_1.DiffOperation.Added,
56
+ value: variationB,
57
+ };
58
+ }
59
+ const diffMeta = compareVariationMeta(variationA, variationB);
60
+ const diffPrimary = compareWidgets(variationA === null || variationA === void 0 ? void 0 : variationA.primary, variationB === null || variationB === void 0 ? void 0 : variationB.primary);
61
+ const diffItems = compareWidgets(variationA === null || variationA === void 0 ? void 0 : variationA.items, variationB === null || variationB === void 0 ? void 0 : variationB.items);
62
+ const diffVariation = {
63
+ ...diffMeta,
64
+ ...(diffPrimary ? { primary: diffPrimary } : {}),
65
+ ...(diffItems ? { items: diffItems } : {}),
66
+ };
67
+ if (utils_1.Objects.isNotEmpty(diffVariation)) {
68
+ return {
69
+ op: Changes_1.DiffOperation.Updated,
70
+ value: diffVariation,
71
+ };
72
+ }
73
+ return undefined;
74
+ },
75
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./Changes";
2
+ export * from "./SharedSlice";
3
+ export * from "./Variation";
@@ -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);
@@ -1,4 +1,4 @@
1
- export * as Comparators from "./comparators";
2
1
  export * from "./CustomType";
2
+ export * as Comparators from "./diff";
3
3
  export * as Section from "./Section";
4
4
  export * as Widgets from "./widgets";
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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"));
6
5
  (0, tslib_1.__exportStar)(require("./CustomType"), exports);
6
+ exports.Comparators = (0, tslib_1.__importStar)(require("./diff"));
7
7
  exports.Section = (0, tslib_1.__importStar)(require("./Section"));
8
8
  exports.Widgets = (0, tslib_1.__importStar)(require("./widgets"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -40,6 +40,7 @@
40
40
  "tslib": "^2.3.1"
41
41
  },
42
42
  "devDependencies": {
43
+ "@fast-check/jest": "^1.4.0",
43
44
  "@relmify/jest-fp-ts": "^1.1.1",
44
45
  "@types/jest": "^27.4.0",
45
46
  "@typescript-eslint/eslint-plugin": "^5.8.1",
@@ -0,0 +1,20 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { WidgetKey as KeyForWidgetContent } from "../documents/widgets"
4
+ import {
5
+ GroupContent,
6
+ NestableContent,
7
+ SlicesContent,
8
+ UIDContent,
9
+ } from "./fields"
10
+
11
+ export const WidgetKey = KeyForWidgetContent
12
+
13
+ const WidgetContent = t.union([
14
+ SlicesContent,
15
+ UIDContent,
16
+ NestableContent,
17
+ GroupContent,
18
+ ])
19
+ export const CustomTypeContent = t.record(WidgetKey, WidgetContent)
20
+ export type CustomTypeContent = t.TypeOf<typeof CustomTypeContent>
@@ -0,0 +1,10 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { UIDContentType } from "../../documents/widgets/UIDContent"
4
+
5
+ export const UIDContent = t.type({
6
+ __TYPE__: t.literal(UIDContentType),
7
+ value: t.string,
8
+ })
9
+
10
+ export type UIDContent = t.TypeOf<typeof UIDContent>
@@ -1,3 +1,4 @@
1
1
  export * from "./GroupContent"
2
2
  export * from "./nestable"
3
3
  export * from "./slices"
4
+ export * from "./UIDContent"
@@ -0,0 +1,12 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { CompositeSliceContentType } from "../../../documents/widgets/slices"
4
+ import { NestableContent } from "../nestable"
5
+
6
+ export const CompositeSliceContent = t.type({
7
+ __TYPE__: t.literal(CompositeSliceContentType),
8
+ repeat: t.array(t.tuple([t.string, NestableContent])),
9
+ "non-repeat": t.record(t.string, NestableContent),
10
+ })
11
+
12
+ export type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>
@@ -1,14 +1,13 @@
1
1
  import * as t from "io-ts"
2
2
 
3
3
  import { SharedSliceContentType as type } from "../../../documents/widgets/slices"
4
- import { GroupItemContent } from "../GroupContent"
5
4
  import { NestableContent } from "../nestable"
6
5
 
7
6
  export const SharedSliceContent = t.strict({
8
7
  __TYPE__: t.literal(type),
9
8
  variation: t.string,
10
9
  primary: t.record(t.string, NestableContent),
11
- items: t.array(GroupItemContent),
10
+ items: t.array(t.tuple([t.string, NestableContent])),
12
11
  })
13
12
  export type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>
14
13
  export const SharedSliceContentType = type
@@ -0,0 +1,7 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { GroupContent } from "../GroupContent"
4
+ import { NestableContent } from "../nestable"
5
+
6
+ export const SimpleSliceContent = t.union([NestableContent, GroupContent])
7
+ export type SimpleSliceContent = t.TypeOf<typeof SimpleSliceContent>
@@ -0,0 +1,26 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { SlicesContentType } from "../../../documents/widgets/slices"
4
+ import { CompositeSliceContent } from "./CompositeSliceContent"
5
+ import { SharedSliceContent } from "./SharedSliceContent"
6
+ import { SimpleSliceContent } from "./SimpleSliceContent"
7
+
8
+ export const SliceItemContent = t.type({
9
+ key: t.string,
10
+ name: t.string,
11
+ maybeLabel: t.union([t.string, t.undefined]),
12
+ widget: t.union([
13
+ CompositeSliceContent,
14
+ SharedSliceContent,
15
+ SimpleSliceContent,
16
+ ]),
17
+ })
18
+
19
+ export type SliceContentItem = t.TypeOf<typeof SliceItemContent>
20
+
21
+ export const SlicesContent = t.type({
22
+ __TYPE__: t.literal(SlicesContentType),
23
+ value: t.array(SliceItemContent),
24
+ })
25
+
26
+ export type SlicesContent = t.TypeOf<typeof SlicesContent>
@@ -1 +1,4 @@
1
+ export * from "./CompositeSliceContent"
1
2
  export * from "./SharedSliceContent"
3
+ export * from "./SimpleSliceContent"
4
+ export * from "./SlicesContent"
@@ -1 +1,2 @@
1
+ export * from "./CustomType"
1
2
  export * from "./fields"
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- export * as Comparators from "./comparators"
2
1
  export * from "./CustomType"
2
+ export * as Comparators from "./diff"
3
3
  export * as Section from "./Section"
4
4
  export * as Widgets from "./widgets"