@platecms/delta-client 0.11.0 → 0.11.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/README.md CHANGED
@@ -282,7 +282,9 @@ const blogPostSchema = schema.contentItem({
282
282
  name: schema.string(),
283
283
  avatar: schema.asset(),
284
284
  }),
285
- tags: schema.array(schema.tag()),
285
+ tags: schema.array(schema.tag()).placeholder({
286
+ minLength: 1
287
+ }),
286
288
  publishedAt: schema.date(),
287
289
  featured: schema.boolean().placeholder(false),
288
290
  });
@@ -324,7 +326,6 @@ const MyEditor = () => {
324
326
  - `@platecms/delta-cast` - Core casting utilities
325
327
  - `@graphql-typed-document-node/core` - GraphQL type safety
326
328
  - `graphql` - GraphQL implementation
327
- - `lodash` - Utility functions
328
329
  - `slate` - Rich text editor framework
329
330
  - `slate-react` - React integration for Slate
330
331
  - `tslib` - TypeScript runtime library
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platecms/delta-client",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Utilities and functions to interact with the Delta CMS.",
5
5
  "license": "UNLICENSED",
6
6
  "publishConfig": {
@@ -18,17 +18,17 @@
18
18
  "src/**/*"
19
19
  ],
20
20
  "peerDependencies": {
21
- "@platecms/delta-cast": "0.11.0",
21
+ "@platecms/delta-cast": "0.11.1",
22
22
  "@graphql-typed-document-node/core": "3.2.0",
23
23
  "graphql": "16.11.0",
24
- "lodash": "4.17.21",
25
24
  "slate": "0.118.0",
26
25
  "slate-react": "0.117.4",
27
26
  "tslib": "2.8.1",
28
27
  "class-transformer": "0.5.1",
29
28
  "reflect-metadata": "0.2.2",
30
29
  "@apollo/client": "3.13.9",
31
- "defu": "6.1.4"
30
+ "defu": "6.1.4",
31
+ "lodash": "4.17.21"
32
32
  },
33
33
  "exports": {
34
34
  "./package.json": "./package.json",
@@ -9,7 +9,6 @@ import {
9
9
  from,
10
10
  } from "@apollo/client";
11
11
  import { PRN, ServiceAbbreviation } from "@platecms/delta-plate-resource-notation";
12
- import { compact } from "lodash";
13
12
  import { defu } from "defu";
14
13
 
15
14
  const placeholderOrganizationPrn = new PRN(
@@ -63,7 +62,7 @@ function createApolloClient(
63
62
  fetchPolicy: "cache-and-network" as FetchPolicy,
64
63
  },
65
64
  },
66
- link: from(compact([options?.errorLink, authLink.concat(httpLink)])),
65
+ link: from([options?.errorLink, authLink.concat(httpLink)].filter((value) => value !== undefined)),
67
66
  });
68
67
  }
69
68
 
@@ -1,5 +1,5 @@
1
- import { compact, first } from "lodash";
2
1
  import { Schema, SchemaConfig } from ".";
2
+ import { compact, first } from "../utils";
3
3
 
4
4
  export class ArraySchema<T extends Schema | Schema[]>
5
5
  implements
@@ -1,5 +1,5 @@
1
- import { isArray } from "lodash";
2
1
  import { ResultType, Schema, SchemaConfig } from ".";
2
+ import { isArray } from "../utils";
3
3
 
