@malloydata/db-publisher 0.0.314 → 0.0.316

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.
Files changed (32) hide show
  1. package/dist/client/api.d.ts +1594 -528
  2. package/dist/client/api.js +1820 -553
  3. package/dist/client/api.js.map +1 -1
  4. package/dist/client/base.d.ts +1 -1
  5. package/dist/client/base.js +1 -1
  6. package/dist/client/common.d.ts +1 -1
  7. package/dist/client/common.js +1 -1
  8. package/dist/client/configuration.d.ts +1 -1
  9. package/dist/client/configuration.js +1 -1
  10. package/dist/client/index.d.ts +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/publisher_connection.d.ts +4 -1
  13. package/dist/publisher_connection.integration.spec.js +208 -0
  14. package/dist/publisher_connection.integration.spec.js.map +1 -0
  15. package/dist/publisher_connection.js +42 -11
  16. package/dist/publisher_connection.js.map +1 -1
  17. package/dist/publisher_connection.unit.spec.d.ts +1 -0
  18. package/dist/{publisher_connection.spec.js → publisher_connection.unit.spec.js} +214 -175
  19. package/dist/publisher_connection.unit.spec.js.map +1 -0
  20. package/package.json +2 -2
  21. package/publisher-api-doc.yaml +1434 -449
  22. package/src/client/.openapi-generator/FILES +0 -1
  23. package/src/client/api.ts +2513 -754
  24. package/src/client/base.ts +1 -1
  25. package/src/client/common.ts +1 -1
  26. package/src/client/configuration.ts +1 -1
  27. package/src/client/index.ts +1 -1
  28. package/src/publisher_connection.integration.spec.ts +200 -0
  29. package/src/publisher_connection.ts +67 -19
  30. package/src/{publisher_connection.spec.ts → publisher_connection.unit.spec.ts} +260 -175
  31. package/dist/publisher_connection.spec.js.map +0 -1
  32. /package/dist/{publisher_connection.spec.d.ts → publisher_connection.integration.spec.d.ts} +0 -0
@@ -5,62 +5,34 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
8
  Object.defineProperty(exports, "__esModule", { value: true });
42
- const malloy = __importStar(require("@malloydata/malloy"));
43
9
  const test_1 = require("@malloydata/malloy/test");
44
10
  const publisher_connection_1 = require("./publisher_connection");
45
- const url_1 = require("url");
46
- const util = __importStar(require("util"));
47
- const fs = __importStar(require("fs"));
48
11
  const client_1 = require("./client");
49
- // mocks client code for testing
12
+ // mocks client code for testing - only for unit tests
50
13
  jest.mock('./client', () => {
51
14
  const mockConnectionsApi = {
52
15
  getConnection: jest.fn(),
53
- getTest: jest.fn(),
16
+ getTable: jest.fn(),
54
17
  getTablesource: jest.fn(),
55
18
  getSqlsource: jest.fn(),
56
19
  getQuerydata: jest.fn(),
57
20
  getTemporarytable: jest.fn(),
21
+ postSqlsource: jest.fn(),
22
+ postQuerydata: jest.fn(),
23
+ postTemporarytable: jest.fn(),
24
+ };
25
+ const mockConnectionsTestApi = {
26
+ testConnectionConfiguration: jest.fn(),
58
27
  };
59
28
  return {
60
29
  Configuration: jest.fn().mockImplementation(() => ({
61
30
  basePath: 'http://test.com/api/v0',
62
31
  })),
63
32
  ConnectionsApi: jest.fn().mockImplementation(() => mockConnectionsApi),
33
+ ConnectionsTestApi: jest
34
+ .fn()
35
+ .mockImplementation(() => mockConnectionsTestApi),
64
36
  };
65
37
  });
66
38
  const [describe] = (0, test_1.describeIfDatabaseAvailable)(['publisher']);
