@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
@@ -465,6 +465,12 @@ interface X12CorpusOptions {
465
465
  readonly count?: number;
466
466
  /** The transaction kinds to cycle through. Defaults to one of each. */
467
467
  readonly mix?: readonly X12CorpusKind[];
468
+ /**
469
+ * Whether each artifact is read back through its parser and the parser's findings recorded as its
470
+ * `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
471
+ * artifact's `warnings` is then empty without having been checked.
472
+ */
473
+ readonly verify?: boolean;
468
474
  }
469
475
  /**
470
476
  * Build a reproducible {@link Corpus} of spec-clean X12 transactions. Each transaction is generated from
@@ -465,6 +465,12 @@ interface X12CorpusOptions {
465
465
  readonly count?: number;
466
466
  /** The transaction kinds to cycle through. Defaults to one of each. */
467
467
  readonly mix?: readonly X12CorpusKind[];
468
+ /**
469
+ * Whether each artifact is read back through its parser and the parser's findings recorded as its
470
+ * `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
471
+ * artifact's `warnings` is then empty without having been checked.
472
+ */
473
+ readonly verify?: boolean;
468
474
  }
469
475
  /**
470
476
  * Build a reproducible {@link Corpus} of spec-clean X12 transactions. Each transaction is generated from
@@ -1,4 +1,12 @@
1
- import { X12Decimal, build837D, build837I, build837P, build835, build271, serializeX12, parseX12 } from '@cosyte/x12';
1
+ import { createRequire } from 'module';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
2
10
 
3
11
  // src/rng/splitmix32.ts
4
12
  function splitmix32(seed) {
@@ -148,6 +156,7 @@ function createRng(seed) {
148
156
  }
149
157
 
150
158
  // src/corpus.ts
159
+ var UNCHECKED = Object.freeze([]);
151
160
  function makeCorpus(seed, artifacts, quirks = []) {
152
161
  const counts = {};
153
162
  const formats = /* @__PURE__ */ new Set();
@@ -167,8 +176,32 @@ function makeCorpus(seed, artifacts, quirks = []) {
167
176
  artifacts: Object.freeze(frozenArtifacts)
168
177
  });
169
178
  }
179
+ function defaultHost() {
180
+ if (typeof import.meta.resolve !== "function") return { require: __require, resolve: void 0 };
181
+ return { require: createRequire(import.meta.url), resolve: (s) => import.meta.resolve(s) };
182
+ }
183
+ function isRequireEsmRefusal(error) {
184
+ return error?.code === "ERR_REQUIRE_ESM";
185
+ }
186
+ function loadPeer(specifier, host) {
187
+ if (host.resolve === void 0) return host.require(specifier);
188
+ const entry = fileURLToPath(host.resolve(specifier));
189
+ try {
190
+ return host.require(entry);
191
+ } catch (error) {
192
+ if (!isRequireEsmRefusal(error)) throw error;
193
+ return host.require(specifier);
194
+ }
195
+ }
196
+ function lazyPeer(specifier, host) {
197
+ let loaded;
198
+ return () => loaded ??= loadPeer(specifier, defaultHost());
199
+ }
200
+ var x12Peer = lazyPeer("@cosyte/x12");
201
+
202
+ // src/x12/money.ts
170
203
  function dec(value) {
171
- const d = X12Decimal.fromString(value);
204
+ const d = x12Peer().X12Decimal.fromString(value);
172
205
  if (d === void 0) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_INVALID_DECIMAL);
173
206
  return d;
174
207
  }
@@ -769,11 +802,11 @@ function generate837(variant, options) {
769
802
  const spec = specOf(rng, resolved);
770
803
  switch (resolved) {
771
804
  case "P":
772
- return build837P(spec);
805
+ return x12Peer().build837P(spec);
773
806
  case "I":
774
- return build837I(spec);
807
+ return x12Peer().build837I(spec);
775
808
  case "D":
776
- return build837D(spec);
809
+ return x12Peer().build837D(spec);
777
810
  }
778
811
  }
