@expo/entity-database-adapter-knex 0.54.0 → 0.57.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/AuthorizationResultBasedKnexEntityLoader.d.ts +279 -0
- package/build/src/AuthorizationResultBasedKnexEntityLoader.js +127 -0
- package/build/src/AuthorizationResultBasedKnexEntityLoader.js.map +1 -0
- package/build/src/BasePostgresEntityDatabaseAdapter.d.ts +150 -0
- package/build/src/BasePostgresEntityDatabaseAdapter.js +119 -0
- package/build/src/BasePostgresEntityDatabaseAdapter.js.map +1 -0
- package/build/src/BaseSQLQueryBuilder.d.ts +61 -0
- package/build/src/BaseSQLQueryBuilder.js +87 -0
- package/build/src/BaseSQLQueryBuilder.js.map +1 -0
- package/build/src/EnforcingKnexEntityLoader.d.ts +124 -0
- package/build/src/EnforcingKnexEntityLoader.js +166 -0
- package/build/src/EnforcingKnexEntityLoader.js.map +1 -0
- package/build/src/KnexEntityLoaderFactory.d.ts +25 -0
- package/build/src/KnexEntityLoaderFactory.js +39 -0
- package/build/src/KnexEntityLoaderFactory.js.map +1 -0
- package/build/src/PaginationStrategy.d.ts +30 -0
- package/build/src/PaginationStrategy.js +35 -0
- package/build/src/PaginationStrategy.js.map +1 -0
- package/build/src/PostgresEntity.d.ts +25 -0
- package/build/src/PostgresEntity.js +39 -0
- package/build/src/PostgresEntity.js.map +1 -0
- package/build/src/PostgresEntityDatabaseAdapter.d.ts +12 -5
- package/build/src/PostgresEntityDatabaseAdapter.js +32 -11
- package/build/src/PostgresEntityDatabaseAdapter.js.map +1 -1
- package/build/src/PostgresEntityDatabaseAdapterProvider.d.ts +9 -0
- package/build/src/PostgresEntityDatabaseAdapterProvider.js +5 -1
- package/build/src/PostgresEntityDatabaseAdapterProvider.js.map +1 -1
- package/build/src/ReadonlyPostgresEntity.d.ts +25 -0
- package/build/src/ReadonlyPostgresEntity.js +39 -0
- package/build/src/ReadonlyPostgresEntity.js.map +1 -0
- package/build/src/SQLOperator.d.ts +261 -0
- package/build/src/SQLOperator.js +464 -0
- package/build/src/SQLOperator.js.map +1 -0
- package/build/src/index.d.ts +15 -0
- package/build/src/index.js +15 -0
- package/build/src/index.js.map +1 -1
- package/build/src/internal/EntityKnexDataManager.d.ts +147 -0
- package/build/src/internal/EntityKnexDataManager.js +453 -0
- package/build/src/internal/EntityKnexDataManager.js.map +1 -0
- package/build/src/internal/getKnexDataManager.d.ts +3 -0
- package/build/src/internal/getKnexDataManager.js +19 -0
- package/build/src/internal/getKnexDataManager.js.map +1 -0
- package/build/src/internal/getKnexEntityLoaderFactory.d.ts +3 -0
- package/build/src/internal/getKnexEntityLoaderFactory.js +11 -0
- package/build/src/internal/getKnexEntityLoaderFactory.js.map +1 -0
- package/build/src/internal/utilityTypes.d.ts +5 -0
- package/build/src/internal/utilityTypes.js +5 -0
- package/build/src/internal/utilityTypes.js.map +1 -0
- package/build/src/internal/weakMaps.d.ts +9 -0
- package/build/src/internal/weakMaps.js +20 -0
- package/build/src/internal/weakMaps.js.map +1 -0
- package/build/src/knexLoader.d.ts +18 -0
- package/build/src/knexLoader.js +31 -0
- package/build/src/knexLoader.js.map +1 -0
- package/package.json +6 -5
- package/src/AuthorizationResultBasedKnexEntityLoader.ts +538 -0
- package/src/BasePostgresEntityDatabaseAdapter.ts +317 -0
- package/src/BaseSQLQueryBuilder.ts +114 -0
- package/src/EnforcingKnexEntityLoader.ts +271 -0
- package/src/KnexEntityLoaderFactory.ts +130 -0
- package/src/PaginationStrategy.ts +32 -0
- package/src/PostgresEntity.ts +118 -0
- package/src/PostgresEntityDatabaseAdapter.ts +78 -24
- package/src/PostgresEntityDatabaseAdapterProvider.ts +11 -1
- package/src/ReadonlyPostgresEntity.ts +115 -0
- package/src/SQLOperator.ts +603 -0
- package/src/__integration-tests__/EntityCreationUtils-test.ts +25 -31
- package/src/__integration-tests__/PostgresEntityIntegration-test.ts +3192 -330
- package/src/__integration-tests__/PostgresEntityQueryContextProvider-test.ts +7 -7
- package/src/__testfixtures__/PostgresTestEntity.ts +17 -3
- package/src/__tests__/AuthorizationResultBasedKnexEntityLoader-test.ts +1167 -0
- package/src/__tests__/BasePostgresEntityDatabaseAdapter-test.ts +160 -0
- package/src/__tests__/EnforcingKnexEntityLoader-test.ts +384 -0
- package/src/__tests__/EntityFields-test.ts +1 -1
- package/src/__tests__/PostgresEntity-test.ts +172 -0
- package/src/__tests__/ReadonlyEntity-test.ts +32 -0
- package/src/__tests__/SQLOperator-test.ts +831 -0
- package/src/__tests__/fixtures/StubPostgresDatabaseAdapter.ts +302 -0
- package/src/__tests__/fixtures/StubPostgresDatabaseAdapterProvider.ts +17 -0
- package/src/__tests__/fixtures/TestEntity.ts +131 -0
- package/src/__tests__/fixtures/TestPaginationEntity.ts +107 -0
- package/src/__tests__/fixtures/createUnitTestPostgresEntityCompanionProvider.ts +42 -0
- package/src/index.ts +15 -0
- package/src/internal/EntityKnexDataManager.ts +832 -0
- package/src/internal/__tests__/EntityKnexDataManager-test.ts +378 -0
- package/src/internal/__tests__/weakMaps-test.ts +25 -0
- package/src/internal/getKnexDataManager.ts +43 -0
- package/src/internal/getKnexEntityLoaderFactory.ts +60 -0
- package/src/internal/utilityTypes.ts +11 -0
- package/src/internal/weakMaps.ts +19 -0
- package/src/knexLoader.ts +110 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
+
EntityCompanionDefinition,
|
|
4
|
+
EntityConfiguration,
|
|
5
|
+
EntityPrivacyPolicy,
|
|
6
|
+
StringField,
|
|
7
|
+
UUIDField,
|
|
8
|
+
ViewerContext,
|
|
9
|
+
} from '@expo/entity';
|
|
10
|
+
import { describe, expect, it } from '@jest/globals';
|
|
11
|
+
|
|
12
|
+
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader';
|
|
13
|
+
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader';
|
|
14
|
+
import { PostgresEntity } from '../PostgresEntity';
|
|
15
|
+
import { ReadonlyPostgresEntity } from '../ReadonlyPostgresEntity';
|
|
16
|
+
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider';
|
|
17
|
+
|
|
18
|
+
type TestPostgresFields = {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const testPostgresEntityConfiguration = new EntityConfiguration<TestPostgresFields, 'id'>({
|
|
24
|
+
idField: 'id',
|
|
25
|
+
tableName: 'postgres_entity_test',
|
|
26
|
+
schema: {
|
|
27
|
+
id: new UUIDField({ columnName: 'id', cache: true }),
|
|
28
|
+
name: new StringField({ columnName: 'name' }),
|
|
29
|
+
},
|
|
30
|
+
databaseAdapterFlavor: 'postgres',
|
|
31
|
+
cacheAdapterFlavor: 'redis',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
class TestPostgresEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
35
|
+
TestPostgresFields,
|
|
36
|
+
'id',
|
|
37
|
+
ViewerContext,
|
|
38
|
+
TestPostgresEntity
|
|
39
|
+
> {
|
|
40
|
+
protected override readonly readRules = [
|
|
41
|
+
new AlwaysAllowPrivacyPolicyRule<TestPostgresFields, 'id', ViewerContext, TestPostgresEntity>(),
|
|
42
|
+
];
|
|
43
|
+
protected override readonly createRules = [
|
|
44
|
+
new AlwaysAllowPrivacyPolicyRule<TestPostgresFields, 'id', ViewerContext, TestPostgresEntity>(),
|
|
45
|
+
];
|
|
46
|
+
protected override readonly updateRules = [
|
|
47
|
+
new AlwaysAllowPrivacyPolicyRule<TestPostgresFields, 'id', ViewerContext, TestPostgresEntity>(),
|
|
48
|
+
];
|
|
49
|
+
protected override readonly deleteRules = [
|
|
50
|
+
new AlwaysAllowPrivacyPolicyRule<TestPostgresFields, 'id', ViewerContext, TestPostgresEntity>(),
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class TestPostgresEntity extends PostgresEntity<TestPostgresFields, 'id', ViewerContext> {
|
|
55
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
56
|
+
TestPostgresFields,
|
|
57
|
+
'id',
|
|
58
|
+
ViewerContext,
|
|
59
|
+
TestPostgresEntity,
|
|
60
|
+
TestPostgresEntityPrivacyPolicy
|
|
61
|
+
> {
|
|
62
|
+
return {
|
|
63
|
+
entityClass: TestPostgresEntity,
|
|
64
|
+
entityConfiguration: testPostgresEntityConfiguration,
|
|
65
|
+
privacyPolicyClass: TestPostgresEntityPrivacyPolicy,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class TestReadonlyPostgresEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
71
|
+
TestPostgresFields,
|
|
72
|
+
'id',
|
|
73
|
+
ViewerContext,
|
|
74
|
+
TestReadonlyPostgresEntity
|
|
75
|
+
> {
|
|
76
|
+
protected override readonly readRules = [
|
|
77
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
78
|
+
TestPostgresFields,
|
|
79
|
+
'id',
|
|
80
|
+
ViewerContext,
|
|
81
|
+
TestReadonlyPostgresEntity
|
|
82
|
+
>(),
|
|
83
|
+
];
|
|
84
|
+
protected override readonly createRules = [
|
|
85
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
86
|
+
TestPostgresFields,
|
|
87
|
+
'id',
|
|
88
|
+
ViewerContext,
|
|
89
|
+
TestReadonlyPostgresEntity
|
|
90
|
+
>(),
|
|
91
|
+
];
|
|
92
|
+
protected override readonly updateRules = [
|
|
93
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
94
|
+
TestPostgresFields,
|
|
95
|
+
'id',
|
|
96
|
+
ViewerContext,
|
|
97
|
+
TestReadonlyPostgresEntity
|
|
98
|
+
>(),
|
|
99
|
+
];
|
|
100
|
+
protected override readonly deleteRules = [
|
|
101
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
102
|
+
TestPostgresFields,
|
|
103
|
+
'id',
|
|
104
|
+
ViewerContext,
|
|
105
|
+
TestReadonlyPostgresEntity
|
|
106
|
+
>(),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class TestReadonlyPostgresEntity extends ReadonlyPostgresEntity<
|
|
111
|
+
TestPostgresFields,
|
|
112
|
+
'id',
|
|
113
|
+
ViewerContext
|
|
114
|
+
> {
|
|
115
|
+
static defineCompanionDefinition(): EntityCompanionDefinition<
|
|
116
|
+
TestPostgresFields,
|
|
117
|
+
'id',
|
|
118
|
+
ViewerContext,
|
|
119
|
+
TestReadonlyPostgresEntity,
|
|
120
|
+
TestReadonlyPostgresEntityPrivacyPolicy
|
|
121
|
+
> {
|
|
122
|
+
return {
|
|
123
|
+
entityClass: TestReadonlyPostgresEntity,
|
|
124
|
+
entityConfiguration: testPostgresEntityConfiguration,
|
|
125
|
+
privacyPolicyClass: TestReadonlyPostgresEntityPrivacyPolicy,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
describe(PostgresEntity, () => {
|
|
131
|
+
describe('knexLoader', () => {
|
|
132
|
+
it('creates a new EnforcingKnexEntityLoader', () => {
|
|
133
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
134
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
135
|
+
expect(TestPostgresEntity.knexLoader(viewerContext)).toBeInstanceOf(
|
|
136
|
+
EnforcingKnexEntityLoader,
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('knexLoaderWithAuthorizationResults', () => {
|
|
142
|
+
it('creates a new AuthorizationResultBasedKnexEntityLoader', () => {
|
|
143
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
144
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
145
|
+
expect(TestPostgresEntity.knexLoaderWithAuthorizationResults(viewerContext)).toBeInstanceOf(
|
|
146
|
+
AuthorizationResultBasedKnexEntityLoader,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe(ReadonlyPostgresEntity, () => {
|
|
153
|
+
describe('knexLoader', () => {
|
|
154
|
+
it('creates a new EnforcingKnexEntityLoader', () => {
|
|
155
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
156
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
157
|
+
expect(TestReadonlyPostgresEntity.knexLoader(viewerContext)).toBeInstanceOf(
|
|
158
|
+
EnforcingKnexEntityLoader,
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('knexLoaderWithAuthorizationResults', () => {
|
|
164
|
+
it('creates a new AuthorizationResultBasedKnexEntityLoader', () => {
|
|
165
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
166
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
167
|
+
expect(
|
|
168
|
+
TestReadonlyPostgresEntity.knexLoaderWithAuthorizationResults(viewerContext),
|
|
169
|
+
).toBeInstanceOf(AuthorizationResultBasedKnexEntityLoader);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ViewerContext } from '@expo/entity';
|
|
2
|
+
import { describe, expect, it } from '@jest/globals';
|
|
3
|
+
|
|
4
|
+
import { AuthorizationResultBasedKnexEntityLoader } from '../AuthorizationResultBasedKnexEntityLoader';
|
|
5
|
+
import { EnforcingKnexEntityLoader } from '../EnforcingKnexEntityLoader';
|
|
6
|
+
import { knexLoader, knexLoaderWithAuthorizationResults } from '../knexLoader';
|
|
7
|
+
import { TestEntity } from './fixtures/TestEntity';
|
|
8
|
+
import { createUnitTestPostgresEntityCompanionProvider } from './fixtures/createUnitTestPostgresEntityCompanionProvider';
|
|
9
|
+
|
|
10
|
+
describe('knexLoader', () => {
|
|
11
|
+
describe('knexLoader', () => {
|
|
12
|
+
it('creates a new EnforcingKnexEntityLoader', async () => {
|
|
13
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
14
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
15
|
+
expect(knexLoader(TestEntity, viewerContext)).toBeInstanceOf(EnforcingKnexEntityLoader);
|
|
16
|
+
expect(TestEntity.knexLoader(viewerContext)).toBeInstanceOf(EnforcingKnexEntityLoader);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('knexLoaderWithAuthorizationResults', () => {
|
|
21
|
+
it('creates a new AuthorizationResultBasedKnexEntityLoader', async () => {
|
|
22
|
+
const companionProvider = createUnitTestPostgresEntityCompanionProvider();
|
|
23
|
+
const viewerContext = new ViewerContext(companionProvider);
|
|
24
|
+
expect(knexLoaderWithAuthorizationResults(TestEntity, viewerContext)).toBeInstanceOf(
|
|
25
|
+
AuthorizationResultBasedKnexEntityLoader,
|
|
26
|
+
);
|
|
27
|
+
expect(TestEntity.knexLoaderWithAuthorizationResults(viewerContext)).toBeInstanceOf(
|
|
28
|
+
AuthorizationResultBasedKnexEntityLoader,
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|