@@ -68,10 +40,12 @@ describe('db:Publisher', () => {
68
40
  describe('unit', () => {
69
41
  describe('create', () => {
70
42
  let mockConnectionsApi;
43
+ let mockConnectionsTestApi;
71
44
  let _mockConfiguration;
72
45
  beforeEach(() => {
73
46
  // Get fresh instances of the mocks
74
47
  mockConnectionsApi = new client_1.ConnectionsApi(new client_1.Configuration());
48
+ mockConnectionsTestApi = new client_1.ConnectionsTestApi(new client_1.Configuration());
75
49
  _mockConfiguration = new client_1.Configuration();
76
50
  });
77
51
  afterEach(() => {
@@ -86,7 +60,13 @@ describe('db:Publisher', () => {
86
60
  };
87
61
  const mockConnectionResponse = {
88
62
  data: {
63
+ name: 'test-connection',
64
+ type: 'bigquery',
89
65
  attributes: mockConnectionAttributes,
66
+ bigqueryConnection: {
67
+ defaultProjectId: 'test-project',
68
+ billingProjectId: 'test-project',
69
+ },
90
70
  },
91
71
  status: 200,
92
72
  statusText: 'OK',
@@ -94,14 +74,17 @@ describe('db:Publisher', () => {
94
74
  config: {},
95
75
  };
96
76
  const mockTestResponse = {
97
- data: undefined,
77
+ data: {
78
+ status: 'ok',
79
+ errorMessage: '',
80
+ },
98
81
  status: 200,
99
82
  statusText: 'OK',
100
83
  headers: {},
101
84
  config: {},
102
85
  };
103
86
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
104
- mockConnectionsApi.getTest.mockResolvedValueOnce(mockTestResponse);
87
+ mockConnectionsTestApi.testConnectionConfiguration.mockResolvedValueOnce(mockTestResponse);
105
88
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
106
89
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
107
90
  accessToken: 'test-token',
@@ -140,7 +123,13 @@ describe('db:Publisher', () => {
140
123
  };
141
124
  const mockConnectionResponse = {
142
125
  data: {
126
+ name: 'test-connection',
127
+ type: 'bigquery',
143
128
  attributes: mockConnectionAttributes,
129
+ bigqueryConnection: {
130
+ defaultProjectId: 'test-project',
131
+ billingProjectId: 'test-project',
132
+ },
144
133
  },
145
134
  status: 200,
146
135
  statusText: 'OK',
@@ -148,14 +137,17 @@ describe('db:Publisher', () => {
148
137
  config: {},
149
138
  };
150
139
  const mockTestResponse = {
151
- data: undefined,
140
+ data: {
141
+ status: 'ok',
142
+ errorMessage: '',
143
+ },
152
144
  status: 200,
153
145
  statusText: 'OK',
154
146
  headers: {},
155
147
  config: {},
156
148
  };
157
149
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
158
- mockConnectionsApi.getTest.mockResolvedValueOnce(mockTestResponse);
150
+ mockConnectionsTestApi.testConnectionConfiguration.mockResolvedValueOnce(mockTestResponse);
159
151
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
160
152
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
161
153
  });
@@ -177,17 +169,6 @@ describe('db:Publisher', () => {
177
169
  jest.clearAllMocks();
178
170
  });
179
171
  it('should fetch table schema successfully', async () => {
180
- const mockTableSchema = {
181
- type: 'table',
182
- name: 'test_table',
183
- tablePath: 'test_path',
184
- connection: 'test-connection',
185
- dialect: 'bigquery',
186
- fields: [
187
- { name: 'id', type: 'number' },
188
- { name: 'name', type: 'string' },
189
- ],
190
- };
191
172
  const mockConnectionResponse = {
192
173
  data: {
193
174
  attributes: {
@@ -204,7 +185,11 @@ describe('db:Publisher', () => {
204
185
  };
205
186
  const mockTableResponse = {
206
187
  data: {
207
- source: JSON.stringify(mockTableSchema),
188
+ resource: 'test_path',
189
+ columns: [
190
+ { name: 'id', type: 'number' },
191
+ { name: 'name', type: 'string' },
192
+ ],
208
193
  },
209
194
  status: 200,
210
195
  statusText: 'OK',
@@ -212,24 +197,69 @@ describe('db:Publisher', () => {
212
197
  config: {},
213
198
  };
214
199
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
215
- mockConnectionsApi.getTablesource.mockResolvedValueOnce(mockTableResponse);
200
+ mockConnectionsApi.getTable.mockResolvedValueOnce(mockTableResponse);
216
201
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
217
202
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
218
203
  accessToken: 'test-token',
219
204
  });
220
205
  const schema = await connection.fetchTableSchema('test_key', 'test_path');
221
- expect(schema).toEqual(mockTableSchema);
222
- expect(mockConnectionsApi.getTablesource).toHaveBeenCalledWith('test-project', 'test-connection', 'test_key', 'test_path', {
206
+ expect(schema).toEqual({
207
+ type: 'table',
208
+ name: 'test_key',
209
+ tablePath: 'test_path',
210
+ connection: 'test-connection',
211
+ dialect: 'bigquery',
212
+ fields: [
213
+ { name: 'id', type: 'number' },
214
+ { name: 'name', type: 'string' },
215
+ ],
216
+ });
217
+ expect(mockConnectionsApi.getTable).toHaveBeenCalledWith('test-project', 'test-connection', 'test_path', 'test_path', {
223
218
  headers: {
224
219
  Authorization: 'Bearer test-token',
225
220
  },
226
221
  });
227
222
  });
228
223
  it('should handle API errors', async () => {
229
- await setupAndTestApiError(mockConnectionsApi, 'getTablesource', connection => connection.fetchTableSchema('test_key', 'test_path'));
224
+ await setupAndTestApiError(mockConnectionsApi, 'getTable', connection => connection.fetchTableSchema('test_key', 'test_path'));
230
225
  });
231
226
  it('should handle invalid JSON response', async () => {
232
- await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'getTablesource', connection => connection.fetchTableSchema('test_key', 'test_path'));
227
+ const mockConnectionResponse = {
228
+ data: {
229
+ attributes: {
230
+ dialectName: 'bigquery',
231
+ isPool: false,
232
+ canPersist: true,
233
+ canStream: true,
234
+ },
235
+ },
236
+ status: 200,
237
+ statusText: 'OK',
238
+ headers: {},
239
+ config: {},
240
+ };
241
+ const mockInvalidResponse = {
242
+ data: { resource: 'invalid json', columns: null },
243
+ status: 200,
244
+ statusText: 'OK',
245
+ headers: {},
246
+ config: {},
247
+ };
248
+ mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
249
+ mockConnectionsApi.getTable.mockResolvedValueOnce(mockInvalidResponse);
250
+ const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
251
+ connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
252
+ accessToken: 'test-token',
253
+ });
254
+ const schema = await connection.fetchTableSchema('test_key', 'test_path');
255
+ expect(schema).toEqual({
256
+ type: 'table',
257
+ name: 'test_key',
258
+ tablePath: 'test_path',
259
+ connection: 'test-connection',
260
+ dialect: 'bigquery',
261
+ fields: [],
262
+ });
233
263
  });
234
264
  });
235
265
  describe('fetchSelectSchema', () => {
@@ -279,7 +309,7 @@ describe('db:Publisher', () => {
279
309
  config: {},
280
310
  };
281
311
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
282
- mockConnectionsApi.getSqlsource.mockResolvedValueOnce(mockSqlResponse);
312
+ mockConnectionsApi.postSqlsource.mockResolvedValueOnce(mockSqlResponse);
283
313
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
284
314
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
285
315
  accessToken: 'test-token',
@@ -289,20 +319,22 @@ describe('db:Publisher', () => {
289
319
  connection: 'test-connection',
290
320
  });
291
321
  expect(schema).toEqual(mockSqlSchema);
292
- expect(mockConnectionsApi.getSqlsource).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', {
322
+ expect(mockConnectionsApi.postSqlsource).toHaveBeenCalledWith('test-project', 'test-connection', {
323
+ sqlStatement: 'SELECT * FROM test_table',
324
+ }, {
293
325
  headers: {
294
326
  Authorization: 'Bearer test-token',
295
327
  },
296
328
  });
297
329
  });
298
330
  it('should handle API errors', async () => {
299
- await setupAndTestApiError(mockConnectionsApi, 'getSqlsource', connection => connection.fetchSelectSchema({
331
+ await setupAndTestApiError(mockConnectionsApi, 'postSqlsource', connection => connection.fetchSelectSchema({
300
332
  selectStr: 'SELECT * FROM test_table',
301
333
  connection: 'test-connection',
302
334
  }));
303
335
  });
304
336
  it('should handle invalid JSON response', async () => {
305
- await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'getSqlsource', connection => connection.fetchSelectSchema({
337
+ await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'postSqlsource', connection => connection.fetchSelectSchema({
306
338
  selectStr: 'SELECT * FROM test_table',
307
339
  connection: 'test-connection',
308
340
  }));
@@ -351,14 +383,14 @@ describe('db:Publisher', () => {
351
383
  config: {},
352
384
  };
353
385
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
354
- mockConnectionsApi.getQuerydata.mockResolvedValueOnce(mockQueryResponse);
386
+ mockConnectionsApi.postQuerydata.mockResolvedValueOnce(mockQueryResponse);
355
387
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
356
388
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
357
389
  accessToken: 'test-token',
358
390
  });
359
391
  const result = await connection.runSQL('SELECT * FROM test_table');
360
392
  expect(result).toEqual(mockQueryData);
361
- expect(mockConnectionsApi.getQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', '{}', {
393
+ expect(mockConnectionsApi.postQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', { sqlStatement: 'SELECT * FROM test_table' }, JSON.stringify({}), {
362
394
  headers: {
363
395
  Authorization: 'Bearer test-token',
364
396
  },
@@ -396,7 +428,7 @@ describe('db:Publisher', () => {
396
428
  config: {},
397
429
  };
398
430
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
399
- mockConnectionsApi.getQuerydata.mockResolvedValueOnce(mockQueryResponse);
431
+ mockConnectionsApi.postQuerydata.mockResolvedValueOnce(mockQueryResponse);
400
432
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
401
433
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
402
434
  accessToken: 'test-token',
@@ -407,17 +439,17 @@ describe('db:Publisher', () => {
407
439
  };
408
440
  const result = await connection.runSQL('SELECT * FROM test_table', options);
409
441
  expect(result).toEqual(mockQueryData);
410
- expect(mockConnectionsApi.getQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', JSON.stringify(options), {
442
+ expect(mockConnectionsApi.postQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', { sqlStatement: 'SELECT * FROM test_table' }, JSON.stringify(options), {
411
443
  headers: {
412
444
  Authorization: 'Bearer test-token',
413
445
  },
414
446
  });
415
447
  });
416
448
  it('should handle API errors', async () => {
417
- await setupAndTestApiError(mockConnectionsApi, 'getQuerydata', connection => connection.runSQL('SELECT * FROM test_table'));
449
+ await setupAndTestApiError(mockConnectionsApi, 'postQuerydata', connection => connection.runSQL('SELECT * FROM test_table'));
418
450
  });
419
451
  it('should handle invalid JSON response', async () => {
420
- await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'getQuerydata', connection => connection.runSQL('SELECT * FROM test_table'), { data: 'invalid json' });
452
+ await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'postQuerydata', connection => connection.runSQL('SELECT * FROM test_table'), { data: 'invalid json' });
421
453
  });
422
454
  });
423
455
  describe('runSQLStream', () => {
@@ -463,7 +495,7 @@ describe('db:Publisher', () => {
463
495
  config: {},
464
496
  };
465
497
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
466
- mockConnectionsApi.getQuerydata.mockResolvedValueOnce(mockQueryResponse);
498
+ mockConnectionsApi.postQuerydata.mockResolvedValueOnce(mockQueryResponse);
467
499
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
468
500
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
469
501
  accessToken: 'test-token',
@@ -474,7 +506,7 @@ describe('db:Publisher', () => {
474
506
  results.push(row);
475
507
  }
476
508
  expect(results).toEqual(mockQueryData.rows);
477
- expect(mockConnectionsApi.getQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', '{}', {
509
+ expect(mockConnectionsApi.postQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', { sqlStatement: 'SELECT * FROM test_table' }, '{}', {
478
510
  headers: {
479
511
  Authorization: 'Bearer test-token',
480
512
  },
@@ -512,7 +544,7 @@ describe('db:Publisher', () => {
512
544
  config: {},
513
545
  };
514
546
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
515
- mockConnectionsApi.getQuerydata.mockResolvedValueOnce(mockQueryResponse);
547
+ mockConnectionsApi.postQuerydata.mockResolvedValueOnce(mockQueryResponse);
516
548
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
517
549
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
518
550
  accessToken: 'test-token',
@@ -527,14 +559,14 @@ describe('db:Publisher', () => {
527
559
  results.push(row);
528
560
  }
529
561
  expect(results).toEqual(mockQueryData.rows);
530
- expect(mockConnectionsApi.getQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', JSON.stringify(options), {
562
+ expect(mockConnectionsApi.postQuerydata).toHaveBeenCalledWith('test-project', 'test-connection', { sqlStatement: 'SELECT * FROM test_table' }, JSON.stringify(options), {
531
563
  headers: {
532
564
  Authorization: 'Bearer test-token',
533
565
  },
534
566
  });
535
567
  });
536
568
  it('should handle API errors', async () => {
537
- await setupAndTestApiError(mockConnectionsApi, 'getQuerydata', async (connection) => {
569
+ await setupAndTestApiError(mockConnectionsApi, 'postQuerydata', async (connection) => {
538
570
  const stream = connection.runSQLStream('SELECT * FROM test_table');
539
571
  const results = [];
540
572
  for await (const row of stream) {
@@ -543,7 +575,7 @@ describe('db:Publisher', () => {
543
575
  });
544
576
  });
545
577
  it('should handle invalid JSON response', async () => {
546
- await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'getQuerydata', async (connection) => {
578
+ await setupAndTestInvalidJsonResponse(mockConnectionsApi, 'postQuerydata', async (connection) => {
547
579
  const stream = connection.runSQLStream('SELECT * FROM test_table');
548
580
  const results = [];
549
581
  for await (const row of stream) {
@@ -588,29 +620,31 @@ describe('db:Publisher', () => {
588
620
  config: {},
589
621
  };
590
622
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
591
- mockConnectionsApi.getTemporarytable.mockResolvedValueOnce(mockTableResponse);
623
+ mockConnectionsApi.postTemporarytable.mockResolvedValueOnce(mockTableResponse);
592
624
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
593
625
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
594
626
  accessToken: 'test-token',
595
627
  });
596
628
  const tableName = await connection.manifestTemporaryTable('SELECT * FROM test_table');
597
629
  expect(tableName).toBe('temp_table_123');
598
- expect(mockConnectionsApi.getTemporarytable).toHaveBeenCalledWith('test-project', 'test-connection', 'SELECT * FROM test_table', {
630
+ expect(mockConnectionsApi.postTemporarytable).toHaveBeenCalledWith('test-project', 'test-connection', { sqlStatement: 'SELECT * FROM test_table' }, {
599
631
  headers: {
600
632
  Authorization: 'Bearer test-token',
601
633
  },
602
634
  });
603
635
  });
604
636
  it('should handle API errors', async () => {
605
- await setupAndTestApiError(mockConnectionsApi, 'getTemporarytable', connection => connection.manifestTemporaryTable('SELECT * FROM test_table'));
637
+ await setupAndTestApiError(mockConnectionsApi, 'postTemporarytable', connection => connection.manifestTemporaryTable('SELECT * FROM test_table'));
606
638
  });
607
639
  });
608
640
  describe('test', () => {
609
641
  let mockConnectionsApi;
642
+ let mockConnectionsTestApi;
610
643
  let _mockConfiguration;
611
644
  beforeEach(() => {
612
645
  // Get fresh instances of the mocks
613
646
  mockConnectionsApi = new client_1.ConnectionsApi(new client_1.Configuration());
647
+ mockConnectionsTestApi = new client_1.ConnectionsTestApi(new client_1.Configuration());
614
648
  _mockConfiguration = new client_1.Configuration();
615
649
  });
616
650
  afterEach(() => {
@@ -619,12 +653,18 @@ describe('db:Publisher', () => {
619
653
  it('should test connection successfully', async () => {
620
654
  const mockConnectionResponse = {
621
655
  data: {
656
+ name: 'test-connection',
657
+ type: 'bigquery',
622
658
  attributes: {
623
659
  dialectName: 'bigquery',
624
660
  isPool: false,
625
661
  canPersist: true,
626
662
  canStream: true,
627
663
  },
664
+ bigqueryConnection: {
665
+ defaultProjectId: 'test-project',
666
+ billingProjectId: 'test-project',
667
+ },
628
668
  },
629
669
  status: 200,
630
670
  statusText: 'OK',
@@ -632,120 +672,119 @@ describe('db:Publisher', () => {
632
672
  config: {},
633
673
  };
634
674
  const mockTestResponse = {
635
- data: undefined,
675
+ data: {
676
+ status: 'ok',
677
+ errorMessage: '',
678
+ },
636
679
  status: 200,
637
680
  statusText: 'OK',
638
681
  headers: {},
639
682
  config: {},
640
683
  };
641
684
  mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
642
- mockConnectionsApi.getTest.mockResolvedValueOnce(mockTestResponse);
685
+ mockConnectionsTestApi.testConnectionConfiguration.mockResolvedValueOnce(mockTestResponse);
643
686
  const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
644
687
  connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
645
688
  accessToken: 'test-token',
646
689
  });
647
690
  await expect(connection.test()).resolves.not.toThrow();
648
- expect(mockConnectionsApi.getTest).toHaveBeenCalledWith('test-project', 'test-connection', {
691
+ expect(mockConnectionsTestApi.testConnectionConfiguration).toHaveBeenCalledWith({
692
+ name: 'test-connection',
693
+ type: 'bigquery',
694
+ attributes: {
695
+ dialectName: 'bigquery',
696
+ isPool: false,
697
+ canPersist: true,
698
+ canStream: true,
699
+ },
700
+ bigqueryConnection: {
701
+ defaultProjectId: 'test-project',
702
+ billingProjectId: 'test-project',
703
+ },
704
+ }, {
649
705
  headers: {
650
706
  Authorization: 'Bearer test-token',
651
707
  },
652
708
  });
653
709
  });
654
710
  });
655
- });
656
- describe.skip('integration', () => {
657
- let conn;
658
- let runtime;
659
- beforeEach(async () => {
660
- conn = await publisher_connection_1.PublisherConnection.create('bigquery',
661
- //{
662
- //connectionUri: 'http://localhost:4000/api/v0/projects/malloy-samples/connections/bigquery',
663
- //}
664
- {
665
- connectionUri: 'http://demo.data.pathways.localhost:8000/api/v0/projects/malloy-samples/connections/bigquery',
666
- accessToken: 'xyz',
667
- });
668
- const files = {
669
- readURL: async (url) => {
670
- const filePath = (0, url_1.fileURLToPath)(url);
671
- return await util.promisify(fs.readFile)(filePath, 'utf8');
672
- },
673
- };
674
- runtime = new malloy.Runtime({
675
- urlReader: files,
676
- connection: conn,
711
+ describe('estimateQueryCost', () => {
712
+ let mockConnectionsApi;
713
+ let _mockConfiguration;
714
+ beforeEach(() => {
715
+ // Get fresh instances of the mocks
716
+ mockConnectionsApi = new client_1.ConnectionsApi(new client_1.Configuration());
717
+ _mockConfiguration = new client_1.Configuration();
718
+ });
719
+ it('should return empty object for query cost estimation', async () => {
720
+ const mockConnectionAttributes = {
721
+ dialectName: 'bigquery',
722
+ isPool: false,
723
+ canPersist: true,
724
+ canStream: true,
725
+ };
726
+ const mockConnectionResponse = {
727
+ data: {
728
+ name: 'test-connection',
729
+ type: 'bigquery',
730
+ attributes: mockConnectionAttributes,
731
+ bigqueryConnection: {
732
+ defaultProjectId: 'test-project',
733
+ billingProjectId: 'test-project',
734
+ },
735
+ },
736
+ status: 200,
737
+ statusText: 'OK',
738
+ headers: {},
739
+ config: {},
740
+ };
741
+ mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
742
+ const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
743
+ connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
744
+ accessToken: 'test-token',
745
+ });
746
+ const cost = await connection.estimateQueryCost('SELECT * FROM test_table');
747
+ expect(cost).toEqual({});
677
748
  });
678
749
  });
679
- afterEach(async () => {
680
- await conn.close();
681
- });
682
- it('tests the connection', async () => {
683
- await conn.test();
684
- });
685
- it('correctly identifies the dialect', () => {
686
- expect(conn.dialectName).toBe('standardsql');
687
- });
688
- it('correctly identifies the connection as a pooled connection', () => {
689
- expect(conn.isPool()).toBe(false);
690
- });
691
- it('correctly identifies the connection as a streaming connection', () => {
692
- expect(conn.canStream()).toBe(true);
693
- });
694
- it('correctly identifies the connection as a persistSQLResults connection', () => {
695
- expect(conn.canPersist()).toBe(true);
696
- });
697
- it('fetches the table schema', async () => {
698
- const schema = await conn.fetchTableSchema('bigquery', 'bigquery-public-data.hacker_news.full');
699
- expect(schema.type).toBe('table');
700
- expect(schema.dialect).toBe('standardsql');
701
- expect(schema.tablePath).toBe('bigquery-public-data.hacker_news.full');
702
- expect(schema.fields.length).toBe(14);
703
- expect(schema.fields[0].name).toBe('title');
704
- expect(schema.fields[0].type).toBe('string');
705
- });
706
- it('fetches the sql source schema', async () => {
707
- const schema = await conn.fetchSelectSchema({
708
- connection: 'bigquery',
709
- selectStr: 'SELECT * FROM bigquery-public-data.hacker_news.full',
710
- });
711
- expect(schema.type).toBe('sql_select');
712
- expect(schema.dialect).toBe('standardsql');
713
- expect(schema.fields.length).toBe(14);
714
- expect(schema.fields[0].name).toBe('title');
715
- expect(schema.fields[0].type).toBe('string');
716
- });
717
- it('runs a SQL query', async () => {
718
- const res = await conn.runSQL('SELECT 1 as T');
719
- expect(res.rows[0]['T']).toBe(1);
720
- });
721
- it('runs a Malloy query', async () => {
722
- var _a;
723
- const sql = await runtime
724
- .loadModel("source: stories is bigquery.table('bigquery-public-data.hacker_news.full')")
725
- .loadQuery('run: stories -> { aggregate: cnt is count() group_by: `by` order_by: cnt desc limit: 10 }')
726
- .getSQL();
727
- const res = await conn.runSQL(sql);
728
- expect(res.totalRows).toBe(10);
729
- let total = 0;
730
- for (const row of res.rows) {
731
- total += +((_a = row['cnt']) !== null && _a !== void 0 ? _a : 0);
732
- }
733
- expect(total).toBe(1836679);
734
- });
735
- it('runs a Malloy query on an sql source', async () => {
736
- const sql = await runtime
737
- .loadModel("source: stories is bigquery.sql('SELECT * FROM bigquery-public-data.hacker_news.full')")
738
- .loadQuery('run: stories -> { aggregate: cnt is count() group_by: `by` order_by: cnt desc limit: 20 }')
739
- .getSQL();
740
- const res = await conn.runSQL(sql);
741
- expect(res.totalRows).toBe(20);
742
- expect(res.rows[0]['cnt']).toBe(1346912);
743
- });
744
- it('get temporary table name', async () => {
745
- const sql = 'SELECT 1 as T';
746
- const tempTableName = await conn.manifestTemporaryTable(sql);
747
- expect(tempTableName).toBeDefined();
748
- expect(tempTableName.startsWith('lofty-complex-452701')).toBe(true);
750
+ describe('close', () => {
751
+ let mockConnectionsApi;
752
+ let _mockConfiguration;
753
+ beforeEach(() => {
754
+ // Get fresh instances of the mocks
755
+ mockConnectionsApi = new client_1.ConnectionsApi(new client_1.Configuration());
756
+ _mockConfiguration = new client_1.Configuration();
757
+ });
758
+ it('should close connection successfully', async () => {
759
+ const mockConnectionAttributes = {
760
+ dialectName: 'bigquery',
761
+ isPool: false,
762
+ canPersist: true,
763
+ canStream: true,
764
+ };
765
+ const mockConnectionResponse = {
766
+ data: {
767
+ name: 'test-connection',
768
+ type: 'bigquery',
769
+ attributes: mockConnectionAttributes,
770
+ bigqueryConnection: {
771
+ defaultProjectId: 'test-project',
772
+ billingProjectId: 'test-project',
773
+ },
774
+ },
775
+ status: 200,
776
+ statusText: 'OK',
777
+ headers: {},
778
+ config: {},
779
+ };
780
+ mockConnectionsApi.getConnection.mockResolvedValueOnce(mockConnectionResponse);
781
+ const connection = await publisher_connection_1.PublisherConnection.create('test-connection', {
782
+ connectionUri: 'http://test.com/api/v0/projects/test-project/connections/test-connection',
783
+ accessToken: 'test-token',
784
+ });
785
+ // close() should not throw and should return void
786
+ await expect(connection.close()).resolves.toBeUndefined();
787
+ });
749
788
  });
750
789
  });
751
790
  });
@@ -813,4 +852,4 @@ async function setupAndTestInvalidJsonResponse(mockConnectionsApi, apiMethod, op
813
852
  });
814
853
  await testErrorHandling(connection, () => operation(connection));
815
854
  }
816
- //# sourceMappingURL=publisher_connection.spec.js.map
855
+ //# sourceMappingURL=publisher_connection.unit.spec.js.map