@aprovan/patchwork-compiler 0.1.2-dev.99f9769 → 0.1.2-dev.9c336a0
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/index.cjs +35 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +34 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -676,6 +676,8 @@ declare class IndexedDBBackend implements FSProvider {
|
|
|
676
676
|
|
|
677
677
|
interface HttpBackendConfig {
|
|
678
678
|
baseUrl: string;
|
|
679
|
+
/** How often to poll for external changes, in milliseconds. Default: 7000. */
|
|
680
|
+
pollIntervalMs?: number;
|
|
679
681
|
}
|
|
680
682
|
/**
|
|
681
683
|
* HTTP-based FSProvider for connecting to remote VFS servers
|
|
@@ -695,8 +697,8 @@ declare class HttpBackend implements FSProvider {
|
|
|
695
697
|
recursive?: boolean;
|
|
696
698
|
}): Promise<void>;
|
|
697
699
|
exists(path: string): Promise<boolean>;
|
|
698
|
-
watch(
|
|
699
|
-
private
|
|
700
|
+
watch(_path: string, callback: WatchCallback): () => void;
|
|
701
|
+
private startPoll;
|
|
700
702
|
private url;
|
|
701
703
|
}
|
|
702
704
|
|
package/dist/index.d.ts
CHANGED
|
@@ -676,6 +676,8 @@ declare class IndexedDBBackend implements FSProvider {
|
|
|
676
676
|
|
|
677
677
|
interface HttpBackendConfig {
|
|
678
678
|
baseUrl: string;
|
|
679
|
+
/** How often to poll for external changes, in milliseconds. Default: 7000. */
|
|
680
|
+
pollIntervalMs?: number;
|
|
679
681
|
}
|
|
680
682
|
/**
|
|
681
683
|
* HTTP-based FSProvider for connecting to remote VFS servers
|
|
@@ -695,8 +697,8 @@ declare class HttpBackend implements FSProvider {
|
|
|
695
697
|
recursive?: boolean;
|
|
696
698
|
}): Promise<void>;
|
|
697
699
|
exists(path: string): Promise<boolean>;
|
|
698
|
-
watch(
|
|
699
|
-
private
|
|
700
|
+
watch(_path: string, callback: WatchCallback): () => void;
|
|
701
|
+
private startPoll;
|
|
700
702
|
private url;
|
|
701
703
|
}
|
|
702
704
|
|
package/dist/index.js
CHANGED
|
@@ -2483,37 +2483,46 @@ var HttpBackend = class {
|
|
|
2483
2483
|
const res = await fetch(this.url(path), { method: "HEAD" });
|
|
2484
2484
|
return res.ok;
|
|
2485
2485
|
}
|
|
2486
|
-
watch(
|
|
2486
|
+
watch(_path, callback) {
|
|
2487
2487
|
const controller = new AbortController();
|
|
2488
|
-
this.
|
|
2488
|
+
this.startPoll(callback, controller.signal);
|
|
2489
2489
|
return () => controller.abort();
|
|
2490
2490
|
}
|
|
2491
|
-
async
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
if (
|
|
2497
|
-
const
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
const
|
|
2504
|
-
|
|
2505
|
-
for (const line of lines) {
|
|
2506
|
-
if (line.startsWith("data: ")) {
|
|
2507
|
-
try {
|
|
2508
|
-
const event = JSON.parse(line.slice(6));
|
|
2509
|
-
callback(event.type, event.path);
|
|
2510
|
-
} catch {
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2491
|
+
async startPoll(callback, signal) {
|
|
2492
|
+
const intervalMs = this.config.pollIntervalMs ?? 7e3;
|
|
2493
|
+
let since = (/* @__PURE__ */ new Date()).toISOString();
|
|
2494
|
+
const poll = async () => {
|
|
2495
|
+
if (signal.aborted) return;
|
|
2496
|
+
if (typeof document !== "undefined" && document.visibilityState !== "visible") return;
|
|
2497
|
+
const pollStart = (/* @__PURE__ */ new Date()).toISOString();
|
|
2498
|
+
try {
|
|
2499
|
+
const res = await fetch(this.url("", { since }), { signal });
|
|
2500
|
+
if (!res.ok) return;
|
|
2501
|
+
const changes = await res.json();
|
|
2502
|
+
since = pollStart;
|
|
2503
|
+
for (const change of changes) {
|
|
2504
|
+
callback("update", change.path);
|
|
2513
2505
|
}
|
|
2506
|
+
} catch {
|
|
2514
2507
|
}
|
|
2515
|
-
}
|
|
2508
|
+
};
|
|
2509
|
+
await poll();
|
|
2510
|
+
if (signal.aborted) return;
|
|
2511
|
+
const timer = setInterval(() => void poll(), intervalMs);
|
|
2512
|
+
const onVisibilityChange = () => {
|
|
2513
|
+
if (typeof document !== "undefined" && document.visibilityState === "visible") {
|
|
2514
|
+
void poll();
|
|
2515
|
+
}
|
|
2516
|
+
};
|
|
2517
|
+
if (typeof document !== "undefined") {
|
|
2518
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
2516
2519
|
}
|
|
2520
|
+
signal.addEventListener("abort", () => {
|
|
2521
|
+
clearInterval(timer);
|
|
2522
|
+
if (typeof document !== "undefined") {
|
|
2523
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2517
2526
|
}
|
|
2518
2527
|
url(path, params) {
|
|
2519
2528
|
const baseUrl = this.config.baseUrl.replace(/\/+$/, "");
|