@roc-db/indexed-db 0.2.0-pre.2 → 0.2.0-pre.21

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 CHANGED
@@ -20,16 +20,45 @@ __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,
26
27
  deleteEntity: () => deleteEntity,
27
28
  createEntity: () => createEntity,
28
- begin: () => begin
29
+ begin: () => begin,
30
+ batchReadEntities: () => batchReadEntities
29
31
  });
30
32
 
33
+ // src/functions/readEntity.ts
34
+ import { DELETED_IN_CHANGE_SET_SYMBOL } from "roc-db";
35
+ var readEntity = (txn, ref) => {
36
+ if (txn.request.changeSetRef) {
37
+ const doc = txn.engineOpts.changeSet.entities.get(ref);
38
+ if (doc === DELETED_IN_CHANGE_SET_SYMBOL)
39
+ return;
40
+ if (doc)
41
+ return doc;
42
+ }
43
+ const objectStore = txn.engineOpts.txn.objectStore("entities");
44
+ const request = objectStore.get(ref);
45
+ return new Promise((resolve, reject) => {
46
+ request.onsuccess = (event) => {
47
+ const document = event.target.result;
48
+ resolve(document);
49
+ };
50
+ request.onerror = (event) => {
51
+ reject(event.target.error);
52
+ };
53
+ });
54
+ };
55
+
56
+ // src/functions/batchReadEntities.ts
57
+ var batchReadEntities = (txn, refs) => {
58
+ return Promise.all(refs.map((ref) => readEntity(txn, ref)));
59
+ };
31
60
  // src/functions/begin.ts
