@malloydata/malloy 0.0.372 → 0.0.373

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.
@@ -1,51 +1,37 @@
1
- import type { URLReader } from '../../runtime_types';
2
1
  import type { Connection, LookupConnection } from '../../connection/types';
3
- import type { ConnectionConfigEntry } from '../../connection/registry';
4
2
  import type { LogMessage } from '../../lang/parse-log';
5
3
  import type { BuildID, BuildManifest, BuildManifestEntry, VirtualMap } from '../../model/malloy_types';
6
- /**
7
- * The parsed contents of a malloy-config.json file.
8
- */
9
- export interface MalloyProjectConfig {
10
- connections?: Record<string, ConnectionConfigEntry>;
11
- manifestPath?: string;
12
- virtualMap?: VirtualMap;
13
- }
4
+ import type { ConfigOverlays } from './config_overlays';
14
5
  /**
15
6
  * In-memory manifest store. Reads, updates, and serializes manifest data.
16
7
  *
17
- * Always valid — starts empty, call load() to populate from a file.
18
- * The BuildManifest object returned by `buildManifest` is stable: load()
19
- * and update() mutate the same entries object, so any reference obtained
20
- * via `buildManifest` stays current without re-assignment.
8
+ * Always valid — starts empty. Populate by calling `loadText(jsonText)` with
9
+ * the manifest file contents, which the caller reads themselves (typically
10
+ * through a `URLReader` they already have). The `Manifest` class deliberately
11
+ * does no IO it exists so that applications that want to build or mutate
12
+ * manifest state have a typed handle with a stable `buildManifest` reference.
21
13
  *
22
- * The `strict` flag controls what happens when a persist source's BuildID
23
- * is not found in the manifest. When strict, the compiler throws an error
24
- * instead of falling through to inline SQL. The flag is loaded from the
25
- * manifest file and can be overridden by the application before creating
26
- * a Runtime.
14
+ * The `BuildManifest` returned by `buildManifest` is stable: `loadText()` and
15
+ * `update()` mutate the same entries object, so any reference obtained via
16
+ * `buildManifest` stays current without re-assignment.
17
+ *
18
+ * The `strict` flag controls what happens when a persist source's BuildID is
19
+ * not found in the manifest. When strict, the compiler throws an error
20
+ * instead of falling through to inline SQL. Loaded from the manifest file by
21
+ * `loadText()`; applications may override it at any time.
27
22
  */
