@forge/cache 0.7.0-next.1 → 0.7.0-next.2

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 CHANGED
@@ -21,4 +21,10 @@ const result = await cacheClient.decrementAndGet("hello");
21
21
  const result = await cacheClient.delete("hello");
22
22
 
23
23
  const result = await cacheClient.scan("hello*", { cursor: "10", count: 10 });
24
+
25
+ const result = await cacheClient.leftPush("list", "3");
26
+
27
+ const result = await cacheClient.rightPop("list");
28
+
29
+ const result = await cacheClient.listLength("list");
24
30
  ```
@@ -305,4 +305,63 @@ describe('Cache', () => {
305
305
  expect(fetch.mock.lastCall).toMatchSnapshot();
306
306
  });
307
307
  });
308
+ describe('leftPush', () => {
309
+ it('handles success', async () => {
310
+ const { cache, fetch } = buildCache();
311
+ fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 1 }), status: 200 });
312
+ const result = await cache.leftPush('list', 'value');
313
+ expect(result).toEqual(1);
314
+ expect(fetch.mock.lastCall).toMatchSnapshot();
315
+ });
316
+ it('handles failure', async () => {
317
+ const { cache, fetch } = buildCache();
318
+ fetch.mockResolvedValueOnce({ ok: false, text: async () => 'Not allowed', status: 403 });
319
+ await expect(cache.leftPush('list', 'value')).rejects.toMatchError(new api_1.HttpError('403: Not allowed'));
320
+ expect(fetch.mock.lastCall).toMatchSnapshot();
321
+ });
322
+ });
323
+ describe('rightPop', () => {
324
+ it('handles success', async () => {
325
+ const { cache, fetch } = buildCache();
326
+ fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 'value' }), status: 200 });
327
+ const result = await cache.rightPop('list');
328
+ expect(result).toEqual('value');
329
+ expect(fetch.mock.lastCall).toMatchSnapshot();
330
+ });
331
+ it('handles success when key does not exist', async () => {
332
+ const { cache, fetch } = buildCache();
333
+ fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: null }), status: 200 });
334
+ const result = await cache.rightPop('list');
335
+ expect(result).toBeNull();
336
+ expect(fetch.mock.lastCall).toMatchSnapshot();
337
+ });
338
+ it('handles failure', async () => {
339
+ const { cache, fetch } = buildCache();
340
+ fetch.mockResolvedValueOnce({ ok: false, text: async () => 'Not allowed', status: 403 });
341
+ await expect(cache.rightPop('list')).rejects.toMatchError(new api_1.HttpError('403: Not allowed'));
342
+ expect(fetch.mock.lastCall).toMatchSnapshot();
343
+ });
344
+ });
345
+ describe('listLength', () => {
346
+ it('handles success', async () => {
347
+ const { cache, fetch } = buildCache();
348
+ fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 2 }), status: 200 });
349
+ const result = await cache.listLength('list');
350
+ expect(result).toBe(2);
351
+ expect(fetch.mock.lastCall).toMatchSnapshot();
352
+ });
353
+ it('handles success when key does not exist', async () => {
354
+ const { cache, fetch } = buildCache();
355
+ fetch.mockResolvedValueOnce({ ok: true, text: async () => JSON.stringify({ response: 0 }), status: 200 });
356
+ const result = await cache.listLength('list');
357
+ expect(result).toBe(0);
358
+ expect(fetch.mock.lastCall).toMatchSnapshot();
359
+ });
360
+ it('handles failure', async () => {
361
+ const { cache, fetch } = buildCache();
362
+ fetch.mockResolvedValueOnce({ ok: false, text: async () => 'Not allowed', status: 403 });
363
+ await expect(cache.listLength('list')).rejects.toMatchError(new api_1.HttpError('403: Not allowed'));
364
+ expect(fetch.mock.lastCall).toMatchSnapshot();
365
+ });
366
+ });
308
367
  });
package/out/cache.d.ts CHANGED
@@ -26,6 +26,9 @@ export declare class Cache {
26
26
  cursor?: string;
27
27
  count?: number;
28
28
  }): Promise<ScanResult>;
29
+ leftPush(key: string, value: string): Promise<number>;
30
+ rightPop(key: string): Promise<string | null>;
31
+ listLength(key: string): Promise<number>;
29
32
  }
30
33
  export declare function getFetchRmsRuntimeV1(): ((path: string, options?: RequestInit) => Promise<Response>) | undefined;
31
34
  export declare function createFetchRmsRuntimeV2(): (path: string, options?: RequestInit) => Promise<Response>;
@@ -1 +1 @@
1
- {"version":3,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C,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,CA4BpG;AAED,wBAAgB,OAAO,UAItB"}
package/out/cache.js CHANGED
@@ -68,6 +68,21 @@ class Cache {
68
68
  const response = await this.client('rms/store/scan', this.buildRequest({ cursor, pattern, count }));
69
69
  return await getResponseBody(response);
70
70
  }
71
+ async leftPush(key, value) {
72
+ const response = await this.client('rms/store/lpush', this.buildRequest({ key, value }));
73
+ const { response: result } = await getResponseBody(response);
74
+ return result;
75
+ }
76
+ async rightPop(key) {
77
+ const response = await this.client('rms/store/rpop', this.buildRequest({ key }));
78
+ const { response: result } = await getResponseBody(response);
79
+ return result;
80
+ }
81
+ async listLength(key) {
82
+ const response = await this.client('rms/store/llen', this.buildRequest({ key }));
83
+ const { response: result } = await getResponseBody(response);
84
+ return result;
85
+ }
71
86
  }
72
87
  exports.Cache = Cache;
73
88
  function getFetchRmsRuntimeV1() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/cache",
3
- "version": "0.7.0-next.1",
3
+ "version": "0.7.0-next.2",
4
4
  "description": "Forge Cache methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",