From 2be77e9ca0fec322b874b50b35837e2af2989f77 Mon Sep 17 00:00:00 2001 From: Elsa Date: Tue, 2 Jun 2026 19:29:07 -0400 Subject: [PATCH] Safe import for immutable --- examples/browser/cql4browsers.js | 40 ++++++++++++++------------------ src/elm/list.ts | 4 ++-- src/util/immutableUtil.ts | 30 ++++++++++++------------ 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/examples/browser/cql4browsers.js b/examples/browser/cql4browsers.js index 16ae36a5a..2c4ddbe1a 100644 --- a/examples/browser/cql4browsers.js +++ b/examples/browser/cql4browsers.js @@ -5715,9 +5715,6 @@ exports.Library = Library; },{"./expressions":23}],28:[function(require,module,exports){ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Slice = exports.Last = exports.First = exports.Current = exports.toDistinctList = exports.Distinct = exports.Flatten = exports.ForEach = exports.IndexOf = exports.ToList = exports.SingletonFrom = exports.Filter = exports.Times = exports.Exists = exports.List = void 0; exports.doUnion = doUnion; @@ -5726,7 +5723,7 @@ exports.doIntersect = doIntersect; exports.doContains = doContains; exports.doIncludes = doIncludes; exports.doProperIncludes = doProperIncludes; -const immutable_1 = __importDefault(require("immutable")); +const immutable_1 = require("immutable"); const comparison_1 = require("../util/comparison"); const immutableUtil_1 = require("../util/immutableUtil"); const util_1 = require("../util/util"); @@ -5898,7 +5895,7 @@ class Distinct extends expression_1.Expression { exports.Distinct = Distinct; const toDistinctList = (list) => { const list_keys = list.map(immutableUtil_1.toNormalizedKey); - const set = immutable_1.default.Set().asMutable(); + const set = (0, immutable_1.Set)().asMutable(); const distinct = []; set.withMutations(y => { list_keys.forEach((key, i) => { @@ -9183,13 +9180,10 @@ var __importStar = (this && this.__importStar) || (function () { return result; }; })(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.toNormalizedKey = void 0; const ucum = __importStar(require("@lhncbc/ucum-lhc")); -const immutable_1 = __importDefault(require("immutable")); +const immutable_1 = require("immutable"); const datatypes_1 = require("../datatypes/datatypes"); const math_1 = require("./math"); const units_1 = require("./units"); @@ -9207,7 +9201,7 @@ const toNormalizedKey = (js) => { } // Handle the edge case of functions if (typeof js === 'function') { - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ name: js.toString(), __instance: 'JS.Function' }); @@ -9219,11 +9213,11 @@ const toNormalizedKey = (js) => { // Handle objects - normalize as necessary to generate unique keys switch (js.constructor) { case Array: - return immutable_1.default.Seq(js) + return (0, immutable_1.Seq)(js) .map((x) => (0, exports.toNormalizedKey)(x)) .toList(); case datatypes_1.Code: - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ code: (0, exports.toNormalizedKey)(js.code), system: (0, exports.toNormalizedKey)(js.system), version: (0, exports.toNormalizedKey)(js.version), @@ -9231,31 +9225,31 @@ const toNormalizedKey = (js) => { __instance: js.constructor }); case Date: - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ epochMs: js.getTime(), __instance: js.constructor }); case datatypes_1.DateTime: if (typeof js.timezoneOffset === 'number' && js.timezoneOffset !== 0) { - return immutable_1.default.Seq(js.convertToTimezoneOffset(0)) + return (0, immutable_1.Seq)(js.convertToTimezoneOffset(0)) .map((x) => (0, exports.toNormalizedKey)(x)) .toMap() .set('__instance', js.constructor); } else { - return immutable_1.default.Seq(js) + return (0, immutable_1.Seq)(js) .map((x) => (0, exports.toNormalizedKey)(x)) .toMap() .set('__instance', js.constructor); } case datatypes_1.Interval: - return immutable_1.default.Seq(js.toClosed()) + return (0, immutable_1.Seq)(js.toClosed()) .map((x) => (0, exports.toNormalizedKey)(x)) .toMap() .set('__instance', js.constructor); case datatypes_1.Quantity: if (!js.unit) { - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ value: (_a = js.value) !== null && _a !== void 0 ? _a : null, unit: null, __instance: js.constructor @@ -9265,7 +9259,7 @@ const toNormalizedKey = (js) => { const baseUnitKey = ucumUtilInstance.commensurablesList(js.unit)[0]; if (!baseUnitKey) { // No units found - normalization not possible and use provided values - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ value: (_b = js.value) !== null && _b !== void 0 ? _b : null, unit: (_c = js.unit) !== null && _c !== void 0 ? _c : null, __instance: js.constructor @@ -9276,20 +9270,20 @@ const toNormalizedKey = (js) => { const baseUnitKeyCode = baseUnitKey[0].csCode_; const conversionValue = (0, units_1.convertUnit)(js.value, js.unit, baseUnitKeyCode); const finalValue = conversionValue ? (0, math_1.decimalAdjust)('round', conversionValue, -8) : null; - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ value: finalValue !== null && finalValue !== void 0 ? finalValue : null, unit: baseUnitKeyCode !== null && baseUnitKeyCode !== void 0 ? baseUnitKeyCode : null, __instance: js.constructor }); } case datatypes_1.Ratio: - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ numerator: (0, exports.toNormalizedKey)(js.numerator), denominator: (0, exports.toNormalizedKey)(js.denominator), __instance: js.constructor }); case RegExp: - return immutable_1.default.Map({ + return (0, immutable_1.Map)({ source: (0, exports.toNormalizedKey)(js.source), global: (0, exports.toNormalizedKey)(js.global), ignoreCase: (0, exports.toNormalizedKey)(js.ignoreCase), @@ -9301,7 +9295,7 @@ const toNormalizedKey = (js) => { return (0, exports.toNormalizedKey)(js.low); } else { - return immutable_1.default.Seq(js) + return (0, immutable_1.Seq)(js) .map((x) => (0, exports.toNormalizedKey)(x)) .toMap() .set('__instance', js.constructor); @@ -9310,7 +9304,7 @@ const toNormalizedKey = (js) => { // If the object is a model object (e.g. FHIRObject) with a _typeHierarchy function, // then use the typeHierarchy information for the __instance value. // Otherwise, use the constructor for the __instance value. - return immutable_1.default.Seq(js) + return (0, immutable_1.Seq)(js) .map((x) => (0, exports.toNormalizedKey)(x)) .toMap() .set('__instance', (_e = (0, exports.toNormalizedKey)((_d = js._typeHierarchy) === null || _d === void 0 ? void 0 : _d.call(js))) !== null && _e !== void 0 ? _e : js.constructor); diff --git a/src/elm/list.ts b/src/elm/list.ts index 5444e5322..d8154a8bf 100644 --- a/src/elm/list.ts +++ b/src/elm/list.ts @@ -1,4 +1,4 @@ -import Immutable from 'immutable'; +import { Set as ImmutableSet } from 'immutable'; import { Context } from '../runtime/context'; import { equals } from '../util/comparison'; import { NormalizedKey, toNormalizedKey } from '../util/immutableUtil'; @@ -188,7 +188,7 @@ export class Distinct extends Expression { export const toDistinctList = (list: unknown[]): unknown[] => { const list_keys = list.map(toNormalizedKey); - const set = Immutable.Set().asMutable(); + const set = ImmutableSet().asMutable(); const distinct: unknown[] = []; set.withMutations(y => { diff --git a/src/util/immutableUtil.ts b/src/util/immutableUtil.ts index a44a5a7bc..5ad387146 100644 --- a/src/util/immutableUtil.ts +++ b/src/util/immutableUtil.ts @@ -1,5 +1,5 @@ import * as ucum from '@lhncbc/ucum-lhc'; -import Immutable from 'immutable'; +import { Map as ImmutableMap, Seq as ImmutableSeq } from 'immutable'; import { Code, DateTime, Interval, Quantity, Ratio, Uncertainty } from '../datatypes/datatypes'; import { decimalAdjust } from './math'; import { convertUnit } from './units'; @@ -22,7 +22,7 @@ export const toNormalizedKey = (js: any): NormalizedKey => { // Handle the edge case of functions if (typeof js === 'function') { - return Immutable.Map({ + return ImmutableMap({ name: js.toString(), __instance: 'JS.Function' }); @@ -36,12 +36,12 @@ export const toNormalizedKey = (js: any): NormalizedKey => { // Handle objects - normalize as necessary to generate unique keys switch (js.constructor) { case Array: - return Immutable.Seq(js) + return ImmutableSeq(js) .map((x: any) => toNormalizedKey(x)) .toList(); case Code: - return Immutable.Map({ + return ImmutableMap({ code: toNormalizedKey(js.code), system: toNormalizedKey(js.system), version: toNormalizedKey(js.version), @@ -50,33 +50,33 @@ export const toNormalizedKey = (js: any): NormalizedKey => { }); case Date: - return Immutable.Map({ + return ImmutableMap({ epochMs: js.getTime(), __instance: js.constructor }); case DateTime: if (typeof js.timezoneOffset === 'number' && js.timezoneOffset !== 0) { - return Immutable.Seq(js.convertToTimezoneOffset(0)) + return ImmutableSeq(js.convertToTimezoneOffset(0)) .map((x: any) => toNormalizedKey(x)) .toMap() .set('__instance', js.constructor); } else { - return Immutable.Seq(js) + return ImmutableSeq(js) .map((x: any) => toNormalizedKey(x)) .toMap() .set('__instance', js.constructor); } case Interval: - return Immutable.Seq(js.toClosed()) + return ImmutableSeq(js.toClosed()) .map((x: any) => toNormalizedKey(x)) .toMap() .set('__instance', js.constructor); case Quantity: if (!js.unit) { - return Immutable.Map({ + return ImmutableMap({ value: js.value ?? null, unit: null, __instance: js.constructor @@ -88,7 +88,7 @@ export const toNormalizedKey = (js: any): NormalizedKey => { if (!baseUnitKey) { // No units found - normalization not possible and use provided values - return Immutable.Map({ + return ImmutableMap({ value: js.value ?? null, unit: js.unit ?? null, __instance: js.constructor @@ -98,7 +98,7 @@ export const toNormalizedKey = (js: any): NormalizedKey => { const baseUnitKeyCode = baseUnitKey[0].csCode_; const conversionValue = convertUnit(js.value, js.unit, baseUnitKeyCode); const finalValue = conversionValue ? decimalAdjust('round', conversionValue, -8) : null; - return Immutable.Map({ + return ImmutableMap({ value: finalValue ?? null, unit: baseUnitKeyCode ?? null, __instance: js.constructor @@ -106,14 +106,14 @@ export const toNormalizedKey = (js: any): NormalizedKey => { } case Ratio: - return Immutable.Map({ + return ImmutableMap({ numerator: toNormalizedKey(js.numerator), denominator: toNormalizedKey(js.denominator), __instance: js.constructor }); case RegExp: - return Immutable.Map({ + return ImmutableMap({ source: toNormalizedKey(js.source), global: toNormalizedKey(js.global), ignoreCase: toNormalizedKey(js.ignoreCase), @@ -125,7 +125,7 @@ export const toNormalizedKey = (js: any): NormalizedKey => { if (js.isPoint()) { return toNormalizedKey(js.low); } else { - return Immutable.Seq(js) + return ImmutableSeq(js) .map((x: any) => toNormalizedKey(x)) .toMap() .set('__instance', js.constructor); @@ -135,7 +135,7 @@ export const toNormalizedKey = (js: any): NormalizedKey => { // If the object is a model object (e.g. FHIRObject) with a _typeHierarchy function, // then use the typeHierarchy information for the __instance value. // Otherwise, use the constructor for the __instance value. - return Immutable.Seq(js) + return ImmutableSeq(js) .map((x: any) => toNormalizedKey(x)) .toMap() .set('__instance', toNormalizedKey(js._typeHierarchy?.()) ?? js.constructor);