@signaldb/core 2.0.0-beta.18 → 2.0.0-beta.19
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/.vite/manifest.json +39 -17
- package/dist/index.cjs.js +9 -9
- package/dist/index.mjs +9 -9
- package/dist/index17.cjs.js +7 -2
- package/dist/index17.mjs +7 -2
- package/dist/index27.cjs.js +36 -337
- package/dist/index27.mjs +36 -337
- package/dist/index28.cjs.js +318 -573
- package/dist/index28.mjs +318 -573
- package/dist/index29.cjs.js +599 -8
- package/dist/index29.mjs +599 -8
- package/dist/index30.cjs.js +6 -6
- package/dist/index30.mjs +6 -6
- package/dist/index31.cjs.js +7 -86
- package/dist/index31.mjs +7 -85
- package/dist/index32.cjs.js +76 -465
- package/dist/index32.mjs +75 -465
- package/dist/index33.cjs.js +45 -64
- package/dist/index33.mjs +45 -64
- package/dist/index34.cjs.js +403 -530
- package/dist/index34.mjs +405 -532
- package/dist/index35.cjs.js +68 -17
- package/dist/index35.mjs +68 -17
- package/dist/index36.cjs.js +535 -344
- package/dist/index36.mjs +537 -346
- package/dist/index37.cjs.js +14 -532
- package/dist/index37.mjs +14 -532
- package/dist/index38.cjs.js +363 -0
- package/dist/index38.mjs +363 -0
- package/dist/index39.cjs.js +513 -0
- package/dist/index39.mjs +513 -0
- package/dist/types/StorageAdapter.d.ts +9 -1
- package/dist/utils/idIndexQuery.d.ts +20 -0
- package/dist/utils/storageIndexQuery.d.ts +20 -0
- package/package.json +1 -1
package/dist/.vite/manifest.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"src/AsyncDataAdapter.ts": {
|
|
3
|
-
"file": "
|
|
3
|
+
"file": "index34.cjs.js",
|
|
4
4
|
"name": "AsyncDataAdapter",
|
|
5
5
|
"src": "src/AsyncDataAdapter.ts",
|
|
6
6
|
"isDynamicEntry": true,
|
|
7
7
|
"imports": [
|
|
8
8
|
"src/getIndexInfo.ts",
|
|
9
9
|
"src/utils/deepClone.ts",
|
|
10
|
-
"src/utils/
|
|
10
|
+
"src/utils/idIndexQuery.ts",
|
|
11
11
|
"src/utils/incrementalQueryUpdate.ts",
|
|
12
12
|
"src/utils/isEqual.ts",
|
|
13
13
|
"src/utils/match.ts",
|
|
@@ -15,24 +15,26 @@
|
|
|
15
15
|
"src/utils/projectItems.ts",
|
|
16
16
|
"src/utils/queryDelta.ts",
|
|
17
17
|
"src/utils/queryId.ts",
|
|
18
|
-
"src/utils/sortItems.ts"
|
|
18
|
+
"src/utils/sortItems.ts",
|
|
19
|
+
"src/utils/storageIndexQuery.ts"
|
|
19
20
|
]
|
|
20
21
|
},
|
|
21
22
|
"src/AutoFetchDataAdapter.ts": {
|
|
22
|
-
"file": "
|
|
23
|
+
"file": "index39.cjs.js",
|
|
23
24
|
"name": "AutoFetchDataAdapter",
|
|
24
25
|
"src": "src/AutoFetchDataAdapter.ts",
|
|
25
26
|
"isDynamicEntry": true,
|
|
26
27
|
"imports": [
|
|
27
28
|
"src/getIndexInfo.ts",
|
|
28
29
|
"src/utils/deepClone.ts",
|
|
29
|
-
"src/utils/
|
|
30
|
+
"src/utils/idIndexQuery.ts",
|
|
30
31
|
"src/utils/isEqual.ts",
|
|
31
32
|
"src/utils/match.ts",
|
|
32
33
|
"src/utils/modify.ts",
|
|
33
34
|
"src/utils/project.ts",
|
|
34
35
|
"src/utils/queryId.ts",
|
|
35
|
-
"src/utils/sortItems.ts"
|
|
36
|
+
"src/utils/sortItems.ts",
|
|
37
|
+
"src/utils/storageIndexQuery.ts"
|
|
36
38
|
]
|
|
37
39
|
},
|
|
38
40
|
"src/Collection/Cursor.ts": {
|
|
@@ -56,7 +58,7 @@
|
|
|
56
58
|
]
|
|
57
59
|
},
|
|
58
60
|
"src/Collection/index.ts": {
|
|
59
|
-
"file": "
|
|
61
|
+
"file": "index29.cjs.js",
|
|
60
62
|
"name": "Collection/index",
|
|
61
63
|
"src": "src/Collection/index.ts",
|
|
62
64
|
"isDynamicEntry": true,
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
]
|
|
74
76
|
},
|
|
75
77
|
"src/DefaultDataAdapter.ts": {
|
|
76
|
-
"file": "
|
|
78
|
+
"file": "index28.cjs.js",
|
|
77
79
|
"name": "DefaultDataAdapter",
|
|
78
80
|
"src": "src/DefaultDataAdapter.ts",
|
|
79
81
|
"isDynamicEntry": true,
|
|
@@ -82,6 +84,7 @@
|
|
|
82
84
|
"src/getIndexInfo.ts",
|
|
83
85
|
"src/utils/EventEmitter.ts",
|
|
84
86
|
"src/utils/deepClone.ts",
|
|
87
|
+
"src/utils/idIndexQuery.ts",
|
|
85
88
|
"src/utils/incrementalQueryUpdate.ts",
|
|
86
89
|
"src/utils/isEqual.ts",
|
|
87
90
|
"src/utils/match.ts",
|
|
@@ -94,7 +97,7 @@
|
|
|
94
97
|
]
|
|
95
98
|
},
|
|
96
99
|
"src/WorkerDataAdapter.ts": {
|
|
97
|
-
"file": "
|
|
100
|
+
"file": "index36.cjs.js",
|
|
98
101
|
"name": "WorkerDataAdapter",
|
|
99
102
|
"src": "src/WorkerDataAdapter.ts",
|
|
100
103
|
"isDynamicEntry": true,
|
|
@@ -110,7 +113,7 @@
|
|
|
110
113
|
]
|
|
111
114
|
},
|
|
112
115
|
"src/WorkerDataAdapterHost.ts": {
|
|
113
|
-
"file": "
|
|
116
|
+
"file": "index38.cjs.js",
|
|
114
117
|
"name": "WorkerDataAdapterHost",
|
|
115
118
|
"src": "src/WorkerDataAdapterHost.ts",
|
|
116
119
|
"isDynamicEntry": true,
|
|
@@ -118,7 +121,7 @@
|
|
|
118
121
|
"src/getIndexInfo.ts",
|
|
119
122
|
"src/utils/compact.ts",
|
|
120
123
|
"src/utils/deepClone.ts",
|
|
121
|
-
"src/utils/
|
|
124
|
+
"src/utils/idIndexQuery.ts",
|
|
122
125
|
"src/utils/incrementalQueryUpdate.ts",
|
|
123
126
|
"src/utils/isEqual.ts",
|
|
124
127
|
"src/utils/match.ts",
|
|
@@ -126,7 +129,8 @@
|
|
|
126
129
|
"src/utils/projectItems.ts",
|
|
127
130
|
"src/utils/queryDelta.ts",
|
|
128
131
|
"src/utils/queryId.ts",
|
|
129
|
-
"src/utils/sortItems.ts"
|
|
132
|
+
"src/utils/sortItems.ts",
|
|
133
|
+
"src/utils/storageIndexQuery.ts"
|
|
130
134
|
]
|
|
131
135
|
},
|
|
132
136
|
"src/createIndex.ts": {
|
|
@@ -148,13 +152,13 @@
|
|
|
148
152
|
"isDynamicEntry": true
|
|
149
153
|
},
|
|
150
154
|
"src/createReactivityAdapter.ts": {
|
|
151
|
-
"file": "
|
|
155
|
+
"file": "index31.cjs.js",
|
|
152
156
|
"name": "createReactivityAdapter",
|
|
153
157
|
"src": "src/createReactivityAdapter.ts",
|
|
154
158
|
"isDynamicEntry": true
|
|
155
159
|
},
|
|
156
160
|
"src/createStorageAdapter.ts": {
|
|
157
|
-
"file": "
|
|
161
|
+
"file": "index30.cjs.js",
|
|
158
162
|
"name": "createStorageAdapter",
|
|
159
163
|
"src": "src/createStorageAdapter.ts",
|
|
160
164
|
"isDynamicEntry": true
|
|
@@ -199,13 +203,13 @@
|
|
|
199
203
|
"isDynamicEntry": true
|
|
200
204
|
},
|
|
201
205
|
"src/utils/batchOnNextTick.ts": {
|
|
202
|
-
"file": "
|
|
206
|
+
"file": "index35.cjs.js",
|
|
203
207
|
"name": "utils/batchOnNextTick",
|
|
204
208
|
"src": "src/utils/batchOnNextTick.ts",
|
|
205
209
|
"isDynamicEntry": true
|
|
206
210
|
},
|
|
207
211
|
"src/utils/compact.ts": {
|
|
208
|
-
"file": "
|
|
212
|
+
"file": "index37.cjs.js",
|
|
209
213
|
"name": "utils/compact",
|
|
210
214
|
"src": "src/utils/compact.ts",
|
|
211
215
|
"isDynamicEntry": true
|
|
@@ -238,6 +242,15 @@
|
|
|
238
242
|
"src/utils/serializeValue.ts"
|
|
239
243
|
]
|
|
240
244
|
},
|
|
245
|
+
"src/utils/idIndexQuery.ts": {
|
|
246
|
+
"file": "index27.cjs.js",
|
|
247
|
+
"name": "utils/idIndexQuery",
|
|
248
|
+
"src": "src/utils/idIndexQuery.ts",
|
|
249
|
+
"isDynamicEntry": true,
|
|
250
|
+
"imports": [
|
|
251
|
+
"src/utils/isFieldExpression.ts"
|
|
252
|
+
]
|
|
253
|
+
},
|
|
241
254
|
"src/utils/incrementalQueryUpdate.ts": {
|
|
242
255
|
"file": "index25.cjs.js",
|
|
243
256
|
"name": "utils/incrementalQueryUpdate",
|
|
@@ -323,7 +336,7 @@
|
|
|
323
336
|
"isDynamicEntry": true
|
|
324
337
|
},
|
|
325
338
|
"src/utils/reactiveOrAsync.ts": {
|
|
326
|
-
"file": "
|
|
339
|
+
"file": "index32.cjs.js",
|
|
327
340
|
"name": "utils/reactiveOrAsync",
|
|
328
341
|
"src": "src/utils/reactiveOrAsync.ts",
|
|
329
342
|
"isDynamicEntry": true
|
|
@@ -349,6 +362,15 @@
|
|
|
349
362
|
"src/utils/get.ts"
|
|
350
363
|
]
|
|
351
364
|
},
|
|
365
|
+
"src/utils/storageIndexQuery.ts": {
|
|
366
|
+
"file": "index33.cjs.js",
|
|
367
|
+
"name": "utils/storageIndexQuery",
|
|
368
|
+
"src": "src/utils/storageIndexQuery.ts",
|
|
369
|
+
"isDynamicEntry": true,
|
|
370
|
+
"imports": [
|
|
371
|
+
"src/utils/getMatchingKeys.ts"
|
|
372
|
+
]
|
|
373
|
+
},
|
|
352
374
|
"src/utils/uniqueBy.ts": {
|
|
353
375
|
"file": "index3.cjs.js",
|
|
354
376
|
"name": "utils/uniqueBy",
|
package/dist/index.cjs.js
CHANGED
|
@@ -6,15 +6,15 @@ const require_randomId = require("./index9.cjs.js");
|
|
|
6
6
|
const require_get = require("./index11.cjs.js");
|
|
7
7
|
const require_serializeValue = require("./index13.cjs.js");
|
|
8
8
|
const require_modify = require("./index20.cjs.js");
|
|
9
|
-
const require_DefaultDataAdapter = require("./
|
|
10
|
-
const require_index = require("./
|
|
11
|
-
const require_createStorageAdapter = require("./
|
|
12
|
-
const require_createReactivityAdapter = require("./
|
|
13
|
-
const require_reactiveOrAsync = require("./
|
|
14
|
-
const require_AsyncDataAdapter = require("./
|
|
15
|
-
const require_WorkerDataAdapter = require("./
|
|
16
|
-
const require_WorkerDataAdapterHost = require("./
|
|
17
|
-
const require_AutoFetchDataAdapter = require("./
|
|
9
|
+
const require_DefaultDataAdapter = require("./index28.cjs.js");
|
|
10
|
+
const require_index = require("./index29.cjs.js");
|
|
11
|
+
const require_createStorageAdapter = require("./index30.cjs.js");
|
|
12
|
+
const require_createReactivityAdapter = require("./index31.cjs.js");
|
|
13
|
+
const require_reactiveOrAsync = require("./index32.cjs.js");
|
|
14
|
+
const require_AsyncDataAdapter = require("./index34.cjs.js");
|
|
15
|
+
const require_WorkerDataAdapter = require("./index36.cjs.js");
|
|
16
|
+
const require_WorkerDataAdapterHost = require("./index38.cjs.js");
|
|
17
|
+
const require_AutoFetchDataAdapter = require("./index39.cjs.js");
|
|
18
18
|
exports.AsyncDataAdapter = require_AsyncDataAdapter.default;
|
|
19
19
|
exports.AutoFetchDataAdapter = require_AutoFetchDataAdapter.default;
|
|
20
20
|
exports.Collection = require_index.default;
|
package/dist/index.mjs
CHANGED
|
@@ -5,13 +5,13 @@ import randomId from "./index9.mjs";
|
|
|
5
5
|
import get from "./index11.mjs";
|
|
6
6
|
import serializeValue from "./index13.mjs";
|
|
7
7
|
import modify from "./index20.mjs";
|
|
8
|
-
import DefaultDataAdapter from "./
|
|
9
|
-
import Collection from "./
|
|
10
|
-
import createStorageAdapter from "./
|
|
11
|
-
import createReactivityAdapter from "./
|
|
12
|
-
import reactiveOrAsync, { unwrap } from "./
|
|
13
|
-
import AsyncDataAdapter from "./
|
|
14
|
-
import WorkerDataAdapter from "./
|
|
15
|
-
import WorkerDataAdapterHost from "./
|
|
16
|
-
import AutoFetchDataAdapter from "./
|
|
8
|
+
import DefaultDataAdapter from "./index28.mjs";
|
|
9
|
+
import Collection from "./index29.mjs";
|
|
10
|
+
import createStorageAdapter from "./index30.mjs";
|
|
11
|
+
import createReactivityAdapter from "./index31.mjs";
|
|
12
|
+
import reactiveOrAsync, { unwrap } from "./index32.mjs";
|
|
13
|
+
import AsyncDataAdapter from "./index34.mjs";
|
|
14
|
+
import WorkerDataAdapter from "./index36.mjs";
|
|
15
|
+
import WorkerDataAdapterHost from "./index38.mjs";
|
|
16
|
+
import AutoFetchDataAdapter from "./index39.mjs";
|
|
17
17
|
export { AsyncDataAdapter, AutoFetchDataAdapter, Collection, Cursor, DefaultDataAdapter, EventEmitter, WorkerDataAdapter, WorkerDataAdapterHost, createReactivityAdapter, createStorageAdapter, get, isEqual, modify, randomId, reactiveOrAsync, serializeValue, unwrap };
|
package/dist/index17.cjs.js
CHANGED
|
@@ -105,11 +105,16 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
105
105
|
let hasNonIndexField = false;
|
|
106
106
|
const matchedBefore = matched;
|
|
107
107
|
const idsBefore = ids;
|
|
108
|
+
let orIds = [];
|
|
109
|
+
let orMatched = false;
|
|
108
110
|
const process$or = ($orNew) => {
|
|
109
111
|
if (hasNonIndexField || $orNew && $orNew.length > 0) {
|
|
110
112
|
newSelector.$or = $or;
|
|
111
113
|
matched = matchedBefore;
|
|
112
114
|
ids = idsBefore;
|
|
115
|
+
} else if (orMatched) {
|
|
116
|
+
ids = matchedBefore ? require_intersection.default(idsBefore, orIds) : orIds;
|
|
117
|
+
matched = true;
|
|
113
118
|
}
|
|
114
119
|
return {
|
|
115
120
|
matched,
|
|
@@ -119,8 +124,8 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
119
124
|
};
|
|
120
125
|
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
121
126
|
if (match) {
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
orIds = [...new Set([...orIds, ...selIds])];
|
|
128
|
+
orMatched = true;
|
|
124
129
|
} else hasNonIndexField = true;
|
|
125
130
|
}) : void 0;
|
|
126
131
|
if ($orNewOrPromise instanceof Promise) return $orNewOrPromise.then(($orNew) => process$or($orNew));
|
package/dist/index17.mjs
CHANGED
|
@@ -105,11 +105,16 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
105
105
|
let hasNonIndexField = false;
|
|
106
106
|
const matchedBefore = matched;
|
|
107
107
|
const idsBefore = ids;
|
|
108
|
+
let orIds = [];
|
|
109
|
+
let orMatched = false;
|
|
108
110
|
const process$or = ($orNew) => {
|
|
109
111
|
if (hasNonIndexField || $orNew && $orNew.length > 0) {
|
|
110
112
|
newSelector.$or = $or;
|
|
111
113
|
matched = matchedBefore;
|
|
112
114
|
ids = idsBefore;
|
|
115
|
+
} else if (orMatched) {
|
|
116
|
+
ids = matchedBefore ? intersection(idsBefore, orIds) : orIds;
|
|
117
|
+
matched = true;
|
|
113
118
|
}
|
|
114
119
|
return {
|
|
115
120
|
matched,
|
|
@@ -119,8 +124,8 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
119
124
|
};
|
|
120
125
|
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
121
126
|
if (match) {
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
orIds = [...new Set([...orIds, ...selIds])];
|
|
128
|
+
orMatched = true;
|
|
124
129
|
} else hasNonIndexField = true;
|
|
125
130
|
}) : void 0;
|
|
126
131
|
if ($orNewOrPromise instanceof Promise) return $orNewOrPromise.then(($orNew) => process$or($orNew));
|
package/dist/index27.cjs.js
CHANGED
|
@@ -1,343 +1,42 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
const require_EventEmitter = require("./index7.cjs.js");
|
|
4
|
-
const require_serializeValue = require("./index13.cjs.js");
|
|
5
|
-
const require_createIndex = require("./index15.cjs.js");
|
|
6
|
-
const require_getIndexInfo = require("./index17.cjs.js");
|
|
7
|
-
const require_deepClone = require("./index18.cjs.js");
|
|
8
|
-
const require_match = require("./index19.cjs.js");
|
|
9
|
-
const require_modify = require("./index20.cjs.js");
|
|
10
|
-
const require_projectItems = require("./index23.cjs.js");
|
|
11
|
-
const require_sortItems = require("./index24.cjs.js");
|
|
12
|
-
const require_incrementalQueryUpdate = require("./index25.cjs.js");
|
|
13
|
-
const require_queryId = require("./index26.cjs.js");
|
|
14
|
-
//#region src/DefaultDataAdapter.ts
|
|
1
|
+
const require_isFieldExpression = require("./index12.cjs.js");
|
|
2
|
+
//#region src/utils/idIndexQuery.ts
|
|
15
3
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
4
|
+
* Resolves a selector on `id` into the ids it names, without consulting an index.
|
|
5
|
+
*
|
|
6
|
+
* `id` is the one field every storage adapter can look up directly — that is what
|
|
7
|
+
* `readIds` is — so a query on it never needs an index to be declared and never
|
|
8
|
+
* needs the whole collection to be read. This behaves like an index provider that
|
|
9
|
+
* happens to need no stored index, because the ids are already in the selector.
|
|
10
|
+
*
|
|
11
|
+
* Only inclusive forms can be answered this way. `$ne`/`$nin` describe everything
|
|
12
|
+
* except* something, which cannot be enumerated without knowing every id, so they
|
|
13
|
+
* report no match and take the ordinary path.
|
|
14
|
+
* @template T - The type of the items in the collection.
|
|
15
|
+
* @template I - The type of the unique identifier for the items.
|
|
16
|
+
* @param selector - The flat selector to resolve.
|
|
17
|
+
* @returns An index result naming the matched ids, or `{ matched: false }`.
|
|
20
18
|
*/
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
indices = /* @__PURE__ */ new Map();
|
|
30
|
-
activeQueries = /* @__PURE__ */ new Map();
|
|
31
|
-
queryEmitters = /* @__PURE__ */ new Map();
|
|
32
|
-
queuedQueryUpdates = /* @__PURE__ */ new Map();
|
|
33
|
-
cachedQueryResults = /* @__PURE__ */ new Map();
|
|
34
|
-
constructor(options) {
|
|
35
|
-
this.options = options || {};
|
|
36
|
-
}
|
|
37
|
-
ensureStorageAdapter(name) {
|
|
38
|
-
if (this.storageAdapters.get(name)) return;
|
|
39
|
-
if (!this.options.storage) return;
|
|
40
|
-
const adapter = this.options.storage(name);
|
|
41
|
-
if (!adapter) return;
|
|
42
|
-
this.storageAdapters.set(name, adapter);
|
|
43
|
-
}
|
|
44
|
-
rebuildIndices(collection) {
|
|
45
|
-
const items = this.items.get(collection.name);
|
|
46
|
-
if (!items) throw new Error(`Items not found for collection ${collection.name}`);
|
|
47
|
-
const indices = this.indices.get(collection.name);
|
|
48
|
-
if (!indices) throw new Error(`Indices not found for collection ${collection.name}`);
|
|
49
|
-
indices.forEach((index) => index.rebuild([...items.values()]));
|
|
50
|
-
}
|
|
51
|
-
async setupStorageAdapter(collection) {
|
|
52
|
-
const storageAdapter = this.storageAdapters.get(collection.name);
|
|
53
|
-
if (!storageAdapter) return;
|
|
54
|
-
return storageAdapter.setup().then(async () => {
|
|
55
|
-
await this.fetchItemsFromStorage(collection);
|
|
56
|
-
}).catch((error) => {
|
|
57
|
-
if (!this.options.onError) {
|
|
58
|
-
console.error(`Error during data persistence operation in collection ${collection.name}`, error);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.options.onError(collection.name, error instanceof Error ? error : new Error(error));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
getIndexInfo(collection, selector) {
|
|
65
|
-
if (selector != null && Object.keys(selector).length === 1 && "id" in selector && typeof selector.id !== "object") return {
|
|
19
|
+
function idIndexQuery(selector) {
|
|
20
|
+
if (selector == null || !Object.hasOwnProperty.call(selector, "id")) return { matched: false };
|
|
21
|
+
const fieldSelector = selector.id;
|
|
22
|
+
if (fieldSelector == null || fieldSelector instanceof RegExp) return { matched: false };
|
|
23
|
+
if (require_isFieldExpression.default(fieldSelector)) {
|
|
24
|
+
const values = fieldSelector.$in;
|
|
25
|
+
if (!Array.isArray(values) || values.length <= 0) return { matched: false };
|
|
26
|
+
return {
|
|
66
27
|
matched: true,
|
|
67
|
-
ids:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (selector == null) return {
|
|
71
|
-
matched: false,
|
|
72
|
-
ids: [],
|
|
73
|
-
optimizedSelector: {}
|
|
74
|
-
};
|
|
75
|
-
return require_getIndexInfo.default((this.indices.get(collection.name) ?? []).map((i) => i.query.bind(i)), selector);
|
|
76
|
-
}
|
|
77
|
-
applyIndexDeltas(collection, changes) {
|
|
78
|
-
const indices = this.indices.get(collection.name) ?? [];
|
|
79
|
-
for (const index of indices) {
|
|
80
|
-
if (changes.modified) index.update(changes.modified);
|
|
81
|
-
if (changes.added && changes.added.length > 0) index.insert(changes.added);
|
|
82
|
-
if (changes.removed && changes.removed.length > 0) index.remove(changes.removed);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
getItem(collection, selector) {
|
|
86
|
-
const memory = this.items.get(collection.name) ?? /* @__PURE__ */ new Map();
|
|
87
|
-
const indexInfo = this.getIndexInfo(collection, selector);
|
|
88
|
-
return (indexInfo.matched ? indexInfo.ids.map((id) => memory.get(require_serializeValue.default(id))).filter((i) => i != null) : [...memory.values()]).find((document) => require_match.default(document, selector));
|
|
89
|
-
}
|
|
90
|
-
queryItems(collection, selector) {
|
|
91
|
-
const indexInfo = this.getIndexInfo(collection, selector);
|
|
92
|
-
const matchItems = (item) => {
|
|
93
|
-
if (indexInfo.optimizedSelector == null) return true;
|
|
94
|
-
if (Object.keys(indexInfo.optimizedSelector).length <= 0) return true;
|
|
95
|
-
return require_match.default(item, indexInfo.optimizedSelector);
|
|
28
|
+
ids: values,
|
|
29
|
+
fields: ["id"],
|
|
30
|
+
keepSelector: false
|
|
96
31
|
};
|
|
97
|
-
const items = this.items.get(collection.name);
|
|
98
|
-
if (!indexInfo.matched) {
|
|
99
|
-
if (require_isEqual.default(selector, {})) return [...items.values()];
|
|
100
|
-
return [...items.values()].filter(matchItems);
|
|
101
|
-
}
|
|
102
|
-
const foundItems = indexInfo.ids.map((ids) => items.get(require_serializeValue.default(ids))).filter((i) => i != null);
|
|
103
|
-
if (require_isEqual.default(indexInfo.optimizedSelector, {})) return foundItems;
|
|
104
|
-
return foundItems.filter(matchItems);
|
|
105
32
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!this.queuedQueryUpdates.get(collection.name)) return;
|
|
115
|
-
const changes = this.queuedQueryUpdates.get(collection.name);
|
|
116
|
-
if (!changes || !hasPendingUpdates(changes)) return;
|
|
117
|
-
this.queuedQueryUpdates.set(collection.name, {
|
|
118
|
-
added: [],
|
|
119
|
-
modified: [],
|
|
120
|
-
removed: []
|
|
121
|
-
});
|
|
122
|
-
const changeset = {
|
|
123
|
-
upserts: [...changes.added, ...changes.modified],
|
|
124
|
-
deletes: changes.removed.map((item) => item.id)
|
|
125
|
-
};
|
|
126
|
-
const flatItems = [
|
|
127
|
-
...changes.added,
|
|
128
|
-
...changes.modified,
|
|
129
|
-
...changes.removed
|
|
130
|
-
];
|
|
131
|
-
const itemIds = new Set(flatItems.map((i) => i.id));
|
|
132
|
-
[...this.activeQueries.get(collection.name)?.values() ?? []].filter(({ selector, options }) => {
|
|
133
|
-
if ((this.cachedQueryResults.get(collection.name)?.get(require_queryId.default(selector, options))?.map((i) => i.id) ?? []).some((id) => itemIds.has(id))) return true;
|
|
134
|
-
return flatItems.some((item) => require_match.default(item, selector));
|
|
135
|
-
}).forEach(({ selector, options }) => {
|
|
136
|
-
this.executeAndCacheQuery(collection, selector, options, changeset);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
executeAndCacheQuery(collection, selector, options, changes) {
|
|
140
|
-
const cached = this.cachedQueryResults.get(collection.name)?.get(require_queryId.default(selector, options));
|
|
141
|
-
const result = (changes && cached ? require_incrementalQueryUpdate.default(cached, selector, options, changes) : null) ?? this.executeQuery(collection, selector, options);
|
|
142
|
-
const delta = cached ? require_queryDelta.diffQueryResults(cached, result) : void 0;
|
|
143
|
-
this.cachedQueryResults.set(collection.name, this.cachedQueryResults.get(collection.name) || /* @__PURE__ */ new Map());
|
|
144
|
-
this.cachedQueryResults.get(collection.name)?.set(require_queryId.default(selector, options), result);
|
|
145
|
-
const emitter = this.queryEmitters.get(collection.name);
|
|
146
|
-
if (!emitter) return;
|
|
147
|
-
if (delta && require_queryDelta.isEmptyQueryDelta(delta)) return;
|
|
148
|
-
emitter.emit("change", selector, options, "complete", delta);
|
|
149
|
-
}
|
|
150
|
-
updateQueries(collection, changes) {
|
|
151
|
-
this.queuedQueryUpdates.set(collection.name, this.queuedQueryUpdates.get(collection.name) || {
|
|
152
|
-
added: [],
|
|
153
|
-
modified: [],
|
|
154
|
-
removed: []
|
|
155
|
-
});
|
|
156
|
-
this.queuedQueryUpdates.get(collection.name)?.added.push(...changes.added);
|
|
157
|
-
this.queuedQueryUpdates.get(collection.name)?.modified.push(...changes.modified);
|
|
158
|
-
this.queuedQueryUpdates.get(collection.name)?.removed.push(...changes.removed);
|
|
159
|
-
this.flushQueuedQueryUpdates(collection);
|
|
160
|
-
}
|
|
161
|
-
createCollectionBackend(collection, indices) {
|
|
162
|
-
this.collections.add(collection);
|
|
163
|
-
this.ensureStorageAdapter(collection.name);
|
|
164
|
-
this.items.set(collection.name, this.items.get(collection.name) ?? /* @__PURE__ */ new Map());
|
|
165
|
-
this.queryEmitters.set(collection.name, this.queryEmitters.get(collection.name) ?? new require_EventEmitter.default());
|
|
166
|
-
this.queryEmitters.get(collection.name)?.setMaxListeners(Infinity);
|
|
167
|
-
this.activeQueries.set(collection.name, this.activeQueries.get(collection.name) || /* @__PURE__ */ new Map());
|
|
168
|
-
this.indices.set(collection.name, indices.map((field) => require_createIndex.default(field)));
|
|
169
|
-
this.rebuildIndices(collection);
|
|
170
|
-
const persistenceReadyPromise = this.setupStorageAdapter(collection);
|
|
171
|
-
const backend = {
|
|
172
|
-
insert: async (newItem) => {
|
|
173
|
-
const items = this.items.get(collection.name);
|
|
174
|
-
if (!items) throw new Error(`Items not found for collection ${collection.name}`);
|
|
175
|
-
if (items.has(require_serializeValue.default(newItem.id))) throw new Error(`Item with id '${newItem.id}' already exists`);
|
|
176
|
-
this.items.get(collection.name)?.set(require_serializeValue.default(newItem.id), newItem);
|
|
177
|
-
await this.storageAdapters.get(collection.name)?.insert([newItem]);
|
|
178
|
-
this.applyIndexDeltas(collection, { added: [newItem] });
|
|
179
|
-
this.updateQueries(collection, {
|
|
180
|
-
added: [],
|
|
181
|
-
modified: [newItem],
|
|
182
|
-
removed: []
|
|
183
|
-
});
|
|
184
|
-
return newItem;
|
|
185
|
-
},
|
|
186
|
-
updateOne: async (selector, modifier) => {
|
|
187
|
-
const { $setOnInsert, ...restModifier } = modifier;
|
|
188
|
-
const item = this.getItem(collection, selector);
|
|
189
|
-
if (item == null) return [];
|
|
190
|
-
const modifiedItem = require_modify.default(require_deepClone.default(item), restModifier);
|
|
191
|
-
if (item.id !== modifiedItem.id && this.getItem(collection, { id: modifiedItem.id }) != null) throw new Error(`Item with id '${modifiedItem.id}' already exists`);
|
|
192
|
-
this.items.get(collection.name)?.set(require_serializeValue.default(modifiedItem.id), modifiedItem);
|
|
193
|
-
await this.storageAdapters.get(collection.name)?.replace([modifiedItem]);
|
|
194
|
-
this.applyIndexDeltas(collection, { modified: [{
|
|
195
|
-
oldItem: item,
|
|
196
|
-
newItem: modifiedItem
|
|
197
|
-
}] });
|
|
198
|
-
this.updateQueries(collection, {
|
|
199
|
-
added: [],
|
|
200
|
-
modified: [modifiedItem],
|
|
201
|
-
removed: []
|
|
202
|
-
});
|
|
203
|
-
return [modifiedItem];
|
|
204
|
-
},
|
|
205
|
-
updateMany: async (selector, modifier) => {
|
|
206
|
-
const { $setOnInsert, ...restModifier } = modifier;
|
|
207
|
-
const items = this.executeQuery(collection, selector, {});
|
|
208
|
-
const changedItems = items.map((item) => {
|
|
209
|
-
const modifiedItem = require_modify.default(require_deepClone.default(item), restModifier);
|
|
210
|
-
if (item.id !== modifiedItem.id && this.getItem(collection, { id: modifiedItem.id }) != null) throw new Error(`Item with id '${modifiedItem.id}' already exists`);
|
|
211
|
-
return modifiedItem;
|
|
212
|
-
});
|
|
213
|
-
changedItems.forEach((item) => {
|
|
214
|
-
this.items.get(collection.name)?.set(require_serializeValue.default(item.id), item);
|
|
215
|
-
});
|
|
216
|
-
await this.storageAdapters.get(collection.name)?.replace(changedItems);
|
|
217
|
-
const pairs = items.map((oldItem, index) => ({
|
|
218
|
-
oldItem,
|
|
219
|
-
newItem: changedItems[index]
|
|
220
|
-
}));
|
|
221
|
-
this.applyIndexDeltas(collection, { modified: pairs });
|
|
222
|
-
this.updateQueries(collection, {
|
|
223
|
-
added: [],
|
|
224
|
-
modified: changedItems,
|
|
225
|
-
removed: []
|
|
226
|
-
});
|
|
227
|
-
return changedItems;
|
|
228
|
-
},
|
|
229
|
-
replaceOne: async (selector, replacement) => {
|
|
230
|
-
const item = this.getItem(collection, selector);
|
|
231
|
-
if (item == null) return [];
|
|
232
|
-
if (item.id !== replacement.id && replacement.id != null && this.getItem(collection, { id: replacement.id }) != null) throw new Error(`Item with id '${replacement.id}' already exists`);
|
|
233
|
-
const modifiedItem = {
|
|
234
|
-
id: item.id,
|
|
235
|
-
...replacement
|
|
236
|
-
};
|
|
237
|
-
this.items.get(collection.name)?.set(require_serializeValue.default(modifiedItem.id), modifiedItem);
|
|
238
|
-
await this.storageAdapters.get(collection.name)?.replace([modifiedItem]);
|
|
239
|
-
this.applyIndexDeltas(collection, { modified: [{
|
|
240
|
-
oldItem: item,
|
|
241
|
-
newItem: modifiedItem
|
|
242
|
-
}] });
|
|
243
|
-
this.updateQueries(collection, {
|
|
244
|
-
added: [],
|
|
245
|
-
modified: [modifiedItem],
|
|
246
|
-
removed: []
|
|
247
|
-
});
|
|
248
|
-
return [modifiedItem];
|
|
249
|
-
},
|
|
250
|
-
removeOne: async (selector) => {
|
|
251
|
-
const item = this.getItem(collection, selector);
|
|
252
|
-
if (item == null) return [];
|
|
253
|
-
this.items.get(collection.name)?.delete(require_serializeValue.default(item.id));
|
|
254
|
-
await this.storageAdapters.get(collection.name)?.remove([item]);
|
|
255
|
-
this.applyIndexDeltas(collection, { removed: [item] });
|
|
256
|
-
this.updateQueries(collection, {
|
|
257
|
-
added: [],
|
|
258
|
-
modified: [],
|
|
259
|
-
removed: [item]
|
|
260
|
-
});
|
|
261
|
-
return [item];
|
|
262
|
-
},
|
|
263
|
-
removeMany: async (selector) => {
|
|
264
|
-
const items = backend.getQueryResult(selector, {});
|
|
265
|
-
items.forEach((item) => {
|
|
266
|
-
this.items.get(collection.name)?.delete(require_serializeValue.default(item.id));
|
|
267
|
-
});
|
|
268
|
-
await this.storageAdapters.get(collection.name)?.remove(items);
|
|
269
|
-
this.applyIndexDeltas(collection, { removed: items });
|
|
270
|
-
this.updateQueries(collection, {
|
|
271
|
-
added: [],
|
|
272
|
-
modified: [],
|
|
273
|
-
removed: items
|
|
274
|
-
});
|
|
275
|
-
return items;
|
|
276
|
-
},
|
|
277
|
-
registerQuery: (selector, options) => {
|
|
278
|
-
this.activeQueries.set(collection.name, this.activeQueries.get(collection.name) || /* @__PURE__ */ new Map());
|
|
279
|
-
this.activeQueries.get(collection.name)?.set(require_queryId.default(selector, options), {
|
|
280
|
-
selector,
|
|
281
|
-
options
|
|
282
|
-
});
|
|
283
|
-
this.executeAndCacheQuery(collection, selector, options);
|
|
284
|
-
},
|
|
285
|
-
unregisterQuery: (selector, options) => {
|
|
286
|
-
if (!this.activeQueries.get(collection.name)) return;
|
|
287
|
-
this.activeQueries.get(collection.name)?.delete(require_queryId.default(selector, options));
|
|
288
|
-
},
|
|
289
|
-
getQueryState: () => "complete",
|
|
290
|
-
onQueryStateChange: (selector, options, callback) => {
|
|
291
|
-
const emitter = this.queryEmitters.get(collection.name);
|
|
292
|
-
if (!emitter) throw new Error(`Query emitter not found for collection ${collection.name}`);
|
|
293
|
-
const handler = (querySelector, queryOptions, state, delta) => {
|
|
294
|
-
if (require_queryId.default(querySelector, queryOptions) !== require_queryId.default(selector, options)) return;
|
|
295
|
-
require_queryDelta.callWithDelta(callback, state, delta);
|
|
296
|
-
};
|
|
297
|
-
emitter.on("change", handler);
|
|
298
|
-
return () => {
|
|
299
|
-
emitter.off("change", handler);
|
|
300
|
-
};
|
|
301
|
-
},
|
|
302
|
-
getQueryError: () => null,
|
|
303
|
-
getQueryResult: (selector, options) => {
|
|
304
|
-
if (this.activeQueries.get(collection.name)?.has(require_queryId.default(selector, options))) {
|
|
305
|
-
const results = this.cachedQueryResults.get(collection.name)?.get(require_queryId.default(selector, options));
|
|
306
|
-
if (!results) throw new Error("Cached query results are not defined!");
|
|
307
|
-
return results;
|
|
308
|
-
}
|
|
309
|
-
return this.executeQuery(collection, selector, options);
|
|
310
|
-
},
|
|
311
|
-
executeQuery: (selector, options) => Promise.resolve(this.executeQuery(collection, selector, options)),
|
|
312
|
-
dispose: async () => {
|
|
313
|
-
const adapter = this.storageAdapters.get(collection.name);
|
|
314
|
-
if (adapter?.teardown) await adapter.teardown();
|
|
315
|
-
this.storageAdapters.delete(collection.name);
|
|
316
|
-
this.items.delete(collection.name);
|
|
317
|
-
this.indices.delete(collection.name);
|
|
318
|
-
this.activeQueries.delete(collection.name);
|
|
319
|
-
this.queryEmitters.delete(collection.name);
|
|
320
|
-
this.queuedQueryUpdates.delete(collection.name);
|
|
321
|
-
this.cachedQueryResults.delete(collection.name);
|
|
322
|
-
},
|
|
323
|
-
isReady: () => persistenceReadyPromise
|
|
324
|
-
};
|
|
325
|
-
return backend;
|
|
326
|
-
}
|
|
327
|
-
async fetchItemsFromStorage(collection) {
|
|
328
|
-
if (!collection) {
|
|
329
|
-
await Promise.all([...this.collections].map((currentCollection) => this.fetchItemsFromStorage(currentCollection)));
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const storageAdapter = this.storageAdapters.get(collection.name);
|
|
333
|
-
if (!storageAdapter) return;
|
|
334
|
-
const items = await storageAdapter.readAll();
|
|
335
|
-
this.items.set(collection.name, items.reduce((map, item) => {
|
|
336
|
-
map.set(require_serializeValue.default(item.id), item);
|
|
337
|
-
return map;
|
|
338
|
-
}, /* @__PURE__ */ new Map()));
|
|
339
|
-
this.rebuildIndices(collection);
|
|
340
|
-
}
|
|
341
|
-
};
|
|
33
|
+
if (typeof fieldSelector === "object") return { matched: false };
|
|
34
|
+
return {
|
|
35
|
+
matched: true,
|
|
36
|
+
ids: [fieldSelector],
|
|
37
|
+
fields: ["id"],
|
|
38
|
+
keepSelector: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
342
41
|
//#endregion
|
|
343
|
-
exports.default =
|
|
42
|
+
exports.default = idIndexQuery;
|