@gaialabs/core 0.1.18 → 0.2.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
@@ -1,72 +1,4 @@
1
- import { ICompressionProvider, BinType, DbPath, StatusFlags, DbRoot, AddressType, DbStringType, StringWrapper, Op, OpCode, ChunkFile, AsmBlock, Address, CopDef, DbEntryPoint } from '@gaialabs/shared';
2
-
3
- /**
4
- * QuintetLZ compression algorithm implementation
5
- * Dictionary-based compression used in Quintet games
6
- */
7
- declare class QuintetLZ implements ICompressionProvider {
8
- static readonly DICTIONARY_SIZE = 256;
9
- static readonly DICTIONARY_INIT = 32;
10
- static readonly DICTIONARY_OFFSET = 239;
11
- private static readonly DEFAULT_PAGE_SIZE;
12
- /**
13
- * Expand (decompress) data using QuintetLZ algorithm
14
- * @param srcData Source data buffer
15
- * @param srcPosition Starting position in source data
16
- * @param srcLen Length of source data to process
17
- * @returns Expanded data
18
- */
19
- expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
20
- /**
21
- * Compact (compress) data using QuintetLZ algorithm
22
- * @param srcData Source data to compress
23
- * @returns Compressed data
24
- */
25
- compact(srcData: Uint8Array): Uint8Array;
26
- }
27
-
28
- /**
29
- * Register compression providers with the global registry
30
- */
31
- declare function registerCompressionProviders(): void;
32
-
33
- /**
34
- * Main project management class
35
- * Converted from GaiaLib/ProjectRoot.cs
36
- */
37
- interface ProjectConfig {
38
- name: string;
39
- romPath: string;
40
- baseDir: string;
41
- system?: string;
42
- database: string;
43
- flipsPath?: string;
44
- resources: Record<BinType, DbPath>;
45
- databasePath?: string;
46
- systemPath?: string;
47
- compression?: string;
48
- }
49
- /**
50
- * Project root management
51
- */
52
- declare class ProjectRoot {
53
- config: ProjectConfig;
54
- name: string;
55
- romPath: string;
56
- baseDir: string;
57
- system?: string;
58
- database: string;
59
- flipsPath?: string;
60
- resources: Record<BinType, DbPath>;
61
- databasePath?: string;
62
- systemPath?: string;
63
- compression?: string;
64
- constructor(config: ProjectConfig);
65
- /**
66
- * Load project from file or directory
67
- */
68
- static load(path?: string): Promise<ProjectRoot>;
69
- }
1
+ import { SupabaseClient } from '@supabase/supabase-js';
70
2
 
71
3
  /**
72
4
  * Lightweight ROM state placeholder used during early development.
@@ -124,51 +56,30 @@ declare class Stack {
124
56
  * Manages the 65816 processor registers and status flags
125
57
  */
126
58
  declare class Registers {
127
- accumulatorFlag?: boolean;
128
- indexFlag?: boolean;
129
- direct?: number;
130
- dataBank?: number;
131
- accumulator?: number;
132
- xIndex?: number;
133
- yIndex?: number;
59
+ value: Record<string, number>;
134
60
  stack: Stack;
135
61
  constructor();
136
- /**
137
- * Get the current status flags
138
- */
139
- get statusFlags(): StatusFlags;
140
- /**
141
- * Set the status flags
142
- */
143
- set statusFlags(value: StatusFlags);
144
- /**
145
- * Reset all registers to initial state
146
- */
147
- reset(): void;
148
62
  }
149
63
 
64
+ declare class MapExt<K, V> extends Map<K, V> {
65
+ constructor();
66
+ tryAdd(key: K, value: V): boolean;
67
+ setFlag(key: K, flag: number, value?: boolean): void;
68
+ clearFlag(key: K, flag: number): void;
69
+ }
150
70
  /**
151
71
  * Manages CPU processor state during ROM analysis
152
72
  * Converted from GaiaLib/Rom/Extraction/ProcessorStateManager.cs
153
73
  */
