@shivaedev/changes 0.7.0 → 0.9.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/CHANGELOG.md +17 -0
- package/README.md +33 -26
- package/dist/capture.d.ts +15 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +12 -0
- package/dist/capture.js.map +1 -0
- package/dist/commandPublication.d.ts +16 -0
- package/dist/commandPublication.d.ts.map +1 -0
- package/dist/commandPublication.js +11 -0
- package/dist/commandPublication.js.map +1 -0
- package/dist/keys.d.ts +3 -5
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +7 -7
- package/dist/keys.js.map +1 -1
- package/package.json +3 -3
- package/src/capture.ts +31 -0
- package/src/commandPublication.ts +18 -0
- package/src/keys.ts +8 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0 - 2026-11-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `commandPublication.ts` exports the `CommandPublication` port, its `CommandPublisher` interface and typed `CommandPublicationError`. The default publishes local Reactivity invalidations.
|
|
8
|
+
- Add `collectionInvalidationKeys` to refresh every list, item and bucket reader of a collection, with optional session scoping. Bucket read dependencies now include the collection wildcard.
|
|
9
|
+
|
|
10
|
+
### Breaking
|
|
11
|
+
|
|
12
|
+
- `@shivaedev/changes/keys.ts` no longer accepts a context argument in `readKeys`, `invalidationKeys` or `collectionInvalidationKeys`. Remove account prefixes and context arguments from server registrations and publications; use plain model record and bucket keys. For custom client cache coordination, import `KeyContext`, `clientReadKeys` and `clientInvalidationKeys` from `@shivaedev/contract/clientKeys.ts` instead. `bind` and `makeClient` handle this automatically.
|
|
13
|
+
|
|
14
|
+
## 0.8.0 - 2026-11-02
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Capture recorded, attempted and discarded change batches through `makeCapture` and its Layer while preserving delivery and enclosing observations.
|
|
19
|
+
|
|
3
20
|
## 0.7.0 - 2026-11-02
|
|
4
21
|
|
|
5
22
|
### Added
|
package/README.md
CHANGED
|
@@ -98,6 +98,19 @@ When interruption arrives while commit is in flight, the boundary waits for the
|
|
|
98
98
|
|
|
99
99
|
Concurrent records from Effects that inherit the same frame join that frame and publish together. Keep all write-related work within the transaction's lifetime.
|
|
100
100
|
|
|
101
|
+
### Publish a command's changes
|
|
102
|
+
|
|
103
|
+
`CommandPublication` from `@shivaedev/changes/commandPublication.ts` is the public port for announcing a command's declared keys after its write commits. Its `publish(keys)` operation defaults to local Reactivity invalidation. The PostgreSQL `postgresChanges` Layer supplies a binding that buffers publication within an enclosing `transact` transaction, publishes only after commit and discards keys on rollback.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { CommandPublication } from "@shivaedev/changes/commandPublication.ts";
|
|
107
|
+
|
|
108
|
+
const publication = yield* CommandPublication;
|
|
109
|
+
yield* publication.publish(["notes:1"]);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Both `publish` and `recover` have `CommandPublicationError` in their typed failure channel; its `cause` preserves the Effect cause. A failed announcement does not undo a committed write. The command boundary handles publication failure separately from the write and can run `publication.recover`. The PostgreSQL binding resynchronizes local streams and broadcasts Resync to other hosts; identity's command wrapper keeps the committed result even when publication or recovery fails.
|
|
113
|
+
|
|
101
114
|
### Record keys and buckets
|
|
102
115
|
|
|
103
116
|
`keys.ts` owns the shared dependency format for contract queries, committed writes and subscriptions. An item key identifies a record by id. A bucket identifies every row with a declared field value; a collection list key covers the whole collection.
|
|
@@ -111,7 +124,7 @@ const keys = [notes.item(1), notes.bucket.userId("alice"), notes.bucket.listId(4
|
|
|
111
124
|
const invalidations = invalidationKeys(keys);
|
|
112
125
|
```
|
|
113
126
|
|
|
114
|
-
Use `readKeys(keys)` to register dependencies with native Reactivity and `invalidationKeys(keys)` when announcing committed writes. A bucket changes when the writer names it; SQL repositories derive those names from model fields marked with `bucket`. Its value is typed by the declared field schema. A filtered list query still reads its entire bucket and reruns when any row there changes. Record changes also invalidate the collection list, while buckets remain explicit. The channel can buffer these keys until commit just like any other change vocabulary.
|
|
127
|
+
Use `readKeys(keys)` to register dependencies with native Reactivity and `invalidationKeys(keys)` when announcing committed writes. A bucket changes when the writer names it; SQL repositories derive those names from model fields marked with `bucket`. Its value is typed by the declared field schema. A filtered list query still reads its entire bucket and reruns when any row there changes. Record changes also invalidate the collection list, while buckets remain explicit. Use `collectionInvalidationKeys(name)` to refresh all list, item and bucket readers of a collection when a bulk operation cannot name individual rows. Item and bucket dependencies include a collection wildcard for these refreshes; ordinary item and bucket invalidations remain precise. Server keys are shared across sessions; each subscriber’s read policy controls delivery. The channel can buffer these keys until commit just like any other change vocabulary.
|
|
115
128
|
|
|
116
129
|
For composite SQL identities, use `compositeId(values)` with stored key values in the repository's `idColumn` order, then pass the resulting string to `collection(name, Schema.String).item(id)`. It encodes the values as a JSON array, with bigint components represented as decimal strings. Repository writes use the same encoder, so the subscriber and writer identify the same record. `recordKey(collection, id)` builds a raw record dependency for native Reactivity; typed item keys use it too.
|
|
117
130
|
|
|
@@ -161,28 +174,21 @@ Set `onPublishFailure: "die"` when that same delivery failure should raise a def
|
|
|
161
174
|
### Capture notifications in tests
|
|
162
175
|
|
|
163
176
|
```ts
|
|
164
|
-
import
|
|
165
|
-
import { Layer } from "effect";
|
|
177
|
+
import { makeCapture } from "@shivaedev/changes/capture.ts";
|
|
166
178
|
|
|
167
|
-
const
|
|
168
|
-
|
|
179
|
+
const capture = yield* makeCapture<MembershipChange>();
|
|
180
|
+
yield* grant("ada", "bob").pipe(Effect.provide(capture.layer(membershipChanges.Observer)));
|
|
169
181
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
);
|
|
182
|
+
const recorded = yield* capture.recorded;
|
|
183
|
+
const attempted = yield* capture.attempted;
|
|
184
|
+
const discarded = yield* capture.discarded;
|
|
185
|
+
```
|
|
175
186
|
|
|
176
|
-
|
|
177
|
-
Effect.sync(() => {
|
|
178
|
-
observations.push(observation);
|
|
179
|
-
}),
|
|
180
|
-
);
|
|
187
|
+
Create a capture for each test, then provide its `layer(observer)` around the complete operation, including the transaction boundary. Each readout returns a snapshot of change batches in observation order. `recorded` contains the distinct changes from each record call; `attempted` contains the deduplicated changes passed to publication; `discarded` contains rolled-back changes, including rolled-back savepoints. Repeated record calls remain separate in `recorded` even when the transaction publishes their shared key once.
|
|
181
188
|
|
|
182
|
-
|
|
183
|
-
```
|
|
189
|
+
An attempt is observed before the sink runs, so `attempted` does not prove delivery. The Layer leaves the sink in place and forwards observations to the enclosing observer. Writes outside the Layer do not enter its readouts. Capture does not infer inserts from refresh keys: retain the write's returned ids when a story needs to identify created rows.
|
|
184
190
|
|
|
185
|
-
`Sink` and `Observer` are channel-specific `Context.Reference`s.
|
|
191
|
+
`Sink` and `Observer` are channel-specific `Context.Reference`s. Provide `Sink` to replace delivery in a scope. The observer receives `Recorded`, `Published` and `Discarded` observations; `Published` names a publication attempt. A synchronous throw or Effect defect from the observer is logged without blocking sink delivery or changing the transaction's outcome.
|
|
186
192
|
|
|
187
193
|
### Work inside the committing transaction
|
|
188
194
|
|
|
@@ -194,14 +200,15 @@ A direct driver binding using `open` must run `frame.beforeCommit` inside its tr
|
|
|
194
200
|
|
|
195
201
|
Import from the module that defines the name; the package has no root entry.
|
|
196
202
|
|
|
197
|
-
| Module | Names
|
|
198
|
-
| ------------------------------- |
|
|
199
|
-
| `@shivaedev/changes/channel.ts` | `makeChannel`, `ChannelOptions`, `Channel`, `BeforeCommit`
|
|
200
|
-
| `@shivaedev/changes/frame.ts` | `Frame`, `CommitFrame`, `Outcome`
|
|
201
|
-
| `@shivaedev/changes/
|
|
202
|
-
| `@shivaedev/changes/
|
|
203
|
-
| `@shivaedev/changes/
|
|
204
|
-
| `@shivaedev/changes/
|
|
203
|
+
| Module | Names |
|
|
204
|
+
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
205
|
+
| `@shivaedev/changes/channel.ts` | `makeChannel`, `ChannelOptions`, `Channel`, `BeforeCommit` |
|
|
206
|
+
| `@shivaedev/changes/frame.ts` | `Frame`, `CommitFrame`, `Outcome` |
|
|
207
|
+
| `@shivaedev/changes/capture.ts` | `makeCapture`, `Capture` |
|
|
208
|
+
| `@shivaedev/changes/observe.ts` | `Observation`, `Observer` |
|
|
209
|
+
| `@shivaedev/changes/publish.ts` | `Publish`, `PublishFailure` |
|
|
210
|
+
| `@shivaedev/changes/keys.ts` | `collection`, `collectionInvalidationKeys`, `compositeId`, `recordKey`, `readKeys`, `invalidationKeys`, `Key`, `ListKey`, `ItemKey`, `BucketKey`, `Collection`, `Identity` |
|
|
211
|
+
| `@shivaedev/changes/buckets.ts` | `bucket`, `declaredBuckets` |
|
|
205
212
|
|
|
206
213
|
A `Channel` exposes `record`, `within`, `batch` and `open`, and the scoped references `Sink`, `CommittedSink`, `Observer` and `BeforeCommit`.
|
|
207
214
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Context, Effect, Layer } from "effect";
|
|
2
|
+
import type { Observer } from "./observe.ts";
|
|
3
|
+
export interface Capture<A> {
|
|
4
|
+
readonly attempted: Effect.Effect<readonly (readonly A[])[]>;
|
|
5
|
+
readonly discarded: Effect.Effect<readonly (readonly A[])[]>;
|
|
6
|
+
readonly layer: (observer: Context.Reference<Observer<A>>) => Layer.Layer<never>;
|
|
7
|
+
readonly recorded: Effect.Effect<readonly (readonly A[])[]>;
|
|
8
|
+
}
|
|
9
|
+
export declare const makeCapture: <A>() => Effect.Effect<{
|
|
10
|
+
attempted: Effect.Effect<A[][], never, never>;
|
|
11
|
+
discarded: Effect.Effect<A[][], never, never>;
|
|
12
|
+
layer: (observer: Context.Reference<Observer<A>>) => Layer.Layer<never>;
|
|
13
|
+
recorded: Effect.Effect<A[][], never, never>;
|
|
14
|
+
}, never, never>;
|
|
15
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,KAAK,EAAO,MAAM,QAAQ,CAAC;AAC1D,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,WAAW,OAAO,CAAC,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC7D,QAAQ,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;CAC5D;AAED,eAAO,MAAM,WAAW,GAA+C,CAAC;;;sBAE9C,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;;gBAkB3E,CAAC"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect, Layer, Ref } from "effect";
|
|
2
|
+
export const makeCapture = Effect.fn("Changes.makeCapture")(function* () {
|
|
3
|
+
const observations = yield* Ref.make([]);
|
|
4
|
+
function layer(observer) {
|
|
5
|
+
return Layer.effect(observer, Effect.map(observer, (parent) => (event) => Effect.andThen(Ref.update(observations, (events) => [...events, { ...event, changes: [...event.changes] }]), Effect.suspend(() => parent(event)))));
|
|
6
|
+
}
|
|
7
|
+
function read(tag) {
|
|
8
|
+
return Effect.map(Ref.get(observations), (events) => events.filter((event) => event._tag === tag).map((event) => [...event.changes]));
|
|
9
|
+
}
|
|
10
|
+
return { attempted: read("Published"), discarded: read("Discarded"), layer, recorded: read("Recorded") };
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAU1D,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC;IACpE,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAA4B,EAAE,CAAC,CAAC;IACpE,SAAS,KAAK,CAAC,QAAwC;QACtD,OAAO,KAAK,CAAC,MAAM,CAClB,QAAQ,EACR,MAAM,CAAC,GAAG,CACT,QAAQ,EACR,CAAC,MAAM,EAAe,EAAE,CACvB,CAAC,KAAK,EAAE,EAAE,CACT,MAAM,CAAC,OAAO,CACb,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAC5F,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CACnC,CACH,CACD,CAAC;IACH,CAAC;IACD,SAAS,IAAI,CAAC,GAA2B;QACxC,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACvI,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,EAAuB,CAAC;AAC/H,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Cause, Context, Effect } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
declare const CommandPublicationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Cause.YieldableError & {
|
|
4
|
+
readonly _tag: "CommandPublicationError";
|
|
5
|
+
} & Readonly<A>;
|
|
6
|
+
export declare class CommandPublicationError extends CommandPublicationError_base<{
|
|
7
|
+
readonly cause: Cause.Cause<unknown>;
|
|
8
|
+
}> {
|
|
9
|
+
}
|
|
10
|
+
export interface CommandPublisher {
|
|
11
|
+
readonly publish: (keys: readonly unknown[]) => Effect.Effect<void, CommandPublicationError, Reactivity.Reactivity>;
|
|
12
|
+
readonly recover: Effect.Effect<void, CommandPublicationError>;
|
|
13
|
+
}
|
|
14
|
+
export declare const CommandPublication: Context.Reference<CommandPublisher>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=commandPublication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandPublication.d.ts","sourceRoot":"","sources":["../src/commandPublication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;;;;AAE3D,qBAAa,uBAAwB,SAAQ,6BAA4C;IACxF,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;CACrC,CAAC;CAAG;AAEL,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,uBAAuB,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACpH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;CAC/D;AAED,eAAO,MAAM,kBAAkB,qCAK7B,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context, Data, Effect } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
export class CommandPublicationError extends Data.TaggedError("CommandPublicationError") {
|
|
4
|
+
}
|
|
5
|
+
export const CommandPublication = Context.Reference("@shivaedev/changes/CommandPublication", {
|
|
6
|
+
defaultValue: () => ({
|
|
7
|
+
publish: (keys) => Reactivity.invalidate(keys).pipe(Effect.catchCause((cause) => Effect.fail(new CommandPublicationError({ cause })))),
|
|
8
|
+
recover: Effect.void,
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=commandPublication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandPublication.js","sourceRoot":"","sources":["../src/commandPublication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAC;AAE3D,MAAM,OAAO,uBAAwB,SAAQ,IAAI,CAAC,WAAW,CAAC,yBAAyB,CAErF;CAAG;AAOL,MAAM,CAAC,MAAM,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAmB,uCAAuC,EAAE;IAC9G,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;QACpB,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,uBAAuB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACtI,OAAO,EAAE,MAAM,CAAC,IAAI;KACpB,CAAC;CACF,CAAC,CAAC"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -46,10 +46,8 @@ export interface Collection<TName extends string, TId extends Identity, TFields
|
|
|
46
46
|
export declare function collection<const TName extends string, TId extends Schema.Top & {
|
|
47
47
|
readonly Type: Identity;
|
|
48
48
|
}, const TFields extends BucketFields = Record<never, never>>(name: TName, _id: TId, fields?: TFields): Collection<TName, TId["Type"], TFields>;
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export declare function readKeys(keys: readonly Key[], context?: KeyContext): readonly string[];
|
|
53
|
-
export declare function invalidationKeys(keys: readonly Key[], context?: KeyContext): readonly string[];
|
|
49
|
+
export declare function readKeys(keys: readonly Key[]): readonly string[];
|
|
50
|
+
export declare function collectionInvalidationKeys(name: string): readonly string[];
|
|
51
|
+
export declare function invalidationKeys(keys: readonly Key[]): readonly string[];
|
|
54
52
|
export {};
|
|
55
53
|
//# sourceMappingURL=keys.d.ts.map
|
package/dist/keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAa,MAAM,QAAQ,CAAC;AAEjD,MAAM,MAAM,QAAQ,GAAG,MAAM,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AK,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3C,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;CACrB;AAED,wBAAgB,UAAU,CACzB,KAAK,CAAC,KAAK,SAAS,MAAM,EAC1B,GAAG,SAAS,MAAM,CAAC,GAAG,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,EACpD,KAAK,CAAC,OAAO,SAAS,YAAY,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxD,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC;AAuBpF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,SAAS,MAAM,EAAE,CAEhE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE1E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,SAAS,MAAM,EAAE,CAExE"}
|
package/dist/keys.js
CHANGED
|
@@ -48,9 +48,6 @@ export function collection(name, _id, fields = {}) {
|
|
|
48
48
|
name,
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
function contextual(key, context) {
|
|
52
|
-
return context === undefined ? key : `${JSON.stringify(["session", context.scope])}:${key}`;
|
|
53
|
-
}
|
|
54
51
|
function own(key) {
|
|
55
52
|
switch (key._tag) {
|
|
56
53
|
case "List":
|
|
@@ -61,10 +58,13 @@ function own(key) {
|
|
|
61
58
|
return JSON.stringify(["bucket", key.collection, key.field, key.value]);
|
|
62
59
|
}
|
|
63
60
|
}
|
|
64
|
-
export function readKeys(keys
|
|
65
|
-
return [...new Set(keys.flatMap((key) => (key._tag === "
|
|
61
|
+
export function readKeys(keys) {
|
|
62
|
+
return [...new Set(keys.flatMap((key) => (key._tag === "List" ? [own(key)] : [own(key), `${key.collection}:*`])))];
|
|
63
|
+
}
|
|
64
|
+
export function collectionInvalidationKeys(name) {
|
|
65
|
+
return [name, `${name}:*`];
|
|
66
66
|
}
|
|
67
|
-
export function invalidationKeys(keys
|
|
68
|
-
return [...new Set(keys.flatMap((key) => (key._tag === "Item" ? [own(key), key.collection] : [own(key)])))]
|
|
67
|
+
export function invalidationKeys(keys) {
|
|
68
|
+
return [...new Set(keys.flatMap((key) => (key._tag === "Item" ? [own(key), key.collection] : [own(key)])))];
|
|
69
69
|
}
|
|
70
70
|
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAIjD,MAAM,UAAU,cAAc,CAAC,MAAyB;IACvD,SAAS,SAAS,CAAC,GAAkB;QACpC,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,iBAAiB,CAAC;YACvB,KAAK,MAAM,CAAC;YACZ,KAAK,MAAM,CAAC;YACZ,KAAK,WAAW,CAAC;YACjB,KAAK,MAAM,CAAC;YACZ,KAAK,OAAO;gBACX,OAAO,IAAI,CAAC;YACb,KAAK,SAAS;gBACb,OAAO,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC;YAC3E,KAAK,OAAO;gBACX,OAAO,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;YACnC,KAAK,SAAS;gBACb,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,G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C,CAAC,CAAC,CAAC,CAAC;AAC7G,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/changes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Commit-bound change channels for Effect: publish recorded changes only after the transaction commits",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"README.md"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@shivaedev/quality": "0.
|
|
47
|
-
"@shivaedev/test-story": "0.
|
|
46
|
+
"@shivaedev/quality": "0.57.0",
|
|
47
|
+
"@shivaedev/test-story": "0.35.0",
|
|
48
48
|
"@types/node": "24.19.2",
|
|
49
49
|
"effect": "4.0.6",
|
|
50
50
|
"typescript": "7.0.2",
|
package/src/capture.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Context, Effect, Layer, Ref } from "effect";
|
|
2
|
+
import type { Observation, Observer } from "./observe.ts";
|
|
3
|
+
|
|
4
|
+
export interface Capture<A> {
|
|
5
|
+
readonly attempted: Effect.Effect<readonly (readonly A[])[]>;
|
|
6
|
+
readonly discarded: Effect.Effect<readonly (readonly A[])[]>;
|
|
7
|
+
readonly layer: (observer: Context.Reference<Observer<A>>) => Layer.Layer<never>;
|
|
8
|
+
readonly recorded: Effect.Effect<readonly (readonly A[])[]>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const makeCapture = Effect.fn("Changes.makeCapture")(function* <A>() {
|
|
12
|
+
const observations = yield* Ref.make<readonly Observation<A>[]>([]);
|
|
13
|
+
function layer(observer: Context.Reference<Observer<A>>): Layer.Layer<never> {
|
|
14
|
+
return Layer.effect(
|
|
15
|
+
observer,
|
|
16
|
+
Effect.map(
|
|
17
|
+
observer,
|
|
18
|
+
(parent): Observer<A> =>
|
|
19
|
+
(event) =>
|
|
20
|
+
Effect.andThen(
|
|
21
|
+
Ref.update(observations, (events) => [...events, { ...event, changes: [...event.changes] }]),
|
|
22
|
+
Effect.suspend(() => parent(event)),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
function read(tag: Observation<A>["_tag"]) {
|
|
28
|
+
return Effect.map(Ref.get(observations), (events) => events.filter((event) => event._tag === tag).map((event) => [...event.changes]));
|
|
29
|
+
}
|
|
30
|
+
return { attempted: read("Published"), discarded: read("Discarded"), layer, recorded: read("Recorded") } satisfies Capture<A>;
|
|
31
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Cause, Context, Data, Effect } from "effect";
|
|
2
|
+
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
|
+
|
|
4
|
+
export class CommandPublicationError extends Data.TaggedError("CommandPublicationError")<{
|
|
5
|
+
readonly cause: Cause.Cause<unknown>;
|
|
6
|
+
}> {}
|
|
7
|
+
|
|
8
|
+
export interface CommandPublisher {
|
|
9
|
+
readonly publish: (keys: readonly unknown[]) => Effect.Effect<void, CommandPublicationError, Reactivity.Reactivity>;
|
|
10
|
+
readonly recover: Effect.Effect<void, CommandPublicationError>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const CommandPublication = Context.Reference<CommandPublisher>("@shivaedev/changes/CommandPublication", {
|
|
14
|
+
defaultValue: () => ({
|
|
15
|
+
publish: (keys) => Reactivity.invalidate(keys).pipe(Effect.catchCause((cause) => Effect.fail(new CommandPublicationError({ cause })))),
|
|
16
|
+
recover: Effect.void,
|
|
17
|
+
}),
|
|
18
|
+
});
|
package/src/keys.ts
CHANGED
|
@@ -90,14 +90,6 @@ export function collection(name: string, _id: Schema.Top, fields: BucketFields =
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export interface KeyContext {
|
|
94
|
-
readonly scope: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function contextual(key: string, context?: KeyContext): string {
|
|
98
|
-
return context === undefined ? key : `${JSON.stringify(["session", context.scope])}:${key}`;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
93
|
function own(key: Key): string {
|
|
102
94
|
switch (key._tag) {
|
|
103
95
|
case "List":
|
|
@@ -109,12 +101,14 @@ function own(key: Key): string {
|
|
|
109
101
|
}
|
|
110
102
|
}
|
|
111
103
|
|
|
112
|
-
export function readKeys(keys: readonly Key[]
|
|
113
|
-
return [...new Set(keys.flatMap((key) => (key._tag === "
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
export function readKeys(keys: readonly Key[]): readonly string[] {
|
|
105
|
+
return [...new Set(keys.flatMap((key) => (key._tag === "List" ? [own(key)] : [own(key), `${key.collection}:*`])))];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function collectionInvalidationKeys(name: string): readonly string[] {
|
|
109
|
+
return [name, `${name}:*`];
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
export function invalidationKeys(keys: readonly Key[]
|
|
119
|
-
return [...new Set(keys.flatMap((key) => (key._tag === "Item" ? [own(key), key.collection] : [own(key)])))]
|
|
112
|
+
export function invalidationKeys(keys: readonly Key[]): readonly string[] {
|
|
113
|
+
return [...new Set(keys.flatMap((key) => (key._tag === "Item" ? [own(key), key.collection] : [own(key)])))];
|
|
120
114
|
}
|