@cosyte/synth 0.1.5 → 0.1.6

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 (46) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/astm/index.cjs +55 -18
  3. package/dist/astm/index.cjs.map +1 -1
  4. package/dist/astm/index.d.cts +7 -0
  5. package/dist/astm/index.d.ts +7 -0
  6. package/dist/astm/index.mjs +54 -18
  7. package/dist/astm/index.mjs.map +1 -1
  8. package/dist/ccda/index.cjs +76 -26
  9. package/dist/ccda/index.cjs.map +1 -1
  10. package/dist/ccda/index.d.cts +6 -0
  11. package/dist/ccda/index.d.ts +6 -0
  12. package/dist/ccda/index.mjs +63 -14
  13. package/dist/ccda/index.mjs.map +1 -1
  14. package/dist/deid/index.cjs +207 -118
  15. package/dist/deid/index.cjs.map +1 -1
  16. package/dist/deid/index.mjs +194 -106
  17. package/dist/deid/index.mjs.map +1 -1
  18. package/dist/fhir/index.cjs +146 -74
  19. package/dist/fhir/index.cjs.map +1 -1
  20. package/dist/fhir/index.d.cts +6 -0
  21. package/dist/fhir/index.d.ts +6 -0
  22. package/dist/fhir/index.mjs +145 -74
  23. package/dist/fhir/index.mjs.map +1 -1
  24. package/dist/hl7/index.cjs +53 -9
  25. package/dist/hl7/index.cjs.map +1 -1
  26. package/dist/hl7/index.d.cts +6 -0
  27. package/dist/hl7/index.d.ts +6 -0
  28. package/dist/hl7/index.mjs +52 -9
  29. package/dist/hl7/index.mjs.map +1 -1
  30. package/dist/index.cjs +1 -3
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.mjs +1 -3
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/ncpdp/index.cjs +74 -22
  35. package/dist/ncpdp/index.cjs.map +1 -1
  36. package/dist/ncpdp/index.d.cts +7 -0
  37. package/dist/ncpdp/index.d.ts +7 -0
  38. package/dist/ncpdp/index.mjs +73 -22
  39. package/dist/ncpdp/index.mjs.map +1 -1
  40. package/dist/x12/index.cjs +65 -17
  41. package/dist/x12/index.cjs.map +1 -1
  42. package/dist/x12/index.d.cts +6 -0
  43. package/dist/x12/index.d.ts +6 -0
  44. package/dist/x12/index.mjs +64 -17
  45. package/dist/x12/index.mjs.map +1 -1
  46. package/package.json +20 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - d3c649c: Each format subpath now imports without loading its parser, and a corpus checks its artifacts in less time.
8
+
9
+ - Importing `@cosyte/synth/hl7`, `/fhir`, `/ccda`, `/x12`, `/ncpdp`, `/astm` or `/deid` no longer loads the sibling parser it builds through. The parser loads on the first call that needs it, synchronously, so every function keeps its signature. It is the same build an `import` or a `require` of the parser gives you, so a returned message, resource, document or interchange is an instance of the parser classes your own code imports. One thing moves: when an optional parser is not installed, the error that names it now comes from the first call that needs it, not from the import of the subpath. Install the parser for each format you generate, as before.
10
+ - Every corpus generator (`hl7Corpus`, `fhirCorpus`, `ccdaCorpus`, `x12Corpus`, `ncpdpCorpus`, `astmCorpus`) takes a new `verify` option. It defaults to `true`, which reads each artifact back through its parser and records the parser's findings as its `warnings`, as before. A corpus now reads each artifact back once and no longer serializes it a second time, since a corpus never reported byte stability; `roundTrip` and the other round-trip functions still check it. `verify: false` skips the read, a large share of a corpus's time, and leaves every artifact's `warnings` empty without checking it. Pass it when the corpus feeds a load test and the parser's verdict is not needed.
11
+ - The sibling parsers move to their latest releases: `@cosyte/hl7` 0.1.8, `@cosyte/fhir` 0.1.8, `@cosyte/ccda` 0.1.6, `@cosyte/x12` 0.1.10, `@cosyte/ncpdp` 0.1.6, `@cosyte/astm` 0.1.6 and `@cosyte/deid` 0.1.5, and each optional peer range now starts at that release.
12
+
13
+ Output change: X12. Every generated 271 now carries the BHT segment the 005010X279A1 guide requires right after its ST, because `@cosyte/x12` 0.1.10 writes it; its SE segment count is one higher, and the X12 271 de-identification loop result moves with it. A 271 golden file committed from an earlier release has to be regenerated. Every other generated artifact is byte for byte what it was for the same seed.
14
+
3
15
  ## 0.1.5
