@keystrokehq/snowflake 0.0.16 → 0.0.18

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 (82) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -233
  3. package/package.json +39 -171
  4. package/dist/accounts/index.d.mts +0 -40
  5. package/dist/accounts/index.mjs +0 -51
  6. package/dist/bulk/index.d.mts +0 -71
  7. package/dist/bulk/index.mjs +0 -65
  8. package/dist/catalog/index.d.mts +0 -144
  9. package/dist/catalog/index.mjs +0 -158
  10. package/dist/client/index.d.mts +0 -44
  11. package/dist/client/index.mjs +0 -273
  12. package/dist/common-DfpCwJx5.mjs +0 -92
  13. package/dist/credential-sets/index.d.mts +0 -3
  14. package/dist/credential-sets/index.mjs +0 -4
  15. package/dist/databases/index.d.mts +0 -2
  16. package/dist/databases/index.mjs +0 -3
  17. package/dist/errors-60AsF7Su.mjs +0 -95
  18. package/dist/events/index.d.mts +0 -382
  19. package/dist/events/index.mjs +0 -291
  20. package/dist/file-formats/index.d.mts +0 -39
  21. package/dist/file-formats/index.mjs +0 -48
  22. package/dist/functions/index.d.mts +0 -53
  23. package/dist/functions/index.mjs +0 -56
  24. package/dist/grants/index.d.mts +0 -93
  25. package/dist/grants/index.mjs +0 -102
  26. package/dist/index.d.mts +0 -4
  27. package/dist/index.mjs +0 -6
  28. package/dist/operations/index.d.mts +0 -1
  29. package/dist/operations/index.mjs +0 -1
  30. package/dist/org-admin/index.d.mts +0 -80
  31. package/dist/org-admin/index.mjs +0 -79
  32. package/dist/pipes/index.d.mts +0 -119
  33. package/dist/pipes/index.mjs +0 -106
  34. package/dist/procedures/index.d.mts +0 -61
  35. package/dist/procedures/index.mjs +0 -79
  36. package/dist/results/index.d.mts +0 -16
  37. package/dist/results/index.mjs +0 -64
  38. package/dist/retry-B4-9MZIp.mjs +0 -164
  39. package/dist/retry-w7cTp1QL.d.mts +0 -10
  40. package/dist/roles/index.d.mts +0 -60
  41. package/dist/roles/index.mjs +0 -74
  42. package/dist/rows/index.d.mts +0 -106
  43. package/dist/rows/index.mjs +0 -223
  44. package/dist/schemas/index.d.mts +0 -2
  45. package/dist/schemas/index.mjs +0 -4
  46. package/dist/schemas-catalog/index.d.mts +0 -2
  47. package/dist/schemas-catalog/index.mjs +0 -3
  48. package/dist/shares/index.d.mts +0 -56
  49. package/dist/shares/index.mjs +0 -77
  50. package/dist/snowflake-s3-sns-webhook.credential-set-D6bLAWy5.d.mts +0 -50
  51. package/dist/snowflake-s3-sns-webhook.credential-set-DzR7oWNK.mjs +0 -44
  52. package/dist/snowflake.credential-set-BxT7Gf3A.d.mts +0 -114
  53. package/dist/snowflake.credential-set-DE3gXf-a.mjs +0 -106
  54. package/dist/sql/index.d.mts +0 -84
  55. package/dist/sql/index.mjs +0 -209
  56. package/dist/sql-options-2k5xQ-oS.d.mts +0 -32
  57. package/dist/sql-options-D6GEa21F.mjs +0 -79
  58. package/dist/sql-safety-BZpAPsq6.mjs +0 -56
  59. package/dist/stages/index.d.mts +0 -64
  60. package/dist/stages/index.mjs +0 -81
  61. package/dist/statements-BumhMhN4.mjs +0 -81
  62. package/dist/statements-DJL0qVNA.d.mts +0 -238
  63. package/dist/status-page/index.d.mts +0 -510
  64. package/dist/status-page/index.mjs +0 -261
  65. package/dist/streaming/index.d.mts +0 -70
  66. package/dist/streaming/index.mjs +0 -56
  67. package/dist/streams/index.d.mts +0 -71
  68. package/dist/streams/index.mjs +0 -78
  69. package/dist/tables/index.d.mts +0 -2
  70. package/dist/tables/index.mjs +0 -3
  71. package/dist/tasks/index.d.mts +0 -79
  72. package/dist/tasks/index.mjs +0 -104
  73. package/dist/triggers/index.d.mts +0 -381
  74. package/dist/triggers/index.mjs +0 -1100
  75. package/dist/users/index.d.mts +0 -61
  76. package/dist/users/index.mjs +0 -67
  77. package/dist/verification/index.d.mts +0 -201
  78. package/dist/verification/index.mjs +0 -512
  79. package/dist/views/index.d.mts +0 -2
  80. package/dist/views/index.mjs +0 -3
  81. package/dist/warehouses/index.d.mts +0 -68
  82. package/dist/warehouses/index.mjs +0 -101
