dbgraph 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ZH-cn.md +32 -9
- package/README.md +32 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/introspect/base.d.ts.map +1 -1
- package/dist/introspect/base.js +8 -1
- package/dist/introspect/base.js.map +1 -1
- package/dist/introspect/connection.d.ts +5 -0
- package/dist/introspect/connection.d.ts.map +1 -1
- package/dist/introspect/connection.js +118 -1
- package/dist/introspect/connection.js.map +1 -1
- package/dist/introspect/index.d.ts +2 -0
- package/dist/introspect/index.d.ts.map +1 -1
- package/dist/introspect/index.js +9 -1
- package/dist/introspect/index.js.map +1 -1
- package/dist/introspect/mongodb.d.ts +51 -0
- package/dist/introspect/mongodb.d.ts.map +1 -0
- package/dist/introspect/mongodb.js +271 -0
- package/dist/introspect/mongodb.js.map +1 -0
- package/dist/introspect/mssql.d.ts +69 -0
- package/dist/introspect/mssql.d.ts.map +1 -0
- package/dist/introspect/mssql.js +409 -0
- package/dist/introspect/mssql.js.map +1 -0
- package/dist/introspect/postgres.d.ts.map +1 -1
- package/dist/introspect/postgres.js +88 -82
- package/dist/introspect/postgres.js.map +1 -1
- package/dist/mcp/tools.js +3 -3
- package/dist/mcp/tools.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MongoDB Introspector
|
|
4
|
+
*
|
|
5
|
+
* Extracts collections, views, indexes, and schema validation rules
|
|
6
|
+
* from a MongoDB database. No document sampling — field-level schema
|
|
7
|
+
* is inferred from $jsonSchema validation rules only.
|
|
8
|
+
*
|
|
9
|
+
* Connection: manages its own MongoClient lifecycle (does NOT use the
|
|
10
|
+
* SQL-centric createConnection() factory in connection.ts).
|
|
11
|
+
* The driver import is guarded so a missing `mongodb` is reported at
|
|
12
|
+
* connect() time, not at module load time.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MongoDBIntrospector = void 0;
|
|
16
|
+
const base_1 = require("./base");
|
|
17
|
+
const connection_1 = require("./connection");
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Lazy MongoDB Driver Import
|
|
20
|
+
// =============================================================================
|
|
21
|
+
let mongoModule;
|
|
22
|
+
try {
|
|
23
|
+
mongoModule = require('mongodb');
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
/* handled at connect() time — see private importMongoDriver() */
|
|
27
|
+
}
|
|
28
|
+
// =============================================================================
|
|
29
|
+
// MongoDBIntrospector
|
|
30
|
+
// =============================================================================
|
|
31
|
+
class MongoDBIntrospector extends base_1.BaseIntrospector {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
super(config);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Override testConnection() — MongoDB does not use the
|
|
37
|
+
* SQL-centric createConnection() factory from connection.ts.
|
|
38
|
+
*/
|
|
39
|
+
async testConnection() {
|
|
40
|
+
try {
|
|
41
|
+
const client = await this.connectClient();
|
|
42
|
+
await client.close();
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Full schema introspection.
|
|
51
|
+
*
|
|
52
|
+
* 1. Connect to MongoDB
|
|
53
|
+
* 2. List collections (collecting regular collections and views)
|
|
54
|
+
* 3. For each collection: indexes + estimatedDocumentCount
|
|
55
|
+
* 4. Build Node[] + Edge[] with schema→collection→index hierarchy
|
|
56
|
+
* 5. Close connection and return IntrospectResult
|
|
57
|
+
*/
|
|
58
|
+
async extractAll() {
|
|
59
|
+
const startTime = Date.now();
|
|
60
|
+
const errors = [];
|
|
61
|
+
const nodes = [];
|
|
62
|
+
const edges = [];
|
|
63
|
+
let client;
|
|
64
|
+
try {
|
|
65
|
+
client = await this.connectClient();
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return {
|
|
69
|
+
nodes: [],
|
|
70
|
+
edges: [],
|
|
71
|
+
durationMs: Date.now() - startTime,
|
|
72
|
+
errors: [err.message],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const db = client.db(this.config.database);
|
|
77
|
+
const dbName = this.config.database;
|
|
78
|
+
// Warn if config.schemas is set — MongoDB has no schema layer
|
|
79
|
+
const hasSchemaFilter = this.config.schemas !== undefined &&
|
|
80
|
+
this.config.schemas.length > 0 &&
|
|
81
|
+
!this.config.schemas.includes('*');
|
|
82
|
+
if (hasSchemaFilter) {
|
|
83
|
+
errors.push(`Warning: "schemas" filter is set for MongoDB source "${this.config.alias}" ` +
|
|
84
|
+
`but MongoDB does not have a schema layer. All collections will be introspected. ` +
|
|
85
|
+
`To suppress this warning, remove "schemas" from this source's config.`);
|
|
86
|
+
}
|
|
87
|
+
// -----------------------------------------------------------------------
|
|
88
|
+
// 1. List all collections (non-system, user-accessible)
|
|
89
|
+
// -----------------------------------------------------------------------
|
|
90
|
+
const collectionsRaw = await db
|
|
91
|
+
.listCollections({}, { nameOnly: false, authorizedCollections: true })
|
|
92
|
+
.toArray();
|
|
93
|
+
// Separate regular collections, timeseries, and views;
|
|
94
|
+
// exclude system collections (system.*)
|
|
95
|
+
const collections = collectionsRaw.filter((c) => !c.name.startsWith('system.') &&
|
|
96
|
+
(!c.type || c.type === 'collection' || c.type === 'timeseries'));
|
|
97
|
+
const views = collectionsRaw.filter((c) => c.type === 'view');
|
|
98
|
+
if (collections.length === 0 && views.length === 0) {
|
|
99
|
+
errors.push('No collections or views found in database');
|
|
100
|
+
return { nodes, edges, durationMs: Date.now() - startTime, errors };
|
|
101
|
+
}
|
|
102
|
+
// -----------------------------------------------------------------------
|
|
103
|
+
// 2. Create schema (database) node
|
|
104
|
+
// -----------------------------------------------------------------------
|
|
105
|
+
const schemaNode = this.makeNode('schema', dbName, this.qn(dbName), this.schemaFilePath(dbName));
|
|
106
|
+
nodes.push(schemaNode);
|
|
107
|
+
// -----------------------------------------------------------------------
|
|
108
|
+
// 3. Process each collection
|
|
109
|
+
// -----------------------------------------------------------------------
|
|
110
|
+
for (const coll of collections) {
|
|
111
|
+
const collName = coll.name;
|
|
112
|
+
const collQual = this.qn(dbName, collName);
|
|
113
|
+
const collFp = this.schemaFilePath(dbName);
|
|
114
|
+
// Gather indexes and document count for this collection
|
|
115
|
+
let indexes = [];
|
|
116
|
+
let docCount;
|
|
117
|
+
const mongoColl = db.collection(collName);
|
|
118
|
+
try {
|
|
119
|
+
indexes = await mongoColl.indexes();
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
errors.push(`Skipping indexes for ${collName}: ${err.message}`);
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
// estimatedDocumentCount() — fast metadata read.
|
|
126
|
+
// NOTE: on sharded clusters this may be approximate.
|
|
127
|
+
docCount = await mongoColl.estimatedDocumentCount();
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
errors.push(`Skipping document count for ${collName}: ${err.message}`);
|
|
131
|
+
}
|
|
132
|
+
// Build metadata from collection options and validator
|
|
133
|
+
const collOptions = coll.options || {};
|
|
134
|
+
const validator = collOptions.validator;
|
|
135
|
+
const validationSchema = validator && validator.$jsonSchema
|
|
136
|
+
? {
|
|
137
|
+
$jsonSchema: validator.$jsonSchema,
|
|
138
|
+
...(collOptions.validationAction ? { validationAction: collOptions.validationAction } : {}),
|
|
139
|
+
...(collOptions.validationLevel ? { validationLevel: collOptions.validationLevel } : {}),
|
|
140
|
+
}
|
|
141
|
+
: undefined;
|
|
142
|
+
const collNode = this.makeNode('table', collName, collQual, collFp, {
|
|
143
|
+
metadata: {
|
|
144
|
+
documentCount: docCount,
|
|
145
|
+
...(validationSchema ? { validation: validationSchema } : {}),
|
|
146
|
+
...(collOptions.capped || collOptions.size || collOptions.max || collOptions.collation || collOptions.timeseries
|
|
147
|
+
? {
|
|
148
|
+
collectionOptions: {
|
|
149
|
+
...(collOptions.capped !== undefined ? { capped: collOptions.capped } : {}),
|
|
150
|
+
...(collOptions.size !== undefined ? { size: collOptions.size } : {}),
|
|
151
|
+
...(collOptions.max !== undefined ? { max: collOptions.max } : {}),
|
|
152
|
+
...(collOptions.collation ? { collation: collOptions.collation } : {}),
|
|
153
|
+
...(collOptions.timeseries ? { timeseries: collOptions.timeseries } : {}),
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
: {}),
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
nodes.push(collNode);
|
|
160
|
+
edges.push(this.containEdge(schemaNode.id, collNode.id));
|
|
161
|
+
// Create index nodes
|
|
162
|
+
for (const idx of indexes) {
|
|
163
|
+
const idxName = idx.name;
|
|
164
|
+
const idxQual = this.qn(dbName, collName, idxName);
|
|
165
|
+
// Determine index type from key values
|
|
166
|
+
const keyValues = Object.values(idx.key || {});
|
|
167
|
+
const SPECIAL_KEY_TYPES = new Set(['text', '2dsphere', '2d', 'hashed']);
|
|
168
|
+
const idxType = keyValues.find((v) => SPECIAL_KEY_TYPES.has(v)) || 'regular';
|
|
169
|
+
const idxNode = this.makeNode('index', idxName, idxQual, collFp, {
|
|
170
|
+
metadata: {
|
|
171
|
+
key: idx.key,
|
|
172
|
+
unique: idx.unique || false,
|
|
173
|
+
sparse: idx.sparse || undefined,
|
|
174
|
+
indexType: idxType,
|
|
175
|
+
partialFilterExpression: idx.partialFilterExpression || undefined,
|
|
176
|
+
ttl: idx.expireAfterSeconds || undefined,
|
|
177
|
+
automatic: idxName === '_id_' ? true : undefined,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
nodes.push(idxNode);
|
|
181
|
+
edges.push(this.containEdge(collNode.id, idxNode.id));
|
|
182
|
+
edges.push(this.makeEdge(collNode.id, idxNode.id, 'indexed_by'));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// -----------------------------------------------------------------------
|
|
186
|
+
// 4. Process views
|
|
187
|
+
// -----------------------------------------------------------------------
|
|
188
|
+
for (const view of views) {
|
|
189
|
+
const viewName = view.name;
|
|
190
|
+
const viewQual = this.qn(dbName, viewName);
|
|
191
|
+
const viewFp = this.schemaFilePath(dbName);
|
|
192
|
+
const viewOptions = view.options || {};
|
|
193
|
+
const viewNode = this.makeNode('view', viewName, viewQual, viewFp, {
|
|
194
|
+
signature: JSON.stringify(viewOptions.pipeline || [], null, 2),
|
|
195
|
+
metadata: {
|
|
196
|
+
viewOn: viewOptions.viewOn,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
nodes.push(viewNode);
|
|
200
|
+
edges.push(this.containEdge(schemaNode.id, viewNode.id));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
errors.push(`Introspection error: ${err.message}`);
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
if (client)
|
|
208
|
+
await client.close();
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
nodes,
|
|
212
|
+
edges,
|
|
213
|
+
durationMs: Date.now() - startTime,
|
|
214
|
+
errors,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
// ===========================================================================
|
|
218
|
+
// Private Helpers
|
|
219
|
+
// ===========================================================================
|
|
220
|
+
/**
|
|
221
|
+
* Lazy-import the mongodb driver and throw a helpful error if absent.
|
|
222
|
+
*/
|
|
223
|
+
importMongoDriver() {
|
|
224
|
+
if (!mongoModule) {
|
|
225
|
+
throw new Error(`mongodb package is not installed.\n` +
|
|
226
|
+
`Connect to ${this.config.alias} (mongodb) by running: npm install mongodb`);
|
|
227
|
+
}
|
|
228
|
+
return mongoModule;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Build a MongoDB connection URI from the config.
|
|
232
|
+
* NOTE: encodeURIComponent() is required for passwords containing
|
|
233
|
+
* special characters (@, :, /, ?, #, %). parseAuth() does raw split only.
|
|
234
|
+
*
|
|
235
|
+
* When config.srv is true, uses mongodb+srv:// protocol (Atlas/cloud).
|
|
236
|
+
* SRV mode: port is forced to undefined (DNS-resolved), TLS is auto-enabled.
|
|
237
|
+
*/
|
|
238
|
+
buildUri() {
|
|
239
|
+
const auth = (0, connection_1.parseAuth)(this.config.auth);
|
|
240
|
+
const host = this.config.host || 'localhost';
|
|
241
|
+
const port = this.config.port || 27017;
|
|
242
|
+
const protocol = this.config.srv ? 'mongodb+srv' : 'mongodb';
|
|
243
|
+
const encodedDb = encodeURIComponent(this.config.database);
|
|
244
|
+
// SRV protocol does not allow manual port — omit it
|
|
245
|
+
const hostPart = this.config.srv ? host : `${host}:${port}`;
|
|
246
|
+
if (auth.user && auth.password) {
|
|
247
|
+
return `${protocol}://${encodeURIComponent(auth.user)}:${encodeURIComponent(auth.password)}@${hostPart}/${encodedDb}`;
|
|
248
|
+
}
|
|
249
|
+
if (auth.user) {
|
|
250
|
+
return `${protocol}://${encodeURIComponent(auth.user)}@${hostPart}/${encodedDb}`;
|
|
251
|
+
}
|
|
252
|
+
return `${protocol}://${hostPart}/${encodedDb}`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Connect to MongoDB and return the MongoClient.
|
|
256
|
+
* SRV protocol forces TLS — config.ssl is ignored when srv is true.
|
|
257
|
+
*/
|
|
258
|
+
async connectClient() {
|
|
259
|
+
const mongodb = this.importMongoDriver();
|
|
260
|
+
const uri = this.buildUri();
|
|
261
|
+
const tls = this.config.srv ? true : (this.config.ssl ?? false);
|
|
262
|
+
return mongodb.MongoClient.connect(uri, {
|
|
263
|
+
tls,
|
|
264
|
+
tlsAllowInvalidCertificates: this.config.tlsInsecure ?? false,
|
|
265
|
+
connectTimeoutMS: 10_000,
|
|
266
|
+
serverSelectionTimeoutMS: 10_000,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
exports.MongoDBIntrospector = MongoDBIntrospector;
|
|
271
|
+
//# sourceMappingURL=mongodb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../../src/introspect/mongodb.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAQH,iCAA0C;AAC1C,6CAAyC;AAEzC,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF,IAAI,WAAgB,CAAC;AACrB,IAAI,CAAC;IACH,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAAC,MAAM,CAAC;IACP,iEAAiE;AACnE,CAAC;AAED,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF,MAAa,mBAAoB,SAAQ,uBAAgB;IACvD,YAAY,MAA0B;QACpC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc;QAClB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YAC1C,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,KAAK,GAAW,EAAE,CAAC;QACzB,MAAM,KAAK,GAAW,EAAE,CAAC;QAEzB,IAAI,MAAW,CAAC;QAChB,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QACtC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO;gBACL,KAAK,EAAE,EAAE;gBAC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CAAC,QAAQ,EAAE,CAAC;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC;QAChE,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE;YACtC,GAAG;YACH,2BAA2B,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,KAAK;YAC7D,gBAAgB,EAAE,MAAM;YACxB,wBAAwB,EAAE,MAAM;SACjC,CAAC,CAAC;IACL,CAAC;CACF;AA3SD,kDA2SC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MSSQL Introspector
|
|
3
|
+
*
|
|
4
|
+
* Extracts schemas, tables, columns, primary keys, foreign keys,
|
|
5
|
+
* indexes, and views from a Microsoft SQL Server database using
|
|
6
|
+
* INFORMATION_SCHEMA and sys catalog views.
|
|
7
|
+
*
|
|
8
|
+
* Connection: uses `connection.ts` which wraps the `mssql` package.
|
|
9
|
+
* The driver import is guarded so a missing `mssql` is reported at
|
|
10
|
+
* connect() time, not at module load time.
|
|
11
|
+
*
|
|
12
|
+
* MSSQL-specific metadata extracted:
|
|
13
|
+
* - Identity columns (via COLUMNPROPERTY)
|
|
14
|
+
* - Index metadata from sys.indexes / sys.index_columns / sys.columns
|
|
15
|
+
* - Schema-based organization (like PostgreSQL, unlike MySQL)
|
|
16
|
+
*/
|
|
17
|
+
import { IntrospectResult, DbConnectionConfig } from '../types';
|
|
18
|
+
import { BaseIntrospector } from './base';
|
|
19
|
+
export declare class MSSQLIntrospector extends BaseIntrospector {
|
|
20
|
+
constructor(config: DbConnectionConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Full schema introspection pipeline.
|
|
23
|
+
*
|
|
24
|
+
* 1. Connect to the MSSQL database
|
|
25
|
+
* 2. Query schemas and filter by config.schemas if provided
|
|
26
|
+
* 3. Query all structural metadata in parallel
|
|
27
|
+
* 4. Build Node[] + Edge[]
|
|
28
|
+
* 5. Close connection and return the result
|
|
29
|
+
*/
|
|
30
|
+
extractAll(): Promise<IntrospectResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Query: non-system schemas.
|
|
33
|
+
*/
|
|
34
|
+
private querySchemas;
|
|
35
|
+
/**
|
|
36
|
+
* Query: tables and views (BASE TABLE or VIEW).
|
|
37
|
+
*/
|
|
38
|
+
private queryTables;
|
|
39
|
+
/**
|
|
40
|
+
* Query: columns with identity detection via COLUMNPROPERTY.
|
|
41
|
+
*/
|
|
42
|
+
private queryColumns;
|
|
43
|
+
/**
|
|
44
|
+
* Query: columns that are part of a PRIMARY KEY constraint.
|
|
45
|
+
*/
|
|
46
|
+
private queryPrimaryKeys;
|
|
47
|
+
/**
|
|
48
|
+
* Query: foreign key columns + referential actions.
|
|
49
|
+
*
|
|
50
|
+
* Uses sys.foreign_keys / sys.foreign_key_columns catalog views
|
|
51
|
+
* (faster than the INFORMATION_SCHEMA 4-table join).
|
|
52
|
+
* Referential action codes are mapped via CASE:
|
|
53
|
+
* 0 = NO ACTION, 1 = CASCADE, 2 = SET_NULL, 3 = SET_DEFAULT
|
|
54
|
+
*/
|
|
55
|
+
private queryForeignKeys;
|
|
56
|
+
/**
|
|
57
|
+
* Query: index columns from sys.indexes / sys.index_columns / sys.columns.
|
|
58
|
+
*
|
|
59
|
+
* MSSQL does NOT expose index metadata in INFORMATION_SCHEMA, so we query
|
|
60
|
+
* the sys catalog views instead. Returns one row per (index × column),
|
|
61
|
+
* grouped later in the build step.
|
|
62
|
+
*/
|
|
63
|
+
private queryIndexes;
|
|
64
|
+
/**
|
|
65
|
+
* Query: view definitions.
|
|
66
|
+
*/
|
|
67
|
+
private queryViews;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=mssql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mssql.d.ts","sourceRoot":"","sources":["../../src/introspect/mssql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAKnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAuE1C,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,MAAM,EAAE,kBAAkB;IAItC;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAyP7C;;OAEG;YACW,YAAY;IAU1B;;OAEG;YACW,WAAW;IAkBzB;;OAEG;YACW,YAAY;IAyB1B;;OAEG;YACW,gBAAgB;IAyB9B;;;;;;;OAOG;YACW,gBAAgB;IA2C9B;;;;;;OAMG;YACW,YAAY;IA0B1B;;OAEG;YACW,UAAU;CAgBzB"}
|