Skip to content

Commit

Permalink
feat: add cascading deletion info (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman authored Dec 29, 2021
1 parent efa131e commit 3727191
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
EntityMutationTrigger,
EntityQueryContext,
EntityNonTransactionalMutationTrigger,
EntityMutationInfo,
EntityTriggerMutationInfo,
} from '@expo/entity';
import { Knex } from 'knex';

Expand Down Expand Up @@ -111,7 +111,7 @@ class ThrowConditionallyTrigger extends EntityMutationTrigger<
_viewerContext: ViewerContext,
_queryContext: EntityQueryContext,
entity: PostgresTriggerTestEntity,
_mutationInfo: EntityMutationInfo<
_mutationInfo: EntityTriggerMutationInfo<
PostgresTriggerTestEntityFields,
string,
ViewerContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Entity,
EntityMutationTrigger,
EntityQueryContext,
EntityMutationInfo,
EntityValidatorMutationInfo,
} from '@expo/entity';
import { Knex } from 'knex';

Expand Down Expand Up @@ -113,7 +113,7 @@ class ThrowConditionallyTrigger extends EntityMutationTrigger<
_viewerContext: ViewerContext,
_queryContext: EntityQueryContext,
entity: PostgresValidatorTestEntity,
_mutationInfo: EntityMutationInfo<
_mutationInfo: EntityValidatorMutationInfo<
PostgresValidatorTestEntityFields,
string,
ViewerContext,
Expand Down
47 changes: 47 additions & 0 deletions packages/entity/src/EntityMutationInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Entity from './Entity';
import ViewerContext from './ViewerContext';

export enum EntityMutationType {
CREATE,
UPDATE,
DELETE,
}

export type EntityValidatorMutationInfo<
TFields,
TID extends NonNullable<TFields[TSelectedFields]>,
TViewerContext extends ViewerContext,
TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>,
TSelectedFields extends keyof TFields = keyof TFields
> =
| {
type: EntityMutationType.CREATE;
}
| {
type: EntityMutationType.UPDATE;
previousValue: TEntity;
};

export type EntityMutationTriggerDeleteCascadeInfo<> = {
entity: Entity<any, any, any, any>;
cascadingDeleteCause: EntityMutationTriggerDeleteCascadeInfo | null;
};

export type EntityTriggerMutationInfo<
TFields,
TID extends NonNullable<TFields[TSelectedFields]>,
TViewerContext extends ViewerContext,
TEntity extends Entity<TFields, TID, TViewerContext, TSelectedFields>,
TSelectedFields extends keyof TFields = keyof TFields
> =
| {
type: EntityMutationType.CREATE;
}
| {
type: EntityMutationType.UPDATE;
previousValue: TEntity;
}
| {
type: EntityMutationType.DELETE;
cascadingDeleteCause: EntityMutationTriggerDeleteCascadeInfo | null;
};
6 changes: 3 additions & 3 deletions packages/entity/src/EntityMutationTriggerConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityMutationInfo } from './EntityMutator';
import { EntityTriggerMutationInfo } from './EntityMutationInfo';
import { EntityTransactionalQueryContext } from './EntityQueryContext';
import ReadonlyEntity from './ReadonlyEntity';
import ViewerContext from './ViewerContext';
Expand Down Expand Up @@ -80,7 +80,7 @@ export abstract class EntityMutationTrigger<
viewerContext: TViewerContext,
queryContext: EntityTransactionalQueryContext,
entity: TEntity,
mutationInfo: EntityMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>
): Promise<void>;
}

Expand All @@ -98,6 +98,6 @@ export abstract class EntityNonTransactionalMutationTrigger<
abstract executeAsync(
viewerContext: TViewerContext,
entity: TEntity,
mutationInfo: EntityMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>
mutationInfo: EntityTriggerMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>
): Promise<void>;
}
10 changes: 8 additions & 2 deletions packages/entity/src/EntityMutationValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EntityMutationInfo } from './EntityMutator';
import { EntityValidatorMutationInfo } from './EntityMutationInfo';
import { EntityTransactionalQueryContext } from './EntityQueryContext';
import ReadonlyEntity from './ReadonlyEntity';
import ViewerContext from './ViewerContext';
Expand All @@ -18,6 +18,12 @@ export default abstract class EntityMutationValidator<
viewerContext: TViewerContext,
queryContext: EntityTransactionalQueryContext,
entity: TEntity,
mutationInfo: EntityMutationInfo<TFields, TID, TViewerContext, TEntity, TSelectedFields>
mutationInfo: EntityValidatorMutationInfo<
TFields,
TID,
TViewerContext,
TEntity,
TSelectedFields
>
): Promise<void>;
}
Loading

0 comments on commit 3727191

Please sign in to comment.