mirror of
https://github.com/expo/entity.git
synced 2026-11-21 10:19:25 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbd1cc8479 | ||
|
|
977b790ba7 | ||
|
|
2693fbc000 | ||
|
|
4709f53b45 | ||
|
|
f4496b9cc7 | ||
|
|
15ebe7d584 | ||
|
|
0d00605a93 | ||
|
|
73d45fdca3 | ||
|
|
3421a746be | ||
|
|
5ae965b736 | ||
|
|
bfa703e4ed | ||
|
|
174d6c602b | ||
|
|
0c0c6a3496 | ||
|
|
3f103e1dbd | ||
|
|
d90dce72c2 | ||
|
|
d800024283 | ||
|
|
b6c950900d | ||
|
|
4965cc2388 | ||
|
|
e3cee07091 | ||
|
|
0a1d1b5972 | ||
|
|
db887d3d7d | ||
|
|
2214f7d19a | ||
|
|
4f4243d314 | ||
|
|
a505216608 | ||
|
|
bc40501535 | ||
|
|
790e75160b | ||
|
|
cd38019789 | ||
|
|
e1c47de3a7 | ||
|
|
a6f1dd7232 | ||
|
|
112d4dc9b3 | ||
|
|
f33d388b48 | ||
|
|
f138841a59 | ||
|
|
090c046bbc | ||
|
|
81906aed16 | ||
|
|
ea9c45fade | ||
|
|
2fc88cb204 | ||
|
|
e4133a865e | ||
|
|
f75ed7f749 | ||
|
|
6bfde96bc3 | ||
|
|
575d8545f7 | ||
|
|
1aae31b0bf | ||
|
|
6cbe50a048 | ||
|
|
0b4385698c | ||
|
|
1a8535f983 | ||
|
|
1f66b9f8f3 | ||
|
|
6a07e6bd66 | ||
|
|
9202ecbb23 | ||
|
|
a3085ed911 | ||
|
|
934e5f3199 |
No files matched your search
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"mode": "bundle",
|
||||
"fileExt": "keep",
|
||||
"overwrite": true,
|
||||
"backup": false,
|
||||
"generationStyle": "default-alias-named-star",
|
||||
|
||||
@@ -7,14 +7,14 @@ on:
|
||||
|
||||
env:
|
||||
# renovate: datasource=github-releases depName=jdx/mise
|
||||
MISE_VERSION: v2026.3.3
|
||||
MISE_VERSION: v2026.3.17
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3.6.3
|
||||
- uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
version: ${{ env.MISE_VERSION }}
|
||||
@@ -22,13 +22,13 @@ jobs:
|
||||
with:
|
||||
cache: yarn
|
||||
- run: mise run ci
|
||||
- uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
||||
- uses: codecov/codecov-action@75cd11691c0faa626561e295848008c8a7dddffe # v5.5.4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
directory: ./coverage
|
||||
flags: unittest
|
||||
fail_ci_if_error: true
|
||||
- uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
|
||||
- uses: codecov/codecov-action@75cd11691c0faa626561e295848008c8a7dddffe # v5.5.4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
directory: ./coverage-integration
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- uses: jdx/mise-action@5228313ee0372e111a38da051671ca30fc5a96db # v3.6.3
|
||||
- uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4.0.1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
version: ${{ env.MISE_VERSION }}
|
||||
|
||||
@@ -3,6 +3,23 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- only throw EntityDatabaseAdapterPaginationCursorInvalidError from cursor decoding logic ([#537](https://github.com/expo/entity/issues/537)) ([e3cee07](https://github.com/expo/entity/commit/e3cee07091af8d1e6c5bb2d82f13e837c7658ea9))
|
||||
- remove unused arg from EntityInvalidationUtils ([#536](https://github.com/expo/entity/issues/536)) ([0a1d1b5](https://github.com/expo/entity/commit/0a1d1b5972c15c932f5c31015f2519163f882f83))
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **deps:** update dependency graphql to v16.13.1 ([#510](https://github.com/expo/entity/issues/510)) ([1a8535f](https://github.com/expo/entity/commit/1a8535f983f38aaa462a8d587e2f62f5fab1043c))
|
||||
|
||||
### Features
|
||||
|
||||
- update the SQLExpression and SQLFragmentHelpers APIs ([#516](https://github.com/expo/entity/issues/516)) ([112d4dc](https://github.com/expo/entity/commit/112d4dc9b379da5317ff6acaf1d2e9bd597128a6))
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
### Features
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
export default {
|
||||
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
|
||||
};
|
||||
+5
-6
@@ -1,9 +1,9 @@
|
||||
const { defineConfig, globalIgnores } = require('eslint/config');
|
||||
const universeNodeConfig = require('eslint-config-universe/flat/node');
|
||||
const universeSharedTypescriptAnalysisConfig = require('eslint-config-universe/flat/shared/typescript-analysis');
|
||||
const tsdoc = require('eslint-plugin-tsdoc');
|
||||
import { defineConfig, globalIgnores } from 'eslint/config';
|
||||
import universeNodeConfig from 'eslint-config-universe/flat/node.js';
|
||||
import universeSharedTypescriptAnalysisConfig from 'eslint-config-universe/flat/shared/typescript-analysis.js';
|
||||
import tsdoc from 'eslint-plugin-tsdoc';
|
||||
|
||||
module.exports = defineConfig([
|
||||
export default defineConfig([
|
||||
globalIgnores([
|
||||
'packages/entity-codemod/**/__testfixtures__/**',
|
||||
'packages/*/build',
|
||||
@@ -17,7 +17,6 @@ module.exports = defineConfig([
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: true,
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const unitConfig = require('./jest.config.js');
|
||||
import unitConfig from './jest.config.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
...unitConfig,
|
||||
coverageDirectory: 'coverage-integration',
|
||||
testMatch: ['**/__integration-tests__/**/*-test.ts'],
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { stripTypeScriptTypes } from 'node:module';
|
||||
|
||||
export function process(sourceText, sourcePath) {
|
||||
return {
|
||||
code: stripTypeScriptTypes(sourceText, {
|
||||
mode: 'transform',
|
||||
sourceMap: true,
|
||||
sourceUrl: sourcePath,
|
||||
}),
|
||||
};
|
||||
}
|
||||
+5
-4
@@ -1,7 +1,8 @@
|
||||
module.exports = {
|
||||
transform: { '\\.[jt]sx?$': ['babel-jest', { rootMode: 'upward' }] },
|
||||
// ESM modules that need to be transformed
|
||||
transformIgnorePatterns: ['node_modules/(?!(uuid)/)'],
|
||||
export default {
|
||||
// This is an absolute path determined at runtime so that running `yarn test`
|
||||
// both from each package's directory and from root works correctly.
|
||||
transform: { '\\.[jt]sx?$': new URL('./jest-transform.js', import.meta.url).toString() },
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
collectCoverageFrom: [
|
||||
'packages/*/src/**',
|
||||
'!packages/*/src/index.ts',
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"packages": ["packages/*"],
|
||||
"npmClient": "yarn",
|
||||
"version": "0.60.0",
|
||||
"version": "0.63.0",
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
[tools]
|
||||
node = "24.14.0"
|
||||
yarn = "4.12.0"
|
||||
node = "24.14.1"
|
||||
|
||||
[tasks.yarn]
|
||||
run = "yarn install --immutable"
|
||||
@@ -35,3 +34,14 @@ run = "yarn integration --coverage"
|
||||
|
||||
[tasks.ci]
|
||||
run = { task = "checks:*" }
|
||||
|
||||
[settings]
|
||||
experimental = true # needed for postinstall hook
|
||||
|
||||
[hooks]
|
||||
postinstall = [
|
||||
# Enable yarn shim. Version controlled by package.json#packageManager
|
||||
# NOTE: mise can install yarn directly, but renovate does not use mise, so we
|
||||
# control yarn versions using the packageManager field.
|
||||
"corepack enable yarn"
|
||||
]
|
||||
+10
-14
@@ -10,7 +10,7 @@
|
||||
"clean": "yarn build --clean",
|
||||
"lint": "eslint .",
|
||||
"lint-fix": "yarn lint --fix",
|
||||
"test": "yarn build --noCheck && jest",
|
||||
"test": "yarn build --noCheck && NODE_OPTIONS='--experimental-vm-modules --disable-warning=ExperimentalWarning' jest",
|
||||
"test:all": "yarn test",
|
||||
"integration": "./resources/run-with-docker yarn test --config jest-integration.config.js --runInBand",
|
||||
"integration:all": "yarn integration",
|
||||
@@ -18,27 +18,23 @@
|
||||
"package-files": "yarn workspaces foreach --all --no-private --parallel --topological pack --dry-run",
|
||||
"typedoc": "yarn build && typedoc"
|
||||
},
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@babel/core": "7.29.0",
|
||||
"@babel/preset-env": "7.29.0",
|
||||
"@babel/preset-typescript": "7.28.5",
|
||||
"@tsconfig/node24": "24.0.4",
|
||||
"@tsconfig/strictest": "2.0.8",
|
||||
"@types/babel__core": "7.20.5",
|
||||
"@types/babel__preset-env": "7.10.0",
|
||||
"@types/node": "24.11.0",
|
||||
"@tsconfig/bases": "1.0.23",
|
||||
"@types/node": "24.12.0",
|
||||
"ctix": "2.7.5",
|
||||
"eslint": "9.39.3",
|
||||
"eslint": "9.39.4",
|
||||
"eslint-config-universe": "15.0.3",
|
||||
"eslint-plugin-tsdoc": "0.5.2",
|
||||
"jest": "30.2.0",
|
||||
"lerna": "9.0.5",
|
||||
"jest": "30.3.0",
|
||||
"lerna": "9.0.7",
|
||||
"prettier": "3.8.1",
|
||||
"prettier-plugin-organize-imports": "4.3.0",
|
||||
"typedoc": "0.28.17",
|
||||
"typedoc": "0.28.18",
|
||||
"typescript": "5.9.3"
|
||||
},
|
||||
"resolutions": {
|
||||
"collect-v8-coverage": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"packageManager": "[email protected]+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8"
|
||||
}
|
||||
@@ -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.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-local-memory
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
**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.60.0",
|
||||
"version": "0.63.0",
|
||||
"description": "Cross-request local memory cache adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -20,20 +20,21 @@
|
||||
"integration": "yarn integration:all --rootDir $(pwd)"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=18"
|
||||
},
|
||||
"keywords": [
|
||||
"entity"
|
||||
],
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@expo/entity": "workspace:^"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity-testing-utils": "workspace:^",
|
||||
"@isaacs/ttlcache": "2.1.4",
|
||||
"@jest/globals": "30.2.0",
|
||||
"@jest/globals": "30.3.0",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import {
|
||||
import type {
|
||||
CacheLoadResult,
|
||||
CacheStatus,
|
||||
EntityConfiguration,
|
||||
IEntityGenericCacher,
|
||||
IEntityLoadKey,
|
||||
IEntityLoadValue,
|
||||
} from '@expo/entity';
|
||||
import { CacheStatus } from '@expo/entity';
|
||||
|
||||
// Sentinel value we store in local memory to negatively cache a database miss.
|
||||
// The sentinel value is distinct from any (positively) cached value.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import {
|
||||
computeIfAbsent,
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
GenericEntityCacheAdapter,
|
||||
IEntityCacheAdapter,
|
||||
IEntityCacheAdapterProvider,
|
||||
} from '@expo/entity';
|
||||
import { computeIfAbsent, GenericEntityCacheAdapter } from '@expo/entity';
|
||||
|
||||
import { GenericLocalMemoryCacher, ILocalMemoryCache } from './GenericLocalMemoryCacher';
|
||||
import type { ILocalMemoryCache } from './GenericLocalMemoryCacher.ts';
|
||||
import { GenericLocalMemoryCacher } from './GenericLocalMemoryCacher.ts';
|
||||
|
||||
export type LocalMemoryCacheCreator = <
|
||||
TFields extends Record<string, any>,
|
||||
|
||||
+1
-2
@@ -1,13 +1,12 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
DateField,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
export type LocalMemoryTestEntityFields = {
|
||||
|
||||
+4
-7
@@ -1,13 +1,10 @@
|
||||
import {
|
||||
EntityCompanionProvider,
|
||||
IEntityMetricsAdapter,
|
||||
NoOpEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityCompanionProvider, NoOpEntityMetricsAdapter } from '@expo/entity';
|
||||
import { StubDatabaseAdapterProvider, StubQueryContextProvider } from '@expo/entity-testing-utils';
|
||||
import { TTLCache } from '@isaacs/ttlcache';
|
||||
|
||||
import { ILocalMemoryCache, LocalMemoryCacheValue } from '../GenericLocalMemoryCacher';
|
||||
import { LocalMemoryCacheAdapterProvider } from '../LocalMemoryCacheAdapterProvider';
|
||||
import type { ILocalMemoryCache, LocalMemoryCacheValue } from '../GenericLocalMemoryCacher.ts';
|
||||
import { LocalMemoryCacheAdapterProvider } from '../LocalMemoryCacheAdapterProvider.ts';
|
||||
|
||||
const queryContextProvider = new StubQueryContextProvider();
|
||||
|
||||
|
||||
+6
-9
@@ -1,7 +1,6 @@
|
||||
import type { GenericEntityCacheAdapter, IEntityGenericCacher } from '@expo/entity';
|
||||
import {
|
||||
CacheStatus,
|
||||
GenericEntityCacheAdapter,
|
||||
IEntityGenericCacher,
|
||||
SingleFieldHolder,
|
||||
SingleFieldValueHolder,
|
||||
ViewerContext,
|
||||
@@ -9,16 +8,14 @@ import {
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { GenericLocalMemoryCacher } from '../GenericLocalMemoryCacher';
|
||||
import { LocalMemoryCacheAdapterProvider } from '../LocalMemoryCacheAdapterProvider';
|
||||
import {
|
||||
LocalMemoryTestEntity,
|
||||
LocalMemoryTestEntityFields,
|
||||
} from '../__testfixtures__/LocalMemoryTestEntity';
|
||||
import { GenericLocalMemoryCacher } from '../GenericLocalMemoryCacher.ts';
|
||||
import type { LocalMemoryCacheAdapterProvider } from '../LocalMemoryCacheAdapterProvider.ts';
|
||||
import type { LocalMemoryTestEntityFields } from '../__testfixtures__/LocalMemoryTestEntity.ts';
|
||||
import { LocalMemoryTestEntity } from '../__testfixtures__/LocalMemoryTestEntity.ts';
|
||||
import {
|
||||
createLocalMemoryTestEntityCompanionProvider,
|
||||
createNoOpLocalMemoryIntegrationTestEntityCompanionProvider,
|
||||
} from '../__testfixtures__/createLocalMemoryTestEntityCompanionProvider';
|
||||
} from '../__testfixtures__/createLocalMemoryTestEntityCompanionProvider.ts';
|
||||
|
||||
describe(GenericLocalMemoryCacher, () => {
|
||||
it('has correct caching behavior', async () => {
|
||||
|
||||
+2
-3
@@ -10,12 +10,11 @@ import {
|
||||
import { TTLCache } from '@isaacs/ttlcache';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import type { ILocalMemoryCache, LocalMemoryCacheValue } from '../GenericLocalMemoryCacher.ts';
|
||||
import {
|
||||
DOES_NOT_EXIST_LOCAL_MEMORY_CACHE,
|
||||
GenericLocalMemoryCacher,
|
||||
ILocalMemoryCache,
|
||||
LocalMemoryCacheValue,
|
||||
} from '../GenericLocalMemoryCacher';
|
||||
} from '../GenericLocalMemoryCacher.ts';
|
||||
|
||||
type BlahFields = {
|
||||
id: string;
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
* @module @expo/entity-cache-adapter-local-memory
|
||||
*/
|
||||
|
||||
export * from './GenericLocalMemoryCacher';
|
||||
export * from './LocalMemoryCacheAdapterProvider';
|
||||
export * from './GenericLocalMemoryCacher.ts';
|
||||
export * from './LocalMemoryCacheAdapterProvider.ts';
|
||||
@@ -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.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-cache-adapter-redis
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-cache-adapter-redis",
|
||||
"version": "0.60.0",
|
||||
"version": "0.63.0",
|
||||
"description": "Redis cache adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -20,13 +20,14 @@
|
||||
"integration": "yarn integration:all --rootDir $(pwd)"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=18"
|
||||
},
|
||||
"keywords": [
|
||||
"entity"
|
||||
],
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@expo/entity": "workspace:^"
|
||||
},
|
||||
@@ -36,8 +37,8 @@
|
||||
"devDependencies": {
|
||||
"@expo/batcher": "1.0.0",
|
||||
"@expo/entity-testing-utils": "workspace:^",
|
||||
"@jest/globals": "30.2.0",
|
||||
"ioredis": "5.10.0",
|
||||
"@jest/globals": "30.3.0",
|
||||
"ioredis": "5.10.1",
|
||||
"ts-mockito": "2.6.1",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import {
|
||||
import type {
|
||||
CacheLoadResult,
|
||||
CacheStatus,
|
||||
EntityConfiguration,
|
||||
IEntityGenericCacher,
|
||||
IEntityLoadKey,
|
||||
IEntityLoadValue,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
CacheStatus,
|
||||
transformCacheObjectToFields,
|
||||
transformFieldsToCacheObject,
|
||||
} from '@expo/entity';
|
||||
|
||||
import { redisTransformerMap } from './RedisCommon';
|
||||
import { wrapNativeRedisCallAsync } from './errors/wrapNativeRedisCallAsync';
|
||||
import { getSurroundingCacheKeyVersionsForInvalidation } from './utils/getSurroundingCacheKeyVersionsForInvalidation';
|
||||
import { redisTransformerMap } from './RedisCommon.ts';
|
||||
import { wrapNativeRedisCallAsync } from './errors/wrapNativeRedisCallAsync.ts';
|
||||
import { getSurroundingCacheKeyVersionsForInvalidation } from './utils/getSurroundingCacheKeyVersionsForInvalidation.ts';
|
||||
|
||||
// Sentinel value we store in Redis to negatively cache a database miss.
|
||||
// The sentinel value is distinct from any (positively) cached value.
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
GenericEntityCacheAdapter,
|
||||
IEntityCacheAdapter,
|
||||
IEntityCacheAdapterProvider,
|
||||
} from '@expo/entity';
|
||||
import { GenericEntityCacheAdapter } from '@expo/entity';
|
||||
|
||||
import { GenericRedisCacheContext, GenericRedisCacher } from './GenericRedisCacher';
|
||||
import type { GenericRedisCacheContext } from './GenericRedisCacher.ts';
|
||||
import { GenericRedisCacher } from './GenericRedisCacher.ts';
|
||||
|
||||
export class RedisCacheAdapterProvider implements IEntityCacheAdapterProvider {
|
||||
constructor(private readonly context: GenericRedisCacheContext) {}
|
||||
|
||||
+9
-18
@@ -1,27 +1,18 @@
|
||||
import { Batcher } from '@expo/batcher';
|
||||
import {
|
||||
GenericEntityCacheAdapter,
|
||||
SingleFieldHolder,
|
||||
SingleFieldValueHolder,
|
||||
ViewerContext,
|
||||
zipToMap,
|
||||
} from '@expo/entity';
|
||||
import type { GenericEntityCacheAdapter } from '@expo/entity';
|
||||
import { SingleFieldHolder, SingleFieldValueHolder, ViewerContext, zipToMap } from '@expo/entity';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
|
||||
import invariant from 'invariant';
|
||||
import Redis from 'ioredis';
|
||||
import nullthrows from 'nullthrows';
|
||||
import { Redis } from 'ioredis';
|
||||
import { URL } from 'url';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import {
|
||||
GenericRedisCacheContext,
|
||||
GenericRedisCacher,
|
||||
IRedis,
|
||||
IRedisTransaction,
|
||||
RedisCacheInvalidationStrategy,
|
||||
} from '../GenericRedisCacher';
|
||||
import { RedisTestEntity, RedisTestEntityFields } from '../__testfixtures__/RedisTestEntity';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider';
|
||||
import type { GenericRedisCacheContext, IRedis, IRedisTransaction } from '../GenericRedisCacher.ts';
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher.ts';
|
||||
import type { RedisTestEntityFields } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { RedisTestEntity } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
class BatchedRedis implements IRedis {
|
||||
private readonly mgetBatcher = new Batcher<string[], (string | null)[]>(
|
||||
|
||||
+7
-9
@@ -1,24 +1,22 @@
|
||||
import type { GenericEntityCacheAdapter } from '@expo/entity';
|
||||
import {
|
||||
CompositeFieldHolder,
|
||||
CompositeFieldValueHolder,
|
||||
GenericEntityCacheAdapter,
|
||||
SingleFieldHolder,
|
||||
SingleFieldValueHolder,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { enforceAsyncResult } from '@expo/results';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import Redis from 'ioredis';
|
||||
import { Redis } from 'ioredis';
|
||||
import { URL } from 'url';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import {
|
||||
GenericRedisCacheContext,
|
||||
GenericRedisCacher,
|
||||
RedisCacheInvalidationStrategy,
|
||||
} from '../GenericRedisCacher';
|
||||
import { RedisTestEntity, RedisTestEntityFields } from '../__testfixtures__/RedisTestEntity';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider';
|
||||
import type { GenericRedisCacheContext } from '../GenericRedisCacher.ts';
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher.ts';
|
||||
import type { RedisTestEntityFields } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { RedisTestEntity } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
class TestViewerContext extends ViewerContext {}
|
||||
|
||||
|
||||
+6
-9
@@ -1,19 +1,16 @@
|
||||
import { CacheStatus, ViewerContext } from '@expo/entity';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import Redis from 'ioredis';
|
||||
import { Redis } from 'ioredis';
|
||||
import { URL } from 'url';
|
||||
|
||||
import {
|
||||
GenericRedisCacheContext,
|
||||
GenericRedisCacher,
|
||||
RedisCacheInvalidationStrategy,
|
||||
} from '../GenericRedisCacher';
|
||||
import type { GenericRedisCacheContext } from '../GenericRedisCacher.ts';
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher.ts';
|
||||
import type { RedisTestEntityFields } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import {
|
||||
RedisTestEntity,
|
||||
redisTestEntityConfiguration,
|
||||
RedisTestEntityFields,
|
||||
} from '../__testfixtures__/RedisTestEntity';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider';
|
||||
} from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
class TestViewerContext extends ViewerContext {}
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { EntityCacheAdapterTransientError, ViewerContext } from '@expo/entity';
|
||||
import { beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import Redis from 'ioredis';
|
||||
import { Redis } from 'ioredis';
|
||||
import { URL } from 'url';
|
||||
|
||||
import {
|
||||
GenericRedisCacheContext,
|
||||
GenericRedisCacher,
|
||||
RedisCacheInvalidationStrategy,
|
||||
} from '../GenericRedisCacher';
|
||||
import { RedisTestEntity } from '../__testfixtures__/RedisTestEntity';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider';
|
||||
import type { GenericRedisCacheContext } from '../GenericRedisCacher.ts';
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher.ts';
|
||||
import { RedisTestEntity } from '../__testfixtures__/RedisTestEntity.ts';
|
||||
import { createRedisIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createRedisIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
class TestViewerContext extends ViewerContext {}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
BufferField,
|
||||
DateField,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
export type RedisTestEntityFields = {
|
||||
|
||||
+4
-7
@@ -1,12 +1,9 @@
|
||||
import {
|
||||
EntityCompanionProvider,
|
||||
IEntityMetricsAdapter,
|
||||
NoOpEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityCompanionProvider, NoOpEntityMetricsAdapter } from '@expo/entity';
|
||||
import { StubDatabaseAdapterProvider, StubQueryContextProvider } from '@expo/entity-testing-utils';
|
||||
|
||||
import { GenericRedisCacheContext } from '../GenericRedisCacher';
|
||||
import { RedisCacheAdapterProvider } from '../RedisCacheAdapterProvider';
|
||||
import type { GenericRedisCacheContext } from '../GenericRedisCacher.ts';
|
||||
import { RedisCacheAdapterProvider } from '../RedisCacheAdapterProvider.ts';
|
||||
|
||||
// share across all in calls in test to simulate postgres
|
||||
const adapterProvider = new StubDatabaseAdapterProvider();
|
||||
|
||||
@@ -6,10 +6,10 @@ import {
|
||||
UUIDField,
|
||||
} from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { Pipeline, Redis } from 'ioredis';
|
||||
import type { Pipeline, Redis } from 'ioredis';
|
||||
import { anything, instance, mock, verify, when } from 'ts-mockito';
|
||||
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher';
|
||||
import { GenericRedisCacher, RedisCacheInvalidationStrategy } from '../GenericRedisCacher.ts';
|
||||
|
||||
type BlahFields = {
|
||||
id: string;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { EntityCacheAdapterTransientError } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { wrapNativeRedisCallAsync } from '../wrapNativeRedisCallAsync';
|
||||
import { wrapNativeRedisCallAsync } from '../wrapNativeRedisCallAsync.ts';
|
||||
|
||||
describe(wrapNativeRedisCallAsync, () => {
|
||||
it('rethrows literals', async () => {
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* @module @expo/entity-cache-adapter-redis
|
||||
*/
|
||||
|
||||
export * from './GenericRedisCacher';
|
||||
export * from './RedisCacheAdapterProvider';
|
||||
export * from './RedisCommon';
|
||||
export * from './errors/wrapNativeRedisCallAsync';
|
||||
export * from './utils/getSurroundingCacheKeyVersionsForInvalidation';
|
||||
export * from './GenericRedisCacher.ts';
|
||||
export * from './RedisCacheAdapterProvider.ts';
|
||||
export * from './RedisCommon.ts';
|
||||
export * from './errors/wrapNativeRedisCallAsync.ts';
|
||||
export * from './utils/getSurroundingCacheKeyVersionsForInvalidation.ts';
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { getSurroundingCacheKeyVersionsForInvalidation } from '../getSurroundingCacheKeyVersionsForInvalidation';
|
||||
import { getSurroundingCacheKeyVersionsForInvalidation } from '../getSurroundingCacheKeyVersionsForInvalidation.ts';
|
||||
|
||||
describe(getSurroundingCacheKeyVersionsForInvalidation, () => {
|
||||
it('returns the correct cache key versions to invalidate', () => {
|
||||
|
||||
@@ -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.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-codemod
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-codemod",
|
||||
"version": "0.60.0",
|
||||
"version": "0.63.0",
|
||||
"description": "jscodeshift codemods for @expo/entity upgrades",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -19,17 +19,18 @@
|
||||
"test": "yarn test:all --rootDir $(pwd)"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=18"
|
||||
},
|
||||
"keywords": [
|
||||
"entity"
|
||||
],
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@jest/globals": "30.2.0",
|
||||
"@jest/globals": "30.3.0",
|
||||
"@types/jscodeshift": "17.3.0",
|
||||
"@types/node": "24.11.0",
|
||||
"@types/node": "24.12.0",
|
||||
"jscodeshift": "17.3.0",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import { UserEntity } from './entities/UserEntity';
|
||||
import { PostEntity } from './entities/PostEntity';
|
||||
import { PostEntity } from './entities/PostEntity.ts';
|
||||
import { UserEntity } from './entities/UserEntity.ts';
|
||||
|
||||
async function loadUser(viewerContext: ViewerContext) {
|
||||
// Basic loader calls - only transformed when using knex-specific methods
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import { UserEntity } from './entities/UserEntity';
|
||||
import { PostEntity } from './entities/PostEntity';
|
||||
import { PostEntity } from './entities/PostEntity.ts';
|
||||
import { UserEntity } from './entities/UserEntity.ts';
|
||||
|
||||
async function loadUser(viewerContext: ViewerContext) {
|
||||
// Basic loader calls - only transformed when using knex-specific methods
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import { CommentEntity } from './entities/CommentEntity';
|
||||
import { CommentEntity } from './entities/CommentEntity.ts';
|
||||
|
||||
// Chained calls
|
||||
const loadComments = async (viewerContext: ViewerContext) => {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import { CommentEntity } from './entities/CommentEntity';
|
||||
import { CommentEntity } from './entities/CommentEntity.ts';
|
||||
|
||||
// Chained calls
|
||||
const loadComments = async (viewerContext: ViewerContext) => {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { readFile, readdir } from 'fs/promises';
|
||||
import { defineInlineTest } from 'jscodeshift/src/testUtils.js';
|
||||
|
||||
async function readfixtureAsync(mod: string, name: string): Promise<string> {
|
||||
return await readFile(new URL(`../__testfixtures__/${mod}/${name}`, import.meta.url), {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function prefixes(suffix: string): (names: string[]) => string[] {
|
||||
return (names) => names.filter((n) => n.endsWith(suffix)).map((n) => n.replace(suffix, ''));
|
||||
}
|
||||
|
||||
const modules = await readdir(new URL('../', import.meta.url)).then(prefixes('.ts'));
|
||||
|
||||
for (const mod of modules) {
|
||||
const transform = await import(`../${mod}.ts`);
|
||||
const fixtureDir = new URL(`../__testfixtures__/${mod}`, import.meta.url);
|
||||
const fixtures = await readdir(fixtureDir).then(prefixes('.input.ts'));
|
||||
for (const fixture of fixtures) {
|
||||
defineInlineTest(
|
||||
transform,
|
||||
{},
|
||||
await readfixtureAsync(mod, `${fixture}.input.ts`),
|
||||
await readfixtureAsync(mod, `${fixture}.output.ts`),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import { readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
jest.autoMockOff();
|
||||
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
|
||||
|
||||
const fixtureDir = 'v0.39.0-v0.40.0';
|
||||
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir);
|
||||
const fixtures = readdirSync(fixtureDirPath)
|
||||
.filter((file) => file.endsWith('.input.ts'))
|
||||
.map((file) => file.replace('.input.ts', ''));
|
||||
|
||||
for (const fixture of fixtures) {
|
||||
const prefix = `${fixtureDir}/${fixture}`;
|
||||
defineTest(__dirname, 'v0.39.0-v0.40.0', null, prefix, { parser: 'ts' });
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import { readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
jest.autoMockOff();
|
||||
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
|
||||
|
||||
const fixtureDir = 'v0.40.0-v0.41.0';
|
||||
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir);
|
||||
const fixtures = readdirSync(fixtureDirPath)
|
||||
.filter((file) => file.endsWith('.input.ts'))
|
||||
.map((file) => file.replace('.input.ts', ''));
|
||||
|
||||
for (const fixture of fixtures) {
|
||||
const prefix = `${fixtureDir}/${fixture}`;
|
||||
defineTest(__dirname, 'v0.40.0-v0.41.0', null, prefix, { parser: 'ts' });
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { jest } from '@jest/globals';
|
||||
import { readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
jest.autoMockOff();
|
||||
const defineTest = require('jscodeshift/dist/testUtils').defineTest;
|
||||
|
||||
const fixtureDir = 'v0.55.0-v0.56.0';
|
||||
const fixtureDirPath = join(__dirname, '..', '__testfixtures__', fixtureDir);
|
||||
const fixtures = readdirSync(fixtureDirPath)
|
||||
.filter((file) => file.endsWith('.input.ts'))
|
||||
.map((file) => file.replace('.input.ts', ''));
|
||||
|
||||
for (const fixture of fixtures) {
|
||||
const prefix = `${fixtureDir}/${fixture}`;
|
||||
defineTest(__dirname, 'v0.55.0-v0.56.0', null, prefix, { parser: 'ts' });
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
import type { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
|
||||
function transformEnforcingEntityChainMethod(
|
||||
j: API['jscodeshift'],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
import type { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
|
||||
function transformWithAuthorizationResultsEntityChainMethod(
|
||||
j: API['jscodeshift'],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
import type { API, Collection, FileInfo, Options } from 'jscodeshift';
|
||||
|
||||
const KNEX_SPECIFIC_METHODS = [
|
||||
'loadFirstByFieldEqualityConjunctionAsync',
|
||||
|
||||
@@ -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.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex-testing-utils
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
**Note:** Version bump only for package @expo/entity-database-adapter-knex-testing-utils
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
**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.60.0",
|
||||
"version": "0.63.0",
|
||||
"description": "Testing utilities for applications using Entity with Knex database adapter",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -19,13 +19,14 @@
|
||||
"test": "yarn test:all --rootDir $(pwd)"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=18"
|
||||
},
|
||||
"keywords": [
|
||||
"entity"
|
||||
],
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@expo/entity": "workspace:^",
|
||||
"@expo/entity-database-adapter-knex": "workspace:^",
|
||||
@@ -36,10 +37,9 @@
|
||||
"@jest/globals": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "30.2.0",
|
||||
"@jest/globals": "30.3.0",
|
||||
"@types/invariant": "2.2.37",
|
||||
"@types/node": "24.11.0",
|
||||
"@types/uuid": "10.0.0",
|
||||
"@types/node": "24.12.0",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
}
|
||||
+10
-19
@@ -1,23 +1,24 @@
|
||||
import type { EntityConfiguration, FieldTransformerMap } from '@expo/entity';
|
||||
import {
|
||||
computeIfAbsent,
|
||||
EntityConfiguration,
|
||||
FieldTransformerMap,
|
||||
getDatabaseFieldForEntityField,
|
||||
IntField,
|
||||
mapMap,
|
||||
StringField,
|
||||
transformFieldsToDatabaseObject,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
import type {
|
||||
SQLFragment,
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
TableOrderByClause,
|
||||
TableQuerySelectionModifiers,
|
||||
} from '@expo/entity-database-adapter-knex';
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
} from '@expo/entity-database-adapter-knex';
|
||||
import invariant from 'invariant';
|
||||
import { v7 as uuidv7 } from 'uuid';
|
||||
|
||||
@@ -191,16 +192,6 @@ export class StubPostgresDatabaseAdapter<
|
||||
return filteredObjects;
|
||||
}
|
||||
|
||||
protected fetchManyByRawWhereClauseInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
_rawWhereClause: string,
|
||||
_bindings: object | any[],
|
||||
_querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Promise<object[]> {
|
||||
throw new Error('Raw WHERE clauses not supported for StubDatabaseAdapter');
|
||||
}
|
||||
|
||||
protected fetchManyBySQLFragmentInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
@@ -252,7 +243,7 @@ export class StubPostgresDatabaseAdapter<
|
||||
tableIdField: string,
|
||||
id: any,
|
||||
object: object,
|
||||
): Promise<object[]> {
|
||||
): Promise<{ updatedRowCount: number }> {
|
||||
// SQL does not support empty updates, mirror behavior here for better test simulation
|
||||
if (Object.keys(object).length === 0) {
|
||||
throw new Error(`Empty update (${tableIdField} = ${id})`);
|
||||
@@ -267,14 +258,14 @@ export class StubPostgresDatabaseAdapter<
|
||||
// SQL updates to a nonexistent row succeed but affect 0 rows,
|
||||
// mirror that behavior here for better test simulation
|
||||
if (objectIndex < 0) {
|
||||
return [];
|
||||
return { updatedRowCount: 0 };
|
||||
}
|
||||
|
||||
objectCollection[objectIndex] = {
|
||||
...objectCollection[objectIndex],
|
||||
...object,
|
||||
};
|
||||
return [objectCollection[objectIndex]];
|
||||
return { updatedRowCount: 1 };
|
||||
}
|
||||
|
||||
protected async deleteInternalAsync(
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
EntityDatabaseAdapter,
|
||||
IEntityDatabaseAdapterProvider,
|
||||
} from '@expo/entity';
|
||||
|
||||
import { StubPostgresDatabaseAdapter } from './StubPostgresDatabaseAdapter';
|
||||
import { StubPostgresDatabaseAdapter } from './StubPostgresDatabaseAdapter.ts';
|
||||
|
||||
export class StubPostgresDatabaseAdapterProvider implements IEntityDatabaseAdapterProvider {
|
||||
private readonly objectCollection = new Map();
|
||||
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
DateField,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
export type DateIDTestFields = {
|
||||
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
export type SimpleTestFields = {
|
||||
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
DateField,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { result, Result } from '@expo/results';
|
||||
import type { Result } from '@expo/results';
|
||||
import { result } from '@expo/results';
|
||||
|
||||
export type TestFields = {
|
||||
customIdField: string;
|
||||
|
||||
+1
-2
@@ -1,11 +1,10 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
export type NumberKeyFields = {
|
||||
|
||||
+3
-4
@@ -1,6 +1,5 @@
|
||||
import { expect, it } from '@jest/globals';
|
||||
import { readFile } from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
it.each([
|
||||
'StubPostgresDatabaseAdapter',
|
||||
@@ -12,14 +11,14 @@ it.each([
|
||||
// Therefore, we duplicate them and ensure they stay in sync.
|
||||
|
||||
const fileContentsFromEntityDatabaseAdapterKnex = await readFile(
|
||||
path.resolve(
|
||||
__dirname,
|
||||
new URL(
|
||||
`../../../entity-database-adapter-knex/src/__tests__/fixtures/${fileName}.ts`,
|
||||
import.meta.url,
|
||||
),
|
||||
'utf-8',
|
||||
);
|
||||
const fileContentsFromTestingUtils = await readFile(
|
||||
path.resolve(__dirname, `../${fileName}.ts`),
|
||||
new URL(`../${fileName}.ts`, import.meta.url),
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
|
||||
+10
-32
@@ -10,20 +10,15 @@ import { describe, expect, it, jest } from '@jest/globals';
|
||||
import { instance, mock } from 'ts-mockito';
|
||||
import { validate, version } from 'uuid';
|
||||
|
||||
import { StubPostgresDatabaseAdapter } from '../StubPostgresDatabaseAdapter';
|
||||
import {
|
||||
DateIDTestFields,
|
||||
dateIDTestEntityConfiguration,
|
||||
} from '../__testfixtures__/DateIDTestEntity';
|
||||
import {
|
||||
SimpleTestFields,
|
||||
simpleTestEntityConfiguration,
|
||||
} from '../__testfixtures__/SimpleTestEntity';
|
||||
import { TestFields, testEntityConfiguration } from '../__testfixtures__/TestEntity';
|
||||
import {
|
||||
NumberKeyFields,
|
||||
numberKeyEntityConfiguration,
|
||||
} from '../__testfixtures__/TestEntityNumberKey';
|
||||
import { StubPostgresDatabaseAdapter } from '../StubPostgresDatabaseAdapter.ts';
|
||||
import type { DateIDTestFields } from '../__testfixtures__/DateIDTestEntity.ts';
|
||||
import { dateIDTestEntityConfiguration } from '../__testfixtures__/DateIDTestEntity.ts';
|
||||
import type { SimpleTestFields } from '../__testfixtures__/SimpleTestEntity.ts';
|
||||
import { simpleTestEntityConfiguration } from '../__testfixtures__/SimpleTestEntity.ts';
|
||||
import type { TestFields } from '../__testfixtures__/TestEntity.ts';
|
||||
import { testEntityConfiguration } from '../__testfixtures__/TestEntity.ts';
|
||||
import type { NumberKeyFields } from '../__testfixtures__/TestEntityNumberKey.ts';
|
||||
import { numberKeyEntityConfiguration } from '../__testfixtures__/TestEntityNumberKey.ts';
|
||||
|
||||
// uuid keeps state internally for v7 generation, so we fix the time for all tests for consistent test results
|
||||
const expectedTime = new Date('2024-06-03T20:16:33.761Z');
|
||||
@@ -494,19 +489,6 @@ describe(StubPostgresDatabaseAdapter, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchManyByRawWhereClauseAsync', () => {
|
||||
it('throws because it is unsupported', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
const databaseAdapter = new StubPostgresDatabaseAdapter<TestFields, 'customIdField'>(
|
||||
testEntityConfiguration,
|
||||
new Map(),
|
||||
);
|
||||
await expect(
|
||||
databaseAdapter.fetchManyByRawWhereClauseAsync(queryContext, '', [], {}),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchManyBySQLFragmentAsync', () => {
|
||||
it('throws because it is unsupported', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
@@ -578,13 +560,9 @@ describe(StubPostgresDatabaseAdapter, () => {
|
||||
]),
|
||||
),
|
||||
);
|
||||
const result = await databaseAdapter.updateAsync(queryContext, 'customIdField', 'hello', {
|
||||
await databaseAdapter.updateAsync(queryContext, 'customIdField', 'hello', {
|
||||
stringField: 'b',
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
stringField: 'b',
|
||||
testIndexedField: 'h1',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws error when empty update to match common DBMS behavior', async () => {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import { EntityCompanionProvider, ViewerContext } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { TestEntity } from '../__testfixtures__/TestEntity';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from '../createUnitTestPostgresEntityCompanionProvider';
|
||||
import { TestEntity } from '../__testfixtures__/TestEntity.ts';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from '../createUnitTestPostgresEntityCompanionProvider.ts';
|
||||
|
||||
describe(createUnitTestPostgresEntityCompanionProvider, () => {
|
||||
it('creates a new EntityCompanionProvider', async () => {
|
||||
|
||||
+3
-6
@@ -1,14 +1,11 @@
|
||||
import {
|
||||
EntityCompanionProvider,
|
||||
IEntityMetricsAdapter,
|
||||
NoOpEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityCompanionProvider, NoOpEntityMetricsAdapter } from '@expo/entity';
|
||||
import {
|
||||
InMemoryFullCacheStubCacheAdapterProvider,
|
||||
StubQueryContextProvider,
|
||||
} from '@expo/entity-testing-utils';
|
||||
|
||||
import { StubPostgresDatabaseAdapterProvider } from './StubPostgresDatabaseAdapterProvider';
|
||||
import { StubPostgresDatabaseAdapterProvider } from './StubPostgresDatabaseAdapterProvider.ts';
|
||||
|
||||
const queryContextProvider = new StubQueryContextProvider();
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@
|
||||
* @module @expo/entity-database-adapter-knex-testing-utils
|
||||
*/
|
||||
|
||||
export * from './createUnitTestPostgresEntityCompanionProvider';
|
||||
export * from './StubPostgresDatabaseAdapter';
|
||||
export * from './StubPostgresDatabaseAdapterProvider';
|
||||
export * from './createUnitTestPostgresEntityCompanionProvider.ts';
|
||||
export * from './StubPostgresDatabaseAdapter.ts';
|
||||
export * from './StubPostgresDatabaseAdapterProvider.ts';
|
||||
@@ -3,6 +3,18 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [0.62.0](https://github.com/expo/entity/compare/v0.61.0...v0.62.0) (2026-03-16)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- only throw EntityDatabaseAdapterPaginationCursorInvalidError from cursor decoding logic ([#537](https://github.com/expo/entity/issues/537)) ([e3cee07](https://github.com/expo/entity/commit/e3cee07091af8d1e6c5bb2d82f13e837c7658ea9))
|
||||
|
||||
# [0.61.0](https://github.com/expo/entity/compare/v0.60.0...v0.61.0) (2026-03-12)
|
||||
|
||||
### Features
|
||||
|
||||
- update the SQLExpression and SQLFragmentHelpers APIs ([#516](https://github.com/expo/entity/issues/516)) ([112d4dc](https://github.com/expo/entity/commit/112d4dc9b379da5317ff6acaf1d2e9bd597128a6))
|
||||
|
||||
# [0.60.0](https://github.com/expo/entity/compare/v0.59.0...v0.60.0) (2026-03-06)
|
||||
|
||||
### Features
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/entity-database-adapter-knex",
|
||||
"version": "0.60.0",
|
||||
"version": "0.63.0",
|
||||
"description": "Knex database adapter for @expo/entity",
|
||||
"files": [
|
||||
"build",
|
||||
@@ -20,21 +20,22 @@
|
||||
"integration": "yarn integration:all --rootDir $(pwd)"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=18"
|
||||
},
|
||||
"keywords": [
|
||||
"entity"
|
||||
],
|
||||
"author": "Expo",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@expo/entity": "workspace:^",
|
||||
"knex": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@expo/entity-testing-utils": "workspace:^",
|
||||
"@jest/globals": "30.2.0",
|
||||
"pg": "8.19.0",
|
||||
"@jest/globals": "30.3.0",
|
||||
"pg": "8.20.0",
|
||||
"ts-mockito": "2.6.1",
|
||||
"typescript": "5.9.3"
|
||||
}
|
||||
|
||||
+15
-33
@@ -1,25 +1,28 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConstructionUtils,
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
IEntityMetricsAdapter,
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
IEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import { Result } from '@expo/results';
|
||||
import type { Result } from '@expo/results';
|
||||
|
||||
import {
|
||||
import type {
|
||||
FieldEqualityCondition,
|
||||
isSingleValueFieldEqualityCondition,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
} from './BasePostgresEntityDatabaseAdapter';
|
||||
import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder';
|
||||
import { PaginationStrategy } from './PaginationStrategy';
|
||||
import { SQLFragment } from './SQLOperator';
|
||||
import type { Connection, PageInfo } from './internal/EntityKnexDataManager';
|
||||
import { EntityKnexDataManager } from './internal/EntityKnexDataManager';
|
||||
import { NonNullableKeys } from './internal/utilityTypes';
|
||||
} from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { isSingleValueFieldEqualityCondition } from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder.ts';
|
||||
import type { PaginationStrategy } from './PaginationStrategy.ts';
|
||||
import type { SQLFragment } from './SQLOperator.ts';
|
||||
import type {
|
||||
Connection,
|
||||
EntityKnexDataManager,
|
||||
PageInfo,
|
||||
} from './internal/EntityKnexDataManager.ts';
|
||||
import type { NonNullableKeys } from './internal/utilityTypes.ts';
|
||||
|
||||
export type EntityLoaderBaseOrderByClause = {
|
||||
/**
|
||||
@@ -397,27 +400,6 @@ export class AuthorizationResultBasedKnexEntityLoader<
|
||||
return await this.constructionUtils.constructAndAuthorizeEntitiesArrayAsync(fieldObjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns array of entity results that match the query, where result error can be UnauthorizedError
|
||||
* @throws Error when rawWhereClause or bindings are invalid
|
||||
*
|
||||
* @deprecated Use loadManyBySQL instead for safer value bindings and more flexible query building.
|
||||
*/
|
||||
async loadManyByRawWhereClauseAsync(
|
||||
rawWhereClause: string,
|
||||
bindings: any[] | object,
|
||||
querySelectionModifiers: EntityLoaderQuerySelectionModifiers<TFields, TSelectedFields> = {},
|
||||
): Promise<readonly Result<TEntity>[]> {
|
||||
const fieldObjects = await this.knexDataManager.loadManyByRawWhereClauseAsync(
|
||||
this.queryContext,
|
||||
rawWhereClause,
|
||||
bindings,
|
||||
querySelectionModifiers,
|
||||
);
|
||||
return await this.constructionUtils.constructAndAuthorizeEntitiesArrayAsync(fieldObjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authorization-result-based version of the EnforcingKnexEntityLoader method by the same name.
|
||||
* @returns SQL query builder for building and executing SQL queries that when executed returns entity results where result error can be UnauthorizedError.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { EntityQueryContext } from '@expo/entity';
|
||||
import {
|
||||
EntityDatabaseAdapter,
|
||||
EntityQueryContext,
|
||||
getDatabaseFieldForEntityField,
|
||||
transformDatabaseObjectToFields,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
import { SQLFragment } from './SQLOperator';
|
||||
import type { SQLFragment } from './SQLOperator.ts';
|
||||
|
||||
/**
|
||||
* Equality operand that is used for selecting entities with a field with a single value.
|
||||
@@ -216,42 +216,6 @@ export abstract class BasePostgresEntityDatabaseAdapter<
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Promise<object[]>;
|
||||
|
||||
/**
|
||||
* Fetch many objects matching the raw WHERE clause.
|
||||
*
|
||||
* @param queryContext - query context with which to perform the fetch
|
||||
* @param rawWhereClause - parameterized SQL WHERE clause with positional binding placeholders or named binding placeholders
|
||||
* @param bindings - array of positional bindings or object of named bindings
|
||||
* @param querySelectionModifiers - limit, offset, and orderBy for the query
|
||||
* @returns array of objects matching the query
|
||||
*/
|
||||
async fetchManyByRawWhereClauseAsync(
|
||||
queryContext: EntityQueryContext,
|
||||
rawWhereClause: string,
|
||||
bindings: any[] | object,
|
||||
querySelectionModifiers: PostgresQuerySelectionModifiers<TFields>,
|
||||
): Promise<readonly Readonly<TFields>[]> {
|
||||
const results = await this.fetchManyByRawWhereClauseInternalAsync(
|
||||
queryContext.getQueryInterface(),
|
||||
this.entityConfiguration.tableName,
|
||||
rawWhereClause,
|
||||
bindings,
|
||||
this.convertToTableQueryModifiers(querySelectionModifiers),
|
||||
);
|
||||
|
||||
return results.map((result) =>
|
||||
transformDatabaseObjectToFields(this.entityConfiguration, this.fieldTransformerMap, result),
|
||||
);
|
||||
}
|
||||
|
||||
protected abstract fetchManyByRawWhereClauseInternalAsync(
|
||||
queryInterface: Knex,
|
||||
tableName: string,
|
||||
rawWhereClause: string,
|
||||
bindings: object | any[],
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Promise<object[]>;
|
||||
|
||||
/**
|
||||
* Fetch many objects matching the SQL fragment.
|
||||
*
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {
|
||||
import type {
|
||||
EntityLoaderOrderByClause,
|
||||
EntityLoaderQuerySelectionModifiers,
|
||||
} from './AuthorizationResultBasedKnexEntityLoader';
|
||||
import { NullsOrdering, OrderByOrdering } from './BasePostgresEntityDatabaseAdapter';
|
||||
import { SQLFragment } from './SQLOperator';
|
||||
} from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import type { NullsOrdering } from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { OrderByOrdering } from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import type { SQLFragment } from './SQLOperator.ts';
|
||||
|
||||
/**
|
||||
* Base SQL query builder that provides common functionality for building SQL queries.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConstructionUtils,
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
@@ -7,15 +7,15 @@ import {
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
|
||||
import {
|
||||
import type {
|
||||
AuthorizationResultBasedKnexEntityLoader,
|
||||
EntityLoaderLoadPageArgs,
|
||||
EntityLoaderQuerySelectionModifiers,
|
||||
} from './AuthorizationResultBasedKnexEntityLoader';
|
||||
import { FieldEqualityCondition } from './BasePostgresEntityDatabaseAdapter';
|
||||
import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder';
|
||||
import { SQLFragment } from './SQLOperator';
|
||||
import type { Connection, EntityKnexDataManager } from './internal/EntityKnexDataManager';
|
||||
} from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import type { FieldEqualityCondition } from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { BaseSQLQueryBuilder } from './BaseSQLQueryBuilder.ts';
|
||||
import type { SQLFragment } from './SQLOperator.ts';
|
||||
import type { Connection, EntityKnexDataManager } from './internal/EntityKnexDataManager.ts';
|
||||
|
||||
/**
|
||||
* Enforcing knex entity loader for non-data-loader-based load methods.
|
||||
@@ -104,50 +104,6 @@ export class EnforcingKnexEntityLoader<
|
||||
return entityResults.map((result) => result.enforceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load entities with a raw SQL WHERE clause.
|
||||
*
|
||||
* @example
|
||||
* Load entities with SQL function
|
||||
* ```typescript
|
||||
* const entitiesWithJsonKey = await ExampleEntity.loader(vc)
|
||||
* .loadManyByRawWhereClauseAsync(
|
||||
* "json_column->>'key_name' = ?",
|
||||
* ['value'],
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Load entities with tuple matching
|
||||
* ```typescript
|
||||
* const entities = await ExampleEntity.loader(vc)
|
||||
* .loadManyByRawWhereClauseAsync(
|
||||
* '(column_1, column_2) IN ((?, ?), (?, ?))',
|
||||
* [value1, value2, value3, value4],
|
||||
* );
|
||||
* ```
|
||||
* @param rawWhereClause - SQL WHERE clause. Interpolated values should be specified as ?-placeholders or :key_name
|
||||
* @param bindings - values to bind to the placeholders in the WHERE clause
|
||||
* @param querySelectionModifiers - limit, offset, and orderBy for the query.
|
||||
* @returns entities matching the WHERE clause
|
||||
* @throws EntityNotAuthorizedError when viewer is not authorized to view one or more of the returned entities
|
||||
* @throws Error when rawWhereClause or bindings are invalid
|
||||
*
|
||||
* @deprecated Use loadManyBySQL instead for safer value bindings and more flexible query building.
|
||||
*/
|
||||
async loadManyByRawWhereClauseAsync(
|
||||
rawWhereClause: string,
|
||||
bindings: any[] | object,
|
||||
querySelectionModifiers: EntityLoaderQuerySelectionModifiers<TFields, TSelectedFields> = {},
|
||||
): Promise<readonly TEntity[]> {
|
||||
const entityResults = await this.knexEntityLoader.loadManyByRawWhereClauseAsync(
|
||||
rawWhereClause,
|
||||
bindings,
|
||||
querySelectionModifiers,
|
||||
);
|
||||
return entityResults.map((result) => result.enforceValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load entities using a SQL query builder. When executed, all queries will enforce authorization and throw if not authorized.
|
||||
*
|
||||
@@ -159,7 +115,7 @@ export class EnforcingKnexEntityLoader<
|
||||
* .limit(10)
|
||||
* .executeAsync();
|
||||
*
|
||||
* const { between, inArray } = SQLFragmentHelpers;
|
||||
* const { between, inArray } = SQLExpression;
|
||||
* const filtered = await ExampleEntity.loader(vc)
|
||||
* .loadManyBySQL(
|
||||
* sql`${between('age', 18, 65)} AND ${inArray('role', ['admin', 'moderator'])}`
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
import type {
|
||||
EntityCompanion,
|
||||
EntityConstructionUtils,
|
||||
EntityPrivacyPolicy,
|
||||
EntityPrivacyPolicyEvaluationContext,
|
||||
EntityQueryContext,
|
||||
IEntityMetricsAdapter,
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
IEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import { EntityConstructionUtils } from '@expo/entity';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader';
|
||||
import { EntityKnexDataManager } from './internal/EntityKnexDataManager';
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader.ts';
|
||||
import type { EntityKnexDataManager } from './internal/EntityKnexDataManager.ts';
|
||||
|
||||
/**
|
||||
* The primary entry point for loading entities via knex queries (non-data-loader methods).
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import {
|
||||
Entity,
|
||||
import type {
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
IEntityClass,
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Entity } from '@expo/entity';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader';
|
||||
import type { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import type { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader.ts';
|
||||
import {
|
||||
knexLoader as knexLoaderFn,
|
||||
knexLoaderWithAuthorizationResults as knexLoaderWithAuthorizationResultsFn,
|
||||
} from './knexLoader';
|
||||
} from './knexLoader.ts';
|
||||
|
||||
/**
|
||||
* Abstract base class for mutable entities backed by Postgres.
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import {
|
||||
EntityConfiguration,
|
||||
FieldTransformer,
|
||||
FieldTransformerMap,
|
||||
getDatabaseFieldForEntityField,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { EntityConfiguration, FieldTransformer, FieldTransformerMap } from '@expo/entity';
|
||||
import { getDatabaseFieldForEntityField } from '@expo/entity';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
import type {
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
TableQuerySelectionModifiers,
|
||||
} from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
TableQuerySelectionModifiers,
|
||||
} from './BasePostgresEntityDatabaseAdapter';
|
||||
import { JSONArrayField, MaybeJSONArrayField } from './EntityFields';
|
||||
import { PostgresEntityDatabaseAdapterConfiguration } from './PostgresEntityDatabaseAdapterProvider';
|
||||
import { SQLFragment } from './SQLOperator';
|
||||
import { wrapNativePostgresCallAsync } from './errors/wrapNativePostgresCallAsync';
|
||||
} from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { JSONArrayField, MaybeJSONArrayField } from './EntityFields.ts';
|
||||
import type { PostgresEntityDatabaseAdapterConfiguration } from './PostgresEntityDatabaseAdapterProvider.ts';
|
||||
import type { SQLFragment } from './SQLOperator.ts';
|
||||
import { wrapNativePostgresCallAsync } from './errors/wrapNativePostgresCallAsync.ts';
|
||||
|
||||
export class PostgresEntityDatabaseAdapter<
|
||||
TFields extends Record<string, any>,
|
||||
@@ -212,18 +210,6 @@ export class PostgresEntityDatabaseAdapter<
|
||||
return await wrapNativePostgresCallAsync(() => query);
|
||||
}
|
||||
|
||||
protected async fetchManyByRawWhereClauseInternalAsync(
|
||||
queryInterface: Knex,
|
||||
tableName: string,
|
||||
rawWhereClause: string,
|
||||
bindings: object | any[],
|
||||
querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Promise<object[]> {
|
||||
let query = queryInterface.select().from(tableName).whereRaw(rawWhereClause, bindings);
|
||||
query = this.applyQueryModifiersToQuery(query, querySelectionModifiers);
|
||||
return await wrapNativePostgresCallAsync(() => query);
|
||||
}
|
||||
|
||||
protected async fetchManyBySQLFragmentInternalAsync(
|
||||
queryInterface: Knex,
|
||||
tableName: string,
|
||||
@@ -259,10 +245,11 @@ export class PostgresEntityDatabaseAdapter<
|
||||
tableIdField: string,
|
||||
id: any,
|
||||
object: object,
|
||||
): Promise<object[]> {
|
||||
return await wrapNativePostgresCallAsync(() =>
|
||||
queryInterface.update(object).into(tableName).where(tableIdField, id).returning('*'),
|
||||
): Promise<{ updatedRowCount: number }> {
|
||||
const updatedRowCount = await wrapNativePostgresCallAsync(() =>
|
||||
queryInterface.update(object).into(tableName).where(tableIdField, id),
|
||||
);
|
||||
return { updatedRowCount };
|
||||
}
|
||||
|
||||
protected async deleteInternalAsync(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
EntityDatabaseAdapter,
|
||||
IEntityDatabaseAdapterProvider,
|
||||
} from '@expo/entity';
|
||||
|
||||
import { PostgresEntityDatabaseAdapter } from './PostgresEntityDatabaseAdapter';
|
||||
import { PostgresEntityDatabaseAdapter } from './PostgresEntityDatabaseAdapter.ts';
|
||||
|
||||
export interface PostgresEntityDatabaseAdapterConfiguration {
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
EntityQueryContextProvider,
|
||||
TransactionConfig,
|
||||
TransactionIsolationLevel,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { TransactionConfig } from '@expo/entity';
|
||||
import { EntityQueryContextProvider, TransactionIsolationLevel } from '@expo/entity';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
/**
|
||||
* Query context provider for knex (postgres).
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {
|
||||
import type {
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
IEntityClass,
|
||||
ReadonlyEntity,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { ReadonlyEntity } from '@expo/entity';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader';
|
||||
import type { AuthorizationResultBasedKnexEntityLoader } from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import type { EnforcingKnexEntityLoader } from './EnforcingKnexEntityLoader.ts';
|
||||
import {
|
||||
knexLoader as knexLoaderFn,
|
||||
knexLoaderWithAuthorizationResults as knexLoaderWithAuthorizationResultsFn,
|
||||
} from './knexLoader';
|
||||
} from './knexLoader.ts';
|
||||
|
||||
/**
|
||||
* Abstract base class for readonly entities backed by Postgres.
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+5
-4
@@ -1,10 +1,11 @@
|
||||
import { createWithUniqueConstraintRecoveryAsync, ViewerContext } from '@expo/entity';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import knex, { Knex } from 'knex';
|
||||
import nullthrows from 'nullthrows';
|
||||
import type { Knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
|
||||
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
||||
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity.ts';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
describe(createWithUniqueConstraintRecoveryAsync, () => {
|
||||
let knexInstance: Knex;
|
||||
|
||||
+85
-132
@@ -4,23 +4,23 @@ import {
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { createUnitTestEntityCompanionProvider } from '@expo/entity-testing-utils';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { enforceAsyncResult } from '@expo/results';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals';
|
||||
import { knex, Knex } from 'knex';
|
||||
import nullthrows from 'nullthrows';
|
||||
import type { Knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
|
||||
import { PaginationSpecification } from '../AuthorizationResultBasedKnexEntityLoader';
|
||||
import { NullsOrdering, OrderByOrdering } from '../BasePostgresEntityDatabaseAdapter';
|
||||
import { PaginationStrategy } from '../PaginationStrategy';
|
||||
import { entityField, unsafeRaw, sql, SQLFragmentHelpers, SQLFragment } from '../SQLOperator';
|
||||
import {
|
||||
PostgresTestEntity,
|
||||
PostgresTestEntityFields,
|
||||
} from '../__testfixtures__/PostgresTestEntity';
|
||||
import { PostgresTriggerTestEntity } from '../__testfixtures__/PostgresTriggerTestEntity';
|
||||
import { PostgresValidatorTestEntity } from '../__testfixtures__/PostgresValidatorTestEntity';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
||||
import type { PaginationSpecification } from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { NullsOrdering, OrderByOrdering } from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { PaginationStrategy } from '../PaginationStrategy.ts';
|
||||
import type { SQLFragment } from '../SQLOperator.ts';
|
||||
import { entityField, sql, SQLExpression, unsafeRaw } from '../SQLOperator.ts';
|
||||
import type { PostgresTestEntityFields } from '../__testfixtures__/PostgresTestEntity.ts';
|
||||
import { PostgresTestEntity } from '../__testfixtures__/PostgresTestEntity.ts';
|
||||
import { PostgresTriggerTestEntity } from '../__testfixtures__/PostgresTriggerTestEntity.ts';
|
||||
import { PostgresValidatorTestEntity } from '../__testfixtures__/PostgresValidatorTestEntity.ts';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
describe('postgres entity integration', () => {
|
||||
let knexInstance: Knex;
|
||||
@@ -456,7 +456,7 @@ describe('postgres entity integration', () => {
|
||||
|
||||
it('supports SQL helper functions', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const { and, or, eq, neq, inArray } = SQLFragmentHelpers;
|
||||
const { and, or, eq, neq, inArray } = SQLExpression;
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
@@ -523,7 +523,7 @@ describe('postgres entity integration', () => {
|
||||
|
||||
it('handles empty-array and empty-condition edge cases with TRUE/FALSE', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
const { and, or, inArray } = SQLFragmentHelpers;
|
||||
const { and, or, inArray } = SQLExpression;
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
@@ -770,7 +770,7 @@ describe('postgres entity integration', () => {
|
||||
sql`(has_a_cat = ${true} AND has_a_dog = ${true})`,
|
||||
];
|
||||
const joinedResults = await PostgresTestEntity.knexLoader(vc1)
|
||||
.loadManyBySQL(SQLFragmentHelpers.or<PostgresTestEntityFields>(...conditions))
|
||||
.loadManyBySQL(SQLExpression.or<PostgresTestEntityFields>(...conditions))
|
||||
.orderBy('name', OrderByOrdering.ASCENDING)
|
||||
.executeAsync();
|
||||
|
||||
@@ -1085,6 +1085,49 @@ describe('postgres entity integration', () => {
|
||||
expect(results.map((e) => e.getField('name'))).toEqual(['alpha', 'gamma', 'beta']);
|
||||
});
|
||||
|
||||
it('supports fieldFragment orderBy with entityField', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'alpha')
|
||||
.setField('hasACat', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'beta')
|
||||
.setField('hasACat', false)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'gamma')
|
||||
.setField('hasACat', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
// Order by entityField references, which translate entity field names to DB column names
|
||||
const results = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
).loadManyByFieldEqualityConjunctionAsync([], {
|
||||
orderBy: [
|
||||
{
|
||||
fieldFragment: sql`${entityField('hasACat')}`,
|
||||
order: OrderByOrdering.DESCENDING,
|
||||
},
|
||||
{
|
||||
fieldFragment: sql`${entityField('name')}`,
|
||||
order: OrderByOrdering.ASCENDING,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(results).toHaveLength(3);
|
||||
expect(results.map((e) => e.getField('name'))).toEqual(['alpha', 'gamma', 'beta']);
|
||||
});
|
||||
|
||||
it('rejects fieldFragment containing trailing ASC or DESC', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
@@ -1165,122 +1208,6 @@ describe('postgres entity integration', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('raw where clause loading', () => {
|
||||
it('loads by raw where clause', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'hello')
|
||||
.setField('hasACat', false)
|
||||
.setField('hasADog', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
const results = await PostgresTestEntity.knexLoader(vc1).loadManyByRawWhereClauseAsync(
|
||||
'name = ?',
|
||||
['hello'],
|
||||
);
|
||||
|
||||
expect(results).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('throws with invalid where clause', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'hello')
|
||||
.setField('hasACat', false)
|
||||
.setField('hasADog', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc1).loadManyByRawWhereClauseAsync('invalid_column = ?', [
|
||||
'hello',
|
||||
]),
|
||||
).rejects.toThrow();
|
||||
});
|
||||
|
||||
it('supports query modifiers', async () => {
|
||||
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'a')
|
||||
.setField('hasADog', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'b')
|
||||
.setField('hasADog', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
await enforceAsyncResult(
|
||||
PostgresTestEntity.creatorWithAuthorizationResults(vc1)
|
||||
.setField('name', 'c')
|
||||
.setField('hasADog', true)
|
||||
.createAsync(),
|
||||
);
|
||||
|
||||
const results = await PostgresTestEntity.knexLoader(vc1).loadManyByRawWhereClauseAsync(
|
||||
'has_a_dog = ?',
|
||||
[true],
|
||||
{
|
||||
limit: 2,
|
||||
offset: 1,
|
||||
orderBy: [
|
||||
{
|
||||
fieldName: 'name',
|
||||
order: OrderByOrdering.ASCENDING,
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
expect(results).toHaveLength(2);
|
||||
expect(results.map((e) => e.getField('name'))).toEqual(['b', 'c']);
|
||||
|
||||
const resultsMultipleOrderBy = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
).loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
||||
orderBy: [
|
||||
{
|
||||
fieldName: 'hasADog',
|
||||
order: OrderByOrdering.ASCENDING,
|
||||
},
|
||||
{
|
||||
fieldName: 'name',
|
||||
order: OrderByOrdering.DESCENDING,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(resultsMultipleOrderBy).toHaveLength(3);
|
||||
expect(resultsMultipleOrderBy.map((e) => e.getField('name'))).toEqual(['c', 'b', 'a']);
|
||||
|
||||
const resultsOrderByRaw = await PostgresTestEntity.knexLoader(
|
||||
vc1,
|
||||
).loadManyByRawWhereClauseAsync('has_a_dog = ?', [true], {
|
||||
orderBy: [
|
||||
{
|
||||
fieldFragment: sql`${entityField('hasADog')}`,
|
||||
order: OrderByOrdering.ASCENDING,
|
||||
},
|
||||
{
|
||||
fieldFragment: sql`${entityField('name')}`,
|
||||
order: OrderByOrdering.DESCENDING,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(resultsOrderByRaw).toHaveLength(3);
|
||||
expect(resultsOrderByRaw.map((e) => e.getField('name'))).toEqual(['c', 'b', 'a']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('trigger transaction behavior', () => {
|
||||
describe('create', () => {
|
||||
it('rolls back transaction when trigger throws except afterCommit', async () => {
|
||||
@@ -2196,6 +2123,32 @@ describe('postgres entity integration', () => {
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Cursor is missing required 'id' field.");
|
||||
|
||||
// Try with valid base64-encoded JSON that decodes to a non-object primitive
|
||||
const primitiveCursor = Buffer.from(JSON.stringify(12345)).toString('base64url');
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc).loadPageAsync({
|
||||
first: 10,
|
||||
after: primitiveCursor,
|
||||
pagination: {
|
||||
strategy: PaginationStrategy.STANDARD,
|
||||
orderBy: [],
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Cursor is missing required 'id' field.");
|
||||
|
||||
// Try with valid base64-encoded JSON string primitive
|
||||
const stringPrimitiveCursor = Buffer.from(JSON.stringify('hello')).toString('base64url');
|
||||
await expect(
|
||||
PostgresTestEntity.knexLoader(vc).loadPageAsync({
|
||||
first: 10,
|
||||
after: stringPrimitiveCursor,
|
||||
pagination: {
|
||||
strategy: PaginationStrategy.STANDARD,
|
||||
orderBy: [],
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("Cursor is missing required 'id' field.");
|
||||
});
|
||||
|
||||
it('performs pagination with both loader types', async () => {
|
||||
|
||||
+6
-5
@@ -1,11 +1,12 @@
|
||||
import { TransactionalDataLoaderMode, ViewerContext } from '@expo/entity';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals';
|
||||
import { knex, Knex } from 'knex';
|
||||
import nullthrows from 'nullthrows';
|
||||
import type { Knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
|
||||
import { PostgresEntityQueryContextProvider } from '../PostgresEntityQueryContextProvider';
|
||||
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
||||
import { PostgresEntityQueryContextProvider } from '../PostgresEntityQueryContextProvider.ts';
|
||||
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity.ts';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
describe(PostgresEntityQueryContextProvider, () => {
|
||||
let knexInstance: Knex;
|
||||
|
||||
+5
-4
@@ -1,11 +1,12 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { enforceAsyncResult } from '@expo/results';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import { knex, Knex } from 'knex';
|
||||
import nullthrows from 'nullthrows';
|
||||
import type { Knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
|
||||
import { InvalidTestEntity } from '../__testfixtures__/InvalidTestEntity';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
||||
import { InvalidTestEntity } from '../__testfixtures__/InvalidTestEntity.ts';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
describe('postgres entity integration', () => {
|
||||
let knexInstance: Knex;
|
||||
|
||||
@@ -8,12 +8,13 @@ import {
|
||||
EntityDatabaseAdapterUnknownError,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import nullthrows from '@expo/nullthrows';
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
||||
import { knex, Knex } from 'knex';
|
||||
import nullthrows from 'nullthrows';
|
||||
import type { Knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
|
||||
import { ErrorsTestEntity } from '../__testfixtures__/ErrorsTestEntity';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
||||
import { ErrorsTestEntity } from '../__testfixtures__/ErrorsTestEntity.ts';
|
||||
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts';
|
||||
|
||||
describe('postgres errors', () => {
|
||||
let knexInstance: Knex;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
StringField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
type ErrorsTestEntityFields = {
|
||||
id: number;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
StringField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
type InvalidTestEntityFields = {
|
||||
id: number;
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
BooleanField,
|
||||
BufferField,
|
||||
DateField,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
JSONObjectField,
|
||||
StringArrayField,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
BufferField,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
import { BigIntField, JSONArrayField, MaybeJSONArrayField } from '../EntityFields';
|
||||
import { PostgresEntity } from '../PostgresEntity';
|
||||
import { BigIntField, JSONArrayField, MaybeJSONArrayField } from '../EntityFields.ts';
|
||||
import { PostgresEntity } from '../PostgresEntity.ts';
|
||||
|
||||
export type PostgresTestEntityFields = {
|
||||
id: string;
|
||||
|
||||
+7
-5
@@ -1,18 +1,20 @@
|
||||
import type {
|
||||
EntityCompanionDefinition,
|
||||
EntityQueryContext,
|
||||
EntityTriggerMutationInfo,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityMutationTrigger,
|
||||
EntityNonTransactionalMutationTrigger,
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
EntityTriggerMutationInfo,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
type PostgresTriggerTestEntityFields = {
|
||||
id: string;
|
||||
|
||||
+6
-4
@@ -1,15 +1,17 @@
|
||||
import type {
|
||||
EntityCompanionDefinition,
|
||||
EntityTransactionalQueryContext,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
EntityTransactionalQueryContext,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
type PostgresUniqueTestEntityFields = {
|
||||
id: string;
|
||||
|
||||
+7
-5
@@ -1,17 +1,19 @@
|
||||
import type {
|
||||
EntityCompanionDefinition,
|
||||
EntityQueryContext,
|
||||
EntityValidatorMutationInfo,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
Entity,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityMutationTrigger,
|
||||
EntityPrivacyPolicy,
|
||||
EntityQueryContext,
|
||||
EntityValidatorMutationInfo,
|
||||
StringField,
|
||||
UUIDField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
type PostgresValidatorTestEntityFields = {
|
||||
id: string;
|
||||
|
||||
+5
-8
@@ -1,13 +1,10 @@
|
||||
import {
|
||||
EntityCompanionProvider,
|
||||
IEntityMetricsAdapter,
|
||||
NoOpEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityCompanionProvider, NoOpEntityMetricsAdapter } from '@expo/entity';
|
||||
import { InMemoryFullCacheStubCacheAdapterProvider } from '@expo/entity-testing-utils';
|
||||
import { Knex } from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
import { PostgresEntityDatabaseAdapterProvider } from '../PostgresEntityDatabaseAdapterProvider';
|
||||
import { PostgresEntityQueryContextProvider } from '../PostgresEntityQueryContextProvider';
|
||||
import { PostgresEntityDatabaseAdapterProvider } from '../PostgresEntityDatabaseAdapterProvider.ts';
|
||||
import { PostgresEntityQueryContextProvider } from '../PostgresEntityQueryContextProvider.ts';
|
||||
|
||||
export const createKnexIntegrationTestEntityCompanionProvider = (
|
||||
knex: Knex,
|
||||
|
||||
+12
-89
@@ -1,32 +1,30 @@
|
||||
import {
|
||||
import type {
|
||||
EntityPrivacyPolicyEvaluationContext,
|
||||
ViewerContext,
|
||||
enforceResultsAsync,
|
||||
IEntityMetricsAdapter,
|
||||
EntityConstructionUtils,
|
||||
EntityQueryContext,
|
||||
IEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import { enforceResultsAsync, EntityConstructionUtils, ViewerContext } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { anyOfClass, anything, instance, mock, spy, verify, when } from 'ts-mockito';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader';
|
||||
import { OrderByOrdering } from '../BasePostgresEntityDatabaseAdapter';
|
||||
import { PaginationStrategy } from '../PaginationStrategy';
|
||||
import { sql } from '../SQLOperator';
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { OrderByOrdering } from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { PaginationStrategy } from '../PaginationStrategy.ts';
|
||||
import { sql } from '../SQLOperator.ts';
|
||||
import { EntityKnexDataManager } from '../internal/EntityKnexDataManager.ts';
|
||||
import type { TestFields } from './fixtures/TestEntity.ts';
|
||||
import {
|
||||
TestEntity,
|
||||
testEntityConfiguration,
|
||||
TestEntityPrivacyPolicy,
|
||||
TestFields,
|
||||
} from './fixtures/TestEntity';
|
||||
} from './fixtures/TestEntity.ts';
|
||||
import type { TestPaginationFields } from './fixtures/TestPaginationEntity.ts';
|
||||
import {
|
||||
TestPaginationEntity,
|
||||
testPaginationEntityConfiguration,
|
||||
TestPaginationPrivacyPolicy,
|
||||
TestPaginationFields,
|
||||
} from './fixtures/TestPaginationEntity';
|
||||
import { EntityKnexDataManager } from '../internal/EntityKnexDataManager';
|
||||
} from './fixtures/TestPaginationEntity.ts';
|
||||
|
||||
describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
it('loads entities with loadManyByFieldEqualityConjunction', async () => {
|
||||
@@ -207,81 +205,6 @@ describe(AuthorizationResultBasedKnexEntityLoader, () => {
|
||||
).once();
|
||||
});
|
||||
|
||||
it('loads entities with loadManyByRawWhereClauseAsync', async () => {
|
||||
const privacyPolicy = new TestEntityPrivacyPolicy();
|
||||
const spiedPrivacyPolicy = spy(privacyPolicy);
|
||||
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);
|
||||
when(
|
||||
knexDataManagerMock.loadManyByRawWhereClauseAsync(
|
||||
queryContext,
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([
|
||||
{
|
||||
customIdField: 'id',
|
||||
stringField: 'huh',
|
||||
intField: 4,
|
||||
testIndexedField: '4',
|
||||
dateField: new Date(),
|
||||
nullableField: null,
|
||||
},
|
||||
]);
|
||||
const knexDataManager = instance(knexDataManagerMock);
|
||||
|
||||
const constructionUtils = new EntityConstructionUtils(
|
||||
viewerContext,
|
||||
queryContext,
|
||||
privacyPolicyEvaluationContext,
|
||||
testEntityConfiguration,
|
||||
TestEntity,
|
||||
/* entitySelectedFields */ undefined,
|
||||
privacyPolicy,
|
||||
metricsAdapter,
|
||||
);
|
||||
const knexEntityLoader = new AuthorizationResultBasedKnexEntityLoader(
|
||||
queryContext,
|
||||
knexDataManager,
|
||||
metricsAdapter,
|
||||
constructionUtils,
|
||||
);
|
||||
|
||||
const result = await knexEntityLoader.loadManyByRawWhereClauseAsync('id = ?', [1], {
|
||||
orderBy: [{ fieldName: 'testIndexedField', order: OrderByOrdering.DESCENDING }],
|
||||
});
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]).not.toBeNull();
|
||||
expect(result[0]!.ok).toBe(true);
|
||||
expect(result[0]!.enforceValue().getField('testIndexedField')).toEqual('4');
|
||||
|
||||
verify(
|
||||
spiedPrivacyPolicy.authorizeReadAsync(
|
||||
viewerContext,
|
||||
queryContext,
|
||||
privacyPolicyEvaluationContext,
|
||||
anyOfClass(TestEntity),
|
||||
anything(),
|
||||
),
|
||||
).once();
|
||||
});
|
||||
|
||||
describe('loads entities with loadManyBySQL', () => {
|
||||
it('returns entities with authorization results', async () => {
|
||||
const privacyPolicy = new TestEntityPrivacyPolicy();
|
||||
|
||||
+11
-33
@@ -1,13 +1,15 @@
|
||||
import { EntityQueryContext, FieldTransformerMap } from '@expo/entity';
|
||||
import type { FieldTransformerMap } from '@expo/entity';
|
||||
import { EntityQueryContext } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
import { instance, mock } from 'ts-mockito';
|
||||
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
import type {
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
} from '../BasePostgresEntityDatabaseAdapter';
|
||||
import { testEntityConfiguration, TestFields } from './fixtures/TestEntity';
|
||||
} from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import { BasePostgresEntityDatabaseAdapter } from '../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import type { TestFields } from './fixtures/TestEntity.ts';
|
||||
import { testEntityConfiguration } from './fixtures/TestEntity.ts';
|
||||
|
||||
class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
TestFields,
|
||||
@@ -16,9 +18,8 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
private readonly fetchResults: object[];
|
||||
private readonly fetchOneResult: object | null;
|
||||
private readonly insertResults: object[];
|
||||
private readonly updateResults: object[];
|
||||
private readonly updateResults: { updatedRowCount: number };
|
||||
private readonly fetchEqualityConditionResults: object[];
|
||||
private readonly fetchRawWhereResults: object[];
|
||||
private readonly fetchSQLFragmentResults: object[];
|
||||
private readonly deleteCount: number;
|
||||
|
||||
@@ -26,18 +27,16 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
fetchResults = [],
|
||||
fetchOneResult = null,
|
||||
insertResults = [],
|
||||
updateResults = [],
|
||||
updateResults = { updatedRowCount: 0 },
|
||||
fetchEqualityConditionResults = [],
|
||||
fetchRawWhereResults = [],
|
||||
fetchSQLFragmentResults = [],
|
||||
deleteCount = 0,
|
||||
}: {
|
||||
fetchResults?: object[];
|
||||
fetchOneResult?: object | null;
|
||||
insertResults?: object[];
|
||||
updateResults?: object[];
|
||||
updateResults?: { updatedRowCount: number };
|
||||
fetchEqualityConditionResults?: object[];
|
||||
fetchRawWhereResults?: object[];
|
||||
fetchSQLFragmentResults?: object[];
|
||||
deleteCount?: number;
|
||||
}) {
|
||||
@@ -47,7 +46,6 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
this.insertResults = insertResults;
|
||||
this.updateResults = updateResults;
|
||||
this.fetchEqualityConditionResults = fetchEqualityConditionResults;
|
||||
this.fetchRawWhereResults = fetchRawWhereResults;
|
||||
this.fetchSQLFragmentResults = fetchSQLFragmentResults;
|
||||
this.deleteCount = deleteCount;
|
||||
}
|
||||
@@ -74,15 +72,6 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
return this.fetchOneResult;
|
||||
}
|
||||
|
||||
protected async fetchManyByRawWhereClauseInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
_rawWhereClause: string,
|
||||
_bindings: object | any[],
|
||||
): Promise<object[]> {
|
||||
return this.fetchRawWhereResults;
|
||||
}
|
||||
|
||||
protected async fetchManyBySQLFragmentInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
@@ -114,7 +103,7 @@ class TestEntityDatabaseAdapter extends BasePostgresEntityDatabaseAdapter<
|
||||
_tableIdField: string,
|
||||
_id: any,
|
||||
_object: object,
|
||||
): Promise<object[]> {
|
||||
): Promise<{ updatedRowCount: number }> {
|
||||
return this.updateResults;
|
||||
}
|
||||
|
||||
@@ -146,15 +135,4 @@ describe(BasePostgresEntityDatabaseAdapter, () => {
|
||||
expect(results).toEqual([{ stringField: 'hello' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchManyWithRawWhereClause', () => {
|
||||
it('transforms object', async () => {
|
||||
const queryContext = instance(mock(EntityQueryContext));
|
||||
const adapter = new TestEntityDatabaseAdapter({
|
||||
fetchRawWhereResults: [{ string_field: 'hello' }],
|
||||
});
|
||||
const results = await adapter.fetchManyByRawWhereClauseAsync(queryContext, 'hello', [], {});
|
||||
expect(results).toEqual([{ stringField: 'hello' }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
+7
-58
@@ -1,4 +1,5 @@
|
||||
import { EntityConstructionUtils, EntityQueryContext, IEntityMetricsAdapter } from '@expo/entity';
|
||||
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';
|
||||
@@ -6,11 +7,11 @@ import { anything, instance, mock, when } from 'ts-mockito';
|
||||
import {
|
||||
AuthorizationResultBasedKnexEntityLoader,
|
||||
AuthorizationResultBasedSQLQueryBuilder,
|
||||
} from '../AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader';
|
||||
import { PaginationStrategy } from '../PaginationStrategy';
|
||||
import { sql } from '../SQLOperator';
|
||||
import { EntityKnexDataManager } from '../internal/EntityKnexDataManager';
|
||||
} from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader.ts';
|
||||
import { PaginationStrategy } from '../PaginationStrategy.ts';
|
||||
import { sql } from '../SQLOperator.ts';
|
||||
import { EntityKnexDataManager } from '../internal/EntityKnexDataManager.ts';
|
||||
|
||||
describe(EnforcingKnexEntityLoader, () => {
|
||||
describe('loadFirstByFieldEqualityConjunction', () => {
|
||||
@@ -136,58 +137,6 @@ describe(EnforcingKnexEntityLoader, () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyByRawWhereClause', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
AuthorizationResultBasedKnexEntityLoader<any, any, any, any, any, any>,
|
||||
);
|
||||
const rejection = new Error();
|
||||
when(
|
||||
nonEnforcingKnexEntityLoaderMock.loadManyByRawWhereClauseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([result(rejection)]);
|
||||
const nonEnforcingKnexEntityLoader = instance(nonEnforcingKnexEntityLoaderMock);
|
||||
const enforcingKnexEntityLoader = new EnforcingKnexEntityLoader(
|
||||
nonEnforcingKnexEntityLoader,
|
||||
instance(mock(EntityQueryContext)),
|
||||
instance(mock(EntityKnexDataManager)),
|
||||
instance(mock<IEntityMetricsAdapter>()),
|
||||
instance(mock(EntityConstructionUtils)),
|
||||
);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByRawWhereClauseAsync(anything(), anything(), anything()),
|
||||
).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.loadManyByRawWhereClauseAsync(
|
||||
anything(),
|
||||
anything(),
|
||||
anything(),
|
||||
),
|
||||
).thenResolve([result(resolved)]);
|
||||
const nonEnforcingKnexEntityLoader = instance(nonEnforcingKnexEntityLoaderMock);
|
||||
const enforcingKnexEntityLoader = new EnforcingKnexEntityLoader(
|
||||
nonEnforcingKnexEntityLoader,
|
||||
instance(mock(EntityQueryContext)),
|
||||
instance(mock(EntityKnexDataManager)),
|
||||
instance(mock<IEntityMetricsAdapter>()),
|
||||
instance(mock(EntityConstructionUtils)),
|
||||
);
|
||||
await expect(
|
||||
enforcingKnexEntityLoader.loadManyByRawWhereClauseAsync(anything(), anything(), anything()),
|
||||
).resolves.toEqual([resolved]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadManyBySQL', () => {
|
||||
it('throws when result is unsuccessful', async () => {
|
||||
const nonEnforcingKnexEntityLoaderMock = mock(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describeFieldTestCase } from '@expo/entity-testing-utils';
|
||||
|
||||
import { BigIntField, JSONArrayField, MaybeJSONArrayField } from '../EntityFields';
|
||||
import { BigIntField, JSONArrayField, MaybeJSONArrayField } from '../EntityFields.ts';
|
||||
|
||||
describeFieldTestCase(
|
||||
new JSONArrayField({ columnName: 'wat' }),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EntityCompanionDefinition } from '@expo/entity';
|
||||
import {
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
StringField,
|
||||
@@ -9,11 +9,11 @@ import {
|
||||
} from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader';
|
||||
import { PostgresEntity } from '../PostgresEntity';
|
||||
import { ReadonlyPostgresEntity } from '../ReadonlyPostgresEntity';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider';
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader.ts';
|
||||
import { PostgresEntity } from '../PostgresEntity.ts';
|
||||
import { ReadonlyPostgresEntity } from '../ReadonlyPostgresEntity.ts';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider.ts';
|
||||
|
||||
type TestPostgresFields = {
|
||||
id: string;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ViewerContext } from '@expo/entity';
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader';
|
||||
import { knexLoader, knexLoaderWithAuthorizationResults } from '../knexLoader';
|
||||
import { TestEntity } from './fixtures/TestEntity';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider';
|
||||
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader.ts';
|
||||
import { knexLoader, knexLoaderWithAuthorizationResults } from '../knexLoader.ts';
|
||||
import { TestEntity } from './fixtures/TestEntity.ts';
|
||||
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider.ts';
|
||||
|
||||
describe('knexLoader', () => {
|
||||
describe('knexLoader', () => {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+12
-21
@@ -1,7 +1,6 @@
|
||||
import type { EntityConfiguration, FieldTransformerMap } from '@expo/entity';
|
||||
import {
|
||||
computeIfAbsent,
|
||||
EntityConfiguration,
|
||||
FieldTransformerMap,
|
||||
getDatabaseFieldForEntityField,
|
||||
IntField,
|
||||
mapMap,
|
||||
@@ -11,16 +10,18 @@ import {
|
||||
import invariant from 'invariant';
|
||||
import { v7 as uuidv7 } from 'uuid';
|
||||
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
import type {
|
||||
TableFieldMultiValueEqualityCondition,
|
||||
TableFieldSingleValueEqualityCondition,
|
||||
TableOrderByClause,
|
||||
TableQuerySelectionModifiers,
|
||||
} from '../../BasePostgresEntityDatabaseAdapter';
|
||||
import { SQLFragment } from '../../SQLOperator';
|
||||
} from '../../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import {
|
||||
BasePostgresEntityDatabaseAdapter,
|
||||
NullsOrdering,
|
||||
OrderByOrdering,
|
||||
} from '../../BasePostgresEntityDatabaseAdapter.ts';
|
||||
import type { SQLFragment } from '../../SQLOperator.ts';
|
||||
|
||||
export class StubPostgresDatabaseAdapter<
|
||||
TFields extends Record<string, any>,
|
||||
@@ -192,16 +193,6 @@ export class StubPostgresDatabaseAdapter<
|
||||
return filteredObjects;
|
||||
}
|
||||
|
||||
protected fetchManyByRawWhereClauseInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
_rawWhereClause: string,
|
||||
_bindings: object | any[],
|
||||
_querySelectionModifiers: TableQuerySelectionModifiers<TFields>,
|
||||
): Promise<object[]> {
|
||||
throw new Error('Raw WHERE clauses not supported for StubDatabaseAdapter');
|
||||
}
|
||||
|
||||
protected fetchManyBySQLFragmentInternalAsync(
|
||||
_queryInterface: any,
|
||||
_tableName: string,
|
||||
@@ -253,7 +244,7 @@ export class StubPostgresDatabaseAdapter<
|
||||
tableIdField: string,
|
||||
id: any,
|
||||
object: object,
|
||||
): Promise<object[]> {
|
||||
): Promise<{ updatedRowCount: number }> {
|
||||
// SQL does not support empty updates, mirror behavior here for better test simulation
|
||||
if (Object.keys(object).length === 0) {
|
||||
throw new Error(`Empty update (${tableIdField} = ${id})`);
|
||||
@@ -268,14 +259,14 @@ export class StubPostgresDatabaseAdapter<
|
||||
// SQL updates to a nonexistent row succeed but affect 0 rows,
|
||||
// mirror that behavior here for better test simulation
|
||||
if (objectIndex < 0) {
|
||||
return [];
|
||||
return { updatedRowCount: 0 };
|
||||
}
|
||||
|
||||
objectCollection[objectIndex] = {
|
||||
...objectCollection[objectIndex],
|
||||
...object,
|
||||
};
|
||||
return [objectCollection[objectIndex]];
|
||||
return { updatedRowCount: 1 };
|
||||
}
|
||||
|
||||
protected async deleteInternalAsync(
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
import {
|
||||
import type {
|
||||
EntityConfiguration,
|
||||
EntityDatabaseAdapter,
|
||||
IEntityDatabaseAdapterProvider,
|
||||
} from '@expo/entity';
|
||||
|
||||
import { StubPostgresDatabaseAdapter } from './StubPostgresDatabaseAdapter';
|
||||
import { StubPostgresDatabaseAdapter } from './StubPostgresDatabaseAdapter.ts';
|
||||
|
||||
export class StubPostgresDatabaseAdapterProvider implements IEntityDatabaseAdapterProvider {
|
||||
private readonly objectCollection = new Map();
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { EntityCompanionDefinition, ViewerContext } from '@expo/entity';
|
||||
import {
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
DateField,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
StringField,
|
||||
UUIDField,
|
||||
EntityPrivacyPolicy,
|
||||
ViewerContext,
|
||||
AlwaysAllowPrivacyPolicyRule,
|
||||
} from '@expo/entity';
|
||||
import { result, Result } from '@expo/results';
|
||||
import type { Result } from '@expo/results';
|
||||
import { result } from '@expo/results';
|
||||
|
||||
import { PostgresEntity } from '../../PostgresEntity';
|
||||
import { PostgresEntity } from '../../PostgresEntity.ts';
|
||||
|
||||
export type TestFields = {
|
||||
customIdField: string;
|
||||
|
||||
+9
-7
@@ -1,18 +1,20 @@
|
||||
import {
|
||||
import type {
|
||||
EntityCompanionDefinition,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
ViewerContext,
|
||||
EntityPrivacyPolicyEvaluationContext,
|
||||
EntityQueryContext,
|
||||
UUIDField,
|
||||
StringField,
|
||||
ViewerContext,
|
||||
} from '@expo/entity';
|
||||
import {
|
||||
DateField,
|
||||
EntityConfiguration,
|
||||
EntityPrivacyPolicy,
|
||||
IntField,
|
||||
RuleEvaluationResult,
|
||||
StringField,
|
||||
UUIDField,
|
||||
} from '@expo/entity';
|
||||
|
||||
import { PostgresEntity } from '../../PostgresEntity';
|
||||
import { PostgresEntity } from '../../PostgresEntity.ts';
|
||||
|
||||
export interface TestPaginationFields {
|
||||
id: string;
|
||||
|
||||
+3
-6
@@ -1,14 +1,11 @@
|
||||
import {
|
||||
EntityCompanionProvider,
|
||||
IEntityMetricsAdapter,
|
||||
NoOpEntityMetricsAdapter,
|
||||
} from '@expo/entity';
|
||||
import type { IEntityMetricsAdapter } from '@expo/entity';
|
||||
import { EntityCompanionProvider, NoOpEntityMetricsAdapter } from '@expo/entity';
|
||||
import {
|
||||
InMemoryFullCacheStubCacheAdapterProvider,
|
||||
StubQueryContextProvider,
|
||||
} from '@expo/entity-testing-utils';
|
||||
|
||||
import { StubPostgresDatabaseAdapterProvider } from './StubPostgresDatabaseAdapterProvider';
|
||||
import { StubPostgresDatabaseAdapterProvider } from './StubPostgresDatabaseAdapterProvider.ts';
|
||||
|
||||
const queryContextProvider = new StubQueryContextProvider();
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from '@jest/globals';
|
||||
|
||||
import { wrapNativePostgresCallAsync } from '../wrapNativePostgresCallAsync';
|
||||
import { wrapNativePostgresCallAsync } from '../wrapNativePostgresCallAsync.ts';
|
||||
|
||||
describe(wrapNativePostgresCallAsync, () => {
|
||||
it('rethrows literals', async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { EntityDatabaseAdapterError } from '@expo/entity';
|
||||
import {
|
||||
EntityDatabaseAdapterCheckConstraintError,
|
||||
EntityDatabaseAdapterError,
|
||||
EntityDatabaseAdapterExclusionConstraintError,
|
||||
EntityDatabaseAdapterForeignKeyConstraintError,
|
||||
EntityDatabaseAdapterNotNullConstraintError,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
EntityDatabaseAdapterUniqueConstraintError,
|
||||
EntityDatabaseAdapterUnknownError,
|
||||
} from '@expo/entity';
|
||||
import { knex } from 'knex';
|
||||
import knex from 'knex';
|
||||
|
||||
function wrapNativePostgresError(
|
||||
error: Error & { code?: string },
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
* @module @expo/entity-database-adapter-knex
|
||||
*/
|
||||
|
||||
export * from './AuthorizationResultBasedKnexEntityLoader';
|
||||
export * from './BasePostgresEntityDatabaseAdapter';
|
||||
export * from './BaseSQLQueryBuilder';
|
||||
export * from './EnforcingKnexEntityLoader';
|
||||
export * from './EntityFields';
|
||||
export * from './KnexEntityLoaderFactory';
|
||||
export * from './knexLoader';
|
||||
export * from './PaginationStrategy';
|
||||
export * from './PostgresEntity';
|
||||
export * from './PostgresEntityDatabaseAdapter';
|
||||
export * from './PostgresEntityDatabaseAdapterProvider';
|
||||
export * from './PostgresEntityQueryContextProvider';
|
||||
export * from './ReadonlyPostgresEntity';
|
||||
export * from './SQLOperator';
|
||||
export * from './errors/wrapNativePostgresCallAsync';
|
||||
export * from './internal/EntityKnexDataManager';
|
||||
export * from './internal/getKnexDataManager';
|
||||
export * from './internal/getKnexEntityLoaderFactory';
|
||||
export * from './internal/utilityTypes';
|
||||
export * from './internal/weakMaps';
|
||||
export * from './AuthorizationResultBasedKnexEntityLoader.ts';
|
||||
export * from './BasePostgresEntityDatabaseAdapter.ts';
|
||||
export * from './BaseSQLQueryBuilder.ts';
|
||||
export * from './EnforcingKnexEntityLoader.ts';
|
||||
export * from './EntityFields.ts';
|
||||
export * from './KnexEntityLoaderFactory.ts';
|
||||
export * from './knexLoader.ts';
|
||||
export * from './PaginationStrategy.ts';
|
||||
export * from './PostgresEntity.ts';
|
||||
export * from './PostgresEntityDatabaseAdapter.ts';
|
||||
export * from './PostgresEntityDatabaseAdapterProvider.ts';
|
||||
export * from './PostgresEntityQueryContextProvider.ts';
|
||||
export * from './ReadonlyPostgresEntity.ts';
|
||||
export * from './SQLOperator.ts';
|
||||
export * from './errors/wrapNativePostgresCallAsync.ts';
|
||||
export * from './internal/EntityKnexDataManager.ts';
|
||||
export * from './internal/getKnexDataManager.ts';
|
||||
export * from './internal/getKnexEntityLoaderFactory.ts';
|
||||
export * from './internal/utilityTypes.ts';
|
||||
export * from './internal/weakMaps.ts';
|
||||
Loaded 100 of 312 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user