kitcn 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/aggregate/index.d.ts +11 -1
  2. package/dist/aggregate/index.js +1 -1
  3. package/dist/auth/generated/index.d.ts +1 -1
  4. package/dist/auth/generated/index.js +1 -1
  5. package/dist/auth/http/index.d.ts +1 -1
  6. package/dist/auth/index.d.ts +4 -4
  7. package/dist/auth/index.js +10 -9
  8. package/dist/auth/nextjs/index.d.ts +2 -2
  9. package/dist/auth/nextjs/index.js +3 -3
  10. package/dist/auth/start/server/index.d.ts +1 -1
  11. package/dist/auth/start/server/index.js +1 -1
  12. package/dist/{builder-CsxVc5xC.js → builder-1Vx-tEnS.js} +3 -3
  13. package/dist/{caller-factory-CWa0ELLD.js → caller-factory-Dd3H7j3V.js} +3 -3
  14. package/dist/{where-clause-compiler-B_H3oio5.d.ts → capabilities-Bem7xvGK.d.ts} +2958 -4145
  15. package/dist/cli.mjs +155 -60
  16. package/dist/{convex-plugin-D8B0oCFq.js → convex-plugin-DfOhBU9g.js} +1 -1
  17. package/dist/{create-schema-orm-B3f2Kc8O.js → create-schema-orm-Bu2JCiBS.js} +1 -1
  18. package/dist/crpc/index.d.ts +3 -3
  19. package/dist/crpc/index.js +4 -4
  20. package/dist/{customFunctions-DxEEO4Dq.js → customFunctions-BbhgdRGl.js} +2 -2
  21. package/dist/definitions-D9vhJ6OV.js +215 -0
  22. package/dist/extensions-DzjCJXYl.js +55 -0
  23. package/dist/filter-expression-Dydt8wS0.js +402 -0
  24. package/dist/{generated-contract-disabled-B-nmd7Ne.d.ts → generated-contract-disabled-BEc4d98x.d.ts} +2 -2
  25. package/dist/{http-types-BoSDAh4Y.d.ts → http-types-90mapMP9.d.ts} +33 -3
  26. package/dist/id-Bibg34Yb.js +37 -0
  27. package/dist/{local-env-yFKub75x.mjs → local-env-Du24tdbp.mjs} +2243 -2113
  28. package/dist/{middleware-Br5zubu7.d.ts → middleware-CE_MC6Gi.d.ts} +1 -1
  29. package/dist/{middleware-DUd1Sj39.js → middleware-cJDRHTRY.js} +1 -1
  30. package/dist/orm/aggregate-index/index.d.ts +20 -0
  31. package/dist/orm/aggregate-index/index.js +2136 -0
  32. package/dist/orm/index.d.ts +5 -4
  33. package/dist/orm/index.js +126 -4292
  34. package/dist/orm/migrations/index.d.ts +3 -0
  35. package/dist/orm/migrations/index.js +506 -0
  36. package/dist/plugins/index.d.ts +1 -1
  37. package/dist/plugins/index.js +1 -1
  38. package/dist/{procedure-caller-DQxnLBS_.js → procedure-caller-DIzXfX2E.js} +2 -2
  39. package/dist/{procedure-name-C55TynK3.d.ts → procedure-name-B09-cf1-.d.ts} +3 -3
  40. package/dist/{query-context-BzihIpnM.js → query-context-DOm5Xm3H.js} +1 -402
  41. package/dist/{query-options-C_eBSIXG.js → query-options-DUiOj01a.js} +33 -1
  42. package/dist/ratelimit/index.d.ts +47 -11
  43. package/dist/ratelimit/index.js +256 -102
  44. package/dist/react/index.d.ts +9 -6
  45. package/dist/react/index.js +36 -17
  46. package/dist/rsc/index.d.ts +6 -9
  47. package/dist/rsc/index.js +7 -11
  48. package/dist/runtime-DfGsZtx3.js +1074 -0
  49. package/dist/schema-Besl-rpv.js +1411 -0
  50. package/dist/server/index.d.ts +4 -4
  51. package/dist/server/index.js +4 -4
  52. package/dist/solid/index.d.ts +9 -6
  53. package/dist/solid/index.js +36 -17
  54. package/dist/{runtime-6DJxpDfb.js → table-rmJm5Qio.js} +3 -1095
  55. package/dist/{token-xlpENMVn.js → token-DcV_0fkF.js} +1 -1
  56. package/dist/{types-C0Xl7P8K.d.ts → types-In-ZZOsd.d.ts} +1 -1
  57. package/dist/{validators-C7LelqTN.js → validators-Dmbhsd3U.js} +1 -1
  58. package/dist/watcher.mjs +1 -1
  59. package/dist/where-clause-compiler-mohWFiG0.d.ts +2042 -0
  60. package/package.json +3 -2
  61. package/skills/kitcn/SKILL.md +19 -18
  62. package/skills/kitcn/references/features/aggregates.md +21 -0
  63. package/skills/kitcn/references/features/auth-organizations.md +3 -3
  64. package/skills/kitcn/references/features/auth-polar.md +2 -1
  65. package/skills/kitcn/references/features/auth.md +8 -1
  66. package/skills/kitcn/references/features/http.md +26 -1
  67. package/skills/kitcn/references/features/ratelimit.md +11 -0
  68. package/skills/kitcn/references/features/react.md +1 -1
  69. package/skills/kitcn/references/setup/auth.md +52 -42
  70. package/skills/kitcn/references/setup/index.md +1 -1
  71. package/skills/kitcn/references/setup/server.md +37 -6
  72. /package/dist/{api-entry-N3nBOlI2.js → api-entry-CkDpGYVg.js} +0 -0
  73. /package/dist/{context-utils-BBUtBqjN.d.ts → context-utils-DwZ3Cam1.d.ts} +0 -0
  74. /package/dist/{create-schema-BXrKE2YY.js → create-schema-BRFjdgRr.js} +0 -0
  75. /package/dist/{error-Bvo7YEhk.js → error-CMLeCadS.js} +0 -0
  76. /package/dist/{generated-contract-disabled-BXaz7JCE.js → generated-contract-disabled-CZa0iyV0.js} +0 -0
  77. /package/dist/{meta-utils-D9K4fICl.js → meta-utils-D2lqN2Lg.js} +0 -0
  78. /package/dist/{query-context-CNo9ffvI.d.ts → query-context-DJONf8X5.d.ts} +0 -0
  79. /package/dist/{token-B9Bjcqug.d.ts → token-kQaqFby4.d.ts} +0 -0
  80. /package/dist/{transformer-yZuBWo8v.js → transformer-D8wO-kEj.js} +0 -0
  81. /package/dist/{types-BCl8gfGy.d.ts → types-Bf3XQex5.d.ts} +0 -0
  82. /package/dist/{types-DF2cg_w0.d.ts → types-MHYXboyy.d.ts} +0 -0
  83. /package/dist/{types-CnTpHR1F.d.ts → types-eNzQmbqM.d.ts} +0 -0
  84. /package/dist/{upstream-BR6sBLg3.js → upstream-BCgGZX6q.js} +0 -0
  85. /package/dist/{validators-BhsByJeg.d.ts → validators-V4eM2-Jg.d.ts} +0 -0
