kitcn 0.30.0 → 0.31.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 (71) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/aggregate/index.d.ts +11 -6
  3. package/dist/aggregate/index.js +2 -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 +15 -15
  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-CG-oIMyR.d.ts} +25 -11
  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-BKvk4lFx.d.ts} +41 -12
  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/{filter-expression-Dydt8wS0.js → index-utils-C1DyktHe.js} +95 -1
  27. package/dist/{local-env-Dk8RJvt5.mjs → local-env-CYYSNf_o.mjs} +92 -72
  28. package/dist/{middleware-CE_MC6Gi.d.ts → middleware-BBS7oLtT.d.ts} +1 -1
  29. package/dist/{middleware-BvnabcNq.js → middleware-D61Nm-iB.js} +1 -1
  30. package/dist/orm/aggregate-index/index.d.ts +1 -1
  31. package/dist/orm/aggregate-index/index.js +32 -34
  32. package/dist/orm/index.d.ts +4 -4
  33. package/dist/orm/index.js +8 -7
  34. package/dist/orm/migrations/index.d.ts +2 -2
  35. package/dist/orm/migrations/index.js +1 -1
  36. package/dist/plugins/index.d.ts +1 -1
  37. package/dist/plugins/index.js +1 -1
  38. package/dist/{procedure-caller-BR-Wb0si.js → procedure-caller-DgMiD0-a.js} +2 -2
  39. package/dist/{procedure-name-l2YusEZI.d.ts → procedure-name-DPYyLiVS.d.ts} +3 -3
  40. package/dist/ratelimit/index.d.ts +2 -2
  41. package/dist/ratelimit/index.js +3 -3
  42. package/dist/rsc/index.d.ts +4 -4
  43. package/dist/rsc/index.js +4 -4
  44. package/dist/{runtime-CcOvOf4K.js → runtime-B-8HKSIE.js} +21 -40
  45. package/dist/schema-BFP_awgP.js +67 -0
  46. package/dist/{schema-D8ZZMSKd.js → schema-DbPcDW-N.js} +10 -117
  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-DvYSTJXe.d.ts → where-clause-compiler-Bgkzm3Y-.d.ts} +85 -81
  55. package/package.json +1 -1
  56. package/dist/id-CuSfWa5q.js +0 -37
  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,71 @@
1
1
  # kitcn
2
2
 
