@cosyte/synth 0.1.3 → 0.1.5

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +28 -24
  3. package/dist/astm/index.cjs +109 -84
  4. package/dist/astm/index.cjs.map +1 -1
  5. package/dist/astm/index.d.cts +4 -3
  6. package/dist/astm/index.d.ts +4 -3
  7. package/dist/astm/index.mjs +109 -84
  8. package/dist/astm/index.mjs.map +1 -1
  9. package/dist/ccda/index.cjs +24 -2
  10. package/dist/ccda/index.cjs.map +1 -1
  11. package/dist/ccda/index.d.cts +5 -4
  12. package/dist/ccda/index.d.ts +5 -4
  13. package/dist/ccda/index.mjs +24 -2
  14. package/dist/ccda/index.mjs.map +1 -1
  15. package/dist/deid/index.cjs +98 -47
  16. package/dist/deid/index.cjs.map +1 -1
  17. package/dist/deid/index.d.cts +4 -3
  18. package/dist/deid/index.d.ts +4 -3
  19. package/dist/deid/index.mjs +98 -47
  20. package/dist/deid/index.mjs.map +1 -1
  21. package/dist/{example-codes-88f3_bQZ.d.cts → example-codes-4RnyF7bV.d.cts} +2 -1
  22. package/dist/{example-codes-88f3_bQZ.d.ts → example-codes-4RnyF7bV.d.ts} +2 -1
  23. package/dist/fhir/index.cjs +33 -2
  24. package/dist/fhir/index.cjs.map +1 -1
  25. package/dist/fhir/index.d.cts +4 -3
  26. package/dist/fhir/index.d.ts +4 -3
  27. package/dist/fhir/index.mjs +33 -2
  28. package/dist/fhir/index.mjs.map +1 -1
  29. package/dist/hl7/index.cjs +33 -3
  30. package/dist/hl7/index.cjs.map +1 -1
  31. package/dist/hl7/index.d.cts +4 -3
  32. package/dist/hl7/index.d.ts +4 -3
  33. package/dist/hl7/index.mjs +33 -3
  34. package/dist/hl7/index.mjs.map +1 -1
  35. package/dist/index.cjs +3 -3
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +13 -8
  38. package/dist/index.d.ts +13 -8
  39. package/dist/index.mjs +3 -3
  40. package/dist/index.mjs.map +1 -1
  41. package/dist/ncpdp/index.cjs +57 -14
  42. package/dist/ncpdp/index.cjs.map +1 -1
  43. package/dist/ncpdp/index.d.cts +3 -2
  44. package/dist/ncpdp/index.d.ts +3 -2
  45. package/dist/ncpdp/index.mjs +57 -14
  46. package/dist/ncpdp/index.mjs.map +1 -1
  47. package/dist/{providers-DcPrqmp5.d.cts → providers-B48qUwHU.d.cts} +2 -1
  48. package/dist/{providers-DcPrqmp5.d.ts → providers-B48qUwHU.d.ts} +2 -1
  49. package/dist/{quirk-DmqYw3Vk.d.ts → quirk-BCSs1jPt.d.cts} +3 -2
  50. package/dist/{quirk-CilFUhwX.d.cts → quirk-BfObsiWV.d.ts} +3 -2
  51. package/dist/x12/index.cjs +82 -33
  52. package/dist/x12/index.cjs.map +1 -1
  53. package/dist/x12/index.d.cts +3 -2
  54. package/dist/x12/index.d.ts +3 -2
  55. package/dist/x12/index.mjs +82 -33
  56. package/dist/x12/index.mjs.map +1 -1
  57. package/package.json +29 -31
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 3d13238: The exported example-code pools and the fatal-code registry are now frozen all the way down. `EXAMPLE_ASTM_TESTS` (`@cosyte/synth/astm`), `EXAMPLE_DRUGS` (`@cosyte/synth/ncpdp`) and the X12 pools `PROFESSIONAL_PROCEDURES`, `INSTITUTIONAL_PROCEDURES`, `DENTAL_PROCEDURES`, `REVENUE_CODES` and `DIAGNOSES` (`@cosyte/synth/x12`) froze the array but left each entry writable, so a JavaScript caller could rewrite an entry and change what every later call with the same seed generated. `SYNTH_FATAL_CODES` was not frozen at all, so a caller could change the code a later `SynthError` carried. Each entry and the registry are now frozen, as the other pools already were, and a write to one throws in strict mode.
8
+
9
+ No generated value, export, warning code or seed mapping changes.
10
+
11
+ - cbae766: Doc comments only. `luhnMod10` is exported from `@cosyte/synth`, so it is public: its doc comment no longer marks it internal, and it now carries an example like any other export. The comment on the fatal-code module that ships in the type declarations now says in plain words how a parser handles bad input.
12
+
13
+ No generated value, export, warning code or seed mapping changes.
14
+
15
+ ## 0.1.4
16
+
17
+ ### Patch Changes
18
+
19
+ - b6ac062: Type declarations are now bundled by tsup 9; the JavaScript is unchanged and the bytes every seed
20
+ produces are unchanged. Each declaration file lists its type-only exports in a separate
21
+ `export type` statement and the shared declaration chunks have new file names. Every subpath
22
+ exports the same names with the same types as before. The source maps of the `hl7`, `ccda` and
23
+ `deid` subpaths embed source that was reformatted, with no change to the code.
24
+
3
25
  ## 0.1.3
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -62,8 +62,9 @@ Node.js 22 or later, tested on 22, 24, and 26.
62
62
  `@cosyte/hl7`, `@cosyte/fhir`, `@cosyte/ccda`, `@cosyte/x12`, `@cosyte/ncpdp`, `@cosyte/astm`, and
