mirror of
https://github.com/expo/entity.git
synced 2026-11-15 17:32:07 -10:00
Compare commits
16
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c692afbcb | ||
|
|
17bd06e67e | ||
|
|
69ef7aa0c9 | ||
|
|
8db4fbbd8a | ||
|
|
c22ed50e80 | ||
|
|
9dcbc3da23 | ||
|
|
e87e2a3a28 | ||
|
|
68e222f512 | ||
|
|
e404297b30 | ||
|
|
cbf51c0488 | ||
|
|
243a0386fb | ||
|
|
727f16662d | ||
|
|
0e1b9f9452 | ||
|
|
52327bd56c | ||
|
|
af121ed765 | ||
|
|
ae9aab60bb |
No files matched your search
@@ -3,6 +3,19 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
### Features
|
||||
|
||||
- add ID-based and field-based knex database loaders for use with locking modifiers ([#706](https://github.com/expo/entity/issues/706)) ([e87e2a3](https://github.com/expo/entity/commit/e87e2a3a28f4279f5911bfd0189964b94a2ced7f))
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
### Features
|
||||
|
||||
- add forShare and skipLocked selection modifiers to knex loader ([#705](https://github.com/expo/entity/issues/705)) ([243a038](https://github.com/expo/entity/commit/243a0386fb9755f3926ade8dcc1b92adf38cd923))
|
||||
- add forUpdate to knex loader ([#704](https://github.com/expo/entity/issues/704)) ([727f166](https://github.com/expo/entity/commit/727f16662d8baa3757bb8e94f51d837f17fd333d))
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package root
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"packages": ["packages/*"],
|
||||
"npmClient": "yarn",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
||||
}
|
||||
+2
-2
@@ -22,8 +22,8 @@
|
||||
"typedoc": "yarn build && typedoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/bases": "1.0.27",
|
||||
"@types/node": "24.13.4",
|
||||
"@tsconfig/bases": "1.0.28",
|
||||
"@types/node": "24.19.1",
|
||||
"ctix": "2.8.2",
|
||||
"jest": "30.5.1",
|
||||
"lerna": "9.0.7",
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**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.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Cross-request local memory cache adapter for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-cache-adapter-redis",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Redis cache adapter for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-codemod",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "jscodeshift codemods for @expo/entity upgrades",
|
||||
"keywords": [
|
||||
"entity"
|
||||
@@ -27,7 +27,7 @@
|
||||
"devDependencies": {
|
||||
"@jest/globals": "30.5.1",
|
||||
"@types/jscodeshift": "17.3.0",
|
||||
"@types/node": "24.13.4",
|
||||
"@types/node": "24.19.1",
|
||||
"jscodeshift": "17.4.0",
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex-testing-utils
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
### Features
|
||||
|
||||
- add forShare and skipLocked selection modifiers to knex loader ([#705](https://github.com/expo/entity/issues/705)) ([243a038](https://github.com/expo/entity/commit/243a0386fb9755f3926ade8dcc1b92adf38cd923))
|
||||
- add forUpdate to knex loader ([#704](https://github.com/expo/entity/issues/704)) ([727f166](https://github.com/expo/entity/commit/727f16662d8baa3757bb8e94f51d837f17fd333d))
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex-testing-utils
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-database-adapter-knex-testing-utils",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Testing utilities for applications using Entity with Knex database adapter",
|
||||
"keywords": [
|
||||
"entity"
|
||||
@@ -33,7 +33,7 @@
|
||||
"devDependencies": {
|
||||
"@jest/globals": "30.5.1",
|
||||
"@types/invariant": "2.2.37",
|
||||
"@types/node": "24.13.4",
|
||||
"@types/node": "24.19.1",
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
+8
-1
@@ -212,7 +212,14 @@ export class StubPostgresDatabaseAdapter<
|
||||
tableName,
|
||||
tableFieldSingleValueEqualityOperands,
|
||||
tableFieldMultiValueEqualityOperands,
|
||||
{ orderBy: undefined, offset: undefined, limit: undefined },
|
||||
{
|
||||
orderBy: undefined,
|
||||
offset: undefined,
|
||||
limit: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: undefined,
|
||||
skipLocked: undefined,
|
||||
},
|
||||
);
|
||||
return results.length;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
### Features
|
||||
|
||||
- add ID-based and field-based knex database loaders for use with locking modifiers ([#706](https://github.com/expo/entity/issues/706)) ([e87e2a3](https://github.com/expo/entity/commit/e87e2a3a28f4279f5911bfd0189964b94a2ced7f))
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
### Features
|
||||
|
||||
- add forShare and skipLocked selection modifiers to knex loader ([#705](https://github.com/expo/entity/issues/705)) ([243a038](https://github.com/expo/entity/commit/243a0386fb9755f3926ade8dcc1b92adf38cd923))
|
||||
- add forUpdate to knex loader ([#704](https://github.com/expo/entity/issues/704)) ([727f166](https://github.com/expo/entity/commit/727f16662d8baa3757bb8e94f51d837f17fd333d))
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-database-adapter-knex",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Knex database adapter for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
@@ -32,7 +32,7 @@
|
||||
"devDependencies": {
|
||||
"@expo/entity-testing-utils": "workspace:^",
|
||||
"@jest/globals": "30.5.1",
|
||||
"pg": "8.23.0",
|
||||
"pg": "8.23.1",
|
||||
"ts-mockito": "2.6.1",
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
|
||||
+195
@@ -1,12 +1,17 @@
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
EntityConstructionUtils,
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
IEntityClass,
|
||||
IEntityMetricsAdapter,
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { EntityNotFoundError, mapMap } from '@expo/entity';
|
||||
import type { Result } from '@expo/results';
|
||||
import { result } from '@expo/results';
|
||||
import assert from 'assert';
|
||||
|
||||
import type {
|
||||
FieldEqualityCondition,
|
||||
@@ -64,6 +69,48 @@ export type EntityLoaderOrderByClause<
|
||||
| EntityLoaderFieldNameOrderByClause<TFields, TSelectedFields>
|
||||
| EntityLoaderFieldFragmentOrderByClause<TFields, TSelectedFields>;
|
||||
|
||||
/**
|
||||
* Row locking modifier that locks the selected rows for update using `SELECT ... FOR UPDATE`.
|
||||
* The lock is held until the end of the transaction, so the query context must be transactional.
|
||||
*/
|
||||
export interface EntityLoaderForUpdateRowLockingModifier {
|
||||
forUpdate: true;
|
||||
forShare?: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* Row locking modifier that locks the selected rows in share mode using `SELECT ... FOR SHARE`.
|
||||
* The lock is held until the end of the transaction, so the query context must be transactional.
|
||||
*/
|
||||
export interface EntityLoaderForShareRowLockingModifier {
|
||||
forShare: true;
|
||||
forUpdate?: never;
|
||||
}
|
||||
|
||||
/**
|
||||
* Row locking modifiers for load methods that never report a missing row as an error. Exactly one of
|
||||
* `forUpdate` or `forShare` is required. `skipLocked` may be set to skip rows already locked by another
|
||||
* transaction (using `SKIP LOCKED`) instead of waiting for them; skipped rows are reported as missing.
|
||||
*/
|
||||
export type EntityLoaderRowLockingModifiers = (
|
||||
| EntityLoaderForUpdateRowLockingModifier
|
||||
| EntityLoaderForShareRowLockingModifier
|
||||
) & {
|
||||
skipLocked?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Row locking modifiers for load methods that throw when a row is missing. Exactly one of `forUpdate`
|
||||
* or `forShare` is required. `skipLocked` is not permitted since a row skipped because another transaction
|
||||
* holds a lock on it would be indistinguishable from a row that does not exist.
|
||||
*/
|
||||
export type EntityLoaderRowLockingModifiersWithoutSkipLocked = (
|
||||
| EntityLoaderForUpdateRowLockingModifier
|
||||
| EntityLoaderForShareRowLockingModifier
|
||||
) & {
|
||||
skipLocked?: never;
|
||||
};
|
||||
|
||||
/**
|
||||
* SQL modifiers that only affect the selection but not the projection.
|
||||
*/
|
||||
@@ -85,6 +132,24 @@ export interface EntityLoaderQuerySelectionModifiers<
|
||||
* Limit the number of entities returned.
|
||||
*/
|
||||
limit?: number;
|
||||
|
||||
/**
|
||||
* Lock the selected rows for update using `SELECT ... FOR UPDATE`. The lock is held until the
|
||||
* end of the transaction, so the query context must be transactional. Mutually exclusive with `forShare`.
|
||||
*/
|
||||
forUpdate?: boolean;
|
||||
|
||||
/**
|
||||
* Lock the selected rows in share mode using `SELECT ... FOR SHARE`. The lock is held until the
|
||||
* end of the transaction, so the query context must be transactional. Mutually exclusive with `forUpdate`.
|
||||
*/
|
||||
forShare?: boolean;
|
||||
|
||||
/**
|
||||
* Skip rows that are already locked by another transaction using `SKIP LOCKED` instead of waiting for them.
|
||||
* Requires `forUpdate` or `forShare`.
|
||||
*/
|
||||
skipLocked?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -357,6 +422,15 @@ export class AuthorizationResultBasedKnexEntityLoader<
|
||||
> {
|
||||
constructor(
|
||||
private readonly queryContext: EntityQueryContext,
|
||||
private readonly entityConfiguration: EntityConfiguration<TFields, TIDField>,
|
||||
private readonly entityClass: IEntityClass<
|
||||
TFields,
|
||||
TIDField,
|
||||
TViewerContext,
|
||||
TEntity,
|
||||
TPrivacyPolicy,
|
||||
TSelectedFields
|
||||
>,
|
||||
private readonly knexDataManager: EntityKnexDataManager<TFields, TIDField>,
|
||||
protected readonly metricsAdapter: IEntityMetricsAdapter,
|
||||
private readonly constructionUtils: EntityConstructionUtils<
|
||||
@@ -369,6 +443,127 @@ export class AuthorizationResultBasedKnexEntityLoader<
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns entity result for matching ID, where result error can be UnauthorizedError or EntityNotFoundError.
|
||||
*/
|
||||
async loadByIDFromDatabaseAsync(
|
||||
id: TFields[TIDField],
|
||||
modifiers: EntityLoaderRowLockingModifiersWithoutSkipLocked,
|
||||
): Promise<Result<TEntity>> {
|
||||
const entityResults = await this.loadManyByIDsFromDatabaseAsync([id], modifiers);
|
||||
const entityResult = entityResults.get(id);
|
||||
assert(entityResult !== undefined, `${id} should be guaranteed to be present in returned map`);
|
||||
return entityResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns entity result for matching ID, or null if no entity exists for ID, where result error can be UnauthorizedError.
|
||||
*/
|
||||
async loadByIDNullableFromDatabaseAsync(
|
||||
id: TFields[TIDField],
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<Result<TEntity> | null> {
|
||||
const entityResults = await this.loadManyByIDsNullableFromDatabaseAsync([id], modifiers);
|
||||
return entityResults.get(id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns map from ID to corresponding entity result, where result error can be UnauthorizedError or EntityNotFoundError.
|
||||
*/
|
||||
async loadManyByIDsFromDatabaseAsync(
|
||||
ids: readonly TFields[TIDField][],
|
||||
modifiers: EntityLoaderRowLockingModifiersWithoutSkipLocked,
|
||||
): Promise<ReadonlyMap<TFields[TIDField], Result<TEntity>>> {
|
||||
const entityResults = await this.loadManyByIDsNullableFromDatabaseAsync(ids, modifiers);
|
||||
return mapMap(
|
||||
entityResults,
|
||||
(entityResult, id) =>
|
||||
entityResult ??
|
||||
result(
|
||||
new EntityNotFoundError({
|
||||
entityClass: this.entityClass,
|
||||
fieldName: this.entityConfiguration.idField,
|
||||
fieldValue: id,
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns map from ID to nullable corresponding entity result, where result error can be UnauthorizedError.
|
||||
*/
|
||||
async loadManyByIDsNullableFromDatabaseAsync(
|
||||
ids: readonly TFields[TIDField][],
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<ReadonlyMap<TFields[TIDField], Result<TEntity> | null>> {
|
||||
const idField = this.entityConfiguration.idField;
|
||||
this.constructionUtils.validateFieldAndValues(idField, ids);
|
||||
|
||||
const fieldObjects =
|
||||
ids.length > 0
|
||||
? await this.knexDataManager.loadManyByFieldEqualityConjunctionAsync(
|
||||
this.queryContext,
|
||||
[{ fieldName: idField, fieldValues: ids }],
|
||||
modifiers,
|
||||
)
|
||||
: [];
|
||||
|
||||
const idsToFieldObjects = new Map<TFields[TIDField], readonly Readonly<TFields>[]>(
|
||||
ids.map((id) => [id, []]),
|
||||
);
|
||||
for (const fieldObject of fieldObjects) {
|
||||
const id = fieldObject[idField];
|
||||
idsToFieldObjects.set(id, [...(idsToFieldObjects.get(id) ?? []), fieldObject]);
|
||||
}
|
||||
|
||||
const idsToEntityResults =
|
||||
await this.constructionUtils.constructAndAuthorizeEntitiesAsync(idsToFieldObjects);
|
||||
return mapMap(idsToEntityResults, (entityResults) => entityResults[0] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns entity result where uniqueFieldName equals fieldValue, or null if no entity matches the condition, where result error can be UnauthorizedError.
|
||||
* @throws when multiple entities match the condition
|
||||
*/
|
||||
async loadByFieldEqualingFromDatabaseAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
uniqueFieldName: N,
|
||||
fieldValue: NonNullable<TFields[N]>,
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<Result<TEntity> | null> {
|
||||
const entityResults = await this.loadManyByFieldEqualingFromDatabaseAsync(
|
||||
uniqueFieldName,
|
||||
fieldValue,
|
||||
modifiers,
|
||||
);
|
||||
assert(
|
||||
entityResults.length <= 1,
|
||||
`loadByFieldEqualingFromDatabase: Multiple entities of type ${this.entityClass.name} found for ${String(
|
||||
uniqueFieldName,
|
||||
)}=${fieldValue}`,
|
||||
);
|
||||
return entityResults[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns array of entity results where fieldName equals fieldValue, where result error can be UnauthorizedError
|
||||
*/
|
||||
async loadManyByFieldEqualingFromDatabaseAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
fieldName: N,
|
||||
fieldValue: NonNullable<TFields[N]>,
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<readonly Result<TEntity>[]> {
|
||||
return await this.loadManyByFieldEqualityConjunctionAsync(
|
||||
[{ fieldName, fieldValue }],
|
||||
modifiers,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns the first entity results that matches the query, where result error can be
|
||||
|
||||
@@ -134,6 +134,21 @@ export interface PostgresQuerySelectionModifiers<TFields extends Record<string,
|
||||
* Limit the number of entities returned.
|
||||
*/
|
||||
limit?: number;
|
||||
|
||||
/**
|
||||
* Lock the selected rows for update using `SELECT ... FOR UPDATE`. Mutually exclusive with `forShare`.
|
||||
*/
|
||||
forUpdate?: boolean;
|
||||
|
||||
/**
|
||||
* Lock the selected rows in share mode using `SELECT ... FOR SHARE`. Mutually exclusive with `forUpdate`.
|
||||
*/
|
||||
forShare?: boolean;
|
||||
|
||||
/**
|
||||
* Skip rows that are already locked by another transaction using `SKIP LOCKED`. Requires `forUpdate` or `forShare`.
|
||||
*/
|
||||
skipLocked?: boolean;
|
||||
}
|
||||
|
||||
export type TableOrderByClause<TFields extends Record<string, any>> =
|
||||
@@ -152,6 +167,9 @@ export interface TableQuerySelectionModifiers<TFields extends Record<string, any
|
||||
orderBy: TableOrderByClause<TFields>[] | undefined;
|
||||
offset: number | undefined;
|
||||
limit: number | undefined;
|
||||
forUpdate: boolean | undefined;
|
||||
forShare: boolean | undefined;
|
||||
skipLocked: boolean | undefined;
|
||||
}
|
||||
|
||||
export abstract class BasePostgresEntityDatabaseAdapter<
|
||||
@@ -343,6 +361,9 @@ export abstract class BasePostgresEntityDatabaseAdapter<
|
||||
: undefined,
|
||||
offset: querySelectionModifiers.offset,
|
||||
limit: querySelectionModifiers.limit,
|
||||
forUpdate: querySelectionModifiers.forUpdate,
|
||||
forShare: querySelectionModifiers.forShare,
|
||||
skipLocked: querySelectionModifiers.skipLocked,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ export abstract class BaseSQLQueryBuilder<
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
orderBy?: readonly EntityLoaderOrderByClause<TFields, TSelectedFields>[];
|
||||
forUpdate?: boolean;
|
||||
forShare?: boolean;
|
||||
skipLocked?: boolean;
|
||||
},
|
||||
) {}
|
||||
|
||||
@@ -41,6 +44,35 @@ export abstract class BaseSQLQueryBuilder<
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the selected rows for update using `SELECT ... FOR UPDATE`. The lock is held until the
|
||||
* end of the transaction, so the query must be executed in a transactional query context.
|
||||
* Mutually exclusive with `forShare`.
|
||||
*/
|
||||
forUpdate(): this {
|
||||
this.modifiers.forUpdate = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the selected rows in share mode using `SELECT ... FOR SHARE`. The lock is held until the
|
||||
* end of the transaction, so the query must be executed in a transactional query context.
|
||||
* Mutually exclusive with `forUpdate`.
|
||||
*/
|
||||
forShare(): this {
|
||||
this.modifiers.forShare = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip rows that are already locked by another transaction using `SKIP LOCKED` instead of waiting for them.
|
||||
* Requires `forUpdate()` or `forShare()`.
|
||||
*/
|
||||
skipLocked(): this {
|
||||
this.modifiers.skipLocked = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order by a field. Can be called multiple times to add multiple order bys.
|
||||
*/
|
||||
|
||||
@@ -6,11 +6,14 @@ import type {
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { mapMap } from '@expo/entity';
|
||||
|
||||
import type {
|
||||
AuthorizationResultBasedKnexEntityLoader,
|
||||
EntityLoaderLoadPageArgs,
|
||||
EntityLoaderQuerySelectionModifiers,
|
||||
EntityLoaderRowLockingModifiers,
|
||||
EntityLoaderRowLockingModifiersWithoutSkipLocked,
|
||||
} from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import type { FieldEqualityCondition } from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder.ts';
|
||||
@@ -57,6 +60,140 @@ export class EnforcingKnexEntityLoader<
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Load an entity by ID directly from the database, bypassing the dataloader and cache.
|
||||
*
|
||||
* Unlike {@link "@expo/entity"!EnforcingEntityLoader.loadByIDAsync | EnforcingEntityLoader.loadByIDAsync}, this
|
||||
* issues one database query per call and does not read from or write to the entity cache. It exists
|
||||
* for cases that need row locking modifiers, which are required to make this intent explicit.
|
||||
* `skipLocked` is not permitted here since a skipped row would be reported as not found.
|
||||
* Use {@link loadByIDNullableFromDatabaseAsync} with `skipLocked`.
|
||||
*
|
||||
* @param id - ID of the entity
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns entity matching ID
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view the returned entity
|
||||
* @throws EntityNotFoundError when no entity exists for ID
|
||||
*/
|
||||
async loadByIDFromDatabaseAsync(
|
||||
id: TFields[TIDField],
|
||||
modifiers: EntityLoaderRowLockingModifiersWithoutSkipLocked,
|
||||
): Promise<TEntity> {
|
||||
const entityResult = await this.knexEntityLoader.loadByIDFromDatabaseAsync(id, modifiers);
|
||||
return entityResult.enforceValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an entity by ID directly from the database, or return null if non-existent.
|
||||
* See {@link loadByIDFromDatabaseAsync} for how this differs from the standard loader.
|
||||
*
|
||||
* @param id - ID of the entity
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns entity for matching ID, or null if no entity exists for ID
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view the returned entity
|
||||
*/
|
||||
async loadByIDNullableFromDatabaseAsync(
|
||||
id: TFields[TIDField],
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<TEntity | null> {
|
||||
const entityResult = await this.knexEntityLoader.loadByIDNullableFromDatabaseAsync(
|
||||
id,
|
||||
modifiers,
|
||||
);
|
||||
return entityResult ? entityResult.enforceValue() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many entities for a list of IDs directly from the database.
|
||||
* See {@link loadByIDFromDatabaseAsync} for how this differs from the standard loader.
|
||||
*
|
||||
* `skipLocked` is not permitted here since a skipped row would be reported as not found.
|
||||
* Use {@link loadManyByIDsNullableFromDatabaseAsync} with `skipLocked`.
|
||||
*
|
||||
* @param ids - IDs of the entities to load
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns map from ID to corresponding entity
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
* @throws EntityNotFoundError when no entity exists for one or more of the IDs
|
||||
*/
|
||||
async loadManyByIDsFromDatabaseAsync(
|
||||
ids: readonly TFields[TIDField][],
|
||||
modifiers: EntityLoaderRowLockingModifiersWithoutSkipLocked,
|
||||
): Promise<ReadonlyMap<TFields[TIDField], TEntity>> {
|
||||
const entityResults = await this.knexEntityLoader.loadManyByIDsFromDatabaseAsync(
|
||||
ids,
|
||||
modifiers,
|
||||
);
|
||||
return mapMap(entityResults, (entityResult) => entityResult.enforceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many entities for a list of IDs directly from the database, returning null for any IDs that are non-existent.
|
||||
* See {@link loadByIDFromDatabaseAsync} for how this differs from the standard loader.
|
||||
*
|
||||
* @param ids - IDs of the entities to load
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns map from ID to nullable corresponding entity
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
*/
|
||||
async loadManyByIDsNullableFromDatabaseAsync(
|
||||
ids: readonly TFields[TIDField][],
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<ReadonlyMap<TFields[TIDField], TEntity | null>> {
|
||||
const entityResults = await this.knexEntityLoader.loadManyByIDsNullableFromDatabaseAsync(
|
||||
ids,
|
||||
modifiers,
|
||||
);
|
||||
return mapMap(entityResults, (entityResult) => entityResult?.enforceValue() ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an entity where uniqueFieldName equals fieldValue directly from the database, or null if no entity matches.
|
||||
* See {@link loadByIDFromDatabaseAsync} for how this differs from the standard loader.
|
||||
*
|
||||
* @param uniqueFieldName - entity field being queried
|
||||
* @param fieldValue - uniqueFieldName field value being queried
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns entity where uniqueFieldName equals fieldValue, or null if no entity matches the condition
|
||||
* @throws when multiple entities match the condition
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view the returned entity
|
||||
*/
|
||||
async loadByFieldEqualingFromDatabaseAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
uniqueFieldName: N,
|
||||
fieldValue: NonNullable<TFields[N]>,
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<TEntity | null> {
|
||||
const entityResult = await this.knexEntityLoader.loadByFieldEqualingFromDatabaseAsync(
|
||||
uniqueFieldName,
|
||||
fieldValue,
|
||||
modifiers,
|
||||
);
|
||||
return entityResult ? entityResult.enforceValue() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load many entities where fieldName equals fieldValue directly from the database.
|
||||
* See {@link loadByIDFromDatabaseAsync} for how this differs from the standard loader.
|
||||
*
|
||||
* @param fieldName - entity field being queried
|
||||
* @param fieldValue - fieldName field value being queried
|
||||
* @param modifiers - row locking modifiers for the query
|
||||
* @returns array of entities where fieldName equals fieldValue
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
*/
|
||||
async loadManyByFieldEqualingFromDatabaseAsync<N extends keyof Pick<TFields, TSelectedFields>>(
|
||||
fieldName: N,
|
||||
fieldValue: NonNullable<TFields[N]>,
|
||||
modifiers: EntityLoaderRowLockingModifiers,
|
||||
): Promise<readonly TEntity[]> {
|
||||
const entityResults = await this.knexEntityLoader.loadManyByFieldEqualingFromDatabaseAsync(
|
||||
fieldName,
|
||||
fieldValue,
|
||||
modifiers,
|
||||
);
|
||||
return entityResults.map((entityResult) => entityResult.enforceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the first entity matching the conjunction of field equality operands and
|
||||
* query modifiers.
|
||||
|
||||
@@ -79,6 +79,8 @@ export class KnexEntityLoaderFactory<
|
||||
|
||||
return new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
this.entityCompanion.entityCompanionDefinition.entityConfiguration,
|
||||
this.entityCompanion.entityCompanionDefinition.entityClass,
|
||||
this.knexDataManager,
|
||||
this.metricsAdapter,
|
||||
constructionUtils,
|
||||
|
||||
@@ -116,7 +116,14 @@ export class PostgresEntityDatabaseAdapter<
|
||||
tableValue: tableTuple[index],
|
||||
})),
|
||||
[],
|
||||
{ limit: 1, orderBy: undefined, offset: undefined },
|
||||
{
|
||||
limit: 1,
|
||||
orderBy: undefined,
|
||||
offset: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: undefined,
|
||||
skipLocked: undefined,
|
||||
},
|
||||
);
|
||||
return results[0] ?? null;
|
||||
}
|
||||
@@ -125,7 +132,7 @@ export class PostgresEntityDatabaseAdapter<
|
||||
query: Knex.QueryBuilder,
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Knex.QueryBuilder {
|
||||
const { orderBy, offset, limit } = querySelectionModifiers;
|
||||
const { orderBy, offset, limit, forUpdate, forShare, skipLocked } = querySelectionModifiers;
|
||||
|
||||
let ret = query;
|
||||
|
||||
@@ -161,6 +168,18 @@ export class PostgresEntityDatabaseAdapter<
|
||||
ret = ret.limit(limit);
|
||||
}
|
||||
|
||||
if (forUpdate) {
|
||||
ret = ret.forUpdate();
|
||||
}
|
||||
|
||||
if (forShare) {
|
||||
ret = ret.forShare();
|
||||
}
|
||||
|
||||
if (skipLocked) {
|
||||
ret = ret.skipLocked();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+486
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
EntityDatabaseAdapterEmptyUpdateResultError,
|
||||
EntityNotFoundError,
|
||||
TransactionIsolationLevel,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
@@ -211,6 +212,491 @@ describe('postgres entity integration', () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe('row locking modifiers (forUpdate, forShare, skipLocked)', () => {
|
||||
// Attempts to lock the row from a separate connection without waiting. Postgres raises
|
||||
// lock_not_available (55P03) when another transaction already holds a conflicting lock on the row.
|
||||
const tryLockRowFromOtherConnectionAsync = async (
|
||||
id: string,
|
||||
lockMode: 'FOR UPDATE' | 'FOR SHARE' = 'FOR UPDATE',
|
||||
): Promise<string | null> => {
|
||||
try {
|
||||
await knexInstance.raw(
|
||||
`SELECT * FROM postgres_test_entities WHERE id = ? ${lockMode} NOWAIT`,
|
||||
[id],
|
||||
);
|
||||
return null;
|
||||
} catch (e) {
|
||||
return (e as any).code ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
it('locks rows loaded with loadManyByFieldEqualityConjunctionAsync until the transaction ends', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'locked')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
// not locked before the transaction
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBeNull();
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const results = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByFieldEqualityConjunctionAsync([{ fieldName: 'name', fieldValue: 'locked' }], {
|
||||
forUpdate: true,
|
||||
});
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0]!.getID()).toBe(entity.getID());
|
||||
|
||||
// locked while the transaction is open
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBe('55P03');
|
||||
});
|
||||
|
||||
// unlocked after the transaction commits
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBeNull();
|
||||
});
|
||||
|
||||
it('locks rows loaded with loadFirstByFieldEqualityConjunctionAsync', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'locked-first')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const result = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadFirstByFieldEqualityConjunctionAsync(
|
||||
[{ fieldName: 'name', fieldValue: 'locked-first' }],
|
||||
{
|
||||
orderBy: [{ fieldName: 'name', order: OrderByOrdering.ASCENDING }],
|
||||
forUpdate: true,
|
||||
},
|
||||
);
|
||||
expect(result?.getID()).toBe(entity.getID());
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBe('55P03');
|
||||
});
|
||||
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBeNull();
|
||||
});
|
||||
|
||||
it('locks rows loaded with the loadManyBySQL query builder', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'locked-sql')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
// via the fluent builder method
|
||||
const results = await PostgresTestEntity.knexLoader(vc1, queryContext)
|
||||
.loadManyBySQL(sql`name = ${'locked-sql'}`)
|
||||
.forUpdate()
|
||||
.executeAsync();
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0]!.getID()).toBe(entity.getID());
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBe('55P03');
|
||||
|
||||
// via the modifiers argument on the authorization-result-based loader
|
||||
const authorizationResults = await PostgresTestEntity.knexLoaderWithAuthorizationResults(
|
||||
vc1,
|
||||
queryContext,
|
||||
)
|
||||
.loadManyBySQL(sql`name = ${'locked-sql'}`, { forUpdate: true })
|
||||
.executeAsync();
|
||||
expect(authorizationResults).toHaveLength(1);
|
||||
expect(authorizationResults[0]!.enforceValue().getID()).toBe(entity.getID());
|
||||
});
|
||||
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBeNull();
|
||||
});
|
||||
|
||||
it('blocks a concurrent forUpdate load until the first transaction completes', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'counter')
|
||||
.setField('hasADog', false)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
const events: string[] = [];
|
||||
const lockAndUpdateAsync = async (label: string, holdDuration: number): Promise<void> => {
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync(
|
||||
'postgres',
|
||||
async (queryContext) => {
|
||||
const locked = await PostgresTestEntity.knexLoader(vc1, queryContext)
|
||||
.loadManyBySQL(sql`id = ${entity.getID()}`)
|
||||
.forUpdate()
|
||||
.executeAsync();
|
||||
events.push(`${label}:locked`);
|
||||
await setTimeout(holdDuration);
|
||||
await PostgresTestEntity.updater(locked[0]!, queryContext)
|
||||
.setField('name', locked[0]!.getField('name') + ',' + label)
|
||||
.updateAsync();
|
||||
events.push(`${label}:updated`);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
lockAndUpdateAsync('a', 200),
|
||||
setTimeout(50).then(() => lockAndUpdateAsync('b', 0)),
|
||||
]);
|
||||
|
||||
// b cannot acquire the lock until a commits, so a's update always lands before b locks
|
||||
expect(events).toEqual(['a:locked', 'a:updated', 'b:locked', 'b:updated']);
|
||||
|
||||
const reloaded = await PostgresTestEntity.loader(vc1).loadByIDAsync(entity.getID());
|
||||
expect(reloaded.getField('name')).toBe('counter,a,b');
|
||||
});
|
||||
|
||||
it('forShare allows concurrent share locks but blocks update locks', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'shared')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const results = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByFieldEqualityConjunctionAsync([{ fieldName: 'name', fieldValue: 'shared' }], {
|
||||
forShare: true,
|
||||
});
|
||||
expect(results).toHaveLength(1);
|
||||
|
||||
// another share lock is compatible, an update lock is not
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID(), 'FOR SHARE')).toBeNull();
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID(), 'FOR UPDATE')).toBe(
|
||||
'55P03',
|
||||
);
|
||||
|
||||
// via the fluent builder method
|
||||
const builderResults = await PostgresTestEntity.knexLoader(vc1, queryContext)
|
||||
.loadManyBySQL(sql`name = ${'shared'}`)
|
||||
.forShare()
|
||||
.executeAsync();
|
||||
expect(builderResults).toHaveLength(1);
|
||||
});
|
||||
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID(), 'FOR UPDATE')).toBeNull();
|
||||
});
|
||||
|
||||
it('skipLocked skips rows locked by another transaction', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entityA = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'queue')
|
||||
.createAsync(),
|
||||
);
|
||||
const entityB = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'queue')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync(
|
||||
'postgres',
|
||||
async (outerQueryContext) => {
|
||||
// lock entityA in the outer transaction
|
||||
const locked = await PostgresTestEntity.knexLoader(vc1, outerQueryContext)
|
||||
.loadManyBySQL(sql`id = ${entityA.getID()}`)
|
||||
.forUpdate()
|
||||
.executeAsync();
|
||||
expect(locked.map((e) => e.getID())).toEqual([entityA.getID()]);
|
||||
|
||||
// a second transaction on another connection sees only the unlocked row
|
||||
const vc2 = new ViewerContext(
|
||||
createKnexIntegrationTestEntityCompanionProvider(knexInstance),
|
||||
);
|
||||
await vc2.runInTransactionForDatabaseAdapterFlavorAsync(
|
||||
'postgres',
|
||||
async (innerQueryContext) => {
|
||||
const skipLockedResults = await PostgresTestEntity.knexLoader(
|
||||
vc2,
|
||||
innerQueryContext,
|
||||
).loadManyByFieldEqualityConjunctionAsync(
|
||||
[{ fieldName: 'name', fieldValue: 'queue' }],
|
||||
{ forUpdate: true, skipLocked: true },
|
||||
);
|
||||
expect(skipLockedResults.map((e) => e.getID())).toEqual([entityB.getID()]);
|
||||
|
||||
const builderResults = await PostgresTestEntity.knexLoader(vc2, innerQueryContext)
|
||||
.loadManyBySQL(sql`name = ${'queue'}`)
|
||||
.forShare()
|
||||
.skipLocked()
|
||||
.executeAsync();
|
||||
expect(builderResults.map((e) => e.getID())).toEqual([entityB.getID()]);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// both rows are visible once the outer transaction commits
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const results = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByFieldEqualityConjunctionAsync([{ fieldName: 'name', fieldValue: 'queue' }], {
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(results).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when forUpdate or forShare is used outside of a transaction', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1).loadManyByFieldEqualityConjunctionAsync([], {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1).loadManyByFieldEqualityConjunctionAsync([], {
|
||||
forShare: true,
|
||||
}),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1)
|
||||
.loadManyBySQL(sql`TRUE`)
|
||||
.forUpdate()
|
||||
.executeAsync(),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
});
|
||||
|
||||
it('throws for invalid row locking modifier combinations', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1, queryContext)
|
||||
.loadManyBySQL(sql`TRUE`)
|
||||
.forUpdate()
|
||||
.forShare()
|
||||
.executeAsync(),
|
||||
).rejects.toThrow('forUpdate and forShare are mutually exclusive');
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1, queryContext)
|
||||
.loadManyBySQL(sql`TRUE`)
|
||||
.skipLocked()
|
||||
.executeAsync(),
|
||||
).rejects.toThrow('skipLocked requires forUpdate or forShare');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('FromDatabase load methods', () => {
|
||||
const tryLockRowFromOtherConnectionAsync = async (id: string): Promise<string | null> => {
|
||||
try {
|
||||
await knexInstance.raw(
|
||||
'SELECT * FROM postgres_test_entities WHERE id = ? FOR UPDATE NOWAIT',
|
||||
[id],
|
||||
);
|
||||
return null;
|
||||
} catch (e) {
|
||||
return (e as any).code ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
it('loadByIDFromDatabaseAsync locks the row and throws EntityNotFoundError when missing', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entity = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'by-id')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const loaded = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadByIDFromDatabaseAsync(entity.getID(), { forUpdate: true });
|
||||
expect(loaded.getID()).toBe(entity.getID());
|
||||
expect(loaded.getField('name')).toBe('by-id');
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBe('55P03');
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1, queryContext).loadByIDFromDatabaseAsync(
|
||||
'00000000-0000-0000-0000-000000000000',
|
||||
{ forUpdate: true },
|
||||
),
|
||||
).rejects.toThrow(EntityNotFoundError);
|
||||
|
||||
const nullable = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadByIDNullableFromDatabaseAsync('00000000-0000-0000-0000-000000000000', {
|
||||
forUpdate: true,
|
||||
});
|
||||
expect(nullable).toBeNull();
|
||||
});
|
||||
|
||||
expect(await tryLockRowFromOtherConnectionAsync(entity.getID())).toBeNull();
|
||||
});
|
||||
|
||||
it('loadManyByIDsFromDatabaseAsync returns a map and throws for missing IDs', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entityA = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1).setField('name', 'a').createAsync(),
|
||||
);
|
||||
const entityB = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1).setField('name', 'b').createAsync(),
|
||||
);
|
||||
const missingId = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const loaded = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByIDsFromDatabaseAsync([entityA.getID(), entityB.getID()], { forShare: true });
|
||||
expect(loaded.size).toBe(2);
|
||||
expect(loaded.get(entityA.getID())!.getField('name')).toBe('a');
|
||||
expect(loaded.get(entityB.getID())!.getField('name')).toBe('b');
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1, queryContext).loadManyByIDsFromDatabaseAsync(
|
||||
[entityA.getID(), missingId],
|
||||
{ forShare: true },
|
||||
),
|
||||
).rejects.toThrow(EntityNotFoundError);
|
||||
|
||||
const nullable = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByIDsNullableFromDatabaseAsync([entityA.getID(), missingId], {
|
||||
forShare: true,
|
||||
});
|
||||
expect(nullable.size).toBe(2);
|
||||
expect(nullable.get(entityA.getID())!.getField('name')).toBe('a');
|
||||
expect(nullable.get(missingId)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('loadManyByIDsNullableFromDatabaseAsync with skipLocked returns null for locked rows', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const entityA = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1).setField('name', 'a').createAsync(),
|
||||
);
|
||||
const entityB = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1).setField('name', 'b').createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync(
|
||||
'postgres',
|
||||
async (outerQueryContext) => {
|
||||
await PostgresTestEntity.knexLoader(vc1, outerQueryContext).loadByIDFromDatabaseAsync(
|
||||
entityA.getID(),
|
||||
{ forUpdate: true },
|
||||
);
|
||||
|
||||
const vc2 = new ViewerContext(
|
||||
createKnexIntegrationTestEntityCompanionProvider(knexInstance),
|
||||
);
|
||||
await vc2.runInTransactionForDatabaseAdapterFlavorAsync(
|
||||
'postgres',
|
||||
async (innerQueryContext) => {
|
||||
const results = await PostgresTestEntity.knexLoader(
|
||||
vc2,
|
||||
innerQueryContext,
|
||||
).loadManyByIDsNullableFromDatabaseAsync([entityA.getID(), entityB.getID()], {
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(results.get(entityA.getID())).toBeNull();
|
||||
expect(results.get(entityB.getID())!.getField('name')).toBe('b');
|
||||
|
||||
// the throwing variants do not permit skipLocked since a skipped row would be reported as not found
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc2, innerQueryContext).loadByIDFromDatabaseAsync(
|
||||
entityB.getID(),
|
||||
// @ts-expect-error skipLocked is not permitted for throwing FromDatabase methods
|
||||
{ forUpdate: true, skipLocked: true },
|
||||
),
|
||||
).resolves.toBeDefined();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('loadByFieldEqualingFromDatabaseAsync and loadManyByFieldEqualingFromDatabaseAsync lock matching rows', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const unique = await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'unique')
|
||||
.createAsync(),
|
||||
);
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'dup')
|
||||
.createAsync(),
|
||||
);
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'dup')
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await vc1.runInTransactionForDatabaseAdapterFlavorAsync('postgres', async (queryContext) => {
|
||||
const loaded = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadByFieldEqualingFromDatabaseAsync('name', 'unique', { forUpdate: true });
|
||||
expect(loaded!.getID()).toBe(unique.getID());
|
||||
expect(await tryLockRowFromOtherConnectionAsync(unique.getID())).toBe('55P03');
|
||||
|
||||
const missing = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadByFieldEqualingFromDatabaseAsync('name', 'nope', { forUpdate: true });
|
||||
expect(missing).toBeNull();
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1, queryContext).loadByFieldEqualingFromDatabaseAsync(
|
||||
'name',
|
||||
'dup',
|
||||
{ forUpdate: true },
|
||||
),
|
||||
).rejects.toThrow('Multiple entities of type PostgresTestEntity found for name=dup');
|
||||
|
||||
const many = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
queryContext,
|
||||
).loadManyByFieldEqualingFromDatabaseAsync('name', 'dup', { forUpdate: true });
|
||||
expect(many).toHaveLength(2);
|
||||
for (const e of many) {
|
||||
expect(await tryLockRowFromOtherConnectionAsync(e.getID())).toBe('55P03');
|
||||
}
|
||||
});
|
||||
|
||||
expect(await tryLockRowFromOtherConnectionAsync(unique.getID())).toBeNull();
|
||||
});
|
||||
|
||||
it('FromDatabase methods require a transaction when a lock is requested', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1).loadByIDFromDatabaseAsync(
|
||||
'00000000-0000-0000-0000-000000000000',
|
||||
{ forUpdate: true },
|
||||
),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
});
|
||||
});
|
||||
|
||||
describe('JSON fields', () => {
|
||||
it('supports both types of array fields', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
+353
-2
@@ -3,9 +3,14 @@ import type {
|
||||
EntityQueryContext,
|
||||
IEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import { enforceResultsAsync, EntityConstructionUtils, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
enforceResultsAsync,
|
||||
EntityConstructionUtils,
|
||||
EntityNotFoundError,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { anyOfClass, anything, instance, mock, spy, verify, when } from 'ts-mockito';
|
||||
import { anyOfClass, anything, deepEqual, instance, mock, spy, verify, when } from 'ts-mockito';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
@@ -87,6 +92,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
);
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -170,6 +177,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
);
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -263,6 +272,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -344,6 +355,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -430,6 +443,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -545,6 +560,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -631,6 +648,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -731,6 +750,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -825,6 +846,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -916,6 +939,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -980,6 +1005,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -1067,6 +1094,8 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
@@ -1087,4 +1116,326 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
expect(connection.pageInfo.endCursor).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('FromDatabase load methods', () => {
|
||||
const makeFieldObject = (id: string, testIndexedField: string): TestFields => ({
|
||||
customIdField: id,
|
||||
stringField: 'huh',
|
||||
intField: 4,
|
||||
testIndexedField,
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
});
|
||||
|
||||
const setup = (): {
|
||||
knexEntityLoader: AuthorizationResultBasedKnexEntityLoader<
|
||||
TestFields,
|
||||
'customIdField',
|
||||
ViewerContext,
|
||||
TestEntity,
|
||||
TestEntityPrivacyPolicy,
|
||||
keyof TestFields
|
||||
>;
|
||||
knexDataManagerMock: EntityKnexDataManager<TestFields, 'customIdField'>;
|
||||
queryContext: EntityQueryContext;
|
||||
} => {
|
||||
const privacyPolicy = new TestEntityPrivacyPolicy();
|
||||
const viewerContext = instance(mock(ViewerContext));
|
||||
const privacyPolicyEvaluationContext =
|
||||
instance(
|
||||
mock<
|
||||
EntityPrivacyPolicyEvaluationContext<
|
||||
TestFields,
|
||||
'customIdField',
|
||||
ViewerContext,
|
||||
TestEntity
|
||||
>
|
||||
>(),
|
||||
);
|
||||
const metricsAdapter = instance(mock<IEntityMetricsAdapter>());
|
||||
const queryContext = instance(mock<EntityQueryContext>());
|
||||
const knexDataManagerMock =
|
||||
mock<EntityKnexDataManager<TestFields, 'customIdField'>>(EntityKnexDataManager);
|
||||
const constructionUtils = new EntityConstructionUtils(
|
||||
viewerContext,
|
||||
queryContext,
|
||||
privacyPolicyEvaluationContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
/* entitySelectedFields */ undefined,
|
||||
privacyPolicy,
|
||||
metricsAdapter,
|
||||
);
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
instance(knexDataManagerMock),
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
);
|
||||
return { knexEntityLoader, knexDataManagerMock, queryContext };
|
||||
};
|
||||
|
||||
it('loads entities with loadManyByIDsNullableFromDatabaseAsync', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const id2 = uuidv4();
|
||||
const missingId = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1'), makeFieldObject(id2, '2')]);
|
||||
|
||||
const results = await knexEntityLoader.loadManyByIDsNullableFromDatabaseAsync(
|
||||
[id1, id2, missingId],
|
||||
{ forUpdate: true },
|
||||
);
|
||||
expect(results.size).toBe(3);
|
||||
expect(results.get(id1)!.enforceValue().getID()).toBe(id1);
|
||||
expect(results.get(id2)!.enforceValue().getID()).toBe(id2);
|
||||
expect(results.get(missingId)).toBeNull();
|
||||
|
||||
verify(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'customIdField', fieldValues: [id1, id2, missingId] }]),
|
||||
deepEqual({ forUpdate: true }),
|
||||
),
|
||||
).once();
|
||||
});
|
||||
|
||||
it('returns an empty map and does not query for an empty list of IDs', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock } = setup();
|
||||
const results = await knexEntityLoader.loadManyByIDsNullableFromDatabaseAsync([], {
|
||||
forUpdate: true,
|
||||
});
|
||||
expect(results.size).toBe(0);
|
||||
verify(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).never();
|
||||
});
|
||||
|
||||
it('returns EntityNotFoundError results for missing IDs with loadManyByIDsFromDatabaseAsync', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const missingId = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1')]);
|
||||
|
||||
const results = await knexEntityLoader.loadManyByIDsFromDatabaseAsync([id1, missingId], {
|
||||
forShare: true,
|
||||
});
|
||||
expect(results.size).toBe(2);
|
||||
expect(results.get(id1)!.ok).toBe(true);
|
||||
const missingResult = results.get(missingId)!;
|
||||
expect(missingResult.ok).toBe(false);
|
||||
expect(missingResult.enforceError()).toBeInstanceOf(EntityNotFoundError);
|
||||
});
|
||||
|
||||
it('loads an entity with loadByIDFromDatabaseAsync', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const missingId = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'customIdField', fieldValues: [id1] }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1')]);
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'customIdField', fieldValues: [missingId] }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([]);
|
||||
|
||||
const found = await knexEntityLoader.loadByIDFromDatabaseAsync(id1, { forUpdate: true });
|
||||
expect(found.enforceValue().getID()).toBe(id1);
|
||||
|
||||
const missing = await knexEntityLoader.loadByIDFromDatabaseAsync(missingId, {
|
||||
forUpdate: true,
|
||||
});
|
||||
expect(missing.ok).toBe(false);
|
||||
expect(missing.enforceError()).toBeInstanceOf(EntityNotFoundError);
|
||||
});
|
||||
|
||||
it('loads an entity or null with loadByIDNullableFromDatabaseAsync', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const missingId = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'customIdField', fieldValues: [id1] }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1')]);
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'customIdField', fieldValues: [missingId] }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([]);
|
||||
|
||||
const found = await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, {
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(found!.enforceValue().getID()).toBe(id1);
|
||||
|
||||
const missing = await knexEntityLoader.loadByIDNullableFromDatabaseAsync(missingId, {
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(missing).toBeNull();
|
||||
});
|
||||
|
||||
it('requires exactly one lock mode at the type level', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1')]);
|
||||
|
||||
// valid: exactly one lock mode, optional skipLocked on nullable variants
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, { forUpdate: true });
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, { forShare: true });
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, {
|
||||
forShare: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
await knexEntityLoader.loadByIDFromDatabaseAsync(id1, { forUpdate: true });
|
||||
|
||||
// @ts-expect-error a lock mode is required
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, {});
|
||||
// @ts-expect-error skipLocked alone is not a lock mode
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, { skipLocked: true });
|
||||
// @ts-expect-error forUpdate must be true
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, { forUpdate: false });
|
||||
await knexEntityLoader.loadByIDNullableFromDatabaseAsync(id1, {
|
||||
forUpdate: true,
|
||||
// @ts-expect-error forUpdate and forShare are mutually exclusive
|
||||
forShare: true,
|
||||
});
|
||||
// @ts-expect-error skipLocked is not permitted on throwing variants
|
||||
await knexEntityLoader.loadByIDFromDatabaseAsync(id1, { forUpdate: true, skipLocked: true });
|
||||
await knexEntityLoader.loadManyByIDsFromDatabaseAsync([id1], {
|
||||
forShare: true,
|
||||
// @ts-expect-error skipLocked is not permitted on throwing variants
|
||||
skipLocked: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('validates ID values for FromDatabase ID loads', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock } = setup();
|
||||
await expect(
|
||||
knexEntityLoader.loadByIDFromDatabaseAsync('not-a-uuid', { forUpdate: true }),
|
||||
).rejects.toThrow('Entity field not valid: TestEntity (customIdField = not-a-uuid)');
|
||||
verify(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).never();
|
||||
});
|
||||
|
||||
it('loads entities with loadManyByFieldEqualingFromDatabaseAsync', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const id2 = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, '1'), makeFieldObject(id2, '2')]);
|
||||
|
||||
const results = await knexEntityLoader.loadManyByFieldEqualingFromDatabaseAsync(
|
||||
'stringField',
|
||||
'huh',
|
||||
{ forUpdate: true },
|
||||
);
|
||||
expect(results).toHaveLength(2);
|
||||
expect(results.map((r) => r.enforceValue().getID())).toEqual([id1, id2]);
|
||||
|
||||
verify(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'stringField', fieldValue: 'huh' }]),
|
||||
deepEqual({ forUpdate: true }),
|
||||
),
|
||||
).once();
|
||||
});
|
||||
|
||||
it('loads an entity or null with loadByFieldEqualingFromDatabaseAsync and throws on multiple matches', async () => {
|
||||
const { knexEntityLoader, knexDataManagerMock, queryContext } = setup();
|
||||
const id1 = uuidv4();
|
||||
const id2 = uuidv4();
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'testIndexedField', fieldValue: 'one' }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, 'one')]);
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'testIndexedField', fieldValue: 'none' }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([]);
|
||||
when(
|
||||
knexDataManagerMock.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
deepEqual([{ fieldName: 'testIndexedField', fieldValue: 'many' }]),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([makeFieldObject(id1, 'many'), makeFieldObject(id2, 'many')]);
|
||||
|
||||
const found = await knexEntityLoader.loadByFieldEqualingFromDatabaseAsync(
|
||||
'testIndexedField',
|
||||
'one',
|
||||
{ forShare: true },
|
||||
);
|
||||
expect(found!.enforceValue().getID()).toBe(id1);
|
||||
|
||||
const missing = await knexEntityLoader.loadByFieldEqualingFromDatabaseAsync(
|
||||
'testIndexedField',
|
||||
'none',
|
||||
{ forShare: true },
|
||||
);
|
||||
expect(missing).toBeNull();
|
||||
|
||||
await expect(
|
||||
knexEntityLoader.loadByFieldEqualingFromDatabaseAsync('testIndexedField', 'many', {
|
||||
forShare: true,
|
||||
}),
|
||||
).rejects.toThrow(
|
||||
'loadByFieldEqualingFromDatabase: Multiple entities of type TestEntity found for testIndexedField=many',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
+70
@@ -6,8 +6,10 @@ import { instance, mock } from 'ts-mockito';
|
||||
import type {
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
TableQuerySelectionModifiers,
|
||||
} from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { BasePostgresEntityDatabaseAdapter } from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { sql } from '../SQLOperator.ts';
|
||||
import type { TestFields } from './fixtures/TestEntity.ts';
|
||||
import { testEntityConfiguration } from './fixtures/TestEntity.ts';
|
||||
|
||||
@@ -22,6 +24,12 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
private readonly fetchEqualityConditionResults: object[];
|
||||
private readonly fetchSQLFragmentResults: object[];
|
||||
private readonly deleteCount: number;
|
||||
public lastEqualityConditionQuerySelectionModifiers:
|
||||
| TableQuerySelectionModifiers<TestFields>
|
||||
| undefined;
|
||||
public lastSQLFragmentQuerySelectionModifiers:
|
||||
| TableQuerySelectionModifiers<TestFields>
|
||||
| undefined;
|
||||
|
||||
constructor({
|
||||
fetchResults = [],
|
||||
@@ -76,7 +84,9 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
_sqlFragment: any,
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TestFields>,
|
||||
): Promise<object[]> {
|
||||
this.lastSQLFragmentQuerySelectionModifiers = querySelectionModifiers;
|
||||
return this.fetchSQLFragmentResults;
|
||||
}
|
||||
|
||||
@@ -85,7 +95,9 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
_tableName: string,
|
||||
_tableFieldSingleValueEqualityOperands: TableFieldSingleValueEqualityCondition[],
|
||||
_tableFieldMultiValueEqualityOperands: TableFieldMultiValueEqualityCondition[],
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TestFields>,
|
||||
): Promise<object[]> {
|
||||
this.lastEqualityConditionQuerySelectionModifiers = querySelectionModifiers;
|
||||
return this.fetchEqualityConditionResults;
|
||||
}
|
||||
|
||||
@@ -151,5 +163,63 @@ describe(BasePostgresEntityDatabaseAdapter, () => {
|
||||
const results = await adapter.fetchManyByFieldEqualityConjunctionAsync(queryContext, [], {});
|
||||
expect(results).toEqual([{ stringField: 'hello' }]);
|
||||
});
|
||||
|
||||
it('converts query selection modifiers including row locking modifiers', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
const adapter = new TestEntityDatabaseAdapter({});
|
||||
await adapter.fetchManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
limit: 2,
|
||||
offset: 1,
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(adapter.lastEqualityConditionQuerySelectionModifiers).toEqual({
|
||||
orderBy: undefined,
|
||||
limit: 2,
|
||||
offset: 1,
|
||||
forUpdate: true,
|
||||
forShare: undefined,
|
||||
skipLocked: true,
|
||||
});
|
||||
|
||||
await adapter.fetchManyByFieldEqualityConjunctionAsync(queryContext, [], { forShare: true });
|
||||
expect(adapter.lastEqualityConditionQuerySelectionModifiers).toEqual({
|
||||
orderBy: undefined,
|
||||
limit: undefined,
|
||||
offset: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: true,
|
||||
skipLocked: undefined,
|
||||
});
|
||||
|
||||
await adapter.fetchManyByFieldEqualityConjunctionAsync(queryContext, [], {});
|
||||
expect(adapter.lastEqualityConditionQuerySelectionModifiers).toEqual({
|
||||
orderBy: undefined,
|
||||
limit: undefined,
|
||||
offset: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: undefined,
|
||||
skipLocked: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchManyBySQLFragmentAsync', () => {
|
||||
it('converts query selection modifiers including row locking modifiers', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
const adapter = new TestEntityDatabaseAdapter({});
|
||||
await adapter.fetchManyBySQLFragmentAsync(queryContext, sql`TRUE`, {
|
||||
forShare: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
expect(adapter.lastSQLFragmentQuerySelectionModifiers).toEqual({
|
||||
orderBy: undefined,
|
||||
limit: undefined,
|
||||
offset: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+289
-1
@@ -2,7 +2,7 @@ import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityConstructionUtils, EntityQueryContext } from '@expo/entity';
|
||||
import { result } from '@expo/results';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { anything, instance, mock, when } from 'ts-mockito';
|
||||
import { anything, deepEqual, instance, mock, when } from 'ts-mockito';
|
||||
|
||||
import {
|
||||
AuthorizationResultBasedKnexEntityLoader,
|
||||
@@ -198,6 +198,294 @@ describe(EnforcingKnexEntityLoader, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('FromDatabase load methods', () => {
|
||||
const makeLoader = (
|
||||
nonEnforcingKnexEntityLoaderMock: AuthorizationResultBasedKnexEntityLoader<
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any,
|
||||
any
|
||||
>,
|
||||
): EnforcingKnexEntityLoader<any, any, any, any, any, any> =>
|
||||
new EnforcingKnexEntityLoader(
|
||||
instance(nonEnforcingKnexEntityLoaderMock),
|
||||
instance(mock(EntityQueryContext)),
|
||||
instance(mock(EntityKnexDataManager)),
|
||||
instance(mock<IEntityMetricsAdapter>()),
|
||||
instance(mock(EntityConstructionUtils)),
|
||||
);
|
||||
|
||||
describe('loadByIDFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByIDFromDatabaseAsync(anything(), anything()),
|
||||
).thenResolve(result(rejection));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByIDFromDatabaseAsync('id', { forUpdate: true }),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns value when result is successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByIDFromDatabaseAsync(
|
||||
'id',
|
||||
deepEqual({ forUpdate: true }),
|
||||
),
|
||||
).thenResolve(result(resolved));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByIDFromDatabaseAsync('id', { forUpdate: true }),
|
||||
).resolves.toEqual(resolved);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadByIDNullableFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByIDNullableFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(result(rejection));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByIDNullableFromDatabaseAsync('id', { forUpdate: true }),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns value when result is successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByIDNullableFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(result(resolved));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByIDNullableFromDatabaseAsync('id', { forUpdate: true }),
|
||||
).resolves.toEqual(resolved);
|
||||
});
|
||||
|
||||
it('returns null when result is null', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByIDNullableFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(null);
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByIDNullableFromDatabaseAsync('id', { forUpdate: true }),
|
||||
).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyByIDsFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByIDsFromDatabaseAsync(anything(), anything()),
|
||||
).thenResolve(new Map([['id', result(rejection)]]));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByIDsFromDatabaseAsync(['id'], { forUpdate: true }),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns value when result is successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByIDsFromDatabaseAsync(anything(), anything()),
|
||||
).thenResolve(new Map([['id', result(resolved)]]));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByIDsFromDatabaseAsync(['id'], { forUpdate: true }),
|
||||
).resolves.toEqual(new Map([['id', resolved]]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyByIDsNullableFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByIDsNullableFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(new Map([['id', result(rejection)]]));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByIDsNullableFromDatabaseAsync(['id'], {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns values and nulls when results are successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByIDsNullableFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(
|
||||
new Map([
|
||||
['id', result(resolved)],
|
||||
['missing', null],
|
||||
]),
|
||||
);
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByIDsNullableFromDatabaseAsync(['id', 'missing'], {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).resolves.toEqual(
|
||||
new Map([
|
||||
['id', resolved],
|
||||
['missing', null],
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadByFieldEqualingFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByFieldEqualingFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(result(rejection));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByFieldEqualingFromDatabaseAsync('field', 'value', {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns value when result is successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByFieldEqualingFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(result(resolved));
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByFieldEqualingFromDatabaseAsync('field', 'value', {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).resolves.toEqual(resolved);
|
||||
});
|
||||
|
||||
it('returns null when result is null', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadByFieldEqualingFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve(null);
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadByFieldEqualingFromDatabaseAsync('field', 'value', {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).resolves.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyByFieldEqualingFromDatabaseAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByFieldEqualingFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([result(rejection)]);
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByFieldEqualingFromDatabaseAsync('field', 'value', {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow(rejection);
|
||||
});
|
||||
|
||||
it('returns values when results are successful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const resolved = {};
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByFieldEqualingFromDatabaseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([result(resolved)]);
|
||||
const enforcingKnexEntityLoader = makeLoader(nonEnforcingKnexEntityLoaderMock);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByFieldEqualingFromDatabaseAsync('field', 'value', {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).resolves.toEqual([resolved]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadPageAsync', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
|
||||
+8
-1
@@ -213,7 +213,14 @@ export class StubPostgresDatabaseAdapter<
|
||||
tableName,
|
||||
tableFieldSingleValueEqualityOperands,
|
||||
tableFieldMultiValueEqualityOperands,
|
||||
{ orderBy: undefined, offset: undefined, limit: undefined },
|
||||
{
|
||||
orderBy: undefined,
|
||||
offset: undefined,
|
||||
limit: undefined,
|
||||
forUpdate: undefined,
|
||||
forShare: undefined,
|
||||
skipLocked: undefined,
|
||||
},
|
||||
);
|
||||
return results.length;
|
||||
}
|
||||
|
||||
+18
@@ -1,8 +1,26 @@
|
||||
import { EntityDatabaseAdapterTransientError, EntityErrorState } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { wrapNativePostgresCallAsync } from '../wrapNativePostgresCallAsync.ts';
|
||||
|
||||
describe(wrapNativePostgresCallAsync, () => {
|
||||
it('classifies a PostgreSQL lock timeout as transient and preserves the cause', async () => {
|
||||
const error = Object.assign(new Error('canceling statement due to lock timeout'), {
|
||||
code: '55P03',
|
||||
});
|
||||
const result = wrapNativePostgresCallAsync(async () => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
await expect(result).rejects.toBeInstanceOf(EntityDatabaseAdapterTransientError);
|
||||
await expect(result).rejects.toMatchObject({
|
||||
state: EntityErrorState.TRANSIENT,
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
cause: error,
|
||||
});
|
||||
});
|
||||
|
||||
it('rethrows literals', async () => {
|
||||
const throwingFn = async (): Promise<void> => {
|
||||
// eslint-disable-next-line no-throw-literal,@typescript-eslint/only-throw-error
|
||||
|
||||
@@ -38,6 +38,8 @@ function translatePostgresError(
|
||||
return new EntityDatabaseAdapterCheckConstraintError(error.message, error);
|
||||
case '23P01':
|
||||
return new EntityDatabaseAdapterExclusionConstraintError(error.message, error);
|
||||
case '55P03':
|
||||
return new EntityDatabaseAdapterTransientError(error.message, error);
|
||||
default:
|
||||
return new EntityDatabaseAdapterUnknownError(error.message, error);
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ export class EntityKnexDataManager<
|
||||
querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>,
|
||||
): Promise<readonly Readonly<TFields>[]> {
|
||||
EntityKnexDataManager.validateOrderByClauses(querySelectionModifiers.orderBy);
|
||||
EntityKnexDataManager.validateRowLockingModifiers(queryContext, querySelectionModifiers);
|
||||
|
||||
return await timeAndLogLoadEventAsync(
|
||||
this.metricsAdapter,
|
||||
@@ -215,6 +216,7 @@ export class EntityKnexDataManager<
|
||||
querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>,
|
||||
): Promise<readonly Readonly<TFields>[]> {
|
||||
EntityKnexDataManager.validateOrderByClauses(querySelectionModifiers.orderBy);
|
||||
EntityKnexDataManager.validateRowLockingModifiers(queryContext, querySelectionModifiers);
|
||||
|
||||
return await timeAndLogLoadEventAsync(
|
||||
this.metricsAdapter,
|
||||
@@ -531,6 +533,30 @@ export class EntityKnexDataManager<
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates row locking modifiers (forUpdate, forShare, skipLocked).
|
||||
*
|
||||
* `SELECT ... FOR UPDATE` and `SELECT ... FOR SHARE` row locks are released at the end of the
|
||||
* transaction. Outside of a transaction the lock is released as soon as the statement completes,
|
||||
* which makes it useless, so require a transactional query context. FOR UPDATE and FOR SHARE
|
||||
* cannot be combined in a single statement, and SKIP LOCKED is only valid with a row lock.
|
||||
*/
|
||||
private static validateRowLockingModifiers<TFields extends Record<string, any>>(
|
||||
queryContext: EntityQueryContext,
|
||||
querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>,
|
||||
): void {
|
||||
const { forUpdate, forShare, skipLocked } = querySelectionModifiers;
|
||||
if (!forUpdate && !forShare) {
|
||||
assert(!skipLocked, 'skipLocked requires forUpdate or forShare.');
|
||||
return;
|
||||
}
|
||||
assert(!(forUpdate && forShare), 'forUpdate and forShare are mutually exclusive.');
|
||||
assert(
|
||||
queryContext.isInTransaction(),
|
||||
'forUpdate and forShare require a transactional query context since row locks are released at the end of the transaction.',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cursor-based pagination uses Postgres tuple comparison (e.g., (a, b) \> (x, y)) which
|
||||
* applies a single comparison direction to all columns. Mixed ordering directions would
|
||||
|
||||
+274
@@ -7,6 +7,7 @@ import { anyNumber, anything, deepEqual, instance, mock, verify, when } from 'ts
|
||||
import { OrderByOrdering } from '../../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { PaginationStrategy } from '../../PaginationStrategy.ts';
|
||||
import { PostgresEntityDatabaseAdapter } from '../../PostgresEntityDatabaseAdapter.ts';
|
||||
import { sql } from '../../SQLOperator.ts';
|
||||
import type { TestFields } from '../../__tests__/fixtures/TestEntity.ts';
|
||||
import { TestEntity, testEntityConfiguration } from '../../__tests__/fixtures/TestEntity.ts';
|
||||
import { EntityKnexDataManager } from '../EntityKnexDataManager.ts';
|
||||
@@ -193,6 +194,279 @@ describe(EntityKnexDataManager, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('row locking modifiers', () => {
|
||||
const fieldObject = {
|
||||
customIdField: '1',
|
||||
testIndexedField: 'unique1',
|
||||
stringField: 'hello',
|
||||
intField: 1,
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
};
|
||||
|
||||
it('throws when loading by field equality conjunction outside of a transaction', async () => {
|
||||
const queryContext = new StubQueryContextProvider().getQueryContext();
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await expect(
|
||||
entityDataManager.loadManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).never();
|
||||
});
|
||||
|
||||
it('throws when loading by SQL fragment outside of a transaction', async () => {
|
||||
const queryContext = new StubQueryContextProvider().getQueryContext();
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await expect(
|
||||
entityDataManager.loadManyBySQLFragmentAsync(queryContext, sql`TRUE`, {
|
||||
forUpdate: true,
|
||||
}),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(anything(), anything(), anything()),
|
||||
).never();
|
||||
});
|
||||
|
||||
it('passes forUpdate through to the database adapter inside of a transaction', async () => {
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
when(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([fieldObject]);
|
||||
when(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(anything(), anything(), anything()),
|
||||
).thenResolve([fieldObject]);
|
||||
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await new StubQueryContextProvider().runInTransactionAsync(async (queryContext) => {
|
||||
const equalityResults = await entityDataManager.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
[{ fieldName: 'stringField', fieldValue: 'hello' }],
|
||||
{ forUpdate: true, limit: 1 },
|
||||
);
|
||||
expect(equalityResults).toHaveLength(1);
|
||||
|
||||
const sqlResults = await entityDataManager.loadManyBySQLFragmentAsync(
|
||||
queryContext,
|
||||
sql`TRUE`,
|
||||
{ forUpdate: true },
|
||||
);
|
||||
expect(sqlResults).toHaveLength(1);
|
||||
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
deepEqual({ forUpdate: true, limit: 1 }),
|
||||
),
|
||||
).once();
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
deepEqual({ forUpdate: true }),
|
||||
),
|
||||
).once();
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when forShare is used outside of a transaction', async () => {
|
||||
const queryContext = new StubQueryContextProvider().getQueryContext();
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await expect(
|
||||
entityDataManager.loadManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
forShare: true,
|
||||
}),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
await expect(
|
||||
entityDataManager.loadManyBySQLFragmentAsync(queryContext, sql`TRUE`, { forShare: true }),
|
||||
).rejects.toThrow('require a transactional query context');
|
||||
});
|
||||
|
||||
it('throws when forUpdate and forShare are both set', async () => {
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await new StubQueryContextProvider().runInTransactionAsync(async (queryContext) => {
|
||||
await expect(
|
||||
entityDataManager.loadManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
forUpdate: true,
|
||||
forShare: true,
|
||||
}),
|
||||
).rejects.toThrow('forUpdate and forShare are mutually exclusive');
|
||||
await expect(
|
||||
entityDataManager.loadManyBySQLFragmentAsync(queryContext, sql`TRUE`, {
|
||||
forUpdate: true,
|
||||
forShare: true,
|
||||
}),
|
||||
).rejects.toThrow('forUpdate and forShare are mutually exclusive');
|
||||
});
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).never();
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(anything(), anything(), anything()),
|
||||
).never();
|
||||
});
|
||||
|
||||
it('throws when skipLocked is set without forUpdate or forShare', async () => {
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await new StubQueryContextProvider().runInTransactionAsync(async (queryContext) => {
|
||||
await expect(
|
||||
entityDataManager.loadManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
skipLocked: true,
|
||||
}),
|
||||
).rejects.toThrow('skipLocked requires forUpdate or forShare');
|
||||
await expect(
|
||||
entityDataManager.loadManyBySQLFragmentAsync(queryContext, sql`TRUE`, {
|
||||
skipLocked: true,
|
||||
}),
|
||||
).rejects.toThrow('skipLocked requires forUpdate or forShare');
|
||||
});
|
||||
});
|
||||
|
||||
it('passes forShare and skipLocked through to the database adapter inside of a transaction', async () => {
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
when(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([fieldObject]);
|
||||
when(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(anything(), anything(), anything()),
|
||||
).thenResolve([fieldObject]);
|
||||
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
await new StubQueryContextProvider().runInTransactionAsync(async (queryContext) => {
|
||||
await entityDataManager.loadManyByFieldEqualityConjunctionAsync(queryContext, [], {
|
||||
forShare: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
await entityDataManager.loadManyBySQLFragmentAsync(queryContext, sql`TRUE`, {
|
||||
forUpdate: true,
|
||||
skipLocked: true,
|
||||
});
|
||||
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
deepEqual({ forShare: true, skipLocked: true }),
|
||||
),
|
||||
).once();
|
||||
verify(
|
||||
databaseAdapterMock.fetchManyBySQLFragmentAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
deepEqual({ forUpdate: true, skipLocked: true }),
|
||||
),
|
||||
).once();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not require a transaction when no row locking modifier is set', async () => {
|
||||
const queryContext = new StubQueryContextProvider().getQueryContext();
|
||||
const databaseAdapterMock = mock<PostgresEntityDatabaseAdapter<TestFields, 'customIdField'>>(
|
||||
PostgresEntityDatabaseAdapter,
|
||||
);
|
||||
when(
|
||||
databaseAdapterMock.fetchManyByFieldEqualityConjunctionAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([fieldObject]);
|
||||
const entityDataManager = new EntityKnexDataManager(
|
||||
testEntityConfiguration,
|
||||
instance(databaseAdapterMock),
|
||||
new NoOpEntityMetricsAdapter(),
|
||||
TestEntity.name,
|
||||
);
|
||||
|
||||
const results = await entityDataManager.loadManyByFieldEqualityConjunctionAsync(
|
||||
queryContext,
|
||||
[],
|
||||
{ forUpdate: false, forShare: false, skipLocked: false },
|
||||
);
|
||||
expect(results).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('pagination', () => {
|
||||
describe('max page size validation', () => {
|
||||
it('should throw when first exceeds maxPageSize', async () => {
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-example
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-example
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-example
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-example",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"private": true,
|
||||
"description": "An example integration of the @expo/entity framework",
|
||||
"keywords": [
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-full-integration-tests
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-full-integration-tests
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-full-integration-tests
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-full-integration-tests",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"private": true,
|
||||
"description": "Full redis and knex integration tests for the entity framework",
|
||||
"keywords": [
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-ip-address-field
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-ip-address-field
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-ip-address-field
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-ip-address-field",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "IP address EntityField definitions for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-local-memory
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**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.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Local memory secondary cache for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-secondary-cache-redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-secondary-cache-redis",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "Redis secondary cache for @expo/entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
|
||||
@@ -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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-testing-utils
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-testing-utils
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-testing-utils
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-testing-utils",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "A package containing utilities for testing applications that use Entity",
|
||||
"keywords": [
|
||||
"entity"
|
||||
@@ -32,7 +32,7 @@
|
||||
"devDependencies": {
|
||||
"@jest/globals": "30.5.1",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "24.13.4",
|
||||
"@types/node": "24.19.1",
|
||||
"typescript": "6.0.3"
|
||||
},
|
||||
"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.69.0](https://github.com/expo/entity/compare/v0.68.0...v0.69.0) (2026-09-29)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity
|
||||
|
||||
# [0.68.0](https://github.com/expo/entity/compare/v0.67.0...v0.68.0) (2026-09-25)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity
|
||||
|
||||
# [0.67.0](https://github.com/expo/entity/compare/v0.66.0...v0.67.0) (2026-09-18)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity",
|
||||
"version": "0.67.0",
|
||||
"version": "0.69.0",
|
||||
"description": "A privacy-first data model",
|
||||
"keywords": [
|
||||
"entity"
|
||||
@@ -33,7 +33,7 @@
|
||||
"@jest/globals": "30.5.1",
|
||||
"@types/invariant": "2.2.37",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/node": "24.13.4",
|
||||
"@types/node": "24.19.1",
|
||||
"lodash-es": "4.18.1",
|
||||
"ts-mockito": "2.6.1",
|
||||
"typescript": "6.0.3",
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
version: '2'
|
||||
services:
|
||||
redis:
|
||||
image: redis@sha256:298e5b3bc566bade82f46ad5511777a4a07a294097ce16ada2f6a42be5239df5
|
||||
image: redis@sha256:6f81e8915c60b065a524e6967e0ad1c639ba6efa84d669f823683ea04d9150ee
|
||||
ports:
|
||||
- '${REDIS_PORT}:6379'
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
postgres:
|
||||
image: postgres:18@sha256:4ef4dbc939d61acea57712655ddb4b4ab27419c913f94cca0cd57cb3ea3c2280
|
||||
image: postgres:18@sha256:5a5a84b19854a9ffaa54082c166ff4ec27473a361e496e5ea167f298f2da9722
|
||||
ports:
|
||||
- '${PGPORT}:5432'
|
||||
volumes:
|
||||
|
||||
@@ -890,7 +890,7 @@ __metadata:
|
||||
dependencies:
|
||||
"@jest/globals": "npm:30.5.1"
|
||||
"@types/jscodeshift": "npm:17.3.0"
|
||||
"@types/node": "npm:24.13.4"
|
||||
"@types/node": "npm:24.19.1"
|
||||
jscodeshift: "npm:17.4.0"
|
||||
typescript: "npm:6.0.3"
|
||||
languageName: unknown
|
||||
@@ -904,7 +904,7 @@ __metadata:
|
||||
"@expo/entity-database-adapter-knex": "workspace:^"
|
||||
"@jest/globals": "npm:30.5.1"
|
||||
"@types/invariant": "npm:2.2.37"
|
||||
"@types/node": "npm:24.13.4"
|
||||
"@types/node": "npm:24.19.1"
|
||||
invariant: "npm:^2.2.4"
|
||||
typescript: "npm:6.0.3"
|
||||
uuid: "npm:^14.0.0"
|
||||
@@ -921,7 +921,7 @@ __metadata:
|
||||
"@expo/entity-testing-utils": "workspace:^"
|
||||
"@jest/globals": "npm:30.5.1"
|
||||
knex: "npm:^3.2.9"
|
||||
pg: "npm:8.23.0"
|
||||
pg: "npm:8.23.1"
|
||||
ts-mockito: "npm:2.6.1"
|
||||
typescript: "npm:6.0.3"
|
||||
languageName: unknown
|
||||
@@ -1007,7 +1007,7 @@ __metadata:
|
||||
"@expo/entity": "workspace:^"
|
||||
"@jest/globals": "npm:30.5.1"
|
||||
"@types/lodash-es": "npm:4.17.12"
|
||||
"@types/node": "npm:24.13.4"
|
||||
"@types/node": "npm:24.19.1"
|
||||
lodash-es: "npm:^4.17.23"
|
||||
ts-mockito: "npm:^2.6.1"
|
||||
typescript: "npm:6.0.3"
|
||||
@@ -1024,7 +1024,7 @@ __metadata:
|
||||
"@jest/globals": "npm:30.5.1"
|
||||
"@types/invariant": "npm:2.2.37"
|
||||
"@types/lodash-es": "npm:4.17.12"
|
||||
"@types/node": "npm:24.13.4"
|
||||
"@types/node": "npm:24.19.1"
|
||||
dataloader: "npm:^2.2.3"
|
||||
invariant: "npm:^2.2.4"
|
||||
lodash-es: "npm:4.18.1"
|
||||
@@ -3042,10 +3042,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@tsconfig/bases@npm:1.0.27":
|
||||
version: 1.0.27
|
||||
resolution: "@tsconfig/bases@npm:1.0.27"
|
||||
checksum: 10c0/ec66e75847f712c82d5db58f3d1d4d806b2d963fb76a991e02d49e2886ceda09b00ffb46386507e332f7272794373a441e977132f4b2c47ef35c16ed75d7adc1
|
||||
"@tsconfig/bases@npm:1.0.28":
|
||||
version: 1.0.28
|
||||
resolution: "@tsconfig/bases@npm:1.0.28"
|
||||
checksum: 10c0/0f50b3f18dcc93f9f9e22fb39c8261ade004291a0f0ead9d2f82fae7a652a30ed678c5455213b5d91e68d9c4418e26acfdb1a56b5e7901c53f062cfb3282d830
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -3389,12 +3389,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:24.13.4":
|
||||
version: 24.13.4
|
||||
resolution: "@types/node@npm:24.13.4"
|
||||
"@types/node@npm:24.19.1":
|
||||
version: 24.19.1
|
||||
resolution: "@types/node@npm:24.19.1"
|
||||
dependencies:
|
||||
undici-types: "npm:~7.18.0"
|
||||
checksum: 10c0/a12196e984cb09ead549651217b4b395961ea011f3a3791a9f78311d70b5f3be343c6fc935376553c06a34c14d963d4f637ad7829837b0c88cf441919f422893
|
||||
undici-types: "npm:>=7.24.0 <7.24.7"
|
||||
checksum: 10c0/789822cc68a0e0b632fd0a9fa53411e33541f03c18dc19942ed38161c369bf0b013917b4c6c760688bd2d09d940c827a601add118dfa04fe35a285535b2a8596
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -6391,9 +6391,9 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"ip-address@npm:^10.0.1, ip-address@npm:^10.1.0":
|
||||
version: 10.4.0
|
||||
resolution: "ip-address@npm:10.4.0"
|
||||
checksum: 10c0/d7b0bd2624fd861afbae6e49036a9b56f9506eaff7ff38592b7b4492dd5c272b53f5356dc8cc019e318acf29a96c90a3d1af1df761960267d23efa96858270fa
|
||||
version: 10.7.2
|
||||
resolution: "ip-address@npm:10.7.2"
|
||||
checksum: 10c0/290b9c63289b2a89a442dac19eff88d919e65cd41d1a720fa963be736e126f3b0cf4f88f6056b06abbf4a95300dc9ce5362a773e012ef30e0400074d175b9d31
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9184,10 +9184,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg-cloudflare@npm:^1.4.0":
|
||||
version: 1.4.0
|
||||
resolution: "pg-cloudflare@npm:1.4.0"
|
||||
checksum: 10c0/553764d00055052648393cda53c1feb065991d6f9fbfdeb56cf8396c5b33377ab2897aaf5dc9cd3933d09023a1f01e8b1ca755431dcf5fd71c92ea277e2888f1
|
||||
"pg-cloudflare@npm:^1.4.1":
|
||||
version: 1.4.1
|
||||
resolution: "pg-cloudflare@npm:1.4.1"
|
||||
checksum: 10c0/32e62c987073472e81c0dc218f850b1212b4e2c1f35d50433d87d054fe268f549ebaf8fc6c1227ab24c12b318f3e3a2a191ffbdfb2daa30b39aa6802ab8fe2f6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9198,10 +9198,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg-connection-string@npm:^2.14.0":
|
||||
version: 2.14.0
|
||||
resolution: "pg-connection-string@npm:2.14.0"
|
||||
checksum: 10c0/c26d85970f782de72b90aa45b4acfa34df90242fc08bc676e8827297164044dbfb40a2cf20b0646bd02662a6b14c5ed27f322db627e41e582f2b705bc41e8b47
|
||||
"pg-connection-string@npm:^2.14.1":
|
||||
version: 2.14.1
|
||||
resolution: "pg-connection-string@npm:2.14.1"
|
||||
checksum: 10c0/7321eed97579b4972a714909e7a444beb2186780fe7fd86ea719ff7c8f1fad07d7e5f85722c4992245b23683ed7d2fe2bdda8f7469fed4c016bb5c3379c575ca
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9221,10 +9221,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg-protocol@npm:^1.16.0":
|
||||
version: 1.16.0
|
||||
resolution: "pg-protocol@npm:1.16.0"
|
||||
checksum: 10c0/8ea4a8f4970aa0ca1e5bf9a482da0a41a043d7470fbaf7592736971146b09a2a4003d953c0091b72fc30bf7a7994a0b7fdf897bf50cd219787bd22806b3ffb04
|
||||
"pg-protocol@npm:^1.16.1":
|
||||
version: 1.16.1
|
||||
resolution: "pg-protocol@npm:1.16.1"
|
||||
checksum: 10c0/84e8bf05c3548c8ffcad29247c075f8f1cf477600c92a7eb0ab27c6c4cbdbe1280433582bfba91f629b1f68bcaf4ae26436a898f430e884d7887543931e8ade6
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9241,14 +9241,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg@npm:8.23.0":
|
||||
version: 8.23.0
|
||||
resolution: "pg@npm:8.23.0"
|
||||
"pg@npm:8.23.1":
|
||||
version: 8.23.1
|
||||
resolution: "pg@npm:8.23.1"
|
||||
dependencies:
|
||||
pg-cloudflare: "npm:^1.4.0"
|
||||
pg-connection-string: "npm:^2.14.0"
|
||||
pg-cloudflare: "npm:^1.4.1"
|
||||
pg-connection-string: "npm:^2.14.1"
|
||||
pg-pool: "npm:^3.14.0"
|
||||
pg-protocol: "npm:^1.16.0"
|
||||
pg-protocol: "npm:^1.16.1"
|
||||
pg-types: "npm:2.2.0"
|
||||
pgpass: "npm:1.0.5"
|
||||
peerDependencies:
|
||||
@@ -9259,7 +9259,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
pg-native:
|
||||
optional: true
|
||||
checksum: 10c0/11ce12a71b4239588c18f078531c378d5bcdbcb9ea892e080a6e71f91aaece2b4b8fd93ee5777f94210f9258ff56161f8ed1a45050c32d295aaca037bba12ee8
|
||||
checksum: 10c0/084ce2bcd025705105d4d9a4c4438b178117acbaae5c766e3d3c9fb812cc55d826a212189e19937b8e3b0a8914a3c3e4ba78ad62af73890f37406a676c1f9e0c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9788,8 +9788,8 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "root@workspace:."
|
||||
dependencies:
|
||||
"@tsconfig/bases": "npm:1.0.27"
|
||||
"@types/node": "npm:24.13.4"
|
||||
"@tsconfig/bases": "npm:1.0.28"
|
||||
"@types/node": "npm:24.19.1"
|
||||
ctix: "npm:2.8.2"
|
||||
jest: "npm:30.5.1"
|
||||
lerna: "npm:9.0.7"
|
||||
@@ -10832,10 +10832,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"undici-types@npm:~7.18.0":
|
||||
version: 7.18.2
|
||||
resolution: "undici-types@npm:7.18.2"
|
||||
checksum: 10c0/85a79189113a238959d7a647368e4f7c5559c3a404ebdb8fc4488145ce9426fcd82252a844a302798dfc0e37e6fb178ff481ed03bc4caf634c5757d9ef43521d
|
||||
"undici-types@npm:>=7.24.0 <7.24.7":
|
||||
version: 7.24.6
|
||||
resolution: "undici-types@npm:7.24.6"
|
||||
checksum: 10c0/d9cd8befb643ac904615c280a095ba4240531f6bb4a5e75a22a7483630ca8d3f1016d2ab6ace6ceda1f63b3a2db2fe037fafe121d6917a0187573aa548ff78ca
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in new issue
Block a user