@instantdb/core
Advanced tools
Comparing version 0.7.6 to 0.7.7
@@ -41,2 +41,3 @@ "use strict"; | ||
const VAL_VAR = makeVar("val"); | ||
const TIME_VAR = makeVar("time"); | ||
// Where | ||
@@ -59,6 +60,7 @@ // ----------------- | ||
makeVar(etype, level), | ||
TIME_VAR, | ||
]; | ||
} | ||
function attrWhere(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -82,4 +84,4 @@ function replaceInAttrPat(attrPat, needle, v) { | ||
const attrPat = fwdAttr | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel)] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level)]; | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel), TIME_VAR] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level), TIME_VAR]; | ||
const nextEtype = fwdAttr ? revEtype : fwdEtype; | ||
@@ -93,3 +95,3 @@ return [nextEtype, nextLevel, attrPat]; | ||
} | ||
return [makeVar(valueEtype, valueLevel), attr.id, v]; | ||
return [makeVar(valueEtype, valueLevel), attr.id, v, TIME_VAR]; | ||
} | ||
@@ -124,3 +126,3 @@ function refAttrPats(store, etype, level, refsPath) { | ||
function makeFind(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -140,3 +142,7 @@ // Relations | ||
function runDatalog(store, dq) { | ||
return (0, datalog_1.query)(store, dq).reduce((res, [e, a, v]) => { | ||
return (0, datalog_1.query)(store, dq).sort((tripleA, tripleB) => { | ||
const tsA = tripleA[3]; | ||
const tsB = tripleB[3]; | ||
return new Date(tsA) - new Date(tsB); | ||
}).reduce((res, [e, a, v]) => { | ||
if (ignoredAttr(store.attrs, a)) { | ||
@@ -175,5 +181,2 @@ return res; | ||
return (Object.entries(parents) | ||
// (XXX): We sort to prevent instaql results from being reordered | ||
// on refresh | ||
.sort((a, b) => (a[0] > b[0] ? 1 : -1)) | ||
.map(([eid, parent]) => { | ||
@@ -180,0 +183,0 @@ const childResults = children.map((label) => { |
@@ -39,2 +39,3 @@ import { query as datalogQuery } from "./datalog"; | ||
const VAL_VAR = makeVar("val"); | ||
const TIME_VAR = makeVar("time"); | ||
// Where | ||
@@ -57,6 +58,7 @@ // ----------------- | ||
makeVar(etype, level), | ||
TIME_VAR, | ||
]; | ||
} | ||
function attrWhere(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -80,4 +82,4 @@ function replaceInAttrPat(attrPat, needle, v) { | ||
const attrPat = fwdAttr | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel)] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level)]; | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel), TIME_VAR] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level), TIME_VAR]; | ||
const nextEtype = fwdAttr ? revEtype : fwdEtype; | ||
@@ -91,3 +93,3 @@ return [nextEtype, nextLevel, attrPat]; | ||
} | ||
return [makeVar(valueEtype, valueLevel), attr.id, v]; | ||
return [makeVar(valueEtype, valueLevel), attr.id, v, TIME_VAR]; | ||
} | ||
@@ -122,3 +124,3 @@ function refAttrPats(store, etype, level, refsPath) { | ||
function makeFind(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -138,3 +140,7 @@ // Relations | ||
function runDatalog(store, dq) { | ||
return datalogQuery(store, dq).reduce((res, [e, a, v]) => { | ||
return datalogQuery(store, dq).sort((tripleA, tripleB) => { | ||
const tsA = tripleA[3]; | ||
const tsB = tripleB[3]; | ||
return new Date(tsA) - new Date(tsB); | ||
}).reduce((res, [e, a, v]) => { | ||
if (ignoredAttr(store.attrs, a)) { | ||
@@ -173,5 +179,2 @@ return res; | ||
return (Object.entries(parents) | ||
// (XXX): We sort to prevent instaql results from being reordered | ||
// on refresh | ||
.sort((a, b) => (a[0] > b[0] ? 1 : -1)) | ||
.map(([eid, parent]) => { | ||
@@ -178,0 +181,0 @@ const childResults = children.map((label) => { |
@@ -36,2 +36,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
function dropLast(arr) { | ||
return arr.slice(0, arr.length - 1); | ||
} | ||
/** | ||
@@ -199,3 +202,6 @@ * Marshall instaql-result into list of triples. Instaql-result may have | ||
op: "transact", | ||
"tx-steps": txSteps, | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, if we wanted to 'expose' the createdAt and updatedAt to the client | ||
"tx-steps": txSteps.map(x => x.concat(Date.now() * 10)), | ||
}; | ||
@@ -564,3 +570,4 @@ this.pendingMutations.set((prev) => { | ||
} | ||
this._forceSend(eventId, mutation); | ||
const txSteps = mutation["tx-steps"].map((x) => dropLast(x)); | ||
this._forceSend(eventId, Object.assign(Object.assign({}, mutation), { "tx-steps": txSteps })); | ||
const timeoutMs = Math.max(5000, this.pendingMutations.currentValue.size * 5000); | ||
@@ -567,0 +574,0 @@ window.setTimeout(() => { |
@@ -64,2 +64,5 @@ "use strict"; | ||
} | ||
function dropLast(arr) { | ||
return arr.slice(0, arr.length - 1); | ||
} | ||
/** | ||
@@ -227,3 +230,6 @@ * Marshall instaql-result into list of triples. Instaql-result may have | ||
op: "transact", | ||
"tx-steps": txSteps, | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, if we wanted to 'expose' the createdAt and updatedAt to the client | ||
"tx-steps": txSteps.map(x => x.concat(Date.now() * 10)), | ||
}; | ||
@@ -592,3 +598,4 @@ this.pendingMutations.set((prev) => { | ||
} | ||
this._forceSend(eventId, mutation); | ||
const txSteps = mutation["tx-steps"].map((x) => dropLast(x)); | ||
this._forceSend(eventId, Object.assign(Object.assign({}, mutation), { "tx-steps": txSteps })); | ||
const timeoutMs = Math.max(5000, this.pendingMutations.currentValue.size * 5000); | ||
@@ -595,0 +602,0 @@ window.setTimeout(() => { |
{ | ||
"name": "@instantdb/core", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "Instant's core local abstraction", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -46,4 +46,4 @@ import { query as datalogQuery } from "./datalog"; | ||
const ATTR_VAR = makeVar("attr"); | ||
const VAL_VAR = makeVar("val"); | ||
const TIME_VAR = makeVar("time"); | ||
@@ -70,2 +70,3 @@ // Where | ||
makeVar(etype, level), | ||
TIME_VAR, | ||
]; | ||
@@ -75,3 +76,3 @@ } | ||
function attrWhere(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -100,4 +101,4 @@ | ||
const attrPat = fwdAttr | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel)] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level)]; | ||
? [makeVar(fwdEtype, level), attr.id, makeVar(revEtype, nextLevel), TIME_VAR] | ||
: [makeVar(fwdEtype, nextLevel), attr.id, makeVar(revEtype, level), TIME_VAR]; | ||
@@ -118,3 +119,3 @@ const nextEtype = fwdAttr ? revEtype : fwdEtype; | ||
return [makeVar(valueEtype, valueLevel), attr.id, v]; | ||
return [makeVar(valueEtype, valueLevel), attr.id, v, TIME_VAR]; | ||
} | ||
@@ -169,3 +170,3 @@ | ||
function makeFind(etype, level) { | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR]; | ||
return [makeVar(etype, level), ATTR_VAR, VAL_VAR, TIME_VAR]; | ||
} | ||
@@ -190,3 +191,7 @@ | ||
function runDatalog(store, dq) { | ||
return datalogQuery(store, dq).reduce((res, [e, a, v]) => { | ||
return datalogQuery(store, dq).sort((tripleA, tripleB) => { | ||
const tsA = tripleA[3]; | ||
const tsB = tripleB[3]; | ||
return new Date(tsA) - new Date(tsB); | ||
}).reduce((res, [e, a, v]) => { | ||
if (ignoredAttr(store.attrs, a)) { | ||
@@ -200,3 +205,3 @@ return res; | ||
return res; | ||
}, {}); | ||
}, {}) | ||
} | ||
@@ -228,5 +233,2 @@ | ||
Object.entries(parents) | ||
// (XXX): We sort to prevent instaql results from being reordered | ||
// on refresh | ||
.sort((a, b) => (a[0] > b[0] ? 1 : -1)) | ||
.map(([eid, parent]) => { | ||
@@ -233,0 +235,0 @@ const childResults = children.map((label) => { |
@@ -30,2 +30,6 @@ import log from "./utils/log"; | ||
function dropLast(arr) { | ||
return arr.slice(0, arr.length - 1); | ||
} | ||
/** | ||
@@ -578,3 +582,6 @@ * Marshall instaql-result into list of triples. Instaql-result may have | ||
op: "transact", | ||
"tx-steps": txSteps, | ||
// (XXX): Hack to ensure that we set a date that will be bigger than | ||
// anything committed to the server. | ||
// eventually we may need something different, if we wanted to 'expose' the createdAt and updatedAt to the client | ||
"tx-steps": txSteps.map(x => x.concat(Date.now() * 10)), | ||
}; | ||
@@ -606,3 +613,4 @@ this.pendingMutations.set((prev) => { | ||
} | ||
this._forceSend(eventId, mutation); | ||
const txSteps = mutation["tx-steps"].map((x) => dropLast(x)); | ||
this._forceSend(eventId, { ...mutation, "tx-steps": txSteps }); | ||
const timeoutMs = Math.max( | ||
@@ -609,0 +617,0 @@ 5000, |
@@ -196,4 +196,4 @@ import { produce } from "immer"; | ||
: Object.values(store.eav).flatMap((aMap) => { | ||
return Object.values(aMap).flatMap((vMap) => Object.values(vMap)); | ||
}); | ||
return Object.values(aMap).flatMap((vMap) => Object.values(vMap)); | ||
}); | ||
} | ||
@@ -200,0 +200,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 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
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
1418531
32375