mirror of
https://github.com/expo/entity.git
synced 2026-11-15 17:32:07 -10:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47d0eac78e | ||
|
|
2069a0d9fd | ||
|
|
83fe9cdea5 | ||
|
|
1934216b70 | ||
|
|
92f5529eba | ||
|
|
67732d6847 | ||
|
|
bb0cd51eb5 |
No files matched your search
+15
-1
@@ -3,6 +3,20 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
|
||||
# [0.31.1](https://github.com/expo/entity/compare/v0.31.0...v0.31.1) (2023-03-06)
|
||||
|
||||
### Features
|
||||
* add loadFirstByFieldEqualityConjunction, a convenience method ([#206](https://github.com/expo/entity/pull/206)) ([1934216](https://github.com/expo/entity/commit/1934216b70572cf2b9693e0f14939f49b90427dd))
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
@@ -128,7 +142,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
||||
|
||||
### Chores
|
||||
|
||||
* Refactor cachers to use an abstract class and interface ([#157](https://github.com/expo/entity/pull/157))
|
||||
* Refactor cachers to use an abstract class and interface ([#157](https://github.com/expo/entity/pull/157))
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@
|
||||
],
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"version": "0.30.0"
|
||||
"version": "0.31.1"
|
||||
}
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
"eslint": "^7.7.0",
|
||||
"eslint-config-universe": "^7.0.0",
|
||||
"eslint-plugin-tsdoc": "^0.2.16",
|
||||
"ioredis": "^5.0.4",
|
||||
"ioredis": "^5.2.5",
|
||||
"jest": "^26.6.3",
|
||||
"lerna": "^5.4.0",
|
||||
"lru-cache": "^6.0.0",
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-cache-adapter-local-memory",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Cross-request local memory cache adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -33,6 +33,6 @@
|
||||
"lru-cache": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0"
|
||||
"@expo/entity": "^0.31.1"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-cache-adapter-redis",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Redis cache adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -31,7 +31,7 @@
|
||||
"ioredis": ">=5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"ioredis": "^5.0.4"
|
||||
"@expo/entity": "^0.31.1",
|
||||
"ioredis": "^5.2.5"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-database-adapter-knex",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Knex database adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -30,10 +30,10 @@
|
||||
"@expo/entity": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"knex": "^2.3.0"
|
||||
"knex": "^2.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity": "^0.31.1",
|
||||
"pg": "^8.7.1"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import { EntityQueryContextProvider } from '@expo/entity';
|
||||
import {
|
||||
EntityQueryContextProvider,
|
||||
TransactionConfig,
|
||||
TransactionIsolationLevel,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
|
||||
/**
|
||||
@@ -13,10 +17,16 @@ export default class PostgresEntityQueryContextProvider extends EntityQueryConte
|
||||
return this.knexInstance;
|
||||
}
|
||||
|
||||
protected createTransactionRunner<T>(): (
|
||||
transactionScope: (trx: any) => Promise<T>
|
||||
) => Promise<T> {
|
||||
return (transactionScope) => this.knexInstance.transaction(transactionScope);
|
||||
protected createTransactionRunner<T>(
|
||||
transactionConfig?: TransactionConfig
|
||||
): (transactionScope: (trx: any) => Promise<T>) => Promise<T> {
|
||||
return (transactionScope) =>
|
||||
this.knexInstance.transaction(
|
||||
transactionScope,
|
||||
transactionConfig
|
||||
? PostgresEntityQueryContextProvider.convertTransactionConfig(transactionConfig)
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
|
||||
protected createNestedTransactionRunner<T>(
|
||||
@@ -24,4 +34,27 @@ export default class PostgresEntityQueryContextProvider extends EntityQueryConte
|
||||
): (transactionScope: (queryInterface: any) => Promise<T>) => Promise<T> {
|
||||
return (transactionScope) => (outerQueryInterface as Knex).transaction(transactionScope);
|
||||
}
|
||||
|
||||
private static convertTransactionConfig(
|
||||
transactionConfig: TransactionConfig
|
||||
): Knex.TransactionConfig {
|
||||
const convertIsolationLevel = (
|
||||
isolationLevel: TransactionIsolationLevel
|
||||
): Knex.IsolationLevels => {
|
||||
switch (isolationLevel) {
|
||||
case TransactionIsolationLevel.READ_COMMITTED:
|
||||
return 'read committed';
|
||||
case TransactionIsolationLevel.REPEATABLE_READ:
|
||||
return 'repeatable read';
|
||||
case TransactionIsolationLevel.SERIALIZABLE:
|
||||
return 'serializable';
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...(transactionConfig.isolationLevel
|
||||
? { isolationLevel: convertIsolationLevel(transactionConfig.isolationLevel) }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
+39
@@ -3,6 +3,7 @@ import {
|
||||
createUnitTestEntityCompanionProvider,
|
||||
enforceResultsAsync,
|
||||
ViewerContext,
|
||||
TransactionIsolationLevel,
|
||||
} from '@expo/entity';
|
||||
import { enforceAsyncResult } from '@expo/results';
|
||||
import { knex, Knex } from 'knex';
|
||||
@@ -111,6 +112,44 @@ describe('postgres entity integration', () => {
|
||||
expect(entities).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('passes transaction config into transactions', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
const firstEntity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creator(vc1).setField('name', 'hello').createAsync()
|
||||
);
|
||||
|
||||
const loadAndUpdateAsync = async (newName: string): Promise<{ error?: Error }> => {
|
||||
try {
|
||||
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
||||
'postgres',
|
||||
async (queryContext) => {
|
||||
const entity = await PostgresTestEntity.loader(vc1, queryContext)
|
||||
.enforcing()
|
||||
.loadByIDAsync(firstEntity.getID());
|
||||
await PostgresTestEntity.updater(entity, queryContext)
|
||||
.setField('name', newName)
|
||||
.enforceUpdateAsync();
|
||||
},
|
||||
{ isolationLevel: TransactionIsolationLevel.SERIALIZABLE }
|
||||
);
|
||||
return {};
|
||||
} catch (e) {
|
||||
return { error: e as Error };
|
||||
}
|
||||
};
|
||||
|
||||
// do some parallel updates to trigger serializable error in at least some of them
|
||||
const results = await Promise.all([
|
||||
loadAndUpdateAsync('hello2'),
|
||||
loadAndUpdateAsync('hello3'),
|
||||
loadAndUpdateAsync('hello4'),
|
||||
loadAndUpdateAsync('hello5'),
|
||||
]);
|
||||
|
||||
expect(results.filter((r) => (r.error as any)?.cause?.code === '40001').length > 0).toBe(true);
|
||||
});
|
||||
|
||||
describe('JSON fields', () => {
|
||||
it('supports both types of array fields', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-example
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@expo/entity-example",
|
||||
"private": true,
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "An example integration of the @expo/entity framework",
|
||||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
@@ -23,7 +23,7 @@
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity": "^0.31.1",
|
||||
"apollo-server-koa": "^2.16.1",
|
||||
"graphql": "^15.3.0",
|
||||
"koa": "^2.13.0",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { EntityQueryContextProvider } from '@expo/entity';
|
||||
import { EntityQueryContextProvider, TransactionConfig } from '@expo/entity';
|
||||
|
||||
export default class InMemoryQueryContextProvider extends EntityQueryContextProvider {
|
||||
protected getQueryInterface(): any {
|
||||
return {};
|
||||
}
|
||||
|
||||
protected createTransactionRunner<T>(): (
|
||||
transactionScope: (queryInterface: any) => Promise<T>
|
||||
) => Promise<T> {
|
||||
protected createTransactionRunner<T>(
|
||||
_transactionConfig?: TransactionConfig
|
||||
): (transactionScope: (queryInterface: any) => Promise<T>) => Promise<T> {
|
||||
return (transactionScope) => Promise.resolve(transactionScope({}));
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-full-integration-tests
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-full-integration-tests
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@expo/entity-full-integration-tests",
|
||||
"private": true,
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Full redis and knex integration tests for the entity framework",
|
||||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
@@ -27,8 +27,8 @@
|
||||
"@expo/entity-database-adapter-knex": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity-cache-adapter-redis": "^0.30.0",
|
||||
"@expo/entity-database-adapter-knex": "^0.30.0"
|
||||
"@expo/entity": "^0.31.1",
|
||||
"@expo/entity-cache-adapter-redis": "^0.31.1",
|
||||
"@expo/entity-database-adapter-knex": "^0.31.1"
|
||||
}
|
||||
}
|
||||
+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',
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-ip-address-field
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-ip-address-field
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-ip-address-field",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "IP address EntityField definitions for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -28,7 +28,7 @@
|
||||
"ip-address": "^8.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity": "^0.31.1",
|
||||
"@types/jsbn": "^1.2.29"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-secondary-cache-local-memory",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Local memory secondary cache for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -31,8 +31,8 @@
|
||||
"@expo/entity-cache-adapter-local-memory": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity-cache-adapter-local-memory": "^0.30.0",
|
||||
"@expo/entity": "^0.31.1",
|
||||
"@expo/entity-cache-adapter-local-memory": "^0.31.1",
|
||||
"nullthrows": "^1.1.1"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-secondary-cache-redis",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "Redis secondary cache for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -31,9 +31,9 @@
|
||||
"@expo/entity-cache-adapter-redis": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity": "^0.30.0",
|
||||
"@expo/entity-cache-adapter-redis": "^0.30.0",
|
||||
"ioredis": "^5.0.4",
|
||||
"@expo/entity": "^0.31.1",
|
||||
"@expo/entity-cache-adapter-redis": "^0.31.1",
|
||||
"ioredis": "^5.2.5",
|
||||
"nullthrows": "^1.1.1"
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,14 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.31.0](https://github.com/expo/entity/compare/v0.30.0...v0.31.0) (2023-01-19)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/expo/entity/compare/v0.29.0...v0.30.0) (2022-12-23)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity",
|
||||
"version": "0.30.0",
|
||||
"version": "0.31.1",
|
||||
"description": "A privacy-first data model",
|
||||
"files": [
|
||||
"build",
|
||||
|
||||
@@ -114,6 +114,22 @@ export default class EnforcingEntityLoader<
|
||||
return mapMap(entityResults, (result) => result.enforceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforcing version of entity loader method by the same name.
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
*/
|
||||
async loadFirstByFieldEqualityConjunctionAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
fieldEqualityOperands: FieldEqualityCondition<TFields, N>[],
|
||||
querySelectionModifiers: Omit<QuerySelectionModifiers<TFields>, 'limit'> &
|
||||
Required<Pick<QuerySelectionModifiers<TFields>, 'orderBy'>>
|
||||
): Promise<TEntity | null> {
|
||||
const entityResult = await this.entityLoader.loadFirstByFieldEqualityConjunctionAsync(
|
||||
fieldEqualityOperands,
|
||||
querySelectionModifiers
|
||||
);
|
||||
return entityResult ? entityResult.enforceValue() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforcing version of entity loader method by the same name.
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
|
||||
@@ -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
|
||||
>
|
||||
>;
|
||||
|
||||
/**
|
||||
|
||||
@@ -182,6 +182,32 @@ export default class EntityLoader<
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the first entity matching the selection constructed from the conjunction of specified
|
||||
* operands, or null if no matching entity exists. Entities loaded using this method are not
|
||||
* batched or cached.
|
||||
*
|
||||
* This is a convenience method for {@link loadManyByFieldEqualityConjunctionAsync}. However, the
|
||||
* `orderBy` option must be specified to define what "first" means. If ordering doesn't matter,
|
||||
* explicitly pass in an empty array.
|
||||
*
|
||||
* @param fieldEqualityOperands - list of field equality selection operand specifications
|
||||
* @param querySelectionModifiers - orderBy and optional offset for the query
|
||||
* @returns the first entity results that matches the query, where result error can be
|
||||
* UnauthorizedError
|
||||
*/
|
||||
async loadFirstByFieldEqualityConjunctionAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
fieldEqualityOperands: FieldEqualityCondition<TFields, N>[],
|
||||
querySelectionModifiers: Omit<QuerySelectionModifiers<TFields>, 'limit'> &
|
||||
Required<Pick<QuerySelectionModifiers<TFields>, 'orderBy'>>
|
||||
): Promise<Result<TEntity> | null> {
|
||||
const results = await this.loadManyByFieldEqualityConjunctionAsync(fieldEqualityOperands, {
|
||||
...querySelectionModifiers,
|
||||
limit: 1,
|
||||
});
|
||||
return results[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads many entities matching the selection constructed from the conjunction of specified operands.
|
||||
* Entities loaded using this method are not batched or cached.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,16 @@ export type PreCommitCallback = (
|
||||
...args: any
|
||||
) => Promise<any>;
|
||||
|
||||
export enum TransactionIsolationLevel {
|
||||
READ_COMMITTED = 'READ_COMMITTED',
|
||||
REPEATABLE_READ = 'REPEATABLE_READ',
|
||||
SERIALIZABLE = 'SERIALIZABLE',
|
||||
}
|
||||
|
||||
export type TransactionConfig = {
|
||||
isolationLevel?: TransactionIsolationLevel;
|
||||
};
|
||||
|
||||
/**
|
||||
* Entity framework representation of transactional and non-transactional database
|
||||
* query execution units.
|
||||
@@ -25,7 +35,8 @@ export abstract class EntityQueryContext {
|
||||
}
|
||||
|
||||
abstract runInTransactionIfNotInTransactionAsync<T>(
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>,
|
||||
transactionConfig?: TransactionConfig
|
||||
): Promise<T>;
|
||||
}
|
||||
|
||||
@@ -48,9 +59,13 @@ export class EntityNonTransactionalQueryContext extends EntityQueryContext {
|
||||
}
|
||||
|
||||
async runInTransactionIfNotInTransactionAsync<T>(
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>,
|
||||
transactionConfig?: TransactionConfig
|
||||
): Promise<T> {
|
||||
return await this.entityQueryContextProvider.runInTransactionAsync(transactionScope);
|
||||
return await this.entityQueryContextProvider.runInTransactionAsync(
|
||||
transactionScope,
|
||||
transactionConfig
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +147,13 @@ export class EntityTransactionalQueryContext extends EntityQueryContext {
|
||||
}
|
||||
|
||||
async runInTransactionIfNotInTransactionAsync<T>(
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>,
|
||||
transactionConfig?: TransactionConfig
|
||||
): Promise<T> {
|
||||
assert(
|
||||
transactionConfig === undefined,
|
||||
'Should not pass transactionConfig to a nested transaction'
|
||||
);
|
||||
return await transactionScope(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
EntityTransactionalQueryContext,
|
||||
EntityNonTransactionalQueryContext,
|
||||
EntityNestedTransactionalQueryContext,
|
||||
TransactionConfig,
|
||||
} from './EntityQueryContext';
|
||||
|
||||
/**
|
||||
@@ -23,9 +24,9 @@ export default abstract class EntityQueryContextProvider {
|
||||
/**
|
||||
* Vend a transaction runner for use in runInTransactionAsync.
|
||||
*/
|
||||
protected abstract createTransactionRunner<T>(): (
|
||||
transactionScope: (queryInterface: any) => Promise<T>
|
||||
) => Promise<T>;
|
||||
protected abstract createTransactionRunner<T>(
|
||||
transactionConfig?: TransactionConfig
|
||||
): (transactionScope: (queryInterface: any) => Promise<T>) => Promise<T>;
|
||||
|
||||
protected abstract createNestedTransactionRunner<T>(
|
||||
outerQueryInterface: any
|
||||
@@ -36,11 +37,12 @@ export default abstract class EntityQueryContextProvider {
|
||||
* @param transactionScope - async callback to execute within the transaction
|
||||
*/
|
||||
async runInTransactionAsync<T>(
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<T>,
|
||||
transactionConfig?: TransactionConfig
|
||||
): Promise<T> {
|
||||
const [returnedValue, queryContext] = await this.createTransactionRunner<
|
||||
[T, EntityTransactionalQueryContext]
|
||||
>()(async (queryInterface) => {
|
||||
>(transactionConfig)(async (queryInterface) => {
|
||||
const queryContext = new EntityTransactionalQueryContext(queryInterface, this);
|
||||
const result = await transactionScope(queryContext);
|
||||
await queryContext.runPreCommitCallbacksAsync();
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { IEntityClass } from './Entity';
|
||||
import EntityCompanionProvider, { DatabaseAdapterFlavor } from './EntityCompanionProvider';
|
||||
import EntityPrivacyPolicy from './EntityPrivacyPolicy';
|
||||
import { EntityQueryContext, EntityTransactionalQueryContext } from './EntityQueryContext';
|
||||
import {
|
||||
EntityQueryContext,
|
||||
EntityTransactionalQueryContext,
|
||||
TransactionConfig,
|
||||
} from './EntityQueryContext';
|
||||
import ReadonlyEntity from './ReadonlyEntity';
|
||||
import ViewerScopedEntityCompanion from './ViewerScopedEntityCompanion';
|
||||
import ViewerScopedEntityCompanionProvider from './ViewerScopedEntityCompanionProvider';
|
||||
@@ -82,11 +86,12 @@ export default class ViewerContext {
|
||||
*/
|
||||
async runInTransactionForDatabaseAdaptorFlavorAsync<TResult>(
|
||||
databaseAdaptorFlavor: DatabaseAdapterFlavor,
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<TResult>
|
||||
transactionScope: (queryContext: EntityTransactionalQueryContext) => Promise<TResult>,
|
||||
transactionConfig?: TransactionConfig
|
||||
): Promise<TResult> {
|
||||
return await this.entityCompanionProvider
|
||||
.getQueryContextProviderForDatabaseAdaptorFlavor(databaseAdaptorFlavor)
|
||||
.getQueryContext()
|
||||
.runInTransactionIfNotInTransactionAsync(transactionScope);
|
||||
.runInTransactionIfNotInTransactionAsync(transactionScope, transactionConfig);
|
||||
}
|
||||
}
|
||||
@@ -222,6 +222,46 @@ describe(EnforcingEntityLoader, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadFirstByFieldEqualityConjunction', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).thenResolve(result(rejection));
|
||||
const entityLoader = instance(entityLoaderMock);
|
||||
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
||||
await expect(
|
||||
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns value when result is successful', async () => {
|
||||
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
||||
const resolved = {};
|
||||
when(
|
||||
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).thenResolve(result(resolved));
|
||||
const entityLoader = instance(entityLoaderMock);
|
||||
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
||||
await expect(
|
||||
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).resolves.toEqual(resolved);
|
||||
});
|
||||
|
||||
it('returns null when the query is successful but no rows match', async () => {
|
||||
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
||||
when(
|
||||
entityLoaderMock.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).thenResolve(null);
|
||||
const entityLoader = instance(entityLoaderMock);
|
||||
const enforcingEntityLoader = new EnforcingEntityLoader(entityLoader);
|
||||
await expect(
|
||||
enforcingEntityLoader.loadFirstByFieldEqualityConjunctionAsync(anything(), anything())
|
||||
).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyByFieldEqualityConjunction', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const entityLoaderMock = mock<EntityLoader<any, any, any, any, any, any>>(EntityLoader);
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -2,6 +2,7 @@ import { enforceAsyncResult } from '@expo/results';
|
||||
import { mock, instance, verify, spy, deepEqual, anyOfClass, anything, when } from 'ts-mockito';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { OrderByOrdering } from '../EntityDatabaseAdapter';
|
||||
import EntityLoader from '../EntityLoader';
|
||||
import { EntityPrivacyPolicyEvaluationContext } from '../EntityPrivacyPolicy';
|
||||
import ViewerContext from '../ViewerContext';
|
||||
@@ -210,6 +211,101 @@ describe(EntityLoader, () => {
|
||||
).rejects.toThrowError('Entity field not valid: TestEntity (customIdField = not-a-uuid)');
|
||||
});
|
||||
|
||||
it('loads entities with loadFirstByFieldEqualityConjunction', async () => {
|
||||
const privacyPolicy = new TestEntityPrivacyPolicy();
|
||||
const spiedPrivacyPolicy = spy(privacyPolicy);
|
||||
const viewerContext = instance(mock(ViewerContext));
|
||||
const privacyPolicyEvaluationContext = instance(mock<EntityPrivacyPolicyEvaluationContext>());
|
||||
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
||||
const queryContext = StubQueryContextProvider.getQueryContext();
|
||||
|
||||
const id1 = uuidv4();
|
||||
const id2 = uuidv4();
|
||||
const id3 = uuidv4();
|
||||
const databaseAdapter = new StubDatabaseAdapter<TestFields>(
|
||||
testEntityConfiguration,
|
||||
StubDatabaseAdapter.convertFieldObjectsToDataStore(
|
||||
testEntityConfiguration,
|
||||
new Map([
|
||||
[
|
||||
testEntityConfiguration.tableName,
|
||||
[
|
||||
{
|
||||
customIdField: id1,
|
||||
stringField: 'huh',
|
||||
intField: 4,
|
||||
testIndexedField: '4',
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
},
|
||||
{
|
||||
customIdField: id2,
|
||||
stringField: 'huh',
|
||||
intField: 4,
|
||||
testIndexedField: '5',
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
},
|
||||
{
|
||||
customIdField: id3,
|
||||
stringField: 'huh2',
|
||||
intField: 4,
|
||||
testIndexedField: '6',
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
},
|
||||
],
|
||||
],
|
||||
])
|
||||
)
|
||||
);
|
||||
const cacheAdapterProvider = new NoCacheStubCacheAdapterProvider();
|
||||
const cacheAdapter = cacheAdapterProvider.getCacheAdapter(testEntityConfiguration);
|
||||
const entityCache = new ReadThroughEntityCache(testEntityConfiguration, cacheAdapter);
|
||||
const dataManager = new EntityDataManager(
|
||||
databaseAdapter,
|
||||
entityCache,
|
||||
StubQueryContextProvider,
|
||||
instance(mock<IEntityMetricsAdapter>()),
|
||||
TestEntity.name
|
||||
);
|
||||
const entityLoader = new EntityLoader(
|
||||
viewerContext,
|
||||
queryContext,
|
||||
privacyPolicyEvaluationContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
privacyPolicy,
|
||||
dataManager,
|
||||
metricsAdapter
|
||||
);
|
||||
const result = await entityLoader.loadFirstByFieldEqualityConjunctionAsync(
|
||||
[
|
||||
{
|
||||
fieldName: 'stringField',
|
||||
fieldValue: 'huh',
|
||||
},
|
||||
{
|
||||
fieldName: 'intField',
|
||||
fieldValue: 4,
|
||||
},
|
||||
],
|
||||
{ orderBy: [{ fieldName: 'testIndexedField', order: OrderByOrdering.DESCENDING }] }
|
||||
);
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.ok).toBe(true);
|
||||
expect(result!.enforceValue().getField('testIndexedField')).toEqual('5');
|
||||
verify(
|
||||
spiedPrivacyPolicy.authorizeReadAsync(
|
||||
viewerContext,
|
||||
queryContext,
|
||||
privacyPolicyEvaluationContext,
|
||||
anyOfClass(TestEntity),
|
||||
anything()
|
||||
)
|
||||
).once();
|
||||
});
|
||||
|
||||
it('authorizes loaded entities', async () => {
|
||||
const privacyPolicy = new TestEntityPrivacyPolicy();
|
||||
const spiedPrivacyPolicy = spy(privacyPolicy);
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import invariant from 'invariant';
|
||||
|
||||
import { EntityQueryContext } from '../EntityQueryContext';
|
||||
import { EntityQueryContext, TransactionIsolationLevel } from '../EntityQueryContext';
|
||||
import ViewerContext from '../ViewerContext';
|
||||
import { createUnitTestEntityCompanionProvider } from '../utils/testing/createUnitTestEntityCompanionProvider';
|
||||
|
||||
@@ -129,4 +129,26 @@ describe(EntityQueryContext, () => {
|
||||
expect(postCommitInvalidationCallback).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('transaction config', () => {
|
||||
it('passes it into the provider', async () => {
|
||||
const companionProvider = createUnitTestEntityCompanionProvider();
|
||||
const viewerContext = new ViewerContext(companionProvider);
|
||||
|
||||
const queryContextProvider =
|
||||
companionProvider.getQueryContextProviderForDatabaseAdaptorFlavor('postgres');
|
||||
const queryContextProviderSpy = jest.spyOn(queryContextProvider, 'runInTransactionAsync');
|
||||
|
||||
const transactionScopeFn = async (): Promise<any> => {};
|
||||
const transactionConfig = { isolationLevel: TransactionIsolationLevel.SERIALIZABLE };
|
||||
|
||||
await viewerContext.runInTransactionForDatabaseAdaptorFlavorAsync(
|
||||
'postgres',
|
||||
transactionScopeFn,
|
||||
transactionConfig
|
||||
);
|
||||
|
||||
expect(queryContextProviderSpy).toHaveBeenCalledWith(transactionScopeFn, transactionConfig);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -385,7 +385,8 @@ describe(EntityDataManager, () => {
|
||||
return await entityDataManager.loadManyByFieldEqualingAsync(queryContext, 'customIdField', [
|
||||
'1',
|
||||
]);
|
||||
}
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
expect(entityDatas.get('1')).toHaveLength(1);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { TransactionConfig } from '../../EntityQueryContext';
|
||||
import EntityQueryContextProvider from '../../EntityQueryContextProvider';
|
||||
|
||||
export class StubQueryContextProvider extends EntityQueryContextProvider {
|
||||
@@ -5,9 +6,9 @@ export class StubQueryContextProvider extends EntityQueryContextProvider {
|
||||
return {};
|
||||
}
|
||||
|
||||
protected createTransactionRunner<T>(): (
|
||||
transactionScope: (queryInterface: any) => Promise<T>
|
||||
) => Promise<T> {
|
||||
protected createTransactionRunner<T>(
|
||||
_transactionConfig?: TransactionConfig
|
||||
): (transactionScope: (queryInterface: any) => Promise<T>) => Promise<T> {
|
||||
return (transactionScope) => Promise.resolve(transactionScope({}));
|
||||
}
|
||||
|
||||
|
||||
@@ -373,31 +373,31 @@
|
||||
integrity sha512-reebgVwjf8VfZxSXU7e+UjpXGwcUTIMpWR9FY54Oh70ulhXrQiZei62B4D9bH3SVYMwnDGzifHJ8INRrJ+0L1g==
|
||||
|
||||
"@expo/entity-cache-adapter-local-memory@file:packages/entity-cache-adapter-local-memory":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
dependencies:
|
||||
lru-cache "^6.0.0"
|
||||
|
||||
"@expo/entity-cache-adapter-redis@file:packages/entity-cache-adapter-redis":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
|
||||
"@expo/entity-database-adapter-knex@file:packages/entity-database-adapter-knex":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
dependencies:
|
||||
knex "^2.3.0"
|
||||
knex "^2.4.1"
|
||||
|
||||
"@expo/entity-ip-address-field@file:packages/entity-ip-address-field":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
dependencies:
|
||||
ip-address "^8.1.0"
|
||||
|
||||
"@expo/entity-secondary-cache-local-memory@file:packages/entity-secondary-cache-local-memory":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
|
||||
"@expo/entity-secondary-cache-redis@file:packages/entity-secondary-cache-redis":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
|
||||
"@expo/entity@file:packages/entity":
|
||||
version "0.29.0"
|
||||
version "0.30.0"
|
||||
dependencies:
|
||||
"@expo/results" "^1.0.0"
|
||||
dataloader "^2.0.0"
|
||||
@@ -5116,10 +5116,10 @@ invariant@^2.2.4:
|
||||
dependencies:
|
||||
loose-envify "^1.0.0"
|
||||
|
||||
ioredis@^5.0.4:
|
||||
version "5.0.6"
|
||||
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-5.0.6.tgz#e50b8cc945f1f3ac932b0b8aab4bd8073d1402a9"
|
||||
integrity sha512-KUm7wPzIet9QrFMoMm09/4bkfVKBUD9KXwBitP3hrNkZ+A6NBndweXGwYIB/7szHcTZgfo7Kvx88SxljJV4D9A==
|
||||
ioredis@^5.2.5:
|
||||
version "5.2.5"
|
||||
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-5.2.5.tgz#c62dc3945ad2a8f0323fbb2765b934a84a68cde0"
|
||||
integrity sha512-7HKo/ClM2DGLRXdFq8ruS3Uuadensz4A76wPOU0adqlOqd1qkhoLPDaBhmVhUhNGpB+J65/bhLmNB8DDY99HJQ==
|
||||
dependencies:
|
||||
"@ioredis/commands" "^1.1.1"
|
||||
cluster-key-slot "^1.1.0"
|
||||
@@ -6082,10 +6082,10 @@ kleur@^3.0.3:
|
||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||
|
||||
knex@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/knex/-/knex-2.3.0.tgz#87fa2a9553d7cafb125d7a0645256fbe29ef5967"
|
||||
integrity sha512-WMizPaq9wRMkfnwKXKXgBZeZFOSHGdtoSz5SaLAVNs3WRDfawt9O89T4XyH52PETxjV8/kRk0Yf+8WBEP/zbYw==
|
||||
knex@^2.4.1:
|
||||
version "2.4.1"
|
||||
resolved "https://registry.yarnpkg.com/knex/-/knex-2.4.1.tgz#eff21a905e102a306a9c43ea11d984b0f54c4583"
|
||||
integrity sha512-5wylehvnTOE8EdypPFakccA1zgo6Lp+TNultncvBUCUD0PasY+PLVa9qPrTFCioxPSPVha1u9ye2niAVVbLM0Q==
|
||||
dependencies:
|
||||
colorette "2.0.19"
|
||||
commander "^9.1.0"
|
||||
|
||||
Reference in new issue
Block a user