@prismicio/types-internal 0.2.9 → 0.3.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.
@@ -19,7 +19,24 @@ export declare enum RichTextNodeType {
19
19
  orderedList = "o-list-item",
20
20
  rtl = "rtl"
21
21
  }
22
- export declare function parseRichTextNodeType(str: string): RichTextNodeType | undefined;
22
+ export declare const RichTextNodeTypeCodec: t.KeyofC<{
23
+ heading1: null;
24
+ heading2: null;
25
+ heading3: null;
26
+ heading4: null;
27
+ heading5: null;
28
+ heading6: null;
29
+ paragraph: null;
30
+ strong: null;
31
+ em: null;
32
+ preformatted: null;
33
+ hyperlink: null;
34
+ image: null;
35
+ embed: null;
36
+ "list-item": null;
37
+ "o-list-item": null;
38
+ rtl: null;
39
+ }>;
23
40
  export declare const RichTextConfig: t.ExactC<t.PartialC<{
24
41
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
25
42
  placeholder: t.StringC;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RichText = exports.RichTextConfig = exports.parseRichTextNodeType = exports.RichTextNodeType = exports.DEFAULT_OPTION = void 0;
3
+ exports.RichText = exports.RichTextConfig = exports.RichTextNodeTypeCodec = exports.RichTextNodeType = exports.DEFAULT_OPTION = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
@@ -27,51 +27,32 @@ var RichTextNodeType;
27
27
  RichTextNodeType["orderedList"] = "o-list-item";
28
28
  RichTextNodeType["rtl"] = "rtl";
29
29
  })(RichTextNodeType = exports.RichTextNodeType || (exports.RichTextNodeType = {}));
