@platecms/delta-client 0.4.1 → 1.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.
Files changed (74) hide show
  1. package/README.md +304 -96
  2. package/package.json +2 -2
  3. package/src/__generated__/gql.d.ts +2 -298
  4. package/src/__generated__/gql.js +1 -149
  5. package/src/__generated__/gql.js.map +1 -1
  6. package/src/__generated__/graphql.d.ts +13 -4199
  7. package/src/__generated__/graphql.js +4 -153
  8. package/src/__generated__/graphql.js.map +1 -1
  9. package/src/schema/index.d.ts +14 -2
  10. package/src/schema/index.js +15 -5
  11. package/src/schema/index.js.map +1 -1
  12. package/src/schema/lib/schemas/array.d.ts +6 -0
  13. package/src/schema/lib/schemas/array.js +20 -0
  14. package/src/schema/lib/schemas/array.js.map +1 -0
  15. package/src/schema/lib/schemas/asset.d.ts +5 -0
  16. package/src/schema/lib/schemas/asset.js +14 -0
  17. package/src/schema/lib/schemas/asset.js.map +1 -0
  18. package/src/schema/lib/schemas/baseSchema.d.ts +10 -0
  19. package/src/schema/lib/schemas/baseSchema.js +36 -0
  20. package/src/schema/lib/schemas/baseSchema.js.map +1 -0
  21. package/src/schema/lib/schemas/boolean.d.ts +4 -0
  22. package/src/schema/lib/schemas/boolean.js +15 -0
  23. package/src/schema/lib/schemas/boolean.js.map +1 -0
  24. package/src/schema/lib/schemas/buildingBlock.d.ts +7 -0
  25. package/src/schema/lib/schemas/buildingBlock.js +26 -0
  26. package/src/schema/lib/schemas/buildingBlock.js.map +1 -0
  27. package/src/schema/lib/schemas/contentItem.d.ts +6 -0
  28. package/src/schema/lib/schemas/contentItem.js +26 -0
  29. package/src/schema/lib/schemas/contentItem.js.map +1 -0
  30. package/src/schema/lib/schemas/contentType.d.ts +5 -0
  31. package/src/schema/lib/schemas/contentType.js +14 -0
  32. package/src/schema/lib/schemas/contentType.js.map +1 -0
  33. package/src/schema/lib/schemas/date.d.ts +5 -0
  34. package/src/schema/lib/schemas/date.js +19 -0
  35. package/src/schema/lib/schemas/date.js.map +1 -0
  36. package/src/schema/lib/schemas/gridPlacement.d.ts +5 -0
  37. package/src/schema/lib/schemas/gridPlacement.js +14 -0
  38. package/src/schema/lib/schemas/gridPlacement.js.map +1 -0
  39. package/src/schema/lib/schemas/index.d.ts +55 -0
  40. package/src/schema/lib/schemas/index.js +33 -0
  41. package/src/schema/lib/schemas/index.js.map +1 -0
  42. package/src/schema/lib/schemas/number.d.ts +4 -0
  43. package/src/schema/lib/schemas/number.js +15 -0
  44. package/src/schema/lib/schemas/number.js.map +1 -0
  45. package/src/schema/lib/schemas/pathPart.d.ts +5 -0
  46. package/src/schema/lib/schemas/pathPart.js +14 -0
  47. package/src/schema/lib/schemas/pathPart.js.map +1 -0
  48. package/src/schema/lib/schemas/smartText.d.ts +5 -0
  49. package/src/schema/lib/schemas/smartText.js +14 -0
  50. package/src/schema/lib/schemas/smartText.js.map +1 -0
  51. package/src/schema/lib/schemas/string.d.ts +4 -0
  52. package/src/schema/lib/schemas/string.js +15 -0
  53. package/src/schema/lib/schemas/string.js.map +1 -0
  54. package/src/schema/lib/schemas/tag.d.ts +5 -0
  55. package/src/schema/lib/schemas/tag.js +14 -0
  56. package/src/schema/lib/schemas/tag.js.map +1 -0
  57. package/src/schema/lib/utils/isContentValue.d.ts +2 -0
  58. package/src/schema/lib/utils/isContentValue.js +17 -0
  59. package/src/schema/lib/utils/isContentValue.js.map +1 -0
  60. package/src/schema/lib/utils/isPrimitiveValue.d.ts +5 -0
  61. package/src/schema/lib/utils/isPrimitiveValue.js +8 -0
  62. package/src/schema/lib/utils/isPrimitiveValue.js.map +1 -0
  63. package/src/schema/lib/nodes.d.ts +0 -46
  64. package/src/schema/lib/nodes.js +0 -14
  65. package/src/schema/lib/nodes.js.map +0 -1
  66. package/src/schema/lib/parser.d.ts +0 -12
  67. package/src/schema/lib/parser.js +0 -49
  68. package/src/schema/lib/parser.js.map +0 -1
  69. package/src/schema/lib/schema.d.ts +0 -17
  70. package/src/schema/lib/schema.js +0 -65
  71. package/src/schema/lib/schema.js.map +0 -1
  72. package/src/schema/lib/utils.d.ts +0 -12
  73. package/src/schema/lib/utils.js +0 -66
  74. package/src/schema/lib/utils.js.map +0 -1
