@convex-dev/workpool 0.2.20-alpha.0 → 0.3.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -68
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/utils.d.ts +1 -8
- package/dist/client/utils.d.ts.map +1 -1
- package/dist/client/utils.js.map +1 -1
- package/dist/component/_generated/api.d.ts +27 -124
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js +10 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +98 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +4 -18
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +10 -38
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/_generated/server.js +9 -5
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/danger.d.ts +2 -2
- package/dist/component/lib.d.ts +9 -9
- package/dist/component/lib.js +2 -2
- package/dist/component/lib.js.map +1 -1
- package/dist/component/schema.d.ts +15 -15
- package/dist/component/shared.d.ts +3 -3
- package/dist/component/stats.d.ts +2 -2
- package/dist/component/worker.d.ts +3 -3
- package/package.json +30 -29
- package/src/client/index.ts +19 -20
- package/src/client/utils.ts +3 -30
- package/src/component/README.md +6 -6
- package/src/component/_generated/api.ts +70 -0
- package/src/component/_generated/component.ts +117 -0
- package/src/component/_generated/{server.d.ts → server.ts} +33 -21
- package/src/component/complete.test.ts +1 -1
- package/src/component/complete.ts +6 -6
- package/src/component/danger.ts +3 -3
- package/src/component/kick.test.ts +5 -5
- package/src/component/kick.ts +6 -6
- package/src/component/lib.test.ts +5 -5
- package/src/component/lib.ts +10 -10
- package/src/component/logging.ts +2 -2
- package/src/component/loop.test.ts +9 -9
- package/src/component/loop.ts +33 -33
- package/src/component/recovery.test.ts +7 -7
- package/src/component/recovery.ts +2 -2
- package/src/component/schema.ts +2 -2
- package/src/component/shared.ts +5 -5
- package/src/component/stats.test.ts +3 -3
- package/src/component/stats.ts +6 -6
- package/src/test.ts +10 -3
- package/src/component/_generated/api.d.ts +0 -151
- package/src/component/_generated/api.js +0 -23
- package/src/component/_generated/server.js +0 -90
- /package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export declare const runMutationWrapper: import("convex/server").RegisteredMutation<"internal", {
|
|
2
2
|
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
3
|
+
fnArgs: any;
|
|
3
4
|
fnHandle: string;
|
|
4
|
-
workId: import("convex/values").GenericId<"work">;
|
|
5
5
|
fnType: "mutation" | "query";
|
|
6
|
-
|
|
6
|
+
workId: import("convex/values").GenericId<"work">;
|
|
7
7
|
attempt: number;
|
|
8
8
|
}, Promise<void>>;
|
|
9
9
|
export declare const runActionWrapper: import("convex/server").RegisteredAction<"internal", {
|
|
10
10
|
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
11
|
+
fnArgs: any;
|
|
11
12
|
fnHandle: string;
|
|
12
13
|
workId: import("convex/values").GenericId<"work">;
|
|
13
|
-
fnArgs: any;
|
|
14
14
|
attempt: number;
|
|
15
15
|
}, Promise<void>>;
|
|
16
16
|
//# sourceMappingURL=worker.d.ts.map
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"email": "support@convex.dev",
|
|
8
8
|
"url": "https://github.com/get-convex/workpool/issues"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.3.1-alpha.0",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"convex",
|
|
@@ -19,25 +19,23 @@
|
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
21
|
"scripts": {
|
|
22
|
-
"dev": "run-p -r 'dev
|
|
23
|
-
"dev:backend": "convex dev --
|
|
22
|
+
"dev": "run-p -r 'dev:*'",
|
|
23
|
+
"dev:backend": "convex dev --typecheck-components",
|
|
24
24
|
"dev:frontend": "cd example && vite --clearScreen false",
|
|
25
|
+
"dev:build": "chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'convex codegen --component-dir ./src/component && npm run build' --initial",
|
|
25
26
|
"predev": "npm run dev:backend -- --until-success",
|
|
26
|
-
"clean": "rm -rf dist
|
|
27
|
-
"build": "tsc --project ./tsconfig.build.json
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"lint": "eslint src && eslint example/convex",
|
|
32
|
-
"all": "run-p -r 'dev:backend' 'dev:frontend' 'build:watch' 'test:watch'",
|
|
27
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
28
|
+
"build": "tsc --project ./tsconfig.build.json",
|
|
29
|
+
"typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"all": "run-p -r 'dev:*' 'test:watch'",
|
|
33
32
|
"test": "vitest run --typecheck",
|
|
34
33
|
"test:watch": "vitest --typecheck --clearScreen false",
|
|
35
34
|
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
36
35
|
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
37
|
-
"attw": "attw $(npm pack -s) --exclude-entrypoints ./convex.config --profile esm-only",
|
|
38
36
|
"prepare": "npm run build",
|
|
39
|
-
"alpha": "npm run clean && npm ci && run-p test lint typecheck
|
|
40
|
-
"release": "npm run clean && npm ci && run-p test lint typecheck
|
|
37
|
+
"alpha": "npm run clean && npm ci && run-p test lint typecheck && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
|
|
38
|
+
"release": "npm run clean && npm ci && run-p test lint typecheck && npm version patch && npm publish && git push --tags",
|
|
41
39
|
"version": "pbcopy <<<$npm_package_version; vim CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
|
|
42
40
|
},
|
|
43
41
|
"files": [
|
|
@@ -47,51 +45,54 @@
|
|
|
47
45
|
"exports": {
|
|
48
46
|
"./package.json": "./package.json",
|
|
49
47
|
".": {
|
|
50
|
-
"@convex-dev/component-source": "./src/client/index.ts",
|
|
51
48
|
"types": "./dist/client/index.d.ts",
|
|
52
49
|
"default": "./dist/client/index.js"
|
|
53
50
|
},
|
|
54
51
|
"./test": "./src/test.ts",
|
|
52
|
+
"./_generated/component.js": {
|
|
53
|
+
"types": "./dist/component/_generated/component.d.ts"
|
|
54
|
+
},
|
|
55
55
|
"./convex.config": {
|
|
56
|
-
"
|
|
56
|
+
"types": "./dist/component/convex.config.d.ts",
|
|
57
|
+
"default": "./dist/component/convex.config.js"
|
|
58
|
+
},
|
|
59
|
+
"./convex.config.js": {
|
|
57
60
|
"types": "./dist/component/convex.config.d.ts",
|
|
58
61
|
"default": "./dist/component/convex.config.js"
|
|
59
62
|
}
|
|
60
63
|
},
|
|
61
64
|
"peerDependencies": {
|
|
62
|
-
"convex": "
|
|
65
|
+
"convex": "^1.24.8",
|
|
63
66
|
"convex-helpers": "^0.1.94"
|
|
64
67
|
},
|
|
65
68
|
"devDependencies": {
|
|
66
|
-
"@arethetypeswrong/cli": "0.18.2",
|
|
67
69
|
"@edge-runtime/vm": "5.0.0",
|
|
68
70
|
"@eslint/eslintrc": "3.3.1",
|
|
69
|
-
"@eslint/js": "9.
|
|
70
|
-
"@types/node": "
|
|
71
|
+
"@eslint/js": "9.39.1",
|
|
72
|
+
"@types/node": "20.19.24",
|
|
71
73
|
"@types/react": "19.2.2",
|
|
72
74
|
"@types/react-dom": "19.2.2",
|
|
73
|
-
"@vitejs/plugin-react": "5.0
|
|
75
|
+
"@vitejs/plugin-react": "5.1.0",
|
|
74
76
|
"@vitest/coverage-v8": "3.2.4",
|
|
75
77
|
"chokidar-cli": "3.0.0",
|
|
76
|
-
"convex": "1.
|
|
78
|
+
"convex": "1.29.0",
|
|
77
79
|
"convex-helpers": "0.1.104",
|
|
78
80
|
"convex-test": "0.0.38",
|
|
79
81
|
"cpy-cli": "6.0.0",
|
|
80
|
-
"eslint": "9.
|
|
81
|
-
"eslint-plugin-react-hooks": "7.0.
|
|
82
|
+
"eslint": "9.39.1",
|
|
83
|
+
"eslint-plugin-react-hooks": "7.0.1",
|
|
82
84
|
"eslint-plugin-react-refresh": "0.4.24",
|
|
83
|
-
"globals": "16.
|
|
85
|
+
"globals": "16.5.0",
|
|
84
86
|
"npm-run-all2": "8.0.4",
|
|
85
87
|
"pkg-pr-new": "0.0.60",
|
|
86
88
|
"prettier": "3.6.2",
|
|
87
89
|
"react": "19.2.0",
|
|
88
90
|
"react-dom": "19.2.0",
|
|
89
91
|
"typescript": "5.9.3",
|
|
90
|
-
"typescript-eslint": "8.
|
|
91
|
-
"vite": "7.1.
|
|
92
|
+
"typescript-eslint": "8.46.3",
|
|
93
|
+
"vite": "7.1.12",
|
|
92
94
|
"vitest": "3.2.4"
|
|
93
95
|
},
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"module": "./dist/esm/client/index.js"
|
|
96
|
+
"types": "./dist/client/index.d.ts",
|
|
97
|
+
"module": "./dist/client/index.js"
|
|
97
98
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
type VAny,
|
|
18
18
|
type VString,
|
|
19
19
|
} from "convex/values";
|
|
20
|
-
import type {
|
|
20
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
21
21
|
import { DEFAULT_LOG_LEVEL, type LogLevel } from "../component/logging.js";
|
|
22
22
|
import {
|
|
23
23
|
type Config,
|
|
@@ -34,11 +34,11 @@ import {
|
|
|
34
34
|
type RunMutationCtx,
|
|
35
35
|
type RunQueryCtx,
|
|
36
36
|
safeFunctionName,
|
|
37
|
-
type UseApi,
|
|
38
37
|
} from "./utils.js";
|
|
39
38
|
export { logLevel as vLogLevel, type LogLevel } from "../component/logging.js";
|
|
40
39
|
export { retryBehavior as vRetryBehavior } from "../component/shared.js";
|
|
41
40
|
export { vResultValidator, type RetryBehavior, type RunResult };
|
|
41
|
+
|
|
42
42
|
export type WorkId = string & { __isWorkId: true };
|
|
43
43
|
export const vWorkIdValidator = v.string() as VString<WorkId>;
|
|
44
44
|
export {
|
|
@@ -53,8 +53,7 @@ export const vOnComplete = vOnCompleteArgs(v.any());
|
|
|
53
53
|
/** @deprecated Use `vOnCompleteArgs()` instead. */
|
|
54
54
|
export const vOnCompleteValidator = vOnCompleteArgs;
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
export type WorkpoolComponent = UseApi<typeof api>;
|
|
56
|
+
export type WorkpoolComponent = ComponentApi;
|
|
58
57
|
|
|
59
58
|
export class Workpool {
|
|
60
59
|
/**
|
|
@@ -70,7 +69,7 @@ export class Workpool {
|
|
|
70
69
|
*/
|
|
71
70
|
constructor(
|
|
72
71
|
public component: WorkpoolComponent,
|
|
73
|
-
public options: WorkpoolOptions
|
|
72
|
+
public options: WorkpoolOptions,
|
|
74
73
|
) {}
|
|
75
74
|
|
|
76
75
|
/**
|
|
@@ -87,12 +86,12 @@ export class Workpool {
|
|
|
87
86
|
ctx: RunMutationCtx,
|
|
88
87
|
fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>,
|
|
89
88
|
fnArgs: Args,
|
|
90
|
-
options?: RetryOption & EnqueueOptions
|
|
89
|
+
options?: RetryOption & EnqueueOptions,
|
|
91
90
|
): Promise<WorkId> {
|
|
92
91
|
const retryBehavior = getRetryBehavior(
|
|
93
92
|
this.options.defaultRetryBehavior,
|
|
94
93
|
this.options.retryActionsByDefault,
|
|
95
|
-
options?.retry
|
|
94
|
+
options?.retry,
|
|
96
95
|
);
|
|
97
96
|
return enqueue(this.component, ctx, "action", fn, fnArgs, {
|
|
98
97
|
retryBehavior,
|
|
@@ -117,12 +116,12 @@ export class Workpool {
|
|
|
117
116
|
ctx: RunMutationCtx,
|
|
118
117
|
fn: FunctionReference<"action", FunctionVisibility, Args, ReturnType>,
|
|
119
118
|
argsArray: Array<Args>,
|
|
120
|
-
options?: RetryOption & EnqueueOptions
|
|
119
|
+
options?: RetryOption & EnqueueOptions,
|
|
121
120
|
): Promise<WorkId[]> {
|
|
122
121
|
const retryBehavior = getRetryBehavior(
|
|
123
122
|
this.options.defaultRetryBehavior,
|
|
124
123
|
this.options.retryActionsByDefault,
|
|
125
|
-
options?.retry
|
|
124
|
+
options?.retry,
|
|
126
125
|
);
|
|
127
126
|
return enqueueBatch(this.component, ctx, "action", fn, argsArray, {
|
|
128
127
|
retryBehavior,
|
|
@@ -148,7 +147,7 @@ export class Workpool {
|
|
|
148
147
|
ctx: RunMutationCtx,
|
|
149
148
|
fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>,
|
|
150
149
|
fnArgs: Args,
|
|
151
|
-
options?: EnqueueOptions
|
|
150
|
+
options?: EnqueueOptions,
|
|
152
151
|
): Promise<WorkId> {
|
|
153
152
|
return enqueue(this.component, ctx, "mutation", fn, fnArgs, {
|
|
154
153
|
...this.options,
|
|
@@ -170,7 +169,7 @@ export class Workpool {
|
|
|
170
169
|
ctx: RunMutationCtx,
|
|
171
170
|
fn: FunctionReference<"mutation", FunctionVisibility, Args, ReturnType>,
|
|
172
171
|
argsArray: Array<Args>,
|
|
173
|
-
options?: EnqueueOptions
|
|
172
|
+
options?: EnqueueOptions,
|
|
174
173
|
): Promise<WorkId[]> {
|
|
175
174
|
return enqueueBatch(this.component, ctx, "mutation", fn, argsArray, {
|
|
176
175
|
...this.options,
|
|
@@ -194,7 +193,7 @@ export class Workpool {
|
|
|
194
193
|
ctx: RunMutationCtx,
|
|
195
194
|
fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>,
|
|
196
195
|
fnArgs: Args,
|
|
197
|
-
options?: EnqueueOptions
|
|
196
|
+
options?: EnqueueOptions,
|
|
198
197
|
): Promise<WorkId> {
|
|
199
198
|
return enqueue(this.component, ctx, "query", fn, fnArgs, {
|
|
200
199
|
...this.options,
|
|
@@ -217,7 +216,7 @@ export class Workpool {
|
|
|
217
216
|
ctx: RunMutationCtx,
|
|
218
217
|
fn: FunctionReference<"query", FunctionVisibility, Args, ReturnType>,
|
|
219
218
|
argsArray: Array<Args>,
|
|
220
|
-
options?: EnqueueOptions
|
|
219
|
+
options?: EnqueueOptions,
|
|
221
220
|
): Promise<WorkId[]> {
|
|
222
221
|
return enqueueBatch(this.component, ctx, "query", fn, argsArray, {
|
|
223
222
|
...this.options,
|
|
@@ -245,7 +244,7 @@ export class Workpool {
|
|
|
245
244
|
*/
|
|
246
245
|
async cancelAll(
|
|
247
246
|
ctx: RunMutationCtx,
|
|
248
|
-
options?: { limit?: number }
|
|
247
|
+
options?: { limit?: number },
|
|
249
248
|
): Promise<void> {
|
|
250
249
|
await ctx.runMutation(this.component.lib.cancelAll, {
|
|
251
250
|
logLevel: this.options.logLevel ?? DEFAULT_LOG_LEVEL,
|
|
@@ -310,7 +309,7 @@ export class Workpool {
|
|
|
310
309
|
workId: WorkId;
|
|
311
310
|
context: Infer<V>;
|
|
312
311
|
result: RunResult;
|
|
313
|
-
}
|
|
312
|
+
},
|
|
314
313
|
) => Promise<void>;
|
|
315
314
|
}): RegisteredMutation<"internal", OnCompleteArgs, null> {
|
|
316
315
|
return internalMutationGeneric({
|
|
@@ -471,7 +470,7 @@ const _ = {} as OnCompleteArgs satisfies SharedOnCompleteArgs;
|
|
|
471
470
|
function getRetryBehavior(
|
|
472
471
|
defaultRetryBehavior: RetryBehavior | undefined,
|
|
473
472
|
retryActionsByDefault: boolean | undefined,
|
|
474
|
-
retryOverride: boolean | RetryBehavior | undefined
|
|
473
|
+
retryOverride: boolean | RetryBehavior | undefined,
|
|
475
474
|
): RetryBehavior | undefined {
|
|
476
475
|
const defaultRetry = defaultRetryBehavior ?? DEFAULT_RETRY_BEHAVIOR;
|
|
477
476
|
const retryByDefault = retryActionsByDefault ?? false;
|
|
@@ -490,7 +489,7 @@ async function enqueueArgs(
|
|
|
490
489
|
| FunctionHandle<FunctionType, DefaultFunctionArgs>,
|
|
491
490
|
opts:
|
|
492
491
|
| (EnqueueOptions & Partial<Config> & { retryBehavior?: RetryBehavior })
|
|
493
|
-
| undefined
|
|
492
|
+
| undefined,
|
|
494
493
|
) {
|
|
495
494
|
const [fnHandle, fnName] =
|
|
496
495
|
typeof fn === "string" && fn.startsWith("function://")
|
|
@@ -521,7 +520,7 @@ function getRunAt(
|
|
|
521
520
|
runAt?: number;
|
|
522
521
|
runAfter?: number;
|
|
523
522
|
}
|
|
524
|
-
| undefined
|
|
523
|
+
| undefined,
|
|
525
524
|
): number {
|
|
526
525
|
if (!options) {
|
|
527
526
|
return Date.now();
|
|
@@ -549,7 +548,7 @@ export async function enqueueBatch<
|
|
|
549
548
|
retryBehavior?: RetryBehavior;
|
|
550
549
|
maxParallelism?: number;
|
|
551
550
|
logLevel?: LogLevel;
|
|
552
|
-
}
|
|
551
|
+
},
|
|
553
552
|
): Promise<WorkId[]> {
|
|
554
553
|
const { config, ...defaults } = await enqueueArgs(fn, options);
|
|
555
554
|
const ids = await ctx.runMutation(component.lib.enqueueBatch, {
|
|
@@ -577,7 +576,7 @@ export async function enqueue<
|
|
|
577
576
|
retryBehavior?: RetryBehavior;
|
|
578
577
|
maxParallelism?: number;
|
|
579
578
|
logLevel?: LogLevel;
|
|
580
|
-
}
|
|
579
|
+
},
|
|
581
580
|
): Promise<WorkId> {
|
|
582
581
|
const id = await ctx.runMutation(component.lib.enqueue, {
|
|
583
582
|
...(await enqueueArgs(fn, options)),
|
package/src/client/utils.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type Expand,
|
|
3
2
|
type FunctionArgs,
|
|
4
3
|
type FunctionReference,
|
|
5
4
|
type FunctionReturnType,
|
|
@@ -8,50 +7,24 @@ import {
|
|
|
8
7
|
getFunctionAddress,
|
|
9
8
|
getFunctionName,
|
|
10
9
|
} from "convex/server";
|
|
11
|
-
import type { GenericId, Value } from "convex/values";
|
|
12
10
|
|
|
13
11
|
/* Type utils follow */
|
|
14
12
|
|
|
15
13
|
export type RunQueryCtx = {
|
|
16
14
|
runQuery: <Query extends FunctionReference<"query", "internal">>(
|
|
17
15
|
query: Query,
|
|
18
|
-
args: FunctionArgs<Query
|
|
16
|
+
args: FunctionArgs<Query>,
|
|
19
17
|
) => Promise<FunctionReturnType<Query>>;
|
|
20
18
|
};
|
|
21
19
|
export type RunMutationCtx = RunQueryCtx & {
|
|
22
20
|
runMutation: <Mutation extends FunctionReference<"mutation", "internal">>(
|
|
23
21
|
mutation: Mutation,
|
|
24
|
-
args: FunctionArgs<Mutation
|
|
22
|
+
args: FunctionArgs<Mutation>,
|
|
25
23
|
) => Promise<FunctionReturnType<Mutation>>;
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
export type OpaqueIds<T> =
|
|
29
|
-
T extends GenericId<string>
|
|
30
|
-
? string
|
|
31
|
-
: T extends (infer U)[]
|
|
32
|
-
? OpaqueIds<U>[]
|
|
33
|
-
: T extends Record<string, Value | undefined>
|
|
34
|
-
? { [K in keyof T]: OpaqueIds<T[K]> }
|
|
35
|
-
: T;
|
|
36
|
-
|
|
37
|
-
export type UseApi<API> = Expand<{
|
|
38
|
-
[mod in keyof API]: API[mod] extends FunctionReference<
|
|
39
|
-
infer FType,
|
|
40
|
-
"public",
|
|
41
|
-
infer FArgs,
|
|
42
|
-
infer FReturnType
|
|
43
|
-
>
|
|
44
|
-
? FunctionReference<
|
|
45
|
-
FType,
|
|
46
|
-
"internal",
|
|
47
|
-
OpaqueIds<FArgs>,
|
|
48
|
-
OpaqueIds<FReturnType>
|
|
49
|
-
>
|
|
50
|
-
: UseApi<API[mod]>;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
26
|
export function safeFunctionName(
|
|
54
|
-
f: FunctionReference<FunctionType, FunctionVisibility
|
|
27
|
+
f: FunctionReference<FunctionType, FunctionVisibility>,
|
|
55
28
|
) {
|
|
56
29
|
const address = getFunctionAddress(f);
|
|
57
30
|
return (
|
package/src/component/README.md
CHANGED
|
@@ -4,10 +4,10 @@ Concepts:
|
|
|
4
4
|
|
|
5
5
|
- `segment`: A slice of time to process work. All work is bucketed into one.
|
|
6
6
|
This enables us to batch work and avoid database conflicts.
|
|
7
|
-
- `generation`: A monotonically increasing counter to ensure the loop is
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
- `generation`: A monotonically increasing counter to ensure the loop is only
|
|
8
|
+
running one instance. If two loops start with the same generation, one will
|
|
9
|
+
successfully increase it, the other will retry and find that the generation
|
|
10
|
+
has changed and fail out.
|
|
11
11
|
- "Retention" is used to refer to situations where a query might have to read
|
|
12
12
|
over a lot of "tombstones" - deleted data that hasn't been vacuumed from the
|
|
13
13
|
underlying database yet. If there are frequent deletions, scanning across them
|
|
@@ -65,8 +65,8 @@ flowchart TD
|
|
|
65
65
|
- Producers (Client, Worker, Recovery) write to a future "segment".
|
|
66
66
|
- Consumers (main) read the current segment.
|
|
67
67
|
- On conflicts, producers will write to progressively higher segments, while
|
|
68
|
-
the main loop will continue to read the segment originally called with.
|
|
69
|
-
|
|
68
|
+
the main loop will continue to read the segment originally called with. This
|
|
69
|
+
means conflicts are less likely on each retry.
|
|
70
70
|
- Patch singletons to avoid tombstones.
|
|
71
71
|
- Use segements & cursors to bound reads to latest data.
|
|
72
72
|
- Do scans outside of the critical path (during load).
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
|
|
11
|
+
import type * as complete from "../complete.js";
|
|
12
|
+
import type * as crons from "../crons.js";
|
|
13
|
+
import type * as danger from "../danger.js";
|
|
14
|
+
import type * as kick from "../kick.js";
|
|
15
|
+
import type * as lib from "../lib.js";
|
|
16
|
+
import type * as logging from "../logging.js";
|
|
17
|
+
import type * as loop from "../loop.js";
|
|
18
|
+
import type * as recovery from "../recovery.js";
|
|
19
|
+
import type * as shared from "../shared.js";
|
|
20
|
+
import type * as stats from "../stats.js";
|
|
21
|
+
import type * as worker from "../worker.js";
|
|
22
|
+
|
|
23
|
+
import type {
|
|
24
|
+
ApiFromModules,
|
|
25
|
+
FilterApi,
|
|
26
|
+
FunctionReference,
|
|
27
|
+
} from "convex/server";
|
|
28
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
29
|
+
|
|
30
|
+
const fullApi: ApiFromModules<{
|
|
31
|
+
complete: typeof complete;
|
|
32
|
+
crons: typeof crons;
|
|
33
|
+
danger: typeof danger;
|
|
34
|
+
kick: typeof kick;
|
|
35
|
+
lib: typeof lib;
|
|
36
|
+
logging: typeof logging;
|
|
37
|
+
loop: typeof loop;
|
|
38
|
+
recovery: typeof recovery;
|
|
39
|
+
shared: typeof shared;
|
|
40
|
+
stats: typeof stats;
|
|
41
|
+
worker: typeof worker;
|
|
42
|
+
}> = anyApi as any;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
46
|
+
*
|
|
47
|
+
* Usage:
|
|
48
|
+
* ```js
|
|
49
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const api: FilterApi<
|
|
53
|
+
typeof fullApi,
|
|
54
|
+
FunctionReference<any, "public">
|
|
55
|
+
> = anyApi as any;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
59
|
+
*
|
|
60
|
+
* Usage:
|
|
61
|
+
* ```js
|
|
62
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export const internal: FilterApi<
|
|
66
|
+
typeof fullApi,
|
|
67
|
+
FunctionReference<any, "internal">
|
|
68
|
+
> = anyApi as any;
|
|
69
|
+
|
|
70
|
+
export const components = componentsGeneric() as unknown as {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `ComponentApi` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { FunctionReference } from "convex/server";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A utility for referencing a Convex component's exposed API.
|
|
15
|
+
*
|
|
16
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
20
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
25
|
+
{
|
|
26
|
+
lib: {
|
|
27
|
+
cancel: FunctionReference<
|
|
28
|
+
"mutation",
|
|
29
|
+
"internal",
|
|
30
|
+
{
|
|
31
|
+
id: string;
|
|
32
|
+
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
33
|
+
},
|
|
34
|
+
any,
|
|
35
|
+
Name
|
|
36
|
+
>;
|
|
37
|
+
cancelAll: FunctionReference<
|
|
38
|
+
"mutation",
|
|
39
|
+
"internal",
|
|
40
|
+
{
|
|
41
|
+
before?: number;
|
|
42
|
+
limit?: number;
|
|
43
|
+
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
44
|
+
},
|
|
45
|
+
any,
|
|
46
|
+
Name
|
|
47
|
+
>;
|
|
48
|
+
enqueue: FunctionReference<
|
|
49
|
+
"mutation",
|
|
50
|
+
"internal",
|
|
51
|
+
{
|
|
52
|
+
config: {
|
|
53
|
+
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
54
|
+
maxParallelism: number;
|
|
55
|
+
};
|
|
56
|
+
fnArgs: any;
|
|
57
|
+
fnHandle: string;
|
|
58
|
+
fnName: string;
|
|
59
|
+
fnType: "action" | "mutation" | "query";
|
|
60
|
+
onComplete?: { context?: any; fnHandle: string };
|
|
61
|
+
retryBehavior?: {
|
|
62
|
+
base: number;
|
|
63
|
+
initialBackoffMs: number;
|
|
64
|
+
maxAttempts: number;
|
|
65
|
+
};
|
|
66
|
+
runAt: number;
|
|
67
|
+
},
|
|
68
|
+
string,
|
|
69
|
+
Name
|
|
70
|
+
>;
|
|
71
|
+
enqueueBatch: FunctionReference<
|
|
72
|
+
"mutation",
|
|
73
|
+
"internal",
|
|
74
|
+
{
|
|
75
|
+
config: {
|
|
76
|
+
logLevel: "DEBUG" | "TRACE" | "INFO" | "REPORT" | "WARN" | "ERROR";
|
|
77
|
+
maxParallelism: number;
|
|
78
|
+
};
|
|
79
|
+
items: Array<{
|
|
80
|
+
fnArgs: any;
|
|
81
|
+
fnHandle: string;
|
|
82
|
+
fnName: string;
|
|
83
|
+
fnType: "action" | "mutation" | "query";
|
|
84
|
+
onComplete?: { context?: any; fnHandle: string };
|
|
85
|
+
retryBehavior?: {
|
|
86
|
+
base: number;
|
|
87
|
+
initialBackoffMs: number;
|
|
88
|
+
maxAttempts: number;
|
|
89
|
+
};
|
|
90
|
+
runAt: number;
|
|
91
|
+
}>;
|
|
92
|
+
},
|
|
93
|
+
Array<string>,
|
|
94
|
+
Name
|
|
95
|
+
>;
|
|
96
|
+
status: FunctionReference<
|
|
97
|
+
"query",
|
|
98
|
+
"internal",
|
|
99
|
+
{ id: string },
|
|
100
|
+
| { previousAttempts: number; state: "pending" }
|
|
101
|
+
| { previousAttempts: number; state: "running" }
|
|
102
|
+
| { state: "finished" },
|
|
103
|
+
Name
|
|
104
|
+
>;
|
|
105
|
+
statusBatch: FunctionReference<
|
|
106
|
+
"query",
|
|
107
|
+
"internal",
|
|
108
|
+
{ ids: Array<string> },
|
|
109
|
+
Array<
|
|
110
|
+
| { previousAttempts: number; state: "pending" }
|
|
111
|
+
| { previousAttempts: number; state: "running" }
|
|
112
|
+
| { state: "finished" }
|
|
113
|
+
>,
|
|
114
|
+
Name
|
|
115
|
+
>;
|
|
116
|
+
};
|
|
117
|
+
};
|