@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.
- package/lib/customtypes/CustomType.d.ts +2 -20
- package/lib/customtypes/CustomType.js +33 -25
- package/lib/customtypes/Format.js +5 -2
- package/lib/customtypes/Section.d.ts +3 -30
- package/lib/customtypes/Section.js +14 -9
- package/lib/customtypes/index.js +9 -4
- package/lib/customtypes/widgets/Group.js +12 -9
- package/lib/customtypes/widgets/UID.js +10 -7
- package/lib/customtypes/widgets/Widget.d.ts +3 -30
- package/lib/customtypes/widgets/Widget.js +19 -14
- package/lib/customtypes/widgets/WidgetTypes.js +3 -1
- package/lib/customtypes/widgets/index.js +14 -7
- package/lib/customtypes/widgets/nestable/BooleanField.js +9 -6
- package/lib/customtypes/widgets/nestable/Color.js +10 -7
- package/lib/customtypes/widgets/nestable/Date.js +10 -7
- package/lib/customtypes/widgets/nestable/Embed.js +10 -7
- package/lib/customtypes/widgets/nestable/GeoPoint.js +10 -7
- package/lib/customtypes/widgets/nestable/Image.js +13 -10
- package/lib/customtypes/widgets/nestable/IntegrationField.js +10 -7
- package/lib/customtypes/widgets/nestable/Link.js +14 -11
- package/lib/customtypes/widgets/nestable/NestableWidget.js +35 -32
- package/lib/customtypes/widgets/nestable/Number.js +14 -11
- package/lib/customtypes/widgets/nestable/Range.js +14 -11
- package/lib/customtypes/widgets/nestable/RichText.js +15 -12
- package/lib/customtypes/widgets/nestable/Select.js +11 -8
- package/lib/customtypes/widgets/nestable/Separator.js +9 -6
- package/lib/customtypes/widgets/nestable/Text.js +10 -7
- package/lib/customtypes/widgets/nestable/Timestamp.js +10 -7
- package/lib/customtypes/widgets/nestable/index.js +36 -15
- package/lib/customtypes/widgets/shared/ImageConstraint.js +12 -9
- package/lib/customtypes/widgets/shared/index.js +8 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.js +13 -10
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +1 -10
- package/lib/customtypes/widgets/slices/LegacySlice.js +8 -6
- package/lib/customtypes/widgets/slices/SharedSlice.js +12 -9
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +7 -4
- package/lib/customtypes/widgets/slices/Slice.js +2 -1
- package/lib/customtypes/widgets/slices/Slices.d.ts +6 -60
- package/lib/customtypes/widgets/slices/Slices.js +33 -27
- package/lib/customtypes/widgets/slices/SlicesTypes.js +3 -1
- package/lib/customtypes/widgets/slices/index.js +16 -7
- package/lib/documents/DocumentData.js +7 -4
- package/lib/documents/index.js +7 -2
- package/lib/documents/widgets/EmptyContent.js +6 -3
- package/lib/documents/widgets/GroupContent.js +14 -10
- package/lib/documents/widgets/SimpleWidgetContent.js +32 -27
- package/lib/documents/widgets/StaticWidgetContent.js +11 -8
- package/lib/documents/widgets/UIDContent.js +8 -4
- package/lib/documents/widgets/index.js +27 -22
- package/lib/documents/widgets/nestable/BooleanContent.js +10 -6
- package/lib/documents/widgets/nestable/EmbedContent.js +24 -20
- package/lib/documents/widgets/nestable/FieldContent.js +10 -6
- package/lib/documents/widgets/nestable/GeoPointContent.js +9 -5
- package/lib/documents/widgets/nestable/ImageContent.js +16 -12
- package/lib/documents/widgets/nestable/IntegrationFieldsContent.js +10 -6
- package/lib/documents/widgets/nestable/Link/DocumentLink.js +12 -7
- package/lib/documents/widgets/nestable/Link/ExternalLink.js +15 -10
- package/lib/documents/widgets/nestable/Link/FileLink.js +15 -10
- package/lib/documents/widgets/nestable/Link/ImageLink.js +14 -9
- package/lib/documents/widgets/nestable/Link/LinkContent.js +13 -9
- package/lib/documents/widgets/nestable/Link/index.js +33 -24
- package/lib/documents/widgets/nestable/SeparatorContent.js +5 -2
- package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +39 -33
- package/lib/documents/widgets/nestable/StructuredTextContent/index.js +11 -7
- package/lib/documents/widgets/nestable/index.js +39 -28
- package/lib/documents/widgets/slices/CompositeSliceContent.js +13 -9
- package/lib/documents/widgets/slices/SharedSliceContent.js +16 -12
- package/lib/documents/widgets/slices/SimpleSliceContent.js +6 -2
- package/lib/documents/widgets/slices/SliceWidgetContent.js +12 -8
- package/lib/documents/widgets/slices/SlicesContent.js +17 -13
- package/lib/documents/widgets/slices/index.js +8 -5
- package/lib/index.js +7 -3
- package/lib/validators/DateFromString.js +7 -4
- package/lib/validators/DateFromStringOrNumber.js +7 -4
- package/lib/validators/DateFromTsMs.js +7 -4
- package/lib/validators/IntFromNumber.js +7 -4
- package/lib/validators/IntFromPixels.js +7 -4
- package/lib/validators/NonEmptyString.js +6 -3
- package/lib/validators/NonEmptyStringOrNull.js +10 -7
- package/lib/validators/NumberOrNull.js +6 -3
- package/lib/validators/StringFromBoolean.js +7 -4
- package/lib/validators/StringFromNumber.js +7 -4
- package/lib/validators/StringOrNull.js +6 -3
- package/lib/validators/function.js +28 -15
- package/lib/validators/index.js +27 -12
- package/package.json +1 -1
- package/src/customtypes/widgets/slices/LegacySlice.ts +1 -2
|
@@ -1,29 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
24
|
+
exports.filterDouble = filterDouble;
|
|
25
|
+
function formatDateTime(date) {
|
|
19
26
|
return date.toISOString().replace(/\.\d{3}Z$/, "+0000");
|
|
20
27
|
}
|
|
21
|
-
|
|
28
|
+
exports.formatDateTime = formatDateTime;
|
|
29
|
+
function formatDate(date) {
|
|
22
30
|
return date.toISOString().replace(/T.*/, "");
|
|
23
31
|
}
|
|
24
|
-
|
|
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
|
-
|
|
45
|
+
exports.grouped = grouped;
|
|
46
|
+
function objectToMap(object) {
|
|
37
47
|
return new Map(Object.entries(object));
|
|
38
48
|
}
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
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;
|
package/lib/validators/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
@@ -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([
|
|
6
|
+
const LegacySlice = t.union([NestableWidget, Group])
|
|
8
7
|
|
|
9
8
|
type LegacySlice = t.TypeOf<typeof LegacySlice>
|
|
10
9
|
|