@convex-dev/sharded-counter 0.1.8 → 0.2.1

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 (85) hide show
  1. package/README.md +39 -41
  2. package/dist/{commonjs/client → client}/index.d.ts +24 -33
  3. package/dist/client/index.d.ts.map +1 -0
  4. package/dist/client/index.js.map +1 -0
  5. package/dist/component/_generated/api.d.ts +34 -0
  6. package/dist/component/_generated/api.d.ts.map +1 -0
  7. package/{src → dist}/component/_generated/api.js +11 -3
  8. package/dist/component/_generated/api.js.map +1 -0
  9. package/dist/component/_generated/component.d.ts +46 -0
  10. package/dist/component/_generated/component.d.ts.map +1 -0
  11. package/dist/component/_generated/component.js +11 -0
  12. package/dist/component/_generated/component.js.map +1 -0
  13. package/dist/component/_generated/dataModel.d.ts +46 -0
  14. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  15. package/dist/component/_generated/dataModel.js +11 -0
  16. package/dist/component/_generated/dataModel.js.map +1 -0
  17. package/{src → dist}/component/_generated/server.d.ts +10 -38
  18. package/dist/component/_generated/server.d.ts.map +1 -0
  19. package/dist/{esm/component → component}/_generated/server.js +9 -5
  20. package/dist/component/_generated/server.js.map +1 -0
  21. package/dist/component/convex.config.d.ts.map +1 -0
  22. package/dist/component/convex.config.js.map +1 -0
  23. package/dist/{commonjs/component → component}/public.d.ts +1 -1
  24. package/dist/component/public.d.ts.map +1 -0
  25. package/dist/{commonjs/component → component}/public.js +4 -4
  26. package/dist/component/public.js.map +1 -0
  27. package/dist/{commonjs/component → component}/schema.d.ts +2 -2
  28. package/dist/component/schema.d.ts.map +1 -0
  29. package/dist/component/schema.js.map +1 -0
  30. package/package.json +61 -38
  31. package/src/client/index.ts +45 -58
  32. package/src/component/_generated/api.ts +50 -0
  33. package/src/component/_generated/component.ts +63 -0
  34. package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +1 -1
  35. package/src/component/_generated/server.ts +156 -0
  36. package/src/component/counter.test.ts +12 -9
  37. package/src/component/public.ts +4 -4
  38. package/src/test.ts +18 -0
  39. package/dist/commonjs/client/index.d.ts.map +0 -1
  40. package/dist/commonjs/client/index.js.map +0 -1
  41. package/dist/commonjs/component/_generated/api.d.ts +0 -14
  42. package/dist/commonjs/component/_generated/api.d.ts.map +0 -1
  43. package/dist/commonjs/component/_generated/api.js +0 -22
  44. package/dist/commonjs/component/_generated/api.js.map +0 -1
  45. package/dist/commonjs/component/_generated/server.d.ts +0 -64
  46. package/dist/commonjs/component/_generated/server.d.ts.map +0 -1
  47. package/dist/commonjs/component/_generated/server.js +0 -74
  48. package/dist/commonjs/component/_generated/server.js.map +0 -1
  49. package/dist/commonjs/component/convex.config.d.ts.map +0 -1
  50. package/dist/commonjs/component/convex.config.js.map +0 -1
  51. package/dist/commonjs/component/public.d.ts.map +0 -1
  52. package/dist/commonjs/component/public.js.map +0 -1
  53. package/dist/commonjs/component/schema.d.ts.map +0 -1
  54. package/dist/commonjs/component/schema.js.map +0 -1
  55. package/dist/commonjs/package.json +0 -3
  56. package/dist/esm/client/index.d.ts +0 -178
  57. package/dist/esm/client/index.d.ts.map +0 -1
  58. package/dist/esm/client/index.js +0 -193
  59. package/dist/esm/client/index.js.map +0 -1
  60. package/dist/esm/component/_generated/api.d.ts +0 -14
  61. package/dist/esm/component/_generated/api.d.ts.map +0 -1
  62. package/dist/esm/component/_generated/api.js +0 -22
  63. package/dist/esm/component/_generated/api.js.map +0 -1
  64. package/dist/esm/component/_generated/server.d.ts +0 -64
  65. package/dist/esm/component/_generated/server.d.ts.map +0 -1
  66. package/dist/esm/component/_generated/server.js.map +0 -1
  67. package/dist/esm/component/convex.config.d.ts +0 -3
  68. package/dist/esm/component/convex.config.d.ts.map +0 -1
  69. package/dist/esm/component/convex.config.js +0 -3
  70. package/dist/esm/component/convex.config.js.map +0 -1
  71. package/dist/esm/component/public.d.ts +0 -23
  72. package/dist/esm/component/public.d.ts.map +0 -1
  73. package/dist/esm/component/public.js +0 -115
  74. package/dist/esm/component/public.js.map +0 -1
  75. package/dist/esm/component/schema.d.ts +0 -15
  76. package/dist/esm/component/schema.d.ts.map +0 -1
  77. package/dist/esm/component/schema.js +0 -10
  78. package/dist/esm/component/schema.js.map +0 -1
  79. package/dist/esm/package.json +0 -3
  80. package/src/component/_generated/api.d.ts +0 -67
  81. package/src/component/_generated/server.js +0 -90
  82. /package/dist/{commonjs/client → client}/index.js +0 -0
  83. /package/dist/{commonjs/component → component}/convex.config.d.ts +0 -0
  84. /package/dist/{commonjs/component → component}/convex.config.js +0 -0
  85. /package/dist/{commonjs/component → component}/schema.js +0 -0
