@convex-dev/crons 0.1.9 → 0.2.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 (97) hide show
  1. package/README.md +18 -16
  2. package/dist/{commonjs/client → client}/index.d.ts +5 -5
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js.map +1 -0
  5. package/dist/client/utils.d.ts +8 -0
  6. package/dist/client/utils.d.ts.map +1 -0
  7. package/dist/client/utils.js +2 -0
  8. package/dist/{commonjs/client → client}/utils.js.map +1 -1
  9. package/dist/component/_generated/api.d.ts +34 -0
  10. package/dist/component/_generated/api.d.ts.map +1 -0
  11. package/{src → dist}/component/_generated/api.js +11 -7
  12. package/dist/component/_generated/api.js.map +1 -0
  13. package/dist/component/_generated/component.d.ts +79 -0
  14. package/dist/component/_generated/component.d.ts.map +1 -0
  15. package/dist/component/_generated/component.js +11 -0
  16. package/dist/component/_generated/component.js.map +1 -0
  17. package/dist/component/_generated/dataModel.d.ts +46 -0
  18. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  19. package/dist/component/_generated/dataModel.js +11 -0
  20. package/dist/component/_generated/dataModel.js.map +1 -0
  21. package/{src → dist}/component/_generated/server.d.ts +10 -42
  22. package/dist/component/_generated/server.d.ts.map +1 -0
  23. package/dist/{commonjs/component → component}/_generated/server.js +9 -7
  24. package/dist/component/_generated/server.js.map +1 -0
  25. package/dist/component/convex.config.d.ts.map +1 -0
  26. package/dist/component/convex.config.js.map +1 -0
  27. package/dist/{commonjs/component → component}/public.d.ts +2 -2
  28. package/dist/component/public.d.ts.map +1 -0
  29. package/dist/component/public.js.map +1 -0
  30. package/dist/{commonjs/component → component}/schema.d.ts +2 -2
  31. package/dist/component/schema.d.ts.map +1 -0
  32. package/dist/{commonjs/component → component}/schema.js +3 -3
  33. package/dist/component/schema.js.map +1 -0
  34. package/package.json +56 -37
  35. package/src/client/index.ts +10 -10
  36. package/src/client/utils.ts +0 -32
  37. package/src/component/_generated/api.ts +50 -0
  38. package/src/component/_generated/component.ts +79 -0
  39. package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -4
  40. package/src/component/_generated/server.ts +161 -0
  41. package/src/component/public.ts +11 -11
  42. package/src/component/schema.ts +1 -1
  43. package/src/test.ts +18 -0
  44. package/dist/commonjs/client/index.d.ts.map +0 -1
  45. package/dist/commonjs/client/index.js.map +0 -1
  46. package/dist/commonjs/client/utils.d.ts +0 -15
  47. package/dist/commonjs/client/utils.d.ts.map +0 -1
  48. package/dist/commonjs/client/utils.js +0 -3
  49. package/dist/commonjs/component/_generated/api.d.ts +0 -12
  50. package/dist/commonjs/component/_generated/api.d.ts.map +0 -1
  51. package/dist/commonjs/component/_generated/api.js +0 -24
  52. package/dist/commonjs/component/_generated/api.js.map +0 -1
  53. package/dist/commonjs/component/_generated/server.d.ts +0 -64
  54. package/dist/commonjs/component/_generated/server.d.ts.map +0 -1
  55. package/dist/commonjs/component/_generated/server.js.map +0 -1
  56. package/dist/commonjs/component/convex.config.d.ts.map +0 -1
  57. package/dist/commonjs/component/convex.config.js.map +0 -1
  58. package/dist/commonjs/component/public.d.ts.map +0 -1
  59. package/dist/commonjs/component/public.js.map +0 -1
  60. package/dist/commonjs/component/schema.d.ts.map +0 -1
  61. package/dist/commonjs/component/schema.js.map +0 -1
  62. package/dist/commonjs/package.json +0 -3
  63. package/dist/esm/client/index.d.ts +0 -89
  64. package/dist/esm/client/index.d.ts.map +0 -1
  65. package/dist/esm/client/index.js +0 -104
  66. package/dist/esm/client/index.js.map +0 -1
  67. package/dist/esm/client/utils.d.ts +0 -15
  68. package/dist/esm/client/utils.d.ts.map +0 -1
  69. package/dist/esm/client/utils.js +0 -3
  70. package/dist/esm/client/utils.js.map +0 -1
  71. package/dist/esm/component/_generated/api.d.ts +0 -12
  72. package/dist/esm/component/_generated/api.d.ts.map +0 -1
  73. package/dist/esm/component/_generated/api.js +0 -24
  74. package/dist/esm/component/_generated/api.js.map +0 -1
  75. package/dist/esm/component/_generated/server.d.ts +0 -64
  76. package/dist/esm/component/_generated/server.d.ts.map +0 -1
  77. package/dist/esm/component/_generated/server.js +0 -76
  78. package/dist/esm/component/_generated/server.js.map +0 -1
  79. package/dist/esm/component/convex.config.d.ts +0 -3
  80. package/dist/esm/component/convex.config.d.ts.map +0 -1
  81. package/dist/esm/component/convex.config.js +0 -3
  82. package/dist/esm/component/convex.config.js.map +0 -1
  83. package/dist/esm/component/public.d.ts +0 -119
  84. package/dist/esm/component/public.d.ts.map +0 -1
  85. package/dist/esm/component/public.js +0 -226
  86. package/dist/esm/component/public.js.map +0 -1
  87. package/dist/esm/component/schema.d.ts +0 -49
  88. package/dist/esm/component/schema.d.ts.map +0 -1
  89. package/dist/esm/component/schema.js +0 -21
  90. package/dist/esm/component/schema.js.map +0 -1
  91. package/dist/esm/package.json +0 -3
  92. package/src/component/_generated/api.d.ts +0 -98
  93. package/src/component/_generated/server.js +0 -94
  94. /package/dist/{commonjs/client → client}/index.js +0 -0
  95. /package/dist/{commonjs/component → component}/convex.config.d.ts +0 -0
  96. /package/dist/{commonjs/component → component}/convex.config.js +0 -0
  97. /package/dist/{commonjs/component → component}/public.js +0 -0