package/README.md CHANGED
@@ -1,148 +1,356 @@
1
- # delta-client-schema
1
+ # @platecms/delta-client
2
2
 
3
- This library is part of the [Delta Client]() utility packages.
4
- It provides a utility to convert abstract building blocks and their values to usable data structures.
3
+ Utilities and functions to interact with the Delta CMS.
5
4
 
6
- ## Usage
5
+ ## Overview
7
6
 
8
- Defining a schema looks as follows consists of a root object and nested fields.
9
- For example for a building block that has a welcome message, the schema would look like this:
7
+ The `@platecms/delta-client` package provides a comprehensive set of utilities for working with the Delta CMS. It includes schema parsing, Slate.js integration, Apollo Client setup, and various helper functions for content management.
10
8
 
11
- ```ts
12
- import { s } from "@platecms/delta-client/schema";
13
-
14
- const heroBuildingBlock = s.object({
15
- title: s.primitive(c('root', 'title')),
16
- description: s.cast(c('root', 'description')),
17
- images: s.array(s.asset())
18
- })
9
+ ## Installation
19
10
 
11
+ ```bash
12
+ npm install @platecms/delta-client
20
13
  ```
21
14
 
22
- The schema can then be used to convert the abstract building block to a usable data structure:
15
+ ## Package Structure
23
16
 
24
- ```ts
25
- import { p as parser } from "@platecms/delta-client/schema";
17
+ This package is organized into several main modules:
26
18
 
27
- const heroBuildingBlock = parser.parse(schema, buildingBlockFieldFulfillments);
28
- ```
19
+ ### 📦 Main Exports
20
+
21
+ - **`@platecms/delta-client`** - Main package entry point
22
+ - **`@platecms/delta-client/slate`** - Slate.js integration and type definitions
23
+ - **`@platecms/delta-client/schema`** - Schema parsing and validation utilities
24
+ - **`@platecms/delta-client/apollo`** - Apollo Client configuration and setup
25
+
26
+ ## Features
27
+
28
+ ### 🎯 Schema Parsing (`/schema`)
29
+
30
+ The schema module provides a powerful type-safe way to parse and validate content from the Delta CMS.
31
+
32
+ #### Basic Usage
33
+
34
+ ```typescript
35
+ import { schema } from '@platecms/delta-client/schema';
36
+
37
+ // Define a content structure
38
+ const articleSchema = schema.buildingBlock({
39
+ // Multiple types for a field
40
+ title: [schema.string(), schema.number()],
41
+ content: schema.smartText(),
42
+ publishedAt: schema.date(),
43
+ featured: schema.boolean(),
44
+ // Array of items
45
+ tags: schema.array(schema.tag()),
46
+ // For related content items
47
+ author: schema.contentItem({
48
+ name: schema.string(),
49
+ email: schema.string(),
50
+ }),
51
+ });
29
52
 
30
- Yields:
53
+ // Parse content data
54
+ const article = articleSchema.parse(buildingBlockFieldFulfillments);
31
55
 
