@forge/cache 0.2.6-next.0 → 0.3.0-next.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/README.md +4 -0
- package/out/__test__/cache.test.js +37 -0
- package/out/cache.d.ts +2 -0
- package/out/cache.d.ts.map +1 -1
- package/out/cache.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,4 +13,8 @@ const result = await cacheClient.setIfNotExists("hello", "3", { ttlSeconds: 10 }
|
|
|
13
13
|
const result = await cacheClient.get("hello");
|
|
14
14
|
|
|
15
15
|
const result = await cacheClient.incrementAndGet("hello");
|
|
16
|
+
|
|
17
|
+
const result = await cacheClient.decrementAndGet("hello");
|
|
18
|
+
|
|
19
|
+
const result = await cacheClient.delete("hello");
|
|
16
20
|
```
|
|
@@ -189,4 +189,41 @@ describe('Cache', () => {
|
|
|
189
189
|
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
190
190
|
});
|
|
191
191
|
});
|
|
192
|
+
describe('decrementAndGet', () => {
|
|
193
|
+
it('handles success', async () => {
|
|
194
|
+
const { cache, fetch } = buildCache();
|
|
195
|
+
fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 0 }), status: 200 });
|
|
196
|
+
const result = await cache.decrementAndGet('key');
|
|
197
|
+
expect(result).toEqual(0);
|
|
198
|
+
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
199
|
+
});
|
|
200
|
+
it('handles success when key exists', async () => {
|
|
201
|
+
const { cache, fetch } = buildCache();
|
|
202
|
+
fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 11 }), status: 200 });
|
|
203
|
+
const result = await cache.decrementAndGet('key');
|
|
204
|
+
expect(result).toEqual(11);
|
|
205
|
+
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
206
|
+
});
|
|
207
|
+
it('handles failure', async () => {
|
|
208
|
+
const { cache, fetch } = buildCache();
|
|
209
|
+
fetch.mockResolvedValueOnce({ ok: false, text: async () => 'Not allowed', status: 403 });
|
|
210
|
+
await expect(cache.decrementAndGet('key')).rejects.toMatchError(new api_1.HttpError('403: Not allowed'));
|
|
211
|
+
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe('delete', () => {
|
|
215
|
+
it('handles success', async () => {
|
|
216
|
+
const { cache, fetch } = buildCache();
|
|
217
|
+
fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 1 }), status: 200 });
|
|
218
|
+
const result = await cache.delete('key');
|
|
219
|
+
expect(result).toEqual(1);
|
|
220
|
+
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
221
|
+
});
|
|
222
|
+
it('handles failure', async () => {
|
|
223
|
+
const { cache, fetch } = buildCache();
|
|
224
|
+
fetch.mockResolvedValueOnce({ ok: false, text: async () => 'Not allowed', status: 403 });
|
|
225
|
+
await expect(cache.delete('key')).rejects.toMatchError(new api_1.HttpError('403: Not allowed'));
|
|
226
|
+
expect(fetch.mock.lastCall).toMatchSnapshot();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
192
229
|
});
|
package/out/cache.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare class Cache {
|
|
|
13
13
|
}): Promise<'OK' | null>;
|
|
14
14
|
get(key: string): Promise<string>;
|
|
15
15
|
incrementAndGet(key: string): Promise<number>;
|
|
16
|
+
decrementAndGet(key: string): Promise<number>;
|
|
17
|
+
delete(key: string): Promise<number>;
|
|
16
18
|
}
|
|
17
19
|
export declare function getFetchRmsRuntimeV1(): ((path: string, options?: RequestInit) => Promise<Response>) | undefined;
|
|
18
20
|
export declare function createFetchRmsRuntimeV2(): (path: string, options?: RequestInit) => Promise<Response>;
|
package/out/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AACA,OAAkB,EAAE,W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CAAC,MAAM;gBAAN,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC;IAGtF,OAAO,CAAC,YAAY;IAUP,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5E,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAO9F,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOjC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMlD;AAED,wBAAgB,oBAAoB,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAE/G;AAID,wBAAgB,uBAAuB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA2BpG;AAED,wBAAgB,OAAO,UAItB"}
|
package/out/cache.js
CHANGED
|
@@ -48,6 +48,16 @@ class Cache {
|
|
|
48
48
|
const { response: result } = await getResponseBody(response);
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
51
|
+
async decrementAndGet(key) {
|
|
52
|
+
const response = await this.client('rms/store/decr', this.buildRequest({ key }));
|
|
53
|
+
const { response: result } = await getResponseBody(response);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
async delete(key) {
|
|
57
|
+
const response = await this.client('rms/store/delete', this.buildRequest({ key }));
|
|
58
|
+
const { response: result } = await getResponseBody(response);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
51
61
|
}
|
|
52
62
|
exports.Cache = Cache;
|
|
53
63
|
function getFetchRmsRuntimeV1() {
|