@nirs4all/preflight 0.1.2 → 0.1.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/index.js CHANGED
@@ -21,6 +21,18 @@ function providerError(error) {
21
21
  return { kind: 'internal', reason: 'METHODS_CALLBACK_FAILED' };
22
22
  }
23
23
 
24
+ /** Inputs above the engine's spectral cell budget are refused before they
25
+ * are serialized, since their JSON can exceed the longest JavaScript string:
26
+ * the same code and meaning as the engine's own validation issue. */
27
+ function cellBudgetIssue(input) {
28
+ const max = input?.options?.max_cells ?? 10_000_000;
29
+ let cells = 0;
30
+ for (const source of input?.sources ?? []) cells += (source.x?.length ?? 0) * (source.x?.[0]?.length ?? 0);
31
+ return cells > max
32
+ ? { code: 'CELL_BUDGET_EXCEEDED', path: 'sources', message: `${cells} spectral cells exceed options.max_cells (${max})`, blocking: true }
33
+ : null;
34
+ }
35
+
24
36
  /** A failed nested selection travels as its DAG-ML message plus the first
25
37
  * error raised by the selection-metrics callback; the Rust engine maps both
26
38
  * exactly as the native provider (`dagml::nested_selection_failure`), so the
@@ -377,8 +389,15 @@ export async function createQualificationRuntime(options = {}) {
377
389
  }
378
390
  };
379
391
  return {
380
- analyze: input => JSON.parse(rust.analyze_json(JSON.stringify(seedAsDecimal(input)), callback)),
381
- validate: input => JSON.parse(rust.validate_json(JSON.stringify(seedAsDecimal(input)))),
392
+ analyze: input => {
393
+ const issue = cellBudgetIssue(input);
394
+ if (issue) throw Object.assign(new Error(issue.message), { code: issue.code });
395
+ return JSON.parse(rust.analyze_json(JSON.stringify(seedAsDecimal(input)), callback));
396
+ },
397
+ validate: input => {
398
+ const issue = cellBudgetIssue(input);
399
+ return issue ? { valid: false, issues: [issue] } : JSON.parse(rust.validate_json(JSON.stringify(seedAsDecimal(input))));
400
+ },
382
401
  // JSON-text entry points: the text reaches the Rust parser unchanged, so
383
402
  // nothing is rounded or decoded by JavaScript (u64 seeds, reserved Y).
384
403
  analyzeJson: text => rust.analyze_json(text, callback),
@@ -2,7 +2,7 @@
2
2
  "name": "nirs4all-preflight-wasm",
3
3
  "type": "module",
4
4
  "description": "WebAssembly binding for nirs4all qualification protocols",
5
- "version": "0.1.2",
5
+ "version": "0.1.4",
6
6
  "license": "CECILL-2.1 OR AGPL-3.0-or-later",
7
7
  "repository": {
8
8
  "type": "git",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nirs4all/preflight",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Rust NIRS dataset qualification with reusable Methods diagnostics",
5
5
  "type": "module",
6
6
  "license": "(CECILL-2.1 OR AGPL-3.0-or-later)",
@@ -27,7 +27,7 @@
27
27
  "THIRD_PARTY_NOTICES.md"
28
28
  ],
29
29
  "dependencies": {
30
- "@nirs4all/methods": "1.3.11",
30
+ "@nirs4all/methods": "1.3.12",
31
31
  "dag-ml-wasm": "0.3.43"
32
32
  },
33
33
  "scripts": {