@prismicio/types-internal 0.2.2 → 0.2.3

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 (87) hide show
  1. package/lib/customtypes/CustomType.d.ts +2 -20
  2. package/lib/customtypes/CustomType.js +33 -25
  3. package/lib/customtypes/Format.js +5 -2
  4. package/lib/customtypes/Section.d.ts +3 -30
  5. package/lib/customtypes/Section.js +14 -9
  6. package/lib/customtypes/index.js +9 -4
  7. package/lib/customtypes/widgets/Group.js +12 -9
  8. package/lib/customtypes/widgets/UID.js +10 -7
  9. package/lib/customtypes/widgets/Widget.d.ts +3 -30
  10. package/lib/customtypes/widgets/Widget.js +19 -14
  11. package/lib/customtypes/widgets/WidgetTypes.js +3 -1
  12. package/lib/customtypes/widgets/index.js +14 -7
  13. package/lib/customtypes/widgets/nestable/BooleanField.js +9 -6
  14. package/lib/customtypes/widgets/nestable/Color.js +10 -7
  15. package/lib/customtypes/widgets/nestable/Date.js +10 -7
  16. package/lib/customtypes/widgets/nestable/Embed.js +10 -7
  17. package/lib/customtypes/widgets/nestable/GeoPoint.js +10 -7
  18. package/lib/customtypes/widgets/nestable/Image.js +13 -10
  19. package/lib/customtypes/widgets/nestable/IntegrationField.js +10 -7
  20. package/lib/customtypes/widgets/nestable/Link.js +14 -11
  21. package/lib/customtypes/widgets/nestable/NestableWidget.js +35 -32
  22. package/lib/customtypes/widgets/nestable/Number.js +14 -11
  23. package/lib/customtypes/widgets/nestable/Range.js +14 -11
  24. package/lib/customtypes/widgets/nestable/RichText.js +15 -12
  25. package/lib/customtypes/widgets/nestable/Select.js +11 -8
  26. package/lib/customtypes/widgets/nestable/Separator.js +9 -6
  27. package/lib/customtypes/widgets/nestable/Text.js +10 -7
  28. package/lib/customtypes/widgets/nestable/Timestamp.js +10 -7
  29. package/lib/customtypes/widgets/nestable/index.js +36 -15
  30. package/lib/customtypes/widgets/shared/ImageConstraint.js +12 -9
  31. package/lib/customtypes/widgets/shared/index.js +8 -1
  32. package/lib/customtypes/widgets/slices/CompositeSlice.js +13 -10
  33. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +1 -10
  34. package/lib/customtypes/widgets/slices/LegacySlice.js +8 -6
  35. package/lib/customtypes/widgets/slices/SharedSlice.js +12 -9
  36. package/lib/customtypes/widgets/slices/SharedSliceRef.js +7 -4
  37. package/lib/customtypes/widgets/slices/Slice.js +2 -1
  38. package/lib/customtypes/widgets/slices/Slices.d.ts +6 -60
  39. package/lib/customtypes/widgets/slices/Slices.js +33 -27
  40. package/lib/customtypes/widgets/slices/SlicesTypes.js +3 -1
  41. package/lib/customtypes/widgets/slices/index.js +16 -7
  42. package/lib/documents/DocumentData.js +7 -4
  43. package/lib/documents/index.js +7 -2
  44. package/lib/documents/widgets/EmptyContent.js +6 -3
  45. package/lib/documents/widgets/GroupContent.js +14 -10
  46. package/lib/documents/widgets/SimpleWidgetContent.js +32 -27
  47. package/lib/documents/widgets/StaticWidgetContent.js +11 -8
  48. package/lib/documents/widgets/UIDContent.js +8 -4
  49. package/lib/documents/widgets/index.js +27 -22
  50. package/lib/documents/widgets/nestable/BooleanContent.js +10 -6
  51. package/lib/documents/widgets/nestable/EmbedContent.js +24 -20
  52. package/lib/documents/widgets/nestable/FieldContent.js +10 -6
  53. package/lib/documents/widgets/nestable/GeoPointContent.js +9 -5
  54. package/lib/documents/widgets/nestable/ImageContent.js +16 -12
  55. package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +10 -6
  56. package/lib/documents/widgets/nestable/Link/DocumentLink.js +12 -7
  57. package/lib/documents/widgets/nestable/Link/ExternalLink.js +15 -10
  58. package/lib/documents/widgets/nestable/Link/FileLink.js +15 -10
  59. package/lib/documents/widgets/nestable/Link/ImageLink.js +14 -9
  60. package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -9
  61. package/lib/documents/widgets/nestable/Link/index.js +33 -24
  62. package/lib/documents/widgets/nestable/SeparatorContent.js +5 -2
  63. package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +39 -33
  64. package/lib/documents/widgets/nestable/StructuredTextContent/index.js +11 -7
  65. package/lib/documents/widgets/nestable/index.js +39 -28
  66. package/lib/documents/widgets/slices/CompositeSliceContent.js +13 -9
  67. package/lib/documents/widgets/slices/SharedSliceContent.js +16 -12
  68. package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -2
  69. package/lib/documents/widgets/slices/SliceWidgetContent.js +12 -8
  70. package/lib/documents/widgets/slices/SlicesContent.js +17 -13
  71. package/lib/documents/widgets/slices/index.js +8 -5
  72. package/lib/index.js +7 -3
  73. package/lib/validators/DateFromString.js +7 -4
  74. package/lib/validators/DateFromStringOrNumber.js +7 -4
  75. package/lib/validators/DateFromTsMs.js +7 -4
  76. package/lib/validators/IntFromNumber.js +7 -4
  77. package/lib/validators/IntFromPixels.js +7 -4
  78. package/lib/validators/NonEmptyString.js +6 -3
  79. package/lib/validators/NonEmptyStringOrNull.js +10 -7
  80. package/lib/validators/NumberOrNull.js +6 -3
  81. package/lib/validators/StringFromBoolean.js +7 -4
  82. package/lib/validators/StringFromNumber.js +7 -4
  83. package/lib/validators/StringOrNull.js +6 -3
  84. package/lib/validators/function.js +28 -15
  85. package/lib/validators/index.js +27 -12
  86. package/package.json +1 -1
  87. package/src/customtypes/widgets/slices/LegacySlice.ts +1 -2
