@roc-db/indexed-db 0.2.0-pre.2 → 0.2.0-pre.20
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/index.js +28 -3
- package/dist/types/createIndexedDBAdapter.d.ts +3 -15
- package/dist/types/functions/begin.d.ts +1 -1
- package/dist/types/functions/index.d.ts +1 -0
- package/dist/types/functions/pageMutations.d.ts +2 -0
- package/package.json +7 -15
- package/dist/roc-db-indexed-db-0.2.0-pre.2.tgz +0 -0
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __export(exports_functions, {
|
|
|
20
20
|
readMutation: () => readMutation,
|
|
21
21
|
readEntity: () => readEntity,
|
|
22
22
|
patchEntity: () => patchEntity,
|
|
23
|
+
pageMutations: () => pageMutations,
|
|
23
24
|
getChangeSetMutations: () => getChangeSetMutations,
|
|
24
25
|
findDebounceMutation: () => findDebounceMutation,
|
|
25
26
|
end: () => end,
|
|
@@ -29,7 +30,7 @@ __export(exports_functions, {
|
|
|
29
30
|
});
|
|
30
31
|
|
|
31
32
|
// src/functions/begin.ts
|
|
32
|
-
var begin = async (request, engineOpts) => {
|
|
33
|
+
var begin = async (request, engineOpts, callback) => {
|
|
33
34
|
return new Promise((resolve, reject) => {
|
|
34
35
|
let db;
|
|
35
36
|
const idbRequest = indexedDB.open(engineOpts.dbName, 1);
|
|
@@ -45,7 +46,7 @@ var begin = async (request, engineOpts) => {
|
|
|
45
46
|
};
|
|
46
47
|
idbRequest.onsuccess = (event) => {
|
|
47
48
|
db = idbRequest.result;
|
|
48
|
-
resolve({
|
|
49
|
+
resolve(callback({
|
|
49
50
|
...engineOpts,
|
|
50
51
|
db,
|
|
51
52
|
txn: db.transaction(["entities", "mutations"], request.type === "write" ? "readwrite" : "readonly"),
|
|
@@ -53,7 +54,7 @@ var begin = async (request, engineOpts) => {
|
|
|
53
54
|
entities: new Map([]),
|
|
54
55
|
mutations: new Map([])
|
|
55
56
|
} : null
|
|
56
|
-
});
|
|
57
|
+
}));
|
|
57
58
|
};
|
|
58
59
|
});
|
|
59
60
|
};
|
|
@@ -189,6 +190,28 @@ var findDebounceMutation = async (request, engine, now) => {
|
|
|
189
190
|
};
|
|
190
191
|
});
|
|
191
192
|
};
|
|
193
|
+
// src/functions/pageMutations.ts
|
|
194
|
+
var pageMutations = async (txn, args) => {
|
|
195
|
+
const { size, changeSetRef, skip } = args;
|
|
196
|
+
if (!changeSetRef)
|
|
197
|
+
throw new Error("changeSetRef is required");
|
|
198
|
+
const objectStore = txn.engineOpts.txn.objectStore("mutations");
|
|
199
|
+
const index = objectStore.index("byChangeSetRef");
|
|
200
|
+
const range = IDBKeyRange.only(changeSetRef);
|
|
201
|
+
const idbRequest = index.openCursor(range);
|
|
202
|
+
return new Promise((resolve, reject) => {
|
|
203
|
+
const results = [];
|
|
204
|
+
idbRequest.onsuccess = () => {
|
|
205
|
+
const cursor = idbRequest.result;
|
|
206
|
+
if (cursor) {
|
|
207
|
+
results.push(cursor.value);
|
|
208
|
+
cursor.continue();
|
|
209
|
+
} else {
|
|
210
|
+
resolve(results);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
};
|
|
192
215
|
// src/functions/patchEntity.ts
|
|
193
216
|
import { deepPatch, NotFoundError } from "roc-db";
|
|
194
217
|
|
|
@@ -315,6 +338,7 @@ var updateEntity = async (txn, ref, { data = {}, children = {}, parents = {}, an
|
|
|
315
338
|
var createIndexedDBAdapter = ({
|
|
316
339
|
operations,
|
|
317
340
|
entities,
|
|
341
|
+
session,
|
|
318
342
|
dbName = "roc-db"
|
|
319
343
|
}) => {
|
|
320
344
|
return createAdapter({
|
|
@@ -322,6 +346,7 @@ var createIndexedDBAdapter = ({
|
|
|
322
346
|
operations,
|
|
323
347
|
entities,
|
|
324
348
|
functions: exports_functions,
|
|
349
|
+
session,
|
|
325
350
|
snowflake: new Snowflake(1, 1),
|
|
326
351
|
async: true
|
|
327
352
|
}, {
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
export declare const createIndexedDBAdapter: ({ operations, entities, dbName, }: {
|
|
1
|
+
export declare const createIndexedDBAdapter: ({ operations, entities, session, dbName, }: {
|
|
2
2
|
operations: any;
|
|
3
3
|
entities: any;
|
|
4
|
+
session: any;
|
|
4
5
|
dbName?: string | undefined;
|
|
5
|
-
}) =>
|
|
6
|
-
_name: string;
|
|
7
|
-
_entityKinds: Entities[number]["shape"]["entity"]["value"];
|
|
8
|
-
_operationNames: Operations[number]["operationName"];
|
|
9
|
-
_operations: Operations;
|
|
10
|
-
_entites: Entities;
|
|
11
|
-
createRef: (entity: any) => string;
|
|
12
|
-
changeSet: (changeSetRef: any) => /*elided*/ any & {
|
|
13
|
-
[x: string]: any;
|
|
14
|
-
};
|
|
15
|
-
syncOptimisticMutation: (mutation: any) => any;
|
|
16
|
-
} & {
|
|
17
|
-
[x: string]: any;
|
|
18
|
-
};
|
|
6
|
+
}) => Adapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const begin: (request: any, engineOpts: any) => Promise<unknown>;
|
|
1
|
+
export declare const begin: (request: any, engineOpts: any, callback: any) => Promise<unknown>;
|
|
@@ -4,6 +4,7 @@ export { deleteEntity } from "./deleteEntity";
|
|
|
4
4
|
export { end } from "./end";
|
|
5
5
|
export { getChangeSetMutations } from "./getChangeSetMutations";
|
|
6
6
|
export { findDebounceMutation } from "./findDebounceMutation";
|
|
7
|
+
export { pageMutations } from "./pageMutations";
|
|
7
8
|
export { patchEntity } from "./patchEntity";
|
|
8
9
|
export { readEntity } from "./readEntity";
|
|
9
10
|
export { readMutation } from "./readMutation";
|
package/package.json
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/indexed-db",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts"
|
|
9
|
+
}
|
|
7
10
|
},
|
|
8
11
|
"files": [
|
|
9
12
|
"dist"
|
|
10
13
|
],
|
|
11
14
|
"sideEffects": false,
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "NODE_ENV=production bun run scripts/build.ts",
|
|
14
|
-
"build:types": "rm -rf dist/types && bun run tsc --noCheck",
|
|
15
|
-
"test": "bun test"
|
|
16
|
-
},
|
|
17
15
|
"dependencies": {},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@roc-db/test-utils": "0.2.0-pre.2",
|
|
20
|
-
"fake-indexeddb": "6.0.0",
|
|
21
|
-
"roc-db": "0.2.0-pre.2",
|
|
22
|
-
"zod": "3.24.2"
|
|
23
|
-
},
|
|
24
16
|
"peerDependencies": {
|
|
25
|
-
"roc-db": "0.2.0-pre.
|
|
26
|
-
"zod": "3.
|
|
17
|
+
"roc-db": "0.2.0-pre.20",
|
|
18
|
+
"zod": "^3.0.0"
|
|
27
19
|
},
|
|
28
20
|
"keywords": [],
|
|
29
21
|
"author": "Eigil Sagafos",
|
|
Binary file
|