Socket
Socket
Sign inDemoInstall

@clickhouse/client-common

Package Overview
Dependencies
Maintainers
4
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clickhouse/client-common - npm Package Compare versions

Comparing version 0.3.1 to 1.0.0

dist/config.d.ts

80

dist/client.d.ts

@@ -1,66 +0,7 @@

import type { ClickHouseLogLevel, ClickHouseSettings, Connection, ConnectionParams, ConnExecResult, Logger, WithClickHouseSummary } from '@clickhouse/client-common';
import type { BaseClickHouseClientConfigOptions, ClickHouseSettings, ConnExecResult, IsSame, WithClickHouseSummary } from '@clickhouse/client-common';
import { type DataFormat } from '@clickhouse/client-common';
import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
import type { ImplementationDetails } from './config';
import type { ConnPingResult } from './connection';
import type { BaseResultSet } from './result';
export type MakeConnection<Stream> = (params: ConnectionParams) => Connection<Stream>;
export type MakeResultSet<Stream> = (stream: Stream, format: DataFormat, session_id: string) => BaseResultSet<Stream>;
export interface ValuesEncoder<Stream> {
validateInsertValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): void;
/**
* A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
* If values are provided as an array of JSON objects, the function encodes it in place.
* If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
* If values are provided as a raw non-object stream, the function does nothing.
*
* @param values a set of values to send to ClickHouse.
* @param format a format to encode value to.
*/
encodeValues<T = unknown>(values: InsertValues<Stream, T>, format: DataFormat): string | Stream;
}
export type CloseStream<Stream> = (stream: Stream) => Promise<void>;
export interface ClickHouseClientConfigOptions<Stream> {
impl: {
make_connection: MakeConnection<Stream>;
make_result_set: MakeResultSet<Stream>;
values_encoder: ValuesEncoder<Stream>;
close_stream: CloseStream<Stream>;
};
/** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
host?: string;
/** The request timeout in milliseconds. Default value: `30_000`. */
request_timeout?: number;
/** Maximum number of sockets to allow per host. Default value: `10`. */
max_open_connections?: number;
compression?: {
/** `response: true` instructs ClickHouse server to respond with
* compressed response body. Default: true. */
response?: boolean;
/** `request: true` enabled compression on the client request body.
* Default: false. */
request?: boolean;
};
/** The name of the user on whose behalf requests are made.
* Default: 'default'. */
username?: string;
/** The user password. Default: ''. */
password?: string;
/** The name of the application using the JS client.
* Default: empty. */
application?: string;
/** Database name to use. Default value: `default`. */
database?: string;
/** ClickHouse settings to apply to all requests. Default value: {} */
clickhouse_settings?: ClickHouseSettings;
log?: {
/** A class to instantiate a custom logger implementation.
* Default: {@link DefaultLogger} */
LoggerClass?: new () => Logger;
/** Default: OFF */
level?: ClickHouseLogLevel;
};
session_id?: string;
additional_headers?: Record<string, string>;
}
export type BaseClickHouseClientConfigOptions<Stream> = Omit<ClickHouseClientConfigOptions<Stream>, 'impl'>;
export interface BaseQueryParams {

@@ -84,2 +25,10 @@ /** ClickHouse's settings that can be applied on query level. */

}
/** Same parameters as {@link QueryParams}, but with `format` field as a type */
export type QueryParamsWithFormat<Format extends DataFormat> = Omit<QueryParams, 'format'> & {
format?: Format;
};
/** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
* allowing to call all methods with all data shapes variants,
* and avoiding generated types that include all possible DataFormat literal values. */
export type QueryResult<Stream, Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? BaseResultSet<Stream, unknown> : BaseResultSet<Stream, Format>;
export interface ExecParams extends BaseQueryParams {

@@ -137,3 +86,3 @@ /** Statement to execute. */

export declare class ClickHouseClient<Stream = unknown> {
private readonly connectionParams;
private readonly clientClickHouseSettings;
private readonly connection;

@@ -144,4 +93,3 @@ private readonly makeResultSet;

private readonly sessionId?;
constructor(config: ClickHouseClientConfigOptions<Stream>);
private getQueryParams;
constructor(config: BaseClickHouseClientConfigOptions & ImplementationDetails<Stream>);
/**

@@ -152,4 +100,5 @@ * Used for most statements that can have a response, such as SELECT.

* or {@link ClickHouseClient.command} for DDLs.
* Returns an implementation of {@link BaseResultSet}.
*/
query(params: QueryParams): Promise<BaseResultSet<Stream>>;
query<Format extends DataFormat = 'JSON'>(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Stream, Format>>;
/**

@@ -188,3 +137,4 @@ * It should be used for statements that do not have any output,

close(): Promise<void>;
private withClientQueryParams;
}
export {};

@@ -5,5 +5,6 @@ "use strict";

const client_common_1 = require("@clickhouse/client-common");
const config_1 = require("./config");
class ClickHouseClient {
constructor(config) {
Object.defineProperty(this, "connectionParams", {
Object.defineProperty(this, "clientClickHouseSettings", {
enumerable: true,

@@ -44,6 +45,10 @@ configurable: true,

});
this.connectionParams = getConnectionParams(config);
const logger = config?.log?.LoggerClass
? new config.log.LoggerClass()
: new client_common_1.DefaultLogger();
const configWithURL = (0, config_1.prepareConfigWithURL)(config, logger, config.impl.handle_specific_url_params ?? null);
const connectionParams = (0, config_1.getConnectionParams)(configWithURL, logger);
this.clientClickHouseSettings = connectionParams.clickhouse_settings;
this.sessionId = config.session_id;
validateConnectionParams(this.connectionParams);
this.connection = config.impl.make_connection(this.connectionParams);
this.connection = config.impl.make_connection(configWithURL, connectionParams);
this.makeResultSet = config.impl.make_result_set;

@@ -53,14 +58,2 @@ this.valuesEncoder = config.impl.values_encoder;

}
getQueryParams(params) {
return {
clickhouse_settings: {
...this.connectionParams.clickhouse_settings,
...params.clickhouse_settings,
},
query_params: params.query_params,
abort_signal: params.abort_signal,
query_id: params.query_id,
session_id: this.sessionId,
};
}
/**

@@ -71,2 +64,3 @@ * Used for most statements that can have a response, such as SELECT.

* or {@link ClickHouseClient.command} for DDLs.
* Returns an implementation of {@link BaseResultSet}.
*/

@@ -78,3 +72,3 @@ async query(params) {

query,
...this.getQueryParams(params),
...this.withClientQueryParams(params),
});

@@ -104,3 +98,3 @@ return this.makeResultSet(stream, format, query_id);

query,
...this.getQueryParams(params),
...this.withClientQueryParams(params),
});

