@streamsy/core 0.11.0 → 0.12.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 +3 -3
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +3 -3
- package/dist/{http-wFQusDU7.js → http-YoA8cUTN.js} +12 -2
- package/dist/{index-B_o4-vX4.d.ts → index-ooCOjS7N.d.ts} +92 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +24 -4
- package/dist/internal/index.d.ts +7 -3
- package/dist/internal/index.js +3 -2
- package/dist/{layer-CwD1bD5X.js → layer-Bf40J6so.js} +9 -64
- package/dist/{layer-DZOWeK0B.js → layer-DjKTdIY5.js} +3 -2
- package/dist/marks-B-fXqEYG.js +195 -0
- package/dist/{program-B6L8HGca.js → program-BlfAJNlD.js} +78 -2
- package/dist/{projection-marks-Ca0Q-L9H.d.ts → projection-marks-CzlDS-kj.d.ts} +49 -12
- package/dist/protocol/index.d.ts +2 -2
- package/dist/protocol/index.js +2 -2
- package/dist/read-offsets-CQ4VkAs8.js +11 -0
- package/dist/remote/index.d.ts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +356 -12
- package/package.json +1 -1
- package/dist/projection-marks-RqurLPLA.js +0 -24
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Array, Context, Effect, Option, Order } from "effect";
|
|
2
|
+
// src/internal/owner-records.ts
|
|
3
|
+
var OwnerRecords = class extends Context.Service()("@streamsy/core/internal/OwnerRecords") {};
|
|
4
|
+
// src/internal/commit-hooks.ts
|
|
5
|
+
var CommitHooks = class extends Context.Service()("@streamsy/core/internal/CommitHooks") {};
|
|
6
|
+
/** Shared registry for storage boundaries: register in a scope, run in order. */
|
|
7
|
+
const commitHookRegistry = () => {
|
|
8
|
+
const hooks = /* @__PURE__ */ new Set();
|
|
9
|
+
const beforeCommit = (hook) => Effect.acquireRelease(Effect.sync(() => {
|
|
10
|
+
const entry = { hook };
|
|
11
|
+
hooks.add(entry);
|
|
12
|
+
return entry;
|
|
13
|
+
}), (entry) => Effect.sync(() => {
|
|
14
|
+
hooks.delete(entry);
|
|
15
|
+
})).pipe(Effect.asVoid);
|
|
16
|
+
const run = (ids) => ids.size === 0 || hooks.size === 0 ? Effect.void : Effect.forEach([...hooks], (entry) => entry.hook(ids), { discard: true });
|
|
17
|
+
return {
|
|
18
|
+
beforeCommit,
|
|
19
|
+
run
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
// src/internal/projection-marks.ts
|
|
23
|
+
var ProjectionMarks = class extends Context.Service()("@streamsy/core/internal/ProjectionMarks") {};
|
|
24
|
+
// src/storage/memory/marks.ts
|
|
25
|
+
/** A private transaction draft of the marks. */
|
|
26
|
+
const copyMarks = (marks) => new Map(Array.map([...marks], ([projection, rows]) => [projection, new Map(rows)]));
|
|
27
|
+
const rowsOf = (marks, projection) => {
|
|
28
|
+
const found = marks.get(projection);
|
|
29
|
+
if (found !== void 0) return found;
|
|
30
|
+
const rows = /* @__PURE__ */ new Map();
|
|
31
|
+
marks.set(projection, rows);
|
|
32
|
+
return rows;
|
|
33
|
+
};
|
|
34
|
+
const byDue = Order.mapInput(Order.Tuple([Order.Number, Order.String]), (mark) => [mark.dueAt, mark.params]);
|
|
35
|
+
const mark = (marks, projection, params) => {
|
|
36
|
+
const rows = rowsOf(marks, projection);
|
|
37
|
+
for (const value of params) {
|
|
38
|
+
const found = rows.get(value);
|
|
39
|
+
rows.set(value, found === void 0 ? {
|
|
40
|
+
params: value,
|
|
41
|
+
seq: 1,
|
|
42
|
+
attempts: 0,
|
|
43
|
+
dueAt: 0,
|
|
44
|
+
stopped: false,
|
|
45
|
+
wakeAt: Option.none(),
|
|
46
|
+
failure: Option.none()
|
|
47
|
+
} : {
|
|
48
|
+
...found,
|
|
49
|
+
seq: found.seq + 1,
|
|
50
|
+
dueAt: Option.isSome(found.wakeAt) ? 0 : found.dueAt,
|
|
51
|
+
wakeAt: Option.none()
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const nextDue = (marks, projection) => {
|
|
56
|
+
let earliest;
|
|
57
|
+
for (const row of marks.get(projection)?.values() ?? []) if (!row.stopped) earliest = earliest === void 0 ? row.dueAt : Math.min(earliest, row.dueAt);
|
|
58
|
+
return Option.fromUndefinedOr(earliest);
|
|
59
|
+
};
|
|
60
|
+
const due = (marks, projection, now, limit) => Array.sort(Array.filter([...marks.get(projection)?.values() ?? []], (row) => !row.stopped && row.dueAt <= now), byDue).slice(0, limit);
|
|
61
|
+
const read = (marks, projection, params) => {
|
|
62
|
+
const rows = marks.get(projection);
|
|
63
|
+
const found = /* @__PURE__ */ new Map();
|
|
64
|
+
for (const value of params) {
|
|
65
|
+
const row = rows?.get(value);
|
|
66
|
+
if (row !== void 0) found.set(value, row);
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
};
|
|
70
|
+
const clear = (marks, projection, params, seq) => {
|
|
71
|
+
const rows = marks.get(projection);
|
|
72
|
+
const row = rows?.get(params);
|
|
73
|
+
if (rows === void 0 || row === void 0) return;
|
|
74
|
+
if (row.seq === seq) rows.delete(params);
|
|
75
|
+
else rows.set(params, {
|
|
76
|
+
...row,
|
|
77
|
+
attempts: 0,
|
|
78
|
+
dueAt: 0,
|
|
79
|
+
stopped: false,
|
|
80
|
+
wakeAt: Option.none(),
|
|
81
|
+
failure: Option.none()
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
/** Sleep only the seq that ran; a concurrent write must run before it can sleep. */
|
|
85
|
+
const sleep = (marks, projection, params, seq, wakeAt) => {
|
|
86
|
+
const rows = rowsOf(marks, projection);
|
|
87
|
+
const row = rows.get(params);
|
|
88
|
+
const matching = row === void 0 || row.seq === seq;
|
|
89
|
+
rows.set(params, {
|
|
90
|
+
params,
|
|
91
|
+
seq: row?.seq ?? 1,
|
|
92
|
+
attempts: 0,
|
|
93
|
+
dueAt: matching ? wakeAt : 0,
|
|
94
|
+
wakeAt: matching ? Option.some(wakeAt) : Option.none(),
|
|
95
|
+
stopped: false,
|
|
96
|
+
failure: Option.none()
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const remove = (marks, projection, params) => {
|
|
100
|
+
marks.get(projection)?.delete(params);
|
|
101
|
+
};
|
|
102
|
+
const fail = (marks, projection, params, options) => {
|
|
103
|
+
const rows = rowsOf(marks, projection);
|
|
104
|
+
const found = rows.get(params);
|
|
105
|
+
rows.set(params, {
|
|
106
|
+
params,
|
|
107
|
+
seq: found?.seq ?? 1,
|
|
108
|
+
attempts: options.attempts,
|
|
109
|
+
dueAt: Option.getOrElse(options.dueAt, () => 0),
|
|
110
|
+
stopped: Option.isNone(options.dueAt),
|
|
111
|
+
wakeAt: Option.none(),
|
|
112
|
+
failure: Option.some({
|
|
113
|
+
...options.failure,
|
|
114
|
+
message: options.failure.message.slice(0, 1e3)
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const failed = (marks, projection, limit) => Array.sort(Array.filter([...marks.get(projection)?.values() ?? []], (row) => row.attempts > 0), Order.combine(Order.mapInput(Order.Boolean, (row) => !row.stopped), byDue)).slice(0, limit);
|
|
119
|
+
const resume = (marks, projection) => {
|
|
120
|
+
let changed = 0;
|
|
121
|
+
const rows = marks.get(projection);
|
|
122
|
+
if (rows === void 0) return 0;
|
|
123
|
+
for (const [key, row] of rows) {
|
|
124
|
+
if (!row.stopped) continue;
|
|
125
|
+
rows.set(key, {
|
|
126
|
+
...row,
|
|
127
|
+
dueAt: 0,
|
|
128
|
+
stopped: false
|
|
129
|
+
});
|
|
130
|
+
changed += 1;
|
|
131
|
+
}
|
|
132
|
+
return changed;
|
|
133
|
+
};
|
|
134
|
+
const retry = (marks, projection, params) => {
|
|
135
|
+
let changed = 0;
|
|
136
|
+
const rows = marks.get(projection);
|
|
137
|
+
if (rows === void 0) return 0;
|
|
138
|
+
for (const [key, row] of rows) {
|
|
139
|
+
if (!row.stopped && (row.attempts === 0 || row.dueAt === 0) || params !== void 0 && key !== params) continue;
|
|
140
|
+
rows.set(key, {
|
|
141
|
+
...row,
|
|
142
|
+
dueAt: 0,
|
|
143
|
+
stopped: false
|
|
144
|
+
});
|
|
145
|
+
changed += 1;
|
|
146
|
+
}
|
|
147
|
+
return changed;
|
|
148
|
+
};
|
|
149
|
+
/** Classify each row once; a failed row at `now` is due, not backing off. */
|
|
150
|
+
const summary = (marks, projection, now) => {
|
|
151
|
+
let fresh = 0;
|
|
152
|
+
let sleeping = 0;
|
|
153
|
+
let retryDue = 0;
|
|
154
|
+
let backingOff = 0;
|
|
155
|
+
let stopped = 0;
|
|
156
|
+
let earliest;
|
|
157
|
+
for (const row of marks.get(projection)?.values() ?? []) {
|
|
158
|
+
if (row.stopped) {
|
|
159
|
+
stopped += 1;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (Option.isSome(row.wakeAt)) sleeping += 1;
|
|
163
|
+
else if (row.attempts === 0) fresh += 1;
|
|
164
|
+
else if (row.dueAt <= now) retryDue += 1;
|
|
165
|
+
else backingOff += 1;
|
|
166
|
+
earliest = earliest === void 0 ? row.dueAt : Math.min(earliest, row.dueAt);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
fresh,
|
|
170
|
+
sleeping,
|
|
171
|
+
retryDue,
|
|
172
|
+
backingOff,
|
|
173
|
+
stopped,
|
|
174
|
+
nextDueAt: Option.fromUndefinedOr(earliest)
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
/** A new private marks store. Each operation runs synchronously when its Effect executes. */
|
|
178
|
+
const memoryProjectionMarks = () => {
|
|
179
|
+
const table = /* @__PURE__ */ new Map();
|
|
180
|
+
return {
|
|
181
|
+
mark: (projection, params) => Effect.sync(() => mark(table, projection, params)),
|
|
182
|
+
nextDue: (projection) => Effect.sync(() => nextDue(table, projection)),
|
|
183
|
+
summary: (projection, now) => Effect.sync(() => summary(table, projection, now)),
|
|
184
|
+
due: (projection, now, limit) => Effect.sync(() => due(table, projection, now, limit)),
|
|
185
|
+
read: (projection, params) => Effect.sync(() => read(table, projection, params)),
|
|
186
|
+
clear: (projection, params, seq) => Effect.sync(() => clear(table, projection, params, seq)),
|
|
187
|
+
sleep: (projection, params, seq, wakeAt) => Effect.sync(() => sleep(table, projection, params, seq, wakeAt)),
|
|
188
|
+
remove: (projection, params) => Effect.sync(() => remove(table, projection, params)),
|
|
189
|
+
fail: (projection, params, options) => Effect.sync(() => fail(table, projection, params, options)),
|
|
190
|
+
retry: (projection, params) => Effect.sync(() => retry(table, projection, params)),
|
|
191
|
+
resume: (projection) => Effect.sync(() => resume(table, projection)),
|
|
192
|
+
failed: (projection, limit) => Effect.sync(() => failed(table, projection, limit))
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
export { commitHookRegistry as _, failed as a, nextDue as c, resume as d, retry as f, CommitHooks as g, ProjectionMarks as h, fail as i, read as l, summary as m, copyMarks as n, mark as o, sleep as p, due as r, memoryProjectionMarks as s, clear as t, remove as u, OwnerRecords as v };
|
|
@@ -403,7 +403,7 @@ const readQueryParser = (isValidOffset) => ({ parse(url) {
|
|
|
403
403
|
const offset = url.searchParams.get("offset") ?? void 0;
|
|
404
404
|
const liveParam = url.searchParams.get("live");
|
|
405
405
|
const cursor = url.searchParams.get("cursor") ?? void 0;
|
|
406
|
-
const live = liveParam === "long-poll" || liveParam === "sse" ? liveParam : void 0;
|
|
406
|
+
const live = liveParam === "long-poll" || liveParam === "sse" || liveParam === "websocket" ? liveParam : void 0;
|
|
407
407
|
if (offset !== void 0 && offset !== "-1" && offset !== "now" && !isValidOffset(offset)) return {
|
|
408
408
|
ok: false,
|
|
409
409
|
response: new Response("Invalid offset format", { status: 400 })
|
|
@@ -550,6 +550,81 @@ const makeShutdownSignal = Effect.gen(function* () {
|
|
|
550
550
|
});
|
|
551
551
|
/** A fresh signal. Provide it to the routes and call `drain` before they close. */
|
|
552
552
|
const layerShutdownSignal = Layer.effect(ShutdownSignal, makeShutdownSignal);
|
|
553
|
+
// src/http/live-frames.ts
|
|
554
|
+
/**
|
|
555
|
+
* Frames of `live=websocket`, a Streamsy extension to Durable Streams HTTP.
|
|
556
|
+
*
|
|
557
|
+
* The server sends one `open` text frame, then a binary `data` frame and a
|
|
558
|
+
* `control` text frame for each batch. A `data` frame holds the exact body of
|
|
559
|
+
* a catch-up `GET` for the batch. A `control` frame has the fields of an SSE
|
|
560
|
+
* control event, and a client moves its offset only on `control`.
|
|
561
|
+
*/
|
|
562
|
+
const LIVE_SOCKET_PROTOCOL = "streamsy-live.v1";
|
|
563
|
+
/** The only client message. The runtime answers it without running the server. */
|
|
564
|
+
const LIVE_PING = "ping";
|
|
565
|
+
const LIVE_PONG = "pong";
|
|
566
|
+
/** The close codes of `streamsy-live.v1`. */
|
|
567
|
+
const LiveCloseCode = {
|
|
568
|
+
/** The stream closed. A `control` frame with `streamClosed` came first. */
|
|
569
|
+
StreamClosed: 1e3,
|
|
570
|
+
InternalError: 1011,
|
|
571
|
+
/** The server restarted or cannot read the socket's state. Reconnect at once. */
|
|
572
|
+
Restart: 1012,
|
|
573
|
+
/** The socket fell behind the byte cap. Read over HTTP, then reconnect. */
|
|
574
|
+
CatchUpRequired: 4100,
|
|
575
|
+
BadMessage: 4400,
|
|
576
|
+
NotFound: 4404,
|
|
577
|
+
Gone: 4410
|
|
578
|
+
};
|
|
579
|
+
/** The browser socket API hides response headers, so `open` carries the content type. */
|
|
580
|
+
function openFrame(contentType, streamNextOffset) {
|
|
581
|
+
return JSON.stringify({
|
|
582
|
+
type: "open",
|
|
583
|
+
protocol: LIVE_SOCKET_PROTOCOL,
|
|
584
|
+
contentType,
|
|
585
|
+
streamNextOffset
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
/** The SSE control rules: no cursor on a closed stream, `upToDate` only while open. */
|
|
589
|
+
function controlFrame(batch) {
|
|
590
|
+
const frame = batch.closed ? {
|
|
591
|
+
type: "control",
|
|
592
|
+
streamNextOffset: batch.nextOffset,
|
|
593
|
+
streamClosed: true
|
|
594
|
+
} : {
|
|
595
|
+
type: "control",
|
|
596
|
+
streamNextOffset: batch.nextOffset,
|
|
597
|
+
streamCursor: batch.cursor
|
|
598
|
+
};
|
|
599
|
+
if (!batch.closed && batch.upToDate) frame.upToDate = true;
|
|
600
|
+
return JSON.stringify(frame);
|
|
601
|
+
}
|
|
602
|
+
/** The cursor a long-poll response would carry after `previous`. */
|
|
603
|
+
const nextCursor = Effect.fn("Http.nextCursor")(function* (previous) {
|
|
604
|
+
const now = yield* Clock.currentTimeMillis;
|
|
605
|
+
const random = yield* Random.next;
|
|
606
|
+
return generateCursor({ now: () => now }, previous, () => random);
|
|
607
|
+
});
|
|
608
|
+
/** The close code for a read that failed with an HTTP status. */
|
|
609
|
+
function closeCodeForStatus(status) {
|
|
610
|
+
if (status === 404) return LiveCloseCode.NotFound;
|
|
611
|
+
if (status === 410) return LiveCloseCode.Gone;
|
|
612
|
+
return LiveCloseCode.InternalError;
|
|
613
|
+
}
|
|
614
|
+
/** A `GET` that asks for `live=websocket` with an `Upgrade: websocket` header. */
|
|
615
|
+
function isLiveUpgrade(request) {
|
|
616
|
+
return request.method === "GET" && request.headers.get("upgrade")?.toLowerCase() === "websocket" && new URL(request.url).searchParams.get("live") === "websocket";
|
|
617
|
+
}
|
|
618
|
+
/** The answer to `live=websocket` from a host or request that cannot upgrade. Clients fall back to long-poll. */
|
|
619
|
+
function upgradeRequired() {
|
|
620
|
+
return new Response("WebSocket upgrade required", {
|
|
621
|
+
status: 426,
|
|
622
|
+
headers: {
|
|
623
|
+
upgrade: "websocket",
|
|
624
|
+
"cache-control": "no-store"
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
}
|
|
553
628
|
// src/http/read.ts
|
|
554
629
|
const responses$2 = responses_exports;
|
|
555
630
|
const bodyCodec = message_body_codec_exports;
|
|
@@ -601,6 +676,7 @@ const read$1 = Effect.fn("Http.read")(function* (reader, id, url, requestHeaders
|
|
|
601
676
|
return new Response(bodyCodec.emptyBodyForContentType(result.contentType), { headers });
|
|
602
677
|
}
|
|
603
678
|
if (query.live && !offset) return responses$2.badRequest("offset required for live modes");
|
|
679
|
+
if (query.live === "websocket") return upgradeRequired();
|
|
604
680
|
const signal = yield* Effect.serviceOption(ShutdownSignal);
|
|
605
681
|
if (query.live === "sse" && offset) {
|
|
606
682
|
const meta = yield* reader.head(id);
|
|
@@ -795,4 +871,4 @@ function app(options = {}) {
|
|
|
795
871
|
return HttpServerResponse.setHeaders(result, securityHeaders);
|
|
796
872
|
}));
|
|
797
873
|
}
|
|
798
|
-
export {
|
|
874
|
+
export { discardRequestBody as _, LIVE_PING as a, LiveCloseCode as c, isLiveUpgrade as d, nextCursor as f, layerShutdownSignal as g, ShutdownSignal as h, requestUrl as i, closeCodeForStatus as l, upgradeRequired as m, checkReadOptions as n, LIVE_PONG as o, openFrame as p, read as r, LIVE_SOCKET_PROTOCOL as s, app as t, controlFrame as u, streamPath as v, securityHeaders as y };
|
|
@@ -1139,7 +1139,13 @@ declare const commitHookRegistry: () => {
|
|
|
1139
1139
|
beforeCommit: (hook: CommitHook) => Effect.Effect<void, never, Scope.Scope>;
|
|
1140
1140
|
run: (ids: ReadonlySet<StreamId>) => Effect.Effect<void, SqlError.SqlError>;
|
|
1141
1141
|
};
|
|
1142
|
-
/**
|
|
1142
|
+
/** Last failed run, retained through marks, retries and resumes. Messages hold at most 1,000 characters. */
|
|
1143
|
+
interface MarkFailure {
|
|
1144
|
+
readonly at: number;
|
|
1145
|
+
readonly reason: Option.Option<string>;
|
|
1146
|
+
readonly message: string;
|
|
1147
|
+
}
|
|
1148
|
+
/** One pending mark: a binding with input work, a retry, or a recorded wake. */
|
|
1143
1149
|
interface PendingMark {
|
|
1144
1150
|
/** The binding's canonical params, as `canonicalParams` encodes them. */
|
|
1145
1151
|
readonly params: string;
|
|
@@ -1147,11 +1153,26 @@ interface PendingMark {
|
|
|
1147
1153
|
readonly seq: number;
|
|
1148
1154
|
/** Failed runs since the last success. A mark keeps it. */
|
|
1149
1155
|
readonly attempts: number;
|
|
1150
|
-
/** Epoch ms. 0 means due now. */
|
|
1156
|
+
/** Epoch ms. 0 means due now; ignored while stopped. */
|
|
1151
1157
|
readonly dueAt: number;
|
|
1158
|
+
/** Recorded wake; when set, equals dueAt and the row has no failure or attempts. */
|
|
1159
|
+
readonly wakeAt: Option.Option<number>;
|
|
1160
|
+
/** Waits until retry or resume. A mark preserves the stop. */
|
|
1161
|
+
readonly stopped: boolean;
|
|
1162
|
+
readonly failure: Option.Option<MarkFailure>;
|
|
1163
|
+
}
|
|
1164
|
+
/** Disjoint counts of one projection's marks at the supplied time. */
|
|
1165
|
+
interface ProjectionMarkSummary {
|
|
1166
|
+
readonly fresh: number;
|
|
1167
|
+
readonly sleeping: number;
|
|
1168
|
+
readonly retryDue: number;
|
|
1169
|
+
readonly backingOff: number;
|
|
1170
|
+
readonly stopped: number;
|
|
1171
|
+
/** Earliest due time across non-stopped marks, including fresh and sleeping marks. */
|
|
1172
|
+
readonly nextDueAt: Option.Option<number>;
|
|
1152
1173
|
}
|
|
1153
1174
|
/**
|
|
1154
|
-
*
|
|
1175
|
+
* Pending marks for attached projections, on a storage owner or in private memory.
|
|
1155
1176
|
*
|
|
1156
1177
|
* A mark is keyed by projection id and canonical params. Version and generation
|
|
1157
1178
|
* are left out, so a deploy that raises the version picks up the old marks.
|
|
@@ -1159,26 +1180,42 @@ interface PendingMark {
|
|
|
1159
1180
|
interface ProjectionMarksApi {
|
|
1160
1181
|
/**
|
|
1161
1182
|
* Insert a mark for each binding, or raise its `seq`. A raise keeps
|
|
1162
|
-
* `attempts` and `
|
|
1183
|
+
* `attempts`, `stopped` and `failure`, so a write never resets backoff or a stop.
|
|
1184
|
+
* A sleeping row becomes due now and loses its wake index.
|
|
1163
1185
|
* Call it inside a commit hook. It joins the transaction and fails like the
|
|
1164
1186
|
* transaction's own statements.
|
|
1165
1187
|
*/
|
|
1166
1188
|
readonly mark: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<void, SqlError.SqlError>;
|
|
1167
|
-
/** The earliest `dueAt` of the projection's marks. */
|
|
1189
|
+
/** The earliest `dueAt` of the projection's non-stopped marks. */
|
|
1168
1190
|
readonly nextDue: (projection: string) => Effect.Effect<Option.Option<number>, StorageFault>;
|
|
1169
|
-
/**
|
|
1191
|
+
/** Five disjoint counts: fresh, sleeping, retry due, backing off and stopped. */
|
|
1192
|
+
readonly summary: (projection: string, now: number) => Effect.Effect<ProjectionMarkSummary, StorageFault>;
|
|
1193
|
+
/** Up to `limit` non-stopped marks with `dueAt <= now`, earliest first. */
|
|
1170
1194
|
readonly due: (projection: string, now: number, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
|
|
1171
1195
|
/** The marks of these bindings that exist, keyed by params. */
|
|
1172
1196
|
readonly read: (projection: string, params: ReadonlyArray<string>) => Effect.Effect<ReadonlyMap<string, PendingMark>, StorageFault>;
|
|
1173
|
-
/** Delete
|
|
1197
|
+
/** Delete on a matching `seq`; otherwise keep the row and reset its failure, attempts, dueAt, wakeAt and stop. */
|
|
1174
1198
|
readonly clear: (projection: string, params: string, seq: number) => Effect.Effect<void, StorageFault>;
|
|
1199
|
+
/** Keep a matching row asleep at wakeAt and reset failure state. A seq mismatch
|
|
1200
|
+
* becomes fresh and due now. An absent row is inserted asleep with seq 1. */
|
|
1201
|
+
readonly sleep: (projection: string, params: string, seq: number, wakeAt: number) => Effect.Effect<void, StorageFault>;
|
|
1175
1202
|
/** Delete the mark whatever its `seq`. */
|
|
1176
1203
|
readonly remove: (projection: string, params: string) => Effect.Effect<void, StorageFault>;
|
|
1177
|
-
/**
|
|
1178
|
-
readonly
|
|
1179
|
-
|
|
1180
|
-
|
|
1204
|
+
/** Insert or update a failure, preserving seq. Some(dueAt) backs off; None stops. */
|
|
1205
|
+
readonly fail: (projection: string, params: string, options: {
|
|
1206
|
+
readonly attempts: number;
|
|
1207
|
+
readonly failure: MarkFailure;
|
|
1208
|
+
readonly dueAt: Option.Option<number>;
|
|
1209
|
+
}) => Effect.Effect<void, StorageFault>;
|
|
1210
|
+
/** Set failed or stopped marks due now and clear their stop, preserving attempts, seq and failure.
|
|
1211
|
+
* Optionally select one binding. Returns the number changed; already due, non-stopped marks are unchanged.
|
|
1212
|
+
*/
|
|
1213
|
+
readonly retry: (projection: string, params?: string) => Effect.Effect<number, StorageFault>;
|
|
1214
|
+
/** Make stopped marks due now, preserving attempts, seq and failure. Returns the number changed. */
|
|
1215
|
+
readonly resume: (projection: string) => Effect.Effect<number, StorageFault>;
|
|
1216
|
+
/** Up to limit marks with attempts > 0, stopped first, then by dueAt and params. */
|
|
1217
|
+
readonly failed: (projection: string, limit: number) => Effect.Effect<ReadonlyArray<PendingMark>, StorageFault>;
|
|
1181
1218
|
}
|
|
1182
1219
|
declare const ProjectionMarks_base: Context.ServiceClass<ProjectionMarks, "@streamsy/core/internal/ProjectionMarks", ProjectionMarksApi>;
|
|
1183
1220
|
declare class ProjectionMarks extends ProjectionMarks_base {}
|
|
1184
|
-
export {
|
|
1221
|
+
export { ReadNextError as $, HeadResult as A, isStreamsFault as At, CreateError as B, StorageCapabilities as C, StreamRecord as Ct, Writer as D, StreamsFault as Dt, StreamsWriter as E, StorageFault as Et, AppendConflict as F, InvalidEpochSeq as G, HeadError as H, AppendError as I, NotSupported as J, InvalidForkRequest as K, AppendErrorFor as L, ReadNextResult as M, ReadResult as N, AppendResult as O, TransportFault as Ot, AppendBaseError as P, ReadError as Q, CreateConflict as R, ProducerPrecondition as S, StreamLifecycle as St, StreamsReader as T, EncodeFault as Tt, InvalidAppendRequest as U, ForkSourceNotFound as V, InvalidCreateRequest as W, ProducerGap as X, OffsetMismatch as Y, ProtocolError as Z, Mutations as _, ProducerState as _t, ProjectionMarksApi as a, StreamNotFound as at, OperationResults as b, StreamConfig as bt, CommitHooksApi as c, AppendOptions as ct, OwnerRecordsApi as d, ReadOptions as dt, RemoveError as et, Storage as f, CreateOptions as ft, MutationRejected as g, ProducerId as gt, MutationApplied as h, Offset as ht, ProjectionMarks as i, StreamGone as it, ReadMessage as j, CreateResult as k, isRetryableFault as kt, commitHookRegistry as l, ProducerOptions as lt, Mutation as m, MessageWindow as mt, PendingMark as n, StreamBusy as nt, CommitHook as o, isProtocolError as ot, StorageShape as p, ChangeSnapshot as pt, InvalidReadRequest as q, ProjectionMarkSummary as r, StreamClosed as rt, CommitHooks as s, AppendCallOptions as st, MarkFailure as t, StaleEpoch as tt, OwnerRecords as u, ReadNextOptions as ut, Operation as v, RecordPatch as vt, Reader as w, DecodeFault as wt, Operations as x, StreamId as xt, OperationResult as y, StoredMessage as yt, CreateConflictReason as z };
|
package/dist/protocol/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { D as Writer, E as StreamsWriter, T as StreamsReader, w as Reader } from "../projection-marks-CzlDS-kj.js";
|
|
2
|
+
import { $ as route_d_exports, J as layer_d_exports, V as streams_d_exports, w as RoutesOptions } from "../index-ooCOjS7N.js";
|
|
3
3
|
import { HttpRouter } from "effect/http";
|
|
4
4
|
/** Raw protocol route for adapters and wire conformance tests. */
|
|
5
5
|
export declare const routes: (options?: Omit<RoutesOptions, "access">) => import("effect/Layer").Layer<never, never, HttpRouter.HttpRouter | HttpRouter.Request<"Requires", StreamsReader> | HttpRouter.Request<"Requires", StreamsWriter>>;
|
package/dist/protocol/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { F as StreamsReader, I as StreamsWriter, l as streams_exports, u as route_exports } from "../streamsy-HKC10a_V.js";
|
|
2
|
-
import { n as layer_exports } from "../layer-
|
|
3
|
-
import { t as app } from "../program-
|
|
2
|
+
import { n as layer_exports } from "../layer-DjKTdIY5.js";
|
|
3
|
+
import { t as app } from "../program-BlfAJNlD.js";
|
|
4
4
|
import { HttpRouter } from "effect/http";
|
|
5
5
|
// src/protocol/routes.ts
|
|
6
6
|
/** Raw protocol route for adapters and wire conformance tests. */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/internal/read-offsets.ts
|
|
2
|
+
const Metadata = Symbol.for("@streamsy/core/internal/ReadOffsets");
|
|
3
|
+
const attachOffsets = (result, offsets) => Object.defineProperty(result, Metadata, {
|
|
4
|
+
value: offsets,
|
|
5
|
+
enumerable: false
|
|
6
|
+
});
|
|
7
|
+
const offsetsOf = (result) => {
|
|
8
|
+
if (!(Metadata in result)) return void 0;
|
|
9
|
+
return result[Metadata];
|
|
10
|
+
};
|
|
11
|
+
export { offsetsOf as n, attachOffsets as t };
|
package/dist/remote/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { E as StreamsWriter, Ot as TransportFault, T as StreamsReader } from "../projection-marks-CzlDS-kj.js";
|
|
2
|
+
import { D as Group, E as Any, O as Identifiers } from "../index-ooCOjS7N.js";
|
|
3
3
|
import { Layer } from "effect";
|
|
4
4
|
import { HttpClient, HttpClientRequest } from "effect/http";
|
|
5
5
|
interface Options {
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import {
|
|
1
|
+
import { C as StorageCapabilities, E as StreamsWriter, T as StreamsReader, f as Storage, pt as ChangeSnapshot, xt as StreamId } from "../projection-marks-CzlDS-kj.js";
|
|
2
|
+
import { K as MemoryOptions, q as ProtocolOptions } from "../index-ooCOjS7N.js";
|
|
3
3
|
import { Context, Effect, Layer } from "effect";
|
|
4
4
|
interface StorageContractOptions {
|
|
5
5
|
readonly name: string;
|