kitcn 0.26.0 → 0.26.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # kitcn
2
2
 
3
+ ## 0.26.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#392](https://github.com/udecode/kitcn/pull/392) [`72d3270`](https://github.com/udecode/kitcn/commit/72d327003547b1f4097aa72db0d35128ed57b04d) Thanks [@MikeyZhang75](https://github.com/MikeyZhang75)! - ## Patches
8
+
9
+ - Fix a crash when writing an object key that cannot be converted to a string,
10
+ such as one created with `Object.create(null)`, into an `aggregateIndex` or
11
+ `rankIndex`. Once enough keys accumulated to rebalance the index, the write
12
+ failed with `TypeError: Cannot convert object to primitive value` instead of
13
+ succeeding.
14
+
3
15
  ## 0.26.0
4
16
 
5
17
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  import { Bn as ConvexTextBuilderInitial, Xt as ConvexTableWithColumns } from "../capabilities-DtDfpdcH.js";
2
- import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-AYna1fq8.js";
2
+ import { C as ConvexNumberBuilderInitial, E as ConvexIdBuilderInitial, N as ConvexCustomBuilderInitial } from "../where-clause-compiler-3fKontPx.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-BdqTbgKh.js";
1
+ import { n as TableAggregate$1, r as aggregateStorageTables, t as DirectAggregate$1 } from "../runtime-CcOvOf4K.js";
2
2
 
3
3
  //#region src/aggregate/index.ts
