@streamsy/projection 0.15.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamsy/projection",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Checkpointed Effect projections over one or more retained streams.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -37,26 +37,26 @@
37
37
  "test:dialects": "bun --bun vitest run test/sql-dialects.test.ts"
38
38
  },
39
39
  "dependencies": {
40
- "@streamsy/core": "^0.15.0"
40
+ "@streamsy/core": "^0.17.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@cloudflare/workers-types": "4.20251228.0",
44
- "@effect/platform-bun": "4.1.5",
45
- "@effect/sql-mysql2": "4.1.5",
46
- "@effect/sql-pg": "4.1.5",
47
- "@effect/sql-sqlite-bun": "4.1.5",
48
- "@effect/sql-sqlite-do": "4.1.5",
49
- "@effect/vitest": "4.1.5",
50
- "@streamsy/serve": "0.15.0",
51
- "@streamsy/storage": "0.15.0",
44
+ "@effect/platform-bun": "4.2.0",
45
+ "@effect/sql-mysql2": "4.2.0",
46
+ "@effect/sql-pg": "4.2.0",
47
+ "@effect/sql-sqlite-bun": "4.2.0",
48
+ "@effect/sql-sqlite-do": "4.2.0",
49
+ "@effect/vitest": "4.2.0",
50
+ "@streamsy/serve": "0.17.0",
51
+ "@streamsy/storage": "0.17.0",
52
52
  "@types/bun": "^1.4.3",
53
- "effect": "4.1.5",
53
+ "effect": "4.2.0",
54
54
  "miniflare": "4.20260730.0",
55
55
  "typescript": "^7.0.2",
56
56
  "vitest": "5.0.5"
57
57
  },
58
58
  "peerDependencies": {
59
- "effect": "^4.1.5"
59
+ "effect": "^4.2.0"
60
60
  },
