@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,115 @@
1
+ import { getStoredTables, getUnifiedTable, } from "./schema.js";
2
+ import { SQLITE_BAIRROS_TABLE_NAME } from "./settings.js";
3
+ /**
4
+ * Creates a generated table, replacing it when its column names, order, or types differ.
5
+ * Call inside a transaction: replacing the table discards its current contents and indexes.
6
+ * @param db - Writable SQLite connection owned by the caller.
7
+ * @param table - Expected generated table definition.
8
+ * @throws {Error} If catalog inspection or schema creation fails.
9
+ */
10
+ export function prepareTableForLoad(db, table) {
11
+ const columns = db.query(`PRAGMA table_info(${quoteIdent(table.name)})`).all();
12
+ const definition = db.query('SELECT sql FROM sqlite_master WHERE type = \'table\' AND name = ?').get(table.name);
13
+ if (columns.length && (columns.length !== table.columns.length
14
+ || columns.some((column, index) => column.name !== table.columns[index]?.name || column.type !== table.columns[index]?.type)
15
+ || table.columns.some((column) => column.check && !definition?.sql.includes(`CHECK (${column.check})`)))) {
16
+ db.run(`DROP TABLE ${quoteIdent(table.name)}`);
17
+ }
18
+ db.run(createTableSql(table));
19
+ }
20
+ /**
21
+ * Generates a single-line CREATE TABLE IF NOT EXISTS statement, including constraints.
22
+ * @param table - Trusted table and column definitions.
23
+ * @returns SQL using WITHOUT ROWID for a unified table.
24
+ */
25
+ export function createTableSql(table) {
26
+ return createTableSqlWithSeparator(table, ', ');
27
+ }
28
+ /**
29
+ * Generates a multiline CREATE TABLE statement for display and documentation.
30
+ * @param table - Trusted table and column definitions.
31
+ * @returns The same schema as `createTableSql`, with one definition per line.
32
+ */
33
+ export function createPrettyTableSql(table) {
34
+ return createTableSqlWithSeparator(table, ',\n ');
35
+ }
36
+ function createTableSqlWithSeparator(table, separator) {
37
+ const primaryKeys = table.columns.filter((column) => column.primaryKey).map((column) => quoteIdent(column.name));
38
+ const definitions = table.columns.map((column) => {
39
+ const parts = [quoteIdent(column.name), column.type];
40
+ if (column.notNull || column.primaryKey) {
41
+ parts.push('NOT NULL');
42
+ }
43
+ if (column.check) {
44
+ parts.push(`CHECK (${column.check})`);
45
+ }
46
+ if (column.references) {
47
+ parts.push(`REFERENCES ${quoteIdent(column.references.table)} (${quoteIdent(column.references.column)})`);
48
+ }
49
+ if (column.comment) {
50
+ parts.push(`/* ${column.comment} */`);
51
+ }
52
+ return parts.join(' ');
53
+ });
54
+ if (primaryKeys.length) {
55
+ definitions.push(`PRIMARY KEY (${primaryKeys.join(', ')})`);
56
+ }
57
+ const withoutRowid = (table.withoutRowid ?? table.unifiedTable) ? ' WITHOUT ROWID' : '';
58
+ if (separator.includes('\n')) {
59
+ return `CREATE TABLE IF NOT EXISTS ${quoteIdent(table.name)} (\n ${definitions.join(separator)}\n)${withoutRowid}`;
60
+ }
61
+ return `CREATE TABLE IF NOT EXISTS ${quoteIdent(table.name)} (${definitions.join(separator)})${withoutRowid}`;
62
+ }
63
+ /**
64
+ * Resolves the address projection that retains the public CEP lookup columns.
65
+ * @param tableName - Physical normalized address table name.
66
+ * @returns The corresponding view name.
67
+ */
68
+ export function cepViewName(tableName) {
69
+ return `${tableName}_consulta`;
70
+ }
71
+ /**
72
+ * Creates the view that resolves neighborhood names and subordinate locality names.
73
+ * @param tableName - Physical normalized address table name.
74
+ * @param bairrosTableName - Physical neighborhood table name.
75
+ * @returns A quoted CREATE VIEW statement with the existing ten public address columns.
76
+ */
77
+ export function createCepViewSql(tableName, bairrosTableName = SQLITE_BAIRROS_TABLE_NAME) {
78
+ return `CREATE VIEW ${quoteIdent(cepViewName(tableName))} AS
79
+ SELECT d.cep, d.logradouro, d.complemento, COALESCE(b.nome, d.localidade_nome) AS bairro,
80
+ d.municipio, d.municipio_cod_ibge, d.uf, d.nome, d.localidade_situacao, d.localidade_tipo
81
+ FROM ${quoteIdent(tableName)} d
82
+ LEFT JOIN ${quoteIdent(bairrosTableName)} b ON b.bairro_id = d.bairro_id`;
83
+ }
84
+ /**
85
+ * Recreates the owned address, neighborhood, and interval tables inside the caller's transaction.
86
+ * Unrelated tables are retained. The transaction must be rolled back if importing or copying data fails.
87
+ * @param db - Writable SQLite connection with foreign keys enabled.
88
+ * @param schema - Source mappings and persisted table definitions.
89
+ * @throws {Error} If a required table definition is missing or SQLite rejects a schema operation.
90
+ */
91
+ export function prepareDatabaseForLoad(db, schema) {
92
+ const cepTable = getUnifiedTable(schema);
93
+ const bairros = schema.find((table) => table.originalName === 'bairros');
94
+ if (!bairros) {
95
+ throw new Error('Neighborhood table definition is missing');
96
+ }
97
+ const stored = getStoredTables(schema);
98
+ db.run(`DROP VIEW IF EXISTS main.${quoteIdent(cepViewName(cepTable.name))}`);
99
+ for (const table of [...stored].reverse()) {
100
+ db.run(`DROP TABLE IF EXISTS main.${quoteIdent(table.name)}`);
101
+ }
102
+ for (const table of stored) {
103
+ db.run(createTableSql(table));
104
+ }
105
+ db.run(createCepViewSql(cepTable.name, bairros.name));
106
+ }
107
+ /**
108
+ * Quotes a SQLite identifier, escaping embedded double quotes.
109
+ * @param value - One identifier, not a dotted SQL expression.
110
+ * @returns A double-quoted identifier safe to interpolate into SQL.
111
+ */
112
+ export function quoteIdent(value) {
113
+ return `"${value.replaceAll('"', '""')}"`;
114
+ }
115
+ //# sourceMappingURL=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AI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC;IACzE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,EAAE,CAAC,GAAG,CAAC,4BAA4B,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7E,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC;QAC1C,EAAE,CAAC,GAAG,CAAC,6BAA6B,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { LocalidadeSituacao, LocalidadeSituacaoCodigo, LocalidadeTipo, LocalidadeTipoCodigo } from './schema.ts';
2
+ /** IBGE numeric codes keyed by Brazilian federative-unit abbreviation. */
3
+ export declare const stateCodes: {
4
+ readonly RO: 11;
5
+ readonly AC: 12;
6
+ readonly AM: 13;
7
+ readonly RR: 14;
8
+ readonly PA: 15;
9
+ readonly AP: 16;
10
+ readonly TO: 17;
11
+ readonly MA: 21;
12
+ readonly PI: 22;
13
+ readonly CE: 23;
14
+ readonly RN: 24;
15
+ readonly PB: 25;
16
+ readonly PE: 26;
17
+ readonly AL: 27;
18
+ readonly SE: 28;
19
+ readonly BA: 29;
20
+ readonly MG: 31;
21
+ readonly ES: 32;
22
+ readonly RJ: 33;
23
+ readonly SP: 35;
24
+ readonly PR: 41;
25
+ readonly SC: 42;
26
+ readonly RS: 43;
27
+ readonly MS: 50;
28
+ readonly MT: 51;
29
+ readonly GO: 52;
30
+ readonly DF: 53;
31
+ };
32
+ /** A Brazilian federative-unit abbreviation supported by the geocoder. */
33
+ export type UF = keyof typeof stateCodes;
34
+ /** All supported Brazilian federative units in `stateCodes` order. */
35
+ export declare const ALL_UFS: ("RO" | "AC" | "AM" | "RR" | "PA" | "AP" | "TO" | "MA" | "PI" | "CE" | "RN" | "PB" | "PE" | "AL" | "SE" | "BA" | "MG" | "ES" | "RJ" | "SP" | "PR" | "SC" | "RS" | "MS" | "MT" | "GO" | "DF")[];
36
+ /** String-valued provenance and quality metadata stored alongside the imported CEP rows. */
37
+ export type LoadMetadata = Record<string, string> & {
38
+ /** Version of the package that performed the import. */
39
+ package_version?: string;
40
+ /** Logical database schema revision used to determine whether a rebuild is required. */
41
+ schema_version?: string;
42
+ /** Source Content-Length header, retained as text. */
43
+ source_content_length?: string;
44
+ /** Source ETag header, including any quotes or weak-validator prefix. */
45
+ source_etag?: string;
46
+ /** Source category, normally `local` or `remote`. */
47
+ source_kind?: string;
48
+ /** Unmodified Last-Modified response header. */
49
+ source_last_modified?: string;
50
+ /** Remote source URL used for validator comparisons. */
51
+ source_url?: string;
52
+ };
53
+ /** Unified address returned by CEP lookups in current SQLite and binary databases. */
54
+ export type DneRow = {
55
+ /** Neighborhood or subordinate locality name, when available. */
56
+ bairro: string | null;
57
+ /** Eight ASCII digits with leading zeros retained and no separator. */
58
+ cep: string;
59
+ /** Additional address information, when available. */
60
+ complemento: string | null;
61
+ /** Descriptive postal coding status of the originating locality, not necessarily the parent municipality. */
62
+ localidade_situacao: LocalidadeSituacao;
63
+ /** Descriptive municipality, district, or village classification of the originating locality. */
64
+ localidade_tipo: LocalidadeTipo;
65
+ /** Street or delivery address; null for a locality-wide CEP. */
66
+ logradouro: string | null;
67
+ /** Municipality name, resolved to the parent for districts and villages. */
68
+ municipio: string;
69
+ /** Seven-digit IBGE municipality code represented as an integer. */
70
+ municipio_cod_ibge: number;
71
+ /** Named recipient, community mailbox, or postal unit, when available. */
72
+ nome: string | null;
73
+ /** Two-letter Brazilian state abbreviation. */
74
+ uf: UF;
75
+ };
76
+ /** Internal SQLite lookup row before the original DNE codes are converted to descriptive values. */
77
+ export type StoredDneRow = Omit<DneRow, 'localidade_situacao' | 'localidade_tipo'> & {
78
+ localidade_situacao: LocalidadeSituacaoCodigo;
79
+ localidade_tipo: LocalidadeTipoCodigo;
80
+ };
81
+ /**
82
+ * Parses a federative-unit abbreviation.
83
+ *
84
+ * Parsing is case-insensitive and returns the canonical uppercase value.
85
+ *
86
+ * @param value Federative-unit abbreviation, for example `MG`.
87
+ * @returns The canonical supported state abbreviation.
88
+ * @throws {Error} If `value` is not a supported federative unit.
89
+ */
90
+ export declare function parseUF(value: string): UF;
package/dist/types.js ADDED
@@ -0,0 +1,49 @@
1
+ /** IBGE numeric codes keyed by Brazilian federative-unit abbreviation. */
2
+ export const stateCodes = {
3
+ RO: 11,
4
+ AC: 12,
5
+ AM: 13,
6
+ RR: 14,
7
+ PA: 15,
8
+ AP: 16,
9
+ TO: 17,
10
+ MA: 21,
11
+ PI: 22,
12
+ CE: 23,
13
+ RN: 24,
14
+ PB: 25,
15
+ PE: 26,
16
+ AL: 27,
17
+ SE: 28,
18
+ BA: 29,
19
+ MG: 31,
20
+ ES: 32,
21
+ RJ: 33,
22
+ SP: 35,
23
+ PR: 41,
24
+ SC: 42,
25
+ RS: 43,
26
+ MS: 50,
27
+ MT: 51,
28
+ GO: 52,
29
+ DF: 53,
30
+ };
31
+ /** All supported Brazilian federative units in `stateCodes` order. */
32
+ export const ALL_UFS = Object.keys(stateCodes).map(parseUF);
33
+ /**
34
+ * Parses a federative-unit abbreviation.
35
+ *
36
+ * Parsing is case-insensitive and returns the canonical uppercase value.
37
+ *
38
+ * @param value Federative-unit abbreviation, for example `MG`.
39
+ * @returns The canonical supported state abbreviation.
40
+ * @throws {Error} If `value` is not a supported federative unit.
41
+ */
42
+ export function parseUF(value) {
43
+ const state = value.trim().toUpperCase();
44
+ if (!Object.hasOwn(stateCodes, state)) {
45
+ throw new Error(`Unknown UF: ${value}`);
46
+ }
47
+ return state;
48
+ }
49
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;CACE,CAAC;AAKX,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAkD5D;;;;;;;;GAQG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACzC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,KAAW,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@konstit/dne",
3
- "version": "0.0.2",
4
- "description": "Build, update and query a local SQLite database of Brazilian postal codes.",
3
+ "version": "0.2.0",
4
+ "description": "Query bundled Brazilian postal codes or build and update local SQLite and binary databases.",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Konstit-Engenharia/konstit-dne.git"
@@ -24,16 +24,28 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "type": "module",
27
+ "main": "./dist/library.js",
28
+ "types": "./dist/library.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/library.d.ts",
32
+ "import": "./dist/library.js",
33
+ "default": "./dist/library.js"
34
+ }
35
+ },
27
36
  "bin": {
28
37
  "dne": "./dist/index.js"
29
38
  },
