@kozou/introspect 0.0.1 → 0.1.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 +202 -0
- package/dist/checks.d.ts +4 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +34 -0
- package/dist/checks.js.map +1 -0
- package/dist/enums.d.ts +4 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +22 -0
- package/dist/enums.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -0
- package/dist/filter.d.ts +10 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +94 -0
- package/dist/filter.js.map +1 -0
- package/dist/fks.d.ts +4 -0
- package/dist/fks.d.ts.map +1 -0
- package/dist/fks.js +61 -0
- package/dist/fks.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/tables.d.ts +5 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +142 -0
- package/dist/tables.js.map +1 -0
- package/dist/views.d.ts +4 -0
- package/dist/views.d.ts.map +1 -0
- package/dist/views.js +90 -0
- package/dist/views.js.map +1 -0
- package/package.json +42 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/checks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.d.ts","sourceRoot":"","sources":["../src/checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAiB5C,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC,CAgClC"}
|
package/dist/checks.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { runQuery } from './errors.js';
|
|
2
|
+
const CHECK_SKIN_RE = /^CHECK \((.*)\)$/s;
|
|
3
|
+
function stripCheckSkin(def) {
|
|
4
|
+
const m = CHECK_SKIN_RE.exec(def);
|
|
5
|
+
return m ? m[1] : def;
|
|
6
|
+
}
|
|
7
|
+
export async function fetchChecks(client, schemas) {
|
|
8
|
+
const result = new Map();
|
|
9
|
+
if (schemas.length === 0)
|
|
10
|
+
return result;
|
|
11
|
+
const rows = await runQuery(client, `SELECT
|
|
12
|
+
n.nspname AS schema,
|
|
13
|
+
c.relname AS table,
|
|
14
|
+
con.conname AS name,
|
|
15
|
+
pg_get_constraintdef(con.oid, true) AS definition
|
|
16
|
+
FROM pg_constraint con
|
|
17
|
+
JOIN pg_class c ON c.oid = con.conrelid
|
|
18
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
19
|
+
WHERE con.contype = 'c'
|
|
20
|
+
AND con.conrelid <> 0
|
|
21
|
+
AND n.nspname = ANY($1)
|
|
22
|
+
ORDER BY n.nspname, c.relname, con.conname`, [schemas], 'fetchChecks');
|
|
23
|
+
for (const row of rows) {
|
|
24
|
+
const key = `${row.schema}.${row.table}`;
|
|
25
|
+
if (!result.has(key))
|
|
26
|
+
result.set(key, []);
|
|
27
|
+
result.get(key).push({
|
|
28
|
+
name: row.name,
|
|
29
|
+
expression: stripCheckSkin(row.definition),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checks.js","sourceRoot":"","sources":["../src/checks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AASvC,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAE1C,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAc,EACd,OAAiB;IAEjB,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IAExC,MAAM,IAAI,GAAG,MAAM,QAAQ,CACzB,MAAM,EACN;;;;;;;;;;;gDAW4C,EAC5C,CAAC,OAAO,CAAC,EACT,aAAa,CACd,CAAC;IAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,UAAU,EAAE,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC;SAC3C,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/enums.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAS3C,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAyBtF"}
|
package/dist/enums.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { runQuery } from './errors.js';
|
|
2
|
+
export async function fetchEnums(client, schemas) {
|
|
3
|
+
if (schemas.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const rows = await runQuery(client, `SELECT
|
|
6
|
+
n.nspname AS schema,
|
|
7
|
+
t.typname AS name,
|
|
8
|
+
array_agg(e.enumlabel ORDER BY e.enumsortorder) AS values
|
|
9
|
+
FROM pg_type t
|
|
10
|
+
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
11
|
+
JOIN pg_enum e ON e.enumtypid = t.oid
|
|
12
|
+
WHERE t.typtype = 'e'
|
|
13
|
+
AND n.nspname = ANY($1)
|
|
14
|
+
GROUP BY n.nspname, t.typname
|
|
15
|
+
ORDER BY n.nspname, t.typname`, [schemas], 'fetchEnums');
|
|
16
|
+
return rows.map((row) => ({
|
|
17
|
+
schema: row.schema,
|
|
18
|
+
name: row.name,
|
|
19
|
+
values: row.values,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=enums.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc,EAAE,OAAiB;IAChE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,IAAI,GAAG,MAAM,QAAQ,CACzB,MAAM,EACN;;;;;;;;;;mCAU+B,EAC/B,CAAC,OAAO,CAAC,EACT,YAAY,CACb,CAAC;IAEF,OAAO,IAAI,CAAC,GAAG,CAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACjC,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE,GAAG,CAAC,MAAM;KACnB,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Client } from 'pg';
|
|
2
|
+
export type KozouIntrospectErrorOptions = {
|
|
3
|
+
/** The failed SQL body. Omitted on connection failure. */
|
|
4
|
+
query?: string;
|
|
5
|
+
/** PostgreSQL error code (e.g. "42501") */
|
|
6
|
+
pgErrorCode?: string;
|
|
7
|
+
/** The original error object (forwarded via the standard Error.cause field). */
|
|
8
|
+
cause?: unknown;
|
|
9
|
+
};
|
|
10
|
+
export declare class KozouIntrospectError extends Error {
|
|
11
|
+
readonly query?: string;
|
|
12
|
+
readonly pgErrorCode?: string;
|
|
13
|
+
constructor(message: string, options?: KozouIntrospectErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
export declare function runQuery<R extends Record<string, unknown>>(client: Client, query: string, params: unknown[], context: string): Promise<R[]>;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAEjC,MAAM,MAAM,2BAA2B,GAAG;IACxC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAClB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC;CAMvE;AAQD,wBAAsB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9D,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,OAAO,EAAE,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,EAAE,CAAC,CAYd"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class KozouIntrospectError extends Error {
|
|
2
|
+
query;
|
|
3
|
+
pgErrorCode;
|
|
4
|
+
constructor(message, options = {}) {
|
|
5
|
+
super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
|
|
6
|
+
this.name = 'KozouIntrospectError';
|
|
7
|
+
this.query = options.query;
|
|
8
|
+
this.pgErrorCode = options.pgErrorCode;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function isPgErrorLike(value) {
|
|
12
|
+
return typeof value === 'object' && value !== null;
|
|
13
|
+
}
|
|
14
|
+
export async function runQuery(client, query, params, context) {
|
|
15
|
+
try {
|
|
16
|
+
const res = await client.query(query, params);
|
|
17
|
+
return res.rows;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
const pgErr = isPgErrorLike(err) ? err : {};
|
|
21
|
+
throw new KozouIntrospectError(`${context}: ${pgErr.message ?? String(err)}`, {
|
|
22
|
+
query,
|
|
23
|
+
pgErrorCode: pgErr.code,
|
|
24
|
+
cause: err,
|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CAAC,IAAI;YACvB,KAAK,EAAE,GAAG;SACX,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RawTable, RawView } from '@kozou/core';
|
|
2
|
+
export type FilterOptions = {
|
|
3
|
+
include?: readonly string[];
|
|
4
|
+
exclude?: readonly string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function shouldRetain(qualified: string, includeRes: readonly RegExp[], excludeRes: readonly RegExp[]): boolean;
|
|
7
|
+
export declare function filterTables(tables: readonly RawTable[], opts: FilterOptions): RawTable[];
|
|
8
|
+
export declare function filterViews(views: readonly RawView[], opts: FilterOptions): RawView[];
|
|
9
|
+
export declare function pruneDanglingForeignKeys(tables: RawTable[]): void;
|
|
10
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AA2CpE,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B,CAAC;AASF,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,OAAO,CAQT;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,IAAI,EAAE,aAAa,GAClB,QAAQ,EAAE,CASZ;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,IAAI,EAAE,aAAa,GAClB,OAAO,EAAE,CASX;AAMD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAWjE"}
|
package/dist/filter.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Convert one user-facing glob into a RegExp that matches a fully
|
|
2
|
+
// qualified `schema.name` string.
|
|
3
|
+
//
|
|
4
|
+
// - Supported wildcards: `*` (zero or more chars except `.`) and `?`
|
|
5
|
+
// (exactly one char except `.`). All other regex metacharacters are
|
|
6
|
+
// escaped, so callers can safely use names containing `+`, `(`, etc.
|
|
7
|
+
// - A pattern without a `.` is treated as `*.<pattern>` so users can
|
|
8
|
+
// write `users` to mean "the `users` table in any schema".
|
|
9
|
+
// - `*` does not cross schema boundaries: `*.users` matches
|
|
10
|
+
// `public.users` but not `public.audit.users` (which is not a valid
|
|
11
|
+
// PostgreSQL identifier anyway, but the constraint keeps the
|
|
12
|
+
// semantics predictable).
|
|
13
|
+
function compilePattern(pattern) {
|
|
14
|
+
const qualified = pattern.includes('.') ? pattern : `*.${pattern}`;
|
|
15
|
+
let body = '';
|
|
16
|
+
for (const ch of qualified) {
|
|
17
|
+
if (ch === '*') {
|
|
18
|
+
body += '[^.]*';
|
|
19
|
+
}
|
|
20
|
+
else if (ch === '?') {
|
|
21
|
+
body += '[^.]';
|
|
22
|
+
}
|
|
23
|
+
else if (/[.+^${}()|[\]\\]/.test(ch)) {
|
|
24
|
+
body += `\\${ch}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
body += ch;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return new RegExp(`^${body}$`);
|
|
31
|
+
}
|
|
32
|
+
function compilePatterns(patterns) {
|
|
33
|
+
if (!patterns || patterns.length === 0)
|
|
34
|
+
return [];
|
|
35
|
+
return patterns.map(compilePattern);
|
|
36
|
+
}
|
|
37
|
+
function matchesAny(qualified, regexes) {
|
|
38
|
+
for (const re of regexes) {
|
|
39
|
+
if (re.test(qualified))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// Returns true if `qualified` should be retained given the filter.
|
|
45
|
+
// Semantics:
|
|
46
|
+
// - If `include` is non-empty, the name must match at least one include
|
|
47
|
+
// pattern.
|
|
48
|
+
// - If `exclude` is non-empty, the name must not match any exclude
|
|
49
|
+
// pattern.
|
|
50
|
+
// - Both lists can be combined; exclude wins over include on conflict.
|
|
51
|
+
export function shouldRetain(qualified, includeRes, excludeRes) {
|
|
52
|
+
if (includeRes.length > 0 && !matchesAny(qualified, includeRes)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (excludeRes.length > 0 && matchesAny(qualified, excludeRes)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
export function filterTables(tables, opts) {
|
|
61
|
+
const includeRes = compilePatterns(opts.include);
|
|
62
|
+
const excludeRes = compilePatterns(opts.exclude);
|
|
63
|
+
if (includeRes.length === 0 && excludeRes.length === 0) {
|
|
64
|
+
return [...tables];
|
|
65
|
+
}
|
|
66
|
+
return tables.filter((t) => shouldRetain(`${t.schema}.${t.name}`, includeRes, excludeRes));
|
|
67
|
+
}
|
|
68
|
+
export function filterViews(views, opts) {
|
|
69
|
+
const includeRes = compilePatterns(opts.include);
|
|
70
|
+
const excludeRes = compilePatterns(opts.exclude);
|
|
71
|
+
if (includeRes.length === 0 && excludeRes.length === 0) {
|
|
72
|
+
return [...views];
|
|
73
|
+
}
|
|
74
|
+
return views.filter((v) => shouldRetain(`${v.schema}.${v.name}`, includeRes, excludeRes));
|
|
75
|
+
}
|
|
76
|
+
// When a table is filtered out, any FK that points to it becomes a
|
|
77
|
+
// dangling reference. Drop those FKs so downstream consumers (graph
|
|
78
|
+
// builder in @kozou/core, MCP responses) never have to handle
|
|
79
|
+
// references to tables that aren't in `tables`.
|
|
80
|
+
export function pruneDanglingForeignKeys(tables) {
|
|
81
|
+
const present = new Set();
|
|
82
|
+
for (const t of tables)
|
|
83
|
+
present.add(`${t.schema}.${t.name}`);
|
|
84
|
+
for (const t of tables) {
|
|
85
|
+
const kept = [];
|
|
86
|
+
for (const fk of t.foreignKeys) {
|
|
87
|
+
const target = `${fk.referencedSchema}.${fk.referencedTable}`;
|
|
88
|
+
if (present.has(target))
|
|
89
|
+
kept.push(fk);
|
|
90
|
+
}
|
|
91
|
+
t.foreignKeys = kept;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAEA,kEAAkE;AAClE,kCAAkC;AAClC,EAAE;AACF,qEAAqE;AACrE,sEAAsE;AACtE,uEAAuE;AACvE,qEAAqE;AACrE,6DAA6D;AAC7D,4DAA4D;AAC5D,sEAAsE;AACtE,+DAA+D;AAC/D,4BAA4B;AAC5B,SAAS,cAAc,CAAC,OAAe;IACrC,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;IACnE,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACf,IAAI,IAAI,OAAO,CAAC;QAClB,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACtB,IAAI,IAAI,MAAM,CAAC;QACjB,CAAC;aAAM,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YACvC,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,eAAe,CAA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CAAC,CAAC;QACzC,CAAC;QACD,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC;IACvB,CAAC;AACH,CAAC"}
|
package/dist/fks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fks.d.ts","sourceRoot":"","sources":["../src/fks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAY,aAAa,EAAE,MAAM,aAAa,CAAC;AA4B3D,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC,CAsDvC"}
|
package/dist/fks.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { runQuery } from './errors.js';
|
|
2
|
+
const ACTION_MAP = {
|
|
3
|
+
a: 'NO ACTION',
|
|
4
|
+
r: 'RESTRICT',
|
|
5
|
+
c: 'CASCADE',
|
|
6
|
+
n: 'SET NULL',
|
|
7
|
+
d: 'SET DEFAULT',
|
|
8
|
+
};
|
|
9
|
+
function mapAction(code) {
|
|
10
|
+
return ACTION_MAP[code] ?? 'NO ACTION';
|
|
11
|
+
}
|
|
12
|
+
export async function fetchForeignKeys(client, schemas) {
|
|
13
|
+
const result = new Map();
|
|
14
|
+
if (schemas.length === 0)
|
|
15
|
+
return result;
|
|
16
|
+
const rows = await runQuery(client, `SELECT
|
|
17
|
+
n.nspname AS schema,
|
|
18
|
+
c.relname AS table,
|
|
19
|
+
con.conname AS name,
|
|
20
|
+
(
|
|
21
|
+
SELECT array_agg(a.attname ORDER BY ord.n)::text[]
|
|
22
|
+
FROM unnest(con.conkey) WITH ORDINALITY AS ord(attnum, n)
|
|
23
|
+
JOIN pg_attribute a ON a.attrelid = con.conrelid AND a.attnum = ord.attnum
|
|
24
|
+
) AS columns,
|
|
25
|
+
rn.nspname AS referenced_schema,
|
|
26
|
+
rc.relname AS referenced_table,
|
|
27
|
+
(
|
|
28
|
+
SELECT array_agg(a.attname ORDER BY ord.n)::text[]
|
|
29
|
+
FROM unnest(con.confkey) WITH ORDINALITY AS ord(attnum, n)
|
|
30
|
+
JOIN pg_attribute a ON a.attrelid = con.confrelid AND a.attnum = ord.attnum
|
|
31
|
+
) AS referenced_columns,
|
|
32
|
+
con.confdeltype AS on_delete,
|
|
33
|
+
con.confupdtype AS on_update,
|
|
34
|
+
d.description AS comment
|
|
35
|
+
FROM pg_constraint con
|
|
36
|
+
JOIN pg_class c ON c.oid = con.conrelid
|
|
37
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
38
|
+
JOIN pg_class rc ON rc.oid = con.confrelid
|
|
39
|
+
JOIN pg_namespace rn ON rn.oid = rc.relnamespace
|
|
40
|
+
LEFT JOIN pg_description d ON d.objoid = con.oid AND d.classoid = 'pg_constraint'::regclass
|
|
41
|
+
WHERE con.contype = 'f'
|
|
42
|
+
AND n.nspname = ANY($1)
|
|
43
|
+
ORDER BY n.nspname, c.relname, con.conname`, [schemas], 'fetchForeignKeys');
|
|
44
|
+
for (const row of rows) {
|
|
45
|
+
const key = `${row.schema}.${row.table}`;
|
|
46
|
+
if (!result.has(key))
|
|
47
|
+
result.set(key, []);
|
|
48
|
+
result.get(key).push({
|
|
49
|
+
name: row.name,
|
|
50
|
+
columns: row.columns ?? [],
|
|
51
|
+
referencedSchema: row.referenced_schema,
|
|
52
|
+
referencedTable: row.referenced_table,
|
|
53
|
+
referencedColumns: row.referenced_columns ?? [],
|
|
54
|
+
onDelete: mapAction(row.on_delete),
|
|
55
|
+
onUpdate: mapAction(row.on_update),
|
|
56
|
+
comment: row.comment,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=fks.js.map
|
package/dist/fks.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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AAG,CAAC,SAAS,CAAC;YAClC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;YAClC,OAAO,EAAE,GAAG,CAAC,OAAO;SACrB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClientConfig } from 'pg';
|
|
2
|
+
import type { RawIntrospection } from '@kozou/core';
|
|
3
|
+
import { KozouIntrospectError } from './errors.js';
|
|
4
|
+
export type IntrospectOptions = {
|
|
5
|
+
connection: string | ClientConfig;
|
|
6
|
+
schemas?: string[];
|
|
7
|
+
include?: string[];
|
|
8
|
+
exclude?: string[];
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
export { KozouIntrospectError };
|
|
12
|
+
export type { KozouIntrospectErrorOptions } from './errors.js';
|
|
13
|
+
export declare function introspect(opts: IntrospectOptions): Promise<RawIntrospection>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,OAAO,EAAE,oBAAoB,EAAY,MAAM,aAAa,CAAC;AAK7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,MAAM,GAAG,YAAY,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,YAAY,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAkB/D,wBAAsB,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4EnF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import pkg from 'pg';
|
|
2
|
+
import { fetchTables, mergeTableMetadata } from './tables.js';
|
|
3
|
+
import { fetchForeignKeys } from './fks.js';
|
|
4
|
+
import { fetchChecks } from './checks.js';
|
|
5
|
+
import { fetchViews } from './views.js';
|
|
6
|
+
import { fetchEnums } from './enums.js';
|
|
7
|
+
import { KozouIntrospectError, runQuery } from './errors.js';
|
|
8
|
+
import { filterTables, filterViews, pruneDanglingForeignKeys } from './filter.js';
|
|
9
|
+
const PgClient = pkg.Client;
|
|
10
|
+
export { KozouIntrospectError };
|
|
11
|
+
function isPgErrorLike(value) {
|
|
12
|
+
return typeof value === 'object' && value !== null;
|
|
13
|
+
}
|
|
14
|
+
async function fetchExistingSchemas(client, schemas) {
|
|
15
|
+
const rows = await runQuery(client, 'SELECT schema_name FROM information_schema.schemata WHERE schema_name = ANY($1)', [schemas], 'fetchExistingSchemas');
|
|
16
|
+
return rows.map((r) => r.schema_name);
|
|
17
|
+
}
|
|
18
|
+
export async function introspect(opts) {
|
|
19
|
+
const schemas = opts.schemas ?? ['public'];
|
|
20
|
+
const timeoutMs = opts.timeoutMs ?? 10_000;
|
|
21
|
+
const baseConfig = typeof opts.connection === 'string'
|
|
22
|
+
? { connectionString: opts.connection }
|
|
23
|
+
: { ...opts.connection };
|
|
24
|
+
const clientConfig = { ...baseConfig, statement_timeout: timeoutMs };
|
|
25
|
+
const client = new PgClient(clientConfig);
|
|
26
|
+
try {
|
|
27
|
+
await client.connect();
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
const pgErr = isPgErrorLike(err) ? err : {};
|
|
31
|
+
throw new KozouIntrospectError(`Failed to connect to PostgreSQL: ${pgErr.message ?? String(err)}`, { pgErrorCode: pgErr.code, cause: err });
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
await client.query('BEGIN');
|
|
35
|
+
await client.query('SET TRANSACTION READ ONLY');
|
|
36
|
+
const serverRows = await runQuery(client, 'SHOW server_version', [], 'showServerVersion');
|
|
37
|
+
const serverVersion = serverRows[0]?.server_version ?? 'unknown';
|
|
38
|
+
const existing = await fetchExistingSchemas(client, schemas);
|
|
39
|
+
for (const s of schemas) {
|
|
40
|
+
if (!existing.includes(s)) {
|
|
41
|
+
console.warn(`[@kozou/introspect] schema "${s}" does not exist (skip)`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const validSchemas = schemas.filter((s) => existing.includes(s));
|
|
45
|
+
const allTables = await fetchTables(client, validSchemas);
|
|
46
|
+
const fks = await fetchForeignKeys(client, validSchemas);
|
|
47
|
+
const checks = await fetchChecks(client, validSchemas);
|
|
48
|
+
mergeTableMetadata(allTables, fks, checks);
|
|
49
|
+
const allViews = await fetchViews(client, validSchemas);
|
|
50
|
+
const enums = await fetchEnums(client, validSchemas);
|
|
51
|
+
const filterOpts = { include: opts.include, exclude: opts.exclude };
|
|
52
|
+
const tables = filterTables(allTables, filterOpts);
|
|
53
|
+
pruneDanglingForeignKeys(tables);
|
|
54
|
+
const views = filterViews(allViews, filterOpts);
|
|
55
|
+
return {
|
|
56
|
+
serverVersion,
|
|
57
|
+
introspectedAt: new Date().toISOString(),
|
|
58
|
+
schemas,
|
|
59
|
+
tables,
|
|
60
|
+
views,
|
|
61
|
+
enums,
|
|
62
|
+
functions: [],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
try {
|
|
67
|
+
await client.query('ROLLBACK');
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
console.warn(`[@kozou/introspect] ROLLBACK failed (ignored): ${String(err)}`);
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
await client.end();
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
console.warn(`[@kozou/introspect] client.end failed (ignored): ${String(err)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,IAAI,CAAC;AAGrB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAElF,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC;AAU5B,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAKhC,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,MAAc,EAAE,OAAiB;IACnE,MAAM,IAAI,GAAG,MAAM,QAAQ,CACzB,MAAM,EACN,iFAAiF,EACjF,CAAC,OAAO,CAAC,EACT,sBAAsB,CACvB,CAAC;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAuB;IACtD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,CA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AK,CAAC,UAAU,CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,kDAAkD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;QACrB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,oDAAoD,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/tables.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Client } from 'pg';
|
|
2
|
+
import type { RawCheck, RawForeignKey, RawTable } from '@kozou/core';
|
|
3
|
+
export declare function fetchTables(client: Client, schemas: string[]): Promise<RawTable[]>;
|
|
4
|
+
export declare function mergeTableMetadata(tables: RawTable[], fks: Map<string, RawForeignKey[]>, checks: Map<string, RawCheck[]>): void;
|
|
5
|
+
//# sourceMappingURL=tables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,QAAQ,EAAa,aAAa,EAAY,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqC1F,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CA6JxF;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,QAAQ,EAAE,EAClB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,EACjC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,GAC9B,IAAI,CAMN"}
|
package/dist/tables.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { runQuery } from './errors.js';
|
|
2
|
+
export async function fetchTables(client, schemas) {
|
|
3
|
+
if (schemas.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const tableRows = await runQuery(client,
|
|
6
|
+
// `c.reltuples` is the planner's row-count estimate, maintained by
|
|
7
|
+
// ANALYZE / autovacuum. PostgreSQL uses -1 to mark "never
|
|
8
|
+
// analyzed", which we surface as null so downstream consumers
|
|
9
|
+
// always see "non-negative count or unknown" instead of mixing the
|
|
10
|
+
// sentinel into the numeric domain.
|
|
11
|
+
`SELECT
|
|
12
|
+
n.nspname AS schema,
|
|
13
|
+
c.relname AS name,
|
|
14
|
+
d.description AS comment,
|
|
15
|
+
CASE WHEN c.reltuples < 0 THEN NULL ELSE c.reltuples::float8 END AS row_count_estimate
|
|
16
|
+
FROM pg_class c
|
|
17
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
18
|
+
LEFT JOIN pg_description d ON d.objoid = c.oid AND d.objsubid = 0
|
|
19
|
+
WHERE c.relkind = 'r'
|
|
20
|
+
AND n.nspname = ANY($1)
|
|
21
|
+
ORDER BY n.nspname, c.relname`, [schemas], 'fetchTables (table list)');
|
|
22
|
+
if (tableRows.length === 0) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const tableNames = tableRows.map((r) => r.name);
|
|
26
|
+
const columnRows = await runQuery(client, `SELECT
|
|
27
|
+
n.nspname AS schema,
|
|
28
|
+
c.relname AS table,
|
|
29
|
+
a.attname AS name,
|
|
30
|
+
format_type(a.atttypid, a.atttypmod) AS data_type,
|
|
31
|
+
t.typname AS udt_name,
|
|
32
|
+
NOT a.attnotnull AS is_nullable,
|
|
33
|
+
pg_get_expr(ad.adbin, ad.adrelid) AS column_default,
|
|
34
|
+
d.description AS comment,
|
|
35
|
+
a.attnum::int AS position
|
|
36
|
+
FROM pg_attribute a
|
|
37
|
+
JOIN pg_class c ON c.oid = a.attrelid
|
|
38
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
39
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
|
40
|
+
LEFT JOIN pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum
|
|
41
|
+
LEFT JOIN pg_description d ON d.objoid = a.attrelid AND d.objsubid = a.attnum
|
|
42
|
+
WHERE c.relkind = 'r'
|
|
43
|
+
AND n.nspname = ANY($1)
|
|
44
|
+
AND a.attnum > 0
|
|
45
|
+
AND NOT a.attisdropped
|
|
46
|
+
ORDER BY n.nspname, c.relname, a.attnum`, [schemas], 'fetchTables (columns)');
|
|
47
|
+
const pkRows = await runQuery(client, `SELECT
|
|
48
|
+
n.nspname AS schema,
|
|
49
|
+
c.relname AS table,
|
|
50
|
+
a.attname AS column,
|
|
51
|
+
ord.n::int AS ordinal
|
|
52
|
+
FROM pg_constraint con
|
|
53
|
+
JOIN pg_class c ON c.oid = con.conrelid
|
|
54
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
55
|
+
JOIN LATERAL unnest(con.conkey) WITH ORDINALITY AS ord(attnum, n) ON true
|
|
56
|
+
JOIN pg_attribute a ON a.attrelid = con.conrelid AND a.attnum = ord.attnum
|
|
57
|
+
WHERE con.contype = 'p'
|
|
58
|
+
AND n.nspname = ANY($1)
|
|
59
|
+
ORDER BY n.nspname, c.relname, ord.n`, [schemas], 'fetchTables (primary keys)');
|
|
60
|
+
const indexRows = await runQuery(client, `SELECT
|
|
61
|
+
n.nspname AS schema,
|
|
62
|
+
t.relname AS table,
|
|
63
|
+
ic.relname AS name,
|
|
64
|
+
(
|
|
65
|
+
SELECT array_agg(a.attname ORDER BY ord.n)::text[]
|
|
66
|
+
FROM unnest(ix.indkey) WITH ORDINALITY AS ord(attnum, n)
|
|
67
|
+
JOIN pg_attribute a ON a.attrelid = ix.indrelid AND a.attnum = ord.attnum
|
|
68
|
+
) AS columns,
|
|
69
|
+
ix.indisunique AS is_unique
|
|
70
|
+
FROM pg_index ix
|
|
71
|
+
JOIN pg_class ic ON ic.oid = ix.indexrelid
|
|
72
|
+
JOIN pg_class t ON t.oid = ix.indrelid
|
|
73
|
+
JOIN pg_namespace n ON n.oid = t.relnamespace
|
|
74
|
+
WHERE t.relkind = 'r'
|
|
75
|
+
AND n.nspname = ANY($1)
|
|
76
|
+
AND NOT ix.indisprimary
|
|
77
|
+
ORDER BY n.nspname, t.relname, ic.relname`, [schemas], 'fetchTables (indexes)');
|
|
78
|
+
const tableKey = (schema, name) => `${schema}.${name}`;
|
|
79
|
+
const columnsByTable = new Map();
|
|
80
|
+
for (const row of columnRows) {
|
|
81
|
+
if (!tableNames.includes(row.table))
|
|
82
|
+
continue;
|
|
83
|
+
const key = tableKey(row.schema, row.table);
|
|
84
|
+
if (!columnsByTable.has(key))
|
|
85
|
+
columnsByTable.set(key, []);
|
|
86
|
+
columnsByTable.get(key).push({
|
|
87
|
+
name: row.name,
|
|
88
|
+
dataType: row.data_type,
|
|
89
|
+
udtName: row.udt_name,
|
|
90
|
+
nullable: row.is_nullable,
|
|
91
|
+
defaultExpr: row.column_default,
|
|
92
|
+
comment: row.comment,
|
|
93
|
+
position: row.position,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const pkByTable = new Map();
|
|
97
|
+
for (const row of pkRows) {
|
|
98
|
+
const key = tableKey(row.schema, row.table);
|
|
99
|
+
if (!pkByTable.has(key))
|
|
100
|
+
pkByTable.set(key, []);
|
|
101
|
+
pkByTable.get(key).push(row.column);
|
|
102
|
+
}
|
|
103
|
+
const indexByTable = new Map();
|
|
104
|
+
for (const row of indexRows) {
|
|
105
|
+
const key = tableKey(row.schema, row.table);
|
|
106
|
+
if (!indexByTable.has(key))
|
|
107
|
+
indexByTable.set(key, []);
|
|
108
|
+
indexByTable.get(key).push({
|
|
109
|
+
name: row.name,
|
|
110
|
+
columns: row.columns ?? [],
|
|
111
|
+
unique: row.is_unique,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return tableRows.map((row) => {
|
|
115
|
+
const key = tableKey(row.schema, row.name);
|
|
116
|
+
return {
|
|
117
|
+
schema: row.schema,
|
|
118
|
+
name: row.name,
|
|
119
|
+
comment: row.comment,
|
|
120
|
+
columns: columnsByTable.get(key) ?? [],
|
|
121
|
+
primaryKey: pkByTable.get(key) ?? [],
|
|
122
|
+
foreignKeys: [],
|
|
123
|
+
checks: [],
|
|
124
|
+
indexes: indexByTable.get(key) ?? [],
|
|
125
|
+
// pg returns float8 as a JS number; round to integer because
|
|
126
|
+
// the dev_spec contract (§7.3.1) types this as `number | null`
|
|
127
|
+
// and a fractional estimate would be misleading at the MCP
|
|
128
|
+
// surface.
|
|
129
|
+
rowCountEstimate: row.row_count_estimate === null
|
|
130
|
+
? null
|
|
131
|
+
: Math.round(row.row_count_estimate),
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export function mergeTableMetadata(tables, fks, checks) {
|
|
136
|
+
for (const table of tables) {
|
|
137
|
+
const key = `${table.schema}.${table.name}`;
|
|
138
|
+
table.foreignKeys = fks.get(key) ?? [];
|
|
139
|
+
table.checks = checks.get(key) ?? [];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAoCvC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc,EAAE,OAAiB;IACjE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,SAAS,GAAG,MAAM,QAAQ,CAC9B,MAAM;IACN,mEAAmE;IACnE,0DAA0D;IAC1D,8DAA8D;IAC9D,mEAAmE;IACnE,oCAAoC;IACpC;;;;;;;;;;mCAU+B,EAC/B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AK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,aAAa,CAAC;AA6BtD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CA0GtF"}
|
package/dist/views.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { runQuery } from './errors.js';
|
|
2
|
+
export async function fetchViews(client, schemas) {
|
|
3
|
+
if (schemas.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const viewRows = await runQuery(client, `SELECT
|
|
6
|
+
n.nspname AS schema,
|
|
7
|
+
c.relname AS name,
|
|
8
|
+
d.description AS comment,
|
|
9
|
+
pg_get_viewdef(c.oid, true) AS definition
|
|
10
|
+
FROM pg_class c
|
|
11
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
12
|
+
LEFT JOIN pg_description d ON d.objoid = c.oid AND d.objsubid = 0
|
|
13
|
+
WHERE c.relkind = 'v'
|
|
14
|
+
AND n.nspname = ANY($1)
|
|
15
|
+
ORDER BY n.nspname, c.relname`, [schemas], 'fetchViews (view list)');
|
|
16
|
+
if (viewRows.length === 0)
|
|
17
|
+
return [];
|
|
18
|
+
const columnRows = await runQuery(client, `SELECT
|
|
19
|
+
n.nspname AS schema,
|
|
20
|
+
c.relname AS view,
|
|
21
|
+
a.attname AS name,
|
|
22
|
+
format_type(a.atttypid, a.atttypmod) AS data_type,
|
|
23
|
+
t.typname AS udt_name,
|
|
24
|
+
NOT a.attnotnull AS is_nullable,
|
|
25
|
+
pg_get_expr(ad.adbin, ad.adrelid) AS column_default,
|
|
26
|
+
d.description AS comment,
|
|
27
|
+
a.attnum::int AS position
|
|
28
|
+
FROM pg_attribute a
|
|
29
|
+
JOIN pg_class c ON c.oid = a.attrelid
|
|
30
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
31
|
+
JOIN pg_type t ON t.oid = a.atttypid
|
|
32
|
+
LEFT JOIN pg_attrdef ad ON ad.adrelid = a.attrelid AND ad.adnum = a.attnum
|
|
33
|
+
LEFT JOIN pg_description d ON d.objoid = a.attrelid AND d.objsubid = a.attnum
|
|
34
|
+
WHERE c.relkind = 'v'
|
|
35
|
+
AND n.nspname = ANY($1)
|
|
36
|
+
AND a.attnum > 0
|
|
37
|
+
AND NOT a.attisdropped
|
|
38
|
+
ORDER BY n.nspname, c.relname, a.attnum`, [schemas], 'fetchViews (columns)');
|
|
39
|
+
const depRows = await runQuery(client, `SELECT DISTINCT
|
|
40
|
+
view_ns.nspname AS view_schema,
|
|
41
|
+
view_cls.relname AS view_name,
|
|
42
|
+
dep_ns.nspname AS dep_schema,
|
|
43
|
+
dep_cls.relname AS dep_name
|
|
44
|
+
FROM pg_rewrite rw
|
|
45
|
+
JOIN pg_class view_cls ON view_cls.oid = rw.ev_class
|
|
46
|
+
JOIN pg_namespace view_ns ON view_ns.oid = view_cls.relnamespace
|
|
47
|
+
JOIN pg_depend d ON d.objid = rw.oid AND d.classid = 'pg_rewrite'::regclass
|
|
48
|
+
JOIN pg_class dep_cls ON dep_cls.oid = d.refobjid AND d.refclassid = 'pg_class'::regclass
|
|
49
|
+
JOIN pg_namespace dep_ns ON dep_ns.oid = dep_cls.relnamespace
|
|
50
|
+
WHERE view_ns.nspname = ANY($1)
|
|
51
|
+
AND view_cls.relkind = 'v'
|
|
52
|
+
AND dep_cls.relkind IN ('r','v','m')
|
|
53
|
+
AND dep_cls.oid <> view_cls.oid
|
|
54
|
+
ORDER BY view_ns.nspname, view_cls.relname, dep_ns.nspname, dep_cls.relname`, [schemas], 'fetchViews (dependencies)');
|
|
55
|
+
const viewKey = (schema, name) => `${schema}.${name}`;
|
|
56
|
+
const columnsByView = new Map();
|
|
57
|
+
for (const row of columnRows) {
|
|
58
|
+
const key = viewKey(row.schema, row.view);
|
|
59
|
+
if (!columnsByView.has(key))
|
|
60
|
+
columnsByView.set(key, []);
|
|
61
|
+
columnsByView.get(key).push({
|
|
62
|
+
name: row.name,
|
|
63
|
+
dataType: row.data_type,
|
|
64
|
+
udtName: row.udt_name,
|
|
65
|
+
nullable: row.is_nullable,
|
|
66
|
+
defaultExpr: row.column_default,
|
|
67
|
+
comment: row.comment,
|
|
68
|
+
position: row.position,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const depsByView = new Map();
|
|
72
|
+
for (const row of depRows) {
|
|
73
|
+
const key = viewKey(row.view_schema, row.view_name);
|
|
74
|
+
if (!depsByView.has(key))
|
|
75
|
+
depsByView.set(key, []);
|
|
76
|
+
depsByView.get(key).push({ schema: row.dep_schema, name: row.dep_name });
|
|
77
|
+
}
|
|
78
|
+
return viewRows.map((row) => {
|
|
79
|
+
const key = viewKey(row.schema, row.name);
|
|
80
|
+
return {
|
|
81
|
+
schema: row.schema,
|
|
82
|
+
name: row.name,
|
|
83
|
+
comment: row.comment,
|
|
84
|
+
columns: columnsByView.get(key) ?? [],
|
|
85
|
+
underlyingTables: depsByView.get(key) ?? [],
|
|
86
|
+
definition: row.definition,
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=views.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.js","sourceRoot":"","sources":["../src/views.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA4BvC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc,EAAE,OAAiB;IAChE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEpC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAC7B,MAAM,EACN;;;;;;;;;;mCAU+B,EAC/B,CAAC,OAAO,CAAC,EACT,wBAAwB,CACzB,CAAC;IAEF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAErC,MAA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,GAAG,CAAC,GAAG,CAAC;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClD,UAAU,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,QAAQ,CAAC,GAAG,CAAU,CAAC,GAAG,EAAE,EAAE;QACnC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO;YACL,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE;YACrC,gBAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE;YAC3C,UAAU,EAAE,GAAG,CAAC,UAAU;SAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kozou/introspect",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "PostgreSQL DDL / COMMENT / VIEW introspection (Kozou v0.1 spec §5).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/kozou-dev/kozou.git",
|
|
9
|
+
"directory": "packages/introspect"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://kozou.org",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/kozou-dev/kozou/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"provenance": true
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"pg": "^8.13.0",
|
|
34
|
+
"@kozou/core": "0.1.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/pg": "^8.11.0",
|
|
38
|
+
"@kozou/test-utils": "0.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"test": "vitest run --coverage"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/README.md
DELETED