@convex-dev/crons 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +18 -1
  2. package/dist/commonjs/client/index.d.ts +1 -1
  3. package/dist/commonjs/client/index.d.ts.map +1 -1
  4. package/dist/commonjs/client/index.js +1 -1
  5. package/dist/commonjs/client/index.js.map +1 -1
  6. package/dist/commonjs/client/utils.d.ts +2 -2
  7. package/dist/commonjs/client/utils.d.ts.map +1 -1
  8. package/dist/esm/client/index.d.ts +1 -1
  9. package/dist/esm/client/index.d.ts.map +1 -1
  10. package/dist/esm/client/index.js +1 -1
  11. package/dist/esm/client/index.js.map +1 -1
  12. package/dist/esm/client/utils.d.ts +2 -2
  13. package/dist/esm/client/utils.d.ts.map +1 -1
  14. package/package.json +4 -2
  15. package/src/client/index.ts +1 -1
  16. package/src/client/utils.ts +2 -2
  17. package/dist/commonjs/component/index.d.ts +0 -135
  18. package/dist/commonjs/component/index.d.ts.map +0 -1
  19. package/dist/commonjs/component/index.js +0 -289
  20. package/dist/commonjs/component/index.js.map +0 -1
  21. package/dist/commonjs/component/parseArgs.d.ts +0 -11
  22. package/dist/commonjs/component/parseArgs.d.ts.map +0 -1
  23. package/dist/commonjs/component/parseArgs.js +0 -28
  24. package/dist/commonjs/component/parseArgs.js.map +0 -1
  25. package/dist/commonjs/frontend/index.d.ts +0 -2
  26. package/dist/commonjs/frontend/index.d.ts.map +0 -1
  27. package/dist/commonjs/frontend/index.js +0 -8
  28. package/dist/commonjs/frontend/index.js.map +0 -1
  29. package/dist/esm/component/index.d.ts +0 -135
  30. package/dist/esm/component/index.d.ts.map +0 -1
  31. package/dist/esm/component/index.js +0 -289
  32. package/dist/esm/component/index.js.map +0 -1
  33. package/dist/esm/component/parseArgs.d.ts +0 -11
  34. package/dist/esm/component/parseArgs.d.ts.map +0 -1
  35. package/dist/esm/component/parseArgs.js +0 -28
  36. package/dist/esm/component/parseArgs.js.map +0 -1
  37. package/dist/esm/frontend/index.d.ts +0 -2
  38. package/dist/esm/frontend/index.d.ts.map +0 -1
  39. package/dist/esm/frontend/index.js +0 -8
  40. package/dist/esm/frontend/index.js.map +0 -1
package/README.md CHANGED
@@ -20,13 +20,28 @@ the unix `cron` command:
20
20
  └───────────────── second (0 - 59, optional)
21
21
  ```
22
22
 
23
+ ## Installation
24
+
25
+ Most developers will want to install this via an npm package:
26
+
27
+ ```bash
28
+ npm install @convex-dev/crons
29
+ ```
30
+
31
+ ## Usage
32
+
23
33
  See `example/convex/example.ts` for a simple example of how to use this library.
24
34
 
25
35
  The component must first be defined in convex.config.ts:
26
36
 
27
37
  ```typescript
38
+ import { defineApp } from "convex/server";
39
+ import crons from "@convex-dev/crons/convex.config.js";
40
+
28
41
  const app = defineApp();
