@platecms/delta-client 0.9.0 → 0.9.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platecms/delta-client",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Utilities and functions to interact with the Delta CMS.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"src/**/*"
|
|
19
19
|
],
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@platecms/delta-cast": "0.9.
|
|
21
|
+
"@platecms/delta-cast": "0.9.1",
|
|
22
22
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
23
23
|
"graphql": "16.11.0",
|
|
24
24
|
"lodash": "4.17.21",
|
|
@@ -79,6 +79,21 @@ describe("Array schema", () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
describe("when using multiple schemas", () => {
|
|
82
|
+
it("should parse an array of strings and numbers", () => {
|
|
83
|
+
const testSchema = schemaBuilder.array([schemaBuilder.string(), schemaBuilder.number()]);
|
|
84
|
+
|
|
85
|
+
const result = testSchema.parse([
|
|
86
|
+
{
|
|
87
|
+
primitiveValue: "hello",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
primitiveValue: 42,
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
expect(result).toEqual(["hello", 42]);
|
|
95
|
+
});
|
|
96
|
+
|
|
82
97
|
it("should parse an array of content values", () => {
|
|
83
98
|
const testSchema = schemaBuilder.array(
|
|
84
99
|
schemaBuilder.contentItem({
|
|
@@ -2,7 +2,11 @@ import { compact, first } from "lodash";
|
|
|
2
2
|
import { Schema, SchemaConfig } from ".";
|
|
3
3
|
|
|
4
4
|
export class ArraySchema<T extends Schema | Schema[]>
|
|
5
|
-
implements
|
|
5
|
+
implements
|
|
6
|
+
Schema<
|
|
7
|
+
T extends Schema[] ? ReturnType<T[number]["parse"]>[] : T extends Schema ? ReturnType<T["parse"]>[] : never,
|
|
8
|
+
unknown
|
|
9
|
+
>
|
|
6
10
|
{
|
|
7
11
|
private _minLength: number = 0;
|
|
8
12
|
|
|
@@ -16,7 +20,7 @@ export class ArraySchema<T extends Schema | Schema[]>
|
|
|
16
20
|
public parse(
|
|
17
21
|
data: unknown,
|
|
18
22
|
config?: SchemaConfig,
|
|
19
|
-
): T extends Schema[] ? T[number]["parse"][] : T extends Schema ? T["parse"][] : never {
|
|
23
|
+
): T extends Schema[] ? ReturnType<T[number]["parse"]>[] : T extends Schema ? ReturnType<T["parse"]>[] : never {
|
|
20
24
|
const dataAsArray = Array.isArray(data) ? data : [];
|
|
21
25
|
|
|
22
26
|
if (dataAsArray.length < this._minLength) {
|
|
@@ -29,10 +33,14 @@ export class ArraySchema<T extends Schema | Schema[]>
|
|
|
29
33
|
const resultForStructures = structures.map((schema) => schema.parse(item, config));
|
|
30
34
|
|
|
31
35
|
return resultForStructures.find((result) => result !== null) ?? first(resultForStructures);
|
|
32
|
-
}) as T extends Schema[] ? T[number]["parse"][] : T extends Schema ? T["parse"][] : never;
|
|
36
|
+
}) as T extends Schema[] ? ReturnType<T[number]["parse"]>[] : T extends Schema ? ReturnType<T["parse"]>[] : never;
|
|
33
37
|
|
|
34
38
|
return config?.placeholders === true
|
|
35
39
|
? results
|
|
36
|
-
: (compact(results) as T extends Schema[]
|
|
40
|
+
: (compact(results) as T extends Schema[]
|
|
41
|
+
? ReturnType<T[number]["parse"]>[]
|
|
42
|
+
: T extends Schema
|
|
43
|
+
? ReturnType<T["parse"]>[]
|
|
44
|
+
: never);
|
|
37
45
|
}
|
|
38
46
|
}
|
|
@@ -9,7 +9,13 @@ export class BuildingBlockSchema<T extends Record<string, Schema | Schema[]>>
|
|
|
9
9
|
public parse(
|
|
10
10
|
data: BuildingBlockFieldFulfillment | BuildingBlockFieldFulfillment[],
|
|
11
11
|
config?: SchemaConfig,
|
|
12
|
-
):
|
|
12
|
+
): {
|
|
13
|
+
[key in keyof T]: T[key] extends Schema[]
|
|
14
|
+
? ReturnType<T[key][number]["parse"]>
|
|
15
|
+
: T[key] extends Schema
|
|
16
|
+
? ReturnType<T[key]["parse"]>
|
|
17
|
+
: never;
|
|
18
|
+
} {
|
|
13
19
|
if (!Array.isArray(data)) {
|
|
14
20
|
data = [data];
|
|
15
21
|
}
|
|
@@ -7,7 +7,16 @@ export class ContentItemSchema<T extends Record<string, Schema | Schema[]>>
|
|
|
7
7
|
{
|
|
8
8
|
public constructor(private readonly structure: T) {}
|
|
9
9
|
|
|
10
|
-
public parse(
|
|
10
|
+
public parse(
|
|
11
|
+
data: unknown,
|
|
12
|
+
config?: SchemaConfig,
|
|
13
|
+
): {
|
|
14
|
+
[key in keyof T]: T[key] extends Schema[]
|
|
15
|
+
? ReturnType<T[key][number]["parse"]>
|
|
16
|
+
: T[key] extends Schema
|
|
17
|
+
? ReturnType<T[key]["parse"]>
|
|
18
|
+
: never;
|
|
19
|
+
} {
|
|
11
20
|
if (isArray(data)) {
|
|
12
21
|
data = data[0];
|
|
13
22
|
}
|
|
@@ -33,9 +33,9 @@ export interface Schema<TResult = unknown, TData = unknown> {
|
|
|
33
33
|
|
|
34
34
|
export type ObjectSchema<T extends Record<string, Schema | Schema[]>> = {
|
|
35
35
|
[key in keyof T]: T[key] extends Schema[]
|
|
36
|
-
? ReturnType<T[key][number]["parse"]>
|
|
36
|
+
? ReturnType<T[key][number]["parse"]>
|
|
37
37
|
: T[key] extends Schema
|
|
38
|
-
? ReturnType<T[key]["parse"]>
|
|
38
|
+
? ReturnType<T[key]["parse"]>
|
|
39
39
|
: never;
|
|
40
40
|
};
|
|
41
41
|
|