dirsql 0.4.95 → 0.4.97
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/dirsql.d.ts +4 -0
- package/dist/dirsql.js +41 -10
- package/docs/reference/sdk.md +1 -1
- package/package.json +6 -6
package/dist/dirsql.d.ts
CHANGED
|
@@ -145,6 +145,8 @@ export declare class DirSQL {
|
|
|
145
145
|
*/
|
|
146
146
|
get ready(): Promise<void>;
|
|
147
147
|
private _inner;
|
|
148
|
+
private readonly _watchStreams;
|
|
149
|
+
private _watchPoll?;
|
|
148
150
|
readonly _options: DirSQLOptions;
|
|
149
151
|
/** Construct from a `.dirsql.toml` config-file path. */
|
|
150
152
|
constructor(configPath: string);
|
|
@@ -208,6 +210,8 @@ export declare class DirSQL {
|
|
|
208
210
|
* Awaits the initial scan on first iteration, starts the underlying
|
|
209
211
|
* watcher, then awaits a bounded native poll each cycle. The iterator
|
|
210
212
|
* runs indefinitely; break out of the `for await` loop to stop.
|
|
213
|
+
* Each stream receives every event observed after its creation, even
|
|
214
|
+
* while another stream is consuming events on the same instance.
|
|
211
215
|
*/
|
|
212
216
|
watch(): AsyncGenerator<RowEvent, void, unknown>;
|
|
213
217
|
/**
|
package/dist/dirsql.js
CHANGED
|
@@ -47,6 +47,8 @@ export class DirSQL {
|
|
|
47
47
|
}
|
|
48
48
|
// Initialized by `ready`. Do NOT touch before awaiting `ready`.
|
|
49
49
|
_inner;
|
|
50
|
+
_watchStreams = new Set();
|
|
51
|
+
_watchPoll;
|
|
50
52
|
// Constructor options preserved verbatim; public-by-design.
|
|
51
53
|
_options;
|
|
52
54
|
constructor(arg) {
|
|
@@ -159,18 +161,47 @@ export class DirSQL {
|
|
|
159
161
|
* Awaits the initial scan on first iteration, starts the underlying
|
|
160
162
|
* watcher, then awaits a bounded native poll each cycle. The iterator
|
|
161
163
|
* runs indefinitely; break out of the `for await` loop to stop.
|
|
164
|
+
* Each stream receives every event observed after its creation, even
|
|
165
|
+
* while another stream is consuming events on the same instance.
|
|
162
166
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
watch() {
|
|
168
|
+
const buffer = [];
|
|
169
|
+
const reference = new WeakRef(buffer);
|
|
170
|
+
this._watchStreams.add(reference);
|
|
171
|
+
const owner = this;
|
|
172
|
+
return (async function* () {
|
|
173
|
+
try {
|
|
174
|
+
await owner.ready;
|
|
175
|
+
await owner._inner.startWatcher();
|
|
176
|
+
while (true) {
|
|
177
|
+
while (buffer.length === 0) {
|
|
178
|
+
owner._watchPoll ??= owner._inner
|
|
179
|
+
.pollEvents(200)
|
|
180
|
+
.then((events) => {
|
|
181
|
+
for (const reference of owner._watchStreams) {
|
|
182
|
+
const stream = reference.deref();
|
|
183
|
+
if (stream) {
|
|
184
|
+
for (const event of events) {
|
|
185
|
+
stream.push(event);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
owner._watchStreams.delete(reference);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.finally(() => {
|
|
194
|
+
owner._watchPoll = undefined;
|
|
195
|
+
});
|
|
196
|
+
await owner._watchPoll;
|
|
197
|
+
}
|
|
198
|
+
yield buffer.shift();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
owner._watchStreams.delete(reference);
|
|
172
203
|
}
|
|
173
|
-
}
|
|
204
|
+
})();
|
|
174
205
|
}
|
|
175
206
|
/**
|
|
176
207
|
* Explicitly close the database connection. Used primarily for cleanup or
|
package/docs/reference/sdk.md
CHANGED
|
@@ -301,7 +301,7 @@ under the root. The watcher starts on first iteration (Python/TypeScript)
|
|
|
301
301
|
or at the `watch()` call (Rust). The stream never terminates on its own;
|
|
302
302
|
stop consuming it to stop.
|
|
303
303
|
|
|
304
|
-
Python: each `watch()` call returns an independent stream, and every stream
|
|
304
|
+
Python/TypeScript: each `watch()` call returns an independent stream, and every stream
|
|
305
305
|
on one instance receives every event observed after it was created, so
|
|
306
306
|
several consumers (one per client, say) can share one instance.
|
|
307
307
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dirsql",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.97",
|
|
4
4
|
"description": "Ephemeral SQL index over a local directory",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/thekevinscott/dirsql",
|
|
@@ -221,10 +221,10 @@
|
|
|
221
221
|
]
|
|
222
222
|
},
|
|
223
223
|
"optionalDependencies": {
|
|
224
|
-
"@dirsql/lib-linux-x64-gnu": "0.4.
|
|
225
|
-
"@dirsql/lib-linux-arm64-gnu": "0.4.
|
|
226
|
-
"@dirsql/lib-darwin-x64": "0.4.
|
|
227
|
-
"@dirsql/lib-darwin-arm64": "0.4.
|
|
228
|
-
"@dirsql/lib-win32-x64-msvc": "0.4.
|
|
224
|
+
"@dirsql/lib-linux-x64-gnu": "0.4.97",
|
|
225
|
+
"@dirsql/lib-linux-arm64-gnu": "0.4.97",
|
|
226
|
+
"@dirsql/lib-darwin-x64": "0.4.97",
|
|
227
|
+
"@dirsql/lib-darwin-arm64": "0.4.97",
|
|
228
|
+
"@dirsql/lib-win32-x64-msvc": "0.4.97"
|
|
229
229
|
}
|
|
230
230
|
}
|