@signaldb/core 1.7.0 → 2.0.0-beta.0
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 +125 -82
- package/dist/AsyncDataAdapter.d.ts +64 -0
- package/dist/AutoFetchDataAdapter.d.ts +113 -0
- package/dist/Collection/Cursor.d.ts +9 -9
- package/dist/Collection/Observer.d.ts +3 -2
- package/dist/Collection/index.d.ts +52 -46
- package/dist/Collection/types.d.ts +4 -9
- package/dist/DataAdapter.d.ts +33 -0
- package/dist/DefaultDataAdapter.d.ts +32 -0
- package/dist/WorkerDataAdapter.d.ts +22 -0
- package/dist/WorkerDataAdapterHost.d.ts +59 -0
- package/dist/createIndex.d.ts +7 -0
- package/dist/createStorageAdapter.d.ts +9 -0
- package/dist/{Collection/getIndexInfo.d.ts → getIndexInfo.d.ts} +17 -19
- package/dist/index.cjs.js +21 -17
- package/dist/index.cjs10.js +15 -26
- package/dist/index.cjs11.js +13 -10
- package/dist/index.cjs12.js +337 -3
- package/dist/index.cjs13.js +384 -115
- package/dist/index.cjs14.js +183 -67
- package/dist/index.cjs15.js +339 -8
- package/dist/index.cjs16.js +563 -20
- package/dist/index.cjs17.js +16 -12
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +27 -36
- package/dist/index.cjs20.js +102 -13
- package/dist/index.cjs21.js +124 -21
- package/dist/index.cjs22.js +5 -68
- package/dist/index.cjs23.js +22 -82
- package/dist/index.cjs24.js +5 -16
- package/dist/index.cjs25.js +8 -27
- package/dist/index.cjs26.js +27 -7
- package/dist/index.cjs27.js +3 -5
- package/dist/index.cjs28.js +5 -27
- package/dist/index.cjs29.js +27 -40
- package/dist/index.cjs3.js +242 -497
- package/dist/index.cjs30.js +42 -0
- package/dist/index.cjs31.js +9 -0
- package/dist/index.cjs4.js +3 -170
- package/dist/index.cjs5.js +3 -67
- package/dist/index.cjs6.js +27 -3
- package/dist/index.cjs7.js +10 -3
- package/dist/index.cjs8.js +3 -3
- package/dist/index.cjs9.js +131 -3
- package/dist/index.d.ts +10 -8
- package/dist/index.mjs +15 -11
- package/dist/index10.mjs +15 -26
- package/dist/index11.mjs +13 -10
- package/dist/index12.mjs +337 -3
- package/dist/index13.mjs +384 -115
- package/dist/index14.mjs +183 -66
- package/dist/index15.mjs +339 -8
- package/dist/index16.mjs +563 -20
- package/dist/index17.mjs +16 -12
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +27 -36
- package/dist/index20.mjs +102 -13
- package/dist/index21.mjs +123 -21
- package/dist/index22.mjs +5 -67
- package/dist/index23.mjs +22 -81
- package/dist/index24.mjs +5 -16
- package/dist/index25.mjs +8 -27
- package/dist/index26.mjs +27 -7
- package/dist/index27.mjs +3 -5
- package/dist/index28.mjs +5 -27
- package/dist/index29.mjs +27 -40
- package/dist/index3.mjs +241 -497
- package/dist/index30.mjs +43 -0
- package/dist/index31.mjs +10 -0
- package/dist/index4.mjs +3 -170
- package/dist/index5.mjs +3 -66
- package/dist/index6.mjs +27 -3
- package/dist/index7.mjs +10 -3
- package/dist/index8.mjs +3 -3
- package/dist/index9.mjs +131 -3
- package/dist/types/IndexProvider.d.ts +12 -7
- package/dist/types/StorageAdapter.d.ts +20 -0
- package/dist/utils/objectId.d.ts +8 -0
- package/dist/utils/queryId.d.ts +9 -0
- package/package.json +2 -2
- package/dist/AutoFetchCollection.d.ts +0 -60
- package/dist/Collection/createIndex.d.ts +0 -15
- package/dist/ReplicatedCollection.d.ts +0 -60
- package/dist/createMemoryAdapter.d.ts +0 -7
- package/dist/persistence/combinePersistenceAdapters.d.ts +0 -32
- package/dist/persistence/createPersistenceAdapter.d.ts +0 -9
- package/dist/types/MemoryAdapter.d.ts +0 -15
- package/dist/types/PersistenceAdapter.d.ts +0 -20
package/dist/.vite/manifest.json
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
"src/
|
|
3
|
-
"file": "index.
|
|
4
|
-
"name": "
|
|
5
|
-
"src": "src/
|
|
2
|
+
"src/AsyncDataAdapter.ts": {
|
|
3
|
+
"file": "index.cjs13.js",
|
|
4
|
+
"name": "AsyncDataAdapter",
|
|
5
|
+
"src": "src/AsyncDataAdapter.ts",
|
|
6
6
|
"imports": [
|
|
7
|
-
"src/
|
|
8
|
-
"src/utils/
|
|
7
|
+
"src/utils/deepClone.ts",
|
|
8
|
+
"src/utils/match.ts",
|
|
9
|
+
"src/utils/modify.ts",
|
|
10
|
+
"src/utils/queryId.ts",
|
|
11
|
+
"src/utils/isEqual.ts",
|
|
12
|
+
"src/getIndexInfo.ts",
|
|
13
|
+
"src/utils/getMatchingKeys.ts",
|
|
14
|
+
"src/utils/sortItems.ts",
|
|
15
|
+
"src/utils/project.ts"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"src/AutoFetchDataAdapter.ts": {
|
|
19
|
+
"file": "index.cjs16.js",
|
|
20
|
+
"name": "AutoFetchDataAdapter",
|
|
21
|
+
"src": "src/AutoFetchDataAdapter.ts",
|
|
22
|
+
"imports": [
|
|
23
|
+
"src/utils/deepClone.ts",
|
|
24
|
+
"src/utils/match.ts",
|
|
25
|
+
"src/utils/modify.ts",
|
|
26
|
+
"src/utils/queryId.ts",
|
|
27
|
+
"src/utils/isEqual.ts",
|
|
28
|
+
"src/getIndexInfo.ts",
|
|
29
|
+
"src/utils/getMatchingKeys.ts",
|
|
30
|
+
"src/utils/sortItems.ts",
|
|
31
|
+
"src/utils/project.ts"
|
|
9
32
|
]
|
|
10
33
|
},
|
|
11
34
|
"src/Collection/Cursor.ts": {
|
|
@@ -13,8 +36,6 @@
|
|
|
13
36
|
"name": "Collection/Cursor",
|
|
14
37
|
"src": "src/Collection/Cursor.ts",
|
|
15
38
|
"imports": [
|
|
16
|
-
"src/utils/sortItems.ts",
|
|
17
|
-
"src/utils/project.ts",
|
|
18
39
|
"src/Collection/Observer.ts"
|
|
19
40
|
]
|
|
20
41
|
},
|
|
@@ -27,69 +48,97 @@
|
|
|
27
48
|
"src/utils/uniqueBy.ts"
|
|
28
49
|
]
|
|
29
50
|
},
|
|
30
|
-
"src/Collection/
|
|
31
|
-
"file": "index.
|
|
32
|
-
"name": "Collection/
|
|
33
|
-
"src": "src/Collection/
|
|
51
|
+
"src/Collection/index.ts": {
|
|
52
|
+
"file": "index.cjs3.js",
|
|
53
|
+
"name": "Collection/index",
|
|
54
|
+
"src": "src/Collection/index.ts",
|
|
34
55
|
"imports": [
|
|
35
|
-
"src/
|
|
36
|
-
"src/utils/
|
|
37
|
-
"src/utils/
|
|
38
|
-
"src/
|
|
56
|
+
"src/utils/EventEmitter.ts",
|
|
57
|
+
"src/utils/createSignal.ts",
|
|
58
|
+
"src/utils/randomId.ts",
|
|
59
|
+
"src/DefaultDataAdapter.ts",
|
|
60
|
+
"src/utils/modify.ts",
|
|
61
|
+
"src/utils/deepClone.ts",
|
|
62
|
+
"src/Collection/Cursor.ts"
|
|
39
63
|
]
|
|
40
64
|
},
|
|
41
|
-
"src/
|
|
42
|
-
"file": "index.
|
|
43
|
-
"name": "
|
|
44
|
-
"src": "src/
|
|
65
|
+
"src/DefaultDataAdapter.ts": {
|
|
66
|
+
"file": "index.cjs12.js",
|
|
67
|
+
"name": "DefaultDataAdapter",
|
|
68
|
+
"src": "src/DefaultDataAdapter.ts",
|
|
45
69
|
"imports": [
|
|
46
|
-
"src/
|
|
70
|
+
"src/createIndex.ts",
|
|
71
|
+
"src/getIndexInfo.ts",
|
|
72
|
+
"src/utils/deepClone.ts",
|
|
73
|
+
"src/utils/EventEmitter.ts",
|
|
74
|
+
"src/utils/isEqual.ts",
|
|
75
|
+
"src/utils/match.ts",
|
|
76
|
+
"src/utils/modify.ts",
|
|
77
|
+
"src/utils/project.ts",
|
|
78
|
+
"src/utils/queryId.ts",
|
|
79
|
+
"src/utils/serializeValue.ts",
|
|
80
|
+
"src/utils/sortItems.ts"
|
|
47
81
|
]
|
|
48
82
|
},
|
|
49
|
-
"src/
|
|
50
|
-
"file": "index.
|
|
51
|
-
"name": "
|
|
52
|
-
"src": "src/
|
|
83
|
+
"src/WorkerDataAdapter.ts": {
|
|
84
|
+
"file": "index.cjs14.js",
|
|
85
|
+
"name": "WorkerDataAdapter",
|
|
86
|
+
"src": "src/WorkerDataAdapter.ts",
|
|
53
87
|
"imports": [
|
|
54
|
-
"src/utils/
|
|
88
|
+
"src/utils/queryId.ts",
|
|
89
|
+
"src/utils/randomId.ts"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
"src/WorkerDataAdapterHost.ts": {
|
|
93
|
+
"file": "index.cjs15.js",
|
|
94
|
+
"name": "WorkerDataAdapterHost",
|
|
95
|
+
"src": "src/WorkerDataAdapterHost.ts",
|
|
96
|
+
"imports": [
|
|
97
|
+
"src/utils/deepClone.ts",
|
|
55
98
|
"src/utils/match.ts",
|
|
56
99
|
"src/utils/modify.ts",
|
|
100
|
+
"src/utils/queryId.ts",
|
|
57
101
|
"src/utils/isEqual.ts",
|
|
58
|
-
"src/
|
|
59
|
-
"src/utils/
|
|
60
|
-
"src/utils/
|
|
61
|
-
"src/utils/
|
|
62
|
-
"src/Collection/Cursor.ts",
|
|
63
|
-
"src/Collection/getIndexInfo.ts",
|
|
64
|
-
"src/Collection/createIndex.ts"
|
|
102
|
+
"src/getIndexInfo.ts",
|
|
103
|
+
"src/utils/getMatchingKeys.ts",
|
|
104
|
+
"src/utils/sortItems.ts",
|
|
105
|
+
"src/utils/project.ts"
|
|
65
106
|
]
|
|
66
107
|
},
|
|
67
|
-
"src/
|
|
68
|
-
"file": "index.
|
|
69
|
-
"name": "
|
|
70
|
-
"src": "src/
|
|
108
|
+
"src/createIndex.ts": {
|
|
109
|
+
"file": "index.cjs20.js",
|
|
110
|
+
"name": "createIndex",
|
|
111
|
+
"src": "src/createIndex.ts",
|
|
71
112
|
"imports": [
|
|
72
|
-
"src/
|
|
73
|
-
"src/
|
|
74
|
-
"src/
|
|
75
|
-
"src/utils/
|
|
113
|
+
"src/createIndexProvider.ts",
|
|
114
|
+
"src/utils/get.ts",
|
|
115
|
+
"src/utils/getMatchingKeys.ts",
|
|
116
|
+
"src/utils/serializeValue.ts"
|
|
76
117
|
]
|
|
77
118
|
},
|
|
78
119
|
"src/createIndexProvider.ts": {
|
|
79
|
-
"file": "index.
|
|
120
|
+
"file": "index.cjs27.js",
|
|
80
121
|
"name": "createIndexProvider",
|
|
81
122
|
"src": "src/createIndexProvider.ts"
|
|
82
123
|
},
|
|
83
|
-
"src/createMemoryAdapter.ts": {
|
|
84
|
-
"file": "index.cjs7.js",
|
|
85
|
-
"name": "createMemoryAdapter",
|
|
86
|
-
"src": "src/createMemoryAdapter.ts"
|
|
87
|
-
},
|
|
88
124
|
"src/createReactivityAdapter.ts": {
|
|
89
|
-
"file": "index.
|
|
125
|
+
"file": "index.cjs5.js",
|
|
90
126
|
"name": "createReactivityAdapter",
|
|
91
127
|
"src": "src/createReactivityAdapter.ts"
|
|
92
128
|
},
|
|
129
|
+
"src/createStorageAdapter.ts": {
|
|
130
|
+
"file": "index.cjs4.js",
|
|
131
|
+
"name": "createStorageAdapter",
|
|
132
|
+
"src": "src/createStorageAdapter.ts"
|
|
133
|
+
},
|
|
134
|
+
"src/getIndexInfo.ts": {
|
|
135
|
+
"file": "index.cjs21.js",
|
|
136
|
+
"name": "getIndexInfo",
|
|
137
|
+
"src": "src/getIndexInfo.ts",
|
|
138
|
+
"imports": [
|
|
139
|
+
"src/utils/intersection.ts"
|
|
140
|
+
]
|
|
141
|
+
},
|
|
93
142
|
"src/index.ts": {
|
|
94
143
|
"file": "index.cjs.js",
|
|
95
144
|
"name": "index",
|
|
@@ -98,39 +147,28 @@
|
|
|
98
147
|
"imports": [
|
|
99
148
|
"src/Collection/Cursor.ts",
|
|
100
149
|
"src/Collection/index.ts",
|
|
101
|
-
"src/
|
|
102
|
-
"src/persistence/combinePersistenceAdapters.ts",
|
|
103
|
-
"src/createIndexProvider.ts",
|
|
104
|
-
"src/createMemoryAdapter.ts",
|
|
105
|
-
"src/persistence/createPersistenceAdapter.ts",
|
|
150
|
+
"src/createStorageAdapter.ts",
|
|
106
151
|
"src/createReactivityAdapter.ts",
|
|
107
152
|
"src/utils/isEqual.ts",
|
|
108
153
|
"src/utils/modify.ts",
|
|
109
154
|
"src/utils/randomId.ts",
|
|
110
155
|
"src/utils/EventEmitter.ts",
|
|
111
|
-
"src/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"imports": [
|
|
119
|
-
"src/persistence/createPersistenceAdapter.ts"
|
|
156
|
+
"src/utils/get.ts",
|
|
157
|
+
"src/utils/serializeValue.ts",
|
|
158
|
+
"src/DefaultDataAdapter.ts",
|
|
159
|
+
"src/AsyncDataAdapter.ts",
|
|
160
|
+
"src/WorkerDataAdapter.ts",
|
|
161
|
+
"src/WorkerDataAdapterHost.ts",
|
|
162
|
+
"src/AutoFetchDataAdapter.ts"
|
|
120
163
|
]
|
|
121
164
|
},
|
|
122
|
-
"src/persistence/createPersistenceAdapter.ts": {
|
|
123
|
-
"file": "index.cjs8.js",
|
|
124
|
-
"name": "persistence/createPersistenceAdapter",
|
|
125
|
-
"src": "src/persistence/createPersistenceAdapter.ts"
|
|
126
|
-
},
|
|
127
165
|
"src/utils/EventEmitter.ts": {
|
|
128
|
-
"file": "index.
|
|
166
|
+
"file": "index.cjs9.js",
|
|
129
167
|
"name": "utils/EventEmitter",
|
|
130
168
|
"src": "src/utils/EventEmitter.ts"
|
|
131
169
|
},
|
|
132
170
|
"src/utils/createSignal.ts": {
|
|
133
|
-
"file": "index.
|
|
171
|
+
"file": "index.cjs18.js",
|
|
134
172
|
"name": "utils/createSignal",
|
|
135
173
|
"src": "src/utils/createSignal.ts"
|
|
136
174
|
},
|
|
@@ -140,12 +178,12 @@
|
|
|
140
178
|
"src": "src/utils/deepClone.ts"
|
|
141
179
|
},
|
|
142
180
|
"src/utils/get.ts": {
|
|
143
|
-
"file": "index.
|
|
181
|
+
"file": "index.cjs10.js",
|
|
144
182
|
"name": "utils/get",
|
|
145
183
|
"src": "src/utils/get.ts"
|
|
146
184
|
},
|
|
147
185
|
"src/utils/getMatchingKeys.ts": {
|
|
148
|
-
"file": "index.
|
|
186
|
+
"file": "index.cjs26.js",
|
|
149
187
|
"name": "utils/getMatchingKeys",
|
|
150
188
|
"src": "src/utils/getMatchingKeys.ts",
|
|
151
189
|
"imports": [
|
|
@@ -154,27 +192,27 @@
|
|
|
154
192
|
]
|
|
155
193
|
},
|
|
156
194
|
"src/utils/intersection.ts": {
|
|
157
|
-
"file": "index.
|
|
195
|
+
"file": "index.cjs28.js",
|
|
158
196
|
"name": "utils/intersection",
|
|
159
197
|
"src": "src/utils/intersection.ts"
|
|
160
198
|
},
|
|
161
199
|
"src/utils/isEqual.ts": {
|
|
162
|
-
"file": "index.
|
|
200
|
+
"file": "index.cjs6.js",
|
|
163
201
|
"name": "utils/isEqual",
|
|
164
202
|
"src": "src/utils/isEqual.ts"
|
|
165
203
|
},
|
|
166
204
|
"src/utils/isFieldExpression.ts": {
|
|
167
|
-
"file": "index.
|
|
205
|
+
"file": "index.cjs30.js",
|
|
168
206
|
"name": "utils/isFieldExpression",
|
|
169
207
|
"src": "src/utils/isFieldExpression.ts"
|
|
170
208
|
},
|
|
171
209
|
"src/utils/match.ts": {
|
|
172
|
-
"file": "index.
|
|
210
|
+
"file": "index.cjs22.js",
|
|
173
211
|
"name": "utils/match",
|
|
174
212
|
"src": "src/utils/match.ts"
|
|
175
213
|
},
|
|
176
214
|
"src/utils/modify.ts": {
|
|
177
|
-
"file": "index.
|
|
215
|
+
"file": "index.cjs7.js",
|
|
178
216
|
"name": "utils/modify",
|
|
179
217
|
"src": "src/utils/modify.ts",
|
|
180
218
|
"imports": [
|
|
@@ -182,7 +220,7 @@
|
|
|
182
220
|
]
|
|
183
221
|
},
|
|
184
222
|
"src/utils/project.ts": {
|
|
185
|
-
"file": "index.
|
|
223
|
+
"file": "index.cjs23.js",
|
|
186
224
|
"name": "utils/project",
|
|
187
225
|
"src": "src/utils/project.ts",
|
|
188
226
|
"imports": [
|
|
@@ -190,23 +228,28 @@
|
|
|
190
228
|
"src/utils/set.ts"
|
|
191
229
|
]
|
|
192
230
|
},
|
|
231
|
+
"src/utils/queryId.ts": {
|
|
232
|
+
"file": "index.cjs24.js",
|
|
233
|
+
"name": "utils/queryId",
|
|
234
|
+
"src": "src/utils/queryId.ts"
|
|
235
|
+
},
|
|
193
236
|
"src/utils/randomId.ts": {
|
|
194
|
-
"file": "index.
|
|
237
|
+
"file": "index.cjs8.js",
|
|
195
238
|
"name": "utils/randomId",
|
|
196
239
|
"src": "src/utils/randomId.ts"
|
|
197
240
|
},
|
|
198
241
|
"src/utils/serializeValue.ts": {
|
|
199
|
-
"file": "index.
|
|
242
|
+
"file": "index.cjs11.js",
|
|
200
243
|
"name": "utils/serializeValue",
|
|
201
244
|
"src": "src/utils/serializeValue.ts"
|
|
202
245
|
},
|
|
203
246
|
"src/utils/set.ts": {
|
|
204
|
-
"file": "index.
|
|
247
|
+
"file": "index.cjs29.js",
|
|
205
248
|
"name": "utils/set",
|
|
206
249
|
"src": "src/utils/set.ts"
|
|
207
250
|
},
|
|
208
251
|
"src/utils/sortItems.ts": {
|
|
209
|
-
"file": "index.
|
|
252
|
+
"file": "index.cjs25.js",
|
|
210
253
|
"name": "utils/sortItems",
|
|
211
254
|
"src": "src/utils/sortItems.ts",
|
|
212
255
|
"imports": [
|
|
@@ -214,7 +257,7 @@
|
|
|
214
257
|
]
|
|
215
258
|
},
|
|
216
259
|
"src/utils/uniqueBy.ts": {
|
|
217
|
-
"file": "index.
|
|
260
|
+
"file": "index.cjs31.js",
|
|
218
261
|
"name": "utils/uniqueBy",
|
|
219
262
|
"src": "src/utils/uniqueBy.ts"
|
|
220
263
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { BaseItem } from './Collection';
|
|
2
|
+
import type Collection from './Collection';
|
|
3
|
+
import type DataAdapter from './DataAdapter';
|
|
4
|
+
import type { CollectionBackend } from './DataAdapter';
|
|
5
|
+
import type StorageAdapter from './types/StorageAdapter';
|
|
6
|
+
export interface AsyncDataAdapterOptions {
|
|
7
|
+
/** Factory to obtain a StorageAdapter per collection name */
|
|
8
|
+
storage: (name: string) => StorageAdapter<any, any>;
|
|
9
|
+
/** Optional logical id (handy if you run multiple adapters side-by-side) */
|
|
10
|
+
id?: string;
|
|
11
|
+
/** Optional error hook (mirrors WorkerDataAdapterHost) */
|
|
12
|
+
onError?: (error: Error) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* AsyncDataAdapter
|
|
16
|
+
* Combines WorkerDataAdapter + WorkerDataAdapterHost into a single, transport-free adapter.
|
|
17
|
+
* - Keeps the DataAdapter/CollectionBackend surface identical to the Worker version.
|
|
18
|
+
* - Executes queries and mutations directly against the provided StorageAdapter.
|
|
19
|
+
* - Preserves index-aware query optimization and push-style query updates to listeners.
|
|
20
|
+
*/
|
|
21
|
+
export default class AsyncDataAdapter implements DataAdapter {
|
|
22
|
+
private options;
|
|
23
|
+
private id;
|
|
24
|
+
private onError;
|
|
25
|
+
private storageAdapters;
|
|
26
|
+
private storageAdapterReady;
|
|
27
|
+
private collectionIndices;
|
|
28
|
+
private queries;
|
|
29
|
+
constructor(options: AsyncDataAdapterOptions);
|
|
30
|
+
createCollectionBackend<T extends BaseItem<I>, I = any, U = T>(collection: Collection<T, I, U>, indices: string[]): CollectionBackend<T, I>;
|
|
31
|
+
private setupStorage;
|
|
32
|
+
private ensureStorageAdapter;
|
|
33
|
+
/**
|
|
34
|
+
* Compute and publish the result for a specific query
|
|
35
|
+
* @param collectionName - name of the collection
|
|
36
|
+
* @param selector - query selector
|
|
37
|
+
* @param options - query options
|
|
38
|
+
*/
|
|
39
|
+
private fulfillQuery;
|
|
40
|
+
/**
|
|
41
|
+
* Notify listeners about state changes and keep the cache updated
|
|
42
|
+
* @param collectionName - name of the collection
|
|
43
|
+
* @param qid - query id
|
|
44
|
+
* @param state - new state
|
|
45
|
+
* @param error - error if state is 'error', null otherwise
|
|
46
|
+
*/
|
|
47
|
+
private publishState;
|
|
48
|
+
private publishResult;
|
|
49
|
+
private getIndexInfo;
|
|
50
|
+
private queryItems;
|
|
51
|
+
private executeQuery;
|
|
52
|
+
/**
|
|
53
|
+
* After mutations, recompute and push updates for affected active queries
|
|
54
|
+
* @param collectionName - name of the collection
|
|
55
|
+
* @param changedItems - items that were inserted/updated/replaced/removed
|
|
56
|
+
*/
|
|
57
|
+
private checkQueryUpdates;
|
|
58
|
+
private insert;
|
|
59
|
+
private updateOne;
|
|
60
|
+
private updateMany;
|
|
61
|
+
private replaceOne;
|
|
62
|
+
private removeOne;
|
|
63
|
+
private removeMany;
|
|
64
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { BaseItem } from './Collection';
|
|
2
|
+
import type Collection from './Collection';
|
|
3
|
+
import type DataAdapter from './DataAdapter';
|
|
4
|
+
import type { CollectionBackend } from './DataAdapter';
|
|
5
|
+
import type StorageAdapter from './types/StorageAdapter';
|
|
6
|
+
import type Selector from './types/Selector';
|
|
7
|
+
/**
|
|
8
|
+
* AutoFetchDataAdapterOptions
|
|
9
|
+
*
|
|
10
|
+
* Merges the core options required to talk to a per-collection StorageAdapter with
|
|
11
|
+
* the auto-fetch behavior inspired by AutoFetchCollection.
|
|
12
|
+
*/
|
|
13
|
+
export interface AutoFetchDataAdapterOptions {
|
|
14
|
+
/** Factory to obtain a StorageAdapter per collection name */
|
|
15
|
+
storage?: (name: string) => StorageAdapter<any, any>;
|
|
16
|
+
/** Optional logical id (handy if you run multiple adapters side-by-side) */
|
|
17
|
+
id?: string;
|
|
18
|
+
/** Optional error hook */
|
|
19
|
+
onError?: (error: Error) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Fetch hook: given a selector, retrieve items from a remote source.
|
|
22
|
+
* Must resolve to an object with an `items` array. Items MUST include an `id`.
|
|
23
|
+
*/
|
|
24
|
+
fetchQueryItems: (collectionName: string, selector: Selector<BaseItem>) => Promise<BaseItem[] | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Optional: called once at adapter construction to subscribe to remote changes.
|
|
27
|
+
* When invoked, call the provided callback whenever the remote source changed
|
|
28
|
+
* and all active queries should be re-fetched.
|
|
29
|
+
*/
|
|
30
|
+
registerRemoteChange?: (onChange: () => Promise<void>) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Merge strategy for ingesting freshly fetched items with existing ones.
|
|
33
|
+
* Default is shallow spread (right wins).
|
|
34
|
+
*/
|
|
35
|
+
mergeItems?: <T extends BaseItem<any>>(a: T, b: T) => T;
|
|
36
|
+
/**
|
|
37
|
+
* Delay (ms) before purging auto-fetched items for a query after the query
|
|
38
|
+
* becomes inactive. Set to 0 to purge immediately. Default: 10s.
|
|
39
|
+
*/
|
|
40
|
+
purgeDelay?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* AutoFetchDataAdapter
|
|
44
|
+
*
|
|
45
|
+
* A DataAdapter that:
|
|
46
|
+
* - Mirrors the CollectionBackend surface (CRUD + query registry + lifecycle)
|
|
47
|
+
* - Executes queries against a provided StorageAdapter (local cache)
|
|
48
|
+
* - On first registration of a selector, auto-fetches from a remote source and
|
|
49
|
+
* ingests the result into storage (upsert), then pushes query result updates
|
|
50
|
+
* - Optionally purges auto-fetched items for a selector once no observers remain
|
|
51
|
+
* - Can subscribe to remote change notifications to re-fetch active selectors
|
|
52
|
+
*
|
|
53
|
+
* IMPORTANT: Purging only ever deletes items that were introduced via the
|
|
54
|
+
* auto-fetch path and are no longer referenced by any active selector. Items
|
|
55
|
+
* inserted through CRUD calls are never purged.
|
|
56
|
+
*/
|
|
57
|
+
export default class AutoFetchDataAdapter implements DataAdapter {
|
|
58
|
+
private options;
|
|
59
|
+
private id;
|
|
60
|
+
private onError;
|
|
61
|
+
private fetchQueryItems;
|
|
62
|
+
private mergeItems;
|
|
63
|
+
private purgeDelay;
|
|
64
|
+
private storageAdapters;
|
|
65
|
+
private storageAdapterReady;
|
|
66
|
+
private collectionIndices;
|
|
67
|
+
private queries;
|
|
68
|
+
private activeObservers;
|
|
69
|
+
private observerTimeouts;
|
|
70
|
+
private selectorIds;
|
|
71
|
+
private idRefCounts;
|
|
72
|
+
private autoloadIds;
|
|
73
|
+
constructor(options: AutoFetchDataAdapterOptions);
|
|
74
|
+
createCollectionBackend<T extends BaseItem<I>, I = any, U = T>(collection: Collection<T, I, U>, indices: string[]): CollectionBackend<T, I>;
|
|
75
|
+
private selectorKey;
|
|
76
|
+
private forceRefetchAll;
|
|
77
|
+
private fetchAndIngest;
|
|
78
|
+
private purgeSelector;
|
|
79
|
+
private setupStorage;
|
|
80
|
+
private ensureStorageAdapter;
|
|
81
|
+
private publishForSelector;
|
|
82
|
+
private publishState;
|
|
83
|
+
private publishResult;
|
|
84
|
+
private fulfillQuery;
|
|
85
|
+
private getIndexInfo;
|
|
86
|
+
private queryItems;
|
|
87
|
+
private executeQuery;
|
|
88
|
+
private checkQueryUpdates;
|
|
89
|
+
private insert;
|
|
90
|
+
private updateOne;
|
|
91
|
+
private updateMany;
|
|
92
|
+
private replaceOne;
|
|
93
|
+
private removeOne;
|
|
94
|
+
private removeMany;
|
|
95
|
+
private upsertMerged;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Usage (example):
|
|
99
|
+
*
|
|
100
|
+
* const adapter = new AutoFetchDataAdapter({
|
|
101
|
+
* storage: (name) => new IndexedDBStorage(name),
|
|
102
|
+
* fetchQueryItems: async (collectionName, selector) => {
|
|
103
|
+
* const res = await fetch(`/api/${collectionName}?q=${encodeURIComponent(JSON.stringify(selector||{}))}`)
|
|
104
|
+
* const items = await res.json()
|
|
105
|
+
* return { items }
|
|
106
|
+
* },
|
|
107
|
+
* registerRemoteChange: (onChange) => subscribeToWS(onChange),
|
|
108
|
+
* mergeItems: (a, b) => ({ ...a, ...b }),
|
|
109
|
+
* purgeDelay: 10_000,
|
|
110
|
+
* })
|
|
111
|
+
*
|
|
112
|
+
* const backend = adapter.createCollectionBackend(myCollection, ['status', 'projectId'])
|
|
113
|
+
*/
|
|
@@ -7,7 +7,7 @@ import type { ObserveCallbacks } from './Observer';
|
|
|
7
7
|
* @returns A boolean indicating if the current scope is reactive.
|
|
8
8
|
*/
|
|
9
9
|
export declare function isInReactiveScope(reactivity: ReactivityAdapter | undefined | false): boolean;
|
|
10
|
-
export interface CursorOptions<T extends BaseItem, U = T> extends FindOptions<T> {
|
|
10
|
+
export interface CursorOptions<T extends BaseItem, U = T, Async extends boolean = false> extends FindOptions<T, Async> {
|
|
11
11
|
transform?: Transform<T, U>;
|
|
12
12
|
bindEvents?: (requery: () => void) => () => void;
|
|
13
13
|
}
|
|
@@ -17,9 +17,9 @@ export interface CursorOptions<T extends BaseItem, U = T> extends FindOptions<T>
|
|
|
17
17
|
* @template T - The type of the items in the collection.
|
|
18
18
|
* @template U - The transformed item type after applying transformations (default is T).
|
|
19
19
|
*/
|
|
20
|
-
export default class Cursor<T extends BaseItem, U = T> {
|
|
20
|
+
export default class Cursor<T extends BaseItem, U = T, Async extends boolean = false> {
|
|
21
21
|
private observer;
|
|
22
|
-
private
|
|
22
|
+
private getItems;
|
|
23
23
|
private options;
|
|
24
24
|
private onCleanupCallbacks;
|
|
25
25
|
/**
|
|
@@ -38,10 +38,9 @@ export default class Cursor<T extends BaseItem, U = T> {
|
|
|
38
38
|
* @param options.reactive - A reactivity adapter to enable observing changes in the cursor's result set.
|
|
39
39
|
* @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
|
|
40
40
|
*/
|
|
41
|
-
constructor(getItems: () => T[], options?: CursorOptions<T, U>);
|
|
41
|
+
constructor(getItems: Async extends true ? () => Promise<T[]> : () => T[], options?: CursorOptions<T, U, Async>);
|
|
42
42
|
private addGetters;
|
|
43
43
|
private transform;
|
|
44
|
-
private getItems;
|
|
45
44
|
private depend;
|
|
46
45
|
private ensureObserver;
|
|
47
46
|
private observeRawChanges;
|
|
@@ -63,8 +62,9 @@ export default class Cursor<T extends BaseItem, U = T> {
|
|
|
63
62
|
* ⚡️ this function is reactive!
|
|
64
63
|
* @param callback - A function to execute for each item in the result set.
|
|
65
64
|
* @param callback.item - The transformed item.
|
|
65
|
+
* @returns A promise that resolves when all items have been processed, or void if not in async mode.
|
|
66
66
|
*/
|
|
67
|
-
forEach(callback: (item: U) => void): void;
|
|
67
|
+
forEach(callback: (item: U) => void): Async extends true ? Promise<void> : void;
|
|
68
68
|
/**
|
|
69
69
|
* Creates a new array populated with the results of applying the provided callback
|
|
70
70
|
* function to each transformed item in the cursor's result set.
|
|
@@ -74,21 +74,21 @@ export default class Cursor<T extends BaseItem, U = T> {
|
|
|
74
74
|
* @param callback.item - The transformed item.
|
|
75
75
|
* @returns An array of results after applying the callback to each item.
|
|
76
76
|
*/
|
|
77
|
-
map<V>(callback: (item: U) => V): V[];
|
|
77
|
+
map<V>(callback: (item: U) => V): Async extends true ? Promise<V[]> : V[];
|
|
78
78
|
/**
|
|
79
79
|
* Fetches all transformed items from the cursor's result set as an array.
|
|
80
80
|
* Automatically applies filtering, sorting, and limiting as per the cursor's options.
|
|
81
81
|
* ⚡️ this function is reactive!
|
|
82
82
|
* @returns An array of transformed items in the result set.
|
|
83
83
|
*/
|
|
84
|
-
fetch(): U[];
|
|
84
|
+
fetch(): Async extends true ? Promise<U[]> : U[];
|
|
85
85
|
/**
|
|
86
86
|
* Counts the total number of items in the cursor's result set after applying
|
|
87
87
|
* filtering and other criteria.
|
|
88
88
|
* ⚡️ this function is reactive!
|
|
89
89
|
* @returns The total number of items in the result set.
|
|
90
90
|
*/
|
|
91
|
-
count(): number;
|
|
91
|
+
count(): Async extends true ? Promise<number> : number;
|
|
92
92
|
/**
|
|
93
93
|
* Observes changes to the cursor's result set and triggers the specified callbacks
|
|
94
94
|
* when items are added, removed, or updated. Supports reactivity and transformation.
|
|
@@ -39,9 +39,10 @@ export default class Observer<T extends {
|
|
|
39
39
|
/**
|
|
40
40
|
* Compares the previous state of items with the new state and triggers the appropriate callbacks
|
|
41
41
|
* for events such as added, removed, changed, or moved items.
|
|
42
|
-
* @param
|
|
42
|
+
* @param getItems - A function that returns a promise resolving to the new items or the items themselves.
|
|
43
43
|
*/
|
|
44
|
-
runChecks(
|
|
44
|
+
runChecks(getItems: () => Promise<T[]> | T[]): void;
|
|
45
|
+
private checkItems;
|
|
45
46
|
/**
|
|
46
47
|
* Stops the observer by unbinding all events and cleaning up resources.
|
|
47
48
|
*/
|