154
74
  declare class ProcessorStateManager {
155
- readonly accumulatorFlags: Map<number, boolean | null>;
156
- readonly indexFlags: Map<number, boolean | null>;
157
- readonly bankNotes: Map<number, number | null>;
158
- readonly stackPositions: Map<number, number>;
75
+ readonly stackPositions: MapExt<number, number>;
76
+ private readonly _buckets;
77
+ get(key: string): MapExt<number, number>;
159
78
  /**
160
79
  * Hydrate processor registers with stored state
161
80
  * Uses Registers from gaia-core/assembly for processor state management
162
81
  */
163
82
  hydrateRegisters(position: number, reg: Registers): void;
164
- getAccumulatorFlag(location: number): boolean | null | undefined;
165
- setAccumulatorFlag(location: number, value: boolean | null): void;
166
- tryAddAccumulatorFlag(location: number, value: boolean | null): boolean;
167
- getIndexFlag(location: number): boolean | null | undefined;
168
- setIndexFlag(location: number, value: boolean | null): void;
169
- tryAddIndexFlag(location: number, value: boolean | null): boolean;
170
- getBankNote(location: number): number | null | undefined;
171
- setBankNote(location: number, value: number | null): void;
172
83
  getStackPosition(location: number): number | undefined;
173
84
  setStackPosition(location: number, value: number): void;
174
85
  tryAddStackPosition(location: number, value: number): boolean;
@@ -193,6 +104,854 @@ declare class RomDataReader {
193
104
  peekAddress(): number;
194
105
  }
195
106
 
107
+ /**
108
+ * Address type classifications
109
+ * Converted from GaiaLib/Enum/AddressType.cs
110
+ */
111
+ declare enum AddressType {
112
+ Unknown = "Unknown",
113
+ Bank = "Bank",
114
+ Offset = "Offset",
115
+ Address = "Address",
116
+ WBank = "WBank",
117
+ Relative = "Relative"
118
+ }
119
+ /**
120
+ * Address space types
121
+ * Converted from GaiaLib/Types/Address.cs
122
+ */
123
+ declare enum AddressSpace {
124
+ None = "None",
125
+ ROM = "ROM",
126
+ WRAM = "WRAM",
127
+ SRAM = "SRAM",
128
+ System = "System"
129
+ }
130
+ /**
131
+ * SNES address structure
132
+ * Converted from GaiaLib/Types/Address.cs
133
+ */
134
+ declare class Address {
135
+ offset: number;
136
+ bank: number;
137
+ static readonly UPPER_BANK = 32768;
138
+ static readonly DATA_BANK_FLAG = 64;
139
+ static readonly FAST_BANK_FLAG = 128;
140
+ constructor(bank: number, offset: number);
141
+ get isROM(): boolean;
142
+ get isCodeBank(): boolean;
143
+ get space(): AddressSpace;
144
+ toInt(): number;
145
+ toString(): string;
146
+ static fromInt(addr: number): Address;
147
+ static typeFromCode(code: string): AddressType;
148
+ static codeFromType(type: AddressType): string | null;
149
+ }
150
+
151
+ /**
152
+ * Member type definitions for data structures
153
+ * Converted from GaiaLib/Enum/MemberType.cs
154
+ */
155
+ declare enum MemberType {
156
+ Byte = "Byte",
157
+ Word = "Word",
158
+ Offset = "Offset",
159
+ Address = "Address",
160
+ Binary = "Binary",
161
+ Code = "Code"
162
+ }
163
+
164
+ /**
165
+ * Processor register type definitions
166
+ * Converted from GaiaLib/Enum/RegisterType.cs
167
+ */
168
+ declare enum RegisterType {
169
+ M = "M",
170
+ X = "X",
171
+ B = "B"
172
+ }
173
+ /**
174
+ * Status flags for 65816 processor
175
+ * Converted from GaiaLib/Enum/StatusFlags.cs
176
+ *
177
+ * Bit pattern: [ n v m x d i z c ]
178
+ * n = Negative
179
+ * v = Overflow
180
+ * m = Accumulator Mode
181
+ * x = Index Mode
182
+ * d = Decimal Mode
183
+ * i = IRQ Disable
184
+ * z = Zero
185
+ * c = Carry
186
+ */
187
+ declare enum StatusFlags {
188
+ /**
189
+ * Clear before starting addition or subtraction.
190
+ * Arithmetic overflow:
191
+ * [addition - carry out of high bit:]
192
+ * 0 = no carry
193
+ * 1 = carry
194
+ * [subtraction - borrow required to subtract:]
195
+ * 0 = borrow required
196
+ * 1 = no borrow required
197
+ * [Logic:]
198
+ * receives bit shifted or rotated out;
199
+ * source of bit rotated in
200
+ */
201
+ Carry = 1,
202
+ /**
203
+ * Indicates zero or non-zero result:
204
+ * 0 = non-zero result
205
+ * 1 = zero result
206
+ */
207
+ Zero = 2,
208
+ /**
209
+ * Enables or disables processor's IRQ interrupt line:
210
+ * Set to disable interrupts by masking the IRQ line
211
+ * Clear to enable IRQ interrupts
212
+ */
213
+ IrqDisable = 4,
214
+ /**
215
+ * Determines mode for add/subtract (not increment/decrement, though):
216
+ * Set to force decimal operation (BCD)
217
+ * Clear to return to binary operation
218
+ */
219
+ DecimalMode = 8,
220
+ IndexMode = 16,
221
+ AccumulatorMode = 32,
222
+ /**
223
+ * Clear to reverse "set-overflow" hardware input.
224
+ * Indicates invalid carry into high bit of arithmetic
225
+ * result (two's-complement overflow):
226
+ * 0 = two's-complement result ok
227
+ * 1 = error if two's-complement arithmetic
228
+ */
229
+ Overflow = 64,
230
+ /**
231
+ * Reflects most significant bit of result
232
+ * (the sign of a two's-complement binary number):
233
+ * 0 = high bit clear (positive result)
234
+ * 1 = high bit set (negative result)
235
+ */
236
+ Negative = 128
237
+ }
238
+
239
+ /**
240
+ * Binary resource type definitions
241
+ * Converted from GaiaLib/Enum/BinType.cs
242
+ */
243
+ declare enum BinType {
244
+ Bitmap = "Bitmap",
245
+ Tilemap = "Tilemap",
246
+ Tileset = "Tileset",
247
+ Palette = "Palette",
248
+ Sound = "Sound",
249
+ Music = "Music",
250
+ Unknown = "Unknown",
251
+ Meta17 = "Meta17",
252
+ Spritemap = "Spritemap",
253
+ Assembly = "Assembly",
254
+ Patch = "Patch",
255
+ Transform = "Transform"
256
+ }
257
+
258
+ /**
259
+ * Transform type definitions
260
+ * Converted from GaiaLib/Enum/XformType.cs
261
+ */
262
+ declare enum XformType {
263
+ Lookup = "Lookup",
264
+ Replace = "Replace"
265
+ }
266
+ /**
267
+ * Transform definition
268
+ * Converted from GaiaLib/Types/XformDef.cs
269
+ */
270
+ interface XformDef {
271
+ type: XformType;
272
+ key?: string;
273
+ value?: string;
274
+ keyIx?: number;
275
+ valueIx?: number;
276
+ }
277
+
278
+ declare class DbFile {
279
+ name: string;
280
+ type: string;
281
+ start: number;
282
+ end: number;
283
+ compressed?: boolean;
284
+ upper?: boolean;
285
+ group?: string;
286
+ scene?: string;
287
+ constructor(data: Partial<DbFile>);
288
+ }
289
+ declare class DbFileType {
290
+ name: string;
291
+ extension: string;
292
+ type: string;
293
+ isPatch: boolean;
294
+ isBlock: boolean;
295
+ header: number;
296
+ constructor(data: Partial<DbFileType>);
297
+ }
298
+
299
+ /**
300
+ * Database part definition
301
+ * Converted from GaiaLib/Database/DbPart.cs
302
+ */
303
+ declare class DbPart {
304
+ name: string;
305
+ start: number;
306
+ end: number;
307
+ type: string;
308
+ bank?: number;
309
+ order?: number;
310
+ constructor(data: Partial<DbPart>);
311
+ }
312
+
313
+ declare class DbTransform {
314
+ key: string;
315
+ value: string;
316
+ constructor(data: Partial<DbTransform>);
317
+ }
318
+
319
+ /**
320
+ * Database block definition
321
+ * Converted from GaiaLib/Database/DbBlock.cs
322
+ */
323
+ declare class DbBlock {
324
+ name: string;
325
+ movable: boolean;
326
+ group?: string;
327
+ scene?: string;
328
+ parts: DbPart[];
329
+ transforms?: DbTransform[];
330
+ postProcess?: string;
331
+ constructor(data: Partial<DbBlock>);
332
+ }
333
+
334
+ /**
335
+ * Interface for compression providers
336
+ */
337
+ interface ICompressionProvider {
338
+ /**
339
+ * Expand (decompress) data
340
+ * @param srcData Source data buffer
341
+ * @param srcPosition Starting position in source data
342
+ * @param srcLen Length of source data to process
343
+ * @returns Expanded data
344
+ */
345
+ expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
346
+ /**
347
+ * Compact (compress) data
348
+ * @param srcData Source data to compress
349
+ * @returns Compressed data
350
+ */
351
+ compact(srcData: Uint8Array): Uint8Array;
352
+ }
353
+
354
+ /**
355
+ * Chunk file for ROM processing
356
+ * Converted from GaiaLib/Types/ChunkFile.cs
357
+ */
358
+ declare class ChunkFile {
359
+ name: string;
360
+ size: number;
361
+ location: number;
362
+ type: DbFileType;
363
+ parts?: AsmBlock[];
364
+ includes?: Set<string>;
365
+ includeLookup?: Map<string, AsmBlock>;
366
+ bank?: number;
367
+ compressed?: boolean;
368
+ upper?: boolean;
369
+ rawData?: Uint8Array | null;
370
+ textData?: string;
371
+ transforms?: {
372
+ key: string;
373
+ value: string;
374
+ }[];
375
+ postProcess?: string;
376
+ mnemonics: Record<number, string>;
377
+ group?: string;
378
+ scene?: string;
379
+ constructor(name: string, size: number, location: number, type: DbFileType);
380
+ }
381
+ declare function createChunkFileFromDbFile(rom: Uint8Array, compression: ICompressionProvider, dbFile: DbFile, fileType: DbFileType): ChunkFile;
382
+ declare function createChunkFileFromDbBlock(block: DbBlock, fileType: DbFileType): ChunkFile;
383
+ /**
384
+ * Chunk file utilities
385
+ */
386
+ declare class ChunkFileUtils {
387
+ /**
388
+ * Rebase blocks to a new location
389
+ */
390
+ static rebase(chunkFile: ChunkFile, newLocation?: number): void;
391
+ /**
392
+ * Calculate the total size of all blocks
393
+ */
394
+ static calculateSize(chunkFile: ChunkFile): number;
395
+ /**
396
+ * Check if a location is outside this block and return the part (matches C# IsOutside)
397
+ * Returns [isOutside, part] where part is the part containing the location
398
+ */
399
+ static isOutsideWithPart(root: ChunkFile[], block: ChunkFile, location: number): [boolean, ChunkFile | null, AsmBlock | null];
400
+ /**
401
+ * Check if a location is inside this block and return the part (matches C# IsInside)
402
+ * Returns [isInside, part] where part is the part containing the location
403
+ */
404
+ static isInsideWithPart(block: ChunkFile, location: number): [boolean, AsmBlock | null];
405
+ /**
406
+ * Check if a location is outside this block (shorthand version)
407
+ */
408
+ static isOutside(block: ChunkFile, location: number): boolean;
409
+ /**
410
+ * Check if a location is inside this block (shorthand version)
411
+ */
412
+ static isInside(block: ChunkFile, location: number): boolean;
413
+ /**
414
+ * Get all included blocks
415
+ */
416
+ static getIncludes(chunkFile: ChunkFile): ChunkFile[];
417
+ }
418
+
419
+ /**
420
+ * COP instruction definition
421
+ * Converted from GaiaLib/Database/CopDef.cs
422
+ */
423
+ declare class CopDef {
424
+ id: number;
425
+ name: string;
426
+ size: number;
427
+ parts: string[];
428
+ halt: boolean;
429
+ constructor(data: Partial<CopDef>);
430
+ }
431
+
432
+ declare class OpCode {
433
+ code: number;
434
+ mnem: string;
435
+ mode: string;
436
+ constructor(code: number, mnem: string, mode: string);
437
+ }
438
+
439
+ /**
440
+ * Represents a single assembly operation/instruction
441
+ */
442
+ declare class Op extends OpCode {
443
+ location: number;
444
+ operands: unknown[];
445
+ size: number;
446
+ copDef?: CopDef;
447
+ constructor(code: OpCode, location?: number, operands?: unknown[], size?: number);
448
+ }
449
+ /**
450
+ * Represents a block of assembly code or data
451
+ */
452
+ declare class AsmBlock {
453
+ label?: string;
454
+ location: number;
455
+ size: number;
456
+ isString: boolean;
457
+ objList: any[];
458
+ structName?: string;
459
+ bank?: number;
460
+ includes?: Set<{
461
+ block: ChunkFile;
462
+ part: AsmBlock;
463
+ }>;
464
+ constructor(location?: number, size?: number, isString?: boolean, label?: string, structName?: string, bank?: number);
465
+ }
466
+ /**
467
+ * Database part utilities
468
+ */
469
+ declare class AsmBlockUtils {
470
+ /**
471
+ * Check if a location is inside this part
472
+ */
473
+ static isInside(part: AsmBlock, location: number): boolean;
474
+ /**
475
+ * Check if a location is outside this part
476
+ */
477
+ static isOutside(part: AsmBlock, location: number): boolean;
478
+ }
479
+
480
+ /**
481
+ * Bit stream for reading/writing binary data at bit level
482
+ * Converted from GaiaLib/Types/BitStream.cs
483
+ */
484
+ declare class BitStream {
485
+ private static readonly NIBBLE_MASK;
486
+ private static readonly NIBBLE_PERFECT_POSITION;
487
+ private data;
488
+ private position;
489
+ private bitFlag;
490
+ private writeSample;
491
+ constructor(data: Uint8Array, position?: number);
492
+ get dataArray(): Uint8Array;
493
+ get currentPosition(): number;
494
+ set currentPosition(value: number);
495
+ /**
496
+ * Read a byte from the stream
497
+ * @returns The byte read, or -1 if the end of the data has been reached
498
+ */
499
+ readByte(): number;
500
+ /**
501
+ * Read a ushort from the stream (ignores the current bit flag)
502
+ * @returns The short read, or -1 if the end of the data has been reached
503
+ */
504
+ readShort(): number;
505
+ /**
506
+ * Read a bit from the stream
507
+ * @returns True if the current bit at bitFlag is set, false otherwise
508
+ */
509
+ readBit(): boolean;
510
+ /**
511
+ * Read a nibble from the stream
512
+ * @returns The nibble read, or -1 if the end of the data has been reached
513
+ */
514
+ readNibble(): number;
515
+ /**
516
+ * Write a bit to the stream
517
+ * @param set True if the current bit should be set, false otherwise
518
+ */
519
+ writeBit(set: boolean): void;
520
+ /**
521
+ * Write a byte to the stream
522
+ * @param value The byte to write
523
+ */
524
+ writeByte(value: number): void;
525
+ /**
526
+ * Write a nibble to the stream
527
+ * @param value The nibble to write
528
+ */
529
+ writeNibble(value: number): void;
530
+ flush(): void;
531
+ }
532
+
533
+ /**
534
+ * Registry for compression providers
535
+ * Allows registration of compression implementations by string ID
536
+ */
537
+ declare class CompressionRegistry {
538
+ private static providers;
539
+ /**
540
+ * Register a compression provider
541
+ * @param id String identifier for the compression type
542
+ * @param factory Factory function that creates the compression provider
543
+ */
544
+ static register(id: string, factory: () => ICompressionProvider): void;
545
+ /**
546
+ * Get a compression provider by ID
547
+ * @param id String identifier for the compression type
548
+ * @returns Compression provider instance
549
+ */
550
+ static get(id: string): ICompressionProvider;
551
+ /**
552
+ * Check if a compression provider is registered
553
+ * @param id String identifier for the compression type
554
+ * @returns True if provider is registered
555
+ */
556
+ static has(id: string): boolean;
557
+ /**
558
+ * Get list of registered provider IDs
559
+ * @returns Array of registered provider IDs
560
+ */
561
+ static getRegisteredIds(): string[];
562
+ /**
563
+ * Clear all registered providers (mainly for testing)
564
+ */
565
+ static clear(): void;
566
+ }
567
+
568
+ /**
569
+ * ROM processing constants
570
+ * Converted from GaiaLib/Types/RomProcessingConstants.cs
571
+ */
572
+ declare class RomProcessingConstants {
573
+ static readonly PAGE_SIZE = 32768;
574
+ static readonly SNES_HEADER_SIZE = 80;
575
+ static readonly DICTIONARIES: string[];
576
+ static readonly DICT_COMMANDS: number[];
577
+ static readonly END_CHARS: number[];
578
+ static readonly WHITESPACE: string[];
579
+ static readonly OPERATORS: string[];
580
+ static readonly COMMA_SPACE: string[];
581
+ static readonly ADDRESS_SPACE: string[];
582
+ static readonly SYMBOL_SPACE: string[];
583
+ static readonly LABEL_SPACE: string[];
584
+ static readonly OBJECT_SPACE: string[];
585
+ static readonly COP_SPLIT_CHARS: string[];
586
+ static readonly WHITESPACE_REGEX: RegExp;
587
+ static readonly COMMA_SPACE_REGEX: RegExp;
588
+ static readonly SYMBOL_SPACE_REGEX: RegExp;
589
+ static readonly LABEL_SPACE_REGEX: RegExp;
590
+ static readonly OBJECT_SPACE_REGEX: RegExp;
591
+ static readonly ADDRESS_SPACE_REGEX: RegExp;
592
+ static readonly COP_SPLIT_REGEX: RegExp;
593
+ static readonly COMMA_SPACE_TRIM_REGEX: RegExp;
594
+ /**
595
+ * Gets the size of an object for processing purposes
596
+ * @param obj The object to get the size for
597
+ * @returns Size in bytes
598
+ * @throws Error when unable to determine size
599
+ */
600
+ static getSize(obj: unknown): number;
601
+ }
602
+ /**
603
+ * BlockReader specific constants
604
+ */
605
+ declare class BlockReaderConstants {
606
+ static readonly REF_SEARCH_MAX_RANGE = 416;
607
+ static readonly BANK_MASK_CHECK = 64;
608
+ static readonly BYTE_DELIMITER_THRESHOLD = 256;
609
+ static readonly BANK_HIGH_MEMORY_1 = 126;
610
+ static readonly BANK_HIGH_MEMORY_2 = 127;
611
+ static readonly POINTER_CHARACTERS: string[];
612
+ static readonly WIDE_STRING_TYPE = "WideString";
613
+ static readonly BINARY_TYPE = "Binary";
614
+ static readonly CODE_TYPE = "Code";
615
+ static readonly LOCATION_FORMAT = "loc_{0:X6}";
616
+ static readonly TYPE_NAME_FORMAT = "{0}_{1:X6}";
617
+ static readonly OFFSET_FORMAT = "+{0:X}";
618
+ static readonly MARKER_FORMAT = "+M";
619
+ static readonly NEGATIVE_OFFSET_FORMAT = "-{0:X}";
620
+ static readonly NEGATIVE_MARKER_FORMAT = "-M";
621
+ }
622
+
623
+ /**
624
+ * Location wrapper for additional metadata
625
+ * Converted from GaiaLib/Types/LocationWrapper.cs
626
+ */
627
+ declare class LocationWrapper {
628
+ location: number;
629
+ type: AddressType;
630
+ constructor(location: number, type: AddressType);
631
+ }
632
+
633
+ /**
634
+ * Database string command definition
635
+ * Converted from GaiaLib/Database/DbStringCommand.cs
636
+ */
637
+ declare class DbStringCommand {
638
+ id: number;
639
+ name: string;
640
+ types: MemberType[];
641
+ delimiter?: number;
642
+ halt: boolean;
643
+ constructor(data: Partial<DbStringCommand>);
644
+ }
645
+ /**
646
+ * Database string layer definition
647
+ * Converted from GaiaLib/Database/DbStringLayer.cs
648
+ */
649
+ interface DbStringLayer {
650
+ base: number;
651
+ map: string[];
652
+ }
653
+ /**
654
+ * Database string type definition
655
+ * Converted from GaiaLib/Database/DbStringType.cs
656
+ */
657
+ declare class DbStringType {
658
+ name: string;
659
+ delimiter: string;
660
+ terminator: number;
661
+ shiftType?: string;
662
+ characterMap: string[];
663
+ commands: Record<string, DbStringCommand>;
664
+ commandLookup: Record<number, DbStringCommand>;
665
+ layers: DbStringLayer[];
666
+ greedyTerminator: boolean;
667
+ constructor(data: Partial<DbStringType>);
668
+ }
669
+ /**
670
+ * String type utilities
671
+ */
672
+ declare class DbStringTypeUtils {
673
+ private static readonly shiftDownFunctions;
674
+ private static readonly shiftUpFunctions;
675
+ static getShiftDown(shiftType?: string): (x: number) => number;
676
+ static getShiftUp(shiftType?: string): (x: number) => number;
677
+ }
678
+
679
+ /**
680
+ * String marker for positioning
681
+ * Converted from GaiaLib/Types/StringMarker.cs
682
+ */
683
+ interface StringMarker {
684
+ offset: number;
685
+ }
686
+ /**
687
+ * String wrapper with type and location information
688
+ * Converted from GaiaLib/Types/StringWrapper.cs
689
+ */
690
+ interface StringWrapper {
691
+ string: string;
692
+ type: DbStringType;
693
+ marker: number;
694
+ location: number;
695
+ }
696
+ /**
697
+ * String entry (commented out in original C# code)
698
+ * Converted from GaiaLib/Types/StringEntry.cs
699
+ */
700
+ interface StringEntry {
701
+ block: AsmBlock;
702
+ index: number;
703
+ size: number;
704
+ data: Uint8Array;
705
+ }
706
+ /**
707
+ * String size comparer utility
708
+ * Converted from GaiaLib/Types/StringSizeComparer.cs
709
+ */
710
+ declare class StringSizeComparer {
711
+ /**
712
+ * Compare two strings by length
713
+ */
714
+ static compare(a: string, b: string): number;
715
+ /**
716
+ * Compare two StringWrapper objects by string length
717
+ */
718
+ static compareWrappers(a: StringWrapper, b: StringWrapper): number;
719
+ }
720
+
721
+ /**
722
+ * Structure definition
723
+ * Converted from GaiaLib/Types/StructDef.cs
724
+ */
725
+ interface StructDef {
726
+ name: string;
727
+ parts: unknown[];
728
+ }
729
+
730
+ /**
731
+ * Table entry definition
732
+ * Converted from GaiaLib/Types/TableEntry.cs
733
+ */
734
+ interface TableEntry {
735
+ location: number;
736
+ object: unknown;
737
+ }
738
+ /**
739
+ * Creates a new TableEntry
740
+ */
741
+ declare function createTableEntry(location: number, object?: unknown): TableEntry;
742
+
743
+ declare class TypedNumber {
744
+ value: number;
745
+ size: number;
746
+ constructor(value: number, size: number);
747
+ }
748
+ declare class Byte extends TypedNumber {
749
+ constructor(value: number);
750
+ }
751
+ declare class Word extends TypedNumber {
752
+ constructor(value: number);
753
+ }
754
+ declare class Long extends TypedNumber {
755
+ constructor(value: number);
756
+ }
757
+
758
+ /**
759
+ * Database entry point definition
760
+ * Converted from GaiaLib/Database/DbEntryPoint.cs
761
+ */
762
+ interface DbEntryPoint {
763
+ location: number;
764
+ name: string;
765
+ }
766
+
767
+ /**
768
+ * Database path configuration
769
+ * Converted from GaiaLib/Database/DbPath.cs
770
+ */
771
+ interface DbPath {
772
+ folder: string;
773
+ extension: string;
774
+ }
775
+ /**
776
+ * Creates a default DbPath
777
+ */
778
+ declare function createDbPath(folder?: string, extension?: string): DbPath;
779
+
780
+ /**
781
+ * Database configuration
782
+ * Converted from GaiaLib/Database/DbConfig.cs
783
+ */
784
+ interface DbConfig {
785
+ sfxLocation: number;
786
+ sfxCount: number;
787
+ compression: string;
788
+ entryPoints: DbEntryPoint[];
789
+ paths: Record<BinType, DbPath>;
790
+ }
791
+
792
+ /**
793
+ * Database structure definition
794
+ * Converted from GaiaLib/Database/DbStruct.cs
795
+ */
796
+ declare class DbStruct {
797
+ name: string;
798
+ types?: string[];
799
+ parent?: string;
800
+ delimiter?: number;
801
+ discriminator?: number;
802
+ constructor(data: Partial<DbStruct>);
803
+ }
804
+
805
+ declare class DbAddressingMode {
806
+ name: string;
807
+ shorthand: string;
808
+ operands: string[];
809
+ size: number;
810
+ formatString?: string;
811
+ parseRegex?: string;
812
+ instructions: Record<string, number>;
813
+ constructor(data: Partial<DbAddressingMode>);
814
+ }
815
+
816
+ interface DbAsset {
817
+ index: number;
818
+ type: string;
819
+ file: string;
820
+ scene: string;
821
+ meta: any;
822
+ }
823
+
824
+ declare class DbScene {
825
+ name: string;
826
+ id: number;
827
+ description?: string;
828
+ assets: DbAsset[];
829
+ constructor(data: Partial<DbScene>);
830
+ }
831
+
832
+ declare class DbGroup {
833
+ name: string;
834
+ prefix: string;
835
+ description?: string;
836
+ scenes: Record<string, DbScene>;
837
+ constructor(data: Partial<DbGroup>);
838
+ }
839
+
840
+ interface DbGameRomModule {
841
+ mnemonics: Record<number, string>;
842
+ overrides: Record<number, Record<string, number>>;
843
+ rewrites: Record<string, number>;
844
+ blocks: Record<string, Record<string, Partial<DbBlock>>>;
845
+ files: Record<string, Record<string, Record<string, Partial<DbFile>>>>;
846
+ config: DbConfig;
847
+ labels: DbLabel[];
848
+ structs: Record<string, DbStruct>;
849
+ copdef: Record<string, Partial<CopDef>>;
850
+ strings: Record<string, Partial<DbStringType>>;
851
+ transforms: Record<string, Partial<DbTransform>[]>;
852
+ addrModes: Record<string, Partial<DbAddressingMode>>;
853
+ groups: Record<string, Partial<DbGroup>>;
854
+ fileTypes: Record<string, Partial<DbFileType>>;
855
+ }
856
+ interface DbBaseRomModule extends DbGameRomModule {
857
+ baseRomFiles: ChunkFile[];
858
+ }
859
+
860
+ /**
861
+ * Main database root class
862
+ * Converted from GaiaLib/Database/DbRoot.cs
863
+ */
864
+ interface DbRoot {
865
+ copDef: Record<number, CopDef>;
866
+ copLookup: Record<string, CopDef>;
867
+ mnemonics: Record<number, string>;
868
+ structs: Record<string, DbStruct>;
869
+ stringTypes: Record<string, DbStringType>;
870
+ stringDelimiters: string[];
871
+ files: DbFile[];
872
+ config: DbConfig;
873
+ blocks: DbBlock[];
874
+ overrides: Record<number, Record<string, number>>;
875
+ labels: Record<number, string>;
876
+ rewrites: Record<number, number>;
877
+ entryPoints: DbEntryPoint[];
878
+ opCodes: Record<number, OpCode>;
879
+ opLookup: Record<string, OpCode[]>;
880
+ addrLookup: Record<string, DbAddressingMode>;
881
+ compression: ICompressionProvider;
882
+ baseRomFiles?: ChunkFile[];
883
+ projectFiles?: ChunkFile[];
884
+ groups: Record<string, DbGroup>;
885
+ scenes: Record<number, DbScene>;
886
+ fileTypes: Record<string, DbFileType>;
887
+ fileExtLookup: Record<string, DbFileType>;
888
+ }
889
+ /**
890
+ * Database root utilities
891
+ */
892
+ declare class DbRootUtils {
893
+ /**
894
+ * JSON serialization options
895
+ */
896
+ /**
897
+ * Load database from a single file
898
+ */
899
+ static fromFolder(folderPath: string, systemPath: string): Promise<DbRoot>;
900
+ /**
901
+ * Load database from folder structure
902
+ */
903
+ static gameModuleFromFolder(folderPath: string, systemPath: string): Promise<DbGameRomModule>;
904
+ static fromGameModule(module: DbGameRomModule): DbRoot;
905
+ static applyFolder(root: DbRoot, folderPath: string, sourceFiles?: ChunkFile[]): Promise<ChunkFile[]>;
906
+ static extractAllContent(root: DbRoot, romPath: string, outPath: string): Promise<void>;
907
+ static rebuildAllContent(root: DbRoot, inPath: string[], outPath: string): Promise<void>;
908
+ }
909
+
910
+ /**
911
+ * Database label definition
912
+ * Converted from GaiaLib/Database/DbLabel.cs
913
+ */
914
+ interface DbLabel {
915
+ location: number;
916
+ label: string;
917
+ }
918
+
919
+ /**
920
+ * Database mnemonic definition
921
+ * Converted from GaiaLib/Database/DbMnemonic.cs
922
+ */
923
+ interface DbMnemonic {
924
+ key: number;
925
+ value: string;
926
+ metadata?: string;
927
+ }
928
+
929
+ declare class DbOverride {
930
+ location: number;
931
+ register: string;
932
+ value: number;
933
+ constructor(values: Partial<DbOverride>);
934
+ }
935
+
936
+ /**
937
+ * Database rewrite rule definition
938
+ * Converted from GaiaLib/Database/DbRewrite.cs
939
+ */
940
+ interface DbRewrite {
941
+ location: number;
942
+ value: number;
943
+ }
944
+
945
+ /**
946
+ * Database sound effect definition
947
+ * Converted from GaiaLib/Database/DbSfx.cs
948
+ */
949
+ interface DbSfx {
950
+ location: number;
951
+ size: number;
952
+ names: string[];
953
+ }
954
+
196
955
  /**
197
956
  * Manages references, chunks, and markers during ROM analysis
198
957
  * Converted from GaiaLib/Rom/Extraction/ReferenceManager.cs
@@ -257,12 +1016,11 @@ declare class StringReader {
257
1016
  * Converted from GaiaLib/Rom/Extraction/AsmReader.cs
258
1017
  */
259
1018
  declare class AsmReader {
260
- private static readonly PROCESSOR_FLAG_MASK;
1019
+ private static readonly STATUS_OP_MASK;
1020
+ private static readonly STATUS_OP_VALUE;
261
1021
  private static readonly ACCUMULATOR_OP_MASK;
262
1022
  private static readonly ACCUMULATOR_OP_VALUE;
263
1023
  static readonly VARIABLE_SIZE_INDICATOR = -2;
264
- private static readonly TWO_BYTES_SIZE;
265
- private static readonly THREE_BYTES_SIZE;
266
1024
  private readonly _blockReader;
267
1025
  private readonly _transformProcessor;
268
1026
  private readonly _addressingModeHandler;
@@ -312,13 +1070,6 @@ declare class BlockReader {
312
1070
  readonly _romDataReader: RomDataReader;
313
1071
  readonly _stateManager: ProcessorStateManager;
314
1072
  readonly _referenceManager: ReferenceManager;
315
- get AccumulatorFlags(): Map<number, boolean | null>;
316
- get IndexFlags(): Map<number, boolean | null>;
317
- get BankNotes(): Map<number, number | null>;
318
- get StackPosition(): Map<number, number>;
319
- get _structTable(): Map<number, string>;
320
- get _markerTable(): Map<number, number>;
321
- get _nameTable(): Map<number, string>;
322
1073
  _partEnd: number;
323
1074
  _currentChunk: ChunkFile | null;
324
1075
  _currentAsmBlock: AsmBlock | null;
@@ -348,7 +1099,7 @@ declare class BlockReader {
348
1099
  * Notes a type at a location and manages chunk references
349
1100
  */
350
1101
  noteType(loc: number, type: string, silent?: boolean, reg?: Registers): string;
351
- private updateRegisterState;
1102
+ updateRegisterState(loc: number, reg: Registers): void;
352
1103
  /**
353
1104
  * Checks if a delimiter has been reached
354
1105
  */
@@ -470,7 +1221,6 @@ declare class AddressingModeHandler {
470
1221
  private readImmediateOperand;
471
1222
  private updateRegisterForImmediateInstruction;
472
1223
  private calculateRegisterValue;
473
- private updateStatusFlags;
474
1224
  private handleAbsoluteLongMode;
475
1225
  private handleBlockMoveMode;
476
1226
  private handleDirectPageMode;
@@ -604,15 +1354,14 @@ declare class RomLayout {
604
1354
  declare class RomWriter {
605
1355
  bpsPath?: string;
606
1356
  readonly outBuffer: Uint8Array;
607
- readonly entryPoints: DbEntryPoint[];
608
1357
  readonly cartName: string;
609
1358
  readonly makerCode: string;
610
- constructor(entryPoints: DbEntryPoint[], cartName: string, makerCode: string);
1359
+ readonly root: DbRoot;
1360
+ constructor(root: DbRoot, cartName: string, makerCode: string);
611
1361
  repack(files: ChunkFile[]): Promise<Uint8Array>;
612
1362
  writeHeader(): void;
613
1363
  writeChecksum(): void;
614
1364
  writeEntryPoints(asmFiles: ChunkFile[]): void;
615
- writeTransform(location: number, value: number, size?: number): void;
616
1365
  writeFile(file: ChunkFile, _chunkLookup: Map<string, number>): Promise<number>;
617
1366
  private writeAscii;
618
1367
  /**
@@ -669,9 +1418,9 @@ declare class StringProcessor {
669
1418
  private readonly memBuffer;
670
1419
  private readonly context;
671
1420
  private readonly root;
1421
+ private readonly stringCharLookup;
672
1422
  constructor(context: AssemblerContext);
673
- dispose(): void;
674
- consumeString(): void;
1423
+ consumeString(typeChar: string): void;
675
1424
  private flushBuffer;
676
1425
  private processString;
677
1426
  private applyLayers;
@@ -713,15 +1462,15 @@ declare class Assembler implements AssemblerContext {
713
1462
  lineBuffer: string;
714
1463
  includes: Set<string>;
715
1464
  blocks: AsmBlock[];
716
- tags: SortedMap<string | null>;
1465
+ tags: SortedMap<string>;
717
1466
  currentBlock: AsmBlock | null;
718
1467
  lineCount: number;
719
1468
  blockIndex: number;
720
1469
  lastDelimiter: number | null;
721
1470
  reqBank: number | null;
722
1471
  eof: boolean;
1472
+ strDelimRegex: RegExp;
723
1473
  constructor(dbRoot: DbRoot, textData: string);
724
- dispose(): void;
725
1474
  parseAssembly(): {
726
1475
  blocks: AsmBlock[];
727
1476
  includes: Set<string>;
@@ -770,7 +1519,6 @@ declare class RomGenerator {
770
1519
  private sourceData;
771
1520
  constructor(projectName?: string);
772
1521
  initialize(): Promise<void>;
773
- validateAndDownload(sourceData: Uint8Array): Promise<boolean>;
774
1522
  generateProject(modules: string[], manualFiles?: ChunkFile[], unshiftManualFiles?: boolean): Promise<Uint8Array>;
775
1523
  private applyProjectInit;
776
1524
  private assembleCodeFromText;
@@ -779,6 +1527,33 @@ declare class RomGenerator {
779
1527
  private writeRom;
780
1528
  }
781
1529
 
1530
+ /**
1531
+ * QuintetLZ compression algorithm implementation
1532
+ * Dictionary-based compression used in Quintet games
1533
+ */
1534
+ declare class QuintetLZ implements ICompressionProvider {
1535
+ static readonly DICTIONARY_SIZE = 256;
1536
+ static readonly DICTIONARY_INIT = 32;
1537
+ static readonly DICTIONARY_OFFSET = 239;
1538
+ private static readonly DEFAULT_PAGE_SIZE;
1539
+ /**
1540
+ * Expand (decompress) data using QuintetLZ algorithm
1541
+ * @param srcData Source data buffer
1542
+ * @param srcPosition Starting position in source data
1543
+ * @param srcLen Length of source data to process
1544
+ * @returns Expanded data
1545
+ */
1546
+ expand(srcData: Uint8Array, srcPosition?: number, srcLen?: number): Uint8Array;
1547
+ /**
1548
+ * Compact (compress) data using QuintetLZ algorithm
1549
+ * @param srcData Source data to compress
1550
+ * @returns Compressed data
1551
+ */
1552
+ compact(srcData: Uint8Array): Uint8Array;
1553
+ }
1554
+
1555
+ declare const CompressionAlgorithms: Record<string, () => ICompressionProvider>;
1556
+
782
1557
  /**
783
1558
  * Represents a single frame in a sprite animation sequence
784
1559
  */
@@ -849,6 +1624,728 @@ declare class SpriteMap {
849
1624
  toBytes(): Uint8Array;
850
1625
  }
851
1626
 
1627
+ /**
1628
+ * Project configuration types
1629
+ * TODO: Implement comprehensive project configuration
1630
+ */
1631
+ interface ProjectConfig {
1632
+ name: string;
1633
+ version: string;
1634
+ description?: string;
1635
+ }
1636
+
1637
+ /**
1638
+ * Collaboration types and utilities
1639
+ * TODO: Implement collaboration functionality
1640
+ */
1641
+ interface CollaborationConfig {
1642
+ enabled: boolean;
1643
+ }
1644
+
1645
+ /**
1646
+ * TypeScript interfaces for Supabase API responses
1647
+ * These types represent the structured data returned from ROM database queries
1648
+ */
1649
+ interface PlatformData {
1650
+ id: string;
1651
+ name: string;
1652
+ meta: any | null;
1653
+ createdAt: string;
1654
+ updatedAt: string;
1655
+ }
1656
+ interface BranchBaseData {
1657
+ id: string;
1658
+ name: string | null;
1659
+ version: number | null;
1660
+ isActive?: boolean | null;
1661
+ notes?: string[] | null;
1662
+ createdAt: string;
1663
+ updatedAt: string;
1664
+ }
1665
+ interface FileBaseData {
1666
+ id: string;
1667
+ name: string;
1668
+ type: string;
1669
+ version: number | null;
1670
+ crc: number | null;
1671
+ meta: any | null;
1672
+ isText: boolean;
1673
+ text: string | null;
1674
+ data: Uint8Array | null;
1675
+ createdAt: string;
1676
+ updatedAt: string;
1677
+ }
1678
+ interface FileBaseRaw extends Omit<FileBaseData, 'data'> {
1679
+ data: string | null;
1680
+ }
1681
+ /**
1682
+ * Platform branch information containing instruction set and addressing modes
1683
+ */
1684
+ interface PlatformBranchData extends BranchBaseData {
1685
+ platformId: string;
1686
+ addressingModes: any | null;
1687
+ instructionSet: any | null;
1688
+ vectors: any | null;
1689
+ types: any | null;
1690
+ platform: PlatformData;
1691
+ }
1692
+ /**
1693
+ * Game ROM branch information with platform reference
1694
+ */
1695
+ interface GameRomBranchData extends BranchBaseData {
1696
+ gameRomId: string;
1697
+ platformBranchId: string;
1698
+ coplib: any | null;
1699
+ config: any | null;
1700
+ files: any | null;
1701
+ blocks: any | null;
1702
+ fixups: any | null;
1703
+ strings: any | null;
1704
+ structs: any | null;
1705
+ scenes: any | null;
1706
+ gameRom: GameRomData;
1707
+ platformBranch: PlatformBranchData;
1708
+ }
1709
+ interface GameRomArtifactData extends FileBaseData {
1710
+ gameRomId: string;
1711
+ }
1712
+ interface GameRomArtifactRaw extends FileBaseRaw {
1713
+ gameRomId: string;
1714
+ }
1715
+ interface GameRomBranchArtifactRaw {
1716
+ id: string;
1717
+ branchId: string;
1718
+ artifactId: string;
1719
+ artifact: GameRomArtifactRaw;
1720
+ }
1721
+ /**
1722
+ * Base ROM information
1723
+ */
1724
+ interface BaseRomData {
1725
+ id: string;
1726
+ name: string;
1727
+ gameId: string;
1728
+ gameRomId: string;
1729
+ createdAt: string;
1730
+ updatedAt: string;
1731
+ }
1732
+ interface GameData {
1733
+ id: string;
1734
+ name: string;
1735
+ createdAt: string;
1736
+ updatedAt: string;
1737
+ }
1738
+ interface RegionData {
1739
+ id: string;
1740
+ name: string;
1741
+ meta: any | null;
1742
+ platformId: string;
1743
+ createdAt: string;
1744
+ updatedAt: string;
1745
+ }
1746
+ interface GameRomData {
1747
+ id: string;
1748
+ crc: number;
1749
+ meta: any | null;
1750
+ gameId: string;
1751
+ regionId: string;
1752
+ createdAt: string;
1753
+ updatedAt: string;
1754
+ game: GameData;
1755
+ region: RegionData;
1756
+ }
1757
+ /**
1758
+ * Base ROM branch with complete relationship chain
1759
+ */
1760
+ interface BaseRomBranchData extends BranchBaseData {
1761
+ baseRomId: string;
1762
+ gameRomBranchId: string;
1763
+ gameRomBranch: GameRomBranchData;
1764
+ baseRom: BaseRomData;
1765
+ }
1766
+ /**
1767
+ * Base ROM file containing binary data
1768
+ */
1769
+ interface BaseRomFileData extends FileBaseData {
1770
+ baseRomId: string;
1771
+ }
1772
+ interface BaseRomBranchFileRaw {
1773
+ id: string;
1774
+ branchId: string;
1775
+ fileId: string;
1776
+ file: BaseRomFileRaw;
1777
+ }
1778
+ /**
1779
+ * Raw BaseRomFile data as returned from Supabase (before conversion)
1780
+ */
1781
+ interface BaseRomFileRaw extends FileBaseRaw {
1782
+ baseRomId: string;
1783
+ }
1784
+ /**
1785
+ * Complete ROM payload containing branch data and files
1786
+ */
1787
+ interface BaseRomPayload {
1788
+ baseRomBranch: BaseRomBranchData;
1789
+ files: BaseRomFileData[];
1790
+ }
1791
+ /**
1792
+ * Options for loading ROM data by name
1793
+ */
1794
+ interface FromSupabaseByNameOptions {
1795
+ /**
1796
+ * Name of the game to load
1797
+ * @default 'Illusion of Gaia'
1798
+ */
1799
+ gameName: string;
1800
+ /**
1801
+ * Name of the base ROM to load
1802
+ * @default 'GaiaLabs BaseROM'
1803
+ */
1804
+ baseRomName: string;
1805
+ /**
1806
+ * Name of the branch to load
1807
+ * Set to null to load the main/develop branch
1808
+ * Set to undefined to not filter by branch name
1809
+ */
1810
+ branchName?: string | null;
1811
+ /**
1812
+ * Version of the branch to load
1813
+ * Set to null to load the latest/main version
1814
+ * Set to undefined to not filter by version
1815
+ */
1816
+ branchVersion?: number | null;
1817
+ }
1818
+ /**
1819
+ * Error codes for Supabase operations
1820
+ */
1821
+ declare enum SupabaseErrorCode {
1822
+ BRANCH_NOT_FOUND = "BRANCH_NOT_FOUND",
1823
+ ROM_NOT_FOUND = "ROM_NOT_FOUND",
1824
+ FILES_NOT_FOUND = "FILES_NOT_FOUND",
1825
+ NETWORK_ERROR = "NETWORK_ERROR",
1826
+ INVALID_DATA = "INVALID_DATA",
1827
+ ENVIRONMENT_ERROR = "ENVIRONMENT_ERROR",
1828
+ PERMISSION_ERROR = "PERMISSION_ERROR"
1829
+ }
1830
+ /**
1831
+ * Custom error class for Supabase operations
1832
+ */
1833
+ declare class SupabaseFromError extends Error {
1834
+ readonly code: SupabaseErrorCode;
1835
+ readonly details?: any;
1836
+ constructor(message: string, code: SupabaseErrorCode, details?: any);
1837
+ }
1838
+ /**
1839
+ * Result type for async operations that may fail
1840
+ */
1841
+ type SupabaseResult<T> = {
1842
+ data: T;
1843
+ error: null;
1844
+ } | {
1845
+ data: null;
1846
+ error: SupabaseFromError;
1847
+ };
1848
+ /**
1849
+ * Project information
1850
+ */
1851
+ interface ProjectData {
1852
+ id: string;
1853
+ name: string;
1854
+ meta: any | null;
1855
+ gameId: string;
1856
+ baseRomId: string;
1857
+ createdAt: string;
1858
+ updatedAt: string;
1859
+ }
1860
+ /**
1861
+ * Project branch with complete relationship chain
1862
+ */
1863
+ interface ProjectBranchData extends BranchBaseData {
1864
+ projectId: string;
1865
+ baseRomBranchId: string;
1866
+ modules: any[];
1867
+ project: ProjectData;
1868
+ baseRomBranch: BaseRomBranchData;
1869
+ }
1870
+ /**
1871
+ * Project file containing binary data
1872
+ */
1873
+ interface ProjectFileData extends FileBaseData {
1874
+ module: string | null;
1875
+ projectId: string;
1876
+ }
1877
+ interface ProjectBranchFileRaw {
1878
+ id: string;
1879
+ branchId: string;
1880
+ fileId: string;
1881
+ file: ProjectFileRaw;
1882
+ }
1883
+ /**
1884
+ * Raw ProjectFile data as returned from Supabase (before conversion)
1885
+ */
1886
+ interface ProjectFileRaw extends FileBaseRaw {
1887
+ module: string | null;
1888
+ projectId: string;
1889
+ }
1890
+ /**
1891
+ * Complete Project payload containing branch data and files
1892
+ */
1893
+ interface ProjectPayload {
1894
+ projectBranch: ProjectBranchData;
1895
+ projectFiles: ProjectFileData[];
1896
+ baseRomBranch: BaseRomBranchData;
1897
+ baseRomFiles: BaseRomFileData[];
1898
+ }
1899
+ /**
1900
+ * Options for loading Project data by name
1901
+ */
1902
+ interface FromSupabaseByProjectOptions {
1903
+ projectName: string;
1904
+ /**
1905
+ * Name of the branch to load
1906
+ * Set to null to load the main/develop branch
1907
+ * Set to undefined to not filter by branch name
1908
+ */
1909
+ branchName?: string | null;
1910
+ /**
1911
+ * Version of the branch to load
1912
+ * Set to null to load the latest/main version
1913
+ * Set to undefined to not filter by version
1914
+ */
1915
+ branchVersion?: number | null;
1916
+ }
1917
+ /**
1918
+ * Query statistics for performance monitoring
1919
+ */
1920
+ interface QueryStats {
1921
+ branchQueryTime: number;
1922
+ fileQueryTime: number;
1923
+ totalTime: number;
1924
+ fileCount: number;
1925
+ }
1926
+
1927
+ /**
1928
+ * Supabase client configuration and initialization
1929
+ */
1930
+
1931
+ /**
1932
+ * Database interface definitions based on Prisma schema
1933
+ * These types represent the structure of data returned from Supabase queries
1934
+ */
1935
+ interface Database {
1936
+ public: {
1937
+ Tables: {
1938
+ BaseRom: {
1939
+ Row: {
1940
+ id: string;
1941
+ name: string;
1942
+ gameId: string;
1943
+ gameRomId: string;
1944
+ createdAt: string;
1945
+ updatedAt: string;
1946
+ };
1947
+ };
1948
+ BaseRomBranch: {
1949
+ Row: {
1950
+ id: string;
1951
+ name: string | null;
1952
+ version: number | null;
1953
+ isPublic: boolean;
1954
+ baseRomId: string;
1955
+ gameRomBranchId: string;
1956
+ fileCrcs: number[];
1957
+ createdAt: string;
1958
+ updatedAt: string;
1959
+ };
1960
+ };
1961
+ GameRomBranch: {
1962
+ Row: {
1963
+ id: string;
1964
+ name: string | null;
1965
+ version: number | null;
1966
+ isPublic: boolean;
1967
+ gameRomId: string;
1968
+ platformBranchId: string;
1969
+ coplib: any | null;
1970
+ config: any | null;
1971
+ files: any | null;
1972
+ blocks: any | null;
1973
+ fixups: any | null;
1974
+ strings: any | null;
1975
+ structs: any | null;
1976
+ scenes: any | null;
1977
+ createdAt: string;
1978
+ updatedAt: string;
1979
+ };
1980
+ };
1981
+ GameRomBranchAsset: {
1982
+ Row: {
1983
+ id: string;
1984
+ name: string;
1985
+ type: string;
1986
+ gameRomBranchId: string;
1987
+ text: string | null;
1988
+ data: string | null;
1989
+ createdAt: string;
1990
+ updatedAt: string;
1991
+ };
1992
+ };
1993
+ PlatformBranch: {
1994
+ Row: {
1995
+ id: string;
1996
+ name: string | null;
1997
+ version: number | null;
1998
+ isPublic: boolean;
1999
+ platformId: string;
2000
+ addressingModes: any | null;
2001
+ instructionSet: any | null;
2002
+ vectors: any | null;
2003
+ createdAt: string;
2004
+ updatedAt: string;
2005
+ };
2006
+ };
2007
+ BaseRomFile: {
2008
+ Row: {
2009
+ id: string;
2010
+ name: string;
2011
+ type: string;
2012
+ version: number | null;
2013
+ crc: number | null;
2014
+ meta: any | null;
2015
+ baseRomId: string;
2016
+ data: string;
2017
+ createdAt: string;
2018
+ updatedAt: string;
2019
+ };
2020
+ };
2021
+ };
2022
+ };
2023
+ }
2024
+ /**
2025
+ * Create and configure a Supabase client instance
2026
+ * @returns Configured Supabase client
2027
+ */
2028
+ declare function createSupabaseClient(): SupabaseClient<Database>;
2029
+ /**
2030
+ * Get the singleton Supabase client instance
2031
+ * Creates the instance if it doesn't exist
2032
+ * @returns Supabase client instance
2033
+ */
2034
+ declare function getSupabaseClient(): SupabaseClient<Database>;
2035
+ /**
2036
+ * Reset the singleton client instance (useful for testing)
2037
+ */
2038
+ declare function resetSupabaseClient(): void;
2039
+
2040
+ /**
2041
+ * ROM data loading functions for Supabase integration
2042
+ *
2043
+ * This module provides functions to load ROM branch data and files from Supabase,
2044
+ * enabling cloud-based ROM database functionality for the GaiaLabs platform.
2045
+ */
2046
+
2047
+ /**
2048
+ * Load ROM data from Supabase using a BaseRomBranch ID
2049
+ *
2050
+ * @param baseRomBranchId - The ID of the BaseRomBranch to load
2051
+ * @returns Promise<BaseRomPayload> containing the branch data and files
2052
+ * @throws {SupabaseFromError} If the branch is not found or other errors occur
2053
+ *
2054
+ * @example
2055
+ * ```typescript
2056
+ * const payload = await fromSupabaseById('clm1234567890');
2057
+ * console.log(payload.baseRomBranch.name);
2058
+ * console.log(`Loaded ${payload.files.length} files`);
2059
+ * ```
2060
+ */
2061
+ declare function fromSupabaseById(baseRomBranchId: string): Promise<BaseRomPayload>;
2062
+ /**
2063
+ * Load ROM data from Supabase using name-based lookup
2064
+ *
2065
+ * @param options - Options for name-based lookup
2066
+ * @returns Promise<BaseRomPayload> containing the branch data and files
2067
+ * @throws {SupabaseFromError} If the branch is not found or other errors occur
2068
+ *
2069
+ * @example
2070
+ * ```typescript
2071
+ * // Load default ROM (GaiaLabs BaseROM, main branch)
2072
+ * const payload1 = await fromSupabaseByName({});
2073
+ *
2074
+ * // Load specific ROM and branch
2075
+ * const payload2 = await fromSupabaseByName({
2076
+ * baseRomName: 'My Custom ROM',
2077
+ * branchName: 'development',
2078
+ * branchVersion: null // latest version
2079
+ * });
2080
+ *
2081
+ * // Load main branch explicitly
2082
+ * const payload3 = await fromSupabaseByName({
2083
+ * baseRomName: 'GaiaLabs BaseROM',
2084
+ * branchName: null, // main branch
2085
+ * branchVersion: null // latest version
2086
+ * });
2087
+ * ```
2088
+ */
2089
+ declare function fromSupabaseByName(options: FromSupabaseByNameOptions): Promise<BaseRomPayload>;
2090
+ /**
2091
+ * Load Project data from Supabase using project name-based lookup
2092
+ *
2093
+ * @param projectName - The name of the project to load
2094
+ * @param options - Options for branch filtering
2095
+ * @returns Promise<ProjectPayload> containing the project branch data and files
2096
+ * @throws {SupabaseFromError} If the project branch is not found or other errors occur
2097
+ *
2098
+ * @example
2099
+ * ```typescript
2100
+ * // Load default project branch (main/latest)
2101
+ * const payload1 = await fromSupabaseByProject('My Game Project');
2102
+ *
2103
+ * // Load specific branch
2104
+ * const payload2 = await fromSupabaseByProject('My Game Project', {
2105
+ * branchName: 'development',
2106
+ * branchVersion: null // latest version
2107
+ * });
2108
+ *
2109
+ * // Load main branch explicitly
2110
+ * const payload3 = await fromSupabaseByProject('My Game Project', {
2111
+ * branchName: null, // main branch
2112
+ * branchVersion: null // latest version
2113
+ * });
2114
+ * ```
2115
+ */
2116
+ declare function fromSupabaseByProject(projectName?: string, branchId?: string): Promise<ProjectPayload>;
2117
+ declare function fromSupabaseByGameRom(gameName?: string, regionName?: string, platformName?: string, branchId?: string): Promise<ProjectPayload>;
2118
+ declare function summaryFromSupabaseByProject(projectName?: string): Promise<ProjectBranchData>;
2119
+
2120
+ /**
2121
+ * Utility functions for Supabase integration
2122
+ */
2123
+ /**
2124
+ * Get environment variable value that works in both browser and Node.js contexts
2125
+ * @param key - The environment variable key to retrieve
2126
+ * @throws {Error} If the environment variable is not set
2127
+ * @returns The environment variable value
2128
+ */
2129
+ declare function getEnvVar(key: string): string;
2130
+ /**
2131
+ * Convert base64 string to Uint8Array for binary data processing
2132
+ * @param base64 - Base64 encoded string
2133
+ * @returns Uint8Array containing the binary data
2134
+ */
2135
+ declare function base64ToUint8Array(base64: string): Uint8Array;
2136
+ /**
2137
+ * Convert hex-encoded string to Uint8Array
2138
+ * @param hexString - Hex encoded string (with or without \x prefix)
2139
+ * @returns Uint8Array containing the binary data
2140
+ */
2141
+ declare function hexToUint8Array(hexString: string): Uint8Array;
2142
+ /**
2143
+ * Convert binary data to appropriate format based on the input string
2144
+ * Automatically detects if the input is hex-encoded or base64
2145
+ * @param dataString - Either hex-encoded string (starting with \x) or base64 string
2146
+ * @returns Uint8Array containing the binary data
2147
+ */
2148
+ declare function decodeDataString(dataString: string): Uint8Array;
2149
+ /**
2150
+ * Convert Uint8Array to base64 string
2151
+ * @param uint8Array - Binary data as Uint8Array
2152
+ * @returns Base64 encoded string
2153
+ */
2154
+ declare function uint8ArrayToBase64(uint8Array: Uint8Array): string;
2155
+ /**
2156
+ * Validate that required environment variables are set
2157
+ * @param requiredVars - Array of environment variable names that must be set
2158
+ * @throws {Error} If any required environment variable is missing
2159
+ */
2160
+ declare function validateEnvironmentVariables(requiredVars: string[]): void;
2161
+
2162
+ /**
2163
+ * Universal file reading utilities
2164
+ * Works in both Node.js and browser environments
2165
+ */
2166
+ interface FileReadOptions {
2167
+ encoding?: 'utf8' | 'binary';
2168
+ }
2169
+ /**
2170
+ * Read a file as text
2171
+ * @param path File path or URL
2172
+ * @param options Read options
2173
+ * @returns Promise<string>
2174
+ */
2175
+ declare function readFileAsText(path: string, options?: FileReadOptions): Promise<string>;
2176
+ /**
2177
+ * Read a file as binary data (Uint8Array)
2178
+ * @param path File path or URL
2179
+ * @returns Promise<Uint8Array>
2180
+ */
2181
+ declare function readFileAsBinary(path: string): Promise<Uint8Array>;
2182
+ /**
2183
+ * Read a JSON file and parse it
2184
+ * @param path File path or URL
2185
+ * @returns Promise<any>
2186
+ */
2187
+ declare function readJsonFile<T = any>(path: string): Promise<T>;
2188
+ /**
2189
+ * Check if a file exists
2190
+ * @param path File path
2191
+ * @returns Promise<boolean>
2192
+ */
2193
+ declare function fileExists(path: string): Promise<boolean>;
2194
+ /**
2195
+ * Get the directory path containing a file
2196
+ * @param filePath File path
2197
+ * @returns string
2198
+ */
2199
+ declare function getDirectory(filePath: string): Promise<string>;
2200
+ /**
2201
+ * Create a temporary directory.
2202
+ * This is a Node.js-specific operation.
2203
+ * @param prefix Prefix for the temporary directory name.
2204
+ * @returns Promise<string> Path to the created temporary directory.
2205
+ */
2206
+ declare function createTempDirectory(prefix: string): Promise<string>;
2207
+ /**
2208
+ * Remove a directory recursively.
2209
+ * This is a Node.js-specific operation.
2210
+ * @param dirPath Path to the directory to remove.
2211
+ * @returns Promise<void>
2212
+ */
2213
+ declare function removeDirectory(dirPath: string): Promise<void>;
2214
+ interface DirectoryEntry {
2215
+ name: string;
2216
+ path: string;
2217
+ isDirectory: boolean;
2218
+ isFile: boolean;
2219
+ }
2220
+ /**
2221
+ * List directory contents
2222
+ * This is a Node.js-specific operation.
2223
+ * @param dirPath Path to the directory to list
2224
+ * @param options Options for filtering and recursion
2225
+ * @returns Promise<DirectoryEntry[]>
2226
+ */
2227
+ declare function listDirectory(dirPath: string, options?: {
2228
+ recursive?: boolean;
2229
+ filter?: (entry: DirectoryEntry) => boolean;
2230
+ extension?: string;
2231
+ }): Promise<DirectoryEntry[]>;
2232
+ /**
2233
+ * Save text content to a file
2234
+ * This is a Node.js-specific operation.
2235
+ * @param path File path where to save the content
2236
+ * @param text Text content to save
2237
+ * @returns Promise<void>
2238
+ */
2239
+ declare function saveFileAsText(path: string, text: string): Promise<void>;
2240
+ /**
2241
+ * Save binary data to a file
2242
+ * This is a Node.js-specific operation.
2243
+ * @param path File path where to save the data
2244
+ * @param data Binary data as Uint8Array to save
2245
+ * @returns Promise<void>
2246
+ */
2247
+ declare function saveFileAsBinary(path: string, data: Uint8Array): Promise<void>;
2248
+
2249
+ declare function crc32_buffer(data: Uint8Array): number;
2250
+ declare function crc32_text_utf8(text: string): number;
2251
+ declare function crc32_text_utf16(text: string): number;
2252
+
2253
+ /**
2254
+ * Base64 encoding and decoding utilities for Uint8Arrays
2255
+ * Works in both Node.js and browser environments
2256
+ */
2257
+ /**
2258
+ * Encode a Uint8Array to a base64 string
2259
+ * @param data The binary data to encode
2260
+ * @returns Base64 encoded string
2261
+ */
2262
+ declare function encodeBase64(data: Uint8Array): string;
2263
+ /**
2264
+ * Decode a base64 string to a Uint8Array
2265
+ * @param base64String The base64 string to decode
2266
+ * @returns Decoded binary data as Uint8Array
2267
+ * @throws {Error} If the input is not a valid base64 string
2268
+ */
2269
+ declare function decodeBase64(base64String: string): Uint8Array;
2270
+ /**
2271
+ * Check if a string is valid base64
2272
+ * @param str The string to validate
2273
+ * @returns True if the string is valid base64, false otherwise
2274
+ */
2275
+ declare function isValidBase64(str: string): boolean;
2276
+ /**
2277
+ * Encode a string to base64 (convenience function)
2278
+ * @param text The text string to encode
2279
+ * @returns Base64 encoded string
2280
+ */
2281
+ declare function encodeBase64String(text: string): string;
2282
+ /**
2283
+ * Decode a base64 string to text (convenience function)
2284
+ * @param base64String The base64 string to decode
2285
+ * @returns Decoded text string
2286
+ * @throws {Error} If the input is not a valid base64 string or doesn't contain valid UTF-8
2287
+ */
2288
+ declare function decodeBase64String(base64String: string): string;
2289
+
2290
+ /**
2291
+ * Debug utility to export processing results as JSON for comparison
2292
+ */
2293
+ declare class DebugExporter {
2294
+ /**
2295
+ * Export chunk files to JSON for comparison with C# output
2296
+ */
2297
+ static exportChunkFiles(files: ChunkFile[], filename: string): void;
2298
+ /**
2299
+ * Export patch application summary
2300
+ */
2301
+ static exportPatchSummary(originalFiles: ChunkFile[], patchedFiles: ChunkFile[], patches: ChunkFile[], filename: string): void;
2302
+ /**
2303
+ * Export layout debugging information
2304
+ */
2305
+ static exportLayoutDebug(files: ChunkFile[], filename: string): void;
2306
+ }
2307
+
2308
+ /**
2309
+ * Convert bytes to hex string
2310
+ */
2311
+ declare function bytesToHex(bytes: Uint8Array): string;
2312
+ /**
2313
+ * Convert hex string to bytes
2314
+ */
2315
+ declare function hexToBytes(hex: string): Uint8Array;
2316
+ /**
2317
+ * Clamp a value between min and max
2318
+ */
2319
+ declare function clamp(value: number, min: number, max: number): number;
2320
+ /**
2321
+ * Convert binary data (Uint8Array) to UTF-8 string representation
2322
+ *
2323
+ * This function properly decodes UTF-8 encoded binary data to avoid corruption
2324
+ * of special characters and multi-byte sequences.
2325
+ *
2326
+ * @param binaryData - The binary data as Uint8Array containing UTF-8 encoded text
2327
+ * @returns The decoded UTF-8 string
2328
+ * @throws {Error} If the binary data contains invalid UTF-8 sequences
2329
+ *
2330
+ * @example
2331
+ * ```typescript
2332
+ * const binaryData = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
2333
+ * const text = binaryToUtf8String(binaryData);
2334
+ * console.log(text); // "Hello World"
2335
+ *
2336
+ * // Handle UTF-8 multi-byte characters
2337
+ * const utf8Data = new Uint8Array([240, 159, 152, 128]); // 😀 emoji
2338
+ * const emoji = binaryToUtf8String(utf8Data);
2339
+ * console.log(emoji); // "😀"
2340
+ * ```
2341
+ */
2342
+ declare function binaryToUtf8String(binaryData: Uint8Array): string;
2343
+ /**
2344
+ * Safely get nested object property
2345
+ */
2346
+ declare function getNestedProperty(obj: any, path: string): any;
2347
+ declare function indexOfAny(str: string, chars: string[], startIndex?: number): number;
2348
+
852
2349
  /**
853
2350
  * GaiaCore - Universal ROM processing engine
854
2351
  *
@@ -867,7 +2364,7 @@ declare class SpriteMap {
867
2364
  */
868
2365
  declare const GAIA_CORE_VERSION = "0.1.6";
869
2366
  declare const isPlatformBrowser: boolean;
870
- declare const isPlatformNode: string | false;
2367
+ declare const isPlatformNode: string;
871
2368
  declare const isPlatformWebWorker: boolean;
872
2369
 
873
- export { AddressingModeHandler, AsmReader, Assembler, type AssemblerContext, AssemblerState, BlockReader, BlockWriter, CopCommandProcessor, GAIA_CORE_VERSION, ObjectType, OperationContext, PostProcessor, ProcessorStateManager, type ProjectConfig, ProjectRoot, QuintetLZ, ReferenceManager, Registers, RomDataReader, RomGenerator, RomLayout, RomProcessor, RomState, RomStateUtils, RomWriter, SortedMap, SpriteFrame, SpriteGroup, SpriteMap, SpritePart, Stack, StackOperations, StringProcessor, StringReader, TransformProcessor, TypeParser, isPlatformBrowser, isPlatformNode, isPlatformWebWorker, registerCompressionProviders };
2370
+ export { Address, AddressSpace, AddressType, AddressingModeHandler, AsmBlock, AsmBlockUtils, AsmReader, Assembler, type AssemblerContext, AssemblerState, type BaseRomBranchData, type BaseRomBranchFileRaw, type BaseRomData, type BaseRomFileData, type BaseRomFileRaw, type BaseRomPayload, BinType, BitStream, BlockReader, BlockReaderConstants, BlockWriter, type BranchBaseData, Byte, ChunkFile, ChunkFileUtils, type CollaborationConfig, CompressionAlgorithms, CompressionRegistry, CopCommandProcessor, CopDef, type Database, DbAddressingMode, type DbAsset, type DbBaseRomModule, DbBlock, type DbConfig, type DbEntryPoint, DbFile, DbFileType, type DbGameRomModule, DbGroup, type DbLabel, type DbMnemonic, DbOverride, DbPart, type DbPath, type DbRewrite, type DbRoot, DbRootUtils, DbScene, type DbSfx, DbStringCommand, type DbStringLayer, DbStringType, DbStringTypeUtils, DbStruct, DbTransform, DebugExporter, type DirectoryEntry, type FileBaseData, type FileBaseRaw, type FileReadOptions, type FromSupabaseByNameOptions, type FromSupabaseByProjectOptions, GAIA_CORE_VERSION, type GameData, type GameRomArtifactData, type GameRomArtifactRaw, type GameRomBranchArtifactRaw, type GameRomBranchData, type GameRomData, type ICompressionProvider, LocationWrapper, Long, MapExt, MemberType, ObjectType, Op, OpCode, OperationContext, type PlatformBranchData, type PlatformData, PostProcessor, ProcessorStateManager, type ProjectBranchData, type ProjectBranchFileRaw, type ProjectConfig, type ProjectData, type ProjectFileData, type ProjectFileRaw, type ProjectPayload, type QueryStats, QuintetLZ, ReferenceManager, type RegionData, RegisterType, Registers, RomDataReader, RomGenerator, RomLayout, RomProcessingConstants, RomProcessor, RomState, RomStateUtils, RomWriter, SortedMap, SpriteFrame, SpriteGroup, SpriteMap, SpritePart, Stack, StackOperations, StatusFlags, type StringEntry, type StringMarker, StringProcessor, StringReader, StringSizeComparer, type StringWrapper, type StructDef, SupabaseErrorCode, SupabaseFromError, type SupabaseResult, type TableEntry, TransformProcessor, TypeParser, TypedNumber, Word, type XformDef, XformType, base64ToUint8Array, binaryToUtf8String, bytesToHex, clamp, crc32_buffer, crc32_text_utf16, crc32_text_utf8, createChunkFileFromDbBlock, createChunkFileFromDbFile, createDbPath, createSupabaseClient, createTableEntry, createTempDirectory, decodeBase64, decodeBase64String, decodeDataString, encodeBase64, encodeBase64String, fileExists, fromSupabaseByGameRom, fromSupabaseById, fromSupabaseByName, fromSupabaseByProject, getDirectory, getEnvVar, getNestedProperty, getSupabaseClient, hexToBytes, hexToUint8Array, indexOfAny, isPlatformBrowser, isPlatformNode, isPlatformWebWorker, isValidBase64, listDirectory, readFileAsBinary, readFileAsText, readJsonFile, removeDirectory, resetSupabaseClient, saveFileAsBinary, saveFileAsText, summaryFromSupabaseByProject, uint8ArrayToBase64, validateEnvironmentVariables };