kitcn 0.29.0 → 0.31.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 (71) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/aggregate/index.d.ts +2 -2
  3. package/dist/aggregate/index.js +1 -1
  4. package/dist/auth/generated/index.d.ts +1 -1
  5. package/dist/auth/generated/index.js +1 -1
  6. package/dist/auth/http/index.d.ts +1 -1
  7. package/dist/auth/index.d.ts +20 -20
  8. package/dist/auth/index.js +133 -9
  9. package/dist/auth/nextjs/index.d.ts +2 -2
  10. package/dist/auth/nextjs/index.js +3 -3
  11. package/dist/auth/start/server/index.d.ts +2 -2
  12. package/dist/auth/start/server/index.js +3 -3
  13. package/dist/{builder-CsAw-DK8.js → builder-Cyd5nCxZ.js} +2 -2
  14. package/dist/{caller-factory-D4pz5GcZ.js → caller-factory-C-N540BC.js} +3 -3
  15. package/dist/{capabilities-6PZBmvc8.d.ts → capabilities-DPB-JKlm.d.ts} +1 -1
  16. package/dist/cli.mjs +1 -1
  17. package/dist/{create-schema-orm-HcJzGCxj.js → create-schema-orm-CwJD930B.js} +1 -1
  18. package/dist/crpc/index.d.ts +2 -2
  19. package/dist/crpc/index.js +3 -3
  20. package/dist/{customFunctions-ivbc6-_g.js → customFunctions-X_B4kET8.js} +64 -1
  21. package/dist/{definitions-DS8ZDc74.js → definitions-3PX4ywR-.js} +2 -2
  22. package/dist/{extensions-Blzsyekm.js → extensions-Bp0XHanR.js} +1 -1
  23. package/dist/{generated-contract-disabled-CgYQZCw2.d.ts → generated-contract-disabled-CTUQ9nxL.d.ts} +70 -41
  24. package/dist/{generated-contract-disabled-_1Mjg9pW.js → generated-contract-disabled-RyPYlwq0.js} +1 -0
  25. package/dist/{http-types-90mapMP9.d.ts → http-types-BhhPZtwa.d.ts} +2 -2
  26. package/dist/{id-CuSfWa5q.js → id-BVdWER1U.js} +1 -1
  27. package/dist/{filter-expression-Dydt8wS0.js → index-utils-C1DyktHe.js} +95 -1
  28. package/dist/{local-env-Dk8RJvt5.mjs → local-env-DGSkmXQk.mjs} +6 -0
  29. package/dist/{middleware-CE_MC6Gi.d.ts → middleware-BBS7oLtT.d.ts} +1 -1
  30. package/dist/{middleware-BvnabcNq.js → middleware-D61Nm-iB.js} +1 -1
  31. package/dist/orm/aggregate-index/index.d.ts +1 -1
  32. package/dist/orm/aggregate-index/index.js +4 -3
  33. package/dist/orm/index.d.ts +4 -4
  34. package/dist/orm/index.js +44 -12
  35. package/dist/orm/migrations/index.d.ts +2 -2
  36. package/dist/orm/migrations/index.js +1 -1
  37. package/dist/plugins/index.d.ts +1 -1
  38. package/dist/plugins/index.js +1 -1
  39. package/dist/{procedure-caller-BR-Wb0si.js → procedure-caller-DgMiD0-a.js} +2 -2
  40. package/dist/{procedure-name-l2YusEZI.d.ts → procedure-name-DPYyLiVS.d.ts} +3 -3
  41. package/dist/ratelimit/index.d.ts +2 -2
  42. package/dist/ratelimit/index.js +3 -3
  43. package/dist/rsc/index.d.ts +4 -4
  44. package/dist/rsc/index.js +4 -4
  45. package/dist/{runtime-CcOvOf4K.js → runtime-BcvcfaP8.js} +2 -2
  46. package/dist/{schema-CzdjX7nx.js → schema-hL2FWCE7.js} +13 -97
  47. package/dist/server/index.d.ts +4 -4
  48. package/dist/server/index.js +4 -4
  49. package/dist/symbols-DDNAddkd.js +21 -0
  50. package/dist/{table-CX2lnX7e.js → table-d9o_n4R3.js} +2 -21
  51. package/dist/{token-B0NKKxqP.js → token-CuJopBdP.js} +1 -1
  52. package/dist/{types-In-ZZOsd.d.ts → types-BXpu7xIU.d.ts} +1 -1
  53. package/dist/watcher.mjs +1 -1
  54. package/dist/{where-clause-compiler-CX5-0M5p.d.ts → where-clause-compiler-Dddhscyy.d.ts} +65 -64
  55. package/package.json +1 -1
  56. package/skills/kitcn/references/features/orm.md +5 -0
  57. /package/dist/{api-entry-CkDpGYVg.js → api-entry-Buvjl9hn.js} +0 -0
  58. /package/dist/{context-utils-DwZ3Cam1.d.ts → context-utils-Cbv4r0AA.d.ts} +0 -0
  59. /package/dist/{convex-plugin-Dic0l-k8.js → convex-plugin-AbNQl1Sg.js} +0 -0
  60. /package/dist/{create-schema-ojI-OH_9.js → create-schema-BmVH4gPc.js} +0 -0
  61. /package/dist/{error-CMLeCadS.js → error-Dyqhgbf6.js} +0 -0
  62. /package/dist/{meta-utils-D2lqN2Lg.js → meta-utils-Cc7neQOB.js} +0 -0
  63. /package/dist/{query-context-DJONf8X5.d.ts → query-context-BkNjkDCk.d.ts} +0 -0
  64. /package/dist/{query-context-DOm5Xm3H.js → query-context-DdSg3fuk.js} +0 -0
  65. /package/dist/{query-options-DUiOj01a.js → query-options-DGG93--5.js} +0 -0
  66. /package/dist/{token-kQaqFby4.d.ts → token-tlbNKQS0.d.ts} +0 -0
  67. /package/dist/{transformer-D8wO-kEj.js → transformer-C8lVwHNT.js} +0 -0
  68. /package/dist/{types-eNzQmbqM.d.ts → types-Bkeicpo6.d.ts} +0 -0
  69. /package/dist/{types-MHYXboyy.d.ts → types-Bqi_ivSd.d.ts} +0 -0
  70. /package/dist/{types-Bf3XQex5.d.ts → types-ex0-J-SC.d.ts} +0 -0
  71. /package/dist/{validators-wOIjhkfN.d.ts → validators-0I-Ik1EN.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,52 @@
1
1
  # kitcn
2
2
 
3
+ ## 0.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#423](https://github.com/udecode/kitcn/pull/423) [`8dbe02a`](https://github.com/udecode/kitcn/commit/8dbe02abeb2a0a5495a33a6a8206fbe53bfd1a16) Thanks [@MikeyZhang75](https://github.com/MikeyZhang75)! - ## Breaking changes
8
+
9
+ - The generated auth runtime exports a new internal `count` query. Rerun
10
+ `npx kitcn codegen` and redeploy before upgrading — Better Auth's `count()`
11
+ calls it on every request that reads a total, and a deployment that predates
12
+ it will fail those requests with a missing-function error.
13
+
14
+ ```ts
15
+ // convex/functions/generated/auth.ts — regenerated
16
+ export const {
17
+ authEnabled,
18
+ authClient,
19
+ getAuth,
20
+ auth,
21
+ count,
22
+ create,
23
+ // ...
24
+ } = authRuntime;
25
+ ```
26
+
27
+ ## Patches
28
+
29
+ - Fix Better Auth's `count()` reading every matching row 200 at a time. A count
30
+ with no filter is now answered by Convex directly and reads no documents at
31
+ all, so `/admin/list-users` and any other total over a whole auth table no
32
+ longer scales with the table. Previously this ran one paginated query per 200
33
+ rows, and inside a query or mutation every one of those rows landed in the
34
+ same transaction, so a large enough table failed on the per-transaction
35
+ document-read limit instead of returning a number.
36
+ - Support constant-cost counts on filtered auth tables. When a table declares an
37
+ `aggregateIndex` whose fields exactly match the fields being counted, counts
38
+ such as members-per-organization read a bucket instead of the members. Counts
39
+ that no index can serve, including anything using `contains`, `ne`, `in`, or
40
+ an OR clause, still page through rows and return the same number as before.
41
+
42
+ ## 0.30.0
43
+
44
+ ### Minor Changes
45
+
46
+ - [#422](https://github.com/udecode/kitcn/pull/422) [`f677251`](https://github.com/udecode/kitcn/commit/f6772514d2525104ac6878c0eeb7334a84af981b) Thanks [@MikeyZhang75](https://github.com/MikeyZhang75)! - ## Patches
47
+
48
+ - Fix soft cascade delete re-reading every child it had already processed. New scheduled campaigns require and resume through an exact foreign-key index, keeping reads linear without allowing mutable trailing index fields to strand a child. Queued jobs reselect a newly available exact index or drain through the legacy replay path.
49
+
3
50
  ## 0.29.0
4
51
 
5
52
  ### Minor Changes
@@ -1,5 +1,5 @@
1
- import { Vn as ConvexTextBuilderInitial, Zt as ConvexTableWithColumns } from "../capabilities-6PZBmvc8.js";
2
- import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-CX5-0M5p.js";
1
+ import { Vn as ConvexTextBuilderInitial, Zt as ConvexTableWithColumns } from "../capabilities-DPB-JKlm.js";
2
+ import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-Dddhscyy.js";
3
3
  import * as convex_values0 from "convex/values";
4
4
  import { GenericId, Infer, Value } from "convex/values";
5
5
  import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
@@ -1,4 +1,4 @@
1
- import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-CcOvOf4K.js";
1
+ import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-BcvcfaP8.js";
2
2
 
3
3
  //#region src/aggregate/index.ts
4
4
  const wrapTriggerFactory = (methodName, factory) => ((...args) => {
@@ -1,2 +1,2 @@
1
- import { C as GenericAuthTriggers, S as GenericAuthTriggerHandlers, b as GenericAuthDefinition, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, v as BetterAuthOptionsWithoutDatabase, w as defineAuth, x as GenericAuthTriggerChange, y as GenericAuthBeforeResult } from "../../generated-contract-disabled-CgYQZCw2.js";
1
+ import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, b as GenericAuthBeforeResult, i as getGeneratedAuthDisabledReason, n as GeneratedAuthDisabledReasonKind, r as createDisabledAuthRuntime, t as AuthRuntime, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../../generated-contract-disabled-CTUQ9nxL.js";
2
2
  export { type AuthRuntime, BetterAuthOptionsWithoutDatabase, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, createDisabledAuthRuntime, defineAuth, getGeneratedAuthDisabledReason };
@@ -1,3 +1,3 @@
1
- import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason } from "../../generated-contract-disabled-_1Mjg9pW.js";
1
+ import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason } from "../../generated-contract-disabled-RyPYlwq0.js";
2
2
 
3
3
  export { createDisabledAuthRuntime, defineAuth, getGeneratedAuthDisabledReason };
@@ -1,4 +1,4 @@
1
- import { t as GetAuth } from "../../types-Bf3XQex5.js";
1
+ import { t as GetAuth } from "../../types-ex0-J-SC.js";
2
2
  import { HttpRouter } from "convex/server";
3
3
  import { MiddlewareHandler } from "hono";
4
4
  import { BaseURLConfig, BetterAuthOptions } from "better-auth";
@@ -1,7 +1,7 @@
1
- import { a as QueryCtxWithPreferredOrmQueryTable, n as LookupByIdResultByCtx, t as DocByCtx } from "../query-context-DJONf8X5.js";
2
- import { t as GetAuth } from "../types-Bf3XQex5.js";
3
- import { t as GenericCtx } from "../context-utils-DwZ3Cam1.js";
4
- import { C as GenericAuthTriggers, S as GenericAuthTriggerHandlers, _ as updateOneHandler, a as AuthFunctions, b as GenericAuthDefinition, c as consumeOneHandler, d as deleteManyHandler, f as deleteOneHandler, g as updateManyHandler, h as incrementOneHandler, i as getGeneratedAuthDisabledReason, l as createApi, m as findOneHandler, n as GeneratedAuthDisabledReasonKind, o as Triggers, p as findManyHandler, r as createDisabledAuthRuntime, s as createClient, t as AuthRuntime, u as createHandler, v as BetterAuthOptionsWithoutDatabase, w as defineAuth, x as GenericAuthTriggerChange, y as GenericAuthBeforeResult } from "../generated-contract-disabled-CgYQZCw2.js";
1
+ import { a as QueryCtxWithPreferredOrmQueryTable, n as LookupByIdResultByCtx, t as DocByCtx } from "../query-context-BkNjkDCk.js";
2
+ import { t as GetAuth } from "../types-ex0-J-SC.js";
3
+ import { t as GenericCtx } from "../context-utils-Cbv4r0AA.js";
4
+ import { C as GenericAuthTriggerHandlers, S as GenericAuthTriggerChange, T as defineAuth, _ as updateManyHandler, a as AuthFunctions, b as GenericAuthBeforeResult, c as consumeOneHandler, d as createHandler, f as deleteManyHandler, g as incrementOneHandler, h as findOneHandler, i as getGeneratedAuthDisabledReason, l as countHandler, m as findManyHandler, n as GeneratedAuthDisabledReasonKind, o as Triggers, p as deleteOneHandler, r as createDisabledAuthRuntime, s as createClient, t as AuthRuntime, u as createApi, v as updateOneHandler, w as GenericAuthTriggers, x as GenericAuthDefinition, y as BetterAuthOptionsWithoutDatabase } from "../generated-contract-disabled-CTUQ9nxL.js";
5
5
  import * as convex_values0 from "convex/values";
6
6
  import { Infer } from "convex/values";
7
7
  import { AuthConfig, DocumentByName, GenericDataModel, GenericMutationCtx, GenericQueryCtx, GenericSchema, PaginationOptions, PaginationResult, SchemaDefinition, TableNamesInDataModel } from "convex/server";
@@ -109,28 +109,28 @@ type AdapterPaginationOptions = PaginationOptions & {
109
109
  };
110
110
  declare const adapterWhereValidator: convex_values0.VObject<{
111
111
  mode?: "sensitive" | "insensitive" | undefined;
112
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
112
113
  connector?: "AND" | "OR" | undefined;
113
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
114
- field: string;
115
114
  value: string | number | boolean | string[] | number[] | null;
115
+ field: string;
116
116
  }, {
117
117
  connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
118
118
  field: convex_values0.VString<string, "required">;
119
119
  mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
120
- operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
120
+ operator: convex_values0.VUnion<"eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
121
121
  value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
122
- }, "required", "mode" | "connector" | "field" | "operator" | "value">;
122
+ }, "required", "mode" | "operator" | "value" | "field" | "connector">;
123
123
  declare const adapterArgsValidator: convex_values0.VObject<{
124
+ limit?: number | undefined;
124
125
  where?: {
125
126
  mode?: "sensitive" | "insensitive" | undefined;
127
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
126
128
  connector?: "AND" | "OR" | undefined;
127
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
128
- field: string;
129
129
  value: string | number | boolean | string[] | number[] | null;
130
+ field: string;
130
131
  }[] | undefined;
131
- limit?: number | undefined;
132
- offset?: number | undefined;
133
132
  select?: string[] | undefined;
133
+ offset?: number | undefined;
134
134
  sortBy?: {
135
135
  field: string;
136
136
  direction: "asc" | "desc";
@@ -150,24 +150,24 @@ declare const adapterArgsValidator: convex_values0.VObject<{
150
150
  }, "optional", "field" | "direction">;
151
151
  where: convex_values0.VArray<{
152
152
  mode?: "sensitive" | "insensitive" | undefined;
153
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
153
154
  connector?: "AND" | "OR" | undefined;
154
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
155
- field: string;
156
155
  value: string | number | boolean | string[] | number[] | null;
156
+ field: string;
157
157
  }[] | undefined, convex_values0.VObject<{
158
158
  mode?: "sensitive" | "insensitive" | undefined;
159
+ operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined;
159
160
  connector?: "AND" | "OR" | undefined;
160
- operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
161
- field: string;
162
161
  value: string | number | boolean | string[] | number[] | null;
162
+ field: string;
163
163
  }, {
164
164
  connector: convex_values0.VUnion<"AND" | "OR" | undefined, [convex_values0.VLiteral<"AND", "required">, convex_values0.VLiteral<"OR", "required">], "optional", never>;
165
165
  field: convex_values0.VString<string, "required">;
166
166
  mode: convex_values0.VUnion<"sensitive" | "insensitive" | undefined, [convex_values0.VLiteral<"sensitive", "required">, convex_values0.VLiteral<"insensitive", "required">], "optional", never>;
167
- operator: convex_values0.VUnion<"lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
167
+ operator: convex_values0.VUnion<"eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
168
168
  value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
169
- }, "required", "mode" | "connector" | "field" | "operator" | "value">, "optional">;
170
- }, "required", "model" | "where" | "limit" | "offset" | "select" | "sortBy" | "sortBy.field" | "sortBy.direction">;
169
+ }, "required", "mode" | "operator" | "value" | "field" | "connector">, "optional">;
170
+ }, "required", "limit" | "where" | "model" | "select" | "offset" | "sortBy" | "sortBy.field" | "sortBy.direction">;
171
171
  declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