@@ -0,0 +1,3 @@
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-Bem7xvGK.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-mohWFiG0.js";
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 };
@@ -0,0 +1,506 @@
1
+ import { a as MIGRATION_RUN_TABLE, c as injectMigrationStorageTables, i as detectMigrationDrift, l as migrationExtension, n as defineMigration, o as MIGRATION_STATE_TABLE, r as defineMigrationSet, s as MIGRATION_STORAGE_TABLE_NAMES, t as buildMigrationPlan, u as migrationStorageTables } from "../../definitions-D9vhJ6OV.js";
2
+
3
+ //#region src/orm/migrations/runtime.ts
4
+ const DEFAULT_BATCH_SIZE = 128;
5
+ function createMigrationHandlers(params) {
6
+ const { schema, migrations, getOrm, getChunkRef } = params;
7
+ const knownTables = new Set(Object.values(schema).map((tableConfig) => tableConfig.name));
8
+ const run = async (ctx, args = {}) => {
9
+ if (!migrations || migrations.migrations.length === 0) return {
10
+ status: "noop",
11
+ reason: "no_migrations_registered"
12
+ };
13
+ const direction = parseDirection(args.direction);
14
+ const dryRun = args.dryRun === true;
15
+ const allowDrift = args.allowDrift === true;
16
+ const restart = args.restart === true;
17
+ const batchSize = parseOptionalPositiveInteger(args.batchSize, "batchSize");
18
+ const steps = parseOptionalPositiveInteger(args.steps, "steps");
19
+ const to = parseOptionalString(args.to, "to");
20
+ const stateRows = await getAllStateRows(ctx.db);
21
+ const appliedState = toAppliedStateMap(stateRows);
22
+ const drift = detectMigrationDrift({
23
+ migrationSet: migrations,
24
+ appliedState
25
+ });
26
+ if (drift.length > 0 && !allowDrift) return {
27
+ status: "drift_blocked",
28
+ direction,
29
+ drift
30
+ };
31
+ const plan = buildMigrationPlan({
32
+ direction,
33
+ migrationSet: migrations,
34
+ appliedState,
35
+ steps,
36
+ to
37
+ });
38
+ if (plan.migrations.length === 0) return {
39
+ status: "noop",
40
+ direction,
41
+ drift,
42
+ plan: []
43
+ };
44
+ for (const migration of plan.migrations) {
45
+ const step = getStepForDirection(migration, direction);
46
+ if (!knownTables.has(step.table)) throw new Error(`Migration '${migration.id}' references unknown table '${step.table}'.`);
47
+ }
48
+ if (dryRun) return {
49
+ status: "dry_run",
50
+ direction,
51
+ drift,
52
+ plan: plan.migrations.map((migration) => migration.id)
53
+ };
54
+ const activeRun = await getActiveRun(ctx.db);
55
+ if (activeRun) return {
56
+ status: "running",
57
+ runId: activeRun.runId
58
+ };
59
+ const now = Date.now();
60
+ const runId = createRunId(now);
61
+ await ctx.db.insert(MIGRATION_RUN_TABLE, {
62
+ runId,
63
+ direction,
64
+ status: "running",
65
+ dryRun: false,
66
+ allowDrift,
67
+ migrationIds: plan.migrations.map((migration) => migration.id),
68
+ currentIndex: 0,
69
+ startedAt: now,
70
+ updatedAt: now,
71
+ cancelRequested: false
72
+ });
73
+ const stateById = new Map(stateRows.map((row) => [row.migrationId, row]));
74
+ for (const migration of plan.migrations) {
75
+ const writeMode = getStepForDirection(migration, direction).writeMode ?? "safe_bypass";
76
+ const existing = stateById.get(migration.id);
77
+ const resetProgress = restart || existing?.direction !== direction;
78
+ if (existing) await ctx.db.patch(existing._id, cleanUndefined({
79
+ checksum: migration.checksum,
80
+ status: "pending",
81
+ direction,
82
+ runId,
83
+ cursor: resetProgress ? null : existing.cursor ?? null,
84
+ processed: resetProgress ? 0 : existing.processed ?? 0,
85
+ startedAt: now,
86
+ updatedAt: now,
87
+ completedAt: null,
88
+ lastError: null,
89
+ writeMode
90
+ }));
91
+ else await ctx.db.insert(MIGRATION_STATE_TABLE, {
92
+ migrationId: migration.id,
93
+ checksum: migration.checksum,
94
+ applied: direction === "down",
95
+ status: "pending",
96
+ direction,
97
+ runId,
98
+ cursor: null,
99
+ processed: 0,
100
+ startedAt: now,
101
+ updatedAt: now,
102
+ completedAt: null,
103
+ lastError: null,
104
+ writeMode
105
+ });
106
+ }
107
+ if (ctx.scheduler) {
108
+ const chunkRef = getChunkRef();
109
+ if (chunkRef) {
110
+ const chunkArgs = { runId };
111
+ if (batchSize !== void 0) chunkArgs.batchSize = batchSize;
112
+ await ctx.scheduler.runAfter(0, chunkRef, chunkArgs);
113
+ return {
114
+ status: "running",
115
+ direction,
116
+ runId,
117
+ plan: plan.migrations.map((migration) => migration.id)
118
+ };
119
+ }
120
+ }
121
+ const inlineResult = await chunk(ctx, {
122
+ runId,
123
+ batchSize
124
+ });
125
+ return {
126
+ status: "running",
127
+ direction,
128
+ runId,
129
+ plan: plan.migrations.map((migration) => migration.id),
130
+ inlineResult
131
+ };
132
+ };
133
+ const chunk = async (ctx, args) => {
134
+ const runId = parseRequiredString(args.runId, "runId");
135
+ const batchSize = parseOptionalPositiveInteger(args.batchSize, "batchSize");
136
+ const runRow = await getRunById(ctx.db, runId);
137
+ if (!runRow) return {
138
+ status: "missing",
139
+ runId
140
+ };
141
+ if (runRow.status !== "running") return {
142
+ status: runRow.status,
143
+ runId
144
+ };
145
+ if (runRow.cancelRequested) {
146
+ await markRunCanceled(ctx.db, runRow);
147
+ return {
148
+ status: "canceled",
149
+ runId
150
+ };
151
+ }
152
+ const migrationId = runRow.migrationIds[runRow.currentIndex];
153
+ if (!migrationId) {
154
+ await markRunCompleted(ctx.db, runRow);
155
+ return {
156
+ status: "completed",
157
+ runId
158
+ };
159
+ }
160
+ const migration = migrations?.byId[migrationId];
161
+ if (!migration) {
162
+ await markRunFailed(ctx.db, runRow, `Migration '${migrationId}' is missing from registry.`);
163
+ return {
164
+ status: "failed",
165
+ runId
166
+ };
167
+ }
168
+ const direction = parseDirection(runRow.direction);
169
+ const step = getStepForDirection(migration, direction);
170
+ const resolvedBatchSize = batchSize ?? step.batchSize ?? DEFAULT_BATCH_SIZE;
171
+ const stateRow = await getOrCreateStateRow(ctx.db, migration, direction, step);
172
+ const cursor = stateRow.cursor ?? null;
173
+ try {
174
+ const page = await ctx.db.query(step.table).paginate({
175
+ cursor,
176
+ numItems: resolvedBatchSize
177
+ });
178
+ const docs = Array.isArray(page?.page) ? page.page : [];
179
+ const orm = getOrm(ctx);
180
+ const writeMode = step.writeMode ?? "safe_bypass";
181
+ let processedInBatch = 0;
182
+ for (const doc of docs) {
183
+ const migrationCtxBase = {
184
+ db: ctx.db,
185
+ migrationId,
186
+ runId,
187
+ direction,
188
+ dryRun: false,
189
+ writeMode
190
+ };
191
+ const result = await runWithWriteMode(orm, writeMode, (resolvedOrm) => step.migrateOne({
192
+ ...migrationCtxBase,
193
+ orm: resolvedOrm
194
+ }, doc));
195
+ if (isPatchPayload(result) && hasDocId(doc)) await ctx.db.patch(doc._id, result);
196
+ processedInBatch += 1;
197
+ }
198
+ const now = Date.now();
199
+ const isDone = Boolean(page?.isDone);
200
+ const nextCursor = isDone ? null : page?.continueCursor ?? null;
201
+ const nextProcessed = (stateRow.processed ?? 0) + processedInBatch;
202
+ if (isDone) {
203
+ await ctx.db.patch(stateRow._id, cleanUndefined({
204
+ status: "completed",
205
+ applied: direction === "up",
206
+ cursor: null,
207
+ processed: nextProcessed,
208
+ completedAt: now,
209
+ updatedAt: now,
210
+ lastError: null,
211
+ runId,
212
+ direction,
213
+ writeMode
214
+ }));
215
+ const nextIndex = runRow.currentIndex + 1;
216
+ const done = nextIndex >= runRow.migrationIds.length;
217
+ await ctx.db.patch(runRow._id, cleanUndefined({
218
+ currentIndex: nextIndex,
219
+ status: done ? "completed" : "running",
220
+ updatedAt: now,
221
+ completedAt: done ? now : null,
222
+ lastError: null
223
+ }));
224
+ if (!done && ctx.scheduler) {
225
+ const chunkRef = getChunkRef();
226
+ if (chunkRef) await ctx.scheduler.runAfter(0, chunkRef, {
227
+ runId,
228
+ batchSize: resolvedBatchSize
229
+ });
230
+ }
231
+ return {
232
+ status: done ? "completed" : "running",
233
+ runId,
234
+ migrationId,
235
+ processedInBatch,
236
+ processed: nextProcessed,
237
+ currentIndex: nextIndex,
238
+ total: runRow.migrationIds.length
239
+ };
240
+ }
241
+ await ctx.db.patch(stateRow._id, cleanUndefined({
242
+ status: "running",
243
+ cursor: nextCursor,
244
+ processed: nextProcessed,
245
+ updatedAt: now,
246
+ runId,
247
+ direction,
248
+ writeMode
249
+ }));
250
+ await ctx.db.patch(runRow._id, cleanUndefined({
251
+ status: "running",
252
+ updatedAt: now
253
+ }));
254
+ if (ctx.scheduler) {
255
+ const chunkRef = getChunkRef();
256
+ if (chunkRef) await ctx.scheduler.runAfter(0, chunkRef, {
257
+ runId,
258
+ batchSize: resolvedBatchSize
259
+ });
260
+ }
261
+ return {
262
+ status: "running",
263
+ runId,
264
+ migrationId,
265
+ processedInBatch,
266
+ processed: nextProcessed,
267
+ cursor: nextCursor
268
+ };
269
+ } catch (error) {
270
+ const message = error.message || String(error);
271
+ await ctx.db.patch(stateRow._id, cleanUndefined({
272
+ status: "failed",
273
+ lastError: message,
274
+ updatedAt: Date.now()
275
+ }));
276
+ await markRunFailed(ctx.db, runRow, message);
277
+ return {
278
+ status: "failed",
279
+ runId,
280
+ migrationId,
281
+ error: message
282
+ };
283
+ }
284
+ };
285
+ const status = async (ctx, args = {}) => {
286
+ if (!migrations) return {
287
+ status: "noop",
288
+ reason: "no_migrations_registered"
289
+ };
290
+ const limit = parseOptionalPositiveInteger(args.limit, "limit") ?? 25;
291
+ const runId = parseOptionalString(args.runId, "runId");
292
+ const stateRows = await getAllStateRows(ctx.db);
293
+ const sortedRuns = [...await getAllRunRows(ctx.db)].sort((left, right) => right.startedAt - left.startedAt);
294
+ const selectedRuns = runId ? sortedRuns.filter((entry) => entry.runId === runId).slice(0, 1) : sortedRuns.slice(0, limit);
295
+ const activeRun = sortedRuns.find((entry) => entry.status === "running") ?? null;
296
+ const appliedState = toAppliedStateMap(stateRows);
297
+ const drift = detectMigrationDrift({
298
+ migrationSet: migrations,
299
+ appliedState
300
+ });
301
+ const pendingUp = buildMigrationPlan({
302
+ direction: "up",
303
+ migrationSet: migrations,
304
+ appliedState
305
+ });
306
+ return {
307
+ status: activeRun ? "running" : "idle",
308
+ activeRun,
309
+ runs: selectedRuns,
310
+ migrations: stateRows.map((row) => ({
311
+ migrationId: row.migrationId,
312
+ checksum: row.checksum,
313
+ applied: row.applied,
314
+ status: row.status,
315
+ direction: row.direction ?? null,
316
+ runId: row.runId ?? null,
317
+ cursor: row.cursor ?? null,
318
+ processed: row.processed,
319
+ updatedAt: row.updatedAt,
320
+ startedAt: row.startedAt ?? null,
321
+ completedAt: row.completedAt ?? null,
322
+ lastError: row.lastError ?? null,
323
+ writeMode: row.writeMode
324
+ })),
325
+ pending: pendingUp.migrations.map((migration) => migration.id),
326
+ drift
327
+ };
328
+ };
329
+ const cancel = async (ctx, args = {}) => {
330
+ if (!migrations) return {
331
+ status: "noop",
332
+ reason: "no_migrations_registered"
333
+ };
334
+ const runId = parseOptionalString(args.runId, "runId");
335
+ const runRow = runId ? await getRunById(ctx.db, runId) : await getActiveRun(ctx.db);
336
+ if (!runRow) return {
337
+ status: "noop",
338
+ reason: "no_active_run"
339
+ };
340
+ if (runRow.status !== "running") return {
341
+ status: "noop",
342
+ reason: "run_not_running",
343
+ runId: runRow.runId,
344
+ runStatus: runRow.status
345
+ };
346
+ const now = Date.now();
347
+ await ctx.db.patch(runRow._id, cleanUndefined({
348
+ cancelRequested: true,
349
+ updatedAt: now
350
+ }));
351
+ if (!(ctx.scheduler ? getChunkRef() : void 0)) {
352
+ await markRunCanceled(ctx.db, runRow);
353
+ return {
354
+ status: "canceled",
355
+ runId: runRow.runId
356
+ };
357
+ }
358
+ return {
359
+ status: "cancel_requested",
360
+ runId: runRow.runId
361
+ };
362
+ };
363
+ return {
364
+ run,
365
+ chunk,
366
+ status,
367
+ cancel
368
+ };
369
+ }
370
+ function getStepForDirection(migration, direction) {
371
+ if (direction === "up") return migration.up;
372
+ if (!migration.down) throw new Error(`Migration '${migration.id}' is missing down migration.`);
373
+ return migration.down;
374
+ }
375
+ function createRunId(now) {
376
+ return `mr_${now}_${Math.random().toString(36).slice(2, 10)}`;
377
+ }
378
+ function parseDirection(value) {
379
+ if (value === void 0 || value === null) return "up";
380
+ if (value === "up" || value === "down") return value;
381
+ throw new Error("Migration direction must be either 'up' or 'down'.");
382
+ }
383
+ function parseOptionalPositiveInteger(value, fieldName) {
384
+ if (value === void 0 || value === null) return;
385
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1) throw new Error(`Migration ${fieldName} must be a positive integer.`);
386
+ return value;
387
+ }
388
+ function parseOptionalString(value, fieldName) {
389
+ if (value === void 0 || value === null) return;
390
+ if (typeof value !== "string" || value.length === 0) throw new Error(`Migration ${fieldName} must be a non-empty string.`);
391
+ return value;
392
+ }
393
+ function parseRequiredString(value, fieldName) {
394
+ const parsed = parseOptionalString(value, fieldName);
395
+ if (!parsed) throw new Error(`Migration ${fieldName} is required.`);
396
+ return parsed;
397
+ }
398
+ function toAppliedStateMap(stateRows) {
399
+ const entries = {};
400
+ for (const row of stateRows) entries[row.migrationId] = {
401
+ applied: row.applied,
402
+ checksum: row.checksum,
403
+ cursor: row.cursor ?? null,
404
+ processed: row.processed
405
+ };
406
+ return entries;
407
+ }
408
+ async function getAllStateRows(db) {
409
+ return await db.query(MIGRATION_STATE_TABLE).collect();
410
+ }
411
+ async function getAllRunRows(db) {
412
+ return await db.query(MIGRATION_RUN_TABLE).collect();
413
+ }
414
+ async function getRunById(db, runId) {
415
+ return await db.query(MIGRATION_RUN_TABLE).withIndex("by_run_id", (query) => query.eq("runId", runId)).first() ?? null;
416
+ }
417
+ async function getActiveRun(db) {
418
+ return await db.query(MIGRATION_RUN_TABLE).withIndex("by_status", (query) => query.eq("status", "running")).first() ?? null;
419
+ }
420
+ async function getOrCreateStateRow(db, migration, direction, step) {
421
+ const existing = await db.query(MIGRATION_STATE_TABLE).withIndex("by_migration_id", (query) => query.eq("migrationId", migration.id)).first();
422
+ if (existing) return existing;
423
+ const now = Date.now();
424
+ const stateId = await db.insert(MIGRATION_STATE_TABLE, {
425
+ migrationId: migration.id,
426
+ checksum: migration.checksum,
427
+ applied: direction === "down",
428
+ status: "pending",
429
+ direction,
430
+ runId: null,
431
+ cursor: null,
432
+ processed: 0,
433
+ startedAt: now,
434
+ updatedAt: now,
435
+ completedAt: null,
436
+ lastError: null,
437
+ writeMode: step.writeMode ?? "safe_bypass"
438
+ });
439
+ const created = await db.get(stateId);
440
+ if (!created) throw new Error(`Failed to create migration state row for '${migration.id}'.`);
441
+ return created;
442
+ }
443
+ async function markRunCompleted(db, runRow) {
444
+ const now = Date.now();
445
+ await db.patch(runRow._id, cleanUndefined({
446
+ status: "completed",
447
+ updatedAt: now,
448
+ completedAt: now,
449
+ cancelRequested: false,
450
+ lastError: null
451
+ }));
452
+ }
453
+ async function markRunCanceled(db, runRow) {
454
+ const now = Date.now();
455
+ await db.patch(runRow._id, cleanUndefined({
456
+ status: "canceled",
457
+ updatedAt: now,
458
+ completedAt: now,
459
+ cancelRequested: true
460
+ }));
461
+ for (const stateRow of await getAllStateRows(db)) if (stateRow.runId === runRow.runId && (stateRow.status === "running" || stateRow.status === "pending")) await db.patch(stateRow._id, cleanUndefined({
462
+ status: "canceled",
463
+ updatedAt: now
464
+ }));
465
+ }
466
+ async function markRunFailed(db, runRow, message) {
467
+ const now = Date.now();
468
+ await db.patch(runRow._id, cleanUndefined({
469
+ status: "failed",
470
+ updatedAt: now,
471
+ completedAt: now,
472
+ lastError: message
473
+ }));
474
+ }
475
+ async function runWithWriteMode(orm, writeMode, callback) {
476
+ if (writeMode === "normal") return await callback(orm);
477
+ return await orm.skipRules.withoutTriggers(async (noTriggersOrm) => {
478
+ return await callback(noTriggersOrm);
479
+ });
480
+ }
481
+ function isPatchPayload(value) {
482
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
483
+ }
484
+ function hasDocId(doc) {
485
+ return "_id" in doc && doc._id !== void 0 && doc._id !== null;
486
+ }
487
+ function cleanUndefined(value) {
488
+ return Object.fromEntries(Object.entries(value).filter(([, candidate]) => candidate !== void 0));
489
+ }
490
+
491
+ //#endregion
492
+ //#region src/orm/migrations/capability.ts
493
+ /**
494
+ * Registers the migration runtime with `createOrm()`.
495
+ *
496
+ * Required by the migration handlers exposed through `orm.api()`. Importing
497
+ * this pulls the migration runtime into the calling Convex module, so only
498
+ * register it where it is actually used.
499
+ */
500
+ const migrationCapability = () => ({
501
+ kind: "migrations",
502
+ value: { createMigrationHandlers }
503
+ });
504
+
505
+ //#endregion
506
+ export { MIGRATION_RUN_TABLE, MIGRATION_STATE_TABLE, MIGRATION_STORAGE_TABLE_NAMES, buildMigrationPlan, createMigrationHandlers, defineMigration, defineMigrationSet, detectMigrationDrift, injectMigrationStorageTables, migrationCapability, migrationExtension, migrationStorageTables };
@@ -1,2 +1,2 @@
1
- import { a as PluginConfigureResolver, i as PluginConfigureInput, n as PluginApiScope, o as definePlugin, r as PluginConfigureContext, s as resolvePluginOptions, t as Plugin } from "../middleware-Br5zubu7.js";
1
+ import { a as PluginConfigureResolver, i as PluginConfigureInput, n as PluginApiScope, o as definePlugin, r as PluginConfigureContext, s as resolvePluginOptions, t as Plugin } from "../middleware-CE_MC6Gi.js";
2
2
  export { type Plugin, type PluginApiScope, type PluginConfigureContext, type PluginConfigureInput, type PluginConfigureResolver, definePlugin, resolvePluginOptions };
