@instantdb/core 0.22.88-experimental.drewh-ssr.20249092140.1 → 0.22.88-experimental.drewh-fix-explorer.20249092035.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/dist/commonjs/Reactor.d.ts +1 -13
- package/dist/commonjs/Reactor.d.ts.map +1 -1
- package/dist/commonjs/Reactor.js +5 -64
- package/dist/commonjs/Reactor.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/esm/Reactor.d.ts +1 -13
- package/dist/esm/Reactor.d.ts.map +1 -1
- package/dist/esm/Reactor.js +5 -64
- package/dist/esm/Reactor.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/standalone/index.js +1372 -1672
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/Reactor.js +9 -74
- package/src/index.ts +0 -9
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/core",
|
|
3
|
-
"version": "0.22.88-experimental.drewh-
|
|
3
|
+
"version": "0.22.88-experimental.drewh-fix-explorer.20249092035.1",
|
|
4
4
|
"description": "Instant's core local abstraction",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
|
|
6
6
|
"repository": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mutative": "^1.0.10",
|
|
55
55
|
"uuid": "^11.1.0",
|
|
56
|
-
"@instantdb/version": "0.22.88-experimental.drewh-
|
|
56
|
+
"@instantdb/version": "0.22.88-experimental.drewh-fix-explorer.20249092035.1"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"test": "vitest",
|
package/src/Reactor.js
CHANGED
|
@@ -319,17 +319,7 @@ export default class Reactor {
|
|
|
319
319
|
this._oauthCallbackResponse = this._oauthLoginInit();
|
|
320
320
|
|
|
321
321
|
// kick off a request to cache it
|
|
322
|
-
this.getCurrentUser()
|
|
323
|
-
this.syncUserToEndpoint(userInfo.user);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
setInterval(
|
|
327
|
-
async () => {
|
|
328
|
-
const currentUser = await this.getCurrentUser();
|
|
329
|
-
this.syncUserToEndpoint(currentUser.user);
|
|
330
|
-
},
|
|
331
|
-
1000 * 60 * 20,
|
|
332
|
-
);
|
|
322
|
+
this.getCurrentUser();
|
|
333
323
|
|
|
334
324
|
NetworkListener.getIsOnline().then((isOnline) => {
|
|
335
325
|
this._isOnline = isOnline;
|
|
@@ -523,42 +513,6 @@ export default class Reactor {
|
|
|
523
513
|
}
|
|
524
514
|
}
|
|
525
515
|
|
|
526
|
-
/**
|
|
527
|
-
* Does the same thing as add-query-ok
|
|
528
|
-
* but called as a result of receiving query info from ssr
|
|
529
|
-
* @param {any} q
|
|
530
|
-
* @param {{ triples: any; pageInfo: any; }} result
|
|
531
|
-
* @param {boolean} enableCardinalityInference
|
|
532
|
-
*/
|
|
533
|
-
_addQueryData(q, result, enableCardinalityInference) {
|
|
534
|
-
if (!this.attrs) {
|
|
535
|
-
throw new Error('Attrs in reactor have not been set');
|
|
536
|
-
}
|
|
537
|
-
const queryHash = weakHash(q);
|
|
538
|
-
const store = s.createStore(
|
|
539
|
-
this.attrs,
|
|
540
|
-
result.triples,
|
|
541
|
-
enableCardinalityInference,
|
|
542
|
-
this._linkIndex,
|
|
543
|
-
this.config.useDateObjects,
|
|
544
|
-
);
|
|
545
|
-
this.querySubs.updateInPlace((prev) => {
|
|
546
|
-
prev[queryHash] = {
|
|
547
|
-
result: {
|
|
548
|
-
store,
|
|
549
|
-
pageInfo: result.pageInfo,
|
|
550
|
-
processedTxId: undefined,
|
|
551
|
-
isExternal: true,
|
|
552
|
-
},
|
|
553
|
-
q,
|
|
554
|
-
};
|
|
555
|
-
});
|
|
556
|
-
this._cleanupPendingMutationsQueries();
|
|
557
|
-
this.notifyOne(queryHash);
|
|
558
|
-
this.notifyOneQueryOnce(queryHash);
|
|
559
|
-
this._cleanupPendingMutationsTimeout();
|
|
560
|
-
}
|
|
561
|
-
|
|
562
516
|
_handleReceive(connId, msg) {
|
|
563
517
|
// opt-out, enabled by default if schema
|
|
564
518
|
const enableCardinalityInference =
|
|
@@ -1192,7 +1146,7 @@ export default class Reactor {
|
|
|
1192
1146
|
}
|
|
1193
1147
|
|
|
1194
1148
|
/** Runs instaql on a query and a store */
|
|
1195
|
-
dataForQuery(hash
|
|
1149
|
+
dataForQuery(hash) {
|
|
1196
1150
|
const errorMessage = this._errorMessage;
|
|
1197
1151
|
if (errorMessage) {
|
|
1198
1152
|
return { error: errorMessage };
|
|
@@ -1216,16 +1170,17 @@ export default class Reactor {
|
|
|
1216
1170
|
return cached;
|
|
1217
1171
|
}
|
|
1218
1172
|
|
|
1219
|
-
|
|
1220
|
-
const { pageInfo, aggregate, processedTxId } = result;
|
|
1173
|
+
const { store, pageInfo, aggregate, processedTxId } = result;
|
|
1221
1174
|
const mutations = this._rewriteMutationsSorted(
|
|
1222
1175
|
store.attrs,
|
|
1223
1176
|
pendingMutations,
|
|
1224
1177
|
);
|
|
1225
|
-
|
|
1226
|
-
store
|
|
1227
|
-
|
|
1228
|
-
|
|
1178
|
+
const newStore = this._applyOptimisticUpdates(
|
|
1179
|
+
store,
|
|
1180
|
+
mutations,
|
|
1181
|
+
processedTxId,
|
|
1182
|
+
);
|
|
1183
|
+
const resp = instaql({ store: newStore, pageInfo, aggregate }, q);
|
|
1229
1184
|
|
|
1230
1185
|
return { data: resp, querySubVersion, pendingMutationsVersion };
|
|
1231
1186
|
}
|
|
@@ -1957,27 +1912,7 @@ export default class Reactor {
|
|
|
1957
1912
|
}
|
|
1958
1913
|
}
|
|
1959
1914
|
|
|
1960
|
-
async syncUserToEndpoint(user) {
|
|
1961
|
-
if (this.config.cookieEndpoint) {
|
|
1962
|
-
try {
|
|
1963
|
-
fetch(this.config.cookieEndpoint + '/sync-auth', {
|
|
1964
|
-
method: 'POST',
|
|
1965
|
-
body: JSON.stringify({
|
|
1966
|
-
user: user,
|
|
1967
|
-
}),
|
|
1968
|
-
headers: {
|
|
1969
|
-
'Content-Type': 'application/json',
|
|
1970
|
-
},
|
|
1971
|
-
});
|
|
1972
|
-
} catch (error) {
|
|
1973
|
-
console.error('Error syncing user with external endpoint', error);
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
|
|
1978
1915
|
updateUser(newUser) {
|
|
1979
|
-
this.syncUserToEndpoint(newUser);
|
|
1980
|
-
|
|
1981
1916
|
const newV = { error: undefined, user: newUser };
|
|
1982
1917
|
this._currentUserCached = { isLoading: false, ...newV };
|
|
1983
1918
|
this._dataForQueryCache = {};
|
package/src/index.ts
CHANGED
|
@@ -20,13 +20,10 @@ import {
|
|
|
20
20
|
validateTransactions,
|
|
21
21
|
TransactionValidationError,
|
|
22
22
|
} from './transactionValidation.ts';
|
|
23
|
-
|
|
24
23
|
import {
|
|
25
24
|
StorageInterface,
|
|
26
25
|
type StorageInterfaceStoreName,
|
|
27
26
|
} from './utils/PersistedObject.ts';
|
|
28
|
-
import { createInstantRouteHandler } from './createRouteHandler.ts';
|
|
29
|
-
import { parseSchemaFromJSON } from './parseSchemaFromJSON.ts';
|
|
30
27
|
|
|
31
28
|
import type {
|
|
32
29
|
PresenceOpts,
|
|
@@ -106,7 +103,6 @@ import type {
|
|
|
106
103
|
} from './schemaTypes.ts';
|
|
107
104
|
import type { InstantRules } from './rulesTypes.ts';
|
|
108
105
|
import type { UploadFileResponse, DeleteFileResponse } from './StorageAPI.ts';
|
|
109
|
-
import { FrameworkClient, type FrameworkConfig } from './framework.ts';
|
|
110
106
|
|
|
111
107
|
import type {
|
|
112
108
|
ExchangeCodeForTokenParams,
|
|
@@ -157,7 +153,6 @@ export type InstantConfig<
|
|
|
157
153
|
appId: string;
|
|
158
154
|
schema?: S;
|
|
159
155
|
websocketURI?: string;
|
|
160
|
-
cookieEndpoint?: string;
|
|
161
156
|
apiURI?: string;
|
|
162
157
|
devtool?: boolean | DevtoolConfig;
|
|
163
158
|
verbose?: boolean;
|
|
@@ -907,9 +902,7 @@ export {
|
|
|
907
902
|
validateQuery,
|
|
908
903
|
QueryValidationError,
|
|
909
904
|
validateTransactions,
|
|
910
|
-
parseSchemaFromJSON,
|
|
911
905
|
TransactionValidationError,
|
|
912
|
-
FrameworkClient,
|
|
913
906
|
|
|
914
907
|
// error
|
|
915
908
|
InstantAPIError,
|
|
@@ -1025,7 +1018,6 @@ export {
|
|
|
1025
1018
|
|
|
1026
1019
|
// SSE
|
|
1027
1020
|
type EventSourceType,
|
|
1028
|
-
type FrameworkConfig,
|
|
1029
1021
|
|
|
1030
1022
|
// sync table types
|
|
1031
1023
|
type SyncTableCallback,
|
|
@@ -1042,5 +1034,4 @@ export {
|
|
|
1042
1034
|
// storage (e.g. indexeddb) interface
|
|
1043
1035
|
StorageInterface,
|
|
1044
1036
|
type StorageInterfaceStoreName,
|
|
1045
|
-
createInstantRouteHandler,
|
|
1046
1037
|
};
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { expect, test } from 'vitest';
|
|
2
|
-
import { i } from '../../src/schema';
|
|
3
|
-
import { parseSchemaFromJSON } from '../../src/parseSchemaFromJSON';
|
|
4
|
-
import { InstantSchemaDef } from '../../src/schemaTypes';
|
|
5
|
-
|
|
6
|
-
const schema = i.schema({
|
|
7
|
-
entities: {
|
|
8
|
-
users: i.entity({
|
|
9
|
-
name: i.string(),
|
|
10
|
-
email: i.string().indexed().unique(),
|
|
11
|
-
bio: i.string().optional(),
|
|
12
|
-
// this is a convenient way to typecheck custom JSON fields
|
|
13
|
-
// though we should probably have a backend solution for this
|
|
14
|
-
stuff: i.json<{ custom: string }>(),
|
|
15
|
-
junk: i.any(),
|
|
16
|
-
}),
|
|
17
|
-
posts: i.entity({
|
|
18
|
-
title: i.string().optional(),
|
|
19
|
-
body: i.string(),
|
|
20
|
-
}),
|
|
21
|
-
comments: i.entity({
|
|
22
|
-
body: i.string().indexed(),
|
|
23
|
-
likes: i.number(),
|
|
24
|
-
}),
|
|
25
|
-
|
|
26
|
-
birthdays: i.entity({
|
|
27
|
-
date: i.date(),
|
|
28
|
-
message: i.string(),
|
|
29
|
-
prizes: i.json<string | number>(),
|
|
30
|
-
}),
|
|
31
|
-
},
|
|
32
|
-
links: {
|
|
33
|
-
usersPosts: {
|
|
34
|
-
forward: {
|
|
35
|
-
on: 'users',
|
|
36
|
-
has: 'many',
|
|
37
|
-
label: 'posts',
|
|
38
|
-
},
|
|
39
|
-
reverse: {
|
|
40
|
-
on: 'posts',
|
|
41
|
-
has: 'one',
|
|
42
|
-
label: 'author',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
postsComments: {
|
|
46
|
-
forward: {
|
|
47
|
-
on: 'posts',
|
|
48
|
-
has: 'many',
|
|
49
|
-
label: 'comments',
|
|
50
|
-
},
|
|
51
|
-
reverse: {
|
|
52
|
-
on: 'comments',
|
|
53
|
-
has: 'one',
|
|
54
|
-
label: 'post',
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
friendships: {
|
|
58
|
-
forward: {
|
|
59
|
-
on: 'users',
|
|
60
|
-
has: 'many',
|
|
61
|
-
label: 'friends',
|
|
62
|
-
},
|
|
63
|
-
reverse: {
|
|
64
|
-
on: 'users',
|
|
65
|
-
has: 'many',
|
|
66
|
-
label: '_friends',
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
referrals: {
|
|
70
|
-
forward: {
|
|
71
|
-
on: 'users',
|
|
72
|
-
has: 'many',
|
|
73
|
-
label: 'referred',
|
|
74
|
-
},
|
|
75
|
-
reverse: {
|
|
76
|
-
on: 'users',
|
|
77
|
-
has: 'one',
|
|
78
|
-
label: 'referrer',
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
rooms: {
|
|
83
|
-
chat: {
|
|
84
|
-
presence: i.entity({
|
|
85
|
-
name: i.string(),
|
|
86
|
-
status: i.string(),
|
|
87
|
-
}),
|
|
88
|
-
topics: {
|
|
89
|
-
sendEmoji: i.entity({
|
|
90
|
-
emoji: i.string(),
|
|
91
|
-
}),
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
type AnySchema = InstantSchemaDef<any, any, any>;
|
|
98
|
-
|
|
99
|
-
// compare schemas by stringifying them with json and comparing the strings
|
|
100
|
-
const compareSchemas = (schema1: AnySchema, schema2: AnySchema) => {
|
|
101
|
-
expect(JSON.stringify(schema1, null, 2)).toBe(
|
|
102
|
-
JSON.stringify(schema2, null, 2),
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
test('ability to parse stringified schema into real schema object', () => {
|
|
107
|
-
const stringified = JSON.stringify(schema, null, 2);
|
|
108
|
-
const parsed = JSON.parse(stringified);
|
|
109
|
-
console.log(stringified);
|
|
110
|
-
|
|
111
|
-
const otherSide = parseSchemaFromJSON(parsed);
|
|
112
|
-
|
|
113
|
-
compareSchemas(schema, otherSide);
|
|
114
|
-
|
|
115
|
-
expect(schema.entities.comments.links).toEqual(
|
|
116
|
-
otherSide.entities.comments.links,
|
|
117
|
-
);
|
|
118
|
-
expect(schema.entities.comments.asType).toEqual(
|
|
119
|
-
otherSide.entities.comments.asType,
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
expect(schema).toStrictEqual(otherSide);
|
|
123
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRouteHandler.d.ts","sourceRoot":"","sources":["../../src/createRouteHandler.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,GAAI,QAAQ;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;gBAqBqB,OAAO;gBAMP,OAAO;CAa5B,CAAC"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createInstantRouteHandler = void 0;
|
|
13
|
-
const createInstantRouteHandler = (config) => {
|
|
14
|
-
function handleUserSync(req) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const body = yield req.json();
|
|
17
|
-
if (body.user && body.user.refresh_token) {
|
|
18
|
-
return new Response('sync', {
|
|
19
|
-
headers: {
|
|
20
|
-
// 7 day expiry
|
|
21
|
-
'Set-Cookie': `instant_user=${JSON.stringify(body.user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
return new Response('sync', {
|
|
27
|
-
headers: {
|
|
28
|
-
// remove the cookie (some browsers)
|
|
29
|
-
'Set-Cookie': `instant_user=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
GET: (_req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
return new Response('Method not allowed', {
|
|
38
|
-
status: 405,
|
|
39
|
-
statusText: 'Method Not Allowed',
|
|
40
|
-
});
|
|
41
|
-
}),
|
|
42
|
-
POST: (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const url = new URL(req.url);
|
|
44
|
-
const pathname = url.pathname;
|
|
45
|
-
const route = pathname.split('/')[pathname.split('/').length - 1];
|
|
46
|
-
switch (route) {
|
|
47
|
-
case 'sync-auth':
|
|
48
|
-
return yield handleUserSync(req);
|
|
49
|
-
}
|
|
50
|
-
return new Response('Route not found', {
|
|
51
|
-
status: 404,
|
|
52
|
-
});
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
exports.createInstantRouteHandler = createInstantRouteHandler;
|
|
57
|
-
//# sourceMappingURL=createRouteHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRouteHandler.js","sourceRoot":"","sources":["../../src/createRouteHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAO,MAAM,yBAAyB,GAAG,CAAC,MAGzC,EAAE,EAAE;IACH,SAAe,cAAc,CAAC,GAAY;;YACxC,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;gBACzC,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;oBAC1B,OAAO,EAAE;wBACP,eAAe;wBACf,YAAY,EAAE,gBAAgB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,6DAA6D;qBACrH;iBACF,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE;oBAC1B,OAAO,EAAE;wBACP,oCAAoC;wBACpC,YAAY,EAAE,sEAAsE;qBACrF;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KAAA;IAED,OAAO;QACL,GAAG,EAAE,CAAO,IAAa,EAAE,EAAE;YAC3B,OAAO,IAAI,QAAQ,CAAC,oBAAoB,EAAE;gBACxC,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,oBAAoB;aACjC,CAAC,CAAC;QACL,CAAC,CAAA;QACD,IAAI,EAAE,CAAO,GAAY,EAAE,EAAE;YAC3B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAC9B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAClE,QAAQ,KAAK,EAAE,CAAC;gBACd,KAAK,WAAW;oBACd,OAAO,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,IAAI,QAAQ,CAAC,iBAAiB,EAAE;gBACrC,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;QACL,CAAC,CAAA;KACF,CAAC;AACJ,CAAC,CAAC;AA3CW,QAAA,yBAAyB,6BA2CpC","sourcesContent":["export const createInstantRouteHandler = (config: {\n appId: string;\n apiURI?: string;\n}) => {\n async function handleUserSync(req: Request) {\n const body = await req.json();\n if (body.user && body.user.refresh_token) {\n return new Response('sync', {\n headers: {\n // 7 day expiry\n 'Set-Cookie': `instant_user=${JSON.stringify(body.user)}; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=604800`,\n },\n });\n } else {\n return new Response('sync', {\n headers: {\n // remove the cookie (some browsers)\n 'Set-Cookie': `instant_user=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=-1`,\n },\n });\n }\n }\n\n return {\n GET: async (_req: Request) => {\n return new Response('Method not allowed', {\n status: 405,\n statusText: 'Method Not Allowed',\n });\n },\n POST: async (req: Request) => {\n const url = new URL(req.url);\n const pathname = url.pathname;\n const route = pathname.split('/')[pathname.split('/').length - 1];\n switch (route) {\n case 'sync-auth':\n return await handleUserSync(req);\n }\n return new Response('Route not found', {\n status: 404,\n });\n },\n };\n};\n"]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { InstantCoreDatabase, InstantDBAttr } from './index.ts';
|
|
2
|
-
import { RuleParams } from './schemaTypes.ts';
|
|
3
|
-
export declare const isServer: boolean;
|
|
4
|
-
export type FrameworkConfig = {
|
|
5
|
-
token?: string | null;
|
|
6
|
-
db: InstantCoreDatabase<any, any>;
|
|
7
|
-
};
|
|
8
|
-
type QueryPromise = {
|
|
9
|
-
type: 'http';
|
|
10
|
-
triples: any;
|
|
11
|
-
attrs: any;
|
|
12
|
-
queryHash: any;
|
|
13
|
-
query: any;
|
|
14
|
-
pageInfo?: any;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'session';
|
|
17
|
-
queryResult: any;
|
|
18
|
-
};
|
|
19
|
-
export declare class FrameworkClient {
|
|
20
|
-
private params;
|
|
21
|
-
private db;
|
|
22
|
-
resultMap: Map<string, {
|
|
23
|
-
status: 'pending' | 'success' | 'error';
|
|
24
|
-
type: 'http' | 'session';
|
|
25
|
-
promise?: Promise<QueryPromise> | null;
|
|
26
|
-
data?: any;
|
|
27
|
-
error?: any;
|
|
28
|
-
}>;
|
|
29
|
-
private queryResolvedCallbacks;
|
|
30
|
-
constructor(params: FrameworkConfig);
|
|
31
|
-
subscribe: (callback: (result: {
|
|
32
|
-
triples: any;
|
|
33
|
-
attrs: any;
|
|
34
|
-
queryHash: string;
|
|
35
|
-
pageInfo?: any;
|
|
36
|
-
}) => void) => void;
|
|
37
|
-
addQueryResult: (queryKey: string, value: any) => void;
|
|
38
|
-
query: (_query: any, opts?: {
|
|
39
|
-
ruleParams: RuleParams;
|
|
40
|
-
}) => {
|
|
41
|
-
type: "http" | "session";
|
|
42
|
-
status: "pending" | "success" | "error";
|
|
43
|
-
promise?: Promise<QueryPromise>;
|
|
44
|
-
data?: any;
|
|
45
|
-
error?: any;
|
|
46
|
-
};
|
|
47
|
-
getExistingResultForQuery: (_query: any, opts?: {
|
|
48
|
-
ruleParams: RuleParams;
|
|
49
|
-
}) => {
|
|
50
|
-
status: "pending" | "success" | "error";
|
|
51
|
-
type: "http" | "session";
|
|
52
|
-
promise?: Promise<QueryPromise> | null;
|
|
53
|
-
data?: any;
|
|
54
|
-
error?: any;
|
|
55
|
-
} | undefined;
|
|
56
|
-
completeIsomorphic: (query: any, triples: any[], attrs: InstantDBAttr[], pageInfo?: any) => {
|
|
57
|
-
data: any;
|
|
58
|
-
pageInfo?: any;
|
|
59
|
-
aggregate?: any;
|
|
60
|
-
};
|
|
61
|
-
hashQuery: (_query: any, opts?: {
|
|
62
|
-
ruleParams: RuleParams;
|
|
63
|
-
}) => {
|
|
64
|
-
hash: string;
|
|
65
|
-
query: any;
|
|
66
|
-
};
|
|
67
|
-
getTriplesAndAttrsForQuery: (query: any) => Promise<{
|
|
68
|
-
triples: any[];
|
|
69
|
-
attrs: InstantDBAttr[];
|
|
70
|
-
query: any;
|
|
71
|
-
queryHash: string;
|
|
72
|
-
type: "http";
|
|
73
|
-
pageInfo?: any;
|
|
74
|
-
}>;
|
|
75
|
-
}
|
|
76
|
-
export {};
|
|
77
|
-
//# sourceMappingURL=framework.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"framework.d.ts","sourceRoot":"","sources":["../../src/framework.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,aAAa,EAEd,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,eAAO,MAAM,QAAQ,SAAwD,CAAC;AAE9E,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,EAAE,EAAE,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACnC,CAAC;AAEF,KAAK,YAAY,GACb;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,GAAG,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,GACD;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEN,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,EAAE,CAAgC;IACnC,SAAS,EAAE,GAAG,CACnB,MAAM,EACN;QACE,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;QACxC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;QACvC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,CACF,CAAa;IAEd,OAAO,CAAC,sBAAsB,CAMX;gBAEP,MAAM,EAAE,eAAe;IAe5B,SAAS,GACd,UAAU,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,GAAG,CAAC;QACb,KAAK,EAAE,GAAG,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,GAAG,CAAC;KAChB,KAAK,IAAI,UAGV;IAGK,cAAc,GAAI,UAAU,MAAM,EAAE,OAAO,GAAG,UAoBnD;IAEK,KAAK,GACV,QAAQ,GAAG,EACX,OAAO;QACL,UAAU,EAAE,UAAU,CAAC;KACxB,KACA;QACD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;QACxC,OAAO,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;QAChC,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,KAAK,CAAC,EAAE,GAAG,CAAC;KACb,CA2DC;IAEK,yBAAyB,GAC9B,QAAQ,GAAG,EACX,OAAO;QACL,UAAU,EAAE,UAAU,CAAC;KACxB;gBA7IS,SAAS,GAAG,SAAS,GAAG,OAAO;cACjC,MAAM,GAAG,SAAS;kBACd,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;eAC/B,GAAG;gBACF,GAAG;kBA6Ib;IAEK,kBAAkB,GACvB,OAAO,GAAG,EACV,SAAS,GAAG,EAAE,EACd,OAAO,aAAa,EAAE,EACtB,WAAW,GAAG;;;;MAyBd;IAEK,SAAS,GACd,QAAQ,GAAG,EACX,OAAO;QACL,UAAU,EAAE,UAAU,CAAC;KACxB,KACA;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAM7B;IAEK,0BAA0B,GAC/B,OAAO,GAAG,KACT,OAAO,CAAC;QACT,OAAO,EAAE,GAAG,EAAE,CAAC;QACf,KAAK,EAAE,aAAa,EAAE,CAAC;QACvB,KAAK,EAAE,GAAG,CAAC;QACX,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,GAAG,CAAC;KAChB,CAAC,CA0CA;CACH"}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.FrameworkClient = exports.isServer = void 0;
|
|
49
|
-
const index_ts_1 = require("./index.js");
|
|
50
|
-
const s = __importStar(require("./store.js"));
|
|
51
|
-
const instaql_js_1 = __importDefault(require("./instaql.js"));
|
|
52
|
-
exports.isServer = typeof window === 'undefined' || 'Deno' in globalThis;
|
|
53
|
-
class FrameworkClient {
|
|
54
|
-
constructor(params) {
|
|
55
|
-
this.resultMap = new Map();
|
|
56
|
-
this.queryResolvedCallbacks = [];
|
|
57
|
-
this.subscribe = (callback) => {
|
|
58
|
-
this.queryResolvedCallbacks.push(callback);
|
|
59
|
-
};
|
|
60
|
-
// Runs on the client when ssr gets html script tags
|
|
61
|
-
this.addQueryResult = (queryKey, value) => {
|
|
62
|
-
this.resultMap.set(queryKey, {
|
|
63
|
-
type: value.type,
|
|
64
|
-
status: 'success',
|
|
65
|
-
data: value,
|
|
66
|
-
promise: null,
|
|
67
|
-
error: null,
|
|
68
|
-
});
|
|
69
|
-
// send the result to the client
|
|
70
|
-
if (!exports.isServer) {
|
|
71
|
-
// make sure the attrs are there to create stores
|
|
72
|
-
if (!this.db._reactor.attrs) {
|
|
73
|
-
this.db._reactor._setAttrs(value.attrs);
|
|
74
|
-
}
|
|
75
|
-
this.db._reactor._addQueryData(value.query, value, !!this.db._reactor.config.schema);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
this.query = (_query, opts) => {
|
|
79
|
-
const { hash, query } = this.hashQuery(_query, opts);
|
|
80
|
-
if (this.db._reactor.status === 'authenticated') {
|
|
81
|
-
const promise = this.db.queryOnce(_query, opts);
|
|
82
|
-
let entry = {
|
|
83
|
-
status: 'pending',
|
|
84
|
-
type: 'session',
|
|
85
|
-
data: undefined,
|
|
86
|
-
error: undefined,
|
|
87
|
-
promise: promise,
|
|
88
|
-
};
|
|
89
|
-
promise.then((result) => {
|
|
90
|
-
entry.status = 'success';
|
|
91
|
-
entry.data = result;
|
|
92
|
-
entry.promise = null;
|
|
93
|
-
});
|
|
94
|
-
promise.catch((error) => {
|
|
95
|
-
entry.status = 'error';
|
|
96
|
-
entry.error = error;
|
|
97
|
-
entry.promise = null;
|
|
98
|
-
});
|
|
99
|
-
return entry;
|
|
100
|
-
}
|
|
101
|
-
const promise = this.getTriplesAndAttrsForQuery(query);
|
|
102
|
-
let entry = {
|
|
103
|
-
status: 'pending',
|
|
104
|
-
type: 'http',
|
|
105
|
-
data: undefined,
|
|
106
|
-
error: undefined,
|
|
107
|
-
promise: promise,
|
|
108
|
-
};
|
|
109
|
-
promise.then((result) => {
|
|
110
|
-
entry.status = 'success';
|
|
111
|
-
entry.data = result;
|
|
112
|
-
entry.promise = null;
|
|
113
|
-
});
|
|
114
|
-
promise.catch((error) => {
|
|
115
|
-
entry.status = 'error';
|
|
116
|
-
entry.error = error;
|
|
117
|
-
entry.promise = null;
|
|
118
|
-
});
|
|
119
|
-
promise.then((result) => {
|
|
120
|
-
this.queryResolvedCallbacks.forEach((callback) => {
|
|
121
|
-
callback({
|
|
122
|
-
queryHash: hash,
|
|
123
|
-
query: query,
|
|
124
|
-
attrs: result.attrs,
|
|
125
|
-
triples: result.triples,
|
|
126
|
-
pageInfo: result.pageInfo,
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
this.resultMap.set(hash, entry);
|
|
131
|
-
return entry;
|
|
132
|
-
};
|
|
133
|
-
this.getExistingResultForQuery = (_query, opts) => {
|
|
134
|
-
const { hash } = this.hashQuery(_query, opts);
|
|
135
|
-
return this.resultMap.get(hash);
|
|
136
|
-
};
|
|
137
|
-
this.completeIsomorphic = (query, triples, attrs, pageInfo) => {
|
|
138
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
139
|
-
const attrMap = {};
|
|
140
|
-
attrs.forEach((attr) => {
|
|
141
|
-
attrMap[attr.id] = attr;
|
|
142
|
-
});
|
|
143
|
-
const enableCardinalityInference = Boolean((_c = (_b = (_a = this.db) === null || _a === void 0 ? void 0 : _a._reactor) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.schema) &&
|
|
144
|
-
('cardinalityInference' in ((_e = (_d = this.db) === null || _d === void 0 ? void 0 : _d._reactor) === null || _e === void 0 ? void 0 : _e.config)
|
|
145
|
-
? Boolean((_g = (_f = this.db) === null || _f === void 0 ? void 0 : _f._reactor.config) === null || _g === void 0 ? void 0 : _g.cardinalityInference)
|
|
146
|
-
: true);
|
|
147
|
-
const store = s.createStore(attrMap, triples, enableCardinalityInference, null, this.params.db._reactor.config.useDateObjects || false);
|
|
148
|
-
const resp = (0, instaql_js_1.default)({ store: store, pageInfo: pageInfo, aggregate: undefined }, query);
|
|
149
|
-
return resp;
|
|
150
|
-
};
|
|
151
|
-
this.hashQuery = (_query, opts) => {
|
|
152
|
-
if (_query && opts && 'ruleParams' in opts) {
|
|
153
|
-
_query = Object.assign({ $$ruleParams: opts['ruleParams'] }, _query);
|
|
154
|
-
}
|
|
155
|
-
const query = _query ? (0, index_ts_1.coerceQuery)(_query) : null;
|
|
156
|
-
return { hash: (0, index_ts_1.weakHash)(query), query: query };
|
|
157
|
-
};
|
|
158
|
-
this.getTriplesAndAttrsForQuery = (query) => __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
var _a, _b, _c, _d, _e, _f;
|
|
160
|
-
const response = yield fetch(`${this.db._reactor.config.apiURI}/runtime/query`, {
|
|
161
|
-
method: 'POST',
|
|
162
|
-
headers: {
|
|
163
|
-
'app-id': this.params.db._reactor.config.appId,
|
|
164
|
-
'Content-Type': 'application/json',
|
|
165
|
-
Authorization: this.params.token
|
|
166
|
-
? `Bearer ${this.params.token}`
|
|
167
|
-
: undefined,
|
|
168
|
-
},
|
|
169
|
-
body: JSON.stringify({
|
|
170
|
-
query: query,
|
|
171
|
-
}),
|
|
172
|
-
});
|
|
173
|
-
if (!response.ok) {
|
|
174
|
-
throw new Error('Error getting triples from server');
|
|
175
|
-
}
|
|
176
|
-
const data = yield response.json();
|
|
177
|
-
const attrs = data === null || data === void 0 ? void 0 : data.attrs;
|
|
178
|
-
if (!attrs) {
|
|
179
|
-
throw new Error('No attrs');
|
|
180
|
-
}
|
|
181
|
-
// TODO: make safer
|
|
182
|
-
const triples = (_c = (_b = (_a = data.result) === null || _a === void 0 ? void 0 : _a[0].data) === null || _b === void 0 ? void 0 : _b['datalog-result']) === null || _c === void 0 ? void 0 : _c['join-rows'][0];
|
|
183
|
-
const pageInfo = (_f = (_e = (_d = data.result) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f['page-info'];
|
|
184
|
-
return {
|
|
185
|
-
attrs,
|
|
186
|
-
triples,
|
|
187
|
-
type: 'http',
|
|
188
|
-
queryHash: this.hashQuery(query).hash,
|
|
189
|
-
query,
|
|
190
|
-
pageInfo,
|
|
191
|
-
};
|
|
192
|
-
});
|
|
193
|
-
this.params = params;
|
|
194
|
-
this.db = params.db;
|
|
195
|
-
this.resultMap = new Map();
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
exports.FrameworkClient = FrameworkClient;
|
|
199
|
-
//# sourceMappingURL=framework.js.map
|