@convex-dev/workpool 0.1.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.
Files changed (80) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +183 -0
  3. package/dist/commonjs/client/index.d.ts +53 -0
  4. package/dist/commonjs/client/index.d.ts.map +1 -0
  5. package/dist/commonjs/client/index.js +40 -0
  6. package/dist/commonjs/client/index.js.map +1 -0
  7. package/dist/commonjs/component/_generated/api.d.ts +14 -0
  8. package/dist/commonjs/component/_generated/api.d.ts.map +1 -0
  9. package/dist/commonjs/component/_generated/api.js +22 -0
  10. package/dist/commonjs/component/_generated/api.js.map +1 -0
  11. package/dist/commonjs/component/_generated/server.d.ts +64 -0
  12. package/dist/commonjs/component/_generated/server.d.ts.map +1 -0
  13. package/dist/commonjs/component/_generated/server.js +74 -0
  14. package/dist/commonjs/component/_generated/server.js.map +1 -0
  15. package/dist/commonjs/component/convex.config.d.ts +3 -0
  16. package/dist/commonjs/component/convex.config.d.ts.map +1 -0
  17. package/dist/commonjs/component/convex.config.js +6 -0
  18. package/dist/commonjs/component/convex.config.js.map +1 -0
  19. package/dist/commonjs/component/lib.d.ts +50 -0
  20. package/dist/commonjs/component/lib.d.ts.map +1 -0
  21. package/dist/commonjs/component/lib.js +562 -0
  22. package/dist/commonjs/component/lib.js.map +1 -0
  23. package/dist/commonjs/component/logging.d.ts +13 -0
  24. package/dist/commonjs/component/logging.d.ts.map +1 -0
  25. package/dist/commonjs/component/logging.js +41 -0
  26. package/dist/commonjs/component/logging.js.map +1 -0
  27. package/dist/commonjs/component/schema.d.ts +149 -0
  28. package/dist/commonjs/component/schema.d.ts.map +1 -0
  29. package/dist/commonjs/component/schema.js +85 -0
  30. package/dist/commonjs/component/schema.js.map +1 -0
  31. package/dist/commonjs/component/stats.d.ts +37 -0
  32. package/dist/commonjs/component/stats.d.ts.map +1 -0
  33. package/dist/commonjs/component/stats.js +75 -0
  34. package/dist/commonjs/component/stats.js.map +1 -0
  35. package/dist/commonjs/package.json +3 -0
  36. package/dist/esm/client/index.d.ts +53 -0
  37. package/dist/esm/client/index.d.ts.map +1 -0
  38. package/dist/esm/client/index.js +40 -0
  39. package/dist/esm/client/index.js.map +1 -0
  40. package/dist/esm/component/_generated/api.d.ts +14 -0
  41. package/dist/esm/component/_generated/api.d.ts.map +1 -0
  42. package/dist/esm/component/_generated/api.js +22 -0
  43. package/dist/esm/component/_generated/api.js.map +1 -0
  44. package/dist/esm/component/_generated/server.d.ts +64 -0
  45. package/dist/esm/component/_generated/server.d.ts.map +1 -0
  46. package/dist/esm/component/_generated/server.js +74 -0
  47. package/dist/esm/component/_generated/server.js.map +1 -0
  48. package/dist/esm/component/convex.config.d.ts +3 -0
  49. package/dist/esm/component/convex.config.d.ts.map +1 -0
  50. package/dist/esm/component/convex.config.js +6 -0
  51. package/dist/esm/component/convex.config.js.map +1 -0
  52. package/dist/esm/component/lib.d.ts +50 -0
  53. package/dist/esm/component/lib.d.ts.map +1 -0
  54. package/dist/esm/component/lib.js +562 -0
  55. package/dist/esm/component/lib.js.map +1 -0
  56. package/dist/esm/component/logging.d.ts +13 -0
  57. package/dist/esm/component/logging.d.ts.map +1 -0
  58. package/dist/esm/component/logging.js +41 -0
  59. package/dist/esm/component/logging.js.map +1 -0
  60. package/dist/esm/component/schema.d.ts +149 -0
  61. package/dist/esm/component/schema.d.ts.map +1 -0
  62. package/dist/esm/component/schema.js +85 -0
  63. package/dist/esm/component/schema.js.map +1 -0
  64. package/dist/esm/component/stats.d.ts +37 -0
  65. package/dist/esm/component/stats.d.ts.map +1 -0
  66. package/dist/esm/component/stats.js +75 -0
  67. package/dist/esm/component/stats.js.map +1 -0
  68. package/dist/esm/package.json +3 -0
  69. package/package.json +83 -0
  70. package/src/client/index.ts +121 -0
  71. package/src/component/_generated/api.d.ts +133 -0
  72. package/src/component/_generated/api.js +23 -0
  73. package/src/component/_generated/dataModel.d.ts +60 -0
  74. package/src/component/_generated/server.d.ts +149 -0
  75. package/src/component/_generated/server.js +90 -0
  76. package/src/component/convex.config.ts +8 -0
  77. package/src/component/lib.ts +670 -0
  78. package/src/component/logging.ts +59 -0
  79. package/src/component/schema.ts +103 -0
  80. package/src/component/stats.ts +90 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # Convex Component: Workpool