4
4
  export abstract class BaseSchema<TResult extends ResultType, TData> implements Schema<TResult, TData> {
5
5
  protected _isNullable = true;
@@ -1,7 +1,6 @@
1
1
  import { ObjectSchema, Schema, SchemaConfig } from ".";
2
- import { isArray } from "lodash";
3
2
  import { isContentValue } from "../utils/isContentValue";
4
-
3
+ import { isArray } from "../utils";
5
4
  export class ContentItemSchema<T extends Record<string, Schema | Schema[]>>
6
5
  implements Schema<ObjectSchema<T>, unknown>
7
6
  {
@@ -0,0 +1,160 @@
1
+ import { compact, first, isArray } from "./index";
2
+
3
+ describe("first", () => {
4
+ it("should return the first element of an array with numbers", () => {
5
+ const array = [1, 2, 3, 4, 5];
6
+ const result = first(array);
7
+ expect(result).toBe(1);
8
+ });
9
+
10
+ it("should return the first element of an array with strings", () => {
11
+ const array = ["apple", "banana", "cherry"];
12
+ const result = first(array);
13
+ expect(result).toBe("apple");
14
+ });
15
+
16
+ it("should return the first element of an array with objects", () => {
17
+ const obj1 = { id: 1, name: "first" };
18
+ const obj2 = { id: 2, name: "second" };
19
+ const array = [obj1, obj2];
20
+ const result = first(array);
21
+ expect(result).toBe(obj1);
22
+ });
23
+
24
+ it("should return undefined for an empty array", () => {
25
+ const array: number[] = [];
26
+ const result = first(array);
27
+ expect(result).toBeUndefined();
28
+ });
29
+
30
+ it("should return the first element even if it's falsy", () => {
31
+ const array = [0, 1, 2];
32
+ const result = first(array);
33
+ expect(result).toBe(0);
34
+ });
35
+
36
+ it("should work with arrays containing undefined", () => {
37
+ const array = [undefined, "second", "third"];
38
+ const result = first(array);
39
+ expect(result).toBeUndefined();
40
+ });
41
+ });
42
+
43
+ describe("compact", () => {
44
+ it("should remove null values from array", () => {
45
+ const array = [1, null, 2, null, 3];
46
+ const result = compact(array);
47
+ expect(result).toEqual([1, 2, 3]);
48
+ });
49
+
50
+ it("should remove undefined values from array", () => {
51
+ const array = [1, undefined, 2, undefined, 3];
52
+ const result = compact(array);
53
+ expect(result).toEqual([1, 2, 3]);
54
+ });
55
+
56
+ it("should remove false values from array", () => {
57
+ const array = [true, false, true, false];
58
+ const result = compact(array);
59
+ expect(result).toEqual([true, true]);
60
+ });
61
+
62
+ it("should remove empty strings from array", () => {
63
+ const array = ["hello", "", "world", ""];
64
+ const result = compact(array);
65
+ expect(result).toEqual(["hello", "world"]);
66
+ });
67
+
68
+ it("should remove zero values from array", () => {
69
+ const array = [1, 0, 2, 0, 3];
70
+ const result = compact(array);
71
+ expect(result).toEqual([1, 2, 3]);
72
+ });
73
+
74
+ it("should remove all falsy values in mixed array", () => {
75
+ const array = [1, null, "hello", undefined, false, "", 0, 2, "world"];
76
+ const result = compact(array);
77
+ expect(result).toEqual([1, "hello", 2, "world"]);
78
+ });
79
+
80
+ it("should return empty array when all values are falsy", () => {
81
+ const array = [null, undefined, false, "", 0];
82
+ const result = compact(array);
83
+ expect(result).toEqual([]);
84
+ });
85
+
86
+ it("should return same array when no falsy values", () => {
87
+ const array = [1, 2, "hello", true, { id: 1 }];
88
+ const result = compact(array);
89
+ expect(result).toEqual([1, 2, "hello", true, { id: 1 }]);
90
+ });
91
+
92
+ it("should work with empty array", () => {
93
+ const array: (string | null)[] = [];
94
+ const result = compact(array);
95
+ expect(result).toEqual([]);
96
+ });
97
+ });
98
+
99
+ describe("isArray", () => {
100
+ it("should return true for empty array", () => {
101
+ const value: unknown = [];
102
+ expect(isArray(value)).toBe(true);
103
+ });
104
+
105
+ it("should return true for array of numbers", () => {
106
+ const value: unknown = [1, 2, 3];
107
+ expect(isArray(value)).toBe(true);
108
+ });
109
+
110
+ it("should return true for array of strings", () => {
111
+ const value: unknown = ["a", "b", "c"];
112
+ expect(isArray(value)).toBe(true);
113
+ });
114
+
115
+ it("should return true for array of objects", () => {
116
+ const value: unknown = [{ id: 1 }, { id: 2 }];
117
+ expect(isArray(value)).toBe(true);
118
+ });
119
+
120
+ it("should return false for null", () => {
121
+ const value: unknown = null;
122
+ expect(isArray(value)).toBe(false);
123
+ });
124
+
125
+ it("should return false for undefined", () => {
126
+ const value: unknown = undefined;
127
+ expect(isArray(value)).toBe(false);
128
+ });
129
+
130
+ it("should return false for plain object", () => {
131
+ const value: unknown = { key: "value" };
132
+ expect(isArray(value)).toBe(false);
133
+ });
134
+
135
+ it("should return false for string", () => {
136
+ const value: unknown = "hello";
137
+ expect(isArray(value)).toBe(false);
138
+ });
139
+
140
+ it("should return false for number", () => {
141
+ const value: unknown = 42;
142
+ expect(isArray(value)).toBe(false);
143
+ });
144
+
145
+ it("should return false for boolean", () => {
146
+ const value: unknown = true;
147
+ expect(isArray(value)).toBe(false);
148
+ });
149
+
150
+ it("should return false for function", () => {
151
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
152
+ function value(): void {}
153
+ expect(isArray(value)).toBe(false);
154
+ });
155
+
156
+ it("should return false for Date object", () => {
157
+ const value: unknown = new Date();
158
+ expect(isArray(value)).toBe(false);
159
+ });
160
+ });
@@ -0,0 +1,11 @@
1
+ export function first<T>(array: T[]): T | undefined {
2
+ return array[0];
3
+ }
4
+
5
+ export function compact<T>(array: (T | "" | 0 | false | null | undefined)[]): T[] {
6
+ return array.filter((value) => Boolean(value)) as T[];
7
+ }
8
+
9
+ export function isArray<T>(value: unknown): value is T[] {
10
+ return Array.isArray(value);
11
+ }