Compare commits

..
6 Commits
41 changed files with 632 additions and 150 deletions

No files matched your search

-4
View File
@@ -1,4 +0,0 @@
**/__tests__/**
**/__integration-tests__/**
**/__mocks__/**
**/__testfixtures__/**
+11
View File
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [0.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package root
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
### Features
- add support for Buffer fields ([#305](https://github.com/expo/entity/issues/305)) ([31b52a5](https://github.com/expo/entity/commit/31b52a5f75842f4810f66c12ad03a10d9192f889))
- allow manual specification of cascadingDeleteCause in delete mutator factory method ([#306](https://github.com/expo/entity/issues/306)) ([4a3eda2](https://github.com/expo/entity/commit/4a3eda209fa747ee093ca3053b3196bf9a52193d))
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package root
+1 -1
View File
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"npmClient": "yarn",
"version": "0.46.0"
"version": "0.48.0"
}
+1 -1
View File
@@ -14,8 +14,8 @@
"test:all": "yarn test",
"integration": "./resources/run-with-docker yarn test --config jest-integration.config.js --runInBand",
"integration:all": "yarn integration",
"prepack": "yarn build",
"ctix": "ctix build && resources/prepend-barrels.sh",
"package-files": "yarn workspaces foreach --all --no-private --parallel --topological pack --dry-run",
"typedoc": "yarn build && typedoc"
},
"devDependencies": {
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-cache-adapter-local-memory",
"version": "0.46.0",
"version": "0.48.0",
"description": "Cross-request local memory cache adapter for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn lint --fix",
@@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [0.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
### Features
- add support for Buffer fields ([#305](https://github.com/expo/entity/issues/305)) ([31b52a5](https://github.com/expo/entity/commit/31b52a5f75842f4810f66c12ad03a10d9192f889))
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-cache-adapter-redis",
"version": "0.46.0",
"version": "0.48.0",
"description": "Redis cache adapter for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn lint --fix",
@@ -1,4 +1,4 @@
import { DateField } from '@expo/entity';
import { BufferField, DateField } from '@expo/entity';
export const redisTransformerMap = new Map([
[
@@ -22,4 +22,25 @@ export const redisTransformerMap = new Map([
read: (val: any) => (val ? new Date(val) : val),
},
],
[
BufferField.name,
{
/**
* All Redis fields are serialized to JSON before being written.
* In the case of buffers, they need to be explicitly reconstructed
* as JavaScript Buffer objects upon retrieval. We also explicitly
* serialize them to base64 strings to ensure no underlying Redis
* changes affect the fields.
*
* Write behavior: Value to write will always be either a Buffer or null.
* Behavior is to pass through null and convert buffers
* to base64 strings.
* Read behavior: Value will always be either null or a base64 string.
* behavior is to convert base64 strings back into Buffer
* objects and pass through null.
*/
write: (val: Buffer) => (val ? val.toString('base64') : null),
read: (val: any) => (val ? Buffer.from(val, 'base64') : val),
},
],
]);
@@ -64,6 +64,8 @@ describe(GenericRedisCacher, () => {
const entity1Created = await RedisTestEntity.creator(viewerContext)
.setField('name', 'blah')
.setField('dateField', new Date())
.setField('bufferField', Buffer.from('hello world'))
.createAsync();
// loading an entity should put it in cache
@@ -207,4 +209,27 @@ describe(GenericRedisCacher, () => {
const entity3 = await RedisTestEntity.loader(vc2).loadByFieldEqualingAsync('name', '');
expect(entity3?.getID()).toEqual(entity1.getID());
});
it('caches and restores buffer fields', async () => {
const viewerContext = new TestViewerContext(
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
);
const buffer = Buffer.from('hello world');
const entity1 = await enforceAsyncResult(
RedisTestEntity.creatorWithAuthorizationResults(viewerContext)
.setField('bufferField', buffer)
.createAsync(),
);
expect(entity1.getField('bufferField')).toEqual(buffer);
const entity2 = await RedisTestEntity.loader(viewerContext).loadByIDAsync(entity1.getID());
expect(entity2.getField('bufferField')).toEqual(buffer);
// simulate new request
const vc2 = new TestViewerContext(
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
);
const entity3 = await RedisTestEntity.loader(vc2).loadByIDAsync(entity1.getID());
expect(entity3.getField('bufferField')).toEqual(buffer);
});
});
@@ -55,9 +55,11 @@ describe(GenericRedisCacher, () => {
redisTestEntityConfiguration,
);
const date = new Date();
const buffer = Buffer.from('hello world');
const entity1Created = await RedisTestEntity.creator(viewerContext)
.setField('name', 'blah')
.setField('dateField', date)
.setField('bufferField', buffer)
.createAsync();
const testKey = `test-id-key-${entity1Created.getID()}`;
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
@@ -80,6 +82,7 @@ describe(GenericRedisCacher, () => {
});
expect(loadedObjectMap.size).toBe(1);
});
it('has correct negative caching behaviour', async () => {
const genericRedisCacher = new GenericRedisCacher(
genericRedisCacheContext,
@@ -92,6 +95,7 @@ describe(GenericRedisCacher, () => {
const cacheLoadResult = loadedObjectMap.get(testKey)!;
expect(cacheLoadResult.status).toBe(CacheStatus.NEGATIVE);
});
it('has correct invalidation behaviour', async () => {
const viewerContext = new TestViewerContext(
createRedisIntegrationTestEntityCompanionProvider(genericRedisCacheContext),
@@ -101,9 +105,11 @@ describe(GenericRedisCacher, () => {
redisTestEntityConfiguration,
);
const date = new Date();
const buffer = Buffer.from('hello world');
const entity1Created = await RedisTestEntity.creator(viewerContext)
.setField('name', 'blah')
.setField('dateField', date)
.setField('bufferField', buffer)
.createAsync();
const testKey = `test-id-key-${entity1Created.getID()}`;
const objectMap = new Map<string, Readonly<RedisTestEntityFields>>([
@@ -1,5 +1,6 @@
import {
AlwaysAllowPrivacyPolicyRule,
BufferField,
DateField,
Entity,
EntityCompanionDefinition,
@@ -14,6 +15,7 @@ export type RedisTestEntityFields = {
id: string;
name: string;
dateField: Date | null;
bufferField: Buffer | null;
};
export class RedisTestEntity extends Entity<RedisTestEntityFields, 'id', ViewerContext> {
@@ -67,11 +69,16 @@ export const redisTestEntityConfiguration = new EntityConfiguration<RedisTestEnt
dateField: new DateField({
columnName: 'date_field',
}),
bufferField: new BufferField({
columnName: 'buffer_field',
cache: true,
}),
},
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
compositeFieldDefinitions: [
{ compositeField: ['id', 'name'], cache: true },
{ compositeField: ['id', 'dateField'], cache: true },
{ compositeField: ['id', 'bufferField'], cache: true },
],
});
+8
View File
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-codemod
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-codemod
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-codemod
+4 -1
View File
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-codemod",
"version": "0.46.0",
"version": "0.48.0",
"description": "jscodeshift codemods for @expo/entity upgrades",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn lint --fix",
@@ -3,6 +3,16 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [0.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-database-adapter-knex
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
### Features
- add support for Buffer fields ([#305](https://github.com/expo/entity/issues/305)) ([31b52a5](https://github.com/expo/entity/commit/31b52a5f75842f4810f66c12ad03a10d9192f889))
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-database-adapter-knex
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-database-adapter-knex",
"version": "0.46.0",
"version": "0.48.0",
"description": "Knex database adapter for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn lint --fix",
@@ -256,6 +256,33 @@ describe('postgres entity integration', () => {
});
});
describe.only('BYTEA fields', () => {
it('supports BYTEA fields', async () => {
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
const buffer = Buffer.from('hello world');
let entity = await enforceAsyncResult(
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
.setField('binaryField', buffer)
.createAsync(),
);
expect(entity.getField('binaryField')).toEqual(buffer);
// load the entity in a different viewer context to ensure field deserialization works from db
const vc2 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
const entityLoaded = await PostgresTestEntity.loader(vc2).loadByIDAsync(entity.getID());
expect(entityLoaded.getField('binaryField')).toEqual(buffer);
const updatedBuffer = Buffer.from('updated hello world');
entity = await enforceAsyncResult(
PostgresTestEntity.updaterWithAuthorizationResults(entity)
.setField('binaryField', updatedBuffer)
.updateAsync(),
);
expect(entity.getField('binaryField')).toEqual(updatedBuffer);
});
});
it('supports single field and composite field equality loading', async () => {
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
@@ -11,6 +11,7 @@ import {
StringField,
UUIDField,
ViewerContext,
BufferField,
} from '@expo/entity';
import { Knex } from 'knex';
@@ -29,6 +30,7 @@ type PostgresTestEntityFields = {
dateField: Date | null;
maybeJsonArrayField: string[] | { hello: string } | null;
bigintField: string | null;
binaryField: Buffer | null;
};
export class PostgresTestEntity extends Entity<PostgresTestEntityFields, 'id', ViewerContext> {
@@ -61,6 +63,7 @@ export class PostgresTestEntity extends Entity<PostgresTestEntityFields, 'id', V
table.dateTime('date_field', { useTz: true });
table.jsonb('maybe_json_array_field');
table.bigint('bigint_field');
table.binary('binary_field');
});
}
await knex.into(tableName).truncate();
@@ -153,6 +156,9 @@ export const postgresTestEntityConfiguration = new EntityConfiguration<
bigintField: new BigIntField({
columnName: 'bigint_field',
}),
binaryField: new BufferField({
columnName: 'binary_field',
}),
},
databaseAdapterFlavor: 'postgres',
cacheAdapterFlavor: 'redis',
+8
View File
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-example
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-example
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-example
+10 -10
View File
@@ -2,7 +2,7 @@
"name": "@expo/entity-example",
"type": "module",
"private": true,
"version": "0.46.0",
"version": "0.48.0",
"description": "An example integration of the @expo/entity framework",
"scripts": {
"build": "tsc --build",
@@ -26,18 +26,18 @@
"@as-integrations/koa": "^1.1.1",
"@expo/entity": "workspace:^",
"@expo/entity-testing-utils": "workspace:^",
"@koa/cors": "^4.0.0",
"@koa/router": "^12.0.0",
"graphql": "^16.6.0",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.0"
"@koa/cors": "^5.0.0",
"@koa/router": "^12.0.2",
"graphql": "^16.11.0",
"koa": "^2.16.1",
"koa-bodyparser": "^4.4.1"
},
"devDependencies": {
"@jest/globals": "^30.0.0",
"@types/koa": "^2.13.6",
"@types/koa-bodyparser": "^4.3.10",
"@types/koa__cors": "^4.0.0",
"@types/koa__router": "^12.0.0",
"@types/koa": "^2.15.0",
"@types/koa-bodyparser": "^4.3.12",
"@types/koa__cors": "^5.0.0",
"@types/koa__router": "^12.0.4",
"@types/supertest": "^2.0.10",
"supertest": "^4.0.2",
"typescript": "^5.8.3"
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-full-integration-tests
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-full-integration-tests
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**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.46.0",
"version": "0.48.0",
"description": "Full redis and knex integration tests for the entity framework",
"scripts": {
"build": "tsc --build",
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-ip-address-field
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-ip-address-field
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-ip-address-field
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-ip-address-field",
"version": "0.46.0",
"version": "0.48.0",
"description": "IP address EntityField definitions for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn lint --fix",
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-secondary-cache-local-memory",
"version": "0.46.0",
"version": "0.48.0",
"description": "Local memory secondary cache for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn run lint --fix",
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-secondary-cache-redis",
"version": "0.46.0",
"version": "0.48.0",
"description": "Redis secondary cache for @expo/entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn run lint --fix",
@@ -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.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-testing-utils
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity-testing-utils
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity-testing-utils
+4 -1
View File
@@ -1,15 +1,18 @@
{
"name": "@expo/entity-testing-utils",
"version": "0.46.0",
"version": "0.48.0",
"description": "A package containing utilities for testing applications that use Entity",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn run lint --fix",
+11
View File
@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [0.48.0](https://github.com/expo/entity/compare/v0.47.0...v0.48.0) (2025-09-19)
**Note:** Version bump only for package @expo/entity
# [0.47.0](https://github.com/expo/entity/compare/v0.46.0...v0.47.0) (2025-09-19)
### Features
- add support for Buffer fields ([#305](https://github.com/expo/entity/issues/305)) ([31b52a5](https://github.com/expo/entity/commit/31b52a5f75842f4810f66c12ad03a10d9192f889))
- allow manual specification of cascadingDeleteCause in delete mutator factory method ([#306](https://github.com/expo/entity/issues/306)) ([4a3eda2](https://github.com/expo/entity/commit/4a3eda209fa747ee093ca3053b3196bf9a52193d))
# [0.46.0](https://github.com/expo/entity/compare/v0.45.0...v0.46.0) (2025-06-26)
**Note:** Version bump only for package @expo/entity
+4 -1
View File
@@ -1,15 +1,18 @@
{
"name": "@expo/entity",
"version": "0.46.0",
"version": "0.48.0",
"description": "A privacy-first data model",
"files": [
"build",
"!*.tsbuildinfo",
"!__*",
"src"
],
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"build": "tsc --build",
"prepack": "rm -rf build && yarn build",
"clean": "yarn build --clean",
"lint": "yarn run --top-level eslint src",
"lint-fix": "yarn run lint --fix",
@@ -477,6 +477,7 @@ export class AuthorizationResultBasedUpdateMutator<
databaseAdapter: EntityDatabaseAdapter<TFields, TIDField>,
metricsAdapter: IEntityMetricsAdapter,
originalEntity: TEntity,
private readonly cascadingDeleteCause: EntityCascadingDeletionInfo | null,
) {
super(
companionProvider,
@@ -517,37 +518,25 @@ export class AuthorizationResultBasedUpdateMutator<
EntityMetricsMutationType.UPDATE,
this.entityClass.name,
this.queryContext,
)(this.updateInTransactionAsync(false, null));
)(this.updateInTransactionAsync(false));
}
private async updateInTransactionAsync(
skipDatabaseUpdate: true,
cascadingDeleteCause: EntityCascadingDeletionInfo,
): Promise<Result<TEntity>>;
private async updateInTransactionAsync(
skipDatabaseUpdate: false,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<Result<TEntity>>;
private async updateInTransactionAsync(
skipDatabaseUpdate: boolean,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<Result<TEntity>> {
private async updateInTransactionAsync(skipDatabaseUpdate: boolean): Promise<Result<TEntity>> {
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) =>
this.updateInternalAsync(innerQueryContext, skipDatabaseUpdate, cascadingDeleteCause),
this.updateInternalAsync(innerQueryContext, skipDatabaseUpdate),
);
}
private async updateInternalAsync(
queryContext: EntityTransactionalQueryContext,
skipDatabaseUpdate: boolean,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<Result<TEntity>> {
this.validateFields(this.updatedFields);
this.ensureStableIDField(this.updatedFields);
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext, {
previousValue: this.originalEntity,
cascadingDeleteCause,
cascadingDeleteCause: this.cascadingDeleteCause,
});
const entityAboutToBeUpdated = entityLoader.utils.constructEntity(this.fieldsForEntity);
@@ -555,7 +544,7 @@ export class AuthorizationResultBasedUpdateMutator<
this.privacyPolicy.authorizeUpdateAsync(
this.viewerContext,
queryContext,
{ previousValue: this.originalEntity, cascadingDeleteCause },
{ previousValue: this.originalEntity, cascadingDeleteCause: this.cascadingDeleteCause },
entityAboutToBeUpdated,
this.metricsAdapter,
),
@@ -568,19 +557,31 @@ export class AuthorizationResultBasedUpdateMutator<
this.mutationValidators,
queryContext,
entityAboutToBeUpdated,
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.beforeAll,
queryContext,
entityAboutToBeUpdated,
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.beforeUpdate,
queryContext,
entityAboutToBeUpdated,
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
// skip the database update when specified
@@ -627,13 +628,21 @@ export class AuthorizationResultBasedUpdateMutator<
this.mutationTriggers.afterUpdate,
queryContext,
updatedEntity,
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.afterAll,
queryContext,
updatedEntity,
{ type: EntityMutationType.UPDATE, previousValue: this.originalEntity, cascadingDeleteCause },
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
queryContext.appendPostCommitCallback(
@@ -644,7 +653,7 @@ export class AuthorizationResultBasedUpdateMutator<
{
type: EntityMutationType.UPDATE,
previousValue: this.originalEntity,
cascadingDeleteCause,
cascadingDeleteCause: this.cascadingDeleteCause,
},
),
);
@@ -724,6 +733,7 @@ export class AuthorizationResultBasedDeleteMutator<
databaseAdapter: EntityDatabaseAdapter<TFields, TIDField>,
metricsAdapter: IEntityMetricsAdapter,
private readonly entity: TEntity,
private readonly cascadingDeleteCause: EntityCascadingDeletionInfo | null,
) {
super(
companionProvider,
@@ -750,20 +760,18 @@ export class AuthorizationResultBasedDeleteMutator<
EntityMetricsMutationType.DELETE,
this.entityClass.name,
this.queryContext,
)(this.deleteInTransactionAsync(new Set(), false, null));
)(this.deleteInTransactionAsync(new Set(), false));
}
private async deleteInTransactionAsync(
processedEntityIdentifiersFromTransitiveDeletions: Set<string>,
skipDatabaseDeletion: boolean,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<Result<void>> {
return await this.queryContext.runInTransactionIfNotInTransactionAsync((innerQueryContext) =>
this.deleteInternalAsync(
innerQueryContext,
processedEntityIdentifiersFromTransitiveDeletions,
skipDatabaseDeletion,
cascadingDeleteCause,
),
);
}
@@ -772,13 +780,12 @@ export class AuthorizationResultBasedDeleteMutator<
queryContext: EntityTransactionalQueryContext,
processedEntityIdentifiersFromTransitiveDeletions: Set<string>,
skipDatabaseDeletion: boolean,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<Result<void>> {
const authorizeDeleteResult = await asyncResult(
this.privacyPolicy.authorizeDeleteAsync(
this.viewerContext,
queryContext,
{ previousValue: null, cascadingDeleteCause },
{ previousValue: null, cascadingDeleteCause: this.cascadingDeleteCause },
this.entity,
this.metricsAdapter,
),
@@ -791,20 +798,25 @@ export class AuthorizationResultBasedDeleteMutator<
this.entity,
queryContext,
processedEntityIdentifiersFromTransitiveDeletions,
cascadingDeleteCause,
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.beforeAll,
queryContext,
this.entity,
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
{
type: EntityMutationType.DELETE,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.beforeDelete,
queryContext,
this.entity,
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
{
type: EntityMutationType.DELETE,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
if (!skipDatabaseDeletion) {
@@ -817,7 +829,7 @@ export class AuthorizationResultBasedDeleteMutator<
const entityLoader = this.entityLoaderFactory.forLoad(this.viewerContext, queryContext, {
previousValue: null,
cascadingDeleteCause,
cascadingDeleteCause: this.cascadingDeleteCause,
});
// Invalidate all caches for the entity so that any previously-cached loads
@@ -838,13 +850,19 @@ export class AuthorizationResultBasedDeleteMutator<
this.mutationTriggers.afterDelete,
queryContext,
this.entity,
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
{
type: EntityMutationType.DELETE,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
await this.executeMutationTriggersAsync(
this.mutationTriggers.afterAll,
queryContext,
this.entity,
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
{
type: EntityMutationType.DELETE,
cascadingDeleteCause: this.cascadingDeleteCause,
},
);
queryContext.appendPostCommitCallback(
@@ -852,7 +870,10 @@ export class AuthorizationResultBasedDeleteMutator<
this,
this.mutationTriggers.afterCommit,
this.entity,
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
{
type: EntityMutationType.DELETE,
cascadingDeleteCause: this.cascadingDeleteCause,
},
),
);
@@ -877,7 +898,6 @@ export class AuthorizationResultBasedDeleteMutator<
entity: TEntity,
queryContext: EntityTransactionalQueryContext,
processedEntityIdentifiers: Set<string>,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): Promise<void> {
// prevent infinite reference cycles by keeping track of entities already processed
if (processedEntityIdentifiers.has(entity.getUniqueIdentifier())) {
@@ -900,7 +920,7 @@ export class AuthorizationResultBasedDeleteMutator<
const newCascadingDeleteCause = {
entity,
cascadingDeleteCause,
cascadingDeleteCause: this.cascadingDeleteCause,
};
await Promise.all(
@@ -950,11 +970,10 @@ export class AuthorizationResultBasedDeleteMutator<
inboundReferenceEntities.map((inboundReferenceEntity) =>
enforceAsyncResult(
mutatorFactory
.forDelete(inboundReferenceEntity, queryContext)
.forDelete(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
.deleteInTransactionAsync(
processedEntityIdentifiers,
/* skipDatabaseDeletion */ true, // deletion is handled by DB
newCascadingDeleteCause,
),
),
),
@@ -966,11 +985,9 @@ export class AuthorizationResultBasedDeleteMutator<
inboundReferenceEntities.map((inboundReferenceEntity) =>
enforceAsyncResult(
mutatorFactory
.forUpdate(inboundReferenceEntity, queryContext)
.forUpdate(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
.setField(fieldName, null)
[
'updateInTransactionAsync'
](/* skipDatabaseUpdate */ true, newCascadingDeleteCause),
['updateInTransactionAsync'](/* skipDatabaseUpdate */ true),
),
),
);
@@ -981,11 +998,9 @@ export class AuthorizationResultBasedDeleteMutator<
inboundReferenceEntities.map((inboundReferenceEntity) =>
enforceAsyncResult(
mutatorFactory
.forUpdate(inboundReferenceEntity, queryContext)
.forUpdate(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
.setField(fieldName, null)
[
'updateInTransactionAsync'
](/* skipDatabaseUpdate */ false, newCascadingDeleteCause),
['updateInTransactionAsync'](/* skipDatabaseUpdate */ false),
),
),
);
@@ -996,11 +1011,10 @@ export class AuthorizationResultBasedDeleteMutator<
inboundReferenceEntities.map((inboundReferenceEntity) =>
enforceAsyncResult(
mutatorFactory
.forDelete(inboundReferenceEntity, queryContext)
.forDelete(inboundReferenceEntity, queryContext, newCascadingDeleteCause)
.deleteInTransactionAsync(
processedEntityIdentifiers,
/* skipDatabaseDeletion */ false,
newCascadingDeleteCause,
),
),
),
+1 -1
View File
@@ -68,6 +68,6 @@ export class EntityDeleter<
.getViewerContext()
.getViewerScopedEntityCompanionForClass(this.entityClass)
.getMutatorFactory()
.forDelete(this.existingEntity, this.queryContext);
.forDelete(this.existingEntity, this.queryContext, /* cascadingDeleteCause */ null);
}
}
+13
View File
@@ -121,6 +121,7 @@ export class EnumField<TRequireExplicitCache extends boolean> extends EntityFiel
/**
* EntityFieldDefinition for a enum column with a strict typescript enum type.
* The strict version checks that the value of the field adheres to a particular typescript enum
*/
export class StrictEnumField<
T extends object,
@@ -140,3 +141,15 @@ export class StrictEnumField<
return super.validateInputValueInternal(value) && Object.values(this.enum).includes(value);
}
}
/**
* EntityFieldDefinition for a column with a JS Buffer type.
*/
export class BufferField<TRequireExplicitCache extends boolean> extends EntityFieldDefinition<
Buffer,
TRequireExplicitCache
> {
protected validateInputValueInternal(value: Buffer): boolean {
return Buffer.isBuffer(value);
}
}
@@ -8,6 +8,7 @@ import { EntityCompanionProvider } from './EntityCompanionProvider';
import { EntityConfiguration } from './EntityConfiguration';
import { EntityDatabaseAdapter } from './EntityDatabaseAdapter';
import { EntityLoaderFactory } from './EntityLoaderFactory';
import { EntityCascadingDeletionInfo } from './EntityMutationInfo';
import { EntityMutationTriggerConfiguration } from './EntityMutationTriggerConfiguration';
import { EntityMutationValidator } from './EntityMutationValidator';
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
@@ -111,6 +112,7 @@ export class EntityMutatorFactory<
forUpdate(
existingEntity: TEntity,
queryContext: EntityQueryContext,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): AuthorizationResultBasedUpdateMutator<
TFields,
TIDField,
@@ -132,6 +134,7 @@ export class EntityMutatorFactory<
this.databaseAdapter,
this.metricsAdapter,
existingEntity,
cascadingDeleteCause,
);
}
@@ -143,6 +146,7 @@ export class EntityMutatorFactory<
forDelete(
existingEntity: TEntity,
queryContext: EntityQueryContext,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): AuthorizationResultBasedDeleteMutator<
TFields,
TIDField,
@@ -164,6 +168,7 @@ export class EntityMutatorFactory<
this.databaseAdapter,
this.metricsAdapter,
existingEntity,
cascadingDeleteCause,
);
}
}
+1 -1
View File
@@ -68,6 +68,6 @@ export class EntityUpdater<
.getViewerContext()
.getViewerScopedEntityCompanionForClass(this.entityClass)
.getMutatorFactory()
.forUpdate(this.existingEntity, this.queryContext);
.forUpdate(this.existingEntity, this.queryContext, /* cascadingDeleteCause */ null);
}
}
@@ -3,6 +3,7 @@ import {
AuthorizationResultBasedDeleteMutator,
AuthorizationResultBasedUpdateMutator,
} from './AuthorizationResultBasedEntityMutator';
import { EntityCascadingDeletionInfo } from './EntityMutationInfo';
import { EntityMutatorFactory } from './EntityMutatorFactory';
import { EntityPrivacyPolicy } from './EntityPrivacyPolicy';
import { EntityQueryContext } from './EntityQueryContext';
@@ -54,6 +55,7 @@ export class ViewerScopedEntityMutatorFactory<
forUpdate(
existingEntity: TEntity,
queryContext: EntityQueryContext,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): AuthorizationResultBasedUpdateMutator<
TFields,
TIDField,
@@ -62,12 +64,13 @@ export class ViewerScopedEntityMutatorFactory<
TPrivacyPolicy,
TSelectedFields
> {
return this.entityMutatorFactory.forUpdate(existingEntity, queryContext);
return this.entityMutatorFactory.forUpdate(existingEntity, queryContext, cascadingDeleteCause);
}
forDelete(
existingEntity: TEntity,
queryContext: EntityQueryContext,
cascadingDeleteCause: EntityCascadingDeletionInfo | null,
): AuthorizationResultBasedDeleteMutator<
TFields,
TIDField,
@@ -76,6 +79,6 @@ export class ViewerScopedEntityMutatorFactory<
TPrivacyPolicy,
TSelectedFields
> {
return this.entityMutatorFactory.forDelete(existingEntity, queryContext);
return this.entityMutatorFactory.forDelete(existingEntity, queryContext, cascadingDeleteCause);
}
}
@@ -4,6 +4,7 @@ import { v1 as uuidv1, v3 as uuidv3, v4 as uuidv4, v5 as uuidv5 } from 'uuid';
import { EntityFieldDefinition } from '../EntityFieldDefinition';
import {
BooleanField,
BufferField,
DateField,
EnumField,
FloatField,
@@ -88,3 +89,9 @@ describeFieldTestCase(
[TestEnum.HELLO, TestEnum.WHO, 'world'],
['what', 1, true],
);
describeFieldTestCase(
new BufferField({ columnName: 'wat' }),
[Buffer.from('hello')],
['hello', 1, true],
);
@@ -20,6 +20,7 @@ import { EntityDatabaseAdapter } from '../EntityDatabaseAdapter';
import { EntityLoaderFactory } from '../EntityLoaderFactory';
import { EntityLoaderUtils } from '../EntityLoaderUtils';
import {
EntityCascadingDeletionInfo,
EntityMutationType,
EntityTriggerMutationInfo,
EntityValidatorMutationInfo,
@@ -596,7 +597,7 @@ describe(EntityMutatorFactory, () => {
const updatedEntity = await enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext)
.forUpdate(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 'huh2')
.updateAsync(),
);
@@ -649,7 +650,7 @@ describe(EntityMutatorFactory, () => {
await enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext)
.forUpdate(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 'huh2')
.updateAsync(),
);
@@ -723,7 +724,7 @@ describe(EntityMutatorFactory, () => {
await enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext)
.forUpdate(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 'huh2')
.updateAsync(),
);
@@ -795,7 +796,7 @@ describe(EntityMutatorFactory, () => {
await enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext)
.forUpdate(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 'huh2')
.updateAsync(),
);
@@ -807,6 +808,116 @@ describe(EntityMutatorFactory, () => {
});
});
it('passes manaully-specified cascading delete cause to privacy policy and validators and triggers', async () => {
const viewerContext = mock<ViewerContext>();
const privacyPolicyEvaluationContext =
instance(
mock<
EntityPrivacyPolicyEvaluationContext<
TestFields,
'customIdField',
ViewerContext,
TestEntity,
keyof TestFields
>
>(),
);
const queryContext = new StubQueryContextProvider().getQueryContext();
const id1 = uuidv4();
const id2 = uuidv4();
const {
privacyPolicy,
mutationTriggers,
mutationValidators,
entityMutatorFactory,
entityLoaderFactory,
} = createEntityMutatorFactory([
{
customIdField: id1,
stringField: 'huh',
testIndexedField: '3',
intField: 3,
dateField: new Date(),
nullableField: null,
},
{
customIdField: id2,
stringField: 'huh',
testIndexedField: '4',
intField: 3,
dateField: new Date(),
nullableField: null,
},
]);
const spiedPrivacyPolicy = spy(privacyPolicy);
const triggerSpies = setUpMutationTriggerSpies(mutationTriggers);
const validatorSpies = setUpMutationValidatorSpies(mutationValidators);
const existingEntity = await enforceAsyncResult(
entityLoaderFactory
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
.loadByIDAsync(id2),
);
const cascadingDeleteCause: EntityCascadingDeletionInfo = {
entity: 'blah' as any,
cascadingDeleteCause: null,
};
await enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext, cascadingDeleteCause)
.setField('stringField', 'huh2')
.updateAsync(),
);
verify(
spiedPrivacyPolicy.authorizeUpdateAsync(
viewerContext,
anyOfClass(EntityTransactionalQueryContext),
deepEqual({ previousValue: existingEntity, cascadingDeleteCause }),
anyOfClass(TestEntity),
anything(),
),
).once();
verify(
spiedPrivacyPolicy.authorizeReadAsync(
viewerContext,
anyOfClass(EntityTransactionalQueryContext),
deepEqual({ previousValue: existingEntity, cascadingDeleteCause }),
anyOfClass(TestEntity),
anything(),
),
).once();
verifyValidatorCounts(viewerContext, validatorSpies, 1, {
type: EntityMutationType.UPDATE,
previousValue: existingEntity,
cascadingDeleteCause,
});
verifyTriggerCounts(
viewerContext,
triggerSpies,
{
beforeCreate: false,
afterCreate: false,
beforeUpdate: true,
afterUpdate: true,
beforeDelete: false,
afterDelete: false,
},
{
type: EntityMutationType.UPDATE,
previousValue: existingEntity,
cascadingDeleteCause,
},
);
});
it('throws when id field is updated', async () => {
const viewerContext = mock<ViewerContext>();
const privacyPolicyEvaluationContext =
@@ -844,7 +955,7 @@ describe(EntityMutatorFactory, () => {
await expect(
enforceAsyncResult(
entityMutatorFactory
.forUpdate(existingEntity, queryContext)
.forUpdate(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('customIdField', uuidv4())
.updateAsync(),
),
@@ -896,7 +1007,9 @@ describe(EntityMutatorFactory, () => {
expect(existingEntity).toBeTruthy();
await enforceAsyncResult(
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
entityMutatorFactory
.forDelete(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
);
await expect(
@@ -946,7 +1059,9 @@ describe(EntityMutatorFactory, () => {
);
await enforceAsyncResult(
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
entityMutatorFactory
.forDelete(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
);
verify(
@@ -998,7 +1113,9 @@ describe(EntityMutatorFactory, () => {
);
await enforceAsyncResult(
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
entityMutatorFactory
.forDelete(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
);
verifyTriggerCounts(
@@ -1054,13 +1171,89 @@ describe(EntityMutatorFactory, () => {
);
await enforceAsyncResult(
entityMutatorFactory.forDelete(existingEntity, queryContext).deleteAsync(),
entityMutatorFactory
.forDelete(existingEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
);
verifyValidatorCounts(viewerContext, validatorSpies, 0, {
type: EntityMutationType.DELETE as any,
});
});
it('passes manaully-specified cascading delete cause to privacy policy and triggers', async () => {
const viewerContext = mock<ViewerContext>();
const privacyPolicyEvaluationContext =
instance(
mock<
EntityPrivacyPolicyEvaluationContext<
TestFields,
'customIdField',
ViewerContext,
TestEntity,
keyof TestFields
>
>(),
);
const queryContext = new StubQueryContextProvider().getQueryContext();
const id1 = uuidv4();
const { mutationTriggers, privacyPolicy, entityMutatorFactory, entityLoaderFactory } =
createEntityMutatorFactory([
{
customIdField: id1,
stringField: 'huh',
testIndexedField: '3',
intField: 3,
dateField: new Date(),
nullableField: null,
},
]);
const spiedPrivacyPolicy = spy(privacyPolicy);
const triggerSpies = setUpMutationTriggerSpies(mutationTriggers);
const existingEntity = await enforceAsyncResult(
entityLoaderFactory
.forLoad(viewerContext, queryContext, privacyPolicyEvaluationContext)
.loadByIDAsync(id1),
);
const cascadingDeleteCause: EntityCascadingDeletionInfo = {
entity: 'blah' as any,
cascadingDeleteCause: null,
};
await enforceAsyncResult(
entityMutatorFactory
.forDelete(existingEntity, queryContext, cascadingDeleteCause)
.deleteAsync(),
);
verify(
spiedPrivacyPolicy.authorizeDeleteAsync(
viewerContext,
anyOfClass(EntityTransactionalQueryContext),
deepEqual({ previousValue: null, cascadingDeleteCause }),
anyOfClass(TestEntity),
anything(),
),
).once();
verifyTriggerCounts(
viewerContext,
triggerSpies,
{
beforeCreate: false,
afterCreate: false,
beforeUpdate: false,
afterUpdate: false,
beforeDelete: true,
afterDelete: true,
},
{ type: EntityMutationType.DELETE, cascadingDeleteCause },
);
});
});
it('invalidates cache for fields upon create', async () => {
@@ -1163,7 +1356,7 @@ describe(EntityMutatorFactory, () => {
await expect(
entityMutatorFactory
.forUpdate(createdEntity, queryContext)
.forUpdate(createdEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 10 as any)
.updateAsync(),
).rejects.toThrow('Entity field not valid: TestEntity (stringField = 10)');
@@ -1284,14 +1477,14 @@ describe(EntityMutatorFactory, () => {
expect(entityCreateResult.value).toBe(undefined);
const entityUpdateResult = await entityMutatorFactory
.forUpdate(fakeEntity, queryContext)
.forUpdate(fakeEntity, queryContext, /* cascadingDeleteCause */ null)
.updateAsync();
expect(entityUpdateResult.ok).toBe(false);
expect(entityUpdateResult.reason).toEqual(rejectionError);
expect(entityUpdateResult.value).toBe(undefined);
const entityDeleteResult = await entityMutatorFactory
.forDelete(fakeEntity, queryContext)
.forDelete(fakeEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync();
expect(entityDeleteResult.ok).toBe(false);
expect(entityDeleteResult.reason).toEqual(rejectionError);
@@ -1406,10 +1599,14 @@ describe(EntityMutatorFactory, () => {
entityMutatorFactory.forCreate(viewerContext, queryContext).createAsync(),
).rejects.toEqual(rejectionError);
await expect(
entityMutatorFactory.forUpdate(fakeEntity, queryContext).updateAsync(),
entityMutatorFactory
.forUpdate(fakeEntity, queryContext, /* cascadingDeleteCause */ null)
.updateAsync(),
).rejects.toEqual(rejectionError);
await expect(
entityMutatorFactory.forDelete(fakeEntity, queryContext).deleteAsync(),
entityMutatorFactory
.forDelete(fakeEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
).rejects.toEqual(rejectionError);
});
@@ -1428,12 +1625,16 @@ describe(EntityMutatorFactory, () => {
await enforceAsyncResult(
entityMutatorFactory
.forUpdate(newEntity, queryContext)
.forUpdate(newEntity, queryContext, /* cascadingDeleteCause */ null)
.setField('stringField', 'wat')
.updateAsync(),
);
await enforceAsyncResult(entityMutatorFactory.forDelete(newEntity, queryContext).deleteAsync());
await enforceAsyncResult(
entityMutatorFactory
.forDelete(newEntity, queryContext, /* cascadingDeleteCause */ null)
.deleteAsync(),
);
verify(
spiedMetricsAdapter.logMutatorMutationEvent(
Generated
+72 -54
View File
@@ -2475,16 +2475,16 @@ __metadata:
"@expo/entity": "workspace:^"
"@expo/entity-testing-utils": "workspace:^"
"@jest/globals": "npm:^30.0.0"
"@koa/cors": "npm:^4.0.0"
"@koa/router": "npm:^12.0.0"
"@types/koa": "npm:^2.13.6"
"@types/koa-bodyparser": "npm:^4.3.10"
"@types/koa__cors": "npm:^4.0.0"
"@types/koa__router": "npm:^12.0.0"
"@koa/cors": "npm:^5.0.0"
"@koa/router": "npm:^12.0.2"
"@types/koa": "npm:^2.15.0"
"@types/koa-bodyparser": "npm:^4.3.12"
"@types/koa__cors": "npm:^5.0.0"
"@types/koa__router": "npm:^12.0.4"
"@types/supertest": "npm:^2.0.10"
graphql: "npm:^16.6.0"
koa: "npm:^2.14.2"
koa-bodyparser: "npm:^4.4.0"
graphql: "npm:^16.11.0"
koa: "npm:^2.16.1"
koa-bodyparser: "npm:^4.4.1"
supertest: "npm:^4.0.2"
typescript: "npm:^5.8.3"
languageName: unknown
@@ -3244,24 +3244,25 @@ __metadata:
languageName: node
linkType: hard
"@koa/cors@npm:^4.0.0":
version: 4.0.0
resolution: "@koa/cors@npm:4.0.0"
"@koa/cors@npm:^5.0.0":
version: 5.0.0
resolution: "@koa/cors@npm:5.0.0"
dependencies:
vary: "npm:^1.1.2"
checksum: 10c0/53caa512e7aacf8d4ad0d9eb427fa84bdfd6fccb9a060b317d77acf352941ad7935bbc0b4569c0c73d9cdef0b3fce83b7e00190548f31076366dd8e60d7e1198
checksum: 10c0/49e5f3b861590bd81aa3663a2f0658234a9b378840bb54a2947b3c5f2067f9d966b6fa2e9049fdc7c74c787456d1885bacd0b7ee1f134274d28282c7df99c3fd
languageName: node
linkType: hard
"@koa/router@npm:^12.0.0":
version: 12.0.0
resolution: "@koa/router@npm:12.0.0"
"@koa/router@npm:^12.0.2":
version: 12.0.2
resolution: "@koa/router@npm:12.0.2"
dependencies:
debug: "npm:^4.3.4"
http-errors: "npm:^2.0.0"
koa-compose: "npm:^4.1.0"
methods: "npm:^1.1.2"
path-to-regexp: "npm:^6.2.1"
checksum: 10c0/a9f8277983410568e30ff25cfe549bdd8f7ef59ad8a04c95b18cd1d2a4d727b3dfaeaab860e92816425b19114607feba5cc1a086f9a8c0a4a534bc57d6b089e1
path-to-regexp: "npm:^6.3.0"
checksum: 10c0/9d33af8b5cb7e80cf2a17e156fe1821ad31ad672ff8e9df62a3af2d2e4a6f49abbbb7038edaea45ef078cabdd8a1ce595ad7da810e96b17c5b954ee46f7e554d
languageName: node
linkType: hard
@@ -4374,12 +4375,12 @@ __metadata:
languageName: node
linkType: hard
"@types/koa-bodyparser@npm:^4.3.10":
version: 4.3.10
resolution: "@types/koa-bodyparser@npm:4.3.10"
"@types/koa-bodyparser@npm:^4.3.12":
version: 4.3.12
resolution: "@types/koa-bodyparser@npm:4.3.12"
dependencies:
"@types/koa": "npm:*"
checksum: 10c0/b236fa446488ba2d73a9bed672d1cc3ececf3dc2e057fc01615251a367f33914b4caba73e56e29ffd670cd528b5d71534c8e126def7bf46fef2002aec6b698f8
checksum: 10c0/1484ad4a24feff23e08d39d243ad80321ab0a42aef355ca8bbedecda85f9778b446d75d8e2ff511d8ad08afa3b473f513debc627b4e0053e9abe950c9e42d1e4
languageName: node
linkType: hard
@@ -4392,7 +4393,7 @@ __metadata:
languageName: node
linkType: hard
"@types/koa@npm:*, @types/koa@npm:^2.13.6":
"@types/koa@npm:*":
version: 2.13.6
resolution: "@types/koa@npm:2.13.6"
dependencies:
@@ -4408,21 +4409,37 @@ __metadata:
languageName: node
linkType: hard
"@types/koa__cors@npm:^4.0.0":
version: 4.0.0
resolution: "@types/koa__cors@npm:4.0.0"
"@types/koa@npm:^2.15.0":
version: 2.15.0
resolution: "@types/koa@npm:2.15.0"
dependencies:
"@types/koa": "npm:*"
checksum: 10c0/ba8379ce6f2484a0b6446d4c3b016951d2ab79ef13b27d0ab41abcfdf60ff72998d0e23722afa85ded9fe28d12ecedfed7b2055d7df72ea7049a613fc61d3acb
"@types/accepts": "npm:*"
"@types/content-disposition": "npm:*"
"@types/cookies": "npm:*"
"@types/http-assert": "npm:*"
"@types/http-errors": "npm:*"
"@types/keygrip": "npm:*"
"@types/koa-compose": "npm:*"
"@types/node": "npm:*"
checksum: 10c0/3fd591e25ecffc32ffa7cb152d2c5caeccefe5a72cb09d187102d8f41101bdaeeb802a07a6672eac58f805fa59892e79c1cc203ca7b27b0de75d7eac508c2b47
languageName: node
linkType: hard
"@types/koa__router@npm:^12.0.0":
version: 12.0.0
resolution: "@types/koa__router@npm:12.0.0"
"@types/koa__cors@npm:^5.0.0":
version: 5.0.0
resolution: "@types/koa__cors@npm:5.0.0"
dependencies:
"@types/koa": "npm:*"
checksum: 10c0/e5a924254b0416ec929b148d39505e3084cfedd5043003baaf76db6e3e9a172a3373e0093e4668375c0e59e81dc7686f4abb201160e8614d84ed40c68b9b5c56
checksum: 10c0/2392b4ad63b8f730fee49f5c2104602613e77cac8e5aaac42cd74c60107563ad6e1194422b565519462eb5358746f59f19f5e890896494f7e7de1ac71566bbb2
languageName: node
linkType: hard
"@types/koa__router@npm:^12.0.4":
version: 12.0.4
resolution: "@types/koa__router@npm:12.0.4"
dependencies:
"@types/koa": "npm:*"
checksum: 10c0/bc783b47d3c2a6bb8171ba3ddffa5781c5ed11e6b716e74281dfb71229ceb3189ddf5ac178e6f9552ca9d43e8370e0bd558054d66439b43a9e500d046a15ffa8
languageName: node
linkType: hard
@@ -6334,13 +6351,13 @@ __metadata:
languageName: node
linkType: hard
"cookies@npm:~0.8.0":
version: 0.8.0
resolution: "cookies@npm:0.8.0"
"cookies@npm:~0.9.0":
version: 0.9.1
resolution: "cookies@npm:0.9.1"
dependencies:
depd: "npm:~2.0.0"
keygrip: "npm:~1.1.0"
checksum: 10c0/0af32f30d1ece0596efc05782c66b9d61659e20c6cc5b695452abf5ceb51883ef43c5c73d86badd7d028a0da7d39f864c95f33640aef04f97fad70f35986bea3
checksum: 10c0/3ffa1c0e992b62ee119adae4dd2ddd4a89166fa5434cd9bd9ff84ec4d2f14dfe2318a601280abfe32a4f64f884ec9345fb1912e488b002d188d2efa0d3919ba3
languageName: node
linkType: hard
@@ -8482,10 +8499,10 @@ __metadata:
languageName: node
linkType: hard
"graphql@npm:^16.6.0":
version: 16.6.0
resolution: "graphql@npm:16.6.0"
checksum: 10c0/3a2c15ff58b69d017618d2b224fa6f3c4a7937e1f711c3a5e0948db536b4931e6e649560b53de7cc26735e027ceea6e2d0a6bb7c29fc4639b290313e3aa71618
"graphql@npm:^16.11.0":
version: 16.11.0
resolution: "graphql@npm:16.11.0"
checksum: 10c0/124da7860a2292e9acf2fed0c71fc0f6a9b9ca865d390d112bdd563c1f474357141501c12891f4164fe984315764736ad67f705219c62f7580681d431a85db88
languageName: node
linkType: hard
@@ -10428,13 +10445,14 @@ __metadata:
languageName: node
linkType: hard
"koa-bodyparser@npm:^4.4.0":
version: 4.4.0
resolution: "koa-bodyparser@npm:4.4.0"
"koa-bodyparser@npm:^4.4.1":
version: 4.4.1
resolution: "koa-bodyparser@npm:4.4.1"
dependencies:
co-body: "npm:^6.0.0"
copy-to: "npm:^2.0.1"
checksum: 10c0/1eb4f742cb94b2b05432f284a923967a1abb36df5ec41361a60c5b0783e8fbbf035c90c42c8956a5ef9265f019f4d17e260c261e1effdbf96830701ef9f3c40f
type-is: "npm:^1.6.18"
checksum: 10c0/72abf648bb62649cebfed310ef8fd09db3ca48867e083814b63f799fedadfdc440817507b9edbcd1d8d75282b23ed64812d924d4d5fc12375ae935150b224c1d
languageName: node
linkType: hard
@@ -10455,15 +10473,15 @@ __metadata:
languageName: node
linkType: hard
"koa@npm:^2.14.2":
version: 2.14.2
resolution: "koa@npm:2.14.2"
"koa@npm:^2.16.1":
version: 2.16.1
resolution: "koa@npm:2.16.1"
dependencies:
accepts: "npm:^1.3.5"
cache-content-type: "npm:^1.0.0"
content-disposition: "npm:~0.5.2"
content-type: "npm:^1.0.4"
cookies: "npm:~0.8.0"
cookies: "npm:~0.9.0"
debug: "npm:^4.3.2"
delegates: "npm:^1.0.0"
depd: "npm:^2.0.0"
@@ -10482,7 +10500,7 @@ __metadata:
statuses: "npm:^1.5.0"
type-is: "npm:^1.6.16"
vary: "npm:^1.1.2"
checksum: 10c0/f60ae84974d7cb834a5937592e010d97134278527a55a3a38973935db9ea409fecbd824e5ff0fa767077d9a9dc1f1a32881b626ddaad8b5978756c345f520cdd
checksum: 10c0/66beb2e4d7968e1081341ea9a9c1f7f3fad4aaa0475c813f1be79ed84c345d9d45de9e34eeee3cdd790fc81ee5efbde2223d49fd5da571e29b0b3bed6baafb8e
languageName: node
linkType: hard
@@ -12310,10 +12328,10 @@ __metadata:
languageName: node
linkType: hard
"path-to-regexp@npm:^6.2.1":
version: 6.2.1
resolution: "path-to-regexp@npm:6.2.1"
checksum: 10c0/7a73811ca703e5c199e5b50b9649ab8f6f7b458a37f7dff9ea338815203f5b1f95fe8cb24d4fdfe2eab5d67ce43562d92534330babca35cdf3231f966adb9360
"path-to-regexp@npm:^6.3.0":
version: 6.3.0
resolution: "path-to-regexp@npm:6.3.0"
checksum: 10c0/73b67f4638b41cde56254e6354e46ae3a2ebc08279583f6af3d96fe4664fc75788f74ed0d18ca44fa4a98491b69434f9eee73b97bb5314bd1b5adb700f5c18d6
languageName: node
linkType: hard
@@ -14553,7 +14571,7 @@ __metadata:
languageName: node
linkType: hard
"type-is@npm:^1.6.16, type-is@npm:~1.6.18":
"type-is@npm:^1.6.16, type-is@npm:^1.6.18, type-is@npm:~1.6.18":
version: 1.6.18
resolution: "type-is@npm:1.6.18"
dependencies: