@roc-db/indexed-db 0.2.0-pre.20 → 0.2.0-pre.23
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
|
@@ -26,9 +26,37 @@ __export(exports_functions, {
|
|
|
26
26
|
end: () => end,
|
|
27
27
|
deleteEntity: () => deleteEntity,
|
|
28
28
|
createEntity: () => createEntity,
|
|
29
|
-
begin: () => begin
|
|
29
|
+
begin: () => begin,
|
|
30
|
+
batchReadEntities: () => batchReadEntities
|
|
30
31
|
});
|
|
31
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
|
+
};
|
|
32
60
|
// src/functions/begin.ts
|
|
33
61
|
var begin = async (request, engineOpts, callback) => {
|
|
34
62
|
return new Promise((resolve, reject) => {
|
|
@@ -100,7 +128,7 @@ var createEntity = (txn, ref, { data = {}, children = {}, ancestors = {}, parent
|
|
|
100
128
|
}
|
|
101
129
|
};
|
|
102
130
|
// src/functions/deleteEntity.ts
|
|
103
|
-
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";
|
|
104
132
|
var deleteIndexed = (store, ref) => {
|
|
105
133
|
const request = store.delete(ref);
|
|
106
134
|
return new Promise((resolve, reject) => {
|
|
@@ -115,7 +143,7 @@ var deleteIndexed = (store, ref) => {
|
|
|
115
143
|
};
|
|
116
144
|
var deleteEntity = async (txn, ref, cascade = false) => {
|
|
117
145
|
if (txn.request.changeSetRef) {
|
|
118
|
-
txn.engineOpts.changeSet.entities.set(ref,
|
|
146
|
+
txn.engineOpts.changeSet.entities.set(ref, DELETED_IN_CHANGE_SET_SYMBOL2);
|
|
119
147
|
if (cascade) {
|
|
120
148
|
throw new Error("TGOD");
|
|
121
149
|
}
|
|
@@ -214,31 +242,6 @@ var pageMutations = async (txn, args) => {
|
|
|
214
242
|
};
|
|
215
243
|
// src/functions/patchEntity.ts
|
|
216
244
|
import { deepPatch, NotFoundError } from "roc-db";
|
|
217
|
-
|
|
218
|
-
// src/functions/readEntity.ts
|
|
219
|
-
import { DELETED_IN_CHANGE_SET_SYMBOL as DELETED_IN_CHANGE_SET_SYMBOL2 } from "roc-db";
|
|
220
|
-
var readEntity = (txn, ref) => {
|
|
221
|
-
if (txn.request.changeSetRef) {
|
|
222
|
-
const doc = txn.engineOpts.changeSet.entities.get(ref);
|
|
223
|
-
if (doc === DELETED_IN_CHANGE_SET_SYMBOL2)
|
|
224
|
-
return;
|
|
225
|
-
if (doc)
|
|
226
|
-
return doc;
|
|
227
|
-
}
|
|
228
|
-
const objectStore = txn.engineOpts.txn.objectStore("entities");
|
|
229
|
-
const request = objectStore.get(ref);
|
|
230
|
-
return new Promise((resolve, reject) => {
|
|
231
|
-
request.onsuccess = (event) => {
|
|
232
|
-
const document = event.target.result;
|
|
233
|
-
resolve(document);
|
|
234
|
-
};
|
|
235
|
-
request.onerror = (event) => {
|
|
236
|
-
reject(event.target.error);
|
|
237
|
-
};
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// src/functions/patchEntity.ts
|
|
242
245
|
var patchEntity = async (txn, ref, { data = {}, children = {}, parents = {}, ancestors = {} }) => {
|
|
243
246
|
const existingDocument = await readEntity(txn, ref);
|
|
244
247
|
if (!existingDocument)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roc-db/indexed-db",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"roc-db": "0.2.0-pre.
|
|
17
|
+
"roc-db": "0.2.0-pre.23",
|
|
18
18
|
"zod": "^3.0.0"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [],
|