@orpc/bun 2.0.0-beta.18 → 2.0.0-beta.19
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 +5 -2
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +13 -13
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -46,11 +46,14 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
46
46
|
**Framework & ecosystem integrations**
|
|
47
47
|
|
|
48
48
|
- [@orpc/next](https://www.npmjs.com/package/@orpc/next): Integrate with [Next.js Server Functions](https://nextjs.org/docs/app/getting-started/mutating-data).
|
|
49
|
+
- [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk): Turn contracts and procedures into [AI SDK](https://ai-sdk.dev/) tools.
|
|
49
50
|
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): Integrate with [TanStack Query](https://tanstack.com/query/latest).
|
|
51
|
+
- [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada): Integrate with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
50
52
|
- [@orpc/experimental-effect](https://www.npmjs.com/package/@orpc/experimental-effect): Integrate with [Effect](https://effect.website/).
|
|
51
53
|
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Implement your contract with [NestJS](https://nestjs.com/).
|
|
52
54
|
- [@orpc/bun](https://www.npmjs.com/package/@orpc/bun): Adapters for [Bun's Redis](https://bun.sh/).
|
|
53
55
|
- [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare): Adapters for [Cloudflare's RateLimit and Durable Objects](https://developers.cloudflare.com/workers/).
|
|
56
|
+
- [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc): Reuse existing [tRPC](https://trpc.io/) routers within oRPC.
|
|
54
57
|
|
|
55
58
|
**Observability**
|
|
56
59
|
|
|
@@ -102,11 +105,10 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
102
105
|
<td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td>
|
|
103
106
|
<td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td>
|
|
104
107
|
<td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td>
|
|
105
|
-
<td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td>
|
|
106
108
|
<td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td>
|
|
109
|
+
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
107
110
|
</tr>
|
|
108
111
|
<tr>
|
|
109
|
-
<td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td>
|
|
110
112
|
<td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
|
|
111
113
|
<td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="139" alt="shota"/><br />shota</a></td>
|
|
112
114
|
</tr>
|
|
@@ -166,6 +168,7 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
|
|
|
166
168
|
<a href="https://github.com/nelsonlaidev?ref=orpc" target="_blank" rel="noopener" title="Nelson Lai"><img src="https://avatars.githubusercontent.com/u/75498339?u=2fc0e0b95dd184c5ffb744df977cb15a18b60672&v=4" width="32" height="32" alt="Nelson Lai" /></a>
|
|
167
169
|
<a href="https://github.com/nguyenlc1993?ref=orpc" target="_blank" rel="noopener" title="Lê Cao Nguyên"><img src="https://avatars.githubusercontent.com/u/13871971?u=83c8b69d9e35b589c4e1f066cc113b1d9461386f&v=4" width="32" height="32" alt="Lê Cao Nguyên" /></a>
|
|
168
170
|
<a href="https://github.com/wobsoriano?ref=orpc" target="_blank" rel="noopener" title="Robert Soriano"><img src="https://avatars.githubusercontent.com/u/13049130?u=6d72104182e7c9ed25934815313fb69107332111&v=4" width="32" height="32" alt="Robert Soriano" /></a>
|
|
171
|
+
<a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="32" height="32" alt="Andrew Peters" /></a>
|
|
169
172
|
<a href="https://github.com/SKostyukovich?ref=orpc" target="_blank" rel="noopener" title="SKostyukovich"><img src="https://avatars.githubusercontent.com/u/10700067?v=4" width="32" height="32" alt="SKostyukovich" /></a>
|
|
170
173
|
<a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="32" height="32" alt="Peter Adam" /></a>
|
|
171
174
|
<a href="https://github.com/FabworksHQ?ref=orpc" target="_blank" rel="noopener" title="Fabworks"><img src="https://avatars.githubusercontent.com/u/160179500?v=4" width="32" height="32" alt="Fabworks" /></a>
|
package/dist/index.d.mts
CHANGED
|
@@ -26,16 +26,16 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
26
26
|
*/
|
|
27
27
|
serializer?: undefined | Pick<RPCSerializer, keyof RPCSerializer>;
|
|
28
28
|
/**
|
|
29
|
-
* Configuration for event
|
|
29
|
+
* Configuration for event resume support.
|
|
30
30
|
*
|
|
31
31
|
* When enabled, published events are temporarily stored so new
|
|
32
32
|
* subscribers can resume from a previous position using `lastEventId`.
|
|
33
33
|
*
|
|
34
34
|
* @default { enabled: false }
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
resume?: {
|
|
37
37
|
/**
|
|
38
|
-
* Whether event
|
|
38
|
+
* Whether event resume support is enabled.
|
|
39
39
|
*
|
|
40
40
|
* When enabled, published events are temporarily stored so new
|
|
41
41
|
* subscribers can resume from a previous position using `lastEventId`.
|
|
@@ -44,7 +44,7 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
44
44
|
*/
|
|
45
45
|
enabled: boolean;
|
|
46
46
|
/**
|
|
47
|
-
* How long (in seconds) to retain events for
|
|
47
|
+
* How long (in seconds) to retain events for resume.
|
|
48
48
|
*
|
|
49
49
|
* Expired events are cleaned up lazily for performance reasons, so
|
|
50
50
|
* some events may remain available slightly longer than this period.
|
|
@@ -59,8 +59,8 @@ declare class BunRedisPublisher<T extends Record<string, object>> extends Publis
|
|
|
59
59
|
private subscriber;
|
|
60
60
|
private readonly prefix;
|
|
61
61
|
private readonly serializer;
|
|
62
|
-
private readonly
|
|
63
|
-
private readonly
|
|
62
|
+
private readonly resumeEnabled;
|
|
63
|
+
private readonly resumeSeconds;
|
|
64
64
|
/**
|
|
65
65
|
* The exactness of the `XTRIM` command.
|
|
66
66
|
* Used for testing purpose.
|
package/dist/index.d.ts
CHANGED
|
@@ -26,16 +26,16 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
26
26
|
*/
|
|
27
27
|
serializer?: undefined | Pick<RPCSerializer, keyof RPCSerializer>;
|
|
28
28
|
/**
|
|
29
|
-
* Configuration for event
|
|
29
|
+
* Configuration for event resume support.
|
|
30
30
|
*
|
|
31
31
|
* When enabled, published events are temporarily stored so new
|
|
32
32
|
* subscribers can resume from a previous position using `lastEventId`.
|
|
33
33
|
*
|
|
34
34
|
* @default { enabled: false }
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
resume?: {
|
|
37
37
|
/**
|
|
38
|
-
* Whether event
|
|
38
|
+
* Whether event resume support is enabled.
|
|
39
39
|
*
|
|
40
40
|
* When enabled, published events are temporarily stored so new
|
|
41
41
|
* subscribers can resume from a previous position using `lastEventId`.
|
|
@@ -44,7 +44,7 @@ interface BunRedisPublisherOptions extends PublisherOptions {
|
|
|
44
44
|
*/
|
|
45
45
|
enabled: boolean;
|
|
46
46
|
/**
|
|
47
|
-
* How long (in seconds) to retain events for
|
|
47
|
+
* How long (in seconds) to retain events for resume.
|
|
48
48
|
*
|
|
49
49
|
* Expired events are cleaned up lazily for performance reasons, so
|
|
50
50
|
* some events may remain available slightly longer than this period.
|
|
@@ -59,8 +59,8 @@ declare class BunRedisPublisher<T extends Record<string, object>> extends Publis
|
|
|
59
59
|
private subscriber;
|
|
60
60
|
private readonly prefix;
|
|
61
61
|
private readonly serializer;
|
|
62
|
-
private readonly
|
|
63
|
-
private readonly
|
|
62
|
+
private readonly resumeEnabled;
|
|
63
|
+
private readonly resumeSeconds;
|
|
64
64
|
/**
|
|
65
65
|
* The exactness of the `XTRIM` command.
|
|
66
66
|
* Used for testing purpose.
|
package/dist/index.mjs
CHANGED
|
@@ -9,15 +9,15 @@ class BunRedisPublisher extends Publisher {
|
|
|
9
9
|
this.redis = redis;
|
|
10
10
|
this.prefix = options.prefix ?? "";
|
|
11
11
|
this.serializer = options.serializer ?? new RPCSerializer();
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this.resumeEnabled = options.resume?.enabled ?? false;
|
|
13
|
+
this.resumeSeconds = options.resume?.seconds ?? 300;
|
|
14
14
|
this.subscriber = options.subscriber;
|
|
15
15
|
}
|
|
16
16
|
subscriber;
|
|
17
17
|
prefix;
|
|
18
18
|
serializer;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
resumeEnabled;
|
|
20
|
+
resumeSeconds;
|
|
21
21
|
/**
|
|
22
22
|
* The exactness of the `XTRIM` command.
|
|
23
23
|
* Used for testing purpose.
|
|
@@ -28,10 +28,10 @@ class BunRedisPublisher extends Publisher {
|
|
|
28
28
|
const redisKey = `${this.prefix}${event}`;
|
|
29
29
|
const data = this.serializePayload(payload);
|
|
30
30
|
let id;
|
|
31
|
-
if (this.
|
|
31
|
+
if (this.resumeEnabled) {
|
|
32
32
|
const now = Date.now();
|
|
33
33
|
for (const [event2, firstPublishTime] of this.firstPublishTimeMap) {
|
|
34
|
-
if (firstPublishTime + this.
|
|
34
|
+
if (firstPublishTime + this.resumeSeconds * 1e3 < now) {
|
|
35
35
|
this.firstPublishTimeMap.delete(event2);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -39,10 +39,10 @@ class BunRedisPublisher extends Publisher {
|
|
|
39
39
|
this.firstPublishTimeMap.set(event, now);
|
|
40
40
|
const result = await Promise.all([
|
|
41
41
|
this.redis.send("XADD", [redisKey, "*", "data", stringifyJSON(data)]),
|
|
42
|
-
this.redis.send("XTRIM", [redisKey, "MINID", this.xTrimExactness, `${now - this.
|
|
43
|
-
// Use a 2x TTL so events published near the end of the
|
|
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
44
|
// are not expired before the next window updates the key expiration.
|
|
45
|
-
this.redis.expire(redisKey, this.
|
|
45
|
+
this.redis.expire(redisKey, this.resumeSeconds * 2)
|
|
46
46
|
]);
|
|
47
47
|
id = result[0];
|
|
48
48
|
} else {
|
|
@@ -54,14 +54,14 @@ class BunRedisPublisher extends Publisher {
|
|
|
54
54
|
async subscribeListener(event, originalListener, { lastEventId, onError } = {}) {
|
|
55
55
|
const redisKey = `${this.prefix}${event}`;
|
|
56
56
|
let pendingPayloads = [];
|
|
57
|
-
const
|
|
57
|
+
const resumedIds = /* @__PURE__ */ new Set();
|
|
58
58
|
const deduplicatingListener = (payload) => {
|
|
59
59
|
if (pendingPayloads) {
|
|
60
60
|
pendingPayloads.push(payload);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
const id = getEventMeta(payload)?.id;
|
|
64
|
-
if (id !== void 0 &&
|
|
64
|
+
if (id !== void 0 && resumedIds.has(id)) {
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
originalListener(payload);
|
|
@@ -80,7 +80,7 @@ class BunRedisPublisher extends Publisher {
|
|
|
80
80
|
try {
|
|
81
81
|
const subscribePromise = subscriber.subscribe(redisKey, redisListener);
|
|
82
82
|
try {
|
|
83
|
-
if (this.
|
|
83
|
+
if (this.resumeEnabled && lastEventId !== void 0) {
|
|
84
84
|
const results = await this.redis.send("XREAD", ["STREAMS", redisKey, lastEventId]);
|
|
85
85
|
if (results && results[redisKey]) {
|
|
86
86
|
const messages = results[redisKey];
|
|
@@ -88,7 +88,7 @@ class BunRedisPublisher extends Publisher {
|
|
|
88
88
|
const rawData = message[1];
|
|
89
89
|
const data = parseEmptyableJSON(rawData);
|
|
90
90
|
const payload = this.deserializePayload(id, data);
|
|
91
|
-
|
|
91
|
+
resumedIds.add(id);
|
|
92
92
|
originalListener(payload);
|
|
93
93
|
}
|
|
94
94
|
}
|
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.19",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.dev",
|
|
7
7
|
"repository": {
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@standardserver/core": "^0.5.0",
|
|
26
|
-
"@orpc/
|
|
27
|
-
"@orpc/
|
|
28
|
-
"@orpc/
|
|
29
|
-
"@orpc/
|
|
30
|
-
"@orpc/shared": "2.0.0-beta.
|
|
26
|
+
"@orpc/ratelimit": "2.0.0-beta.19",
|
|
27
|
+
"@orpc/client": "2.0.0-beta.19",
|
|
28
|
+
"@orpc/publisher": "2.0.0-beta.19",
|
|
29
|
+
"@orpc/server": "2.0.0-beta.19",
|
|
30
|
+
"@orpc/shared": "2.0.0-beta.19"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/bun": "^1.3.14",
|