@keystrokehq/snowflake 0.0.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.
Files changed (81) hide show
  1. package/README.md +247 -0
  2. package/dist/_official/index.d.mts +2 -0
  3. package/dist/_official/index.mjs +3 -0
  4. package/dist/_runtime/index.d.mts +1 -0
  5. package/dist/_runtime/index.mjs +1 -0
  6. package/dist/accounts.d.mts +40 -0
  7. package/dist/accounts.mjs +51 -0
  8. package/dist/bulk.d.mts +71 -0
  9. package/dist/bulk.mjs +65 -0
  10. package/dist/catalog.d.mts +144 -0
  11. package/dist/catalog.mjs +158 -0
  12. package/dist/client.d.mts +44 -0
  13. package/dist/client.mjs +273 -0
  14. package/dist/common-BnKTPQXc.mjs +92 -0
  15. package/dist/connection.d.mts +2 -0
  16. package/dist/connection.mjs +3 -0
  17. package/dist/databases.d.mts +2 -0
  18. package/dist/databases.mjs +3 -0
  19. package/dist/errors-DKnc9o_a.mjs +95 -0
  20. package/dist/events.d.mts +382 -0
  21. package/dist/events.mjs +291 -0
  22. package/dist/file-formats.d.mts +39 -0
  23. package/dist/file-formats.mjs +48 -0
  24. package/dist/functions.d.mts +53 -0
  25. package/dist/functions.mjs +56 -0
  26. package/dist/grants.d.mts +93 -0
  27. package/dist/grants.mjs +102 -0
  28. package/dist/index.d.mts +1 -0
  29. package/dist/index.mjs +1 -0
  30. package/dist/integration-CCWMSTlO.d.mts +170 -0
  31. package/dist/integration-Dptv8L0L.mjs +207 -0
  32. package/dist/org-admin.d.mts +80 -0
  33. package/dist/org-admin.mjs +79 -0
  34. package/dist/pipes.d.mts +119 -0
  35. package/dist/pipes.mjs +106 -0
  36. package/dist/procedures.d.mts +61 -0
  37. package/dist/procedures.mjs +79 -0
  38. package/dist/results.d.mts +16 -0
  39. package/dist/results.mjs +64 -0
  40. package/dist/retry-0hMfb8cC.mjs +164 -0
  41. package/dist/retry-w7cTp1QL.d.mts +10 -0
  42. package/dist/roles.d.mts +60 -0
  43. package/dist/roles.mjs +74 -0
  44. package/dist/rows.d.mts +106 -0
  45. package/dist/rows.mjs +223 -0
  46. package/dist/schemas/index.d.mts +2 -0
  47. package/dist/schemas/index.mjs +4 -0
  48. package/dist/schemas-catalog.d.mts +2 -0
  49. package/dist/schemas-catalog.mjs +3 -0
  50. package/dist/shares.d.mts +56 -0
  51. package/dist/shares.mjs +77 -0
  52. package/dist/sql-options-2k5xQ-oS.d.mts +32 -0
  53. package/dist/sql-options-DI-OmLU6.mjs +79 -0
  54. package/dist/sql-safety-CywdR3EP.mjs +56 -0
  55. package/dist/sql.d.mts +84 -0
  56. package/dist/sql.mjs +209 -0
  57. package/dist/stages.d.mts +64 -0
  58. package/dist/stages.mjs +81 -0
  59. package/dist/statements-B2ThF_4b.mjs +81 -0
  60. package/dist/statements-DJL0qVNA.d.mts +238 -0
  61. package/dist/status-page.d.mts +510 -0
  62. package/dist/status-page.mjs +261 -0
  63. package/dist/streaming.d.mts +70 -0
  64. package/dist/streaming.mjs +56 -0
  65. package/dist/streams.d.mts +71 -0
  66. package/dist/streams.mjs +78 -0
  67. package/dist/tables.d.mts +2 -0
  68. package/dist/tables.mjs +3 -0
  69. package/dist/tasks.d.mts +79 -0
  70. package/dist/tasks.mjs +104 -0
  71. package/dist/triggers.d.mts +578 -0
  72. package/dist/triggers.mjs +1363 -0
  73. package/dist/users.d.mts +61 -0
  74. package/dist/users.mjs +67 -0
  75. package/dist/verification.d.mts +201 -0
  76. package/dist/verification.mjs +512 -0
  77. package/dist/views.d.mts +2 -0
  78. package/dist/views.mjs +3 -0
  79. package/dist/warehouses.d.mts +68 -0
  80. package/dist/warehouses.mjs +101 -0
  81. package/package.json +190 -0
