@s2-dev/streamstore 0.16.12 → 0.17.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/dist/cjs/basin.d.ts +6 -2
- package/dist/cjs/basin.d.ts.map +1 -1
- package/dist/cjs/basin.js +11 -5
- package/dist/cjs/basin.js.map +1 -1
- package/dist/cjs/batch-transform.d.ts +64 -0
- package/dist/cjs/batch-transform.d.ts.map +1 -0
- package/dist/cjs/batch-transform.js +144 -0
- package/dist/cjs/batch-transform.js.map +1 -0
- package/dist/cjs/generated/proto/s2.d.ts.map +1 -0
- package/dist/cjs/generated/proto/s2.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/stream/factory.d.ts +15 -0
- package/dist/cjs/lib/stream/factory.d.ts.map +1 -0
- package/dist/cjs/lib/stream/factory.js +36 -0
- package/dist/cjs/lib/stream/factory.js.map +1 -0
- package/dist/cjs/lib/stream/runtime.d.ts +13 -0
- package/dist/cjs/lib/stream/runtime.d.ts.map +1 -0
- package/dist/cjs/lib/stream/runtime.js +50 -0
- package/dist/cjs/lib/stream/runtime.js.map +1 -0
- package/dist/cjs/lib/stream/transport/fetch/index.d.ts +79 -0
- package/dist/cjs/lib/stream/transport/fetch/index.d.ts.map +1 -0
- package/dist/cjs/lib/stream/transport/fetch/index.js +382 -0
- package/dist/cjs/lib/stream/transport/fetch/index.js.map +1 -0
- package/dist/cjs/lib/stream/transport/fetch/shared.d.ts +7 -0
- package/dist/cjs/lib/stream/transport/fetch/shared.d.ts.map +1 -0
- package/dist/cjs/lib/stream/transport/fetch/shared.js +170 -0
- package/dist/cjs/lib/stream/transport/fetch/shared.js.map +1 -0
- package/dist/cjs/lib/stream/transport/s2s/framing.d.ts +47 -0
- package/dist/cjs/lib/stream/transport/s2s/framing.d.ts.map +1 -0
- package/dist/cjs/lib/stream/transport/s2s/framing.js +123 -0
- package/dist/cjs/lib/stream/transport/s2s/framing.js.map +1 -0
- package/dist/cjs/lib/stream/transport/s2s/index.d.ts +23 -0
- package/dist/cjs/lib/stream/transport/s2s/index.d.ts.map +1 -0
- package/dist/cjs/lib/stream/transport/s2s/index.js +785 -0
- package/dist/cjs/lib/stream/transport/s2s/index.js.map +1 -0
- package/dist/cjs/lib/stream/types.d.ts +53 -0
- package/dist/cjs/lib/stream/types.d.ts.map +1 -0
- package/dist/cjs/lib/stream/types.js +3 -0
- package/dist/cjs/lib/stream/types.js.map +1 -0
- package/dist/cjs/stream.d.ts +22 -116
- package/dist/cjs/stream.d.ts.map +1 -1
- package/dist/cjs/stream.js +35 -551
- package/dist/cjs/stream.js.map +1 -1
- package/dist/cjs/utils.d.ts +32 -6
- package/dist/cjs/utils.d.ts.map +1 -1
- package/dist/cjs/utils.js +129 -34
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/basin.d.ts +6 -2
- package/dist/esm/basin.d.ts.map +1 -1
- package/dist/esm/basin.js +11 -5
- package/dist/esm/basin.js.map +1 -1
- package/dist/esm/batch-transform.d.ts +64 -0
- package/dist/esm/batch-transform.d.ts.map +1 -0
- package/dist/esm/batch-transform.js +140 -0
- package/dist/esm/batch-transform.js.map +1 -0
- package/dist/esm/generated/proto/s2.d.ts.map +1 -0
- package/dist/esm/generated/proto/s2.js.map +1 -0
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/stream/factory.d.ts +15 -0
- package/dist/esm/lib/stream/factory.d.ts.map +1 -0
- package/dist/esm/lib/stream/factory.js +33 -0
- package/dist/esm/lib/stream/factory.js.map +1 -0
- package/dist/esm/lib/stream/runtime.d.ts +13 -0
- package/dist/esm/lib/stream/runtime.d.ts.map +1 -0
- package/dist/esm/lib/stream/runtime.js +46 -0
- package/dist/esm/lib/stream/runtime.js.map +1 -0
- package/dist/esm/lib/stream/transport/fetch/index.d.ts +79 -0
- package/dist/esm/lib/stream/transport/fetch/index.d.ts.map +1 -0
- package/dist/esm/lib/stream/transport/fetch/index.js +376 -0
- package/dist/esm/lib/stream/transport/fetch/index.js.map +1 -0
- package/dist/esm/lib/stream/transport/fetch/shared.d.ts +7 -0
- package/dist/esm/lib/stream/transport/fetch/shared.d.ts.map +1 -0
- package/dist/esm/lib/stream/transport/fetch/shared.js +166 -0
- package/dist/esm/lib/stream/transport/fetch/shared.js.map +1 -0
- package/dist/esm/lib/stream/transport/s2s/framing.d.ts +47 -0
- package/dist/esm/lib/stream/transport/s2s/framing.d.ts.map +1 -0
- package/dist/esm/lib/stream/transport/s2s/framing.js +118 -0
- package/dist/esm/lib/stream/transport/s2s/framing.js.map +1 -0
- package/dist/esm/lib/stream/transport/s2s/index.d.ts +23 -0
- package/dist/esm/lib/stream/transport/s2s/index.d.ts.map +1 -0
- package/dist/esm/lib/stream/transport/s2s/index.js +781 -0
- package/dist/esm/lib/stream/transport/s2s/index.js.map +1 -0
- package/dist/esm/lib/stream/types.d.ts +53 -0
- package/dist/esm/lib/stream/types.d.ts.map +1 -0
- package/dist/esm/lib/stream/types.js +2 -0
- package/dist/esm/lib/stream/types.js.map +1 -0
- package/dist/esm/stream.d.ts +22 -116
- package/dist/esm/stream.d.ts.map +1 -1
- package/dist/esm/stream.js +36 -551
- package/dist/esm/stream.js.map +1 -1
- package/dist/esm/utils.d.ts +32 -6
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js +126 -34
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/generated/proto/s2/v1/s2.d.ts.map +0 -1
- package/dist/cjs/generated/proto/s2/v1/s2.js.map +0 -1
- package/dist/esm/generated/proto/s2/v1/s2.d.ts.map +0 -1
- package/dist/esm/generated/proto/s2/v1/s2.js.map +0 -1
- /package/dist/cjs/generated/proto/{s2/v1/s2.d.ts → s2.d.ts} +0 -0
- /package/dist/cjs/generated/proto/{s2/v1/s2.js → s2.js} +0 -0
- /package/dist/esm/generated/proto/{s2/v1/s2.d.ts → s2.d.ts} +0 -0
- /package/dist/esm/generated/proto/{s2/v1/s2.js → s2.js} +0 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetchTransport = exports.FetchAppendSession = exports.FetchReadSession = void 0;
|
|
4
|
+
const error_js_1 = require("../../../../error.js");
|
|
5
|
+
const index_js_1 = require("../../../../generated/client/index.js");
|
|
6
|
+
const index_js_2 = require("../../../../generated/index.js");
|
|
7
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
8
|
+
const base64_js_1 = require("../../../base64.js");
|
|
9
|
+
const event_stream_js_1 = require("../../../event-stream.js");
|
|
10
|
+
const Redacted = require("../../../redacted.js");
|
|
11
|
+
const shared_js_1 = require("./shared.js");
|
|
12
|
+
class FetchReadSession extends event_stream_js_1.EventStream {
|
|
13
|
+
static async create(client, name, args, options) {
|
|
14
|
+
const { as, ...queryParams } = args ?? {};
|
|
15
|
+
const response = await (0, index_js_2.read)({
|
|
16
|
+
client,
|
|
17
|
+
path: {
|
|
18
|
+
stream: name,
|
|
19
|
+
},
|
|
20
|
+
headers: {
|
|
21
|
+
accept: "text/event-stream",
|
|
22
|
+
...(as === "bytes" ? { "s2-format": "base64" } : {}),
|
|
23
|
+
},
|
|
24
|
+
query: queryParams,
|
|
25
|
+
parseAs: "stream",
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
if (response.error) {
|
|
29
|
+
if ("message" in response.error) {
|
|
30
|
+
throw new error_js_1.S2Error({
|
|
31
|
+
message: response.error.message,
|
|
32
|
+
code: response.error.code ?? undefined,
|
|
33
|
+
status: response.response.status,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// special case for 416 - Range Not Satisfiable
|
|
38
|
+
throw new error_js_1.RangeNotSatisfiableError({
|
|
39
|
+
status: response.response.status,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!response.response.body) {
|
|
44
|
+
throw new error_js_1.S2Error({
|
|
45
|
+
message: "No body in SSE response",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const format = (args?.as ?? "string");
|
|
49
|
+
return new FetchReadSession(response.response.body, format);
|
|
50
|
+
}
|
|
51
|
+
_lastReadPosition = undefined;
|
|
52
|
+
constructor(stream, format) {
|
|
53
|
+
super(stream, (msg) => {
|
|
54
|
+
// Parse SSE events according to the S2 protocol
|
|
55
|
+
if (msg.event === "batch" && msg.data) {
|
|
56
|
+
const rawBatch = JSON.parse(msg.data);
|
|
57
|
+
const batch = (() => {
|
|
58
|
+
// If format is bytes, decode base64 to Uint8Array
|
|
59
|
+
if (format === "bytes") {
|
|
60
|
+
return {
|
|
61
|
+
...rawBatch,
|
|
62
|
+
records: rawBatch.records.map((record) => ({
|
|
63
|
+
...record,
|
|
64
|
+
body: record.body ? (0, base64_js_1.decodeFromBase64)(record.body) : undefined,
|
|
65
|
+
headers: record.headers?.map((header) => header.map((h) => (0, base64_js_1.decodeFromBase64)(h))),
|
|
66
|
+
})),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return {
|
|
71
|
+
...rawBatch,
|
|
72
|
+
records: rawBatch.records.map((record) => ({
|
|
73
|
+
...record,
|
|
74
|
+
headers: record.headers
|
|
75
|
+
? Object.fromEntries(record.headers)
|
|
76
|
+
: undefined,
|
|
77
|
+
})),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
})();
|
|
81
|
+
if (batch.tail) {
|
|
82
|
+
this._lastReadPosition = batch.tail;
|
|
83
|
+
}
|
|
84
|
+
return { done: false, batch: true, value: batch.records ?? [] };
|
|
85
|
+
}
|
|
86
|
+
if (msg.event === "error") {
|
|
87
|
+
// Handle error events
|
|
88
|
+
throw new error_js_1.S2Error({ message: msg.data ?? "Unknown error" });
|
|
89
|
+
}
|
|
90
|
+
// Skip ping events and other events
|
|
91
|
+
return { done: false };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
lastReadPosition() {
|
|
95
|
+
return this._lastReadPosition;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.FetchReadSession = FetchReadSession;
|
|
99
|
+
class AcksStream extends ReadableStream {
|
|
100
|
+
constructor(setController) {
|
|
101
|
+
super({
|
|
102
|
+
start: (controller) => {
|
|
103
|
+
setController(controller);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async [Symbol.asyncDispose]() {
|
|
108
|
+
await this.cancel("disposed");
|
|
109
|
+
}
|
|
110
|
+
// Polyfill for older browsers
|
|
111
|
+
[Symbol.asyncIterator]() {
|
|
112
|
+
const fn = ReadableStream.prototype[Symbol.asyncIterator];
|
|
113
|
+
if (typeof fn === "function")
|
|
114
|
+
return fn.call(this);
|
|
115
|
+
const reader = this.getReader();
|
|
116
|
+
return {
|
|
117
|
+
next: async () => {
|
|
118
|
+
const r = await reader.read();
|
|
119
|
+
if (r.done) {
|
|
120
|
+
reader.releaseLock();
|
|
121
|
+
return { done: true, value: undefined };
|
|
122
|
+
}
|
|
123
|
+
return { done: false, value: r.value };
|
|
124
|
+
},
|
|
125
|
+
throw: async (e) => {
|
|
126
|
+
await reader.cancel(e);
|
|
127
|
+
reader.releaseLock();
|
|
128
|
+
return { done: true, value: undefined };
|
|
129
|
+
},
|
|
130
|
+
return: async () => {
|
|
131
|
+
await reader.cancel("done");
|
|
132
|
+
reader.releaseLock();
|
|
133
|
+
return { done: true, value: undefined };
|
|
134
|
+
},
|
|
135
|
+
[Symbol.asyncIterator]() {
|
|
136
|
+
return this;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Session for appending records to a stream.
|
|
143
|
+
* Queues append requests and ensures only one is in-flight at a time.
|
|
144
|
+
*/
|
|
145
|
+
class FetchAppendSession {
|
|
146
|
+
_lastAckedPosition = undefined;
|
|
147
|
+
queue = [];
|
|
148
|
+
pendingResolvers = [];
|
|
149
|
+
inFlight = false;
|
|
150
|
+
options;
|
|
151
|
+
stream;
|
|
152
|
+
acksController;
|
|
153
|
+
_readable;
|
|
154
|
+
_writable;
|
|
155
|
+
closed = false;
|
|
156
|
+
processingPromise = null;
|
|
157
|
+
queuedBytes = 0;
|
|
158
|
+
maxQueuedBytes;
|
|
159
|
+
waitingForCapacity = [];
|
|
160
|
+
client;
|
|
161
|
+
readable;
|
|
162
|
+
writable;
|
|
163
|
+
static async create(stream, transportConfig, sessionOptions, requestOptions) {
|
|
164
|
+
return new FetchAppendSession(stream, transportConfig, sessionOptions, requestOptions);
|
|
165
|
+
}
|
|
166
|
+
constructor(stream, transportConfig, sessionOptions, requestOptions) {
|
|
167
|
+
this.options = requestOptions;
|
|
168
|
+
this.stream = stream;
|
|
169
|
+
this.maxQueuedBytes = sessionOptions?.maxQueuedBytes ?? 10 * 1024 * 1024; // 10 MiB default
|
|
170
|
+
this.client = (0, index_js_1.createClient)((0, index_js_1.createConfig)({
|
|
171
|
+
baseUrl: transportConfig.baseUrl,
|
|
172
|
+
auth: () => Redacted.value(transportConfig.accessToken),
|
|
173
|
+
}));
|
|
174
|
+
// Create the readable stream for acks
|
|
175
|
+
this._readable = new AcksStream((controller) => {
|
|
176
|
+
this.acksController = controller;
|
|
177
|
+
});
|
|
178
|
+
this.readable = this._readable;
|
|
179
|
+
// Create the writable stream
|
|
180
|
+
let writableController;
|
|
181
|
+
this._writable = new WritableStream({
|
|
182
|
+
start: (controller) => {
|
|
183
|
+
writableController = controller;
|
|
184
|
+
},
|
|
185
|
+
write: async (chunk) => {
|
|
186
|
+
// Calculate batch size
|
|
187
|
+
let batchMeteredSize = 0;
|
|
188
|
+
for (const record of chunk.records) {
|
|
189
|
+
batchMeteredSize += (0, utils_js_1.meteredSizeBytes)(record);
|
|
190
|
+
}
|
|
191
|
+
// Wait for capacity if needed
|
|
192
|
+
while (this.queuedBytes + batchMeteredSize > this.maxQueuedBytes &&
|
|
193
|
+
!this.closed) {
|
|
194
|
+
await new Promise((resolve) => {
|
|
195
|
+
this.waitingForCapacity.push(resolve);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Submit the batch
|
|
199
|
+
this.submit(chunk.records, {
|
|
200
|
+
fencing_token: chunk.fencing_token ?? undefined,
|
|
201
|
+
match_seq_num: chunk.match_seq_num ?? undefined,
|
|
202
|
+
}, batchMeteredSize);
|
|
203
|
+
},
|
|
204
|
+
close: async () => {
|
|
205
|
+
this.closed = true;
|
|
206
|
+
await this.waitForDrain();
|
|
207
|
+
},
|
|
208
|
+
abort: async (reason) => {
|
|
209
|
+
this.closed = true;
|
|
210
|
+
this.queue = [];
|
|
211
|
+
this.queuedBytes = 0;
|
|
212
|
+
// Reject all pending promises
|
|
213
|
+
const error = new error_js_1.S2Error({
|
|
214
|
+
message: `AppendSession was aborted: ${reason}`,
|
|
215
|
+
});
|
|
216
|
+
for (const resolver of this.pendingResolvers) {
|
|
217
|
+
resolver.reject(error);
|
|
218
|
+
}
|
|
219
|
+
this.pendingResolvers = [];
|
|
220
|
+
// Reject all waiting for capacity
|
|
221
|
+
for (const resolver of this.waitingForCapacity) {
|
|
222
|
+
resolver();
|
|
223
|
+
}
|
|
224
|
+
this.waitingForCapacity = [];
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
this.writable = this._writable;
|
|
228
|
+
}
|
|
229
|
+
async [Symbol.asyncDispose]() {
|
|
230
|
+
await this.close();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get a stream of acknowledgements for appends.
|
|
234
|
+
*/
|
|
235
|
+
acks() {
|
|
236
|
+
return this._readable;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Close the append session.
|
|
240
|
+
* Waits for all pending appends to complete before resolving.
|
|
241
|
+
*/
|
|
242
|
+
async close() {
|
|
243
|
+
await this.writable.close();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Submit an append request to the session.
|
|
247
|
+
* The request will be queued and sent when no other request is in-flight.
|
|
248
|
+
* Returns a promise that resolves when the append is acknowledged or rejects on error.
|
|
249
|
+
*/
|
|
250
|
+
submit(records, args, precalculatedSize) {
|
|
251
|
+
if (this.closed) {
|
|
252
|
+
return Promise.reject(new error_js_1.S2Error({ message: "AppendSession is closed" }));
|
|
253
|
+
}
|
|
254
|
+
const recordsArray = Array.isArray(records) ? records : [records];
|
|
255
|
+
// Validate batch size limits
|
|
256
|
+
if (recordsArray.length > 1000) {
|
|
257
|
+
return Promise.reject(new error_js_1.S2Error({
|
|
258
|
+
message: `Batch of ${recordsArray.length} exceeds maximum batch size of 1000 records`,
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
// Validate metered size (use precalculated if provided)
|
|
262
|
+
let batchMeteredSize = precalculatedSize ?? 0;
|
|
263
|
+
if (batchMeteredSize === 0) {
|
|
264
|
+
for (const record of recordsArray) {
|
|
265
|
+
batchMeteredSize += (0, utils_js_1.meteredSizeBytes)(record);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (batchMeteredSize > 1024 * 1024) {
|
|
269
|
+
return Promise.reject(new error_js_1.S2Error({
|
|
270
|
+
message: `Batch size ${batchMeteredSize} bytes exceeds maximum of 1 MiB (1048576 bytes)`,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
this.queue.push({
|
|
275
|
+
records: recordsArray,
|
|
276
|
+
fencing_token: args?.fencing_token,
|
|
277
|
+
match_seq_num: args?.match_seq_num,
|
|
278
|
+
meteredSize: batchMeteredSize,
|
|
279
|
+
});
|
|
280
|
+
this.queuedBytes += batchMeteredSize;
|
|
281
|
+
this.pendingResolvers.push({ resolve, reject });
|
|
282
|
+
// Start processing if not already running
|
|
283
|
+
if (!this.processingPromise) {
|
|
284
|
+
this.processingPromise = this.processLoop();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Main processing loop that sends queued requests one at a time.
|
|
290
|
+
*/
|
|
291
|
+
async processLoop() {
|
|
292
|
+
while (this.queue.length > 0) {
|
|
293
|
+
this.inFlight = true;
|
|
294
|
+
const args = this.queue.shift();
|
|
295
|
+
const resolver = this.pendingResolvers.shift();
|
|
296
|
+
try {
|
|
297
|
+
const ack = await (0, shared_js_1.streamAppend)(this.stream, this.client, args.records, {
|
|
298
|
+
fencing_token: args.fencing_token,
|
|
299
|
+
match_seq_num: args.match_seq_num,
|
|
300
|
+
}, this.options);
|
|
301
|
+
this._lastAckedPosition = ack;
|
|
302
|
+
// Emit ack to the acks stream if it exists
|
|
303
|
+
if (this.acksController) {
|
|
304
|
+
this.acksController.enqueue(ack);
|
|
305
|
+
}
|
|
306
|
+
// Resolve the promise for this request
|
|
307
|
+
resolver.resolve(ack);
|
|
308
|
+
// Release capacity and wake up waiting writers
|
|
309
|
+
this.queuedBytes -= args.meteredSize;
|
|
310
|
+
while (this.waitingForCapacity.length > 0) {
|
|
311
|
+
const waiter = this.waitingForCapacity.shift();
|
|
312
|
+
waiter();
|
|
313
|
+
// Only wake one at a time - let them check capacity again
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
this.inFlight = false;
|
|
319
|
+
this.processingPromise = null;
|
|
320
|
+
// Reject the promise for this request
|
|
321
|
+
resolver.reject(error);
|
|
322
|
+
// Reject all remaining pending promises
|
|
323
|
+
for (const pendingResolver of this.pendingResolvers) {
|
|
324
|
+
pendingResolver.reject(error);
|
|
325
|
+
}
|
|
326
|
+
this.pendingResolvers = [];
|
|
327
|
+
// Clear the queue and reset queued bytes
|
|
328
|
+
this.queue = [];
|
|
329
|
+
this.queuedBytes = 0;
|
|
330
|
+
// Wake up all waiting writers (they'll see the closed state or retry)
|
|
331
|
+
for (const waiter of this.waitingForCapacity) {
|
|
332
|
+
waiter();
|
|
333
|
+
}
|
|
334
|
+
this.waitingForCapacity = [];
|
|
335
|
+
// Do not rethrow here to avoid unhandled rejection; callers already received rejection
|
|
336
|
+
}
|
|
337
|
+
this.inFlight = false;
|
|
338
|
+
}
|
|
339
|
+
this.processingPromise = null;
|
|
340
|
+
}
|
|
341
|
+
async waitForDrain() {
|
|
342
|
+
// Wait for processing to complete
|
|
343
|
+
if (this.processingPromise) {
|
|
344
|
+
await this.processingPromise;
|
|
345
|
+
}
|
|
346
|
+
// Wait until queue is empty and nothing is in flight
|
|
347
|
+
while (this.queue.length > 0 || this.inFlight) {
|
|
348
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
349
|
+
}
|
|
350
|
+
// Close the acks stream if it exists
|
|
351
|
+
if (this.acksController) {
|
|
352
|
+
this.acksController.close();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
lastAckedPosition() {
|
|
356
|
+
return this._lastAckedPosition;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.FetchAppendSession = FetchAppendSession;
|
|
360
|
+
/**
|
|
361
|
+
* Fetch-based transport using HTTP/1.1 + JSON
|
|
362
|
+
* Works in all JavaScript environments (browser, Node.js, Deno, etc.)
|
|
363
|
+
*/
|
|
364
|
+
class FetchTransport {
|
|
365
|
+
client;
|
|
366
|
+
transportConfig;
|
|
367
|
+
constructor(config) {
|
|
368
|
+
this.client = (0, index_js_1.createClient)((0, index_js_1.createConfig)({
|
|
369
|
+
baseUrl: config.baseUrl,
|
|
370
|
+
auth: () => Redacted.value(config.accessToken),
|
|
371
|
+
}));
|
|
372
|
+
this.transportConfig = config;
|
|
373
|
+
}
|
|
374
|
+
async makeAppendSession(stream, sessionOptions, requestOptions) {
|
|
375
|
+
return FetchAppendSession.create(stream, this.transportConfig, sessionOptions, requestOptions);
|
|
376
|
+
}
|
|
377
|
+
async makeReadSession(stream, args, options) {
|
|
378
|
+
return FetchReadSession.create(this.client, stream, args, options);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
exports.FetchTransport = FetchTransport;
|
|
382
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/lib/stream/transport/fetch/index.ts"],"names":[],"mappings":";;;AACA,mDAAyE;AACzE,oEAI+C;AAM/C,6DAAsD;AACtD,mDAAwD;AACxD,kDAAsD;AACtD,8DAAuD;AACvD,iDAAiD;AAajD,2CAA2C;AAE3C,MAAa,gBAEX,SAAQ,6BAA+B;IACxC,MAAM,CAAC,KAAK,CAAC,MAAM,CAClB,MAAc,EACd,IAAY,EACZ,IAAuB,EACvB,OAA0B;QAE1B,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAI,EAAC;YAC3B,MAAM;YACN,IAAI,EAAE;gBACL,MAAM,EAAE,IAAI;aACZ;YACD,OAAO,EAAE;gBACR,MAAM,EAAE,mBAAmB;gBAC3B,GAAG,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpD;YACD,KAAK,EAAE,WAAW;YAClB,OAAO,EAAE,QAAQ;YACjB,GAAG,OAAO;SACV,CAAC,CAAC;QACH,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;YACpB,IAAI,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;gBACjC,MAAM,IAAI,kBAAO,CAAC;oBACjB,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO;oBAC/B,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS;oBACtC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CA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AAc,CAAC,KAAK,EAAE,CAAC;QAC7B,CAAC;IACF,CAAC;IAED,iBAAiB;QAChB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IAChC,CAAC;CACD;AAzSD,gDAySC;AAED;;;GAGG;AACH,MAAa,cAAc;IACT,MAAM,CAAS;IACf,eAAe,CAAkB;IAClD,YAAY,MAAuB;QAClC,IAAI,CAAC,MAAM,GAAG,IAAA,uBAAY,EACzB,IAAA,uBAAY,EAAC;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC;SAC9C,CAAC,CACF,CAAC;QACF,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,iBAAiB,CACtB,MAAc,EACd,cAAqC,EACrC,cAAiC;QAEjC,OAAO,kBAAkB,CAAC,MAAM,CAC/B,MAAM,EACN,IAAI,CAAC,eAAe,EACpB,cAAc,EACd,cAAc,CACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CACpB,MAAc,EACd,IAAuB,EACvB,OAA0B;QAE1B,OAAO,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACpE,CAAC;CACD;AAjCD,wCAiCC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { S2RequestOptions } from "../../../../common.js";
|
|
2
|
+
import type { Client } from "../../../../generated/client/index.js";
|
|
3
|
+
import { type AppendAck } from "../../../../generated/index.js";
|
|
4
|
+
import type { AppendArgs, AppendRecord, ReadArgs, ReadBatch } from "../../types.js";
|
|
5
|
+
export declare function streamRead<Format extends "string" | "bytes" = "string">(stream: string, client: Client, args?: ReadArgs<Format>, options?: S2RequestOptions): Promise<ReadBatch<Format>>;
|
|
6
|
+
export declare function streamAppend(stream: string, client: Client, records: AppendRecord | AppendRecord[], args?: Omit<AppendArgs, "records">, options?: S2RequestOptions): Promise<AppendAck>;
|
|
7
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/stream/transport/fetch/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EACN,KAAK,SAAS,EAUd,MAAM,gCAAgC,CAAC;AAMxC,OAAO,KAAK,EACX,UAAU,EAEV,YAAY,EAEZ,QAAQ,EACR,SAAS,EACT,MAAM,gBAAgB,CAAC;AAExB,wBAAsB,UAAU,CAAC,MAAM,SAAS,QAAQ,GAAG,OAAO,GAAG,QAAQ,EAC5E,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,OAAO,CAAC,EAAE,gBAAgB,8BA2D1B;AAED,wBAAsB,YAAY,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GAAG,YAAY,EAAE,EACtC,IAAI,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,EAClC,OAAO,CAAC,EAAE,gBAAgB,sBAqH1B"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamRead = streamRead;
|
|
4
|
+
exports.streamAppend = streamAppend;
|
|
5
|
+
const error_js_1 = require("../../../../error.js");
|
|
6
|
+
const index_js_1 = require("../../../../generated/index.js");
|
|
7
|
+
const utils_js_1 = require("../../../../utils.js");
|
|
8
|
+
const base64_js_1 = require("../../../base64.js");
|
|
9
|
+
async function streamRead(stream, client, args, options) {
|
|
10
|
+
const { as, ...queryParams } = args ?? {};
|
|
11
|
+
const response = await (0, index_js_1.read)({
|
|
12
|
+
client,
|
|
13
|
+
path: {
|
|
14
|
+
stream,
|
|
15
|
+
},
|
|
16
|
+
headers: {
|
|
17
|
+
...(as === "bytes" ? { "s2-format": "base64" } : {}),
|
|
18
|
+
},
|
|
19
|
+
query: queryParams,
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
if (response.error) {
|
|
23
|
+
if ("message" in response.error) {
|
|
24
|
+
throw new error_js_1.S2Error({
|
|
25
|
+
message: response.error.message,
|
|
26
|
+
code: response.error.code ?? undefined,
|
|
27
|
+
status: response.response.status,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// special case for 416 - Range Not Satisfiable
|
|
32
|
+
throw new error_js_1.RangeNotSatisfiableError({
|
|
33
|
+
status: response.response.status,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (args?.as === "bytes") {
|
|
38
|
+
const res = {
|
|
39
|
+
...response.data,
|
|
40
|
+
records: response.data.records?.map((record) => ({
|
|
41
|
+
...record,
|
|
42
|
+
body: record.body ? (0, base64_js_1.decodeFromBase64)(record.body) : undefined,
|
|
43
|
+
headers: record.headers?.map((header) => header.map((h) => (0, base64_js_1.decodeFromBase64)(h))),
|
|
44
|
+
})),
|
|
45
|
+
};
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const res = {
|
|
50
|
+
...response.data,
|
|
51
|
+
records: response.data.records.map((record) => ({
|
|
52
|
+
...record,
|
|
53
|
+
headers: record.headers
|
|
54
|
+
? Object.fromEntries(record.headers)
|
|
55
|
+
: undefined,
|
|
56
|
+
})),
|
|
57
|
+
};
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function streamAppend(stream, client, records, args, options) {
|
|
62
|
+
const recordsArray = Array.isArray(records) ? records : [records];
|
|
63
|
+
if (recordsArray.length === 0) {
|
|
64
|
+
throw new error_js_1.S2Error({ message: "Cannot append empty array of records" });
|
|
65
|
+
}
|
|
66
|
+
let batchMeteredSize = 0;
|
|
67
|
+
for (const record of recordsArray) {
|
|
68
|
+
batchMeteredSize += (0, utils_js_1.meteredSizeBytes)(record);
|
|
69
|
+
}
|
|
70
|
+
if (batchMeteredSize > 1024 * 1024) {
|
|
71
|
+
throw new error_js_1.S2Error({
|
|
72
|
+
message: `Batch size ${batchMeteredSize} bytes exceeds maximum of 1 MiB (1048576 bytes)`,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (recordsArray.length > 1000) {
|
|
76
|
+
throw new error_js_1.S2Error({
|
|
77
|
+
message: `Batch of ${recordsArray.length} exceeds maximum batch size of 1000 records`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
let encodedRecords = [];
|
|
81
|
+
let hasAnyBytesRecords = false;
|
|
82
|
+
for (const record of recordsArray) {
|
|
83
|
+
const format = (0, utils_js_1.computeAppendRecordFormat)(record);
|
|
84
|
+
if (format === "bytes") {
|
|
85
|
+
const formattedRecord = record;
|
|
86
|
+
const encodedRecord = {
|
|
87
|
+
...formattedRecord,
|
|
88
|
+
body: formattedRecord.body
|
|
89
|
+
? (0, base64_js_1.encodeToBase64)(formattedRecord.body)
|
|
90
|
+
: undefined,
|
|
91
|
+
headers: formattedRecord.headers?.map((header) => header.map((h) => (0, base64_js_1.encodeToBase64)(h))),
|
|
92
|
+
};
|
|
93
|
+
encodedRecords.push(encodedRecord);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Normalize headers to array format
|
|
97
|
+
const normalizeHeaders = (headers) => {
|
|
98
|
+
if (headers === undefined) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
else if (Array.isArray(headers)) {
|
|
102
|
+
return headers;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return Object.entries(headers);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const formattedRecord = record;
|
|
109
|
+
const encodedRecord = {
|
|
110
|
+
...formattedRecord,
|
|
111
|
+
headers: formattedRecord.headers
|
|
112
|
+
? normalizeHeaders(formattedRecord.headers)
|
|
113
|
+
: undefined,
|
|
114
|
+
};
|
|
115
|
+
encodedRecords.push(encodedRecord);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const response = await (0, index_js_1.append)({
|
|
119
|
+
client,
|
|
120
|
+
path: {
|
|
121
|
+
stream,
|
|
122
|
+
},
|
|
123
|
+
body: {
|
|
124
|
+
fencing_token: args?.fencing_token,
|
|
125
|
+
match_seq_num: args?.match_seq_num,
|
|
126
|
+
records: encodedRecords,
|
|
127
|
+
},
|
|
128
|
+
headers: {
|
|
129
|
+
...(hasAnyBytesRecords ? { "s2-format": "base64" } : {}),
|
|
130
|
+
},
|
|
131
|
+
...options,
|
|
132
|
+
});
|
|
133
|
+
if (response.error) {
|
|
134
|
+
if ("message" in response.error) {
|
|
135
|
+
throw new error_js_1.S2Error({
|
|
136
|
+
message: response.error.message,
|
|
137
|
+
code: response.error.code ?? undefined,
|
|
138
|
+
status: response.response.status,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// special case for 412 - append condition failed
|
|
143
|
+
if ("seq_num_mismatch" in response.error) {
|
|
144
|
+
throw new error_js_1.SeqNumMismatchError({
|
|
145
|
+
message: "Append condition failed: sequence number mismatch",
|
|
146
|
+
code: "APPEND_CONDITION_FAILED",
|
|
147
|
+
status: response.response.status,
|
|
148
|
+
expectedSeqNum: response.error.seq_num_mismatch,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else if ("fencing_token_mismatch" in response.error) {
|
|
152
|
+
throw new error_js_1.FencingTokenMismatchError({
|
|
153
|
+
message: "Append condition failed: fencing token mismatch",
|
|
154
|
+
code: "APPEND_CONDITION_FAILED",
|
|
155
|
+
status: response.response.status,
|
|
156
|
+
expectedFencingToken: response.error.fencing_token_mismatch,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// fallback for unknown 412 error format
|
|
161
|
+
throw new error_js_1.S2Error({
|
|
162
|
+
message: "Append condition failed",
|
|
163
|
+
status: response.response.status,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return response.data;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../../../src/lib/stream/transport/fetch/shared.ts"],"names":[],"mappings":";;AAkCA,gCA+DC;AAED,oCA0HC;AA5ND,mDAK8B;AAE9B,6DAWwC;AACxC,mDAG8B;AAC9B,kDAAsE;AAU/D,KAAK,UAAU,UAAU,CAC/B,MAAc,EACd,MAAc,EACd,IAAuB,EACvB,OAA0B;IAE1B,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;IAC1C,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAI,EAAC;QAC3B,MAAM;QACN,IAAI,EAAE;YACL,MAAM;SACN;QACD,OAAO,EAAE;YACR,GAAG,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpD;QACD,KAAK,EAAE,WAAW;QAClB,GAAG,OAAO;KACV,CAAC,CAAC;IACH,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,SAAS,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjC,MAAM,IAAI,kBAAO,CAAC;gBACjB,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO;gBAC/B,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,SAAS;gBACtC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAA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47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S2S Protocol Message Framing
|
|
3
|
+
*
|
|
4
|
+
* Message format:
|
|
5
|
+
* - 3 bytes: Length prefix (total message length including flag byte, big-endian)
|
|
6
|
+
* - 1 byte: Flag byte [T][CC][RRRRR]
|
|
7
|
+
* - T (bit 7): Terminal flag (1 = stream ends after this message)
|
|
8
|
+
* - CC (bits 6-5): Compression (00=none, 01=zstd, 10=gzip)
|
|
9
|
+
* - RRRRR (bits 4-0): Reserved
|
|
10
|
+
* - Variable: Body (protobuf message or JSON error for terminal frames)
|
|
11
|
+
*/
|
|
12
|
+
export type CompressionType = "none" | "zstd" | "gzip";
|
|
13
|
+
export interface S2SFrame {
|
|
14
|
+
terminal: boolean;
|
|
15
|
+
compression: CompressionType;
|
|
16
|
+
body: Uint8Array;
|
|
17
|
+
statusCode?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Frame a message for s2s protocol
|
|
21
|
+
*/
|
|
22
|
+
export declare function frameMessage(opts: {
|
|
23
|
+
terminal: boolean;
|
|
24
|
+
compression?: CompressionType;
|
|
25
|
+
body: Uint8Array;
|
|
26
|
+
statusCode?: number;
|
|
27
|
+
}): Uint8Array;
|
|
28
|
+
/**
|
|
29
|
+
* Parser for reading s2s frames from a stream
|
|
30
|
+
*/
|
|
31
|
+
export declare class S2SFrameParser {
|
|
32
|
+
private buffer;
|
|
33
|
+
/**
|
|
34
|
+
* Add data to the parser buffer
|
|
35
|
+
*/
|
|
36
|
+
push(data: Uint8Array): void;
|
|
37
|
+
/**
|
|
38
|
+
* Try to parse the next frame from the buffer
|
|
39
|
+
* Returns null if not enough data available
|
|
40
|
+
*/
|
|
41
|
+
parseFrame(): S2SFrame | null;
|
|
42
|
+
/**
|
|
43
|
+
* Check if parser has any buffered data
|
|
44
|
+
*/
|
|
45
|
+
hasData(): boolean;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=framing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/stream/transport/s2s/framing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,eAAe,CAAC;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,UAAU,CA+Cb;AAED;;GAEG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,MAAM,CAAiC;IAE/C;;OAEG;IACI,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAOnC;;;OAGG;IACI,UAAU,IAAI,QAAQ,GAAG,IAAI;IA8CpC;;OAEG;IACI,OAAO,IAAI,OAAO;CAGzB"}
|