@platecms/delta-client 0.4.1 → 0.7.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 (102) hide show
  1. package/README.md +309 -96
  2. package/package.json +4 -6
  3. package/src/__generated__/fragment-masking.ts +87 -0
  4. package/src/__generated__/gql.ts +52 -0
  5. package/src/__generated__/graphql.ts +3141 -0
  6. package/src/__generated__/{index.d.ts → index.ts} +1 -1
  7. package/src/api/index.ts +1 -0
  8. package/src/apollo/index.ts +70 -0
  9. package/src/graphql/tags/tag.query.gql +5 -0
  10. package/src/graphql/tags/tags.fragments.gql +17 -0
  11. package/src/schema/index.spec.ts +211 -0
  12. package/src/schema/index.ts +18 -0
  13. package/src/schema/lib/schemas/array.spec.ts +111 -0
  14. package/src/schema/lib/schemas/array.ts +38 -0
  15. package/src/schema/lib/schemas/asset.spec.ts +101 -0
  16. package/src/schema/lib/schemas/asset.ts +12 -0
  17. package/src/schema/lib/schemas/baseSchema.ts +42 -0
  18. package/src/schema/lib/schemas/boolean.spec.ts +65 -0
  19. package/src/schema/lib/schemas/boolean.ts +12 -0
  20. package/src/schema/lib/schemas/buildingBlock.spec.ts +56 -0
  21. package/src/schema/lib/schemas/buildingBlock.ts +33 -0
  22. package/src/schema/lib/schemas/contentItem.spec.ts +61 -0
  23. package/src/schema/lib/schemas/contentItem.ts +31 -0
  24. package/src/schema/lib/schemas/contentType.spec.ts +113 -0
  25. package/src/schema/lib/schemas/contentType.ts +12 -0
  26. package/src/schema/lib/schemas/date.spec.ts +82 -0
  27. package/src/schema/lib/schemas/date.ts +17 -0
  28. package/src/schema/lib/schemas/gridPlacement.spec.ts +77 -0
  29. package/src/schema/lib/schemas/gridPlacement.ts +12 -0
  30. package/src/schema/lib/schemas/index.ts +66 -0
  31. package/src/schema/lib/schemas/number.spec.ts +65 -0
  32. package/src/schema/lib/schemas/number.ts +12 -0
  33. package/src/schema/lib/schemas/pathPart.spec.ts +120 -0
  34. package/src/schema/lib/schemas/pathPart.ts +12 -0
  35. package/src/schema/lib/schemas/smartText.spec.ts +105 -0
  36. package/src/schema/lib/schemas/smartText.ts +12 -0
  37. package/src/schema/lib/schemas/string.spec.ts +65 -0
  38. package/src/schema/lib/schemas/string.ts +12 -0
  39. package/src/schema/lib/schemas/tag.spec.ts +89 -0
  40. package/src/schema/lib/schemas/tag.ts +12 -0
  41. package/src/schema/lib/utils/isContentValue.spec.ts +111 -0
  42. package/src/schema/lib/utils/isContentValue.ts +17 -0
  43. package/src/schema/lib/utils/isPrimitiveValue.spec.ts +38 -0
  44. package/src/schema/lib/utils/isPrimitiveValue.ts +7 -0
  45. package/src/slate/index.ts +84 -0
  46. package/src/utils/{index.d.ts → index.ts} +3 -2
  47. package/src/utils/lib/connectors/BaseConnector.ts +26 -0
  48. package/src/utils/lib/connectors/WindowConnector.ts +70 -0
  49. package/src/utils/lib/events/ConnectorEvents.ts +89 -0
  50. package/src/utils/lib/events/EventEmitter.ts +19 -0
  51. package/src/__generated__/fragment-masking.d.ts +0 -19
  52. package/src/__generated__/fragment-masking.js +0 -22
  53. package/src/__generated__/fragment-masking.js.map +0 -1
  54. package/src/__generated__/gql.d.ts +0 -308
  55. package/src/__generated__/gql.js +0 -161
  56. package/src/__generated__/gql.js.map +0 -1
  57. package/src/__generated__/graphql.d.ts +0 -6343
  58. package/src/__generated__/graphql.js +0 -219
  59. package/src/__generated__/graphql.js.map +0 -1
  60. package/src/__generated__/index.js +0 -6
  61. package/src/__generated__/index.js.map +0 -1
  62. package/src/api/index.d.ts +0 -2
  63. package/src/api/index.js +0 -4
  64. package/src/api/index.js.map +0 -1
  65. package/src/apollo/index.d.ts +0 -7
  66. package/src/apollo/index.js +0 -40
  67. package/src/apollo/index.js.map +0 -1
  68. package/src/index.js +0 -3
  69. package/src/index.js.map +0 -1
  70. package/src/schema/index.d.ts +0 -2
  71. package/src/schema/index.js +0 -8
  72. package/src/schema/index.js.map +0 -1
  73. package/src/schema/lib/nodes.d.ts +0 -46
  74. package/src/schema/lib/nodes.js +0 -14
  75. package/src/schema/lib/nodes.js.map +0 -1
  76. package/src/schema/lib/parser.d.ts +0 -12
  77. package/src/schema/lib/parser.js +0 -49
  78. package/src/schema/lib/parser.js.map +0 -1
  79. package/src/schema/lib/schema.d.ts +0 -17
  80. package/src/schema/lib/schema.js +0 -65
  81. package/src/schema/lib/schema.js.map +0 -1
  82. package/src/schema/lib/utils.d.ts +0 -12
  83. package/src/schema/lib/utils.js +0 -66
  84. package/src/schema/lib/utils.js.map +0 -1
  85. package/src/slate/index.d.ts +0 -65
  86. package/src/slate/index.js +0 -3
  87. package/src/slate/index.js.map +0 -1
  88. package/src/utils/index.js +0 -6
  89. package/src/utils/index.js.map +0 -1
  90. package/src/utils/lib/connectors/BaseConnector.d.ts +0 -16
  91. package/src/utils/lib/connectors/BaseConnector.js +0 -17
  92. package/src/utils/lib/connectors/BaseConnector.js.map +0 -1
  93. package/src/utils/lib/connectors/WindowConnector.d.ts +0 -10
  94. package/src/utils/lib/connectors/WindowConnector.js +0 -53
  95. package/src/utils/lib/connectors/WindowConnector.js.map +0 -1
  96. package/src/utils/lib/events/ConnectorEvents.d.ts +0 -63
  97. package/src/utils/lib/events/ConnectorEvents.js +0 -24
  98. package/src/utils/lib/events/ConnectorEvents.js.map +0 -1
  99. package/src/utils/lib/events/EventEmitter.d.ts +0 -7
  100. package/src/utils/lib/events/EventEmitter.js +0 -21
  101. package/src/utils/lib/events/EventEmitter.js.map +0 -1
  102. /package/src/{index.d.ts → index.ts} +0 -0
