@absolutejs/sync 1.9.0 → 1.9.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/engine/cdc.d.ts +2 -2
- package/dist/engine/index.js +69 -59
- package/dist/engine/index.js.map +3 -3
- package/dist/index.js +71 -63
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/engine/cdc.d.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* `error` SSE event so the client knows to resubscribe (vs silently
|
|
21
21
|
* dropping commits).
|
|
22
22
|
*/
|
|
23
|
-
import { Elysia } from 'elysia';
|
|
23
|
+
import type { Elysia as ElysiaType } from 'elysia';
|
|
24
24
|
import { type SyncEngine } from './syncEngine';
|
|
25
25
|
export type SyncCdcOptions = {
|
|
26
26
|
/** The engine whose change log this route streams. */
|
|
@@ -32,7 +32,7 @@ export type SyncCdcOptions = {
|
|
|
32
32
|
/** Per-stream in-flight buffer cap. Passed to {@link SyncEngine.streamChanges}. Default 10000. */
|
|
33
33
|
maxBuffer?: number;
|
|
34
34
|
};
|
|
35
|
-
export declare const syncCdc: ({ engine, path, heartbeatMs, maxBuffer }: SyncCdcOptions) =>
|
|
35
|
+
export declare const syncCdc: ({ engine, path, heartbeatMs, maxBuffer }: SyncCdcOptions) => ElysiaType<"", {
|
|
36
36
|
decorator: {};
|
|
37
37
|
store: {};
|
|
38
38
|
derive: {};
|
package/dist/engine/index.js
CHANGED
|
@@ -2702,7 +2702,14 @@ var createSyncEngine = (options = {}) => {
|
|
|
2702
2702
|
return engine;
|
|
2703
2703
|
};
|
|
2704
2704
|
// src/engine/cdc.ts
|
|
2705
|
-
|
|
2705
|
+
var cachedElysia;
|
|
2706
|
+
var loadElysia = () => {
|
|
2707
|
+
if (cachedElysia !== undefined)
|
|
2708
|
+
return cachedElysia;
|
|
2709
|
+
const mod = __require("elysia");
|
|
2710
|
+
cachedElysia = mod.Elysia;
|
|
2711
|
+
return cachedElysia;
|
|
2712
|
+
};
|
|
2706
2713
|
var parseSince = (query2, lastEventId) => {
|
|
2707
2714
|
const raw = query2.since ?? lastEventId ?? "0";
|
|
2708
2715
|
const parsed = Number(raw);
|
|
@@ -2724,68 +2731,71 @@ var syncCdc = ({
|
|
|
2724
2731
|
path = "/sync/cdc",
|
|
2725
2732
|
heartbeatMs = 25000,
|
|
2726
2733
|
maxBuffer = 1e4
|
|
2727
|
-
}) =>
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2734
|
+
}) => {
|
|
2735
|
+
const Elysia = loadElysia();
|
|
2736
|
+
return new Elysia({ name: "@absolutejs/sync/cdc" }).get(path, (context) => {
|
|
2737
|
+
const lastEventId = context.request.headers.get("last-event-id");
|
|
2738
|
+
const since = parseSince(context.query, lastEventId);
|
|
2739
|
+
const encoder = new TextEncoder;
|
|
2740
|
+
const stream = new ReadableStream({
|
|
2741
|
+
async start(controller) {
|
|
2742
|
+
const write = (chunk) => {
|
|
2743
|
+
try {
|
|
2744
|
+
controller.enqueue(encoder.encode(chunk));
|
|
2745
|
+
} catch {}
|
|
2746
|
+
};
|
|
2747
|
+
write(encodeEvent("open", null, {
|
|
2748
|
+
since,
|
|
2749
|
+
at: Date.now()
|
|
2750
|
+
}));
|
|
2751
|
+
const heartbeat = setInterval(() => write(`: ping
|
|
2743
2752
|
|
|
2744
2753
|
`), heartbeatMs);
|
|
2745
|
-
try {
|
|
2746
|
-
for await (const entry of engine.streamChanges({
|
|
2747
|
-
since,
|
|
2748
|
-
signal: context.request.signal,
|
|
2749
|
-
maxBuffer
|
|
2750
|
-
})) {
|
|
2751
|
-
write(encodeEvent("change", entry.version, entry));
|
|
2752
|
-
}
|
|
2753
|
-
} catch (error) {
|
|
2754
|
-
if (error instanceof MissedChangesError) {
|
|
2755
|
-
write(encodeEvent("error", null, {
|
|
2756
|
-
name: "MissedChangesError",
|
|
2757
|
-
message: error.message,
|
|
2758
|
-
requestedSince: error.requestedSince,
|
|
2759
|
-
availableSince: error.availableSince
|
|
2760
|
-
}));
|
|
2761
|
-
} else if (error instanceof CdcConsumerSlowError) {
|
|
2762
|
-
write(encodeEvent("error", null, {
|
|
2763
|
-
name: "CdcConsumerSlowError",
|
|
2764
|
-
message: error.message,
|
|
2765
|
-
lastDeliveredVersion: error.lastDeliveredVersion
|
|
2766
|
-
}));
|
|
2767
|
-
} else {
|
|
2768
|
-
write(encodeEvent("error", null, {
|
|
2769
|
-
name: error instanceof Error ? error.name : "Error",
|
|
2770
|
-
message: error instanceof Error ? error.message : String(error)
|
|
2771
|
-
}));
|
|
2772
|
-
}
|
|
2773
|
-
} finally {
|
|
2774
|
-
clearInterval(heartbeat);
|
|
2775
2754
|
try {
|
|
2776
|
-
|
|
2777
|
-
|
|
2755
|
+
for await (const entry of engine.streamChanges({
|
|
2756
|
+
since,
|
|
2757
|
+
signal: context.request.signal,
|
|
2758
|
+
maxBuffer
|
|
2759
|
+
})) {
|
|
2760
|
+
write(encodeEvent("change", entry.version, entry));
|
|
2761
|
+
}
|
|
2762
|
+
} catch (error) {
|
|
2763
|
+
if (error instanceof MissedChangesError) {
|
|
2764
|
+
write(encodeEvent("error", null, {
|
|
2765
|
+
name: "MissedChangesError",
|
|
2766
|
+
message: error.message,
|
|
2767
|
+
requestedSince: error.requestedSince,
|
|
2768
|
+
availableSince: error.availableSince
|
|
2769
|
+
}));
|
|
2770
|
+
} else if (error instanceof CdcConsumerSlowError) {
|
|
2771
|
+
write(encodeEvent("error", null, {
|
|
2772
|
+
name: "CdcConsumerSlowError",
|
|
2773
|
+
message: error.message,
|
|
2774
|
+
lastDeliveredVersion: error.lastDeliveredVersion
|
|
2775
|
+
}));
|
|
2776
|
+
} else {
|
|
2777
|
+
write(encodeEvent("error", null, {
|
|
2778
|
+
name: error instanceof Error ? error.name : "Error",
|
|
2779
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2780
|
+
}));
|
|
2781
|
+
}
|
|
2782
|
+
} finally {
|
|
2783
|
+
clearInterval(heartbeat);
|
|
2784
|
+
try {
|
|
2785
|
+
controller.close();
|
|
2786
|
+
} catch {}
|
|
2787
|
+
}
|
|
2778
2788
|
}
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
}
|
|
2789
|
+
});
|
|
2790
|
+
return new Response(stream, {
|
|
2791
|
+
headers: {
|
|
2792
|
+
"cache-control": "no-cache, no-transform",
|
|
2793
|
+
connection: "keep-alive",
|
|
2794
|
+
"content-type": "text/event-stream"
|
|
2795
|
+
}
|
|
2796
|
+
});
|
|
2787
2797
|
});
|
|
2788
|
-
}
|
|
2798
|
+
};
|
|
2789
2799
|
// src/engine/schema.ts
|
|
2790
2800
|
var defineSchema = (schemas) => schemas;
|
|
2791
2801
|
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
@@ -3081,5 +3091,5 @@ export {
|
|
|
3081
3091
|
CdcConsumerSlowError
|
|
3082
3092
|
};
|
|
3083
3093
|
|
|
3084
|
-
//# debugId=
|
|
3094
|
+
//# debugId=5962FD669C5BC3D964756E2164756E21
|
|
3085
3095
|
//# sourceMappingURL=index.js.map
|