@prismicio/types-internal 2.0.0-alpha.4 → 2.0.0-alpha.5

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 (31) hide show
  1. package/lib/content/Document.js +4 -3
  2. package/lib/content/fields/GroupContent.d.ts +1 -1
  3. package/lib/content/fields/GroupContent.js +3 -3
  4. package/lib/content/fields/nestable/EmbedContent.d.ts +0 -1
  5. package/lib/content/fields/nestable/NestableContent.js +2 -1
  6. package/lib/content/fields/nestable/RichTextContent/Blocks.js +4 -4
  7. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +4 -4
  8. package/lib/content/fields/slices/Slice/SharedSliceContent.js +4 -4
  9. package/lib/content/fields/slices/SliceItem.js +2 -1
  10. package/lib/content/utils.js +3 -3
  11. package/lib/customtypes/index.d.ts +2 -2
  12. package/lib/customtypes/index.js +2 -3
  13. package/lib/customtypes/widgets/nestable/RichText.js +10 -10
  14. package/lib/customtypes/widgets/slices/Slices.d.ts +12 -3
  15. package/lib/customtypes/widgets/slices/Slices.js +4 -4
  16. package/lib/customtypes/widgets/slices/index.d.ts +6 -6
  17. package/lib/customtypes/widgets/slices/index.js +6 -11
  18. package/package.json +1 -1
  19. package/src/content/Document.ts +4 -3
  20. package/src/content/fields/GroupContent.ts +4 -4
  21. package/src/content/fields/nestable/EmbedContent.ts +1 -1
  22. package/src/content/fields/nestable/NestableContent.ts +2 -1
  23. package/src/content/fields/nestable/RichTextContent/Blocks.ts +4 -4
  24. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -3
  25. package/src/content/fields/slices/Slice/SharedSliceContent.ts +4 -3
  26. package/src/content/fields/slices/SliceItem.ts +2 -2
  27. package/src/content/utils.ts +4 -5
  28. package/src/customtypes/index.ts +2 -2
  29. package/src/customtypes/widgets/nestable/RichText.ts +15 -15
  30. package/src/customtypes/widgets/slices/Slices.ts +4 -4
  31. package/src/customtypes/widgets/slices/index.ts +6 -6
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentLegacy = exports.Document = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
6
7
  const function_1 = require("fp-ts/lib/function");
7
8
  const t = tslib_1.__importStar(require("io-ts"));
8
9
  const common_1 = require("../common");
