@lakeql/adapter-fabric 0.0.0-stage → 1.0.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/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 reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ 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 [yyyy] [name of copyright owner]
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 implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Fabric adapter core: `FabricDataSource` implementation,
3
+ * `fabricAdapterFactory`, and `fabricAdapterDefinition`.
4
+ *
5
+ * @module
6
+ */
7
+ import { validateFabricConfig } from "./config.mjs";
8
+ import { AdapterFactory, ColumnInfo, DataSource, DataSourceCapabilities, QueryProps, SourceConfig, TableDefinition } from "@lakeql/datasource";
9
+ import { FabricClient } from "@lakeql/fabric-client";
10
+ /**
11
+ * Capabilities declared by every `FabricDataSource` instance.
12
+ *
13
+ * The first adapter slice supports query, stream (simulated), and all
14
+ * metadata discovery. DDL and write are explicitly unsupported.
15
+ */
16
+ declare const FABRIC_CAPABILITIES: DataSourceCapabilities;
17
+ /**
18
+ * Fabric implementation of the adapter-neutral {@link DataSource}
19
+ * contract.
20
+ *
21
+ * Constructed exclusively through `fabricAdapterFactory.createDataSource()`.
22
+ * The class holds a single {@link FabricClient} and the runtime
23
+ * data-source name for error context.
24
+ */
25
+ declare class FabricDataSource implements DataSource {
26
+ readonly adapter: "fabric";
27
+ readonly capabilities: DataSourceCapabilities;
28
+ readonly typeMapper: import("@lakeql/datasource").TypeMapper;
29
+ /** @internal */
30
+ private readonly client;
31
+ /** @internal */
32
+ private readonly dataSourceName;
33
+ /** Tracks whether {@link close} has been called. */
34
+ private closed;
35
+ constructor(client: FabricClient, dataSourceName: string);
36
+ /**
37
+ * Execute a client operation with unified error classification.
38
+ * All errors are passed through `classifyFabricError()`.
39
+ */
40
+ private executeWithErrorHandling;
41
+ /** Throw if the data source has been closed. */
42
+ private assertNotClosed;
43
+ /**
44
+ * Extracts a bearer token from query options for OBO flow.
45
+ *
46
+ * @returns The bearer token string, or `undefined` if not provided.
47
+ */
48
+ private static extractBearerToken;
49
+ /**
50
+ * Executes a SQL query and returns all rows as keyed records.
51
+ *
52
+ * Fabric's TDS driver returns rows as keyed objects natively,
53
+ * so no row-zipper transform is needed.
54
+ */
55
+ query<TRow>(props: QueryProps): Promise<TRow[]>;
56
+ /**
57
+ * Executes a SQL query and returns rows as an asynchronous generator.
58
+ *
59
+ * Fabric does not support native streaming — this simulates it by
60
+ * running a full query and yielding rows one at a time.
61
+ */
62
+ stream<TRow>(props: QueryProps): Promise<AsyncGenerator<TRow>>;
63
+ /**
64
+ * Lists all catalogs (databases) visible to the current connection.
65
+ *
66
+ * Queries `sys.databases` and filters out system databases.
67
+ */
68
+ catalogs(): Promise<string[]>;
69
+ /**
70
+ * Lists schemas within the given catalog.
71
+ *
72
+ * Queries `INFORMATION_SCHEMA.SCHEMATA` with a bracket-quoted catalog
73
+ * identifier.
74
+ *
75
+ * @param catalog - The catalog whose schemas to list.
76
+ */
77
+ schemas(catalog: string): Promise<string[]>;
78
+ /**
79
+ * Lists base tables within the given catalog and schema.
80
+ *
81
+ * Queries `INFORMATION_SCHEMA.TABLES` with a bracket-quoted catalog
82
+ * identifier and an escaped schema literal.
83
+ *
84
+ * @param catalog - The catalog to query.
85
+ * @param schema - The schema to filter on.
86
+ */
87
+ tables(catalog: string, schema: string): Promise<string[]>;
88
+ /**
89
+ * Lists views within the given catalog and schema.
90
+ *
91
+ * Queries `INFORMATION_SCHEMA.TABLES` with a bracket-quoted catalog
92
+ * identifier, an escaped schema literal, and the `VIEW` predicate.
93
+ *
94
+ * @param catalog - The catalog to query.
95
+ * @param schema - The schema to filter on.
96
+ */
97
+ views(catalog: string, schema: string): Promise<string[]>;
98
+ /**
99
+ * Lists columns for the given fully-qualified table.
100
+ *
101
+ * Queries `INFORMATION_SCHEMA.COLUMNS` with bracket-quoted catalog
102
+ * and escaped schema/table literals.
103
+ *
104
+ * @param catalog - The catalog containing the table.
105
+ * @param schema - The schema containing the table.
106
+ * @param table - The table whose columns to list.
107
+ */
108
+ columns(catalog: string, schema: string, table: string): Promise<ColumnInfo[]>;
109
+ /**
110
+ * Not supported by Fabric adapter. Always throws
111
+ * {@link UnsupportedOperationError}.
112
+ */
113
+ createTable(_definition: TableDefinition): Promise<void>;
114
+ /**
115
+ * Not supported by Fabric adapter. Always throws
116
+ * {@link UnsupportedOperationError}.
117
+ */
118
+ dropTable(_catalog: string, _schema: string, _table: string): Promise<void>;
119
+ /**
120
+ * Returns a safely bracket-quoted Fabric qualified table name.
121
+ *
122
+ * Applies {@link quoteIdentifier} independently to each of the three
123
+ * segments (`catalog`, `schema`, `tableName`) and joins them with dots.
124
+ *
125
+ * @param config - Source configuration with catalog, schema, and tableName.
126
+ * @returns The bracket-quoted qualified identifier, e.g. `[catalog].[schema].[table]`.
127
+ * @throws {Error} If any segment is empty or contains control characters.
128
+ */
129
+ qualifiedTableName(config: SourceConfig): string;
130
+ /**
131
+ * Closes the underlying Fabric client connection.
132
+ *
133
+ * Subsequent calls resolve immediately without invoking `close()` again.
134
+ */
135
+ close(): Promise<void>;
136
+ }
137
+ /**
138
+ * Fabric adapter factory implementing the neutral {@link AdapterFactory}
139
+ * contract.
140
+ *
141
+ * The factory is stateless: it retains no mutable per-data-source state
142
+ * between calls to `createDataSource()`, `createReadStrategy()`, and
143
+ * `createWriteStrategy()`. All construction methods are synchronous and
144
+ * do not perform network requests, metadata discovery, hidden global
145
+ * registration, or environment lookup.
146
+ */
147
+ export declare const fabricAdapterFactory: AdapterFactory;
148
+ /**
149
+ * Typed-config registration value compatible with
150
+ * `AdapterDefinition<"fabric", FabricConnectionConfig>` from `@lakeql/config`
151
+ * through structural typing.
152
+ *
153
+ * The adapter package does NOT import or depend on `@lakeql/config`. This
154
+ * definition is consumed by `defineConfig()` to provide compile-time
155
+ * connection-shape inference for Fabric data sources.
156
+ *
157
+ * Intentionally omits `registrationOptions` and `mergeDataSourceConfig`
158
+ * because Fabric receives a complete explicit connection payload.
159
+ */
160
+ export declare const fabricAdapterDefinition: {
161
+ /** Literal adapter name for typed narrowing. */
162
+ readonly adapterName: "fabric";
163
+ /** The exact adapter factory instance. */
164
+ readonly factory: AdapterFactory;
165
+ /** The shared assertion-style config validator. */
166
+ readonly validateDataSourceConfig: typeof validateFabricConfig;
167
+ };
168
+ export { FABRIC_CAPABILITIES, FabricDataSource };
@@ -0,0 +1 @@
1
+ import{validateFabricConfig as e}from"./config.mjs";import{ADAPTER_NAME as t}from"./constants.mjs";import{fabricDialect as n}from"./dialect.mjs";import{classifyFabricError as r}from"./errors.mjs";import{fabricResponseNormalizer as i}from"./normalizer.mjs";import{escapeLiteral as a,quoteIdentifier as o,quoteQualifiedIdentifier as s}from"./sql-helpers.mjs";import{fabricTypeMapper as c}from"./type-mapper.mjs";import{QueryExecutionError as l,UnsupportedOperationError as u,UnsupportedWriteStrategy as d}from"@lakeql/datasource";import{FabricClient as f}from"@lakeql/fabric-client";import{createSqlReadStrategy as p}from"@lakeql/sql-read-strategy";const m={query:!0,stream:!0,metadata:{catalogs:!0,schemas:!0,tables:!0,views:!0,columns:!0},write:{supported:!1,modes:[]},ddl:{createTable:!1,dropTable:!1}},h=[`sys`,`INFORMATION_SCHEMA`,`guest`,`queryinsights`,`_rsc`];var g=class e{adapter=t;capabilities=m;typeMapper=c;client;dataSourceName;closed=!1;constructor(e,t){this.client=e,this.dataSourceName=t}async executeWithErrorHandling(e){try{return await e()}catch(e){throw r(e,this.dataSourceName)}}assertNotClosed(){if(this.closed)throw new l(`DataSource is closed`,t,this.dataSourceName)}static extractBearerToken(e){if(e.requestAuth!==void 0){if(e.requestAuth.type===`bearer`)return e.requestAuth.token;if(e.requestAuth.type===`oauth2`)return e.requestAuth.accessToken}}async query(t){this.assertNotClosed();let n=e.extractBearerToken(t);return this.executeWithErrorHandling(async()=>this.client.query({sql:t.sql,signal:t.signal,bearerToken:n}))}async stream(e){this.assertNotClosed();let t=await this.query(e);async function*n(){for(let e of t)yield e}return n()}async catalogs(){return this.assertNotClosed(),this.executeWithErrorHandling(async()=>(await this.client.query({sql:`SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb') ORDER BY name`})).map(e=>String(e.name)))}async schemas(e){this.assertNotClosed();let t=h.map(e=>a(e)).join(`, `),n=`SELECT schema_name FROM ${o(e)}.INFORMATION_SCHEMA.SCHEMATA WHERE schema_name NOT IN (${t}) AND schema_name NOT LIKE 'db[_]%' ORDER BY schema_name`;return this.executeWithErrorHandling(async()=>(await this.client.query({sql:n})).map(e=>String(e.schema_name)))}async tables(e,t){this.assertNotClosed();let n=`SELECT table_name FROM ${o(e)}.INFORMATION_SCHEMA.TABLES WHERE table_schema = ${a(t)} AND table_type = 'BASE TABLE' ORDER BY table_name`;return this.executeWithErrorHandling(async()=>(await this.client.query({sql:n})).map(e=>String(e.table_name)))}async views(e,t){this.assertNotClosed();let n=`SELECT table_name FROM ${o(e)}.INFORMATION_SCHEMA.TABLES WHERE table_schema = ${a(t)} AND table_type = 'VIEW' ORDER BY table_name`;return this.executeWithErrorHandling(async()=>(await this.client.query({sql:n})).map(e=>String(e.table_name)))}async columns(e,t,n){this.assertNotClosed();let r=`SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM ${o(e)}.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ${a(t)} AND TABLE_NAME = ${a(n)} ORDER BY ORDINAL_POSITION`;return this.executeWithErrorHandling(async()=>(await this.client.query({sql:r})).map(e=>({name:String(e.COLUMN_NAME),type:String(e.DATA_TYPE),extra:e.IS_NULLABLE===`YES`?`nullable`:void 0,description:void 0})))}async createTable(e){throw this.assertNotClosed(),new u(`Fabric adapter does not support CREATE TABLE in this adapter slice`,t,this.dataSourceName,`createTable`)}async dropTable(e,n,r){throw this.assertNotClosed(),new u(`Fabric adapter does not support DROP TABLE in this adapter slice`,t,this.dataSourceName,`dropTable`)}qualifiedTableName(e){return s(e.catalog,e.schema,e.tableName)}async close(){if(!this.closed){this.closed=!0;try{await this.client.close()}catch{}}}};const _={adapterName:t,createDataSource(t,n){e(t);let r={host:t.host,port:t.port,catalog:t.catalog,auth:t.auth};return t.source!==void 0&&(r.source=t.source),new g(new f(r),n)},createReadStrategy({dataSource:e,resolveAuth:t,paging:r}){return p({dataSource:e,resolveAuth:t,dialect:n,normalizer:i,readValidation:r?{maxPerPage:r.maxRecordsPerPage}:void 0,defaultPerPage:r?.defaultPerPage})},createWriteStrategy({dataSourceName:e}){return new d({adapter:t,dataSource:e})}},v={adapterName:t,factory:_,validateDataSourceConfig:e};export{m as FABRIC_CAPABILITIES,g as FabricDataSource,v as fabricAdapterDefinition,_ as fabricAdapterFactory};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * OAuth2 client credentials authentication for Azure AD.
3
+ */
4
+ export interface FabricOAuth2Auth {
5
+ type: "oauth2";
6
+ /** Azure AD tenant ID. */
7
+ tenantId: string;
8
+ /** Azure AD application (client) ID. */
9
+ clientId: string;
10
+ /** Azure AD client secret. */
11
+ clientSecret: string;
12
+ /** Optional scope override. */
13
+ scope?: string;
14
+ }
15
+ /**
16
+ * Bearer token authentication (e.g. pre-acquired OAuth2 token).
17
+ */
18
+ export interface FabricBearerAuth {
19
+ type: "bearer";
20
+ /** The bearer token value. */
21
+ token: string;
22
+ }
23
+ /**
24
+ * Authentication credentials for a Fabric connection — either OAuth2
25
+ * client credentials or a static bearer token.
26
+ */
27
+ export type FabricAuth = FabricOAuth2Auth | FabricBearerAuth;
28
+ /**
29
+ * Configuration for connecting to a Microsoft Fabric SQL endpoint.
30
+ *
31
+ * Fields mirror `FabricClientProps` from `@lakeql/fabric-client`. The outer
32
+ * runtime definition owns adapter selection through its `adapter` field;
33
+ * this type intentionally does not include an inner adapter discriminator.
34
+ */
35
+ export interface FabricConnectionConfig {
36
+ /** Fabric SQL endpoint hostname (e.g. `"your-endpoint.datawarehouse.fabric.microsoft.com"`). */
37
+ host: string;
38
+ /** Port the Fabric SQL endpoint listens on (typically `1433`). */
39
+ port: number;
40
+ /** Default catalog (database) for all queries. */
41
+ catalog: string;
42
+ /** Authentication credentials. */
43
+ auth: FabricAuth;
44
+ /** Source identifier for diagnostics. */
45
+ source?: string;
46
+ }
47
+ /**
48
+ * Assertion-style validator for {@link FabricConnectionConfig}.
49
+ *
50
+ * Validates the shape and constraints of a Fabric connection configuration
51
+ * payload. Throws a plain `Error` synchronously when the input is invalid.
52
+ * Error messages identify the offending field by name but never include
53
+ * client secrets, bearer tokens, or serialized configuration objects.
54
+ *
55
+ * The same implementation is used at both the `defineConfig()` boundary
56
+ * (via `fabricAdapterDefinition.validateDataSourceConfig`) and the
57
+ * `fabricAdapterFactory.createDataSource()` boundary, ensuring a single
58
+ * set of validation rules.
59
+ *
60
+ * @param config - The unknown value to validate.
61
+ * @throws {Error} When the input is not a valid `FabricConnectionConfig`.
62
+ */
63
+ export declare function validateFabricConfig(config: unknown): asserts config is FabricConnectionConfig;
@@ -0,0 +1 @@
1
+ import{isPlainObject as e}from"./sql-helpers.mjs";function t(e,t){if(typeof e!=`string`||e===``)throw Error(`Invalid Fabric config: "${t}" must be a non-empty string`)}function n(n){if(!e(n))throw Error(`Invalid Fabric config: expected a non-null plain object`);t(n.host,`host`);let{port:r}=n;if(typeof r!=`number`||!Number.isFinite(r)||!Number.isInteger(r)||r<1||r>65535)throw Error(`Invalid Fabric config: "port" must be a finite integer in the range 1–65535`);if(t(n.catalog,`catalog`),!e(n.auth))throw Error(`Invalid Fabric config: "auth" must be a non-null plain object`);let{auth:i}=n,a=i.type;if(a===`oauth2`){t(i.tenantId,`auth.tenantId`),t(i.clientId,`auth.clientId`),t(i.clientSecret,`auth.clientSecret`),i.scope!==void 0&&t(i.scope,`auth.scope`);let e=/* @__PURE__ */ new Set([`type`,`tenantId`,`clientId`,`clientSecret`,`scope`]);if(Object.keys(i).filter(t=>!e.has(t)).length>0)throw Error(`Invalid Fabric config: "auth" contains unexpected fields; oauth2 auth allows only type, tenantId, clientId, clientSecret, scope`)}else if(a===`bearer`){t(i.token,`auth.token`);let e=/* @__PURE__ */ new Set([`type`,`token`]);if(Object.keys(i).filter(t=>!e.has(t)).length>0)throw Error(`Invalid Fabric config: "auth" contains unexpected fields; bearer auth allows only type, token`)}else throw Error(`Invalid Fabric config: "auth.type" must be "oauth2" or "bearer"`);n.source!==void 0&&t(n.source,`source`)}export{n as validateFabricConfig};
@@ -0,0 +1,2 @@
1
+ /** Adapter name literal for the Fabric adapter. Used across all modules. */
2
+ export declare const ADAPTER_NAME: "fabric";
@@ -0,0 +1 @@
1
+ const e=`fabric`;export{e as ADAPTER_NAME};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Fabric-specific {@link QueryDialect} implementation using Kysely components.
3
+ *
4
+ * Provides T-SQL–specific SQL generation hooks: MSSQL-compatible Kysely
5
+ * components for query compilation, `DATEDIFF(SECOND, ...)` for date
6
+ * conversion, `OFFSET/FETCH` for pagination, and bracket-quoted
7
+ * identifier quoting.
8
+ *
9
+ * @module
10
+ */
11
+ import { QueryDialect } from "@lakeql/query-builder";
12
+ /**
13
+ * Fabric query dialect implementing the neutral {@link QueryDialect} contract.
14
+ *
15
+ * Uses Kysely's MSSQL adapter/compiler since Fabric's SQL dialect is
16
+ * T-SQL. The dialect provides Fabric-specific SQL fragments for
17
+ * timestamp conversion, pagination, and identifier quoting.
18
+ */
19
+ export declare const fabricDialect: QueryDialect;
@@ -0,0 +1 @@
1
+ import{ADAPTER_NAME as e}from"./constants.mjs";import{quoteQualifiedIdentifier as t}from"./sql-helpers.mjs";import{MssqlAdapter as n,MssqlIntrospector as r,MssqlQueryCompiler as i,sql as a}from"kysely";const o={adapterName:e,createAdapter:()=>new n,createQueryCompiler:()=>new i,createIntrospector:e=>new r(e),toUnixTimestamp:e=>a.raw(`DATEDIFF(SECOND, '1970-01-01', ${e})`),pagination:(e,t)=>a.raw(`OFFSET ${t??0} ROWS FETCH NEXT ${e} ROWS ONLY`),trueLiteral:()=>a.raw(`1`),qualifiedTable:e=>t(e.catalog,e.schema,e.tableName)};export{o as fabricDialect};
@@ -0,0 +1,18 @@
1
+ import { DataSourceError } from "@lakeql/datasource";
2
+ /**
3
+ * Classify a Fabric client error into the shared {@link DataSourceError}
4
+ * hierarchy.
5
+ *
6
+ * The classifier always sets `adapter` to `"fabric"` and preserves the
7
+ * original error as `cause`. Error messages are bounded and
8
+ * credential-safe — they never include passwords, tokens,
9
+ * authorization headers, raw SQL, or complete request options.
10
+ *
11
+ * Already-classified {@link DataSourceError} instances are returned
12
+ * unchanged with strict reference identity (no double-wrapping).
13
+ *
14
+ * @param error - The caught error value (may be any type).
15
+ * @param dataSource - Runtime name of the data source for error context.
16
+ * @returns A concrete {@link DataSourceError} subclass instance.
17
+ */
18
+ export declare function classifyFabricError(error: unknown, dataSource: string): DataSourceError;
@@ -0,0 +1 @@
1
+ import{ADAPTER_NAME as e}from"./constants.mjs";import{AuthenticationError as t,CancellationError as n,DataSourceError as r,NetworkError as i,QueryExecutionError as a,TimeoutError as o}from"@lakeql/datasource";import{FabricCancellationError as s,FabricClientError as c,FabricQueryError as l,FabricTimeoutError as u}from"@lakeql/fabric-client";function d(d,f){if(d instanceof r)return d;let p={cause:d};if(d instanceof l)return new a(`Fabric query failed: error ${d.errorNumber} (state ${d.state})`,e,f,p);if(d instanceof c){let n=d.statusCode;return n===401||n===403?new t(`Fabric authentication failed (HTTP ${n})`,e,f,p):n===408||n===504?new o(`Fabric request timed out (HTTP ${n})`,e,f,p):n===void 0||n===0?new i(`Fabric network error: no response received`,e,f,p):new a(`Fabric client error (HTTP ${n})`,e,f,p)}if(d instanceof u)return new o(`Fabric query timed out`,e,f,p);if(d instanceof s)return new n(`Fabric query was cancelled`,e,f,p);if(d instanceof DOMException){if(d.name===`TimeoutError`)return new o(`Fabric request timed out`,e,f,p);if(d.name===`AbortError`)return new n(`Fabric request was aborted`,e,f,p)}if(d instanceof TypeError)return new i(`Fabric network error`,e,f,p);let m=d instanceof DOMException?`Fabric unexpected DOMException: ${d.name}`:`Fabric unknown error`;return new a(m,e,f,p)}export{d as classifyFabricError};
@@ -0,0 +1,9 @@
1
+ /** Fabric adapter factory implementing the neutral AdapterFactory contract. */
2
+ import { fabricAdapterDefinition, fabricAdapterFactory } from "./adapter.mjs";
3
+ import { ADAPTER_NAME } from "./constants.mjs";
4
+ import { FabricAuth, FabricBearerAuth, FabricConnectionConfig, FabricOAuth2Auth, validateFabricConfig } from "./config.mjs";
5
+ import { classifyFabricError } from "./errors.mjs";
6
+ import { fabricDialect } from "./dialect.mjs";
7
+ import { fabricResponseNormalizer } from "./normalizer.mjs";
8
+ import { fabricTypeMapper } from "./type-mapper.mjs";
9
+ export { ADAPTER_NAME, type FabricAuth, type FabricBearerAuth, type FabricConnectionConfig, type FabricOAuth2Auth, classifyFabricError, fabricAdapterDefinition, fabricAdapterFactory, fabricDialect, fabricResponseNormalizer, fabricTypeMapper, validateFabricConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{fabricAdapterDefinition as e,fabricAdapterFactory as t}from"./adapter.mjs";import{ADAPTER_NAME as n}from"./constants.mjs";import{validateFabricConfig as r}from"./config.mjs";import{classifyFabricError as i}from"./errors.mjs";import{fabricDialect as a}from"./dialect.mjs";import{fabricResponseNormalizer as o}from"./normalizer.mjs";import{fabricTypeMapper as s}from"./type-mapper.mjs";export{n as ADAPTER_NAME,i as classifyFabricError,e as fabricAdapterDefinition,t as fabricAdapterFactory,a as fabricDialect,o as fabricResponseNormalizer,s as fabricTypeMapper,r as validateFabricConfig};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Fabric-specific {@link ResponseNormalizer} implementation.
3
+ *
4
+ * Fabric's TDS driver returns the presence sentinel as the integer `1` rather
5
+ * than a boolean, so a real data row's sentinel is `true` or `1`. All other
6
+ * CTE decoding is shared with the Trino adapter via
7
+ * {@link createCteResponseNormalizer}.
8
+ *
9
+ * @module
10
+ */
11
+ import { ResponseNormalizer } from "@lakeql/response-transformer";
12
+ /**
13
+ * Fabric response normalizer implementing the neutral
14
+ * {@link ResponseNormalizer} contract. Accepts `true` or `1` as the record
15
+ * sentinel (T-SQL returns `1`).
16
+ */
17
+ export declare const fabricResponseNormalizer: ResponseNormalizer;
@@ -0,0 +1 @@
1
+ import{ADAPTER_NAME as e}from"./constants.mjs";import{isPlainObject as t}from"./sql-helpers.mjs";import{createCteResponseNormalizer as n}from"@lakeql/response-transformer";const r=n({adapterName:e,isPresentSentinel:e=>e===!0||e===1,acceptedSentinelDescription:`true/1`,isPlainObject:t});export{r as fabricResponseNormalizer};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Adapter-owned Fabric/T-SQL rendering helpers for bracket-quoted
3
+ * identifier quoting and literal escaping. These are used by metadata
4
+ * queries, DDL rendering, and the Fabric dialect throughout the adapter.
5
+ *
6
+ * @module
7
+ */
8
+ import { escapeLiteral, isPlainObject } from "@lakeql/datasource";
9
+ /**
10
+ * Quote a single SQL identifier segment for T-SQL using bracket quoting.
11
+ *
12
+ * The input is treated as exactly one identifier segment. Dots within the
13
+ * value are preserved as part of the segment and are **not** interpreted as
14
+ * qualification separators. Embedded right-bracket characters are escaped by
15
+ * doubling them (`]` → `]]`), and the result is wrapped in brackets.
16
+ *
17
+ * @param segment - The raw identifier segment to quote.
18
+ * @returns The safely bracket-quoted identifier string.
19
+ * @throws {Error} If `segment` is empty or contains C0/C1 control characters.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * quoteIdentifier("my_table") // => "[my_table]"
24
+ * // A literal "]" is escaped by doubling it ("]]"), per T-SQL bracket quoting:
25
+ * quoteIdentifier("has]bracket") // => "[has]]bracket]"
26
+ * // Dots stay part of the single segment, they are not treated as separators:
27
+ * quoteIdentifier("catalog.with.dot") // => "[catalog.with.dot]"
28
+ * ```
29
+ */
30
+ export declare function quoteIdentifier(segment: string): string;
31
+ /**
32
+ * Quote a fully-qualified T-SQL identifier composed of one or more segments.
33
+ *
34
+ * Applies {@link quoteIdentifier} independently to each segment and joins
35
+ * them with literal dots. Requires at least one segment.
36
+ *
37
+ * @param segments - One or more raw identifier segments (e.g. catalog, schema, table).
38
+ * @returns The safely quoted qualified identifier string.
39
+ * @throws {Error} If no segments are provided, or if any segment is invalid.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * quoteQualifiedIdentifier("warehouse", "dbo", "orders")
44
+ * // => '[warehouse].[dbo].[orders]'
45
+ * ```
46
+ */
47
+ export declare function quoteQualifiedIdentifier(...segments: string[]): string;
48
+ export { escapeLiteral, isPlainObject };
@@ -0,0 +1 @@
1
+ import{escapeLiteral as e,isPlainObject as t,quoteQualified as n,rejectControlChars as r}from"@lakeql/datasource";function i(e){if(e.length===0)throw Error(`Identifier segment must not be empty`);return r(e,`Identifier segment`),`[${e.replaceAll(`]`,`]]`)}]`}function a(...e){return n(i,...e)}export{e as escapeLiteral,t as isPlainObject,i as quoteIdentifier,a as quoteQualifiedIdentifier};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Fabric type mapping between T-SQL / Fabric SQL types and LakeQL primitive
3
+ * types.
4
+ *
5
+ * @module
6
+ */
7
+ /** Shared {@link TypeMapper} for Fabric / T-SQL types. */
8
+ export declare const fabricTypeMapper: import("@lakeql/datasource").TypeMapper;
@@ -0,0 +1 @@
1
+ import{createTypeMapper as e}from"@lakeql/datasource";const t=e({toPrimitive:{nvarchar:`String`,varchar:`String`,char:`String`,nchar:`String`,text:`String`,ntext:`String`,xml:`String`,uniqueidentifier:`String`,varbinary:`String`,binary:`String`,int:`Integer`,bigint:`Integer`,smallint:`Integer`,tinyint:`Integer`,float:`Float`,real:`Float`,decimal:`Float`,numeric:`Float`,money:`Float`,smallmoney:`Float`,bit:`Boolean`,date:`Date`,datetime:`DateTime`,datetime2:`DateTime`,datetimeoffset:`DateTime`,smalldatetime:`DateTime`,time:`DateTime`},toEngine:{String:`NVARCHAR(MAX)`,Integer:`BIGINT`,Float:`FLOAT`,Boolean:`BIT`,Date:`DATE`,DateTime:`DATETIME2(3)`}});export{t as fabricTypeMapper};
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@lakeql/adapter-fabric",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Microsoft Fabric adapter for LakeQL",
5
+ "keywords": [
6
+ "adapter",
7
+ "fabric",
8
+ "lakeql",
9
+ "mssql"
10
+ ],
11
+ "homepage": "https://lakeql.dev",
12
+ "license": "Apache-2.0",
13
+ "author": {
14
+ "name": "Marcus Reinhardt",
15
+ "url": "https://github.com/noxify"
16
+ },
17
+ "contributors": [
18
+ {
19
+ "name": "Marcus Reinhardt",
20
+ "url": "https://github.com/noxify"
21
+ }
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/noxify/lakeql",
26
+ "directory": "packages/adapter-fabric"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "type": "module",
32
+ "sideEffects": false,
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.mts",
36
+ "import": "./dist/index.mjs"
37
+ }
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "dependencies": {
43
+ "@lakeql/datasource": "1.0.0",
44
+ "@lakeql/fabric-client": "1.0.0",
45
+ "@lakeql/query-builder": "1.0.0",
46
+ "@lakeql/response-transformer": "1.0.0",
47
+ "@lakeql/sql-read-strategy": "1.0.0",
48
+ "kysely": "0.29.8"
49
+ },
50
+ "devDependencies": {
51
+ "@lakeql/tsconfig": "0.1.0",
52
+ "@lakeql/vitest-config": "0.1.0",
53
+ "@types/node": "24.19.2",
54
+ "tsdown": "0.23.7",
55
+ "typescript": "6.0.3",
56
+ "vitest": "5.1.0"
57
+ },
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "clean": "git clean -xdf .cache .turbo dist node_modules dist",
61
+ "clean:cache": "git clean -xdf .cache .turbo",
62
+ "clean:dist": "git clean -xdf dist",
63
+ "dev": "tsdown --watch",
64
+ "test": "vitest run",
65
+ "typecheck": "tsc --noEmit"
66
+ }
6
67
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.