kitcn 0.31.0 → 0.32.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.
@@ -1,3 +1,3 @@
1
- import { C as MigrationStep, D as defineMigration, E as buildMigrationPlan, O as defineMigrationSet, S as MigrationStateMap, T as MigrationWriteMode, _ as MigrationManifestEntry, a as MAX_STATUS_RUN_LIMIT, b as MigrationRunStatus, c as MigrationRunChunkArgs, d as MigrationAppliedState, f as MigrationDefinition, g as MigrationDriftIssue, h as MigrationDocContext, k as detectMigrationDrift, l as MigrationStatusArgs, m as MigrationDoc, o as MigrationCancelArgs, p as MigrationDirection, s as MigrationRunArgs, u as createMigrationHandlers, v as MigrationMigrateOne, w as MigrationTableName, x as MigrationSet, y as MigrationPlan } from "../../capabilities-DPB-JKlm.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-Dddhscyy.js";
1
+ import { C as MigrationStep, D as defineMigration, E as buildMigrationPlan, O as defineMigrationSet, S as MigrationStateMap, T as MigrationWriteMode, _ as MigrationManifestEntry, a as MAX_STATUS_RUN_LIMIT, b as MigrationRunStatus, c as MigrationRunChunkArgs, d as MigrationAppliedState, f as MigrationDefinition, g as MigrationDriftIssue, h as MigrationDocContext, k as detectMigrationDrift, l as MigrationStatusArgs, m as MigrationDoc, o as MigrationCancelArgs, p as MigrationDirection, s as MigrationRunArgs, u as createMigrationHandlers, v as MigrationMigrateOne, w as MigrationTableName, x as MigrationSet, y as MigrationPlan } from "../../capabilities-CD-Ij91k.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-FDJTqLDC.js";
3
3
  export { MAX_STATUS_RUN_LIMIT, 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 };
@@ -545,6 +545,13 @@ var OrderedStreamQuery = class extends StreamableQuery {
545
545
  minUpperBound = indexBounds.upperBound;
546
546
  minUpperBoundInclusive = indexBounds.upperBoundInclusive;
547
547
  }
