@prismicio/types-internal 2.2.0-alpha.2 → 2.2.0-alpha.21

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 (244) hide show
  1. package/lib/common/Asset.d.ts +16 -0
  2. package/lib/common/Asset.js +11 -0
  3. package/lib/common/Embed.d.ts +15 -0
  4. package/lib/common/Embed.js +10 -0
  5. package/lib/common/UUID.d.ts +7 -0
  6. package/lib/common/UUID.js +8 -0
  7. package/lib/common/index.d.ts +2 -0
  8. package/lib/common/index.js +2 -0
  9. package/lib/content/Document.d.ts +40 -40
  10. package/lib/content/fields/GroupContent.d.ts +12 -12
  11. package/lib/content/fields/WidgetContent.d.ts +56 -56
  12. package/lib/content/fields/nestable/NestableContent.d.ts +7 -7
  13. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +35 -12
  14. package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
  15. package/lib/content/fields/nestable/RichTextContent/index.d.ts +9 -9
  16. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +14 -14
  17. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +5 -5
  18. package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
  19. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +14 -14
  20. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +14 -14
  21. package/lib/content/fields/slices/Slice/index.d.ts +30 -30
  22. package/lib/content/fields/slices/SliceItem.d.ts +30 -30
  23. package/lib/content/fields/slices/SlicesContent.d.ts +42 -42
  24. package/lib/customtypes/CustomType.d.ts +2 -0
  25. package/lib/customtypes/CustomType.js +8 -1
  26. package/lib/import/converters/Document.d.ts +2 -2
  27. package/lib/import/converters/Document.js +6 -6
  28. package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
  29. package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
  30. package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
  31. package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
  32. package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
  33. package/lib/import/converters/fields/Slices/Slices.js +16 -0
  34. package/lib/import/converters/fields/Slices/index.d.ts +1 -0
  35. package/lib/import/converters/fields/Slices/index.js +4 -0
  36. package/lib/import/converters/fields/UID.d.ts +1 -1
  37. package/lib/import/converters/fields/UID.js +0 -2
  38. package/lib/import/converters/fields/index.d.ts +1 -0
  39. package/lib/import/converters/fields/index.js +1 -0
  40. package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
  41. package/lib/import/converters/fields/nestable/Embed.js +24 -5
  42. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
  43. package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
  44. package/lib/import/converters/fields/nestable/GeooPoint.d.ts +3 -0
  45. package/lib/import/converters/fields/nestable/GeooPoint.js +15 -0
  46. package/lib/import/converters/fields/nestable/Image.d.ts +6 -18
  47. package/lib/import/converters/fields/nestable/Image.js +47 -24
  48. package/lib/import/converters/fields/nestable/Link.d.ts +3 -2
  49. package/lib/import/converters/fields/nestable/Link.js +62 -11
  50. package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
  51. package/lib/import/converters/fields/nestable/Nestable.js +9 -3
  52. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
  53. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
  54. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
  55. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
  56. package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
  57. package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
  58. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
  59. package/lib/import/converters/fields/nestable/RichText/textBlock.js +34 -0
  60. package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
  61. package/lib/import/converters/fields/nestable/RichText.js +55 -0
  62. package/lib/import/converters/fields/nestable/index.d.ts +3 -0
  63. package/lib/import/converters/fields/nestable/index.js +3 -0
  64. package/lib/import/validators/Document.js +4 -9
  65. package/lib/import/validators/fields/ImportField.d.ts +68 -68
  66. package/lib/import/validators/fields/ImportField.js +8 -4
  67. package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
  68. package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
  69. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
  70. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
  71. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
  72. package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
  73. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
  74. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
  75. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
  76. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
  77. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
  78. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
  79. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
  80. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
  81. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
  82. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
  83. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
  84. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
  85. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
  86. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
  87. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
  88. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
  89. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
  90. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
  91. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
  92. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
  93. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
  94. package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
  95. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
  96. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
  97. package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
  98. package/lib/import/validators/fields/ImportSlices/index.js +4 -0
  99. package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
  100. package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
  101. package/lib/import/validators/fields/UID.d.ts +2 -2
  102. package/lib/import/validators/fields/UID.js +1 -1
  103. package/lib/import/validators/fields/nestable/Embed.d.ts +8 -22
  104. package/lib/import/validators/fields/nestable/Embed.js +5 -28
  105. package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
  106. package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
  107. package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
  108. package/lib/import/validators/fields/nestable/Image/default.js +19 -0
  109. package/lib/import/validators/fields/nestable/Image/index.d.ts +45 -0
  110. package/lib/import/validators/fields/nestable/Image/index.js +41 -0
  111. package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
  112. package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
  113. package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
  114. package/lib/import/validators/fields/nestable/Image/model.js +2 -0
  115. package/lib/import/validators/fields/nestable/Image/validators.d.ts +35 -0
  116. package/lib/import/validators/fields/nestable/Image/validators.js +31 -0
  117. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
  118. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
  119. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
  120. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
  121. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
  122. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
  123. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
  124. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
  125. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
  126. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
  127. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
  128. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
  129. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
  130. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
  131. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
  132. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
  133. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
  134. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
  135. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
  136. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
  137. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
  138. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
  139. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
  140. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
  141. package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
  142. package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
  143. package/lib/import/validators/fields/nestable/Link.d.ts +33 -0
  144. package/lib/import/validators/fields/nestable/Link.js +16 -11
  145. package/lib/import/validators/fields/nestable/Nestable.d.ts +65 -62
  146. package/lib/import/validators/fields/nestable/Nestable.js +18 -6
  147. package/lib/import/validators/fields/nestable/index.d.ts +5 -1
  148. package/lib/import/validators/fields/nestable/index.js +7 -1
  149. package/lib/utils/DocumentId.d.ts +2 -0
  150. package/lib/utils/DocumentId.js +7 -0
  151. package/lib/utils/Objects.d.ts +1 -1
  152. package/lib/utils/Objects.js +1 -1
  153. package/lib/utils/io-ts.d.ts +2 -0
  154. package/lib/utils/io-ts.js +22 -0
  155. package/lib/validators/BasicTypes.d.ts +0 -1
  156. package/lib/validators/BasicTypes.js +7 -8
  157. package/lib/validators/DefaultOrElse.js +1 -1
  158. package/lib/validators/NonEmptyString.js +1 -1
  159. package/lib/validators/NumberRange.d.ts +32 -0
  160. package/lib/validators/NumberRange.js +40 -0
  161. package/lib/validators/function.d.ts +20 -0
  162. package/lib/validators/function.js +41 -1
  163. package/lib/validators/index.d.ts +1 -0
  164. package/lib/validators/index.js +3 -1
  165. package/package.json +4 -2
  166. package/src/common/Asset.ts +25 -0
  167. package/src/common/Embed.ts +22 -0
  168. package/src/common/UUID.ts +19 -0
  169. package/src/common/index.ts +2 -0
  170. package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -1
  171. package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
  172. package/src/customtypes/CustomType.ts +13 -0
  173. package/src/import/converters/Document.ts +10 -7
  174. package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
  175. package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
  176. package/src/import/converters/fields/Slices/Slices.ts +20 -0
  177. package/src/import/converters/fields/Slices/index.ts +1 -0
  178. package/src/import/converters/fields/UID.ts +1 -5
  179. package/src/import/converters/fields/index.ts +1 -0
  180. package/src/import/converters/fields/nestable/Embed.ts +29 -7
  181. package/src/import/converters/fields/nestable/GeoPoint.ts +16 -0
  182. package/src/import/converters/fields/nestable/Image.ts +69 -44
  183. package/src/import/converters/fields/nestable/Link.ts +77 -0
  184. package/src/import/converters/fields/nestable/Nestable.ts +17 -6
  185. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -0
  186. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +14 -0
  187. package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
  188. package/src/import/converters/fields/nestable/RichText/textBlock.ts +35 -0
  189. package/src/import/converters/fields/nestable/index.ts +3 -0
  190. package/src/import/validators/Document.ts +4 -12
  191. package/src/import/validators/fields/ImportField.ts +12 -6
  192. package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
  193. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -0
  194. package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
  195. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
  196. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +64 -0
  197. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
  198. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
  199. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
  200. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
  201. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
  202. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
  203. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
  204. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
  205. package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
  206. package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
  207. package/src/import/validators/fields/ImportSlices/index.ts +1 -0
  208. package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
  209. package/src/import/validators/fields/UID.ts +2 -2
  210. package/src/import/validators/fields/nestable/Embed.ts +6 -51
  211. package/src/import/validators/fields/nestable/GeoPoint.ts +21 -0
  212. package/src/import/validators/fields/nestable/Image/default.ts +25 -0
  213. package/src/import/validators/fields/nestable/Image/index.ts +73 -0
  214. package/src/import/validators/fields/nestable/Image/merge.ts +64 -0
  215. package/src/import/validators/fields/nestable/Image/model.ts +18 -0
  216. package/src/import/validators/fields/nestable/Image/validators.ts +45 -0
  217. package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
  218. package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
  219. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
  220. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
  221. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
  222. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
  223. package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
  224. package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
  225. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
  226. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
  227. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
  228. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
  229. package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
  230. package/src/import/validators/fields/nestable/Link.ts +59 -0
  231. package/src/import/validators/fields/nestable/Nestable.ts +19 -4
  232. package/src/import/validators/fields/nestable/index.ts +5 -1
  233. package/src/utils/DocumentId.ts +8 -0
  234. package/src/utils/Objects.ts +2 -2
  235. package/src/utils/io-ts.ts +29 -0
  236. package/src/validators/BasicTypes.ts +13 -11
  237. package/src/validators/DefaultOrElse.ts +1 -1
  238. package/src/validators/NonEmptyString.ts +4 -5
  239. package/src/validators/NumberRange.ts +51 -0
  240. package/src/validators/function.ts +44 -0
  241. package/src/validators/index.ts +1 -0
  242. package/lib/import/validators/fields/nestable/Image.d.ts +0 -24
  243. package/lib/import/validators/fields/nestable/Image.js +0 -45
  244. package/src/import/validators/fields/nestable/Image.ts +0 -90
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HyperlinkSpan = exports.HyperlinkSpanType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../../../../../../../validators/function");
7
+ const Link_1 = require("../../../Link");
8
+ const SpanLocation_1 = require("./SpanLocation");
9
+ exports.HyperlinkSpanType = t.literal("hyperlink");
10
+ exports.HyperlinkSpan = t.exact(t.intersection([
11
+ t.type({
12
+ type: exports.HyperlinkSpanType,
13
+ }),
14
+ SpanLocation_1.SpanLocation,
15
+ (0, function_1.withCustomError)(t.type({
16
+ data: Link_1.Link,
17
+ }), () => "Hyperlink span must contain a 'data' field with link data"),
18
+ ]));
@@ -0,0 +1,5 @@
1
+ import * as t from "io-ts";
2
+ export declare const SpanLocation: t.TypeC<{
3
+ start: t.NumberC;
4
+ end: t.NumberC;
5
+ }>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpanLocation = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const validators_1 = require("../../../../../../../validators");
7
+ exports.SpanLocation = t.type({
8
+ start: validators_1.Number,
9
+ end: validators_1.Number,
10
+ });
@@ -0,0 +1,17 @@
1
+ import * as t from "io-ts";
2
+ export declare const TextSpanType: t.KeyofC<{
3
+ strong: null;
4
+ em: null;
5
+ label: null;
6
+ }>;
7
+ export declare const TextSpan: t.ExactC<t.IntersectionC<[t.TypeC<{
8
+ type: t.KeyofC<{
9
+ strong: null;
10
+ em: null;
11
+ label: null;
12
+ }>;
13
+ }>, t.TypeC<{
14
+ start: t.NumberC;
15
+ end: t.NumberC;
16
+ }>]>>;
17
+ export declare type TextSpan = t.TypeOf<typeof TextSpan>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextSpan = exports.TextSpanType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const SpanLocation_1 = require("./SpanLocation");
7
+ const TextSpanTypes = {
8
+ Strong: "strong",
9
+ Em: "em",
10
+ Label: "label",
11
+ };
12
+ exports.TextSpanType = t.keyof({
13
+ [TextSpanTypes.Strong]: null,
14
+ [TextSpanTypes.Em]: null,
15
+ [TextSpanTypes.Label]: null,
16
+ });
17
+ exports.TextSpan = t.exact(t.intersection([
18
+ t.type({
19
+ type: exports.TextSpanType,
20
+ }),
21
+ SpanLocation_1.SpanLocation,
22
+ ]));
@@ -0,0 +1,2 @@
1
+ export * from "./HyperlinkSpan";
2
+ export * from "./TextSpan";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./HyperlinkSpan"), exports);
5
+ (0, tslib_1.__exportStar)(require("./TextSpan"), exports);
@@ -0,0 +1,2 @@
1
+ export { ImportBlock } from "./ImportBlock";
2
+ export { ImportRichText } from "./ImportRichText";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportRichText = exports.ImportBlock = void 0;
4
+ var ImportBlock_1 = require("./ImportBlock");
5
+ Object.defineProperty(exports, "ImportBlock", { enumerable: true, get: function () { return ImportBlock_1.ImportBlock; } });
6
+ var ImportRichText_1 = require("./ImportRichText");
7
+ Object.defineProperty(exports, "ImportRichText", { enumerable: true, get: function () { return ImportRichText_1.ImportRichText; } });
@@ -1,5 +1,37 @@
1
1
  import type { TypeOf } from "io-ts";
