@imferno/wasm 3.0.2-beta.5af77ef → 3.0.2-beta.67b6b7d

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.d.ts CHANGED
@@ -1,68 +1,86 @@
1
1
  /**
2
- * Auto-initializing IMF Parser TypeScript Definitions
2
+ * Auto-initializing imferno WASM bindings.
3
3
  *
4
- * All functions automatically handle WASM initialization.
4
+ * Every function initialises the WASM module on first use, so all of them
5
+ * return Promises. Value types (`ValidationResult`, `Imferno`, `ImfReport`,
6
+ * `ValidateOptions`, ...) live in ./types.d.ts, generated from the Rust types
7
+ * by `cargo xtask generate-types-ts` and shared verbatim with @imferno/node.
5
8
  */
6
9
 
7
- /** Parse ASSETMAP.xml content */
8
- export function parseAssetmapTyped(xmlContent: string): Promise<any>;
10
+ import type {
11
+ ImfReport,
12
+ Imferno,
13
+ RuleInfo,
14
+ ValidateOptions,
15
+ ValidationReport,
16
+ ValidationResult,
17
+ } from './types.js';
9
18
 
10
- /** Parse CPL XML content */
11
- export function parseCplTyped(xmlContent: string): Promise<any>;
19
+ export * from './types.js';
12
20
 
13
- /** Parse PKL XML content */
14
- export function parsePklTyped(xmlContent: string): Promise<any>;
15
-
16
- /** Parse VOLINDEX.xml content */
17
- export function parseVolindexTyped(xmlContent: string): Promise<any>;
18
-
19
- /** Options for the validate function */
20
- export interface ValidateOptions {
21
- /** Core constraints spec version: "auto" | "v2013" | "v2016" | "v2020" */
22
- coreSpec?: "auto" | "v2013" | "v2016" | "v2020";
23
- /** Application profile version: "auto" | "none" | "v2020" | "v2021" | "v2023" */
24
- app2eSpec?: "auto" | "none" | "v2020" | "v2021" | "v2023";
25
- /** ESLint-style rules configuration */
26
- rules?: Record<string, string>;
27
- }
21
+ /**
22
+ * Parse and validate an IMF package. This is the recommended entry point.
23
+ *
24
+ * Parse failures are reported as findings in `validation`, not thrown.
25
+ * @param files Object mapping filenames to XML string content
26
+ * @param options Optional validation options (spec selection, rules)
27
+ * @returns `{ package, validation }` — the full parsed package and all findings.
28
+ */
29
+ export function validate(
30
+ files: Record<string, string>,
31
+ options?: ValidateOptions | null,
32
+ ): Promise<ValidationResult>;
28
33
 
29
- /** Result returned by the validate function */
30
- export interface ValidateResult {
31
- /** Validation report with issues, compliance status, and profile */
32
- report: any;
33
- /** Parsed Composition Playlists */
34
- cpls: any[];
35
- /** Parsed AssetMap (null if parsing failed) */
36
- assetMap: any | null;
37
- /** Parsed Packing Lists */
38
- packingLists: any[];
39
- /** Parsed Volume Index (null if parsing failed) */
40
- volumeIndex: any | null;
41
- /** Assets in the AssetMap with no CPL or SCM reference */
42
- unreferencedAssets: { id: string; path: string }[];
43
- /** Sidecar assets declared in SCMs */
44
- declaredSidecars: { id: string; cplIds: string[] }[];
45
- }
34
+ /**
35
+ * Parse an IMF package without validating it.
36
+ * @param files Object mapping filenames to XML string content
37
+ * @returns The full parsed package. Rejects if the package cannot be parsed.
38
+ */
39
+ export function parsePackage(files: Record<string, string>): Promise<Imferno>;
46
40
 
47
41
  /**
48
- * Validate a full IMF package and return both validation report and parsed data.
42
+ * Legacy: validate and return the lossy `ImfReport` summary. Prefer `validate`.
49
43
  * @param files Object mapping filenames to XML string content
50
44
  * @param options Optional validation options (spec selection, rules)
51
- * @returns Validation report + parsed package data
45
+ * @returns Rejects if the package cannot be parsed.
52
46
  */
