arkormx 2.12.8 → 2.12.10

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/dist/cli.mjs CHANGED
@@ -242,6 +242,9 @@ const readAppliedMigrationsState = (stateFilePath) => {
242
242
  version: 1,
243
243
  migrations: parsed.migrations.filter((migration) => {
244
244
  return typeof migration?.id === "string" && typeof migration?.file === "string" && typeof migration?.className === "string" && typeof migration?.appliedAt === "string" && (migration?.checksum === void 0 || typeof migration?.checksum === "string");
245
+ }).map((migration) => migration.operations === void 0 || Array.isArray(migration.operations) ? migration : {
246
+ ...migration,
247
+ operations: void 0
245
248
  }),
246
249
  runs: Array.isArray(parsed.runs) ? parsed.runs.filter((run) => {
247
250
  return typeof run?.id === "string" && typeof run?.appliedAt === "string" && Array.isArray(run?.migrationIds) && run.migrationIds.every((item) => typeof item === "string");
@@ -267,6 +270,20 @@ const writeAppliedMigrationsStateToStore = async (adapter, stateFilePath, state)
267
270
  }
268
271
  writeAppliedMigrationsState(stateFilePath, state);
269
272
  };
273
+ /**
274
+ * Whether `identity` counts as applied in `state`.
275
+ *
276
+ * Passing a `checksum` makes an edited migration file count as *not* applied so
277
+ * it is re-run. That only suits the Prisma/file-backed flow, where re-applying a
278
+ * migration just rewrites the generated schema. Adapter-backed runtimes must
279
+ * omit the checksum and let the state store alone decide, since replaying an
280
+ * already-applied `up()` would run its SQL a second time.
281
+ *
282
+ * @param state
283
+ * @param identity
284
+ * @param checksum
285
+ * @returns
286
+ */
270
287
  const isMigrationApplied = (state, identity, checksum) => {
271
288
  const matched = state.migrations.find((migration) => migration.id === identity);
272
289
  if (!matched) return false;
@@ -622,6 +639,30 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
622
639
  tables: nextTables
623
640
  };
624
641
  };
642
+ /**
643
+ * Replays an applied migration's `up()` from the current file to recover its
644
+ * schema plan.
645
+ *
646
+ * Only used for entries recorded before the plan was stored alongside them; the
647
+ * result reflects the file as it stands now, which is why a recorded plan always
648
+ * wins over this.
649
+ *
650
+ * @param migration
651
+ * @param availableByIdentity
652
+ * @returns
653
+ */
654
+ const replayAppliedMigrationPlan = async (migration, availableByIdentity) => {
655
+ const migrationClass = availableByIdentity.get(migration.id);
656
+ if (!migrationClass) throw new ArkormException(`Unable to rebuild persisted column mappings because migration [${migration.id}] could not be resolved from the current migration files.`, {
657
+ operation: "migration.columnMappings",
658
+ meta: {
659
+ migrationId: migration.id,
660
+ file: migration.file,
661
+ className: migration.className
662
+ }
663
+ });
664
+ return await getMigrationPlan(migrationClass, "up", { inert: true });
665
+ };
625
666
  const rebuildPersistedColumnMappingsState = async (state, availableMigrations, features = resolvePersistedMetadataFeatures()) => {
626
667
  const availableByIdentity = new Map(availableMigrations.map(([migrationClass, file]) => [buildMigrationIdentity(file, migrationClass.name), migrationClass]));
627
668
  let nextState = createEmptyPersistedColumnMappingsState();
@@ -634,16 +675,7 @@ const rebuildPersistedColumnMappingsState = async (state, availableMigrations, f
634
675
  return left.index - right.index;
635
676
  });