32
- ```ts
33
- const heroBuildingBlock = {
34
- title: "Hero Title",
35
- description: {
36
- type: 'root',
56
+ // Result
57
+ {
58
+ title: "My article",
59
+ content: {
60
+ type: "root",
37
61
  children: [
38
62
  {
39
- type: 'text',
40
- value: 'Welcome to our website'
63
+ type: "paragraph",
64
+ children: [
65
+ {
66
+ type: "text",
67
+ value: "My first article"
68
+ }
69
+ ]
41
70
  }
42
71
  ]
43
72
  },
44
- images: [
45
- {
46
- fileName: "first image",
47
- url: 'https://example.com/image.jpg',
48
- }
49
- ]
73
+ publishedAt: new Date(),
74
+ featured: true,
75
+ tags: [{
76
+ name: "Higlighted",
77
+ //...other tag fields
78
+ }],
79
+ author: {
80
+ name: "Plate",
81
+ email: "my@email.com"
82
+ }
50
83
  }
51
84
  ```
52
85
 
53
- ## API
54
-
55
- ### Object
86
+ #### Available Types
87
+
88
+ - **`schema.string()`** - String values
89
+ - **`schema.number()`** - Numeric values
90
+ - **`schema.boolean()`** - Boolean values
91
+ - **`schema.date()`** - Date values
92
+ - **`schema.asset()`** - Asset references
93
+ - **`schema.smartText()`** - Rich text content
94
+ - **`schema.contentItem()`** - Related content items
95
+ - **`schema.buildingBlock()`** - Building block structures
96
+ - **`schema.array()`** - Arrays of any schema
97
+ - **`schema.gridPlacement()`** - Grid layout placements
98
+ - **`schema.contentType()`** - Content type references
99
+ - **`schema.pathPart()`** - URL path components
100
+ - **`schema.tag()`** - Tag references
101
+
102
+ #### Advanced Features
103
+
104
+ ```typescript
105
+ // Nullable fields with placeholders
106
+ const schema = schema.contentItem({
107
+ title: schema.string().nullable(false), // Required field, throws
108
+ description: schema.string().placeholder("No description available"), // Default value
109
+ });
110
+
111
+ // Array handling
112
+ const tagsSchema = schema.array(schema.tag());
113
+
114
+ // Nested structures
115
+ const pageSchema = schema.buildingBlock({
116
+ hero: schema.contentItem({
117
+ title: schema.string(),
118
+ image: schema.asset(),
119
+ }),
120
+ sections: schema.array(schema.contentItem({
121
+ type: schema.string(),
122
+ content: schema.smartText(),
123
+ })),
124
+ });
125
+ ```
56
126
 
57
- ```ts
58
- s.object({
59
- // shape of the object
60
- })
127
+ ### 🎨 Slate.js Integration (`/slate`)
128
+
129
+ Provides TypeScript definitions and utilities for working with Slate.js in the Delta CMS context.
130
+
131
+ #### Type Definitions
132
+
133
+ ```typescript
134
+ import { DeltaElement, DeltaLeaf } from '@platecms/delta-client/slate';
135
+
136
+ // Available element types
137
+ type DeltaElement =
138
+ | ParagraphElement
139
+ | HeadingElement
140
+ | ListElement
141
+ | ListItemElement
142
+ | BlockquoteElement
143
+ | CodeElement
144
+ | ContentValueElement
145
+ | LinkElement;
146
+
147
+ // Leaf node with formatting
148
+ type DeltaLeaf = {
149
+ text: string;
150
+ bold?: true;
151
+ italic?: true;
152
+ underline?: true;
153
+ strikethrough?: true;
154
+ inlineCode?: true;
155
+ highlight?: true;
156
+ title?: true;
157
+ };
61
158
  ```
62
159
 
63
- ### Array
160
+ ### 🚀 Apollo Client Setup (`/apollo`)
64
161
 
65
- Default array with one placeholder
162
+ Pre-configured Apollo Client for GraphQL communication with Delta CMS.
66
163
 
67
- ```ts
68
- s.array(
69
- s.primitive('value')
70
- )
71
- ```
164
+ #### Basic Setup
72
165
 
73
- Array with a limit of the maximum number of items to display
166
+ ```typescript
167
+ import { createApolloClient } from '@platecms/delta-client/apollo';
74
168
 
