@instantdb/core 0.22.96-experimental.drewh-ts-target.20761590091.1 → 0.22.96-experimental.surgical.20765334274.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
|
@@ -1,4 +1,13 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.uploadFile = uploadFile;
|
|
4
13
|
exports.deleteFile = deleteFile;
|
|
@@ -6,67 +15,77 @@ exports.getSignedUploadUrl = getSignedUploadUrl;
|
|
|
6
15
|
exports.upload = upload;
|
|
7
16
|
exports.getDownloadUrl = getDownloadUrl;
|
|
8
17
|
const fetch_js_1 = require("./utils/fetch.js");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
function uploadFile(_a) {
|
|
19
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, file, refreshToken, contentType, contentDisposition, }) {
|
|
20
|
+
const headers = {
|
|
21
|
+
app_id: appId,
|
|
22
|
+
path,
|
|
23
|
+
authorization: `Bearer ${refreshToken}`,
|
|
24
|
+
'content-type': contentType || file.type,
|
|
25
|
+
};
|
|
26
|
+
if (contentDisposition) {
|
|
27
|
+
headers['content-disposition'] = contentDisposition;
|
|
28
|
+
}
|
|
29
|
+
const data = yield (0, fetch_js_1.jsonFetch)(`${apiURI}/storage/upload`, {
|
|
30
|
+
method: 'PUT',
|
|
31
|
+
headers,
|
|
32
|
+
body: file,
|
|
33
|
+
});
|
|
34
|
+
return data;
|
|
23
35
|
});
|
|
24
|
-
return data;
|
|
25
36
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
function deleteFile(_a) {
|
|
38
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, refreshToken, }) {
|
|
39
|
+
const { data } = yield (0, fetch_js_1.jsonFetch)(`${apiURI}/storage/files?app_id=${appId}&filename=${encodeURIComponent(path)}`, {
|
|
40
|
+
method: 'DELETE',
|
|
41
|
+
headers: {
|
|
42
|
+
'content-type': 'application/json',
|
|
43
|
+
authorization: `Bearer ${refreshToken}`,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return data;
|
|
33
47
|
});
|
|
34
|
-
return data;
|
|
35
48
|
}
|
|
36
49
|
// Deprecated Storage API (Jan 2025)
|
|
37
50
|
// ---------------------------------
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
function getSignedUploadUrl(_a) {
|
|
52
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, fileName, refreshToken, metadata = {}, }) {
|
|
53
|
+
const { data } = yield (0, fetch_js_1.jsonFetch)(`${apiURI}/storage/signed-upload-url`, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'content-type': 'application/json',
|
|
57
|
+
authorization: `Bearer ${refreshToken}`,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify({
|
|
60
|
+
app_id: appId,
|
|
61
|
+
filename: fileName,
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
return data;
|
|
49
65
|
});
|
|
50
|
-
return data;
|
|
51
66
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
function upload(presignedUrl, file) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const response = yield fetch(presignedUrl, {
|
|
70
|
+
method: 'PUT',
|
|
71
|
+
body: file,
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': file.type,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return response.ok;
|
|
59
77
|
});
|
|
60
|
-
return response.ok;
|
|
61
78
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
79
|
+
function getDownloadUrl(_a) {
|
|
80
|
+
return __awaiter(this, arguments, void 0, function* ({ apiURI, appId, path, refreshToken, }) {
|
|
81
|
+
const { data } = yield (0, fetch_js_1.jsonFetch)(`${apiURI}/storage/signed-download-url?app_id=${appId}&filename=${encodeURIComponent(path)}`, {
|
|
82
|
+
method: 'GET',
|
|
83
|
+
headers: {
|
|
84
|
+
'content-type': 'application/json',
|
|
85
|
+
authorization: `Bearer ${refreshToken}`,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
return data;
|
|
69
89
|
});
|
|
70
|
-
return data;
|
|
71
90
|
}
|
|
72
91
|
//# sourceMappingURL=StorageAPI.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageAPI.js","sourceRoot":"","sources":["../../src/StorageAPI.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StorageAPI.js","sourceRoot":"","sources":["../../src/StorageAPI.ts"],"names":[],"mappings":";;;;;;;;;;;AAcA,gCAkCC;AAED,gCAuBC;AAKD,gDA0BC;AAED,wBAUC;AAED,wCAyBC;AA/ID,+CAA6C;AAc7C,SAAsB,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,IAAA,oBAAS,EAAC,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,SAAsB,UAAU;yDAAC,EAC/B,MAAM,EACN,KAAK,EACL,IAAI,EACJ,YAAY,GAMb;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,oBAAS,EAC9B,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,SAAsB,kBAAkB;yDAAC,EACvC,MAAM,EACN,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,QAAQ,GAAG,EAAE,GAOd;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,oBAAS,EAAC,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,SAAsB,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,SAAsB,cAAc;yDAAC,EACnC,MAAM,EACN,KAAK,EACL,IAAI,EACJ,YAAY,GAMb;QACC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,oBAAS,EAC9B,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"]}
|
|
@@ -32,6 +32,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
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
|
+
};
|
|
35
44
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
46
|
};
|
|
@@ -58,24 +67,23 @@ function syncSubFromStorage(sub, useDateObjects) {
|
|
|
58
67
|
return sub;
|
|
59
68
|
}
|
|
60
69
|
function syncSubToStorage(_k, sub) {
|
|
70
|
+
var _a;
|
|
61
71
|
if (sub.values) {
|
|
62
72
|
const entities = [];
|
|
63
|
-
for (const e of sub.values
|
|
73
|
+
for (const e of (_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities) {
|
|
64
74
|
const store = s.toJSON(e.store);
|
|
65
|
-
entities.push({
|
|
75
|
+
entities.push(Object.assign(Object.assign({}, e), { store }));
|
|
66
76
|
}
|
|
67
|
-
return {
|
|
68
|
-
...sub,
|
|
69
|
-
values: { attrsStore: sub.values.attrsStore.toJSON(), entities },
|
|
70
|
-
};
|
|
77
|
+
return Object.assign(Object.assign({}, sub), { values: { attrsStore: sub.values.attrsStore.toJSON(), entities } });
|
|
71
78
|
}
|
|
72
79
|
else {
|
|
73
80
|
return sub;
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
function onMergeSub(_key, storageSub, inMemorySub) {
|
|
77
|
-
|
|
78
|
-
const
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const storageTxId = (_a = storageSub === null || storageSub === void 0 ? void 0 : storageSub.state) === null || _a === void 0 ? void 0 : _a.txId;
|
|
86
|
+
const memoryTxId = (_b = inMemorySub === null || inMemorySub === void 0 ? void 0 : inMemorySub.state) === null || _b === void 0 ? void 0 : _b.txId;
|
|
79
87
|
if (storageTxId && (!memoryTxId || storageTxId > memoryTxId)) {
|
|
80
88
|
return storageSub;
|
|
81
89
|
}
|
|
@@ -89,7 +97,8 @@ function queryEntity(sub, store, attrsStore) {
|
|
|
89
97
|
return res.data[sub.table][0];
|
|
90
98
|
}
|
|
91
99
|
function getServerCreatedAt(sub, store, attrsStore, entityId) {
|
|
92
|
-
|
|
100
|
+
var _a;
|
|
101
|
+
const aid = (_a = s.getAttrByFwdIdentName(attrsStore, sub.table, 'id')) === null || _a === void 0 ? void 0 : _a.id;
|
|
93
102
|
if (!aid) {
|
|
94
103
|
return -1;
|
|
95
104
|
}
|
|
@@ -112,17 +121,18 @@ function applyChangesToStore(store, attrsStore, changes) {
|
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
function changedFieldsOfChanges(store, attrsStore, changes) {
|
|
124
|
+
var _a, _b, _c, _d;
|
|
115
125
|
// This will be more complicated when we include links, we can either add a
|
|
116
126
|
// changedLinks field or we can have something like 'bookshelves.title`
|
|
117
127
|
const changedFields = {};
|
|
118
128
|
for (const { action, triple } of changes) {
|
|
119
129
|
const [e, a, v] = triple;
|
|
120
|
-
const field = attrsStore.getAttr(a)
|
|
130
|
+
const field = (_b = (_a = attrsStore.getAttr(a)) === null || _a === void 0 ? void 0 : _a['forward-identity']) === null || _b === void 0 ? void 0 : _b[2];
|
|
121
131
|
if (!field)
|
|
122
132
|
continue;
|
|
123
|
-
const fields = changedFields[e]
|
|
133
|
+
const fields = (_c = changedFields[e]) !== null && _c !== void 0 ? _c : {};
|
|
124
134
|
changedFields[e] = fields;
|
|
125
|
-
const oldNew = fields[field]
|
|
135
|
+
const oldNew = (_d = fields[field]) !== null && _d !== void 0 ? _d : {};
|
|
126
136
|
switch (action) {
|
|
127
137
|
case 'added':
|
|
128
138
|
oldNew.newValue = v;
|
|
@@ -152,12 +162,13 @@ function subData(sub, entities) {
|
|
|
152
162
|
// and returns the type. We have to wait until the attrs
|
|
153
163
|
// are loaded before we can determine the type.
|
|
154
164
|
function orderFieldTypeMutative(sub, getAttrs) {
|
|
165
|
+
var _a;
|
|
155
166
|
if (sub.orderFieldType) {
|
|
156
167
|
return sub.orderFieldType;
|
|
157
168
|
}
|
|
158
169
|
const orderFieldType = sub.orderField === 'serverCreatedAt'
|
|
159
170
|
? 'number'
|
|
160
|
-
: s.getAttrByFwdIdentName(getAttrs(), sub.table, sub.orderField)
|
|
171
|
+
: (_a = s.getAttrByFwdIdentName(getAttrs(), sub.table, sub.orderField)) === null || _a === void 0 ? void 0 : _a['checked-data-type'];
|
|
161
172
|
sub.orderFieldType = orderFieldType;
|
|
162
173
|
return orderFieldType;
|
|
163
174
|
}
|
|
@@ -191,16 +202,10 @@ var CallbackEventType;
|
|
|
191
202
|
CallbackEventType["Error"] = "Error";
|
|
192
203
|
})(CallbackEventType || (exports.CallbackEventType = CallbackEventType = {}));
|
|
193
204
|
class SyncTable {
|
|
194
|
-
trySend;
|
|
195
|
-
subs;
|
|
196
|
-
// Using any for the SyncCallback because we'd need Reactor to be typed
|
|
197
|
-
callbacks = {};
|
|
198
|
-
config;
|
|
199
|
-
idToHash = {};
|
|
200
|
-
log;
|
|
201
|
-
createStore;
|
|
202
|
-
getAttrs;
|
|
203
205
|
constructor(trySend, storage, config, log, createStore, getAttrs) {
|
|
206
|
+
// Using any for the SyncCallback because we'd need Reactor to be typed
|
|
207
|
+
this.callbacks = {};
|
|
208
|
+
this.idToHash = {};
|
|
204
209
|
this.trySend = trySend;
|
|
205
210
|
this.config = config;
|
|
206
211
|
this.log = log;
|
|
@@ -211,13 +216,13 @@ class SyncTable {
|
|
|
211
216
|
merge: onMergeSub,
|
|
212
217
|
serialize: syncSubToStorage,
|
|
213
218
|
parse: (_key, x) => syncSubFromStorage(x, this.config.useDateObjects),
|
|
214
|
-
objectSize: (sub) => sub.values
|
|
219
|
+
objectSize: (sub) => { var _a; return ((_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities.length) || 0; },
|
|
215
220
|
logger: log,
|
|
216
221
|
gc: {
|
|
217
222
|
maxAgeMs: 1000 * 60 * 60 * 24 * 7 * 52, // 1 year
|
|
218
223
|
maxEntries: 1000,
|
|
219
224
|
// Size of each sub is the number of entity
|
|
220
|
-
maxSize:
|
|
225
|
+
maxSize: 1000000, // 1 million entities
|
|
221
226
|
},
|
|
222
227
|
});
|
|
223
228
|
}
|
|
@@ -230,7 +235,7 @@ class SyncTable {
|
|
|
230
235
|
this.callbacks[hash].push(cb);
|
|
231
236
|
this.initSubscription(q, hash, cb);
|
|
232
237
|
return (opts) => {
|
|
233
|
-
this.unsubscribe(hash, cb, opts
|
|
238
|
+
this.unsubscribe(hash, cb, opts === null || opts === void 0 ? void 0 : opts.keepSubscription);
|
|
234
239
|
};
|
|
235
240
|
}
|
|
236
241
|
unsubscribe(hash, cb, keepSubscription) {
|
|
@@ -239,7 +244,7 @@ class SyncTable {
|
|
|
239
244
|
if (!cbs.length) {
|
|
240
245
|
delete this.callbacks[hash];
|
|
241
246
|
const sub = this.subs.currentValue[hash];
|
|
242
|
-
if (sub
|
|
247
|
+
if (sub === null || sub === void 0 ? void 0 : sub.state) {
|
|
243
248
|
this.clearSubscriptionData(sub.state.subscriptionId, !!keepSubscription);
|
|
244
249
|
}
|
|
245
250
|
if (!keepSubscription) {
|
|
@@ -272,47 +277,52 @@ class SyncTable {
|
|
|
272
277
|
'keep-subscription': keepSubscription,
|
|
273
278
|
});
|
|
274
279
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (existingSub.
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
280
|
+
initSubscription(query, hash, cb) {
|
|
281
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
var _a, _b, _c, _d;
|
|
283
|
+
// Wait for storage to load so that we know if we already have an existing subscription
|
|
284
|
+
yield this.subs.waitForKeyToLoad(hash);
|
|
285
|
+
const existingSub = this.subs.currentValue[hash];
|
|
286
|
+
if (existingSub && existingSub.state && existingSub.state.txId) {
|
|
287
|
+
this.sendResync(existingSub, existingSub.state, existingSub.state.txId);
|
|
288
|
+
if (((_a = existingSub.values) === null || _a === void 0 ? void 0 : _a.entities) && cb) {
|
|
289
|
+
cb({
|
|
290
|
+
type: CallbackEventType.LoadFromStorage,
|
|
291
|
+
data: subData(existingSub, (_b = existingSub.values) === null || _b === void 0 ? void 0 : _b.entities),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
286
295
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
296
|
+
const table = Object.keys(query)[0];
|
|
297
|
+
const orderBy = ((_d = (_c = query[table]) === null || _c === void 0 ? void 0 : _c.$) === null || _d === void 0 ? void 0 : _d.order) || { serverCreatedAt: 'asc' };
|
|
298
|
+
const [orderField, orderDirection] = Object.entries(orderBy)[0];
|
|
299
|
+
this.subs.updateInPlace((prev) => {
|
|
300
|
+
prev[hash] = {
|
|
301
|
+
query,
|
|
302
|
+
hash: hash,
|
|
303
|
+
table,
|
|
304
|
+
orderDirection,
|
|
305
|
+
orderField,
|
|
306
|
+
createdAt: Date.now(),
|
|
307
|
+
updatedAt: Date.now(),
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
this.sendStart(query);
|
|
302
311
|
});
|
|
303
|
-
this.sendStart(query);
|
|
304
312
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
flushPending() {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
for (const hash of Object.keys(this.callbacks)) {
|
|
316
|
+
yield this.subs.waitForKeyToLoad(hash);
|
|
317
|
+
const sub = this.subs.currentValue[hash];
|
|
318
|
+
if (sub) {
|
|
319
|
+
yield this.initSubscription(sub.query, sub.hash);
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
this.log.error('Missing sub for hash in flushPending', hash);
|
|
323
|
+
}
|
|
314
324
|
}
|
|
315
|
-
}
|
|
325
|
+
});
|
|
316
326
|
}
|
|
317
327
|
onStartSyncOk(msg) {
|
|
318
328
|
const subscriptionId = msg['subscription-id'];
|
|
@@ -337,6 +347,7 @@ class SyncTable {
|
|
|
337
347
|
}
|
|
338
348
|
}
|
|
339
349
|
onSyncLoadBatch(msg) {
|
|
350
|
+
var _a;
|
|
340
351
|
const subscriptionId = msg['subscription-id'];
|
|
341
352
|
const joinRows = msg['join-rows'];
|
|
342
353
|
const hash = this.idToHash[subscriptionId];
|
|
@@ -350,7 +361,7 @@ class SyncTable {
|
|
|
350
361
|
this.log.error('Missing sub for hash', hash, msg);
|
|
351
362
|
return;
|
|
352
363
|
}
|
|
353
|
-
const values = sub.values
|
|
364
|
+
const values = (_a = sub.values) !== null && _a !== void 0 ? _a : {
|
|
354
365
|
entities: [],
|
|
355
366
|
attrsStore: this.getAttrs(),
|
|
356
367
|
};
|
|
@@ -381,6 +392,7 @@ class SyncTable {
|
|
|
381
392
|
}
|
|
382
393
|
}
|
|
383
394
|
onSyncInitFinish(msg) {
|
|
395
|
+
var _a;
|
|
384
396
|
const subscriptionId = msg['subscription-id'];
|
|
385
397
|
const hash = this.idToHash[subscriptionId];
|
|
386
398
|
if (!hash) {
|
|
@@ -405,11 +417,12 @@ class SyncTable {
|
|
|
405
417
|
if (sub) {
|
|
406
418
|
this.notifyCbs(hash, {
|
|
407
419
|
type: CallbackEventType.InitialSyncComplete,
|
|
408
|
-
data: subData(sub, sub.values
|
|
420
|
+
data: subData(sub, ((_a = sub.values) === null || _a === void 0 ? void 0 : _a.entities) || []),
|
|
409
421
|
});
|
|
410
422
|
}
|
|
411
423
|
}
|
|
412
424
|
onSyncUpdateTriples(msg) {
|
|
425
|
+
var _a, _b, _c;
|
|
413
426
|
const subscriptionId = msg['subscription-id'];
|
|
414
427
|
const hash = this.idToHash[subscriptionId];
|
|
415
428
|
if (!hash) {
|
|
@@ -435,11 +448,11 @@ class SyncTable {
|
|
|
435
448
|
// Note: this won't work as well when links are involved
|
|
436
449
|
const byEid = {};
|
|
437
450
|
for (const change of tx.changes) {
|
|
438
|
-
const eidChanges = byEid[change.triple[0]]
|
|
451
|
+
const eidChanges = (_a = byEid[change.triple[0]]) !== null && _a !== void 0 ? _a : [];
|
|
439
452
|
byEid[change.triple[0]] = eidChanges;
|
|
440
453
|
eidChanges.push(change);
|
|
441
454
|
}
|
|
442
|
-
const values = sub.values
|
|
455
|
+
const values = (_b = sub.values) !== null && _b !== void 0 ? _b : {
|
|
443
456
|
entities: [],
|
|
444
457
|
attrsStore: this.getAttrs(),
|
|
445
458
|
};
|
|
@@ -500,7 +513,7 @@ class SyncTable {
|
|
|
500
513
|
sortEntitiesInPlace(sub, orderFieldType, entities);
|
|
501
514
|
this.notifyCbs(hash, {
|
|
502
515
|
type: CallbackEventType.SyncTransaction,
|
|
503
|
-
data: subData(sub, sub.values
|
|
516
|
+
data: subData(sub, (_c = sub.values) === null || _c === void 0 ? void 0 : _c.entities),
|
|
504
517
|
added,
|
|
505
518
|
removed,
|
|
506
519
|
updated,
|