61
61
  "tsdown": {
62
62
  "fixedExtension": false,
@@ -1,188 +0,0 @@
1
- import { Context, Effect, Layer, Option, Schema } from "effect";
2
- import { CommitBoundary, StreamAddress, Streamsy } from "@streamsy/core";
3
- import { OwnerRecords } from "@streamsy/core/internal";
4
- /** Declaration order of the map is the read and item order of every pass. */
5
- type InputMap = Record<string, Streamsy.Address<unknown, unknown>>;
6
- type ItemOf<Address> = Address extends StreamAddress.StreamAddress<infer A> ? A : never;
7
- interface Slice<A> {
8
- /** Cursor the read started after. Equal to `nextOffset` when the slice is empty. */
9
- readonly from: string;
10
- readonly items: ReadonlyArray<A>;
11
- /**
12
- * One storage offset per item, also the read cursor just after that item.
13
- * For a non-empty local slice, offsets.at(-1) === nextOffset. Undefined for
14
- * non-empty HTTP reads; empty slices always have offsets: [].
15
- */
16
- readonly offsets?: ReadonlyArray<string>;
17
- readonly nextOffset: string;
18
- readonly upToDate: boolean;
19
- readonly closed: boolean;
20
- /** The input is gone. This final unit is followed by forgetting the binding. */
21
- readonly gone?: boolean;
22
- }
23
- type Slices<Inputs extends InputMap> = { readonly [K in keyof Inputs]: Slice<ItemOf<Inputs[K]>>; };
24
- /** One item tagged with its input; `index` is its position in the whole unit. */
25
- type Entry<Inputs extends InputMap> = { readonly [K in keyof Inputs]: {
26
- readonly input: K;
27
- readonly item: ItemOf<Inputs[K]>;
28
- readonly index: number;
29
- /** Storage offset of this item; reading from it resumes after the item. Absent over HTTP. */
30
- readonly offset?: string;
31
- }; }[keyof Inputs];
32
- type InputServices<Inputs extends InputMap> = Inputs[keyof Inputs]["stream"]["Identifier"];
33
- /** A typed handler failure bearing this marker stops its binding without retry. */
34
- declare const NonRetryable: unique symbol;
35
- declare const NotAttached_base: Schema.Class<NotAttached, Schema.TaggedStruct<"NotAttached", {
36
- readonly projection: Schema.String;
37
- }>, import("effect/Cause").YieldableError>;
38
- /** No live runner for this declaration exists in the selected registry. */
39
- declare class NotAttached extends NotAttached_base {}
40
- declare const InvalidBinding_base: Schema.Class<InvalidBinding, Schema.TaggedStruct<"InvalidBinding", {
41
- readonly projection: Schema.String;
42
- readonly params: Schema.$Record<Schema.String, Schema.String>;
43
- }>, import("effect/Cause").YieldableError>;
44
- /** Encoded params do not round-trip through the attached declaration's codecs. */
45
- declare class InvalidBinding extends InvalidBinding_base {}
46
- declare const ProjectionFault_base: Schema.Class<ProjectionFault, Schema.TaggedStruct<"ProjectionFault", {
47
- readonly phase: Schema.Literals<readonly ["load", "read", "pin", "process", "checkpoint"]>;
48
- readonly reason: Schema.Literals<readonly ["history-unavailable", "identity-mismatch", "invalid-record", "invalid-source", "invalid-options", "invalid-output", "token-conflict", "output-busy", "range-unreproducible", "stale-epoch", "retired-generation", "storage-failure", "unsupported-composition"]>;
49
- readonly input: Schema.optionalKey<Schema.String>;
50
- readonly message: Schema.String;
51
- readonly cause: Schema.optionalKey<Schema.Defect>;
52
- }>, import("effect/Cause").YieldableError>;
53
- /** Phase says where the run stopped; a `checkpoint` failure means processing already completed. */
54
- declare class ProjectionFault extends ProjectionFault_base {
55
- get retryable(): boolean;
56
- }
57
- declare const Range: Schema.Struct<{
58
- readonly closed: Schema.optionalKey<Schema.Boolean>;
59
- readonly gone: Schema.optionalKey<Schema.Literal<true>>;
60
- readonly from: Schema.String;
61
- readonly nextOffset: Schema.String;
62
- }>;
63
- interface Range extends Schema.Schema.Type<typeof Range> {}
64
- /** `params` holds the decoded values the declaration was bound with. Keys use the encoded strings. */
65
- interface Unit<P = Record<string, string>> {
66
- readonly projectionId: string;
67
- readonly generation: number;
68
- readonly params: P;
69
- /** The inputs that contributed items or a terminal outcome; retries reproduce these. */
70
- readonly ranges: Record<string, Range>;
71
- /** Recorded wake time, rather than the clock time when this unit runs. */
72
- readonly due: Option.Option<number>;
73
- readonly key: string;
74
- }
75
- declare const CheckpointRecord: Schema.Struct<{
76
- readonly identity: Schema.Struct<{
77
- readonly inputs: Schema.$Record<Schema.String, Schema.String>;
78
- }>;
79
- /** Input key to accepted offset; the next pass reads after these. */
80
- readonly inputs: Schema.$Record<Schema.String, Schema.String>;
81
- readonly pending: Schema.optionalKey<Schema.Struct<{
82
- readonly ranges: Schema.$Record<Schema.String, Schema.Struct<{
83
- readonly closed: Schema.optionalKey<Schema.Boolean>;
84
- readonly gone: Schema.optionalKey<Schema.Literal<true>>;
85
- readonly from: Schema.String;
86
- readonly nextOffset: Schema.String;
87
- readonly count: Schema.Finite;
88
- readonly upToDate: Schema.optionalKey<Schema.Boolean>;
89
- }>>;
90
- readonly due: Schema.optionalKey<Schema.Finite>;
91
- readonly seqs: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Finite>>;
92
- }>>;
93
- /** Next process wake, in epoch milliseconds. Absent means no timer. */
94
- readonly wakeAt: Schema.optionalKey<Schema.Finite>;
95
- /** Inputs whose terminal close has already been processed. */
96
- readonly closed: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Boolean>>;
97
- /** The final gone unit committed; only forgetting remains. */
98
- readonly ended: Schema.optionalKey<Schema.Literal<true>>;
99
- readonly state: Schema.optionalKey<Schema.String>;
100
- readonly adapters: Schema.Struct<{
101
- readonly outputs: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
102
- readonly epoch: Schema.Finite;
103
- readonly nextSeq: Schema.Finite;
104
- }>>>;
105
- }>;
106
- }>;
107
- interface CheckpointRecord extends Schema.Schema.Type<typeof CheckpointRecord> {}
108
- type RetirementStatus = "retired" | "already-retired";
109
- interface ProjectionKey {
110
- readonly id: string;
111
- readonly generation: number;
112
- readonly params: Record<string, string>;
113
- }
114
- declare const recordKey: (key: ProjectionKey) => string;
115
- interface Loaded {
116
- readonly record: Option.Option<CheckpointRecord>;
117
- readonly token: string;
118
- }
119
- /** A binding found by `CheckpointStoreApi.list`. */
120
- interface ListedBinding {
121
- readonly generation: number;
122
- readonly params: Record<string, string>;
123
- }
124
- interface RoutedStreamRecord {
125
- readonly output: string;
126
- readonly streamId: string;
127
- }
128
- /** Access the route inventory in the checkpoint owner's transaction. */
129
- interface RouteRecords {
130
- /** Whether this output owns the stream, including after a forget. */
131
- readonly has: (key: ProjectionKey, output: string, streamId: string) => Effect.Effect<boolean, ProjectionFault>;
132
- readonly state: (key: ProjectionKey, output: string, streamId: string) => Effect.Effect<"absent" | "live" | "forgotten", ProjectionFault>;
133
- readonly add: (key: ProjectionKey, output: string, streamId: string) => Effect.Effect<void, ProjectionFault>;
134
- /** Lists every route record for the key in unspecified order. */
135
- readonly list: (key: ProjectionKey) => Effect.Effect<ReadonlyArray<RoutedStreamRecord>, ProjectionFault>;
136
- /** Mark every route record for the key as forgotten. An absent checkpoint can tolerate unsupported listing. */
137
- readonly forget: (key: ProjectionKey, options?: {
138
- readonly ignoreUnsupportedList?: boolean;
139
- }) => Effect.Effect<void, ProjectionFault>;
140
- readonly clear: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault>;
141
- }
142
- interface CheckpointStoreApi {
143
- readonly load: (key: ProjectionKey) => Effect.Effect<Loaded, ProjectionFault>;
144
- /**
145
- * Lists each generation and encoded params with a live checkpoint for an id.
146
- * Reads every stored version slot, including legacy slots. Each pair appears once,
147
- * in unspecified order.
148
- */
149
- readonly list?: (id: string) => Effect.Effect<ReadonlyArray<ListedBinding>, ProjectionFault>;
150
- /** Generation-owned streams opened lazily by routed outputs. */
151
- readonly routes?: RouteRecords;
152
- /** Compare-and-set inside the owner transaction; returns the new token. */
153
- readonly compareAndSet: (key: ProjectionKey, ifToken: string, record: CheckpointRecord) => Effect.Effect<string, ProjectionFault>;
154
- /** Deletes a live record. Absent keys and tombstones are ignored. */
155
- readonly remove: (key: ProjectionKey) => Effect.Effect<void, ProjectionFault>;
156
- /** Replaces a live, absent or undecodable record with a tombstone. */
157
- readonly retire?: (key: ProjectionKey) => Effect.Effect<RetirementStatus, ProjectionFault>;
158
- }
159
- type EncodedEntries = ReadonlyArray<readonly [key: string, encoded: string]>;
160
- declare const CheckpointStore_base: Context.ServiceClass<CheckpointStore, "@streamsy/projection/CheckpointStore", CheckpointStoreApi>;
161
- /** Stores each projection's offsets and encoded state in one compare-and-set record. */
162
- declare class CheckpointStore extends CheckpointStore_base {
163
- /**
164
- * Checkpoints on the storage owner, in its transaction. Works over every Streamsy
165
- * storage host, so checkpoints and streams always share one owner.
166
- */
167
- static readonly layer: Layer.Layer<CheckpointStore, never, CommitBoundary | OwnerRecords>;
168
- /** An independent store for rebuilt values and tests. It shares no owner with streams. */
169
- static readonly layerMemory: Layer.Layer<CheckpointStore, never, never>;
170
- }
171
- /** The encoded seam a checkpoint Layer builds on; both shipped Layers use it. */
172
- interface EncodedStore {
173
- /** A snapshot of the stored entries whose keys start with the exact prefix. */
174
- readonly list?: (prefix: string) => Effect.Effect<EncodedEntries, ProjectionFault>;
175
- readonly read: (key: string) => Effect.Effect<Option.Option<string>, ProjectionFault>;
176
- readonly write: (key: string, value: string) => Effect.Effect<void, ProjectionFault>;
177
- readonly remove: (key: string) => Effect.Effect<void, ProjectionFault>;
178
- readonly withTransaction: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E | ProjectionFault, R>;
179
- }
180
- declare const fromStore: (store: EncodedStore) => CheckpointStoreApi;
181
- /** What the kernel needs to locate a record; every projection value satisfies it. */
182
- interface Identity {
183
- readonly id: string;
184
- readonly generation: number;
185
- readonly params: Record<string, string>;
186
- readonly inputs: InputMap;
187
- }
188
- export { ItemOf as C, InputServices as S, Slices as T, NonRetryable as _, Identity as a, Entry as b, ProjectionKey as c, RoutedStreamRecord as d, fromStore as f, InvalidBinding as g, Unit as h, EncodedStore as i, RetirementStatus as l, Range as m, CheckpointStore as n, ListedBinding as o, recordKey as p, CheckpointStoreApi as r, Loaded as s, CheckpointRecord as t, RouteRecords as u, NotAttached as v, Slice as w, InputMap as x, ProjectionFault as y };