@keystrokehq/snowflake 0.0.16 → 0.0.17

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 (100) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -233
  3. package/dist/actions/index.cjs +18 -0
  4. package/dist/actions/index.d.cts +2 -0
  5. package/dist/actions/index.d.mts +2 -0
  6. package/dist/actions/index.mjs +2 -0
  7. package/dist/actions-BGkaZb6a.cjs +801 -0
  8. package/dist/actions-BGkaZb6a.cjs.map +1 -0
  9. package/dist/actions-BR_JWhT_.mjs +700 -0
  10. package/dist/actions-BR_JWhT_.mjs.map +1 -0
  11. package/dist/index-DUGCZPGQ.d.cts +443 -0
  12. package/dist/index-DUGCZPGQ.d.cts.map +1 -0
  13. package/dist/index-RhOmpRxD.d.mts +445 -0
  14. package/dist/index-RhOmpRxD.d.mts.map +1 -0
  15. package/dist/index.cjs +34 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.cts +19 -0
  18. package/dist/index.d.cts.map +1 -0
  19. package/dist/index.d.mts +19 -4
  20. package/dist/index.d.mts.map +1 -0
  21. package/dist/index.mjs +15 -5
  22. package/dist/index.mjs.map +1 -0
  23. package/package.json +39 -171
  24. package/dist/accounts/index.d.mts +0 -40
  25. package/dist/accounts/index.mjs +0 -51
  26. package/dist/bulk/index.d.mts +0 -71
  27. package/dist/bulk/index.mjs +0 -65
  28. package/dist/catalog/index.d.mts +0 -144
  29. package/dist/catalog/index.mjs +0 -158
  30. package/dist/client/index.d.mts +0 -44
  31. package/dist/client/index.mjs +0 -273
  32. package/dist/common-DfpCwJx5.mjs +0 -92
  33. package/dist/credential-sets/index.d.mts +0 -3
  34. package/dist/credential-sets/index.mjs +0 -4
  35. package/dist/databases/index.d.mts +0 -2
  36. package/dist/databases/index.mjs +0 -3
  37. package/dist/errors-60AsF7Su.mjs +0 -95
  38. package/dist/events/index.d.mts +0 -382
  39. package/dist/events/index.mjs +0 -291
  40. package/dist/file-formats/index.d.mts +0 -39
  41. package/dist/file-formats/index.mjs +0 -48
  42. package/dist/functions/index.d.mts +0 -53
  43. package/dist/functions/index.mjs +0 -56
  44. package/dist/grants/index.d.mts +0 -93
  45. package/dist/grants/index.mjs +0 -102
  46. package/dist/operations/index.d.mts +0 -1
  47. package/dist/operations/index.mjs +0 -1
  48. package/dist/org-admin/index.d.mts +0 -80
  49. package/dist/org-admin/index.mjs +0 -79
  50. package/dist/pipes/index.d.mts +0 -119
  51. package/dist/pipes/index.mjs +0 -106
  52. package/dist/procedures/index.d.mts +0 -61
  53. package/dist/procedures/index.mjs +0 -79
  54. package/dist/results/index.d.mts +0 -16
  55. package/dist/results/index.mjs +0 -64
  56. package/dist/retry-B4-9MZIp.mjs +0 -164
  57. package/dist/retry-w7cTp1QL.d.mts +0 -10
  58. package/dist/roles/index.d.mts +0 -60
  59. package/dist/roles/index.mjs +0 -74
  60. package/dist/rows/index.d.mts +0 -106
  61. package/dist/rows/index.mjs +0 -223
  62. package/dist/schemas/index.d.mts +0 -2
  63. package/dist/schemas/index.mjs +0 -4
  64. package/dist/schemas-catalog/index.d.mts +0 -2
  65. package/dist/schemas-catalog/index.mjs +0 -3
  66. package/dist/shares/index.d.mts +0 -56
  67. package/dist/shares/index.mjs +0 -77
  68. package/dist/snowflake-s3-sns-webhook.credential-set-D6bLAWy5.d.mts +0 -50
  69. package/dist/snowflake-s3-sns-webhook.credential-set-DzR7oWNK.mjs +0 -44
  70. package/dist/snowflake.credential-set-BxT7Gf3A.d.mts +0 -114
  71. package/dist/snowflake.credential-set-DE3gXf-a.mjs +0 -106
  72. package/dist/sql/index.d.mts +0 -84
  73. package/dist/sql/index.mjs +0 -209
  74. package/dist/sql-options-2k5xQ-oS.d.mts +0 -32
  75. package/dist/sql-options-D6GEa21F.mjs +0 -79
  76. package/dist/sql-safety-BZpAPsq6.mjs +0 -56
  77. package/dist/stages/index.d.mts +0 -64
  78. package/dist/stages/index.mjs +0 -81
  79. package/dist/statements-BumhMhN4.mjs +0 -81
  80. package/dist/statements-DJL0qVNA.d.mts +0 -238
  81. package/dist/status-page/index.d.mts +0 -510
  82. package/dist/status-page/index.mjs +0 -261
  83. package/dist/streaming/index.d.mts +0 -70
  84. package/dist/streaming/index.mjs +0 -56
  85. package/dist/streams/index.d.mts +0 -71
  86. package/dist/streams/index.mjs +0 -78
  87. package/dist/tables/index.d.mts +0 -2
  88. package/dist/tables/index.mjs +0 -3
  89. package/dist/tasks/index.d.mts +0 -79
  90. package/dist/tasks/index.mjs +0 -104
  91. package/dist/triggers/index.d.mts +0 -381
  92. package/dist/triggers/index.mjs +0 -1100
  93. package/dist/users/index.d.mts +0 -61
  94. package/dist/users/index.mjs +0 -67
  95. package/dist/verification/index.d.mts +0 -201
  96. package/dist/verification/index.mjs +0 -512
  97. package/dist/views/index.d.mts +0 -2
  98. package/dist/views/index.mjs +0 -3
  99. package/dist/warehouses/index.d.mts +0 -68
  100. package/dist/warehouses/index.mjs +0 -101