30
39
  "files": [
31
40
  "dist",
41
+ "data/dne.bin",
32
42
  "README.md",
33
43
  "LICENSE"
34
44
  ],
35
45
  "scripts": {
36
46
  "build:database": "bun run src/index.ts build",
47
+ "build:package-database": "bun run scripts/build-package-database.ts",
48
+ "prepack": "bun run build >&2 && bun run build:package-database >&2",
37
49
  "get": "bun run src/index.ts get",
38
50
  "test": "bun test --dots --parallel",
39
51
  "benchmark": "bun run bench/benchmark.ts",
@@ -52,16 +64,17 @@
52
64
  "audit": "bun audit",
53
65
  "check": "bun run coverage && bun run --parallel tsc lint:biome lint:oxlint build audit",
54
66
  "build": "bun run build:artifacts",
55
- "build:artifacts": "bun run build:clean && bun run --parallel build:js",
67
+ "build:artifacts": "bun run build:clean && bun run --parallel build:js build:library",
56
68
  "build:clean": "rm -rf ./dist",
57
- "build:js": "bun build ./src/index.ts --outdir ./dist --target=bun --format=esm --sourcemap=external --minify --keep-names --splitting --chunk-naming 'chunks/[name]-[hash].[ext]'"
69
+ "build:js": "bun build ./src/index.ts --outdir ./dist --target=bun --format=esm --sourcemap=external --minify --keep-names --splitting --chunk-naming 'chunks/[name]-[hash].[ext]'",
70
+ "build:library": "bunx --bun tsc -p tsconfig.build.json"
58
71
  },
59
72
  "dependencies": {
60
73
  "@konstit/cli": "0.0.4"
61
74
  },
62
75
  "devDependencies": {
63
76
  "@biomejs/biome": "2.5.9",
64
- "@types/bun": "1.4.0",
77
+ "@types/bun": "1.4.2",
65
78
  "dprint": "^0.56.0",
66
79
  "mitata": "^1.0.34",
67
80
  "oxlint": "^1.79.0",