edfcore 0.2.18 → 0.2.20

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 CHANGED
@@ -6,6 +6,28 @@ alone does not tell you whether you were affected.
6
6
  edfcore is pre-1.0. Patch releases have carried behaviour changes where the old behaviour was a
7
7
  defect; those are called out below.
8
8
 
9
+ ## 0.2.20
10
+
11
+ - **Fixed** `filterAnnotationsByTime` dropping an annotation whose duration was written as an
12
+ explicit `0`. A TAL spells an instant either by omitting the duration field or by writing `0`;
13
+ the two are the same instant, and the docs say edfcore does not distinguish them. The left-edge
14
+ clause keyed on `durationTicks === undefined` — a fact about the writer, not the event — so an
15
+ explicitly-zero marker fell out of the window starting at its own onset AND out of the window
16
+ before it, belonging to no window at all in an adjacent-window partition. It also disagreed with
17
+ `annotationsAt`, which had always treated the two spellings alike. The clause now tests the
18
+ event's actual duration; positive-duration events and the half-open rule are untouched.
19
+
20
+ ## 0.2.19
21
+
22
+ - **Fixed** `mergeChunks` merging across a real gap whenever the index had not been scanned — the
23
+ one thing the helper exists to refuse. Its gap check read `precededByGap`, which is `undefined`
24
+ in two different situations: no gap, and nobody looked. `openEdf` returns a probed index that has
25
+ looked for none, and `readRecords` reads by record number without consulting the timeline, so two
26
+ chunks five seconds apart arrived record-adjacent with that field empty on both and were joined
27
+ silently. The refusal now compares the chunks' own `startSeconds` in exact ticks — each chunk
28
+ decoded its onset from its own bytes, so the evidence was in hand the whole time and never needed
29
+ an index. The `precededByGap` branch stays, because its message names the indexed gap's duration.
30
+
9
31
  ## 0.2.18
10
32
 