4
16
 
5
17
  ### Patch Changes
@@ -1,6 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var astm = require('@cosyte/astm');
3
+ var module$1 = require('module');
4
+ var url = require('url');
5
+
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
4
13
 
5
14
  // src/rng/splitmix32.ts
6
15
  function splitmix32(seed) {
@@ -150,6 +159,7 @@ function createRng(seed) {
150
159
  }
151
160
 
152
161
  // src/corpus.ts
162
+ var UNCHECKED = Object.freeze([]);
153
163
  function makeCorpus(seed, artifacts, quirks = []) {
154
164
  const counts = {};
155
165
  const formats = /* @__PURE__ */ new Set();
@@ -586,6 +596,28 @@ var ASTM_COMMENT_TEXT = Object.freeze([
586
596
  "Sample generated by @cosyte/synth.",
587
597
  "Placeholder result comment for conformance testing."
588
598
  ]);
599
+ function defaultHost() {
600
+ if (typeof undefined !== "function") return { require: __require, resolve: void 0 };
601
+ return { require: module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))), resolve: (s) => undefined(s) };
602
+ }
603
+ function isRequireEsmRefusal(error) {
604
+ return error?.code === "ERR_REQUIRE_ESM";
605
+ }
606
+ function loadPeer(specifier, host) {
607
+ if (host.resolve === void 0) return host.require(specifier);
608
+ const entry = url.fileURLToPath(host.resolve(specifier));
609
+ try {
610
+ return host.require(entry);
611
+ } catch (error) {
612
+ if (!isRequireEsmRefusal(error)) throw error;
613
+ return host.require(specifier);
614
+ }
615
+ }
616
+ function lazyPeer(specifier, host) {
617
+ let loaded;
618
+ return () => loaded ??= loadPeer(specifier, defaultHost());
619
+ }
620
+ var astmPeer = lazyPeer("@cosyte/astm");
589
621
 
590
622
  // src/astm/message.ts
591
623
  function resultValue(rng, low, high, decimals) {
@@ -640,7 +672,7 @@ function buildResultInput(options) {
640
672
  };
641
673
  }
642
674
  function generateAstmResult(options) {
643
- return astm.buildAstmMessage(buildResultInput(options));
675
+ return astmPeer().buildAstmMessage(buildResultInput(options));
644
676
  }
