@signaldb/core 1.7.1 → 2.0.0-beta.1
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 +138 -82
- package/dist/AsyncDataAdapter.d.ts +64 -0
- package/dist/AutoFetchDataAdapter.d.ts +112 -0
- package/dist/Collection/Cursor.d.ts +9 -9
- package/dist/Collection/Observer.d.ts +3 -2
- package/dist/Collection/index.d.ts +54 -46
- package/dist/Collection/types.d.ts +4 -9
- package/dist/DataAdapter.d.ts +34 -0
- package/dist/DefaultDataAdapter.d.ts +33 -0
- package/dist/WorkerDataAdapter.d.ts +25 -0
- package/dist/WorkerDataAdapterHost.d.ts +62 -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 +348 -3
- package/dist/index.cjs13.js +396 -110
- package/dist/index.cjs14.js +178 -68
- package/dist/index.cjs15.js +384 -8
- package/dist/index.cjs16.js +572 -20
- package/dist/index.cjs17.js +12 -4
- package/dist/index.cjs18.js +24 -5
- package/dist/index.cjs2.js +29 -32
- package/dist/index.cjs20.js +5 -13
- package/dist/index.cjs21.js +99 -21
- package/dist/index.cjs22.js +108 -58
- package/dist/index.cjs23.js +5 -82
- package/dist/index.cjs24.js +23 -14
- package/dist/index.cjs25.js +8 -27
- package/dist/index.cjs26.js +27 -7
- package/dist/index.cjs27.js +44 -5
- package/dist/index.cjs28.js +6 -27
- package/dist/index.cjs29.js +7 -40
- package/dist/index.cjs3.js +198 -444
- package/dist/index.cjs30.js +5 -0
- package/dist/index.cjs31.js +7 -0
- package/dist/index.cjs32.js +29 -0
- package/dist/index.cjs33.js +42 -0
- package/dist/index.cjs4.js +3 -165
- package/dist/index.cjs5.js +3 -66
- 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 +11 -8
- package/dist/index.mjs +15 -11
- package/dist/index10.mjs +15 -26
- package/dist/index11.mjs +13 -10
- package/dist/index12.mjs +348 -3
- package/dist/index13.mjs +396 -110
- package/dist/index14.mjs +178 -67
- package/dist/index15.mjs +384 -8
- package/dist/index16.mjs +572 -20
- package/dist/index17.mjs +12 -4
- package/dist/index18.mjs +24 -5
- package/dist/index2.mjs +29 -32
- package/dist/index20.mjs +5 -13
- package/dist/index21.mjs +99 -21
- package/dist/index22.mjs +108 -58
- package/dist/index23.mjs +5 -81
- package/dist/index24.mjs +23 -14
- package/dist/index25.mjs +8 -27
- package/dist/index26.mjs +27 -7
- package/dist/index27.mjs +44 -5
- package/dist/index28.mjs +6 -27
- package/dist/index29.mjs +7 -40
- package/dist/index3.mjs +198 -445
- package/dist/index30.mjs +6 -0
- package/dist/index31.mjs +8 -0
- package/dist/index32.mjs +30 -0
- package/dist/index33.mjs +43 -0
- package/dist/index4.mjs +3 -165
- package/dist/index5.mjs +3 -65
- 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/batchOnNextTick.d.ts +16 -0
- package/dist/utils/objectId.d.ts +8 -0
- package/dist/utils/queryId.d.ts +9 -0
- package/package.json +1 -1
- 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
|
+
"imports": [
|
|
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",
|
|
6
22
|
"imports": [
|
|
7
|
-
"src/
|
|
8
|
-
"src/utils/
|
|
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,100 @@
|
|
|
27
48
|
"src/utils/uniqueBy.ts"
|
|
28
49
|
]
|
|
29
50
|
},
|
|
30
|
-
"src/Collection/createIndex.ts": {
|
|
31
|
-
"file": "index.cjs14.js",
|
|
32
|
-
"name": "Collection/createIndex",
|
|
33
|
-
"src": "src/Collection/createIndex.ts",
|
|
34
|
-
"imports": [
|
|
35
|
-
"src/createIndexProvider.ts",
|
|
36
|
-
"src/utils/get.ts",
|
|
37
|
-
"src/utils/getMatchingKeys.ts",
|
|
38
|
-
"src/utils/serializeValue.ts"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"src/Collection/getIndexInfo.ts": {
|
|
42
|
-
"file": "index.cjs22.js",
|
|
43
|
-
"name": "Collection/getIndexInfo",
|
|
44
|
-
"src": "src/Collection/getIndexInfo.ts",
|
|
45
|
-
"imports": [
|
|
46
|
-
"src/utils/intersection.ts"
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
51
|
"src/Collection/index.ts": {
|
|
50
52
|
"file": "index.cjs3.js",
|
|
51
53
|
"name": "Collection/index",
|
|
52
54
|
"src": "src/Collection/index.ts",
|
|
53
55
|
"imports": [
|
|
54
56
|
"src/utils/EventEmitter.ts",
|
|
55
|
-
"src/utils/
|
|
57
|
+
"src/utils/createSignal.ts",
|
|
58
|
+
"src/utils/randomId.ts",
|
|
59
|
+
"src/DefaultDataAdapter.ts",
|
|
56
60
|
"src/utils/modify.ts",
|
|
61
|
+
"src/utils/deepClone.ts",
|
|
62
|
+
"src/utils/queryId.ts",
|
|
63
|
+
"src/Collection/Cursor.ts"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"src/DefaultDataAdapter.ts": {
|
|
67
|
+
"file": "index.cjs12.js",
|
|
68
|
+
"name": "DefaultDataAdapter",
|
|
69
|
+
"src": "src/DefaultDataAdapter.ts",
|
|
70
|
+
"imports": [
|
|
71
|
+
"src/createIndex.ts",
|
|
72
|
+
"src/getIndexInfo.ts",
|
|
73
|
+
"src/utils/deepClone.ts",
|
|
74
|
+
"src/utils/EventEmitter.ts",
|
|
57
75
|
"src/utils/isEqual.ts",
|
|
76
|
+
"src/utils/match.ts",
|
|
77
|
+
"src/utils/modify.ts",
|
|
78
|
+
"src/utils/project.ts",
|
|
79
|
+
"src/utils/queryId.ts",
|
|
80
|
+
"src/utils/serializeValue.ts",
|
|
81
|
+
"src/utils/sortItems.ts"
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"src/WorkerDataAdapter.ts": {
|
|
85
|
+
"file": "index.cjs14.js",
|
|
86
|
+
"name": "WorkerDataAdapter",
|
|
87
|
+
"src": "src/WorkerDataAdapter.ts",
|
|
88
|
+
"imports": [
|
|
89
|
+
"src/utils/queryId.ts",
|
|
58
90
|
"src/utils/randomId.ts",
|
|
91
|
+
"src/utils/batchOnNextTick.ts"
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
"src/WorkerDataAdapterHost.ts": {
|
|
95
|
+
"file": "index.cjs15.js",
|
|
96
|
+
"name": "WorkerDataAdapterHost",
|
|
97
|
+
"src": "src/WorkerDataAdapterHost.ts",
|
|
98
|
+
"imports": [
|
|
59
99
|
"src/utils/deepClone.ts",
|
|
60
|
-
"src/utils/
|
|
61
|
-
"src/utils/
|
|
62
|
-
"src/
|
|
63
|
-
"src/
|
|
64
|
-
"src/
|
|
100
|
+
"src/utils/match.ts",
|
|
101
|
+
"src/utils/modify.ts",
|
|
102
|
+
"src/utils/queryId.ts",
|
|
103
|
+
"src/utils/isEqual.ts",
|
|
104
|
+
"src/getIndexInfo.ts",
|
|
105
|
+
"src/utils/getMatchingKeys.ts",
|
|
106
|
+
"src/utils/sortItems.ts",
|
|
107
|
+
"src/utils/project.ts",
|
|
108
|
+
"src/utils/compact.ts"
|
|
65
109
|
]
|
|
66
110
|
},
|
|
67
|
-
"src/
|
|
68
|
-
"file": "index.
|
|
69
|
-
"name": "
|
|
70
|
-
"src": "src/
|
|
111
|
+
"src/createIndex.ts": {
|
|
112
|
+
"file": "index.cjs21.js",
|
|
113
|
+
"name": "createIndex",
|
|
114
|
+
"src": "src/createIndex.ts",
|
|
71
115
|
"imports": [
|
|
72
|
-
"src/
|
|
73
|
-
"src/
|
|
74
|
-
"src/
|
|
75
|
-
"src/utils/
|
|
116
|
+
"src/createIndexProvider.ts",
|
|
117
|
+
"src/utils/get.ts",
|
|
118
|
+
"src/utils/getMatchingKeys.ts",
|
|
119
|
+
"src/utils/serializeValue.ts"
|
|
76
120
|
]
|
|
77
121
|
},
|
|
78
122
|
"src/createIndexProvider.ts": {
|
|
79
|
-
"file": "index.
|
|
123
|
+
"file": "index.cjs30.js",
|
|
80
124
|
"name": "createIndexProvider",
|
|
81
125
|
"src": "src/createIndexProvider.ts"
|
|
82
126
|
},
|
|
83
|
-
"src/createMemoryAdapter.ts": {
|
|
84
|
-
"file": "index.cjs7.js",
|
|
85
|
-
"name": "createMemoryAdapter",
|
|
86
|
-
"src": "src/createMemoryAdapter.ts"
|
|
87
|
-
},
|
|
88
127
|
"src/createReactivityAdapter.ts": {
|
|
89
|
-
"file": "index.
|
|
128
|
+
"file": "index.cjs5.js",
|
|
90
129
|
"name": "createReactivityAdapter",
|
|
91
130
|
"src": "src/createReactivityAdapter.ts"
|
|
92
131
|
},
|
|
132
|
+
"src/createStorageAdapter.ts": {
|
|
133
|
+
"file": "index.cjs4.js",
|
|
134
|
+
"name": "createStorageAdapter",
|
|
135
|
+
"src": "src/createStorageAdapter.ts"
|
|
136
|
+
},
|
|
137
|
+
"src/getIndexInfo.ts": {
|
|
138
|
+
"file": "index.cjs22.js",
|
|
139
|
+
"name": "getIndexInfo",
|
|
140
|
+
"src": "src/getIndexInfo.ts",
|
|
141
|
+
"imports": [
|
|
142
|
+
"src/utils/intersection.ts"
|
|
143
|
+
]
|
|
144
|
+
},
|
|
93
145
|
"src/index.ts": {
|
|
94
146
|
"file": "index.cjs.js",
|
|
95
147
|
"name": "index",
|
|
@@ -98,39 +150,38 @@
|
|
|
98
150
|
"imports": [
|
|
99
151
|
"src/Collection/Cursor.ts",
|
|
100
152
|
"src/Collection/index.ts",
|
|
101
|
-
"src/
|
|
102
|
-
"src/persistence/combinePersistenceAdapters.ts",
|
|
103
|
-
"src/createIndexProvider.ts",
|
|
104
|
-
"src/createMemoryAdapter.ts",
|
|
105
|
-
"src/persistence/createPersistenceAdapter.ts",
|
|
153
|
+
"src/createStorageAdapter.ts",
|
|
106
154
|
"src/createReactivityAdapter.ts",
|
|
107
155
|
"src/utils/isEqual.ts",
|
|
108
156
|
"src/utils/modify.ts",
|
|
109
157
|
"src/utils/randomId.ts",
|
|
110
158
|
"src/utils/EventEmitter.ts",
|
|
111
|
-
"src/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"imports": [
|
|
119
|
-
"src/persistence/createPersistenceAdapter.ts"
|
|
159
|
+
"src/utils/get.ts",
|
|
160
|
+
"src/utils/serializeValue.ts",
|
|
161
|
+
"src/DefaultDataAdapter.ts",
|
|
162
|
+
"src/AsyncDataAdapter.ts",
|
|
163
|
+
"src/WorkerDataAdapter.ts",
|
|
164
|
+
"src/WorkerDataAdapterHost.ts",
|
|
165
|
+
"src/AutoFetchDataAdapter.ts"
|
|
120
166
|
]
|
|
121
167
|
},
|
|
122
|
-
"src/persistence/createPersistenceAdapter.ts": {
|
|
123
|
-
"file": "index.cjs8.js",
|
|
124
|
-
"name": "persistence/createPersistenceAdapter",
|
|
125
|
-
"src": "src/persistence/createPersistenceAdapter.ts"
|
|
126
|
-
},
|
|
127
168
|
"src/utils/EventEmitter.ts": {
|
|
128
|
-
"file": "index.
|
|
169
|
+
"file": "index.cjs9.js",
|
|
129
170
|
"name": "utils/EventEmitter",
|
|
130
171
|
"src": "src/utils/EventEmitter.ts"
|
|
131
172
|
},
|
|
173
|
+
"src/utils/batchOnNextTick.ts": {
|
|
174
|
+
"file": "index.cjs27.js",
|
|
175
|
+
"name": "utils/batchOnNextTick",
|
|
176
|
+
"src": "src/utils/batchOnNextTick.ts"
|
|
177
|
+
},
|
|
178
|
+
"src/utils/compact.ts": {
|
|
179
|
+
"file": "index.cjs28.js",
|
|
180
|
+
"name": "utils/compact",
|
|
181
|
+
"src": "src/utils/compact.ts"
|
|
182
|
+
},
|
|
132
183
|
"src/utils/createSignal.ts": {
|
|
133
|
-
"file": "index.
|
|
184
|
+
"file": "index.cjs18.js",
|
|
134
185
|
"name": "utils/createSignal",
|
|
135
186
|
"src": "src/utils/createSignal.ts"
|
|
136
187
|
},
|
|
@@ -140,12 +191,12 @@
|
|
|
140
191
|
"src": "src/utils/deepClone.ts"
|
|
141
192
|
},
|
|
142
193
|
"src/utils/get.ts": {
|
|
143
|
-
"file": "index.
|
|
194
|
+
"file": "index.cjs10.js",
|
|
144
195
|
"name": "utils/get",
|
|
145
196
|
"src": "src/utils/get.ts"
|
|
146
197
|
},
|
|
147
198
|
"src/utils/getMatchingKeys.ts": {
|
|
148
|
-
"file": "index.
|
|
199
|
+
"file": "index.cjs26.js",
|
|
149
200
|
"name": "utils/getMatchingKeys",
|
|
150
201
|
"src": "src/utils/getMatchingKeys.ts",
|
|
151
202
|
"imports": [
|
|
@@ -154,27 +205,27 @@
|
|
|
154
205
|
]
|
|
155
206
|
},
|
|
156
207
|
"src/utils/intersection.ts": {
|
|
157
|
-
"file": "index.
|
|
208
|
+
"file": "index.cjs31.js",
|
|
158
209
|
"name": "utils/intersection",
|
|
159
210
|
"src": "src/utils/intersection.ts"
|
|
160
211
|
},
|
|
161
212
|
"src/utils/isEqual.ts": {
|
|
162
|
-
"file": "index.
|
|
213
|
+
"file": "index.cjs6.js",
|
|
163
214
|
"name": "utils/isEqual",
|
|
164
215
|
"src": "src/utils/isEqual.ts"
|
|
165
216
|
},
|
|
166
217
|
"src/utils/isFieldExpression.ts": {
|
|
167
|
-
"file": "index.
|
|
218
|
+
"file": "index.cjs33.js",
|
|
168
219
|
"name": "utils/isFieldExpression",
|
|
169
220
|
"src": "src/utils/isFieldExpression.ts"
|
|
170
221
|
},
|
|
171
222
|
"src/utils/match.ts": {
|
|
172
|
-
"file": "index.
|
|
223
|
+
"file": "index.cjs23.js",
|
|
173
224
|
"name": "utils/match",
|
|
174
225
|
"src": "src/utils/match.ts"
|
|
175
226
|
},
|
|
176
227
|
"src/utils/modify.ts": {
|
|
177
|
-
"file": "index.
|
|
228
|
+
"file": "index.cjs7.js",
|
|
178
229
|
"name": "utils/modify",
|
|
179
230
|
"src": "src/utils/modify.ts",
|
|
180
231
|
"imports": [
|
|
@@ -182,7 +233,7 @@
|
|
|
182
233
|
]
|
|
183
234
|
},
|
|
184
235
|
"src/utils/project.ts": {
|
|
185
|
-
"file": "index.
|
|
236
|
+
"file": "index.cjs24.js",
|
|
186
237
|
"name": "utils/project",
|
|
187
238
|
"src": "src/utils/project.ts",
|
|
188
239
|
"imports": [
|
|
@@ -190,23 +241,28 @@
|
|
|
190
241
|
"src/utils/set.ts"
|
|
191
242
|
]
|
|
192
243
|
},
|
|
244
|
+
"src/utils/queryId.ts": {
|
|
245
|
+
"file": "index.cjs20.js",
|
|
246
|
+
"name": "utils/queryId",
|
|
247
|
+
"src": "src/utils/queryId.ts"
|
|
248
|
+
},
|
|
193
249
|
"src/utils/randomId.ts": {
|
|
194
|
-
"file": "index.
|
|
250
|
+
"file": "index.cjs8.js",
|
|
195
251
|
"name": "utils/randomId",
|
|
196
252
|
"src": "src/utils/randomId.ts"
|
|
197
253
|
},
|
|
198
254
|
"src/utils/serializeValue.ts": {
|
|
199
|
-
"file": "index.
|
|
255
|
+
"file": "index.cjs11.js",
|
|
200
256
|
"name": "utils/serializeValue",
|
|
201
257
|
"src": "src/utils/serializeValue.ts"
|
|
202
258
|
},
|
|
203
259
|
"src/utils/set.ts": {
|
|
204
|
-
"file": "index.
|
|
260
|
+
"file": "index.cjs32.js",
|
|
205
261
|
"name": "utils/set",
|
|
206
262
|
"src": "src/utils/set.ts"
|
|
207
263
|
},
|
|
208
264
|
"src/utils/sortItems.ts": {
|
|
209
|
-
"file": "index.
|
|
265
|
+
"file": "index.cjs25.js",
|
|
210
266
|
"name": "utils/sortItems",
|
|
211
267
|
"src": "src/utils/sortItems.ts",
|
|
212
268
|
"imports": [
|
|
@@ -214,7 +270,7 @@
|
|
|
214
270
|
]
|
|
215
271
|
},
|
|
216
272
|
"src/utils/uniqueBy.ts": {
|
|
217
|
-
"file": "index.
|
|
273
|
+
"file": "index.cjs29.js",
|
|
218
274
|
"name": "utils/uniqueBy",
|
|
219
275
|
"src": "src/utils/uniqueBy.ts"
|
|
220
276
|
}
|
|
@@ -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,112 @@
|
|
|
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 forceRefetchAll;
|
|
76
|
+
private fetchAndIngest;
|
|
77
|
+
private purgeSelector;
|
|
78
|
+
private setupStorage;
|
|
79
|
+
private ensureStorageAdapter;
|
|
80
|
+
private publishForSelector;
|
|
81
|
+
private publishState;
|
|
82
|
+
private publishResult;
|
|
83
|
+
private fulfillQuery;
|
|
84
|
+
private getIndexInfo;
|
|
85
|
+
private queryItems;
|
|
86
|
+
private executeQuery;
|
|
87
|
+
private checkQueryUpdates;
|
|
88
|
+
private insert;
|
|
89
|
+
private updateOne;
|
|
90
|
+
private updateMany;
|
|
91
|
+
private replaceOne;
|
|
92
|
+
private removeOne;
|
|
93
|
+
private removeMany;
|
|
94
|
+
private upsertMerged;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Usage (example):
|
|
98
|
+
*
|
|
99
|
+
* const adapter = new AutoFetchDataAdapter({
|
|
100
|
+
* storage: (name) => new IndexedDBStorage(name),
|
|
101
|
+
* fetchQueryItems: async (collectionName, selector) => {
|
|
102
|
+
* const res = await fetch(`/api/${collectionName}?q=${encodeURIComponent(JSON.stringify(selector||{}))}`)
|
|
103
|
+
* const items = await res.json()
|
|
104
|
+
* return { items }
|
|
105
|
+
* },
|
|
106
|
+
* registerRemoteChange: (onChange) => subscribeToWS(onChange),
|
|
107
|
+
* mergeItems: (a, b) => ({ ...a, ...b }),
|
|
108
|
+
* purgeDelay: 10_000,
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* const backend = adapter.createCollectionBackend(myCollection, ['status', 'projectId'])
|
|
112
|
+
*/
|
|
@@ -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
|
*/
|