@k67/kaitai-struct-ts 0.8.0 → 0.10.0

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/dist/index.d.mts CHANGED
@@ -560,8 +560,26 @@ declare class KsyParser {
560
560
  * @param imports - Map of import names to their YAML content
561
561
  * @param options - Parsing options
562
562
  * @returns Parsed schema with resolved imports
563
+ * @throws {ParseError} If import resolution fails
564
+ * @example
565
+ * ```typescript
566
+ * const parser = new KsyParser()
567
+ * const imports = new Map([
568
+ * ['/common/riff', riffYamlContent]
569
+ * ])
570
+ * const schema = parser.parseWithImports(wavYaml, imports)
571
+ * ```
572
+ */
573
+ parseWithImports(mainYaml: string, imports: Map<string, string>, options?: ParseOptions$1): KsySchema;
574
+ /**
575
+ * Extract namespace from import path.
576
+ * Converts paths like '/common/riff' or 'common/riff' to 'riff'.
577
+ *
578
+ * @param importPath - Import path from meta.imports
579
+ * @returns Namespace identifier
580
+ * @private
563
581
  */
564
- parseWithImports(mainYaml: string, _imports: Map<string, string>, options?: ParseOptions$1): KsySchema;
582
+ private extractNamespace;
565
583
  }
566
584
  /**
567
585
  * Options for parsing .ksy files.
@@ -753,15 +771,21 @@ declare class TypeInterpreter {
753
771
  endian?: Endianness | object;
754
772
  encoding?: string;
755
773
  } | undefined);
774
+ /**
775
+ * Safely extract a KaitaiStream from an object that may expose `_io`.
776
+ * Avoids using `any` casts to satisfy linting.
777
+ */
778
+ private static getKaitaiIO;
756
779
  /**
757
780
  * Parse binary data according to the schema.
758
781
  *
759
782
  * @param stream - Binary stream to parse
760
783
  * @param parent - Parent object (for nested types)
761
784
  * @param typeArgs - Arguments for parametric types
785
+ * @param root - Root object of the parse tree (for nested types)
762
786
  * @returns Parsed object
763
787
  */
764
- parse(stream: KaitaiStream, parent?: unknown, typeArgs?: Array<string | number | boolean>): Record<string, unknown>;
788
+ parse(stream: KaitaiStream, parent?: unknown, typeArgs?: Array<string | number | boolean>, root?: unknown): Record<string, unknown>;
765
789
  /**
766
790
  * Set up lazy-evaluated instance getters.
767
791
  * Instances are computed on first access and cached.
@@ -829,6 +853,25 @@ declare class TypeInterpreter {
829
853
  * @private
830
854
  */
831
855
  private parseType;
856
+ /**
857
+ * Parse parameterized type syntax and extract type name and arguments.
858
+ * Supports: type_name(arg1, arg2, ...) or just type_name
859
+ *
860
+ * @param typeSpec - Type specification string
861
+ * @param context - Execution context for evaluating argument expressions
862
+ * @returns Object with typeName and evaluated args
863
+ * @private
864
+ */
865
+ private parseParameterizedType;
866
+ /**
867
+ * Parse and evaluate a single type argument.
868
+ *
869
+ * @param arg - Argument string
870
+ * @param context - Execution context
871
+ * @returns Evaluated argument value
872
+ * @private
873
+ */
874
+ private parseArgument;
832
875
  /**
833
876
  * Parse a switch type (type selection based on expression).
834
877
  *
@@ -871,7 +914,7 @@ declare class TypeInterpreter {
871
914
  private readFloat;
872
915
  /**
873
916
  * Apply processing transformation to data.
874
- * Supports basic transformations like zlib decompression.
917
+ * Delegates to the process utility module.
875
918
  *
876
919
  * @param data - Data to process
877
920
  * @param process - Processing specification
@@ -879,6 +922,15 @@ declare class TypeInterpreter {
879
922
  * @private
880
923
  */
881
924
  private applyProcessing;
