@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.
- package/README.md +247 -0
- package/dist/_official/index.d.mts +2 -0
- package/dist/_official/index.mjs +3 -0
- package/dist/_runtime/index.d.mts +1 -0
- package/dist/_runtime/index.mjs +1 -0
- package/dist/accounts.d.mts +40 -0
- package/dist/accounts.mjs +51 -0
- package/dist/bulk.d.mts +71 -0
- package/dist/bulk.mjs +65 -0
- package/dist/catalog.d.mts +144 -0
- package/dist/catalog.mjs +158 -0
- package/dist/client.d.mts +44 -0
- package/dist/client.mjs +273 -0
- package/dist/common-BnKTPQXc.mjs +92 -0
- package/dist/connection.d.mts +2 -0
- package/dist/connection.mjs +3 -0
- package/dist/databases.d.mts +2 -0
- package/dist/databases.mjs +3 -0
- package/dist/errors-DKnc9o_a.mjs +95 -0
- package/dist/events.d.mts +382 -0
- package/dist/events.mjs +291 -0
- package/dist/file-formats.d.mts +39 -0
- package/dist/file-formats.mjs +48 -0
- package/dist/functions.d.mts +53 -0
- package/dist/functions.mjs +56 -0
- package/dist/grants.d.mts +93 -0
- package/dist/grants.mjs +102 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/integration-CCWMSTlO.d.mts +170 -0
- package/dist/integration-Dptv8L0L.mjs +207 -0
- package/dist/org-admin.d.mts +80 -0
- package/dist/org-admin.mjs +79 -0
- package/dist/pipes.d.mts +119 -0
- package/dist/pipes.mjs +106 -0
- package/dist/procedures.d.mts +61 -0
- package/dist/procedures.mjs +79 -0
- package/dist/results.d.mts +16 -0
- package/dist/results.mjs +64 -0
- package/dist/retry-0hMfb8cC.mjs +164 -0
- package/dist/retry-w7cTp1QL.d.mts +10 -0
- package/dist/roles.d.mts +60 -0
- package/dist/roles.mjs +74 -0
- package/dist/rows.d.mts +106 -0
- package/dist/rows.mjs +223 -0
- package/dist/schemas/index.d.mts +2 -0
- package/dist/schemas/index.mjs +4 -0
- package/dist/schemas-catalog.d.mts +2 -0
- package/dist/schemas-catalog.mjs +3 -0
- package/dist/shares.d.mts +56 -0
- package/dist/shares.mjs +77 -0
- package/dist/sql-options-2k5xQ-oS.d.mts +32 -0
- package/dist/sql-options-DI-OmLU6.mjs +79 -0
- package/dist/sql-safety-CywdR3EP.mjs +56 -0
- package/dist/sql.d.mts +84 -0
- package/dist/sql.mjs +209 -0
- package/dist/stages.d.mts +64 -0
- package/dist/stages.mjs +81 -0
- package/dist/statements-B2ThF_4b.mjs +81 -0
- package/dist/statements-DJL0qVNA.d.mts +238 -0
- package/dist/status-page.d.mts +510 -0
- package/dist/status-page.mjs +261 -0
- package/dist/streaming.d.mts +70 -0
- package/dist/streaming.mjs +56 -0
- package/dist/streams.d.mts +71 -0
- package/dist/streams.mjs +78 -0
- package/dist/tables.d.mts +2 -0
- package/dist/tables.mjs +3 -0
- package/dist/tasks.d.mts +79 -0
- package/dist/tasks.mjs +104 -0
- package/dist/triggers.d.mts +578 -0
- package/dist/triggers.mjs +1363 -0
- package/dist/users.d.mts +61 -0
- package/dist/users.mjs +67 -0
- package/dist/verification.d.mts +201 -0
- package/dist/verification.mjs +512 -0
- package/dist/views.d.mts +2 -0
- package/dist/views.mjs +3 -0
- package/dist/warehouses.d.mts +68 -0
- package/dist/warehouses.mjs +101 -0
- package/package.json +190 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SnowflakeClient } from "./client.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.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/file-formats.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 };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { executeSql } from "./sql.mjs";
|
|
2
|
+
import { a as quoteLiteral, t as buildFqn } from "./sql-safety-CywdR3EP.mjs";
|
|
3
|
+
import { t as formatOptions } from "./sql-options-DI-OmLU6.mjs";
|
|
4
|
+
import { showFileFormats } from "./catalog.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/file-formats.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 };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SnowflakeClient } from "./client.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.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/functions.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 };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { executeSql } from "./sql.mjs";
|
|
2
|
+
import { a as quoteLiteral, t as buildFqn } from "./sql-safety-CywdR3EP.mjs";
|
|
3
|
+
import { t as formatOptions } from "./sql-options-DI-OmLU6.mjs";
|
|
4
|
+
import { showFunctions } from "./catalog.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/functions.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 };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SnowflakeClient } from "./client.mjs";
|
|
2
|
+
import { CatalogResult, ShowOptions, showGrants } from "./catalog.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/grants.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 };
|
package/dist/grants.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { executeSql } from "./sql.mjs";
|
|
2
|
+
import { i as quoteIdentifier, t as buildFqn } from "./sql-safety-CywdR3EP.mjs";
|
|
3
|
+
import { showGrants } from "./catalog.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/grants.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 };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as _keystrokehq_integration_authoring_official0 from "@keystrokehq/integration-authoring/official";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
4
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
5
|
+
import { InferCredentialSetAuth } from "@keystrokehq/core/credential-set";
|
|
6
|
+
|
|
7
|
+
//#region src/integration.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Public auth schema for Snowflake connections.
|
|
10
|
+
*
|
|
11
|
+
* Modeled as a discriminated union on `mode`. `connection.kind` is `manual`
|
|
12
|
+
* because Keystroke does not run an interactive Snowflake OAuth dance — OAuth
|
|
13
|
+
* mode accepts a bearer token provided by the caller (external IdP /
|
|
14
|
+
* Snowflake-hosted OAuth). See `IMPLEMENTATION_NOTES.md` § 2 for rationale.
|
|
15
|
+
*/
|
|
16
|
+
declare const snowflakeAuthModeSchema: z.ZodEnum<{
|
|
17
|
+
keypair: "keypair";
|
|
18
|
+
oauth: "oauth";
|
|
19
|
+
pat: "pat";
|
|
20
|
+
basic: "basic";
|
|
21
|
+
}>;
|
|
22
|
+
type SnowflakeAuthMode = z.infer<typeof snowflakeAuthModeSchema>;
|
|
23
|
+
declare const snowflakeAuthSchema: z.ZodObject<{
|
|
24
|
+
mode: z.ZodEnum<{
|
|
25
|
+
keypair: "keypair";
|
|
26
|
+
oauth: "oauth";
|
|
27
|
+
pat: "pat";
|
|
28
|
+
basic: "basic";
|
|
29
|
+
}>;
|
|
30
|
+
SNOWFLAKE_ACCOUNT: z.ZodString;
|
|
31
|
+
SNOWFLAKE_USER: z.ZodOptional<z.ZodString>;
|
|
32
|
+
SNOWFLAKE_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
33
|
+
SNOWFLAKE_PRIVATE_KEY_PASSPHRASE: z.ZodOptional<z.ZodString>;
|
|
34
|
+
SNOWFLAKE_PAT: z.ZodOptional<z.ZodString>;
|
|
35
|
+
SNOWFLAKE_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
36
|
+
SNOWFLAKE_OAUTH_ACCESS_TOKEN: z.ZodOptional<z.ZodString>;
|
|
37
|
+
SNOWFLAKE_OAUTH_REFRESH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
38
|
+
SNOWFLAKE_OAUTH_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
39
|
+
SNOWFLAKE_OAUTH_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
40
|
+
SNOWFLAKE_OAUTH_TOKEN_URL: z.ZodOptional<z.ZodString>;
|
|
41
|
+
SNOWFLAKE_OAUTH_SCOPES: z.ZodOptional<z.ZodString>;
|
|
42
|
+
SNOWFLAKE_ROLE: z.ZodOptional<z.ZodString>;
|
|
43
|
+
SNOWFLAKE_WAREHOUSE: z.ZodOptional<z.ZodString>;
|
|
44
|
+
SNOWFLAKE_DATABASE: z.ZodOptional<z.ZodString>;
|
|
45
|
+
SNOWFLAKE_SCHEMA: z.ZodOptional<z.ZodString>;
|
|
46
|
+
SNOWFLAKE_HOST: z.ZodOptional<z.ZodString>;
|
|
47
|
+
SNOWFLAKE_REGION: z.ZodOptional<z.ZodString>;
|
|
48
|
+
SNOWFLAKE_PUBLIC_KEY_FP: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
declare const snowflakeOfficialIntegration: {
|
|
51
|
+
id: "snowflake";
|
|
52
|
+
name: string;
|
|
53
|
+
description: string;
|
|
54
|
+
auth: z.ZodObject<{
|
|
55
|
+
mode: z.ZodEnum<{
|
|
56
|
+
keypair: "keypair";
|
|
57
|
+
oauth: "oauth";
|
|
58
|
+
pat: "pat";
|
|
59
|
+
basic: "basic";
|
|
60
|
+
}>;
|
|
61
|
+
SNOWFLAKE_ACCOUNT: z.ZodString;
|
|
62
|
+
SNOWFLAKE_USER: z.ZodOptional<z.ZodString>;
|
|
63
|
+
SNOWFLAKE_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
64
|
+
SNOWFLAKE_PRIVATE_KEY_PASSPHRASE: z.ZodOptional<z.ZodString>;
|
|
65
|
+
SNOWFLAKE_PAT: z.ZodOptional<z.ZodString>;
|
|
66
|
+
SNOWFLAKE_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
67
|
+
SNOWFLAKE_OAUTH_ACCESS_TOKEN: z.ZodOptional<z.ZodString>;
|
|
68
|
+
SNOWFLAKE_OAUTH_REFRESH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
69
|
+
SNOWFLAKE_OAUTH_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
70
|
+
SNOWFLAKE_OAUTH_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
71
|
+
SNOWFLAKE_OAUTH_TOKEN_URL: z.ZodOptional<z.ZodString>;
|
|
72
|
+
SNOWFLAKE_OAUTH_SCOPES: z.ZodOptional<z.ZodString>;
|
|
73
|
+
SNOWFLAKE_ROLE: z.ZodOptional<z.ZodString>;
|
|
74
|
+
SNOWFLAKE_WAREHOUSE: z.ZodOptional<z.ZodString>;
|
|
75
|
+
SNOWFLAKE_DATABASE: z.ZodOptional<z.ZodString>;
|
|
76
|
+
SNOWFLAKE_SCHEMA: z.ZodOptional<z.ZodString>;
|
|
77
|
+
SNOWFLAKE_HOST: z.ZodOptional<z.ZodString>;
|
|
78
|
+
SNOWFLAKE_REGION: z.ZodOptional<z.ZodString>;
|
|
79
|
+
SNOWFLAKE_PUBLIC_KEY_FP: z.ZodOptional<z.ZodString>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
};
|
|
82
|
+
declare const snowflakeBundle: _keystrokehq_integration_authoring_official0.OfficialIntegrationBundle<"snowflake", z.ZodObject<{
|
|
83
|
+
mode: z.ZodEnum<{
|
|
84
|
+
keypair: "keypair";
|
|
85
|
+
oauth: "oauth";
|
|
86
|
+
pat: "pat";
|
|
87
|
+
basic: "basic";
|
|
88
|
+
}>;
|
|
89
|
+
SNOWFLAKE_ACCOUNT: z.ZodString;
|
|
90
|
+
SNOWFLAKE_USER: z.ZodOptional<z.ZodString>;
|
|
91
|
+
SNOWFLAKE_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
92
|
+
SNOWFLAKE_PRIVATE_KEY_PASSPHRASE: z.ZodOptional<z.ZodString>;
|
|
93
|
+
SNOWFLAKE_PAT: z.ZodOptional<z.ZodString>;
|
|
94
|
+
SNOWFLAKE_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
95
|
+
SNOWFLAKE_OAUTH_ACCESS_TOKEN: z.ZodOptional<z.ZodString>;
|
|
96
|
+
SNOWFLAKE_OAUTH_REFRESH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
97
|
+
SNOWFLAKE_OAUTH_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
98
|
+
SNOWFLAKE_OAUTH_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
99
|
+
SNOWFLAKE_OAUTH_TOKEN_URL: z.ZodOptional<z.ZodString>;
|
|
100
|
+
SNOWFLAKE_OAUTH_SCOPES: z.ZodOptional<z.ZodString>;
|
|
101
|
+
SNOWFLAKE_ROLE: z.ZodOptional<z.ZodString>;
|
|
102
|
+
SNOWFLAKE_WAREHOUSE: z.ZodOptional<z.ZodString>;
|
|
103
|
+
SNOWFLAKE_DATABASE: z.ZodOptional<z.ZodString>;
|
|
104
|
+
SNOWFLAKE_SCHEMA: z.ZodOptional<z.ZodString>;
|
|
105
|
+
SNOWFLAKE_HOST: z.ZodOptional<z.ZodString>;
|
|
106
|
+
SNOWFLAKE_REGION: z.ZodOptional<z.ZodString>;
|
|
107
|
+
SNOWFLAKE_PUBLIC_KEY_FP: z.ZodOptional<z.ZodString>;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
declare const snowflake: _keystrokehq_core0.CredentialSet<"snowflake", z.ZodObject<{
|
|
110
|
+
mode: z.ZodEnum<{
|
|
111
|
+
keypair: "keypair";
|
|
112
|
+
oauth: "oauth";
|
|
113
|
+
pat: "pat";
|
|
114
|
+
basic: "basic";
|
|
115
|
+
}>;
|
|
116
|
+
SNOWFLAKE_ACCOUNT: z.ZodString;
|
|
117
|
+
SNOWFLAKE_USER: z.ZodOptional<z.ZodString>;
|
|
118
|
+
SNOWFLAKE_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
119
|
+
SNOWFLAKE_PRIVATE_KEY_PASSPHRASE: z.ZodOptional<z.ZodString>;
|
|
120
|
+
SNOWFLAKE_PAT: z.ZodOptional<z.ZodString>;
|
|
121
|
+
SNOWFLAKE_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
122
|
+
SNOWFLAKE_OAUTH_ACCESS_TOKEN: z.ZodOptional<z.ZodString>;
|
|
123
|
+
SNOWFLAKE_OAUTH_REFRESH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
124
|
+
SNOWFLAKE_OAUTH_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
125
|
+
SNOWFLAKE_OAUTH_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
126
|
+
SNOWFLAKE_OAUTH_TOKEN_URL: z.ZodOptional<z.ZodString>;
|
|
127
|
+
SNOWFLAKE_OAUTH_SCOPES: z.ZodOptional<z.ZodString>;
|
|
128
|
+
SNOWFLAKE_ROLE: z.ZodOptional<z.ZodString>;
|
|
129
|
+
SNOWFLAKE_WAREHOUSE: z.ZodOptional<z.ZodString>;
|
|
130
|
+
SNOWFLAKE_DATABASE: z.ZodOptional<z.ZodString>;
|
|
131
|
+
SNOWFLAKE_SCHEMA: z.ZodOptional<z.ZodString>;
|
|
132
|
+
SNOWFLAKE_HOST: z.ZodOptional<z.ZodString>;
|
|
133
|
+
SNOWFLAKE_REGION: z.ZodOptional<z.ZodString>;
|
|
134
|
+
SNOWFLAKE_PUBLIC_KEY_FP: z.ZodOptional<z.ZodString>;
|
|
135
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
136
|
+
mode: z.ZodEnum<{
|
|
137
|
+
keypair: "keypair";
|
|
138
|
+
oauth: "oauth";
|
|
139
|
+
pat: "pat";
|
|
140
|
+
basic: "basic";
|
|
141
|
+
}>;
|
|
142
|
+
SNOWFLAKE_ACCOUNT: z.ZodString;
|
|
143
|
+
SNOWFLAKE_USER: z.ZodOptional<z.ZodString>;
|
|
144
|
+
SNOWFLAKE_PRIVATE_KEY: z.ZodOptional<z.ZodString>;
|
|
145
|
+
SNOWFLAKE_PRIVATE_KEY_PASSPHRASE: z.ZodOptional<z.ZodString>;
|
|
146
|
+
SNOWFLAKE_PAT: z.ZodOptional<z.ZodString>;
|
|
147
|
+
SNOWFLAKE_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
148
|
+
SNOWFLAKE_OAUTH_ACCESS_TOKEN: z.ZodOptional<z.ZodString>;
|
|
149
|
+
SNOWFLAKE_OAUTH_REFRESH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
150
|
+
SNOWFLAKE_OAUTH_CLIENT_ID: z.ZodOptional<z.ZodString>;
|
|
151
|
+
SNOWFLAKE_OAUTH_CLIENT_SECRET: z.ZodOptional<z.ZodString>;
|
|
152
|
+
SNOWFLAKE_OAUTH_TOKEN_URL: z.ZodOptional<z.ZodString>;
|
|
153
|
+
SNOWFLAKE_OAUTH_SCOPES: z.ZodOptional<z.ZodString>;
|
|
154
|
+
SNOWFLAKE_ROLE: z.ZodOptional<z.ZodString>;
|
|
155
|
+
SNOWFLAKE_WAREHOUSE: z.ZodOptional<z.ZodString>;
|
|
156
|
+
SNOWFLAKE_DATABASE: z.ZodOptional<z.ZodString>;
|
|
157
|
+
SNOWFLAKE_SCHEMA: z.ZodOptional<z.ZodString>;
|
|
158
|
+
SNOWFLAKE_HOST: z.ZodOptional<z.ZodString>;
|
|
159
|
+
SNOWFLAKE_REGION: z.ZodOptional<z.ZodString>;
|
|
160
|
+
SNOWFLAKE_PUBLIC_KEY_FP: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>>[] | undefined>;
|
|
162
|
+
type SnowflakeCredentials = InferCredentialSetAuth<typeof snowflake>;
|
|
163
|
+
/**
|
|
164
|
+
* Parse raw credential values through the full refinement pipeline. Callers
|
|
165
|
+
* (client, operations) should use this instead of the raw object schema so
|
|
166
|
+
* mode-specific invariants are enforced.
|
|
167
|
+
*/
|
|
168
|
+
declare function parseSnowflakeCredentials(input: unknown): SnowflakeCredentials;
|
|
169
|
+
//#endregion
|
|
170
|
+
export { snowflakeAuthModeSchema as a, snowflakeOfficialIntegration as c, snowflake as i, SnowflakeCredentials as n, snowflakeAuthSchema as o, parseSnowflakeCredentials as r, snowflakeBundle as s, SnowflakeAuthMode as t };
|