@shivaedev/changes 0.5.0 → 0.6.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 +22 -0
- package/README.md +72 -73
- package/dist/keys.d.ts +2 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +9 -2
- package/dist/keys.js.map +1 -1
- package/package.json +5 -5
- package/src/keys.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 - 2026-10-30
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `changes/keys.ts` exports `recordKey` for raw record dependencies and `compositeId` for composite identities, including bigint components encoded as decimal strings.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- SQL repository writes and manual invalidations build record keys through `changes/keys.ts`, sharing the format used by subscriptions. Existing key strings remain unchanged.
|
|
12
|
+
|
|
13
|
+
## 0.5.1 - 2026-10-30
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Require Effect 4.0.6 and align the Effect companion package peers and generated starter catalog to the same exact release. Install the 4.0.6 Effect stack together.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- Register hosted RPC cache-control handling through Effect 4.0.6's request-scoped pre-response API so responses keep `private, no-store`.
|
|
22
|
+
- Accept native RPC's `application/x-ndjson` media type while preserving `application/ndjson` callers at the transport guard.
|
|
23
|
+
- Keep subscriptions open after their HTTP request body completes; closing the socket still cancels them.
|
|
24
|
+
|
|
3
25
|
## 0.5.0 - 2026-10-28
|
|
4
26
|
|
|
5
27
|
### Added
|
package/README.md
CHANGED
|
@@ -18,33 +18,6 @@ yield* Effect.gen(function* () {
|
|
|
18
18
|
|
|
19
19
|
`membershipChanges` is the channel defined below. It groups notifications by subject and domain, so another write to the same member inside this transaction does not add a second notification. A nested transaction that rolls back contributes no notification, and a failed outer commit publishes nothing. Feature code describes what changed; the native transaction decides whether it happened.
|
|
20
20
|
|
|
21
|
-
## Record keys and buckets
|
|
22
|
-
|
|
23
|
-
`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.
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { Schema } from "effect";
|
|
27
|
-
import { collection, invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
28
|
-
|
|
29
|
-
const notes = collection("notes", Schema.Number, { userId: Schema.String, listId: Schema.Number });
|
|
30
|
-
const keys = [notes.item(1), notes.bucket.userId("alice"), notes.bucket.listId(42)];
|
|
31
|
-
const invalidations = invalidationKeys(keys);
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
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.
|
|
35
|
-
|
|
36
|
-
`bucket(schema)` from `@shivaedev/changes/buckets.ts` declares a model field as a write bucket without changing its schema type or variants:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { bucket } from "@shivaedev/changes/buckets.ts";
|
|
40
|
-
|
|
41
|
-
const listId = bucket(Schema.NumberFromString);
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
The SQL binding reads these declarations with `declaredBuckets(model.fields)` and decodes old and new stored values into the same identity values queries use. Bucket schemas decode to strings, numbers, null or undefined and require no services. Absent values contribute no key. See the [SQL guide](../sql/README.md#transactions-and-invalidation) for repository writes and PostgreSQL requirements.
|
|
45
|
-
|
|
46
|
-
Query read policies belong to the contract. The query checks its session viewer before its record or bucket scope can become a subscription; a change key grants no read permission. See the [contract query guide](../contract/README.md#query-policies-record-keys-and-buckets).
|
|
47
|
-
|
|
48
21
|
## Using it
|
|
49
22
|
|
|
50
23
|
### How to think about it
|
|
@@ -56,7 +29,6 @@ Owners matter when a program uses more than one database or client. Owner B comm
|
|
|
56
29
|
The channel owns notifications, not writes. Record descriptions of what needs refreshing beside the write that affects it. Choose a key that identifies notifications that can share one refresh; this boundary is for coalescing refresh work, rather than storing every business event.
|
|
57
30
|
|
|
58
31
|
The work has three parts:
|
|
59
|
-
|
|
60
32
|
1. Once per binding, define the change type, owner, key and publish function, and bind the native transaction.
|
|
61
33
|
2. Once per feature, record the subjects affected by each write.
|
|
62
34
|
3. In each operation, run the feature through the transaction boundary or group autocommitted work with a batch.
|
|
@@ -69,19 +41,20 @@ import { Effect } from "effect";
|
|
|
69
41
|
import { SqlClient } from "effect/sql";
|
|
70
42
|
|
|
71
43
|
interface MembershipChange {
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
readonly subject: string;
|
|
45
|
+
readonly domain: string;
|
|
74
46
|
}
|
|
75
47
|
|
|
76
48
|
const published: Array<MembershipChange> = [];
|
|
77
49
|
|
|
78
50
|
const membershipChanges = makeChannel<MembershipChange, SqlClient.SqlClient>({
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
51
|
+
name: "MembershipChanges",
|
|
52
|
+
owner: Effect.map(SqlClient.SqlClient, (sql) => sql.transactionService),
|
|
53
|
+
key: (change) => `${change.subject}:${change.domain}`,
|
|
54
|
+
publish: (changes) =>
|
|
55
|
+
Effect.sync(() => {
|
|
56
|
+
published.push(...changes);
|
|
57
|
+
}),
|
|
85
58
|
});
|
|
86
59
|
```
|
|
87
60
|
|
|
@@ -93,14 +66,14 @@ The owner is the native SQL client's transaction-service identity. The key group
|
|
|
93
66
|
|
|
94
67
|
```ts
|
|
95
68
|
const grantMembership = (owner: string, member: string) =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
69
|
+
Effect.gen(function* () {
|
|
70
|
+
const sql = yield* SqlClient.SqlClient;
|
|
71
|
+
yield* sql`insert into membership (owner, member) values (${owner}, ${member})`;
|
|
72
|
+
yield* membershipChanges.record([
|
|
73
|
+
{ subject: owner, domain: "memberships" },
|
|
74
|
+
{ subject: member, domain: "memberships" },
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
104
77
|
```
|
|
105
78
|
|
|
106
79
|
One write can name several subjects. `record` deduplicates the supplied changes by the channel's key, and the transaction frame deduplicates across later records and committed nested frames. Keys retain their first-seen order.
|
|
@@ -111,12 +84,10 @@ Record while the transaction body is still running. A record or a nested frame o
|
|
|
111
84
|
|
|
112
85
|
```ts
|
|
113
86
|
const grant = (owner: string, member: string) =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
});
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
const sql = yield* SqlClient.SqlClient;
|
|
89
|
+
return yield* grantMembership(owner, member).pipe(membershipChanges.within(sql.withTransaction));
|
|
90
|
+
});
|
|
120
91
|
```
|
|
121
92
|
|
|
122
93
|
Provide the application's native SQL layer when running `grant`. Publication happens after the native transaction succeeds and before the wrapper returns. A typed failure, defect, body interruption or failed commit discards the root frame. A nested commit merges into its parent; a nested rollback leaves the parent's own changes intact.
|
|
@@ -125,12 +96,41 @@ When interruption arrives while commit is in flight, the boundary waits for the
|
|
|
125
96
|
|
|
126
97
|
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.
|
|
127
98
|
|
|
99
|
+
### Record keys and buckets
|
|
100
|
+
|
|
101
|
+
`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.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { Schema } from "effect";
|
|
105
|
+
import { collection, invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
106
|
+
|
|
107
|
+
const notes = collection("notes", Schema.Number, { userId: Schema.String, listId: Schema.Number });
|
|
108
|
+
const keys = [notes.item(1), notes.bucket.userId("alice"), notes.bucket.listId(42)];
|
|
109
|
+
const invalidations = invalidationKeys(keys);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
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.
|
|
113
|
+
|
|
114
|
+
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.
|
|
115
|
+
|
|
116
|
+
`bucket(schema)` from `@shivaedev/changes/buckets.ts` declares a model field as a write bucket without changing its schema type or variants:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { bucket } from "@shivaedev/changes/buckets.ts";
|
|
120
|
+
|
|
121
|
+
const listId = bucket(Schema.NumberFromString);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The SQL binding reads these declarations with `declaredBuckets(model.fields)` and decodes old and new stored values into the same identity values queries use. Bucket schemas decode to strings, numbers, null or undefined and require no services. Absent values contribute no key. See the [SQL guide](https://github.com/ShivaeDev/platform/blob/main/packages/sql/README.md#transactions-and-invalidation) for repository writes and PostgreSQL requirements.
|
|
125
|
+
|
|
126
|
+
Query read policies belong to the contract. The query checks its session viewer before its record or bucket scope can become a subscription; a change key grants no read permission. See the [contract query guide](https://github.com/ShivaeDev/platform/blob/main/packages/contract/README.md#query-policies-record-keys-and-buckets).
|
|
127
|
+
|
|
128
128
|
### Group already-autocommitted writes
|
|
129
129
|
|
|
130
130
|
```ts
|
|
131
131
|
const grantSeveral = Effect.gen(function* () {
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
yield* grantMembership("ada", "bob");
|
|
133
|
+
yield* grantMembership("ada", "cyd");
|
|
134
134
|
}).pipe(membershipChanges.batch);
|
|
135
135
|
```
|
|
136
136
|
|
|
@@ -165,23 +165,19 @@ import { Layer } from "effect";
|
|
|
165
165
|
const captured: Array<MembershipChange> = [];
|
|
166
166
|
const observations: Array<Observation<MembershipChange>> = [];
|
|
167
167
|
|
|
168
|
-
const captureSink = Layer.succeed(
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}),
|
|
168
|
+
const captureSink = Layer.succeed(membershipChanges.Sink, (changes: readonly MembershipChange[]) =>
|
|
169
|
+
Effect.sync(() => {
|
|
170
|
+
captured.push(...changes);
|
|
171
|
+
}),
|
|
173
172
|
);
|
|
174
173
|
|
|
175
|
-
const observe = Layer.succeed(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}),
|
|
174
|
+
const observe = Layer.succeed(membershipChanges.Observer, (observation: Observation<MembershipChange>) =>
|
|
175
|
+
Effect.sync(() => {
|
|
176
|
+
observations.push(observation);
|
|
177
|
+
}),
|
|
180
178
|
);
|
|
181
179
|
|
|
182
|
-
const capturedGrant = grant("ada", "bob").pipe(
|
|
183
|
-
Effect.provide(Layer.merge(captureSink, observe)),
|
|
184
|
-
);
|
|
180
|
+
const capturedGrant = grant("ada", "bob").pipe(Effect.provide(Layer.merge(captureSink, observe)));
|
|
185
181
|
```
|
|
186
182
|
|
|
187
183
|
`Sink` and `Observer` are channel-specific `Context.Reference`s. Within the provided scope, the sink receives the changes instead of the configured publish function; the configured sink resumes outside it. The observer receives `Recorded` for the distinct changes in a record call, `Published` for the buffer passed to publication and `Discarded` for a rolled-back frame's changes. `Published` is emitted before the sink runs; it does not prove successful delivery. Discarded parent changes include changes merged from children that committed earlier. A rollback therefore remains visible to a coverage check through its earlier `Recorded` observation.
|
|
@@ -196,23 +192,26 @@ A direct driver binding using `open` must run `frame.beforeCommit` inside its tr
|
|
|
196
192
|
|
|
197
193
|
Import from the module that defines the name; the package has no root entry.
|
|
198
194
|
|
|
199
|
-
| Module
|
|
200
|
-
|
|
|
201
|
-
|
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
|
|
|
195
|
+
| Module | Names |
|
|
196
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
197
|
+
| `@shivaedev/changes/channel.ts` | `makeChannel`, `ChannelOptions`, `Channel`, `BeforeCommit` |
|
|
198
|
+
| `@shivaedev/changes/frame.ts` | `Frame`, `CommitFrame`, `Outcome` |
|
|
199
|
+
| `@shivaedev/changes/observe.ts` | `Observation`, `Observer` |
|
|
200
|
+
| `@shivaedev/changes/publish.ts` | `Publish`, `PublishFailure` |
|
|
201
|
+
| `@shivaedev/changes/keys.ts` | `collection`, `compositeId`, `recordKey`, `readKeys`, `invalidationKeys`, `Key`, `ListKey`, `ItemKey`, `BucketKey`, `Collection`, `Identity`, `KeyContext` |
|
|
202
|
+
| `@shivaedev/changes/buckets.ts` | `bucket`, `declaredBuckets` |
|
|
203
|
+
|
|
204
|
+
A `Channel` exposes `record`, `within`, `batch` and `open`, and the scoped references `Sink`, `CommittedSink`, `Observer` and `BeforeCommit`.
|
|
205
205
|
|
|
206
206
|
`key` is optional; for string changes, omitting it deduplicates repeated strings. A custom key is useful when a change is a structured description of an affected subject.
|
|
207
207
|
|
|
208
208
|
### Install, setup and limits
|
|
209
209
|
|
|
210
210
|
```sh
|
|
211
|
-
pnpm add @shivaedev/changes effect
|
|
211
|
+
pnpm add @shivaedev/changes effect
|
|
212
212
|
```
|
|
213
213
|
|
|
214
214
|
`effect` is a peer dependency, so the application's Effect version runs the channel. The package declares Node 24 or newer. The SQL example also needs the application's native SQL driver and layer; neither the channel nor its installation creates a database connection or table.
|
|
215
|
-
|
|
216
215
|
- The channel is an in-process notification boundary. It has no persistent outbox, replay or cross-process transport; deployment delivery requires a separate design.
|
|
217
216
|
- Only explicitly recorded changes reach the channel. Trigger, cascade and raw SQL write discovery belongs to a binding or the application.
|
|
218
217
|
- A native adapter must observe the real commit outcome. Wrapping only the body of a transaction does not establish that outcome.
|
package/dist/keys.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
export type Identity = string | number;
|
|
3
|
+
export declare function compositeId(values: readonly unknown[]): string;
|
|
4
|
+
export declare function recordKey(name: string, id: unknown): string;
|
|
3
5
|
export interface ListKey<TName extends string = string> {
|
|
4
6
|
readonly _tag: "List";
|
|
5
7
|
readonly collection: TName;
|
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,
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAE9D;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM,CAG3D;AAED,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;CAC3B;AAED,MAAM,WAAW,OAAO,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACrD,QAAQ,CAAC,IAAI,EAAE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C,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;AAYpF,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAiBD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAItF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAE9F"}
|
package/dist/keys.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Hash, Schema } from "effect";
|
|
2
|
+
export function compositeId(values) {
|
|
3
|
+
return JSON.stringify(values, (_key, value) => (typeof value === "bigint" ? String(value) : value));
|
|
4
|
+
}
|
|
5
|
+
export function recordKey(name, id) {
|
|
6
|
+
const identity = typeof id === "string" || typeof id === "number" || typeof id === "bigint" || typeof id === "boolean" ? String(id) : Hash.hash(id);
|
|
7
|
+
return `${name}:${identity}`;
|
|
8
|
+
}
|
|
2
9
|
export const Key = Schema.Union([
|
|
3
10
|
Schema.Struct({
|
|
4
11
|
_tag: Schema.Literal("Bucket"),
|
|
@@ -25,7 +32,7 @@ function own(key) {
|
|
|
25
32
|
case "List":
|
|
26
33
|
return key.collection;
|
|
27
34
|
case "Item":
|
|
28
|
-
return
|
|
35
|
+
return recordKey(key.collection, key.id);
|
|
29
36
|
case "Bucket":
|
|
30
37
|
return JSON.stringify(["bucket", key.collection, key.field, key.value]);
|
|
31
38
|
}
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAItC,MAAM,UAAU,WAAW,CAAC,MAA0B;IACrD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,KAAc,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9G,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,EAAW;IAClD,MAAM,QAAQ,GAAG,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpJ,OAAO,GAAG,IAAI,IAAI,QAAQ,EAAE,CAAC;AAC9B,CAAC;AAqBD,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,MAAM,CAAC,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC9B,UAAU,EAAE,MAAM,CAAC,MAAM;QACzB,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,C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,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACpJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/changes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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,15 +43,15 @@
|
|
|
43
43
|
"README.md"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@shivaedev/quality": "0.
|
|
47
|
-
"@shivaedev/test-story": "0.
|
|
46
|
+
"@shivaedev/quality": "0.48.0",
|
|
47
|
+
"@shivaedev/test-story": "0.26.2",
|
|
48
48
|
"@types/node": "24.19.2",
|
|
49
|
-
"effect": "4.0.
|
|
49
|
+
"effect": "4.0.6",
|
|
50
50
|
"typescript": "7.0.2",
|
|
51
51
|
"vitest": "5.0.5"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"effect": "4.0.
|
|
54
|
+
"effect": "4.0.6"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=24"
|
package/src/keys.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Hash, Schema } from "effect";
|
|
2
2
|
|
|
3
3
|
export type Identity = string | number;
|
|
4
4
|
|
|
5
|
+
export function compositeId(values: readonly unknown[]): string {
|
|
6
|
+
return JSON.stringify(values, (_key, value: unknown) => (typeof value === "bigint" ? String(value) : value));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function recordKey(name: string, id: unknown): string {
|
|
10
|
+
const identity = typeof id === "string" || typeof id === "number" || typeof id === "bigint" || typeof id === "boolean" ? String(id) : Hash.hash(id);
|
|
11
|
+
return `${name}:${identity}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
export interface ListKey<TName extends string = string> {
|
|
6
15
|
readonly _tag: "List";
|
|
7
16
|
readonly collection: TName;
|
|
@@ -69,7 +78,7 @@ function own(key: Key): string {
|
|
|
69
78
|
case "List":
|
|
70
79
|
return key.collection;
|
|
71
80
|
case "Item":
|
|
72
|
-
return
|
|
81
|
+
return recordKey(key.collection, key.id);
|
|
73
82
|
case "Bucket":
|
|
74
83
|
return JSON.stringify(["bucket", key.collection, key.field, key.value]);
|
|
75
84
|
}
|