636
677
  for (const { migration } of orderedMigrations) {
637
- const migrationClass = availableByIdentity.get(migration.id);
638
- if (!migrationClass) throw new ArkormException(`Unable to rebuild persisted column mappings because migration [${migration.id}] could not be resolved from the current migration files.`, {
639
- operation: "migration.columnMappings",
640
- meta: {
641
- migrationId: migration.id,
642
- file: migration.file,
643
- className: migration.className
644
- }
645
- });
646
- const operations = await getMigrationPlan(migrationClass, "up", { inert: true });
678
+ const operations = migration.operations ?? await replayAppliedMigrationPlan(migration, availableByIdentity);
647
679
  nextState = applyOperationsToPersistedColumnMappingsState(nextState, operations, features);
648
680
  }
649
681
  return nextState;
@@ -5117,13 +5149,18 @@ var MigrateCommand = class extends Command {
5117
5149
  if (!appliedMigrationState) return true;
5118
5150
  const identity = buildMigrationIdentity(file, migrationClass.name);
5119
5151
  const checksum = computeMigrationChecksum(file);
5120
- const alreadyApplied = isMigrationApplied(appliedMigrationState, identity, checksum);
5121
- if (alreadyApplied) skipped.push([migrationClass, file]);
5122
- else if (findAppliedMigration(appliedMigrationState, identity)) changed.push([migrationClass, file]);
5152
+ const recorded = findAppliedMigration(appliedMigrationState, identity);
5153
+ const alreadyApplied = useDatabaseMigrations ? Boolean(recorded) : isMigrationApplied(appliedMigrationState, identity, checksum);
5154
+ if (alreadyApplied) skipped.push([
5155
+ migrationClass,
5156
+ file,
5157
+ Boolean(recorded?.checksum) && recorded?.checksum !== checksum
5158
+ ]);
5159
+ else if (recorded) changed.push([migrationClass, file]);
5123
5160
  return !alreadyApplied;
5124
5161
  });
