@convex-dev/workpool 0.2.19-alpha.2 → 0.2.19-alpha.3

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.
Files changed (194) hide show
  1. package/README.md +1 -0
  2. package/dist/{commonjs/client → client}/index.d.ts +13 -11
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/{commonjs/client → client}/index.js +6 -7
  5. package/dist/client/index.js.map +1 -0
  6. package/dist/{commonjs/client → client}/utils.d.ts +2 -2
  7. package/dist/client/utils.d.ts.map +1 -0
  8. package/dist/client/utils.js.map +1 -0
  9. package/dist/component/_generated/api.d.ts +151 -0
  10. package/dist/component/_generated/api.d.ts.map +1 -0
  11. package/dist/component/_generated/api.js.map +1 -0
  12. package/dist/component/_generated/dataModel.d.ts +60 -0
  13. package/dist/component/_generated/server.d.ts +149 -0
  14. package/dist/component/_generated/server.d.ts.map +1 -0
  15. package/dist/component/_generated/server.js.map +1 -0
  16. package/dist/{commonjs/component → component}/complete.d.ts +2 -2
  17. package/dist/component/complete.d.ts.map +1 -0
  18. package/dist/{commonjs/component → component}/complete.js +1 -1
  19. package/dist/component/complete.js.map +1 -0
  20. package/dist/component/convex.config.d.ts.map +1 -0
  21. package/dist/component/convex.config.js.map +1 -0
  22. package/dist/component/crons.d.ts.map +1 -0
  23. package/dist/{esm/component → component}/crons.js +4 -4
  24. package/dist/component/crons.js.map +1 -0
  25. package/dist/component/danger.d.ts.map +1 -0
  26. package/dist/component/danger.js.map +1 -0
  27. package/dist/{esm/component → component}/kick.d.ts +2 -2
  28. package/dist/component/kick.d.ts.map +1 -0
  29. package/dist/component/kick.js.map +1 -0
  30. package/dist/{esm/component → component}/lib.d.ts +1 -1
  31. package/dist/component/lib.d.ts.map +1 -0
  32. package/dist/{commonjs/component → component}/lib.js +3 -4
  33. package/dist/component/lib.js.map +1 -0
  34. package/dist/component/logging.d.ts.map +1 -0
  35. package/dist/component/logging.js.map +1 -0
  36. package/dist/{commonjs/component → component}/loop.d.ts +2 -2
  37. package/dist/component/loop.d.ts.map +1 -0
  38. package/dist/{commonjs/component → component}/loop.js +1 -1
  39. package/dist/component/loop.js.map +1 -0
  40. package/dist/{esm/component → component}/recovery.d.ts +2 -2
  41. package/dist/component/recovery.d.ts.map +1 -0
  42. package/dist/{commonjs/component → component}/recovery.js +1 -1
  43. package/dist/component/recovery.js.map +1 -0
  44. package/dist/{commonjs/component → component}/schema.d.ts.map +1 -1
  45. package/dist/component/schema.js.map +1 -0
  46. package/dist/component/shared.d.ts.map +1 -0
  47. package/dist/component/shared.js.map +1 -0
  48. package/dist/{esm/component → component}/stats.d.ts +4 -4
  49. package/dist/component/stats.d.ts.map +1 -0
  50. package/dist/{commonjs/component → component}/stats.js +0 -3
  51. package/dist/component/stats.js.map +1 -0
  52. package/dist/component/worker.d.ts.map +1 -0
  53. package/dist/component/worker.js.map +1 -0
  54. package/package.json +42 -39
  55. package/src/client/index.ts +32 -29
  56. package/src/client/utils.ts +7 -7
  57. package/src/component/_generated/api.d.ts +1 -0
  58. package/src/component/complete.test.ts +6 -6
  59. package/src/component/complete.ts +9 -5
  60. package/src/component/crons.ts +4 -4
  61. package/src/component/kick.test.ts +3 -3
  62. package/src/component/kick.ts +2 -2
  63. package/src/component/lib.test.ts +6 -6
  64. package/src/component/lib.ts +15 -5
  65. package/src/component/logging.test.ts +1 -1
  66. package/src/component/loop.test.ts +7 -7
  67. package/src/component/loop.ts +8 -8
  68. package/src/component/recovery.test.ts +9 -9
  69. package/src/component/recovery.ts +2 -2
  70. package/src/component/stats.test.ts +11 -11
  71. package/src/component/stats.ts +4 -7
  72. package/src/test.ts +3 -0
  73. package/dist/commonjs/client/index.d.ts.map +0 -1
  74. package/dist/commonjs/client/index.js.map +0 -1
  75. package/dist/commonjs/client/utils.d.ts.map +0 -1
  76. package/dist/commonjs/client/utils.js.map +0 -1
  77. package/dist/commonjs/component/_generated/api.d.ts +0 -12
  78. package/dist/commonjs/component/_generated/api.d.ts.map +0 -1
  79. package/dist/commonjs/component/_generated/api.js.map +0 -1
  80. package/dist/commonjs/component/_generated/server.d.ts +0 -64
  81. package/dist/commonjs/component/_generated/server.d.ts.map +0 -1
  82. package/dist/commonjs/component/_generated/server.js.map +0 -1
  83. package/dist/commonjs/component/complete.d.ts.map +0 -1
  84. package/dist/commonjs/component/complete.js.map +0 -1
  85. package/dist/commonjs/component/convex.config.d.ts.map +0 -1
  86. package/dist/commonjs/component/convex.config.js.map +0 -1
  87. package/dist/commonjs/component/crons.d.ts.map +0 -1
  88. package/dist/commonjs/component/crons.js +0 -61
  89. package/dist/commonjs/component/crons.js.map +0 -1
  90. package/dist/commonjs/component/danger.d.ts.map +0 -1
  91. package/dist/commonjs/component/danger.js.map +0 -1
  92. package/dist/commonjs/component/kick.d.ts +0 -9
  93. package/dist/commonjs/component/kick.d.ts.map +0 -1
  94. package/dist/commonjs/component/kick.js.map +0 -1
  95. package/dist/commonjs/component/lib.d.ts +0 -79
  96. package/dist/commonjs/component/lib.d.ts.map +0 -1
  97. package/dist/commonjs/component/lib.js.map +0 -1
  98. package/dist/commonjs/component/logging.d.ts.map +0 -1
  99. package/dist/commonjs/component/logging.js.map +0 -1
  100. package/dist/commonjs/component/loop.d.ts.map +0 -1
  101. package/dist/commonjs/component/loop.js.map +0 -1
  102. package/dist/commonjs/component/recovery.d.ts +0 -53
  103. package/dist/commonjs/component/recovery.d.ts.map +0 -1
  104. package/dist/commonjs/component/recovery.js.map +0 -1
  105. package/dist/commonjs/component/schema.js.map +0 -1
  106. package/dist/commonjs/component/shared.d.ts.map +0 -1
  107. package/dist/commonjs/component/shared.js.map +0 -1
  108. package/dist/commonjs/component/stats.d.ts +0 -45
  109. package/dist/commonjs/component/stats.d.ts.map +0 -1
  110. package/dist/commonjs/component/stats.js.map +0 -1
  111. package/dist/commonjs/component/worker.d.ts.map +0 -1
  112. package/dist/commonjs/component/worker.js.map +0 -1
  113. package/dist/commonjs/package.json +0 -3
  114. package/dist/esm/client/index.d.ts +0 -429
  115. package/dist/esm/client/index.d.ts.map +0 -1
  116. package/dist/esm/client/index.js +0 -317
  117. package/dist/esm/client/index.js.map +0 -1
  118. package/dist/esm/client/utils.d.ts +0 -16
  119. package/dist/esm/client/utils.d.ts.map +0 -1
  120. package/dist/esm/client/utils.js +0 -9
  121. package/dist/esm/client/utils.js.map +0 -1
  122. package/dist/esm/component/_generated/api.d.ts +0 -12
  123. package/dist/esm/component/_generated/api.d.ts.map +0 -1
  124. package/dist/esm/component/_generated/api.js +0 -22
  125. package/dist/esm/component/_generated/api.js.map +0 -1
  126. package/dist/esm/component/_generated/server.d.ts +0 -64
  127. package/dist/esm/component/_generated/server.d.ts.map +0 -1
  128. package/dist/esm/component/_generated/server.js +0 -74
  129. package/dist/esm/component/_generated/server.js.map +0 -1
  130. package/dist/esm/component/complete.d.ts +0 -89
  131. package/dist/esm/component/complete.d.ts.map +0 -1
  132. package/dist/esm/component/complete.js +0 -88
  133. package/dist/esm/component/complete.js.map +0 -1
  134. package/dist/esm/component/convex.config.d.ts +0 -3
  135. package/dist/esm/component/convex.config.d.ts.map +0 -1
  136. package/dist/esm/component/convex.config.js +0 -4
  137. package/dist/esm/component/convex.config.js.map +0 -1
  138. package/dist/esm/component/crons.d.ts +0 -4
  139. package/dist/esm/component/crons.d.ts.map +0 -1
  140. package/dist/esm/component/crons.js.map +0 -1
  141. package/dist/esm/component/danger.d.ts +0 -11
  142. package/dist/esm/component/danger.d.ts.map +0 -1
  143. package/dist/esm/component/danger.js +0 -92
  144. package/dist/esm/component/danger.js.map +0 -1
  145. package/dist/esm/component/kick.d.ts.map +0 -1
  146. package/dist/esm/component/kick.js +0 -102
  147. package/dist/esm/component/kick.js.map +0 -1
  148. package/dist/esm/component/lib.d.ts.map +0 -1
  149. package/dist/esm/component/lib.js +0 -179
  150. package/dist/esm/component/lib.js.map +0 -1
  151. package/dist/esm/component/logging.d.ts +0 -16
  152. package/dist/esm/component/logging.d.ts.map +0 -1
  153. package/dist/esm/component/logging.js +0 -71
  154. package/dist/esm/component/logging.js.map +0 -1
  155. package/dist/esm/component/loop.d.ts +0 -14
  156. package/dist/esm/component/loop.d.ts.map +0 -1
  157. package/dist/esm/component/loop.js +0 -503
  158. package/dist/esm/component/loop.js.map +0 -1
  159. package/dist/esm/component/recovery.d.ts.map +0 -1
  160. package/dist/esm/component/recovery.js +0 -97
  161. package/dist/esm/component/recovery.js.map +0 -1
  162. package/dist/esm/component/schema.d.ts +0 -228
  163. package/dist/esm/component/schema.d.ts.map +0 -1
  164. package/dist/esm/component/schema.js +0 -79
  165. package/dist/esm/component/schema.js.map +0 -1
  166. package/dist/esm/component/shared.d.ts +0 -140
  167. package/dist/esm/component/shared.d.ts.map +0 -1
  168. package/dist/esm/component/shared.js +0 -79
  169. package/dist/esm/component/shared.js.map +0 -1
  170. package/dist/esm/component/stats.d.ts.map +0 -1
  171. package/dist/esm/component/stats.js +0 -129
  172. package/dist/esm/component/stats.js.map +0 -1
  173. package/dist/esm/component/worker.d.ts +0 -16
  174. package/dist/esm/component/worker.d.ts.map +0 -1
  175. package/dist/esm/component/worker.js +0 -76
  176. package/dist/esm/component/worker.js.map +0 -1
  177. package/dist/esm/package.json +0 -3
  178. /package/dist/{commonjs/client → client}/utils.js +0 -0
  179. /package/dist/{commonjs/component → component}/_generated/api.js +0 -0
  180. /package/dist/{commonjs/component → component}/_generated/server.js +0 -0
  181. /package/dist/{commonjs/component → component}/convex.config.d.ts +0 -0
  182. /package/dist/{commonjs/component → component}/convex.config.js +0 -0
  183. /package/dist/{commonjs/component → component}/crons.d.ts +0 -0
  184. /package/dist/{commonjs/component → component}/danger.d.ts +0 -0
  185. /package/dist/{commonjs/component → component}/danger.js +0 -0
  186. /package/dist/{commonjs/component → component}/kick.js +0 -0
  187. /package/dist/{commonjs/component → component}/logging.d.ts +0 -0
  188. /package/dist/{commonjs/component → component}/logging.js +0 -0
  189. /package/dist/{commonjs/component → component}/schema.d.ts +0 -0
  190. /package/dist/{commonjs/component → component}/schema.js +0 -0
  191. /package/dist/{commonjs/component → component}/shared.d.ts +0 -0
  192. /package/dist/{commonjs/component → component}/shared.js +0 -0
  193. /package/dist/{commonjs/component → component}/worker.d.ts +0 -0
  194. /package/dist/{commonjs/component → component}/worker.js +0 -0