@@ -1,4 +1,3 @@
1
- /* eslint-disable */
2
1
  /**
3
2
  * Generated utilities for implementing server-side Convex query and mutation functions.
4
3
  *
@@ -7,27 +6,8 @@
7
6
  * To regenerate, run `npx convex dev`.
8
7
  * @module
9
8
  */
10
-
11
- import {
12
- ActionBuilder,
13
- AnyComponents,
14
- HttpActionBuilder,
15
- MutationBuilder,
16
- QueryBuilder,
17
- GenericActionCtx,
18
- GenericMutationCtx,
19
- GenericQueryCtx,
20
- GenericDatabaseReader,
21
- GenericDatabaseWriter,
22
- FunctionReference,
23
- } from "convex/server";
9
+ import type { ActionBuilder, HttpActionBuilder, MutationBuilder, QueryBuilder, GenericActionCtx, GenericMutationCtx, GenericQueryCtx, GenericDatabaseReader, GenericDatabaseWriter } from "convex/server";
24
10
  import type { DataModel } from "./dataModel.js";
25
-
26
- type GenericCtx =
27
- | GenericActionCtx<DataModel>
28
- | GenericMutationCtx<DataModel>
29
- | GenericQueryCtx<DataModel>;
30
-
31
11
  /**
32
12
  * Define a query in this Convex app's public API.
33
13
  *
@@ -37,7 +17,6 @@ type GenericCtx =
37
17
  * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
38
18
  */
39
19
  export declare const query: QueryBuilder<DataModel, "public">;
40
-
41
20
  /**
42
21
  * Define a query that is only accessible from other Convex functions (but not from the client).
43
22
  *
@@ -47,7 +26,6 @@ export declare const query: QueryBuilder<DataModel, "public">;
47
26
  * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
48
27
  */
49
28
  export declare const internalQuery: QueryBuilder<DataModel, "internal">;
50
-
51
29
  /**
52
30
  * Define a mutation in this Convex app's public API.
53
31
  *
@@ -57,7 +35,6 @@ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
57
35
  * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
58
36
  */
59
37
  export declare const mutation: MutationBuilder<DataModel, "public">;
60
-
61
38
  /**
62
39
  * Define a mutation that is only accessible from other Convex functions (but not from the client).
63
40
  *
@@ -67,7 +44,6 @@ export declare const mutation: MutationBuilder<DataModel, "public">;
67
44
  * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
68
45
  */
69
46
  export declare const internalMutation: MutationBuilder<DataModel, "internal">;
70
-
71
47
  /**
72
48
  * Define an action in this Convex app's public API.
73
49
  *
@@ -80,7 +56,6 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
80
56
  * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
81
57
  */
