@ahmadmoussawi/webdb 0.0.0-stage → 0.1.1

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.
Files changed (106) hide show
  1. package/README.md +386 -2
  2. package/dist/constants.d.ts +18 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/core/index.d.ts +15 -0
  5. package/dist/core/index.d.ts.map +1 -0
  6. package/dist/core/js/buffer_pool.c.d.ts +142 -0
  7. package/dist/core/js/buffer_pool.c.d.ts.map +1 -0
  8. package/dist/core/js/catalog.c.d.ts +186 -0
  9. package/dist/core/js/catalog.c.d.ts.map +1 -0
  10. package/dist/core/js/codecs.c.d.ts +32 -0
  11. package/dist/core/js/codecs.c.d.ts.map +1 -0
  12. package/dist/core/js/index.d.ts +7 -0
  13. package/dist/core/js/index.d.ts.map +1 -0
  14. package/dist/core/js/page.c.d.ts +229 -0
  15. package/dist/core/js/page.c.d.ts.map +1 -0
  16. package/dist/core/js/page_table.c.d.ts +48 -0
  17. package/dist/core/js/page_table.c.d.ts.map +1 -0
  18. package/dist/core/js/vm.c.d.ts +11 -0
  19. package/dist/core/js/vm.c.d.ts.map +1 -0
  20. package/dist/core/js/vm.helpers.c.d.ts +124 -0
  21. package/dist/core/js/vm.helpers.c.d.ts.map +1 -0
  22. package/dist/core/types.d.ts +26 -0
  23. package/dist/core/types.d.ts.map +1 -0
  24. package/dist/core/wasm/embedded_wasm.d.ts +7 -0
  25. package/dist/core/wasm/embedded_wasm.d.ts.map +1 -0
  26. package/dist/core/wasm/wasm_core.d.ts +75 -0
  27. package/dist/core/wasm/wasm_core.d.ts.map +1 -0
  28. package/dist/host/api/index.d.ts +3 -0
  29. package/dist/host/api/index.d.ts.map +1 -0
  30. package/dist/host/api/query_builder.d.ts +216 -0
  31. package/dist/host/api/query_builder.d.ts.map +1 -0
  32. package/dist/host/api/webdb.d.ts +172 -0
  33. package/dist/host/api/webdb.d.ts.map +1 -0
  34. package/dist/host/compiler/compiler.d.ts +151 -0
  35. package/dist/host/compiler/compiler.d.ts.map +1 -0
  36. package/dist/host/compiler/expr_parser.d.ts +87 -0
  37. package/dist/host/compiler/expr_parser.d.ts.map +1 -0
  38. package/dist/host/compiler/index.d.ts +4 -0
  39. package/dist/host/compiler/index.d.ts.map +1 -0
  40. package/dist/host/compiler/planner/cost.d.ts +23 -0
  41. package/dist/host/compiler/planner/cost.d.ts.map +1 -0
  42. package/dist/host/compiler/planner/custom_order.d.ts +16 -0
  43. package/dist/host/compiler/planner/custom_order.d.ts.map +1 -0
  44. package/dist/host/compiler/planner/heuristic.d.ts +11 -0
  45. package/dist/host/compiler/planner/heuristic.d.ts.map +1 -0
  46. package/dist/host/compiler/planner/index.d.ts +34 -0
  47. package/dist/host/compiler/planner/index.d.ts.map +1 -0
  48. package/dist/host/compiler/planner/noop.d.ts +11 -0
  49. package/dist/host/compiler/planner/noop.d.ts.map +1 -0
  50. package/dist/host/compiler/planner/types.d.ts +100 -0
  51. package/dist/host/compiler/planner/types.d.ts.map +1 -0
  52. package/dist/host/compiler/planner/where_optimizer.d.ts +30 -0
  53. package/dist/host/compiler/planner/where_optimizer.d.ts.map +1 -0
  54. package/dist/host/compiler/planner.d.ts +2 -0
  55. package/dist/host/compiler/planner.d.ts.map +1 -0
  56. package/dist/host/driver/buffer_pool_driver.d.ts +94 -0
  57. package/dist/host/driver/buffer_pool_driver.d.ts.map +1 -0
  58. package/dist/host/driver/crash_recovery.d.ts +24 -0
  59. package/dist/host/driver/crash_recovery.d.ts.map +1 -0
  60. package/dist/host/driver/index.d.ts +4 -0
  61. package/dist/host/driver/index.d.ts.map +1 -0
  62. package/dist/host/driver/transaction_coordinator.d.ts +166 -0
  63. package/dist/host/driver/transaction_coordinator.d.ts.map +1 -0
  64. package/dist/host/storage/crc32.d.ts +24 -0
  65. package/dist/host/storage/crc32.d.ts.map +1 -0
  66. package/dist/host/storage/idb.d.ts +27 -0
  67. package/dist/host/storage/idb.d.ts.map +1 -0
  68. package/dist/host/storage/index.d.ts +8 -0
  69. package/dist/host/storage/index.d.ts.map +1 -0
  70. package/dist/host/storage/io.d.ts +60 -0
  71. package/dist/host/storage/io.d.ts.map +1 -0
  72. package/dist/host/storage/memory.d.ts +28 -0
  73. package/dist/host/storage/memory.d.ts.map +1 -0
  74. package/dist/host/storage/opfs.d.ts +31 -0
  75. package/dist/host/storage/opfs.d.ts.map +1 -0
  76. package/dist/host/storage/vfs.d.ts +36 -0
  77. package/dist/host/storage/vfs.d.ts.map +1 -0
  78. package/dist/host/storage/wal_codec.d.ts +56 -0
  79. package/dist/host/storage/wal_codec.d.ts.map +1 -0
  80. package/dist/index.d.ts +9 -0
  81. package/dist/index.d.ts.map +1 -0
  82. package/dist/layouts/index.d.ts +5 -0
  83. package/dist/layouts/index.d.ts.map +1 -0
  84. package/dist/layouts/page_format.d.ts +163 -0
  85. package/dist/layouts/page_format.d.ts.map +1 -0
  86. package/dist/layouts/pool_format.d.ts +126 -0
  87. package/dist/layouts/pool_format.d.ts.map +1 -0
  88. package/dist/layouts/syspage_format.d.ts +499 -0
  89. package/dist/layouts/syspage_format.d.ts.map +1 -0
  90. package/dist/layouts/wal_format.d.ts +197 -0
  91. package/dist/layouts/wal_format.d.ts.map +1 -0
  92. package/dist/shared/c_runtime.d.ts +47 -0
  93. package/dist/shared/c_runtime.d.ts.map +1 -0
  94. package/dist/shared/index.d.ts +4 -0
  95. package/dist/shared/index.d.ts.map +1 -0
  96. package/dist/shared/page_provider.d.ts +12 -0
  97. package/dist/shared/page_provider.d.ts.map +1 -0
  98. package/dist/shared/vm_context.d.ts +73 -0
  99. package/dist/shared/vm_context.d.ts.map +1 -0
  100. package/dist/types/index.d.ts +338 -0
  101. package/dist/types/index.d.ts.map +1 -0
  102. package/dist/webdb.js +13059 -0
  103. package/dist/webdb.js.map +1 -0
  104. package/dist/webdb.umd.cjs +5 -0
  105. package/dist/webdb.umd.cjs.map +1 -0
  106. package/package.json +82 -4