@@ -1,29 +1,40 @@
1
- import { BooleanContentType } from "./BooleanContent";
2
- import { EmbedContentType } from "./EmbedContent";
3
- import { FieldContentType } from "./FieldContent";
4
- import { GeoPointContentType } from "./GeoPointContent";
5
- import { ImageContentType } from "./ImageContent";
6
- import { IntegrationFieldsContentType } from "./IntegrationFieldsContent";
7
- import { LinksTypes } from "./Link";
8
- import { SeparatorContentType } from "./SeparatorContent";
9
- import { StructuredTextContentType } from "./StructuredTextContent";
10
- export { default as BooleanContent } from "./BooleanContent";
11
- export { default as EmbedContent } from "./EmbedContent";
12
- export { default as FieldContent } from "./FieldContent";
13
- export { GeoPointContent } from "./GeoPointContent";
14
- export { ImageContent, ImageContentView, } from "./ImageContent";
15
- export { default as IntegrationFieldsContent } from "./IntegrationFieldsContent";
16
- export * as Links from "./Link";
17
- export * from "./SeparatorContent";
18
- export * from "./StructuredTextContent";
19
- export const NestableTypes = {
20
- Links: LinksTypes,
21
- StructuredText: StructuredTextContentType,
22
- Boolean: BooleanContentType,
23
- Embed: EmbedContentType,
24
- Field: FieldContentType,
25
- GeoPoint: GeoPointContentType,
26
- Image: ImageContentType,
27
- IntegrationFields: IntegrationFieldsContentType,
28
- Separator: SeparatorContentType,
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NestableTypes = exports.Links = exports.IntegrationFieldsContent = exports.ImageContentView = exports.ImageContent = exports.GeoPointContent = exports.FieldContent = exports.EmbedContent = exports.BooleanContent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const BooleanContent_1 = require("./BooleanContent");
6
+ const EmbedContent_1 = require("./EmbedContent");
7
+ const FieldContent_1 = require("./FieldContent");
8
+ const GeoPointContent_1 = require("./GeoPointContent");
9
+ const ImageContent_1 = require("./ImageContent");
10
+ const IntegrationFieldsContent_1 = require("./IntegrationFieldsContent");
11
+ const Link_1 = require("./Link");
12
+ const SeparatorContent_1 = require("./SeparatorContent");
13
+ const StructuredTextContent_1 = require("./StructuredTextContent");
14
+ var BooleanContent_2 = require("./BooleanContent");
15
+ Object.defineProperty(exports, "BooleanContent", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(BooleanContent_2).default; } });
16
+ var EmbedContent_2 = require("./EmbedContent");
17
+ Object.defineProperty(exports, "EmbedContent", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(EmbedContent_2).default; } });
18
+ var FieldContent_2 = require("./FieldContent");
19
+ Object.defineProperty(exports, "FieldContent", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(FieldContent_2).default; } });
20
+ var GeoPointContent_2 = require("./GeoPointContent");
21
+ Object.defineProperty(exports, "GeoPointContent", { enumerable: true, get: function () { return GeoPointContent_2.GeoPointContent; } });
22
+ var ImageContent_2 = require("./ImageContent");
23
+ Object.defineProperty(exports, "ImageContent", { enumerable: true, get: function () { return ImageContent_2.ImageContent; } });
24
+ Object.defineProperty(exports, "ImageContentView", { enumerable: true, get: function () { return ImageContent_2.ImageContentView; } });
25
+ var IntegrationFieldsContent_2 = require("./IntegrationFieldsContent");
26
+ Object.defineProperty(exports, "IntegrationFieldsContent", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(IntegrationFieldsContent_2).default; } });
27
+ exports.Links = (0, tslib_1.__importStar)(require("./Link"));
28
+ (0, tslib_1.__exportStar)(require("./SeparatorContent"), exports);
29
+ (0, tslib_1.__exportStar)(require("./StructuredTextContent"), exports);
30
+ exports.NestableTypes = {
31
+ Links: Link_1.LinksTypes,
32
+ StructuredText: StructuredTextContent_1.StructuredTextContentType,
33
+ Boolean: BooleanContent_1.BooleanContentType,
34
+ Embed: EmbedContent_1.EmbedContentType,
35
+ Field: FieldContent_1.FieldContentType,
36
+ GeoPoint: GeoPointContent_1.GeoPointContentType,
37
+ Image: ImageContent_1.ImageContentType,
38
+ IntegrationFields: IntegrationFieldsContent_1.IntegrationFieldsContentType,
39
+ Separator: SeparatorContent_1.SeparatorContentType,
29
40
  };