75
- ```ts
76
- s.array(
77
- s.primitive('value'), 5 // limit to 5 items
78
- )
169
+ const client = createApolloClient('https://api.delta-cms.com/graphql', {
170
+ name: 'delta-cms-client',
171
+ headers: {
172
+ 'Authorization': 'Bearer your-token',
173
+ },
174
+ });
79
175
  ```
80
176
 
81
- Array with an array of placeholders, also uses this a minimum number of items to display
82
-
83
- ```ts
84
- s.array(
85
- [
86
- s.primitive('value'),
87
- s.primitive('value'),
88
- // other fields
89
- ]
90
- )
177
+ #### Advanced Configuration
178
+
179
+ ```typescript
180
+ import { createApolloClient } from '@platecms/delta-client/apollo';
181
+ import { onError } from '@apollo/client/link/error';
182
+
183
+ const errorLink = onError(({ graphQLErrors, networkError }) => {
184
+ if (graphQLErrors) {
185
+ graphQLErrors.forEach(({ message, locations, path }) =>
186
+ console.log(`GraphQL error: Message: ${message}, Location: ${locations}, Path: ${path}`)
187
+ );
188
+ }
189
+ });
190
+
191
+ const client = createApolloClient('https://api.delta-cms.com/graphql', {
192
+ name: 'delta-cms-client',
193
+ errorLink,
194
+ headers: {
195
+ 'X-Custom-Header': 'value',
196
+ },
197
+ });
91
198
  ```
92
199
 
93
- ### Primitive
200
+ ### 🛠️ Utilities (`/utils`)
94
201
 
95
- #### string
202
+ Helper functions and connectors for Delta CMS integration.
96
203
 
97
- ```ts
98
- s.primitive('value')
204
+ #### Connectors
205
+
206
+ ```typescript
207
+ import { WindowConnector, ConnectorEvents } from '@platecms/delta-client/utils';
208
+
209
+ // Window-based communication
210
+ const connector = new WindowConnector();
211
+ connector.on(ConnectorEvents.CONTENT_UPDATED, (data) => {
212
+ console.log('Content updated:', data);
213
+ });
99
214
  ```
100
215
 
101
- #### number
216
+ #### Draft Types
217
+
218
+ ```typescript
219
+ import { Draft } from '@platecms/delta-client/utils';
220
+
221
+ type DraftArticle = Draft<{
222
+ title: string;
223
+ content: string;
224
+ }>;
102
225
 
103
- ```ts
104
- s.primitive(23)
226
+ // Draft objects include isDraft and uuid properties
227
+ const draft: DraftArticle = {
228
+ title: "My Article",
229
+ content: "Article content...",
230
+ isDraft: true,
231
+ uuid: "123e4567-e89b-12d3-a456-426614174000",
232
+ };
105
233
  ```
106
234
 
107
- ### Asset
235
+ ## API Reference
108
236
 
109
- Accepts a partial Asset object as a placeholder
237
+ ### Schema schemas
110
238
 
111
- ```ts
112
- s.asset({
113
- fileName: 'first',
114
- url: 'https://example.com/image.jpg'
115
- })
239
+ All schemas support the following methods:
240
+
241
+ - **`.nullable(boolean)`** - Set whether the field can be null
242
+ - **`.placeholder(value)`** - Set default value when data is missing
243
+ - **`.parse(data, config?)`** - Parse data with optional configuration
244
+
245
+ ### Configuration Options
246
+
247
+ ```typescript
248
+ interface schemaConfig {
249
+ placeholders?: boolean; // Enable placeholder values
250
+ }
116
251
  ```
117
252
 
118
- ### PathPart
253
+ ### Apollo Client Options
119
254
 