@@ -1,429 +0,0 @@
1
- import { DefaultFunctionArgs, FunctionReference, FunctionType, FunctionVisibility, GenericDataModel, GenericMutationCtx, RegisteredMutation } from "convex/server";
2
- import { Infer, Validator, VAny, VString } from "convex/values";
3
- import { Mounts } from "../component/_generated/api.js";
4
- import { type LogLevel } from "../component/logging.js";
5
- import { vResultValidator, type RetryBehavior, RunResult, Status } from "../component/shared.js";
6
- import { RunMutationCtx, RunQueryCtx, UseApi } from "./utils.js";
7
- export { vResultValidator, type RunResult, type RetryBehavior };
8
- export { retryBehavior as vRetryBehavior } from "../component/shared.js";
9
- export { logLevel as vLogLevel, type LogLevel } from "../component/logging.js";
10
- export type WorkId = string & {
11
- __isWorkId: true;
12
- };
13
- export declare const vWorkIdValidator: VString<WorkId>;
14
- export {
15
- /** @deprecated Use `vWorkIdValidator` instead. */
16
- vWorkIdValidator as workIdValidator,
17
- /** @deprecated Use `vResultValidator` instead. */
18
- vResultValidator as resultValidator, };
19
- /** Equivalent to `vOnCompleteArgs(<your-context-validator>)`. */
20
- export declare const vOnComplete: import("convex/values").VObject<{
21
- context: any;
22
- workId: WorkId;
23
- result: {
24
- kind: "success";
25
- returnValue: any;
26
- } | {
27
- kind: "failed";
28
- error: string;
29
- } | {
30
- kind: "canceled";
31
- };
32
- }, {
33
- workId: VString<WorkId, "required">;
34
- context: VAny<any, "required", string>;
35
- result: import("convex/values").VUnion<{
36
- kind: "success";
37
- returnValue: any;
38
- } | {
39
- kind: "failed";
40
- error: string;
41
- } | {
42
- kind: "canceled";
43
- }, [import("convex/values").VObject<{
44
- kind: "success";
45
- returnValue: any;
46
- }, {
47
- kind: import("convex/values").VLiteral<"success", "required">;
48
- returnValue: VAny<any, "required", string>;
49
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
50
- kind: "failed";
51
- error: string;
52
- }, {
53
- kind: import("convex/values").VLiteral<"failed", "required">;
54
- error: VString<string, "required">;
55
- }, "required", "kind" | "error">, import("convex/values").VObject<{
56
- kind: "canceled";
57
- }, {
58
- kind: import("convex/values").VLiteral<"canceled", "required">;
59
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
60
- }, "required", "context" | `context.${string}` | "workId" | "result" | "result.kind" | "result.returnValue" | `result.returnValue.${string}` | "result.error">;
61
- /** @deprecated Use `vOnCompleteArgs()` instead. */
62
- export declare const vOnCompleteValidator: typeof vOnCompleteArgs;
63
- export declare const DEFAULT_RETRY_BEHAVIOR: RetryBehavior;
64
- export type WorkpoolComponent = UseApi<Mounts>;
65
- export declare class Workpool {
66
- component: WorkpoolComponent;
67
- options: WorkpoolOptions;
68
- /**
69
- * Initializes a Workpool.
70
- *
71
- * Note: if you want different pools, you need to *create different instances*
72
- * of Workpool in convex.config.ts. It isn't sufficient to have different
73
- * instances of this class.
74
- *
75
- * @param component - The component to use, like `components.workpool` from
76
- * `./_generated/api.ts`.
77
- * @param options - The {@link WorkpoolOptions} for the Workpool.
78
- */
79
- constructor(component: WorkpoolComponent, options: WorkpoolOptions);
80
- /**
81
- * Enqueues an action to be run.
82
- *
83
- * @param ctx - The mutation or action context that can call ctx.runMutation.
84
- * @param fn - The action to run, like `internal.example.myAction`.
85
- * @param fnArgs - The arguments to pass to the action.
86
- * @param options - The options for the action to specify retry behavior,
87
- * onComplete handling, and scheduling via `runAt` or `runAfter`.
88
- * @returns The ID of the work that was enqueued.
89
- */
90
- enqueueAction<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: RetryOption & EnqueueOptions): Promise<WorkId>;
91
- /**
92
- * Enqueues a batch of actions to be run.
93
- * Each action will be run independently, and the onComplete handler will
94
- * be called for each action.
95
- *
96
- * @param ctx - The mutation or action ctx that can call ctx.runMutation.
97
- * @param fn - The action to run, like `internal.example.myAction`.
98
- * @param argsArray - The arguments to pass to the action.
99
- * @param options - The options for the actions to specify retry behavior,
100
- * onComplete handling, and scheduling via `runAt` or `runAfter`.
101
- * @returns The IDs of the work that was enqueued.
102
- */
103
- enqueueActionBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: RetryOption & EnqueueOptions): Promise<WorkId[]>;
104
- /**
105
- * Enqueues a mutation to be run.
106
- *
107
- * Note: mutations are not retried by the workpool. Convex automatically
108
- * retries them on database conflicts and transient failures.
109
- * Because they're deterministic, external retries don't provide any benefit.
110
- *
111
- * @param ctx - The mutation or action context that can call ctx.runMutation.
112
- * @param fn - The mutation to run, like `internal.example.myMutation`.
113
- * @param fnArgs - The arguments to pass to the mutation.
114
- * @param options - The options for the mutation to specify onComplete handling
115
- * and scheduling via `runAt` or `runAfter`.
116
- */
117
- enqueueMutation<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: EnqueueOptions): Promise<WorkId>;
118
- /**
119
- * Enqueues a batch of mutations to be run.
120
- * Each mutation will be run independently, and the onComplete handler will
121
- * be called for each mutation.
122
- *
123
- * @param ctx - The mutation or action context that can call ctx.runMutation.
124
- * @param fn - The mutation to run, like `internal.example.myMutation`.
125
- * @param argsArray - The arguments to pass to the mutations.
126
- * @param options - The options for the mutations to specify onComplete handling
127
- * and scheduling via `runAt` or `runAfter`.
128
- */
129
- enqueueMutationBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: EnqueueOptions): Promise<WorkId[]>;
130
- /**
131
- * Enqueues a query to be run.
132
- * Usually not what you want, but it can be useful during workflows.
133
- * The query is run in a mutation and the result is returned to the caller,
134
- * so it can conflict if other mutations are writing the value.
135
- *
136
- * @param ctx - The mutation or action context that can call ctx.runMutation.
137
- * @param fn - The query to run, like `internal.example.myQuery`.
138
- * @param fnArgs - The arguments to pass to the query.
139
- * @param options - The options for the query to specify onComplete handling
140
- * and scheduling via `runAt` or `runAfter`.
141
- */
142
- enqueueQuery<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>, fnArgs: Args, options?: EnqueueOptions): Promise<WorkId>;
143
- /**
144
- * Enqueues a batch of queries to be run.
145
- * Each query will be run independently, and the onComplete handler will
146
- * be called for each query.
147
- *
148
- * @param ctx - The mutation or action context that can call ctx.runMutation.
149
- * @param fn - The query to run, like `internal.example.myQuery`.
150
- * @param argsArray - The arguments to pass to the queries.
151
- * @param options - The options for the queries to specify onComplete handling
152
- * and scheduling via `runAt` or `runAfter`.
153
- */
154
- enqueueQueryBatch<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>, argsArray: Array<Args>, options?: EnqueueOptions): Promise<WorkId[]>;
155
- /**
156
- * Cancels a work item. If it's already started, it will be allowed to finish
157
- * but will not be retried.
158
- *
159
- * @param ctx - The mutation or action context that can call ctx.runMutation.
160
- * @param id - The ID of the work to cancel.
161
- */
162
- cancel(ctx: RunMutationCtx, id: WorkId): Promise<void>;
163
- /**
164
- * Cancels all pending work items. See {@link cancel}.
165
- *
166
- * @param ctx - The mutation or action context that can call ctx.runMutation.
167
- */
168
- cancelAll(ctx: RunMutationCtx, options?: {
169
- limit?: number;
170
- }): Promise<void>;
171
- /**
172
- * Gets the status of a work item.
173
- *
174
- * @param ctx - The query context that can call ctx.runQuery.
175
- * @param id - The ID of the work to get the status of.
176
- * @returns The status of the work item. One of:
177
- * - `{ state: "pending", previousAttempts: number }`
178
- * - `{ state: "running", previousAttempts: number }`
179
- * - `{ state: "finished" }`
180
- */
181
- status(ctx: RunQueryCtx, id: WorkId): Promise<Status>;
182
- /**
183
- * Gets the status of a batch of work items.
184
- *
185
- * @param ctx - The query context that can call ctx.runQuery.
186
- * @param ids - The IDs of the work to get the status of.
187
- * @returns The status of the work items.
188
- */
189
- statusBatch(ctx: RunQueryCtx, ids: WorkId[]): Promise<Status[]>;
190
- /**
191
- * Defines a mutation that will be run after a work item completes.
192
- * You can pass this to a call to enqueue* like so:
193
- * ```ts
194
- * export const myOnComplete = workpool.defineOnComplete({
195
- * context: v.literal("myContextValue"), // optional
196
- * handler: async (ctx, {workId, context, result}) => {
197
- * // ... do something with the result
198
- * },
199
- * });
200
- *
201
- * // in some other function:
202
- * const workId = await workpool.enqueueAction(ctx, internal.foo.bar, {
203
- * // ... args to action
204
- * }, {
205
- * onComplete: internal.foo.myOnComplete,
206
- * });
207
- * ```
208
- */
209
- defineOnComplete<DataModel extends GenericDataModel, V extends Validator<any, any, any> = VAny<any, "optional">>({ context, handler, }: {
210
- context?: V;
211
- handler: (ctx: GenericMutationCtx<DataModel>, args: {
212
- workId: WorkId;
213
- context: Infer<V>;
214
- result: RunResult;
215
- }) => Promise<void>;
216
- }): RegisteredMutation<"internal", OnCompleteArgs, null>;
217
- }
218
- /**
219
- * Returns a validator to use for the onComplete mutation.
220
- * To be used like:
221
- * ```ts
222
- * export const myOnComplete = internalMutation({
223
- * args: vOnCompleteArgs(v.string()),
224
- * handler: async (ctx, {workId, context, result}) => {
225
- * // context has been validated as a string
226
- * // ... do something with the result
227
- * },
228
- * });
229
- * @param context - The context validator. If not provided, it will be `v.any()`.
230
- * @returns The validator for the onComplete mutation.
231
- */
232
- export declare function vOnCompleteArgs<V extends Validator<any, "required", any> = VAny>(context?: V): import("convex/values").VObject<import("convex/server").Expand<{ [Property in V["isOptional"] extends "optional" ? "context" : never]?: Exclude<Infer<{
233
- workId: VString<WorkId, "required">;
234
- context: V;
235
- result: import("convex/values").VUnion<{
236
- kind: "success";
237
- returnValue: any;
238
- } | {
239
- kind: "failed";
240
- error: string;
241
- } | {
242
- kind: "canceled";
243
- }, [import("convex/values").VObject<{
244
- kind: "success";
245
- returnValue: any;
246
- }, {
247
- kind: import("convex/values").VLiteral<"success", "required">;
248
- returnValue: VAny<any, "required", string>;
249
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
250
- kind: "failed";
251
- error: string;
252
- }, {
253
- kind: import("convex/values").VLiteral<"failed", "required">;
254
- error: VString<string, "required">;
255
- }, "required", "kind" | "error">, import("convex/values").VObject<{
256
- kind: "canceled";
257
- }, {
258
- kind: import("convex/values").VLiteral<"canceled", "required">;
259
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
260
- }[Property]>, undefined> | undefined; } & { [Property_1 in Exclude<"context", V["isOptional"] extends "optional" ? "context" : never> | Exclude<"workId", V["isOptional"] extends "optional" ? "context" : never> | Exclude<"result", V["isOptional"] extends "optional" ? "context" : never>]: Infer<{
261
- workId: VString<WorkId, "required">;
262
- context: V;
263
- result: import("convex/values").VUnion<{
264
- kind: "success";
265
- returnValue: any;
266
- } | {
267
- kind: "failed";
268
- error: string;
269
- } | {
270
- kind: "canceled";
271
- }, [import("convex/values").VObject<{
272
- kind: "success";
273
- returnValue: any;
274
- }, {
275
- kind: import("convex/values").VLiteral<"success", "required">;
276
- returnValue: VAny<any, "required", string>;
277
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
278
- kind: "failed";
279
- error: string;
280
- }, {
281
- kind: import("convex/values").VLiteral<"failed", "required">;
282
- error: VString<string, "required">;
283
- }, "required", "kind" | "error">, import("convex/values").VObject<{
284
- kind: "canceled";
285
- }, {
286
- kind: import("convex/values").VLiteral<"canceled", "required">;
287
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
288
- }[Property_1]>; }>, {
289
- workId: VString<WorkId, "required">;
290
- context: V;
291
- result: import("convex/values").VUnion<{
292
- kind: "success";
293
- returnValue: any;
294
- } | {
295
- kind: "failed";
296
- error: string;
297
- } | {
298
- kind: "canceled";
299
- }, [import("convex/values").VObject<{
300
- kind: "success";
301
- returnValue: any;
302
- }, {
303
- kind: import("convex/values").VLiteral<"success", "required">;
304
- returnValue: VAny<any, "required", string>;
305
- }, "required", "kind" | "returnValue" | `returnValue.${string}`>, import("convex/values").VObject<{
306
- kind: "failed";
307
- error: string;
308
- }, {
309
- kind: import("convex/values").VLiteral<"failed", "required">;
310
- error: VString<string, "required">;
311
- }, "required", "kind" | "error">, import("convex/values").VObject<{
312
- kind: "canceled";
313
- }, {
314
- kind: import("convex/values").VLiteral<"canceled", "required">;
315
- }, "required", "kind">], "required", "kind" | "returnValue" | `returnValue.${string}` | "error">;
316
- }, "required", "context" | "workId" | "result" | `context.${V["fieldPaths"]}` | "result.kind" | "result.returnValue" | `result.returnValue.${string}` | "result.error">;
317
- export type RetryOption = {
318
- /** Whether to retry the action if it fails.
319
- * If false, the action won’t be retried.
320
- * If true, it will use the default retry behavior.
321
- * If custom behavior is provided, it will retry using that behavior.
322
- * If unset, it will use the Workpool's configured default.
323
- */
324
- retry?: boolean | RetryBehavior;
325
- };
326
- export type WorkpoolOptions = {
327
- /** How many actions/mutations can be running at once within this pool.
328
- * Min 1, Suggested max: 100 on Pro, 20 on the free plan.
329
- */
330
- maxParallelism?: number;
331
- /** How much to log. This is updated on each call to `enqueue*`,
332
- * `status`, or `cancel*`.
333
- * Default is REPORT, which logs warnings, errors, and a periodic report.
334
- * With INFO, you can also see events for started and completed work.
335
- * Stats generated can be parsed by tools like
336
- * [Axiom](https://axiom.co) for monitoring.
337
- * With DEBUG, you can see timers and internal events for work being
338
- * scheduled.
339
- */
340
- logLevel?: LogLevel;
341
- } & WorkpoolRetryOptions;
342
- export type WorkpoolRetryOptions = {
343
- /** Default retry behavior for enqueued actions.
344
- * See {@link RetryBehavior}.
345
- */
346
- defaultRetryBehavior?: RetryBehavior;
347
- /** Whether to retry actions that fail by default. Default: false.
348
- * NOTE: Only enable this if your actions are idempotent.
349
- * See the docs (README.md) for more details.
350
- */
351
- retryActionsByDefault?: boolean;
352
- };
353
- export type EnqueueOptions = {
354
- /**
355
- * The name of the function. By default, if you pass in api.foo.bar.baz,
356
- * it will use "foo/bar:baz" as the name. If you pass in a function handle,
357
- * it will use the function handle directly.
358
- */
359
- name?: string;
360
- /**
361
- * A mutation to run after the function succeeds, fails, or is canceled.
362
- * The context type is for your use, feel free to provide a validator for it.
363
- * e.g.
364
- * ```ts
365
- * export const completion = workpool.defineOnComplete({
366
- * context: v.string(),
367
- * handler: async (ctx, {workId, context, result}) => {
368
- * // context has been validated as a string
369
- * // ... do something with the result
370
- * },
371
- * });
372
- * ```
373
- * or more manually:
374
- * ```ts
375
- * export const completion = internalMutation({
376
- * args: vOnCompleteArgs(v.string()),
377
- * handler: async (ctx, args) => {
378
- * console.log(args.result, "Got Context back -> ", args.context, Date.now() - args.context);
379
- * },
380
- * });
381
- * ```
382
- */
383
- onComplete?: FunctionReference<"mutation", FunctionVisibility, OnCompleteArgs> | null;
384
- /**
385
- * A context object to pass to the `onComplete` mutation.
386
- * Useful for passing data from the enqueue site to the onComplete site.
387
- */
388
- context?: unknown;
389
- } & ({
390
- /**
391
- * The time (ms since epoch) to run the action at.
392
- * If not provided, the action will be run as soon as possible.
393
- * Note: this is advisory only. It may run later.
394
- */
395
- runAt?: number;
396
- } | {
397
- /**
398
- * The number of milliseconds to run the action after.
399
- * If not provided, the action will be run as soon as possible.
400
- * Note: this is advisory only. It may run later.
401
- */
402
- runAfter?: number;
403
- });
404
- export type OnCompleteArgs = {
405
- /**
406
- * The ID of the work that completed.
407
- */
408
- workId: WorkId;
409
- /**
410
- * The context object passed when enqueuing the work.
411
- * Useful for passing data from the enqueue site to the onComplete site.
412
- */
413
- context: unknown;
414
- /**
415
- * The result of the run that completed.
416
- */
417
- result: RunResult;
418
- };
419
- export declare function enqueueBatch<FnType extends FunctionType, Args extends DefaultFunctionArgs, ReturnType>(component: UseApi<Mounts>, ctx: RunMutationCtx, fnType: FnType, fn: FunctionReference<FnType, FunctionVisibility, Args, ReturnType>, fnArgsArray: Array<Args>, options: EnqueueOptions & {
420
- retryBehavior?: RetryBehavior;
421
- maxParallelism?: number;
422
- logLevel?: LogLevel;
423
- }): Promise<WorkId[]>;
424
- export declare function enqueue<FnType extends FunctionType, Args extends DefaultFunctionArgs, ReturnType>(component: UseApi<Mounts>, ctx: RunMutationCtx, fnType: FnType, fn: FunctionReference<FnType, FunctionVisibility, Args, ReturnType>, fnArgs: Args, options: EnqueueOptions & {
425
- retryBehavior?: RetryBehavior;
426
- maxParallelism?: number;
427
- logLevel?: LogLevel;
428
- }): Promise<WorkId>;
429
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EAEnB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAElB,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAK,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAIL,gBAAgB,EAChB,KAAK,aAAa,EAClB,SAAS,EAET,MAAM,EACP,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,cAAc,EACd,WAAW,EAEX,MAAM,EACP,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,gBAAgB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,CAAC;AAChE,OAAO,EAAE,aAAa,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,QAAQ,IAAI,SAAS,E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