package/README.md CHANGED
@@ -1,148 +1,361 @@
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
+ // Array handling with placeholders
115
+ const tagsSchema = schema.array(
116
+ schema.string().placeholder('placeholder')
117
+ ).placeholder({ minLength: 1 });
118
+
119
+ // Nested structures
120
+ const pageSchema = schema.buildingBlock({
121
+ hero: schema.contentItem({
122
+ title: schema.string(),
123
+ image: schema.asset(),
124
+ }),
125
+ sections: schema.array(schema.contentItem({
126
+ type: schema.string(),
127
+ content: schema.smartText(),
128
+ })),
129
+ });
130
+ ```
56
131
 
57
- ```ts
58
- s.object({
59
- // shape of the object
60
- })
132
+ ### 🎨 Slate.js Integration (`/slate`)
133
+
134
+ Provides TypeScript definitions and utilities for working with Slate.js in the Delta CMS context.
135
+
136
+ #### Type Definitions
137
+
138
+ ```typescript
139
+ import { DeltaElement, DeltaLeaf } from '@platecms/delta-client/slate';
140
+
141
+ // Available element types
142
+ type DeltaElement =
143
+ | ParagraphElement
144
+ | HeadingElement
145
+ | ListElement
146
+ | ListItemElement
147
+ | BlockquoteElement
148
+ | CodeElement
149
+ | ContentValueElement
150
+ | LinkElement;
151
+
152
+ // Leaf node with formatting
153
+ type DeltaLeaf = {
154
+ text: string;
155
+ bold?: true;
156
+ italic?: true;
157
+ underline?: true;
158
+ strikethrough?: true;
159
+ inlineCode?: true;
160
+ highlight?: true;
161
+ title?: true;
162
+ };
61
163
  ```
