@signaldb/core 2.0.0-beta.20 → 2.0.0-beta.22
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/README.md +3 -3
- package/dist/.vite/manifest.json +61 -59
- package/dist/AsyncDataAdapter.d.ts +15 -2
- package/dist/AutoFetchDataAdapter.d.ts +13 -2
- package/dist/Collection/Observer.d.ts +1 -1
- package/dist/Collection/index.d.ts +11 -12
- package/dist/DataAdapter.d.ts +19 -3
- package/dist/WorkerDataAdapterHost.d.ts +19 -6
- package/dist/index.cjs.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index12.cjs.js +1 -1
- package/dist/index12.mjs +1 -1
- package/dist/index15.cjs.js +6 -2
- package/dist/index15.mjs +6 -2
- package/dist/index17.cjs.js +4 -2
- package/dist/index17.mjs +4 -3
- package/dist/index18.cjs.js +1 -0
- package/dist/index18.mjs +1 -1
- package/dist/index28.cjs.js +15 -5
- package/dist/index28.mjs +15 -5
- package/dist/index29.cjs.js +30 -17
- package/dist/index29.mjs +30 -17
- package/dist/index33.cjs.js +17 -49
- package/dist/index33.mjs +17 -49
- package/dist/index34.cjs.js +45 -445
- package/dist/index34.mjs +45 -445
- package/dist/index35.cjs.js +132 -65
- package/dist/index35.mjs +132 -65
- package/dist/index36.cjs.js +385 -531
- package/dist/index36.mjs +386 -533
- package/dist/index37.cjs.js +68 -17
- package/dist/index37.mjs +68 -17
- package/dist/index38.cjs.js +536 -319
- package/dist/index38.mjs +538 -321
- package/dist/index39.cjs.js +301 -466
- package/dist/index39.mjs +301 -466
- package/dist/index40.cjs.js +484 -0
- package/dist/index40.mjs +484 -0
- package/dist/index5.cjs.js +3 -3
- package/dist/index5.mjs +3 -3
- package/dist/index6.cjs.js +1 -0
- package/dist/index6.mjs +1 -1
- package/dist/types/StorageAdapter.d.ts +80 -0
- package/dist/utils/executeStorageQuery.d.ts +28 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,15 +34,15 @@ SignalDB is a client-side database optimized for modern web applications. It pro
|
|
|
34
34
|
import { Collection } from '@signaldb/core'
|
|
35
35
|
|
|
36
36
|
const Posts = new Collection()
|
|
37
|
-
const postId = Posts.insert({ title: 'Foo', text: 'Lorem ipsum …' })
|
|
37
|
+
const postId = await Posts.insert({ title: 'Foo', text: 'Lorem ipsum …' })
|
|
38
38
|
|
|
39
|
-
Posts.updateOne({ id: postId }, { // updates the post
|
|
39
|
+
await Posts.updateOne({ id: postId }, { // updates the post
|
|
40
40
|
$set: {
|
|
41
41
|
title: 'New title',
|
|
42
42
|
}
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
-
Posts.removeOne({ id: postId }) // removes the post
|
|
45
|
+
await Posts.removeOne({ id: postId }) // removes the post
|
|
46
46
|
|
|
47
47
|
const cursor = collection.find({})
|
|
48
48
|
|
package/dist/.vite/manifest.json
CHANGED
|
@@ -1,40 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"src/AsyncDataAdapter.ts": {
|
|
3
|
-
"file": "
|
|
3
|
+
"file": "index36.cjs.js",
|
|
4
4
|
"name": "AsyncDataAdapter",
|
|
5
5
|
"src": "src/AsyncDataAdapter.ts",
|
|
6
6
|
"isDynamicEntry": true,
|
|
7
7
|
"imports": [
|
|
8
|
-
"src/
|
|
8
|
+
"src/utils/queryDelta.ts",
|
|
9
9
|
"src/utils/deepClone.ts",
|
|
10
|
-
"src/utils/idIndexQuery.ts",
|
|
11
|
-
"src/utils/incrementalQueryUpdate.ts",
|
|
12
|
-
"src/utils/isEqual.ts",
|
|
13
10
|
"src/utils/match.ts",
|
|
14
11
|
"src/utils/modify.ts",
|
|
15
|
-
"src/utils/
|
|
16
|
-
"src/utils/queryDelta.ts",
|
|
12
|
+
"src/utils/incrementalQueryUpdate.ts",
|
|
17
13
|
"src/utils/queryId.ts",
|
|
18
|
-
"src/utils/
|
|
19
|
-
"src/utils/storageIndexQuery.ts"
|
|
14
|
+
"src/utils/executeStorageQuery.ts"
|
|
20
15
|
]
|
|
21
16
|
},
|
|
22
17
|
"src/AutoFetchDataAdapter.ts": {
|
|
23
|
-
"file": "
|
|
18
|
+
"file": "index40.cjs.js",
|
|
24
19
|
"name": "AutoFetchDataAdapter",
|
|
25
20
|
"src": "src/AutoFetchDataAdapter.ts",
|
|
26
21
|
"isDynamicEntry": true,
|
|
27
22
|
"imports": [
|
|
28
|
-
"src/getIndexInfo.ts",
|
|
29
|
-
"src/utils/deepClone.ts",
|
|
30
|
-
"src/utils/idIndexQuery.ts",
|
|
31
23
|
"src/utils/isEqual.ts",
|
|
24
|
+
"src/utils/deepClone.ts",
|
|
32
25
|
"src/utils/match.ts",
|
|
33
26
|
"src/utils/modify.ts",
|
|
34
|
-
"src/utils/project.ts",
|
|
35
27
|
"src/utils/queryId.ts",
|
|
36
|
-
"src/utils/
|
|
37
|
-
"src/utils/storageIndexQuery.ts"
|
|
28
|
+
"src/utils/executeStorageQuery.ts"
|
|
38
29
|
]
|
|
39
30
|
},
|
|
40
31
|
"src/Collection/Cursor.ts": {
|
|
@@ -53,8 +44,8 @@
|
|
|
53
44
|
"isDynamicEntry": true,
|
|
54
45
|
"imports": [
|
|
55
46
|
"src/utils/isEqual.ts",
|
|
56
|
-
"src/utils/
|
|
57
|
-
"src/utils/
|
|
47
|
+
"src/utils/uniqueBy.ts",
|
|
48
|
+
"src/utils/queryDelta.ts"
|
|
58
49
|
]
|
|
59
50
|
},
|
|
60
51
|
"src/Collection/index.ts": {
|
|
@@ -64,14 +55,14 @@
|
|
|
64
55
|
"isDynamicEntry": true,
|
|
65
56
|
"imports": [
|
|
66
57
|
"src/Collection/Cursor.ts",
|
|
67
|
-
"src/DefaultDataAdapter.ts",
|
|
68
|
-
"src/createIndex.ts",
|
|
69
58
|
"src/utils/EventEmitter.ts",
|
|
70
59
|
"src/utils/createSignal.ts",
|
|
60
|
+
"src/utils/randomId.ts",
|
|
61
|
+
"src/createIndex.ts",
|
|
71
62
|
"src/utils/deepClone.ts",
|
|
72
63
|
"src/utils/modify.ts",
|
|
73
64
|
"src/utils/queryId.ts",
|
|
74
|
-
"src/
|
|
65
|
+
"src/DefaultDataAdapter.ts"
|
|
75
66
|
]
|
|
76
67
|
},
|
|
77
68
|
"src/DefaultDataAdapter.ts": {
|
|
@@ -80,57 +71,52 @@
|
|
|
80
71
|
"src": "src/DefaultDataAdapter.ts",
|
|
81
72
|
"isDynamicEntry": true,
|
|
82
73
|
"imports": [
|
|
74
|
+
"src/utils/isEqual.ts",
|
|
75
|
+
"src/utils/queryDelta.ts",
|
|
76
|
+
"src/utils/EventEmitter.ts",
|
|
77
|
+
"src/utils/serializeValue.ts",
|
|
83
78
|
"src/createIndex.ts",
|
|
84
79
|
"src/getIndexInfo.ts",
|
|
85
|
-
"src/utils/EventEmitter.ts",
|
|
86
80
|
"src/utils/deepClone.ts",
|
|
87
|
-
"src/utils/idIndexQuery.ts",
|
|
88
|
-
"src/utils/incrementalQueryUpdate.ts",
|
|
89
|
-
"src/utils/isEqual.ts",
|
|
90
81
|
"src/utils/match.ts",
|
|
91
82
|
"src/utils/modify.ts",
|
|
92
83
|
"src/utils/projectItems.ts",
|
|
93
|
-
"src/utils/
|
|
84
|
+
"src/utils/sortItems.ts",
|
|
85
|
+
"src/utils/incrementalQueryUpdate.ts",
|
|
94
86
|
"src/utils/queryId.ts",
|
|
95
|
-
"src/utils/
|
|
96
|
-
"src/utils/sortItems.ts"
|
|
87
|
+
"src/utils/idIndexQuery.ts"
|
|
97
88
|
]
|
|
98
89
|
},
|
|
99
90
|
"src/WorkerDataAdapter.ts": {
|
|
100
|
-
"file": "
|
|
91
|
+
"file": "index38.cjs.js",
|
|
101
92
|
"name": "WorkerDataAdapter",
|
|
102
93
|
"src": "src/WorkerDataAdapter.ts",
|
|
103
94
|
"isDynamicEntry": true,
|
|
104
95
|
"imports": [
|
|
105
|
-
"src/utils/
|
|
96
|
+
"src/utils/queryDelta.ts",
|
|
97
|
+
"src/utils/randomId.ts",
|
|
106
98
|
"src/utils/deepClone.ts",
|
|
107
|
-
"src/utils/incrementalQueryUpdate.ts",
|
|
108
99
|
"src/utils/match.ts",
|
|
109
100
|
"src/utils/modify.ts",
|
|
110
|
-
"src/utils/
|
|
101
|
+
"src/utils/incrementalQueryUpdate.ts",
|
|
111
102
|
"src/utils/queryId.ts",
|
|
112
|
-
"src/utils/
|
|
103
|
+
"src/utils/batchOnNextTick.ts"
|
|
113
104
|
]
|
|
114
105
|
},
|
|
115
106
|
"src/WorkerDataAdapterHost.ts": {
|
|
116
|
-
"file": "
|
|
107
|
+
"file": "index39.cjs.js",
|
|
117
108
|
"name": "WorkerDataAdapterHost",
|
|
118
109
|
"src": "src/WorkerDataAdapterHost.ts",
|
|
119
110
|
"isDynamicEntry": true,
|
|
120
111
|
"imports": [
|
|
121
|
-
"src/
|
|
122
|
-
"src/utils/compact.ts",
|
|
112
|
+
"src/utils/queryDelta.ts",
|
|
123
113
|
"src/utils/deepClone.ts",
|
|
124
|
-
"src/utils/idIndexQuery.ts",
|
|
125
|
-
"src/utils/incrementalQueryUpdate.ts",
|
|
126
|
-
"src/utils/isEqual.ts",
|
|
127
114
|
"src/utils/match.ts",
|
|
128
115
|
"src/utils/modify.ts",
|
|
129
|
-
"src/utils/
|
|
130
|
-
"src/utils/queryDelta.ts",
|
|
116
|
+
"src/utils/incrementalQueryUpdate.ts",
|
|
131
117
|
"src/utils/queryId.ts",
|
|
132
|
-
"src/utils/
|
|
133
|
-
"src/utils/
|
|
118
|
+
"src/utils/compact.ts",
|
|
119
|
+
"src/utils/executeStorageQuery.ts"
|
|
134
120
|
]
|
|
135
121
|
},
|
|
136
122
|
"src/createIndex.ts": {
|
|
@@ -141,8 +127,8 @@
|
|
|
141
127
|
"imports": [
|
|
142
128
|
"src/createIndexProvider.ts",
|
|
143
129
|
"src/utils/get.ts",
|
|
144
|
-
"src/utils/
|
|
145
|
-
"src/utils/
|
|
130
|
+
"src/utils/serializeValue.ts",
|
|
131
|
+
"src/utils/getMatchingKeys.ts"
|
|
146
132
|
]
|
|
147
133
|
},
|
|
148
134
|
"src/createIndexProvider.ts": {
|
|
@@ -178,22 +164,22 @@
|
|
|
178
164
|
"src": "src/index.ts",
|
|
179
165
|
"isEntry": true,
|
|
180
166
|
"imports": [
|
|
181
|
-
"src/
|
|
182
|
-
"src/AutoFetchDataAdapter.ts",
|
|
167
|
+
"src/utils/isEqual.ts",
|
|
183
168
|
"src/Collection/Cursor.ts",
|
|
184
|
-
"src/Collection/index.ts",
|
|
185
|
-
"src/DefaultDataAdapter.ts",
|
|
186
|
-
"src/WorkerDataAdapter.ts",
|
|
187
|
-
"src/WorkerDataAdapterHost.ts",
|
|
188
|
-
"src/createReactivityAdapter.ts",
|
|
189
|
-
"src/createStorageAdapter.ts",
|
|
190
169
|
"src/utils/EventEmitter.ts",
|
|
170
|
+
"src/utils/randomId.ts",
|
|
191
171
|
"src/utils/get.ts",
|
|
192
|
-
"src/utils/
|
|
172
|
+
"src/utils/serializeValue.ts",
|
|
193
173
|
"src/utils/modify.ts",
|
|
194
|
-
"src/
|
|
174
|
+
"src/DefaultDataAdapter.ts",
|
|
175
|
+
"src/Collection/index.ts",
|
|
176
|
+
"src/createStorageAdapter.ts",
|
|
177
|
+
"src/createReactivityAdapter.ts",
|
|
195
178
|
"src/utils/reactiveOrAsync.ts",
|
|
196
|
-
"src/
|
|
179
|
+
"src/AsyncDataAdapter.ts",
|
|
180
|
+
"src/WorkerDataAdapter.ts",
|
|
181
|
+
"src/WorkerDataAdapterHost.ts",
|
|
182
|
+
"src/AutoFetchDataAdapter.ts"
|
|
197
183
|
]
|
|
198
184
|
},
|
|
199
185
|
"src/utils/EventEmitter.ts": {
|
|
@@ -203,13 +189,13 @@
|
|
|
203
189
|
"isDynamicEntry": true
|
|
204
190
|
},
|
|
205
191
|
"src/utils/batchOnNextTick.ts": {
|
|
206
|
-
"file": "
|
|
192
|
+
"file": "index37.cjs.js",
|
|
207
193
|
"name": "utils/batchOnNextTick",
|
|
208
194
|
"src": "src/utils/batchOnNextTick.ts",
|
|
209
195
|
"isDynamicEntry": true
|
|
210
196
|
},
|
|
211
197
|
"src/utils/compact.ts": {
|
|
212
|
-
"file": "
|
|
198
|
+
"file": "index33.cjs.js",
|
|
213
199
|
"name": "utils/compact",
|
|
214
200
|
"src": "src/utils/compact.ts",
|
|
215
201
|
"isDynamicEntry": true
|
|
@@ -226,6 +212,22 @@
|
|
|
226
212
|
"src": "src/utils/deepClone.ts",
|
|
227
213
|
"isDynamicEntry": true
|
|
228
214
|
},
|
|
215
|
+
"src/utils/executeStorageQuery.ts": {
|
|
216
|
+
"file": "index35.cjs.js",
|
|
217
|
+
"name": "utils/executeStorageQuery",
|
|
218
|
+
"src": "src/utils/executeStorageQuery.ts",
|
|
219
|
+
"isDynamicEntry": true,
|
|
220
|
+
"imports": [
|
|
221
|
+
"src/utils/isEqual.ts",
|
|
222
|
+
"src/getIndexInfo.ts",
|
|
223
|
+
"src/utils/match.ts",
|
|
224
|
+
"src/utils/projectItems.ts",
|
|
225
|
+
"src/utils/sortItems.ts",
|
|
226
|
+
"src/utils/idIndexQuery.ts",
|
|
227
|
+
"src/utils/compact.ts",
|
|
228
|
+
"src/utils/storageIndexQuery.ts"
|
|
229
|
+
]
|
|
230
|
+
},
|
|
229
231
|
"src/utils/get.ts": {
|
|
230
232
|
"file": "index11.cjs.js",
|
|
231
233
|
"name": "utils/get",
|
|
@@ -363,7 +365,7 @@
|
|
|
363
365
|
]
|
|
364
366
|
},
|
|
365
367
|
"src/utils/storageIndexQuery.ts": {
|
|
366
|
-
"file": "
|
|
368
|
+
"file": "index34.cjs.js",
|
|
367
369
|
"name": "utils/storageIndexQuery",
|
|
368
370
|
"src": "src/utils/storageIndexQuery.ts",
|
|
369
371
|
"isDynamicEntry": true,
|
|
@@ -85,8 +85,21 @@ export default class AsyncDataAdapter implements DataAdapter {
|
|
|
85
85
|
private publishState;
|
|
86
86
|
private publishResult;
|
|
87
87
|
private queryItemIds;
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Reads one query's result from the storage adapter.
|
|
90
|
+
*
|
|
91
|
+
* The work lives in `executeStorageQuery` because this method used to exist
|
|
92
|
+
* three times over — here, in `AutoFetchDataAdapter` and in
|
|
93
|
+
* `WorkerDataAdapterHost` — as the same eight lines, which is how a storage
|
|
94
|
+
* adapter capability ends up honoured by one adapter and silently ignored by
|
|
95
|
+
* the others.
|
|
96
|
+
* @template T - The type of the items.
|
|
97
|
+
* @template I - The type of the item ids.
|
|
98
|
+
* @param collectionName - The collection to read from.
|
|
99
|
+
* @param selector - The query's selector.
|
|
100
|
+
* @param options - The query's sort, window and projection.
|
|
101
|
+
* @returns The query result.
|
|
102
|
+
*/
|
|
90
103
|
private executeQuery;
|
|
91
104
|
/**
|
|
92
105
|
* After mutations, bring every affected active query up to date.
|
|
@@ -79,8 +79,19 @@ export default class AutoFetchDataAdapter implements DataAdapter {
|
|
|
79
79
|
private publishState;
|
|
80
80
|
private publishResult;
|
|
81
81
|
private fulfillQuery;
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Reads one query's result from the local storage adapter.
|
|
84
|
+
*
|
|
85
|
+
* Shares `executeStorageQuery` with the other adapters — the projection this
|
|
86
|
+
* used to do by hand was `projectItems` spelled out, so nothing about the
|
|
87
|
+
* result changes.
|
|
88
|
+
* @template T - The type of the items.
|
|
89
|
+
* @template I - The type of the item ids.
|
|
90
|
+
* @param collectionName - The collection to read from.
|
|
91
|
+
* @param selector - The query's selector.
|
|
92
|
+
* @param options - The query's sort, window and projection.
|
|
93
|
+
* @returns The query result.
|
|
94
|
+
*/
|
|
84
95
|
private executeQuery;
|
|
85
96
|
private checkQueryUpdates;
|
|
86
97
|
private insert;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QueryDelta } from '../utils/queryDelta';
|
|
2
2
|
type AddedCallback<T> = (item: T) => void;
|
|
3
3
|
type AddedBeforeCallback<T> = (item: T, before: T) => void;
|
|
4
|
-
type ChangedCallback<T> = (item: T) => void;
|
|
4
|
+
type ChangedCallback<T> = (item: T, before: T) => void;
|
|
5
5
|
type ChangedFieldCallback<T> = <Field extends keyof T>(item: T, field: Field, oldValue: T[Field], newValue: T[Field]) => void;
|
|
6
6
|
type MovedBeforeCallback<T> = (item: T, before: T) => void;
|
|
7
7
|
type RemovedCallback<T> = (item: T) => void;
|
|
@@ -29,7 +29,7 @@ export interface CollectionOptions<T extends BaseItem<I>, I, E extends BaseItem
|
|
|
29
29
|
}
|
|
30
30
|
interface CollectionEvents<T extends BaseItem, E extends BaseItem = T, U = E> {
|
|
31
31
|
'added': (item: T) => void;
|
|
32
|
-
'changed': (item: T, modifier: Modifier<T
|
|
32
|
+
'changed': (item: T, modifier: Modifier<T>, previousItem?: T) => void;
|
|
33
33
|
'removed': (item: T) => void;
|
|
34
34
|
'observer.created': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
35
35
|
'observer.disposed': <O extends QueryOptions<T>>(selector?: Selector<T>, options?: O) => void;
|
|
@@ -154,8 +154,8 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E ext
|
|
|
154
154
|
* @param options.memory - The in-memory adapter for storing items.
|
|
155
155
|
* @param options.reactivity - The reactivity adapter for observing changes in the collection.
|
|
156
156
|
* @param options.transform - A transformation function to apply to items when retrieving them.
|
|
157
|
-
* @param options.persistence -
|
|
158
|
-
* @param options.indices - An array of index
|
|
157
|
+
* @param options.persistence - Deprecated. A storage adapter for saving and loading items; pass a `DataAdapter` instead.
|
|
158
|
+
* @param options.indices - An array of field names to index for optimized querying.
|
|
159
159
|
* @param options.enableDebugMode - A boolean to enable or disable debug mode.
|
|
160
160
|
* @param options.fieldTracking - A boolean to enable or disable field tracking by default.
|
|
161
161
|
* @param options.transformAll - A function that will be able to solve the n+1 problem
|
|
@@ -175,14 +175,14 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E ext
|
|
|
175
175
|
/**
|
|
176
176
|
* Checks whether the collection is currently performing a pull operation
|
|
177
177
|
* ⚡️ this function is reactive!
|
|
178
|
-
* (loading data from
|
|
178
|
+
* (loading data from storage).
|
|
179
179
|
* @returns A boolean indicating if the collection is in the process of pulling data.
|
|
180
180
|
*/
|
|
181
181
|
isPulling(): boolean;
|
|
182
182
|
/**
|
|
183
183
|
* Checks whether the collection is currently performing a push operation
|
|
184
184
|
* ⚡️ this function is reactive!
|
|
185
|
-
* (saving data to
|
|
185
|
+
* (saving data to storage).
|
|
186
186
|
* @returns A boolean indicating if the collection is in the process of pushing data.
|
|
187
187
|
*/
|
|
188
188
|
isPushing(): boolean;
|
|
@@ -210,17 +210,16 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E ext
|
|
|
210
210
|
*/
|
|
211
211
|
setFieldTracking(enable: boolean): void;
|
|
212
212
|
/**
|
|
213
|
-
* Resolves when the
|
|
213
|
+
* Resolves when the storage adapter finished initializing
|
|
214
214
|
* and the collection is ready to be used.
|
|
215
215
|
* @returns A promise that resolves when the collection is ready.
|
|
216
216
|
* @example
|
|
217
217
|
* ```ts
|
|
218
|
-
* const collection = new Collection(
|
|
219
|
-
*
|
|
220
|
-
* })
|
|
221
|
-
* await collection.isReady()
|
|
218
|
+
* const collection = new Collection('items', dataAdapter)
|
|
219
|
+
* await collection.ready()
|
|
222
220
|
*
|
|
223
|
-
* collection.insert({ name: 'Item 1' })
|
|
221
|
+
* await collection.insert({ name: 'Item 1' })
|
|
222
|
+
* ```
|
|
224
223
|
*/
|
|
225
224
|
ready(): Promise<void>;
|
|
226
225
|
/**
|
|
@@ -238,7 +237,7 @@ export default class Collection<T extends BaseItem<I> = BaseItem, I = any, E ext
|
|
|
238
237
|
private withPushState;
|
|
239
238
|
private queryListeners;
|
|
240
239
|
/**
|
|
241
|
-
* Disposes the collection, unregisters
|
|
240
|
+
* Disposes the collection, unregisters storage adapters, clears memory, and
|
|
242
241
|
* cleans up all resources used by the collection.
|
|
243
242
|
* @returns A promise that resolves when the collection is disposed.
|
|
244
243
|
*/
|
package/dist/DataAdapter.d.ts
CHANGED
|
@@ -25,11 +25,27 @@ export interface QueryOptions<T extends BaseItem> {
|
|
|
25
25
|
* still in flight, for instance — must omit the delta for as long as it does.
|
|
26
26
|
*/
|
|
27
27
|
export type StateChangeCallback<T extends BaseItem = BaseItem> = (state: 'active' | 'complete' | 'error', delta?: QueryDelta<T>) => void;
|
|
28
|
+
/**
|
|
29
|
+
* What a write changed.
|
|
30
|
+
*
|
|
31
|
+
* An adapter that also knows what the changed items looked like *before* the write returns the
|
|
32
|
+
* object form, and the `'changed'` event on the `Collection` then carries that previous state as
|
|
33
|
+
* its third argument. An adapter that does not returns the changed items on their own, exactly as
|
|
34
|
+
* before, and the event omits the argument.
|
|
35
|
+
*
|
|
36
|
+
* The previous state is reported per item, so `previousItems[n]` is what `items[n]` was before the
|
|
37
|
+
* write. An adapter that reports it must report it for every item it changed.
|
|
38
|
+
*/
|
|
39
|
+
export interface DetailedWriteResult<T> {
|
|
40
|
+
items: T[];
|
|
41
|
+
previousItems: T[];
|
|
42
|
+
}
|
|
43
|
+
export type WriteResult<T> = T[] | DetailedWriteResult<T>;
|
|
28
44
|
export interface CollectionBackend<T extends BaseItem<I>, I> {
|
|
29
45
|
insert(item: T): Promise<T>;
|
|
30
|
-
updateOne(selector: Selector<T>, modifier: Modifier<T>): Promise<T
|
|
31
|
-
updateMany(selector: Selector<T>, modifier: Modifier<T>): Promise<T
|
|
32
|
-
replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<T
|
|
46
|
+
updateOne(selector: Selector<T>, modifier: Modifier<T>): Promise<WriteResult<T>>;
|
|
47
|
+
updateMany(selector: Selector<T>, modifier: Modifier<T>): Promise<WriteResult<T>>;
|
|
48
|
+
replaceOne(selector: Selector<T>, replacement: Omit<T, 'id'> & Partial<Pick<T, 'id'>>): Promise<WriteResult<T>>;
|
|
33
49
|
removeOne(selector: Selector<T>): Promise<T[]>;
|
|
34
50
|
removeMany(selector: Selector<T>): Promise<T[]>;
|
|
35
51
|
registerQuery<O extends QueryOptions<T>>(selector: Selector<T>, options: O): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseItem } from './Collection';
|
|
2
|
-
import { QueryOptions } from './DataAdapter';
|
|
2
|
+
import { DetailedWriteResult, QueryOptions } from './DataAdapter';
|
|
3
3
|
import { default as Modifier } from './types/Modifier';
|
|
4
4
|
import { default as StorageAdapter } from './types/StorageAdapter';
|
|
5
5
|
import { default as Selector } from './types/Selector';
|
|
@@ -20,9 +20,9 @@ type CollectionMethods<T extends BaseItem<I>, I = any> = {
|
|
|
20
20
|
unregisterQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<void>;
|
|
21
21
|
executeQuery: <O extends QueryOptions<T>>(collectionName: string, selector: Selector<T>, options?: O) => Promise<T[]>;
|
|
22
22
|
insert: (collectionName: string, items: [T][]) => Promise<(T | Error)[]>;
|
|
23
|
-
updateOne: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T
|
|
24
|
-
updateMany: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(T
|
|
25
|
-
replaceOne: (collectionName: string, args: [Selector<T>, Omit<T, 'id'> & Partial<Pick<T, 'id'>>][]) => Promise<(T
|
|
23
|
+
updateOne: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(DetailedWriteResult<T> | Error)[]>;
|
|
24
|
+
updateMany: (collectionName: string, args: [Selector<T>, Modifier<T>][]) => Promise<(DetailedWriteResult<T> | Error)[]>;
|
|
25
|
+
replaceOne: (collectionName: string, args: [Selector<T>, Omit<T, 'id'> & Partial<Pick<T, 'id'>>][]) => Promise<(DetailedWriteResult<T> | Error)[]>;
|
|
26
26
|
removeOne: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
|
|
27
27
|
removeMany: (collectionName: string, selectors: [Selector<T>][]) => Promise<(T[] | Error)[]>;
|
|
28
28
|
isReady: (collectionName: string) => Promise<void>;
|
|
@@ -40,8 +40,21 @@ export default class WorkerDataAdapterHost<T extends BaseItem<I>, I = any> {
|
|
|
40
40
|
constructor(workerContext: WorkerDataAdapterHostEndpoint, options: WorkerDataAdapterHostOptions);
|
|
41
41
|
private respond;
|
|
42
42
|
private handleMessage;
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Reads one query's result from the storage adapter.
|
|
45
|
+
*
|
|
46
|
+
* Shares `executeStorageQuery` with `AsyncDataAdapter` and
|
|
47
|
+
* `AutoFetchDataAdapter`. It used to be the same eight lines in all three,
|
|
48
|
+
* which is how a storage-adapter capability ends up honoured by one of them
|
|
49
|
+
* and silently missing from the others — and how the primary-key fast path
|
|
50
|
+
* came to be maintained three times over.
|
|
51
|
+
* @template T - The type of the items.
|
|
52
|
+
* @template I - The type of the item ids.
|
|
53
|
+
* @param collectionName - The collection to read from.
|
|
54
|
+
* @param selector - The query's selector.
|
|
55
|
+
* @param options - The query's sort, window and projection.
|
|
56
|
+
* @returns The query result.
|
|
57
|
+
*/
|
|
45
58
|
private executeQuery;
|
|
46
59
|
private ensureQuery;
|
|
47
60
|
private setQueryItems;
|
package/dist/index.cjs.js
CHANGED
|
@@ -11,10 +11,10 @@ const require_index = require("./index29.cjs.js");
|
|
|
11
11
|
const require_createStorageAdapter = require("./index30.cjs.js");
|
|
12
12
|
const require_createReactivityAdapter = require("./index31.cjs.js");
|
|
13
13
|
const require_reactiveOrAsync = require("./index32.cjs.js");
|
|
14
|
-
const require_AsyncDataAdapter = require("./
|
|
15
|
-
const require_WorkerDataAdapter = require("./
|
|
16
|
-
const require_WorkerDataAdapterHost = require("./
|
|
17
|
-
const require_AutoFetchDataAdapter = require("./
|
|
14
|
+
const require_AsyncDataAdapter = require("./index36.cjs.js");
|
|
15
|
+
const require_WorkerDataAdapter = require("./index38.cjs.js");
|
|
16
|
+
const require_WorkerDataAdapterHost = require("./index39.cjs.js");
|
|
17
|
+
const require_AutoFetchDataAdapter = require("./index40.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.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { default as Selector } from './types/Selector';
|
|
|
4
4
|
export type { default as Modifier } from './types/Modifier';
|
|
5
5
|
export type { BaseItem, ObserveCallbacks, CursorOptions, Transform, TransformAll, SortSpecifier, FieldSpecifier, AnyFindOptions, AsyncFindOptions, FindOptions, SyncFindOptions, CollectionOptions, QueryStateAccessor, } from './Collection';
|
|
6
6
|
export type { default as DataAdapter } from './DataAdapter';
|
|
7
|
-
export type { CollectionBackend, QueryOptions, StateChangeCallback, } from './DataAdapter';
|
|
7
|
+
export type { CollectionBackend, DetailedWriteResult, QueryOptions, StateChangeCallback, WriteResult, } from './DataAdapter';
|
|
8
8
|
export type { QueryDelta } from './utils/queryDelta';
|
|
9
9
|
export { default as Cursor } from './Collection/Cursor';
|
|
10
10
|
export { default as Collection } from './Collection';
|
package/dist/index.mjs
CHANGED
|
@@ -10,8 +10,8 @@ import Collection from "./index29.mjs";
|
|
|
10
10
|
import createStorageAdapter from "./index30.mjs";
|
|
11
11
|
import createReactivityAdapter from "./index31.mjs";
|
|
12
12
|
import reactiveOrAsync, { unwrap } from "./index32.mjs";
|
|
13
|
-
import AsyncDataAdapter from "./
|
|
14
|
-
import WorkerDataAdapter from "./
|
|
15
|
-
import WorkerDataAdapterHost from "./
|
|
16
|
-
import AutoFetchDataAdapter from "./
|
|
13
|
+
import AsyncDataAdapter from "./index36.mjs";
|
|
14
|
+
import WorkerDataAdapter from "./index38.mjs";
|
|
15
|
+
import WorkerDataAdapterHost from "./index39.mjs";
|
|
16
|
+
import AutoFetchDataAdapter from "./index40.mjs";
|
|
17
17
|
export { AsyncDataAdapter, AutoFetchDataAdapter, Collection, Cursor, DefaultDataAdapter, EventEmitter, WorkerDataAdapter, WorkerDataAdapterHost, createReactivityAdapter, createStorageAdapter, get, isEqual, modify, randomId, reactiveOrAsync, serializeValue, unwrap };
|
package/dist/index12.cjs.js
CHANGED
package/dist/index12.mjs
CHANGED
package/dist/index15.cjs.js
CHANGED
|
@@ -52,11 +52,15 @@ function createIndex(field) {
|
|
|
52
52
|
rebuild(items) {
|
|
53
53
|
index.clear();
|
|
54
54
|
items.forEach((item) => {
|
|
55
|
-
|
|
55
|
+
const value = require_serializeValue.default(require_get.default(item, field));
|
|
56
|
+
ensureSet(value).add(item.id);
|
|
56
57
|
});
|
|
57
58
|
},
|
|
58
59
|
insert(items) {
|
|
59
|
-
for (const item of items)
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
const value = require_serializeValue.default(require_get.default(item, field));
|
|
62
|
+
ensureSet(value).add(item.id);
|
|
63
|
+
}
|
|
60
64
|
},
|
|
61
65
|
remove(items) {
|
|
62
66
|
for (const item of items) {
|
package/dist/index15.mjs
CHANGED
|
@@ -52,11 +52,15 @@ function createIndex(field) {
|
|
|
52
52
|
rebuild(items) {
|
|
53
53
|
index.clear();
|
|
54
54
|
items.forEach((item) => {
|
|
55
|
-
|
|
55
|
+
const value = serializeValue(get(item, field));
|
|
56
|
+
ensureSet(value).add(item.id);
|
|
56
57
|
});
|
|
57
58
|
},
|
|
58
59
|
insert(items) {
|
|
59
|
-
for (const item of items)
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
const value = serializeValue(get(item, field));
|
|
62
|
+
ensureSet(value).add(item.id);
|
|
63
|
+
}
|
|
60
64
|
},
|
|
61
65
|
remove(items) {
|
|
62
66
|
for (const item of items) {
|
package/dist/index17.cjs.js
CHANGED
|
@@ -26,7 +26,8 @@ function getMergedIndexInfo(queryFunctions, selector) {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
if (resultOrPromise instanceof Promise) return resultOrPromise.then(async (result) => {
|
|
29
|
-
|
|
29
|
+
const memo = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
30
|
+
return processResult(memo, result);
|
|
30
31
|
});
|
|
31
32
|
const memo = memoOrPromise;
|
|
32
33
|
if (memo instanceof Promise) throw new Error("Mixing async and sync index providers is not supported");
|
|
@@ -124,7 +125,7 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
124
125
|
};
|
|
125
126
|
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
126
127
|
if (match) {
|
|
127
|
-
orIds = [
|
|
128
|
+
orIds = [.../* @__PURE__ */ new Set([...orIds, ...selIds])];
|
|
128
129
|
orMatched = true;
|
|
129
130
|
} else hasNonIndexField = true;
|
|
130
131
|
}) : void 0;
|
|
@@ -139,3 +140,4 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
139
140
|
}
|
|
140
141
|
//#endregion
|
|
141
142
|
exports.default = getIndexInfo;
|
|
143
|
+
exports.getMergedIndexInfo = getMergedIndexInfo;
|
package/dist/index17.mjs
CHANGED
|
@@ -26,7 +26,8 @@ function getMergedIndexInfo(queryFunctions, selector) {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
if (resultOrPromise instanceof Promise) return resultOrPromise.then(async (result) => {
|
|
29
|
-
|
|
29
|
+
const memo = memoOrPromise instanceof Promise ? await memoOrPromise : memoOrPromise;
|
|
30
|
+
return processResult(memo, result);
|
|
30
31
|
});
|
|
31
32
|
const memo = memoOrPromise;
|
|
32
33
|
if (memo instanceof Promise) throw new Error("Mixing async and sync index providers is not supported");
|
|
@@ -124,7 +125,7 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
124
125
|
};
|
|
125
126
|
const $orNewOrPromise = Array.isArray($or) ? optimizeLogicGate(queryFunctions, $or, (match, selIds) => {
|
|
126
127
|
if (match) {
|
|
127
|
-
orIds = [
|
|
128
|
+
orIds = [.../* @__PURE__ */ new Set([...orIds, ...selIds])];
|
|
128
129
|
orMatched = true;
|
|
129
130
|
} else hasNonIndexField = true;
|
|
130
131
|
}) : void 0;
|
|
@@ -138,4 +139,4 @@ function getIndexInfo(queryFunctions, selector) {
|
|
|
138
139
|
return processFlatInfo(flatInfoOrPromise);
|
|
139
140
|
}
|
|
140
141
|
//#endregion
|
|
141
|
-
export { getIndexInfo as default };
|
|
142
|
+
export { getIndexInfo as default, getMergedIndexInfo };
|
package/dist/index18.cjs.js
CHANGED
package/dist/index18.mjs
CHANGED