@konstit/dne 0.0.2 → 0.1.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 (44) hide show
  1. package/README.md +215 -13
  2. package/data/dne.bin +0 -0
  3. package/dist/bairro.d.ts +27 -0
  4. package/dist/bairro.js +9 -0
  5. package/dist/bairro.js.map +1 -0
  6. package/dist/binary-db-errors.d.ts +56 -0
  7. package/dist/binary-db-errors.js +68 -0
  8. package/dist/binary-db-errors.js.map +1 -0
  9. package/dist/binary-db-format.d.ts +192 -0
  10. package/dist/binary-db-format.js +250 -0
  11. package/dist/binary-db-format.js.map +1 -0
  12. package/dist/binary-db-reader.d.ts +114 -0
  13. package/dist/binary-db-reader.js +700 -0
  14. package/dist/binary-db-reader.js.map +1 -0
  15. package/dist/cep.d.ts +50 -0
  16. package/dist/cep.js +184 -0
  17. package/dist/cep.js.map +1 -0
  18. package/dist/errors.d.ts +14 -0
  19. package/dist/errors.js +21 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.js +55 -33
  22. package/dist/index.js.map +29 -16
  23. package/dist/library.d.ts +10 -0
  24. package/dist/library.js +8 -0
  25. package/dist/library.js.map +1 -0
  26. package/dist/schema.d.ts +88 -0
  27. package/dist/schema.js +233 -0
  28. package/dist/schema.js.map +1 -0
  29. package/dist/settings.d.ts +34 -0
  30. package/dist/settings.js +35 -0
  31. package/dist/settings.js.map +1 -0
  32. package/dist/sqlite-db-errors.d.ts +40 -0
  33. package/dist/sqlite-db-errors.js +54 -0
  34. package/dist/sqlite-db-errors.js.map +1 -0
  35. package/dist/sqlite-db-reader.d.ts +130 -0
  36. package/dist/sqlite-db-reader.js +307 -0
  37. package/dist/sqlite-db-reader.js.map +1 -0
  38. package/dist/sqlite-db-schema.d.ts +49 -0
  39. package/dist/sqlite-db-schema.js +115 -0
  40. package/dist/sqlite-db-schema.js.map +1 -0
  41. package/dist/types.d.ts +90 -0
  42. package/dist/types.js +49 -0
  43. package/dist/types.js.map +1 -0
  44. package/package.json +17 -4
@@ -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.1.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,9 +64,10 @@
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"