@@ -3,8 +3,8 @@ declare const _default: import("convex/server").SchemaDefinition<{
3
3
  name?: string | undefined;
4
4
  schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
5
5
  executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
6
- functionHandle: string;
7
6
  args: Record<string, any>;
7
+ functionHandle: string;
8
8
  schedule: {
9
9
  kind: "interval";
10
10
  ms: number;
@@ -41,7 +41,7 @@ declare const _default: import("convex/server").SchemaDefinition<{
41
41
  }, "required", "kind" | "cronspec" | "tz">], "required", "kind" | "ms" | "cronspec" | "tz">;
42
42
  schedulerJobId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions"> | undefined, "optional">;
43
43
  executionJobId: import("convex/values").VId<import("convex/values").GenericId<"_scheduled_functions"> | undefined, "optional">;
44
- }, "required", "name" | "functionHandle" | "args" | "schedule" | "schedulerJobId" | "executionJobId" | `args.${string}` | "schedule.kind" | "schedule.ms" | "schedule.cronspec" | "schedule.tz">, {
44
+ }, "required", "args" | "functionHandle" | "name" | "schedule" | "schedulerJobId" | "executionJobId" | `args.${string}` | "schedule.kind" | "schedule.ms" | "schedule.cronspec" | "schedule.tz">, {
45
45
  name: ["name", "_creationTime"];
46
46
  }, {}, {}>;
47
47
  }, true>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,wBAoBG"}