172
172
  declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
173
173
  declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => D | null;
@@ -531,4 +531,4 @@ declare const convex: (opts: {
531
531
  };
532
532
  };
533
533
  //#endregion
534
- export { type AuthFunctions, type AuthRuntime, BetterAuthOptionsWithoutDatabase, ConvexCleanedWhere, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, GetAuth, SessionClientSignals, type Triggers, adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
534
+ export { type AuthFunctions, type AuthRuntime, BetterAuthOptionsWithoutDatabase, ConvexCleanedWhere, type GeneratedAuthDisabledReasonKind, GenericAuthBeforeResult, GenericAuthDefinition, GenericAuthTriggerChange, GenericAuthTriggerHandlers, GenericAuthTriggers, GetAuth, SessionClientSignals, type Triggers, adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
@@ -1,11 +1,11 @@
1
1
  import { n as asyncMap } from "../upstream-BCgGZX6q.js";
2
2
  import { r as partial } from "../validators-CIoUYCqO.js";
3
- import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason, t as DEFAULT_AUTH_DEFINITION_PATH } from "../generated-contract-disabled-_1Mjg9pW.js";
4
- import { n as createGeneratedFunctionReference, o as isQueryCtx, s as isRunMutationCtx } from "../api-entry-CkDpGYVg.js";
5
- import { n as customCtx, r as customMutation } from "../customFunctions-ivbc6-_g.js";
6
- import { l as eq } from "../filter-expression-Dydt8wS0.js";
7
- import { o as mergedStream, s as stream, t as getByIdWithOrmQueryFallback, u as unsetToken } from "../query-context-DOm5Xm3H.js";
8
- import { n as convex } from "../convex-plugin-Dic0l-k8.js";
3
+ import { i as defineAuth, n as createDisabledAuthRuntime, r as getGeneratedAuthDisabledReason, t as DEFAULT_AUTH_DEFINITION_PATH } from "../generated-contract-disabled-RyPYlwq0.js";
4
+ import { n as createGeneratedFunctionReference, o as isQueryCtx, s as isRunMutationCtx } from "../api-entry-Buvjl9hn.js";
5
+ import { i as customQuery, n as customCtx, r as customMutation } from "../customFunctions-X_B4kET8.js";
6
+ import { C as eq, o as getAggregateIndexes } from "../index-utils-C1DyktHe.js";
7
+ import { o as mergedStream, s as stream, t as getByIdWithOrmQueryFallback, u as unsetToken } from "../query-context-DdSg3fuk.js";
8
+ import { n as convex } from "../convex-plugin-AbNQl1Sg.js";
9
9
  import { v } from "convex/values";
10
10
  import { internalActionGeneric, internalMutationGeneric, internalQueryGeneric, paginationOptsValidator } from "convex/server";
11
11
  import { createAdapterFactory } from "better-auth/adapters";
@@ -346,6 +346,66 @@ const listOne = async (ctx, schema, betterAuthSchema, args) => {
346
346
  }
347
347
  };
