@prismicio/types-internal 2.0.0-alpha.3 → 2.0.0-alpha.5
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/Document.js +4 -3
- package/lib/content/LegacyContentCtx.js +1 -1
- package/lib/content/fields/GroupContent.d.ts +1 -1
- package/lib/content/fields/GroupContent.js +3 -3
- package/lib/content/fields/WidgetContent.d.ts +1 -1
- package/lib/content/fields/nestable/EmbedContent.d.ts +0 -1
- package/lib/content/fields/nestable/NestableContent.js +2 -1
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +4 -4
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +4 -4
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +4 -4
- package/lib/content/fields/slices/SliceItem.js +2 -1
- package/lib/content/utils.js +3 -3
- package/lib/customtypes/index.d.ts +2 -2
- package/lib/customtypes/index.js +2 -3
- package/lib/customtypes/widgets/Group.d.ts +164 -3
- package/lib/customtypes/widgets/Group.js +4 -5
- package/lib/customtypes/widgets/UID.d.ts +8 -3
- package/lib/customtypes/widgets/UID.js +4 -5
- package/lib/customtypes/widgets/Widget.d.ts +2 -2
- package/lib/customtypes/widgets/Widget.js +5 -5
- package/lib/customtypes/widgets/nestable/Link.d.ts +0 -1
- package/lib/customtypes/widgets/nestable/Link.js +0 -1
- package/lib/customtypes/widgets/nestable/RichText.d.ts +1 -1
- package/lib/customtypes/widgets/nestable/RichText.js +10 -10
- package/lib/customtypes/widgets/nestable/Text.d.ts +0 -1
- package/lib/customtypes/widgets/nestable/Text.js +0 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +6 -3
- package/lib/customtypes/widgets/slices/CompositeSlice.js +4 -5
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -3
- package/lib/customtypes/widgets/slices/LegacySlice.js +3 -3
- package/lib/customtypes/widgets/slices/SharedSliceRef.d.ts +2 -3
- package/lib/customtypes/widgets/slices/SharedSliceRef.js +2 -2
- package/lib/customtypes/widgets/slices/Slice.d.ts +3 -3
- package/lib/customtypes/widgets/slices/Slices.d.ts +13 -4
- package/lib/customtypes/widgets/slices/Slices.js +9 -9
- package/lib/customtypes/widgets/slices/index.d.ts +6 -6
- package/lib/customtypes/widgets/slices/index.js +6 -11
- package/package.json +1 -1
- package/src/content/Document.ts +4 -3
- package/src/content/LegacyContentCtx.ts +2 -2
- package/src/content/fields/GroupContent.ts +4 -4
- package/src/content/fields/WidgetContent.ts +1 -1
- package/src/content/fields/nestable/EmbedContent.ts +1 -1
- package/src/content/fields/nestable/NestableContent.ts +2 -1
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +4 -4
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -3
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +4 -3
- package/src/content/fields/slices/SliceItem.ts +2 -2
- package/src/content/utils.ts +4 -5
- package/src/customtypes/index.ts +2 -2
- package/src/customtypes/widgets/Group.ts +4 -6
- package/src/customtypes/widgets/UID.ts +4 -6
- package/src/customtypes/widgets/Widget.ts +5 -5
- package/src/customtypes/widgets/nestable/Link.ts +0 -2
- package/src/customtypes/widgets/nestable/RichText.ts +16 -16
- package/src/customtypes/widgets/nestable/Text.ts +0 -2
- package/src/customtypes/widgets/slices/CompositeSlice.ts +4 -6
- package/src/customtypes/widgets/slices/LegacySlice.ts +3 -5
- package/src/customtypes/widgets/slices/SharedSliceRef.ts +2 -4
- package/src/customtypes/widgets/slices/Slice.ts +3 -3
- package/src/customtypes/widgets/slices/Slices.ts +7 -7
- package/src/customtypes/widgets/slices/index.ts +6 -6
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
export declare const CompositeSliceType = "Slice";
|
|
3
|
-
declare const
|
|
3
|
+
export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
|
|
4
|
+
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
5
|
+
}>>;
|
|
6
|
+
export type CompositeSliceConfig = t.TypeOf<typeof CompositeSliceConfig>;
|
|
7
|
+
export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
4
8
|
type: t.LiteralC<"Slice">;
|
|
5
9
|
}>, t.PartialC<{
|
|
6
10
|
fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
@@ -325,5 +329,4 @@ declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
325
329
|
label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
326
330
|
}>>;
|
|
327
331
|
}>]>>;
|
|
328
|
-
type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
|
|
329
|
-
export default CompositeSlice;
|
|
332
|
+
export type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompositeSliceType = void 0;
|
|
3
|
+
exports.CompositeSlice = exports.CompositeSliceConfig = exports.CompositeSliceType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = tslib_1.__importStar(require("io-ts"));
|
|
6
6
|
const common_1 = require("../../../common");
|
|
7
7
|
const validators_1 = require("../../../validators");
|
|
8
8
|
const NestableWidget_1 = require("../nestable/NestableWidget");
|
|
9
9
|
exports.CompositeSliceType = "Slice";
|
|
10
|
-
|
|
10
|
+
exports.CompositeSliceConfig = t.exact(t.partial({
|
|
11
11
|
label: validators_1.StringOrNull,
|
|
12
12
|
}));
|
|
13
|
-
|
|
13
|
+
exports.CompositeSlice = t.exact(t.intersection([
|
|
14
14
|
t.type({
|
|
15
15
|
type: t.literal(exports.CompositeSliceType),
|
|
16
16
|
}),
|
|
@@ -21,7 +21,6 @@ const CompositeSlice = t.exact(t.intersection([
|
|
|
21
21
|
display: t.string,
|
|
22
22
|
"non-repeat": t.record(common_1.WidgetKey, NestableWidget_1.NestableWidget),
|
|
23
23
|
repeat: t.record(common_1.WidgetKey, NestableWidget_1.NestableWidget),
|
|
24
|
-
config: CompositeSliceConfig,
|
|
24
|
+
config: exports.CompositeSliceConfig,
|
|
25
25
|
}),
|
|
26
26
|
]));
|
|
27
|
-
exports.default = CompositeSlice;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
declare const LegacySlice: t.UnionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
2
|
+
export declare const LegacySlice: t.UnionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3
3
|
type: t.LiteralC<"Color">;
|
|
4
4
|
}>, t.PartialC<{
|
|
5
5
|
fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
@@ -323,5 +323,4 @@ declare const LegacySlice: t.UnionC<[t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC
|
|
|
323
323
|
}>]>>]>>;
|
|
324
324
|
}>>;
|
|
325
325
|
}>]>>]>;
|
|
326
|
-
type LegacySlice = t.TypeOf<typeof LegacySlice>;
|
|
327
|
-
export default LegacySlice;
|
|
326
|
+
export type LegacySlice = t.TypeOf<typeof LegacySlice>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LegacySlice = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const t = tslib_1.__importStar(require("io-ts"));
|
|
5
|
-
const Group_1 =
|
|
6
|
+
const Group_1 = require("../Group");
|
|
6
7
|
const NestableWidget_1 = require("../nestable/NestableWidget");
|
|
7
|
-
|
|
8
|
-
exports.default = LegacySlice;
|
|
8
|
+
exports.LegacySlice = t.union([NestableWidget_1.NestableWidget, Group_1.Group]);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
declare const SharedSliceRef: t.ExactC<t.TypeC<{
|
|
2
|
+
export declare const SharedSliceRef: t.ExactC<t.TypeC<{
|
|
3
3
|
type: t.LiteralC<"SharedSlice">;
|
|
4
4
|
}>>;
|
|
5
|
-
type SharedSliceRef = t.TypeOf<typeof SharedSliceRef>;
|
|
6
|
-
export default SharedSliceRef;
|
|
5
|
+
export type SharedSliceRef = t.TypeOf<typeof SharedSliceRef>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedSliceRef = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const t = tslib_1.__importStar(require("io-ts"));
|
|
5
6
|
const SharedSlice_1 = require("./SharedSlice");
|
|
6
|
-
|
|
7
|
+
exports.SharedSliceRef = t.exact(t.type({
|
|
7
8
|
type: t.literal(SharedSlice_1.SharedSliceType),
|
|
8
9
|
}));
|
|
9
|
-
exports.default = SharedSliceRef;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type CompositeSlice from "./CompositeSlice";
|
|
2
|
-
import type LegacySlice from "./LegacySlice";
|
|
1
|
+
import type { CompositeSlice } from "./CompositeSlice";
|
|
2
|
+
import type { LegacySlice } from "./LegacySlice";
|
|
3
3
|
import type { SharedSlice } from "./SharedSlice";
|
|
4
|
-
import type SharedSliceRef from "./SharedSliceRef";
|
|
4
|
+
import type { SharedSliceRef } from "./SharedSliceRef";
|
|
5
5
|
export type DynamicSlice = CompositeSlice | LegacySlice | SharedSliceRef;
|
|
6
6
|
export type StaticSlice = CompositeSlice | LegacySlice | SharedSlice;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import { SharedSlice } from "./SharedSlice";
|
|
3
|
-
import SharedSliceRef from "./SharedSliceRef";
|
|
3
|
+
import { SharedSliceRef } from "./SharedSliceRef";
|
|
4
4
|
export declare const LegacySlicesFieldType = "Choice";
|
|
5
5
|
export declare const SlicesFieldType = "Slices";
|
|
6
6
|
export declare const SlicesLabels: t.UnionC<[t.RecordC<t.StringC, t.ReadonlyArrayC<t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
@@ -2316,13 +2316,19 @@ export declare const DynamicSlicesConfig: t.ExactC<t.PartialC<{
|
|
|
2316
2316
|
}>>;
|
|
2317
2317
|
export type DynamicSlicesConfig = t.TypeOf<typeof DynamicSlicesConfig>;
|
|
2318
2318
|
export declare function slicesReader<T extends StaticSlicesConfig | DynamicSlicesConfig>(codec: t.Type<T, unknown>): t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
2319
|
-
type: t.
|
|
2319
|
+
type: t.KeyofC<{
|
|
2320
|
+
Slices: null;
|
|
2321
|
+
Choice: null;
|
|
2322
|
+
}>;
|
|
2320
2323
|
}>, t.PartialC<{
|
|
2321
2324
|
fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
2322
2325
|
config: t.Type<T, unknown, unknown>;
|
|
2323
2326
|
}>]>>;
|
|
2324
2327
|
export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
2325
|
-
type: t.
|
|
2328
|
+
type: t.KeyofC<{
|
|
2329
|
+
Slices: null;
|
|
2330
|
+
Choice: null;
|
|
2331
|
+
}>;
|
|
2326
2332
|
}>, t.PartialC<{
|
|
2327
2333
|
fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
2328
2334
|
config: t.Type<{
|
|
@@ -3328,7 +3334,10 @@ export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
3328
3334
|
}>]>>;
|
|
3329
3335
|
export type StaticSlices = t.TypeOf<typeof StaticSlices>;
|
|
3330
3336
|
export declare const DynamicSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
3331
|
-
type: t.
|
|
3337
|
+
type: t.KeyofC<{
|
|
3338
|
+
Slices: null;
|
|
3339
|
+
Choice: null;
|
|
3340
|
+
}>;
|
|
3332
3341
|
}>, t.PartialC<{
|
|
3333
3342
|
fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
|
|
3334
3343
|
config: t.Type<{
|
|
@@ -5,10 +5,10 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const t = tslib_1.__importStar(require("io-ts"));
|
|
6
6
|
const common_1 = require("../../../common");
|
|
7
7
|
const validators_1 = require("../../../validators");
|
|
8
|
-
const CompositeSlice_1 =
|
|
9
|
-
const LegacySlice_1 =
|
|
8
|
+
const CompositeSlice_1 = require("./CompositeSlice");
|
|
9
|
+
const LegacySlice_1 = require("./LegacySlice");
|
|
10
10
|
const SharedSlice_1 = require("./SharedSlice");
|
|
11
|
-
const SharedSliceRef_1 =
|
|
11
|
+
const SharedSliceRef_1 = require("./SharedSliceRef");
|
|
12
12
|
exports.LegacySlicesFieldType = "Choice";
|
|
13
13
|
exports.SlicesFieldType = "Slices";
|
|
14
14
|
exports.SlicesLabels = t.union([
|
|
@@ -26,12 +26,12 @@ function slicesConfigReader(codec) {
|
|
|
26
26
|
return t.exact(t.partial({
|
|
27
27
|
label: validators_1.StringOrNull,
|
|
28
28
|
labels: exports.SlicesLabels,
|
|
29
|
-
choices: t.record(common_1.WidgetKey, t.union([LegacySlice_1.
|
|
29
|
+
choices: t.record(common_1.WidgetKey, t.union([LegacySlice_1.LegacySlice, CompositeSlice_1.CompositeSlice, codec])),
|
|
30
30
|
}));
|
|
31
31
|
}
|
|
32
32
|
exports.slicesConfigReader = slicesConfigReader;
|
|
33
33
|
exports.StaticSlicesConfig = slicesConfigReader(SharedSlice_1.SharedSlice);
|
|
34
|
-
exports.DynamicSlicesConfig = slicesConfigReader(SharedSliceRef_1.
|
|
34
|
+
exports.DynamicSlicesConfig = slicesConfigReader(SharedSliceRef_1.SharedSliceRef);
|
|
35
35
|
const SlicesConfig = {
|
|
36
36
|
toStatic(config, sharedSlices) {
|
|
37
37
|
const choices = Object.entries(config.choices || {}).reduce((acc, [ref, slice]) => {
|
|
@@ -52,10 +52,10 @@ const SlicesConfig = {
|
|
|
52
52
|
function slicesReader(codec) {
|
|
53
53
|
return t.exact(t.intersection([
|
|
54
54
|
t.type({
|
|
55
|
-
type: t.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
type: t.keyof({
|
|
56
|
+
[exports.SlicesFieldType]: null,
|
|
57
|
+
[exports.LegacySlicesFieldType]: null,
|
|
58
|
+
}),
|
|
59
59
|
}),
|
|
60
60
|
t.partial({
|
|
61
61
|
fieldset: validators_1.StringOrNull,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./CompositeSlice";
|
|
2
|
+
export * from "./LegacySlice";
|
|
3
3
|
export * from "./SharedSlice";
|
|
4
|
-
export
|
|
5
|
-
export *
|
|
6
|
-
export *
|
|
7
|
-
export
|
|
4
|
+
export * from "./SharedSliceRef";
|
|
5
|
+
export * from "./Slice";
|
|
6
|
+
export * from "./Slices";
|
|
7
|
+
export * from "./SlicesTypes";
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SlicesTypes = exports.SliceZone = exports.Slice = exports.SharedSliceRef = exports.LegacySlice = exports.CompositeSlice = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var LegacySlice_1 = require("./LegacySlice");
|
|
8
|
-
Object.defineProperty(exports, "LegacySlice", { enumerable: true, get: function () { return tslib_1.__importDefault(LegacySlice_1).default; } });
|
|
4
|
+
tslib_1.__exportStar(require("./CompositeSlice"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./LegacySlice"), exports);
|
|
9
6
|
tslib_1.__exportStar(require("./SharedSlice"), exports);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var SlicesTypes_1 = require("./SlicesTypes");
|
|
15
|
-
Object.defineProperty(exports, "SlicesTypes", { enumerable: true, get: function () { return SlicesTypes_1.SlicesTypes; } });
|
|
7
|
+
tslib_1.__exportStar(require("./SharedSliceRef"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./Slice"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./Slices"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./SlicesTypes"), exports);
|
package/package.json
CHANGED
package/src/content/Document.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
+
import { isLeft, isRight } from "fp-ts/lib/Either"
|
|
2
3
|
import { pipe } from "fp-ts/lib/function"
|
|
3
4
|
import * as t from "io-ts"
|
|
4
5
|
|
|
@@ -29,7 +30,7 @@ const DocumentLegacyCodec = (allTypes?: LegacyContentCtx["allTypes"]) => {
|
|
|
29
30
|
(acc, [widgetKey, widgetValue]) => {
|
|
30
31
|
const widgetCtx = defaultCtx(widgetKey, allTypes)
|
|
31
32
|
const parsedW = WidgetLegacy(widgetCtx).decode(widgetValue)
|
|
32
|
-
if (!parsedW || parsedW
|
|
33
|
+
if (!parsedW || isLeft(parsedW)) return acc
|
|
33
34
|
|
|
34
35
|
return { ...acc, [widgetKey]: parsedW.right }
|
|
35
36
|
},
|
|
@@ -68,7 +69,7 @@ function extractMetadata(data: { [p: string]: unknown }): {
|
|
|
68
69
|
(acc, [k, v]) => {
|
|
69
70
|
if (k.endsWith("_TYPE")) {
|
|
70
71
|
const decodedValue = FieldOrSliceType.decode(v)
|
|
71
|
-
if (decodedValue
|
|
72
|
+
if (isRight(decodedValue)) {
|
|
72
73
|
return {
|
|
73
74
|
...acc,
|
|
74
75
|
types: acc.types.set(
|
|
@@ -118,7 +119,7 @@ function parseLegacyDocument(legacyDoc: unknown): Document | undefined {
|
|
|
118
119
|
}),
|
|
119
120
|
)
|
|
120
121
|
|
|
121
|
-
return result
|
|
122
|
+
return isLeft(result) ? undefined : result.right
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
function encodeToLegacyDocument(document: Document): DocumentLegacy {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { FieldType, SlicesTypes } from "../customtypes/widgets"
|
|
4
4
|
|
|
5
|
-
export const FieldOrSliceType = t.union([
|
|
5
|
+
export const FieldOrSliceType = t.union([FieldType, SlicesTypes])
|
|
6
6
|
export type FieldOrSliceType = t.TypeOf<typeof FieldOrSliceType>
|
|
7
7
|
export class LegacyContentCtx {
|
|
8
8
|
fieldKey: string
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
+
import { isLeft } from "fp-ts/lib/Either"
|
|
2
3
|
import { pipe } from "fp-ts/lib/function"
|
|
3
4
|
import * as t from "io-ts"
|
|
4
5
|
|
|
@@ -20,7 +21,7 @@ export const GroupItemContent = t.strict({
|
|
|
20
21
|
export type GroupItemContent = t.TypeOf<typeof GroupItemContent>
|
|
21
22
|
|
|
22
23
|
const itemLegacyReader = t.array(t.tuple([t.string, t.unknown]))
|
|
23
|
-
|
|
24
|
+
type GroupItemLegacy = t.TypeOf<typeof itemLegacyReader>
|
|
24
25
|
|
|
25
26
|
export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
|
|
26
27
|
return new t.Type<GroupItemContent, WithTypes<GroupItemLegacy>>(
|
|
@@ -37,9 +38,8 @@ export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
37
38
|
const result = NestableLegacy(itemCtx).decode(itemValue)
|
|
38
39
|
if (!result) return acc
|
|
39
40
|
|
|
40
|
-
if (result
|
|
41
|
-
|
|
42
|
-
else return acc
|
|
41
|
+
if (isLeft(result)) return acc
|
|
42
|
+
return [...acc, [itemKey, result.right]]
|
|
43
43
|
},
|
|
44
44
|
[],
|
|
45
45
|
)
|
|
@@ -35,7 +35,7 @@ export const isWidgetContent = (u: unknown): u is WidgetContent =>
|
|
|
35
35
|
isSlicesContent(u)
|
|
36
36
|
|
|
37
37
|
export type WidgetContent = t.TypeOf<typeof WidgetContent>
|
|
38
|
-
export type
|
|
38
|
+
export type ContentType = WidgetContent["__TYPE__"]
|
|
39
39
|
|
|
40
40
|
export const WidgetLegacy = (ctx: LegacyContentCtx) => {
|
|
41
41
|
return {
|
|
@@ -34,7 +34,7 @@ export const EmbedContentLegacy = t.exact(
|
|
|
34
34
|
]),
|
|
35
35
|
)
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
type EmbedLegacy = t.TypeOf<typeof EmbedContentLegacy>
|
|
38
38
|
|
|
39
39
|
export const EmbedLegacy = (ctx: LegacyContentCtx) =>
|
|
40
40
|
new t.Type<EmbedContent, WithTypes<EmbedLegacy>, unknown>(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRight } from "fp-ts/lib/Either"
|
|
1
2
|
import * as t from "io-ts"
|
|
2
3
|
|
|
3
4
|
import type { LegacyContentCtx } from "../../LegacyContentCtx"
|
|
@@ -119,7 +120,7 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
|
|
|
119
120
|
if (!ctx.fieldType) return
|
|
120
121
|
|
|
121
122
|
const nullValue = EmptyLegacy(ctx.fieldType).decode(value)
|
|
122
|
-
if (nullValue
|
|
123
|
+
if (isRight(nullValue)) return nullValue
|
|
123
124
|
|
|
124
125
|
const codec = (() => {
|
|
125
126
|
switch (ctx.fieldType) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
-
import
|
|
2
|
+
import { isLeft, isRight } from "fp-ts/lib/Either"
|
|
3
3
|
import { pipe } from "fp-ts/lib/function"
|
|
4
4
|
import * as t from "io-ts"
|
|
5
5
|
|
|
@@ -44,12 +44,12 @@ export const ValidatedMetas = (linkCodec: LinkCodec) =>
|
|
|
44
44
|
const res = metas
|
|
45
45
|
.reduce<Array<Meta>>((acc, maybeMeta) => {
|
|
46
46
|
const maybeDecodedMeta = Meta.decode(maybeMeta)
|
|
47
|
-
if (
|
|
47
|
+
if (isRight(maybeDecodedMeta)) {
|
|
48
48
|
const meta = maybeDecodedMeta.right
|
|
49
49
|
// if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
|
|
50
50
|
if (meta.data && meta.type === "hyperlink") {
|
|
51
51
|
const decoded = linkCodec.decode(meta.data)
|
|
52
|
-
if (decoded
|
|
52
|
+
if (isLeft(decoded)) return acc
|
|
53
53
|
|
|
54
54
|
return [...acc, { ...meta, data: decoded.right }]
|
|
55
55
|
} else if (meta.type !== "hyperlink") {
|
|
@@ -67,7 +67,7 @@ export const ValidatedMetas = (linkCodec: LinkCodec) =>
|
|
|
67
67
|
if (meta.type === "hyperlink" && meta.data) {
|
|
68
68
|
// since the Span data are typed as unknown we have to redecode for type safety and then encode to either new format or legacy.
|
|
69
69
|
const decoded = linkCodec.decode(meta.data)
|
|
70
|
-
if (decoded
|
|
70
|
+
if (isLeft(decoded)) return acc
|
|
71
71
|
|
|
72
72
|
return [...acc, { ...meta, data: linkCodec.encode(decoded.right) }]
|
|
73
73
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
+
import { isLeft } from "fp-ts/lib/Either"
|
|
2
3
|
import { pipe } from "fp-ts/lib/function"
|
|
3
4
|
import * as t from "io-ts"
|
|
4
5
|
|
|
@@ -44,7 +45,7 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
44
45
|
const result = RepeatableWidgetsLegacy(itemsCtx).decode(
|
|
45
46
|
parsedSlice.repeat,
|
|
46
47
|
)
|
|
47
|
-
if (!result || result
|
|
48
|
+
if (!result || isLeft(result)) return
|
|
48
49
|
return result.right
|
|
49
50
|
})() || []
|
|
50
51
|
|
|
@@ -57,8 +58,8 @@ export const CompositeSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
57
58
|
const result = NestableLegacy(fieldCtx).decode(value)
|
|
58
59
|
if (!result) return acc
|
|
59
60
|
|
|
60
|
-
if (result
|
|
61
|
-
|
|
61
|
+
if (isLeft(result)) return acc
|
|
62
|
+
return { ...acc, [key]: result.right }
|
|
62
63
|
}, {})
|
|
63
64
|
|
|
64
65
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
+
import { isLeft } from "fp-ts/lib/Either"
|
|
2
3
|
import { pipe } from "fp-ts/lib/function"
|
|
3
4
|
import * as t from "io-ts"
|
|
4
5
|
import { withFallback } from "io-ts-types"
|
|
@@ -43,7 +44,7 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
43
44
|
const result = RepeatableWidgetsLegacy(itemsCtx).decode(
|
|
44
45
|
parsedSlice.items,
|
|
45
46
|
)
|
|
46
|
-
if (!result || result
|
|
47
|
+
if (!result || isLeft(result)) return
|
|
47
48
|
return result.right
|
|
48
49
|
})() || []
|
|
49
50
|
|
|
@@ -59,8 +60,8 @@ export const SharedSliceLegacy = (ctx: LegacyContentCtx) => {
|
|
|
59
60
|
const result = NestableLegacy(FieldCtx).decode(value)
|
|
60
61
|
if (!result) return acc
|
|
61
62
|
|
|
62
|
-
if (result
|
|
63
|
-
|
|
63
|
+
if (isLeft(result)) return acc
|
|
64
|
+
return { ...acc, [key]: result.right }
|
|
64
65
|
}, {})
|
|
65
66
|
|
|
66
67
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { either } from "fp-ts"
|
|
2
|
+
import { isLeft } from "fp-ts/lib/Either"
|
|
2
3
|
import { pipe } from "fp-ts/lib/function"
|
|
3
4
|
import * as t from "io-ts"
|
|
4
5
|
|
|
@@ -54,8 +55,7 @@ export const SlicesItemLegacy = (ctx: LegacyContentCtx) => {
|
|
|
54
55
|
)
|
|
55
56
|
const itemCtx = getFieldCtx(parsedSlice.key, ctx)
|
|
56
57
|
const item = SliceLegacy(itemCtx).decode(parsedSlice.value)
|
|
57
|
-
if (!item || item.
|
|
58
|
-
return t.failure(sliceItem, context)
|
|
58
|
+
if (!item || isLeft(item)) return t.failure(sliceItem, context)
|
|
59
59
|
|
|
60
60
|
return t.success({
|
|
61
61
|
key: parsedSlice.key,
|
package/src/content/utils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isRight } from "fp-ts/lib/Either"
|
|
2
|
+
|
|
1
3
|
import { FieldContentType, FieldType } from "./fields"
|
|
2
4
|
|
|
3
5
|
type WithFieldType = WithContentType & { type: FieldType }
|
|
@@ -7,14 +9,11 @@ export function hasFieldContentType(obj: unknown): obj is WithFieldType {
|
|
|
7
9
|
obj.__TYPE__ === FieldContentType &&
|
|
8
10
|
(obj as WithFieldType)?.type !== undefined &&
|
|
9
11
|
typeof (obj as WithFieldType).type === "string" &&
|
|
10
|
-
FieldType.decode((obj as WithFieldType).type)
|
|
12
|
+
isRight(FieldType.decode((obj as WithFieldType).type))
|
|
11
13
|
)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
type WithContentType = { __TYPE__: string }
|
|
15
17
|
export function hasContentType(obj: unknown): obj is WithContentType {
|
|
16
|
-
return (
|
|
17
|
-
(obj as WithContentType)?.__TYPE__ !== undefined &&
|
|
18
|
-
typeof (obj as WithContentType).__TYPE__ === "string"
|
|
19
|
-
)
|
|
18
|
+
return typeof (obj as WithContentType).__TYPE__ === "string"
|
|
20
19
|
}
|
package/src/customtypes/index.ts
CHANGED
|
@@ -5,16 +5,16 @@ import { StringOrNull } from "../../validators"
|
|
|
5
5
|
import { NestableWidget } from "./nestable/NestableWidget"
|
|
6
6
|
|
|
7
7
|
export const GroupFieldType = "Group"
|
|
8
|
-
const GroupConfig = t.exact(
|
|
8
|
+
export const GroupConfig = t.exact(
|
|
9
9
|
t.partial({
|
|
10
10
|
label: StringOrNull,
|
|
11
11
|
repeat: t.boolean,
|
|
12
12
|
fields: t.record(WidgetKey, NestableWidget),
|
|
13
13
|
}),
|
|
14
14
|
)
|
|
15
|
-
type GroupConfig = t.TypeOf<typeof GroupConfig>
|
|
15
|
+
export type GroupConfig = t.TypeOf<typeof GroupConfig>
|
|
16
16
|
|
|
17
|
-
const Group = t.exact(
|
|
17
|
+
export const Group = t.exact(
|
|
18
18
|
t.intersection([
|
|
19
19
|
t.type({
|
|
20
20
|
type: t.literal(GroupFieldType),
|
|
@@ -27,6 +27,4 @@ const Group = t.exact(
|
|
|
27
27
|
}),
|
|
28
28
|
]),
|
|
29
29
|
)
|
|
30
|
-
type Group = t.TypeOf<typeof Group>
|
|
31
|
-
|
|
32
|
-
export default Group
|
|
30
|
+
export type Group = t.TypeOf<typeof Group>
|
|
@@ -4,16 +4,16 @@ import { StringOrNull } from "../../validators"
|
|
|
4
4
|
|
|
5
5
|
export const UIDFieldType = "UID"
|
|
6
6
|
|
|
7
|
-
const UIDConfig = t.exact(
|
|
7
|
+
export const UIDConfig = t.exact(
|
|
8
8
|
t.partial({
|
|
9
9
|
label: StringOrNull,
|
|
10
10
|
useAsTitle: t.boolean,
|
|
11
11
|
placeholder: t.string,
|
|
12
12
|
}),
|
|
13
13
|
)
|
|
14
|
-
type UIDConfig = t.TypeOf<typeof UIDConfig>
|
|
14
|
+
export type UIDConfig = t.TypeOf<typeof UIDConfig>
|
|
15
15
|
|
|
16
|
-
const UID = t.exact(
|
|
16
|
+
export const UID = t.exact(
|
|
17
17
|
t.intersection([
|
|
18
18
|
t.type({
|
|
19
19
|
type: t.literal(UIDFieldType),
|
|
@@ -24,6 +24,4 @@ const UID = t.exact(
|
|
|
24
24
|
}),
|
|
25
25
|
]),
|
|
26
26
|
)
|
|
27
|
-
type UID = t.TypeOf<typeof UID>
|
|
28
|
-
|
|
29
|
-
export default UID
|
|
27
|
+
export type UID = t.TypeOf<typeof UID>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts"
|
|
2
2
|
|
|
3
|
-
import Group,
|
|
3
|
+
import { Group, GroupFieldType } from "./Group"
|
|
4
4
|
import {
|
|
5
5
|
BooleanFieldType,
|
|
6
6
|
ColorFieldType,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
SlicesFieldType,
|
|
28
28
|
StaticSlices,
|
|
29
29
|
} from "./slices/Slices"
|
|
30
|
-
import UID,
|
|
30
|
+
import { UID, UIDFieldType } from "./UID"
|
|
31
31
|
|
|
32
32
|
export function widgetReader<T extends StaticSlices | DynamicSlices>(
|
|
33
33
|
codec: t.Type<T, unknown>,
|
|
@@ -41,7 +41,7 @@ export type StaticWidget = t.TypeOf<typeof StaticWidget>
|
|
|
41
41
|
export const DynamicWidget = widgetReader(DynamicSlices)
|
|
42
42
|
export type DynamicWidget = t.TypeOf<typeof DynamicWidget>
|
|
43
43
|
|
|
44
|
-
export const
|
|
44
|
+
export const FieldType = t.keyof({
|
|
45
45
|
[ColorFieldType]: null,
|
|
46
46
|
[BooleanFieldType]: null,
|
|
47
47
|
[NumberFieldType]: null,
|
|
@@ -63,7 +63,7 @@ export const FieldTypes = t.keyof({
|
|
|
63
63
|
[LegacySlicesFieldType]: null,
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
export type
|
|
66
|
+
export type FieldType = t.TypeOf<typeof FieldType>
|
|
67
67
|
|
|
68
68
|
export const Widgets = {
|
|
69
69
|
toStatic(
|
|
@@ -75,7 +75,7 @@ export const Widgets = {
|
|
|
75
75
|
case "Slices":
|
|
76
76
|
return Slices.toStatic(widget, sharedSlices)
|
|
77
77
|
default:
|
|
78
|
-
return widget
|
|
78
|
+
return widget
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
}
|