@malloydata/malloy 0.0.336 → 0.0.337

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,5 +1,6 @@
1
1
  import type { LogMessage } from '../../lang';
2
2
  import type { Connection, InfoConnection, LookupConnection, FetchSchemaOptions } from '../../connection/types';
3
+ import type { ConnectionTypeDef, ConnectionPropertyDefinition, ConnectionsConfig } from '../../connection/registry';
3
4
  import type { URLReader, EventStream } from '../../runtime_types';
4
5
  import type { SQLSourceDef, QueryRunStats } from '../../model';
5
6
  import type { RunSQLOptions } from '../../run_sql_options';
@@ -55,6 +56,31 @@ export declare class MalloyError extends Error {
55
56
  }
56
57
  export declare class Malloy {
57
58
  static get version(): string;
59
+ /**
60
+ * Register a connection type with the global registry.
61
+ * Typically called by db-* packages on import as a side effect.
62
+ */
63
+ static registerConnectionType(typeName: string, def: ConnectionTypeDef): void;
64
+ /**
65
+ * Get the property definitions for a registered connection type.
66
+ */
67
+ static getConnectionProperties(typeName: string): ConnectionPropertyDefinition[] | undefined;
68
+ /**
69
+ * Get the names of all registered connection types.
70
+ */
71
+ static getRegisteredConnectionTypes(): string[];
72
+ /**
73
+ * Parse a JSON config string into an editable ConnectionsConfig.
74
+ */
75
+ static readConnectionsConfig(jsonText: string): ConnectionsConfig;
76
+ /**
77
+ * Serialize a ConnectionsConfig to a JSON string.
78
+ */
79
+ static writeConnectionsConfig(config: ConnectionsConfig): string;
80
+ /**
81
+ * Create a LookupConnection from a ConnectionsConfig using registered factories.
82
+ */
83
+ static createConnectionsFromConfig(config: ConnectionsConfig): LookupConnection<Connection>;
58
84
  private static _parse;
59
85
  /**
60
86
  * Parse a Malloy document by URL.
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Malloy = exports.MalloyError = void 0;
8
8
  const lang_1 = require("../../lang");
9
+ const registry_1 = require("../../connection/registry");
9
10
  const model_1 = require("../../model");
10
11
  const sql_block_1 = require("../../model/sql_block");
11
12
  const version_1 = require("../../version");
@@ -43,6 +44,43 @@ class Malloy {
43
44
  static get version() {
44
45
  return version_1.MALLOY_VERSION;
45
46
  }
47
+ /**
48
+ * Register a connection type with the global registry.
49
+ * Typically called by db-* packages on import as a side effect.
50
+ */
51
+ static registerConnectionType(typeName, def) {
52
+ (0, registry_1.registerConnectionType)(typeName, def);
53
+ }
54
+ /**
55
+ * Get the property definitions for a registered connection type.
56
+ */
57
+ static getConnectionProperties(typeName) {
58
+ return (0, registry_1.getConnectionProperties)(typeName);
59
+ }
60
+ /**
61
+ * Get the names of all registered connection types.
62
+ */
63
+ static getRegisteredConnectionTypes() {
64
+ return (0, registry_1.getRegisteredConnectionTypes)();
65
+ }
66
+ /**
67
+ * Parse a JSON config string into an editable ConnectionsConfig.
68
+ */
69
+ static readConnectionsConfig(jsonText) {
70
+ return (0, registry_1.readConnectionsConfig)(jsonText);
71
+ }
72
+ /**
73
+ * Serialize a ConnectionsConfig to a JSON string.
74
+ */
75
+ static writeConnectionsConfig(config) {
76
+ return (0, registry_1.writeConnectionsConfig)(config);
77
+ }
78
+ /**
79
+ * Create a LookupConnection from a ConnectionsConfig using registered factories.
80
+ */
81
+ static createConnectionsFromConfig(config) {
82
+ return (0, registry_1.createConnectionsFromConfig)(config);
83
+ }
46
84
  static _parse(source, url, eventStream, options, invalidationKey) {
47
85
  if (url === undefined) {
48
86
  url = new URL(MALLOY_INTERNAL_URL);
@@ -1,2 +1,3 @@
1
1
  export * from './types';
2
2
  export * from './base_connection';
3
+ export * from './registry';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./base_connection"), exports);
19
+ __exportStar(require("./registry"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,73 @@
1
+ import type { Connection, ConnectionConfig, LookupConnection } from './types';
2
+ /**
3
+ * A factory function that creates a Connection from a config object.
4
+ */
5
+ export type ConnectionTypeFactory = (config: ConnectionConfig) => Connection;
6
+ /**
7
+ * The type of a connection property value.
8
+ */
9
+ export type ConnectionPropertyType = 'string' | 'number' | 'boolean' | 'password' | 'file';
10
+ /**
11
+ * Describes a single configuration property for a connection type.
12
+ */
13
+ export interface ConnectionPropertyDefinition {
14
+ name: string;
15
+ displayName: string;
16
+ type: ConnectionPropertyType;
17
+ optional?: true;
18
+ default?: string;
19
+ description?: string;
20
+ /** For type 'file': extension filters for picker dialogs. */
21
+ fileFilters?: Record<string, string[]>;
22
+ }
23
+ /**
24
+ * A connection type definition: factory plus property metadata.
25
+ */
26
+ export interface ConnectionTypeDef {
27
+ factory: ConnectionTypeFactory;
28
+ properties: ConnectionPropertyDefinition[];
29
+ }
30
+ /**
31
+ * A single connection entry in a JSON config.
32
+ */
33
+ export interface ConnectionConfigEntry {
34
+ is: string;
35
+ [key: string]: string | number | boolean | undefined;
36
+ }
37
+ /**
38
+ * The editable intermediate representation of a connections config file.
39
+ */
40
+ export interface ConnectionsConfig {
41
+ connections: Record<string, ConnectionConfigEntry>;
42
+ }
43
+ /**
44
+ * Register a connection type with its factory and property definitions.
45
+ *
46
+ * @param typeName The connection type name (e.g. "duckdb", "bigquery").
47
+ * @param def The connection type definition (factory + properties).
48
+ */
49
+ export declare function registerConnectionType(typeName: string, def: ConnectionTypeDef): void;
50
+ /**
51
+ * Get the property definitions for a registered connection type.
52
+ *
53
+ * @param typeName The connection type name.
54
+ * @returns The property definitions, or undefined if the type is not registered.
55
+ */
56
+ export declare function getConnectionProperties(typeName: string): ConnectionPropertyDefinition[] | undefined;
57
+ /**
58
+ * Get the names of all registered connection types.
59
+ */
60
+ export declare function getRegisteredConnectionTypes(): string[];
61
+ /**
62
+ * Parse a JSON config string into a ConnectionsConfig.
63
+ * Validates that each connection entry has an `is` field.
64
+ */
65
+ export declare function readConnectionsConfig(jsonText: string): ConnectionsConfig;
66
+ /**
67
+ * Serialize a ConnectionsConfig to a JSON string with 2-space indent.
68
+ */
69
+ export declare function writeConnectionsConfig(config: ConnectionsConfig): string;
70
+ /**
71
+ * Create a LookupConnection from a ConnectionsConfig using registered factories.
72
+ */
73
+ export declare function createConnectionsFromConfig(config: ConnectionsConfig): LookupConnection<Connection>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.registerConnectionType = registerConnectionType;
8
+ exports.getConnectionProperties = getConnectionProperties;
9
+ exports.getRegisteredConnectionTypes = getRegisteredConnectionTypes;
10
+ exports.readConnectionsConfig = readConnectionsConfig;
11
+ exports.writeConnectionsConfig = writeConnectionsConfig;
12
+ exports.createConnectionsFromConfig = createConnectionsFromConfig;
13
+ // Module-level registry
14
+ const registry = new Map();
15
+ /**
16
+ * Register a connection type with its factory and property definitions.
17
+ *
18
+ * @param typeName The connection type name (e.g. "duckdb", "bigquery").
19
+ * @param def The connection type definition (factory + properties).
20
+ */
21
+ function registerConnectionType(typeName, def) {
22
+ registry.set(typeName, def);
23
+ }
24
+ /**
25
+ * Get the property definitions for a registered connection type.
26
+ *
27
+ * @param typeName The connection type name.
28
+ * @returns The property definitions, or undefined if the type is not registered.
29
+ */
30
+ function getConnectionProperties(typeName) {
31
+ var _a;
32
+ return (_a = registry.get(typeName)) === null || _a === void 0 ? void 0 : _a.properties;
33
+ }
34
+ /**
35
+ * Get the names of all registered connection types.
36
+ */
37
+ function getRegisteredConnectionTypes() {
38
+ return [...registry.keys()];
39
+ }
40
+ /**
41
+ * Parse a JSON config string into a ConnectionsConfig.
42
+ * Validates that each connection entry has an `is` field.
43
+ */
44
+ function readConnectionsConfig(jsonText) {
45
+ const parsed = JSON.parse(jsonText);
46
+ const connections = parsed.connections;
47
+ if (connections === undefined || typeof connections !== 'object') {
48
+ throw new Error('Invalid connections config: missing "connections" object');
49
+ }
50
+ for (const [name, entry] of Object.entries(connections)) {
51
+ if (typeof entry !== 'object' ||
52
+ entry === null ||
53
+ !entry.is) {
54
+ throw new Error(`Connection "${name}" is missing required "is" property`);
55
+ }
56
+ }
57
+ return parsed;
58
+ }
59
+ /**
60
+ * Serialize a ConnectionsConfig to a JSON string with 2-space indent.
61
+ */
62
+ function writeConnectionsConfig(config) {
63
+ return JSON.stringify(config, null, 2);
64
+ }
65
+ /**
66
+ * Create a LookupConnection from a ConnectionsConfig using registered factories.
67
+ */
68
+ function createConnectionsFromConfig(config) {
69
+ const entries = Object.entries(config.connections);
70
+ const firstConnectionName = entries.length > 0 ? entries[0][0] : undefined;
71
+ const cache = new Map();
72
+ return {
73
+ async lookupConnection(connectionName) {
74
+ if (connectionName === undefined) {
75
+ connectionName = firstConnectionName;
76
+ }
77
+ if (connectionName === undefined) {
78
+ throw new Error('No connections defined in config');
79
+ }
80
+ const cached = cache.get(connectionName);
81
+ if (cached)
82
+ return cached;
83
+ const entry = config.connections[connectionName];
84
+ if (!entry) {
85
+ throw new Error(`No connection named "${connectionName}" found in config`);
86
+ }
87
+ const typeDef = registry.get(entry.is);
88
+ if (!typeDef) {
89
+ throw new Error(`No registered connection type "${entry.is}" for connection "${connectionName}". ` +
90
+ 'Did you forget to import the connection package?');
91
+ }
92
+ const connConfig = { name: connectionName };
93
+ for (const [key, value] of Object.entries(entry)) {
94
+ if (key === 'is')
95
+ continue;
96
+ if (value !== undefined) {
97
+ connConfig[key] = value;
98
+ }
99
+ }
100
+ const connection = typeDef.factory(connConfig);
101
+ cache.set(connectionName, connection);
102
+ return connection;
103
+ },
104
+ };
105
+ }
106
+ //# sourceMappingURL=registry.js.map
@@ -1,6 +1,5 @@
1
1
  import type { RunSQLOptions } from '../run_sql_options';
2
2
  import type { Annotation, MalloyQueryData, QueryDataRow, QueryRunStats, SQLSourceDef, TableSourceDef } from '../model/malloy_types';
3
- import type { Dialect } from '../dialect';
4
3
  import type { SQLSourceRequest } from '../lang/translate-response';
5
4
  /**
6
5
  * Options passed to fetchSchema methods.
@@ -49,24 +48,10 @@ export interface InfoConnection {
49
48
  getDigest(): string;
50
49
  }
51
50
  export type ConnectionParameterValue = string | number | boolean | Array<ConnectionParameterValue>;
52
- export interface ConnectionParameter {
53
- name: string;
54
- label: string;
55
- type: 'string' | 'number' | 'boolean';
56
- isOptional?: boolean;
57
- isSecret?: boolean;
58
- defaultValue?: ConnectionParameterValue;
59
- }
60
- export type ConnectionConfigSchema = ConnectionParameter[];
61
51
  export interface ConnectionConfig {
62
52
  name: string;
63
53
  [key: string]: ConnectionParameterValue | undefined;
64
54
  }
65
- export interface ConnectionFactory {
66
- connectionName: string;
67
- configSchema: ConnectionConfigSchema;
68
- createConnection(connectionConfig: ConnectionConfig, dialectRegistrar?: (dialect: Dialect) => void): Connection & TestableConnection;
69
- }
70
55
  export interface ConnectionMetadata {
71
56
  url?: string;
72
57
  }
package/dist/index.d.ts CHANGED
@@ -8,7 +8,9 @@ export { Model, Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConne
8
8
  export type { PreparedQuery, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, Loggable, ModelMaterializer, DocumentTablePath, DocumentSymbol, ResultJSON, PreparedResultJSON, PreparedResultMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, ModelCache, CachedModel, DateField, TimestampField, } from './api/foundation';
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
- export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
11
+ export type { Connection, ConnectionConfig, ConnectionParameterValue, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
12
+ export { registerConnectionType, getConnectionProperties, getRegisteredConnectionTypes, readConnectionsConfig, writeConnectionsConfig, createConnectionsFromConfig, } from './connection/registry';
13
+ export type { ConnectionTypeFactory, ConnectionPropertyType, ConnectionPropertyDefinition, ConnectionTypeDef, ConnectionConfigEntry, ConnectionsConfig, } from './connection/registry';
12
14
  export { toAsyncGenerator } from './connection_utils';
13
15
  export { modelDefToModelInfo, sourceDefToSourceInfo, writeMalloyObjectToTag, extractMalloyObjectFromTag, } from './to_stable';
14
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.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = 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.isBasicAtomic = 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.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
37
- exports.makeDigest = exports.PersistSource = exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = exports.extractMalloyObjectFromTag = exports.writeMalloyObjectToTag = exports.sourceDefToSourceInfo = exports.modelDefToModelInfo = exports.toAsyncGenerator = 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 = void 0;
37
+ exports.makeDigest = exports.PersistSource = exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = exports.extractMalloyObjectFromTag = exports.writeMalloyObjectToTag = exports.sourceDefToSourceInfo = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.createConnectionsFromConfig = exports.writeConnectionsConfig = exports.readConnectionsConfig = exports.getRegisteredConnectionTypes = exports.getConnectionProperties = exports.registerConnectionType = 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 = void 0;
38
38
  /*
39
39
  * Copyright 2023 Google LLC
40
40
  *
@@ -133,6 +133,13 @@ Object.defineProperty(exports, "DataWriter", { enumerable: true, get: function (
133
133
  Object.defineProperty(exports, "Explore", { enumerable: true, get: function () { return foundation_1.Explore; } });
134
134
  Object.defineProperty(exports, "InMemoryModelCache", { enumerable: true, get: function () { return foundation_1.InMemoryModelCache; } });
135
135
  Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return foundation_1.CacheManager; } });
136
+ var registry_1 = require("./connection/registry");
137
+ Object.defineProperty(exports, "registerConnectionType", { enumerable: true, get: function () { return registry_1.registerConnectionType; } });
138
+ Object.defineProperty(exports, "getConnectionProperties", { enumerable: true, get: function () { return registry_1.getConnectionProperties; } });
139
+ Object.defineProperty(exports, "getRegisteredConnectionTypes", { enumerable: true, get: function () { return registry_1.getRegisteredConnectionTypes; } });
140
+ Object.defineProperty(exports, "readConnectionsConfig", { enumerable: true, get: function () { return registry_1.readConnectionsConfig; } });
141
+ Object.defineProperty(exports, "writeConnectionsConfig", { enumerable: true, get: function () { return registry_1.writeConnectionsConfig; } });
142
+ Object.defineProperty(exports, "createConnectionsFromConfig", { enumerable: true, get: function () { return registry_1.createConnectionsFromConfig; } });
136
143
  var connection_utils_1 = require("./connection_utils");
137
144
  Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
138
145
  var to_stable_1 = require("./to_stable");
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.336";
1
+ export declare const MALLOY_VERSION = "0.0.337";
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.336';
5
+ exports.MALLOY_VERSION = '0.0.337';
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.336",
3
+ "version": "0.0.337",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -45,9 +45,9 @@
45
45
  "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"
46
46
  },
47
47
  "dependencies": {
48
- "@malloydata/malloy-filter": "0.0.336",
49
- "@malloydata/malloy-interfaces": "0.0.336",
50
- "@malloydata/malloy-tag": "0.0.336",
48
+ "@malloydata/malloy-filter": "0.0.337",
49
+ "@malloydata/malloy-interfaces": "0.0.337",
50
+ "@malloydata/malloy-tag": "0.0.337",
51
51
  "antlr4ts": "^0.5.0-alpha.4",
52
52
  "assert": "^2.0.0",
53
53
  "blueimp-md5": "^2.19.0",