53
- export function validate(
47
+ export function buildReport(
54
48
  files: Record<string, string>,
55
- options?: ValidateOptions,
56
- ): Promise<ValidateResult>;
49
+ options?: ValidateOptions | null,
50
+ ): Promise<ImfReport>;
51
+
52
+ /**
53
+ * Pretty-print a validation result as a human-readable string.
54
+ * @param report The object `validate()` returned, or (legacy) `buildReport()`'s.
55
+ */
56
+ export function formatReport(report: ValidationResult | ImfReport): Promise<string>;
57
+
58
+ /** A SARIF 2.1.0 log (https://docs.oasis-open.org/sarif/sarif/v2.1.0/). */
59
+ export interface SarifLog {
60
+ $schema?: string;
61
+ version: "2.1.0";
62
+ runs: Array<Record<string, unknown>>;
63
+ }
64
+
65
+ /**
66
+ * Convert a validation result to a SARIF 2.1.0 log: rules by rule id
67
+ * (`ST2067-3/SegmentDuration`), each finding pointing at the applied
68
+ * edition's clause in that edition's taxonomy (`ST2067-3:2016`).
69
+ * @param report The object `validate()` returned, or its `validation`.
70
+ */
71
+ export function toSarif(report: ValidationResult | ValidationReport): Promise<SarifLog>;
72
+
73
+ /** The rule catalogue: one entry per rule, with its per-edition table. */
74
+ export function listRules(): Promise<RuleInfo[]>;
57
75
 
58
76
  /** Get the library version */
59
77
  export function getVersion(): Promise<string>;
60
78
 
61
- /** Manual WASM initialization (for advanced use) */
62
- export function init(wasmBuffer?: ArrayBuffer): Promise<void>;
79
+ /**
80
+ * Initialise the WASM module explicitly. Optional: every function initialises
81
+ * on first use. Pass the `.wasm` bytes to avoid fetching them.
82
+ */
83
+ export function init(wasmBytes?: ArrayBuffer | ArrayBufferView): Promise<void>;
63
84
 
64
- /** Typed validation code constants for use in rules config */
85
+ /** Rule ids (`SPEC/Name`) per spec, for use as rules-config keys */
65
86
  export { codes } from './codes.js';
66
-
67
- /** Raw WASM bindings (for advanced use) */
68
- export declare const wasm: typeof import('./imferno_wasm.js');
package/index.js CHANGED
@@ -18,7 +18,7 @@ function ensureInit() {
18
18
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
19
  const wasmPath = path.join(__dirname, 'imferno_wasm_bg.wasm');
20
20
  const wasmBuffer = readFileSync(wasmPath);
21
- initPromise = wasmInit(wasmBuffer);
21
+ initPromise = wasmInit({ module_or_path: wasmBuffer });
22
22
  } catch (error) {
23
23
  console.error('Failed to load WASM in Node.js:', error);
24
24
  throw error;
@@ -54,6 +54,18 @@ export async function validate(files, options) {
54
54
  return wasm.validate(files, options);
55
55
  }
56
56
 
57
+ // Validation findings as a SARIF 2.1.0 log
58
+ export async function toSarif(report) {
59
+ await ensureInit();
60
+ return wasm.toSarif(report);
61
+ }
62
+
63
+ // The rule catalogue (one entry per rule, with its per-edition table)
64
+ export async function listRules() {
65
+ await ensureInit();
66
+ return wasm.listRules();
67
+ }
68
+
57
69
  // Utility
58
70
  export async function getVersion() {
59
71
  await ensureInit();
@@ -63,6 +75,13 @@ export async function getVersion() {
63
75
  // Typed validation codes
64
76
  export { codes } from './codes.js';
65
77
 
66
- // For users who want manual control
67
- export { wasmInit as init };
68
- export { wasm };
78
+ /**
79
+ * Initialise the WASM module explicitly (optional — every function does it on
80
+ * first use). Pass the `.wasm` bytes or a compiled module to skip fetching.
81
+ */
82
+ export function init(wasmBytes) {
83
+ if (!initPromise) {
84
+ initPromise = wasmInit(wasmBytes === undefined ? undefined : { module_or_path: wasmBytes });
85
+ }
86
+ return initPromise.then(() => undefined);
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imferno/wasm",
3
- "version": "3.0.2-beta.5af77ef",
3
+ "version": "3.0.2-beta.67b6b7d",
4
4
  "description": "Fast, type-safe SMPTE ST 2067 IMF parser for JavaScript and TypeScript",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "codes.d.ts",
15
15
  "index.js",
16
16
  "index.d.ts",
17
+ "types.d.ts",
17
18
  "README.md",
18
19
  "LICENSE"
19
20
  ],
@@ -58,6 +59,8 @@
58
59
  },
59
60
  "devDependencies": {
60
61
  "ajv": "^8.18.0",
62
+ "ts-json-schema-generator": "2.9.0",
63
+ "typescript": "^5.9.3",
61
64
  "vitest": "^4.0.18"
62
65
  }
63
66
  }