@sanity/assist 5.0.4 → 6.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 (131) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +28 -254
  3. package/dist/index.d.ts +322 -410
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +3181 -2649
  6. package/dist/index.js.map +1 -1
  7. package/package.json +38 -78
  8. package/dist/index.cjs +0 -4239
  9. package/dist/index.cjs.map +0 -1
  10. package/dist/index.d.cts +0 -791
  11. package/sanity.json +0 -8
  12. package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
  13. package/src/_lib/connector/ConnectToRegion.tsx +0 -23
  14. package/src/_lib/connector/ConnectorRegion.tsx +0 -24
  15. package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
  16. package/src/_lib/connector/ConnectorsStore.ts +0 -122
  17. package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
  18. package/src/_lib/connector/helpers.ts +0 -5
  19. package/src/_lib/connector/index.ts +0 -9
  20. package/src/_lib/connector/mapConnectorToLine.ts +0 -83
  21. package/src/_lib/connector/types.ts +0 -56
  22. package/src/_lib/connector/useConnectorsStore.ts +0 -14
  23. package/src/_lib/connector/useRegionRects.ts +0 -142
  24. package/src/_lib/fixedListenQuery.ts +0 -101
  25. package/src/_lib/form/DocumentForm.tsx +0 -201
  26. package/src/_lib/form/constants.ts +0 -1
  27. package/src/_lib/form/helpers.ts +0 -32
  28. package/src/_lib/form/index.ts +0 -1
  29. package/src/_lib/randomKey.ts +0 -29
  30. package/src/_lib/useListeningQuery.ts +0 -62
  31. package/src/_lib/usePrevious.ts +0 -9
  32. package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
  33. package/src/assistConnectors/ConnectorPath.tsx +0 -63
  34. package/src/assistConnectors/draw/arrowPath.ts +0 -9
  35. package/src/assistConnectors/draw/connectorPath.ts +0 -142
  36. package/src/assistConnectors/index.ts +0 -1
  37. package/src/assistDocument/AssistDocumentContext.tsx +0 -51
  38. package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
  39. package/src/assistDocument/AssistDocumentInput.tsx +0 -61
  40. package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
  41. package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
  42. package/src/assistDocument/components/AssistDocumentForm.tsx +0 -287
  43. package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
  44. package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
  45. package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
  46. package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
  47. package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
  48. package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
  49. package/src/assistDocument/components/helpers.ts +0 -21
  50. package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
  51. package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
  52. package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
  53. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
  54. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
  55. package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
  56. package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
  57. package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
  58. package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -127
  59. package/src/assistDocument/hooks/useDocumentState.ts +0 -6
  60. package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
  61. package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
  62. package/src/assistDocument/index.ts +0 -1
  63. package/src/assistFormComponents/AssistField.tsx +0 -63
  64. package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
  65. package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
  66. package/src/assistFormComponents/AssistItem.tsx +0 -21
  67. package/src/assistFormComponents/validation/listItem.tsx +0 -63
  68. package/src/assistFormComponents/validation/validationList.tsx +0 -90
  69. package/src/assistInspector/AssistInspector.tsx +0 -419
  70. package/src/assistInspector/FieldAutocomplete.tsx +0 -146
  71. package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
  72. package/src/assistInspector/constants.ts +0 -1
  73. package/src/assistInspector/helpers.ts +0 -211
  74. package/src/assistInspector/index.ts +0 -27
  75. package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
  76. package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
  77. package/src/assistLayout/AssistLayout.tsx +0 -39
  78. package/src/assistLayout/RunInstructionProvider.tsx +0 -278
  79. package/src/assistLayout/fieldRefCache.tsx +0 -34
  80. package/src/assistTypes.ts +0 -83
  81. package/src/components/AssistFeatureBadge.tsx +0 -9
  82. package/src/components/FadeInContent.tsx +0 -40
  83. package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
  84. package/src/components/ImageContext.tsx +0 -85
  85. package/src/components/SafeValueInput.tsx +0 -74
  86. package/src/components/TimeAgo.tsx +0 -18
  87. package/src/constants.ts +0 -20
  88. package/src/fieldActions/PrivateIcon.tsx +0 -20
  89. package/src/fieldActions/assistFieldActions.tsx +0 -320
  90. package/src/fieldActions/customFieldActions.tsx +0 -333
  91. package/src/fieldActions/generateCaptionActions.tsx +0 -77
  92. package/src/fieldActions/generateImageActions.tsx +0 -58
  93. package/src/fieldActions/useUserInput.ts +0 -107
  94. package/src/globals.d.ts +0 -4
  95. package/src/helpers/assistSupported.ts +0 -49
  96. package/src/helpers/conditionalMembers.test.ts +0 -319
  97. package/src/helpers/conditionalMembers.ts +0 -134
  98. package/src/helpers/ids.test.ts +0 -28
  99. package/src/helpers/ids.ts +0 -23
  100. package/src/helpers/misc.ts +0 -25
  101. package/src/helpers/styleguide.ts +0 -24
  102. package/src/helpers/typeUtils.ts +0 -60
  103. package/src/helpers/useAssistSupported.ts +0 -8
  104. package/src/index.ts +0 -26
  105. package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
  106. package/src/onboarding/InspectorOnboarding.tsx +0 -47
  107. package/src/onboarding/onboardingStore.ts +0 -32
  108. package/src/plugin.tsx +0 -162
  109. package/src/presence/AiFieldPresence.tsx +0 -28
  110. package/src/presence/AssistAvatar.tsx +0 -96
  111. package/src/presence/AssistDocumentPresence.tsx +0 -50
  112. package/src/presence/useAssistPresence.ts +0 -64
  113. package/src/schemas/assistDocumentSchema.tsx +0 -497
  114. package/src/schemas/contextDocumentSchema.tsx +0 -57
  115. package/src/schemas/index.ts +0 -69
  116. package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
  117. package/src/schemas/serialize/schemaUtils.ts +0 -38
  118. package/src/schemas/serialize/serializeSchema.test.ts +0 -819
  119. package/src/schemas/serialize/serializeSchema.ts +0 -224
  120. package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
  121. package/src/schemas/typeDefExtensions.ts +0 -127
  122. package/src/translate/FieldTranslationProvider.tsx +0 -382
  123. package/src/translate/getLanguageParams.ts +0 -26
  124. package/src/translate/languageStore.ts +0 -18
  125. package/src/translate/paths.test.ts +0 -181
  126. package/src/translate/paths.ts +0 -183
  127. package/src/translate/translateActions.tsx +0 -205
  128. package/src/translate/types.ts +0 -197
  129. package/src/types.ts +0 -220
  130. package/src/useApiClient.ts +0 -338
  131. package/v2-incompatible.js +0 -11