28
23
  export declare class Manifest {
29
- private readonly _urlReader?;
30
24
  private readonly _manifest;
31
25
  private readonly _touched;
32
- constructor(urlReader?: URLReader);
33
- /**
34
- * Load manifest data from a manifest root directory.
35
- * Reads `<manifestRoot>/malloy-manifest.json` via the URLReader.
36
- * Replaces any existing data. If the file doesn't exist or no URLReader
37
- * is available, clears to empty.
38
- */
39
- load(manifestRoot: URL): Promise<void>;
40
26
  /**
41
27
  * Load manifest data from a JSON string.
42
28
  * Replaces any existing data.
43
29
  */
44
30
  loadText(jsonText: string): void;
45
31
  /**
46
- * The live BuildManifest. This is a stable reference — load() and update()
47
- * mutate the same object, so passing this to a Runtime means the Runtime
48
- * always sees current data including the strict flag.
32
+ * The live BuildManifest. This is a stable reference — `loadText()` and
33
+ * `update()` mutate the same object, so passing this to a Runtime means
34
+ * the Runtime always sees current data including the strict flag.
49
35
  */
50
36
  get buildManifest(): BuildManifest;
51
37
  /**
@@ -73,97 +59,112 @@ export declare class Manifest {
73
59
  private _loadParsed;
74
60
  }
75
61
  /**
76
- * Loads and holds a Malloy project configuration (connections + manifest +
77
- * virtualMap). Pass directly to Runtime everything flows automatically.
62
+ * A resolved Malloy runtime configuration. The constructor takes either a
63
+ * JSON string (legacy/compat) or a POJO plus an optional `ConfigOverlays`
64
+ * dict, compiles the input into a typed tree, resolves all overlay
65
+ * references, and builds the connection lookup via the connection registry.
78
66
  *
79
- * // From a URL — reads config + manifest via URLReader
80
- * const config = new MalloyConfig(urlReader, configURL);
81
- * await config.load();
67
+ * After construction:
68
+ * - `connections` the `LookupConnection` runtime consumes. Starts as the
69
+ * lookup created from the resolved connections; `wrapConnections()` replaces
70
+ * it with a wrapped version for host-specific behavior.
71
+ * - `virtualMap` — extracted from the POJO as-is.
72
+ * - `manifestPath` — extracted from the POJO as-is (the raw string).
73
+ * - `manifestURL` — resolved URL of `malloy-manifest.json`, computed from
74
+ * `manifestPath` + the `configURL` carried on the `config` overlay (if
75
+ * any). `undefined` when no `configURL` is available. Runtime uses this
76
+ * to lazily read the manifest on the first persistence query. Builders
77
+ * that want to construct or mutate manifest state use the standalone
78
+ * `Manifest` class directly — they don't go through MalloyConfig.
79
+ * - `log` — validation warnings and overlay-resolution warnings.
82
80
  *
83
- * // From text you already have
84
- * const config = new MalloyConfig(configText);
81
+ * Typical usage:
85
82
  *
86
- * // Either way, pass to Runtime connections, buildManifest, virtualMap
87
- * // all come from the config. No manual wiring needed.
83
+ * // From a pre-loaded POJO (e.g. from `discoverConfig` or Publisher):
84
+ * const config = new MalloyConfig(pojo);
88
85
  * const runtime = new Runtime({config, urlReader});
89
86
  *
90
- * To override specific fields, mutate the config before passing:
91
- * config.connectionMap = myCustomConnections;
87
+ * // From a JSON string:
88
+ * const config = new MalloyConfig(configText);
89
+ *
90
+ * // With host-supplied overlays (local hosts after discovery):
91
+ * const config = new MalloyConfig(pojo, {
92
+ * config: contextOverlay({rootDirectory: ceilingURL}),
93
+ * });
94
+ *
95
+ * // Wrap the connection lookup for host-specific behavior:
96
+ * config.wrapConnections(base => name => base(name) ?? fallback(name));
97
+ *
98
+ * The old async `new MalloyConfig(urlReader, configURL)` form has been
99
+ * removed. Callers that need to load from a URL should pre-load via
100
+ * `urlReader.readURL()` / `JSON.parse()` and pass the POJO, or use the
101
+ * sync string form after reading the file.
92
102
  */
93
103
  export declare class MalloyConfig {
94
- private readonly _urlReader?;
95
- private readonly _configURL?;
96
- private _data;
97
- private _log;
98
- private _connectionMap;
99
- private readonly _manifest;
100
- private _managedLookup;
101
- private _connectionLookupOverride;
102
- private _onConnectionCreated;
103
- constructor(configText: string);
104
- constructor(urlReader: URLReader, configURL: string);
105
- /**
106
- * Load everything: parse config file, then load the default manifest.
107
- * No-op if created from text.
108
- */
109
- load(): Promise<void>;
110
- /**
111
- * Load only the config file. Does not load the manifest.
112
- * No-op if created from text.
113
- */
114
- loadConfig(): Promise<void>;
115
- /**
116
- * The parsed config data. Undefined if created from URL and not yet loaded.
104
+ readonly virtualMap?: VirtualMap;
105
+ readonly manifestPath?: string;
106
+ /**
107
+ * Resolved URL of the manifest file (`malloy-manifest.json`), if a
108
+ * `configURL` was provided in the `config` overlay. Computed once in the
109
+ * constructor from `manifestPath` (default `'MANIFESTS'`) joined to
110
+ * `configURL`. Stays `undefined` for callers that didn't supply a
111
+ * `configURL` — Runtime treats that as "no auto-read."
112
+ */
113
+ readonly manifestURL?: URL;
114
+ readonly log: readonly LogMessage[];
115
+ private _connections;
116
+ private readonly _managedLookup;
117
+ private readonly _overlays;
118
+ constructor(source: string);
119
+ constructor(pojo: object, overlays?: ConfigOverlays);
120
+ /**
121
+ * The live `LookupConnection` consumed by Runtime. Stable until
122
+ * `wrapConnections()` is called; after that, returns the wrapped lookup.
117
123
  */
118
- get data(): MalloyProjectConfig | undefined;
124
+ get connections(): LookupConnection<Connection>;
119
125
  /**
120
- * The active connection entries. Set this to override which connections
121
- * are used before constructing a Runtime.
126
+ * Wrap the current connection lookup with a host-supplied wrapper.
127
+ * Mutates in place subsequent `connections` accesses return the new
128
+ * wrapped lookup. Runtime never needs to know whether wrapping happened.
129
+ *
130
+ * Typical uses:
131
+ * - VS Code layers settings + defaults below the config lookup
132
+ * - Publisher attaches session-specific behavior to resolved connections
122
133
  */
123
- get connectionMap(): Record<string, ConnectionConfigEntry> | undefined;
124
- set connectionMap(map: Record<string, ConnectionConfigEntry>);
134
+ wrapConnections(wrapper: (base: LookupConnection<Connection>) => LookupConnection<Connection>): void;
125
135
  /**
126
- * A LookupConnection built from the current connectionMap via the
127
- * connection type registry. The result is cached repeated access
128
- * returns the same object (and the same underlying connections).
136
+ * Notify every connection this config has handed out that it is time to
137
+ * release its resources, then drop them from the internal cache.
129
138
  *
130
- * If `connectionLookup` has been set, returns the override instead.
139
+ * Most callers should use `Runtime.releaseConnections()` instead the
140
+ * expected contract is one MalloyConfig per Runtime, and the runtime is
141
+ * the natural handle for lifecycle. This method exists because Runtime
142
+ * forwards to it, and for the rare case of a MalloyConfig constructed
143
+ * without an accompanying Runtime.
131
144
  *
132
- * Changing `connectionMap` invalidates the cache; the next access
133
- * creates a fresh ManagedConnectionLookup.
134
- */
135
- get connections(): LookupConnection<Connection>;
136
- /**
137
- * Override the connection lookup entirely. When set, the `connections`
138
- * getter returns this instead of building from `connectionMap`.
139
- * Use this when you need to merge config connections with other sources.
140
- */
141
- get connectionLookup(): LookupConnection<Connection> | undefined;
142
- set connectionLookup(lookup: LookupConnection<Connection> | undefined);
143
- /**
144
- * Callback invoked once per connection immediately after factory creation.
145
- * Use for post-creation setup (e.g., registering WASM file handlers).
146
- * Must be set before the first connection is looked up.
147
- */
148
- set onConnectionCreated(cb: ((name: string, connection: Connection) => void) | undefined);
149
- /**
150
- * Close all connections created by this config's internal managed lookup.
151
- * Does nothing if connections were overridden via `connectionLookup`.
152
- */
153
- close(): Promise<void>;
154
- /**
155
- * The Manifest object. Always exists, may be empty if not yet loaded.
156
- */
157
- get manifest(): Manifest;
158
- /**
159
- * The VirtualMap parsed from config, if present.
145
+ * MalloyConfig does not own any connection resources itself — pools,
146
+ * sockets, file handles, and in-process databases all live inside the
147
+ * individual Connection objects. What the managed lookup owns is a cache
148
+ * of `name → Connection` populated lazily as callers request connections.
149
+ * This method walks that cache and calls `Connection.close()` on each
150
+ * entry, which is the signal each connection uses to shut down whatever
151
+ * resources it actually holds.
152
+ *
153
+ * Connections that were never looked up were never constructed and have
154
+ * nothing to release; they are skipped. Wrapping lookups installed via
155
+ * `wrapConnections()` do not interfere — the managed lookup under the
156
+ * wrap is the one holding the cache.
160
157
  */
161
- get virtualMap(): VirtualMap | undefined;
158
+ releaseConnections(): Promise<void>;
162
159
  /**
163
- * Errors and warnings from parsing and validating the config.
164
- * Includes JSON parse errors (severity 'error') and schema validation
165
- * warnings (severity 'warn') such as unknown keys, unknown connection
166
- * types, wrong value types, and missing environment variables.
160
+ * Query a value from the overlays used to resolve this config.
161
+ *
162
+ * Returns the value the named overlay produces for the given path,
163
+ * or `undefined` if the overlay doesn't exist or the path has no value.
164
+ *
165
+ * config.readOverlay('config', 'rootDirectory')
166
+ * config.readOverlay('config', 'configURL')
167
+ * config.readOverlay('env', 'PG_PASSWORD')
167
168
  */
168
- get log(): LogMessage[];
169
+ readOverlay(overlayName: string, ...path: string[]): unknown;
169
170
  }