@konstit/dne 0.0.2 → 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.
Files changed (62) hide show
  1. package/README.md +87 -159
  2. package/data/dne.bin +0 -0
  3. package/dist/bairro-runs.d.ts +20 -0
  4. package/dist/bairro-runs.js +202 -0
  5. package/dist/bairro-runs.js.map +1 -0
  6. package/dist/bairro.d.ts +27 -0
  7. package/dist/bairro.js +9 -0
  8. package/dist/bairro.js.map +1 -0
  9. package/dist/binary-db-errors.d.ts +56 -0
  10. package/dist/binary-db-errors.js +68 -0
  11. package/dist/binary-db-errors.js.map +1 -0
  12. package/dist/binary-db-format.d.ts +200 -0
  13. package/dist/binary-db-format.js +258 -0
  14. package/dist/binary-db-format.js.map +1 -0
  15. package/dist/binary-db-integrity.d.ts +4 -0
  16. package/dist/binary-db-integrity.js +20 -0
  17. package/dist/binary-db-integrity.js.map +1 -0
  18. package/dist/binary-db-reader.d.ts +126 -0
  19. package/dist/binary-db-reader.js +556 -0
  20. package/dist/binary-db-reader.js.map +1 -0
  21. package/dist/binary-db-validator.d.ts +13 -0
  22. package/dist/binary-db-validator.js +712 -0
  23. package/dist/binary-db-validator.js.map +1 -0
  24. package/dist/cep.d.ts +50 -0
  25. package/dist/cep.js +184 -0
  26. package/dist/cep.js.map +1 -0
  27. package/dist/errors.d.ts +14 -0
  28. package/dist/errors.js +21 -0
  29. package/dist/errors.js.map +1 -0
  30. package/dist/fsst.d.ts +18 -0
  31. package/dist/fsst.js +117 -0
  32. package/dist/fsst.js.map +1 -0
  33. package/dist/index.js +55 -33
  34. package/dist/index.js.map +36 -16
  35. package/dist/library.d.ts +10 -0
  36. package/dist/library.js +8 -0
  37. package/dist/library.js.map +1 -0
  38. package/dist/locality-runs.d.ts +18 -0
  39. package/dist/locality-runs.js +108 -0
  40. package/dist/locality-runs.js.map +1 -0
  41. package/dist/packed-bits.d.ts +6 -0
  42. package/dist/packed-bits.js +41 -0
  43. package/dist/packed-bits.js.map +1 -0
  44. package/dist/schema.d.ts +88 -0
  45. package/dist/schema.js +233 -0
  46. package/dist/schema.js.map +1 -0
  47. package/dist/settings.d.ts +34 -0
  48. package/dist/settings.js +35 -0
  49. package/dist/settings.js.map +1 -0
  50. package/dist/sqlite-db-errors.d.ts +40 -0
  51. package/dist/sqlite-db-errors.js +54 -0
  52. package/dist/sqlite-db-errors.js.map +1 -0
  53. package/dist/sqlite-db-reader.d.ts +130 -0
  54. package/dist/sqlite-db-reader.js +307 -0
  55. package/dist/sqlite-db-reader.js.map +1 -0
  56. package/dist/sqlite-db-schema.d.ts +49 -0
  57. package/dist/sqlite-db-schema.js +115 -0
  58. package/dist/sqlite-db-schema.js.map +1 -0
  59. package/dist/types.d.ts +90 -0
  60. package/dist/types.js +49 -0
  61. package/dist/types.js.map +1 -0
  62. package/package.json +18 -5
