@platecms/delta-client 0.6.0 → 0.8.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.
- package/README.md +309 -96
- package/package.json +4 -6
- package/src/__generated__/fragment-masking.ts +87 -0
- package/src/__generated__/gql.ts +52 -0
- package/src/__generated__/graphql.ts +3141 -0
- package/src/__generated__/{index.d.ts → index.ts} +1 -1
- package/src/api/index.ts +1 -0
- package/src/apollo/index.ts +70 -0
- package/src/graphql/tags/tag.query.gql +5 -0
- package/src/graphql/tags/tags.fragments.gql +17 -0
- package/src/index.ts +1 -0
- package/src/schema/index.spec.ts +211 -0
- package/src/schema/index.ts +18 -0
- package/src/schema/lib/schemas/array.spec.ts +111 -0
- package/src/schema/lib/schemas/array.ts +38 -0
- package/src/schema/lib/schemas/asset.spec.ts +101 -0
- package/src/schema/lib/schemas/asset.ts +12 -0
- package/src/schema/lib/schemas/baseSchema.ts +42 -0
- package/src/schema/lib/schemas/boolean.spec.ts +65 -0
- package/src/schema/lib/schemas/boolean.ts +12 -0
- package/src/schema/lib/schemas/buildingBlock.spec.ts +56 -0
- package/src/schema/lib/schemas/buildingBlock.ts +33 -0
- package/src/schema/lib/schemas/contentItem.spec.ts +61 -0
- package/src/schema/lib/schemas/contentItem.ts +31 -0
- package/src/schema/lib/schemas/contentType.spec.ts +113 -0
- package/src/schema/lib/schemas/contentType.ts +12 -0
- package/src/schema/lib/schemas/date.spec.ts +82 -0
- package/src/schema/lib/schemas/date.ts +17 -0
- package/src/schema/lib/schemas/gridPlacement.spec.ts +77 -0
- package/src/schema/lib/schemas/gridPlacement.ts +12 -0
- package/src/schema/lib/schemas/index.ts +66 -0
- package/src/schema/lib/schemas/number.spec.ts +65 -0
- package/src/schema/lib/schemas/number.ts +12 -0
- package/src/schema/lib/schemas/pathPart.spec.ts +120 -0
- package/src/schema/lib/schemas/pathPart.ts +12 -0
- package/src/schema/lib/schemas/smartText.spec.ts +105 -0
- package/src/schema/lib/schemas/smartText.ts +12 -0
- package/src/schema/lib/schemas/string.spec.ts +65 -0
- package/src/schema/lib/schemas/string.ts +12 -0
- package/src/schema/lib/schemas/tag.spec.ts +89 -0
- package/src/schema/lib/schemas/tag.ts +12 -0
- package/src/schema/lib/utils/isContentValue.spec.ts +111 -0
- package/src/schema/lib/utils/isContentValue.ts +17 -0
- package/src/schema/lib/utils/isPrimitiveValue.spec.ts +38 -0
- package/src/schema/lib/utils/isPrimitiveValue.ts +7 -0
- package/src/slate/index.ts +84 -0
- package/src/utils/{index.d.ts → index.ts} +3 -2
- package/src/utils/lib/connectors/BaseConnector.ts +26 -0
- package/src/utils/lib/connectors/WindowConnector.ts +70 -0
- package/src/utils/lib/events/ConnectorEvents.ts +89 -0
- package/src/utils/lib/events/EventEmitter.ts +19 -0
- package/src/__generated__/fragment-masking.d.ts +0 -19
- package/src/__generated__/fragment-masking.js +0 -22
- package/src/__generated__/fragment-masking.js.map +0 -1
- package/src/__generated__/gql.d.ts +0 -12
- package/src/__generated__/gql.js +0 -13
- package/src/__generated__/gql.js.map +0 -1
- package/src/__generated__/graphql.d.ts +0 -2157
- package/src/__generated__/graphql.js +0 -70
- package/src/__generated__/graphql.js.map +0 -1
- package/src/__generated__/index.js +0 -6
- package/src/__generated__/index.js.map +0 -1
- package/src/api/index.d.ts +0 -2
- package/src/api/index.js +0 -4
- package/src/api/index.js.map +0 -1
- package/src/apollo/index.d.ts +0 -7
- package/src/apollo/index.js +0 -40
- package/src/apollo/index.js.map +0 -1
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -3
- package/src/index.js.map +0 -1
- package/src/schema/index.d.ts +0 -2
- package/src/schema/index.js +0 -8
- package/src/schema/index.js.map +0 -1
- package/src/schema/lib/nodes.d.ts +0 -46
- package/src/schema/lib/nodes.js +0 -14
- package/src/schema/lib/nodes.js.map +0 -1
- package/src/schema/lib/parser.d.ts +0 -12
- package/src/schema/lib/parser.js +0 -49
- package/src/schema/lib/parser.js.map +0 -1
- package/src/schema/lib/schema.d.ts +0 -17
- package/src/schema/lib/schema.js +0 -65
- package/src/schema/lib/schema.js.map +0 -1
- package/src/schema/lib/utils.d.ts +0 -12
- package/src/schema/lib/utils.js +0 -66
- package/src/schema/lib/utils.js.map +0 -1
- package/src/slate/index.d.ts +0 -65
- package/src/slate/index.js +0 -3
- package/src/slate/index.js.map +0 -1
- package/src/utils/index.js +0 -6
- package/src/utils/index.js.map +0 -1
- package/src/utils/lib/connectors/BaseConnector.d.ts +0 -16
- package/src/utils/lib/connectors/BaseConnector.js +0 -17
- package/src/utils/lib/connectors/BaseConnector.js.map +0 -1
- package/src/utils/lib/connectors/WindowConnector.d.ts +0 -10
- package/src/utils/lib/connectors/WindowConnector.js +0 -53
- package/src/utils/lib/connectors/WindowConnector.js.map +0 -1
- package/src/utils/lib/events/ConnectorEvents.d.ts +0 -63
- package/src/utils/lib/events/ConnectorEvents.js +0 -24
- package/src/utils/lib/events/ConnectorEvents.js.map +0 -1
- package/src/utils/lib/events/EventEmitter.d.ts +0 -7
- package/src/utils/lib/events/EventEmitter.js +0 -21
- package/src/utils/lib/events/EventEmitter.js.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { NumberSchema } from "./number";
|
|
3
|
+
|
|
4
|
+
describe("Number schema", () => {
|
|
5
|
+
it("should parse to a number when parsing a number content value", () => {
|
|
6
|
+
const schema = new NumberSchema();
|
|
7
|
+
|
|
8
|
+
const result = schema.parse([
|
|
9
|
+
{
|
|
10
|
+
primitiveValue: 42,
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual(42);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should return null when parsing an a non number content value", () => {
|
|
18
|
+
const schema = new NumberSchema();
|
|
19
|
+
|
|
20
|
+
const result = schema.parse([
|
|
21
|
+
{
|
|
22
|
+
primitiveValue: "hello",
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
expect(result).toEqual(null);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("when placeholders are enabled", () => {
|
|
30
|
+
it("should return the placeholder when parsing an empty array", () => {
|
|
31
|
+
const schema = new NumberSchema().placeholder(1);
|
|
32
|
+
|
|
33
|
+
const result = schema.parse([], {
|
|
34
|
+
placeholders: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual(1);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should return the placeholder when parsing an non number content value", () => {
|
|
41
|
+
const schema = new NumberSchema().placeholder(1);
|
|
42
|
+
|
|
43
|
+
const result = schema.parse(
|
|
44
|
+
[
|
|
45
|
+
{
|
|
46
|
+
primitiveValue: "hello",
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
{
|
|
50
|
+
placeholders: true,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("when nullable is disabled", () => {
|
|
59
|
+
it("should throw an error when parsing an non number content value", () => {
|
|
60
|
+
const schema = new NumberSchema().nullable(false);
|
|
61
|
+
|
|
62
|
+
expect(() => schema.parse([{ primitiveValue: "hello" }])).toThrow("Data could not be found and is not nullable");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseSchema } from "./baseSchema";
|
|
2
|
+
import { isPrimitiveValue } from "../utils/isPrimitiveValue";
|
|
3
|
+
|
|
4
|
+
export class NumberSchema extends BaseSchema<number | null, unknown> {
|
|
5
|
+
protected override findValue(data: unknown): number | null {
|
|
6
|
+
if (isPrimitiveValue(data) && typeof data.primitiveValue === "number") {
|
|
7
|
+
return data.primitiveValue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { NumberSchema } from "./number";
|
|
3
|
+
import { PathPartSchema } from "./pathPart";
|
|
4
|
+
|
|
5
|
+
describe("PathPart schema", () => {
|
|
6
|
+
it("should parse to a path part when parsing a path part content value", () => {
|
|
7
|
+
const schema = new PathPartSchema();
|
|
8
|
+
|
|
9
|
+
const result = schema.parse([
|
|
10
|
+
{
|
|
11
|
+
pathPart: {
|
|
12
|
+
prn: "123",
|
|
13
|
+
name: "title",
|
|
14
|
+
path: "title",
|
|
15
|
+
contentFields: [
|
|
16
|
+
{
|
|
17
|
+
name: "title",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
expect(result).toEqual({
|
|
25
|
+
prn: "123",
|
|
26
|
+
name: "title",
|
|
27
|
+
path: "title",
|
|
28
|
+
contentFields: [
|
|
29
|
+
{
|
|
30
|
+
name: "title",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should return null when parsing an a non path part content value", () => {
|
|
37
|
+
const schema = new PathPartSchema();
|
|
38
|
+
|
|
39
|
+
const result = schema.parse([
|
|
40
|
+
{
|
|
41
|
+
primitiveValue: "hello",
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
expect(result).toEqual(null);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("when placeholders are enabled", () => {
|
|
49
|
+
it("should return the placeholder when parsing an empty array", () => {
|
|
50
|
+
const schema = new PathPartSchema().placeholder({
|
|
51
|
+
prn: "123",
|
|
52
|
+
name: "title",
|
|
53
|
+
path: "title",
|
|
54
|
+
contentFields: [
|
|
55
|
+
{
|
|
56
|
+
name: "title",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = schema.parse([], {
|
|
62
|
+
placeholders: true,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(result).toEqual({
|
|
66
|
+
prn: "123",
|
|
67
|
+
name: "title",
|
|
68
|
+
path: "title",
|
|
69
|
+
contentFields: [
|
|
70
|
+
{
|
|
71
|
+
name: "title",
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should return the placeholder when parsing an non path part content value", () => {
|
|
78
|
+
const schema = new PathPartSchema().placeholder({
|
|
79
|
+
prn: "123",
|
|
80
|
+
name: "title",
|
|
81
|
+
path: "title",
|
|
82
|
+
contentFields: [
|
|
83
|
+
{
|
|
84
|
+
name: "title",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const result = schema.parse(
|
|
90
|
+
[
|
|
91
|
+
{
|
|
92
|
+
primitiveValue: true,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
{
|
|
96
|
+
placeholders: true,
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(result).toEqual({
|
|
101
|
+
prn: "123",
|
|
102
|
+
name: "title",
|
|
103
|
+
path: "title",
|
|
104
|
+
contentFields: [
|
|
105
|
+
{
|
|
106
|
+
name: "title",
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("when nullable is disabled", () => {
|
|
114
|
+
it("should throw an error when parsing an non path part content value", () => {
|
|
115
|
+
const schema = new NumberSchema().nullable(false);
|
|
116
|
+
|
|
117
|
+
expect(() => schema.parse([{ primitiveValue: "hello" }])).toThrow("Data could not be found and is not nullable");
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PathPart } from "../../../__generated__/graphql";
|
|
2
|
+
import { BaseSchema } from "./baseSchema";
|
|
3
|
+
|
|
4
|
+
export class PathPartSchema extends BaseSchema<PathPart | null, unknown> {
|
|
5
|
+
protected override findValue(data: unknown): PathPart | null {
|
|
6
|
+
if (typeof data === "object" && data !== null && "pathPart" in data) {
|
|
7
|
+
return (data as { pathPart: PathPart }).pathPart;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { SmartTextSchema } from "./smartText";
|
|
3
|
+
import { c } from "@platecms/delta-castscript";
|
|
4
|
+
|
|
5
|
+
describe("SmartText schema", () => {
|
|
6
|
+
it("should parse to a smart text when parsing a smart text content value", () => {
|
|
7
|
+
const schema = new SmartTextSchema();
|
|
8
|
+
|
|
9
|
+
const result = schema.parse([
|
|
10
|
+
{
|
|
11
|
+
interpolatedSmartText: c("root", [c("paragraph", "hello")]),
|
|
12
|
+
},
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
expect(result).toEqual({
|
|
16
|
+
type: "root",
|
|
17
|
+
children: [
|
|
18
|
+
{
|
|
19
|
+
type: "paragraph",
|
|
20
|
+
children: [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
value: "hello",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should return null when parsing an a non smart text content value", () => {
|
|
32
|
+
const schema = new SmartTextSchema();
|
|
33
|
+
|
|
34
|
+
const result = schema.parse([
|
|
35
|
+
{
|
|
36
|
+
primitiveValue: "hello",
|
|
37
|
+
},
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
expect(result).toEqual(null);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe("when placeholders are enabled", () => {
|
|
44
|
+
it("should return the placeholder when parsing an empty array", () => {
|
|
45
|
+
const schema = new SmartTextSchema().placeholder(c("root", [c("paragraph", "placeholder")]));
|
|
46
|
+
|
|
47
|
+
const result = schema.parse([], {
|
|
48
|
+
placeholders: true,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(result).toEqual({
|
|
52
|
+
type: "root",
|
|
53
|
+
children: [
|
|
54
|
+
{
|
|
55
|
+
type: "paragraph",
|
|
56
|
+
children: [
|
|
57
|
+
{
|
|
58
|
+
type: "text",
|
|
59
|
+
value: "placeholder",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should return the placeholder when parsing an non smart text content value", () => {
|
|
68
|
+
const schema = new SmartTextSchema().placeholder(c("root", [c("paragraph", "placeholder")]));
|
|
69
|
+
|
|
70
|
+
const result = schema.parse(
|
|
71
|
+
[
|
|
72
|
+
{
|
|
73
|
+
primitiveValue: true,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
{
|
|
77
|
+
placeholders: true,
|
|
78
|
+
},
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(result).toEqual({
|
|
82
|
+
type: "root",
|
|
83
|
+
children: [
|
|
84
|
+
{
|
|
85
|
+
type: "paragraph",
|
|
86
|
+
children: [
|
|
87
|
+
{
|
|
88
|
+
type: "text",
|
|
89
|
+
value: "placeholder",
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("when nullable is disabled", () => {
|
|
99
|
+
it("should throw an error when parsing an non smart text content value", () => {
|
|
100
|
+
const schema = new SmartTextSchema().nullable(false);
|
|
101
|
+
|
|
102
|
+
expect(() => schema.parse([{ primitiveValue: 42 }])).toThrow("Data could not be found and is not nullable");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Root as SmartText } from "@platecms/delta-cast";
|
|
2
|
+
import { BaseSchema } from "./baseSchema";
|
|
3
|
+
|
|
4
|
+
export class SmartTextSchema extends BaseSchema<SmartText | null, unknown> {
|
|
5
|
+
protected override findValue(data: unknown): SmartText | null {
|
|
6
|
+
if (typeof data === "object" && data !== null && "interpolatedSmartText" in data) {
|
|
7
|
+
return (data as { interpolatedSmartText: SmartText }).interpolatedSmartText;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { StringSchema } from "./string";
|
|
3
|
+
|
|
4
|
+
describe("String schema", () => {
|
|
5
|
+
it("should parse to a string when parsing a string content value", () => {
|
|
6
|
+
const schema = new StringSchema();
|
|
7
|
+
|
|
8
|
+
const result = schema.parse([
|
|
9
|
+
{
|
|
10
|
+
primitiveValue: "hello",
|
|
11
|
+
},
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual("hello");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("should return null when parsing an a non string content value", () => {
|
|
18
|
+
const schema = new StringSchema();
|
|
19
|
+
|
|
20
|
+
const result = schema.parse([
|
|
21
|
+
{
|
|
22
|
+
primitiveValue: 42,
|
|
23
|
+
},
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
expect(result).toEqual(null);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("when placeholders are enabled", () => {
|
|
30
|
+
it("should return the placeholder when parsing an empty array", () => {
|
|
31
|
+
const schema = new StringSchema().placeholder("hello");
|
|
32
|
+
|
|
33
|
+
const result = schema.parse([], {
|
|
34
|
+
placeholders: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result).toEqual("hello");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should return the placeholder when parsing an non string content value", () => {
|
|
41
|
+
const schema = new StringSchema().placeholder("hello");
|
|
42
|
+
|
|
43
|
+
const result = schema.parse(
|
|
44
|
+
[
|
|
45
|
+
{
|
|
46
|
+
primitiveValue: true,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
{
|
|
50
|
+
placeholders: true,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(result).toEqual("hello");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("when nullable is disabled", () => {
|
|
59
|
+
it("should throw an error when parsing an non string content value", () => {
|
|
60
|
+
const schema = new StringSchema().nullable(false);
|
|
61
|
+
|
|
62
|
+
expect(() => schema.parse([{ primitiveValue: 42 }])).toThrow("Data could not be found and is not nullable");
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseSchema } from "./baseSchema";
|
|
2
|
+
import { isPrimitiveValue } from "../utils/isPrimitiveValue";
|
|
3
|
+
|
|
4
|
+
export class StringSchema extends BaseSchema<string | null, unknown> {
|
|
5
|
+
protected override findValue(data: unknown): string | null {
|
|
6
|
+
if (isPrimitiveValue(data) && typeof data.primitiveValue === "string") {
|
|
7
|
+
return data.primitiveValue;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { TagSchema } from "./tag";
|
|
3
|
+
|
|
4
|
+
describe("Tag schema", () => {
|
|
5
|
+
it("should parse to a tag when parsing a tag content value", () => {
|
|
6
|
+
const schema = new TagSchema();
|
|
7
|
+
|
|
8
|
+
const result = schema.parse([
|
|
9
|
+
{
|
|
10
|
+
linkedTag: {
|
|
11
|
+
prn: "123",
|
|
12
|
+
name: "title",
|
|
13
|
+
path: "title",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
expect(result).toEqual({
|
|
19
|
+
prn: "123",
|
|
20
|
+
name: "title",
|
|
21
|
+
path: "title",
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should return null when parsing an a non tag content value", () => {
|
|
26
|
+
const schema = new TagSchema();
|
|
27
|
+
|
|
28
|
+
const result = schema.parse([
|
|
29
|
+
{
|
|
30
|
+
primitiveValue: "hello",
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual(null);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("when placeholders are enabled", () => {
|
|
38
|
+
it("should return the placeholder when parsing an empty array", () => {
|
|
39
|
+
const schema = new TagSchema().placeholder({
|
|
40
|
+
prn: "123",
|
|
41
|
+
name: "title",
|
|
42
|
+
path: "title",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const result = schema.parse([], {
|
|
46
|
+
placeholders: true,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(result).toEqual({
|
|
50
|
+
prn: "123",
|
|
51
|
+
name: "title",
|
|
52
|
+
path: "title",
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should return the placeholder when parsing an non tag content value", () => {
|
|
57
|
+
const schema = new TagSchema().placeholder({
|
|
58
|
+
prn: "123",
|
|
59
|
+
name: "title",
|
|
60
|
+
path: "title",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const result = schema.parse(
|
|
64
|
+
[
|
|
65
|
+
{
|
|
66
|
+
primitiveValue: true,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
{
|
|
70
|
+
placeholders: true,
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(result).toEqual({
|
|
75
|
+
prn: "123",
|
|
76
|
+
name: "title",
|
|
77
|
+
path: "title",
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("when nullable is disabled", () => {
|
|
83
|
+
it("should throw an error when parsing an non tag content value", () => {
|
|
84
|
+
const schema = new TagSchema().nullable(false);
|
|
85
|
+
|
|
86
|
+
expect(() => schema.parse([{ primitiveValue: 42 }])).toThrow("Data could not be found and is not nullable");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Tag } from "../../../__generated__/graphql";
|
|
2
|
+
import { BaseSchema } from "./baseSchema";
|
|
3
|
+
|
|
4
|
+
export class TagSchema extends BaseSchema<Tag | null, unknown> {
|
|
5
|
+
protected override findValue(data: unknown): Tag | null {
|
|
6
|
+
if (typeof data === "object" && data !== null && "linkedTag" in data) {
|
|
7
|
+
return (data as { linkedTag: Tag }).linkedTag;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { isContentValue } from "./isContentValue";
|
|
2
|
+
|
|
3
|
+
describe("isContentValue", () => {
|
|
4
|
+
it("should return false if the data is not a content value and has values", () => {
|
|
5
|
+
const data = {
|
|
6
|
+
__typename: "ContentValue",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const result = isContentValue(data);
|
|
10
|
+
|
|
11
|
+
expect(result).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should return true if the data is a content value and has a primitive value", () => {
|
|
15
|
+
const data = {
|
|
16
|
+
__typename: "ContentValue",
|
|
17
|
+
primitiveValue: "Hello",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const result = isContentValue(data);
|
|
21
|
+
|
|
22
|
+
expect(result).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should return true if the data is a content value and has a related asset", () => {
|
|
26
|
+
const data = {
|
|
27
|
+
__typename: "ContentValue",
|
|
28
|
+
relatedAsset: {
|
|
29
|
+
__typename: "Asset",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const result = isContentValue(data);
|
|
34
|
+
|
|
35
|
+
expect(result).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should return true if the data is a content value and has a linked content type", () => {
|
|
39
|
+
const data = {
|
|
40
|
+
__typename: "ContentValue",
|
|
41
|
+
linkedContentType: {
|
|
42
|
+
__typename: "ContentType",
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should return true if the data is a content value and has a linked grid placement", () => {
|
|
48
|
+
const data = {
|
|
49
|
+
__typename: "ContentValue",
|
|
50
|
+
linkedGridPlacement: {
|
|
51
|
+
__typename: "GridPlacement",
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const result = isContentValue(data);
|
|
56
|
+
|
|
57
|
+
expect(result).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should return true if the data is a content value and has a linked path part", () => {
|
|
61
|
+
const data = {
|
|
62
|
+
__typename: "ContentValue",
|
|
63
|
+
linkedPathPart: {
|
|
64
|
+
__typename: "PathPart",
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const result = isContentValue(data);
|
|
69
|
+
|
|
70
|
+
expect(result).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("should return true if the data is a content value and has a linked tag", () => {
|
|
74
|
+
const data = {
|
|
75
|
+
__typename: "ContentValue",
|
|
76
|
+
linkedTag: {
|
|
77
|
+
__typename: "Tag",
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const result = isContentValue(data);
|
|
82
|
+
|
|
83
|
+
expect(result).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should return true if the data is a content value and has a related content item", () => {
|
|
87
|
+
const data = {
|
|
88
|
+
__typename: "ContentValue",
|
|
89
|
+
relatedContentItem: {
|
|
90
|
+
__typename: "ContentItem",
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const result = isContentValue(data);
|
|
95
|
+
|
|
96
|
+
expect(result).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("should return true if the data is a content value and has a smart text", () => {
|
|
100
|
+
const data = {
|
|
101
|
+
__typename: "ContentValue",
|
|
102
|
+
smartText: {
|
|
103
|
+
__typename: "SmartText",
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const result = isContentValue(data);
|
|
108
|
+
|
|
109
|
+
expect(result).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ContentValue } from "../../../__generated__/graphql";
|
|
2
|
+
|
|
3
|
+
export function isContentValue(data: unknown): data is ContentValue {
|
|
4
|
+
return (
|
|
5
|
+
data !== null &&
|
|
6
|
+
typeof data === "object" &&
|
|
7
|
+
("primitiveValue" in data ||
|
|
8
|
+
"relatedAsset" in data ||
|
|
9
|
+
"linkedContentType" in data ||
|
|
10
|
+
"linkedGridPlacement" in data ||
|
|
11
|
+
"linkedPathPart" in data ||
|
|
12
|
+
"linkedTag" in data ||
|
|
13
|
+
"relatedContentItem" in data ||
|
|
14
|
+
"smartText" in data ||
|
|
15
|
+
"interpolatedSmartText" in data)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { isPrimitiveValue } from "./isPrimitiveValue";
|
|
3
|
+
|
|
4
|
+
describe("isPrimitiveValue", () => {
|
|
5
|
+
it("should return false if the data is not a content value", () => {
|
|
6
|
+
const data = {
|
|
7
|
+
__typename: "ContentValue",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const result = isPrimitiveValue(data);
|
|
11
|
+
|
|
12
|
+
expect(result).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should return false if the data is a content value and has no primitive value", () => {
|
|
16
|
+
const data = {
|
|
17
|
+
__typename: "ContentValue",
|
|
18
|
+
relatedAsset: {
|
|
19
|
+
__typename: "Asset",
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const result = isPrimitiveValue(data);
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should return true if the data is a content value and has a primitive value", () => {
|
|
29
|
+
const data = {
|
|
30
|
+
__typename: "ContentValue",
|
|
31
|
+
primitiveValue: "Hello",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const result = isPrimitiveValue(data);
|
|
35
|
+
|
|
36
|
+
expect(result).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Primitive } from "@platecms/delta-types";
|
|
2
|
+
import { ContentValue } from "../../../__generated__/graphql";
|
|
3
|
+
import { isContentValue } from "./isContentValue";
|
|
4
|
+
|
|
5
|
+
export function isPrimitiveValue(data: unknown): data is ContentValue & { primitiveValue: Primitive } {
|
|
6
|
+
return isContentValue(data) && data.primitiveValue !== null && data.primitiveValue !== undefined;
|
|
7
|
+
}
|