62
164
 
63
- ### Array
165
+ ### 🚀 Apollo Client Setup (`/apollo`)
64
166
 
65
- Default array with one placeholder
167
+ Pre-configured Apollo Client for GraphQL communication with Delta CMS.
66
168
 
67
- ```ts
68
- s.array(
69
- s.primitive('value')
70
- )
71
- ```
169
+ #### Basic Setup
72
170
 
73
- Array with a limit of the maximum number of items to display
171
+ ```typescript
172
+ import { createApolloClient } from '@platecms/delta-client/apollo';
74
173
 
75
- ```ts
76
- s.array(
77
- s.primitive('value'), 5 // limit to 5 items
78
- )
174
+ const client = createApolloClient('https://api.delta-cms.com/graphql', {
175
+ name: 'delta-cms-client',
176
+ headers: {
177
+ 'Authorization': 'Bearer your-token',
178
+ },
179
+ });
79
180
  ```
80
181
 
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
- )
182
+ #### Advanced Configuration
183
+
184
+ ```typescript
185
+ import { createApolloClient } from '@platecms/delta-client/apollo';
186
+ import { onError } from '@apollo/client/link/error';
187
+
188
+ const errorLink = onError(({ graphQLErrors, networkError }) => {
189
+ if (graphQLErrors) {
190
+ graphQLErrors.forEach(({ message, locations, path }) =>
191
+ console.log(`GraphQL error: Message: ${message}, Location: ${locations}, Path: ${path}`)
192
+ );
193
+ }
194
+ });
195
+
196
+ const client = createApolloClient('https://api.delta-cms.com/graphql', {
197
+ name: 'delta-cms-client',
198
+ errorLink,
199
+ headers: {
200
+ 'X-Custom-Header': 'value',
201
+ },
202
+ });
91
203
  ```
92
204
 
93
- ### Primitive
205
+ ### 🛠️ Utilities (`/utils`)
94
206
 
95
- #### string
207
+ Helper functions and connectors for Delta CMS integration.
96
208
 
97
- ```ts
98
- s.primitive('value')
209
+ #### Connectors
210
+
211
+ ```typescript
212
+ import { WindowConnector, ConnectorEvents } from '@platecms/delta-client/utils';
213
+
214
+ // Window-based communication
215
+ const connector = new WindowConnector();
216
+ connector.on(ConnectorEvents.CONTENT_UPDATED, (data) => {
217
+ console.log('Content updated:', data);
218
+ });
99
219
  ```
100
220
 
101
- #### number
221
+ #### Draft Types
222
+
223
+ ```typescript
224
+ import { Draft } from '@platecms/delta-client/utils';
225
+
226
+ type DraftArticle = Draft<{
227
+ title: string;
228
+ content: string;
229
+ }>;
102
230
 
103
- ```ts
104
- s.primitive(23)
231
+ // Draft objects include isDraft and uuid properties
232
+ const draft: DraftArticle = {
233
+ title: "My Article",
234
+ content: "Article content...",
235
+ isDraft: true,
236
+ uuid: "123e4567-e89b-12d3-a456-426614174000",
237
+ };
105
238
  ```
106
239
 
107
- ### Asset
240
+ ## API Reference
108
241
 
109
- Accepts a partial Asset object as a placeholder
242
+ ### Schema schemas
110
243
 
111
- ```ts
112
- s.asset({
113
- fileName: 'first',
114
- url: 'https://example.com/image.jpg'
115
- })
244
+ All schemas support the following methods:
245
+
246
+ - **`.nullable(boolean)`** - Set whether the field can be null
247
+ - **`.placeholder(value)`** - Set default value when data is missing
248
+ - **`.parse(data, config?)`** - Parse data with optional configuration
249
+
250
+ ### Configuration Options
251
+
252
+ ```typescript
253
+ interface schemaConfig {
254
+ placeholders?: boolean; // Enable placeholder values
255
+ }
116
256
  ```
