@forge/sql 2.3.2 → 2.3.3-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.
package/out/__test__/sql.test.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_fetch_1 = require("node-fetch");
|
|
4
3
|
const api_1 = require("@forge/api");
|
|
5
4
|
const sql_1 = require("../sql");
|
|
6
5
|
const sql_statement_1 = require("../sql-statement");
|
|
@@ -17,7 +16,7 @@ describe('SqlClient', () => {
|
|
|
17
16
|
});
|
|
18
17
|
function mockFetchExecute(rows) {
|
|
19
18
|
const body = { rows };
|
|
20
|
-
const response = new
|
|
19
|
+
const response = new Response(JSON.stringify(body), { status: 200 });
|
|
21
20
|
mockFetch.mockResolvedValue(response);
|
|
22
21
|
return body;
|
|
23
22
|
}
|
|
@@ -58,13 +57,13 @@ describe('SqlClient', () => {
|
|
|
58
57
|
});
|
|
59
58
|
it('should handle invalid JSON body', async () => {
|
|
60
59
|
const responseText = 'Invalid JSON';
|
|
61
|
-
const response = new
|
|
60
|
+
const response = new Response(responseText, { status: 200 });
|
|
62
61
|
mockFetch.mockResolvedValue(response);
|
|
63
62
|
await expect(sqlClient['storageApi']('SELECT * from strange;', [], 'one', sql_1.SQL_API_ENDPOINTS.EXECUTE)).rejects.toThrow(`Unexpected error. Response was not valid JSON: ${responseText}`);
|
|
64
63
|
});
|
|
65
64
|
it('should throw ForgeSQLAPIError on API error', async () => {
|
|
66
65
|
const forgeError = { code: 'INVALID_QUERY', message: 'Invalid SQL query' };
|
|
67
|
-
const mockResponse = new
|
|
66
|
+
const mockResponse = new Response(JSON.stringify(forgeError), {
|
|
68
67
|
status: 400
|
|
69
68
|
});
|
|
70
69
|
mockFetch.mockResolvedValue(mockResponse);
|
|
@@ -132,7 +131,7 @@ describe('SqlClient', () => {
|
|
|
132
131
|
});
|
|
133
132
|
it('should handle API errors', async () => {
|
|
134
133
|
const forgeError = { code: 'INVALID_QUERY', message: 'Invalid SQL query' };
|
|
135
|
-
const mockResponse = new
|
|
134
|
+
const mockResponse = new Response(JSON.stringify(forgeError), {
|
|
136
135
|
status: 400
|
|
137
136
|
});
|
|
138
137
|
mockFetch.mockResolvedValue(mockResponse);
|
|
@@ -141,7 +140,7 @@ describe('SqlClient', () => {
|
|
|
141
140
|
});
|
|
142
141
|
describe('_provision', () => {
|
|
143
142
|
it('should work if the response is a 201', async () => {
|
|
144
|
-
const mockResponse = new
|
|
143
|
+
const mockResponse = new Response(JSON.stringify({ success: true }), {
|
|
145
144
|
status: 201,
|
|
146
145
|
statusText: 'OK'
|
|
147
146
|
});
|
|
@@ -150,7 +149,7 @@ describe('SqlClient', () => {
|
|
|
150
149
|
expect(mockFetch).toHaveBeenCalledWith('/api/v1/provision', expect.objectContaining({ method: 'POST' }));
|
|
151
150
|
});
|
|
152
151
|
it('should work if the response is a 204', async () => {
|
|
153
|
-
const mockResponse = new
|
|
152
|
+
const mockResponse = new Response(undefined, {
|
|
154
153
|
status: 204,
|
|
155
154
|
statusText: 'OK'
|
|
156
155
|
});
|
|
@@ -159,7 +158,7 @@ describe('SqlClient', () => {
|
|
|
159
158
|
expect(mockFetch).toHaveBeenCalledWith('/api/v1/provision', expect.objectContaining({ method: 'POST' }));
|
|
160
159
|
});
|
|
161
160
|
it('should throw an error if the response is not 201 or 204', async () => {
|
|
162
|
-
const mockResponse = new
|
|
161
|
+
const mockResponse = new Response('Server Error', {
|
|
163
162
|
status: 500,
|
|
164
163
|
statusText: 'Bad Request'
|
|
165
164
|
});
|
|
@@ -181,7 +180,7 @@ describe('SqlClient', () => {
|
|
|
181
180
|
});
|
|
182
181
|
it('should throw ForgeSQLError when response is not valid JSON', async () => {
|
|
183
182
|
const forgeError = { code: 'INVALID_QUERY', message: 'Invalid SQL query' };
|
|
184
|
-
const mockResponse = new
|
|
183
|
+
const mockResponse = new Response(JSON.stringify(forgeError), {
|
|
185
184
|
status: 400
|
|
186
185
|
});
|
|
187
186
|
mockFetch.mockResolvedValue(mockResponse);
|
package/out/sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAgC,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7E,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,aAAK,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAElF,qBAAa,SAAS;YACN,WAAW;YAYX,UAAU;YAsBV,qBAAqB;IAYnC,OAAO,CAAC,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,eAA2C,GACpD,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAU3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAK9D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;CAGrE;AAED,eAAO,MAAM,GAAG,WAAkB,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const node_fetch_1 = require("node-fetch");
|
|
4
3
|
const errorCodes_1 = require("../../errorCodes");
|
|
5
4
|
const errors_1 = require("../../errors");
|
|
6
5
|
const error_handling_1 = require("../error-handling");
|
|
7
6
|
describe('errorFromResponse', () => {
|
|
8
7
|
const traceId = 'trace-id';
|
|
9
8
|
it('should do nothing if response is ok', async () => {
|
|
10
|
-
const mockResponse = new
|
|
9
|
+
const mockResponse = new Response('OK', {
|
|
11
10
|
status: 200,
|
|
12
11
|
statusText: 'OK'
|
|
13
12
|
});
|
|
@@ -18,7 +17,7 @@ describe('errorFromResponse', () => {
|
|
|
18
17
|
const code = 'ERROR_CODE';
|
|
19
18
|
const suggestion = 'Do something different';
|
|
20
19
|
it('should return a ForgeSQLAPIError when response body is a Forge error', async () => {
|
|
21
|
-
const mockResponse = new
|
|
20
|
+
const mockResponse = new Response(JSON.stringify({ code, message }), {
|
|
22
21
|
status: 400,
|
|
23
22
|
statusText: 'Bad Request',
|
|
24
23
|
headers: { 'x-trace-id': traceId }
|
|
@@ -42,7 +41,7 @@ describe('errorFromResponse', () => {
|
|
|
42
41
|
});
|
|
43
42
|
it('should include context if present in the Forge error', async () => {
|
|
44
43
|
const context = { key: 'value' };
|
|
45
|
-
const mockResponse = new
|
|
44
|
+
const mockResponse = new Response(JSON.stringify({ code, message, context }), {
|
|
46
45
|
status: 400,
|
|
47
46
|
statusText: 'Bad Request',
|
|
48
47
|
headers: { 'x-trace-id': traceId }
|
|
@@ -67,7 +66,7 @@ describe('errorFromResponse', () => {
|
|
|
67
66
|
});
|
|
68
67
|
it('should include top level additional fields if present in the Forge error', async () => {
|
|
69
68
|
const extraFields = { extraValue: 'value', debug: true };
|
|
70
|
-
const mockResponse = new
|
|
69
|
+
const mockResponse = new Response(JSON.stringify({ code, message, ...extraFields }), {
|
|
71
70
|
status: 400,
|
|
72
71
|
statusText: 'Bad Request',
|
|
73
72
|
headers: { 'x-trace-id': traceId }
|
|
@@ -93,7 +92,7 @@ describe('errorFromResponse', () => {
|
|
|
93
92
|
it('should merge context and additional top level fields if both present in the Forge error', async () => {
|
|
94
93
|
const context = { key: 'value' };
|
|
95
94
|
const extraFields = { extraValue: 'value', debug: true };
|
|
96
|
-
const mockResponse = new
|
|
95
|
+
const mockResponse = new Response(JSON.stringify({ code, message, context, ...extraFields }), {
|
|
97
96
|
status: 400,
|
|
98
97
|
statusText: 'Bad Request',
|
|
99
98
|
headers: { 'x-trace-id': traceId }
|
|
@@ -117,7 +116,7 @@ describe('errorFromResponse', () => {
|
|
|
117
116
|
}
|
|
118
117
|
});
|
|
119
118
|
it('should include suggestion if present in the Forge error', async () => {
|
|
120
|
-
const mockResponse = new
|
|
119
|
+
const mockResponse = new Response(JSON.stringify({ code, message, suggestion }), {
|
|
121
120
|
status: 400,
|
|
122
121
|
statusText: 'Bad Request',
|
|
123
122
|
headers: { 'x-trace-id': traceId }
|
|
@@ -143,7 +142,7 @@ describe('errorFromResponse', () => {
|
|
|
143
142
|
});
|
|
144
143
|
describe('Handle non forge errors - UNKNOWN_ERROR', () => {
|
|
145
144
|
it('returns an when no response body', async () => {
|
|
146
|
-
const mockResponse = new
|
|
145
|
+
const mockResponse = new Response(undefined, {
|
|
147
146
|
status: 404,
|
|
148
147
|
statusText: 'Not Found',
|
|
149
148
|
headers: { 'x-trace-id': traceId }
|
|
@@ -169,7 +168,7 @@ describe('errorFromResponse', () => {
|
|
|
169
168
|
});
|
|
170
169
|
it("returns UNKNOWN_ERROR if there is a JSON body that isn't a forge error", async () => {
|
|
171
170
|
const body = JSON.stringify({ not: 'a forge error' });
|
|
172
|
-
const mockResponse = new
|
|
171
|
+
const mockResponse = new Response(body, {
|
|
173
172
|
status: 500,
|
|
174
173
|
statusText: 'Internal Server Error',
|
|
175
174
|
headers: { 'x-trace-id': traceId }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/sql",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3-next.0",
|
|
4
4
|
"description": "Forge SQL sdk",
|
|
5
5
|
"author": "Atlassian",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -16,12 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "14.18.63",
|
|
19
|
-
"@types/node-fetch": "^2.6.11",
|
|
20
19
|
"expect-type": "^0.17.3",
|
|
21
|
-
"node-fetch": "2.7.0",
|
|
22
20
|
"jest-when": "^3.6.0"
|
|
23
21
|
},
|
|
24
22
|
"dependencies": {
|
|
25
|
-
"@forge/api": "^
|
|
23
|
+
"@forge/api": "^5.0.0-next.0"
|
|
26
24
|
}
|
|
27
25
|
}
|