@streamsy/core 0.4.0 → 0.5.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 +40 -3
- package/dist/{cursor-generator-CGz1TO_N.js → cursor-generator-DySXZ93b.js} +1 -2
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +2 -2
- package/dist/{http-EnNOUsIK.js → http-x2IjDHvw.js} +9 -11
- package/dist/{index-CFv8vZvy.d.ts → index-C26ncp7Y.d.ts} +63 -43
- package/dist/index.d.ts +2 -2
- package/dist/index.js +52 -51
- package/dist/internal/index.d.ts +1 -3
- package/dist/internal/index.js +2 -2
- package/dist/{layer-D8ybaCL2.js → layer-DJ-c63nY.js} +31 -31
- package/dist/{layer-KvknRFUT.js → layer-DyezIxJT.js} +22 -33
- package/dist/{owner-BQzMpfC1.js → owner-BWQ2KvC_.js} +1 -2
- package/dist/{owner-records-QDlssl__.d.ts → owner-records-BV5Un5R0.d.ts} +0 -22
- package/dist/{owner-records-CX6yU28i.js → owner-records-C0p8jeC1.js} +1 -2
- package/dist/{program-DJ8NpHIf.js → program-DXUjw5B2.js} +38 -55
- package/dist/protocol/index.d.ts +2 -4
- package/dist/protocol/index.js +4 -5
- package/dist/remote/index.d.ts +2 -4
- package/dist/remote/index.js +10 -14
- package/dist/{rolldown-runtime-D7D4PA-g.js → rolldown-runtime-D8jQpDG7.js} +1 -2
- package/dist/{streamsy-OjRubIPC.js → streamsy-DJMArv09.js} +61 -44
- package/dist/testing/index.d.ts +2 -10
- package/dist/testing/index.js +22 -27
- package/package.json +1 -1
package/dist/internal/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as isForeignOwner, n as attachOwner, o as ownerOf, t as CurrentOwner } from "../owner-
|
|
2
|
-
import { t as OwnerRecords } from "../owner-records-
|
|
1
|
+
import { a as isForeignOwner, n as attachOwner, o as ownerOf, t as CurrentOwner } from "../owner-BWQ2KvC_.js";
|
|
2
|
+
import { t as OwnerRecords } from "../owner-records-C0p8jeC1.js";
|
|
3
3
|
export { CurrentOwner, OwnerRecords, attachOwner, isForeignOwner, ownerOf };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { M as Storage, N as ZERO_OFFSET } from "./streamsy-
|
|
2
|
-
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-
|
|
3
|
-
import { n as attachOwner, o as ownerOf } from "./owner-
|
|
4
|
-
import { t as OwnerRecords } from "./owner-records-
|
|
5
|
-
import { Context, Effect, Layer, Option, Predicate, Queue, Schedule, Semaphore, Stream } from "effect";
|
|
6
|
-
|
|
1
|
+
import { M as Storage, N as ZERO_OFFSET } from "./streamsy-DJMArv09.js";
|
|
2
|
+
import { a as MutationRejected, l as OperationResults, o as Mutations, u as Operations } from "./layer-DyezIxJT.js";
|
|
3
|
+
import { n as attachOwner, o as ownerOf } from "./owner-BWQ2KvC_.js";
|
|
4
|
+
import { t as OwnerRecords } from "./owner-records-C0p8jeC1.js";
|
|
5
|
+
import { Array, Context, Effect, Layer, Option, Order, Predicate, Queue, Schedule, Semaphore, Stream } from "effect";
|
|
6
|
+
// src/storage/commit-boundary.ts
|
|
7
7
|
/** The transaction of the storage owner. Every Streamsy storage host provides it. */
|
|
8
8
|
var CommitBoundary = class extends Context.Service()("@streamsy/core/CommitBoundary") {};
|
|
9
|
-
|
|
10
|
-
//#region src/storage/memory/state.ts
|
|
9
|
+
// src/storage/memory/state.ts
|
|
11
10
|
const copyRecord = (record) => ({
|
|
12
11
|
id: record.id,
|
|
13
12
|
currentOffset: record.currentOffset,
|
|
@@ -48,26 +47,31 @@ function patchRecord(record, patch) {
|
|
|
48
47
|
};
|
|
49
48
|
}
|
|
50
49
|
function indexDeadlines(state) {
|
|
51
|
-
state.deadlines = [...state.entries.values()]
|
|
50
|
+
state.deadlines = Array.sort(Array.flatMap([...state.entries.values()], ({ record }) => record.lifecycle.softDeleted || record.lifecycle.expiresAtMs === void 0 ? [] : [{
|
|
52
51
|
at: record.lifecycle.expiresAtMs,
|
|
53
52
|
streamId: record.id
|
|
54
|
-
}]).
|
|
53
|
+
}]), Order.make((a, b) => {
|
|
54
|
+
const compared = a.at - b.at || a.streamId.localeCompare(b.streamId);
|
|
55
|
+
return compared < 0 ? -1 : compared > 0 ? 1 : 0;
|
|
56
|
+
}));
|
|
55
57
|
}
|
|
56
58
|
/** A private transaction draft; no mutable stream data aliases the committed state. */
|
|
57
59
|
const copyState = (state) => ({
|
|
58
|
-
entries: new Map([...state.entries]
|
|
60
|
+
entries: new Map(Array.map([...state.entries], ([id, entry]) => [id, {
|
|
59
61
|
record: copyRecord(entry.record),
|
|
60
|
-
messages: entry.messages
|
|
61
|
-
producers: new Map([...entry.producers]
|
|
62
|
+
messages: Array.map(entry.messages, copyMessage),
|
|
63
|
+
producers: new Map(Array.map([...entry.producers], ([producerId, producer]) => [producerId, {
|
|
62
64
|
epoch: producer.epoch,
|
|
63
65
|
lastSeq: producer.lastSeq
|
|
64
66
|
}]))
|
|
65
67
|
}])),
|
|
66
|
-
children: new Map([...state.children]
|
|
67
|
-
deadlines: state.deadlines
|
|
68
|
+
children: new Map(Array.map([...state.children], ([id, children]) => [id, new Set(children)])),
|
|
69
|
+
deadlines: Array.map(state.deadlines, (deadline) => ({ ...deadline }))
|
|
68
70
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
// src/storage/memory/lineage.ts
|
|
72
|
+
/** Synchronous port of cascade-reclaim and chained message composition.
|
|
73
|
+
* Called only inside the memory mutation lock or synchronous read snapshot.
|
|
74
|
+
*/
|
|
71
75
|
function addEdge(state, parent, child) {
|
|
72
76
|
const children = state.children.get(parent) ?? /* @__PURE__ */ new Set();
|
|
73
77
|
children.add(child);
|
|
@@ -95,10 +99,10 @@ function composeMessages(state, id, chain) {
|
|
|
95
99
|
const entry = state.entries.get(id);
|
|
96
100
|
if (!entry) return [];
|
|
97
101
|
const { forkedFrom, forkOffset } = entry.record.lifecycle;
|
|
98
|
-
|
|
102
|
+
const inherited = chain && forkedFrom !== void 0 && forkOffset !== void 0 ? Array.filter(composeMessages(state, forkedFrom, true), (message) => message.offset <= forkOffset) : [];
|
|
103
|
+
return Array.sort([...inherited, ...entry.messages], Order.mapInput(Order.String, (message) => message.offset));
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
//#region src/storage/memory/notifier.ts
|
|
105
|
+
// src/storage/memory/notifier.ts
|
|
102
106
|
/** Private store-wide wakes, with retention isolated to each active subscription. */
|
|
103
107
|
const createNotifier = Effect.gen(function* () {
|
|
104
108
|
const queues = /* @__PURE__ */ new Set();
|
|
@@ -138,8 +142,7 @@ const createNotifier = Effect.gen(function* () {
|
|
|
138
142
|
})
|
|
139
143
|
};
|
|
140
144
|
});
|
|
141
|
-
|
|
142
|
-
//#region src/storage/memory/boundary.ts
|
|
145
|
+
// src/storage/memory/boundary.ts
|
|
143
146
|
var ActiveDraft = class extends Context.Service()("@streamsy/core/internal/MemoryActiveDraft") {};
|
|
144
147
|
const makeBoundary = (committed, publish) => Effect.gen(function* () {
|
|
145
148
|
const owner = {};
|
|
@@ -193,8 +196,7 @@ const makeBoundary = (committed, publish) => Effect.gen(function* () {
|
|
|
193
196
|
changed
|
|
194
197
|
};
|
|
195
198
|
});
|
|
196
|
-
|
|
197
|
-
//#region src/storage/memory/changes.ts
|
|
199
|
+
// src/storage/memory/changes.ts
|
|
198
200
|
function snapshot(state, id) {
|
|
199
201
|
const record = state.entries.get(id)?.record;
|
|
200
202
|
return {
|
|
@@ -212,8 +214,7 @@ function changes(state, bus, id, push, interval) {
|
|
|
212
214
|
return Stream.concat(Stream.fromEffect(read), Stream.fromQueue(subscription).pipe(Stream.mapEffect(() => read)));
|
|
213
215
|
}));
|
|
214
216
|
}
|
|
215
|
-
|
|
216
|
-
//#region src/storage/memory/layer.ts
|
|
217
|
+
// src/storage/memory/layer.ts
|
|
217
218
|
function reject(state, operation, index) {
|
|
218
219
|
const id = Predicate.isTagged(operation, "Create") ? operation.record.id : operation.streamId;
|
|
219
220
|
const entry = state.entries.get(id);
|
|
@@ -268,7 +269,7 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
268
269
|
const record = copyRecord(operation.record);
|
|
269
270
|
state.entries.set(record.id, {
|
|
270
271
|
record,
|
|
271
|
-
messages: operation.initialMessages
|
|
272
|
+
messages: Array.map(operation.initialMessages, copyMessage),
|
|
272
273
|
producers: /* @__PURE__ */ new Map()
|
|
273
274
|
});
|
|
274
275
|
if (chain && record.lifecycle.forkedFrom !== void 0) addEdge(state, record.lifecycle.forkedFrom, record.id);
|
|
@@ -283,7 +284,7 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
283
284
|
results.push(OperationResults.Created({ record: copyRecord(entry.record) }));
|
|
284
285
|
},
|
|
285
286
|
Append: (append) => {
|
|
286
|
-
entry.messages.push(...append.messages
|
|
287
|
+
entry.messages.push(...Array.map(append.messages, copyMessage));
|
|
287
288
|
entry.record = patchRecord(entry.record, append.patch);
|
|
288
289
|
if (append.producer) entry.producers.set(append.producer.producerId, { ...append.producer.next });
|
|
289
290
|
results.push(OperationResults.Appended({ record: copyRecord(entry.record) }));
|
|
@@ -315,13 +316,13 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
315
316
|
expiryIndex: chain ? "indexed" : "lazy"
|
|
316
317
|
},
|
|
317
318
|
record: Effect.fn("Memory.record")((id) => owner.access((state) => Option.fromUndefinedOr(state.entries.get(id)?.record).pipe(Option.map(copyRecord)))),
|
|
318
|
-
messages: Effect.fn("Memory.messages")((id, window) => owner.access((state) => composeMessages(state, id, chain)
|
|
319
|
+
messages: Effect.fn("Memory.messages")((id, window) => owner.access((state) => Array.map(Array.filter(composeMessages(state, id, chain), (message) => (window.after === void 0 || message.offset > window.after) && (window.until === void 0 || message.offset <= window.until)).slice(0, window.limit === void 0 ? void 0 : Math.max(0, window.limit)), copyMessage))),
|
|
319
320
|
producer: Effect.fn("Memory.producer")((id, producerId) => owner.access((state) => Option.fromUndefinedOr(state.entries.get(id)?.producers.get(producerId)).pipe(Option.map((value) => ({
|
|
320
321
|
epoch: value.epoch,
|
|
321
322
|
lastSeq: value.lastSeq
|
|
322
323
|
}))))),
|
|
323
324
|
mutate: Effect.fn("Memory.mutate")(function* (mutation) {
|
|
324
|
-
const ids = mutation.operations
|
|
325
|
+
const ids = Array.map(mutation.operations, (operation) => Predicate.isTagged(operation, "Create") ? operation.record.id : operation.streamId);
|
|
325
326
|
if (ids.length === 0 || new Set(ids).size !== ids.length || !chain && ids.length > 1) return yield* Effect.die(/* @__PURE__ */ new Error("Mutation requires distinct streams within atomicScope"));
|
|
326
327
|
return yield* Effect.gen(function* () {
|
|
327
328
|
const result = yield* owner.access((state) => commit(state, mutation));
|
|
@@ -336,5 +337,4 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
336
337
|
});
|
|
337
338
|
return Context.make(Storage, attachOwner(storage, ownerOf(owner.boundary))).pipe(Context.add(CommitBoundary, owner.boundary), Context.add(OwnerRecords, owner.records));
|
|
338
339
|
}));
|
|
339
|
-
//#endregion
|
|
340
340
|
export { CommitBoundary as n, layer as t };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as __exportAll } from "./rolldown-runtime-
|
|
2
|
-
import { A as StreamsReader, C as ProducerGap, D as StreamGone, E as StreamClosed, F as isValid, I as next, J as ProducerState, K as Offset, M as Storage, N as ZERO_OFFSET, O as StreamNotFound, P as compare, Q as StreamId, S as OffsetMismatch, T as StreamBusy, X as StoredMessage, Y as RecordPatch, _ as InvalidAppendRequest, b as InvalidReadRequest, et as StreamRecord, f as AppendResult, g as ForkSourceNotFound, h as CreateConflict, j as StreamsWriter, m as AppendConflict, n as bind, p as CreateResult, q as ProducerId, v as InvalidEpochSeq, w as StaleEpoch, x as NotSupported, y as InvalidForkRequest } from "./streamsy-
|
|
3
|
-
import { r as attachStorage } from "./owner-
|
|
4
|
-
import { t as generateCursor } from "./cursor-generator-
|
|
5
|
-
import { Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Schema, Stream } from "effect";
|
|
6
|
-
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
|
+
import { A as StreamsReader, C as ProducerGap, D as StreamGone, E as StreamClosed, F as isValid, I as next, J as ProducerState, K as Offset, M as Storage, N as ZERO_OFFSET, O as StreamNotFound, P as compare, Q as StreamId, S as OffsetMismatch, T as StreamBusy, X as StoredMessage, Y as RecordPatch, _ as InvalidAppendRequest, b as InvalidReadRequest, et as StreamRecord, f as AppendResult, g as ForkSourceNotFound, h as CreateConflict, j as StreamsWriter, m as AppendConflict, n as bind, p as CreateResult, q as ProducerId, v as InvalidEpochSeq, w as StaleEpoch, x as NotSupported, y as InvalidForkRequest } from "./streamsy-DJMArv09.js";
|
|
3
|
+
import { r as attachStorage } from "./owner-BWQ2KvC_.js";
|
|
4
|
+
import { t as generateCursor } from "./cursor-generator-DySXZ93b.js";
|
|
5
|
+
import { Array, Clock, Context, Data, Effect, Layer, Match, Option, Predicate, Random, Schema, Stream } from "effect";
|
|
6
|
+
// src/storage/mutation.ts
|
|
7
7
|
const ProducerPrecondition = Schema.Struct({
|
|
8
8
|
producerId: ProducerId,
|
|
9
9
|
expected: Schema.Option(ProducerState),
|
|
@@ -62,8 +62,7 @@ var MutationRejected = class extends Schema.TaggedError()("MutationRejected", {
|
|
|
62
62
|
const Operations = Data.taggedEnum();
|
|
63
63
|
const OperationResults = Data.taggedEnum();
|
|
64
64
|
const Mutations = Data.taggedEnum();
|
|
65
|
-
|
|
66
|
-
//#region src/policy/content-type-matcher.ts
|
|
65
|
+
// src/policy/content-type-matcher.ts
|
|
67
66
|
/**
|
|
68
67
|
* Content type normalization and matching for the durable streams protocol.
|
|
69
68
|
*
|
|
@@ -84,8 +83,7 @@ function normalizeContentType(ct) {
|
|
|
84
83
|
function contentTypeMatches(expected, actual) {
|
|
85
84
|
return normalizeContentType(expected) === normalizeContentType(actual);
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
//#region src/policy/create-config-matcher.ts
|
|
86
|
+
// src/policy/create-config-matcher.ts
|
|
89
87
|
function configMatches(existing, options) {
|
|
90
88
|
const contentType = options.contentType ?? existing.config.contentType ?? "application/octet-stream";
|
|
91
89
|
if (!contentTypeMatches(existing.config.contentType, contentType)) return false;
|
|
@@ -97,8 +95,7 @@ function configMatches(existing, options) {
|
|
|
97
95
|
if (existing.config.expiresAt !== options.expiresAt && !inheritedForkExpiry) return false;
|
|
98
96
|
return existing.lifecycle.closed === (options.closed === true);
|
|
99
97
|
}
|
|
100
|
-
|
|
101
|
-
//#region src/policy/expiry-policy.ts
|
|
98
|
+
// src/policy/expiry-policy.ts
|
|
102
99
|
/** Pure rules ported from ExpiryPolicy; touch and expiry execution belong to the protocol. */
|
|
103
100
|
function computeExpiresAtMs(config, now) {
|
|
104
101
|
if (config.ttlSeconds !== void 0) return now + config.ttlSeconds * 1e3;
|
|
@@ -108,8 +105,7 @@ function isExpired(record, now) {
|
|
|
108
105
|
const at = record.lifecycle.expiresAtMs;
|
|
109
106
|
return at !== void 0 && at <= now;
|
|
110
107
|
}
|
|
111
|
-
|
|
112
|
-
//#region src/policy/message-framer.ts
|
|
108
|
+
// src/policy/message-framer.ts
|
|
113
109
|
/**
|
|
114
110
|
* Body framing for the durable streams protocol.
|
|
115
111
|
*
|
|
@@ -131,11 +127,10 @@ function isExpired(record, now) {
|
|
|
131
127
|
function frameMessages(data, contentType) {
|
|
132
128
|
if (!contentType.toLowerCase().startsWith("application/json")) return [data];
|
|
133
129
|
const parsed = JSON.parse(new TextDecoder().decode(data));
|
|
134
|
-
if (Array.isArray(parsed)) return parsed.length === 0 ? [] :
|
|
130
|
+
if (Array.isArray(parsed)) return parsed.length === 0 ? [] : Array.map(parsed, (item) => new TextEncoder().encode(JSON.stringify(item)));
|
|
135
131
|
return [new TextEncoder().encode(JSON.stringify(parsed))];
|
|
136
132
|
}
|
|
137
|
-
|
|
138
|
-
//#region src/policy/fork-plan-builder.ts
|
|
133
|
+
// src/policy/fork-plan-builder.ts
|
|
139
134
|
/** Fork-side validation and plan building. */
|
|
140
135
|
const ForkBuildResult = Data.taggedEnum();
|
|
141
136
|
const ForkPrefix = Data.taggedEnum();
|
|
@@ -224,7 +219,7 @@ var ForkPlanBuilder = class {
|
|
|
224
219
|
const tail = sourceTail ?? [];
|
|
225
220
|
if (contentType.toLowerCase().startsWith("application/json")) {
|
|
226
221
|
if (subOffset > tail.length) return ForkPrefix.Invalid({ errorMessage: "Stream-Fork-Sub-Offset exceeds source message count" });
|
|
227
|
-
return ForkPrefix.Prefix({ messages: tail.slice(0, subOffset)
|
|
222
|
+
return ForkPrefix.Prefix({ messages: Array.map(tail.slice(0, subOffset), (m) => m.data) });
|
|
228
223
|
}
|
|
229
224
|
const first = tail[0];
|
|
230
225
|
if (!first) return ForkPrefix.Invalid({ errorMessage: "Stream-Fork-Sub-Offset has no source message to fork" });
|
|
@@ -235,7 +230,7 @@ var ForkPlanBuilder = class {
|
|
|
235
230
|
const framed = [...prefix, ...initialData ? frameMessages(initialData, contentType) : []];
|
|
236
231
|
let offset = previousOffset;
|
|
237
232
|
const now = this.deps.clock.now();
|
|
238
|
-
return
|
|
233
|
+
return Array.map(framed, (data) => {
|
|
239
234
|
offset = next(offset);
|
|
240
235
|
return {
|
|
241
236
|
data,
|
|
@@ -254,8 +249,7 @@ var ForkPlanBuilder = class {
|
|
|
254
249
|
};
|
|
255
250
|
}
|
|
256
251
|
};
|
|
257
|
-
|
|
258
|
-
//#region src/protocol/expiry.ts
|
|
252
|
+
// src/protocol/expiry.ts
|
|
259
253
|
const expireIfNeeded = Effect.fn("Protocol.expireIfNeeded")(function* (storage, id) {
|
|
260
254
|
const record = yield* storage.record(id);
|
|
261
255
|
const now = yield* Clock.currentTimeMillis;
|
|
@@ -293,8 +287,7 @@ const expireDue = Effect.fn("Protocol.expireDue")(function* () {
|
|
|
293
287
|
})] }).pipe(Effect.uninterruptible, Effect.catchTag("MutationRejected", () => Effect.void));
|
|
294
288
|
}
|
|
295
289
|
});
|
|
296
|
-
|
|
297
|
-
//#region src/protocol/create.ts
|
|
290
|
+
// src/protocol/create.ts
|
|
298
291
|
function newRecord(id, contentType, options, now, fork) {
|
|
299
292
|
const at = computeExpiresAtMs(options, now);
|
|
300
293
|
const config = {
|
|
@@ -365,7 +358,7 @@ const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}
|
|
|
365
358
|
const type = options.contentType ?? "application/octet-stream";
|
|
366
359
|
const record = newRecord(id, type, options, now);
|
|
367
360
|
let offset = record.currentOffset;
|
|
368
|
-
const initialMessages = (options.initialData ? frameMessages(options.initialData, type) : []
|
|
361
|
+
const initialMessages = Array.map(options.initialData ? frameMessages(options.initialData, type) : [], (data) => ({
|
|
369
362
|
data,
|
|
370
363
|
offset: offset = next(offset),
|
|
371
364
|
timestamp: now
|
|
@@ -396,8 +389,7 @@ const create = Effect.fn("Protocol.create")(function* (storage, id, options = {}
|
|
|
396
389
|
return Effect.die(/* @__PURE__ */ new Error(`Unexpected create rejection: ${rejection.reason}`));
|
|
397
390
|
}));
|
|
398
391
|
});
|
|
399
|
-
|
|
400
|
-
//#region src/policy/producer-idempotency-service.ts
|
|
392
|
+
// src/policy/producer-idempotency-service.ts
|
|
401
393
|
/** Pure producer idempotency decisions. */
|
|
402
394
|
const ProducerValidation = Data.taggedEnum();
|
|
403
395
|
function validateProducer(state, epoch, seq) {
|
|
@@ -485,7 +477,7 @@ const append = Effect.fn("Protocol.append")(function* (storage, id, options) {
|
|
|
485
477
|
});
|
|
486
478
|
const now = yield* Clock.currentTimeMillis;
|
|
487
479
|
let offset = record.currentOffset;
|
|
488
|
-
const messages = (closeOnly ? [] : frameMessages(options.data, record.config.contentType)
|
|
480
|
+
const messages = Array.map(closeOnly ? [] : frameMessages(options.data, record.config.contentType), (data) => ({
|
|
489
481
|
data,
|
|
490
482
|
offset: offset = next(offset),
|
|
491
483
|
timestamp: now
|
|
@@ -529,8 +521,7 @@ const append = Effect.fn("Protocol.append")(function* (storage, id, options) {
|
|
|
529
521
|
}
|
|
530
522
|
return yield* new StreamBusy({ id });
|
|
531
523
|
});
|
|
532
|
-
|
|
533
|
-
//#region src/protocol/read.ts
|
|
524
|
+
// src/protocol/read.ts
|
|
534
525
|
const head = Effect.fn("Protocol.head")(function* (storage, id) {
|
|
535
526
|
const found = yield* expireIfNeeded(storage, id);
|
|
536
527
|
if (Option.isNone(found)) return yield* new StreamNotFound({ id });
|
|
@@ -561,7 +552,7 @@ const readRecord = Effect.fn("Protocol.readRecord")(function* (storage, record,
|
|
|
561
552
|
const upToDate = nextOffset === record.currentOffset;
|
|
562
553
|
return {
|
|
563
554
|
contentType: record.config.contentType,
|
|
564
|
-
messages:
|
|
555
|
+
messages: Array.map(messages, (message) => ({ data: message.data })),
|
|
565
556
|
nextOffset,
|
|
566
557
|
upToDate,
|
|
567
558
|
closed: record.lifecycle.closed && upToDate
|
|
@@ -613,8 +604,7 @@ const readNext = Effect.fn("Protocol.readNext")(function* (storage, id, options,
|
|
|
613
604
|
cursor: yield* cursor
|
|
614
605
|
};
|
|
615
606
|
});
|
|
616
|
-
|
|
617
|
-
//#region src/protocol/layer.ts
|
|
607
|
+
// src/protocol/layer.ts
|
|
618
608
|
var layer_exports = /* @__PURE__ */ __exportAll({
|
|
619
609
|
bind: () => bind,
|
|
620
610
|
expireDue: () => expireDue,
|
|
@@ -652,5 +642,4 @@ const layer = (options = {}) => Layer.effectContext(Effect.gen(function* () {
|
|
|
652
642
|
});
|
|
653
643
|
return Context.make(StreamsReader, attachStorage(reader, storage)).pipe(Context.add(StreamsWriter, attachStorage(writer, storage)));
|
|
654
644
|
}));
|
|
655
|
-
//#endregion
|
|
656
645
|
export { MutationRejected as a, OperationResult as c, ProducerPrecondition as d, MutationApplied as i, OperationResults as l, layer_exports as n, Mutations as o, Mutation as r, Operation as s, layer as t, Operations as u };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context, Data, Effect, Predicate } from "effect";
|
|
2
|
-
|
|
2
|
+
// src/internal/owner.ts
|
|
3
3
|
/** Private bridge: a stream guard dies with this sentinel; the atomic runner translates it. */
|
|
4
4
|
const ForeignOwnerType = Symbol.for("@streamsy/core/internal/ForeignOwner");
|
|
5
5
|
var ForeignOwner = class extends Data.TaggedError("ForeignOwner") {
|
|
@@ -32,5 +32,4 @@ const storageOf = (wire) => {
|
|
|
32
32
|
if (!(Metadata in wire)) return void 0;
|
|
33
33
|
return wire[Metadata];
|
|
34
34
|
};
|
|
35
|
-
//#endregion
|
|
36
35
|
export { isForeignOwner as a, checkWriteOwner as i, attachOwner as n, ownerOf as o, attachStorage as r, storageOf as s, CurrentOwner as t };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Context, Data, Effect, Option, Schema, Stream } from "effect";
|
|
2
|
-
//#region src/fault.d.ts
|
|
3
2
|
declare const StorageFault_base: Schema.Class<StorageFault, Schema.TaggedStruct<"StorageFault", {
|
|
4
3
|
readonly operation: Schema.String;
|
|
5
4
|
readonly message: Schema.String;
|
|
@@ -36,8 +35,6 @@ type StreamsFault = typeof StreamsFault.Type;
|
|
|
36
35
|
declare const isStreamsFault: <I>(input: I) => input is I & (StorageFault | TransportFault);
|
|
37
36
|
/** A storage or transport failure that can succeed later. */
|
|
38
37
|
declare const isRetryableFault: (error: unknown) => error is StreamsFault;
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/schema/index.d.ts
|
|
41
38
|
declare const StreamId: Schema.brand<Schema.String, "StreamId">;
|
|
42
39
|
declare const Offset: Schema.brand<Schema.String, "Offset">;
|
|
43
40
|
declare const ProducerId: Schema.brand<Schema.String, "ProducerId">;
|
|
@@ -126,8 +123,6 @@ declare const RecordPatch: Schema.Struct<{
|
|
|
126
123
|
readonly clear: Schema.optionalKey<Schema.$Array<Schema.Literals<readonly ["ttlSeconds", "expiresAt", "expiresAtMs", "lastSeq"]>>>;
|
|
127
124
|
}>;
|
|
128
125
|
interface RecordPatch extends Schema.Schema.Type<typeof RecordPatch> {}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/policy/options.d.ts
|
|
131
126
|
/** Private pure-policy input, promoted to protocol options in Batch 3. */
|
|
132
127
|
interface CreateOptions {
|
|
133
128
|
readonly contentType?: string;
|
|
@@ -139,8 +134,6 @@ interface CreateOptions {
|
|
|
139
134
|
readonly forkSubOffset?: number;
|
|
140
135
|
readonly initialData?: Uint8Array;
|
|
141
136
|
}
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/protocol/options.d.ts
|
|
144
137
|
interface ProducerOptions {
|
|
145
138
|
readonly producerId: string;
|
|
146
139
|
readonly producerEpoch: number;
|
|
@@ -177,8 +170,6 @@ interface ReadNextOptions {
|
|
|
177
170
|
offset: string;
|
|
178
171
|
cursor?: string;
|
|
179
172
|
}
|
|
180
|
-
//#endregion
|
|
181
|
-
//#region src/protocol/errors.d.ts
|
|
182
173
|
declare const StreamNotFound_base: Schema.Class<StreamNotFound, Schema.TaggedStruct<"StreamNotFound", {
|
|
183
174
|
readonly id: Schema.brand<Schema.String, "StreamId">;
|
|
184
175
|
}>, import("effect/Cause").YieldableError>;
|
|
@@ -300,8 +291,6 @@ type ProtocolError = HeadError | ReadNextError | CreateError | AppendError | Rem
|
|
|
300
291
|
declare const isProtocolError: (error: {
|
|
301
292
|
readonly _tag: string;
|
|
302
293
|
}) => error is ProtocolError;
|
|
303
|
-
//#endregion
|
|
304
|
-
//#region src/protocol/results.d.ts
|
|
305
294
|
/** Payload-only messages exposed by the public protocol; storage owns offsets and timestamps. */
|
|
306
295
|
interface ReadMessage {
|
|
307
296
|
readonly data: Uint8Array;
|
|
@@ -427,8 +416,6 @@ interface HeadResult {
|
|
|
427
416
|
readonly expiresAt?: string;
|
|
428
417
|
readonly closed: boolean;
|
|
429
418
|
}
|
|
430
|
-
//#endregion
|
|
431
|
-
//#region src/protocol/tags.d.ts
|
|
432
419
|
interface Reader<E = StorageFault> {
|
|
433
420
|
readonly head: (id: StreamId) => Effect.Effect<HeadResult, HeadError | E>;
|
|
434
421
|
readonly read: (id: StreamId, options?: ReadOptions) => Effect.Effect<ReadResult, ReadError | E>;
|
|
@@ -444,8 +431,6 @@ declare const StreamsReader_base: Context.ServiceClass<StreamsReader, "@streamsy
|
|
|
444
431
|
declare class StreamsReader extends StreamsReader_base {}
|
|
445
432
|
declare const StreamsWriter_base: Context.ServiceClass<StreamsWriter, "@streamsy/core/StreamsWriter", Writer<StorageFault | TransportFault>>;
|
|
446
433
|
declare class StreamsWriter extends StreamsWriter_base {}
|
|
447
|
-
//#endregion
|
|
448
|
-
//#region src/storage/capabilities.d.ts
|
|
449
434
|
declare const StorageCapabilities: Schema.Struct<{
|
|
450
435
|
readonly fork: Schema.Literals<readonly ["none", "copy", "chain"]>;
|
|
451
436
|
readonly atomicScope: Schema.Literals<readonly ["stream", "store"]>;
|
|
@@ -453,8 +438,6 @@ declare const StorageCapabilities: Schema.Struct<{
|
|
|
453
438
|
readonly expiryIndex: Schema.Literals<readonly ["lazy", "indexed"]>;
|
|
454
439
|
}>;
|
|
455
440
|
interface StorageCapabilities extends Schema.Schema.Type<typeof StorageCapabilities> {}
|
|
456
|
-
//#endregion
|
|
457
|
-
//#region src/storage/mutation.d.ts
|
|
458
441
|
declare const ProducerPrecondition: Schema.Struct<{
|
|
459
442
|
readonly producerId: Schema.brand<Schema.String, "ProducerId">;
|
|
460
443
|
readonly expected: Schema.Option<Schema.Struct<{
|
|
@@ -2930,8 +2913,6 @@ declare const Mutations: {
|
|
|
2930
2913
|
})[]];
|
|
2931
2914
|
}, "_tag">;
|
|
2932
2915
|
};
|
|
2933
|
-
//#endregion
|
|
2934
|
-
//#region src/storage/storage.d.ts
|
|
2935
2916
|
interface StorageShape {
|
|
2936
2917
|
readonly capabilities: StorageCapabilities;
|
|
2937
2918
|
readonly record: (id: StreamId) => Effect.Effect<Option.Option<StreamRecord>, StorageFault>;
|
|
@@ -2946,8 +2927,6 @@ interface StorageShape {
|
|
|
2946
2927
|
}
|
|
2947
2928
|
declare const Storage_base: Context.ServiceClass<Storage, "@streamsy/core/Storage", StorageShape>;
|
|
2948
2929
|
declare class Storage extends Storage_base {}
|
|
2949
|
-
//#endregion
|
|
2950
|
-
//#region src/internal/owner-records.d.ts
|
|
2951
2930
|
/**
|
|
2952
2931
|
* Encoded records on the storage owner, for the projection checkpoint store.
|
|
2953
2932
|
* Calls inside `CommitBoundary.withTransaction` join that transaction.
|
|
@@ -2959,5 +2938,4 @@ interface OwnerRecordsApi {
|
|
|
2959
2938
|
}
|
|
2960
2939
|
declare const OwnerRecords_base: Context.ServiceClass<OwnerRecords, "@streamsy/core/internal/OwnerRecords", OwnerRecordsApi>;
|
|
2961
2940
|
declare class OwnerRecords extends OwnerRecords_base {}
|
|
2962
|
-
//#endregion
|
|
2963
2941
|
export { ProducerOptions as $, CreateConflictReason as A, ProducerGap as B, ReadNextResult as C, AppendError as D, AppendConflict as E, InvalidEpochSeq as F, StaleEpoch as G, ReadError as H, InvalidForkRequest as I, StreamGone as J, StreamBusy as K, InvalidReadRequest as L, ForkSourceNotFound as M, HeadError as N, AppendErrorFor as O, InvalidAppendRequest as P, AppendOptions as Q, NotSupported as R, ReadMessage as S, AppendBaseError as T, ReadNextError as U, ProtocolError as V, RemoveError as W, isProtocolError as X, StreamNotFound as Y, AppendCallOptions as Z, StreamsWriter as _, StreamsFault as _t, Mutation as a, Offset as at, CreateResult as b, isStreamsFault as bt, Mutations as c, RecordPatch as ct, OperationResults as d, StreamId as dt, ReadNextOptions as et, Operations as f, StreamLifecycle as ft, StreamsReader as g, StorageFault as gt, Reader as h, EncodeFault as ht, StorageShape as i, MessageWindow as it, CreateError as j, CreateConflict as k, Operation as l, StoredMessage as lt, StorageCapabilities as m, DecodeFault as mt, OwnerRecordsApi as n, CreateOptions as nt, MutationApplied as o, ProducerId as ot, ProducerPrecondition as p, StreamRecord as pt, StreamClosed as q, Storage as r, ChangeSnapshot as rt, MutationRejected as s, ProducerState as st, OwnerRecords as t, ReadOptions as tt, OperationResult as u, StreamConfig as ut, Writer as v, TransportFault as vt, ReadResult as w, HeadResult as x, AppendResult as y, isRetryableFault as yt, OffsetMismatch as z };
|