348
348
 
349
+ //#endregion
350
+ //#region src/auth/count-plan.ts
351
+ /**
352
+ * Better Auth's `createdAt` maps onto `_creationTime` inside the paginated read
353
+ * path, and `_creationTime` cannot back an `aggregateIndex`. Counting on either
354
+ * timestamp would compare against a column the ORM does not index.
355
+ */
356
+ const UNBOUNDABLE_FIELDS = new Set(["createdAt", "updatedAt"]);
357
+ /**
358
+ * Translate a Better Auth `Where[]` into an ORM `count({ where })` object.
359
+ *
360
+ * Returns `null` for every shape a bounded count cannot serve. `null` is not an
361
+ * error: the caller falls back to walking pages, which returns the same number
362
+ * and is merely linear in matching rows.
363
+ *
364
+ * Only equality on a plain scalar translates. `OR` is excluded because both
365
+ * adapters de-duplicate documents by id across OR clauses, which a scalar count
366
+ * cannot reproduce. The remaining operators (`ne`, `in`, `not_in`, `contains`,
367
+ * `starts_with`, `ends_with`, and any insensitive comparison) are applied as JS
368
+ * post-filters on the read path, so no index can bound them.
369
+ */
370
+ const toOrmCountWhere = (where) => {
371
+ if (!where?.length) return {};
372
+ const result = {};
373
+ for (const clause of where) {
374
+ if (clause.connector === "OR" || clause.mode === "insensitive") return null;
375
+ if ((clause.operator ?? "eq") !== "eq") return null;
376
+ if (clause.value === null || Array.isArray(clause.value)) return null;
377
+ if (UNBOUNDABLE_FIELDS.has(clause.field) || clause.field in result) return null;
378
+ result[clause.field] = clause.value;
379
+ }
380
+ return result;
381
+ };
382
+ /**
383
+ * Whether the table declares an `aggregateIndex` covering exactly `fields`.
384
+ *
385
+ * The ORM's count planner matches an aggregate index as an exact set, not a
386
+ * prefix, so an index on `[organizationId]` serves `{ organizationId }` and
387
+ * nothing else. Checking here keeps the caller's error handling narrow: a
388
+ * declared aggregate index also guarantees the aggregate capability is
389
+ * registered, because `createOrm` fails closed otherwise.
390
+ */
391
+ const hasExactAggregateIndex = (table, fields) => {
392
+ const requested = new Set(fields);
393
+ return getAggregateIndexes(table).some((index) => index.fields.length === requested.size && index.fields.every((field) => requested.has(field)));
394
+ };
395
+ const BOUNDED_COUNT_REFUSALS = [
396
+ "COUNT_NOT_INDEXED:",
397
+ "COUNT_INDEX_BUILDING:",
398
+ "COUNT_FILTER_UNSUPPORTED:",
399
+ "COUNT_RLS_UNSUPPORTED:"
400
+ ];
401
+ /**
402
+ * Whether the ORM declined to serve a count rather than failing at it.
403
+ *
404
+ * A refusal is safe to swallow: the paginated walk produces the same number.
405
+ * Anything else is a real error and must surface.
406
+ */
407
+ const isBoundedCountRefusal = (error) => error instanceof Error && BOUNDED_COUNT_REFUSALS.some((code) => error.message.startsWith(code));
408
+
349
409
  //#endregion