63
63
  `@cosyte/deid` are **optional peer dependencies**, each needed only for its subpath (`@cosyte/synth/hl7`,
64
64
  `@cosyte/synth/fhir`, `@cosyte/synth/ccda`, `@cosyte/synth/x12`, `@cosyte/synth/ncpdp`,
65
- `@cosyte/synth/astm`, and `@cosyte/synth/deid`: the last needs `@cosyte/deid` **plus** the parsers for
66
- the formats it pairs): install only the packages whose fixtures you generate. The package core has
65
+ `@cosyte/synth/astm`, and `@cosyte/synth/deid`: the last loads `@cosyte/deid` **plus** the five
66
+ parsers it pairs, `@cosyte/hl7`, `@cosyte/fhir`, `@cosyte/ccda`, `@cosyte/x12`, and `@cosyte/ncpdp`,
67
+ as soon as it is imported): install only the packages whose fixtures you generate. The package core has
67
68
  **zero third-party runtime dependencies**.
68
69
 
69
70
  ## Usage
@@ -358,7 +359,7 @@ isSyntheticNpi(safe.npi(rng)); // true, always a deliberately-invalid-Luhn NPI (
358
359
  fed straight back in: each artifact re-parses with zero warnings.
359
360
  - **Deterministic**, a hand-rolled seeded PRNG (`sfc32`/`splitmix32`); `Math.random` is lint-banned.
360
361
  A seed determines the output, byte for byte, on the same parser versions, and CI compares those
361
- bytes across Node 22 and 24.
362
+ bytes across Node 22, 24, and 26.
362
363
  - **Immutable**, generated artifacts and the `Corpus` result are deep-frozen.
363
364
  - **Zero third-party runtime dependencies**, the parser peers are first-party Cosyte packages,
364
365
  installed from npm for the tests; dual ESM + CJS, validated with `attw`.
@@ -367,21 +368,24 @@ isSyntheticNpi(safe.npi(rng)); // true, always a deliberately-invalid-Luhn NPI (
367
368
 