925
+ /**
926
+ * Evaluate expression-based endianness (switch-on).
927
+ *
928
+ * @param endianExpr - Endianness expression with switch-on and cases
929
+ * @param context - Execution context
930
+ * @returns Resolved endianness ('le' or 'be')
931
+ * @private
932
+ */
933
+ private evaluateEndianExpression;
882
934
  /**
883
935
  * Evaluate a value that can be an expression or literal.
884
936
  *
@@ -909,7 +961,18 @@ declare class TypeInterpreter {
909
961
  */
910
962
  declare class KaitaiError extends Error {
911
963
  position?: number | undefined;
912
- constructor(message: string, position?: number | undefined);
964
+ context?: Uint8Array | undefined;
965
+ constructor(message: string, position?: number | undefined, context?: Uint8Array | undefined);
966
+ /**
967
+ * Format error message with position and context.
968
+ * @private
969
+ */
970
+ private static formatMessage;
971
+ /**
972
+ * Format hex dump context around error position.
973
+ * @private
974
+ */
975
+ private static formatHexContext;
913
976
  }
914
977
  /**
915
978
  * Error thrown when validation fails.
@@ -923,7 +986,7 @@ declare class KaitaiError extends Error {
923
986
  * ```
924
987
  */
925
988
  declare class ValidationError extends KaitaiError {
926
- constructor(message: string, position?: number);
989
+ constructor(message: string, position?: number, context?: Uint8Array);
927
990
  }
928
991
  /**
929
992
  * Error thrown when parsing fails.
@@ -937,7 +1000,7 @@ declare class ValidationError extends KaitaiError {
937
1000
  * ```
938
1001
  */
939
1002
  declare class ParseError extends KaitaiError {
940
- constructor(message: string, position?: number);
1003
+ constructor(message: string, position?: number, context?: Uint8Array);
941
1004
  }
942
1005
  /**
943
1006
  * Error thrown when end of stream is reached unexpectedly.
@@ -951,7 +1014,7 @@ declare class ParseError extends KaitaiError {
951
1014
  * ```
952
1015
  */
953
1016
  declare class EOFError extends KaitaiError {
954
- constructor(message?: string, position?: number);
1017
+ constructor(message?: string, position?: number, context?: Uint8Array);
955
1018
  }
956
1019
  /**
957
1020
  * Error thrown when a required feature is not yet implemented.
package/dist/index.d.ts CHANGED
@@ -560,8 +560,26 @@ declare class KsyParser {
560
560
  * @param imports - Map of import names to their YAML content
561
561
  * @param options - Parsing options
562
562
  * @returns Parsed schema with resolved imports
563
+ * @throws {ParseError} If import resolution fails
564
+ * @example
565
+ * ```typescript
566
+ * const parser = new KsyParser()
567
+ * const imports = new Map([
568
+ * ['/common/riff', riffYamlContent]
569
+ * ])
570
+ * const schema = parser.parseWithImports(wavYaml, imports)
571
+ * ```
572
+ */
573
+ parseWithImports(mainYaml: string, imports: Map<string, string>, options?: ParseOptions$1): KsySchema;
574
+ /**
575
+ * Extract namespace from import path.
576
+ * Converts paths like '/common/riff' or 'common/riff' to 'riff'.
577
+ *
578
+ * @param importPath - Import path from meta.imports
579
+ * @returns Namespace identifier
580
+ * @private
563
581
  */
564
- parseWithImports(mainYaml: string, _imports: Map<string, string>, options?: ParseOptions$1): KsySchema;
582
+ private extractNamespace;
565
583
  }
566
584
  /**
567
585
  * Options for parsing .ksy files.
@@ -753,15 +771,21 @@ declare class TypeInterpreter {
753
771
  endian?: Endianness | object;
754
772
  encoding?: string;
755
773
  } | undefined);
774
+ /**
775
+ * Safely extract a KaitaiStream from an object that may expose `_io`.
776
+ * Avoids using `any` casts to satisfy linting.
777
+ */
778
+ private static getKaitaiIO;
756
779
  /**
757
780
  * Parse binary data according to the schema.
758
781
  *
759
782
  * @param stream - Binary stream to parse
760
783
  * @param parent - Parent object (for nested types)
761
784
  * @param typeArgs - Arguments for parametric types
785
+ * @param root - Root object of the parse tree (for nested types)
762
786
  * @returns Parsed object
763
787
  */
