@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.
- package/LICENSE +201 -0
- package/README.md +183 -0
- package/dist/commonjs/client/index.d.ts +53 -0
- package/dist/commonjs/client/index.d.ts.map +1 -0
- package/dist/commonjs/client/index.js +40 -0
- package/dist/commonjs/client/index.js.map +1 -0
- package/dist/commonjs/component/_generated/api.d.ts +14 -0
- package/dist/commonjs/component/_generated/api.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/api.js +22 -0
- package/dist/commonjs/component/_generated/api.js.map +1 -0
- package/dist/commonjs/component/_generated/server.d.ts +64 -0
- package/dist/commonjs/component/_generated/server.d.ts.map +1 -0
- package/dist/commonjs/component/_generated/server.js +74 -0
- package/dist/commonjs/component/_generated/server.js.map +1 -0
- package/dist/commonjs/component/convex.config.d.ts +3 -0
- package/dist/commonjs/component/convex.config.d.ts.map +1 -0
- package/dist/commonjs/component/convex.config.js +6 -0
- package/dist/commonjs/component/convex.config.js.map +1 -0
- package/dist/commonjs/component/lib.d.ts +50 -0
- package/dist/commonjs/component/lib.d.ts.map +1 -0
- package/dist/commonjs/component/lib.js +562 -0
- package/dist/commonjs/component/lib.js.map +1 -0
- package/dist/commonjs/component/logging.d.ts +13 -0
- package/dist/commonjs/component/logging.d.ts.map +1 -0
- package/dist/commonjs/component/logging.js +41 -0
- package/dist/commonjs/component/logging.js.map +1 -0
- package/dist/commonjs/component/schema.d.ts +149 -0
- package/dist/commonjs/component/schema.d.ts.map +1 -0
- package/dist/commonjs/component/schema.js +85 -0
- package/dist/commonjs/component/schema.js.map +1 -0
- package/dist/commonjs/component/stats.d.ts +37 -0
- package/dist/commonjs/component/stats.d.ts.map +1 -0
- package/dist/commonjs/component/stats.js +75 -0
- package/dist/commonjs/component/stats.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/client/index.d.ts +53 -0
- package/dist/esm/client/index.d.ts.map +1 -0
- package/dist/esm/client/index.js +40 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/component/_generated/api.d.ts +14 -0
- package/dist/esm/component/_generated/api.d.ts.map +1 -0
- package/dist/esm/component/_generated/api.js +22 -0
- package/dist/esm/component/_generated/api.js.map +1 -0
- package/dist/esm/component/_generated/server.d.ts +64 -0
- package/dist/esm/component/_generated/server.d.ts.map +1 -0
- package/dist/esm/component/_generated/server.js +74 -0
- package/dist/esm/component/_generated/server.js.map +1 -0
- package/dist/esm/component/convex.config.d.ts +3 -0
- package/dist/esm/component/convex.config.d.ts.map +1 -0
- package/dist/esm/component/convex.config.js +6 -0
- package/dist/esm/component/convex.config.js.map +1 -0
- package/dist/esm/component/lib.d.ts +50 -0
- package/dist/esm/component/lib.d.ts.map +1 -0
- package/dist/esm/component/lib.js +562 -0
- package/dist/esm/component/lib.js.map +1 -0
- package/dist/esm/component/logging.d.ts +13 -0
- package/dist/esm/component/logging.d.ts.map +1 -0
- package/dist/esm/component/logging.js +41 -0
- package/dist/esm/component/logging.js.map +1 -0
- package/dist/esm/component/schema.d.ts +149 -0
- package/dist/esm/component/schema.d.ts.map +1 -0
- package/dist/esm/component/schema.js +85 -0
- package/dist/esm/component/schema.js.map +1 -0
- package/dist/esm/component/stats.d.ts +37 -0
- package/dist/esm/component/stats.d.ts.map +1 -0
- package/dist/esm/component/stats.js +75 -0
- package/dist/esm/component/stats.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/package.json +83 -0
- package/src/client/index.ts +121 -0
- package/src/component/_generated/api.d.ts +133 -0
- package/src/component/_generated/api.js +23 -0
- package/src/component/_generated/dataModel.d.ts +60 -0
- package/src/component/_generated/server.d.ts +149 -0
- package/src/component/_generated/server.js +90 -0
- package/src/component/convex.config.ts +8 -0
- package/src/component/lib.ts +670 -0
- package/src/component/logging.ts +59 -0
- package/src/component/schema.ts +103 -0
- package/src/component/stats.ts +90 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Infer } from "convex/values";
|
|
2
|
+
export declare const completionStatus: import("convex/values").VUnion<"success" | "error" | "canceled" | "timeout", [import("convex/values").VLiteral<"success", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"canceled", "required">, import("convex/values").VLiteral<"timeout", "required">], "required", never>;
|
|
3
|
+
export type CompletionStatus = Infer<typeof completionStatus>;
|
|
4
|
+
/**
|
|
5
|
+
Data flow:
|
|
6
|
+
|
|
7
|
+
- The mutation `mainLoop` runs periodically and serially.
|
|
8
|
+
- Several tables act as queues, with client-driven mutations enqueueing at high
|
|
9
|
+
timestamps and `mainLoop` popping at low timestamps:
|
|
10
|
+
pendingStart, pendingCompletion, and pendingCancelation.
|
|
11
|
+
- The `enqueue` mutation writes to pendingStart.
|
|
12
|
+
- The `cancel` mutation writes to pendingCancelation.
|
|
13
|
+
- The `saveResult` mutation, run as part of scheduled work, writes to pendingCompletion.
|
|
14
|
+
- mainLoop processes the queues:
|
|
15
|
+
- pendingStart => inProgressWork.
|
|
16
|
+
- pendingCompletion and pendingCancelation => completedWork.
|
|
17
|
+
- inProgressWork that finishes uncleanly (timeout or system failure) => completedWork.
|
|
18
|
+
- `mainLoop` schedules itself to run.
|
|
19
|
+
- `enqueue`, `cancel`, and `saveResult` mutations check when `mainLoop` is scheduled to run,
|
|
20
|
+
and if it's too far in the future, they schedule it to run sooner.
|
|
21
|
+
- `status` query reads from pendingWork and completedWork.
|
|
22
|
+
- `cleanup` mutation deletes old rows from completedWork.
|
|
23
|
+
|
|
24
|
+
To avoid OCCs, we restrict which mutations can read and write from each table:
|
|
25
|
+
- pools: read by all, written only when static Workpool options change.
|
|
26
|
+
- mainLoop (table): read by all, written mostly by `mainLoop`.
|
|
27
|
+
If `mainLoop` will not run for a while, mainLoop table is written by `enqueue`, `cancel`, or `saveResult`.
|
|
28
|
+
- pendingWork: `enqueue` inserts at high timestamps, `mainLoop` pops at low timestamps. `status` query does point-reads.
|
|
29
|
+
- pendingCompletion: `saveResult` inserts at high timestamps, `mainLoop` pops at low timestamps.
|
|
30
|
+
- pendingCancelation: `cancel` inserts at high timestamps, `mainLoop` pops at low timestamps.
|
|
31
|
+
- inProgressWork: `mainLoop` inserts, reads all, and deletes.
|
|
32
|
+
- completedWork: `mainLoop` inserts at hight timestamps, `status` query reads, `cleanup` deletes at low timestamps.
|
|
33
|
+
|
|
34
|
+
*/
|
|
35
|
+
declare const _default: import("convex/server").SchemaDefinition<{
|
|
36
|
+
pool: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
37
|
+
maxParallelism: number;
|
|
38
|
+
statusTtl: number;
|
|
39
|
+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
40
|
+
}, {
|
|
41
|
+
maxParallelism: import("convex/values").VFloat64<number, "required">;
|
|
42
|
+
statusTtl: import("convex/values").VFloat64<number, "required">;
|
|
43
|
+
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>;
|
|
44
|
+
}, "required", "maxParallelism" | "statusTtl" | "logLevel">, {}, {}, {}>;
|
|
45
|
+
mainLoop: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
46
|
+
state: {
|
|
47
|
+
kind: "running";
|
|
48
|
+
} | {
|
|
49
|
+
kind: "scheduled";
|
|
50
|
+
runAtTime: number;
|
|
51
|
+
fn: import("convex/values").GenericId<"_scheduled_functions">;
|
|
52
|
+
} | {
|
|
53
|
+
kind: "idle";
|
|
54
|
+
};
|
|
55
|
+
}, {
|
|
56
|
+
state: import("convex/values").VUnion<{
|
|
57
|
+
kind: "running";
|
|
58
|
+
} | {
|
|
59
|
+
kind: "scheduled";
|
|
60
|
+
runAtTime: number;
|
|
61
|
+
fn: import("convex/values").GenericId<"_scheduled_functions">;
|
|
62
|
+
} | {
|
|
63
|
+
kind: "idle";
|
|
64
|
+
}, [import("convex/values").VObject<{
|
|
65
|
+
kind: "running";
|
|
66
|
+
}, {
|
|
67
|
+
kind: import("convex/values").VLiteral<"running", "required">;
|
|
68
|
+
}, "required", "kind">, import("convex/values").VObject<{
|
|
69
|
+
kind: "scheduled";
|
|
70
|
+
runAtTime: number;
|
|
71
|
+
fn: import("convex/values").GenericId<"_scheduled_functions">;
|
|
72
|
+
}, {
|
|
73
|
+
kind: import("convex/values").VLiteral<"scheduled", "required">;
|
|
74
|
+
runAtTime: import("convex/values").VFloat64<number, "required">;
|
|
75
|
+
fn: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions">, "required">;
|
|
76
|
+
}, "required", "kind" | "runAtTime" | "fn">, import("convex/values").VObject<{
|
|
77
|
+
kind: "idle";
|
|
78
|
+
}, {
|
|
79
|
+
kind: import("convex/values").VLiteral<"idle", "required">;
|
|
80
|
+
}, "required", "kind">], "required", "kind" | "runAtTime" | "fn">;
|
|
81
|
+
}, "required", "state" | "state.kind" | "state.runAtTime" | "state.fn">, {}, {}, {}>;
|
|
82
|
+
work: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
83
|
+
fnType: "action" | "mutation";
|
|
84
|
+
fnHandle: string;
|
|
85
|
+
fnName: string;
|
|
86
|
+
fnArgs: any;
|
|
87
|
+
}, {
|
|
88
|
+
fnType: import("convex/values").VUnion<"action" | "mutation", [import("convex/values").VLiteral<"action", "required">, import("convex/values").VLiteral<"mutation", "required">], "required", never>;
|
|
89
|
+
fnHandle: import("convex/values").VString<string, "required">;
|
|
90
|
+
fnName: import("convex/values").VString<string, "required">;
|
|
91
|
+
fnArgs: import("convex/values").VAny<any, "required", string>;
|
|
92
|
+
}, "required", "fnType" | "fnHandle" | "fnName" | "fnArgs" | `fnArgs.${string}`>, {}, {}, {}>;
|
|
93
|
+
pendingStart: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
94
|
+
workId: import("convex/values").GenericId<"work">;
|
|
95
|
+
}, {
|
|
96
|
+
workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
|
|
97
|
+
}, "required", "workId">, {
|
|
98
|
+
workId: ["workId", "_creationTime"];
|
|
99
|
+
}, {}, {}>;
|
|
100
|
+
pendingCompletion: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
101
|
+
workId: import("convex/values").GenericId<"work">;
|
|
102
|
+
generation: number;
|
|
103
|
+
completionStatus: "success" | "error" | "canceled" | "timeout";
|
|
104
|
+
}, {
|
|
105
|
+
generation: import("convex/values").VFloat64<number, "required">;
|
|
106
|
+
completionStatus: import("convex/values").VUnion<"success" | "error" | "canceled" | "timeout", [import("convex/values").VLiteral<"success", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"canceled", "required">, import("convex/values").VLiteral<"timeout", "required">], "required", never>;
|
|
107
|
+
workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
|
|
108
|
+
}, "required", "workId" | "generation" | "completionStatus">, {
|
|
109
|
+
workId: ["workId", "_creationTime"];
|
|
110
|
+
generation: ["generation", "_creationTime"];
|
|
111
|
+
}, {}, {}>;
|
|
112
|
+
pendingCancelation: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
113
|
+
workId: import("convex/values").GenericId<"work">;
|
|
114
|
+
}, {
|
|
115
|
+
workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
|
|
116
|
+
}, "required", "workId">, {}, {}, {}>;
|
|
117
|
+
inProgressWork: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
118
|
+
running: import("convex/values").GenericId<"_scheduled_functions">;
|
|
119
|
+
workId: import("convex/values").GenericId<"work">;
|
|
120
|
+
timeoutMs: number | null;
|
|
121
|
+
}, {
|
|
122
|
+
running: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions">, "required">;
|
|
123
|
+
timeoutMs: import("convex/values").VUnion<number | null, [import("convex/values").VFloat64<number, "required">, import("convex/values").VNull<null, "required">], "required", never>;
|
|
124
|
+
workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
|
|
125
|
+
}, "required", "running" | "workId" | "timeoutMs">, {
|
|
126
|
+
workId: ["workId", "_creationTime"];
|
|
127
|
+
}, {}, {}>;
|
|
128
|
+
inProgressCount: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
129
|
+
count: number;
|
|
130
|
+
}, {
|
|
131
|
+
count: import("convex/values").VFloat64<number, "required">;
|
|
132
|
+
}, "required", "count">, {}, {}, {}>;
|
|
133
|
+
completedWork: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
134
|
+
workId: import("convex/values").GenericId<"work">;
|
|
135
|
+
completionStatus: "success" | "error" | "canceled" | "timeout";
|
|
136
|
+
}, {
|
|
137
|
+
completionStatus: import("convex/values").VUnion<"success" | "error" | "canceled" | "timeout", [import("convex/values").VLiteral<"success", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"canceled", "required">, import("convex/values").VLiteral<"timeout", "required">], "required", never>;
|
|
138
|
+
workId: import("convex/values").VId<import("convex/values").GenericId<"work">, "required">;
|
|
139
|
+
}, "required", "workId" | "completionStatus">, {
|
|
140
|
+
workId: ["workId", "_creationTime"];
|
|
141
|
+
}, {}, {}>;
|
|
142
|
+
completionGeneration: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
143
|
+
generation: number;
|
|
144
|
+
}, {
|
|
145
|
+
generation: import("convex/values").VFloat64<number, "required">;
|
|
146
|
+
}, "required", "generation">, {}, {}, {}>;
|
|
147
|
+
}, true>;
|
|
148
|
+
export default _default;
|
|
149
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAK,MAAM,eAAe,CAAC;AAGzC,eAAO,MAAM,gBAAgB,sUAK5B,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wBA0DG"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
2
|
+
import { v } from "convex/values";
|
|
3
|
+
import { logLevel } from "./logging";
|
|
4
|
+
export const completionStatus = v.union(v.literal("success"), v.literal("error"), v.literal("canceled"), v.literal("timeout"));
|
|
5
|
+
/**
|
|
6
|
+
Data flow:
|
|
7
|
+
|
|
8
|
+
- The mutation `mainLoop` runs periodically and serially.
|
|
9
|
+
- Several tables act as queues, with client-driven mutations enqueueing at high
|
|
10
|
+
timestamps and `mainLoop` popping at low timestamps:
|
|
11
|
+
pendingStart, pendingCompletion, and pendingCancelation.
|
|
12
|
+
- The `enqueue` mutation writes to pendingStart.
|
|
13
|
+
- The `cancel` mutation writes to pendingCancelation.
|
|
14
|
+
- The `saveResult` mutation, run as part of scheduled work, writes to pendingCompletion.
|
|
15
|
+
- mainLoop processes the queues:
|
|
16
|
+
- pendingStart => inProgressWork.
|
|
17
|
+
- pendingCompletion and pendingCancelation => completedWork.
|
|
18
|
+
- inProgressWork that finishes uncleanly (timeout or system failure) => completedWork.
|
|
19
|
+
- `mainLoop` schedules itself to run.
|
|
20
|
+
- `enqueue`, `cancel`, and `saveResult` mutations check when `mainLoop` is scheduled to run,
|
|
21
|
+
and if it's too far in the future, they schedule it to run sooner.
|
|
22
|
+
- `status` query reads from pendingWork and completedWork.
|
|
23
|
+
- `cleanup` mutation deletes old rows from completedWork.
|
|
24
|
+
|
|
25
|
+
To avoid OCCs, we restrict which mutations can read and write from each table:
|
|
26
|
+
- pools: read by all, written only when static Workpool options change.
|
|
27
|
+
- mainLoop (table): read by all, written mostly by `mainLoop`.
|
|
28
|
+
If `mainLoop` will not run for a while, mainLoop table is written by `enqueue`, `cancel`, or `saveResult`.
|
|
29
|
+
- pendingWork: `enqueue` inserts at high timestamps, `mainLoop` pops at low timestamps. `status` query does point-reads.
|
|
30
|
+
- pendingCompletion: `saveResult` inserts at high timestamps, `mainLoop` pops at low timestamps.
|
|
31
|
+
- pendingCancelation: `cancel` inserts at high timestamps, `mainLoop` pops at low timestamps.
|
|
32
|
+
- inProgressWork: `mainLoop` inserts, reads all, and deletes.
|
|
33
|
+
- completedWork: `mainLoop` inserts at hight timestamps, `status` query reads, `cleanup` deletes at low timestamps.
|
|
34
|
+
|
|
35
|
+
*/
|
|
36
|
+
export default defineSchema({
|
|
37
|
+
// Statically configured, singleton.
|
|
38
|
+
pool: defineTable({
|
|
39
|
+
maxParallelism: v.number(),
|
|
40
|
+
statusTtl: v.number(),
|
|
41
|
+
logLevel,
|
|
42
|
+
}),
|
|
43
|
+
mainLoop: defineTable({
|
|
44
|
+
state: v.union(v.object({ kind: v.literal("running") }), v.object({
|
|
45
|
+
kind: v.literal("scheduled"),
|
|
46
|
+
runAtTime: v.number(),
|
|
47
|
+
fn: v.id("_scheduled_functions"),
|
|
48
|
+
}), v.object({ kind: v.literal("idle") })),
|
|
49
|
+
}),
|
|
50
|
+
work: defineTable({
|
|
51
|
+
fnType: v.union(v.literal("action"), v.literal("mutation")),
|
|
52
|
+
fnHandle: v.string(),
|
|
53
|
+
fnName: v.string(),
|
|
54
|
+
fnArgs: v.any(),
|
|
55
|
+
}),
|
|
56
|
+
pendingStart: defineTable({
|
|
57
|
+
workId: v.id("work"),
|
|
58
|
+
}).index("workId", ["workId"]),
|
|
59
|
+
pendingCompletion: defineTable({
|
|
60
|
+
generation: v.number(),
|
|
61
|
+
completionStatus,
|
|
62
|
+
workId: v.id("work"),
|
|
63
|
+
})
|
|
64
|
+
.index("workId", ["workId"])
|
|
65
|
+
.index("generation", ["generation"]),
|
|
66
|
+
pendingCancelation: defineTable({
|
|
67
|
+
workId: v.id("work"),
|
|
68
|
+
}),
|
|
69
|
+
inProgressWork: defineTable({
|
|
70
|
+
running: v.id("_scheduled_functions"),
|
|
71
|
+
timeoutMs: v.union(v.number(), v.null()),
|
|
72
|
+
workId: v.id("work"),
|
|
73
|
+
}).index("workId", ["workId"]),
|
|
74
|
+
inProgressCount: defineTable({
|
|
75
|
+
count: v.number(),
|
|
76
|
+
}),
|
|
77
|
+
completedWork: defineTable({
|
|
78
|
+
completionStatus,
|
|
79
|
+
workId: v.id("work"),
|
|
80
|
+
}).index("workId", ["workId"]),
|
|
81
|
+
completionGeneration: defineTable({
|
|
82
|
+
generation: v.number(),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAS,CAAC,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CACrC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAClB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,EACrB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CACrB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,eAAe,YAAY,CAAC;IAC1B,oCAAoC;IACpC,IAAI,EAAE,WAAW,CAAC;QAChB,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;QACrB,QAAQ;KACT,CAAC;IAEF,QAAQ,EAAE,WAAW,CAAC;Q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,MAAM,CAAC;KACrB,CAAC;IAEF,cAAc,EAAE,WAAW,CAAC;QAC1B,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC;QACrC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC;KACrB,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;IAC9B,eAAe,EAAE,WAAW,CAAC;QAC3B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC;IAEF,aAAa,EAAE,WAAW,CAAC;QACzB,gBAAgB;QAChB,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC;KACrB,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC;IAE9B,oBAAoB,EAAE,WAAW,CAAC;QAChC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;KACvB,CAAC;CACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Doc } from "./_generated/dataModel";
|
|
2
|
+
/**
|
|
3
|
+
* Record stats about work execution. Intended to be queried by Axiom or Datadog.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Sample axiom dashboard query:
|
|
7
|
+
|
|
8
|
+
workpool
|
|
9
|
+
| extend parsed_message = iff(
|
|
10
|
+
isnotnull(parse_json(trim("'", tostring(["data.message"])))),
|
|
11
|
+
parse_json(trim("'", tostring(["data.message"]))),
|
|
12
|
+
parse_json('{}')
|
|
13
|
+
)
|
|
14
|
+
| extend lagSinceEnqueued = parsed_message["lagSinceEnqueued"]
|
|
15
|
+
| extend fnName = parsed_message["fnName"]
|
|
16
|
+
| summarize avg(todouble(lagSinceEnqueued)) by bin_auto(_time), tostring(fnName)
|
|
17
|
+
|
|
18
|
+
*/
|
|
19
|
+
export declare function recordStarted(work: Doc<"work">): string;
|
|
20
|
+
export declare function recordCompleted(work: Doc<"work">, status: "success" | "error" | "canceled" | "timeout"): string;
|
|
21
|
+
/**
|
|
22
|
+
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
23
|
+
* Use this to debug or diagnose your queue length when it's backed up.
|
|
24
|
+
*/
|
|
25
|
+
export declare const queueLength: import("convex/server").RegisteredQuery<"internal", {}, Promise<any>>;
|
|
26
|
+
/**
|
|
27
|
+
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
28
|
+
* Use this while developing to see the state of the queue.
|
|
29
|
+
*/
|
|
30
|
+
export declare const debugCounts: import("convex/server").RegisteredQuery<"internal", {}, Promise<{
|
|
31
|
+
pendingStart: any;
|
|
32
|
+
inProgressWork: any;
|
|
33
|
+
pendingCompletion: any;
|
|
34
|
+
pendingCancelation: any;
|
|
35
|
+
active: number;
|
|
36
|
+
}>>;
|
|
37
|
+
//# sourceMappingURL=stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../../src/component/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAG7C;;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,OAAO,GAAG,UAAU,GAAG,SAAS,GACnD,MAAM,CASR;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,uEAOtB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;GAwBtB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { v } from "convex/values";
|
|
2
|
+
import { internalQuery } from "./_generated/server";
|
|
3
|
+
/**
|
|
4
|
+
* Record stats about work execution. Intended to be queried by Axiom or Datadog.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Sample axiom dashboard query:
|
|
8
|
+
|
|
9
|
+
workpool
|
|
10
|
+
| extend parsed_message = iff(
|
|
11
|
+
isnotnull(parse_json(trim("'", tostring(["data.message"])))),
|
|
12
|
+
parse_json(trim("'", tostring(["data.message"]))),
|
|
13
|
+
parse_json('{}')
|
|
14
|
+
)
|
|
15
|
+
| extend lagSinceEnqueued = parsed_message["lagSinceEnqueued"]
|
|
16
|
+
| extend fnName = parsed_message["fnName"]
|
|
17
|
+
| summarize avg(todouble(lagSinceEnqueued)) by bin_auto(_time), tostring(fnName)
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
export function recordStarted(work) {
|
|
21
|
+
return JSON.stringify({
|
|
22
|
+
workId: work._id,
|
|
23
|
+
event: "started",
|
|
24
|
+
fnName: work.fnName,
|
|
25
|
+
enqueuedAt: work._creationTime,
|
|
26
|
+
startedAt: Date.now(),
|
|
27
|
+
lagSinceEnqueued: Date.now() - work._creationTime,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function recordCompleted(work, status) {
|
|
31
|
+
return JSON.stringify({
|
|
32
|
+
workId: work._id,
|
|
33
|
+
event: "completed",
|
|
34
|
+
fnName: work.fnName,
|
|
35
|
+
completedAt: Date.now(),
|
|
36
|
+
status,
|
|
37
|
+
lagSinceEnqueued: Date.now() - work._creationTime,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
42
|
+
* Use this to debug or diagnose your queue length when it's backed up.
|
|
43
|
+
*/
|
|
44
|
+
export const queueLength = internalQuery({
|
|
45
|
+
args: {},
|
|
46
|
+
returns: v.number(),
|
|
47
|
+
handler: async (ctx) => {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
return ctx.db.query("pendingStart").count();
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Warning: this should not be used from a mutation, as it will cause conflicts.
|
|
54
|
+
* Use this while developing to see the state of the queue.
|
|
55
|
+
*/
|
|
56
|
+
export const debugCounts = internalQuery({
|
|
57
|
+
args: {},
|
|
58
|
+
returns: v.any(),
|
|
59
|
+
handler: async (ctx) => {
|
|
60
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
61
|
+
const inProgressWork = await ctx.db.query("inProgressWork").count();
|
|
62
|
+
const pendingStart = await ctx.db.query("pendingStart").count();
|
|
63
|
+
const pendingCompletion = await ctx.db.query("pendingCompletion").count();
|
|
64
|
+
const pendingCancelation = await ctx.db.query("pendingCancelation").count();
|
|
65
|
+
return {
|
|
66
|
+
pendingStart,
|
|
67
|
+
inProgressWork,
|
|
68
|
+
pendingCompletion,
|
|
69
|
+
pendingCancelation,
|
|
70
|
+
active: inProgressWork - pendingCompletion - pendingCancelation,
|
|
71
|
+
};
|
|
72
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +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,qBAAqB,CAAC;AAEpD;;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,CAA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C,KAAK,EAAE,CAAC;QACV,MAAM,kBAAkB,GAAG,MACzB,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,oBAAoB,CAClC,CAAC,KAAK,EAAE,CAAC;QACV,OAAO;YACL,YAAY;YACZ,cAAc;YACd,iBAAiB;YACjB,kBAAkB;YAClB,MAAM,EAAE,cAAc,GAAG,iBAAiB,GAAG,kBAAkB;SAChE,CAAC;QACF,sDAAsD;IACxD,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -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,EAA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nB;QAAE,IAAI,EAAE,YAAY,CAAA;KAAE,GACtB;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,gBAAgB,EAAE,gBAAgB,CAAA;KAAE,CAC5D;CAGF;AAID,KAAK,WAAW,GAAG;IACjB,QAAQ,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;CACzD,CAAC;AACF,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,aAAa,CAAC,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IACrB,CAAC,SAAS,SAAS,CAAC,MAAM,EAAE,CAAC,GACzB,MAAM,GACN,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACnB,SAAS,CAAC,CAAC,CAAC,EAAE,GACd,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,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":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAQpB,eAAe,GAChB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,gBAAgB,EAAyB,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAyB,CAAC;AAInD,MAAM,OAAO,QAAQ;IAET;IACA;IAFV,YACU,SAA6B,EAC7B,OAiBP;QAlBO,cAAS,GAAT,SAAS,CAAoB;QAC7B,YAAO,GAAP,OAAO,C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|
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"}
|