@sanity/assist 5.0.3 → 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.
- package/LICENSE +1 -1
- package/README.md +28 -254
- package/dist/index.d.ts +322 -410
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3182 -2673
- package/dist/index.js.map +1 -1
- package/package.json +41 -77
- package/dist/index.cjs +0 -4264
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -791
- package/sanity.json +0 -8
- package/src/_lib/connector/ConnectFromRegion.tsx +0 -25
- package/src/_lib/connector/ConnectToRegion.tsx +0 -23
- package/src/_lib/connector/ConnectorRegion.tsx +0 -24
- package/src/_lib/connector/ConnectorsProvider.tsx +0 -20
- package/src/_lib/connector/ConnectorsStore.ts +0 -122
- package/src/_lib/connector/ConnectorsStoreContext.ts +0 -5
- package/src/_lib/connector/helpers.ts +0 -5
- package/src/_lib/connector/index.ts +0 -9
- package/src/_lib/connector/mapConnectorToLine.ts +0 -83
- package/src/_lib/connector/types.ts +0 -56
- package/src/_lib/connector/useConnectorsStore.ts +0 -14
- package/src/_lib/connector/useRegionRects.ts +0 -142
- package/src/_lib/fixedListenQuery.ts +0 -101
- package/src/_lib/form/DocumentForm.tsx +0 -201
- package/src/_lib/form/constants.ts +0 -1
- package/src/_lib/form/helpers.ts +0 -32
- package/src/_lib/form/index.ts +0 -1
- package/src/_lib/randomKey.ts +0 -29
- package/src/_lib/useListeningQuery.ts +0 -62
- package/src/_lib/usePrevious.ts +0 -9
- package/src/assistConnectors/AssistConnectorsOverlay.tsx +0 -133
- package/src/assistConnectors/ConnectorPath.tsx +0 -63
- package/src/assistConnectors/draw/arrowPath.ts +0 -9
- package/src/assistConnectors/draw/connectorPath.ts +0 -142
- package/src/assistConnectors/index.ts +0 -1
- package/src/assistDocument/AssistDocumentContext.tsx +0 -51
- package/src/assistDocument/AssistDocumentContextProvider.tsx +0 -17
- package/src/assistDocument/AssistDocumentInput.tsx +0 -61
- package/src/assistDocument/AssistDocumentLayout.tsx +0 -12
- package/src/assistDocument/RequestRunInstructionProvider.tsx +0 -61
- package/src/assistDocument/components/AssistDocumentForm.tsx +0 -286
- package/src/assistDocument/components/AssistTypeContext.tsx +0 -7
- package/src/assistDocument/components/FieldRefPreview.tsx +0 -26
- package/src/assistDocument/components/InstructionsArrayField.tsx +0 -8
- package/src/assistDocument/components/InstructionsArrayInput.tsx +0 -27
- package/src/assistDocument/components/SelectedFieldContext.tsx +0 -10
- package/src/assistDocument/components/generic/HiddenFieldTitle.tsx +0 -5
- package/src/assistDocument/components/helpers.ts +0 -21
- package/src/assistDocument/components/instruction/BackToInstructionsLink.tsx +0 -32
- package/src/assistDocument/components/instruction/FieldRefInput.tsx +0 -54
- package/src/assistDocument/components/instruction/InstructionInput.tsx +0 -89
- package/src/assistDocument/components/instruction/InstructionOutputField.tsx +0 -46
- package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +0 -206
- package/src/assistDocument/components/instruction/PromptInput.tsx +0 -59
- package/src/assistDocument/components/instruction/appearance/IconInput.tsx +0 -46
- package/src/assistDocument/components/instruction/appearance/InstructionVisibility.tsx +0 -37
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +0 -129
- package/src/assistDocument/hooks/useDocumentState.ts +0 -6
- package/src/assistDocument/hooks/useInstructionToaster.tsx +0 -75
- package/src/assistDocument/hooks/useStudioAssistDocument.ts +0 -99
- package/src/assistDocument/index.ts +0 -1
- package/src/assistFormComponents/AssistField.tsx +0 -63
- package/src/assistFormComponents/AssistFormBlock.tsx +0 -31
- package/src/assistFormComponents/AssistInlineFormBlock.tsx +0 -13
- package/src/assistFormComponents/AssistItem.tsx +0 -21
- package/src/assistFormComponents/validation/listItem.tsx +0 -63
- package/src/assistFormComponents/validation/validationList.tsx +0 -90
- package/src/assistInspector/AssistInspector.tsx +0 -423
- package/src/assistInspector/FieldAutocomplete.tsx +0 -146
- package/src/assistInspector/InstructionTaskHistoryButton.tsx +0 -262
- package/src/assistInspector/constants.ts +0 -1
- package/src/assistInspector/helpers.ts +0 -211
- package/src/assistInspector/index.ts +0 -27
- package/src/assistLayout/AiAssistanceConfigContext.tsx +0 -32
- package/src/assistLayout/AiAssistanceConfigProvider.tsx +0 -98
- package/src/assistLayout/AssistLayout.tsx +0 -39
- package/src/assistLayout/RunInstructionProvider.tsx +0 -278
- package/src/assistLayout/fieldRefCache.tsx +0 -34
- package/src/assistTypes.ts +0 -83
- package/src/components/AssistFeatureBadge.tsx +0 -9
- package/src/components/FadeInContent.tsx +0 -40
- package/src/components/HideReferenceChangedBannerInput.tsx +0 -25
- package/src/components/ImageContext.tsx +0 -85
- package/src/components/SafeValueInput.tsx +0 -74
- package/src/components/TimeAgo.tsx +0 -18
- package/src/constants.ts +0 -20
- package/src/fieldActions/PrivateIcon.tsx +0 -20
- package/src/fieldActions/assistFieldActions.tsx +0 -320
- package/src/fieldActions/customFieldActions.tsx +0 -333
- package/src/fieldActions/generateCaptionActions.tsx +0 -77
- package/src/fieldActions/generateImageActions.tsx +0 -58
- package/src/fieldActions/useUserInput.ts +0 -107
- package/src/globals.d.ts +0 -4
- package/src/helpers/assistSupported.ts +0 -49
- package/src/helpers/conditionalMembers.test.ts +0 -319
- package/src/helpers/conditionalMembers.ts +0 -134
- package/src/helpers/ids.test.ts +0 -28
- package/src/helpers/ids.ts +0 -23
- package/src/helpers/misc.ts +0 -25
- package/src/helpers/styleguide.ts +0 -24
- package/src/helpers/typeUtils.ts +0 -60
- package/src/helpers/useAssistSupported.ts +0 -8
- package/src/index.ts +0 -26
- package/src/onboarding/FirstAssistedPathProvider.tsx +0 -30
- package/src/onboarding/InspectorOnboarding.tsx +0 -47
- package/src/onboarding/onboardingStore.ts +0 -32
- package/src/plugin.tsx +0 -162
- package/src/presence/AiFieldPresence.tsx +0 -28
- package/src/presence/AssistAvatar.tsx +0 -96
- package/src/presence/AssistDocumentPresence.tsx +0 -50
- package/src/presence/useAssistPresence.ts +0 -64
- package/src/schemas/assistDocumentSchema.tsx +0 -497
- package/src/schemas/contextDocumentSchema.tsx +0 -57
- package/src/schemas/index.ts +0 -69
- package/src/schemas/serialize/SchemTypeTool.tsx +0 -103
- package/src/schemas/serialize/schemaUtils.ts +0 -38
- package/src/schemas/serialize/serializeSchema.test.ts +0 -819
- package/src/schemas/serialize/serializeSchema.ts +0 -224
- package/src/schemas/serializedSchemaTypeSchema.ts +0 -60
- package/src/schemas/typeDefExtensions.ts +0 -127
- package/src/translate/FieldTranslationProvider.tsx +0 -382
- package/src/translate/getLanguageParams.ts +0 -26
- package/src/translate/languageStore.ts +0 -18
- package/src/translate/paths.test.ts +0 -181
- package/src/translate/paths.ts +0 -183
- package/src/translate/translateActions.tsx +0 -205
- package/src/translate/types.ts +0 -197
- package/src/types.ts +0 -220
- package/src/useApiClient.ts +0 -338
- 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
|
-
})
|