@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.
- package/README.md +87 -159
- package/data/dne.bin +0 -0
- package/dist/bairro-runs.d.ts +20 -0
- package/dist/bairro-runs.js +202 -0
- package/dist/bairro-runs.js.map +1 -0
- package/dist/bairro.d.ts +27 -0
- package/dist/bairro.js +9 -0
- package/dist/bairro.js.map +1 -0
- package/dist/binary-db-errors.d.ts +56 -0
- package/dist/binary-db-errors.js +68 -0
- package/dist/binary-db-errors.js.map +1 -0
- package/dist/binary-db-format.d.ts +200 -0
- package/dist/binary-db-format.js +258 -0
- package/dist/binary-db-format.js.map +1 -0
- package/dist/binary-db-integrity.d.ts +4 -0
- package/dist/binary-db-integrity.js +20 -0
- package/dist/binary-db-integrity.js.map +1 -0
- package/dist/binary-db-reader.d.ts +126 -0
- package/dist/binary-db-reader.js +556 -0
- package/dist/binary-db-reader.js.map +1 -0
- package/dist/binary-db-validator.d.ts +13 -0
- package/dist/binary-db-validator.js +712 -0
- package/dist/binary-db-validator.js.map +1 -0
- package/dist/cep.d.ts +50 -0
- package/dist/cep.js +184 -0
- package/dist/cep.js.map +1 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/fsst.d.ts +18 -0
- package/dist/fsst.js +117 -0
- package/dist/fsst.js.map +1 -0
- package/dist/index.js +55 -33
- package/dist/index.js.map +36 -16
- package/dist/library.d.ts +10 -0
- package/dist/library.js +8 -0
- package/dist/library.js.map +1 -0
- package/dist/locality-runs.d.ts +18 -0
- package/dist/locality-runs.js +108 -0
- package/dist/locality-runs.js.map +1 -0
- package/dist/packed-bits.d.ts +6 -0
- package/dist/packed-bits.js +41 -0
- package/dist/packed-bits.js.map +1 -0
- package/dist/schema.d.ts +88 -0
- package/dist/schema.js +233 -0
- package/dist/schema.js.map +1 -0
- package/dist/settings.d.ts +34 -0
- package/dist/settings.js +35 -0
- package/dist/settings.js.map +1 -0
- package/dist/sqlite-db-errors.d.ts +40 -0
- package/dist/sqlite-db-errors.js +54 -0
- package/dist/sqlite-db-errors.js.map +1 -0
- package/dist/sqlite-db-reader.d.ts +130 -0
- package/dist/sqlite-db-reader.js +307 -0
- package/dist/sqlite-db-reader.js.map +1 -0
- package/dist/sqlite-db-schema.d.ts +49 -0
- package/dist/sqlite-db-schema.js +115 -0
- package/dist/sqlite-db-schema.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +49 -0
- package/dist/types.js.map +1 -0
- package/package.json +18 -5
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Public binary reader, format constants, file helpers, errors, and neighborhood types. */
|
|
2
|
+
export * from './binary-db-reader.ts';
|
|
3
|
+
/** SQLite reader and its typed errors. */
|
|
4
|
+
export { DneDatabaseClosedError, DneDatabaseDataError, DneDatabaseError, type DneDatabaseErrorCode, DneDatabaseIOError, DneDatabaseQueryError, DneDatabaseReader, DneDatabaseSchemaError, } from './sqlite-db-reader.ts';
|
|
5
|
+
/** CEP helpers and address records shared by both readers. */
|
|
6
|
+
export { CEP_RANGES, cepToU32, formatCep, normalizeCep, ufForCep } from './cep.ts';
|
|
7
|
+
export type { DneRow, LoadMetadata, UF } from './types.ts';
|
|
8
|
+
export { parseUF } from './types.ts';
|
|
9
|
+
/** Descriptive locality classification and postal coding status returned by CEP lookups. */
|
|
10
|
+
export type { LocalidadeSituacao, LocalidadeTipo } from './schema.ts';
|
package/dist/library.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Public binary reader, format constants, file helpers, errors, and neighborhood types. */
|
|
2
|
+
export * from "./binary-db-reader.js";
|
|
3
|
+
/** SQLite reader and its typed errors. */
|
|
4
|
+
export { DneDatabaseClosedError, DneDatabaseDataError, DneDatabaseError, DneDatabaseIOError, DneDatabaseQueryError, DneDatabaseReader, DneDatabaseSchemaError, } from "./sqlite-db-reader.js";
|
|
5
|
+
/** CEP helpers and address records shared by both readers. */
|
|
6
|
+
export { CEP_RANGES, cepToU32, formatCep, normalizeCep, ufForCep } from "./cep.js";
|
|
7
|
+
export { parseUF } from "./types.js";
|
|
8
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,cAAc,uBAAuB,CAAC;AACtC,0CAA0C;AAC1C,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAEhB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,8DAA8D;AAC9D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEnF,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BinaryRegion, type ByteWidth } from './binary-db-format.ts';
|
|
2
|
+
export type LocalityRuns = {
|
|
3
|
+
count: number;
|
|
4
|
+
directoryOffset: number;
|
|
5
|
+
startsOffset: number;
|
|
6
|
+
idsOffset: number;
|
|
7
|
+
};
|
|
8
|
+
/** Groups consecutive rows with the same municipality and locality indicators. */
|
|
9
|
+
export declare function encodeLocalityRuns(ids: Uint8Array, flags: Uint8Array, width: ByteWidth): {
|
|
10
|
+
ids: Uint8Array<ArrayBuffer>;
|
|
11
|
+
flags: Uint8Array<ArrayBuffer>;
|
|
12
|
+
};
|
|
13
|
+
/** Reads locations after the file has passed integrity verification. */
|
|
14
|
+
export declare function readLocalityRunsLayout(data: DataView, region: BinaryRegion, rows: number): LocalityRuns;
|
|
15
|
+
/** Validates run starts and the directory used to bound each row lookup. */
|
|
16
|
+
export declare function parseLocalityRuns(data: DataView, region: BinaryRegion, rows: number, width: ByteWidth): LocalityRuns;
|
|
17
|
+
/** Returns the run that contains the row; only runs touching its 256-row block are searched. */
|
|
18
|
+
export declare function findLocalityRun(data: DataView, runs: LocalityRuns, row: number): number;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { DneBinaryDatabaseFormatError } from "./binary-db-errors.js";
|
|
2
|
+
import { readPackedInteger, writePackedInteger, } from "./binary-db-format.js";
|
|
3
|
+
const HEADER_BYTES = 8;
|
|
4
|
+
const BLOCK_SHIFT = 8;
|
|
5
|
+
const BLOCK_ROWS = 1 << BLOCK_SHIFT;
|
|
6
|
+
/** Groups consecutive rows with the same municipality and locality indicators. */
|
|
7
|
+
export function encodeLocalityRuns(ids, flags, width) {
|
|
8
|
+
const source = new DataView(ids.buffer, ids.byteOffset, ids.byteLength);
|
|
9
|
+
const starts = [];
|
|
10
|
+
const runIds = [];
|
|
11
|
+
const runFlags = [];
|
|
12
|
+
let previousId = -1;
|
|
13
|
+
let previousFlags = -1;
|
|
14
|
+
for (let row = 0; row < flags.length; row++) {
|
|
15
|
+
const id = readPackedInteger(source, row * width, width);
|
|
16
|
+
const indicators = flags[row] ?? 0;
|
|
17
|
+
if (id !== previousId || indicators !== previousFlags) {
|
|
18
|
+
starts.push(row);
|
|
19
|
+
runIds.push(id);
|
|
20
|
+
runFlags.push(indicators);
|
|
21
|
+
previousId = id;
|
|
22
|
+
previousFlags = indicators;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const count = starts.length;
|
|
26
|
+
const blockCount = Math.ceil(flags.length / BLOCK_ROWS);
|
|
27
|
+
const startsOffset = HEADER_BYTES + (blockCount + 1) * 4;
|
|
28
|
+
const idsOffset = startsOffset + count * 4;
|
|
29
|
+
const bytes = new Uint8Array(idsOffset + count * width);
|
|
30
|
+
const data = new DataView(bytes.buffer);
|
|
31
|
+
data.setUint32(0, count, true);
|
|
32
|
+
data.setUint8(4, BLOCK_SHIFT);
|
|
33
|
+
let run = 0;
|
|
34
|
+
for (let block = 0; block < blockCount; block++) {
|
|
35
|
+
while (run + 1 < count && (starts[run + 1] ?? 0) <= block * BLOCK_ROWS) {
|
|
36
|
+
run++;
|
|
37
|
+
}
|
|
38
|
+
data.setUint32(HEADER_BYTES + block * 4, run, true);
|
|
39
|
+
}
|
|
40
|
+
data.setUint32(HEADER_BYTES + blockCount * 4, count, true);
|
|
41
|
+
for (let index = 0; index < count; index++) {
|
|
42
|
+
data.setUint32(startsOffset + index * 4, starts[index] ?? 0, true);
|
|
43
|
+
writePackedInteger(bytes, idsOffset + index * width, runIds[index] ?? 0, width);
|
|
44
|
+
}
|
|
45
|
+
return { ids: bytes, flags: Uint8Array.from(runFlags) };
|
|
46
|
+
}
|
|
47
|
+
/** Reads locations after the file has passed integrity verification. */
|
|
48
|
+
export function readLocalityRunsLayout(data, region, rows) {
|
|
49
|
+
const count = data.getUint32(region.offset, true);
|
|
50
|
+
const directoryOffset = region.offset + HEADER_BYTES;
|
|
51
|
+
const startsOffset = directoryOffset + (Math.ceil(rows / BLOCK_ROWS) + 1) * 4;
|
|
52
|
+
return { count, directoryOffset, startsOffset, idsOffset: startsOffset + count * 4 };
|
|
53
|
+
}
|
|
54
|
+
/** Validates run starts and the directory used to bound each row lookup. */
|
|
55
|
+
export function parseLocalityRuns(data, region, rows, width) {
|
|
56
|
+
if (region.length < HEADER_BYTES) {
|
|
57
|
+
throw new DneBinaryDatabaseFormatError('Binary locality runs are truncated');
|
|
58
|
+
}
|
|
59
|
+
const count = data.getUint32(region.offset, true);
|
|
60
|
+
if (count === 0 || count > rows || data.getUint32(region.offset + 4, true) !== BLOCK_SHIFT) {
|
|
61
|
+
throw new DneBinaryDatabaseFormatError('Invalid binary locality run header');
|
|
62
|
+
}
|
|
63
|
+
const blockCount = Math.ceil(rows / BLOCK_ROWS);
|
|
64
|
+
const directoryOffset = region.offset + HEADER_BYTES;
|
|
65
|
+
const startsOffset = directoryOffset + (blockCount + 1) * 4;
|
|
66
|
+
const idsOffset = startsOffset + count * 4;
|
|
67
|
+
if (idsOffset + count * width !== region.offset + region.length) {
|
|
68
|
+
throw new DneBinaryDatabaseFormatError('Invalid binary locality run length');
|
|
69
|
+
}
|
|
70
|
+
let previous = -1;
|
|
71
|
+
for (let run = 0; run < count; run++) {
|
|
72
|
+
const start = data.getUint32(startsOffset + run * 4, true);
|
|
73
|
+
if ((run === 0 && start !== 0) || start <= previous || start >= rows) {
|
|
74
|
+
throw new DneBinaryDatabaseFormatError('Invalid binary locality run boundary');
|
|
75
|
+
}
|
|
76
|
+
previous = start;
|
|
77
|
+
}
|
|
78
|
+
let run = 0;
|
|
79
|
+
for (let block = 0; block < blockCount; block++) {
|
|
80
|
+
while (run + 1 < count && data.getUint32(startsOffset + (run + 1) * 4, true) <= block * BLOCK_ROWS) {
|
|
81
|
+
run++;
|
|
82
|
+
}
|
|
83
|
+
if (data.getUint32(directoryOffset + block * 4, true) !== run) {
|
|
84
|
+
throw new DneBinaryDatabaseFormatError('Invalid binary locality run directory');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (data.getUint32(directoryOffset + blockCount * 4, true) !== count) {
|
|
88
|
+
throw new DneBinaryDatabaseFormatError('Invalid binary locality run sentinel');
|
|
89
|
+
}
|
|
90
|
+
return { count, directoryOffset, startsOffset, idsOffset };
|
|
91
|
+
}
|
|
92
|
+
/** Returns the run that contains the row; only runs touching its 256-row block are searched. */
|
|
93
|
+
export function findLocalityRun(data, runs, row) {
|
|
94
|
+
const block = Math.floor(row / BLOCK_ROWS);
|
|
95
|
+
let low = data.getUint32(runs.directoryOffset + block * 4, true);
|
|
96
|
+
let high = Math.min(runs.count, data.getUint32(runs.directoryOffset + (block + 1) * 4, true) + 1);
|
|
97
|
+
while (low + 1 < high) {
|
|
98
|
+
const middle = low + ((high - low) >>> 1);
|
|
99
|
+
if (data.getUint32(runs.startsOffset + middle * 4, true) <= row) {
|
|
100
|
+
low = middle;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
high = middle;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return low;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=locality-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locality-runs.js","sourceRoot":"","sources":["../src/locality-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAGnB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,UAAU,GAAG,CAAC,IAAI,WAAW,CAAC;AASpC,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,GAAe,EAAE,KAAiB,EAAE,KAAgB;IACrF,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;IACxE,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;IACpB,IAAI,aAAa,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;QAC5C,MAAM,EAAE,GAAG,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,EAAE,KAAK,UAAU,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;YACtD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,MAAM,CAAC,IAAI,CAAC,EAAE,C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AE,CAAC;QACtB,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,GAAG,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;YAChE,GAAG,GAAG,MAAM,CAAC;QACf,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Minimum nonzero bit width for a column containing values from zero through maxValue. */
|
|
2
|
+
export declare function integerBitWidth(maxValue: number): number;
|
|
3
|
+
/** Reads one unsigned value without decoding any preceding values. Width must be in 1..32. */
|
|
4
|
+
export declare function readPackedBits(data: DataView, offset: number, index: number, width: number): number;
|
|
5
|
+
/** Writes one unsigned value into a zero-initialized packed column. */
|
|
6
|
+
export declare function writePackedBits(bytes: Uint8Array, index: number, width: number, value: number): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Minimum nonzero bit width for a column containing values from zero through maxValue. */
|
|
2
|
+
export function integerBitWidth(maxValue) {
|
|
3
|
+
return Math.max(1, Math.ceil(Math.log2(maxValue + 1)));
|
|
4
|
+
}
|
|
5
|
+
/** Reads one unsigned value without decoding any preceding values. Width must be in 1..32. */
|
|
6
|
+
export function readPackedBits(data, offset, index, width) {
|
|
7
|
+
const bit = index * width;
|
|
8
|
+
const byte = offset + Math.floor(bit / 8);
|
|
9
|
+
const shift = bit & 7;
|
|
10
|
+
const end = shift + width;
|
|
11
|
+
let value = data.getUint8(byte);
|
|
12
|
+
if (end > 8) {
|
|
13
|
+
value |= data.getUint8(byte + 1) << 8;
|
|
14
|
+
}
|
|
15
|
+
if (end > 16) {
|
|
16
|
+
value |= data.getUint8(byte + 2) << 16;
|
|
17
|
+
}
|
|
18
|
+
if (end > 24) {
|
|
19
|
+
value |= data.getUint8(byte + 3) << 24;
|
|
20
|
+
}
|
|
21
|
+
let result = (value >>> shift) & (0xffff_ffff >>> (32 - width));
|
|
22
|
+
if (end > 32) {
|
|
23
|
+
result += (data.getUint8(byte + 4) & ((1 << (end - 32)) - 1)) * 2 ** (32 - shift);
|
|
24
|
+
}
|
|
25
|
+
return result >>> 0;
|
|
26
|
+
}
|
|
27
|
+
/** Writes one unsigned value into a zero-initialized packed column. */
|
|
28
|
+
export function writePackedBits(bytes, index, width, value) {
|
|
29
|
+
if (!Number.isInteger(value) || value < 0 || value >= 2 ** width || width < 1 || width > 32) {
|
|
30
|
+
throw new Error(`Invalid ${width}-bit column value: ${value}`);
|
|
31
|
+
}
|
|
32
|
+
const bit = index * width;
|
|
33
|
+
const byte = Math.floor(bit / 8);
|
|
34
|
+
const shift = bit & 7;
|
|
35
|
+
const shifted = value * 2 ** shift;
|
|
36
|
+
const count = Math.ceil((shift + width) / 8);
|
|
37
|
+
for (let part = 0; part < count; part++) {
|
|
38
|
+
bytes[byte + part] = (bytes[byte + part] ?? 0) | (Math.floor(shifted / 2 ** (part * 8)) & 255);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=packed-bits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packed-bits.js","sourceRoot":"","sources":["../src/packed-bits.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,MAAM,UAAU,eAAe,CAAC,QAAgB;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,cAAc,CAAC,IAAc,EAAE,MAAc,EAAE,KAAa,EAAE,KAAa;IACzF,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,CAA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S,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QAC5F,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,sBAAsB,KAAK,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,CAAC;IAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC;IACtB,MAAM,OAAO,GAAG,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QACxC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;IACjG,CAAC;AACH,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Logical schema revision recorded in load metadata to invalidate outdated imports. */
|
|
2
|
+
export declare const DATABASE_SCHEMA_VERSION = "4";
|
|
3
|
+
/** DNE locality codes in the order used by the binary format: municipality, district, village. */
|
|
4
|
+
export declare const LOCALIDADE_TIPO_CODIGOS: readonly ["M", "D", "P"];
|
|
5
|
+
/** Original `LOC_IN_TIPO_LOC` values retained in DNE imports and SQLite storage. */
|
|
6
|
+
export type LocalidadeTipoCodigo = (typeof LOCALIDADE_TIPO_CODIGOS)[number];
|
|
7
|
+
/** Original `LOC_IN_SIT` values retained in DNE imports and SQLite storage. */
|
|
8
|
+
export type LocalidadeSituacaoCodigo = 0 | 1 | 2 | 3;
|
|
9
|
+
/** Descriptive locality types in the same order as `LOCALIDADE_TIPO_CODIGOS`. */
|
|
10
|
+
export declare const LOCALIDADE_TIPOS: readonly ["municipio", "distrito", "povoado"];
|
|
11
|
+
/** Descriptive classification of the originating locality returned by CEP lookups. */
|
|
12
|
+
export type LocalidadeTipo = (typeof LOCALIDADE_TIPOS)[number];
|
|
13
|
+
/** Descriptive postal coding statuses indexed by the original `LOC_IN_SIT` code. */
|
|
14
|
+
export declare const LOCALIDADE_SITUACOES: readonly ["sem_codificacao_por_logradouro", "codificada_por_logradouro", "inserida_na_codificacao_por_logradouro", "em_codificacao_por_logradouro"];
|
|
15
|
+
/** Postal coding status of the originating locality returned by CEP lookups. */
|
|
16
|
+
export type LocalidadeSituacao = (typeof LOCALIDADE_SITUACOES)[number];
|
|
17
|
+
/** SQLite column declaration used to generate the unified database schema. */
|
|
18
|
+
export type ColumnDefinition = {
|
|
19
|
+
/** Trusted SQL expression inserted into a CHECK constraint; not user-supplied SQL. */
|
|
20
|
+
check?: string;
|
|
21
|
+
/** SQL comment describing the stored value. */
|
|
22
|
+
comment?: string;
|
|
23
|
+
/** Physical column name, quoted when generating SQL. */
|
|
24
|
+
name: string;
|
|
25
|
+
/** SQLite storage affinity. */
|
|
26
|
+
type: 'TEXT' | 'INTEGER';
|
|
27
|
+
/** Includes the column in the table's primary key and implies NOT NULL. */
|
|
28
|
+
primaryKey?: boolean;
|
|
29
|
+
/** Rejects SQL NULL values when enabled. */
|
|
30
|
+
notNull?: boolean;
|
|
31
|
+
/** Optional foreign key, using a physical table name and its referenced column. */
|
|
32
|
+
references?: {
|
|
33
|
+
table: string;
|
|
34
|
+
column: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** Describes a DNE source file or the generated unified SQLite table. */
|
|
38
|
+
export type TableDefinition = {
|
|
39
|
+
/** Physical table name after applying any caller-provided override. */
|
|
40
|
+
name: string;
|
|
41
|
+
/** Stable logical name used to identify the source and apply overrides. */
|
|
42
|
+
originalName: string;
|
|
43
|
+
/** Output columns; source-only definitions may have an empty array. */
|
|
44
|
+
columns: ColumnDefinition[];
|
|
45
|
+
/** Source filename pattern; null disables file matching and omission derives it from `originalName`. */
|
|
46
|
+
fileGlob?: string | null;
|
|
47
|
+
/** Maps logical source fields to zero-based positions in an @-delimited record. */
|
|
48
|
+
sourceFields?: Readonly<Record<string, number>>;
|
|
49
|
+
/** Marks the generated CEP table, which has no corresponding source file. */
|
|
50
|
+
unifiedTable?: boolean;
|
|
51
|
+
/** Stores a table directly in its primary-key B-tree without a separate rowid. */
|
|
52
|
+
withoutRowid?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/** Maps stable logical table names to caller-selected physical table names. */
|
|
55
|
+
export type TableNameMap = Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates independently mutable source and output schema definitions.
|
|
58
|
+
* @param tableNames - Optional physical-name overrides keyed by the original table name.
|
|
59
|
+
* @returns New table, column, and source-field objects for this invocation.
|
|
60
|
+
*/
|
|
61
|
+
export declare function buildSchema(tableNames?: TableNameMap): TableDefinition[];
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the generated CEP table from a schema.
|
|
64
|
+
* @param schema - Source and output table definitions.
|
|
65
|
+
* @returns The first definition marked as the unified table, without copying it.
|
|
66
|
+
* @throws {Error} If the schema has no unified table.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getUnifiedTable(schema: readonly TableDefinition[]): TableDefinition;
|
|
69
|
+
/**
|
|
70
|
+
* Lists persisted tables in parent-before-child creation and insertion order.
|
|
71
|
+
* @param schema - Source and output table definitions returned by `buildSchema`.
|
|
72
|
+
* @returns Definitions with output columns; source-only definitions are excluded.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getStoredTables(schema: readonly TableDefinition[]): TableDefinition[];
|
|
75
|
+
/**
|
|
76
|
+
* Resolves the source filename pattern for a table.
|
|
77
|
+
* @param table - Source or output table definition.
|
|
78
|
+
* @returns The explicit or derived uppercase TXT pattern, or null for a generated table.
|
|
79
|
+
*/
|
|
80
|
+
export declare function getTableFilesGlob(table: TableDefinition): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Resolves logical source fields to their positions in a delimited record.
|
|
83
|
+
* @param table - Definition containing a source-field mapping.
|
|
84
|
+
* @param fields - Field names in the desired output order.
|
|
85
|
+
* @returns Zero-based indexes in the same order as `fields`.
|
|
86
|
+
* @throws {Error} If the mapping or any requested field is missing.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getSourceFieldIndexes(table: TableDefinition, fields: readonly string[]): number[];
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/** Logical schema revision recorded in load metadata to invalidate outdated imports. */
|
|
2
|
+
export const DATABASE_SCHEMA_VERSION = '4';
|
|
3
|
+
/** DNE locality codes in the order used by the binary format: municipality, district, village. */
|
|
4
|
+
export const LOCALIDADE_TIPO_CODIGOS = ['M', 'D', 'P'];
|
|
5
|
+
/** Descriptive locality types in the same order as `LOCALIDADE_TIPO_CODIGOS`. */
|
|
6
|
+
export const LOCALIDADE_TIPOS = ['municipio', 'distrito', 'povoado'];
|
|
7
|
+
/** Descriptive postal coding statuses indexed by the original `LOC_IN_SIT` code. */
|
|
8
|
+
export const LOCALIDADE_SITUACOES = [
|
|
9
|
+
'sem_codificacao_por_logradouro',
|
|
10
|
+
'codificada_por_logradouro',
|
|
11
|
+
'inserida_na_codificacao_por_logradouro',
|
|
12
|
+
'em_codificacao_por_logradouro',
|
|
13
|
+
];
|
|
14
|
+
const baseTables = [
|
|
15
|
+
{
|
|
16
|
+
name: 'log_localidade',
|
|
17
|
+
originalName: 'log_localidade',
|
|
18
|
+
sourceFields: {
|
|
19
|
+
locNu: 0,
|
|
20
|
+
uf: 1,
|
|
21
|
+
nome: 2,
|
|
22
|
+
cep: 3,
|
|
23
|
+
situacao: 4,
|
|
24
|
+
tipo: 5,
|
|
25
|
+
locNuSub: 6,
|
|
26
|
+
munNu: 8,
|
|
27
|
+
},
|
|
28
|
+
columns: [],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'log_bairro',
|
|
32
|
+
originalName: 'log_bairro',
|
|
33
|
+
sourceFields: {
|
|
34
|
+
baiNu: 0,
|
|
35
|
+
uf: 1,
|
|
36
|
+
locNu: 2,
|
|
37
|
+
bairro: 3,
|
|
38
|
+
abreviado: 4,
|
|
39
|
+
},
|
|
40
|
+
columns: [],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'log_faixa_bairro',
|
|
44
|
+
originalName: 'log_faixa_bairro',
|
|
45
|
+
sourceFields: { baiNu: 0, cepInicial: 1, cepFinal: 2 },
|
|
46
|
+
columns: [],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'log_cpc',
|
|
50
|
+
originalName: 'log_cpc',
|
|
51
|
+
sourceFields: {
|
|
52
|
+
uf: 1,
|
|
53
|
+
locNu: 2,
|
|
54
|
+
nome: 3,
|
|
55
|
+
endereco: 4,
|
|
56
|
+
cep: 5,
|
|
57
|
+
},
|
|
58
|
+
columns: [],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'log_logradouro',
|
|
62
|
+
originalName: 'log_logradouro',
|
|
63
|
+
fileGlob: 'LOG_LOGRADOURO_*.TXT',
|
|
64
|
+
sourceFields: {
|
|
65
|
+
uf: 1,
|
|
66
|
+
locNu: 2,
|
|
67
|
+
baiNuIni: 3,
|
|
68
|
+
logNo: 5,
|
|
69
|
+
cep: 7,
|
|
70
|
+
tloTx: 8,
|
|
71
|
+
logStaTlo: 9,
|
|
72
|
+
},
|
|
73
|
+
columns: [],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'log_grande_usuario',
|
|
77
|
+
originalName: 'log_grande_usuario',
|
|
78
|
+
sourceFields: {
|
|
79
|
+
uf: 1,
|
|
80
|
+
locNu: 2,
|
|
81
|
+
baiNu: 3,
|
|
82
|
+
nome: 5,
|
|
83
|
+
endereco: 6,
|
|
84
|
+
cep: 7,
|
|
85
|
+
},
|
|
86
|
+
columns: [],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'log_unid_oper',
|
|
90
|
+
originalName: 'log_unid_oper',
|
|
91
|
+
sourceFields: {
|
|
92
|
+
uf: 1,
|
|
93
|
+
locNu: 2,
|
|
94
|
+
baiNu: 3,
|
|
95
|
+
nome: 5,
|
|
96
|
+
endereco: 6,
|
|
97
|
+
cep: 7,
|
|
98
|
+
},
|
|
99
|
+
columns: [],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'bairros',
|
|
103
|
+
originalName: 'bairros',
|
|
104
|
+
fileGlob: null,
|
|
105
|
+
columns: [
|
|
106
|
+
{ name: 'bairro_id', type: 'INTEGER', primaryKey: true, check: 'bairro_id > 0' },
|
|
107
|
+
{ name: 'localidade_id', type: 'INTEGER', notNull: true, check: 'localidade_id > 0' },
|
|
108
|
+
{ name: 'uf', type: 'TEXT', notNull: true },
|
|
109
|
+
{ name: 'nome', type: 'TEXT', notNull: true },
|
|
110
|
+
{ name: 'nome_abreviado', type: 'TEXT' },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: 'bairro_faixas',
|
|
115
|
+
originalName: 'bairro_faixas',
|
|
116
|
+
fileGlob: null,
|
|
117
|
+
withoutRowid: true,
|
|
118
|
+
columns: [
|
|
119
|
+
{ name: 'bairro_id', type: 'INTEGER', primaryKey: true, references: { table: 'bairros', column: 'bairro_id' } },
|
|
120
|
+
{
|
|
121
|
+
name: 'cep_inicial',
|
|
122
|
+
type: 'TEXT',
|
|
123
|
+
primaryKey: true,
|
|
124
|
+
check: 'length(cep_inicial) = 8 AND cep_inicial NOT GLOB \'*[^0-9]*\'',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'cep_final',
|
|
128
|
+
type: 'TEXT',
|
|
129
|
+
primaryKey: true,
|
|
130
|
+
check: 'length(cep_final) = 8 AND cep_final NOT GLOB \'*[^0-9]*\' AND cep_inicial <= cep_final',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'cep_unificado',
|
|
136
|
+
originalName: 'cep_unificado',
|
|
137
|
+
fileGlob: null,
|
|
138
|
+
unifiedTable: true,
|
|
139
|
+
columns: [
|
|
140
|
+
{
|
|
141
|
+
name: 'cep',
|
|
142
|
+
type: 'TEXT',
|
|
143
|
+
primaryKey: true,
|
|
144
|
+
comment: 'Contém somente os oito dígitos do CEP, sem separadores.',
|
|
145
|
+
},
|
|
146
|
+
{ name: 'logradouro', type: 'TEXT' },
|
|
147
|
+
{ name: 'complemento', type: 'TEXT' },
|
|
148
|
+
{ name: 'bairro_id', type: 'INTEGER', references: { table: 'bairros', column: 'bairro_id' } },
|
|
149
|
+
{
|
|
150
|
+
name: 'localidade_nome',
|
|
151
|
+
type: 'TEXT',
|
|
152
|
+
comment: 'Original district or village name for a locality-wide CEP.',
|
|
153
|
+
check: 'localidade_nome IS NULL OR (bairro_id IS NULL AND localidade_tipo IN (\'D\', \'P\'))',
|
|
154
|
+
},
|
|
155
|
+
{ name: 'municipio', type: 'TEXT', notNull: true },
|
|
156
|
+
{ name: 'municipio_cod_ibge', type: 'INTEGER', notNull: true },
|
|
157
|
+
{ name: 'uf', type: 'TEXT', notNull: true },
|
|
158
|
+
{ name: 'nome', type: 'TEXT' },
|
|
159
|
+
{ name: 'localidade_situacao', type: 'INTEGER', notNull: true, check: 'localidade_situacao IN (0, 1, 2, 3)' },
|
|
160
|
+
{ name: 'localidade_tipo', type: 'TEXT', notNull: true, check: 'localidade_tipo IN (\'M\', \'D\', \'P\')' },
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
];
|
|
164
|
+
/**
|
|
165
|
+
* Creates independently mutable source and output schema definitions.
|
|
166
|
+
* @param tableNames - Optional physical-name overrides keyed by the original table name.
|
|
167
|
+
* @returns New table, column, and source-field objects for this invocation.
|
|
168
|
+
*/
|
|
169
|
+
export function buildSchema(tableNames = {}) {
|
|
170
|
+
return baseTables.map((table) => ({
|
|
171
|
+
...table,
|
|
172
|
+
name: tableNames[table.originalName] ?? table.name,
|
|
173
|
+
columns: table.columns.map((column) => ({
|
|
174
|
+
...column,
|
|
175
|
+
...(column.references
|
|
176
|
+
? { references: { ...column.references, table: tableNames[column.references.table] ?? column.references.table } }
|
|
177
|
+
: {}),
|
|
178
|
+
})),
|
|
179
|
+
sourceFields: table.sourceFields ? { ...table.sourceFields } : undefined,
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves the generated CEP table from a schema.
|
|
184
|
+
* @param schema - Source and output table definitions.
|
|
185
|
+
* @returns The first definition marked as the unified table, without copying it.
|
|
186
|
+
* @throws {Error} If the schema has no unified table.
|
|
187
|
+
*/
|
|
188
|
+
export function getUnifiedTable(schema) {
|
|
189
|
+
const table = schema.find((candidate) => candidate.unifiedTable);
|
|
190
|
+
if (!table) {
|
|
191
|
+
throw new Error('Unified schema table not found');
|
|
192
|
+
}
|
|
193
|
+
return table;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Lists persisted tables in parent-before-child creation and insertion order.
|
|
197
|
+
* @param schema - Source and output table definitions returned by `buildSchema`.
|
|
198
|
+
* @returns Definitions with output columns; source-only definitions are excluded.
|
|
199
|
+
*/
|
|
200
|
+
export function getStoredTables(schema) {
|
|
201
|
+
return schema.filter((table) => table.columns.length > 0);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Resolves the source filename pattern for a table.
|
|
205
|
+
* @param table - Source or output table definition.
|
|
206
|
+
* @returns The explicit or derived uppercase TXT pattern, or null for a generated table.
|
|
207
|
+
*/
|
|
208
|
+
export function getTableFilesGlob(table) {
|
|
209
|
+
if (table.unifiedTable || table.fileGlob === null) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return table.fileGlob ?? `${table.originalName.toUpperCase()}.TXT`;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Resolves logical source fields to their positions in a delimited record.
|
|
216
|
+
* @param table - Definition containing a source-field mapping.
|
|
217
|
+
* @param fields - Field names in the desired output order.
|
|
218
|
+
* @returns Zero-based indexes in the same order as `fields`.
|
|
219
|
+
* @throws {Error} If the mapping or any requested field is missing.
|
|
220
|
+
*/
|
|
221
|
+
export function getSourceFieldIndexes(table, fields) {
|
|
222
|
+
if (!table.sourceFields) {
|
|
223
|
+
throw new Error(`Source fields for table '${table.originalName}' not found`);
|
|
224
|
+
}
|
|
225
|
+
return fields.map((field) => {
|
|
226
|
+
const index = table.sourceFields?.[field];
|
|
227
|
+
if (index === undefined) {
|
|
228
|
+
throw new Error(`Source field '${field}' for table '${table.originalName}' not found`);
|
|
229
|
+
}
|
|
230
|
+
return index;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,kGAAkG;AAClG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAMhE,iFAAiF;AACjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAG9E,oFAAoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,gCAAgC;IAChC,2BAA2B;IAC3B,wCAAwC;IACxC,+BAA+B;CACvB,CAAC;AA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,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,MAAkC;IAChE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAsB;IACtD,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAsB,EAAE,MAAyB;IACrF,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,KAAK,CAAC,YAAY,aAAa,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,gBAAgB,KAAK,CAAC,YAAY,aAAa,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Executable name used in CLI output. */
|
|
2
|
+
export declare const BINARY_NAME = "dne";
|
|
3
|
+
/** Default local SQLite database filename. */
|
|
4
|
+
export declare const SQLITE_FILE_NAME = "dne.db";
|
|
5
|
+
/** Default physical table name for unified CEP rows. */
|
|
6
|
+
export declare const SQLITE_CEP_TABLE_NAME = "dne";
|
|
7
|
+
/** Table storing neighborhoods under their original DNE identifiers. */
|
|
8
|
+
export declare const SQLITE_BAIRROS_TABLE_NAME = "bairros";
|
|
9
|
+
/** Table storing the distinct CEP intervals assigned to each neighborhood. */
|
|
10
|
+
export declare const SQLITE_BAIRRO_FAIXAS_TABLE_NAME = "bairro_faixas";
|
|
11
|
+
/** Table storing string-valued import provenance and quality metadata. */
|
|
12
|
+
export declare const SQLITE_METADATA_TABLE_NAME = "edne_metadata";
|
|
13
|
+
/** SQLite database page size in bytes for generated files. */
|
|
14
|
+
export declare const SQLITE_PAGE_SIZE = 32768;
|
|
15
|
+
/** SQLite cache-size pragma; the negative value specifies kibibytes rather than pages. */
|
|
16
|
+
export declare const SQLITE_CACHE_SIZE = -200000;
|
|
17
|
+
/** Maximum number of CEP rows bound in one batched INSERT statement. */
|
|
18
|
+
export declare const SQLITE_INSERT_BATCH_SIZE = 1000;
|
|
19
|
+
/** Default Correios e-DNE source archive URL. */
|
|
20
|
+
export declare const EDNE_DOWNLOAD_URL = "https://www2.correios.com.br/sistemas/edne/download/eDNE_Basico.zip";
|
|
21
|
+
/** Maximum number of simultaneous byte-range download workers. */
|
|
22
|
+
export declare const HTTP_FETCH_CONCURRENCY = 8;
|
|
23
|
+
/** Target byte-range size in bytes for parallel downloads. */
|
|
24
|
+
export declare const HTTP_FETCH_CHUNK_SIZE: number;
|
|
25
|
+
/** Default timeout per HTTP attempt in milliseconds. */
|
|
26
|
+
export declare const HTTP_FETCH_TIMEOUT_MS = 30000;
|
|
27
|
+
/** Default retry count after the initial HTTP attempt. */
|
|
28
|
+
export declare const HTTP_FETCH_MAX_RETRIES = 2;
|
|
29
|
+
/** Initial exponential-backoff delay in milliseconds. */
|
|
30
|
+
export declare const HTTP_FETCH_RETRY_BASE_DELAY_MS = 100;
|
|
31
|
+
/** Maximum exponential-backoff delay in milliseconds. */
|
|
32
|
+
export declare const HTTP_FETCH_RETRY_MAX_DELAY_MS = 1000;
|
|
33
|
+
/** Maximum delay honored from a Retry-After response header, in milliseconds. */
|
|
34
|
+
export declare const HTTP_FETCH_RETRY_AFTER_MAX_MS = 2000;
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Executable name used in CLI output. */
|
|
2
|
+
export const BINARY_NAME = 'dne';
|
|
3
|
+
/** Default local SQLite database filename. */
|
|
4
|
+
export const SQLITE_FILE_NAME = 'dne.db';
|
|
5
|
+
/** Default physical table name for unified CEP rows. */
|
|
6
|
+
export const SQLITE_CEP_TABLE_NAME = 'dne';
|
|
7
|
+
/** Table storing neighborhoods under their original DNE identifiers. */
|
|
8
|
+
export const SQLITE_BAIRROS_TABLE_NAME = 'bairros';
|
|
9
|
+
/** Table storing the distinct CEP intervals assigned to each neighborhood. */
|
|
10
|
+
export const SQLITE_BAIRRO_FAIXAS_TABLE_NAME = 'bairro_faixas';
|
|
11
|
+
/** Table storing string-valued import provenance and quality metadata. */
|
|
12
|
+
export const SQLITE_METADATA_TABLE_NAME = 'edne_metadata';
|
|
13
|
+
/** SQLite database page size in bytes for generated files. */
|
|
14
|
+
export const SQLITE_PAGE_SIZE = 32768; // 32KiB
|
|
15
|
+
/** SQLite cache-size pragma; the negative value specifies kibibytes rather than pages. */
|
|
16
|
+
export const SQLITE_CACHE_SIZE = -200000; // ~195 MiB; negative means cache size in KiB not pages
|
|
17
|
+
/** Maximum number of CEP rows bound in one batched INSERT statement. */
|
|
18
|
+
export const SQLITE_INSERT_BATCH_SIZE = 1000;
|
|
19
|
+
/** Default Correios e-DNE source archive URL. */
|
|
20
|
+
export const EDNE_DOWNLOAD_URL = 'https://www2.correios.com.br/sistemas/edne/download/eDNE_Basico.zip';
|
|
21
|
+
/** Maximum number of simultaneous byte-range download workers. */
|
|
22
|
+
export const HTTP_FETCH_CONCURRENCY = 8;
|
|
23
|
+
/** Target byte-range size in bytes for parallel downloads. */
|
|
24
|
+
export const HTTP_FETCH_CHUNK_SIZE = 2 * 1024 * 1024; // 2MB
|
|
25
|
+
/** Default timeout per HTTP attempt in milliseconds. */
|
|
26
|
+
export const HTTP_FETCH_TIMEOUT_MS = 30_000;
|
|
27
|
+
/** Default retry count after the initial HTTP attempt. */
|
|
28
|
+
export const HTTP_FETCH_MAX_RETRIES = 2;
|
|
29
|
+
/** Initial exponential-backoff delay in milliseconds. */
|
|
30
|
+
export const HTTP_FETCH_RETRY_BASE_DELAY_MS = 100;
|
|
31
|
+
/** Maximum exponential-backoff delay in milliseconds. */
|
|
32
|
+
export const HTTP_FETCH_RETRY_MAX_DELAY_MS = 1_000;
|
|
33
|
+
/** Maximum delay honored from a Retry-After response header, in milliseconds. */
|
|
34
|
+
export const HTTP_FETCH_RETRY_AFTER_MAX_MS = 2_000;
|
|
35
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AAEjC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AACzC,wDAAwD;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,wEAAwE;AACxE,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAC;AACnD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,+BAA+B,GAAG,eAAe,CAAC;AAC/D,0EAA0E;AAC1E,MAAM,CAAC,MAAM,0BAA0B,GAAG,eAAe,CAAC;AAC1D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,QAAQ;AAC/C,0FAA0F;AAC1F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAM,CAAC,CAAC,uDAAuD;A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