package/README.md ADDED
@@ -0,0 +1,247 @@
1
+ # @keystrokehq/snowflake
2
+
3
+ Official Keystroke integration for the Snowflake Data Cloud. One package wraps the Snowflake SQL API v2, Snowpipe file REST, Snowpipe Streaming, Streams, Tasks, Warehouses, Roles, Users, Grants, Shares, account admin, and the public Snowflake status page behind a typed, `fetch`-based HTTPS client — plus 22 polling triggers and 3 auto-ingest webhook triggers.
4
+
5
+ No Node-native dependencies. The runtime is built on `fetch` + `SubtleCrypto`, so it runs in Cloudflare Workers and other isolate tiers without any shim.
6
+
7
+ See `PLAN.md` for the full action/trigger enumeration and `IMPLEMENTATION_NOTES.md` for the decisions that shipped with this build.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @keystrokehq/snowflake
13
+ ```
14
+
15
+ ## Credentials
16
+
17
+ The public `snowflake` connection accepts four auth modes via a discriminated union on `mode`:
18
+
19
+ | Mode | When to use |
20
+ |------|-------------|
21
+ | `keypair` | Service accounts with an RSA key pair registered on the Snowflake user (recommended). |
22
+ | `oauth` | External IdP or Snowflake-hosted OAuth — supply a bearer access token, optionally refreshable. |
23
+ | `pat` | Programmatic Access Token (Snowflake preview). |
24
+ | `basic` | Legacy username + password. Emits a deprecation warning at client creation time. |
25
+
26
+ Shared required fields: `SNOWFLAKE_ACCOUNT`, plus `SNOWFLAKE_USER` for any non-OAuth mode. Optional session fields — `SNOWFLAKE_ROLE`, `SNOWFLAKE_WAREHOUSE`, `SNOWFLAKE_DATABASE`, `SNOWFLAKE_SCHEMA`, `SNOWFLAKE_HOST`, `SNOWFLAKE_REGION` — are honored by every operation when the input does not provide an override.
27
+
28
+ Example vault values for key-pair mode:
29
+
30
+ ```ts
31
+ import type { SnowflakeCredentials } from '@keystrokehq/snowflake/connection';
32
+
33
+ const credentials: SnowflakeCredentials = {
34
+ mode: 'keypair',
35
+ SNOWFLAKE_ACCOUNT: 'my-org-my-account',
36
+ SNOWFLAKE_USER: 'KEYSTROKE_SVC',
37
+ SNOWFLAKE_PRIVATE_KEY: '-----BEGIN PRIVATE KEY-----\n...',
38
+ SNOWFLAKE_ROLE: 'KEYSTROKE_ROLE',
39
+ SNOWFLAKE_WAREHOUSE: 'KEYSTROKE_WH',
40
+ };
41
+ ```
42
+
43
+ ## Client
44
+
45
+ All domain functions accept a `SnowflakeClient` produced by `createSnowflakeClient(credentials)`. The client is stateless other than an internal OAuth/keypair JWT cache; reuse a single client across many operations.
46
+
47
+ ```ts
48
+ import { createSnowflakeClient } from '@keystrokehq/snowflake/client';
49
+
50
+ const client = createSnowflakeClient(credentials);
51
+ ```
52
+
53
+ ## Quickstart
54
+
55
+ ### Execute a statement
56
+
57
+ ```ts
58
+ import { executeSql } from '@keystrokehq/snowflake/sql';
59
+
60
+ const result = await executeSql(client, {
61
+ statement: 'SELECT 1 AS ping',
62
+ timeout: 60,
63
+ });
64
+
65
+ for (const row of result.rows) {
66
+ console.log(row);
67
+ }
68
+ ```
69
+
70
+ ### Find rows with parameter binding
71
+
72
+ ```ts
73
+ import { findRows } from '@keystrokehq/snowflake/rows';
74
+
75
+ const rows = await findRows(client, {
76
+ database: 'ANALYTICS',
77
+ schema: 'PUBLIC',
78
+ table: 'ORDERS',
79
+ where: { STATUS: 'OPEN' },
80
+ orderBy: [{ column: 'CREATED_AT', direction: 'DESC' }],
81
+ limit: 100,
82
+ });
83
+ ```
84
+
85
+ ### Show tables in a schema
86
+
87
+ ```ts
88
+ import { showTables } from '@keystrokehq/snowflake/catalog';
89
+
90
+ const tables = await showTables(client, {
91
+ database: 'ANALYTICS',
92
+ schema: 'PUBLIC',
93
+ });
94
+ ```
95
+
96
+ ### Run a task on demand
97
+
98
+ ```ts
99
+ import { executeTask } from '@keystrokehq/snowflake/tasks';
100
+
101
+ await executeTask(client, {
102
+ database: 'ANALYTICS',
103
+ schema: 'PUBLIC',
104
+ name: 'REFRESH_FACTS',
105
+ });
106
+ ```
107
+
108
+ ### Refresh a pipe + insert files over Snowpipe REST
109
+
110
+ ```ts
111
+ import { insertFiles, refreshPipe } from '@keystrokehq/snowflake/pipes';
112
+
113
+ await refreshPipe(client, {
114
+ database: 'ANALYTICS',
115
+ schema: 'RAW',
116
+ name: 'ORDERS_PIPE',
117
+ });
118
+
119
+ await insertFiles(client, {
120
+ database: 'ANALYTICS',
121
+ schema: 'RAW',
122
+ name: 'ORDERS_PIPE',
123
+ files: [{ path: 'orders/2026/04/20.parquet' }],
124
+ });
125
+ ```
126
+
127
+ ## Triggers
128
+
129
+ ### Polling trigger — new rows on a stream
130
+
131
+ ```ts
132
+ import { polling } from '@keystrokehq/snowflake/triggers';
133
+
134
+ const bound = polling.streamHasNewRows({
135
+ streamName: 'ANALYTICS.PUBLIC.ORDERS_STREAM',
136
+ schedule: '*/5 * * * *',
137
+ name: 'Orders stream has new rows',
138
+ transform: (event) => ({
139
+ streamName: event.streamName,
140
+ checkedAt: event.checkedAt,
141
+ }),
142
+ });
143
+ ```
144
+
145
+ ### Polling trigger — signature-diff on `SHOW GRANTS`
146
+
147
+ ```ts
148
+ import { polling } from '@keystrokehq/snowflake/triggers';
149
+
150
+ const grants = polling.grantsChanged({
151
+ grantee: { role: 'KEYSTROKE_ROLE' },
152
+ schedule: '15m',
153
+ });
154
+ ```
155
+
156
+ ### Auto-ingest webhook — AWS SNS
157
+
158
+ ```ts
159
+ import { webhooks } from '@keystrokehq/snowflake/triggers';
160
+
161
+ const s3Sns = webhooks.autoIngestS3Sns({
162
+ name: 'Snowpipe via SNS',
163
+ transform: (batch) => ({
164
+ bucket: batch.events[0]?.bucket,
165
+ objects: batch.events.length,
166
+ }),
167
+ });
168
+ ```
169
+
170
+ ### Auto-ingest webhook — GCS Pub/Sub push
171
+
172
+ ```ts
173
+ import { webhooks } from '@keystrokehq/snowflake/triggers';
174
+
175
+ const gcs = webhooks.autoIngestGcsPubSub({
176
+ transform: (batch) => ({ objects: batch.events.length }),
177
+ });
178
+ ```
179
+
180
+ ### Auto-ingest webhook — Azure Event Grid
181
+
182
+ ```ts
183
+ import { webhooks } from '@keystrokehq/snowflake/triggers';
184
+
185
+ const eg = webhooks.autoIngestAzureEventGrid({
186
+ transform: (batch) => ({ objects: batch.events.length }),
187
+ });
188
+ ```
189
+
190
+ ## Verification helpers
191
+
192
+ Every auto-ingest webhook verifies itself through the `verify` callback wired by the trigger factory. The underlying helpers are also exported for direct use — for example, from an edge proxy that wants to reject unsigned requests before the payload reaches a workflow.
193
+
194
+ ```ts
195
+ import {
196
+ SnowflakeWebhookVerificationError,
197
+ verifyEventGridRequest,
198
+ verifyPubSubPushAuthorization,
199
+ verifySnsMessage,
200
+ } from '@keystrokehq/snowflake/verification';
201
+
202
+ try {
203
+ await verifySnsMessage(rawBody, {
204
+ expectedTopicArn: 'arn:aws:sns:us-east-1:123456789012:snowpipe-orders',
205
+ });
206
+ } catch (err) {
207
+ if (err instanceof SnowflakeWebhookVerificationError) {
208
+ // err.reason ∈ 'invalid-json' | 'schema' | 'topic-arn' | 'signing-cert-host' | 'signature' | ...
209
+ }
210
+ }
211
+ ```
212
+
213
+ ## Public surface
214
+
215
+ - `@keystrokehq/snowflake/connection` — `snowflake` credential set, `snowflakeBundle`, and credential types.
216
+ - `@keystrokehq/snowflake/client` — `createSnowflakeClient(credentials, options?)` for direct SQL API access.
217
+ - `@keystrokehq/snowflake/schemas` — shared Zod schemas (statements, results, pipes, catalog, and more).
218
+ - `@keystrokehq/snowflake/events` — curated Zod event contracts emitted by each trigger.
219
+ - `@keystrokehq/snowflake/triggers` — `polling`, `webhooks`, and `autoIngest` direct-binding helpers.
220
+ - `@keystrokehq/snowflake/verification` — auto-ingest cloud-event verification (SNS, Pub/Sub, Event Grid).
221
+
222
+ ### Operation domains
223
+
224
+ - `sql` — `submitStatement`, `getStatement`, `cancelStatement`, `executeSql`, `runQuery`, `getStatementResultPartition`, `iterateStatementResult`, `waitForStatement`.
225
+ - `results` — partition iteration + row hydration helpers.
226
+ - `catalog` — `SHOW`/`DESCRIBE` across databases, schemas, tables, views, columns, warehouses, roles, users, stages, pipes, tasks, streams, shares, functions, procedures, file formats, grants; plus Relay-style `findDatabases`/`findSchemas`/`findTables` and BASIC-parity `describeTable`/`exploreColumns`.
227
+ - `rows` — `findRow`, `findRows`, `insertRow`, `batchInsert`, `updateRow`, `deleteRow`, `upsertRow`, `mergeRows`.
228
+ - `databases`, `schemas-catalog`, `tables`, `views`, `stages`, `file-formats`, `streams`, `tasks`, `warehouses`, `roles`, `users`, `grants`, `shares`, `functions`, `procedures`, `accounts`, `org-admin` — DDL + admin.
229
+ - `pipes`, `streaming`, `bulk` — Snowpipe file REST, Snowpipe Streaming channels, stage-oriented bulk helpers.
230
+ - `status-page` — Composio-parity Snowflake status page endpoints.
231
+
232
+ ### Internal repo-only surfaces
233
+
234
+ - `@keystrokehq/snowflake/_official`
235
+ - `@keystrokehq/snowflake/_runtime`
236
+
237
+ Do not import these from end-user code.
238
+
239
+ ## Safety
240
+
241
+ - Destructive DDL operations (`dropTable`, `dropDatabase`, `dropSchema`, `dropUser`, `dropRole`, `dropWarehouse`, `dropShare`, etc.) require an explicit `confirm: true` input and are marked `needsApproval: true` where surfaced through the operation factory.
242
+ - The package never streams file bytes directly through the SQL API. File-oriented helpers (`putFile`, `getFile`) orchestrate `PUT @stage` / `GET @stage` SQL statements and return the result; binary payloads must be supplied through an external stage with its own cloud credentials.
243
+ - `basic` auth emits `console.warn` at client creation time; Snowflake has deprecated password-only programmatic access.
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,2 @@
1
+ import { c as snowflakeOfficialIntegration, i as snowflake, s as snowflakeBundle } from "../integration-CCWMSTlO.mjs";
2
+ export { snowflake, snowflakeBundle, snowflakeOfficialIntegration };
@@ -0,0 +1,3 @@
1
+ import { a as snowflakeBundle, n as snowflake, o as snowflakeOfficialIntegration } from "../integration-Dptv8L0L.mjs";
2
+
3
+ export { snowflake, snowflakeBundle, snowflakeOfficialIntegration };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,40 @@
1
+ import { SnowflakeClient } from "./client.mjs";
2
+ import { d as HydratedRow, m as ColumnMeta } from "./statements-DJL0qVNA.mjs";
3
+ //#region src/accounts.d.ts
4
+ interface AccountContext {
5
+ readonly warehouse?: string;
6
+ readonly role?: string;
7
+ }
8
+ interface DescribeAccountOptions extends AccountContext {}
9
+ /**
10
+ * Returns a single-row identity snapshot for the account that the
11
+ * current connection is bound to. Useful as a "whoami" / health probe.
12
+ *
13
+ * The helper is deliberately a single SELECT so we don't need any
14
+ * privileged role; `CURRENT_*` functions work for any authenticated user.
15
+ */
16
+ declare function describeAccount(client: SnowflakeClient, options?: DescribeAccountOptions): Promise<HydratedRow>;
17
+ interface ShowRegionsOptions extends AccountContext {
18
+ readonly like?: string;
19
+ }
20
+ interface ShowRegionsResult {
21
+ readonly columns: readonly ColumnMeta[];
22
+ readonly rows: readonly HydratedRow[];
23
+ }
24
+ /**
25
+ * `SHOW REGIONS` — requires ORGADMIN. Returns the globally-available
26
+ * Snowflake regions along with region-group / cloud-provider metadata.
27
+ */
28
+ declare function showRegions(client: SnowflakeClient, options?: ShowRegionsOptions): Promise<ShowRegionsResult>;
29
+ interface FetchCatalogIntegrationOptions extends AccountContext {
30
+ readonly name: string;
31
+ }
32
+ /**
33
+ * `DESC CATALOG INTEGRATION <name>` — returns the property list for a
34
+ * Snowflake Iceberg catalog integration (the `SNOWFLAKE_FETCH_CATALOG_INTEGRATION`
35
+ * Composio op). Every row has a `property` / `value` / `default` / `description`
36
+ * shape.
37
+ */
38
+ declare function fetchCatalogIntegration(client: SnowflakeClient, options: FetchCatalogIntegrationOptions): Promise<readonly HydratedRow[]>;
39
+ //#endregion
40
+ export { AccountContext, DescribeAccountOptions, FetchCatalogIntegrationOptions, ShowRegionsOptions, ShowRegionsResult, describeAccount, fetchCatalogIntegration, showRegions };
@@ -0,0 +1,51 @@
1
+ import { executeSql } from "./sql.mjs";
2
+ import { i as quoteIdentifier, r as likeClause } from "./sql-safety-CywdR3EP.mjs";
3
+
4
+ //#region src/accounts.ts
5
+ /**
6
+ * Returns a single-row identity snapshot for the account that the
7
+ * current connection is bound to. Useful as a "whoami" / health probe.
8
+ *
9
+ * The helper is deliberately a single SELECT so we don't need any
10
+ * privileged role; `CURRENT_*` functions work for any authenticated user.
11
+ */
12
+ async function describeAccount(client, options = {}) {
13
+ const row = (await executeSql(client, {
14
+ statement: "SELECT CURRENT_ACCOUNT() AS ACCOUNT_LOCATOR, CURRENT_ACCOUNT_NAME() AS ACCOUNT_NAME, CURRENT_REGION() AS REGION, CURRENT_ORGANIZATION_NAME() AS ORGANIZATION_NAME, CURRENT_VERSION() AS SNOWFLAKE_VERSION, CURRENT_ROLE() AS ROLE, CURRENT_WAREHOUSE() AS WAREHOUSE, CURRENT_DATABASE() AS DATABASE, CURRENT_SCHEMA() AS SCHEMA",
15
+ warehouse: options.warehouse,
16
+ role: options.role
17
+ })).rows[0];
18
+ if (!row) throw new Error("describeAccount: Snowflake returned no rows for identity SELECT");
19
+ return row;
20
+ }
21
+ /**
22
+ * `SHOW REGIONS` — requires ORGADMIN. Returns the globally-available
23
+ * Snowflake regions along with region-group / cloud-provider metadata.
24
+ */
25
+ async function showRegions(client, options = {}) {
26
+ const result = await executeSql(client, {
27
+ statement: `SHOW REGIONS${likeClause(options.like)}`,
28
+ warehouse: options.warehouse,
29
+ role: options.role
30
+ });
31
+ return {
32
+ columns: result.columns,
33
+ rows: result.rows
34
+ };
35
+ }
36
+ /**
37
+ * `DESC CATALOG INTEGRATION <name>` — returns the property list for a
38
+ * Snowflake Iceberg catalog integration (the `SNOWFLAKE_FETCH_CATALOG_INTEGRATION`
39
+ * Composio op). Every row has a `property` / `value` / `default` / `description`
40
+ * shape.
41
+ */
42
+ async function fetchCatalogIntegration(client, options) {
43
+ return (await executeSql(client, {
44
+ statement: `DESCRIBE CATALOG INTEGRATION ${quoteIdentifier(options.name)}`,
45
+ warehouse: options.warehouse,
46
+ role: options.role
47
+ })).rows;
48
+ }
49
+
50
+ //#endregion
51
+ export { describeAccount, fetchCatalogIntegration, showRegions };
@@ -0,0 +1,71 @@
1
+ import { SnowflakeClient } from "./client.mjs";
2
+ import { d as HydratedRow } from "./statements-DJL0qVNA.mjs";
3
+ import { ExecuteSqlResult } from "./sql.mjs";
4
+ import { t as OptionMap } from "./sql-options-2k5xQ-oS.mjs";
5
+ import { StageRef } from "./stages.mjs";
6
+
7
+ //#region src/bulk.d.ts
8
+ interface TableRef {
9
+ readonly database?: string;
10
+ readonly schema?: string;
11
+ readonly table: string;
12
+ }
13
+ interface BulkContext {
14
+ readonly warehouse?: string;
15
+ readonly role?: string;
16
+ }
17
+ interface CopyIntoSourceStage {
18
+ readonly kind: 'stage';
19
+ readonly stage: StageRef;
20
+ readonly pathSuffix?: string;
21
+ readonly files?: readonly string[];
22
+ readonly pattern?: string;
23
+ }
24
+ interface CopyIntoSourceExternalLocation {
25
+ readonly kind: 'location';
26
+ /** e.g. `'s3://bucket/path/'` — caller is responsible for URL shape. */
27
+ readonly url: string;
28
+ readonly credentials?: OptionMap;
29
+ readonly encryption?: OptionMap;
30
+ readonly files?: readonly string[];
31
+ readonly pattern?: string;
32
+ }
33
+ interface CopyIntoSourceQuery {
34
+ readonly kind: 'query';
35
+ /** Pre-composed SELECT body (caller owns identifier escaping). */
36
+ readonly sql: string;
37
+ }
38
+ type CopyIntoSource = CopyIntoSourceStage | CopyIntoSourceExternalLocation | CopyIntoSourceQuery;
39
+ interface CopyIntoOptions extends TableRef, BulkContext {
40
+ readonly columns?: readonly string[];
41
+ readonly source: CopyIntoSource;
42
+ readonly fileFormat?: OptionMap;
43
+ readonly copyOptions?: OptionMap;
44
+ /** `VALIDATION_MODE = RETURN_ERRORS | RETURN_ALL_ERRORS | RETURN_n_ROWS`. */
45
+ readonly validationMode?: string;
46
+ readonly onError?: string;
47
+ readonly force?: boolean;
48
+ readonly truncateColumns?: boolean;
49
+ }
50
+ declare function copyInto(client: SnowflakeClient, options: CopyIntoOptions): Promise<ExecuteSqlResult<HydratedRow | readonly unknown[]>>;
51
+ declare function validateCopyInto(client: SnowflakeClient, options: CopyIntoOptions): Promise<ExecuteSqlResult<HydratedRow | readonly unknown[]>>;
52
+ interface UnloadOptions extends BulkContext {
53
+ readonly stage: StageRef;
54
+ readonly pathSuffix?: string;
55
+ /** Pre-composed SELECT body; the helper wraps it in parens. */
56
+ readonly query: string;
57
+ readonly fileFormat?: OptionMap;
58
+ readonly copyOptions?: OptionMap;
59
+ readonly overwrite?: boolean;
60
+ readonly header?: boolean;
61
+ readonly singleFile?: boolean;
62
+ readonly maxFileSize?: number | bigint;
63
+ readonly partitionBy?: string;
64
+ }
65
+ declare function unload(client: SnowflakeClient, options: UnloadOptions): Promise<ExecuteSqlResult<HydratedRow | readonly unknown[]>>;
66
+ interface TruncateTableOptions extends TableRef, BulkContext {
67
+ readonly ifExists?: boolean;
68
+ }
69
+ declare function truncateTable(client: SnowflakeClient, options: TruncateTableOptions): Promise<void>;
70
+ //#endregion
71
+ export { BulkContext, CopyIntoOptions, CopyIntoSource, CopyIntoSourceExternalLocation, CopyIntoSourceQuery, CopyIntoSourceStage, TableRef, TruncateTableOptions, UnloadOptions, copyInto, truncateTable, unload, validateCopyInto };
package/dist/bulk.mjs ADDED
@@ -0,0 +1,65 @@
1
+ import { executeSql } from "./sql.mjs";
2
+ import { a as quoteLiteral, t as buildFqn } from "./sql-safety-CywdR3EP.mjs";
3
+ import { n as renderOptionGroup, t as formatOptions } from "./sql-options-DI-OmLU6.mjs";
4
+ import { stagePath } from "./stages.mjs";
5
+
6
+ //#region src/bulk.ts
7
+ function tableFqn(ref) {
8
+ return buildFqn(ref.database, ref.schema, ref.table);
9
+ }
10
+ function renderSource(source) {
11
+ if (source.kind === "query") return `(${source.sql})`;
12
+ if (source.kind === "stage") return `${stagePath(source.stage, source.pathSuffix)}${source.files && source.files.length > 0 ? ` FILES = (${source.files.map(quoteLiteral).join(", ")})` : ""}${source.pattern ? ` PATTERN = ${quoteLiteral(source.pattern)}` : ""}`;
13
+ const files = source.files && source.files.length > 0 ? ` FILES = (${source.files.map(quoteLiteral).join(", ")})` : "";
14
+ const pattern = source.pattern ? ` PATTERN = ${quoteLiteral(source.pattern)}` : "";
15
+ const creds = renderOptionGroup("CREDENTIALS", source.credentials);
16
+ const enc = renderOptionGroup("ENCRYPTION", source.encryption);
17
+ return `${quoteLiteral(source.url)}${creds}${enc}${files}${pattern}`;
18
+ }
19
+ function collectCopyOptions(opts) {
20
+ const merged = { ...opts.copyOptions ?? {} };
21
+ if (opts.onError !== void 0) merged.onError = opts.onError;
22
+ if (opts.force !== void 0) merged.force = opts.force;
23
+ if (opts.truncateColumns !== void 0) merged.truncateColumns = opts.truncateColumns;
24
+ return Object.keys(merged).length > 0 ? merged : void 0;
25
+ }
26
+ async function copyInto(client, options) {
27
+ const columnList = options.columns && options.columns.length > 0 ? `(${options.columns.map((c) => `"${c.replaceAll("\"", "\"\"")}"`).join(", ")})` : "";
28
+ const copyOpts = collectCopyOptions(options);
29
+ return executeSql(client, {
30
+ statement: `COPY INTO ${tableFqn(options)}${columnList ? ` ${columnList}` : ""} FROM ${renderSource(options.source)}` + renderOptionGroup("FILE_FORMAT", options.fileFormat) + (copyOpts ? ` ${formatOptions(copyOpts)}` : "") + (options.validationMode ? ` VALIDATION_MODE = ${options.validationMode}` : ""),
31
+ warehouse: options.warehouse,
32
+ role: options.role
33
+ });
34
+ }
35
+ async function validateCopyInto(client, options) {
36
+ return copyInto(client, {
37
+ ...options,
38
+ validationMode: options.validationMode ?? "RETURN_ERRORS"
39
+ });
40
+ }
41
+ async function unload(client, options) {
42
+ const scope = stagePath(options.stage, options.pathSuffix);
43
+ const copyOpts = { ...options.copyOptions ?? {} };
44
+ if (options.overwrite !== void 0) copyOpts.overwrite = options.overwrite;
45
+ if (options.header !== void 0) copyOpts.header = options.header;
46
+ if (options.singleFile !== void 0) copyOpts.singleFile = options.singleFile;
47
+ if (options.maxFileSize !== void 0) copyOpts.maxFileSize = options.maxFileSize;
48
+ const copyOptions = Object.keys(copyOpts).length > 0 ? copyOpts : void 0;
49
+ const partition = options.partitionBy ? ` PARTITION BY (${options.partitionBy})` : "";
50
+ return executeSql(client, {
51
+ statement: `COPY INTO ${scope} FROM (${options.query})` + renderOptionGroup("FILE_FORMAT", options.fileFormat) + (copyOptions ? ` ${formatOptions(copyOptions)}` : "") + partition,
52
+ warehouse: options.warehouse,
53
+ role: options.role
54
+ });
55
+ }
56
+ async function truncateTable(client, options) {
57
+ await executeSql(client, {
58
+ statement: `TRUNCATE TABLE${options.ifExists ? " IF EXISTS" : ""} ${tableFqn(options)}`,
59
+ warehouse: options.warehouse,
60
+ role: options.role
61
+ });
62
+ }
63
+
64
+ //#endregion
65
+ export { copyInto, truncateTable, unload, validateCopyInto };
@@ -0,0 +1,144 @@
1
+ import { SnowflakeClient } from "./client.mjs";
2
+ import { d as HydratedRow } from "./statements-DJL0qVNA.mjs";
3
+ //#region src/catalog.d.ts
4
+ interface ShowOptions {
5
+ /** Optional `LIKE '<pattern>'` filter. Escaped via {@link quoteLiteral}. */
6
+ readonly like?: string;
7
+ /** Cap results. Snowflake supports `LIMIT <n>` on SHOW. */
8
+ readonly limit?: number;
9
+ /** Runtime overrides forwarded to {@link executeSql}. */
10
+ readonly warehouse?: string;
11
+ readonly role?: string;
12
+ readonly database?: string;
13
+ readonly schema?: string;
14
+ }
15
+ interface ShowScopedOptions extends ShowOptions {
16
+ /** Restrict results to the named database. */
17
+ readonly inDatabase?: string;
18
+ /** Restrict to a `DB.SCHEMA` scope. */
19
+ readonly inSchema?: {
20
+ readonly database: string;
21
+ readonly schema: string;
22
+ };
23
+ /** Restrict to `SHOW X IN ACCOUNT`. */
24
+ readonly inAccount?: boolean;
25
+ }
26
+ interface CatalogResult {
27
+ readonly rows: readonly HydratedRow[];
28
+ readonly columns: readonly {
29
+ readonly name: string;
30
+ readonly type: string;
31
+ }[];
32
+ }
33
+ interface ShowDatabasesOptions extends ShowOptions {}
34
+ declare function showDatabases(client: SnowflakeClient, options?: ShowDatabasesOptions): Promise<CatalogResult>;
35
+ interface ShowSchemasOptions extends ShowScopedOptions {
36
+ /** `HISTORY` variant returns dropped schemas too. */
37
+ readonly history?: boolean;
38
+ }
39
+ declare function showSchemas(client: SnowflakeClient, options?: ShowSchemasOptions): Promise<CatalogResult>;
40
+ interface ShowTablesOptions extends ShowScopedOptions {
41
+ readonly history?: boolean;
42
+ /** Cascading to TEMPORARY + TRANSIENT + EXTERNAL tables. */
43
+ readonly terse?: boolean;
44
+ }
45
+ declare function showTables(client: SnowflakeClient, options?: ShowTablesOptions): Promise<CatalogResult>;
46
+ interface ShowViewsOptions extends ShowScopedOptions {
47
+ readonly terse?: boolean;
48
+ }
49
+ declare function showViews(client: SnowflakeClient, options?: ShowViewsOptions): Promise<CatalogResult>;
50
+ interface ShowMaterializedViewsOptions extends ShowScopedOptions {}
51
+ declare function showMaterializedViews(client: SnowflakeClient, options?: ShowMaterializedViewsOptions): Promise<CatalogResult>;
52
+ interface ShowColumnsOptions extends ShowOptions {
53
+ readonly inTable?: {
54
+ readonly database?: string;
55
+ readonly schema?: string;
56
+ readonly table: string;
57
+ };
58
+ readonly inView?: {
59
+ readonly database?: string;
60
+ readonly schema?: string;
61
+ readonly view: string;
62
+ };
63
+ readonly inSchema?: {
64
+ readonly database: string;
65
+ readonly schema: string;
66
+ };
67
+ readonly inDatabase?: string;
68
+ }
69
+ declare function showColumns(client: SnowflakeClient, options?: ShowColumnsOptions): Promise<CatalogResult>;
70
+ declare function showWarehouses(client: SnowflakeClient, options?: ShowOptions): Promise<CatalogResult>;
71
+ declare function showRoles(client: SnowflakeClient, options?: ShowOptions): Promise<CatalogResult>;
72
+ declare function showUsers(client: SnowflakeClient, options?: ShowOptions): Promise<CatalogResult>;
73
+ declare function showStages(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
74
+ declare function showPipes(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
75
+ declare function showTasks(client: SnowflakeClient, options?: ShowScopedOptions & {
76
+ readonly terse?: boolean;
77
+ }): Promise<CatalogResult>;
78
+ declare function showStreams(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
79
+ declare function showShares(client: SnowflakeClient, options?: ShowOptions): Promise<CatalogResult>;
80
+ declare function showFunctions(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
81
+ declare function showProcedures(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
82
+ declare function showFileFormats(client: SnowflakeClient, options?: ShowScopedOptions): Promise<CatalogResult>;
83
+ interface ShowGrantsOptions extends ShowOptions {
84
+ /** `SHOW GRANTS ON <object>`. Object keyword is caller-provided (TABLE, DATABASE, etc.). */
85
+ readonly on?: {
86
+ readonly objectType: string;
87
+ readonly name: string;
88
+ readonly schema?: string;
89
+ readonly database?: string;
90
+ };
91
+ /** `SHOW GRANTS TO {ROLE | USER | SHARE} <name>`. */
92
+ readonly toRole?: string;
93
+ readonly toUser?: string;
94
+ readonly toShare?: string;
95
+ /** `SHOW GRANTS OF ROLE <name>`. */
96
+ readonly ofRole?: string;
97
+ readonly ofShare?: string;
98
+ }
99
+ declare function showGrants(client: SnowflakeClient, options?: ShowGrantsOptions): Promise<CatalogResult>;
100
+ interface DescribeTableOptions extends Pick<ShowOptions, 'warehouse' | 'role'> {
101
+ readonly database?: string;
102
+ readonly schema?: string;
103
+ readonly table: string;
104
+ /** `DESCRIBE TABLE X TYPE = STAGE | COLUMNS` (default COLUMNS). */
105
+ readonly type?: 'COLUMNS' | 'STAGE';
106
+ }
107
+ declare function describeTable(client: SnowflakeClient, options: DescribeTableOptions): Promise<CatalogResult>;
108
+ interface ExploreColumnsOptions extends Pick<ShowOptions, 'warehouse' | 'role'> {
109
+ readonly database?: string;
110
+ readonly schema?: string;
111
+ readonly table: string;
112
+ /** Restrict to these columns; when empty, all columns are sampled. */
113
+ readonly columns?: readonly string[];
114
+ /** Distinct-value sample cap per column (default 100). */
115
+ readonly limit?: number;
116
+ }
117
+ interface ExploreColumnsResult {
118
+ readonly table: string;
119
+ readonly samples: readonly {
120
+ readonly column: string;
121
+ readonly distinctValues: readonly unknown[];
122
+ }[];
123
+ }
124
+ /**
125
+ * Composio `SNOWFLAKE_BASIC_EXPLORE_COLUMNS` parity — pull a small distinct
126
+ * sample from each requested column to help LLMs disambiguate column
127
+ * semantics.
128
+ */
129
+ declare function exploreColumns(client: SnowflakeClient, options: ExploreColumnsOptions): Promise<ExploreColumnsResult>;
130
+ interface FindDatabasesOptions extends ShowOptions {
131
+ /** Optional case-insensitive substring match applied client-side. */
132
+ readonly nameContains?: string;
133
+ }
134
+ declare function findDatabases(client: SnowflakeClient, options?: FindDatabasesOptions): Promise<CatalogResult>;
135
+ interface FindSchemasOptions extends ShowSchemasOptions {
136
+ readonly nameContains?: string;
137
+ }
138
+ declare function findSchemas(client: SnowflakeClient, options?: FindSchemasOptions): Promise<CatalogResult>;
139
+ interface FindTablesOptions extends ShowTablesOptions {
140
+ readonly nameContains?: string;
141
+ }
142
+ declare function findTables(client: SnowflakeClient, options?: FindTablesOptions): Promise<CatalogResult>;
143
+ //#endregion
144
+ export { CatalogResult, DescribeTableOptions, ExploreColumnsOptions, ExploreColumnsResult, FindDatabasesOptions, FindSchemasOptions, FindTablesOptions, ShowColumnsOptions, ShowDatabasesOptions, ShowGrantsOptions, ShowMaterializedViewsOptions, ShowOptions, ShowSchemasOptions, ShowScopedOptions, ShowTablesOptions, ShowViewsOptions, describeTable, exploreColumns, findDatabases, findSchemas, findTables, showColumns, showDatabases, showFileFormats, showFunctions, showGrants, showMaterializedViews, showPipes, showProcedures, showRoles, showSchemas, showShares, showStages, showStreams, showTables, showTasks, showUsers, showViews, showWarehouses };