@@ -16,7 +17,7 @@ const DocumentLegacyCodec = (allTypes) => {
16
17
  return Object.entries(parsedDoc).reduce((acc, [widgetKey, widgetValue]) => {
17
18
  const widgetCtx = (0, LegacyContentCtx_1.defaultCtx)(widgetKey, allTypes);
18
19
  const parsedW = (0, fields_1.WidgetLegacy)(widgetCtx).decode(widgetValue);
19
- if (!parsedW || (parsedW === null || parsedW === void 0 ? void 0 : parsedW._tag) === "Left")
20
+ if (!parsedW || (0, Either_1.isLeft)(parsedW))
20
21
  return acc;
21
22
  return { ...acc, [widgetKey]: parsedW.right };
22
23
  }, {});
@@ -39,7 +40,7 @@ function extractMetadata(data) {
39
40
  const { types, widgets } = fields.reduce((acc, [k, v]) => {
40
41
  if (k.endsWith("_TYPE")) {
41
42
  const decodedValue = LegacyContentCtx_1.FieldOrSliceType.decode(v);
42
- if (decodedValue._tag === "Right") {
43
+ if ((0, Either_1.isRight)(decodedValue)) {
43
44
  return {
44
45
  ...acc,
45
46
  types: acc.types.set(k.substring(0, k.length - 5), decodedValue.right),
@@ -78,7 +79,7 @@ function parseLegacyDocument(legacyDoc) {
78
79
  // parse the actual widgets
79
80
  return DocumentLegacyCodec(types).decode(widgets);
80
81
  }));
81
- return result._tag === "Left" ? undefined : result.right;
82
+ return (0, Either_1.isLeft)(result) ? undefined : result.right;
82
83
  }
83
84
  function encodeToLegacyDocument(document) {
84
85
  const encoded = DocumentLegacyCodec().encode(document);
@@ -315,7 +315,7 @@ export declare const GroupItemContent: t.ExactC<t.TypeC<{
315
315
  }>>;
316
316
  export type GroupItemContent = t.TypeOf<typeof GroupItemContent>;
317
317
  declare const itemLegacyReader: t.ArrayC<t.TupleC<[t.StringC, t.UnknownC]>>;
318
- export type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>;
318
+ type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>;
319
319
  export declare const GroupItemLegacy: (ctx: LegacyContentCtx) => t.Type<{
320
320
  __TYPE__: "GroupItemContent";
321
321
  value: [string, {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
6
7
  const function_1 = require("fp-ts/lib/function");
7
8
  const t = tslib_1.__importStar(require("io-ts"));
8
9
  const LegacyContentCtx_1 = require("../LegacyContentCtx");
@@ -22,10 +23,9 @@ const GroupItemLegacy = (ctx) => {
22
23
  const result = (0, nestable_1.NestableLegacy)(itemCtx).decode(itemValue);
23
24
  if (!result)
24
25
  return acc;
25
- if (result._tag === "Right")
26
- return [...acc, [itemKey, result.right]];
27
- else
26
+ if ((0, Either_1.isLeft)(result))
28
27
  return acc;
28
+ return [...acc, [itemKey, result.right]];
29
29
  }, []);
30
30
  return {
31
31
  value: parsedItems,
@@ -35,7 +35,6 @@ export declare const EmbedContentLegacy: t.ExactC<t.IntersectionC<[t.TypeC<{
35
35
  thumbnail_height: t.UnionC<[t.Type<number, number, unknown>, t.NullC, t.UndefinedC]>;
36
36
  html: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
37
37
  }>]>>;
38
- export type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>;
39
38
  export declare const EmbedLegacy: (ctx: LegacyContentCtx) => t.Type<{
40
39
  embed_url: string;
41
40
  type: string;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NestableLegacy = exports.isNestableContent = exports.NestableContent = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const Either_1 = require("fp-ts/lib/Either");
5
6
  const t = tslib_1.__importStar(require("io-ts"));
6
7
  const EmptyContent_1 = require("../EmptyContent");
7
8
  const BooleanContent_1 = require("./BooleanContent");
@@ -54,7 +55,7 @@ const NestableLegacy = (ctx) => {
54
55
  if (!ctx.fieldType)
55
56
  return;
56
57
  const nullValue = (0, EmptyContent_1.EmptyLegacy)(ctx.fieldType).decode(value);
57
- if (nullValue._tag === "Right")
58
+ if ((0, Either_1.isRight)(nullValue))
58
59
  return nullValue;
59
60
  const codec = (() => {
60
61
  switch (ctx.fieldType) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Block = exports.BlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
- const E = tslib_1.__importStar(require("fp-ts/lib/Either"));
6
+ const Either_1 = require("fp-ts/lib/Either");
7
7
  const function_1 = require("fp-ts/lib/function");
8
8
  const t = tslib_1.__importStar(require("io-ts"));
9
9
  const nestable_1 = require("../../../../customtypes/widgets/nestable");
@@ -29,12 +29,12 @@ const ValidatedMetas = (linkCodec) => new t.Type("ValidatedMetas", (metas) => Ar
29
29
  const res = metas
30
30
  .reduce((acc, maybeMeta) => {
31
31
  const maybeDecodedMeta = exports.Meta.decode(maybeMeta);
32
- if (E.isRight(maybeDecodedMeta)) {
32
+ if ((0, Either_1.isRight)(maybeDecodedMeta)) {
33
33
  const meta = maybeDecodedMeta.right;
34
34
  // if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
35
35
  if (meta.data && meta.type === "hyperlink") {
36
36
  const decoded = linkCodec.decode(meta.data);
37
- if (decoded._tag === "Left")
37
+ if ((0, Either_1.isLeft)(decoded))
38
38
  return acc;
39
39
  return [...acc, { ...meta, data: decoded.right }];
40
40
  }
@@ -54,7 +54,7 @@ const ValidatedMetas = (linkCodec) => new t.Type("ValidatedMetas", (metas) => Ar
54
54
  if (meta.type === "hyperlink" && meta.data) {
55
55
  // since the Span data are typed as unknown we have to redecode for type safety and then encode to either new format or legacy.
56
56
  const decoded = linkCodec.decode(meta.data);
57
- if (decoded._tag === "Left")
57
+ if ((0, Either_1.isLeft)(decoded))
58
58
  return acc;
59
59
  return [...acc, { ...meta, data: linkCodec.encode(decoded.right) }];
60
60
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
6
7
  const function_1 = require("fp-ts/lib/function");
7
8
  const t = tslib_1.__importStar(require("io-ts"));
8
9
  const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
@@ -22,7 +23,7 @@ const CompositeSliceLegacy = (ctx) => {
22
23
  const repeat = (() => {
23
24
  const itemsCtx = (0, LegacyContentCtx_1.getFieldCtx)("repeat", ctx);
24
25
  const result = (0, RepeatableContent_1.RepeatableWidgetsLegacy)(itemsCtx).decode(parsedSlice.repeat);
25
- if (!result || result._tag === "Left")
26
+ if (!result || (0, Either_1.isLeft)(result))
26
27
  return;
27
28
  return result.right;
28
29
  })() || [];
@@ -33,10 +34,9 @@ const CompositeSliceLegacy = (ctx) => {
33
34
  const result = (0, nestable_1.NestableLegacy)(fieldCtx).decode(value);
34
35
  if (!result)
35
36
  return acc;
36
- if (result._tag === "Right")
37
- return { ...acc, [key]: result.right };
38
- else
37
+ if ((0, Either_1.isLeft)(result))
39
38
  return acc;
39
+ return { ...acc, [key]: result.right };
40
40
  }, {});
41
41
  return {
42
42
  nonRepeat,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SharedSliceContent = exports.SharedSliceLegacy = exports.isSharedSliceContent = exports.SharedSliceContentType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
6
7
  const function_1 = require("fp-ts/lib/function");
7
8
  const t = tslib_1.__importStar(require("io-ts"));
8
9
  const io_ts_types_1 = require("io-ts-types");
@@ -27,7 +28,7 @@ const SharedSliceLegacy = (ctx) => {
27
28
  parsedSlice.variation,
28
29
  ]);
29
30
  const result = (0, RepeatableContent_1.RepeatableWidgetsLegacy)(itemsCtx).decode(parsedSlice.items);
30
- if (!result || result._tag === "Left")
31
+ if (!result || (0, Either_1.isLeft)(result))
31
32
  return;
32
33
  return result.right;
33
34
  })() || [];
@@ -40,10 +41,9 @@ const SharedSliceLegacy = (ctx) => {
40
41
  const result = (0, nestable_1.NestableLegacy)(FieldCtx).decode(value);
41
42
  if (!result)
42
43
  return acc;
43
- if (result._tag === "Right")
44
- return { ...acc, [key]: result.right };
45
- else
44
+ if ((0, Either_1.isLeft)(result))
46
45
  return acc;
46
+ return { ...acc, [key]: result.right };
47
47
  }, {});
48
48
  return {
49
49
  variation: parsedSlice.variation,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SlicesItemLegacy = exports.SliceItemContent = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
+ const Either_1 = require("fp-ts/lib/Either");
6
7
  const function_1 = require("fp-ts/lib/function");
7
8
  const t = tslib_1.__importStar(require("io-ts"));
8
9
  const function_2 = require("../../../validators/function");
@@ -36,7 +37,7 @@ const SlicesItemLegacy = (ctx) => {
36
37
  const sliceName = parsedSlice.key.substring(0, stopIdx > 0 ? stopIdx : undefined);
37
38
  const itemCtx = (0, LegacyContentCtx_1.getFieldCtx)(parsedSlice.key, ctx);
38
39
  const item = (0, Slice_1.SliceLegacy)(itemCtx).decode(parsedSlice.value);
39
- if (!item || item._tag === "Left")
40
+ if (!item || (0, Either_1.isLeft)(item))
40
41
  return t.failure(sliceItem, context);
41
42
  return t.success({
42
43
  key: parsedSlice.key,
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasContentType = exports.hasFieldContentType = void 0;
4
+ const Either_1 = require("fp-ts/lib/Either");
4
5
  const fields_1 = require("./fields");
5
6
  function hasFieldContentType(obj) {
6
7
  return (hasContentType(obj) &&
7
8
  obj.__TYPE__ === fields_1.FieldContentType &&
8
9
  (obj === null || obj === void 0 ? void 0 : obj.type) !== undefined &&
9
10
  typeof obj.type === "string" &&
10
- fields_1.FieldType.decode(obj.type)._tag === "Right");
11
+ (0, Either_1.isRight)(fields_1.FieldType.decode(obj.type)));
11
12
  }
12
13
  exports.hasFieldContentType = hasFieldContentType;
13
14
  function hasContentType(obj) {
14
- return ((obj === null || obj === void 0 ? void 0 : obj.__TYPE__) !== undefined &&
15
- typeof obj.__TYPE__ === "string");
15
+ return typeof obj.__TYPE__ === "string";
16
16
  }
17
17
  exports.hasContentType = hasContentType;
@@ -1,4 +1,4 @@
1
1
  export * from "./CustomType";
2
- export * as Comparators from "./diff";
3
- export * as Section from "./Section";
2
+ export * from "./diff";
3
+ export * from "./Section";
4
4
  export * from "./widgets";
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Section = exports.Comparators = void 0;
4
3
  const tslib_1 = require("tslib");
5
4
  tslib_1.__exportStar(require("./CustomType"), exports);
6
- exports.Comparators = tslib_1.__importStar(require("./diff"));
7
- exports.Section = tslib_1.__importStar(require("./Section"));
5
+ tslib_1.__exportStar(require("./diff"), exports);
6
+ tslib_1.__exportStar(require("./Section"), exports);
8
7
  tslib_1.__exportStar(require("./widgets"), exports);
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RichText = exports.RichTextConfig = exports.RichTextNodeTypeCodec = exports.RichTextNodeType = exports.DEFAULT_OPTION = exports.RichTextFieldType = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const fp_ts_1 = require("fp-ts/");
5
6
  const Either_1 = require("fp-ts/lib/Either");
7
+ const function_1 = require("fp-ts/lib/function");
6
8
  const t = tslib_1.__importStar(require("io-ts"));
7
9
  const validators_1 = require("../../../validators");
8
10
  const ImageConstraint_1 = tslib_1.__importDefault(require("../shared/ImageConstraint"));
@@ -44,18 +46,18 @@ exports.RichTextNodeTypeCodec = t.keyof({
44
46
  [exports.RichTextNodeType.orderedList]: null,
45
47
  [exports.RichTextNodeType.rtl]: null,
46
48
  });
47
- const RichTextOptions = new t.Type("RichTextOptions", (u) => typeof u === "string", (u, context) => {
48
- return Either_1.either.chain(t.union([t.string, t.null]).validate(u, context), (s) => {
49
+ const RichTextOptions = new t.Type("RichTextOptions", (u) => typeof u === "string", (u) => {
50
+ return (0, function_1.pipe)(t.union([t.string, t.null]).decode(u), fp_ts_1.either.map((s) => {
49
51
  if (!s)
50
- return t.success(exports.DEFAULT_OPTION);
52
+ return exports.DEFAULT_OPTION;
51
53
  const entries = s.split(",").map((e) => e.trim());
52
54
  const filtered = entries.filter((entry) => {
53
55
  return (0, Either_1.getOrElseW)(() => undefined)(exports.RichTextNodeTypeCodec.decode(entry));
54
56
  });
55
57
  if (!filtered.length)
56
- return t.success(exports.DEFAULT_OPTION);
57
- return t.success(filtered.join(","));
58
- });
58
+ return exports.DEFAULT_OPTION;
59
+ return filtered.join(",");
60
+ }));
59
61
  }, (a) => a);
60
62
  const NoLabels = (labels) => {
61
63
  if (!labels)
@@ -100,15 +102,13 @@ const RichTextLabels = new t.Type("RichTextLabels", (u) => {
100
102
  }, (u, context) => {
101
103
  const legacyValidator = t.record(t.string, t.readonlyArray(t.record(t.literal("name"), t.string)));
102
104
  const validator = t.readonlyArray(t.string);
103
- return Either_1.either.chain(t
104
- .union([legacyValidator, validator, t.string, t.null])
105
- .validate(u, context), (labels) => {
105
+ return (0, function_1.pipe)(t.union([legacyValidator, validator, t.string, t.null]).decode(u), fp_ts_1.either.chain((labels) => {
106
106
  return (NoLabels(labels) ||
107
107
  LabelsAsArray(labels) ||
108
108
  LabelsAsObject(labels) ||
109
109
  LabelsAsString(labels) ||
110
110
  t.failure(u, context));
111
- });
111
+ }));
112
112
  }, (res) => res);
113
113
  exports.RichTextConfig = t.exact(t.partial({
114
114
  label: validators_1.StringOrNull,
@@ -2316,13 +2316,19 @@ export declare const DynamicSlicesConfig: t.ExactC<t.PartialC<{
2316
2316
  }>>;
2317
2317
  export type DynamicSlicesConfig = t.TypeOf<typeof DynamicSlicesConfig>;
2318
2318
  export declare function slicesReader<T extends StaticSlicesConfig | DynamicSlicesConfig>(codec: t.Type<T, unknown>): t.ExactC<t.IntersectionC<[t.TypeC<{
2319
- type: t.UnionC<[t.LiteralC<"Slices">, t.LiteralC<"Choice">]>;
2319
+ type: t.KeyofC<{
2320
+ Slices: null;
2321
+ Choice: null;
2322
+ }>;
2320
2323
  }>, t.PartialC<{
2321
2324
  fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
2322
2325
  config: t.Type<T, unknown, unknown>;
2323
2326
  }>]>>;
2324
2327
  export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
2325
- type: t.UnionC<[t.LiteralC<"Slices">, t.LiteralC<"Choice">]>;
2328
+ type: t.KeyofC<{
2329
+ Slices: null;
2330
+ Choice: null;
2331
+ }>;
2326
2332
  }>, t.PartialC<{
2327
2333
  fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
2328
2334
  config: t.Type<{
@@ -3328,7 +3334,10 @@ export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
3328
3334
  }>]>>;
3329
3335
  export type StaticSlices = t.TypeOf<typeof StaticSlices>;
3330
3336
  export declare const DynamicSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
3331
- type: t.UnionC<[t.LiteralC<"Slices">, t.LiteralC<"Choice">]>;
3337
+ type: t.KeyofC<{
3338
+ Slices: null;
3339
+ Choice: null;
3340
+ }>;
3332
3341
  }>, t.PartialC<{
3333
3342
  fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
3334
3343
  config: t.Type<{
@@ -52,10 +52,10 @@ const SlicesConfig = {
52
52
  function slicesReader(codec) {
53
53
  return t.exact(t.intersection([
54
54
  t.type({
55
- type: t.union([
56
- t.literal(exports.SlicesFieldType),
57
- t.literal(exports.LegacySlicesFieldType),
58
- ]),
55
+ type: t.keyof({
56
+ [exports.SlicesFieldType]: null,
57
+ [exports.LegacySlicesFieldType]: null,
58
+ }),
59
59
  }),
60
60
  t.partial({
61
61
  fieldset: validators_1.StringOrNull,
@@ -1,7 +1,7 @@
1
- export { CompositeSlice } from "./CompositeSlice";
2
- export { LegacySlice } from "./LegacySlice";
1
+ export * from "./CompositeSlice";
2
+ export * from "./LegacySlice";
3
3
  export * from "./SharedSlice";
4
- export { SharedSliceRef } from "./SharedSliceRef";
5
- export * as Slice from "./Slice";
6
- export * as SliceZone from "./Slices";
7
- export { SlicesTypes } from "./SlicesTypes";
4
+ export * from "./SharedSliceRef";
5
+ export * from "./Slice";
6
+ export * from "./Slices";
7
+ export * from "./SlicesTypes";
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SlicesTypes = exports.SliceZone = exports.Slice = exports.SharedSliceRef = exports.LegacySlice = exports.CompositeSlice = void 0;
4
3
  const tslib_1 = require("tslib");
5
- var CompositeSlice_1 = require("./CompositeSlice");
6
- Object.defineProperty(exports, "CompositeSlice", { enumerable: true, get: function () { return CompositeSlice_1.CompositeSlice; } });
7
- var LegacySlice_1 = require("./LegacySlice");
8
- Object.defineProperty(exports, "LegacySlice", { enumerable: true, get: function () { return LegacySlice_1.LegacySlice; } });
4
+ tslib_1.__exportStar(require("./CompositeSlice"), exports);
5
+ tslib_1.__exportStar(require("./LegacySlice"), exports);
9
6
  tslib_1.__exportStar(require("./SharedSlice"), exports);
10
- var SharedSliceRef_1 = require("./SharedSliceRef");
11
- Object.defineProperty(exports, "SharedSliceRef", { enumerable: true, get: function () { return SharedSliceRef_1.SharedSliceRef; } });
12
- exports.Slice = tslib_1.__importStar(require("./Slice"));
13
- exports.SliceZone = tslib_1.__importStar(require("./Slices"));
14
- var SlicesTypes_1 = require("./SlicesTypes");
15
- Object.defineProperty(exports, "SlicesTypes", { enumerable: true, get: function () { return SlicesTypes_1.SlicesTypes; } });
7
+ tslib_1.__exportStar(require("./SharedSliceRef"), exports);
8
+ tslib_1.__exportStar(require("./Slice"), exports);
9
+ tslib_1.__exportStar(require("./Slices"), exports);
10
+ tslib_1.__exportStar(require("./SlicesTypes"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.0.0-alpha.4",
3
+ "version": "2.0.0-alpha.5",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,4 +1,5 @@
1
1
  import { either } from "fp-ts"
2
+ import { isLeft, isRight } from "fp-ts/lib/Either"
2
3
  import { pipe } from "fp-ts/lib/function"
3
4
  import * as t from "io-ts"
4
5
 
@@ -29,7 +30,7 @@ const DocumentLegacyCodec = (allTypes?: LegacyContentCtx["allTypes"]) => {
29
30
  (acc, [widgetKey, widgetValue]) => {
30
31
  const widgetCtx = defaultCtx(widgetKey, allTypes)
31
32
  const parsedW = WidgetLegacy(widgetCtx).decode(widgetValue)
32
- if (!parsedW || parsedW?._tag === "Left") return acc
33
+ if (!parsedW || isLeft(parsedW)) return acc
33
34
 
34
35
  return { ...acc, [widgetKey]: parsedW.right }
35
36
  },
@@ -68,7 +69,7 @@ function extractMetadata(data: { [p: string]: unknown }): {
68
69
  (acc, [k, v]) => {
69
70
  if (k.endsWith("_TYPE")) {
70
71
  const decodedValue = FieldOrSliceType.decode(v)
71
- if (decodedValue._tag === "Right") {
72
+ if (isRight(decodedValue)) {
72
73
  return {
73
74
  ...acc,
74
75
  types: acc.types.set(
@@ -118,7 +119,7 @@ function parseLegacyDocument(legacyDoc: unknown): Document | undefined {
118
119
  }),
119
120
  )
120
121
 
121
- return result._tag === "Left" ? undefined : result.right
122
+ return isLeft(result) ? undefined : result.right
122
123
  }
123
124
 
124
125
  function encodeToLegacyDocument(document: Document): DocumentLegacy {
@@ -1,4 +1,5 @@
1
1
  import { either } from "fp-ts"
2
+ import { isLeft } from "fp-ts/lib/Either"
2
3
  import { pipe } from "fp-ts/lib/function"
3
4
  import * as t from "io-ts"
4
5
 
@@ -20,7 +21,7 @@ export const GroupItemContent = t.strict({
20
21
  export type GroupItemContent = t.TypeOf<typeof GroupItemContent>
21
22
 
22
23
  const itemLegacyReader = t.array(t.tuple([t.string, t.unknown]))
23
- export type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>
24
+ type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>
24
25
 
25
26
  export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
26
27
  return new t.Type<GroupItemContent, WithTypes<GroupItemLegacy>>(
@@ -37,9 +38,8 @@ export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
37
38
  const result = NestableLegacy(itemCtx).decode(itemValue)
38
39
  if (!result) return acc
39
40
 
40
- if (result._tag === "Right")
41
- return [...acc, [itemKey, result.right]]
42
- else return acc
41
+ if (isLeft(result)) return acc
42
+ return [...acc, [itemKey, result.right]]
43
43
  },
44
44
  [],
45
45
  )
@@ -34,7 +34,7 @@ export const EmbedContentLegacy = t.exact(
34
34
  ]),
35
35
  )
36
36
 
37
- export type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
37
+ type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
38
38
 
39
39
  export const EmbedLegacy = (ctx: LegacyContentCtx) =>
40
40
  new t.Type<EmbedContent, WithTypes<EmbedLegacy>, unknown>(
@@ -1,3 +1,4 @@
1
+ import { isRight } from "fp-ts/lib/Either"
1
2
  import * as t from "io-ts"
2
3
 
3
4
  import type { LegacyContentCtx } from "../../LegacyContentCtx"
@@ -119,7 +120,7 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
119
120
  if (!ctx.fieldType) return
120
121
 
121
122
  const nullValue = EmptyLegacy(ctx.fieldType).decode(value)
122
- if (nullValue._tag === "Right") return nullValue
123
+ if (isRight(nullValue)) return nullValue
123
124
 
124
125
  const codec = (() => {
125
126
  switch (ctx.fieldType) {
@@ -1,5 +1,5 @@
1
1
  import { either } from "fp-ts"
2
- import * as E from "fp-ts/lib/Either"
2
+ import { isLeft, isRight } from "fp-ts/lib/Either"
3
3
  import { pipe } from "fp-ts/lib/function"
4
4
  import * as t from "io-ts"
5
5
 
@@ -44,12 +44,12 @@ export const ValidatedMetas = (linkCodec: LinkCodec) =>
44
44
  const res = metas
45
45
  .reduce<Array<Meta>>((acc, maybeMeta) => {
46
46
  const maybeDecodedMeta = Meta.decode(maybeMeta)
47
- if (E.isRight(maybeDecodedMeta)) {
47
+ if (isRight(maybeDecodedMeta)) {
48
48
  const meta = maybeDecodedMeta.right
49
49
  // if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
50
50
  if (meta.data && meta.type === "hyperlink") {
51
51
  const decoded = linkCodec.decode(meta.data)
52
- if (decoded._tag === "Left") return acc
52
+ if (isLeft(decoded)) return acc
53
53
 
54
54
  return [...acc, { ...meta, data: decoded.right }]
55
55
  } else if (meta.type !== "hyperlink") {
@@ -67,7 +67,7 @@ export const ValidatedMetas = (linkCodec: LinkCodec) =>
67
67
  if (meta.type === "hyperlink" && meta.data) {
68
68
  // since the Span data are typed as unknown we have to redecode for type safety and then encode to either new format or legacy.
69
69
  const decoded = linkCodec.decode(meta.data)
70
- if (decoded._tag === "Left") return acc
70
+ if (isLeft(decoded)) return acc
71
71
 
72
72
  return [...acc, { ...meta, data: linkCodec.encode(decoded.right) }]
73
73
  }
@@ -1,4 +1,5 @@
1
1
  import { either } from "fp-ts"
2
+ import { isLeft } from "fp-ts/lib/Either"
2
3
  import { pipe } from "fp-ts/lib/function"
3
4
  import * as t from "io-ts"
4
5
 
@@ -44,7 +45,7 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
44
45
  const result = RepeatableWidgetsLegacy(itemsCtx).decode(
45
46
  parsedSlice.repeat,
46
47
  )
47
- if (!result || result._tag === "Left") return
48
+ if (!result || isLeft(result)) return
48
49
  return result.right
49
50
  })() || []
50
51
 
@@ -57,8 +58,8 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
57
58
  const result = NestableLegacy(fieldCtx).decode(value)
58
59
  if (!result) return acc
59
60
 
60
- if (result._tag === "Right") return { ...acc, [key]: result.right }
61
- else return acc
61
+ if (isLeft(result)) return acc
62
+ return { ...acc, [key]: result.right }
62
63
  }, {})
63
64
 
64
65
  return {
@@ -1,4 +1,5 @@
1
1
  import { either } from "fp-ts"
2
+ import { isLeft } from "fp-ts/lib/Either"
2
3
  import { pipe } from "fp-ts/lib/function"
3
4
  import * as t from "io-ts"
4
5
  import { withFallback } from "io-ts-types"
@@ -43,7 +44,7 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
43
44
  const result = RepeatableWidgetsLegacy(itemsCtx).decode(
44
45
  parsedSlice.items,
45
46
  )
46
- if (!result || result._tag === "Left") return
47
+ if (!result || isLeft(result)) return
47
48
  return result.right
48
49
  })() || []
49
50
 
@@ -59,8 +60,8 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
59
60
  const result = NestableLegacy(FieldCtx).decode(value)
60
61
  if (!result) return acc
61
62
 
62
- if (result._tag === "Right") return { ...acc, [key]: result.right }
63
- else return acc
63
+ if (isLeft(result)) return acc
64
+ return { ...acc, [key]: result.right }
64
65
  }, {})
65
66
 
66
67
  return {
@@ -1,4 +1,5 @@
1
1
  import { either } from "fp-ts"
2
+ import { isLeft } from "fp-ts/lib/Either"
2
3
  import { pipe } from "fp-ts/lib/function"
3
4
  import * as t from "io-ts"
4
5
 
@@ -54,8 +55,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
54
55
  )
55
56
  const itemCtx = getFieldCtx(parsedSlice.key, ctx)
56
57
  const item = SliceLegacy(itemCtx).decode(parsedSlice.value)
57
- if (!item || item._tag === "Left")
58
- return t.failure(sliceItem, context)
58
+ if (!item || isLeft(item)) return t.failure(sliceItem, context)
59
59
 
60
60
  return t.success({
61
61
  key: parsedSlice.key,
@@ -1,3 +1,5 @@
1
+ import { isRight } from "fp-ts/lib/Either"
2
+
1
3
  import { FieldContentType, FieldType } from "./fields"
2
4
 
3
5
  type WithFieldType = WithContentType & { type: FieldType }
@@ -7,14 +9,11 @@ export function hasFieldContentType(obj: unknown): obj is WithFieldType {
7
9
  obj.__TYPE__ === FieldContentType &&
8
10
  (obj as WithFieldType)?.type !== undefined &&
9
11
  typeof (obj as WithFieldType).type === "string" &&
10
- FieldType.decode((obj as WithFieldType).type)._tag === "Right"
12
+ isRight(FieldType.decode((obj as WithFieldType).type))
11
13
  )
12
14
  }
13
15
 
14
16
  type WithContentType = { __TYPE__: string }
15
17
  export function hasContentType(obj: unknown): obj is WithContentType {
16
- return (
17
- (obj as WithContentType)?.__TYPE__ !== undefined &&
18
- typeof (obj as WithContentType).__TYPE__ === "string"
19
- )
18
+ return typeof (obj as WithContentType).__TYPE__ === "string"
20
19
  }
@@ -1,4 +1,4 @@
1
1
  export * from "./CustomType"
2
- export * as Comparators from "./diff"
3
- export * as Section from "./Section"
2
+ export * from "./diff"
3
+ export * from "./Section"
4
4
  export * from "./widgets"
@@ -1,4 +1,6 @@
1
- import { either, getOrElseW } from "fp-ts/lib/Either"
1
+ import { either } from "fp-ts/"
2
+ import { getOrElseW } from "fp-ts/lib/Either"
3
+ import { pipe } from "fp-ts/lib/function"
2
4
  import * as t from "io-ts"
3
5
 
4
6
  import { StringOrNull } from "../../../validators"
@@ -51,21 +53,21 @@ export const RichTextNodeTypeCodec = t.keyof({
51
53
  const RichTextOptions = new t.Type<string, string, unknown>(
52
54
  "RichTextOptions",
53
55
  (u: unknown): u is string => typeof u === "string",
54
- (u: unknown, context: t.Context) => {
55
- return either.chain(
56
- t.union([t.string, t.null]).validate(u, context),
57
- (s: string | null) => {
58
- if (!s) return t.success(DEFAULT_OPTION)
56
+ (u: unknown) => {
57
+ return pipe(
58
+ t.union([t.string, t.null]).decode(u),
59
+ either.map((s: string | null) => {
60
+ if (!s) return DEFAULT_OPTION
59
61
  const entries = s.split(",").map((e: string) => e.trim())
60
62
  const filtered = entries.filter((entry) => {
61
63
  return getOrElseW(() => undefined)(
62
64
  RichTextNodeTypeCodec.decode(entry),
63
65
  )
64
66
  })
65
- if (!filtered.length) return t.success(DEFAULT_OPTION)
67
+ if (!filtered.length) return DEFAULT_OPTION
66
68
 
67
- return t.success(filtered.join(","))
68
- },
69
+ return filtered.join(",")
70
+ }),
69
71
  )
70
72
  },
71
73
  (a) => a,
@@ -169,11 +171,9 @@ const RichTextLabels = new t.Type<ReadonlyArray<string>, object, unknown>(
169
171
  )
170
172
  const validator = t.readonlyArray(t.string)
171
173
 
172
- return either.chain(
173
- t
174
- .union([legacyValidator, validator, t.string, t.null])
175
- .validate(u, context),
176
- (labels) => {
174
+ return pipe(
175
+ t.union([legacyValidator, validator, t.string, t.null]).decode(u),
176
+ either.chain((labels) => {
177
177
  return (
178
178
  NoLabels(labels) ||
179
179
  LabelsAsArray(labels) ||
@@ -181,7 +181,7 @@ const RichTextLabels = new t.Type<ReadonlyArray<string>, object, unknown>(
181
181
  LabelsAsString(labels) ||
182
182
  t.failure(u, context)
183
183
  )
184
- },
184
+ }),
185
185
  )
186
186
  },
187
187
  (res) => res,
@@ -77,10 +77,10 @@ export function slicesReader<
77
77
  return t.exact(
78
78
  t.intersection([
79
79
  t.type({
80
- type: t.union([
81
- t.literal(SlicesFieldType),
82
- t.literal(LegacySlicesFieldType),
83
- ]),
80
+ type: t.keyof({
81
+ [SlicesFieldType]: null,
82
+ [LegacySlicesFieldType]: null,
83
+ }),
84
84
  }),
85
85
  t.partial({
86
86
  fieldset: StringOrNull,
@@ -1,7 +1,7 @@
1
- export { CompositeSlice } from "./CompositeSlice"
2
- export { LegacySlice } from "./LegacySlice"
1
+ export * from "./CompositeSlice"
2
+ export * from "./LegacySlice"
3
3
  export * from "./SharedSlice"
4
- export { SharedSliceRef } from "./SharedSliceRef"
5
- export * as Slice from "./Slice"
6
- export * as SliceZone from "./Slices"
7
- export { SlicesTypes } from "./SlicesTypes"
4
+ export * from "./SharedSliceRef"
5
+ export * from "./Slice"
6
+ export * from "./Slices"
7
+ export * from "./SlicesTypes"