@askdb/sqlserver 0.1.0-beta.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for, the acceptance of support, warranty, indemnity, or
168
+ other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Yahya Gilany
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing
201
+ permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # `@askdb/sqlserver`
2
+
3
+ Microsoft SQL Server integration for AskDB. Bundles three pieces:
4
+
5
+ 1. **Dialect** — re-exports `SQLSERVER_DIALECT` from `@askdb/core`. Pass `dialect: SQLSERVER_DIALECT` to `ask()` to target SQL Server (T-SQL).
6
+ 2. **Connector** — `createSqlServerConnector()` implements the `Connector` contract from `@askdb/introspect` for live introspection mode.
7
+ 3. **Catalog runner** — `createSqlServerCatalogQueryRunner(connectionString)` returns an introspection-only `CatalogQueryRunner` backed by `mssql` (peer dependency, lazy-loaded). Introspects via `sys.*` catalog views.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @askdb/core @askdb/introspect @askdb/sqlserver
13
+ ```
14
+
15
+ `mssql` is an **optional peer dependency** — install it only when using live introspection mode:
16
+
17
+ ```bash
18
+ pnpm add mssql
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ### NL→SQL
24
+
25
+ ```ts
26
+ import { ask, loadSchema } from "@askdb/core";
27
+ import { SQLSERVER_DIALECT } from "@askdb/sqlserver";
28
+
29
+ const schema = loadSchema("./my-app.schema");
30
+
31
+ const { sql } = await ask({
32
+ question: "How many paid orders were created last month?",
33
+ schema,
34
+ model,
35
+ dialect: SQLSERVER_DIALECT,
36
+ });
37
+ ```
38
+
39
+ ### Introspection
40
+
41
+ ```ts
42
+ import { introspect } from "@askdb/introspect";
43
+ import { createSqlServerConnector, createSqlServerCatalogQueryRunner } from "@askdb/sqlserver";
44
+
45
+ const result = await introspect(
46
+ {
47
+ mode: "live",
48
+ runner: createSqlServerCatalogQueryRunner(
49
+ "Server=host,1433;Database=mydb;User Id=sa;Password=pass;",
50
+ ),
51
+ },
52
+ { outDir: "./my-app.schema", schemaId: "my-app" },
53
+ { connector: createSqlServerConnector() },
54
+ );
55
+ ```
56
+
57
+ ## Captured metadata
58
+
59
+ Tables, views, columns (SQL Server native type strings), primary keys, unique constraints, foreign keys (with referential actions), and indexes.
60
+
61
+ ## License
62
+
63
+ Apache-2.0
@@ -0,0 +1,84 @@
1
+ import type { CatalogQueryRunner, IntrospectionFilters, IntrospectionResult } from "@askdb/introspect";
2
+ import { compileTableFilters } from "./glob.js";
3
+ export type DescribeSqlServerInput = {
4
+ runner: CatalogQueryRunner;
5
+ filters?: IntrospectionFilters;
6
+ /** Optional `schemaId` for the resulting `SqlSchema`. Defaults to `"introspected"`. */
7
+ schemaId?: string;
8
+ };
9
+ /** Internal: the catalog SQL strings, exposed for snapshot-based tests. */
10
+ export declare const SQLSERVER_CATALOG_SQL: {
11
+ readonly tables: "SELECT\n s.name AS schema_name,\n t.name AS table_name,\n 'BASE TABLE' AS table_type\nFROM sys.tables t\nJOIN sys.schemas s ON s.schema_id = t.schema_id\nUNION ALL\nSELECT\n s.name AS schema_name,\n v.name AS table_name,\n 'VIEW' AS table_type\nFROM sys.views v\nJOIN sys.schemas s ON s.schema_id = v.schema_id\nORDER BY schema_name, table_name";
12
+ readonly views: "SELECT\n s.name AS schema_name,\n v.name AS view_name,\n m.definition AS view_definition\nFROM sys.views v\nJOIN sys.schemas s ON s.schema_id = v.schema_id\nLEFT JOIN sys.sql_modules m ON m.object_id = v.object_id\nORDER BY s.name, v.name";
13
+ readonly columns: "SELECT\n s.name AS schema_name,\n o.name AS table_name,\n c.name AS column_name,\n c.column_id AS ordinal_position,\n typ.name AS type_name,\n c.max_length AS max_length,\n c.precision AS precision_v,\n c.scale AS scale,\n c.is_nullable AS is_nullable\nFROM sys.columns c\nJOIN sys.objects o ON o.object_id = c.object_id\nJOIN sys.schemas s ON s.schema_id = o.schema_id\nJOIN sys.types typ ON typ.user_type_id = c.user_type_id\nWHERE o.type IN ('U','V')\nORDER BY s.name, o.name, c.column_id";
14
+ readonly constraints: "SELECT\n s.name AS schema_name,\n t.name AS table_name,\n i.name AS constraint_name,\n c.name AS column_name,\n ic.key_ordinal AS ordinal_position,\n CASE WHEN i.is_primary_key = 1 THEN 'PRIMARY KEY' ELSE 'UNIQUE' END AS constraint_type\nFROM sys.indexes i\nJOIN sys.tables t ON t.object_id = i.object_id\nJOIN sys.schemas s ON s.schema_id = t.schema_id\nJOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id\nJOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id\nWHERE (i.is_primary_key = 1 OR i.is_unique_constraint = 1)\n AND ic.is_included_column = 0\nORDER BY s.name, t.name, i.name, ic.key_ordinal";
15
+ readonly foreign_keys: "SELECT\n s.name AS schema_name,\n pt.name AS table_name,\n fk.name AS constraint_name,\n pc.name AS column_name,\n fkc.constraint_column_id AS ordinal_position,\n rs.name AS referenced_schema,\n rt.name AS referenced_table,\n rc.name AS referenced_column,\n fk.update_referential_action AS update_action,\n fk.delete_referential_action AS delete_action\nFROM sys.foreign_keys fk\nJOIN sys.tables pt ON pt.object_id = fk.parent_object_id\nJOIN sys.schemas s ON s.schema_id = pt.schema_id\nJOIN sys.tables rt ON rt.object_id = fk.referenced_object_id\nJOIN sys.schemas rs ON rs.schema_id = rt.schema_id\nJOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id\nJOIN sys.columns pc ON pc.object_id = fkc.parent_object_id AND pc.column_id = fkc.parent_column_id\nJOIN sys.columns rc ON rc.object_id = fkc.referenced_object_id AND rc.column_id = fkc.referenced_column_id\nORDER BY s.name, pt.name, fk.name, fkc.constraint_column_id";
16
+ readonly indexes: "SELECT\n s.name AS schema_name,\n t.name AS table_name,\n i.name AS index_name,\n c.name AS column_name,\n ic.key_ordinal AS ordinal_position,\n i.is_unique AS is_unique,\n i.type_desc AS method\nFROM sys.indexes i\nJOIN sys.tables t ON t.object_id = i.object_id\nJOIN sys.schemas s ON s.schema_id = t.schema_id\nJOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id\nJOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id\nWHERE i.is_primary_key = 0\n AND i.is_unique_constraint = 0\n AND i.name IS NOT NULL\n AND ic.is_included_column = 0\nORDER BY s.name, t.name, i.name, ic.key_ordinal";
17
+ };
18
+ type TableRow = {
19
+ schema_name: string;
20
+ table_name: string;
21
+ table_type: "BASE TABLE" | "VIEW";
22
+ };
23
+ type ViewRow = {
24
+ schema_name: string;
25
+ view_name: string;
26
+ view_definition: string | null;
27
+ };
28
+ type ColumnRow = {
29
+ schema_name: string;
30
+ table_name: string;
31
+ column_name: string;
32
+ ordinal_position: number;
33
+ type_name: string;
34
+ max_length: number;
35
+ precision_v: number;
36
+ scale: number;
37
+ is_nullable: 0 | 1 | boolean;
38
+ };
39
+ type ConstraintRow = {
40
+ schema_name: string;
41
+ table_name: string;
42
+ constraint_name: string;
43
+ column_name: string;
44
+ ordinal_position: number;
45
+ constraint_type: "PRIMARY KEY" | "UNIQUE";
46
+ };
47
+ type ForeignKeyRow = {
48
+ schema_name: string;
49
+ table_name: string;
50
+ constraint_name: string;
51
+ column_name: string;
52
+ ordinal_position: number;
53
+ referenced_schema: string;
54
+ referenced_table: string;
55
+ referenced_column: string;
56
+ update_action: number;
57
+ delete_action: number;
58
+ };
59
+ type IndexRow = {
60
+ schema_name: string;
61
+ table_name: string;
62
+ index_name: string;
63
+ column_name: string;
64
+ ordinal_position: number;
65
+ is_unique: 0 | 1 | boolean;
66
+ method: string;
67
+ };
68
+ export declare function describeSqlServer(input: DescribeSqlServerInput): Promise<IntrospectionResult>;
69
+ type FoldInput = {
70
+ schemaId: string;
71
+ tableFilter: ReturnType<typeof compileTableFilters>;
72
+ includeSchemas: ReadonlyArray<string> | undefined;
73
+ excludeSchemas: ReadonlyArray<string>;
74
+ tableRows: TableRow[];
75
+ viewRows: ViewRow[];
76
+ columnRows: ColumnRow[];
77
+ constraintRows: ConstraintRow[];
78
+ fkRows: ForeignKeyRow[];
79
+ indexRows: IndexRow[];
80
+ declaredFilters: ReadonlyArray<string>;
81
+ };
82
+ export declare function foldSqlServerResult(input: FoldInput): IntrospectionResult;
83
+ export {};
84
+ //# sourceMappingURL=describe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../../src/connector/describe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EAWpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAsBhD,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAuGF,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB;;;;;;;CAOxB,CAAC;AAEX,KAAK,QAAQ,GAAG;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,YAAY,GAAG,MAAM,CAAC;CACnC,CAAC;AACF,KAAK,OAAO,GAAG;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AACF,KAAK,SAAS,GAAG;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,C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,EAAE,CAAC;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,mBAAmB,CAyGzE"}
@@ -0,0 +1,387 @@
1
+ import { compileTableFilters } from "./glob.js";
2
+ import { makeColumnId, makeTableId } from "./ids.js";
3
+ /**
4
+ * System schemas excluded from the default introspection.
5
+ * Honors the engine-agnostic `excludeSchemas` filter additively.
6
+ */
7
+ const DEFAULT_SYSTEM_SCHEMAS = new Set([
8
+ "sys",
9
+ "INFORMATION_SCHEMA",
10
+ "db_owner",
11
+ "db_accessadmin",
12
+ "db_securityadmin",
13
+ "db_ddladmin",
14
+ "db_backupoperator",
15
+ "db_datareader",
16
+ "db_datawriter",
17
+ "db_denydatareader",
18
+ "db_denydatawriter",
19
+ "guest",
20
+ ]);
21
+ // sys.* catalog queries. Tables/views, columns (no comments/defaults yet —
22
+ // follow-up), PKs + UNIQUE constraints via sys.indexes, FKs via sys.foreign_keys,
23
+ // non-PK/non-UNIQUE indexes for completeness.
24
+ const SQL_TABLES = `SELECT
25
+ s.name AS schema_name,
26
+ t.name AS table_name,
27
+ 'BASE TABLE' AS table_type
28
+ FROM sys.tables t
29
+ JOIN sys.schemas s ON s.schema_id = t.schema_id
30
+ UNION ALL
31
+ SELECT
32
+ s.name AS schema_name,
33
+ v.name AS table_name,
34
+ 'VIEW' AS table_type
35
+ FROM sys.views v
36
+ JOIN sys.schemas s ON s.schema_id = v.schema_id
37
+ ORDER BY schema_name, table_name`;
38
+ const SQL_VIEWS = `SELECT
39
+ s.name AS schema_name,
40
+ v.name AS view_name,
41
+ m.definition AS view_definition
42
+ FROM sys.views v
43
+ JOIN sys.schemas s ON s.schema_id = v.schema_id
44
+ LEFT JOIN sys.sql_modules m ON m.object_id = v.object_id
45
+ ORDER BY s.name, v.name`;
46
+ const SQL_COLUMNS = `SELECT
47
+ s.name AS schema_name,
48
+ o.name AS table_name,
49
+ c.name AS column_name,
50
+ c.column_id AS ordinal_position,
51
+ typ.name AS type_name,
52
+ c.max_length AS max_length,
53
+ c.precision AS precision_v,
54
+ c.scale AS scale,
55
+ c.is_nullable AS is_nullable
56
+ FROM sys.columns c
57
+ JOIN sys.objects o ON o.object_id = c.object_id
58
+ JOIN sys.schemas s ON s.schema_id = o.schema_id
59
+ JOIN sys.types typ ON typ.user_type_id = c.user_type_id
60
+ WHERE o.type IN ('U','V')
61
+ ORDER BY s.name, o.name, c.column_id`;
62
+ const SQL_CONSTRAINTS = `SELECT
63
+ s.name AS schema_name,
64
+ t.name AS table_name,
65
+ i.name AS constraint_name,
66
+ c.name AS column_name,
67
+ ic.key_ordinal AS ordinal_position,
68
+ CASE WHEN i.is_primary_key = 1 THEN 'PRIMARY KEY' ELSE 'UNIQUE' END AS constraint_type
69
+ FROM sys.indexes i
70
+ JOIN sys.tables t ON t.object_id = i.object_id
71
+ JOIN sys.schemas s ON s.schema_id = t.schema_id
72
+ JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
73
+ JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
74
+ WHERE (i.is_primary_key = 1 OR i.is_unique_constraint = 1)
75
+ AND ic.is_included_column = 0
76
+ ORDER BY s.name, t.name, i.name, ic.key_ordinal`;
77
+ const SQL_FOREIGN_KEYS = `SELECT
78
+ s.name AS schema_name,
79
+ pt.name AS table_name,
80
+ fk.name AS constraint_name,
81
+ pc.name AS column_name,
82
+ fkc.constraint_column_id AS ordinal_position,
83
+ rs.name AS referenced_schema,
84
+ rt.name AS referenced_table,
85
+ rc.name AS referenced_column,
86
+ fk.update_referential_action AS update_action,
87
+ fk.delete_referential_action AS delete_action
88
+ FROM sys.foreign_keys fk
89
+ JOIN sys.tables pt ON pt.object_id = fk.parent_object_id
90
+ JOIN sys.schemas s ON s.schema_id = pt.schema_id
91
+ JOIN sys.tables rt ON rt.object_id = fk.referenced_object_id
92
+ JOIN sys.schemas rs ON rs.schema_id = rt.schema_id
93
+ JOIN sys.foreign_key_columns fkc ON fkc.constraint_object_id = fk.object_id
94
+ JOIN sys.columns pc ON pc.object_id = fkc.parent_object_id AND pc.column_id = fkc.parent_column_id
95
+ JOIN sys.columns rc ON rc.object_id = fkc.referenced_object_id AND rc.column_id = fkc.referenced_column_id
96
+ ORDER BY s.name, pt.name, fk.name, fkc.constraint_column_id`;
97
+ const SQL_INDEXES = `SELECT
98
+ s.name AS schema_name,
99
+ t.name AS table_name,
100
+ i.name AS index_name,
101
+ c.name AS column_name,
102
+ ic.key_ordinal AS ordinal_position,
103
+ i.is_unique AS is_unique,
104
+ i.type_desc AS method
105
+ FROM sys.indexes i
106
+ JOIN sys.tables t ON t.object_id = i.object_id
107
+ JOIN sys.schemas s ON s.schema_id = t.schema_id
108
+ JOIN sys.index_columns ic ON ic.object_id = i.object_id AND ic.index_id = i.index_id
109
+ JOIN sys.columns c ON c.object_id = ic.object_id AND c.column_id = ic.column_id
110
+ WHERE i.is_primary_key = 0
111
+ AND i.is_unique_constraint = 0
112
+ AND i.name IS NOT NULL
113
+ AND ic.is_included_column = 0
114
+ ORDER BY s.name, t.name, i.name, ic.key_ordinal`;
115
+ /** Internal: the catalog SQL strings, exposed for snapshot-based tests. */
116
+ export const SQLSERVER_CATALOG_SQL = {
117
+ tables: SQL_TABLES,
118
+ views: SQL_VIEWS,
119
+ columns: SQL_COLUMNS,
120
+ constraints: SQL_CONSTRAINTS,
121
+ foreign_keys: SQL_FOREIGN_KEYS,
122
+ indexes: SQL_INDEXES,
123
+ };
124
+ export async function describeSqlServer(input) {
125
+ const runner = input.runner;
126
+ const tableFilter = compileTableFilters(input.filters?.tables);
127
+ const run = async (sql) => {
128
+ const result = await runner(sql);
129
+ if (result.rows.length === 0)
130
+ return [];
131
+ const idx = new Map();
132
+ for (let i = 0; i < result.columns.length; i++)
133
+ idx.set(result.columns[i], i);
134
+ return result.rows.map((row) => {
135
+ const record = {};
136
+ for (const [name, i] of idx)
137
+ record[name] = row[i];
138
+ return record;
139
+ });
140
+ };
141
+ const [tableRows, viewRows, columnRows, constraintRows, fkRows, indexRows] = await Promise.all([
142
+ run(SQL_TABLES),
143
+ run(SQL_VIEWS),
144
+ run(SQL_COLUMNS),
145
+ run(SQL_CONSTRAINTS),
146
+ run(SQL_FOREIGN_KEYS),
147
+ run(SQL_INDEXES),
148
+ ]);
149
+ return foldSqlServerResult({
150
+ schemaId: input.schemaId ?? "introspected",
151
+ tableFilter,
152
+ includeSchemas: input.filters?.schemas,
153
+ excludeSchemas: input.filters?.excludeSchemas ?? [],
154
+ tableRows,
155
+ viewRows,
156
+ columnRows,
157
+ constraintRows,
158
+ fkRows,
159
+ indexRows,
160
+ declaredFilters: input.filters?.tables ?? [],
161
+ });
162
+ }
163
+ export function foldSqlServerResult(input) {
164
+ const warnings = [];
165
+ const includeSet = input.includeSchemas ? new Set(input.includeSchemas) : undefined;
166
+ const excludeSet = new Set(input.excludeSchemas);
167
+ const includes = (schemaName) => {
168
+ if (DEFAULT_SYSTEM_SCHEMAS.has(schemaName))
169
+ return false;
170
+ if (excludeSet.has(schemaName))
171
+ return false;
172
+ if (includeSet && !includeSet.has(schemaName))
173
+ return false;
174
+ return true;
175
+ };
176
+ const colsByTable = new Map();
177
+ for (const c of input.columnRows) {
178
+ if (!includes(c.schema_name))
179
+ continue;
180
+ const key = `${c.schema_name}.${c.table_name}`;
181
+ const list = colsByTable.get(key) ?? [];
182
+ list.push(c);
183
+ colsByTable.set(key, list);
184
+ }
185
+ const constraintsByTable = groupByQualified(input.constraintRows, includes);
186
+ const fksByTable = groupByQualified(input.fkRows, includes);
187
+ const indexesByTable = groupByQualified(input.indexRows, includes);
188
+ const viewDefByQualified = new Map();
189
+ for (const v of input.viewRows) {
190
+ if (!includes(v.schema_name))
191
+ continue;
192
+ if (v.view_definition)
193
+ viewDefByQualified.set(`${v.schema_name}.${v.view_name}`, v.view_definition);
194
+ }
195
+ const tablesBySchema = new Map();
196
+ const viewsBySchema = new Map();
197
+ const viewDefinitions = {};
198
+ for (const t of input.tableRows) {
199
+ if (!includes(t.schema_name))
200
+ continue;
201
+ const qualified = `${t.schema_name}.${t.table_name}`;
202
+ if (!input.tableFilter(qualified))
203
+ continue;
204
+ const cols = (colsByTable.get(qualified) ?? [])
205
+ .slice()
206
+ .sort((a, b) => a.ordinal_position - b.ordinal_position);
207
+ const constraints = constraintsByTable.get(qualified) ?? [];
208
+ const pkRows = constraints
209
+ .filter((c) => c.constraint_type === "PRIMARY KEY")
210
+ .sort((a, b) => a.ordinal_position - b.ordinal_position);
211
+ const pkColumns = pkRows.map((r) => r.column_name);
212
+ const pkSet = new Set(pkColumns);
213
+ const columns = cols.map((c) => buildColumn(t.schema_name, t.table_name, c, pkSet));
214
+ if (t.table_type === "VIEW") {
215
+ const def = viewDefByQualified.get(qualified) ?? "";
216
+ const list = viewsBySchema.get(t.schema_name) ?? [];
217
+ list.push({
218
+ schema: t.schema_name,
219
+ name: t.table_name,
220
+ definition: def,
221
+ columns,
222
+ });
223
+ viewsBySchema.set(t.schema_name, list);
224
+ viewDefinitions[makeTableId(t.schema_name, t.table_name)] = def;
225
+ continue;
226
+ }
227
+ const list = tablesBySchema.get(t.schema_name) ?? [];
228
+ list.push({
229
+ id: makeTableId(t.schema_name, t.table_name),
230
+ schema: t.schema_name,
231
+ name: t.table_name,
232
+ comment: undefined,
233
+ columns,
234
+ primaryKey: pkColumns.length > 0 ? { columns: pkColumns } : undefined,
235
+ foreignKeys: buildForeignKeys(fksByTable.get(qualified) ?? []),
236
+ uniqueConstraints: buildUniques(constraints),
237
+ indexes: buildIndexes(indexesByTable.get(qualified) ?? []),
238
+ checkConstraints: [],
239
+ });
240
+ tablesBySchema.set(t.schema_name, list);
241
+ }
242
+ const schemaNames = sortedUnique([
243
+ ...tablesBySchema.keys(),
244
+ ...viewsBySchema.keys(),
245
+ ]);
246
+ const namespaces = schemaNames.map((name) => ({
247
+ name,
248
+ tables: (tablesBySchema.get(name) ?? []).slice().sort(byName),
249
+ views: (viewsBySchema.get(name) ?? []).slice().sort(byName),
250
+ enums: [],
251
+ sequences: [],
252
+ }));
253
+ for (const pattern of input.declaredFilters) {
254
+ const matched = namespaces.some((ns) => ns.tables.some((t) => compileTableFilters([pattern])(`${ns.name}.${t.name}`)) ||
255
+ ns.views.some((v) => compileTableFilters([pattern])(`${ns.name}.${v.name}`)));
256
+ if (!matched)
257
+ warnings.push({ code: "ambiguous_filter", filter: pattern });
258
+ }
259
+ const schema = { schemaId: input.schemaId, schemas: namespaces };
260
+ const isEmpty = namespaces.length === 0;
261
+ return { schema, warnings, isEmpty, viewDefinitions, provider: "sqlserver" };
262
+ }
263
+ function buildColumn(schemaName, tableName, c, pkSet) {
264
+ // Render a precision-aware type string for the prompt — e.g. `nvarchar(255)`,
265
+ // `decimal(10,2)`. `max_length` is in bytes; for nvarchar/nchar it's 2 × chars
266
+ // (we surface bytes here; consumers don't need the unit).
267
+ const dataType = renderType(c);
268
+ return {
269
+ id: makeColumnId(schemaName, tableName, c.column_name),
270
+ name: c.column_name,
271
+ ordinalPosition: c.ordinal_position,
272
+ dataType,
273
+ udtName: c.type_name,
274
+ nullable: c.is_nullable === 1 || c.is_nullable === true,
275
+ primaryKey: pkSet.has(c.column_name),
276
+ defaultExpression: undefined,
277
+ comment: undefined,
278
+ };
279
+ }
280
+ function renderType(c) {
281
+ const t = c.type_name.toLowerCase();
282
+ if (t === "decimal" || t === "numeric")
283
+ return `${c.type_name}(${c.precision_v},${c.scale})`;
284
+ if (t === "char" || t === "varchar" || t === "binary" || t === "varbinary") {
285
+ return c.max_length === -1 ? `${c.type_name}(max)` : `${c.type_name}(${c.max_length})`;
286
+ }
287
+ if (t === "nchar" || t === "nvarchar") {
288
+ if (c.max_length === -1)
289
+ return `${c.type_name}(max)`;
290
+ // nchar/nvarchar max_length is bytes (= 2 × chars).
291
+ return `${c.type_name}(${Math.floor(c.max_length / 2)})`;
292
+ }
293
+ return c.type_name;
294
+ }
295
+ function buildUniques(rows) {
296
+ const byName = new Map();
297
+ for (const r of rows) {
298
+ if (r.constraint_type !== "UNIQUE")
299
+ continue;
300
+ const list = byName.get(r.constraint_name) ?? [];
301
+ list.push(r);
302
+ byName.set(r.constraint_name, list);
303
+ }
304
+ return Array.from(byName, ([name, list]) => ({
305
+ name,
306
+ columns: list
307
+ .slice()
308
+ .sort((a, b) => a.ordinal_position - b.ordinal_position)
309
+ .map((r) => r.column_name),
310
+ })).sort((a, b) => a.name.localeCompare(b.name));
311
+ }
312
+ function buildForeignKeys(rows) {
313
+ const byName = new Map();
314
+ for (const r of rows) {
315
+ const list = byName.get(r.constraint_name) ?? [];
316
+ list.push(r);
317
+ byName.set(r.constraint_name, list);
318
+ }
319
+ const fks = [];
320
+ for (const [name, list] of byName) {
321
+ const ordered = list.slice().sort((a, b) => a.ordinal_position - b.ordinal_position);
322
+ const sample = ordered[0];
323
+ fks.push({
324
+ name,
325
+ columns: ordered.map((r) => r.column_name),
326
+ references: {
327
+ schema: sample.referenced_schema,
328
+ table: sample.referenced_table,
329
+ columns: ordered.map((r) => r.referenced_column),
330
+ },
331
+ onDelete: mapAction(sample.delete_action),
332
+ onUpdate: mapAction(sample.update_action),
333
+ });
334
+ }
335
+ return fks.sort((a, b) => a.name.localeCompare(b.name));
336
+ }
337
+ function mapAction(code) {
338
+ switch (code) {
339
+ case 0:
340
+ return "no action";
341
+ case 1:
342
+ return "cascade";
343
+ case 2:
344
+ return "set null";
345
+ case 3:
346
+ return "set default";
347
+ default:
348
+ return undefined;
349
+ }
350
+ }
351
+ function buildIndexes(rows) {
352
+ const byName = new Map();
353
+ for (const r of rows) {
354
+ const list = byName.get(r.index_name) ?? [];
355
+ list.push(r);
356
+ byName.set(r.index_name, list);
357
+ }
358
+ return Array.from(byName, ([name, list]) => {
359
+ const ordered = list.slice().sort((a, b) => a.ordinal_position - b.ordinal_position);
360
+ const sample = ordered[0];
361
+ return {
362
+ name,
363
+ columns: ordered.map((r) => r.column_name),
364
+ unique: sample.is_unique === 1 || sample.is_unique === true,
365
+ method: sample.method,
366
+ };
367
+ }).sort((a, b) => a.name.localeCompare(b.name));
368
+ }
369
+ function groupByQualified(rows, includes) {
370
+ const out = new Map();
371
+ for (const r of rows) {
372
+ if (!includes(r.schema_name))
373
+ continue;
374
+ const key = `${r.schema_name}.${r.table_name}`;
375
+ const list = out.get(key) ?? [];
376
+ list.push(r);
377
+ out.set(key, list);
378
+ }
379
+ return out;
380
+ }
381
+ function sortedUnique(values) {
382
+ return Array.from(new Set(values)).sort((a, b) => a.localeCompare(b));
383
+ }
384
+ function byName(a, b) {
385
+ return a.name.localeCompare(b.name);
386
+ }
387
+ //# sourceMappingURL=describe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.js","sourceRoot":"","sources":["../../src/connector/describe.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErD;;;GAGG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAS;IAC7C,KAAK;IACL,oBAAoB;IACpB,UAAU;IACV,gBAAgB;IAChB,kBAAkB;IAClB,aAAa;IACb,mBAAmB;IACnB,eAAe;IACf,eAAe;IACf,mBAAmB;IACnB,mBAAmB;IACnB,OAAO;CACR,CAAC,CAAC;AASH,2EAA2E;AAC3E,kFAAkF;AAClF,8CAA8C;AAE9C,MAAM,UAAU,GAAG;;;;;;;;;;;;;iCAac,CAAC;AAElC,MAAM,SAAS,GAAG;;;;;;;wBAOM,CAAC;AAEzB,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;qCAeiB,CAAC;AAE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AC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,MAAM,CAA6B,CAAI,EAAE,CAAI;IACpD,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type GlobMatcher = (qualifiedName: string) => boolean;
2
+ export declare function compileTableFilters(patterns: ReadonlyArray<string> | undefined): GlobMatcher;
3
+ //# sourceMappingURL=glob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/connector/glob.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,WAAW,GAAG,CAAC,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC;AAE7D,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,SAAS,GAC1C,WAAW,CAIb"}
@@ -0,0 +1,23 @@
1
+ /** Minimal glob matcher — identical to the postgres / mysql / sqlite connectors. */
2
+ function compileGlob(pattern) {
3
+ let out = "^";
4
+ for (const ch of pattern) {
5
+ if (ch === "*")
6
+ out += ".*";
7
+ else if (ch === "?")
8
+ out += ".";
9
+ else if (/[.+^${}()|[\]\\]/.test(ch))
10
+ out += "\\" + ch;
11
+ else
12
+ out += ch;
13
+ }
14
+ out += "$";
15
+ return new RegExp(out);
16
+ }
17
+ export function compileTableFilters(patterns) {
18
+ if (!patterns || patterns.length === 0)
19
+ return () => true;
20
+ const compiled = patterns.map(compileGlob);
21
+ return (qualifiedName) => compiled.some((re) => re.test(qualifiedName));
22
+ }
23
+ //# sourceMappingURL=glob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/connector/glob.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,SAAS,WAAW,CAAC,OAAe;IAClC,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACzB,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,IAAI,CAAC;aACvB,IAAI,EAAE,KAAK,GAAG;YAAE,GAAG,IAAI,GAAG,CAAC;aAC3B,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC;;YAClD,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IACD,GAAG,IAAI,GAAG,CAAC;IACX,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAID,MAAM,UAAU,mBAAmB,CACjC,QAA2C;IAE3C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC;IAC1D,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** Schema v2 ID conventions — aligned with the postgres / mysql / sqlite connectors. */
2
+ export declare function makeTableId(schemaName: string, tableName: string): string;
3
+ export declare function makeColumnId(schemaName: string, tableName: string, columnName: string): string;
4
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/connector/ids.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,MAAM,CAER"}
@@ -0,0 +1,8 @@
1
+ /** Schema v2 ID conventions — aligned with the postgres / mysql / sqlite connectors. */
2
+ export function makeTableId(schemaName, tableName) {
3
+ return `table:${schemaName}.${tableName}`;
4
+ }
5
+ export function makeColumnId(schemaName, tableName, columnName) {
6
+ return `table:${schemaName}.${tableName}#${columnName}`;
7
+ }
8
+ //# sourceMappingURL=ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/connector/ids.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAC,UAAkB,EAAE,SAAiB;IAC/D,OAAO,SAAS,UAAU,IAAI,SAAS,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,UAAkB,EAClB,SAAiB,EACjB,UAAkB;IAElB,OAAO,SAAS,UAAU,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { CatalogQueryRunner, Connector, IntrospectionFilters } from "@askdb/introspect";
2
+ /**
3
+ * Connector input for `@askdb/sqlserver`. Live introspection only — supply a
4
+ * `CatalogQueryRunner` (e.g. from {@link createSqlServerCatalogQueryRunner}).
5
+ */
6
+ export type SqlServerIntrospectionInput = {
7
+ mode: "live";
8
+ runner: CatalogQueryRunner;
9
+ filters?: IntrospectionFilters;
10
+ };
11
+ export declare function createSqlServerConnector(): Connector<SqlServerIntrospectionInput>;
12
+ export { describeSqlServer, SQLSERVER_CATALOG_SQL } from "./describe.js";
13
+ export type { DescribeSqlServerInput } from "./describe.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EAErB,MAAM,mBAAmB,CAAC;AAG3B;;;GAGG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,CAAC;AAEF,wBAAgB,wBAAwB,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAMjF;AAED,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACzE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { describeSqlServer } from "./describe.js";
2
+ export function createSqlServerConnector() {
3
+ return {
4
+ async describe(input) {
5
+ return describeSqlServer({ runner: input.runner, filters: input.filters });
6
+ },
7
+ };
8
+ }
9
+ export { describeSqlServer, SQLSERVER_CATALOG_SQL } from "./describe.js";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connector/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAYlD,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,KAAK,CAAC,QAAQ,CAAC,KAAkC;YAC/C,OAAO,iBAAiB,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CatalogQueryRunner } from "@askdb/introspect";
2
+ export type { CatalogQueryResult, CatalogQueryRunner } from "@askdb/introspect";
3
+ /** @internal exposed for tests that need to reset the lazy `mssql` cache. */
4
+ export declare function __resetMssqlModuleCacheForTests(): void;
5
+ /**
6
+ * Build the built-in `mssql`-backed catalog query runner used by live SQL
7
+ * Server introspection. `connectionString` follows the standard mssql URI
8
+ * (`mssql://user:pass@host:port/database`) or the Server=...; format.
9
+ */
10
+ export declare function createSqlServerCatalogQueryRunner(connectionString: string): CatalogQueryRunner;
11
+ //# sourceMappingURL=sqlserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlserver.d.ts","sourceRoot":"","sources":["../../src/exec/sqlserver.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEhF,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA2BhF,6EAA6E;AAC7E,wBAAgB,+BAA+B,IAAI,IAAI,CAEtD;AAkCD;;;;GAIG;AACH,wBAAgB,iCAAiC,CAAC,gBAAgB,EAAE,MAAM,GAAG,kBAAkB,CAE9F"}
@@ -0,0 +1,60 @@
1
+ import { AskDbError } from "@askdb/core";
2
+ /**
3
+ * Lazily resolve the optional `mssql` peer dependency. Mirrors the lazy-load
4
+ * pattern in `@askdb/postgres` / `@askdb/mysql` so consumers with a custom
5
+ * `CatalogQueryRunner` can import `@askdb/sqlserver` without `mssql` installed.
6
+ */
7
+ let mssqlModulePromise;
8
+ async function loadMssqlOrThrow() {
9
+ if (!mssqlModulePromise) {
10
+ mssqlModulePromise = import("mssql").catch((cause) => {
11
+ mssqlModulePromise = undefined;
12
+ throw new AskDbError("The built-in SQL Server catalog query runner requires the optional `mssql` peer dependency. " +
13
+ "Install it (e.g. `pnpm add mssql`) or pass a custom catalog query runner to the SQL Server connector.", cause);
14
+ });
15
+ }
16
+ return mssqlModulePromise;
17
+ }
18
+ /** @internal exposed for tests that need to reset the lazy `mssql` cache. */
19
+ export function __resetMssqlModuleCacheForTests() {
20
+ mssqlModulePromise = undefined;
21
+ }
22
+ async function runSqlServerCatalogQuery(connectionString, sql, params) {
23
+ const mod = await loadMssqlOrThrow();
24
+ const mssql = mod.default ?? mod;
25
+ const pool = new mssql.ConnectionPool(connectionString);
26
+ await pool.connect();
27
+ try {
28
+ const request = pool.request();
29
+ // The connector currently issues only literal SQL (no parameters); honour
30
+ // optional params via positional binding in case a custom caller plugs in.
31
+ if (params) {
32
+ for (let i = 0; i < params.length; i++) {
33
+ request.input(`p${i}`, params[i]);
34
+ }
35
+ }
36
+ const result = await request.query(sql);
37
+ const rows = result.recordset ?? [];
38
+ const columns = rows.length > 0 ? Object.keys(rows[0]) : [];
39
+ const data = rows.map((row) => columns.map((c) => (row[c] === undefined ? null : row[c])));
40
+ return { columns, rows: data };
41
+ }
42
+ catch (e) {
43
+ if (e instanceof AskDbError)
44
+ throw e;
45
+ const message = e instanceof Error ? e.message : String(e);
46
+ throw new AskDbError(`SQL Server catalog query failed: ${message}`, e);
47
+ }
48
+ finally {
49
+ await pool.close();
50
+ }
51
+ }
52
+ /**
53
+ * Build the built-in `mssql`-backed catalog query runner used by live SQL
54
+ * Server introspection. `connectionString` follows the standard mssql URI
55
+ * (`mssql://user:pass@host:port/database`) or the Server=...; format.
56
+ */
57
+ export function createSqlServerCatalogQueryRunner(connectionString) {
58
+ return (sql, params) => runSqlServerCatalogQuery(connectionString, sql, params);
59
+ }
60
+ //# sourceMappingURL=sqlserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlserver.js","sourceRoot":"","sources":["../../src/exec/sqlserver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASzC;;;;GAIG;AACH,IAAI,kBAAoD,CAAC;AAEzD,KAAK,UAAU,gBAAgB;IAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACxB,kBAAkB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACnD,kBAAkB,GAAG,SAAS,CAAC;YAC/B,MAAM,IAAI,UAAU,CAClB,8FAA8F;gBAC5F,uGAAuG,EACzG,KAAK,CACN,CAAC;QACJ,CA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AAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,YAAY,UAAU;YAAE,MAAM,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3D,MAAM,IAAI,UAAU,CAAC,oCAAoC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,CAAC,gBAAwB;IACxE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,wBAAwB,CAAC,gBAAgB,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@askdb/sqlserver` — Microsoft SQL Server (T-SQL) integration for AskDB.
3
+ *
4
+ * Pairs with `SQLSERVER_DIALECT` from `@askdb/core`. This package ships only
5
+ * the introspection connector and the `mssql`-backed catalog runner; the
6
+ * NL→SQL prompt + validator live in `@askdb/core`.
7
+ */
8
+ export { SQLSERVER_DIALECT, type DialectSpec as SqlServerDialect, } from "@askdb/core";
9
+ export { createSqlServerConnector, describeSqlServer, SQLSERVER_CATALOG_SQL, type DescribeSqlServerInput, type SqlServerIntrospectionInput, } from "./connector/index.js";
10
+ export { createSqlServerCatalogQueryRunner, type CatalogQueryResult, type CatalogQueryRunner, } from "./exec/sqlserver.js";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,EACjB,KAAK,WAAW,IAAI,gBAAgB,GACrC,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,GACjC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,iCAAiC,EACjC,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `@askdb/sqlserver` — Microsoft SQL Server (T-SQL) integration for AskDB.
3
+ *
4
+ * Pairs with `SQLSERVER_DIALECT` from `@askdb/core`. This package ships only
5
+ * the introspection connector and the `mssql`-backed catalog runner; the
6
+ * NL→SQL prompt + validator live in `@askdb/core`.
7
+ */
8
+ export { SQLSERVER_DIALECT, } from "@askdb/core";
9
+ export { createSqlServerConnector, describeSqlServer, SQLSERVER_CATALOG_SQL, } from "./connector/index.js";
10
+ export { createSqlServerCatalogQueryRunner, } from "./exec/sqlserver.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,iBAAiB,GAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GAGtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,iCAAiC,GAGlC,MAAM,qBAAqB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@askdb/sqlserver",
3
+ "version": "0.1.0-beta.1",
4
+ "description": "AskDB Microsoft SQL Server integration: introspection connector via sys.* catalog views and an mssql-backed catalog query runner. Pairs with @askdb/core's SQLSERVER_DIALECT.",
5
+ "keywords": [
6
+ "askdb",
7
+ "sqlserver",
8
+ "mssql",
9
+ "tsql",
10
+ "nl-to-sql",
11
+ "natural-language-to-sql",
12
+ "schema-v2",
13
+ "introspection"
14
+ ],
15
+ "homepage": "https://github.com/Ygilany/AskDB#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/Ygilany/AskDB/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Ygilany/AskDB.git",
22
+ "directory": "packages/sqlserver"
23
+ },
24
+ "license": "Apache-2.0",
25
+ "author": "Yahya Gilany",
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "README.md",
38
+ "LICENSE",
39
+ "NOTICE"
40
+ ],
41
+ "engines": {
42
+ "node": ">=20"
43
+ },
44
+ "dependencies": {
45
+ "@askdb/core": "0.5.0-beta.4",
46
+ "@askdb/introspect": "0.3.0-beta.2"
47
+ },
48
+ "peerDependencies": {
49
+ "mssql": ">=10"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "mssql": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "devDependencies": {
57
+ "@types/mssql": "^9.1.7",
58
+ "mssql": "^11.0.1",
59
+ "typescript": "^5.7.3",
60
+ "vitest": "^3.0.9"
61
+ },
62
+ "scripts": {
63
+ "build": "tsc -p tsconfig.build.json",
64
+ "lint": "tsc -p tsconfig.build.json --noEmit",
65
+ "test": "vitest run --config ../../vitest.config.ts"
66
+ }
67
+ }