368
369
  The full reference is on [docs.cosyte.com/synth](https://docs.cosyte.com/synth):
369
370
 
370
- - [Installation](https://docs.cosyte.com/synth/installation) and the [quickstart](https://docs.cosyte.com/synth/quickstart).
371
- - Core concepts: [the archetype](https://docs.cosyte.com/synth/concepts-archetype) and the [limitations](https://docs.cosyte.com/synth/limitations).
372
- - Guides: [the overview](https://docs.cosyte.com/synth/guides-overview), [FHIR R4 and US Core](https://docs.cosyte.com/synth/guides-fhir),
371
+ - [Installation](https://docs.cosyte.com/synth/installation), the [quickstart](https://docs.cosyte.com/synth/quickstart), and
372
+ a tutorial: [test your HL7 handling with generated fixtures](https://docs.cosyte.com/synth/test-hl7-handling-with-fixtures).
373
+ - How-to guides: [HL7 v2](https://docs.cosyte.com/synth/guides-hl7), [FHIR R4 and US Core](https://docs.cosyte.com/synth/guides-fhir),
373
374
  [C-CDA](https://docs.cosyte.com/synth/guides-ccda), [X12](https://docs.cosyte.com/synth/guides-x12), [NCPDP](https://docs.cosyte.com/synth/guides-ncpdp),
374
- [ASTM](https://docs.cosyte.com/synth/guides-astm), [vendor quirks](https://docs.cosyte.com/synth/guides-quirks), and
375
- [the `@cosyte/deid` pairing loop](https://docs.cosyte.com/synth/guides-deid).
376
- - [Troubleshooting](https://docs.cosyte.com/synth/troubleshooting).
375
+ [ASTM](https://docs.cosyte.com/synth/guides-astm), [vendor quirks](https://docs.cosyte.com/synth/guides-quirks),
376
+ [the `@cosyte/deid` pairing loop](https://docs.cosyte.com/synth/guides-deid), [synthetic values](https://docs.cosyte.com/synth/draw-synthetic-values),
377
+ and [pinning a golden fixture](https://docs.cosyte.com/synth/guides-overview).
378
+ - Explanation: [how it works](https://docs.cosyte.com/synth/concepts-archetype) and [what it does and does not do](https://docs.cosyte.com/synth/limitations).
379
+ - Reference: [fatal codes](https://docs.cosyte.com/synth/fatal-codes), the [quirk catalog](https://docs.cosyte.com/synth/quirk-catalog), and the API reference.
380
+ - [Troubleshooting](https://docs.cosyte.com/synth/troubleshooting), [testing and quality](https://docs.cosyte.com/synth/testing-and-quality), and [performance](https://docs.cosyte.com/synth/performance).
377
381
  - [`CHANGELOG.md`](https://github.com/cosyte/synth/blob/main/CHANGELOG.md): every release.
378
382
 
379
383
  ## Support
380
384
 
381
385
  Questions, bug reports, and requests for a format or a quirk go in
382
386
  [GitHub issues](https://github.com/cosyte/synth/issues). Every fixture this package makes is
383
- synthetic: never attach a real patient's data to an issue. For help with an integration test suite,
384
- see our [integration services](https://cosyte.com/integration-services).
387
+ synthetic: never attach a real patient's data to an issue. Need an integration built and tested, or
388
+ hosted and run for you? See our [integration services](https://cosyte.com/integration-services).
385
389
 
386
390
  ## Security
387
391
 
@@ -402,19 +406,19 @@ Typo, link, and test fixes can go straight to a pull request.
402
406
 
403
407
  **What a contribution has to clear**, every one of them a script this package declares:
404
408
 
405
- | check | what it is |
406
- | ----------------------------- | -------------------------------------------------------- |
407
- | `pnpm typecheck` | `tsc --noEmit`, strict, over the source and the examples |
408
- | `pnpm lint` | ESLint, at `--max-warnings=0` |
409
- | `pnpm format:check` | Prettier |
410
- | `pnpm phi-scan` | no patient-shaped value anywhere in a tracked file |
411
- | `pnpm test` | Vitest, including the synthetic-safety suites |
412
- | `pnpm test:coverage` | the coverage gate |
413
- | `pnpm build` | the dual ESM and CJS bundle |
414
- | `pnpm attw` | per-condition type resolution for consumers |
415
- | `pnpm run determinism:digest` | the bytes each seed produces, against the baseline |
416
- | `pnpm check:no-emdash` | the house punctuation rule |
417
- | `pnpm check:no-internal-refs` | no internal bookkeeping on the public surface |
409
+ | check | what it is |
410
+ | ----------------------------- | ----------------------------------------------------- |
411
+ | `pnpm typecheck` | `tsc --noEmit`, strict (the examples: in `pnpm test`) |
412
+ | `pnpm lint` | ESLint, at `--max-warnings=0` |
413
+ | `pnpm format:check` | Prettier |
414
+ | `pnpm phi-scan` | no patient-shaped value anywhere in a tracked file |
415
+ | `pnpm test` | Vitest, including the synthetic-safety suites |
416
+ | `pnpm test:coverage` | the coverage gate |
417
+ | `pnpm build` | the dual ESM and CJS bundle |
418
+ | `pnpm attw` | per-condition type resolution for consumers |
419
+ | `pnpm run determinism:digest` | the bytes each seed produces, against the baseline |
420
+ | `pnpm check:no-emdash` | the house punctuation rule |
421
+ | `pnpm check:no-internal-refs` | no internal bookkeeping on the public surface |
418
422
 
419
423
  New behavior needs a test beside it, and a change a consumer would notice needs a changeset
420
424
  (`pnpm changeset`), whose summary becomes the changelog entry. A change to the bytes a seed produces
@@ -32,7 +32,16 @@ function sfc32Next(s) {
32
32
  }
33
33
 
34
34
  // src/codes.ts
35
- var SYNTH_FATAL_CODES = {
35
+ var SYNTH_FATAL_CODES = Object.freeze({
36
+ /**
37
+ * A format was requested that this build cannot generate through a real parser builder/serializer.
38
+ * Fatal, never a hand-written byte fallback.
39
+ *
40
+ * **No code path in this build raises it.** All six formats generate, so it is reserved for a
41
+ * future format that does not, and is kept because removing a published code is a breaking change.
42
+ * An unsupported *kind* within a format that does generate is `SYNTH_UNSUPPORTED_KIND`.
43
+ */
44
+ SYNTH_UNSUPPORTED_FORMAT: "SYNTH_UNSUPPORTED_FORMAT",
36
45
  /**
37
46
  * A vendor quirk was requested that the target format's profile system does not support. Fatal,
38
47
  * never a silent no-op and never a fabricated quirk.
@@ -49,6 +58,10 @@ var SYNTH_FATAL_CODES = {
49
58
  * warning code(s). Fatal, never emit a mislabeled fixture.
50
59
  */
51
60
  SYNTH_INTENDED_WARNING_MISMATCH: "SYNTH_INTENDED_WARNING_MISMATCH",
61
+ /** A concept's code-system URI has no OID mapping in the C-CDA example-code table. Fatal. */
62
+ SYNTH_UNMAPPED_CODE_SYSTEM: "SYNTH_UNMAPPED_CODE_SYSTEM",
63
+ /** A money value could not be read as an X12 decimal. Fatal: a generator never rounds to a float. */
64
+ SYNTH_INVALID_DECIMAL: "SYNTH_INVALID_DECIMAL",
52
65
  /** An integer range was requested with its maximum below its minimum. Fatal. */
53
66
  SYNTH_INVALID_RANGE: "SYNTH_INVALID_RANGE",
54
67
  /** A value was drawn from an empty pool. Fatal, never a fabricated substitute. */
@@ -61,7 +74,17 @@ var SYNTH_FATAL_CODES = {
61
74
  * see `resolveKind`: a selector union is erased at run time, and a selector that falls through
62
75
  * either mislabels the fixture or hands the value to a peer builder that quotes it back.
63
76
  */
64
- SYNTH_UNSUPPORTED_KIND: "SYNTH_UNSUPPORTED_KIND"};
77
+ SYNTH_UNSUPPORTED_KIND: "SYNTH_UNSUPPORTED_KIND",
78
+ /**
79
+ * A requested profile IS published by the adopted implementation guide, and this build does not
80
+ * generate it. Deliberately distinct from `SYNTH_UNSUPPORTED_KIND`, which says the name is not in
81
+ * the adopted set at all: "the guide does not publish this" and "we do not generate this yet" are
82
+ * different answers, and a caller building to a regulatory profile set has to be able to tell them
83
+ * apart without matching message text. Fatal, and raised **before** anything is generated: a
84
+ * mislabelled artifact is worse than no artifact.
85
+ */
86
+ SYNTH_PROFILE_NOT_GENERATED: "SYNTH_PROFILE_NOT_GENERATED"
87
+ });
65
88
  var SYNTH_FATAL_MESSAGES = Object.freeze({
66
89
  SYNTH_UNSUPPORTED_FORMAT: "The requested format is not generable by this build. A generator has no byte fallback: it builds through a parser's own serializer or it refuses.",
67
90
  SYNTH_UNSUPPORTED_QUIRK: "The requested vendor quirk is not in the target format's quirk registry. Compare the request against that format's exported registry (HL7_QUIRKS, CCDA_QUIRKS, ASTM_QUIRKS).",
@@ -472,88 +495,90 @@ function astmHeaderIdentity(rng) {
472
495
  }
473
496
 
474
497
  // src/astm/example-codes.ts
475
- var EXAMPLE_ASTM_TESTS = Object.freeze([
476
- {
477
- localCode: "GLU",
478
- loinc: "2345-7",
479
- name: "Glucose",
480
- units: "mg/dL",
481
- referenceRange: "70-110",
482
- valueLow: 55,
483
- valueHigh: 260,
484
- decimals: 0
485
- },
486
- {
487
- localCode: "K",
488
- loinc: "2823-3",
489
- name: "Potassium",
490
- units: "mmol/L",
491
- referenceRange: "3.5-5.1",
492
- valueLow: 28,
493
- valueHigh: 62,
494
- decimals: 1
495
- },
496
- {
497
- localCode: "NA",
498
- loinc: "2951-2",
499
- name: "Sodium",
500
- units: "mmol/L",
501
- referenceRange: "136-145",
502
- valueLow: 125,
503
- valueHigh: 155,
504
- decimals: 0
505
- },
506
- {
507
- localCode: "CREA",
508
- loinc: "2160-0",
509
- name: "Creatinine",
510
- units: "mg/dL",
511
- referenceRange: "0.6-1.3",
512
- valueLow: 4,
513
- valueHigh: 32,
514
- decimals: 1
515
- },
516
- {
517
- localCode: "HGB",
518
- loinc: "718-7",
519
- name: "Hemoglobin",
520
- units: "g/dL",
521
- referenceRange: "12.0-17.5",
522
- valueLow: 80,
523
- valueHigh: 190,
524
- decimals: 1
525
- },
526
- {
527
- localCode: "WBC",
528
- loinc: "6690-2",
529
- name: "Leukocytes",
530
- units: "10*3/uL",
531
- referenceRange: "4.5-11.0",
532
- valueLow: 30,
533
- valueHigh: 150,
534
- decimals: 1
535
- },
536
- {
537
- localCode: "TSH",
538
- loinc: "3016-3",
539
- name: "Thyrotropin",
540
- units: "mIU/L",
541
- referenceRange: "0.40-4.50",
542
- valueLow: 2,
543
- valueHigh: 90,
544
- decimals: 2
545
- },
546
- {
547
- localCode: "ALT",
548
- loinc: "1742-6",
549
- name: "Alanine aminotransferase",
550
- units: "U/L",
551
- referenceRange: "7-56",
552
- valueLow: 5,
553
- valueHigh: 120,
554
- decimals: 0
555
- }
556
- ]);
498
+ var EXAMPLE_ASTM_TESTS = Object.freeze(
499
+ [
500
+ {
501
+ localCode: "GLU",
502
+ loinc: "2345-7",
503
+ name: "Glucose",
504
+ units: "mg/dL",
505
+ referenceRange: "70-110",
506
+ valueLow: 55,
507
+ valueHigh: 260,
508
+ decimals: 0
509
+ },
510
+ {
511
+ localCode: "K",
512
+ loinc: "2823-3",
513
+ name: "Potassium",
514
+ units: "mmol/L",
515
+ referenceRange: "3.5-5.1",
516
+ valueLow: 28,
517
+ valueHigh: 62,
518
+ decimals: 1
519
+ },
520
+ {
521
+ localCode: "NA",
522
+ loinc: "2951-2",
523
+ name: "Sodium",
524
+ units: "mmol/L",
525
+ referenceRange: "136-145",
526
+ valueLow: 125,
527
+ valueHigh: 155,
528
+ decimals: 0
529
+ },
530
+ {
531
+ localCode: "CREA",
532
+ loinc: "2160-0",
533
+ name: "Creatinine",
534
+ units: "mg/dL",
535
+ referenceRange: "0.6-1.3",
536
+ valueLow: 4,
537
+ valueHigh: 32,
538
+ decimals: 1
539
+ },
540
+ {
541
+ localCode: "HGB",
542
+ loinc: "718-7",
543
+ name: "Hemoglobin",
544
+ units: "g/dL",
545
+ referenceRange: "12.0-17.5",
546
+ valueLow: 80,
547
+ valueHigh: 190,
548
+ decimals: 1
549
+ },
550
+ {
551
+ localCode: "WBC",
552
+ loinc: "6690-2",
553
+ name: "Leukocytes",
554
+ units: "10*3/uL",
555
+ referenceRange: "4.5-11.0",
556
+ valueLow: 30,
557
+ valueHigh: 150,
558
+ decimals: 1
559
+ },
560
+ {
561
+ localCode: "TSH",
562
+ loinc: "3016-3",
563
+ name: "Thyrotropin",
564
+ units: "mIU/L",
565
+ referenceRange: "0.40-4.50",
566
+ valueLow: 2,
567
+ valueHigh: 90,
568
+ decimals: 2
569
+ },
570
+ {
571
+ localCode: "ALT",
572
+ loinc: "1742-6",
573
+ name: "Alanine aminotransferase",
574
+ units: "U/L",
575
+ referenceRange: "7-56",
576
+ valueLow: 5,
577
+ valueHigh: 120,
578
+ decimals: 0
579
+ }
580
+ ].map((entry) => Object.freeze(entry))
581
+ );
557
582
  var ASTM_ABNORMAL_FLAGS = Object.freeze(["N", "L", "H", "A"]);
558
583
  var ASTM_RESULT_STATUSES = Object.freeze(["F", "P", "C"]);
559
584
  var ASTM_COMMENT_TEXT = Object.freeze([