548
+ if (compareKeys({
549
+ value: maxLowerBound,
550
+ kind: maxLowerBoundInclusive ? "predecessor" : "successor"
551
+ }, {
552
+ value: minUpperBound,
553
+ kind: minUpperBoundInclusive ? "successor" : "predecessor"
554
+ }) >= 0) return new EmptyStream(order, this.getIndexFields(), this.getEqualityIndexFilter());
548
555
  return streamIndexRange(db, schema, table, index, {
549
556
  lowerBound: maxLowerBound,
550
557
  lowerBoundInclusive: maxLowerBoundInclusive,
@@ -1050,7 +1057,7 @@ var SingletonStream = class SingletonStream extends QueryStream {
1050
1057
  }
1051
1058
  narrow(indexBounds) {
1052
1059
  if (indexKeyWithinBounds(this.#indexKey, indexBounds)) return new SingletonStream(this.#value, this.#order, this.#indexFields, this.#indexKey, this.#equalityIndexFilter);
1053
- return new EmptyStream(this.#order, this.#indexFields);
1060
+ return new EmptyStream(this.#order, this.#indexFields, this.#equalityIndexFilter);
1054
1061
  }
1055
1062
  };
1056
1063
  /**
@@ -1086,12 +1093,14 @@ function indexKeyWithinBounds(indexKey, indexBounds) {
1086
1093
  * towards maxScan.
1087
1094
  */
1088
1095
  var EmptyStream = class extends QueryStream {
1096
+ #equalityIndexFilter;
1089
1097
  #order;
1090
1098
  #indexFields;
1091
- constructor(order, indexFields) {
1099
+ constructor(order, indexFields, equalityIndexFilter = []) {
1092
1100
  super();
1093
1101
  this.#order = order;
1094
1102
  this.#indexFields = indexFields;
1103
+ this.#equalityIndexFilter = equalityIndexFilter;
1095
1104
  }
1096
1105
  iterWithKeys() {
1097
1106
  return { [Symbol.asyncIterator]() {
@@ -1110,7 +1119,7 @@ var EmptyStream = class extends QueryStream {
1110
1119
  return this.#indexFields;
1111
1120
  }
1112
1121
  getEqualityIndexFilter() {
1113
- return [];
1122
+ return this.#equalityIndexFilter;
1114
1123
  }
1115
1124
  narrow(_indexBounds) {
1116
1125
  return this;
@@ -1,6 +1,5 @@
1
- import { f as text, g as custom, m as integer, s as index, t as convexTable } from "./table-d9o_n4R3.js";
2
- import { t as id } from "./id-BVdWER1U.js";
3
- import { ConvexError, convexToJson, jsonToConvex, v } from "convex/values";
1
+ import { n as AGGREGATE_TREE_TABLE, t as AGGREGATE_NODE_TABLE } from "./schema-BFP_awgP.js";
2
+ import { ConvexError, convexToJson, jsonToConvex } from "convex/values";
4
3
 
5
4
  //#region src/aggregate-core/compare.ts
6
5
  function isCommitTsPlaceholder(value) {
@@ -44,36 +43,6 @@ function makeComparable(v) {
44
43
  return [8, keys.map((k) => [k, record[k]]).map(makeComparable)];
45
44
  }
46
45
 
47
- //#endregion
48
- //#region src/aggregate-core/schema.ts
49
- const AGGREGATE_TREE_TABLE = "aggregate_rank_tree";
50
- const AGGREGATE_NODE_TABLE = "aggregate_rank_node";
51
- const aggregateCounterValidator = v.object({
52
- count: v.number(),
53
- sum: v.number()
54
- });
55
- const aggregateItemValidator = v.object({
56
- k: v.any(),
57
- v: v.any(),
58
- s: v.number()
59
- });
60
- const aggregateTreeTable = convexTable(AGGREGATE_TREE_TABLE, {
61
- aggregateName: text().notNull(),
62
- deletionStack: custom(v.array(v.id(AGGREGATE_NODE_TABLE))),
63
- maxNodeSize: integer().notNull(),
64
- namespace: custom(v.any()),
65
- root: id(AGGREGATE_NODE_TABLE).notNull()
66
- }, (tree) => [index("by_namespace").on(tree.namespace), index("by_aggregate_name").on(tree.aggregateName)]);
67
- const aggregateNodeTable = convexTable(AGGREGATE_NODE_TABLE, {
68
- aggregate: custom(aggregateCounterValidator),
69
- items: custom(v.array(aggregateItemValidator)).notNull(),
70
- subtrees: custom(v.array(v.string())).notNull()
71
- });
72
- const aggregateStorageTables = {
73
- [AGGREGATE_NODE_TABLE]: aggregateNodeTable,
74
- [AGGREGATE_TREE_TABLE]: aggregateTreeTable
75
- };
76
-
77
46
  //#endregion
78
47
  //#region src/aggregate-core/btree.ts
79
48
  const DEFAULT_MAX_NODE_SIZE = 16;
@@ -525,14 +494,21 @@ async function deleteTreeNodes(db, node) {
525
494
  }
526
495
  /**
527
496
  * Deletes up to `limit` nodes from one namespace tree belonging to an
528
- * aggregate, returning true once none are left. The traversal stack lives on
497
+ * aggregate, reporting `done` once none are left. The traversal stack lives on
529
498
  * the tree document so a large tree resumes across transactions.
499
+ *
500
+ * Nodes are dropped whatever they contain, so a caller clearing an aggregate
501
+ * never has to empty the tree key by key first.
530
502
  */
531
503
  async function deleteTreesHandler(ctx, args) {
532
504
  const tree = (await ctx.db.query(AGGREGATE_TREE_TABLE).withIndex("by_aggregate_name", (q) => q.eq("aggregateName", args.aggregateName)).take(1))[0];
533
- if (!tree) return true;
505
+ if (!tree) return {
506
+ done: true,
507
+ documents: 0
508
+ };
534
509
  const stack = [...tree.deletionStack ?? [tree.root]];
535
510
  let remaining = Math.max(1, Math.floor(args.limit));
511
+ let documents = 0;
536
512
  while (stack.length > 0 && remaining > 0) {
537
513
  const nodeId = stack.pop();
538
514
  const node = await ctx.db.get(nodeId);
@@ -540,10 +516,14 @@ async function deleteTreesHandler(ctx, args) {
540
516
  if (!node) continue;
541
517
  stack.push(...node.subtrees);
542
518
  await ctx.db.delete(nodeId);
519
+ documents += 1;
543
520
  }
544
521
  if (stack.length > 0) await ctx.db.patch(tree._id, { deletionStack: stack });
545
522
  else await ctx.db.delete(tree._id);
546
- return false;
523
+ return {
524
+ done: false,
525
+ documents: documents + 1
526
+ };
547
527
  }
548
528
  async function clearTree(db, args) {
549
529
  const tree = await getTree(db, args.namespace);
@@ -935,9 +915,10 @@ var Aggregate = class {
935
915
  });
936
916
  }
937
917
  /**
938
- * Deletes up to `limit` namespace trees without recreating them. Returns true
939
- * once this aggregate owns no trees, so callers can drain every namespace
940
- * across several mutations instead of walking them all in one.
918
+ * Deletes up to `limit` nodes from one namespace tree without recreating it,
919
+ * reporting `done` once this aggregate owns no trees and how many documents
920
+ * the call wrote. Callers drain every namespace across several mutations
921
+ * instead of walking them all in one, and charge their budget by `documents`.
941
922
  */
942
923
  async deleteTrees(ctx, limit) {
943
924
  return deleteTreesHandler({ db: ctx.db }, {
@@ -1077,4 +1058,4 @@ function namespaceFromOpts(opts) {
1077
1058
  }
1078
1059
 
1079
1060
  //#endregion
1080
- export { TableAggregate as n, aggregateStorageTables as r, DirectAggregate as t };
1061
+ export { TableAggregate as n, DirectAggregate as t };
@@ -0,0 +1,67 @@
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 { v } from "convex/values";
3
+
4
+ //#region src/orm/builders/id.ts
5
+ /**
6
+ * ID column builder class
7
+ * Compiles to v.id(tableName) or v.optional(v.id(tableName))
8
+ */
9
+ var ConvexIdBuilder = class extends ConvexColumnBuilder {
10
+ static [entityKind] = "ConvexIdBuilder";
11
+ constructor(name, tableName) {
12
+ super(name, "string", "ConvexId");
13
+ this.tableName = tableName;
14
+ this.config.referenceTable = tableName;
15
+ }
16
+ /**
17
+ * Expose Convex validator for schema integration
18
+ */
19
+ get convexValidator() {
20
+ if (this.config.notNull) return v.id(this.tableName);
21
+ return v.optional(v.union(v.null(), v.id(this.tableName)));
22
+ }
23
+ /**
24
+ * Compile to Convex validator
25
+ * .notNull() → v.id(tableName)
26
+ * nullable → v.optional(v.id(tableName))
27
+ */
28
+ build() {
29
+ return this.convexValidator;
30
+ }
31
+ };
32
+ function id(tableName) {
33
+ return new ConvexIdBuilder("", tableName);
34
+ }
35
+
36
+ //#endregion
37
+ //#region src/aggregate-core/schema.ts
38
+ const AGGREGATE_TREE_TABLE = "aggregate_rank_tree";
39
+ const AGGREGATE_NODE_TABLE = "aggregate_rank_node";
40
+ const aggregateCounterValidator = v.object({
41
+ count: v.number(),
42
+ sum: v.number()
43
+ });
44
+ const aggregateItemValidator = v.object({
45
+ k: v.any(),
46
+ v: v.any(),
47
+ s: v.number()
48
+ });
49
+ const aggregateTreeTable = convexTable(AGGREGATE_TREE_TABLE, {
50
+ aggregateName: text().notNull(),
51
+ deletionStack: custom(v.array(v.id(AGGREGATE_NODE_TABLE))),
52
+ maxNodeSize: integer().notNull(),
53
+ namespace: custom(v.any()),
54
+ root: id(AGGREGATE_NODE_TABLE).notNull()
55
+ }, (tree) => [index("by_namespace").on(tree.namespace), index("by_aggregate_name").on(tree.aggregateName)]);
56
+ const aggregateNodeTable = convexTable(AGGREGATE_NODE_TABLE, {
57
+ aggregate: custom(aggregateCounterValidator),
58
+ items: custom(v.array(aggregateItemValidator)).notNull(),
59
+ subtrees: custom(v.array(v.string())).notNull()
60
+ });
61
+ const aggregateStorageTables = {
62
+ [AGGREGATE_NODE_TABLE]: aggregateNodeTable,
63
+ [AGGREGATE_TREE_TABLE]: aggregateTreeTable
64
+ };
65
+
66
+ //#endregion
67
+ export { aggregateTreeTable as a, aggregateStorageTables as i, AGGREGATE_TREE_TABLE as n, id as o, aggregateNodeTable as r, AGGREGATE_NODE_TABLE as t };
@@ -1,7 +1,7 @@
1
1
  import { _ as json, f as text, h as arrayOf, m as integer, s as index, t as convexTable, v as objectOf } from "./table-d9o_n4R3.js";
2
- import { t as id } from "./id-BVdWER1U.js";
2
+ import { a as aggregateTreeTable, n as AGGREGATE_TREE_TABLE, r as aggregateNodeTable, t as AGGREGATE_NODE_TABLE } from "./schema-BFP_awgP.js";
3
3
  import { g as TablePolymorphic, h as TableName, i as OrmContext, m as TableDeleteConfig, n as Columns } from "./symbols-DDNAddkd.js";
4
- import { E as filterValuesEqual, L as matchLikePattern, T as filterValueInList, d as INTERNAL_CREATION_TIME_FIELD, f as PUBLIC_CREATED_AT_FIELD, j as isFieldReference, m as usesSystemCreatedAtAlias, n as findIndexForColumns, p as hasUserCreatedAtColumn, s as getIndexes, t as findExactIndexForColumns, u as CREATED_AT_MIGRATION_MESSAGE, w as fieldRef } from "./index-utils-C1DyktHe.js";
4
+ import { E as filterValuesEqual, L as matchLikePattern, T as filterValueInList, d as INTERNAL_CREATION_TIME_FIELD, f as PUBLIC_CREATED_AT_FIELD, j as isFieldReference, m as usesSystemCreatedAtAlias, n as findIndexForColumns, p as hasUserCreatedAtColumn, s as getIndexes, t as findExactIndexForColumns, u as CREATED_AT_MIGRATION_MESSAGE, w as fieldRef } from "./index-utils-DvK7P6Q1.js";
5
5
  import { t as defineSchemaExtension } from "./extensions-Bp0XHanR.js";
6
6
 
7
7
  //#region src/internal/concurrency.ts
@@ -1344,9 +1344,11 @@ const getRankIndexDefinitions = (tableConfig) => {
1344
1344
  const AGGREGATE_BUCKET_TABLE = "aggregate_bucket";
1345
1345
  const AGGREGATE_MEMBER_TABLE = "aggregate_member";
1346
1346
  const AGGREGATE_EXTREMA_TABLE = "aggregate_extrema";
1347
- const AGGREGATE_RANK_TREE_TABLE = "aggregate_rank_tree";
1348
- const AGGREGATE_RANK_NODE_TABLE = "aggregate_rank_node";
1349
1347
  const AGGREGATE_STATE_TABLE = "aggregate_state";
1348
+ const AGGREGATE_RANK_TREE_TABLE = AGGREGATE_TREE_TABLE;
1349
+ const AGGREGATE_RANK_NODE_TABLE = AGGREGATE_NODE_TABLE;
1350
+ const rankTreeTable = aggregateTreeTable;
1351
+ const rankNodeTable = aggregateNodeTable;
1350
1352
  /**
1351
1353
  * Partition key a rank index's btree rows are stored under. Lives next to the
1352
1354
  * table names because it is how `AGGREGATE_RANK_TREE_TABLE` is addressed, and
@@ -1411,24 +1413,6 @@ const countStateTable = convexTable(AGGREGATE_STATE_TABLE, {
1411
1413
  index("by_kind_status").on(t.kind, t.status),
1412
1414
  index("by_table_status").on(t.tableKey, t.status)
1413
1415
  ]);
1414
- const rankTreeTable = convexTable(AGGREGATE_RANK_TREE_TABLE, {
1415
- aggregateName: text().notNull(),
1416
- maxNodeSize: integer().notNull(),
1417
- namespace: json(),
1418
- root: id(AGGREGATE_RANK_NODE_TABLE).notNull()
1419
- }, (tree) => [index("by_namespace").on(tree.namespace), index("by_aggregate_name").on(tree.aggregateName)]);
1420
- const rankNodeTable = convexTable(AGGREGATE_RANK_NODE_TABLE, {
1421
- aggregate: objectOf({
1422
- count: integer().notNull(),
1423
- sum: integer().notNull()
1424
- }),
1425
- items: arrayOf(objectOf({
1426
- k: json(),
1427
- v: json(),
1428
- s: integer().notNull()
1429
- })).notNull(),
1430
- subtrees: arrayOf(text().notNull()).notNull()
1431
- });
1432
1416
  const aggregateStorageTables = {
1433
1417
  [AGGREGATE_BUCKET_TABLE]: countBucketTable,
1434
1418
  [AGGREGATE_MEMBER_TABLE]: countMemberTable,
package/dist/watcher.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as generateMeta, d as PARSE_SNAPSHOT_SUFFIX, i as resolveConfiguredBackend, n as withLocalCodegenEnv, o as getConvexConfig, r as loadCliConfig, u as logger } from "./local-env-DGSkmXQk.mjs";
2
+ import { a as generateMeta, d as PARSE_SNAPSHOT_SUFFIX, i as resolveConfiguredBackend, n as withLocalCodegenEnv, o as getConvexConfig, r as loadCliConfig, u as logger } from "./local-env-CYYSNf_o.mjs";
3
3
  import path from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5