@forge/cache 0.8.0-next.2 → 0.9.0-next.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.
@@ -2,9 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tunnel_1 = require("../tunnel");
4
4
  const validator_1 = require("../utils/validator");
5
- const parseSuccessResponse = (response) => {
6
- return { response };
7
- };
8
5
  describe('Forge Cache Tunnel', () => {
9
6
  let cache;
10
7
  beforeEach(() => {
@@ -13,12 +10,12 @@ describe('Forge Cache Tunnel', () => {
13
10
  });
14
11
  test('set method', async () => {
15
12
  const response = await cache.set('key', 'value');
16
- expect(response).toStrictEqual(parseSuccessResponse('OK'));
13
+ expect(response).toStrictEqual(undefined);
17
14
  });
18
15
  test('get method', async () => {
19
16
  await cache.set('key', 'value');
20
17
  const response = await cache.get('key');
21
- expect(response).toStrictEqual(parseSuccessResponse('value'));
18
+ expect(response).toStrictEqual('value');
22
19
  });
23
20
  test('get method throws error for list value', async () => {
24
21
  cache.__localStore.set('key', ['value1', 'value2']);
@@ -31,51 +28,51 @@ describe('Forge Cache Tunnel', () => {
31
28
  });
32
29
  test('setIfNotExists method', async () => {
33
30
  const response = await cache.setIfNotExists('key', 'value');
34
- expect(response).toStrictEqual(parseSuccessResponse('OK'));
31
+ expect(response).toStrictEqual('OK');
35
32
  const newResponse = await cache.setIfNotExists('key', 'new value');
36
- expect(newResponse).toStrictEqual(parseSuccessResponse(null));
33
+ expect(newResponse).toStrictEqual(null);
37
34
  });
38
35
  test('getAndSet method', async () => {
39
36
  await cache.set('key', 'value');
40
37
  const response = await cache.getAndSet('key', 'new value');
41
- expect(response).toStrictEqual(parseSuccessResponse('value'));
38
+ expect(response).toStrictEqual('value');
42
39
  const newResponse = await cache.get('key');
43
- expect(newResponse).toStrictEqual(parseSuccessResponse('new value'));
40
+ expect(newResponse).toStrictEqual('new value');
44
41
  });
45
42
  test('delete method', async () => {
46
43
  await cache.set('key', 'value');
47
44
  const response = await cache.delete('key');
48
- expect(response).toStrictEqual(parseSuccessResponse(1));
45
+ expect(response).toStrictEqual(1);
49
46
  const newResponse = await cache.get('key');
50
- expect(newResponse).toStrictEqual(parseSuccessResponse(null));
47
+ expect(newResponse).toStrictEqual(null);
51
48
  });
52
49
  test('incrementAndGet method', async () => {
53
50
  await cache.set('key', '5');
54
51
  const response = await cache.incrementAndGet('key');
55
- expect(response).toStrictEqual(parseSuccessResponse(6));
52
+ expect(response).toStrictEqual(6);
56
53
  });
57
54
  test('leftPush method', async () => {
58
55
  cache.__localStore.set('key', ['value1', 'value2']);
59
56
  const response = await cache.leftPush('key', 'value3');
60
57
  const result = ['value3', 'value1', 'value2'].length;
61
- expect(response).toStrictEqual(parseSuccessResponse(result));
58
+ expect(response).toStrictEqual(result);
62
59
  });
63
60
  test('rightPop method', async () => {
64
61
  await cache.leftPush('key', 'value1');
65
62
  await cache.leftPush('key', 'value2');
66
63
  const response = await cache.rightPop('key');
67
- expect(response).toStrictEqual(parseSuccessResponse('value1'));
64
+ expect(response).toStrictEqual('value1');
68
65
  });
69
66
  test('listLength method', async () => {
70
67
  await cache.leftPush('key', 'value1');
71
68
  await cache.leftPush('key', 'value2');
72
69
  const response = await cache.listLength('key');
73
- expect(response).toStrictEqual(parseSuccessResponse(2));
70
+ expect(response).toStrictEqual(2);
74
71
  });
75
72
  test('decrementAndGet method', async () => {
76
73
  await cache.set('key', '5');
77
74
  const response = await cache.decrementAndGet('key');
78
- expect(response).toStrictEqual(parseSuccessResponse(4));
75
+ expect(response).toStrictEqual(4);
79
76
  });
80
77
  test('incrementAndGet method throws error when key holds a list value', async () => {
81
78
  cache.__localStore.set('key', ['value1', 'value2']);
package/out/tunnel.d.ts CHANGED
@@ -28,6 +28,6 @@ export declare class TunnelCache implements IForgeCache {
28
28
  cursor?: string;
29
29
  count?: number;
30
30
  }): Promise<ScanResult>;
31
- parseSuccessResponse(response: string | number | null | string[]): Promise<any>;
31
+ parseSuccessResponse(response: string | number | null | string[] | any): Promise<any>;
32
32
  }
33
33
  //# sourceMappingURL=tunnel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tunnel.d.ts","sourceRoot":"","sources":["../src/tunnel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQjD,oBAAY,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAAC,CAAC;AAEzE,qBAAa,WAAY,YAAW,WAAW;IACtC,YAAY,EAAE,eAAe,CAAC;gBACzB,KAAK,EAAE,eAAe;IAKrB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5E,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAQxC,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;IAW9F,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAU3F,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASpC,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3E,QAAQ,CAAC,GAAG,EAAE,MAA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(0, validator_1.assertIsValidValue)(value);
12
12
  (0, validator_1.assertIsSizedValue)(value);
13
13
  this.__localStore.set(key, value);
14
- return await this.parseSuccessResponse('OK');
15
14
  }
16
15
  async get(key) {
17
16
  (0, validator_1.assertIsValidKey)(key);
18
17
  const value = this.__localStore.get(key);
19
18
  (0, validator_1.assertAndThrowIfArray)(value);
20
- return await this.parseSuccessResponse(value !== null && value !== void 0 ? value : null);
19
+ const { response: result } = await this.parseSuccessResponse(value !== null && value !== void 0 ? value : null);
20
+ return result;
21
21
  }
22
22
  async setIfNotExists(key, value, opt) {
23
23
  (0, validator_1.assertIsValidKey)(key);
24
24
  (0, validator_1.assertIsValidValue)(value);
25
25
  (0, validator_1.assertIsSizedValue)(value);
26
26
  if (this.__localStore.get(key)) {
27
- return await this.parseSuccessResponse(null);
27
+ const { response: result } = await this.parseSuccessResponse(null);
28
+ return result;
28
29
  }
29
30
  this.__localStore.set(key, value);
30
- return await this.parseSuccessResponse('OK');
31
+ const { response: result } = await this.parseSuccessResponse('OK');
32
+ return result;
31
33
  }
32
34
  async getAndSet(key, value, opt) {
33
35
  var _a;
@@ -36,15 +38,18 @@ class TunnelCache {
36
38
  (0, validator_1.assertIsSizedValue)(value);
37
39
  const oldValue = (_a = this.__localStore.get(key)) !== null && _a !== void 0 ? _a : null;
38
40
  this.__localStore.set(key, value);
39
- return await this.parseSuccessResponse(oldValue);
41
+ const { response: result } = await this.parseSuccessResponse(oldValue);
42
+ return result;
40
43
  }
41
44
  async delete(key) {
42
45
  (0, validator_1.assertIsValidKey)(key);
43
46
  if (this.__localStore.get(key)) {
44
47
  this.__localStore.delete(key);
45
- return await this.parseSuccessResponse(1);
48
+ const { response: result } = await this.parseSuccessResponse(1);
49
+ return result;
46
50
  }
47
- return await this.parseSuccessResponse(0);
51
+ const { response: result } = await this.parseSuccessResponse(0);
52
+ return result;
48
53
  }
49
54
  async incrementAndGet(key, opt) {
50
55
  var _a;
@@ -53,7 +58,8 @@ class TunnelCache {
53
58
  (0, validator_1.assertAndThrowIfArray)(oldValue);
54
59
  const newValue = Number.parseInt((_a = oldValue) !== null && _a !== void 0 ? _a : '0') + 1;
55
60
  this.__localStore.set(key, newValue.toString());
56
- return await this.parseSuccessResponse(newValue);
61
+ const { response: result } = await this.parseSuccessResponse(newValue);
62
+ return result;
57
63
  }
58
64
  async leftPush(key, value) {
59
65
  (0, validator_1.assertIsValidKey)(key);
@@ -65,25 +71,30 @@ class TunnelCache {
65
71
  this.__localStore.set(key, []);
66
72
  }
67
73
  this.__localStore.get(key).unshift(value);
68
- return await this.parseSuccessResponse(this.__localStore.get(key).length);
74
+ const { response: result } = await this.parseSuccessResponse(this.__localStore.get(key).length);
75
+ return result;
69
76
  }
70
77
  async rightPop(key) {
71
78
  (0, validator_1.assertIsValidKey)(key);
72
79
  const oldValue = this.__localStore.get(key);
73
80
  if (!oldValue) {
74
- return await this.parseSuccessResponse(null);
81
+ const { response: result } = await this.parseSuccessResponse(null);
82
+ return result;
75
83
  }
76
84
  (0, validator_1.assertAndThrowIfNotArray)(oldValue);
77
- return await this.parseSuccessResponse(this.__localStore.get(key).pop() || null);
85
+ const { response: result } = await this.parseSuccessResponse(this.__localStore.get(key).pop() || null);
86
+ return result;
78
87
  }
79
88
  async listLength(key) {
80
89
  (0, validator_1.assertIsValidKey)(key);
81
90
  const oldValue = this.__localStore.get(key);
82
91
  if (!oldValue) {
83
- return await this.parseSuccessResponse(0);
92
+ const { response: result } = await this.parseSuccessResponse(0);
93
+ return result;
84
94
  }
85
95
  (0, validator_1.assertAndThrowIfNotArray)(oldValue);
86
- return await this.parseSuccessResponse(this.__localStore.get(key).length);
96
+ const { response: result } = await this.parseSuccessResponse(this.__localStore.get(key).length);
97
+ return result;
87
98
  }
88
99
  async decrementAndGet(key, opt) {
89
100
  var _a;
@@ -92,7 +103,8 @@ class TunnelCache {
92
103
  (0, validator_1.assertAndThrowIfArray)(oldValue);
93
104
  const newValue = Number.parseInt((_a = oldValue) !== null && _a !== void 0 ? _a : '0') - 1;
94
105
  this.__localStore.set(key, newValue.toString());
95
- return await this.parseSuccessResponse(newValue);
106
+ const { response: result } = await this.parseSuccessResponse(newValue);
107
+ return result;
96
108
  }
97
109
  async scan(pattern, opt) {
98
110
  const cursor = (opt === null || opt === void 0 ? void 0 : opt.cursor) ? Number(opt.cursor) : 0;
@@ -1,11 +1,14 @@
1
- export declare class ForgeCacheTunnelError extends Error {
1
+ import { HttpError } from '@forge/api';
2
+ export declare class ForgeCacheTunnelError extends HttpError {
2
3
  readonly message: string;
3
4
  readonly reason?: any;
4
- constructor(message: string, reason?: any);
5
+ readonly status: number;
6
+ constructor(message: string, reason?: any, status?: number);
5
7
  }
6
8
  export declare function assertIsValidValue(value: unknown): void;
7
9
  export declare function assertAndThrowIfArray(value: string | number | undefined | string[]): void;
8
10
  export declare function assertAndThrowIfNotArray(value: string | number | undefined | string[]): void;
9
11
  export declare function assertIsValidKey(key: unknown): void;
10
12
  export declare function assertIsSizedValue(value: unknown): void;
13
+ export declare function getErrorMessageObj(title: string): string;
11
14
  //# sourceMappingURL=validator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/utils/validator.ts"],"names":[],"mappings":"AASA,qBAAa,qBAAsB,SAAQ,KAAK;IAE5C,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,MAAM,CAAC;gBADP,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,KAAK;CAIxB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAOhD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,QAIlF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,QAIrF;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,QAsB5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAOhD"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/utils/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAUvC,qBAAa,qBAAsB,SAAQ,SAAS;IAEhD,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,MAAM,CAAC;IAChB,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAFd,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,KAAK,EACZ,MAAM,GAAE,MAAY;CAKhC;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAOhD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,QAIlF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,QAIrF;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,QAsB5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAOhD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQxD"}
@@ -1,27 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertIsSizedValue = exports.assertIsValidKey = exports.assertAndThrowIfNotArray = exports.assertAndThrowIfArray = exports.assertIsValidValue = exports.ForgeCacheTunnelError = void 0;
3
+ exports.getErrorMessageObj = exports.assertIsSizedValue = exports.assertIsValidKey = exports.assertAndThrowIfNotArray = exports.assertAndThrowIfArray = exports.assertIsValidValue = exports.ForgeCacheTunnelError = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const api_1 = require("@forge/api");
5
6
  const object_sizeof_1 = tslib_1.__importDefault(require("object-sizeof"));
6
7
  const MIN_VALID_KEY_LENGTH = 1;
7
8
  const MAX_VALID_KEY_LENGTH = 500;
8
9
  const VALID_KEY_REGEX = /^(?!\s+$)[a-zA-Z0-9:._\s-#]+$/;
9
10
  const KiB = 1024;
10
11
  const MAX_VALID_VALUE_LENGTH = 240 * KiB;
11
- class ForgeCacheTunnelError extends Error {
12
- constructor(message, reason) {
12
+ class ForgeCacheTunnelError extends api_1.HttpError {
13
+ constructor(message, reason, status = 400) {
13
14
  super(message);
14
15
  this.message = message;
15
16
  this.reason = reason;
17
+ this.status = status;
18
+ this.message = `${status}: ${message}`;
16
19
  }
17
20
  }
18
21
  exports.ForgeCacheTunnelError = ForgeCacheTunnelError;
19
22
  function assertIsValidValue(value) {
20
23
  if (value === undefined || value === null) {
21
- throw new ForgeCacheTunnelError('Provided value is required');
24
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided value is required'));
22
25
  }
23
26
  if (typeof value !== 'string') {
24
- throw new ForgeCacheTunnelError('Provided value must be a string', { type: typeof value });
27
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided value must be a string'), { type: typeof value });
25
28
  }
26
29
  }
27
30
  exports.assertIsValidValue = assertIsValidValue;
@@ -42,19 +45,19 @@ function assertIsValidKey(key) {
42
45
  throw new Error('Provided key must be a string');
43
46
  }
44
47
  if (key.length < MIN_VALID_KEY_LENGTH) {
45
- throw new ForgeCacheTunnelError('Provided key length was under the minimum valid key length', {
48
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided key length was under the minimum valid key length'), {
46
49
  length: key.length,
47
50
  minLength: MIN_VALID_KEY_LENGTH
48
51
  });
49
52
  }
50
53
  if (key.length > MAX_VALID_KEY_LENGTH) {
51
- throw new ForgeCacheTunnelError('Provided key length was above the maximum valid key length', {
54
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided key length was above the maximum valid key length'), {
52
55
  length: key.length,
53
56
  maxLength: MAX_VALID_KEY_LENGTH
54
57
  });
55
58
  }
56
59
  if (!VALID_KEY_REGEX.test(key)) {
57
- throw new ForgeCacheTunnelError('Provided key must match regex', {
60
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided key must match regex'), {
58
61
  regex: VALID_KEY_REGEX
59
62
  });
60
63
  }
@@ -62,10 +65,20 @@ function assertIsValidKey(key) {
62
65
  exports.assertIsValidKey = assertIsValidKey;
63
66
  function assertIsSizedValue(value) {
64
67
  if ((0, object_sizeof_1.default)(value) > MAX_VALID_VALUE_LENGTH) {
65
- throw new ForgeCacheTunnelError('Provided value bytes was over maximum valid value size', {
68
+ throw new ForgeCacheTunnelError(getErrorMessageObj('Provided value bytes was over maximum valid value size'), {
66
69
  bytes: (0, object_sizeof_1.default)(value),
67
70
  maxBytes: MAX_VALID_VALUE_LENGTH
68
71
  });
69
72
  }
70
73
  }
71
74
  exports.assertIsSizedValue = assertIsSizedValue;
75
+ function getErrorMessageObj(title) {
76
+ const obj = {
77
+ error: {
78
+ code: 'BadRequest',
79
+ title: title
80
+ }
81
+ };
82
+ return JSON.stringify(obj);
83
+ }
84
+ exports.getErrorMessageObj = getErrorMessageObj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/cache",
3
- "version": "0.8.0-next.2",
3
+ "version": "0.9.0-next.0",
4
4
  "description": "Forge Cache methods",
5
5
  "author": "Atlassian",
6
6
  "license": "UNLICENSED",
@@ -20,7 +20,7 @@
20
20
  "node-fetch": "2.7.0"
21
21
  },
22
22
  "dependencies": {
23
- "@forge/api": "^3.6.0-next.0",
23
+ "@forge/api": "^3.6.0",
24
24
  "object-sizeof": "^2.6.4"
25
25
  }
26
26
  }