764
- parse(stream: KaitaiStream, parent?: unknown, typeArgs?: Array<string | number | boolean>): Record<string, unknown>;
788
+ parse(stream: KaitaiStream, parent?: unknown, typeArgs?: Array<string | number | boolean>, root?: unknown): Record<string, unknown>;
765
789
  /**
766
790
  * Set up lazy-evaluated instance getters.
767
791
  * Instances are computed on first access and cached.
@@ -829,6 +853,25 @@ declare class TypeInterpreter {
829
853
  * @private
830
854
  */
831
855
  private parseType;
856
+ /**
857
+ * Parse parameterized type syntax and extract type name and arguments.
858
+ * Supports: type_name(arg1, arg2, ...) or just type_name
859
+ *
860
+ * @param typeSpec - Type specification string
861
+ * @param context - Execution context for evaluating argument expressions
862
+ * @returns Object with typeName and evaluated args
863
+ * @private
864
+ */
865
+ private parseParameterizedType;
866
+ /**
867
+ * Parse and evaluate a single type argument.
868
+ *
869
+ * @param arg - Argument string
870
+ * @param context - Execution context
871
+ * @returns Evaluated argument value
872
+ * @private
873
+ */
874
+ private parseArgument;
832
875
  /**
833
876
  * Parse a switch type (type selection based on expression).
834
877
  *
@@ -871,7 +914,7 @@ declare class TypeInterpreter {
871
914
  private readFloat;
872
915
  /**
873
916
  * Apply processing transformation to data.
874
- * Supports basic transformations like zlib decompression.
917
+ * Delegates to the process utility module.
875
918
  *
876
919
  * @param data - Data to process
877
920
  * @param process - Processing specification
@@ -879,6 +922,15 @@ declare class TypeInterpreter {
879
922
  * @private
880
923
  */
881
924
  private applyProcessing;
925
+ /**
926
+ * Evaluate expression-based endianness (switch-on).
927
+ *
928
+ * @param endianExpr - Endianness expression with switch-on and cases
929
+ * @param context - Execution context
930
+ * @returns Resolved endianness ('le' or 'be')
931
+ * @private
932
+ */
933
+ private evaluateEndianExpression;
882
934
  /**
883
935
  * Evaluate a value that can be an expression or literal.
884
936
  *
@@ -909,7 +961,18 @@ declare class TypeInterpreter {
909
961
  */
910
962
  declare class KaitaiError extends Error {
911
963
  position?: number | undefined;
912
- constructor(message: string, position?: number | undefined);
964
+ context?: Uint8Array | undefined;
965
+ constructor(message: string, position?: number | undefined, context?: Uint8Array | undefined);
966
+ /**
967
+ * Format error message with position and context.
968
+ * @private
969
+ */
970
+ private static formatMessage;
971
+ /**
972
+ * Format hex dump context around error position.
973
+ * @private
974
+ */
975
+ private static formatHexContext;
913
976
  }
914
977
  /**
915
978
  * Error thrown when validation fails.
@@ -923,7 +986,7 @@ declare class KaitaiError extends Error {
923
986
  * ```
924
987
  */
925
988
  declare class ValidationError extends KaitaiError {
926
- constructor(message: string, position?: number);
989
+ constructor(message: string, position?: number, context?: Uint8Array);
927
990
  }
928
991
  /**
929
992
  * Error thrown when parsing fails.
@@ -937,7 +1000,7 @@ declare class ValidationError extends KaitaiError {
937
1000
  * ```
938
1001
  */
939
1002
  declare class ParseError extends KaitaiError {
940
- constructor(message: string, position?: number);
1003
+ constructor(message: string, position?: number, context?: Uint8Array);
941
1004
  }
942
1005
  /**
943
1006
  * Error thrown when end of stream is reached unexpectedly.
@@ -951,7 +1014,7 @@ declare class ParseError extends KaitaiError {
951
1014
  * ```
952
1015
  */
953
1016
  declare class EOFError extends KaitaiError {
954
- constructor(message?: string, position?: number);
1017
+ constructor(message?: string, position?: number, context?: Uint8Array);
955
1018
  }
956
1019
  /**
957
1020
  * Error thrown when a required feature is not yet implemented.