cojson-storage-indexeddb 0.19.3 → 0.19.4
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +7 -0
- package/dist/CoJsonIDBTransaction.d.ts +1 -0
- package/dist/CoJsonIDBTransaction.d.ts.map +1 -1
- package/dist/CoJsonIDBTransaction.js +3 -0
- package/dist/CoJsonIDBTransaction.js.map +1 -1
- package/dist/idbClient.d.ts +18 -15
- package/dist/idbClient.d.ts.map +1 -1
- package/dist/idbClient.js +39 -46
- package/dist/idbClient.js.map +1 -1
- package/package.json +2 -2
- package/src/CoJsonIDBTransaction.ts +4 -0
- package/src/idbClient.ts +85 -94
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoJsonIDBTransaction.d.ts","sourceRoot":"","sources":["../src/CoJsonIDBTransaction.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,UAAU,GACV,cAAc,GACd,gBAAgB,CAAC;AAKrB,qBAAa,oBAAoB;IAC/B,EAAE,EAAE,WAAW,CAAC;IACR,EAAE,EAAE,cAAc,CAAC;IAE3B,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAM;IAClD,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAM;IAEpC,EAAE,SAAiB;IAEnB,OAAO,UAAS;IAChB,MAAM,UAAS;IACf,IAAI,UAAS;gBAED,EAAE,EAAE,WAAW;IAM3B,OAAO;IAcP,SAAS,SAAqB;IAC9B,UAAU;IAKV,cAAc,CAAC,IAAI,EAAE,SAAS;IAS9B,OAAO,CAAC,WAAW;IAgCnB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC;IAy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CAAC,EAAE,CAAC,SAAS,WAAW,EACxD,EAAE,EAAE,WAAW,EACf,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,CAAC,cAeT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoJsonIDBTransaction.js","sourceRoot":"","sources":["../src/CoJsonIDBTransaction.ts"],"names":[],"mappings":"AAMA,gDAAgD;AAChD,6FAA6F;AAC7F,2BAA2B;AAC3B,MAAM,OAAO,oBAAoB;IAa/B,YAAY,EAAe;QAT3B,oBAAe,GAAgC,EAAE,CAAC;QAClD,mBAAc,GAAmB,EAAE,CAAC;QAEpC,OAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAEnB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAG,KAAK,CAAC;QACf,SAAI,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"CoJsonIDBTransaction.js","sourceRoot":"","sources":["../src/CoJsonIDBTransaction.ts"],"names":[],"mappings":"AAMA,gDAAgD;AAChD,6FAA6F;AAC7F,2BAA2B;AAC3B,MAAM,OAAO,oBAAoB;IAa/B,YAAY,EAAe;QAT3B,oBAAe,GAAgC,EAAE,CAAC;QAClD,mBAAc,GAAmB,EAAE,CAAC;QAEpC,OAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAEnB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAG,KAAK,CAAC;QACf,SAAI,GAAG,KAAK,CAAC;QA0Bb,cAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAvB5B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,WAAW,CAC3B,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,CAAC,EAC1D,WAAW,CACZ,CAAC;QAEF,IAAI,C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O,CAAC,OAAO,CAAC,MAAW,CAAC,CAAC;YAC7B,EAAE,CAAC,MAAM,EAAE,CAAC;QACd,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/idbClient.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import type { CojsonInternalTypes, RawCoID, SessionID } from "cojson";
|
|
1
|
+
import type { CojsonInternalTypes, RawCoID, SessionID, DBTransactionInterfaceAsync } from "cojson";
|
|
2
2
|
import type { DBClientInterfaceAsync, SessionRow, SignatureAfterRow, StoredCoValueRow, StoredSessionRow, TransactionRow } from "cojson";
|
|
3
3
|
import { CoJsonIDBTransaction } from "./CoJsonIDBTransaction.js";
|
|
4
|
-
export declare class
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
constructor(db: IDBDatabase);
|
|
9
|
-
makeRequest<T>(handler: (txEntry: CoJsonIDBTransaction) => IDBRequest<T>): Promise<T>;
|
|
10
|
-
getCoValue(coValueId: RawCoID): Promise<StoredCoValueRow | undefined>;
|
|
11
|
-
getCoValueRowID(coValueId: RawCoID): Promise<number | undefined>;
|
|
12
|
-
getCoValueSessions(coValueRowId: number): Promise<StoredSessionRow[]>;
|
|
4
|
+
export declare class IDBTransaction implements DBTransactionInterfaceAsync {
|
|
5
|
+
private tx;
|
|
6
|
+
constructor(tx: CoJsonIDBTransaction);
|
|
7
|
+
run<T>(handler: (txEntry: CoJsonIDBTransaction) => IDBRequest<T>): Promise<T>;
|
|
13
8
|
getSingleCoValueSession(coValueRowId: number, sessionID: SessionID): Promise<StoredSessionRow | undefined>;
|
|
14
|
-
getNewTransactionInSession(sessionRowId: number, fromIdx: number, toIdx: number): Promise<TransactionRow[]>;
|
|
15
|
-
getSignatures(sessionRowId: number, firstNewTxIdx: number): Promise<SignatureAfterRow[]>;
|
|
16
|
-
upsertCoValue(id: RawCoID, header?: CojsonInternalTypes.CoValueHeader): Promise<number | undefined>;
|
|
17
9
|
addSessionUpdate({ sessionUpdate, sessionRow, }: {
|
|
18
10
|
sessionUpdate: SessionRow;
|
|
19
11
|
sessionRow?: StoredSessionRow;
|
|
@@ -24,7 +16,18 @@ export declare class IDBClient implements DBClientInterfaceAsync {
|
|
|
24
16
|
idx: number;
|
|
25
17
|
signature: CojsonInternalTypes.Signature;
|
|
26
18
|
}): Promise<IDBValidKey>;
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
}
|
|
20
|
+
export declare class IDBClient implements DBClientInterfaceAsync {
|
|
21
|
+
private db;
|
|
22
|
+
activeTransaction: CoJsonIDBTransaction | undefined;
|
|
23
|
+
autoBatchingTransaction: CoJsonIDBTransaction | undefined;
|
|
24
|
+
constructor(db: IDBDatabase);
|
|
25
|
+
getCoValue(coValueId: RawCoID): Promise<StoredCoValueRow | undefined>;
|
|
26
|
+
getCoValueRowID(coValueId: RawCoID): Promise<number | undefined>;
|
|
27
|
+
getCoValueSessions(coValueRowId: number): Promise<StoredSessionRow[]>;
|
|
28
|
+
getNewTransactionInSession(sessionRowId: number, fromIdx: number, toIdx: number): Promise<TransactionRow[]>;
|
|
29
|
+
getSignatures(sessionRowId: number, firstNewTxIdx: number): Promise<SignatureAfterRow[]>;
|
|
30
|
+
upsertCoValue(id: RawCoID, header?: CojsonInternalTypes.CoValueHeader): Promise<number | undefined>;
|
|
31
|
+
transaction(operationsCallback: (tx: DBTransactionInterfaceAsync) => Promise<unknown>): Promise<void>;
|
|
29
32
|
}
|
|
30
33
|
//# sourceMappingURL=idbClient.d.ts.map
|
package/dist/idbClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idbClient.d.ts","sourceRoot":"","sources":["../src/idbClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"idbClient.d.ts","sourceRoot":"","sources":["../src/idbClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,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,CAAC;IAMrE,eAAe,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAIhE,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAMrE,0BAA0B,CAC9B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,cAAc,EAAE,CAAC;IAQtB,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAWzB,aAAa,CACjB,EAAE,EAAE,OAAO,EACX,MAAM,CAAC,EAAE,mBAAmB,CAAC,aAAa,GACzC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAWxB,WAAW,CACf,kBAAkB,EAAE,CAAC,EAAE,EAAE,2BAA2B,KAAK,OAAO,CAAC,OAAO,CAAC;CAW5E"}
|
package/dist/idbClient.js
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
import { CoJsonIDBTransaction, putIndexedDbStore, queryIndexedDbStore, } from "./CoJsonIDBTransaction.js";
|
|
2
|
+
export class IDBTransaction {
|
|
3
|
+
constructor(tx) {
|
|
4
|
+
this.tx = tx;
|
|
5
|
+
}
|
|
6
|
+
run(handler) {
|
|
7
|
+
return this.tx.handleRequest(handler);
|
|
8
|
+
}
|
|
9
|
+
async getSingleCoValueSession(coValueRowId, sessionID) {
|
|
10
|
+
return this.run((tx) => tx
|
|
11
|
+
.getObjectStore("sessions")
|
|
12
|
+
.index("uniqueSessions")
|
|
13
|
+
.get([coValueRowId, sessionID]));
|
|
14
|
+
}
|
|
15
|
+
async addSessionUpdate({ sessionUpdate, sessionRow, }) {
|
|
16
|
+
return this.run((tx) => tx.getObjectStore("sessions").put(sessionRow?.rowID
|
|
17
|
+
? {
|
|
18
|
+
rowID: sessionRow.rowID,
|
|
19
|
+
...sessionUpdate,
|
|
20
|
+
}
|
|
21
|
+
: sessionUpdate));
|
|
22
|
+
}
|
|
23
|
+
async addTransaction(sessionRowID, idx, newTransaction) {
|
|
24
|
+
await this.run((tx) => tx.getObjectStore("transactions").add({
|
|
25
|
+
ses: sessionRowID,
|
|
26
|
+
idx,
|
|
27
|
+
tx: newTransaction,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
async addSignatureAfter({ sessionRowID, idx, signature, }) {
|
|
31
|
+
return this.run((tx) => tx.getObjectStore("signatureAfter").put({
|
|
32
|
+
ses: sessionRowID,
|
|
33
|
+
idx,
|
|
34
|
+
signature,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
2
38
|
export class IDBClient {
|
|
3
39
|
constructor(db) {
|
|
4
40
|
this.db = db;
|
|
5
41
|
}
|
|
6
|
-
makeRequest(handler) {
|
|
7
|
-
if (this.activeTransaction) {
|
|
8
|
-
return this.activeTransaction.handleRequest(handler);
|
|
9
|
-
}
|
|
10
|
-
if (this.autoBatchingTransaction?.isReusable()) {
|
|
11
|
-
return this.autoBatchingTransaction.handleRequest(handler);
|
|
12
|
-
}
|
|
13
|
-
const tx = new CoJsonIDBTransaction(this.db);
|
|
14
|
-
this.autoBatchingTransaction = tx;
|
|
15
|
-
return tx.handleRequest(handler);
|
|
16
|
-
}
|
|
17
42
|
async getCoValue(coValueId) {
|
|
18
43
|
return queryIndexedDbStore(this.db, "coValues", (store) => store.index("coValuesById").get(coValueId));
|
|
19
44
|
}
|
|
@@ -23,9 +48,6 @@ export class IDBClient {
|
|
|
23
48
|
async getCoValueSessions(coValueRowId) {
|
|
24
49
|
return queryIndexedDbStore(this.db, "sessions", (store) => store.index("sessionsByCoValue").getAll(coValueRowId));
|
|
25
50
|
}
|
|
26
|
-
async getSingleCoValueSession(coValueRowId, sessionID) {
|
|
27
|
-
return queryIndexedDbStore(this.db, "sessions", (store) => store.index("uniqueSessions").get([coValueRowId, sessionID]));
|
|
28
|
-
}
|
|
29
51
|
async getNewTransactionInSession(sessionRowId, fromIdx, toIdx) {
|
|
30
52
|
return queryIndexedDbStore(this.db, "transactions", (store) => store.getAll(IDBKeyRange.bound([sessionRowId, fromIdx], [sessionRowId, toIdx])));
|
|
31
53
|
}
|
|
@@ -41,43 +63,14 @@ export class IDBClient {
|
|
|
41
63
|
header,
|
|
42
64
|
}).catch(() => this.getCoValueRowID(id));
|
|
43
65
|
}
|
|
44
|
-
async addSessionUpdate({ sessionUpdate, sessionRow, }) {
|
|
45
|
-
return this.makeRequest((tx) => tx.getObjectStore("sessions").put(sessionRow?.rowID
|
|
46
|
-
? {
|
|
47
|
-
rowID: sessionRow.rowID,
|
|
48
|
-
...sessionUpdate,
|
|
49
|
-
}
|
|
50
|
-
: sessionUpdate));
|
|
51
|
-
}
|
|
52
|
-
async addTransaction(sessionRowID, idx, newTransaction) {
|
|
53
|
-
await this.makeRequest((tx) => tx.getObjectStore("transactions").add({
|
|
54
|
-
ses: sessionRowID,
|
|
55
|
-
idx,
|
|
56
|
-
tx: newTransaction,
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
async addSignatureAfter({ sessionRowID, idx, signature, }) {
|
|
60
|
-
return this.makeRequest((tx) => tx.getObjectStore("signatureAfter").put({
|
|
61
|
-
ses: sessionRowID,
|
|
62
|
-
idx,
|
|
63
|
-
signature,
|
|
64
|
-
}));
|
|
65
|
-
}
|
|
66
|
-
closeTransaction(tx) {
|
|
67
|
-
tx.commit();
|
|
68
|
-
if (tx === this.activeTransaction) {
|
|
69
|
-
this.activeTransaction = undefined;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
66
|
async transaction(operationsCallback) {
|
|
73
67
|
const tx = new CoJsonIDBTransaction(this.db);
|
|
74
|
-
this.activeTransaction = tx;
|
|
75
68
|
try {
|
|
76
|
-
await operationsCallback();
|
|
69
|
+
await operationsCallback(new IDBTransaction(tx));
|
|
77
70
|
tx.commit(); // Tells the browser to not wait for another possible request and commit the transaction immediately
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
catch (error) {
|
|
73
|
+
tx.rollback();
|
|
81
74
|
}
|
|
82
75
|
}
|
|
83
76
|
}
|
package/dist/idbClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idbClient.js","sourceRoot":"","sources":["../src/idbClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"idbClient.js","sourceRoot":"","sources":["../src/idbClient.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,OAAO,cAAc;IACzB,YAAoB,EAAwB;QAAxB,OAAE,GAAF,EAAE,CAAsB;IAAG,CAAC;IAEhD,GAAG,CACD,OAAyD;QAEzD,OAAO,IAAI,CAAC,EAAE,CAAC,aAAa,CAAI,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,YAAoB,EACpB,SAAoB;QAEpB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CACrB,EAAE;aACC,cAAc,CAAC,UAAU,CAAC;aAC1B,KAAK,CAAC,gBAAgB,CAAC;aACvB,GAAG,CAAC,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAClC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,EACrB,aAAa,EACb,UAAU,GAIX;QACC,OAAO,IAAI,CAAC,GAAG,CACb,CAAC,EAAE,EAAE,EAAE,CACL,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,GAAG,CAC/B,UAAU,EAAE,KAAK;YACf,CAAC,CAAC;gBACE,KAAK,EAAE,UAAU,CAAC,KAAK;gBACvB,GAAG,aAAa;aACjB;YACH,CAAC,CAAC,aAAa,CACI,CAC1B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,YAAoB,EACpB,GAA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E,CAAC;YACf,EAAE,CAAC,QAAQ,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cojson-storage-indexeddb",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"cojson": "0.19.
|
|
9
|
+
"cojson": "0.19.4"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"typescript": "5.6.2",
|
package/src/idbClient.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
CojsonInternalTypes,
|
|
3
|
+
RawCoID,
|
|
4
|
+
SessionID,
|
|
5
|
+
DBTransactionInterfaceAsync,
|
|
6
|
+
} from "cojson";
|
|
2
7
|
import type {
|
|
3
8
|
CoValueRow,
|
|
4
9
|
DBClientInterfaceAsync,
|
|
@@ -13,34 +18,89 @@ import {
|
|
|
13
18
|
putIndexedDbStore,
|
|
14
19
|
queryIndexedDbStore,
|
|
15
20
|
} from "./CoJsonIDBTransaction.js";
|
|
16
|
-
import { StoreName } from "./CoJsonIDBTransaction.js";
|
|
17
21
|
|
|
18
|
-
export class
|
|
19
|
-
private
|
|
22
|
+
export class IDBTransaction implements DBTransactionInterfaceAsync {
|
|
23
|
+
constructor(private tx: CoJsonIDBTransaction) {}
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
run<T>(
|
|
26
|
+
handler: (txEntry: CoJsonIDBTransaction) => IDBRequest<T>,
|
|
27
|
+
): Promise<T> {
|
|
28
|
+
return this.tx.handleRequest<T>(handler);
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
async getSingleCoValueSession(
|
|
32
|
+
coValueRowId: number,
|
|
33
|
+
sessionID: SessionID,
|
|
34
|
+
): Promise<StoredSessionRow | undefined> {
|
|
35
|
+
return this.run((tx) =>
|
|
36
|
+
tx
|
|
37
|
+
.getObjectStore("sessions")
|
|
38
|
+
.index("uniqueSessions")
|
|
39
|
+
.get([coValueRowId, sessionID]),
|
|
40
|
+
);
|
|
26
41
|
}
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
async addSessionUpdate({
|
|
44
|
+
sessionUpdate,
|
|
45
|
+
sessionRow,
|
|
46
|
+
}: {
|
|
47
|
+
sessionUpdate: SessionRow;
|
|
48
|
+
sessionRow?: StoredSessionRow;
|
|
49
|
+
}): Promise<number> {
|
|
50
|
+
return this.run<number>(
|
|
51
|
+
(tx) =>
|
|
52
|
+
tx.getObjectStore("sessions").put(
|
|
53
|
+
sessionRow?.rowID
|
|
54
|
+
? {
|
|
55
|
+
rowID: sessionRow.rowID,
|
|
56
|
+
...sessionUpdate,
|
|
57
|
+
}
|
|
58
|
+
: sessionUpdate,
|
|
59
|
+
) as IDBRequest<number>,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
async addTransaction(
|
|
64
|
+
sessionRowID: number,
|
|
65
|
+
idx: number,
|
|
66
|
+
newTransaction: CojsonInternalTypes.Transaction,
|
|
67
|
+
) {
|
|
68
|
+
await this.run((tx) =>
|
|
69
|
+
tx.getObjectStore("transactions").add({
|
|
70
|
+
ses: sessionRowID,
|
|
71
|
+
idx,
|
|
72
|
+
tx: newTransaction,
|
|
73
|
+
} satisfies TransactionRow),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
38
76
|
|
|
39
|
-
|
|
77
|
+
async addSignatureAfter({
|
|
78
|
+
sessionRowID,
|
|
79
|
+
idx,
|
|
80
|
+
signature,
|
|
81
|
+
}: {
|
|
82
|
+
sessionRowID: number;
|
|
83
|
+
idx: number;
|
|
84
|
+
signature: CojsonInternalTypes.Signature;
|
|
85
|
+
}) {
|
|
86
|
+
return this.run((tx) =>
|
|
87
|
+
tx.getObjectStore("signatureAfter").put({
|
|
88
|
+
ses: sessionRowID,
|
|
89
|
+
idx,
|
|
90
|
+
signature,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
40
95
|
|
|
41
|
-
|
|
96
|
+
export class IDBClient implements DBClientInterfaceAsync {
|
|
97
|
+
private db;
|
|
98
|
+
|
|
99
|
+
activeTransaction: CoJsonIDBTransaction | undefined;
|
|
100
|
+
autoBatchingTransaction: CoJsonIDBTransaction | undefined;
|
|
42
101
|
|
|
43
|
-
|
|
102
|
+
constructor(db: IDBDatabase) {
|
|
103
|
+
this.db = db;
|
|
44
104
|
}
|
|
45
105
|
|
|
46
106
|
async getCoValue(coValueId: RawCoID): Promise<StoredCoValueRow | undefined> {
|
|
@@ -59,15 +119,6 @@ export class IDBClient implements DBClientInterfaceAsync {
|
|
|
59
119
|
);
|
|
60
120
|
}
|
|
61
121
|
|
|
62
|
-
async getSingleCoValueSession(
|
|
63
|
-
coValueRowId: number,
|
|
64
|
-
sessionID: SessionID,
|
|
65
|
-
): Promise<StoredSessionRow | undefined> {
|
|
66
|
-
return queryIndexedDbStore(this.db, "sessions", (store) =>
|
|
67
|
-
store.index("uniqueSessions").get([coValueRowId, sessionID]),
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
122
|
async getNewTransactionInSession(
|
|
72
123
|
sessionRowId: number,
|
|
73
124
|
fromIdx: number,
|
|
@@ -108,76 +159,16 @@ export class IDBClient implements DBClientInterfaceAsync {
|
|
|
108
159
|
}).catch(() => this.getCoValueRowID(id));
|
|
109
160
|
}
|
|
110
161
|
|
|
111
|
-
async
|
|
112
|
-
|
|
113
|
-
sessionRow,
|
|
114
|
-
}: {
|
|
115
|
-
sessionUpdate: SessionRow;
|
|
116
|
-
sessionRow?: StoredSessionRow;
|
|
117
|
-
}): Promise<number> {
|
|
118
|
-
return this.makeRequest<number>(
|
|
119
|
-
(tx) =>
|
|
120
|
-
tx.getObjectStore("sessions").put(
|
|
121
|
-
sessionRow?.rowID
|
|
122
|
-
? {
|
|
123
|
-
rowID: sessionRow.rowID,
|
|
124
|
-
...sessionUpdate,
|
|
125
|
-
}
|
|
126
|
-
: sessionUpdate,
|
|
127
|
-
) as IDBRequest<number>,
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async addTransaction(
|
|
132
|
-
sessionRowID: number,
|
|
133
|
-
idx: number,
|
|
134
|
-
newTransaction: CojsonInternalTypes.Transaction,
|
|
162
|
+
async transaction(
|
|
163
|
+
operationsCallback: (tx: DBTransactionInterfaceAsync) => Promise<unknown>,
|
|
135
164
|
) {
|
|
136
|
-
await this.makeRequest((tx) =>
|
|
137
|
-
tx.getObjectStore("transactions").add({
|
|
138
|
-
ses: sessionRowID,
|
|
139
|
-
idx,
|
|
140
|
-
tx: newTransaction,
|
|
141
|
-
} satisfies TransactionRow),
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async addSignatureAfter({
|
|
146
|
-
sessionRowID,
|
|
147
|
-
idx,
|
|
148
|
-
signature,
|
|
149
|
-
}: {
|
|
150
|
-
sessionRowID: number;
|
|
151
|
-
idx: number;
|
|
152
|
-
signature: CojsonInternalTypes.Signature;
|
|
153
|
-
}) {
|
|
154
|
-
return this.makeRequest((tx) =>
|
|
155
|
-
tx.getObjectStore("signatureAfter").put({
|
|
156
|
-
ses: sessionRowID,
|
|
157
|
-
idx,
|
|
158
|
-
signature,
|
|
159
|
-
}),
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
closeTransaction(tx: CoJsonIDBTransaction) {
|
|
164
|
-
tx.commit();
|
|
165
|
-
|
|
166
|
-
if (tx === this.activeTransaction) {
|
|
167
|
-
this.activeTransaction = undefined;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async transaction(operationsCallback: () => unknown) {
|
|
172
165
|
const tx = new CoJsonIDBTransaction(this.db);
|
|
173
166
|
|
|
174
|
-
this.activeTransaction = tx;
|
|
175
|
-
|
|
176
167
|
try {
|
|
177
|
-
await operationsCallback();
|
|
168
|
+
await operationsCallback(new IDBTransaction(tx));
|
|
178
169
|
tx.commit(); // Tells the browser to not wait for another possible request and commit the transaction immediately
|
|
179
|
-
}
|
|
180
|
-
|
|
170
|
+
} catch (error) {
|
|
171
|
+
tx.rollback();
|
|
181
172
|
}
|
|
182
173
|
}
|
|
183
174
|
}
|