11
33
  - **Fixed** `readTriggers` timing every event on the nominal grid — `sampleIndex * recordDuration /
@@ -1 +1 @@
1
- {"version":3,"file":"annotations-query.d.ts","sourceRoot":"","sources":["../src/annotations-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MA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ACpC,WAAW,EAAE,SAAS,aAAa,EAAE,GACpC,aAAa,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAQlE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,SAAS,aAAa,EAAE,EACrC,OAAO,EAAE,MAAM,GACd,SAAS,aAAa,EAAE,CAS1B"}
@@ -35,8 +35,17 @@ export function filterAnnotationsByTime(annotations, window) {
35
35
  return Object.freeze(annotations.filter((annotation) => {
36
36
  const onset = annotation.onsetTicksFromFirstRecord;
37
37
  const end = onset + (annotation.durationTicks ?? 0n);
38
- // Half-open on both sides: [onset, end) against [from, to).
39
- return (onset < to && (end > from || (annotation.durationTicks === undefined && onset >= from)));
38
+ // Half-open on both sides: [onset, end) against [from, to). An instantaneous event has an
39
+ // empty interval, so `end > from` can never hold for one and it needs the second clause.
40
+ //
41
+ // That clause tests `end === onset` — the event's actual duration — and NOT
42
+ // `durationTicks === undefined`, which is a fact about the WRITER rather than the event. A
43
+ // TAL may spell an instant either by omitting the duration field or by writing `0`, the two
44
+ // are the same instant, and `annotations.md` says edfcore does not distinguish them. Keying
45
+ // on the spelling dropped every explicitly-zero event from the window starting at its own
46
+ // onset — and from the previous window too, so in an adjacent-window partition it belonged
47
+ // to no window at all (fixed in 0.2.20).
48
+ return onset < to && (end > from || (end === onset && onset >= from));
40
49
  }));
41
50
  }
42
51
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"annotations-query.js","sourceRoot":"","sources":["../src/annotations-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,WAAqC,EACrC,MAA2B;IAE3B,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,YAAY,C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.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAiC,MAAM,YAAY,CAAC;AA+D1E;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAwEjE"}
1
+ {"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAiC,MAAM,YAAY,CAAC;AA4F1E;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAwEjE"}
package/dist/chunks.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * convention every option check in the package follows.
16
16
  */
17
17
  import { appendDiagnostics } from './diagnostics/collector.js';
18
+ import { secondsToTicks, ticksToSeconds } from './tal/ticks.js';
18
19
  /** Reads as one line at the call site, and keeps the `chunks[i]` non-null assertions out of it. */
19
20
  function at(chunks, index) {
20
21
  const chunk = chunks[index];
@@ -25,9 +26,19 @@ function at(chunks, index) {
25
26
  /**
26
27
  * Everything that makes two chunks joinable, checked before a byte is allocated.
27
28
  *
28
- * The record-adjacency test is the obvious one. The per-signal sample-index test is the one that
29
- * earns its place: `trimToWindow` narrows a chunk on each signal's own grid, so two chunks can
30
- * still be record-adjacent after a trim has removed the samples between them. Comparing
29
+ * Three tests, and the second and third are the ones that earn their place.
30
+ *
31
+ * `precededByGap` alone is not enough, because it is `undefined` in two different situations: no
32
+ * gap, and nobody looked. `openEdf` returns a probed index, `gapBefore` has nothing to report from
33
+ * one, and `readRecords` reads by record number without ever consulting the timeline — so two
34
+ * chunks a minute apart on an EDF+D file arrive record-adjacent with `precededByGap: undefined` on
35
+ * both, and the field the refusal was keyed on says nothing at all. Every chunk carries its own
36
+ * `startSeconds`, decoded from the annotation regions in its own bytes, so the evidence was in hand
37
+ * the whole time: the second test compares the clock instead of asking the index.
38
+ *
39
+ * The per-signal sample-index test is the third: `trimToWindow` narrows a chunk on each signal's
40
+ * own grid without changing the chunk's `durationSeconds`, so a trimmed chunk passes both the
41
+ * record and the clock test while the samples between the two are gone. Comparing
31
42
  * `firstSampleIndex` against the previous chunk's end catches exactly that, per signal, which is
32
43
  * the granularity at which it actually happens.
33
44
  */
@@ -43,6 +54,21 @@ function assertJoinable(previous, next, index) {
43
54
  throw new RangeError(`mergeChunks: chunk ${index} starts at record ${next.records.start}, but the chunk before ` +
44
55
  `it ends at ${expectedStart}. Chunks must be adjacent and in order.`);
45
56
  }
57
+ // In exact ticks, never in float seconds: both values were produced from ticks by
58
+ // `ticksToSeconds`, and rounding back recovers the tick they came from for any recording
59
+ // shorter than ~28.5 years — the same round trip `trimToWindow` relies on. A float comparison
60
+ // here would let a sub-tick discrepancy through, and an epsilon would let a real one through.
61
+ const previousEndTicks = secondsToTicks(previous.startSeconds) + secondsToTicks(previous.durationSeconds);
62
+ const nextStartTicks = secondsToTicks(next.startSeconds);
63
+ if (previousEndTicks !== nextStartTicks) {
64
+ const gapSeconds = ticksToSeconds(nextStartTicks - previousEndTicks);
65
+ throw new RangeError(`mergeChunks: chunk ${index} starts at ${next.startSeconds} s, but the chunk before it ends ` +
66
+ `at ${ticksToSeconds(previousEndTicks)} s — a discontinuity of ${gapSeconds} s. The two ` +
67
+ 'are record-adjacent, so this is a gap in TIME that the record numbers cannot show: ' +
68
+ 'either the index was never scanned, or these chunks came from separate reads. ' +
69
+ 'Concatenating them would date every sample after the join wrong by that much. Next: ' +
70
+ 'await buildRecordIndex(recording) and merge each contiguous run separately.');
71
+ }
46
72
  if (next.signals.length !== previous.signals.length) {
47
73
  throw new RangeError(`mergeChunks: chunk ${index} carries ${next.signals.length} signal(s), the chunk before it ` +
48
74
  `${previous.signals.length}. Every chunk must have been read with the same signal selection.`);
@@ -1 +1 @@
1
- {"version":3,"file":"chunks.js","sourceRoot":"","sources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 +109,5 @@ export declare const SIGNAL_FIELD_BLOCK_OFFSETS: {
109
109
  readonly reserved: 224;
110
110
  };
111
111
  /** Published package version. Kept in sync with package.json by a test. */
112
- export declare const VERSION = "0.2.18";
112
+ export declare const VERSION = "0.2.20";
113
113
  //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -79,5 +79,5 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
79
79
  reserved: 224,
80
80
  };
81
81
  /** Published package version. Kept in sync with package.json by a test. */
82
- export const VERSION = '0.2.18';
82
+ export const VERSION = '0.2.20';
83
83
  //# sourceMappingURL=constants.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edfcore",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "Modern, typed, zero-dependency reader for EDF, EDF+, BDF and BDF+ biosignal files. Works in browsers and Node with true random access.",
5
5
  "keywords": [
6
6
  "edf",
@@ -42,10 +42,17 @@ export function filterAnnotationsByTime(
42
42
  annotations.filter((annotation) => {
43
43
  const onset = annotation.onsetTicksFromFirstRecord;
44
44
  const end = onset + (annotation.durationTicks ?? 0n);
45
- // Half-open on both sides: [onset, end) against [from, to).
46
- return (
47
- onset < to && (end > from || (annotation.durationTicks === undefined && onset >= from))
48
- );
45
+ // Half-open on both sides: [onset, end) against [from, to). An instantaneous event has an
46
+ // empty interval, so `end > from` can never hold for one and it needs the second clause.
47
+ //
48
+ // That clause tests `end === onset` — the event's actual duration — and NOT
49
+ // `durationTicks === undefined`, which is a fact about the WRITER rather than the event. A
50
+ // TAL may spell an instant either by omitting the duration field or by writing `0`, the two
51
+ // are the same instant, and `annotations.md` says edfcore does not distinguish them. Keying
52
+ // on the spelling dropped every explicitly-zero event from the window starting at its own
53
+ // onset — and from the previous window too, so in an adjacent-window partition it belonged
54
+ // to no window at all (fixed in 0.2.20).
55
+ return onset < to && (end > from || (end === onset && onset >= from));
49
56
  }),
50
57
  );
51
58
  }
package/src/chunks.ts CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import { appendDiagnostics } from './diagnostics/collector.js';
19
+ import { secondsToTicks, ticksToSeconds } from './tal/ticks.js';
19
20
  import type { EdfChunk, EdfChunkSignal, EdfDiagnostic } from './types.js';
20
21
 
21
22
  /** Reads as one line at the call site, and keeps the `chunks[i]` non-null assertions out of it. */
@@ -28,9 +29,19 @@ function at(chunks: readonly EdfChunk[], index: number): EdfChunk {
28
29
  /**
29
30
  * Everything that makes two chunks joinable, checked before a byte is allocated.
30
31
  *
31
- * The record-adjacency test is the obvious one. The per-signal sample-index test is the one that
32
- * earns its place: `trimToWindow` narrows a chunk on each signal's own grid, so two chunks can
33
- * still be record-adjacent after a trim has removed the samples between them. Comparing
32
+ * Three tests, and the second and third are the ones that earn their place.
33
+ *
34
+ * `precededByGap` alone is not enough, because it is `undefined` in two different situations: no
35
+ * gap, and nobody looked. `openEdf` returns a probed index, `gapBefore` has nothing to report from
36
+ * one, and `readRecords` reads by record number without ever consulting the timeline — so two
37
+ * chunks a minute apart on an EDF+D file arrive record-adjacent with `precededByGap: undefined` on
38
+ * both, and the field the refusal was keyed on says nothing at all. Every chunk carries its own
39
+ * `startSeconds`, decoded from the annotation regions in its own bytes, so the evidence was in hand
40
+ * the whole time: the second test compares the clock instead of asking the index.
41
+ *
42
+ * The per-signal sample-index test is the third: `trimToWindow` narrows a chunk on each signal's
43
+ * own grid without changing the chunk's `durationSeconds`, so a trimmed chunk passes both the
44
+ * record and the clock test while the samples between the two are gone. Comparing
34
45
  * `firstSampleIndex` against the previous chunk's end catches exactly that, per signal, which is
35
46
  * the granularity at which it actually happens.
36
47
  */
@@ -52,6 +63,25 @@ function assertJoinable(previous: EdfChunk, next: EdfChunk, index: number): void
52
63
  );
53
64
  }
54
65
 
66
+ // In exact ticks, never in float seconds: both values were produced from ticks by
67
+ // `ticksToSeconds`, and rounding back recovers the tick they came from for any recording
68
+ // shorter than ~28.5 years — the same round trip `trimToWindow` relies on. A float comparison
69
+ // here would let a sub-tick discrepancy through, and an epsilon would let a real one through.
70
+ const previousEndTicks =
71
+ secondsToTicks(previous.startSeconds) + secondsToTicks(previous.durationSeconds);
72
+ const nextStartTicks = secondsToTicks(next.startSeconds);
73
+ if (previousEndTicks !== nextStartTicks) {
74
+ const gapSeconds = ticksToSeconds(nextStartTicks - previousEndTicks);
75
+ throw new RangeError(
76
+ `mergeChunks: chunk ${index} starts at ${next.startSeconds} s, but the chunk before it ends ` +
77
+ `at ${ticksToSeconds(previousEndTicks)} s — a discontinuity of ${gapSeconds} s. The two ` +
78
+ 'are record-adjacent, so this is a gap in TIME that the record numbers cannot show: ' +
79
+ 'either the index was never scanned, or these chunks came from separate reads. ' +
80
+ 'Concatenating them would date every sample after the join wrong by that much. Next: ' +
81
+ 'await buildRecordIndex(recording) and merge each contiguous run separately.',
82
+ );
83
+ }
84
+
55
85
  if (next.signals.length !== previous.signals.length) {
56
86
  throw new RangeError(
57
87
  `mergeChunks: chunk ${index} carries ${next.signals.length} signal(s), the chunk before it ` +
package/src/constants.ts CHANGED
@@ -93,4 +93,4 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
93
93
  } as const;
94
94
 
95
95
  /** Published package version. Kept in sync with package.json by a test. */
96
- export const VERSION = '0.2.18';
96
+ export const VERSION = '0.2.20';