117
257
 
118
- ### PathPart
258
+ ### Apollo Client Options
119
259
 
120
- Accepts a partial PathPart object as a placeholder
260
+ ```typescript
261
+ interface ApolloClientOptions {
262
+ name?: string;
263
+ errorLink?: ApolloLink;
264
+ headers?: Record<string, string>;
265
+ }
266
+ ```
267
+
268
+ ## Examples
269
+
270
+ ### Complete Content Parsing Example
271
+
272
+ ```typescript
273
+ import { schema } from '@platecms/delta-client/schema';
274
+ import { createApolloClient } from '@platecms/delta-client/apollo';
275
+
276
+ // Define schema
277
+ const blogPostSchema = schema.contentItem({
278
+ title: schema.string().nullable(false),
279
+ excerpt: schema.string().placeholder("No excerpt available"),
280
+ content: schema.smartText(),
281
+ author: schema.contentItem({
282
+ name: schema.string(),
283
+ avatar: schema.asset(),
284
+ }),
285
+ tags: schema.array(schema.tag()),
286
+ publishedAt: schema.date(),
287
+ featured: schema.boolean().placeholder(false),
288
+ });
289
+
290
+ // Setup Apollo Client
291
+ const client = createApolloClient('https://api.delta-cms.com/graphql');
292
+
293
+ // Parse content
294
+ const blogPost = blogPostSchema.parse(contentValue, { placeholders: true });
295
+ ```
121
296
 
122
- ```ts
123
- s.pathPart({
124
- path: '/blogs',
125
- })
297
+ ### Slate.js Editor Integration
298
+
299
+ ```typescript
300
+ import { BaseEditor } from 'slate';
301
+ import { ReactEditor } from 'slate-react';
302
+ import { DeltaElement, DeltaLeaf } from '@platecms/delta-client/slate';
303
+
304
+ // Type your editor
305
+ type CustomEditor = BaseEditor & ReactEditor;
306
+
307
+ // Use in your editor component
308
+ const MyEditor = () => {
309
+ const editor = useMemo(() => withReact(createEditor()), []);
310
+
311
+ // Your editor implementation
312
+ return (
313
+ <Slate editor={editor} value={value} onChange={setValue}>
314
+ <Editable />
315
+ </Slate>
316
+ );
317
+ };
126
318
  ```
127
319
 
128
- ### GridPlacement
320
+ ## Dependencies
129
321
 
130
- Accepts a partial GridPlacement object as a placeholder
322
+ ### Peer Dependencies
131
323
 
132
- ```ts
133
- s.gridPlacement({
134
- prn: 'prn:grid:123',
135
- row: 1
136
- })
324
+ - `@platecms/delta-cast` - Core casting utilities
325
+ - `@graphql-typed-document-node/core` - GraphQL type safety
326
+ - `graphql` - GraphQL implementation
327
+ - `lodash` - Utility functions
328
+ - `slate` - Rich text editor framework
329
+ - `slate-react` - React integration for Slate
330
+ - `tslib` - TypeScript runtime library
331
+ - `class-transformer` - Object transformation
332
+ - `reflect-metadata` - Metadata reflection
333
+ - `@apollo/client` - GraphQL client
334
+ - `defu` - Object merging utility
335
+
336
+ ## Development
337
+
338
+ This package is part of the Delta monorepo and uses Nx for build orchestration.
339
+
340
+ ### Building
341
+
342
+ ```bash
343
+ nx build delta-client
137
344
  ```
138
345
 
139
- ### Cast
346
+ ### Testing
140
347
 
141
- Accepts a correct root object to cast the schema to a usable data structure
348
+ ```bash
349
+ nx test delta-client
350
+ ```
351
+
352
+ ### Linting
142
353
 
