Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@instantdb/core

Package Overview
Dependencies
Maintainers
3
Versions
205
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@instantdb/core - npm Package Compare versions

Comparing version 0.7.3 to 0.7.4

6

dist/module/Reactor.d.ts

@@ -19,2 +19,3 @@ export default class Reactor {

_errorMessage: any;
___presence: {};
_setStatus(status: any, err: any): void;

@@ -39,2 +40,3 @@ /**

_handleReceive(msg: any): void;
_sessionId: any;
_setAttrs(attrs: any): void;

@@ -111,2 +113,6 @@ /**

signOut(): void;
___setPresence(roomId: any, newMe: any): void;
___subscribePresence(roomId: any, cb: any): () => void;
___setOthers(roomId: any, data: any): void;
___notifyPresenceSubs(roomId: any): void;
}

@@ -113,0 +119,0 @@ declare class PersistedObject {

77

dist/module/Reactor.js

@@ -115,2 +115,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

this._errorMessage = null;
// (XXX-EPH): Keeping track of roomId -> { result, cbs } here
this.___presence = {};
/**

@@ -310,2 +312,5 @@ * merge querySubs from storage and in memory. Has the following side

this._flushPendingMessages();
// (XXX-EPH): set session-id, so we know
// which item is us
this._sessionId = msg["session-id"];
break;

@@ -363,2 +368,14 @@ case "add-query-ok":

break;
case "presence-refresh":
const roomId = msg["room-id"];
this.___setOthers(roomId, msg.data);
this.___notifyPresenceSubs(roomId);
break;
case "subscribe-presence-ok":
case "set-presence-ok":
// (XXX-EPH): Right now we will get a presence-refresh
// anyways, so there is no need to do anything for
// these actions. Makes me wonder if we should even
// have these actions.
break;
case "error":

@@ -582,2 +599,15 @@ // (XXX): Error handling is spaghetti right now.

});
// (XXX-EPH): Resubscribe to presence
const roomIds = Object.keys(this.___presence);
roomIds.forEach((roomId) => {
this._send(uuid(), { op: "subscribe-presence", "room-id": roomId });
});
// (XXX-EPH): Resend `me`
const presence = Object.entries(this.___presence);
presence.forEach(([roomId, { result }]) => {
const me = result === null || result === void 0 ? void 0 : result.me;
if (!me)
return;
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: me });
});
}

@@ -716,3 +746,50 @@ _send(eventId, msg) {

}
// ---------------------------
// Presence Hacking
// Prototyping out a demo for presence
// This will change like crazy
___setPresence(roomId, newMe) {
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: newMe });
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.me = newMe;
this.___notifyPresenceSubs(roomId, newMe);
}
___subscribePresence(roomId, cb) {
const eventId = uuid();
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].cbs = this.___presence[roomId].cbs || [];
this.___presence[roomId].cbs.push(cb);
this._send(eventId, { op: "subscribe-presence", "room-id": roomId });
// (XXX-EPH)
// What if there was a previous result?
return () => {
this.___presence[roomId].cbs = this.___presence[roomId].cbs.filter((x) => x !== cb);
};
}
___setOthers(roomId, data) {
const othersObj = data;
// no need to keep track of `me`
delete othersObj[this._sessionId];
const others = Object.keys(othersObj).map((k) => {
const other = othersObj[k];
other.sessionId = k;
return other;
});
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.others = others;
}
___notifyPresenceSubs(roomId) {
// get cbs, cut into me and others, and call cbs
const p = this.___presence[roomId];
if (!p)
return;
const { cbs, result } = p;
if (!cbs || !result)
return;
const { me, others } = result;
cbs.forEach((cb) => cb({ data: { me, others } }));
}
}
//# sourceMappingURL=Reactor.js.map

@@ -19,2 +19,3 @@ export default class Reactor {

_errorMessage: any;
___presence: {};
_setStatus(status: any, err: any): void;

@@ -39,2 +40,3 @@ /**

_handleReceive(msg: any): void;
_sessionId: any;
_setAttrs(attrs: any): void;

@@ -111,2 +113,6 @@ /**

signOut(): void;
___setPresence(roomId: any, newMe: any): void;
___subscribePresence(roomId: any, cb: any): () => void;
___setOthers(roomId: any, data: any): void;
___notifyPresenceSubs(roomId: any): void;
}

@@ -113,0 +119,0 @@ declare class PersistedObject {

@@ -143,2 +143,4 @@ "use strict";

this._errorMessage = null;
// (XXX-EPH): Keeping track of roomId -> { result, cbs } here
this.___presence = {};
/**

@@ -338,2 +340,5 @@ * merge querySubs from storage and in memory. Has the following side

this._flushPendingMessages();
// (XXX-EPH): set session-id, so we know
// which item is us
this._sessionId = msg["session-id"];
break;

@@ -391,2 +396,14 @@ case "add-query-ok":

break;
case "presence-refresh":
const roomId = msg["room-id"];
this.___setOthers(roomId, msg.data);
this.___notifyPresenceSubs(roomId);
break;
case "subscribe-presence-ok":
case "set-presence-ok":
// (XXX-EPH): Right now we will get a presence-refresh
// anyways, so there is no need to do anything for
// these actions. Makes me wonder if we should even
// have these actions.
break;
case "error":

@@ -610,2 +627,15 @@ // (XXX): Error handling is spaghetti right now.

});
// (XXX-EPH): Resubscribe to presence
const roomIds = Object.keys(this.___presence);
roomIds.forEach((roomId) => {
this._send((0, uuid_1.default)(), { op: "subscribe-presence", "room-id": roomId });
});
// (XXX-EPH): Resend `me`
const presence = Object.entries(this.___presence);
presence.forEach(([roomId, { result }]) => {
const me = result === null || result === void 0 ? void 0 : result.me;
if (!me)
return;
this._send((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data: me });
});
}

@@ -744,4 +774,51 @@ _send(eventId, msg) {

}
// ---------------------------
// Presence Hacking
// Prototyping out a demo for presence
// This will change like crazy
___setPresence(roomId, newMe) {
this._send((0, uuid_1.default)(), { op: "set-presence", "room-id": roomId, data: newMe });
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.me = newMe;
this.___notifyPresenceSubs(roomId, newMe);
}
___subscribePresence(roomId, cb) {
const eventId = (0, uuid_1.default)();
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].cbs = this.___presence[roomId].cbs || [];
this.___presence[roomId].cbs.push(cb);
this._send(eventId, { op: "subscribe-presence", "room-id": roomId });
// (XXX-EPH)
// What if there was a previous result?
return () => {
this.___presence[roomId].cbs = this.___presence[roomId].cbs.filter((x) => x !== cb);
};
}
___setOthers(roomId, data) {
const othersObj = data;
// no need to keep track of `me`
delete othersObj[this._sessionId];
const others = Object.keys(othersObj).map((k) => {
const other = othersObj[k];
other.sessionId = k;
return other;
});
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.others = others;
}
___notifyPresenceSubs(roomId) {
// get cbs, cut into me and others, and call cbs
const p = this.___presence[roomId];
if (!p)
return;
const { cbs, result } = p;
if (!cbs || !result)
return;
const { me, others } = result;
cbs.forEach((cb) => cb({ data: { me, others } }));
}
}
exports.default = Reactor;
//# sourceMappingURL=Reactor.js.map

2

package.json
{
"name": "@instantdb/core",
"version": "0.7.3",
"version": "0.7.4",
"description": "Instant's core local abstraction",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -132,2 +132,5 @@ import log from "./utils/log";

// (XXX-EPH): Keeping track of roomId -> { result, cbs } here
___presence = {};
constructor(

@@ -276,2 +279,5 @@ config,

this._flushPendingMessages();
// (XXX-EPH): set session-id, so we know
// which item is us
this._sessionId = msg["session-id"];
break;

@@ -332,2 +338,14 @@ case "add-query-ok":

break;
case "presence-refresh":
const roomId = msg["room-id"];
this.___setOthers(roomId, msg.data);
this.___notifyPresenceSubs(roomId);
break;
case "subscribe-presence-ok":
case "set-presence-ok":
// (XXX-EPH): Right now we will get a presence-refresh
// anyways, so there is no need to do anything for
// these actions. Makes me wonder if we should even
// have these actions.
break;
case "error":

@@ -630,2 +648,14 @@ // (XXX): Error handling is spaghetti right now.

});
// (XXX-EPH): Resubscribe to presence
const roomIds = Object.keys(this.___presence);
roomIds.forEach((roomId) => {
this._send(uuid(), { op: "subscribe-presence", "room-id": roomId });
});
// (XXX-EPH): Resend `me`
const presence = Object.entries(this.___presence);
presence.forEach(([roomId, { result }]) => {
const me = result?.me;
if (!me) return;
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: me });
});
}

@@ -820,2 +850,55 @@

}
// ---------------------------
// Presence Hacking
// Prototyping out a demo for presence
// This will change like crazy
___setPresence(roomId, newMe) {
this._send(uuid(), { op: "set-presence", "room-id": roomId, data: newMe });
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.me = newMe;
this.___notifyPresenceSubs(roomId, newMe);
}
___subscribePresence(roomId, cb) {
const eventId = uuid();
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].cbs = this.___presence[roomId].cbs || [];
this.___presence[roomId].cbs.push(cb);
this._send(eventId, { op: "subscribe-presence", "room-id": roomId });
// (XXX-EPH)
// What if there was a previous result?
return () => {
this.___presence[roomId].cbs = this.___presence[roomId].cbs.filter(
(x) => x !== cb,
);
};
}
___setOthers(roomId, data) {
const othersObj = data;
// no need to keep track of `me`
delete othersObj[this._sessionId];
const others = Object.keys(othersObj).map((k) => {
const other = othersObj[k];
other.sessionId = k;
return other;
});
this.___presence[roomId] = this.___presence[roomId] || {};
this.___presence[roomId].result = this.___presence[roomId].result || {};
this.___presence[roomId].result.others = others;
}
___notifyPresenceSubs(roomId) {
// get cbs, cut into me and others, and call cbs
const p = this.___presence[roomId];
if (!p) return;
const { cbs, result } = p;
if (!cbs || !result) return;
const { me, others } = result;
cbs.forEach((cb) => cb({ data: { me, others } }));
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc