mirror of
https://github.com/expo/entity.git
synced 2026-11-13 20:28:06 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47d0eac78e |
No files matched your search
@@ -31,6 +31,27 @@ export default class NoteEntity extends Entity<NoteFields, string, ExampleViewer
|
||||
}
|
||||
}
|
||||
|
||||
const noteEntityConfiguration = new EntityConfiguration<NoteFields>({
|
||||
idField: 'id',
|
||||
tableName: 'notes',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
}),
|
||||
userID: new UUIDField({
|
||||
columnName: 'user_id',
|
||||
}),
|
||||
title: new StringField({
|
||||
columnName: 'title',
|
||||
}),
|
||||
body: new StringField({
|
||||
columnName: 'body',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
});
|
||||
|
||||
/**
|
||||
* The companion provides configuration instructions to the Entity framework for this type
|
||||
* of entity. In some languages, this would be representable as "abstract" static members
|
||||
@@ -38,25 +59,6 @@ export default class NoteEntity extends Entity<NoteFields, string, ExampleViewer
|
||||
*/
|
||||
export const noteEntityCompanion = new EntityCompanionDefinition({
|
||||
entityClass: NoteEntity,
|
||||
entityConfiguration: new EntityConfiguration<NoteFields>({
|
||||
idField: 'id',
|
||||
tableName: 'notes',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
}),
|
||||
userID: new UUIDField({
|
||||
columnName: 'user_id',
|
||||
}),
|
||||
title: new StringField({
|
||||
columnName: 'title',
|
||||
}),
|
||||
body: new StringField({
|
||||
columnName: 'body',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
}),
|
||||
entityConfiguration: noteEntityConfiguration,
|
||||
privacyPolicyClass: NotePrivacyPolicy,
|
||||
});
|
||||
+4
-4
@@ -74,7 +74,7 @@ const makeEntityClasses = async (knex: Knex, edgeDeletionBehavior: EntityEdgeDel
|
||||
const categoryEntityConfiguration = new EntityConfiguration<CategoryFields>({
|
||||
idField: 'id',
|
||||
tableName: categoriesTableName,
|
||||
getInboundEdges: () => [OtherEntity],
|
||||
getInboundEdges: async () => [OtherEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
@@ -84,7 +84,7 @@ const makeEntityClasses = async (knex: Knex, edgeDeletionBehavior: EntityEdgeDel
|
||||
columnName: 'parent_other_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => OtherEntity,
|
||||
getAssociatedEntityClass: async () => OtherEntity,
|
||||
edgeDeletionBehavior,
|
||||
},
|
||||
}),
|
||||
@@ -102,7 +102,7 @@ const makeEntityClasses = async (knex: Knex, edgeDeletionBehavior: EntityEdgeDel
|
||||
const otherEntityConfiguration = new EntityConfiguration<OtherFields>({
|
||||
idField: 'id',
|
||||
tableName: othersTableName,
|
||||
getInboundEdges: () => [CategoryEntity],
|
||||
getInboundEdges: async () => [CategoryEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
@@ -112,7 +112,7 @@ const makeEntityClasses = async (knex: Knex, edgeDeletionBehavior: EntityEdgeDel
|
||||
columnName: 'parent_category_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => CategoryEntity,
|
||||
getAssociatedEntityClass: async () => CategoryEntity,
|
||||
edgeDeletionBehavior,
|
||||
},
|
||||
}),
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ const childEntityConfiguration = new EntityConfiguration<ChildFields>({
|
||||
columnName: 'parent_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => ParentEntity,
|
||||
getAssociatedEntityClass: async () => ParentEntity,
|
||||
edgeDeletionBehavior: EntityEdgeDeletionBehavior.CASCADE_DELETE_INVALIDATE_CACHE_ONLY,
|
||||
},
|
||||
}),
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ export default class ParentEntity extends Entity<ParentFields, string, ViewerCon
|
||||
const parentEntityConfiguration = new EntityConfiguration<ParentFields>({
|
||||
idField: 'id',
|
||||
tableName: 'parents',
|
||||
getInboundEdges: () => [ChildEntity],
|
||||
getInboundEdges: async () => [ChildEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
|
||||
@@ -13,7 +13,7 @@ export default class EntityConfiguration<TFields> {
|
||||
readonly cacheableKeys: ReadonlySet<keyof TFields>;
|
||||
readonly cacheKeyVersion: number;
|
||||
|
||||
readonly getInboundEdges: () => IEntityClass<any, any, any, any, any, any>[];
|
||||
readonly getInboundEdges: () => Promise<IEntityClass<any, any, any, any, any, any>[]>;
|
||||
readonly schema: ReadonlyMap<keyof TFields, EntityFieldDefinition<any>>;
|
||||
readonly entityToDBFieldsKeyMapping: ReadonlyMap<keyof TFields, string>;
|
||||
readonly dbToEntityFieldsKeyMapping: ReadonlyMap<string, keyof TFields>;
|
||||
@@ -25,7 +25,7 @@ export default class EntityConfiguration<TFields> {
|
||||
idField,
|
||||
tableName,
|
||||
schema,
|
||||
getInboundEdges = () => [],
|
||||
getInboundEdges = async () => [],
|
||||
cacheKeyVersion = 0,
|
||||
databaseAdapterFlavor,
|
||||
cacheAdapterFlavor,
|
||||
@@ -48,7 +48,7 @@ export default class EntityConfiguration<TFields> {
|
||||
/**
|
||||
* List of other entity types that reference this type in EntityFieldDefinition associations.
|
||||
*/
|
||||
getInboundEdges?: () => IEntityClass<any, any, any, any, any, any>[];
|
||||
getInboundEdges?: () => Promise<IEntityClass<any, any, any, any, any, any>[]>;
|
||||
|
||||
/**
|
||||
* Cache key version for this entity type. Should be bumped when a field is added to, removed from, or changed
|
||||
|
||||
@@ -61,13 +61,15 @@ export interface EntityAssociationDefinition<
|
||||
/**
|
||||
* Class of entity on the other end of this edge.
|
||||
*/
|
||||
getAssociatedEntityClass: () => IEntityClass<
|
||||
TAssociatedFields,
|
||||
TAssociatedID,
|
||||
TViewerContext,
|
||||
TAssociatedEntity,
|
||||
TAssociatedPrivacyPolicy,
|
||||
TAssociatedSelectedFields
|
||||
getAssociatedEntityClass: () => Promise<
|
||||
IEntityClass<
|
||||
TAssociatedFields,
|
||||
TAssociatedID,
|
||||
TViewerContext,
|
||||
TAssociatedEntity,
|
||||
TAssociatedPrivacyPolicy,
|
||||
TAssociatedSelectedFields
|
||||
>
|
||||
>;
|
||||
|
||||
/**
|
||||
|
||||
@@ -734,7 +734,7 @@ export class DeleteMutator<
|
||||
TSelectedFields
|
||||
>;
|
||||
const entityConfiguration = companionDefinition.entityConfiguration;
|
||||
const inboundEdges = entityConfiguration.getInboundEdges();
|
||||
const inboundEdges = await entityConfiguration.getInboundEdges();
|
||||
await Promise.all(
|
||||
inboundEdges.map(async (entityClass) => {
|
||||
return await mapMapAsync(
|
||||
@@ -745,9 +745,9 @@ export class DeleteMutator<
|
||||
return;
|
||||
}
|
||||
|
||||
const associatedConfiguration = association
|
||||
.getAssociatedEntityClass()
|
||||
.getCompanionDefinition().entityConfiguration;
|
||||
const associatedConfiguration = (
|
||||
await association.getAssociatedEntityClass()
|
||||
).getCompanionDefinition().entityConfiguration;
|
||||
if (associatedConfiguration !== entityConfiguration) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,23 +84,25 @@ class BlahEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
||||
];
|
||||
}
|
||||
|
||||
const blahConfiguration = new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
cache: true,
|
||||
}),
|
||||
ownerID: new UUIDField({
|
||||
columnName: 'owner_id',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
});
|
||||
|
||||
const blahCompanion = new EntityCompanionDefinition({
|
||||
entityClass: BlahEntity,
|
||||
entityConfiguration: new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
cache: true,
|
||||
}),
|
||||
ownerID: new UUIDField({
|
||||
columnName: 'owner_id',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
}),
|
||||
entityConfiguration: blahConfiguration,
|
||||
privacyPolicyClass: BlahEntityPrivacyPolicy,
|
||||
});
|
||||
|
||||
|
||||
@@ -360,7 +360,7 @@ const makeEntityClasses = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) =>
|
||||
const parentEntityConfiguration = new EntityConfiguration<ParentFields>({
|
||||
idField: 'id',
|
||||
tableName: 'parents',
|
||||
getInboundEdges: () => [ChildEntity],
|
||||
getInboundEdges: async () => [ChildEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
@@ -374,7 +374,7 @@ const makeEntityClasses = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) =>
|
||||
const childEntityConfiguration = new EntityConfiguration<ChildFields>({
|
||||
idField: 'id',
|
||||
tableName: 'children',
|
||||
getInboundEdges: () => [GrandChildEntity],
|
||||
getInboundEdges: async () => [GrandChildEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
@@ -384,7 +384,7 @@ const makeEntityClasses = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) =>
|
||||
columnName: 'parent_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => ParentEntity,
|
||||
getAssociatedEntityClass: async () => ParentEntity,
|
||||
edgeDeletionBehavior,
|
||||
},
|
||||
}),
|
||||
@@ -405,7 +405,7 @@ const makeEntityClasses = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) =>
|
||||
columnName: 'parent_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => ChildEntity,
|
||||
getAssociatedEntityClass: async () => ChildEntity,
|
||||
edgeDeletionBehavior,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -45,20 +45,22 @@ class BlahEntity extends Entity<BlahFields, string, ViewerContext> {
|
||||
}
|
||||
}
|
||||
|
||||
const blahConfiguration = new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
cache: true,
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
});
|
||||
|
||||
const blahCompanion = new EntityCompanionDefinition({
|
||||
entityClass: BlahEntity,
|
||||
entityConfiguration: new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
cache: true,
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
}),
|
||||
entityConfiguration: blahConfiguration,
|
||||
privacyPolicyClass: BlahEntityPrivacyPolicy,
|
||||
mutationTriggers: () => ({
|
||||
afterCommit: [new TestNonTransactionalMutationTrigger()],
|
||||
|
||||
@@ -226,19 +226,21 @@ class EmptyPolicy extends EntityPrivacyPolicy<BlahFields, string, ViewerContext,
|
||||
protected override readonly deleteRules = [];
|
||||
}
|
||||
|
||||
const blahConfiguration = new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
});
|
||||
|
||||
const blahEntityCompanionDefinition = new EntityCompanionDefinition({
|
||||
entityClass: BlahEntity,
|
||||
entityConfiguration: new EntityConfiguration<BlahFields>({
|
||||
idField: 'id',
|
||||
tableName: 'blah_table',
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
}),
|
||||
},
|
||||
databaseAdapterFlavor: 'postgres',
|
||||
cacheAdapterFlavor: 'redis',
|
||||
}),
|
||||
entityConfiguration: blahConfiguration,
|
||||
privacyPolicyClass: AlwaysDenyPolicy,
|
||||
});
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ const makeEntityClass = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) => {
|
||||
const categoryEntityConfiguration = new EntityConfiguration<CategoryFields>({
|
||||
idField: 'id',
|
||||
tableName: 'categories',
|
||||
getInboundEdges: () => [CategoryEntity],
|
||||
getInboundEdges: async () => [CategoryEntity],
|
||||
schema: {
|
||||
id: new UUIDField({
|
||||
columnName: 'id',
|
||||
@@ -63,7 +63,7 @@ const makeEntityClass = (edgeDeletionBehavior: EntityEdgeDeletionBehavior) => {
|
||||
columnName: 'parent_category_id',
|
||||
cache: true,
|
||||
association: {
|
||||
getAssociatedEntityClass: () => CategoryEntity,
|
||||
getAssociatedEntityClass: async () => CategoryEntity,
|
||||
edgeDeletionBehavior,
|
||||
},
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user