@@ -1,819 +0,0 @@
1
- import {Schema} from '@sanity/schema'
2
- import {defineArrayMember, defineField, defineType} from 'sanity'
3
- import {describe, expect, test} from 'vitest'
4
-
5
- import {AssistOptions} from '../typeDefExtensions'
6
- import {serializeSchema} from './serializeSchema'
7
-
8
- const mockStudioTypes = [
9
- defineField({
10
- type: 'object',
11
- name: 'slug',
12
- fields: [{type: 'string', name: '_ref'}],
13
- }),
14
- defineField({
15
- type: 'object',
16
- name: 'sanity.imageHotspot',
17
- fields: [{type: 'string', name: 'whatever'}],
18
- }),
19
- defineField({
20
- type: 'object',
21
- name: 'sanity.imageCrop',
22
- fields: [{type: 'string', name: 'whatever'}],
23
- }),
24
- ]
25
-
26
- describe('serializeSchema', () => {
27
- test('should serialize excluded document schema to support exclude: false overrides at the field level', () => {
28
- const schema = Schema.compile({
29
- name: 'test',
30
- types: [
31
- defineType({
32
- type: 'document',
33
- name: 'article',
34
- fields: [{type: 'string', name: 'title'}],
35
- options: {
36
- aiAssist: {
37
- exclude: true,
38
- },
39
- },
40
- }),
41
- ],
42
- })
43
-
44
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
45
-
46
- expect(serializedTypes).toEqual([
47
- {
48
- fields: [
49
- {
50
- name: 'title',
51
- title: 'Title',
52
- type: 'string',
53
- },
54
- ],
55
- name: 'article',
56
- title: 'Article',
57
- type: 'document',
58
- },
59
- ])
60
- })
61
-
62
- test('should serialize simple schema', () => {
63
- const schema = Schema.compile({
64
- name: 'test',
65
- types: [
66
- {
67
- type: 'document',
68
- name: 'article',
69
- fields: [
70
- {type: 'string', name: 'title'},
71
- {type: 'some', name: 'some'},
72
- {
73
- name: 'array',
74
- of: [{type: 'some'}],
75
- type: 'array',
76
- },
77
- ],
78
- },
79
- {
80
- type: 'object',
81
- name: 'some',
82
- fields: [{type: 'string', name: 'title'}],
83
- },
84
- ],
85
- })
86
-
87
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
88
-
89
- expect(serializedTypes).toEqual([
90
- {
91
- fields: [
92
- {name: 'title', title: 'Title', type: 'string'},
93
- {name: 'some', title: 'Some', type: 'some'},
94
- {
95
- name: 'array',
96
- of: [{name: 'some', title: 'Some', type: 'some'}],
97
- title: 'Array',
98
- type: 'array',
99
- },
100
- ],
101
- name: 'article',
102
- title: 'Article',
103
- type: 'document',
104
- },
105
- {
106
- fields: [{name: 'title', title: 'Title', type: 'string'}],
107
- name: 'some',
108
- title: 'Some',
109
- type: 'object',
110
- },
111
- ])
112
- })
113
-
114
- test('should not serialize slug type', () => {
115
- const schema = Schema.compile({
116
- name: 'test',
117
- types: mockStudioTypes,
118
- })
119
-
120
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
121
-
122
- //everything excluded directly or indirectly
123
- expect(serializedTypes).toEqual([])
124
- })
125
-
126
- test('should not serialize excluded fields or types or types with every member excluded (except images)', () => {
127
- const options: AssistOptions = {aiAssist: {exclude: true}}
128
-
129
- const schema = Schema.compile({
130
- name: 'test',
131
- types: [
132
- {
133
- type: 'document',
134
- name: 'mostFieldsExcluded',
135
- fields: [
136
- defineField({type: 'string', name: 'title', options}),
137
- defineField({
138
- type: 'object',
139
- name: 'excludedObject',
140
- // all fields excluded should exclude field
141
- fields: [{type: 'string', name: 'title', options}],
142
- options: {aiAssist: {exclude: true}},
143
- }),
144
- defineField({
145
- type: 'array',
146
- name: 'excludedArray',
147
- // all items excluded should exclude field
148
- of: [{type: 'object', name: 'remove', options}, {type: 'excluded'}],
149
- options: {aiAssist: {exclude: true}},
150
- }),
151
- //image without extra fields should NOT be excluded
152
- defineField({type: 'image', name: 'image'}),
153
- defineField({type: 'file', name: 'file'}),
154
- defineField({type: 'reference', name: 'reference', to: [{type: 'excluded'}]}),
155
- defineField({
156
- type: 'crossDatasetReference',
157
- name: 'crossDatasetReference',
158
- to: [{type: 'excluded'}],
159
- dataset: 'x',
160
- projectId: 'y',
161
- }),
162
- ],
163
- },
164
- defineField({
165
- type: 'object',
166
- name: 'excluded',
167
- fields: [{type: 'string', name: 'title', options}],
168
- options: {aiAssist: {exclude: true}},
169
- }),
170
- ...mockStudioTypes,
171
- ],
172
- })
173
-
174
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
175
-
176
- //everything excluded directly or indirectly
177
- expect(serializedTypes).toEqual([
178
- {
179
- fields: [
180
- {
181
- fields: [],
182
- name: 'image',
183
- title: 'Image',
184
- type: 'image',
185
- },
186
- ],
187
- name: 'mostFieldsExcluded',
188
- title: 'Most Fields Excluded',
189
- type: 'document',
190
- },
191
- ])
192
- })
193
-
194
- test('should serialize opt-in inline object using custom typeName', () => {
195
- const schema = Schema.compile({
196
- name: 'test',
197
- types: [
198
- {
199
- type: 'document',
200
- name: 'article',
201
- fields: [
202
- {type: 'string', name: 'title'},
203
- defineField({
204
- type: 'object',
205
- name: 'some',
206
- fields: [{type: 'string', name: 'title'}],
207
- }),
208
- defineField({
209
- type: 'array',
210
- name: 'array',
211
- of: [
212
- defineArrayMember({
213
- type: 'object',
214
- name: 'inlineArrayMember',
215
- fields: [{type: 'string', name: 'title'}],
216
- }),
217
- ],
218
- }),
219
- ],
220
- },
221
- ],
222
- })
223
-
224
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
225
-
226
- expect(serializedTypes).toEqual([
227
- {
228
- fields: [
229
- {name: 'title', title: 'Title', type: 'string'},
230
- {
231
- name: 'some',
232
- title: 'Some',
233
- type: 'object',
234
- fields: [{name: 'title', title: 'Title', type: 'string'}],
235
- },
236
- {
237
- name: 'array',
238
- of: [
239
- {
240
- type: 'object',
241
- name: 'inlineArrayMember',
242
- title: 'Inline Array Member',
243
- fields: [{name: 'title', title: 'Title', type: 'string'}],
244
- },
245
- ],
246
- title: 'Array',
247
- type: 'array',
248
- },
249
- ],
250
- name: 'article',
251
- title: 'Article',
252
- type: 'document',
253
- },
254
- ])
255
- })
256
-
257
- test('should serialize inline object', () => {
258
- const schema = Schema.compile({
259
- name: 'test',
260
- types: [
261
- {
262
- type: 'document',
263
- name: 'article',
264
- fields: [
265
- {type: 'string', name: 'title'},
266
- defineField({
267
- type: 'object',
268
- name: 'someObject',
269
- fields: [{type: 'string', name: 'title'}],
270
- }),
271
- defineField({
272
- type: 'file',
273
- name: 'someFile',
274
- fields: [{type: 'string', name: 'title'}],
275
- }),
276
- defineField({
277
- type: 'image',
278
- name: 'someImage',
279
- fields: [{type: 'string', name: 'title'}],
280
- }),
281
- ],
282
- },
283
- ...mockStudioTypes,
284
- ],
285
- })
286
-
287
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
288
-
289
- expect(serializedTypes).toEqual([
290
- {
291
- fields: [
292
- {name: 'title', title: 'Title', type: 'string'},
293
- {
294
- name: 'someObject',
295
- title: 'Some Object',
296
- type: 'object',
297
- fields: [{name: 'title', title: 'Title', type: 'string'}],
298
- },
299
- {
300
- name: 'someImage',
301
- title: 'Some Image',
302
- type: 'image',
303
- fields: [{name: 'title', title: 'Title', type: 'string'}],
304
- },
305
- ],
306
- name: 'article',
307
- title: 'Article',
308
- type: 'document',
309
- },
310
- ])
311
- })
312
-
313
- test('should serialize inline, anonymous array object type', () => {
314
- const schema = Schema.compile({
315
- name: 'test',
316
- types: [
317
- {
318
- type: 'document',
319
- name: 'article',
320
- fields: [
321
- {type: 'string', name: 'title'},
322
- defineField({
323
- type: 'array',
324
- name: 'array',
325
- of: [
326
- defineArrayMember({
327
- type: 'object',
328
- title: 'Nameless item',
329
- fields: [{type: 'string', name: 'title'}],
330
- }),
331
- ],
332
- }),
333
- ],
334
- },
335
- {
336
- fields: [{name: 'title', title: 'Title', type: 'string'}],
337
- name: 'item',
338
- title: 'Item',
339
- type: 'object',
340
- },
341
- ],
342
- })
343
-
344
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
345
-
346
- expect(serializedTypes).toEqual([
347
- {
348
- fields: [
349
- {name: 'title', title: 'Title', type: 'string'},
350
- {
351
- name: 'array',
352
- of: [
353
- {
354
- name: 'object',
355
- title: 'Nameless item',
356
- type: 'object',
357
- fields: [{name: 'title', title: 'Title', type: 'string'}],
358
- },
359
- ],
360
- title: 'Array',
361
- type: 'array',
362
- },
363
- ],
364
- name: 'article',
365
- title: 'Article',
366
- type: 'document',
367
- },
368
- {
369
- fields: [{name: 'title', title: 'Title', type: 'string'}],
370
- name: 'item',
371
- title: 'Item',
372
- type: 'object',
373
- },
374
- ])
375
- })
376
-
377
- test('should serialize nested inline objects', () => {
378
- const schema = Schema.compile({
379
- name: 'test',
380
- types: [
381
- {
382
- type: 'document',
383
- name: 'article',
384
- fields: [
385
- defineField({
386
- type: 'object',
387
- name: 'outer',
388
- fields: [
389
- defineField({
390
- type: 'object',
391
- name: 'inner',
392
- fields: [{type: 'string', name: 'title'}],
393
- }),
394
- ],
395
- }),
396
- ],
397
- },
398
- ],
399
- })
400
-
401
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
402
-
403
- expect(serializedTypes).toEqual([
404
- {
405
- name: 'article',
406
- title: 'Article',
407
- type: 'document',
408
- fields: [
409
- {
410
- fields: [
411
- {
412
- type: 'object',
413
- name: 'inner',
414
- title: 'Inner',
415
- fields: [{name: 'title', title: 'Title', type: 'string'}],
416
- },
417
- ],
418
- type: 'object',
419
- name: 'outer',
420
- title: 'Outer',
421
- },
422
- ],
423
- },
424
- ])
425
- })
426
-
427
- test('should serialize list values', () => {
428
- const schema = Schema.compile({
429
- name: 'test',
430
- types: [defineType({type: 'string', name: 'list', options: {list: ['a', 'b']}})],
431
- })
432
-
433
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
434
-
435
- expect(serializedTypes).toEqual([
436
- {name: 'list', title: 'String', type: 'string', values: ['a', 'b']},
437
- ])
438
- })
439
-
440
- test('should serialize list values in string array', () => {
441
- const schema = Schema.compile({
442
- name: 'test',
443
- types: [
444
- defineType({
445
- type: 'array',
446
- name: 'list',
447
- of: [{type: 'string'}],
448
- options: {
449
- list: [
450
- {title: 'A', value: 'a'},
451
- {title: 'B', value: 'b'},
452
- ],
453
- },
454
- }),
455
- ],
456
- })
457
-
458
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
459
-
460
- expect(serializedTypes).toEqual([
461
- {
462
- name: 'list',
463
- type: 'array',
464
- of: [{type: 'string', name: 'string', title: 'String'}],
465
- values: ['a', 'b'],
466
- },
467
- ])
468
- })
469
-
470
- test('should not try to serialize list values if list values are not an array', () => {
471
- const schema = Schema.compile({
472
- name: 'test',
473
- types: [
474
- defineType({
475
- type: 'array',
476
- name: 'list',
477
- of: [{type: 'string'}],
478
- options: {
479
- list: new Promise(() => {}) as any, // Type usually only accepts array, but some plugins might use other types
480
- },
481
- }),
482
- ],
483
- })
484
-
485
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
486
-
487
- expect(serializedTypes).toEqual([
488
- {
489
- name: 'list',
490
- type: 'array',
491
- of: [{type: 'string', name: 'string', title: 'String'}],
492
- values: undefined,
493
- },
494
- ])
495
- })
496
-
497
- test('should annotate truthy readonly', () => {
498
- const schema = Schema.compile({
499
- name: 'test',
500
- types: [
501
- {
502
- type: 'document',
503
- name: 'article',
504
- fields: [
505
- {type: 'string', name: 'title', readOnly: () => true},
506
- {type: 'some', name: 'some'},
507
- ],
508
- },
509
- defineType({
510
- type: 'object',
511
- name: 'some',
512
- readOnly: true,
513
- fields: [{type: 'string', name: 'title'}],
514
- }),
515
- ],
516
- })
517
-
518
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
519
-
520
- expect(serializedTypes).toEqual([
521
- {
522
- name: 'article',
523
- title: 'Article',
524
- type: 'document',
525
- fields: [
526
- {name: 'title', readOnly: 'function', title: 'Title', type: 'string'},
527
- {name: 'some', readOnly: true, title: 'Some', type: 'some'},
528
- ],
529
- },
530
- {
531
- name: 'some',
532
- readOnly: true,
533
- title: 'Some',
534
- type: 'object',
535
- fields: [{name: 'title', title: 'Title', type: 'string'}],
536
- },
537
- ])
538
- })
539
-
540
- test('should annotate truthy hidden', () => {
541
- const schema = Schema.compile({
542
- name: 'test',
543
- types: [
544
- {
545
- type: 'document',
546
- name: 'article',
547
- fields: [
548
- {type: 'string', name: 'title', hidden: true},
549
- {type: 'some', name: 'some'},
550
- ],
551
- },
552
- defineType({
553
- type: 'object',
554
- name: 'some',
555
- hidden: () => true,
556
- fields: [{type: 'string', name: 'title'}],
557
- }),
558
- ],
559
- })
560
-
561
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
562
-
563
- expect(serializedTypes).toEqual([
564
- {
565
- name: 'article',
566
- title: 'Article',
567
- type: 'document',
568
- fields: [
569
- {hidden: true, name: 'title', title: 'Title', type: 'string'},
570
- {hidden: 'function', name: 'some', title: 'Some', type: 'some'},
571
- ],
572
- },
573
- {
574
- hidden: 'function',
575
- name: 'some',
576
- title: 'Some',
577
- type: 'object',
578
- fields: [{name: 'title', title: 'Title', type: 'string'}],
579
- },
580
- ])
581
- })
582
-
583
- test('should serialize annotations', () => {
584
- const schema = Schema.compile({
585
- name: 'test',
586
- types: [
587
- defineType({
588
- type: 'object',
589
- name: 'annotation',
590
- fields: [defineField({type: 'string', name: 'fact', title: 'Fact'})],
591
- }),
592
- defineType({
593
- name: 'blockAlias',
594
- type: 'block',
595
- marks: {annotations: [{type: 'annotation'}]},
596
- }),
597
- defineType({
598
- type: 'document',
599
- name: 'article',
600
- fields: [
601
- {
602
- type: 'array',
603
- name: 'inlinePte',
604
- of: [
605
- defineArrayMember({
606
- type: 'block',
607
- marks: {
608
- annotations: [
609
- defineArrayMember({
610
- type: 'object',
611
- name: 'inline-annotation',
612
- fields: [defineField({type: 'string', name: 'fact', title: 'Fact'})],
613
- }),
614
- ],
615
- },
616
- }),
617
- ],
618
- },
619
- {type: 'array', name: 'pte', of: [{type: 'blockAlias'}]},
620
- ],
621
- }),
622
- ],
623
- })
624
-
625
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
626
-
627
- expect(serializedTypes).toEqual([
628
- {
629
- name: 'annotation',
630
- title: 'Annotation',
631
- type: 'object',
632
- fields: [{name: 'fact', title: 'Fact', type: 'string'}],
633
- },
634
- {
635
- name: 'article',
636
- title: 'Article',
637
- type: 'document',
638
- fields: [
639
- {
640
- name: 'inlinePte',
641
- title: 'Inline Pte',
642
- type: 'array',
643
- of: [
644
- {
645
- name: 'block',
646
- title: 'Block',
647
- type: 'block',
648
- inlineOf: [],
649
- annotations: [
650
- {
651
- name: 'inline-annotation',
652
- title: 'Inline Annotation',
653
- type: 'object',
654
- fields: [{name: 'fact', title: 'Fact', type: 'string'}],
655
- },
656
- ],
657
- },
658
- ],
659
- },
660
- {
661
- name: 'pte',
662
- of: [{name: 'blockAlias', title: 'Block', type: 'blockAlias'}],
663
- title: 'Pte',
664
- type: 'array',
665
- },
666
- ],
667
- },
668
- {
669
- name: 'blockAlias',
670
- title: 'Block',
671
- type: 'block',
672
- annotations: [{name: 'annotation', title: 'Annotation', type: 'annotation'}],
673
- inlineOf: [],
674
- },
675
- ])
676
- })
677
-
678
- test('should serialize inline block types', () => {
679
- const schema = Schema.compile({
680
- name: 'test',
681
- types: [
682
- defineType({
683
- type: 'object',
684
- name: 'inline-block',
685
- fields: [
686
- defineField({type: 'string', name: 'fact', title: 'Fact'}),
687
- defineField({type: 'blockAlias', name: 'recurse', title: 'Recursive'}),
688
- ],
689
- }),
690
- defineType({
691
- name: 'blockAlias',
692
- type: 'block',
693
- of: [{type: 'inline-block'}],
694
- }),
695
- defineType({
696
- type: 'document',
697
- name: 'article',
698
- fields: [{type: 'array', name: 'pte', of: [{type: 'blockAlias'}]}],
699
- }),
700
- ],
701
- })
702
-
703
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
704
-
705
- expect(serializedTypes).toEqual([
706
- {
707
- name: 'article',
708
- title: 'Article',
709
- type: 'document',
710
- fields: [
711
- {
712
- name: 'pte',
713
- of: [
714
- {
715
- name: 'blockAlias',
716
- title: 'Block',
717
- type: 'blockAlias',
718
- },
719
- ],
720
- title: 'Pte',
721
- type: 'array',
722
- },
723
- ],
724
- },
725
- {
726
- name: 'blockAlias',
727
- title: 'Block',
728
- type: 'block',
729
- annotations: [
730
- {
731
- fields: [{name: 'href', title: 'Link', type: 'url'}],
732
- name: 'link',
733
- title: 'Link',
734
- type: 'object',
735
- },
736
- ],
737
- inlineOf: [
738
- {
739
- name: 'inline-block',
740
- title: 'Inline Block',
741
- type: 'inline-block',
742
- },
743
- ],
744
- },
745
- {
746
- name: 'inline-block',
747
- title: 'Inline Block',
748
- type: 'object',
749
- fields: [
750
- {name: 'fact', title: 'Fact', type: 'string'},
751
- {
752
- name: 'recurse',
753
- title: 'Recursive',
754
- type: 'blockAlias',
755
- },
756
- ],
757
- },
758
- ])
759
- })
760
-
761
- test('should no serialize global document reference types (for now)', () => {
762
- const schema = Schema.compile({
763
- name: 'test',
764
- types: [
765
- defineType({
766
- type: 'object',
767
- name: 'author',
768
- fields: [
769
- defineField({
770
- type: 'string',
771
- name: 'name',
772
- }),
773
- defineField({
774
- type: 'globalDocumentReference',
775
- name: 'person',
776
- title: 'Person',
777
- resourceType: 'dataset',
778
- resourceId: 'exx11uqh.blog',
779
- to: [
780
- {
781
- type: 'person',
782
- preview: {
783
- select: {
784
- title: 'title',
785
- media: 'coverImage',
786
- },
787
- prepare(val: any) {
788
- return {
789
- title: val.title,
790
- media: val.coverImage,
791
- }
792
- },
793
- },
794
- },
795
- ],
796
- }),
797
- ],
798
- }),
799
- ],
800
- })
801
-
802
- const serializedTypes = serializeSchema(schema, {leanFormat: true})
803
-
804
- expect(serializedTypes).toEqual([
805
- {
806
- fields: [
807
- {
808
- name: 'name',
809
- title: 'Name',
810
- type: 'string',
811
- },
812
- ],
813
- name: 'author',
814
- title: 'Author',
815
- type: 'object',
816
- },
817
- ])
818
- })
819
- })