@flamingo-stack/openframe-frontend-core 0.0.195 → 0.0.197
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/chunk-4CWSZPXH.cjs.map +1 -1
- package/dist/{chunk-PJ5KFD2V.js → chunk-4ML3NA2L.js} +75 -1
- package/dist/{chunk-PJ5KFD2V.js.map → chunk-4ML3NA2L.js.map} +1 -1
- package/dist/{chunk-U6AJSRJP.js → chunk-GIQZAYY5.js} +731 -365
- package/dist/chunk-GIQZAYY5.js.map +1 -0
- package/dist/{chunk-IQM3G2I6.cjs → chunk-IMDXOVYD.cjs} +777 -411
- package/dist/chunk-IMDXOVYD.cjs.map +1 -0
- package/dist/{chunk-CVMSC7M4.cjs → chunk-OII2IERE.cjs} +77 -3
- package/dist/chunk-OII2IERE.cjs.map +1 -0
- package/dist/chunk-UC43NICZ.cjs.map +1 -1
- package/dist/chunk-V2FNIPZJ.cjs.map +1 -1
- package/dist/chunk-VJTFBYVG.cjs.map +1 -1
- package/dist/chunk-VRHGVLSL.cjs.map +1 -1
- package/dist/chunk-WZW7C7TF.cjs.map +1 -1
- package/dist/chunk-XQFFGR6U.cjs.map +1 -1
- package/dist/components/chart.d.ts +7 -14
- package/dist/components/chart.d.ts.map +1 -1
- package/dist/components/chat/hooks/index.d.ts +1 -0
- package/dist/components/chat/hooks/index.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts +15 -0
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts.map +1 -0
- package/dist/components/chat/types/api.types.d.ts +43 -0
- package/dist/components/chat/types/api.types.d.ts.map +1 -1
- package/dist/components/chat/types/network.types.d.ts +4 -0
- package/dist/components/chat/types/network.types.d.ts.map +1 -1
- package/dist/components/features/board/ticket-card-skeleton.d.ts.map +1 -1
- package/dist/components/features/board/ticket-card.d.ts.map +1 -1
- package/dist/components/features/index.cjs +3 -3
- package/dist/components/features/index.cjs.map +1 -1
- package/dist/components/features/index.js +2 -2
- package/dist/components/icons/index.cjs.map +1 -1
- package/dist/components/icons-v2-generated/index.cjs.map +1 -1
- package/dist/components/index.cjs +5 -3
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +4 -2
- package/dist/components/navigation/index.cjs +3 -3
- package/dist/components/navigation/index.cjs.map +1 -1
- package/dist/components/navigation/index.js +2 -2
- package/dist/components/resizable.d.ts +1 -1
- package/dist/components/toast/index.cjs.map +1 -1
- package/dist/components/ui/file-manager/index.cjs.map +1 -1
- package/dist/components/ui/index.cjs +5 -3
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +4 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/index.cjs +5 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/nats/index.cjs +73 -0
- package/dist/nats/index.cjs.map +1 -1
- package/dist/nats/index.js +73 -0
- package/dist/nats/index.js.map +1 -1
- package/dist/nats/nats.d.ts +22 -1
- package/dist/nats/nats.d.ts.map +1 -1
- package/dist/tailwind.config.cjs +7 -7
- package/dist/tailwind.config.cjs.map +1 -1
- package/dist/tailwind.config.js +7 -7
- package/dist/tailwind.config.js.map +1 -1
- package/package.json +1 -1
- package/src/components/chat/hooks/index.ts +1 -0
- package/src/components/chat/hooks/use-jetstream-dialog-subscription.ts +474 -0
- package/src/components/chat/types/api.types.ts +45 -0
- package/src/components/chat/types/network.types.ts +4 -0
- package/src/components/features/board/ticket-card-skeleton.tsx +16 -4
- package/src/components/features/board/ticket-card.tsx +6 -4
- package/src/nats/nats.ts +117 -0
- package/dist/chunk-CVMSC7M4.cjs.map +0 -1
- package/dist/chunk-IQM3G2I6.cjs.map +0 -1
- package/dist/chunk-U6AJSRJP.js.map +0 -1
package/src/nats/nats.ts
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ConnectionOptions,
|
|
3
|
+
Consumer,
|
|
4
|
+
ConsumerMessages,
|
|
5
|
+
JsMsg,
|
|
3
6
|
MsgHdrs as NatsHeaders,
|
|
4
7
|
Msg,
|
|
5
8
|
NatsConnection,
|
|
6
9
|
Subscription,
|
|
7
10
|
} from 'nats.ws'
|
|
8
11
|
|
|
12
|
+
export type JetStreamDeliverPolicy = 'new' | 'byStartSequence'
|
|
13
|
+
|
|
14
|
+
export interface JetStreamOrderedSubscribeOptions {
|
|
15
|
+
streamName: string
|
|
16
|
+
filterSubject: string
|
|
17
|
+
deliverPolicy: JetStreamDeliverPolicy
|
|
18
|
+
/** Required when deliverPolicy === 'byStartSequence'. */
|
|
19
|
+
optStartSeq?: number
|
|
20
|
+
/** Auto-cleanup the ephemeral consumer after this idle time. Default: 5 minutes. */
|
|
21
|
+
inactiveThresholdMs?: number
|
|
22
|
+
/** AbortSignal to tear down the consumer. */
|
|
23
|
+
signal?: AbortSignal
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface JetStreamSubscriptionHandle {
|
|
27
|
+
unsubscribe(): void
|
|
28
|
+
}
|
|
29
|
+
|
|
9
30
|
export interface NatsClientOptions {
|
|
10
31
|
/**
|
|
11
32
|
* NATS server URL(s), for example:
|
|
@@ -147,6 +168,16 @@ export interface NatsClient {
|
|
|
147
168
|
options?: NatsSubscribeOptions,
|
|
148
169
|
): NatsSubscriptionHandle
|
|
149
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Subscribe to a JetStream subject via an ephemeral OrderedConsumer (no acks).
|
|
173
|
+
* Use `optStartSeq` with `deliverPolicy: 'byStartSequence'` to resume from a known offset,
|
|
174
|
+
* or `deliverPolicy: 'new'` to live-tail.
|
|
175
|
+
*/
|
|
176
|
+
subscribeJetStreamOrdered(
|
|
177
|
+
onMessage: (msg: JsMsg) => void | Promise<void>,
|
|
178
|
+
options: JetStreamOrderedSubscribeOptions,
|
|
179
|
+
): Promise<JetStreamSubscriptionHandle>
|
|
180
|
+
|
|
150
181
|
onStatus(listener: (event: NatsStatusEvent) => void): () => void
|
|
151
182
|
}
|
|
152
183
|
|
|
@@ -473,6 +504,91 @@ export function createNatsClient(options: NatsClientOptions): NatsClient {
|
|
|
473
504
|
)
|
|
474
505
|
}
|
|
475
506
|
|
|
507
|
+
async function subscribeJetStreamOrdered(
|
|
508
|
+
onMessage: (msg: JsMsg) => void | Promise<void>,
|
|
509
|
+
opts: JetStreamOrderedSubscribeOptions,
|
|
510
|
+
): Promise<JetStreamSubscriptionHandle> {
|
|
511
|
+
const conn = requireConnection()
|
|
512
|
+
if (opts.signal?.aborted) {
|
|
513
|
+
return { unsubscribe() {} }
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const nats = await importNats()
|
|
517
|
+
if (opts.signal?.aborted) {
|
|
518
|
+
return { unsubscribe() {} }
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const inactiveThresholdNs =
|
|
522
|
+
(opts.inactiveThresholdMs ?? 5 * 60_000) * 1_000_000
|
|
523
|
+
|
|
524
|
+
const js = conn.jetstream()
|
|
525
|
+
const consumer: Consumer = await js.consumers.get(opts.streamName, {
|
|
526
|
+
filterSubjects: opts.filterSubject,
|
|
527
|
+
deliver_policy: nats.DeliverPolicy.StartSequence,
|
|
528
|
+
opt_start_seq: opts.optStartSeq ?? 0,
|
|
529
|
+
inactive_threshold: inactiveThresholdNs,
|
|
530
|
+
})
|
|
531
|
+
|
|
532
|
+
const iterRef: { current: ConsumerMessages | null } = { current: null }
|
|
533
|
+
let closed = false
|
|
534
|
+
|
|
535
|
+
const onAbort = () => {
|
|
536
|
+
void teardown()
|
|
537
|
+
}
|
|
538
|
+
opts.signal?.addEventListener('abort', onAbort, { once: true })
|
|
539
|
+
|
|
540
|
+
async function teardown(): Promise<void> {
|
|
541
|
+
if (closed) return
|
|
542
|
+
closed = true
|
|
543
|
+
opts.signal?.removeEventListener('abort', onAbort)
|
|
544
|
+
const iter = iterRef.current
|
|
545
|
+
iterRef.current = null
|
|
546
|
+
if (iter) {
|
|
547
|
+
try {
|
|
548
|
+
await iter.close()
|
|
549
|
+
} catch {
|
|
550
|
+
// ignore
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
if (opts.signal?.aborted) {
|
|
556
|
+
void teardown()
|
|
557
|
+
return { unsubscribe() {} }
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
;(async () => {
|
|
561
|
+
try {
|
|
562
|
+
const iter = await consumer.consume()
|
|
563
|
+
if (closed) {
|
|
564
|
+
try {
|
|
565
|
+
await iter.close()
|
|
566
|
+
} catch {
|
|
567
|
+
// ignore
|
|
568
|
+
}
|
|
569
|
+
return
|
|
570
|
+
}
|
|
571
|
+
iterRef.current = iter
|
|
572
|
+
for await (const msg of iter) {
|
|
573
|
+
if (closed) break
|
|
574
|
+
try {
|
|
575
|
+
await onMessage(msg)
|
|
576
|
+
} catch (e) {
|
|
577
|
+
emitStatus({ status: 'error', data: e })
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
} catch (e) {
|
|
581
|
+
if (!closed) emitStatus({ status: 'error', data: e })
|
|
582
|
+
}
|
|
583
|
+
})().catch((e) => emitStatus({ status: 'error', data: e }))
|
|
584
|
+
|
|
585
|
+
return {
|
|
586
|
+
unsubscribe() {
|
|
587
|
+
void teardown()
|
|
588
|
+
},
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
476
592
|
function onStatus(listener: (event: NatsStatusEvent) => void): () => void {
|
|
477
593
|
statusListeners.add(listener)
|
|
478
594
|
return () => statusListeners.delete(listener)
|
|
@@ -491,6 +607,7 @@ export function createNatsClient(options: NatsClientOptions): NatsClient {
|
|
|
491
607
|
subscribeBytes,
|
|
492
608
|
subscribeString,
|
|
493
609
|
subscribeJson,
|
|
610
|
+
subscribeJetStreamOrdered,
|
|
494
611
|
onStatus,
|
|
495
612
|
}
|
|
496
613
|
}
|