@malloydata/db-publisher 0.0.270-dev250429163414

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 (40) hide show
  1. package/dist/client/api.d.ts +1537 -0
  2. package/dist/client/api.js +1572 -0
  3. package/dist/client/api.js.map +1 -0
  4. package/dist/client/base.d.ts +66 -0
  5. package/dist/client/base.js +69 -0
  6. package/dist/client/base.js.map +1 -0
  7. package/dist/client/common.d.ts +65 -0
  8. package/dist/client/common.js +147 -0
  9. package/dist/client/common.js.map +1 -0
  10. package/dist/client/configuration.d.ts +91 -0
  11. package/dist/client/configuration.js +50 -0
  12. package/dist/client/configuration.js.map +1 -0
  13. package/dist/client/index.d.ts +15 -0
  14. package/dist/client/index.js +32 -0
  15. package/dist/client/index.js.map +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +12 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/publisher_connection.d.ts +29 -0
  20. package/dist/publisher_connection.js +119 -0
  21. package/dist/publisher_connection.js.map +1 -0
  22. package/dist/publisher_connection.spec.d.ts +1 -0
  23. package/dist/publisher_connection.spec.js +806 -0
  24. package/dist/publisher_connection.spec.js.map +1 -0
  25. package/openapitools.json +7 -0
  26. package/package.json +32 -0
  27. package/publisher-api-doc.yaml +1026 -0
  28. package/src/client/.openapi-generator/FILES +9 -0
  29. package/src/client/.openapi-generator/VERSION +1 -0
  30. package/src/client/.openapi-generator-ignore +23 -0
  31. package/src/client/api.ts +2342 -0
  32. package/src/client/base.ts +86 -0
  33. package/src/client/common.ts +150 -0
  34. package/src/client/configuration.ts +115 -0
  35. package/src/client/git_push.sh +57 -0
  36. package/src/client/index.ts +19 -0
  37. package/src/index.ts +8 -0
  38. package/src/publisher_connection.spec.ts +1118 -0
  39. package/src/publisher_connection.ts +223 -0
  40. package/tsconfig.json +13 -0
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PublisherConnection = void 0;
10
+ var publisher_connection_1 = require("./publisher_connection");
11
+ Object.defineProperty(exports, "PublisherConnection", { enumerable: true, get: function () { return publisher_connection_1.PublisherConnection; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+DAA2D;AAAnD,2HAAA,mBAAmB,OAAA"}
@@ -0,0 +1,29 @@
1
+ import type { Connection, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryRunStats, StreamingConnection, SQLSourceDef, SQLSourceRequest, TableSourceDef, RunSQLOptions, TestableConnection } from '@malloydata/malloy';
2
+ import { BaseConnection } from '@malloydata/malloy/connection';
3
+ interface PublisherConnectionOptions {
4
+ connectionUri: string;
5
+ accessToken?: string;
6
+ }
7
+ export declare class PublisherConnection extends BaseConnection implements Connection, StreamingConnection, TestableConnection, PersistSQLResults {
8
+ readonly name: string;
9
+ readonly projectName: string;
10
+ private connectionsApi;
11
+ private connectionAttributes;
12
+ private accessToken;
13
+ static create(name: string, options: PublisherConnectionOptions): Promise<PublisherConnection>;
14
+ private static getAuthHeaders;
15
+ private constructor();
16
+ get dialectName(): string;
17
+ isPool(): this is PooledConnection;
18
+ canPersist(): this is PersistSQLResults;
19
+ canStream(): this is StreamingConnection;
20
+ fetchTableSchema(tableKey: string, tablePath: string): Promise<TableSourceDef>;
21
+ fetchSelectSchema(sqlRef: SQLSourceRequest): Promise<SQLSourceDef>;
22
+ estimateQueryCost(_sqlCommand: string): Promise<QueryRunStats>;
23
+ runSQL(sql: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
24
+ runSQLStream(sqlCommand: string, options?: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
25
+ test(): Promise<void>;
26
+ manifestTemporaryTable(sqlCommand: string): Promise<string>;
27
+ close(): Promise<void>;
28
+ }
29
+ export {};
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PublisherConnection = void 0;
10
+ const connection_1 = require("@malloydata/malloy/connection");
11
+ const client_1 = require("./client");
12
+ class PublisherConnection extends connection_1.BaseConnection {
13
+ static async create(name, options) {
14
+ const url = new URL(options.connectionUri);
15
+ const urlParts = url.pathname.split('/');
16
+ if (urlParts.length !== 7) {
17
+ const fmt = '/api/v0/projects/{projectName}/connections/{connectionName}';
18
+ throw new Error(`Invalid connection URI: ${options.connectionUri}. Expected format: ${fmt}`);
19
+ }
20
+ const apiTag = urlParts[1];
21
+ const versionTag = urlParts[2];
22
+ const projectName = urlParts[4];
23
+ const connectionName = urlParts[6];
24
+ if (name !== connectionName) {
25
+ throw new Error(`Connection name mismatch: ${name} !== ${connectionName}. Connection name must match the URI path.`);
26
+ }
27
+ const apiUrl = `${url.origin}/${apiTag}/${versionTag}`;
28
+ const configuration = new client_1.Configuration({
29
+ basePath: apiUrl,
30
+ });
31
+ const connectionsApi = new client_1.ConnectionsApi(configuration);
32
+ const response = await connectionsApi.getConnection(projectName, name, {
33
+ headers: PublisherConnection.getAuthHeaders(options.accessToken),
34
+ });
35
+ const connectionAttributes = response.data
36
+ .attributes;
37
+ const connection = new PublisherConnection(name, projectName, connectionsApi, connectionAttributes, options.accessToken);
38
+ await connection.test();
39
+ return connection;
40
+ }
41
+ static getAuthHeaders(accessToken) {
42
+ return {
43
+ ...(accessToken && { Authorization: `Bearer ${accessToken}` }),
44
+ };
45
+ }
46
+ constructor(name, projectName, connectionsApi, connectionAttributes, accessToken) {
47
+ super();
48
+ this.name = name;
49
+ this.projectName = projectName;
50
+ this.connectionsApi = connectionsApi;
51
+ this.connectionAttributes = connectionAttributes;
52
+ this.accessToken = accessToken;
53
+ }
54
+ get dialectName() {
55
+ return this.connectionAttributes.dialectName;
56
+ }
57
+ isPool() {
58
+ return this.connectionAttributes.isPool;
59
+ }
60
+ canPersist() {
61
+ return this.connectionAttributes.canPersist;
62
+ }
63
+ canStream() {
64
+ return this.connectionAttributes.canStream;
65
+ }
66
+ async fetchTableSchema(tableKey, tablePath) {
67
+ const response = await this.connectionsApi.getTablesource(this.projectName, this.name, tableKey, tablePath, {
68
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
69
+ });
70
+ return JSON.parse(response.data.source);
71
+ }
72
+ async fetchSelectSchema(sqlRef) {
73
+ const response = await this.connectionsApi.getSqlsource(this.projectName, this.name, sqlRef.selectStr, {
74
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
75
+ });
76
+ return JSON.parse(response.data.source);
77
+ }
78
+ async estimateQueryCost(_sqlCommand) {
79
+ // Most connection types don't support cost estimation.
80
+ return {};
81
+ }
82
+ async runSQL(sql, options = {}) {
83
+ // TODO: Add support for abortSignal.
84
+ options.abortSignal = undefined;
85
+ const response = await this.connectionsApi.getQuerydata(this.projectName, this.name, sql, JSON.stringify(options), {
86
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
87
+ });
88
+ return JSON.parse(response.data.data);
89
+ }
90
+ async *runSQLStream(sqlCommand, options = {}) {
91
+ // TODO: Add support for abortSignal.
92
+ options.abortSignal = undefined;
93
+ // TODO: Add real streaming support to publisher API.
94
+ const response = await this.connectionsApi.getQuerydata(this.projectName, this.name, sqlCommand, JSON.stringify(options), {
95
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
96
+ });
97
+ const queryData = JSON.parse(response.data.data);
98
+ for (const row of queryData.rows) {
99
+ yield row;
100
+ }
101
+ }
102
+ async test() {
103
+ await this.connectionsApi.getTest(this.projectName, this.name, {
104
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
105
+ });
106
+ }
107
+ async manifestTemporaryTable(sqlCommand) {
108
+ const response = await this.connectionsApi.getTemporarytable(this.projectName, this.name, sqlCommand, {
109
+ headers: PublisherConnection.getAuthHeaders(this.accessToken),
110
+ });
111
+ return response.data.table;
112
+ }
113
+ async close() {
114
+ // Can't close the remote connection.
115
+ return;
116
+ }
117
+ }
118
+ exports.PublisherConnection = PublisherConnection;
119
+ //# sourceMappingURL=publisher_connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher_connection.js","sourceRoot":"","sources":["../src/publisher_connection.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAgBH,8DAA6D;AAE7D,qCAAuD;AAOvD,MAAa,mBACX,SAAQ,2BAAc;IAatB,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAAmC;QACnE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,MAAM,GAAG,GAAG,6DAA6D,CAAC;YAC1E,MAAM,IAAI,KAAK,CACb,2BAA2B,OAAO,CAAC,aAAa,sBAAsB,GAAG,EAAE,CAC5E,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QAEnC,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,6BAA6B,IAAI,QAAQ,cAAc,4CAA4C,CACpG,CAAC;QAC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