@cosyte/terminology 0.0.6 → 0.0.7

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/index.d.cts CHANGED
@@ -2247,11 +2247,11 @@ declare function parseUcum(unit: string): ParseResult;
2247
2247
  * @throws {Error} If reducing `node` reaches an atom with no linear definition, or one whose
2248
2248
  * definition does not parse. **No expression {@link parseUcum} accepts reaches either**; a node
2249
2249
  * you assemble yourself can, including by defining an atom in terms of a special unit such as
2250
- * `Cel`, which lands on the table's own `Cel`. A third guard, against a definition that leads
2251
- * back to itself, is **not** reachable from a node you assemble — a definition is resolved
2252
- * against the bundled table, so your atom can name a table atom but never be one — and is
2253
- * reached only by mutating an atom of the loaded table in place. The message names the fault,
2254
- * never the atom.
2250
+ * `Cel`, which lands on the table's own `Cel`. A third guard catches a definition that leads back
2251
+ * to itself. Naming a table atom does not reach it — a definition is resolved against the loaded
2252
+ * table, so your atom can name one but never be one — and neither does the table itself, which is
2253
+ * frozen; what reaches it is a `value` accessor that re-enters `reduce` for the same atom while
2254
+ * that atom is still being reduced. The message names the fault, never the atom.
2255
2255
  * @example
2256
2256
  * ```ts
2257
2257
  * import { parseUcum, reduce } from "@cosyte/terminology";
@@ -2282,7 +2282,13 @@ declare function reduce(node: UnitNode): Reduction;
2282
2282
  /**
2283
2283
  * Load the UCUM essence table, parsing the embedded verbatim XML on first call and caching it.
2284
2284
  *
2285
- * @returns The immutable in-memory {@link UcumEssence} model (7 base units, 24 prefixes, ~305 atoms).
2285
+ * One table is shared by every caller and by the engine itself, so it is handed out **frozen**: an
2286
+ * atom's definition cannot be rewritten in place, and neither can the `atoms` array the parser
2287
+ * scans. It used to be, and doing so before that atom's first reduction poisoned the
2288
+ * reduction memo for the life of the process — a fabricated unit equivalence that survived putting
2289
+ * the table back. A write is refused, which in strict mode means a `TypeError`.
2290
+ *
2291
+ * @returns The shared, frozen in-memory {@link UcumEssence} model.
2286
2292
  * @example
2287
2293
  * ```ts
2288
2294
  * import { loadUcumEssence } from "@cosyte/terminology";
package/dist/index.d.ts CHANGED
@@ -2247,11 +2247,11 @@ declare function parseUcum(unit: string): ParseResult;
2247
2247
  * @throws {Error} If reducing `node` reaches an atom with no linear definition, or one whose
2248
2248
  * definition does not parse. **No expression {@link parseUcum} accepts reaches either**; a node
2249
2249
  * you assemble yourself can, including by defining an atom in terms of a special unit such as
2250
- * `Cel`, which lands on the table's own `Cel`. A third guard, against a definition that leads
2251
- * back to itself, is **not** reachable from a node you assemble — a definition is resolved
2252
- * against the bundled table, so your atom can name a table atom but never be one — and is
2253
- * reached only by mutating an atom of the loaded table in place. The message names the fault,
2254
- * never the atom.
2250
+ * `Cel`, which lands on the table's own `Cel`. A third guard catches a definition that leads back
2251
+ * to itself. Naming a table atom does not reach it — a definition is resolved against the loaded
2252
+ * table, so your atom can name one but never be one — and neither does the table itself, which is
2253
+ * frozen; what reaches it is a `value` accessor that re-enters `reduce` for the same atom while
2254
+ * that atom is still being reduced. The message names the fault, never the atom.
2255
2255
  * @example