2
2
  import * as t from "io-ts";
3
+ declare const WebLink: t.ExactC<t.IntersectionC<[t.TypeC<{
4
+ link_type: t.LiteralC<"Web">;
5
+ url: t.StringC;
6
+ }>, t.PartialC<{
7
+ target: t.StringC;
8
+ }>]>>;
9
+ export declare type WebLink = t.TypeOf<typeof WebLink>;
10
+ declare const DocumentLink: t.ExactC<t.TypeC<{
11
+ link_type: t.LiteralC<"Document">;
12
+ id: t.Type<string, string, unknown>;
13
+ }>>;
14
+ export declare type DocumentLink = t.TypeOf<typeof DocumentLink>;
15
+ declare const MediaLink: t.ExactC<t.TypeC<{
16
+ link_type: t.LiteralC<"Media">;
17
+ id: t.StringC;
18
+ }>>;
19
+ export declare type MediaLink = t.TypeOf<typeof MediaLink>;
20
+ export declare const Link: t.Type<({
21
+ link_type: "Web";
22
+ url: string;
23
+ } & {
24
+ target?: string;
25
+ }) | {
26
+ link_type: "Document";
27
+ id: string;
28
+ } | {
29
+ link_type: "Media";
30
+ id: string;
31
+ }, {
32
+ link_type: "Document" | "Web" | "Media";
33
+ }, unknown>;
34
+ export declare type Link = TypeOf<typeof Link>;
3
35
  export declare const ImportLink: t.Type<{
4
36
  type: "Link";
5
37
  value: ({
@@ -18,3 +50,4 @@ export declare const ImportLink: t.Type<{
18
50
  link_type: "Document" | "Web" | "Media";
19
51
  } | undefined, unknown>;
20
52
  export declare type ImportLink = TypeOf<typeof ImportLink>;
53
+ export {};
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImportLink = void 0;
3
+ exports.ImportLink = exports.Link = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const DocumentId_1 = require("../../../../utils/DocumentId");
6
7
  const validators_1 = require("../../../../validators");
8
+ const function_1 = require("../../../../validators/function");
7
9
  const ImportContent_1 = require("../ImportContent");
8
- const io_ts_types_1 = require("io-ts-types");
9
- const AnyLink = t.type({
10
- link_type: (0, io_ts_types_1.withMessage)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be one of `Web`, `Document` or `Media`"),
10
+ const LinkTypeValidator = t.type({
11
+ link_type: (0, function_1.withCustomError)(t.union([t.literal("Web"), t.literal("Document"), t.literal("Media")]), () => "The value must be `Web`, `Document` or `Media`"),
11
12
  });
12
- const WebLink = t.intersection([
13
+ const WebLink = t.exact(t.intersection([
13
14
  t.type({
14
15
  link_type: t.literal("Web"),
15
16
  url: validators_1.String,
@@ -17,14 +18,18 @@ const WebLink = t.intersection([
17
18
  t.partial({
18
19
  target: validators_1.String,
19
20
  }),
20
- ]);
21
- const DocumentLink = t.type({
21
+ ]));
22
+ const DocumentLink = t.strict({
22
23
  link_type: t.literal("Document"),
23
- id: validators_1.String,
24
+ id: DocumentId_1.DocumentId,
24
25
  });
25
- const MediaLink = t.type({
26
+ const MediaLink = t.strict({
26
27
  link_type: t.literal("Media"),
27
28
  id: validators_1.String,
28
29
  });
29
- const Link = AnyLink.pipe(t.union([WebLink, DocumentLink, MediaLink]));
30
- exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.NullOrElse)(Link));
30
+ exports.Link = LinkTypeValidator.pipe(t.union([WebLink, DocumentLink, MediaLink]));
31
+ // This is the default value for the link
32
+ const AnyLink = t.strict({
33
+ link_type: t.literal("Any"),
34
+ });
35
+ exports.ImportLink = (0, ImportContent_1.ImportContent)("Link", (0, validators_1.DefaultOrElse)(AnyLink)(exports.Link));
@@ -1,14 +1,17 @@
1
1
  import type { NestableWidget } from "../../../../customtypes";
2
- import { ImportBoolean } from ".";
2
+ import { ImportBoolean } from "./Boolean";
3
3
  import { ImportColor } from "./Color";
4
4
  import { ImportDate } from "./Date";
5
5
  import { ImportEmbed } from "./Embed";
6
+ import { ImportGeoPoint } from "./GeoPoint";
6
7
  import { ImportImage } from "./Image";
8
+ import { ImportRichText } from "./ImportRichText";
9
+ import { ImportLink } from "./Link";
7
10
  import { ImportNumber } from "./Number";
8
11
  import { ImportSelect } from "./Select";
9
12
  import { ImportText } from "./Text";
10
13
  import { ImportTimestamp } from "./Timestamp";
11
- export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportImage;
14
+ export declare type ImportNestable = ImportBoolean | ImportColor | ImportNumber | ImportSelect | ImportText | ImportDate | ImportTimestamp | ImportEmbed | ImportLink | ImportGeoPoint | ImportImage | ImportRichText;
12
15
  export declare const ImportNestable: {
13
16
  is(u: unknown): u is ImportNestable;
14
17
  decode: (field: NestableWidget) => (content: unknown) => {
@@ -23,49 +26,43 @@ export declare const ImportNestable: {
23
26
  value: Date | null;
24
27
  }, Date | undefined, unknown> | import("io-ts").Type<{
25
28
  type: "Embed";
26
- value: ({
29
+ value: {
27
30
  embed_url: string;
28
- type: string;
29
- } & {
30
- version?: string | number | null;
31
- title?: string;
32
- author_name?: string | null;
33
- author_url?: string | null;
34
- provider_name?: string | null;
35
- provider_url?: string | null;
36
- cache_age?: string | number | null;
37
- thumbnail_url?: string | null;
38
- thumbnail_width?: number | null;
39
- thumbnail_height?: number | null;
40
- html?: string | null;
41
- } & {
42
- all: unknown;
43
- }) | null;
44
- }, ({
31
+ } | null;
32
+ }, {
45
33
  embed_url: string;
46
- type: string;
47
- } & {
48
- version?: string | number | null;
49
- title?: string;
50
- author_name?: string | null;
51
- author_url?: string | null;
52
- provider_name?: string | null;
53
- provider_url?: string | null;
54
- cache_age?: string | number | null;
55
- thumbnail_url?: string | null;
56
- thumbnail_width?: number | null;
57
- thumbnail_height?: number | null;
58
- html?: string | null;
59
- } & {
60
- all: unknown;
61
- }) | undefined, unknown> | import("io-ts").Type<{
34
+ } | undefined, unknown> | import("io-ts").Type<{
35
+ type: "GeoPoint";
36
+ value: {
37
+ latitude: number;
38
+ longitude: number;
39
+ } | null;
40
+ }, {
41
+ latitude: number;
42
+ longitude: number;
43
+ } | undefined, unknown> | import("io-ts").Type<{
62
44
  type: "Image";
63
- value: (import("./Image").ImageField & {
64
- thumbnails: Record<string, import("./Image").ImageField>;
65
- }) | null;
66
- }, (import("./Image").ImageField & {
67
- thumbnails: Record<string, import("./Image").ImageField>;
68
- }) | undefined, unknown> | import("io-ts").Type<{
45
+ value: import("./Image").ImageFieldWithThumbnails | null;
46
+ }, import("./Image").ImageFieldWithThumbnails | undefined, unknown> | import("io-ts").Type<{
47
+ type: "Link";
48
+ value: ({
49
+ link_type: "Web";
50
+ url: string;
51
+ } & {
52
+ target?: string;
53
+ }) | {
54
+ link_type: "Document";
55
+ id: string;
56
+ } | {
57
+ link_type: "Media";
58
+ id: string;
59
+ } | null;
60
+ }, {
61
+ link_type: "Document" | "Web" | "Media";
62
+ } | undefined, unknown> | import("io-ts").Type<{
63
+ type: "StructuredText";
64
+ value: import("./ImportRichText").ImportBlock[] | null;
65
+ }, unknown[] | undefined, unknown> | import("io-ts").Type<{
69
66
  type: "Number";
70
67
  value: number | null;
71
68
  }, number | undefined, unknown> | import("io-ts").Type<{
@@ -90,31 +87,37 @@ export declare const ImportNestable: {
90
87
  }> | import("fp-ts/lib/Either").Right<{
91
88
  type: "Number";
92
89
  value: number | null;
90
+ }> | import("fp-ts/lib/Either").Right<{
91
+ type: "StructuredText";
92
+ value: import("./ImportRichText").ImportBlock[] | null;
93
+ }> | import("fp-ts/lib/Either").Right<{
94
+ type: "Link";
95
+ value: ({
96
+ link_type: "Web";
97
+ url: string;
98
+ } & {
99
+ target?: string;
100
+ }) | {
101
+ link_type: "Document";
102
+ id: string;
103
+ } | {
104
+ link_type: "Media";
105
+ id: string;
106
+ } | null;
93
107
  }> | import("fp-ts/lib/Either").Right<{
94
108
  type: "Image";
95
- value: (import("./Image").ImageField & {
96
- thumbnails: Record<string, import("./Image").ImageField>;
97
- }) | null;
109
+ value: import("./Image").ImageFieldWithThumbnails | null;
110
+ }> | import("fp-ts/lib/Either").Right<{
111
+ type: "GeoPoint";
112
+ value: {
113
+ latitude: number;
114
+ longitude: number;
115
+ } | null;
98
116
  }> | import("fp-ts/lib/Either").Right<{
99
117
  type: "Embed";
100
- value: ({
118
+ value: {
101
119
  embed_url: string;
102
- type: string;
103
- } & {
104
- version?: string | number | null;
105
- title?: string;
106
- author_name?: string | null;
107
- author_url?: string | null;
108
- provider_name?: string | null;
109
- provider_url?: string | null;
110
- cache_age?: string | number | null;
111
- thumbnail_url?: string | null;
112
- thumbnail_width?: number | null;
113
- thumbnail_height?: number | null;
114
- html?: string | null;
115
- } & {
116
- all: unknown;
117
- }) | null;
120
+ } | null;
118
121
  }> | import("fp-ts/lib/Either").Right<{
119
122
  type: "Date";
120
123
  value: Date | null;
@@ -1,18 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ImportNestable = void 0;
4
- const _1 = require(".");
4
+ const Boolean_1 = require("./Boolean");
5
5
  const Color_1 = require("./Color");
6
6
  const Date_1 = require("./Date");
7
7
  const Embed_1 = require("./Embed");
8
+ const GeoPoint_1 = require("./GeoPoint");
8
9
  const Image_1 = require("./Image");
10
+ const ImportRichText_1 = require("./ImportRichText");
11
+ const Link_1 = require("./Link");
9
12
  const Number_1 = require("./Number");
10
13
  const Select_1 = require("./Select");
11
14
  const Text_1 = require("./Text");
12
15
  const Timestamp_1 = require("./Timestamp");
13
16
  exports.ImportNestable = {
14
17
  is(u) {
15
- return (_1.ImportBoolean.is(u) ||
18
+ return (Boolean_1.ImportBoolean.is(u) ||
16
19
  Color_1.ImportColor.is(u) ||
17
20
  (0, Number_1.ImportNumber)().is(u) ||
18
21
  (0, Select_1.ImportSelect)().is(u) ||
@@ -20,14 +23,17 @@ exports.ImportNestable = {
20
23
  Date_1.ImportDate.is(u) ||
21
24
  Timestamp_1.ImportTimestamp.is(u) ||
22
25
  Embed_1.ImportEmbed.is(u) ||
23
- Image_1.ImportImage.is(u));
26
+ Link_1.ImportLink.is(u) ||
27
+ GeoPoint_1.ImportGeoPoint.is(u) ||
28
+ (0, Image_1.ImportImage)().is(u) ||
29
+ (0, ImportRichText_1.ImportRichText)().is(u));
24
30
  },
25
31
  decode: (field) => {
26
32
  return (content) => {
27
33
  const codec = (() => {
28
34
  switch (field.type) {
29
35
  case "Boolean":
30
- return _1.ImportBoolean;
36
+ return Boolean_1.ImportBoolean;
31
37
  case "Color":
32
38
  return Color_1.ImportColor;
33
39
  case "Number":
@@ -40,10 +46,16 @@ exports.ImportNestable = {
40
46
  return Date_1.ImportDate;
41
47
  case "Timestamp":
42
48
  return Timestamp_1.ImportTimestamp;
43
- case "Image":
44
- return Image_1.ImportImage;
45
49
  case "Embed":
46
50
  return Embed_1.ImportEmbed;
51
+ case "Link":
52
+ return Link_1.ImportLink;
53
+ case "Image":
54
+ return (0, Image_1.ImportImage)(field);
55
+ case "GeoPoint":
56
+ return GeoPoint_1.ImportGeoPoint;
57
+ case "StructuredText":
58
+ return (0, ImportRichText_1.ImportRichText)(field);
47
59
  default:
48
60
  throw new Error(`Unsupported type of nestable field ${field.type}`);
49
61
  }
@@ -1,8 +1,12 @@
1
1
  export * from "./Boolean";
2
2
  export * from "./Color";
3
3
  export * from "./Date";
4
- export * from "./Embed";
4
+ export { ImportEmbed } from "./Embed";
5
+ export * from "./GeoPoint";
5
6
  export * from "./Image";
7
+ export * from "./Image/index";
8
+ export * from "./ImportRichText";
9
+ export * from "./Link";
6
10
  export * from "./Nestable";
7
11
  export * from "./Number";
8
12
  export * from "./Select";
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImportEmbed = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  (0, tslib_1.__exportStar)(require("./Boolean"), exports);
5
6
  (0, tslib_1.__exportStar)(require("./Color"), exports);
6
7
  (0, tslib_1.__exportStar)(require("./Date"), exports);
7
- (0, tslib_1.__exportStar)(require("./Embed"), exports);
8
+ var Embed_1 = require("./Embed");
9
+ Object.defineProperty(exports, "ImportEmbed", { enumerable: true, get: function () { return Embed_1.ImportEmbed; } });
10
+ (0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
8
11
  (0, tslib_1.__exportStar)(require("./Image"), exports);
12
+ (0, tslib_1.__exportStar)(require("./Image/index"), exports);
13
+ (0, tslib_1.__exportStar)(require("./ImportRichText"), exports);
14
+ (0, tslib_1.__exportStar)(require("./Link"), exports);
9
15
  (0, tslib_1.__exportStar)(require("./Nestable"), exports);
10
16
  (0, tslib_1.__exportStar)(require("./Number"), exports);
11
17
  (0, tslib_1.__exportStar)(require("./Select"), exports);
@@ -0,0 +1,2 @@
1
+ import * as t from "io-ts";
2
+ export declare const DocumentId: t.Type<string, string, unknown>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentId = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../validators/function");
7
+ exports.DocumentId = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "DocumentId", (s) => s.length === 16), () => "DocumentId must be a 16 character string");
@@ -5,4 +5,4 @@ export declare function zipObjects<A, B = A>(objLeft?: Partial<Record<string, A>
5
5
  export declare function isNotEmpty<A extends object>(obj: A): boolean;
6
6
  export declare function withOptionals<T extends object>(object: T, optionals: Array<[keyof T, T[keyof T] | null | undefined]>): T;
7
7
  export declare function isObject(value: unknown): value is Record<string, unknown>;
8
- export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T) => O): Record<string, O>;
8
+ export declare function mapValues<T, O>(record: Record<string, T>, fn: (value: T, key: string) => O): Record<string, O>;
@@ -37,6 +37,6 @@ function isObject(value) {
37
37
  }
38
38
  exports.isObject = isObject;
39
39
  function mapValues(record, fn) {
40
- return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value) }), {});
40
+ return Object.entries(record).reduce((acc, [key, value]) => ({ ...acc, [key]: fn(value, key) }), {});
41
41
  }
42
42
  exports.mapValues = mapValues;
@@ -0,0 +1,2 @@
1
+ import type { Validation } from "io-ts";
2
+ export declare const combineValidationResults: <T>(validationResults: readonly Validation<T>[]) => Validation<readonly T[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.combineValidationResults = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
+ const function_1 = require("fp-ts/function");
7
+ const RA = (0, tslib_1.__importStar)(require("fp-ts/ReadonlyArray"));
8
+ /*
9
+ * Semigroup simply defines how to concatenate two values of the same type.
10
+ * In this instance, Errors from io-ts are arrays already, so we just need to concatenate them.
11
+ */
12
+ const validationErrorsSemigroup = {
13
+ concat: (a, b) => [...a, ...b],
14
+ };
15
+ /*
16
+ * This is a helper function to combine multiple io-ts validations into one.
17
+ * t.array(...) works in the same way - it collects all the errors when decoding an array of values.
18
+ * However, it requires you to pass in a single io-ts validator as a parameter, which is not always convenient.
19
+ * Sometimes we have arrays of validation results received from function calls that don't have a validator instance.
20
+ */
21
+ const combineValidationResults = (validationResults) => (0, function_1.pipe)(validationResults, RA.traverse(E.getApplicativeValidation(validationErrorsSemigroup))((validation) => validation));
22
+ exports.combineValidationResults = combineValidationResults;
@@ -8,4 +8,3 @@ export declare const EmptyObject: t.Type<Record<never, never>, {
8
8
  [key: string]: unknown;
9
9
  }, unknown>;
10
10
  export declare const EmptyArray: t.Type<never[], never[], unknown>;
11
- export declare const AnyObject: t.RecordC<t.StringC, t.UnknownC>;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AnyObject = exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
3
+ exports.EmptyArray = exports.EmptyObject = exports.Boolean = exports.NumberOrNull = exports.Number = exports.StringOrNull = exports.String = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const function_1 = require("fp-ts/lib/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
- const io_ts_types_1 = require("io-ts-types");
9
- exports.String = (0, io_ts_types_1.withMessage)(t.string, () => "The value must be a string");
10
- exports.StringOrNull = (0, io_ts_types_1.withMessage)(t.union([t.string, t.null]), () => "The value must be a string or null");
11
- exports.Number = (0, io_ts_types_1.withMessage)(t.number, () => "The value must be a number");
12
- exports.NumberOrNull = (0, io_ts_types_1.withMessage)(t.union([t.number, t.null]), () => "The value must be a number or null");
13
- exports.Boolean = (0, io_ts_types_1.withMessage)(t.boolean, () => "The value must be a boolean");
8
+ const function_2 = require("./function");
9
+ exports.String = (0, function_2.withCustomError)(t.string, () => "The value must be a string");
10
+ exports.StringOrNull = (0, function_2.withCustomError)(t.union([t.string, t.null]), () => "The value must be a string or null");
11
+ exports.Number = (0, function_2.withCustomError)(t.number, () => "The value must be a number");
12
+ exports.NumberOrNull = (0, function_2.withCustomError)(t.union([t.number, t.null]), () => "The value must be a number or null");
13
+ exports.Boolean = (0, function_2.withCustomError)(t.boolean, () => "The value must be a boolean");
14
14
  exports.EmptyObject = t.UnknownRecord.pipe(new t.Type("emptyObject", (u) => t.UnknownRecord.is(u), (u, c) => {
15
15
  if (Object.keys(u).length > 0)
16
16
  return t.failure(u, c, "The object is not empty.");
@@ -23,4 +23,3 @@ exports.EmptyArray = new t.Type("emptyArray", (u) => t.UnknownArray.is(u) && u.l
23
23
  return t.success(new Array());
24
24
  }));
25
25
  }, () => []);
26
- exports.AnyObject = (0, io_ts_types_1.withMessage)(t.record(t.string, t.unknown), () => "The value must be an object");
@@ -6,7 +6,7 @@ const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
7
  const BasicTypes_1 = require("./BasicTypes");
8
8
  const DefaultOrElse = (inputValidator) => {
9
- return (codec) => new t.Type("NullOrT", (u) => null === u || codec.is(u), (u) => {
9
+ return (codec) => new t.Type("DefaultOrElse", (u) => null === u || codec.is(u), (u) => {
10
10
  if ((0, Either_1.isRight)(inputValidator.decode(u)))
11
11
  return t.success(null);
12
12
  return codec.decode(u);
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const t = (0, tslib_1.__importStar)(require("io-ts"));
5
5
  const function_1 = require("./function");
6
- exports.default = (0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0);
6
+ exports.default = (0, function_1.withCustomError)((0, function_1.refineType)(t.string, "nonEmptyString", (s) => s.trim().length > 0), () => "The value must be a non-empty string");
@@ -0,0 +1,32 @@
1
+ import * as t from "io-ts";
2
+ declare const _default: (min: number, max: number, fieldName: string) => t.Type<number, number, unknown>;
3
+ /**
4
+ * Creates a custom runtime type for validating that a number falls within a specified range.
5
+ *
6
+ * @param min - The minimum value of the range.
7
+ * @param max - The maximum value of the range.
8
+ * @param fieldName - The name of the field being validated (used in error messages).
9
+ * @returns A runtime type representing the number range validation.
10
+ *
11
+ * * @example
12
+ * // Creating a custom runtime type for age validation
13
+ * const AgeType = numberInRange(18, 99, 'Age');
14
+ *
15
+ * // Valid age
16
+ * const validAgeResult = AgeType.decode(25);
17
+ * if (t.isRight(validAgeResult)) {
18
+ * console.log('Valid age:', validAgeResult.right); // Output: Valid age: 25
19
+ * } else {
20
+ * console.error('Invalid age:', t.left(validAgeResult).map(t.reporter.report));
21
+ * }
22
+ *
23
+ * @example
24
+ * // Invalid age
25
+ * const invalidAgeResult = AgeType.decode(15);
26
+ * if (t.isRight(invalidAgeResult)) {
27
+ * console.log('Valid age:', invalidAgeResult.right);
28
+ * } else {
29
+ * console.error('Invalid age:', t.left(invalidAgeResult).map(t.reporter.report));
30
+ * }
31
+ */
32
+ export default _default;
@@ -0,0 +1,40 @@
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 BasicTypes_1 = require("./BasicTypes");
6
+ /**
7
+ * Creates a custom runtime type for validating that a number falls within a specified range.
8
+ *
9
+ * @param min - The minimum value of the range.
10
+ * @param max - The maximum value of the range.
11
+ * @param fieldName - The name of the field being validated (used in error messages).
12
+ * @returns A runtime type representing the number range validation.
13
+ *
14
+ * * @example
15
+ * // Creating a custom runtime type for age validation
16
+ * const AgeType = numberInRange(18, 99, 'Age');
17
+ *
18
+ * // Valid age
19
+ * const validAgeResult = AgeType.decode(25);
20
+ * if (t.isRight(validAgeResult)) {
21
+ * console.log('Valid age:', validAgeResult.right); // Output: Valid age: 25
22
+ * } else {
23
+ * console.error('Invalid age:', t.left(validAgeResult).map(t.reporter.report));
24
+ * }
25
+ *
26
+ * @example
27
+ * // Invalid age
28
+ * const invalidAgeResult = AgeType.decode(15);
29
+ * if (t.isRight(invalidAgeResult)) {
30
+ * console.log('Valid age:', invalidAgeResult.right);
31
+ * } else {
32
+ * console.error('Invalid age:', t.left(invalidAgeResult).map(t.reporter.report));
33
+ * }
34
+ */
35
+ exports.default = (min, max, fieldName) => BasicTypes_1.Number.pipe(new t.Type("numberInRange", (u) => BasicTypes_1.Number.is(u), (u, context) => {
36
+ if (u > max || u < min) {
37
+ return t.failure(u, context, `${fieldName} must be a number between ${min} and ${max}`);
38
+ }
39
+ return t.success(u);
40
+ }, t.identity));