@malloydata/db-publisher 0.0.321 → 0.0.322
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/dist/client/api.d.ts +28 -10
- package/dist/client/api.js +3 -3
- package/dist/client/api.js.map +1 -1
- package/dist/client/common.js +5 -1
- package/dist/client/common.js.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/publisher_connection.d.ts +1 -0
- package/dist/publisher_connection.js +90 -42
- package/dist/publisher_connection.js.map +1 -1
- package/package.json +3 -3
- package/publisher-api-doc.yaml +19 -7
- package/scripts/patch-common.js +132 -0
- package/src/client/api.ts +30 -12
- package/src/client/common.ts +5 -1
- package/src/client/index.ts +6 -4
- package/src/publisher_connection.ts +129 -74
- package/tsconfig.json +2 -0
|
@@ -26,6 +26,7 @@ import type {
|
|
|
26
26
|
RawAxiosRequestConfig,
|
|
27
27
|
} from './client';
|
|
28
28
|
import {Configuration, ConnectionsApi, ConnectionsTestApi} from './client';
|
|
29
|
+
import {AxiosError} from 'axios';
|
|
29
30
|
|
|
30
31
|
interface PublisherConnectionOptions {
|
|
31
32
|
connectionUri: string;
|
|
@@ -147,33 +148,51 @@ export class PublisherConnection
|
|
|
147
148
|
_tableKey: string,
|
|
148
149
|
tablePath: string
|
|
149
150
|
): Promise<TableSourceDef> {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
151
|
+
let result = {} as TableSourceDef;
|
|
152
|
+
try {
|
|
153
|
+
const response = await this.connectionsApi.getTable(
|
|
154
|
+
this.projectName,
|
|
155
|
+
this.name,
|
|
156
|
+
tablePath.split('.')[0],
|
|
157
|
+
tablePath,
|
|
158
|
+
{
|
|
159
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
result = JSON.parse(response.data.source as string) as TableSourceDef;
|
|
163
|
+
} catch (error: AxiosError | unknown) {
|
|
164
|
+
this.extractAndThrowError(
|
|
165
|
+
error,
|
|
166
|
+
`Failed to fetch table schema for ${tablePath}`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
160
170
|
}
|
|
161
171
|
|
|
162
172
|
public async fetchSelectSchema(
|
|
163
173
|
sqlRef: SQLSourceRequest
|
|
164
174
|
): Promise<SQLSourceDef> {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
let result = {} as SQLSourceDef;
|
|
176
|
+
try {
|
|
177
|
+
const request: PostSqlsourceRequest = {
|
|
178
|
+
sqlStatement: sqlRef.selectStr,
|
|
179
|
+
};
|
|
180
|
+
const response = await this.connectionsApi.postSqlsource(
|
|
181
|
+
this.projectName,
|
|
182
|
+
this.name,
|
|
183
|
+
request,
|
|
184
|
+
{
|
|
185
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
result = JSON.parse(response.data.source as string) as SQLSourceDef;
|
|
189
|
+
} catch (error: AxiosError | unknown) {
|
|
190
|
+
this.extractAndThrowError(
|
|
191
|
+
error,
|
|
192
|
+
'Failed to fetch select schema for SQL query'
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
177
196
|
}
|
|
178
197
|
|
|
179
198
|
public async estimateQueryCost(_sqlCommand: string): Promise<QueryRunStats> {
|
|
@@ -185,76 +204,112 @@ export class PublisherConnection
|
|
|
185
204
|
sql: string,
|
|
186
205
|
options: RunSQLOptions = {}
|
|
187
206
|
): Promise<MalloyQueryData> {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
207
|
+
let result = {} as MalloyQueryData;
|
|
208
|
+
try {
|
|
209
|
+
// TODO: Add support for abortSignal.
|
|
210
|
+
options.abortSignal = undefined;
|
|
211
|
+
const request: PostSqlsourceRequest = {
|
|
212
|
+
sqlStatement: sql,
|
|
213
|
+
};
|
|
214
|
+
const response = await this.connectionsApi.postQuerydata(
|
|
215
|
+
this.projectName,
|
|
216
|
+
this.name,
|
|
217
|
+
request,
|
|
218
|
+
JSON.stringify(options),
|
|
219
|
+
{
|
|
220
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
result = JSON.parse(response.data.data as string) as MalloyQueryData;
|
|
224
|
+
} catch (error: AxiosError | unknown) {
|
|
225
|
+
this.extractAndThrowError(error, 'Failed to execute SQL query');
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
203
228
|
}
|
|
204
229
|
|
|
205
230
|
public async *runSQLStream(
|
|
206
231
|
sqlCommand: string,
|
|
207
232
|
options: RunSQLOptions = {}
|
|
208
233
|
): AsyncIterableIterator<QueryDataRow> {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
try {
|
|
235
|
+
// TODO: Add support for abortSignal.
|
|
236
|
+
options.abortSignal = undefined;
|
|
237
|
+
// TODO: Add real streaming support to publisher API.
|
|
238
|
+
const request: PostSqlsourceRequest = {
|
|
239
|
+
sqlStatement: sqlCommand,
|
|
240
|
+
};
|
|
241
|
+
const response = await this.connectionsApi.postQuerydata(
|
|
242
|
+
this.projectName,
|
|
243
|
+
this.name,
|
|
244
|
+
request,
|
|
245
|
+
JSON.stringify(options),
|
|
246
|
+
{
|
|
247
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
248
|
+
}
|
|
249
|
+
);
|
|
250
|
+
const queryData = JSON.parse(
|
|
251
|
+
response.data.data as string
|
|
252
|
+
) as MalloyQueryData;
|
|
253
|
+
for (const row of queryData.rows) {
|
|
254
|
+
yield row;
|
|
222
255
|
}
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
) as MalloyQueryData;
|
|
227
|
-
for (const row of queryData.rows) {
|
|
228
|
-
yield row;
|
|
256
|
+
} catch (error: AxiosError | unknown) {
|
|
257
|
+
this.extractAndThrowError(error, 'Failed to execute streaming SQL query');
|
|
258
|
+
return;
|
|
229
259
|
}
|
|
230
260
|
}
|
|
231
261
|
|
|
232
262
|
public async test(): Promise<void> {
|
|
233
|
-
|
|
234
|
-
this.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
263
|
+
try {
|
|
264
|
+
await this.connectionsTestApi.testConnectionConfiguration(
|
|
265
|
+
this.connectionData,
|
|
266
|
+
{
|
|
267
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
268
|
+
}
|
|
269
|
+
);
|
|
270
|
+
} catch (error: AxiosError | unknown) {
|
|
271
|
+
this.extractAndThrowError(
|
|
272
|
+
error,
|
|
273
|
+
'Failed to test connection configuration'
|
|
274
|
+
);
|
|
275
|
+
}
|
|
239
276
|
}
|
|
240
277
|
|
|
241
278
|
public async manifestTemporaryTable(sqlCommand: string): Promise<string> {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
279
|
+
let result = '';
|
|
280
|
+
try {
|
|
281
|
+
const request: PostSqlsourceRequest = {
|
|
282
|
+
sqlStatement: sqlCommand,
|
|
283
|
+
};
|
|
284
|
+
const response = await this.connectionsApi.postTemporarytable(
|
|
285
|
+
this.projectName,
|
|
286
|
+
this.name,
|
|
287
|
+
request,
|
|
288
|
+
{
|
|
289
|
+
headers: PublisherConnection.getAuthHeaders(this.accessToken),
|
|
290
|
+
}
|
|
291
|
+
);
|
|
292
|
+
result = response.data.table as string;
|
|
293
|
+
} catch (error: AxiosError | unknown) {
|
|
294
|
+
this.extractAndThrowError(error, 'Failed to manifest temporary table');
|
|
295
|
+
}
|
|
296
|
+
return result;
|
|
254
297
|
}
|
|
255
298
|
|
|
256
299
|
public async close(): Promise<void> {
|
|
257
300
|
// Can't close the remote connection.
|
|
258
301
|
return;
|
|
259
302
|
}
|
|
303
|
+
|
|
304
|
+
private extractAndThrowError(
|
|
305
|
+
error: AxiosError | unknown,
|
|
306
|
+
defaultMessage: string
|
|
307
|
+
): void {
|
|
308
|
+
if (error instanceof AxiosError) {
|
|
309
|
+
const errorMessage =
|
|
310
|
+
error?.response?.data?.message || error?.message || defaultMessage;
|
|
311
|
+
throw new Error(errorMessage);
|
|
312
|
+
}
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
260
315
|
}
|