@orpc/experimental-lock 2.0.0-beta.46 → 2.0.0-beta.48

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 DELETED
@@ -1,81 +0,0 @@
1
- import { Context, MiddlewareOptions, Middleware } from '@orpc/server';
2
- import { Value, Promisable } from '@orpc/shared';
3
- import { L as Locker } from './shared/experimental-lock.D9u4cJfq.js';
4
- export { a as LockCallbackOptions, b as LockOptions } from './shared/experimental-lock.D9u4cJfq.js';
5
-
6
- /**
7
- * Thrown when a lock cannot be acquired before the timeout elapses.
8
- *
9
- * @see {@link https://orpc.dev/docs/helpers/lock#options | Lock Helpers - Options}
10
- */
11
- declare class LockTimeoutError extends Error {
12
- /**
13
- * The key of the lock that could not be acquired.
14
- */
15
- readonly key: string;
16
- constructor(key: string);
17
- }
18
-
19
- declare const LOCK_MIDDLEWARE_CONTEXT_SYMBOL: unique symbol;
20
- interface LockMiddlewareContext {
21
- [LOCK_MIDDLEWARE_CONTEXT_SYMBOL]?: {
22
- /**
23
- * The locks held in this request, mainly for deduplication purposes
24
- */
25
- held: {
26
- locker: Locker;
27
- key: string;
28
- waited: boolean;
29
- }[];
30
- };
31
- }
32
- interface LockMiddlewareOutContext {
33
- /**
34
- * Whether the lock was acquired only after waiting for another holder to release it.
35
- * `false` means the lock was acquired immediately.
36
- */
37
- ['lock/waited']: boolean;
38
- }
39
- interface LockMiddlewareOptions<TInContext extends Context, TInput> {
40
- /**
41
- * The locker to acquire the lock from
42
- */
43
- locker: Value<Promisable<Locker>, [options: MiddlewareOptions<TInContext, unknown, Record<never, never>>, input: TInput]>;
44
- /**
45
- * The key to identify the work that must not run concurrently
46
- */
47
- key: Value<Promisable<string>, [options: MiddlewareOptions<TInContext, unknown, Record<never, never>>, input: TInput]>;
48
- /**
49
- * How long the lock is held before it expires automatically, in milliseconds.
50
- *
51
- * @default the adapter default
52
- */
53
- ttl?: Value<Promisable<number | undefined>, [options: MiddlewareOptions<TInContext, unknown, Record<never, never>>, input: TInput]> | undefined;
54
- /**
55
- * How long to wait for the lock to become available, in milliseconds.
56
- *
57
- * @default the adapter default
58
- */
59
- timeout?: Value<Promisable<number | undefined>, [options: MiddlewareOptions<TInContext, unknown, Record<never, never>>, input: TInput]> | undefined;
60
- /**
61
- * If your lock middleware is used multiple times
62
- * or you invoke a procedure inside another procedure (shared the same context) that also has
63
- * lock middleware **with the same locker and key**, this option
64
- * will ensure that the lock is only acquired once per request,
65
- * instead of waiting for itself until the timeout elapses.
66
- *
67
- * @default true
68
- */
69
- dedupe?: boolean | undefined;
70
- }
71
- /**
72
- * Creates a middleware that runs oRPC procedures under a lock, so that calls
73
- * sharing the same key never run concurrently. Rejects with a `CONFLICT` error
74
- * when the lock cannot be acquired before the timeout elapses.
75
- *
76
- * @see {@link https://orpc.dev/docs/helpers/lock#lock-middleware | Lock Helpers - Lock Middleware}
77
- */
78
- declare function lock<TInContext extends Context, TInput>({ dedupe, ...options }: LockMiddlewareOptions<TInContext, TInput>): Middleware<TInContext, LockMiddlewareOutContext, TInput, any, object>;
79
-
80
- export { LOCK_MIDDLEWARE_CONTEXT_SYMBOL, LockTimeoutError, Locker, lock };
81
- export type { LockMiddlewareContext, LockMiddlewareOptions, LockMiddlewareOutContext };
@@ -1,13 +0,0 @@
1
- class LockTimeoutError extends Error {
2
- /**
3
- * The key of the lock that could not be acquired.
4
- */
5
- key;
6
- constructor(key) {
7
- super(`Timed out waiting for the lock of key "${key}"`);
8
- this.name = "LockTimeoutError";
9
- this.key = key;
10
- }
11
- }
12
-
13
- export { LockTimeoutError as L };
@@ -1,46 +0,0 @@
1
- import { Promisable } from '@orpc/shared';
2
-
3
- interface LockOptions {
4
- /**
5
- * How long the lock is held before it expires automatically, in milliseconds.
6
- * Guards against holders that never release the lock, such as a crashed process.
7
- *
8
- * @default the adapter default
9
- */
10
- ttl?: number | undefined;
11
- /**
12
- * How long to wait for the lock to become available, in milliseconds.
13
- *
14
- * @default the adapter default
15
- */
16
- timeout?: number | undefined;
17
- /**
18
- * Aborts waiting for the lock. Has no effect once the lock is acquired.
19
- */
20
- signal?: AbortSignal | undefined;
21
- }
22
- interface LockCallbackOptions {
23
- /**
24
- * Whether the lock was acquired only after waiting for another holder to release it.
25
- * `false` means the lock was acquired immediately.
26
- */
27
- waited: boolean;
28
- }
29
- /**
30
- * Standard interface for running work under a lock, so that work sharing
31
- * the same key never runs concurrently.
32
- * Implement it for custom strategies, or use one of the provided adapters.
33
- *
34
- * @see {@link https://orpc.dev/docs/helpers/lock | Lock Helpers}
35
- */
36
- interface Locker {
37
- /**
38
- * Runs `fn` while holding the lock for `key`, and releases the lock afterwards,
39
- * even when `fn` throws.
40
- *
41
- * @throws {LockTimeoutError} when the lock cannot be acquired before the timeout elapses
42
- */
43
- lock<T>(key: string, fn: (options: LockCallbackOptions) => Promisable<T>, options?: LockOptions): Promise<T>;
44
- }
45
-
46
- export type { Locker as L, LockCallbackOptions as a, LockOptions as b };
@@ -1,46 +0,0 @@
1
- import { Promisable } from '@orpc/shared';
2
-
3
- interface LockOptions {
4
- /**
5
- * How long the lock is held before it expires automatically, in milliseconds.
6
- * Guards against holders that never release the lock, such as a crashed process.
7
- *
8
- * @default the adapter default
9
- */
10
- ttl?: number | undefined;
11
- /**
12
- * How long to wait for the lock to become available, in milliseconds.
13
- *
14
- * @default the adapter default
15
- */
16
- timeout?: number | undefined;
17
- /**
18
- * Aborts waiting for the lock. Has no effect once the lock is acquired.
19
- */
20
- signal?: AbortSignal | undefined;
21
- }
22
- interface LockCallbackOptions {
23
- /**
24
- * Whether the lock was acquired only after waiting for another holder to release it.
25
- * `false` means the lock was acquired immediately.
26
- */
27
- waited: boolean;
28
- }
29
- /**
30
- * Standard interface for running work under a lock, so that work sharing
31
- * the same key never runs concurrently.
32
- * Implement it for custom strategies, or use one of the provided adapters.
33
- *
34
- * @see {@link https://orpc.dev/docs/helpers/lock | Lock Helpers}
35
- */
36
- interface Locker {
37
- /**
38
- * Runs `fn` while holding the lock for `key`, and releases the lock afterwards,
39
- * even when `fn` throws.
40
- *
41
- * @throws {LockTimeoutError} when the lock cannot be acquired before the timeout elapses
42
- */
43
- lock<T>(key: string, fn: (options: LockCallbackOptions) => Promisable<T>, options?: LockOptions): Promise<T>;
44
- }
45
-
46
- export type { Locker as L, LockCallbackOptions as a, LockOptions as b };