@shivaedev/changes 0.5.1 → 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 +10 -0
- package/README.md +10 -8
- 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 +3 -3
- package/src/keys.ts +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 0.5.1 - 2026-10-30
|
|
4
14
|
|
|
5
15
|
### Changed
|
package/README.md
CHANGED
|
@@ -111,6 +111,8 @@ const invalidations = invalidationKeys(keys);
|
|
|
111
111
|
|
|
112
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
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
|
+
|
|
114
116
|
`bucket(schema)` from `@shivaedev/changes/buckets.ts` declares a model field as a write bucket without changing its schema type or variants:
|
|
115
117
|
|
|
116
118
|
```ts
|
|
@@ -190,14 +192,14 @@ A direct driver binding using `open` must run `frame.beforeCommit` inside its tr
|
|
|
190
192
|
|
|
191
193
|
Import from the module that defines the name; the package has no root entry.
|
|
192
194
|
|
|
193
|
-
| Module | Names
|
|
194
|
-
| ------------------------------- |
|
|
195
|
-
| `@shivaedev/changes/channel.ts` | `makeChannel`, `ChannelOptions`, `Channel`, `BeforeCommit`
|
|
196
|
-
| `@shivaedev/changes/frame.ts` | `Frame`, `CommitFrame`, `Outcome`
|
|
197
|
-
| `@shivaedev/changes/observe.ts` | `Observation`, `Observer`
|
|
198
|
-
| `@shivaedev/changes/publish.ts` | `Publish`, `PublishFailure`
|
|
199
|
-
| `@shivaedev/changes/keys.ts` | `collection`, `readKeys`, `invalidationKeys`, `Key`, `ListKey`, `ItemKey`, `BucketKey`, `Collection`, `Identity`, `KeyContext` |
|
|
200
|
-
| `@shivaedev/changes/buckets.ts` | `bucket`, `declaredBuckets`
|
|
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` |
|
|
201
203
|
|
|
202
204
|
A `Channel` exposes `record`, `within`, `batch` and `open`, and the scoped references `Sink`, `CommittedSink`, `Observer` and `BeforeCommit`.
|
|
203
205
|
|
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,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;CACtB;AAED,MAAM,WAAW,SAAS,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM;IACvD,QAA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G,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,EAA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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,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.48.0",
|
|
47
|
+
"@shivaedev/test-story": "0.26.2",
|
|
48
48
|
"@types/node": "24.19.2",
|
|
49
49
|
"effect": "4.0.6",
|
|
50
50
|
"typescript": "7.0.2",
|
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
|
}
|