@malloydata/malloy 0.0.398 → 0.0.399

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.
@@ -67,6 +67,7 @@ export * from './expressions/range';
67
67
  export * from './expressions/time-frame';
68
68
  export * from './expressions/unary';
69
69
  export * from './statements/import-statement';
70
+ export * from './statements/export-statement';
70
71
  export * from './query-properties/extend';
71
72
  export * from './parameters/argument';
72
73
  export * from './parameters/has-parameter';
@@ -105,6 +105,7 @@ __exportStar(require("./expressions/range"), exports);
105
105
  __exportStar(require("./expressions/time-frame"), exports);
106
106
  __exportStar(require("./expressions/unary"), exports);
107
107
  __exportStar(require("./statements/import-statement"), exports);
108
+ __exportStar(require("./statements/export-statement"), exports);
108
109
  __exportStar(require("./query-properties/extend"), exports);
109
110
  __exportStar(require("./parameters/argument"), exports);
110
111
  __exportStar(require("./parameters/has-parameter"), exports);
@@ -0,0 +1,12 @@
1
+ import type { DocStatement, Document } from '../types/malloy-element';
2
+ import { ListOf, MalloyElement } from '../types/malloy-element';
3
+ export declare class ExportItem extends MalloyElement {
4
+ readonly name: string;
5
+ elementType: string;
6
+ constructor(name: string);
7
+ }
8
+ export declare class ExportStatement extends ListOf<ExportItem> implements DocStatement {
9
+ elementType: string;
10
+ constructor(items: ExportItem[]);
11
+ execute(doc: Document): void;
12
+ }
@@ -0,0 +1,53 @@
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.ExportStatement = exports.ExportItem = void 0;
8
+ const malloy_types_1 = require("../../../model/malloy_types");
9
+ const malloy_element_1 = require("../types/malloy-element");
10
+ class ExportItem extends malloy_element_1.MalloyElement {
11
+ constructor(name) {
12
+ super();
13
+ this.name = name;
14
+ this.elementType = 'exportItem';
15
+ }
16
+ }
17
+ exports.ExportItem = ExportItem;
18
+ class ExportStatement extends malloy_element_1.ListOf {
19
+ constructor(items) {
20
+ super(items);
21
+ this.elementType = 'export statement';
22
+ }
23
+ execute(doc) {
24
+ if (doc.explicitExports === undefined) {
25
+ doc.explicitExports = new Set();
26
+ }
27
+ const explicit = doc.explicitExports;
28
+ for (const item of this.list) {
29
+ const name = item.name;
30
+ if (explicit.has(name)) {
31
+ item.logError('duplicate-export-name', `'${name}' already appears in an export statement`);
32
+ continue;
33
+ }
34
+ const entry = doc.documentModel.get(name);
35
+ if (entry === undefined) {
36
+ item.logError('export-name-not-defined', `Cannot export '${name}': no such definition above this statement`);
37
+ continue;
38
+ }
39
+ const def = entry.entry;
40
+ const exportable = (0, malloy_types_1.isSourceDef)(def) ||
41
+ def.type === 'query' ||
42
+ def.type === 'userType' ||
43
+ def.type === 'given';
44
+ if (!exportable) {
45
+ item.logError('export-name-not-exportable', `Cannot export '${name}': only sources, queries, given declarations, and user types may be exported`);
46
+ continue;
47
+ }
48
+ explicit.add(name);
49
+ }
50
+ }
51
+ }
52
+ exports.ExportStatement = ExportStatement;
53
+ //# sourceMappingURL=export-statement.js.map
@@ -111,6 +111,7 @@ export declare class Document extends MalloyElement implements NameSpace {
111
111
  documentModel: Map<string, ModelEntry>;
112
112
  documentSrcRegistry: Record<SourceID, SourceRegistryValue>;
113
113
  documentGivens: Map<string, Given>;
114
+ explicitExports: Set<string> | undefined;
114
115
  queryList: Query[];
115
116
  statements: DocStatementList;
116
117
  didInitModel: boolean;
@@ -477,6 +477,7 @@ class Document extends MalloyElement {
477
477
  this.documentModel = new Map();
478
478
  this.documentSrcRegistry = {};
479
479
  this.documentGivens = new Map();
480
+ this.explicitExports = undefined;
480
481
  this.queryList = [];
481
482
  if (extendingModelDef) {
482
483
  if (extendingModelDef.annotation) {
@@ -623,12 +624,14 @@ class Document extends MalloyElement {
623
624
  if (this.hasAnnotation()) {
624
625
  def.annotation = this.currentModelAnnotation();
625
626
  }
627
+ const explicit = this.explicitExports;
628
+ const isExported = (name, modelEntry) => explicit ? explicit.has(name) : modelEntry.exported === true;
626
629
  for (const [name, modelEntry] of this.documentModel) {
627
630
  const entryDef = modelEntry.entry;
628
631
  if ((0, malloy_types_1.isSourceDef)(entryDef) ||
629
632
  entryDef.type === 'query' ||
630
633
  entryDef.type === 'userType') {
631
- if (modelEntry.exported) {
634
+ if (isExported(name, modelEntry)) {
632
635
  def.exports.push(name);
633
636
  }
634
637
  if (entryDef.type === 'userType') {
@@ -643,7 +646,7 @@ class Document extends MalloyElement {
643
646
  }
644
647
  }
645
648
  else if (entryDef.type === 'given') {
646
- if (modelEntry.exported) {
649
+ if (isExported(name, modelEntry)) {
647
650
  def.exports.push(name);
648
651
  }
649
652
  def.contents[name] = { ...entryDef };
@@ -62,129 +62,130 @@ export declare class MalloyLexer extends Lexer {
62
62
  static readonly ELSE = 56;
63
63
  static readonly END = 57;
64
64
  static readonly EXCLUDE = 58;
65
- static readonly EXTEND = 59;
66
- static readonly FALSE = 60;
67
- static readonly FILTER = 61;
68
- static readonly FULL = 62;
69
- static readonly FOR = 63;
70
- static readonly FROM = 64;
71
- static readonly HAS = 65;
72
- static readonly HOUR = 66;
73
- static readonly IMPORT = 67;
74
- static readonly INCLUDE = 68;
75
- static readonly INNER = 69;
76
- static readonly IS = 70;
77
- static readonly IN = 71;
78
- static readonly INTERNAL_KW = 72;
79
- static readonly JSON = 73;
80
- static readonly LAST = 74;
81
- static readonly LEFT = 75;
82
- static readonly LIKE = 76;
83
- static readonly MAX = 77;
84
- static readonly MIN = 78;
85
- static readonly MINUTE = 79;
86
- static readonly MONTH = 80;
87
- static readonly NOT = 81;
88
- static readonly NOW = 82;
89
- static readonly NULL = 83;
90
- static readonly NUMBER = 84;
91
- static readonly ON = 85;
92
- static readonly OR = 86;
93
- static readonly PICK = 87;
94
- static readonly PRIVATE_KW = 88;
95
- static readonly PUBLIC_KW = 89;
96
- static readonly QUARTER = 90;
97
- static readonly RIGHT = 91;
98
- static readonly SECOND = 92;
99
- static readonly STRING = 93;
100
- static readonly SOURCE_KW = 94;
101
- static readonly SUM = 95;
102
- static readonly SQL = 96;
103
- static readonly TABLE = 97;
104
- static readonly THEN = 98;
105
- static readonly THIS = 99;
106
- static readonly TIMESTAMPTZ = 100;
107
- static readonly TIMESTAMP = 101;
108
- static readonly TO = 102;
109
- static readonly TRUE = 103;
110
- static readonly TURTLE = 104;
111
- static readonly WEEK = 105;
112
- static readonly WHEN = 106;
113
- static readonly WITH = 107;
114
- static readonly YEAR = 108;
115
- static readonly UNGROUPED = 109;
116
- static readonly VIRTUAL = 110;
117
- static readonly HACKY_REGEX = 111;
118
- static readonly RAW_SQ = 112;
119
- static readonly RAW_DQ = 113;
120
- static readonly SQ3_FILTER = 114;
121
- static readonly SQ_FILTER = 115;
122
- static readonly DQ3_FILTER = 116;
123
- static readonly DQ_FILTER = 117;
124
- static readonly BQ3_FILTER = 118;
125
- static readonly BQ_FILTER = 119;
126
- static readonly SQ_STRING = 120;
127
- static readonly DQ_STRING = 121;
128
- static readonly BQ_STRING = 122;
129
- static readonly DOC_BLOCK_ANNOTATION_BEGIN = 123;
130
- static readonly BLOCK_ANNOTATION_BEGIN = 124;
131
- static readonly DOC_ANNOTATION = 125;
132
- static readonly ANNOTATION = 126;
133
- static readonly AMPER = 127;
134
- static readonly ARROW = 128;
135
- static readonly FAT_ARROW = 129;
136
- static readonly OPAREN = 130;
137
- static readonly CPAREN = 131;
138
- static readonly OBRACK = 132;
139
- static readonly CBRACK = 133;
140
- static readonly OCURLY = 134;
141
- static readonly CCURLY = 135;
142
- static readonly DOUBLECOLON = 136;
143
- static readonly TRIPLECOLON = 137;
144
- static readonly EXCLAM = 138;
145
- static readonly COLON = 139;
146
- static readonly COMMA = 140;
147
- static readonly DOT = 141;
148
- static readonly LT = 142;
149
- static readonly GT = 143;
150
- static readonly EQ = 144;
151
- static readonly NE = 145;
152
- static readonly LTE = 146;
153
- static readonly GTE = 147;
154
- static readonly PLUS = 148;
155
- static readonly MINUS = 149;
156
- static readonly STAR = 150;
157
- static readonly STARSTAR = 151;
158
- static readonly SLASH = 152;
159
- static readonly BAR = 153;
160
- static readonly SEMI = 154;
161
- static readonly NOT_MATCH = 155;
162
- static readonly MATCH = 156;
163
- static readonly PERCENT = 157;
164
- static readonly DOUBLE_QMARK = 158;
165
- static readonly QMARK = 159;
166
- static readonly LITERAL_TIMESTAMP = 160;
167
- static readonly LITERAL_HOUR = 161;
168
- static readonly LITERAL_DAY = 162;
169
- static readonly LITERAL_QUARTER = 163;
170
- static readonly LITERAL_MONTH = 164;
171
- static readonly LITERAL_WEEK = 165;
172
- static readonly LITERAL_YEAR = 166;
173
- static readonly GIVEN_REF = 167;
174
- static readonly IDENTIFIER = 168;
175
- static readonly PERCENT_LITERAL = 169;
176
- static readonly NUMERIC_LITERAL = 170;
177
- static readonly INTEGER_LITERAL = 171;
178
- static readonly BLOCK_COMMENT = 172;
179
- static readonly COMMENT_TO_EOL = 173;
180
- static readonly WHITE_SPACE = 174;
181
- static readonly SQL_BEGIN = 175;
182
- static readonly UNWATED_CHARS_TRAILING_NUMBERS = 176;
183
- static readonly UNEXPECTED_CHAR = 177;
184
- static readonly OPEN_CODE = 178;
185
- static readonly SQL_END = 179;
186
- static readonly BLOCK_ANNOTATION_END = 180;
187
- static readonly BLOCK_ANNOTATION_TEXT = 181;
65
+ static readonly EXPORT = 59;
66
+ static readonly EXTEND = 60;
67
+ static readonly FALSE = 61;
68
+ static readonly FILTER = 62;
69
+ static readonly FULL = 63;
70
+ static readonly FOR = 64;
71
+ static readonly FROM = 65;
72
+ static readonly HAS = 66;
73
+ static readonly HOUR = 67;
74
+ static readonly IMPORT = 68;
75
+ static readonly INCLUDE = 69;
76
+ static readonly INNER = 70;
77
+ static readonly IS = 71;
78
+ static readonly IN = 72;
79
+ static readonly INTERNAL_KW = 73;
80
+ static readonly JSON = 74;
81
+ static readonly LAST = 75;
82
+ static readonly LEFT = 76;
83
+ static readonly LIKE = 77;
84
+ static readonly MAX = 78;
85
+ static readonly MIN = 79;
86
+ static readonly MINUTE = 80;
87
+ static readonly MONTH = 81;
88
+ static readonly NOT = 82;
89
+ static readonly NOW = 83;
90
+ static readonly NULL = 84;
91
+ static readonly NUMBER = 85;
92
+ static readonly ON = 86;
93
+ static readonly OR = 87;
94
+ static readonly PICK = 88;
95
+ static readonly PRIVATE_KW = 89;
96
+ static readonly PUBLIC_KW = 90;
97
+ static readonly QUARTER = 91;
98
+ static readonly RIGHT = 92;
99
+ static readonly SECOND = 93;
100
+ static readonly STRING = 94;
101
+ static readonly SOURCE_KW = 95;
102
+ static readonly SUM = 96;
103
+ static readonly SQL = 97;
104
+ static readonly TABLE = 98;
105
+ static readonly THEN = 99;
106
+ static readonly THIS = 100;
107
+ static readonly TIMESTAMPTZ = 101;
108
+ static readonly TIMESTAMP = 102;
109
+ static readonly TO = 103;
110
+ static readonly TRUE = 104;
111
+ static readonly TURTLE = 105;
112
+ static readonly WEEK = 106;
113
+ static readonly WHEN = 107;
114
+ static readonly WITH = 108;
115
+ static readonly YEAR = 109;
116
+ static readonly UNGROUPED = 110;
117
+ static readonly VIRTUAL = 111;
118
+ static readonly HACKY_REGEX = 112;
119
+ static readonly RAW_SQ = 113;
120
+ static readonly RAW_DQ = 114;
121
+ static readonly SQ3_FILTER = 115;
122
+ static readonly SQ_FILTER = 116;
123
+ static readonly DQ3_FILTER = 117;
124
+ static readonly DQ_FILTER = 118;
125
+ static readonly BQ3_FILTER = 119;
126
+ static readonly BQ_FILTER = 120;
127
+ static readonly SQ_STRING = 121;
128
+ static readonly DQ_STRING = 122;
129
+ static readonly BQ_STRING = 123;
130
+ static readonly DOC_BLOCK_ANNOTATION_BEGIN = 124;
131
+ static readonly BLOCK_ANNOTATION_BEGIN = 125;
132
+ static readonly DOC_ANNOTATION = 126;
133
+ static readonly ANNOTATION = 127;
134
+ static readonly AMPER = 128;
135
+ static readonly ARROW = 129;
136
+ static readonly FAT_ARROW = 130;
137
+ static readonly OPAREN = 131;
138
+ static readonly CPAREN = 132;
139
+ static readonly OBRACK = 133;
140
+ static readonly CBRACK = 134;
141
+ static readonly OCURLY = 135;
142
+ static readonly CCURLY = 136;
143
+ static readonly DOUBLECOLON = 137;
144
+ static readonly TRIPLECOLON = 138;
145
+ static readonly EXCLAM = 139;
146
+ static readonly COLON = 140;
147
+ static readonly COMMA = 141;
148
+ static readonly DOT = 142;
149
+ static readonly LT = 143;
150
+ static readonly GT = 144;
151
+ static readonly EQ = 145;
152
+ static readonly NE = 146;
153
+ static readonly LTE = 147;
154
+ static readonly GTE = 148;
155
+ static readonly PLUS = 149;
156
+ static readonly MINUS = 150;
157
+ static readonly STAR = 151;
158
+ static readonly STARSTAR = 152;
159
+ static readonly SLASH = 153;
160
+ static readonly BAR = 154;
161
+ static readonly SEMI = 155;
162
+ static readonly NOT_MATCH = 156;
163
+ static readonly MATCH = 157;
164
+ static readonly PERCENT = 158;
165
+ static readonly DOUBLE_QMARK = 159;
166
+ static readonly QMARK = 160;
167
+ static readonly LITERAL_TIMESTAMP = 161;
168
+ static readonly LITERAL_HOUR = 162;
169
+ static readonly LITERAL_DAY = 163;
170
+ static readonly LITERAL_QUARTER = 164;
171
+ static readonly LITERAL_MONTH = 165;
172
+ static readonly LITERAL_WEEK = 166;
173
+ static readonly LITERAL_YEAR = 167;
174
+ static readonly GIVEN_REF = 168;
175
+ static readonly IDENTIFIER = 169;
176
+ static readonly PERCENT_LITERAL = 170;
177
+ static readonly NUMERIC_LITERAL = 171;
178
+ static readonly INTEGER_LITERAL = 172;
179
+ static readonly BLOCK_COMMENT = 173;
180
+ static readonly COMMENT_TO_EOL = 174;
181
+ static readonly WHITE_SPACE = 175;
182
+ static readonly SQL_BEGIN = 176;
183
+ static readonly UNWATED_CHARS_TRAILING_NUMBERS = 177;
184
+ static readonly UNEXPECTED_CHAR = 178;
185
+ static readonly OPEN_CODE = 179;
186
+ static readonly SQL_END = 180;
187
+ static readonly BLOCK_ANNOTATION_END = 181;
188
+ static readonly BLOCK_ANNOTATION_TEXT = 182;
188
189
  static readonly SQL_MODE = 1;
189
190
  static readonly BLOCK_ANNOTATION_MODE = 2;
190
191
  static readonly channelNames: string[];