@malloydata/malloy 0.0.364 → 0.0.365
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/api/foundation/config.d.ts +42 -13
- package/dist/api/foundation/config.js +79 -14
- package/dist/api/foundation/runtime.d.ts +18 -9
- package/dist/api/foundation/runtime.js +20 -13
- package/dist/connection/registry.d.ts +16 -2
- package/dist/connection/registry.js +18 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { URLReader } from '../../runtime_types';
|
|
2
2
|
import type { Connection, LookupConnection } from '../../connection/types';
|
|
3
3
|
import type { ConnectionConfigEntry } from '../../connection/registry';
|
|
4
|
-
import type { BuildID, BuildManifest, BuildManifestEntry } from '../../model/malloy_types';
|
|
4
|
+
import type { BuildID, BuildManifest, BuildManifestEntry, VirtualMap } from '../../model/malloy_types';
|
|
5
5
|
/**
|
|
6
6
|
* The parsed contents of a malloy-config.json file.
|
|
7
7
|
*/
|
|
8
8
|
export interface MalloyProjectConfig {
|
|
9
9
|
connections?: Record<string, ConnectionConfigEntry>;
|
|
10
10
|
manifestPath?: string;
|
|
11
|
+
virtualMap?: VirtualMap;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* In-memory manifest store. Reads, updates, and serializes manifest data.
|
|
@@ -71,9 +72,8 @@ export declare class Manifest {
|
|
|
71
72
|
private _loadParsed;
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
|
-
* Loads and holds a Malloy project configuration (connections + manifest
|
|
75
|
-
*
|
|
76
|
-
* Two construction modes:
|
|
75
|
+
* Loads and holds a Malloy project configuration (connections + manifest +
|
|
76
|
+
* virtualMap). Pass directly to Runtime — everything flows automatically.
|
|
77
77
|
*
|
|
78
78
|
* // From a URL — reads config + manifest via URLReader
|
|
79
79
|
* const config = new MalloyConfig(urlReader, configURL);
|
|
@@ -82,12 +82,12 @@ export declare class Manifest {
|
|
|
82
82
|
* // From text you already have
|
|
83
83
|
* const config = new MalloyConfig(configText);
|
|
84
84
|
*
|
|
85
|
-
* // Either way,
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
85
|
+
* // Either way, pass to Runtime — connections, buildManifest, virtualMap
|
|
86
|
+
* // all come from the config. No manual wiring needed.
|
|
87
|
+
* const runtime = new Runtime({config, urlReader});
|
|
88
|
+
*
|
|
89
|
+
* To override specific fields, mutate the config before passing:
|
|
90
|
+
* config.connectionMap = myCustomConnections;
|
|
91
91
|
*/
|
|
92
92
|
export declare class MalloyConfig {
|
|
93
93
|
private readonly _urlReader?;
|
|
@@ -95,6 +95,9 @@ export declare class MalloyConfig {
|
|
|
95
95
|
private _data;
|
|
96
96
|
private _connectionMap;
|
|
97
97
|
private readonly _manifest;
|
|
98
|
+
private _managedLookup;
|
|
99
|
+
private _connectionLookupOverride;
|
|
100
|
+
private _onConnectionCreated;
|
|
98
101
|
constructor(configText: string);
|
|
99
102
|
constructor(urlReader: URLReader, configURL: string);
|
|
100
103
|
/**
|
|
@@ -119,13 +122,39 @@ export declare class MalloyConfig {
|
|
|
119
122
|
set connectionMap(map: Record<string, ConnectionConfigEntry>);
|
|
120
123
|
/**
|
|
121
124
|
* A LookupConnection built from the current connectionMap via the
|
|
122
|
-
* connection type registry.
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
+
* connection type registry. The result is cached — repeated access
|
|
126
|
+
* returns the same object (and the same underlying connections).
|
|
127
|
+
*
|
|
128
|
+
* If `connectionLookup` has been set, returns the override instead.
|
|
129
|
+
*
|
|
130
|
+
* Changing `connectionMap` invalidates the cache; the next access
|
|
131
|
+
* creates a fresh ManagedConnectionLookup.
|
|
125
132
|
*/
|
|
126
133
|
get connections(): LookupConnection<Connection>;
|
|
134
|
+
/**
|
|
135
|
+
* Override the connection lookup entirely. When set, the `connections`
|
|
136
|
+
* getter returns this instead of building from `connectionMap`.
|
|
137
|
+
* Use this when you need to merge config connections with other sources.
|
|
138
|
+
*/
|
|
139
|
+
get connectionLookup(): LookupConnection<Connection> | undefined;
|
|
140
|
+
set connectionLookup(lookup: LookupConnection<Connection> | undefined);
|
|
141
|
+
/**
|
|
142
|
+
* Callback invoked once per connection immediately after factory creation.
|
|
143
|
+
* Use for post-creation setup (e.g., registering WASM file handlers).
|
|
144
|
+
* Must be set before the first connection is looked up.
|
|
145
|
+
*/
|
|
146
|
+
set onConnectionCreated(cb: ((name: string, connection: Connection) => void) | undefined);
|
|
147
|
+
/**
|
|
148
|
+
* Close all connections created by this config's internal managed lookup.
|
|
149
|
+
* Does nothing if connections were overridden via `connectionLookup`.
|
|
150
|
+
*/
|
|
151
|
+
close(): Promise<void>;
|
|
127
152
|
/**
|
|
128
153
|
* The Manifest object. Always exists, may be empty if not yet loaded.
|
|
129
154
|
*/
|
|
130
155
|
get manifest(): Manifest;
|
|
156
|
+
/**
|
|
157
|
+
* The VirtualMap parsed from config, if present.
|
|
158
|
+
*/
|
|
159
|
+
get virtualMap(): VirtualMap | undefined;
|
|
131
160
|
}
|
|
@@ -144,9 +144,8 @@ class Manifest {
|
|
|
144
144
|
}
|
|
145
145
|
exports.Manifest = Manifest;
|
|
146
146
|
/**
|
|
147
|
-
* Loads and holds a Malloy project configuration (connections + manifest
|
|
148
|
-
*
|
|
149
|
-
* Two construction modes:
|
|
147
|
+
* Loads and holds a Malloy project configuration (connections + manifest +
|
|
148
|
+
* virtualMap). Pass directly to Runtime — everything flows automatically.
|
|
150
149
|
*
|
|
151
150
|
* // From a URL — reads config + manifest via URLReader
|
|
152
151
|
* const config = new MalloyConfig(urlReader, configURL);
|
|
@@ -155,12 +154,12 @@ exports.Manifest = Manifest;
|
|
|
155
154
|
* // From text you already have
|
|
156
155
|
* const config = new MalloyConfig(configText);
|
|
157
156
|
*
|
|
158
|
-
* // Either way,
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
157
|
+
* // Either way, pass to Runtime — connections, buildManifest, virtualMap
|
|
158
|
+
* // all come from the config. No manual wiring needed.
|
|
159
|
+
* const runtime = new Runtime({config, urlReader});
|
|
160
|
+
*
|
|
161
|
+
* To override specific fields, mutate the config before passing:
|
|
162
|
+
* config.connectionMap = myCustomConnections;
|
|
164
163
|
*/
|
|
165
164
|
class MalloyConfig {
|
|
166
165
|
constructor(urlReaderOrText, configURL) {
|
|
@@ -219,18 +218,59 @@ class MalloyConfig {
|
|
|
219
218
|
}
|
|
220
219
|
set connectionMap(map) {
|
|
221
220
|
this._connectionMap = map;
|
|
221
|
+
// Invalidate cached managed lookup — new map means new connections
|
|
222
|
+
this._managedLookup = undefined;
|
|
222
223
|
}
|
|
223
224
|
/**
|
|
224
225
|
* A LookupConnection built from the current connectionMap via the
|
|
225
|
-
* connection type registry.
|
|
226
|
-
*
|
|
227
|
-
*
|
|
226
|
+
* connection type registry. The result is cached — repeated access
|
|
227
|
+
* returns the same object (and the same underlying connections).
|
|
228
|
+
*
|
|
229
|
+
* If `connectionLookup` has been set, returns the override instead.
|
|
230
|
+
*
|
|
231
|
+
* Changing `connectionMap` invalidates the cache; the next access
|
|
232
|
+
* creates a fresh ManagedConnectionLookup.
|
|
228
233
|
*/
|
|
229
234
|
get connections() {
|
|
235
|
+
if (this._connectionLookupOverride) {
|
|
236
|
+
return this._connectionLookupOverride;
|
|
237
|
+
}
|
|
230
238
|
if (!this._connectionMap) {
|
|
231
239
|
throw new Error('Config not loaded. Call load() or loadConfig() first.');
|
|
232
240
|
}
|
|
233
|
-
|
|
241
|
+
if (!this._managedLookup) {
|
|
242
|
+
this._managedLookup = (0, registry_1.createConnectionsFromConfig)({ connections: this._connectionMap }, this._onConnectionCreated);
|
|
243
|
+
}
|
|
244
|
+
return this._managedLookup;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Override the connection lookup entirely. When set, the `connections`
|
|
248
|
+
* getter returns this instead of building from `connectionMap`.
|
|
249
|
+
* Use this when you need to merge config connections with other sources.
|
|
250
|
+
*/
|
|
251
|
+
get connectionLookup() {
|
|
252
|
+
return this._connectionLookupOverride;
|
|
253
|
+
}
|
|
254
|
+
set connectionLookup(lookup) {
|
|
255
|
+
this._connectionLookupOverride = lookup;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Callback invoked once per connection immediately after factory creation.
|
|
259
|
+
* Use for post-creation setup (e.g., registering WASM file handlers).
|
|
260
|
+
* Must be set before the first connection is looked up.
|
|
261
|
+
*/
|
|
262
|
+
set onConnectionCreated(cb) {
|
|
263
|
+
this._onConnectionCreated = cb;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Close all connections created by this config's internal managed lookup.
|
|
267
|
+
* Does nothing if connections were overridden via `connectionLookup`.
|
|
268
|
+
*/
|
|
269
|
+
async close() {
|
|
270
|
+
if (this._managedLookup) {
|
|
271
|
+
await this._managedLookup.close();
|
|
272
|
+
this._managedLookup = undefined;
|
|
273
|
+
}
|
|
234
274
|
}
|
|
235
275
|
/**
|
|
236
276
|
* The Manifest object. Always exists, may be empty if not yet loaded.
|
|
@@ -238,6 +278,13 @@ class MalloyConfig {
|
|
|
238
278
|
get manifest() {
|
|
239
279
|
return this._manifest;
|
|
240
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* The VirtualMap parsed from config, if present.
|
|
283
|
+
*/
|
|
284
|
+
get virtualMap() {
|
|
285
|
+
var _a;
|
|
286
|
+
return (_a = this._data) === null || _a === void 0 ? void 0 : _a.virtualMap;
|
|
287
|
+
}
|
|
241
288
|
}
|
|
242
289
|
exports.MalloyConfig = MalloyConfig;
|
|
243
290
|
/**
|
|
@@ -248,6 +295,24 @@ function parseConfigText(jsonText) {
|
|
|
248
295
|
var _a;
|
|
249
296
|
const parsed = JSON.parse(jsonText);
|
|
250
297
|
const connections = Object.fromEntries(Object.entries((_a = parsed.connections) !== null && _a !== void 0 ? _a : {}).filter(([, v]) => (0, registry_1.isConnectionConfigEntry)(v)));
|
|
251
|
-
|
|
298
|
+
const result = { ...parsed, connections };
|
|
299
|
+
if (parsed.virtualMap &&
|
|
300
|
+
typeof parsed.virtualMap === 'object' &&
|
|
301
|
+
!Array.isArray(parsed.virtualMap)) {
|
|
302
|
+
const outer = new Map();
|
|
303
|
+
for (const [connName, inner] of Object.entries(parsed.virtualMap)) {
|
|
304
|
+
if (inner && typeof inner === 'object' && !Array.isArray(inner)) {
|
|
305
|
+
const innerMap = new Map();
|
|
306
|
+
for (const [virtualName, tablePath] of Object.entries(inner)) {
|
|
307
|
+
if (typeof tablePath === 'string') {
|
|
308
|
+
innerMap.set(virtualName, tablePath);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
outer.set(connName, innerMap);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
result.virtualMap = outer;
|
|
315
|
+
}
|
|
316
|
+
return result;
|
|
252
317
|
}
|
|
253
318
|
//# sourceMappingURL=config.js.map
|
|
@@ -4,6 +4,7 @@ import type { ModelDef, Query as InternalQuery, SearchIndexResult, SearchValueMa
|
|
|
4
4
|
import type { Dialect } from '../../dialect';
|
|
5
5
|
import type { RunSQLOptions } from '../../run_sql_options';
|
|
6
6
|
import type { CacheManager } from './cache';
|
|
7
|
+
import type { MalloyConfig } from './config';
|
|
7
8
|
import type { ParseOptions, CompileOptions, CompileQueryOptions } from './types';
|
|
8
9
|
import type { PreparedResult, Explore } from './core';
|
|
9
10
|
import { Model, PreparedQuery } from './core';
|
|
@@ -13,11 +14,17 @@ type ModelString = string;
|
|
|
13
14
|
type QueryURL = URL;
|
|
14
15
|
type QueryString = string;
|
|
15
16
|
type Connectionable = {
|
|
17
|
+
config: MalloyConfig;
|
|
18
|
+
connection?: undefined;
|
|
19
|
+
connections?: LookupConnection<Connection>;
|
|
20
|
+
} | {
|
|
16
21
|
connection: Connection;
|
|
17
22
|
connections?: undefined;
|
|
23
|
+
config?: undefined;
|
|
18
24
|
} | {
|
|
19
25
|
connections: LookupConnection<Connection>;
|
|
20
26
|
connection?: undefined;
|
|
27
|
+
config?: undefined;
|
|
21
28
|
};
|
|
22
29
|
declare class FluentState<T> {
|
|
23
30
|
protected runtime: Runtime;
|
|
@@ -39,14 +46,13 @@ export declare class Runtime {
|
|
|
39
46
|
private _connections;
|
|
40
47
|
private _eventStream;
|
|
41
48
|
private _cacheManager;
|
|
49
|
+
private _config;
|
|
42
50
|
private _buildManifest;
|
|
43
51
|
private _virtualMap;
|
|
44
|
-
constructor({ urlReader, connections, connection, eventStream, cacheManager,
|
|
52
|
+
constructor({ urlReader, connections, connection, config, eventStream, cacheManager, }: {
|
|
45
53
|
urlReader?: URLReader;
|
|
46
54
|
eventStream?: EventStream;
|
|
47
55
|
cacheManager?: CacheManager;
|
|
48
|
-
buildManifest?: BuildManifest;
|
|
49
|
-
virtualMap?: VirtualMap;
|
|
50
56
|
} & Connectionable);
|
|
51
57
|
/**
|
|
52
58
|
* @return The `CacheManager` for this runtime instance.
|
|
@@ -69,6 +75,10 @@ export declare class Runtime {
|
|
|
69
75
|
* When set, compiled queries automatically resolve persist sources
|
|
70
76
|
* against this manifest. Can be overridden per-query via
|
|
71
77
|
* CompileQueryOptions.buildManifest.
|
|
78
|
+
*
|
|
79
|
+
* When constructed with a MalloyConfig, falls through to
|
|
80
|
+
* config.manifest.buildManifest (a live reference — builder
|
|
81
|
+
* mutations are visible automatically).
|
|
72
82
|
*/
|
|
73
83
|
get buildManifest(): BuildManifest | undefined;
|
|
74
84
|
set buildManifest(manifest: BuildManifest | undefined);
|
|
@@ -77,6 +87,9 @@ export declare class Runtime {
|
|
|
77
87
|
* When set, compiled queries automatically resolve virtual sources
|
|
78
88
|
* against this map. Can be overridden per-query via
|
|
79
89
|
* CompileQueryOptions.virtualMap.
|
|
90
|
+
*
|
|
91
|
+
* When constructed with a MalloyConfig, falls through to
|
|
92
|
+
* config.virtualMap.
|
|
80
93
|
*/
|
|
81
94
|
get virtualMap(): VirtualMap | undefined;
|
|
82
95
|
set virtualMap(map: VirtualMap | undefined);
|
|
@@ -152,21 +165,17 @@ export declare class Runtime {
|
|
|
152
165
|
}
|
|
153
166
|
export declare class ConnectionRuntime extends Runtime {
|
|
154
167
|
readonly rawConnections: Connection[];
|
|
155
|
-
constructor({ urlReader, connections,
|
|
168
|
+
constructor({ urlReader, connections, }: {
|
|
156
169
|
urlReader?: URLReader;
|
|
157
170
|
connections: Connection[];
|
|
158
|
-
buildManifest?: BuildManifest;
|
|
159
|
-
virtualMap?: VirtualMap;
|
|
160
171
|
});
|
|
161
172
|
}
|
|
162
173
|
export declare class SingleConnectionRuntime<T extends Connection = Connection> extends Runtime {
|
|
163
174
|
readonly connection: T;
|
|
164
|
-
constructor({ urlReader, connection, eventStream, cacheManager,
|
|
175
|
+
constructor({ urlReader, connection, eventStream, cacheManager, }: {
|
|
165
176
|
urlReader?: URLReader;
|
|
166
177
|
eventStream?: EventStream;
|
|
167
178
|
cacheManager?: CacheManager;
|
|
168
|
-
buildManifest?: BuildManifest;
|
|
169
|
-
virtualMap?: VirtualMap;
|
|
170
179
|
connection: T;
|
|
171
180
|
});
|
|
172
181
|
get supportsNesting(): boolean;
|
|
@@ -46,11 +46,15 @@ class FluentState {
|
|
|
46
46
|
* An environment for compiling and running Malloy queries.
|
|
47
47
|
*/
|
|
48
48
|
class Runtime {
|
|
49
|
-
constructor({ urlReader, connections, connection, eventStream, cacheManager,
|
|
49
|
+
constructor({ urlReader, connections, connection, config, eventStream, cacheManager, }) {
|
|
50
50
|
this.isTestRuntime = false;
|
|
51
|
-
if (
|
|
51
|
+
if (config !== undefined) {
|
|
52
|
+
this._config = config;
|
|
53
|
+
connections = connections !== null && connections !== void 0 ? connections : config.connections;
|
|
54
|
+
}
|
|
55
|
+
else if (connections === undefined) {
|
|
52
56
|
if (connection === undefined) {
|
|
53
|
-
throw new Error('A LookupConnection<Connection
|
|
57
|
+
throw new Error('A MalloyConfig, LookupConnection<Connection>, or Connection is required.');
|
|
54
58
|
}
|
|
55
59
|
connections = {
|
|
56
60
|
lookupConnection: () => Promise.resolve(connection),
|
|
@@ -63,8 +67,6 @@ class Runtime {
|
|
|
63
67
|
this._connections = connections;
|
|
64
68
|
this._eventStream = eventStream;
|
|
65
69
|
this._cacheManager = cacheManager;
|
|
66
|
-
this._buildManifest = buildManifest;
|
|
67
|
-
this._virtualMap = virtualMap;
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
72
|
* @return The `CacheManager` for this runtime instance.
|
|
@@ -95,9 +97,14 @@ class Runtime {
|
|
|
95
97
|
* When set, compiled queries automatically resolve persist sources
|
|
96
98
|
* against this manifest. Can be overridden per-query via
|
|
97
99
|
* CompileQueryOptions.buildManifest.
|
|
100
|
+
*
|
|
101
|
+
* When constructed with a MalloyConfig, falls through to
|
|
102
|
+
* config.manifest.buildManifest (a live reference — builder
|
|
103
|
+
* mutations are visible automatically).
|
|
98
104
|
*/
|
|
99
105
|
get buildManifest() {
|
|
100
|
-
|
|
106
|
+
var _a, _b;
|
|
107
|
+
return (_a = this._buildManifest) !== null && _a !== void 0 ? _a : (_b = this._config) === null || _b === void 0 ? void 0 : _b.manifest.buildManifest;
|
|
101
108
|
}
|
|
102
109
|
set buildManifest(manifest) {
|
|
103
110
|
this._buildManifest = manifest;
|
|
@@ -107,9 +114,13 @@ class Runtime {
|
|
|
107
114
|
* When set, compiled queries automatically resolve virtual sources
|
|
108
115
|
* against this map. Can be overridden per-query via
|
|
109
116
|
* CompileQueryOptions.virtualMap.
|
|
117
|
+
*
|
|
118
|
+
* When constructed with a MalloyConfig, falls through to
|
|
119
|
+
* config.virtualMap.
|
|
110
120
|
*/
|
|
111
121
|
get virtualMap() {
|
|
112
|
-
|
|
122
|
+
var _a, _b;
|
|
123
|
+
return (_a = this._virtualMap) !== null && _a !== void 0 ? _a : (_b = this._config) === null || _b === void 0 ? void 0 : _b.virtualMap;
|
|
113
124
|
}
|
|
114
125
|
set virtualMap(map) {
|
|
115
126
|
this._virtualMap = map;
|
|
@@ -236,25 +247,21 @@ exports.Runtime = Runtime;
|
|
|
236
247
|
// ConnectionRuntime and SingleConnectionRuntime
|
|
237
248
|
// =============================================================================
|
|
238
249
|
class ConnectionRuntime extends Runtime {
|
|
239
|
-
constructor({ urlReader, connections,
|
|
250
|
+
constructor({ urlReader, connections, }) {
|
|
240
251
|
super({
|
|
241
252
|
connections: readers_1.FixedConnectionMap.fromArray(connections),
|
|
242
253
|
urlReader,
|
|
243
|
-
buildManifest,
|
|
244
|
-
virtualMap,
|
|
245
254
|
});
|
|
246
255
|
this.rawConnections = connections;
|
|
247
256
|
}
|
|
248
257
|
}
|
|
249
258
|
exports.ConnectionRuntime = ConnectionRuntime;
|
|
250
259
|
class SingleConnectionRuntime extends Runtime {
|
|
251
|
-
constructor({ urlReader, connection, eventStream, cacheManager,
|
|
260
|
+
constructor({ urlReader, connection, eventStream, cacheManager, }) {
|
|
252
261
|
super({
|
|
253
262
|
urlReader,
|
|
254
263
|
eventStream,
|
|
255
264
|
cacheManager,
|
|
256
|
-
buildManifest,
|
|
257
|
-
virtualMap,
|
|
258
265
|
connection,
|
|
259
266
|
});
|
|
260
267
|
this.connection = connection;
|
|
@@ -106,6 +106,20 @@ export declare function readConnectionsConfig(jsonText: string): ConnectionsConf
|
|
|
106
106
|
*/
|
|
107
107
|
export declare function writeConnectionsConfig(config: ConnectionsConfig): string;
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
109
|
+
* A LookupConnection with lifecycle management: close() shuts down all
|
|
110
|
+
* cached connections, and an optional onConnectionCreated callback fires
|
|
111
|
+
* once per connection after factory creation (before caching).
|
|
110
112
|
*/
|
|
111
|
-
export
|
|
113
|
+
export interface ManagedConnectionLookup extends LookupConnection<Connection> {
|
|
114
|
+
close(): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Create a ManagedConnectionLookup from a ConnectionsConfig using registered
|
|
118
|
+
* factories. Connections are cached per name for the lifetime of the returned
|
|
119
|
+
* object. Call close() to shut down all cached connections.
|
|
120
|
+
*
|
|
121
|
+
* @param onConnectionCreated Optional callback invoked once per connection
|
|
122
|
+
* immediately after factory creation. Use this for post-creation setup
|
|
123
|
+
* (e.g., registering WASM file handlers).
|
|
124
|
+
*/
|
|
125
|
+
export declare function createConnectionsFromConfig(config: ConnectionsConfig, onConnectionCreated?: (name: string, connection: Connection) => void): ManagedConnectionLookup;
|
|
@@ -93,9 +93,15 @@ function writeConnectionsConfig(config) {
|
|
|
93
93
|
return JSON.stringify(config, null, 2);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
|
-
* Create a
|
|
96
|
+
* Create a ManagedConnectionLookup from a ConnectionsConfig using registered
|
|
97
|
+
* factories. Connections are cached per name for the lifetime of the returned
|
|
98
|
+
* object. Call close() to shut down all cached connections.
|
|
99
|
+
*
|
|
100
|
+
* @param onConnectionCreated Optional callback invoked once per connection
|
|
101
|
+
* immediately after factory creation. Use this for post-creation setup
|
|
102
|
+
* (e.g., registering WASM file handlers).
|
|
97
103
|
*/
|
|
98
|
-
function createConnectionsFromConfig(config) {
|
|
104
|
+
function createConnectionsFromConfig(config, onConnectionCreated) {
|
|
99
105
|
const entries = Object.entries(config.connections);
|
|
100
106
|
const firstConnectionName = entries.length > 0 ? entries[0][0] : undefined;
|
|
101
107
|
const cache = new Map();
|
|
@@ -137,9 +143,19 @@ function createConnectionsFromConfig(config) {
|
|
|
137
143
|
}
|
|
138
144
|
}
|
|
139
145
|
const connection = await typeDef.factory(connConfig);
|
|
146
|
+
if (onConnectionCreated) {
|
|
147
|
+
onConnectionCreated(connectionName, connection);
|
|
148
|
+
}
|
|
140
149
|
cache.set(connectionName, connection);
|
|
141
150
|
return connection;
|
|
142
151
|
},
|
|
152
|
+
async close() {
|
|
153
|
+
const connections = [...cache.values()];
|
|
154
|
+
cache.clear();
|
|
155
|
+
for (const conn of connections) {
|
|
156
|
+
await conn.close();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
143
159
|
};
|
|
144
160
|
}
|
|
145
161
|
//# sourceMappingURL=registry.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, Sorta
|
|
|
9
9
|
export type { QueryOptionsReader, RunSQLOptions } from './run_sql_options';
|
|
10
10
|
export type { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLReader, InvalidationKey, } from './runtime_types';
|
|
11
11
|
export type { Connection, ConnectionConfig, ConnectionParameterValue, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
|
|
12
|
-
export { registerConnectionType, getConnectionProperties, getConnectionTypeDisplayName, getRegisteredConnectionTypes, isValueRef, resolveValue, } from './connection/registry';
|
|
13
|
-
export type { ConnectionTypeFactory, ConnectionPropertyType, ConnectionPropertyDefinition, ConnectionTypeDef, ConnectionConfigEntry, ConnectionsConfig, ConfigValue, JsonConfigValue, ValueRef, } from './connection/registry';
|
|
12
|
+
export { registerConnectionType, getConnectionProperties, getConnectionTypeDisplayName, getRegisteredConnectionTypes, createConnectionsFromConfig, isValueRef, resolveValue, } from './connection/registry';
|
|
13
|
+
export type { ConnectionTypeFactory, ConnectionPropertyType, ConnectionPropertyDefinition, ConnectionTypeDef, ConnectionConfigEntry, ConnectionsConfig, ConfigValue, JsonConfigValue, ValueRef, ManagedConnectionLookup, } from './connection/registry';
|
|
14
14
|
export { toAsyncGenerator } from './connection_utils';
|
|
15
15
|
export { modelDefToModelInfo, sourceDefToSourceInfo } from './to_stable';
|
|
16
16
|
export * as API from './api';
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Malloy = exports.Model = exports.MalloyTranslator = exports.malloyToQuery = exports.constantExprToSQL = exports.isDateUnit = exports.isTimestampUnit = exports.composeSQLExpr = exports.indent = exports.expressionIsUngroupedAggregate = exports.expressionIsScalar = exports.expressionIsCalculation = exports.expressionIsAnalytic = exports.expressionIsAggregate = exports.mkFieldDef = exports.mkArrayDef = exports.isBasicArray = exports.isRepeatedRecord = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoined = exports.isCompoundArrayData = exports.isBasicAtomic = exports.isAtomic = exports.isSourceDef = exports.TinyParser = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.DatabricksDialect = exports.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
|
|
37
|
-
exports.makeDigest = exports.EMPTY_BUILD_MANIFEST = exports.PersistSource = exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = exports.sourceDefToSourceInfo = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.resolveValue = exports.isValueRef = exports.getRegisteredConnectionTypes = exports.getConnectionTypeDisplayName = exports.getConnectionProperties = exports.registerConnectionType = exports.MalloyConfig = exports.Manifest = exports.CacheManager = exports.InMemoryModelCache = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = void 0;
|
|
37
|
+
exports.makeDigest = exports.EMPTY_BUILD_MANIFEST = exports.PersistSource = exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = exports.sourceDefToSourceInfo = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.resolveValue = exports.isValueRef = exports.createConnectionsFromConfig = exports.getRegisteredConnectionTypes = exports.getConnectionTypeDisplayName = exports.getConnectionProperties = exports.registerConnectionType = exports.MalloyConfig = exports.Manifest = exports.CacheManager = exports.InMemoryModelCache = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = void 0;
|
|
38
38
|
/*
|
|
39
39
|
* Copyright 2023 Google LLC
|
|
40
40
|
*
|
|
@@ -143,6 +143,7 @@ Object.defineProperty(exports, "registerConnectionType", { enumerable: true, get
|
|
|
143
143
|
Object.defineProperty(exports, "getConnectionProperties", { enumerable: true, get: function () { return registry_1.getConnectionProperties; } });
|
|
144
144
|
Object.defineProperty(exports, "getConnectionTypeDisplayName", { enumerable: true, get: function () { return registry_1.getConnectionTypeDisplayName; } });
|
|
145
145
|
Object.defineProperty(exports, "getRegisteredConnectionTypes", { enumerable: true, get: function () { return registry_1.getRegisteredConnectionTypes; } });
|
|
146
|
+
Object.defineProperty(exports, "createConnectionsFromConfig", { enumerable: true, get: function () { return registry_1.createConnectionsFromConfig; } });
|
|
146
147
|
Object.defineProperty(exports, "isValueRef", { enumerable: true, get: function () { return registry_1.isValueRef; } });
|
|
147
148
|
Object.defineProperty(exports, "resolveValue", { enumerable: true, get: function () { return registry_1.resolveValue; } });
|
|
148
149
|
var connection_utils_1 = require("./connection_utils");
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.365";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.365';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.365",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@malloydata/malloy-filter": "0.0.
|
|
51
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
52
|
-
"@malloydata/malloy-tag": "0.0.
|
|
50
|
+
"@malloydata/malloy-filter": "0.0.365",
|
|
51
|
+
"@malloydata/malloy-interfaces": "0.0.365",
|
|
52
|
+
"@malloydata/malloy-tag": "0.0.365",
|
|
53
53
|
"@noble/hashes": "^1.8.0",
|
|
54
54
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
55
55
|
"assert": "^2.0.0",
|