@malloydata/malloy 0.0.271 → 0.0.273
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/dist/api/core.js +21 -2
- package/dist/dialect/trino/dialect_functions.js +21 -0
- package/dist/lang/ast/expressions/constant-expression.d.ts +2 -2
- package/dist/lang/ast/expressions/constant-expression.js +2 -2
- package/dist/lang/ast/field-space/dynamic-space.js +1 -1
- package/dist/lang/ast/field-space/include-utils.d.ts +28 -0
- package/dist/lang/ast/field-space/include-utils.js +258 -0
- package/dist/lang/ast/field-space/parameter-space.d.ts +2 -2
- package/dist/lang/ast/field-space/parameter-space.js +2 -2
- package/dist/lang/ast/field-space/query-input-space.d.ts +4 -4
- package/dist/lang/ast/field-space/query-input-space.js +4 -4
- package/dist/lang/ast/field-space/query-spaces.d.ts +1 -0
- package/dist/lang/ast/field-space/query-spaces.js +4 -1
- package/dist/lang/ast/field-space/refined-space.d.ts +4 -8
- package/dist/lang/ast/field-space/refined-space.js +64 -7
- package/dist/lang/ast/field-space/static-space.d.ts +6 -4
- package/dist/lang/ast/field-space/static-space.js +29 -9
- package/dist/lang/ast/query-elements/query-arrow.js +2 -2
- package/dist/lang/ast/query-elements/query-refine.js +1 -1
- package/dist/lang/ast/query-items/field-declaration.d.ts +2 -2
- package/dist/lang/ast/query-items/field-declaration.js +2 -2
- package/dist/lang/ast/query-properties/qop-desc.js +1 -1
- package/dist/lang/ast/source-elements/refined-source.js +7 -134
- package/dist/lang/ast/types/field-space.d.ts +3 -3
- package/dist/lang/ast/view-elements/qop-desc-view.js +1 -1
- package/dist/lang/ast/view-elements/view-arrow.js +1 -1
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +4 -4
- package/dist/lang/lib/Malloy/MalloyParser.js +13 -15
- package/dist/lang/malloy-to-ast.js +5 -9
- package/dist/lang/parse-log.d.ts +3 -0
- package/dist/lang/test/parse-expects.js +1 -1
- package/dist/lang/test/test-translator.js +1 -1
- package/dist/model/composite_source_utils.d.ts +1 -0
- package/dist/model/composite_source_utils.js +24 -3
- package/dist/model/malloy_query.js +4 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
package/dist/api/core.js
CHANGED
|
@@ -437,6 +437,21 @@ function statedCompileQuery(state) {
|
|
|
437
437
|
const modelAnnotations = (0, annotation_1.annotationToTaglines)(result.modelDef.annotation).map(l => ({
|
|
438
438
|
value: l,
|
|
439
439
|
}));
|
|
440
|
+
let source;
|
|
441
|
+
if (query.compositeResolvedSourceDef) {
|
|
442
|
+
source = query.compositeResolvedSourceDef;
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
if ((0, model_1.refIsStructDef)(query.structRef)) {
|
|
446
|
+
source = query.structRef;
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
source = result.modelDef.contents[query.structRef];
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const sourceAnnotations = (0, annotation_1.annotationToTaglines)(source.annotation).map(l => ({
|
|
453
|
+
value: l,
|
|
454
|
+
}));
|
|
440
455
|
annotations.push({
|
|
441
456
|
value: malloy_tag_1.Tag.withPrefix('#(malloy) ')
|
|
442
457
|
.set(['source_name'], translatedQuery.sourceExplore)
|
|
@@ -454,9 +469,10 @@ function statedCompileQuery(state) {
|
|
|
454
469
|
sql: translatedQuery.sql,
|
|
455
470
|
schema,
|
|
456
471
|
connection_name: translatedQuery.connectionName,
|
|
457
|
-
annotations: annotations
|
|
458
|
-
model_annotations: modelAnnotations
|
|
472
|
+
annotations: annotationsOrUndefined(annotations),
|
|
473
|
+
model_annotations: annotationsOrUndefined(modelAnnotations),
|
|
459
474
|
query_timezone: translatedQuery.queryTimezone,
|
|
475
|
+
source_annotations: annotationsOrUndefined(sourceAnnotations),
|
|
460
476
|
},
|
|
461
477
|
default_row_limit_added: translatedQuery.defaultRowLimitAdded,
|
|
462
478
|
};
|
|
@@ -480,4 +496,7 @@ function statedCompileQuery(state) {
|
|
|
480
496
|
}
|
|
481
497
|
}
|
|
482
498
|
exports.statedCompileQuery = statedCompileQuery;
|
|
499
|
+
function annotationsOrUndefined(annotations) {
|
|
500
|
+
return annotations.length > 0 ? annotations : undefined;
|
|
501
|
+
}
|
|
483
502
|
//# sourceMappingURL=core.js.map
|
|
@@ -363,5 +363,26 @@ exports.PRESTO_DIALECT_FUNCTIONS = {
|
|
|
363
363
|
...(0, util_1.def)('array_sort_desc', { 'x': { array: T } }, { array: T }),
|
|
364
364
|
...(0, util_1.def)('remove_nulls', { 'x': { array: T } }, { array: T }),
|
|
365
365
|
...(0, util_1.def)('array_top_n', { 'x': { array: T }, 'n': 'number' }, { array: T }),
|
|
366
|
+
// presto with more parameters
|
|
367
|
+
hll_accumulate: {
|
|
368
|
+
default: {
|
|
369
|
+
takes: { 'value': { dimension: T } },
|
|
370
|
+
returns: { measure: { sql_native: 'hyperloglog' } },
|
|
371
|
+
generic: {
|
|
372
|
+
'T': ['string', 'number', 'date', 'timestamp', 'boolean', 'json'],
|
|
373
|
+
},
|
|
374
|
+
isSymmetric: true,
|
|
375
|
+
impl: { sql: 'APPROX_SET(${value}, 0.0040625)' },
|
|
376
|
+
},
|
|
377
|
+
with_percent: {
|
|
378
|
+
takes: { 'value': { dimension: T }, 'accuracy': 'number' },
|
|
379
|
+
returns: { measure: { sql_native: 'hyperloglog' } },
|
|
380
|
+
generic: {
|
|
381
|
+
'T': ['string', 'number', 'date', 'timestamp', 'boolean', 'json'],
|
|
382
|
+
},
|
|
383
|
+
isSymmetric: true,
|
|
384
|
+
impl: { sql: 'APPROX_SET(${value}, 0.0040625)' },
|
|
385
|
+
},
|
|
386
|
+
},
|
|
366
387
|
};
|
|
367
388
|
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StructDef } from '../../../model/malloy_types';
|
|
1
|
+
import type { AccessModifierLabel, StructDef } from '../../../model/malloy_types';
|
|
2
2
|
import type { BinaryMalloyOperator } from '../types/binary_operators';
|
|
3
3
|
import type { ExprValue } from '../types/expr-value';
|
|
4
4
|
import { ExpressionDef } from '../types/expression-def';
|
|
@@ -15,7 +15,7 @@ export declare class ConstantFieldSpace implements FieldSpace {
|
|
|
15
15
|
dialectName(): string;
|
|
16
16
|
dialectObj(): undefined;
|
|
17
17
|
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
18
|
-
|
|
18
|
+
accessProtectionLevel(): AccessModifierLabel;
|
|
19
19
|
}
|
|
20
20
|
export declare class ConstantExpression extends ExpressionDef {
|
|
21
21
|
readonly expr: ExpressionDef;
|
|
@@ -156,7 +156,7 @@ class DynamicSpace extends static_space_1.StaticSpace {
|
|
|
156
156
|
}
|
|
157
157
|
// Add access modifiers at the end so views don't obey them
|
|
158
158
|
for (const [name, access] of this.newAccessModifiers) {
|
|
159
|
-
const index = this.sourceDef.fields.findIndex(f => { var _a; return (_a = f.as) !== null && _a !== void 0 ? _a : f.name === name; });
|
|
159
|
+
const index = this.sourceDef.fields.findIndex(f => { var _a; return ((_a = f.as) !== null && _a !== void 0 ? _a : f.name) === name; });
|
|
160
160
|
if (index === -1) {
|
|
161
161
|
throw new Error(`Can't find field '${name}' to set access modifier`);
|
|
162
162
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AccessModifierLabel, Annotation, DocumentLocation, SourceDef } from '../../../model/malloy_types';
|
|
2
|
+
import type { IncludeItem } from '../source-query-elements/include-item';
|
|
3
|
+
import type { FieldReference } from '../query-items/field-references';
|
|
4
|
+
export interface JoinIncludeProcessingState {
|
|
5
|
+
star: AccessModifierLabel | 'inherit' | 'except' | undefined;
|
|
6
|
+
starNote: Annotation | undefined;
|
|
7
|
+
fieldsIncluded: Set<string>;
|
|
8
|
+
joinNames: Set<string>;
|
|
9
|
+
fieldsExcepted: Set<string>;
|
|
10
|
+
allFields: Set<string>;
|
|
11
|
+
alreadyPrivateFields: Set<string>;
|
|
12
|
+
modifiers: Map<string, AccessModifierLabel>;
|
|
13
|
+
renames: {
|
|
14
|
+
as: string;
|
|
15
|
+
name: FieldReference;
|
|
16
|
+
location: DocumentLocation;
|
|
17
|
+
}[];
|
|
18
|
+
fieldsToInclude: Set<string> | undefined;
|
|
19
|
+
notes: Map<string, Annotation>;
|
|
20
|
+
}
|
|
21
|
+
export interface IncludeProcessingState {
|
|
22
|
+
joins: {
|
|
23
|
+
path: string[];
|
|
24
|
+
state: JoinIncludeProcessingState;
|
|
25
|
+
}[];
|
|
26
|
+
}
|
|
27
|
+
export declare function getIncludeStateForJoin(joinPath: string[], state: IncludeProcessingState): JoinIncludeProcessingState;
|
|
28
|
+
export declare function processIncludeList(includeItems: IncludeItem[] | undefined, from: SourceDef): IncludeProcessingState;
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.processIncludeList = exports.getIncludeStateForJoin = void 0;
|
|
10
|
+
const malloy_types_1 = require("../../../model/malloy_types");
|
|
11
|
+
const include_item_1 = require("../source-query-elements/include-item");
|
|
12
|
+
const field_references_1 = require("../query-items/field-references");
|
|
13
|
+
const composite_source_utils_1 = require("../../../model/composite_source_utils");
|
|
14
|
+
function getJoinFields(from, joinPath, logTo) {
|
|
15
|
+
let fields = from.fields;
|
|
16
|
+
for (const joinName of joinPath) {
|
|
17
|
+
const join = fields.find(f => { var _a; return ((_a = f.as) !== null && _a !== void 0 ? _a : f.name) === joinName; });
|
|
18
|
+
if (join === undefined) {
|
|
19
|
+
logTo.logError('field-not-found', `\`${joinName}\` not found`);
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
if (!(0, malloy_types_1.isJoined)(join)) {
|
|
23
|
+
logTo.logError('field-not-found', `\`${joinName}\` is not a join`);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
fields = join.fields;
|
|
27
|
+
}
|
|
28
|
+
return fields;
|
|
29
|
+
}
|
|
30
|
+
function getIncludeStateForJoin(joinPath, state) {
|
|
31
|
+
const joinState = state.joins.find(s => (0, composite_source_utils_1.pathEq)(s.path, joinPath));
|
|
32
|
+
if (joinState !== undefined)
|
|
33
|
+
return joinState.state;
|
|
34
|
+
return {
|
|
35
|
+
star: undefined,
|
|
36
|
+
starNote: undefined,
|
|
37
|
+
joinNames: new Set(),
|
|
38
|
+
fieldsIncluded: new Set(),
|
|
39
|
+
fieldsExcepted: new Set(),
|
|
40
|
+
allFields: new Set(),
|
|
41
|
+
alreadyPrivateFields: new Set(),
|
|
42
|
+
modifiers: new Map(),
|
|
43
|
+
renames: [],
|
|
44
|
+
notes: new Map(),
|
|
45
|
+
fieldsToInclude: undefined,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.getIncludeStateForJoin = getIncludeStateForJoin;
|
|
49
|
+
function getOrCreateIncludeStateForJoin(joinPath, state, from, logTo) {
|
|
50
|
+
const joinState = state.joins.find(s => (0, composite_source_utils_1.pathEq)(s.path, joinPath));
|
|
51
|
+
if (joinState !== undefined)
|
|
52
|
+
return joinState.state;
|
|
53
|
+
else {
|
|
54
|
+
const fromFields = getJoinFields(from, joinPath, logTo);
|
|
55
|
+
const allFields = new Set(fromFields.map(f => { var _a; return (_a = f.as) !== null && _a !== void 0 ? _a : f.name; }));
|
|
56
|
+
const joinNames = new Set(fromFields.filter(f => (0, malloy_types_1.isJoined)(f)).map(f => { var _a; return (_a = f.as) !== null && _a !== void 0 ? _a : f.name; }));
|
|
57
|
+
const alreadyPrivateFields = new Set(fromFields
|
|
58
|
+
.filter(f => f.accessModifier === 'private')
|
|
59
|
+
.map(f => { var _a; return (_a = f.as) !== null && _a !== void 0 ? _a : f.name; }));
|
|
60
|
+
const joinState = {
|
|
61
|
+
star: undefined,
|
|
62
|
+
joinNames,
|
|
63
|
+
starNote: undefined,
|
|
64
|
+
fieldsIncluded: new Set(),
|
|
65
|
+
fieldsExcepted: new Set(),
|
|
66
|
+
allFields,
|
|
67
|
+
alreadyPrivateFields,
|
|
68
|
+
modifiers: new Map(),
|
|
69
|
+
renames: [],
|
|
70
|
+
notes: new Map(),
|
|
71
|
+
fieldsToInclude: new Set(),
|
|
72
|
+
};
|
|
73
|
+
state.joins.push({ path: [...joinPath], state: joinState });
|
|
74
|
+
return joinState;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function checkParents(state, joinPath, from, f, kind) {
|
|
78
|
+
for (let prefixLength = 0; prefixLength < joinPath.length; prefixLength++) {
|
|
79
|
+
const parentPath = joinPath.slice(0, prefixLength);
|
|
80
|
+
const joinName = joinPath[prefixLength];
|
|
81
|
+
const parentState = getOrCreateIncludeStateForJoin(parentPath, state, from, f);
|
|
82
|
+
if (parentState.fieldsExcepted.has(joinName)) {
|
|
83
|
+
const action = kind === 'except' ? 'exclude' : 'include';
|
|
84
|
+
f.logError('include-after-exclude', `Cannot ${action} fields from \`${joinName}\` when \`${joinName}\` is itself excepted`);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
else if (parentState.alreadyPrivateFields.has(joinName) ||
|
|
88
|
+
parentState.modifiers.get(joinName) === 'private') {
|
|
89
|
+
f.logError('field-not-accessible', `\`${joinName}\` is private`);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
else if (kind === 'public') {
|
|
93
|
+
parentState.modifiers.set(joinName, 'public');
|
|
94
|
+
}
|
|
95
|
+
parentState.fieldsIncluded.add(joinName);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function processIncludeList(includeItems, from) {
|
|
99
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
100
|
+
const state = { joins: [] };
|
|
101
|
+
if (includeItems === undefined) {
|
|
102
|
+
return state;
|
|
103
|
+
}
|
|
104
|
+
for (const item of includeItems) {
|
|
105
|
+
if (item instanceof include_item_1.IncludeAccessItem) {
|
|
106
|
+
for (const f of item.fields) {
|
|
107
|
+
const joinPath = f.name instanceof field_references_1.WildcardFieldReference
|
|
108
|
+
? (_b = (_a = f.name.joinPath) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : []
|
|
109
|
+
: f.name.path.slice(0, -1);
|
|
110
|
+
const joinState = getOrCreateIncludeStateForJoin(joinPath, state, from, f);
|
|
111
|
+
checkParents(state, joinPath, from, f, item.kind);
|
|
112
|
+
if (f.name instanceof field_references_1.WildcardFieldReference) {
|
|
113
|
+
if (joinState.star !== undefined) {
|
|
114
|
+
item.logError('already-used-star-in-include', 'Wildcard already used in this include block');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
joinState.star = (_c = item.kind) !== null && _c !== void 0 ? _c : 'inherit';
|
|
118
|
+
joinState.starNote = {
|
|
119
|
+
notes: (_e = (_d = f.note) === null || _d === void 0 ? void 0 : _d.notes) !== null && _e !== void 0 ? _e : [],
|
|
120
|
+
blockNotes: (_g = (_f = item.note) === null || _f === void 0 ? void 0 : _f.blockNotes) !== null && _g !== void 0 ? _g : [],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (!joinState.allFields.has(f.name.getName())) {
|
|
126
|
+
item.logError('field-not-found', `\`${f.name.refString}\` not found`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const name = f.name.nameString;
|
|
130
|
+
if (joinState.joinNames.has(name)) {
|
|
131
|
+
const joinJoinState = getIncludeStateForJoin([...joinPath, name], state);
|
|
132
|
+
if (item.kind === 'private') {
|
|
133
|
+
// If we're making a join private, we need to make sure we didn't also make any
|
|
134
|
+
// of its fields public or internal
|
|
135
|
+
if (Object.values(joinJoinState.modifiers).some(m => m === 'public' || m === 'internal') ||
|
|
136
|
+
joinJoinState.star === 'internal' ||
|
|
137
|
+
joinJoinState.star === 'public') {
|
|
138
|
+
f.logError('cannot-expand-access', `Cannot make \`${name}\` and also make fields in \`${name}\` public or internal`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (joinState.alreadyPrivateFields.has(name)) {
|
|
144
|
+
f.logError('cannot-expand-access', `Cannot expand access of \`${name}\` from private to ${item.kind}`);
|
|
145
|
+
}
|
|
146
|
+
if (joinState.modifiers.has(name)) {
|
|
147
|
+
f.logError('duplicate-include', `Field \`${name}\` already referenced in include list`);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
if (item.kind !== undefined) {
|
|
151
|
+
joinState.modifiers.set((_h = f.as) !== null && _h !== void 0 ? _h : name, item.kind);
|
|
152
|
+
}
|
|
153
|
+
joinState.fieldsIncluded.add(name);
|
|
154
|
+
if (f.note || item.note) {
|
|
155
|
+
joinState.notes.set(name, {
|
|
156
|
+
notes: (_k = (_j = f.note) === null || _j === void 0 ? void 0 : _j.notes) !== null && _k !== void 0 ? _k : [],
|
|
157
|
+
blockNotes: (_m = (_l = item.note) === null || _l === void 0 ? void 0 : _l.blockNotes) !== null && _m !== void 0 ? _m : [],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (f.as) {
|
|
162
|
+
if (f.name instanceof field_references_1.WildcardFieldReference) {
|
|
163
|
+
f.logError('wildcard-include-rename', 'Cannot rename a wildcard field in an `include` block');
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
if (joinPath.length > 0) {
|
|
167
|
+
f.logError('cannot-rename-join-field', 'Cannot rename a joined field in an `include` block');
|
|
168
|
+
}
|
|
169
|
+
joinState.renames.push({
|
|
170
|
+
name: f.name,
|
|
171
|
+
as: f.as,
|
|
172
|
+
location: f.location,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (item instanceof include_item_1.IncludeExceptItem) {
|
|
180
|
+
for (const f of item.fields) {
|
|
181
|
+
const joinPath = f instanceof field_references_1.WildcardFieldReference
|
|
182
|
+
? (_p = (_o = f.joinPath) === null || _o === void 0 ? void 0 : _o.path) !== null && _p !== void 0 ? _p : []
|
|
183
|
+
: f.path.slice(0, -1);
|
|
184
|
+
const joinState = getOrCreateIncludeStateForJoin(joinPath, state, from, f);
|
|
185
|
+
checkParents(state, joinPath, from, f, item.kind);
|
|
186
|
+
if (f instanceof field_references_1.WildcardFieldReference) {
|
|
187
|
+
if (joinState.star !== undefined) {
|
|
188
|
+
item.logError('already-used-star-in-include', 'Wildcard already used in this include block');
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
joinState.star = 'except';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const name = f.getName();
|
|
196
|
+
if (!joinState.allFields.has(name)) {
|
|
197
|
+
item.logError('field-not-found', `\`${f.refString}\` not found`);
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (joinState.joinNames.has(name)) {
|
|
201
|
+
const joinJoinState = getIncludeStateForJoin([...joinPath, name], state);
|
|
202
|
+
const star = joinJoinState.star;
|
|
203
|
+
if (joinJoinState.fieldsIncluded.size > 0 ||
|
|
204
|
+
star === 'inherit' ||
|
|
205
|
+
star === 'public' ||
|
|
206
|
+
star === 'private' ||
|
|
207
|
+
star === 'internal') {
|
|
208
|
+
f.logError('exclude-after-include', `Cannot except \`${name}\` when fields from \`${name}\` are already included`);
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
else if (joinJoinState.fieldsExcepted.size > 0 ||
|
|
212
|
+
star === 'except') {
|
|
213
|
+
f.logError('exclude-after-exclude', `Cannot except \`${name}\` when fields from \`${name}\` are already excepted`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (joinState.star === 'except') {
|
|
218
|
+
item.logWarning('except-star-and-list', 'Excluding specific fields is unnecessary if also using `except: *`');
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
joinState.fieldsExcepted.add(f.nameString);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const join of state.joins) {
|
|
228
|
+
const joinState = join.state;
|
|
229
|
+
const starFields = new Set(joinState.allFields);
|
|
230
|
+
joinState.fieldsIncluded.forEach(f => starFields.delete(f));
|
|
231
|
+
joinState.fieldsExcepted.forEach(f => starFields.delete(f));
|
|
232
|
+
joinState.alreadyPrivateFields.forEach(f => starFields.delete(f));
|
|
233
|
+
if (joinState.star === 'except') {
|
|
234
|
+
joinState.fieldsToInclude = joinState.fieldsIncluded;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
joinState.fieldsToInclude = new Set(joinState.allFields);
|
|
238
|
+
for (const field of joinState.fieldsExcepted) {
|
|
239
|
+
joinState.fieldsToInclude.delete(field);
|
|
240
|
+
}
|
|
241
|
+
for (const field of starFields) {
|
|
242
|
+
if (joinState.star !== 'inherit') {
|
|
243
|
+
joinState.modifiers.set(field, (_q = joinState.star) !== null && _q !== void 0 ? _q : 'private');
|
|
244
|
+
}
|
|
245
|
+
if (joinState.starNote) {
|
|
246
|
+
joinState.notes.set(field, { ...joinState.starNote });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// TODO: validate that a field isn't renamed more than once
|
|
252
|
+
// TODO: validate that excluded fields are not referenced by included fields
|
|
253
|
+
// TODO: make renames fields work in existing references
|
|
254
|
+
// TODO: make renames that would replace an excluded field don't do that
|
|
255
|
+
return state;
|
|
256
|
+
}
|
|
257
|
+
exports.processIncludeList = processIncludeList;
|
|
258
|
+
//# sourceMappingURL=include-utils.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Dialect } from '../../../dialect';
|
|
2
|
-
import type { StructDef } from '../../../model';
|
|
2
|
+
import type { AccessModifierLabel, StructDef } from '../../../model';
|
|
3
3
|
import type { HasParameter } from '../parameters/has-parameter';
|
|
4
4
|
import type { FieldName, FieldSpace, QueryFieldSpace } from '../types/field-space';
|
|
5
5
|
import type { LookupResult } from '../types/lookup-result';
|
|
@@ -16,5 +16,5 @@ export declare class ParameterSpace implements FieldSpace {
|
|
|
16
16
|
dialectName(): string;
|
|
17
17
|
dialectObj(): Dialect | undefined;
|
|
18
18
|
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
19
|
-
|
|
19
|
+
accessProtectionLevel(): AccessModifierLabel;
|
|
20
20
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* expressions in the query is called the "input space". There is a
|
|
6
6
|
* specialized QuerySpace for each type of query operation.
|
|
7
7
|
*/
|
|
8
|
-
import type { SourceDef } from '../../../model';
|
|
8
|
+
import type { AccessModifierLabel, SourceDef } from '../../../model';
|
|
9
9
|
import type { AtomicFieldDeclaration } from '../query-items/field-declaration';
|
|
10
10
|
import { Join } from '../source-properties/join';
|
|
11
11
|
import type { QueryFieldSpace } from '../types/field-space';
|
|
@@ -13,7 +13,7 @@ import type { QueryOperationSpace } from './query-spaces';
|
|
|
13
13
|
import { RefinedSpace } from './refined-space';
|
|
14
14
|
export declare class QueryInputSpace extends RefinedSpace implements QueryFieldSpace {
|
|
15
15
|
private queryOutput;
|
|
16
|
-
readonly
|
|
16
|
+
readonly _accessProtectionLevel: AccessModifierLabel;
|
|
17
17
|
extendList: string[];
|
|
18
18
|
/**
|
|
19
19
|
* Because of circularity concerns this constructor is not typed
|
|
@@ -21,10 +21,10 @@ export declare class QueryInputSpace extends RefinedSpace implements QueryFieldS
|
|
|
21
21
|
* @param input The source which might be extended
|
|
22
22
|
* @param queryOutput MUST BE A QuerySpace
|
|
23
23
|
*/
|
|
24
|
-
constructor(input: SourceDef, queryOutput: QueryOperationSpace,
|
|
24
|
+
constructor(input: SourceDef, queryOutput: QueryOperationSpace, _accessProtectionLevel: AccessModifierLabel);
|
|
25
25
|
extendSource(extendField: Join | AtomicFieldDeclaration): void;
|
|
26
26
|
isQueryFieldSpace(): this is QueryFieldSpace;
|
|
27
27
|
outputSpace(): QueryOperationSpace;
|
|
28
28
|
inputSpace(): this;
|
|
29
|
-
|
|
29
|
+
accessProtectionLevel(): AccessModifierLabel;
|
|
30
30
|
}
|
|
@@ -32,10 +32,10 @@ class QueryInputSpace extends refined_space_1.RefinedSpace {
|
|
|
32
32
|
* @param input The source which might be extended
|
|
33
33
|
* @param queryOutput MUST BE A QuerySpace
|
|
34
34
|
*/
|
|
35
|
-
constructor(input, queryOutput,
|
|
35
|
+
constructor(input, queryOutput, _accessProtectionLevel) {
|
|
36
36
|
super(input);
|
|
37
37
|
this.queryOutput = queryOutput;
|
|
38
|
-
this.
|
|
38
|
+
this._accessProtectionLevel = _accessProtectionLevel;
|
|
39
39
|
this.extendList = [];
|
|
40
40
|
}
|
|
41
41
|
extendSource(extendField) {
|
|
@@ -56,8 +56,8 @@ class QueryInputSpace extends refined_space_1.RefinedSpace {
|
|
|
56
56
|
inputSpace() {
|
|
57
57
|
return this;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
return this.
|
|
59
|
+
accessProtectionLevel() {
|
|
60
|
+
return this._accessProtectionLevel;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
exports.QueryInputSpace = QueryInputSpace;
|
|
@@ -41,6 +41,7 @@ export declare abstract class QueryOperationSpace extends RefinedSpace implement
|
|
|
41
41
|
constructor(queryInputSpace: SourceFieldSpace, refineThis: model.PipeSegment | undefined, nestParent: QueryOperationSpace | undefined, astEl: MalloyElement);
|
|
42
42
|
abstract addRefineFromFields(refineThis: model.PipeSegment): void;
|
|
43
43
|
logError<T extends MessageCode>(code: T, parameters: MessageParameterType<T>, options?: Omit<LogMessageOptions, 'severity'>): T;
|
|
44
|
+
accessProtectionLevel(): model.AccessModifierLabel;
|
|
44
45
|
inputSpace(): QueryInputSpace;
|
|
45
46
|
outputSpace(): QueryOperationSpace;
|
|
46
47
|
protected addWild(wild: WildcardFieldReference): void;
|
|
@@ -81,7 +81,7 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
|
81
81
|
// (or `getPipeSegment` for index segments); if anyone
|
|
82
82
|
// tries to access it before that, they'll get an error
|
|
83
83
|
this._fieldUsage = undefined;
|
|
84
|
-
this.exprSpace = new query_input_space_1.QueryInputSpace(queryInputSpace.structDef(), this, queryInputSpace.
|
|
84
|
+
this.exprSpace = new query_input_space_1.QueryInputSpace(queryInputSpace.structDef(), this, queryInputSpace.accessProtectionLevel());
|
|
85
85
|
if (refineThis)
|
|
86
86
|
this.addRefineFromFields(refineThis);
|
|
87
87
|
}
|
|
@@ -91,6 +91,9 @@ class QueryOperationSpace extends refined_space_1.RefinedSpace {
|
|
|
91
91
|
}
|
|
92
92
|
return code;
|
|
93
93
|
}
|
|
94
|
+
accessProtectionLevel() {
|
|
95
|
+
return 'public';
|
|
96
|
+
}
|
|
94
97
|
inputSpace() {
|
|
95
98
|
return this.exprSpace;
|
|
96
99
|
}
|
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AccessModifierLabel, type Annotation, type SourceDef } from '../../../model/malloy_types';
|
|
2
2
|
import type { FieldListEdit } from '../source-properties/field-list-edit';
|
|
3
3
|
import { DynamicSpace } from './dynamic-space';
|
|
4
4
|
import type { MalloyElement } from '../types/malloy-element';
|
|
5
5
|
import type { ParameterSpace } from './parameter-space';
|
|
6
|
-
import type
|
|
6
|
+
import { type IncludeProcessingState } from './include-utils';
|
|
7
7
|
export declare class RefinedSpace extends DynamicSpace {
|
|
8
8
|
/**
|
|
9
9
|
* Factory for FieldSpace when there are accept/except edits
|
|
10
10
|
* @param from A structdef which seeds this space
|
|
11
11
|
* @param choose A accept/except edit of the "from" fields
|
|
12
12
|
*/
|
|
13
|
-
static filteredFrom(from: SourceDef, choose: FieldListEdit | undefined,
|
|
14
|
-
as: string;
|
|
15
|
-
name: FieldReference;
|
|
16
|
-
location: DocumentLocation;
|
|
17
|
-
}[] | undefined, parameters: ParameterSpace | undefined): RefinedSpace;
|
|
13
|
+
static filteredFrom(from: SourceDef, choose: FieldListEdit | undefined, includeState: IncludeProcessingState, parameters: ParameterSpace | undefined): RefinedSpace;
|
|
18
14
|
pushFields(...defs: MalloyElement[]): void;
|
|
19
15
|
addField(def: MalloyElement): void;
|
|
20
16
|
addAccessModifiers(ams: Map<string, AccessModifierLabel>): void;
|
|
21
17
|
addNotes(notes: Map<string, Annotation>): void;
|
|
22
|
-
|
|
18
|
+
accessProtectionLevel(): AccessModifierLabel;
|
|
23
19
|
}
|
|
@@ -23,20 +23,27 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.RefinedSpace = void 0;
|
|
26
|
+
const malloy_types_1 = require("../../../model/malloy_types");
|
|
26
27
|
const dynamic_space_1 = require("./dynamic-space");
|
|
27
28
|
const space_entry_1 = require("../types/space-entry");
|
|
28
29
|
const rename_space_field_1 = require("./rename-space-field");
|
|
29
30
|
const space_field_1 = require("../types/space-field");
|
|
31
|
+
const include_utils_1 = require("./include-utils");
|
|
30
32
|
class RefinedSpace extends dynamic_space_1.DynamicSpace {
|
|
31
33
|
/**
|
|
32
34
|
* Factory for FieldSpace when there are accept/except edits
|
|
33
35
|
* @param from A structdef which seeds this space
|
|
34
36
|
* @param choose A accept/except edit of the "from" fields
|
|
35
37
|
*/
|
|
36
|
-
static filteredFrom(from, choose,
|
|
37
|
-
|
|
38
|
+
static filteredFrom(from, choose, includeState, parameters) {
|
|
39
|
+
var _a;
|
|
40
|
+
const edited = new RefinedSpace({
|
|
41
|
+
...from,
|
|
42
|
+
fields: editJoinsFromIncludeState([], from, includeState),
|
|
43
|
+
});
|
|
38
44
|
const renameMap = new Map();
|
|
39
|
-
|
|
45
|
+
const s = (0, include_utils_1.getIncludeStateForJoin)([], includeState);
|
|
46
|
+
for (const rename of (_a = s.renames) !== null && _a !== void 0 ? _a : []) {
|
|
40
47
|
if (renameMap.has(rename.name.refString)) {
|
|
41
48
|
rename.name.logError('already-renamed', `${rename.name.refString} already renamed to ${rename.as}`);
|
|
42
49
|
}
|
|
@@ -48,11 +55,11 @@ class RefinedSpace extends dynamic_space_1.DynamicSpace {
|
|
|
48
55
|
});
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
|
-
if (fieldsToInclude !== undefined) {
|
|
58
|
+
if (s.fieldsToInclude !== undefined) {
|
|
52
59
|
const oldMap = edited.entries();
|
|
53
60
|
edited.dropEntries();
|
|
54
61
|
for (const [symbol, value] of oldMap) {
|
|
55
|
-
if (fieldsToInclude.has(symbol)) {
|
|
62
|
+
if (s.fieldsToInclude.has(symbol)) {
|
|
56
63
|
const renamed = renameMap.get(symbol);
|
|
57
64
|
if (renamed) {
|
|
58
65
|
if (value instanceof space_field_1.SpaceField) {
|
|
@@ -119,9 +126,59 @@ class RefinedSpace extends dynamic_space_1.DynamicSpace {
|
|
|
119
126
|
this.newNotes.set(symbol, note);
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
return
|
|
129
|
+
accessProtectionLevel() {
|
|
130
|
+
return 'internal';
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
exports.RefinedSpace = RefinedSpace;
|
|
134
|
+
function editJoinsFromIncludeState(path, from, includeState) {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
let fields;
|
|
137
|
+
const joinedState = (0, include_utils_1.getIncludeStateForJoin)(path, includeState);
|
|
138
|
+
const isJoin = path.length > 0;
|
|
139
|
+
if (isJoin) {
|
|
140
|
+
if (joinedState.fieldsToInclude) {
|
|
141
|
+
fields = from.fields.filter(f => { var _a, _b; return (_a = joinedState.fieldsToInclude) === null || _a === void 0 ? void 0 : _a.has((_b = f.as) !== null && _b !== void 0 ? _b : f.name); });
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
fields = from.fields;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
fields = from.fields;
|
|
149
|
+
}
|
|
150
|
+
// const fields = from.fields;
|
|
151
|
+
const updatedFields = [];
|
|
152
|
+
for (const field of fields) {
|
|
153
|
+
const name = (_a = field.as) !== null && _a !== void 0 ? _a : field.name;
|
|
154
|
+
// TODO ensure you can't make it more permissive here...
|
|
155
|
+
const accessModifier = (_b = joinedState.modifiers.get(name)) !== null && _b !== void 0 ? _b : field.accessModifier;
|
|
156
|
+
const notes = joinedState.notes.get(name);
|
|
157
|
+
const rename = joinedState.renames.find(r => { var _a; return r.name.nameString === ((_a = field.as) !== null && _a !== void 0 ? _a : field.name); });
|
|
158
|
+
const editedField = isJoin
|
|
159
|
+
? {
|
|
160
|
+
...field,
|
|
161
|
+
as: rename ? rename.name.nameString : field.as,
|
|
162
|
+
accessModifier: accessModifier === 'public' ? undefined : accessModifier,
|
|
163
|
+
annotation: notes
|
|
164
|
+
? {
|
|
165
|
+
inherits: field.annotation,
|
|
166
|
+
blockNotes: notes.blockNotes,
|
|
167
|
+
notes: notes.notes,
|
|
168
|
+
}
|
|
169
|
+
: field.annotation,
|
|
170
|
+
}
|
|
171
|
+
: { ...field };
|
|
172
|
+
if ((0, malloy_types_1.isJoined)(editedField)) {
|
|
173
|
+
updatedFields.push({
|
|
174
|
+
...editedField,
|
|
175
|
+
fields: editJoinsFromIncludeState([...path, (_c = field.as) !== null && _c !== void 0 ? _c : field.name], editedField, includeState),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
updatedFields.push(editedField);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return updatedFields;
|
|
183
|
+
}
|
|
127
184
|
//# sourceMappingURL=refined-space.js.map
|