@nova-energy/openamx 0.18.0 → 0.21.0

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.
@@ -3,7 +3,7 @@ import { inputError, throwInputErrors } from '../diagnostics/errors';
3
3
  import { Environment } from './environment';
4
4
  import { evaluateExpression } from './evaluateExpression';
5
5
  import { parseStrictCsvText, parseStrictJsonText } from './dataText';
6
- import { isMeasurement, measurement } from './measurement';
6
+ import { isMeasurement, measurement, measurementPhysicalValue } from './measurement';
7
7
  import { ExternalUnitTextError, parseExternalUnitText } from './externalUnits';
8
8
  import { fieldRegistry } from '../typechecker/declarationRegistry';
9
9
  function defaultsEnvironment(environment, registry) {
@@ -15,12 +15,12 @@ export { parseStrictCsvText, parseStrictJsonText } from './dataText';
15
15
  export { serializeCsvText } from './csvTextSerialization';
16
16
  class StopValidation {
17
17
  }
18
- export function describeInputSchema(declaration, types, registry) {
18
+ export function describeInputSchema(declaration, types, registry, enums) {
19
19
  const recordType = declaration.annotation.type === 'listType'
20
20
  && declaration.annotation.element?.type === 'namedType'
21
21
  ? types.get(declaration.annotation.element.name)
22
22
  : undefined;
23
- const csvCompatible = !!recordType && recordType.fields.every(field => isCsvScalar(field.annotation, fieldRegistry(field, registry)));
23
+ const csvCompatible = !!recordType && recordType.fields.every(field => isCsvScalar(field.annotation, fieldRegistry(field, registry), enums));
24
24
  return {
25
25
  name: declaration.name,
26
26
  type: typeName(declaration.annotation),
@@ -38,7 +38,7 @@ export function describeInputSchema(declaration, types, registry) {
38
38
  }) } : {})
39
39
  };
40
40
  }
41
- export function validateInputText(text, format, declaration, types, mode = 'aggregate', context = {}, registry) {
41
+ export function validateInputText(text, format, declaration, types, mode = 'aggregate', context = {}, registry, enums) {
42
42
  if (mode !== 'aggregate' && mode !== 'fail-fast') {
43
43
  return { diagnostics: [inputError('AMX4001', `Unsupported validation mode '${safeText(String(mode))}'`, { ...context, inputName: declaration.name })] };
44
44
  }
@@ -49,7 +49,7 @@ export function validateInputText(text, format, declaration, types, mode = 'aggr
49
49
  throw new StopValidation();
50
50
  };
51
51
  const validationContext = { ...context, inputName: declaration.name, declarationSource: declaration.source };
52
- const environment = new Environment(types);
52
+ const environment = inputEnvironment(types, enums);
53
53
  let value;
54
54
  try {
55
55
  if (format === 'json') {
@@ -65,10 +65,10 @@ export function validateInputText(text, format, declaration, types, mode = 'aggr
65
65
  }));
66
66
  return { value: undefined, diagnostics };
67
67
  }
68
- value = convertJson(parsed.value, declaration.annotation, '', declaration.source, types, environment, report, validationContext, undefined, registry);
68
+ value = convertJson(parsed.value, declaration.annotation, '', declaration.source, types, environment, report, validationContext, undefined, registry, false, enums);
69
69
  }
70
70
  else {
71
- value = convertCsv(text, declaration.annotation, declaration.source, types, environment, report, validationContext, registry);
71
+ value = convertCsv(text, declaration.annotation, declaration.source, types, environment, report, validationContext, registry, enums);
72
72
  }
73
73
  }
74
74
  catch (error) {
@@ -77,7 +77,7 @@ export function validateInputText(text, format, declaration, types, mode = 'aggr
77
77
  }
78
78
  return { value, diagnostics };
79
79
  }
80
- export async function loadInputValues(declarations, types, rawMappings = [], mode = 'aggregate', entryFile, registry) {
80
+ export async function loadInputValues(declarations, types, rawMappings = [], mode = 'aggregate', entryFile, registry, enums) {
81
81
  if (mode !== 'aggregate' && mode !== 'fail-fast') {
82
82
  throwInputErrors([inputError('AMX4001', `Unsupported validation mode '${safeText(String(mode))}'`, { file: entryFile })]);
83
83
  }
@@ -145,7 +145,7 @@ export async function loadInputValues(declarations, types, rawMappings = [], mod
145
145
  }));