4
4
  const wrapTriggerFactory = (methodName, factory) => ((...args) => {
@@ -1,4 +1,4 @@
1
- import { t as DirectAggregate } from "../../runtime-BdqTbgKh.js";
1
+ import { t as DirectAggregate } from "../../runtime-CcOvOf4K.js";
2
2
  import { a as Columns } from "../../table-CX2lnX7e.js";
3
3
  import { Y as normalizeTemporalComparableValue, bt as PUBLIC_CREATED_AT_FIELD, c as AGGREGATE_ERROR, f as createError, i as AGGREGATE_STATE_TABLE, l as COUNT_ERROR, lt as mapWithConcurrency, n as AGGREGATE_EXTREMA_TABLE, o as getAggregateIndexDefinitions, r as AGGREGATE_MEMBER_TABLE, s as getRankIndexDefinitions, t as AGGREGATE_BUCKET_TABLE, xt as usesSystemCreatedAtAlias, yt as INTERNAL_CREATION_TIME_FIELD } from "../../schema-e0wbZ_Ax.js";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { $n as BinaryExpression, $t as OrmLifecycleOperation, A as DatabaseWithMutations, An as ConvexCheckConfig, Ar as AnyColumn, At as VectorQueryConfig, B as RlsContext, Bn as ConvexTextBuilderInitial, Br as IsUnique, Bt as RelationsBuilderColumnConfig, C as MigrationTableName, Cn as aggregateIndex, Cr as notBetween, Ct as OrderDirection, D as defineMigrationSet, Dn as uniqueIndex, Dt as ReturningResult, E as defineMigration, En as searchIndex, Er as startsWith, Et as ReturningAll, Fn as ConvexUniqueConstraintConfig, Fr as ColumnBuilderWithTableName, Ft as ExtractTablesWithRelations, Gt as defineRelations, H as EdgeMetadata, In as check, Ir as ColumnDataType, It as ManyConfig, Jt as ConvexDeletionConfig, Kt as defineRelationsPart, Ln as foreignKey, Lr as DrizzleEntity, Lt as OneConfig, M as OrmReader$1, Mn as ConvexForeignKeyConfig, Mr as ColumnBuilderBaseConfig, Mt as unsetToken, N as OrmWriter$1, Nn as ConvexUniqueConstraintBuilder, Nr as ColumnBuilderRuntimeConfig, O as detectMigrationDrift, On as vectorIndex, Or as SystemFields, Ot as ReturningSelection, Pn as ConvexUniqueConstraintBuilderOn, Pr as ColumnBuilderTypeConfig, Pt as ExtractTablesFromSchema, Qn as TableName, Qt as OrmLifecycleChange, Rn as unique, Rr as HasDefault, Rt as RelationsBuilder, S as MigrationStep, Sn as ConvexVectorIndexConfig, Sr as not, St as OrderByClause, T as buildMigrationPlan, Tn as rankIndex, Tr as or, Tt as PredicateWhereIndexConfig, U as extractRelationsConfig, Un as Brand, Ut as TableRelationalConfig, V as RlsMode, Vn as text, Vr as NotNull, Wn as Columns, Wt as TablesRelationalConfig, Xn as OrmSchemaRelations, Xt as ConvexTableWithColumns, Yn as OrmSchemaExtensions, Yt as ConvexTable, Zn as OrmSchemaTriggers, Zt as DiscriminatorBuilderConfig, _ as MigrationMigrateOne, _n as ConvexSearchIndexBuilder, _r as isNull, _t as MutationPaginateConfig, an as RlsPolicyConfig, ar as and, at as CountConfig, b as MigrationSet, bn as ConvexVectorIndexBuilder, br as lte, bt as MutationReturning, cn as RlsRole, cr as endsWith, ct as FilterOperators, d as MigrationDefinition, dn as ConvexAggregateIndexBuilder, dr as gt, dt as InferModelFromColumns, en as TableConfig, er as ExpressionVisitor, et as AggregateConfig, f as MigrationDirection, fn as ConvexAggregateIndexBuilderOn, fr as gte, ft as InferSelectModel, g as MigrationManifestEntry, gn as ConvexRankIndexBuilderOn, gr as isNotNull, gt as MutationExecutionMode, h as MigrationDriftIssue, hn as ConvexRankIndexBuilder, hr as isFieldReference, ht as MutationExecuteResult, i as OrmMigrationCapability, in as RlsPolicy, ir as UnaryExpression, it as BuildRelationResult, j as DatabaseWithQuery, jn as ConvexForeignKeyBuilder, jr as ColumnBuilder, jt as VectorSearchProvider, kn as ConvexCheckBuilder, kt as UpdateSet, ln as RlsRoleConfig, lr as eq, lt as GetColumnData, m as MigrationDocContext, mn as ConvexIndexBuilderOn, mr as inArray, mt as MutationExecuteConfig, n as OrmCapabilities, nn as deletion, nr as FilterExpression, nt as AggregateResult, on as RlsPolicyToOption, or as between, ot as CountResult, p as MigrationDoc, pn as ConvexIndexBuilder, pr as ilike, pt as InsertValue, qn as OrmSchemaExtensionTables, qt as ConvexDeletionBuilder, r as OrmCapability, rn as discriminator, rr as LogicalExpression, rt as BuildQueryResult, sn as rlsPolicy, sr as contains, st as DBQueryConfig, t as OrmAggregateCapability, tn as convexTable, tr as FieldReference, tt as AggregateFieldValue, u as MigrationAppliedState, un as rlsRole, ur as fieldRef, ut as InferInsertModel, v as MigrationPlan, vn as ConvexSearchIndexBuilderOn, vr as like, vt as MutationPaginatedResult, w as MigrationWriteMode, wn as index, wr as notInArray, wt as PaginatedResult, x as MigrationStateMap, xn as ConvexVectorIndexBuilderOn, xr as ne, xt as MutationRunMode, y as MigrationRunStatus, yn as ConvexSearchIndexConfig, yr as lt, yt as MutationResult, zn as ConvexTextBuilder, zr as IsPrimaryKey, zt as RelationsBuilderColumnBase } from "../capabilities-DtDfpdcH.js";
2
- import { $ as OrmClientWithApi$1, A as ConvexDateMode, B as ConvexBytesBuilderInitial, C as ConvexNumberBuilderInitial, D as id, E as ConvexIdBuilderInitial, F as custom, G as ConvexBigIntBuilder, H as ConvexBooleanBuilder, I as json, J as CreateOrmOptions, K as ConvexBigIntBuilderInitial, L as objectOf, M as ConvexCustomBuilder, N as ConvexCustomBuilderInitial, O as ConvexDateBuilder, P as arrayOf, Q as OrmClientBase$1, R as unionOf, S as ConvexNumberBuilder, St as defineTriggers, T as ConvexIdBuilder, U as ConvexBooleanBuilderInitial, V as bytes, W as boolean, X as GenericOrmCtx$1, Y as GenericOrm$1, Z as OrmApiResult, _ as ConvexTimestampMode, _t as OrmBeforeResult, a as requireSchemaRelations, at as ScheduledMutationBatchArgs, b as ConvexTextEnumBuilderInitial, bt as OrmTriggerContext, c as TableConfigResult, ct as scheduledDeleteFactory, d as OrmNotFoundError, et as OrmFunctions, f as ConvexVectorBuilder, g as ConvexTimestampBuilderInitial, gt as defineSchemaExtension, h as ConvexTimestampBuilder, ht as SchemaExtension, i as getSchemaTriggers, it as createOrm, j as date, k as ConvexDateBuilderInitial, l as getTableColumns, m as vector, n as defineSchema, nt as OrmWriterCtx, o as asc, ot as scheduledMutationBatchFactory, p as ConvexVectorBuilderInitial, q as bigint, r as getSchemaRelations, rt as ResolveOrmSchema, s as desc, st as ScheduledDeleteArgs, t as WhereClauseResult, tt as OrmReaderCtx, u as getTableConfig, v as timestamp, vt as OrmTableTriggers, w as integer, x as textEnum, xt as OrmTriggers, y as ConvexTextEnumBuilder, yt as OrmTriggerChange, z as ConvexBytesBuilder } from "../where-clause-compiler-AYna1fq8.js";
2
+ import { $ as OrmClientWithApi$1, A as ConvexDateMode, B as ConvexBytesBuilderInitial, C as ConvexNumberBuilderInitial, D as id, E as ConvexIdBuilderInitial, F as custom, G as ConvexBigIntBuilder, H as ConvexBooleanBuilder, I as json, J as CreateOrmOptions, K as ConvexBigIntBuilderInitial, L as objectOf, M as ConvexCustomBuilder, N as ConvexCustomBuilderInitial, O as ConvexDateBuilder, P as arrayOf, Q as OrmClientBase$1, R as unionOf, S as ConvexNumberBuilder, St as defineTriggers, T as ConvexIdBuilder, U as ConvexBooleanBuilderInitial, V as bytes, W as boolean, X as GenericOrmCtx$1, Y as GenericOrm$1, Z as OrmApiResult, _ as ConvexTimestampMode, _t as OrmBeforeResult, a as requireSchemaRelations, at as ScheduledMutationBatchArgs, b as ConvexTextEnumBuilderInitial, bt as OrmTriggerContext, c as TableConfigResult, ct as scheduledDeleteFactory, d as OrmNotFoundError, et as OrmFunctions, f as ConvexVectorBuilder, g as ConvexTimestampBuilderInitial, gt as defineSchemaExtension, h as ConvexTimestampBuilder, ht as SchemaExtension, i as getSchemaTriggers, it as createOrm, j as date, k as ConvexDateBuilderInitial, l as getTableColumns, m as vector, n as defineSchema, nt as OrmWriterCtx, o as asc, ot as scheduledMutationBatchFactory, p as ConvexVectorBuilderInitial, q as bigint, r as getSchemaRelations, rt as ResolveOrmSchema, s as desc, st as ScheduledDeleteArgs, t as WhereClauseResult, tt as OrmReaderCtx, u as getTableConfig, v as timestamp, vt as OrmTableTriggers, w as integer, x as textEnum, xt as OrmTriggers, y as ConvexTextEnumBuilder, yt as OrmTriggerChange, z as ConvexBytesBuilder } from "../where-clause-compiler-3fKontPx.js";
3
3
  import { i as pretendRequired, n as deprecated, r as pretend } from "../validators-wOIjhkfN.js";
4
4
  import { a as QueryCtxWithPreferredOrmQueryTable, i as QueryCtxWithOrmQueryTable, n as LookupByIdResultByCtx, o as getByIdWithOrmQueryFallback, r as QueryCtxWithOptionalOrmQueryTable, t as DocByCtx } from "../query-context-DJONf8X5.js";
5
5
  import { DefineSchemaOptions, GenericDatabaseReader, GenericDatabaseWriter, GenericSchema, SchemaDefinition } from "convex/server";
@@ -1,3 +1,3 @@
1
1
  import { C as MigrationTableName, D as defineMigrationSet, E as defineMigration, O as detectMigrationDrift, S as MigrationStep, T as buildMigrationPlan, _ as MigrationMigrateOne, a as MigrationCancelArgs, b as MigrationSet, c as MigrationStatusArgs, d as MigrationDefinition, f as MigrationDirection, g as MigrationManifestEntry, h as MigrationDriftIssue, l as createMigrationHandlers, m as MigrationDocContext, o as MigrationRunArgs, p as MigrationDoc, s as MigrationRunChunkArgs, u as MigrationAppliedState, v as MigrationPlan, w as MigrationWriteMode, x as MigrationStateMap, y as MigrationRunStatus } from "../../capabilities-DtDfpdcH.js";
2
- import { Ct as migrationCapability, dt as MIGRATION_STORAGE_TABLE_NAMES, ft as injectMigrationStorageTables, lt as MIGRATION_RUN_TABLE, mt as migrationStorageTables, pt as migrationExtension, ut as MIGRATION_STATE_TABLE } from "../../where-clause-compiler-AYna1fq8.js";
2
+ import { Ct as migrationCapability, dt as MIGRATION_STORAGE_TABLE_NAMES, ft as injectMigrationStorageTables, lt as MIGRATION_RUN_TABLE, mt as migrationStorageTables, pt as migrationExtension, ut as MIGRATION_STATE_TABLE } from "../../where-clause-compiler-3fKontPx.js";
3
3
  export { MIGRATION_RUN_TABLE, MIGRATION_STATE_TABLE, MIGRATION_STORAGE_TABLE_NAMES, type MigrationAppliedState, type MigrationCancelArgs, type MigrationDefinition, type MigrationDirection, type MigrationDoc, type MigrationDocContext, type MigrationDriftIssue, type MigrationManifestEntry, type MigrationMigrateOne, type MigrationPlan, type MigrationRunArgs, type MigrationRunChunkArgs, type MigrationRunStatus, type MigrationSet, type MigrationStateMap, type MigrationStatusArgs, type MigrationStep, type MigrationTableName, type MigrationWriteMode, buildMigrationPlan, createMigrationHandlers, defineMigration, defineMigrationSet, detectMigrationDrift, injectMigrationStorageTables, migrationCapability, migrationExtension, migrationStorageTables };
@@ -439,7 +439,7 @@ async function insertIntoNode(ctx, maxNodeSize, node, item) {
439
439
  const minNodeSize = minNodeSizeFor(maxNodeSize);
440
440
  if (newN.items.length > maxNodeSize) {
441
441
  if (newN.items.length !== maxNodeSize + 1 || newN.items.length !== 2 * minNodeSize + 1) throw new Error(`bad ${newN.items.length}`);
442
- log(`splitting node ${newN._id} at ${newN.items[minNodeSize].k}`);
442
+ log(`splitting node ${newN._id} at ${p(newN.items[minNodeSize].k)}`);
443
443
  const topLevel = nodeCounts(newN);
444
444
  const subCounts = await subtreeCounts(ctx.db, newN);
445
445
  const leftCount = add(accumulate(topLevel.slice(0, minNodeSize)), accumulate(subCounts.length ? subCounts.slice(0, minNodeSize + 1) : []));
@@ -120,6 +120,19 @@ declare const migrationStorageTables: {
120
120
  fieldName: "direction";
121
121
  };
122
122
  };
123
+ updatedAt: ConvexNumberBuilderInitial<""> & {
124
+ _: {
125
+ notNull: true;
126
+ };
127
+ } & {
128
+ _: {
129
+ tableName: "migration_state";
130
+ };
131
+ } & {
132
+ _: {
133
+ fieldName: "updatedAt";
134
+ };
135
+ };
123
136
  migrationId: ConvexTextBuilderInitial<""> & {
124
137
  _: {
125
138
  notNull: true;
@@ -190,19 +203,6 @@ declare const migrationStorageTables: {
190
203
  fieldName: "startedAt";
191
204
  };
192
205
  };
193
- updatedAt: ConvexNumberBuilderInitial<""> & {
194
- _: {
195
- notNull: true;
196
- };
197
- } & {
198
- _: {
199
- tableName: "migration_state";
200
- };
201
- } & {
202
- _: {
203
- fieldName: "updatedAt";
204
- };
205
- };
206
206
  completedAt: ConvexNumberBuilderInitial<""> & {
207
207
  _: {
208
208
  tableName: "migration_state";
@@ -269,7 +269,7 @@ declare const migrationStorageTables: {
269
269
  fieldName: "direction";
270
270
  };
271
271
  };
272
- runId: ConvexTextBuilderInitial<""> & {
272
+ updatedAt: ConvexNumberBuilderInitial<""> & {
273
273
  _: {
274
274
  notNull: true;
275
275
  };
@@ -279,10 +279,10 @@ declare const migrationStorageTables: {
279
279
  };
280
280
  } & {
281
281
  _: {
282
- fieldName: "runId";
282
+ fieldName: "updatedAt";
283
283
  };
284
284
  };
285
- startedAt: ConvexNumberBuilderInitial<""> & {
285
+ runId: ConvexTextBuilderInitial<""> & {
286
286
  _: {
287
287
  notNull: true;
288
288
  };
@@ -292,10 +292,10 @@ declare const migrationStorageTables: {
292
292
  };
293
293
  } & {
294
294
  _: {
295
- fieldName: "startedAt";
295
+ fieldName: "runId";
296
296
  };
297
297
  };
298
- updatedAt: ConvexNumberBuilderInitial<""> & {
298
+ startedAt: ConvexNumberBuilderInitial<""> & {
299
299
  _: {
300
300
  notNull: true;
301
301
  };
@@ -305,7 +305,7 @@ declare const migrationStorageTables: {
305
305
  };
306
306
  } & {
307
307
  _: {
308
- fieldName: "updatedAt";
308
+ fieldName: "startedAt";
309
309
  };
310
310
  };
311
311
  completedAt: ConvexNumberBuilderInitial<""> & {
@@ -1034,7 +1034,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1034
1034
  fieldName: "updatedAt";
1035
1035
  };
1036
1036
  };
1037
- tableKey: ConvexTextBuilderInitial<""> & {
1037
+ indexName: ConvexTextBuilderInitial<""> & {
1038
1038
  _: {
1039
1039
  notNull: true;
1040
1040
  };
@@ -1044,10 +1044,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1044
1044
  };
1045
1045
  } & {
1046
1046
  _: {
1047
- fieldName: "tableKey";
1047
+ fieldName: "indexName";
1048
1048
  };
1049
1049
  };
1050
- indexName: ConvexTextBuilderInitial<""> & {
1050
+ tableKey: ConvexTextBuilderInitial<""> & {
1051
1051
  _: {
1052
1052
  notNull: true;
1053
1053
  };
@@ -1057,7 +1057,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1057
1057
  };
1058
1058
  } & {
1059
1059
  _: {
1060
- fieldName: "indexName";
1060
+ fieldName: "tableKey";
1061
1061
  };
1062
1062
  };
1063
1063
  keyHash: ConvexTextBuilderInitial<""> & {
@@ -1159,7 +1159,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1159
1159
  fieldName: "updatedAt";
1160
1160
  };
1161
1161
  };
1162
- tableKey: ConvexTextBuilderInitial<""> & {
1162
+ indexName: ConvexTextBuilderInitial<""> & {
1163
1163
  _: {
1164
1164
  notNull: true;
1165
1165
  };
@@ -1169,10 +1169,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1169
1169
  };
1170
1170
  } & {
1171
1171
  _: {
1172
- fieldName: "tableKey";
1172
+ fieldName: "indexName";
1173
1173
  };
1174
1174
  };
1175
- indexName: ConvexTextBuilderInitial<""> & {
1175
+ tableKey: ConvexTextBuilderInitial<""> & {
1176
1176
  _: {
1177
1177
  notNull: true;
1178
1178
  };
@@ -1182,7 +1182,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1182
1182
  };
1183
1183
  } & {
1184
1184
  _: {
1185
- fieldName: "indexName";
1185
+ fieldName: "tableKey";
1186
1186
  };
1187
1187
  };
1188
1188
  keyHash: ConvexTextBuilderInitial<""> & {
@@ -1366,7 +1366,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1366
1366
  fieldName: "updatedAt";
1367
1367
  };
1368
1368
  };
1369
- tableKey: ConvexTextBuilderInitial<""> & {
1369
+ indexName: ConvexTextBuilderInitial<""> & {
1370
1370
  _: {
1371
1371
  notNull: true;
1372
1372
  };
@@ -1376,10 +1376,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1376
1376
  };
1377
1377
  } & {
1378
1378
  _: {
1379
- fieldName: "tableKey";
1379
+ fieldName: "indexName";
1380
1380
  };
1381
1381
  };
1382
- indexName: ConvexTextBuilderInitial<""> & {
1382
+ tableKey: ConvexTextBuilderInitial<""> & {
1383
1383
  _: {
1384
1384
  notNull: true;
1385
1385
  };
@@ -1389,7 +1389,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1389
1389
  };
1390
1390
  } & {
1391
1391
  _: {
1392
- fieldName: "indexName";
1392
+ fieldName: "tableKey";
1393
1393
  };
1394
1394
  };
1395
1395
  keyHash: ConvexTextBuilderInitial<""> & {
@@ -1611,7 +1611,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1611
1611
  fieldName: "cursor";
1612
1612
  };
1613
1613
  };
1614
- processed: ConvexNumberBuilderInitial<""> & {
1614
+ updatedAt: ConvexNumberBuilderInitial<""> & {
1615
1615
  _: {
1616
1616
  notNull: true;
1617
1617
  };
@@ -1621,10 +1621,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1621
1621
  };
1622
1622
  } & {
1623
1623
  _: {
1624
- fieldName: "processed";
1624
+ fieldName: "updatedAt";
1625
1625
  };
1626
1626
  };
1627
- startedAt: ConvexNumberBuilderInitial<""> & {
1627
+ processed: ConvexNumberBuilderInitial<""> & {
1628
1628
  _: {
1629
1629
  notNull: true;
1630
1630
  };
@@ -1634,10 +1634,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1634
1634
  };
1635
1635
  } & {
1636
1636
  _: {
1637
- fieldName: "startedAt";
1637
+ fieldName: "processed";
1638
1638
  };
1639
1639
  };
1640
- updatedAt: ConvexNumberBuilderInitial<""> & {
1640
+ startedAt: ConvexNumberBuilderInitial<""> & {
1641
1641
  _: {
1642
1642
  notNull: true;
1643
1643
  };
@@ -1647,7 +1647,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1647
1647
  };
1648
1648
  } & {
1649
1649
  _: {
1650
- fieldName: "updatedAt";
1650
+ fieldName: "startedAt";
1651
1651
  };
1652
1652
  };
1653
1653
  completedAt: ConvexNumberBuilderInitial<""> & {
@@ -1668,7 +1668,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1668
1668
  fieldName: "lastError";
1669
1669
  };
1670
1670
  };
1671
- tableKey: ConvexTextBuilderInitial<""> & {
1671
+ indexName: ConvexTextBuilderInitial<""> & {
1672
1672
  _: {
1673
1673
  notNull: true;
1674
1674
  };
@@ -1678,10 +1678,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1678
1678
  };
1679
1679
  } & {
1680
1680
  _: {
1681
- fieldName: "tableKey";
1681
+ fieldName: "indexName";
1682
1682
  };
1683
1683
  };
1684
- indexName: ConvexTextBuilderInitial<""> & {
1684
+ keyDefinitionHash: ConvexTextBuilderInitial<""> & {
1685
1685
  _: {
1686
1686
  notNull: true;
1687
1687
  };
@@ -1691,10 +1691,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1691
1691
  };
1692
1692
  } & {
1693
1693
  _: {
1694
- fieldName: "indexName";
1694
+ fieldName: "keyDefinitionHash";
1695
1695
  };
1696
1696
  };
1697
- keyDefinitionHash: ConvexTextBuilderInitial<""> & {
1697
+ metricDefinitionHash: ConvexTextBuilderInitial<""> & {
1698
1698
  _: {
1699
1699
  notNull: true;
1700
1700
  };
@@ -1704,10 +1704,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1704
1704
  };
1705
1705
  } & {
1706
1706
  _: {
1707
- fieldName: "keyDefinitionHash";
1707
+ fieldName: "metricDefinitionHash";
1708
1708
  };
1709
1709
  };
1710
- metricDefinitionHash: ConvexTextBuilderInitial<""> & {
1710
+ tableKey: ConvexTextBuilderInitial<""> & {
1711
1711
  _: {
1712
1712
  notNull: true;
1713
1713
  };
@@ -1717,7 +1717,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1717
1717
  };
1718
1718
  } & {
1719
1719
  _: {
1720
- fieldName: "metricDefinitionHash";
1720
+ fieldName: "tableKey";
1721
1721
  };
1722
1722
  };
1723
1723
  };
@@ -1762,6 +1762,19 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1762
1762
  fieldName: "direction";
1763
1763
  };
1764
1764
  };
1765
+ updatedAt: ConvexNumberBuilderInitial<""> & {
1766
+ _: {
1767
+ notNull: true;
1768
+ };
1769
+ } & {
1770
+ _: {
1771
+ tableName: "migration_state";
1772
+ };
1773
+ } & {
1774
+ _: {
1775
+ fieldName: "updatedAt";
1776
+ };
1777
+ };
1765
1778
  migrationId: ConvexTextBuilderInitial<""> & {
1766
1779
  _: {
1767
1780
  notNull: true;
@@ -1832,19 +1845,6 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1832
1845
  fieldName: "startedAt";
1833
1846
  };
1834
1847
  };
1835
- updatedAt: ConvexNumberBuilderInitial<""> & {
1836
- _: {
1837
- notNull: true;
1838
- };
1839
- } & {
1840
- _: {
1841
- tableName: "migration_state";
1842
- };
1843
- } & {
1844
- _: {
1845
- fieldName: "updatedAt";
1846
- };
1847
- };
1848
1848
  completedAt: ConvexNumberBuilderInitial<""> & {
1849
1849
  _: {
1850
1850
  tableName: "migration_state";
@@ -1911,7 +1911,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1911
1911
  fieldName: "direction";
1912
1912
  };
1913
1913
  };
1914
- runId: ConvexTextBuilderInitial<""> & {
1914
+ updatedAt: ConvexNumberBuilderInitial<""> & {
1915
1915
  _: {
1916
1916
  notNull: true;
1917
1917
  };
@@ -1921,10 +1921,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1921
1921
  };
1922
1922
  } & {
1923
1923
  _: {
1924
- fieldName: "runId";
1924
+ fieldName: "updatedAt";
1925
1925
  };
1926
1926
  };
