@algolia/client-common 5.8.1 → 5.9.1
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/dist/common.d.cts +562 -426
- package/dist/common.d.ts +562 -426
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +5 -5
- package/index.ts +0 -9
- package/src/__tests__/cache/browser-local-storage-cache.test.ts +0 -171
- package/src/__tests__/cache/fallbackable-cache.test.ts +0 -126
- package/src/__tests__/cache/memory-cache.test.ts +0 -82
- package/src/__tests__/cache/null-cache.test.ts +0 -47
- package/src/__tests__/create-iterable-promise.test.ts +0 -236
- package/src/__tests__/logger/null-logger.test.ts +0 -22
- package/src/cache/createBrowserLocalStorageCache.ts +0 -106
- package/src/cache/createFallbackableCache.ts +0 -43
- package/src/cache/createMemoryCache.ts +0 -43
- package/src/cache/createNullCache.ts +0 -29
- package/src/cache/index.ts +0 -4
- package/src/constants.ts +0 -7
- package/src/createAlgoliaAgent.ts +0 -18
- package/src/createAuth.ts +0 -25
- package/src/createIterablePromise.ts +0 -47
- package/src/getAlgoliaAgent.ts +0 -19
- package/src/logger/createNullLogger.ts +0 -15
- package/src/logger/index.ts +0 -1
- package/src/transporter/createStatefulHost.ts +0 -19
- package/src/transporter/createTransporter.ts +0 -315
- package/src/transporter/errors.ts +0 -77
- package/src/transporter/helpers.ts +0 -96
- package/src/transporter/index.ts +0 -6
- package/src/transporter/responses.ts +0 -13
- package/src/transporter/stackTrace.ts +0 -22
- package/src/types/cache.ts +0 -75
- package/src/types/createClient.ts +0 -15
- package/src/types/createIterablePromise.ts +0 -40
- package/src/types/host.ts +0 -43
- package/src/types/index.ts +0 -7
- package/src/types/logger.ts +0 -24
- package/src/types/requester.ts +0 -67
- package/src/types/transporter.ts +0 -153
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/common';
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/common.cjs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algolia/client-common",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.1",
|
|
4
4
|
"description": "Common package for the Algolia JavaScript API client.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"files": [
|
|
13
13
|
"dist",
|
|
14
|
-
"
|
|
15
|
-
"index.ts"
|
|
14
|
+
"index.js",
|
|
15
|
+
"index.d.ts"
|
|
16
16
|
],
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@arethetypeswrong/cli": "0.16.4",
|
|
38
|
-
"@types/node": "22.7.
|
|
38
|
+
"@types/node": "22.7.5",
|
|
39
39
|
"jsdom": "25.0.1",
|
|
40
40
|
"publint": "0.2.11",
|
|
41
41
|
"ts-node": "10.9.2",
|
|
42
42
|
"tsup": "8.3.0",
|
|
43
|
-
"typescript": "5.6.
|
|
43
|
+
"typescript": "5.6.3",
|
|
44
44
|
"vitest": "2.1.2"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
package/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './src/cache';
|
|
2
|
-
export * from './src/constants';
|
|
3
|
-
export * from './src/createAlgoliaAgent';
|
|
4
|
-
export * from './src/createAuth';
|
|
5
|
-
export * from './src/createIterablePromise';
|
|
6
|
-
export * from './src/getAlgoliaAgent';
|
|
7
|
-
export * from './src/logger';
|
|
8
|
-
export * from './src/transporter';
|
|
9
|
-
export * from './src/types';
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createBrowserLocalStorageCache } from '../../cache';
|
|
4
|
-
|
|
5
|
-
const version = 'foobar';
|
|
6
|
-
const notAvailableStorage = new Proxy(window.localStorage, {
|
|
7
|
-
get() {
|
|
8
|
-
return (): void => {
|
|
9
|
-
throw new Error('Component is not available');
|
|
10
|
-
};
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
type DefaultValue = Promise<{ bar: number }>;
|
|
15
|
-
|
|
16
|
-
describe('browser local storage cache', () => {
|
|
17
|
-
const missMock = vi.fn();
|
|
18
|
-
const events = {
|
|
19
|
-
miss: (): Promise<any> => Promise.resolve(missMock()),
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
window.localStorage.clear();
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('sets/gets values', async () => {
|
|
28
|
-
const cache = createBrowserLocalStorageCache({ key: version });
|
|
29
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 1 });
|
|
30
|
-
|
|
31
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 1 });
|
|
32
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
33
|
-
|
|
34
|
-
await cache.set({ key: 'foo' }, { foo: 2 });
|
|
35
|
-
|
|
36
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
|
|
37
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('reads unexpired timeToLive keys', async () => {
|
|
41
|
-
const cache = createBrowserLocalStorageCache({
|
|
42
|
-
key: version,
|
|
43
|
-
timeToLive: 5,
|
|
44
|
-
});
|
|
45
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
46
|
-
|
|
47
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
await cache.get({ key: 'foo' }, defaultValue, {
|
|
51
|
-
miss: () => Promise.resolve(missMock()),
|
|
52
|
-
}),
|
|
53
|
-
).toMatchObject({ bar: 1 });
|
|
54
|
-
|
|
55
|
-
expect(missMock.mock.calls.length).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('deletes keys', async () => {
|
|
59
|
-
const cache = createBrowserLocalStorageCache({ key: version });
|
|
60
|
-
|
|
61
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
62
|
-
await cache.delete({ key: 'foo' });
|
|
63
|
-
|
|
64
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
65
|
-
|
|
66
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
67
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('deletes expired keys', async () => {
|
|
71
|
-
const cache = createBrowserLocalStorageCache({
|
|
72
|
-
key: version,
|
|
73
|
-
timeToLive: -1,
|
|
74
|
-
});
|
|
75
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
76
|
-
|
|
77
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
78
|
-
|
|
79
|
-
expect(
|
|
80
|
-
await cache.get({ key: 'foo' }, defaultValue, {
|
|
81
|
-
miss: () => Promise.resolve(missMock()),
|
|
82
|
-
}),
|
|
83
|
-
).toMatchObject({ bar: 2 });
|
|
84
|
-
|
|
85
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test('can be cleared', async () => {
|
|
89
|
-
const cache = createBrowserLocalStorageCache({ key: version });
|
|
90
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
91
|
-
|
|
92
|
-
await cache.clear();
|
|
93
|
-
|
|
94
|
-
const defaultValue = (): Promise<void> => Promise.resolve({ bar: 2 });
|
|
95
|
-
|
|
96
|
-
expect(localStorage.length).toBe(0);
|
|
97
|
-
|
|
98
|
-
expect(
|
|
99
|
-
await cache.get({ key: 'foo' }, defaultValue, {
|
|
100
|
-
miss: () => Promise.resolve(missMock()),
|
|
101
|
-
}),
|
|
102
|
-
).toMatchObject({ bar: 2 });
|
|
103
|
-
|
|
104
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
105
|
-
|
|
106
|
-
expect(localStorage.getItem(`algolia-client-js-${version}`)).toEqual('{}');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('do throws localstorage exceptions on access', async () => {
|
|
110
|
-
const message = "Failed to read the 'localStorage' property from 'Window': Access is denied for this document.";
|
|
111
|
-
const cache = createBrowserLocalStorageCache(
|
|
112
|
-
new Proxy(
|
|
113
|
-
{ key: 'foo' },
|
|
114
|
-
{
|
|
115
|
-
get(_, key): DOMException | string {
|
|
116
|
-
if (key === 'key') {
|
|
117
|
-
return 'foo';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Simulates a window.localStorage access.
|
|
121
|
-
throw new DOMException(message);
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
),
|
|
125
|
-
);
|
|
126
|
-
const key = { foo: 'bar' };
|
|
127
|
-
const value = 'foo';
|
|
128
|
-
const fallback = 'bar';
|
|
129
|
-
|
|
130
|
-
await expect(cache.delete(key)).rejects.toEqual(new DOMException(message));
|
|
131
|
-
await expect(cache.set(key, value)).rejects.toEqual(new DOMException(message));
|
|
132
|
-
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new DOMException(message));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('do throws localstorage exceptions after access', async () => {
|
|
136
|
-
const cache = createBrowserLocalStorageCache({
|
|
137
|
-
key: version,
|
|
138
|
-
localStorage: notAvailableStorage,
|
|
139
|
-
});
|
|
140
|
-
const key = { foo: 'bar' };
|
|
141
|
-
const value = 'foo';
|
|
142
|
-
const fallback = 'bar';
|
|
143
|
-
const message = 'Component is not available';
|
|
144
|
-
|
|
145
|
-
await expect(cache.delete(key)).rejects.toEqual(new Error(message));
|
|
146
|
-
await expect(cache.set(key, value)).rejects.toEqual(new Error(message));
|
|
147
|
-
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new Error(message));
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test('creates a namespace within local storage', async () => {
|
|
151
|
-
const cache = createBrowserLocalStorageCache({
|
|
152
|
-
key: version,
|
|
153
|
-
});
|
|
154
|
-
const key = { foo: 'bar' };
|
|
155
|
-
const value = 'foo';
|
|
156
|
-
expect(localStorage.getItem(`algolia-client-js-${version}`)).toBeNull();
|
|
157
|
-
|
|
158
|
-
await cache.set(key, value);
|
|
159
|
-
|
|
160
|
-
const expectedValue = expect.objectContaining({
|
|
161
|
-
[JSON.stringify(key)]: {
|
|
162
|
-
timestamp: expect.any(Number),
|
|
163
|
-
value,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const localStorageValue = localStorage.getItem(`algolia-client-js-${version}`);
|
|
168
|
-
|
|
169
|
-
expect(JSON.parse(localStorageValue ? localStorageValue : '{}')).toEqual(expectedValue);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createBrowserLocalStorageCache,
|
|
5
|
-
createFallbackableCache,
|
|
6
|
-
createMemoryCache,
|
|
7
|
-
createNullCache,
|
|
8
|
-
} from '../../cache';
|
|
9
|
-
|
|
10
|
-
const version = 'foobar';
|
|
11
|
-
const notAvailableStorage = new Proxy(window.localStorage, {
|
|
12
|
-
get() {
|
|
13
|
-
return (): void => {
|
|
14
|
-
throw new Error('Component is not available');
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
type DefaultValue = Promise<Record<number, number>>;
|
|
20
|
-
|
|
21
|
-
describe('fallbackable cache', () => {
|
|
22
|
-
const key = { 1: 2 };
|
|
23
|
-
const value = { 3: 4 };
|
|
24
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ 5: 6 });
|
|
25
|
-
|
|
26
|
-
test('always fallback in null cache', async () => {
|
|
27
|
-
const cache = createFallbackableCache({ caches: [] });
|
|
28
|
-
|
|
29
|
-
await cache.set(key, value);
|
|
30
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
31
|
-
5: 6,
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe('order', () => {
|
|
36
|
-
test('use memory cache', async () => {
|
|
37
|
-
const cache = createFallbackableCache({
|
|
38
|
-
caches: [createMemoryCache()],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
await cache.set(key, value);
|
|
42
|
-
|
|
43
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
44
|
-
3: 4,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('use null cache first', async () => {
|
|
49
|
-
const cache = createFallbackableCache({
|
|
50
|
-
caches: [createNullCache(), createMemoryCache()],
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await cache.set(key, value);
|
|
54
|
-
|
|
55
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
56
|
-
5: 6,
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('fallback to to memory cache', async () => {
|
|
62
|
-
const cache = createFallbackableCache({
|
|
63
|
-
caches: [
|
|
64
|
-
createBrowserLocalStorageCache({
|
|
65
|
-
key: version,
|
|
66
|
-
// @ts-expect-error this will make the cache fail, and normally we fallback on memory cache
|
|
67
|
-
localStorage: {},
|
|
68
|
-
}),
|
|
69
|
-
createMemoryCache(),
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
await cache.set(key, value);
|
|
74
|
-
|
|
75
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
76
|
-
3: 4,
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('fallback to null cache', async () => {
|
|
81
|
-
const cache = createFallbackableCache({
|
|
82
|
-
caches: [
|
|
83
|
-
createBrowserLocalStorageCache({
|
|
84
|
-
key: version,
|
|
85
|
-
// @ts-expect-error this will make the cache fail, and normally we fallback on memory cache
|
|
86
|
-
localStorage: {},
|
|
87
|
-
}),
|
|
88
|
-
],
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
await cache.set(key, value);
|
|
92
|
-
|
|
93
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
94
|
-
5: 6,
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('fallback to memory cache', async () => {
|
|
99
|
-
const cache = createFallbackableCache({
|
|
100
|
-
caches: [
|
|
101
|
-
createBrowserLocalStorageCache({
|
|
102
|
-
key: version,
|
|
103
|
-
// @ts-expect-error this will make the cache fail
|
|
104
|
-
localStorage: {},
|
|
105
|
-
}),
|
|
106
|
-
createBrowserLocalStorageCache({
|
|
107
|
-
key: version,
|
|
108
|
-
localStorage: notAvailableStorage, // this will make the cache fail due localStorage not available
|
|
109
|
-
}),
|
|
110
|
-
createMemoryCache(),
|
|
111
|
-
],
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
await cache.set(key, value);
|
|
115
|
-
|
|
116
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
117
|
-
3: 4,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
await cache.clear();
|
|
121
|
-
|
|
122
|
-
expect(await cache.get(key, defaultValue)).toEqual({
|
|
123
|
-
5: 6,
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createMemoryCache } from '../../cache';
|
|
4
|
-
|
|
5
|
-
type DefaultValue = Promise<{ bar: number }>;
|
|
6
|
-
|
|
7
|
-
describe('memory cache', () => {
|
|
8
|
-
const missMock = vi.fn();
|
|
9
|
-
const events = {
|
|
10
|
-
miss: (): Promise<any> => Promise.resolve(missMock()),
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
vi.clearAllMocks();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('sets/gets values', async () => {
|
|
18
|
-
const cache = createMemoryCache();
|
|
19
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 1 });
|
|
20
|
-
|
|
21
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({
|
|
22
|
-
bar: 1,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
await cache.set({ key: 'foo' }, { foo: 2 });
|
|
26
|
-
|
|
27
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
28
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
|
|
29
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('getted values do not have references to the value on cache', async () => {
|
|
33
|
-
const cache = createMemoryCache();
|
|
34
|
-
const key = { foo: 'bar' };
|
|
35
|
-
const obj = { 1: { 2: 'bar' } };
|
|
36
|
-
const defaultObj = { 1: { 2: 'too' } };
|
|
37
|
-
|
|
38
|
-
await cache.set(key, obj);
|
|
39
|
-
const gettedValue = await cache.get(key, () => Promise.resolve(defaultObj));
|
|
40
|
-
gettedValue[1][2] = 'foo';
|
|
41
|
-
|
|
42
|
-
expect(await cache.get(key, () => Promise.resolve(defaultObj))).toEqual({
|
|
43
|
-
1: { 2: 'bar' },
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('deletes keys', async () => {
|
|
48
|
-
const cache = createMemoryCache();
|
|
49
|
-
|
|
50
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
51
|
-
await cache.delete({ key: 'foo' });
|
|
52
|
-
|
|
53
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
54
|
-
|
|
55
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
56
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('can be cleared', async () => {
|
|
60
|
-
const cache = createMemoryCache();
|
|
61
|
-
|
|
62
|
-
await cache.set({ key: 'foo' }, { bar: 1 });
|
|
63
|
-
await cache.clear();
|
|
64
|
-
|
|
65
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
66
|
-
|
|
67
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
68
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('do not force promise based api for clearing cache', async () => {
|
|
72
|
-
const cache = createMemoryCache();
|
|
73
|
-
|
|
74
|
-
cache.set({ key: 'foo' }, { bar: 1 });
|
|
75
|
-
cache.clear();
|
|
76
|
-
|
|
77
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 2 });
|
|
78
|
-
|
|
79
|
-
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
|
|
80
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { createNullCache } from '../../cache';
|
|
4
|
-
|
|
5
|
-
type DefaultValue = Promise<{ bar: number }>;
|
|
6
|
-
|
|
7
|
-
describe('null cache', () => {
|
|
8
|
-
const cache = createNullCache();
|
|
9
|
-
const missMock = vi.fn();
|
|
10
|
-
const events = {
|
|
11
|
-
miss: (): Promise<any> => Promise.resolve(missMock()),
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('does not set value', async () => {
|
|
19
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 12 });
|
|
20
|
-
|
|
21
|
-
await cache.set({ key: 'key' }, { foo: 10 });
|
|
22
|
-
|
|
23
|
-
expect(await cache.get({ key: 'key' }, defaultValue, events)).toMatchObject({
|
|
24
|
-
bar: 12,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('returns default value', async () => {
|
|
31
|
-
const defaultValue = (): DefaultValue => Promise.resolve({ bar: 12 });
|
|
32
|
-
|
|
33
|
-
expect(await cache.get({ foo: 'foo' }, defaultValue, events)).toMatchObject({
|
|
34
|
-
bar: 12,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
expect(missMock.mock.calls.length).toBe(1);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test('can be deleted', () => {
|
|
41
|
-
expect(async () => await cache.delete('foo')).not.toThrowError();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('can be cleared', () => {
|
|
45
|
-
expect(async () => await cache.clear()).not.toThrowError();
|
|
46
|
-
});
|
|
47
|
-
});
|