@sanity/sdk 2.0.2 → 2.1.1-canary.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/index.d.ts +1493 -2180
- package/dist/index.js +25 -117
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/src/_exports/index.ts +9 -1
- package/src/document/documentStore.ts +7 -3
- package/src/document/patchOperations.test.ts +8 -342
- package/src/document/patchOperations.ts +13 -259
- package/src/presence/bifurTransport.test.ts +257 -0
- package/src/presence/bifurTransport.ts +102 -0
- package/src/presence/types.ts +62 -0
- package/src/query/queryStore.test.ts +4 -1
- package/src/releases/releasesStore.test.ts +5 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {type SanityClient} from '@sanity/client'
|
|
2
|
+
import {type Observable} from 'rxjs'
|
|
3
|
+
|
|
4
|
+
/** @public */
|
|
5
|
+
export interface PresenceLocation {
|
|
6
|
+
type: 'document'
|
|
7
|
+
documentId: string
|
|
8
|
+
path: string[]
|
|
9
|
+
lastActiveAt: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** @public */
|
|
13
|
+
export type PresenceTransport = [
|
|
14
|
+
incomingEvents$: Observable<TransportEvent>,
|
|
15
|
+
dispatchMessage: (message: TransportMessage) => Observable<void>,
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
export type TransportEvent = RollCallEvent | StateEvent | DisconnectEvent
|
|
20
|
+
|
|
21
|
+
/** @public */
|
|
22
|
+
export interface RollCallEvent {
|
|
23
|
+
type: 'rollCall'
|
|
24
|
+
userId: string
|
|
25
|
+
sessionId: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @public */
|
|
29
|
+
export interface StateEvent {
|
|
30
|
+
type: 'state'
|
|
31
|
+
userId: string
|
|
32
|
+
sessionId: string
|
|
33
|
+
timestamp: string
|
|
34
|
+
locations: PresenceLocation[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @public */
|
|
38
|
+
export interface DisconnectEvent {
|
|
39
|
+
type: 'disconnect'
|
|
40
|
+
userId: string
|
|
41
|
+
sessionId: string
|
|
42
|
+
timestamp: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @public */
|
|
46
|
+
export type TransportMessage =
|
|
47
|
+
| {type: 'rollCall'}
|
|
48
|
+
| {type: 'state'; locations: PresenceLocation[]}
|
|
49
|
+
| {type: 'disconnect'}
|
|
50
|
+
|
|
51
|
+
/** @public */
|
|
52
|
+
export interface BifurTransportOptions {
|
|
53
|
+
client: SanityClient
|
|
54
|
+
token$: Observable<string | null>
|
|
55
|
+
sessionId: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @public */
|
|
59
|
+
export interface PresenceStore {
|
|
60
|
+
locations$: Observable<PresenceLocation[]>
|
|
61
|
+
reportPresence: (locations: PresenceLocation[]) => void
|
|
62
|
+
}
|
|
@@ -20,6 +20,7 @@ describe('queryStore', () => {
|
|
|
20
20
|
let instance: SanityInstance
|
|
21
21
|
let liveEvents: Subject<LiveEvent>
|
|
22
22
|
let fetch: SanityClient['observable']['fetch']
|
|
23
|
+
let listen: SanityClient['observable']['listen']
|
|
23
24
|
// Mock data for testing
|
|
24
25
|
const mockData = {
|
|
25
26
|
movies: [
|
|
@@ -37,6 +38,8 @@ describe('queryStore', () => {
|
|
|
37
38
|
of({result: mockData.movies, syncTags: []}).pipe(delay(0)),
|
|
38
39
|
) as SanityClient['observable']['fetch']
|
|
39
40
|
|
|
41
|
+
listen = vi.fn().mockReturnValue(of(mockData.movies))
|
|
42
|
+
|
|
40
43
|
liveEvents = new Subject<LiveEvent>()
|
|
41
44
|
|
|
42
45
|
const events = vi.fn().mockReturnValue(liveEvents) as SanityClient['live']['events']
|
|
@@ -47,7 +50,7 @@ describe('queryStore', () => {
|
|
|
47
50
|
observable: of({
|
|
48
51
|
config,
|
|
49
52
|
live: {events},
|
|
50
|
-
observable: {fetch},
|
|
53
|
+
observable: {fetch, listen},
|
|
51
54
|
} as SanityClient),
|
|
52
55
|
} as StateSource<SanityClient>)
|
|
53
56
|
})
|
|
@@ -17,7 +17,7 @@ vi.mock('../utils/listenQuery', () => ({
|
|
|
17
17
|
}))
|
|
18
18
|
|
|
19
19
|
// Mock console.error to prevent test runner noise and allow verification
|
|
20
|
-
|
|
20
|
+
let consoleErrorSpy: ReturnType<typeof vi.spyOn>
|
|
21
21
|
|
|
22
22
|
describe('releasesStore', () => {
|
|
23
23
|
let instance: SanityInstance
|
|
@@ -25,7 +25,7 @@ describe('releasesStore', () => {
|
|
|
25
25
|
|
|
26
26
|
beforeEach(() => {
|
|
27
27
|
vi.resetAllMocks()
|
|
28
|
-
consoleErrorSpy.
|
|
28
|
+
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
29
29
|
|
|
30
30
|
instance = createSanityInstance({projectId: 'test', dataset: 'test'})
|
|
31
31
|
|
|
@@ -36,6 +36,7 @@ describe('releasesStore', () => {
|
|
|
36
36
|
|
|
37
37
|
afterEach(() => {
|
|
38
38
|
instance.dispose()
|
|
39
|
+
consoleErrorSpy.mockRestore()
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
it('should set active releases state when listenQuery succeeds', async () => {
|
|
@@ -63,6 +64,8 @@ describe('releasesStore', () => {
|
|
|
63
64
|
|
|
64
65
|
expect(state.getCurrent()).toEqual(mockReleases.reverse())
|
|
65
66
|
expect(consoleErrorSpy).not.toHaveBeenCalled()
|
|
67
|
+
|
|
68
|
+
vi.useRealTimers()
|
|
66
69
|
})
|
|
67
70
|
|
|
68
71
|
it('should update active releases state when listenQuery emits new data', async () => {
|