@orpc/bun 2.0.0-beta.33 → 2.0.0-beta.35
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/README.md +15 -14
- package/dist/index.d.mts +8 -59
- package/dist/index.d.ts +8 -59
- package/dist/index.mjs +26 -110
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -52,20 +52,20 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
52
52
|
|
|
53
53
|
**Framework & ecosystem integrations**
|
|
54
54
|
|
|
55
|
-
| Package | Purpose
|
|
56
|
-
| ------------------------------------------------------------------------------------ |
|
|
57
|
-
| [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
58
|
-
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
59
|
-
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
60
|
-
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
61
|
-
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/).
|
|
62
|
-
| [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/).
|
|
63
|
-
| [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/).
|
|
64
|
-
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/).
|
|
65
|
-
| [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads.
|
|
66
|
-
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/).
|
|
67
|
-
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare
|
|
68
|
-
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
55
|
+
| Package | Purpose | Docs |
|
|
56
|
+
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
57
|
+
| [@orpc/next](https://www.npmjs.com/package/@orpc/next) | Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data). | [Next.js](https://orpc.dev/docs/integrations/next) |
|
|
58
|
+
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk) | Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools. | [AI SDK](https://orpc.dev/docs/integrations/ai-sdk) |
|
|
59
|
+
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query) | Integrate with [TanStack Query](https://tanstack.com/query/latest). | [TanStack Query](https://orpc.dev/docs/integrations/tanstack-query) |
|
|
60
|
+
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada) | Integrate with [Pinia Colada](https://pinia-colada.esm.dev/). | [Pinia Colada](https://orpc.dev/docs/integrations/pinia-colada) |
|
|
61
|
+
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
|
|
62
|
+
| [@orpc/experimental-msw](https://www.npmjs.com/package/@orpc/experimental-msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
|
|
63
|
+
| [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
|
|
64
|
+
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
|
|
65
|
+
| [@orpc/node](https://www.npmjs.com/package/@orpc/node) | [Node.js](https://nodejs.org/) plugins for static file serving and large uploads. | [Static File](https://orpc.dev/docs/plugins/static-file), [Tmp File Upload](https://orpc.dev/docs/plugins/tmp-file-upload), [Batch Response Compression](https://orpc.dev/docs/plugins/batch-response-compression) |
|
|
66
|
+
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun) | Adapters for [Bun's Redis](https://bun.sh/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit) |
|
|
67
|
+
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare) | Adapters for [Cloudflare Workers](https://developers.cloudflare.com/workers/). | [Publisher](https://orpc.dev/docs/helpers/publisher), [Rate Limit](https://orpc.dev/docs/helpers/ratelimit), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
|
|
68
|
+
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc) | Reuse existing [tRPC](https://trpc.io/) routers within oRPC. | [tRPC](https://orpc.dev/docs/integrations/trpc) |
|
|
69
69
|
|
|
70
70
|
**Observability**
|
|
71
71
|
|
|
@@ -124,6 +124,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
124
124
|
<td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&v=4" width="139" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
|
|
125
125
|
<td align="center"><a href="https://github.com/hoangbn?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&v=4" width="139" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
|
|
126
126
|
<td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="139" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
|
|
127
|
+
<td align="center"><a href="https://automatio.ai/?ref=middleapi&utm_source=middleapi&utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&v=4" width="139" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
|
|
127
128
|
</tr>
|
|
128
129
|
</table>
|
|
129
130
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRedisPublisher, BaseRedisPublisherOptions, RedisStreamTrimOptions, RedisStreamEntry } from '@orpc/publisher/base-redis';
|
|
2
2
|
import { Promisable } from '@orpc/shared';
|
|
3
3
|
import { RedisClient } from 'bun';
|
|
4
|
-
import { RPCSerializer } from '@orpc/client';
|
|
5
4
|
import { RateLimiter, RateLimitOptions, RateLimitResult } from '@orpc/ratelimit';
|
|
6
5
|
|
|
7
|
-
interface BunRedisPublisherOptions extends
|
|
6
|
+
interface BunRedisPublisherOptions extends BaseRedisPublisherOptions {
|
|
8
7
|
/**
|
|
9
8
|
* Redis subscriber instance.
|
|
10
9
|
* Pub/Sub takes over the connection, so a client with subscriptions
|
|
@@ -13,46 +12,6 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
13
12
|
* @default redis.duplicate() (lazily created on first listen)
|
|
14
13
|
*/
|
|
15
14
|
subscriber?: undefined | Promisable<RedisClient>;
|
|
16
|
-
/**
|
|
17
|
-
* The prefix to use for Redis keys.
|
|
18
|
-
*
|
|
19
|
-
* @default ''
|
|
20
|
-
*/
|
|
21
|
-
prefix?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Serializer for serialize and deserialize payloads.
|
|
24
|
-
*
|
|
25
|
-
* @default RPCSerializer
|
|
26
|
-
*/
|
|
27
|
-
serializer?: undefined | Pick<RPCSerializer, keyof RPCSerializer>;
|
|
28
|
-
/**
|
|
29
|
-
* Configuration for event resume support.
|
|
30
|
-
*
|
|
31
|
-
* When enabled, published events are temporarily stored so new
|
|
32
|
-
* subscribers can resume from a previous position using `lastEventId`.
|
|
33
|
-
*
|
|
34
|
-
* @default { enabled: false }
|
|
35
|
-
*/
|
|
36
|
-
resume?: {
|
|
37
|
-
/**
|
|
38
|
-
* Whether event resume support is enabled.
|
|
39
|
-
*
|
|
40
|
-
* When enabled, published events are temporarily stored so new
|
|
41
|
-
* subscribers can resume from a previous position using `lastEventId`.
|
|
42
|
-
*
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
enabled: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* How long (in seconds) to retain events for resume.
|
|
48
|
-
*
|
|
49
|
-
* Expired events are cleaned up lazily for performance reasons, so
|
|
50
|
-
* some events may remain available slightly longer than this period.
|
|
51
|
-
*
|
|
52
|
-
* @default 300 (5 min)
|
|
53
|
-
*/
|
|
54
|
-
seconds?: number;
|
|
55
|
-
};
|
|
56
15
|
}
|
|
57
16
|
/**
|
|
58
17
|
* Publisher adapter for Bun's built-in Redis client. Distributes events across
|
|
@@ -60,24 +19,14 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
60
19
|
*
|
|
61
20
|
* @see {@link https://orpc.dev/docs/helpers/publisher#adapters | Publisher Helpers - Adapters}
|
|
62
21
|
*/
|
|
63
|
-
declare class BunRedisPublisher<T extends Record<string, object>> extends
|
|
22
|
+
declare class BunRedisPublisher<T extends Record<string, object>> extends BaseRedisPublisher<T> {
|
|
64
23
|
private readonly redis;
|
|
65
24
|
private subscriber;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* The exactness of the `XTRIM` command.
|
|
72
|
-
* Used for testing purpose.
|
|
73
|
-
*/
|
|
74
|
-
private readonly xTrimExactness;
|
|
75
|
-
constructor(redis: RedisClient, options?: BunRedisPublisherOptions);
|
|
76
|
-
private readonly firstPublishTimeMap;
|
|
77
|
-
publish<K extends keyof T & string>(event: K, payload: T[K]): Promise<void>;
|
|
78
|
-
protected subscribeListener<K extends keyof T & string>(event: K, originalListener: (payload: T[K]) => void, { lastEventId, onError }?: PublisherSubscribeListenerOptions): Promise<() => Promise<void>>;
|
|
79
|
-
private serializePayload;
|
|
80
|
-
private deserializePayload;
|
|
25
|
+
constructor(redis: RedisClient, { subscriber, ...options }?: BunRedisPublisherOptions);
|
|
26
|
+
protected publishMessage(channel: string, message: string): Promise<void>;
|
|
27
|
+
protected subscribeChannel(channel: string, listener: (message: unknown) => void): Promise<() => Promise<void>>;
|
|
28
|
+
protected addStreamEntry(key: string, data: string, trim?: RedisStreamTrimOptions): Promise<string>;
|
|
29
|
+
protected readStreamEntries(key: string, lastId: string): Promise<RedisStreamEntry[]>;
|
|
81
30
|
}
|
|
82
31
|
|
|
83
32
|
interface BunRedisRateLimiterOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRedisPublisher, BaseRedisPublisherOptions, RedisStreamTrimOptions, RedisStreamEntry } from '@orpc/publisher/base-redis';
|
|
2
2
|
import { Promisable } from '@orpc/shared';
|
|
3
3
|
import { RedisClient } from 'bun';
|
|
4
|
-
import { RPCSerializer } from '@orpc/client';
|
|
5
4
|
import { RateLimiter, RateLimitOptions, RateLimitResult } from '@orpc/ratelimit';
|
|
6
5
|
|
|
7
|
-
interface BunRedisPublisherOptions extends
|
|
6
|
+
interface BunRedisPublisherOptions extends BaseRedisPublisherOptions {
|
|
8
7
|
/**
|
|
9
8
|
* Redis subscriber instance.
|
|
10
9
|
* Pub/Sub takes over the connection, so a client with subscriptions
|
|
@@ -13,46 +12,6 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
13
12
|
* @default redis.duplicate() (lazily created on first listen)
|
|
14
13
|
*/
|
|
15
14
|
subscriber?: undefined | Promisable<RedisClient>;
|
|
16
|
-
/**
|
|
17
|
-
* The prefix to use for Redis keys.
|
|
18
|
-
*
|
|
19
|
-
* @default ''
|
|
20
|
-
*/
|
|
21
|
-
prefix?: string;
|
|
22
|
-
/**
|
|
23
|
-
* Serializer for serialize and deserialize payloads.
|
|
24
|
-
*
|
|
25
|
-
* @default RPCSerializer
|
|
26
|
-
*/
|
|
27
|
-
serializer?: undefined | Pick<RPCSerializer, keyof RPCSerializer>;
|
|
28
|
-
/**
|
|
29
|
-
* Configuration for event resume support.
|
|
30
|
-
*
|
|
31
|
-
* When enabled, published events are temporarily stored so new
|
|
32
|
-
* subscribers can resume from a previous position using `lastEventId`.
|
|
33
|
-
*
|
|
34
|
-
* @default { enabled: false }
|
|
35
|
-
*/
|
|
36
|
-
resume?: {
|
|
37
|
-
/**
|
|
38
|
-
* Whether event resume support is enabled.
|
|
39
|
-
*
|
|
40
|
-
* When enabled, published events are temporarily stored so new
|
|
41
|
-
* subscribers can resume from a previous position using `lastEventId`.
|
|
42
|
-
*
|
|
43
|
-
* @default false
|
|
44
|
-
*/
|
|
45
|
-
enabled: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* How long (in seconds) to retain events for resume.
|
|
48
|
-
*
|
|
49
|
-
* Expired events are cleaned up lazily for performance reasons, so
|
|
50
|
-
* some events may remain available slightly longer than this period.
|
|
51
|
-
*
|
|
52
|
-
* @default 300 (5 min)
|
|
53
|
-
*/
|
|
54
|
-
seconds?: number;
|
|
55
|
-
};
|
|
56
15
|
}
|
|
57
16
|
/**
|
|
58
17
|
* Publisher adapter for Bun's built-in Redis client. Distributes events across
|
|
@@ -60,24 +19,14 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
60
19
|
*
|
|
61
20
|
* @see {@link https://orpc.dev/docs/helpers/publisher#adapters | Publisher Helpers - Adapters}
|
|
62
21
|
*/
|
|
63
|
-
declare class BunRedisPublisher<T extends Record<string, object>> extends
|
|
22
|
+
declare class BunRedisPublisher<T extends Record<string, object>> extends BaseRedisPublisher<T> {
|
|
64
23
|
private readonly redis;
|
|
65
24
|
private subscriber;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* The exactness of the `XTRIM` command.
|
|
72
|
-
* Used for testing purpose.
|
|
73
|
-
*/
|
|
74
|
-
private readonly xTrimExactness;
|
|
75
|
-
constructor(redis: RedisClient, options?: BunRedisPublisherOptions);
|
|
76
|
-
private readonly firstPublishTimeMap;
|
|
77
|
-
publish<K extends keyof T & string>(event: K, payload: T[K]): Promise<void>;
|
|
78
|
-
protected subscribeListener<K extends keyof T & string>(event: K, originalListener: (payload: T[K]) => void, { lastEventId, onError }?: PublisherSubscribeListenerOptions): Promise<() => Promise<void>>;
|
|
79
|
-
private serializePayload;
|
|
80
|
-
private deserializePayload;
|
|
25
|
+
constructor(redis: RedisClient, { subscriber, ...options }?: BunRedisPublisherOptions);
|
|
26
|
+
protected publishMessage(channel: string, message: string): Promise<void>;
|
|
27
|
+
protected subscribeChannel(channel: string, listener: (message: unknown) => void): Promise<() => Promise<void>>;
|
|
28
|
+
protected addStreamEntry(key: string, data: string, trim?: RedisStreamTrimOptions): Promise<string>;
|
|
29
|
+
protected readStreamEntries(key: string, lastId: string): Promise<RedisStreamEntry[]>;
|
|
81
30
|
}
|
|
82
31
|
|
|
83
32
|
interface BunRedisRateLimiterOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -1,123 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { stringifyJSON, parseEmptyableJSON, once, sleep } from '@orpc/shared';
|
|
4
|
-
import { unwrapEvent, withEventMeta, getEventMeta } from '@standardserver/core';
|
|
1
|
+
import { BaseRedisPublisher } from '@orpc/publisher/base-redis';
|
|
2
|
+
import { sleep } from '@orpc/shared';
|
|
5
3
|
|
|
6
|
-
class BunRedisPublisher extends
|
|
7
|
-
constructor(redis, options = {}) {
|
|
4
|
+
class BunRedisPublisher extends BaseRedisPublisher {
|
|
5
|
+
constructor(redis, { subscriber, ...options } = {}) {
|
|
8
6
|
super(options);
|
|
9
7
|
this.redis = redis;
|
|
10
|
-
this.
|
|
11
|
-
this.serializer = options.serializer ?? new RPCSerializer();
|
|
12
|
-
this.resumeEnabled = options.resume?.enabled ?? false;
|
|
13
|
-
this.resumeSeconds = options.resume?.seconds ?? 300;
|
|
14
|
-
this.subscriber = options.subscriber;
|
|
8
|
+
this.subscriber = subscriber;
|
|
15
9
|
}
|
|
16
10
|
subscriber;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
resumeEnabled;
|
|
20
|
-
resumeSeconds;
|
|
21
|
-
/**
|
|
22
|
-
* The exactness of the `XTRIM` command.
|
|
23
|
-
* Used for testing purpose.
|
|
24
|
-
*/
|
|
25
|
-
xTrimExactness = "~";
|
|
26
|
-
firstPublishTimeMap = /* @__PURE__ */ new Map();
|
|
27
|
-
async publish(event, payload) {
|
|
28
|
-
const redisKey = `${this.prefix}${event}`;
|
|
29
|
-
const data = this.serializePayload(payload);
|
|
30
|
-
let id;
|
|
31
|
-
if (this.resumeEnabled) {
|
|
32
|
-
const now = Date.now();
|
|
33
|
-
for (const [event2, firstPublishTime] of this.firstPublishTimeMap) {
|
|
34
|
-
if (firstPublishTime + this.resumeSeconds * 1e3 < now) {
|
|
35
|
-
this.firstPublishTimeMap.delete(event2);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!this.firstPublishTimeMap.has(event)) {
|
|
39
|
-
this.firstPublishTimeMap.set(event, now);
|
|
40
|
-
const result = await Promise.all([
|
|
41
|
-
this.redis.send("XADD", [redisKey, "*", "data", stringifyJSON(data)]),
|
|
42
|
-
this.redis.send("XTRIM", [redisKey, "MINID", this.xTrimExactness, `${now - this.resumeSeconds * 1e3}-0`]),
|
|
43
|
-
// Use a 2x TTL so events published near the end of the resume window
|
|
44
|
-
// are not expired before the next window updates the key expiration.
|
|
45
|
-
this.redis.expire(redisKey, this.resumeSeconds * 2)
|
|
46
|
-
]);
|
|
47
|
-
id = result[0];
|
|
48
|
-
} else {
|
|
49
|
-
id = await this.redis.send("XADD", [redisKey, "*", "data", stringifyJSON(data)]);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
await this.redis.publish(redisKey, stringifyJSON({ data, id }));
|
|
11
|
+
async publishMessage(channel, message) {
|
|
12
|
+
await this.redis.publish(channel, message);
|
|
53
13
|
}
|
|
54
|
-
async
|
|
55
|
-
const redisKey = `${this.prefix}${event}`;
|
|
56
|
-
let pendingPayloads = [];
|
|
57
|
-
const resumedIds = /* @__PURE__ */ new Set();
|
|
58
|
-
const deduplicatingListener = (payload) => {
|
|
59
|
-
if (pendingPayloads) {
|
|
60
|
-
pendingPayloads.push(payload);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const id = getEventMeta(payload)?.id;
|
|
64
|
-
if (id !== void 0 && resumedIds.has(id)) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
originalListener(payload);
|
|
68
|
-
};
|
|
69
|
-
const redisListener = (message) => {
|
|
70
|
-
try {
|
|
71
|
-
const { id, data } = parseEmptyableJSON(message);
|
|
72
|
-
const payload = this.deserializePayload(id, data);
|
|
73
|
-
deduplicatingListener(payload);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
onError?.(error);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
14
|
+
async subscribeChannel(channel, listener) {
|
|
78
15
|
this.subscriber ??= this.redis.duplicate();
|
|
79
16
|
const subscriber = await this.subscriber;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const results = await this.redis.send("XREAD", ["STREAMS", redisKey, lastEventId]);
|
|
85
|
-
if (results && results[redisKey]) {
|
|
86
|
-
const messages = results[redisKey];
|
|
87
|
-
for (const [id, message] of messages) {
|
|
88
|
-
const rawData = message[1];
|
|
89
|
-
const data = parseEmptyableJSON(rawData);
|
|
90
|
-
const payload = this.deserializePayload(id, data);
|
|
91
|
-
resumedIds.add(id);
|
|
92
|
-
originalListener(payload);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} finally {
|
|
97
|
-
const pending = pendingPayloads;
|
|
98
|
-
pendingPayloads = void 0;
|
|
99
|
-
for (const payload of pending) {
|
|
100
|
-
deduplicatingListener(payload);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
await subscribePromise;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
await subscriber.unsubscribe(redisKey, redisListener);
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
|
-
return once(async () => {
|
|
109
|
-
await subscriber.unsubscribe(redisKey, redisListener);
|
|
110
|
-
});
|
|
17
|
+
await subscriber.subscribe(channel, listener);
|
|
18
|
+
return async () => {
|
|
19
|
+
await subscriber.unsubscribe(channel, listener);
|
|
20
|
+
};
|
|
111
21
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
22
|
+
async addStreamEntry(key, data, trim) {
|
|
23
|
+
if (!trim) {
|
|
24
|
+
return await this.redis.send("XADD", [key, "*", "data", data]);
|
|
25
|
+
}
|
|
26
|
+
const [id] = await Promise.all([
|
|
27
|
+
this.redis.send("XADD", [key, "*", "data", data]),
|
|
28
|
+
this.redis.send("XTRIM", [key, "MINID", trim.exactness, trim.minId]),
|
|
29
|
+
this.redis.expire(key, trim.expireSeconds)
|
|
30
|
+
]);
|
|
31
|
+
return id;
|
|
115
32
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
33
|
+
async readStreamEntries(key, lastId) {
|
|
34
|
+
const results = await this.redis.send("XREAD", ["STREAMS", key, lastId]);
|
|
35
|
+
const entries = results?.[key] ?? [];
|
|
36
|
+
return entries.map(([id, fields]) => ({ id, data: fields[1] }));
|
|
121
37
|
}
|
|
122
38
|
}
|
|
123
39
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/bun",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.35",
|
|
5
5
|
"description": "Bun integration for oRPC: Redis-backed pub/sub and rate limiting using Bun's built-in Redis client",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@orpc/client": "2.0.0-beta.
|
|
39
|
-
"@orpc/publisher": "2.0.0-beta.
|
|
40
|
-
"@orpc/ratelimit": "2.0.0-beta.
|
|
41
|
-
"@orpc/server": "2.0.0-beta.
|
|
42
|
-
"@orpc/shared": "2.0.0-beta.
|
|
43
|
-
"@
|
|
38
|
+
"@orpc/client": "2.0.0-beta.35",
|
|
39
|
+
"@orpc/publisher": "2.0.0-beta.35",
|
|
40
|
+
"@orpc/ratelimit": "2.0.0-beta.35",
|
|
41
|
+
"@orpc/server": "2.0.0-beta.35",
|
|
42
|
+
"@orpc/shared": "2.0.0-beta.35",
|
|
43
|
+
"@standard-server/core": "~0.9.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/bun": "^1.3.14",
|