@@ -125,3 +119,3 @@ }

values: this.valuesEncoder.encodeValues(params.values, format),
...this.getQueryParams(params),
...this.withClientQueryParams(params),
});

@@ -145,2 +139,14 @@ return { ...result, executed: true };

}
withClientQueryParams(params) {
return {
clickhouse_settings: {
...this.clientClickHouseSettings,
...params.clickhouse_settings,
},
query_params: params.query_params,
abort_signal: params.abort_signal,
query_id: params.query_id,
session_id: this.sessionId,
};
}
}

@@ -166,35 +172,2 @@ exports.ClickHouseClient = ClickHouseClient;

}
function validateConnectionParams({ url }) {
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error(`Only http(s) protocol is supported, but given: [${url.protocol}]`);
}
}
function createUrl(host) {
try {
return new URL(host);
}
catch (err) {
throw new Error('Configuration parameter "host" contains malformed url.');
}
}
function getConnectionParams(config) {
return {
application_id: config.application,
url: createUrl(config.host ?? 'http://localhost:8123'),
request_timeout: config.request_timeout ?? 30000,
max_open_connections: config.max_open_connections ?? 10,
compression: {
decompress_response: config.compression?.response ?? true,
compress_request: config.compression?.request ?? false,
},
username: config.username ?? 'default',
password: config.password ?? '',
database: config.database ?? 'default',
clickhouse_settings: config.clickhouse_settings ?? {},
log_writer: new client_common_1.LogWriter(config?.log?.LoggerClass
? new config.log.LoggerClass()
: new client_common_1.DefaultLogger(), 'Connection', config.log?.level),
additional_headers: config.additional_headers,
};
}
function isInsertColumnsExcept(obj) {

@@ -201,0 +174,0 @@ return (obj !== undefined &&

@@ -8,6 +8,3 @@ import type { WithClickHouseSummary } from './clickhouse_types';

max_open_connections: number;
compression: {
decompress_response: boolean;
compress_request: boolean;
};
compression: CompressionSettings;
username: string;

@@ -18,5 +15,12 @@ password: string;

log_writer: LogWriter;
keep_alive: {
enabled: boolean;
};
application_id?: string;
additional_headers?: Record<string, string>;
http_headers?: Record<string, string>;
}
export interface CompressionSettings {
decompress_response: boolean;
compress_request: boolean;
}
export interface ConnBaseQueryParams {

@@ -23,0 +27,0 @@ query: string;

@@ -1,17 +0,34 @@

declare const supportedJSONFormats: readonly ["JSON", "JSONStrings", "JSONCompact", "JSONCompactStrings", "JSONColumnsWithMetadata", "JSONObjectEachRow", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
declare const streamableJSONFormats: readonly ["JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
declare const recordsJSONFormats: readonly ["JSONObjectEachRow"];
declare const singleDocumentJSONFormats: readonly ["JSON", "JSONStrings", "JSONCompact", "JSONCompactStrings", "JSONColumnsWithMetadata"];
declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes", "Parquet"];
export type JSONDataFormat = (typeof supportedJSONFormats)[number];
/** CSV, TSV, etc. - can be streamed, but cannot be decoded as JSON. */
export type RawDataFormat = (typeof supportedRawFormats)[number];
/** Each row is returned as a separate JSON object or an array, and these formats can be streamed. */
export type StreamableJSONDataFormat = (typeof streamableJSONFormats)[number];
/** Returned as a single {@link ResponseJSON} object, cannot be streamed. */
export type SingleDocumentJSONFormat = (typeof singleDocumentJSONFormats)[number];
/** Returned as a single object { row_1: T, row_2: T, ...} <br/>
* (i.e. Record<string, T>), cannot be streamed. */
export type RecordsJSONFormat = (typeof recordsJSONFormats)[number];
/** All allowed JSON formats, whether streamable or not. */
export type JSONDataFormat = StreamableJSONDataFormat | SingleDocumentJSONFormat | RecordsJSONFormat;
/** Data formats that are currently supported by the client. <br/>
* This is a union of the following types:<br/>
* * {@link JSONDataFormat}
* * {@link RawDataFormat}
* * {@link StreamableDataFormat}
* * {@link StreamableJSONDataFormat}
* * {@link SingleDocumentJSONFormat}
* * {@link RecordsJSONFormat}
* @see https://clickhouse.com/docs/en/interfaces/formats */
export type DataFormat = JSONDataFormat | RawDataFormat;
declare const streamableFormat: readonly ["JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes", "CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes", "Parquet"];
type StreamableDataFormat = (typeof streamableFormat)[number];
/** All data formats that can be streamed, whether it can be decoded as JSON or not. */
export type StreamableDataFormat = (typeof streamableFormat)[number];
export declare function isNotStreamableJSONFamily(format: DataFormat): format is SingleDocumentJSONFormat;
export declare function isStreamableJSONFamily(format: DataFormat): format is StreamableJSONDataFormat;
export declare function isSupportedRawFormat(dataFormat: DataFormat): boolean;
export declare function validateStreamFormat(format: any): format is StreamableDataFormat;
/**
* Decodes a string in a ClickHouse format into a plain JavaScript object or an array of objects.
* @param text a string in a ClickHouse data format
* @param format One of the supported formats: https://clickhouse.com/docs/en/interfaces/formats/
*/
export declare function decode(text: string, format: DataFormat): any;
/**
* Encodes a single row of values into a string in a JSON format acceptable by ClickHouse.

@@ -18,0 +35,0 @@ * @param value a single value to encode.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeJSON = exports.decode = exports.validateStreamFormat = exports.isSupportedRawFormat = void 0;
exports.encodeJSON = exports.validateStreamFormat = exports.isSupportedRawFormat = exports.isStreamableJSONFamily = exports.isNotStreamableJSONFamily = void 0;
const streamableJSONFormats = [

@@ -14,2 +14,3 @@ 'JSONEachRow',

];
const recordsJSONFormats = ['JSONObjectEachRow'];
const singleDocumentJSONFormats = [

@@ -21,5 +22,5 @@ 'JSON',

'JSONColumnsWithMetadata',
'JSONObjectEachRow',
];
const supportedJSONFormats = [
...recordsJSONFormats,
...singleDocumentJSONFormats,

@@ -41,3 +42,2 @@ ...streamableJSONFormats,

];
// TODO add others formats
const streamableFormat = [

@@ -48,9 +48,10 @@ ...streamableJSONFormats,

function isNotStreamableJSONFamily(format) {
// @ts-expect-error JSON is not assignable to notStreamableJSONFormats
return singleDocumentJSONFormats.includes(format);
return (singleDocumentJSONFormats.includes(format) ||
recordsJSONFormats.includes(format));
}
exports.isNotStreamableJSONFamily = isNotStreamableJSONFamily;
function isStreamableJSONFamily(format) {
// @ts-expect-error JSON is not assignable to streamableJSONFormats
return streamableJSONFormats.includes(format);
}
exports.isStreamableJSONFamily = isStreamableJSONFamily;
function isSupportedRawFormat(dataFormat) {

@@ -68,23 +69,2 @@ return supportedRawFormats.includes(dataFormat);

/**
* Decodes a string in a ClickHouse format into a plain JavaScript object or an array of objects.
* @param text a string in a ClickHouse data format
* @param format One of the supported formats: https://clickhouse.com/docs/en/interfaces/formats/
*/
function decode(text, format) {
if (isNotStreamableJSONFamily(format)) {
return JSON.parse(text);
}
if (isStreamableJSONFamily(format)) {
return text
.split('\n')
.filter(Boolean)
.map((l) => decode(l, 'JSON'));
}
if (isSupportedRawFormat(format)) {
throw new Error(`Cannot decode ${format} to JSON`);
}
throw new Error(`The client does not support [${format}] format decoding.`);
}
exports.decode = decode;
/**
* Encodes a single row of values into a string in a JSON format acceptable by ClickHouse.

@@ -91,0 +71,0 @@ * @param value a single value to encode.

/** Should be re-exported by the implementation */
export { type BaseClickHouseClientConfigOptions, type ClickHouseClientConfigOptions, type BaseQueryParams, type QueryParams, type ExecParams, type InsertParams, type InsertValues, ClickHouseClient, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type PingResult, } from './client';
export type { Row, BaseResultSet } from './result';
export { type DataFormat } from './data_formatter';
export { type BaseQueryParams, type QueryParams, type QueryResult, type ExecParams, type InsertParams, type InsertValues, ClickHouseClient, type CommandParams, type CommandResult, type ExecResult, type InsertResult, type PingResult, } from './client';
export { type BaseClickHouseClientConfigOptions } from './config';
export type { Row, BaseResultSet, ResultJSONType, RowJSONType, ResultStream, } from './result';
export type { DataFormat, RawDataFormat, JSONDataFormat, StreamableDataFormat, StreamableJSONDataFormat, SingleDocumentJSONFormat, } from './data_formatter';
export { ClickHouseError } from './error';

@@ -9,9 +10,10 @@ export { ClickHouseLogLevel, type ErrorLogParams, type WarnLogParams, type Logger, type LogParams, } from './logger';

export { type ClickHouseSettings, type MergeTreeSettings, SettingsMap, } from './settings';
/** For implementations usage only */
export { encodeJSON, isSupportedRawFormat, decode, validateStreamFormat, } from './data_formatter';
export { type ValuesEncoder, type MakeResultSet, type MakeConnection, } from './client';
/** For implementations usage only - should not be re-exported */
export { formatQuerySettings, formatQueryParams, encodeJSON, isSupportedRawFormat, isStreamableJSONFamily, isNotStreamableJSONFamily, validateStreamFormat, } from './data_formatter';
export { type ValuesEncoder, type MakeResultSet, type MakeConnection, type HandleImplSpecificURLParams, type ImplementationDetails, booleanConfigURLValue, enumConfigURLValue, getConnectionParams, numberConfigURLValue, } from './config';
export { withCompressionHeaders, isSuccessfulResponse, toSearchParams, transformUrl, withHttpSettings, } from './utils';
export { LogWriter, DefaultLogger, type LogWriterParams } from './logger';
export { parseError } from './error';
export type { Connection, ConnectionParams, ConnInsertResult, ConnExecResult, ConnQueryResult, ConnBaseQueryParams, ConnBaseResult, ConnInsertParams, ConnPingResult, ConnOperation, } from './connection';
export { type RawDataFormat, type JSONDataFormat, formatQuerySettings, formatQueryParams, } from './data_formatter';
export type { CompressionSettings, Connection, ConnectionParams, ConnInsertResult, ConnExecResult, ConnQueryResult, ConnBaseQueryParams, ConnBaseResult, ConnInsertParams, ConnPingResult, ConnOperation, } from './connection';
export type { QueryParamsWithFormat } from './client';
export type { IsSame } from './ts_utils';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatQueryParams = exports.formatQuerySettings = exports.parseError = exports.DefaultLogger = exports.LogWriter = exports.withHttpSettings = exports.transformUrl = exports.toSearchParams = exports.isSuccessfulResponse = exports.withCompressionHeaders = exports.validateStreamFormat = exports.decode = exports.isSupportedRawFormat = exports.encodeJSON = exports.SettingsMap = exports.ClickHouseLogLevel = exports.ClickHouseError = exports.ClickHouseClient = void 0;
exports.parseError = exports.DefaultLogger = exports.LogWriter = exports.withHttpSettings = exports.transformUrl = exports.toSearchParams = exports.isSuccessfulResponse = exports.withCompressionHeaders = exports.numberConfigURLValue = exports.getConnectionParams = exports.enumConfigURLValue = exports.booleanConfigURLValue = exports.validateStreamFormat = exports.isNotStreamableJSONFamily = exports.isStreamableJSONFamily = exports.isSupportedRawFormat = exports.encodeJSON = exports.formatQueryParams = exports.formatQuerySettings = exports.SettingsMap = exports.ClickHouseLogLevel = exports.ClickHouseError = exports.ClickHouseClient = void 0;
/** Should be re-exported by the implementation */

@@ -13,8 +13,16 @@ var client_1 = require("./client");

Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return settings_1.SettingsMap; } });
/** For implementations usage only */
/** For implementations usage only - should not be re-exported */
var data_formatter_1 = require("./data_formatter");
Object.defineProperty(exports, "formatQuerySettings", { enumerable: true, get: function () { return data_formatter_1.formatQuerySettings; } });
Object.defineProperty(exports, "formatQueryParams", { enumerable: true, get: function () { return data_formatter_1.formatQueryParams; } });
Object.defineProperty(exports, "encodeJSON", { enumerable: true, get: function () { return data_formatter_1.encodeJSON; } });
Object.defineProperty(exports, "isSupportedRawFormat", { enumerable: true, get: function () { return data_formatter_1.isSupportedRawFormat; } });
Object.defineProperty(exports, "decode", { enumerable: true, get: function () { return data_formatter_1.decode; } });
Object.defineProperty(exports, "isStreamableJSONFamily", { enumerable: true, get: function () { return data_formatter_1.isStreamableJSONFamily; } });
Object.defineProperty(exports, "isNotStreamableJSONFamily", { enumerable: true, get: function () { return data_formatter_1.isNotStreamableJSONFamily; } });
Object.defineProperty(exports, "validateStreamFormat", { enumerable: true, get: function () { return data_formatter_1.validateStreamFormat; } });
var config_1 = require("./config");
Object.defineProperty(exports, "booleanConfigURLValue", { enumerable: true, get: function () { return config_1.booleanConfigURLValue; } });
Object.defineProperty(exports, "enumConfigURLValue", { enumerable: true, get: function () { return config_1.enumConfigURLValue; } });
Object.defineProperty(exports, "getConnectionParams", { enumerable: true, get: function () { return config_1.getConnectionParams; } });
Object.defineProperty(exports, "numberConfigURLValue", { enumerable: true, get: function () { return config_1.numberConfigURLValue; } });
var utils_1 = require("./utils");

@@ -31,5 +39,2 @@ Object.defineProperty(exports, "withCompressionHeaders", { enumerable: true, get: function () { return utils_1.withCompressionHeaders; } });

Object.defineProperty(exports, "parseError", { enumerable: true, get: function () { return error_2.parseError; } });
var data_formatter_2 = require("./data_formatter");
Object.defineProperty(exports, "formatQuerySettings", { enumerable: true, get: function () { return data_formatter_2.formatQuerySettings; } });
Object.defineProperty(exports, "formatQueryParams", { enumerable: true, get: function () { return data_formatter_2.formatQueryParams; } });
//# sourceMappingURL=index.js.map

@@ -131,3 +131,3 @@ "use strict";

ClickHouseLogLevel[ClickHouseLogLevel["OFF"] = 127] = "OFF";
})(ClickHouseLogLevel = exports.ClickHouseLogLevel || (exports.ClickHouseLogLevel = {}));
})(ClickHouseLogLevel || (exports.ClickHouseLogLevel = ClickHouseLogLevel = {}));
function formatMessage({ level, module, message, }) {

@@ -134,0 +134,0 @@ const ts = new Date().toISOString();

@@ -1,2 +0,8 @@

export interface Row {
import type { ResponseJSON } from './clickhouse_types';
import type { DataFormat, RawDataFormat, RecordsJSONFormat, SingleDocumentJSONFormat, StreamableDataFormat, StreamableJSONDataFormat } from './data_formatter';
export type ResultStream<Format extends DataFormat | unknown, Stream> = Format extends StreamableDataFormat ? Stream : Format extends SingleDocumentJSONFormat ? never : Format extends RecordsJSONFormat ? never : Stream;
export type ResultJSONType<T, F extends DataFormat | unknown> = F extends StreamableJSONDataFormat ? T[] : F extends SingleDocumentJSONFormat ? ResponseJSON<T> : F extends RecordsJSONFormat ? Record<string, T> : F extends RawDataFormat ? never : // happens only when Format could not be inferred from a literal
T[] | Record<string, T> | ResponseJSON<T>;
export type RowJSONType<T, F extends DataFormat | unknown> = F extends StreamableJSONDataFormat ? T : F extends RawDataFormat | SingleDocumentJSONFormat | RecordsJSONFormat ? never : T;
export interface Row<JSONType = unknown, Format extends DataFormat | unknown = unknown> {
/** A string representation of a row. */

@@ -9,5 +15,5 @@ text: string;

*/
json<T>(): T;
json<T = JSONType>(): RowJSONType<T, Format>;
}
export interface BaseResultSet<Stream> {
export interface BaseResultSet<Stream, Format extends DataFormat | unknown> {
/**

@@ -17,2 +23,4 @@ * The method waits for all the rows to be fully loaded

*
* It is possible to call this method for all supported formats.
*
* The method should throw if the underlying stream was already consumed

@@ -26,10 +34,41 @@ * by calling the other methods.

*
* Should be called only for JSON* formats family.
*
* The method should throw if the underlying stream was already consumed
* by calling the other methods.
* by calling the other methods, or if it is called for non-JSON formats,
* such as CSV, TSV etc.
*/
json<T>(): Promise<T>;
json<T = unknown>(): Promise<ResultJSONType<T, Format>>;
/**
* Returns a readable stream for responses that can be streamed
* (i.e. all except JSON).
* Returns a readable stream for responses that can be streamed.
*
* Formats that CAN be streamed ({@link StreamableDataFormat}):
* * JSONEachRow
* * JSONStringsEachRow
* * JSONCompactEachRow
* * JSONCompactStringsEachRow
* * JSONCompactEachRowWithNames
* * JSONCompactEachRowWithNamesAndTypes
* * JSONCompactStringsEachRowWithNames
* * JSONCompactStringsEachRowWithNamesAndTypes
* * CSV
* * CSVWithNames
* * CSVWithNamesAndTypes
* * TabSeparated
* * TabSeparatedRaw
* * TabSeparatedWithNames
* * TabSeparatedWithNamesAndTypes
* * CustomSeparated
* * CustomSeparatedWithNames
* * CustomSeparatedWithNamesAndTypes
* * Parquet
*
* Formats that CANNOT be streamed (the method returns "never" in TS):
* * JSON
* * JSONStrings
* * JSONCompact
* * JSONCompactStrings
* * JSONColumnsWithMetadata
* * JSONObjectEachRow
*
* Every iteration provides an array of {@link Row} instances

@@ -44,3 +83,3 @@ * for {@link StreamableDataFormat} format.

*/
stream(): Stream;
stream(): ResultStream<Format, Stream>;
/** Close the underlying stream. */

@@ -47,0 +86,0 @@ close(): void;

export * from './connection';
export * from './url';
export * from './permutations';

@@ -19,3 +19,2 @@ "use strict";

__exportStar(require("./url"), exports);
__exportStar(require("./permutations"), exports);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

declare const _default: "0.3.1";
declare const _default: "1.0.0";
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = '0.3.1';
exports.default = '1.0.0';
//# sourceMappingURL=version.js.map

@@ -5,3 +5,3 @@ {

"homepage": "https://clickhouse.com",
"version": "0.3.1",
"version": "1.0.0",
"license": "Apache-2.0",

@@ -8,0 +8,0 @@ "keywords": [

@@ -7,5 +7,17 @@ <p align="center">

<p align="center">
<a href="https://www.npmjs.com/package/@clickhouse/client">
<img alt="NPM Version" src="https://img.shields.io/npm/v/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
</a>
<a href="https://www.npmjs.com/package/@clickhouse/client">
<img alt="NPM Downloads" src="https://img.shields.io/npm/dw/%40clickhouse%2Fclient?color=%233178C6&logo=npm">
</a>
<a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml">
<img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml/badge.svg?branch=main">
</a>
<img src="https://sonarcloud.io/api/project_badges/measure?project=ClickHouse_clickhouse-js&metric=alert_status">
<img src="https://sonarcloud.io/api/project_badges/measure?project=ClickHouse_clickhouse-js&metric=coverage">
</p>

@@ -12,0 +24,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc