@abraca/dabra 2.90.0 → 2.92.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/package.json +5 -11
- package/src/AbracadabraBaseProvider.ts +0 -963
- package/src/AbracadabraClient.ts +0 -1960
- package/src/AbracadabraProvider.ts +0 -915
- package/src/AbracadabraWS.ts +0 -695
- package/src/BackgroundSyncManager.ts +0 -856
- package/src/BackgroundSyncPersistence.ts +0 -140
- package/src/ChatClient.ts +0 -314
- package/src/CloseEvents.ts +0 -49
- package/src/ContentManager.ts +0 -246
- package/src/CoverReconcile.ts +0 -168
- package/src/CryptoIdentityKeystore.ts +0 -754
- package/src/DeviceRegistrationService.ts +0 -257
- package/src/DocConverters.ts +0 -1859
- package/src/DocKeyManager.ts +0 -163
- package/src/DocTypes.ts +0 -628
- package/src/DocUtils.ts +0 -251
- package/src/DocumentCache.ts +0 -210
- package/src/DocumentManager.ts +0 -410
- package/src/E2EAbracadabraProvider.ts +0 -426
- package/src/E2EOfflineStore.ts +0 -55
- package/src/EncryptedChatClient.ts +0 -173
- package/src/EncryptedY.ts +0 -145
- package/src/EventEmitter.ts +0 -59
- package/src/FileBlobStore.ts +0 -569
- package/src/IdentityDoc.ts +0 -711
- package/src/IncomingMessage.ts +0 -63
- package/src/MessageReceiver.ts +0 -151
- package/src/MessageSender.ts +0 -22
- package/src/MetaManager.ts +0 -194
- package/src/MnemonicKeyDerivation.ts +0 -171
- package/src/NodeConnect.ts +0 -63
- package/src/NodeIdentity.ts +0 -378
- package/src/NotificationsClient.ts +0 -207
- package/src/OfflineStore.ts +0 -294
- package/src/OutgoingMessage.ts +0 -25
- package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
- package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
- package/src/OutgoingMessages/CloseMessage.ts +0 -17
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
- package/src/OutgoingMessages/StatelessMessage.ts +0 -18
- package/src/OutgoingMessages/SubdocMessage.ts +0 -35
- package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
- package/src/OutgoingMessages/UpdateMessage.ts +0 -20
- package/src/QueryClient.ts +0 -209
- package/src/RpcClient.ts +0 -659
- package/src/SchemaTypes.ts +0 -179
- package/src/SearchIndex.ts +0 -250
- package/src/ServerRegistry.ts +0 -220
- package/src/ServerReset.ts +0 -222
- package/src/TokenManager.ts +0 -337
- package/src/TreeManager.ts +0 -894
- package/src/TreeTimestamps.ts +0 -101
- package/src/auth.ts +0 -62
- package/src/awarenessStatesToArray.ts +0 -10
- package/src/index.ts +0 -219
- package/src/messageRecord.ts +0 -121
- package/src/sync/BroadcastChannelSync.ts +0 -235
- package/src/types.ts +0 -790
- package/src/webrtc/AbracadabraWebRTC.ts +0 -683
- package/src/webrtc/DataChannelRouter.ts +0 -179
- package/src/webrtc/DevicePairingChannel.ts +0 -496
- package/src/webrtc/E2EEChannel.ts +0 -195
- package/src/webrtc/FileTransferChannel.ts +0 -367
- package/src/webrtc/ManualSignaling.ts +0 -204
- package/src/webrtc/PeerConnection.ts +0 -133
- package/src/webrtc/SignalingSocket.ts +0 -378
- package/src/webrtc/YjsDataChannel.ts +0 -203
- package/src/webrtc/index.ts +0 -26
- package/src/webrtc/types.ts +0 -177
package/src/TreeTimestamps.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TreeTimestamps
|
|
3
|
-
*
|
|
4
|
-
* Attaches an afterTransaction observer on a child Y.Doc so that whenever a
|
|
5
|
-
* LOCAL edit is made, the `updatedAt` timestamp on the corresponding entry
|
|
6
|
-
* in the root doc's `doc-tree` map is written.
|
|
7
|
-
*
|
|
8
|
-
* This propagates "last edited" timestamps to all peers via the root CRDT,
|
|
9
|
-
* without requiring any server-side changes.
|
|
10
|
-
*
|
|
11
|
-
* Leading-edge + trailing-edge throttle (default 5 s window): the first
|
|
12
|
-
* update flushes immediately so the "last edited" badge updates instantly;
|
|
13
|
-
* follow-up updates within the window are coalesced into one trailing flush.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import * as Y from "yjs";
|
|
17
|
-
|
|
18
|
-
import { patchEntry } from "./DocUtils.ts";
|
|
19
|
-
import type { OfflineStore } from "./OfflineStore.ts";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Attach an observer that writes `updatedAt` to the root doc-tree entry for
|
|
23
|
-
* `childDocId` whenever the child doc receives a local edit.
|
|
24
|
-
*
|
|
25
|
-
* @param treeMap The root doc's "doc-tree" Y.Map.
|
|
26
|
-
* @param childDocId The child document's UUID (key in treeMap).
|
|
27
|
-
* @param childDoc The child Y.Doc to observe.
|
|
28
|
-
* @param offlineStore The child provider's OfflineStore (used to detect
|
|
29
|
-
* offline-replay origins and skip them). Pass null when
|
|
30
|
-
* the offline store is disabled.
|
|
31
|
-
* @param options Optional config. `throttleMs` controls the throttle
|
|
32
|
-
* window (default 5000).
|
|
33
|
-
* @returns Cleanup function — call on provider destroy. Flushes
|
|
34
|
-
* any pending write before detaching.
|
|
35
|
-
*/
|
|
36
|
-
export function attachUpdatedAtObserver(
|
|
37
|
-
treeMap: Y.Map<any>,
|
|
38
|
-
childDocId: string,
|
|
39
|
-
childDoc: Y.Doc,
|
|
40
|
-
offlineStore: OfflineStore | null,
|
|
41
|
-
options?: { throttleMs?: number },
|
|
42
|
-
): () => void {
|
|
43
|
-
const throttleMs = options?.throttleMs ?? 5000;
|
|
44
|
-
|
|
45
|
-
let lastFlushedAt = 0;
|
|
46
|
-
let pendingTs = 0;
|
|
47
|
-
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
48
|
-
|
|
49
|
-
function writeTs(ts: number): void {
|
|
50
|
-
const raw = treeMap.get(childDocId);
|
|
51
|
-
if (!raw) return;
|
|
52
|
-
// Per-key set on the entry's nested Y.Map: the 5 s `updatedAt`
|
|
53
|
-
// write no longer clobbers a concurrent parentId/label edit
|
|
54
|
-
// (whole-entry-LWW fix, audit ⑦).
|
|
55
|
-
patchEntry(treeMap, childDocId, { updatedAt: ts });
|
|
56
|
-
lastFlushedAt = ts;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function flushPending(): void {
|
|
60
|
-
timer = null;
|
|
61
|
-
if (pendingTs === 0) return;
|
|
62
|
-
const ts = pendingTs;
|
|
63
|
-
pendingTs = 0;
|
|
64
|
-
writeTs(ts);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function handler(tr: Y.Transaction): void {
|
|
68
|
-
// Only LOCAL edits stamp updatedAt. Remote updates (tr.local === false:
|
|
69
|
-
// initial sync replay, other peers' edits, offline-store replay,
|
|
70
|
-
// cross-tab broadcast) are stamped by the client that made them and the
|
|
71
|
-
// timestamp propagates through the root CRDT — counting them here
|
|
72
|
-
// turned "last edited" into "last synced on this client": merely
|
|
73
|
-
// opening a doc bumped its updatedAt to now.
|
|
74
|
-
if (!tr.local) return;
|
|
75
|
-
if (offlineStore !== null && tr.origin === offlineStore) return;
|
|
76
|
-
// No-op transactions (nothing actually changed) don't count as edits.
|
|
77
|
-
if (tr.changed.size === 0) return;
|
|
78
|
-
|
|
79
|
-
const now = Date.now();
|
|
80
|
-
if (now - lastFlushedAt >= throttleMs) {
|
|
81
|
-
// Leading edge — flush immediately.
|
|
82
|
-
writeTs(now);
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// Inside the throttle window — coalesce into a trailing flush.
|
|
86
|
-
pendingTs = now;
|
|
87
|
-
if (timer === null) {
|
|
88
|
-
timer = setTimeout(flushPending, throttleMs - (now - lastFlushedAt));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
childDoc.on("afterTransaction", handler);
|
|
93
|
-
|
|
94
|
-
return () => {
|
|
95
|
-
childDoc.off("afterTransaction", handler);
|
|
96
|
-
if (timer !== null) {
|
|
97
|
-
clearTimeout(timer);
|
|
98
|
-
flushPending();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
package/src/auth.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as encoding from "lib0/encoding";
|
|
2
|
-
import * as decoding from "lib0/decoding";
|
|
3
|
-
import type { AuthorizedScope } from "./types.ts";
|
|
4
|
-
|
|
5
|
-
export enum AuthMessageType {
|
|
6
|
-
Token = 0,
|
|
7
|
-
PermissionDenied = 1,
|
|
8
|
-
Authenticated = 2,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const writeAuthentication = (
|
|
12
|
-
encoder: encoding.Encoder,
|
|
13
|
-
auth: string,
|
|
14
|
-
) => {
|
|
15
|
-
encoding.writeVarUint(encoder, AuthMessageType.Token);
|
|
16
|
-
encoding.writeVarString(encoder, auth);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const writePermissionDenied = (
|
|
20
|
-
encoder: encoding.Encoder,
|
|
21
|
-
reason: string,
|
|
22
|
-
) => {
|
|
23
|
-
encoding.writeVarUint(encoder, AuthMessageType.PermissionDenied);
|
|
24
|
-
encoding.writeVarString(encoder, reason);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const writeAuthenticated = (
|
|
28
|
-
encoder: encoding.Encoder,
|
|
29
|
-
scope: AuthorizedScope,
|
|
30
|
-
) => {
|
|
31
|
-
encoding.writeVarUint(encoder, AuthMessageType.Authenticated);
|
|
32
|
-
encoding.writeVarString(encoder, scope);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const writeTokenSyncRequest = (
|
|
36
|
-
encoder: encoding.Encoder,
|
|
37
|
-
) => {
|
|
38
|
-
encoding.writeVarUint(encoder, AuthMessageType.Token);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const readAuthMessage = (
|
|
42
|
-
decoder: decoding.Decoder,
|
|
43
|
-
sendToken: () => void,
|
|
44
|
-
permissionDeniedHandler: (reason: string) => void,
|
|
45
|
-
authenticatedHandler: (scope: string) => void,
|
|
46
|
-
) => {
|
|
47
|
-
switch (decoding.readVarUint(decoder)) {
|
|
48
|
-
case AuthMessageType.Token: {
|
|
49
|
-
sendToken();
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case AuthMessageType.PermissionDenied: {
|
|
53
|
-
permissionDeniedHandler(decoding.readVarString(decoder));
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
case AuthMessageType.Authenticated: {
|
|
57
|
-
authenticatedHandler(decoding.readVarString(decoder));
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
}
|
|
62
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
export * from "./AbracadabraBaseProvider.ts";
|
|
2
|
-
export * from "./AbracadabraWS.ts";
|
|
3
|
-
export * from "./types.ts";
|
|
4
|
-
export * from "./AbracadabraProvider.ts";
|
|
5
|
-
export * from "./AbracadabraClient.ts";
|
|
6
|
-
export {
|
|
7
|
-
TokenManager,
|
|
8
|
-
LocalStorageDeviceSessionStorage,
|
|
9
|
-
} from "./TokenManager.ts";
|
|
10
|
-
export type {
|
|
11
|
-
TokenManagerOptions,
|
|
12
|
-
DeviceSessionRecord,
|
|
13
|
-
DeviceSessionStorage,
|
|
14
|
-
} from "./TokenManager.ts";
|
|
15
|
-
export * from "./OfflineStore.ts";
|
|
16
|
-
export * from "./ServerReset.ts";
|
|
17
|
-
export * from "./auth.ts";
|
|
18
|
-
export * from "./CloseEvents.ts";
|
|
19
|
-
export * from "./awarenessStatesToArray.ts";
|
|
20
|
-
export { SubdocMessage } from "./OutgoingMessages/SubdocMessage.ts";
|
|
21
|
-
export { CryptoIdentityKeystore } from "./CryptoIdentityKeystore.ts";
|
|
22
|
-
export {
|
|
23
|
-
signChallengeWithSeed,
|
|
24
|
-
makeChallengeSigner,
|
|
25
|
-
deterministicKeypair,
|
|
26
|
-
loadOrCreateKeyFile,
|
|
27
|
-
loginOrRegisterWithKey,
|
|
28
|
-
loginOrRegisterWithPolicy,
|
|
29
|
-
} from "./NodeIdentity.ts";
|
|
30
|
-
export type {
|
|
31
|
-
NodeKeypair,
|
|
32
|
-
LoadKeyFileOptions,
|
|
33
|
-
LoginOrRegisterOptions,
|
|
34
|
-
KeyAuthClient,
|
|
35
|
-
PolicyAuthClient,
|
|
36
|
-
ConnectPolicyResult,
|
|
37
|
-
} from "./NodeIdentity.ts";
|
|
38
|
-
export { openSyncedProvider, pickEntrySpace } from "./NodeConnect.ts";
|
|
39
|
-
export {
|
|
40
|
-
serverRegistryPath,
|
|
41
|
-
defaultKeyFileFor,
|
|
42
|
-
loadServerRegistry,
|
|
43
|
-
saveServerRegistry,
|
|
44
|
-
resolveServer,
|
|
45
|
-
addServer,
|
|
46
|
-
removeServer,
|
|
47
|
-
setDefault,
|
|
48
|
-
migrateLegacyDefault,
|
|
49
|
-
} from "./ServerRegistry.ts";
|
|
50
|
-
export type { ServerProfile, ServerRegistry } from "./ServerRegistry.ts";
|
|
51
|
-
export { DocumentCache } from "./DocumentCache.ts";
|
|
52
|
-
export type { DocumentCacheOptions } from "./DocumentCache.ts";
|
|
53
|
-
export { SearchIndex } from "./SearchIndex.ts";
|
|
54
|
-
export { FileBlobStore } from "./FileBlobStore.ts";
|
|
55
|
-
export { DocKeyManager } from "./DocKeyManager.ts";
|
|
56
|
-
export { E2EAbracadabraProvider } from "./E2EAbracadabraProvider.ts";
|
|
57
|
-
export { E2EOfflineStore } from "./E2EOfflineStore.ts";
|
|
58
|
-
export * from "./EncryptedY.ts";
|
|
59
|
-
export type { DocEncryptionInfo } from "./types.ts";
|
|
60
|
-
export { attachUpdatedAtObserver } from "./TreeTimestamps.ts";
|
|
61
|
-
export { BackgroundSyncManager } from "./BackgroundSyncManager.ts";
|
|
62
|
-
export type { BackgroundSyncManagerOptions } from "./BackgroundSyncManager.ts";
|
|
63
|
-
export { BackgroundSyncPersistence } from "./BackgroundSyncPersistence.ts";
|
|
64
|
-
export type {
|
|
65
|
-
DocSyncState,
|
|
66
|
-
DocSyncStatus,
|
|
67
|
-
} from "./BackgroundSyncPersistence.ts";
|
|
68
|
-
export * from "./webrtc/index.ts";
|
|
69
|
-
export { BroadcastChannelSync } from "./sync/BroadcastChannelSync.ts";
|
|
70
|
-
export {
|
|
71
|
-
IdentityDocProvider,
|
|
72
|
-
deriveIdentityDocId,
|
|
73
|
-
// Deterministic id of the `kind = "dm"` doc between two pubkeys. Consumers
|
|
74
|
-
// need this to key reactive DM state synchronously; `findOrCreateDmDoc()`
|
|
75
|
-
// on AbracadabraClient is the async find-or-create that backs it.
|
|
76
|
-
deriveDmDocId,
|
|
77
|
-
} from "./IdentityDoc.ts";
|
|
78
|
-
export type {
|
|
79
|
-
IdentityDocConfiguration,
|
|
80
|
-
IdentityProfile,
|
|
81
|
-
IdentityServerEntry,
|
|
82
|
-
IdentitySpaceEntry,
|
|
83
|
-
IdentityDeviceEntry,
|
|
84
|
-
DeviceServerStatus,
|
|
85
|
-
DeviceTier,
|
|
86
|
-
} from "./IdentityDoc.ts";
|
|
87
|
-
export { DeviceRegistrationService } from "./DeviceRegistrationService.ts";
|
|
88
|
-
export { ChatClient } from "./ChatClient.ts";
|
|
89
|
-
export { RpcClient, RpcError, RPC_PREFIX } from "./RpcClient.ts";
|
|
90
|
-
export { QueryClient, QueryError, QUERY_PREFIX } from "./QueryClient.ts";
|
|
91
|
-
export type {
|
|
92
|
-
QueryKind,
|
|
93
|
-
QueryFrame,
|
|
94
|
-
QuerySpec,
|
|
95
|
-
QuerySubscriptionHandlers,
|
|
96
|
-
QuerySubscriptionHandle,
|
|
97
|
-
QueryTransport,
|
|
98
|
-
DocumentMetaWire,
|
|
99
|
-
} from "./QueryClient.ts";
|
|
100
|
-
export type {
|
|
101
|
-
RpcKind,
|
|
102
|
-
RpcFrame,
|
|
103
|
-
RpcErrorPayload,
|
|
104
|
-
RpcErrorCode,
|
|
105
|
-
RpcTransport,
|
|
106
|
-
RpcTarget,
|
|
107
|
-
RpcCallOptions,
|
|
108
|
-
RpcCallHandle,
|
|
109
|
-
RpcHandler,
|
|
110
|
-
RpcHandlerContext,
|
|
111
|
-
} from "./RpcClient.ts";
|
|
112
|
-
export type {
|
|
113
|
-
ChatClientTransport,
|
|
114
|
-
SendMessageInput,
|
|
115
|
-
SendMessageResult,
|
|
116
|
-
EditMessageInput,
|
|
117
|
-
DeleteMessageInput,
|
|
118
|
-
MarkReadInput as ChatMarkReadInput,
|
|
119
|
-
} from "./ChatClient.ts";
|
|
120
|
-
export {
|
|
121
|
-
EncryptedChatClient,
|
|
122
|
-
ChannelKeyResolver,
|
|
123
|
-
encryptChatContent,
|
|
124
|
-
decryptChatContent,
|
|
125
|
-
isEncryptedContent,
|
|
126
|
-
} from "./EncryptedChatClient.ts";
|
|
127
|
-
export {
|
|
128
|
-
foldRecords,
|
|
129
|
-
recordFromYAny,
|
|
130
|
-
} from "./messageRecord.ts";
|
|
131
|
-
export type {
|
|
132
|
-
MessageRecord,
|
|
133
|
-
FoldedMessage,
|
|
134
|
-
} from "./messageRecord.ts";
|
|
135
|
-
export { NotificationsClient } from "./NotificationsClient.ts";
|
|
136
|
-
export type {
|
|
137
|
-
InboxEntry,
|
|
138
|
-
FetchInboxInput,
|
|
139
|
-
MarkReadInput as InboxMarkReadInput,
|
|
140
|
-
} from "./NotificationsClient.ts";
|
|
141
|
-
// Legacy type re-exports — wire-shape types from the deprecated chat:* / notify:*
|
|
142
|
-
// protocol that consumers may still import. The dashboard's reactive layer
|
|
143
|
-
// reads/writes these shapes directly off Y.Array entries on channel-period and
|
|
144
|
-
// inbox docs, independently of ChatClient/NotificationsClient.
|
|
145
|
-
export type {
|
|
146
|
-
ChatMessage,
|
|
147
|
-
ChatChannel,
|
|
148
|
-
ChatTypingEvent,
|
|
149
|
-
ChatReadReceipt,
|
|
150
|
-
ChatReadCursor,
|
|
151
|
-
SendChatMessageInput,
|
|
152
|
-
GetChatHistoryInput,
|
|
153
|
-
NotificationRecord,
|
|
154
|
-
NotificationReadUpdate,
|
|
155
|
-
CreateNotificationInput,
|
|
156
|
-
FetchNotificationsInput,
|
|
157
|
-
} from "./types.ts";
|
|
158
|
-
export {
|
|
159
|
-
generateMnemonic,
|
|
160
|
-
validateMnemonic,
|
|
161
|
-
mnemonicToEd25519Seed,
|
|
162
|
-
mnemonicToKeyPair,
|
|
163
|
-
deriveSeedWrappingKey,
|
|
164
|
-
wrapSeed,
|
|
165
|
-
unwrapSeed,
|
|
166
|
-
bip39Wordlist,
|
|
167
|
-
} from "./MnemonicKeyDerivation.ts";
|
|
168
|
-
export { DocumentManager } from "./DocumentManager.ts";
|
|
169
|
-
export type { DocumentManagerConfig } from "./DocumentManager.ts";
|
|
170
|
-
export { TreeManager } from "./TreeManager.ts";
|
|
171
|
-
export type { ChildrenPage } from "./TreeManager.ts";
|
|
172
|
-
export { ContentManager } from "./ContentManager.ts";
|
|
173
|
-
export type { DocumentContent } from "./ContentManager.ts";
|
|
174
|
-
export { MetaManager, MetaValidationError } from "./MetaManager.ts";
|
|
175
|
-
export type {
|
|
176
|
-
DocumentMetaInfo,
|
|
177
|
-
SchemaValidatorLike,
|
|
178
|
-
} from "./MetaManager.ts";
|
|
179
|
-
export { TypedDocTypeMismatchError } from "./SchemaTypes.ts";
|
|
180
|
-
export type {
|
|
181
|
-
SchemaRegistryLike,
|
|
182
|
-
SchemaDocTypeName,
|
|
183
|
-
SchemaMetaOf,
|
|
184
|
-
TypedTreeEntry,
|
|
185
|
-
TypedDocsClient,
|
|
186
|
-
} from "./SchemaTypes.ts";
|
|
187
|
-
export * from "./DocTypes.ts";
|
|
188
|
-
export {
|
|
189
|
-
waitForSync,
|
|
190
|
-
withTimeout,
|
|
191
|
-
normalizeRootId,
|
|
192
|
-
toPlain,
|
|
193
|
-
readEntries,
|
|
194
|
-
makeEntryMap,
|
|
195
|
-
patchEntry,
|
|
196
|
-
isPlaceholderLabel,
|
|
197
|
-
} from "./DocUtils.ts";
|
|
198
|
-
export {
|
|
199
|
-
reconcileDocCover,
|
|
200
|
-
collectMediaFileBlocks,
|
|
201
|
-
} from "./CoverReconcile.ts";
|
|
202
|
-
export type { MediaFileBlock } from "./CoverReconcile.ts";
|
|
203
|
-
export {
|
|
204
|
-
yjsToMarkdown,
|
|
205
|
-
populateYDocFromMarkdown,
|
|
206
|
-
parseFrontmatter,
|
|
207
|
-
filenameToLabel,
|
|
208
|
-
buildHeadingElement,
|
|
209
|
-
buildParagraphElement,
|
|
210
|
-
buildBulletListElement,
|
|
211
|
-
buildOrderedListElement,
|
|
212
|
-
buildTaskListElement,
|
|
213
|
-
buildCodeBlockElement,
|
|
214
|
-
buildBlockquoteElement,
|
|
215
|
-
buildHorizontalRuleElement,
|
|
216
|
-
buildBlocksFromMarkdown,
|
|
217
|
-
readBlocksFromFragment,
|
|
218
|
-
} from "./DocConverters.ts";
|
|
219
|
-
export type { DocumentBlock } from "./DocConverters.ts";
|
package/src/messageRecord.ts
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decode + fold message records from a period doc's `messages` Y.Array
|
|
3
|
-
* into the flat `ChatMessage[]` shape the dashboard renders.
|
|
4
|
-
*
|
|
5
|
-
* The server appends three kinds of records to the array (see
|
|
6
|
-
* `abracadabra-rs/crates/abracadabra/src/messages.rs`):
|
|
7
|
-
*
|
|
8
|
-
* - `record_kind: "message"` — a real message (default kind).
|
|
9
|
-
* - `record_kind: "edit"` — an updated version of `target_id`.
|
|
10
|
-
* - `record_kind: "tombstone"` — `target_id` is deleted.
|
|
11
|
-
*
|
|
12
|
-
* Folding rules:
|
|
13
|
-
* - For each `target_id`, apply edits in `ts` order; the *last* edit's
|
|
14
|
-
* content wins. The original message's id, sender_id, and ts stay.
|
|
15
|
-
* `editedAt` is the latest edit's ts.
|
|
16
|
-
* - Any target_id with a tombstone is dropped from the output entirely.
|
|
17
|
-
* - Records without record_kind default to "message" (back-compat).
|
|
18
|
-
*
|
|
19
|
-
* Cross-period folding: edits and tombstones can in principle target a
|
|
20
|
-
* message in a *prior* period (e.g. user edits a message that lived on
|
|
21
|
-
* the previous period after rollover). Callers that paginate across
|
|
22
|
-
* periods should fold the joined list, not each period independently.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export interface MessageRecord {
|
|
26
|
-
record_kind?: 'message' | 'edit' | 'tombstone'
|
|
27
|
-
id: string
|
|
28
|
-
target_id?: string
|
|
29
|
-
sender_id: string
|
|
30
|
-
channel_doc_id: string
|
|
31
|
-
period_id: string
|
|
32
|
-
ts: number
|
|
33
|
-
content: string
|
|
34
|
-
mentions?: string[]
|
|
35
|
-
reply_to?: string | null
|
|
36
|
-
sig?: string
|
|
37
|
-
server_sig?: string
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface FoldedMessage {
|
|
41
|
-
id: string
|
|
42
|
-
channel: string
|
|
43
|
-
senderId: string
|
|
44
|
-
senderName?: string
|
|
45
|
-
content: string
|
|
46
|
-
createdAt: number
|
|
47
|
-
/** Set if the message has been edited at least once. */
|
|
48
|
-
editedAt?: number
|
|
49
|
-
/** Reply target message id, if any. */
|
|
50
|
-
replyTo?: string
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Fold an ordered list of records (oldest-first) into the visible
|
|
55
|
-
* messages a UI should render. Records may come from one period or
|
|
56
|
-
* across multiple periods concatenated in time order.
|
|
57
|
-
*/
|
|
58
|
-
export function foldRecords(records: MessageRecord[]): FoldedMessage[] {
|
|
59
|
-
const tombstoned = new Set<string>()
|
|
60
|
-
for (const r of records) {
|
|
61
|
-
if (r.record_kind === 'tombstone' && r.target_id) tombstoned.add(r.target_id)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const base = new Map<string, FoldedMessage>()
|
|
65
|
-
for (const r of records) {
|
|
66
|
-
const kind = r.record_kind ?? 'message'
|
|
67
|
-
if (kind !== 'message') continue
|
|
68
|
-
if (tombstoned.has(r.id)) continue
|
|
69
|
-
base.set(r.id, {
|
|
70
|
-
id: r.id,
|
|
71
|
-
channel: r.channel_doc_id,
|
|
72
|
-
senderId: r.sender_id,
|
|
73
|
-
content: r.content,
|
|
74
|
-
createdAt: r.ts,
|
|
75
|
-
...(r.reply_to ? { replyTo: r.reply_to } : {}),
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const r of records) {
|
|
80
|
-
if (r.record_kind !== 'edit' || !r.target_id) continue
|
|
81
|
-
if (tombstoned.has(r.target_id)) continue
|
|
82
|
-
const original = base.get(r.target_id)
|
|
83
|
-
if (!original) continue
|
|
84
|
-
original.content = r.content
|
|
85
|
-
original.editedAt = r.ts
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return [...base.values()].sort((a, b) => a.createdAt - b.createdAt)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Decode whatever the Y.Array stored for an entry into a MessageRecord.
|
|
93
|
-
* Note: the server stamps `ts` server-side via `Any::BigInt(now_ts_ms())`,
|
|
94
|
-
* so on the wire it round-trips as a JS BigInt — `typeof` is `'bigint'`,
|
|
95
|
-
* not `'number'`. Accept both and coerce.
|
|
96
|
-
*/
|
|
97
|
-
export function recordFromYAny(any: unknown): MessageRecord | null {
|
|
98
|
-
if (!any || typeof any !== 'object') return null
|
|
99
|
-
const o = any as Record<string, unknown>
|
|
100
|
-
const tsRaw = o.ts
|
|
101
|
-
const tsIsValid = typeof tsRaw === 'number' || typeof tsRaw === 'bigint'
|
|
102
|
-
if (typeof o.id !== 'string' || typeof o.sender_id !== 'string'
|
|
103
|
-
|| typeof o.channel_doc_id !== 'string' || !tsIsValid) {
|
|
104
|
-
return null
|
|
105
|
-
}
|
|
106
|
-
const ts = typeof tsRaw === 'bigint' ? Number(tsRaw) : (tsRaw as number)
|
|
107
|
-
return {
|
|
108
|
-
record_kind: typeof o.record_kind === 'string' ? o.record_kind as MessageRecord['record_kind'] : 'message',
|
|
109
|
-
id: o.id,
|
|
110
|
-
target_id: typeof o.target_id === 'string' ? o.target_id : undefined,
|
|
111
|
-
sender_id: o.sender_id,
|
|
112
|
-
channel_doc_id: o.channel_doc_id,
|
|
113
|
-
period_id: typeof o.period_id === 'string' ? o.period_id : '',
|
|
114
|
-
ts,
|
|
115
|
-
content: typeof o.content === 'string' ? o.content : '',
|
|
116
|
-
mentions: Array.isArray(o.mentions) ? o.mentions as string[] : [],
|
|
117
|
-
reply_to: typeof o.reply_to === 'string' ? o.reply_to : null,
|
|
118
|
-
sig: typeof o.sig === 'string' ? o.sig : undefined,
|
|
119
|
-
server_sig: typeof o.server_sig === 'string' ? o.server_sig : undefined,
|
|
120
|
-
}
|
|
121
|
-
}
|