5125
- skipped.forEach(([migrationClass, file]) => {
5126
- this.success(this.app.splitLogger("Skipped", `${file} (${migrationClass.name})`));
5162
+ skipped.forEach(([migrationClass, file, drifted]) => {
5163
+ this.success(this.app.splitLogger("Skipped", `${file} (${migrationClass.name})${drifted ? " [changed since applied]" : ""}`));
5127
5164
  });
5128
5165
  changed.forEach(([migrationClass, file]) => {
5129
5166
  this.success(this.app.splitLogger("Changed", `${file} (${migrationClass.name})`));
@@ -5140,7 +5177,9 @@ var MigrateCommand = class extends Command {
5140
5177
  return;
5141
5178
  }
5142
5179
  let columnMappingsState = createEmptyPersistedColumnMappingsState();
5143
- for (const [MigrationClassItem] of pending) {
5180
+ const executedPlans = /* @__PURE__ */ new Map();
5181
+ for (const [MigrationClassItem, file] of pending) {
5182
+ const identity = buildMigrationIdentity(file, MigrationClassItem.name);
5144
5183
  if (useDatabaseMigrations) {
5145
5184
  const planned = await this.runWithDatabaseCreationRetry(adapter, () => getMigrationPlan(MigrationClassItem, "up", { inert: true }));
5146
5185
  if (!planned.ok) return;
@@ -5150,13 +5189,16 @@ var MigrateCommand = class extends Command {
5150
5189
  this.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
5151
5190
  return;
5152
5191
  }
5153
- if (!(await this.runWithDatabaseCreationRetry(adapter, () => applyMigrationToDatabase(adapter, MigrationClassItem))).ok) return;
5192
+ const applied = await this.runWithDatabaseCreationRetry(adapter, () => applyMigrationToDatabase(adapter, MigrationClassItem));
5193
+ if (!applied.ok) return;
5194
+ executedPlans.set(identity, applied.value.operations);
5154
5195
  continue;
5155
5196
  }
5156
- await applyMigrationToPrismaSchema(MigrationClassItem, {
5197
+ const applied = await applyMigrationToPrismaSchema(MigrationClassItem, {
5157
5198
  schemaPath,
5158
5199
  write: true
5159
5200
  });
5201
+ executedPlans.set(identity, applied.operations);
5160
5202
  }
5161
5203
  if (appliedMigrationState) {
5162
5204
  const runAppliedIds = [];
@@ -5167,7 +5209,8 @@ var MigrateCommand = class extends Command {
5167
5209
  file,
5168
5210
  className: migrationClass.name,
5169
5211
  appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
5170
- checksum: computeMigrationChecksum(file)
5212
+ checksum: computeMigrationChecksum(file),
5213
+ operations: executedPlans.get(identity)
5171
5214
  });
5172
5215
  runAppliedIds.push(identity);
5173
5216
  }
@@ -5356,23 +5399,32 @@ var MigrateFreshCommand = class extends Command {
5356
5399
  }
5357
5400
  let appliedState = createEmptyAppliedMigrationsState();
5358
5401
  if (!(await this.runWithDatabaseCreationRetry(adapter, () => writeAppliedMigrationsStateToStore(adapter, stateFilePath, appliedState))).ok) return;
5359
- for (const [MigrationClassItem] of migrations) {
5402
+ const executedPlans = /* @__PURE__ */ new Map();
5403
+ for (const [MigrationClassItem, file] of migrations) {
5404
+ const identity = buildMigrationIdentity(file, MigrationClassItem.name);
5360
5405
  if (useDatabaseMigrations) {
5361
- if (!(await this.runWithDatabaseCreationRetry(adapter, () => applyMigrationToDatabase(adapter, MigrationClassItem))).ok) return;
5406
+ const applied = await this.runWithDatabaseCreationRetry(adapter, () => applyMigrationToDatabase(adapter, MigrationClassItem));
5407
+ if (!applied.ok) return;
5408
+ executedPlans.set(identity, applied.value.operations);
5362
5409
  continue;
5363
5410
  }
5364
- await applyMigrationToPrismaSchema(MigrationClassItem, {
5411
+ const applied = await applyMigrationToPrismaSchema(MigrationClassItem, {
5365
5412
  schemaPath,
5366
5413
  write: true
5367
5414
  });
5415
+ executedPlans.set(identity, applied.operations);
5416
+ }
5417
+ for (const [migrationClass, file] of migrations) {
5418
+ const identity = buildMigrationIdentity(file, migrationClass.name);
5419
+ appliedState = markMigrationApplied(appliedState, {
5420
+ id: identity,
5421
+ file,
5422
+ className: migrationClass.name,
5423
+ appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
5424
+ checksum: computeMigrationChecksum(file),
5425
+ operations: executedPlans.get(identity)
5426
+ });
5368
5427
  }
5369
- for (const [migrationClass, file] of migrations) appliedState = markMigrationApplied(appliedState, {
5370
- id: buildMigrationIdentity(file, migrationClass.name),
5371
- file,
5372
- className: migrationClass.name,
5373
- appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
5374
- checksum: computeMigrationChecksum(file)
5375
- });
5376
5428
  appliedState = markMigrationRun(appliedState, {
5377
5429
  id: buildMigrationRunId(),
5378
5430
  appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -5582,7 +5634,7 @@ var MigrationHistoryCommand = class extends Command {
5582
5634
  {--state-file= : Path to applied migration state file}
5583
5635
  {--reset : Clear tracked migration history file}
5584
5636
  {--delete : Delete tracked migration history file}
5585
- {--json : Print raw JSON output}
5637
+ {--json : Print JSON output (without each migration's recorded schema plan)}
5586
5638
  `;
5587
5639
  this.description = "Inspect or reset tracked migration history";
5588
5640
  }
@@ -5618,7 +5670,11 @@ var MigrationHistoryCommand = class extends Command {
5618
5670
  if (this.option("json")) {
5619
5671
  this.success(JSON.stringify({
5620
5672
  path: usesDatabaseState ? "database" : stateFilePath,
5621
- ...state
5673
+ ...state,
5674
+ migrations: state.migrations.map(({ operations: _operations, ...migration }) => ({
5675
+ ...migration,
5676
+ hasRecordedPlan: Array.isArray(_operations)
5677
+ }))
5622
5678
  }, null, 2));
5623
5679
  return;
5624
5680
  }
@@ -1,7 +1,7 @@
1
- import { Kysely, Transaction } from "kysely";
2
- import { PrismaClient } from "@prisma/client";
3
1
  import { Collection } from "@h3ravel/collect.js";
2
+ import { Kysely, Transaction } from "kysely";
4
3
  import { Application, Command, Musket } from "@h3ravel/musket";
4
+ import { PrismaClient } from "@prisma/client";
5
5
  //#region src/types/migrations.d.ts
6
6
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'decimal' | 'boolean' | 'json' | 'date' | 'dateTime' | 'timestamp';
7
7
  interface PrimaryKeyGeneration {
@@ -122,6 +122,16 @@ interface AppliedMigrationEntry {
122
122
  className: string;
123
123
  appliedAt: string;
124
124
  checksum?: string;
125
+ /**
126
+ * The schema plan this migration actually executed when it was applied.
127
+ *
128
+ * Recorded so derived metadata (persisted column mappings, enums) can be
129
+ * rebuilt from what ran rather than from the migration file's current
130
+ * contents, which may have been edited since. Absent on entries written
131
+ * before this was recorded, and on migrations applied through a backend that
132
+ * does not produce a plan; consumers fall back to replaying the file.
133
+ */
134
+ operations?: SchemaOperation[];
125
135
  }
126
136
  interface AppliedMigrationRun {
127
137
  id: string;
@@ -678,6 +688,8 @@ declare abstract class Relation<TModel> {
678
688
  * @returns
679
689
  */
680
690
  where(where: ModelWhereInput<TModel>): this;
691
+ where(callback: (query: QueryBuilder<TModel>) => unknown): this;
692
+ where<TKey extends keyof ModelAttributes<TModel> & string>(column: TKey, value: DatabaseValue): this;
681
693
  /**
682
694
  * Adds an OR where clause to the query.
683
695
  *
@@ -685,6 +697,8 @@ declare abstract class Relation<TModel> {
685
697
  * @returns
686
698
  */
687
699
  orWhere(where: ModelWhereInput<TModel>): this;
700
+ orWhere(callback: (query: QueryBuilder<TModel>) => unknown): this;
701
+ orWhere<TKey extends keyof ModelAttributes<TModel> & string>(column: TKey, value: DatabaseValue): this;
688
702
  /**
689
703
  * Adds a NOT where clause to the query.
690
704
  *
@@ -699,6 +713,36 @@ declare abstract class Relation<TModel> {
699
713
  * @returns
700
714
  */
701
715
  orWhereNot(where: ModelWhereInput<TModel>): this;
716
+ /**
717
+ * Apply a callback when the supplied value is truthy.
718
+ *
719
+ * Keeping this on the relation avoids forcing callers to await `getQuery()`
720
+ * merely to compose optional constraints.
721
+ *
722
+ * @param value
723
+ * @param callback
724
+ * @param defaultCallback
725
+ * @returns
726
+ */
727
+ when<TValue>(value: TValue | (() => TValue), callback: (relation: this, value: TValue) => unknown, defaultCallback?: (relation: this, value: TValue) => unknown): this;
728
+ /**
729
+ * Apply a callback when the supplied value is falsy.
730
+ *
731
+ * @param value
732
+ * @param callback
733
+ * @param defaultCallback
734
+ * @returns
735
+ */
736
+ unless<TValue>(value: TValue | (() => TValue), callback: (relation: this, value: TValue) => unknown, defaultCallback?: (relation: this, value: TValue) => unknown): this;
737
+ /**
738
+ * Pass the relation through a callback and preserve the chain.
739
+ *
740
+ * @param callback
741
+ * @returns
742
+ */
743
+ tap(callback: (relation: this) => unknown): this;
744
+ /** Pass the relation into a callback and return its result. */
745
+ pipe<TResult>(callback: (relation: this) => TResult): TResult;
702
746
  /**
703
747
  * Adds a null check for a key.
704
748
  *
@@ -713,6 +757,20 @@ declare abstract class Relation<TModel> {
713
757
  * @returns
714
758
  */
715
759
  whereNotNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
760
+ /**
761
+ * Adds an OR null check for a key.
762
+ *
763
+ * @param key
764
+ * @returns
765
+ */
766
+ orWhereNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
767
+ /**
768
+ * Adds an OR not-null check for a key.
769
+ *
770
+ * @param key
771
+ * @returns
772
+ */
773
+ orWhereNotNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
716
774
  /**
717
775
  * Adds a between range clause for a key.
718
776
  *
@@ -1129,6 +1187,116 @@ declare abstract class Relation<TModel> {
1129
1187
  * @returns
1130
1188
  */
1131
1189
  with(relations: string | string[] | EagerLoadRelations<TModel>): this;
1190
+ /**
1191
+ * Add a relationship count/existence constraint to the related query.
1192
+ *
1193
+ * @param relation
1194
+ * @param operator
1195
+ * @param count
1196
+ * @param callback
1197
+ * @returns
1198
+ */
1199
+ has(relation: string, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1200
+ /**
1201
+ * Add an OR relationship count/existence constraint to the related query.
1202
+ *
1203
+ * @param relation
1204
+ * @param operator
1205
+ * @param count
1206
+ * @returns
1207
+ */
1208
+ orHas(relation: string, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1209
+ /**
1210
+ * Require the related query's model to have a nested relationship.
1211
+ *
1212
+ * @param relation
1213
+ * @param callback
1214
+ * @param operator
1215
+ * @param count
1216
+ * @returns
1217
+ */
1218
+ whereHas(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1219
+ /**
1220
+ * Add an OR nested relationship constraint to the related query.
1221
+ *
1222
+ * @param relation
1223
+ * @param callback
1224
+ * @param operator
1225
+ * @param count
1226
+ * @returns
1227
+ */
1228
+ orWhereHas(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1229
+ /**
1230
+ * Require the related query's model not to have a nested relationship.
1231
+ *
1232
+ * @param relation
1233
+ * @param callback
1234
+ * @returns
1235
+ */
1236
+ doesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1237
+ /**
1238
+ * Add an OR nested relationship absence constraint.
1239
+ *
1240
+ * @param relation
1241
+ * @returns
1242
+ */
1243
+ orDoesntHave(relation: string): this;
1244
+ /**
1245
+ * Require a constrained nested relationship to be absent.
1246
+ *
1247
+ * @param relation
1248
+ * @param callback
1249
+ * @returns
1250
+ */
1251
+ whereDoesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1252
+ /**
1253
+ * Add an OR constrained nested relationship absence clause.
1254
+ *
1255
+ * @param relation
1256
+ * @param callback
1257
+ * @returns
1258
+ */
1259
+ orWhereDoesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1260
+ /**
1261
+ * Add a constrained polymorphic nested relationship clause.
1262
+ *
1263
+ * @param relation
1264
+ * @param types
1265
+ * @param callback
1266
+ * @param operator
1267
+ * @param count
1268
+ * @returns
1269
+ */
1270
+ whereHasMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1271
+ /**
1272
+ * Add an OR constrained polymorphic nested relationship clause.
1273
+ *
1274
+ * @param relation
1275
+ * @param types
1276
+ * @param callback
1277
+ * @param operator
1278
+ * @param count
1279
+ * @returns
1280
+ */
1281
+ orWhereHasMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1282
+ /**
1283
+ * Require a constrained polymorphic nested relationship to be absent.
1284
+ *
1285
+ * @param relation
1286
+ * @param types
1287
+ * @param callback
1288
+ * @returns
1289
+ */
1290
+ whereDoesntHaveMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown): this;
1291
+ /**
1292
+ * Add an OR polymorphic nested relationship absence clause.
1293
+ *
1294
+ * @param relation
1295
+ * @param types
1296
+ * @param callback
1297
+ * @returns
1298
+ */
1299
+ orWhereDoesntHaveMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown): this;
1132
1300
  /**
1133
1301
  * Add relationship count aggregates to the related-model query.
1134
1302
  *
@@ -8336,6 +8504,20 @@ declare const readAppliedMigrationsStateFromStore: (adapter: DatabaseAdapter | u
8336
8504
  declare const writeAppliedMigrationsState: (stateFilePath: string, state: AppliedMigrationsState) => void;
8337
8505
  declare const writeAppliedMigrationsStateToStore: (adapter: DatabaseAdapter | undefined, stateFilePath: string, state: AppliedMigrationsState) => Promise<void>;
8338
8506
  declare const deleteAppliedMigrationsStateFromStore: (adapter: DatabaseAdapter | undefined, stateFilePath: string) => Promise<"database" | "file" | "missing-file">;
8507
+ /**
8508
+ * Whether `identity` counts as applied in `state`.
8509
+ *
8510
+ * Passing a `checksum` makes an edited migration file count as *not* applied so
8511
+ * it is re-run. That only suits the Prisma/file-backed flow, where re-applying a
8512
+ * migration just rewrites the generated schema. Adapter-backed runtimes must
8513
+ * omit the checksum and let the state store alone decide, since replaying an
8514
+ * already-applied `up()` would run its SQL a second time.
8515
+ *
8516
+ * @param state
8517
+ * @param identity
8518
+ * @param checksum
8519
+ * @returns
8520
+ */
8339
8521
  declare const isMigrationApplied: (state: AppliedMigrationsState, identity: string, checksum?: string) => boolean;
8340
8522
  declare const findAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationEntry | undefined;
8341
8523
  declare const markMigrationApplied: (state: AppliedMigrationsState, entry: AppliedMigrationEntry) => AppliedMigrationsState;
@@ -1,7 +1,7 @@
1
- import { Collection } from "@h3ravel/collect.js";
2
1
  import { Kysely, Transaction } from "kysely";
3
- import { Application, Command, Musket } from "@h3ravel/musket";
4
2
  import { PrismaClient } from "@prisma/client";
3
+ import { Collection } from "@h3ravel/collect.js";
4
+ import { Application, Command, Musket } from "@h3ravel/musket";
5
5
  //#region src/types/migrations.d.ts
6
6
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'decimal' | 'boolean' | 'json' | 'date' | 'dateTime' | 'timestamp';
7
7
  interface PrimaryKeyGeneration {
@@ -122,6 +122,16 @@ interface AppliedMigrationEntry {
122
122
  className: string;
123
123
  appliedAt: string;
124
124
  checksum?: string;
125
+ /**
126
+ * The schema plan this migration actually executed when it was applied.
127
+ *
128
+ * Recorded so derived metadata (persisted column mappings, enums) can be
129
+ * rebuilt from what ran rather than from the migration file's current
130
+ * contents, which may have been edited since. Absent on entries written
131
+ * before this was recorded, and on migrations applied through a backend that
132
+ * does not produce a plan; consumers fall back to replaying the file.
133
+ */
134
+ operations?: SchemaOperation[];
125
135
  }
126
136
  interface AppliedMigrationRun {
127
137
  id: string;
@@ -678,6 +688,8 @@ declare abstract class Relation<TModel> {
678
688
  * @returns
679
689
  */
680
690
  where(where: ModelWhereInput<TModel>): this;
691
+ where(callback: (query: QueryBuilder<TModel>) => unknown): this;
692
+ where<TKey extends keyof ModelAttributes<TModel> & string>(column: TKey, value: DatabaseValue): this;
681
693
  /**
682
694
  * Adds an OR where clause to the query.
683
695
  *
@@ -685,6 +697,8 @@ declare abstract class Relation<TModel> {
685
697
  * @returns
686
698
  */
687
699
  orWhere(where: ModelWhereInput<TModel>): this;
700
+ orWhere(callback: (query: QueryBuilder<TModel>) => unknown): this;
701
+ orWhere<TKey extends keyof ModelAttributes<TModel> & string>(column: TKey, value: DatabaseValue): this;
688
702
  /**
689
703
  * Adds a NOT where clause to the query.
690
704
  *
@@ -699,6 +713,36 @@ declare abstract class Relation<TModel> {
699
713
  * @returns
700
714
  */
701
715
  orWhereNot(where: ModelWhereInput<TModel>): this;
716
+ /**
717
+ * Apply a callback when the supplied value is truthy.
718
+ *
719
+ * Keeping this on the relation avoids forcing callers to await `getQuery()`
720
+ * merely to compose optional constraints.
721
+ *
722
+ * @param value
723
+ * @param callback
724
+ * @param defaultCallback
725
+ * @returns
726
+ */
727
+ when<TValue>(value: TValue | (() => TValue), callback: (relation: this, value: TValue) => unknown, defaultCallback?: (relation: this, value: TValue) => unknown): this;
728
+ /**
729
+ * Apply a callback when the supplied value is falsy.
730
+ *
731
+ * @param value
732
+ * @param callback
733
+ * @param defaultCallback
734
+ * @returns
735
+ */
736
+ unless<TValue>(value: TValue | (() => TValue), callback: (relation: this, value: TValue) => unknown, defaultCallback?: (relation: this, value: TValue) => unknown): this;
737
+ /**
738
+ * Pass the relation through a callback and preserve the chain.
739
+ *
740
+ * @param callback
741
+ * @returns
742
+ */
743
+ tap(callback: (relation: this) => unknown): this;
744
+ /** Pass the relation into a callback and return its result. */
745
+ pipe<TResult>(callback: (relation: this) => TResult): TResult;
702
746
  /**
703
747
  * Adds a null check for a key.
704
748
  *
@@ -713,6 +757,20 @@ declare abstract class Relation<TModel> {
713
757
  * @returns
714
758
  */
715
759
  whereNotNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
760
+ /**
761
+ * Adds an OR null check for a key.
762
+ *
763
+ * @param key
764
+ * @returns
765
+ */
766
+ orWhereNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
767
+ /**
768
+ * Adds an OR not-null check for a key.
769
+ *
770
+ * @param key
771
+ * @returns
772
+ */
773
+ orWhereNotNull<TKey extends keyof ModelAttributes<TModel> & string>(key: TKey): this;
716
774
  /**
717
775
  * Adds a between range clause for a key.
718
776
  *
@@ -1129,6 +1187,116 @@ declare abstract class Relation<TModel> {
1129
1187
  * @returns
1130
1188
  */
1131
1189
  with(relations: string | string[] | EagerLoadRelations<TModel>): this;
1190
+ /**
1191
+ * Add a relationship count/existence constraint to the related query.
1192
+ *
1193
+ * @param relation
1194
+ * @param operator
1195
+ * @param count
1196
+ * @param callback
1197
+ * @returns
1198
+ */
1199
+ has(relation: string, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1200
+ /**
1201
+ * Add an OR relationship count/existence constraint to the related query.
1202
+ *
1203
+ * @param relation
1204
+ * @param operator
1205
+ * @param count
1206
+ * @returns
1207
+ */
1208
+ orHas(relation: string, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1209
+ /**
1210
+ * Require the related query's model to have a nested relationship.
1211
+ *
1212
+ * @param relation
1213
+ * @param callback
1214
+ * @param operator
1215
+ * @param count
1216
+ * @returns
1217
+ */
1218
+ whereHas(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1219
+ /**
1220
+ * Add an OR nested relationship constraint to the related query.
1221
+ *
1222
+ * @param relation
1223
+ * @param callback
1224
+ * @param operator
1225
+ * @param count
1226
+ * @returns
1227
+ */
1228
+ orWhereHas(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1229
+ /**
1230
+ * Require the related query's model not to have a nested relationship.
1231
+ *
1232
+ * @param relation
1233
+ * @param callback
1234
+ * @returns
1235
+ */
1236
+ doesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1237
+ /**
1238
+ * Add an OR nested relationship absence constraint.
1239
+ *
1240
+ * @param relation
1241
+ * @returns
1242
+ */
1243
+ orDoesntHave(relation: string): this;
1244
+ /**
1245
+ * Require a constrained nested relationship to be absent.
1246
+ *
1247
+ * @param relation
1248
+ * @param callback
1249
+ * @returns
1250
+ */
1251
+ whereDoesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1252
+ /**
1253
+ * Add an OR constrained nested relationship absence clause.
1254
+ *
1255
+ * @param relation
1256
+ * @param callback
1257
+ * @returns
1258
+ */
1259
+ orWhereDoesntHave(relation: string, callback?: (query: QueryBuilder<any, any>) => unknown): this;
1260
+ /**
1261
+ * Add a constrained polymorphic nested relationship clause.
1262
+ *
1263
+ * @param relation
1264
+ * @param types
1265
+ * @param callback
1266
+ * @param operator
1267
+ * @param count
1268
+ * @returns
1269
+ */
1270
+ whereHasMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1271
+ /**
1272
+ * Add an OR constrained polymorphic nested relationship clause.
1273
+ *
1274
+ * @param relation
1275
+ * @param types
1276
+ * @param callback
1277
+ * @param operator
1278
+ * @param count
1279
+ * @returns
1280
+ */
1281
+ orWhereHasMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown, operator?: '>=' | '>' | '=' | '!=' | '<=' | '<', count?: number): this;
1282
+ /**
1283
+ * Require a constrained polymorphic nested relationship to be absent.
1284
+ *
1285
+ * @param relation
1286
+ * @param types
1287
+ * @param callback
1288
+ * @returns
1289
+ */
1290
+ whereDoesntHaveMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown): this;
1291
+ /**
1292
+ * Add an OR polymorphic nested relationship absence clause.
1293
+ *
1294
+ * @param relation
1295
+ * @param types
1296
+ * @param callback
1297
+ * @returns
1298
+ */
1299
+ orWhereDoesntHaveMorph<TRelated = any>(relation: string, types: string | RelationshipModelStatic | Array<string | RelationshipModelStatic>, callback?: (query: QueryBuilder<TRelated, any>, type: string) => unknown): this;
1132
1300
  /**
1133
1301
  * Add relationship count aggregates to the related-model query.
1134
1302
  *
@@ -8336,6 +8504,20 @@ declare const readAppliedMigrationsStateFromStore: (adapter: DatabaseAdapter | u
8336
8504
  declare const writeAppliedMigrationsState: (stateFilePath: string, state: AppliedMigrationsState) => void;
8337
8505
  declare const writeAppliedMigrationsStateToStore: (adapter: DatabaseAdapter | undefined, stateFilePath: string, state: AppliedMigrationsState) => Promise<void>;
8338
8506
  declare const deleteAppliedMigrationsStateFromStore: (adapter: DatabaseAdapter | undefined, stateFilePath: string) => Promise<"database" | "file" | "missing-file">;
8507
+ /**
8508
+ * Whether `identity` counts as applied in `state`.
8509
+ *
8510
+ * Passing a `checksum` makes an edited migration file count as *not* applied so
8511
+ * it is re-run. That only suits the Prisma/file-backed flow, where re-applying a
8512
+ * migration just rewrites the generated schema. Adapter-backed runtimes must
8513
+ * omit the checksum and let the state store alone decide, since replaying an
8514
+ * already-applied `up()` would run its SQL a second time.
8515
+ *
8516
+ * @param state
8517
+ * @param identity
8518
+ * @param checksum
8519
+ * @returns
8520
+ */
8339
8521
  declare const isMigrationApplied: (state: AppliedMigrationsState, identity: string, checksum?: string) => boolean;
8340
8522
  declare const findAppliedMigration: (state: AppliedMigrationsState, identity: string) => AppliedMigrationEntry | undefined;
8341
8523
  declare const markMigrationApplied: (state: AppliedMigrationsState, entry: AppliedMigrationEntry) => AppliedMigrationsState;