@prismicio/types-internal 2.0.0-beta.1 → 2.0.0

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.
@@ -48,16 +48,23 @@ const GroupItemLegacy = (ctx) => {
48
48
  };
49
49
  exports.GroupItemLegacy = GroupItemLegacy;
50
50
  const GroupLegacy = (ctx) => {
51
- const codec = t.array((0, exports.GroupItemLegacy)(ctx));
51
+ const codecDecode = t.array(t.union([t.null, (0, exports.GroupItemLegacy)(ctx)]));
52
+ const codecEncode = t.array((0, exports.GroupItemLegacy)(ctx));
52
53
  return new t.Type("GroupLegacy", exports.isGroupContent, (items) => {
53
- return (0, function_1.pipe)(codec.decode(items), fp_ts_1.either.map((parsedItems) => {
54
+ return (0, function_1.pipe)(codecDecode.decode(items), fp_ts_1.either.map((parsedItems) => {
54
55
  return {
55
- value: parsedItems,
56
+ value: parsedItems.map((i) => {
57
+ if (i === null) {
58
+ return { __TYPE__: exports.GroupItemContentType, value: [] };
59
+ }
60
+ else
61
+ return i;
62
+ }),
56
63
  __TYPE__: exports.GroupContentType,
57
64
  };
58
65
  }));
59
66
  }, (g) => {
60
- const res = codec.encode(g.value);
67
+ const res = codecEncode.encode(g.value);
61
68
  return {
62
69
  content: res.map((block) => block.content),
63
70
  types: res.reduce((acc, block) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -71,25 +71,29 @@ export const GroupItemLegacy = (ctx: LegacyContentCtx) => {
71
71
 
72
72
  type GroupLegacy = Array<GroupItemLegacy>
73
73
  export const GroupLegacy = (ctx: LegacyContentCtx) => {
74
- const codec = t.array(GroupItemLegacy(ctx))
74
+ const codecDecode = t.array(t.union([t.null, GroupItemLegacy(ctx)]))
75
+ const codecEncode = t.array(GroupItemLegacy(ctx))
75
76
 
76
77
  return new t.Type<GroupContent, WithTypes<GroupLegacy>, unknown>(
77
78
  "GroupLegacy",
78
79
  isGroupContent,
79
80
  (items) => {
80
81
  return pipe(
81
- codec.decode(items),
82
+ codecDecode.decode(items),
82
83
  either.map((parsedItems) => {
83
84
  return {
84
- value: parsedItems,
85
+ value: parsedItems.map((i) => {
86
+ if (i === null) {
87
+ return { __TYPE__: GroupItemContentType, value: [] }
88
+ } else return i
89
+ }),
85
90
  __TYPE__: GroupContentType,
86
91
  }
87
92
  }),
88
93
  )
89
94
  },
90
95
  (g: GroupContent) => {
91
- const res = codec.encode(g.value)
92
-
96
+ const res = codecEncode.encode(g.value)
93
97
  return {
94
98
  content: res.map((block) => block.content),
95
99
  types: res.reduce<Record<string, FieldOrSliceType>>(
@@ -1,29 +0,0 @@
1
- import * as t from "io-ts";
2
- export declare const ContentRelationshipResolver: t.ReadonlyArrayC<t.Type<{
3
- customTypeId: string;
4
- } & {
5
- fields?: readonly ({
6
- fieldId: string;
7
- } & {
8
- customTypes?: readonly {
9
- customTypeId: string;
10
- fields: readonly {
11
- fieldId: string;
12
- }[];
13
- }[];
14
- })[];
15
- }, {
16
- customTypeId: string;
17
- } & {
18
- fields?: readonly ({
19
- fieldId: string;
20
- } & {
21
- customTypes?: readonly {
22
- customTypeId: string;
23
- fields: readonly {
24
- fieldId: string;
25
- }[];
26
- }[];
27
- })[];
28
- }, unknown>>;
29
- export declare type ContentRelationshipResolver = t.TypeOf<typeof ContentRelationshipResolver>;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentRelationshipResolver = 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
- // This allows to parse an element that is either a string or a type T and converts the string to T if necessary so we get a consistent output.
9
- const StringOrT = (codec) => {
10
- return (asObject) => new t.Type("StringOrT", (u) => u instanceof Object, (u) => {
11
- return (0, function_1.pipe)(t.union([t.string, codec]).decode(u), fp_ts_1.either.map((decoded) => {
12
- if (typeof decoded === "string")
13
- return asObject(decoded);
14
- return decoded;
15
- }));
16
- }, (f) => f);
17
- };
18
- /*
19
- * The models have slight differences if they are nested or not to avoid recursion and so an infinite level of nesting which would be incompatible with the Content API mechanism to resolve nested content.
20
- */
21
- const FieldResolver = StringOrT(t.type({
22
- fieldId: t.string,
23
- }))((id) => ({ fieldId: id }));
24
- const NestedCustomTypeResolver = t.type({
25
- customTypeId: t.string,
26
- fields: t.readonlyArray(FieldResolver),
27
- });
28
- const RootFieldResolver = StringOrT(t.intersection([
29
- t.type({
30
- fieldId: t.string,
31
- }),
32
- t.partial({
33
- customTypes: t.readonlyArray(NestedCustomTypeResolver),
34
- }),
35
- ]))((id) => ({ fieldId: id }));
36
- const CustomTypeResolver = StringOrT(t.intersection([
37
- t.type({
38
- customTypeId: t.string,
39
- }),
40
- t.partial({
41
- fields: t.readonlyArray(RootFieldResolver),
42
- }),
43
- ]))((id) => ({ customTypeId: id }));
44
- exports.ContentRelationshipResolver = t.readonlyArray(CustomTypeResolver);
@@ -1,82 +0,0 @@
1
- import * as t from "io-ts";
2
- export declare const LinkFieldType = "Link";
3
- export declare const LinkConfig: t.ExactC<t.PartialC<{
4
- label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
5
- useAsTitle: t.BooleanC;
6
- placeholder: t.StringC;
7
- select: t.UnionC<[t.LiteralC<"media">, t.LiteralC<"document">, t.LiteralC<"web">, t.NullC]>;
8
- customtypes: t.ReadonlyArrayC<t.Type<{
9
- customTypeId: string;
10
- } & {
11
- fields?: readonly ({
12
- fieldId: string;
13
- } & {
14
- customTypes?: readonly {
15
- customTypeId: string;
16
- fields: readonly {
17
- fieldId: string;
18
- }[];
19
- }[];
20
- })[];
21
- }, {
22
- customTypeId: string;
23
- } & {
24
- fields?: readonly ({
25
- fieldId: string;
26
- } & {
27
- customTypes?: readonly {
28
- customTypeId: string;
29
- fields: readonly {
30
- fieldId: string;
31
- }[];
32
- }[];
33
- })[];
34
- }, unknown>>;
35
- masks: t.Type<readonly string[], object, unknown>;
36
- tags: t.Type<readonly string[], object, unknown>;
37
- allowTargetBlank: t.BooleanC;
38
- }>>;
39
- export declare type LinkConfig = t.TypeOf<typeof LinkConfig>;
40
- export declare const Link: t.ExactC<t.IntersectionC<[t.TypeC<{
41
- type: t.LiteralC<"Link">;
42
- }>, t.PartialC<{
43
- fieldset: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
44
- config: t.ExactC<t.PartialC<{
45
- label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
46
- useAsTitle: t.BooleanC;
47
- placeholder: t.StringC;
48
- select: t.UnionC<[t.LiteralC<"media">, t.LiteralC<"document">, t.LiteralC<"web">, t.NullC]>;
49
- customtypes: t.ReadonlyArrayC<t.Type<{
50
- customTypeId: string;
51
- } & {
52
- fields?: readonly ({
53
- fieldId: string;
54
- } & {
55
- customTypes?: readonly {
56
- customTypeId: string;
57
- fields: readonly {
58
- fieldId: string;
59
- }[];
60
- }[];
61
- })[];
62
- }, {
63
- customTypeId: string;
64
- } & {
65
- fields?: readonly ({
66
- fieldId: string;
67
- } & {
68
- customTypes?: readonly {
69
- customTypeId: string;
70
- fields: readonly {
71
- fieldId: string;
72
- }[];
73
- }[];
74
- })[];
75
- }, unknown>>;
76
- masks: t.Type<readonly string[], object, unknown>;
77
- tags: t.Type<readonly string[], object, unknown>;
78
- allowTargetBlank: t.BooleanC;
79
- }>>;
80
- }>]>>;
81
- export declare type Link = t.TypeOf<typeof Link>;
82
- export * from "./ContentRelationshipResolver";
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Link = exports.LinkConfig = exports.LinkFieldType = void 0;
4
- const tslib_1 = require("tslib");
5
- const Either_1 = require("fp-ts/lib/Either");
6
- const t = (0, tslib_1.__importStar)(require("io-ts"));
7
- const withFallback_1 = require("io-ts-types/lib/withFallback");
8
- const validators_1 = require("../../../../validators");
9
- const ContentRelationshipResolver_1 = require("./ContentRelationshipResolver");
10
- const arrayString = (entries) => {
11
- if (entries instanceof Array) {
12
- const isValidEntries = entries.reduce((acc, l) => acc && typeof l === "string", true);
13
- if (isValidEntries)
14
- return t.success(entries);
15
- }
16
- return;
17
- };
18
- const plainString = (entries) => {
19
- if (typeof entries === "string") {
20
- return t.success([entries]);
21
- }
22
- return;
23
- };
24
- const MasksArrayString = new t.Type("MasksArrayString", (u) => {
25
- return u instanceof Array;
26
- }, (u, context) => {
27
- return Either_1.either.chain(t.union([t.array(t.string), t.string]).validate(u, context), (masks) => {
28
- return arrayString(masks) || plainString(masks) || t.failure(u, context);
29
- });
30
- }, (res) => res);
31
- exports.LinkFieldType = "Link";
32
- exports.LinkConfig = t.exact(t.partial({
33
- label: validators_1.StringOrNull,
34
- useAsTitle: t.boolean,
35
- placeholder: t.string,
36
- select: (0, withFallback_1.withFallback)(t.union([
37
- t.literal("media"),
38
- t.literal("document"),
39
- t.literal("web"),
40
- t.null,
41
- ]), null),
42
- customtypes: ContentRelationshipResolver_1.ContentRelationshipResolver,
43
- masks: MasksArrayString,
44
- tags: MasksArrayString,
45
- allowTargetBlank: t.boolean,
46
- }));
47
- exports.Link = t.exact(t.intersection([
48
- t.type({
49
- type: t.literal(exports.LinkFieldType),
50
- }),
51
- t.partial({
52
- fieldset: validators_1.StringOrNull,
53
- config: exports.LinkConfig,
54
- }),
55
- ]));
56
- (0, tslib_1.__exportStar)(require("./ContentRelationshipResolver"), exports);