@cosyte/astm 0.0.15 → 0.0.18
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 +290 -0
- package/README.md +118 -11
- package/dist/index.cjs +413 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +965 -58
- package/dist/index.d.ts +965 -58
- package/dist/index.mjs +407 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,19 @@ var FATAL_CODES = {
|
|
|
6
6
|
EMPTY_INPUT: "EMPTY_INPUT",
|
|
7
7
|
/** The first record is not an `H` (header) record: an ASTM message must lead with `H`. */
|
|
8
8
|
ASTM_RECORD_NO_HEADER: "ASTM_RECORD_NO_HEADER",
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* The first `H` record could not declare all four delimiters (field/repeat/component/escape).
|
|
11
|
+
* One code, four reasons, and the message says which: the record is not a header, it is shorter
|
|
12
|
+
* than a header plus a three-character definition, its definition field holds fewer than three
|
|
13
|
+
* characters before the next field separator, or its field separator is also one of the other
|
|
14
|
+
* three. Only the second of those is "too short", so read the message rather than assuming it.
|
|
15
|
+
*
|
|
16
|
+
* **Two of the four cannot be reached on this fatal, and are not dead code.** A first record that
|
|
17
|
+
* is not an `H` raises `ASTM_RECORD_NO_HEADER` before the declaration is ever read, and a field
|
|
18
|
+
* separator reused among the other three ends the delimiter definition where it appears, so the
|
|
19
|
+
* truncation reason answers first. The reader names all four because it is also called directly
|
|
20
|
+
* and on later headers, where the same conditions are a warning rather than this fatal.
|
|
21
|
+
*/
|
|
10
22
|
ASTM_RECORD_UNDECLARED_DELIMITERS: "ASTM_RECORD_UNDECLARED_DELIMITERS"
|
|
11
23
|
};
|
|
12
24
|
var AstmParseError = class extends Error {
|
|
@@ -45,17 +57,26 @@ var CANONICAL_DELIMITERS = {
|
|
|
45
57
|
escape: "&"
|
|
46
58
|
};
|
|
47
59
|
function readDelimiters(headerRecord) {
|
|
48
|
-
|
|
49
|
-
|
|
60
|
+
const result = readDelimiterDeclaration(headerRecord);
|
|
61
|
+
return result.ok ? result.delimiters : void 0;
|
|
62
|
+
}
|
|
63
|
+
function readDelimiterDeclaration(headerRecord) {
|
|
64
|
+
if (headerRecord.charAt(0) !== "H") return { ok: false, fault: "not-a-header" };
|
|
65
|
+
if (headerRecord.length < 5) return { ok: false, fault: "record-too-short" };
|
|
50
66
|
const field = headerRecord.charAt(1);
|
|
51
67
|
const defEnd = headerRecord.indexOf(field, 2);
|
|
52
68
|
const definition = headerRecord.slice(2, defEnd === -1 ? headerRecord.length : defEnd);
|
|
53
|
-
if (definition.length < 3) return
|
|
69
|
+
if (definition.length < 3) return { ok: false, fault: "definition-truncated" };
|
|
54
70
|
const repeat = definition.charAt(0);
|
|
55
71
|
const component = definition.charAt(1);
|
|
56
72
|
const escape = definition.charAt(2);
|
|
57
|
-
if (field === repeat || field === component || field === escape)
|
|
58
|
-
|
|
73
|
+
if (field === repeat || field === component || field === escape) {
|
|
74
|
+
return { ok: false, fault: "field-separator-reused" };
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, delimiters: { field, repeat, component, escape } };
|
|
77
|
+
}
|
|
78
|
+
function hasCollidingRoles(d) {
|
|
79
|
+
return d.repeat === d.component || d.repeat === d.escape || d.component === d.escape;
|
|
59
80
|
}
|
|
60
81
|
function isNonStandard(d) {
|
|
61
82
|
return d.field !== CANONICAL_DELIMITERS.field || d.repeat !== CANONICAL_DELIMITERS.repeat || d.component !== CANONICAL_DELIMITERS.component || d.escape !== CANONICAL_DELIMITERS.escape;
|
|
@@ -144,18 +165,237 @@ var WARNING_CODES = {
|
|
|
144
165
|
* boundaries, silently, and this can happen to one record inside a run of these warnings); and a
|
|
145
166
|
* set differing in the repeat, component or escape role usually splits into fields normally,
|
|
146
167
|
* where a mis-split component can cost a test identity while the value survives, and where an
|
|
147
|
-
* `&X&` sequence whose body is
|
|
168
|
+
* `&X&` sequence whose body is an unrecognized character that is itself a delimiter in force is an
|
|
169
|
+
* opaque atom, so that delimiter does not split
|
|
148
170
|
* and every field after it shifts. The escape role's worst case has narrowed and not
|
|
149
171
|
* disappeared: an escape character heading no sequence is now read as a literal and reported
|
|
150
172
|
* under {@link WARNING_CODES.ASTM_UNPAIRED_ESCAPE_CHARACTER} rather than merging the rest of the
|
|
151
|
-
* record,
|
|
152
|
-
* {@link WARNING_CODES.
|
|
173
|
+
* record, and a delimiter swallowed inside an `&X&` body now raises
|
|
174
|
+
* {@link WARNING_CODES.ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE} as well as the tolerable
|
|
175
|
+
* {@link WARNING_CODES.ASTM_UNKNOWN_ESCAPE_SEQUENCE}, though it still splits the same way. The
|
|
176
|
+
* mirror of that case, where the leftmost alignment lets a delimiter split that a competing
|
|
177
|
+
* alignment would have held, gains a boundary rather than losing one, so the record splits into
|
|
178
|
+
* more fields than another reading gives and this code cannot see it either
|
|
179
|
+
* ({@link WARNING_CODES.ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT} reports that). Treat this code as a
|
|
153
180
|
* report that one record definitely lost its fields, never as a sweep that would have fired if
|
|
154
181
|
* any had.
|
|
155
182
|
*/
|
|
156
183
|
ASTM_RECORD_FIELDS_UNSEPARATED: "ASTM_RECORD_FIELDS_UNSEPARATED",
|
|
157
184
|
/** The header declared delimiters other than the canonical `H|\^&`: tolerated, noted. */
|
|
158
185
|
ASTM_NONSTANDARD_DELIMITERS: "ASTM_NONSTANDARD_DELIMITERS",
|
|
186
|
+
/**
|
|
187
|
+
* A header declared **one character in two roles**, so the boundary between those two roles is
|
|
188
|
+
* not recoverable from the bytes. The declaration is still read and honored and no record is
|
|
189
|
+
* dropped: what is gone is a distinction the sender's own bytes no longer carry.
|
|
190
|
+
*
|
|
191
|
+
* The field separator is not part of this: a declaration naming it in another role is refused
|
|
192
|
+
* earlier (the `ASTM_RECORD_UNDECLARED_DELIMITERS` fatal on the first header,
|
|
193
|
+
* {@link WARNING_CODES.ASTM_RECORD_UNREADABLE_REDECLARATION} on a later one). What this code
|
|
194
|
+
* covers is the three unordered pairs among the rest: **repeat/component, repeat/escape,
|
|
195
|
+
* component/escape**.
|
|
196
|
+
*
|
|
197
|
+
* Measured on `H|^^&` (repeat and component both `^`): the field `A^B^C^D` reads back as four
|
|
198
|
+
* repeats of one component each, so `components` holds only `A` and a two-repeats-of-two-components
|
|
199
|
+
* reading cannot be recovered. Measured on `H|\&&` (component and escape both `&`): `A&B` splits
|
|
200
|
+
* into two components while `A&F&B` reads as the single component `A|B`, so the same character
|
|
201
|
+
* means two different things depending on what follows it.
|
|
202
|
+
*
|
|
203
|
+
* **It is not tolerable**, and the reason is the pair it travels with: such a set is always
|
|
204
|
+
* non-canonical, so before this code existed the only warning on the stream was
|
|
205
|
+
* {@link WARNING_CODES.ASTM_NONSTANDARD_DELIMITERS}, which a profile may tolerate. That made a
|
|
206
|
+
* structurally unreadable declaration indistinguishable, to a strict consumer, from an ordinary
|
|
207
|
+
* vendor set. Emit refuses the same sets outright (`ASTM_EMIT_INVALID_DELIMITERS`).
|
|
208
|
+
*
|
|
209
|
+
* One warning per header that **changes** the set in force into such a set, not one per colliding
|
|
210
|
+
* pair. A later header restating the colliding set already in force is a no-op and warns nothing,
|
|
211
|
+
* on the same rule as {@link WARNING_CODES.ASTM_NONSTANDARD_DELIMITERS}: the set it names was
|
|
212
|
+
* already reported when it came into force.
|
|
213
|
+
*/
|
|
214
|
+
ASTM_RECORD_DELIMITER_ROLE_COLLISION: "ASTM_RECORD_DELIMITER_ROLE_COLLISION",
|
|
215
|
+
/**
|
|
216
|
+
* An escape sequence whose body was **not** a recognized mnemonic held a character that is one of
|
|
217
|
+
* the three splitting delimiters in force, and the atom rule (an `&X&` triple is opaque) kept it
|
|
218
|
+
* out of the split, so a boundary the bytes carried never became one. The sequence is preserved
|
|
219
|
+
* verbatim in the value; nothing is dropped and nothing is re-split.
|
|
220
|
+
*
|
|
221
|
+
* Measured on the canonical set: `R|1|^^^687|28.6&|&U/L||||F` reads `value` = `28.6&|&U/L`, with
|
|
222
|
+
* **no units** and status `unspecified` rather than `final`.
|
|
223
|
+
*
|
|
224
|
+
* **This is the code that says a boundary was lost.** The same condition also raises
|
|
225
|
+
* {@link WARNING_CODES.ASTM_UNKNOWN_ESCAPE_SEQUENCE}, which stays and stays tolerable: that code
|
|
226
|
+
* reports only that a body was not recognized, which is true of bodies that cost nothing. This one
|
|
227
|
+
* is the narrower, safety-critical half, and no profile may tolerate it.
|
|
228
|
+
*
|
|
229
|
+
* **What it does not do is repair anything.** The atom rule is unchanged (it is what keeps `&F&`
|
|
230
|
+
* one token under a set that names `F` as a delimiter), so the value is byte-identical to what it
|
|
231
|
+
* was before this code existed. It also cannot see the condition through a re-emit: emit rewrites
|
|
232
|
+
* the preserved sequence into recognized mnemonics, and the resulting stream says that value
|
|
233
|
+
* unambiguously, so a second-generation read is silent and correct about its own bytes. The place
|
|
234
|
+
* to catch this is the first read of the wire bytes, which is where it now refuses a strict parse.
|
|
235
|
+
*/
|
|
236
|
+
ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE: "ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE",
|
|
237
|
+
/**
|
|
238
|
+
* Escape sequences are matched greedily and leftmost, so the escape character that **closed** an
|
|
239
|
+
* unrecognized sequence could not also **open** the next one. Where it could have, and where the
|
|
240
|
+
* body it would have held is the delimiter that was split on, the same bytes carry two alignments
|
|
241
|
+
* that disagree by one boundary: under the reading taken that delimiter ends a field, repeat or
|
|
242
|
+
* component, and under the other it sits inside an opaque atom and ends nothing. The leftmost
|
|
243
|
+
* reading is kept, every byte is preserved, and nothing is re-split.
|
|
244
|
+
*
|
|
245
|
+
* **This is the mirror of {@link WARNING_CODES.ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE}, and
|
|
246
|
+
* the direction is the reason it needs its own code.** That one reports a boundary the reading
|
|
247
|
+
* **lost**; this one reports a boundary the reading may have **gained**, which is the more
|
|
248
|
+
* dangerous direction, because a gained boundary hands back a value the sender's bytes do not
|
|
249
|
+
* unambiguously carry. Measured on the canonical set: `R|1|^^^687|28.6&Z&|&U/L||||F` reads
|
|
250
|
+
* `value` = `28.6&Z&` and `units` = `&U/L` under the leftmost alignment, and reads as a single
|
|
251
|
+
* unsplit field carrying both under the other.
|
|
252
|
+
*
|
|
253
|
+
* **Two exclusions, both deliberate, and the first is wider than its own argument.** Where the
|
|
254
|
+
* earlier sequence's body is a **recognized** mnemonic nothing is reported, because the reading
|
|
255
|
+
* taken interprets a construct (`&F&` is the sender escaping a field separator, which is what the
|
|
256
|
+
* mechanism is for) while the competing alignment's body is a delimiter character it usually
|
|
257
|
+
* cannot interpret at all, so this codec's own vocabulary prefers the reading taken. That is not
|
|
258
|
+
* the same as the reading taken being conformant, and where the declared set names a mnemonic
|
|
259
|
+
* letter as a splitting delimiter both alignments interpret one construct and neither is
|
|
260
|
+
* preferred, yet this stays silent. Both residues are measured and recorded rather than closed by
|
|
261
|
+
* widening the test. And where the escape
|
|
262
|
+
* character after the delimiter does not itself close a sequence there is no competing alignment
|
|
263
|
+
* at all, so an ordinary escaped value followed by an ordinary boundary is silent.
|
|
264
|
+
*
|
|
265
|
+
* **It is a report, not a repair, and not a round-trip guard.** The reading is unchanged: picking
|
|
266
|
+
* the other alignment would be a different guess with no more evidence behind it. Emit then
|
|
267
|
+
* rewrites the preserved sequences into recognized mnemonics, and those bytes carry the reading
|
|
268
|
+
* that was taken unambiguously, so a second-generation read is silent and is correct about its own
|
|
269
|
+
* bytes. The first read of the wire bytes is the only place the ambiguity exists to be caught.
|
|
270
|
+
*/
|
|
271
|
+
ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT: "ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT",
|
|
272
|
+
/**
|
|
273
|
+
* Two escape alignments of the same bytes disagreed about a **field** boundary, the reading taken
|
|
274
|
+
* kept it, and the escape character that reading resumes on **heads no sequence at all**, so the
|
|
275
|
+
* boundary was bought with a byte this reading cannot read while the competing alignment is
|
|
276
|
+
* exactly the reading that can. Every field after that point sits one place further right than the
|
|
277
|
+
* competing alignment puts it.
|
|
278
|
+
*
|
|
279
|
+
* **The shift is the harm, and on a result record it reaches the status slot.** Measured on the
|
|
280
|
+
* canonical set, `R|1|^^^687|28.6&F&|&U/L||||F` reads **9** fields under the reading taken and
|
|
281
|
+
* **8** under the competing one, so the sender's trailing `F` lands in field 9 (the result status)
|
|
282
|
+
* under the first and in no field at all under the second. The parse hands back units `&U/L` and a
|
|
283
|
+
* status of **`final`**, and both are consequences of the alignment rather than values the sender
|
|
284
|
+
* placed in those slots. A downstream system reading `final` would act on a result the bytes do
|
|
285
|
+
* not say was finalised. Before this code the only warning on that stream was the **tolerable**
|
|
286
|
+
* {@link WARNING_CODES.ASTM_UNPAIRED_ESCAPE_CHARACTER}, so the widest gate-legal profile plus
|
|
287
|
+
* `{ strict: true }` accepted it.
|
|
288
|
+
*
|
|
289
|
+
* **It is a report, not a repair.** The split is unchanged, every decoded byte is identical, and
|
|
290
|
+
* the units and status read are the ones that were always read. Picking the other alignment would
|
|
291
|
+
* be a different guess with no more evidence behind it, and it would change values on a published
|
|
292
|
+
* package. What is new is that the shift is reported by a code no profile may tolerate.
|
|
293
|
+
*
|
|
294
|
+
* **It fires alongside {@link WARNING_CODES.ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT}, not instead
|
|
295
|
+
* of it, and neither test is a widening of the other.** That code asks whether this codec's
|
|
296
|
+
* vocabulary prefers the reading taken *at* the contested position, and is silent where the
|
|
297
|
+
* earlier body is a recognized mnemonic. This one asks what the reading taken makes of the bytes
|
|
298
|
+
* *after* the boundary, and does not consult the earlier body at all.
|
|
299
|
+
*
|
|
300
|
+
* **Two deliberate bounds, both stated rather than left to be found.**
|
|
301
|
+
* - **Only the field role, and that bound is a CHOICE rather than a consequence.** A gained repeat
|
|
302
|
+
* or component boundary divides one field and reaches nothing outside it, so it moves no
|
|
303
|
+
* **field-indexed** slot: the units and the status stay where they were. **It does not follow
|
|
304
|
+
* that it moves no modeled slot at all, and writing that down would be false.** Components are
|
|
305
|
+
* modeled *inside* a field: a Universal Test ID's four components are the LOINC-candidate slot,
|
|
306
|
+
* the test name, the **coding scheme** and the **local code**, and a patient name's three are
|
|
307
|
+
* last, first and middle. A gained component boundary shifts those, so a local code can be read
|
|
308
|
+
* as a coding scheme and a given name as a middle name. Measured, and **where the earlier body is
|
|
309
|
+
* a recognized mnemonic, reported by nothing** (only the tolerable
|
|
310
|
+
* {@link WARNING_CODES.ASTM_UNPAIRED_ESCAPE_CHARACTER} fires, so a gate-legal profile accepts it).
|
|
311
|
+
* An **unrecognized** earlier body raises
|
|
312
|
+
* {@link WARNING_CODES.ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT} there and is refused, which is the
|
|
313
|
+
* same split this code's own exclusion takes. It is a separate, open condition rather than something this
|
|
314
|
+
* code covers, because wiring this sink to another split is a different criterion needing its own
|
|
315
|
+
* population measurement. The repeat role costs the **value**, which this code does not report
|
|
316
|
+
* either.
|
|
317
|
+
* - **The tail is weighed one construct deep.** Where the escape character the reading taken
|
|
318
|
+
* resumes on heads a sequence this codec *recognizes*, the reading taken interprets it and the
|
|
319
|
+
* competing alignment would leave it bare, so the bytes prefer the reading taken: under a set
|
|
320
|
+
* naming the field separator `F`, `28.6&F&F&F&U/L` is that separator escaped, written, and
|
|
321
|
+
* escaped again, and refusing it would be an over-refusal of a well-formed stream. Where it
|
|
322
|
+
* heads a sequence whose body is *unrecognized*, the reading taken still consumes it while the
|
|
323
|
+
* competing alignment would leave **two** escape characters bare, so the preference is stronger
|
|
324
|
+
* again, and this stays silent there even though the field shift is real. That last case is the
|
|
325
|
+
* named residue: measured, not overlooked.
|
|
326
|
+
*
|
|
327
|
+
* **Catch it on the first read.** Emit rewrites the preserved sequences into recognized mnemonics,
|
|
328
|
+
* and those bytes carry the reading that was taken unambiguously, so a second-generation read is
|
|
329
|
+
* silent and is correct about its own bytes. A clean re-read is not evidence.
|
|
330
|
+
*/
|
|
331
|
+
ASTM_RECORD_ALIGNMENT_SHIFTED_FIELDS: "ASTM_RECORD_ALIGNMENT_SHIFTED_FIELDS",
|
|
332
|
+
/**
|
|
333
|
+
* Two escape alignments of the same bytes disagreed about a **repeat** boundary, the reading
|
|
334
|
+
* taken kept it, and the escape character that reading resumes on **heads no sequence at all**.
|
|
335
|
+
* Same contested position and same tail test as
|
|
336
|
+
* {@link WARNING_CODES.ASTM_RECORD_ALIGNMENT_SHIFTED_FIELDS}, on a different delimiter role, and
|
|
337
|
+
* what it costs is a different thing, which is why it is a different code.
|
|
338
|
+
*
|
|
339
|
+
* **Nothing shifts, and that is not the same as nothing being lost.** No field-indexed slot
|
|
340
|
+
* moves: the units and the result status are read out of the same field numbers under either
|
|
341
|
+
* alignment. What this reports is that **the field is read as more repeats than the competing
|
|
342
|
+
* alignment gives it**, which is true wherever it fires. What that costs depends on **which**
|
|
343
|
+
* boundary was gained, and the two cases are stated separately rather than folded into one claim.
|
|
344
|
+
*
|
|
345
|
+
* **Where it is the FIRST boundary in the field, a modeled slot is lost**, because a field's
|
|
346
|
+
* modeled value and components are taken from its **first repeat alone**. Everything past the
|
|
347
|
+
* boundary stays on the wire and stays in `repeats`, and leaves every modeled slot:
|
|
348
|
+
*
|
|
349
|
+
* - **A value truncates.** Under `H|F^&`, `R|1|^^^687|28.6&S&F&U/L||||F` reads the value field as
|
|
350
|
+
* the two repeats `28.6^` and `&U/L`, so a consumer reads `28.6^` and the rest of the value is
|
|
351
|
+
* gone. The competing alignment reads one repeat carrying all of it.
|
|
352
|
+
* - **A modeled component list is deleted rather than shifted.** The same boundary inside a
|
|
353
|
+
* Universal Test ID leaves the components of the first repeat only: under `H|F^&`,
|
|
354
|
+
* `R|1|&F&F&687|28.6|U/L||||F` reads a UTID of one component holding a decoded field separator,
|
|
355
|
+
* with no coding scheme and no local code, where the bytes carry `687`. A patient name loses
|
|
356
|
+
* its given and middle names the same way. That is the half of this condition the shift report
|
|
357
|
+
* could not cover, because components are modeled **inside** a field.
|
|
358
|
+
*
|
|
359
|
+
* Before this code the only warnings on those streams were **tolerable** ones
|
|
360
|
+
* ({@link WARNING_CODES.ASTM_NONSTANDARD_DELIMITERS} and, where the tail applies,
|
|
361
|
+
* {@link WARNING_CODES.ASTM_UNPAIRED_ESCAPE_CHARACTER}), so the widest gate-legal profile plus
|
|
362
|
+
* `{ strict: true }` accepted a truncated value and an emptied Universal Test ID.
|
|
363
|
+
*
|
|
364
|
+
* **Where it is a LATER boundary, no modeled slot moves and this still fires.** The first repeat
|
|
365
|
+
* is identical under both alignments, so the value, the components and every slot taken from them
|
|
366
|
+
* read the same either way (`R|1|^^^687|5.0F28.6&S&F&U/L||||F` under `H|F^&` reads a value of
|
|
367
|
+
* `5.0` under both), and what differs is the repeat structure after the first. It fires there
|
|
368
|
+
* deliberately: the boundary is still one the bytes do not force and a consumer reading `repeats`
|
|
369
|
+
* is still reading an alignment guess. Relative to the modeled slots that is **over-reporting,
|
|
370
|
+
* never under-reporting**. Narrowing it to the first boundary would change which streams a
|
|
371
|
+
* published package refuses and wants its own measurement, so the bound is written down instead.
|
|
372
|
+
*
|
|
373
|
+
* **It is a report, not a repair.** The split is unchanged, every decoded byte is identical,
|
|
374
|
+
* `repeats` still carries every one of them, and the value read is the value that was always
|
|
375
|
+
* read. Picking the other alignment would be a different guess with no more evidence behind it,
|
|
376
|
+
* on a published package.
|
|
377
|
+
*
|
|
378
|
+
* **Two further deliberate bounds, both stated rather than left to be found.**
|
|
379
|
+
* - **Only the repeat role.** The **component** role reaches a modeled slot too, and differently:
|
|
380
|
+
* there the components stay in the record and move one slot along, so a local code reads as a
|
|
381
|
+
* coding scheme and a given name as a middle name. That is measured, reported by nothing where
|
|
382
|
+
* the earlier body is a recognized mnemonic, and open. It is not covered here, because wiring a
|
|
383
|
+
* sink to another split is another criterion wanting its own population measurement.
|
|
384
|
+
* - **The tail is weighed one construct deep**, exactly as for the shift report. Where the escape
|
|
385
|
+
* character the reading resumes on heads a sequence this codec *recognizes*, the bytes prefer
|
|
386
|
+
* the reading taken and the repeats are the ones the sender wrote: under a set naming the
|
|
387
|
+
* repeat separator `F`, `28.6&F&F&F&U/L` is that separator escaped, written, and escaped again,
|
|
388
|
+
* and refusing it would be an over-refusal of a well-formed stream. Where it heads a sequence
|
|
389
|
+
* whose body is *unrecognized*, the competing alignment would leave **two** escape characters
|
|
390
|
+
* bare, so the preference is stronger again, and this stays silent there even though the gained
|
|
391
|
+
* boundary is real. That last case is the named residue: measured, not overlooked.
|
|
392
|
+
*
|
|
393
|
+
* **Catch it on the first read.** Emit rewrites the preserved sequences into recognized
|
|
394
|
+
* mnemonics, and those bytes carry the reading that was taken unambiguously, so a
|
|
395
|
+
* second-generation read is silent and is correct about its own bytes. A clean re-read is not
|
|
396
|
+
* evidence.
|
|
397
|
+
*/
|
|
398
|
+
ASTM_RECORD_ALIGNMENT_TRUNCATED_FIELD: "ASTM_RECORD_ALIGNMENT_TRUNCATED_FIELD",
|
|
159
399
|
/** An escape sequence body was not one of `&F&`/`&S&`/`&R&`/`&E&`: preserved verbatim. */
|
|
160
400
|
ASTM_UNKNOWN_ESCAPE_SEQUENCE: "ASTM_UNKNOWN_ESCAPE_SEQUENCE",
|
|
161
401
|
/**
|
|
@@ -177,7 +417,8 @@ var WARNING_CODES = {
|
|
|
177
417
|
* *different* escape character in the same record may still head a real three-character sequence,
|
|
178
418
|
* and if that sequence's body happens to be a delimiter (`&|&` under the canonical set) the atom
|
|
179
419
|
* rule means that delimiter does not split. That case is reported separately, under
|
|
180
|
-
* {@link WARNING_CODES.
|
|
420
|
+
* {@link WARNING_CODES.ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE}, and it still costs a field
|
|
421
|
+
* boundary.
|
|
181
422
|
*/
|
|
182
423
|
ASTM_UNPAIRED_ESCAPE_CHARACTER: "ASTM_UNPAIRED_ESCAPE_CHARACTER",
|
|
183
424
|
/**
|
|
@@ -243,7 +484,8 @@ var WARNING_CODES = {
|
|
|
243
484
|
*/
|
|
244
485
|
ASTM_RECORD_DELIMITERS_REDECLARED: "ASTM_RECORD_DELIMITERS_REDECLARED",
|
|
245
486
|
/**
|
|
246
|
-
* A later `H` (header) record could not declare a usable delimiter set: it was
|
|
487
|
+
* A later `H` (header) record could not declare a usable delimiter set: it was not a header, it
|
|
488
|
+
* was too short, its delimiter definition held fewer than three characters, or the
|
|
247
489
|
* field separator it named also appeared among the other three, leaving the four roles
|
|
248
490
|
* indistinguishable. The delimiters **already in force are kept** and every record is still surfaced;
|
|
249
491
|
* a set is never guessed and no record is dropped.
|
|
@@ -285,6 +527,41 @@ function nonStandardDelimiters(position) {
|
|
|
285
527
|
position
|
|
286
528
|
};
|
|
287
529
|
}
|
|
530
|
+
function delimiterRoleCollision(position) {
|
|
531
|
+
return {
|
|
532
|
+
code: WARNING_CODES.ASTM_RECORD_DELIMITER_ROLE_COLLISION,
|
|
533
|
+
message: "Header declared one character in two delimiter roles, honored as declared; the boundary between those two roles cannot be recovered from the bytes, and emit refuses such a set.",
|
|
534
|
+
position
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function delimiterSwallowedByEscape(position) {
|
|
538
|
+
return {
|
|
539
|
+
code: WARNING_CODES.ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE,
|
|
540
|
+
message: "An unrecognized escape sequence held a delimiter in force, so that delimiter did not end a field, repeat or component. The sequence is preserved verbatim and nothing is re-split.",
|
|
541
|
+
position
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
function ambiguousEscapeAlignment(position) {
|
|
545
|
+
return {
|
|
546
|
+
code: WARNING_CODES.ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT,
|
|
547
|
+
message: "An unrecognized escape sequence ended where another one could have begun, so a delimiter that ended a field, repeat or component here sits inside a sequence under the other alignment. The leftmost alignment was kept, every byte is preserved, and nothing is re-split.",
|
|
548
|
+
position
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
function alignmentShiftedFields(position) {
|
|
552
|
+
return {
|
|
553
|
+
code: WARNING_CODES.ASTM_RECORD_ALIGNMENT_SHIFTED_FIELDS,
|
|
554
|
+
message: "A field boundary here is one of two escape alignments the bytes carry, and the reading that took it resumes on an escape character heading no sequence, which the other alignment uses to close one. Every later field is one place further right than the other reading puts it, so a result's units and status may be read out of slots the sender did not put them in. The reading was kept and every byte is preserved.",
|
|
555
|
+
position
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function alignmentTruncatedField(position) {
|
|
559
|
+
return {
|
|
560
|
+
code: WARNING_CODES.ASTM_RECORD_ALIGNMENT_TRUNCATED_FIELD,
|
|
561
|
+
message: "A repeat boundary here is one of two escape alignments the bytes carry, and the reading that took it resumes on an escape character heading no sequence, which the other alignment uses to close one. This field is read as more repeats than the other reading gives it, and its modeled value and components are taken from the first repeat alone, so where that boundary is the first one the rest of the field leaves every modeled slot. The reading was kept and every byte is preserved.",
|
|
562
|
+
position
|
|
563
|
+
};
|
|
564
|
+
}
|
|
288
565
|
function delimitersRedeclared(position) {
|
|
289
566
|
return {
|
|
290
567
|
code: WARNING_CODES.ASTM_RECORD_DELIMITERS_REDECLARED,
|
|
@@ -900,7 +1177,7 @@ var defaultProfile = defineAstmProfile({
|
|
|
900
1177
|
// src/profiles/reference-corpus.ts
|
|
901
1178
|
var referenceCorpus = defineAstmProfile({
|
|
902
1179
|
name: "referenceCorpus",
|
|
903
|
-
description: "Non-standard-escape tolerance grounded firsthand in the escape-agnostic OSS reference corpus (python-astm / senaite). Mostly syntactic encoding noise, with one measured exception: an escape sequence whose body is itself a delimiter is an opaque atom, so that delimiter does not split and a result can lose its units and its status. Read the values; do not rely on this profile leaving only cosmetic deviations behind.",
|
|
1180
|
+
description: "Non-standard-escape tolerance grounded firsthand in the escape-agnostic OSS reference corpus (python-astm / senaite). Mostly syntactic encoding noise, with one measured exception: an escape sequence whose body is an unrecognized character that is itself a delimiter in force is an opaque atom, so that delimiter does not split and a result can lose its units and its status. The mirror case is measured too: sequences are matched leftmost, so one can end where another could have begun and a delimiter splits that the other alignment would have held. Read the values; do not rely on this profile leaving only cosmetic deviations behind.",
|
|
904
1181
|
provenance: {
|
|
905
1182
|
source: "kxepal/python-astm codec.py (BSD) + senaite.astm / senaite.lis2a",
|
|
906
1183
|
reference: "https://github.com/kxepal/python-astm/blob/master/astm/codec.py ; https://github.com/senaite/senaite.astm",
|
|
@@ -910,7 +1187,7 @@ var referenceCorpus = defineAstmProfile({
|
|
|
910
1187
|
tolerate: [
|
|
911
1188
|
{
|
|
912
1189
|
code: "ASTM_UNKNOWN_ESCAPE_SEQUENCE",
|
|
913
|
-
rationale: "The OSS reference stack (python-astm codec.py, firsthand-verified) treats '&' as literal data and never decodes escape sequences, so streams from that ecosystem carry non-standard '&\u2026&' bodies our escape-aware tokenizer flags. The body is preserved byte-for-byte in the value. NOT always non-clinical, and this is measured rather than assumed: where the body is a delimiter, that delimiter never became a field boundary, so `28.6&|&U/L` reads as one value with no units and no final status.
|
|
1190
|
+
rationale: "The OSS reference stack (python-astm codec.py, firsthand-verified) treats '&' as literal data and never decodes escape sequences, so streams from that ecosystem carry non-standard '&\u2026&' bodies our escape-aware tokenizer flags. The body is preserved byte-for-byte in the value. NOT always non-clinical, and this is measured rather than assumed: where the body is a delimiter, that delimiter never became a field boundary, so `28.6&|&U/L` reads as one value with no units and no final status. That subset now also raises ASTM_RECORD_DELIMITER_SWALLOWED_BY_ESCAPE, which this profile cannot tolerate, so tolerating this code no longer hides it. The same holds for the mirror case, where a sequence ends where another could have begun and a delimiter splits that the other alignment would have held: that raises ASTM_RECORD_AMBIGUOUS_ESCAPE_ALIGNMENT, which this profile cannot tolerate either. Where that gained boundary is a field boundary and the reading taken resumes on an escape character heading no sequence, every later field shifts and a result's units and status move with it, which raises ASTM_RECORD_ALIGNMENT_SHIFTED_FIELDS, untolerable here as well. Where that same gained boundary is a repeat boundary, nothing shifts but the field is read out of its first repeat alone, so a value truncates and a test identity empties, which raises ASTM_RECORD_ALIGNMENT_TRUNCATED_FIELD, untolerable here too. Both of those carry the same tail bound and stay silent where the escape character past the boundary heads a sequence of its own, recognized or not, which is much of this corpus: tolerating this code does not quiet them, but their absence is not a statement that nothing was lost."
|
|
914
1191
|
}
|
|
915
1192
|
]
|
|
916
1193
|
});
|
|
@@ -938,7 +1215,7 @@ function getDefaultAstmProfile() {
|
|
|
938
1215
|
function isEscapeSequenceAt(text, i, escape) {
|
|
939
1216
|
return text.charAt(i) === escape && text.charAt(i + 2) === escape;
|
|
940
1217
|
}
|
|
941
|
-
function decodeEscapes(leaf, d, onUnknown, onUnpaired) {
|
|
1218
|
+
function decodeEscapes(leaf, d, onUnknown, onUnpaired, onSwallowedDelimiter) {
|
|
942
1219
|
const esc = d.escape;
|
|
943
1220
|
if (!leaf.includes(esc)) return leaf;
|
|
944
1221
|
let out = "";
|
|
@@ -961,6 +1238,7 @@ function decodeEscapes(leaf, d, onUnknown, onUnpaired) {
|
|
|
961
1238
|
if (replacement === void 0) {
|
|
962
1239
|
out += esc + body + esc;
|
|
963
1240
|
onUnknown?.();
|
|
1241
|
+
if (isSplittingDelimiter(body, d)) onSwallowedDelimiter?.();
|
|
964
1242
|
} else {
|
|
965
1243
|
out += replacement;
|
|
966
1244
|
}
|
|
@@ -968,21 +1246,22 @@ function decodeEscapes(leaf, d, onUnknown, onUnpaired) {
|
|
|
968
1246
|
}
|
|
969
1247
|
return out;
|
|
970
1248
|
}
|
|
1249
|
+
function isSplittingDelimiter(body, d) {
|
|
1250
|
+
return body === d.field || body === d.repeat || body === d.component;
|
|
1251
|
+
}
|
|
1252
|
+
var MNEMONIC_ROLES = {
|
|
1253
|
+
F: "field",
|
|
1254
|
+
S: "component",
|
|
1255
|
+
R: "repeat",
|
|
1256
|
+
E: "escape"
|
|
1257
|
+
};
|
|
1258
|
+
function isMnemonicBody(body) {
|
|
1259
|
+
return Object.hasOwn(MNEMONIC_ROLES, body);
|
|
1260
|
+
}
|
|
971
1261
|
function escapeBody(body, d) {
|
|
972
|
-
|
|
973
|
-
case "F":
|
|
974
|
-
return d.field;
|
|
975
|
-
case "S":
|
|
976
|
-
return d.component;
|
|
977
|
-
case "R":
|
|
978
|
-
return d.repeat;
|
|
979
|
-
case "E":
|
|
980
|
-
return d.escape;
|
|
981
|
-
default:
|
|
982
|
-
return void 0;
|
|
983
|
-
}
|
|
1262
|
+
return isMnemonicBody(body) ? d[MNEMONIC_ROLES[body]] : void 0;
|
|
984
1263
|
}
|
|
985
|
-
function splitEscapeAware(text, delimiter, escape) {
|
|
1264
|
+
function splitEscapeAware(text, delimiter, escape, onAmbiguousAlignment, onShiftedFields, onTruncatedField) {
|
|
986
1265
|
if (text.length === 0) return [""];
|
|
987
1266
|
const out = [];
|
|
988
1267
|
let current = "";
|
|
@@ -990,6 +1269,14 @@ function splitEscapeAware(text, delimiter, escape) {
|
|
|
990
1269
|
while (i < text.length) {
|
|
991
1270
|
const ch = text.charAt(i);
|
|
992
1271
|
if (ch === escape && isEscapeSequenceAt(text, i, escape)) {
|
|
1272
|
+
const contested = text.charAt(i + 3) === delimiter && text.charAt(i + 4) === escape;
|
|
1273
|
+
if (contested && !isMnemonicBody(text.charAt(i + 1))) {
|
|
1274
|
+
onAmbiguousAlignment?.(out.length);
|
|
1275
|
+
}
|
|
1276
|
+
if (contested && !isEscapeSequenceAt(text, i + 4, escape)) {
|
|
1277
|
+
onShiftedFields?.(out.length);
|
|
1278
|
+
onTruncatedField?.(out.length);
|
|
1279
|
+
}
|
|
993
1280
|
current += text.slice(i, i + 3);
|
|
994
1281
|
i += 3;
|
|
995
1282
|
continue;
|
|
@@ -1008,18 +1295,30 @@ function splitEscapeAware(text, delimiter, escape) {
|
|
|
1008
1295
|
}
|
|
1009
1296
|
|
|
1010
1297
|
// src/records/tokenize.ts
|
|
1011
|
-
function tokenizeRecord(record, d, onUnknownEscape, onUnpairedEscape) {
|
|
1012
|
-
const rawFields = splitEscapeAware(
|
|
1298
|
+
function tokenizeRecord(record, d, onUnknownEscape, onUnpairedEscape, onSwallowedDelimiter, onAmbiguousAlignment, onAlignmentShiftedFields, onAlignmentTruncatedField) {
|
|
1299
|
+
const rawFields = splitEscapeAware(
|
|
1300
|
+
record,
|
|
1301
|
+
d.field,
|
|
1302
|
+
d.escape,
|
|
1303
|
+
(fieldIndex) => onAmbiguousAlignment?.(fieldIndex),
|
|
1304
|
+
(fieldIndex) => onAlignmentShiftedFields?.(fieldIndex)
|
|
1305
|
+
);
|
|
1013
1306
|
return rawFields.map(
|
|
1014
1307
|
(raw, fieldIndex) => toField(
|
|
1015
1308
|
raw,
|
|
1016
1309
|
d,
|
|
1017
1310
|
() => onUnknownEscape?.(fieldIndex),
|
|
1018
|
-
() => onUnpairedEscape?.(fieldIndex)
|
|
1311
|
+
() => onUnpairedEscape?.(fieldIndex),
|
|
1312
|
+
() => onSwallowedDelimiter?.(fieldIndex),
|
|
1313
|
+
() => onAmbiguousAlignment?.(fieldIndex),
|
|
1314
|
+
// The repeat split runs INSIDE one field, so the index it hands back is a repeat index and is
|
|
1315
|
+
// discarded: what a caller needs is which field carries the contested boundary, and that is
|
|
1316
|
+
// the index this map is already iterating.
|
|
1317
|
+
() => onAlignmentTruncatedField?.(fieldIndex)
|
|
1019
1318
|
)
|
|
1020
1319
|
);
|
|
1021
1320
|
}
|
|
1022
|
-
function tokenizeHeader(record, d, onUnknownEscape, onUnpairedEscape) {
|
|
1321
|
+
function tokenizeHeader(record, d, onUnknownEscape, onUnpairedEscape, onSwallowedDelimiter, onAmbiguousAlignment, onAlignmentShiftedFields, onAlignmentTruncatedField) {
|
|
1023
1322
|
const defEnd = record.indexOf(d.field, 2);
|
|
1024
1323
|
const definition = defEnd === -1 ? record.slice(2) : record.slice(2, defEnd);
|
|
1025
1324
|
const head = [opaqueField(record.slice(0, Math.min(1, record.length))), opaqueField(definition)];
|
|
@@ -1028,18 +1327,35 @@ function tokenizeHeader(record, d, onUnknownEscape, onUnpairedEscape) {
|
|
|
1028
1327
|
record.slice(defEnd + 1),
|
|
1029
1328
|
d,
|
|
1030
1329
|
(i) => onUnknownEscape?.(i + 2),
|
|
1031
|
-
(i) => onUnpairedEscape?.(i + 2)
|
|
1330
|
+
(i) => onUnpairedEscape?.(i + 2),
|
|
1331
|
+
(i) => onSwallowedDelimiter?.(i + 2),
|
|
1332
|
+
(i) => onAmbiguousAlignment?.(i + 2),
|
|
1333
|
+
(i) => onAlignmentShiftedFields?.(i + 2),
|
|
1334
|
+
(i) => onAlignmentTruncatedField?.(i + 2)
|
|
1032
1335
|
);
|
|
1033
1336
|
return [...head, ...data];
|
|
1034
1337
|
}
|
|
1035
1338
|
function opaqueField(raw) {
|
|
1036
1339
|
return { raw, components: [raw], repeats: [[raw]] };
|
|
1037
1340
|
}
|
|
1038
|
-
function toField(raw, d, onUnknownEscape, onUnpairedEscape) {
|
|
1039
|
-
const rawRepeats = splitEscapeAware(
|
|
1341
|
+
function toField(raw, d, onUnknownEscape, onUnpairedEscape, onSwallowedDelimiter, onAmbiguousAlignment, onAlignmentTruncatedField) {
|
|
1342
|
+
const rawRepeats = splitEscapeAware(
|
|
1343
|
+
raw,
|
|
1344
|
+
d.repeat,
|
|
1345
|
+
d.escape,
|
|
1346
|
+
() => {
|
|
1347
|
+
onAmbiguousAlignment();
|
|
1348
|
+
},
|
|
1349
|
+
void 0,
|
|
1350
|
+
() => {
|
|
1351
|
+
onAlignmentTruncatedField();
|
|
1352
|
+
}
|
|
1353
|
+
);
|
|
1040
1354
|
const repeats = rawRepeats.map(
|
|
1041
|
-
(rep) => splitEscapeAware(rep, d.component, d.escape)
|
|
1042
|
-
(
|
|
1355
|
+
(rep) => splitEscapeAware(rep, d.component, d.escape, () => {
|
|
1356
|
+
onAmbiguousAlignment();
|
|
1357
|
+
}).map(
|
|
1358
|
+
(comp) => decodeEscapes(comp, d, onUnknownEscape, onUnpairedEscape, onSwallowedDelimiter)
|
|
1043
1359
|
)
|
|
1044
1360
|
);
|
|
1045
1361
|
const components = repeats[0] ?? [""];
|
|
@@ -1076,18 +1392,22 @@ function parseAstmRecords(raw, options = {}) {
|
|
|
1076
1392
|
leadType !== void 0 && leadType.length > 0 ? { recordIndex: 0, recordType: leadType } : { recordIndex: 0 }
|
|
1077
1393
|
);
|
|
1078
1394
|
}
|
|
1079
|
-
const
|
|
1080
|
-
if (
|
|
1395
|
+
const declaration = readDelimiterDeclaration(first);
|
|
1396
|
+
if (!declaration.ok) {
|
|
1081
1397
|
throw new AstmParseError(
|
|
1082
1398
|
FATAL_CODES.ASTM_RECORD_UNDECLARED_DELIMITERS,
|
|
1083
|
-
|
|
1399
|
+
UNDECLARED_DELIMITER_MESSAGES[declaration.fault],
|
|
1084
1400
|
{ recordIndex: 0, recordType: "H" }
|
|
1085
1401
|
);
|
|
1086
1402
|
}
|
|
1403
|
+
const delimiters = declaration.delimiters;
|
|
1087
1404
|
const warnings = [];
|
|
1088
1405
|
if (isNonStandard(delimiters)) {
|
|
1089
1406
|
warnings.push(nonStandardDelimiters({ recordIndex: 0, recordType: "H" }));
|
|
1090
1407
|
}
|
|
1408
|
+
if (hasCollidingRoles(delimiters)) {
|
|
1409
|
+
warnings.push(delimiterRoleCollision({ recordIndex: 0, recordType: "H" }));
|
|
1410
|
+
}
|
|
1091
1411
|
let active = delimiters;
|
|
1092
1412
|
const built = lines.map((line2, recordIndex) => {
|
|
1093
1413
|
if (recordIndex > 0 && line2.charAt(0) === "H") {
|
|
@@ -1119,6 +1439,12 @@ function parseAstmRecords(raw, options = {}) {
|
|
|
1119
1439
|
} : { header, records, delimiters, classification, warnings: finalWarnings };
|
|
1120
1440
|
return deepFreeze(message);
|
|
1121
1441
|
}
|
|
1442
|
+
var UNDECLARED_DELIMITER_MESSAGES = {
|
|
1443
|
+
"not-a-header": "Header record does not begin with an H type letter.",
|
|
1444
|
+
"record-too-short": "Header record is too short to declare the four delimiters.",
|
|
1445
|
+
"definition-truncated": "Header record declares fewer than three delimiter-definition characters before its next field separator, so the repeat, component and escape roles are not all named.",
|
|
1446
|
+
"field-separator-reused": "Header record names its field separator in one of the other three delimiter roles, so the four roles are not distinguishable."
|
|
1447
|
+
};
|
|
1122
1448
|
function resolveProfile(options) {
|
|
1123
1449
|
if (options.profile === null) return void 0;
|
|
1124
1450
|
if (options.profile !== void 0) return options.profile;
|
|
@@ -1134,6 +1460,7 @@ function adoptRedeclaredDelimiters(line2, active, recordIndex, warnings) {
|
|
|
1134
1460
|
if (sameDelimiters(declared, active)) return active;
|
|
1135
1461
|
warnings.push(delimitersRedeclared(position));
|
|
1136
1462
|
if (isNonStandard(declared)) warnings.push(nonStandardDelimiters(position));
|
|
1463
|
+
if (hasCollidingRoles(declared)) warnings.push(delimiterRoleCollision(position));
|
|
1137
1464
|
return declared;
|
|
1138
1465
|
}
|
|
1139
1466
|
function sameDelimiters(a, b) {
|
|
@@ -1159,7 +1486,45 @@ function buildRecord(line2, recordIndex, d, warnings) {
|
|
|
1159
1486
|
unpairedEscapeCharacter({ recordIndex, recordType: rawType, fieldIndex: fieldIndex + 1 })
|
|
1160
1487
|
);
|
|
1161
1488
|
};
|
|
1162
|
-
const
|
|
1489
|
+
const onSwallowedDelimiter = (fieldIndex) => {
|
|
1490
|
+
warnings.push(
|
|
1491
|
+
delimiterSwallowedByEscape({ recordIndex, recordType: rawType, fieldIndex: fieldIndex + 1 })
|
|
1492
|
+
);
|
|
1493
|
+
};
|
|
1494
|
+
const onAmbiguousAlignment = (fieldIndex) => {
|
|
1495
|
+
warnings.push(
|
|
1496
|
+
ambiguousEscapeAlignment({ recordIndex, recordType: rawType, fieldIndex: fieldIndex + 1 })
|
|
1497
|
+
);
|
|
1498
|
+
};
|
|
1499
|
+
const onAlignmentShiftedFields = (fieldIndex) => {
|
|
1500
|
+
warnings.push(
|
|
1501
|
+
alignmentShiftedFields({ recordIndex, recordType: rawType, fieldIndex: fieldIndex + 1 })
|
|
1502
|
+
);
|
|
1503
|
+
};
|
|
1504
|
+
const onAlignmentTruncatedField = (fieldIndex) => {
|
|
1505
|
+
warnings.push(
|
|
1506
|
+
alignmentTruncatedField({ recordIndex, recordType: rawType, fieldIndex: fieldIndex + 1 })
|
|
1507
|
+
);
|
|
1508
|
+
};
|
|
1509
|
+
const fields = rawType === "H" ? tokenizeHeader(
|
|
1510
|
+
line2,
|
|
1511
|
+
d,
|
|
1512
|
+
onUnknownEscape,
|
|
1513
|
+
onUnpairedEscape,
|
|
1514
|
+
onSwallowedDelimiter,
|
|
1515
|
+
onAmbiguousAlignment,
|
|
1516
|
+
onAlignmentShiftedFields,
|
|
1517
|
+
onAlignmentTruncatedField
|
|
1518
|
+
) : tokenizeRecord(
|
|
1519
|
+
line2,
|
|
1520
|
+
d,
|
|
1521
|
+
onUnknownEscape,
|
|
1522
|
+
onUnpairedEscape,
|
|
1523
|
+
onSwallowedDelimiter,
|
|
1524
|
+
onAmbiguousAlignment,
|
|
1525
|
+
onAlignmentShiftedFields,
|
|
1526
|
+
onAlignmentTruncatedField
|
|
1527
|
+
);
|
|
1163
1528
|
if (fields.length === 1 && line2.slice(1).trim().length > 0) {
|
|
1164
1529
|
warnings.push(fieldsUnseparated({ recordIndex, recordType: rawType }));
|
|
1165
1530
|
}
|
|
@@ -2371,7 +2736,7 @@ function concatBytes3(chunks) {
|
|
|
2371
2736
|
}
|
|
2372
2737
|
|
|
2373
2738
|
// src/index.ts
|
|
2374
|
-
var VERSION = "0.0.
|
|
2739
|
+
var VERSION = "0.0.18";
|
|
2375
2740
|
|
|
2376
2741
|
exports.ALL_ASTM_WARNING_CODES = ALL_ASTM_WARNING_CODES;
|
|
2377
2742
|
exports.AMBIGUOUS_CODES = AMBIGUOUS_CODES;
|
|
@@ -2395,6 +2760,9 @@ exports.SAFETY_CRITICAL_CODES = SAFETY_CRITICAL_CODES;
|
|
|
2395
2760
|
exports.TOLERABLE_CODES = TOLERABLE_CODES;
|
|
2396
2761
|
exports.VERSION = VERSION;
|
|
2397
2762
|
exports.WARNING_CODES = WARNING_CODES;
|
|
2763
|
+
exports.alignmentShiftedFields = alignmentShiftedFields;
|
|
2764
|
+
exports.alignmentTruncatedField = alignmentTruncatedField;
|
|
2765
|
+
exports.ambiguousEscapeAlignment = ambiguousEscapeAlignment;
|
|
2398
2766
|
exports.ambiguousMessageKind = ambiguousMessageKind;
|
|
2399
2767
|
exports.ambiguousValueSplit = ambiguousValueSplit;
|
|
2400
2768
|
exports.applyAstmProfile = applyAstmProfile;
|
|
@@ -2414,6 +2782,8 @@ exports.decodeEscapes = decodeEscapes;
|
|
|
2414
2782
|
exports.deepFreeze = deepFreeze;
|
|
2415
2783
|
exports.defineAstmProfile = defineAstmProfile;
|
|
2416
2784
|
exports.defineLivdCatalog = defineLivdCatalog;
|
|
2785
|
+
exports.delimiterRoleCollision = delimiterRoleCollision;
|
|
2786
|
+
exports.delimiterSwallowedByEscape = delimiterSwallowedByEscape;
|
|
2417
2787
|
exports.delimitersRedeclared = delimitersRedeclared;
|
|
2418
2788
|
exports.detectFraming = detectFraming;
|
|
2419
2789
|
exports.encodeComponent = encodeComponent;
|
|
@@ -2425,6 +2795,7 @@ exports.frameSequenceGap = frameSequenceGap;
|
|
|
2425
2795
|
exports.frameUnterminated = frameUnterminated;
|
|
2426
2796
|
exports.getAstmProfile = getAstmProfile;
|
|
2427
2797
|
exports.getDefaultAstmProfile = getDefaultAstmProfile;
|
|
2798
|
+
exports.hasCollidingRoles = hasCollidingRoles;
|
|
2428
2799
|
exports.interpretAbnormalFlag = interpretAbnormalFlag;
|
|
2429
2800
|
exports.interpretResultStatus = interpretResultStatus;
|
|
2430
2801
|
exports.isNonStandard = isNonStandard;
|
|
@@ -2452,6 +2823,7 @@ exports.patient = patient;
|
|
|
2452
2823
|
exports.primaryCode = primaryCode;
|
|
2453
2824
|
exports.profileQuirkApplied = profileQuirkApplied;
|
|
2454
2825
|
exports.query = query;
|
|
2826
|
+
exports.readDelimiterDeclaration = readDelimiterDeclaration;
|
|
2455
2827
|
exports.readDelimiters = readDelimiters;
|
|
2456
2828
|
exports.recognizeUniversalTestId = recognizeUniversalTestId;
|
|
2457
2829
|
exports.resolveProfileTransport = resolveProfileTransport;
|