120
- Accepts a partial PathPart object as a placeholder
255
+ ```typescript
256
+ interface ApolloClientOptions {
257
+ name?: string;
258
+ errorLink?: ApolloLink;
259
+ headers?: Record<string, string>;
260
+ }
261
+ ```
262
+
263
+ ## Examples
264
+
265
+ ### Complete Content Parsing Example
266
+
267
+ ```typescript
268
+ import { schema } from '@platecms/delta-client/schema';
269
+ import { createApolloClient } from '@platecms/delta-client/apollo';
270
+
271
+ // Define schema
272
+ const blogPostSchema = schema.contentItem({
273
+ title: schema.string().nullable(false),
274
+ excerpt: schema.string().placeholder("No excerpt available"),
275
+ content: schema.smartText(),
276
+ author: schema.contentItem({
277
+ name: schema.string(),
278
+ avatar: schema.asset(),
279
+ }),
280
+ tags: schema.array(schema.tag()),
281
+ publishedAt: schema.date(),
282
+ featured: schema.boolean().placeholder(false),
283
+ });
284
+
285
+ // Setup Apollo Client
286
+ const client = createApolloClient('https://api.delta-cms.com/graphql');
287
+
288
+ // Parse content
289
+ const blogPost = blogPostSchema.parse(contentValue, { placeholders: true });
290
+ ```
121
291
 
122
- ```ts
123
- s.pathPart({
124
- path: '/blogs',
125
- })
292
+ ### Slate.js Editor Integration
293
+
294
+ ```typescript
295
+ import { BaseEditor } from 'slate';
296
+ import { ReactEditor } from 'slate-react';
297
+ import { DeltaElement, DeltaLeaf } from '@platecms/delta-client/slate';
298
+
299
+ // Type your editor
300
+ type CustomEditor = BaseEditor & ReactEditor;
301
+
302
+ // Use in your editor component
303
+ const MyEditor = () => {
304
+ const editor = useMemo(() => withReact(createEditor()), []);
305
+
306
+ // Your editor implementation
307
+ return (
308
+ <Slate editor={editor} value={value} onChange={setValue}>
309
+ <Editable />
310
+ </Slate>
311
+ );
312
+ };
126
313
  ```
127
314
 
128
- ### GridPlacement
315
+ ## Dependencies
129
316
 
130
- Accepts a partial GridPlacement object as a placeholder
317
+ ### Peer Dependencies
131
318
 
132
- ```ts
133
- s.gridPlacement({
134
- prn: 'prn:grid:123',
135
- row: 1
136
- })
319
+ - `@platecms/delta-cast` - Core casting utilities
320
+ - `@graphql-typed-document-node/core` - GraphQL type safety
321
+ - `graphql` - GraphQL implementation
322
+ - `lodash` - Utility functions
323
+ - `slate` - Rich text editor framework
324
+ - `slate-react` - React integration for Slate
325
+ - `tslib` - TypeScript runtime library
326
+ - `class-transformer` - Object transformation
327
+ - `reflect-metadata` - Metadata reflection
328
+ - `@apollo/client` - GraphQL client
329
+ - `defu` - Object merging utility
330
+
331
+ ## Development
332
+
333
+ This package is part of the Delta monorepo and uses Nx for build orchestration.
334
+
335
+ ### Building
336
+
337
+ ```bash
338
+ nx build delta-client
137
339
  ```
138
340
 
139
- ### Cast
341
+ ### Testing
140
342
 
141
- Accepts a correct root object to cast the schema to a usable data structure
343
+ ```bash
344
+ nx test delta-client
345
+ ```
346
+
347
+ ### Linting
142
348
 
143
- ```ts
144
- s.cast({
145
- type: 'root',
146
- children: []
147
- })
349
+ ```bash
350
+ nx lint delta-client
148
351
  ```
352
+
353
+ ## Repository
354
+
355
+ - **Homepage**: https://bitbucket.org/startmetplate/delta/src/dev/packages/delta-client
356
+ - **Repository**: https://bitbucket.org/startmetplate/delta.git
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platecms/delta-client",
3
- "version": "0.4.1",
3
+ "version": "1.0.0",
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.4.1",
21
+ "@platecms/delta-cast": "1.0.0",
22
22
  "@graphql-typed-document-node/core": "3.2.0",
23
23
  "graphql": "16.11.0",
24
24
  "lodash": "4.17.21",