@sanity/sdk 2.18.0 → 2.20.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/dist/_exports/_internal.d.ts +2 -2
- package/dist/_exports/_internal.d.ts.map +1 -1
- package/dist/_exports/_internal.js +196 -22
- package/dist/_exports/_internal.js.map +1 -1
- package/dist/authStore-CWTAuieY.js +1072 -0
- package/dist/authStore-CWTAuieY.js.map +1 -0
- package/dist/clientStore-CMzJ7XhZ.js +168 -0
- package/dist/clientStore-CMzJ7XhZ.js.map +1 -0
- package/dist/createGroqSearchFilter-B0NdA-EP.js +1222 -0
- package/dist/createGroqSearchFilter-B0NdA-EP.js.map +1 -0
- package/dist/getEnv-76AjZd_f.js +178 -0
- package/dist/getEnv-76AjZd_f.js.map +1 -0
- package/dist/index.d.ts +2 -1921
- package/dist/index.js +4165 -3711
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/telemetryManager-Bd3O8z2S.js +127 -0
- package/dist/telemetryManager-Bd3O8z2S.js.map +1 -0
- package/dist/utils-BMwA8Kg9.d.ts +3334 -0
- package/dist/utils-BMwA8Kg9.d.ts.map +1 -0
- package/dist/version-DL2l07HG.js +9 -0
- package/dist/version-DL2l07HG.js.map +1 -0
- package/package.json +13 -21
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/index.ts +37 -1
- package/src/comments/addonDatasetStore.test.ts +215 -0
- package/src/comments/addonDatasetStore.ts +249 -0
- package/src/comments/buildCommentThreads.test.ts +83 -0
- package/src/comments/buildCommentThreads.ts +54 -0
- package/src/comments/commentActions.test.ts +540 -0
- package/src/comments/commentActions.ts +555 -0
- package/src/comments/commentFieldPath.test.ts +40 -0
- package/src/comments/commentFieldPath.ts +44 -0
- package/src/comments/commentsConstants.ts +80 -0
- package/src/comments/commentsStore.test.ts +419 -0
- package/src/comments/commentsStore.ts +483 -0
- package/src/comments/normalizeComment.test.ts +116 -0
- package/src/comments/normalizeComment.ts +45 -0
- package/src/comments/observeComments.test.ts +193 -0
- package/src/comments/observeComments.ts +113 -0
- package/src/comments/reducers.test.ts +277 -0
- package/src/comments/reducers.ts +316 -0
- package/src/comments/types.ts +249 -0
- package/src/comments/weakenReferences.test.ts +47 -0
- package/src/comments/weakenReferences.ts +29 -0
- package/src/document/documentConstants.ts +8 -0
- package/src/document/documentStore.concurrency.test.ts +313 -22
- package/src/document/documentStore.test.ts +98 -1
- package/src/document/documentStore.ts +36 -5
- package/src/document/patchOperations.test.ts +27 -0
- package/src/document/patchOperations.ts +10 -1
- package/src/document/permissions.test.ts +3 -1
- package/src/document/reducers.test.ts +133 -0
- package/src/document/reducers.ts +18 -3
- package/src/document/util.test.ts +46 -0
- package/src/document/util.ts +37 -1
- package/src/presence/bifurTransport.test.ts +155 -3
- package/src/presence/bifurTransport.ts +79 -12
- package/src/presence/paths.test.ts +70 -0
- package/src/presence/paths.ts +41 -0
- package/src/presence/presenceStore.test.ts +822 -2
- package/src/presence/presenceStore.ts +518 -102
- package/src/presence/types.ts +175 -3
- package/src/projection/projectionStore.test.ts +0 -8
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts +0 -926
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +0 -1
- package/dist/_chunks-es/_internal.js +0 -133
- package/dist/_chunks-es/_internal.js.map +0 -1
- package/dist/_chunks-es/createGroqSearchFilter.js +0 -1586
- package/dist/_chunks-es/createGroqSearchFilter.js.map +0 -1
- package/dist/_chunks-es/telemetryManager.js +0 -93
- package/dist/_chunks-es/telemetryManager.js.map +0 -1
- package/dist/_chunks-es/version.js +0 -7
- package/dist/_chunks-es/version.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {type Path} from '@sanity/types'
|
|
2
|
+
import {describe, expect, it} from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {startsWithPath} from './paths'
|
|
5
|
+
|
|
6
|
+
describe('startsWithPath', () => {
|
|
7
|
+
it('treats the empty path as a prefix of everything, which is the document root', () => {
|
|
8
|
+
expect(startsWithPath([], ['title'])).toBe(true)
|
|
9
|
+
expect(startsWithPath([], [])).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('matches a path against itself', () => {
|
|
13
|
+
expect(startsWithPath(['title'], ['title'])).toBe(true)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('matches a descendant', () => {
|
|
17
|
+
expect(startsWithPath(['body'], ['body', 'children'])).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('does not match an ancestor, since a longer prefix cannot fit', () => {
|
|
21
|
+
expect(startsWithPath(['body', 'children'], ['body'])).toBe(false)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('does not match a sibling', () => {
|
|
25
|
+
expect(startsWithPath(['title'], ['subtitle'])).toBe(false)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('does not match a partial segment name', () => {
|
|
29
|
+
// `title` must not be treated as a prefix of `titleImage`.
|
|
30
|
+
expect(startsWithPath(['title'], ['titleImage'])).toBe(false)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('compares keyed segments by key rather than by identity', () => {
|
|
34
|
+
// Distinct objects with the same key, which is what arrives over the wire.
|
|
35
|
+
expect(startsWithPath(['cast', {_key: 'a'}], ['cast', {_key: 'a'}, 'name'])).toBe(true)
|
|
36
|
+
expect(startsWithPath(['cast', {_key: 'a'}], ['cast', {_key: 'b'}, 'name'])).toBe(false)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('does not confuse a keyed segment with a string or a number', () => {
|
|
40
|
+
expect(startsWithPath([{_key: 'a'}], ['a'])).toBe(false)
|
|
41
|
+
expect(startsWithPath(['a'], [{_key: 'a'}])).toBe(false)
|
|
42
|
+
expect(startsWithPath([{_key: '0'}], [0])).toBe(false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('compares numeric indexes', () => {
|
|
46
|
+
expect(startsWithPath(['awards', 0], ['awards', 0])).toBe(true)
|
|
47
|
+
expect(startsWithPath(['awards', 0], ['awards', 1])).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('compares index tuples structurally', () => {
|
|
51
|
+
const prefix: Path = ['body', [0, 2]]
|
|
52
|
+
expect(startsWithPath(prefix, ['body', [0, 2], 'children'])).toBe(true)
|
|
53
|
+
expect(startsWithPath(prefix, ['body', [0, 3]])).toBe(false)
|
|
54
|
+
expect(startsWithPath(prefix, ['body', [0, '']])).toBe(false)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('does not confuse a tuple with a keyed segment', () => {
|
|
58
|
+
expect(startsWithPath([[0, 2]], [{_key: 'a'}])).toBe(false)
|
|
59
|
+
expect(startsWithPath([{_key: 'a'}], [[0, 2]])).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('handles a realistic Portable Text span path', () => {
|
|
63
|
+
const field: Path = ['body']
|
|
64
|
+
const span: Path = ['body', {_key: 'block-1'}, 'children', {_key: 'span-1'}, 'text']
|
|
65
|
+
|
|
66
|
+
expect(startsWithPath(field, span)).toBe(true)
|
|
67
|
+
expect(startsWithPath(['title'], span)).toBe(false)
|
|
68
|
+
expect(startsWithPath(['body', {_key: 'block-2'}], span)).toBe(false)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {type IndexTuple, type KeyedSegment, type Path, type PathSegment} from '@sanity/types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Segments are not always strings, despite what `PresenceLocation.path` declares.
|
|
5
|
+
* Array items arrive as `{_key}` and Portable Text spans as a mix of keys and
|
|
6
|
+
* property names, because that is what the Studio sends.
|
|
7
|
+
*/
|
|
8
|
+
function isKeyedSegment(segment: PathSegment): segment is KeyedSegment {
|
|
9
|
+
return (
|
|
10
|
+
typeof segment === 'object' && segment !== null && !Array.isArray(segment) && '_key' in segment
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Index tuples (`[from, to]`) only occur in slice selections, which presence never
|
|
16
|
+
* reports. Compared structurally rather than assumed absent.
|
|
17
|
+
*/
|
|
18
|
+
function isEqualTuple(a: IndexTuple, b: IndexTuple): boolean {
|
|
19
|
+
return a.length === b.length && a.every((value, index) => value === b[index])
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Compares two path segments, whatever shape they arrive in. */
|
|
23
|
+
function isEqualSegment(a: PathSegment, b: PathSegment): boolean {
|
|
24
|
+
if (a === b) return true
|
|
25
|
+
if (isKeyedSegment(a) && isKeyedSegment(b)) return a._key === b._key
|
|
26
|
+
if (Array.isArray(a) && Array.isArray(b)) return isEqualTuple(a, b)
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* True when `candidate` is at or below `prefix` in the document tree.
|
|
32
|
+
*
|
|
33
|
+
* Equivalent to `startsWith` from the Studio's `@sanity/util/paths`, which is not
|
|
34
|
+
* an SDK dependency.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export function startsWithPath(prefix: Path, candidate: Path): boolean {
|
|
39
|
+
if (prefix.length > candidate.length) return false
|
|
40
|
+
return prefix.every((segment, index) => isEqualSegment(segment, candidate[index]))
|
|
41
|
+
}
|