@@ -1,60 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { t as OptionMap } from "../sql-options-2k5xQ-oS.mjs";
3
- import { CatalogResult, ShowOptions, showRoles } from "../catalog/index.mjs";
4
-
5
- //#region src/roles/index.d.ts
6
- interface RoleContext {
7
- readonly warehouse?: string;
8
- readonly sessionRole?: string;
9
- }
10
- interface CreateRoleOptions extends RoleContext {
11
- readonly name: string;
12
- readonly orReplace?: boolean;
13
- readonly ifNotExists?: boolean;
14
- readonly comment?: string;
15
- readonly options?: OptionMap;
16
- }
17
- declare function createRole(client: SnowflakeClient, options: CreateRoleOptions): Promise<void>;
18
- interface AlterRoleOptions extends RoleContext {
19
- readonly name: string;
20
- readonly rename?: string;
21
- readonly set?: OptionMap;
22
- readonly unset?: readonly string[];
23
- readonly comment?: string;
24
- readonly ifExists?: boolean;
25
- }
26
- declare function alterRole(client: SnowflakeClient, options: AlterRoleOptions): Promise<void>;
27
- interface DropRoleOptions extends RoleContext {
28
- readonly name: string;
29
- readonly ifExists?: boolean;
30
- }
31
- declare function dropRole(client: SnowflakeClient, options: DropRoleOptions): Promise<void>;
32
- interface UseRoleOptions extends RoleContext {
33
- readonly name: string;
34
- }
35
- declare function useRole(client: SnowflakeClient, options: UseRoleOptions): Promise<void>;
36
- interface GrantRoleToUserOptions extends RoleContext {
37
- /** Role being granted. */
38
- readonly role: string;
39
- readonly user: string;
40
- }
41
- declare function grantRoleToUser(client: SnowflakeClient, options: GrantRoleToUserOptions): Promise<void>;
42
- interface RevokeRoleFromUserOptions extends RoleContext {
43
- readonly role: string;
44
- readonly user: string;
45
- }
46
- declare function revokeRoleFromUser(client: SnowflakeClient, options: RevokeRoleFromUserOptions): Promise<void>;
47
- interface GrantRoleToRoleOptions extends RoleContext {
48
- /** The child role being granted. */
49
- readonly role: string;
50
- /** The parent role that will inherit `role`. */
51
- readonly parentRole: string;
52
- }
53
- declare function grantRoleToRole(client: SnowflakeClient, options: GrantRoleToRoleOptions): Promise<void>;
54
- interface RevokeRoleFromRoleOptions extends RoleContext {
55
- readonly role: string;
56
- readonly parentRole: string;
57
- }
58
- declare function revokeRoleFromRole(client: SnowflakeClient, options: RevokeRoleFromRoleOptions): Promise<void>;
59
- //#endregion
60
- export { AlterRoleOptions, type CatalogResult, CreateRoleOptions, DropRoleOptions, GrantRoleToRoleOptions, GrantRoleToUserOptions, RevokeRoleFromRoleOptions, RevokeRoleFromUserOptions, RoleContext, type ShowOptions, UseRoleOptions, alterRole, createRole, dropRole, grantRoleToRole, grantRoleToUser, revokeRoleFromRole, revokeRoleFromUser, showRoles, useRole };
@@ -1,74 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { a as quoteLiteral, i as quoteIdentifier } from "../sql-safety-BZpAPsq6.mjs";
3
- import { t as formatOptions } from "../sql-options-D6GEa21F.mjs";
4
- import { showRoles } from "../catalog/index.mjs";
5
-
6
- //#region src/roles/index.ts
7
- async function createRole(client, options) {
8
- const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""} ROLE${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
9
- const body = options.options && Object.keys(options.options).length > 0 ? ` ${formatOptions(options.options)}` : "";
10
- const comment = options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : "";
11
- await executeSql(client, {
12
- statement: `${prefix} ${quoteIdentifier(options.name)}${body}${comment}`,
13
- warehouse: options.warehouse,
14
- role: options.sessionRole
15
- });
16
- }
17
- async function alterRole(client, options) {
18
- let tail;
19
- if (options.rename) tail = `RENAME TO ${quoteIdentifier(options.rename)}`;
20
- else if (options.set && Object.keys(options.set).length > 0) tail = `SET ${formatOptions(options.set)}`;
21
- else if (options.unset && options.unset.length > 0) tail = `UNSET ${options.unset.map((k) => k.toUpperCase()).join(", ")}`;
22
- else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
23
- else throw new Error("alterRole requires one of: rename / set / unset / comment");
24
- await executeSql(client, {
25
- statement: `ALTER ROLE${options.ifExists ? " IF EXISTS" : ""} ${quoteIdentifier(options.name)} ${tail}`,
26
- warehouse: options.warehouse,
27
- role: options.sessionRole
28
- });
29
- }
30
- async function dropRole(client, options) {
31
- await executeSql(client, {
32
- statement: `DROP ROLE${options.ifExists ? " IF EXISTS" : ""} ${quoteIdentifier(options.name)}`,
33
- warehouse: options.warehouse,
34
- role: options.sessionRole
35
- });
36
- }
37
- async function useRole(client, options) {
38
- await executeSql(client, {
39
- statement: `USE ROLE ${quoteIdentifier(options.name)}`,
40
- warehouse: options.warehouse,
41
- role: options.sessionRole
42
- });
43
- }
44
- async function grantRoleToUser(client, options) {
45
- await executeSql(client, {
46
- statement: `GRANT ROLE ${quoteIdentifier(options.role)} TO USER ${quoteIdentifier(options.user)}`,
47
- warehouse: options.warehouse,
48
- role: options.sessionRole
49
- });
50
- }
51
- async function revokeRoleFromUser(client, options) {
52
- await executeSql(client, {
53
- statement: `REVOKE ROLE ${quoteIdentifier(options.role)} FROM USER ${quoteIdentifier(options.user)}`,
54
- warehouse: options.warehouse,
55
- role: options.sessionRole
56
- });
57
- }
58
- async function grantRoleToRole(client, options) {
59
- await executeSql(client, {
60
- statement: `GRANT ROLE ${quoteIdentifier(options.role)} TO ROLE ${quoteIdentifier(options.parentRole)}`,
61
- warehouse: options.warehouse,
62
- role: options.sessionRole
63
- });
64
- }
65
- async function revokeRoleFromRole(client, options) {
66
- await executeSql(client, {
67
- statement: `REVOKE ROLE ${quoteIdentifier(options.role)} FROM ROLE ${quoteIdentifier(options.parentRole)}`,
68
- warehouse: options.warehouse,
69
- role: options.sessionRole
70
- });
71
- }
72
-
73
- //#endregion
74
- export { alterRole, createRole, dropRole, grantRoleToRole, grantRoleToUser, revokeRoleFromRole, revokeRoleFromUser, showRoles, useRole };
@@ -1,106 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { d as HydratedRow, v as SqlBinding } from "../statements-DJL0qVNA.mjs";
3
- //#region src/rows/index.d.ts
4
- /**
5
- * A value a caller can pass into an `insert` / `update` / `where` map. The
6
- * binding helper below maps each JS primitive onto a Snowflake type (`TEXT`,
7
- * `FIXED`, `REAL`, `BOOLEAN`, `TIMESTAMP_LTZ`) so the SQL API receives a
8
- * faithful typed value. Callers needing a specific Snowflake type can pass a
9
- * pre-built `SqlBinding` directly.
10
- */
11
- type RowValue = string | number | bigint | boolean | Date | null | undefined | SqlBinding;
12
- type RowRecord = Readonly<Record<string, RowValue>>;
13
- interface RowTableRef {
14
- readonly database?: string;
15
- readonly schema?: string;
16
- readonly table: string;
17
- }
18
- interface RowContext {
19
- readonly warehouse?: string;
20
- readonly role?: string;
21
- }
22
- /**
23
- * Map a JS value to its Snowflake typed binding. Callers who need full
24
- * control can pre-build a `{type, value}` object and pass it through.
25
- */
26
- declare function inferBinding(value: RowValue): SqlBinding;
27
- /**
28
- * Mutable binding builder. Internally indexes bindings starting at 1 and
29
- * returns the `?` placeholder for each append so callers can weave them into
30
- * their SQL composition.
31
- */
32
- declare class BindingBuilder {
33
- private readonly map;
34
- private counter;
35
- add(value: RowValue): string;
36
- toRecord(): Readonly<Record<string, SqlBinding>>;
37
- size(): number;
38
- }
39
- type OrderDirection = 'ASC' | 'DESC';
40
- interface FindRowsOptions extends RowTableRef, RowContext {
41
- readonly where?: RowRecord;
42
- readonly columns?: readonly string[];
43
- readonly orderBy?: readonly {
44
- readonly column: string;
45
- readonly direction?: OrderDirection;
46
- }[];
47
- readonly limit?: number;
48
- readonly offset?: number;
49
- }
50
- interface FindRowOptions extends RowTableRef, RowContext {
51
- readonly where: RowRecord;
52
- readonly columns?: readonly string[];
53
- }
54
- declare function findRows(client: SnowflakeClient, options: FindRowsOptions): Promise<readonly HydratedRow[]>;
55
- declare function findRow(client: SnowflakeClient, options: FindRowOptions): Promise<HydratedRow | undefined>;
56
- interface InsertRowOptions extends RowTableRef, RowContext {
57
- readonly row: RowRecord;
58
- }
59
- declare function insertRow(client: SnowflakeClient, options: InsertRowOptions): Promise<number>;
60
- interface BatchInsertOptions extends RowTableRef, RowContext {
61
- readonly rows: readonly RowRecord[];
62
- /**
63
- * When provided, use this explicit column list and look up each row's
64
- * value by column; when missing, use the union of keys from the first
65
- * row (all subsequent rows must share the same shape).
66
- */
67
- readonly columns?: readonly string[];
68
- }
69
- declare function batchInsert(client: SnowflakeClient, options: BatchInsertOptions): Promise<number>;
70
- interface UpdateRowOptions extends RowTableRef, RowContext {
71
- readonly where: RowRecord;
72
- readonly set: RowRecord;
73
- }
74
- declare function updateRow(client: SnowflakeClient, options: UpdateRowOptions): Promise<number>;
75
- interface DeleteRowOptions extends RowTableRef, RowContext {
76
- readonly where: RowRecord;
77
- }
78
- declare function deleteRow(client: SnowflakeClient, options: DeleteRowOptions): Promise<number>;
79
- interface UpsertRowOptions extends RowTableRef, RowContext {
80
- readonly row: RowRecord;
81
- /** Columns whose equality defines the MATCH condition. */
82
- readonly matchColumns: readonly string[];
83
- /**
84
- * Columns to write on UPDATE (defaults to every column in `row` except the
85
- * match columns, which are left untouched on match).
86
- */
87
- readonly updateColumns?: readonly string[];
88
- }
89
- interface UpsertRowResult {
90
- readonly inserted: number;
91
- readonly updated: number;
92
- }
93
- declare function upsertRow(client: SnowflakeClient, options: UpsertRowOptions): Promise<UpsertRowResult>;
94
- interface MergeRowsOptions extends RowTableRef, RowContext {
95
- /**
96
- * Raw MERGE statement source. Useful when callers want full control over
97
- * a merge and just want the client/context/binding infra. `statement`
98
- * should already reference the resolved FQN from
99
- * {@link buildFqn}/{@link quoteIdentifier}.
100
- */
101
- readonly statement: string;
102
- readonly bindings?: Readonly<Record<string, SqlBinding>>;
103
- }
104
- declare function mergeRows(client: SnowflakeClient, options: MergeRowsOptions): Promise<UpsertRowResult>;
105
- //#endregion
106
- export { BatchInsertOptions, BindingBuilder, DeleteRowOptions, FindRowOptions, FindRowsOptions, InsertRowOptions, MergeRowsOptions, OrderDirection, RowContext, RowRecord, RowTableRef, RowValue, UpdateRowOptions, UpsertRowOptions, UpsertRowResult, batchInsert, deleteRow, findRow, findRows, inferBinding, insertRow, mergeRows, updateRow, upsertRow };
@@ -1,223 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { i as quoteIdentifier, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
3
-
4
- //#region src/rows/index.ts
5
- function isSqlBinding(value) {
6
- return typeof value === "object" && value !== null && "type" in value && "value" in value && typeof value.type === "string";
7
- }
8
- /**
9
- * Map a JS value to its Snowflake typed binding. Callers who need full
10
- * control can pre-build a `{type, value}` object and pass it through.
11
- */
12
- function inferBinding(value) {
13
- if (isSqlBinding(value)) return value;
14
- if (value === null || value === void 0) return {
15
- type: "TEXT",
16
- value: null
17
- };
18
- if (typeof value === "string") return {
19
- type: "TEXT",
20
- value
21
- };
22
- if (typeof value === "boolean") return {
23
- type: "BOOLEAN",
24
- value: value ? "true" : "false"
25
- };
26
- if (typeof value === "bigint") return {
27
- type: "FIXED",
28
- value: value.toString()
29
- };
30
- if (typeof value === "number") {
31
- if (Number.isNaN(value) || !Number.isFinite(value)) throw new TypeError("Cannot bind NaN or Infinity as a Snowflake value");
32
- return Number.isInteger(value) ? {
33
- type: "FIXED",
34
- value: value.toString()
35
- } : {
36
- type: "REAL",
37
- value: value.toString()
38
- };
39
- }
40
- if (value instanceof Date) return {
41
- type: "TIMESTAMP_LTZ",
42
- value: value.toISOString()
43
- };
44
- const unreachable = value;
45
- throw new TypeError(`Unsupported binding type: ${typeof unreachable}`);
46
- }
47
- /**
48
- * Mutable binding builder. Internally indexes bindings starting at 1 and
49
- * returns the `?` placeholder for each append so callers can weave them into
50
- * their SQL composition.
51
- */
52
- var BindingBuilder = class {
53
- map = {};
54
- counter = 0;
55
- add(value) {
56
- this.counter += 1;
57
- this.map[String(this.counter)] = inferBinding(value);
58
- return "?";
59
- }
60
- toRecord() {
61
- return this.map;
62
- }
63
- size() {
64
- return this.counter;
65
- }
66
- };
67
- function composeWhere(where, bindings) {
68
- const clauses = [];
69
- for (const [column, value] of Object.entries(where)) {
70
- if (value === null || value === void 0) {
71
- clauses.push(`${quoteIdentifier(column)} IS NULL`);
72
- continue;
73
- }
74
- clauses.push(`${quoteIdentifier(column)} = ${bindings.add(value)}`);
75
- }
76
- return clauses.length > 0 ? ` WHERE ${clauses.join(" AND ")}` : "";
77
- }
78
- function composeSet(set, bindings) {
79
- const fragments = Object.entries(set).map(([column, value]) => `${quoteIdentifier(column)} = ${bindings.add(value)}`);
80
- if (fragments.length === 0) throw new Error("updateRow requires at least one column in `set`");
81
- return fragments.join(", ");
82
- }
83
- function executeRowStatement(client, sql, bindings, ctx) {
84
- return executeSql(client, {
85
- statement: sql,
86
- warehouse: ctx.warehouse,
87
- role: ctx.role,
88
- database: ctx.database,
89
- schema: ctx.schema,
90
- bindings: bindings.size() > 0 ? bindings.toRecord() : void 0
91
- });
92
- }
93
- /**
94
- * Read the first numeric value from the first row of a DML result.
95
- * Snowflake returns INSERT/UPDATE/DELETE stats as a single row with a
96
- * column like `"number of rows inserted"`.
97
- */
98
- function readAffectedRows(result) {
99
- if (result.rows.length === 0) return 0;
100
- const firstRow = result.rows[0];
101
- if (!firstRow) return 0;
102
- const values = Array.isArray(firstRow) ? firstRow : Object.values(firstRow);
103
- for (const value of values) {
104
- if (typeof value === "number") return value;
105
- if (typeof value === "bigint") return Number(value);
106
- if (typeof value === "string") {
107
- const parsed = Number(value);
108
- if (!Number.isNaN(parsed)) return parsed;
109
- }
110
- }
111
- return 0;
112
- }
113
- function composeColumnList(columns) {
114
- if (!columns || columns.length === 0) return "*";
115
- return columns.map((c) => quoteIdentifier(c)).join(", ");
116
- }
117
- function composeOrderBy(orderBy) {
118
- if (!orderBy || orderBy.length === 0) return "";
119
- return ` ORDER BY ${orderBy.map(({ column, direction }) => {
120
- const dir = direction === "DESC" ? " DESC" : " ASC";
121
- return `${quoteIdentifier(column)}${dir}`;
122
- }).join(", ")}`;
123
- }
124
- function composeLimitOffset(limit, offset) {
125
- let out = "";
126
- if (typeof limit === "number" && limit >= 0) out += ` LIMIT ${Math.floor(limit)}`;
127
- if (typeof offset === "number" && offset > 0) out += ` OFFSET ${Math.floor(offset)}`;
128
- return out;
129
- }
130
- async function findRows(client, options) {
131
- const bindings = new BindingBuilder();
132
- return (await executeRowStatement(client, `SELECT ${composeColumnList(options.columns)} FROM ${buildFqn(options.database, options.schema, options.table)}` + composeWhere(options.where ?? {}, bindings) + composeOrderBy(options.orderBy) + composeLimitOffset(options.limit, options.offset), bindings, options)).rows;
133
- }
134
- async function findRow(client, options) {
135
- return (await findRows(client, {
136
- ...options,
137
- limit: 1
138
- }))[0];
139
- }
140
- async function insertRow(client, options) {
141
- const columns = Object.keys(options.row);
142
- if (columns.length === 0) throw new Error("insertRow requires at least one column in `row`");
143
- const bindings = new BindingBuilder();
144
- const placeholders = columns.map((column) => bindings.add(options.row[column]));
145
- return readAffectedRows(await executeRowStatement(client, `INSERT INTO ${buildFqn(options.database, options.schema, options.table)} (${columns.map((c) => quoteIdentifier(c)).join(", ")}) VALUES (${placeholders.join(", ")})`, bindings, options));
146
- }
147
- async function batchInsert(client, options) {
148
- if (options.rows.length === 0) return 0;
149
- const first = options.rows[0];
150
- if (!first) return 0;
151
- const columns = options.columns ?? Object.keys(first);
152
- if (columns.length === 0) throw new Error("batchInsert requires at least one column");
153
- const bindings = new BindingBuilder();
154
- const valueTuples = options.rows.map((row) => {
155
- return `(${columns.map((column) => bindings.add(row[column])).join(", ")})`;
156
- });
157
- return readAffectedRows(await executeRowStatement(client, `INSERT INTO ${buildFqn(options.database, options.schema, options.table)} (${columns.map((c) => quoteIdentifier(c)).join(", ")}) VALUES ${valueTuples.join(", ")}`, bindings, options));
158
- }
159
- async function updateRow(client, options) {
160
- const bindings = new BindingBuilder();
161
- const setClause = composeSet(options.set, bindings);
162
- const whereClause = composeWhere(options.where, bindings);
163
- return readAffectedRows(await executeRowStatement(client, `UPDATE ${buildFqn(options.database, options.schema, options.table)} SET ${setClause}${whereClause}`, bindings, options));
164
- }
165
- async function deleteRow(client, options) {
166
- if (Object.keys(options.where).length === 0) throw new Error("deleteRow refuses an empty where filter; call executeSql to truncate intentionally");
167
- const bindings = new BindingBuilder();
168
- const whereClause = composeWhere(options.where, bindings);
169
- return readAffectedRows(await executeRowStatement(client, `DELETE FROM ${buildFqn(options.database, options.schema, options.table)}${whereClause}`, bindings, options));
170
- }
171
- function readMergeStats(result) {
172
- if (result.rows.length === 0) return {
173
- inserted: 0,
174
- updated: 0
175
- };
176
- const firstRow = result.rows[0];
177
- if (!firstRow) return {
178
- inserted: 0,
179
- updated: 0
180
- };
181
- const entries = Array.isArray(firstRow) ? result.columns.map((col, idx) => [col.name, firstRow[idx]]) : Object.entries(firstRow);
182
- let inserted = 0;
183
- let updated = 0;
184
- for (const [name, value] of entries) {
185
- const numeric = typeof value === "number" ? value : Number(value);
186
- if (!Number.isFinite(numeric)) continue;
187
- const key = name.toLowerCase();
188
- if (key.includes("insert")) inserted = numeric;
189
- else if (key.includes("update")) updated = numeric;
190
- }
191
- return {
192
- inserted,
193
- updated
194
- };
195
- }
196
- async function upsertRow(client, options) {
197
- const rowColumns = Object.keys(options.row);
198
- if (rowColumns.length === 0) throw new Error("upsertRow requires at least one column in `row`");
199
- if (options.matchColumns.length === 0) throw new Error("upsertRow requires at least one match column");
200
- for (const column of options.matchColumns) if (!rowColumns.includes(column)) throw new Error(`upsertRow match column "${column}" is missing from row`);
201
- const bindings = new BindingBuilder();
202
- const srcTuples = rowColumns.map((column) => bindings.add(options.row[column]));
203
- const fqn = buildFqn(options.database, options.schema, options.table);
204
- rowColumns.map((c) => quoteIdentifier(c)).join(", ");
205
- const matchPredicate = options.matchColumns.map((column) => `t.${quoteIdentifier(column)} = s.${quoteIdentifier(column)}`).join(" AND ");
206
- const updateSet = (options.updateColumns ?? rowColumns.filter((c) => !options.matchColumns.includes(c))).map((column) => `${quoteIdentifier(column)} = s.${quoteIdentifier(column)}`).join(", ");
207
- const insertCols = rowColumns.map((c) => quoteIdentifier(c)).join(", ");
208
- const insertVals = rowColumns.map((c) => `s.${quoteIdentifier(c)}`).join(", ");
209
- return readMergeStats(await executeRowStatement(client, `MERGE INTO ${fqn} t USING (SELECT ${srcTuples.map((placeholder, idx) => `${placeholder} AS ${quoteIdentifier(rowColumns[idx] ?? "")}`).join(", ")}) s ON ${matchPredicate}` + (updateSet ? ` WHEN MATCHED THEN UPDATE SET ${updateSet}` : "") + ` WHEN NOT MATCHED THEN INSERT (${insertCols}) VALUES (${insertVals})`, bindings, options));
210
- }
211
- async function mergeRows(client, options) {
212
- return readMergeStats(await executeSql(client, {
213
- statement: options.statement,
214
- warehouse: options.warehouse,
215
- role: options.role,
216
- database: options.database,
217
- schema: options.schema,
218
- bindings: options.bindings
219
- }));
220
- }
221
-
222
- //#endregion
223
- export { BindingBuilder, batchInsert, deleteRow, findRow, findRows, inferBinding, insertRow, mergeRows, updateRow, upsertRow };
@@ -1,2 +0,0 @@
1
- import { C as resultSetMetaDataSchema, D as sqlBindingValueSchema, E as snowflakeObjectRowSchema, O as sqlBindingsSchema, S as partitionInfoSchema, T as snowflakeIdentifier, _ as SnowflakeObjectRow, a as SubmitStatementInput, b as StatementContext, c as statementStatus, d as HydratedRow, f as PartitionResponse, g as ResultSetMetaData, h as PartitionInfo, i as StatementTerminalStatus, k as statementContextSchema, l as statementStatusCodeSchema, m as ColumnMeta, n as StatementResponse, o as cancelStatementResponseSchema, p as partitionResponseSchema, r as StatementStatus, s as statementResponseSchema, t as CancelStatementResponse, u as submitStatementInputSchema, v as SqlBinding, w as snowflakeFqn, x as columnMetaSchema, y as SqlBindings } from "../statements-DJL0qVNA.mjs";
2
- export { CancelStatementResponse, ColumnMeta, HydratedRow, PartitionInfo, PartitionResponse, ResultSetMetaData, SnowflakeObjectRow, SqlBinding, SqlBindings, StatementContext, StatementResponse, StatementStatus, StatementTerminalStatus, SubmitStatementInput, cancelStatementResponseSchema, columnMetaSchema, partitionInfoSchema, partitionResponseSchema, resultSetMetaDataSchema, snowflakeFqn, snowflakeIdentifier, snowflakeObjectRowSchema, sqlBindingValueSchema, sqlBindingsSchema, statementContextSchema, statementResponseSchema, statementStatus, statementStatusCodeSchema, submitStatementInputSchema };
@@ -1,4 +0,0 @@
1
- import { a as snowflakeIdentifier, c as sqlBindingsSchema, i as snowflakeFqn, l as statementContextSchema, n as partitionInfoSchema, o as snowflakeObjectRowSchema, r as resultSetMetaDataSchema, s as sqlBindingValueSchema, t as columnMetaSchema } from "../common-DfpCwJx5.mjs";
2
- import { a as submitStatementInputSchema, i as statementStatusCodeSchema, n as statementResponseSchema, o as partitionResponseSchema, r as statementStatus, t as cancelStatementResponseSchema } from "../statements-BumhMhN4.mjs";
3
-
4
- export { cancelStatementResponseSchema, columnMetaSchema, partitionInfoSchema, partitionResponseSchema, resultSetMetaDataSchema, snowflakeFqn, snowflakeIdentifier, snowflakeObjectRowSchema, sqlBindingValueSchema, sqlBindingsSchema, statementContextSchema, statementResponseSchema, statementStatus, statementStatusCodeSchema, submitStatementInputSchema };
@@ -1,2 +0,0 @@
1
- import { CatalogResult, FindSchemasOptions, ShowSchemasOptions, findSchemas, showSchemas } from "../catalog/index.mjs";
2
- export { type CatalogResult, type FindSchemasOptions, type ShowSchemasOptions, findSchemas, showSchemas };
@@ -1,3 +0,0 @@
1
- import { findSchemas, showSchemas } from "../catalog/index.mjs";
2
-
3
- export { findSchemas, showSchemas };
@@ -1,56 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { d as HydratedRow } from "../statements-DJL0qVNA.mjs";
3
- import { CatalogResult, ShowOptions, showShares } from "../catalog/index.mjs";
4
-
5
- //#region src/shares/index.d.ts
6
- interface ShareContext {
7
- readonly warehouse?: string;
8
- readonly role?: string;
9
- }
10
- interface CreateShareOptions extends ShareContext {
11
- readonly name: string;
12
- readonly orReplace?: boolean;
13
- readonly ifNotExists?: boolean;
14
- readonly comment?: string;
15
- }
16
- declare function createShare(client: SnowflakeClient, options: CreateShareOptions): Promise<void>;
17
- interface AlterShareOptions extends ShareContext {
18
- readonly name: string;
19
- readonly ifExists?: boolean;
20
- /** Replace the full account list via `SET ACCOUNTS = (...)`. */
21
- readonly setAccounts?: readonly string[];
22
- /** `ADD ACCOUNTS = (...)`. */
23
- readonly addAccounts?: readonly string[];
24
- /** `REMOVE ACCOUNTS = (...)`. */
25
- readonly removeAccounts?: readonly string[];
26
- /** `SET COMMENT = '...'`. */
27
- readonly comment?: string;
28
- /** `UNSET COMMENT`. */
29
- readonly unsetComment?: boolean;
30
- }
31
- declare function alterShare(client: SnowflakeClient, options: AlterShareOptions): Promise<void>;
32
- interface DropShareOptions extends ShareContext {
33
- readonly name: string;
34
- readonly ifExists?: boolean;
35
- }
36
- declare function dropShare(client: SnowflakeClient, options: DropShareOptions): Promise<void>;
37
- interface DescribeShareOptions extends ShareContext {
38
- readonly name: string;
39
- }
40
- declare function describeShare(client: SnowflakeClient, options: DescribeShareOptions): Promise<readonly HydratedRow[]>;
41
- interface AddAccountsToShareOptions extends ShareContext {
42
- readonly name: string;
43
- readonly accounts: readonly string[];
44
- readonly ifExists?: boolean;
45
- /** Optional `SHARE_RESTRICTIONS = TRUE|FALSE` appended to ADD ACCOUNTS. */
46
- readonly shareRestrictions?: boolean;
47
- }
48
- declare function addAccountsToShare(client: SnowflakeClient, options: AddAccountsToShareOptions): Promise<void>;
49
- interface RemoveAccountsFromShareOptions extends ShareContext {
50
- readonly name: string;
51
- readonly accounts: readonly string[];
52
- readonly ifExists?: boolean;
53
- }
54
- declare function removeAccountsFromShare(client: SnowflakeClient, options: RemoveAccountsFromShareOptions): Promise<void>;
55
- //#endregion
56
- export { AddAccountsToShareOptions, AlterShareOptions, type CatalogResult, CreateShareOptions, DescribeShareOptions, DropShareOptions, RemoveAccountsFromShareOptions, ShareContext, type ShowOptions, addAccountsToShare, alterShare, createShare, describeShare, dropShare, removeAccountsFromShare, showShares };
@@ -1,77 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { a as quoteLiteral, i as quoteIdentifier } from "../sql-safety-BZpAPsq6.mjs";
3
- import { showShares } from "../catalog/index.mjs";
4
-
5
- //#region src/shares/index.ts
6
- async function createShare(client, options) {
7
- const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""} SHARE${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
8
- const comment = options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : "";
9
- await executeSql(client, {
10
- statement: `${prefix} ${quoteIdentifier(options.name)}${comment}`,
11
- warehouse: options.warehouse,
12
- role: options.role
13
- });
14
- }
15
- /**
16
- * Snowflake account identifiers for shares take the form
17
- * `<orgName>.<accountName>` (unquoted). We validate the shape lightly
18
- * and pass it through without quoting because Snowflake treats quoted
19
- * identifiers here as case-sensitive names which would not match the
20
- * real account.
21
- */
22
- const ACCOUNT_ID_RE = /^[A-Za-z0-9_]+\.[A-Za-z0-9_]+$/u;
23
- function renderAccountList(accounts) {
24
- if (accounts.length === 0) throw new Error("accounts must be a non-empty list");
25
- for (const a of accounts) if (!ACCOUNT_ID_RE.test(a)) throw new Error(`Invalid account identifier "${a}" — expected "<orgName>.<accountName>" (letters, digits, underscore)`);
26
- return accounts.join(", ");
27
- }
28
- async function alterShare(client, options) {
29
- let tail;
30
- if (options.addAccounts) tail = `ADD ACCOUNTS = (${renderAccountList(options.addAccounts)})`;
31
- else if (options.removeAccounts) tail = `REMOVE ACCOUNTS = (${renderAccountList(options.removeAccounts)})`;
32
- else if (options.setAccounts) tail = `SET ACCOUNTS = (${renderAccountList(options.setAccounts)})`;
33
- else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
34
- else if (options.unsetComment) tail = "UNSET COMMENT";
35
- else throw new Error("alterShare requires one of: setAccounts / addAccounts / removeAccounts / comment / unsetComment");
36
- await executeSql(client, {
37
- statement: `ALTER SHARE${options.ifExists ? " IF EXISTS" : ""} ${quoteIdentifier(options.name)} ${tail}`,
38
- warehouse: options.warehouse,
39
- role: options.role
40
- });
41
- }
42
- async function dropShare(client, options) {
43
- await executeSql(client, {
44
- statement: `DROP SHARE${options.ifExists ? " IF EXISTS" : ""} ${quoteIdentifier(options.name)}`,
45
- warehouse: options.warehouse,
46
- role: options.role
47
- });
48
- }
49
- async function describeShare(client, options) {
50
- return (await executeSql(client, {
51
- statement: `DESCRIBE SHARE ${quoteIdentifier(options.name)}`,
52
- warehouse: options.warehouse,
53
- role: options.role
54
- })).rows;
55
- }
56
- async function addAccountsToShare(client, options) {
57
- const ifExists = options.ifExists ? " IF EXISTS" : "";
58
- const accounts = renderAccountList(options.accounts);
59
- const restrictions = options.shareRestrictions !== void 0 ? ` SHARE_RESTRICTIONS = ${options.shareRestrictions ? "TRUE" : "FALSE"}` : "";
60
- await executeSql(client, {
61
- statement: `ALTER SHARE${ifExists} ${quoteIdentifier(options.name)} ADD ACCOUNTS = (${accounts})${restrictions}`,
62
- warehouse: options.warehouse,
63
- role: options.role
64
- });
65
- }
66
- async function removeAccountsFromShare(client, options) {
67
- const ifExists = options.ifExists ? " IF EXISTS" : "";
68
- const accounts = renderAccountList(options.accounts);
69
- await executeSql(client, {
70
- statement: `ALTER SHARE${ifExists} ${quoteIdentifier(options.name)} REMOVE ACCOUNTS = (${accounts})`,
71
- warehouse: options.warehouse,
72
- role: options.role
73
- });
74
- }
75
-
76
- //#endregion
77
- export { addAccountsToShare, alterShare, createShare, describeShare, dropShare, removeAccountsFromShare, showShares };
@@ -1,50 +0,0 @@
1
- import { CredentialSet } from "@keystrokehq/core";
2
- import { z } from "zod";
3
- import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
4
- import { InferCredentialSetAuth } from "@keystrokehq/core/credential-set";
5
-
6
- //#region src/credential-sets/snowflake-azure-eventgrid-webhook.credential-set.d.ts
7
- declare const snowflakeAzureEventGridWebhookCredentialSet: CredentialSet<"snowflake-azure-eventgrid-webhook", z.ZodObject<{
8
- sharedSecret: z.ZodOptional<z.ZodString>;
9
- sharedSecretHeader: z.ZodOptional<z.ZodDefault<z.ZodString>>;
10
- expectedTopicArn: z.ZodOptional<z.ZodString>;
11
- }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
12
- sharedSecret: z.ZodOptional<z.ZodString>;
13
- sharedSecretHeader: z.ZodOptional<z.ZodDefault<z.ZodString>>;
14
- expectedTopicArn: z.ZodOptional<z.ZodString>;
15
- }, z.core.$strip>>[] | undefined>;
16
- type SnowflakeAzureEventGridWebhookCredentials = InferCredentialSetAuth<typeof snowflakeAzureEventGridWebhookCredentialSet>;
17
- //#endregion
18
- //#region src/credential-sets/snowflake-gcs-pubsub-webhook.credential-set.d.ts
19
- declare const snowflakeGcsPubSubWebhookCredentialSet: CredentialSet<"snowflake-gcs-pubsub-webhook", z.ZodObject<{
20
- expectedAudience: z.ZodString;
21
- expectedServiceAccount: z.ZodString;
22
- jwksUri: z.ZodOptional<z.ZodDefault<z.ZodString>>;
23
- issuer: z.ZodOptional<z.ZodDefault<z.ZodString>>;
24
- }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
25
- expectedAudience: z.ZodString;
26
- expectedServiceAccount: z.ZodString;
27
- jwksUri: z.ZodOptional<z.ZodDefault<z.ZodString>>;
28
- issuer: z.ZodOptional<z.ZodDefault<z.ZodString>>;
29
- }, z.core.$strip>>[] | undefined>;
30
- type SnowflakeGcsPubSubWebhookCredentials = InferCredentialSetAuth<typeof snowflakeGcsPubSubWebhookCredentialSet>;
31
- //#endregion
32
- //#region src/credential-sets/snowflake-s3-sns-webhook.credential-set.d.ts
33
- declare const snowflakeS3SnsWebhookCredentialSet: CredentialSet<"snowflake-s3-sns-webhook", z.ZodObject<{
34
- expectedTopicArn: z.ZodOptional<z.ZodString>;
35
- allowedSigningCertHostPattern: z.ZodOptional<z.ZodDefault<z.ZodString>>;
36
- autoConfirmSubscriptions: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
37
- true: "true";
38
- false: "false";
39
- }>>>;
40
- }, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
41
- expectedTopicArn: z.ZodOptional<z.ZodString>;
42
- allowedSigningCertHostPattern: z.ZodOptional<z.ZodDefault<z.ZodString>>;
43
- autoConfirmSubscriptions: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
44
- true: "true";
45
- false: "false";
46
- }>>>;
47
- }, z.core.$strip>>[] | undefined>;
48
- type SnowflakeS3SnsWebhookCredentials = InferCredentialSetAuth<typeof snowflakeS3SnsWebhookCredentialSet>;
49
- //#endregion
50
- export { SnowflakeAzureEventGridWebhookCredentials as a, snowflakeGcsPubSubWebhookCredentialSet as i, snowflakeS3SnsWebhookCredentialSet as n, snowflakeAzureEventGridWebhookCredentialSet as o, SnowflakeGcsPubSubWebhookCredentials as r, SnowflakeS3SnsWebhookCredentials as t };