146
146
  continue;
147
147
  }
148
- const validated = validateInputText(text, extension.slice(1), declaration, types, mode, { file: entryFile, dataFile: filePath }, registry);
148
+ const validated = validateInputText(text, extension.slice(1), declaration, types, mode, { file: entryFile, dataFile: filePath }, registry, enums);
149
149
  diagnostics.push(...validated.diagnostics);
150
150
  if (validated.diagnostics.length > 0 && mode === 'fail-fast')
151
151
  throw new StopValidation();
@@ -161,11 +161,11 @@ export async function loadInputValues(declarations, types, rawMappings = [], mod
161
161
  throw error;
162
162
  }
163
163
  }
164
- function convertJson(value, annotation, pointer, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault = false) {
164
+ function convertJson(value, annotation, pointer, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault = false, enums) {
165
165
  if (annotation.type === 'nullableType') {
166
166
  if (value === null)
167
167
  return null;
168
- return convertJson(value, annotation.element, pointer, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault);
168
+ return convertJson(value, annotation.element, pointer, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault, enums);
169
169
  }
170
170
  if (value === null) {
171
171
  report(shapeDiagnostic('Null is not allowed for this input type', typeName(annotation), 'null', pointer, context, declarationSource, fieldSource));
@@ -176,7 +176,7 @@ function convertJson(value, annotation, pointer, declarationSource, types, envir
176
176
  report(shapeDiagnostic('Expected a JSON array', typeName(annotation), actualType(value), pointer, context, declarationSource, fieldSource));
177
177
  return [];
178
178
  }
179
- return value.map((item, index) => convertJson(item, annotation.element, `${pointer}/${index}`, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault));
179
+ return value.map((item, index) => convertJson(item, annotation.element, `${pointer}/${index}`, declarationSource, types, environment, report, context, fieldSource, registry, internalDefault, enums));
180
180
  }
181
181
  const name = annotation.name;
182
182
  const dimension = registry?.dimensions.get(name);
@@ -188,6 +188,14 @@ function convertJson(value, annotation, pointer, declarationSource, types, envir
188
188
  }
189
189
  if (dimension)
190
190
  return convertJsonMeasurement(value, dimension.vector, pointer, declarationSource, fieldSource, context, report, registry);
191
+ const enumeration = enums?.get(name);
192
+ if (enumeration) {
193
+ const values = resolvedEnumValues(enumeration);
194
+ if (!values.includes(value)) {
195
+ report(shapeDiagnostic(`Value is not a member of enum '${name}'`, name, describe(value), pointer, context, declarationSource, fieldSource));
196
+ }
197
+ return value;
198
+ }
191
199
  if (name === 'Number' || name === 'String' || name === 'Boolean' || name === 'DateTime') {
192
200
  const valid = name === 'Number' ? typeof value === 'number' && Number.isFinite(value)
193
201
  : name === 'String' || name === 'DateTime' ? typeof value === 'string'
@@ -221,11 +229,11 @@ function convertJson(value, annotation, pointer, declarationSource, types, envir
221
229
  const fieldScope = fieldRegistry(field, registry);
222
230
  const propertyPointer = `${pointer}/${escapePointer(field.name)}`;
223
231
  if (Object.prototype.hasOwnProperty.call(object, field.name)) {
224
- materialized[field.name] = convertJson(object[field.name], field.annotation, propertyPointer, declarationSource, types, environment, report, context, field.source, fieldScope, internalDefault);
232
+ materialized[field.name] = convertJson(object[field.name], field.annotation, propertyPointer, declarationSource, types, environment, report, context, field.source, fieldScope, internalDefault, enums);
225
233
  }
226
234
  else if (field.defaultExpression) {
227
235
  const value = evaluateExpression(field.defaultExpression, defaultsEnvironment(environment, fieldScope), context.file);
228
- materialized[field.name] = convertJson(value, field.annotation, propertyPointer, declarationSource, types, environment, report, context, field.source, fieldScope, true);
236
+ materialized[field.name] = convertJson(value, field.annotation, propertyPointer, declarationSource, types, environment, report, context, field.source, fieldScope, true, enums);
229
237
  }
230
238
  else if (field.optional) {
231
239
  materialized[field.name] = null;
@@ -236,13 +244,13 @@ function convertJson(value, annotation, pointer, declarationSource, types, envir
236
244
  }
237
245
  return materialized;
238
246
  }
239
- function convertCsv(text, annotation, declarationSource, types, environment, report, context, registry) {
247
+ function convertCsv(text, annotation, declarationSource, types, environment, report, context, registry, enums) {
240
248
  if (annotation.type !== 'listType' || annotation.element?.type !== 'namedType' || !types.has(annotation.element.name)) {
241
249
  report(shapeDiagnostic('CSV input requires a list of one record type', 'RecordType[]', typeName(annotation), '', context, declarationSource));
242
250
  return [];
243
251
  }
244
252
  const recordType = types.get(annotation.element.name);
245
- const scalarFields = recordType.fields.every(field => isCsvScalar(field.annotation, fieldRegistry(field, registry)));
253
+ const scalarFields = recordType.fields.every(field => isCsvScalar(field.annotation, fieldRegistry(field, registry), enums));
246
254
  if (!scalarFields) {
247
255
  report(shapeDiagnostic('CSV records may contain only scalar fields', 'scalar-field RecordType[]', recordType.name, '', context, declarationSource));
248
256
  return [];
@@ -294,7 +302,7 @@ function convertCsv(text, annotation, declarationSource, types, environment, rep
294
302
  if (field.defaultExpression) {
295
303
  const fieldScope = fieldRegistry(field, registry);
296
304
  const value = evaluateExpression(field.defaultExpression, defaultsEnvironment(environment, fieldScope), context.file);
297
- materialized[field.name] = convertJson(value, field.annotation, propertyPath, context.declarationSource, types, environment, report, context, field.source, fieldScope, true);
305
+ materialized[field.name] = convertJson(value, field.annotation, propertyPath, context.declarationSource, types, environment, report, context, field.source, fieldScope, true, enums);
298
306
  }
299
307
  else if (field.optional)
300
308
  materialized[field.name] = null;
@@ -303,13 +311,13 @@ function convertCsv(text, annotation, declarationSource, types, environment, rep
303
311
  const cell = row[column];
304
312
  if (!cell)
305
313
  continue;
306
- materialized[field.name] = convertCsvCell(cell, field.annotation, propertyPath, recordNumber, column + 1, field.source, report, context, fieldRegistry(field, registry));
314
+ materialized[field.name] = convertCsvCell(cell, field.annotation, propertyPath, recordNumber, column + 1, field.source, report, context, fieldRegistry(field, registry), enums);
307
315
  }
308
316
  result.push(materialized);
309
317
  }
310
318
  return result;
311
319
  }
312
- function convertCsvCell(cell, annotation, dataPath, recordNumber, columnNumber, fieldSource, report, context, registry) {
320
+ function convertCsvCell(cell, annotation, dataPath, recordNumber, columnNumber, fieldSource, report, context, registry, enums) {
313
321
  const base = annotation.type === 'nullableType' ? annotation.element : annotation;
314
322
  const nullable = annotation.type === 'nullableType';
315
323
  const location = { ...context, recordNumber, dataLine: recordNumber + 1, dataColumn: columnNumber };
@@ -320,6 +328,11 @@ function convertCsvCell(cell, annotation, dataPath, recordNumber, columnNumber,
320
328
  return null;
321
329
  }
322
330
  if (cell.value === '' && cell.quoted) {
331
+ if (base.type === 'namedType' && enums?.has(base.name)) {
332
+ const value = '';
333
+ validateCsvEnumValue(value, base.name, enums.get(base.name), dataPath, location, fieldSource, report);
334
+ return value;
335
+ }
323
336
  if (base.type === 'namedType' && base.name === 'String')
324
337
  return '';
325
338
  report(shapeDiagnostic('Quoted empty CSV cell is valid only for String fields', typeName(annotation), 'empty String', dataPath, location, undefined, fieldSource));
@@ -327,6 +340,20 @@ function convertCsvCell(cell, annotation, dataPath, recordNumber, columnNumber,
327
340
  }
328
341
  if (base.type !== 'namedType')
329
342
  return cell.value;
343
+ const enumeration = enums?.get(base.name);
344
+ if (enumeration) {
345
+ const valueType = typeof resolvedEnumValues(enumeration)[0];
346
+ let value = cell.value;
347
+ if (valueType === 'number') {
348
+ if (!/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/.test(cell.value) || !Number.isFinite(Number(cell.value))) {
349
+ report(shapeDiagnostic('Invalid finite numeric enum input', base.name, cell.value, dataPath, location, undefined, fieldSource));
350
+ return cell.value;
351
+ }
352
+ value = Number(cell.value);
353
+ }
354
+ validateCsvEnumValue(value, base.name, enumeration, dataPath, location, fieldSource, report);
355
+ return value;
356
+ }
330
357
  const dimension = registry?.dimensions.get(base.name);
331
358
  if (dimension) {
332
359
  const match = cell.value.match(/^\s*([+-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)\s+(.+?)\s*$/);
@@ -398,7 +425,12 @@ function convertMeasurement(value, unitText, expectedVector, unitPath, context,
398
425
  report(measurementDiagnostic('AMX4005', 'Measurement unit has an incompatible dimension', unitPath, context, declarationSource, fieldSource, formatVector(expectedVector, registry), formatVector(unit.vector, registry)));
399
426
  return null;
400
427
  }
401
- return measurement(value, unit);
428
+ const result = measurement(value, unit);
429
+ if (!Number.isFinite(measurementPhysicalValue(result))) {
430
+ report(measurementDiagnostic('AMX4005', 'Measurement physical value must be finite', unitPath, context, declarationSource, fieldSource, 'finite physical value', String(measurementPhysicalValue(result))));
431
+ return null;
432
+ }
433
+ return result;
402
434
  }
403
435
  function measurementDiagnostic(code, message, dataPath, context, declarationSource, fieldSource, expected, actual) {
404
436
  return inputError(code, message, {
@@ -459,10 +491,36 @@ function typeName(annotation) {
459
491
  return annotation.name;
460
492
  return annotation.type === 'listType' ? `${typeName(annotation.element)}[]` : `${typeName(annotation.element)}?`;
461
493
  }
462
- function isCsvScalar(annotation, registry) {
494
+ function isCsvScalar(annotation, registry, enums) {
463
495
  const base = annotation.type === 'nullableType' ? annotation.element : annotation;
464
496
  return base.type === 'namedType' && (['String', 'Number', 'Boolean', 'DateTime'].includes(base.name)
465
- || !!registry?.dimensions.has(base.name));
497
+ || !!registry?.dimensions.has(base.name)
498
+ || !!enums?.has(base.name));
499
+ }
500
+ function inputEnvironment(types, enums) {
501
+ const environment = new Environment(types);
502
+ for (const [name, declaration] of enums ?? []) {
503
+ const values = resolvedEnumValues(declaration);
504
+ const members = {};
505
+ declaration.members.forEach((member, index) => { members[member.name] = values[index]; });
506
+ environment.enumDeclarations.set(name, declaration);
507
+ environment.enumValues.set(name, members);
508
+ }
509
+ return environment;
510
+ }
511
+ function resolvedEnumValues(declaration) {
512
+ return declaration.resolvedValues ?? declaration.members.map((member, index) => {
513
+ if (!member.value)
514
+ return index + 1;
515
+ if (member.value.type === 'numberLiteral' || member.value.type === 'stringLiteral')
516
+ return member.value.value;
517
+ return NaN;
518
+ });
519
+ }
520
+ function validateCsvEnumValue(value, name, declaration, dataPath, context, fieldSource, report) {
521
+ if (!resolvedEnumValues(declaration).includes(value)) {
522
+ report(shapeDiagnostic(`Value is not a member of enum '${name}'`, name, String(value), dataPath, context, undefined, fieldSource));
523
+ }
466
524
  }
467
525
  function isDateTime(value) {
468
526
  const parts = value.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/);
@@ -20,11 +20,27 @@ export function unitFromMetadata(unit) {
20
20
  const factors = [{ identity: unit.identity, name: unit.name, exponent: 1 }];
21
21
  return Object.freeze({
22
22
  scale: unit.scale,
23
+ offset: unit.offset,
23
24
  vector: vectorRecord(unit.vector),
24
25
  factors: Object.freeze(factors),
25
26
  text: unit.name
26
27
  });
27
28
  }
29
+ export function physicalValue(value, unit) {
30
+ return value * unit.scale + unit.offset;
31
+ }
32
+ export function displayValue(physical, unit) {
33
+ return (physical - unit.offset) / unit.scale;
34
+ }
35
+ export function measurementPhysicalValue(value) {
36
+ return physicalValue(value.value, value.unit);
37
+ }
38
+ export function measurementDisplayValue(physical, unit) {
39
+ return displayValue(physical, unit);
40
+ }
41
+ export function isAffineUnit(unit) {
42
+ return unit.offset !== 0;
43
+ }
28
44
  function combineFactors(left, right, multiplier) {
29
45
  const factors = new Map();
30
46
  for (const factor of left.factors)
@@ -51,20 +67,28 @@ function combineVectorRecords(left, right, multiplier) {
51
67
  return vector;
52
68
  }
53
69
  export function composeUnits(left, right, divide = false) {
70
+ if (isAffineUnit(left) || isAffineUnit(right)) {
71
+ throw new Error('Affine measurement units cannot be composed');
72
+ }
54
73
  const multiplier = divide ? -1 : 1;
55
74
  const factors = combineFactors(left, right, multiplier);
56
75
  return Object.freeze({
57
76
  scale: divide ? left.scale / right.scale : left.scale * right.scale,
77
+ offset: 0,
58
78
  vector: Object.freeze(combineVectorRecords(left, right, multiplier)),
59
79
  factors: Object.freeze(factors),
60
80
  text: formatFactors(factors)
61
81
  });
62
82
  }
63
83
  export function powerUnit(unit, exponent) {
84
+ if (isAffineUnit(unit)) {
85
+ throw new Error('Affine measurement units may not be powered');
86
+ }
64
87
  const factors = unit.factors.map(factor => ({ ...factor, exponent: factor.exponent * exponent }))
65
88
  .filter(factor => factor.exponent !== 0);
66
89
  return Object.freeze({
67
90
  scale: Math.pow(unit.scale, exponent),
91
+ offset: unit.offset,
68
92
  vector: Object.freeze(Object.fromEntries(Object.entries(unit.vector)
69
93
  .map(([identity, power]) => [identity, power * exponent]).filter(([, power]) => power !== 0))),
70
94
  factors: Object.freeze(factors),
@@ -84,19 +108,22 @@ export function canonicalUnit(vector, registry) {
84
108
  }
85
109
  return Object.freeze({
86
110
  scale: 1,
111
+ offset: 0,
87
112
  vector: vectorRecord(vector),
88
113
  factors: Object.freeze(factors),
89
114
  text: formatFactors(factors)
90
115
  });
91
116
  }
92
117
  export function sqrtMeasurement(value, registry) {
118
+ if (isAffineUnit(value.unit))
119
+ throw new Error('Affine measurement sqrt is not supported');
93
120
  const vector = new Map();
94
121
  for (const [identity, exponent] of Object.entries(value.unit.vector)) {
95
122
  if (exponent % 2 !== 0)
96
123
  throw new Error('sqrt requires integral measurement dimension exponents');
97
124
  vector.set(identity, exponent / 2);
98
125
  }
99
- const physical = value.value * value.unit.scale;
126
+ const physical = measurementPhysicalValue(value);
100
127
  const physicalRoot = Math.sqrt(physical);
101
128
  if (!Number.isFinite(physicalRoot))
102
129
  return measurement(physicalRoot, canonicalUnit(vector, registry));
@@ -281,9 +281,12 @@ export async function loadEntryModule(entryPath, options = {}) {
281
281
  const entryStatements = flattenStatements(entryRecord.doc);
282
282
  const inputDeclarations = entryStatements.filter(statement => statement.type === 'inputDeclaration');
283
283
  const entryTypes = new Map(entryRecord.importedTypes);
284
+ const entryEnums = new Map(entryRecord.importedEnums);
284
285
  for (const statement of entryStatements) {
285
286
  if (statement.type === 'typeDeclaration')
286
287
  entryTypes.set(statement.name, statement);
288
+ else if (statement.type === 'enumDeclaration')
289
+ entryEnums.set(statement.name, statement);
287
290
  }
288
291
  const outputs = prepareOutputs(options.outputMappings, entryRecord.checkResult.exportedBindings, entryTypes, options.reservedOutputPath, registry);
289
292
  const outputSchemas = options.inputInspection || options.outputInspection
@@ -299,7 +302,7 @@ export async function loadEntryModule(entryPath, options = {}) {
299
302
  inputName: options.inputInspection.name
300
303
  }]);
301
304
  }
302
- const validation = validateInputText(options.inputInspection.text, options.inputInspection.format, declaration, entryTypes, options.validation ?? 'aggregate', { file: entryPath }, registry);
305
+ const validation = validateInputText(options.inputInspection.text, options.inputInspection.format, declaration, entryTypes, options.validation ?? 'aggregate', { file: entryPath }, registry, entryEnums);
303
306
  return {
304
307
  doc: entryRecord.doc,
305
308
  env: new Environment(entryTypes, new Map(), registry),
@@ -308,7 +311,7 @@ export async function loadEntryModule(entryPath, options = {}) {
308
311
  diagramEmissions: [],
309
312
  registry,
310
313
  inputInspection: {
311
- schema: describeInputSchema(declaration, entryTypes, registry),
314
+ schema: describeInputSchema(declaration, entryTypes, registry, entryEnums),
312
315
  valid: validation.diagnostics.length === 0,
313
316
  diagnostics: validation.diagnostics,
314
317
  outputs: outputSchemas ?? []
@@ -326,7 +329,7 @@ export async function loadEntryModule(entryPath, options = {}) {
326
329
  registry
327
330
  };
328
331
  }
329
- const inputValues = await loadInputValues(inputDeclarations, entryTypes, options.inputMappings, options.validation, entryPath, registry);
332
+ const inputValues = await loadInputValues(inputDeclarations, entryTypes, options.inputMappings, options.validation, entryPath, registry, entryEnums);
330
333
  const evaluatedEnvironments = new Map();
331
334
  for (const canonicalPath of evaluationOrder) {
332
335
  const record = resolved.get(canonicalPath);
@@ -1,6 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { outputError } from '../diagnostics/errors';
3
- import { isMeasurement } from './measurement';
3
+ import { isMeasurement, measurementPhysicalValue } from './measurement';
4
4
  import { fieldRegistry } from '../typechecker/declarationRegistry';
5
5
  function typeName(type) {
6
6
  if (type.kind === 'named')
@@ -149,8 +149,9 @@ function jsonValue(value, type, output, recordTypes, registry) {
149
149
  return value.map(item => jsonValue(item, type.element, output, recordTypes, registry));
150
150
  }
151
151
  if (type.kind === 'measurement') {
152
- if (!isMeasurement(value) || !Number.isFinite(value.value))
152
+ if (!isMeasurement(value) || !Number.isFinite(value.value) || !Number.isFinite(measurementPhysicalValue(value))) {
153
153
  return invalidValue(output, 'expected a finite measurement value');
154
+ }
154
155
  if (!sameVector(value.unit.vector, type.vector))
155
156
  return invalidValue(output, 'measurement has an incompatible dimension');
156
157
  return { value: value.value, unit: value.unit.text };
@@ -198,8 +199,9 @@ function csvCell(value, type, output, registry) {
198
199
  return csvCell(value, type.element, output, registry);
199
200
  }
200
201
  if (type.kind === 'measurement') {
201
- if (!isMeasurement(value) || !Number.isFinite(value.value))
202
+ if (!isMeasurement(value) || !Number.isFinite(value.value) || !Number.isFinite(measurementPhysicalValue(value))) {
202
203
  return invalidValue(output, 'expected a finite measurement value');
204
+ }
203
205
  if (!sameVector(value.unit.vector, type.vector) || !value.unit.text)
204
206
  return invalidValue(output, 'measurement has an incompatible dimension or missing unit text');
205
207
  text = `${JSON.stringify(value.value)} ${value.unit.text}`;