@malloydata/malloy 0.0.237-dev250225015031 → 0.0.237-dev250225144145

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.
@@ -4,7 +4,7 @@ import { Connection } from '../connection/types';
4
4
  import { AndChain } from './utils';
5
5
  import { QueryInfo } from '../dialect/dialect';
6
6
  import { EventStream } from '../runtime_types';
7
- import { Tag } from '../tags';
7
+ import { Tag } from '@malloydata/malloy-tag';
8
8
  interface TurtleDefPlus extends TurtleDef, Filtered {
9
9
  }
10
10
  /** Parent from QueryStruct. */
@@ -225,6 +225,8 @@ declare class JoinInstance {
225
225
  export declare class Segment {
226
226
  static nextStructDef(structDef: SourceDef, segment: PipeSegment): QueryResultDef;
227
227
  }
228
+ export declare function getResultStructDefForView(source: SourceDef, view: TurtleDef): SourceDef;
229
+ export declare function getResultStructDefForQuery(model: ModelDef, query: Query): SourceDef;
228
230
  type StageGroupMaping = {
229
231
  fromGroup: number;
230
232
  toGroup: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryModel = exports.Segment = void 0;
3
+ exports.QueryModel = exports.getResultStructDefForQuery = exports.getResultStructDefForView = exports.Segment = void 0;
4
4
  /*
5
5
  * Copyright 2023 Google LLC
6
6
  *
@@ -29,7 +29,7 @@ const standardsql_1 = require("../dialect/standardsql/standardsql");
29
29
  const malloy_types_1 = require("./malloy_types");
30
30
  const utils_1 = require("./utils");
31
31
  const utils_2 = require("./materialization/utils");
32
- const tags_1 = require("../tags");
32
+ const annotation_1 = require("../annotation");
33
33
  function pathToCol(path) {
34
34
  return path.map(el => encodeURIComponent(el)).join('/');
35
35
  }
@@ -1564,6 +1564,21 @@ class Segment {
1564
1564
  }
1565
1565
  }
1566
1566
  exports.Segment = Segment;
1567
+ function getResultStructDefForView(source, view) {
1568
+ const qs = new QueryStruct(source, undefined, {
1569
+ model: new QueryModel(undefined),
1570
+ }, {});
1571
+ const queryQueryQuery = QueryQuery.makeQuery(view, qs, new StageWriter(true, undefined), // stage write indicates we want to get a result.
1572
+ false);
1573
+ return queryQueryQuery.getResultStructDef();
1574
+ }
1575
+ exports.getResultStructDefForView = getResultStructDefForView;
1576
+ function getResultStructDefForQuery(model, query) {
1577
+ const queryModel = new QueryModel(model);
1578
+ const compiled = queryModel.compileQuery(query);
1579
+ return compiled.structs[compiled.structs.length - 1];
1580
+ }
1581
+ exports.getResultStructDefForQuery = getResultStructDefForQuery;
1567
1582
  /** Query builder object. */
1568
1583
  class QueryQuery extends QueryField {
1569
1584
  constructor(fieldDef, parent, stageWriter, isJoinedSubquery) {
@@ -3087,7 +3102,7 @@ class QueryStruct {
3087
3102
  modelCompilerFlags() {
3088
3103
  if (this._modelTag === undefined) {
3089
3104
  const annotation = this.structDef.modelAnnotation;
3090
- const { tag } = tags_1.Tag.annotationToTag(annotation, { prefix: /^##!\s*/ });
3105
+ const { tag } = (0, annotation_1.annotationToTag)(annotation, { prefix: /^##!\s*/ });
3091
3106
  this._modelTag = tag;
3092
3107
  }
3093
3108
  return this._modelTag;
@@ -7,14 +7,14 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.buildQueryMaterializationSpec = exports.shouldMaterialize = void 0;
10
- const tags_1 = require("../../tags");
11
10
  const utils_1 = require("../utils");
11
+ const annotation_1 = require("../../annotation");
12
12
  function shouldMaterialize(annotation) {
13
13
  const clonedAnnotation = structuredClone(annotation);
14
14
  if (clonedAnnotation) {
15
15
  clonedAnnotation.inherits = undefined;
16
16
  }
17
- const sourceTag = tags_1.Tag.annotationToTag(clonedAnnotation).tag;
17
+ const sourceTag = (0, annotation_1.annotationToTag)(clonedAnnotation).tag;
18
18
  return sourceTag.has('materialize');
19
19
  }
20
20
  exports.shouldMaterialize = shouldMaterialize;
@@ -0,0 +1,3 @@
1
+ import * as Malloy from '@malloydata/malloy-interfaces';
2
+ import { ModelDef } from './model';
3
+ export declare function modelDefToModelInfo(modelDef: ModelDef): Malloy.ModelInfo;
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelDefToModelInfo = void 0;
4
+ const model_1 = require("./model");
5
+ const malloy_query_1 = require("./model/malloy_query");
6
+ function modelDefToModelInfo(modelDef) {
7
+ const modelInfo = {
8
+ entries: [],
9
+ anonymous_queries: [],
10
+ };
11
+ for (const [name, entry] of Object.entries(modelDef.contents)) {
12
+ if (!modelDef.exports.includes(name))
13
+ continue;
14
+ if ((0, model_1.isSourceDef)(entry)) {
15
+ const sourceInfo = {
16
+ kind: 'source',
17
+ name,
18
+ schema: {
19
+ fields: convertFieldInfos(entry, entry.fields),
20
+ },
21
+ };
22
+ modelInfo.entries.push(sourceInfo);
23
+ }
24
+ else if (entry.type === 'query') {
25
+ const outputStruct = (0, malloy_query_1.getResultStructDefForQuery)(modelDef, entry);
26
+ const queryInfo = {
27
+ kind: 'source',
28
+ name,
29
+ schema: {
30
+ fields: convertFieldInfos(outputStruct, outputStruct.fields),
31
+ },
32
+ };
33
+ modelInfo.entries.push(queryInfo);
34
+ }
35
+ }
36
+ return modelInfo;
37
+ }
38
+ exports.modelDefToModelInfo = modelDefToModelInfo;
39
+ function convertFieldInfos(source, fields) {
40
+ var _a, _b, _c;
41
+ const result = [];
42
+ for (const field of fields) {
43
+ if ((0, model_1.isTurtle)(field)) {
44
+ const outputStruct = (0, malloy_query_1.getResultStructDefForView)(source, field);
45
+ const fieldInfo = {
46
+ kind: 'view',
47
+ name: (_a = field.as) !== null && _a !== void 0 ? _a : field.name,
48
+ schema: { fields: convertFieldInfos(outputStruct, outputStruct.fields) },
49
+ };
50
+ result.push(fieldInfo);
51
+ }
52
+ else if ((0, model_1.isAtomic)(field)) {
53
+ const aggregate = (0, model_1.expressionIsAggregate)(field.expressionType);
54
+ const scalar = (0, model_1.expressionIsScalar)(field.expressionType);
55
+ if (!aggregate && !scalar)
56
+ continue;
57
+ if (field.type === 'error')
58
+ continue;
59
+ const fieldInfo = {
60
+ kind: aggregate ? 'measure' : 'dimension',
61
+ name: (_b = field.as) !== null && _b !== void 0 ? _b : field.name,
62
+ type: typeDefToType(field),
63
+ };
64
+ result.push(fieldInfo);
65
+ }
66
+ else if ((0, model_1.isJoinedSource)(field)) {
67
+ const fieldInfo = {
68
+ kind: 'join',
69
+ name: (_c = field.as) !== null && _c !== void 0 ? _c : field.name,
70
+ schema: {
71
+ fields: convertFieldInfos(field, field.fields),
72
+ },
73
+ relationship: convertJoinType(field.join),
74
+ };
75
+ result.push(fieldInfo);
76
+ }
77
+ }
78
+ return result;
79
+ }
80
+ function typeDefToType(field) {
81
+ if ((0, model_1.isLeafAtomic)(field)) {
82
+ switch (field.type) {
83
+ case 'string':
84
+ return { kind: 'string_type' };
85
+ case 'number':
86
+ return {
87
+ kind: 'number_type',
88
+ subtype: field.numberType === 'float'
89
+ ? 'decimal'
90
+ : field.numberType === 'integer'
91
+ ? 'integer'
92
+ : undefined,
93
+ };
94
+ case 'boolean':
95
+ return { kind: 'boolean_type' };
96
+ case 'date':
97
+ return {
98
+ kind: 'date_type',
99
+ timeframe: convertDateTimeframe(field.timeframe),
100
+ };
101
+ case 'timestamp':
102
+ return {
103
+ kind: 'timestamp_type',
104
+ timeframe: convertTimestampTimeframe(field.timeframe),
105
+ };
106
+ case 'json':
107
+ return { kind: 'json_type' };
108
+ case 'sql native':
109
+ return {
110
+ kind: 'sql_native_type',
111
+ sql_type: field.rawType,
112
+ };
113
+ case 'error':
114
+ throw new Error('Error type is not supported in stable interface');
115
+ }
116
+ }
117
+ else if ((0, model_1.isRepeatedRecord)(field)) {
118
+ return {
119
+ kind: 'array_type',
120
+ element_type: convertRecordType(field),
121
+ };
122
+ }
123
+ else if (field.type === 'record') {
124
+ return convertRecordType(field);
125
+ }
126
+ else if (field.type === 'array') {
127
+ return {
128
+ kind: 'array_type',
129
+ element_type: typeDefToType(field.elementTypeDef),
130
+ };
131
+ }
132
+ throw new Error('Unexpected field type');
133
+ }
134
+ function convertRecordType(field) {
135
+ return {
136
+ kind: 'record_type',
137
+ fields: field.fields.map(f => {
138
+ if ((0, model_1.isAtomic)(f)) {
139
+ return {
140
+ name: f.name,
141
+ type: typeDefToType(f),
142
+ };
143
+ }
144
+ else {
145
+ throw new Error('Expected record type to not have a table as its child');
146
+ }
147
+ }),
148
+ };
149
+ }
150
+ function convertDateTimeframe(timeframe) {
151
+ switch (timeframe) {
152
+ case undefined:
153
+ return undefined;
154
+ case 'day':
155
+ case 'week':
156
+ case 'month':
157
+ case 'year':
158
+ case 'quarter':
159
+ return timeframe;
160
+ default:
161
+ throw new Error('Invalid date timeframe');
162
+ }
163
+ }
164
+ function convertTimestampTimeframe(timeframe) {
165
+ return timeframe;
166
+ }
167
+ function convertJoinType(type) {
168
+ return type;
169
+ }
170
+ //# sourceMappingURL=to_stable.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.237-dev250225015031",
3
+ "version": "0.0.237-dev250225144145",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -41,6 +41,8 @@
41
41
  "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"
42
42
  },
43
43
  "dependencies": {
44
+ "@malloydata/malloy-interfaces": "^0.0.237-dev250225144145",
45
+ "@malloydata/malloy-tag": "^0.0.237-dev250225144145",
44
46
  "antlr4ts": "^0.5.0-alpha.4",
45
47
  "assert": "^2.0.0",
46
48
  "jest-diff": "^29.6.2",
@@ -1,42 +0,0 @@
1
- import { ATN } from "antlr4ts/atn/ATN";
2
- import { CharStream } from "antlr4ts/CharStream";
3
- import { Lexer } from "antlr4ts/Lexer";
4
- import { Vocabulary } from "antlr4ts/Vocabulary";
5
- export declare class MalloyTagLexer extends Lexer {
6
- static readonly MINUS_DOTTY = 1;
7
- static readonly DOTTY = 2;
8
- static readonly DOT = 3;
9
- static readonly MINUS = 4;
10
- static readonly EQ = 5;
11
- static readonly RF_BEG = 6;
12
- static readonly RF_END = 7;
13
- static readonly PR_BEG = 8;
14
- static readonly PR_END = 9;
15
- static readonly AR_BEG = 10;
16
- static readonly COMMA = 11;
17
- static readonly AR_END = 12;
18
- static readonly SQ_STRING = 13;
19
- static readonly DQ_STRING = 14;
20
- static readonly BQ_STRING = 15;
21
- static readonly NUMERIC_LITERAL = 16;
22
- static readonly BARE_STRING = 17;
23
- static readonly COMMENT = 18;
24
- static readonly WHITE_SPACE = 19;
25
- static readonly UNEXPECTED_CHAR = 20;
26
- static readonly channelNames: string[];
27
- static readonly modeNames: string[];
28
- static readonly ruleNames: string[];
29
- private static readonly _LITERAL_NAMES;
30
- private static readonly _SYMBOLIC_NAMES;
31
- static readonly VOCABULARY: Vocabulary;
32
- get vocabulary(): Vocabulary;
33
- constructor(input: CharStream);
34
- get grammarFileName(): string;
35
- get ruleNames(): string[];
36
- get serializedATN(): string;
37
- get channelNames(): string[];
38
- get modeNames(): string[];
39
- static readonly _serializedATN: string;
40
- static __ATN: ATN;
41
- static get _ATN(): ATN;
42
- }