@forge/cache 0.8.0 → 0.9.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/out/__test__/tunnel.test.js +19 -22
- package/out/cache.d.ts.map +1 -1
- package/out/tunnel.d.ts +1 -1
- package/out/tunnel.d.ts.map +1 -1
- package/out/tunnel.js +26 -14
- package/out/utils/validator.d.ts +5 -2
- package/out/utils/validator.d.ts.map +1 -1
- package/out/utils/validator.js +24 -11
- package/package.json +1 -1
|
@@ -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(
|
|
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(
|
|
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']);
|
|
@@ -26,56 +23,56 @@ describe('Forge Cache Tunnel', () => {
|
|
|
26
23
|
await cache.get('key');
|
|
27
24
|
}
|
|
28
25
|
catch (error) {
|
|
29
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
26
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
30
27
|
}
|
|
31
28
|
});
|
|
32
29
|
test('setIfNotExists method', async () => {
|
|
33
30
|
const response = await cache.setIfNotExists('key', 'value');
|
|
34
|
-
expect(response).toStrictEqual(
|
|
31
|
+
expect(response).toStrictEqual('OK');
|
|
35
32
|
const newResponse = await cache.setIfNotExists('key', 'new value');
|
|
36
|
-
expect(newResponse).toStrictEqual(
|
|
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(
|
|
38
|
+
expect(response).toStrictEqual('value');
|
|
42
39
|
const newResponse = await cache.get('key');
|
|
43
|
-
expect(newResponse).toStrictEqual(
|
|
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(
|
|
45
|
+
expect(response).toStrictEqual(1);
|
|
49
46
|
const newResponse = await cache.get('key');
|
|
50
|
-
expect(newResponse).toStrictEqual(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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']);
|
|
@@ -83,7 +80,7 @@ describe('Forge Cache Tunnel', () => {
|
|
|
83
80
|
await cache.incrementAndGet('key');
|
|
84
81
|
}
|
|
85
82
|
catch (error) {
|
|
86
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
83
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
87
84
|
}
|
|
88
85
|
});
|
|
89
86
|
test('leftPush method throws error when key holds a non-list value', async () => {
|
|
@@ -92,7 +89,7 @@ describe('Forge Cache Tunnel', () => {
|
|
|
92
89
|
await cache.leftPush('key', 'newValue');
|
|
93
90
|
}
|
|
94
91
|
catch (error) {
|
|
95
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
92
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
96
93
|
}
|
|
97
94
|
});
|
|
98
95
|
test('rightPop method throws error when key holds a non-list value', async () => {
|
|
@@ -101,7 +98,7 @@ describe('Forge Cache Tunnel', () => {
|
|
|
101
98
|
await cache.rightPop('key');
|
|
102
99
|
}
|
|
103
100
|
catch (error) {
|
|
104
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
101
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
105
102
|
}
|
|
106
103
|
});
|
|
107
104
|
test('listLength method throws error when key holds a non-list value', async () => {
|
|
@@ -110,7 +107,7 @@ describe('Forge Cache Tunnel', () => {
|
|
|
110
107
|
await cache.listLength('key');
|
|
111
108
|
}
|
|
112
109
|
catch (error) {
|
|
113
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
110
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
114
111
|
}
|
|
115
112
|
});
|
|
116
113
|
test('decrementAndGet method throws error when key holds a list value', async () => {
|
|
@@ -119,7 +116,7 @@ describe('Forge Cache Tunnel', () => {
|
|
|
119
116
|
await cache.decrementAndGet('key');
|
|
120
117
|
}
|
|
121
118
|
catch (error) {
|
|
122
|
-
expect(error).toEqual(new validator_1.ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
119
|
+
expect(error).toEqual(new validator_1.ForgeCacheTunnelError((0, validator_1.getErrorMessageObj)('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422));
|
|
123
120
|
}
|
|
124
121
|
});
|
|
125
122
|
describe('scan method', () => {
|
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,WAAW,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAmB,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAOjD,oBAAY,QAAQ,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,CAAC;AAEzE,oBAAY,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAGF,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAYtE;AAED,qBAAa,KAAM,YAAW,WAAW;IAC3B,OAAO,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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AAM,GAAG,IAAI,CAAC;IAU7C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAMtD;AAED,wBAAgB,oBAAoB,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAG/G;AAID,wBAAgB,uBAAuB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA0BpG;AAED,wBAAgB,OAAO,IAAI,KAAK,GAAG,WAAW,CAS7C"}
|
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
|
package/out/tunnel.d.ts.map
CHANGED
|
@@ -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,MA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,OAAO,CAAC,MAAM,CAAC;IAkBrD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAkB7C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAaxC,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAe3E,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBlG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,EAAE,GAAG,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAKtF"}
|
package/out/tunnel.js
CHANGED
|
@@ -11,23 +11,25 @@ class TunnelCache {
|
|
|
11
11
|
(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
|
-
|
|
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
|
-
|
|
27
|
+
const { response: result } = await this.parseSuccessResponse(null);
|
|
28
|
+
return result;
|
|
28
29
|
}
|
|
29
30
|
this.__localStore.set(key, value);
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
+
const { response: result } = await this.parseSuccessResponse(1);
|
|
49
|
+
return result;
|
|
46
50
|
}
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
81
|
+
const { response: result } = await this.parseSuccessResponse(null);
|
|
82
|
+
return result;
|
|
75
83
|
}
|
|
76
84
|
(0, validator_1.assertAndThrowIfNotArray)(oldValue);
|
|
77
|
-
|
|
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
|
-
|
|
92
|
+
const { response: result } = await this.parseSuccessResponse(0);
|
|
93
|
+
return result;
|
|
84
94
|
}
|
|
85
95
|
(0, validator_1.assertAndThrowIfNotArray)(oldValue);
|
|
86
|
-
|
|
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
|
-
|
|
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;
|
package/out/utils/validator.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { HttpError } from '@forge/api';
|
|
2
|
+
export declare class ForgeCacheTunnelError extends HttpError {
|
|
2
3
|
readonly message: string;
|
|
3
4
|
readonly reason?: any;
|
|
4
|
-
|
|
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, code?: 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":"
|
|
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,QAQlF;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,QAQrF;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,QAsB5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAOhD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAe,GAAG,MAAM,CAQ7E"}
|
package/out/utils/validator.js
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
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
|
|
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;
|
|
28
31
|
function assertAndThrowIfArray(value) {
|
|
29
32
|
if (value && Array.isArray(value)) {
|
|
30
|
-
throw new ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
33
|
+
throw new ForgeCacheTunnelError(getErrorMessageObj('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422);
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
exports.assertAndThrowIfArray = assertAndThrowIfArray;
|
|
34
37
|
function assertAndThrowIfNotArray(value) {
|
|
35
38
|
if (value && !Array.isArray(value)) {
|
|
36
|
-
throw new ForgeCacheTunnelError('WRONGTYPE Operation against a key holding the wrong kind of value
|
|
39
|
+
throw new ForgeCacheTunnelError(getErrorMessageObj('WRONGTYPE Operation against a key holding the wrong kind of value', 'UnprocessableContent'), {}, 422);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
exports.assertAndThrowIfNotArray = assertAndThrowIfNotArray;
|
|
@@ -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, code = 'BadRequest') {
|
|
76
|
+
const obj = {
|
|
77
|
+
error: {
|
|
78
|
+
code: code,
|
|
79
|
+
title: title
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return JSON.stringify(obj);
|
|
83
|
+
}
|
|
84
|
+
exports.getErrorMessageObj = getErrorMessageObj;
|