@instantdb/core
Advanced tools
Comparing version 0.14.16 to 0.14.17
@@ -398,2 +398,54 @@ import { test, expect } from "vitest"; | ||
test("lookup doesn't override attrs for lookups in self links", () => { | ||
const refAttrId = uuid(); | ||
const postIdAttrId = uuid(); | ||
const postsSlugAttrId = uuid(); | ||
const attrs = { | ||
[postIdAttrId]: { | ||
id: postIdAttrId, | ||
"forward-identity": [uuid(), "posts", "id"], | ||
"value-type": "blob", | ||
cardinality: "one", | ||
"unique?": true, | ||
"index?": false, | ||
}, | ||
[postsSlugAttrId]: { | ||
id: postsSlugAttrId, | ||
"forward-identity": [uuid(), "posts", "slug"], | ||
"value-type": "blob", | ||
cardinality: "one", | ||
"unique?": true, | ||
"index?": true, | ||
}, | ||
[refAttrId]: { | ||
id: refAttrId, | ||
"forward-identity": [uuid(), "posts", "parent"], | ||
"reverse-identity": [uuid(), "posts", "child"], | ||
"value-type": "ref", | ||
cardinality: "one", | ||
"unique?": true, | ||
"index?": true, | ||
}, | ||
}; | ||
const ops1 = instatx.tx.posts[instatx.lookup("slug", "life-is-good")] | ||
.update({}) | ||
.link({ parent: instatx.lookup("slug", "life-is-good") }); | ||
const result1 = instaml.transform(attrs, ops1); | ||
expect(result1.filter((x) => x[0] !== "add-triple")).toEqual([]); | ||
const ops2 = instatx.tx.posts[instatx.lookup("slug", "life-is-good")] | ||
.update({}) | ||
.link({ child: instatx.lookup("slug", "life-is-good") }); | ||
const result2 = instaml.transform(attrs, ops2); | ||
expect(result2.filter((x) => x[0] !== "add-triple")).toEqual([]); | ||
}); | ||
test("lookup creates unique ref attrs for ref lookup", () => { | ||
@@ -400,0 +452,0 @@ const uid = uuid(); |
@@ -39,3 +39,3 @@ // https://www.npmjs.com/package/fake-indexeddb | ||
// Initialize the store | ||
reactor._handleReceive({ | ||
reactor._handleReceive(0, { | ||
op: "add-query-ok", | ||
@@ -42,0 +42,0 @@ q, |
@@ -94,3 +94,3 @@ /** | ||
_flushEnqueuedRoomData(roomId: any): void; | ||
_handleReceive(msg: any): void; | ||
_handleReceive(wsId: any, msg: any): void; | ||
_sessionId: any; | ||
@@ -157,4 +157,4 @@ /** | ||
_flushPendingMessages(): void; | ||
_trySendAuthed(eventId: any, msg: any): void; | ||
_trySend(eventId: any, msg: any): void; | ||
_trySendAuthed(...args: any[]): void; | ||
_trySend(eventId: any, msg: any, opts: any): void; | ||
_wsOnOpen: (e: any) => void; | ||
@@ -161,0 +161,0 @@ _wsOnMessage: (e: any) => void; |
@@ -58,2 +58,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
const ignoreLogging = { | ||
"set-presence": true, | ||
"set-presence-ok": true, | ||
"refresh-presence": true, | ||
}; | ||
function querySubsFromJSON(str) { | ||
@@ -263,3 +268,3 @@ var _a; | ||
} | ||
this._handleReceive(JSON.parse(e.data.toString())); | ||
this._handleReceive(targetWs._id, JSON.parse(e.data.toString())); | ||
}; | ||
@@ -419,3 +424,3 @@ this._wsOnError = (e) => { | ||
} | ||
_handleReceive(msg) { | ||
_handleReceive(wsId, msg) { | ||
var _a, _b, _c, _d; | ||
@@ -427,2 +432,5 @@ // opt-out, enabled by default if schema | ||
: true); | ||
if (!ignoreLogging[msg.op]) { | ||
log.info("[receive]", wsId, msg.op, msg); | ||
} | ||
switch (msg.op) { | ||
@@ -907,12 +915,15 @@ case "init-ok": | ||
} | ||
_trySendAuthed(eventId, msg) { | ||
_trySendAuthed(...args) { | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
return; | ||
} | ||
this._trySend(eventId, msg); | ||
this._trySend(...args); | ||
} | ||
_trySend(eventId, msg) { | ||
_trySend(eventId, msg, opts) { | ||
if (this._ws.readyState !== WS_OPEN_STATUS) { | ||
return; | ||
} | ||
if (!ignoreLogging[msg.op]) { | ||
log.info("[send]", this._ws._id, msg.op, msg); | ||
} | ||
this._ws.send(JSON.stringify(Object.assign({ "client-event-id": eventId }, msg))); | ||
@@ -919,0 +930,0 @@ } |
@@ -94,3 +94,3 @@ /** | ||
_flushEnqueuedRoomData(roomId: any): void; | ||
_handleReceive(msg: any): void; | ||
_handleReceive(wsId: any, msg: any): void; | ||
_sessionId: any; | ||
@@ -157,4 +157,4 @@ /** | ||
_flushPendingMessages(): void; | ||
_trySendAuthed(eventId: any, msg: any): void; | ||
_trySend(eventId: any, msg: any): void; | ||
_trySendAuthed(...args: any[]): void; | ||
_trySend(eventId: any, msg: any, opts: any): void; | ||
_wsOnOpen: (e: any) => void; | ||
@@ -161,0 +161,0 @@ _wsOnMessage: (e: any) => void; |
{ | ||
"name": "@instantdb/core", | ||
"version": "v0.14.16", | ||
"version": "v0.14.17", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -59,2 +59,8 @@ // @ts-check | ||
const ignoreLogging = { | ||
"set-presence": true, | ||
"set-presence-ok": true, | ||
"refresh-presence": true, | ||
}; | ||
function querySubsFromJSON(str) { | ||
@@ -353,3 +359,3 @@ const parsed = JSON.parse(str); | ||
_handleReceive(msg) { | ||
_handleReceive(wsId, msg) { | ||
// opt-out, enabled by default if schema | ||
@@ -361,3 +367,5 @@ const enableCardinalityInference = | ||
: true); | ||
if (!ignoreLogging[msg.op]) { | ||
log.info("[receive]", wsId, msg.op, msg); | ||
} | ||
switch (msg.op) { | ||
@@ -1014,13 +1022,16 @@ case "init-ok": | ||
_trySendAuthed(eventId, msg) { | ||
_trySendAuthed(...args) { | ||
if (this.status !== STATUS.AUTHENTICATED) { | ||
return; | ||
} | ||
this._trySend(eventId, msg); | ||
this._trySend(...args); | ||
} | ||
_trySend(eventId, msg) { | ||
_trySend(eventId, msg, opts) { | ||
if (this._ws.readyState !== WS_OPEN_STATUS) { | ||
return; | ||
} | ||
if (!ignoreLogging[msg.op]) { | ||
log.info("[send]", this._ws._id, msg.op, msg); | ||
} | ||
this._ws.send(JSON.stringify({ "client-event-id": eventId, ...msg })); | ||
@@ -1068,3 +1079,3 @@ } | ||
} | ||
this._handleReceive(JSON.parse(e.data.toString())); | ||
this._handleReceive(targetWs._id, JSON.parse(e.data.toString())); | ||
}; | ||
@@ -1163,3 +1174,8 @@ | ||
// c.f https://issues.chromium.org/issues/41343684 | ||
log.info("[socket][start]", this._ws._id, "close previous ws id = ", prevWs._id) | ||
log.info( | ||
"[socket][start]", | ||
this._ws._id, | ||
"close previous ws id = ", | ||
prevWs._id, | ||
); | ||
prevWs.close(); | ||
@@ -1166,0 +1182,0 @@ } |
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 too big to display
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 too big to display
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
2426794
42680