dsh-plugin-dbgraph-service 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/assert.d.ts +18 -0
- package/lib/assert.js +21 -0
- package/lib/brand.d.ts +36 -0
- package/lib/brand.js +35 -0
- package/lib/index.d.ts +256 -0
- package/lib/index.js +530 -0
- package/lib/invariant.d.ts +16 -0
- package/lib/invariant.js +22 -0
- package/lib/schema.d.ts +150 -0
- package/lib/schema.js +152 -0
- package/lib/tokenize.d.ts +45 -0
- package/lib/tokenize.js +205 -0
- package/lib/types.d.ts +598 -0
- package/lib/types.js +30 -0
- package/lib/zh-aliases.d.ts +72 -0
- package/lib/zh-aliases.js +246 -0
- package/package.json +62 -3
- package/README.md +0 -3
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dbgraph seam vocabulary: connection configuration, the raw catalog a dialect produces, the
|
|
3
|
+
* normalized request and result unions `ctx.dbgraph` answers, and the two provider contracts (a
|
|
4
|
+
* database dialect and the on-disk index store).
|
|
5
|
+
*
|
|
6
|
+
* Types only — {@link DbgraphError}, the branded id factories, and the `ENGINES` / `OBJECT_KINDS` /
|
|
7
|
+
* `EDGE_KINDS` vocabulary arrays are runtime and live in `index.ts` and `brand.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Two rules shape every shape below. First, **the index holds structure and never a business
|
|
10
|
+
* value**: the only data-derived field anywhere is {@link RawColumn.enumValues}, a bounded sample of
|
|
11
|
+
* distinct literals used to teach the model what `status = 'paid'` looks like. Second, **nothing here
|
|
12
|
+
* reaches the network**: execution lives behind {@link DatabaseDialect.execute}, which the service
|
|
13
|
+
* calls; the store is offline by construction.
|
|
14
|
+
* @module dsh-plugin-dbgraph-service/types
|
|
15
|
+
*/
|
|
16
|
+
import type { ConnectionId } from './brand.ts';
|
|
17
|
+
import type { StoredConnection } from './schema.ts';
|
|
18
|
+
export type { StoredConnection } from './schema.ts';
|
|
19
|
+
/** The database families a dialect can serve. */
|
|
20
|
+
export declare const ENGINES: readonly ["mysql", "postgres", "sqlite", "mongodb", "redis"];
|
|
21
|
+
/** One database family. */
|
|
22
|
+
export type Engine = (typeof ENGINES)[number];
|
|
23
|
+
/**
|
|
24
|
+
* The node categories the index format defines. Open rather than closed for the same reason the
|
|
25
|
+
* graph format is: a newer dialect may write a kind this build does not know, and a consumer must
|
|
26
|
+
* still surface it as data.
|
|
27
|
+
*/
|
|
28
|
+
export declare const OBJECT_KINDS: readonly ["table", "view", "collection", "key_pattern"];
|
|
29
|
+
/** A node category. */
|
|
30
|
+
export type ObjectKind = (typeof OBJECT_KINDS)[number];
|
|
31
|
+
/**
|
|
32
|
+
* The relationship categories the index format defines. `fk` and `view_ref` come from the server's
|
|
33
|
+
* own catalog; `index` records a real index over one or more columns; `code_ref` is filled in later
|
|
34
|
+
* by the codegraph bridge and is absent from a database-only index.
|
|
35
|
+
*/
|
|
36
|
+
export declare const EDGE_KINDS: readonly ["fk", "index", "view_ref", "code_ref"];
|
|
37
|
+
/** A relationship category. */
|
|
38
|
+
export type EdgeKind = (typeof EDGE_KINDS)[number];
|
|
39
|
+
/**
|
|
40
|
+
* One configured connection, as it is persisted. Deliberately carries no secret: the password lives
|
|
41
|
+
* in the host's credential seam under {@link ConnectionConfig.credentialRef}, and this record is what
|
|
42
|
+
* a configuration surface may render.
|
|
43
|
+
*/
|
|
44
|
+
export interface ConnectionConfig {
|
|
45
|
+
/** Stable identity; also the index directory name. See `isValidConnectionId`. */
|
|
46
|
+
readonly id: string;
|
|
47
|
+
/** Database family. */
|
|
48
|
+
readonly engine: Engine;
|
|
49
|
+
/** Human label shown in the prompt digest and in errors. */
|
|
50
|
+
readonly label?: string;
|
|
51
|
+
/** Host name, absent for a local file (SQLite). */
|
|
52
|
+
readonly host?: string;
|
|
53
|
+
/** TCP port, absent for a local file. */
|
|
54
|
+
readonly port?: number;
|
|
55
|
+
/** Database name; for SQLite the file path; for Redis a logical database index. */
|
|
56
|
+
readonly database?: string;
|
|
57
|
+
/** Login user, absent for SQLite. */
|
|
58
|
+
readonly user?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The credential-seam reference holding this connection's password. Derived from the id by
|
|
61
|
+
* `credentialRefName`, stored explicitly so a deployment may point it at its own variable.
|
|
62
|
+
*/
|
|
63
|
+
readonly credentialRef?: string;
|
|
64
|
+
/** Whether sensitive columns are masked in results (default `redact`). */
|
|
65
|
+
readonly sensitiveColumns?: SensitiveMode;
|
|
66
|
+
/** Extra column-name patterns masked in addition to the built-in list. */
|
|
67
|
+
readonly sensitivePatterns?: readonly string[];
|
|
68
|
+
}
|
|
69
|
+
/** How a result renders a column whose name or comment matches a sensitive pattern. */
|
|
70
|
+
export type SensitiveMode = 'redact' | 'show';
|
|
71
|
+
/** Everything a dialect needs to reach one server for one operation. */
|
|
72
|
+
export interface DialectInput {
|
|
73
|
+
/** The connection being served. */
|
|
74
|
+
readonly connection: ConnectionConfig;
|
|
75
|
+
/**
|
|
76
|
+
* The resolved plaintext password, when the seam supplied one. Re-resolved per operation by the
|
|
77
|
+
* caller — a dialect must never cache it across calls.
|
|
78
|
+
*/
|
|
79
|
+
readonly password?: string;
|
|
80
|
+
/** Distinct-value sample size used for {@link RawColumn.enumValues}. */
|
|
81
|
+
readonly enumSampleLimit: number;
|
|
82
|
+
/** Per-statement timeout. */
|
|
83
|
+
readonly queryTimeoutMs: number;
|
|
84
|
+
/** Aborts the operation. */
|
|
85
|
+
readonly signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
/** The answer to a connection test. */
|
|
88
|
+
export interface DialectProbe {
|
|
89
|
+
/** Whether a round-trip succeeded. */
|
|
90
|
+
readonly ok: boolean;
|
|
91
|
+
/** Server version string, when the engine reports one. */
|
|
92
|
+
readonly serverVersion?: string;
|
|
93
|
+
/** Failure detail, when `ok` is false. */
|
|
94
|
+
readonly error?: string;
|
|
95
|
+
/** Round-trip time in milliseconds. */
|
|
96
|
+
readonly elapsedMs: number;
|
|
97
|
+
}
|
|
98
|
+
/** Limits the service imposes on one execution, whichever dialect runs it. */
|
|
99
|
+
export interface ExecuteLimits {
|
|
100
|
+
/** Rows returned before truncation. */
|
|
101
|
+
readonly maxRows: number;
|
|
102
|
+
/** Statement timeout. */
|
|
103
|
+
readonly timeoutMs: number;
|
|
104
|
+
/** Whether to run the statement at all when it is not obviously a read. */
|
|
105
|
+
readonly readOnly: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** One raw column, as a dialect read it off the server. */
|
|
108
|
+
export interface RawColumn {
|
|
109
|
+
/** Declared name, verbatim. */
|
|
110
|
+
readonly name: string;
|
|
111
|
+
/** One-based position within the object. */
|
|
112
|
+
readonly ordinal: number;
|
|
113
|
+
/** Declared type, verbatim — normalization is the writer's job, not the dialect's. */
|
|
114
|
+
readonly type: string;
|
|
115
|
+
/** Whether the column admits NULL. */
|
|
116
|
+
readonly nullable?: boolean;
|
|
117
|
+
/** Declared default, rendered as text. */
|
|
118
|
+
readonly defaultValue?: string;
|
|
119
|
+
/** Column comment, when the server keeps one. The single most valuable field for Chinese lookup. */
|
|
120
|
+
readonly comment?: string;
|
|
121
|
+
/** Whether the column participates in the primary key. */
|
|
122
|
+
readonly isPrimaryKey?: boolean;
|
|
123
|
+
/** Whether a single-column unique constraint covers it. */
|
|
124
|
+
readonly isUnique?: boolean;
|
|
125
|
+
/** At most {@link DialectInput.enumSampleLimit} distinct literals, when sampling was requested. */
|
|
126
|
+
readonly enumValues?: readonly string[];
|
|
127
|
+
}
|
|
128
|
+
/** One raw relationship, as a dialect read it off the server. */
|
|
129
|
+
export interface RawEdge {
|
|
130
|
+
/** Relationship category. */
|
|
131
|
+
readonly kind: EdgeKind;
|
|
132
|
+
/** Constraint or index name, when the server keeps one. */
|
|
133
|
+
readonly name?: string;
|
|
134
|
+
/** Columns on the source object. */
|
|
135
|
+
readonly columns: readonly string[];
|
|
136
|
+
/** Referenced object name, for `fk` and `view_ref`. */
|
|
137
|
+
readonly refObject?: string;
|
|
138
|
+
/** Referenced columns, for `fk`. */
|
|
139
|
+
readonly refColumns?: readonly string[];
|
|
140
|
+
/** Whether the index this edge records is unique. */
|
|
141
|
+
readonly unique?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/** One raw object (table, view, collection, key pattern). */
|
|
144
|
+
export interface RawObject {
|
|
145
|
+
/** Node category. */
|
|
146
|
+
readonly kind: ObjectKind;
|
|
147
|
+
/** Namespace the object lives in (schema, or absent when the engine has none). */
|
|
148
|
+
readonly schema?: string;
|
|
149
|
+
/** Object name. */
|
|
150
|
+
readonly name: string;
|
|
151
|
+
/** Object comment. */
|
|
152
|
+
readonly comment?: string;
|
|
153
|
+
/** Approximate row count from catalog statistics — never a `COUNT(*)`. */
|
|
154
|
+
readonly rowEstimate?: number;
|
|
155
|
+
/** Columns in declared order. */
|
|
156
|
+
readonly columns: readonly RawColumn[];
|
|
157
|
+
/** Relationships leaving this object. */
|
|
158
|
+
readonly edges?: readonly RawEdge[];
|
|
159
|
+
}
|
|
160
|
+
/** One dialect's answer for one level of indexing. */
|
|
161
|
+
export interface RawCatalog {
|
|
162
|
+
/** Which engine produced this. Must equal the connection's engine. */
|
|
163
|
+
readonly engine: Engine;
|
|
164
|
+
/** Server version, when reported. */
|
|
165
|
+
readonly serverVersion?: string;
|
|
166
|
+
/** Database this snapshot describes. */
|
|
167
|
+
readonly database: string;
|
|
168
|
+
/** Every object reachable with the configured privileges. */
|
|
169
|
+
readonly objects: readonly RawObject[];
|
|
170
|
+
/** Epoch milliseconds when the snapshot was taken. */
|
|
171
|
+
readonly fetchedAt: number;
|
|
172
|
+
/** Which level this snapshot covers, so the writer never mistakes L1 for a complete catalog. */
|
|
173
|
+
readonly level: IndexLevel;
|
|
174
|
+
/** Per-object failures the dialect chose to tolerate rather than abort the whole run. */
|
|
175
|
+
readonly warnings?: readonly string[];
|
|
176
|
+
}
|
|
177
|
+
/** How much of a connection's catalog a run covers. */
|
|
178
|
+
export type IndexLevel = 'l1' | 'l2';
|
|
179
|
+
/** A dialect implements exactly one engine: probe, two fetch levels, and one execute. */
|
|
180
|
+
export interface DatabaseDialect {
|
|
181
|
+
/** The engine this dialect serves. Registration rejects a second dialect for the same engine. */
|
|
182
|
+
readonly engine: Engine;
|
|
183
|
+
/** Round-trip check, used before the first index and by the connection list. */
|
|
184
|
+
test(input: DialectInput): Promise<DialectProbe>;
|
|
185
|
+
/** Structural snapshot: object and column names and declared types. Fast enough to run inline. */
|
|
186
|
+
fetchL1(input: DialectInput): Promise<RawCatalog>;
|
|
187
|
+
/**
|
|
188
|
+
* Enrichment: comments, foreign keys, indexes, row estimates and enum samples, merged onto the L1
|
|
189
|
+
* snapshot. Slow enough to belong in a background job.
|
|
190
|
+
*/
|
|
191
|
+
fetchL2(input: DialectInput, l1: RawCatalog): Promise<RawCatalog>;
|
|
192
|
+
/**
|
|
193
|
+
* The only networked read the seam performs after indexing.
|
|
194
|
+
*
|
|
195
|
+
* `parameters` binds the statement's `?` placeholders in order. It is a separate argument rather
|
|
196
|
+
* than something folded into the statement string because the resolver produces a parameterized
|
|
197
|
+
* predicate and the seam must never inline a value the user typed.
|
|
198
|
+
*/
|
|
199
|
+
execute(input: DialectInput, query: string, limits: ExecuteLimits, parameters?: readonly unknown[]): Promise<SqlResult>;
|
|
200
|
+
}
|
|
201
|
+
/** A row as a dialect returns it. Values are already JSON-safe scalars or strings. */
|
|
202
|
+
export type Row = Readonly<Record<string, unknown>>;
|
|
203
|
+
/** The result of one executed statement. */
|
|
204
|
+
export interface SqlResult {
|
|
205
|
+
/** Column names in result order. */
|
|
206
|
+
readonly columns: readonly string[];
|
|
207
|
+
/** Returned rows. */
|
|
208
|
+
readonly rows: readonly Row[];
|
|
209
|
+
/** Rows returned, after truncation. */
|
|
210
|
+
readonly rowCount: number;
|
|
211
|
+
/** Whether {@link ExecuteLimits.maxRows} clipped the answer. */
|
|
212
|
+
readonly truncated: boolean;
|
|
213
|
+
/** Columns masked because they matched a sensitive pattern. */
|
|
214
|
+
readonly redacted: readonly string[];
|
|
215
|
+
/** Server-reported affected rows, for a non-SELECT statement. */
|
|
216
|
+
readonly affectedRows?: number;
|
|
217
|
+
/** Wall-clock time of the round trip. */
|
|
218
|
+
readonly elapsedMs: number;
|
|
219
|
+
/** Non-fatal warnings the server or the executor attached. */
|
|
220
|
+
readonly warnings?: readonly string[];
|
|
221
|
+
}
|
|
222
|
+
/** The on-disk index state of one connection, as a configuration surface renders it. */
|
|
223
|
+
export interface IndexState {
|
|
224
|
+
/** Epoch milliseconds of the last structural snapshot, absent when never indexed. */
|
|
225
|
+
readonly l1IndexedAt?: number;
|
|
226
|
+
/** Epoch milliseconds of the last enrichment pass, absent when never completed. */
|
|
227
|
+
readonly l2IndexedAt?: number;
|
|
228
|
+
/** Objects in the index. */
|
|
229
|
+
readonly objects: number;
|
|
230
|
+
/** Columns in the index. */
|
|
231
|
+
readonly columns: number;
|
|
232
|
+
/** Whether {@link l2IndexedAt} is older than the configured freshness window. */
|
|
233
|
+
readonly stale: boolean;
|
|
234
|
+
/** Which writer produced the current index. */
|
|
235
|
+
readonly writer?: IndexWriterKind;
|
|
236
|
+
}
|
|
237
|
+
/** Which implementation wrote the index. `js` is the parity reference and fallback. */
|
|
238
|
+
export type IndexWriterKind = 'js' | 'rust';
|
|
239
|
+
/** One entry of the connection list. Never carries a secret. */
|
|
240
|
+
export interface ConnectionSummary {
|
|
241
|
+
/** The connection identity. */
|
|
242
|
+
readonly id: string;
|
|
243
|
+
/** Database family. */
|
|
244
|
+
readonly engine: Engine;
|
|
245
|
+
/** Human label, when configured. */
|
|
246
|
+
readonly label?: string;
|
|
247
|
+
/** Host, when the connection is a server. */
|
|
248
|
+
readonly host?: string;
|
|
249
|
+
/** Database name, when configured. */
|
|
250
|
+
readonly database?: string;
|
|
251
|
+
/** Whether the credential seam currently resolves this connection's password. */
|
|
252
|
+
readonly credentialConfigured: boolean;
|
|
253
|
+
/** Index state, or the reason it could not be read. */
|
|
254
|
+
readonly index: IndexState;
|
|
255
|
+
}
|
|
256
|
+
/** One object in a listing, without its columns. */
|
|
257
|
+
export interface ObjectView {
|
|
258
|
+
/** Object name, qualified by schema when the engine has one. */
|
|
259
|
+
readonly object: string;
|
|
260
|
+
/** Node category. */
|
|
261
|
+
readonly kind: string;
|
|
262
|
+
/** Object comment. */
|
|
263
|
+
readonly comment?: string;
|
|
264
|
+
/** Number of indexed columns. */
|
|
265
|
+
readonly columnCount: number;
|
|
266
|
+
/** Approximate row count. */
|
|
267
|
+
readonly rowEstimate?: number;
|
|
268
|
+
}
|
|
269
|
+
/** One column in a listing. */
|
|
270
|
+
export interface ColumnView {
|
|
271
|
+
/** Column name. */
|
|
272
|
+
readonly name: string;
|
|
273
|
+
/** Declared type, verbatim. */
|
|
274
|
+
readonly type: string;
|
|
275
|
+
/** Whether the column admits NULL. */
|
|
276
|
+
readonly nullable: boolean;
|
|
277
|
+
/** Declared default, rendered as text. */
|
|
278
|
+
readonly defaultValue?: string;
|
|
279
|
+
/** Column comment. */
|
|
280
|
+
readonly comment?: string;
|
|
281
|
+
/** Whether the column participates in the primary key. */
|
|
282
|
+
readonly isPrimaryKey: boolean;
|
|
283
|
+
/** Whether a single-column unique constraint covers it. */
|
|
284
|
+
readonly isUnique: boolean;
|
|
285
|
+
/** Sampled distinct literals, when the enrichment pass captured them. */
|
|
286
|
+
readonly enumValues?: readonly string[];
|
|
287
|
+
}
|
|
288
|
+
/** Why a `find` request did or did not produce a row set. */
|
|
289
|
+
export type FindStatus = 'resolved' | 'ambiguous' | 'missing_predicate' | 'not_found';
|
|
290
|
+
/** How one column was matched to the user's words. */
|
|
291
|
+
export type MatchSource = 'name' | 'name-part' | 'comment' | 'synonym' | 'fuzzy';
|
|
292
|
+
/** One column the resolver chose, with the evidence that chose it. */
|
|
293
|
+
export interface MatchedColumn {
|
|
294
|
+
/** Column name. */
|
|
295
|
+
readonly column: string;
|
|
296
|
+
/** Column comment, when indexed. */
|
|
297
|
+
readonly comment?: string;
|
|
298
|
+
/** What made this column a hit. */
|
|
299
|
+
readonly matchedBy: MatchSource;
|
|
300
|
+
/** Which user word produced the hit, when the request named one. */
|
|
301
|
+
readonly term?: string;
|
|
302
|
+
/** Resolver score, 0..1. */
|
|
303
|
+
readonly score: number;
|
|
304
|
+
}
|
|
305
|
+
/** One object the resolver considered. */
|
|
306
|
+
export interface FindCandidate {
|
|
307
|
+
/** Object name, qualified by schema when the engine has one. */
|
|
308
|
+
readonly object: string;
|
|
309
|
+
/** Node category. */
|
|
310
|
+
readonly kind: string;
|
|
311
|
+
/** Object comment. */
|
|
312
|
+
readonly comment?: string;
|
|
313
|
+
/** Resolver score for the object, 0..1. */
|
|
314
|
+
readonly score: number;
|
|
315
|
+
/** Columns that matched inside this object. */
|
|
316
|
+
readonly columns: readonly MatchedColumn[];
|
|
317
|
+
}
|
|
318
|
+
/** The `find` request: words in, one parameterized statement out. */
|
|
319
|
+
export interface FindRequest {
|
|
320
|
+
/** Connection identity. */
|
|
321
|
+
readonly connection: string;
|
|
322
|
+
/** What the user is talking about, e.g. `用户`. Optional when `object` names a table outright. */
|
|
323
|
+
readonly entity?: string;
|
|
324
|
+
/** What the user asked for, e.g. `[密码]`. Omitted means every column. */
|
|
325
|
+
readonly fields?: readonly string[];
|
|
326
|
+
/** Predicate values, keyed by the column name the caller believes exists. */
|
|
327
|
+
readonly where?: Readonly<Record<string, unknown>>;
|
|
328
|
+
/** Table to use directly, skipping object resolution. */
|
|
329
|
+
readonly object?: string;
|
|
330
|
+
/** Rows requested (default 50, capped by the tool's configuration). */
|
|
331
|
+
readonly limit?: number;
|
|
332
|
+
}
|
|
333
|
+
/** The `find` result. */
|
|
334
|
+
export interface FindResult {
|
|
335
|
+
/** Why this answer is what it is. */
|
|
336
|
+
readonly status: FindStatus;
|
|
337
|
+
/** Causal explanation of the status, shown to the model verbatim. */
|
|
338
|
+
readonly reason: string;
|
|
339
|
+
/** The chosen object, when one was chosen. */
|
|
340
|
+
readonly resolved?: FindCandidate;
|
|
341
|
+
/** 0..1 confidence in {@link resolved}. */
|
|
342
|
+
readonly confidence: number;
|
|
343
|
+
/** Ranked alternatives, present whenever resolution was not decisive. */
|
|
344
|
+
readonly candidates?: readonly FindCandidate[];
|
|
345
|
+
/** The statement that was run, parameter placeholders included. Never includes literal values. */
|
|
346
|
+
readonly sql?: string;
|
|
347
|
+
/** Rows returned. */
|
|
348
|
+
readonly rows?: readonly Row[];
|
|
349
|
+
/** Rows returned, after truncation. */
|
|
350
|
+
readonly rowCount?: number;
|
|
351
|
+
/** Whether the row cap clipped the answer. */
|
|
352
|
+
readonly truncated?: boolean;
|
|
353
|
+
/** Columns masked by the sensitive rule. */
|
|
354
|
+
readonly redacted?: readonly string[];
|
|
355
|
+
/** Wall-clock time, including the networked execution. */
|
|
356
|
+
readonly elapsedMs: number;
|
|
357
|
+
}
|
|
358
|
+
/** Why one indexing run produced what it produced. */
|
|
359
|
+
export interface IndexReport {
|
|
360
|
+
/** Connection identity. */
|
|
361
|
+
readonly connection: string;
|
|
362
|
+
/** Level this run covered. */
|
|
363
|
+
readonly level: IndexLevel;
|
|
364
|
+
/** Objects written. */
|
|
365
|
+
readonly objects: number;
|
|
366
|
+
/** Columns written. */
|
|
367
|
+
readonly columns: number;
|
|
368
|
+
/** Edges written. */
|
|
369
|
+
readonly edges: number;
|
|
370
|
+
/** Search terms written. */
|
|
371
|
+
readonly terms: number;
|
|
372
|
+
/** Which writer ran. */
|
|
373
|
+
readonly writer: IndexWriterKind;
|
|
374
|
+
/** Wall-clock time of the whole run. */
|
|
375
|
+
readonly elapsedMs: number;
|
|
376
|
+
/** Non-fatal problems: a per-object failure, a skipped enrichment, a missing driver capability. */
|
|
377
|
+
readonly warnings: readonly string[];
|
|
378
|
+
}
|
|
379
|
+
/** What `ctx.dbgraph` exposes to a consumer. */
|
|
380
|
+
export interface DbgraphService {
|
|
381
|
+
/** Every configured connection with its index state, secrets omitted. */
|
|
382
|
+
listConnections(): Promise<readonly ConnectionSummary[]>;
|
|
383
|
+
/** One connection's structural overview, from the index. */
|
|
384
|
+
schema(request: SchemaRequest, signal?: AbortSignal): Promise<SchemaResult>;
|
|
385
|
+
/** Objects matching a query, ranked. */
|
|
386
|
+
objects(request: ObjectsRequest, signal?: AbortSignal): Promise<ObjectsResult>;
|
|
387
|
+
/** One object's columns. */
|
|
388
|
+
columns(request: ColumnsRequest, signal?: AbortSignal): Promise<ColumnsResult>;
|
|
389
|
+
/** Resolve words to an object and columns, then execute one parameterized read. */
|
|
390
|
+
find(request: FindRequest, signal?: AbortSignal): Promise<FindResult>;
|
|
391
|
+
/** Execute one statement against the server, with no semantic resolution. */
|
|
392
|
+
sql(request: SqlRequest, signal?: AbortSignal): Promise<SqlResult>;
|
|
393
|
+
/** Which objects a change to this one reaches. */
|
|
394
|
+
impact(request: ImpactRequest, signal?: AbortSignal): Promise<ImpactResult>;
|
|
395
|
+
/** Which objects reference this one. */
|
|
396
|
+
refs(request: RefsRequest, signal?: AbortSignal): Promise<RefsResult>;
|
|
397
|
+
/** Build or refresh an index, returning the first target's report. Prefer {@link indexMany}. */
|
|
398
|
+
index(request: IndexRequest, signal?: AbortSignal): Promise<IndexReport>;
|
|
399
|
+
/**
|
|
400
|
+
* Build or refresh every target connection, one report each. With no `connection`, that is every
|
|
401
|
+
* configured connection — the shape a tool needs to tell the model what actually happened, rather
|
|
402
|
+
* than the first of several runs.
|
|
403
|
+
*/
|
|
404
|
+
indexMany(request: IndexRequest, signal?: AbortSignal): Promise<IndexReport[]>;
|
|
405
|
+
}
|
|
406
|
+
/** `schema` request. */
|
|
407
|
+
export interface SchemaRequest {
|
|
408
|
+
/** Connection identity. */
|
|
409
|
+
readonly connection: string;
|
|
410
|
+
}
|
|
411
|
+
/** `schema` result. */
|
|
412
|
+
export interface SchemaResult {
|
|
413
|
+
/** Connection identity. */
|
|
414
|
+
readonly connection: string;
|
|
415
|
+
/** Database family. */
|
|
416
|
+
readonly engine: Engine;
|
|
417
|
+
/** Database name. */
|
|
418
|
+
readonly database: string;
|
|
419
|
+
/** Objects in the index, ranked by size then name. */
|
|
420
|
+
readonly objects: readonly ObjectView[];
|
|
421
|
+
/** Whether the object list was clipped. */
|
|
422
|
+
readonly truncated: boolean;
|
|
423
|
+
/** Index state. */
|
|
424
|
+
readonly index: IndexState;
|
|
425
|
+
/** Fraction of columns carrying a comment, 0..1 — tells the model how much to trust name matching. */
|
|
426
|
+
readonly commentCoverage: number;
|
|
427
|
+
}
|
|
428
|
+
/** `objects` request. */
|
|
429
|
+
export interface ObjectsRequest {
|
|
430
|
+
/** Connection identity. */
|
|
431
|
+
readonly connection: string;
|
|
432
|
+
/** Free-text query over names and comments; omitted lists the largest objects. */
|
|
433
|
+
readonly query?: string;
|
|
434
|
+
/** Maximum objects returned. */
|
|
435
|
+
readonly limit?: number;
|
|
436
|
+
}
|
|
437
|
+
/** `objects` result. */
|
|
438
|
+
export interface ObjectsResult {
|
|
439
|
+
/** Ranked matches. */
|
|
440
|
+
readonly objects: readonly ObjectView[];
|
|
441
|
+
/** Whether the cap clipped the list. */
|
|
442
|
+
readonly truncated: boolean;
|
|
443
|
+
}
|
|
444
|
+
/** `columns` request. */
|
|
445
|
+
export interface ColumnsRequest {
|
|
446
|
+
/** Connection identity. */
|
|
447
|
+
readonly connection: string;
|
|
448
|
+
/** Object name, as listed by `objects`. */
|
|
449
|
+
readonly object: string;
|
|
450
|
+
}
|
|
451
|
+
/** `columns` result. */
|
|
452
|
+
export interface ColumnsResult {
|
|
453
|
+
/** Object name. */
|
|
454
|
+
readonly object: string;
|
|
455
|
+
/** Node category. */
|
|
456
|
+
readonly kind: string;
|
|
457
|
+
/** Object comment. */
|
|
458
|
+
readonly comment?: string;
|
|
459
|
+
/** Columns in declared order. */
|
|
460
|
+
readonly columns: readonly ColumnView[];
|
|
461
|
+
/** Whether a column cap clipped the list. */
|
|
462
|
+
readonly truncated: boolean;
|
|
463
|
+
}
|
|
464
|
+
/** `sql` request. */
|
|
465
|
+
export interface SqlRequest {
|
|
466
|
+
/** Connection identity. */
|
|
467
|
+
readonly connection: string;
|
|
468
|
+
/** The statement. Executed with the configured row cap and timeout. */
|
|
469
|
+
readonly query: string;
|
|
470
|
+
/** Rows requested, overriding the tool default. */
|
|
471
|
+
readonly limit?: number;
|
|
472
|
+
/** Statement timeout in milliseconds. */
|
|
473
|
+
readonly timeoutMs?: number;
|
|
474
|
+
}
|
|
475
|
+
/** `impact` / `refs` request. */
|
|
476
|
+
export interface ImpactRequest {
|
|
477
|
+
/** Connection identity. */
|
|
478
|
+
readonly connection: string;
|
|
479
|
+
/** Object name. */
|
|
480
|
+
readonly object: string;
|
|
481
|
+
}
|
|
482
|
+
/** `refs` request. */
|
|
483
|
+
export interface RefsRequest {
|
|
484
|
+
/** Connection identity. */
|
|
485
|
+
readonly connection: string;
|
|
486
|
+
/** Object name. */
|
|
487
|
+
readonly object: string;
|
|
488
|
+
}
|
|
489
|
+
/** One edge touching the object a request named. */
|
|
490
|
+
export interface RelationView {
|
|
491
|
+
/** Relationship category. */
|
|
492
|
+
readonly kind: EdgeKind;
|
|
493
|
+
/** The object on the other end. */
|
|
494
|
+
readonly object: string;
|
|
495
|
+
/** Column on this side. */
|
|
496
|
+
readonly column?: string;
|
|
497
|
+
/** Column on the other side. */
|
|
498
|
+
readonly refColumn?: string;
|
|
499
|
+
/** Constraint or index name. */
|
|
500
|
+
readonly name?: string;
|
|
501
|
+
}
|
|
502
|
+
/** `impact` result. */
|
|
503
|
+
export interface ImpactResult {
|
|
504
|
+
/** Object named in the request. */
|
|
505
|
+
readonly object: string;
|
|
506
|
+
/** Objects a change to it reaches. */
|
|
507
|
+
readonly entries: readonly RelationView[];
|
|
508
|
+
/** Whether the cap clipped the list. */
|
|
509
|
+
readonly truncated: boolean;
|
|
510
|
+
}
|
|
511
|
+
/** `refs` result. */
|
|
512
|
+
export interface RefsResult {
|
|
513
|
+
/** Object named in the request. */
|
|
514
|
+
readonly object: string;
|
|
515
|
+
/** Objects referencing it, from the database catalog. */
|
|
516
|
+
readonly entries: readonly RelationView[];
|
|
517
|
+
/** Whether the cap clipped the list. */
|
|
518
|
+
readonly truncated: boolean;
|
|
519
|
+
}
|
|
520
|
+
/** `index` request. */
|
|
521
|
+
export interface IndexRequest {
|
|
522
|
+
/** Connection identity, or every configured connection when omitted. */
|
|
523
|
+
readonly connection?: string;
|
|
524
|
+
/** Which level to build. `full` runs L1 then L2. */
|
|
525
|
+
readonly mode: 'l1' | 'l2' | 'full';
|
|
526
|
+
/** Sample size for enum values; the connection's own configuration wins when larger. */
|
|
527
|
+
readonly enumSampleLimit?: number;
|
|
528
|
+
/** Force the JavaScript writer even when the native one is available. */
|
|
529
|
+
readonly writer?: IndexWriterKind | 'auto';
|
|
530
|
+
}
|
|
531
|
+
/** The offline half of the seam: read the index, and write it. */
|
|
532
|
+
export interface DbgraphStore {
|
|
533
|
+
/** Store identity, for diagnostics and conflict messages. */
|
|
534
|
+
readonly id: string;
|
|
535
|
+
/**
|
|
536
|
+
* Absolute directory this store keeps its files under, when it has one. Read by the tool so the
|
|
537
|
+
* prompt digest and the index resolve the same root instead of each deriving its own.
|
|
538
|
+
*/
|
|
539
|
+
readonly root?: string;
|
|
540
|
+
/** The connections this store's configuration file lists. */
|
|
541
|
+
connections(): Promise<readonly StoredConnection[]>;
|
|
542
|
+
/** State of one connection's index. */
|
|
543
|
+
state(connection: string): Promise<IndexState>;
|
|
544
|
+
/** Structural overview. */
|
|
545
|
+
schema(request: SchemaRequest): Promise<SchemaResult>;
|
|
546
|
+
/** Object listing. */
|
|
547
|
+
objects(request: ObjectsRequest): Promise<ObjectsResult>;
|
|
548
|
+
/** Column listing. */
|
|
549
|
+
columns(request: ColumnsRequest): Promise<ColumnsResult>;
|
|
550
|
+
/** Resolve a request to a candidate and a `WHERE` plan, without touching the network. */
|
|
551
|
+
resolve(request: FindRequest): Promise<Resolution>;
|
|
552
|
+
/** Objects a change reaches. */
|
|
553
|
+
impact(request: ImpactRequest): Promise<ImpactResult>;
|
|
554
|
+
/** Objects referencing this one. */
|
|
555
|
+
refs(request: RefsRequest): Promise<RefsResult>;
|
|
556
|
+
/** Write a snapshot. Replaces the connection's index atomically. */
|
|
557
|
+
write(connection: ConnectionId, catalog: RawCatalog, options: WriteOptions): Promise<IndexReport>;
|
|
558
|
+
}
|
|
559
|
+
/** What the store needs beyond the catalog itself. */
|
|
560
|
+
export interface WriteOptions {
|
|
561
|
+
/** Which writer to prefer. */
|
|
562
|
+
readonly writer: IndexWriterKind | 'auto';
|
|
563
|
+
/** Alias table handed to the writer, so the word table exists in exactly one place. */
|
|
564
|
+
readonly aliases: readonly AliasGroup[];
|
|
565
|
+
}
|
|
566
|
+
/** The offline answer to a `find` request. */
|
|
567
|
+
export interface Resolution {
|
|
568
|
+
/** Why resolution ended where it did. */
|
|
569
|
+
readonly status: FindStatus;
|
|
570
|
+
/** Human-readable explanation, forwarded verbatim. */
|
|
571
|
+
readonly reason: string;
|
|
572
|
+
/** The chosen candidate, when one was chosen. */
|
|
573
|
+
readonly resolved?: FindCandidate;
|
|
574
|
+
/** 0..1 confidence. */
|
|
575
|
+
readonly confidence: number;
|
|
576
|
+
/** Ranked alternatives. */
|
|
577
|
+
readonly candidates?: readonly FindCandidate[];
|
|
578
|
+
/** The `WHERE` clause the caller must execute, with `?` placeholders. */
|
|
579
|
+
readonly predicate?: PredicatePlan;
|
|
580
|
+
}
|
|
581
|
+
/** A parameterized predicate the executor binds. */
|
|
582
|
+
export interface PredicatePlan {
|
|
583
|
+
/** SQL fragment, starting with `WHERE`, or empty when there is no condition. */
|
|
584
|
+
readonly clause: string;
|
|
585
|
+
/** Values bound in placeholder order. */
|
|
586
|
+
readonly values: readonly unknown[];
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* One group of words that mean the same column. The table crosses into the native writer as JSON so
|
|
590
|
+
* the vocabulary exists once, in `zh-aliases.ts`, rather than again in Rust.
|
|
591
|
+
*/
|
|
592
|
+
export interface AliasGroup {
|
|
593
|
+
/** Canonical meaning, e.g. `password`. */
|
|
594
|
+
readonly meaning: string;
|
|
595
|
+
/** Words a user may type, e.g. `['密码', '口令', 'passwd', 'pwd']`. */
|
|
596
|
+
readonly words: readonly string[];
|
|
597
|
+
}
|
|
598
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dbgraph seam vocabulary: connection configuration, the raw catalog a dialect produces, the
|
|
3
|
+
* normalized request and result unions `ctx.dbgraph` answers, and the two provider contracts (a
|
|
4
|
+
* database dialect and the on-disk index store).
|
|
5
|
+
*
|
|
6
|
+
* Types only — {@link DbgraphError}, the branded id factories, and the `ENGINES` / `OBJECT_KINDS` /
|
|
7
|
+
* `EDGE_KINDS` vocabulary arrays are runtime and live in `index.ts` and `brand.ts`.
|
|
8
|
+
*
|
|
9
|
+
* Two rules shape every shape below. First, **the index holds structure and never a business
|
|
10
|
+
* value**: the only data-derived field anywhere is {@link RawColumn.enumValues}, a bounded sample of
|
|
11
|
+
* distinct literals used to teach the model what `status = 'paid'` looks like. Second, **nothing here
|
|
12
|
+
* reaches the network**: execution lives behind {@link DatabaseDialect.execute}, which the service
|
|
13
|
+
* calls; the store is offline by construction.
|
|
14
|
+
* @module dsh-plugin-dbgraph-service/types
|
|
15
|
+
*/
|
|
16
|
+
/** The database families a dialect can serve. */
|
|
17
|
+
export const ENGINES = ['mysql', 'postgres', 'sqlite', 'mongodb', 'redis'];
|
|
18
|
+
/**
|
|
19
|
+
* The node categories the index format defines. Open rather than closed for the same reason the
|
|
20
|
+
* graph format is: a newer dialect may write a kind this build does not know, and a consumer must
|
|
21
|
+
* still surface it as data.
|
|
22
|
+
*/
|
|
23
|
+
export const OBJECT_KINDS = ['table', 'view', 'collection', 'key_pattern'];
|
|
24
|
+
/**
|
|
25
|
+
* The relationship categories the index format defines. `fk` and `view_ref` come from the server's
|
|
26
|
+
* own catalog; `index` records a real index over one or more columns; `code_ref` is filled in later
|
|
27
|
+
* by the codegraph bridge and is absent from a database-only index.
|
|
28
|
+
*/
|
|
29
|
+
export const EDGE_KINDS = ['fk', 'index', 'view_ref', 'code_ref'];
|
|
30
|
+
//# sourceMappingURL=types.js.map
|