@imferno/wasm 3.0.2-beta.1b73397 → 3.0.2-beta.2427eb9

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,61 @@
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 { ImfReport, Imferno, ValidateOptions, ValidationResult } from './types.js';
9
11
 
10
- /** Parse CPL XML content */
11
- export function parseCplTyped(xmlContent: string): Promise<any>;
12
+ export * from './types.js';
12
13
 
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" | "v2014" | "v2016" | "v2020" | "v2023" | "v2026" */
24
- app2eSpec?: "auto" | "none" | "v2014" | "v2016" | "v2020" | "v2023" | "v2026";
25
- /** ESLint-style rules configuration */
26
- rules?: Record<string, string>;
27
- }
14
+ /**
15
+ * Parse and validate an IMF package. This is the recommended entry point.
16
+ *
17
+ * Parse failures are reported as findings in `validation`, not thrown.
18
+ * @param files Object mapping filenames to XML string content
19
+ * @param options Optional validation options (spec selection, rules)
20
+ * @returns `{ package, validation }` — the full parsed package and all findings.
21
+ */
22
+ export function validate(
23
+ files: Record<string, string>,
24
+ options?: ValidateOptions | null,
25
+ ): Promise<ValidationResult>;
28
26
 
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
- }
27
+ /**
28
+ * Parse an IMF package without validating it.
29
+ * @param files Object mapping filenames to XML string content
30
+ * @returns The full parsed package. Rejects if the package cannot be parsed.
31
+ */
32
+ export function parsePackage(files: Record<string, string>): Promise<Imferno>;
46
33
 
47
34
  /**
48
- * Validate a full IMF package and return both validation report and parsed data.
35
+ * Legacy: validate and return the lossy `ImfReport` summary. Prefer `validate`.
49
36
  * @param files Object mapping filenames to XML string content
50
37
  * @param options Optional validation options (spec selection, rules)
51
- * @returns Validation report + parsed package data
38
+ * @returns Rejects if the package cannot be parsed.
52
39
  */
53
- export function validate(
40
+ export function buildReport(
54
41
  files: Record<string, string>,
55
- options?: ValidateOptions,
56
- ): Promise<ValidateResult>;
42
+ options?: ValidateOptions | null,
43
+ ): Promise<ImfReport>;
44
+
45
+ /**
46
+ * Pretty-print a validation result as a human-readable string.
47
+ * @param report The object `validate()` returned, or (legacy) `buildReport()`'s.
48
+ */
49
+ export function formatReport(report: ValidationResult | ImfReport): Promise<string>;
57
50
 
58
51
  /** Get the library version */
59
52
  export function getVersion(): Promise<string>;
60
53
 
61
- /** Manual WASM initialization (for advanced use) */
62
- export function init(wasmBuffer?: ArrayBuffer): Promise<void>;
54
+ /**
55
+ * Initialise the WASM module explicitly. Optional: every function initialises
56
+ * on first use. Pass the `.wasm` bytes to avoid fetching them.
57
+ */
58
+ export function init(wasmBytes?: ArrayBuffer | ArrayBufferView): Promise<void>;
63
59
 
64
60
  /** Typed validation code constants for use in rules config */
65
61
  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;
@@ -63,6 +63,13 @@ export async function getVersion() {
63
63
  // Typed validation codes
64
64
  export { codes } from './codes.js';
65
65
 
66
- // For users who want manual control
67
- export { wasmInit as init };
68
- export { wasm };
66
+ /**
67
+ * Initialise the WASM module explicitly (optional — every function does it on
68
+ * first use). Pass the `.wasm` bytes or a compiled module to skip fetching.
69
+ */
70
+ export function init(wasmBytes) {
71
+ if (!initPromise) {
72
+ initPromise = wasmInit(wasmBytes === undefined ? undefined : { module_or_path: wasmBytes });
73
+ }
74
+ return initPromise.then(() => undefined);
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imferno/wasm",
3
- "version": "3.0.2-beta.1b73397",
3
+ "version": "3.0.2-beta.2427eb9",
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
  }