@instantdb/core 0.22.88-experimental.drewh-ssr.20251523170.1 → 0.22.88-experimental.split-store.20252005043.1
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/__tests__/src/Reactor.test.js +18 -11
- package/__tests__/src/{datalog.test.js → datalog.test.ts} +17 -5
- package/__tests__/src/{instaml.test.js → instaml.test.ts} +183 -119
- package/__tests__/src/instaql.bench.ts +34 -0
- package/__tests__/src/{instaql.test.js → instaql.test.ts} +342 -455
- package/__tests__/src/instaqlInference.test.js +13 -9
- package/__tests__/src/{store.test.js → store.test.ts} +215 -212
- package/dist/commonjs/Reactor.d.ts +24 -19
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +112 -106
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/SyncTable.d.ts +4 -1
- package/dist/commonjs/SyncTable.d.ts.map +1 -1
- package/dist/commonjs/SyncTable.js +35 -37
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/index.d.ts +1 -5
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -7
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.d.ts +17 -4
- package/dist/commonjs/instaml.d.ts.map +1 -1
- package/dist/commonjs/instaml.js +115 -82
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.d.ts +4 -3
- package/dist/commonjs/instaql.d.ts.map +1 -1
- package/dist/commonjs/instaql.js +65 -63
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/reactorTypes.d.ts +29 -0
- package/dist/commonjs/reactorTypes.d.ts.map +1 -0
- package/dist/commonjs/reactorTypes.js +3 -0
- package/dist/commonjs/reactorTypes.js.map +1 -0
- package/dist/commonjs/store.d.ts +67 -25
- package/dist/commonjs/store.d.ts.map +1 -1
- package/dist/commonjs/store.js +177 -81
- package/dist/commonjs/store.js.map +1 -1
- package/dist/esm/Reactor.d.ts +24 -19
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +113 -107
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/SyncTable.d.ts +4 -1
- package/dist/esm/SyncTable.d.ts.map +1 -1
- package/dist/esm/SyncTable.js +35 -37
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/index.d.ts +1 -5
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.d.ts +17 -4
- package/dist/esm/instaml.d.ts.map +1 -1
- package/dist/esm/instaml.js +112 -77
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.d.ts +4 -3
- package/dist/esm/instaql.d.ts.map +1 -1
- package/dist/esm/instaql.js +65 -63
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/reactorTypes.d.ts +29 -0
- package/dist/esm/reactorTypes.d.ts.map +1 -0
- package/dist/esm/reactorTypes.js +2 -0
- package/dist/esm/reactorTypes.js.map +1 -0
- package/dist/esm/store.d.ts +67 -25
- package/dist/esm/store.d.ts.map +1 -1
- package/dist/esm/store.js +174 -81
- package/dist/esm/store.js.map +1 -1
- package/dist/standalone/index.js +1851 -1961
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +155 -143
- package/src/SyncTable.ts +85 -45
- package/src/index.ts +0 -9
- package/src/{instaml.js → instaml.ts} +201 -96
- package/src/instaql.ts +88 -62
- package/src/reactorTypes.ts +32 -0
- package/src/store.ts +257 -101
- package/__tests__/src/instaql.bench.js +0 -29
- package/__tests__/src/serializeSchema.test.ts +0 -123
- package/dist/commonjs/createRouteHandler.d.ts +0 -8
- package/dist/commonjs/createRouteHandler.d.ts.map +0 -1
- package/dist/commonjs/createRouteHandler.js +0 -57
- package/dist/commonjs/createRouteHandler.js.map +0 -1
- package/dist/commonjs/framework.d.ts +0 -77
- package/dist/commonjs/framework.d.ts.map +0 -1
- package/dist/commonjs/framework.js +0 -199
- package/dist/commonjs/framework.js.map +0 -1
- package/dist/commonjs/parseSchemaFromJSON.d.ts +0 -3
- package/dist/commonjs/parseSchemaFromJSON.d.ts.map +0 -1
- package/dist/commonjs/parseSchemaFromJSON.js +0 -148
- package/dist/commonjs/parseSchemaFromJSON.js.map +0 -1
- package/dist/esm/createRouteHandler.d.ts +0 -8
- package/dist/esm/createRouteHandler.d.ts.map +0 -1
- package/dist/esm/createRouteHandler.js +0 -53
- package/dist/esm/createRouteHandler.js.map +0 -1
- package/dist/esm/framework.d.ts +0 -77
- package/dist/esm/framework.d.ts.map +0 -1
- package/dist/esm/framework.js +0 -159
- package/dist/esm/framework.js.map +0 -1
- package/dist/esm/parseSchemaFromJSON.d.ts +0 -3
- package/dist/esm/parseSchemaFromJSON.d.ts.map +0 -1
- package/dist/esm/parseSchemaFromJSON.js +0 -144
- package/dist/esm/parseSchemaFromJSON.js.map +0 -1
- package/src/createRouteHandler.ts +0 -44
- package/src/framework.ts +0 -281
- package/src/parseSchemaFromJSON.ts +0 -176
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export default class Reactor<RoomSchema extends import("./presence.ts").RoomSchemaShape = {}> {
|
|
5
5
|
constructor(config: any, Storage: typeof IndexedDBStorage | undefined, NetworkListener: typeof WindowNetworkListener | undefined, versions: any, EventSourceConstructor: any);
|
|
6
|
-
|
|
6
|
+
/** @type {s.AttrsStore | undefined} */
|
|
7
|
+
attrs: s.AttrsStore | undefined;
|
|
7
8
|
_isOnline: boolean;
|
|
8
9
|
_isShutdown: boolean;
|
|
9
10
|
status: string;
|
|
10
|
-
/** @type {PersistedObject} */
|
|
11
|
-
querySubs: PersistedObject<
|
|
11
|
+
/** @type {PersistedObject<string, QuerySub, QuerySubInStorage>} */
|
|
12
|
+
querySubs: PersistedObject<string, QuerySub, QuerySubInStorage>;
|
|
12
13
|
/** @type {PersistedObject} */
|
|
13
14
|
kv: PersistedObject<any, any, any>;
|
|
14
15
|
/** @type {SyncTable} */
|
|
@@ -78,6 +79,7 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
78
79
|
queryCacheLimit: any;
|
|
79
80
|
versions: any;
|
|
80
81
|
_beforeUnload(): void;
|
|
82
|
+
ensureAttrs(): s.AttrsStore;
|
|
81
83
|
updateSchema(schema: any): void;
|
|
82
84
|
_reactorStats(): {
|
|
83
85
|
inFlightMutationCount: number;
|
|
@@ -100,17 +102,6 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
100
102
|
_setStatus(status: any, err: any): void;
|
|
101
103
|
_onMergeKv: (key: any, storageV: any, inMemoryV: any) => any;
|
|
102
104
|
_flushEnqueuedRoomData(roomId: any): void;
|
|
103
|
-
/**
|
|
104
|
-
* Does the same thing as add-query-ok
|
|
105
|
-
* but called as a result of receiving query info from ssr
|
|
106
|
-
* @param {any} q
|
|
107
|
-
* @param {{ triples: any; pageInfo: any; }} result
|
|
108
|
-
* @param {boolean} enableCardinalityInference
|
|
109
|
-
*/
|
|
110
|
-
_addQueryData(q: any, result: {
|
|
111
|
-
triples: any;
|
|
112
|
-
pageInfo: any;
|
|
113
|
-
}, enableCardinalityInference: boolean): void;
|
|
114
105
|
_handleReceive(connId: any, msg: any): void;
|
|
115
106
|
_sessionId: any;
|
|
116
107
|
_pendingMutations(): any;
|
|
@@ -150,12 +141,24 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
150
141
|
_unsubQuery(q: any, hash: any, cb: any): void;
|
|
151
142
|
_hasQueryListeners(hash: any): boolean;
|
|
152
143
|
_cleanupQuery(q: any, hash: any): void;
|
|
153
|
-
|
|
144
|
+
/**
|
|
145
|
+
*
|
|
146
|
+
* @param {s.AttrsStore} attrs
|
|
147
|
+
* @param {any} muts
|
|
148
|
+
* @param {number} [processedTxId]
|
|
149
|
+
*/
|
|
150
|
+
_rewriteMutations(attrs: s.AttrsStore, muts: any, processedTxId?: number): any;
|
|
154
151
|
_rewriteMutationsSorted(attrs: any, muts: any): any[];
|
|
155
|
-
|
|
152
|
+
/**
|
|
153
|
+
* @returns {s.AttrsStore}
|
|
154
|
+
*/
|
|
155
|
+
optimisticAttrs(): s.AttrsStore;
|
|
156
156
|
/** Runs instaql on a query and a store */
|
|
157
|
-
dataForQuery(hash: any
|
|
158
|
-
_applyOptimisticUpdates(store: any, mutations: any, processedTxId: any):
|
|
157
|
+
dataForQuery(hash: any): any;
|
|
158
|
+
_applyOptimisticUpdates(store: any, attrsStore: any, mutations: any, processedTxId: any): {
|
|
159
|
+
store: any;
|
|
160
|
+
attrsStore: any;
|
|
161
|
+
};
|
|
159
162
|
/** Re-run instaql and call all callbacks with new data */
|
|
160
163
|
notifyOne: (hash: any) => void;
|
|
161
164
|
notifyOneQueryOnce: (hash: any) => void;
|
|
@@ -257,7 +260,6 @@ export default class Reactor<RoomSchema extends import("./presence.ts").RoomSche
|
|
|
257
260
|
}>;
|
|
258
261
|
_hasCurrentUser(): Promise<boolean>;
|
|
259
262
|
changeCurrentUser(newUser: any): Promise<void>;
|
|
260
|
-
syncUserToEndpoint(user: any): Promise<void>;
|
|
261
263
|
updateUser(newUser: any): void;
|
|
262
264
|
sendMagicCode({ email }: {
|
|
263
265
|
email: any;
|
|
@@ -350,6 +352,9 @@ export type Logger = import("./utils/log.ts").Logger;
|
|
|
350
352
|
export type Connection = import("./Connection.ts").Connection<any>;
|
|
351
353
|
export type TransportType = import("./Connection.ts").TransportType;
|
|
352
354
|
export type EventSourceConstructor = import("./Connection.ts").EventSourceConstructor;
|
|
355
|
+
export type QuerySub = import("./reactorTypes.ts").QuerySub;
|
|
356
|
+
export type QuerySubInStorage = import("./reactorTypes.ts").QuerySubInStorage;
|
|
357
|
+
import * as s from './store.ts';
|
|
353
358
|
import { PersistedObject } from './utils/PersistedObject.ts';
|
|
354
359
|
import { SyncTable } from './SyncTable.ts';
|
|
355
360
|
import { Deferred } from './utils/Deferred.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Reactor.d.ts","sourceRoot":"","sources":["../../src/Reactor.js"],"names":[],"mappings":"AAyMA;;GAEG;AACH,6BAFwD,UAAU,SAArD,OAAQ,eAAe,EAAE,eAAgB;IAmEpD,8KAiHC;IAjLD,uCAAuC;IACvC,OADW,CAAC,CAAC,UAAU,GAAG,SAAS,CAC7B;IACN,mBAAiB;IACjB,qBAAoB;IACpB,eAA2B;IAE3B,mEAAmE;IACnE,WADW,eAAe,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CACrD;IAEV,8BAA8B;IAC9B,mCAAG;IAEH,wBAAwB;IACxB,YADW,SAAS,CACT;IAEX,wEAAwE;IACxE,UADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAA;KAAE,CAAC,CAAC,CACtD;IACd,gFAAgF;IAChF,eADW,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,CAAC,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC,CACzD;IACnB,eAAa;IACb,gBAAc;IACd,wBAAsB;IACtB,2BAAyB;IACzB,YAAO;IACP,qCAAkC;IAClC,0BAA2B;IAC3B,4BAAwB;IACxB,yBAAyB;IACzB,YADW,UAAU,CACV;IACX,4BAA4B;IAC5B,gBADW,aAAa,CACF;IAEtB,qCAAqC;IACrC,cADW,sBAAsB,CACpB;IACb,6BAA6B;IAC7B,OADW,OAAO,GAAG,IAAI,CACZ;IACb,qBAAsB;IACtB,oBAAqB;IACrB,gEAAgE;IAChE,wBADW,OAAO,CAAC,IAAI,GAAG;QAAC,KAAK,E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O,mBAAmB,EAAE,iBAAiB;mBAnCxC,YAAY;gCASC,4BAA4B;0BAmBlC,gBAAgB;yBApBjB,qBAAqB;yBAJrB,cAAc;4BACX,iBAAiB;6BAHhB,uBAAuB;kCAClB,4BAA4B"}
|
package/dist/commonjs/Reactor.js
CHANGED
|
@@ -87,6 +87,8 @@ const SyncTable_ts_1 = require("./SyncTable.js");
|
|
|
87
87
|
/** @typedef {import('./Connection.ts').Connection} Connection */
|
|
88
88
|
/** @typedef {import('./Connection.ts').TransportType} TransportType */
|
|
89
89
|
/** @typedef {import('./Connection.ts').EventSourceConstructor} EventSourceConstructor */
|
|
90
|
+
/** @typedef {import('./reactorTypes.ts').QuerySub} QuerySub */
|
|
91
|
+
/** @typedef {import('./reactorTypes.ts').QuerySubInStorage} QuerySubInStorage */
|
|
90
92
|
const STATUS = {
|
|
91
93
|
CONNECTING: 'connecting',
|
|
92
94
|
OPENED: 'opened',
|
|
@@ -139,20 +141,37 @@ const ignoreLogging = {
|
|
|
139
141
|
'refresh-presence': true,
|
|
140
142
|
'patch-presence': true,
|
|
141
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* @param {QuerySubInStorage} x
|
|
146
|
+
* @param {boolean | null} useDateObjects
|
|
147
|
+
* @returns {QuerySub}
|
|
148
|
+
*/
|
|
142
149
|
function querySubFromStorage(x, useDateObjects) {
|
|
143
150
|
var _a;
|
|
144
151
|
const v = typeof x === 'string' ? JSON.parse(x) : x;
|
|
145
152
|
if ((_a = v === null || v === void 0 ? void 0 : v.result) === null || _a === void 0 ? void 0 : _a.store) {
|
|
146
|
-
const
|
|
147
|
-
|
|
153
|
+
const attrsStore = s.attrsStoreFromJSON(v.result.attrsStore, v.result.store);
|
|
154
|
+
if (attrsStore) {
|
|
155
|
+
const storeJSON = v.result.store;
|
|
156
|
+
v.result.store = s.fromJSON(attrsStore, Object.assign(Object.assign({}, storeJSON), { useDateObjects: useDateObjects }));
|
|
157
|
+
v.result.attrsStore = attrsStore;
|
|
158
|
+
}
|
|
148
159
|
}
|
|
149
160
|
return v;
|
|
150
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @param {string} _key
|
|
165
|
+
* @param {QuerySub} sub
|
|
166
|
+
* @returns QuerySubInStorage
|
|
167
|
+
*/
|
|
151
168
|
function querySubToStorage(_key, sub) {
|
|
152
|
-
|
|
153
|
-
const jsonSub =
|
|
154
|
-
if (
|
|
155
|
-
|
|
169
|
+
const { result } = sub, rest = __rest(sub, ["result"]);
|
|
170
|
+
const jsonSub = /** @type {import('./reactorTypes.ts').QuerySubInStorage} */ (rest);
|
|
171
|
+
if (result) {
|
|
172
|
+
/** @type {import('./reactorTypes.ts').QuerySubResultInStorage} */
|
|
173
|
+
const jsonResult = Object.assign(Object.assign({}, result), { store: s.toJSON(result.store), attrsStore: result.attrsStore.toJSON() });
|
|
174
|
+
jsonSub.result = jsonResult;
|
|
156
175
|
}
|
|
157
176
|
return jsonSub;
|
|
158
177
|
}
|
|
@@ -297,7 +316,7 @@ class Reactor {
|
|
|
297
316
|
}
|
|
298
317
|
try {
|
|
299
318
|
const txSteps = instaml.transform({
|
|
300
|
-
|
|
319
|
+
attrsStore: this.optimisticAttrs(),
|
|
301
320
|
schema: this.config.schema,
|
|
302
321
|
stores: Object.values(this.querySubs.currentValue).map((sub) => { var _a; return (_a = sub === null || sub === void 0 ? void 0 : sub.result) === null || _a === void 0 ? void 0 : _a.store; }),
|
|
303
322
|
useDateObjects: this.config.useDateObjects,
|
|
@@ -463,16 +482,12 @@ class Reactor {
|
|
|
463
482
|
this._initStorage(Storage);
|
|
464
483
|
this._syncTable = new SyncTable_ts_1.SyncTable(this._trySendAuthed.bind(this), new Storage(this.config.appId, 'syncSubs'), {
|
|
465
484
|
useDateObjects: this.config.useDateObjects,
|
|
466
|
-
}, this._log, (triples) =>
|
|
485
|
+
}, this._log, (triples) => {
|
|
486
|
+
return s.createStore(this.ensureAttrs(), triples, this.config.enableCardinalityInference, this.config.useDateObjects);
|
|
487
|
+
}, () => this.ensureAttrs());
|
|
467
488
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
468
489
|
// kick off a request to cache it
|
|
469
|
-
this.getCurrentUser()
|
|
470
|
-
this.syncUserToEndpoint(userInfo.user);
|
|
471
|
-
});
|
|
472
|
-
setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
473
|
-
const currentUser = yield this.getCurrentUser();
|
|
474
|
-
this.syncUserToEndpoint(currentUser.user);
|
|
475
|
-
}), 1000 * 60 * 20);
|
|
490
|
+
this.getCurrentUser();
|
|
476
491
|
NetworkListener.getIsOnline().then((isOnline) => {
|
|
477
492
|
this._isOnline = isOnline;
|
|
478
493
|
this._startSocket();
|
|
@@ -499,6 +514,12 @@ class Reactor {
|
|
|
499
514
|
addEventListener('beforeunload', this._beforeUnload);
|
|
500
515
|
}
|
|
501
516
|
}
|
|
517
|
+
ensureAttrs() {
|
|
518
|
+
if (!this.attrs) {
|
|
519
|
+
throw new Error('attrs have not loaded.');
|
|
520
|
+
}
|
|
521
|
+
return this.attrs;
|
|
522
|
+
}
|
|
502
523
|
updateSchema(schema) {
|
|
503
524
|
this.config = Object.assign(Object.assign({}, this.config), { schema: schema, cardinalityInference: Boolean(schema) });
|
|
504
525
|
this._linkIndex = schema ? (0, linkIndex_ts_1.createLinkIndex)(this.config.schema) : null;
|
|
@@ -522,7 +543,7 @@ class Reactor {
|
|
|
522
543
|
serialize: querySubToStorage,
|
|
523
544
|
parse: (_key, x) => querySubFromStorage(x, this.config.useDateObjects),
|
|
524
545
|
// objectSize
|
|
525
|
-
objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
|
|
546
|
+
objectSize: (x) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = x === null || x === void 0 ? void 0 : x.result) === null || _a === void 0 ? void 0 : _a.store) === null || _b === void 0 ? void 0 : _b.triples) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0; },
|
|
526
547
|
logger: this._log,
|
|
527
548
|
preloadEntryCount: 10,
|
|
528
549
|
gc: {
|
|
@@ -618,35 +639,6 @@ class Reactor {
|
|
|
618
639
|
}
|
|
619
640
|
}
|
|
620
641
|
}
|
|
621
|
-
/**
|
|
622
|
-
* Does the same thing as add-query-ok
|
|
623
|
-
* but called as a result of receiving query info from ssr
|
|
624
|
-
* @param {any} q
|
|
625
|
-
* @param {{ triples: any; pageInfo: any; }} result
|
|
626
|
-
* @param {boolean} enableCardinalityInference
|
|
627
|
-
*/
|
|
628
|
-
_addQueryData(q, result, enableCardinalityInference) {
|
|
629
|
-
if (!this.attrs) {
|
|
630
|
-
throw new Error('Attrs in reactor have not been set');
|
|
631
|
-
}
|
|
632
|
-
const queryHash = (0, weakHash_ts_1.default)(q);
|
|
633
|
-
const store = s.createStore(this.attrs, result.triples, enableCardinalityInference, this._linkIndex, this.config.useDateObjects);
|
|
634
|
-
this.querySubs.updateInPlace((prev) => {
|
|
635
|
-
prev[queryHash] = {
|
|
636
|
-
result: {
|
|
637
|
-
store,
|
|
638
|
-
pageInfo: result.pageInfo,
|
|
639
|
-
processedTxId: undefined,
|
|
640
|
-
isExternal: true,
|
|
641
|
-
},
|
|
642
|
-
q,
|
|
643
|
-
};
|
|
644
|
-
});
|
|
645
|
-
this._cleanupPendingMutationsQueries();
|
|
646
|
-
this.notifyOne(queryHash);
|
|
647
|
-
this.notifyOneQueryOnce(queryHash);
|
|
648
|
-
this._cleanupPendingMutationsTimeout();
|
|
649
|
-
}
|
|
650
642
|
_handleReceive(connId, msg) {
|
|
651
643
|
var _a, _b, _c, _d, _e, _f;
|
|
652
644
|
// opt-out, enabled by default if schema
|
|
@@ -685,7 +677,8 @@ class Reactor {
|
|
|
685
677
|
const pageInfo = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['page-info'];
|
|
686
678
|
const aggregate = (_f = (_e = result === null || result === void 0 ? void 0 : result[0]) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f['aggregate'];
|
|
687
679
|
const triples = (0, instaqlResult_js_1.extractTriples)(result);
|
|
688
|
-
const
|
|
680
|
+
const attrsStore = this.ensureAttrs();
|
|
681
|
+
const store = s.createStore(attrsStore, triples, enableCardinalityInference, this.config.useDateObjects);
|
|
689
682
|
this.querySubs.updateInPlace((prev) => {
|
|
690
683
|
if (!prev[hash]) {
|
|
691
684
|
this._log.info('Missing value in querySubs', { hash, q });
|
|
@@ -693,6 +686,7 @@ class Reactor {
|
|
|
693
686
|
}
|
|
694
687
|
prev[hash].result = {
|
|
695
688
|
store,
|
|
689
|
+
attrsStore,
|
|
696
690
|
pageInfo,
|
|
697
691
|
aggregate,
|
|
698
692
|
processedTxId: msg['processed-tx-id'],
|
|
@@ -727,7 +721,7 @@ class Reactor {
|
|
|
727
721
|
this._setAttrs(attrs);
|
|
728
722
|
}
|
|
729
723
|
this._cleanupPendingMutationsTimeout();
|
|
730
|
-
const rewrittenMutations = this._rewriteMutations(this.
|
|
724
|
+
const rewrittenMutations = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations(), processedTxId);
|
|
731
725
|
if (rewrittenMutations !== this._pendingMutations()) {
|
|
732
726
|
// We know we've changed the mutations to fix the attr ids and removed
|
|
733
727
|
// processed attrs, so we'll persist those changes to prevent optimisticAttrs
|
|
@@ -743,19 +737,33 @@ class Reactor {
|
|
|
743
737
|
const result = x['instaql-result'];
|
|
744
738
|
const hash = (0, weakHash_ts_1.default)(q);
|
|
745
739
|
const triples = (0, instaqlResult_js_1.extractTriples)(result);
|
|
746
|
-
const
|
|
747
|
-
const
|
|
740
|
+
const attrsStore = this.ensureAttrs();
|
|
741
|
+
const store = s.createStore(attrsStore, triples, enableCardinalityInference, this.config.useDateObjects);
|
|
742
|
+
const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
748
743
|
const pageInfo = (_b = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b['page-info'];
|
|
749
744
|
const aggregate = (_d = (_c = result === null || result === void 0 ? void 0 : result[0]) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d['aggregate'];
|
|
750
|
-
return {
|
|
745
|
+
return {
|
|
746
|
+
q,
|
|
747
|
+
hash,
|
|
748
|
+
store: newStore,
|
|
749
|
+
attrsStore: newAttrsStore,
|
|
750
|
+
pageInfo,
|
|
751
|
+
aggregate,
|
|
752
|
+
};
|
|
751
753
|
});
|
|
752
|
-
updates.forEach(({ hash, q, store, pageInfo, aggregate }) => {
|
|
754
|
+
updates.forEach(({ hash, q, store, attrsStore, pageInfo, aggregate }) => {
|
|
753
755
|
this.querySubs.updateInPlace((prev) => {
|
|
754
756
|
if (!prev[hash]) {
|
|
755
757
|
this._log.error('Missing value in querySubs', { hash, q });
|
|
756
758
|
return;
|
|
757
759
|
}
|
|
758
|
-
prev[hash].result = {
|
|
760
|
+
prev[hash].result = {
|
|
761
|
+
store,
|
|
762
|
+
attrsStore,
|
|
763
|
+
pageInfo,
|
|
764
|
+
aggregate,
|
|
765
|
+
processedTxId,
|
|
766
|
+
};
|
|
759
767
|
});
|
|
760
768
|
});
|
|
761
769
|
this._cleanupPendingMutationsQueries();
|
|
@@ -767,7 +775,7 @@ class Reactor {
|
|
|
767
775
|
case 'transact-ok': {
|
|
768
776
|
const { 'client-event-id': eventId, 'tx-id': txId } = msg;
|
|
769
777
|
this._inFlightMutationEventIds.delete(eventId);
|
|
770
|
-
const muts = this._rewriteMutations(this.
|
|
778
|
+
const muts = this._rewriteMutations(this.ensureAttrs(), this._pendingMutations());
|
|
771
779
|
const prevMutation = muts.get(eventId);
|
|
772
780
|
if (!prevMutation) {
|
|
773
781
|
break;
|
|
@@ -776,11 +784,17 @@ class Reactor {
|
|
|
776
784
|
this._updatePendingMutations((prev) => {
|
|
777
785
|
prev.set(eventId, Object.assign(Object.assign({}, prev.get(eventId)), { 'tx-id': txId, confirmed: Date.now() }));
|
|
778
786
|
});
|
|
779
|
-
const newAttrs =
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
787
|
+
const newAttrs = [];
|
|
788
|
+
for (const step of prevMutation['tx-steps']) {
|
|
789
|
+
if (step[0] === 'add-attr') {
|
|
790
|
+
const attr = step[1];
|
|
791
|
+
newAttrs.push(attr);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
if (newAttrs.length) {
|
|
795
|
+
const existingAttrs = Object.values(this.ensureAttrs().attrs);
|
|
796
|
+
this._setAttrs([...existingAttrs, ...newAttrs]);
|
|
797
|
+
}
|
|
784
798
|
this._finishTransaction('synced', eventId);
|
|
785
799
|
this._cleanupPendingMutationsTimeout();
|
|
786
800
|
break;
|
|
@@ -941,10 +955,10 @@ class Reactor {
|
|
|
941
955
|
this._completeQueryOnce(q, hash, r.dfd);
|
|
942
956
|
}
|
|
943
957
|
_setAttrs(attrs) {
|
|
944
|
-
this.attrs = attrs.reduce((acc, attr) => {
|
|
958
|
+
this.attrs = new s.AttrsStoreClass(attrs.reduce((acc, attr) => {
|
|
945
959
|
acc[attr.id] = attr;
|
|
946
960
|
return acc;
|
|
947
|
-
}, {});
|
|
961
|
+
}, {}), this._linkIndex);
|
|
948
962
|
this.notifyAttrsSubs();
|
|
949
963
|
}
|
|
950
964
|
_startQuerySub(q, hash) {
|
|
@@ -1050,6 +1064,12 @@ class Reactor {
|
|
|
1050
1064
|
// We remove `add-attr` commands for attrs that already exist.
|
|
1051
1065
|
// We update `add-triple` and `retract-triple` commands to use the
|
|
1052
1066
|
// server attr-ids.
|
|
1067
|
+
/**
|
|
1068
|
+
*
|
|
1069
|
+
* @param {s.AttrsStore} attrs
|
|
1070
|
+
* @param {any} muts
|
|
1071
|
+
* @param {number} [processedTxId]
|
|
1072
|
+
*/
|
|
1053
1073
|
_rewriteMutations(attrs, muts, processedTxId) {
|
|
1054
1074
|
if (!attrs)
|
|
1055
1075
|
return muts;
|
|
@@ -1057,12 +1077,12 @@ class Reactor {
|
|
|
1057
1077
|
return new Map();
|
|
1058
1078
|
const findExistingAttr = (attr) => {
|
|
1059
1079
|
const [_, etype, label] = attr['forward-identity'];
|
|
1060
|
-
const existing =
|
|
1080
|
+
const existing = s.getAttrByFwdIdentName(attrs, etype, label);
|
|
1061
1081
|
return existing;
|
|
1062
1082
|
};
|
|
1063
1083
|
const findReverseAttr = (attr) => {
|
|
1064
1084
|
const [_, etype, label] = attr['forward-identity'];
|
|
1065
|
-
const revAttr =
|
|
1085
|
+
const revAttr = s.getAttrByReverseIdentName(attrs, etype, label);
|
|
1066
1086
|
return revAttr;
|
|
1067
1087
|
};
|
|
1068
1088
|
const mapping = { attrIdMap: {}, refSwapAttrIds: new Set() };
|
|
@@ -1125,8 +1145,11 @@ class Reactor {
|
|
|
1125
1145
|
}
|
|
1126
1146
|
// ---------------------------
|
|
1127
1147
|
// Transact
|
|
1148
|
+
/**
|
|
1149
|
+
* @returns {s.AttrsStore}
|
|
1150
|
+
*/
|
|
1128
1151
|
optimisticAttrs() {
|
|
1129
|
-
var _a;
|
|
1152
|
+
var _a, _b;
|
|
1130
1153
|
const pendingMutationSteps = [...this._pendingMutations().values()] // hack due to Map()
|
|
1131
1154
|
.flatMap((x) => x['tx-steps']);
|
|
1132
1155
|
const deletedAttrIds = new Set(pendingMutationSteps
|
|
@@ -1139,20 +1162,25 @@ class Reactor {
|
|
|
1139
1162
|
}
|
|
1140
1163
|
else if (_action === 'update-attr' &&
|
|
1141
1164
|
attr.id &&
|
|
1142
|
-
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a
|
|
1143
|
-
const fullAttr = Object.assign(Object.assign({}, this.attrs
|
|
1165
|
+
((_a = this.attrs) === null || _a === void 0 ? void 0 : _a.getAttr(attr.id))) {
|
|
1166
|
+
const fullAttr = Object.assign(Object.assign({}, this.attrs.getAttr(attr.id)), attr);
|
|
1144
1167
|
pendingAttrs.push(fullAttr);
|
|
1145
1168
|
}
|
|
1146
1169
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1170
|
+
if (!deletedAttrIds.size && !pendingAttrs.length) {
|
|
1171
|
+
return this.attrs || new s.AttrsStoreClass({}, this._linkIndex);
|
|
1172
|
+
}
|
|
1173
|
+
const attrs = Object.assign({}, (((_b = this.attrs) === null || _b === void 0 ? void 0 : _b.attrs) || {}));
|
|
1174
|
+
for (const attr of pendingAttrs) {
|
|
1175
|
+
attrs[attr.id] = attr;
|
|
1176
|
+
}
|
|
1177
|
+
for (const id of deletedAttrIds) {
|
|
1178
|
+
delete attrs[id];
|
|
1179
|
+
}
|
|
1180
|
+
return new s.AttrsStoreClass(attrs, this._linkIndex);
|
|
1153
1181
|
}
|
|
1154
1182
|
/** Runs instaql on a query and a store */
|
|
1155
|
-
dataForQuery(hash
|
|
1183
|
+
dataForQuery(hash) {
|
|
1156
1184
|
const errorMessage = this._errorMessage;
|
|
1157
1185
|
if (errorMessage) {
|
|
1158
1186
|
return { error: errorMessage };
|
|
@@ -1174,22 +1202,21 @@ class Reactor {
|
|
|
1174
1202
|
pendingMutationsVersion === cached.pendingMutationsVersion) {
|
|
1175
1203
|
return cached;
|
|
1176
1204
|
}
|
|
1177
|
-
|
|
1178
|
-
const
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
store = this._applyOptimisticUpdates(store, mutations, processedTxId);
|
|
1182
|
-
}
|
|
1183
|
-
const resp = (0, instaql_ts_1.default)({ store: store, pageInfo, aggregate }, q);
|
|
1205
|
+
const { store, attrsStore, pageInfo, aggregate, processedTxId } = result;
|
|
1206
|
+
const mutations = this._rewriteMutationsSorted(attrsStore, pendingMutations);
|
|
1207
|
+
const { store: newStore, attrsStore: newAttrsStore } = this._applyOptimisticUpdates(store, attrsStore, mutations, processedTxId);
|
|
1208
|
+
const resp = (0, instaql_ts_1.default)({ store: newStore, attrsStore: newAttrsStore, pageInfo, aggregate }, q);
|
|
1184
1209
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1185
1210
|
}
|
|
1186
|
-
_applyOptimisticUpdates(store, mutations, processedTxId) {
|
|
1211
|
+
_applyOptimisticUpdates(store, attrsStore, mutations, processedTxId) {
|
|
1187
1212
|
for (const [_, mut] of mutations) {
|
|
1188
1213
|
if (!mut['tx-id'] || (processedTxId && mut['tx-id'] > processedTxId)) {
|
|
1189
|
-
|
|
1214
|
+
const result = s.transact(store, attrsStore, mut['tx-steps']);
|
|
1215
|
+
store = result.store;
|
|
1216
|
+
attrsStore = result.attrsStore;
|
|
1190
1217
|
}
|
|
1191
1218
|
}
|
|
1192
|
-
return store;
|
|
1219
|
+
return { store, attrsStore };
|
|
1193
1220
|
}
|
|
1194
1221
|
/** Re-compute all subscriptions */
|
|
1195
1222
|
notifyAll() {
|
|
@@ -1269,7 +1296,7 @@ class Reactor {
|
|
|
1269
1296
|
.forEach(({ eventId, q }) => {
|
|
1270
1297
|
this._trySendAuthed(eventId, { op: 'add-query', q });
|
|
1271
1298
|
});
|
|
1272
|
-
const muts = this._rewriteMutationsSorted(this.
|
|
1299
|
+
const muts = this._rewriteMutationsSorted(this.ensureAttrs(), this._pendingMutations());
|
|
1273
1300
|
muts.forEach(([eventId, mut]) => {
|
|
1274
1301
|
if (!mut['tx-id']) {
|
|
1275
1302
|
this._sendMutation(eventId, mut);
|
|
@@ -1556,7 +1583,7 @@ class Reactor {
|
|
|
1556
1583
|
subscribeAttrs(cb) {
|
|
1557
1584
|
this.attrsCbs.push(cb);
|
|
1558
1585
|
if (this.attrs) {
|
|
1559
|
-
cb(this.attrs);
|
|
1586
|
+
cb(this.attrs.attrs);
|
|
1560
1587
|
}
|
|
1561
1588
|
return () => {
|
|
1562
1589
|
this.attrsCbs = this.attrsCbs.filter((x) => x !== cb);
|
|
@@ -1572,7 +1599,7 @@ class Reactor {
|
|
|
1572
1599
|
if (!this.attrs)
|
|
1573
1600
|
return;
|
|
1574
1601
|
const oas = this.optimisticAttrs();
|
|
1575
|
-
this.attrsCbs.forEach((cb) => cb(oas));
|
|
1602
|
+
this.attrsCbs.forEach((cb) => cb(oas.attrs));
|
|
1576
1603
|
}
|
|
1577
1604
|
notifyConnectionStatusSubs(status) {
|
|
1578
1605
|
this.connectionStatusCbs.forEach((cb) => cb(status));
|
|
@@ -1644,28 +1671,7 @@ class Reactor {
|
|
|
1644
1671
|
}
|
|
1645
1672
|
});
|
|
1646
1673
|
}
|
|
1647
|
-
syncUserToEndpoint(user) {
|
|
1648
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1649
|
-
if (this.config.cookieEndpoint) {
|
|
1650
|
-
try {
|
|
1651
|
-
fetch(this.config.cookieEndpoint + '/sync-auth', {
|
|
1652
|
-
method: 'POST',
|
|
1653
|
-
body: JSON.stringify({
|
|
1654
|
-
user: user,
|
|
1655
|
-
}),
|
|
1656
|
-
headers: {
|
|
1657
|
-
'Content-Type': 'application/json',
|
|
1658
|
-
},
|
|
1659
|
-
});
|
|
1660
|
-
}
|
|
1661
|
-
catch (error) {
|
|
1662
|
-
console.error('Error syncing user with external endpoint', error);
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
});
|
|
1666
|
-
}
|
|
1667
1674
|
updateUser(newUser) {
|
|
1668
|
-
this.syncUserToEndpoint(newUser);
|
|
1669
1675
|
const newV = { error: undefined, user: newUser };
|
|
1670
1676
|
this._currentUserCached = Object.assign({ isLoading: false }, newV);
|
|
1671
1677
|
this._dataForQueryCache = {};
|