82
58
  export declare const action: ActionBuilder<DataModel, "public">;
83
-
84
59
  /**
85
60
  * Define an action that is only accessible from other Convex functions (but not from the client).
86
61
  *
@@ -88,38 +63,36 @@ export declare const action: ActionBuilder<DataModel, "public">;
88
63
  * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
89
64
  */
90
65
  export declare const internalAction: ActionBuilder<DataModel, "internal">;
91
-
92
66
  /**
93
67
  * Define an HTTP action.
94
68
  *
95
- * This function will be used to respond to HTTP requests received by a Convex
96
- * deployment if the requests matches the path and method where this action
97
- * is routed. Be sure to route your action in `convex/http.js`.
69
+ * The wrapped function will be used to respond to HTTP requests received
70
+ * by a Convex deployment if the requests matches the path and method where
71
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
98
72
  *
99
- * @param func - The function. It receives an {@link ActionCtx} as its first argument.
73
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
74
+ * and a Fetch API `Request` object as its second.
100
75
  * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
101
76
  */
102
77
  export declare const httpAction: HttpActionBuilder;
103
-
104
78
  /**
105
79
  * A set of services for use within Convex query functions.
106
80
  *
107
81
  * The query context is passed as the first argument to any Convex query
108
82
  * function run on the server.
109
83
  *
110
- * This differs from the {@link MutationCtx} because all of the services are
111
- * read-only.
84
+ * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
112
85
  */
113
86
  export type QueryCtx = GenericQueryCtx<DataModel>;
114
-
115
87
  /**
116
88
  * A set of services for use within Convex mutation functions.
117
89
  *
118
90
  * The mutation context is passed as the first argument to any Convex mutation
119
91
  * function run on the server.
92
+ *
93
+ * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
120
94
  */
121
95
  export type MutationCtx = GenericMutationCtx<DataModel>;
122
-
123
96
  /**
124
97
  * A set of services for use within Convex action functions.
125
98
  *
@@ -127,7 +100,6 @@ export type MutationCtx = GenericMutationCtx<DataModel>;
127
100
  * function run on the server.
128
101
  */
129
102
  export type ActionCtx = GenericActionCtx<DataModel>;
130
-
131
103
  /**
132
104
  * An interface to read from the database within Convex query functions.
133
105
  *
@@ -136,7 +108,6 @@ export type ActionCtx = GenericActionCtx<DataModel>;
136
108
  * building a query.
137
109
  */
138
110
  export type DatabaseReader = GenericDatabaseReader<DataModel>;
139
-
140
111
  /**
141
112
  * An interface to read from and write to the database within Convex mutation
142
113
  * functions.
@@ -147,3 +118,4 @@ export type DatabaseReader = GenericDatabaseReader<DataModel>;
147
118
  * for the guarantees Convex provides your functions.
148
119
  */
149
120
  export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
121
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB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, run `npx convex dev`.
8
8
  * @module
9
9
  */
10
- import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, componentsGeneric, } from "convex/server";
10
+ import { actionGeneric, httpActionGeneric, queryGeneric, mutationGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, } from "convex/server";
11
11
  /**
12
12
  * Define a query in this Convex app's public API.
13
13
  *
@@ -64,11 +64,15 @@ export const action = actionGeneric;
64
64
  */
65
65
  export const internalAction = internalActionGeneric;
66
66
  /**
67
- * Define a Convex HTTP action.
67
+ * Define an HTTP action.
68
68
  *
69
- * @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
70
- * as its second.
71
- * @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
69
+ * The wrapped function will be used to respond to HTTP requests received
70
+ * by a Convex deployment if the requests matches the path and method where
71
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
72
+ *
73
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
74
+ * and a Fetch API `Request` object as its second.
75
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
72
76
  */
73
77
  export const httpAction = httpActionGeneric;
