@expo/entity-cache-adapter-local-memory 0.24.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/README.md +44 -0
- package/build/GenericLocalMemoryCacher.d.ts +20 -0
- package/build/GenericLocalMemoryCacher.js +79 -0
- package/build/GenericLocalMemoryCacher.js.map +1 -0
- package/build/LocalMemoryCacheAdapter.d.ts +11 -0
- package/build/LocalMemoryCacheAdapter.js +45 -0
- package/build/LocalMemoryCacheAdapter.js.map +1 -0
- package/build/LocalMemoryCacheAdapterProvider.d.ts +13 -0
- package/build/LocalMemoryCacheAdapterProvider.js +30 -0
- package/build/LocalMemoryCacheAdapterProvider.js.map +1 -0
- package/build/__integration-tests__/LocalMemoryCacheAdapter-integration-test.d.ts +1 -0
- package/build/__integration-tests__/LocalMemoryCacheAdapter-integration-test.js +128 -0
- package/build/__integration-tests__/LocalMemoryCacheAdapter-integration-test.js.map +1 -0
- package/build/__tests__/LocalMemoryCacheAdapter-test.d.ts +1 -0
- package/build/__tests__/LocalMemoryCacheAdapter-test.js +118 -0
- package/build/__tests__/LocalMemoryCacheAdapter-test.js.map +1 -0
- package/build/testfixtures/LocalMemoryTestEntity.d.ts +16 -0
- package/build/testfixtures/LocalMemoryTestEntity.js +53 -0
- package/build/testfixtures/LocalMemoryTestEntity.js.map +1 -0
- package/build/testfixtures/createLocalMemoryIntegrationTestEntityCompanionProvider.d.ts +6 -0
- package/build/testfixtures/createLocalMemoryIntegrationTestEntityCompanionProvider.js +32 -0
- package/build/testfixtures/createLocalMemoryIntegrationTestEntityCompanionProvider.js.map +1 -0
- package/package.json +38 -0
- package/src/GenericLocalMemoryCacher.ts +154 -0
- package/src/LocalMemoryCacheAdapter.ts +80 -0
- package/src/LocalMemoryCacheAdapterProvider.ts +43 -0
- package/src/__integration-tests__/LocalMemoryCacheAdapter-integration-test.ts +180 -0
- package/src/__tests__/LocalMemoryCacheAdapter-test.ts +125 -0
- package/src/testfixtures/LocalMemoryTestEntity.ts +100 -0
- package/src/testfixtures/createLocalMemoryIntegrationTestEntityCompanionProvider.ts +48 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlwaysAllowPrivacyPolicyRule,
|
|
3
|
+
EntityPrivacyPolicy,
|
|
4
|
+
ViewerContext,
|
|
5
|
+
UUIDField,
|
|
6
|
+
DateField,
|
|
7
|
+
StringField,
|
|
8
|
+
EntityConfiguration,
|
|
9
|
+
EntityCompanionDefinition,
|
|
10
|
+
Entity,
|
|
11
|
+
} from '@expo/entity';
|
|
12
|
+
|
|
13
|
+
export type LocalMemoryTestEntityFields = {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
dateField: Date | null;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default class LocalMemoryTestEntity extends Entity<
|
|
20
|
+
LocalMemoryTestEntityFields,
|
|
21
|
+
string,
|
|
22
|
+
ViewerContext
|
|
23
|
+
> {
|
|
24
|
+
static getCompanionDefinition(): EntityCompanionDefinition<
|
|
25
|
+
LocalMemoryTestEntityFields,
|
|
26
|
+
string,
|
|
27
|
+
ViewerContext,
|
|
28
|
+
LocalMemoryTestEntity,
|
|
29
|
+
LocalMemoryTestEntityPrivacyPolicy
|
|
30
|
+
> {
|
|
31
|
+
return localMemoryTestEntityCompanionDefinition;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class LocalMemoryTestEntityPrivacyPolicy extends EntityPrivacyPolicy<
|
|
36
|
+
LocalMemoryTestEntityFields,
|
|
37
|
+
string,
|
|
38
|
+
ViewerContext,
|
|
39
|
+
LocalMemoryTestEntity
|
|
40
|
+
> {
|
|
41
|
+
protected override readonly createRules = [
|
|
42
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
43
|
+
LocalMemoryTestEntityFields,
|
|
44
|
+
string,
|
|
45
|
+
ViewerContext,
|
|
46
|
+
LocalMemoryTestEntity
|
|
47
|
+
>(),
|
|
48
|
+
];
|
|
49
|
+
protected override readonly readRules = [
|
|
50
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
51
|
+
LocalMemoryTestEntityFields,
|
|
52
|
+
string,
|
|
53
|
+
ViewerContext,
|
|
54
|
+
LocalMemoryTestEntity
|
|
55
|
+
>(),
|
|
56
|
+
];
|
|
57
|
+
protected override readonly updateRules = [
|
|
58
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
59
|
+
LocalMemoryTestEntityFields,
|
|
60
|
+
string,
|
|
61
|
+
ViewerContext,
|
|
62
|
+
LocalMemoryTestEntity
|
|
63
|
+
>(),
|
|
64
|
+
];
|
|
65
|
+
protected override readonly deleteRules = [
|
|
66
|
+
new AlwaysAllowPrivacyPolicyRule<
|
|
67
|
+
LocalMemoryTestEntityFields,
|
|
68
|
+
string,
|
|
69
|
+
ViewerContext,
|
|
70
|
+
LocalMemoryTestEntity
|
|
71
|
+
>(),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const localMemoryTestEntityConfiguration =
|
|
76
|
+
new EntityConfiguration<LocalMemoryTestEntityFields>({
|
|
77
|
+
idField: 'id',
|
|
78
|
+
tableName: 'local_memory_test_entities',
|
|
79
|
+
schema: {
|
|
80
|
+
id: new UUIDField({
|
|
81
|
+
columnName: 'id',
|
|
82
|
+
cache: true,
|
|
83
|
+
}),
|
|
84
|
+
name: new StringField({
|
|
85
|
+
columnName: 'name',
|
|
86
|
+
cache: true,
|
|
87
|
+
}),
|
|
88
|
+
dateField: new DateField({
|
|
89
|
+
columnName: 'date_field',
|
|
90
|
+
}),
|
|
91
|
+
},
|
|
92
|
+
databaseAdapterFlavor: 'postgres',
|
|
93
|
+
cacheAdapterFlavor: 'local-memory',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const localMemoryTestEntityCompanionDefinition = new EntityCompanionDefinition({
|
|
97
|
+
entityClass: LocalMemoryTestEntity,
|
|
98
|
+
entityConfiguration: localMemoryTestEntityConfiguration,
|
|
99
|
+
privacyPolicyClass: LocalMemoryTestEntityPrivacyPolicy,
|
|
100
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoOpEntityMetricsAdapter,
|
|
3
|
+
IEntityMetricsAdapter,
|
|
4
|
+
EntityCompanionProvider,
|
|
5
|
+
StubQueryContextProvider,
|
|
6
|
+
StubDatabaseAdapterProvider,
|
|
7
|
+
} from '@expo/entity';
|
|
8
|
+
|
|
9
|
+
import { LocalMemoryCacheAdapterProvider } from '../LocalMemoryCacheAdapterProvider';
|
|
10
|
+
|
|
11
|
+
export const createLocalMemoryIntegrationTestEntityCompanionProvider = (
|
|
12
|
+
localMemoryOptions: { maxSize?: number; ttlSeconds?: number } = {},
|
|
13
|
+
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
|
|
14
|
+
): EntityCompanionProvider => {
|
|
15
|
+
const localMemoryCacheAdapterProvider =
|
|
16
|
+
localMemoryOptions.maxSize === 0 && localMemoryOptions.ttlSeconds === 0
|
|
17
|
+
? LocalMemoryCacheAdapterProvider.getNoOpProvider()
|
|
18
|
+
: LocalMemoryCacheAdapterProvider.getProvider(localMemoryOptions);
|
|
19
|
+
return new EntityCompanionProvider(
|
|
20
|
+
metricsAdapter,
|
|
21
|
+
new Map([
|
|
22
|
+
[
|
|
23
|
+
'postgres',
|
|
24
|
+
{
|
|
25
|
+
adapterProvider: new StubDatabaseAdapterProvider(),
|
|
26
|
+
queryContextProvider: StubQueryContextProvider,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
]),
|
|
30
|
+
new Map([
|
|
31
|
+
[
|
|
32
|
+
'local-memory',
|
|
33
|
+
{
|
|
34
|
+
cacheAdapterProvider: localMemoryCacheAdapterProvider,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
])
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createNoopLocalMemoryIntegrationTestEntityCompanionProvider = (
|
|
42
|
+
metricsAdapter: IEntityMetricsAdapter = new NoOpEntityMetricsAdapter()
|
|
43
|
+
): EntityCompanionProvider => {
|
|
44
|
+
return createLocalMemoryIntegrationTestEntityCompanionProvider(
|
|
45
|
+
{ maxSize: 0, ttlSeconds: 0 },
|
|
46
|
+
metricsAdapter
|
|
47
|
+
);
|
|
48
|
+
};
|