@kyneta/changefeed 1.3.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/LICENSE +21 -0
- package/README.md +135 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
- package/src/__tests__/changefeed.test.ts +347 -0
- package/src/__tests__/reactive-map.test.ts +324 -0
- package/src/callable.ts +82 -0
- package/src/change.ts +28 -0
- package/src/changefeed.ts +250 -0
- package/src/index.ts +27 -0
- package/src/reactive-map.ts +162 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Duane Johnson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# @kyneta/changefeed
|
|
2
|
+
|
|
3
|
+
The universal reactive contract for Kyneta — a Moore machine identified by `[CHANGEFEED]`.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A **changefeed** is a reactive value with a current state and a stream of future changes. You read `.current` to see what's there now; you `.subscribe()` to learn what changes next.
|
|
8
|
+
|
|
9
|
+
The protocol is expressed through a single well-known symbol: `CHANGEFEED` (`Symbol.for("kyneta:changefeed")`). Any object carrying this symbol participates in the reactive protocol — schema-interpreted refs, local state, peer lifecycle feeds, or anything else.
|
|
10
|
+
|
|
11
|
+
This package contains the **contract only** — zero dependencies, no schema, no interpreters, no paths. Schema-specific extensions (`Op`, `ComposedChangefeedProtocol`, tree observation) live in `@kyneta/schema`, which depends on this package.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm add @kyneta/changefeed
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## API
|
|
20
|
+
|
|
21
|
+
### Types
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
// The universal base type for all changes — an open protocol identified by a string discriminant.
|
|
25
|
+
interface ChangeBase {
|
|
26
|
+
readonly type: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// A batch of changes with optional provenance.
|
|
30
|
+
interface Changeset<C = ChangeBase> {
|
|
31
|
+
readonly changes: readonly C[]
|
|
32
|
+
readonly origin?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The protocol object behind [CHANGEFEED] — a Moore machine coalgebra.
|
|
36
|
+
interface ChangefeedProtocol<S, C extends ChangeBase = ChangeBase> {
|
|
37
|
+
readonly current: S
|
|
38
|
+
subscribe(callback: (changeset: Changeset<C>) => void): () => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Developer-facing type: [CHANGEFEED] marker + direct .current and .subscribe().
|
|
42
|
+
interface Changefeed<S, C extends ChangeBase = ChangeBase> {
|
|
43
|
+
readonly [CHANGEFEED]: ChangefeedProtocol<S, C>
|
|
44
|
+
readonly current: S
|
|
45
|
+
subscribe(callback: (changeset: Changeset<C>) => void): () => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Marker interface — any object with [CHANGEFEED] participates in the protocol.
|
|
49
|
+
interface HasChangefeed<S = unknown, A extends ChangeBase = ChangeBase> {
|
|
50
|
+
readonly [CHANGEFEED]: ChangefeedProtocol<S, A>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A Changefeed that is also callable — feed() returns feed.current.
|
|
54
|
+
type CallableChangefeed<S, C extends ChangeBase = ChangeBase> =
|
|
55
|
+
Changefeed<S, C> & (() => S)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Functions
|
|
59
|
+
|
|
60
|
+
#### `createChangefeed<S, C>(getCurrent: () => S): [Changefeed<S, C>, emit]`
|
|
61
|
+
|
|
62
|
+
Create a standalone changefeed with push semantics. Returns a `[feed, emit]` tuple.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createChangefeed } from "@kyneta/changefeed"
|
|
66
|
+
|
|
67
|
+
let count = 0
|
|
68
|
+
const [feed, emit] = createChangefeed(() => count)
|
|
69
|
+
|
|
70
|
+
feed.current // 0
|
|
71
|
+
feed.subscribe(cs => console.log(cs.changes))
|
|
72
|
+
|
|
73
|
+
count = 1
|
|
74
|
+
emit({ changes: [{ type: "increment", amount: 1 }] })
|
|
75
|
+
// subscriber receives the changeset
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### `createCallable<S, C>(feed: Changefeed<S, C>): CallableChangefeed<S, C>`
|
|
79
|
+
|
|
80
|
+
Wrap a changefeed in a callable function-object. `feed()` returns `feed.current`.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { createChangefeed, createCallable } from "@kyneta/changefeed"
|
|
84
|
+
|
|
85
|
+
let count = 0
|
|
86
|
+
const [source, emit] = createChangefeed(() => count)
|
|
87
|
+
const feed = createCallable(source)
|
|
88
|
+
|
|
89
|
+
feed() // 0 — callable
|
|
90
|
+
feed.current // 0 — getter
|
|
91
|
+
feed.subscribe // subscribe to changes
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### `changefeed<S, C>(source: HasChangefeed<S, C>): Changefeed<S, C>`
|
|
95
|
+
|
|
96
|
+
Project any object with `[CHANGEFEED]` into a developer-facing `Changefeed` — lifting the hidden protocol surface to direct `.current` and `.subscribe()` accessibility.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { changefeed } from "@kyneta/changefeed"
|
|
100
|
+
|
|
101
|
+
const feed = changefeed(doc.title)
|
|
102
|
+
feed.current // live value
|
|
103
|
+
feed.subscribe(cb) // subscribe to changes
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### `hasChangefeed(value: unknown): value is HasChangefeed`
|
|
107
|
+
|
|
108
|
+
Type guard — returns `true` if `value` has a `[CHANGEFEED]` property.
|
|
109
|
+
|
|
110
|
+
#### `staticChangefeed<S>(head: S): ChangefeedProtocol<S, never>`
|
|
111
|
+
|
|
112
|
+
Creates a protocol object that never emits changes — useful for static data sources that still need to participate in the protocol.
|
|
113
|
+
|
|
114
|
+
## Relationship to `@kyneta/schema`
|
|
115
|
+
|
|
116
|
+
`@kyneta/schema` depends on `@kyneta/changefeed` and extends the contract with tree-structured observation:
|
|
117
|
+
|
|
118
|
+
| This package (`@kyneta/changefeed`) | `@kyneta/schema` |
|
|
119
|
+
|---|---|
|
|
120
|
+
| `ChangeBase` | `TextChange`, `MapChange`, `SequenceChange`, ... |
|
|
121
|
+
| `Changeset<C>` | `Op<C>` (addressed delta with `Path`) |
|
|
122
|
+
| `ChangefeedProtocol<S, C>` | `ComposedChangefeedProtocol<S, C>` (adds `subscribeTree`) |
|
|
123
|
+
| `Changefeed<S, C>` | `HasComposedChangefeed<S, C>` |
|
|
124
|
+
| `hasChangefeed()` | `hasComposedChangefeed()`, `getOrCreateChangefeed()` |
|
|
125
|
+
| `createChangefeed()`, `createCallable()` | `expandMapOpsToLeaves()` |
|
|
126
|
+
|
|
127
|
+
Consumers import the contract from `@kyneta/changefeed` directly — schema does **not** re-export contract symbols. The import path tells the truth about the dependency.
|
|
128
|
+
|
|
129
|
+
## Relationship to `@kyneta/cast`
|
|
130
|
+
|
|
131
|
+
The Kyneta compiler detects `[CHANGEFEED]` structurally on types for automatic reactive subscription. `HasChangefeed<S, C>` is the type-level marker the compiler looks for. The Cast runtime uses `hasChangefeed()` at runtime to discover reactive values and subscribe to their change streams.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* All changes carry a string `type` discriminant. Built-in change types
|
|
3
|
+
* use well-known strings ("text", "sequence", "map", "replace", "tree").
|
|
4
|
+
* Third-party producers extend this with their own types.
|
|
5
|
+
*
|
|
6
|
+
* Provenance metadata (e.g. "local", "sync") is carried at the batch
|
|
7
|
+
* level on `Changeset.origin`, not on individual changes. See
|
|
8
|
+
* `Changeset` in `changefeed.ts`.
|
|
9
|
+
*/
|
|
10
|
+
interface ChangeBase {
|
|
11
|
+
readonly type: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The single symbol that marks a value as a changefeed. Accessing
|
|
16
|
+
* `obj[CHANGEFEED]` yields a `ChangefeedProtocol<S, C>` — the current
|
|
17
|
+
* value and a stream of future changes.
|
|
18
|
+
*
|
|
19
|
+
* Uses `Symbol.for` so that multiple copies of this module (e.g. in
|
|
20
|
+
* different bundle chunks) share the same symbol identity.
|
|
21
|
+
*/
|
|
22
|
+
declare const CHANGEFEED: unique symbol;
|
|
23
|
+
/**
|
|
24
|
+
* A changeset is the unit of delivery through the changefeed protocol.
|
|
25
|
+
* It wraps one or more changes with optional batch-level metadata.
|
|
26
|
+
*
|
|
27
|
+
* - Auto-commit produces a degenerate changeset of one change.
|
|
28
|
+
* - Transactions and `applyChanges` produce multi-change batches.
|
|
29
|
+
* - `origin` carries provenance for the entire batch (e.g. "sync",
|
|
30
|
+
* "undo", "local"). Individual changes do not carry provenance —
|
|
31
|
+
* the batch does.
|
|
32
|
+
*
|
|
33
|
+
* The subscriber API always receives a `Changeset`, making it uniform
|
|
34
|
+
* regardless of how the changes were produced.
|
|
35
|
+
*/
|
|
36
|
+
interface Changeset<C = ChangeBase> {
|
|
37
|
+
/** The individual changes in this batch. */
|
|
38
|
+
readonly changes: readonly C[];
|
|
39
|
+
/** Provenance of the batch (e.g. "sync", "undo", "local"). */
|
|
40
|
+
readonly origin?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The protocol object that sits behind the `[CHANGEFEED]` symbol.
|
|
44
|
+
*
|
|
45
|
+
* A coalgebra: `current` gives the live state, `subscribe` gives the
|
|
46
|
+
* stream of future changes. In automata-theory terms this is a Moore
|
|
47
|
+
* machine with a push-based transition stream.
|
|
48
|
+
*
|
|
49
|
+
* Properties:
|
|
50
|
+
* - `current` is a getter — always returns the live current value
|
|
51
|
+
* - `subscribe` returns an unsubscribe function
|
|
52
|
+
* - Subscribers receive a `Changeset<C>` — a batch of changes with
|
|
53
|
+
* optional provenance. For auto-commit (single mutation), the
|
|
54
|
+
* changeset contains exactly one change.
|
|
55
|
+
* - Static (non-reactive) sources return a protocol whose tail never emits:
|
|
56
|
+
* `{ current: value, subscribe: () => () => {} }`
|
|
57
|
+
*
|
|
58
|
+
* This is internal plumbing — developers interact with `Changefeed<S, C>`
|
|
59
|
+
* (the developer-facing type that includes `[CHANGEFEED]`, `.current`,
|
|
60
|
+
* and `.subscribe()` in one interface).
|
|
61
|
+
*/
|
|
62
|
+
interface ChangefeedProtocol<S, C extends ChangeBase = ChangeBase> {
|
|
63
|
+
/** The current value, always live (a getter). */
|
|
64
|
+
readonly current: S;
|
|
65
|
+
/** Subscribe to future changes. Returns an unsubscribe function. */
|
|
66
|
+
subscribe(callback: (changeset: Changeset<C>) => void): () => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The developer-facing changefeed type: a reactive value with direct
|
|
70
|
+
* access to `.current`, `.subscribe()`, and the `[CHANGEFEED]` marker.
|
|
71
|
+
*
|
|
72
|
+
* Developers write `readonly peers: Changefeed<PeerMap, PeerChange>` —
|
|
73
|
+
* no `Has` prefix, no separate protocol object, no triple declaration.
|
|
74
|
+
*
|
|
75
|
+
* A `Changefeed<S, C>` is the intersection of:
|
|
76
|
+
* - The `[CHANGEFEED]` marker (for compiler detection and runtime protocol)
|
|
77
|
+
* - Direct `.current` and `.subscribe()` access (for developer ergonomics)
|
|
78
|
+
*
|
|
79
|
+
* Use `changefeed(source)` to project any `HasChangefeed` into a
|
|
80
|
+
* `Changefeed`, or `createChangefeed()` to build one from scratch.
|
|
81
|
+
*/
|
|
82
|
+
interface Changefeed<S, C extends ChangeBase = ChangeBase> {
|
|
83
|
+
/** The protocol object behind the symbol. */
|
|
84
|
+
readonly [CHANGEFEED]: ChangefeedProtocol<S, C>;
|
|
85
|
+
/** The current value, always live (a getter). */
|
|
86
|
+
readonly current: S;
|
|
87
|
+
/** Subscribe to future changes. Returns an unsubscribe function. */
|
|
88
|
+
subscribe(callback: (changeset: Changeset<C>) => void): () => void;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* An object that carries a changefeed protocol under the `[CHANGEFEED]`
|
|
92
|
+
* symbol.
|
|
93
|
+
*
|
|
94
|
+
* Any ref, interpreted node, or enriched value can implement this
|
|
95
|
+
* interface to participate in the reactive protocol.
|
|
96
|
+
*/
|
|
97
|
+
interface HasChangefeed<S = unknown, A extends ChangeBase = ChangeBase> {
|
|
98
|
+
readonly [CHANGEFEED]: ChangefeedProtocol<S, A>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns `true` if `value` has a `[CHANGEFEED]` property, i.e. it
|
|
102
|
+
* implements the `HasChangefeed` interface.
|
|
103
|
+
*/
|
|
104
|
+
declare function hasChangefeed<S = unknown, A extends ChangeBase = ChangeBase>(value: unknown): value is HasChangefeed<S, A>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a changefeed protocol that never emits changes — useful for
|
|
107
|
+
* static/non-reactive data sources that still need to participate in
|
|
108
|
+
* the changefeed protocol.
|
|
109
|
+
*/
|
|
110
|
+
declare function staticChangefeed<S>(head: S): ChangefeedProtocol<S, never>;
|
|
111
|
+
/**
|
|
112
|
+
* Project any object with `[CHANGEFEED]` into a developer-facing
|
|
113
|
+
* `Changefeed<S, C>` — lifting the hidden protocol surface to direct
|
|
114
|
+
* `.current` and `.subscribe()` accessibility.
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* const feed = changefeed(doc.title)
|
|
118
|
+
* feed.current // live value
|
|
119
|
+
* feed.subscribe(cb) // subscribe to changes
|
|
120
|
+
* feed[CHANGEFEED] // the protocol object (same as doc.title[CHANGEFEED])
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
declare function changefeed<S, C extends ChangeBase>(source: HasChangefeed<S, C>): Changefeed<S, C>;
|
|
124
|
+
/**
|
|
125
|
+
* Create a standalone `Changefeed<S, C>` with push semantics.
|
|
126
|
+
*
|
|
127
|
+
* Returns a tuple of the feed and an emit function. The feed's
|
|
128
|
+
* `[CHANGEFEED]` returns the protocol view of itself. Manages its
|
|
129
|
+
* own subscriber set internally.
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* const [feed, emit] = createChangefeed(() => count)
|
|
133
|
+
* feed.current // read live value
|
|
134
|
+
* feed.subscribe(cs => { ... }) // subscribe
|
|
135
|
+
* hasChangefeed(feed) // true
|
|
136
|
+
* emit({ changes: [{ type: "replace", value: 42 }] }) // push
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function createChangefeed<S, C extends ChangeBase = ChangeBase>(getCurrent: () => S): [feed: Changefeed<S, C>, emit: (changeset: Changeset<C>) => void];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A changefeed that is also callable — `feed()` returns `feed.current`.
|
|
143
|
+
*
|
|
144
|
+
* This is the intersection of `Changefeed<S, C>` and `() => S`.
|
|
145
|
+
* The call signature provides ergonomic read access without `.current`.
|
|
146
|
+
*/
|
|
147
|
+
type CallableChangefeed<S, C extends ChangeBase = ChangeBase> = Changefeed<S, C> & (() => S);
|
|
148
|
+
/**
|
|
149
|
+
* Wrap a `Changefeed<S, C>` in a callable function-object.
|
|
150
|
+
*
|
|
151
|
+
* The returned object:
|
|
152
|
+
* - `feed()` → `feed.current` (callable)
|
|
153
|
+
* - `feed.current` → delegated getter
|
|
154
|
+
* - `feed.subscribe(cb)` → delegated
|
|
155
|
+
* - `feed[CHANGEFEED]` → delegated protocol
|
|
156
|
+
* - `hasChangefeed(feed)` → `true`
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const [source, emit] = createChangefeed(() => count)
|
|
160
|
+
* const feed = createCallable(source)
|
|
161
|
+
* feed() // read current value
|
|
162
|
+
* feed.current // same as feed()
|
|
163
|
+
* feed.subscribe(cb) // subscribe to changes
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
declare function createCallable<S, C extends ChangeBase>(feed: Changefeed<S, C>): CallableChangefeed<S, C>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A callable changefeed over a `ReadonlyMap<K, V>` with lifted
|
|
170
|
+
* collection accessors.
|
|
171
|
+
*
|
|
172
|
+
* `reactiveMap()` returns the current `ReadonlyMap<K, V>`.
|
|
173
|
+
* `.get()`, `.has()`, `.keys()`, `.size`, and `[Symbol.iterator]()`
|
|
174
|
+
* delegate to the internal map — no need to unwrap `.current` first.
|
|
175
|
+
*
|
|
176
|
+
* Extends `CallableChangefeed` — assignable anywhere a
|
|
177
|
+
* `CallableChangefeed<ReadonlyMap<K, V>, C>` or `Changefeed` is expected.
|
|
178
|
+
*/
|
|
179
|
+
interface ReactiveMap<K, V, C extends ChangeBase = ChangeBase> extends CallableChangefeed<ReadonlyMap<K, V>, C> {
|
|
180
|
+
/** Get the value for a key, or `undefined` if absent. */
|
|
181
|
+
get(key: K): V | undefined;
|
|
182
|
+
/** Whether the map contains a key. */
|
|
183
|
+
has(key: K): boolean;
|
|
184
|
+
/** An iterator over all keys. */
|
|
185
|
+
keys(): IterableIterator<K>;
|
|
186
|
+
/** The number of entries. */
|
|
187
|
+
readonly size: number;
|
|
188
|
+
/** Iterate over `[key, value]` pairs. */
|
|
189
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The producer-side handle for a `ReactiveMap`.
|
|
193
|
+
*
|
|
194
|
+
* Provides raw map mutations (`set`, `delete`, `clear`) that modify
|
|
195
|
+
* the internal map **without** emitting changes. Call `emit()` with
|
|
196
|
+
* the appropriate changeset after mutations are complete.
|
|
197
|
+
*
|
|
198
|
+
* This separation lets the consumer batch mutations and emit a single
|
|
199
|
+
* changeset — e.g. `clear()` → N × `set()` → one `emit()`.
|
|
200
|
+
*/
|
|
201
|
+
interface ReactiveMapHandle<K, V, C extends ChangeBase> {
|
|
202
|
+
/** Insert or overwrite an entry. Does NOT emit. */
|
|
203
|
+
set(key: K, value: V): void;
|
|
204
|
+
/** Remove an entry. Returns `true` if the key was present. Does NOT emit. */
|
|
205
|
+
delete(key: K): boolean;
|
|
206
|
+
/** Remove all entries. Does NOT emit. */
|
|
207
|
+
clear(): void;
|
|
208
|
+
/** Push a changeset to all subscribers. */
|
|
209
|
+
emit(changeset: Changeset<C>): void;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Create a `ReactiveMap<K, V, C>` and its producer-side handle.
|
|
213
|
+
*
|
|
214
|
+
* The reactive map owns its internal `Map<K, V>`. Consumers read via
|
|
215
|
+
* the `ReactiveMap` surface (call signature, `.get()`, `.has()`, etc.).
|
|
216
|
+
* Producers mutate via the `ReactiveMapHandle` (`set`, `delete`,
|
|
217
|
+
* `clear`) and push notifications via `emit`.
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* const [peers, handle] = createReactiveMap<PeerId, PeerInfo, PeerChange>()
|
|
221
|
+
*
|
|
222
|
+
* handle.set("alice", aliceInfo)
|
|
223
|
+
* handle.emit({ changes: [{ type: "peer-joined", peer: aliceInfo }] })
|
|
224
|
+
*
|
|
225
|
+
* peers() // ReadonlyMap with one entry
|
|
226
|
+
* peers.get("alice") // aliceInfo
|
|
227
|
+
* peers.size // 1
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
declare function createReactiveMap<K, V, C extends ChangeBase = ChangeBase>(): [
|
|
231
|
+
ReactiveMap<K, V, C>,
|
|
232
|
+
ReactiveMapHandle<K, V, C>
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
export { CHANGEFEED, type CallableChangefeed, type ChangeBase, type Changefeed, type ChangefeedProtocol, type Changeset, type HasChangefeed, type ReactiveMap, type ReactiveMapHandle, changefeed, createCallable, createChangefeed, createReactiveMap, hasChangefeed, staticChangefeed };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// src/changefeed.ts
|
|
2
|
+
var CHANGEFEED = /* @__PURE__ */ Symbol.for("kyneta:changefeed");
|
|
3
|
+
function hasChangefeed(value) {
|
|
4
|
+
return value !== null && value !== void 0 && (typeof value === "object" || typeof value === "function") && CHANGEFEED in value;
|
|
5
|
+
}
|
|
6
|
+
function staticChangefeed(head) {
|
|
7
|
+
return {
|
|
8
|
+
get current() {
|
|
9
|
+
return head;
|
|
10
|
+
},
|
|
11
|
+
subscribe() {
|
|
12
|
+
return () => {
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function changefeed(source) {
|
|
18
|
+
const protocol = source[CHANGEFEED];
|
|
19
|
+
return {
|
|
20
|
+
[CHANGEFEED]: protocol,
|
|
21
|
+
get current() {
|
|
22
|
+
return protocol.current;
|
|
23
|
+
},
|
|
24
|
+
subscribe(callback) {
|
|
25
|
+
return protocol.subscribe(callback);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createChangefeed(getCurrent) {
|
|
30
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
31
|
+
const protocol = {
|
|
32
|
+
get current() {
|
|
33
|
+
return getCurrent();
|
|
34
|
+
},
|
|
35
|
+
subscribe(callback) {
|
|
36
|
+
subscribers.add(callback);
|
|
37
|
+
return () => {
|
|
38
|
+
subscribers.delete(callback);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const feed = {
|
|
43
|
+
[CHANGEFEED]: protocol,
|
|
44
|
+
get current() {
|
|
45
|
+
return getCurrent();
|
|
46
|
+
},
|
|
47
|
+
subscribe(callback) {
|
|
48
|
+
return protocol.subscribe(callback);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const emit = (changeset) => {
|
|
52
|
+
for (const cb of subscribers) {
|
|
53
|
+
cb(changeset);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
return [feed, emit];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/callable.ts
|
|
60
|
+
function createCallable(feed) {
|
|
61
|
+
const callable = () => feed.current;
|
|
62
|
+
Object.defineProperty(callable, CHANGEFEED, {
|
|
63
|
+
get() {
|
|
64
|
+
return feed[CHANGEFEED];
|
|
65
|
+
},
|
|
66
|
+
enumerable: false,
|
|
67
|
+
configurable: false
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(callable, "current", {
|
|
70
|
+
get() {
|
|
71
|
+
return feed.current;
|
|
72
|
+
},
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: false
|
|
75
|
+
});
|
|
76
|
+
callable.subscribe = (callback) => {
|
|
77
|
+
return feed.subscribe(callback);
|
|
78
|
+
};
|
|
79
|
+
return callable;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/reactive-map.ts
|
|
83
|
+
function createReactiveMap() {
|
|
84
|
+
const map = /* @__PURE__ */ new Map();
|
|
85
|
+
const [feed, emit] = createChangefeed(() => map);
|
|
86
|
+
const callable = () => map;
|
|
87
|
+
Object.defineProperty(callable, CHANGEFEED, {
|
|
88
|
+
get() {
|
|
89
|
+
return feed[CHANGEFEED];
|
|
90
|
+
},
|
|
91
|
+
enumerable: false,
|
|
92
|
+
configurable: false
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(callable, "current", {
|
|
95
|
+
get() {
|
|
96
|
+
return map;
|
|
97
|
+
},
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: false
|
|
100
|
+
});
|
|
101
|
+
callable.subscribe = (callback) => {
|
|
102
|
+
return feed.subscribe(callback);
|
|
103
|
+
};
|
|
104
|
+
callable.get = (key) => map.get(key);
|
|
105
|
+
callable.has = (key) => map.has(key);
|
|
106
|
+
callable.keys = () => map.keys();
|
|
107
|
+
Object.defineProperty(callable, "size", {
|
|
108
|
+
get() {
|
|
109
|
+
return map.size;
|
|
110
|
+
},
|
|
111
|
+
enumerable: true,
|
|
112
|
+
configurable: false
|
|
113
|
+
});
|
|
114
|
+
callable[Symbol.iterator] = () => map[Symbol.iterator]();
|
|
115
|
+
const handle = {
|
|
116
|
+
set(key, value) {
|
|
117
|
+
map.set(key, value);
|
|
118
|
+
},
|
|
119
|
+
delete(key) {
|
|
120
|
+
return map.delete(key);
|
|
121
|
+
},
|
|
122
|
+
clear() {
|
|
123
|
+
map.clear();
|
|
124
|
+
},
|
|
125
|
+
emit
|
|
126
|
+
};
|
|
127
|
+
return [callable, handle];
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
CHANGEFEED,
|
|
131
|
+
changefeed,
|
|
132
|
+
createCallable,
|
|
133
|
+
createChangefeed,
|
|
134
|
+
createReactiveMap,
|
|
135
|
+
hasChangefeed,
|
|
136
|
+
staticChangefeed
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/changefeed.ts","../src/callable.ts","../src/reactive-map.ts"],"sourcesContent":["// Changefeed — the universal reactive contract.\n//\n// A changefeed is a reactive value with a current state and a stream\n// of future changes. You read `current` to see what's there now;\n// you subscribe to learn what changes next.\n//\n// The changefeed protocol is expressed through a single symbol: CHANGEFEED.\n//\n// Changes are delivered as `Changeset<C>` — a batch of one or more\n// changes with optional provenance metadata. Auto-commit wraps a\n// single change in a degenerate changeset of one; transactions and\n// `applyChanges` deliver multi-change batches. The subscriber API\n// is uniform regardless of batch size.\n//\n// This module is the canonical home of the reactive contract. It has\n// zero dependencies — no schema, no paths, no interpreters.\n\nimport type { ChangeBase } from \"./change.js\"\n\n// ---------------------------------------------------------------------------\n// Symbol\n// ---------------------------------------------------------------------------\n\n/**\n * The single symbol that marks a value as a changefeed. Accessing\n * `obj[CHANGEFEED]` yields a `ChangefeedProtocol<S, C>` — the current\n * value and a stream of future changes.\n *\n * Uses `Symbol.for` so that multiple copies of this module (e.g. in\n * different bundle chunks) share the same symbol identity.\n */\nexport const CHANGEFEED: unique symbol = Symbol.for(\"kyneta:changefeed\") as any\n\n// ---------------------------------------------------------------------------\n// Changeset — the unit of batch delivery\n// ---------------------------------------------------------------------------\n\n/**\n * A changeset is the unit of delivery through the changefeed protocol.\n * It wraps one or more changes with optional batch-level metadata.\n *\n * - Auto-commit produces a degenerate changeset of one change.\n * - Transactions and `applyChanges` produce multi-change batches.\n * - `origin` carries provenance for the entire batch (e.g. \"sync\",\n * \"undo\", \"local\"). Individual changes do not carry provenance —\n * the batch does.\n *\n * The subscriber API always receives a `Changeset`, making it uniform\n * regardless of how the changes were produced.\n */\nexport interface Changeset<C = ChangeBase> {\n /** The individual changes in this batch. */\n readonly changes: readonly C[]\n /** Provenance of the batch (e.g. \"sync\", \"undo\", \"local\"). */\n readonly origin?: string\n}\n\n// ---------------------------------------------------------------------------\n// Core interfaces — protocol layer\n// ---------------------------------------------------------------------------\n\n/**\n * The protocol object that sits behind the `[CHANGEFEED]` symbol.\n *\n * A coalgebra: `current` gives the live state, `subscribe` gives the\n * stream of future changes. In automata-theory terms this is a Moore\n * machine with a push-based transition stream.\n *\n * Properties:\n * - `current` is a getter — always returns the live current value\n * - `subscribe` returns an unsubscribe function\n * - Subscribers receive a `Changeset<C>` — a batch of changes with\n * optional provenance. For auto-commit (single mutation), the\n * changeset contains exactly one change.\n * - Static (non-reactive) sources return a protocol whose tail never emits:\n * `{ current: value, subscribe: () => () => {} }`\n *\n * This is internal plumbing — developers interact with `Changefeed<S, C>`\n * (the developer-facing type that includes `[CHANGEFEED]`, `.current`,\n * and `.subscribe()` in one interface).\n */\nexport interface ChangefeedProtocol<S, C extends ChangeBase = ChangeBase> {\n /** The current value, always live (a getter). */\n readonly current: S\n /** Subscribe to future changes. Returns an unsubscribe function. */\n subscribe(callback: (changeset: Changeset<C>) => void): () => void\n}\n\n// ---------------------------------------------------------------------------\n// Core interfaces — developer-facing type\n// ---------------------------------------------------------------------------\n\n/**\n * The developer-facing changefeed type: a reactive value with direct\n * access to `.current`, `.subscribe()`, and the `[CHANGEFEED]` marker.\n *\n * Developers write `readonly peers: Changefeed<PeerMap, PeerChange>` —\n * no `Has` prefix, no separate protocol object, no triple declaration.\n *\n * A `Changefeed<S, C>` is the intersection of:\n * - The `[CHANGEFEED]` marker (for compiler detection and runtime protocol)\n * - Direct `.current` and `.subscribe()` access (for developer ergonomics)\n *\n * Use `changefeed(source)` to project any `HasChangefeed` into a\n * `Changefeed`, or `createChangefeed()` to build one from scratch.\n */\nexport interface Changefeed<S, C extends ChangeBase = ChangeBase> {\n /** The protocol object behind the symbol. */\n readonly [CHANGEFEED]: ChangefeedProtocol<S, C>\n /** The current value, always live (a getter). */\n readonly current: S\n /** Subscribe to future changes. Returns an unsubscribe function. */\n subscribe(callback: (changeset: Changeset<C>) => void): () => void\n}\n\n/**\n * An object that carries a changefeed protocol under the `[CHANGEFEED]`\n * symbol.\n *\n * Any ref, interpreted node, or enriched value can implement this\n * interface to participate in the reactive protocol.\n */\nexport interface HasChangefeed<S = unknown, A extends ChangeBase = ChangeBase> {\n readonly [CHANGEFEED]: ChangefeedProtocol<S, A>\n}\n\n// ---------------------------------------------------------------------------\n// Type guard\n// ---------------------------------------------------------------------------\n\n/**\n * Returns `true` if `value` has a `[CHANGEFEED]` property, i.e. it\n * implements the `HasChangefeed` interface.\n */\nexport function hasChangefeed<S = unknown, A extends ChangeBase = ChangeBase>(\n value: unknown,\n): value is HasChangefeed<S, A> {\n return (\n value !== null &&\n value !== undefined &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n CHANGEFEED in (value as object)\n )\n}\n\n// ---------------------------------------------------------------------------\n// Static feed helper\n// ---------------------------------------------------------------------------\n\n/**\n * Creates a changefeed protocol that never emits changes — useful for\n * static/non-reactive data sources that still need to participate in\n * the changefeed protocol.\n */\nexport function staticChangefeed<S>(head: S): ChangefeedProtocol<S, never> {\n return {\n get current() {\n return head\n },\n subscribe() {\n return () => {}\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Projector — lift HasChangefeed to Changefeed\n// ---------------------------------------------------------------------------\n\n/**\n * Project any object with `[CHANGEFEED]` into a developer-facing\n * `Changefeed<S, C>` — lifting the hidden protocol surface to direct\n * `.current` and `.subscribe()` accessibility.\n *\n * ```ts\n * const feed = changefeed(doc.title)\n * feed.current // live value\n * feed.subscribe(cb) // subscribe to changes\n * feed[CHANGEFEED] // the protocol object (same as doc.title[CHANGEFEED])\n * ```\n */\nexport function changefeed<S, C extends ChangeBase>(\n source: HasChangefeed<S, C>,\n): Changefeed<S, C> {\n const protocol = source[CHANGEFEED]\n return {\n [CHANGEFEED]: protocol,\n get current(): S {\n return protocol.current\n },\n subscribe(callback: (changeset: Changeset<C>) => void): () => void {\n return protocol.subscribe(callback)\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory — create standalone Changefeed values\n// ---------------------------------------------------------------------------\n\n/**\n * Create a standalone `Changefeed<S, C>` with push semantics.\n *\n * Returns a tuple of the feed and an emit function. The feed's\n * `[CHANGEFEED]` returns the protocol view of itself. Manages its\n * own subscriber set internally.\n *\n * ```ts\n * const [feed, emit] = createChangefeed(() => count)\n * feed.current // read live value\n * feed.subscribe(cs => { ... }) // subscribe\n * hasChangefeed(feed) // true\n * emit({ changes: [{ type: \"replace\", value: 42 }] }) // push\n * ```\n */\nexport function createChangefeed<S, C extends ChangeBase = ChangeBase>(\n getCurrent: () => S,\n): [feed: Changefeed<S, C>, emit: (changeset: Changeset<C>) => void] {\n const subscribers = new Set<(changeset: Changeset<C>) => void>()\n\n const protocol: ChangefeedProtocol<S, C> = {\n get current(): S {\n return getCurrent()\n },\n subscribe(callback: (changeset: Changeset<C>) => void): () => void {\n subscribers.add(callback)\n return () => {\n subscribers.delete(callback)\n }\n },\n }\n\n const feed: Changefeed<S, C> = {\n [CHANGEFEED]: protocol,\n get current(): S {\n return getCurrent()\n },\n subscribe(callback: (changeset: Changeset<C>) => void): () => void {\n return protocol.subscribe(callback)\n },\n }\n\n const emit = (changeset: Changeset<C>): void => {\n for (const cb of subscribers) {\n cb(changeset)\n }\n }\n\n return [feed, emit]\n}\n","// callable — the createCallable combinator.\n//\n// Wraps a Changefeed<S, C> in a callable function-object so that\n// `feed()` returns `feed.current`. The callable preserves the full\n// changefeed contract: [CHANGEFEED], .current, .subscribe().\n//\n// This is the same function-object pattern used by LocalRef in\n// @kyneta/cast — a function with properties attached.\n\nimport type { ChangeBase } from \"./change.js\"\nimport type { Changefeed, ChangefeedProtocol, Changeset } from \"./changefeed.js\"\nimport { CHANGEFEED } from \"./changefeed.js\"\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * A changefeed that is also callable — `feed()` returns `feed.current`.\n *\n * This is the intersection of `Changefeed<S, C>` and `() => S`.\n * The call signature provides ergonomic read access without `.current`.\n */\nexport type CallableChangefeed<\n S,\n C extends ChangeBase = ChangeBase,\n> = Changefeed<S, C> & (() => S)\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Wrap a `Changefeed<S, C>` in a callable function-object.\n *\n * The returned object:\n * - `feed()` → `feed.current` (callable)\n * - `feed.current` → delegated getter\n * - `feed.subscribe(cb)` → delegated\n * - `feed[CHANGEFEED]` → delegated protocol\n * - `hasChangefeed(feed)` → `true`\n *\n * ```ts\n * const [source, emit] = createChangefeed(() => count)\n * const feed = createCallable(source)\n * feed() // read current value\n * feed.current // same as feed()\n * feed.subscribe(cb) // subscribe to changes\n * ```\n */\nexport function createCallable<S, C extends ChangeBase>(\n feed: Changefeed<S, C>,\n): CallableChangefeed<S, C> {\n const callable: any = () => feed.current\n\n // [CHANGEFEED] — non-enumerable getter delegating to source\n Object.defineProperty(callable, CHANGEFEED, {\n get(): ChangefeedProtocol<S, C> {\n return feed[CHANGEFEED]\n },\n enumerable: false,\n configurable: false,\n })\n\n // .current — getter delegating to source\n Object.defineProperty(callable, \"current\", {\n get(): S {\n return feed.current\n },\n enumerable: true,\n configurable: false,\n })\n\n // .subscribe — delegating to source\n callable.subscribe = (\n callback: (changeset: Changeset<C>) => void,\n ): (() => void) => {\n return feed.subscribe(callback)\n }\n\n return callable as CallableChangefeed<S, C>\n}\n","// reactive-map — a callable changefeed over a mutable Map.\n//\n// ReactiveMap<K, V, C> is a CallableChangefeed<ReadonlyMap<K, V>, C>\n// with lifted collection accessors (.get, .has, .keys, .size, iteration).\n// The handle provides raw map mutations (set, delete, clear) without\n// automatic emission — the consumer decides when and what to emit.\n//\n// This extracts the recurring pattern of \"callable changefeed over a\n// ReadonlyMap with convenience accessors\" (used by exchange.peers,\n// Catalog, and future reactive collections) into a single combinator.\n\nimport type { CallableChangefeed } from \"./callable.js\"\nimport type { ChangeBase } from \"./change.js\"\nimport type { ChangefeedProtocol, Changeset } from \"./changefeed.js\"\nimport { CHANGEFEED, createChangefeed } from \"./changefeed.js\"\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/**\n * A callable changefeed over a `ReadonlyMap<K, V>` with lifted\n * collection accessors.\n *\n * `reactiveMap()` returns the current `ReadonlyMap<K, V>`.\n * `.get()`, `.has()`, `.keys()`, `.size`, and `[Symbol.iterator]()`\n * delegate to the internal map — no need to unwrap `.current` first.\n *\n * Extends `CallableChangefeed` — assignable anywhere a\n * `CallableChangefeed<ReadonlyMap<K, V>, C>` or `Changefeed` is expected.\n */\nexport interface ReactiveMap<K, V, C extends ChangeBase = ChangeBase>\n extends CallableChangefeed<ReadonlyMap<K, V>, C> {\n /** Get the value for a key, or `undefined` if absent. */\n get(key: K): V | undefined\n /** Whether the map contains a key. */\n has(key: K): boolean\n /** An iterator over all keys. */\n keys(): IterableIterator<K>\n /** The number of entries. */\n readonly size: number\n /** Iterate over `[key, value]` pairs. */\n [Symbol.iterator](): IterableIterator<[K, V]>\n}\n\n/**\n * The producer-side handle for a `ReactiveMap`.\n *\n * Provides raw map mutations (`set`, `delete`, `clear`) that modify\n * the internal map **without** emitting changes. Call `emit()` with\n * the appropriate changeset after mutations are complete.\n *\n * This separation lets the consumer batch mutations and emit a single\n * changeset — e.g. `clear()` → N × `set()` → one `emit()`.\n */\nexport interface ReactiveMapHandle<K, V, C extends ChangeBase> {\n /** Insert or overwrite an entry. Does NOT emit. */\n set(key: K, value: V): void\n /** Remove an entry. Returns `true` if the key was present. Does NOT emit. */\n delete(key: K): boolean\n /** Remove all entries. Does NOT emit. */\n clear(): void\n /** Push a changeset to all subscribers. */\n emit(changeset: Changeset<C>): void\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Create a `ReactiveMap<K, V, C>` and its producer-side handle.\n *\n * The reactive map owns its internal `Map<K, V>`. Consumers read via\n * the `ReactiveMap` surface (call signature, `.get()`, `.has()`, etc.).\n * Producers mutate via the `ReactiveMapHandle` (`set`, `delete`,\n * `clear`) and push notifications via `emit`.\n *\n * ```ts\n * const [peers, handle] = createReactiveMap<PeerId, PeerInfo, PeerChange>()\n *\n * handle.set(\"alice\", aliceInfo)\n * handle.emit({ changes: [{ type: \"peer-joined\", peer: aliceInfo }] })\n *\n * peers() // ReadonlyMap with one entry\n * peers.get(\"alice\") // aliceInfo\n * peers.size // 1\n * ```\n */\nexport function createReactiveMap<K, V, C extends ChangeBase = ChangeBase>(): [\n ReactiveMap<K, V, C>,\n ReactiveMapHandle<K, V, C>,\n] {\n const map = new Map<K, V>()\n\n // Create the base changefeed + emit pair.\n // The thunk reads the same Map instance — never reassigned.\n const [feed, emit] = createChangefeed<ReadonlyMap<K, V>, C>(() => map)\n\n // Build the callable function-object.\n // We construct it manually (rather than using createCallable) so we\n // can attach the collection accessors in one pass.\n const callable: any = () => map as ReadonlyMap<K, V>\n\n // ── Changefeed protocol ──\n\n Object.defineProperty(callable, CHANGEFEED, {\n get(): ChangefeedProtocol<ReadonlyMap<K, V>, C> {\n return feed[CHANGEFEED]\n },\n enumerable: false,\n configurable: false,\n })\n\n Object.defineProperty(callable, \"current\", {\n get(): ReadonlyMap<K, V> {\n return map\n },\n enumerable: true,\n configurable: false,\n })\n\n callable.subscribe = (\n callback: (changeset: Changeset<C>) => void,\n ): (() => void) => {\n return feed.subscribe(callback)\n }\n\n // ── Lifted collection accessors ──\n\n callable.get = (key: K): V | undefined => map.get(key)\n callable.has = (key: K): boolean => map.has(key)\n callable.keys = (): IterableIterator<K> => map.keys()\n\n Object.defineProperty(callable, \"size\", {\n get(): number {\n return map.size\n },\n enumerable: true,\n configurable: false,\n })\n\n callable[Symbol.iterator] = (): IterableIterator<[K, V]> =>\n map[Symbol.iterator]()\n\n // ── Handle (producer side) ──\n\n const handle: ReactiveMapHandle<K, V, C> = {\n set(key: K, value: V): void {\n map.set(key, value)\n },\n delete(key: K): boolean {\n return map.delete(key)\n },\n clear(): void {\n map.clear()\n },\n emit,\n }\n\n return [callable as ReactiveMap<K, V, C>, handle]\n}\n"],"mappings":"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","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kyneta/changefeed",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Universal reactive contract — a Moore machine identified by [CHANGEFEED]",
|
|
5
|
+
"author": "Duane Johnson",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/halecraft/kyneta",
|
|
10
|
+
"directory": "packages/changefeed"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"src"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./src": "./src/index.ts",
|
|
30
|
+
"./src/*": "./src/*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.5.0",
|
|
34
|
+
"typescript": "^5.9.2",
|
|
35
|
+
"vitest": "^4.0.17"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"test": "verify logic",
|
|
40
|
+
"verify": "verify"
|
|
41
|
+
}
|
|
42
|
+
}
|