@instantdb/core
Advanced tools
Comparing version 0.10.31 to 0.10.32
@@ -98,4 +98,4 @@ /** | ||
_flushPendingMessages(): void; | ||
_send(eventId: any, msg: any): void; | ||
_forceSend(eventId: any, msg: any): void; | ||
_trySendAuthed(eventId: any, msg: any): void; | ||
_trySend(eventId: any, msg: any): void; | ||
_wsOnOpen: () => void; | ||
@@ -102,0 +102,0 @@ _wsOnMessage: (e: any) => void; |
@@ -34,2 +34,3 @@ // @ts-check | ||
}; | ||
const WS_OPEN_STATUS = 1; | ||
const defaultConfig = { | ||
@@ -165,3 +166,3 @@ apiURI: "https://api.instantdb.com", | ||
var _a; | ||
this._forceSend(uuid(), { | ||
this._trySend(uuid(), { | ||
op: "init", | ||
@@ -479,3 +480,3 @@ "app-id": this.config.appId, | ||
}); | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
const errorMessage = this._errorMessage; | ||
@@ -612,3 +613,3 @@ const prevResult = (_b = (_a = this.querySubs.currentValue) === null || _a === void 0 ? void 0 : _a[hash]) === null || _b === void 0 ? void 0 : _b.result; | ||
else { | ||
this._forceSend(eventId, mutation); | ||
this._trySend(eventId, mutation); | ||
// (XXX): If a transaction is pending for over 3 seconds, | ||
@@ -650,3 +651,3 @@ // we want to unblock the UX, so mark it as enqueued | ||
safeSubs.forEach(({ eventId, q }) => { | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
}); | ||
@@ -661,3 +662,3 @@ const muts = this._rewriteMutations(this.attrs, this.pendingMutations.currentValue); | ||
roomIds.forEach((roomId) => { | ||
this._send(uuid(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "join-room", "room-id": roomId }); | ||
}); | ||
@@ -669,12 +670,15 @@ const presence = Object.entries(this._presence); | ||
return; | ||
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: user }); | ||
this._trySendAuthed(uuid(), { op: "set-presence", "room-id": roomId, data: user }); | ||
}); | ||
} | ||
_send(eventId, msg) { | ||
_trySendAuthed(eventId, msg) { | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
return; | ||
} | ||
this._forceSend(eventId, msg); | ||
this._trySend(eventId, msg); | ||
} | ||
_forceSend(eventId, msg) { | ||
_trySend(eventId, msg) { | ||
if (this._ws.readyState !== WS_OPEN_STATUS) { | ||
return; | ||
} | ||
this._ws.send(JSON.stringify(Object.assign({ "client-event-id": eventId }, msg))); | ||
@@ -986,3 +990,3 @@ } | ||
joinRoom(roomId) { | ||
this._send(uuid(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "join-room", "room-id": roomId }); | ||
return () => { | ||
@@ -998,3 +1002,3 @@ this._cleanupRoom(roomId); | ||
delete this._broadcastSubs[roomId]; | ||
this._send(uuid(), { op: "leave-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "leave-room", "room-id": roomId }); | ||
} | ||
@@ -1027,3 +1031,3 @@ } | ||
const data = Object.assign(Object.assign({}, (_b = (_a = this._presence[roomId]) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.user), partialData); | ||
this._send(uuid(), { op: "set-presence", "room-id": roomId, data }); | ||
this._trySendAuthed(uuid(), { op: "set-presence", "room-id": roomId, data }); | ||
this._presence[roomId] = this._presence[roomId] || {}; | ||
@@ -1087,3 +1091,3 @@ this._presence[roomId].result = this._presence[roomId].result || {}; | ||
publishTopic({ roomType, roomId, topic, data }) { | ||
this._send(uuid(), { | ||
this._trySendAuthed(uuid(), { | ||
op: "client-broadcast", | ||
@@ -1090,0 +1094,0 @@ "room-id": roomId, |
@@ -98,4 +98,4 @@ /** | ||
_flushPendingMessages(): void; | ||
_send(eventId: any, msg: any): void; | ||
_forceSend(eventId: any, msg: any): void; | ||
_trySendAuthed(eventId: any, msg: any): void; | ||
_trySend(eventId: any, msg: any): void; | ||
_wsOnOpen: () => void; | ||
@@ -102,0 +102,0 @@ _wsOnMessage: (e: any) => void; |
@@ -62,2 +62,3 @@ "use strict"; | ||
}; | ||
const WS_OPEN_STATUS = 1; | ||
const defaultConfig = { | ||
@@ -193,3 +194,3 @@ apiURI: "https://api.instantdb.com", | ||
var _a; | ||
this._forceSend((0, uuid_1.default)(), { | ||
this._trySend((0, uuid_1.default)(), { | ||
op: "init", | ||
@@ -507,3 +508,3 @@ "app-id": this.config.appId, | ||
}); | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
const errorMessage = this._errorMessage; | ||
@@ -640,3 +641,3 @@ const prevResult = (_b = (_a = this.querySubs.currentValue) === null || _a === void 0 ? void 0 : _a[hash]) === null || _b === void 0 ? void 0 : _b.result; | ||
else { | ||
this._forceSend(eventId, mutation); | ||
this._trySend(eventId, mutation); | ||
// (XXX): If a transaction is pending for over 3 seconds, | ||
@@ -678,3 +679,3 @@ // we want to unblock the UX, so mark it as enqueued | ||
safeSubs.forEach(({ eventId, q }) => { | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
}); | ||
@@ -689,3 +690,3 @@ const muts = this._rewriteMutations(this.attrs, this.pendingMutations.currentValue); | ||
roomIds.forEach((roomId) => { | ||
this._send((0, uuid_1.default)(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed((0, uuid_1.default)(), { op: "join-room", "room-id": roomId }); | ||
}); | ||
@@ -697,12 +698,15 @@ const presence = Object.entries(this._presence); | ||
return; | ||
this._send((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data: user }); | ||
this._trySendAuthed((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data: user }); | ||
}); | ||
} | ||
_send(eventId, msg) { | ||
_trySendAuthed(eventId, msg) { | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
return; | ||
} | ||
this._forceSend(eventId, msg); | ||
this._trySend(eventId, msg); | ||
} | ||
_forceSend(eventId, msg) { | ||
_trySend(eventId, msg) { | ||
if (this._ws.readyState !== WS_OPEN_STATUS) { | ||
return; | ||
} | ||
this._ws.send(JSON.stringify(Object.assign({ "client-event-id": eventId }, msg))); | ||
@@ -1014,3 +1018,3 @@ } | ||
joinRoom(roomId) { | ||
this._send((0, uuid_1.default)(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed((0, uuid_1.default)(), { op: "join-room", "room-id": roomId }); | ||
return () => { | ||
@@ -1026,3 +1030,3 @@ this._cleanupRoom(roomId); | ||
delete this._broadcastSubs[roomId]; | ||
this._send((0, uuid_1.default)(), { op: "leave-room", "room-id": roomId }); | ||
this._trySendAuthed((0, uuid_1.default)(), { op: "leave-room", "room-id": roomId }); | ||
} | ||
@@ -1055,3 +1059,3 @@ } | ||
const data = Object.assign(Object.assign({}, (_b = (_a = this._presence[roomId]) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.user), partialData); | ||
this._send((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data }); | ||
this._trySendAuthed((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data }); | ||
this._presence[roomId] = this._presence[roomId] || {}; | ||
@@ -1115,3 +1119,3 @@ this._presence[roomId].result = this._presence[roomId].result || {}; | ||
publishTopic({ roomType, roomId, topic, data }) { | ||
this._send((0, uuid_1.default)(), { | ||
this._trySendAuthed((0, uuid_1.default)(), { | ||
op: "client-broadcast", | ||
@@ -1118,0 +1122,0 @@ "room-id": roomId, |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.10.31", | ||
"version": "0.10.32", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,2 +29,4 @@ // @ts-check | ||
const WS_OPEN_STATUS = 1; | ||
const defaultConfig = { | ||
@@ -451,3 +453,3 @@ apiURI: "https://api.instantdb.com", | ||
}); | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
const errorMessage = this._errorMessage; | ||
@@ -665,3 +667,3 @@ const prevResult = this.querySubs.currentValue?.[hash]?.result; | ||
} else { | ||
this._forceSend(eventId, mutation); | ||
this._trySend(eventId, mutation); | ||
@@ -710,3 +712,3 @@ // (XXX): If a transaction is pending for over 3 seconds, | ||
safeSubs.forEach(({ eventId, q }) => { | ||
this._send(eventId, { op: "add-query", q }); | ||
this._trySendAuthed(eventId, { op: "add-query", q }); | ||
}); | ||
@@ -724,3 +726,3 @@ const muts = this._rewriteMutations( | ||
roomIds.forEach((roomId) => { | ||
this._send(uuid(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "join-room", "room-id": roomId }); | ||
}); | ||
@@ -731,14 +733,17 @@ const presence = Object.entries(this._presence); | ||
if (!user) return; | ||
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: user }); | ||
this._trySendAuthed(uuid(), { op: "set-presence", "room-id": roomId, data: user }); | ||
}); | ||
} | ||
_send(eventId, msg) { | ||
_trySendAuthed(eventId, msg) { | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
return; | ||
} | ||
this._forceSend(eventId, msg); | ||
this._trySend(eventId, msg); | ||
} | ||
_forceSend(eventId, msg) { | ||
_trySend(eventId, msg) { | ||
if (this._ws.readyState !== WS_OPEN_STATUS) { | ||
return | ||
} | ||
this._ws.send(JSON.stringify({ "client-event-id": eventId, ...msg })); | ||
@@ -751,3 +756,3 @@ } | ||
this.getCurrentUser().then((resp) => { | ||
this._forceSend(uuid(), { | ||
this._trySend(uuid(), { | ||
op: "init", | ||
@@ -1114,3 +1119,3 @@ "app-id": this.config.appId, | ||
joinRoom(roomId) { | ||
this._send(uuid(), { op: "join-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "join-room", "room-id": roomId }); | ||
@@ -1129,3 +1134,3 @@ return () => { | ||
delete this._broadcastSubs[roomId]; | ||
this._send(uuid(), { op: "leave-room", "room-id": roomId }); | ||
this._trySendAuthed(uuid(), { op: "leave-room", "room-id": roomId }); | ||
} | ||
@@ -1168,3 +1173,3 @@ } | ||
this._send(uuid(), { op: "set-presence", "room-id": roomId, data }); | ||
this._trySendAuthed(uuid(), { op: "set-presence", "room-id": roomId, data }); | ||
@@ -1244,3 +1249,3 @@ this._presence[roomId] = this._presence[roomId] || {}; | ||
publishTopic({ roomType, roomId, topic, data }) { | ||
this._send(uuid(), { | ||
this._trySendAuthed(uuid(), { | ||
op: "client-broadcast", | ||
@@ -1247,0 +1252,0 @@ "room-id": roomId, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2861867
40794