32
- var begin = async (request, engineOpts) => {
61
+ var begin = async (request, engineOpts, callback) => {
33
62
  return new Promise((resolve, reject) => {
34
63
  let db;
35
64
  const idbRequest = indexedDB.open(engineOpts.dbName, 1);
@@ -45,7 +74,7 @@ var begin = async (request, engineOpts) => {
45
74
  };
46
75
  idbRequest.onsuccess = (event) => {
47
76
  db = idbRequest.result;
48
- resolve({
77
+ resolve(callback({
49
78
  ...engineOpts,
50
79
  db,
51
80
  txn: db.transaction(["entities", "mutations"], request.type === "write" ? "readwrite" : "readonly"),
@@ -53,7 +82,7 @@ var begin = async (request, engineOpts) => {
53
82
  entities: new Map([]),
54
83
  mutations: new Map([])
55
84
  } : null
56
- });
85
+ }));
57
86
  };
58
87
  });
59
88
  };
@@ -99,7 +128,7 @@ var createEntity = (txn, ref, { data = {}, children = {}, ancestors = {}, parent
99
128
  }
100
129
  };
101
130
  // src/functions/deleteEntity.ts
102
- import { DELETED_IN_CHANGE_SET_SYMBOL } from "roc-db";
131
+ import { DELETED_IN_CHANGE_SET_SYMBOL as DELETED_IN_CHANGE_SET_SYMBOL2 } from "roc-db";
103
132
  var deleteIndexed = (store, ref) => {
104
133
  const request = store.delete(ref);
105
134
  return new Promise((resolve, reject) => {
@@ -114,7 +143,7 @@ var deleteIndexed = (store, ref) => {
114
143
  };
115
144
  var deleteEntity = async (txn, ref, cascade = false) => {
116
145
  if (txn.request.changeSetRef) {
117
- txn.engineOpts.changeSet.entities.set(ref, DELETED_IN_CHANGE_SET_SYMBOL);
146
+ txn.engineOpts.changeSet.entities.set(ref, DELETED_IN_CHANGE_SET_SYMBOL2);
118
147
  if (cascade) {
119
148
  throw new Error("TGOD");
120
149
  }
@@ -189,33 +218,30 @@ var findDebounceMutation = async (request, engine, now) => {
189
218
  };
190
219
  });
191
220
  };
192
- // src/functions/patchEntity.ts
193
- import { deepPatch, NotFoundError } from "roc-db";
194
-
195
- // src/functions/readEntity.ts
196
- import { DELETED_IN_CHANGE_SET_SYMBOL as DELETED_IN_CHANGE_SET_SYMBOL2 } from "roc-db";
197
- var readEntity = (txn, ref) => {
198
- if (txn.request.changeSetRef) {
199
- const doc = txn.engineOpts.changeSet.entities.get(ref);
200
- if (doc === DELETED_IN_CHANGE_SET_SYMBOL2)
201
- return;
202
- if (doc)
203
- return doc;
204
- }
205
- const objectStore = txn.engineOpts.txn.objectStore("entities");
206
- const request = objectStore.get(ref);
221
+ // src/functions/pageMutations.ts
222
+ var pageMutations = async (txn, args) => {
223
+ const { size, changeSetRef, skip } = args;
224
+ if (!changeSetRef)
225
+ throw new Error("changeSetRef is required");
226
+ const objectStore = txn.engineOpts.txn.objectStore("mutations");
227
+ const index = objectStore.index("byChangeSetRef");
228
+ const range = IDBKeyRange.only(changeSetRef);
229
+ const idbRequest = index.openCursor(range);
207
230
  return new Promise((resolve, reject) => {
208
- request.onsuccess = (event) => {
209
- const document = event.target.result;
210
- resolve(document);
211
- };
212
- request.onerror = (event) => {
213
- reject(event.target.error);
231
+ const results = [];
232
+ idbRequest.onsuccess = () => {
233
+ const cursor = idbRequest.result;
234
+ if (cursor) {
235
+ results.push(cursor.value);
236
+ cursor.continue();
237
+ } else {
238
+ resolve(results);
239
+ }
214
240
  };
215
241
  });
216
242
  };
217
-
218
243
  // src/functions/patchEntity.ts
244
+ import { deepPatch, NotFoundError } from "roc-db";
219
245
  var patchEntity = async (txn, ref, { data = {}, children = {}, parents = {}, ancestors = {} }) => {
220
246
  const existingDocument = await readEntity(txn, ref);
221
247
  if (!existingDocument)
@@ -315,6 +341,7 @@ var updateEntity = async (txn, ref, { data = {}, children = {}, parents = {}, an
315
341
  var createIndexedDBAdapter = ({
316
342
  operations,
317
343
  entities,
344
+ session,
318
345
  dbName = "roc-db"
319
346
  }) => {
320
347
  return createAdapter({
@@ -322,6 +349,7 @@ var createIndexedDBAdapter = ({
322
349
  operations,
323
350
  entities,
324
351
  functions: exports_functions,
352
+ session,
325
353
  snowflake: new Snowflake(1, 1),
326
354
  async: true
327
355
  }, {
@@ -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;
@@ -0,0 +1,2 @@
1
+ import type { Ref } from "roc-db";
2
+ export declare const batchReadEntities: (txn: any, refs: Ref[]) => Promise<any[]>;
@@ -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>;
@@ -1,9 +1,11 @@
1
+ export { batchReadEntities } from "./batchReadEntities";
1
2
  export { begin } from "./begin";
2
3
  export { createEntity } from "./createEntity";
3
4
  export { deleteEntity } from "./deleteEntity";
4
5
  export { end } from "./end";
5
6
  export { getChangeSetMutations } from "./getChangeSetMutations";
6
7
  export { findDebounceMutation } from "./findDebounceMutation";
8
+ export { pageMutations } from "./pageMutations";
7
9
  export { patchEntity } from "./patchEntity";
8
10
  export { readEntity } from "./readEntity";
9
11
  export { readMutation } from "./readMutation";
@@ -0,0 +1,2 @@
1
+ import type { IndexedDBReadTransaction } from "../types/IndexedDBReadTransaction";
2
+ export declare const pageMutations: (txn: IndexedDBReadTransaction, args: any) => Promise<unknown>;
package/package.json CHANGED
@@ -1,29 +1,21 @@
1
1
  {
2
2
  "name": "@roc-db/indexed-db",
3
- "version": "0.2.0-pre.2",
3
+ "version": "0.2.0-pre.21",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": "./src/index.ts"
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.2",
26
- "zod": "3.24.2"
17
+ "roc-db": "0.2.0-pre.21",
18
+ "zod": "^3.0.0"
27
19
  },
28
20
  "keywords": [],
29
21
  "author": "Eigil Sagafos",