@cosyte/synth 0.0.2 → 0.0.4
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/CHANGELOG.md +321 -0
- package/README.md +13 -4
- package/dist/astm/index.cjs +83 -42
- package/dist/astm/index.cjs.map +1 -1
- package/dist/astm/index.d.cts +1 -1
- package/dist/astm/index.d.ts +1 -1
- package/dist/astm/index.mjs +83 -42
- package/dist/astm/index.mjs.map +1 -1
- package/dist/ccda/index.cjs +89 -44
- package/dist/ccda/index.cjs.map +1 -1
- package/dist/ccda/index.d.cts +5 -3
- package/dist/ccda/index.d.ts +5 -3
- package/dist/ccda/index.mjs +89 -44
- package/dist/ccda/index.mjs.map +1 -1
- package/dist/deid/index.cjs +92 -13
- package/dist/deid/index.cjs.map +1 -1
- package/dist/deid/index.d.cts +1 -1
- package/dist/deid/index.d.ts +1 -1
- package/dist/deid/index.mjs +93 -14
- package/dist/deid/index.mjs.map +1 -1
- package/dist/fhir/index.cjs +78 -5
- package/dist/fhir/index.cjs.map +1 -1
- package/dist/fhir/index.mjs +78 -5
- package/dist/fhir/index.mjs.map +1 -1
- package/dist/hl7/index.cjs +89 -41
- package/dist/hl7/index.cjs.map +1 -1
- package/dist/hl7/index.d.cts +1 -1
- package/dist/hl7/index.d.ts +1 -1
- package/dist/hl7/index.mjs +89 -41
- package/dist/hl7/index.mjs.map +1 -1
- package/dist/index.cjs +91 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -8
- package/dist/index.d.ts +126 -8
- package/dist/index.mjs +89 -41
- package/dist/index.mjs.map +1 -1
- package/dist/ncpdp/index.cjs +56 -4
- package/dist/ncpdp/index.cjs.map +1 -1
- package/dist/ncpdp/index.mjs +56 -4
- package/dist/ncpdp/index.mjs.map +1 -1
- package/dist/{quirk-JLyO1Ncj.d.ts → quirk-C9t9CkPS.d.ts} +17 -6
- package/dist/{quirk-DmkgoZdh.d.cts → quirk-DYMDojVw.d.cts} +17 -6
- package/dist/x12/index.cjs +82 -13
- package/dist/x12/index.cjs.map +1 -1
- package/dist/x12/index.d.cts +2 -1
- package/dist/x12/index.d.ts +2 -1
- package/dist/x12/index.mjs +83 -14
- package/dist/x12/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/ncpdp/index.mjs
CHANGED
|
@@ -31,6 +31,45 @@ function sfc32Next(s) {
|
|
|
31
31
|
return t >>> 0;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// src/codes.ts
|
|
35
|
+
var SYNTH_FATAL_CODES = {
|
|
36
|
+
/** An integer range was requested with its maximum below its minimum. Fatal. */
|
|
37
|
+
SYNTH_INVALID_RANGE: "SYNTH_INVALID_RANGE",
|
|
38
|
+
/** A value was drawn from an empty pool. Fatal — never a fabricated substitute. */
|
|
39
|
+
SYNTH_EMPTY_POOL: "SYNTH_EMPTY_POOL",
|
|
40
|
+
/**
|
|
41
|
+
* A caller-supplied selector (a message kind, a document type, a corpus mix entry, a claim
|
|
42
|
+
* variant, a Bundle type, a resource profile) is not in the closed set that governs it. Fatal —
|
|
43
|
+
* see `resolveKind`: a selector union is erased at run time, and a selector that falls through
|
|
44
|
+
* either mislabels the fixture or hands the value to a peer builder that quotes it back.
|
|
45
|
+
*/
|
|
46
|
+
SYNTH_UNSUPPORTED_KIND: "SYNTH_UNSUPPORTED_KIND"
|
|
47
|
+
};
|
|
48
|
+
var SYNTH_FATAL_MESSAGES = Object.freeze({
|
|
49
|
+
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.",
|
|
50
|
+
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).",
|
|
51
|
+
SYNTH_QUIRK_ANCHOR_ABSENT: "The quirk transform found no structural anchor to mutate, so the fixture would not carry the deviation it is labelled with. Refusing to emit a mislabeled fixture.",
|
|
52
|
+
SYNTH_INTENDED_WARNING_MISMATCH: "A bare parse of the generated quirk artifact did not produce exactly the declared intended warning code(s). Refusing to emit a mislabeled fixture.",
|
|
53
|
+
SYNTH_UNMAPPED_CODE_SYSTEM: "The concept's code-system URI has no OID mapping in the C-CDA example-code table.",
|
|
54
|
+
SYNTH_INVALID_DECIMAL: "The value could not be read as an X12 decimal.",
|
|
55
|
+
SYNTH_INVALID_RANGE: "An integer range was requested with its maximum below its minimum.",
|
|
56
|
+
SYNTH_EMPTY_POOL: "A value was drawn from an empty pool.",
|
|
57
|
+
SYNTH_INVALID_PROFILE: "defineSynthProfile requires a non-empty string name.",
|
|
58
|
+
SYNTH_UNSUPPORTED_KIND: "The requested kind, document type, corpus mix entry, variant or profile is not one this generator supports. The supported set is the exported union for that option."
|
|
59
|
+
});
|
|
60
|
+
var SynthError = class extends Error {
|
|
61
|
+
/** The stable fatal code. */
|
|
62
|
+
code;
|
|
63
|
+
/**
|
|
64
|
+
* @param code - The stable {@link SynthFatalCode}. The message comes from the frozen registry.
|
|
65
|
+
*/
|
|
66
|
+
constructor(code) {
|
|
67
|
+
super(SYNTH_FATAL_MESSAGES[code]);
|
|
68
|
+
this.name = "SynthError";
|
|
69
|
+
this.code = code;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
34
73
|
// src/rng/rng.ts
|
|
35
74
|
var Sfc32Rng = class {
|
|
36
75
|
seed;
|
|
@@ -48,7 +87,7 @@ var Sfc32Rng = class {
|
|
|
48
87
|
return this.nextUint32() / 4294967296;
|
|
49
88
|
}
|
|
50
89
|
int(min, max) {
|
|
51
|
-
if (max < min) throw new
|
|
90
|
+
if (max < min) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_INVALID_RANGE);
|
|
52
91
|
const span = max - min + 1;
|
|
53
92
|
return min + Math.floor(this.float() * span);
|
|
54
93
|
}
|
|
@@ -56,7 +95,7 @@ var Sfc32Rng = class {
|
|
|
56
95
|
return this.float() < p;
|
|
57
96
|
}
|
|
58
97
|
pick(items) {
|
|
59
|
-
if (items.length === 0) throw new
|
|
98
|
+
if (items.length === 0) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_EMPTY_POOL);
|
|
60
99
|
return items[this.int(0, items.length - 1)];
|
|
61
100
|
}
|
|
62
101
|
digits(n) {
|
|
@@ -649,8 +688,19 @@ function telecomRoundTrip(wire) {
|
|
|
649
688
|
return { content: wire, warnings, byteStable, specClean: warnings.length === 0 && byteStable };
|
|
650
689
|
}
|
|
651
690
|
|
|
691
|
+
// src/select.ts
|
|
692
|
+
function resolveKind(allowed, requested) {
|
|
693
|
+
const match = allowed.find((value) => value === requested);
|
|
694
|
+
if (match === void 0) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_KIND);
|
|
695
|
+
return match;
|
|
696
|
+
}
|
|
697
|
+
function resolveMix(allowed, requested, fallback) {
|
|
698
|
+
if (requested === void 0) return fallback;
|
|
699
|
+
return requested.map((entry) => resolveKind(allowed, entry));
|
|
700
|
+
}
|
|
701
|
+
|
|
652
702
|
// src/ncpdp/index.ts
|
|
653
|
-
var
|
|
703
|
+
var ALL_KINDS = Object.freeze([
|
|
654
704
|
"NewRx",
|
|
655
705
|
"RxRenewalRequest",
|
|
656
706
|
"RxChangeRequest",
|
|
@@ -658,6 +708,7 @@ var DEFAULT_MIX = Object.freeze([
|
|
|
658
708
|
"B2",
|
|
659
709
|
"B3"
|
|
660
710
|
]);
|
|
711
|
+
var DEFAULT_MIX = ALL_KINDS;
|
|
661
712
|
function generateKind(kind, seed) {
|
|
662
713
|
switch (kind) {
|
|
663
714
|
case "NewRx":
|
|
@@ -673,7 +724,8 @@ function generateKind(kind, seed) {
|
|
|
673
724
|
}
|
|
674
725
|
}
|
|
675
726
|
function ncpdpCorpus(options) {
|
|
676
|
-
const { seed
|
|
727
|
+
const { seed } = options;
|
|
728
|
+
const mix = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
|
|
677
729
|
const count = options.count ?? mix.length;
|
|
678
730
|
const seedStream = createRng(seed);
|
|
679
731
|
const artifacts = Array.from({ length: count }, (_unused, i) => {
|