@@ -1,3 +1,3 @@
1
- import { n as resolvePluginOptions, t as definePlugin } from "../middleware-DUd1Sj39.js";
1
+ import { n as resolvePluginOptions, t as definePlugin } from "../middleware-cJDRHTRY.js";
2
2
 
3
3
  export { definePlugin, resolvePluginOptions };
@@ -1,5 +1,5 @@
1
- import { i as decodeWire, o as encodeWire } from "./transformer-yZuBWo8v.js";
2
- import { _ as CRPCError } from "./builder-CsxVc5xC.js";
1
+ import { i as decodeWire, o as encodeWire } from "./transformer-D8wO-kEj.js";
2
+ import { _ as CRPCError } from "./builder-1Vx-tEnS.js";
3
3
  import { z } from "zod";
4
4
 
5
5
  //#region src/server/env.ts
@@ -1,6 +1,6 @@
1
- import { t as VRequired } from "./validators-BhsByJeg.js";
2
- import { C as HttpProcedure, D as ProcedureMeta, R as getTransformer, S as HttpMethod, c as InferHttpInput, d as CRPCHttpRouter, j as DataTransformerOptions, l as InferHttpOutput, p as HttpRouterRecord, w as HttpProcedureBuilderDef, x as HttpHandlerOpts } from "./http-types-BoSDAh4Y.js";
3
- import { g as UnsetMarker, i as IntersectIfDefined, o as MiddlewareBuilder, p as Overwrite$1, s as MiddlewareFunction, t as AnyMiddleware } from "./types-CnTpHR1F.js";
1
+ import { t as VRequired } from "./validators-V4eM2-Jg.js";
2
+ import { A as HttpProcedureBuilderDef, D as HttpHandlerOpts, L as DataTransformerOptions, N as ProcedureMeta, O as HttpMethod, W as getTransformer, _ as CRPCHttpRouter, f as InferHttpInput, k as HttpProcedure, p as InferHttpOutput, y as HttpRouterRecord } from "./http-types-90mapMP9.js";
3
+ import { g as UnsetMarker, i as IntersectIfDefined, o as MiddlewareBuilder, p as Overwrite$1, s as MiddlewareFunction, t as AnyMiddleware } from "./types-eNzQmbqM.js";
4
4
  import { ConvexError, GenericId, GenericValidator, ObjectType, OptionalProperty, PropertyValidators, VAny, VArray, VBoolean, VBytes, VFloat64, VId, VInt64, VLiteral, VNull, VObject, VOptional, VRecord, VString, VUnion, Validator, Value as Value$1 } from "convex/values";
5
5
  import { ActionBuilder, ArgsArrayToObject, DefaultFunctionArgs, FunctionReference, FunctionReturnType, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder, RegisteredAction, RegisteredMutation, RegisteredQuery, TableNamesInDataModel } from "convex/server";
6
6
  import { z } from "zod";