29
- app.use(component, { name: "crons" });
42
+ app.use(crons, { name: "crons" });
43
+
44
+ export default app;
30
45
  ```
31
46
 
32
47
  and can then be used from Convex functions via the `Crons` wrapper class:
@@ -52,5 +67,7 @@ Convex feature you can do so via an init script that idempotently registers a
52
67
  cron with a given name. e.g., in an `init.ts` file that gets run on every
53
68
  deploy via `convex dev --run init`.
54
69
 
70
+ ## Design
71
+
55
72
  The design of this component is based on the Cronvex demo app that's described in
56
73
  [this Stack post](https://stack.convex.dev/cron-jobs).
@@ -41,7 +41,7 @@ export declare class Crons {
41
41
  *
42
42
  * @param identifier - Either the ID or name of the cron job.
43
43
  */
44
- del(ctx: RunMutationCtx, identifier: {
44
+ delete(ctx: RunMutationCtx, identifier: {
45
45
  id: string;
46
46
  } | {
47
47
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAEZ,4BAA4B,EAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,QA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,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEjE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAqCzB,qBAAa,KAAK;IACJ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC;IAEjD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,CAAC,SAAS,4BAA4B,EACnD,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC;IASlB;;;;OAIG;IACG,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUjD;;;;;OAKG;IACG,GAAG,CACP,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAa3B;;;;OAIG;IACG,MAAM,CACV,GAAG,EAAE,cAAc,EACnB,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,IAAI,CAAC;CAGjB"}
@@ -92,7 +92,7 @@ export class Crons {
92
92
  *
93
93
  * @param identifier - Either the ID or name of the cron job.
94
94
  */
95
- async del(ctx, identifier) {
95
+ async delete(ctx, identifier) {
96
96
  return ctx.runMutation(this.component.public.del, { identifier });
97
97
  }
98
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EACL,oBAAoB,GAIrB,MAAM,eAAe,CAAC;AAOvB,2EAA2E;AAE3E,yCAAyC;AACzC,EAA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AAmB,EACnB,QAAkB,EAClB,IAAO,EACP,IAAqB,EACrB,IAAa;QAEb,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,IAAI;YACJ,QAAQ;YACR,cAAc,EAAE,MAAM,oBAAoB,CAAC,IAAI,CAAC;YAChD,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,GAAgB;QACzB,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,GAAG,IAAI;YACP,cAAc,EAAE,IAAI,CAAC,cAEpB;SACF,CAAC,CAAC,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,GAAgB,EAChB,UAA6C;QAE7C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3E,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,OAAO,IAAI,CAAC;SACb;QACD,OAAO;YACL,GAAG,IAAI;YACP,cAAc,EAAE,IAAI,CAAC,cAEpB;SACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,GAAmB,EACnB,UAA6C;QAE7C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
- import { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
2
- import { GenericId } from "convex/values";
1
+ import type { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
2
+ import type { GenericId } from "convex/values";
3
3
  export type RunQueryCtx = {
4
4
  runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/client/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;CACzD,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,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,SA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,GAAG,CAAC,CAAC;CACrB,CAAC,CAAC"}
@@ -41,7 +41,7 @@ export declare class Crons {
41
41
  *
42
42
  * @param identifier - Either the ID or name of the cron job.
43
43
  */
44
- del(ctx: RunMutationCtx, identifier: {
44
+ delete(ctx: RunMutationCtx, identifier: {
45
45
  id: string;
46
46
  } | {
47
47
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,EAEZ,4BAA4B,EAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEjE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAqCzB,qBAAa,KAAK;IACJ,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC;IAEjD;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,CAAC,SAAS,4BAA4B,EACnD,GAAG,EAAE,cAAc,EACnB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,EACrB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC;IASlB;;;;OAIG;IACG,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAUjD;;;;;OAKG;IACG,GAAG,CACP,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAa3B;;;;OAIG;IACG,GAAG,C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A;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,IAAI,CAAC;CAGjB"}
@@ -92,7 +92,7 @@ export class Crons {
92
92
  *
93
93
  * @param identifier - Either the ID or name of the cron job.
94
94
  */
95
- async del(ctx, identifier) {
95
+ async delete(ctx, identifier) {
96
96
  return ctx.runMutation(this.component.public.del, { identifier });
97
97
  }
98
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,OAAO,EACL,oBAAoB,GAIrB,MAAM,eAAe,CAAC;AAOvB,2EAA2E;AAE3E,yCAAyC;AACzC,EAAE;AACF,6EAA6E;AAC7E,2BAA2B;AAC3B,EAAE;AACF,oBAAoB;AACpB,oBAAoB;AACpB,oBAAoB;AACpB,mEAAmE;AACnE,qCAAqC;AACrC,+CAA+C;AAC/C,oCAAoC;AACpC,sCAAsC;AACtC,gDAAgD;AAChD,EAAE;AACF,kEAAkE;AAClE,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,sCAAsC;AACtC,EAAE;AACF,6CAA6C;AAC7C,MAAM;AACN,4DAA4D;AAC5D,0BAA0B;AAC1B,WAAW;AACX,+CAA+C;AAC/C,iCAAiC;AACjC,iCAAiC;AACjC,cAAc;AACd,OAAO;AACP,IAAI;AACJ,MAAM,OAAO,KAAK;IACI;IAApB,YAAoB,SAA6B;QAA7B,cAAS,GAAT,SAAS,CAAoB;IAAG,CAAC;IAErD;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CACZ,GAAmB,EACnB,QAAkB,EAClB,IAAO,EACP,IAAqB,EACrB,IAAa;QAEb,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE;YACrD,IAAI;YACJ,QAAQ;YACR,cAAc,EAAE,MAAM,oBAAoB,CAAC,IAAI,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QAC3E,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,OAAO,IAAI,CAAC;SACb;QACD,OAAO;YACL,GAAG,IAAI;YACP,cAAc,EAAE,IAAI,CAAC,cAEpB;SACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,GAAmB,EACnB,UAA6C;QAE7C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACpE,CAAC;CACF"}
@@ -1,5 +1,5 @@
1
- import { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
2
- import { GenericId } from "convex/values";
1
+ import type { Expand, FunctionReference, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
2
+ import type { GenericId } from "convex/values";
3
3
  export type RunQueryCtx = {
4
4
  runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/client/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,MAAM,EACN,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;CACzD,CAAC;AACF,MAAM,MAAM,cAAc,GAAG;IAC3B,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,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AI,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@convex-dev/crons",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Convex component for scheduling periodic jobs.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -38,9 +38,11 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "convex": "^1.16.1",
42
41
  "cron-parser": "^4.9.0"
43
42
  },
43
+ "peerDependencies": {
44
+ "convex": "~1.16.5"
45
+ },
44
46
  "devDependencies": {
45
47
  "@eslint/js": "^9.9.1",
46
48
  "@types/node": "^18.17.0",
@@ -119,7 +119,7 @@ export class Crons {
119
119
  *
120
120
  * @param identifier - Either the ID or name of the cron job.
121
121
  */
122
- async del(
122
+ async delete(
123
123
  ctx: RunMutationCtx,
124
124
  identifier: { id: string } | { name: string }
125
125
  ): Promise<null> {
@@ -1,13 +1,13 @@
1
1
  // Type utilities for component clients.
2
2
 
3
- import {
3
+ import type {
4
4
  Expand,
5
5
  FunctionReference,
6
6
  GenericDataModel,
7
7
  GenericMutationCtx,
8
8
  GenericQueryCtx,
9
9
  } from "convex/server";
10
- import { GenericId } from "convex/values";
10
+ import type { GenericId } from "convex/values";
11
11
 
12
12
  export type RunQueryCtx = {
13
13
  runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
@@ -1,135 +0,0 @@
1
- /**
2
- * Schedule a mutation or action to run on a recurring basis.
3
- *
4
- * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.
5
- *
6
- * ```
7
- * * * * * * *
8
- * ┬ ┬ ┬ ┬ ┬ ┬
9
- * │ │ │ │ │ |
10
- * │ │ │ │ │ └── day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
11
- * │ │ │ │ └───── month (1 - 12)
12
- * │ │ │ └──────── day of month (1 - 31, L)
13
- * │ │ └─────────── hour (0 - 23)
14
- * │ └────────────── minute (0 - 59)
15
- * └───────────────── second (0 - 59, optional)
16
- * ```
17
- *
18
- * @param name - Optional unique name for the cron job. Will throw if a name is
19
- * provided and a cron with the same name already exists.
20
- * @param cronspec - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
21
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
22
- * @param args - The arguments to the function.
23
- * @returns The ID of the cron job.
24
- */
25
- export declare const registerCron: import("convex/server").RegisteredMutation<"public", {
26
- name?: string | undefined;
27
- functionHandle: string;
28
- args: any;
29
- cronspec: string;
30
- }, Promise<import("convex/values").GenericId<"crons">>>;
31
- /**
32
- * Schedule a mutation or action to run on the given interval.
33
- *
34
- * @param name - Optional unique name for the cron job. Will throw if a name is
35
- * provided and a cron with the same name already exists.
36
- * @param ms - The time in ms between runs for this scheduled job, >= 1000.
37
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
38
- * @param args - Any arguments to the function.
39
- * @returns The ID of the cron job.
40
- */
41
- export declare const registerInterval: import("convex/server").RegisteredMutation<"public", {
42
- name?: string | undefined;
43
- functionHandle: string;
44
- args: any;
45
- ms: number;
46
- }, Promise<import("convex/values").GenericId<"crons">>>;
47
- /**
48
- * List all user space cron jobs.
49
- *
50
- * @returns List of `cron` table rows.
51
- */
52
- export declare const list: import("convex/server").RegisteredQuery<"public", {}, Promise<{
53
- _id: import("convex/values").GenericId<"crons">;
54
- _creationTime: number;
55
- name?: string | undefined;
56
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
57
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
58
- functionHandle: string;
59
- args: any;
60
- schedule: {
61
- kind: "interval";
62
- ms: number;
63
- } | {
64
- kind: "cron";
65
- cronspec: string;
66
- };
67
- }[]>>;
68
- /**
69
- * Get an existing cron job by id.
70
- *
71
- * @param id - ID of the cron job.
72
- * @returns Cron job document.
73
- */
74
- export declare const get: import("convex/server").RegisteredQuery<"public", {
75
- id: import("convex/values").GenericId<"crons">;
76
- }, Promise<{
77
- _id: import("convex/values").GenericId<"crons">;
78
- _creationTime: number;
79
- name?: string | undefined;
80
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
81
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
82
- functionHandle: string;
83
- args: any;
84
- schedule: {
85
- kind: "interval";
86
- ms: number;
87
- } | {
88
- kind: "cron";
89
- cronspec: string;
90
- };
91
- } | null>>;
92
- /**
93
- * Get an existing cron job by name.
94
- *
95
- * @param name - Name of the cron job.
96
- * @returns Cron job document.
97
- */
98
- export declare const getByName: import("convex/server").RegisteredQuery<"public", {
99
- name: string;
100
- }, Promise<{
101
- _id: import("convex/values").GenericId<"crons">;
102
- _creationTime: number;
103
- name?: string | undefined;
104
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
105
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
106
- functionHandle: string;
107
- args: any;
108
- schedule: {
109
- kind: "interval";
110
- ms: number;
111
- } | {
112
- kind: "cron";
113
- cronspec: string;
114
- };
115
- } | null>>;
116
- /**
117
- * Delete and deschedule a cron job by id.
118
- *
119
- * @param id - ID of the cron job.
120
- */
121
- export declare const del: import("convex/server").RegisteredMutation<"public", {
122
- id: import("convex/values").GenericId<"crons">;
123
- }, Promise<void>>;
124
- /**
125
- * Delete and deschedule a cron job by name.
126
- *
127
- * @param name - Name of the cron job.
128
- */
129
- export declare const delByName: import("convex/server").RegisteredMutation<"public", {
130
- name: string;
131
- }, Promise<void>>;
132
- export declare const rescheduler: import("convex/server").RegisteredMutation<"internal", {
133
- id: import("convex/values").GenericId<"crons">;
134
- }, Promise<void>>;
135
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/component/index.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,YAAY;;;;;uDAgBvB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;uDAgB3B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;KAKf,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;UAOd,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;UAUpB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,GAAG;;iBAWd,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,SAAS;;iBAcpB,CAAC;AAiGH,eAAO,MAAM,WAAW;;iBA6EtB,CAAC"}
@@ -1,289 +0,0 @@
1
- // Implementation of crons in user space.
2
- //
3
- // Crons can be registered at runtime via the `registerCron` or
4
- // `registerInterval` mutations.
5
- //
6
- // If you'd like to statically define cronjobs like in the built-in `crons.ts`
7
- // Convex feature you can do so via an init script that idempotently registers a
8
- // cron with a given name. e.g., in an `init.ts` file that gets run on every
9
- // deploy via `convex dev --run init`:
10
- //
11
- // if ((await ctx.runQuery(components.crons.lib.getByName, { name: "daily" })) == null) {
12
- // await ctx.runMutation(components.crons.lib.registerCron, {
13
- // name: "daily",
14
- // cronspec: "0 0 * * *",
15
- // functionHandle: await createFunctionHandle(internal.whatever.myFunctionName)
16
- // args: { message: "daily cron" },
17
- // });
18
- // }
19
- import { v } from "convex/values";
20
- import { parseArgs } from "./parseArgs.js";
21
- import { mutation, query, internalMutation, } from "./_generated/server.js";
22
- import { internal } from "./_generated/api.js";
23
- import parser from "cron-parser";
24
- /**
25
- * Schedule a mutation or action to run on a recurring basis.
26
- *
27
- * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.
28
- *
29
- * ```
30
- * * * * * * *
31
- * ┬ ┬ ┬ ┬ ┬ ┬
32
- * │ │ │ │ │ |
33
- * │ │ │ │ │ └── day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
34
- * │ │ │ │ └───── month (1 - 12)
35
- * │ │ │ └──────── day of month (1 - 31, L)
36
- * │ │ └─────────── hour (0 - 23)
37
- * │ └────────────── minute (0 - 59)
38
- * └───────────────── second (0 - 59, optional)
39
- * ```
40
- *
41
- * @param name - Optional unique name for the cron job. Will throw if a name is
42
- * provided and a cron with the same name already exists.
43
- * @param cronspec - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
44
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
45
- * @param args - The arguments to the function.
46
- * @returns The ID of the cron job.
47
- */
48
- export const registerCron = mutation({
49
- args: {
50
- name: v.optional(v.string()),
51
- cronspec: v.string(),
52
- functionHandle: v.string(),
53
- args: v.any(),
54
- },
55
- handler: async (ctx, { name, cronspec, functionHandle, args }) => {
56
- return await scheduleCron(ctx, { cronspec: cronspec, kind: "cron" }, functionHandle, name, args);
57
- },
58
- });
59
- /**
60
- * Schedule a mutation or action to run on the given interval.
61
- *
62
- * @param name - Optional unique name for the cron job. Will throw if a name is
63
- * provided and a cron with the same name already exists.
64
- * @param ms - The time in ms between runs for this scheduled job, >= 1000.
65
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
66
- * @param args - Any arguments to the function.
67
- * @returns The ID of the cron job.
68
- */
69
- export const registerInterval = mutation({
70
- args: {
71
- name: v.optional(v.string()),
72
- ms: v.float64(),
73
- functionHandle: v.string(),
74
- args: v.any(),
75
- },
76
- handler: async (ctx, { name, ms, functionHandle, args }) => {
77
- return await scheduleCron(ctx, { kind: "interval", ms }, functionHandle, name, args);
78
- },
79
- });
80
- /**
81
- * List all user space cron jobs.
82
- *
83
- * @returns List of `cron` table rows.
84
- */
85
- export const list = query({
86
- args: {},
87
- handler: async (ctx) => {
88
- return await ctx.db.query("crons").collect();
89
- },
90
- });
91
- /**
92
- * Get an existing cron job by id.
93
- *
94
- * @param id - ID of the cron job.
95
- * @returns Cron job document.
96
- */
97
- export const get = query({
98
- args: {
99
- id: v.id("crons"),
100
- },
101
- handler: async (ctx, { id }) => {
102
- return await ctx.db.get(id);
103
- },
104
- });
105
- /**
106
- * Get an existing cron job by name.
107
- *
108
- * @param name - Name of the cron job.
109
- * @returns Cron job document.
110
- */
111
- export const getByName = query({
112
- args: {
113
- name: v.string(),
114
- },
115
- handler: async (ctx, { name }) => {
116
- return await ctx.db
117
- .query("crons")
118
- .withIndex("name", (q) => q.eq("name", name))
119
- .unique();
120
- },
121
- });
122
- /**
123
- * Delete and deschedule a cron job by id.
124
- *
125
- * @param id - ID of the cron job.
126
- */
127
- export const del = mutation({
128
- args: {
129
- id: v.id("crons"),
130
- },
131
- handler: async (ctx, { id }) => {
132
- const cron = await ctx.db.get(id);
133
- if (!cron) {
134
- throw new Error(`Cron ${id} not found`);
135
- }
136
- await delCron(ctx, cron);
137
- },
138
- });
139
- /**
140
- * Delete and deschedule a cron job by name.
141
- *
142
- * @param name - Name of the cron job.
143
- */
144
- export const delByName = mutation({
145
- args: {
146
- name: v.string(),
147
- },
148
- handler: async (ctx, { name }) => {
149
- const cron = await ctx.db
150
- .query("crons")
151
- .withIndex("name", (q) => q.eq("name", name))
152
- .unique();
153
- if (!cron) {
154
- throw new Error(`Cron "${name}" not found`);
155
- }
156
- await delCron(ctx, cron);
157
- },
158
- });
159
- async function delCron(ctx, cron) {
160
- if (!cron.schedulerJobId) {
161
- throw new Error(`Cron ${cron._id} not scheduled`);
162
- }
163
- console.log(`Canceling scheduler job ${cron.schedulerJobId}`);
164
- await ctx.scheduler.cancel(cron.schedulerJobId);
165
- if (cron.executionJobId) {
166
- console.log(`Canceling execution job ${cron.executionJobId}`);
167
- await ctx.scheduler.cancel(cron.executionJobId);
168
- }
169
- console.log(`Deleting cron ${cron._id}`);
170
- await ctx.db.delete(cron._id);
171
- }
172
- // Initial registration and scheduling of the cron job.
173
- async function scheduleCron(ctx, schedule, functionHandle, name, args) {
174
- // Input validation
175
- if (name &&
176
- (await ctx.db
177
- .query("crons")
178
- .withIndex("name", (q) => q.eq("name", name))
179
- .unique())) {
180
- throw new Error(`Cron with name "${name}" already exists`);
181
- }
182
- if (schedule.kind === "interval" && schedule.ms < 1000) {
183
- throw new Error("Interval must be >= 1000ms"); // Just a sanity check.
184
- }
185
- if (schedule.kind === "cron") {
186
- try {
187
- parser.parseExpression(schedule.cronspec);
188
- }
189
- catch {
190
- throw new Error(`Invalid cronspec: "${schedule.cronspec}"`);
191
- }
192
- }
193
- args = parseArgs(args);
194
- if (schedule.kind === "interval") {
195
- const id = await ctx.db.insert("crons", {
196
- functionHandle,
197
- args,
198
- name,
199
- schedule: { kind: "interval", ms: schedule.ms },
200
- });
201
- // TODO: add support for extracting the function name from a function handle
202
- console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) every ${schedule.ms} ms`);
203
- const schedulerJobId = await ctx.scheduler.runAfter(schedule.ms, internal.index.rescheduler, { id });
204
- await ctx.db.patch(id, { schedulerJobId });
205
- return id;
206
- }
207
- const id = await ctx.db.insert("crons", {
208
- functionHandle,
209
- args,
210
- name,
211
- schedule: { kind: "cron", cronspec: schedule.cronspec },
212
- });
213
- console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) on cronspec "${schedule.cronspec}"`);
214
- const schedulerJobId = await ctx.scheduler.runAt(nextScheduledDate(new Date(), schedule.cronspec), internal.index.rescheduler, { id });
215
- await ctx.db.patch(id, { schedulerJobId });
216
- return id;
217
- }
218
- // Continue rescheduling a cron job.
219
- //
220
- // This is the main worker function that does the scheduling but also schedules
221
- // the target function so that it runs in a different context. As a result this
222
- // function probably *shouldn't* fail since it isn't doing much, but under heavy
223
- // OCC contention it's possible it may eventually fail. In this case the cron
224
- // will be lost and we'll need a janitor job to recover it.
225
- export const rescheduler = internalMutation({
226
- args: {
227
- id: v.id("crons"),
228
- },
229
- handler: async (ctx, { id }) => {
230
- // Cron job is the logical concept we're rescheduling repeatedly.
231
- const cronJob = await ctx.db.get(id);
232
- if (!cronJob) {
233
- throw Error(`Cron ${id} not found`);
234
- }
235
- if (!cronJob.schedulerJobId) {
236
- throw Error(`Cron ${id} not scheduled`);
237
- }
238
- // Scheduler job is the job that's running right now, that we use to trigger
239
- // repeated executions.
240
- const schedulerJob = await ctx.db.system.get(cronJob.schedulerJobId);
241
- if (!schedulerJob) {
242
- throw Error(`Scheduler job ${cronJob.schedulerJobId} not found`);
243
- }
244
- // XXX The convex-test library runs mutations through the `inProgress` state
245
- // but the production state machine does not. Remove the `inProgress` allowance
246
- // once the test library has been updated.
247
- if (schedulerJob.state.kind !== "pending" &&
248
- schedulerJob.state.kind !== "inProgress") {
249
- throw Error(`We are running in job ${schedulerJob._id} but state is ${schedulerJob.state.kind}`);
250
- }
251
- // Execution job is the previous job used to actually do the work of the cron.
252
- let stillRunning = false;
253
- if (cronJob.executionJobId) {
254
- const executionJob = await ctx.db.system.get(cronJob.executionJobId);
255
- if (executionJob &&
256
- (executionJob.state.kind === "pending" ||
257
- executionJob.state.kind === "inProgress")) {
258
- stillRunning = true;
259
- }
260
- }
261
- if (stillRunning) {
262
- console.log(`Cron ${cronJob._id} still running, skipping this run.`);
263
- }
264
- else {
265
- console.log(`Running cron ${cronJob._id}.`);
266
- await ctx.scheduler.runAfter(0, cronJob.functionHandle, cronJob.args);
267
- }
268
- // Now reschedule the next run.
269
- if (cronJob.schedule.kind === "interval") {
270
- const nextTime = schedulerJob.scheduledTime + cronJob.schedule.ms;
271
- const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
272
- await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
273
- }
274
- else {
275
- const nextTime = nextScheduledDate(new Date(schedulerJob.scheduledTime), cronJob.schedule.cronspec);
276
- const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
277
- await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
278
- }
279
- },
280
- });
281
- // Calculate the next date to run a cron given the last time it was scheduled.
282
- function nextScheduledDate(prevDate, cronspec) {
283
- const options = {
284
- currentDate: prevDate,
285
- };
286
- const interval = parser.parseExpression(cronspec, options);
287
- return interval.next().toDate();
288
- }
289
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,+DAA+D;AAC/D,gCAAgC;AAChC,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,sCAAsC;AACtC,EAAE;AACF,yFAAyF;AACzF,+DAA+D;AAC/D,qBAAqB;AACrB,6BAA6B;AAC7B,mFAAmF;AACnF,uCAAuC;AACvC,QAAQ;AACR,IAAI;AAGJ,OAAO,EAAE,CAAC,EAAS,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAEL,QAAQ,EACR,KAAK,EACL,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;IACnC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,KAAK,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;SAChE;IACH,CAAC;CACF,CAAC,CAAC;AAEH,8EAA8E;AAC9E,SAAS,iBAAiB,CAAC,QAAc,EAAE,QAAgB;IACzD,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;KACtB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;AAClC,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Value } from "convex/values";
2
- /**
3
- * Validate that the arguments to a Convex function are an object, defaulting
4
- * `undefined` to `{}`.
5
- */
6
- export declare function parseArgs(args: Record<string, Value> | undefined): Record<string, Value>;
7
- /**
8
- * Check whether a value is a plain old JavaScript object.
9
- */
10
- export declare function isSimpleObject(value: unknown): boolean;
11
- //# sourceMappingURL=parseArgs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseArgs.d.ts","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS,GACtC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAYvB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,WAU5C"}
@@ -1,28 +0,0 @@
1
- // TODO export these from Convex if they're not already
2
- /**
3
- * Validate that the arguments to a Convex function are an object, defaulting
4
- * `undefined` to `{}`.
5
- */
6
- export function parseArgs(args) {
7
- if (args === undefined) {
8
- return {};
9
- }
10
- if (!isSimpleObject(args)) {
11
- throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
12
- }
13
- return args;
14
- }
15
- /**
16
- * Check whether a value is a plain old JavaScript object.
17
- */
18
- export function isSimpleObject(value) {
19
- const isObject = typeof value === "object";
20
- const prototype = Object.getPrototypeOf(value);
21
- const isSimple = prototype === null ||
22
- prototype === Object.prototype ||
23
- // Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
24
- // conditions but are still simple objects.
25
- prototype?.constructor?.name === "Object";
26
- return isObject && isSimple;
27
- }
28
- //# sourceMappingURL=parseArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseArgs.js","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAEA,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,IAAuC;IAEvC,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,mEACE,IACF,EAAE,CACH,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GACZ,SAAS,KAAK,IAAI;QAClB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,yGAAyG;QACzG,2CAA2C;QAC3C,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC;IAC5C,OAAO,QAAQ,IAAI,QAAQ,CAAC;AAC9B,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function subtract(a: number, b: number): number;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -1,8 +0,0 @@
1
- // This is where React components go.
2
- if (typeof window === "undefined") {
3
- throw new Error("this is frontend code, but it's running somewhere else!");
4
- }
5
- export function subtract(a, b) {
6
- return a - b;
7
- }
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;CAC5E;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -1,135 +0,0 @@
1
- /**
2
- * Schedule a mutation or action to run on a recurring basis.
3
- *
4
- * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.
5
- *
6
- * ```
7
- * * * * * * *
8
- * ┬ ┬ ┬ ┬ ┬ ┬
9
- * │ │ │ │ │ |
10
- * │ │ │ │ │ └── day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
11
- * │ │ │ │ └───── month (1 - 12)
12
- * │ │ │ └──────── day of month (1 - 31, L)
13
- * │ │ └─────────── hour (0 - 23)
14
- * │ └────────────── minute (0 - 59)
15
- * └───────────────── second (0 - 59, optional)
16
- * ```
17
- *
18
- * @param name - Optional unique name for the cron job. Will throw if a name is
19
- * provided and a cron with the same name already exists.
20
- * @param cronspec - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
21
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
22
- * @param args - The arguments to the function.
23
- * @returns The ID of the cron job.
24
- */
25
- export declare const registerCron: import("convex/server").RegisteredMutation<"public", {
26
- name?: string | undefined;
27
- functionHandle: string;
28
- args: any;
29
- cronspec: string;
30
- }, Promise<import("convex/values").GenericId<"crons">>>;
31
- /**
32
- * Schedule a mutation or action to run on the given interval.
33
- *
34
- * @param name - Optional unique name for the cron job. Will throw if a name is
35
- * provided and a cron with the same name already exists.
36
- * @param ms - The time in ms between runs for this scheduled job, >= 1000.
37
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
38
- * @param args - Any arguments to the function.
39
- * @returns The ID of the cron job.
40
- */
41
- export declare const registerInterval: import("convex/server").RegisteredMutation<"public", {
42
- name?: string | undefined;
43
- functionHandle: string;
44
- args: any;
45
- ms: number;
46
- }, Promise<import("convex/values").GenericId<"crons">>>;
47
- /**
48
- * List all user space cron jobs.
49
- *
50
- * @returns List of `cron` table rows.
51
- */
52
- export declare const list: import("convex/server").RegisteredQuery<"public", {}, Promise<{
53
- _id: import("convex/values").GenericId<"crons">;
54
- _creationTime: number;
55
- name?: string | undefined;
56
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
57
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
58
- functionHandle: string;
59
- args: any;
60
- schedule: {
61
- kind: "interval";
62
- ms: number;
63
- } | {
64
- kind: "cron";
65
- cronspec: string;
66
- };
67
- }[]>>;
68
- /**
69
- * Get an existing cron job by id.
70
- *
71
- * @param id - ID of the cron job.
72
- * @returns Cron job document.
73
- */
74
- export declare const get: import("convex/server").RegisteredQuery<"public", {
75
- id: import("convex/values").GenericId<"crons">;
76
- }, Promise<{
77
- _id: import("convex/values").GenericId<"crons">;
78
- _creationTime: number;
79
- name?: string | undefined;
80
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
81
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
82
- functionHandle: string;
83
- args: any;
84
- schedule: {
85
- kind: "interval";
86
- ms: number;
87
- } | {
88
- kind: "cron";
89
- cronspec: string;
90
- };
91
- } | null>>;
92
- /**
93
- * Get an existing cron job by name.
94
- *
95
- * @param name - Name of the cron job.
96
- * @returns Cron job document.
97
- */
98
- export declare const getByName: import("convex/server").RegisteredQuery<"public", {
99
- name: string;
100
- }, Promise<{
101
- _id: import("convex/values").GenericId<"crons">;
102
- _creationTime: number;
103
- name?: string | undefined;
104
- schedulerJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
105
- executionJobId?: import("convex/values").GenericId<"_scheduled_functions"> | undefined;
106
- functionHandle: string;
107
- args: any;
108
- schedule: {
109
- kind: "interval";
110
- ms: number;
111
- } | {
112
- kind: "cron";
113
- cronspec: string;
114
- };
115
- } | null>>;
116
- /**
117
- * Delete and deschedule a cron job by id.
118
- *
119
- * @param id - ID of the cron job.
120
- */
121
- export declare const del: import("convex/server").RegisteredMutation<"public", {
122
- id: import("convex/values").GenericId<"crons">;
123
- }, Promise<void>>;
124
- /**
125
- * Delete and deschedule a cron job by name.
126
- *
127
- * @param name - Name of the cron job.
128
- */
129
- export declare const delByName: import("convex/server").RegisteredMutation<"public", {
130
- name: string;
131
- }, Promise<void>>;
132
- export declare const rescheduler: import("convex/server").RegisteredMutation<"internal", {
133
- id: import("convex/values").GenericId<"crons">;
134
- }, Promise<void>>;
135
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/component/index.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,YAAY;;;;;uDAgBvB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;;;;;uDAgB3B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;KAKf,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;UAOd,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;UAUpB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,GAAG;;iBAWd,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,SAAS;;iBAcpB,CAAC;AAiGH,eAAO,MAAM,WAAW;;iBA6EtB,CAAC"}
@@ -1,289 +0,0 @@
1
- // Implementation of crons in user space.
2
- //
3
- // Crons can be registered at runtime via the `registerCron` or
4
- // `registerInterval` mutations.
5
- //
6
- // If you'd like to statically define cronjobs like in the built-in `crons.ts`
7
- // Convex feature you can do so via an init script that idempotently registers a
8
- // cron with a given name. e.g., in an `init.ts` file that gets run on every
9
- // deploy via `convex dev --run init`:
10
- //
11
- // if ((await ctx.runQuery(components.crons.lib.getByName, { name: "daily" })) == null) {
12
- // await ctx.runMutation(components.crons.lib.registerCron, {
13
- // name: "daily",
14
- // cronspec: "0 0 * * *",
15
- // functionHandle: await createFunctionHandle(internal.whatever.myFunctionName)
16
- // args: { message: "daily cron" },
17
- // });
18
- // }
19
- import { v } from "convex/values";
20
- import { parseArgs } from "./parseArgs.js";
21
- import { mutation, query, internalMutation, } from "./_generated/server.js";
22
- import { internal } from "./_generated/api.js";
23
- import parser from "cron-parser";
24
- /**
25
- * Schedule a mutation or action to run on a recurring basis.
26
- *
27
- * Like the unix command `cron`, Sunday is 0, Monday is 1, etc.
28
- *
29
- * ```
30
- * * * * * * *
31
- * ┬ ┬ ┬ ┬ ┬ ┬
32
- * │ │ │ │ │ |
33
- * │ │ │ │ │ └── day of week (0 - 7, 1L - 7L) (0 or 7 is Sun)
34
- * │ │ │ │ └───── month (1 - 12)
35
- * │ │ │ └──────── day of month (1 - 31, L)
36
- * │ │ └─────────── hour (0 - 23)
37
- * │ └────────────── minute (0 - 59)
38
- * └───────────────── second (0 - 59, optional)
39
- * ```
40
- *
41
- * @param name - Optional unique name for the cron job. Will throw if a name is
42
- * provided and a cron with the same name already exists.
43
- * @param cronspec - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
44
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
45
- * @param args - The arguments to the function.
46
- * @returns The ID of the cron job.
47
- */
48
- export const registerCron = mutation({
49
- args: {
50
- name: v.optional(v.string()),
51
- cronspec: v.string(),
52
- functionHandle: v.string(),
53
- args: v.any(),
54
- },
55
- handler: async (ctx, { name, cronspec, functionHandle, args }) => {
56
- return await scheduleCron(ctx, { cronspec: cronspec, kind: "cron" }, functionHandle, name, args);
57
- },
58
- });
59
- /**
60
- * Schedule a mutation or action to run on the given interval.
61
- *
62
- * @param name - Optional unique name for the cron job. Will throw if a name is
63
- * provided and a cron with the same name already exists.
64
- * @param ms - The time in ms between runs for this scheduled job, >= 1000.
65
- * @param functionHandle - A {@link FunctionHandle} string for the function to schedule.
66
- * @param args - Any arguments to the function.
67
- * @returns The ID of the cron job.
68
- */
69
- export const registerInterval = mutation({
70
- args: {
71
- name: v.optional(v.string()),
72
- ms: v.float64(),
73
- functionHandle: v.string(),
74
- args: v.any(),
75
- },
76
- handler: async (ctx, { name, ms, functionHandle, args }) => {
77
- return await scheduleCron(ctx, { kind: "interval", ms }, functionHandle, name, args);
78
- },
79
- });
80
- /**
81
- * List all user space cron jobs.
82
- *
83
- * @returns List of `cron` table rows.
84
- */
85
- export const list = query({
86
- args: {},
87
- handler: async (ctx) => {
88
- return await ctx.db.query("crons").collect();
89
- },
90
- });
91
- /**
92
- * Get an existing cron job by id.
93
- *
94
- * @param id - ID of the cron job.
95
- * @returns Cron job document.
96
- */
97
- export const get = query({
98
- args: {
99
- id: v.id("crons"),
100
- },
101
- handler: async (ctx, { id }) => {
102
- return await ctx.db.get(id);
103
- },
104
- });
105
- /**
106
- * Get an existing cron job by name.
107
- *
108
- * @param name - Name of the cron job.
109
- * @returns Cron job document.
110
- */
111
- export const getByName = query({
112
- args: {
113
- name: v.string(),
114
- },
115
- handler: async (ctx, { name }) => {
116
- return await ctx.db
117
- .query("crons")
118
- .withIndex("name", (q) => q.eq("name", name))
119
- .unique();
120
- },
121
- });
122
- /**
123
- * Delete and deschedule a cron job by id.
124
- *
125
- * @param id - ID of the cron job.
126
- */
127
- export const del = mutation({
128
- args: {
129
- id: v.id("crons"),
130
- },
131
- handler: async (ctx, { id }) => {
132
- const cron = await ctx.db.get(id);
133
- if (!cron) {
134
- throw new Error(`Cron ${id} not found`);
135
- }
136
- await delCron(ctx, cron);
137
- },
138
- });
139
- /**
140
- * Delete and deschedule a cron job by name.
141
- *
142
- * @param name - Name of the cron job.
143
- */
144
- export const delByName = mutation({
145
- args: {
146
- name: v.string(),
147
- },
148
- handler: async (ctx, { name }) => {
149
- const cron = await ctx.db
150
- .query("crons")
151
- .withIndex("name", (q) => q.eq("name", name))
152
- .unique();
153
- if (!cron) {
154
- throw new Error(`Cron "${name}" not found`);
155
- }
156
- await delCron(ctx, cron);
157
- },
158
- });
159
- async function delCron(ctx, cron) {
160
- if (!cron.schedulerJobId) {
161
- throw new Error(`Cron ${cron._id} not scheduled`);
162
- }
163
- console.log(`Canceling scheduler job ${cron.schedulerJobId}`);
164
- await ctx.scheduler.cancel(cron.schedulerJobId);
165
- if (cron.executionJobId) {
166
- console.log(`Canceling execution job ${cron.executionJobId}`);
167
- await ctx.scheduler.cancel(cron.executionJobId);
168
- }
169
- console.log(`Deleting cron ${cron._id}`);
170
- await ctx.db.delete(cron._id);
171
- }
172
- // Initial registration and scheduling of the cron job.
173
- async function scheduleCron(ctx, schedule, functionHandle, name, args) {
174
- // Input validation
175
- if (name &&
176
- (await ctx.db
177
- .query("crons")
178
- .withIndex("name", (q) => q.eq("name", name))
179
- .unique())) {
180
- throw new Error(`Cron with name "${name}" already exists`);
181
- }
182
- if (schedule.kind === "interval" && schedule.ms < 1000) {
183
- throw new Error("Interval must be >= 1000ms"); // Just a sanity check.
184
- }
185
- if (schedule.kind === "cron") {
186
- try {
187
- parser.parseExpression(schedule.cronspec);
188
- }
189
- catch {
190
- throw new Error(`Invalid cronspec: "${schedule.cronspec}"`);
191
- }
192
- }
193
- args = parseArgs(args);
194
- if (schedule.kind === "interval") {
195
- const id = await ctx.db.insert("crons", {
196
- functionHandle,
197
- args,
198
- name,
199
- schedule: { kind: "interval", ms: schedule.ms },
200
- });
201
- // TODO: add support for extracting the function name from a function handle
202
- console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) every ${schedule.ms} ms`);
203
- const schedulerJobId = await ctx.scheduler.runAfter(schedule.ms, internal.index.rescheduler, { id });
204
- await ctx.db.patch(id, { schedulerJobId });
205
- return id;
206
- }
207
- const id = await ctx.db.insert("crons", {
208
- functionHandle,
209
- args,
210
- name,
211
- schedule: { kind: "cron", cronspec: schedule.cronspec },
212
- });
213
- console.log(`Scheduling cron with name "${name}" and id ${id} to run ${functionHandle}(${JSON.stringify(args)}) on cronspec "${schedule.cronspec}"`);
214
- const schedulerJobId = await ctx.scheduler.runAt(nextScheduledDate(new Date(), schedule.cronspec), internal.index.rescheduler, { id });
215
- await ctx.db.patch(id, { schedulerJobId });
216
- return id;
217
- }
218
- // Continue rescheduling a cron job.
219
- //
220
- // This is the main worker function that does the scheduling but also schedules
221
- // the target function so that it runs in a different context. As a result this
222
- // function probably *shouldn't* fail since it isn't doing much, but under heavy
223
- // OCC contention it's possible it may eventually fail. In this case the cron
224
- // will be lost and we'll need a janitor job to recover it.
225
- export const rescheduler = internalMutation({
226
- args: {
227
- id: v.id("crons"),
228
- },
229
- handler: async (ctx, { id }) => {
230
- // Cron job is the logical concept we're rescheduling repeatedly.
231
- const cronJob = await ctx.db.get(id);
232
- if (!cronJob) {
233
- throw Error(`Cron ${id} not found`);
234
- }
235
- if (!cronJob.schedulerJobId) {
236
- throw Error(`Cron ${id} not scheduled`);
237
- }
238
- // Scheduler job is the job that's running right now, that we use to trigger
239
- // repeated executions.
240
- const schedulerJob = await ctx.db.system.get(cronJob.schedulerJobId);
241
- if (!schedulerJob) {
242
- throw Error(`Scheduler job ${cronJob.schedulerJobId} not found`);
243
- }
244
- // XXX The convex-test library runs mutations through the `inProgress` state
245
- // but the production state machine does not. Remove the `inProgress` allowance
246
- // once the test library has been updated.
247
- if (schedulerJob.state.kind !== "pending" &&
248
- schedulerJob.state.kind !== "inProgress") {
249
- throw Error(`We are running in job ${schedulerJob._id} but state is ${schedulerJob.state.kind}`);
250
- }
251
- // Execution job is the previous job used to actually do the work of the cron.
252
- let stillRunning = false;
253
- if (cronJob.executionJobId) {
254
- const executionJob = await ctx.db.system.get(cronJob.executionJobId);
255
- if (executionJob &&
256
- (executionJob.state.kind === "pending" ||
257
- executionJob.state.kind === "inProgress")) {
258
- stillRunning = true;
259
- }
260
- }
261
- if (stillRunning) {
262
- console.log(`Cron ${cronJob._id} still running, skipping this run.`);
263
- }
264
- else {
265
- console.log(`Running cron ${cronJob._id}.`);
266
- await ctx.scheduler.runAfter(0, cronJob.functionHandle, cronJob.args);
267
- }
268
- // Now reschedule the next run.
269
- if (cronJob.schedule.kind === "interval") {
270
- const nextTime = schedulerJob.scheduledTime + cronJob.schedule.ms;
271
- const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
272
- await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
273
- }
274
- else {
275
- const nextTime = nextScheduledDate(new Date(schedulerJob.scheduledTime), cronJob.schedule.cronspec);
276
- const nextSchedulerJobId = await ctx.scheduler.runAt(nextTime, internal.index.rescheduler, { id });
277
- await ctx.db.patch(id, { schedulerJobId: nextSchedulerJobId });
278
- }
279
- },
280
- });
281
- // Calculate the next date to run a cron given the last time it was scheduled.
282
- function nextScheduledDate(prevDate, cronspec) {
283
- const options = {
284
- currentDate: prevDate,
285
- };
286
- const interval = parser.parseExpression(cronspec, options);
287
- return interval.next().toDate();
288
- }
289
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,+DAA+D;AAC/D,gCAAgC;AAChC,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,4EAA4E;AAC5E,sCAAsC;AACtC,EAAE;AACF,yFAAyF;AACzF,+DAA+D;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AAE,CACP,CAAC;YACF,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;SAChE;aAAM;YACL,MAAM,QAAQ,GAAG,iBAAiB,CAChC,IAAI,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAC1B,CAAC;YACF,MAAM,kBAAkB,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,KAAK,CAClD,QAAQ,EACR,QAAQ,CAAC,KAAK,CAAC,WAAW,EAC1B,EAAE,EAAE,EAAE,CACP,CAAC;YACF,MAAM,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC;SAChE;IACH,CAAC;CACF,CAAC,CAAC;AAEH,8EAA8E;AAC9E,SAAS,iBAAiB,CAAC,QAAc,EAAE,QAAgB;IACzD,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,QAAQ;KACtB,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;AAClC,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Value } from "convex/values";
2
- /**
3
- * Validate that the arguments to a Convex function are an object, defaulting
4
- * `undefined` to `{}`.
5
- */
6
- export declare function parseArgs(args: Record<string, Value> | undefined): Record<string, Value>;
7
- /**
8
- * Check whether a value is a plain old JavaScript object.
9
- */
10
- export declare function isSimpleObject(value: unknown): boolean;
11
- //# sourceMappingURL=parseArgs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseArgs.d.ts","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAItC;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,SAAS,GACtC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAYvB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,WAU5C"}
@@ -1,28 +0,0 @@
1
- // TODO export these from Convex if they're not already
2
- /**
3
- * Validate that the arguments to a Convex function are an object, defaulting
4
- * `undefined` to `{}`.
5
- */
6
- export function parseArgs(args) {
7
- if (args === undefined) {
8
- return {};
9
- }
10
- if (!isSimpleObject(args)) {
11
- throw new Error(`The arguments to a Convex function must be an object. Received: ${args}`);
12
- }
13
- return args;
14
- }
15
- /**
16
- * Check whether a value is a plain old JavaScript object.
17
- */
18
- export function isSimpleObject(value) {
19
- const isObject = typeof value === "object";
20
- const prototype = Object.getPrototypeOf(value);
21
- const isSimple = prototype === null ||
22
- prototype === Object.prototype ||
23
- // Objects generated from other contexts (e.g. across Node.js `vm` modules) will not satisfy the previous
24
- // conditions but are still simple objects.
25
- prototype?.constructor?.name === "Object";
26
- return isObject && isSimple;
27
- }
28
- //# sourceMappingURL=parseArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseArgs.js","sourceRoot":"","sources":["../../../src/component/parseArgs.ts"],"names":[],"mappings":"AAEA,uDAAuD;AAEvD;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,IAAuC;IAEvC,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,OAAO,EAAE,CAAC;KACX;IACD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,mEACE,IACF,EAAE,CACH,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC;IAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,QAAQ,GACZ,SAAS,KAAK,IAAI;QAClB,SAAS,KAAK,MAAM,CAAC,SAAS;QAC9B,yGAAyG;QACzG,2CAA2C;QAC3C,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC;IAC5C,OAAO,QAAQ,IAAI,QAAQ,CAAC;AAC9B,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function subtract(a: number, b: number): number;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -1,8 +0,0 @@
1
- // This is where React components go.
2
- if (typeof window === "undefined") {
3
- throw new Error("this is frontend code, but it's running somewhere else!");
4
- }
5
- export function subtract(a, b) {
6
- return a - b;
7
- }
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/frontend/index.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;CAC5E;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS,EAAE,CAAS;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}