@forge/sql 0.0.1-experimental-30ae54f → 0.0.1-experimental-f20602a
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__/sql.test.js +9 -11
- package/out/errorCodes.d.ts +6 -0
- package/out/errorCodes.d.ts.map +1 -0
- package/out/errorCodes.js +8 -0
- package/out/index.d.ts +2 -0
- package/out/index.d.ts.map +1 -1
- package/out/index.js +3 -0
- package/out/sql.d.ts +1 -0
- package/out/sql.d.ts.map +1 -1
- package/out/sql.js +16 -14
- package/out/utils/__test__/response-handler.test.js +3 -3
- package/out/utils/response-handler.d.ts +2 -1
- package/out/utils/response-handler.d.ts.map +1 -1
- package/out/utils/response-handler.js +4 -2
- package/package.json +2 -2
package/out/__test__/sql.test.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const api_1 = require("@forge/api");
|
|
4
4
|
const sql_1 = require("../sql");
|
|
5
5
|
const sql_statement_1 = require("../sql-statement");
|
|
6
|
-
const response_handler_1 = require("../utils/response-handler");
|
|
7
6
|
jest.mock('@forge/api');
|
|
8
7
|
jest.mock('../sql-statement');
|
|
9
8
|
jest.mock('../utils/response-handler', () => ({
|
|
@@ -32,7 +31,7 @@ describe('SqlClient', () => {
|
|
|
32
31
|
it('should send a request with the correct options and return the response', async () => {
|
|
33
32
|
const mockResponse = { ok: true, status: 200 };
|
|
34
33
|
mockFetch.mockResolvedValue(mockResponse);
|
|
35
|
-
const path = 'api/v1/
|
|
34
|
+
const path = 'api/v1/execute';
|
|
36
35
|
const options = { method: 'GET', headers: { 'Custom-Header': 'value' } };
|
|
37
36
|
const response = await sqlClient['sendRequest'](path, options);
|
|
38
37
|
expect(mockFetch).toHaveBeenCalledWith(path, {
|
|
@@ -48,7 +47,7 @@ describe('SqlClient', () => {
|
|
|
48
47
|
it('should handle requests without options', async () => {
|
|
49
48
|
const mockResponse = { ok: true, status: 200 };
|
|
50
49
|
mockFetch.mockResolvedValue(mockResponse);
|
|
51
|
-
const path = 'api/v1/
|
|
50
|
+
const path = 'api/v1/execute';
|
|
52
51
|
const response = await sqlClient['sendRequest'](path);
|
|
53
52
|
expect(mockFetch).toHaveBeenCalledWith(path, {
|
|
54
53
|
redirect: 'follow',
|
|
@@ -61,7 +60,7 @@ describe('SqlClient', () => {
|
|
|
61
60
|
it('should propagate fetch errors', async () => {
|
|
62
61
|
const mockError = new Error('Network error');
|
|
63
62
|
mockFetch.mockRejectedValue(mockError);
|
|
64
|
-
const path = 'api/v1/
|
|
63
|
+
const path = 'api/v1/execute';
|
|
65
64
|
await expect(sqlClient['sendRequest'](path)).rejects.toThrow(mockError);
|
|
66
65
|
expect(mockFetch).toHaveBeenCalledWith(path, expect.any(Object));
|
|
67
66
|
});
|
|
@@ -72,7 +71,7 @@ describe('SqlClient', () => {
|
|
|
72
71
|
mockFetch.mockResolvedValue(mockResponse);
|
|
73
72
|
mockGetResponseBody.mockResolvedValue({ rows: [] });
|
|
74
73
|
const result = await sqlClient.storageApi('SELECT * FROM test');
|
|
75
|
-
expect(mockFetch).toHaveBeenCalledWith('api/v1/
|
|
74
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/execute', {
|
|
76
75
|
method: 'POST',
|
|
77
76
|
body: JSON.stringify({ query: 'SELECT * FROM test', params: [], method: 'all' }),
|
|
78
77
|
redirect: 'follow',
|
|
@@ -87,7 +86,7 @@ describe('SqlClient', () => {
|
|
|
87
86
|
mockGetResponseBody.mockResolvedValue({ rows: [] });
|
|
88
87
|
const params = [1];
|
|
89
88
|
const result = await sqlClient.storageApi('SELECT * FROM test WHERE id = ?', params, 'one');
|
|
90
|
-
expect(mockFetch).toHaveBeenCalledWith('api/v1/
|
|
89
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/execute', {
|
|
91
90
|
method: 'POST',
|
|
92
91
|
body: JSON.stringify({ query: 'SELECT * FROM test WHERE id = ?', params, method: 'one' }),
|
|
93
92
|
redirect: 'follow',
|
|
@@ -102,7 +101,7 @@ describe('SqlClient', () => {
|
|
|
102
101
|
const mockError = new Error('Invalid JSON');
|
|
103
102
|
mockGetResponseBody.mockRejectedValue(mockError);
|
|
104
103
|
await expect(sqlClient.storageApi('INVALID SQL QUERY')).rejects.toThrow(mockError);
|
|
105
|
-
expect(mockFetch).toHaveBeenCalledWith('api/v1/
|
|
104
|
+
expect(mockFetch).toHaveBeenCalledWith('api/v1/execute', expect.any(Object));
|
|
106
105
|
expect(mockGetResponseBody).toHaveBeenCalledWith(mockResponse);
|
|
107
106
|
});
|
|
108
107
|
});
|
|
@@ -140,10 +139,9 @@ describe('SqlClient', () => {
|
|
|
140
139
|
expect(mockSqlStatement.execute).toHaveBeenCalled();
|
|
141
140
|
});
|
|
142
141
|
it('should handle API errors', async () => {
|
|
143
|
-
const
|
|
144
|
-
mockSqlStatement.execute.
|
|
145
|
-
|
|
146
|
-
expect(result).toEqual({ rows: [], err: mockApiError });
|
|
142
|
+
const mockApiError1 = new Error('INVALID SQL QUERY');
|
|
143
|
+
mockSqlStatement.execute.mockRejectedValueOnce(mockApiError1);
|
|
144
|
+
await expect(sqlClient.execute('INVALID SQL QUERY')).rejects.toThrow(mockApiError1);
|
|
147
145
|
expect(sql_statement_1.SqlStatement).toHaveBeenCalledWith('INVALID SQL QUERY', expect.any(Function));
|
|
148
146
|
expect(mockSqlStatement.execute).toHaveBeenCalled();
|
|
149
147
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorCodes.d.ts","sourceRoot":"","sources":["../src/errorCodes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;CAItB,CAAC"}
|
package/out/index.d.ts
CHANGED
package/out/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,eAAe,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,GAAG,CAAC"}
|
package/out/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorCodes = void 0;
|
|
3
4
|
const sql_1 = require("./sql");
|
|
5
|
+
const errorCodes_1 = require("./errorCodes");
|
|
6
|
+
Object.defineProperty(exports, "errorCodes", { enumerable: true, get: function () { return errorCodes_1.errorCodes; } });
|
|
4
7
|
exports.default = sql_1.sql;
|
package/out/sql.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class SqlClient {
|
|
|
5
5
|
storageApi(query: string, params?: SqlParameters, method?: string): Promise<Result>;
|
|
6
6
|
prepare(query: string): SqlStatement;
|
|
7
7
|
execute(query: string): Promise<Result>;
|
|
8
|
+
_provision(): Promise<void>;
|
|
8
9
|
}
|
|
9
10
|
export declare const sql: SqlClient;
|
|
10
11
|
//# sourceMappingURL=sql.d.ts.map
|
package/out/sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE9D,qBAAa,SAAS;YACN,WAAW;IAYnB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,EAAE,MAAM,SAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ5F,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY;IAI9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CASlC;AAED,eAAO,MAAM,GAAG,WAAkB,CAAC"}
|
package/out/sql.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sql = exports.SqlClient = void 0;
|
|
4
|
-
const
|
|
5
|
-
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
4
|
+
const api_1 = require("@forge/api");
|
|
6
5
|
const response_handler_1 = require("./utils/response-handler");
|
|
7
6
|
const sql_statement_1 = require("./sql-statement");
|
|
8
|
-
const fetch_1 = require("@forge/api/out/api/fetch");
|
|
9
7
|
class SqlClient {
|
|
10
8
|
async sendRequest(path, options) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
options.redirect = 'follow';
|
|
14
|
-
options.headers = {
|
|
15
|
-
...options.headers,
|
|
9
|
+
const response = await (0, api_1.__fetchProduct)({ provider: 'none', remote: 'sql' })(path, {
|
|
10
|
+
...options,
|
|
16
11
|
redirect: 'follow',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
headers: {
|
|
13
|
+
...options?.headers,
|
|
14
|
+
'Content-Type': 'application/json'
|
|
15
|
+
}
|
|
16
|
+
});
|
|
20
17
|
return response;
|
|
21
18
|
}
|
|
22
19
|
async storageApi(query, params = [], method = 'all') {
|
|
23
|
-
const response = await this.sendRequest('api/v1/
|
|
20
|
+
const response = await this.sendRequest('api/v1/execute', {
|
|
24
21
|
method: 'POST',
|
|
25
22
|
body: JSON.stringify({ query, params, method })
|
|
26
23
|
});
|
|
@@ -30,11 +27,16 @@ class SqlClient {
|
|
|
30
27
|
return new sql_statement_1.SqlStatement(query, this.storageApi.bind(this));
|
|
31
28
|
}
|
|
32
29
|
async execute(query) {
|
|
30
|
+
return await this.prepare(query).execute();
|
|
31
|
+
}
|
|
32
|
+
async _provision() {
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
await this.sendRequest('/api/v1/provision', {
|
|
35
|
+
method: 'POST'
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
catch (e) {
|
|
37
|
-
|
|
39
|
+
throw e;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -4,7 +4,7 @@ const response_handler_1 = require("../response-handler");
|
|
|
4
4
|
describe('getResponseBody', () => {
|
|
5
5
|
it('should return parsed response when response is ok', async () => {
|
|
6
6
|
const mockResponse = {
|
|
7
|
-
text: jest.fn().mockResolvedValue(JSON.stringify({
|
|
7
|
+
text: jest.fn().mockResolvedValue(JSON.stringify({ rows: [] })),
|
|
8
8
|
ok: true,
|
|
9
9
|
status: 200
|
|
10
10
|
};
|
|
@@ -15,7 +15,7 @@ describe('getResponseBody', () => {
|
|
|
15
15
|
const mockResponse = {
|
|
16
16
|
text: jest
|
|
17
17
|
.fn()
|
|
18
|
-
.mockResolvedValue(JSON.stringify({
|
|
18
|
+
.mockResolvedValue(JSON.stringify({ code: 'ERROR_CODE', message: 'Error Title', debug: { info: 'detail' } })),
|
|
19
19
|
ok: false,
|
|
20
20
|
status: 400
|
|
21
21
|
};
|
|
@@ -24,7 +24,7 @@ describe('getResponseBody', () => {
|
|
|
24
24
|
status: 400,
|
|
25
25
|
code: 'ERROR_CODE',
|
|
26
26
|
message: 'Error Title',
|
|
27
|
-
|
|
27
|
+
debug: { info: 'detail' }
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
it('should throw ApiError with UNKNOWN_ERROR when response is not ok and error JSON is invalid', async () => {
|
|
@@ -3,7 +3,8 @@ export declare class ApiError extends Error {
|
|
|
3
3
|
readonly status: number;
|
|
4
4
|
readonly code: string;
|
|
5
5
|
readonly suggestion?: string | undefined;
|
|
6
|
-
|
|
6
|
+
readonly debug?: any;
|
|
7
|
+
constructor(status: number, code: string, message: string, suggestion?: string | undefined, debug?: any);
|
|
7
8
|
}
|
|
8
9
|
export declare function getResponseBody(response: Response): Promise<Result>;
|
|
9
10
|
//# sourceMappingURL=response-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,qBAAa,QAAS,SAAQ,KAAK;IAE/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"response-handler.d.ts","sourceRoot":"","sources":["../../src/utils/response-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAE3C,qBAAa,QAAS,SAAQ,KAAK;IAE/B,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAErB,QAAQ,CAAC,UAAU,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC;gBAJN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,CAAC,oBAAQ,EACnB,KAAK,CAAC,KAAK;CAIvB;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BzE"}
|
|
@@ -5,11 +5,13 @@ class ApiError extends Error {
|
|
|
5
5
|
status;
|
|
6
6
|
code;
|
|
7
7
|
suggestion;
|
|
8
|
-
|
|
8
|
+
debug;
|
|
9
|
+
constructor(status, code, message, suggestion, debug) {
|
|
9
10
|
super(message);
|
|
10
11
|
this.status = status;
|
|
11
12
|
this.code = code;
|
|
12
13
|
this.suggestion = suggestion;
|
|
14
|
+
this.debug = debug;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
exports.ApiError = ApiError;
|
|
@@ -18,7 +20,7 @@ async function getResponseBody(response) {
|
|
|
18
20
|
if (!response.ok) {
|
|
19
21
|
try {
|
|
20
22
|
const parsedError = JSON.parse(responseText);
|
|
21
|
-
throw new ApiError(response.status, parsedError?.
|
|
23
|
+
throw new ApiError(response.status, parsedError?.code, parsedError?.message, parsedError?.suggestion, parsedError?.debug);
|
|
22
24
|
}
|
|
23
25
|
catch (e) {
|
|
24
26
|
if (!(e instanceof ApiError)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/sql",
|
|
3
|
-
"version": "0.0.1-experimental-
|
|
3
|
+
"version": "0.0.1-experimental-f20602a",
|
|
4
4
|
"description": "Forge SQL package",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
"node-fetch": "2.7.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@forge/api": "^3.9.
|
|
24
|
+
"@forge/api": "^3.9.2-next.0-experimental-f20602a"
|
|
25
25
|
}
|
|
26
26
|
}
|