@@ -0,0 +1,56 @@
1
+ /** Stable categories exposed by the binary database reader for programmatic error handling. */
2
+ export type DneBinaryDatabaseErrorCode = 'IO_ERROR' | 'INVALID_FORMAT' | 'UNSUPPORTED_VERSION' | 'READER_CLOSED';
3
+ /** Base class for all errors exposed by the binary database reader and its file helpers. */
4
+ export declare abstract class DneBinaryDatabaseError extends Error {
5
+ /** Identifies the failure category without requiring callers to parse the message. */
6
+ abstract readonly code: DneBinaryDatabaseErrorCode;
7
+ /**
8
+ * Initializes a reader error and preserves an underlying failure in `cause` when provided.
9
+ * @param message - Human-readable diagnostic information.
10
+ * @param options - Standard error options, including the original cause.
11
+ */
12
+ protected constructor(message: string, options?: ErrorOptions);
13
+ }
14
+ /** The database file could not be opened, mapped, or read. Inspect `cause` for the operating-system error. */
15
+ export declare class DneBinaryDatabaseIOError extends DneBinaryDatabaseError {
16
+ readonly path: string;
17
+ /** Identifies a failure to access the database file. */
18
+ readonly code = "IO_ERROR";
19
+ /**
20
+ * Creates an access error for a database path.
21
+ * @param path - Path supplied by the caller, without normalization.
22
+ * @param options - Error options containing the original file-system failure.
23
+ */
24
+ constructor(path: string, options?: ErrorOptions);
25
+ }
26
+ /** The file or a decoded record violates the supported binary format. */
27
+ export declare class DneBinaryDatabaseFormatError extends DneBinaryDatabaseError {
28
+ /** Identifies invalid headers, sections, metadata, or record contents. */
29
+ readonly code = "INVALID_FORMAT";
30
+ /**
31
+ * Creates a validation or decoding error.
32
+ * @param message - Description of the invalid structure or failed decoding operation.
33
+ * @param options - Error options containing a native decoding error, when applicable.
34
+ */
35
+ constructor(message: string, options?: ErrorOptions);
36
+ }
37
+ /** The file declares a binary format version that this reader does not support. */
38
+ export declare class DneBinaryDatabaseVersionError extends DneBinaryDatabaseError {
39
+ readonly actualVersion: number;
40
+ readonly supportedVersion: number;
41
+ /** Identifies a format-version mismatch that requires a compatible reader or a rebuilt file. */
42
+ readonly code = "UNSUPPORTED_VERSION";
43
+ /**
44
+ * Creates a version mismatch error.
45
+ * @param actualVersion - Version declared in the file header.
46
+ * @param supportedVersion - Version accepted by this reader.
47
+ */
48
+ constructor(actualVersion: number, supportedVersion: number);
49
+ }
50
+ /** A lookup was attempted after the reader released its mapping references. */
51
+ export declare class DneBinaryDatabaseClosedError extends DneBinaryDatabaseError {
52
+ /** Identifies use of a reader after `close()`. */
53
+ readonly code = "READER_CLOSED";
54
+ /** Creates an error for a lookup attempted after `close()`. */
55
+ constructor();
56
+ }
@@ -0,0 +1,68 @@
1
+ /** Base class for all errors exposed by the binary database reader and its file helpers. */
2
+ export class DneBinaryDatabaseError extends Error {
3
+ /**
4
+ * Initializes a reader error and preserves an underlying failure in `cause` when provided.
5
+ * @param message - Human-readable diagnostic information.
6
+ * @param options - Standard error options, including the original cause.
7
+ */
8
+ constructor(message, options) {
9
+ super(message, options);
10
+ this.name = new.target.name;
11
+ }
12
+ }
13
+ /** The database file could not be opened, mapped, or read. Inspect `cause` for the operating-system error. */
14
+ export class DneBinaryDatabaseIOError extends DneBinaryDatabaseError {
15
+ path;
16
+ /** Identifies a failure to access the database file. */
17
+ code = 'IO_ERROR';
18
+ /**
19
+ * Creates an access error for a database path.
20
+ * @param path - Path supplied by the caller, without normalization.
21
+ * @param options - Error options containing the original file-system failure.
22
+ */
23
+ constructor(path, options) {
24
+ super(`Unable to read binary database: ${path}`, options);
25
+ this.path = path;
26
+ }
27
+ }
28
+ /** The file or a decoded record violates the supported binary format. */
29
+ export class DneBinaryDatabaseFormatError extends DneBinaryDatabaseError {
30
+ /** Identifies invalid headers, sections, metadata, or record contents. */
31
+ code = 'INVALID_FORMAT';
32
+ /**
33
+ * Creates a validation or decoding error.
34
+ * @param message - Description of the invalid structure or failed decoding operation.
35
+ * @param options - Error options containing a native decoding error, when applicable.
36
+ */
37
+ // biome-ignore lint/complexity/noUselessConstructor: Exposes and documents the protected base constructor as a public API.
38
+ constructor(message, options) {
39
+ super(message, options);
40
+ }
41
+ }
42
+ /** The file declares a binary format version that this reader does not support. */
43
+ export class DneBinaryDatabaseVersionError extends DneBinaryDatabaseError {
44
+ actualVersion;
45
+ supportedVersion;
46
+ /** Identifies a format-version mismatch that requires a compatible reader or a rebuilt file. */
47
+ code = 'UNSUPPORTED_VERSION';
48
+ /**
49
+ * Creates a version mismatch error.
50
+ * @param actualVersion - Version declared in the file header.
51
+ * @param supportedVersion - Version accepted by this reader.
52
+ */
53
+ constructor(actualVersion, supportedVersion) {
54
+ super(`Unsupported binary database version: ${actualVersion}. Rebuild the database with build --force.`);
55
+ this.actualVersion = actualVersion;
56
+ this.supportedVersion = supportedVersion;
57
+ }
58
+ }
59
+ /** A lookup was attempted after the reader released its mapping references. */
60
+ export class DneBinaryDatabaseClosedError extends DneBinaryDatabaseError {
61
+ /** Identifies use of a reader after `close()`. */
62
+ code = 'READER_CLOSED';
63
+ /** Creates an error for a lookup attempted after `close()`. */
64
+ constructor() {
65
+ super('Binary database is closed');
66
+ }
67
+ }
68
+ //# sourceMappingURL=binary-db-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-db-errors.js","sourceRoot":"","sources":["../src/binary-db-errors.ts"],"names":[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F"}
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Binary format revision accepted by the current reader and emitted by the writer.
3
+ */
4
+ export declare const BINARY_DATABASE_VERSION = 5;
5
+ /**
6
+ * Fixed file-header size in bytes, including the section directory and reserved space.
7
+ */
8
+ export declare const BINARY_DATABASE_HEADER_SIZE = 256;
9
+ /** SHA-256 footer covering every preceding byte, including header and alignment padding. */
10
+ export declare const BINARY_DATABASE_CHECKSUM_SIZE = 32;
11
+ /** Neighborhood section header: row count and widths of the original DNE identifiers. */
12
+ export declare const BINARY_BAIRRO_HEADER_SIZE = 16;
13
+ /**
14
+ * Eight-byte signature identifying a DNE binary database, independent of its version.
15
+ */
16
+ export declare const BINARY_DATABASE_MAGIC: Uint8Array<ArrayBuffer>;
17
+ /**
18
+ * Largest integer representable by an unsigned four-byte field.
19
+ */
20
+ export declare const MAX_UINT32 = 4294967295;
21
+ /**
22
+ * Number of possible five-digit CEP prefixes.
23
+ */
24
+ export declare const CEP_PREFIX_COUNT = 100000;
25
+ /**
26
+ * Number of CEP prefix offsets, including the final row-count sentinel.
27
+ */
28
+ export declare const CEP_PREFIX_OFFSETS_COUNT: number;
29
+ /**
30
+ * Number of bits used to store each three-digit CEP suffix.
31
+ */
32
+ export declare const CEP_SUFFIX_BITS = 10;
33
+ /**
34
+ * Size in bytes of a front-coded string dictionary header.
35
+ */
36
+ export declare const DICTIONARY_HEADER_SIZE = 32;
37
+ /** Dictionary codec identifiers stored at byte 30 of each dictionary header. */
38
+ export declare const DICTIONARY_CODEC_PLAIN = 0;
39
+ export declare const DICTIONARY_CODEC_FSST = 2;
40
+ /** FSST uses 255 symbols of up to eight bytes; code 255 escapes one literal byte. */
41
+ export declare const FSST_SYMBOL_COUNT = 255;
42
+ export declare const FSST_SYMBOL_TABLE_SIZE: number;
43
+ /**
44
+ * Base-two logarithm of the number of strings in one dictionary block.
45
+ */
46
+ export declare const DICTIONARY_BLOCK_SHIFT = 3;
47
+ /**
48
+ * Number of strings decoded from a shared front-coding block.
49
+ */
50
+ export declare const DICTIONARY_BLOCK_SIZE: number;
51
+ /**
52
+ * Base-two logarithm of the row count covered by one sparse-rank block.
53
+ */
54
+ export declare const SPARSE_RANK_SHIFT = 8;
55
+ /**
56
+ * Number of rows covered by a sparse-rank index entry.
57
+ */
58
+ export declare const SPARSE_RANK_ROWS: number;
59
+ /**
60
+ * Absolute byte offset of the section directory within the file header.
61
+ */
62
+ export declare const SECTION_TABLE_OFFSET = 32;
63
+ /**
64
+ * Canonical section order used by the binary header directory and file writer.
65
+ */
66
+ export declare const BINARY_SECTION_NAMES: readonly ["metadata", "cepPrefixOffsets", "cepSuffixes", "logradouroIds", "complementoBitmap", "complementoRanks", "complementoIds", "bairroIds", "municipalityIds", "nomeBitmap", "nomeRanks", "nomeIds", "municipalities", "logradouroDictionary", "complementoDictionary", "bairroDictionary", "municipioDictionary", "ufDictionary", "nomeDictionary", "localidadeFlags", "bairros", "bairroFaixaOffsets", "bairroFaixas", "bairroAbreviadoDictionary", "localidadeNomeBitmap", "localidadeNomeRanks", "localidadeNomeIds"];
67
+ /**
68
+ * Name of one section in the current binary file format.
69
+ */
70
+ export type BinarySectionName = (typeof BINARY_SECTION_NAMES)[number];
71
+ /**
72
+ * Supported byte widths for a packed unsigned integer.
73
+ */
74
+ export type ByteWidth = 1 | 2 | 3 | 4;
75
+ /**
76
+ * Byte range occupied by a section in the binary database.
77
+ */
78
+ export type BinaryRegion = {
79
+ /**
80
+ * Section length in bytes, excluding alignment padding.
81
+ */
82
+ length: number;
83
+ /**
84
+ * Absolute byte offset from the beginning of the file.
85
+ */
86
+ offset: number;
87
+ };
88
+ /**
89
+ * Decoded binary header, with section ranges expressed as absolute byte offsets.
90
+ */
91
+ export type BinaryHeader = {
92
+ /**
93
+ * Byte width of each row offset in the CEP prefix directory.
94
+ */
95
+ cepPrefixOffsetWidth: ByteWidth;
96
+ /**
97
+ * Total file length in bytes, including final alignment padding.
98
+ */
99
+ fileSize: number;
100
+ /**
101
+ * Number of records in the municipality table.
102
+ */
103
+ municipalityCount: number;
104
+ /**
105
+ * Byte width of municipality IDs in the locality runs.
106
+ */
107
+ municipalityIdWidth: ByteWidth;
108
+ /**
109
+ * Number of CEP records across all row-oriented columns.
110
+ */
111
+ rowCount: number;
112
+ /**
113
+ * Location and size of each required section.
114
+ */
115
+ sections: Record<BinarySectionName, BinaryRegion>;
116
+ };
117
+ /**
118
+ * Rounds a nonnegative byte offset up to the next eight-byte boundary.
119
+ * @param value - Byte offset or length to align.
120
+ * @returns An aligned offset greater than or equal to the input.
121
+ */
122
+ export declare function alignBinaryOffset(value: number): number;
123
+ /**
124
+ * Computes storage for one presence bit per row.
125
+ * @param rowCount - Nonnegative number of rows.
126
+ * @returns The minimum whole-byte length of the bitmap.
127
+ */
128
+ export declare function bitmapByteLength(rowCount: number): number;
129
+ /**
130
+ * Computes storage for a column of fixed-width bit-packed values.
131
+ * @param count - Nonnegative number of values.
132
+ * @param bits - Positive bit width of each value.
133
+ * @returns The minimum whole-byte length of the packed column.
134
+ */
135
+ export declare function packedBitLength(count: number, bits: number): number;
136
+ /**
137
+ * Builds the lookup table used to count set bits in each possible byte.
138
+ * @returns A new 256-entry array whose entry i is the population count of i.
139
+ */
140
+ export declare function createPopcountTable(): Uint8Array<ArrayBuffer>;
141
+ /**
142
+ * Chooses the smallest supported byte width for a nonnegative unsigned integer.
143
+ * @param maxValue - Maximum value to store; callers must ensure it fits in four bytes.
144
+ * @returns A width from one through four bytes.
145
+ */
146
+ export declare function integerByteWidth(maxValue: number): ByteWidth;
147
+ /**
148
+ * Validates a byte-width value decoded from a binary header.
149
+ * @param value - Encoded width.
150
+ * @param name - Field name included in diagnostics.
151
+ * @returns The validated width.
152
+ * @throws {Error} If the width is not 1, 2, 3, or 4.
153
+ */
154
+ export declare function readByteWidth(value: number, name: string): ByteWidth;
155
+ /**
156
+ * Returns the largest unsigned integer representable by a supported width.
157
+ * @param width - Storage width in bytes.
158
+ * @returns The inclusive maximum value for that width.
159
+ */
160
+ export declare function maxPackedInteger(width: ByteWidth): number;
161
+ /**
162
+ * Validates an integer before writing it to a packed column.
163
+ * @param value - Candidate unsigned integer.
164
+ * @param width - Available storage in bytes.
165
+ * @param name - Field name included in diagnostics.
166
+ * @throws {Error} If the value is negative, unsafe, fractional, or too large for the width.
167
+ */
168
+ export declare function assertPackedInteger(value: number, width: ByteWidth, name: string): void;
169
+ /**
170
+ * Reads one little-endian unsigned integer from a data view.
171
+ * @param data - View over the binary bytes.
172
+ * @param offset - Byte offset relative to the view.
173
+ * @param width - Number of bytes to read.
174
+ * @returns The decoded unsigned integer.
175
+ * @throws {RangeError} If the requested bytes lie outside the view.
176
+ */
177
+ export declare function readPackedInteger(data: DataView, offset: number, width: ByteWidth): number;
178
+ /**
179
+ * Writes a little-endian unsigned integer to a caller-owned byte array.
180
+ * @param target - Destination with room for the complete value.
181
+ * @param offset - Starting byte offset within the destination.
182
+ * @param value - Unsigned integer to encode.
183
+ * @param width - Storage width in bytes.
184
+ * @throws {Error} If the value does not fit the requested width. The caller must validate destination bounds.
185
+ */
186
+ export declare function writePackedInteger(target: Uint8Array, offset: number, value: number, width: ByteWidth): void;
187
+ /**
188
+ * Compares a byte sequence to the complete binary file signature.
189
+ * @param bytes - Candidate signature; its length must exactly match the magic length.
190
+ * @returns True only for an exact signature match.
191
+ */
192
+ export declare function hasBinaryMagic(bytes: Uint8Array): boolean;
193
+ /**
194
+ * Writes a ten-bit CEP suffix into a packed column.
195
+ * @param target - Destination bytes sized for the full packed column.
196
+ * @param index - Zero-based value index within the column.
197
+ * @param value - Unsigned integer smaller than 1024.
198
+ * @throws {Error} If the value exceeds the ten-bit range.
199
+ */
200
+ export declare function writePacked10(target: Uint8Array, index: number, value: number): void;
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Binary format revision accepted by the current reader and emitted by the writer.
3
+ */
4
+ export const BINARY_DATABASE_VERSION = 5;
5
+ /**
6
+ * Fixed file-header size in bytes, including the section directory and reserved space.
7
+ */
8
+ export const BINARY_DATABASE_HEADER_SIZE = 256;
9
+ /** SHA-256 footer covering every preceding byte, including header and alignment padding. */
10
+ export const BINARY_DATABASE_CHECKSUM_SIZE = 32;
11
+ /** Neighborhood section header: row count and widths of the original DNE identifiers. */
12
+ export const BINARY_BAIRRO_HEADER_SIZE = 16;
13
+ /**
14
+ * Eight-byte signature identifying a DNE binary database, independent of its version.
15
+ */
16
+ export const BINARY_DATABASE_MAGIC = Uint8Array.from([68, 78, 69, 66, 73, 78, 0, 0]); // DNEBIN\0\0
17
+ /**
18
+ * Largest integer representable by an unsigned four-byte field.
19
+ */
20
+ export const MAX_UINT32 = 0xffff_ffff;
21
+ /**
22
+ * Number of possible five-digit CEP prefixes.
23
+ */
24
+ export const CEP_PREFIX_COUNT = 100_000;
25
+ /**
26
+ * Number of CEP prefix offsets, including the final row-count sentinel.
27
+ */
28
+ export const CEP_PREFIX_OFFSETS_COUNT = CEP_PREFIX_COUNT + 1;
29
+ /**
30
+ * Number of bits used to store each three-digit CEP suffix.
31
+ */
32
+ export const CEP_SUFFIX_BITS = 10;
33
+ /**
34
+ * Size in bytes of a front-coded string dictionary header.
35
+ */
36
+ export const DICTIONARY_HEADER_SIZE = 32;
37
+ /** Dictionary codec identifiers stored at byte 30 of each dictionary header. */
38
+ export const DICTIONARY_CODEC_PLAIN = 0;
39
+ export const DICTIONARY_CODEC_FSST = 2;
40
+ /** FSST uses 255 symbols of up to eight bytes; code 255 escapes one literal byte. */
41
+ export const FSST_SYMBOL_COUNT = 255;
42
+ export const FSST_SYMBOL_TABLE_SIZE = FSST_SYMBOL_COUNT * 9;
43
+ /**
44
+ * Base-two logarithm of the number of strings in one dictionary block.
45
+ */
46
+ export const DICTIONARY_BLOCK_SHIFT = 3;
47
+ /**
48
+ * Number of strings decoded from a shared front-coding block.
49
+ */
50
+ export const DICTIONARY_BLOCK_SIZE = 1 << DICTIONARY_BLOCK_SHIFT;
51
+ /**
52
+ * Base-two logarithm of the row count covered by one sparse-rank block.
53
+ */
54
+ export const SPARSE_RANK_SHIFT = 8;
55
+ /**
56
+ * Number of rows covered by a sparse-rank index entry.
57
+ */
58
+ export const SPARSE_RANK_ROWS = 1 << SPARSE_RANK_SHIFT;
59
+ /**
60
+ * Absolute byte offset of the section directory within the file header.
61
+ */
62
+ export const SECTION_TABLE_OFFSET = 32;
63
+ /**
64
+ * Canonical section order used by the binary header directory and file writer.
65
+ */
66
+ export const BINARY_SECTION_NAMES = [
67
+ 'metadata',
68
+ 'cepPrefixOffsets',
69
+ 'cepSuffixes',
70
+ 'logradouroIds',
71
+ 'complementoBitmap',
72
+ 'complementoRanks',
73
+ 'complementoIds',
74
+ 'bairroIds',
75
+ 'municipalityIds',
76
+ 'nomeBitmap',
77
+ 'nomeRanks',
78
+ 'nomeIds',
79
+ 'municipalities',
80
+ 'logradouroDictionary',
81
+ 'complementoDictionary',
82
+ 'bairroDictionary',
83
+ 'municipioDictionary',
84
+ 'ufDictionary',
85
+ 'nomeDictionary',
86
+ 'localidadeFlags',
87
+ 'bairros',
88
+ 'bairroFaixaOffsets',
89
+ 'bairroFaixas',
90
+ 'bairroAbreviadoDictionary',
91
+ 'localidadeNomeBitmap',
92
+ 'localidadeNomeRanks',
93
+ 'localidadeNomeIds',
94
+ ];
95
+ /**
96
+ * Rounds a nonnegative byte offset up to the next eight-byte boundary.
97
+ * @param value - Byte offset or length to align.
98
+ * @returns An aligned offset greater than or equal to the input.
99
+ */
100
+ export function alignBinaryOffset(value) {
101
+ return Math.ceil(value / 8) * 8;
102
+ }
103
+ /**
104
+ * Computes storage for one presence bit per row.
105
+ * @param rowCount - Nonnegative number of rows.
106
+ * @returns The minimum whole-byte length of the bitmap.
107
+ */
108
+ export function bitmapByteLength(rowCount) {
109
+ return Math.ceil(rowCount / 8);
110
+ }
111
+ /**
112
+ * Computes storage for a column of fixed-width bit-packed values.
113
+ * @param count - Nonnegative number of values.
114
+ * @param bits - Positive bit width of each value.
115
+ * @returns The minimum whole-byte length of the packed column.
116
+ */
117
+ export function packedBitLength(count, bits) {
118
+ return Math.ceil(count * bits / 8);
119
+ }
120
+ /**
121
+ * Builds the lookup table used to count set bits in each possible byte.
122
+ * @returns A new 256-entry array whose entry i is the population count of i.
123
+ */
124
+ export function createPopcountTable() {
125
+ const table = new Uint8Array(256);
126
+ for (let value = 1; value < table.length; value++) {
127
+ table[value] = (table[value >>> 1] ?? 0) + (value & 1);
128
+ }
129
+ return table;
130
+ }
131
+ /**
132
+ * Chooses the smallest supported byte width for a nonnegative unsigned integer.
133
+ * @param maxValue - Maximum value to store; callers must ensure it fits in four bytes.
134
+ * @returns A width from one through four bytes.
135
+ */
136
+ export function integerByteWidth(maxValue) {
137
+ if (maxValue <= 0xff) {
138
+ return 1;
139
+ }
140
+ if (maxValue <= 0xffff) {
141
+ return 2;
142
+ }
143
+ if (maxValue <= 0xffffff) {
144
+ return 3;
145
+ }
146
+ return 4;
147
+ }
148
+ /**
149
+ * Validates a byte-width value decoded from a binary header.
150
+ * @param value - Encoded width.
151
+ * @param name - Field name included in diagnostics.
152
+ * @returns The validated width.
153
+ * @throws {Error} If the width is not 1, 2, 3, or 4.
154
+ */
155
+ export function readByteWidth(value, name) {
156
+ if (value !== 1 && value !== 2 && value !== 3 && value !== 4) {
157
+ throw new Error(`Unsupported binary ${name} width: ${value}`);
158
+ }
159
+ return value;
160
+ }
161
+ /**
162
+ * Returns the largest unsigned integer representable by a supported width.
163
+ * @param width - Storage width in bytes.
164
+ * @returns The inclusive maximum value for that width.
165
+ */
166
+ export function maxPackedInteger(width) {
167
+ return width === 4 ? MAX_UINT32 : (2 ** (width * 8)) - 1;
168
+ }
169
+ /**
170
+ * Validates an integer before writing it to a packed column.
171
+ * @param value - Candidate unsigned integer.
172
+ * @param width - Available storage in bytes.
173
+ * @param name - Field name included in diagnostics.
174
+ * @throws {Error} If the value is negative, unsafe, fractional, or too large for the width.
175
+ */
176
+ export function assertPackedInteger(value, width, name) {
177
+ if (!Number.isSafeInteger(value) || value < 0 || value > maxPackedInteger(width)) {
178
+ throw new Error(`Binary ${name} exceeds the ${width}-byte unsigned integer limit: ${value}`);
179
+ }
180
+ }
181
+ /**
182
+ * Reads one little-endian unsigned integer from a data view.
183
+ * @param data - View over the binary bytes.
184
+ * @param offset - Byte offset relative to the view.
185
+ * @param width - Number of bytes to read.
186
+ * @returns The decoded unsigned integer.
187
+ * @throws {RangeError} If the requested bytes lie outside the view.
188
+ */
189
+ export function readPackedInteger(data, offset, width) {
190
+ switch (width) {
191
+ case 1:
192
+ return data.getUint8(offset);
193
+ case 2:
194
+ return data.getUint16(offset, true);
195
+ case 3:
196
+ return data.getUint8(offset)
197
+ | (data.getUint8(offset + 1) << 8)
198
+ | (data.getUint8(offset + 2) << 16);
199
+ case 4:
200
+ return data.getUint32(offset, true);
201
+ }
202
+ }
203
+ /**
204
+ * Writes a little-endian unsigned integer to a caller-owned byte array.
205
+ * @param target - Destination with room for the complete value.
206
+ * @param offset - Starting byte offset within the destination.
207
+ * @param value - Unsigned integer to encode.
208
+ * @param width - Storage width in bytes.
209
+ * @throws {Error} If the value does not fit the requested width. The caller must validate destination bounds.
210
+ */
211
+ export function writePackedInteger(target, offset, value, width) {
212
+ assertPackedInteger(value, width, 'column value');
213
+ target[offset] = value & 0xff;
214
+ if (width > 1) {
215
+ target[offset + 1] = (value >>> 8) & 0xff;
216
+ }
217
+ if (width > 2) {
218
+ target[offset + 2] = (value >>> 16) & 0xff;
219
+ }
220
+ if (width > 3) {
221
+ target[offset + 3] = (value >>> 24) & 0xff;
222
+ }
223
+ }
224
+ /**
225
+ * Compares a byte sequence to the complete binary file signature.
226
+ * @param bytes - Candidate signature; its length must exactly match the magic length.
227
+ * @returns True only for an exact signature match.
228
+ */
229
+ export function hasBinaryMagic(bytes) {
230
+ if (bytes.byteLength !== BINARY_DATABASE_MAGIC.length) {
231
+ return false;
232
+ }
233
+ return BINARY_DATABASE_MAGIC.every((value, index) => bytes[index] === value);
234
+ }
235
+ /**
236
+ * Writes a ten-bit CEP suffix into a packed column.
237
+ * @param target - Destination bytes sized for the full packed column.
238
+ * @param index - Zero-based value index within the column.
239
+ * @param value - Unsigned integer smaller than 1024.
240
+ * @throws {Error} If the value exceeds the ten-bit range.
241
+ */
242
+ export function writePacked10(target, index, value) {
243
+ if (value < 0 || value >= 1 << CEP_SUFFIX_BITS) {
244
+ throw new Error(`CEP suffix exceeds ${CEP_SUFFIX_BITS} bits: ${value}`);
245
+ }
246
+ const bitOffset = index * CEP_SUFFIX_BITS;
247
+ const byteIndex = bitOffset >>> 3;
248
+ const shift = bitOffset & 7;
249
+ const shifted = value << shift;
250
+ target[byteIndex] = (target[byteIndex] ?? 0) | (shifted & 0xff);
251
+ if (byteIndex + 1 < target.byteLength) {
252
+ target[byteIndex + 1] = (target[byteIndex + 1] ?? 0) | ((shifted >>> 8) & 0xff);
253
+ }
254
+ if (byteIndex + 2 < target.byteLength) {
255
+ target[byteIndex + 2] = (target[byteIndex + 2] ?? 0) | ((shifted >>> 16) & 0xff);
256
+ }
257
+ }
258
+ //# sourceMappingURL=binary-db-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-db-format.js","sourceRoot":"","sources":["../src/binary-db-format.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AACzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAC/C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAEhD,yFAAyF;AACzF,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa;AACnG;;GAEG;AACH,MAAM,CAAC,MA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E,KAAa;IAC5E,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,eAAe,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CAAC,sBAAsB,eAAe,UAAU,KAAK,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,SAAS,GAAG,KAAK,GAAG,eAAe,CAAC;IAC1C,MAAM,SAAS,GAAG,SAAS,KAAK,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC;IAC5B,MAAM,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC;IAC/B,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAChE,IAAI,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACtC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACtC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACnF,CAAC;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Fully validates serialized bytes before recording their SHA-256 in the reserved footer. */
2
+ export declare function sealBinaryDatabaseBytes(bytes: Uint8Array): void;
3
+ /** Checks integrity under the trusted producer and immutable file contract. */
4
+ export declare function verifyBinaryDatabaseChecksum(bytes: Uint8Array): void;
@@ -0,0 +1,20 @@
1
+ import { DneBinaryDatabaseFormatError } from "./binary-db-errors.js";
2
+ import { BINARY_DATABASE_CHECKSUM_SIZE } from "./binary-db-format.js";
3
+ import { validateBinaryDatabaseBytes } from "./binary-db-validator.js";
4
+ /** Fully validates serialized bytes before recording their SHA-256 in the reserved footer. */
5
+ export function sealBinaryDatabaseBytes(bytes) {
6
+ validateBinaryDatabaseBytes(bytes);
7
+ const end = bytes.byteLength - BINARY_DATABASE_CHECKSUM_SIZE;
8
+ bytes.set(new Bun.CryptoHasher('sha256').update(bytes.subarray(0, end)).digest(), end);
9
+ }
10
+ /** Checks integrity under the trusted producer and immutable file contract. */
11
+ export function verifyBinaryDatabaseChecksum(bytes) {
12
+ const end = bytes.byteLength - BINARY_DATABASE_CHECKSUM_SIZE;
13
+ const digest = new Bun.CryptoHasher('sha256').update(bytes.subarray(0, end)).digest();
14
+ for (let index = 0; index < BINARY_DATABASE_CHECKSUM_SIZE; index++) {
15
+ if (bytes[end + index] !== digest[index]) {
16
+ throw new DneBinaryDatabaseFormatError('Binary database SHA-256 checksum mismatch');
17
+ }
18
+ }
19
+ }
20
+ //# sourceMappingURL=binary-db-integrity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary-db-integrity.js","sourceRoot":"","sources":["../src/binary-db-integrity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAEvE,8FAA8F;AAC9F,MAAM,UAAU,uBAAuB,CAAC,KAAiB;IACvD,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,GAAG,6BAA6B,CAAC;IAC7D,KAAK,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC;AACzF,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,4BAA4B,CAAC,KAAiB;IAC5D,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,GAAG,6BAA6B,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACtF,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,6BAA6B,EAAE,KAAK,EAAE,EAAE,CAAC;QACnE,IAAI,KAAK,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,MAAM,IAAI,4BAA4B,CAAC,2CAA2C,CAAC,CAAC;QACtF,CAAC;IACH,CAAC;AACH,CAAC"}