2
+
3
+ [![npm version](https://badge.fury.io/js/@convex-dev%2Fworkpool.svg)](https://badge.fury.io/js/@convex-dev%2Fworkpool)
4
+
5
+ <!-- START: Include on https://convex.dev/components -->
6
+
7
+ This Convex component pools actions and mutations to restrict parallel requests.
8
+
9
+ Suppose you have some important async work, like sending verification emails,
10
+ and some less important async work, like scraping data from an API. If all of
11
+ these are scheduled with `ctx.scheduler.runAfter`, they'll compete with each
12
+ other for resources. The emails might be delayed if there are too many scraping
13
+ requests queued ahead of them.
14
+
15
+ To resolve this problem, you can separate work into different pools.
16
+
17
+ ```ts
18
+ const emailPool = new Workpool(components.emailWorkpool, {
19
+ maxParallelism: 5,
20
+ });
21
+ const scrapePool = new Workpool(components.scrapeWorkpool, {
22
+ maxParallelism: 1,
23
+ });
24
+
25
+ export const signUp = mutation({
26
+ handler: async (ctx, args) => {
27
+ const userId = await ctx.db.insert("users", args);
28
+ await emailPool.enqueueAction(internal.auth.sendEmailVerification, {
29
+ userId,
30
+ });
31
+ },
32
+ });
33
+
34
+ export const downloadLatestWeather = mutation({
35
+ handler: async (ctx, args) => {
36
+ for (const city of allCities) {
37
+ await scrapePool.enqueueAction(internal.weather.scrape, { city });
38
+ }
39
+ },
40
+ });
41
+ ```
42
+
43
+ With limited parallelism, you can reduce
44
+ [OCC errors](https://docs.convex.dev/error#1)
45
+ from mutations that read and write the same data.
46
+
47
+ Consider this action that calls a mutation to increment a singleton counter.
48
+ By calling the mutation on a workpool with `maxParallelism: 1`, it will never
49
+ throw an error due to conflicts with parallel mutations.
50
+
51
+ ```ts
52
+ const counterPool = new Workpool(components.counterWorkpool, {
53
+ maxParallelism: 1,
54
+ });
55
+
56
+ export const doSomethingAndCount = action({
57
+ handler: async (ctx) => {
58
+ const doSomething = await fetch("https://example.com");
59
+ await counterPool.enqueueMutation(internal.counter.increment, {});
60
+ },
61
+ });
62
+
63
+ // This mutation is prone to conflicting with itself, because it always reads
64
+ // and writes the same data. By running it in a workpool with low parallelism,
65
+ // it will run serially.
66
+ export const increment = internalMutation({
67
+ handler: async (ctx) => {
68
+ const countDoc = await ctx.db.query("counter").unique();
69
+ await ctx.db.patch(countDoc!._id, { count: countDoc!.count + 1 });
70
+ },
71
+ });
72
+ ```
73
+
74
+ Effectively, Workpool runs async functions similar to
75
+ `ctx.scheduler.runAfter(0, ...)`, but it limits the number of functions that
76
+ can run in parallel.
77
+
78
+ ## Pre-requisite: Convex
79
+
80
+ You'll need an existing Convex project to use the component.
81
+ Convex is a hosted backend platform, including a database, serverless functions,
82
+ and a ton more you can learn about [here](https://docs.convex.dev/get-started).
83
+
84
+ Run `npm create convex` or follow any of the [quickstarts](https://docs.convex.dev/home) to set one up.
85
+
86
+ ## Installation
87
+
88
+ See [`example/`](./example/convex/) for a working demo.
89
+
90
+ 1. Install the Workpool component:
91
+
92
+ ```bash
93
+ npm install @convex-dev/workpool
94
+ ```
95
+
96
+ 2. Create a [`convex.config.ts`](./example/convex/convex.config.ts) file in your
97
+ app's `convex/` folder and install the component by calling `use`:
98
+
99
+ ```ts
100
+ // convex/convex.config.ts
101
+ import { defineApp } from "convex/server";
102
+ import workpool from "@convex-dev/workpool/convex.config";
103
+
104
+ const app = defineApp();
105
+ app.use(workpool, { name: "emailWorkpool" });
106
+ app.use(workpool, { name: "scrapeWorkpool" });
107
+ export default app;
108
+ ```
109
+
110
+ ## Usage
111
+
112
+ ```ts
113
+ import { components } from "./_generated/api";
114
+ import { Workpool } from "@convex-dev/workpool";
115
+
116
+ const pool = new Workpool(components.emailWorkpool, { maxParallelism: 10 });
117
+ ```
118
+
119
+ Then you have the following interface on `pool`:
120
+
121
+ ```ts
122
+ // Schedule functions to run in the background.
123
+ const id = await pool.enqueueMutation(internal.foo.bar, args);
124
+ // Or for an action:
125
+ const id = await pool.enqueueAction(internal.foo.baz, args);
126
+
127
+ // Is it done yet? Did it succeed or fail?
128
+ const status = await pool.status(id);
129
+
130
+ // You can cancel the work, if it hasn't finished yet.
131
+ await pool.cancel(id);
132
+ ```
133
+
134
+ See more example usage in [example.ts](./example/convex/example.ts).
135
+
136
+ ## Optimizations with and without Workpool
137
+
138
+ The benefit of Workpool is that it won't fall over if there are many jobs
139
+ scheduled at once, and it allows you to throttle low-priority jobs.
140
+
141
+ However, Workpool has some overhead and can slow down your workload compared
142
+ to using `ctx.scheduler` directly.
143
+
144
+ Since each Workpool has some overhead -- each runs several functions to
145
+ coordinate its work -- don't create too many of them.
146
+
147
+ If you're running into issues with too many concurrent functions, there are
148
+ alternatives to Workpool:
149
+
150
+ - Try combining multiple mutations into a single mutation, with batching or
151
+ debouncing.
152
+ - Call plain TypeScript functions if possible.
153
+ - In particular, an action calling `ctx.runAction` has more overhead than just
154
+ calling the action's handler directly.
155
+
156
+ See [best practices](https://docs.convex.dev/production/best-practices) for more.
157
+
158
+ ## Reading function status
159
+
160
+ The workpool stores the status of each function in the database, so you can
161
+ read it even after the function has finished.
162
+ By default, it will keep the status for 1 day but you can change this with
163
+ the `statusTtl` option to `Workpool`.
164
+
165
+ To keep the status forever, set `statusTtl: Number.POSITIVE_INFINITY`.
166
+
167
+ You can read the status of a function by calling `pool.status(id)`.
168
+
169
+ The status will be one of:
170
+
171
+ - `{ kind: "pending" }`: The function has not started yet.
172
+ - `{ kind: "inProgress" }`: The function is currently running.
173
+ - `{ kind: "completed"; completionStatus: CompletionStatus }`: The function has
174
+ finished.
175
+
176
+ The `CompletionStatus` type is one of:
177
+
178
+ - `"success"`: The function completed successfully.
179
+ - `"error"`: The function threw an error.
180
+ - `"canceled"`: The function was canceled.
181
+ - `"timeout"`: The function timed out.
182
+
183
+ <!-- END: Include on https://convex.dev/components -->
@@ -0,0 +1,53 @@
1
+ import { DefaultFunctionArgs, Expand, FunctionReference, FunctionVisibility, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
2
+ import { GenericId } from "convex/values";
3
+ import { api } from "../component/_generated/api";
4
+ import { LogLevel } from "../component/logging";
5
+ import { completionStatus, type CompletionStatus } from "../component/schema";
6
+ export { completionStatus, type CompletionStatus };
7
+ export type WorkId = string;
8
+ export declare class Workpool {
9
+ private component;
10
+ private options;
11
+ constructor(component: UseApi<typeof api>, options: {
12
+ /** How many actions/mutations can be running at once within this pool.
13
+ * Min 1, Max 300.
14
+ */
15
+ maxParallelism: number;
16
+ /** How much to log.
17
+ * Default WARN.
18
+ * With INFO, you can see events for started and completed work, which can
19
+ * be parsed.
20
+ * With DEBUG, you can see timers and internal events for work being
21
+ * scheduled.
22
+ */
23
+ logLevel?: LogLevel;
24
+ /** How long to keep completed work in the database, for access by `status`.
25
+ * Default 1 day.
26
+ */
27
+ statusTtl?: number;
28
+ });
29
+ enqueueAction<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>, fnArgs: Args): Promise<WorkId>;
30
+ enqueueMutation<Args extends DefaultFunctionArgs, ReturnType>(ctx: RunMutationCtx, fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>, fnArgs: Args): Promise<WorkId>;
31
+ cancel(ctx: RunMutationCtx, id: WorkId): Promise<void>;
32
+ status(ctx: RunQueryCtx, id: WorkId): Promise<{
33
+ kind: "pending";
34
+ } | {
35
+ kind: "inProgress";
36
+ } | {
37
+ kind: "completed";
38
+ completionStatus: CompletionStatus;
39
+ }>;
40
+ }
41
+ type RunQueryCtx = {
42
+ runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
43
+ };
44
+ type RunMutationCtx = {
45
+ runMutation: GenericMutationCtx<GenericDataModel>["runMutation"];
46
+ };
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
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,MAAM,EACN,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEnD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,qBAAa,QAAQ;IAEjB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,OAAO;gBADP,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC,EAC7B,OAAO,EAAE;QACf;;WAEG;QACH,cAAc,EAAE,MAAM,CAAC;QACvB;;;;;;WAMG;QACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;QACpB;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;IAEG,aAAa,CAAC,IAAI,SAAS,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GACnC,CAAC,CAAC;AAEZ,MAAM,MAAM,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC;KAC9B,GAAG,IAAI,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,SAAS,iBAAiB,CACpD,MAAM,KAAK,EACX,QAAQ,EACR,MAAM,KAAK,EACX,MAAM,WAAW,EACjB,MAAM,cAAc,CACrB,GACG,iBAAiB,CACf,KAAK,EACL,UAAU,EACV,SAAS,CAAC,KAAK,CAAC,EAChB,SAAS,CAAC,WAAW,CAAC,EACtB,cAAc,CACf,GACD,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACrB,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { createFunctionHandle, getFunctionName, } from "convex/server";
2
+ import { completionStatus } from "../component/schema";
3
+ export { completionStatus };
4
+ export class Workpool {
5
+ component;
6
+ options;
7
+ constructor(component, options) {
8
+ this.component = component;
9
+ this.options = options;
10
+ }
11
+ async enqueueAction(ctx, fn, fnArgs) {
12
+ const fnHandle = await createFunctionHandle(fn);
13
+ const id = await ctx.runMutation(this.component.lib.enqueue, {
14
+ fnHandle,
15
+ fnName: getFunctionName(fn),
16
+ fnArgs,
17
+ fnType: "action",
18
+ options: this.options,
19
+ });
20
+ return id;
21
+ }
22
+ async enqueueMutation(ctx, fn, fnArgs) {
23
+ const fnHandle = await createFunctionHandle(fn);
24
+ const id = await ctx.runMutation(this.component.lib.enqueue, {
25
+ fnHandle,
26
+ fnName: getFunctionName(fn),
27
+ fnArgs,
28
+ fnType: "mutation",
29
+ options: this.options,
30
+ });
31
+ return id;
32
+ }
33
+ async cancel(ctx, id) {
34
+ await ctx.runMutation(this.component.lib.cancel, { id });
35
+ }
36
+ async status(ctx, id) {
37
+ return await ctx.runQuery(this.component.lib.status, { id });
38
+ }
39
+ }
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"m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AAC,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD,KAAK,CAAC,MAAM,CACV,GAAgB,EAChB,EAAU;QAMV,OAAO,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A utility for referencing Convex functions in your app's API.
3
+ *
4
+ * Usage:
5
+ * ```js
6
+ * const myFunctionReference = api.myModule.myFunction;
7
+ * ```
8
+ */
9
+ export const api: import("convex/server").AnyApi;
10
+ export const internal: import("convex/server").AnyApi;
11
+ export const components: {
12
+ [x: string]: import("../../../node_modules/convex/dist/esm-types/server/components").AnyComponentReference;
13
+ };
14
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,iDAA0B;AAC1B,sDAA+B;AAC/B;;EAA8C"}
@@ -0,0 +1,22 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+ import { anyApi, componentsGeneric } from "convex/server";
11
+ /**
12
+ * A utility for referencing Convex functions in your app's API.
13
+ *
14
+ * Usage:
15
+ * ```js
16
+ * const myFunctionReference = api.myModule.myFunction;
17
+ * ```
18
+ */
19
+ export const api = anyApi;
20
+ export const internal = anyApi;
21
+ export const components = componentsGeneric();
22
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/component/_generated/api.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC;AAC1B,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Define a query in this Convex app's public API.
3
+ *
4
+ * This function will be allowed to read your Convex database and will be accessible from the client.
5
+ *
6
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
7
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
8
+ */
9
+ export const query: import("convex/server").QueryBuilder<any, "public">;
10
+ /**
11
+ * Define a query that is only accessible from other Convex functions (but not from the client).
12
+ *
13
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
14
+ *
15
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
16
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
17
+ */
18
+ export const internalQuery: import("convex/server").QueryBuilder<any, "internal">;
19
+ /**
20
+ * Define a mutation in this Convex app's public API.
21
+ *
22
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
23
+ *
24
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
25
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
26
+ */
27
+ export const mutation: import("convex/server").MutationBuilder<any, "public">;
28
+ /**
29
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
30
+ *
31
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
32
+ *
33
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
34
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
35
+ */
36
+ export const internalMutation: import("convex/server").MutationBuilder<any, "internal">;
37
+ /**
38
+ * Define an action in this Convex app's public API.
39
+ *
40
+ * An action is a function which can execute any JavaScript code, including non-deterministic
41
+ * code and code with side-effects, like calling third-party services.
42
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
43
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
44
+ *
45
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
46
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
47
+ */
48
+ export const action: import("convex/server").ActionBuilder<any, "public">;
49
+ /**
50
+ * Define an action that is only accessible from other Convex functions (but not from the client).
51
+ *
52
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
53
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
54
+ */
55
+ export const internalAction: import("convex/server").ActionBuilder<any, "internal">;
56
+ /**
57
+ * Define a Convex HTTP action.
58
+ *
59
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
60
+ * as its second.
61
+ * @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
62
+ */
63
+ export const httpAction: (func: (ctx: import("convex/server").GenericActionCtx<import("convex/server").GenericDataModel>, request: Request) => Promise<Response>) => import("convex/server").PublicHttpAction;
64
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../../src/component/_generated/server.js"],"names":[],"mappings":"AAqBA;;;;;;;GAOG;AACH,wEAAkC;AAElC;;;;;;;GAOG;AACH,kFAAkD;AAElD;;;;;;;GAOG;AACH,8EAAwC;AAExC;;;;;;;GAOG;AACH,wFAAwD;AAExD;;;;;;;;;;GAUG;AACH,0EAAoC;AAEpC;;;;;GAKG;AACH,oFAAoD;AAEpD;;;;;;GAMG;AACH,8MAA4C"}