@@ -0,0 +1,31 @@
1
+ import { IVfsAdapter } from './vfs.js';
2
+ export declare class OpfsVfsAdapter implements IVfsAdapter {
3
+ readonly name: "opfs";
4
+ readonly isSynchronous: boolean;
5
+ private dbName;
6
+ private rootDir;
7
+ private dbFileHandle;
8
+ private walFileHandle;
9
+ private dbSyncHandle;
10
+ private walSyncHandle;
11
+ constructor(dbName: string);
12
+ private initHandles;
13
+ readPage(pageId: number): Promise<Uint8Array | null>;
14
+ writePage(pageId: number, data: Uint8Array): Promise<void>;
15
+ writePages(pages: Array<{
16
+ pageId: number;
17
+ data: Uint8Array;
18
+ }>): Promise<void>;
19
+ flush(): Promise<void>;
20
+ truncate(pageCount: number): Promise<void>;
21
+ readWalHeader(): Promise<Uint8Array | null>;
22
+ writeWalHeader(header: Uint8Array): Promise<void>;
23
+ readWalFrame(frameIndex: number): Promise<Uint8Array | null>;
24
+ readWalFrames(startFrameIndex: number, maxFrames?: number): Promise<Uint8Array[]>;
25
+ appendWalFrames(frames: Uint8Array[]): Promise<void>;
26
+ flushWal(): Promise<void>;
27
+ truncateWal(frameIndex: number): Promise<void>;
28
+ getWalFrameCount(): Promise<number>;
29
+ close(): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=opfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opfs.d.ts","sourceRoot":"","sources":["../../../src/host/storage/opfs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAU;IAChC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAEhC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAA0C;IACzD,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,aAAa,CAAqC;IAG1D,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,aAAa,CAAa;gBAEtB,MAAM,EAAE,MAAM;YAKZ,WAAW;IAqBnB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAmBpD,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAMtB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc1C,aAAa,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAe3C,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAYjD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAkB5D,aAAa,CAAC,eAAe,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAcjF,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBpD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAMzB,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc9C,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAanC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAa7B"}
@@ -0,0 +1,36 @@
1
+ export interface IVfsAdapter {
2
+ readonly name: 'memory' | 'opfs' | 'idb';
3
+ readonly isSynchronous: boolean;
4
+ /** Reads a 4KB page from storage into a Uint8Array */
5
+ readPage(pageId: number): Promise<Uint8Array | null>;
6
+ /** Writes a 4KB page from memory to persistent storage */
7
+ writePage(pageId: number, data: Uint8Array): Promise<void>;
8
+ /** Atomically commits a batch of dirty pages or WAL frames */
9
+ writePages(pages: Array<{
10
+ pageId: number;
11
+ data: Uint8Array;
12
+ }>): Promise<void>;
13
+ /** Flushes all in-flight writes durably to persistent storage */
14
+ flush(): Promise<void>;
15
+ /** Truncates the storage file/store to the specified page count */
16
+ truncate(pageCount: number): Promise<void>;
17
+ /** Reads the 32-byte WAL file header. Returns null if WAL is empty or does not exist. */
18
+ readWalHeader(): Promise<Uint8Array | null>;
19
+ /** Writes or overwrites the 32-byte WAL file header */
20
+ writeWalHeader(header: Uint8Array): Promise<void>;
21
+ /** Reads a single 4,128-byte WAL frame (32B header + 4096B page data) by 0-based frame index */
22
+ readWalFrame(frameIndex: number): Promise<Uint8Array | null>;
23
+ /** Reads a batch of consecutive 4,128-byte WAL frames starting from frameIndex */
24
+ readWalFrames(startFrameIndex: number, maxFrames?: number): Promise<Uint8Array[]>;
25
+ /** Appends one or more 4,128-byte WAL frames to the end of the log */
26
+ appendWalFrames(frames: Uint8Array[]): Promise<void>;
27
+ /** Flushes WAL writes durably to persistent storage */
28
+ flushWal(): Promise<void>;
29
+ /** Truncates the WAL to the specified frame count (0 resets WAL) */
30
+ truncateWal(frameIndex: number): Promise<void>;
31
+ /** Returns the current number of frames in the WAL */
32
+ getWalFrameCount(): Promise<number>;
33
+ /** Closes and cleans up storage handles */
34
+ close(): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=vfs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vfs.d.ts","sourceRoot":"","sources":["../../../src/host/storage/vfs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;IACzC,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC;IAEhC,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAA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+1,56 @@
1
+ export declare const WAL_MAGIC_BYTES: Uint8Array<ArrayBuffer>;
2
+ export interface WalFileHeader {
3
+ walVersion: number;
4
+ pageSize: number;
5
+ checkpointSeq: number;
6
+ salt1: number;
7
+ salt2: number;
8
+ checksum: number;
9
+ }
10
+ export interface WalFrameHeader {
11
+ magic: number;
12
+ frameType: number;
13
+ flags: number;
14
+ txId: number;
15
+ pageId: number;
16
+ dbSizePages: number;
17
+ frameSeq: number;
18
+ checksum: number;
19
+ }
20
+ export interface WalFrame {
21
+ header: WalFrameHeader;
22
+ pageData: Uint8Array;
23
+ }
24
+ /**
25
+ * Encodes a 32-byte WAL file header.
26
+ */
27
+ export declare function encodeWalFileHeader(header?: Partial<WalFileHeader>): Uint8Array;
28
+ /**
29
+ * Decodes and validates a 32-byte WAL file header.
30
+ */
31
+ export declare function decodeWalFileHeader(bytes: Uint8Array, verifyChecksum?: boolean): WalFileHeader;
32
+ /**
33
+ * Encodes a single 4,128-byte WAL frame (32-byte header + 4096-byte page payload).
34
+ */
35
+ export declare function encodeWalFrame(header: Omit<WalFrameHeader, 'magic' | 'checksum'> & {
36
+ magic?: number;
37
+ checksum?: number;
38
+ }, pageData?: Uint8Array): Uint8Array;
39
+ /**
40
+ * Decodes only the 32-byte header of a WAL frame without copying the 4096 page bytes.
41
+ */
42
+ export declare function decodeWalFrameHeader(frameBytes: Uint8Array): WalFrameHeader;
43
+ /**
44
+ * Validates a candidate WAL frame without throwing, detecting truncated tails,
45
+ * magic mismatches, and torn writes / CRC32 bit corruption.
46
+ */
47
+ export declare function validateWalFrame(frameBytes: Uint8Array): {
48
+ valid: boolean;
49
+ reason?: 'truncated' | 'magic_mismatch' | 'checksum_mismatch';
50
+ header?: WalFrameHeader;
51
+ };
52
+ /**
53
+ * Decodes and verifies a complete 4,128-byte WAL frame.
54
+ */
55
+ export declare function decodeWalFrame(frameBytes: Uint8Array, verifyChecksum?: boolean): WalFrame;
56
+ //# sourceMappingURL=wal_codec.d.ts.map
@@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GG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG;IACxD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;IAC9D,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAgBA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,EAAE,cAAc,GAAE,OAAc,GAAG,QAAQ,CAyB/F"}
@@ -0,0 +1,9 @@
1
+ export * from './types/index.js';
2
+ export * from './constants.js';
3
+ export * from './host/storage/index.js';
4
+ export * from './host/driver/index.js';
5
+ export * from './host/compiler/index.js';
6
+ export * from './host/api/index.js';
7
+ export * from './core/index.js';
8
+ export * from './shared/index.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './page_format.ts';
2
+ export * from './syspage_format.ts';
3
+ export * from './pool_format.ts';
4
+ export * from './wal_format.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layouts/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * AUTO-GENERATED AT BUILD TIME FROM src/layouts/schemas/page_format.json
3
+ * DO NOT EDIT MANUALLY. Run 'npm run generate:layouts' to rebuild.
4
+ */
5
+ /**
6
+ * ============================================================================
7
+ * CRITICAL WARNING: FROZEN ON-DISK PAGE FORMAT SPECIFICATION
8
+ * DO NOT alter the order, types, or byte lengths of existing fields in this
9
+ * layout! Changing any field offset will invalidate existing binary databases,
10
+ * break cross-version read compatibility, and result in unrecoverable data
11
+ * corruption.
12
+ *
13
+ * Any future extensions MUST use designated reserved bytes or bump
14
+ * CURRENT_ENGINE_VERSION and CURRENT_MIN_READ_VERSION.
15
+ * ============================================================================
16
+ */
17
+ /**
18
+ * Standard uniform page size in bytes across the entire database engine (4 KB).
19
+ * Every page in the database file and buffer pool is rigidly aligned to this size.
20
+ */
21
+ export declare const PAGE_SIZE = 4096;
22
+ /**
23
+ * Strict maximum size in bytes allowed for a single serialized row record (2 KB).
24
+ * Enforces the B-tree invariant that at least two rows fit on a leaf data page
25
+ * without requiring overflow chaining in the v1 engine.
26
+ */
27
+ export declare const MAX_ROW_SIZE = 2048;
28
+ /**
29
+ * 32-bit Word Byte Layout Grid for SLOTTED_PAGE_HEADER:
30
+ * Byte 0 Byte 1 Byte 2 Byte 3
31
+ * +-----------------+-----------------+-----------------+-----------------+
32
+ * | TYPE (1B) | FLAGS (1B) | CELL_COUNT (2B) |
33
+ * +-----------------+-----------------+-----------------------------------+
34
+ * | CONTENT_OFFSET (2B) | NEXT_PAGE_ID [0..1] |
35
+ * +-----------------------------------+-----------------------------------+
36
+ * | NEXT_PAGE_ID [2..3] | FREE_BYTES (2B) |
37
+ * +-----------------------------------+-----------------------------------+
38
+ * | CHECKSUM (4B) |
39
+ * +-----------------------------------------------------------------------+
40
+ *
41
+ * Field Details:
42
+ * +--------+------+----------------+----------+----------------------------------------------+
43
+ * | Offset | Size | Field Name | Type | Description |
44
+ * +--------+------+----------------+----------+----------------------------------------------+
45
+ * | 0 | 1B | TYPE | uint8_t | Identifies the page structure and role. |
46
+ * | 1 | 1B | FLAGS | uint8_t | Flags and reserved attributes for this page. |
47
+ * | 2 | 2B | CELL_COUNT | uint16_t | Number of active records/cells |
48
+ * | 4 | 2B | CONTENT_OFFSET | uint16_t | Byte offset pointing to the start |
49
+ * | 6 | 4B | NEXT_PAGE_ID | uint32_t | Multifunctional 32-bit pointer: |
50
+ * | 10 | 2B | FREE_BYTES | uint16_t | Cumulative count of fragmented |
51
+ * | 12 | 4B | CHECKSUM | uint32_t | IEEE 802.3 CRC32 checksum computed |
52
+ * +--------+------+----------------+----------+----------------------------------------------+
53
+ * | Total: 16 Bytes |
54
+ * +------------------------------------------------------------------------------------------+
55
+ */
56
+ /**
57
+ * Ordered sequence of fields composing the 16-byte header of all standard
58
+ * data and interior pages (pages 2+).
59
+ * Defined as an immutable array of `[fieldName, byteSize]` tuples to guarantee
60
+ * strict byte ordering across all JavaScript/TypeScript runtime engines.
61
+ */
62
+ export declare const SLOTTED_PAGE_HEADER_FIELDS: readonly [readonly ["TYPE", 1], readonly ["FLAGS", 1], readonly ["CELL_COUNT", 2], readonly ["CONTENT_OFFSET", 2], readonly ["NEXT_PAGE_ID", 4], readonly ["FREE_BYTES", 2], readonly ["CHECKSUM", 4]];
63
+ /**
64
+ * Total size in bytes of the standard slotted page header (16 bytes).
65
+ */
66
+ export declare const PAGE_HEADER_SIZE = 16;
67
+ /**
68
+ * Byte offset 0 (uint8_t): Identifies the page structure and role.
69
+ * Valid types:
70
+ * - `0x00` (PAGE_TYPE_FREE): Free/recycled page on the free list.
71
+ * - `0x02` (PAGE_TYPE_INDEX_INTERIOR): B-tree index interior node.
72
+ * - `0x05` (PAGE_TYPE_TABLE_INTERIOR): B-tree table interior routing node.
73
+ * - `0x0A` (PAGE_TYPE_INDEX_LEAF): B-tree index leaf node.
74
+ * - `0x0C` (PAGE_TYPE_CATALOG_PAGE): Dedicated column catalog page.
75
+ * - `0x0D` (PAGE_TYPE_LEAF_DATA): Table leaf data page storing rows.
76
+ */
77
+ export declare const PAGE_HEADER_OFFSET_TYPE = 0;
78
+ /**
79
+ * Byte offset 1 (uint8_t): Flags and reserved attributes for this page.
80
+ * Initialized to `0x00` in v1.
81
+ */
82
+ export declare const PAGE_HEADER_OFFSET_FLAGS = 1;
83
+ /**
84
+ * Byte offset 2 (uint16_t, little-endian): Number of active records/cells
85
+ * stored on this page. Also specifies the count of 2-byte slot directory entries.
86
+ */
87
+ export declare const PAGE_HEADER_OFFSET_CELL_COUNT = 2;
88
+ /**
89
+ * Byte offset 4 (uint16_t, little-endian): Byte offset pointing to the start
90
+ * of the lower cell payload boundary. Payloads are allocated from byte 4096
91
+ * growing upwards toward the slot directory. An empty page has this set to 4096.
92
+ */
93
+ export declare const PAGE_HEADER_OFFSET_CONTENT_OFFSET = 4;
94
+ /**
95
+ * Byte offset 6 (uint32_t, little-endian): Multifunctional 32-bit pointer:
96
+ * - Table Leaf Data (0x0D): Forward sibling pointer (`next_page_id`) linking data pages.
97
+ * - Table Interior (0x05): Rightmost child pointer (`right_child_page_id`).
98
+ * - Free Page (0x00): Next pageId on the free list chain (`next_free_page_id`).
99
+ */
100
+ export declare const PAGE_HEADER_OFFSET_NEXT_PAGE_ID = 6;
101
+ /**
102
+ * Byte offset 10 (uint16_t, little-endian): Cumulative count of fragmented
103
+ * unallocated bytes left behind by deleted or shrunk records. This space is
104
+ * reclaimed when page defragmentation (`page_compact`) is invoked.
105
+ */
106
+ export declare const PAGE_HEADER_OFFSET_FREE_BYTES = 10;
107
+ /**
108
+ * Byte offset 12 (uint32_t, little-endian): IEEE 802.3 CRC32 checksum computed
109
+ * over the entire 4KB page (with bytes 12..15 zeroed during calculation) to detect
110
+ * torn writes or on-disk storage corruption.
111
+ */
112
+ export declare const PAGE_HEADER_OFFSET_CHECKSUM = 12;
113
+ /**
114
+ * 32-bit Word Byte Layout Grid for TABLE_INTERIOR_CELL:
115
+ * Byte 0 Byte 1 Byte 2 Byte 3
116
+ * +-----------------+-----------------+-----------------+-----------------+
117
+ * | CHILD_PAGE_ID (4B) |
118
+ * +-----------------------------------------------------------------------+
119
+ * | Bytes 4..11 (8B): ROWID (int64_t) |
120
+ * +-----------------------------------------------------------------------+
121
+ *
122
+ * Field Details:
123
+ * +--------+------+---------------+----------+-------------+
124
+ * | Offset | Size | Field Name | Type | Description |
125
+ * +--------+------+---------------+----------+-------------+
126
+ * | 0 | 4B | CHILD_PAGE_ID | uint32_t | |
127
+ * | 4 | 8B | ROWID | int64_t | |
128
+ * +--------+------+---------------+----------+-------------+
129
+ * | Total: 12 Bytes |
130
+ * +--------------------------------------------------------+
131
+ */
132
+ /**
133
+ * Ordered sequence of fields composing a single 12-byte routing cell in a
134
+ * Table Interior B-tree node (`page_type = 0x05`).
135
+ */
136
+ export declare const TABLE_INTERIOR_CELL_FIELDS: readonly [readonly ["CHILD_PAGE_ID", 4], readonly ["ROWID", 8]];
137
+ /**
138
+ * Total size in bytes of a single table interior cell (12 bytes).
139
+ * Composed of a 4-byte child `page_id` and an 8-byte signed `rowid` separator key.
140
+ */
141
+ export declare const TABLE_INTERIOR_CELL_SIZE = 12;
142
+ /**
143
+ * Byte offset 0 within an interior cell (uint32_t, little-endian):
144
+ * The `page_id` of the child subtree containing keys less than or equal to `rowid`.
145
+ */
146
+ export declare const TABLE_INTERIOR_CELL_OFFSET_CHILD_PAGE_ID = 0;
147
+ /**
148
+ * Byte offset 4 within an interior cell (int64_t, little-endian):
149
+ * The separator `rowid` key. Keys $\le \text{rowid}$ route to `child_page_id`;
150
+ * keys $> \text{rowid}$ continue searching to the right.
151
+ */
152
+ export declare const TABLE_INTERIOR_CELL_OFFSET_ROWID = 4;
153
+ /**
154
+ * Maximum number of 12-byte interior cells that can fit inside one 4KB interior page:
155
+ * \lfloor(4096 - 16) / (12 + 2)\rfloor = 291 cells (where 2 is the slot directory entry size).
156
+ */
157
+ export declare const MAX_TABLE_INTERIOR_CELLS = 291;
158
+ /**
159
+ * Median split index for interior page splits. When splitting a full 291-cell
160
+ * interior node, entry 145 is promoted to the parent routing node.
161
+ */
162
+ export declare const TABLE_INTERIOR_SPLIT_INDEX = 145;
163
+ //# sourceMappingURL=page_format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page_format.d.ts","sourceRoot":"","sources":["../../src/layouts/page_format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH,eAAO,MAAM,SAAS,OAAO,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,YAAY,OAAO,CAAC;AAMjC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,wMAQ7B,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAGnC;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,IAAI,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,IAAI,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,KAAK,CAAC;AAM9C;;;;;;;;;;;;;;;;;;GAkBG;AACH;;;GAGG;AACH,eAAO,MAAM,0BAA0B,iEAG7B,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAG3C;;;GAGG;AACH,eAAO,MAAM,wCAAwC,IAAI,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,0BAA0B,MAAM,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * AUTO-GENERATED AT BUILD TIME FROM src/layouts/schemas/pool_format.json
3
+ * DO NOT EDIT MANUALLY. Run 'npm run generate:layouts' to rebuild.
4
+ */
5
+ /**
6
+ * Default cache buffer pool size in bytes (4 MB = 1024 * 4096).
7
+ */
8
+ export declare const DEFAULT_CACHE_SIZE_BYTES = 4194304;
9
+ /**
10
+ * Default number of page cache slots in the buffer pool (1024).
11
+ */
12
+ export declare const DEFAULT_SLOT_COUNT = 1024;
13
+ /**
14
+ * Alias for DEFAULT_SLOT_COUNT (1024).
15
+ */
16
+ export declare const DEFAULT_PAGE_SLOTS = 1024;
17
+ /**
18
+ * Default number of hash table buckets for page-to-slot mapping (2048, load factor <= 50%).
19
+ */
20
+ export declare const DEFAULT_PAGE_TO_SLOT_BUCKETS = 2048;
21
+ /**
22
+ * Size in bytes of each hash table bucket (uint32 page_id + uint32 slot_idx = 8 bytes).
23
+ */
24
+ export declare const PAGE_TO_SLOT_BUCKET_SIZE = 8;
25
+ /**
26
+ * Total size in bytes of the page-to-slot hash table (2048 * 8 = 16 KB).
27
+ */
28
+ export declare const PAGE_TO_SLOT_SIZE = 16384;
29
+ /**
30
+ * Size in bytes allocated for VM execution context state (12 KB).
31
+ */
32
+ export declare const VM_CONTEXT_SIZE = 12288;
33
+ /**
34
+ * Size in bytes allocated for SQL result row serialization buffer (64 KB).
35
+ */
36
+ export declare const RESULT_BUFFER_SIZE = 65536;
37
+ /**
38
+ * Size in bytes allocated for compiled query bytecode instructions (32 KB).
39
+ */
40
+ export declare const BYTECODE_SIZE = 32768;
41
+ /**
42
+ * Size in bytes allocated for temporary single-page staging / decompression (4 KB).
43
+ */
44
+ export declare const PAGE_SCRATCHPAD_SIZE = 4096;
45
+ /**
46
+ * Padding bytes to align transient execution arena at boundary 0x430000 (61,312 bytes).
47
+ */
48
+ export declare const ALIGNMENT_PADDING_SIZE = 61312;
49
+ /**
50
+ * Maximum memory limit in bytes for transient query execution arena (16 MB).
51
+ */
52
+ export declare const DEFAULT_MAX_QUERY_MEMORY = 16777216;
53
+ /**
54
+ * Shared Memory Architecture Map (1024 Slots / 4MB Cache Default):
55
+ * +----------------------+--------+-------------------+------------------------------------------------+
56
+ * | Memory Address Range | Size | Region Name | Description |
57
+ * +----------------------+--------+-------------------+------------------------------------------------+
58
+ * | 0x400000..0x400FFF | 4096B | SLOT_TO_PAGE | Array of 1024 uint32 pageIds mapping slot -... |
59
+ * | 0x401000..0x404FFF | 16384B | PAGE_TO_SLOT | Open-addressing hash table (2048 buckets x ... |
60
+ * | 0x405000..0x40507F | 128B | DIRTY_MASK | Bitmask (128 bytes = 1024 bits) tracking di... |
61
+ * | 0x405080..0x40807F | 12288B | VM_CONTEXT | Execution context frames for the SQL VM. |
62
+ * | 0x408080..0x41807F | 65536B | RESULT_BUFFER | Output buffer for query result rows. |
63
+ * | 0x418080..0x42007F | 32768B | BYTECODE | Instruction buffer for compiled bytecode ro... |
64
+ * | 0x420080..0x42107F | 4096B | PAGE_SCRATCHPAD | Staging buffer for page compression or I/O ... |
65
+ * | 0x421080..0x42FFFF | 61312B | ALIGNMENT_PADDING | Padding aligning transient arena to 0x430000. |
66
+ * +----------------------+--------+-------------------+------------------------------------------------+
67
+ * | Arena Start: 0x430000 | Total Regions: 196608 Bytes |
68
+ * +----------------------------------------------------------------------------------------------------+
69
+ */
70
+ export declare const DEFAULT_BUFFER_POOL_REGIONS: readonly [readonly ["SLOT_TO_PAGE", 4096], readonly ["PAGE_TO_SLOT", 16384], readonly ["DIRTY_MASK", 128], readonly ["VM_CONTEXT", 12288], readonly ["RESULT_BUFFER", 65536], readonly ["BYTECODE", 32768], readonly ["PAGE_SCRATCHPAD", 4096], readonly ["ALIGNMENT_PADDING", 61312]];
71
+ /**
72
+ * Byte offset 0x400000: Array of 1024 uint32 pageIds mapping slot -> pageId.
73
+ */
74
+ export declare const SLOT_TO_PAGE_OFFSET = 4194304;
75
+ /**
76
+ * Byte offset 0x401000: Open-addressing hash table (2048 buckets x 8B) mapping pageId -> slot.
77
+ */
78
+ export declare const PAGE_TO_SLOT_OFFSET = 4198400;
79
+ /**
80
+ * Byte offset 0x405000: Bitmask (128 bytes = 1024 bits) tracking dirty slots.
81
+ */
82
+ export declare const DIRTY_MASK_OFFSET = 4214784;
83
+ /**
84
+ * Byte offset 0x405080: Execution context frames for the SQL VM.
85
+ */
86
+ export declare const VM_CONTEXT_OFFSET = 4214912;
87
+ /**
88
+ * Byte offset 0x408080: Output buffer for query result rows.
89
+ */
90
+ export declare const RESULT_BUFFER_OFFSET = 4227200;
91
+ /**
92
+ * Byte offset 0x418080: Instruction buffer for compiled bytecode routines.
93
+ */
94
+ export declare const BYTECODE_OFFSET = 4292736;
95
+ /**
96
+ * Byte offset 0x420080: Staging buffer for page compression or I/O reassembly.
97
+ */
98
+ export declare const PAGE_SCRATCHPAD_OFFSET = 4325504;
99
+ /**
100
+ * Byte offset 0x421080: Padding aligning transient arena to 0x430000.
101
+ */
102
+ export declare const ALIGNMENT_PADDING_OFFSET = 4329600;
103
+ /**
104
+ * Byte offset 0x430000: Start of dynamic transient query execution arena.
105
+ */
106
+ export declare const TRANSIENT_ARENA_OFFSET = 4390912;
107
+ /**
108
+ * Total buffer pool and shared Wasm memory allocation in bytes (20.1875 MB).
109
+ */
110
+ export declare const TOTAL_MEMORY_BYTES = 21168128;
111
+ /**
112
+ * Computes memory layout offsets for arbitrary slot counts.
113
+ */
114
+ export declare function computeBufferPoolOffsets(slotCount: number, _maxQueryMemory?: number): {
115
+ slotsEndOffset: number;
116
+ slotToPageOffset: number;
117
+ pageToSlotOffset: number;
118
+ pageToSlotBuckets: number;
119
+ dirtyMaskOffset: number;
120
+ vmContextOffset: number;
121
+ resultBufferOffset: number;
122
+ bytecodeOffset: number;
123
+ pageScratchpadOffset: number;
124
+ transientArenaOffset: number;
125
+ };
126
+ //# sourceMappingURL=pool_format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool_format.d.ts","sourceRoot":"","sources":["../../src/layouts/pool_format.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;GAEG;A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