@malloydata/malloy 0.0.335 → 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.
- package/CONTEXT.md +4 -3
- package/MALLOY_API.md +129 -0
- package/dist/annotation.d.ts +0 -2
- package/dist/annotation.js +29 -23
- package/dist/api/asynchronous.d.ts +1 -1
- package/dist/api/foundation/cache.d.ts +32 -0
- package/dist/api/foundation/cache.js +92 -0
- package/dist/api/foundation/compile.d.ts +201 -0
- package/dist/api/foundation/compile.js +429 -0
- package/dist/api/foundation/core.d.ts +493 -0
- package/dist/api/foundation/core.js +1247 -0
- package/dist/api/foundation/document.d.ts +167 -0
- package/dist/api/foundation/document.js +206 -0
- package/dist/api/foundation/index.d.ts +10 -0
- package/dist/api/foundation/index.js +77 -0
- package/dist/api/foundation/readers.d.ts +53 -0
- package/dist/api/foundation/readers.js +134 -0
- package/dist/api/foundation/result.d.ts +185 -0
- package/dist/api/foundation/result.js +704 -0
- package/dist/api/foundation/runtime.d.ts +361 -0
- package/dist/api/foundation/runtime.js +733 -0
- package/dist/api/foundation/types.d.ts +54 -0
- package/dist/api/foundation/types.js +7 -0
- package/dist/api/foundation/writers.d.ts +42 -0
- package/dist/api/foundation/writers.js +230 -0
- package/dist/api/util.d.ts +1 -1
- package/dist/connection/base_connection.d.ts +5 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/connection/index.js +1 -0
- package/dist/connection/registry.d.ts +73 -0
- package/dist/connection/registry.js +106 -0
- package/dist/connection/types.d.ts +5 -15
- package/dist/dialect/duckdb/duckdb.js +2 -1
- package/dist/dialect/snowflake/snowflake.js +7 -1
- package/dist/dialect/trino/trino.js +7 -2
- package/dist/index.d.ts +9 -4
- package/dist/index.js +37 -26
- package/dist/lang/ast/error-factory.js +3 -5
- package/dist/lang/ast/source-elements/query-source.js +2 -7
- package/dist/lang/ast/source-elements/refined-source.js +11 -1
- package/dist/lang/ast/source-elements/sql-source.d.ts +1 -1
- package/dist/lang/ast/source-elements/sql-source.js +18 -3
- package/dist/lang/ast/sql-elements/sql-string.d.ts +2 -2
- package/dist/lang/ast/sql-elements/sql-string.js +18 -1
- package/dist/lang/ast/statements/define-source.js +7 -2
- package/dist/lang/ast/statements/import-statement.js +53 -21
- package/dist/lang/ast/types/document-compile-result.d.ts +1 -0
- package/dist/lang/ast/types/malloy-element.d.ts +3 -1
- package/dist/lang/ast/types/malloy-element.js +23 -7
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +1 -1
- package/dist/lang/parse-malloy.d.ts +3 -2
- package/dist/lang/parse-malloy.js +14 -25
- package/dist/lang/test/test-translator.js +1 -0
- package/dist/lang/translate-response.d.ts +1 -0
- package/dist/model/constant_expression_compiler.js +6 -7
- package/dist/model/index.d.ts +3 -1
- package/dist/model/index.js +15 -9
- package/dist/model/malloy_types.d.ts +89 -15
- package/dist/model/malloy_types.js +12 -0
- package/dist/model/persist_utils.d.ts +47 -0
- package/dist/model/persist_utils.js +257 -0
- package/dist/model/query_model_impl.d.ts +2 -4
- package/dist/model/query_model_impl.js +5 -13
- package/dist/model/query_node.d.ts +1 -2
- package/dist/model/query_node.js +3 -13
- package/dist/model/query_query.d.ts +17 -1
- package/dist/model/query_query.js +81 -36
- package/dist/model/source_def_utils.d.ts +50 -0
- package/dist/model/source_def_utils.js +154 -0
- package/dist/model/sql_block.d.ts +5 -1
- package/dist/model/sql_block.js +29 -4
- package/dist/model/sql_compiled.d.ts +29 -0
- package/dist/model/sql_compiled.js +102 -0
- package/dist/model/stage_writer.d.ts +1 -3
- package/dist/model/stage_writer.js +7 -25
- package/dist/model/utils.d.ts +20 -1
- package/dist/model/utils.js +40 -0
- package/dist/run_sql_options.d.ts +0 -1
- package/dist/taggable.d.ts +10 -0
- package/dist/taggable.js +7 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -4
- package/dist/malloy.d.ts +0 -1365
- package/dist/malloy.js +0 -3421
- package/dist/model/materialization/utils.d.ts +0 -3
- package/dist/model/materialization/utils.js +0 -41
package/CONTEXT.md
CHANGED
|
@@ -10,9 +10,9 @@ packages/malloy/
|
|
|
10
10
|
│ ├── lang/ # Translator: Parse tree → AST → IR (see src/lang/CONTEXT.md)
|
|
11
11
|
│ ├── model/ # Compiler: IR → SQL (see src/model/CONTEXT.md)
|
|
12
12
|
│ ├── dialect/ # Database-specific SQL generation
|
|
13
|
-
│ ├── api/ #
|
|
14
|
-
│
|
|
15
|
-
│ └──
|
|
13
|
+
│ ├── api/ # API layers (see src/api/CONTEXT.md)
|
|
14
|
+
│ │ └── foundation/ # Public API classes (see MALLOY_API.md)
|
|
15
|
+
│ └── connection/ # Database connection abstractions
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Two-Phase Architecture
|
|
@@ -53,5 +53,6 @@ For detailed information about the compiler, see [src/model/CONTEXT.md](src/mode
|
|
|
53
53
|
## Subsystem Context
|
|
54
54
|
|
|
55
55
|
For deeper details on specific subsystems:
|
|
56
|
+
- [MALLOY_API.md](MALLOY_API.md) - Public API classes (Model, PreparedQuery, Runtime, Materializers)
|
|
56
57
|
- [src/lang/CONTEXT.md](src/lang/CONTEXT.md) - Translator architecture (grammar, AST, IR generation)
|
|
57
58
|
- [src/model/CONTEXT.md](src/model/CONTEXT.md) - Compiler architecture (SQL generation, expression compilation)
|
package/MALLOY_API.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Foundation API - Public API Classes
|
|
2
|
+
|
|
3
|
+
The directory `src/api/foundation/` is the main public API surface for the Malloy package. It exports classes that wrap internal IR types and provide user-facing functionality. See `src/api/CONTEXT.md` for a complete overview of all API layers.
|
|
4
|
+
|
|
5
|
+
## Core Data Classes
|
|
6
|
+
|
|
7
|
+
### `Model`
|
|
8
|
+
Wraps `ModelDef` (internal IR). Represents a compiled Malloy model.
|
|
9
|
+
|
|
10
|
+
- `explores: Explore[]` - All sources in the model (wrapped)
|
|
11
|
+
- `getPreparedQueryByName(name): PreparedQuery`
|
|
12
|
+
- `getPreparedQueryByIndex(index): PreparedQuery`
|
|
13
|
+
- `getExploreByName(name): Explore`
|
|
14
|
+
- `_modelDef` - Escape hatch to raw IR
|
|
15
|
+
|
|
16
|
+
### `PreparedQuery`
|
|
17
|
+
Wraps `Query` (internal IR) + `ModelDef`. A query that can be compiled to SQL.
|
|
18
|
+
|
|
19
|
+
- `getPreparedResult(options?): PreparedResult` - Compile to SQL
|
|
20
|
+
- `dialect: string`
|
|
21
|
+
- `name?: string`
|
|
22
|
+
- `_query`, `_modelDef` - Escape hatches
|
|
23
|
+
|
|
24
|
+
**Issue:** Each `getPreparedResult()` call creates a new `QueryModel`, reprocessing the ModelDef.
|
|
25
|
+
|
|
26
|
+
### `PreparedResult`
|
|
27
|
+
Wraps `CompiledQuery` (internal). The compiled SQL and metadata.
|
|
28
|
+
|
|
29
|
+
- `sql: string` - The generated SQL
|
|
30
|
+
- `connectionName: string` - Which connection to run against
|
|
31
|
+
- `resultExplore: Explore` - Schema of the result
|
|
32
|
+
|
|
33
|
+
### `Result`
|
|
34
|
+
Extends `PreparedResult`. Adds actual query result data.
|
|
35
|
+
|
|
36
|
+
- `data: DataArray` - The result rows
|
|
37
|
+
- `totalRows: number`
|
|
38
|
+
- `runStats: QueryRunStats`
|
|
39
|
+
|
|
40
|
+
### `Explore`
|
|
41
|
+
Wraps `StructDef` (internal). Represents a source (historical name was "explore").
|
|
42
|
+
|
|
43
|
+
- `name: string`
|
|
44
|
+
- `allFields: Field[]`
|
|
45
|
+
- `getFieldByName(name): Field`
|
|
46
|
+
- `getQueryByName(name): PreparedQuery` - Get a view as a query
|
|
47
|
+
|
|
48
|
+
### `ExploreField`
|
|
49
|
+
Extends `Explore`. A joined source (appears as a field in parent).
|
|
50
|
+
|
|
51
|
+
### `Query`
|
|
52
|
+
Wraps `TurtleDef`. Represents a view definition. **Different from `PreparedQuery`.**
|
|
53
|
+
|
|
54
|
+
### `QueryField`
|
|
55
|
+
Extends `Query`. A view that appears as a field in an explore.
|
|
56
|
+
|
|
57
|
+
### `AtomicField` and subclasses
|
|
58
|
+
Field wrappers: `StringField`, `NumberField`, `DateField`, `TimestampField`, `BooleanField`, `JSONField`, `UnsupportedField`
|
|
59
|
+
|
|
60
|
+
## Runtime & Materializer Classes
|
|
61
|
+
|
|
62
|
+
### `Runtime`
|
|
63
|
+
Entry point for loading and running Malloy. Holds URLReader, connections, event stream.
|
|
64
|
+
|
|
65
|
+
- `loadModel(source): ModelMaterializer`
|
|
66
|
+
- `loadQuery(query): QueryMaterializer`
|
|
67
|
+
- `getModel(source): Promise<Model>`
|
|
68
|
+
- `getQuery(query): Promise<PreparedQuery>`
|
|
69
|
+
|
|
70
|
+
### `SingleConnectionRuntime`
|
|
71
|
+
Extends `Runtime`. For single-connection use cases.
|
|
72
|
+
|
|
73
|
+
### `ConnectionRuntime`
|
|
74
|
+
Extends `Runtime`. Holds array of connections.
|
|
75
|
+
|
|
76
|
+
### `ModelMaterializer`
|
|
77
|
+
Fluent builder for loading models. Returned by `runtime.loadModel()`.
|
|
78
|
+
|
|
79
|
+
- `getModel(): Promise<Model>`
|
|
80
|
+
- `loadQueryByName(name): QueryMaterializer`
|
|
81
|
+
- `loadExploreByName(name): ExploreMaterializer`
|
|
82
|
+
- `extendModel(source): ModelMaterializer`
|
|
83
|
+
|
|
84
|
+
### `QueryMaterializer`
|
|
85
|
+
Fluent builder for queries. Returned by `modelMaterializer.loadQueryByName()`.
|
|
86
|
+
|
|
87
|
+
- `getPreparedQuery(): Promise<PreparedQuery>`
|
|
88
|
+
- `getPreparedResult(): Promise<PreparedResult>`
|
|
89
|
+
- `getSQL(): Promise<string>`
|
|
90
|
+
- `run(options?): Promise<Result>`
|
|
91
|
+
|
|
92
|
+
### `PreparedResultMaterializer`
|
|
93
|
+
Fluent builder for prepared results.
|
|
94
|
+
|
|
95
|
+
### `ExploreMaterializer`
|
|
96
|
+
Fluent builder for explores/sources.
|
|
97
|
+
|
|
98
|
+
## Result Data Classes
|
|
99
|
+
|
|
100
|
+
### `DataArray`
|
|
101
|
+
Iterable array of `DataRecord`. Query result rows.
|
|
102
|
+
|
|
103
|
+
### `DataRecord`
|
|
104
|
+
Single result row. Field values accessed by name.
|
|
105
|
+
|
|
106
|
+
## Utility Classes
|
|
107
|
+
|
|
108
|
+
- `Parse` - Parsed (not compiled) Malloy document
|
|
109
|
+
- `Malloy` - Static methods: `parse()`, `compile()`, `run()`
|
|
110
|
+
- `MalloyError` - Error with structured problems
|
|
111
|
+
- `EmptyURLReader`, `InMemoryURLReader` - URLReader implementations
|
|
112
|
+
- `FixedConnectionMap` - LookupConnection implementation
|
|
113
|
+
- `CacheManager`, `InMemoryModelCache` - Caching
|
|
114
|
+
- `JSONWriter`, `CSVWriter` - Result writers
|
|
115
|
+
- `DocumentSymbol`, `DocumentPosition`, `DocumentRange`, etc. - IDE support
|
|
116
|
+
|
|
117
|
+
## Naming Issues
|
|
118
|
+
|
|
119
|
+
| Current Name | What It Actually Is |
|
|
120
|
+
|--------------|---------------------|
|
|
121
|
+
| `Explore` | A source (historical name) |
|
|
122
|
+
| `PreparedQuery` | Uncompiled query holding IR |
|
|
123
|
+
| `PreparedResult` | Compiled query with SQL (not a "result") |
|
|
124
|
+
| `Query` | A view/turtle definition |
|
|
125
|
+
|
|
126
|
+
## Known Architectural Issues
|
|
127
|
+
|
|
128
|
+
1. **Transient QueryModel**: `PreparedQuery.getPreparedResult()` creates new `QueryModel` each call - expensive.
|
|
129
|
+
3. **Name collision**: `Query` class (view wrapper) vs internal `Query` type vs `PreparedQuery`
|
package/dist/annotation.d.ts
CHANGED
|
@@ -4,9 +4,7 @@ import type { LogMessage } from './lang';
|
|
|
4
4
|
export interface TagParseSpec {
|
|
5
5
|
prefix?: RegExp;
|
|
6
6
|
extending?: Tag;
|
|
7
|
-
scopes?: Tag[];
|
|
8
7
|
}
|
|
9
|
-
export declare function addModelScope(spec: TagParseSpec | undefined, modelScope: Tag): TagParseSpec;
|
|
10
8
|
export declare function annotationToTaglines(annote: Annotation | undefined, prefix?: RegExp): string[];
|
|
11
9
|
export interface MalloyTagParse {
|
|
12
10
|
tag: Tag;
|
package/dist/annotation.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addModelScope = addModelScope;
|
|
4
3
|
exports.annotationToTaglines = annotationToTaglines;
|
|
5
4
|
exports.annotationToTag = annotationToTag;
|
|
6
5
|
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
7
|
-
function addModelScope(spec, modelScope) {
|
|
8
|
-
const useSpec = spec ? { ...spec } : {};
|
|
9
|
-
if (useSpec.scopes) {
|
|
10
|
-
useSpec.scopes = useSpec.scopes.concat(modelScope);
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
useSpec.scopes = [modelScope];
|
|
14
|
-
}
|
|
15
|
-
return useSpec;
|
|
16
|
-
}
|
|
17
6
|
function annotationToTaglines(annote, prefix) {
|
|
18
7
|
annote || (annote = {});
|
|
19
8
|
const tagLines = annote.inherits
|
|
@@ -31,7 +20,6 @@ function annotationToTaglines(annote, prefix) {
|
|
|
31
20
|
return tagLines.concat(prefixed(annote.blockNotes), prefixed(annote.notes));
|
|
32
21
|
}
|
|
33
22
|
function annotationToTag(annote, spec = {}) {
|
|
34
|
-
var _a;
|
|
35
23
|
let extending = spec.extending || new malloy_tag_1.Tag();
|
|
36
24
|
const prefix = spec.prefix || /^##? /;
|
|
37
25
|
annote || (annote = {});
|
|
@@ -54,21 +42,39 @@ function annotationToTag(annote, spec = {}) {
|
|
|
54
42
|
matchingNotes.push(note);
|
|
55
43
|
}
|
|
56
44
|
}
|
|
57
|
-
for (
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
for (const note of matchingNotes) {
|
|
46
|
+
const noteParse = (0, malloy_tag_1.parseTag)(note.text, extending);
|
|
47
|
+
extending = noteParse.tag;
|
|
48
|
+
allErrs.push(...noteParse.log.map((e) => mapMalloyError(e, note)));
|
|
49
|
+
}
|
|
50
|
+
// Validate references and add any warnings
|
|
51
|
+
const refErrors = extending.validateReferences();
|
|
52
|
+
for (const refError of refErrors) {
|
|
53
|
+
allErrs.push({
|
|
54
|
+
code: 'tag-reference-error',
|
|
55
|
+
severity: 'warn',
|
|
56
|
+
message: refError,
|
|
57
|
+
});
|
|
64
58
|
}
|
|
65
59
|
return { tag: extending, log: allErrs };
|
|
66
60
|
}
|
|
67
61
|
function mapMalloyError(e, note) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
// Calculate prefix length (same logic as parseTagLine)
|
|
63
|
+
let prefixLen = 0;
|
|
64
|
+
if (note.text[0] === '#') {
|
|
65
|
+
const skipTo = note.text.indexOf(' ');
|
|
66
|
+
if (skipTo > 0) {
|
|
67
|
+
prefixLen = skipTo;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Map error position to source location
|
|
71
|
+
// e.line is 0-based line within the (stripped) input
|
|
72
|
+
// e.offset is 0-based column within that line
|
|
73
|
+
const line = note.at.range.start.line + e.line;
|
|
74
|
+
const character = e.line === 0
|
|
75
|
+
? note.at.range.start.character + prefixLen + e.offset
|
|
76
|
+
: e.offset;
|
|
77
|
+
const loc = { line, character };
|
|
72
78
|
return {
|
|
73
79
|
code: 'tag-parse-error',
|
|
74
80
|
severity: 'error',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as Malloy from '@malloydata/malloy-interfaces';
|
|
2
2
|
import type { InfoConnection, Connection, LookupConnection } from './connection';
|
|
3
3
|
import type { URLReader } from '../runtime_types';
|
|
4
|
-
import type { CacheManager } from '
|
|
4
|
+
import type { CacheManager } from './foundation';
|
|
5
5
|
export interface CompilerNeedFetch<T extends InfoConnection> {
|
|
6
6
|
connections: LookupConnection<T>;
|
|
7
7
|
urls: URLReader;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ModelDef } from '../../model';
|
|
2
|
+
import type { InvalidationKey, URLReader } from '../../runtime_types';
|
|
3
|
+
interface CacheGetModelDefResponse {
|
|
4
|
+
modelDef: ModelDef;
|
|
5
|
+
invalidationKeys: {
|
|
6
|
+
[url: string]: InvalidationKey;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface ModelCache {
|
|
10
|
+
getModel(url: URL): Promise<CachedModel | undefined>;
|
|
11
|
+
setModel(url: URL, cachedModel: CachedModel): Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export interface CachedModel {
|
|
14
|
+
modelDef: ModelDef;
|
|
15
|
+
invalidationKeys: {
|
|
16
|
+
[url: string]: InvalidationKey;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export declare class CacheManager {
|
|
20
|
+
private modelCache;
|
|
21
|
+
private modelDependencies;
|
|
22
|
+
private modelInvalidationKeys;
|
|
23
|
+
constructor(modelCache: ModelCache);
|
|
24
|
+
getCachedModelDef(urlReader: URLReader, url: string): Promise<CacheGetModelDefResponse | undefined>;
|
|
25
|
+
setCachedModelDef(url: string, cachedModel: CachedModel): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
export declare class InMemoryModelCache implements ModelCache {
|
|
28
|
+
private readonly models;
|
|
29
|
+
getModel(url: URL): Promise<CachedModel | undefined>;
|
|
30
|
+
setModel(url: URL, cachedModel: CachedModel): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
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.InMemoryModelCache = exports.CacheManager = void 0;
|
|
8
|
+
const readers_1 = require("./readers");
|
|
9
|
+
class CacheManager {
|
|
10
|
+
constructor(modelCache) {
|
|
11
|
+
this.modelCache = modelCache;
|
|
12
|
+
this.modelDependencies = new Map();
|
|
13
|
+
this.modelInvalidationKeys = new Map();
|
|
14
|
+
}
|
|
15
|
+
async getCachedModelDef(urlReader, url) {
|
|
16
|
+
const _dependencies = this.modelDependencies.get(url);
|
|
17
|
+
if (_dependencies === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const dependencies = [url, ...flatDeps(_dependencies)];
|
|
21
|
+
const invalidationKeys = {};
|
|
22
|
+
for (const dependency of dependencies) {
|
|
23
|
+
const invalidationKey = this.modelInvalidationKeys.get(dependency);
|
|
24
|
+
if (invalidationKey === undefined || invalidationKey === null) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
invalidationKeys[dependency] = invalidationKey;
|
|
28
|
+
}
|
|
29
|
+
for (const dependency of dependencies) {
|
|
30
|
+
const invalidationKey = await (0, readers_1.getInvalidationKey)(urlReader, new URL(dependency));
|
|
31
|
+
if (invalidationKey !== invalidationKeys[dependency]) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const cached = await this.modelCache.getModel(new URL(url));
|
|
36
|
+
if (cached === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
for (const dependency of dependencies) {
|
|
40
|
+
if (cached.invalidationKeys[dependency] !== invalidationKeys[dependency]) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Return the cached model def and the invalidation keys for this
|
|
45
|
+
// model def's dependencies
|
|
46
|
+
return { modelDef: cached.modelDef, invalidationKeys };
|
|
47
|
+
}
|
|
48
|
+
async setCachedModelDef(url, cachedModel) {
|
|
49
|
+
this.modelDependencies.set(url, cachedModel.modelDef.dependencies);
|
|
50
|
+
const invalidationKeys = {};
|
|
51
|
+
for (const dependency of [
|
|
52
|
+
url,
|
|
53
|
+
...flatDeps(cachedModel.modelDef.dependencies),
|
|
54
|
+
]) {
|
|
55
|
+
if (cachedModel.invalidationKeys[dependency] === null) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (cachedModel.invalidationKeys[dependency] === undefined) {
|
|
59
|
+
throw new Error(`Missing invalidation key for dependency ${dependency}`);
|
|
60
|
+
}
|
|
61
|
+
this.modelInvalidationKeys.set(dependency, cachedModel.invalidationKeys[dependency]);
|
|
62
|
+
invalidationKeys[dependency] = cachedModel.invalidationKeys[dependency];
|
|
63
|
+
}
|
|
64
|
+
const result = await this.modelCache.setModel(new URL(url), {
|
|
65
|
+
modelDef: cachedModel.modelDef,
|
|
66
|
+
invalidationKeys,
|
|
67
|
+
});
|
|
68
|
+
if (result) {
|
|
69
|
+
return true; // TODO just return `result` when it's a boolean
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.CacheManager = CacheManager;
|
|
75
|
+
function flatDeps(tree) {
|
|
76
|
+
return [...Object.keys(tree), ...Object.values(tree).map(flatDeps).flat()];
|
|
77
|
+
}
|
|
78
|
+
// TODO maybe make this memory bounded....
|
|
79
|
+
class InMemoryModelCache {
|
|
80
|
+
constructor() {
|
|
81
|
+
this.models = new Map();
|
|
82
|
+
}
|
|
83
|
+
async getModel(url) {
|
|
84
|
+
return Promise.resolve(this.models.get(url.toString()));
|
|
85
|
+
}
|
|
86
|
+
async setModel(url, cachedModel) {
|
|
87
|
+
this.models.set(url.toString(), cachedModel);
|
|
88
|
+
return Promise.resolve(true);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.InMemoryModelCache = InMemoryModelCache;
|
|
92
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { LogMessage } from '../../lang';
|
|
2
|
+
import type { Connection, InfoConnection, LookupConnection, FetchSchemaOptions } from '../../connection/types';
|
|
3
|
+
import type { ConnectionTypeDef, ConnectionPropertyDefinition, ConnectionsConfig } from '../../connection/registry';
|
|
4
|
+
import type { URLReader, EventStream } from '../../runtime_types';
|
|
5
|
+
import type { SQLSourceDef, QueryRunStats } from '../../model';
|
|
6
|
+
import type { RunSQLOptions } from '../../run_sql_options';
|
|
7
|
+
import type { CacheManager } from './cache';
|
|
8
|
+
import { Parse } from './document';
|
|
9
|
+
import type { ParseOptions, CompileOptions, CompileQueryOptions } from './types';
|
|
10
|
+
import type { PreparedResult } from './core';
|
|
11
|
+
import { Model } from './core';
|
|
12
|
+
import { Result, DataRecord } from './result';
|
|
13
|
+
type Compilable = {
|
|
14
|
+
url: URL;
|
|
15
|
+
source?: undefined;
|
|
16
|
+
parse?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
source: string;
|
|
19
|
+
url?: URL;
|
|
20
|
+
parse?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
parse: Parse;
|
|
23
|
+
url?: URL;
|
|
24
|
+
source?: undefined;
|
|
25
|
+
};
|
|
26
|
+
export interface MalloyCompileOptions {
|
|
27
|
+
url?: URL;
|
|
28
|
+
source?: string;
|
|
29
|
+
parse?: Parse;
|
|
30
|
+
urlReader: URLReader;
|
|
31
|
+
connections: LookupConnection<InfoConnection>;
|
|
32
|
+
model?: Model;
|
|
33
|
+
cacheManager?: CacheManager;
|
|
34
|
+
refreshSchemaCache?: boolean | number;
|
|
35
|
+
noThrowOnError?: boolean;
|
|
36
|
+
eventStream?: EventStream;
|
|
37
|
+
importBaseURL?: URL;
|
|
38
|
+
testEnvironment?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface MalloyRunOptions {
|
|
41
|
+
connection?: Connection;
|
|
42
|
+
preparedResult?: PreparedResult;
|
|
43
|
+
sqlStruct?: SQLSourceDef;
|
|
44
|
+
connections?: LookupConnection<Connection>;
|
|
45
|
+
options?: RunSQLOptions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A Malloy error, which may contain log messages produced during compilation.
|
|
49
|
+
*/
|
|
50
|
+
export declare class MalloyError extends Error {
|
|
51
|
+
readonly problems: LogMessage[];
|
|
52
|
+
/**
|
|
53
|
+
* An array of log messages produced during compilation.
|
|
54
|
+
*/
|
|
55
|
+
constructor(message: string, problems?: LogMessage[]);
|
|
56
|
+
}
|
|
57
|
+
export declare class Malloy {
|
|
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>;
|
|
84
|
+
private static _parse;
|
|
85
|
+
/**
|
|
86
|
+
* Parse a Malloy document by URL.
|
|
87
|
+
*
|
|
88
|
+
* @param url The URL of the Malloy document to parse.
|
|
89
|
+
* @param urlReader Object capable of fetching URL contents.
|
|
90
|
+
* @return A (promise of a) `Parse` result.
|
|
91
|
+
*/
|
|
92
|
+
static parse({ url, urlReader, eventStream, options, }: {
|
|
93
|
+
url: URL;
|
|
94
|
+
urlReader: URLReader;
|
|
95
|
+
eventStream?: EventStream;
|
|
96
|
+
options?: ParseOptions;
|
|
97
|
+
}): Promise<Parse>;
|
|
98
|
+
/**
|
|
99
|
+
* Parse a Malloy document by contents.
|
|
100
|
+
*
|
|
101
|
+
* @param url The URL of the Malloy document to parse (optional).
|
|
102
|
+
* @param source The contents of the Malloy document to parse.
|
|
103
|
+
* @return A `Parse` result.
|
|
104
|
+
*/
|
|
105
|
+
static parse({ source, url, eventStream, options, }: {
|
|
106
|
+
url?: URL;
|
|
107
|
+
source: string;
|
|
108
|
+
eventStream?: EventStream;
|
|
109
|
+
options?: ParseOptions;
|
|
110
|
+
}): Parse;
|
|
111
|
+
/**
|
|
112
|
+
* Compile a parsed Malloy document.
|
|
113
|
+
*
|
|
114
|
+
* @param urlReader Object capable of reading contents of a URL.
|
|
115
|
+
* @param connections Mapping of connection names to objects capable of reading Malloy schemas.
|
|
116
|
+
* @param parse The parsed Malloy document.
|
|
117
|
+
* @param model A compiled model to build upon (optional).
|
|
118
|
+
* @return A (promise of a) compiled `Model`.
|
|
119
|
+
*/
|
|
120
|
+
static compile({ url, source, parse, urlReader, connections, model, refreshSchemaCache, noThrowOnError, eventStream, importBaseURL, cacheManager, }: {
|
|
121
|
+
urlReader: URLReader;
|
|
122
|
+
connections: LookupConnection<InfoConnection>;
|
|
123
|
+
model?: Model;
|
|
124
|
+
cacheManager?: CacheManager;
|
|
125
|
+
} & Compilable & CompileOptions & CompileQueryOptions & ParseOptions): Promise<Model>;
|
|
126
|
+
/**
|
|
127
|
+
* A dialect must provide a response for every table, or the translator loop
|
|
128
|
+
* will never exit. Because there was a time when this happened, we throw
|
|
129
|
+
* instead of looping forever, but the fix is to correct the dialect.
|
|
130
|
+
*/
|
|
131
|
+
static safelyFetchTableSchema(connection: InfoConnection, toFetch: Record<string, string>, opts: FetchSchemaOptions): Promise<{
|
|
132
|
+
schemas: Record<string, import("../../model").TableSourceDef>;
|
|
133
|
+
errors: Record<string, string>;
|
|
134
|
+
}>;
|
|
135
|
+
/**
|
|
136
|
+
* Run a fully-prepared query.
|
|
137
|
+
*
|
|
138
|
+
* @param get A mapping from connection names to objects capable of running SQL.
|
|
139
|
+
* @param preparedResult A fully-prepared query which is ready to run (a `PreparedResult`).
|
|
140
|
+
* @return Query result data and associated metadata.
|
|
141
|
+
*/
|
|
142
|
+
static run(params: {
|
|
143
|
+
connections: LookupConnection<Connection>;
|
|
144
|
+
preparedResult: PreparedResult;
|
|
145
|
+
options?: RunSQLOptions;
|
|
146
|
+
}): Promise<Result>;
|
|
147
|
+
static run(params: {
|
|
148
|
+
connection: Connection;
|
|
149
|
+
preparedResult: PreparedResult;
|
|
150
|
+
options?: RunSQLOptions;
|
|
151
|
+
}): Promise<Result>;
|
|
152
|
+
static run(params: {
|
|
153
|
+
connection: Connection;
|
|
154
|
+
sqlStruct: SQLSourceDef;
|
|
155
|
+
options?: RunSQLOptions;
|
|
156
|
+
}): Promise<Result>;
|
|
157
|
+
static run(params: {
|
|
158
|
+
connections: LookupConnection<Connection>;
|
|
159
|
+
sqlStruct: SQLSourceDef;
|
|
160
|
+
options?: RunSQLOptions;
|
|
161
|
+
}): Promise<Result>;
|
|
162
|
+
static run(params: {
|
|
163
|
+
connection: Connection;
|
|
164
|
+
sqlStruct: SQLSourceDef;
|
|
165
|
+
options?: RunSQLOptions;
|
|
166
|
+
}): Promise<Result>;
|
|
167
|
+
static run(params: {
|
|
168
|
+
connections: LookupConnection<Connection>;
|
|
169
|
+
sqlStruct: SQLSourceDef;
|
|
170
|
+
options?: RunSQLOptions;
|
|
171
|
+
}): Promise<Result>;
|
|
172
|
+
static runStream(params: {
|
|
173
|
+
connections: LookupConnection<Connection>;
|
|
174
|
+
preparedResult: PreparedResult;
|
|
175
|
+
options?: RunSQLOptions;
|
|
176
|
+
}): AsyncIterableIterator<DataRecord>;
|
|
177
|
+
static runStream(params: {
|
|
178
|
+
connection: Connection;
|
|
179
|
+
preparedResult: PreparedResult;
|
|
180
|
+
options?: RunSQLOptions;
|
|
181
|
+
}): AsyncIterableIterator<DataRecord>;
|
|
182
|
+
static runStream(params: {
|
|
183
|
+
connection: Connection;
|
|
184
|
+
sqlStruct: SQLSourceDef;
|
|
185
|
+
options?: RunSQLOptions;
|
|
186
|
+
}): AsyncIterableIterator<DataRecord>;
|
|
187
|
+
static runStream(params: {
|
|
188
|
+
connections: LookupConnection<Connection>;
|
|
189
|
+
sqlStruct: SQLSourceDef;
|
|
190
|
+
options?: RunSQLOptions;
|
|
191
|
+
}): AsyncIterableIterator<DataRecord>;
|
|
192
|
+
static estimateQueryCost(params: {
|
|
193
|
+
connections: LookupConnection<Connection>;
|
|
194
|
+
preparedResult: PreparedResult;
|
|
195
|
+
}): Promise<QueryRunStats>;
|
|
196
|
+
static estimateQueryCost(params: {
|
|
197
|
+
connections: LookupConnection<Connection>;
|
|
198
|
+
sqlStruct: SQLSourceDef;
|
|
199
|
+
}): Promise<QueryRunStats>;
|
|
200
|
+
}
|
|
201
|
+
export {};
|