@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/dist/sql.mjs ADDED
@@ -0,0 +1,209 @@
1
+ import { n as SnowflakeSqlError, t as SnowflakeApiError } from "./errors-DKnc9o_a.mjs";
2
+ import { a as submitStatementInputSchema, n as statementResponseSchema, o as partitionResponseSchema, r as statementStatus } from "./statements-B2ThF_4b.mjs";
3
+ import { hydrateRows } from "./results.mjs";
4
+
5
+ //#region src/sql.ts
6
+ const STATEMENTS_PATH = "/api/v2/statements";
7
+ /**
8
+ * Submit a statement. When `async: true` (or the server chooses async) we
9
+ * return the inflated response envelope along with the `pending` status so
10
+ * callers can poll via {@link getStatement} / {@link waitForStatement}.
11
+ *
12
+ * The SQL API itself keys idempotency on the `requestId` query param which
13
+ * {@link SnowflakeClient} auto-populates — callers can override it per
14
+ * request when they need deterministic retries.
15
+ */
16
+ async function submitStatement(client, input, options = {}) {
17
+ const parsed = submitStatementInputSchema.parse(input);
18
+ const query = {};
19
+ if (options.async) query.async = true;
20
+ const response = await client.requestRaw(STATEMENTS_PATH, {
21
+ method: "POST",
22
+ body: parsed,
23
+ query,
24
+ requestId: options.requestId
25
+ });
26
+ const body = await response.json();
27
+ const envelope = statementResponseSchema.parse(body);
28
+ return {
29
+ response: envelope,
30
+ httpStatus: response.status,
31
+ status: statementStatus({
32
+ httpStatus: response.status,
33
+ code: envelope.code
34
+ })
35
+ };
36
+ }
37
+ /**
38
+ * Fetch the current status of a previously submitted async statement. Returns
39
+ * both the envelope and the derived `status` bucket.
40
+ */
41
+ async function getStatement(client, handle, options = {}) {
42
+ const query = options.partition !== void 0 ? { partition: options.partition } : void 0;
43
+ const response = await client.requestRaw(`${STATEMENTS_PATH}/${encodeURIComponent(handle)}`, {
44
+ method: "GET",
45
+ query
46
+ });
47
+ const body = await response.json();
48
+ const envelope = statementResponseSchema.parse(body);
49
+ return {
50
+ response: envelope,
51
+ httpStatus: response.status,
52
+ status: statementStatus({
53
+ httpStatus: response.status,
54
+ code: envelope.code
55
+ })
56
+ };
57
+ }
58
+ /**
59
+ * POST `/cancel`. Snowflake responds with `code: 333335` on success — we
60
+ * normalise anything else into a {@link SnowflakeApiError}.
61
+ */
62
+ async function cancelStatement(client, handle) {
63
+ const response = await client.requestRaw(`${STATEMENTS_PATH}/${encodeURIComponent(handle)}/cancel`, {
64
+ method: "POST",
65
+ retry: false
66
+ });
67
+ if (!response.ok) {
68
+ const text = await response.text().catch(() => "");
69
+ throw new SnowflakeApiError({
70
+ kind: "http",
71
+ status: response.status,
72
+ message: `Failed to cancel statement ${handle}: ${text || response.statusText}`
73
+ });
74
+ }
75
+ }
76
+ /**
77
+ * Submit + wait + fetch all partitions in one go. The returned rows are
78
+ * hydrated into objects keyed by column name by default; pass
79
+ * `hydrate: false` to get the raw tuple form.
80
+ */
81
+ async function executeSql(client, input, options = {}) {
82
+ const submitted = await submitStatement(client, input, options);
83
+ let envelope = submitted.response;
84
+ let status = submitted.status;
85
+ if (status === "pending") {
86
+ envelope = await waitForStatementEnvelope(client, envelope.statementHandle, options);
87
+ status = statementStatus({
88
+ httpStatus: 200,
89
+ code: envelope.code
90
+ });
91
+ }
92
+ if (status === "cancelled") throw new SnowflakeSqlError({
93
+ kind: "cancelled",
94
+ status: 200,
95
+ message: envelope.message ?? "Statement was cancelled",
96
+ code: envelope.code,
97
+ sqlState: envelope.sqlState,
98
+ statementHandle: envelope.statementHandle
99
+ });
100
+ if (status === "failed") throw new SnowflakeSqlError({
101
+ kind: "sql",
102
+ status: 422,
103
+ message: envelope.message ?? "Statement failed",
104
+ code: envelope.code,
105
+ sqlState: envelope.sqlState,
106
+ statementHandle: envelope.statementHandle
107
+ });
108
+ const columns = envelope.resultSetMetaData?.rowType ?? [];
109
+ const partitionCount = envelope.resultSetMetaData?.partitionInfo?.length ?? (envelope.data ? 1 : 0);
110
+ const firstRows = envelope.data ?? [];
111
+ const remainder = [];
112
+ for (let i = 1; i < partitionCount; i += 1) {
113
+ const partition = await getStatementResultPartition(client, envelope.statementHandle, i);
114
+ remainder.push(...partition.data ?? []);
115
+ }
116
+ const rawRows = [...firstRows, ...remainder];
117
+ const rows = options.hydrate !== false ? hydrateRows(rawRows, columns) : rawRows;
118
+ return {
119
+ handle: envelope.statementHandle,
120
+ columns,
121
+ rows,
122
+ envelope,
123
+ partitions: Math.max(1, partitionCount)
124
+ };
125
+ }
126
+ /**
127
+ * Composio `SNOWFLAKE_BASIC_RUN_QUERY` parity — requires an explicit
128
+ * database + schema to match the published BASIC shape.
129
+ */
130
+ async function runQuery(client, input, options = {}) {
131
+ return executeSql(client, {
132
+ statement: input.statement,
133
+ database: input.database,
134
+ schema: input.schema_name,
135
+ warehouse: input.warehouse,
136
+ role: input.role
137
+ }, options);
138
+ }
139
+ /**
140
+ * Fetch a single partition for a known handle.
141
+ */
142
+ async function getStatementResultPartition(client, handle, partition) {
143
+ const body = await client.request(`${STATEMENTS_PATH}/${encodeURIComponent(handle)}`, {
144
+ method: "GET",
145
+ query: { partition }
146
+ });
147
+ return partitionResponseSchema.parse(body);
148
+ }
149
+ /**
150
+ * Async iterator over every partition for a handle. Useful for streaming
151
+ * large result sets into downstream pipelines.
152
+ */
153
+ async function* iterateStatementResult(client, handle, options = {}) {
154
+ const first = await getStatementResultPartition(client, handle, 0);
155
+ yield first;
156
+ const total = first.resultSetMetaData?.partitionInfo?.length ?? 0;
157
+ const cap = Math.min(total, options.maxPartitions ?? total);
158
+ for (let i = 1; i < cap; i += 1) yield await getStatementResultPartition(client, handle, i);
159
+ }
160
+ async function waitForStatementEnvelope(client, handle, options) {
161
+ const pollIntervalMs = options.pollIntervalMs ?? 500;
162
+ const maxWaitMs = options.maxWaitMs ?? 300 * 1e3;
163
+ const now = options.now ?? (() => Date.now());
164
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
165
+ const deadline = now() + maxWaitMs;
166
+ for (;;) {
167
+ const result = await getStatement(client, handle);
168
+ if (result.status !== "pending") return result.response;
169
+ if (now() >= deadline) throw new SnowflakeApiError({
170
+ kind: "timeout",
171
+ status: 0,
172
+ message: `Statement ${handle} did not reach a terminal status within ${maxWaitMs}ms`,
173
+ retryable: false
174
+ });
175
+ await sleep(pollIntervalMs);
176
+ }
177
+ }
178
+ /**
179
+ * Blocking helper: polls `getStatement` until the statement reaches a
180
+ * terminal status or the `maxWaitMs` budget elapses. Returns the terminal
181
+ * envelope (throws for `failed` / `cancelled`).
182
+ */
183
+ async function waitForStatement(client, handle, options = {}) {
184
+ const envelope = await waitForStatementEnvelope(client, handle, options);
185
+ const status = statementStatus({
186
+ httpStatus: 200,
187
+ code: envelope.code
188
+ });
189
+ if (status === "failed") throw new SnowflakeSqlError({
190
+ kind: "sql",
191
+ status: 422,
192
+ message: envelope.message ?? "Statement failed",
193
+ code: envelope.code,
194
+ sqlState: envelope.sqlState,
195
+ statementHandle: envelope.statementHandle
196
+ });
197
+ if (status === "cancelled") throw new SnowflakeSqlError({
198
+ kind: "cancelled",
199
+ status: 200,
200
+ message: envelope.message ?? "Statement was cancelled",
201
+ code: envelope.code,
202
+ sqlState: envelope.sqlState,
203
+ statementHandle: envelope.statementHandle
204
+ });
205
+ return envelope;
206
+ }
207
+
208
+ //#endregion
209
+ export { cancelStatement, executeSql, getStatement, getStatementResultPartition, iterateStatementResult, runQuery, submitStatement, waitForStatement };
@@ -0,0 +1,64 @@
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 { CatalogResult, ShowScopedOptions, showStages } from "./catalog.mjs";
6
+
7
+ //#region src/stages.d.ts
8
+ interface StageRef {
9
+ readonly database?: string;
10
+ readonly schema?: string;
11
+ readonly name: string;
12
+ }
13
+ interface StageContext {
14
+ readonly warehouse?: string;
15
+ readonly role?: string;
16
+ }
17
+ /** `@<fqn>` form used inside LIST / REMOVE / COPY INTO commands. */
18
+ declare function stagePath(ref: StageRef, pathSuffix?: string): string;
19
+ interface CreateStageOptions extends StageRef, StageContext {
20
+ readonly orReplace?: boolean;
21
+ readonly ifNotExists?: boolean;
22
+ readonly temporary?: boolean;
23
+ /** `URL='...'`, `STORAGE_INTEGRATION='...'`, `CREDENTIALS=(...)`, `ENCRYPTION=(...)`, etc. */
24
+ readonly options?: OptionMap;
25
+ readonly fileFormat?: OptionMap;
26
+ readonly copyOptions?: OptionMap;
27
+ readonly comment?: string;
28
+ }
29
+ declare function createStage(client: SnowflakeClient, options: CreateStageOptions): Promise<void>;
30
+ interface AlterStageOptions extends StageRef, StageContext {
31
+ readonly rename?: StageRef;
32
+ readonly set?: OptionMap;
33
+ readonly unset?: readonly string[];
34
+ readonly refreshSubpath?: string;
35
+ readonly comment?: string;
36
+ }
37
+ declare function alterStage(client: SnowflakeClient, options: AlterStageOptions): Promise<void>;
38
+ interface DropStageOptions extends StageRef, StageContext {
39
+ readonly ifExists?: boolean;
40
+ }
41
+ declare function dropStage(client: SnowflakeClient, options: DropStageOptions): Promise<void>;
42
+ interface DescribeStageOptions extends StageRef, StageContext {}
43
+ declare function describeStage(client: SnowflakeClient, options: DescribeStageOptions): Promise<readonly HydratedRow[]>;
44
+ interface ListStageFilesOptions extends StageRef, StageContext {
45
+ readonly pathSuffix?: string;
46
+ /** Regex pattern matched against file names. */
47
+ readonly pattern?: string;
48
+ }
49
+ declare function listStageFiles(client: SnowflakeClient, options: ListStageFilesOptions): Promise<readonly HydratedRow[]>;
50
+ interface RemoveStageFilesOptions extends StageRef, StageContext {
51
+ readonly pathSuffix?: string;
52
+ readonly pattern?: string;
53
+ }
54
+ declare function removeStageFiles(client: SnowflakeClient, options: RemoveStageFilesOptions): Promise<ExecuteSqlResult<HydratedRow | readonly unknown[]>>;
55
+ /**
56
+ * PUT is not supported by the Snowflake SQL API v2 — the API cannot accept
57
+ * raw file bytes. Callers needing a file upload should use a pre-signed S3
58
+ * URL + external stage, or drive `snowsql`/`snowflake-sdk` from a trusted
59
+ * context.
60
+ */
61
+ declare function putFile(): never;
62
+ declare function getFile(): never;
63
+ //#endregion
64
+ export { AlterStageOptions, type CatalogResult, CreateStageOptions, DescribeStageOptions, DropStageOptions, ListStageFilesOptions, RemoveStageFilesOptions, type ShowScopedOptions, StageContext, StageRef, alterStage, createStage, describeStage, dropStage, getFile, listStageFiles, putFile, removeStageFiles, showStages, stagePath };
@@ -0,0 +1,81 @@
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 { showStages } from "./catalog.mjs";
5
+
6
+ //#region src/stages.ts
7
+ function stageFqn(ref) {
8
+ return buildFqn(ref.database, ref.schema, ref.name);
9
+ }
10
+ /** `@<fqn>` form used inside LIST / REMOVE / COPY INTO commands. */
11
+ function stagePath(ref, pathSuffix) {
12
+ const fqn = stageFqn(ref);
13
+ if (!pathSuffix) return `@${fqn}`;
14
+ return `@${fqn}${pathSuffix.startsWith("/") ? pathSuffix : `/${pathSuffix}`}`;
15
+ }
16
+ async function createStage(client, options) {
17
+ const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""}${options.temporary ? " TEMPORARY" : ""} STAGE${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
18
+ const topOptions = options.options ? ` ${formatOptions(options.options)}` : "";
19
+ await executeSql(client, {
20
+ statement: `${prefix} ${stageFqn(options)}${topOptions}` + renderOptionGroup("FILE_FORMAT", options.fileFormat) + renderOptionGroup("COPY_OPTIONS", options.copyOptions) + (options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : ""),
21
+ warehouse: options.warehouse,
22
+ role: options.role
23
+ });
24
+ }
25
+ async function alterStage(client, options) {
26
+ let tail;
27
+ if (options.rename) tail = `RENAME TO ${stageFqn(options.rename)}`;
28
+ else if (options.refreshSubpath !== void 0) tail = `REFRESH${options.refreshSubpath.length > 0 ? ` SUBPATH = ${quoteLiteral(options.refreshSubpath)}` : ""}`;
29
+ else if (options.set && Object.keys(options.set).length > 0) tail = `SET ${formatOptions(options.set)}`;
30
+ else if (options.unset && options.unset.length > 0) tail = `UNSET ${options.unset.map((k) => k.toUpperCase()).join(", ")}`;
31
+ else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
32
+ else throw new Error("alterStage requires one of: rename / refreshSubpath / set / unset / comment");
33
+ await executeSql(client, {
34
+ statement: `ALTER STAGE ${stageFqn(options)} ${tail}`,
35
+ warehouse: options.warehouse,
36
+ role: options.role
37
+ });
38
+ }
39
+ async function dropStage(client, options) {
40
+ await executeSql(client, {
41
+ statement: `DROP STAGE${options.ifExists ? " IF EXISTS" : ""} ${stageFqn(options)}`,
42
+ warehouse: options.warehouse,
43
+ role: options.role
44
+ });
45
+ }
46
+ async function describeStage(client, options) {
47
+ return (await executeSql(client, {
48
+ statement: `DESCRIBE STAGE ${stageFqn(options)}`,
49
+ warehouse: options.warehouse,
50
+ role: options.role
51
+ })).rows;
52
+ }
53
+ async function listStageFiles(client, options) {
54
+ return (await executeSql(client, {
55
+ statement: `LIST ${stagePath(options, options.pathSuffix)}${options.pattern ? ` PATTERN = ${quoteLiteral(options.pattern)}` : ""}`,
56
+ warehouse: options.warehouse,
57
+ role: options.role
58
+ })).rows;
59
+ }
60
+ async function removeStageFiles(client, options) {
61
+ return executeSql(client, {
62
+ statement: `REMOVE ${stagePath(options, options.pathSuffix)}${options.pattern ? ` PATTERN = ${quoteLiteral(options.pattern)}` : ""}`,
63
+ warehouse: options.warehouse,
64
+ role: options.role
65
+ });
66
+ }
67
+ /**
68
+ * PUT is not supported by the Snowflake SQL API v2 — the API cannot accept
69
+ * raw file bytes. Callers needing a file upload should use a pre-signed S3
70
+ * URL + external stage, or drive `snowsql`/`snowflake-sdk` from a trusted
71
+ * context.
72
+ */
73
+ function putFile() {
74
+ throw new Error("putFile is not supported by the REST integration — use a pre-signed stage URL or the official Snowflake driver to upload raw file bytes.");
75
+ }
76
+ function getFile() {
77
+ throw new Error("getFile is not supported by the REST integration — use a pre-signed stage URL or the official Snowflake driver to download raw file bytes.");
78
+ }
79
+
80
+ //#endregion
81
+ export { alterStage, createStage, describeStage, dropStage, getFile, listStageFiles, putFile, removeStageFiles, showStages, stagePath };
@@ -0,0 +1,81 @@
1
+ import { c as sqlBindingsSchema, l as statementContextSchema, r as resultSetMetaDataSchema } from "./common-BnKTPQXc.mjs";
2
+ import { z } from "zod";
3
+
4
+ //#region src/schemas/results.ts
5
+ /**
6
+ * Result-partition + row hydration schemas.
7
+ *
8
+ * A single partition response arrives under `GET /api/v2/statements/{handle}?partition={n}`
9
+ * and uses the same envelope as the submit response — just with `data`
10
+ * populated with the rows for that partition.
11
+ */
12
+ const partitionResponseSchema = z.object({
13
+ statementHandle: z.string().optional(),
14
+ code: z.string().optional(),
15
+ message: z.string().optional(),
16
+ resultSetMetaData: resultSetMetaDataSchema.optional(),
17
+ data: z.array(z.array(z.unknown())).optional()
18
+ }).catchall(z.unknown());
19
+
20
+ //#endregion
21
+ //#region src/schemas/statements.ts
22
+ /**
23
+ * Schemas for the Snowflake SQL API v2 statement endpoints.
24
+ *
25
+ * https://docs.snowflake.com/en/developer-guide/sql-api/submitting-requests
26
+ * https://docs.snowflake.com/en/developer-guide/sql-api/responses-errors
27
+ */
28
+ /** Status code reported under `code` / `message` alongside the HTTP status. */
29
+ const statementStatusCodeSchema = z.string();
30
+ /**
31
+ * Input body for `POST /api/v2/statements`.
32
+ * `statement` is required. All other fields fall back to session / account
33
+ * defaults when omitted.
34
+ */
35
+ const submitStatementInputSchema = z.object({
36
+ statement: z.string().min(1),
37
+ bindings: sqlBindingsSchema.optional()
38
+ }).merge(statementContextSchema).strict();
39
+ /**
40
+ * Response body for a submitted statement — either the inline result (200)
41
+ * or a pending handle (202).
42
+ */
43
+ const statementResponseSchema = z.object({
44
+ code: statementStatusCodeSchema.optional(),
45
+ sqlState: z.string().optional(),
46
+ message: z.string().optional(),
47
+ statementHandle: z.string(),
48
+ statementStatusUrl: z.string().optional(),
49
+ createdOn: z.number().optional(),
50
+ requestId: z.string().optional(),
51
+ statementHandles: z.array(z.string()).optional(),
52
+ resultSetMetaData: resultSetMetaDataSchema.optional(),
53
+ data: z.array(z.array(z.unknown())).optional()
54
+ }).catchall(z.unknown());
55
+ /**
56
+ * Snowflake code ranges (SQL API v2):
57
+ * - 090002 — success (inline result)
58
+ * - 333333 — statement accepted (async)
59
+ * - 333334 — statement executing (still polling)
60
+ * - 333335 — user-triggered cancel succeeded
61
+ * - 390xxx / 3900xx / 0919xx / ... — SQL-level failures
62
+ *
63
+ * We map explicitly the two non-error status codes; everything else is
64
+ * treated as `failed` when the HTTP status is also an error, otherwise
65
+ * `done`.
66
+ */
67
+ function statementStatus(input) {
68
+ if (input.httpStatus === 202) return "pending";
69
+ if (input.code === "333334" || input.code === "333333") return "pending";
70
+ if (input.code === "333335") return "cancelled";
71
+ if (input.httpStatus >= 400) return "failed";
72
+ return "done";
73
+ }
74
+ const cancelStatementResponseSchema = z.object({
75
+ code: z.string().optional(),
76
+ message: z.string().optional(),
77
+ statementHandle: z.string().optional()
78
+ }).catchall(z.unknown());
79
+
80
+ //#endregion
81
+ export { submitStatementInputSchema as a, statementStatusCodeSchema as i, statementResponseSchema as n, partitionResponseSchema as o, statementStatus as r, cancelStatementResponseSchema as t };
@@ -0,0 +1,238 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas/common.d.ts
4
+ /**
5
+ * Snowflake identifiers are 1-255 chars. Unquoted identifiers are normalized
6
+ * to upper-case; quoted identifiers preserve case. We keep raw validation
7
+ * permissive and let the server reject bad names — a strict regex would
8
+ * forbid unicode-quoted identifiers legitimately used in the wild.
9
+ */
10
+ declare const snowflakeIdentifier: z.ZodString;
11
+ /**
12
+ * Fully-qualified name: `DATABASE.SCHEMA.NAME` (or subsets). Stored as a
13
+ * single string; we do *not* split/rejoin so callers can pass quoted
14
+ * segments through verbatim.
15
+ */
16
+ declare const snowflakeFqn: z.ZodString;
17
+ /**
18
+ * Optional context overrides applied per-statement.
19
+ * Every field is optional — absent values fall back to the connection's
20
+ * session defaults and then to account-level defaults.
21
+ */
22
+ declare const statementContextSchema: z.ZodObject<{
23
+ database: z.ZodOptional<z.ZodString>;
24
+ schema: z.ZodOptional<z.ZodString>;
25
+ warehouse: z.ZodOptional<z.ZodString>;
26
+ role: z.ZodOptional<z.ZodString>;
27
+ timeout: z.ZodOptional<z.ZodNumber>;
28
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
29
+ }, z.core.$strict>;
30
+ type StatementContext = z.infer<typeof statementContextSchema>;
31
+ /**
32
+ * SQL API v2 supports typed bindings: each binding is an object with a
33
+ * `type` and a `value`. We allow the simple positional shape and the
34
+ * keyed-map shape Snowflake accepts.
35
+ */
36
+ declare const sqlBindingValueSchema: z.ZodObject<{
37
+ type: z.ZodString;
38
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
39
+ }, z.core.$strip>;
40
+ declare const sqlBindingsSchema: z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodObject<{
41
+ type: z.ZodString;
42
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
43
+ }, z.core.$strip>>, z.ZodArray<z.ZodObject<{
44
+ type: z.ZodString;
45
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
46
+ }, z.core.$strip>>]>;
47
+ type SqlBinding = z.infer<typeof sqlBindingValueSchema>;
48
+ type SqlBindings = z.infer<typeof sqlBindingsSchema>;
49
+ /**
50
+ * Loosely-typed record shape for objects returned by `SHOW ...` commands.
51
+ * Snowflake returns positional arrays with a `rowType[]` describing each
52
+ * column — callers either consume the tuple form directly or `hydrateRow`
53
+ * into a `Record<string, unknown>`.
54
+ */
55
+ declare const snowflakeObjectRowSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
56
+ type SnowflakeObjectRow = z.infer<typeof snowflakeObjectRowSchema>;
57
+ /**
58
+ * Column metadata entry as returned under `resultSetMetaData.rowType`.
59
+ */
60
+ declare const columnMetaSchema: z.ZodObject<{
61
+ name: z.ZodString;
62
+ type: z.ZodString;
63
+ nullable: z.ZodOptional<z.ZodBoolean>;
64
+ length: z.ZodOptional<z.ZodNumber>;
65
+ precision: z.ZodOptional<z.ZodNumber>;
66
+ scale: z.ZodOptional<z.ZodNumber>;
67
+ byteLength: z.ZodOptional<z.ZodNumber>;
68
+ collation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ database: z.ZodOptional<z.ZodString>;
70
+ schema: z.ZodOptional<z.ZodString>;
71
+ table: z.ZodOptional<z.ZodString>;
72
+ }, z.core.$catchall<z.ZodUnknown>>;
73
+ type ColumnMeta = z.infer<typeof columnMetaSchema>;
74
+ /**
75
+ * Partition entry describing a shard of the total result set.
76
+ */
77
+ declare const partitionInfoSchema: z.ZodObject<{
78
+ rowCount: z.ZodNumber;
79
+ uncompressedSize: z.ZodOptional<z.ZodNumber>;
80
+ compressedSize: z.ZodOptional<z.ZodNumber>;
81
+ }, z.core.$catchall<z.ZodUnknown>>;
82
+ type PartitionInfo = z.infer<typeof partitionInfoSchema>;
83
+ declare const resultSetMetaDataSchema: z.ZodObject<{
84
+ numRows: z.ZodOptional<z.ZodNumber>;
85
+ format: z.ZodOptional<z.ZodString>;
86
+ partitionInfo: z.ZodOptional<z.ZodArray<z.ZodObject<{
87
+ rowCount: z.ZodNumber;
88
+ uncompressedSize: z.ZodOptional<z.ZodNumber>;
89
+ compressedSize: z.ZodOptional<z.ZodNumber>;
90
+ }, z.core.$catchall<z.ZodUnknown>>>>;
91
+ rowType: z.ZodOptional<z.ZodArray<z.ZodObject<{
92
+ name: z.ZodString;
93
+ type: z.ZodString;
94
+ nullable: z.ZodOptional<z.ZodBoolean>;
95
+ length: z.ZodOptional<z.ZodNumber>;
96
+ precision: z.ZodOptional<z.ZodNumber>;
97
+ scale: z.ZodOptional<z.ZodNumber>;
98
+ byteLength: z.ZodOptional<z.ZodNumber>;
99
+ collation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
100
+ database: z.ZodOptional<z.ZodString>;
101
+ schema: z.ZodOptional<z.ZodString>;
102
+ table: z.ZodOptional<z.ZodString>;
103
+ }, z.core.$catchall<z.ZodUnknown>>>>;
104
+ }, z.core.$catchall<z.ZodUnknown>>;
105
+ type ResultSetMetaData = z.infer<typeof resultSetMetaDataSchema>;
106
+ //#endregion
107
+ //#region src/schemas/results.d.ts
108
+ declare const partitionResponseSchema: z.ZodObject<{
109
+ statementHandle: z.ZodOptional<z.ZodString>;
110
+ code: z.ZodOptional<z.ZodString>;
111
+ message: z.ZodOptional<z.ZodString>;
112
+ resultSetMetaData: z.ZodOptional<z.ZodObject<{
113
+ numRows: z.ZodOptional<z.ZodNumber>;
114
+ format: z.ZodOptional<z.ZodString>;
115
+ partitionInfo: z.ZodOptional<z.ZodArray<z.ZodObject<{
116
+ rowCount: z.ZodNumber;
117
+ uncompressedSize: z.ZodOptional<z.ZodNumber>;
118
+ compressedSize: z.ZodOptional<z.ZodNumber>;
119
+ }, z.core.$catchall<z.ZodUnknown>>>>;
120
+ rowType: z.ZodOptional<z.ZodArray<z.ZodObject<{
121
+ name: z.ZodString;
122
+ type: z.ZodString;
123
+ nullable: z.ZodOptional<z.ZodBoolean>;
124
+ length: z.ZodOptional<z.ZodNumber>;
125
+ precision: z.ZodOptional<z.ZodNumber>;
126
+ scale: z.ZodOptional<z.ZodNumber>;
127
+ byteLength: z.ZodOptional<z.ZodNumber>;
128
+ collation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
129
+ database: z.ZodOptional<z.ZodString>;
130
+ schema: z.ZodOptional<z.ZodString>;
131
+ table: z.ZodOptional<z.ZodString>;
132
+ }, z.core.$catchall<z.ZodUnknown>>>>;
133
+ }, z.core.$catchall<z.ZodUnknown>>>;
134
+ data: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnknown>>>;
135
+ }, z.core.$catchall<z.ZodUnknown>>;
136
+ type PartitionResponse = z.infer<typeof partitionResponseSchema>;
137
+ /**
138
+ * A single logical row as hydrated into an object keyed by column name.
139
+ * Values are permissive (`unknown`) because Snowflake types map to many
140
+ * TS shapes — callers coerce further with `hydrateValue` when needed.
141
+ */
142
+ type HydratedRow = Record<string, unknown>;
143
+ //#endregion
144
+ //#region src/schemas/statements.d.ts
145
+ /** Status code reported under `code` / `message` alongside the HTTP status. */
146
+ declare const statementStatusCodeSchema: z.ZodString;
147
+ /**
148
+ * Input body for `POST /api/v2/statements`.
149
+ * `statement` is required. All other fields fall back to session / account
150
+ * defaults when omitted.
151
+ */
152
+ declare const submitStatementInputSchema: z.ZodObject<{
153
+ statement: z.ZodString;
154
+ bindings: z.ZodOptional<z.ZodUnion<[z.ZodRecord<z.ZodString, z.ZodObject<{
155
+ type: z.ZodString;
156
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
157
+ }, z.core.$strip>>, z.ZodArray<z.ZodObject<{
158
+ type: z.ZodString;
159
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
160
+ }, z.core.$strip>>]>>;
161
+ database: z.ZodOptional<z.ZodString>;
162
+ schema: z.ZodOptional<z.ZodString>;
163
+ warehouse: z.ZodOptional<z.ZodString>;
164
+ role: z.ZodOptional<z.ZodString>;
165
+ timeout: z.ZodOptional<z.ZodNumber>;
166
+ parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
167
+ }, z.core.$strict>;
168
+ type SubmitStatementInput = z.infer<typeof submitStatementInputSchema>;
169
+ /**
170
+ * Response body for a submitted statement — either the inline result (200)
171
+ * or a pending handle (202).
172
+ */
173
+ declare const statementResponseSchema: z.ZodObject<{
174
+ code: z.ZodOptional<z.ZodString>;
175
+ sqlState: z.ZodOptional<z.ZodString>;
176
+ message: z.ZodOptional<z.ZodString>;
177
+ statementHandle: z.ZodString;
178
+ statementStatusUrl: z.ZodOptional<z.ZodString>;
179
+ createdOn: z.ZodOptional<z.ZodNumber>;
180
+ requestId: z.ZodOptional<z.ZodString>;
181
+ statementHandles: z.ZodOptional<z.ZodArray<z.ZodString>>;
182
+ resultSetMetaData: z.ZodOptional<z.ZodObject<{
183
+ numRows: z.ZodOptional<z.ZodNumber>;
184
+ format: z.ZodOptional<z.ZodString>;
185
+ partitionInfo: z.ZodOptional<z.ZodArray<z.ZodObject<{
186
+ rowCount: z.ZodNumber;
187
+ uncompressedSize: z.ZodOptional<z.ZodNumber>;
188
+ compressedSize: z.ZodOptional<z.ZodNumber>;
189
+ }, z.core.$catchall<z.ZodUnknown>>>>;
190
+ rowType: z.ZodOptional<z.ZodArray<z.ZodObject<{
191
+ name: z.ZodString;
192
+ type: z.ZodString;
193
+ nullable: z.ZodOptional<z.ZodBoolean>;
194
+ length: z.ZodOptional<z.ZodNumber>;
195
+ precision: z.ZodOptional<z.ZodNumber>;
196
+ scale: z.ZodOptional<z.ZodNumber>;
197
+ byteLength: z.ZodOptional<z.ZodNumber>;
198
+ collation: z.ZodOptional<z.ZodNullable<z.ZodString>>;
199
+ database: z.ZodOptional<z.ZodString>;
200
+ schema: z.ZodOptional<z.ZodString>;
201
+ table: z.ZodOptional<z.ZodString>;
202
+ }, z.core.$catchall<z.ZodUnknown>>>>;
203
+ }, z.core.$catchall<z.ZodUnknown>>>;
204
+ data: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnknown>>>;
205
+ }, z.core.$catchall<z.ZodUnknown>>;
206
+ type StatementResponse = z.infer<typeof statementResponseSchema>;
207
+ /**
208
+ * Terminal + transient statuses as exposed through the `code` field. Most
209
+ * callers only care whether the statement is `pending`, `done`, or
210
+ * `failed` — the `statementStatus` helper below compresses the raw `code`
211
+ * into those buckets.
212
+ */
213
+ type StatementTerminalStatus = 'done' | 'failed' | 'cancelled';
214
+ type StatementStatus = StatementTerminalStatus | 'pending';
215
+ /**
216
+ * Snowflake code ranges (SQL API v2):
217
+ * - 090002 — success (inline result)
218
+ * - 333333 — statement accepted (async)
219
+ * - 333334 — statement executing (still polling)
220
+ * - 333335 — user-triggered cancel succeeded
221
+ * - 390xxx / 3900xx / 0919xx / ... — SQL-level failures
222
+ *
223
+ * We map explicitly the two non-error status codes; everything else is
224
+ * treated as `failed` when the HTTP status is also an error, otherwise
225
+ * `done`.
226
+ */
227
+ declare function statementStatus(input: {
228
+ httpStatus: number;
229
+ code?: string | undefined;
230
+ }): StatementStatus;
231
+ declare const cancelStatementResponseSchema: z.ZodObject<{
232
+ code: z.ZodOptional<z.ZodString>;
233
+ message: z.ZodOptional<z.ZodString>;
234
+ statementHandle: z.ZodOptional<z.ZodString>;
235
+ }, z.core.$catchall<z.ZodUnknown>>;
236
+ type CancelStatementResponse = z.infer<typeof cancelStatementResponseSchema>;
237
+ //#endregion
238
+ export { resultSetMetaDataSchema as C, sqlBindingValueSchema as D, snowflakeObjectRowSchema as E, sqlBindingsSchema as O, partitionInfoSchema as S, snowflakeIdentifier as T, SnowflakeObjectRow as _, SubmitStatementInput as a, StatementContext as b, statementStatus as c, HydratedRow as d, PartitionResponse as f, ResultSetMetaData as g, PartitionInfo as h, StatementTerminalStatus as i, statementContextSchema as k, statementStatusCodeSchema as l, ColumnMeta as m, StatementResponse as n, cancelStatementResponseSchema as o, partitionResponseSchema as p, StatementStatus as r, statementResponseSchema as s, CancelStatementResponse as t, submitStatementInputSchema as u, SqlBinding as v, snowflakeFqn as w, columnMetaSchema as x, SqlBindings as y };