@toyz/loom-rpc 0.3.4 → 0.5.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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/stream.d.ts +65 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +289 -0
- package/dist/stream.js.map +1 -0
- package/dist/transport.d.ts +7 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +45 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { rpc } from "./rpc";
|
|
8
8
|
export { mutate } from "./mutate";
|
|
9
|
+
export { stream, onStream, RPC_STREAMS } from "./stream";
|
|
9
10
|
export { service, SERVICE_NAME } from "./service";
|
|
10
11
|
export { RpcTransport, HttpTransport, RpcError } from "./transport";
|
|
11
|
-
export type { RpcMethods, InferArgs, InferReturn, RpcQueryOptions, RpcMutator, RpcQuery, RpcRequest, RpcResponse, } from "./types";
|
|
12
|
+
export type { RpcMethods, InferArgs, InferReturn, RpcQueryOptions, RpcStreamOptions, RpcMutator, RpcQuery, RpcStream, RpcRequest, RpcResponse, } from "./types";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGpE,YAAY,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,eAAe,EACf,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGpE,YAAY,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// Decorators
|
|
8
8
|
export { rpc } from "./rpc";
|
|
9
9
|
export { mutate } from "./mutate";
|
|
10
|
+
export { stream, onStream, RPC_STREAMS } from "./stream";
|
|
10
11
|
export { service, SERVICE_NAME } from "./service";
|
|
11
12
|
// Transport
|
|
12
13
|
export { RpcTransport, HttpTransport, RpcError } from "./transport";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAElD,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,aAAa;AACb,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAElD,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LoomRPC — @stream / @onStream decorators
|
|
3
|
+
*
|
|
4
|
+
* @stream — Auto-accessor decorator for server-push streams.
|
|
5
|
+
* @onStream — Method decorator that wires a stream handler on a LoomElement.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { stream, onStream } from "@toyz/loom-rpc";
|
|
9
|
+
*
|
|
10
|
+
* // eager (default) — opens automatically on connectedCallback
|
|
11
|
+
* @stream(ChatRouter, "messages", { fn: el => [el.roomId] })
|
|
12
|
+
* accessor chatMessages!: RpcStream<ChatMessage>;
|
|
13
|
+
*
|
|
14
|
+
* // callback-style (component)
|
|
15
|
+
* @onStream("chatMessages")
|
|
16
|
+
* onMessage(msg: ChatMessage) {
|
|
17
|
+
* this.msgs.push(msg);
|
|
18
|
+
* this.scheduleUpdate();
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // direct iteration (service / advanced)
|
|
22
|
+
* for await (const msg of this.chatMessages) { ... }
|
|
23
|
+
*
|
|
24
|
+
* // manual — must call open() yourself
|
|
25
|
+
* @stream(ChatRouter, "history", { fn: el => [el.roomId], eager: false })
|
|
26
|
+
* accessor history!: RpcStream<ChatMessage>;
|
|
27
|
+
* this.history.open();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import type { RpcMethods, RpcStream, RpcStreamOptions } from "./types";
|
|
31
|
+
/** Symbol for inspect() introspection */
|
|
32
|
+
export declare const RPC_STREAMS: import("@toyz/loom").LoomSymbol<unknown>;
|
|
33
|
+
/**
|
|
34
|
+
* @stream(Router, method, opts?) — streaming auto-accessor decorator.
|
|
35
|
+
*
|
|
36
|
+
* Returns an `RpcStream<T>` which is also directly iterable:
|
|
37
|
+
* `for await (const x of this.myStream) { ... }`
|
|
38
|
+
*
|
|
39
|
+
* By default (`eager: true`) the stream opens automatically in
|
|
40
|
+
* `connectedCallback`. Set `eager: false` and call `.open()` manually.
|
|
41
|
+
*
|
|
42
|
+
* Requires the registered `RpcTransport` to implement `stream()`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function stream<TRouter extends object, TMethod extends RpcMethods<TRouter>>(router: new (...args: any[]) => TRouter, method: TMethod, opts?: RpcStreamOptions<TRouter, TMethod>): <This extends object>(_target: ClassAccessorDecoratorTarget<This, RpcStream<TRouter[TMethod] extends (...args: any[]) => AsyncIterable<infer U> ? U : TRouter[TMethod] extends (...args: any[]) => Promise<infer U_1> ? U_1 : unknown>>, context: ClassAccessorDecoratorContext<This, RpcStream<TRouter[TMethod] extends (...args: any[]) => AsyncIterable<infer U> ? U : TRouter[TMethod] extends (...args: any[]) => Promise<infer U_1> ? U_1 : unknown>>) => ClassAccessorDecoratorResult<This, RpcStream<TRouter[TMethod] extends (...args: any[]) => AsyncIterable<infer U> ? U : TRouter[TMethod] extends (...args: any[]) => Promise<infer U_1> ? U_1 : unknown>>;
|
|
45
|
+
/** @internal — exported so tests can create state directly without decorators */
|
|
46
|
+
export declare function createStreamState<T>(routerName: string, method: string, opts: RpcStreamOptions<any, any> | undefined, scheduleUpdate: () => void, host: any): RpcStream<T> & {
|
|
47
|
+
_subscribe(cb: (e: T) => void): () => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Wire a method as a handler for an `RpcStream` accessor on a `LoomElement`.
|
|
51
|
+
*
|
|
52
|
+
* - Subscribes to the shared pump in `connectedCallback` (via `CONNECT_HOOKS`)
|
|
53
|
+
* - Auto-opens the stream if still idle
|
|
54
|
+
* - Unsubscribes and closes on disconnect (cleanup fn returned to `CONNECT_HOOKS`)
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* @onStream("chatMessages")
|
|
58
|
+
* onMessage(msg: ChatMessage) {
|
|
59
|
+
* this.msgs.push(msg);
|
|
60
|
+
* this.scheduleUpdate();
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function onStream(accessorName: string): <This extends object>(_target: (this: This, value: any) => void, context: ClassMethodDecoratorContext<This>) => void;
|
|
65
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIvE,yCAAyC;AACzC,eAAO,MAAM,WAAW,0CAA8B,CAAC;AAMvD;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CACpB,OAAO,SAAS,MAAM,EACtB,OAAO,SAAS,UAAU,CAAC,OAAO,CAAC,EAEnC,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,EACvC,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,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4
|
+
* @stream — Auto-accessor decorator for server-push streams.
|
|
5
|
+
* @onStream — Method decorator that wires a stream handler on a LoomElement.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { stream, onStream } from "@toyz/loom-rpc";
|
|
9
|
+
*
|
|
10
|
+
* // eager (default) — opens automatically on connectedCallback
|
|
11
|
+
* @stream(ChatRouter, "messages", { fn: el => [el.roomId] })
|
|
12
|
+
* accessor chatMessages!: RpcStream<ChatMessage>;
|
|
13
|
+
*
|
|
14
|
+
* // callback-style (component)
|
|
15
|
+
* @onStream("chatMessages")
|
|
16
|
+
* onMessage(msg: ChatMessage) {
|
|
17
|
+
* this.msgs.push(msg);
|
|
18
|
+
* this.scheduleUpdate();
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // direct iteration (service / advanced)
|
|
22
|
+
* for await (const msg of this.chatMessages) { ... }
|
|
23
|
+
*
|
|
24
|
+
* // manual — must call open() yourself
|
|
25
|
+
* @stream(ChatRouter, "history", { fn: el => [el.roomId], eager: false })
|
|
26
|
+
* accessor history!: RpcStream<ChatMessage>;
|
|
27
|
+
* this.history.open();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
import { app, createSymbol } from "@toyz/loom";
|
|
31
|
+
import { Reactive } from "@toyz/loom/store";
|
|
32
|
+
import { RpcTransport } from "./transport";
|
|
33
|
+
import { resolveServiceName } from "./service";
|
|
34
|
+
/** Symbol for inspect() introspection */
|
|
35
|
+
export const RPC_STREAMS = createSymbol("rpc:streams");
|
|
36
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
// @stream decorator
|
|
38
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
39
|
+
/**
|
|
40
|
+
* @stream(Router, method, opts?) — streaming auto-accessor decorator.
|
|
41
|
+
*
|
|
42
|
+
* Returns an `RpcStream<T>` which is also directly iterable:
|
|
43
|
+
* `for await (const x of this.myStream) { ... }`
|
|
44
|
+
*
|
|
45
|
+
* By default (`eager: true`) the stream opens automatically in
|
|
46
|
+
* `connectedCallback`. Set `eager: false` and call `.open()` manually.
|
|
47
|
+
*
|
|
48
|
+
* Requires the registered `RpcTransport` to implement `stream()`.
|
|
49
|
+
*/
|
|
50
|
+
export function stream(router, method, opts) {
|
|
51
|
+
const routerName = resolveServiceName(router);
|
|
52
|
+
return (_target, context) => {
|
|
53
|
+
const stateKey = Symbol(`stream:${String(context.name)}`);
|
|
54
|
+
const traceKey = Symbol(`stream:trace:${String(context.name)}`);
|
|
55
|
+
const accessorName = String(context.name);
|
|
56
|
+
context.addInitializer(function () {
|
|
57
|
+
const ctor = this.constructor;
|
|
58
|
+
ctor[RPC_STREAMS.key] ??= [];
|
|
59
|
+
ctor[RPC_STREAMS.key].push({
|
|
60
|
+
accessor: accessorName,
|
|
61
|
+
router: routerName,
|
|
62
|
+
method: String(method),
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
get() {
|
|
67
|
+
if (!this[stateKey]) {
|
|
68
|
+
const sentinel = new Reactive(0);
|
|
69
|
+
this[traceKey] = sentinel;
|
|
70
|
+
sentinel.subscribe(() => this.scheduleUpdate?.());
|
|
71
|
+
const notify = () => { sentinel.set((v) => v + 1); };
|
|
72
|
+
this[stateKey] = createStreamState(routerName, method, opts, notify, this);
|
|
73
|
+
}
|
|
74
|
+
this[traceKey].value;
|
|
75
|
+
return this[stateKey];
|
|
76
|
+
},
|
|
77
|
+
set(_val) {
|
|
78
|
+
// State is managed internally
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
84
|
+
// Internal state factory
|
|
85
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
86
|
+
/** @internal — exported so tests can create state directly without decorators */
|
|
87
|
+
export function createStreamState(routerName, method, opts, scheduleUpdate, host) {
|
|
88
|
+
let status = "idle";
|
|
89
|
+
let error = null;
|
|
90
|
+
// Subscriber callbacks registered by @onStream — fed by the shared pump
|
|
91
|
+
const subscribers = new Set();
|
|
92
|
+
// Active iterator — held so close() can terminate the pump
|
|
93
|
+
let activeIterator = null;
|
|
94
|
+
function setStatus(s) {
|
|
95
|
+
status = s;
|
|
96
|
+
scheduleUpdate();
|
|
97
|
+
}
|
|
98
|
+
function getTransport() {
|
|
99
|
+
try {
|
|
100
|
+
return { transport: app.get(RpcTransport), ok: true };
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return {
|
|
104
|
+
ok: false,
|
|
105
|
+
error: new Error("[LoomRPC] No RpcTransport registered. " +
|
|
106
|
+
"Call app.use(RpcTransport, ...) before app.start()."),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Shared pump — one connection per RpcStream, fans out to all @onStream subscribers.
|
|
112
|
+
* Called by open(). No-op if already streaming.
|
|
113
|
+
*/
|
|
114
|
+
async function pump() {
|
|
115
|
+
if (status === "streaming")
|
|
116
|
+
return;
|
|
117
|
+
const result = getTransport();
|
|
118
|
+
if (!result.ok) {
|
|
119
|
+
error = result.error;
|
|
120
|
+
setStatus("error");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const { transport } = result;
|
|
124
|
+
if (!transport.stream) {
|
|
125
|
+
error = new Error("[LoomRPC] The registered RpcTransport does not implement stream(). " +
|
|
126
|
+
"Use a transport that supports streaming (e.g. WsTransport).");
|
|
127
|
+
setStatus("error");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const args = opts?.fn ? opts.fn(host) : [];
|
|
131
|
+
let iterable;
|
|
132
|
+
try {
|
|
133
|
+
iterable = transport.stream(routerName, method, args);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
137
|
+
setStatus("error");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
setStatus("streaming");
|
|
141
|
+
try {
|
|
142
|
+
activeIterator = iterable[Symbol.asyncIterator]();
|
|
143
|
+
while (true) {
|
|
144
|
+
const { value, done } = await activeIterator.next();
|
|
145
|
+
if (done)
|
|
146
|
+
break;
|
|
147
|
+
for (const cb of subscribers)
|
|
148
|
+
cb(value);
|
|
149
|
+
}
|
|
150
|
+
setStatus("closed");
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
if (status !== "closed") {
|
|
154
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
155
|
+
setStatus("error");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
activeIterator = null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Raw iterable — each call creates an independent generator, separate from
|
|
164
|
+
* the pump. Used for `for await (const x of stream)` and `.events`.
|
|
165
|
+
*/
|
|
166
|
+
function makeIterable() {
|
|
167
|
+
return {
|
|
168
|
+
[Symbol.asyncIterator]() {
|
|
169
|
+
const r = getTransport();
|
|
170
|
+
if (!r.ok) {
|
|
171
|
+
return {
|
|
172
|
+
async next() {
|
|
173
|
+
error = r.error;
|
|
174
|
+
setStatus("error");
|
|
175
|
+
return { value: undefined, done: true };
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const { transport } = r;
|
|
180
|
+
if (!transport.stream) {
|
|
181
|
+
return {
|
|
182
|
+
async next() {
|
|
183
|
+
error = new Error("[LoomRPC] Transport does not implement stream().");
|
|
184
|
+
setStatus("error");
|
|
185
|
+
return { value: undefined, done: true };
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const args = opts?.fn ? opts.fn(host) : [];
|
|
190
|
+
setStatus("streaming");
|
|
191
|
+
const inner = transport.stream(routerName, method, args)[Symbol.asyncIterator]();
|
|
192
|
+
return {
|
|
193
|
+
async next() {
|
|
194
|
+
try {
|
|
195
|
+
const result = await inner.next();
|
|
196
|
+
if (result.done)
|
|
197
|
+
setStatus("closed");
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
if (status !== "closed") {
|
|
202
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
203
|
+
setStatus("error");
|
|
204
|
+
}
|
|
205
|
+
return { value: undefined, done: true };
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
return() {
|
|
209
|
+
setStatus("closed");
|
|
210
|
+
return inner.return?.() ?? Promise.resolve({ value: undefined, done: true });
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const iterable = makeIterable();
|
|
217
|
+
const state = {
|
|
218
|
+
get status() { return status; },
|
|
219
|
+
get error() { return error; },
|
|
220
|
+
open() { pump(); },
|
|
221
|
+
close() {
|
|
222
|
+
if (activeIterator) {
|
|
223
|
+
activeIterator.return?.();
|
|
224
|
+
activeIterator = null;
|
|
225
|
+
}
|
|
226
|
+
setStatus("closed");
|
|
227
|
+
},
|
|
228
|
+
get events() { return iterable; },
|
|
229
|
+
[Symbol.asyncIterator]() {
|
|
230
|
+
return iterable[Symbol.asyncIterator]();
|
|
231
|
+
},
|
|
232
|
+
/** @internal — used by @onStream */
|
|
233
|
+
_subscribe(cb) {
|
|
234
|
+
subscribers.add(cb);
|
|
235
|
+
return () => subscribers.delete(cb);
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
return state;
|
|
239
|
+
}
|
|
240
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
241
|
+
// @onStream decorator
|
|
242
|
+
// ──────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
/** @internal — same singleton key that LoomElement.connectedCallback reads */
|
|
244
|
+
const CONNECT_HOOKS = createSymbol("connect:hooks");
|
|
245
|
+
/**
|
|
246
|
+
* Wire a method as a handler for an `RpcStream` accessor on a `LoomElement`.
|
|
247
|
+
*
|
|
248
|
+
* - Subscribes to the shared pump in `connectedCallback` (via `CONNECT_HOOKS`)
|
|
249
|
+
* - Auto-opens the stream if still idle
|
|
250
|
+
* - Unsubscribes and closes on disconnect (cleanup fn returned to `CONNECT_HOOKS`)
|
|
251
|
+
*
|
|
252
|
+
* ```ts
|
|
253
|
+
* @onStream("chatMessages")
|
|
254
|
+
* onMessage(msg: ChatMessage) {
|
|
255
|
+
* this.msgs.push(msg);
|
|
256
|
+
* this.scheduleUpdate();
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export function onStream(accessorName) {
|
|
261
|
+
return function (_target, context) {
|
|
262
|
+
const handlerKey = context.name;
|
|
263
|
+
context.addInitializer(function () {
|
|
264
|
+
// Use the same CONNECT_HOOKS array that LoomElement.connectedCallback reads.
|
|
265
|
+
// createSymbol is a singleton registry so "connect:hooks" always resolves
|
|
266
|
+
// to the same LoomSymbol regardless of which package calls it.
|
|
267
|
+
if (!this[CONNECT_HOOKS.key])
|
|
268
|
+
this[CONNECT_HOOKS.key] = [];
|
|
269
|
+
this[CONNECT_HOOKS.key].push((el) => {
|
|
270
|
+
const s = el[accessorName];
|
|
271
|
+
if (!s)
|
|
272
|
+
return;
|
|
273
|
+
if (typeof s._subscribe === "function") {
|
|
274
|
+
const unsub = s._subscribe((event) => {
|
|
275
|
+
el[handlerKey].call(el, event);
|
|
276
|
+
});
|
|
277
|
+
// Return cleanup — LoomElement.disconnectedCallback calls these
|
|
278
|
+
return () => {
|
|
279
|
+
unsub();
|
|
280
|
+
el[accessorName]?.close();
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
if (s.status === "idle")
|
|
284
|
+
s.open();
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;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IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;YAE3D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAO,EAAE,EAAE;gBACvC,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAExB,CAAC;gBACF,IAAI,CAAC,CAAC;oBAAE,OAAO;gBAEf,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;oBACvC,MAAM,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,KAAU,EAAE,EAAE;wBACvC,EAAE,CAAC,UAAU,CAAsB,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;oBACvD,CAAC,CAAC,CAAC;oBACH,gEAAgE;oBAChE,OAAO,GAAG,EAAE;wBACV,KAAK,EAAE,CAAC;wBACP,EAAE,CAAC,YAAY,CAAoB,EAAE,KAAK,EAAE,CAAC;oBAChD,CAAC,CAAC;gBACJ,CAAC;gBAED,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM;oBAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export declare abstract class RpcTransport {
|
|
17
17
|
abstract call<T>(router: string, method: string, args: any[], signal?: AbortSignal): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Optional — implement to support @stream / RpcStream.
|
|
20
|
+
* Returns an AsyncIterable the consumer drives via `for await`.
|
|
21
|
+
* The transport controls the connection (WebSocket, SSE, etc.).
|
|
22
|
+
* Teardown happens automatically when the iterator is returned/thrown.
|
|
23
|
+
*/
|
|
24
|
+
stream?<T>(router: string, method: string, args: any[]): AsyncIterable<T>;
|
|
18
25
|
}
|
|
19
26
|
/**
|
|
20
27
|
* Default HTTP transport — POST JSON to `/rpc/{router}/{method}`.
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,8BAAsB,YAAY;IAChC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,8BAAsB,YAAY;IAChC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IAE/F;;;;;OAKG;IACH,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC;CAC1E;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;gBAErC,OAAO,SAAS,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAO5D,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;CAsC7F;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,MAAM,CAAC,EAAE,MAAM;aACf,MAAM,CAAC,EAAE,MAAM;aACf,MAAM,CAAC,EAAE,MAAM;aACf,IAAI,CAAC,EAAE,MAAM;gBAJ7B,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,IAAI,CAAC,EAAE,MAAM,YAAA;CAKhC"}
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,MAAM,OAAgB,YAAY;
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;GAIG;AACH,MAAM,OAAgB,YAAY;CAUjC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAY;IAC5B,OAAO,CAAS;IAChB,OAAO,CAAyB;IAEjD,YAAY,OAAO,GAAG,MAAM,EAAE,UAAkC,EAAE;QAChE,KAAK,EAAE,CAAC;QACR,uBAAuB;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CAAI,MAAc,EAAE,MAAc,EAAE,IAAW,EAAE,MAAoB;QAC7E,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QAClD,MAAM,IAAI,GAAe,EAAE,IAAI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;IACzB,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -57,6 +57,51 @@ export interface RpcMutator<TArgs extends any[], TReturn> {
|
|
|
57
57
|
/** Reset the mutator state (clear data, error, loading) */
|
|
58
58
|
reset(): void;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for @stream decorator.
|
|
62
|
+
*/
|
|
63
|
+
export interface RpcStreamOptions<TRouter, TMethod extends RpcMethods<TRouter>> {
|
|
64
|
+
/** Extract procedure args from element/service state. Called once when the stream opens. */
|
|
65
|
+
fn?: (el: any) => InferArgs<TRouter, TMethod>;
|
|
66
|
+
/**
|
|
67
|
+
* Whether to open the stream automatically when the element connects.
|
|
68
|
+
* When false, call `stream.open()` manually to start receiving events.
|
|
69
|
+
* Default: true
|
|
70
|
+
*/
|
|
71
|
+
eager?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* State container for a server-push stream.
|
|
75
|
+
*
|
|
76
|
+
* Implements `AsyncIterable<T>` so you can iterate directly:
|
|
77
|
+
* ```ts
|
|
78
|
+
* for await (const msg of this.chatMessages) { ... }
|
|
79
|
+
* ```
|
|
80
|
+
* Or use `.events` for the same iterable, or `.open()` + `@onStream` for
|
|
81
|
+
* component-level callback wiring.
|
|
82
|
+
*/
|
|
83
|
+
export interface RpcStream<T> extends AsyncIterable<T> {
|
|
84
|
+
/** Current state of the stream connection */
|
|
85
|
+
readonly status: "idle" | "streaming" | "error" | "closed";
|
|
86
|
+
/** Error if status === "error", otherwise null */
|
|
87
|
+
readonly error: Error | null;
|
|
88
|
+
/**
|
|
89
|
+
* Open the stream and start pumping events to `@onStream` callbacks.
|
|
90
|
+
* Called automatically on connect when `eager: true` (the default).
|
|
91
|
+
* Call manually when `eager: false`.
|
|
92
|
+
*/
|
|
93
|
+
open(): void;
|
|
94
|
+
/** Close the stream and release the connection */
|
|
95
|
+
close(): void;
|
|
96
|
+
/**
|
|
97
|
+
* Named alias for `[Symbol.asyncIterator]()` — same iterable, explicit name.
|
|
98
|
+
* Prefer iterating the stream directly (`for await (const x of stream)`)
|
|
99
|
+
* unless you need to hold a reference to the iterable separately.
|
|
100
|
+
*/
|
|
101
|
+
readonly events: AsyncIterable<T>;
|
|
102
|
+
/** Required by AsyncIterable — delegates to .events */
|
|
103
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
104
|
+
}
|
|
60
105
|
/**
|
|
61
106
|
* State container for a query — auto-fetched, reactive, with SWR.
|
|
62
107
|
* Extends ApiState for backwards compatibility.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK;CACjE,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IACxC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAC1C,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,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W,SAAS,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;IACpD,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAC;IAC3D,kDAAkD;IAClD,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B;;;;OAIG;IACH,IAAI,IAAI,IAAI,CAAC;IACb,kDAAkD;IAClD,KAAK,IAAI,IAAI,CAAC;IACd;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAClC,uDAAuD;IACvD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,QAAQ,CAAC,KAAK,SAAS,GAAG,EAAE,EAAE,OAAO,CAAE,SAAQ,QAAQ,CAAC,OAAO,CAAC;CAEhF;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5C"}
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|