22 createFunctionHandle ,
33 type DocumentByName ,
44 type FunctionReference ,
5+ type GenericActionCtx ,
56 type GenericDataModel ,
67 type GenericMutationCtx ,
78 type GenericQueryCtx ,
@@ -152,7 +153,7 @@ export class Migrations<DataModel extends GenericDataModel> {
152153 }
153154
154155 private async _runInteractive (
155- ctx : RunMutationCtx ,
156+ ctx : MutationCtx | ActionCtx ,
156157 args : MigrationArgs ,
157158 fnRef ?: MigrationFunctionReference ,
158159 next ?: { name : string ; fnHandle : string } [ ] ,
@@ -461,7 +462,7 @@ export class Migrations<DataModel extends GenericDataModel> {
461462 * It's helpful to see what it would do without committing the transaction.
462463 */
463464 async runOne (
464- ctx : RunMutationCtx ,
465+ ctx : MutationCtx | ActionCtx ,
465466 fnRef : MigrationFunctionReference ,
466467 opts ?: {
467468 cursor ?: string | null ;
@@ -513,7 +514,10 @@ export class Migrations<DataModel extends GenericDataModel> {
513514 * @param ctx Context from a mutation or action. Needs `runMutation`.
514515 * @param fnRefs The migrations to run in order. Like [internal.migrations.foo].
515516 */
516- async runSerially ( ctx : RunMutationCtx , fnRefs : MigrationFunctionReference [ ] ) {
517+ async runSerially (
518+ ctx : MutationCtx | ActionCtx ,
519+ fnRefs : MigrationFunctionReference [ ] ,
520+ ) {
517521 if ( fnRefs . length === 0 ) return ;
518522 const [ fnRef , ...rest ] = fnRefs ;
519523 const next = await Promise . all (
@@ -538,7 +542,7 @@ export class Migrations<DataModel extends GenericDataModel> {
538542 * @returns The status of the migrations, in the order of the input.
539543 */
540544 async getStatus (
541- ctx : RunQueryCtx ,
545+ ctx : QueryCtx | MutationCtx | ActionCtx ,
542546 {
543547 migrations,
544548 limit,
@@ -567,7 +571,7 @@ export class Migrations<DataModel extends GenericDataModel> {
567571 * @returns The status of the migration after attempting to cancel it.
568572 */
569573 async cancel (
570- ctx : RunMutationCtx ,
574+ ctx : MutationCtx | ActionCtx ,
571575 migration : MigrationFunctionReference | string ,
572576 ) : Promise < MigrationStatus > {
573577 const name =
@@ -585,7 +589,7 @@ export class Migrations<DataModel extends GenericDataModel> {
585589 * @param ctx Context from a mutation or action. Needs `runMutation`.
586590 * @returns The status of up to 100 of the canceled migrations.
587591 */
588- async cancelAll ( ctx : RunMutationCtx ) {
592+ async cancelAll ( ctx : MutationCtx | ActionCtx ) {
589593 return ctx . runMutation ( this . component . lib . cancelAll , { } ) ;
590594 }
591595
@@ -604,14 +608,6 @@ export type MigrationFunctionReference = FunctionReference<
604608 MigrationArgs
605609> ;
606610
607- /* Type utils follow */
608-
609- type RunQueryCtx = {
610- runQuery : GenericQueryCtx < GenericDataModel > [ "runQuery" ] ;
611- } ;
612- type RunMutationCtx = {
613- runMutation : GenericMutationCtx < GenericDataModel > [ "runMutation" ] ;
614- } ;
615611
616612function logStatusAndInstructions (
617613 name : string ,
@@ -687,3 +683,15 @@ function logStatusAndInstructions(
687683 }
688684 return output ;
689685}
686+
687+ /* Type utils follow */
688+
689+ type QueryCtx = Pick < GenericQueryCtx < GenericDataModel > , "runQuery" > ;
690+ type MutationCtx = Pick <
691+ GenericMutationCtx < GenericDataModel > ,
692+ "runQuery" | "runMutation"
693+ > ;
694+ type ActionCtx = Pick <
695+ GenericActionCtx < GenericDataModel > ,
696+ "runQuery" | "runMutation" | "runAction"
697+ > ;
0 commit comments