@brass-build/client 0.1.0 → 0.3.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/AGENTS.md +72 -63
- package/CHANGELOG.md +97 -0
- package/README.md +325 -235
- package/dist/auth-flow.d.ts +10 -1
- package/dist/auth-flow.d.ts.map +1 -1
- package/dist/auth-flow.js +64 -20
- package/dist/auth-flow.js.map +1 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +245 -76
- package/dist/client.js.map +1 -1
- package/dist/document-checkpoints.d.ts +1 -0
- package/dist/document-checkpoints.d.ts.map +1 -1
- package/dist/document-checkpoints.js +27 -0
- package/dist/document-checkpoints.js.map +1 -1
- package/dist/document-engine.d.ts +4 -0
- package/dist/document-engine.d.ts.map +1 -0
- package/dist/document-engine.js +9 -0
- package/dist/document-engine.js.map +1 -0
- package/dist/document-signals.d.ts +31 -1
- package/dist/document-signals.d.ts.map +1 -1
- package/dist/document-signals.js +59 -0
- package/dist/document-signals.js.map +1 -1
- package/dist/document-streams.d.ts +8 -1
- package/dist/document-streams.d.ts.map +1 -1
- package/dist/document-streams.js +79 -8
- package/dist/document-streams.js.map +1 -1
- package/dist/document-thumbnail-capture.d.ts +20 -0
- package/dist/document-thumbnail-capture.d.ts.map +1 -1
- package/dist/document-thumbnail-capture.js +247 -9
- package/dist/document-thumbnail-capture.js.map +1 -1
- package/dist/documents-namespace.d.ts.map +1 -1
- package/dist/documents-namespace.js +22 -3
- package/dist/documents-namespace.js.map +1 -1
- package/dist/documents.d.ts +49 -16
- package/dist/documents.d.ts.map +1 -1
- package/dist/documents.js +981 -237
- package/dist/documents.js.map +1 -1
- package/dist/embed-protocol.d.ts +3 -0
- package/dist/embed-protocol.d.ts.map +1 -0
- package/dist/embed-protocol.js +26 -0
- package/dist/embed-protocol.js.map +1 -0
- package/dist/emitter.d.ts.map +1 -1
- package/dist/emitter.js +8 -1
- package/dist/emitter.js.map +1 -1
- package/dist/export-guest.d.ts.map +1 -1
- package/dist/export-guest.js +14 -6
- package/dist/export-guest.js.map +1 -1
- package/dist/fetch-deadline.d.ts +22 -0
- package/dist/fetch-deadline.d.ts.map +1 -0
- package/dist/fetch-deadline.js +96 -0
- package/dist/fetch-deadline.js.map +1 -0
- package/dist/fetch-retry.d.ts +1 -0
- package/dist/fetch-retry.d.ts.map +1 -1
- package/dist/fetch-retry.js +12 -5
- package/dist/fetch-retry.js.map +1 -1
- package/dist/handle-types.d.ts +150 -0
- package/dist/handle-types.d.ts.map +1 -0
- package/dist/handle-types.js +8 -0
- package/dist/handle-types.js.map +1 -0
- package/dist/handles.d.ts +48 -48
- package/dist/handles.d.ts.map +1 -1
- package/dist/handles.js +3122 -501
- package/dist/handles.js.map +1 -1
- package/dist/hosted-runtime.d.ts.map +1 -1
- package/dist/hosted-runtime.js +8 -12
- package/dist/hosted-runtime.js.map +1 -1
- package/dist/hosted-ui.d.ts +0 -1
- package/dist/hosted-ui.d.ts.map +1 -1
- package/dist/hosted-ui.js +29 -24
- package/dist/hosted-ui.js.map +1 -1
- package/dist/importer.d.ts.map +1 -1
- package/dist/importer.js +204 -8
- package/dist/importer.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/join-coverage.d.ts +12 -0
- package/dist/join-coverage.d.ts.map +1 -0
- package/dist/join-coverage.js +37 -0
- package/dist/join-coverage.js.map +1 -0
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +5 -1
- package/dist/jwt.js.map +1 -1
- package/dist/launch-context.js +2 -2
- package/dist/launch-context.js.map +1 -1
- package/dist/mutate-batching.d.ts +25 -2
- package/dist/mutate-batching.d.ts.map +1 -1
- package/dist/mutate-batching.js +57 -10
- package/dist/mutate-batching.js.map +1 -1
- package/dist/open-document.d.ts +30 -1
- package/dist/open-document.d.ts.map +1 -1
- package/dist/open-document.js +1905 -322
- package/dist/open-document.js.map +1 -1
- package/dist/presence.d.ts +28 -0
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +149 -7
- package/dist/presence.js.map +1 -1
- package/dist/record-paging.d.ts +335 -71
- package/dist/record-paging.d.ts.map +1 -1
- package/dist/record-paging.js +590 -127
- package/dist/record-paging.js.map +1 -1
- package/dist/selection-persistence.d.ts.map +1 -1
- package/dist/selection-persistence.js +11 -1
- package/dist/selection-persistence.js.map +1 -1
- package/dist/serializer.d.ts +30 -1
- package/dist/serializer.d.ts.map +1 -1
- package/dist/session-persistence.d.ts.map +1 -1
- package/dist/session-persistence.js +9 -8
- package/dist/session-persistence.js.map +1 -1
- package/dist/session-toolbar.d.ts +0 -1
- package/dist/session-toolbar.d.ts.map +1 -1
- package/dist/session-toolbar.js +356 -83
- package/dist/session-toolbar.js.map +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +87 -18
- package/dist/session.js.map +1 -1
- package/dist/tail-ops.d.ts +14 -4
- package/dist/tail-ops.d.ts.map +1 -1
- package/dist/tail-ops.js +75 -15
- package/dist/tail-ops.js.map +1 -1
- package/dist/topic-lifecycle.d.ts +4 -0
- package/dist/topic-lifecycle.d.ts.map +1 -1
- package/dist/topic-lifecycle.js +25 -1
- package/dist/topic-lifecycle.js.map +1 -1
- package/dist/types.d.ts +47 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/undo.d.ts +2 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +11 -0
- package/dist/undo.js.map +1 -1
- package/dist/unload-guard.d.ts +5 -0
- package/dist/unload-guard.d.ts.map +1 -0
- package/dist/unload-guard.js +88 -0
- package/dist/unload-guard.js.map +1 -0
- package/dist/version-bar.d.ts +4 -3
- package/dist/version-bar.d.ts.map +1 -1
- package/dist/version-bar.js +162 -20
- package/dist/version-bar.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist/vite.d.ts +18 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +133 -8
- package/dist/vite.js.map +1 -1
- package/dist/when-saved.d.ts +2 -0
- package/dist/when-saved.d.ts.map +1 -0
- package/dist/when-saved.js +70 -0
- package/dist/when-saved.js.map +1 -0
- package/dist/ws-client.d.ts +27 -3
- package/dist/ws-client.d.ts.map +1 -1
- package/dist/ws-client.js +408 -89
- package/dist/ws-client.js.map +1 -1
- package/dist/ws-frame-limit.d.ts.map +1 -1
- package/dist/ws-frame-limit.js +23 -17
- package/dist/ws-frame-limit.js.map +1 -1
- package/docs/app-manifest.md +7 -8
- package/docs/custom-chrome.md +21 -22
- package/docs/hosted-ui-advanced.md +14 -17
- package/docs/imported-documents.md +53 -197
- package/docs/presence.md +45 -21
- package/docs/schemas.md +12 -17
- package/docs/streams.md +55 -57
- package/package.json +4 -3
- package/src/auth-flow.ts +90 -23
- package/src/client.ts +262 -80
- package/src/document-checkpoints.ts +30 -0
- package/src/document-engine.ts +15 -0
- package/src/document-signals.ts +120 -8
- package/src/document-streams.ts +95 -9
- package/src/document-thumbnail-capture.ts +253 -9
- package/src/documents-namespace.ts +38 -13
- package/src/documents.ts +1103 -290
- package/src/embed-protocol.ts +25 -0
- package/src/emitter.ts +8 -1
- package/src/export-guest.ts +15 -9
- package/src/fetch-deadline.ts +119 -0
- package/src/fetch-retry.ts +14 -5
- package/src/handle-types.ts +303 -0
- package/src/handles.ts +3407 -683
- package/src/hosted-runtime.ts +8 -12
- package/src/hosted-ui.ts +28 -32
- package/src/importer.ts +216 -8
- package/src/index.ts +29 -18
- package/src/internal.ts +7 -0
- package/src/join-coverage.ts +42 -0
- package/src/jwt.ts +8 -1
- package/src/launch-context.ts +2 -2
- package/src/mutate-batching.ts +60 -11
- package/src/open-document.ts +2441 -502
- package/src/presence.ts +210 -11
- package/src/record-paging.ts +686 -137
- package/src/selection-persistence.ts +10 -1
- package/src/serializer.ts +33 -1
- package/src/session-persistence.ts +9 -8
- package/src/session-toolbar.ts +387 -89
- package/src/session.ts +91 -17
- package/src/tail-ops.ts +76 -10
- package/src/topic-lifecycle.ts +31 -1
- package/src/types.ts +56 -4
- package/src/undo.ts +13 -5
- package/src/unload-guard.ts +91 -0
- package/src/version-bar.ts +183 -26
- package/src/version.ts +1 -1
- package/src/vite.ts +175 -10
- package/src/when-saved.ts +66 -0
- package/src/ws-client.ts +461 -92
- package/src/ws-frame-limit.ts +23 -17
package/dist/fetch-retry.js
CHANGED
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
//
|
|
15
15
|
// - A GET is idempotent, so replaying it is always safe: retry the whole
|
|
16
16
|
// transient 5xx / 429 set AND a thrown network error (`RETRY_READ`).
|
|
17
|
-
// - A write is NOT idempotent, so only a 503 is safe to replay
|
|
18
|
-
//
|
|
19
|
-
// throttle / scale-up / deploy-window blip)
|
|
20
|
-
//
|
|
21
|
-
//
|
|
17
|
+
// - A write is NOT idempotent, so only a 503 is safe to replay, and only on
|
|
18
|
+
// a route where a 503 means the write did not land: the gateway's own 503
|
|
19
|
+
// (a transient throttle / scale-up / deploy-window blip) is returned before
|
|
20
|
+
// the request reaches the handler, and a handler that answers 503 does so
|
|
21
|
+
// for a write it refused rather than applied. A 502 / 504 / 429 or a network
|
|
22
|
+
// throw might mean the handler ran, so those stay hard failures
|
|
23
|
+
// (`RETRY_WRITE_503`).
|
|
22
24
|
// - A 500 is never retried under either policy: an unhandled server error
|
|
23
25
|
// is usually deterministic, so a replay just doubles the cost without
|
|
24
26
|
// changing the outcome.
|
|
@@ -54,9 +56,11 @@ const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
54
56
|
export async function fetchWithRetry(doFetch, options = {}) {
|
|
55
57
|
const policy = options.policy ?? RETRY_READ;
|
|
56
58
|
const maxAttempts = options.maxAttempts ?? 3;
|
|
59
|
+
const maxNetworkAttempts = options.maxNetworkAttempts ?? maxAttempts;
|
|
57
60
|
const baseDelayMs = options.baseDelayMs ?? 300;
|
|
58
61
|
const sleep = options.sleep ?? defaultSleep;
|
|
59
62
|
let lastError;
|
|
63
|
+
let networkThrows = 0;
|
|
60
64
|
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
61
65
|
let response;
|
|
62
66
|
try {
|
|
@@ -68,6 +72,9 @@ export async function fetchWithRetry(doFetch, options = {}) {
|
|
|
68
72
|
if (!policy.replayNetworkErrors)
|
|
69
73
|
throw err;
|
|
70
74
|
lastError = err;
|
|
75
|
+
networkThrows += 1;
|
|
76
|
+
if (networkThrows >= maxNetworkAttempts)
|
|
77
|
+
throw err;
|
|
71
78
|
}
|
|
72
79
|
if (response && !policy.replayStatuses.has(response.status)) {
|
|
73
80
|
return response;
|
package/dist/fetch-retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-retry.js","sourceRoot":"","sources":["../src/fetch-retry.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,uCAAuC;AACvC,EAAE;AACF,uEAAuE;AACvE,iEAAiE;AACjE,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,
|
|
1
|
+
{"version":3,"file":"fetch-retry.js","sourceRoot":"","sources":["../src/fetch-retry.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAC5E,wEAAwE;AACxE,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,uEAAuE;AACvE,uCAAuC;AACvC,EAAE;AACF,uEAAuE;AACvE,iEAAiE;AACjE,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,4EAA4E;AAC5E,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/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,IAAI,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
export interface Change<T = unknown> {
|
|
2
|
+
readonly set: ReadonlyMap<string, T>;
|
|
3
|
+
readonly deleted: readonly string[];
|
|
4
|
+
readonly order?: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export type ChangeSource = 'local' | 'remote' | 'undo' | 'redo';
|
|
7
|
+
export interface ChangeOrigin {
|
|
8
|
+
readonly source: ChangeSource;
|
|
9
|
+
}
|
|
10
|
+
export type MapSubscriber<T = unknown> = (change: Change<T>, origin?: ChangeOrigin) => void;
|
|
11
|
+
export type InternalMapSubscriber<T> = (change: Change<T>, origin: ChangeOrigin | undefined, resync: boolean) => void;
|
|
12
|
+
/**
|
|
13
|
+
* One positional edit, applied in the order the change carries them.
|
|
14
|
+
*
|
|
15
|
+
* `at` indexes the sequence as the preceding splices in the same change left
|
|
16
|
+
* it, so applying them in order to what you already hold leaves you current.
|
|
17
|
+
* That is the whole contract: a subscriber never has to ask what the list
|
|
18
|
+
* holds, because every fire says how to get from its last state to this one.
|
|
19
|
+
*/
|
|
20
|
+
export interface Splice<E> {
|
|
21
|
+
readonly at: number;
|
|
22
|
+
readonly removed: number;
|
|
23
|
+
readonly inserted: readonly E[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What changed in a list. Fires once on registration carrying the whole list
|
|
27
|
+
* as a single splice, then on every change carrying only what moved.
|
|
28
|
+
*
|
|
29
|
+
* A registration fire and a resync are not special cases a subscriber has to
|
|
30
|
+
* recognise: both arrive as splices that replace what it was last told, so
|
|
31
|
+
* one apply loop is the entire subscriber.
|
|
32
|
+
*/
|
|
33
|
+
export interface ListChange<T> {
|
|
34
|
+
readonly splices: readonly Splice<T>[];
|
|
35
|
+
}
|
|
36
|
+
export type ListSubscriber<T = unknown> = (change: ListChange<T>) => void;
|
|
37
|
+
export type InternalListSubscriber = (change: ListChange<unknown>, origin?: ChangeOrigin) => void;
|
|
38
|
+
export type HandleUnsubscribe = () => void;
|
|
39
|
+
export interface HandleOwner {
|
|
40
|
+
assertWritable(): void;
|
|
41
|
+
assertReadable(): void;
|
|
42
|
+
ensureLocalUpdatesSubscribed(): void;
|
|
43
|
+
commitMutate(): void;
|
|
44
|
+
originOf(event: unknown): ChangeSource;
|
|
45
|
+
}
|
|
46
|
+
export interface MapHandle<T = unknown> {
|
|
47
|
+
get(entryKey: string): T | undefined;
|
|
48
|
+
keys(): string[];
|
|
49
|
+
has(entryKey: string): boolean;
|
|
50
|
+
mutate(fn: (draft: Record<string, T>) => void): void;
|
|
51
|
+
subscribe(cb: MapSubscriber<T>): HandleUnsubscribe;
|
|
52
|
+
/**
|
|
53
|
+
* Report each time this container has been delivered whole: on
|
|
54
|
+
* registration, and again after a version checkout, a return to head or a
|
|
55
|
+
* hydrate replaces it.
|
|
56
|
+
*
|
|
57
|
+
* This is where the work that follows on the collection belongs rather than
|
|
58
|
+
* on any single change: frame the camera on what arrived, run the first pass
|
|
59
|
+
* over it. It repeats because that work is owed again each time the
|
|
60
|
+
* container is replaced.
|
|
61
|
+
*
|
|
62
|
+
* It reports that this peer holds what it had converged to when the delivery
|
|
63
|
+
* began, which is the only claim available: more always arrives afterwards.
|
|
64
|
+
*/
|
|
65
|
+
onSettled(cb: () => void): HandleUnsubscribe;
|
|
66
|
+
map<U>(entryKey: string): MapHandle<U>;
|
|
67
|
+
list<U>(entryKey: string): ListHandle<U>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The array a list `mutate` hands its callback: an ordinary `T[]` plus
|
|
71
|
+
* `move`.
|
|
72
|
+
*
|
|
73
|
+
* `move` is here because a plain array has no way to say "this entry is now
|
|
74
|
+
* at that position", and the difference matters once two people edit at once.
|
|
75
|
+
* Spelled as a removal and an insertion, a reposition merges with another
|
|
76
|
+
* peer's reposition of the SAME entry by keeping BOTH insertions, so the entry
|
|
77
|
+
* ends up in the list twice and a reader has to guess which position was
|
|
78
|
+
* meant. `move` states the reposition, and the two merge to one entry.
|
|
79
|
+
*/
|
|
80
|
+
export interface ListDraft<T> extends Array<T> {
|
|
81
|
+
/** Reposition the entry at `from` so it sits at `to`. Indices are clamped
|
|
82
|
+
* to the list, and a `from` outside it does nothing. */
|
|
83
|
+
move(from: number, to: number): void;
|
|
84
|
+
}
|
|
85
|
+
export interface ListHandle<T = unknown> {
|
|
86
|
+
length(): number;
|
|
87
|
+
mutate(fn: (draft: ListDraft<T>) => void): void;
|
|
88
|
+
subscribe(cb: ListSubscriber<T>): HandleUnsubscribe;
|
|
89
|
+
/**
|
|
90
|
+
* Report each time this container has been delivered whole: on
|
|
91
|
+
* registration, and again after a version checkout, a return to head or a
|
|
92
|
+
* hydrate replaces it.
|
|
93
|
+
*
|
|
94
|
+
* This is where the work that follows on the collection belongs rather than
|
|
95
|
+
* on any single change: frame the camera on what arrived, run the first pass
|
|
96
|
+
* over it. It repeats because that work is owed again each time the
|
|
97
|
+
* container is replaced.
|
|
98
|
+
*
|
|
99
|
+
* It reports that this peer holds what it had converged to when the delivery
|
|
100
|
+
* began, which is the only claim available: more always arrives afterwards.
|
|
101
|
+
*/
|
|
102
|
+
onSettled(cb: () => void): HandleUnsubscribe;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Where an ordered map puts a key.
|
|
106
|
+
*
|
|
107
|
+
* The two anchor forms name a neighbouring key, which is what a reader's
|
|
108
|
+
* gesture actually means (insert after the paragraph the caret is in, drop
|
|
109
|
+
* this step on that one) and what survives a peer editing the collection
|
|
110
|
+
* between the render and the write. `index` counts positions in `keys()`, for
|
|
111
|
+
* a surface that works in indices; anything at or past the end appends, and a
|
|
112
|
+
* negative index goes to the front.
|
|
113
|
+
*
|
|
114
|
+
* An anchor key the order list does not name puts the key at the end.
|
|
115
|
+
*/
|
|
116
|
+
export type OrderedMapPosition = {
|
|
117
|
+
before: string;
|
|
118
|
+
} | {
|
|
119
|
+
after: string;
|
|
120
|
+
} | {
|
|
121
|
+
index: number;
|
|
122
|
+
};
|
|
123
|
+
export interface OrderedMapHandle<T = unknown> {
|
|
124
|
+
get(entryKey: string): T | undefined;
|
|
125
|
+
has(entryKey: string): boolean;
|
|
126
|
+
keys(): string[];
|
|
127
|
+
ordered(): {
|
|
128
|
+
key: string;
|
|
129
|
+
value: T;
|
|
130
|
+
}[];
|
|
131
|
+
mutate(fn: (draft: Record<string, T>) => void): void;
|
|
132
|
+
insert(entryKey: string, value: T, at: OrderedMapPosition): void;
|
|
133
|
+
move(entryKey: string, to: OrderedMapPosition): void;
|
|
134
|
+
subscribe(cb: MapSubscriber<T>): HandleUnsubscribe;
|
|
135
|
+
/**
|
|
136
|
+
* Report each time this container has been delivered whole: on
|
|
137
|
+
* registration, and again after a version checkout, a return to head or a
|
|
138
|
+
* hydrate replaces it.
|
|
139
|
+
*
|
|
140
|
+
* This is where the work that follows on the collection belongs rather than
|
|
141
|
+
* on any single change: frame the camera on what arrived, run the first pass
|
|
142
|
+
* over it. It repeats because that work is owed again each time the
|
|
143
|
+
* container is replaced.
|
|
144
|
+
*
|
|
145
|
+
* It reports that this peer holds what it had converged to when the delivery
|
|
146
|
+
* began, which is the only claim available: more always arrives afterwards.
|
|
147
|
+
*/
|
|
148
|
+
onSettled(cb: () => void): HandleUnsubscribe;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=handle-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-types.d.ts","sourceRoot":"","sources":["../src/handle-types.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,OAAO;IAUjC,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAErC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAKpC,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAcD,MAAM,M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,IAAI,GAAG,iBAAiB,CAAC;CAC9C;AAcD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAE3C,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAErC,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IAE/B,IAAI,IAAI,MAAM,EAAE,CAAC;IAGjB,OAAO,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,EAAE,CAAC;IAKvC,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC;IAIrD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAIjE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAAC;IASrD,SAAS,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;IACnD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,iBAAiB,CAAC;CAC9C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The handle surface's public types, kept apart from the `handles.ts` code
|
|
2
|
+
// that implements them against Loro. Every type the package entry re-exports
|
|
3
|
+
// pulls its declaring module into a consumer's typecheck graph, so declaring
|
|
4
|
+
// them here is what makes the public surface engine-neutral all the way down
|
|
5
|
+
// rather than only in the signatures an app calls.
|
|
6
|
+
// `public-types-engine-free.test.ts` holds that line.
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=handle-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle-types.js","sourceRoot":"","sources":["../src/handle-types.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,mDAAmD;AACnD,sDAAsD"}
|
package/dist/handles.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LoroMovableList, LoroMap } from 'loro-crdt';
|
|
2
2
|
import { MutateBatcher } from './mutate-batching.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
originOf(event: unknown): ChangeSource;
|
|
20
|
-
}
|
|
21
|
-
export interface MapHandle<T = unknown> {
|
|
22
|
-
read(): Record<string, T>;
|
|
23
|
-
get(entryKey: string): T | undefined;
|
|
3
|
+
import type { Change, ChangeOrigin, ChangeSource, HandleOwner, HandleUnsubscribe, ListDraft, ListHandle, ListSubscriber, MapHandle, MapSubscriber, OrderedMapHandle, OrderedMapPosition } from './handle-types.js';
|
|
4
|
+
export type { Change, ChangeOrigin, ChangeSource, HandleOwner, ListDraft, HandleUnsubscribe, ListHandle, ListSubscriber, MapHandle, MapSubscriber, OrderedMapHandle, OrderedMapPosition, };
|
|
5
|
+
/**
|
|
6
|
+
* Where a root map's ADDITIONS go once the map has paged itself part-way
|
|
7
|
+
* through a mutation.
|
|
8
|
+
*
|
|
9
|
+
* A mutation large enough to need paging usually starts against a map that
|
|
10
|
+
* is not yet paged, so the decision cannot be made once at the top. The
|
|
11
|
+
* proxy consults this on every assignment; while it declines, the mutation
|
|
12
|
+
* runs exactly as an unpaged one does.
|
|
13
|
+
*/
|
|
14
|
+
interface WriteDivert {
|
|
15
|
+
take(key: string, value: unknown): boolean;
|
|
16
|
+
holds(key: string): boolean;
|
|
17
|
+
peek(key: string): unknown;
|
|
18
|
+
drop(key: string): void;
|
|
24
19
|
keys(): string[];
|
|
25
|
-
has(entryKey: string): boolean;
|
|
26
|
-
mutate(fn: (draft: Record<string, T>) => void): void;
|
|
27
|
-
subscribe(cb: MapSubscriber<T>): HandleUnsubscribe;
|
|
28
|
-
map<U>(entryKey: string): MapHandle<U>;
|
|
29
|
-
list<U>(entryKey: string): ListHandle<U>;
|
|
30
20
|
}
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
export declare function wrapLoroMapProxy(loroMap: LoroMap, batcher?: MutateBatcher, divert?: WriteDivert, guardKeys?: boolean): Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* What a ROOT map handle needs from its owning Document to present a paged
|
|
24
|
+
* store. Bundled rather than passed one by one: every member is read off the
|
|
25
|
+
* ACTIVE source's `meta` at call time (a version checkout swaps the source),
|
|
26
|
+
* and a handle that can never be a paged root is given none of them.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* The document's version, as the freshness stamp a cached index checks.
|
|
30
|
+
*
|
|
31
|
+
* Loro's frontiers, which advance on every op whatever produced it: a local
|
|
32
|
+
* write, a remote import, an undo, a version checkout. A cached index cannot
|
|
33
|
+
* key on the map's SIZE instead, because a remote change and a local undo can
|
|
34
|
+
* leave the size they found it at while changing which keys are there, and the
|
|
35
|
+
* index then answers from keys the map no longer holds. Reading it costs about
|
|
36
|
+
* 2 us and does not close the open transaction, so a mutation still commits as
|
|
37
|
+
* one change.
|
|
38
|
+
*/
|
|
39
|
+
export type StateVersion = readonly {
|
|
40
|
+
peer: string;
|
|
41
|
+
counter: number;
|
|
42
|
+
}[];
|
|
43
|
+
export interface PagedRootHooks {
|
|
44
|
+
isPaged(): boolean;
|
|
45
|
+
page(): void;
|
|
46
|
+
sessionToken(): string;
|
|
47
|
+
stateVersion(): StateVersion;
|
|
48
48
|
}
|
|
49
|
-
export declare function
|
|
50
|
-
export declare function
|
|
51
|
-
export declare function createRootListHandle<T>(root: LoroList, owner: HandleOwner): ListHandle<T>;
|
|
49
|
+
export declare function createRootMapHandle<T>(root: LoroMap, owner: HandleOwner, paging?: PagedRootHooks): MapHandle<T>;
|
|
50
|
+
export declare function createRootListHandle<T>(root: LoroMovableList, owner: HandleOwner): ListHandle<T>;
|
|
52
51
|
export declare function rebindRootMapAnchor(handle: MapHandle<unknown>, next: LoroMap): void;
|
|
53
|
-
export declare function rebindRootListAnchor(handle: ListHandle<unknown>, next:
|
|
52
|
+
export declare function rebindRootListAnchor(handle: ListHandle<unknown>, next: LoroMovableList): void;
|
|
53
|
+
export declare function snapshotRootMapKeys(handle: MapHandle<unknown>): void;
|
|
54
54
|
export declare function resyncRootHandle(handle: MapHandle<unknown> | ListHandle<unknown>): void;
|
|
55
55
|
export declare function teardownRootHandle(handle: MapHandle<unknown> | ListHandle<unknown>): void;
|
|
56
56
|
export declare function createOrderedMapHandle<T>(map: MapHandle<T>, order: ListHandle<string>, owner: HandleOwner): OrderedMapHandle<T>;
|
package/dist/handles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handles.d.ts","sourceRoot":"","sources":["../src/handles.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"handles.d.ts","sourceRoot":"","sources":["../src/handles.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EACf,OAAO,EAIR,MAAM,WAAW,CAAC;AA8BnB,OAAO,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