@orpc/experimental-lock 2.0.0-beta.45 → 2.0.0-beta.46
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 +47 -16
- package/dist/adapters/base-redis.d.mts +1 -1
- package/dist/adapters/base-redis.d.ts +1 -1
- package/dist/adapters/base-redis.mjs +3 -3
- package/dist/adapters/redis.d.mts +7 -0
- package/dist/adapters/redis.d.ts +7 -0
- package/dist/adapters/redis.mjs +9 -0
- package/dist/adapters/upstash.d.mts +7 -0
- package/dist/adapters/upstash.d.ts +7 -0
- package/dist/adapters/upstash.mjs +9 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,9 +21,40 @@
|
|
|
21
21
|
</a>
|
|
22
22
|
</div>
|
|
23
23
|
|
|
24
|
+
**oRPC** is a TypeScript framework for building end-to-end typesafe APIs. Write your API once as plain TypeScript functions, and oRPC gives you a fully typed client, a REST API with an OpenAPI document, and MCP tools for AI agents, with no code generation. It runs on Node.js, Bun, Deno, Cloudflare Workers, and more.
|
|
25
|
+
|
|
26
|
+
Define procedures on the server and serve them with an [RPC handler](https://orpc.dev/docs/rpc/handler):
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { os } from '@orpc/server'
|
|
30
|
+
import * as z from 'zod'
|
|
31
|
+
|
|
32
|
+
export const router = {
|
|
33
|
+
planet: {
|
|
34
|
+
find: os
|
|
35
|
+
.input(z.object({ id: z.number() }))
|
|
36
|
+
.handler(({ input }) => ({ id: input.id, name: 'Earth' })),
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then call them from a client that knows every input and output, without generating anything:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type { RouterClient } from '@orpc/server'
|
|
45
|
+
import type { router } from './router'
|
|
46
|
+
import { createORPCClient } from '@orpc/client'
|
|
47
|
+
import { RPCLink } from '@orpc/client/fetch'
|
|
48
|
+
|
|
49
|
+
const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
|
|
50
|
+
const client: RouterClient<typeof router> = createORPCClient(link)
|
|
51
|
+
|
|
52
|
+
const planet = await client.planet.find({ id: 1 }) // { id: number, name: string }
|
|
53
|
+
```
|
|
54
|
+
|
|
24
55
|
## Documentation
|
|
25
56
|
|
|
26
|
-
|
|
57
|
+
Read the full documentation at [orpc.dev](https://orpc.dev), starting with the [Getting Started guide](https://orpc.dev/docs/getting-started).
|
|
27
58
|
|
|
28
59
|
## Packages
|
|
29
60
|
|
|
@@ -56,21 +87,21 @@ You can read the documentation [here](https://orpc.dev).
|
|
|
56
87
|
|
|
57
88
|
**Framework & ecosystem integrations**
|
|
58
89
|
|
|
59
|
-
| Package
|
|
60
|
-
|
|
|
61
|
-
| [@orpc/next](https://www.npmjs.com/package/@orpc/next)
|
|
62
|
-
| [@orpc/ai-sdk](https://www.npmjs.com/package/@orpc/ai-sdk)
|
|
63
|
-
| [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp)
|
|
64
|
-
| [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query)
|
|
65
|
-
| [@orpc/pinia-colada](https://www.npmjs.com/package/@orpc/pinia-colada)
|
|
66
|
-
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr)
|
|
67
|
-
| [@orpc/msw](https://www.npmjs.com/package/@orpc/msw)
|
|
68
|
-
| [@orpc/
|
|
69
|
-
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest)
|
|
70
|
-
| [@orpc/node](https://www.npmjs.com/package/@orpc/node)
|
|
71
|
-
| [@orpc/bun](https://www.npmjs.com/package/@orpc/bun)
|
|
72
|
-
| [@orpc/cloudflare](https://www.npmjs.com/package/@orpc/cloudflare)
|
|
73
|
-
| [@orpc/trpc](https://www.npmjs.com/package/@orpc/trpc)
|
|
90
|
+
| Package | Purpose | Docs |
|
|
91
|
+
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| [@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) |
|
|
93
|
+
| [@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) |
|
|
94
|
+
| [@orpc/mcp](https://www.npmjs.com/package/@orpc/mcp) | Expose procedures as [MCP](https://modelcontextprotocol.io/) tools. | [MCP](https://orpc.dev/docs/integrations/mcp) |
|
|
95
|
+
| [@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) |
|
|
96
|
+
| [@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) |
|
|
97
|
+
| [@orpc/swr](https://www.npmjs.com/package/@orpc/swr) | Integrate with [SWR](https://swr.vercel.app/). | [SWR](https://orpc.dev/docs/integrations/swr) |
|
|
98
|
+
| [@orpc/msw](https://www.npmjs.com/package/@orpc/msw) | Mock procedures with [Mock Service Worker](https://mswjs.io/). | [MSW](https://orpc.dev/docs/integrations/msw) |
|
|
99
|
+
| [@orpc/effect](https://www.npmjs.com/package/@orpc/effect) | Integrate with [Effect](https://effect.website/). | [Effect](https://orpc.dev/docs/integrations/effect) |
|
|
100
|
+
| [@orpc/nest](https://www.npmjs.com/package/@orpc/nest) | Implement your contract with [NestJS](https://nestjs.com/). | [NestJS](https://orpc.dev/docs/integrations/nest) |
|
|
101
|
+
| [@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) |
|
|
102
|
+
| [@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), [Lock](https://orpc.dev/docs/helpers/lock) |
|
|
103
|
+
| [@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), [Lock](https://orpc.dev/docs/helpers/lock), [Traces](https://orpc.dev/docs/integrations/cloudflare-traces) |
|
|
104
|
+
| [@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) |
|
|
74
105
|
|
|
75
106
|
**Observability**
|
|
76
107
|
|
|
@@ -44,7 +44,7 @@ interface BaseRedisLockerOptions {
|
|
|
44
44
|
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
45
45
|
*/
|
|
46
46
|
declare abstract class BaseRedisLocker implements Locker {
|
|
47
|
-
protected readonly
|
|
47
|
+
protected readonly keyPrefix: string;
|
|
48
48
|
protected readonly ttl: number;
|
|
49
49
|
protected readonly timeout: number;
|
|
50
50
|
protected readonly retryInterval: number;
|
|
@@ -44,7 +44,7 @@ interface BaseRedisLockerOptions {
|
|
|
44
44
|
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
45
45
|
*/
|
|
46
46
|
declare abstract class BaseRedisLocker implements Locker {
|
|
47
|
-
protected readonly
|
|
47
|
+
protected readonly keyPrefix: string;
|
|
48
48
|
protected readonly ttl: number;
|
|
49
49
|
protected readonly timeout: number;
|
|
50
50
|
protected readonly retryInterval: number;
|
|
@@ -9,18 +9,18 @@ end
|
|
|
9
9
|
return 0
|
|
10
10
|
`;
|
|
11
11
|
class BaseRedisLocker {
|
|
12
|
-
|
|
12
|
+
keyPrefix;
|
|
13
13
|
ttl;
|
|
14
14
|
timeout;
|
|
15
15
|
retryInterval;
|
|
16
16
|
constructor(options) {
|
|
17
|
-
this.
|
|
17
|
+
this.keyPrefix = options.prefix ?? "";
|
|
18
18
|
this.ttl = options.ttl;
|
|
19
19
|
this.timeout = options.timeout ?? 1e4;
|
|
20
20
|
this.retryInterval = options.retryInterval ?? 100;
|
|
21
21
|
}
|
|
22
22
|
async lock(key, fn, options = {}) {
|
|
23
|
-
const prefixedKey = `${this.
|
|
23
|
+
const prefixedKey = `${this.keyPrefix}${key}`;
|
|
24
24
|
const ttl = options.ttl ?? this.ttl;
|
|
25
25
|
const deadline = Date.now() + (options.timeout ?? this.timeout);
|
|
26
26
|
const token = crypto.randomUUID();
|
|
@@ -12,7 +12,14 @@ import '../shared/experimental-lock.D9u4cJfq.mjs';
|
|
|
12
12
|
*/
|
|
13
13
|
declare class RedisLocker extends BaseRedisLocker {
|
|
14
14
|
private readonly redis;
|
|
15
|
+
private readonly options;
|
|
15
16
|
constructor(redis: RedisClientType<any, any, any, any, any>, options: BaseRedisLockerOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
21
|
+
*/
|
|
22
|
+
prefix(prefix: string): RedisLocker;
|
|
16
23
|
protected acquire(key: string, token: string, ttl: number): Promise<boolean>;
|
|
17
24
|
protected evalScript(script: string, keys: string[], args: string[]): Promise<unknown>;
|
|
18
25
|
private connectIfNeeded;
|
package/dist/adapters/redis.d.ts
CHANGED
|
@@ -12,7 +12,14 @@ import '../shared/experimental-lock.D9u4cJfq.js';
|
|
|
12
12
|
*/
|
|
13
13
|
declare class RedisLocker extends BaseRedisLocker {
|
|
14
14
|
private readonly redis;
|
|
15
|
+
private readonly options;
|
|
15
16
|
constructor(redis: RedisClientType<any, any, any, any, any>, options: BaseRedisLockerOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
21
|
+
*/
|
|
22
|
+
prefix(prefix: string): RedisLocker;
|
|
16
23
|
protected acquire(key: string, token: string, ttl: number): Promise<boolean>;
|
|
17
24
|
protected evalScript(script: string, keys: string[], args: string[]): Promise<unknown>;
|
|
18
25
|
private connectIfNeeded;
|
package/dist/adapters/redis.mjs
CHANGED
|
@@ -6,6 +6,15 @@ class RedisLocker extends BaseRedisLocker {
|
|
|
6
6
|
constructor(redis, options) {
|
|
7
7
|
super(options);
|
|
8
8
|
this.redis = redis;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
15
|
+
*/
|
|
16
|
+
prefix(prefix) {
|
|
17
|
+
return new RedisLocker(this.redis, { ...this.options, prefix: `${this.keyPrefix}${prefix}` });
|
|
9
18
|
}
|
|
10
19
|
async acquire(key, token, ttl) {
|
|
11
20
|
await this.connectIfNeeded();
|
|
@@ -12,7 +12,14 @@ import '../shared/experimental-lock.D9u4cJfq.mjs';
|
|
|
12
12
|
*/
|
|
13
13
|
declare class UpstashLocker extends BaseRedisLocker {
|
|
14
14
|
private readonly redis;
|
|
15
|
+
private readonly options;
|
|
15
16
|
constructor(redis: Redis, options: BaseRedisLockerOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
21
|
+
*/
|
|
22
|
+
prefix(prefix: string): UpstashLocker;
|
|
16
23
|
protected acquire(key: string, token: string, ttl: number): Promise<boolean>;
|
|
17
24
|
protected evalScript(script: string, keys: string[], args: string[]): Promise<unknown>;
|
|
18
25
|
}
|
|
@@ -12,7 +12,14 @@ import '../shared/experimental-lock.D9u4cJfq.js';
|
|
|
12
12
|
*/
|
|
13
13
|
declare class UpstashLocker extends BaseRedisLocker {
|
|
14
14
|
private readonly redis;
|
|
15
|
+
private readonly options;
|
|
15
16
|
constructor(redis: Redis, options: BaseRedisLockerOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
21
|
+
*/
|
|
22
|
+
prefix(prefix: string): UpstashLocker;
|
|
16
23
|
protected acquire(key: string, token: string, ttl: number): Promise<boolean>;
|
|
17
24
|
protected evalScript(script: string, keys: string[], args: string[]): Promise<unknown>;
|
|
18
25
|
}
|
|
@@ -6,6 +6,15 @@ class UpstashLocker extends BaseRedisLocker {
|
|
|
6
6
|
constructor(redis, options) {
|
|
7
7
|
super(options);
|
|
8
8
|
this.redis = redis;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a locker with `prefix` appended to this locker's prefix, sharing its Redis client.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link https://orpc.dev/docs/helpers/lock#adapters | Lock Helpers - Adapters}
|
|
15
|
+
*/
|
|
16
|
+
prefix(prefix) {
|
|
17
|
+
return new UpstashLocker(this.redis, { ...this.options, prefix: `${this.keyPrefix}${prefix}` });
|
|
9
18
|
}
|
|
10
19
|
async acquire(key, token, ttl) {
|
|
11
20
|
const result = await this.redis.set(key, token, { nx: true, px: ttl });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/experimental-lock",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.46",
|
|
5
5
|
"description": "Locking for oRPC procedures, with memory, Redis, and Upstash adapters",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": [
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@orpc/server": "2.0.0-beta.
|
|
74
|
-
"@orpc/shared": "2.0.0-beta.
|
|
73
|
+
"@orpc/server": "2.0.0-beta.46",
|
|
74
|
+
"@orpc/shared": "2.0.0-beta.46"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@upstash/redis": "^1.39.0",
|