779
812
  function generate837P(options) {
@@ -785,6 +818,8 @@ function generate837I(options) {
785
818
  function generate837D(options) {
786
819
  return generate837("D", options);
787
820
  }
821
+
822
+ // src/x12/remit-835.ts
788
823
  function generate835(options) {
789
824
  const rng = createRng(options.seed);
790
825
  const partners = x12TradingPartners(rng);
@@ -885,8 +920,10 @@ function generate835(options) {
885
920
  },
886
921
  claims: [claim]
887
922
  };
888
- return build835(spec);
923
+ return x12Peer().build835(spec);
889
924
  }
925
+
926
+ // src/x12/eligibility-271.ts
890
927
  function generate271(options) {
891
928
  const rng = createRng(options.seed);
892
929
  const partners = x12TradingPartners(rng);
@@ -966,13 +1003,15 @@ function generate271(options) {
966
1003
  }
967
1004
  ]
968
1005
  };
969
- return build271(spec);
1006
+ return x12Peer().build271(spec);
970
1007
  }
1008
+
1009
+ // src/x12/round-trip.ts
971
1010
  function roundTrip(interchange) {
972
- const content = serializeX12(interchange);
973
- const reparsed = parseX12(content);
1011
+ const content = x12Peer().serializeX12(interchange);
1012
+ const reparsed = x12Peer().parseX12(content);
974
1013
  const warnings = reparsed.warnings.map((w) => String(w.code));
975
- const byteStable = serializeX12(reparsed) === content;
1014
+ const byteStable = x12Peer().serializeX12(reparsed) === content;
976
1015
  return {
977
1016
  content,
978
1017
  warnings,
@@ -980,6 +1019,14 @@ function roundTrip(interchange) {
980
1019
  specClean: warnings.length === 0 && byteStable
981
1020
  };
982
1021
  }
1022
+ function x12CorpusArtifact(interchange, verify) {
1023
+ const content = x12Peer().serializeX12(interchange);
1024
+ if (!verify) return { content, warnings: UNCHECKED };
1025
+ return {
1026
+ content,
1027
+ warnings: x12Peer().parseX12(content).warnings.map((w) => String(w.code))
1028
+ };
1029
+ }
983
1030
 
984
1031
  // src/x12/index.ts
985
1032
  var ALL_KINDS = Object.freeze(["837P", "837I", "837D", "835", "271"]);
@@ -987,26 +1034,26 @@ var DEFAULT_MIX = ALL_KINDS;
987
1034
  function generateKind(kind, seed) {
988
1035
  switch (kind) {
989
1036
  case "835":
990
- return roundTrip(generate835({ seed }));
1037
+ return generate835({ seed });
991
1038
  case "271":
992
- return roundTrip(generate271({ seed }));
1039
+ return generate271({ seed });
993
1040
  case "837P":
994
- return roundTrip(generate837("P", { seed }));
1041
+ return generate837("P", { seed });
995
1042
  case "837I":
996
- return roundTrip(generate837("I", { seed }));
1043
+ return generate837("I", { seed });
997
1044
  case "837D":
998
- return roundTrip(generate837("D", { seed }));
1045
+ return generate837("D", { seed });
999
1046
  }
1000
1047
  }
1001
1048
  function x12Corpus(options) {
1002
- const { seed } = options;
1049
+ const { seed, verify = true } = options;
1003
1050
  const mix = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
1004
1051
  const count = options.count ?? mix.length;
1005
1052
  const seedStream = createRng(seed);
1006
1053
  const artifacts = Array.from({ length: count }, (_unused, i) => {
1007
1054
  const kind = mix[i % mix.length] ?? "837P";
1008
1055
  const txSeed = seedStream.nextUint32();
1009
- const rt = generateKind(kind, txSeed);
1056
+ const rt = x12CorpusArtifact(generateKind(kind, txSeed), verify);
1010
1057
  return {
1011
1058
  format: "x12",
1012
1059
  kind,