2256
2256
  * ```ts
2257
2257
  * import { parseUcum, reduce } from "@cosyte/terminology";
@@ -2282,7 +2282,13 @@ declare function reduce(node: UnitNode): Reduction;
2282
2282
  /**
2283
2283
  * Load the UCUM essence table, parsing the embedded verbatim XML on first call and caching it.
2284
2284
  *
2285
- * @returns The immutable in-memory {@link UcumEssence} model (7 base units, 24 prefixes, ~305 atoms).
2285
+ * One table is shared by every caller and by the engine itself, so it is handed out **frozen**: an
2286
+ * atom's definition cannot be rewritten in place, and neither can the `atoms` array the parser
2287
+ * scans. It used to be, and doing so before that atom's first reduction poisoned the
2288
+ * reduction memo for the life of the process — a fabricated unit equivalence that survived putting
2289
+ * the table back. A write is refused, which in strict mode means a `TypeError`.
2290
+ *
2291
+ * @returns The shared, frozen in-memory {@link UcumEssence} model.
2286
2292
  * @example
2287
2293
  * ```ts
2288
2294
  * import { loadUcumEssence } from "@cosyte/terminology";
package/dist/index.mjs CHANGED
@@ -3731,7 +3731,29 @@ function parseEssence(xml) {
3731
3731
  atoms.sort((a, b) => b.code.length - a.code.length);
3732
3732
  const atomByCode = new Map(atoms.map((a) => [a.code, a]));
3733
3733
  const prefixByCode = new Map(prefixes.map((p) => [p.code, p]));
3734
- return { prefixes, atoms, atomByCode, prefixByCode };
3734
+ return freezeEssence({ prefixes, atoms, atomByCode, prefixByCode });
3735
+ }
3736
+ function refuseTableWrite() {
3737
+ throw new TypeError("the UCUM unit table is immutable");
3738
+ }
3739
+ function sealLookup(map) {
3740
+ return Object.defineProperties(map, {
3741
+ set: { value: refuseTableWrite },
3742
+ delete: { value: refuseTableWrite },
3743
+ clear: { value: refuseTableWrite }
3744
+ });
3745
+ }
3746
+ function freezeEssence(essence) {
3747
+ for (const atom of essence.atoms) {
3748
+ if (atom.value) Object.freeze(atom.value);
3749
+ Object.freeze(atom);
3750
+ }
3751
+ for (const prefix of essence.prefixes) Object.freeze(prefix);
3752
+ Object.freeze(essence.atoms);
3753
+ Object.freeze(essence.prefixes);
3754
+ sealLookup(essence.atomByCode);
3755
+ sealLookup(essence.prefixByCode);
3756
+ return Object.freeze(essence);
3735
3757
  }
3736
3758
  var cached;
3737
3759
  function loadUcumEssence() {
@@ -4729,7 +4751,7 @@ function approximateMatch(graph, query, options = {}) {
4729
4751
  }
4730
4752
 
4731
4753
  // src/index.ts
4732
- var VERSION = "0.0.6";
4754
+ var VERSION = "0.0.7";
4733
4755
 
4734
4756
  export { COMPLEX_MAP_SOURCE_SYSTEM, DIAGNOSTIC_CODES, FATAL_CODES, HL7_V2_OID_ROOT, HL7_V2_URL_PREFIX, ICD10CM_ORDER_FILE_FIELDS, ICD10CM_SYSTEM, ICD9CM_SYSTEM, MAP_CATEGORIES, NO_MAP_CATEGORIES, RELA, RELA_INVERSE, RXNORM_SYSTEM, SNOMEDCT_SYSTEM, SYSTEM_IDENTITIES, TERM_TYPES, TerminologyError, VERSION, applyComplexMap, applyGem, approximateMatch, asTermType, brandsFor, buildSubsumption, codeableConcept, coding, consistsOf, defaultStatusMapper, doseFormsOf, expand, genericFor, getArray, getBoolean, getConcept, getNumber, getString, ingredientsOf, invertGem, isA, isJsonObject, isSynonymTermType, isUnknownSystem, loadCodeSystem, loadComplexMap, loadConceptMap, loadGems, loadRxNormGraph, loadUcumEssence, loadValueSet, lookup, makeStatus, matchesFilter, parseCsv, parseCsvSource, parseFhirCodeSystem, parseFixedWidth, parseRrf, parseRrfLine, parseUcum, reduce, relatedByRela, resolveNdc, resolveSystem, sliceField, translate, ucumEqual, unsupportedOps, validateCode, validateCodeInValueSet, validateUcum };
4735
4757
  //# sourceMappingURL=index.mjs.map