@malloydata/malloy 0.0.339 → 0.0.340

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,9 +1,8 @@
1
- import { Tag } from '@malloydata/malloy-tag';
1
+ import type { Tag } from '@malloydata/malloy-tag';
2
2
  import type { Annotation } from './model';
3
3
  import type { LogMessage } from './lang';
4
4
  export interface TagParseSpec {
5
5
  prefix?: RegExp;
6
- extending?: Tag;
7
6
  }
8
7
  export declare function annotationToTaglines(annote: Annotation | undefined, prefix?: RegExp): string[];
9
8
  export interface MalloyTagParse {
@@ -3,32 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.annotationToTaglines = annotationToTaglines;
4
4
  exports.annotationToTag = annotationToTag;
5
5
  const malloy_tag_1 = require("@malloydata/malloy-tag");
6
- function annotationToTaglines(annote, prefix) {
7
- annote || (annote = {});
8
- const tagLines = annote.inherits
9
- ? annotationToTaglines(annote.inherits, prefix)
6
+ /**
7
+ * Collect all matching Notes from an Annotation, walking the inherits
8
+ * chain. Returns notes in inheritance order (inherited first).
9
+ */
10
+ function collectNotes(annote, prefix) {
11
+ const inherited = annote.inherits
12
+ ? collectNotes(annote.inherits, prefix)
10
13
  : [];
11
- function prefixed(na) {
12
- const ret = [];
13
- for (const n of na || []) {
14
- if (prefix === undefined || n.text.match(prefix)) {
15
- ret.push(n.text);
16
- }
17
- }
18
- return ret;
19
- }
20
- return tagLines.concat(prefixed(annote.blockNotes), prefixed(annote.notes));
21
- }
22
- function annotationToTag(annote, spec = {}) {
23
- let extending = spec.extending || new malloy_tag_1.Tag();
24
- const prefix = spec.prefix || /^##? /;
25
- annote || (annote = {});
26
- const allErrs = [];
27
- if (annote.inherits) {
28
- const inherits = annotationToTag(annote.inherits, spec);
29
- allErrs.push(...inherits.log);
30
- extending = inherits.tag;
31
- }
32
14
  const allNotes = [];
33
15
  if (annote.blockNotes) {
34
16
  allNotes.push(...annote.blockNotes);
@@ -36,19 +18,32 @@ function annotationToTag(annote, spec = {}) {
36
18
  if (annote.notes) {
37
19
  allNotes.push(...annote.notes);
38
20
  }
39
- const matchingNotes = [];
40
- for (const note of allNotes) {
41
- if (note.text.match(prefix)) {
42
- matchingNotes.push(note);
43
- }
21
+ if (prefix) {
22
+ const matching = allNotes.filter(note => note.text.match(prefix));
23
+ return inherited.concat(matching);
44
24
  }
45
- for (const note of matchingNotes) {
46
- const noteParse = (0, malloy_tag_1.parseTag)(note.text, extending);
47
- extending = noteParse.tag;
25
+ return inherited.concat(allNotes);
26
+ }
27
+ function annotationToTaglines(annote, prefix) {
28
+ return collectNotes(annote || {}, prefix).map(n => n.text);
29
+ }
30
+ // TODO: Error location mapping currently works by post-hoc mapping
31
+ // parse errors back to source locations using the Note's `at` field.
32
+ // The proper approach is to pass source location information into the
33
+ // MOTLY parser session so that errors come back with correct locations
34
+ // directly, eliminating the need for this remapping step.
35
+ function annotationToTag(annote, spec = {}) {
36
+ const prefix = spec.prefix || /^##? /;
37
+ annote || (annote = {});
38
+ const notes = collectNotes(annote, prefix);
39
+ const allErrs = [];
40
+ const session = new malloy_tag_1.TagParser();
41
+ for (const note of notes) {
42
+ const noteParse = session.parse(note.text);
48
43
  allErrs.push(...noteParse.log.map((e) => mapMalloyError(e, note)));
49
44
  }
50
- // Validate references and add any warnings
51
- const refErrors = extending.validateReferences();
45
+ const tag = session.finish();
46
+ const refErrors = tag.validateReferences();
52
47
  for (const refError of refErrors) {
53
48
  allErrs.push({
54
49
  code: 'tag-reference-error',
@@ -56,7 +51,7 @@ function annotationToTag(annote, spec = {}) {
56
51
  message: refError,
57
52
  });
58
53
  }
59
- return { tag: extending, log: allErrs };
54
+ return { tag, log: allErrs };
60
55
  }
61
56
  function mapMalloyError(e, note) {
62
57
  // Calculate prefix length (same logic as parseTagLine)
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export type { Connection, ConnectionConfig, ConnectionParameterValue, FetchSchem
12
12
  export { registerConnectionType, getConnectionProperties, getRegisteredConnectionTypes, readConnectionsConfig, writeConnectionsConfig, createConnectionsFromConfig, } from './connection/registry';
13
13
  export type { ConnectionTypeFactory, ConnectionPropertyType, ConnectionPropertyDefinition, ConnectionTypeDef, ConnectionConfigEntry, ConnectionsConfig, } from './connection/registry';
14
14
  export { toAsyncGenerator } from './connection_utils';
15
- export { modelDefToModelInfo, sourceDefToSourceInfo, writeMalloyObjectToTag, extractMalloyObjectFromTag, } from './to_stable';
15
+ export { modelDefToModelInfo, sourceDefToSourceInfo } from './to_stable';
16
16
  export * as API from './api';
17
17
  export type { SQLSourceRequest } from './lang/translate-response';
18
18
  export { sqlKey } from './model/sql_block';
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.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.isCompoundArrayData = exports.isBasicAtomic = exports.isAtomic = 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.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 = exports.ConnectionRuntime = exports.AtomicFieldType = void 0;
37
+ exports.makeDigest = exports.PersistSource = exports.annotationToTaglines = exports.annotationToTag = exports.sqlKey = exports.API = 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 = exports.ConnectionRuntime = exports.AtomicFieldType = void 0;
38
38
  /*
39
39
  * Copyright 2023 Google LLC
40
40
  *
@@ -147,8 +147,6 @@ Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: func
147
147
  var to_stable_1 = require("./to_stable");
148
148
  Object.defineProperty(exports, "modelDefToModelInfo", { enumerable: true, get: function () { return to_stable_1.modelDefToModelInfo; } });
149
149
  Object.defineProperty(exports, "sourceDefToSourceInfo", { enumerable: true, get: function () { return to_stable_1.sourceDefToSourceInfo; } });
150
- Object.defineProperty(exports, "writeMalloyObjectToTag", { enumerable: true, get: function () { return to_stable_1.writeMalloyObjectToTag; } });
151
- Object.defineProperty(exports, "extractMalloyObjectFromTag", { enumerable: true, get: function () { return to_stable_1.extractMalloyObjectFromTag; } });
152
150
  exports.API = __importStar(require("./api"));
153
151
  var sql_block_1 = require("./model/sql_block");
154
152
  Object.defineProperty(exports, "sqlKey", { enumerable: true, get: function () { return sql_block_1.sqlKey; } });
@@ -1,6 +1,4 @@
1
1
  import type { Note } from '../../../model/malloy_types';
2
- import type { Tag } from '@malloydata/malloy-tag';
3
- import type { MessageLogger } from '../../parse-log';
4
2
  import type { Document, DocStatement } from './malloy-element';
5
3
  import { MalloyElement } from './malloy-element';
6
4
  import type { QueryPropertyInterface } from './query-property-interface';
@@ -14,6 +12,6 @@ export declare class ObjectAnnotation extends MalloyElement implements QueryProp
14
12
  }
15
13
  export declare class ModelAnnotation extends ObjectAnnotation implements DocStatement {
16
14
  elementType: string;
17
- getCompilerFlags(existing: Tag, logTo: MessageLogger): Tag;
15
+ getCompilerFlagLines(): string[];
18
16
  execute(doc: Document): void;
19
17
  }
@@ -24,7 +24,7 @@
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.ModelAnnotation = exports.ObjectAnnotation = void 0;
26
26
  const malloy_element_1 = require("./malloy-element");
27
- const annotation_1 = require("../../../annotation");
27
+ const COMPILER_FLAG_PREFIX = /^##! /;
28
28
  class ObjectAnnotation extends malloy_element_1.MalloyElement {
29
29
  constructor(notes) {
30
30
  super();
@@ -41,13 +41,10 @@ class ModelAnnotation extends ObjectAnnotation {
41
41
  super(...arguments);
42
42
  this.elementType = 'modelAnnotation';
43
43
  }
44
- getCompilerFlags(existing, logTo) {
45
- const tagParse = (0, annotation_1.annotationToTag)({ notes: this.notes }, {
46
- prefix: /^##! /,
47
- extending: existing,
48
- });
49
- tagParse.log.forEach(err => logTo.log(err));
50
- return tagParse.tag;
44
+ getCompilerFlagLines() {
45
+ return this.notes
46
+ .filter(note => note.text.match(COMPILER_FLAG_PREFIX))
47
+ .map(note => note.text);
51
48
  }
52
49
  execute(doc) {
53
50
  if (doc.annotation.notes === undefined) {
@@ -273,7 +273,7 @@ class MalloyElement {
273
273
  }
274
274
  inExperiment(experimentId, silent = false) {
275
275
  var _a;
276
- const experimental = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.compilerFlags.tag('experimental');
276
+ const experimental = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.getCompilerFlags().tag('experimental');
277
277
  const enabled = experimental && (experimental.bare() || experimental.has(experimentId));
278
278
  if (enabled) {
279
279
  return true;
@@ -30,12 +30,14 @@ type HasAnnotations = ParserRuleContext & {
30
30
  export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElement> implements MalloyParserVisitor<ast.MalloyElement> {
31
31
  readonly parseInfo: MalloyParseInfo;
32
32
  readonly msgLog: MessageLogger;
33
- compilerFlags: Tag;
34
33
  readonly timer: Timer;
35
- constructor(parseInfo: MalloyParseInfo, msgLog: MessageLogger, compilerFlags: Tag);
34
+ private compilerFlagSrc;
35
+ private compilerFlagTag?;
36
+ constructor(parseInfo: MalloyParseInfo, msgLog: MessageLogger, compilerFlagSrc: string[]);
37
+ getCompilerFlags(): Tag;
36
38
  run(): {
37
39
  ast: ast.MalloyElement;
38
- compilerFlags: Tag;
40
+ compilerFlagSrc: string[];
39
41
  timingInfo: Malloy.TimingInfo;
40
42
  };
41
43
  /**
@@ -88,25 +88,26 @@ const DEFAULT_COMPILER_FLAGS = [];
88
88
  * AST from an ANTLR parse tree.
89
89
  */
90
90
  class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
91
- constructor(parseInfo, msgLog, compilerFlags) {
91
+ constructor(parseInfo, msgLog, compilerFlagSrc) {
92
92
  super();
93
93
  this.parseInfo = parseInfo;
94
94
  this.msgLog = msgLog;
95
- this.compilerFlags = compilerFlags;
96
95
  this.timer = new timing_1.Timer('generate_ast');
97
96
  const parseCompilerFlagsTimer = new timing_1.Timer('parse_compiler_flags');
98
- for (const flag of DEFAULT_COMPILER_FLAGS) {
99
- const withNewTag = (0, malloy_tag_1.parseTag)(flag, this.compilerFlags);
100
- this.compilerFlags = withNewTag.tag;
101
- }
97
+ this.compilerFlagSrc = [...DEFAULT_COMPILER_FLAGS, ...compilerFlagSrc];
102
98
  this.timer.contribute([parseCompilerFlagsTimer.stop()]);
103
99
  }
100
+ getCompilerFlags() {
101
+ if (!this.compilerFlagTag) {
102
+ this.compilerFlagTag = (0, malloy_tag_1.parseTag)(this.compilerFlagSrc).tag;
103
+ }
104
+ return this.compilerFlagTag;
105
+ }
104
106
  run() {
105
107
  const ast = this.visit(this.parseInfo.root);
106
- const compilerFlags = this.compilerFlags;
107
108
  return {
108
109
  ast,
109
- compilerFlags,
110
+ compilerFlagSrc: this.compilerFlagSrc,
110
111
  timingInfo: this.timer.stop(),
111
112
  };
112
113
  }
@@ -157,7 +158,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
157
158
  }));
158
159
  }
159
160
  inExperiment(experimentId, cx) {
160
- const experimental = this.compilerFlags.tag('experimental');
161
+ const experimental = this.getCompilerFlags().tag('experimental');
161
162
  if (experimental &&
162
163
  (experimental.bare() || experimental.has(experimentId))) {
163
164
  return true;
@@ -1289,7 +1290,22 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1289
1290
  }
1290
1291
  updateCompilerFlags(tags) {
1291
1292
  const parseCompilerFlagsTimer = new timing_1.Timer('parse_compiler_flags');
1292
- this.compilerFlags = tags.getCompilerFlags(this.compilerFlags, this.msgLog);
1293
+ const newLines = tags.getCompilerFlagLines();
1294
+ if (newLines.length > 0) {
1295
+ const oldLength = this.compilerFlagSrc.length;
1296
+ this.compilerFlagSrc.push(...newLines);
1297
+ const { tag, log } = (0, malloy_tag_1.parseTag)(this.compilerFlagSrc);
1298
+ this.compilerFlagTag = tag;
1299
+ for (const err of log) {
1300
+ if (err.line >= oldLength) {
1301
+ this.msgLog.log({
1302
+ code: 'tag-parse-error',
1303
+ severity: 'error',
1304
+ message: err.message,
1305
+ });
1306
+ }
1307
+ }
1308
+ }
1293
1309
  this.timer.contribute([parseCompilerFlagsTimer.stop()]);
1294
1310
  }
1295
1311
  visitDocAnnotations(pcx) {
@@ -5,7 +5,7 @@ import type { ZoneData } from './zone';
5
5
  import { Zone } from './zone';
6
6
  import { ReferenceList } from './reference-list';
7
7
  import type { ResponseBase, ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse, TablePathResponse } from './translate-response';
8
- import { Tag } from '@malloydata/malloy-tag';
8
+ import type { Tag } from '@malloydata/malloy-tag';
9
9
  import type { MalloyParseInfo } from './malloy-parse-info';
10
10
  import type { EventStream } from '../runtime_types';
11
11
  import type { ParserRuleContext } from 'antlr4ts';
@@ -114,7 +114,8 @@ export declare abstract class MalloyTranslation {
114
114
  modelDef: ModelDef;
115
115
  modelWasModified: boolean;
116
116
  imports: ImportLocation[];
117
- compilerFlags: Tag;
117
+ compilerFlagSrc: string[];
118
+ getCompilerFlags(): Tag;
118
119
  readonly parseStep: ParseStep;
119
120
  readonly modelAnnotationStep: ModelAnnotationStep;
120
121
  readonly importsAndTablesStep: ImportsAndTablesStep;
@@ -234,10 +234,10 @@ class ASTStep {
234
234
  throw new Error('TRANSLATOR INTERNAL ERROR: Translator parse response had no errors, but also no parser');
235
235
  }
236
236
  stepTimer.incorporate(parseResponse.timingInfo);
237
- const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger, that.compilerFlags);
238
- const { ast: newAST, compilerFlags, timingInfo } = secondPass.run();
237
+ const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger, that.compilerFlagSrc);
238
+ const { ast: newAST, compilerFlagSrc, timingInfo } = secondPass.run();
239
239
  stepTimer.contribute([timingInfo]);
240
- that.compilerFlags = compilerFlags;
240
+ that.compilerFlagSrc = compilerFlagSrc;
241
241
  if (newAST.elementType === 'unimplemented') {
242
242
  newAST.logError('untranslated-parse-node', 'INTERNAL COMPILER ERROR: Untranslated parse node');
243
243
  }
@@ -425,11 +425,8 @@ class TranslateStep {
425
425
  // begin with the compiler flags of the model we are extending
426
426
  if (extendingModel && !this.importedAnnotations) {
427
427
  const parseCompilerFlagsTimer = new timing_1.Timer('parse_compiler_flags');
428
- const tagParse = (0, annotation_1.annotationToTag)(extendingModel.annotation, {
429
- prefix: /^##! /,
430
- });
428
+ that.compilerFlagSrc = (0, annotation_1.annotationToTaglines)(extendingModel.annotation, /^##! /);
431
429
  stepTimer.contribute([parseCompilerFlagsTimer.stop()]);
432
- that.compilerFlags = tagParse.tag;
433
430
  this.importedAnnotations = true;
434
431
  }
435
432
  const astResponse = this.astStep.step(that);
@@ -488,6 +485,9 @@ class TranslateStep {
488
485
  }
489
486
  }
490
487
  class MalloyTranslation {
488
+ getCompilerFlags() {
489
+ return (0, malloy_tag_1.parseTag)(this.compilerFlagSrc).tag;
490
+ }
491
491
  constructor(sourceURL, importBaseURL = null, grammarRule = 'malloyDocument') {
492
492
  this.sourceURL = sourceURL;
493
493
  this.importBaseURL = importBaseURL;
@@ -495,7 +495,7 @@ class MalloyTranslation {
495
495
  this.sqlSources = [];
496
496
  this.modelWasModified = false;
497
497
  this.imports = [];
498
- this.compilerFlags = new malloy_tag_1.Tag();
498
+ this.compilerFlagSrc = [];
499
499
  this._urlIsFullPath = undefined;
500
500
  /*
501
501
  Experimental dialect support, not confident this is how this should work.
@@ -753,7 +753,7 @@ class MalloyTranslation {
753
753
  if (this.allDialectsEnabled) {
754
754
  return true;
755
755
  }
756
- const experimental = this.compilerFlags.tag('experimental');
756
+ const experimental = this.getCompilerFlags().tag('experimental');
757
757
  return (experimental !== undefined &&
758
758
  (experimental.bare() || experimental.has('dialect', dialect)));
759
759
  }
@@ -6,15 +6,3 @@ export declare function modelDefToModelInfo(modelDef: ModelDef): Malloy.ModelInf
6
6
  export declare function convertFieldInfos(source: SourceDef, fields: FieldDef[]): Malloy.FieldInfo[];
7
7
  export declare function writeLiteralToTag(tag: Tag, path: (string | number)[], literal: Malloy.LiteralValue): void;
8
8
  export declare function getResultStructMetadataAnnotation(field: SourceDef, resultMetadata: ResultStructMetadataDef): Malloy.Annotation | undefined;
9
- /**
10
- * Writes a Malloy interface object to a tag at a given path.
11
- *
12
- * E.g. `writeMalloyObjectToTag(tag, ['expr'], 'Expression', {kind: 'field_reference', name: 'carrier'})`
13
- *
14
- * produces the tag `#(malloy) expr { kind = field_reference name = carrier }`
15
- */
16
- export declare function writeMalloyObjectToTag(tag: Tag, path: (string | number)[], obj: unknown, type: string): void;
17
- /**
18
- * Extracts a Malloy interface object from a tag at a given path; the inverse of `writeMalloyObjectToTag`.
19
- */
20
- export declare function extractMalloyObjectFromTag(tag: Tag, type: string): unknown;
package/dist/to_stable.js CHANGED
@@ -44,8 +44,6 @@ exports.modelDefToModelInfo = modelDefToModelInfo;
44
44
  exports.convertFieldInfos = convertFieldInfos;
45
45
  exports.writeLiteralToTag = writeLiteralToTag;
46
46
  exports.getResultStructMetadataAnnotation = getResultStructMetadataAnnotation;
47
- exports.writeMalloyObjectToTag = writeMalloyObjectToTag;
48
- exports.extractMalloyObjectFromTag = extractMalloyObjectFromTag;
49
47
  const Malloy = __importStar(require("@malloydata/malloy-interfaces"));
50
48
  const model_1 = require("./model");
51
49
  const annotation_1 = require("./annotation");
@@ -510,6 +508,11 @@ function convertJoinType(type) {
510
508
  * E.g. `writeMalloyObjectToTag(tag, ['expr'], 'Expression', {kind: 'field_reference', name: 'carrier'})`
511
509
  *
512
510
  * produces the tag `#(malloy) expr { kind = field_reference name = carrier }`
511
+ *
512
+ * Note: The inverse function `extractMalloyObjectFromTag` lives in the
513
+ * renderer (malloy-render/src/data_tree/utils.ts) since that is its only
514
+ * consumer. These two functions are kept separate to avoid the renderer
515
+ * depending on the malloy core package for deserialization.
513
516
  */
514
517
  function writeMalloyObjectToTag(tag, path, obj, type) {
515
518
  if (type === 'string') {
@@ -571,75 +574,8 @@ function writeMalloyObjectToTag(tag, path, obj, type) {
571
574
  writeMalloyObjectToTag(tag, path, obj, unionType);
572
575
  }
573
576
  }
574
- /**
575
- * Extracts a Malloy interface object from a tag at a given path; the inverse of `writeMalloyObjectToTag`.
576
- */
577
- function extractMalloyObjectFromTag(tag, type) {
578
- if (type === 'string') {
579
- return tag.text();
580
- }
581
- else if (type === 'number') {
582
- return tag.numeric();
583
- }
584
- else if (type === 'boolean') {
585
- return tag.text() === 'true';
586
- }
587
- const typeDef = Malloy.MALLOY_INTERFACE_TYPES[type];
588
- if (typeDef === undefined) {
589
- throw new Error(`Unknown Malloy interface type ${type}`);
590
- }
591
- if (typeDef.type === 'enum') {
592
- const value = tag.text();
593
- if (value === undefined) {
594
- throw new Error(`Missing value for enum ${type}`);
595
- }
596
- if (value in typeDef.values) {
597
- return value;
598
- }
599
- throw new Error(`Unknown value ${value} for enum ${type}`);
600
- }
601
- else if (typeDef.type === 'struct') {
602
- const result = {};
603
- for (const [key, type] of Object.entries(typeDef.fields)) {
604
- const valueTag = tag.tag(key);
605
- if (valueTag === undefined) {
606
- if (type.optional)
607
- continue;
608
- else {
609
- throw new Error(`Missing value for key ${key} of type ${type}`);
610
- }
611
- }
612
- if (type.array) {
613
- const arr = [];
614
- const values = valueTag.array();
615
- if (values === undefined) {
616
- throw new Error(`Missing array value for key ${key} of type ${type}`);
617
- }
618
- for (const value of values) {
619
- arr.push(extractMalloyObjectFromTag(value, type.type));
620
- }
621
- result[key] = arr;
622
- }
623
- else {
624
- const value = extractMalloyObjectFromTag(valueTag, type.type);
625
- if (value !== undefined && value !== null) {
626
- result[key] = value;
627
- }
628
- }
629
- }
630
- return result;
631
- } /* (typeDef.type === 'union') */
632
- else {
633
- const kind = tag.text('kind');
634
- if (kind === undefined) {
635
- throw new Error(`Missing kind for union ${type}`);
636
- }
637
- const unionType = typeDef.options[kind];
638
- if (unionType === undefined) {
639
- throw new Error(`Unknown kind ${kind} for union ${type}`);
640
- }
641
- const value = extractMalloyObjectFromTag(tag, unionType);
642
- return { kind, ...value };
643
- }
644
- }
577
+ // Note: The inverse function `extractMalloyObjectFromTag` lives in the
578
+ // renderer (malloy-render/src/data_tree/utils.ts) since that is its only
579
+ // consumer. These two functions are kept separate to avoid the renderer
580
+ // depending on the malloy core package for deserialization.
645
581
  //# sourceMappingURL=to_stable.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.339";
1
+ export declare const MALLOY_VERSION = "0.0.340";
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.339';
5
+ exports.MALLOY_VERSION = '0.0.340';
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.339",
3
+ "version": "0.0.340",
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.339",
49
- "@malloydata/malloy-interfaces": "0.0.339",
50
- "@malloydata/malloy-tag": "0.0.339",
48
+ "@malloydata/malloy-filter": "0.0.340",
49
+ "@malloydata/malloy-interfaces": "0.0.340",
50
+ "@malloydata/malloy-tag": "0.0.340",
51
51
  "@noble/hashes": "^1.8.0",
52
52
  "antlr4ts": "^0.5.0-alpha.4",
53
53
  "assert": "^2.0.0",