@@ -3,7 +3,7 @@ import { v } from "convex/values";
3
3
  export default defineSchema({
4
4
  // User space crons.
5
5
  crons: defineTable({
6
- name: v.optional(v.string()),
6
+ name: v.optional(v.string()), // optional
7
7
  functionHandle: v.string(),
8
8
  args: v.record(v.string(), v.any()),
9
9
  schedule: v.union(v.object({
@@ -11,10 +11,10 @@ export default defineSchema({
11
11
  ms: v.float64(), // milliseconds
12
12
  }), v.object({
13
13
  kind: v.literal("cron"),
14
- cronspec: v.string(),
14
+ cronspec: v.string(), // "* * * * *"
15
15
  tz: v.optional(v.string()), // optional timezone, e.g. "America/New_York"
16
16
  })),
17
- schedulerJobId: v.optional(v.id("_scheduled_functions")),
17
+ schedulerJobId: v.optional(v.id("_scheduled_functions")), // job to wait for the next execution
18
18
  executionJobId: v.optional(v.id("_scheduled_functions")), // async job to run the function
19
19
  }).index("name", ["name"]),
20
20
  });
@@ -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,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC,eAAe,YAAY,CAAC;IAC1B,oBAAoB;IACpB,KAAK,EAAE,WAAW,CAAC;QACjB,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW;QACzC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE;QAC1B,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC;QACnC,QAAQ,EAAE,CAAC,CAAC,KAAK,CACf,CAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;YAC3B,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,eAAe;SACjC,CAAC,EACF,CAAC,CAAC,MAAM,CAAC;YACP,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;YACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,cAAc;YACpC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,6CAA6C;SAC1E,CAAC,CACH;QACD,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,EAAE,qCAAqC;QAC/F,cAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,EAAE,gCAAgC;KAC3F,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;CAC3B,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convex-dev/crons",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "Convex component for scheduling periodic jobs.",
5
5
  "keywords": [
6
6
  "convex",
@@ -17,56 +17,75 @@
17
17
  "repository": "github:get-convex/crons",
18
18
  "license": "Apache-2.0",
19
19
  "type": "module",
20
- "exports": {
21
- "./package.json": "./package.json",
22
- ".": {
23
- "import": {
24
- "@convex-dev/component-source": "./src/client/index.ts",
25
- "types": "./dist/esm/client/index.d.ts",
26
- "default": "./dist/esm/client/index.js"
27
- },
28
- "require": {
29
- "@convex-dev/component-source": "./src/client/index.ts",
30
- "types": "./dist/commonjs/client/index.d.ts",
31
- "default": "./dist/commonjs/client/index.js"
32
- }
33
- },
34
- "./convex.config": {
35
- "import": {
36
- "@convex-dev/component-source": "./src/component/convex.config.ts",
37
- "types": "./dist/esm/component/convex.config.d.ts",
38
- "default": "./dist/esm/component/convex.config.js"
39
- }
40
- }
41
- },
42
- "main": "./dist/commonjs/client/index.js",
43
- "module": "./dist/esm/client/index.js",
44
- "types": "./dist/commonjs/client/index.d.ts",
45
20
  "files": [
46
21
  "dist",
47
22
  "src"
48
23
  ],
49
24
  "scripts": {
50
- "build": "npm run build:esm && npm run build:cjs",
51
- "build:cjs": "tsc --project ./commonjs.json && echo '{\\n \"type\": \"commonjs\"\\n}' > dist/commonjs/package.json",
52
- "build:esm": "tsc --project ./esm.json && echo '{\\n \"type\": \"module\"\\n}' > dist/esm/package.json",
53
- "lint": "eslint --ext .ts src",
25
+ "dev": "run-p -r 'dev:*'",
26
+ "dev:backend": "convex dev --typecheck-components",
27
+ "dev:frontend": "cd example && vite --clearScreen false",
28
+ "dev:build": "chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'convex codegen --component-dir ./src/component && npm run build' --initial",
29
+ "predev": "npm run dev:backend -- --until-success",
30
+ "clean": "rm -rf dist *.tsbuildinfo",
31
+ "build": "tsc --project ./tsconfig.build.json",
32
+ "typecheck": "tsc --noEmit && tsc -p example/convex",
33
+ "lint": "eslint .",
34
+ "all": "run-p -r 'dev:*' 'test:watch'",
35
+ "test": "vitest run --typecheck",
36
+ "test:watch": "vitest --typecheck --clearScreen false",
37
+ "test:debug": "vitest --inspect-brk --no-file-parallelism",
38
+ "test:coverage": "vitest run --coverage --coverage.reporter=text",
54
39
  "prepare": "npm run build",
55
- "typecheck": "tsc --noEmit"
40
+ "alpha": "npm run clean && npm ci && run-p test lint typecheck && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
41
+ "release": "npm run clean && npm ci && run-p test lint typecheck && npm version patch && npm publish && git push --tags",
42
+ "version": "pbcopy <<<$npm_package_version; vim CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
43
+ },
44
+ "exports": {
45
+ "./package.json": "./package.json",
46
+ ".": {
47
+ "types": "./dist/client/index.d.ts",
48
+ "default": "./dist/client/index.js"
49
+ },
50
+ "./test": "./src/test.ts",
51
+ "./_generated/component.js": {
52
+ "types": "./dist/component/_generated/component.d.ts"
53
+ },
54
+ "./convex.config": {
55
+ "types": "./dist/component/convex.config.d.ts",
56
+ "default": "./dist/component/convex.config.js"
57
+ },
58
+ "./convex.config.js": {
59
+ "types": "./dist/component/convex.config.d.ts",
60
+ "default": "./dist/component/convex.config.js"
61
+ }
56
62
  },
63
+ "module": "./dist/client/index.js",
64
+ "types": "./dist/client/index.d.ts",
57
65
  "dependencies": {
58
66
  "cron-parser": "^4.9.0"
59
67
  },
68
+ "peerDependencies": {
69
+ "convex": "^1.24.8"
70
+ },
60
71
  "devDependencies": {
72
+ "@arethetypeswrong/cli": "0.18.2",
73
+ "@edge-runtime/vm": "5.0.0",
74
+ "@eslint/eslintrc": "^3.1.0",
61
75
  "@eslint/js": "^9.28.0",
62
- "@types/node": "^18.17.0",
76
+ "@types/node": "20.19.24",
77
+ "@typescript-eslint/eslint-plugin": "^8.4.0",
78
+ "@typescript-eslint/parser": "^8.4.0",
79
+ "chokidar-cli": "3.0.0",
80
+ "convex-test": "^0.0.38",
63
81
  "eslint": "^9.28.0",
82
+ "eslint-plugin-react-hooks": "^7.0.1",
83
+ "eslint-plugin-react-refresh": "^0.4.24",
64
84
  "globals": "^16.2.0",
85
+ "npm-run-all2": "8.0.4",
65
86
  "prettier": "3.2.5",
66
- "typescript": "~5.0.3",
67
- "typescript-eslint": "^8.33.1"
68
- },
69
- "peerDependencies": {
70
- "convex": "~1.16.5 || >=1.17.0 <1.35.0"
87
+ "typescript": "^5.5.0",
88
+ "typescript-eslint": "^8.33.1",
89
+ "vitest": "^3.2.4"
71
90
  }
72
91
  }
@@ -2,13 +2,13 @@
2
2
 
3
3
  import {
4
4
  createFunctionHandle,
5
- FunctionArgs,
6
- FunctionHandle,
7
- SchedulableFunctionReference,
5
+ type FunctionArgs,
6
+ type FunctionHandle,
7
+ type SchedulableFunctionReference,
8
8
  } from "convex/server";
9
- import { api } from "../component/_generated/api.js";
10
- import { CronInfo, Schedule } from "../component/public.js";
11
- import { RunMutationCtx, RunQueryCtx, UseApi } from "./utils.js";
9
+ import type { ComponentApi } from "../component/_generated/component.js";
10
+ import type { CronInfo, Schedule } from "../component/public.js";
11
+ import type { RunMutationCtx, RunQueryCtx } from "./utils.js";
12
12
 
13
13
  export type { CronInfo };
14
14
 
@@ -52,7 +52,7 @@ export class Crons {
52
52
  * }
53
53
  * ```
54
54
  */
55
- constructor(private component: UseApi<typeof api>) {}
55
+ constructor(private component: ComponentApi) {}
56
56
 
57
57
  /**
58
58
  * Schedule a mutation or action to run on a cron schedule or interval.
@@ -71,7 +71,7 @@ export class Crons {
71
71
  schedule: Schedule,
72
72
  func: F,
73
73
  args: FunctionArgs<F>,
74
- name?: string
74
+ name?: string,
75
75
  ): Promise<string> {
76
76
  return ctx.runMutation(this.component.public.register, {
77
77
  name,
@@ -104,7 +104,7 @@ export class Crons {
104
104
  */
105
105
  async get(
106
106
  ctx: RunQueryCtx,
107
- identifier: { id: string } | { name: string }
107
+ identifier: { id: string } | { name: string },
108
108
  ): Promise<CronInfo | null> {
109
109
  const cron = await ctx.runQuery(this.component.public.get, { identifier });
110
110
  if (cron === null) {
@@ -125,7 +125,7 @@ export class Crons {
125
125
  */
126
126
  async delete(
127
127
  ctx: RunMutationCtx,
128
- identifier: { id: string } | { name: string }
128
+ identifier: { id: string } | { name: string },
129
129
  ): Promise<null> {
130
130
  return ctx.runMutation(this.component.public.del, { identifier });
131
131
  }
@@ -1,13 +1,8 @@
1
- // Type utilities for component clients.
2
-
3
1
  import type {
4
- Expand,
5
- FunctionReference,
6
2
  GenericDataModel,
7
3
  GenericMutationCtx,
8
4
  GenericQueryCtx,
9
5
  } from "convex/server";
10
- import type { GenericId } from "convex/values";
11
6
 
12
7
  export type RunQueryCtx = {
13
8
  runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
@@ -15,30 +10,3 @@ export type RunQueryCtx = {
15
10
  export type RunMutationCtx = {
16
11
  runMutation: GenericMutationCtx<GenericDataModel>["runMutation"];
17
12
  };
18
-
19
- export type OpaqueIds<T> =
20
- T extends GenericId<infer _T>
21
- ? string
22
- : T extends (infer U)[]
23
- ? OpaqueIds<U>[]
24
- : T extends object
25
- ? { [K in keyof T]: OpaqueIds<T[K]> }
26
- : T;
27
-
28
- export type UseApi<API> = Expand<{
29
- [mod in keyof API]: API[mod] extends FunctionReference<
30
- infer FType,
31
- "public",
32
- infer FArgs,
33
- infer FReturnType,
34
- infer FComponentPath
35
- >
36
- ? FunctionReference<
37
- FType,
38
- "internal",
39
- OpaqueIds<FArgs>,
40
- OpaqueIds<FReturnType>,
41
- FComponentPath
42
- >
43
- : UseApi<API[mod]>;
44
- }>;
@@ -0,0 +1,50 @@
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 public_ from "../public.js";
12
+
13
+ import type {
14
+ ApiFromModules,
15
+ FilterApi,
16
+ FunctionReference,
17
+ } from "convex/server";
18
+ import { anyApi, componentsGeneric } from "convex/server";
19
+
20
+ const fullApi: ApiFromModules<{
21
+ public: typeof public_;
22
+ }> = anyApi as any;
23
+
24
+ /**
25
+ * A utility for referencing Convex functions in your app's public API.
26
+ *
27
+ * Usage:
28
+ * ```js
29
+ * const myFunctionReference = api.myModule.myFunction;
30
+ * ```
31
+ */
32
+ export const api: FilterApi<
33
+ typeof fullApi,
34
+ FunctionReference<any, "public">
35
+ > = anyApi as any;
36
+
37
+ /**
38
+ * A utility for referencing Convex functions in your app's internal API.
39
+ *
40
+ * Usage:
41
+ * ```js
42
+ * const myFunctionReference = internal.myModule.myFunction;
43
+ * ```
44
+ */
45
+ export const internal: FilterApi<
46
+ typeof fullApi,
47
+ FunctionReference<any, "internal">
48
+ > = anyApi as any;
49
+
50
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,79 @@
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
+ public: {
27
+ del: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ { identifier: { id: string } | { name: string } },
31
+ null,
32
+ Name
33
+ >;
34
+ get: FunctionReference<
35
+ "query",
36
+ "internal",
37
+ { identifier: { id: string } | { name: string } },
38
+ {
39
+ args: Record<string, any>;
40
+ functionHandle: string;
41
+ id: string;
42
+ name?: string;
43
+ schedule:
44
+ | { kind: "interval"; ms: number }
45
+ | { cronspec: string; kind: "cron"; tz?: string };
46
+ } | null,
47
+ Name
48
+ >;
49
+ list: FunctionReference<
50
+ "query",
51
+ "internal",
52
+ {},
53
+ Array<{
54
+ args: Record<string, any>;
55
+ functionHandle: string;
56
+ id: string;
57
+ name?: string;
58
+ schedule:
59
+ | { kind: "interval"; ms: number }
60
+ | { cronspec: string; kind: "cron"; tz?: string };
61
+ }>,
62
+ Name
63
+ >;
64
+ register: FunctionReference<
65
+ "mutation",
66
+ "internal",
67
+ {
68
+ args: Record<string, any>;
69
+ functionHandle: string;
70
+ name?: string;
71
+ schedule:
72
+ | { kind: "interval"; ms: number }
73
+ | { cronspec: string; kind: "cron"; tz?: string };
74
+ },
75
+ string,
76
+ Name
77
+ >;
78
+ };
79
+ };
@@ -1,5 +1,3 @@
1
- /* prettier-ignore-start */
2
-
3
1
  /* eslint-disable */
4
2
  /**
5
3
  * Generated data model types.
@@ -60,5 +58,3 @@ export type Id<TableName extends TableNames | SystemTableNames> =
60
58
  * `mutationGeneric` to make them type-safe.
61
59
  */
62
60
  export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
63
-
64
- /* prettier-ignore-end */
@@ -0,0 +1,161 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ ActionBuilder,
13
+ HttpActionBuilder,
14
+ MutationBuilder,
15
+ QueryBuilder,
16
+ GenericActionCtx,
17
+ GenericMutationCtx,
18
+ GenericQueryCtx,
19
+ GenericDatabaseReader,
20
+ GenericDatabaseWriter,
21
+ } from "convex/server";
22
+ import {
23
+ actionGeneric,
24
+ httpActionGeneric,
25
+ queryGeneric,
26
+ mutationGeneric,
27
+ internalActionGeneric,
28
+ internalMutationGeneric,
29
+ internalQueryGeneric,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Define a query in this Convex app's public API.
35
+ *
36
+ * This function will be allowed to read your Convex database and will be accessible from the client.
37
+ *
38
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
39
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
40
+ */
41
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
42
+
43
+ /**
44
+ * Define a query that is only accessible from other Convex functions (but not from the client).
45
+ *
46
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
47
+ *
48
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
49
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
50
+ */
51
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
52
+ internalQueryGeneric;
53
+
54
+ /**
55
+ * Define a mutation in this Convex app's public API.
56
+ *
57
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
58
+ *
59
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
60
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
63
+
64
+ /**
65
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
66
+ *
67
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
68
+ *
69
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
70
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
71
+ */
72
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
73
+ internalMutationGeneric;
74
+
75
+ /**
76
+ * Define an action in this Convex app's public API.
77
+ *
78
+ * An action is a function which can execute any JavaScript code, including non-deterministic
79
+ * code and code with side-effects, like calling third-party services.
80
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
81
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
82
+ *
83
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
84
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
85
+ */
86
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
87
+
88
+ /**
89
+ * Define an action that is only accessible from other Convex functions (but not from the client).
90
+ *
91
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
92
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
93
+ */
94
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
95
+ internalActionGeneric;
96
+
97
+ /**
98
+ * Define an HTTP action.
99
+ *
100
+ * The wrapped function will be used to respond to HTTP requests received
101
+ * by a Convex deployment if the requests matches the path and method where
102
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
103
+ *
104
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
105
+ * and a Fetch API `Request` object as its second.
106
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
107
+ */
108
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
109
+
110
+ type GenericCtx =
111
+ | GenericActionCtx<DataModel>
112
+ | GenericMutationCtx<DataModel>
113
+ | GenericQueryCtx<DataModel>;
114
+
115
+ /**
116
+ * A set of services for use within Convex query functions.
117
+ *
118
+ * The query context is passed as the first argument to any Convex query
119
+ * function run on the server.
120
+ *
121
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
122
+ */
123
+ export type QueryCtx = GenericQueryCtx<DataModel>;
124
+
125
+ /**
126
+ * A set of services for use within Convex mutation functions.
127
+ *
128
+ * The mutation context is passed as the first argument to any Convex mutation
129
+ * function run on the server.
130
+ *
131
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
132
+ */
133
+ export type MutationCtx = GenericMutationCtx<DataModel>;
134
+
135
+ /**
136
+ * A set of services for use within Convex action functions.
137
+ *
138
+ * The action context is passed as the first argument to any Convex action
139
+ * function run on the server.
140
+ */
141
+ export type ActionCtx = GenericActionCtx<DataModel>;
142
+
143
+ /**
144
+ * An interface to read from the database within Convex query functions.
145
+ *
146
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
147
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
148
+ * building a query.
149
+ */
150
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
151
+
152
+ /**
153
+ * An interface to read from and write to the database within Convex mutation
154
+ * functions.
155
+ *
156
+ * Convex guarantees that all writes within a single mutation are
157
+ * executed atomically, so you never have to worry about partial writes leaving
158
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
159
+ * for the guarantees Convex provides your functions.
160
+ */
161
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -2,16 +2,16 @@
2
2
  //
3
3
  // See ../client/index.ts for the public API.
4
4
 
5
- import { FunctionHandle } from "convex/server";
5
+ import type { FunctionHandle } from "convex/server";
6
6
  import { v } from "convex/values";
7
7
  import {
8
- MutationCtx,
8
+ type MutationCtx,
9
9
  mutation,
10
10
  query,
11
11
  internalMutation,
12
12
  } from "./_generated/server.js";
13
13
  import { internal } from "./_generated/api.js";
14
- import { Doc, Id } from "./_generated/dataModel.js";
14
+ import type { Doc, Id } from "./_generated/dataModel.js";
15
15
  import parser from "cron-parser";
16
16
  import schema from "./schema.js";
17
17
 
@@ -99,7 +99,7 @@ export const register = mutation({
99
99
  schedule,
100
100
  });
101
101
  console.log(
102
- `Scheduling cron "${name}" (${id}) on schedule ${JSON.stringify(schedule)}`
102
+ `Scheduling cron "${name}" (${id}) on schedule ${JSON.stringify(schedule)}`,
103
103
  );
104
104
 
105
105
  await scheduleNextRun(ctx, id, new Date(), schedule);
@@ -124,13 +124,13 @@ async function scheduleNextRun(
124
124
  ctx: MutationCtx,
125
125
  id: Id<"crons">,
126
126
  lastScheduled: Date,
127
- schedule: Schedule
127
+ schedule: Schedule,
128
128
  ) {
129
129
  const nextRun = calculateNextRun(lastScheduled, schedule);
130
130
  const schedulerJobId = await ctx.scheduler.runAt(
131
131
  nextRun,
132
132
  internal.public.rescheduler,
133
- { id }
133
+ { id },
134
134
  );
135
135
  await ctx.db.patch(id, { schedulerJobId });
136
136
  }
@@ -177,7 +177,7 @@ export const get = query({
177
177
  args: {
178
178
  identifier: v.union(
179
179
  v.object({ id: v.id("crons") }),
180
- v.object({ name: v.string() })
180
+ v.object({ name: v.string() }),
181
181
  ),
182
182
  },
183
183
  returns: v.union(cronInfoValidator, v.null()),
@@ -209,7 +209,7 @@ export const del = mutation({
209
209
  args: {
210
210
  identifier: v.union(
211
211
  v.object({ id: v.id("crons") }),
212
- v.object({ name: v.string() })
212
+ v.object({ name: v.string() }),
213
213
  ),
214
214
  },
215
215
  returns: v.null(),
@@ -276,7 +276,7 @@ export const rescheduler = internalMutation({
276
276
  schedulerJob.state.kind !== "inProgress"
277
277
  ) {
278
278
  throw Error(
279
- `We are running in job ${schedulerJob._id} but state is ${schedulerJob.state.kind}`
279
+ `We are running in job ${schedulerJob._id} but state is ${schedulerJob.state.kind}`,
280
280
  );
281
281
  }
282
282
 
@@ -299,7 +299,7 @@ export const rescheduler = internalMutation({
299
299
  await ctx.scheduler.runAfter(
300
300
  0,
301
301
  cronJob.functionHandle as FunctionHandle<"mutation" | "action">,
302
- cronJob.args
302
+ cronJob.args,
303
303
  );
304
304
  }
305
305
 
@@ -307,7 +307,7 @@ export const rescheduler = internalMutation({
307
307
  ctx,
308
308
  id,
309
309
  new Date(schedulerJob.scheduledTime),
310
- cronJob.schedule
310
+ cronJob.schedule,
311
311
  );
312
312
  },
313
313
  });
@@ -16,7 +16,7 @@ export default defineSchema({
16
16
  kind: v.literal("cron"),
17
17
  cronspec: v.string(), // "* * * * *"
18
18
  tz: v.optional(v.string()), // optional timezone, e.g. "America/New_York"
19
- })
19
+ }),
20
20
  ),
21
21
  schedulerJobId: v.optional(v.id("_scheduled_functions")), // job to wait for the next execution
22
22
  executionJobId: v.optional(v.id("_scheduled_functions")), // async job to run the function