@antelopejs/interface-database-catalog 0.0.0-stage → 0.0.1
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/LICENSE +190 -0
- package/README.md +70 -2
- package/dist/index.d.ts +273 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/docs/index.md +48 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright (c) 2025-present - AntelopeJS Team
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
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>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
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
|
+
|
|
11
|
+
## What it offers
|
|
12
|
+
|
|
13
|
+
- `Info` returns the engine, version, database and role of the connection.
|
|
14
|
+
- `ListRelations` lists every relation with its kind, row estimate, key and write privileges, and says why a relation cannot be registered when it cannot.
|
|
15
|
+
- `DescribeRelations` details columns with their native types and the `@Field` declarations they accept, indexes and foreign keys.
|
|
16
|
+
- `Profile` aggregates a relation per column and per foreign key, never returning rows.
|
|
17
|
+
- `CheckReference` measures how much of one column's values another column holds, for references the database does not declare.
|
|
18
|
+
|
|
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.
|
|
20
|
+
|
|
21
|
+
## Implementations
|
|
22
|
+
|
|
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.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
The package is not published to npm yet. Once it is, add it to the module that reads the catalog:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @antelopejs/interface-database-catalog
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick start
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { ListRelations } from "@antelopejs/interface-database-catalog";
|
|
37
|
+
|
|
38
|
+
export async function listMappableRelations() {
|
|
39
|
+
const relations = await ListRelations(["public"]);
|
|
40
|
+
return relations
|
|
41
|
+
.filter((relation) => !relation.unmappable)
|
|
42
|
+
.map((relation) => `${relation.schema}.${relation.name}`);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Relations are named `"schema.name"`, the form `DescribeRelations` and `Profile` take.
|
|
47
|
+
|
|
48
|
+
## Documentation
|
|
49
|
+
|
|
50
|
+
- [Overview](https://github.com/AntelopeJS/interface-database-catalog/blob/main/docs/index.md)
|
|
51
|
+
|
|
52
|
+
## Compatibility
|
|
53
|
+
|
|
54
|
+
| Package | Range |
|
|
55
|
+
| ----------------------------------- | ---------------- |
|
|
56
|
+
| `@antelopejs/interface-core` (peer) | `>=0.2.0 <1.0.0` |
|
|
57
|
+
| `@antelopejs/core` | `>=1.14.0` |
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
Read [CONTRIBUTING.md](./CONTRIBUTING.md) before you open a pull request. The local checks are:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pnpm install
|
|
65
|
+
pnpm lint
|
|
66
|
+
pnpm typecheck
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
[Apache-2.0](./LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the connected database is, as the provider's own connection sees it.
|
|
3
|
+
*/
|
|
4
|
+
export interface CatalogInfo {
|
|
5
|
+
/** The engine's name, e.g. `postgresql`. */
|
|
6
|
+
engine: string;
|
|
7
|
+
/** The server's version, e.g. `17.5`. */
|
|
8
|
+
version: string;
|
|
9
|
+
/** The database the connection is on. */
|
|
10
|
+
database: string;
|
|
11
|
+
/** The role the connection runs as. */
|
|
12
|
+
role: string;
|
|
13
|
+
}
|
|
14
|
+
/** The kinds of relation a catalog lists. */
|
|
15
|
+
export type RelationKind = "table" | "partitioned" | "view" | "materialized" | "foreign";
|
|
16
|
+
/**
|
|
17
|
+
* Where a row estimate came from: the database's statistics, its live-tuple counter for a table
|
|
18
|
+
* never analyzed, or the planner's estimate for a relation that has neither.
|
|
19
|
+
*/
|
|
20
|
+
export type EstimateSource = "statistics" | "live-tuples" | "plan";
|
|
21
|
+
/** Whether a relation's key is its primary key or a unique index that identifies rows as one does. */
|
|
22
|
+
export type KeySource = "primary" | "unique";
|
|
23
|
+
/**
|
|
24
|
+
* The columns registration aliases `_id` to.
|
|
25
|
+
*/
|
|
26
|
+
export interface RelationKey {
|
|
27
|
+
columns: string[];
|
|
28
|
+
source: KeySource;
|
|
29
|
+
}
|
|
30
|
+
/** What the provider's connection may write to a relation. */
|
|
31
|
+
export interface RelationWrites {
|
|
32
|
+
insert: boolean;
|
|
33
|
+
update: boolean;
|
|
34
|
+
delete: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* One relation of the connected database.
|
|
38
|
+
*
|
|
39
|
+
* `key` and `unmappable` are the provider's own registration rules: a relation the summary calls
|
|
40
|
+
* mappable registers, and a relation without a key registers without `_id`.
|
|
41
|
+
*/
|
|
42
|
+
export interface RelationSummary {
|
|
43
|
+
/** The native schema, used verbatim as the schema id. */
|
|
44
|
+
schema: string;
|
|
45
|
+
/** The native name, used verbatim as the table id. */
|
|
46
|
+
name: string;
|
|
47
|
+
kind: RelationKind;
|
|
48
|
+
estimatedRows: number | null;
|
|
49
|
+
estimate: EstimateSource | null;
|
|
50
|
+
key: RelationKey | null;
|
|
51
|
+
/** Why the relation cannot be registered, when it cannot. */
|
|
52
|
+
unmappable?: string;
|
|
53
|
+
writes: RelationWrites;
|
|
54
|
+
comment: string | null;
|
|
55
|
+
}
|
|
56
|
+
/** How an identity column takes its values. */
|
|
57
|
+
export type IdentityKind = "always" | "by default";
|
|
58
|
+
/**
|
|
59
|
+
* A field type a column may be declared as, in the spelling `@Field` takes (`"string"`,
|
|
60
|
+
* `"number"`, `"date"`, `"boolean"`, `"object"`, `"string[]"`, …), with the reason it does not
|
|
61
|
+
* round-trip when it does not.
|
|
62
|
+
*/
|
|
63
|
+
export interface DeclaredReading {
|
|
64
|
+
declared: string;
|
|
65
|
+
lossy?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One column of a relation.
|
|
69
|
+
*/
|
|
70
|
+
export interface ColumnDescription {
|
|
71
|
+
/** The native name, used verbatim as the field name. */
|
|
72
|
+
name: string;
|
|
73
|
+
/** The native type with its modifiers, e.g. `character varying(200)`. */
|
|
74
|
+
native: string;
|
|
75
|
+
nullable: boolean;
|
|
76
|
+
hasDefault: boolean;
|
|
77
|
+
generated: boolean;
|
|
78
|
+
identity: IdentityKind | null;
|
|
79
|
+
/** An enum's labels, in their sort order. */
|
|
80
|
+
enumLabels?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The declarations registration accepts for this column, the one a generator should propose
|
|
83
|
+
* first. Empty when the native type is not supported, and then `unsupported` says why.
|
|
84
|
+
*/
|
|
85
|
+
accepts: DeclaredReading[];
|
|
86
|
+
unsupported?: string;
|
|
87
|
+
/** Why a write never assigns this column, when it never does. */
|
|
88
|
+
readOnly?: string;
|
|
89
|
+
comment: string | null;
|
|
90
|
+
}
|
|
91
|
+
/** Columns of one relation, named `"schema.name"`. */
|
|
92
|
+
export interface RelationColumns {
|
|
93
|
+
relation: string;
|
|
94
|
+
columns: string[];
|
|
95
|
+
}
|
|
96
|
+
/** A declared foreign key. */
|
|
97
|
+
export interface Reference {
|
|
98
|
+
name: string;
|
|
99
|
+
from: RelationColumns;
|
|
100
|
+
to: RelationColumns;
|
|
101
|
+
}
|
|
102
|
+
/** An index the database holds on a relation. */
|
|
103
|
+
export interface IndexDescription {
|
|
104
|
+
name: string;
|
|
105
|
+
columns: string[];
|
|
106
|
+
unique: boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A relation in full: its columns, its indexes, and the foreign keys out of it and into it.
|
|
110
|
+
*/
|
|
111
|
+
export interface RelationDescription extends RelationSummary {
|
|
112
|
+
columns: ColumnDescription[];
|
|
113
|
+
indexes: IndexDescription[];
|
|
114
|
+
references: Reference[];
|
|
115
|
+
referencedBy: Reference[];
|
|
116
|
+
}
|
|
117
|
+
/** A measure that did not finish in its time. */
|
|
118
|
+
export interface MeasureTimeout {
|
|
119
|
+
status: "timeout";
|
|
120
|
+
}
|
|
121
|
+
/** A measure the database refused, by its error code only. */
|
|
122
|
+
export interface MeasureError {
|
|
123
|
+
status: "error";
|
|
124
|
+
code: string;
|
|
125
|
+
}
|
|
126
|
+
/** A measure's value. */
|
|
127
|
+
export interface MeasureValue<T> {
|
|
128
|
+
status: "ok";
|
|
129
|
+
value: T;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The outcome of one measure. A measure that times out or fails leaves the others standing.
|
|
133
|
+
*/
|
|
134
|
+
export type Measure<T> = MeasureValue<T> | MeasureTimeout | MeasureError;
|
|
135
|
+
/** How a profile sampled its relation, when it did. */
|
|
136
|
+
export interface SampleInfo {
|
|
137
|
+
percent: number;
|
|
138
|
+
rows: number;
|
|
139
|
+
}
|
|
140
|
+
/** A row count, and whether it was counted or estimated. */
|
|
141
|
+
export interface RowCount {
|
|
142
|
+
rows: number;
|
|
143
|
+
exact: boolean;
|
|
144
|
+
}
|
|
145
|
+
/** The ends of a number, date or enum column. Dates are ISO strings. */
|
|
146
|
+
export interface ValueRange {
|
|
147
|
+
min: number | string;
|
|
148
|
+
max: number | string;
|
|
149
|
+
}
|
|
150
|
+
/** Rows in one calendar month, `YYYY-MM`, in UTC. */
|
|
151
|
+
export interface MonthCount {
|
|
152
|
+
month: string;
|
|
153
|
+
rows: number;
|
|
154
|
+
}
|
|
155
|
+
/** One category of a column, with its rows. */
|
|
156
|
+
export interface CategoryCount {
|
|
157
|
+
value: string | number | boolean;
|
|
158
|
+
rows: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The categories of a column with few distinct values. Values counted too rarely to be a
|
|
162
|
+
* category are folded into `other`, and never named.
|
|
163
|
+
*/
|
|
164
|
+
export interface Categories {
|
|
165
|
+
values: CategoryCount[];
|
|
166
|
+
other: number;
|
|
167
|
+
}
|
|
168
|
+
/** Lengths of a text column's values. */
|
|
169
|
+
export interface LengthStats {
|
|
170
|
+
min: number;
|
|
171
|
+
avg: number;
|
|
172
|
+
max: number;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* What a profile concludes about a column, from its measures:
|
|
176
|
+
* - `enum-like`: an enum, or few distinct values over enough rows;
|
|
177
|
+
* - `identifier-like`: one distinct value per row, never null;
|
|
178
|
+
* - `label-candidate`: text that is nearly unique and short enough to show;
|
|
179
|
+
* - `time-axis`: a date column filled enough and spread over enough months;
|
|
180
|
+
* - `measure`: a number column that is neither a key nor a reference.
|
|
181
|
+
*/
|
|
182
|
+
export type ColumnTrait = "enum-like" | "identifier-like" | "label-candidate" | "time-axis" | "measure";
|
|
183
|
+
/**
|
|
184
|
+
* One column's profile. Only measures that apply to the column's type are present.
|
|
185
|
+
*/
|
|
186
|
+
export interface ColumnProfile {
|
|
187
|
+
name: string;
|
|
188
|
+
nulls?: Measure<number>;
|
|
189
|
+
/** A lower bound when the profile is sampled. */
|
|
190
|
+
distinct?: Measure<number>;
|
|
191
|
+
range?: Measure<ValueRange>;
|
|
192
|
+
months?: Measure<MonthCount[]>;
|
|
193
|
+
categories?: Measure<Categories>;
|
|
194
|
+
length?: Measure<LengthStats>;
|
|
195
|
+
traits: ColumnTrait[];
|
|
196
|
+
}
|
|
197
|
+
/** How many children each referenced parent has, over a declared foreign key out of the relation. */
|
|
198
|
+
export interface FanOut {
|
|
199
|
+
average: number;
|
|
200
|
+
max: number;
|
|
201
|
+
parentsWithoutChildren: number;
|
|
202
|
+
}
|
|
203
|
+
/** A declared foreign key out of the profiled relation, with its fan-out. */
|
|
204
|
+
export interface ReferenceProfile {
|
|
205
|
+
reference: Reference;
|
|
206
|
+
fanOut: Measure<FanOut>;
|
|
207
|
+
}
|
|
208
|
+
/** A declared foreign key into the profiled relation, with the referring relation's size. */
|
|
209
|
+
export interface InboundProfile {
|
|
210
|
+
reference: Reference;
|
|
211
|
+
estimatedRows: number | null;
|
|
212
|
+
}
|
|
213
|
+
/** The relation and columns to profile; every column when `columns` is absent. */
|
|
214
|
+
export interface ProfileRequest {
|
|
215
|
+
relation: string;
|
|
216
|
+
columns?: string[];
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Aggregates over a relation. It carries no row: values appear only as enum labels and as
|
|
220
|
+
* categories.
|
|
221
|
+
*/
|
|
222
|
+
export interface RelationProfile {
|
|
223
|
+
relation: string;
|
|
224
|
+
rows: Measure<RowCount>;
|
|
225
|
+
sample: SampleInfo | null;
|
|
226
|
+
columns: ColumnProfile[];
|
|
227
|
+
references: ReferenceProfile[];
|
|
228
|
+
inbound: InboundProfile[];
|
|
229
|
+
}
|
|
230
|
+
/** One column of one relation, the relation named `"schema.name"`. */
|
|
231
|
+
export interface ColumnReference {
|
|
232
|
+
relation: string;
|
|
233
|
+
column: string;
|
|
234
|
+
}
|
|
235
|
+
/** A column that may refer to another without a declared foreign key. */
|
|
236
|
+
export interface ReferenceCheck {
|
|
237
|
+
from: ColumnReference;
|
|
238
|
+
to: ColumnReference;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* How much of a column's non-null values the other column holds, and whether that other column
|
|
242
|
+
* is its relation's key.
|
|
243
|
+
*/
|
|
244
|
+
export interface ReferenceMatch {
|
|
245
|
+
containment: number;
|
|
246
|
+
checkedRows: number;
|
|
247
|
+
sampled: boolean;
|
|
248
|
+
targetIsKey: boolean;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The connected database: engine, version, database and role.
|
|
252
|
+
*
|
|
253
|
+
* Every function of this interface refuses outside development, and on a provider instance that
|
|
254
|
+
* owns its tables rather than describing a database it was pointed at.
|
|
255
|
+
*/
|
|
256
|
+
export declare const Info: () => Promise<CatalogInfo>;
|
|
257
|
+
/**
|
|
258
|
+
* Every relation the connection can see, in the given schemas or in all of them, partitions left
|
|
259
|
+
* out: their parent is the table.
|
|
260
|
+
*/
|
|
261
|
+
export declare const ListRelations: (schemas?: string[] | undefined) => Promise<RelationSummary[]>;
|
|
262
|
+
/** The named relations, `"schema.name"`, in full. */
|
|
263
|
+
export declare const DescribeRelations: (relations: string[]) => Promise<RelationDescription[]>;
|
|
264
|
+
/**
|
|
265
|
+
* Aggregates over one relation, read without writing anything and within a time bound per
|
|
266
|
+
* measure. A large relation is sampled, and the answer says so.
|
|
267
|
+
*/
|
|
268
|
+
export declare const Profile: (request: ProfileRequest) => Promise<RelationProfile>;
|
|
269
|
+
/**
|
|
270
|
+
* Whether one column's values are found in another's, for a reference the database does not
|
|
271
|
+
* declare.
|
|
272
|
+
*/
|
|
273
|
+
export declare const CheckReference: (check: ReferenceCheck) => Promise<Measure<ReferenceMatch>>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheckReference = exports.Profile = exports.DescribeRelations = exports.ListRelations = exports.Info = void 0;
|
|
4
|
+
const interface_core_1 = require("@antelopejs/interface-core");
|
|
5
|
+
/**
|
|
6
|
+
* The connected database: engine, version, database and role.
|
|
7
|
+
*
|
|
8
|
+
* Every function of this interface refuses outside development, and on a provider instance that
|
|
9
|
+
* owns its tables rather than describing a database it was pointed at.
|
|
10
|
+
*/
|
|
11
|
+
exports.Info = (0, interface_core_1.InterfaceFunction)();
|
|
12
|
+
/**
|
|
13
|
+
* Every relation the connection can see, in the given schemas or in all of them, partitions left
|
|
14
|
+
* out: their parent is the table.
|
|
15
|
+
*/
|
|
16
|
+
exports.ListRelations = (0, interface_core_1.InterfaceFunction)();
|
|
17
|
+
/** The named relations, `"schema.name"`, in full. */
|
|
18
|
+
exports.DescribeRelations = (0, interface_core_1.InterfaceFunction)();
|
|
19
|
+
/**
|
|
20
|
+
* Aggregates over one relation, read without writing anything and within a time bound per
|
|
21
|
+
* measure. A large relation is sampled, and the answer says so.
|
|
22
|
+
*/
|
|
23
|
+
exports.Profile = (0, interface_core_1.InterfaceFunction)();
|
|
24
|
+
/**
|
|
25
|
+
* Whether one column's values are found in another's, for a reference the database does not
|
|
26
|
+
* declare.
|
|
27
|
+
*/
|
|
28
|
+
exports.CheckReference = (0, interface_core_1.InterfaceFunction)();
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Interface Database Catalog
|
|
2
|
+
|
|
3
|
+
## Reaching a provider
|
|
4
|
+
|
|
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:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
"dms-ai": {
|
|
9
|
+
importOverrides: [
|
|
10
|
+
{ interface: "@antelopejs/interface-database-catalog", source: "postgres-erp", id: "erp" },
|
|
11
|
+
],
|
|
12
|
+
},
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`GetInterfaceInstances` then lists the declared connections, and `GetInterfaceInstance(catalog, "erp")` reaches that one.
|
|
16
|
+
|
|
17
|
+
## Functions
|
|
18
|
+
|
|
19
|
+
| Function | Answers |
|
|
20
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
21
|
+
| `Info()` | engine, version, database and role of the connection |
|
|
22
|
+
| `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 |
|
|
23
|
+
| `DescribeRelations(relations)` | the named relations in full: columns with their native types and the declarations they accept, indexes, foreign keys out and in |
|
|
24
|
+
| `Profile({ relation, columns? })` | aggregates per column and per foreign key, and the traits they imply |
|
|
25
|
+
| `CheckReference({ from, to })` | how much of one column's values another column holds, for a reference the database does not declare |
|
|
26
|
+
|
|
27
|
+
Relations are named `"schema.name"`.
|
|
28
|
+
|
|
29
|
+
## What a profile answers
|
|
30
|
+
|
|
31
|
+
A profile holds aggregates, never rows:
|
|
32
|
+
|
|
33
|
+
- counts, null counts and distinct counts;
|
|
34
|
+
- the ends of number, date and enum columns, never of text columns;
|
|
35
|
+
- rows per month for date columns;
|
|
36
|
+
- lengths of text values;
|
|
37
|
+
- children per parent over each foreign key.
|
|
38
|
+
|
|
39
|
+
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.
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
## Refusals
|
|
44
|
+
|
|
45
|
+
Every function refuses:
|
|
46
|
+
|
|
47
|
+
- outside development;
|
|
48
|
+
- on a provider instance that owns its tables.
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-database-catalog",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "AntelopeJS interface for describing and profiling a connected database",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"antelopejs",
|
|
7
|
+
"catalog",
|
|
8
|
+
"database",
|
|
9
|
+
"interface"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/AntelopeJS/interface-database-catalog/tree/main/docs",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/AntelopeJS/interface-database-catalog.git"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"docs"
|
|
20
|
+
],
|
|
21
|
+
"main": "dist/index.js",
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "rimraf dist && tsc",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"format": "oxfmt .",
|
|
38
|
+
"lint:fix": "oxlint --fix",
|
|
39
|
+
"lint": "oxlint",
|
|
40
|
+
"prepack": "pnpm run build",
|
|
41
|
+
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
42
|
+
"format:check": "oxfmt --check .",
|
|
43
|
+
"knip": "knip"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@antelopejs/interface-core": ">=0.2.0 <1.0.0",
|
|
47
|
+
"@antelopejs/tooling-configs": "^0.0.8",
|
|
48
|
+
"@types/node": "^22.19.15",
|
|
49
|
+
"knip": "^6.34.0",
|
|
50
|
+
"oxfmt": "^0.66.0",
|
|
51
|
+
"oxlint": "1.81.0",
|
|
52
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
53
|
+
"release-it": "^19.2.4",
|
|
54
|
+
"release-it-changelogen": "^0.1.0",
|
|
55
|
+
"rimraf": "^6.1.3",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@antelopejs/interface-core": ">=0.2.0 <1.0.0"
|
|
60
|
+
},
|
|
61
|
+
"packageManager": "pnpm@10.6.5"
|
|
62
|
+
}
|