Repository navigation
Expand file tree
/
Copy paththoughtspace.ts
More file actions
53 lines (41 loc) · 2 KB
/
Copy paththoughtspace.ts
File metadata and controls
53 lines (41 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type Index from '../@types/IndexType'
import type Lexeme from '../@types/Lexeme'
import type Thought from '../@types/Thought'
import type ThoughtUpdates from '../@types/ThoughtUpdates'
import type { DataProvider } from './DataProvider'
import createTreecrdtThoughtspace from './treecrdt/runtime'
export type PersistThoughtspaceBatch = Parameters<DataProvider['updateThoughts']>[0] & {
local?: boolean
}
/** Storage lifetime requested from the active thoughtspace provider. */
export type ThoughtspaceStorage = 'memory' | 'persistent'
export type ThoughtspaceMaterializationSnapshot = {
thoughtIndex: Index<Thought>
lexemeIndex: Index<Lexeme>
}
export type ThoughtspaceMaterializationBridge = {
getSnapshot: () => ThoughtspaceMaterializationSnapshot
apply: (updates: ThoughtUpdates) => void | Promise<void>
}
export type ThoughtspaceRuntimeInitOptions = {
storage: ThoughtspaceStorage
materialization?: ThoughtspaceMaterializationBridge
}
export type ThoughtspaceAccessBlockedReason = 'already-open' | 'unsupported'
export type ThoughtspaceAccessResult =
{ status: 'acquired' } | { status: 'blocked'; reason: ThoughtspaceAccessBlockedReason }
/** App-facing lifecycle interface for the active thoughtspace implementation. */
export interface ThoughtspaceRuntime {
/** Acquires any runtime-specific access required before opening the interactive thoughtspace. */
acquireAccess: () => Promise<ThoughtspaceAccessResult>
init: (options: ThoughtspaceRuntimeInitOptions) => Promise<{ clientId: string; storage: string }>
drop: () => Promise<unknown>
waitForIdle: () => Promise<void>
persistPushQueueBatches: (batches: readonly PersistThoughtspaceBatch[]) => Promise<void>
}
const treecrdtThoughtspace = createTreecrdtThoughtspace()
/** The active data provider backing the current app thoughtspace. */
export const db: DataProvider = treecrdtThoughtspace.db
/** The active thoughtspace runtime implementation. */
export const thoughtspaceRuntime: ThoughtspaceRuntime = treecrdtThoughtspace
export default db