@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,237 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {describe, expect, test} from 'vitest'
|
|
3
|
-
|
|
4
|
-
import {jsonPathToStudioPath} from './jsonPath'
|
|
5
|
-
import {fromString, get, toString} from './studioPath'
|
|
6
|
-
import {ContentSourceMapParsedPath} from './types'
|
|
7
|
-
|
|
8
|
-
const srcObject = {
|
|
9
|
-
title: 'Hei',
|
|
10
|
-
nested: {'0': 'Zero-Key'},
|
|
11
|
-
nullVal: null,
|
|
12
|
-
body: [
|
|
13
|
-
{_key: 'foo', title: 'Foo'},
|
|
14
|
-
{_key: 'bar', children: [{_key: 'child1', text: 'Heisann'}]},
|
|
15
|
-
],
|
|
16
|
-
multiDimensional: [
|
|
17
|
-
[[{_key: 'abc', title: 'hai'}], [{_key: 'def', title: 'def'}]],
|
|
18
|
-
[
|
|
19
|
-
[13, 14],
|
|
20
|
-
[15, 16],
|
|
21
|
-
],
|
|
22
|
-
],
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe('fromString', () => {
|
|
26
|
-
test('throws if not a string', () => {
|
|
27
|
-
// @ts-expect-error
|
|
28
|
-
expect(() => fromString()).toThrow('Path is not a string')
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
expect(() => fromString(13)).toThrow('Path is not a string')
|
|
31
|
-
|
|
32
|
-
expect(() => fromString(null as any)).toThrow('Path is not a string')
|
|
33
|
-
// @ts-expect-error
|
|
34
|
-
expect(() => fromString(false)).toThrow('Path is not a string')
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
test('handles plain property segments', () => {
|
|
38
|
-
expect(fromString('foo')).toEqual(['foo'])
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
test('handles index segments', () => {
|
|
42
|
-
expect(fromString('[0]')).toEqual([0])
|
|
43
|
-
expect(fromString('[1337]')).toEqual([1337])
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
test('handles key segments', () => {
|
|
47
|
-
expect(fromString('[_key == "foo"]')).toEqual([{_key: 'foo'}])
|
|
48
|
-
expect(fromString("[ _key== 'B4z']")).toEqual([{_key: 'B4z'}])
|
|
49
|
-
expect(fromString('[_key=="bar"]')).toEqual([{_key: 'bar'}])
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test('handles deep prop segments', () => {
|
|
53
|
-
expect(fromString('foo.bar')).toEqual(['foo', 'bar'])
|
|
54
|
-
expect(fromString('bar.foo')).toEqual(['bar', 'foo'])
|
|
55
|
-
expect(fromString('bar.foo.baz')).toEqual(['bar', 'foo', 'baz'])
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
test('handles deep array index segments', () => {
|
|
59
|
-
expect(fromString('foo[13]')).toEqual(['foo', 13])
|
|
60
|
-
expect(fromString('bar.foo[3]')).toEqual(['bar', 'foo', 3])
|
|
61
|
-
expect(fromString('[3][18]')).toEqual([3, 18])
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
test('handles deep key segments', () => {
|
|
65
|
-
expect(fromString('foo[_key=="bar"].body[_key=="13ch"')).toEqual([
|
|
66
|
-
'foo',
|
|
67
|
-
{_key: 'bar'},
|
|
68
|
-
'body',
|
|
69
|
-
{_key: '13ch'},
|
|
70
|
-
])
|
|
71
|
-
expect(fromString('bar.foo[3][_key == "seg"]')).toEqual(['bar', 'foo', 3, {_key: 'seg'}])
|
|
72
|
-
expect(fromString('[_key=="foo"][_key== "bar"][_key =="baz"][ _key == "seg" ')).toEqual([
|
|
73
|
-
{_key: 'foo'},
|
|
74
|
-
{_key: 'bar'},
|
|
75
|
-
{_key: 'baz'},
|
|
76
|
-
{_key: 'seg'},
|
|
77
|
-
])
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe('toString', () => {
|
|
82
|
-
test('throws if not an array', () => {
|
|
83
|
-
// @ts-expect-error
|
|
84
|
-
expect(() => toString()).toThrow('Path is not an array')
|
|
85
|
-
|
|
86
|
-
expect(() => toString(13 as any)).toThrow('Path is not an array')
|
|
87
|
-
|
|
88
|
-
expect(() => toString(null as any)).toThrow('Path is not an array')
|
|
89
|
-
expect(() => toString(false as any)).toThrow('Path is not an array')
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
test('handles plain property segments', () => {
|
|
93
|
-
expect(toString(['foo'])).toEqual('foo')
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
test('handles index segments', () => {
|
|
97
|
-
expect(toString([0])).toEqual('[0]')
|
|
98
|
-
expect(toString([1337])).toEqual('[1337]')
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
test('handles key segments', () => {
|
|
102
|
-
expect(toString([{_key: 'foo'}])).toEqual('[_key=="foo"]')
|
|
103
|
-
expect(toString([{_key: 'B4z'}])).toEqual('[_key=="B4z"]')
|
|
104
|
-
expect(toString([{_key: 'bar'}])).toEqual('[_key=="bar"]')
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
test('handles deep prop segments', () => {
|
|
108
|
-
expect(toString(['foo', 'bar'])).toEqual('foo.bar')
|
|
109
|
-
expect(toString(['bar', 'foo'])).toEqual('bar.foo')
|
|
110
|
-
expect(toString(['bar', 'foo', 'baz'])).toEqual('bar.foo.baz')
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
test('handles deep array index segments', () => {
|
|
114
|
-
expect(toString(['foo', 13])).toEqual('foo[13]')
|
|
115
|
-
expect(toString(['bar', 'foo', 3])).toEqual('bar.foo[3]')
|
|
116
|
-
expect(toString([3, 18])).toEqual('[3][18]')
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
test('handles deep key segments', () => {
|
|
120
|
-
expect(toString(['foo', {_key: 'bar'}, 'body', {_key: '13ch'}])).toEqual(
|
|
121
|
-
'foo[_key=="bar"].body[_key=="13ch"]',
|
|
122
|
-
)
|
|
123
|
-
expect(toString(['bar', 'foo', 3, {_key: 'seg'}])).toEqual('bar.foo[3][_key=="seg"]')
|
|
124
|
-
expect(toString([{_key: 'foo'}, {_key: 'bar'}, {_key: 'baz'}, {_key: 'seg'}])).toEqual(
|
|
125
|
-
'[_key=="foo"][_key=="bar"][_key=="baz"][_key=="seg"]',
|
|
126
|
-
)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
test('throws on unrecognized segment types', () => {
|
|
130
|
-
expect(() => toString([{foo: 'bar'} as any])).toThrow(
|
|
131
|
-
'Unsupported path segment `{"foo":"bar"}`',
|
|
132
|
-
)
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
describe('get', () => {
|
|
137
|
-
test('throws on non-array/non-string path', () => {
|
|
138
|
-
expect(() => get(srcObject, null as any)).toThrow('Path must be an array or a string')
|
|
139
|
-
expect(() => get(srcObject, 13 as any)).toThrow('Path must be an array or a string')
|
|
140
|
-
expect(() => get(srcObject, false as any)).toThrow('Path must be an array or a string')
|
|
141
|
-
expect(() => get(srcObject, true as any)).toThrow('Path must be an array or a string')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('can get simple props', () => {
|
|
145
|
-
expect(get(srcObject, 'title')).toEqual(srcObject.title)
|
|
146
|
-
expect(get(srcObject, ['title'])).toEqual(srcObject.title)
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
test('can pass default value', () => {
|
|
150
|
-
const defaultVal = Math.random()
|
|
151
|
-
expect(get(srcObject, 'notSet', defaultVal)).toEqual(defaultVal)
|
|
152
|
-
expect(get(srcObject, ['notSet'], defaultVal)).toEqual(defaultVal)
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
test('can use array indexes', () => {
|
|
156
|
-
expect(get(srcObject, ['body', 0])).toEqual(srcObject.body[0])
|
|
157
|
-
expect(get(srcObject, ['body', 1, 'children', 0])).toEqual(srcObject.body[1].children![0])
|
|
158
|
-
expect(get(srcObject, ['multiDimensional', 1, 1])).toEqual(srcObject.multiDimensional[1][1])
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
test('can use key lookup', () => {
|
|
162
|
-
expect(get(srcObject, ['body', {_key: 'bar'}])).toEqual(srcObject.body[1])
|
|
163
|
-
expect(get(srcObject, ['body', {_key: 'bar'}, 'children', {_key: 'child1'}])).toEqual(
|
|
164
|
-
srcObject.body[1].children![0],
|
|
165
|
-
)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test('falls back to default value on array index at non-array', () => {
|
|
169
|
-
const defaultVal = {}
|
|
170
|
-
expect(get(srcObject, ['title', 1], defaultVal)).toEqual(defaultVal)
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
test('falls back to default value on property lookup at non-object', () => {
|
|
174
|
-
const defaultVal = {}
|
|
175
|
-
expect(get(srcObject, ['title', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
176
|
-
expect(get(srcObject, ['multiDimensional', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
177
|
-
expect(get(srcObject, ['nullVal', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
test('falls back to default value on key lookup at non-array', () => {
|
|
181
|
-
const defaultVal = {}
|
|
182
|
-
expect(get(srcObject, ['nullVal', {_key: 'abc'}], defaultVal)).toEqual(defaultVal)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
test('can get numbered key from object', () => {
|
|
186
|
-
expect(get(srcObject, 'nested.0')).toEqual('Zero-Key')
|
|
187
|
-
expect(get(srcObject, ['nested', '0'])).toEqual('Zero-Key')
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
describe('get + jsonpath', () => {
|
|
192
|
-
const tget = (obj: unknown, path: ContentSourceMapParsedPath, defaultValue?: unknown) =>
|
|
193
|
-
get(obj, jsonPathToStudioPath(path), defaultValue)
|
|
194
|
-
test('can pass default value', () => {
|
|
195
|
-
const defaultVal = Math.random()
|
|
196
|
-
expect(tget(srcObject, ['notSet'], defaultVal)).toEqual(defaultVal)
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
test('can use array indexes', () => {
|
|
200
|
-
expect(tget(srcObject, ['body', 0])).toEqual(srcObject.body[0])
|
|
201
|
-
expect(tget(srcObject, ['body', 1, 'children', 0])).toEqual(srcObject.body[1].children![0])
|
|
202
|
-
expect(tget(srcObject, ['multiDimensional', 1, 1])).toEqual(srcObject.multiDimensional[1][1])
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
test('can use key lookup', () => {
|
|
206
|
-
expect(tget(srcObject, ['body', {_key: 'bar', _index: -1}])).toEqual(srcObject.body[1])
|
|
207
|
-
expect(
|
|
208
|
-
tget(srcObject, [
|
|
209
|
-
'body',
|
|
210
|
-
{_key: 'bar', _index: -1},
|
|
211
|
-
'children',
|
|
212
|
-
{_key: 'child1', _index: -1},
|
|
213
|
-
]),
|
|
214
|
-
).toEqual(srcObject.body[1].children![0])
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
test('falls back to default value on array index at non-array', () => {
|
|
218
|
-
const defaultVal = {}
|
|
219
|
-
expect(tget(srcObject, ['title', 1], defaultVal)).toEqual(defaultVal)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
test('falls back to default value on property lookup at non-object', () => {
|
|
223
|
-
const defaultVal = {}
|
|
224
|
-
expect(tget(srcObject, ['title', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
225
|
-
expect(tget(srcObject, ['multiDimensional', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
226
|
-
expect(tget(srcObject, ['nullVal', 'bar'], defaultVal)).toEqual(defaultVal)
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
test('falls back to default value on key lookup at non-array', () => {
|
|
230
|
-
const defaultVal = {}
|
|
231
|
-
expect(tget(srcObject, ['nullVal', {_key: 'abc', _index: -1}], defaultVal)).toEqual(defaultVal)
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
test('can get numbered key from object', () => {
|
|
235
|
-
expect(tget(srcObject, ['nested', '0'])).toEqual('Zero-Key')
|
|
236
|
-
})
|
|
237
|
-
})
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import {expect, test, vi} from 'vitest'
|
|
2
|
-
|
|
3
|
-
import type {ContentSourceMap} from '../types'
|
|
4
|
-
import {encodeIntoResult} from './encodeIntoResult'
|
|
5
|
-
|
|
6
|
-
const encodeTestCases: {
|
|
7
|
-
name: string
|
|
8
|
-
queryResult: {
|
|
9
|
-
result: unknown
|
|
10
|
-
resultSourceMap: ContentSourceMap
|
|
11
|
-
}
|
|
12
|
-
expected: {
|
|
13
|
-
encoderCalls: number
|
|
14
|
-
encoderArgs: unknown[][]
|
|
15
|
-
}
|
|
16
|
-
}[] = [
|
|
17
|
-
{
|
|
18
|
-
name: 'resolves exact mappings to source',
|
|
19
|
-
queryResult: {
|
|
20
|
-
result: [
|
|
21
|
-
{
|
|
22
|
-
_id: 'foo',
|
|
23
|
-
this: 'that',
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
resultSourceMap: {
|
|
27
|
-
documents: [
|
|
28
|
-
{
|
|
29
|
-
_id: 'foo',
|
|
30
|
-
_type: 'bar',
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
paths: ["$['this']"],
|
|
34
|
-
mappings: {
|
|
35
|
-
"$[0]['this']": {
|
|
36
|
-
source: {
|
|
37
|
-
document: 0,
|
|
38
|
-
path: 0,
|
|
39
|
-
type: 'documentValue',
|
|
40
|
-
},
|
|
41
|
-
type: 'value',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
expected: {
|
|
47
|
-
encoderCalls: 1,
|
|
48
|
-
encoderArgs: [
|
|
49
|
-
[
|
|
50
|
-
{
|
|
51
|
-
sourcePath: ['this'],
|
|
52
|
-
sourceDocument: {
|
|
53
|
-
_id: 'foo',
|
|
54
|
-
_type: 'bar',
|
|
55
|
-
},
|
|
56
|
-
resultPath: [0, 'this'],
|
|
57
|
-
value: 'that',
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: 'resolves aggregated mappings to source',
|
|
65
|
-
queryResult: {
|
|
66
|
-
result: [
|
|
67
|
-
{
|
|
68
|
-
_id: 'foo',
|
|
69
|
-
nested: {
|
|
70
|
-
object: {
|
|
71
|
-
this: 'that',
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
resultSourceMap: {
|
|
77
|
-
documents: [
|
|
78
|
-
{
|
|
79
|
-
_id: 'foo',
|
|
80
|
-
_type: 'bar',
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
paths: ["$['something']['nested']"],
|
|
84
|
-
mappings: {
|
|
85
|
-
"$[0]['nested']": {
|
|
86
|
-
source: {
|
|
87
|
-
document: 0,
|
|
88
|
-
path: 0,
|
|
89
|
-
type: 'documentValue',
|
|
90
|
-
},
|
|
91
|
-
type: 'value',
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
expected: {
|
|
97
|
-
encoderCalls: 1,
|
|
98
|
-
encoderArgs: [
|
|
99
|
-
[
|
|
100
|
-
{
|
|
101
|
-
sourcePath: ['something', 'nested', 'object', 'this'],
|
|
102
|
-
sourceDocument: {
|
|
103
|
-
_id: 'foo',
|
|
104
|
-
_type: 'bar',
|
|
105
|
-
},
|
|
106
|
-
resultPath: [0, 'nested', 'object', 'this'],
|
|
107
|
-
value: 'that',
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'plucks out _key to use as path segment',
|
|
115
|
-
queryResult: {
|
|
116
|
-
result: [
|
|
117
|
-
{
|
|
118
|
-
_id: 'foo',
|
|
119
|
-
nested: {
|
|
120
|
-
arr: [
|
|
121
|
-
{
|
|
122
|
-
_key: 'im_a_key',
|
|
123
|
-
value: 'that',
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
resultSourceMap: {
|
|
130
|
-
documents: [
|
|
131
|
-
{
|
|
132
|
-
_id: 'foo',
|
|
133
|
-
_type: 'bar',
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
paths: ["$['projected']['nested']"],
|
|
137
|
-
mappings: {
|
|
138
|
-
"$[0]['nested']": {
|
|
139
|
-
source: {
|
|
140
|
-
document: 0,
|
|
141
|
-
path: 0,
|
|
142
|
-
type: 'documentValue',
|
|
143
|
-
},
|
|
144
|
-
type: 'value',
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
expected: {
|
|
150
|
-
encoderCalls: 2,
|
|
151
|
-
encoderArgs: [
|
|
152
|
-
[
|
|
153
|
-
{
|
|
154
|
-
sourcePath: ['projected', 'nested', 'arr', {_key: 'im_a_key', _index: 0}, '_key'],
|
|
155
|
-
sourceDocument: {
|
|
156
|
-
_id: 'foo',
|
|
157
|
-
_type: 'bar',
|
|
158
|
-
},
|
|
159
|
-
resultPath: [0, 'nested', 'arr', {_key: 'im_a_key', _index: 0}, '_key'],
|
|
160
|
-
value: 'im_a_key',
|
|
161
|
-
},
|
|
162
|
-
],
|
|
163
|
-
[
|
|
164
|
-
{
|
|
165
|
-
sourcePath: ['projected', 'nested', 'arr', {_key: 'im_a_key', _index: 0}, 'value'],
|
|
166
|
-
sourceDocument: {
|
|
167
|
-
_id: 'foo',
|
|
168
|
-
_type: 'bar',
|
|
169
|
-
},
|
|
170
|
-
resultPath: [0, 'nested', 'arr', {_key: 'im_a_key', _index: 0}, 'value'],
|
|
171
|
-
value: 'that',
|
|
172
|
-
},
|
|
173
|
-
],
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
name: 'handles _key array filter selectors in source paths',
|
|
179
|
-
queryResult: {
|
|
180
|
-
result: [
|
|
181
|
-
{
|
|
182
|
-
_id: 'foo',
|
|
183
|
-
arr: [
|
|
184
|
-
{
|
|
185
|
-
_key: 'im_a_key',
|
|
186
|
-
value: 'that',
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
resultSourceMap: {
|
|
192
|
-
documents: [
|
|
193
|
-
{
|
|
194
|
-
_id: 'foo',
|
|
195
|
-
_type: 'bar',
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
paths: ["$['projected'][?(@._key=='fooKey')]"],
|
|
199
|
-
mappings: {
|
|
200
|
-
"$[0]['arr']": {
|
|
201
|
-
source: {
|
|
202
|
-
document: 0,
|
|
203
|
-
path: 0,
|
|
204
|
-
type: 'documentValue',
|
|
205
|
-
},
|
|
206
|
-
type: 'value',
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
expected: {
|
|
212
|
-
encoderCalls: 2,
|
|
213
|
-
encoderArgs: [
|
|
214
|
-
[
|
|
215
|
-
{
|
|
216
|
-
sourcePath: [
|
|
217
|
-
'projected',
|
|
218
|
-
{_key: 'fooKey', _index: -1},
|
|
219
|
-
{_key: 'im_a_key', _index: 0},
|
|
220
|
-
'_key',
|
|
221
|
-
],
|
|
222
|
-
sourceDocument: {
|
|
223
|
-
_id: 'foo',
|
|
224
|
-
_type: 'bar',
|
|
225
|
-
},
|
|
226
|
-
resultPath: [0, 'arr', {_key: 'im_a_key', _index: 0}, '_key'],
|
|
227
|
-
value: 'im_a_key',
|
|
228
|
-
},
|
|
229
|
-
],
|
|
230
|
-
[
|
|
231
|
-
{
|
|
232
|
-
sourcePath: [
|
|
233
|
-
'projected',
|
|
234
|
-
{_key: 'fooKey', _index: -1},
|
|
235
|
-
{_key: 'im_a_key', _index: 0},
|
|
236
|
-
'value',
|
|
237
|
-
],
|
|
238
|
-
sourceDocument: {
|
|
239
|
-
_id: 'foo',
|
|
240
|
-
_type: 'bar',
|
|
241
|
-
},
|
|
242
|
-
resultPath: [0, 'arr', {_key: 'im_a_key', _index: 0}, 'value'],
|
|
243
|
-
value: 'that',
|
|
244
|
-
},
|
|
245
|
-
],
|
|
246
|
-
],
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
]
|
|
250
|
-
|
|
251
|
-
test.each(encodeTestCases)('encode $name', ({queryResult, expected}) => {
|
|
252
|
-
const mockTranscoder = vi.fn().mockImplementation((input: string) => input)
|
|
253
|
-
encodeIntoResult(queryResult.result, queryResult.resultSourceMap, mockTranscoder)
|
|
254
|
-
|
|
255
|
-
expect(mockTranscoder).toBeCalledTimes(expected.encoderCalls)
|
|
256
|
-
for (const args of expected.encoderArgs) {
|
|
257
|
-
expect(mockTranscoder).toBeCalledWith(...args)
|
|
258
|
-
}
|
|
259
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {vercelStegaCombine} from '@vercel/stega'
|
|
2
|
-
import {expect, test} from 'vitest'
|
|
3
|
-
|
|
4
|
-
import {vercelStegaCleanAll} from './vercelStegaCleanAll'
|
|
5
|
-
|
|
6
|
-
test('it removes everything', () => {
|
|
7
|
-
const payload = {
|
|
8
|
-
foo: ['bar', 'baz'],
|
|
9
|
-
multistrings: 'multi stega embedded',
|
|
10
|
-
}
|
|
11
|
-
const encoded = JSON.parse(JSON.stringify(payload))
|
|
12
|
-
const editInfo = JSON.stringify({origin: 'sanity.io', href: '/studio'})
|
|
13
|
-
encoded.foo[0] = vercelStegaCombine(encoded.foo[0], editInfo)
|
|
14
|
-
encoded.foo[1] = vercelStegaCombine(encoded.foo[1], editInfo)
|
|
15
|
-
encoded.multistrings = [
|
|
16
|
-
vercelStegaCombine('multi', editInfo),
|
|
17
|
-
vercelStegaCombine('stega', editInfo),
|
|
18
|
-
vercelStegaCombine('embedded', editInfo),
|
|
19
|
-
].join(' ')
|
|
20
|
-
expect(vercelStegaCleanAll(encoded)).toEqual(payload)
|
|
21
|
-
})
|