@signaldb/core 1.0.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/README.md +68 -0
- package/dist/.vite/manifest.json +222 -0
- package/dist/AutoFetchCollection.d.ts +60 -0
- package/dist/Collection/Cursor.d.ts +112 -0
- package/dist/Collection/Observer.d.ts +61 -0
- package/dist/Collection/createIndex.d.ts +15 -0
- package/dist/Collection/getIndexInfo.d.ts +41 -0
- package/dist/Collection/index.d.ts +235 -0
- package/dist/Collection/types.d.ts +25 -0
- package/dist/ReplicatedCollection.d.ts +60 -0
- package/dist/createIndexProvider.d.ts +8 -0
- package/dist/createMemoryAdapter.d.ts +7 -0
- package/dist/createReactivityAdapter.d.ts +8 -0
- package/dist/index.cjs.js +24 -0
- package/dist/index.cjs10.js +8 -0
- package/dist/index.cjs11.js +5 -0
- package/dist/index.cjs12.js +37 -0
- package/dist/index.cjs13.js +26 -0
- package/dist/index.cjs14.js +7 -0
- package/dist/index.cjs15.js +43 -0
- package/dist/index.cjs16.js +13 -0
- package/dist/index.cjs17.js +20 -0
- package/dist/index.cjs18.js +247 -0
- package/dist/index.cjs19.js +71 -0
- package/dist/index.cjs2.js +631 -0
- package/dist/index.cjs20.js +80 -0
- package/dist/index.cjs21.js +10 -0
- package/dist/index.cjs22.js +27 -0
- package/dist/index.cjs23.js +137 -0
- package/dist/index.cjs24.js +18 -0
- package/dist/index.cjs25.js +7 -0
- package/dist/index.cjs26.js +19 -0
- package/dist/index.cjs27.js +24 -0
- package/dist/index.cjs28.js +42 -0
- package/dist/index.cjs29.js +29 -0
- package/dist/index.cjs3.js +165 -0
- package/dist/index.cjs30.js +9 -0
- package/dist/index.cjs4.js +70 -0
- package/dist/index.cjs5.js +5 -0
- package/dist/index.cjs6.js +5 -0
- package/dist/index.cjs7.js +5 -0
- package/dist/index.cjs8.js +5 -0
- package/dist/index.cjs9.js +30 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +24 -0
- package/dist/index10.mjs +9 -0
- package/dist/index11.mjs +6 -0
- package/dist/index12.mjs +37 -0
- package/dist/index13.mjs +27 -0
- package/dist/index14.mjs +8 -0
- package/dist/index15.mjs +43 -0
- package/dist/index16.mjs +14 -0
- package/dist/index17.mjs +21 -0
- package/dist/index18.mjs +247 -0
- package/dist/index19.mjs +71 -0
- package/dist/index2.mjs +632 -0
- package/dist/index20.mjs +80 -0
- package/dist/index21.mjs +11 -0
- package/dist/index22.mjs +28 -0
- package/dist/index23.mjs +138 -0
- package/dist/index24.mjs +18 -0
- package/dist/index25.mjs +8 -0
- package/dist/index26.mjs +20 -0
- package/dist/index27.mjs +25 -0
- package/dist/index28.mjs +43 -0
- package/dist/index29.mjs +30 -0
- package/dist/index3.mjs +166 -0
- package/dist/index30.mjs +10 -0
- package/dist/index4.mjs +70 -0
- package/dist/index5.mjs +6 -0
- package/dist/index6.mjs +6 -0
- package/dist/index7.mjs +6 -0
- package/dist/index8.mjs +6 -0
- package/dist/index9.mjs +31 -0
- package/dist/persistence/combinePersistenceAdapters.d.ts +32 -0
- package/dist/persistence/createPersistenceAdapter.d.ts +9 -0
- package/dist/types/Dependency.d.ts +4 -0
- package/dist/types/EventEmitter.d.ts +25 -0
- package/dist/types/IndexProvider.d.ts +19 -0
- package/dist/types/MemoryAdapter.d.ts +15 -0
- package/dist/types/Modifier.d.ts +39 -0
- package/dist/types/PersistenceAdapter.d.ts +20 -0
- package/dist/types/ReactivityAdapter.d.ts +6 -0
- package/dist/types/Selector.d.ts +47 -0
- package/dist/types/Signal.d.ts +4 -0
- package/dist/utils/compact.d.ts +9 -0
- package/dist/utils/createSignal.d.ts +14 -0
- package/dist/utils/deepClone.d.ts +17 -0
- package/dist/utils/get.d.ts +9 -0
- package/dist/utils/getMatchingKeys.d.ts +14 -0
- package/dist/utils/intersection.d.ts +9 -0
- package/dist/utils/isEqual.d.ts +14 -0
- package/dist/utils/isFieldExpression.d.ts +11 -0
- package/dist/utils/match.d.ts +12 -0
- package/dist/utils/modify.d.ts +14 -0
- package/dist/utils/project.d.ts +15 -0
- package/dist/utils/randomId.d.ts +7 -0
- package/dist/utils/serializeValue.d.ts +12 -0
- package/dist/utils/set.d.ts +13 -0
- package/dist/utils/sortItems.d.ts +12 -0
- package/dist/utils/uniqueBy.d.ts +10 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="#">
|
|
3
|
+
<img src="/docs/public/logo.svg" width="150px" alt="SignalDB Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/maxnowack/signaldb/releases"><img src="https://img.shields.io/github/v/release/maxnowack/signaldb?include_prereleases&label=version&sort=semver" alt="Current Version" /></a>
|
|
9
|
+
<a href="https://github.com/maxnowack/signaldb/actions"><img src="https://img.shields.io/github/checks-status/maxnowack/signaldb/main" alt="Status Checks" /></a>
|
|
10
|
+
<img src="https://img.shields.io/npm/types/signaldb" alt="TypeScript" />
|
|
11
|
+
<a href="https://app.codecov.io/gh/maxnowack/signaldb"><img src="https://img.shields.io/codecov/c/github/maxnowack/signaldb" alt="Coverage" /></a>
|
|
12
|
+
<a href="https://github.com/maxnowack/signaldb/blob/main/LICENSE"><img src="https://img.shields.io/github/license/maxnowack/signaldb" alt="License" /></a>
|
|
13
|
+
<a href="https://github.com/maxnowack/signaldb/stargazers"><img src="https://img.shields.io/github/stars/maxnowack/signaldb" alt="Stargazers" /></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://signaldb.js.org/getting-started/">Getting Started</a> |
|
|
18
|
+
<a href="https://signaldb.js.org/reference/">Reference</a>
|
|
19
|
+
<p>
|
|
20
|
+
|
|
21
|
+
# SignalDB
|
|
22
|
+
|
|
23
|
+
SignalDB is a client-side database optimized for modern web applications. It provides an optimistic UI for creating responsive and dynamic interfaces, a MongoDB-like interface for familiarity, and robust TypeScript support to ensure type safety and accelerate development. SignalDB enables versatile local data persistence with support for various storage providers and facilitates real-time updates by gathering and synchronizing data from multiple sources. Its framework-agnostic design makes it suitable for projects of any scale, offering instant data access with minimal latency, which is ideal for applications requiring fast data handling and real-time interactions. Adapters are available for popular reactive libraries, including [Angular](https://signaldb.js.org/guides/angular/), [React](https://signaldb.js.org/guides/react/), [Solid](https://signaldb.js.org/guides/solid-js/), [Svelte](https://signaldb.js.org/guides/svelte/) and [Vue.js](https://signaldb.js.org/guides/vue/).
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
````
|
|
28
|
+
$ npm install @signaldb/core
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { Collection } from '@signaldb/core'
|
|
35
|
+
|
|
36
|
+
const Posts = new Collection()
|
|
37
|
+
const postId = Posts.insert({ title: 'Foo', text: 'Lorem ipsum …' })
|
|
38
|
+
|
|
39
|
+
Posts.updateOne({ id: postId }, { // updates the post
|
|
40
|
+
$set: {
|
|
41
|
+
title: 'New title',
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
Posts.removeOne({ id: postId }) // removes the post
|
|
46
|
+
|
|
47
|
+
const cursor = collection.find({})
|
|
48
|
+
|
|
49
|
+
// returns an array with all documents in the collection
|
|
50
|
+
// reruns automatically in a reactive context
|
|
51
|
+
console.log(cursor.fetch())
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
See the [documentation](https://signaldb.js.org/) for more information.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
Licensed under MIT license. Copyright (c) 2024 Max Nowack
|
|
58
|
+
|
|
59
|
+
## Contributions
|
|
60
|
+
Contributions are welcome. Please open issues and/or file Pull Requests.
|
|
61
|
+
See [Contributing.md](https://github.com/maxnowack/signaldb/blob/main/CONTRIBUTING.md) to get started.
|
|
62
|
+
|
|
63
|
+
## Troubleshooting
|
|
64
|
+
|
|
65
|
+
If you encounter any issues, there are several ways to get support.
|
|
66
|
+
- Join our [Discord server](https://discord.gg/MB4ZGJX7).
|
|
67
|
+
- [Start a discussion](https://github.com/maxnowack/signaldb/discussions/new/choose)
|
|
68
|
+
- [Open an issue](https://github.com/maxnowack/signaldb/issues/new)
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
{
|
|
2
|
+
"../../../node_modules/tslib/tslib.es6.mjs": {
|
|
3
|
+
"file": "index.cjs24.js",
|
|
4
|
+
"name": "node_modules/tslib/tslib.es6",
|
|
5
|
+
"src": "../../../node_modules/tslib/tslib.es6.mjs"
|
|
6
|
+
},
|
|
7
|
+
"src/AutoFetchCollection.ts": {
|
|
8
|
+
"file": "index.cjs3.js",
|
|
9
|
+
"name": "packages/base/core/src/AutoFetchCollection",
|
|
10
|
+
"src": "src/AutoFetchCollection.ts",
|
|
11
|
+
"imports": [
|
|
12
|
+
"src/ReplicatedCollection.ts",
|
|
13
|
+
"src/utils/createSignal.ts"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"src/Collection/Cursor.ts": {
|
|
17
|
+
"file": "index.cjs18.js",
|
|
18
|
+
"name": "packages/base/core/src/Collection/Cursor",
|
|
19
|
+
"src": "src/Collection/Cursor.ts",
|
|
20
|
+
"imports": [
|
|
21
|
+
"src/utils/sortItems.ts",
|
|
22
|
+
"src/utils/project.ts",
|
|
23
|
+
"src/Collection/Observer.ts"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"src/Collection/Observer.ts": {
|
|
27
|
+
"file": "index.cjs23.js",
|
|
28
|
+
"name": "packages/base/core/src/Collection/Observer",
|
|
29
|
+
"src": "src/Collection/Observer.ts",
|
|
30
|
+
"imports": [
|
|
31
|
+
"src/utils/isEqual.ts",
|
|
32
|
+
"src/utils/uniqueBy.ts"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
"src/Collection/createIndex.ts": {
|
|
36
|
+
"file": "index.cjs12.js",
|
|
37
|
+
"name": "packages/base/core/src/Collection/createIndex",
|
|
38
|
+
"src": "src/Collection/createIndex.ts",
|
|
39
|
+
"imports": [
|
|
40
|
+
"src/createIndexProvider.ts",
|
|
41
|
+
"src/utils/get.ts",
|
|
42
|
+
"src/utils/getMatchingKeys.ts",
|
|
43
|
+
"src/utils/serializeValue.ts"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"src/Collection/getIndexInfo.ts": {
|
|
47
|
+
"file": "index.cjs19.js",
|
|
48
|
+
"name": "packages/base/core/src/Collection/getIndexInfo",
|
|
49
|
+
"src": "src/Collection/getIndexInfo.ts",
|
|
50
|
+
"imports": [
|
|
51
|
+
"../../../node_modules/tslib/tslib.es6.mjs",
|
|
52
|
+
"src/utils/intersection.ts"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"src/Collection/index.ts": {
|
|
56
|
+
"file": "index.cjs2.js",
|
|
57
|
+
"name": "packages/base/core/src/Collection/index",
|
|
58
|
+
"src": "src/Collection/index.ts",
|
|
59
|
+
"imports": [
|
|
60
|
+
"src/types/EventEmitter.ts",
|
|
61
|
+
"src/utils/match.ts",
|
|
62
|
+
"src/utils/modify.ts",
|
|
63
|
+
"src/utils/isEqual.ts",
|
|
64
|
+
"src/utils/randomId.ts",
|
|
65
|
+
"src/utils/deepClone.ts",
|
|
66
|
+
"src/utils/serializeValue.ts",
|
|
67
|
+
"src/utils/createSignal.ts",
|
|
68
|
+
"src/Collection/Cursor.ts",
|
|
69
|
+
"src/Collection/getIndexInfo.ts",
|
|
70
|
+
"src/Collection/createIndex.ts"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"src/ReplicatedCollection.ts": {
|
|
74
|
+
"file": "index.cjs20.js",
|
|
75
|
+
"name": "packages/base/core/src/ReplicatedCollection",
|
|
76
|
+
"src": "src/ReplicatedCollection.ts",
|
|
77
|
+
"imports": [
|
|
78
|
+
"src/Collection/index.ts",
|
|
79
|
+
"src/persistence/combinePersistenceAdapters.ts",
|
|
80
|
+
"src/persistence/createPersistenceAdapter.ts",
|
|
81
|
+
"src/utils/createSignal.ts"
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
"src/createIndexProvider.ts": {
|
|
85
|
+
"file": "index.cjs5.js",
|
|
86
|
+
"name": "packages/base/core/src/createIndexProvider",
|
|
87
|
+
"src": "src/createIndexProvider.ts"
|
|
88
|
+
},
|
|
89
|
+
"src/createMemoryAdapter.ts": {
|
|
90
|
+
"file": "index.cjs6.js",
|
|
91
|
+
"name": "packages/base/core/src/createMemoryAdapter",
|
|
92
|
+
"src": "src/createMemoryAdapter.ts"
|
|
93
|
+
},
|
|
94
|
+
"src/createReactivityAdapter.ts": {
|
|
95
|
+
"file": "index.cjs8.js",
|
|
96
|
+
"name": "packages/base/core/src/createReactivityAdapter",
|
|
97
|
+
"src": "src/createReactivityAdapter.ts"
|
|
98
|
+
},
|
|
99
|
+
"src/index.ts": {
|
|
100
|
+
"file": "index.cjs.js",
|
|
101
|
+
"name": "packages/base/core/src/index",
|
|
102
|
+
"src": "src/index.ts",
|
|
103
|
+
"isEntry": true,
|
|
104
|
+
"imports": [
|
|
105
|
+
"src/Collection/index.ts",
|
|
106
|
+
"src/AutoFetchCollection.ts",
|
|
107
|
+
"src/persistence/combinePersistenceAdapters.ts",
|
|
108
|
+
"src/createIndexProvider.ts",
|
|
109
|
+
"src/createMemoryAdapter.ts",
|
|
110
|
+
"src/persistence/createPersistenceAdapter.ts",
|
|
111
|
+
"src/createReactivityAdapter.ts",
|
|
112
|
+
"src/utils/isEqual.ts",
|
|
113
|
+
"src/utils/modify.ts",
|
|
114
|
+
"src/utils/randomId.ts",
|
|
115
|
+
"src/Collection/createIndex.ts"
|
|
116
|
+
]
|
|
117
|
+
},
|
|
118
|
+
"src/persistence/combinePersistenceAdapters.ts": {
|
|
119
|
+
"file": "index.cjs4.js",
|
|
120
|
+
"name": "packages/base/core/src/persistence/combinePersistenceAdapters",
|
|
121
|
+
"src": "src/persistence/combinePersistenceAdapters.ts",
|
|
122
|
+
"imports": [
|
|
123
|
+
"src/persistence/createPersistenceAdapter.ts"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"src/persistence/createPersistenceAdapter.ts": {
|
|
127
|
+
"file": "index.cjs7.js",
|
|
128
|
+
"name": "packages/base/core/src/persistence/createPersistenceAdapter",
|
|
129
|
+
"src": "src/persistence/createPersistenceAdapter.ts"
|
|
130
|
+
},
|
|
131
|
+
"src/types/EventEmitter.ts": {
|
|
132
|
+
"file": "index.cjs13.js",
|
|
133
|
+
"name": "packages/base/core/src/types/EventEmitter",
|
|
134
|
+
"src": "src/types/EventEmitter.ts"
|
|
135
|
+
},
|
|
136
|
+
"src/utils/createSignal.ts": {
|
|
137
|
+
"file": "index.cjs17.js",
|
|
138
|
+
"name": "packages/base/core/src/utils/createSignal",
|
|
139
|
+
"src": "src/utils/createSignal.ts"
|
|
140
|
+
},
|
|
141
|
+
"src/utils/deepClone.ts": {
|
|
142
|
+
"file": "index.cjs15.js",
|
|
143
|
+
"name": "packages/base/core/src/utils/deepClone",
|
|
144
|
+
"src": "src/utils/deepClone.ts"
|
|
145
|
+
},
|
|
146
|
+
"src/utils/get.ts": {
|
|
147
|
+
"file": "index.cjs26.js",
|
|
148
|
+
"name": "packages/base/core/src/utils/get",
|
|
149
|
+
"src": "src/utils/get.ts"
|
|
150
|
+
},
|
|
151
|
+
"src/utils/getMatchingKeys.ts": {
|
|
152
|
+
"file": "index.cjs27.js",
|
|
153
|
+
"name": "packages/base/core/src/utils/getMatchingKeys",
|
|
154
|
+
"src": "src/utils/getMatchingKeys.ts",
|
|
155
|
+
"imports": [
|
|
156
|
+
"src/utils/isFieldExpression.ts",
|
|
157
|
+
"src/utils/serializeValue.ts"
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
"src/utils/intersection.ts": {
|
|
161
|
+
"file": "index.cjs25.js",
|
|
162
|
+
"name": "packages/base/core/src/utils/intersection",
|
|
163
|
+
"src": "src/utils/intersection.ts"
|
|
164
|
+
},
|
|
165
|
+
"src/utils/isEqual.ts": {
|
|
166
|
+
"file": "index.cjs9.js",
|
|
167
|
+
"name": "packages/base/core/src/utils/isEqual",
|
|
168
|
+
"src": "src/utils/isEqual.ts"
|
|
169
|
+
},
|
|
170
|
+
"src/utils/isFieldExpression.ts": {
|
|
171
|
+
"file": "index.cjs28.js",
|
|
172
|
+
"name": "packages/base/core/src/utils/isFieldExpression",
|
|
173
|
+
"src": "src/utils/isFieldExpression.ts"
|
|
174
|
+
},
|
|
175
|
+
"src/utils/match.ts": {
|
|
176
|
+
"file": "index.cjs14.js",
|
|
177
|
+
"name": "packages/base/core/src/utils/match",
|
|
178
|
+
"src": "src/utils/match.ts"
|
|
179
|
+
},
|
|
180
|
+
"src/utils/modify.ts": {
|
|
181
|
+
"file": "index.cjs10.js",
|
|
182
|
+
"name": "packages/base/core/src/utils/modify",
|
|
183
|
+
"src": "src/utils/modify.ts"
|
|
184
|
+
},
|
|
185
|
+
"src/utils/project.ts": {
|
|
186
|
+
"file": "index.cjs22.js",
|
|
187
|
+
"name": "packages/base/core/src/utils/project",
|
|
188
|
+
"src": "src/utils/project.ts",
|
|
189
|
+
"imports": [
|
|
190
|
+
"src/utils/get.ts",
|
|
191
|
+
"src/utils/set.ts"
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"src/utils/randomId.ts": {
|
|
195
|
+
"file": "index.cjs11.js",
|
|
196
|
+
"name": "packages/base/core/src/utils/randomId",
|
|
197
|
+
"src": "src/utils/randomId.ts"
|
|
198
|
+
},
|
|
199
|
+
"src/utils/serializeValue.ts": {
|
|
200
|
+
"file": "index.cjs16.js",
|
|
201
|
+
"name": "packages/base/core/src/utils/serializeValue",
|
|
202
|
+
"src": "src/utils/serializeValue.ts"
|
|
203
|
+
},
|
|
204
|
+
"src/utils/set.ts": {
|
|
205
|
+
"file": "index.cjs29.js",
|
|
206
|
+
"name": "packages/base/core/src/utils/set",
|
|
207
|
+
"src": "src/utils/set.ts"
|
|
208
|
+
},
|
|
209
|
+
"src/utils/sortItems.ts": {
|
|
210
|
+
"file": "index.cjs21.js",
|
|
211
|
+
"name": "packages/base/core/src/utils/sortItems",
|
|
212
|
+
"src": "src/utils/sortItems.ts",
|
|
213
|
+
"imports": [
|
|
214
|
+
"src/utils/get.ts"
|
|
215
|
+
]
|
|
216
|
+
},
|
|
217
|
+
"src/utils/uniqueBy.ts": {
|
|
218
|
+
"file": "index.cjs30.js",
|
|
219
|
+
"name": "packages/base/core/src/utils/uniqueBy",
|
|
220
|
+
"src": "src/utils/uniqueBy.ts"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { BaseItem } from './Collection';
|
|
2
|
+
import type { ReplicatedCollectionOptions } from './ReplicatedCollection';
|
|
3
|
+
import ReplicatedCollection from './ReplicatedCollection';
|
|
4
|
+
import type Selector from './types/Selector';
|
|
5
|
+
interface AutoFetchOptions<T extends {
|
|
6
|
+
id: I;
|
|
7
|
+
} & Record<string, any>, I> {
|
|
8
|
+
fetchQueryItems: (selector: Selector<T>) => ReturnType<ReplicatedCollectionOptions<T, I>['pull']>;
|
|
9
|
+
purgeDelay?: number;
|
|
10
|
+
registerRemoteChange?: (onChange: () => Promise<void>) => Promise<void>;
|
|
11
|
+
mergeItems?: (itemA: T, itemB: T) => T;
|
|
12
|
+
}
|
|
13
|
+
export type AutoFetchCollectionOptions<T extends BaseItem<I>, I, U = T> = Omit<ReplicatedCollectionOptions<T, I, U>, 'pull' | 'registerRemoteChange'> & AutoFetchOptions<T, I>;
|
|
14
|
+
/**
|
|
15
|
+
* A special collection that automatically fetches items when they are needed.
|
|
16
|
+
*/
|
|
17
|
+
export default class AutoFetchCollection<T extends BaseItem<I> = BaseItem, I = any, U = T> extends ReplicatedCollection<T, I, U> {
|
|
18
|
+
private activeObservers;
|
|
19
|
+
private observerTimeouts;
|
|
20
|
+
private purgeDelay;
|
|
21
|
+
private idQueryCache;
|
|
22
|
+
private itemsCache;
|
|
23
|
+
private fetchQueryItems;
|
|
24
|
+
private triggerReload;
|
|
25
|
+
private reactivityAdapter;
|
|
26
|
+
private loadingSignals;
|
|
27
|
+
private isFetchingSignal;
|
|
28
|
+
private mergeItems;
|
|
29
|
+
/**
|
|
30
|
+
* @param options {Object} - Options for the collection.
|
|
31
|
+
* @param options.fetchQueryItems {Function} - A function that fetches items from the server. It takes the selector as an argument and returns a promise that resolves to an object with an `items` property.
|
|
32
|
+
* @param options.purgeDelay {Number} - The delay in milliseconds before purging an item from the cache.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options: AutoFetchCollectionOptions<T, I, U>);
|
|
35
|
+
/**
|
|
36
|
+
* Registers a query manually that items should be fetched for it
|
|
37
|
+
* @param selector {Object} Selector of the query
|
|
38
|
+
*/
|
|
39
|
+
registerQuery(selector: Selector<T>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Unregisters a query manually that items are not fetched anymore for it
|
|
42
|
+
* @param selector {Object} Selector of the query
|
|
43
|
+
*/
|
|
44
|
+
unregisterQuery(selector: Selector<T>): void;
|
|
45
|
+
private getKeyForSelector;
|
|
46
|
+
private forceRefetch;
|
|
47
|
+
private fetchSelector;
|
|
48
|
+
private handleObserverCreation;
|
|
49
|
+
private handleObserverDisposal;
|
|
50
|
+
private ensureSignal;
|
|
51
|
+
private setLoading;
|
|
52
|
+
/**
|
|
53
|
+
* Indicates wether a query is currently been loaded
|
|
54
|
+
* ⚡️ this function is reactive!
|
|
55
|
+
* @param selector {Object} Selector of the query
|
|
56
|
+
* @returns The loading state
|
|
57
|
+
*/
|
|
58
|
+
isLoading(selector?: Selector<T>): boolean;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type ReactivityAdapter from '../types/ReactivityAdapter';
|
|
2
|
+
import type { BaseItem, FindOptions, Transform } from './types';
|
|
3
|
+
import type { ObserveCallbacks } from './Observer';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the current scope is reactive, considering the provided reactivity adapter.
|
|
6
|
+
* @param reactivity - The reactivity adapter or a boolean indicating whether reactivity is enabled.
|
|
7
|
+
* @returns A boolean indicating if the current scope is reactive.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isInReactiveScope(reactivity: ReactivityAdapter | undefined | false): boolean;
|
|
10
|
+
export interface CursorOptions<T extends BaseItem, U = T> extends FindOptions<T> {
|
|
11
|
+
transform?: Transform<T, U>;
|
|
12
|
+
bindEvents?: (requery: () => void) => () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents a cursor for querying and observing a filtered, sorted, and transformed
|
|
16
|
+
* subset of items from a collection. Supports reactivity and field tracking.
|
|
17
|
+
* @template T - The type of the items in the collection.
|
|
18
|
+
* @template U - The transformed item type after applying transformations (default is T).
|
|
19
|
+
*/
|
|
20
|
+
export default class Cursor<T extends BaseItem, U = T> {
|
|
21
|
+
private observer;
|
|
22
|
+
private getFilteredItems;
|
|
23
|
+
private options;
|
|
24
|
+
private onCleanupCallbacks;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new instance of the `Cursor` class.
|
|
27
|
+
* Provides utilities for querying, observing, and transforming items from a collection.
|
|
28
|
+
* @template T - The type of the items in the collection.
|
|
29
|
+
* @template U - The transformed item type after applying transformations (default is T).
|
|
30
|
+
* @param getItems - A function that retrieves the filtered list of items.
|
|
31
|
+
* @param options - Optional configuration for the cursor.
|
|
32
|
+
* @param options.transform - A transformation function to apply to each item when retrieving them.
|
|
33
|
+
* @param options.bindEvents - A function to bind reactivity events for the cursor, which should return a cleanup function.
|
|
34
|
+
* @param options.fields - A projection object defining which fields of the item should be included or excluded.
|
|
35
|
+
* @param options.sort - A sort specifier to determine the order of the items.
|
|
36
|
+
* @param options.skip - The number of items to skip from the beginning of the result set.
|
|
37
|
+
* @param options.limit - The maximum number of items to return in the result set.
|
|
38
|
+
* @param options.reactive - A reactivity adapter to enable observing changes in the cursor's result set.
|
|
39
|
+
* @param options.fieldTracking - A boolean to enable fine-grained field tracking for reactivity.
|
|
40
|
+
*/
|
|
41
|
+
constructor(getItems: () => T[], options?: CursorOptions<T, U>);
|
|
42
|
+
private addGetters;
|
|
43
|
+
private transform;
|
|
44
|
+
private getItems;
|
|
45
|
+
private depend;
|
|
46
|
+
private ensureObserver;
|
|
47
|
+
private observeRawChanges;
|
|
48
|
+
/**
|
|
49
|
+
* Cleans up all resources associated with the cursor, such as reactive bindings
|
|
50
|
+
* and event listeners. This method should be called when the cursor is no longer needed
|
|
51
|
+
* to prevent memory leaks.
|
|
52
|
+
*/
|
|
53
|
+
cleanup(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Registers a cleanup callback to be executed when the `cleanup` method is called.
|
|
56
|
+
* Useful for managing resources and ensuring proper cleanup of bindings or listeners.
|
|
57
|
+
* @param callback - A function to be executed during cleanup.
|
|
58
|
+
*/
|
|
59
|
+
onCleanup(callback: () => void): void;
|
|
60
|
+
/**
|
|
61
|
+
* Iterates over each item in the cursor's result set, applying the provided callback
|
|
62
|
+
* function to each transformed item.
|
|
63
|
+
* ⚡️ this function is reactive!
|
|
64
|
+
* @param callback - A function to execute for each item in the result set.
|
|
65
|
+
* @param callback.item - The transformed item.
|
|
66
|
+
*/
|
|
67
|
+
forEach(callback: (item: U) => void): void;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a new array populated with the results of applying the provided callback
|
|
70
|
+
* function to each transformed item in the cursor's result set.
|
|
71
|
+
* ⚡️ this function is reactive!
|
|
72
|
+
* @template V - The type of the items in the resulting array.
|
|
73
|
+
* @param callback - A function to execute for each item in the result set.
|
|
74
|
+
* @param callback.item - The transformed item.
|
|
75
|
+
* @returns An array of results after applying the callback to each item.
|
|
76
|
+
*/
|
|
77
|
+
map<V>(callback: (item: U) => V): V[];
|
|
78
|
+
/**
|
|
79
|
+
* Fetches all transformed items from the cursor's result set as an array.
|
|
80
|
+
* Automatically applies filtering, sorting, and limiting as per the cursor's options.
|
|
81
|
+
* ⚡️ this function is reactive!
|
|
82
|
+
* @returns An array of transformed items in the result set.
|
|
83
|
+
*/
|
|
84
|
+
fetch(): U[];
|
|
85
|
+
/**
|
|
86
|
+
* Counts the total number of items in the cursor's result set after applying
|
|
87
|
+
* filtering and other criteria.
|
|
88
|
+
* ⚡️ this function is reactive!
|
|
89
|
+
* @returns The total number of items in the result set.
|
|
90
|
+
*/
|
|
91
|
+
count(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Observes changes to the cursor's result set and triggers the specified callbacks
|
|
94
|
+
* when items are added, removed, or updated. Supports reactivity and transformation.
|
|
95
|
+
* @param callbacks - An object containing the callback functions to handle different change events.
|
|
96
|
+
* @param callbacks.added - Triggered when an item is added to the result set.
|
|
97
|
+
* @param callbacks.removed - Triggered when an item is removed from the result set.
|
|
98
|
+
* @param callbacks.changed - Triggered when an item in the result set is modified.
|
|
99
|
+
* @param callbacks.addedBefore - Triggered when an item is added before another item in the result set.
|
|
100
|
+
* @param callbacks.movedBefore - Triggered when an item is moved before another item in the result set.
|
|
101
|
+
* @param callbacks.changedField - Triggered when a specific field of an item changes.
|
|
102
|
+
* @param skipInitial - A boolean indicating whether to skip the initial notification of the current result set.
|
|
103
|
+
* @returns A function to stop observing changes.
|
|
104
|
+
*/
|
|
105
|
+
observeChanges(callbacks: ObserveCallbacks<U>, skipInitial?: boolean): () => void;
|
|
106
|
+
/**
|
|
107
|
+
* Forces the cursor to re-evaluate its result set by re-fetching items
|
|
108
|
+
* from the collection. This is useful when the underlying data or query
|
|
109
|
+
* criteria have changed, and you want to ensure the cursor reflects the latest state.
|
|
110
|
+
*/
|
|
111
|
+
requery(): void;
|
|
112
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
type AddedCallback<T> = (item: T) => void;
|
|
2
|
+
type AddedBeforeCallback<T> = (item: T, before: T) => void;
|
|
3
|
+
type ChangedCallback<T> = (item: T) => void;
|
|
4
|
+
type ChangedFieldCallback<T> = <Field extends keyof T>(item: T, field: Field, oldValue: T[Field], newValue: T[Field]) => void;
|
|
5
|
+
type MovedBeforeCallback<T> = (item: T, before: T) => void;
|
|
6
|
+
type RemovedCallback<T> = (item: T) => void;
|
|
7
|
+
export interface ObserveCallbacks<T> {
|
|
8
|
+
added?: AddedCallback<T>;
|
|
9
|
+
addedBefore?: AddedBeforeCallback<T>;
|
|
10
|
+
changed?: ChangedCallback<T>;
|
|
11
|
+
changedField?: ChangedFieldCallback<T>;
|
|
12
|
+
movedBefore?: MovedBeforeCallback<T>;
|
|
13
|
+
removed?: RemovedCallback<T>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Represents an observer that tracks changes in a collection of items and triggers
|
|
17
|
+
* callbacks for various events such as addition, removal, and modification of items.
|
|
18
|
+
* @template T - The type of the items being observed, which must include an `id` field.
|
|
19
|
+
*/
|
|
20
|
+
export default class Observer<T extends {
|
|
21
|
+
id: any;
|
|
22
|
+
}> {
|
|
23
|
+
private previousItems;
|
|
24
|
+
private callbacks;
|
|
25
|
+
private unbindEvents;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new instance of the `Observer` class.
|
|
28
|
+
* Sets up event bindings and initializes the callbacks for tracking changes in a collection.
|
|
29
|
+
* @param bindEvents - A function to bind external events to the observer. Must return a cleanup function to unbind those events.
|
|
30
|
+
*/
|
|
31
|
+
constructor(bindEvents: () => () => void);
|
|
32
|
+
private call;
|
|
33
|
+
private hasCallbacks;
|
|
34
|
+
/**
|
|
35
|
+
* Determines if the observer has no active callbacks registered for any events.
|
|
36
|
+
* @returns A boolean indicating whether the observer is empty (i.e., no callbacks are registered).
|
|
37
|
+
*/
|
|
38
|
+
isEmpty(): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Compares the previous state of items with the new state and triggers the appropriate callbacks
|
|
41
|
+
* for events such as added, removed, changed, or moved items.
|
|
42
|
+
* @param newItems - The new list of items to compare against the previous state.
|
|
43
|
+
*/
|
|
44
|
+
runChecks(newItems: T[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Stops the observer by unbinding all events and cleaning up resources.
|
|
47
|
+
*/
|
|
48
|
+
stop(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Registers callbacks for specific events to observe changes in the collection.
|
|
51
|
+
* @param callbacks - An object containing the callbacks for various events (e.g., 'added', 'removed').
|
|
52
|
+
* @param skipInitial - A boolean indicating whether to skip invoking the callbacks for the initial state of the collection.
|
|
53
|
+
*/
|
|
54
|
+
addCallbacks(callbacks: ObserveCallbacks<T>, skipInitial?: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* Removes the specified callbacks for specific events, unregistering them from the observer.
|
|
57
|
+
* @param callbacks - An object containing the callbacks to be removed for various events.
|
|
58
|
+
*/
|
|
59
|
+
removeCallbacks(callbacks: ObserveCallbacks<T>): void;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type IndexProvider from '../types/IndexProvider';
|
|
2
|
+
import type { BaseItem } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* creates an index for a specific field but uses an external map to store the index
|
|
5
|
+
* @param field name of the field
|
|
6
|
+
* @param index the external map to use for the index
|
|
7
|
+
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
8
|
+
*/
|
|
9
|
+
export declare function createExternalIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string, index: Map<string, Set<number>>): IndexProvider<T, I>;
|
|
10
|
+
/**
|
|
11
|
+
* creates an index for a specific field
|
|
12
|
+
* @param field name of the field
|
|
13
|
+
* @returns an index provider to pass to the `indices` option of the collection constructor
|
|
14
|
+
*/
|
|
15
|
+
export default function createIndex<T extends BaseItem<I> = BaseItem, I = any>(field: string): IndexProvider<T, I>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type IndexProvider from '../types/IndexProvider';
|
|
2
|
+
import type { FlatSelector } from '../types/Selector';
|
|
3
|
+
import type Selector from '../types/Selector';
|
|
4
|
+
import type { BaseItem } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves merged index information for a given flat selector by querying multiple
|
|
7
|
+
* index providers. Combines results from all index providers to determine matched positions
|
|
8
|
+
* and an optimized selector.
|
|
9
|
+
* @template T - The type of the items in the collection.
|
|
10
|
+
* @template I - The type of the unique identifier for the items.
|
|
11
|
+
* @param indexProviders - An array of index providers to query.
|
|
12
|
+
* @param selector - The flat selector used to filter items.
|
|
13
|
+
* @returns An object containing:
|
|
14
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
15
|
+
* - `positions`: An array of matched item positions.
|
|
16
|
+
* - `optimizedSelector`: A flat selector optimized based on the index results.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getMergedIndexInfo<T extends BaseItem<I> = BaseItem, I = any>(indexProviders: IndexProvider<T, I>[], selector: FlatSelector<T>): {
|
|
19
|
+
matched: boolean;
|
|
20
|
+
positions: number[];
|
|
21
|
+
optimizedSelector: FlatSelector<T>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves index information for a given complex selector by querying multiple
|
|
25
|
+
* index providers. Handles nested `$and` and `$or` conditions in the selector and
|
|
26
|
+
* optimizes the selector to minimize processing overhead.
|
|
27
|
+
* @template T - The type of the items in the collection.
|
|
28
|
+
* @template I - The type of the unique identifier for the items.
|
|
29
|
+
* @param indexProviders - An array of index providers to query.
|
|
30
|
+
* @param selector - The complex selector used to filter items.
|
|
31
|
+
* @returns An object containing:
|
|
32
|
+
* - `matched`: A boolean indicating if the selector matched any items.
|
|
33
|
+
* - `positions`: An array of matched item positions.
|
|
34
|
+
* - `optimizedSelector`: A selector optimized based on the index results, with unused
|
|
35
|
+
* conditions removed.
|
|
36
|
+
*/
|
|
37
|
+
export default function getIndexInfo<T extends BaseItem<I> = BaseItem, I = any>(indexProviders: IndexProvider<T, I>[], selector: Selector<T>): {
|
|
38
|
+
matched: boolean;
|
|
39
|
+
positions: number[];
|
|
40
|
+
optimizedSelector: Selector<T>;
|
|
41
|
+
};
|