@@ -1,22 +1,26 @@
1
- import { isRight } from "fp-ts/Either";
2
- import * as O from "fp-ts/Option";
3
- import * as t from "io-ts";
4
- import { GroupContent, SimpleWidgetContent } from "../index";
5
- export const CompositeSliceContentType = "CompositeSliceContent";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompositeSliceContent = exports.CompositeSliceContentType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Either_1 = require("fp-ts/Either");
6
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const index_1 = require("../index");
9
+ exports.CompositeSliceContentType = "CompositeSliceContent";
6
10
  const codec = t.exact(t.partial({
7
11
  repeat: t.array(t.unknown),
8
12
  "non-repeat": t.UnknownRecord,
9
13
  }));
10
- export const CompositeSliceContent = {
14
+ exports.CompositeSliceContent = {
11
15
  fromJson: (prefixes, key, value, fieldTypes, fieldPositions) => {
12
16
  const prefixedRepeatKey = Array.of(prefixes, [key, "repeat"])
13
17
  .flat()
14
18
  .join(".");
15
19
  const decodedValue = codec.decode(value);
16
- if (isRight(decodedValue)) {
20
+ if ((0, Either_1.isRight)(decodedValue)) {
17
21
  const repeatObj = decodedValue.right.repeat;
18
22
  const nonRepeatObj = decodedValue.right["non-repeat"] ?? {};
19
- const groupItemsContentsRepeat = GroupContent.itemsContentsFromJson(prefixedRepeatKey, repeatObj, fieldTypes, fieldPositions);
23
+ const groupItemsContentsRepeat = index_1.GroupContent.itemsContentsFromJson(prefixedRepeatKey, repeatObj, fieldTypes, fieldPositions);
20
24
  const sortedFields = Object.entries(nonRepeatObj).sort(([k1], [k2]) => {
21
25
  const p1 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`) ?? 10000;
22
26
  const p2 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`) ?? 10000;
@@ -26,7 +30,7 @@ export const CompositeSliceContent = {
26
30
  const kp = Array.of(prefixes, [key, "non-repeat", k]).flat().join(".");
27
31
  const kind = fieldTypes.get(kp);
28
32
  if (kind) {
29
- const mWidgetContent = SimpleWidgetContent.from(kind, v);
33
+ const mWidgetContent = index_1.SimpleWidgetContent.from(kind, v);
30
34
  if (O.isSome(mWidgetContent)) {
31
35
  acc[k] = mWidgetContent.value;
32
36
  }
@@ -1,17 +1,21 @@
1
- import { map } from "fp-ts/Either";
2
- import * as O from "fp-ts/Option";
3
- import * as t from "io-ts";
4
- import { withFallback } from "io-ts-types";
5
- import { GroupContent, SimpleWidgetContent } from "../index";
6
- export const SharedSliceContentType = "SharedSliceContent";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedSliceContent = exports.SharedSliceContentType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Either_1 = require("fp-ts/Either");
6
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const io_ts_types_1 = require("io-ts-types");
9
+ const index_1 = require("../index");
10
+ exports.SharedSliceContentType = "SharedSliceContent";
7
11
  const codec = t.exact(t.type({
8
12
  variation: t.string,
9
- items: withFallback(t.array(t.unknown), []),
10
- primary: withFallback(t.UnknownRecord, {}),
13
+ items: (0, io_ts_types_1.withFallback)(t.array(t.unknown), []),
14
+ primary: (0, io_ts_types_1.withFallback)(t.UnknownRecord, {}),
11
15
  }));
12
- export const SharedSliceContent = {
16
+ exports.SharedSliceContent = {
13
17
  fromJson: (prefixes, key, value, fieldTypes, fieldPositions) => {
14
- const r = map((v) => {
18
+ const r = (0, Either_1.map)((v) => {
15
19
  const prefixedItemsKey = Array.of(prefixes, [
16
20
  key,
17
21
  "variations",
@@ -20,7 +24,7 @@ export const SharedSliceContent = {
20
24
  ])
21
25
  .flat()
22
26
  .join(".");
23
- const groupItemsContents = GroupContent.itemsContentsFromJson(prefixedItemsKey, v.items, fieldTypes, fieldPositions);
27
+ const groupItemsContents = index_1.GroupContent.itemsContentsFromJson(prefixedItemsKey, v.items, fieldTypes, fieldPositions);
24
28
  const sortedFields = Object.entries(v.primary).sort(([k1], [k2]) => {
25
29
  const p1 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k1}`) ?? 10000;
26
30
  const p2 = fieldPositions.get(`${Array.of(prefixes, [key]).flat().join(".")}.${k2}`) ?? 10000;
@@ -38,7 +42,7 @@ export const SharedSliceContent = {
38
42
  .join(".");
39
43
  const kind = fieldTypes.get(kp);
40
44
  if (kind) {
41
- const maybeWidgetContent = SimpleWidgetContent.from(kind, w);
45
+ const maybeWidgetContent = index_1.SimpleWidgetContent.from(kind, w);
42
46
  if (O.isSome(maybeWidgetContent)) {
43
47
  acc[k] = maybeWidgetContent.value;
44
48
  }
@@ -1,2 +1,6 @@
1
- import StaticWidgetContent from "../StaticWidgetContent";
2
- export const SimpleSliceContent = StaticWidgetContent;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleSliceContent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const StaticWidgetContent_1 = (0, tslib_1.__importDefault)(require("../StaticWidgetContent"));
6
+ exports.SimpleSliceContent = StaticWidgetContent_1.default;
@@ -1,19 +1,23 @@
1
- import * as O from "fp-ts/Option";
2
- import StaticWidgetContent from "../StaticWidgetContent";
3
- import { CompositeSliceContent } from "./CompositeSliceContent";
4
- import { SharedSliceContent } from "./SharedSliceContent";
5
- export const SliceWidgetContent = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SliceWidgetContent = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
6
+ const StaticWidgetContent_1 = (0, tslib_1.__importDefault)(require("../StaticWidgetContent"));
7
+ const CompositeSliceContent_1 = require("./CompositeSliceContent");
8
+ const SharedSliceContent_1 = require("./SharedSliceContent");
9
+ exports.SliceWidgetContent = {
6
10
  fromJson: (prefixes, key, value, fieldTypes, fieldPositions) => {
7
11
  const prefixedKey = Array.of(prefixes, [key]).flat().join(".");
8
12
  const fieldType = fieldTypes.get(prefixedKey);
9
13
  if (fieldType === "SharedSlice") {
10
- return SharedSliceContent.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
14
+ return SharedSliceContent_1.SharedSliceContent.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
11
15
  }
12
16
  else if (fieldType === "Slice") {
13
- return CompositeSliceContent.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
17
+ return CompositeSliceContent_1.CompositeSliceContent.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
14
18
  }
15
19
  else if (fieldType) {
16
- return StaticWidgetContent.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
20
+ return StaticWidgetContent_1.default.fromJson(prefixes, key, value, fieldTypes, fieldPositions);
17
21
  }
18
22
  else {
19
23
  return O.none;
@@ -1,22 +1,26 @@
1
- import * as A from "fp-ts/Array";
2
- import { pipe } from "fp-ts/function";
3
- import * as O from "fp-ts/Option";
4
- import * as t from "io-ts";
5
- import { nullable } from "../../../validators/function";
6
- import { SliceWidgetContent } from "./SliceWidgetContent";
7
- export const SlicesContentType = "SliceContentType";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SlicesContent = exports.SlicesContentType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const A = (0, tslib_1.__importStar)(require("fp-ts/Array"));
6
+ const function_1 = require("fp-ts/function");
7
+ const O = (0, tslib_1.__importStar)(require("fp-ts/Option"));
8
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
9
+ const function_2 = require("../../../validators/function");
10
+ const SliceWidgetContent_1 = require("./SliceWidgetContent");
11
+ exports.SlicesContentType = "SliceContentType";
8
12
  const codec = t.exact(t.intersection([
9
13
  t.type({
10
14
  key: t.string,
11
15
  value: t.unknown,
12
16
  }),
13
17
  t.partial({
14
- label: nullable(t.string),
18
+ label: (0, function_2.nullable)(t.string),
15
19
  }),
16
20
  ]));
17
- export const SlicesContent = {
21
+ exports.SlicesContent = {
18
22
  itemsCodec: (value, codecWidget) => {
19
- return pipe(codec.decode(value), O.fromEither, O.chain((r) => {
23
+ return (0, function_1.pipe)(codec.decode(value), O.fromEither, O.chain((r) => {
20
24
  const stopIdx = r.key.indexOf("$");
21
25
  const name = r.key.substring(0, stopIdx > 0 ? stopIdx : undefined);
22
26
  const maybeWidget = codecWidget(name, r.value);
@@ -33,10 +37,10 @@ export const SlicesContent = {
33
37
  fromJson: (key, value, fieldTypes, fieldPositions) => {
34
38
  if (fieldTypes.get(key) === "Slices") {
35
39
  const jsItems = O.getOrElse(() => new Array())(O.fromEither(t.array(t.unknown).decode(value)));
36
- const widgetCodec = (name, wValue) => SliceWidgetContent.fromJson([key], name, wValue, fieldTypes, fieldPositions);
40
+ const widgetCodec = (name, wValue) => SliceWidgetContent_1.SliceWidgetContent.fromJson([key], name, wValue, fieldTypes, fieldPositions);
37
41
  return O.some({
38
- value: A.compact(jsItems.map((jsItem) => SlicesContent.itemsCodec(jsItem, widgetCodec))),
39
- __TYPE__: SlicesContentType,
42
+ value: A.compact(jsItems.map((jsItem) => exports.SlicesContent.itemsCodec(jsItem, widgetCodec))),
43
+ __TYPE__: exports.SlicesContentType,
40
44
  });
41
45
  }
42
46
  else {
@@ -1,5 +1,8 @@
1
- export * from "./CompositeSliceContent";
2
- export * from "./SharedSliceContent";
3
- export * from "./SimpleSliceContent";
4
- export * from "./SlicesContent";
5
- export * from "./SliceWidgetContent";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./CompositeSliceContent"), exports);
5
+ (0, tslib_1.__exportStar)(require("./SharedSliceContent"), exports);
6
+ (0, tslib_1.__exportStar)(require("./SimpleSliceContent"), exports);
7
+ (0, tslib_1.__exportStar)(require("./SlicesContent"), exports);
8
+ (0, tslib_1.__exportStar)(require("./SliceWidgetContent"), exports);
package/lib/index.js CHANGED
@@ -1,3 +1,7 @@
1
- export * as CustomTypes from "./customtypes";
2
- export * as Documents from "./documents";
3
- export * as Validators from "./validators";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Validators = exports.Documents = exports.CustomTypes = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.CustomTypes = (0, tslib_1.__importStar)(require("./customtypes"));
6
+ exports.Documents = (0, tslib_1.__importStar)(require("./documents"));
7
+ exports.Validators = (0, tslib_1.__importStar)(require("./validators"));
@@ -1,7 +1,10 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
4
- export default new t.Type("dateFromString", (u) => u instanceof Date, (u, c) => pipe(t.string.validate(u, c), chain((s) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
7
+ exports.default = new t.Type("dateFromString", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(t.string.validate(u, c), (0, Either_1.chain)((s) => {
5
8
  const d = new Date(s);
6
9
  return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
7
10
  })), (date) => date.toISOString());
@@ -1,7 +1,10 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
4
- export default new t.Type("dateFromStringOrNumber", (u) => u instanceof Date, (u, c) => pipe(t.union([t.number, t.string]).validate(u, c), chain((s) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
7
+ exports.default = new t.Type("dateFromStringOrNumber", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(t.union([t.number, t.string]).validate(u, c), (0, Either_1.chain)((s) => {
5
8
  const d = new Date(s);
6
9
  return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
7
10
  })), (date) => date);
@@ -1,7 +1,10 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
4
- export default new t.Type("dateFromTsMs", (u) => u instanceof Date, (u, c) => pipe(t.number.validate(u, c), chain((s) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
7
+ exports.default = new t.Type("dateFromTsMs", (u) => u instanceof Date, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((s) => {
5
8
  const d = new Date(s);
6
9
  return isNaN(d.getTime()) ? t.failure(u, c) : t.success(d);
7
10
  })), (date) => date.getTime());
@@ -1,8 +1,11 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
4
7
  /** A codec that succeeds if a number can be parsed to an integer */
5
- export default new t.Type("IntFromNumber", t.Int.is, (u, c) => pipe(t.number.validate(u, c), chain((n) => {
8
+ exports.default = new t.Type("IntFromNumber", t.Int.is, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((n) => {
6
9
  if (t.Int.is(n))
7
10
  return t.success(n);
8
11
  else {
@@ -1,12 +1,15 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
4
7
  const PixelsRegex = /^([0-9]+)px$/;
5
8
  /**
6
9
  * A codec that succeeds if a string representing pixels (eg: "200px") can be
7
10
  * parsed to an integer
8
11
  */
9
- export default new t.Type("IntFromPixels", t.Int.is, (u, c) => pipe(t.string.validate(u, c), chain((strPixels) => {
12
+ exports.default = new t.Type("IntFromPixels", t.Int.is, (u, c) => (0, function_1.pipe)(t.string.validate(u, c), (0, Either_1.chain)((strPixels) => {
10
13
  try {
11
14
  const matched = strPixels.match(PixelsRegex);
12
15
  if (!matched)
@@ -1,3 +1,6 @@
1
- import * as t from "io-ts";
2
- import { refineType } from "./function";
3
- export default refineType(t.string, "nonEmptyString", (s) => s.trim().length > 0);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
5
+ const function_1 = require("./function");
6
+ exports.default = (0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0);
@@ -1,12 +1,15 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import { success, Type } from "io-ts";
4
- import StringOrNull from "./StringOrNull";
5
- export default new Type("nonEmptyStringOrNull", (u) => typeof u === "string" || u === null, (u, c) => pipe(StringOrNull.validate(u, c), chain((s) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const io_ts_1 = require("io-ts");
7
+ const StringOrNull_1 = (0, tslib_1.__importDefault)(require("./StringOrNull"));
8
+ exports.default = new io_ts_1.Type("nonEmptyStringOrNull", (u) => typeof u === "string" || u === null, (u, c) => (0, function_1.pipe)(StringOrNull_1.default.validate(u, c), (0, Either_1.chain)((s) => {
6
9
  if (typeof s === "string" && s.length > 0) {
7
- return success(s);
10
+ return (0, io_ts_1.success)(s);
8
11
  }
9
12
  else {
10
- return success(null);
13
+ return (0, io_ts_1.success)(null);
11
14
  }
12
15
  })), (s) => s);
@@ -1,3 +1,6 @@
1
- import * as t from "io-ts";
2
- import { nullable } from "./function";
3
- export default nullable(t.number);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
5
+ const function_1 = require("./function");
6
+ exports.default = (0, function_1.nullable)(t.number);
@@ -1,7 +1,10 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
4
7
  /** A codec that validates a Boolean and convert it as a string */
5
- export default new t.Type("StringFromInt", t.string.is, (u, c) => pipe(t.boolean.validate(u, c), chain((i) => {
8
+ exports.default = new t.Type("StringFromInt", t.string.is, (u, c) => (0, function_1.pipe)(t.boolean.validate(u, c), (0, Either_1.chain)((i) => {
6
9
  return t.success(i.toString());
7
10
  })), (i) => i);
@@ -1,7 +1,10 @@
1
- import { chain } from "fp-ts/Either";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const Either_1 = require("fp-ts/Either");
5
+ const function_1 = require("fp-ts/function");
6
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
4
7
  /** A codec that validates a number and convert it as a string */
5
- export default new t.Type("StringFromInt", t.string.is, (u, c) => pipe(t.number.validate(u, c), chain((i) => {
8
+ exports.default = new t.Type("StringFromInt", t.string.is, (u, c) => (0, function_1.pipe)(t.number.validate(u, c), (0, Either_1.chain)((i) => {
6
9
  return t.success(i.toString());
7
10
  })), (i) => i);
@@ -1,3 +1,6 @@
1
- import * as t from "io-ts";
2
- import { nullable } from "./function";
3
- export default nullable(t.string);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
5
+ const function_1 = require("./function");
6
+ exports.default = (0, function_1.nullable)(t.string);
@@ -1,27 +1,36 @@
1
- import { either } from "fp-ts";
2
- import { pipe } from "fp-ts/function";
3
- import * as t from "io-ts";
4
- import { mapOutput } from "io-ts-types/mapOutput";
5
- export function nullable(c) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addType = exports.isEmpty = exports.objectToMap = exports.grouped = exports.formatDate = exports.formatDateTime = exports.filterDouble = exports.refineType = exports.nullable = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fp_ts_1 = require("fp-ts");
6
+ const function_1 = require("fp-ts/function");
7
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const mapOutput_1 = require("io-ts-types/mapOutput");
9
+ function nullable(c) {
6
10
  return t.union([c, t.null, t.undefined]);
7
11
  }
8
- export function refineType(type, newName, pred) {
9
- return new t.Type(newName, type.is, (u, c) => pipe(type.validate(u, c), either.chain((v) => (pred(v) ? t.success(v) : t.failure(u, c)))), type.encode);
12
+ exports.nullable = nullable;
13
+ function refineType(type, newName, pred) {
14
+ return new t.Type(newName, type.is, (u, c) => (0, function_1.pipe)(type.validate(u, c), fp_ts_1.either.chain((v) => (pred(v) ? t.success(v) : t.failure(u, c)))), type.encode);
10
15
  }
11
- export function filterDouble(value) {
16
+ exports.refineType = refineType;
17
+ function filterDouble(value) {
12
18
  if (value === "") {
13
19
  return null;
14
20
  }
15
21
  const result = Number(value);
16
22
  return Number.isNaN(result) ? null : result;
17
23
  }
18
- export function formatDateTime(date) {
24
+ exports.filterDouble = filterDouble;
25
+ function formatDateTime(date) {
19
26
  return date.toISOString().replace(/\.\d{3}Z$/, "+0000");
20
27
  }
21
- export function formatDate(date) {
28
+ exports.formatDateTime = formatDateTime;
29
+ function formatDate(date) {
22
30
  return date.toISOString().replace(/T.*/, "");
23
31
  }
24
- export function grouped(array, n) {
32
+ exports.formatDate = formatDate;
33
+ function grouped(array, n) {
25
34
  return array.reduce((acc, curr, idx) => {
26
35
  if (idx % n === 0) {
27
36
  acc.push([curr]);
@@ -33,15 +42,19 @@ export function grouped(array, n) {
33
42
  return acc;
34
43
  }, new Array());
35
44
  }
36
- export function objectToMap(object) {
45
+ exports.grouped = grouped;
46
+ function objectToMap(object) {
37
47
  return new Map(Object.entries(object));
38
48
  }
39
- export function isEmpty(obj) {
49
+ exports.objectToMap = objectToMap;
50
+ function isEmpty(obj) {
40
51
  for (const _x in obj) {
41
52
  return false;
42
53
  }
43
54
  return true;
44
55
  }
45
- export function addType(codec, t) {
46
- return mapOutput(codec, (o) => ({ ...o, __TYPE__: t }));
56
+ exports.isEmpty = isEmpty;
57
+ function addType(codec, t) {
58
+ return (0, mapOutput_1.mapOutput)(codec, (o) => ({ ...o, __TYPE__: t }));
47
59
  }
60
+ exports.addType = addType;
@@ -1,12 +1,27 @@
1
- export { default as DateFromString } from "./DateFromString";
2
- export { default as DateFromStringOrNumber } from "./DateFromStringOrNumber";
3
- export { default as DateFromTsMs } from "./DateFromTsMs";
4
- export * as Function from "./function";
5
- export { default as IntFromNumber } from "./IntFromNumber";
6
- export { default as IntFromPixels } from "./IntFromPixels";
7
- export { default as NonEmptyString } from "./NonEmptyString";
8
- export { default as NonEmptyStringOrNull } from "./NonEmptyStringOrNull";
9
- export { default as NumberOrNull } from "./NumberOrNull";
10
- export { default as StringFromBoolean } from "./StringFromBoolean";
11
- export { default as StringFromNumber } from "./StringFromNumber";
12
- export { default as StringOrNull } from "./StringOrNull";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringOrNull = exports.StringFromNumber = exports.StringFromBoolean = exports.NumberOrNull = exports.NonEmptyStringOrNull = exports.NonEmptyString = exports.IntFromPixels = exports.IntFromNumber = exports.Function = exports.DateFromTsMs = exports.DateFromStringOrNumber = exports.DateFromString = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var DateFromString_1 = require("./DateFromString");
6
+ Object.defineProperty(exports, "DateFromString", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(DateFromString_1).default; } });
7
+ var DateFromStringOrNumber_1 = require("./DateFromStringOrNumber");
8
+ Object.defineProperty(exports, "DateFromStringOrNumber", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(DateFromStringOrNumber_1).default; } });
9
+ var DateFromTsMs_1 = require("./DateFromTsMs");
10
+ Object.defineProperty(exports, "DateFromTsMs", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(DateFromTsMs_1).default; } });
11
+ exports.Function = (0, tslib_1.__importStar)(require("./function"));
12
+ var IntFromNumber_1 = require("./IntFromNumber");
13
+ Object.defineProperty(exports, "IntFromNumber", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(IntFromNumber_1).default; } });
14
+ var IntFromPixels_1 = require("./IntFromPixels");
15
+ Object.defineProperty(exports, "IntFromPixels", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(IntFromPixels_1).default; } });
16
+ var NonEmptyString_1 = require("./NonEmptyString");
17
+ Object.defineProperty(exports, "NonEmptyString", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(NonEmptyString_1).default; } });
18
+ var NonEmptyStringOrNull_1 = require("./NonEmptyStringOrNull");
19
+ Object.defineProperty(exports, "NonEmptyStringOrNull", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(NonEmptyStringOrNull_1).default; } });
20
+ var NumberOrNull_1 = require("./NumberOrNull");
21
+ Object.defineProperty(exports, "NumberOrNull", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(NumberOrNull_1).default; } });
22
+ var StringFromBoolean_1 = require("./StringFromBoolean");
23
+ Object.defineProperty(exports, "StringFromBoolean", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(StringFromBoolean_1).default; } });
24
+ var StringFromNumber_1 = require("./StringFromNumber");
25
+ Object.defineProperty(exports, "StringFromNumber", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(StringFromNumber_1).default; } });
26
+ var StringOrNull_1 = require("./StringOrNull");
27
+ Object.defineProperty(exports, "StringOrNull", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(StringOrNull_1).default; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -2,9 +2,8 @@ import * as t from "io-ts"
2
2
 
3
3
  import Group from "../Group"
4
4
  import NestableWidget from "../nestable/NestableWidget"
5
- import UID from "../UID"
6
5
 
7
- const LegacySlice = t.union([UID, NestableWidget, Group])
6
+ const LegacySlice = t.union([NestableWidget, Group])
8
7
 
9
8
  type LegacySlice = t.TypeOf<typeof LegacySlice>
10
9