@oxidezap/baileyrs 0.3.10 → 0.3.12
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/lib/Bridge/schema.js +42 -16
- package/lib/Bridge/types.d.ts +13 -2
- package/lib/Compatibility/auth-state.js +2 -11
- package/lib/Compatibility/host-auth-state.js +2 -0
- package/lib/Compatibility/internal/auth-state.js +6 -0
- package/lib/Compatibility/internal/host-auth-state.js +3 -0
- package/lib/Compatibility/legacy-store/adapter.js +137 -3
- package/lib/Compatibility/legacy-store/codecs/basic.js +5 -8
- package/lib/Compatibility/legacy-store/multi-file.d.ts +12 -1
- package/lib/Compatibility/legacy-store/multi-file.js +37 -25
- package/lib/Compatibility/legacy-store/record-files.d.ts +3 -0
- package/lib/Compatibility/legacy-store/record-files.js +5 -0
- package/lib/Compatibility/legacy-store/rollback.d.ts +8 -0
- package/lib/Compatibility/legacy-store/rollback.js +16 -0
- package/lib/Compatibility/legacy-store/snapshot.d.ts +7 -0
- package/lib/Compatibility/legacy-store/snapshot.js +53 -0
- package/lib/Compatibility/legacy-store/types.d.ts +4 -1
- package/lib/Socket/chat-actions.js +1 -1
- package/lib/Socket/events-core.js +9 -1
- package/lib/Socket/index.d.ts +3 -717
- package/lib/Types/Auth.d.ts +5 -0
- package/lib/Types/Events.d.ts +6 -1
- package/lib/Utils/atomic-store.d.ts +20 -0
- package/lib/Utils/atomic-store.js +116 -0
- package/lib/Utils/durable-directory.d.ts +3 -0
- package/lib/Utils/durable-directory.js +35 -0
- package/lib/Utils/flush-deadline.d.ts +19 -0
- package/lib/Utils/flush-deadline.js +97 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/native-auth-rollback.d.ts +14 -0
- package/lib/Utils/native-auth-rollback.js +17 -0
- package/lib/Utils/process-file-lock.d.ts +6 -0
- package/lib/Utils/process-file-lock.js +38 -0
- package/lib/Utils/snapshot-rollback-proof.d.ts +9 -0
- package/lib/Utils/snapshot-rollback-proof.js +43 -0
- package/lib/Utils/snapshot-rollback.d.ts +5 -0
- package/lib/Utils/snapshot-rollback.js +69 -0
- package/lib/Utils/snapshot-transactions.d.ts +10 -0
- package/lib/Utils/snapshot-transactions.js +108 -0
- package/lib/Utils/store-migration.d.ts +10 -0
- package/lib/Utils/store-migration.js +16 -0
- package/lib/Utils/transactional-file-store.d.ts +7 -0
- package/lib/Utils/transactional-file-store.js +157 -0
- package/lib/Utils/use-bridge-store.d.ts +3 -49
- package/lib/Utils/use-bridge-store.js +121 -109
- package/lib/Utils/use-memory-store.js +17 -4
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.js +2 -2
- package/lib/Utils/wrap-legacy-store.d.ts +1 -0
- package/lib/Utils/wrap-legacy-store.js +1 -0
- package/lib/host-types.d.ts +1 -15
- package/lib/node-surface.d.ts +2 -1
- package/lib/node-surface.js +2 -1
- package/package.json +12 -10
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isLegacyAuthRecordFile } from './record-files.js';
|
|
2
|
+
import { requireOfflineMigration } from '../../Utils/store-migration.js';
|
|
3
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { createSnapshotTransactions } from '../../Utils/snapshot-transactions.js';
|
|
6
|
+
import { defaultSyncDir } from '../../Utils/durable-directory.js';
|
|
7
|
+
import { rowKey } from '../../Utils/atomic-store.js';
|
|
8
|
+
import { BufferJSON } from '../../Utils/generics.js';
|
|
9
|
+
/** All legacy and native-mirror writes share the same persistent snapshot.
|
|
10
|
+
* The original JSON files are migration backups after the first commit.
|
|
11
|
+
*/
|
|
12
|
+
export const legacySnapshotKeys = async (folder, fileName, options = {}) => {
|
|
13
|
+
await requireOfflineMigration(folder, 'bridge-legacy-v1.json', isLegacyAuthRecordFile, options);
|
|
14
|
+
const store = createSnapshotTransactions(folder, 'bridge-legacy-v1.json', new Set(['legacy']), async () => {
|
|
15
|
+
await requireOfflineMigration(folder, 'bridge-legacy-v1.json', isLegacyAuthRecordFile, options);
|
|
16
|
+
const rows = new Map();
|
|
17
|
+
for (const name of await readdir(folder)) {
|
|
18
|
+
if (!isLegacyAuthRecordFile(name))
|
|
19
|
+
continue;
|
|
20
|
+
rows.set(rowKey('legacy', name), await readFile(join(folder, name)));
|
|
21
|
+
}
|
|
22
|
+
return rows;
|
|
23
|
+
}, defaultSyncDir);
|
|
24
|
+
const decode = (bytes) => bytes ? JSON.parse(Buffer.from(bytes).toString(), BufferJSON.reviver) : null;
|
|
25
|
+
const transactionView = (rows, mutated) => ({
|
|
26
|
+
get: async (type, ids) => Object.fromEntries(ids.map(id => [id, decode(rows.get(rowKey('legacy', fileName(type, id))))])),
|
|
27
|
+
set: async (data) => {
|
|
28
|
+
for (const [type, values] of Object.entries(data))
|
|
29
|
+
for (const [id, value] of Object.entries(values ?? {})) {
|
|
30
|
+
const key = rowKey('legacy', fileName(type, id));
|
|
31
|
+
mutated();
|
|
32
|
+
if (value == null)
|
|
33
|
+
rows.delete(key);
|
|
34
|
+
else
|
|
35
|
+
rows.set(key, Buffer.from(JSON.stringify(value, BufferJSON.replacer)));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const transaction = (work) => {
|
|
40
|
+
let dirty = false;
|
|
41
|
+
return store.transaction(rows => work(transactionView(rows, () => {
|
|
42
|
+
dirty = true;
|
|
43
|
+
})), () => dirty);
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
get: async (type, ids) => Object.fromEntries(await Promise.all(ids.map(async (id) => [id, decode(await store.read(rows => rows.get(rowKey('legacy', fileName(type, id)))))]))),
|
|
47
|
+
set: data => transaction(async (keys) => {
|
|
48
|
+
await keys.set(data);
|
|
49
|
+
}),
|
|
50
|
+
bridgeTransaction: transaction
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -11,9 +11,12 @@ type Awaitable<T> = T | PromiseLike<T>;
|
|
|
11
11
|
export type LegacyKeysStore = {
|
|
12
12
|
get(type: string, ids: string[]): Awaitable<Record<string, unknown>>;
|
|
13
13
|
set(data: Record<string, Record<string, unknown>>): Awaitable<void>;
|
|
14
|
+
bridgeTransaction?<T>(work: (keys: LegacyKeysStore) => Promise<T>): Promise<T>;
|
|
14
15
|
};
|
|
15
16
|
export interface WrappedLegacyStore extends JsStoreCallbacks {
|
|
16
|
-
/**
|
|
17
|
+
/** Drain admitted callbacks and their durable commit barriers. A 30s timeout
|
|
18
|
+
* leaves backend operations pending. Await a later successful flush before
|
|
19
|
+
* deleting auth state or starting an older writer. */
|
|
17
20
|
flush(): Promise<void>;
|
|
18
21
|
/** Kept for socket lifecycle compatibility. The adapter owns no background resources. */
|
|
19
22
|
dispose(): void;
|
|
@@ -58,7 +58,7 @@ export const makeChatActionMethods = (ctx) => {
|
|
|
58
58
|
await client.deleteChat(jid);
|
|
59
59
|
}
|
|
60
60
|
else if ('deleteForMe' in mod) {
|
|
61
|
-
await client.deleteMessageForMe(jid, mod.deleteForMe.key.id, !!mod.deleteForMe.key.fromMe);
|
|
61
|
+
await client.deleteMessageForMe(jid, mod.deleteForMe.key.id, !!mod.deleteForMe.key.fromMe, mod.deleteForMe.key.participant);
|
|
62
62
|
}
|
|
63
63
|
else if ('pushNameSetting' in mod) {
|
|
64
64
|
await client.setPushName(mod.pushNameSetting);
|
|
@@ -630,17 +630,23 @@ const DISPATCHERS = {
|
|
|
630
630
|
ctx.ev.emit('chats.update', [{ id: evt.jid, unreadCount: evt.read ? 0 : -1 }]),
|
|
631
631
|
// Upstream `chat-utils.ts:819` emits `chats.lock` from `lockChatAction.locked`.
|
|
632
632
|
lockChatUpdate: (evt, { ctx }) => ctx.ev.emit('chats.lock', { id: evt.jid, locked: evt.locked }),
|
|
633
|
+
labelSublist: (evt, { ctx }) => {
|
|
634
|
+
const { type: _type, ...update } = evt;
|
|
635
|
+
ctx.ev.emit('labels.sublist', update);
|
|
636
|
+
},
|
|
633
637
|
labelEdit: (evt, { ctx }) =>
|
|
634
638
|
// Upstream `labels.edit` carries a `Label`. A delete arrives with
|
|
635
639
|
// `deleted: true` (consumers remove it from their store).
|
|
636
640
|
ctx.ev.emit('labels.edit', {
|
|
637
641
|
id: evt.labelId,
|
|
642
|
+
...(evt.actionTimestamp !== undefined ? { actionTimestamp: evt.actionTimestamp } : {}),
|
|
638
643
|
name: evt.name,
|
|
639
644
|
color: evt.color,
|
|
640
645
|
deleted: evt.deleted,
|
|
641
646
|
predefinedId: evt.predefinedId
|
|
642
647
|
}),
|
|
643
648
|
labelAssociation: (evt, { ctx }) => ctx.ev.emit('labels.association', {
|
|
649
|
+
...(evt.actionTimestamp !== undefined ? { actionTimestamp: evt.actionTimestamp } : {}),
|
|
644
650
|
// The two halves arrive on separate bridge events and upstream tells
|
|
645
651
|
// them apart by the association's own type, so a message id is what
|
|
646
652
|
// decides which of the two shapes this is.
|
|
@@ -693,7 +699,9 @@ const DISPATCHERS = {
|
|
|
693
699
|
from: evt.action.callCreator ?? evt.from,
|
|
694
700
|
...(evt.action.callCreator ? { callCreator: evt.action.callCreator } : {}),
|
|
695
701
|
id: evt.action.callId,
|
|
696
|
-
|
|
702
|
+
// Upstream uses new Date(+attrs.t * 1000), including Invalid Date
|
|
703
|
+
// when t is absent. Preserve that contract without inventing a time.
|
|
704
|
+
date: new Date((evt.timestamp ?? Number.NaN) * 1000),
|
|
697
705
|
status,
|
|
698
706
|
offline: evt.offline,
|
|
699
707
|
isGroup,
|