@prismicio/types-internal 3.16.2-alpha.2 → 3.16.2-alpha.4
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/content/fields/nestable/LinkContent.js +17 -17
- package/lib/content/fields/nestable/TableContent.d.ts +1 -1
- package/lib/content/fields/nestable/TableContent.js +6 -6
- package/lib/content/fields/slices/SlicesContent.d.ts +8 -0
- package/lib/content/fields/slices/SlicesContent.js +2 -1
- package/lib/content/helpers.d.ts +9 -0
- package/lib/content/helpers.js +22 -0
- package/lib/content/utils.d.ts +3 -10
- package/lib/content/utils.js +6 -21
- package/package.json +1 -1
- package/src/content/fields/nestable/LinkContent.ts +1 -1
- package/src/content/fields/nestable/TableContent.ts +2 -3
- package/src/content/fields/slices/SlicesContent.ts +1 -1
- package/src/content/helpers.ts +25 -0
- package/src/content/utils.ts +3 -26
|
@@ -31,7 +31,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
31
31
|
const io_ts_types_1 = require("io-ts-types");
|
|
32
32
|
const validators_1 = require("../../../validators");
|
|
33
33
|
const function_2 = require("../../../validators/function");
|
|
34
|
-
const
|
|
34
|
+
const helpers_1 = require("../../helpers");
|
|
35
35
|
// ImageLink.
|
|
36
36
|
exports.ImageLinkType = "ImageLink";
|
|
37
37
|
const isImageLinkKind = (input) => typeof input === "string";
|
|
@@ -52,7 +52,7 @@ const filledImageLinkLegacyCodec = t.intersection([
|
|
|
52
52
|
date: validators_1.StringOrNull,
|
|
53
53
|
})),
|
|
54
54
|
]);
|
|
55
|
-
const FilledImageLinkLegacy = new t.Type("FilledImageLink", (u) => (0,
|
|
55
|
+
const FilledImageLinkLegacy = new t.Type("FilledImageLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
|
|
56
56
|
return (0, function_1.pipe)(filledImageLinkLegacyCodec.decode(image), fp_ts_1.either.map((parsedImage) => {
|
|
57
57
|
return exports.FilledImageLinkContent.encode({
|
|
58
58
|
...parsedImage,
|
|
@@ -80,7 +80,7 @@ const imageLinkLegacyCodec = t.intersection([
|
|
|
80
80
|
variant: t.string,
|
|
81
81
|
})),
|
|
82
82
|
]);
|
|
83
|
-
const ImageLinkLegacy = new t.Type("ImageLink", (u) => (0,
|
|
83
|
+
const ImageLinkLegacy = new t.Type("ImageLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ImageLinkType, (image) => {
|
|
84
84
|
return (0, function_1.pipe)(imageLinkLegacyCodec.decode(image), fp_ts_1.either.map((parsedImage) => {
|
|
85
85
|
return exports.ImageLinkContent.encode({
|
|
86
86
|
...parsedImage,
|
|
@@ -112,7 +112,7 @@ const filledFileLinkLegacyCodec = t.exact(t.intersection([
|
|
|
112
112
|
}),
|
|
113
113
|
t.partial({ date: validators_1.StringOrNull }),
|
|
114
114
|
]));
|
|
115
|
-
const FilledFileLinkLegacy = new t.Type("FilledFileLink", (u) => (0,
|
|
115
|
+
const FilledFileLinkLegacy = new t.Type("FilledFileLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
|
|
116
116
|
return (0, function_1.pipe)(filledFileLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedFile) => {
|
|
117
117
|
return exports.FilledFileLinkContent.encode({
|
|
118
118
|
...parsedFile,
|
|
@@ -140,7 +140,7 @@ const fileLinkLegacyCodec = t.intersection([
|
|
|
140
140
|
variant: t.string,
|
|
141
141
|
})),
|
|
142
142
|
]);
|
|
143
|
-
const FileLinkLegacy = new t.Type("FileLink", (u) => (0,
|
|
143
|
+
const FileLinkLegacy = new t.Type("FileLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.FileLinkType, (file) => {
|
|
144
144
|
return (0, function_1.pipe)(fileLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedFile) => {
|
|
145
145
|
return exports.FileLinkContent.encode({
|
|
146
146
|
...parsedFile,
|
|
@@ -167,7 +167,7 @@ const mediaLinkLegacyCodec = t.intersection([
|
|
|
167
167
|
variant: t.string,
|
|
168
168
|
})),
|
|
169
169
|
]);
|
|
170
|
-
const MediaLinkLegacy = new t.Type("MediaLink", (u) => (0,
|
|
170
|
+
const MediaLinkLegacy = new t.Type("MediaLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.MediaLinkType, (mediaLink) => {
|
|
171
171
|
return (0, function_1.pipe)(mediaLinkLegacyCodec.decode(mediaLink), fp_ts_1.either.map((parsedMediaLink) => {
|
|
172
172
|
return exports.MediaLinkContent.encode({
|
|
173
173
|
...parsedMediaLink,
|
|
@@ -188,7 +188,7 @@ exports.DocumentLinkType = "DocumentLink";
|
|
|
188
188
|
const filledDocumentLinkLegacyCodec = t.strict({
|
|
189
189
|
id: validators_1.NonEmptyString,
|
|
190
190
|
});
|
|
191
|
-
const FilledDocumentLinkLegacy = new t.Type("FilledDocumentLink", (u) => (0,
|
|
191
|
+
const FilledDocumentLinkLegacy = new t.Type("FilledDocumentLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (doc) => {
|
|
192
192
|
return (0, function_1.pipe)(filledDocumentLinkLegacyCodec.decode(doc), fp_ts_1.either.map((parsedDoc) => {
|
|
193
193
|
return exports.FilledDocumentLinkContent.encode({
|
|
194
194
|
...parsedDoc,
|
|
@@ -216,7 +216,7 @@ const documentLinkLegacyCodec = t.intersection([
|
|
|
216
216
|
variant: t.string,
|
|
217
217
|
})),
|
|
218
218
|
]);
|
|
219
|
-
const DocumentLinkLegacy = new t.Type("DocumentLink", (u) => (0,
|
|
219
|
+
const DocumentLinkLegacy = new t.Type("DocumentLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.DocumentLinkType, (file) => {
|
|
220
220
|
return (0, function_1.pipe)(documentLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedDoc) => {
|
|
221
221
|
return exports.DocumentLinkContent.encode({
|
|
222
222
|
...parsedDoc,
|
|
@@ -246,7 +246,7 @@ const filledExternalLinkLegacyCodec = t.exact(t.intersection([
|
|
|
246
246
|
})),
|
|
247
247
|
}),
|
|
248
248
|
]));
|
|
249
|
-
const FilledExternalLinkLegacy = new t.Type("FilledExternalLink", (u) => (0,
|
|
249
|
+
const FilledExternalLinkLegacy = new t.Type("FilledExternalLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (link) => {
|
|
250
250
|
return (0, function_1.pipe)(filledExternalLinkLegacyCodec.decode(link), fp_ts_1.either.map((parsedLink) => {
|
|
251
251
|
return exports.FilledExternalLinkContent.encode({
|
|
252
252
|
...parsedLink,
|
|
@@ -274,7 +274,7 @@ const externalLinkLegacyCodec = t.intersection([
|
|
|
274
274
|
variant: t.string,
|
|
275
275
|
})),
|
|
276
276
|
]);
|
|
277
|
-
const ExternalLinkLegacy = new t.Type("ExternalLink", (u) => (0,
|
|
277
|
+
const ExternalLinkLegacy = new t.Type("ExternalLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.ExternalLinkType, (file) => {
|
|
278
278
|
return (0, function_1.pipe)(externalLinkLegacyCodec.decode(file), fp_ts_1.either.map((parsedLink) => {
|
|
279
279
|
return exports.ExternalLinkContent.encode({
|
|
280
280
|
...parsedLink,
|
|
@@ -301,7 +301,7 @@ const anyLinkLegacyCodec = t.exact(t.intersection([
|
|
|
301
301
|
variant: t.string,
|
|
302
302
|
}),
|
|
303
303
|
]));
|
|
304
|
-
const AnyLinkLegacy = new t.Type("AnyLink", (u) => (0,
|
|
304
|
+
const AnyLinkLegacy = new t.Type("AnyLink", (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.AnyLinkType, (anyLink) => {
|
|
305
305
|
return (0, function_1.pipe)(anyLinkLegacyCodec.decode(anyLink), fp_ts_1.either.map((parsedAnyLink) => {
|
|
306
306
|
return exports.AnyLinkContent.encode({
|
|
307
307
|
...parsedAnyLink,
|
|
@@ -319,9 +319,9 @@ exports.AnyLinkContent = t.intersection([
|
|
|
319
319
|
]);
|
|
320
320
|
// Link.
|
|
321
321
|
exports.LinkContentType = "LinkContent";
|
|
322
|
-
const isLinkContent = (u) => (0,
|
|
322
|
+
const isLinkContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
|
|
323
323
|
exports.isLinkContent = isLinkContent;
|
|
324
|
-
exports.LinkLegacy = (0,
|
|
324
|
+
exports.LinkLegacy = (0, helpers_1.withKey)(t.union([
|
|
325
325
|
ImageLinkLegacy,
|
|
326
326
|
FileLinkLegacy,
|
|
327
327
|
DocumentLinkLegacy,
|
|
@@ -354,12 +354,12 @@ exports.Link = t.union([
|
|
|
354
354
|
exports.MediaLinkContent,
|
|
355
355
|
exports.AnyLinkContent,
|
|
356
356
|
]);
|
|
357
|
-
exports.LinkContent = (0,
|
|
357
|
+
exports.LinkContent = (0, helpers_1.withKey)(t.strict({
|
|
358
358
|
__TYPE__: t.literal(exports.LinkContentType),
|
|
359
359
|
value: exports.Link,
|
|
360
360
|
}));
|
|
361
361
|
// FilledLink.
|
|
362
|
-
const isFilledLinkContent = (u) => (0,
|
|
362
|
+
const isFilledLinkContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.LinkContentType;
|
|
363
363
|
exports.isFilledLinkContent = isFilledLinkContent;
|
|
364
364
|
exports.FilledLinkLegacy = t.union([
|
|
365
365
|
FilledImageLinkLegacy,
|
|
@@ -368,7 +368,7 @@ exports.FilledLinkLegacy = t.union([
|
|
|
368
368
|
FilledExternalLinkLegacy,
|
|
369
369
|
]);
|
|
370
370
|
const FilledLinkContentLegacy = (ctx) => {
|
|
371
|
-
const FilledLinkLegacyWithKey = (0,
|
|
371
|
+
const FilledLinkLegacyWithKey = (0, helpers_1.withKey)(exports.FilledLinkLegacy);
|
|
372
372
|
return new t.Type("FilledLinkLegacy", exports.isFilledLinkContent, (u) => {
|
|
373
373
|
return (0, function_1.pipe)(FilledLinkLegacyWithKey.decode(u), fp_ts_1.either.map(({ key, ...value }) => exports.FilledLinkContent.encode({
|
|
374
374
|
__TYPE__: "LinkContent",
|
|
@@ -393,7 +393,7 @@ exports.FilledLink = t.union([
|
|
|
393
393
|
exports.FilledDocumentLinkContent,
|
|
394
394
|
exports.FilledExternalLinkContent,
|
|
395
395
|
]);
|
|
396
|
-
exports.FilledLinkContent = (0,
|
|
396
|
+
exports.FilledLinkContent = (0, helpers_1.withKey)(t.strict({
|
|
397
397
|
__TYPE__: t.literal(exports.LinkContentType),
|
|
398
398
|
value: exports.FilledLink,
|
|
399
399
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import { type NestableWidget } from "../../../customtypes";
|
|
3
3
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
4
|
-
import { ContentPath, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../../utils";
|
|
4
|
+
import type { ContentPath, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../../utils";
|
|
5
5
|
export declare const TableContentType = "TableContent";
|
|
6
6
|
export declare const isTableContent: (u: unknown) => u is {
|
|
7
7
|
__TYPE__: "TableContent";
|
|
@@ -6,12 +6,12 @@ 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
8
|
const customtypes_1 = require("../../../customtypes");
|
|
9
|
-
const
|
|
9
|
+
const helpers_1 = require("../../helpers");
|
|
10
10
|
const RichTextContent_1 = require("./RichTextContent");
|
|
11
11
|
exports.TableContentType = "TableContent";
|
|
12
|
-
const isTableContent = (u) => (0,
|
|
12
|
+
const isTableContent = (u) => (0, helpers_1.hasContentType)(u) && u.__TYPE__ === exports.TableContentType;
|
|
13
13
|
exports.isTableContent = isTableContent;
|
|
14
|
-
const TableCell = (0,
|
|
14
|
+
const TableCell = (0, helpers_1.withKey)(t.intersection([
|
|
15
15
|
t.strict({
|
|
16
16
|
type: t.union([t.literal("tableHeader"), t.literal("tableCell")]),
|
|
17
17
|
content: RichTextContent_1.RichTextContent,
|
|
@@ -20,7 +20,7 @@ const TableCell = (0, utils_1.withKey)(t.intersection([
|
|
|
20
20
|
columnWidth: t.number,
|
|
21
21
|
})),
|
|
22
22
|
]));
|
|
23
|
-
const TableRow = (0,
|
|
23
|
+
const TableRow = (0, helpers_1.withKey)(t.strict({
|
|
24
24
|
type: t.literal("tableRow"),
|
|
25
25
|
content: t.array(TableCell),
|
|
26
26
|
}));
|
|
@@ -29,7 +29,7 @@ exports.TableContent = t.strict({
|
|
|
29
29
|
content: t.array(TableRow),
|
|
30
30
|
});
|
|
31
31
|
// Legacy.
|
|
32
|
-
const TableCellLegacy = (0,
|
|
32
|
+
const TableCellLegacy = (0, helpers_1.withKey)(t.intersection([
|
|
33
33
|
t.strict({
|
|
34
34
|
type: t.union([t.literal("tableHeader"), t.literal("tableCell")]),
|
|
35
35
|
content: RichTextContent_1.RichTextLegacyContent,
|
|
@@ -38,7 +38,7 @@ const TableCellLegacy = (0, utils_1.withKey)(t.intersection([
|
|
|
38
38
|
columnWidth: t.number,
|
|
39
39
|
})),
|
|
40
40
|
]));
|
|
41
|
-
const TableRowLegacy = (0,
|
|
41
|
+
const TableRowLegacy = (0, helpers_1.withKey)(t.strict({
|
|
42
42
|
type: t.literal("tableRow"),
|
|
43
43
|
content: t.array(TableCellLegacy),
|
|
44
44
|
}));
|
|
@@ -2,6 +2,7 @@ import * as t from "io-ts";
|
|
|
2
2
|
import { type StaticSlices, CompositeSlice, Group, NestableWidget, VariationFields } from "../../../customtypes";
|
|
3
3
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
4
4
|
import { ContentPath, TraverseSliceContentFn, TraverseSliceContentWithModelFn, TraverseWidgetContentFn, TraverseWidgetContentWithModelFn } from "../../utils";
|
|
5
|
+
import { SharedSliceItemContent } from "./SliceItem";
|
|
5
6
|
export declare const SlicesContentType = "SliceContentType";
|
|
6
7
|
export declare const isSlicesContent: (u: unknown) => u is {
|
|
7
8
|
__TYPE__: "SliceContentType";
|
|
@@ -9807,6 +9808,13 @@ export declare function traverseSlices({ path, key, model, content, }: {
|
|
|
9807
9808
|
transformWidget?: TraverseWidgetContentFn;
|
|
9808
9809
|
transformSlice?: TraverseSliceContentFn;
|
|
9809
9810
|
}) => SlicesContent | undefined;
|
|
9811
|
+
export declare function traverseSharedSliceContentWithModel({ path, sliceKey, sliceName, model, content, }: {
|
|
9812
|
+
path: ContentPath;
|
|
9813
|
+
sliceKey: string;
|
|
9814
|
+
sliceName: string;
|
|
9815
|
+
model: VariationFields;
|
|
9816
|
+
content: SharedSliceItemContent | undefined;
|
|
9817
|
+
}): (transformWidget: TraverseWidgetContentWithModelFn, transformSlice: TraverseSliceContentWithModelFn) => SharedSliceItemContent | undefined;
|
|
9810
9818
|
export declare function traverseSlicesWithModel({ path, key, model, content, }: {
|
|
9811
9819
|
path: ContentPath;
|
|
9812
9820
|
key: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseSlicesWithModel = exports.traverseSlices = exports.slicesContentWithDefaultValues = exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = void 0;
|
|
3
|
+
exports.traverseSlicesWithModel = exports.traverseSharedSliceContentWithModel = exports.traverseSlices = exports.slicesContentWithDefaultValues = exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = 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");
|
|
@@ -288,6 +288,7 @@ function traverseSharedSliceContentWithModel({ path, sliceKey, sliceName, model,
|
|
|
288
288
|
});
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
|
+
exports.traverseSharedSliceContentWithModel = traverseSharedSliceContentWithModel;
|
|
291
292
|
function traverseCompositeSliceContentWithModel({ path, sliceKey, sliceName, model, content, }) {
|
|
292
293
|
return (transformWidget, transformSlice) => {
|
|
293
294
|
var _a, _b, _c, _d;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
declare type WithContentType = {
|
|
3
|
+
__TYPE__: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function hasContentType(obj: unknown): obj is WithContentType;
|
|
6
|
+
export declare function withKey<C extends t.Mixed>(codec: C): t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
7
|
+
key: t.Type<string, string, unknown>;
|
|
8
|
+
}>>, C]>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withKey = exports.hasContentType = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
function hasContentType(obj) {
|
|
8
|
+
return typeof obj === "object" && obj !== null && "__TYPE__" in obj;
|
|
9
|
+
}
|
|
10
|
+
exports.hasContentType = hasContentType;
|
|
11
|
+
const isUuid = (input) => typeof input === "string" && (0, uuid_1.validate)(input);
|
|
12
|
+
const uuidWithFallback = new t.Type("UUID", isUuid, (u, c) => {
|
|
13
|
+
if (typeof u === "undefined")
|
|
14
|
+
return t.success((0, uuid_1.v4)());
|
|
15
|
+
if (isUuid(u))
|
|
16
|
+
return t.success(u);
|
|
17
|
+
return t.failure(u, c);
|
|
18
|
+
}, t.identity);
|
|
19
|
+
function withKey(codec) {
|
|
20
|
+
return t.intersection([t.strict({ key: uuidWithFallback }), codec]);
|
|
21
|
+
}
|
|
22
|
+
exports.withKey = withKey;
|
package/lib/content/utils.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
1
|
import type { CompositeSlice, Group, NestableWidget, StaticSlices, UID, VariationFields } from "../customtypes";
|
|
3
2
|
import { FieldType, SharedSliceItemContent, SliceItemContent, WidgetContent } from "./fields";
|
|
4
|
-
|
|
3
|
+
export { hasContentType, withKey } from "./helpers";
|
|
4
|
+
declare type WithFieldType = {
|
|
5
|
+
__TYPE__: string;
|
|
5
6
|
type: FieldType;
|
|
6
7
|
};
|
|
7
8
|
export declare function hasFieldContentType(obj: unknown): obj is WithFieldType;
|
|
8
|
-
declare type WithContentType = {
|
|
9
|
-
__TYPE__: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function hasContentType(obj: unknown): obj is WithContentType;
|
|
12
|
-
export declare function withKey<C extends t.Mixed>(codec: C): t.IntersectionC<[t.ExactC<t.TypeC<{
|
|
13
|
-
key: t.Type<string, string, unknown>;
|
|
14
|
-
}>>, C]>;
|
|
15
9
|
export declare type TraverseSliceContentFn = <S extends SliceItemContent | SharedSliceItemContent, D extends VariationFields | CompositeSlice | Group | NestableWidget>({ path, key, apiId, model, content, }: {
|
|
16
10
|
path: ContentPath;
|
|
17
11
|
key: string;
|
|
@@ -54,4 +48,3 @@ export declare const ContentPath: {
|
|
|
54
48
|
type: ContentPathEntry["type"];
|
|
55
49
|
}>): ContentPath;
|
|
56
50
|
};
|
|
57
|
-
export {};
|
package/lib/content/utils.js
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContentPath = exports.
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
3
|
+
exports.ContentPath = exports.hasFieldContentType = exports.withKey = exports.hasContentType = void 0;
|
|
5
4
|
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
-
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
5
|
const fields_1 = require("./fields");
|
|
6
|
+
var helpers_1 = require("./helpers");
|
|
7
|
+
Object.defineProperty(exports, "hasContentType", { enumerable: true, get: function () { return helpers_1.hasContentType; } });
|
|
8
|
+
Object.defineProperty(exports, "withKey", { enumerable: true, get: function () { return helpers_1.withKey; } });
|
|
9
|
+
const helpers_2 = require("./helpers");
|
|
9
10
|
function hasFieldContentType(obj) {
|
|
10
11
|
var _a;
|
|
11
|
-
return (hasContentType(obj) &&
|
|
12
|
+
return ((0, helpers_2.hasContentType)(obj) &&
|
|
12
13
|
obj.__TYPE__ === fields_1.FieldContentType &&
|
|
13
14
|
((_a = obj) === null || _a === void 0 ? void 0 : _a.type) !== undefined &&
|
|
14
15
|
typeof obj.type === "string" &&
|
|
15
16
|
(0, Either_1.isRight)(fields_1.FieldType.decode(obj.type)));
|
|
16
17
|
}
|
|
17
18
|
exports.hasFieldContentType = hasFieldContentType;
|
|
18
|
-
function hasContentType(obj) {
|
|
19
|
-
return typeof obj === "object" && obj !== null && "__TYPE__" in obj;
|
|
20
|
-
}
|
|
21
|
-
exports.hasContentType = hasContentType;
|
|
22
|
-
const isUuid = (input) => typeof input === "string" && (0, uuid_1.validate)(input);
|
|
23
|
-
const uuidWithFallback = new t.Type("UUID", isUuid, (u, c) => {
|
|
24
|
-
if (typeof u === "undefined")
|
|
25
|
-
return t.success((0, uuid_1.v4)());
|
|
26
|
-
if (isUuid(u))
|
|
27
|
-
return t.success(u);
|
|
28
|
-
return t.failure(u, c);
|
|
29
|
-
}, t.identity);
|
|
30
|
-
function withKey(codec) {
|
|
31
|
-
return t.intersection([t.strict({ key: uuidWithFallback }), codec]);
|
|
32
|
-
}
|
|
33
|
-
exports.withKey = withKey;
|
|
34
19
|
const PATH_SEPARATOR = "::";
|
|
35
20
|
exports.ContentPath = {
|
|
36
21
|
serialize(path) {
|
package/package.json
CHANGED
|
@@ -29,8 +29,8 @@ import { withFallback } from "io-ts-types"
|
|
|
29
29
|
|
|
30
30
|
import { NonEmptyString, StringOrNull } from "../../../validators"
|
|
31
31
|
import { nullable } from "../../../validators/function"
|
|
32
|
+
import { hasContentType, withKey } from "../../helpers"
|
|
32
33
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
33
|
-
import { hasContentType, withKey } from "../../utils"
|
|
34
34
|
|
|
35
35
|
// ImageLink.
|
|
36
36
|
|
|
@@ -6,13 +6,12 @@ import {
|
|
|
6
6
|
type NestableWidget,
|
|
7
7
|
TableCell as TableCellModel,
|
|
8
8
|
} from "../../../customtypes"
|
|
9
|
+
import { hasContentType, withKey } from "../../helpers"
|
|
9
10
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx"
|
|
10
|
-
import {
|
|
11
|
+
import type {
|
|
11
12
|
ContentPath,
|
|
12
|
-
hasContentType,
|
|
13
13
|
TraverseWidgetContentFn,
|
|
14
14
|
TraverseWidgetContentWithModelFn,
|
|
15
|
-
withKey,
|
|
16
15
|
} from "../../utils"
|
|
17
16
|
import { RichTextContent, RichTextLegacyContent } from "./RichTextContent"
|
|
18
17
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as t from "io-ts"
|
|
2
|
+
import { v4 as uuid, validate as validateUuid } from "uuid"
|
|
3
|
+
|
|
4
|
+
type WithContentType = { __TYPE__: string }
|
|
5
|
+
export function hasContentType(obj: unknown): obj is WithContentType {
|
|
6
|
+
return typeof obj === "object" && obj !== null && "__TYPE__" in obj
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const isUuid = (input: unknown): input is string =>
|
|
10
|
+
typeof input === "string" && validateUuid(input)
|
|
11
|
+
|
|
12
|
+
const uuidWithFallback = new t.Type<string, string, unknown>(
|
|
13
|
+
"UUID",
|
|
14
|
+
isUuid,
|
|
15
|
+
(u, c) => {
|
|
16
|
+
if (typeof u === "undefined") return t.success(uuid())
|
|
17
|
+
if (isUuid(u)) return t.success(u)
|
|
18
|
+
return t.failure(u, c)
|
|
19
|
+
},
|
|
20
|
+
t.identity,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export function withKey<C extends t.Mixed>(codec: C) {
|
|
24
|
+
return t.intersection([t.strict({ key: uuidWithFallback }), codec])
|
|
25
|
+
}
|
package/src/content/utils.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { isRight } from "fp-ts/lib/Either"
|
|
2
|
-
import * as t from "io-ts"
|
|
3
|
-
import { v4 as uuid, validate as validateUuid } from "uuid"
|
|
4
2
|
|
|
5
3
|
import type {
|
|
6
4
|
CompositeSlice,
|
|
@@ -17,8 +15,10 @@ import {
|
|
|
17
15
|
SliceItemContent,
|
|
18
16
|
WidgetContent,
|
|
19
17
|
} from "./fields"
|
|
18
|
+
export { hasContentType, withKey } from "./helpers"
|
|
19
|
+
import { hasContentType } from "./helpers"
|
|
20
20
|
|
|
21
|
-
type WithFieldType =
|
|
21
|
+
type WithFieldType = { __TYPE__: string; type: FieldType }
|
|
22
22
|
export function hasFieldContentType(obj: unknown): obj is WithFieldType {
|
|
23
23
|
return (
|
|
24
24
|
hasContentType(obj) &&
|
|
@@ -29,29 +29,6 @@ export function hasFieldContentType(obj: unknown): obj is WithFieldType {
|
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
type WithContentType = { __TYPE__: string }
|
|
33
|
-
export function hasContentType(obj: unknown): obj is WithContentType {
|
|
34
|
-
return typeof obj === "object" && obj !== null && "__TYPE__" in obj
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const isUuid = (input: unknown): input is string =>
|
|
38
|
-
typeof input === "string" && validateUuid(input)
|
|
39
|
-
|
|
40
|
-
const uuidWithFallback = new t.Type<string, string, unknown>(
|
|
41
|
-
"UUID",
|
|
42
|
-
isUuid,
|
|
43
|
-
(u, c) => {
|
|
44
|
-
if (typeof u === "undefined") return t.success(uuid())
|
|
45
|
-
if (isUuid(u)) return t.success(u)
|
|
46
|
-
return t.failure(u, c)
|
|
47
|
-
},
|
|
48
|
-
t.identity,
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
export function withKey<C extends t.Mixed>(codec: C) {
|
|
52
|
-
return t.intersection([t.strict({ key: uuidWithFallback }), codec])
|
|
53
|
-
}
|
|
54
|
-
|
|
55
32
|
export type TraverseSliceContentFn = <
|
|
56
33
|
S extends SliceItemContent | SharedSliceItemContent,
|
|
57
34
|
D extends VariationFields | CompositeSlice | Group | NestableWidget,
|