@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.
- package/LICENSE +1 -1
- package/README.md +9 -233
- package/package.json +39 -171
- package/dist/accounts/index.d.mts +0 -40
- package/dist/accounts/index.mjs +0 -51
- package/dist/bulk/index.d.mts +0 -71
- package/dist/bulk/index.mjs +0 -65
- package/dist/catalog/index.d.mts +0 -144
- package/dist/catalog/index.mjs +0 -158
- package/dist/client/index.d.mts +0 -44
- package/dist/client/index.mjs +0 -273
- package/dist/common-DfpCwJx5.mjs +0 -92
- package/dist/credential-sets/index.d.mts +0 -3
- package/dist/credential-sets/index.mjs +0 -4
- package/dist/databases/index.d.mts +0 -2
- package/dist/databases/index.mjs +0 -3
- package/dist/errors-60AsF7Su.mjs +0 -95
- package/dist/events/index.d.mts +0 -382
- package/dist/events/index.mjs +0 -291
- package/dist/file-formats/index.d.mts +0 -39
- package/dist/file-formats/index.mjs +0 -48
- package/dist/functions/index.d.mts +0 -53
- package/dist/functions/index.mjs +0 -56
- package/dist/grants/index.d.mts +0 -93
- package/dist/grants/index.mjs +0 -102
- package/dist/index.d.mts +0 -4
- package/dist/index.mjs +0 -6
- package/dist/operations/index.d.mts +0 -1
- package/dist/operations/index.mjs +0 -1
- package/dist/org-admin/index.d.mts +0 -80
- package/dist/org-admin/index.mjs +0 -79
- package/dist/pipes/index.d.mts +0 -119
- package/dist/pipes/index.mjs +0 -106
- package/dist/procedures/index.d.mts +0 -61
- package/dist/procedures/index.mjs +0 -79
- package/dist/results/index.d.mts +0 -16
- package/dist/results/index.mjs +0 -64
- package/dist/retry-B4-9MZIp.mjs +0 -164
- package/dist/retry-w7cTp1QL.d.mts +0 -10
- package/dist/roles/index.d.mts +0 -60
- package/dist/roles/index.mjs +0 -74
- package/dist/rows/index.d.mts +0 -106
- package/dist/rows/index.mjs +0 -223
- package/dist/schemas/index.d.mts +0 -2
- package/dist/schemas/index.mjs +0 -4
- package/dist/schemas-catalog/index.d.mts +0 -2
- package/dist/schemas-catalog/index.mjs +0 -3
- package/dist/shares/index.d.mts +0 -56
- package/dist/shares/index.mjs +0 -77
- package/dist/snowflake-s3-sns-webhook.credential-set-D6bLAWy5.d.mts +0 -50
- package/dist/snowflake-s3-sns-webhook.credential-set-DzR7oWNK.mjs +0 -44
- package/dist/snowflake.credential-set-BxT7Gf3A.d.mts +0 -114
- package/dist/snowflake.credential-set-DE3gXf-a.mjs +0 -106
- package/dist/sql/index.d.mts +0 -84
- package/dist/sql/index.mjs +0 -209
- package/dist/sql-options-2k5xQ-oS.d.mts +0 -32
- package/dist/sql-options-D6GEa21F.mjs +0 -79
- package/dist/sql-safety-BZpAPsq6.mjs +0 -56
- package/dist/stages/index.d.mts +0 -64
- package/dist/stages/index.mjs +0 -81
- package/dist/statements-BumhMhN4.mjs +0 -81
- package/dist/statements-DJL0qVNA.d.mts +0 -238
- package/dist/status-page/index.d.mts +0 -510
- package/dist/status-page/index.mjs +0 -261
- package/dist/streaming/index.d.mts +0 -70
- package/dist/streaming/index.mjs +0 -56
- package/dist/streams/index.d.mts +0 -71
- package/dist/streams/index.mjs +0 -78
- package/dist/tables/index.d.mts +0 -2
- package/dist/tables/index.mjs +0 -3
- package/dist/tasks/index.d.mts +0 -79
- package/dist/tasks/index.mjs +0 -104
- package/dist/triggers/index.d.mts +0 -381
- package/dist/triggers/index.mjs +0 -1100
- package/dist/users/index.d.mts +0 -61
- package/dist/users/index.mjs +0 -67
- package/dist/verification/index.d.mts +0 -201
- package/dist/verification/index.mjs +0 -512
- package/dist/views/index.d.mts +0 -2
- package/dist/views/index.mjs +0 -3
- package/dist/warehouses/index.d.mts +0 -68
- package/dist/warehouses/index.mjs +0 -101
package/dist/index.d.mts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { a as snowflakeAuthSchema, i as snowflakeAuthModeSchema, n as SnowflakeCredentials, o as snowflakeCredentialSet, r as parseSnowflakeCredentials, t as SnowflakeAuthMode } from "./snowflake.credential-set-BxT7Gf3A.mjs";
|
|
2
|
-
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";
|
|
3
|
-
import { a as SnowflakeAzureEventGridWebhookCredentials, i as snowflakeGcsPubSubWebhookCredentialSet, n as snowflakeS3SnsWebhookCredentialSet, o as snowflakeAzureEventGridWebhookCredentialSet, r as SnowflakeGcsPubSubWebhookCredentials, t as SnowflakeS3SnsWebhookCredentials } from "./snowflake-s3-sns-webhook.credential-set-D6bLAWy5.mjs";
|
|
4
|
-
export { CancelStatementResponse, ColumnMeta, HydratedRow, PartitionInfo, PartitionResponse, ResultSetMetaData, SnowflakeAuthMode, SnowflakeAzureEventGridWebhookCredentials, SnowflakeCredentials, SnowflakeGcsPubSubWebhookCredentials, SnowflakeObjectRow, SnowflakeS3SnsWebhookCredentials, SqlBinding, SqlBindings, StatementContext, StatementResponse, StatementStatus, StatementTerminalStatus, SubmitStatementInput, cancelStatementResponseSchema, columnMetaSchema, parseSnowflakeCredentials, partitionInfoSchema, partitionResponseSchema, resultSetMetaDataSchema, snowflakeAuthModeSchema, snowflakeAuthSchema, snowflakeAzureEventGridWebhookCredentialSet, snowflakeCredentialSet, snowflakeFqn, snowflakeGcsPubSubWebhookCredentialSet, snowflakeIdentifier, snowflakeObjectRowSchema, snowflakeS3SnsWebhookCredentialSet, sqlBindingValueSchema, sqlBindingsSchema, statementContextSchema, statementResponseSchema, statementStatus, statementStatusCodeSchema, submitStatementInputSchema };
|
package/dist/index.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { i as snowflakeCredentialSet, n as snowflakeAuthModeSchema, r as snowflakeAuthSchema, t as parseSnowflakeCredentials } from "./snowflake.credential-set-DE3gXf-a.mjs";
|
|
2
|
-
import { n as snowflakeGcsPubSubWebhookCredentialSet, r as snowflakeAzureEventGridWebhookCredentialSet, t as snowflakeS3SnsWebhookCredentialSet } from "./snowflake-s3-sns-webhook.credential-set-DzR7oWNK.mjs";
|
|
3
|
-
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";
|
|
4
|
-
import { a as submitStatementInputSchema, i as statementStatusCodeSchema, n as statementResponseSchema, o as partitionResponseSchema, r as statementStatus, t as cancelStatementResponseSchema } from "./statements-BumhMhN4.mjs";
|
|
5
|
-
|
|
6
|
-
export { cancelStatementResponseSchema, columnMetaSchema, parseSnowflakeCredentials, partitionInfoSchema, partitionResponseSchema, resultSetMetaDataSchema, snowflakeAuthModeSchema, snowflakeAuthSchema, snowflakeAzureEventGridWebhookCredentialSet, snowflakeCredentialSet, snowflakeFqn, snowflakeGcsPubSubWebhookCredentialSet, snowflakeIdentifier, snowflakeObjectRowSchema, snowflakeS3SnsWebhookCredentialSet, sqlBindingValueSchema, sqlBindingsSchema, statementContextSchema, statementResponseSchema, statementStatus, statementStatusCodeSchema, submitStatementInputSchema };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { SnowflakeClient } from "../client/index.mjs";
|
|
2
|
-
import { d as HydratedRow, m as ColumnMeta } from "../statements-DJL0qVNA.mjs";
|
|
3
|
-
import { t as OptionMap } from "../sql-options-2k5xQ-oS.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/org-admin/index.d.ts
|
|
6
|
-
interface OrgAdminContext {
|
|
7
|
-
readonly warehouse?: string;
|
|
8
|
-
readonly role?: string;
|
|
9
|
-
}
|
|
10
|
-
interface ListOrganizationAccountsOptions extends OrgAdminContext {
|
|
11
|
-
readonly like?: string;
|
|
12
|
-
}
|
|
13
|
-
interface ListOrganizationAccountsResult {
|
|
14
|
-
readonly columns: readonly ColumnMeta[];
|
|
15
|
-
readonly rows: readonly HydratedRow[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* `SHOW ORGANIZATION ACCOUNTS`. Lists every account in the org (ORGADMIN
|
|
19
|
-
* only).
|
|
20
|
-
*/
|
|
21
|
-
declare function listOrganizationAccounts(client: SnowflakeClient, options?: ListOrganizationAccountsOptions): Promise<ListOrganizationAccountsResult>;
|
|
22
|
-
interface CreateOrganizationAccountOptions extends OrgAdminContext {
|
|
23
|
-
readonly name: string;
|
|
24
|
-
readonly adminName: string;
|
|
25
|
-
readonly adminPassword: string;
|
|
26
|
-
readonly email: string;
|
|
27
|
-
/** `STANDARD`, `ENTERPRISE`, `BUSINESS_CRITICAL`, `VPS`. */
|
|
28
|
-
readonly edition: 'STANDARD' | 'ENTERPRISE' | 'BUSINESS_CRITICAL' | 'VPS';
|
|
29
|
-
/** Snowflake region identifier, e.g. `AWS_US_WEST_2`. */
|
|
30
|
-
readonly region?: string;
|
|
31
|
-
readonly regionGroup?: string;
|
|
32
|
-
readonly firstName?: string;
|
|
33
|
-
readonly lastName?: string;
|
|
34
|
-
readonly mustChangePassword?: boolean;
|
|
35
|
-
readonly comment?: string;
|
|
36
|
-
/** Any other `KEY = value` options the org admin wants to forward. */
|
|
37
|
-
readonly options?: OptionMap;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* `CREATE ORGANIZATION ACCOUNT <name>
|
|
41
|
-
* ADMIN_NAME = '...' ADMIN_PASSWORD = '...' EMAIL = '...'
|
|
42
|
-
* EDITION = '...' [REGION = '...'] [REGION_GROUP = '...']
|
|
43
|
-
* [FIRST_NAME = '...'] [LAST_NAME = '...']
|
|
44
|
-
* [MUST_CHANGE_PASSWORD = TRUE|FALSE]
|
|
45
|
-
* [COMMENT = '...']`
|
|
46
|
-
*/
|
|
47
|
-
declare function createOrganizationAccount(client: SnowflakeClient, options: CreateOrganizationAccountOptions): Promise<void>;
|
|
48
|
-
interface AlterAccountOptions extends OrgAdminContext {
|
|
49
|
-
/**
|
|
50
|
-
* Target account name — if omitted, the statement targets the current
|
|
51
|
-
* account (`ALTER ACCOUNT SET ...`). When provided, Snowflake runs it as
|
|
52
|
-
* `ALTER ACCOUNT <name> SET ...` (ORGADMIN scope).
|
|
53
|
-
*/
|
|
54
|
-
readonly name?: string;
|
|
55
|
-
readonly ifExists?: boolean;
|
|
56
|
-
readonly set?: OptionMap;
|
|
57
|
-
readonly unset?: readonly string[];
|
|
58
|
-
readonly setResourceMonitor?: string;
|
|
59
|
-
readonly unsetResourceMonitor?: boolean;
|
|
60
|
-
readonly comment?: string;
|
|
61
|
-
}
|
|
62
|
-
declare function alterAccount(client: SnowflakeClient, options: AlterAccountOptions): Promise<void>;
|
|
63
|
-
interface EnableAccountFeatureOptions extends OrgAdminContext {
|
|
64
|
-
/** Feature parameter name, e.g. `ENABLE_UNREDACTED_QUERY_SYNTAX_ERROR`. */
|
|
65
|
-
readonly feature: string;
|
|
66
|
-
/** When `false`, emits `SET <FEATURE> = FALSE` (i.e., disables it). */
|
|
67
|
-
readonly enabled?: boolean;
|
|
68
|
-
readonly ifExists?: boolean;
|
|
69
|
-
/** Scope the change to a specific account (requires ORGADMIN). */
|
|
70
|
-
readonly name?: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Generic `ALTER ACCOUNT SET <FEATURE> = TRUE|FALSE` wrapper. Snowflake
|
|
74
|
-
* exposes a growing set of account-level boolean parameters; this helper
|
|
75
|
-
* keeps the pattern uniform for workflow authors without embedding the
|
|
76
|
-
* full (ever-changing) feature catalogue in the package.
|
|
77
|
-
*/
|
|
78
|
-
declare function enableAccountFeature(client: SnowflakeClient, options: EnableAccountFeatureOptions): Promise<void>;
|
|
79
|
-
//#endregion
|
|
80
|
-
export { AlterAccountOptions, CreateOrganizationAccountOptions, EnableAccountFeatureOptions, ListOrganizationAccountsOptions, ListOrganizationAccountsResult, OrgAdminContext, alterAccount, createOrganizationAccount, enableAccountFeature, listOrganizationAccounts };
|
package/dist/org-admin/index.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { executeSql } from "../sql/index.mjs";
|
|
2
|
-
import { a as quoteLiteral, i as quoteIdentifier, r as likeClause } from "../sql-safety-BZpAPsq6.mjs";
|
|
3
|
-
import { t as formatOptions } from "../sql-options-D6GEa21F.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/org-admin/index.ts
|
|
6
|
-
/**
|
|
7
|
-
* `SHOW ORGANIZATION ACCOUNTS`. Lists every account in the org (ORGADMIN
|
|
8
|
-
* only).
|
|
9
|
-
*/
|
|
10
|
-
async function listOrganizationAccounts(client, options = {}) {
|
|
11
|
-
const result = await executeSql(client, {
|
|
12
|
-
statement: `SHOW ORGANIZATION ACCOUNTS${likeClause(options.like)}`,
|
|
13
|
-
warehouse: options.warehouse,
|
|
14
|
-
role: options.role
|
|
15
|
-
});
|
|
16
|
-
return {
|
|
17
|
-
columns: result.columns,
|
|
18
|
-
rows: result.rows
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* `CREATE ORGANIZATION ACCOUNT <name>
|
|
23
|
-
* ADMIN_NAME = '...' ADMIN_PASSWORD = '...' EMAIL = '...'
|
|
24
|
-
* EDITION = '...' [REGION = '...'] [REGION_GROUP = '...']
|
|
25
|
-
* [FIRST_NAME = '...'] [LAST_NAME = '...']
|
|
26
|
-
* [MUST_CHANGE_PASSWORD = TRUE|FALSE]
|
|
27
|
-
* [COMMENT = '...']`
|
|
28
|
-
*/
|
|
29
|
-
async function createOrganizationAccount(client, options) {
|
|
30
|
-
const parts = [
|
|
31
|
-
`ADMIN_NAME = ${quoteLiteral(options.adminName)}`,
|
|
32
|
-
`ADMIN_PASSWORD = ${quoteLiteral(options.adminPassword)}`,
|
|
33
|
-
`EMAIL = ${quoteLiteral(options.email)}`,
|
|
34
|
-
`EDITION = ${quoteLiteral(options.edition)}`
|
|
35
|
-
];
|
|
36
|
-
if (options.region) parts.push(`REGION = ${quoteLiteral(options.region)}`);
|
|
37
|
-
if (options.regionGroup) parts.push(`REGION_GROUP = ${quoteLiteral(options.regionGroup)}`);
|
|
38
|
-
if (options.firstName) parts.push(`FIRST_NAME = ${quoteLiteral(options.firstName)}`);
|
|
39
|
-
if (options.lastName) parts.push(`LAST_NAME = ${quoteLiteral(options.lastName)}`);
|
|
40
|
-
if (options.mustChangePassword !== void 0) parts.push(`MUST_CHANGE_PASSWORD = ${options.mustChangePassword ? "TRUE" : "FALSE"}`);
|
|
41
|
-
if (options.comment) parts.push(`COMMENT = ${quoteLiteral(options.comment)}`);
|
|
42
|
-
if (options.options && Object.keys(options.options).length > 0) parts.push(formatOptions(options.options));
|
|
43
|
-
await executeSql(client, {
|
|
44
|
-
statement: `CREATE ORGANIZATION ACCOUNT ${quoteIdentifier(options.name)} ${parts.join(" ")}`,
|
|
45
|
-
warehouse: options.warehouse,
|
|
46
|
-
role: options.role
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function alterAccount(client, options) {
|
|
50
|
-
let tail;
|
|
51
|
-
if (options.setResourceMonitor !== void 0) tail = `SET RESOURCE_MONITOR = ${quoteIdentifier(options.setResourceMonitor)}`;
|
|
52
|
-
else if (options.unsetResourceMonitor) tail = "UNSET RESOURCE_MONITOR";
|
|
53
|
-
else if (options.set && Object.keys(options.set).length > 0) tail = `SET ${formatOptions(options.set)}`;
|
|
54
|
-
else if (options.unset && options.unset.length > 0) tail = `UNSET ${options.unset.map((k) => k.toUpperCase()).join(", ")}`;
|
|
55
|
-
else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
|
|
56
|
-
else throw new Error("alterAccount requires one of: set / unset / setResourceMonitor / unsetResourceMonitor / comment");
|
|
57
|
-
await executeSql(client, {
|
|
58
|
-
statement: `ALTER ACCOUNT${options.ifExists ? " IF EXISTS" : ""}${options.name ? ` ${quoteIdentifier(options.name)}` : ""} ${tail}`,
|
|
59
|
-
warehouse: options.warehouse,
|
|
60
|
-
role: options.role
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Generic `ALTER ACCOUNT SET <FEATURE> = TRUE|FALSE` wrapper. Snowflake
|
|
65
|
-
* exposes a growing set of account-level boolean parameters; this helper
|
|
66
|
-
* keeps the pattern uniform for workflow authors without embedding the
|
|
67
|
-
* full (ever-changing) feature catalogue in the package.
|
|
68
|
-
*/
|
|
69
|
-
async function enableAccountFeature(client, options) {
|
|
70
|
-
const enabled = options.enabled !== false;
|
|
71
|
-
await executeSql(client, {
|
|
72
|
-
statement: `ALTER ACCOUNT${options.ifExists ? " IF EXISTS" : ""}${options.name ? ` ${quoteIdentifier(options.name)}` : ""} SET ${options.feature.toUpperCase()} = ${enabled ? "TRUE" : "FALSE"}`,
|
|
73
|
-
warehouse: options.warehouse,
|
|
74
|
-
role: options.role
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
export { alterAccount, createOrganizationAccount, enableAccountFeature, listOrganizationAccounts };
|
package/dist/pipes/index.d.mts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { SnowflakeClient } from "../client/index.mjs";
|
|
2
|
-
import { d as HydratedRow } from "../statements-DJL0qVNA.mjs";
|
|
3
|
-
import { CatalogResult, ShowScopedOptions, showPipes } from "../catalog/index.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/pipes/index.d.ts
|
|
6
|
-
interface PipeRef {
|
|
7
|
-
readonly database?: string;
|
|
8
|
-
readonly schema?: string;
|
|
9
|
-
readonly name: string;
|
|
10
|
-
}
|
|
11
|
-
interface PipeContext {
|
|
12
|
-
readonly warehouse?: string;
|
|
13
|
-
readonly role?: string;
|
|
14
|
-
}
|
|
15
|
-
interface CreatePipeOptions extends PipeRef, PipeContext {
|
|
16
|
-
readonly orReplace?: boolean;
|
|
17
|
-
readonly ifNotExists?: boolean;
|
|
18
|
-
readonly autoIngest?: boolean;
|
|
19
|
-
/** S3 SNS topic ARN (AUTO_INGEST buckets sending SNS notifications). */
|
|
20
|
-
readonly awsSnsTopic?: string;
|
|
21
|
-
/** Notification integration for GCS / Azure Event Grid ingest. */
|
|
22
|
-
readonly integration?: string;
|
|
23
|
-
/** Notification integration that receives ERRORS (Snowflake error-integration object). */
|
|
24
|
-
readonly errorIntegration?: string;
|
|
25
|
-
readonly comment?: string;
|
|
26
|
-
/** The `COPY INTO ...` body that defines what this pipe loads. */
|
|
27
|
-
readonly copyStatement: string;
|
|
28
|
-
}
|
|
29
|
-
declare function createPipe(client: SnowflakeClient, options: CreatePipeOptions): Promise<void>;
|
|
30
|
-
interface AlterPipeOptions extends PipeRef, PipeContext {
|
|
31
|
-
readonly setPipeExecutionPaused?: boolean;
|
|
32
|
-
readonly comment?: string;
|
|
33
|
-
readonly refresh?: {
|
|
34
|
-
readonly prefix?: string;
|
|
35
|
-
readonly modifiedAfter?: string;
|
|
36
|
-
};
|
|
37
|
-
readonly rename?: PipeRef;
|
|
38
|
-
readonly unset?: readonly string[];
|
|
39
|
-
}
|
|
40
|
-
declare function alterPipe(client: SnowflakeClient, options: AlterPipeOptions): Promise<void>;
|
|
41
|
-
interface DropPipeOptions extends PipeRef, PipeContext {
|
|
42
|
-
readonly ifExists?: boolean;
|
|
43
|
-
}
|
|
44
|
-
declare function dropPipe(client: SnowflakeClient, options: DropPipeOptions): Promise<void>;
|
|
45
|
-
interface DescribePipeOptions extends PipeRef, PipeContext {}
|
|
46
|
-
declare function describePipe(client: SnowflakeClient, options: DescribePipeOptions): Promise<readonly HydratedRow[]>;
|
|
47
|
-
/** Convenience for `ALTER PIPE name REFRESH ...`. */
|
|
48
|
-
declare function refreshPipe(client: SnowflakeClient, options: PipeRef & PipeContext & {
|
|
49
|
-
readonly prefix?: string;
|
|
50
|
-
readonly modifiedAfter?: string;
|
|
51
|
-
}): Promise<void>;
|
|
52
|
-
interface SnowpipeInsertFile {
|
|
53
|
-
readonly path: string;
|
|
54
|
-
readonly size?: number | bigint;
|
|
55
|
-
}
|
|
56
|
-
interface InsertFilesOptions extends PipeRef {
|
|
57
|
-
readonly files: readonly SnowpipeInsertFile[];
|
|
58
|
-
readonly requestId?: string;
|
|
59
|
-
}
|
|
60
|
-
interface InsertFilesResponse {
|
|
61
|
-
readonly requestId: string;
|
|
62
|
-
/** Server-reported ingest batch id (`pipe` field per Snowflake docs). */
|
|
63
|
-
readonly pipe?: string;
|
|
64
|
-
readonly responseCode?: string;
|
|
65
|
-
readonly message?: string;
|
|
66
|
-
readonly skippedFiles?: readonly {
|
|
67
|
-
readonly path: string;
|
|
68
|
-
readonly reason?: string;
|
|
69
|
-
}[];
|
|
70
|
-
}
|
|
71
|
-
declare function insertFiles(client: SnowflakeClient, options: InsertFilesOptions): Promise<InsertFilesResponse>;
|
|
72
|
-
interface InsertReportOptions extends PipeRef {
|
|
73
|
-
readonly beginMark?: string;
|
|
74
|
-
readonly requestId?: string;
|
|
75
|
-
}
|
|
76
|
-
interface InsertReportResponse {
|
|
77
|
-
readonly pipe?: string;
|
|
78
|
-
readonly completeResult?: boolean;
|
|
79
|
-
readonly nextBeginMark?: string;
|
|
80
|
-
readonly files?: readonly {
|
|
81
|
-
readonly path: string;
|
|
82
|
-
readonly stageLocation?: string;
|
|
83
|
-
readonly fileSize?: number;
|
|
84
|
-
readonly timeReceived?: string;
|
|
85
|
-
readonly lastInsertTime?: string;
|
|
86
|
-
readonly rowsInserted?: number;
|
|
87
|
-
readonly rowsParsed?: number;
|
|
88
|
-
readonly errorsSeen?: number;
|
|
89
|
-
readonly errorLimit?: number;
|
|
90
|
-
readonly firstError?: string;
|
|
91
|
-
readonly status?: string;
|
|
92
|
-
}[];
|
|
93
|
-
}
|
|
94
|
-
declare function insertReport(client: SnowflakeClient, options: InsertReportOptions): Promise<InsertReportResponse>;
|
|
95
|
-
interface LoadHistoryScanOptions extends PipeRef {
|
|
96
|
-
readonly startTimeInclusive: string;
|
|
97
|
-
readonly endTimeExclusive: string;
|
|
98
|
-
readonly requestId?: string;
|
|
99
|
-
}
|
|
100
|
-
interface LoadHistoryScanResponse {
|
|
101
|
-
readonly pipe?: string;
|
|
102
|
-
readonly completeResult?: boolean;
|
|
103
|
-
readonly files?: readonly {
|
|
104
|
-
readonly path: string;
|
|
105
|
-
readonly stageLocation?: string;
|
|
106
|
-
readonly fileSize?: number;
|
|
107
|
-
readonly timeReceived?: string;
|
|
108
|
-
readonly lastInsertTime?: string;
|
|
109
|
-
readonly rowsInserted?: number;
|
|
110
|
-
readonly rowsParsed?: number;
|
|
111
|
-
readonly errorsSeen?: number;
|
|
112
|
-
readonly errorLimit?: number;
|
|
113
|
-
readonly firstError?: string;
|
|
114
|
-
readonly status?: string;
|
|
115
|
-
}[];
|
|
116
|
-
}
|
|
117
|
-
declare function loadHistoryScan(client: SnowflakeClient, options: LoadHistoryScanOptions): Promise<LoadHistoryScanResponse>;
|
|
118
|
-
//#endregion
|
|
119
|
-
export { AlterPipeOptions, type CatalogResult, CreatePipeOptions, DescribePipeOptions, DropPipeOptions, InsertFilesOptions, InsertFilesResponse, InsertReportOptions, InsertReportResponse, LoadHistoryScanOptions, LoadHistoryScanResponse, PipeContext, PipeRef, type ShowScopedOptions, SnowpipeInsertFile, alterPipe, createPipe, describePipe, dropPipe, insertFiles, insertReport, loadHistoryScan, refreshPipe, showPipes };
|
package/dist/pipes/index.mjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { executeSql } from "../sql/index.mjs";
|
|
2
|
-
import { a as quoteLiteral, i as quoteIdentifier, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
|
|
3
|
-
import { showPipes } from "../catalog/index.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/pipes/index.ts
|
|
6
|
-
function pipeFqn(ref) {
|
|
7
|
-
return buildFqn(ref.database, ref.schema, ref.name);
|
|
8
|
-
}
|
|
9
|
-
function pipeRestPath(ref, required) {
|
|
10
|
-
if (required && (!ref.database || !ref.schema)) throw new Error("Snowpipe REST requires fully-qualified database.schema.pipe (provide `database` and `schema`)");
|
|
11
|
-
return [
|
|
12
|
-
ref.database,
|
|
13
|
-
ref.schema,
|
|
14
|
-
ref.name
|
|
15
|
-
].filter((segment) => segment !== void 0 && segment.length > 0).join(".");
|
|
16
|
-
}
|
|
17
|
-
async function createPipe(client, options) {
|
|
18
|
-
const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""} PIPE${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
|
|
19
|
-
const auto = options.autoIngest ? " AUTO_INGEST = TRUE" : "";
|
|
20
|
-
const sns = options.awsSnsTopic ? ` AWS_SNS_TOPIC = ${quoteLiteral(options.awsSnsTopic)}` : "";
|
|
21
|
-
const integration = options.integration ? ` INTEGRATION = ${quoteLiteral(options.integration)}` : "";
|
|
22
|
-
const errorIntegration = options.errorIntegration ? ` ERROR_INTEGRATION = ${quoteIdentifier(options.errorIntegration)}` : "";
|
|
23
|
-
const comment = options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : "";
|
|
24
|
-
await executeSql(client, {
|
|
25
|
-
statement: `${prefix} ${pipeFqn(options)}${auto}${sns}${integration}${errorIntegration}${comment} AS ${options.copyStatement}`,
|
|
26
|
-
warehouse: options.warehouse,
|
|
27
|
-
role: options.role
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async function alterPipe(client, options) {
|
|
31
|
-
let tail;
|
|
32
|
-
if (options.rename) tail = `RENAME TO ${pipeFqn(options.rename)}`;
|
|
33
|
-
else if (options.refresh) tail = `REFRESH${options.refresh.prefix ? ` PREFIX = ${quoteLiteral(options.refresh.prefix)}` : ""}${options.refresh.modifiedAfter ? ` MODIFIED_AFTER = ${quoteLiteral(options.refresh.modifiedAfter)}` : ""}`;
|
|
34
|
-
else if (options.setPipeExecutionPaused !== void 0) tail = `SET PIPE_EXECUTION_PAUSED = ${options.setPipeExecutionPaused ? "TRUE" : "FALSE"}`;
|
|
35
|
-
else if (options.comment !== void 0) tail = `SET COMMENT = ${quoteLiteral(options.comment)}`;
|
|
36
|
-
else if (options.unset && options.unset.length > 0) tail = `UNSET ${options.unset.map((k) => k.toUpperCase()).join(", ")}`;
|
|
37
|
-
else throw new Error("alterPipe requires one of: rename / refresh / setPipeExecutionPaused / comment / unset");
|
|
38
|
-
await executeSql(client, {
|
|
39
|
-
statement: `ALTER PIPE ${pipeFqn(options)} ${tail}`,
|
|
40
|
-
warehouse: options.warehouse,
|
|
41
|
-
role: options.role
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async function dropPipe(client, options) {
|
|
45
|
-
await executeSql(client, {
|
|
46
|
-
statement: `DROP PIPE${options.ifExists ? " IF EXISTS" : ""} ${pipeFqn(options)}`,
|
|
47
|
-
warehouse: options.warehouse,
|
|
48
|
-
role: options.role
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
async function describePipe(client, options) {
|
|
52
|
-
return (await executeSql(client, {
|
|
53
|
-
statement: `DESCRIBE PIPE ${pipeFqn(options)}`,
|
|
54
|
-
warehouse: options.warehouse,
|
|
55
|
-
role: options.role
|
|
56
|
-
})).rows;
|
|
57
|
-
}
|
|
58
|
-
/** Convenience for `ALTER PIPE name REFRESH ...`. */
|
|
59
|
-
async function refreshPipe(client, options) {
|
|
60
|
-
await alterPipe(client, {
|
|
61
|
-
...options,
|
|
62
|
-
refresh: {
|
|
63
|
-
prefix: options.prefix,
|
|
64
|
-
modifiedAfter: options.modifiedAfter
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
async function insertFiles(client, options) {
|
|
69
|
-
if (options.files.length === 0) throw new Error("insertFiles requires at least one file");
|
|
70
|
-
const path = `/v1/data/pipes/${pipeRestPath(options, true)}/insertFiles`;
|
|
71
|
-
const body = { files: options.files.map((f) => ({
|
|
72
|
-
path: f.path,
|
|
73
|
-
...f.size !== void 0 ? { size: typeof f.size === "bigint" ? Number(f.size) : f.size } : {}
|
|
74
|
-
})) };
|
|
75
|
-
return client.request(path, {
|
|
76
|
-
method: "POST",
|
|
77
|
-
body,
|
|
78
|
-
requestId: options.requestId,
|
|
79
|
-
query: options.requestId ? { requestId: options.requestId } : void 0
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async function insertReport(client, options) {
|
|
83
|
-
const path = `/v1/data/pipes/${pipeRestPath(options, true)}/insertReport`;
|
|
84
|
-
const query = {};
|
|
85
|
-
if (options.beginMark) query.beginMark = options.beginMark;
|
|
86
|
-
if (options.requestId) query.requestId = options.requestId;
|
|
87
|
-
return client.request(path, {
|
|
88
|
-
method: "GET",
|
|
89
|
-
query
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
async function loadHistoryScan(client, options) {
|
|
93
|
-
const path = `/v1/data/pipes/${pipeRestPath(options, true)}/loadHistoryScan`;
|
|
94
|
-
const query = {
|
|
95
|
-
startTimeInclusive: options.startTimeInclusive,
|
|
96
|
-
endTimeExclusive: options.endTimeExclusive
|
|
97
|
-
};
|
|
98
|
-
if (options.requestId) query.requestId = options.requestId;
|
|
99
|
-
return client.request(path, {
|
|
100
|
-
method: "GET",
|
|
101
|
-
query
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
//#endregion
|
|
106
|
-
export { alterPipe, createPipe, describePipe, dropPipe, insertFiles, insertReport, loadHistoryScan, refreshPipe, showPipes };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { SnowflakeClient } from "../client/index.mjs";
|
|
2
|
-
import { d as HydratedRow, v as SqlBinding } from "../statements-DJL0qVNA.mjs";
|
|
3
|
-
import { ExecuteSqlResult } from "../sql/index.mjs";
|
|
4
|
-
import { t as OptionMap } from "../sql-options-2k5xQ-oS.mjs";
|
|
5
|
-
import { CatalogResult, ShowScopedOptions, showProcedures } from "../catalog/index.mjs";
|
|
6
|
-
import { RowValue } from "../rows/index.mjs";
|
|
7
|
-
|
|
8
|
-
//#region src/procedures/index.d.ts
|
|
9
|
-
interface ProcedureRef {
|
|
10
|
-
readonly database?: string;
|
|
11
|
-
readonly schema?: string;
|
|
12
|
-
readonly name: string;
|
|
13
|
-
}
|
|
14
|
-
interface ProcedureContext {
|
|
15
|
-
readonly warehouse?: string;
|
|
16
|
-
readonly role?: string;
|
|
17
|
-
}
|
|
18
|
-
interface ProcedureArgument {
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly type: string;
|
|
21
|
-
readonly defaultExpression?: string;
|
|
22
|
-
}
|
|
23
|
-
type ProcedureLanguage = 'SQL' | 'JAVASCRIPT' | 'PYTHON' | 'JAVA' | 'SCALA';
|
|
24
|
-
type ExecuteAs = 'CALLER' | 'OWNER';
|
|
25
|
-
interface CreateProcedureOptions extends ProcedureRef, ProcedureContext {
|
|
26
|
-
readonly orReplace?: boolean;
|
|
27
|
-
readonly ifNotExists?: boolean;
|
|
28
|
-
readonly secure?: boolean;
|
|
29
|
-
readonly arguments?: readonly ProcedureArgument[];
|
|
30
|
-
readonly returns: string;
|
|
31
|
-
readonly language?: ProcedureLanguage;
|
|
32
|
-
readonly executeAs?: ExecuteAs;
|
|
33
|
-
/** Additional keywords: `STRICT`, `IMMUTABLE`, `VOLATILE`, etc. */
|
|
34
|
-
readonly modifiers?: readonly string[];
|
|
35
|
-
/** Language-specific options: `RUNTIME_VERSION`, `PACKAGES`, `HANDLER`, `IMPORTS`. */
|
|
36
|
-
readonly options?: OptionMap;
|
|
37
|
-
readonly comment?: string;
|
|
38
|
-
readonly as: string;
|
|
39
|
-
readonly dollarQuotedBody?: boolean;
|
|
40
|
-
}
|
|
41
|
-
declare function createProcedure(client: SnowflakeClient, options: CreateProcedureOptions): Promise<void>;
|
|
42
|
-
interface DropProcedureOptions extends ProcedureRef, ProcedureContext {
|
|
43
|
-
readonly ifExists?: boolean;
|
|
44
|
-
readonly arguments?: readonly ProcedureArgument[];
|
|
45
|
-
}
|
|
46
|
-
declare function dropProcedure(client: SnowflakeClient, options: DropProcedureOptions): Promise<void>;
|
|
47
|
-
interface DescribeProcedureOptions extends ProcedureRef, ProcedureContext {
|
|
48
|
-
readonly arguments?: readonly ProcedureArgument[];
|
|
49
|
-
}
|
|
50
|
-
declare function describeProcedure(client: SnowflakeClient, options: DescribeProcedureOptions): Promise<readonly HydratedRow[]>;
|
|
51
|
-
interface CallProcedureOptions extends ProcedureRef, ProcedureContext {
|
|
52
|
-
/** Positional arguments — every value flows through SQL API bindings (`?` placeholders). */
|
|
53
|
-
readonly arguments?: readonly RowValue[];
|
|
54
|
-
/** Pre-built bindings map (takes precedence over `arguments`). */
|
|
55
|
-
readonly bindings?: Readonly<Record<string, SqlBinding>>;
|
|
56
|
-
/** Raw SQL expression list when you need to pass a named function, subquery, or bind-unfriendly value. */
|
|
57
|
-
readonly rawArguments?: readonly string[];
|
|
58
|
-
}
|
|
59
|
-
declare function callProcedure(client: SnowflakeClient, options: CallProcedureOptions): Promise<ExecuteSqlResult<HydratedRow | readonly unknown[]>>;
|
|
60
|
-
//#endregion
|
|
61
|
-
export { CallProcedureOptions, type CatalogResult, CreateProcedureOptions, DescribeProcedureOptions, DropProcedureOptions, ExecuteAs, ProcedureArgument, ProcedureContext, ProcedureLanguage, ProcedureRef, type ShowScopedOptions, callProcedure, createProcedure, describeProcedure, dropProcedure, showProcedures };
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { executeSql } from "../sql/index.mjs";
|
|
2
|
-
import { a as quoteLiteral, t as buildFqn } from "../sql-safety-BZpAPsq6.mjs";
|
|
3
|
-
import { BindingBuilder } from "../rows/index.mjs";
|
|
4
|
-
import { t as formatOptions } from "../sql-options-D6GEa21F.mjs";
|
|
5
|
-
import { showProcedures } from "../catalog/index.mjs";
|
|
6
|
-
|
|
7
|
-
//#region src/procedures/index.ts
|
|
8
|
-
function renderArguments(args) {
|
|
9
|
-
if (!args || args.length === 0) return "()";
|
|
10
|
-
return `(${args.map((a) => {
|
|
11
|
-
const suffix = a.defaultExpression ? ` DEFAULT ${a.defaultExpression}` : "";
|
|
12
|
-
return `${a.name} ${a.type.toUpperCase()}${suffix}`;
|
|
13
|
-
}).join(", ")})`;
|
|
14
|
-
}
|
|
15
|
-
function renderArgumentTypes(args) {
|
|
16
|
-
if (!args || args.length === 0) return "()";
|
|
17
|
-
return `(${args.map((a) => a.type.toUpperCase()).join(", ")})`;
|
|
18
|
-
}
|
|
19
|
-
function renderBody(body, forceDollarQuoted, language) {
|
|
20
|
-
if (forceDollarQuoted ?? (language !== void 0 && language !== "SQL")) {
|
|
21
|
-
if (body.includes("$$")) throw new Error("Procedure body contains \"$$\"; cannot safely dollar-quote.");
|
|
22
|
-
return `$$${body}$$`;
|
|
23
|
-
}
|
|
24
|
-
return body;
|
|
25
|
-
}
|
|
26
|
-
async function createProcedure(client, options) {
|
|
27
|
-
const prefix = `CREATE${options.orReplace ? " OR REPLACE" : ""}${options.secure ? " SECURE" : ""} PROCEDURE${options.ifNotExists ? " IF NOT EXISTS" : ""}`;
|
|
28
|
-
const args = renderArguments(options.arguments);
|
|
29
|
-
const language = options.language ? ` LANGUAGE ${options.language}` : "";
|
|
30
|
-
const executeAs = options.executeAs ? ` EXECUTE AS ${options.executeAs}` : "";
|
|
31
|
-
const modifiers = options.modifiers && options.modifiers.length > 0 ? ` ${options.modifiers.map((m) => m.toUpperCase()).join(" ")}` : "";
|
|
32
|
-
const body = options.options && Object.keys(options.options).length > 0 ? ` ${formatOptions(options.options)}` : "";
|
|
33
|
-
const comment = options.comment ? ` COMMENT = ${quoteLiteral(options.comment)}` : "";
|
|
34
|
-
const rendered = renderBody(options.as, options.dollarQuotedBody, options.language);
|
|
35
|
-
await executeSql(client, {
|
|
36
|
-
statement: `${prefix} ${buildFqn(options.database, options.schema, options.name)}${args} RETURNS ${options.returns}${language}${executeAs}${modifiers}${body}${comment} AS ${rendered}`,
|
|
37
|
-
warehouse: options.warehouse,
|
|
38
|
-
role: options.role
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
async function dropProcedure(client, options) {
|
|
42
|
-
const fqn = buildFqn(options.database, options.schema, options.name);
|
|
43
|
-
await executeSql(client, {
|
|
44
|
-
statement: `DROP PROCEDURE${options.ifExists ? " IF EXISTS" : ""} ${fqn}${renderArgumentTypes(options.arguments)}`,
|
|
45
|
-
warehouse: options.warehouse,
|
|
46
|
-
role: options.role
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async function describeProcedure(client, options) {
|
|
50
|
-
return (await executeSql(client, {
|
|
51
|
-
statement: `DESCRIBE PROCEDURE ${buildFqn(options.database, options.schema, options.name)}${renderArgumentTypes(options.arguments)}`,
|
|
52
|
-
warehouse: options.warehouse,
|
|
53
|
-
role: options.role
|
|
54
|
-
})).rows;
|
|
55
|
-
}
|
|
56
|
-
async function callProcedure(client, options) {
|
|
57
|
-
const fqn = buildFqn(options.database, options.schema, options.name);
|
|
58
|
-
if (options.rawArguments) return executeSql(client, {
|
|
59
|
-
statement: `CALL ${fqn}(${options.rawArguments.join(", ")})`,
|
|
60
|
-
warehouse: options.warehouse,
|
|
61
|
-
role: options.role,
|
|
62
|
-
bindings: options.bindings
|
|
63
|
-
});
|
|
64
|
-
const builder = new BindingBuilder();
|
|
65
|
-
const placeholders = (options.arguments ?? []).map((a) => builder.add(a));
|
|
66
|
-
const bindings = options.bindings ? {
|
|
67
|
-
...builder.toRecord(),
|
|
68
|
-
...options.bindings
|
|
69
|
-
} : builder.size() > 0 ? builder.toRecord() : void 0;
|
|
70
|
-
return executeSql(client, {
|
|
71
|
-
statement: `CALL ${fqn}(${placeholders.join(", ")})`,
|
|
72
|
-
warehouse: options.warehouse,
|
|
73
|
-
role: options.role,
|
|
74
|
-
bindings
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
export { callProcedure, createProcedure, describeProcedure, dropProcedure, showProcedures };
|
package/dist/results/index.d.mts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { d as HydratedRow, m as ColumnMeta } from "../statements-DJL0qVNA.mjs";
|
|
2
|
-
//#region src/results/index.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* Hydrate a single positional row into an object keyed by column name.
|
|
5
|
-
* Values are coerced per Snowflake type; unknown / unrepresentable values
|
|
6
|
-
* are passed through verbatim.
|
|
7
|
-
*/
|
|
8
|
-
declare function hydrateRow(row: readonly unknown[], columns: readonly ColumnMeta[]): HydratedRow;
|
|
9
|
-
declare function hydrateRows(rows: readonly (readonly unknown[])[], columns: readonly ColumnMeta[]): HydratedRow[];
|
|
10
|
-
/**
|
|
11
|
-
* Coerce a single raw value (already in whatever shape Snowflake sent it
|
|
12
|
-
* over the wire) into the nearest safe JS primitive / object.
|
|
13
|
-
*/
|
|
14
|
-
declare function hydrateValue(raw: unknown, column: ColumnMeta): unknown;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { hydrateRow, hydrateRows, hydrateValue };
|
package/dist/results/index.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
//#region src/results/index.ts
|
|
2
|
-
const MAX_SAFE_INT_AS_STRING = String(Number.MAX_SAFE_INTEGER);
|
|
3
|
-
const MIN_SAFE_INT_AS_STRING = String(Number.MIN_SAFE_INTEGER);
|
|
4
|
-
/**
|
|
5
|
-
* Hydrate a single positional row into an object keyed by column name.
|
|
6
|
-
* Values are coerced per Snowflake type; unknown / unrepresentable values
|
|
7
|
-
* are passed through verbatim.
|
|
8
|
-
*/
|
|
9
|
-
function hydrateRow(row, columns) {
|
|
10
|
-
const hydrated = {};
|
|
11
|
-
for (let i = 0; i < columns.length; i += 1) {
|
|
12
|
-
const column = columns[i];
|
|
13
|
-
if (!column) continue;
|
|
14
|
-
hydrated[column.name] = hydrateValue(row[i], column);
|
|
15
|
-
}
|
|
16
|
-
return hydrated;
|
|
17
|
-
}
|
|
18
|
-
function hydrateRows(rows, columns) {
|
|
19
|
-
const hydrated = [];
|
|
20
|
-
for (const row of rows) hydrated.push(hydrateRow(row, columns));
|
|
21
|
-
return hydrated;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Coerce a single raw value (already in whatever shape Snowflake sent it
|
|
25
|
-
* over the wire) into the nearest safe JS primitive / object.
|
|
26
|
-
*/
|
|
27
|
-
function hydrateValue(raw, column) {
|
|
28
|
-
if (raw === null || raw === void 0) return null;
|
|
29
|
-
const type = column.type.toUpperCase();
|
|
30
|
-
if (typeof raw === "string") return coerceString(raw, type, column);
|
|
31
|
-
return raw;
|
|
32
|
-
}
|
|
33
|
-
function coerceString(raw, type, column) {
|
|
34
|
-
if (type === "BOOLEAN") return raw === "true" || raw === "1";
|
|
35
|
-
if (type === "FIXED") return coerceFixed(raw, column);
|
|
36
|
-
if (type === "REAL") {
|
|
37
|
-
const parsed = Number(raw);
|
|
38
|
-
return Number.isFinite(parsed) ? parsed : raw;
|
|
39
|
-
}
|
|
40
|
-
if (type === "BINARY") return raw;
|
|
41
|
-
if (type === "DATE" || type === "TIME" || type.startsWith("TIMESTAMP")) return raw;
|
|
42
|
-
if (type === "OBJECT" || type === "ARRAY" || type === "VARIANT") try {
|
|
43
|
-
return JSON.parse(raw);
|
|
44
|
-
} catch {
|
|
45
|
-
return raw;
|
|
46
|
-
}
|
|
47
|
-
return raw;
|
|
48
|
-
}
|
|
49
|
-
function coerceFixed(raw, column) {
|
|
50
|
-
if ((column.scale ?? 0) > 0) {
|
|
51
|
-
const parsed = Number(raw);
|
|
52
|
-
return Number.isFinite(parsed) ? parsed : raw;
|
|
53
|
-
}
|
|
54
|
-
if (isSafeInteger(raw)) return Number(raw);
|
|
55
|
-
return raw;
|
|
56
|
-
}
|
|
57
|
-
function isSafeInteger(value) {
|
|
58
|
-
if (!/^-?\d+$/u.test(value)) return false;
|
|
59
|
-
if (value.startsWith("-")) return value.length < MIN_SAFE_INT_AS_STRING.length || value.length === MIN_SAFE_INT_AS_STRING.length && value <= MIN_SAFE_INT_AS_STRING;
|
|
60
|
-
return value.length < MAX_SAFE_INT_AS_STRING.length || value.length === MAX_SAFE_INT_AS_STRING.length && value <= MAX_SAFE_INT_AS_STRING;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { hydrateRow, hydrateRows, hydrateValue };
|