@forge/sql 0.0.1-experimental-8f73b3e → 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.
@@ -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/sql/execute';
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/sql/execute';
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/sql/execute';
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/sql/execute', {
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/sql/execute', {
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/sql/execute', expect.any(Object));
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 mockApiError = new response_handler_1.ApiError(400, 'BAD_REQUEST', 'Invalid query');
144
- mockSqlStatement.execute.mockRejectedValue(mockApiError);
145
- const result = await sqlClient.execute('INVALID SQL QUERY');
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,6 @@
1
+ export declare const errorCodes: {
2
+ SQL_EXECUTION_ERROR: string;
3
+ INVALID_SQL_QUERY: string;
4
+ QUERY_TIMED_OUT: string;
5
+ };
6
+ //# sourceMappingURL=errorCodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorCodes.d.ts","sourceRoot":"","sources":["../src/errorCodes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;CAItB,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorCodes = void 0;
4
+ exports.errorCodes = {
5
+ SQL_EXECUTION_ERROR: 'SQL_EXECUTION_ERROR',
6
+ INVALID_SQL_QUERY: 'INVALID_SQL_QUERY',
7
+ QUERY_TIMED_OUT: 'QUERY_TIMED_OUT'
8
+ };
package/out/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { sql } from './sql';
2
+ import { errorCodes } from './errorCodes';
3
+ export { errorCodes };
2
4
  export default sql;
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -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.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;AAG9D,qBAAa,SAAS;YACN,WAAW;IAcnB,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;IAQvC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CASlC;AAED,eAAO,MAAM,GAAG,WAAkB,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,22 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sql = exports.SqlClient = void 0;
4
- const tslib_1 = require("tslib");
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 url = `https://sql/${path}`;
12
- options = (0, fetch_1.addMagicAgent)(options);
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
- 'Content-Type': 'application/json'
18
- };
19
- const response = await (0, node_fetch_1.default)(url, options);
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') {
@@ -30,12 +27,7 @@ class SqlClient {
30
27
  return new sql_statement_1.SqlStatement(query, this.storageApi.bind(this));
31
28
  }
32
29
  async execute(query) {
33
- try {
34
- return await this.prepare(query).execute();
35
- }
36
- catch (e) {
37
- return { rows: [], err: e };
38
- }
30
+ return await this.prepare(query).execute();
39
31
  }
40
32
  async _provision() {
41
33
  try {
@@ -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({ response: { rows: [] } })),
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({ error: { code: 'ERROR_CODE', title: 'Error Title', data: { info: 'detail' } } })),
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
- data: { info: 'detail' }
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
- constructor(status: number, code: string, message: string, suggestion?: string | undefined);
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;gBAHX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACN,UAAU,CAAC,oBAAQ;CAI/B;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CA0BzE"}
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
- constructor(status, code, message, suggestion) {
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?.error?.code, parsedError?.error?.message, parsedError?.error?.suggestion);
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-8f73b3e",
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.1-experimental-8f73b3e"
24
+ "@forge/api": "^3.9.2-next.0-experimental-f20602a"
25
25
  }
26
26
  }