@cosyte/synth 0.1.4 → 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.
- package/CHANGELOG.md +24 -0
- package/README.md +14 -10
- package/dist/astm/index.cjs +164 -102
- package/dist/astm/index.cjs.map +1 -1
- package/dist/astm/index.d.cts +7 -0
- package/dist/astm/index.d.ts +7 -0
- package/dist/astm/index.mjs +163 -102
- package/dist/astm/index.mjs.map +1 -1
- package/dist/ccda/index.cjs +100 -28
- package/dist/ccda/index.cjs.map +1 -1
- package/dist/ccda/index.d.cts +6 -0
- package/dist/ccda/index.d.ts +6 -0
- package/dist/ccda/index.mjs +87 -16
- package/dist/ccda/index.mjs.map +1 -1
- package/dist/deid/index.cjs +305 -165
- package/dist/deid/index.cjs.map +1 -1
- package/dist/deid/index.mjs +292 -153
- package/dist/deid/index.mjs.map +1 -1
- package/dist/fhir/index.cjs +179 -76
- package/dist/fhir/index.cjs.map +1 -1
- package/dist/fhir/index.d.cts +6 -0
- package/dist/fhir/index.d.ts +6 -0
- package/dist/fhir/index.mjs +178 -76
- package/dist/fhir/index.mjs.map +1 -1
- package/dist/hl7/index.cjs +86 -12
- package/dist/hl7/index.cjs.map +1 -1
- package/dist/hl7/index.d.cts +6 -0
- package/dist/hl7/index.d.ts +6 -0
- package/dist/hl7/index.mjs +85 -12
- package/dist/hl7/index.mjs.map +1 -1
- package/dist/index.cjs +3 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- package/dist/index.mjs +3 -5
- package/dist/index.mjs.map +1 -1
- package/dist/ncpdp/index.cjs +131 -36
- package/dist/ncpdp/index.cjs.map +1 -1
- package/dist/ncpdp/index.d.cts +7 -0
- package/dist/ncpdp/index.d.ts +7 -0
- package/dist/ncpdp/index.mjs +130 -36
- package/dist/ncpdp/index.mjs.map +1 -1
- package/dist/x12/index.cjs +147 -50
- package/dist/x12/index.cjs.map +1 -1
- package/dist/x12/index.d.cts +6 -0
- package/dist/x12/index.d.ts +6 -0
- package/dist/x12/index.mjs +146 -50
- package/dist/x12/index.mjs.map +1 -1
- package/package.json +20 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
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
|
+
|
|
15
|
+
## 0.1.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 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.
|
|
20
|
+
|
|
21
|
+
No generated value, export, warning code or seed mapping changes.
|
|
22
|
+
|
|
23
|
+
- 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.
|
|
24
|
+
|
|
25
|
+
No generated value, export, warning code or seed mapping changes.
|
|
26
|
+
|
|
3
27
|
## 0.1.4
|
|
4
28
|
|
|
5
29
|
### 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
|
|
66
|
-
|
|
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
|
|
@@ -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)
|
|
371
|
-
|
|
372
|
-
-
|
|
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),
|
|
375
|
-
[the `@cosyte/deid` pairing loop](https://docs.cosyte.com/synth/guides-deid).
|
|
376
|
-
|
|
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.
|
|
384
|
-
|
|
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
|
|
package/dist/astm/index.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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) {
|
|
@@ -32,7 +41,16 @@ function sfc32Next(s) {
|
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
// src/codes.ts
|
|
35
|
-
var SYNTH_FATAL_CODES = {
|
|
44
|
+
var SYNTH_FATAL_CODES = Object.freeze({
|
|
45
|
+
/**
|
|
46
|
+
* A format was requested that this build cannot generate through a real parser builder/serializer.
|
|
47
|
+
* Fatal, never a hand-written byte fallback.
|
|
48
|
+
*
|
|
49
|
+
* **No code path in this build raises it.** All six formats generate, so it is reserved for a
|
|
50
|
+
* future format that does not, and is kept because removing a published code is a breaking change.
|
|
51
|
+
* An unsupported *kind* within a format that does generate is `SYNTH_UNSUPPORTED_KIND`.
|
|
52
|
+
*/
|
|
53
|
+
SYNTH_UNSUPPORTED_FORMAT: "SYNTH_UNSUPPORTED_FORMAT",
|
|
36
54
|
/**
|
|
37
55
|
* A vendor quirk was requested that the target format's profile system does not support. Fatal,
|
|
38
56
|
* never a silent no-op and never a fabricated quirk.
|
|
@@ -49,6 +67,10 @@ var SYNTH_FATAL_CODES = {
|
|
|
49
67
|
* warning code(s). Fatal, never emit a mislabeled fixture.
|
|
50
68
|
*/
|
|
51
69
|
SYNTH_INTENDED_WARNING_MISMATCH: "SYNTH_INTENDED_WARNING_MISMATCH",
|
|
70
|
+
/** A concept's code-system URI has no OID mapping in the C-CDA example-code table. Fatal. */
|
|
71
|
+
SYNTH_UNMAPPED_CODE_SYSTEM: "SYNTH_UNMAPPED_CODE_SYSTEM",
|
|
72
|
+
/** A money value could not be read as an X12 decimal. Fatal: a generator never rounds to a float. */
|
|
73
|
+
SYNTH_INVALID_DECIMAL: "SYNTH_INVALID_DECIMAL",
|
|
52
74
|
/** An integer range was requested with its maximum below its minimum. Fatal. */
|
|
53
75
|
SYNTH_INVALID_RANGE: "SYNTH_INVALID_RANGE",
|
|
54
76
|
/** A value was drawn from an empty pool. Fatal, never a fabricated substitute. */
|
|
@@ -61,7 +83,17 @@ var SYNTH_FATAL_CODES = {
|
|
|
61
83
|
* see `resolveKind`: a selector union is erased at run time, and a selector that falls through
|
|
62
84
|
* either mislabels the fixture or hands the value to a peer builder that quotes it back.
|
|
63
85
|
*/
|
|
64
|
-
SYNTH_UNSUPPORTED_KIND: "SYNTH_UNSUPPORTED_KIND"
|
|
86
|
+
SYNTH_UNSUPPORTED_KIND: "SYNTH_UNSUPPORTED_KIND",
|
|
87
|
+
/**
|
|
88
|
+
* A requested profile IS published by the adopted implementation guide, and this build does not
|
|
89
|
+
* generate it. Deliberately distinct from `SYNTH_UNSUPPORTED_KIND`, which says the name is not in
|
|
90
|
+
* the adopted set at all: "the guide does not publish this" and "we do not generate this yet" are
|
|
91
|
+
* different answers, and a caller building to a regulatory profile set has to be able to tell them
|
|
92
|
+
* apart without matching message text. Fatal, and raised **before** anything is generated: a
|
|
93
|
+
* mislabelled artifact is worse than no artifact.
|
|
94
|
+
*/
|
|
95
|
+
SYNTH_PROFILE_NOT_GENERATED: "SYNTH_PROFILE_NOT_GENERATED"
|
|
96
|
+
});
|
|
65
97
|
var SYNTH_FATAL_MESSAGES = Object.freeze({
|
|
66
98
|
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
99
|
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).",
|
|
@@ -127,6 +159,7 @@ function createRng(seed) {
|
|
|
127
159
|
}
|
|
128
160
|
|
|
129
161
|
// src/corpus.ts
|
|
162
|
+
var UNCHECKED = Object.freeze([]);
|
|
130
163
|
function makeCorpus(seed, artifacts, quirks = []) {
|
|
131
164
|
const counts = {};
|
|
132
165
|
const formats = /* @__PURE__ */ new Set();
|
|
@@ -472,88 +505,90 @@ function astmHeaderIdentity(rng) {
|
|
|
472
505
|
}
|
|
473
506
|
|
|
474
507
|
// src/astm/example-codes.ts
|
|
475
|
-
var EXAMPLE_ASTM_TESTS = Object.freeze(
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
508
|
+
var EXAMPLE_ASTM_TESTS = Object.freeze(
|
|
509
|
+
[
|
|
510
|
+
{
|
|
511
|
+
localCode: "GLU",
|
|
512
|
+
loinc: "2345-7",
|
|
513
|
+
name: "Glucose",
|
|
514
|
+
units: "mg/dL",
|
|
515
|
+
referenceRange: "70-110",
|
|
516
|
+
valueLow: 55,
|
|
517
|
+
valueHigh: 260,
|
|
518
|
+
decimals: 0
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
localCode: "K",
|
|
522
|
+
loinc: "2823-3",
|
|
523
|
+
name: "Potassium",
|
|
524
|
+
units: "mmol/L",
|
|
525
|
+
referenceRange: "3.5-5.1",
|
|
526
|
+
valueLow: 28,
|
|
527
|
+
valueHigh: 62,
|
|
528
|
+
decimals: 1
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
localCode: "NA",
|
|
532
|
+
loinc: "2951-2",
|
|
533
|
+
name: "Sodium",
|
|
534
|
+
units: "mmol/L",
|
|
535
|
+
referenceRange: "136-145",
|
|
536
|
+
valueLow: 125,
|
|
537
|
+
valueHigh: 155,
|
|
538
|
+
decimals: 0
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
localCode: "CREA",
|
|
542
|
+
loinc: "2160-0",
|
|
543
|
+
name: "Creatinine",
|
|
544
|
+
units: "mg/dL",
|
|
545
|
+
referenceRange: "0.6-1.3",
|
|
546
|
+
valueLow: 4,
|
|
547
|
+
valueHigh: 32,
|
|
548
|
+
decimals: 1
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
localCode: "HGB",
|
|
552
|
+
loinc: "718-7",
|
|
553
|
+
name: "Hemoglobin",
|
|
554
|
+
units: "g/dL",
|
|
555
|
+
referenceRange: "12.0-17.5",
|
|
556
|
+
valueLow: 80,
|
|
557
|
+
valueHigh: 190,
|
|
558
|
+
decimals: 1
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
localCode: "WBC",
|
|
562
|
+
loinc: "6690-2",
|
|
563
|
+
name: "Leukocytes",
|
|
564
|
+
units: "10*3/uL",
|
|
565
|
+
referenceRange: "4.5-11.0",
|
|
566
|
+
valueLow: 30,
|
|
567
|
+
valueHigh: 150,
|
|
568
|
+
decimals: 1
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
localCode: "TSH",
|
|
572
|
+
loinc: "3016-3",
|
|
573
|
+
name: "Thyrotropin",
|
|
574
|
+
units: "mIU/L",
|
|
575
|
+
referenceRange: "0.40-4.50",
|
|
576
|
+
valueLow: 2,
|
|
577
|
+
valueHigh: 90,
|
|
578
|
+
decimals: 2
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
localCode: "ALT",
|
|
582
|
+
loinc: "1742-6",
|
|
583
|
+
name: "Alanine aminotransferase",
|
|
584
|
+
units: "U/L",
|
|
585
|
+
referenceRange: "7-56",
|
|
586
|
+
valueLow: 5,
|
|
587
|
+
valueHigh: 120,
|
|
588
|
+
decimals: 0
|
|
589
|
+
}
|
|
590
|
+
].map((entry) => Object.freeze(entry))
|
|
591
|
+
);
|
|
557
592
|
var ASTM_ABNORMAL_FLAGS = Object.freeze(["N", "L", "H", "A"]);
|
|
558
593
|
var ASTM_RESULT_STATUSES = Object.freeze(["F", "P", "C"]);
|
|
559
594
|
var ASTM_COMMENT_TEXT = Object.freeze([
|
|
@@ -561,6 +596,28 @@ var ASTM_COMMENT_TEXT = Object.freeze([
|
|
|
561
596
|
"Sample generated by @cosyte/synth.",
|
|
562
597
|
"Placeholder result comment for conformance testing."
|
|
563
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");
|
|
564
621
|
|
|
565
622
|
// src/astm/message.ts
|
|
566
623
|
function resultValue(rng, low, high, decimals) {
|
|
@@ -615,7 +672,7 @@ function buildResultInput(options) {
|
|
|
615
672
|
};
|
|
616
673
|
}
|
|
617
674
|
function generateAstmResult(options) {
|
|
618
|
-
return
|
|
675
|
+
return astmPeer().buildAstmMessage(buildResultInput(options));
|
|
619
676
|
}
|
|
620
677
|
function generateAstmOrder(options) {
|
|
621
678
|
return generateAstmResult({ ...options, resultCount: 0, comment: false });
|
|
@@ -623,21 +680,23 @@ function generateAstmOrder(options) {
|
|
|
623
680
|
function generateAstmResultFramed(options) {
|
|
624
681
|
const raw = generateAstmResult(options);
|
|
625
682
|
const recordLines = raw.split("\r").filter((line) => line.length > 0).map((line) => `${line}\r`);
|
|
626
|
-
return
|
|
683
|
+
return astmPeer().composeAstmFrames(recordLines);
|
|
627
684
|
}
|
|
685
|
+
|
|
686
|
+
// src/astm/round-trip.ts
|
|
628
687
|
function astmRoundTrip(raw) {
|
|
629
|
-
const message =
|
|
688
|
+
const message = astmPeer().parseAstmRecords(raw);
|
|
630
689
|
const warnings = message.warnings.map((w) => String(w.code));
|
|
631
|
-
const byteStable =
|
|
690
|
+
const byteStable = astmPeer().serializeAstmRecords(message) === raw;
|
|
632
691
|
return { content: raw, warnings, byteStable, specClean: warnings.length === 0 && byteStable };
|
|
633
692
|
}
|
|
634
693
|
function astmFramedRoundTrip(bytes) {
|
|
635
|
-
const { message, frameWarnings } =
|
|
694
|
+
const { message, frameWarnings } = astmPeer().parseFramedAstm(bytes);
|
|
636
695
|
const warnings = [
|
|
637
696
|
...frameWarnings.map((w) => String(w.code)),
|
|
638
697
|
...message.warnings.map((w) => String(w.code))
|
|
639
698
|
];
|
|
640
|
-
const reframed =
|
|
699
|
+
const reframed = astmPeer().serializeFramedAstm(message);
|
|
641
700
|
const byteStable = bytesEqual(reframed, bytes);
|
|
642
701
|
const content = latin1(bytes);
|
|
643
702
|
return { content, warnings, byteStable, specClean: warnings.length === 0 && byteStable };
|
|
@@ -652,6 +711,11 @@ function latin1(bytes) {
|
|
|
652
711
|
for (const b of bytes) out += String.fromCharCode(b);
|
|
653
712
|
return out;
|
|
654
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
|
+
}
|
|
655
719
|
|
|
656
720
|
// src/select.ts
|
|
657
721
|
function resolveKind(allowed, requested) {
|
|
@@ -739,7 +803,7 @@ var ASTM_QUIRKS = Object.freeze({
|
|
|
739
803
|
})
|
|
740
804
|
});
|
|
741
805
|
function toleratingProfile(quirk) {
|
|
742
|
-
return quirk === "unknown-escape" ?
|
|
806
|
+
return quirk === "unknown-escape" ? astmPeer().astmProfiles.referenceCorpus : void 0;
|
|
743
807
|
}
|
|
744
808
|
var CR = "\r";
|
|
745
809
|
function applyQuirk(quirk, records) {
|
|
@@ -783,7 +847,7 @@ function generateAstmQuirk(options) {
|
|
|
783
847
|
}
|
|
784
848
|
assertIntendedWarnings(
|
|
785
849
|
descriptor.intendedWarnings,
|
|
786
|
-
|
|
850
|
+
astmPeer().parseAstmRecords(content).warnings.map((w) => String(w.code))
|
|
787
851
|
);
|
|
788
852
|
return Object.freeze({
|
|
789
853
|
format: "astm",
|
|
@@ -796,12 +860,10 @@ function generateAstmQuirk(options) {
|
|
|
796
860
|
function astmQuirkRoundTrip(artifact) {
|
|
797
861
|
const quirk = artifact.quirk;
|
|
798
862
|
const descriptor = resolveQuirk(ASTM_QUIRKS, "astm", quirk);
|
|
799
|
-
const bare =
|
|
863
|
+
const bare = astmPeer().parseAstmRecords(artifact.content).warnings.map((w) => String(w.code));
|
|
800
864
|
const profile = toleratingProfile(quirk);
|
|
801
865
|
const withProfile = profile !== void 0 && descriptor.toleratingProfile !== void 0 ? (() => {
|
|
802
|
-
const warnings =
|
|
803
|
-
(w) => String(w.code)
|
|
804
|
-
);
|
|
866
|
+
const warnings = astmPeer().parseAstmRecords(artifact.content, { profile }).warnings.map((w) => String(w.code));
|
|
805
867
|
return {
|
|
806
868
|
profileName: descriptor.toleratingProfile,
|
|
807
869
|
disposition: descriptor.disposition,
|
|
@@ -851,23 +913,23 @@ var astmQuirkProfile = defineSynthProfile({
|
|
|
851
913
|
// src/astm/index.ts
|
|
852
914
|
var ALL_KINDS = Object.freeze(["Result", "Order"]);
|
|
853
915
|
var DEFAULT_MIX = ALL_KINDS;
|
|
854
|
-
function generateKind(kind, seed) {
|
|
916
|
+
function generateKind(kind, seed, verify) {
|
|
855
917
|
switch (kind) {
|
|
856
918
|
case "Result":
|
|
857
|
-
return
|
|
919
|
+
return astmCorpusArtifact(generateAstmResult({ seed }), verify);
|
|
858
920
|
case "Order":
|
|
859
|
-
return
|
|
921
|
+
return astmCorpusArtifact(generateAstmOrder({ seed }), verify);
|
|
860
922
|
}
|
|
861
923
|
}
|
|
862
924
|
function astmCorpus(options) {
|
|
863
|
-
const { seed } = options;
|
|
925
|
+
const { seed, verify = true } = options;
|
|
864
926
|
const mix = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
|
|
865
927
|
const count = options.count ?? mix.length;
|
|
866
928
|
const seedStream = createRng(seed);
|
|
867
929
|
const artifacts = Array.from({ length: count }, (_unused, i) => {
|
|
868
930
|
const kind = mix[i % mix.length] ?? "Result";
|
|
869
931
|
const msgSeed = seedStream.nextUint32();
|
|
870
|
-
const rt = generateKind(kind, msgSeed);
|
|
932
|
+
const rt = generateKind(kind, msgSeed, verify);
|
|
871
933
|
return {
|
|
872
934
|
format: "astm",
|
|
873
935
|
kind,
|