@massalabs/gossip-sdk 0.0.2-dev.20260225123954 → 0.0.2-dev.20260225142738
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/dist/db/migrate.js +10 -1
- package/dist/services/message.js +8 -11
- package/dist/services/refresh.js +5 -1
- package/package.json +1 -1
package/dist/db/migrate.js
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* a failure at migration N leaves 0..N-1 committed.
|
|
7
7
|
*/
|
|
8
8
|
import { MIGRATIONS } from './generated-migrations.js';
|
|
9
|
+
function makeCreateStatementsIdempotent(statement) {
|
|
10
|
+
if (/^\s*CREATE\s+TABLE\s+(?!IF\s+NOT\s+EXISTS)/i.test(statement)) {
|
|
11
|
+
return statement.replace(/^(\s*CREATE\s+TABLE\s+)/i, '$1IF NOT EXISTS ');
|
|
12
|
+
}
|
|
13
|
+
if (/^\s*CREATE\s+(UNIQUE\s+)?INDEX\s+(?!IF\s+NOT\s+EXISTS)/i.test(statement)) {
|
|
14
|
+
return statement.replace(/^(\s*CREATE\s+(?:UNIQUE\s+)?INDEX\s+)/i, '$1IF NOT EXISTS ');
|
|
15
|
+
}
|
|
16
|
+
return statement;
|
|
17
|
+
}
|
|
9
18
|
export async function runMigrations(execRaw, withTransaction) {
|
|
10
19
|
await execRaw(`CREATE TABLE IF NOT EXISTS _migrations (
|
|
11
20
|
idx INTEGER PRIMARY KEY,
|
|
@@ -18,7 +27,7 @@ export async function runMigrations(execRaw, withTransaction) {
|
|
|
18
27
|
for (const migration of pending) {
|
|
19
28
|
await withTransaction(async () => {
|
|
20
29
|
for (const stmt of migration.statements) {
|
|
21
|
-
await execRaw(stmt);
|
|
30
|
+
await execRaw(makeCreateStatementsIdempotent(stmt));
|
|
22
31
|
}
|
|
23
32
|
await execRaw('INSERT INTO _migrations (idx, tag, applied_at) VALUES (?, ?, ?)', [migration.idx, migration.tag, Date.now()]);
|
|
24
33
|
});
|
package/dist/services/message.js
CHANGED
|
@@ -581,15 +581,14 @@ export class MessageService {
|
|
|
581
581
|
}
|
|
582
582
|
const peerId = decodeUserId(contactUserId);
|
|
583
583
|
const sessionStatus = this.session.peerSessionStatus(peerId);
|
|
584
|
-
if (
|
|
585
|
-
log.info('session not active
|
|
584
|
+
if (sessionStatus !== SessionStatus.Active) {
|
|
585
|
+
log.info('session not active, skipping send queue', {
|
|
586
586
|
contactUserId,
|
|
587
587
|
sessionStatus: sessionStatusToString(sessionStatus),
|
|
588
588
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
};
|
|
589
|
+
// Not an error: queued messages should remain pending until the
|
|
590
|
+
// handshake reaches Active.
|
|
591
|
+
return { success: true, data: 0 };
|
|
593
592
|
}
|
|
594
593
|
// retrieve all messages in send queue that need to be updated for this contact
|
|
595
594
|
const pendingMessages = (await this.queries.messages.getSendQueue(ownerUserId, contactUserId)).map(rowToMessage);
|
|
@@ -630,13 +629,11 @@ export class MessageService {
|
|
|
630
629
|
/* Encrypt message*/
|
|
631
630
|
const sendOutput = await this.session.sendMessage(peerId, serializedContent);
|
|
632
631
|
if (!sendOutput) {
|
|
633
|
-
log.
|
|
632
|
+
log.info('session manager returned null for queued message; will retry later', {
|
|
634
633
|
messageId: msg.id,
|
|
635
634
|
});
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
error: new Error('Session manager returned null for queued message'),
|
|
639
|
-
};
|
|
635
|
+
// Treat as transient and keep message in WAITING_SESSION.
|
|
636
|
+
continue;
|
|
640
637
|
}
|
|
641
638
|
encryptedMessage = sendOutput.data;
|
|
642
639
|
seeker = sendOutput.seeker;
|
package/dist/services/refresh.js
CHANGED
|
@@ -157,8 +157,12 @@ export class RefreshService {
|
|
|
157
157
|
});
|
|
158
158
|
await this.announcementService.processOutgoingAnnouncements(activePendingDiscussions);
|
|
159
159
|
// Step 3: send queued messages and keep-alives
|
|
160
|
+
// NOTE: only flush queued messages once the session is fully Active.
|
|
161
|
+
// SelfRequested means the handshake is still establishing and
|
|
162
|
+
// session.sendMessage() can return null.
|
|
163
|
+
const activeEstablishedDiscussions = activePendingDiscussions.filter(discussion => this.session.peerSessionStatus(decodeUserId(discussion.contactUserId)) === SessionStatus.Active);
|
|
160
164
|
const keepAliveSet = new Set(keepAlivePeerIds);
|
|
161
|
-
for (const discussion of
|
|
165
|
+
for (const discussion of activeEstablishedDiscussions) {
|
|
162
166
|
if (!discussion.weAccepted)
|
|
163
167
|
continue;
|
|
164
168
|
// Send keep alive message if needed
|
package/package.json
CHANGED