350
410
  //#region src/auth/create-api.ts
351
411
  const AUTH_TABLE_TRIGGER_KEYS = new Set([
@@ -543,6 +603,50 @@ const createHandler = async (ctx, args, schema, betterAuthSchema) => {
543
603
  return toConvexSafe(result);
544
604
  };
545
605
  const findOneHandler = async (ctx, args, schema, betterAuthSchema) => toConvexSafe(await listOne(ctx, schema, betterAuthSchema, args));
606
+ /**
607
+ * Convex's table count is internal API and absent from its published typings,
608
+ * so probe for it instead of assuming the deployment exposes it.
609
+ */
610
+ const nativeTableCount = async (ctx, tableName) => {
611
+ const query = ctx?.db?.query?.(tableName);
612
+ if (typeof query?.count !== "function") return null;
613
+ try {
614
+ return await query.count();
615
+ } catch {
616
+ return null;
617
+ }
618
+ };
619
+ /**
620
+ * Row count for one Better Auth model, or `null` when the requested shape can
621
+ * only be answered by reading the rows.
622
+ *
623
+ * Two shapes are bounded:
624
+ * - An empty `where` uses Convex's native table count, which reads no
625
+ * documents. This is the shape `countTotalUsers` issues, and the only one
626
+ * that also works on a plain (non-ORM) auth schema.
627
+ * - An equality-only `where` whose field set exactly matches a declared
628
+ * `aggregateIndex` reads a constant number of bucket rows through the ORM.
629
+ *
630
+ * Everything else returns `null` so the caller walks pages instead. That walk
631
+ * returns the same number; it is only linear in matching rows.
632
+ */
633
+ const countHandler = async (ctx, args, schema, betterAuthSchema) => {
634
+ const tableName = resolveSchemaTableName(schema, betterAuthSchema, args.model);
635
+ if (!tableName) return null;
636
+ const where = toOrmCountWhere(args.where);
637
+ if (!where) return null;
638
+ const fields = Object.keys(where);
639
+ if (fields.length === 0) return await nativeTableCount(ctx, tableName);
640
+ const builder = ctx?.orm?.query?.[tableName];
641
+ if (typeof builder?.count !== "function") return null;
642
+ if (!hasExactAggregateIndex(schema.tables[tableName], fields)) return null;
643
+ try {
644
+ return await builder.count({ where });
645
+ } catch (error) {
646
+ if (isBoundedCountRefusal(error)) return null;
647
+ throw error;
648
+ }
649
+ };
546
650
  const findManyHandler = async (ctx, args, schema, betterAuthSchema) => toConvexSafe(await paginate(ctx, schema, betterAuthSchema, args));
547
651
  const updateOneHandler = async (ctx, args, schema, betterAuthSchema) => {
548
652
  const triggerCtx = args.triggerCtx ?? ctx;
@@ -713,6 +817,7 @@ const createApi = (schema, getAuth, options) => {
713
817
  };
714
818
  const mutationBuilderBase = internalMutation ?? internalMutationGeneric;
715
819
  const mutationBuilder = context ? customMutation(mutationBuilderBase, customCtx(async (ctx) => await context?.(ctx) ?? ctx)) : mutationBuilderBase;
820
+ const countQueryBuilder = context ? customQuery(internalQueryGeneric, customCtx(async (ctx) => await context?.(ctx) ?? ctx)) : internalQueryGeneric;
716
821
  const resolveTableTriggers = (model, triggerCtx) => {
717
822
  const tableTriggers = (typeof triggers === "function" ? triggers(triggerCtx) : triggers)?.[model];
718
823
  return ensureRuntimeTableTriggers(model, tableTriggers);
@@ -761,6 +866,13 @@ const createApi = (schema, getAuth, options) => {
761
866
  where: v.optional(v.array(adapterWhereValidator))
762
867
  });
763
868
  return {
869
+ count: countQueryBuilder({
870
+ args: {
871
+ model: modelValidator,
872
+ where: v.optional(v.array(adapterWhereValidator))
873
+ },
874
+ handler: async (ctx, args) => countHandler(ctx, args, schema, getBetterAuthSchema())
875
+ }),
764
876
  consumeOne: mutationBuilder({
765
877
  args: { input: deleteInput },
766
878
  handler: async (ctx, args) => {
@@ -1013,13 +1125,13 @@ const ORM_SCHEMA_OPTIONS = Symbol.for("kitcn:OrmSchemaOptions");
1013
1125
  const hasOrmSchemaMetadata = (schema) => !!schema && typeof schema === "object" && ORM_SCHEMA_OPTIONS in schema;
1014
1126
  const createAuthSchema = async ({ file, schema, tables }) => {
1015
1127
  if (hasOrmSchemaMetadata(schema)) {
1016
- const { createSchemaOrm } = await import("../create-schema-orm-HcJzGCxj.js");
1128
+ const { createSchemaOrm } = await import("../create-schema-orm-CwJD930B.js");
1017
1129
  return createSchemaOrm({
1018
1130
  file,
1019
1131
  tables
1020
1132
  });
1021
1133
  }
1022
- const { createSchema } = await import("../create-schema-ojI-OH_9.js");
1134
+ const { createSchema } = await import("../create-schema-BmVH4gPc.js");
1023
1135
  return createSchema({
1024
1136
  file,
1025
1137
  tables
@@ -1051,6 +1163,11 @@ const httpAdapter = (ctx, { authFunctions, debugLogs, schema }) => {
1051
1163
  paginationOpts,
1052
1164
  where: parseWhere(w)
1053
1165
  })))).flatMap((r) => r.docs)).length;
1166
+ const bounded = await ctx.runQuery(authFunctions.count, {
1167
+ model: data.model,
1168
+ where: parseWhere(data.where)
1169
+ });
1170
+ if (bounded !== null) return bounded;
1054
1171
  return (await handlePagination(async ({ paginationOpts }) => await ctx.runQuery(authFunctions.findMany, {
1055
1172
  ...data,
1056
1173
  paginationOpts,
@@ -1227,6 +1344,11 @@ const dbAdapter = (ctx, { authFunctions, debugLogs, getBetterAuthSchema, schema
1227
1344
  paginationOpts,
1228
1345
  where: parseWhere(w)
1229
1346
  }, schema, betterAuthSchema)))).flatMap((r) => r.docs)).length;
1347
+ const bounded = await countHandler(ctx, {
1348
+ model: data.model,
1349
+ where: parseWhere(data.where)
1350
+ }, schema, betterAuthSchema);
1351
+ if (bounded !== null) return bounded;
1230
1352
  return (await handlePagination(async ({ paginationOpts }) => await findManyHandler(ctx, {
1231
1353
  ...data,
1232
1354
  paginationOpts,
@@ -1452,6 +1574,7 @@ const createLazyAuthProxy = (resolve) => new Proxy({}, { get(_target, prop, rece
1452
1574
  return typeof value === "function" ? value.bind(auth) : value;
1453
1575
  } });
1454
1576
  const AUTH_RUNTIME_PROCEDURE_TYPES = {
1577
+ count: "query",
1455
1578
  consumeOne: "mutation",
1456
1579
  create: "mutation",
1457
1580
  deleteMany: "mutation",
@@ -1468,6 +1591,7 @@ const createGeneratedInternalFunctionReference = (name) => createGeneratedFuncti
1468
1591
  const resolveAuthFunctions = (internal, moduleName) => {
1469
1592
  const existing = internal?.[moduleName] ?? {};
1470
1593
  return {
1594
+ count: existing.count ?? createGeneratedInternalFunctionReference(`${moduleName}:count`),
1471
1595
  consumeOne: existing.consumeOne ?? createGeneratedInternalFunctionReference(`${moduleName}:consumeOne`),
1472
1596
  create: existing.create ?? createGeneratedInternalFunctionReference(`${moduleName}:create`),
1473
1597
  deleteMany: existing.deleteMany ?? createGeneratedInternalFunctionReference(`${moduleName}:deleteMany`),
@@ -1609,4 +1733,4 @@ const getHeaders = async (ctx, session) => {
1609
1733
  };
1610
1734
 
1611
1735
  //#endregion
1612
- export { adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
1736
+ export { adapterArgsValidator, adapterConfig, adapterWhereValidator, checkUniqueFields, consumeOneHandler, convex, countHandler, createApi, createAuthRuntime, createClient, createDisabledAuthRuntime, createHandler, dbAdapter, defineAuth, deleteManyHandler, deleteOneHandler, findManyHandler, findOneHandler, getAuthUserId, getAuthUserIdentity, getGeneratedAuthDisabledReason, getHeaders, getInvalidAuthDefinitionExportReason, getSession, getSessionNetworkSignals, handlePagination, hasUniqueFields, httpAdapter, incrementOneHandler, listOne, paginate, resolveGeneratedAuthDefinition, selectFields, updateManyHandler, updateOneHandler };
@@ -1,5 +1,5 @@
1
- import { H as ConvexContext, W as LazyCaller } from "../../procedure-name-l2YusEZI.js";
2
- import { t as GetTokenOptions } from "../../token-kQaqFby4.js";
1
+ import { H as ConvexContext, W as LazyCaller } from "../../procedure-name-DPYyLiVS.js";
2
+ import { t as GetTokenOptions } from "../../token-tlbNKQS0.js";
3
3
 
4
4
  //#region src/auth-nextjs/index.d.ts
5
5
  /** Auth options for server-side calls. */
@@ -1,6 +1,6 @@
1
- import { t as getToken } from "../../token-B0NKKxqP.js";
2
- import { n as defaultIsUnauthorized } from "../../error-CMLeCadS.js";
3
- import { t as createCallerFactory } from "../../caller-factory-D4pz5GcZ.js";
1
+ import { t as getToken } from "../../token-CuJopBdP.js";
2
+ import { n as defaultIsUnauthorized } from "../../error-Dyqhgbf6.js";
3
+ import { t as createCallerFactory } from "../../caller-factory-C-N540BC.js";
4
4
 
5
5
  //#region src/auth-nextjs/index.ts
6
6
  /** biome-ignore-all lint/suspicious/noExplicitAny: lib */
@@ -1,5 +1,5 @@
1
- import { H as ConvexContext, W as LazyCaller } from "../../../procedure-name-l2YusEZI.js";
2
- import { t as GetTokenOptions } from "../../../token-kQaqFby4.js";
1
+ import { H as ConvexContext, W as LazyCaller } from "../../../procedure-name-DPYyLiVS.js";
2
+ import { t as GetTokenOptions } from "../../../token-tlbNKQS0.js";
3
3
  import { FunctionReference, FunctionReturnType, OptionalRestArgs } from "convex/server";
4
4
 
5
5
  //#region src/auth-start/server.d.ts
@@ -1,6 +1,6 @@
1
- import { t as getToken } from "../../../token-B0NKKxqP.js";
2
- import { n as defaultIsUnauthorized } from "../../../error-CMLeCadS.js";
3
- import { t as createCallerFactory } from "../../../caller-factory-D4pz5GcZ.js";
1
+ import { t as getToken } from "../../../token-CuJopBdP.js";
2
+ import { n as defaultIsUnauthorized } from "../../../error-Dyqhgbf6.js";
3
+ import { t as createCallerFactory } from "../../../caller-factory-C-N540BC.js";
4
4
  import { stripIndent } from "common-tags";
5
5
  import { getRequest } from "@tanstack/react-start/server";
6
6
  import { ConvexHttpClient } from "convex/browser";
@@ -1,6 +1,6 @@
1
1
  import { o as vRequired, t as addFieldsToValidator } from "./validators-CIoUYCqO.js";
2
- import { n as customCtx, t as NoOp } from "./customFunctions-ivbc6-_g.js";
3
- import { s as getTransformer } from "./transformer-D8wO-kEj.js";
2
+ import { n as customCtx, t as NoOp } from "./customFunctions-X_B4kET8.js";
3
+ import { s as getTransformer } from "./transformer-C8lVwHNT.js";
4
4
  import { ConvexError, v } from "convex/values";
5
5
  import { HttpRouter, actionGeneric, httpActionGeneric, internalActionGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric } from "convex/server";
6
6
  import * as z$1 from "zod";
@@ -1,6 +1,6 @@
1
- import { n as defaultIsUnauthorized } from "./error-CMLeCadS.js";
2
- import { i as getFunctionType, n as getFuncRef, t as buildMetaIndex } from "./meta-utils-D2lqN2Lg.js";
3
- import { s as getTransformer } from "./transformer-D8wO-kEj.js";
1
+ import { n as defaultIsUnauthorized } from "./error-Dyqhgbf6.js";
2
+ import { i as getFunctionType, n as getFuncRef, t as buildMetaIndex } from "./meta-utils-Cc7neQOB.js";
3
+ import { s as getTransformer } from "./transformer-C8lVwHNT.js";
4
4
  import { fetchAction, fetchMutation, fetchQuery } from "convex/nextjs";
5
5
 
6
6
  //#region src/server/caller.ts
@@ -1,4 +1,4 @@
1
- import { a as ReturnTypeOrValue, i as KnownKeysOnly, o as Simplify, t as Assume } from "./types-MHYXboyy.js";
1
+ import { a as ReturnTypeOrValue, i as KnownKeysOnly, o as Simplify, t as Assume } from "./types-Bqi_ivSd.js";
2
2
  import * as convex_values0 from "convex/values";
3
3
  import { GenericId, Validator, Value } from "convex/values";
4
4
  import { FilterExpression, GenericDatabaseReader, GenericDatabaseWriter, GenericIndexFields, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IndexRange, IndexRangeBuilder, SchedulableFunctionReference, Scheduler, SchemaDefinition, TableDefinition, VectorFilterBuilder } from "convex/server";
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { C as Columns, D as TableName, E as RlsPolicies, O as createSystemFields, S as getRankIndexes, T as OrmSchemaExtensions, _ as loadEsbuild, a as generateMeta, b as getAggregateIndexes, c as resolveSchemaDefaultExport, f as createProjectJiti, g as loadDotenv, h as loadClackPrompts, i as resolveConfiguredBackend, l as schemaDeclaresAggregateIndexes, m as loadBabelParser, n as withLocalCodegenEnv, o as getConvexConfig, p as CRPC_BUILDER_STUB_SOURCE, r as loadCliConfig, s as collectSchemaTables, t as getLocalBackendEnvVars, u as logger, v as highlighter, w as EnableRLS, x as getIndexes, y as isColorEnabled } from "./local-env-Dk8RJvt5.mjs";
2
+ import { C as Columns, D as TableName, E as RlsPolicies, O as createSystemFields, S as getRankIndexes, T as OrmSchemaExtensions, _ as loadEsbuild, a as generateMeta, b as getAggregateIndexes, c as resolveSchemaDefaultExport, f as createProjectJiti, g as loadDotenv, h as loadClackPrompts, i as resolveConfiguredBackend, l as schemaDeclaresAggregateIndexes, m as loadBabelParser, n as withLocalCodegenEnv, o as getConvexConfig, p as CRPC_BUILDER_STUB_SOURCE, r as loadCliConfig, s as collectSchemaTables, t as getLocalBackendEnvVars, u as logger, v as highlighter, w as EnableRLS, x as getIndexes, y as isColorEnabled } from "./local-env-DGSkmXQk.mjs";
3
3
  import { createRequire } from "node:module";
4
4
  import fs, { existsSync, readFileSync } from "node:fs";
5
5
  import path, { basename, delimiter, dirname, extname, isAbsolute, join, posix, relative, resolve } from "node:path";
@@ -1,4 +1,4 @@
1
- import { augmentBetterAuthTables, indexFields } from "./create-schema-ojI-OH_9.js";
1
+ import { augmentBetterAuthTables, indexFields } from "./create-schema-BmVH4gPc.js";
2
2
 
3
3
  //#region src/auth/create-schema-orm.ts
4
4
  const specialFields = (tables) => Object.fromEntries(Object.entries(tables).map(([key, table]) => {
@@ -1,5 +1,5 @@
1
- import { B as dateWireCodec, F as DATE_CODEC_TAG, G as identityTransformer, H as defaultCRPCTransformer, I as DataTransformer, L as DataTransformerOptions, P as CombinedDataTransformer, R as WireCodec, U as encodeWire, V as decodeWire, W as getTransformer, a as HttpErrorCode, c as HttpQueryKey, d as HttpRouteMap, f as InferHttpInput, g as isHttpClientError, h as buildHttpQueryPrefixKey, i as HttpClientFromRouter, l as HttpQueryPrefixKey, m as buildHttpQueryKey, n as HttpClient, o as HttpMutationKey, p as InferHttpOutput, r as HttpClientError, s as HttpProcedureCall, t as HTTP_DEFAULT_STALE_TIME, u as HttpRouteInfo, z as createTaggedTransformer } from "../http-types-90mapMP9.js";
2
- import { A as HttpInputArgs, C as ReservedMutationOptions, D as VanillaMutation, E as VanillaAction, F as replaceUrlParam, M as RESERVED_KEYS, N as buildSearchParams, O as HttpClientOptions, P as executeHttpRequest, S as ReservedInfiniteQueryOptions, T as StaticQueryOptsParam, _ as IsPaginated, a as BaseInfiniteQueryOptsParam, b as PaginatedFnMeta, c as ConvexMutationKey, d as ConvexQueryMeta, f as EmptyObject, g as InfiniteQueryInput, h as FnMeta, i as BaseConvexQueryOptions, j as HttpProxyBaseOptions, k as HttpFormValue, l as ConvexQueryHookOptions, m as FUNC_REF_SYMBOL, n as BaseConvexActionOptions, o as ConvexActionKey, p as ExtractPaginatedItem, r as BaseConvexInfiniteQueryOptions, s as ConvexInfiniteQueryMeta, t as AuthType, u as ConvexQueryKey, v as Meta, w as ReservedQueryOptions, x as PaginationOpts, y as MutationVariables } from "../types-In-ZZOsd.js";
1
+ import { B as dateWireCodec, F as DATE_CODEC_TAG, G as identityTransformer, H as defaultCRPCTransformer, I as DataTransformer, L as DataTransformerOptions, P as CombinedDataTransformer, R as WireCodec, U as encodeWire, V as decodeWire, W as getTransformer, a as HttpErrorCode, c as HttpQueryKey, d as HttpRouteMap, f as InferHttpInput, g as isHttpClientError, h as buildHttpQueryPrefixKey, i as HttpClientFromRouter, l as HttpQueryPrefixKey, m as buildHttpQueryKey, n as HttpClient, o as HttpMutationKey, p as InferHttpOutput, r as HttpClientError, s as HttpProcedureCall, t as HTTP_DEFAULT_STALE_TIME, u as HttpRouteInfo, z as createTaggedTransformer } from "../http-types-BhhPZtwa.js";
2
+ import { A as HttpInputArgs, C as ReservedMutationOptions, D as VanillaMutation, E as VanillaAction, F as replaceUrlParam, M as RESERVED_KEYS, N as buildSearchParams, O as HttpClientOptions, P as executeHttpRequest, S as ReservedInfiniteQueryOptions, T as StaticQueryOptsParam, _ as IsPaginated, a as BaseInfiniteQueryOptsParam, b as PaginatedFnMeta, c as ConvexMutationKey, d as ConvexQueryMeta, f as EmptyObject, g as InfiniteQueryInput, h as FnMeta, i as BaseConvexQueryOptions, j as HttpProxyBaseOptions, k as HttpFormValue, l as ConvexQueryHookOptions, m as FUNC_REF_SYMBOL, n as BaseConvexActionOptions, o as ConvexActionKey, p as ExtractPaginatedItem, r as BaseConvexInfiniteQueryOptions, s as ConvexInfiniteQueryMeta, t as AuthType, u as ConvexQueryKey, v as Meta, w as ReservedQueryOptions, x as PaginationOpts, y as MutationVariables } from "../types-BXpu7xIU.js";
3
3
  import { FunctionArgs, FunctionReference } from "convex/server";
4
4
 
5
5
  //#region src/crpc/auth-error.d.ts
@@ -1,6 +1,6 @@
1
- import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-CMLeCadS.js";
2
- import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-D8wO-kEj.js";
3
- import { a as buildSearchParams, c as HTTP_DEFAULT_STALE_TIME, d as buildHttpQueryPrefixKey, f as isHttpClientError, i as RESERVED_KEYS, l as HttpClientError, n as convexInfiniteQueryOptions, o as executeHttpRequest, r as convexQuery, s as replaceUrlParam, t as convexAction, u as buildHttpQueryKey } from "../query-options-DUiOj01a.js";
1
+ import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r as isCRPCClientError, t as CRPCClientError } from "../error-Dyqhgbf6.js";
2
+ import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-C8lVwHNT.js";
3
+ import { a as buildSearchParams, c as HTTP_DEFAULT_STALE_TIME, d as buildHttpQueryPrefixKey, f as isHttpClientError, i as RESERVED_KEYS, l as HttpClientError, n as convexInfiniteQueryOptions, o as executeHttpRequest, r as convexQuery, s as replaceUrlParam, t as convexAction, u as buildHttpQueryKey } from "../query-options-DGG93--5.js";
4
4
 
5
5
  //#region src/crpc/auth-error.ts
6
6
  /**
@@ -30,6 +30,69 @@ const NoOp = {
30
30
  }
31
31
  };
32
32
  /**
33
+ * customQuery helps define custom behavior on top of `query` or `internalQuery`
34
+ * by passing a function that modifies the ctx and args.
35
+ *
36
+ * Example usage:
37
+ * ```js
38
+ * const myQueryBuilder = customQuery(query, {
39
+ * args: { sessionId: v.id("sessions") },
40
+ * input: async (ctx, args) => {
41
+ * const user = await getUserOrNull(ctx);
42
+ * const session = await db.get(sessionId);
43
+ * const db = wrapDatabaseReader({ user }, ctx.db, rlsRules);
44
+ * return {
45
+ * ctx: { db, user, session },
46
+ * args: {},
47
+ * onSuccess: ({ result }) => {
48
+ * // Optional callback that runs after the function executes
49
+ * // Has access to resources created during input processing
50
+ * console.log(`Query for ${user.name} returned:`, result);
51
+ * }
52
+ * };
53
+ * },
54
+ * });
55
+ *
56
+ * // Using the custom builder
57
+ * export const getSomeData = myQueryBuilder({
58
+ * args: { someArg: v.string() },
59
+ * handler: async (ctx, args) => {
60
+ * const { db, user, session, scheduler } = ctx;
61
+ * const { someArg } = args;
62
+ * // ...
63
+ * }
64
+ * });
65
+ * ```
66
+ *
67
+ * Simple usage only modifying ctx:
68
+ * ```js
69
+ * const myInternalQuery = customQuery(
70
+ * internalQuery,
71
+ * customCtx(async (ctx) => {
72
+ * return {
73
+ * // Throws an exception if the user isn't logged in
74
+ * user: await getUserByTokenIdentifier(ctx),
75
+ * };
76
+ * })
77
+ * );
78
+ *
79
+ * // Using it
80
+ * export const getUser = myInternalQuery({
81
+ * args: {},
82
+ * handler: async (ctx, args) => {
83
+ * return ctx.user;
84
+ * },
85
+ * });
86
+ *
87
+ * @param query The query to be modified. Usually `query` or `internalQuery`
88
+ * from `_generated/server`.
89
+ * @param customization The modifier to be applied to the query, changing ctx and args.
90
+ * @returns A new query builder to define queries with modified ctx and args.
91
+ */
92
+ function customQuery(query, customization) {
93
+ return customFnBuilder(query, customization);
94
+ }
95
+ /**
33
96
  * customMutation helps define custom behavior on top of `mutation`
34
97
  * or `internalMutation` by passing a function that modifies the ctx and args.
35
98
  *
@@ -142,4 +205,4 @@ function customFnBuilder(builder, customization) {
142
205
  }
143
206
 
144
207
  //#endregion
145
- export { customCtx as n, customMutation as r, NoOp as t };
208
+ export { customQuery as i, customCtx as n, customMutation as r, NoOp as t };
@@ -1,5 +1,5 @@
1
- import { A as integer, C as index, I as ConvexColumnBuilder, L as entityKind, M as custom, O as text, t as convexTable } from "./table-CX2lnX7e.js";
2
- import { t as defineSchemaExtension } from "./extensions-Blzsyekm.js";
1
+ import { b as ConvexColumnBuilder, f as text, g as custom, m as integer, s as index, t as convexTable, x as entityKind } from "./table-d9o_n4R3.js";
2
+ import { t as defineSchemaExtension } from "./extensions-Bp0XHanR.js";
3
3
  import { v } from "convex/values";
4
4
 
5
5
  //#region src/orm/builders/boolean.ts
@@ -1,4 +1,4 @@
1
- import { d as OrmSchemaExtensionTriggers, l as OrmSchemaExtensionRelations } from "./table-CX2lnX7e.js";
1
+ import { c as OrmSchemaExtensionTriggers, o as OrmSchemaExtensionRelations } from "./symbols-DDNAddkd.js";
2
2
 
3
3
  //#region src/orm/extensions.ts
4
4
  function defineChainMethod(target, key, value) {