@@ -1,291 +0,0 @@
1
- import { o as snowflakeObjectRowSchema, t as columnMetaSchema } from "../common-DfpCwJx5.mjs";
2
- import { z } from "zod";
3
-
4
- //#region src/events/index.ts
5
- /**
6
- * Trigger event contracts — Zod schemas for the payload shapes that
7
- * `src/triggers.ts` emits. Every polling trigger returns exactly one of
8
- * these events per poll; webhook triggers return the mapped payload
9
- * shapes defined alongside them.
10
- *
11
- * Design notes:
12
- * - Events are flat, serialisable objects — no class instances, no
13
- * dates (ISO-8601 strings instead), no BigInts.
14
- * - Row lists are returned verbatim as `HydratedRow` / column metadata
15
- * pairs so downstream workflows can pick columns dynamically without
16
- * the schema needing to know the shape ahead of time.
17
- * - `.catchall(unknown)` on object-history events — Snowflake adds
18
- * columns over time (e.g., `ACTIVITY_NAME` → `FIRST_ERROR_CODE`) and
19
- * we never want a new column to hard-fail an in-flight workflow.
20
- */
21
- /**
22
- * Row batch shape used by the SQL-emitting polling triggers.
23
- *
24
- * `rows` is the hydrated row list (column-name keyed record) straight
25
- * from `executeSql`. `columns` preserves the `resultSetMetaData.rowType`
26
- * entries so downstream workflows can introspect nullability / type
27
- * without a round-trip. `fetchedAt` is the ISO-8601 timestamp we
28
- * captured the result at.
29
- */
30
- const snowflakeRowBatchSchema = z.object({
31
- rows: z.array(snowflakeObjectRowSchema),
32
- columns: z.array(columnMetaSchema),
33
- rowCount: z.number().int().nonnegative(),
34
- fetchedAt: z.string()
35
- }).catchall(z.unknown());
36
- const streamHasDataEventSchema = z.object({
37
- streamName: z.string(),
38
- hasData: z.boolean(),
39
- checkedAt: z.string()
40
- }).catchall(z.unknown());
41
- const streamAppendOnlyEventSchema = snowflakeRowBatchSchema.extend({ streamName: z.string() });
42
- const scheduledSqlEventSchema = snowflakeRowBatchSchema.extend({ statementDigest: z.string() });
43
- const scheduledDeltaEventSchema = snowflakeRowBatchSchema.extend({
44
- table: z.string(),
45
- cursorColumn: z.string(),
46
- highWaterValue: z.string().nullable()
47
- });
48
- const taskRunEventSchema = z.object({
49
- name: z.string(),
50
- databaseName: z.string().optional(),
51
- schemaName: z.string().optional(),
52
- state: z.string(),
53
- queryId: z.string().optional(),
54
- scheduledTime: z.string().optional(),
55
- completedTime: z.string().optional(),
56
- errorCode: z.string().nullable().optional(),
57
- errorMessage: z.string().nullable().optional(),
58
- attemptNumber: z.number().int().optional(),
59
- runId: z.string().optional(),
60
- row: snowflakeObjectRowSchema
61
- }).catchall(z.unknown());
62
- const statementCompletedEventSchema = z.object({
63
- queryId: z.string(),
64
- executionStatus: z.string(),
65
- queryText: z.string().optional(),
66
- errorCode: z.string().nullable().optional(),
67
- errorMessage: z.string().nullable().optional(),
68
- startTime: z.string().optional(),
69
- endTime: z.string().optional(),
70
- warehouseName: z.string().optional(),
71
- databaseName: z.string().optional(),
72
- schemaName: z.string().optional(),
73
- userName: z.string().optional(),
74
- roleName: z.string().optional(),
75
- totalElapsedTimeMs: z.number().nullable().optional(),
76
- row: snowflakeObjectRowSchema
77
- }).catchall(z.unknown());
78
- const pipeLoadEventSchema = z.object({
79
- pipeName: z.string(),
80
- filePath: z.string(),
81
- status: z.string(),
82
- loadTime: z.string().optional(),
83
- rowCount: z.number().int().nullable().optional(),
84
- rowParsed: z.number().int().nullable().optional(),
85
- errorLimit: z.number().int().nullable().optional(),
86
- errorsSeen: z.number().int().nullable().optional(),
87
- firstErrorMessage: z.string().nullable().optional(),
88
- firstErrorLineNumber: z.number().int().nullable().optional(),
89
- firstErrorColumnName: z.string().nullable().optional(),
90
- fileSize: z.number().int().nullable().optional(),
91
- stageLocation: z.string().nullable().optional(),
92
- row: snowflakeObjectRowSchema
93
- }).catchall(z.unknown());
94
- /**
95
- * Kinds of Snowflake objects the SHOW-diff polling triggers can surface.
96
- * Kept open-ended (`z.string()`) via the enum's `catch` so new kinds can
97
- * be added without bumping the schema — callers rarely want to pattern
98
- * match on the kind, they just want the row.
99
- */
100
- const snowflakeObjectKindSchema = z.enum([
101
- "USER",
102
- "ROLE",
103
- "DATABASE",
104
- "SCHEMA",
105
- "TABLE",
106
- "VIEW",
107
- "STAGE",
108
- "PIPE",
109
- "TASK",
110
- "STREAM",
111
- "SHARE",
112
- "WAREHOUSE",
113
- "FUNCTION",
114
- "PROCEDURE",
115
- "FILE_FORMAT"
116
- ]);
117
- const snowflakeObjectLifecycleEventSchema = z.object({
118
- kind: z.string(),
119
- name: z.string(),
120
- change: z.enum(["created", "dropped"]),
121
- identity: z.string(),
122
- owner: z.string().optional(),
123
- createdOn: z.string().optional(),
124
- detectedAt: z.string(),
125
- row: snowflakeObjectRowSchema
126
- }).catchall(z.unknown());
127
- const shareChangedEventSchema = z.object({
128
- name: z.string(),
129
- kind: z.string().optional(),
130
- change: z.enum([
131
- "created",
132
- "dropped",
133
- "modified"
134
- ]),
135
- identity: z.string(),
136
- detectedAt: z.string(),
137
- previousRow: snowflakeObjectRowSchema.optional(),
138
- currentRow: snowflakeObjectRowSchema.optional()
139
- }).catchall(z.unknown());
140
- const grantChangedEventSchema = z.object({
141
- privilege: z.string(),
142
- grantedOn: z.string(),
143
- objectName: z.string(),
144
- granteeName: z.string(),
145
- granteeType: z.string().optional(),
146
- change: z.enum(["granted", "revoked"]),
147
- identity: z.string(),
148
- detectedAt: z.string(),
149
- row: snowflakeObjectRowSchema
150
- }).catchall(z.unknown());
151
- const warehouseCreditsEventSchema = z.object({
152
- warehouseName: z.string(),
153
- startTime: z.string().optional(),
154
- endTime: z.string().optional(),
155
- creditsUsed: z.number().nullable().optional(),
156
- creditsUsedCompute: z.number().nullable().optional(),
157
- creditsUsedCloudServices: z.number().nullable().optional(),
158
- row: snowflakeObjectRowSchema
159
- }).catchall(z.unknown());
160
- const warehouseQueueEventSchema = z.object({
161
- warehouseName: z.string(),
162
- startTime: z.string().optional(),
163
- endTime: z.string().optional(),
164
- avgRunning: z.number().nullable().optional(),
165
- avgQueuedLoad: z.number().nullable().optional(),
166
- avgQueuedProvisioning: z.number().nullable().optional(),
167
- avgBlocked: z.number().nullable().optional(),
168
- row: snowflakeObjectRowSchema
169
- }).catchall(z.unknown());
170
- const statusPageIncidentEventSchema = z.object({
171
- id: z.string(),
172
- name: z.string(),
173
- status: z.string(),
174
- impact: z.string().optional(),
175
- createdAt: z.string().optional(),
176
- updatedAt: z.string().optional(),
177
- resolvedAt: z.string().nullable().optional(),
178
- shortlink: z.string().optional(),
179
- detectedAt: z.string(),
180
- raw: z.record(z.string(), z.unknown())
181
- }).catchall(z.unknown());
182
- const statusPageComponentChangeEventSchema = z.object({
183
- id: z.string(),
184
- name: z.string(),
185
- previousStatus: z.string().nullable(),
186
- currentStatus: z.string(),
187
- description: z.string().optional(),
188
- changedAt: z.string(),
189
- detectedAt: z.string(),
190
- raw: z.record(z.string(), z.unknown())
191
- }).catchall(z.unknown());
192
- const snowflakeDiffSnapshotEntrySchema = z.object({
193
- identity: z.string(),
194
- signature: z.string().optional()
195
- }).catchall(z.unknown());
196
- /**
197
- * Canonical object-storage event shape emitted by the three auto-ingest
198
- * webhook triggers. Each cloud's native payload is normalised to this
199
- * shape; the raw envelope is preserved under `raw` for callers that
200
- * need provider-specific fields (etag, metageneration, blob tier, ...).
201
- */
202
- const snowpipeObjectEventSchema = z.object({
203
- provider: z.enum([
204
- "aws-s3",
205
- "gcp-gcs",
206
- "azure-blob"
207
- ]),
208
- eventType: z.string(),
209
- eventTime: z.string(),
210
- bucket: z.string(),
211
- key: z.string(),
212
- size: z.number().int().nonnegative().nullable().optional(),
213
- etag: z.string().nullable().optional(),
214
- region: z.string().nullable().optional(),
215
- sourceIp: z.string().nullable().optional(),
216
- messageId: z.string().nullable().optional(),
217
- receivedAt: z.string(),
218
- raw: z.record(z.string(), z.unknown())
219
- }).catchall(z.unknown());
220
- /**
221
- * Batch envelope used by auto-ingest webhook triggers — a single SNS
222
- * notification, Pub/Sub push, or Event Grid batch can carry multiple
223
- * object events, so the trigger emits `{ events, receivedAt, messageId }`.
224
- */
225
- const snowpipeObjectBatchSchema = z.object({
226
- events: z.array(snowpipeObjectEventSchema),
227
- provider: z.enum([
228
- "aws-s3",
229
- "gcp-gcs",
230
- "azure-blob"
231
- ]),
232
- receivedAt: z.string(),
233
- messageId: z.string().nullable().optional(),
234
- topic: z.string().nullable().optional(),
235
- raw: z.record(z.string(), z.unknown())
236
- }).catchall(z.unknown());
237
- /**
238
- * Raw SNS "Notification" envelope. The outer webhook payload we accept
239
- * from `autoIngestS3Sns` matches this shape — fields per the AWS SNS
240
- * HTTP(S) delivery spec.
241
- */
242
- const snsNotificationSchema = z.object({
243
- Type: z.enum([
244
- "Notification",
245
- "SubscriptionConfirmation",
246
- "UnsubscribeConfirmation"
247
- ]),
248
- MessageId: z.string(),
249
- TopicArn: z.string(),
250
- Message: z.string(),
251
- Timestamp: z.string(),
252
- SignatureVersion: z.string(),
253
- Signature: z.string(),
254
- SigningCertURL: z.string(),
255
- Subject: z.string().optional(),
256
- Token: z.string().optional(),
257
- SubscribeURL: z.string().optional(),
258
- UnsubscribeURL: z.string().optional()
259
- }).catchall(z.unknown());
260
- /**
261
- * GCP Pub/Sub push envelope. The push subscription wraps the Pub/Sub
262
- * message in `{message, subscription}`; `message.data` is base64 and
263
- * decodes to the GCS object-change notification.
264
- */
265
- const gcsPubSubPushSchema = z.object({
266
- message: z.object({
267
- messageId: z.string().optional(),
268
- publishTime: z.string().optional(),
269
- data: z.string().optional(),
270
- attributes: z.record(z.string(), z.string()).optional()
271
- }).catchall(z.unknown()),
272
- subscription: z.string().optional()
273
- }).catchall(z.unknown());
274
- /**
275
- * Azure Event Grid event (Event Grid schema v1.0). The wire format is
276
- * always a JSON array; we schema-validate a single envelope and the
277
- * trigger unwraps the array at the boundary.
278
- */
279
- const azureEventGridEventSchema = z.object({
280
- id: z.string(),
281
- eventType: z.string(),
282
- subject: z.string(),
283
- eventTime: z.string(),
284
- dataVersion: z.string().optional(),
285
- metadataVersion: z.string().optional(),
286
- topic: z.string().optional(),
287
- data: z.record(z.string(), z.unknown())
288
- }).catchall(z.unknown());
289
-
290
- //#endregion
291
- export { azureEventGridEventSchema, gcsPubSubPushSchema, grantChangedEventSchema, pipeLoadEventSchema, scheduledDeltaEventSchema, scheduledSqlEventSchema, shareChangedEventSchema, snowflakeDiffSnapshotEntrySchema, snowflakeObjectKindSchema, snowflakeObjectLifecycleEventSchema, snowflakeRowBatchSchema, snowpipeObjectBatchSchema, snowpipeObjectEventSchema, snsNotificationSchema, statementCompletedEventSchema, statusPageComponentChangeEventSchema, statusPageIncidentEventSchema, streamAppendOnlyEventSchema, streamHasDataEventSchema, taskRunEventSchema, warehouseCreditsEventSchema, warehouseQueueEventSchema };
@@ -1,39 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { d as HydratedRow } from "../statements-DJL0qVNA.mjs";
3
- import { t as OptionMap } from "../sql-options-2k5xQ-oS.mjs";
4
- import { CatalogResult, ShowScopedOptions, showFileFormats } from "../catalog/index.mjs";
5
-
6
- //#region src/file-formats/index.d.ts
7
- interface FileFormatRef {
8
- readonly database?: string;
9
- readonly schema?: string;
10
- readonly name: string;
11
- }
12
- interface FileFormatContext {
13
- readonly warehouse?: string;
14
- readonly role?: string;
15
- }
16
- interface CreateFileFormatOptions extends FileFormatRef, FileFormatContext {
17
- readonly orReplace?: boolean;
18
- readonly ifNotExists?: boolean;
19
- readonly temporary?: boolean;
20
- /** `TYPE = 'CSV'`, `FIELD_DELIMITER = '|'`, `SKIP_HEADER = 1`, etc. */
21
- readonly options: OptionMap;
22
- readonly comment?: string;
23
- }
24
- declare function createFileFormat(client: SnowflakeClient, options: CreateFileFormatOptions): Promise<void>;
25
- interface AlterFileFormatOptions extends FileFormatRef, FileFormatContext {
26
- readonly rename?: FileFormatRef;
27
- readonly set?: OptionMap;
28
- readonly unset?: readonly string[];
29
- readonly comment?: string;
30
- }
31
- declare function alterFileFormat(client: SnowflakeClient, options: AlterFileFormatOptions): Promise<void>;
32
- interface DropFileFormatOptions extends FileFormatRef, FileFormatContext {
33
- readonly ifExists?: boolean;
34
- }
35
- declare function dropFileFormat(client: SnowflakeClient, options: DropFileFormatOptions): Promise<void>;
36
- interface DescribeFileFormatOptions extends FileFormatRef, FileFormatContext {}
37
- declare function describeFileFormat(client: SnowflakeClient, options: DescribeFileFormatOptions): Promise<readonly HydratedRow[]>;
38
- //#endregion
39
- export { AlterFileFormatOptions, type CatalogResult, CreateFileFormatOptions, DescribeFileFormatOptions, DropFileFormatOptions, FileFormatContext, FileFormatRef, type ShowScopedOptions, alterFileFormat, createFileFormat, describeFileFormat, dropFileFormat, showFileFormats };
@@ -1,48 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { a as quoteLiteral, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
3
- import { t as formatOptions } from "../sql-options-D6GEa21F.mjs";
4
- import { showFileFormats } from "../catalog/index.mjs";
5
-
6
- //#region src/file-formats/index.ts
7
- function fileFormatFqn(ref) {
8
- return buildFqn(ref.database, ref.schema, ref.name);
9
- }
10
- async function createFileFormat(client, options) {
11
- const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""}${options.temporary ? " TEMPORARY" : ""} FILE FORMAT${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
12
- const body = formatOptions(options.options);
13
- await executeSql(client, {
14
- statement: `${prefix} ${fileFormatFqn(options)} ${body}` + (options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : ""),
15
- warehouse: options.warehouse,
16
- role: options.role
17
- });
18
- }
19
- async function alterFileFormat(client, options) {
20
- let tail;
21
- if (options.rename) tail = `RENAME TO ${fileFormatFqn(options.rename)}`;
22
- else if (options.set && Object.keys(options.set).length > 0) tail = `SET ${formatOptions(options.set)}`;
23
- else if (options.unset && options.unset.length > 0) tail = `UNSET ${options.unset.map((k) => k.toUpperCase()).join(", ")}`;
24
- else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
25
- else throw new Error("alterFileFormat requires one of: rename / set / unset / comment");
26
- await executeSql(client, {
27
- statement: `ALTER FILE FORMAT ${fileFormatFqn(options)} ${tail}`,
28
- warehouse: options.warehouse,
29
- role: options.role
30
- });
31
- }
32
- async function dropFileFormat(client, options) {
33
- await executeSql(client, {
34
- statement: `DROP FILE FORMAT${options.ifExists ? " IF EXISTS" : ""} ${fileFormatFqn(options)}`,
35
- warehouse: options.warehouse,
36
- role: options.role
37
- });
38
- }
39
- async function describeFileFormat(client, options) {
40
- return (await executeSql(client, {
41
- statement: `DESCRIBE FILE FORMAT ${fileFormatFqn(options)}`,
42
- warehouse: options.warehouse,
43
- role: options.role
44
- })).rows;
45
- }
46
-
47
- //#endregion
48
- export { alterFileFormat, createFileFormat, describeFileFormat, dropFileFormat, showFileFormats };
@@ -1,53 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { d as HydratedRow } from "../statements-DJL0qVNA.mjs";
3
- import { t as OptionMap } from "../sql-options-2k5xQ-oS.mjs";
4
- import { CatalogResult, ShowScopedOptions, showFunctions } from "../catalog/index.mjs";
5
-
6
- //#region src/functions/index.d.ts
7
- interface FunctionRef {
8
- readonly database?: string;
9
- readonly schema?: string;
10
- readonly name: string;
11
- }
12
- interface FunctionContext {
13
- readonly warehouse?: string;
14
- readonly role?: string;
15
- }
16
- interface FunctionArgument {
17
- readonly name: string;
18
- /** Snowflake type keyword (NUMBER, VARCHAR, DATE, VARIANT, ...). */
19
- readonly type: string;
20
- readonly defaultExpression?: string;
21
- }
22
- type FunctionLanguage = 'SQL' | 'JAVASCRIPT' | 'PYTHON' | 'JAVA' | 'SCALA';
23
- interface CreateFunctionOptions extends FunctionRef, FunctionContext {
24
- readonly orReplace?: boolean;
25
- readonly ifNotExists?: boolean;
26
- readonly secure?: boolean;
27
- readonly temporary?: boolean;
28
- readonly arguments?: readonly FunctionArgument[];
29
- /** Return type keyword, e.g. `NUMBER`, `VARCHAR`, `TABLE (col1 NUMBER, col2 VARCHAR)`. */
30
- readonly returns: string;
31
- readonly language?: FunctionLanguage;
32
- /** `STRICT`, `IMMUTABLE`, `VOLATILE`, `MEMOIZABLE`, `RETURNS NULL ON NULL INPUT`. Raw keywords joined with spaces. */
33
- readonly modifiers?: readonly string[];
34
- /** Language-specific options: `RUNTIME_VERSION = '3.10'`, `PACKAGES = ('snowflake-snowpark-python')`, `HANDLER = 'main'`, `IMPORTS = (@STG/pkg.zip)`. */
35
- readonly options?: OptionMap;
36
- readonly comment?: string;
37
- /** Function body (SQL expression, JS, Python, Java). `$$...$$` wrapping is applied automatically for non-SQL languages. */
38
- readonly as: string;
39
- /** Force `$$...$$` (dollar-quoted) body delimiter even for SQL. */
40
- readonly dollarQuotedBody?: boolean;
41
- }
42
- declare function createFunction(client: SnowflakeClient, options: CreateFunctionOptions): Promise<void>;
43
- interface DropFunctionOptions extends FunctionRef, FunctionContext {
44
- readonly ifExists?: boolean;
45
- readonly arguments?: readonly FunctionArgument[];
46
- }
47
- declare function dropFunction(client: SnowflakeClient, options: DropFunctionOptions): Promise<void>;
48
- interface DescribeFunctionOptions extends FunctionRef, FunctionContext {
49
- readonly arguments?: readonly FunctionArgument[];
50
- }
51
- declare function describeFunction(client: SnowflakeClient, options: DescribeFunctionOptions): Promise<readonly HydratedRow[]>;
52
- //#endregion
53
- export { type CatalogResult, CreateFunctionOptions, DescribeFunctionOptions, DropFunctionOptions, FunctionArgument, FunctionContext, FunctionLanguage, FunctionRef, type ShowScopedOptions, createFunction, describeFunction, dropFunction, showFunctions };
@@ -1,56 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { a as quoteLiteral, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
3
- import { t as formatOptions } from "../sql-options-D6GEa21F.mjs";
4
- import { showFunctions } from "../catalog/index.mjs";
5
-
6
- //#region src/functions/index.ts
7
- function renderArguments(args) {
8
- if (!args || args.length === 0) return "()";
9
- return `(${args.map((a) => {
10
- const suffix = a.defaultExpression ? ` DEFAULT ${a.defaultExpression}` : "";
11
- return `${a.name} ${a.type.toUpperCase()}${suffix}`;
12
- }).join(", ")})`;
13
- }
14
- function renderArgumentTypes(args) {
15
- if (!args || args.length === 0) return "()";
16
- return `(${args.map((a) => a.type.toUpperCase()).join(", ")})`;
17
- }
18
- function renderBody(body, forceDollarQuoted, language) {
19
- if (forceDollarQuoted ?? (language !== void 0 && language !== "SQL")) {
20
- if (body.includes("$$")) throw new Error("Function body contains \"$$\"; cannot safely dollar-quote. Use quoteLiteral-style body or a custom delimiter.");
21
- return `$$${body}$$`;
22
- }
23
- return body;
24
- }
25
- async function createFunction(client, options) {
26
- const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""}${options.secure ? " SECURE" : ""}${options.temporary ? " TEMPORARY" : ""} FUNCTION${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
27
- const args = renderArguments(options.arguments);
28
- const language = options.language ? ` LANGUAGE ${options.language}` : "";
29
- const modifiers = options.modifiers && options.modifiers.length > 0 ? ` ${options.modifiers.map((m) => m.toUpperCase()).join(" ")}` : "";
30
- const body = options.options && Object.keys(options.options).length > 0 ? ` ${formatOptions(options.options)}` : "";
31
- const comment = options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : "";
32
- const rendered = renderBody(options.as, options.dollarQuotedBody, options.language);
33
- await executeSql(client, {
34
- statement: `${prefix} ${buildFqn(options.database, options.schema, options.name)}${args} RETURNS ${options.returns}${language}${modifiers}${body}${comment} AS ${rendered}`,
35
- warehouse: options.warehouse,
36
- role: options.role
37
- });
38
- }
39
- async function dropFunction(client, options) {
40
- const fqn = buildFqn(options.database, options.schema, options.name);
41
- await executeSql(client, {
42
- statement: `DROP FUNCTION${options.ifExists ? " IF EXISTS" : ""} ${fqn}${renderArgumentTypes(options.arguments)}`,
43
- warehouse: options.warehouse,
44
- role: options.role
45
- });
46
- }
47
- async function describeFunction(client, options) {
48
- return (await executeSql(client, {
49
- statement: `DESCRIBE FUNCTION ${buildFqn(options.database, options.schema, options.name)}${renderArgumentTypes(options.arguments)}`,
50
- warehouse: options.warehouse,
51
- role: options.role
52
- })).rows;
53
- }
54
-
55
- //#endregion
56
- export { createFunction, describeFunction, dropFunction, showFunctions };
@@ -1,93 +0,0 @@
1
- import { SnowflakeClient } from "../client/index.mjs";
2
- import { CatalogResult, ShowOptions, showGrants } from "../catalog/index.mjs";
3
-
4
- //#region src/grants/index.d.ts
5
- interface GrantContext {
6
- readonly warehouse?: string;
7
- readonly role?: string;
8
- }
9
- /**
10
- * What a privilege is being granted on. `kind: 'object'` covers the
11
- * vast majority of cases (TABLE / VIEW / STAGE / FILE FORMAT / FUNCTION /
12
- * PROCEDURE / STREAM / TASK / PIPE / ...). Scope-level variants
13
- * (`database` / `schema` / `warehouse` / `role` / `integration` / `account`)
14
- * cover grants that apply to whole containers. `allIn` / `futureIn`
15
- * produce `GRANT ... ON ALL|FUTURE <PLURAL> IN ...` statements.
16
- */
17
- type GrantOn = {
18
- readonly kind: 'object'; /** Snowflake object keyword, e.g., `TABLE`, `VIEW`, `STAGE`. */
19
- readonly objectType: string;
20
- readonly database?: string;
21
- readonly schema?: string;
22
- readonly name: string;
23
- } | {
24
- readonly kind: 'database' | 'warehouse' | 'role' | 'integration';
25
- readonly name: string;
26
- } | {
27
- readonly kind: 'schema';
28
- readonly database?: string;
29
- readonly name: string;
30
- } | {
31
- readonly kind: 'account';
32
- } | {
33
- readonly kind: 'allIn' | 'futureIn'; /** Plural keyword, e.g., `TABLES`, `VIEWS`, `SCHEMAS`. */
34
- readonly pluralType: string;
35
- readonly inDatabase?: string;
36
- readonly inSchema?: {
37
- readonly database?: string;
38
- readonly name: string;
39
- };
40
- };
41
- type GrantTarget = {
42
- readonly role: string;
43
- } | {
44
- readonly user: string;
45
- } | {
46
- readonly share: string;
47
- };
48
- interface GrantPrivilegesOptions extends GrantContext {
49
- readonly privileges: 'ALL' | 'ALL PRIVILEGES' | readonly string[];
50
- readonly on: GrantOn;
51
- readonly to: GrantTarget;
52
- readonly withGrantOption?: boolean;
53
- }
54
- declare function grantPrivileges(client: SnowflakeClient, options: GrantPrivilegesOptions): Promise<void>;
55
- interface RevokePrivilegesOptions extends GrantContext {
56
- readonly privileges: 'ALL' | 'ALL PRIVILEGES' | readonly string[];
57
- readonly on: GrantOn;
58
- readonly from: GrantTarget;
59
- /** Only revoke the grant option, not the underlying privilege. */
60
- readonly grantOptionFor?: boolean;
61
- readonly cascade?: boolean;
62
- readonly restrict?: boolean;
63
- }
64
- declare function revokePrivileges(client: SnowflakeClient, options: RevokePrivilegesOptions): Promise<void>;
65
- interface ShowGrantsToRoleOptions extends ShowOptions {
66
- readonly role: string;
67
- }
68
- declare function showGrantsToRole(client: SnowflakeClient, options: ShowGrantsToRoleOptions): Promise<CatalogResult>;
69
- interface ShowGrantsToUserOptions extends ShowOptions {
70
- readonly user: string;
71
- }
72
- declare function showGrantsToUser(client: SnowflakeClient, options: ShowGrantsToUserOptions): Promise<CatalogResult>;
73
- interface ShowGrantsOnObjectOptions extends ShowOptions {
74
- readonly objectType: string;
75
- readonly database?: string;
76
- readonly schema?: string;
77
- readonly name: string;
78
- }
79
- declare function showGrantsOnObject(client: SnowflakeClient, options: ShowGrantsOnObjectOptions): Promise<CatalogResult>;
80
- interface ShowGrantsOfRoleOptions extends ShowOptions {
81
- readonly role: string;
82
- }
83
- declare function showGrantsOfRole(client: SnowflakeClient, options: ShowGrantsOfRoleOptions): Promise<CatalogResult>;
84
- interface ShowFutureGrantsOptions extends ShowOptions {
85
- readonly inDatabase?: string;
86
- readonly inSchema?: {
87
- readonly database?: string;
88
- readonly name: string;
89
- };
90
- }
91
- declare function showFutureGrants(client: SnowflakeClient, options: ShowFutureGrantsOptions): Promise<CatalogResult>;
92
- //#endregion
93
- export { type CatalogResult, GrantContext, GrantOn, GrantPrivilegesOptions, GrantTarget, RevokePrivilegesOptions, ShowFutureGrantsOptions, ShowGrantsOfRoleOptions, ShowGrantsOnObjectOptions, ShowGrantsToRoleOptions, ShowGrantsToUserOptions, grantPrivileges, revokePrivileges, showFutureGrants, showGrants, showGrantsOfRole, showGrantsOnObject, showGrantsToRole, showGrantsToUser };
@@ -1,102 +0,0 @@
1
- import { executeSql } from "../sql/index.mjs";
2
- import { i as quoteIdentifier, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
3
- import { showGrants } from "../catalog/index.mjs";
4
-
5
- //#region src/grants/index.ts
6
- /**
7
- * Grants / privileges: GRANT, REVOKE, and five SHOW GRANTS convenience
8
- * wrappers plus SHOW FUTURE GRANTS.
9
- *
10
- * Covers PLAN §6.15 (7 actions).
11
- */
12
- function renderScope(on) {
13
- switch (on.kind) {
14
- case "object": return `${on.objectType.toUpperCase()} ${buildFqn(on.database, on.schema, on.name)}`;
15
- case "schema": return `SCHEMA ${buildFqn(on.database, on.name)}`;
16
- case "database": return `DATABASE ${quoteIdentifier(on.name)}`;
17
- case "warehouse": return `WAREHOUSE ${quoteIdentifier(on.name)}`;
18
- case "role": return `ROLE ${quoteIdentifier(on.name)}`;
19
- case "integration": return `INTEGRATION ${quoteIdentifier(on.name)}`;
20
- case "account": return "ACCOUNT";
21
- case "allIn":
22
- case "futureIn": {
23
- const modifier = on.kind === "allIn" ? "ALL" : "FUTURE";
24
- const plural = on.pluralType.toUpperCase();
25
- if (on.inDatabase) return `${modifier} ${plural} IN DATABASE ${quoteIdentifier(on.inDatabase)}`;
26
- if (on.inSchema) return `${modifier} ${plural} IN SCHEMA ${buildFqn(on.inSchema.database, on.inSchema.name)}`;
27
- throw new Error(`${on.kind} requires inDatabase or inSchema`);
28
- }
29
- }
30
- }
31
- function renderTarget(target) {
32
- if ("role" in target) return `ROLE ${quoteIdentifier(target.role)}`;
33
- if ("user" in target) return `USER ${quoteIdentifier(target.user)}`;
34
- return `SHARE ${quoteIdentifier(target.share)}`;
35
- }
36
- function renderPrivileges(privileges) {
37
- if (privileges === "ALL" || privileges === "ALL PRIVILEGES") return "ALL PRIVILEGES";
38
- if (privileges.length === 0) throw new Error("privileges must be non-empty (or \"ALL\" / \"ALL PRIVILEGES\")");
39
- return privileges.map((p) => p.toUpperCase()).join(", ");
40
- }
41
- async function grantPrivileges(client, options) {
42
- await executeSql(client, {
43
- statement: `GRANT ${renderPrivileges(options.privileges)} ON ${renderScope(options.on)} TO ${renderTarget(options.to)}${options.withGrantOption ? " WITH GRANT OPTION" : ""}`,
44
- warehouse: options.warehouse,
45
- role: options.role
46
- });
47
- }
48
- async function revokePrivileges(client, options) {
49
- if (options.cascade && options.restrict) throw new Error("revokePrivileges: cascade and restrict are mutually exclusive");
50
- await executeSql(client, {
51
- statement: `${options.grantOptionFor ? "REVOKE GRANT OPTION FOR" : "REVOKE"} ${renderPrivileges(options.privileges)} ON ${renderScope(options.on)} FROM ${renderTarget(options.from)}${options.cascade ? " CASCADE" : options.restrict ? " RESTRICT" : ""}`,
52
- warehouse: options.warehouse,
53
- role: options.role
54
- });
55
- }
56
- async function showGrantsToRole(client, options) {
57
- return showGrants(client, {
58
- ...options,
59
- toRole: options.role
60
- });
61
- }
62
- async function showGrantsToUser(client, options) {
63
- return showGrants(client, {
64
- ...options,
65
- toUser: options.user
66
- });
67
- }
68
- async function showGrantsOnObject(client, options) {
69
- return showGrants(client, {
70
- ...options,
71
- on: {
72
- objectType: options.objectType,
73
- database: options.database,
74
- schema: options.schema,
75
- name: options.name
76
- }
77
- });
78
- }
79
- async function showGrantsOfRole(client, options) {
80
- return showGrants(client, {
81
- ...options,
82
- ofRole: options.role
83
- });
84
- }
85
- async function showFutureGrants(client, options) {
86
- let scope;
87
- if (options.inDatabase) scope = `DATABASE ${quoteIdentifier(options.inDatabase)}`;
88
- else if (options.inSchema) scope = `SCHEMA ${buildFqn(options.inSchema.database, options.inSchema.name)}`;
89
- else throw new Error("showFutureGrants requires inDatabase or inSchema");
90
- const result = await executeSql(client, {
91
- statement: `SHOW FUTURE GRANTS IN ${scope}`,
92
- warehouse: options.warehouse,
93
- role: options.role
94
- });
95
- return {
96
- rows: result.rows,
97
- columns: result.columns
98
- };
99
- }
100
-
101
- //#endregion
102
- export { grantPrivileges, revokePrivileges, showFutureGrants, showGrants, showGrantsOfRole, showGrantsOnObject, showGrantsToRole, showGrantsToUser };