@convex-dev/workpool 0.1.3-alpha.0 → 0.2.0-beta.0
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 +144 -4
- package/dist/commonjs/client/index.d.ts +123 -35
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +122 -15
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/client/utils.d.ts +16 -0
- package/dist/commonjs/client/utils.d.ts.map +1 -0
- package/dist/commonjs/client/utils.js +2 -0
- package/dist/commonjs/client/utils.js.map +1 -0
- package/dist/commonjs/component/convex.config.d.ts.map +1 -1
- package/dist/commonjs/component/convex.config.js +0 -2
- package/dist/commonjs/component/convex.config.js.map +1 -1
- package/dist/commonjs/component/kick.d.ts +9 -0
- package/dist/commonjs/component/kick.d.ts.map +1 -0
- package/dist/commonjs/component/kick.js +97 -0
- package/dist/commonjs/component/kick.js.map +1 -0
- package/dist/commonjs/component/lib.d.ts +23 -32
- package/dist/commonjs/component/lib.d.ts.map +1 -1
- package/dist/commonjs/component/lib.js +70 -564
- package/dist/commonjs/component/lib.js.map +1 -1
- package/dist/commonjs/component/logging.d.ts +6 -4
- package/dist/commonjs/component/logging.d.ts.map +1 -1
- package/dist/commonjs/component/logging.js +13 -2
- package/dist/commonjs/component/logging.js.map +1 -1
- package/dist/commonjs/component/loop.d.ts +26 -0
- package/dist/commonjs/component/loop.d.ts.map +1 -0
- package/dist/commonjs/component/loop.js +453 -0
- package/dist/commonjs/component/loop.js.map +1 -0
- package/dist/commonjs/component/recovery.d.ts +8 -0
- package/dist/commonjs/component/recovery.d.ts.map +1 -0
- package/dist/commonjs/component/recovery.js +74 -0
- package/dist/commonjs/component/recovery.js.map +1 -0
- package/dist/commonjs/component/schema.d.ts +163 -93
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +54 -65
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/commonjs/component/shared.d.ts +130 -0
- package/dist/commonjs/component/shared.d.ts.map +1 -0
- package/dist/commonjs/component/shared.js +65 -0
- package/dist/commonjs/component/shared.js.map +1 -0
- package/dist/commonjs/component/stats.d.ts +3 -2
- package/dist/commonjs/component/stats.d.ts.map +1 -1
- package/dist/commonjs/component/stats.js +17 -3
- package/dist/commonjs/component/stats.js.map +1 -1
- package/dist/commonjs/component/worker.d.ts +25 -0
- package/dist/commonjs/component/worker.d.ts.map +1 -0
- package/dist/commonjs/component/worker.js +86 -0
- package/dist/commonjs/component/worker.js.map +1 -0
- package/dist/esm/client/index.d.ts +123 -35
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +122 -15
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/utils.d.ts +16 -0
- package/dist/esm/client/utils.d.ts.map +1 -0
- package/dist/esm/client/utils.js +2 -0
- package/dist/esm/client/utils.js.map +1 -0
- package/dist/esm/component/convex.config.d.ts.map +1 -1
- package/dist/esm/component/convex.config.js +0 -2
- package/dist/esm/component/convex.config.js.map +1 -1
- package/dist/esm/component/kick.d.ts +9 -0
- package/dist/esm/component/kick.d.ts.map +1 -0
- package/dist/esm/component/kick.js +97 -0
- package/dist/esm/component/kick.js.map +1 -0
- package/dist/esm/component/lib.d.ts +23 -32
- package/dist/esm/component/lib.d.ts.map +1 -1
- package/dist/esm/component/lib.js +70 -564
- package/dist/esm/component/lib.js.map +1 -1
- package/dist/esm/component/logging.d.ts +6 -4
- package/dist/esm/component/logging.d.ts.map +1 -1
- package/dist/esm/component/logging.js +13 -2
- package/dist/esm/component/logging.js.map +1 -1
- package/dist/esm/component/loop.d.ts +26 -0
- package/dist/esm/component/loop.d.ts.map +1 -0
- package/dist/esm/component/loop.js +453 -0
- package/dist/esm/component/loop.js.map +1 -0
- package/dist/esm/component/recovery.d.ts +8 -0
- package/dist/esm/component/recovery.d.ts.map +1 -0
- package/dist/esm/component/recovery.js +74 -0
- package/dist/esm/component/recovery.js.map +1 -0
- package/dist/esm/component/schema.d.ts +163 -93
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +54 -65
- package/dist/esm/component/schema.js.map +1 -1
- package/dist/esm/component/shared.d.ts +130 -0
- package/dist/esm/component/shared.d.ts.map +1 -0
- package/dist/esm/component/shared.js +65 -0
- package/dist/esm/component/shared.js.map +1 -0
- package/dist/esm/component/stats.d.ts +3 -2
- package/dist/esm/component/stats.d.ts.map +1 -1
- package/dist/esm/component/stats.js +17 -3
- package/dist/esm/component/stats.js.map +1 -1
- package/dist/esm/component/worker.d.ts +25 -0
- package/dist/esm/component/worker.d.ts.map +1 -0
- package/dist/esm/component/worker.js +86 -0
- package/dist/esm/component/worker.js.map +1 -0
- package/package.json +6 -5
- package/src/client/index.ts +231 -70
- package/src/client/utils.ts +45 -0
- package/src/component/README.md +73 -0
- package/src/component/_generated/api.d.ts +36 -66
- package/src/component/convex.config.ts +0 -3
- package/src/component/kick.test.ts +286 -0
- package/src/component/kick.ts +118 -0
- package/src/component/lib.test.ts +203 -0
- package/src/component/lib.ts +80 -671
- package/src/component/logging.ts +24 -10
- package/src/component/loop.ts +579 -0
- package/src/component/recovery.ts +79 -0
- package/src/component/schema.ts +59 -77
- package/src/component/setup.test.ts +5 -0
- package/src/component/shared.ts +127 -0
- package/src/component/stats.ts +20 -6
- package/src/component/worker.ts +94 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Infer } from "convex/values";
|
|
2
|
+
import { Logger } from "./logging.js";
|
|
3
|
+
export declare const SECOND = 1000;
|
|
4
|
+
export declare const MINUTE: number;
|
|
5
|
+
export declare const HOUR: number;
|
|
6
|
+
export declare const DAY: number;
|
|
7
|
+
export declare const YEAR: number;
|
|
8
|
+
export declare function toSegment(ms: number): bigint;
|
|
9
|
+
export declare function currentSegment(): bigint;
|
|
10
|
+
export declare function nextSegment(): bigint;
|
|
11
|
+
export declare function fromSegment(segment: bigint): number;
|
|
12
|
+
export declare const config: import("convex/values").VObject<{
|
|
13
|
+
maxParallelism: number;
|
|
14
|
+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
15
|
+
}, {
|
|
16
|
+
maxParallelism: import("convex/values").VFloat64<number, "required">;
|
|
17
|
+
logLevel: import("convex/values").VUnion<"DEBUG" | "INFO" | "WARN" | "ERROR", [import("convex/values").VLiteral<"DEBUG", "required">, import("convex/values").VLiteral<"INFO", "required">, import("convex/values").VLiteral<"WARN", "required">, import("convex/values").VLiteral<"ERROR", "required">], "required", never>;
|
|
18
|
+
}, "required", "maxParallelism" | "logLevel">;
|
|
19
|
+
export type Config = Infer<typeof config>;
|
|
20
|
+
export declare const retryBehavior: import("convex/values").VObject<{
|
|
21
|
+
maxAttempts: number;
|
|
22
|
+
initialBackoffMs: number;
|
|
23
|
+
base: number;
|
|
24
|
+
}, {
|
|
25
|
+
maxAttempts: import("convex/values").VFloat64<number, "required">;
|
|
26
|
+
initialBackoffMs: import("convex/values").VFloat64<number, "required">;
|
|
27
|
+
base: import("convex/values").VFloat64<number, "required">;
|
|
28
|
+
}, "required", "maxAttempts" | "initialBackoffMs" | "base">;
|
|
29
|
+
export type RetryBehavior = {
|
|
30
|
+
/**
|
|
31
|
+
* The maximum number of attempts to make. 2 means one retry.
|
|
32
|
+
*/
|
|
33
|
+
maxAttempts: number;
|
|
34
|
+
/**
|
|
35
|
+
* The initial backoff time in milliseconds. 100 means wait 100ms before the
|
|
36
|
+
* first retry.
|
|
37
|
+
*/
|
|
38
|
+
initialBackoffMs: number;
|
|
39
|
+
/**
|
|
40
|
+
* The base for the backoff. 2 means double the backoff each time.
|
|
41
|
+
* e.g. if the initial backoff is 100ms, and the base is 2, then the first
|
|
42
|
+
* retry will wait 200ms, the second will wait 400ms, etc.
|
|
43
|
+
*/
|
|
44
|
+
base: number;
|
|
45
|
+
};
|
|
46
|
+
export declare const runResult: import("convex/values").VUnion<{
|
|
47
|
+
kind: "success";
|
|
48
|
+
returnValue: any;
|
|
49
|
+
} | {
|
|
50
|
+
kind: "failed";
|
|
51
|
+
error: string;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "canceled";
|
|
54
|
+
}, [import("convex/values").VObject<{
|
|
55
|
+
kind: "success";
|
|
56
|
+
returnValue: any;
|
|
57
|
+
}, {
|
|
58
|
+
kind: import("convex/values").VLiteral<"success", "required">;
|
|
59
|
+
returnValue: import("convex/values").VAny<any, "required", string>;
|
|
60
|
+
}, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
|
|
61
|
+
kind: "failed";
|
|
62
|
+
error: string;
|
|
63
|
+
}, {
|
|
64
|
+
kind: import("convex/values").VLiteral<"failed", "required">;
|
|
65
|
+
error: import("convex/values").VString<string, "required">;
|
|
66
|
+
}, "required", "kind" | "error">, import("convex/values").VObject<{
|
|
67
|
+
kind: "canceled";
|
|
68
|
+
}, {
|
|
69
|
+
kind: import("convex/values").VLiteral<"canceled", "required">;
|
|
70
|
+
}, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
|
|
71
|
+
export type RunResult = Infer<typeof runResult>;
|
|
72
|
+
export declare const onComplete: import("convex/values").VObject<{
|
|
73
|
+
context?: any;
|
|
74
|
+
fnHandle: string;
|
|
75
|
+
}, {
|
|
76
|
+
fnHandle: import("convex/values").VString<string, "required">;
|
|
77
|
+
context: import("convex/values").VAny<any, "optional", string>;
|
|
78
|
+
}, "required", "fnHandle" | "context" | `context.${string}`>;
|
|
79
|
+
export type OnComplete = Infer<typeof onComplete>;
|
|
80
|
+
export type OnCompleteArgs = {
|
|
81
|
+
/**
|
|
82
|
+
* The ID of the work that completed.
|
|
83
|
+
*/
|
|
84
|
+
workId: string;
|
|
85
|
+
/**
|
|
86
|
+
* The context object passed when enqueuing the work.
|
|
87
|
+
* Useful for passing data from the enqueue site to the onComplete site.
|
|
88
|
+
*/
|
|
89
|
+
context: unknown;
|
|
90
|
+
/**
|
|
91
|
+
* The result of the run that completed.
|
|
92
|
+
*/
|
|
93
|
+
result: RunResult;
|
|
94
|
+
};
|
|
95
|
+
export declare const status: import("convex/values").VUnion<{
|
|
96
|
+
state: "pending";
|
|
97
|
+
attempt: number;
|
|
98
|
+
} | {
|
|
99
|
+
state: "running";
|
|
100
|
+
attempt: number;
|
|
101
|
+
} | {
|
|
102
|
+
state: "finished";
|
|
103
|
+
}, [import("convex/values").VUnion<{
|
|
104
|
+
state: "pending";
|
|
105
|
+
attempt: number;
|
|
106
|
+
} | {
|
|
107
|
+
state: "running";
|
|
108
|
+
attempt: number;
|
|
109
|
+
} | {
|
|
110
|
+
state: "finished";
|
|
111
|
+
}, [import("convex/values").VObject<{
|
|
112
|
+
state: "pending";
|
|
113
|
+
attempt: number;
|
|
114
|
+
}, {
|
|
115
|
+
state: import("convex/values").VLiteral<"pending", "required">;
|
|
116
|
+
attempt: import("convex/values").VFloat64<number, "required">;
|
|
117
|
+
}, "required", "state" | "attempt">, import("convex/values").VObject<{
|
|
118
|
+
state: "running";
|
|
119
|
+
attempt: number;
|
|
120
|
+
}, {
|
|
121
|
+
state: import("convex/values").VLiteral<"running", "required">;
|
|
122
|
+
attempt: import("convex/values").VFloat64<number, "required">;
|
|
123
|
+
}, "required", "state" | "attempt">, import("convex/values").VObject<{
|
|
124
|
+
state: "finished";
|
|
125
|
+
}, {
|
|
126
|
+
state: import("convex/values").VLiteral<"finished", "required">;
|
|
127
|
+
}, "required", "state">], "required", "state" | "attempt">], "required", "state" | "attempt">;
|
|
128
|
+
export type Status = Infer<typeof status>;
|
|
129
|
+
export declare function boundScheduledTime(ms: number, console: Logger): number;
|
|
130
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC,OAAO,EAAE,MAAM,EAAY,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,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MAAM,CAAC,CAAC;AAE1C,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAatE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { logLevel } from "./logging.js";
|
|
3
|
+
const SEGMENT_MS = 250;
|
|
4
|
+
export const SECOND = 1000;
|
|
5
|
+
export const MINUTE = 60 * SECOND;
|
|
6
|
+
export const HOUR = 60 * MINUTE;
|
|
7
|
+
export const DAY = 24 * HOUR;
|
|
8
|
+
export const YEAR = 365 * DAY;
|
|
9
|
+
export function toSegment(ms) {
|
|
10
|
+
return BigInt(Math.floor(ms / SEGMENT_MS));
|
|
11
|
+
}
|
|
12
|
+
export function currentSegment() {
|
|
13
|
+
return toSegment(Date.now());
|
|
14
|
+
}
|
|
15
|
+
export function nextSegment() {
|
|
16
|
+
return toSegment(Date.now()) + 1n;
|
|
17
|
+
}
|
|
18
|
+
export function fromSegment(segment) {
|
|
19
|
+
return Number(segment) * SEGMENT_MS;
|
|
20
|
+
}
|
|
21
|
+
export const config = v.object({
|
|
22
|
+
maxParallelism: v.number(),
|
|
23
|
+
logLevel,
|
|
24
|
+
});
|
|
25
|
+
export const retryBehavior = v.object({
|
|
26
|
+
maxAttempts: v.number(),
|
|
27
|
+
initialBackoffMs: v.number(),
|
|
28
|
+
base: v.number(),
|
|
29
|
+
});
|
|
30
|
+
// This ensures that the type satisfies the schema.
|
|
31
|
+
const _ = {};
|
|
32
|
+
export const runResult = v.union(v.object({
|
|
33
|
+
kind: v.literal("success"),
|
|
34
|
+
returnValue: v.any(),
|
|
35
|
+
}), v.object({
|
|
36
|
+
kind: v.literal("failed"),
|
|
37
|
+
error: v.string(),
|
|
38
|
+
}), v.object({
|
|
39
|
+
kind: v.literal("canceled"),
|
|
40
|
+
}));
|
|
41
|
+
export const onComplete = v.object({
|
|
42
|
+
fnHandle: v.string(),
|
|
43
|
+
context: v.optional(v.any()),
|
|
44
|
+
});
|
|
45
|
+
export const status = v.union(v.union(v.object({
|
|
46
|
+
state: v.literal("pending"),
|
|
47
|
+
attempt: v.number(),
|
|
48
|
+
}), v.object({
|
|
49
|
+
state: v.literal("running"),
|
|
50
|
+
attempt: v.number(),
|
|
51
|
+
}), v.object({
|
|
52
|
+
state: v.literal("finished"),
|
|
53
|
+
})));
|
|
54
|
+
export function boundScheduledTime(ms, console) {
|
|
55
|
+
if (ms < Date.now() - YEAR) {
|
|
56
|
+
console.warn("runAt is too far in the past, defaulting to now", ms);
|
|
57
|
+
return Date.now();
|
|
58
|
+
}
|
|
59
|
+
if (ms > Date.now() + 4 * YEAR) {
|
|
60
|
+
console.warn("runAt is too far in the future, defaulting to 1 year from now", ms);
|
|
61
|
+
return Date.now() + YEAR;
|
|
62
|
+
}
|
|
63
|
+
return ms;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/component/shared.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAU,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAClC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAC;AAChC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7B,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAE9B,MAAM,UAAU,SAAS,CAAC,EAAU;IAClC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC;AAC7C,C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C,MAAM,EAAE;IACpB,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;CAC7B,CAAC,CAAC;AAmBH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAC3B,CAAC,CAAC,KAAK,CACL,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,EACF,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;CACpB,CAAC,EACF,CAAC,CAAC,MAAM,CAAC;IACP,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;CAC7B,CAAC,CACH,CACF,CAAC;AAGF,MAAM,UAAU,kBAAkB,CAAC,EAAU,EAAE,OAAe;IAC5D,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,EAAE,CAAC,CAAC;QACpE,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;KACnB;IACD,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE;QAC9B,OAAO,CAAC,IAAI,CACV,+DAA+D,EAC/D,EAAE,CACH,CAAC;QACF,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;KAC1B;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -17,7 +17,8 @@ workpool
|
|
|
17
17
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function recordStarted(work: Doc<"work">): string;
|
|
20
|
-
export declare function recordCompleted(work: Doc<"work">, status: "success" | "
|
|
20
|
+
export declare function recordCompleted(work: Doc<"work">, status: "success" | "failed" | "canceled"): string;
|
|
21
|
+
export declare function recordReport(state: Doc<"internalState">): string;
|
|
21
22
|
/**
|
|
22
23
|
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
23
24
|
* Use this to debug or diagnose your queue length when it's backed up.
|
|
@@ -29,7 +30,7 @@ export declare const queueLength: import("convex/server").RegisteredQuery<"inter
|
|
|
29
30
|
*/
|
|
30
31
|
export declare const debugCounts: import("convex/server").RegisteredQuery<"internal", {}, Promise<{
|
|
31
32
|
pendingStart: any;
|
|
32
|
-
inProgressWork:
|
|
33
|
+
inProgressWork: number;
|
|
33
34
|
pendingCompletion: any;
|
|
34
35
|
pendingCancelation: any;
|
|
35
36
|
active: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CASvD;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EACjB,MAAM,EAAE,SAAS,GAAG,
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CASvD;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EACjB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,GACxC,MAAM,CASR;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,eAAe,CAAC,GAAG,MAAM,CAahE;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,uEAOtB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;GAuBtB,CAAC"}
|
|
@@ -37,6 +37,20 @@ export function recordCompleted(work, status) {
|
|
|
37
37
|
lagSinceEnqueued: Date.now() - work._creationTime,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
+
export function recordReport(state) {
|
|
41
|
+
const { completed, succeeded, failed, retries, canceled } = state.report;
|
|
42
|
+
const withoutRetries = completed - retries;
|
|
43
|
+
return JSON.stringify({
|
|
44
|
+
event: "report",
|
|
45
|
+
completed,
|
|
46
|
+
succeeded,
|
|
47
|
+
failed,
|
|
48
|
+
retries,
|
|
49
|
+
canceled,
|
|
50
|
+
failureRate: completed ? (failed + retries) / completed : 0,
|
|
51
|
+
permanentFailureRate: withoutRetries ? failed / withoutRetries : 0,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
40
54
|
/**
|
|
41
55
|
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
42
56
|
* Use this to debug or diagnose your queue length when it's backed up.
|
|
@@ -57,19 +71,19 @@ export const debugCounts = internalQuery({
|
|
|
57
71
|
args: {},
|
|
58
72
|
returns: v.any(),
|
|
59
73
|
handler: async (ctx) => {
|
|
74
|
+
const inProgressWork = (await ctx.db.query("internalState").unique())?.running.length ?? 0;
|
|
60
75
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
61
|
-
const inProgressWork = await ctx.db.query("inProgressWork").count();
|
|
62
76
|
const pendingStart = await ctx.db.query("pendingStart").count();
|
|
63
77
|
const pendingCompletion = await ctx.db.query("pendingCompletion").count();
|
|
64
78
|
const pendingCancelation = await ctx.db.query("pendingCancelation").count();
|
|
79
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
65
80
|
return {
|
|
66
81
|
pendingStart,
|
|
67
82
|
inProgressWork,
|
|
68
83
|
pendingCompletion,
|
|
69
84
|
pendingCancelation,
|
|
70
|
-
active: inProgressWork - pendingCompletion
|
|
85
|
+
active: inProgressWork - pendingCompletion,
|
|
71
86
|
};
|
|
72
|
-
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
73
87
|
},
|
|
74
88
|
});
|
|
75
89
|
//# sourceMappingURL=stats.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC7C,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAI,CAAC,aAAa;QAC9B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa;KAClD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,IAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AAEH,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC7C,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,MAAM,EAAE,IAAI,CAAC,GAAG;QAChB,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,UAAU,EAAE,IAAI,C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AC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAS,CAAC,KAAK,EAAE,CAAC;IACvD,CAAC;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;IACvC,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE;IAChB,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrB,MAAM,cAAc,GAClB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACtE,uDAAuD;QACvD,MAAM,YAAY,GAAG,MAAO,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAS,CAAC,KAAK,EAAE,CAAC;QACzE,MAAM,iBAAiB,GAAG,MACxB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,mBAAmB,CACjC,CAAC,KAAK,EAAE,CAAC;QACV,MAAM,kBAAkB,GAAG,MACzB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAClC,CAAC,KAAK,EAAE,CAAC;QACV,sDAAsD;QACtD,OAAO;YACL,YAAY;YACZ,cAAc;YACd,iBAAiB;YACjB,kBAAkB;YAClB,MAAM,EAAE,cAAc,GAAG,iBAAiB;SAC3C,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const runMutationWrapper: import("convex/server").RegisteredMutation<"internal", {
|
|
2
|
+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
3
|
+
fnHandle: string;
|
|
4
|
+
workId: import("convex/values").GenericId<"work">;
|
|
5
|
+
fnArgs: any;
|
|
6
|
+
}, Promise<void>>;
|
|
7
|
+
export declare const runActionWrapper: import("convex/server").RegisteredAction<"internal", {
|
|
8
|
+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
9
|
+
fnHandle: string;
|
|
10
|
+
workId: import("convex/values").GenericId<"work">;
|
|
11
|
+
fnArgs: any;
|
|
12
|
+
}, Promise<void>>;
|
|
13
|
+
export declare const saveResult: import("convex/server").RegisteredMutation<"internal", {
|
|
14
|
+
workId: import("convex/values").GenericId<"work">;
|
|
15
|
+
runResult: {
|
|
16
|
+
kind: "success";
|
|
17
|
+
returnValue: any;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "failed";
|
|
20
|
+
error: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "canceled";
|
|
23
|
+
};
|
|
24
|
+
}, Promise<void>>;
|
|
25
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/component/worker.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,kBAAkB;;;;;iBA0B7B,CAAC;AASH,eAAO,MAAM,gBAAgB;;;;;iBA2B3B,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;iBAarB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { internal } from "./_generated/api.js";
|
|
3
|
+
import { internalAction, internalMutation } from "./_generated/server.js";
|
|
4
|
+
import { kickMainLoop } from "./kick.js";
|
|
5
|
+
import { createLogger, logLevel } from "./logging.js";
|
|
6
|
+
import { nextSegment, runResult } from "./shared.js";
|
|
7
|
+
export const runMutationWrapper = internalMutation({
|
|
8
|
+
args: {
|
|
9
|
+
workId: v.id("work"),
|
|
10
|
+
fnHandle: v.string(),
|
|
11
|
+
fnArgs: v.any(),
|
|
12
|
+
logLevel,
|
|
13
|
+
},
|
|
14
|
+
handler: async (ctx, { workId, fnHandle: handleStr, fnArgs, logLevel }) => {
|
|
15
|
+
const console = createLogger(logLevel);
|
|
16
|
+
const fnHandle = handleStr;
|
|
17
|
+
try {
|
|
18
|
+
const returnValue = await ctx.runMutation(fnHandle, fnArgs);
|
|
19
|
+
// NOTE: we could run the `saveResult` handler here, or call `ctx.runMutation`,
|
|
20
|
+
// but we want the mutation to be a separate transaction to reduce the window for OCCs.
|
|
21
|
+
await ctx.scheduler.runAfter(0, internal.worker.saveResult, {
|
|
22
|
+
workId,
|
|
23
|
+
runResult: { kind: "success", returnValue },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(e);
|
|
28
|
+
await ctx.scheduler.runAfter(0, internal.worker.saveResult, {
|
|
29
|
+
workId,
|
|
30
|
+
runResult: { kind: "failed", error: formatError(e) },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
function formatError(e) {
|
|
36
|
+
if (e instanceof Error) {
|
|
37
|
+
return e.message;
|
|
38
|
+
}
|
|
39
|
+
return String(e);
|
|
40
|
+
}
|
|
41
|
+
export const runActionWrapper = internalAction({
|
|
42
|
+
args: {
|
|
43
|
+
workId: v.id("work"),
|
|
44
|
+
fnHandle: v.string(),
|
|
45
|
+
fnArgs: v.any(),
|
|
46
|
+
logLevel,
|
|
47
|
+
},
|
|
48
|
+
handler: async (ctx, { workId, fnHandle: handleStr, fnArgs, logLevel }) => {
|
|
49
|
+
const console = createLogger(logLevel);
|
|
50
|
+
const fnHandle = handleStr;
|
|
51
|
+
try {
|
|
52
|
+
const returnValue = await ctx.runAction(fnHandle, fnArgs);
|
|
53
|
+
// NOTE: we could run `ctx.runMutation`, but we want to guarantee execution,
|
|
54
|
+
// and `ctx.scheduler.runAfter` won't OCC.
|
|
55
|
+
await ctx.scheduler.runAfter(0, internal.worker.saveResult, {
|
|
56
|
+
workId,
|
|
57
|
+
runResult: { kind: "success", returnValue },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.error(e);
|
|
62
|
+
// We let the main loop handle the retries.
|
|
63
|
+
await ctx.scheduler.runAfter(0, internal.worker.saveResult, {
|
|
64
|
+
workId,
|
|
65
|
+
runResult: { kind: "failed", error: formatError(e) },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
export const saveResult = internalMutation({
|
|
71
|
+
args: {
|
|
72
|
+
workId: v.id("work"),
|
|
73
|
+
runResult,
|
|
74
|
+
},
|
|
75
|
+
handler: async (ctx, { workId, runResult }) => {
|
|
76
|
+
await ctx.db.insert("pendingCompletion", {
|
|
77
|
+
runResult,
|
|
78
|
+
workId,
|
|
79
|
+
segment: nextSegment(),
|
|
80
|
+
});
|
|
81
|
+
await kickMainLoop(ctx, "saveResult");
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
+
const console = "THIS IS A REMINDER TO USE createLogger";
|
|
86
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/component/worker.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;IACjD,IAAI,EAAE;QACJ,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC;QACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;QACpB,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE;QACf,QAAQ;K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AO,EAAE,WAAW,EAAE;SACvB,CAAC,CAAC;QACH,MAAM,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IACxC,CAAC;CACF,CAAC,CAAC;AAEH,6DAA6D;AAC7D,MAAM,OAAO,GAAG,wCAAwC,CAAC"}
|
|
@@ -1,53 +1,141 @@
|
|
|
1
|
-
import { DefaultFunctionArgs,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export type
|
|
1
|
+
import { DefaultFunctionArgs, FunctionReference, FunctionVisibility } from "convex/server";
|
|
2
|
+
import { VString } from "convex/values";
|
|
3
|
+
import { Mounts } from "../component/_generated/api.js";
|
|
4
|
+
import { runResult as runResultValidator, RunResult, type RetryBehavior, Status } from "../component/shared.js";
|
|
5
|
+
import { type LogLevel } from "../component/logging.js";
|
|
6
|
+
import { RunMutationCtx, RunQueryCtx, UseApi } from "./utils.js";
|
|
7
|
+
export { runResultValidator, type RunResult };
|
|
8
|
+
export declare const DEFAULT_RETRY_BEHAVIOR: RetryBehavior;
|
|
9
|
+
export type WorkId = string & {
|
|
10
|
+
__isWorkId: true;
|
|
11
|
+
};
|
|
12
|
+
export declare const workIdValidator: VString<WorkId, "required">;
|
|
8
13
|
export declare class Workpool {
|
|
9
14
|
private component;
|
|
10
15
|
private options;
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Initializes a Workpool.
|
|
18
|
+
*
|
|
19
|
+
* Note: if you want different pools, you need to *create different instances*
|
|
20
|
+
* of Workpool in convex.config.ts. It isn't sufficient to have different
|
|
21
|
+
* instances of this class.
|
|
22
|
+
*
|
|
23
|
+
* @param component - The component to use, like `components.workpool` from
|
|
24
|
+
* `./_generated/api.ts`.
|
|
25
|
+
* @param options - The options for the Workpool.
|
|
26
|
+
*/
|
|
27
|
+
constructor(component: UseApi<Mounts>, // UseApi<api> for jump to definition
|
|
28
|
+
options: {
|
|
12
29
|
/** How many actions/mutations can be running at once within this pool.
|
|
13
30
|
* Min 1, Max 300.
|
|
14
31
|
*/
|
|
15
|
-
maxParallelism
|
|
16
|
-
/** How much to log.
|
|
17
|
-
*
|
|
32
|
+
maxParallelism?: number;
|
|
33
|
+
/** How much to log. This is updated on each call to `enqueue*`,
|
|
34
|
+
* `status`, or `cancel*`.
|
|
35
|
+
* Default is WARN.
|
|
18
36
|
* With INFO, you can see events for started and completed work, which can
|
|
19
|
-
* be parsed.
|
|
37
|
+
* be parsed by tools like [Axiom](https://axiom.co) for monitoring.
|
|
20
38
|
* With DEBUG, you can see timers and internal events for work being
|
|
21
39
|
* scheduled.
|
|
22
40
|
*/
|
|
23
41
|
logLevel?: LogLevel;
|
|
24
|
-
/**
|
|
25
|
-
|
|
42
|
+
/** Default retry behavior for enqueued actions. */
|
|
43
|
+
defaultRetryBehavior?: RetryBehavior;
|
|
44
|
+
/** Whether to retry actions that fail by default. Default: false.
|
|
45
|
+
* NOTE: Only do this if your actions are idempotent.
|
|
46
|
+
* See the docs (README.md) for more details.
|
|
26
47
|
*/
|
|
27
|
-
|
|
48
|
+
retryActionsByDefault?: boolean;
|
|
28
49
|
});
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Enqueues an action to be run.
|
|
52
|
+
*
|
|
53
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
54
|
+
* @param fn - The action to run, like `internal.example.myAction`.
|
|
55
|
+
* @param fnArgs - The arguments to pass to the action.
|
|
56
|
+
* @param options - The options for the action to specify retry behavior,
|
|
57
|
+
* onComplete handling, and scheduling via `runAt` or `runAfter`.
|
|
58
|
+
* @returns The ID of the work that was enqueued.
|
|
59
|
+
*/
|
|
60
|
+
enqueueAction<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: {
|
|
61
|
+
/** Whether to retry the action if it fails.
|
|
62
|
+
* If true, it will use the default retry behavior.
|
|
63
|
+
* If custom behavior is provided, it will retry using that behavior.
|
|
64
|
+
* If unset, it will use the Workpool's configured default.
|
|
65
|
+
*/
|
|
66
|
+
retry?: boolean | RetryBehavior;
|
|
67
|
+
} & CallbackOptions & SchedulerOptions): Promise<WorkId>;
|
|
68
|
+
/**
|
|
69
|
+
* Enqueues a mutation to be run.
|
|
70
|
+
*
|
|
71
|
+
* Note: mutations are not retried by the workpool. Convex automatically
|
|
72
|
+
* retries them on database conflicts and transient failures.
|
|
73
|
+
* Because they're deterministic, external retries don't provide any benefit.
|
|
74
|
+
*
|
|
75
|
+
* @param ctx - The mutation or action context that can call ctx.runMutation.
|
|
76
|
+
* @param fn - The mutation to run, like `internal.example.myMutation`.
|
|
77
|
+
* @param fnArgs - The arguments to pass to the mutation.
|
|
78
|
+
* @param options - The options for the mutation to specify onComplete handling
|
|
79
|
+
* and scheduling via `runAt` or `runAfter`.
|
|
80
|
+
*/
|
|
81
|
+
enqueueMutation<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: CallbackOptions & SchedulerOptions): Promise<WorkId>;
|
|
31
82
|
cancel(ctx: RunMutationCtx, id: WorkId): Promise<void>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} | {
|
|
35
|
-
kind: "inProgress";
|
|
36
|
-
} | {
|
|
37
|
-
kind: "completed";
|
|
38
|
-
completionStatus: CompletionStatus;
|
|
39
|
-
}>;
|
|
83
|
+
cancelAll(ctx: RunMutationCtx): Promise<void>;
|
|
84
|
+
status(ctx: RunQueryCtx, id: WorkId): Promise<Status>;
|
|
40
85
|
}
|
|
41
|
-
type
|
|
42
|
-
|
|
86
|
+
export type SchedulerOptions = {
|
|
87
|
+
/**
|
|
88
|
+
* The time (ms since epoch) to run the action at.
|
|
89
|
+
* If not provided, the action will be run as soon as possible.
|
|
90
|
+
* Note: this is advisory only. It may run later.
|
|
91
|
+
*/
|
|
92
|
+
runAt?: number;
|
|
93
|
+
} | {
|
|
94
|
+
/**
|
|
95
|
+
* The number of milliseconds to run the action after.
|
|
96
|
+
* If not provided, the action will be run as soon as possible.
|
|
97
|
+
* Note: this is advisory only. It may run later.
|
|
98
|
+
*/
|
|
99
|
+
runAfter?: number;
|
|
100
|
+
};
|
|
101
|
+
export type CallbackOptions = {
|
|
102
|
+
/**
|
|
103
|
+
* A mutation to run after the function succeeds, fails, or is canceled.
|
|
104
|
+
* The context type is for your use, feel free to provide a validator for it.
|
|
105
|
+
* e.g.
|
|
106
|
+
* ```ts
|
|
107
|
+
* export const completion = internalMutation({
|
|
108
|
+
* args: {
|
|
109
|
+
* workId: workIdValidator,
|
|
110
|
+
* context: v.any(),
|
|
111
|
+
* result: runResult,
|
|
112
|
+
* },
|
|
113
|
+
* handler: async (ctx, args) => {
|
|
114
|
+
* console.log(args.result, "Got Context back -> ", args.context, Date.now() - args.context);
|
|
115
|
+
* },
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
onComplete?: FunctionReference<"mutation", FunctionVisibility, OnCompleteArgs> | null;
|
|
120
|
+
/**
|
|
121
|
+
* A context object to pass to the `onComplete` mutation.
|
|
122
|
+
* Useful for passing data from the enqueue site to the onComplete site.
|
|
123
|
+
*/
|
|
124
|
+
context?: unknown;
|
|
43
125
|
};
|
|
44
|
-
type
|
|
45
|
-
|
|
126
|
+
export type OnCompleteArgs = {
|
|
127
|
+
/**
|
|
128
|
+
* The ID of the work that completed.
|
|
129
|
+
*/
|
|
130
|
+
workId: WorkId;
|
|
131
|
+
/**
|
|
132
|
+
* The context object passed when enqueuing the work.
|
|
133
|
+
* Useful for passing data from the enqueue site to the onComplete site.
|
|
134
|
+
*/
|
|
135
|
+
context: unknown;
|
|
136
|
+
/**
|
|
137
|
+
* The result of the run that completed.
|
|
138
|
+
*/
|
|
139
|
+
result: RunResult;
|
|
46
140
|
};
|
|
47
|
-
export type OpaqueIds<T> = T extends GenericId<infer _T> ? string : T extends (infer U)[] ? OpaqueIds<U>[] : T extends object ? {
|
|
48
|
-
[K in keyof T]: OpaqueIds<T[K]>;
|
|
49
|
-
} : T;
|
|
50
|
-
export type UseApi<API> = Expand<{
|
|
51
|
-
[mod in keyof API]: API[mod] extends FunctionReference<infer FType, "public", infer FArgs, infer FReturnType, infer FComponentPath> ? FunctionReference<FType, "internal", OpaqueIds<FArgs>, OpaqueIds<FReturnType>, FComponentPath> : UseApi<API[mod]>;
|
|
52
|
-
}>;
|
|
53
141
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAEL,SAAS,IAAI,kBAAkB,EAC/B,SAAS,EACT,KAAK,aAAa,EAElB,MAAM,EAEP,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGjE,OAAO,EAAE,kBAAkB,EAAE,KAAK,SAAS,EAAE,CAAC;AAG9C,eAAO,MAAM,sBAAsB,EAAE,aAIpC,CAAC;AACF,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG;IAAE,UAAU,EAAE,IAAI,CAAA;CAAE,CAAC;AACnD,eAAO,MAAM,eAAe,6BAAgC,CAAC;AAE7D,qBAAa,QAAQ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