@sanity/client 6.8.0-pink-lizard.11 → 6.8.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/README.md +2 -112
- package/dist/_chunks/{nodeMiddleware-cQeqivr5.cjs → nodeMiddleware-AQIXW8nd.cjs} +2 -2
- package/dist/_chunks/{nodeMiddleware-cQeqivr5.cjs.map → nodeMiddleware-AQIXW8nd.cjs.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-pr0WzTXK.js → nodeMiddleware-cKmlsf7J.js} +2 -2
- package/dist/_chunks/{nodeMiddleware-pr0WzTXK.js.map → nodeMiddleware-cKmlsf7J.js.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-xcYOjX4T.cjs → resolveEditInfo-2keGcJpx.cjs} +2 -1
- package/dist/_chunks/{resolveEditInfo-xcYOjX4T.cjs.map → resolveEditInfo-2keGcJpx.cjs.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-8A-bssPb.js → resolveEditInfo-hVGpZYTe.js} +2 -2
- package/dist/_chunks/{resolveEditInfo-8A-bssPb.js.map → resolveEditInfo-hVGpZYTe.js.map} +1 -1
- package/dist/csm.cjs +1 -1
- package/dist/csm.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/stega.browser.cjs +23 -65
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +23 -65
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +25 -21
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +26 -22
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/src/csm/resolveEditInfo.ts +2 -1
- package/src/stega/stegaEncodeSourceMap.ts +25 -18
- package/src/csm/applySourceDocuments.test.ts +0 -410
- package/src/csm/createEditUrl.test.ts +0 -39
- package/src/csm/jsonPath.test.ts +0 -39
- package/src/csm/resolveEditUrl.test.ts +0 -537
- package/src/csm/studioPath.test.ts +0 -237
- package/src/stega/encodeIntoResult.test.ts +0 -259
- package/src/stega/vercelStegaCleanAll.test.ts +0 -21
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
import {describe, expect, test} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import type {ContentSourceMap} from '../types'
|
|
4
|
-
import {applySourceDocuments} from './applySourceDocuments'
|
|
5
|
-
|
|
6
|
-
describe('complex queries', () => {
|
|
7
|
-
test('Can apply an array keyed field update', () => {
|
|
8
|
-
const result = {
|
|
9
|
-
page: {
|
|
10
|
-
_type: 'page',
|
|
11
|
-
_id: 'drafts.home',
|
|
12
|
-
title: 'Home',
|
|
13
|
-
sections: [
|
|
14
|
-
{
|
|
15
|
-
symbol: null,
|
|
16
|
-
products: null,
|
|
17
|
-
_type: 'hero',
|
|
18
|
-
tagline: 'ACME’s elegant construction is both minimal and inviting.',
|
|
19
|
-
headline: 'Touch of Texture ',
|
|
20
|
-
subline: 'You can follow us on Twitter, Twitch, LinkedIn, and GitHub.',
|
|
21
|
-
style: {
|
|
22
|
-
_type: 'sectionStyle',
|
|
23
|
-
variant: 'default',
|
|
24
|
-
},
|
|
25
|
-
_key: '44540ccd70c3',
|
|
26
|
-
product: null,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
}
|
|
31
|
-
const resultSourceMap = {
|
|
32
|
-
documents: [
|
|
33
|
-
{
|
|
34
|
-
_id: 'drafts.home',
|
|
35
|
-
_type: 'page',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
_id: 'drafts.462efcc6-3c8b-47c6-8474-5544e1a4acde',
|
|
39
|
-
_type: 'product',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
_id: 'drafts.e1bf9f1f-efdb-4105-8c26-6b64f897e9c1',
|
|
43
|
-
_type: 'product',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
_id: 'drafts.807cc05c-8c4c-443a-a9c1-198fd3fd7b16',
|
|
47
|
-
_type: 'product',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
_id: 'drafts.siteSettings',
|
|
51
|
-
_type: 'siteSettings',
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
paths: [
|
|
55
|
-
"$['_type']",
|
|
56
|
-
"$['_id']",
|
|
57
|
-
"$['title']",
|
|
58
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['style']",
|
|
59
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['_key']",
|
|
60
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['_type']",
|
|
61
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['tagline']",
|
|
62
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['headline']",
|
|
63
|
-
"$['sections'][?(@._key=='44540ccd70c3')]['subline']",
|
|
64
|
-
],
|
|
65
|
-
mappings: {
|
|
66
|
-
"$['page']['_id']": {
|
|
67
|
-
source: {
|
|
68
|
-
document: 0,
|
|
69
|
-
path: 1,
|
|
70
|
-
type: 'documentValue',
|
|
71
|
-
},
|
|
72
|
-
type: 'value',
|
|
73
|
-
},
|
|
74
|
-
"$['page']['_type']": {
|
|
75
|
-
source: {
|
|
76
|
-
document: 0,
|
|
77
|
-
path: 0,
|
|
78
|
-
type: 'documentValue',
|
|
79
|
-
},
|
|
80
|
-
type: 'value',
|
|
81
|
-
},
|
|
82
|
-
"$['page']['sections'][0]['_key']": {
|
|
83
|
-
source: {
|
|
84
|
-
document: 0,
|
|
85
|
-
path: 4,
|
|
86
|
-
type: 'documentValue',
|
|
87
|
-
},
|
|
88
|
-
type: 'value',
|
|
89
|
-
},
|
|
90
|
-
"$['page']['sections'][0]['_type']": {
|
|
91
|
-
source: {
|
|
92
|
-
document: 0,
|
|
93
|
-
path: 5,
|
|
94
|
-
type: 'documentValue',
|
|
95
|
-
},
|
|
96
|
-
type: 'value',
|
|
97
|
-
},
|
|
98
|
-
"$['page']['sections'][0]['headline']": {
|
|
99
|
-
source: {
|
|
100
|
-
document: 0,
|
|
101
|
-
path: 7,
|
|
102
|
-
type: 'documentValue',
|
|
103
|
-
},
|
|
104
|
-
type: 'value',
|
|
105
|
-
},
|
|
106
|
-
"$['page']['sections'][0]['style']": {
|
|
107
|
-
source: {
|
|
108
|
-
document: 0,
|
|
109
|
-
path: 3,
|
|
110
|
-
type: 'documentValue',
|
|
111
|
-
},
|
|
112
|
-
type: 'value',
|
|
113
|
-
},
|
|
114
|
-
"$['page']['sections'][0]['subline']": {
|
|
115
|
-
source: {
|
|
116
|
-
document: 0,
|
|
117
|
-
path: 8,
|
|
118
|
-
type: 'documentValue',
|
|
119
|
-
},
|
|
120
|
-
type: 'value',
|
|
121
|
-
},
|
|
122
|
-
"$['page']['sections'][0]['tagline']": {
|
|
123
|
-
source: {
|
|
124
|
-
document: 0,
|
|
125
|
-
path: 6,
|
|
126
|
-
type: 'documentValue',
|
|
127
|
-
},
|
|
128
|
-
type: 'value',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
} satisfies ContentSourceMap
|
|
132
|
-
// In this draft the headline "Touch of Texture 1" is changed
|
|
133
|
-
const draft = {
|
|
134
|
-
_createdAt: '2023-06-27T14:35:36Z',
|
|
135
|
-
_id: 'drafts.home',
|
|
136
|
-
_rev: '3b8d3273-43ec-471c-9629-1ab5e0e894fa',
|
|
137
|
-
_type: 'page',
|
|
138
|
-
_updatedAt: '2023-10-26T13:22:12.692Z',
|
|
139
|
-
sections: [
|
|
140
|
-
{
|
|
141
|
-
_key: '44540ccd70c3',
|
|
142
|
-
_type: 'hero',
|
|
143
|
-
headline: 'Touch of Texture 1',
|
|
144
|
-
style: {
|
|
145
|
-
_type: 'sectionStyle',
|
|
146
|
-
variant: 'default',
|
|
147
|
-
},
|
|
148
|
-
subline: 'You can follow us on Twitter, Twitch, LinkedIn, and GitHub.',
|
|
149
|
-
tagline: 'ACME’s elegant construction is both minimal and inviting.',
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
title: 'Home',
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const optimisticResult = applySourceDocuments(result, resultSourceMap, (sourceDocument) =>
|
|
156
|
-
sourceDocument._id === draft._id ? draft : undefined,
|
|
157
|
-
)
|
|
158
|
-
expect(result.page.sections[0].headline).not.toBe(draft.sections[0].headline)
|
|
159
|
-
expect(optimisticResult.page.sections[0].headline).toBe(draft.sections[0].headline)
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
describe('simple queries', () => {
|
|
164
|
-
const result = [
|
|
165
|
-
{
|
|
166
|
-
title: ' Lunar Glide: Moon 🌙 Walking Sneaker 👟',
|
|
167
|
-
slug: {
|
|
168
|
-
current: 'lunar-glide-moon-walking-sneakers',
|
|
169
|
-
_type: 'slug',
|
|
170
|
-
},
|
|
171
|
-
price: '600',
|
|
172
|
-
media: {
|
|
173
|
-
alt: '',
|
|
174
|
-
asset: {
|
|
175
|
-
_type: 'reference',
|
|
176
|
-
_ref: 'image-6b34db59881e9566f3dd0be25e3059c15f145ea1-5000x4000-jpg',
|
|
177
|
-
},
|
|
178
|
-
crop: null,
|
|
179
|
-
hotspot: null,
|
|
180
|
-
},
|
|
181
|
-
brand: null,
|
|
182
|
-
},
|
|
183
|
-
]
|
|
184
|
-
const resultSourceMap = {
|
|
185
|
-
documents: [
|
|
186
|
-
{
|
|
187
|
-
_id: 'drafts.04eee032-4e79-4691-ba8d-23d403404462',
|
|
188
|
-
_type: 'shoe',
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
paths: [
|
|
192
|
-
"$['slug']",
|
|
193
|
-
"$['price']",
|
|
194
|
-
"$['media'][?(@._key=='a5ecdafbbf23')]['alt']",
|
|
195
|
-
"$['media'][?(@._key=='a5ecdafbbf23')]['asset']",
|
|
196
|
-
"$['title']",
|
|
197
|
-
],
|
|
198
|
-
mappings: {
|
|
199
|
-
"$[0]['media']['alt']": {
|
|
200
|
-
source: {
|
|
201
|
-
document: 0,
|
|
202
|
-
path: 2,
|
|
203
|
-
type: 'documentValue',
|
|
204
|
-
},
|
|
205
|
-
type: 'value',
|
|
206
|
-
},
|
|
207
|
-
"$[0]['media']['asset']": {
|
|
208
|
-
source: {
|
|
209
|
-
document: 0,
|
|
210
|
-
path: 3,
|
|
211
|
-
type: 'documentValue',
|
|
212
|
-
},
|
|
213
|
-
type: 'value',
|
|
214
|
-
},
|
|
215
|
-
"$[0]['price']": {
|
|
216
|
-
source: {
|
|
217
|
-
document: 0,
|
|
218
|
-
path: 1,
|
|
219
|
-
type: 'documentValue',
|
|
220
|
-
},
|
|
221
|
-
type: 'value',
|
|
222
|
-
},
|
|
223
|
-
"$[0]['slug']": {
|
|
224
|
-
source: {
|
|
225
|
-
document: 0,
|
|
226
|
-
path: 0,
|
|
227
|
-
type: 'documentValue',
|
|
228
|
-
},
|
|
229
|
-
type: 'value',
|
|
230
|
-
},
|
|
231
|
-
"$[0]['title']": {
|
|
232
|
-
source: {
|
|
233
|
-
document: 0,
|
|
234
|
-
path: 4,
|
|
235
|
-
type: 'documentValue',
|
|
236
|
-
},
|
|
237
|
-
type: 'value',
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
} satisfies ContentSourceMap
|
|
241
|
-
// In this draft the headline "Touch of Texture 1" is changed
|
|
242
|
-
const draft = {
|
|
243
|
-
_createdAt: '2023-10-24T22:32:10Z',
|
|
244
|
-
_id: 'drafts.04eee032-4e79-4691-ba8d-23d403404462',
|
|
245
|
-
_rev: '353f9340-5242-472a-ace2-9ed3b35b697d',
|
|
246
|
-
_type: 'shoe',
|
|
247
|
-
_updatedAt: '2023-11-06T15:21:18Z',
|
|
248
|
-
description: [
|
|
249
|
-
{
|
|
250
|
-
_key: '9e13c355c001',
|
|
251
|
-
_type: 'block',
|
|
252
|
-
children: [
|
|
253
|
-
{
|
|
254
|
-
_key: '45922d4ac846',
|
|
255
|
-
_type: 'span',
|
|
256
|
-
marks: [],
|
|
257
|
-
text: 'Step into the future with our Lunar Glide sneakers. Inspired by the concept of moon walking, these boots are designed to give you an out-of-this-world experience.',
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
markDefs: [],
|
|
261
|
-
style: 'normal',
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
_key: '8edf13f0aa44',
|
|
265
|
-
_type: 'block',
|
|
266
|
-
children: [
|
|
267
|
-
{
|
|
268
|
-
_key: 'e4f37de2e480',
|
|
269
|
-
_type: 'span',
|
|
270
|
-
marks: [],
|
|
271
|
-
text: "With a unique design that mimics the moon's surface, you'll feel like you're walking on air. Perfect for those who dare to dream and reach for the stars.",
|
|
272
|
-
},
|
|
273
|
-
],
|
|
274
|
-
markDefs: [],
|
|
275
|
-
style: 'normal',
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
_key: '83b0a0effe85',
|
|
279
|
-
_type: 'block',
|
|
280
|
-
children: [
|
|
281
|
-
{
|
|
282
|
-
_key: '1cca2a19e6d4',
|
|
283
|
-
_type: 'span',
|
|
284
|
-
marks: [],
|
|
285
|
-
text: 'lorem ipsum dolor ',
|
|
286
|
-
},
|
|
287
|
-
],
|
|
288
|
-
markDefs: [],
|
|
289
|
-
style: 'normal',
|
|
290
|
-
},
|
|
291
|
-
],
|
|
292
|
-
media: [
|
|
293
|
-
{
|
|
294
|
-
_key: 'a5ecdafbbf23',
|
|
295
|
-
_type: 'image',
|
|
296
|
-
alt: 'a pair of white fila shoes on a white surface',
|
|
297
|
-
asset: {
|
|
298
|
-
_ref: 'image-6b34db59881e9566f3dd0be25e3059c15f145ea1-5000x4000-jpg',
|
|
299
|
-
_type: 'reference',
|
|
300
|
-
},
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
_key: 'de42470a6d7e',
|
|
304
|
-
_type: 'image',
|
|
305
|
-
alt: 'a pair of red and white puma shoes on a white background',
|
|
306
|
-
asset: {
|
|
307
|
-
_ref: 'image-30b82c6709c0f21268b679126abea51953ee95e0-2000x2000-png',
|
|
308
|
-
_type: 'reference',
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
_key: '03062ec8c1df',
|
|
313
|
-
_type: 'image',
|
|
314
|
-
alt: 'red ish?',
|
|
315
|
-
asset: {
|
|
316
|
-
_ref: 'image-50ec4c0aa413c05ee616897bb4d7e53da9300851-6240x4160-jpg',
|
|
317
|
-
_type: 'reference',
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
_key: 'aa9ce9dbb69e',
|
|
322
|
-
_type: 'image',
|
|
323
|
-
alt: 'a pair of blue and white puma sneakers on a white background',
|
|
324
|
-
asset: {
|
|
325
|
-
_ref: 'image-3cbcebadb37df62978382532f4962bd4b383dc42-2000x2000-png',
|
|
326
|
-
_type: 'reference',
|
|
327
|
-
},
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
_key: 'fdda03417578',
|
|
331
|
-
_type: 'image',
|
|
332
|
-
alt: 'a pair of blue and white puma shoes on a white background',
|
|
333
|
-
asset: {
|
|
334
|
-
_ref: 'image-bf41fd175948f64963bdb36e24919d06cf252c5a-2000x2000-png',
|
|
335
|
-
_type: 'reference',
|
|
336
|
-
},
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
_key: '5eaeda579ff0',
|
|
340
|
-
_type: 'image',
|
|
341
|
-
alt: 'a pair of white and yellow nike running shoes',
|
|
342
|
-
asset: {
|
|
343
|
-
_ref: 'image-d4ec5719e0ff4b353622fcd19bc9cec26cb981a2-1728x2160-png',
|
|
344
|
-
_type: 'reference',
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
_key: 'f818bf37e73c',
|
|
349
|
-
_type: 'image',
|
|
350
|
-
alt: 'a pair of black nike running shoes on a white background',
|
|
351
|
-
asset: {
|
|
352
|
-
_ref: 'image-c8c55ac00c66668813e42c3a65453c0b18651314-1728x2160-png',
|
|
353
|
-
_type: 'reference',
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
_key: '84b5a348eee4',
|
|
358
|
-
_type: 'image',
|
|
359
|
-
alt: 'a red nike shoe is on a red background',
|
|
360
|
-
asset: {
|
|
361
|
-
_ref: 'image-99b15b86bf42103d24e7f43daf824bc64f399529-5472x3648-jpg',
|
|
362
|
-
_type: 'reference',
|
|
363
|
-
},
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
_key: 'ecad6c0bb52e',
|
|
367
|
-
_type: 'image',
|
|
368
|
-
alt: 'a pair of blue and white nike air jordans with orange laces',
|
|
369
|
-
asset: {
|
|
370
|
-
_ref: 'image-4ee918f4acbd9abfa147bae7c3121a01ffae6b02-3127x4690-jpg',
|
|
371
|
-
_type: 'reference',
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
{
|
|
375
|
-
_key: 'f3717ed670bf',
|
|
376
|
-
_type: 'image',
|
|
377
|
-
alt: 'ok',
|
|
378
|
-
asset: {
|
|
379
|
-
_ref: 'image-d9c1d238064120a8c439e922f1e4778cf31b27c1-7016x4960-jpg',
|
|
380
|
-
_type: 'reference',
|
|
381
|
-
},
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
_key: '4b2070d8b664',
|
|
385
|
-
_type: 'image',
|
|
386
|
-
alt: 'a pair of neon yellow nike shoes on a green background',
|
|
387
|
-
asset: {
|
|
388
|
-
_ref: 'image-fdcd7baa37dbf04de62626b2549a0b60964f67a0-2400x3000-jpg',
|
|
389
|
-
_type: 'reference',
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
],
|
|
393
|
-
price: 600,
|
|
394
|
-
slug: {
|
|
395
|
-
_type: 'slug',
|
|
396
|
-
current: 'lunar-glide-moon-walking-sneakers',
|
|
397
|
-
},
|
|
398
|
-
title: 'Moon shoes!',
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
test('Can apply an array keyed field update', () => {
|
|
402
|
-
const optimisticResult = applySourceDocuments(result, resultSourceMap, (sourceDocument) =>
|
|
403
|
-
sourceDocument._id === draft._id ? draft : undefined,
|
|
404
|
-
)
|
|
405
|
-
expect(result[0].title).not.toBe(draft.title)
|
|
406
|
-
expect(optimisticResult[0].title).toBe(draft.title)
|
|
407
|
-
expect(result[0].media.alt).not.toBe(draft.media[0].alt)
|
|
408
|
-
expect(optimisticResult[0].media.alt).toBe(draft.media[0].alt)
|
|
409
|
-
})
|
|
410
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {expect, test} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {createEditUrl} from './createEditUrl'
|
|
4
|
-
import {parseJsonPath} from './jsonPath'
|
|
5
|
-
|
|
6
|
-
const baseUrl = 'https://test.sanity.studio'
|
|
7
|
-
const projectId = 'abc123'
|
|
8
|
-
const dataset = 'production'
|
|
9
|
-
const workspace = 'staging'
|
|
10
|
-
const tool = 'content'
|
|
11
|
-
const id = 'drafts.homepage'
|
|
12
|
-
const type = 'page'
|
|
13
|
-
|
|
14
|
-
const cases = [
|
|
15
|
-
{
|
|
16
|
-
context: {baseUrl, workspace, tool, id, type},
|
|
17
|
-
path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]['baz'][?(@._key=='section-2')]"),
|
|
18
|
-
expected:
|
|
19
|
-
'https://test.sanity.studio/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0].baz[_key=="section-2"]?baseUrl=https://test.sanity.studio&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0].baz[_key=="section-2"]&workspace=staging&tool=content',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
context: {baseUrl: '/', id, type},
|
|
23
|
-
path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"),
|
|
24
|
-
expected:
|
|
25
|
-
'/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0]',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
context: {baseUrl: '/', workspace, tool, id, type},
|
|
29
|
-
path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"),
|
|
30
|
-
expected:
|
|
31
|
-
'/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0]&workspace=staging&tool=content',
|
|
32
|
-
},
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
test.each(cases)('$expected', ({context, path, expected}) => {
|
|
36
|
-
expect(decodeURIComponent(createEditUrl({projectId, dataset, ...context, path}))).toEqual(
|
|
37
|
-
expected,
|
|
38
|
-
)
|
|
39
|
-
})
|
package/src/csm/jsonPath.test.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {expect, test} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import {jsonPath, jsonPathToStudioPath, parseJsonPath} from './jsonPath'
|
|
4
|
-
|
|
5
|
-
test('formats normalised JSON Paths', () => {
|
|
6
|
-
expect(jsonPath(['foo', 'bar', 0, 'baz'])).toBe("$['foo']['bar'][0]['baz']")
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
test('formats normalised JSON Paths with escaped characters', () => {
|
|
10
|
-
expect(jsonPath(['foo', 'bar', 0, 'baz', "it's a 'test'"])).toBe(
|
|
11
|
-
"$['foo']['bar'][0]['baz']['it\\'s a \\'test\\'']",
|
|
12
|
-
)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('parses normalised JSON Paths', () => {
|
|
16
|
-
expect(parseJsonPath("$['foo']['bar'][0]['baz']")).toEqual(['foo', 'bar', 0, 'baz'])
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('parses normalised JSON Paths with escaped characters', () => {
|
|
20
|
-
expect(parseJsonPath("$['foo']['bar'][0]['baz']['it\\'s a \\'test\\'']")).toEqual([
|
|
21
|
-
'foo',
|
|
22
|
-
'bar',
|
|
23
|
-
0,
|
|
24
|
-
'baz',
|
|
25
|
-
"it's a 'test'",
|
|
26
|
-
])
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
test('parses normalised JSON Paths with key array filter selectors', () => {
|
|
30
|
-
expect(
|
|
31
|
-
parseJsonPath("$['foo'][?(@._key=='section-1')][0]['baz'][?(@._key=='section-2')]"),
|
|
32
|
-
).toEqual(['foo', {_key: 'section-1', _index: -1}, 0, 'baz', {_key: 'section-2', _index: -1}])
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('translates a json path to a studio path', () => {
|
|
36
|
-
expect(
|
|
37
|
-
jsonPathToStudioPath(['foo', {_key: 'section-1', _index: -1}, 0, 'baz', {_key: '', _index: 2}]),
|
|
38
|
-
).toEqual(['foo', {_key: 'section-1'}, 0, 'baz', 2])
|
|
39
|
-
})
|