@instantdb/core 0.22.96-experimental.drewh-ts-target.20761590091.1 → 0.22.97-experimental.bump-next-cia.20761479934.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/Connection.js +51 -50
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/InMemoryStorage.js +32 -13
- package/dist/commonjs/InMemoryStorage.js.map +1 -1
- package/dist/commonjs/IndexedDBStorage.js +217 -193
- package/dist/commonjs/IndexedDBStorage.js.map +1 -1
- package/dist/commonjs/InstantError.js +0 -1
- package/dist/commonjs/InstantError.js.map +1 -1
- package/dist/commonjs/Reactor.js +610 -566
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/StorageAPI.js +70 -51
- package/dist/commonjs/StorageAPI.js.map +1 -1
- package/dist/commonjs/SyncTable.js +81 -68
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/WindowNetworkListener.js +13 -2
- package/dist/commonjs/WindowNetworkListener.js.map +1 -1
- package/dist/commonjs/__types__/fieldsTypeTest.js +16 -8
- package/dist/commonjs/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/commonjs/__types__/useDatesTypeTest.js +6 -3
- package/dist/commonjs/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/commonjs/authAPI.js +79 -62
- package/dist/commonjs/authAPI.js.map +1 -1
- package/dist/commonjs/createRouteHandler.js +15 -5
- package/dist/commonjs/createRouteHandler.js.map +1 -1
- package/dist/commonjs/datalog.js +1 -1
- package/dist/commonjs/datalog.js.map +1 -1
- package/dist/commonjs/devtool.js +8 -26
- package/dist/commonjs/devtool.js.map +1 -1
- package/dist/commonjs/framework.d.ts.map +1 -1
- package/dist/commonjs/framework.js +152 -142
- package/dist/commonjs/framework.js.map +1 -1
- package/dist/commonjs/index.js +190 -204
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.js +30 -44
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.js +33 -25
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.js +7 -6
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
- package/dist/commonjs/presence.js +8 -7
- package/dist/commonjs/presence.js.map +1 -1
- package/dist/commonjs/queryValidation.js +2 -1
- package/dist/commonjs/queryValidation.js.map +1 -1
- package/dist/commonjs/schema.js +6 -8
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/schemaTypes.js +3 -22
- package/dist/commonjs/schemaTypes.js.map +1 -1
- package/dist/commonjs/store.js +38 -29
- package/dist/commonjs/store.js.map +1 -1
- package/dist/commonjs/transactionValidation.js +2 -1
- package/dist/commonjs/transactionValidation.js.map +1 -1
- package/dist/commonjs/utils/Deferred.js +0 -3
- package/dist/commonjs/utils/Deferred.js.map +1 -1
- package/dist/commonjs/utils/PersistedObject.js +233 -216
- package/dist/commonjs/utils/PersistedObject.js.map +1 -1
- package/dist/commonjs/utils/fetch.js +19 -9
- package/dist/commonjs/utils/fetch.js.map +1 -1
- package/dist/commonjs/utils/linkIndex.js +4 -2
- package/dist/commonjs/utils/linkIndex.js.map +1 -1
- package/dist/commonjs/utils/object.js +1 -1
- package/dist/commonjs/utils/object.js.map +1 -1
- package/dist/esm/Connection.js +51 -50
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/InMemoryStorage.js +32 -13
- package/dist/esm/InMemoryStorage.js.map +1 -1
- package/dist/esm/IndexedDBStorage.js +217 -193
- package/dist/esm/IndexedDBStorage.js.map +1 -1
- package/dist/esm/InstantError.js +0 -1
- package/dist/esm/InstantError.js.map +1 -1
- package/dist/esm/Reactor.js +610 -566
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/StorageAPI.js +70 -51
- package/dist/esm/StorageAPI.js.map +1 -1
- package/dist/esm/SyncTable.js +81 -68
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/WindowNetworkListener.js +13 -2
- package/dist/esm/WindowNetworkListener.js.map +1 -1
- package/dist/esm/__types__/fieldsTypeTest.js +16 -8
- package/dist/esm/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/esm/__types__/useDatesTypeTest.js +6 -3
- package/dist/esm/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/esm/authAPI.js +79 -62
- package/dist/esm/authAPI.js.map +1 -1
- package/dist/esm/createRouteHandler.js +15 -5
- package/dist/esm/createRouteHandler.js.map +1 -1
- package/dist/esm/datalog.js +1 -1
- package/dist/esm/datalog.js.map +1 -1
- package/dist/esm/devtool.js +8 -26
- package/dist/esm/devtool.js.map +1 -1
- package/dist/esm/framework.d.ts.map +1 -1
- package/dist/esm/framework.js +152 -142
- package/dist/esm/framework.js.map +1 -1
- package/dist/esm/index.js +190 -204
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.js +30 -44
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.js +33 -25
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.js +7 -6
- package/dist/esm/parseSchemaFromJSON.js.map +1 -1
- package/dist/esm/presence.js +8 -7
- package/dist/esm/presence.js.map +1 -1
- package/dist/esm/queryValidation.js +2 -1
- package/dist/esm/queryValidation.js.map +1 -1
- package/dist/esm/schema.js +6 -8
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/schemaTypes.js +3 -22
- package/dist/esm/schemaTypes.js.map +1 -1
- package/dist/esm/store.js +38 -29
- package/dist/esm/store.js.map +1 -1
- package/dist/esm/transactionValidation.js +2 -1
- package/dist/esm/transactionValidation.js.map +1 -1
- package/dist/esm/utils/Deferred.js +0 -3
- package/dist/esm/utils/Deferred.js.map +1 -1
- package/dist/esm/utils/PersistedObject.js +233 -216
- package/dist/esm/utils/PersistedObject.js.map +1 -1
- package/dist/esm/utils/fetch.js +19 -9
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/linkIndex.js +4 -2
- package/dist/esm/utils/linkIndex.js.map +1 -1
- package/dist/esm/utils/object.js +1 -1
- package/dist/esm/utils/object.js.map +1 -1
- package/dist/standalone/index.js +2367 -2610
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/framework.ts +1 -0
package/dist/esm/StorageAPI.js
CHANGED
|
@@ -1,65 +1,84 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { jsonFetch } from './utils/fetch.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export function uploadFile(_a) {
|
|
12
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, file, refreshToken, contentType, contentDisposition, }) {
|
|
13
|
+
const headers = {
|
|
14
|
+
app_id: appId,
|
|
15
|
+
path,
|
|
16
|
+
authorization: `Bearer ${refreshToken}`,
|
|
17
|
+
'content-type': contentType || file.type,
|
|
18
|
+
};
|
|
19
|
+
if (contentDisposition) {
|
|
20
|
+
headers['content-disposition'] = contentDisposition;
|
|
21
|
+
}
|
|
22
|
+
const data = yield jsonFetch(`${apiURI}/storage/upload`, {
|
|
23
|
+
method: 'PUT',
|
|
24
|
+
headers,
|
|
25
|
+
body: file,
|
|
26
|
+
});
|
|
27
|
+
return data;
|
|
16
28
|
});
|
|
17
|
-
return data;
|
|
18
29
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
export function deleteFile(_a) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, refreshToken, }) {
|
|
32
|
+
const { data } = yield jsonFetch(`${apiURI}/storage/files?app_id=${appId}&filename=${encodeURIComponent(path)}`, {
|
|
33
|
+
method: 'DELETE',
|
|
34
|
+
headers: {
|
|
35
|
+
'content-type': 'application/json',
|
|
36
|
+
authorization: `Bearer ${refreshToken}`,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
return data;
|
|
26
40
|
});
|
|
27
|
-
return data;
|
|
28
41
|
}
|
|
29
42
|
// Deprecated Storage API (Jan 2025)
|
|
30
43
|
// ---------------------------------
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
export function getSignedUploadUrl(_a) {
|
|
45
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, fileName, refreshToken, metadata = {}, }) {
|
|
46
|
+
const { data } = yield jsonFetch(`${apiURI}/storage/signed-upload-url`, {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'content-type': 'application/json',
|
|
50
|
+
authorization: `Bearer ${refreshToken}`,
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify({
|
|
53
|
+
app_id: appId,
|
|
54
|
+
filename: fileName,
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
42
58
|
});
|
|
43
|
-
return data;
|
|
44
59
|
}
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
export function upload(presignedUrl, file) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const response = yield fetch(presignedUrl, {
|
|
63
|
+
method: 'PUT',
|
|
64
|
+
body: file,
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': file.type,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return response.ok;
|
|
52
70
|
});
|
|
53
|
-
return response.ok;
|
|
54
71
|
}
|
|
55
|
-
export
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
export function getDownloadUrl(_a) {
|
|
73
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, refreshToken, }) {
|
|
74
|
+
const { data } = yield jsonFetch(`${apiURI}/storage/signed-download-url?app_id=${appId}&filename=${encodeURIComponent(path)}`, {
|
|
75
|
+
method: 'GET',
|
|
76
|
+
headers: {
|
|
77
|
+
'content-type': 'application/json',
|
|
78
|
+
authorization: `Bearer ${refreshToken}`,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
return data;
|
|
62
82
|
});
|
|
63
|
-
return data;
|
|
64
83
|
}
|
|
65
84
|
//# sourceMappingURL=StorageAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageAPI.js","sourceRoot":"","sources":["../../src/StorageAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAc7C,MAAM,
|
|
1
|
+
{"version":3,"file":"StorageAPI.js","sourceRoot":"","sources":["../../src/StorageAPI.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAc7C,MAAM,UAAgB,UAAU;yDAAC,EAC/B,MAAM,EACN,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,kBAAkB,GASnB;QACC,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,KAAK;YACb,IAAI;YACJ,aAAa,EAAE,UAAU,YAAY,EAAE;YACvC,cAAc,EAAE,WAAW,IAAI,IAAI,CAAC,IAAI;SACzC,CAAC;QACF,IAAI,kBAAkB,EAAE,CAAC;YACvB,OAAO,CAAC,qBAAqB,CAAC,GAAG,kBAAkB,CAAC;QACtD,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,GAAG,MAAM,iBAAiB,EAAE;YACvD,MAAM,EAAE,KAAK;YACb,OAAO;YACP,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,MAAM,UAAgB,UAAU;yDAAC,EAC/B,MAAM,EACN,KAAK,EACL,IAAI,EACJ,YAAY,GAMb;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAC9B,GAAG,MAAM,yBAAyB,KAAK,aAAa,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAC9E;YACE,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,YAAY,EAAE;aACxC;SACF,CACF,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,oCAAoC;AACpC,oCAAoC;AAEpC,MAAM,UAAgB,kBAAkB;yDAAC,EACvC,MAAM,EACN,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,QAAQ,GAAG,EAAE,GAOd;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAAC,GAAG,MAAM,4BAA4B,EAAE;YACtE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,YAAY,EAAE;aACxC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC;SACH,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CAAA;AAED,MAAM,UAAgB,MAAM,CAAC,YAAY,EAAE,IAAI;;QAC7C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,YAAY,EAAE;YACzC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,IAAI;YACV,OAAO,EAAE;gBACP,cAAc,EAAE,IAAI,CAAC,IAAI;aAC1B;SACF,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;CAAA;AAED,MAAM,UAAgB,cAAc;yDAAC,EACnC,MAAM,EACN,KAAK,EACL,IAAI,EACJ,YAAY,GAMb;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAC9B,GAAG,MAAM,uCAAuC,KAAK,aAAa,kBAAkB,CAClF,IAAI,CACL,EAAE,EACH;YACE,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,YAAY,EAAE;aACxC;SACF,CACF,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;CAAA","sourcesContent":["import { jsonFetch } from './utils/fetch.js';\n\nexport type UploadFileResponse = {\n data: {\n id: string;\n };\n};\n\nexport type DeleteFileResponse = {\n data: {\n id: string | null;\n };\n};\n\nexport async function uploadFile({\n apiURI,\n appId,\n path,\n file,\n refreshToken,\n contentType,\n contentDisposition,\n}: {\n apiURI: string;\n appId: string;\n path: string;\n file: File | Blob;\n refreshToken?: string;\n contentType?: string;\n contentDisposition?: string;\n}): Promise<UploadFileResponse> {\n const headers = {\n app_id: appId,\n path,\n authorization: `Bearer ${refreshToken}`,\n 'content-type': contentType || file.type,\n };\n if (contentDisposition) {\n headers['content-disposition'] = contentDisposition;\n }\n\n const data = await jsonFetch(`${apiURI}/storage/upload`, {\n method: 'PUT',\n headers,\n body: file,\n });\n\n return data;\n}\n\nexport async function deleteFile({\n apiURI,\n appId,\n path,\n refreshToken,\n}: {\n apiURI: string;\n appId: string;\n path: string;\n refreshToken?: string;\n}): Promise<DeleteFileResponse> {\n const { data } = await jsonFetch(\n `${apiURI}/storage/files?app_id=${appId}&filename=${encodeURIComponent(path)}`,\n {\n method: 'DELETE',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${refreshToken}`,\n },\n },\n );\n\n return data;\n}\n\n// Deprecated Storage API (Jan 2025)\n// ---------------------------------\n\nexport async function getSignedUploadUrl({\n apiURI,\n appId,\n fileName,\n refreshToken,\n metadata = {},\n}: {\n apiURI: string;\n appId: string;\n fileName: string;\n refreshToken?: string;\n metadata?: Record<string, any>;\n}) {\n const { data } = await jsonFetch(`${apiURI}/storage/signed-upload-url`, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${refreshToken}`,\n },\n body: JSON.stringify({\n app_id: appId,\n filename: fileName,\n }),\n });\n\n return data;\n}\n\nexport async function upload(presignedUrl, file) {\n const response = await fetch(presignedUrl, {\n method: 'PUT',\n body: file,\n headers: {\n 'Content-Type': file.type,\n },\n });\n\n return response.ok;\n}\n\nexport async function getDownloadUrl({\n apiURI,\n appId,\n path,\n refreshToken,\n}: {\n apiURI: string;\n appId: string;\n path: string;\n refreshToken?: string;\n}) {\n const { data } = await jsonFetch(\n `${apiURI}/storage/signed-download-url?app_id=${appId}&filename=${encodeURIComponent(\n path,\n )}`,\n {\n method: 'GET',\n headers: {\n 'content-type': 'application/json',\n authorization: `Bearer ${refreshToken}`,\n },\n },\n );\n\n return data;\n}\n"]}
|
package/dist/esm/SyncTable.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { PersistedObject } from "./utils/PersistedObject.js";
|
|
2
11
|
import * as s from "./store.js";
|
|
3
12
|
import weakHash from "./utils/weakHash.js";
|
|
@@ -19,24 +28,23 @@ function syncSubFromStorage(sub, useDateObjects) {
|
|
|
19
28
|
return sub;
|
|
20
29
|
}
|
|
21
30
|
function syncSubToStorage(_k, sub) {
|
|
31
|
+
var _a;
|
|
22
32
|
if (sub.values) {
|
|
23
33
|
const entities = [];
|
|
24
|
-
for (const e of sub.values
|
|
34
|
+
for (const e of (_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities) {
|
|
25
35
|
const store = s.toJSON(e.store);
|
|
26
|
-
entities.push({
|
|
36
|
+
entities.push(Object.assign(Object.assign({}, e), { store }));
|
|
27
37
|
}
|
|
28
|
-
return {
|
|
29
|
-
...sub,
|
|
30
|
-
values: { attrsStore: sub.values.attrsStore.toJSON(), entities },
|
|
31
|
-
};
|
|
38
|
+
return Object.assign(Object.assign({}, sub), { values: { attrsStore: sub.values.attrsStore.toJSON(), entities } });
|
|
32
39
|
}
|
|
33
40
|
else {
|
|
34
41
|
return sub;
|
|
35
42
|
}
|
|
36
43
|
}
|
|
37
44
|
function onMergeSub(_key, storageSub, inMemorySub) {
|
|
38
|
-
|
|
39
|
-
const
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const storageTxId = (_a = storageSub === null || storageSub === void 0 ? void 0 : storageSub.state) === null || _a === void 0 ? void 0 : _a.txId;
|
|
47
|
+
const memoryTxId = (_b = inMemorySub === null || inMemorySub === void 0 ? void 0 : inMemorySub.state) === null || _b === void 0 ? void 0 : _b.txId;
|
|
40
48
|
if (storageTxId && (!memoryTxId || storageTxId > memoryTxId)) {
|
|
41
49
|
return storageSub;
|
|
42
50
|
}
|
|
@@ -50,7 +58,8 @@ function queryEntity(sub, store, attrsStore) {
|
|
|
50
58
|
return res.data[sub.table][0];
|
|
51
59
|
}
|
|
52
60
|
function getServerCreatedAt(sub, store, attrsStore, entityId) {
|
|
53
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
const aid = (_a = s.getAttrByFwdIdentName(attrsStore, sub.table, 'id')) === null || _a === void 0 ? void 0 : _a.id;
|
|
54
63
|
if (!aid) {
|
|
55
64
|
return -1;
|
|
56
65
|
}
|
|
@@ -73,17 +82,18 @@ function applyChangesToStore(store, attrsStore, changes) {
|
|
|
73
82
|
}
|
|
74
83
|
}
|
|
75
84
|
function changedFieldsOfChanges(store, attrsStore, changes) {
|
|
85
|
+
var _a, _b, _c, _d;
|
|
76
86
|
// This will be more complicated when we include links, we can either add a
|
|
77
87
|
// changedLinks field or we can have something like 'bookshelves.title`
|
|
78
88
|
const changedFields = {};
|
|
79
89
|
for (const { action, triple } of changes) {
|
|
80
90
|
const [e, a, v] = triple;
|
|
81
|
-
const field = attrsStore.getAttr(a)
|
|
91
|
+
const field = (_b = (_a = attrsStore.getAttr(a)) === null || _a === void 0 ? void 0 : _a['forward-identity']) === null || _b === void 0 ? void 0 : _b[2];
|
|
82
92
|
if (!field)
|
|
83
93
|
continue;
|
|
84
|
-
const fields = changedFields[e]
|
|
94
|
+
const fields = (_c = changedFields[e]) !== null && _c !== void 0 ? _c : {};
|
|
85
95
|
changedFields[e] = fields;
|
|
86
|
-
const oldNew = fields[field]
|
|
96
|
+
const oldNew = (_d = fields[field]) !== null && _d !== void 0 ? _d : {};
|
|
87
97
|
switch (action) {
|
|
88
98
|
case 'added':
|
|
89
99
|
oldNew.newValue = v;
|
|
@@ -113,12 +123,13 @@ function subData(sub, entities) {
|
|
|
113
123
|
// and returns the type. We have to wait until the attrs
|
|
114
124
|
// are loaded before we can determine the type.
|
|
115
125
|
function orderFieldTypeMutative(sub, getAttrs) {
|
|
126
|
+
var _a;
|
|
116
127
|
if (sub.orderFieldType) {
|
|
117
128
|
return sub.orderFieldType;
|
|
118
129
|
}
|
|
119
130
|
const orderFieldType = sub.orderField === 'serverCreatedAt'
|
|
120
131
|
? 'number'
|
|
121
|
-
: s.getAttrByFwdIdentName(getAttrs(), sub.table, sub.orderField)
|
|
132
|
+
: (_a = s.getAttrByFwdIdentName(getAttrs(), sub.table, sub.orderField)) === null || _a === void 0 ? void 0 : _a['checked-data-type'];
|
|
122
133
|
sub.orderFieldType = orderFieldType;
|
|
123
134
|
return orderFieldType;
|
|
124
135
|
}
|
|
@@ -152,16 +163,10 @@ export var CallbackEventType;
|
|
|
152
163
|
CallbackEventType["Error"] = "Error";
|
|
153
164
|
})(CallbackEventType || (CallbackEventType = {}));
|
|
154
165
|
export class SyncTable {
|
|
155
|
-
trySend;
|
|
156
|
-
subs;
|
|
157
|
-
// Using any for the SyncCallback because we'd need Reactor to be typed
|
|
158
|
-
callbacks = {};
|
|
159
|
-
config;
|
|
160
|
-
idToHash = {};
|
|
161
|
-
log;
|
|
162
|
-
createStore;
|
|
163
|
-
getAttrs;
|
|
164
166
|
constructor(trySend, storage, config, log, createStore, getAttrs) {
|
|
167
|
+
// Using any for the SyncCallback because we'd need Reactor to be typed
|
|
168
|
+
this.callbacks = {};
|
|
169
|
+
this.idToHash = {};
|
|
165
170
|
this.trySend = trySend;
|
|
166
171
|
this.config = config;
|
|
167
172
|
this.log = log;
|
|
@@ -172,13 +177,13 @@ export class SyncTable {
|
|
|
172
177
|
merge: onMergeSub,
|
|
173
178
|
serialize: syncSubToStorage,
|
|
174
179
|
parse: (_key, x) => syncSubFromStorage(x, this.config.useDateObjects),
|
|
175
|
-
objectSize: (sub) => sub.values
|
|
180
|
+
objectSize: (sub) => { var _a; return ((_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities.length) || 0; },
|
|
176
181
|
logger: log,
|
|
177
182
|
gc: {
|
|
178
183
|
maxAgeMs: 1000 * 60 * 60 * 24 * 7 * 52, // 1 year
|
|
179
184
|
maxEntries: 1000,
|
|
180
185
|
// Size of each sub is the number of entity
|
|
181
|
-
maxSize:
|
|
186
|
+
maxSize: 1000000, // 1 million entities
|
|
182
187
|
},
|
|
183
188
|
});
|
|
184
189
|
}
|
|
@@ -191,7 +196,7 @@ export class SyncTable {
|
|
|
191
196
|
this.callbacks[hash].push(cb);
|
|
192
197
|
this.initSubscription(q, hash, cb);
|
|
193
198
|
return (opts) => {
|
|
194
|
-
this.unsubscribe(hash, cb, opts
|
|
199
|
+
this.unsubscribe(hash, cb, opts === null || opts === void 0 ? void 0 : opts.keepSubscription);
|
|
195
200
|
};
|
|
196
201
|
}
|
|
197
202
|
unsubscribe(hash, cb, keepSubscription) {
|
|
@@ -200,7 +205,7 @@ export class SyncTable {
|
|
|
200
205
|
if (!cbs.length) {
|
|
201
206
|
delete this.callbacks[hash];
|
|
202
207
|
const sub = this.subs.currentValue[hash];
|
|
203
|
-
if (sub
|
|
208
|
+
if (sub === null || sub === void 0 ? void 0 : sub.state) {
|
|
204
209
|
this.clearSubscriptionData(sub.state.subscriptionId, !!keepSubscription);
|
|
205
210
|
}
|
|
206
211
|
if (!keepSubscription) {
|
|
@@ -233,47 +238,52 @@ export class SyncTable {
|
|
|
233
238
|
'keep-subscription': keepSubscription,
|
|
234
239
|
});
|
|
235
240
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (existingSub.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
initSubscription(query, hash, cb) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
var _a, _b, _c, _d;
|
|
244
|
+
// Wait for storage to load so that we know if we already have an existing subscription
|
|
245
|
+
yield this.subs.waitForKeyToLoad(hash);
|
|
246
|
+
const existingSub = this.subs.currentValue[hash];
|
|
247
|
+
if (existingSub && existingSub.state && existingSub.state.txId) {
|
|
248
|
+
this.sendResync(existingSub, existingSub.state, existingSub.state.txId);
|
|
249
|
+
if (((_a = existingSub.values) === null || _a === void 0 ? void 0 : _a.entities) && cb) {
|
|
250
|
+
cb({
|
|
251
|
+
type: CallbackEventType.LoadFromStorage,
|
|
252
|
+
data: subData(existingSub, (_b = existingSub.values) === null || _b === void 0 ? void 0 : _b.entities),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
247
256
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
257
|
+
const table = Object.keys(query)[0];
|
|
258
|
+
const orderBy = ((_d = (_c = query[table]) === null || _c === void 0 ? void 0 : _c.$) === null || _d === void 0 ? void 0 : _d.order) || { serverCreatedAt: 'asc' };
|
|
259
|
+
const [orderField, orderDirection] = Object.entries(orderBy)[0];
|
|
260
|
+
this.subs.updateInPlace((prev) => {
|
|
261
|
+
prev[hash] = {
|
|
262
|
+
query,
|
|
263
|
+
hash: hash,
|
|
264
|
+
table,
|
|
265
|
+
orderDirection,
|
|
266
|
+
orderField,
|
|
267
|
+
createdAt: Date.now(),
|
|
268
|
+
updatedAt: Date.now(),
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
this.sendStart(query);
|
|
263
272
|
});
|
|
264
|
-
this.sendStart(query);
|
|
265
273
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
flushPending() {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
for (const hash of Object.keys(this.callbacks)) {
|
|
277
|
+
yield this.subs.waitForKeyToLoad(hash);
|
|
278
|
+
const sub = this.subs.currentValue[hash];
|
|
279
|
+
if (sub) {
|
|
280
|
+
yield this.initSubscription(sub.query, sub.hash);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
this.log.error('Missing sub for hash in flushPending', hash);
|
|
284
|
+
}
|
|
275
285
|
}
|
|
276
|
-
}
|
|
286
|
+
});
|
|
277
287
|
}
|
|
278
288
|
onStartSyncOk(msg) {
|
|
279
289
|
const subscriptionId = msg['subscription-id'];
|
|
@@ -298,6 +308,7 @@ export class SyncTable {
|
|
|
298
308
|
}
|
|
299
309
|
}
|
|
300
310
|
onSyncLoadBatch(msg) {
|
|
311
|
+
var _a;
|
|
301
312
|
const subscriptionId = msg['subscription-id'];
|
|
302
313
|
const joinRows = msg['join-rows'];
|
|
303
314
|
const hash = this.idToHash[subscriptionId];
|
|
@@ -311,7 +322,7 @@ export class SyncTable {
|
|
|
311
322
|
this.log.error('Missing sub for hash', hash, msg);
|
|
312
323
|
return;
|
|
313
324
|
}
|
|
314
|
-
const values = sub.values
|
|
325
|
+
const values = (_a = sub.values) !== null && _a !== void 0 ? _a : {
|
|
315
326
|
entities: [],
|
|
316
327
|
attrsStore: this.getAttrs(),
|
|
317
328
|
};
|
|
@@ -342,6 +353,7 @@ export class SyncTable {
|
|
|
342
353
|
}
|
|
343
354
|
}
|
|
344
355
|
onSyncInitFinish(msg) {
|
|
356
|
+
var _a;
|
|
345
357
|
const subscriptionId = msg['subscription-id'];
|
|
346
358
|
const hash = this.idToHash[subscriptionId];
|
|
347
359
|
if (!hash) {
|
|
@@ -366,11 +378,12 @@ export class SyncTable {
|
|
|
366
378
|
if (sub) {
|
|
367
379
|
this.notifyCbs(hash, {
|
|
368
380
|
type: CallbackEventType.InitialSyncComplete,
|
|
369
|
-
data: subData(sub, sub.values
|
|
381
|
+
data: subData(sub, ((_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities) || []),
|
|
370
382
|
});
|
|
371
383
|
}
|
|
372
384
|
}
|
|
373
385
|
onSyncUpdateTriples(msg) {
|
|
386
|
+
var _a, _b, _c;
|
|
374
387
|
const subscriptionId = msg['subscription-id'];
|
|
375
388
|
const hash = this.idToHash[subscriptionId];
|
|
376
389
|
if (!hash) {
|
|
@@ -396,11 +409,11 @@ export class SyncTable {
|
|
|
396
409
|
// Note: this won't work as well when links are involved
|
|
397
410
|
const byEid = {};
|
|
398
411
|
for (const change of tx.changes) {
|
|
399
|
-
const eidChanges = byEid[change.triple[0]]
|
|
412
|
+
const eidChanges = (_a = byEid[change.triple[0]]) !== null && _a !== void 0 ? _a : [];
|
|
400
413
|
byEid[change.triple[0]] = eidChanges;
|
|
401
414
|
eidChanges.push(change);
|
|
402
415
|
}
|
|
403
|
-
const values = sub.values
|
|
416
|
+
const values = (_b = sub.values) !== null && _b !== void 0 ? _b : {
|
|
404
417
|
entities: [],
|
|
405
418
|
attrsStore: this.getAttrs(),
|
|
406
419
|
};
|
|
@@ -461,7 +474,7 @@ export class SyncTable {
|
|
|
461
474
|
sortEntitiesInPlace(sub, orderFieldType, entities);
|
|
462
475
|
this.notifyCbs(hash, {
|
|
463
476
|
type: CallbackEventType.SyncTransaction,
|
|
464
|
-
data: subData(sub, sub.values
|
|
477
|
+
data: subData(sub, (_c = sub.values) === null || _c === void 0 ? void 0 : _c.entities),
|
|
465
478
|
added,
|
|
466
479
|
removed,
|
|
467
480
|
updated,
|