@expo/entity-database-adapter-knex 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/EntityFields.js.map +1 -0
- package/build/{PostgresEntityDatabaseAdapter.d.ts → src/PostgresEntityDatabaseAdapter.d.ts} +2 -2
- package/build/{PostgresEntityDatabaseAdapter.js → src/PostgresEntityDatabaseAdapter.js} +10 -12
- package/build/src/PostgresEntityDatabaseAdapter.js.map +1 -0
- package/build/{PostgresEntityDatabaseAdapterProvider.d.ts → src/PostgresEntityDatabaseAdapterProvider.d.ts} +2 -2
- package/build/src/PostgresEntityDatabaseAdapterProvider.js +11 -0
- package/build/src/PostgresEntityDatabaseAdapterProvider.js.map +1 -0
- package/build/{PostgresEntityQueryContextProvider.d.ts → src/PostgresEntityQueryContextProvider.d.ts} +1 -1
- package/build/{PostgresEntityQueryContextProvider.js → src/PostgresEntityQueryContextProvider.js} +2 -1
- package/build/src/PostgresEntityQueryContextProvider.js.map +1 -0
- package/build/src/__integration-tests__/EntityCreationUtils-test.d.ts +1 -0
- package/build/src/__integration-tests__/EntityCreationUtils-test.js +105 -0
- package/build/src/__integration-tests__/EntityCreationUtils-test.js.map +1 -0
- package/build/src/__integration-tests__/PostgresEntityIntegration-test.d.ts +1 -0
- package/build/src/__integration-tests__/PostgresEntityIntegration-test.js +497 -0
- package/build/src/__integration-tests__/PostgresEntityIntegration-test.js.map +1 -0
- package/build/src/__integration-tests__/PostgresEntityQueryContextProvider-test.d.ts +1 -0
- package/build/src/__integration-tests__/PostgresEntityQueryContextProvider-test.js +294 -0
- package/build/src/__integration-tests__/PostgresEntityQueryContextProvider-test.js.map +1 -0
- package/build/src/__integration-tests__/PostgresInvalidSetup-test.d.ts +1 -0
- package/build/src/__integration-tests__/PostgresInvalidSetup-test.js +70 -0
- package/build/src/__integration-tests__/PostgresInvalidSetup-test.js.map +1 -0
- package/build/src/__integration-tests__/errors-test.d.ts +1 -0
- package/build/src/__integration-tests__/errors-test.js +128 -0
- package/build/src/__integration-tests__/errors-test.js.map +1 -0
- package/build/src/__testfixtures__/ErrorsTestEntity.d.ts +24 -0
- package/build/src/__testfixtures__/ErrorsTestEntity.js +107 -0
- package/build/src/__testfixtures__/ErrorsTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/InvalidTestEntity.d.ts +19 -0
- package/build/src/__testfixtures__/InvalidTestEntity.js +62 -0
- package/build/src/__testfixtures__/InvalidTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/PostgresTestEntity.d.ts +31 -0
- package/build/src/__testfixtures__/PostgresTestEntity.js +96 -0
- package/build/src/__testfixtures__/PostgresTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/PostgresTriggerTestEntity.d.ts +19 -0
- package/build/src/__testfixtures__/PostgresTriggerTestEntity.js +101 -0
- package/build/src/__testfixtures__/PostgresTriggerTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/PostgresUniqueTestEntity.d.ts +25 -0
- package/build/src/__testfixtures__/PostgresUniqueTestEntity.js +71 -0
- package/build/src/__testfixtures__/PostgresUniqueTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/PostgresValidatorTestEntity.d.ts +19 -0
- package/build/src/__testfixtures__/PostgresValidatorTestEntity.js +77 -0
- package/build/src/__testfixtures__/PostgresValidatorTestEntity.js.map +1 -0
- package/build/src/__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.d.ts +3 -0
- package/build/src/__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.js +27 -0
- package/build/src/__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.js.map +1 -0
- package/build/src/__tests__/EntityFields-test.d.ts +1 -0
- package/build/src/__tests__/EntityFields-test.js +8 -0
- package/build/src/__tests__/EntityFields-test.js.map +1 -0
- package/build/src/errors/__tests__/wrapNativePostgresCallAsync-test.d.ts +1 -0
- package/build/src/errors/__tests__/wrapNativePostgresCallAsync-test.js +22 -0
- package/build/src/errors/__tests__/wrapNativePostgresCallAsync-test.js.map +1 -0
- package/build/src/errors/wrapNativePostgresCallAsync.d.ts +1 -0
- package/build/{errors → src/errors}/wrapNativePostgresCallAsync.js +1 -1
- package/build/src/errors/wrapNativePostgresCallAsync.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/package.json +13 -26
- package/src/PostgresEntityDatabaseAdapter.ts +5 -5
- package/src/PostgresEntityDatabaseAdapterProvider.ts +3 -5
- package/src/PostgresEntityQueryContextProvider.ts +1 -1
- package/src/__integration-tests__/EntityCreationUtils-test.ts +224 -0
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +20 -19
- package/src/__integration-tests__/PostgresEntityQueryContextProvider-test.ts +3 -2
- package/src/__integration-tests__/PostgresInvalidSetup-test.ts +5 -4
- package/src/__integration-tests__/errors-test.ts +3 -2
- package/src/__testfixtures__/ErrorsTestEntity.ts +6 -6
- package/src/__testfixtures__/InvalidTestEntity.ts +6 -10
- package/src/__testfixtures__/PostgresTestEntity.ts +8 -12
- package/src/__testfixtures__/PostgresTriggerTestEntity.ts +7 -7
- package/src/__testfixtures__/PostgresUniqueTestEntity.ts +28 -5
- package/src/__testfixtures__/PostgresValidatorTestEntity.ts +6 -6
- package/src/__testfixtures__/createKnexIntegrationTestEntityCompanionProvider.ts +4 -4
- package/src/errors/__tests__/wrapNativePostgresCallAsync-test.ts +3 -1
- package/src/errors/wrapNativePostgresCallAsync.ts +2 -2
- package/src/index.ts +4 -4
- package/build/EntityFields.js.map +0 -1
- package/build/PostgresEntityDatabaseAdapter.js.map +0 -1
- package/build/PostgresEntityDatabaseAdapterProvider.js +0 -13
- package/build/PostgresEntityDatabaseAdapterProvider.js.map +0 -1
- package/build/PostgresEntityQueryContextProvider.js.map +0 -1
- package/build/errors/wrapNativePostgresCallAsync.d.ts +0 -1
- package/build/errors/wrapNativePostgresCallAsync.js.map +0 -1
- package/build/index.d.ts +0 -9
- package/build/index.js +0 -35
- package/build/index.js.map +0 -1
- package/build/tsconfig.build.tsbuildinfo +0 -1
- /package/build/{EntityFields.d.ts → src/EntityFields.d.ts} +0 -0
- /package/build/{EntityFields.js → src/EntityFields.js} +0 -0
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/entity-database-adapter-knex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Knex database adapter for @expo/entity",
|
|
5
5
|
"files": [
|
|
6
6
|
"build",
|
|
7
7
|
"src"
|
|
8
8
|
],
|
|
9
|
-
"main": "build/index.js",
|
|
10
|
-
"types": "build/index.d.ts",
|
|
9
|
+
"main": "build/src/index.js",
|
|
10
|
+
"types": "build/src/index.d.ts",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"lint": "
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"integration": "../../resources/run-with-docker yarn integration-no-setup",
|
|
19
|
-
"integration-no-setup": "jest --config ../../resources/jest-integration.config.js --rootDir . --runInBand --passWithNoTests",
|
|
20
|
-
"ctix": "ctix build --config ../../.ctirc && ../../resources/prepend-barrel.sh '@expo/entity-database-adapter-knex'"
|
|
12
|
+
"build": "tsc --build",
|
|
13
|
+
"clean": "yarn build --clean",
|
|
14
|
+
"lint": "yarn run --top-level eslint src",
|
|
15
|
+
"lint-fix": "yarn lint --fix",
|
|
16
|
+
"test": "yarn test:all --rootDir $(pwd)",
|
|
17
|
+
"integration": "yarn integration:all --rootDir $(pwd)"
|
|
21
18
|
},
|
|
22
19
|
"engines": {
|
|
23
20
|
"node": ">=16"
|
|
@@ -28,24 +25,14 @@
|
|
|
28
25
|
"author": "Expo",
|
|
29
26
|
"license": "MIT",
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@expo/entity": "^0.
|
|
28
|
+
"@expo/entity": "^0.46.0",
|
|
32
29
|
"knex": "^3.1.0"
|
|
33
30
|
},
|
|
34
31
|
"devDependencies": {
|
|
35
|
-
"@expo/entity-testing-utils": "^0.
|
|
36
|
-
"@
|
|
37
|
-
"@types/node": "^20.14.1",
|
|
38
|
-
"ctix": "^2.7.0",
|
|
39
|
-
"eslint": "^9.26.0",
|
|
40
|
-
"eslint-config-universe": "^15.0.3",
|
|
41
|
-
"eslint-plugin-tsdoc": "^0.4.0",
|
|
42
|
-
"jest": "^29.7.0",
|
|
32
|
+
"@expo/entity-testing-utils": "^0.46.0",
|
|
33
|
+
"@jest/globals": "^30.0.0",
|
|
43
34
|
"pg": "8.14.1",
|
|
44
|
-
"prettier": "^3.5.3",
|
|
45
|
-
"prettier-plugin-organize-imports": "^4.1.0",
|
|
46
|
-
"ts-jest": "^29.3.2",
|
|
47
|
-
"ts-mockito": "^2.6.1",
|
|
48
35
|
"typescript": "^5.8.3"
|
|
49
36
|
},
|
|
50
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "79f61f8d7f7f024e4e9a557473a5737eedb3ffe6"
|
|
51
38
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EntityDatabaseAdapter,
|
|
3
|
-
FieldTransformerMap,
|
|
4
3
|
FieldTransformer,
|
|
5
|
-
|
|
6
|
-
TableFieldSingleValueEqualityCondition,
|
|
4
|
+
FieldTransformerMap,
|
|
7
5
|
TableFieldMultiValueEqualityCondition,
|
|
6
|
+
TableFieldSingleValueEqualityCondition,
|
|
7
|
+
TableQuerySelectionModifiers,
|
|
8
8
|
TableQuerySelectionModifiersWithOrderByRaw,
|
|
9
9
|
} from '@expo/entity';
|
|
10
10
|
import { Knex } from 'knex';
|
|
11
11
|
|
|
12
12
|
import { JSONArrayField, MaybeJSONArrayField } from './EntityFields';
|
|
13
|
-
import wrapNativePostgresCallAsync from './errors/wrapNativePostgresCallAsync';
|
|
13
|
+
import { wrapNativePostgresCallAsync } from './errors/wrapNativePostgresCallAsync';
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export class PostgresEntityDatabaseAdapter<
|
|
16
16
|
TFields extends Record<string, any>,
|
|
17
17
|
TIDField extends keyof TFields,
|
|
18
18
|
> extends EntityDatabaseAdapter<TFields, TIDField> {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
IEntityDatabaseAdapterProvider,
|
|
3
2
|
EntityConfiguration,
|
|
4
3
|
EntityDatabaseAdapter,
|
|
4
|
+
IEntityDatabaseAdapterProvider,
|
|
5
5
|
} from '@expo/entity';
|
|
6
6
|
|
|
7
|
-
import PostgresEntityDatabaseAdapter from './PostgresEntityDatabaseAdapter';
|
|
7
|
+
import { PostgresEntityDatabaseAdapter } from './PostgresEntityDatabaseAdapter';
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
implements IEntityDatabaseAdapterProvider
|
|
11
|
-
{
|
|
9
|
+
export class PostgresEntityDatabaseAdapterProvider implements IEntityDatabaseAdapterProvider {
|
|
12
10
|
getDatabaseAdapter<TFields extends Record<string, any>, TIDField extends keyof TFields>(
|
|
13
11
|
entityConfiguration: EntityConfiguration<TFields, TIDField>,
|
|
14
12
|
): EntityDatabaseAdapter<TFields, TIDField> {
|
|
@@ -8,7 +8,7 @@ import { Knex } from 'knex';
|
|
|
8
8
|
/**
|
|
9
9
|
* Query context provider for knex (postgres).
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export class PostgresEntityQueryContextProvider extends EntityQueryContextProvider {
|
|
12
12
|
constructor(private readonly knexInstance: Knex) {
|
|
13
13
|
super();
|
|
14
14
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { createWithUniqueConstraintRecoveryAsync, ViewerContext } from '@expo/entity';
|
|
2
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
|
3
|
+
import knex, { Knex } from 'knex';
|
|
4
|
+
import nullthrows from 'nullthrows';
|
|
5
|
+
|
|
6
|
+
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity';
|
|
7
|
+
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
|
8
|
+
|
|
9
|
+
describe(createWithUniqueConstraintRecoveryAsync, () => {
|
|
10
|
+
let knexInstance: Knex;
|
|
11
|
+
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
knexInstance = knex({
|
|
14
|
+
client: 'pg',
|
|
15
|
+
connection: {
|
|
16
|
+
user: nullthrows(process.env['PGUSER']),
|
|
17
|
+
password: nullthrows(process.env['PGPASSWORD']),
|
|
18
|
+
host: 'localhost',
|
|
19
|
+
port: parseInt(nullthrows(process.env['PGPORT']), 10),
|
|
20
|
+
database: nullthrows(process.env['PGDATABASE']),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
await PostgresUniqueTestEntity.createOrTruncatePostgresTableAsync(knexInstance);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterAll(async () => {
|
|
30
|
+
await PostgresUniqueTestEntity.dropPostgresTableAsync(knexInstance);
|
|
31
|
+
await knexInstance.destroy();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe.each([true, false])('is parallel creations %p', (parallel) => {
|
|
35
|
+
it('recovers when the same entity is created twice outside of transaction', async () => {
|
|
36
|
+
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
37
|
+
|
|
38
|
+
const args = {
|
|
39
|
+
name: 'unique',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let createdEntities: [PostgresUniqueTestEntity, PostgresUniqueTestEntity];
|
|
43
|
+
if (parallel) {
|
|
44
|
+
createdEntities = await Promise.all([
|
|
45
|
+
createWithUniqueConstraintRecoveryAsync(
|
|
46
|
+
vc1,
|
|
47
|
+
PostgresUniqueTestEntity,
|
|
48
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
49
|
+
args,
|
|
50
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
51
|
+
args,
|
|
52
|
+
),
|
|
53
|
+
createWithUniqueConstraintRecoveryAsync(
|
|
54
|
+
vc1,
|
|
55
|
+
PostgresUniqueTestEntity,
|
|
56
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
57
|
+
args,
|
|
58
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
59
|
+
args,
|
|
60
|
+
),
|
|
61
|
+
]);
|
|
62
|
+
} else {
|
|
63
|
+
createdEntities = [
|
|
64
|
+
await createWithUniqueConstraintRecoveryAsync(
|
|
65
|
+
vc1,
|
|
66
|
+
PostgresUniqueTestEntity,
|
|
67
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
68
|
+
args,
|
|
69
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
70
|
+
args,
|
|
71
|
+
),
|
|
72
|
+
await createWithUniqueConstraintRecoveryAsync(
|
|
73
|
+
vc1,
|
|
74
|
+
PostgresUniqueTestEntity,
|
|
75
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
76
|
+
args,
|
|
77
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
78
|
+
args,
|
|
79
|
+
),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
expect(createdEntities[0].getID()).toEqual(createdEntities[1].getID());
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('recovers when the same entity is created twice within same transaction', async () => {
|
|
87
|
+
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
88
|
+
|
|
89
|
+
const args = {
|
|
90
|
+
name: 'unique',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const createdEntities = await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
94
|
+
'postgres',
|
|
95
|
+
async (queryContext) => {
|
|
96
|
+
if (parallel) {
|
|
97
|
+
return await Promise.all([
|
|
98
|
+
createWithUniqueConstraintRecoveryAsync(
|
|
99
|
+
vc1,
|
|
100
|
+
PostgresUniqueTestEntity,
|
|
101
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
102
|
+
args,
|
|
103
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
104
|
+
args,
|
|
105
|
+
queryContext,
|
|
106
|
+
),
|
|
107
|
+
createWithUniqueConstraintRecoveryAsync(
|
|
108
|
+
vc1,
|
|
109
|
+
PostgresUniqueTestEntity,
|
|
110
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
111
|
+
args,
|
|
112
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
113
|
+
args,
|
|
114
|
+
queryContext,
|
|
115
|
+
),
|
|
116
|
+
]);
|
|
117
|
+
} else {
|
|
118
|
+
return [
|
|
119
|
+
await createWithUniqueConstraintRecoveryAsync(
|
|
120
|
+
vc1,
|
|
121
|
+
PostgresUniqueTestEntity,
|
|
122
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
123
|
+
args,
|
|
124
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
125
|
+
args,
|
|
126
|
+
queryContext,
|
|
127
|
+
),
|
|
128
|
+
await createWithUniqueConstraintRecoveryAsync(
|
|
129
|
+
vc1,
|
|
130
|
+
PostgresUniqueTestEntity,
|
|
131
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
132
|
+
args,
|
|
133
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
134
|
+
args,
|
|
135
|
+
queryContext,
|
|
136
|
+
),
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(nullthrows(createdEntities[0]).getID()).toEqual(
|
|
143
|
+
nullthrows(createdEntities[1]).getID(),
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('recovers when the same entity is created twice within two transactions', async () => {
|
|
148
|
+
const vc1 = new ViewerContext(createKnexIntegrationTestEntityCompanionProvider(knexInstance));
|
|
149
|
+
|
|
150
|
+
const args = {
|
|
151
|
+
name: 'unique',
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
let createdEntities: [PostgresUniqueTestEntity, PostgresUniqueTestEntity];
|
|
155
|
+
if (parallel) {
|
|
156
|
+
createdEntities = await Promise.all([
|
|
157
|
+
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
158
|
+
'postgres',
|
|
159
|
+
async (queryContext) => {
|
|
160
|
+
return await createWithUniqueConstraintRecoveryAsync(
|
|
161
|
+
vc1,
|
|
162
|
+
PostgresUniqueTestEntity,
|
|
163
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
164
|
+
args,
|
|
165
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
166
|
+
args,
|
|
167
|
+
queryContext,
|
|
168
|
+
);
|
|
169
|
+
},
|
|
170
|
+
),
|
|
171
|
+
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
172
|
+
'postgres',
|
|
173
|
+
async (queryContext) => {
|
|
174
|
+
return await createWithUniqueConstraintRecoveryAsync(
|
|
175
|
+
vc1,
|
|
176
|
+
PostgresUniqueTestEntity,
|
|
177
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
178
|
+
args,
|
|
179
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
180
|
+
args,
|
|
181
|
+
queryContext,
|
|
182
|
+
);
|
|
183
|
+
},
|
|
184
|
+
),
|
|
185
|
+
]);
|
|
186
|
+
} else {
|
|
187
|
+
createdEntities = [
|
|
188
|
+
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
189
|
+
'postgres',
|
|
190
|
+
async (queryContext) => {
|
|
191
|
+
return await createWithUniqueConstraintRecoveryAsync(
|
|
192
|
+
vc1,
|
|
193
|
+
PostgresUniqueTestEntity,
|
|
194
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
195
|
+
args,
|
|
196
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
197
|
+
args,
|
|
198
|
+
queryContext,
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
),
|
|
202
|
+
await vc1.runInTransactionForDatabaseAdaptorFlavorAsync(
|
|
203
|
+
'postgres',
|
|
204
|
+
async (queryContext) => {
|
|
205
|
+
return await createWithUniqueConstraintRecoveryAsync(
|
|
206
|
+
vc1,
|
|
207
|
+
PostgresUniqueTestEntity,
|
|
208
|
+
PostgresUniqueTestEntity.getByNameAsync,
|
|
209
|
+
args,
|
|
210
|
+
PostgresUniqueTestEntity.createWithNameAsync,
|
|
211
|
+
args,
|
|
212
|
+
queryContext,
|
|
213
|
+
);
|
|
214
|
+
},
|
|
215
|
+
),
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
expect(nullthrows(createdEntities[0]).getID()).toEqual(
|
|
220
|
+
nullthrows(createdEntities[1]).getID(),
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { OrderByOrdering,
|
|
1
|
+
import { OrderByOrdering, TransactionIsolationLevel, ViewerContext } from '@expo/entity';
|
|
2
2
|
import { createUnitTestEntityCompanionProvider } from '@expo/entity-testing-utils';
|
|
3
3
|
import { enforceAsyncResult } from '@expo/results';
|
|
4
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals';
|
|
4
5
|
import { knex, Knex } from 'knex';
|
|
5
6
|
import nullthrows from 'nullthrows';
|
|
6
7
|
import { setTimeout } from 'timers/promises';
|
|
7
8
|
|
|
8
|
-
import PostgresTestEntity from '../__testfixtures__/PostgresTestEntity';
|
|
9
|
-
import PostgresTriggerTestEntity from '../__testfixtures__/PostgresTriggerTestEntity';
|
|
10
|
-
import PostgresValidatorTestEntity from '../__testfixtures__/PostgresValidatorTestEntity';
|
|
9
|
+
import { PostgresTestEntity } from '../__testfixtures__/PostgresTestEntity';
|
|
10
|
+
import { PostgresTriggerTestEntity } from '../__testfixtures__/PostgresTriggerTestEntity';
|
|
11
|
+
import { PostgresValidatorTestEntity } from '../__testfixtures__/PostgresValidatorTestEntity';
|
|
11
12
|
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
|
12
13
|
|
|
13
14
|
describe('postgres entity integration', () => {
|
|
@@ -561,35 +562,35 @@ describe('postgres entity integration', () => {
|
|
|
561
562
|
|
|
562
563
|
await expect(
|
|
563
564
|
PostgresTriggerTestEntity.creator(vc1).setField('name', 'beforeCreate').createAsync(),
|
|
564
|
-
).rejects.
|
|
565
|
+
).rejects.toThrow('name cannot have value beforeCreate');
|
|
565
566
|
await expect(
|
|
566
567
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'beforeCreate'),
|
|
567
568
|
).resolves.toBeNull();
|
|
568
569
|
|
|
569
570
|
await expect(
|
|
570
571
|
PostgresTriggerTestEntity.creator(vc1).setField('name', 'afterCreate').createAsync(),
|
|
571
|
-
).rejects.
|
|
572
|
+
).rejects.toThrow('name cannot have value afterCreate');
|
|
572
573
|
await expect(
|
|
573
574
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterCreate'),
|
|
574
575
|
).resolves.toBeNull();
|
|
575
576
|
|
|
576
577
|
await expect(
|
|
577
578
|
PostgresTriggerTestEntity.creator(vc1).setField('name', 'beforeAll').createAsync(),
|
|
578
|
-
).rejects.
|
|
579
|
+
).rejects.toThrow('name cannot have value beforeAll');
|
|
579
580
|
await expect(
|
|
580
581
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'beforeAll'),
|
|
581
582
|
).resolves.toBeNull();
|
|
582
583
|
|
|
583
584
|
await expect(
|
|
584
585
|
PostgresTriggerTestEntity.creator(vc1).setField('name', 'afterAll').createAsync(),
|
|
585
|
-
).rejects.
|
|
586
|
+
).rejects.toThrow('name cannot have value afterAll');
|
|
586
587
|
await expect(
|
|
587
588
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterAll'),
|
|
588
589
|
).resolves.toBeNull();
|
|
589
590
|
|
|
590
591
|
await expect(
|
|
591
592
|
PostgresTriggerTestEntity.creator(vc1).setField('name', 'afterCommit').createAsync(),
|
|
592
|
-
).rejects.
|
|
593
|
+
).rejects.toThrow('name cannot have value afterCommit');
|
|
593
594
|
await expect(
|
|
594
595
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterCommit'),
|
|
595
596
|
).resolves.not.toBeNull();
|
|
@@ -608,35 +609,35 @@ describe('postgres entity integration', () => {
|
|
|
608
609
|
|
|
609
610
|
await expect(
|
|
610
611
|
PostgresTriggerTestEntity.updater(entity).setField('name', 'beforeUpdate').updateAsync(),
|
|
611
|
-
).rejects.
|
|
612
|
+
).rejects.toThrow('name cannot have value beforeUpdate');
|
|
612
613
|
await expect(
|
|
613
614
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'beforeUpdate'),
|
|
614
615
|
).resolves.toBeNull();
|
|
615
616
|
|
|
616
617
|
await expect(
|
|
617
618
|
PostgresTriggerTestEntity.updater(entity).setField('name', 'afterUpdate').updateAsync(),
|
|
618
|
-
).rejects.
|
|
619
|
+
).rejects.toThrow('name cannot have value afterUpdate');
|
|
619
620
|
await expect(
|
|
620
621
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterUpdate'),
|
|
621
622
|
).resolves.toBeNull();
|
|
622
623
|
|
|
623
624
|
await expect(
|
|
624
625
|
PostgresTriggerTestEntity.updater(entity).setField('name', 'beforeAll').updateAsync(),
|
|
625
|
-
).rejects.
|
|
626
|
+
).rejects.toThrow('name cannot have value beforeAll');
|
|
626
627
|
await expect(
|
|
627
628
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'beforeAll'),
|
|
628
629
|
).resolves.toBeNull();
|
|
629
630
|
|
|
630
631
|
await expect(
|
|
631
632
|
PostgresTriggerTestEntity.updater(entity).setField('name', 'afterAll').updateAsync(),
|
|
632
|
-
).rejects.
|
|
633
|
+
).rejects.toThrow('name cannot have value afterAll');
|
|
633
634
|
await expect(
|
|
634
635
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterAll'),
|
|
635
636
|
).resolves.toBeNull();
|
|
636
637
|
|
|
637
638
|
await expect(
|
|
638
639
|
PostgresTriggerTestEntity.updater(entity).setField('name', 'afterCommit').updateAsync(),
|
|
639
|
-
).rejects.
|
|
640
|
+
).rejects.toThrow('name cannot have value afterCommit');
|
|
640
641
|
await expect(
|
|
641
642
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterCommit'),
|
|
642
643
|
).resolves.not.toBeNull();
|
|
@@ -654,7 +655,7 @@ describe('postgres entity integration', () => {
|
|
|
654
655
|
.createAsync();
|
|
655
656
|
await expect(
|
|
656
657
|
PostgresTriggerTestEntity.deleter(entityBeforeDelete).deleteAsync(),
|
|
657
|
-
).rejects.
|
|
658
|
+
).rejects.toThrow('name cannot have value beforeDelete');
|
|
658
659
|
await expect(
|
|
659
660
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'beforeDelete'),
|
|
660
661
|
).resolves.not.toBeNull();
|
|
@@ -664,7 +665,7 @@ describe('postgres entity integration', () => {
|
|
|
664
665
|
.createAsync();
|
|
665
666
|
await expect(
|
|
666
667
|
PostgresTriggerTestEntity.deleter(entityAfterDelete).deleteAsync(),
|
|
667
|
-
).rejects.
|
|
668
|
+
).rejects.toThrow('name cannot have value afterDelete');
|
|
668
669
|
await expect(
|
|
669
670
|
PostgresTriggerTestEntity.loader(vc1).loadByFieldEqualingAsync('name', 'afterDelete'),
|
|
670
671
|
).resolves.not.toBeNull();
|
|
@@ -681,7 +682,7 @@ describe('postgres entity integration', () => {
|
|
|
681
682
|
PostgresValidatorTestEntity.creator(vc1)
|
|
682
683
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
683
684
|
.createAsync(),
|
|
684
|
-
).rejects.
|
|
685
|
+
).rejects.toThrow('name cannot have value beforeCreateAndBeforeUpdate');
|
|
685
686
|
await expect(
|
|
686
687
|
PostgresValidatorTestEntity.loader(vc1).loadByFieldEqualingAsync(
|
|
687
688
|
'name',
|
|
@@ -704,7 +705,7 @@ describe('postgres entity integration', () => {
|
|
|
704
705
|
PostgresValidatorTestEntity.updater(entity)
|
|
705
706
|
.setField('name', 'beforeCreateAndBeforeUpdate')
|
|
706
707
|
.updateAsync(),
|
|
707
|
-
).rejects.
|
|
708
|
+
).rejects.toThrow('name cannot have value beforeCreateAndBeforeUpdate');
|
|
708
709
|
await expect(
|
|
709
710
|
PostgresValidatorTestEntity.loader(vc1).loadByFieldEqualingAsync(
|
|
710
711
|
'name',
|
|
@@ -783,7 +784,7 @@ describe('postgres entity integration', () => {
|
|
|
783
784
|
throw Error('wat');
|
|
784
785
|
}, 0);
|
|
785
786
|
}),
|
|
786
|
-
).rejects.
|
|
787
|
+
).rejects.toThrow('wat');
|
|
787
788
|
|
|
788
789
|
expect(preCommitCallCount).toBe(2);
|
|
789
790
|
expect(preCommitInnerCallCount).toBe(2);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { TransactionalDataLoaderMode, ViewerContext } from '@expo/entity';
|
|
2
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it, test } from '@jest/globals';
|
|
2
3
|
import { knex, Knex } from 'knex';
|
|
3
4
|
import nullthrows from 'nullthrows';
|
|
4
5
|
|
|
5
|
-
import PostgresEntityQueryContextProvider from '../PostgresEntityQueryContextProvider';
|
|
6
|
-
import PostgresUniqueTestEntity from '../__testfixtures__/PostgresUniqueTestEntity';
|
|
6
|
+
import { PostgresEntityQueryContextProvider } from '../PostgresEntityQueryContextProvider';
|
|
7
|
+
import { PostgresUniqueTestEntity } from '../__testfixtures__/PostgresUniqueTestEntity';
|
|
7
8
|
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
|
8
9
|
|
|
9
10
|
describe(PostgresEntityQueryContextProvider, () => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ViewerContext } from '@expo/entity';
|
|
2
2
|
import { enforceAsyncResult } from '@expo/results';
|
|
3
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
|
3
4
|
import { knex, Knex } from 'knex';
|
|
4
5
|
import nullthrows from 'nullthrows';
|
|
5
6
|
|
|
6
|
-
import InvalidTestEntity from '../__testfixtures__/InvalidTestEntity';
|
|
7
|
+
import { InvalidTestEntity } from '../__testfixtures__/InvalidTestEntity';
|
|
7
8
|
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
|
8
9
|
|
|
9
10
|
describe('postgres entity integration', () => {
|
|
@@ -47,7 +48,7 @@ describe('postgres entity integration', () => {
|
|
|
47
48
|
.createAsync(),
|
|
48
49
|
);
|
|
49
50
|
|
|
50
|
-
await expect(InvalidTestEntity.deleter(entity1).deleteAsync()).rejects.
|
|
51
|
+
await expect(InvalidTestEntity.deleter(entity1).deleteAsync()).rejects.toThrow(
|
|
51
52
|
'Excessive deletions from database adapter delete',
|
|
52
53
|
);
|
|
53
54
|
});
|
|
@@ -69,7 +70,7 @@ describe('postgres entity integration', () => {
|
|
|
69
70
|
|
|
70
71
|
await expect(
|
|
71
72
|
InvalidTestEntity.updater(entity1).setField('name', 'blah').updateAsync(),
|
|
72
|
-
).rejects.
|
|
73
|
+
).rejects.toThrow('Excessive results from database adapter update');
|
|
73
74
|
});
|
|
74
75
|
|
|
75
76
|
it('throws after update of no rows', async () => {
|
|
@@ -84,7 +85,7 @@ describe('postgres entity integration', () => {
|
|
|
84
85
|
|
|
85
86
|
await expect(
|
|
86
87
|
InvalidTestEntity.updater(entity1).setField('name', 'blah').updateAsync(),
|
|
87
|
-
).rejects.
|
|
88
|
+
).rejects.toThrow('Empty results from database adapter update');
|
|
88
89
|
});
|
|
89
90
|
});
|
|
90
91
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ViewerContext,
|
|
3
2
|
EntityDatabaseAdapterCheckConstraintError,
|
|
4
3
|
EntityDatabaseAdapterExclusionConstraintError,
|
|
5
4
|
EntityDatabaseAdapterForeignKeyConstraintError,
|
|
@@ -7,11 +6,13 @@ import {
|
|
|
7
6
|
EntityDatabaseAdapterTransientError,
|
|
8
7
|
EntityDatabaseAdapterUniqueConstraintError,
|
|
9
8
|
EntityDatabaseAdapterUnknownError,
|
|
9
|
+
ViewerContext,
|
|
10
10
|
} from '@expo/entity';
|
|
11
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
|
|
11
12
|
import { knex, Knex } from 'knex';
|
|
12
13
|
import nullthrows from 'nullthrows';
|
|
13
14
|
|
|
14
|
-
import ErrorsTestEntity from '../__testfixtures__/ErrorsTestEntity';
|
|
15
|
+
import { ErrorsTestEntity } from '../__testfixtures__/ErrorsTestEntity';
|
|
15
16
|
import { createKnexIntegrationTestEntityCompanionProvider } from '../__testfixtures__/createKnexIntegrationTestEntityCompanionProvider';
|
|
16
17
|
|
|
17
18
|
describe('postgres errors', () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
-
EntityPrivacyPolicy,
|
|
4
|
-
ViewerContext,
|
|
5
|
-
StringField,
|
|
6
|
-
EntityConfiguration,
|
|
7
|
-
EntityCompanionDefinition,
|
|
8
3
|
Entity,
|
|
4
|
+
EntityCompanionDefinition,
|
|
5
|
+
EntityConfiguration,
|
|
6
|
+
EntityPrivacyPolicy,
|
|
9
7
|
IntField,
|
|
8
|
+
StringField,
|
|
9
|
+
ViewerContext,
|
|
10
10
|
} from '@expo/entity';
|
|
11
11
|
import { Knex } from 'knex';
|
|
12
12
|
|
|
@@ -22,7 +22,7 @@ type ErrorsTestEntityFields = {
|
|
|
22
22
|
|
|
23
23
|
const foreignTableName = 'foreign_table';
|
|
24
24
|
|
|
25
|
-
export
|
|
25
|
+
export class ErrorsTestEntity extends Entity<ErrorsTestEntityFields, 'id', ViewerContext> {
|
|
26
26
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
27
27
|
ErrorsTestEntityFields,
|
|
28
28
|
'id',
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
-
EntityPrivacyPolicy,
|
|
4
|
-
ViewerContext,
|
|
5
|
-
StringField,
|
|
6
|
-
EntityConfiguration,
|
|
7
|
-
EntityCompanionDefinition,
|
|
8
3
|
Entity,
|
|
4
|
+
EntityCompanionDefinition,
|
|
5
|
+
EntityConfiguration,
|
|
6
|
+
EntityPrivacyPolicy,
|
|
9
7
|
IntField,
|
|
8
|
+
StringField,
|
|
9
|
+
ViewerContext,
|
|
10
10
|
} from '@expo/entity';
|
|
11
11
|
import { Knex } from 'knex';
|
|
12
12
|
|
|
@@ -15,11 +15,7 @@ type InvalidTestEntityFields = {
|
|
|
15
15
|
name: string | null;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export
|
|
19
|
-
InvalidTestEntityFields,
|
|
20
|
-
'id',
|
|
21
|
-
ViewerContext
|
|
22
|
-
> {
|
|
18
|
+
export class InvalidTestEntity extends Entity<InvalidTestEntityFields, 'id', ViewerContext> {
|
|
23
19
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
24
20
|
InvalidTestEntityFields,
|
|
25
21
|
'id',
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
-
EntityPrivacyPolicy,
|
|
4
|
-
ViewerContext,
|
|
5
|
-
StringField,
|
|
6
3
|
BooleanField,
|
|
7
|
-
StringArrayField,
|
|
8
|
-
JSONObjectField,
|
|
9
4
|
DateField,
|
|
10
|
-
EntityConfiguration,
|
|
11
|
-
EntityCompanionDefinition,
|
|
12
5
|
Entity,
|
|
6
|
+
EntityCompanionDefinition,
|
|
7
|
+
EntityConfiguration,
|
|
8
|
+
EntityPrivacyPolicy,
|
|
9
|
+
JSONObjectField,
|
|
10
|
+
StringArrayField,
|
|
11
|
+
StringField,
|
|
13
12
|
UUIDField,
|
|
13
|
+
ViewerContext,
|
|
14
14
|
} from '@expo/entity';
|
|
15
15
|
import { Knex } from 'knex';
|
|
16
16
|
|
|
@@ -31,11 +31,7 @@ type PostgresTestEntityFields = {
|
|
|
31
31
|
bigintField: string | null;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
export
|
|
35
|
-
PostgresTestEntityFields,
|
|
36
|
-
'id',
|
|
37
|
-
ViewerContext
|
|
38
|
-
> {
|
|
34
|
+
export class PostgresTestEntity extends Entity<PostgresTestEntityFields, 'id', ViewerContext> {
|
|
39
35
|
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
40
36
|
PostgresTestEntityFields,
|
|
41
37
|
'id',
|