3
+ ## 0.31.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#424](https://github.com/udecode/kitcn/pull/424) [`0e3a221`](https://github.com/udecode/kitcn/commit/0e3a2214e8e1037b323e603f19c2df89b0d95602) Thanks [@MikeyZhang75](https://github.com/MikeyZhang75)! - ## Patches
8
+
9
+ - Stop `aggregateBackfill` rewriting the stored state it is about to delete.
10
+ Clearing a `rankIndex` walked the btree once per member — a root-to-leaf
11
+ descent plus a patch on every node along the way — and then dropped the whole
12
+ tree regardless, so all of that work was thrown away. Clearing an
13
+ `aggregateIndex` did the same thing with buckets, decrementing each one down to
14
+ zero before deleting it. Both now delete their member rows outright and let the
15
+ existing tree and bucket sweeps reclaim the rest. Clearing 120 rank members
16
+ across three partitions went from 201 btree node writes to 15, one per node.
17
+ - Fix a `rankIndex` clear crashing with `Unexpected field 'deletionStack'` once a
18
+ partition holds more than a few hundred rows. The rank storage tables now
19
+ reuse the same definitions the btree writes to, so a large tree can persist its
20
+ traversal state and resume across mutations. Run
21
+ `npx convex dev` (or your usual codegen) to pick the schema up.
22
+ - Report real work from a clear chunk instead of a fixed guess, so
23
+ `aggregateBackfill --batch-size` now bounds a clear by the documents it
24
+ actually touches. Multi-partition rank indexes no longer schedule far more
25
+ chunks than the remaining work needs.
26
+ - Allow an app to declare `aggregateStorageTables` from `kitcn/aggregate`
27
+ alongside a table that also declares a `rankIndex`. `defineSchema` used to
28
+ reject that combination as a duplicate table name.
29
+
30
+ ## 0.31.0
31
+
32
+ ### Minor Changes
33
+
34
+ - [#423](https://github.com/udecode/kitcn/pull/423) [`8dbe02a`](https://github.com/udecode/kitcn/commit/8dbe02abeb2a0a5495a33a6a8206fbe53bfd1a16) Thanks [@MikeyZhang75](https://github.com/MikeyZhang75)! - ## Breaking changes
35
+
36
+ - The generated auth runtime exports a new internal `count` query. Rerun
37
+ `npx kitcn codegen` and redeploy before upgrading — Better Auth's `count()`
38
+ calls it on every request that reads a total, and a deployment that predates
39
+ it will fail those requests with a missing-function error.
40
+
41
+ ```ts
42
+ // convex/functions/generated/auth.ts — regenerated
43
+ export const {
44
+ authEnabled,
45
+ authClient,
46
+ getAuth,
47
+ auth,
48
+ count,
49
+ create,
50
+ // ...
51
+ } = authRuntime;
52
+ ```
53
+
54
+ ## Patches
55
+
56
+ - Fix Better Auth's `count()` reading every matching row 200 at a time. A count
57
+ with no filter is now answered by Convex directly and reads no documents at
58
+ all, so `/admin/list-users` and any other total over a whole auth table no
59
+ longer scales with the table. Previously this ran one paginated query per 200
60
+ rows, and inside a query or mutation every one of those rows landed in the
61
+ same transaction, so a large enough table failed on the per-transaction
62
+ document-read limit instead of returning a number.
63
+ - Support constant-cost counts on filtered auth tables. When a table declares an
64
+ `aggregateIndex` whose fields exactly match the fields being counted, counts
65
+ such as members-per-organization read a bucket instead of the members. Counts
66
+ that no index can serve, including anything using `contains`, `ne`, `in`, or
67
+ an OR clause, still page through rows and return the same number as before.
68
+
3
69
  ## 0.30.0
4
70
 
5
71
  ### 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-DvYSTJXe.js";
1
+ import { Vn as ConvexTextBuilderInitial, Zt as ConvexTableWithColumns } from "../capabilities-CG-oIMyR.js";
2
+ import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-Bgkzm3Y-.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";
@@ -136,6 +136,10 @@ declare const aggregateStorageTables: {
136
136
  //#endregion
137
137
  //#region src/aggregate-core/btree.d.ts
138
138
  type Key$2 = Value;
139
+ type DeleteTreesResult = {
140
+ /** True once this aggregate owns no tree row at all. */done: boolean; /** Documents this call wrote, so callers can charge a real work budget. */
141
+ documents: number;
142
+ };
139
143
  //#endregion
140
144
  //#region src/aggregate-core/positions.d.ts
141
145
  type Bound$1<K extends Key$2, ID extends string> = {
@@ -240,11 +244,12 @@ declare class Aggregate<K extends Key, ID extends string, TNamespace extends Val
240
244
  rootLazy?: boolean;
241
245
  }, TNamespace>): Promise<void>;
242
246
  /**
243
- * Deletes up to `limit` namespace trees without recreating them. Returns true
244
- * once this aggregate owns no trees, so callers can drain every namespace
245
- * across several mutations instead of walking them all in one.
247
+ * Deletes up to `limit` nodes from one namespace tree without recreating it,
248
+ * reporting `done` once this aggregate owns no trees and how many documents
249
+ * the call wrote. Callers drain every namespace across several mutations
250
+ * instead of walking them all in one, and charge their budget by `documents`.
246
251
  */
247
- deleteTrees(ctx: RunMutationCtx, limit: number): Promise<boolean>;
252
+ deleteTrees(ctx: RunMutationCtx, limit: number): Promise<DeleteTreesResult>;
248
253
  makeRootLazy(ctx: RunMutationCtx, namespace: TNamespace): Promise<void>;
249
254
  paginateNamespaces(ctx: RunQueryCtx, cursor?: string, pageSize?: number): Promise<{
250
255
  cursor: string;
@@ -1,4 +1,5 @@
1
- import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-CcOvOf4K.js";
1
+ import { n as TableAggregate$1, t as DirectAggregate$1 } from "../runtime-B-8HKSIE.js";
2
+ import { i as aggregateStorageTables } from "../schema-BFP_awgP.js";
2
3
 
3
4
  //#region src/aggregate/index.ts
4
5
  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-BKvk4lFx.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-BKvk4lFx.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";
@@ -111,29 +111,29 @@ declare const adapterWhereValidator: convex_values0.VObject<{
111
111
  mode?: "sensitive" | "insensitive" | undefined;
112
112
  connector?: "AND" | "OR" | undefined;
113
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
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>;
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" | "value" | "connector" | "field" | "operator">;
123
123
  declare const adapterArgsValidator: convex_values0.VObject<{
124
124
  where?: {
125
125
  mode?: "sensitive" | "insensitive" | undefined;
126
126
  connector?: "AND" | "OR" | undefined;
127
127
  operator?: "lt" | "lte" | "gt" | "gte" | "eq" | "in" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
128
- field: string;
129
128
  value: string | number | boolean | string[] | number[] | null;
129
+ field: string;
130
130
  }[] | undefined;
131
131
  limit?: number | undefined;
132
132
  offset?: number | undefined;
133
133
  select?: string[] | undefined;
134
134
  sortBy?: {
135
- field: string;
136
135
  direction: "asc" | "desc";
136
+ field: string;
137
137
  } | undefined;
138
138
  model: string;
139
139
  }, {
@@ -142,32 +142,32 @@ declare const adapterArgsValidator: convex_values0.VObject<{
142
142
  offset: convex_values0.VFloat64<number | undefined, "optional">;
143
143
  select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
144
144
  sortBy: convex_values0.VObject<{
145
- field: string;
146
145
  direction: "asc" | "desc";
146
+ field: string;
147
147
  } | undefined, {
148
148
  direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
149
149
  field: convex_values0.VString<string, "required">;
150
- }, "optional", "field" | "direction">;
150
+ }, "optional", "direction" | "field">;
151
151
  where: convex_values0.VArray<{
152
152
  mode?: "sensitive" | "insensitive" | undefined;
153
153
  connector?: "AND" | "OR" | undefined;
154
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
159
  connector?: "AND" | "OR" | undefined;
160
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
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>;
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" | "value" | "connector" | "field" | "operator">, "optional">;
170
+ }, "required", "model" | "where" | "limit" | "offset" | "select" | "sortBy" | "sortBy.direction" | "sortBy.field">;
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";
@@ -2341,12 +2341,16 @@ type ClearIndexChunkResult = {
2341
2341
  * reports whether anything is left. Callers drive it to completion across
2342
2342
  * transactions, so clearing a large index never has to fit in one mutation.
2343
2343
  *
2344
- * Members are removed through the normal delta machinery rather than raw
2345
- * deletes, so buckets and extrema stay consistent with the members that remain
2346
- * at every intermediate step. That keeps concurrent writers correct while the
2347
- * clear drains. Residual bucket/extrema rows (drift with no member behind them)
2348
- * are swept only once no members are left, and the loop re-checks members
2349
- * afterwards.
2344
+ * Member rows are deleted outright rather than run back through the delta
2345
+ * machinery. The bucket and extrema branches below drop every row this index
2346
+ * owns whatever it holds, so folding a removal delta into a bucket first would
2347
+ * only rewrite a document this same clear is about to delete.
2348
+ *
2349
+ * Branch order is load-bearing: buckets and extrema are swept only once no
2350
+ * members are left, and the loop re-checks members afterwards. The intermediate
2351
+ * "members gone, buckets still populated" state is safe because `setCountState`
2352
+ * refuses to leave CLEARING while a bucket or extrema row survives, and the
2353
+ * CLEARING write barrier keeps concurrent writers out of the index.
2350
2354
  */
2351
2355
  declare const clearCountIndexChunk: (db: GenericDatabaseWriter<any>, tableName: string, indexName: string, batchSize: number) => Promise<ClearIndexChunkResult>;
2352
2356
  declare const listCountStates: (db: GenericDatabaseReader<any> | GenericDatabaseWriter<any>) => Promise<CountState[]>;
@@ -2392,10 +2396,20 @@ declare const ensureRankAllowedForRls: (tableConfig: TableRelationalConfig, rlsM
2392
2396
  declare const compileRankPlan: (tableConfig: TableRelationalConfig, indexName: string, where: unknown) => RankQueryPlan;
2393
2397
  declare const ensureRankIndexReady: (db: GenericDatabaseReader<any> | GenericDatabaseWriter<any>, tableName: string, indexName: string) => Promise<void>;
2394
2398
  /**
2395
- * Removes at most `batchSize` rank members and reports whether anything is
2396
- * left. Each member is removed from the btree before its row is dropped, so the
2397
- * tree stays consistent with the members that remain and a partially drained
2398
- * clear can safely resume in a later mutation.
2399
+ * Removes at most `batchSize` documents of a rank index's stored state and
2400
+ * reports whether anything is left. Callers drive it to completion across
2401
+ * transactions, so clearing a large index never has to fit in one mutation.
2402
+ *
2403
+ * Member rows are dropped without touching the btree. The tree branch below
2404
+ * deletes every node whatever it contains, so removing a member key first would
2405
+ * only buy a root-to-leaf descent plus an aggregate patch per level on nodes
2406
+ * this same clear is about to delete.
2407
+ *
2408
+ * Branch order is load-bearing: a member delete recreates the tree it lands on,
2409
+ * so the members must be gone before the first node is dropped. The
2410
+ * intermediate "members gone, tree still full" state is safe because
2411
+ * `setCountState` refuses to leave CLEARING while a tree row survives, and the
2412
+ * CLEARING write barrier keeps concurrent writers out of the index.
2399
2413
  */
2400
2414
  declare const clearRankIndexChunk: (db: GenericDatabaseWriter<any>, tableName: string, indexName: string, batchSize: number) => Promise<{
2401
2415
  done: boolean;
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-CYYSNf_o.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
  /**