74
78
  //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/component/_generated/server.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;GAOG;AAaH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAGvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsC,YAAY,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,oBAAoB,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAyC,eAAe,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,uBAAuB,CAAC;AAE1B;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,MAAM,GAAuC,aAAa,CAAC;AAExE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,qBAAqB,CAAC;AAExB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsB,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex.config.d.ts","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":";AAEA,wBAAiD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convex.config.js","sourceRoot":"","sources":["../../src/component/convex.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAe,eAAe,CAAC,gBAAgB,CAAC,CAAC"}
@@ -2,8 +2,8 @@ export declare const DEFAULT_SHARD_COUNT = 16;
2
2
  export declare const add: import("convex/server").RegisteredMutation<"public", {
3
3
  shard?: number | undefined;
4
4
  shards?: number | undefined;
5
- name: string;
6
5
  count: number;
6
+ name: string;
7
7
  }, Promise<number>>;
8
8
  export declare const count: import("convex/server").RegisteredQuery<"public", {
9
9
  name: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/component/public.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,eAAO,MAAM,GAAG;;;;;mBA6Bd,CAAC;AAEH,eAAO,MAAM,KAAK;;mBAUhB,CAAC;AAEH,eAAO,MAAM,SAAS;;;iBA2BpB,CAAC;AAEH,eAAO,MAAM,KAAK;;iBAWhB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;mBA2BxB,CAAC"}
@@ -17,7 +17,7 @@ export const add = mutation({
17
17
  .withIndex("name", (q) => q.eq("name", args.name).eq("shard", shard))
18
18
  .unique();
19
19
  if (counter) {
20
- await ctx.db.patch(counter._id, {
20
+ await ctx.db.patch("counters", counter._id, {
21
21
  value: counter.value + args.count,
22
22
  });
23
23
  }
@@ -55,7 +55,7 @@ export const rebalance = mutation({
55
55
  for (let i = 0; i < shardCount; i++) {
56
56
  const shard = counters.find((c) => c.shard === i);
57
57
  if (shard) {
58
- await ctx.db.patch(shard._id, { value });
58
+ await ctx.db.patch("counters", shard._id, { value });
59
59
  }
60
60
  else {
61
61
  await ctx.db.insert("counters", {
@@ -67,7 +67,7 @@ export const rebalance = mutation({
67
67
  }
68
68
  const toDelete = counters.filter((c) => c.shard >= shardCount);
69
69
  for (const counter of toDelete) {
70
- await ctx.db.delete(counter._id);
70
+ await ctx.db.delete("counters", counter._id);
71
71
  }
72
72
  },
73
73
  });
@@ -78,7 +78,7 @@ export const reset = mutation({
78
78
  .query("counters")
79
79
  .withIndex("name", (q) => q.eq("name", args.name))
80
80
  .collect()
81
- .then((counters) => Promise.all(counters.map((c) => ctx.db.delete(c._id))));
81
+ .then((counters) => Promise.all(counters.map((c) => ctx.db.delete("counters", c._id))));
82
82
  },
83
83
  });
84
84
  export const estimateCount = query({
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.js","sourceRoot":"","sources":["../../src/component/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,MAAM,CAAC,MAAM,GAAG,GAAG,QAAQ,CAAC;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,EAAE,CAAC,CAAC,QAAQ,C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ACpE,MAAM,EAAE,CAAC;YACZ,IAAI,OAAO,EAAE,CAAC;gBACZ,SAAS,IAAI,OAAO,CAAC,KAAK,CAAC;YAC7B,CAAC;QACH,CAAC;QACD,OAAO,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG,cAAc,CAAC;IACnD,CAAC;CACF,CAAC,CAAC;AAEH,uBAAuB;AACvB,SAAS,OAAO,CAAI,KAAU;IAC5B,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -1,13 +1,13 @@
1
1
  declare const _default: import("convex/server").SchemaDefinition<{
2
2
  counters: import("convex/server").TableDefinition<import("convex/values").VObject<{
3
3
  name: string;
4
- value: number;
5
4
  shard: number;
5
+ value: number;
6
6
  }, {
7
7
  name: import("convex/values").VString<string, "required">;
8
8
  value: import("convex/values").VFloat64<number, "required">;
9
9
  shard: import("convex/values").VFloat64<number, "required">;
10
- }, "required", "name" | "value" | "shard">, {
10
+ }, "required", "name" | "shard" | "value">, {
11
11
  name: ["name", "shard", "_creationTime"];
12
12
  }, {}, {}>;
13
13
  }, true>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA,wBAMG"}
@@ -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,QAAQ,EAAE,WAAW,CAAC;QACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;QACjB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;KAClB,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC,CAAC"}
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "email": "support@convex.dev",
8
8
  "url": "https://github.com/get-convex/sharded-counter/issues"
9
9
  },
10
- "version": "0.1.8",
10
+ "version": "0.2.1",
11
11
  "license": "Apache-2.0",
12
12
  "keywords": [
13
13
  "convex",
@@ -16,15 +16,23 @@
16
16
  ],
17
17
  "type": "module",
18
18
  "scripts": {
19
- "build": "npm run build:esm && npm run build:cjs",
20
- "build:esm": "tsc --project ./esm.json && echo '{\\n \"type\": \"module\"\\n}' > dist/esm/package.json",
21
- "build:cjs": "tsc --project ./commonjs.json && echo '{\\n \"type\": \"commonjs\"\\n}' > dist/commonjs/package.json",
22
- "dev": "cd example; npm run dev",
23
- "typecheck": "tsc --noEmit",
24
- "prepare": "npm run build",
25
- "test": "vitest",
19
+ "dev": "convex dev --start 'npm run dev:build'",
20
+ "dev:frontend": "cd example && vite --clearScreen false",
21
+ "dev:build": "chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'npm run build:codegen' --initial",
22
+ "predev": "convex init && npm run build:codegen",
23
+ "build": "tsc --project ./tsconfig.build.json",
24
+ "build:codegen": "npx convex codegen --component-dir ./src/component && npm run build",
25
+ "build:clean": "rm -rf dist *.tsbuildinfo && npm run build:codegen",
26
+ "typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
27
+ "lint": "eslint .",
28
+ "test": "vitest run --typecheck",
29
+ "test:watch": "vitest --typecheck --clearScreen false",
26
30
  "test:debug": "vitest --inspect-brk --no-file-parallelism",
27
- "test:coverage": "vitest run --coverage --coverage.reporter=text"
31
+ "test:coverage": "vitest run --coverage --coverage.reporter=text",
32
+ "preversion": "npm ci && npm run build:clean && npm run test && npm run lint && npm run typecheck",
33
+ "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
34
+ "release": "npm version patch && npm publish && git push --follow-tags",
35
+ "version": "(npm whoami || npm login) && vim -c 'normal o' -c 'normal o## '$npm_package_version CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
28
36
  },
29
37
  "files": [
30
38
  "dist",
@@ -33,41 +41,56 @@
33
41
  "exports": {
34
42
  "./package.json": "./package.json",
35
43
  ".": {
36
- "import": {
37
- "@convex-dev/component-source": "./src/client/index.ts",
38
- "types": "./dist/esm/client/index.d.ts",
39
- "default": "./dist/esm/client/index.js"
40
- },
41
- "require": {
42
- "@convex-dev/component-source": "./src/client/index.ts",
43
- "types": "./dist/commonjs/client/index.d.ts",
44
- "default": "./dist/commonjs/client/index.js"
45
- }
44
+ "types": "./dist/client/index.d.ts",
45
+ "default": "./dist/client/index.js"
46
+ },
47
+ "./test": "./src/test.ts",
48
+ "./_generated/component.js": {
49
+ "types": "./dist/component/_generated/component.d.ts"
46
50
  },
47
51
  "./convex.config": {
48
- "import": {
49
- "@convex-dev/component-source": "./src/component/convex.config.ts",
50
- "types": "./dist/esm/component/convex.config.d.ts",
51
- "default": "./dist/esm/component/convex.config.js"
52
- }
52
+ "types": "./dist/component/convex.config.d.ts",
53
+ "default": "./dist/component/convex.config.js"
54
+ },
55
+ "./convex.config.js": {
56
+ "types": "./dist/component/convex.config.d.ts",
57
+ "default": "./dist/component/convex.config.js"
53
58
  }
54
59
  },
55
60
  "peerDependencies": {
56
- "convex": "~1.16.5 || >=1.17.0 <1.35.0"
61
+ "convex": "^1.24.8"
57
62
  },
58
63
  "devDependencies": {
59
- "@eslint/js": "^9.9.1",
60
- "@types/node": "^18.17.0",
61
- "eslint": "^9.9.1",
62
- "convex-test": "^0.0.31",
63
- "@fast-check/vitest": "^0.1.3",
64
- "globals": "^15.9.0",
65
- "vitest": "^2.1.1",
66
- "prettier": "3.2.5",
67
- "typescript": "~5.0.3",
68
- "typescript-eslint": "^8.4.0"
64
+ "@convex-dev/eslint-plugin": "^2.0.0",
65
+ "@convex-dev/migrations": "0.3.3",
66
+ "@edge-runtime/vm": "5.0.0",
67
+ "@eslint/eslintrc": "3.3.5",
68
+ "@eslint/js": "9.39.4",
69
+ "@fast-check/vitest": "0.4.0",
70
+ "@types/node": "24.12.2",
71
+ "@types/react": "19.2.14",
72
+ "@types/react-dom": "19.2.3",
73
+ "@types/react-window": "2.0.0",
74
+ "@vitejs/plugin-react": "6.0.1",
75
+ "chokidar-cli": "3.0.0",
76
+ "convex": "1.35.1",
77
+ "convex-helpers": "0.1.114",
78
+ "convex-test": "0.0.48",
79
+ "eslint": "9.39.4",
80
+ "eslint-plugin-react-hooks": "7.0.1",
81
+ "eslint-plugin-react-refresh": "0.5.2",
82
+ "globals": "17.5.0",
83
+ "npm-run-all2": "9.0.0",
84
+ "prettier": "3.8.3",
85
+ "react": "19.2.5",
86
+ "react-dom": "19.2.5",
87
+ "react-use": "17.6.0",
88
+ "react-window": "2.2.7",
89
+ "typescript": "5.9.3",
90
+ "typescript-eslint": "8.58.2",
91
+ "vite": "8.0.16",
92
+ "vitest": "4.1.4"
69
93
  },
70
- "main": "./dist/commonjs/client/index.js",
71
- "types": "./dist/commonjs/client/index.d.ts",
72
- "module": "./dist/esm/client/index.js"
94
+ "types": "./dist/client/index.d.ts",
95
+ "module": "./dist/client/index.js"
73
96
  }
@@ -1,15 +1,13 @@
1
- import {
1
+ import type {
2
2
  DocumentByName,
3
- Expand,
4
- FunctionReference,
3
+ GenericActionCtx,
5
4
  GenericDataModel,
6
5
  GenericMutationCtx,
7
6
  GenericQueryCtx,
8
7
  TableNamesInDataModel,
9
8
  } from "convex/server";
10
- import { GenericId } from "convex/values";
11
- import { api } from "../component/_generated/api";
12
-
9
+ import type { GenericId } from "convex/values";
10
+ import type { ComponentApi } from "../component/_generated/component.js";
13
11
  /**
14
12
  * A sharded counter is a map from string -> counter, where each counter can
15
13
  * be incremented or decremented atomically.
@@ -31,7 +29,7 @@ export class ShardedCounter<ShardsKey extends string> {
31
29
  * keys not in `options.shards`.
32
30
  */
33
31
  constructor(
34
- private component: UseApi<typeof api>,
32
+ private component: ComponentApi,
35
33
  options?: {
36
34
  shards?: Partial<Record<ShardsKey, number>>;
37
35
  defaultShards?: number;
@@ -59,7 +57,7 @@ export class ShardedCounter<ShardsKey extends string> {
59
57
  * @param count The amount to increment the counter by. Defaults to 1.
60
58
  */
61
59
  async add<Name extends ShardsKey>(
62
- ctx: RunMutationCtx,
60
+ ctx: MutationCtx | ActionCtx,
63
61
  name: Name,
64
62
  count: number = 1,
65
63
  ) {
@@ -76,7 +74,7 @@ export class ShardedCounter<ShardsKey extends string> {
76
74
  * Decrease the counter for key `name` by `count`.
77
75
  */
78
76
  async subtract<Name extends ShardsKey>(
79
- ctx: RunMutationCtx,
77
+ ctx: MutationCtx | ActionCtx,
80
78
  name: Name,
81
79
  count: number = 1,
82
80
  ) {
@@ -86,14 +84,14 @@ export class ShardedCounter<ShardsKey extends string> {
86
84
  /**
87
85
  * Increment the counter for key `name` by 1.
88
86
  */
89
- async inc<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name) {
87
+ async inc<Name extends ShardsKey>(ctx: MutationCtx | ActionCtx, name: Name) {
90
88
  return this.add(ctx, name, 1);
91
89
  }
92
90
 
93
91
  /**
94
92
  * Decrement the counter for key `name` by 1.
95
93
  */
96
- async dec<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name) {
94
+ async dec<Name extends ShardsKey>(ctx: MutationCtx | ActionCtx, name: Name) {
97
95
  return this.add(ctx, name, -1);
98
96
  }
99
97
 
@@ -103,7 +101,10 @@ export class ShardedCounter<ShardsKey extends string> {
103
101
  * NOTE: this reads from all shards. If used in a mutation, it will contend
104
102
  * with all mutations that update the counter for this key.
105
103
  */
106
- async count<Name extends ShardsKey>(ctx: RunQueryCtx, name: Name) {
104
+ async count<Name extends ShardsKey>(
105
+ ctx: QueryCtx | MutationCtx | ActionCtx,
106
+ name: Name,
107
+ ) {
107
108
  return ctx.runQuery(this.component.public.count, { name });
108
109
  }
109
110
 
@@ -119,7 +120,10 @@ export class ShardedCounter<ShardsKey extends string> {
119
120
  * This operation reads and writes all shards, so it can cause contention if
120
121
  * called too often.
121
122
  */
122
- async rebalance<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name) {
123
+ async rebalance<Name extends ShardsKey>(
124
+ ctx: MutationCtx | ActionCtx,
125
+ name: Name,
126
+ ) {
123
127
  await ctx.runMutation(this.component.public.rebalance, {
124
128
  name,
125
129
  shards: this.shardsForKey(name),
@@ -131,7 +135,10 @@ export class ShardedCounter<ShardsKey extends string> {
131
135
  *
132
136
  * @param name The key to clear the counter for.
133
137
  */
134
- async reset<Name extends ShardsKey>(ctx: RunMutationCtx, name: Name) {
138
+ async reset<Name extends ShardsKey>(
139
+ ctx: MutationCtx | ActionCtx,
140
+ name: Name,
141
+ ) {
135
142
  await ctx.runMutation(this.component.public.reset, { name });
136
143
  }
137
144
 
@@ -147,7 +154,7 @@ export class ShardedCounter<ShardsKey extends string> {
147
154
  * Use this to reduce contention when reading the counter.
148
155
  */
149
156
  async estimateCount<Name extends ShardsKey>(
150
- ctx: RunQueryCtx,
157
+ ctx: QueryCtx | MutationCtx | ActionCtx,
151
158
  name: Name,
152
159
  readFromShards: number = 1,
153
160
  ) {
@@ -177,50 +184,54 @@ export class ShardedCounter<ShardsKey extends string> {
177
184
  /**
178
185
  * Add `count` to the counter.
179
186
  */
180
- add: async (ctx: RunMutationCtx, count: number = 1) =>
187
+ add: async (ctx: MutationCtx | ActionCtx, count: number = 1) =>
181
188
  this.add(ctx, name, count),
182
189
  /**
183
190
  * Subtract `count` from the counter.
184
191
  */
185
- subtract: async (ctx: RunMutationCtx, count: number = 1) =>
192
+ subtract: async (ctx: MutationCtx | ActionCtx, count: number = 1) =>
186
193
  this.add(ctx, name, -count),
187
194
  /**
188
195
  * Increment the counter by 1.
189
196
  */
190
- inc: async (ctx: RunMutationCtx) => this.add(ctx, name, 1),
197
+ inc: async (ctx: MutationCtx | ActionCtx) => this.add(ctx, name, 1),
191
198
  /**
192
199
  * Decrement the counter by 1.
193
200
  */
194
- dec: async (ctx: RunMutationCtx) => this.add(ctx, name, -1),
201
+ dec: async (ctx: MutationCtx | ActionCtx) => this.add(ctx, name, -1),
195
202
  /**
196
203
  * Get the current value of the counter.
197
204
  *
198
205
  * NOTE: this reads from all shards. If used in a mutation, it will
199
206
  * contend with all mutations that update the counter for this key.
200
207
  */
201
- count: async (ctx: RunQueryCtx) => this.count(ctx, name),
208
+ count: async (ctx: QueryCtx | MutationCtx | ActionCtx) =>
209
+ this.count(ctx, name),
202
210
  /**
203
211
  * Reset the counter for this key.
204
212
  */
205
- reset: async (ctx: RunMutationCtx) => this.reset(ctx, name),
213
+ reset: async (ctx: MutationCtx | ActionCtx) => this.reset(ctx, name),
206
214
  /**
207
215
  * Redistribute counts evenly across the counter's shards.
208
216
  *
209
217
  * This operation reads and writes all shards, so it can cause contention
210
218
  * if called too often.
211
219
  */
212
- rebalance: async (ctx: RunMutationCtx) => this.rebalance(ctx, name),
220
+ rebalance: async (ctx: MutationCtx | ActionCtx) =>
221
+ this.rebalance(ctx, name),
213
222
  /**
214
223
  * Estimate the counter by only reading from a subset of shards,
215
224
  * and extrapolating the total count.
216
225
  *
217
226
  * Use this to reduce contention when reading the counter.
218
227
  */
219
- estimateCount: async (ctx: RunQueryCtx, readFromShards: number = 1) =>
220
- this.estimateCount(ctx, name, readFromShards),
228
+ estimateCount: async (
229
+ ctx: QueryCtx | MutationCtx | ActionCtx,
230
+ readFromShards: number = 1,
231
+ ) => this.estimateCount(ctx, name, readFromShards),
221
232
  };
222
233
  }
223
- trigger<Ctx extends RunMutationCtx, Name extends ShardsKey>(
234
+ trigger<Ctx extends MutationCtx, Name extends ShardsKey>(
224
235
  name: Name,
225
236
  ): Trigger<Ctx, GenericDataModel, TableNamesInDataModel<GenericDataModel>> {
226
237
  return async (ctx, change) => {
@@ -264,36 +275,12 @@ export type Change<
264
275
  }
265
276
  );
266
277
 
267
- type RunQueryCtx = {
268
- runQuery: GenericQueryCtx<GenericDataModel>["runQuery"];
269
- };
270
- type RunMutationCtx = {
271
- runMutation: GenericMutationCtx<GenericDataModel>["runMutation"];
272
- };
273
-
274
- export type OpaqueIds<T> =
275
- T extends GenericId<infer _T>
276
- ? string
277
- : T extends (infer U)[]
278
- ? OpaqueIds<U>[]
279
- : T extends object
280
- ? { [K in keyof T]: OpaqueIds<T[K]> }
281
- : T;
282
-
283
- export type UseApi<API> = Expand<{
284
- [mod in keyof API]: API[mod] extends FunctionReference<
285
- infer FType,
286
- "public",
287
- infer FArgs,
288
- infer FReturnType,
289
- infer FComponentPath
290
- >
291
- ? FunctionReference<
292
- FType,
293
- "internal",
294
- OpaqueIds<FArgs>,
295
- OpaqueIds<FReturnType>,
296
- FComponentPath
297
- >
298
- : UseApi<API[mod]>;
299
- }>;
278
+ type QueryCtx = Pick<GenericQueryCtx<GenericDataModel>, "runQuery">;
279
+ type MutationCtx = Pick<
280
+ GenericMutationCtx<GenericDataModel>,
281
+ "runQuery" | "runMutation"
282
+ >;
283
+ type ActionCtx = Pick<
284
+ GenericActionCtx<GenericDataModel>,
285
+ "runQuery" | "runMutation" | "runAction"
286
+ >;