143
- ```ts
144
- s.cast({
145
- type: 'root',
146
- children: []
147
- })
354
+ ```bash
355
+ nx lint delta-client
148
356
  ```
357
+
358
+ ## Repository
359
+
360
+ - **Homepage**: https://bitbucket.org/startmetplate/delta/src/dev/packages/delta-client
361
+ - **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": "0.7.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": "0.7.0",
22
22
  "@graphql-typed-document-node/core": "3.2.0",
23
23
  "graphql": "16.11.0",
24
24
  "lodash": "4.17.21",
@@ -34,8 +34,7 @@
34
34
  "./package.json": "./package.json",
35
35
  ".": {
36
36
  "import": "./index.esm.js",
37
- "default": "./index.cjs.js",
38
- "types": "./src/index.d.ts"
37
+ "default": "./index.cjs.js"
39
38
  },
40
39
  "./slate": {
41
40
  "types": "./src/slate/index.d.ts",
@@ -51,8 +50,7 @@
51
50
  "types": "./src/apollo/index.d.ts",
52
51
  "import": "./src/apollo/index.js",
53
52
  "default": "./src/apollo/index.cjs.js"
54
- },
55
- "./slate/index": "./src/slate/index.js"
53
+ }
56
54
  },
57
55
  "module": "./index.esm.js"
58
56
  }
@@ -0,0 +1,87 @@
1
+ /* eslint-disable */
2
+ import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
3
+ import { FragmentDefinitionNode } from 'graphql';
4
+ import { Incremental } from './graphql';
5
+
6
+
7
+ export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
8
+ infer TType,
9
+ any
10
+ >
11
+ ? [TType] extends [{ ' $fragmentName'?: infer TKey }]
12
+ ? TKey extends string
13
+ ? { ' $fragmentRefs'?: { [key in TKey]: TType } }
14
+ : never
15
+ : never
16
+ : never;
17
+
18
+ // return non-nullable if `fragmentType` is non-nullable
19
+ export function useFragment<TType>(
20
+ _documentNode: DocumentTypeDecoration<TType, any>,
21
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
22
+ ): TType;
23
+ // return nullable if `fragmentType` is undefined
24
+ export function useFragment<TType>(
25
+ _documentNode: DocumentTypeDecoration<TType, any>,
26
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
27
+ ): TType | undefined;
28
+ // return nullable if `fragmentType` is nullable
29
+ export function useFragment<TType>(
30
+ _documentNode: DocumentTypeDecoration<TType, any>,
31
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
32
+ ): TType | null;
33
+ // return nullable if `fragmentType` is nullable or undefined
34
+ export function useFragment<TType>(
35
+ _documentNode: DocumentTypeDecoration<TType, any>,
36
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
37
+ ): TType | null | undefined;
38
+ // return array of non-nullable if `fragmentType` is array of non-nullable
39
+ export function useFragment<TType>(
40
+ _documentNode: DocumentTypeDecoration<TType, any>,
41
+ fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
42
+ ): Array<TType>;
43
+ // return array of nullable if `fragmentType` is array of nullable
44
+ export function useFragment<TType>(
45
+ _documentNode: DocumentTypeDecoration<TType, any>,
46
+ fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
47
+ ): Array<TType> | null | undefined;
48
+ // return readonly array of non-nullable if `fragmentType` is array of non-nullable
49
+ export function useFragment<TType>(
50
+ _documentNode: DocumentTypeDecoration<TType, any>,
51
+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
52
+ ): ReadonlyArray<TType>;
53
+ // return readonly array of nullable if `fragmentType` is array of nullable
54
+ export function useFragment<TType>(
55
+ _documentNode: DocumentTypeDecoration<TType, any>,
56
+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
57
+ ): ReadonlyArray<TType> | null | undefined;
58
+ export function useFragment<TType>(
59
+ _documentNode: DocumentTypeDecoration<TType, any>,
60
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | Array<FragmentType<DocumentTypeDecoration<TType, any>>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
61
+ ): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
62
+ return fragmentType as any;
63
+ }
64
+
65
+
66
+ export function makeFragmentData<
67
+ F extends DocumentTypeDecoration<any, any>,
68
+ FT extends ResultOf<F>
69
+ >(data: FT, _fragment: F): FragmentType<F> {
70
+ return data as FragmentType<F>;
71
+ }
72
+ export function isFragmentReady<TQuery, TFrag>(
73
+ queryNode: DocumentTypeDecoration<TQuery, any>,
74
+ fragmentNode: TypedDocumentNode<TFrag>,
75
+ data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
76
+ ): data is FragmentType<typeof fragmentNode> {
77
+ const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
78
+ ?.deferredFields;
79
+
80
+ if (!deferredFields) return true;
81
+
82
+ const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
83
+ const fragName = fragDef?.name?.value;
84
+
85
+ const fields = (fragName && deferredFields[fragName]) || [];
86
+ return fields.length > 0 && fields.every(field => data && field in data);
87
+ }
@@ -0,0 +1,52 @@
1
+ /* eslint-disable */
2
+ import * as types from './graphql';
3
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
4
+
5
+ /**
6
+ * Map of all GraphQL operations in the project.
7
+ *
8
+ * This map has several performance disadvantages:
9
+ * 1. It is not tree-shakeable, so it will include all operations in the project.
10
+ * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
11
+ * 3. It does not support dead code elimination, so it will add unused operations.
12
+ *
13
+ * Therefore it is highly recommended to use the babel or swc plugin for production.
14
+ * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size
15
+ */
16
+ type Documents = {
17
+ "query tag($prn: [PRN!]!) {\n tag(prn: $prn) {\n ...tagFragment\n }\n}": typeof types.TagDocument,
18
+ "fragment tagFragment on Tag {\n _id: prn\n prn\n name\n path\n color\n visibility\n forceVisibilityOnDescendants\n stage\n amountOfChildren\n amountOfContentExperiences\n amountOfContentItems\n hasForcedVisibility\n nestingLevel\n createdAt\n updatedAt\n}": typeof types.TagFragmentFragmentDoc,
19
+ };
20
+ const documents: Documents = {
21
+ "query tag($prn: [PRN!]!) {\n tag(prn: $prn) {\n ...tagFragment\n }\n}": types.TagDocument,
22
+ "fragment tagFragment on Tag {\n _id: prn\n prn\n name\n path\n color\n visibility\n forceVisibilityOnDescendants\n stage\n amountOfChildren\n amountOfContentExperiences\n amountOfContentItems\n hasForcedVisibility\n nestingLevel\n createdAt\n updatedAt\n}": types.TagFragmentFragmentDoc,
23
+ };
24
+
25
+ /**
26
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
27
+ *
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
32
+ * ```
33
+ *
34
+ * The query argument is unknown!
35
+ * Please regenerate the types.
36
+ */
37
+ export function graphql(source: string): unknown;
38
+
39
+ /**
40
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
41
+ */
42
+ export function graphql(source: "query tag($prn: [PRN!]!) {\n tag(prn: $prn) {\n ...tagFragment\n }\n}"): (typeof documents)["query tag($prn: [PRN!]!) {\n tag(prn: $prn) {\n ...tagFragment\n }\n}"];
43
+ /**
44
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
45
+ */
46
+ export function graphql(source: "fragment tagFragment on Tag {\n _id: prn\n prn\n name\n path\n color\n visibility\n forceVisibilityOnDescendants\n stage\n amountOfChildren\n amountOfContentExperiences\n amountOfContentItems\n hasForcedVisibility\n nestingLevel\n createdAt\n updatedAt\n}"): (typeof documents)["fragment tagFragment on Tag {\n _id: prn\n prn\n name\n path\n color\n visibility\n forceVisibilityOnDescendants\n stage\n amountOfChildren\n amountOfContentExperiences\n amountOfContentItems\n hasForcedVisibility\n nestingLevel\n createdAt\n updatedAt\n}"];
47
+
48
+ export function graphql(source: string) {
49
+ return (documents as any)[source] ?? {};
50
+ }
51
+
52
+ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;