@antelopejs/interface-database-catalog 0.0.2 → 0.0.4

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 CHANGED
@@ -1,13 +1,15 @@
1
- # @antelopejs/interface-database-catalog
1
+ # `@antelopejs/interface-database-catalog`
2
2
 
3
3
  <div align="center">
4
- <a href="./LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Apache_2.0-000000?style=for-the-badge&labelColor=000000"></a>
5
- <a href="https://discord.gg/sjK28QHrA7"><img alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
6
- <a href="https://github.com/AntelopeJS/interface-database-catalog/tree/main/docs"><img alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
4
+ <a href="./LICENSE"><img data-illustration alt="License" src="https://img.shields.io/badge/License-Apache_2.0-000000?style=for-the-badge&labelColor=000000"></a>
5
+ <a href="https://discord.gg/g4pFt6eXqu"><img data-illustration alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
6
+ <a href="https://github.com/AntelopeJS/interface-database-catalog/tree/main/docs"><img data-illustration alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
7
7
  </div>
8
8
 
9
9
  Describes and profiles a database that an [`@antelopejs/interface-database`](https://github.com/AntelopeJS/interface-database) provider is connected to but does not own, so a generator can propose a module whose tables mirror it. It is a development tool: every function refuses outside development.
10
10
 
11
+ Part of [AntelopeJS](https://github.com/AntelopeJS/antelopejs). Used by [AntelopeJS DMS](https://github.com/AntelopeJS/dms), the open-source back office for your PostgreSQL, MongoDB or RethinkDB database.
12
+
11
13
  ## What it offers
12
14
 
13
15
  - `Info` returns the engine, version, database and role of the connection.
@@ -15,16 +17,17 @@ Describes and profiles a database that an [`@antelopejs/interface-database`](htt
15
17
  - `DescribeRelations` details columns with their native types and the `@Field` declarations they accept, indexes and foreign keys.
16
18
  - `Profile` aggregates a relation per column and per foreign key, never returning rows.
17
19
  - `CheckReference` measures how much of one column's values another column holds, for references the database does not declare.
20
+ - `SampleRows` answers a few rows of a relation, each value as text, for a person to look at. It is the one function that returns rows, and it is never meant for a generator or a model.
18
21
 
19
- The answers follow the provider's own registration rules: a relation the catalog calls mappable registers, and the key it names is the one `_id` aliases.
22
+ The answers follow the provider's own registration rules. A relation the catalog calls mappable registers, and the key it names is the one `_id` aliases.
20
23
 
21
24
  ## Implementations
22
25
 
23
- No public module implements this interface yet. A provider of `@antelopejs/interface-database` that connects to a database it does not own can implement it as well.
26
+ `@antelopejs/postgres`, `@antelopejs/mongodb` and `@antelopejs/rethinkdb` implement this interface next to `@antelopejs/interface-database`. Each lists it under `antelopeJs.implements` in its `package.json`. Another provider of `@antelopejs/interface-database` that connects to a database it does not own can implement it as well.
24
27
 
25
28
  ## Install
26
29
 
27
- The package is not published to npm yet. Once it is, add it to the module that reads the catalog:
30
+ Add the package to the module that reads the catalog:
28
31
 
29
32
  ```bash
30
33
  pnpm add @antelopejs/interface-database-catalog
@@ -51,13 +54,15 @@ Relations are named `"schema.name"`, the form `DescribeRelations` and `Profile`
51
54
 
52
55
  ## Compatibility
53
56
 
54
- Requires AntelopeJS core `>=1.14.0` and the following peer dependency:
57
+ The interface has one AntelopeJS peer dependency:
58
+
59
+ <!-- antelopejs-docs-compat:start -->
55
60
 
56
- <!-- docs-compat: ./package.json#peerDependencies -->
61
+ | Package | Supported | Tested with |
62
+ | ---------------------------- | ---------------- | ----------- |
63
+ | `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` | `0.4.0` |
57
64
 
58
- | Package | Range |
59
- | ---------------------------- | ---------------- |
60
- | `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` |
65
+ <!-- antelopejs-docs-compat:end -->
61
66
 
62
67
  ## Contributing
63
68
 
@@ -65,8 +70,7 @@ Read [CONTRIBUTING.md](./CONTRIBUTING.md) before you open a pull request. The lo
65
70
 
66
71
  ```bash
67
72
  pnpm install
68
- pnpm lint
69
- pnpm typecheck
73
+ pnpm run checks
70
74
  ```
71
75
 
72
76
  ## License
package/dist/index.d.ts CHANGED
@@ -247,6 +247,35 @@ export interface ReferenceMatch {
247
247
  sampled: boolean;
248
248
  targetIsKey: boolean;
249
249
  }
250
+ /** The most rows a sample answers. */
251
+ export declare const SAMPLE_ROWS_LIMIT = 20;
252
+ /** The most characters a sampled value answers before it is cut. */
253
+ export declare const SAMPLE_TEXT_LENGTH = 200;
254
+ /** The relation, columns and number of rows to sample; every column when `columns` is absent. */
255
+ export interface SampleRequest {
256
+ relation: string;
257
+ columns?: string[];
258
+ /** At most `SAMPLE_ROWS_LIMIT`. */
259
+ limit: number;
260
+ }
261
+ /** A sampled value as text, cut at `SAMPLE_TEXT_LENGTH` characters. */
262
+ export interface SampledText {
263
+ text: string;
264
+ truncated: boolean;
265
+ }
266
+ /** A binary value, answered by its length only. */
267
+ export interface SampledBinary {
268
+ bytes: number;
269
+ }
270
+ export type SampledValue = SampledText | SampledBinary | null;
271
+ /** Rows of a relation, each value in the order of `columns`. */
272
+ export interface RowSample {
273
+ relation: string;
274
+ columns: string[];
275
+ rows: SampledValue[][];
276
+ /** How the relation was sampled before its first rows were read, when it was. */
277
+ sample: SampleInfo | null;
278
+ }
250
279
  /**
251
280
  * The connected database: engine, version, database and role.
252
281
  *
@@ -271,3 +300,8 @@ export declare const Profile: (request: ProfileRequest) => Promise<RelationProfi
271
300
  * declare.
272
301
  */
273
302
  export declare const CheckReference: (check: ReferenceCheck) => Promise<Measure<ReferenceMatch>>;
303
+ /**
304
+ * A few rows of a relation, for a person to look at. Unlike every other function, it answers
305
+ * row values: a consumer shows them to the project's owner and passes them to nothing else.
306
+ */
307
+ export declare const SampleRows: (request: SampleRequest) => Promise<RowSample>;
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckReference = exports.Profile = exports.DescribeRelations = exports.ListRelations = exports.Info = void 0;
3
+ exports.SampleRows = exports.CheckReference = exports.Profile = exports.DescribeRelations = exports.ListRelations = exports.Info = exports.SAMPLE_TEXT_LENGTH = exports.SAMPLE_ROWS_LIMIT = void 0;
4
4
  const interface_core_1 = require("@antelopejs/interface-core");
5
+ /** The most rows a sample answers. */
6
+ exports.SAMPLE_ROWS_LIMIT = 20;
7
+ /** The most characters a sampled value answers before it is cut. */
8
+ exports.SAMPLE_TEXT_LENGTH = 200;
5
9
  /**
6
10
  * The connected database: engine, version, database and role.
7
11
  *
@@ -26,4 +30,9 @@ exports.Profile = (0, interface_core_1.InterfaceFunction)();
26
30
  * declare.
27
31
  */
28
32
  exports.CheckReference = (0, interface_core_1.InterfaceFunction)();
33
+ /**
34
+ * A few rows of a relation, for a person to look at. Unlike every other function, it answers
35
+ * row values: a consumer shows them to the project's owner and passes them to nothing else.
36
+ */
37
+ exports.SampleRows = (0, interface_core_1.InterfaceFunction)();
29
38
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAwS/D;;;;;GAKG;AACU,QAAA,IAAI,GAAG,IAAA,kCAAiB,GAA8B,CAAC;AAEpE;;;GAGG;AACU,QAAA,aAAa,GACxB,IAAA,kCAAiB,GAAsD,CAAC;AAE1E,qDAAqD;AACxC,QAAA,iBAAiB,GAC5B,IAAA,kCAAiB,GAA2D,CAAC;AAE/E;;;GAGG;AACU,QAAA,OAAO,GAClB,IAAA,kCAAiB,GAAyD,CAAC;AAE7E;;;GAGG;AACU,QAAA,cAAc,GACzB,IAAA,kCAAiB,GAEd,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAwS/D,sCAAsC;AACzB,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAEpC,oEAAoE;AACvD,QAAA,kBAAkB,GAAG,GAAG,CAAC;AAgCtC;;;;;GAKG;AACU,QAAA,IAAI,GAAG,IAAA,kCAAiB,GAA8B,CAAC;AAEpE;;;GAGG;AACU,QAAA,aAAa,GACxB,IAAA,kCAAiB,GAAsD,CAAC;AAE1E,qDAAqD;AACxC,QAAA,iBAAiB,GAC5B,IAAA,kCAAiB,GAA2D,CAAC;AAE/E;;;GAGG;AACU,QAAA,OAAO,GAClB,IAAA,kCAAiB,GAAyD,CAAC;AAE7E;;;GAGG;AACU,QAAA,cAAc,GACzB,IAAA,kCAAiB,GAEd,CAAC;AAEN;;;GAGG;AACU,QAAA,UAAU,GACrB,IAAA,kCAAiB,GAAkD,CAAC"}
package/docs/index.md CHANGED
@@ -1,10 +1,66 @@
1
- # Interface Database Catalog
1
+ ---
2
+ title: Inspect an existing database
3
+ description: Discover, describe and profile the relations of a database that an interface-database provider is connected to but does not own.
4
+ mode: how-to
5
+ ---
2
6
 
3
- ## Reaching a provider
7
+ Use `@antelopejs/interface-database-catalog` to discover relations, inspect their structure, and profile aggregate characteristics before mapping an existing database into an application. The catalog describes a provider's connection. It does not open a new connection or register tables. It returns no raw records, except through `SampleRows`, which answers a few rows for a person to look at.
4
8
 
5
- A module that implements `@antelopejs/interface-database` over a database it does not own may also implement this interface. A consumer reaches it through a connection declared in the project configuration, one per database:
9
+ ## Before you begin
6
10
 
7
- ```ts
11
+ Run inside an AntelopeJS module in development, connected to a provider that implements this catalog and does not own its tables. Every catalog function refuses outside development or on an instance that owns its tables. These refusals are safety boundaries. Do not work around them in production.
12
+
13
+ ## Explore in increasing detail
14
+
15
+ | Step | Call | Use the answer to… |
16
+ | ----------------------------------------- | -------------------------------- | ---------------------------------------------------------------- |
17
+ | 1. Identify the connection | `Info()` | Confirm the engine, database, and role before inspecting data. |
18
+ | 2. Select a relation | `ListRelations(schemas?)` | Review names, keys, write privileges, and mapping refusals. |
19
+ | 3. Understand its structure | `DescribeRelations(relations)` | Inspect field declarations, indexes, and declared relationships. |
20
+ | 4. Measure only what you need | `Profile({ relation, columns })` | Inspect aggregates and traits for selected columns. |
21
+ | 5. Investigate an undeclared relationship | `CheckReference({ from, to })` | Measure value containment without declaring a foreign key. |
22
+
23
+ Read the metadata before you request a profile. Name relations with their schema, such as `"public.orders"`. A profile without `columns` covers every column of the relation.
24
+
25
+ ## Inspect one relation
26
+
27
+ This example uses the consuming module's default catalog binding. First inspect the relation list, then pass a name it returned to `inspectRelation`, such as `"public.orders"`. It reads metadata only. A profile is a separate step, and it can cost more.
28
+
29
+ ```ts docs-check
30
+ import {
31
+ Info,
32
+ ListRelations,
33
+ DescribeRelations,
34
+ } from "@antelopejs/interface-database-catalog";
35
+
36
+ export async function listDatabase() {
37
+ return { connection: await Info(), relations: await ListRelations() };
38
+ }
39
+
40
+ export async function inspectRelation(relation: string) {
41
+ const descriptions = await DescribeRelations([relation]);
42
+ return descriptions.map((description) => ({
43
+ relation: `${description.schema}.${description.name}`,
44
+ key: description.key,
45
+ writes: description.writes,
46
+ columns: description.columns,
47
+ unmappable: description.unmappable,
48
+ }));
49
+ }
50
+ ```
51
+
52
+ Before you generate table declarations, review `unmappable`, each column's `accepts` and `lossy` notes, and the write permissions. A relation without a key is not refused for that reason alone. It registers without `_id`. Reading the catalog grants no permission and adds no constraint.
53
+
54
+ ## Advanced: select a named provider
55
+
56
+ A module that implements `@antelopejs/interface-database` over a database it does not own may also implement this interface. Each consumer reaches it through a connection declared on its own module entry in the project configuration, one per database. Two consumers of the same database give their connections the same id:
57
+
58
+ ```ts fragment
59
+ "dms-builder": {
60
+ importOverrides: [
61
+ { interface: "@antelopejs/interface-database-catalog", source: "postgres-erp", id: "erp" },
62
+ ],
63
+ },
8
64
  "dms-ai": {
9
65
  importOverrides: [
10
66
  { interface: "@antelopejs/interface-database-catalog", source: "postgres-erp", id: "erp" },
@@ -12,7 +68,7 @@ A module that implements `@antelopejs/interface-database` over a database it doe
12
68
  },
13
69
  ```
14
70
 
15
- `GetInterfaceInstances(interfaceID)` lists connections visible to the calling module. `GetInterfaceInstance(interfaceID, connectionID)` returns connection metadata, including its loadable `path`, or `undefined`; it does not return the catalog exports. Resolve the connection by package name and load its path using AntelopeJS's established CommonJS loader pattern:
71
+ `GetInterfaceInstances(interfaceID)` lists connections visible to the calling module. `GetInterfaceInstance(interfaceID, connectionID)` returns the connection's metadata, including the `path` to load, or `undefined`. It does not return the catalog exports. Look the connection up by package name, then `require` its `path`:
16
72
 
17
73
  ```ts docs-check
18
74
  import { GetInterfaceInstance } from "@antelopejs/interface-core";
@@ -31,17 +87,18 @@ export async function inspectErp() {
31
87
  }
32
88
  ```
33
89
 
34
- Run this inside the consuming AntelopeJS module, with the provider loaded and the connection configured. A plain package import uses that module's default binding; loading `connection.path` selects the named binding. These calls do not create database connections themselves.
90
+ Run this inside the consuming AntelopeJS module, with the provider loaded and the connection configured. `require` returns an untyped value, and the annotation states its shape without checking it. It holds because `connection.path` resolves to this interface package, bound to the connection's provider. A plain package import uses the module's default binding, and loading `connection.path` selects the named binding. These calls do not open database connections.
35
91
 
36
92
  ## Functions
37
93
 
38
- | Function | Answers |
39
- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
40
- | `Info()` | engine, version, database and role of the connection |
41
- | `ListRelations(schemas?)` | every relation, partitions left out: kind, row estimate and its source, key, write privileges, comment, and why it cannot be registered when it cannot |
42
- | `DescribeRelations(relations)` | the named relations in full: columns with their native types and the declarations they accept, indexes, foreign keys out and in |
43
- | `Profile({ relation, columns? })` | aggregates per column and per foreign key, and the traits they imply |
44
- | `CheckReference({ from, to })` | how much of one column's values another column holds, for a reference the database does not declare |
94
+ | Function | Answers |
95
+ | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
96
+ | `Info()` | engine, version, database and role of the connection |
97
+ | `ListRelations(schemas?)` | visible relations (excluding child partitions), row estimates, keys, write privileges, and mapping refusals |
98
+ | `DescribeRelations(relations)` | the named relations in full: columns with their native types and the declarations they accept, indexes, foreign keys out and in |
99
+ | `Profile({ relation, columns? })` | aggregates per column and per foreign key, and the traits they imply |
100
+ | `CheckReference({ from, to })` | whether one column's non-null values occur in another, without assuming a declared foreign key |
101
+ | `SampleRows({ relation, columns?, limit })` | a few rows, each value as text, for a person to look at; never for a generator or a model |
45
102
 
46
103
  Relations are named `"schema.name"`.
47
104
 
@@ -57,7 +114,28 @@ A profile holds aggregates, never rows:
57
114
 
58
115
  Values appear only as enum labels and as **categories**: the most frequent values of a column with few distinct values, each counted often enough to be a category rather than a record. Rarer values are folded into `other` and never named.
59
116
 
60
- Every measure has a time bound. A measure that does not finish answers `{ status: "timeout" }`, and the rest of the profile stands. A large relation is sampled, and `sample` says by how much. A distinct count from a sample is then a lower bound.
117
+ ### Interpret incomplete measurements
118
+
119
+ Every measure has its own time bound. Check its status before you read a value. A failed measure leaves the rest of the profile standing.
120
+
121
+ | Status | Available data | Interpretation |
122
+ | ----------- | -------------- | ----------------------------------------------------------------------------------- |
123
+ | `"ok"` | `value` | The measure completed. Check sampling and exactness before treating it as a census. |
124
+ | `"timeout"` | No value | The time bound expired. This is not a zero count. |
125
+ | `"error"` | `code` | The database refused the measure; only its error code is exposed. |
126
+
127
+ A large relation is sampled, and `sample` reports the percentage and the row count. A distinct count from a sample is a lower bound. Row counts also carry an `exact` flag. `CheckReference` answers a `Measure` too. Its value reports containment and whether the target is a key. It does not prove that the database enforces a foreign key.
128
+
129
+ ## What a sample answers
130
+
131
+ `SampleRows` is the one function that answers row values. It is meant for a person who decides what a relation's columns hold, never for a generator or a model:
132
+
133
+ - at most `SAMPLE_ROWS_LIMIT` (20) rows;
134
+ - every value as text, cut at `SAMPLE_TEXT_LENGTH` (200) characters, and `truncated` when it was;
135
+ - a binary value as its length only;
136
+ - a large relation is sampled as a profile is, and `sample` says so.
137
+
138
+ The interface does not fix how the provider reads the rows. `@antelopejs/postgres` reads them in one read-only transaction under the time bound of a measure, and throws when the read does not finish.
61
139
 
62
140
  ## Refusals
63
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/interface-database-catalog",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "AntelopeJS interface for describing and profiling a connected database",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -32,22 +32,32 @@
32
32
  "provenance": true
33
33
  },
34
34
  "scripts": {
35
- "build": "rimraf dist && tsc",
35
+ "build": "rimraf dist && tsc --skipLibCheck",
36
36
  "typecheck": "tsc --noEmit",
37
+ "test": "pnpm run build",
37
38
  "format": "oxfmt .",
38
39
  "lint:fix": "oxlint --fix",
39
40
  "lint": "oxlint",
40
41
  "prepack": "pnpm run build",
41
- "release": "pnpm run lint && pnpm run prepack && release-it",
42
+ "release": "pnpm run lint && pnpm run typecheck && pnpm run prepack && release-it",
42
43
  "format:check": "oxfmt --check .",
43
- "knip": "knip"
44
+ "knip": "knip",
45
+ "prepare": "if [ -e .git ] && command -v git >/dev/null 2>&1 && command -v lefthook >/dev/null 2>&1 && GIT_DIR=.git GIT_WORK_TREE=. git rev-parse --git-dir >/dev/null 2>&1; then GIT_DIR=.git GIT_WORK_TREE=. lefthook install; fi",
46
+ "checks": "antelopejs-checks",
47
+ "size": "antelopejs-check-size",
48
+ "sync": "antelopejs-sync",
49
+ "sync:check": "antelopejs-sync --check",
50
+ "suppressions": "antelopejs-suppressions",
51
+ "suppressions:update": "antelopejs-suppressions --update"
44
52
  },
45
53
  "devDependencies": {
54
+ "@antelopejs/core": "^1.21.0",
46
55
  "@antelopejs/interface-core": ">=0.2.4 <1.0.0",
47
- "@antelopejs/tooling-configs": "^0.0.9",
56
+ "@antelopejs/tooling-configs": "^0.5.1",
48
57
  "@types/node": "^22.19.15",
49
58
  "knip": "^6.34.0",
50
- "oxfmt": "^0.66.0",
59
+ "lefthook": "^2.2.2",
60
+ "oxfmt": "^0.77.0",
51
61
  "oxlint": "1.81.0",
52
62
  "oxlint-tsgolint": "^7.0.2001",
53
63
  "release-it": "^19.2.4",
@@ -58,5 +68,10 @@
58
68
  "peerDependencies": {
59
69
  "@antelopejs/interface-core": ">=0.2.4 <1.0.0"
60
70
  },
61
- "packageManager": "pnpm@10.6.5"
71
+ "packageManager": "pnpm@10.6.5",
72
+ "antelopeJs": {
73
+ "docs": {
74
+ "standard": true
75
+ }
76
+ }
62
77
  }