@open-artifact/whiteboard-core 0.1.0 → 0.2.1
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/package.json +4 -3
- package/src/codec.d.ts +2 -4
- package/src/json.d.ts +2 -56
- package/src/json.js +2 -221
- package/src/sync/doc-hash.d.ts +1 -13
- package/src/sync/doc-hash.js +1 -67
- package/src/sync/engine.d.ts +1 -228
- package/src/sync/engine.js +1 -1091
- package/src/sync/index.d.ts +3 -1
- package/src/sync/index.js +3 -1
- package/src/sync/live-board.d.ts +2 -1
- package/src/sync/transport.d.ts +1 -88
- package/src/sync/transport.js +1 -35
package/src/sync/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Live sync: the transport contract, the engine
|
|
2
|
+
* Live sync: the transport contract, the engine (shared through
|
|
3
|
+
* `@open-artifact/live-store`) and the live board.
|
|
3
4
|
*/
|
|
4
5
|
export * from './transport.ts';
|
|
5
6
|
export * from './doc-hash.ts';
|
|
6
7
|
export * from './engine.ts';
|
|
8
|
+
export * from '@open-artifact/live-store/cache';
|
|
7
9
|
export * from './live-board.ts';
|
package/src/sync/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Live sync: the transport contract, the engine
|
|
2
|
+
* Live sync: the transport contract, the engine (shared through
|
|
3
|
+
* `@open-artifact/live-store`) and the live board.
|
|
3
4
|
*/
|
|
4
5
|
export * from "./transport.js";
|
|
5
6
|
export * from "./doc-hash.js";
|
|
6
7
|
export * from "./engine.js";
|
|
8
|
+
export * from '@open-artifact/live-store/cache';
|
|
7
9
|
export * from "./live-board.js";
|
package/src/sync/live-board.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* The live board: the sync engine bound to the board codec, with helpers to
|
|
3
3
|
* read and change the board's content and title.
|
|
4
4
|
*/
|
|
5
|
+
import { type OrderCarry } from '../codec.ts';
|
|
5
6
|
import type { ElementMeasures } from '../geometry.ts';
|
|
6
7
|
import type { Board, BoardContent } from '../schema.ts';
|
|
7
8
|
import { type LiveCache, type LiveCodec, type LiveStore } from './engine.ts';
|
|
@@ -25,7 +26,7 @@ export declare function shareUnchangedBoard(previous: Board, next: Board): Board
|
|
|
25
26
|
* composed content (the editor may add steps, such as moving stickers with
|
|
26
27
|
* their hosts).
|
|
27
28
|
*/
|
|
28
|
-
export declare function createBoardLiveCodec(parseContent?: (raw: unknown) => BoardContent): LiveCodec<Board>;
|
|
29
|
+
export declare function createBoardLiveCodec(parseContent?: (raw: unknown) => BoardContent): LiveCodec<Board, OrderCarry>;
|
|
29
30
|
/** Options of {@link createLiveBoardDocument}. */
|
|
30
31
|
export interface LiveBoardOptions {
|
|
31
32
|
transport: SyncTransport;
|
package/src/sync/transport.d.ts
CHANGED
|
@@ -1,88 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* The document store the live sync engine talks to, and the clock it runs on.
|
|
3
|
-
*
|
|
4
|
-
* {@link SyncTransport} is structural: the runtime's `db` capability
|
|
5
|
-
* (`DbCapability`) satisfies it as-is, and tests pass an in-memory fake. The
|
|
6
|
-
* engine never imports the runtime.
|
|
7
|
-
*/
|
|
8
|
-
/** One stored document. */
|
|
9
|
-
export interface SyncDocument {
|
|
10
|
-
/** Even segment count: `elements/<id>`, `board/meta`. */
|
|
11
|
-
path: string;
|
|
12
|
-
data: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* A write's precondition: only while the document still has this hash
|
|
16
|
-
* (`documentSha256` of what was read), or `null`: only while it is absent.
|
|
17
|
-
* A failed one refuses the whole batch with `conflict`.
|
|
18
|
-
*/
|
|
19
|
-
export interface SyncWriteGuard {
|
|
20
|
-
ifMatch?: string | null;
|
|
21
|
-
}
|
|
22
|
-
/** One write of a batch. */
|
|
23
|
-
export type SyncWrite =
|
|
24
|
-
/** Replaces the document (creating it when absent). */
|
|
25
|
-
({
|
|
26
|
-
op: 'set';
|
|
27
|
-
path: string;
|
|
28
|
-
data: Record<string, unknown>;
|
|
29
|
-
} & SyncWriteGuard)
|
|
30
|
-
/** Applies a JSON merge patch; an absent document starts empty. */
|
|
31
|
-
| ({
|
|
32
|
-
op: 'update';
|
|
33
|
-
path: string;
|
|
34
|
-
patch: Record<string, unknown>;
|
|
35
|
-
} & SyncWriteGuard)
|
|
36
|
-
/** Removes the document (a no-op when absent). */
|
|
37
|
-
| ({
|
|
38
|
-
op: 'delete';
|
|
39
|
-
path: string;
|
|
40
|
-
} & SyncWriteGuard);
|
|
41
|
-
/** Changes made by someone else. */
|
|
42
|
-
export interface SyncChangeEvent {
|
|
43
|
-
/** Path → the document's new data, or `null` when it was deleted. */
|
|
44
|
-
changes: Record<string, Record<string, unknown> | null>;
|
|
45
|
-
/** Who made the change, when the host knows. */
|
|
46
|
-
author?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* A document store with change notifications. Writes are all or nothing and
|
|
50
|
-
* are never echoed back through {@link SyncTransport.onChange}.
|
|
51
|
-
*/
|
|
52
|
-
export interface SyncTransport {
|
|
53
|
-
/** Reads one document; `null` when absent. */
|
|
54
|
-
get(path: string): Promise<Record<string, unknown> | null>;
|
|
55
|
-
/** Every document of one collection. */
|
|
56
|
-
list(collection: string): Promise<SyncDocument[]>;
|
|
57
|
-
/** Applies a batch in order, all or nothing. */
|
|
58
|
-
write(writes: SyncWrite[]): Promise<void>;
|
|
59
|
-
/** Subscribes to changes made by anyone else; returns an unsubscribe function. */
|
|
60
|
-
onChange(listener: (event: SyncChangeEvent) => void): () => void;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Why a store call failed. Hosts reject with an error whose `code` is one of
|
|
64
|
-
* these (the runtime's `ArtifactError` codes plus `resource_exhausted`);
|
|
65
|
-
* anything else counts as `unavailable`.
|
|
66
|
-
*/
|
|
67
|
-
export type SyncErrorCode = 'conflict' | 'not_writer' | 'not_granted' | 'invalid' | 'not_found' | 'unavailable' | 'resource_exhausted';
|
|
68
|
-
/** The code of a store failure (`unavailable` for anything unrecognized). */
|
|
69
|
-
export declare function syncErrorCode(error: unknown): SyncErrorCode;
|
|
70
|
-
/** The message of a store failure, for status text. */
|
|
71
|
-
export declare function syncErrorMessage(error: unknown): string;
|
|
72
|
-
/** True for failures that mean the viewer may no longer write. */
|
|
73
|
-
export declare function isAccessError(code: SyncErrorCode): boolean;
|
|
74
|
-
/** An opaque timer handle. */
|
|
75
|
-
export type TimerHandle = unknown;
|
|
76
|
-
/** The clock and timers the engine uses; tests inject a fake. */
|
|
77
|
-
export interface SyncTimers {
|
|
78
|
-
setTimeout(callback: () => void, ms: number): TimerHandle;
|
|
79
|
-
clearTimeout(handle: TimerHandle): void;
|
|
80
|
-
/** Epoch milliseconds. */
|
|
81
|
-
now(): number;
|
|
82
|
-
/** A number in [0, 1). */
|
|
83
|
-
random(): number;
|
|
84
|
-
}
|
|
85
|
-
/** Real timers. */
|
|
86
|
-
export declare const SYSTEM_TIMERS: SyncTimers;
|
|
87
|
-
/** The collection of a document path (`elements/a1` → `elements`). */
|
|
88
|
-
export declare function collectionOfPath(path: string): string;
|
|
1
|
+
export * from '@open-artifact/live-store/transport';
|
package/src/sync/transport.js
CHANGED
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* The document store the live sync engine talks to, and the clock it runs on.
|
|
3
|
-
*
|
|
4
|
-
* {@link SyncTransport} is structural: the runtime's `db` capability
|
|
5
|
-
* (`DbCapability`) satisfies it as-is, and tests pass an in-memory fake. The
|
|
6
|
-
* engine never imports the runtime.
|
|
7
|
-
*/
|
|
8
|
-
const SYNC_ERROR_CODES = ['conflict', 'not_writer', 'not_granted', 'invalid', 'not_found', 'unavailable', 'resource_exhausted'];
|
|
9
|
-
/** The code of a store failure (`unavailable` for anything unrecognized). */
|
|
10
|
-
export function syncErrorCode(error) {
|
|
11
|
-
const code = typeof error === 'object' && error !== null ? error.code : undefined;
|
|
12
|
-
return typeof code === 'string' && SYNC_ERROR_CODES.includes(code) ? code : 'unavailable';
|
|
13
|
-
}
|
|
14
|
-
/** The message of a store failure, for status text. */
|
|
15
|
-
export function syncErrorMessage(error) {
|
|
16
|
-
if (error instanceof Error && error.message !== '')
|
|
17
|
-
return error.message;
|
|
18
|
-
return typeof error === 'string' && error !== '' ? error : 'unknown error';
|
|
19
|
-
}
|
|
20
|
-
/** True for failures that mean the viewer may no longer write. */
|
|
21
|
-
export function isAccessError(code) {
|
|
22
|
-
return code === 'not_writer' || code === 'not_granted';
|
|
23
|
-
}
|
|
24
|
-
/** Real timers. */
|
|
25
|
-
export const SYSTEM_TIMERS = {
|
|
26
|
-
setTimeout: (callback, ms) => globalThis.setTimeout(callback, ms),
|
|
27
|
-
clearTimeout: (handle) => globalThis.clearTimeout(handle),
|
|
28
|
-
now: () => Date.now(),
|
|
29
|
-
random: () => Math.random(),
|
|
30
|
-
};
|
|
31
|
-
/** The collection of a document path (`elements/a1` → `elements`). */
|
|
32
|
-
export function collectionOfPath(path) {
|
|
33
|
-
const slash = path.lastIndexOf('/');
|
|
34
|
-
return slash < 0 ? '' : path.slice(0, slash);
|
|
35
|
-
}
|
|
1
|
+
export * from '@open-artifact/live-store/transport';
|