30
- function parseRichTextNodeType(str) {
31
- switch (str) {
32
- case RichTextNodeType.heading1:
33
- return RichTextNodeType.heading1;
34
- case RichTextNodeType.heading2:
35
- return RichTextNodeType.heading2;
36
- case RichTextNodeType.heading3:
37
- return RichTextNodeType.heading3;
38
- case RichTextNodeType.heading4:
39
- return RichTextNodeType.heading4;
40
- case RichTextNodeType.heading5:
41
- return RichTextNodeType.heading5;
42
- case RichTextNodeType.heading6:
43
- return RichTextNodeType.heading6;
44
- case RichTextNodeType.paragraph:
45
- return RichTextNodeType.paragraph;
46
- case RichTextNodeType.strong:
47
- return RichTextNodeType.strong;
48
- case RichTextNodeType.em:
49
- return RichTextNodeType.em;
50
- case RichTextNodeType.preformatted:
51
- return RichTextNodeType.preformatted;
52
- case RichTextNodeType.hyperlink:
53
- return RichTextNodeType.hyperlink;
54
- case RichTextNodeType.image:
55
- return RichTextNodeType.image;
56
- case RichTextNodeType.embed:
57
- return RichTextNodeType.embed;
58
- case RichTextNodeType.list:
59
- return RichTextNodeType.list;
60
- case RichTextNodeType.orderedList:
61
- return RichTextNodeType.orderedList;
62
- case RichTextNodeType.rtl:
63
- return RichTextNodeType.rtl;
64
- default:
65
- return;
66
- }
67
- }
68
- exports.parseRichTextNodeType = parseRichTextNodeType;
30
+ exports.RichTextNodeTypeCodec = t.keyof({
31
+ [RichTextNodeType.heading1]: null,
32
+ [RichTextNodeType.heading2]: null,
33
+ [RichTextNodeType.heading3]: null,
34
+ [RichTextNodeType.heading4]: null,
35
+ [RichTextNodeType.heading5]: null,
36
+ [RichTextNodeType.heading6]: null,
37
+ [RichTextNodeType.paragraph]: null,
38
+ [RichTextNodeType.strong]: null,
39
+ [RichTextNodeType.em]: null,
40
+ [RichTextNodeType.preformatted]: null,
41
+ [RichTextNodeType.hyperlink]: null,
42
+ [RichTextNodeType.image]: null,
43
+ [RichTextNodeType.embed]: null,
44
+ [RichTextNodeType.list]: null,
45
+ [RichTextNodeType.orderedList]: null,
46
+ [RichTextNodeType.rtl]: null,
47
+ });
69
48
  const RichTextOptions = new t.Type("RichTextOptions", (u) => typeof u === "string", (u, context) => {
70
49
  return Either_1.either.chain(t.union([t.string, t.null]).validate(u, context), (s) => {
71
50
  if (!s)
72
51
  return t.success(exports.DEFAULT_OPTION);
73
52
  const entries = s.split(",").map((e) => e.trim());
74
- const filtered = entries.filter((entry) => parseRichTextNodeType(entry));
53
+ const filtered = entries.filter((entry) => {
54
+ return (0, Either_1.getOrElseW)(() => undefined)(exports.RichTextNodeTypeCodec.decode(entry));
55
+ });
75
56
  if (!filtered.length)
76
57
  return t.success(exports.DEFAULT_OPTION);
77
58
  return t.success(filtered.join(","));
@@ -14,8 +14,9 @@ exports.GroupContent = Object.freeze({
14
14
  return jsItems.map((jsItem) => {
15
15
  if (typeof jsItem === "object" && jsItem !== null) {
16
16
  const sorted = Object.entries(jsItem).sort(([k1], [k2]) => {
17
- const p1 = fieldPositions.get(`${prefixedKey}.${k1}`) ?? 10000;
18
- const p2 = fieldPositions.get(`${prefixedKey}.${k2}`) ?? 10000;
17
+ var _a, _b;
18
+ const p1 = (_a = fieldPositions.get(`${prefixedKey}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
19
+ const p2 = (_b = fieldPositions.get(`${prefixedKey}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
19
20
  return p1 - p2;
20
21
  });
21
22
  const w = sorted.map(([k, v]) => {
@@ -5,6 +5,6 @@ const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  exports.UIDContentType = "UIDContent";
8
- exports.UIDContent = new t.Type("UIDContent", (u) => u?.__TYPE__ === exports.UIDContentType, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
8
+ exports.UIDContent = new t.Type("UIDContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.UIDContentType; }, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
9
9
  return t.success({ value: u, __TYPE__: "UIDContent" });
10
10
  }), (uidContent) => uidContent.value);
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  exports.BooleanContentType = "BooleanContent";
8
- const BooleanContent = new t.Type("BooleanContent", (u) => u?.__TYPE__ === exports.BooleanContentType, (u, c) => Either_1.Chain.chain(t.boolean.validate(u, c), (u) => {
8
+ const BooleanContent = new t.Type("BooleanContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.BooleanContentType; }, (u, c) => Either_1.Chain.chain(t.boolean.validate(u, c), (u) => {
9
9
  return t.success({ value: u, __TYPE__: exports.BooleanContentType });
10
10
  }), (booleanContent) => t.boolean.encode(booleanContent.value));
11
11
  exports.default = BooleanContent;
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  exports.IntegrationFieldsContentType = "IntegrationFieldsContent";
8
- const IntegrationFieldsContent = new t.Type("IntegrationFieldsContent", (u) => u?.__TYPE__ === exports.IntegrationFieldsContentType, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
8
+ const IntegrationFieldsContent = new t.Type("IntegrationFieldsContent", (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.IntegrationFieldsContentType; }, (u, c) => Either_1.Chain.chain(t.string.validate(u, c), (u) => {
9
9
  return t.success({
10
10
  value: u,
11
11
  __TYPE__: exports.IntegrationFieldsContentType,
@@ -7,7 +7,8 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  const index_1 = require("./index");
8
8
  exports.LinkContentType = "LinkContent";
9
9
  exports.LinkContent = new t.Type("LinkContent", (u) => {
10
- return index_1.Link.is(u?.value);
10
+ var _a;
11
+ return index_1.Link.is((_a = u) === null || _a === void 0 ? void 0 : _a.value);
11
12
  }, (u, c) => Either_1.Chain.chain(index_1.Link.validate(u, c), (u) => {
12
13
  return t.success({ value: u, __TYPE__: exports.LinkContentType });
13
14
  }), (linkContent) => index_1.Link.encode(linkContent.value));
@@ -1,27 +1,70 @@
1
1
  import * as t from "io-ts";
2
+ import { RichTextNodeType } from "../../../../customtypes/widgets/nestable";
2
3
  export declare const Meta: t.ExactC<t.IntersectionC<[t.PartialC<{
3
4
  data: t.UnknownC;
4
5
  }>, t.TypeC<{
5
6
  start: t.NumberC;
6
7
  end: t.NumberC;
7
- type: t.StringC;
8
+ type: t.KeyofC<{
9
+ heading1: null;
10
+ heading2: null;
11
+ heading3: null;
12
+ heading4: null;
13
+ heading5: null;
14
+ heading6: null;
15
+ paragraph: null;
16
+ strong: null;
17
+ em: null;
18
+ preformatted: null;
19
+ hyperlink: null;
20
+ image: null;
21
+ embed: null;
22
+ "list-item": null;
23
+ "o-list-item": null;
24
+ rtl: null;
25
+ }>;
8
26
  }>]>>;
27
+ export declare type Meta = t.TypeOf<typeof Meta>;
28
+ export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
29
+ data: t.UnknownC;
30
+ }>, t.TypeC<{
31
+ start: t.NumberC;
32
+ end: t.NumberC;
33
+ type: t.KeyofC<{
34
+ heading1: null;
35
+ heading2: null;
36
+ heading3: null;
37
+ heading4: null;
38
+ heading5: null;
39
+ heading6: null;
40
+ paragraph: null;
41
+ strong: null;
42
+ em: null;
43
+ preformatted: null;
44
+ hyperlink: null;
45
+ image: null;
46
+ embed: null;
47
+ "list-item": null;
48
+ "o-list-item": null;
49
+ rtl: null;
50
+ }>;
51
+ }>]>>;
52
+ export declare type Span = Meta;
9
53
  export declare const ValidatedMetas: t.Type<({
10
54
  data?: unknown;
11
55
  } & {
12
56
  start: number;
13
57
  end: number;
14
- type: string;
58
+ type: RichTextNodeType;
15
59
  })[], ({
16
60
  data?: unknown;
17
61
  } & {
18
62
  start: number;
19
63
  end: number;
20
- type: string;
64
+ type: RichTextNodeType;
21
65
  })[], unknown>;
22
- export declare const ImageBlockType = "image";
23
66
  export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
24
- type: t.LiteralC<"image">;
67
+ type: t.LiteralC<RichTextNodeType.image>;
25
68
  data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
26
69
  origin: t.ExactC<t.TypeC<{
27
70
  id: t.StringC;
@@ -115,9 +158,8 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
115
158
  }>]>>;
116
159
  export declare type ImageBlock = t.TypeOf<typeof ImageBlock>;
117
160
  export declare function checkImageBlock(block: Block): block is ImageBlock;
118
- export declare const EmbedBlockType = "embed";
119
161
  export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
120
- type: t.LiteralC<"embed">;
162
+ type: t.LiteralC<RichTextNodeType.embed>;
121
163
  data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
122
164
  }>, t.PartialC<{
123
165
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
@@ -126,7 +168,7 @@ export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
126
168
  export declare type EmbedBlock = t.TypeOf<typeof EmbedBlock>;
127
169
  export declare function checkEmbedBlock(block: Block): block is EmbedBlock;
128
170
  export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
129
- type: t.Type<string, string, unknown>;
171
+ type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
130
172
  content: t.IntersectionC<[t.TypeC<{
131
173
  text: t.StringC;
132
174
  }>, t.PartialC<{
@@ -135,13 +177,13 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
135
177
  } & {
136
178
  start: number;
137
179
  end: number;
138
- type: string;
180
+ type: RichTextNodeType;
139
181
  })[], ({
140
182
  data?: unknown;
141
183
  } & {
142
184
  start: number;
143
185
  end: number;
144
- type: string;
186
+ type: RichTextNodeType;
145
187
  })[], unknown>;
146
188
  }>]>;
147
189
  }>, t.PartialC<{
@@ -150,7 +192,7 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
150
192
  }>]>>;
151
193
  export declare type TextBlock = t.TypeOf<typeof TextBlock>;
152
194
  export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
153
- type: t.LiteralC<"image">;
195
+ type: t.LiteralC<RichTextNodeType.image>;
154
196
  data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
155
197
  origin: t.ExactC<t.TypeC<{
156
198
  id: t.StringC;
@@ -242,13 +284,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
242
284
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
243
285
  direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
244
286
  }>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
245
- type: t.LiteralC<"embed">;
287
+ type: t.LiteralC<RichTextNodeType.embed>;
246
288
  data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
247
289
  }>, t.PartialC<{
248
290
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
249
291
  direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
250
292
  }>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
251
- type: t.Type<string, string, unknown>;
293
+ type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
252
294
  content: t.IntersectionC<[t.TypeC<{
253
295
  text: t.StringC;
254
296
  }>, t.PartialC<{
@@ -257,13 +299,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
257
299
  } & {
258
300
  start: number;
259
301
  end: number;
260
- type: string;
302
+ type: RichTextNodeType;
261
303
  })[], ({
262
304
  data?: unknown;
263
305
  } & {
264
306
  start: number;
265
307
  end: number;
266
- type: string;
308
+ type: RichTextNodeType;
267
309
  })[], unknown>;
268
310
  }>]>;
269
311
  }>, t.PartialC<{
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Block = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.EmbedBlockType = exports.checkImageBlock = exports.ImageBlock = exports.ImageBlockType = exports.ValidatedMetas = exports.Meta = void 0;
3
+ exports.Block = 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 E = (0, tslib_1.__importStar)(require("fp-ts/lib/Either"));
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
+ const nestable_1 = require("../../../../customtypes/widgets/nestable");
7
8
  const validators_1 = require("../../../../validators");
8
9
  const function_1 = require("../../../../validators/function");
9
10
  const EmbedContent_1 = require("../EmbedContent");
@@ -16,9 +17,11 @@ exports.Meta = t.exact(t.intersection([
16
17
  t.type({
17
18
  start: t.number,
18
19
  end: t.number,
19
- type: t.string,
20
+ type: nestable_1.RichTextNodeTypeCodec,
20
21
  }),
21
22
  ]));
23
+ // export alias for code clarity
24
+ exports.Span = exports.Meta;
22
25
  exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(metas) && metas.every(exports.Meta.is), (metas, c) => {
23
26
  if (Array.isArray(metas)) {
24
27
  const res = metas
@@ -42,10 +45,9 @@ exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(m
42
45
  else
43
46
  return t.failure(metas, c);
44
47
  }, (m) => t.array(exports.Meta).encode(m));
45
- exports.ImageBlockType = "image";
46
48
  exports.ImageBlock = t.exact(t.intersection([
47
49
  t.type({
48
- type: t.literal(exports.ImageBlockType),
50
+ type: t.literal(nestable_1.RichTextNodeType.image),
49
51
  data: t.intersection([
50
52
  ImageContent_1.ImageContentView,
51
53
  t.partial({
@@ -59,13 +61,12 @@ exports.ImageBlock = t.exact(t.intersection([
59
61
  }),
60
62
  ]));
61
63
  function checkImageBlock(block) {
62
- return block.type === exports.ImageBlockType;
64
+ return block.type === nestable_1.RichTextNodeType.image;
63
65
  }
64
66
  exports.checkImageBlock = checkImageBlock;
65
- exports.EmbedBlockType = "embed";
66
67
  exports.EmbedBlock = t.exact(t.intersection([
67
68
  t.type({
68
- type: t.literal(exports.EmbedBlockType),
69
+ type: t.literal(nestable_1.RichTextNodeType.embed),
69
70
  data: EmbedContent_1.EmbedContent,
70
71
  }),
71
72
  t.partial({
@@ -74,12 +75,12 @@ exports.EmbedBlock = t.exact(t.intersection([
74
75
  }),
75
76
  ]));
76
77
  function checkEmbedBlock(block) {
77
- return block.type === exports.EmbedBlockType;
78
+ return block.type === nestable_1.RichTextNodeType.embed;
78
79
  }
79
80
  exports.checkEmbedBlock = checkEmbedBlock;
80
81
  exports.TextBlock = t.exact(t.intersection([
81
82
  t.type({
82
- type: (0, function_1.refineType)(t.string, `string which isn't ${exports.ImageBlockType} ${exports.EmbedBlockType}`, (s) => s !== exports.ImageBlockType && s !== exports.EmbedBlockType),
83
+ type: (0, function_1.refineType)(nestable_1.RichTextNodeTypeCodec, `string which isn't ${nestable_1.RichTextNodeType.image} ${nestable_1.RichTextNodeType.embed}`, (s) => s !== nestable_1.RichTextNodeType.image && s !== nestable_1.RichTextNodeType.embed),
83
84
  content: t.intersection([
84
85
  t.type({
85
86
  text: t.string,
@@ -6,7 +6,7 @@ const Either_1 = require("fp-ts/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  const Block_1 = require("./Block");
8
8
  exports.StructuredTextContentType = "StructuredTextContent";
9
- exports.StructuredTextContent = new t.Type(exports.StructuredTextContentType, (u) => u?.__TYPE__ === exports.StructuredTextContentType, (u, c) => Either_1.Chain.chain(t.array(Block_1.Block).validate(u, c), (u) => {
9
+ exports.StructuredTextContent = new t.Type(exports.StructuredTextContentType, (u) => { var _a; return ((_a = u) === null || _a === void 0 ? void 0 : _a.__TYPE__) === exports.StructuredTextContentType; }, (u, c) => Either_1.Chain.chain(t.array(Block_1.Block).validate(u, c), (u) => {
10
10
  return t.success({ value: u, __TYPE__: exports.StructuredTextContentType });
11
11
  }), () => {
12
12
  throw new Error("NotImplementedError: Not relevant method");
@@ -13,17 +13,19 @@ const codec = t.exact(t.partial({
13
13
  }));
14
14
  exports.CompositeSliceContent = {
15
15
  fromJson: (prefixes, key, value, fieldTypes, fieldPositions) => {
16
+ var _a;
16
17
  const prefixedRepeatKey = Array.of(prefixes, [key, "repeat"])
17
18
  .flat()
18
19
  .join(".");
19
20
  const decodedValue = codec.decode(value);
20
21
  if ((0, Either_1.isRight)(decodedValue)) {
21
22
  const repeatObj = decodedValue.right.repeat;
22
- const nonRepeatObj = decodedValue.right["non-repeat"] ?? {};
23
+ const nonRepeatObj = (_a = decodedValue.right["non-repeat"]) !== null && _a !== void 0 ? _a : {};
23
24
  const groupItemsContentsRepeat = index_1.GroupContent.itemsContentsFromJson(prefixedRepeatKey, repeatObj, fieldTypes, fieldPositions);
24
25
  const sortedFields = Object.entries(nonRepeatObj).sort(([k1], [k2]) => {
25
- const p1 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`) ?? 10000;
26
- const p2 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`) ?? 10000;
26
+ var _a, _b;
27
+ const p1 = (_a = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
28
+ const p2 = (_b = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
27
29
  return p1 - p2;
28
30
  });
29
31
  const nonRepeat = sortedFields.reduce((acc, [k, v]) => {
@@ -26,8 +26,9 @@ exports.SharedSliceContent = {
26
26
  .join(".");
27
27
  const groupItemsContents = index_1.GroupContent.itemsContentsFromJson(prefixedItemsKey, v.items, fieldTypes, fieldPositions);
28
28
  const sortedFields = Object.entries(v.primary).sort(([k1], [k2]) => {
29
- const p1 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`) ?? 10000;
30
- const p2 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`) ?? 10000;
29
+ var _a, _b;
30
+ const p1 = (_a = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`)) !== null && _a !== void 0 ? _a : 10000;
31
+ const p2 = (_b = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`)) !== null && _b !== void 0 ? _b : 10000;
31
32
  return p1 - p2;
32
33
  });
33
34
  const primary = sortedFields.reduce((acc, [k, w]) => {
@@ -25,10 +25,11 @@ exports.SlicesContent = {
25
25
  const name = r.key.substring(0, stopIdx > 0 ? stopIdx : undefined);
26
26
  const maybeWidget = codecWidget(name, r.value);
27
27
  return O.map((widget) => {
28
+ var _a;
28
29
  return {
29
30
  key: r.key,
30
31
  name,
31
- maybeLabel: r.label ?? undefined,
32
+ maybeLabel: (_a = r.label) !== null && _a !== void 0 ? _a : undefined,
32
33
  widget: widget,
33
34
  };
34
35
  })(maybeWidget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,4 +1,4 @@
1
- import { either } from "fp-ts/lib/Either"
1
+ import { either, getOrElseW } from "fp-ts/lib/Either"
2
2
  import * as t from "io-ts"
3
3
 
4
4
  import { StringOrNull } from "../../../validators"
@@ -26,46 +26,24 @@ export enum RichTextNodeType {
26
26
  rtl = "rtl",
27
27
  }
28
28
 
29
- export function parseRichTextNodeType(
30
- str: string,
31
- ): RichTextNodeType | undefined {
32
- switch (str) {
33
- case RichTextNodeType.heading1:
34
- return RichTextNodeType.heading1
35
- case RichTextNodeType.heading2:
36
- return RichTextNodeType.heading2
37
- case RichTextNodeType.heading3:
38
- return RichTextNodeType.heading3
39
- case RichTextNodeType.heading4:
40
- return RichTextNodeType.heading4
41
- case RichTextNodeType.heading5:
42
- return RichTextNodeType.heading5
43
- case RichTextNodeType.heading6:
44
- return RichTextNodeType.heading6
45
- case RichTextNodeType.paragraph:
46
- return RichTextNodeType.paragraph
47
- case RichTextNodeType.strong:
48
- return RichTextNodeType.strong
49
- case RichTextNodeType.em:
50
- return RichTextNodeType.em
51
- case RichTextNodeType.preformatted:
52
- return RichTextNodeType.preformatted
53
- case RichTextNodeType.hyperlink:
54
- return RichTextNodeType.hyperlink
55
- case RichTextNodeType.image:
56
- return RichTextNodeType.image
57
- case RichTextNodeType.embed:
58
- return RichTextNodeType.embed
59
- case RichTextNodeType.list:
60
- return RichTextNodeType.list
61
- case RichTextNodeType.orderedList:
62
- return RichTextNodeType.orderedList
63
- case RichTextNodeType.rtl:
64
- return RichTextNodeType.rtl
65
- default:
66
- return
67
- }
68
- }
29
+ export const RichTextNodeTypeCodec = t.keyof({
30
+ [RichTextNodeType.heading1]: null,
31
+ [RichTextNodeType.heading2]: null,
32
+ [RichTextNodeType.heading3]: null,
33
+ [RichTextNodeType.heading4]: null,
34
+ [RichTextNodeType.heading5]: null,
35
+ [RichTextNodeType.heading6]: null,
36
+ [RichTextNodeType.paragraph]: null,
37
+ [RichTextNodeType.strong]: null,
38
+ [RichTextNodeType.em]: null,
39
+ [RichTextNodeType.preformatted]: null,
40
+ [RichTextNodeType.hyperlink]: null,
41
+ [RichTextNodeType.image]: null,
42
+ [RichTextNodeType.embed]: null,
43
+ [RichTextNodeType.list]: null,
44
+ [RichTextNodeType.orderedList]: null,
45
+ [RichTextNodeType.rtl]: null,
46
+ })
69
47
 
70
48
  const RichTextOptions = new t.Type<string, string, unknown>(
71
49
  "RichTextOptions",
@@ -76,7 +54,11 @@ const RichTextOptions = new t.Type<string, string, unknown>(
76
54
  (s: string | null) => {
77
55
  if (!s) return t.success(DEFAULT_OPTION)
78
56
  const entries = s.split(",").map((e: string) => e.trim())
79
- const filtered = entries.filter((entry) => parseRichTextNodeType(entry))
57
+ const filtered = entries.filter((entry) => {
58
+ return getOrElseW(() => undefined)(
59
+ RichTextNodeTypeCodec.decode(entry),
60
+ )
61
+ })
80
62
  if (!filtered.length) return t.success(DEFAULT_OPTION)
81
63
 
82
64
  return t.success(filtered.join(","))
@@ -1,6 +1,10 @@
1
1
  import * as E from "fp-ts/lib/Either"
2
2
  import * as t from "io-ts"
3
3
 
4
+ import {
5
+ RichTextNodeType,
6
+ RichTextNodeTypeCodec,
7
+ } from "../../../../customtypes/widgets/nestable"
4
8
  import { StringOrNull } from "../../../../validators"
5
9
  import { nullable, refineType } from "../../../../validators/function"
6
10
  import { EmbedContent } from "../EmbedContent"
@@ -15,12 +19,15 @@ export const Meta = t.exact(
15
19
  t.type({
16
20
  start: t.number,
17
21
  end: t.number,
18
- type: t.string,
22
+ type: RichTextNodeTypeCodec,
19
23
  }),
20
24
  ]),
21
25
  )
26
+ export type Meta = t.TypeOf<typeof Meta>
22
27
 
23
- type Meta = t.TypeOf<typeof Meta>
28
+ // export alias for code clarity
29
+ export const Span = Meta
30
+ export type Span = Meta
24
31
 
25
32
  export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
26
33
  "ValidatedMetas",
@@ -51,12 +58,10 @@ export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
51
58
  (m) => t.array(Meta).encode(m),
52
59
  )
53
60
 
54
- export const ImageBlockType = "image"
55
-
56
61
  export const ImageBlock = t.exact(
57
62
  t.intersection([
58
63
  t.type({
59
- type: t.literal(ImageBlockType),
64
+ type: t.literal(RichTextNodeType.image),
60
65
  data: t.intersection([
61
66
  ImageContentView,
62
67
  t.partial({
@@ -72,14 +77,13 @@ export const ImageBlock = t.exact(
72
77
  )
73
78
  export type ImageBlock = t.TypeOf<typeof ImageBlock>
74
79
  export function checkImageBlock(block: Block): block is ImageBlock {
75
- return block.type === ImageBlockType
80
+ return block.type === RichTextNodeType.image
76
81
  }
77
82
 
78
- export const EmbedBlockType = "embed"
79
83
  export const EmbedBlock = t.exact(
80
84
  t.intersection([
81
85
  t.type({
82
- type: t.literal(EmbedBlockType),
86
+ type: t.literal(RichTextNodeType.embed),
83
87
  data: EmbedContent,
84
88
  }),
85
89
  t.partial({
@@ -90,16 +94,16 @@ export const EmbedBlock = t.exact(
90
94
  )
91
95
  export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
92
96
  export function checkEmbedBlock(block: Block): block is EmbedBlock {
93
- return block.type === EmbedBlockType
97
+ return block.type === RichTextNodeType.embed
94
98
  }
95
99
 
96
100
  export const TextBlock = t.exact(
97
101
  t.intersection([
98
102
  t.type({
99
103
  type: refineType(
100
- t.string,
101
- `string which isn't ${ImageBlockType} ${EmbedBlockType}`,
102
- (s) => s !== ImageBlockType && s !== EmbedBlockType,
104
+ RichTextNodeTypeCodec,
105
+ `string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
106
+ (s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
103
107
  ),
104
108
  content: t.intersection([
105
109
  t.type({