645
677
  function generateAstmOrder(options) {
646
678
  return generateAstmResult({ ...options, resultCount: 0, comment: false });
@@ -648,21 +680,23 @@ function generateAstmOrder(options) {
648
680
  function generateAstmResultFramed(options) {
649
681
  const raw = generateAstmResult(options);
650
682
  const recordLines = raw.split("\r").filter((line) => line.length > 0).map((line) => `${line}\r`);
651
- return astm.composeAstmFrames(recordLines);
683
+ return astmPeer().composeAstmFrames(recordLines);
652
684
  }
685
+
686
+ // src/astm/round-trip.ts
653
687
  function astmRoundTrip(raw) {
654
- const message = astm.parseAstmRecords(raw);
688
+ const message = astmPeer().parseAstmRecords(raw);
655
689
  const warnings = message.warnings.map((w) => String(w.code));
656
- const byteStable = astm.serializeAstmRecords(message) === raw;
690
+ const byteStable = astmPeer().serializeAstmRecords(message) === raw;
657
691
  return { content: raw, warnings, byteStable, specClean: warnings.length === 0 && byteStable };
658
692
  }
659
693
  function astmFramedRoundTrip(bytes) {
660
- const { message, frameWarnings } = astm.parseFramedAstm(bytes);
694
+ const { message, frameWarnings } = astmPeer().parseFramedAstm(bytes);
661
695
  const warnings = [
662
696
  ...frameWarnings.map((w) => String(w.code)),
663
697
  ...message.warnings.map((w) => String(w.code))
664
698
  ];
665
- const reframed = astm.serializeFramedAstm(message);
699
+ const reframed = astmPeer().serializeFramedAstm(message);
666
700
  const byteStable = bytesEqual(reframed, bytes);
667
701
  const content = latin1(bytes);
668
702
  return { content, warnings, byteStable, specClean: warnings.length === 0 && byteStable };
@@ -677,6 +711,11 @@ function latin1(bytes) {
677
711
  for (const b of bytes) out += String.fromCharCode(b);
678
712
  return out;
679
713
  }
714
+ function astmCorpusArtifact(raw, verify) {
715
+ if (!verify) return { content: raw, warnings: UNCHECKED };
716
+ const warnings = astmPeer().parseAstmRecords(raw).warnings.map((w) => String(w.code));
717
+ return { content: raw, warnings };
718
+ }
680
719
 
681
720
  // src/select.ts
682
721
  function resolveKind(allowed, requested) {
@@ -764,7 +803,7 @@ var ASTM_QUIRKS = Object.freeze({
764
803
  })
765
804
  });
766
805
  function toleratingProfile(quirk) {
767
- return quirk === "unknown-escape" ? astm.astmProfiles.referenceCorpus : void 0;
806
+ return quirk === "unknown-escape" ? astmPeer().astmProfiles.referenceCorpus : void 0;
768
807
  }
769
808
  var CR = "\r";
770
809
  function applyQuirk(quirk, records) {
@@ -808,7 +847,7 @@ function generateAstmQuirk(options) {
808
847
  }
809
848
  assertIntendedWarnings(
810
849
  descriptor.intendedWarnings,
811
- astm.parseAstmRecords(content).warnings.map((w) => String(w.code))
850
+ astmPeer().parseAstmRecords(content).warnings.map((w) => String(w.code))
812
851
  );
813
852
  return Object.freeze({
814
853
  format: "astm",
@@ -821,12 +860,10 @@ function generateAstmQuirk(options) {
821
860
  function astmQuirkRoundTrip(artifact) {
822
861
  const quirk = artifact.quirk;
823
862
  const descriptor = resolveQuirk(ASTM_QUIRKS, "astm", quirk);
824
- const bare = astm.parseAstmRecords(artifact.content).warnings.map((w) => String(w.code));
863
+ const bare = astmPeer().parseAstmRecords(artifact.content).warnings.map((w) => String(w.code));
825
864
  const profile = toleratingProfile(quirk);
826
865
  const withProfile = profile !== void 0 && descriptor.toleratingProfile !== void 0 ? (() => {
827
- const warnings = astm.parseAstmRecords(artifact.content, { profile }).warnings.map(
828
- (w) => String(w.code)
829
- );
866
+ const warnings = astmPeer().parseAstmRecords(artifact.content, { profile }).warnings.map((w) => String(w.code));
830
867
  return {
831
868
  profileName: descriptor.toleratingProfile,
832
869
  disposition: descriptor.disposition,
@@ -876,23 +913,23 @@ var astmQuirkProfile = defineSynthProfile({
876
913
  // src/astm/index.ts
877
914
  var ALL_KINDS = Object.freeze(["Result", "Order"]);
878
915
  var DEFAULT_MIX = ALL_KINDS;
879
- function generateKind(kind, seed) {
916
+ function generateKind(kind, seed, verify) {
880
917
  switch (kind) {
881
918
  case "Result":
882
- return astmRoundTrip(generateAstmResult({ seed }));
919
+ return astmCorpusArtifact(generateAstmResult({ seed }), verify);
883
920
  case "Order":
884
- return astmRoundTrip(generateAstmOrder({ seed }));
921
+ return astmCorpusArtifact(generateAstmOrder({ seed }), verify);
885
922
  }
886
923
  }
887
924
  function astmCorpus(options) {
888
- const { seed } = options;
925
+ const { seed, verify = true } = options;
889
926
  const mix = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
890
927
  const count = options.count ?? mix.length;
891
928
  const seedStream = createRng(seed);
892
929
  const artifacts = Array.from({ length: count }, (_unused, i) => {
893
930
  const kind = mix[i % mix.length] ?? "Result";
894
931
  const msgSeed = seedStream.nextUint32();
895
- const rt = generateKind(kind, msgSeed);
932
+ const rt = generateKind(kind, msgSeed, verify);
896
933
  return {
897
934
  format: "astm",
898
935
  kind,