1927
- startedAt: ConvexNumberBuilderInitial<""> & {
1927
+ runId: ConvexTextBuilderInitial<""> & {
1928
1928
  _: {
1929
1929
  notNull: true;
1930
1930
  };
@@ -1934,10 +1934,10 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1934
1934
  };
1935
1935
  } & {
1936
1936
  _: {
1937
- fieldName: "startedAt";
1937
+ fieldName: "runId";
1938
1938
  };
1939
1939
  };
1940
- updatedAt: ConvexNumberBuilderInitial<""> & {
1940
+ startedAt: ConvexNumberBuilderInitial<""> & {
1941
1941
  _: {
1942
1942
  notNull: true;
1943
1943
  };
@@ -1947,7 +1947,7 @@ declare const BUILTIN_SCHEMA_EXTENSIONS: readonly [SchemaExtension<{
1947
1947
  };
1948
1948
  } & {
1949
1949
  _: {
1950
- fieldName: "updatedAt";
1950
+ fieldName: "startedAt";
1951
1951
  };
1952
1952
  };
1953
1953
  completedAt: ConvexNumberBuilderInitial<""> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitcn",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "kitcn - React Query integration and CLI tools for Convex",
5
5
  "keywords": [
6
6
  "convex",
@@ -77,6 +77,7 @@ export const authClient = createAuthClient({
77
77
  ```ts
78
78
  // convex/functions/schema.ts
79
79
  import {
80
+ aggregateIndex,
80
81
  convexTable,
81
82
  defineSchema,
82
83
  id,
@@ -111,6 +112,8 @@ export const member = convexTable(
111
112
  index("userId").on(t.userId),
112
113
  index("organizationId_userId").on(t.organizationId, t.userId),
113
114
  index("organizationId_role").on(t.organizationId, t.role),
115
+ // Backs `member.count({ where: { organizationId } })` for seat limits.
116
+ aggregateIndex("by_organization").on(t.organizationId),
114
117
  ]
115
118
  );
116
119
 
@@ -134,6 +137,10 @@ export const invitation = convexTable(
134
137
  t.status
135
138
  ),
136
139
  index("organizationId_status").on(t.organizationId, t.status),
140
+ // Backs `invitation.count({ where: { organizationId, status } })`.
141
+ // `count()` index matching is exact-set, so the aggregate key must list
142
+ // every field the filter constrains.
143
+ aggregateIndex("by_organization_status").on(t.organizationId, t.status),
137
144
  ]
138
145
  );
139
146
 
@@ -145,6 +152,11 @@ export const session = convexTable("session", {
145
152
  });
146
153
  ```
147
154
 
155
+ `count()` requires its aggregate index to be `READY`. Backfill these indexes
156
+ before routing live traffic to the count path. When schema and count code ship
157
+ together, catch only `COUNT_INDEX_BUILDING` and read the exact count from the
158
+ matching native organization index until backfill completes.
159
+
148
160
  ### Teams (Optional)
149
161
 
150
162
  ```ts
@@ -506,16 +518,18 @@ export const inviteMember = authMutation
506
518
  permissions: { invitation: ["create"] },
507
519
  });
508
520
 
509
- // Check member limit
510
- const members = await ctx.orm.query.member.findMany({
511
- where: { organizationId: input.organizationId },
512
- limit: DEFAULT_LIST_LIMIT,
513
- });
514
- const pending = await ctx.orm.query.invitation.findMany({
515
- where: { organizationId: input.organizationId, status: "pending" },
516
- limit: DEFAULT_LIST_LIMIT,
517
- });
518
- if (members.length + pending.length >= MEMBER_LIMIT) {
521
+ // Check member limit. Count off `aggregateIndex`, never by collecting rows
522
+ // to read `.length` -- that puts every member and pending invitation into
523
+ // the transaction's read set to produce two integers.
524
+ const [members, pending] = await Promise.all([
525
+ ctx.orm.query.member.count({
526
+ where: { organizationId: input.organizationId },
527
+ }),
528
+ ctx.orm.query.invitation.count({
529
+ where: { organizationId: input.organizationId, status: "pending" },
530
+ }),
531
+ ]);
532
+ if (members + pending >= MEMBER_LIMIT) {
519
533
  throw new CRPCError({
520
534
  code: "FORBIDDEN",
521
535
  message: `Organization member limit reached. Maximum ${MEMBER_LIMIT} members allowed.`,