Socket
Socket
Sign inDemoInstall

@clickhouse/client

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clickhouse/client - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

2

dist/clickhouse_types.d.ts

@@ -24,2 +24,2 @@ export interface ResponseJSON<T = unknown> {

}
export declare type InputJSONObjectEachRow<T = unknown> = Record<string, T>;
export type InputJSONObjectEachRow<T = unknown> = Record<string, T>;
/// <reference types="node" />
/// <reference types="node" />
import Stream from 'stream';
import { Logger } from './logger';
import type { Logger } from './logger';
import { type DataFormat } from './data_formatter';

@@ -35,6 +35,4 @@ import { ResultSet } from './result';

log?: {
/** Enable logging. Default value: false. */
enable?: boolean;
/** A class to instantiate a custom logger implementation. */
LoggerClass?: new (enabled: boolean) => Logger;
LoggerClass?: new () => Logger;
};

@@ -70,3 +68,3 @@ tls?: BasicTLSOptions | MutualTLSOptions;

}
declare type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
export interface InsertParams<T = unknown> extends BaseParams {

@@ -83,3 +81,3 @@ /** Name of a table to insert into. */

private readonly connection;
readonly logger: Logger;
private readonly logger;
constructor(config?: ClickHouseClientConfigOptions);

@@ -86,0 +84,0 @@ private getBaseParams;

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

}
function normalizeConfig(config, loggingEnabled) {
function normalizeConfig(config) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;

@@ -61,4 +61,3 @@ let tls = undefined;

log: {
enable: loggingEnabled,
LoggerClass: (_q = (_p = config.log) === null || _p === void 0 ? void 0 : _p.LoggerClass) !== null && _q !== void 0 ? _q : logger_1.Logger,
LoggerClass: (_q = (_p = config.log) === null || _p === void 0 ? void 0 : _p.LoggerClass) !== null && _q !== void 0 ? _q : logger_1.DefaultLogger,
},

@@ -70,3 +69,2 @@ session_id: config.session_id,

constructor(config = {}) {
var _a;
Object.defineProperty(this, "config", {

@@ -90,6 +88,5 @@ enumerable: true,

});
const loggingEnabled = Boolean(((_a = config.log) === null || _a === void 0 ? void 0 : _a.enable) || process.env.CLICKHOUSE_LOG_ENABLE);
this.config = normalizeConfig(config, loggingEnabled);
this.config = normalizeConfig(config);
validateConfig(this.config);
this.logger = new this.config.log.LoggerClass(this.config.log.enable);
this.logger = new logger_1.LogWriter(new this.config.log.LoggerClass());
this.connection = (0, connection_1.createConnection)(this.config, this.logger);

@@ -96,0 +93,0 @@ }

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

const onResponse = async (_response) => {
this.logResponse(params, _response, start);
this.logResponse(request, params, _response, start);
const decompressionResult = decompressResponse(_response);

@@ -247,5 +247,19 @@ if (isDecompressionError(decompressionResult)) {

}
logResponse(params, response, startTimestamp) {
logResponse(request, params, response, startTimestamp) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { authorization, host, ...headers } = request.getHeaders();
const duration = Date.now() - startTimestamp;
this.logger.debug(`[http adapter] response: ${params.method} ${params.url.pathname}${params.url.search ? ` ${params.url.search}` : ''} ${response.statusCode} ${duration}ms`);
this.logger.debug({
module: 'HTTP Adapter',
message: 'Got a response from ClickHouse',
args: {
request_method: params.method,
request_path: params.url.pathname,
request_params: params.url.search,
request_headers: headers,
response_status: response.statusCode,
response_headers: response.headers,
response_time_ms: duration,
},
});
}

@@ -252,0 +266,0 @@ getHeaders(params) {

/// <reference types="node" />
import Http from 'http';
import type { Logger } from '../../logger';
import type { LogWriter } from '../../logger';
import type { Connection, ConnectionParams } from '../connection';

@@ -8,4 +8,4 @@ import type { RequestParams } from './base_http_adapter';

export declare class HttpAdapter extends BaseHttpAdapter implements Connection {
constructor(config: ConnectionParams, logger: Logger);
constructor(config: ConnectionParams, logger: LogWriter);
protected createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
}
import type { ClickHouseSettings } from '../../settings';
declare type ToSearchParamsOptions = {
type ToSearchParamsOptions = {
database: string;

@@ -4,0 +4,0 @@ clickhouse_settings?: ClickHouseSettings;

@@ -5,8 +5,8 @@ /// <reference types="node" />

import type { Connection, ConnectionParams } from '../connection';
import type { Logger } from '../../logger';
import type { LogWriter } from '../../logger';
import type Http from 'http';
export declare class HttpsAdapter extends BaseHttpAdapter implements Connection {
constructor(config: ConnectionParams, logger: Logger);
constructor(config: ConnectionParams, logger: LogWriter);
protected buildDefaultHeaders(username: string, password: string): Http.OutgoingHttpHeaders;
protected createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
}
/// <reference types="node" />
/// <reference types="node" />
import type Stream from 'stream';
import type { Logger } from '../logger';
import type { LogWriter } from '../logger';
import type { ClickHouseSettings } from '../settings';

@@ -20,3 +20,3 @@ export interface ConnectionParams {

}
export declare type TLSParams = {
export type TLSParams = {
ca_cert: Buffer;

@@ -47,2 +47,2 @@ type: 'Basic';

}
export declare function createConnection(params: ConnectionParams, logger: Logger): Connection;
export declare function createConnection(params: ConnectionParams, logger: LogWriter): Connection;
declare const supportedJSONFormats: readonly ["JSON", "JSONObjectEachRow", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
export declare type JSONDataFormat = typeof supportedJSONFormats[number];
export declare type RawDataFormat = typeof supportedRawFormats[number];
export declare type DataFormat = JSONDataFormat | RawDataFormat;
export type JSONDataFormat = typeof supportedJSONFormats[number];
export type RawDataFormat = typeof supportedRawFormats[number];
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"];
declare type StreamableDataFormat = typeof streamableFormat[number];
type StreamableDataFormat = typeof streamableFormat[number];
export declare function isSupportedRawFormat(dataFormat: DataFormat): boolean;

@@ -9,0 +9,0 @@ export declare function validateStreamFormat(format: any): format is StreamableDataFormat;

@@ -1,8 +0,30 @@

export declare class Logger {
readonly enabled: boolean;
constructor(enabled?: boolean);
debug(message: string): void;
info(message: string): void;
warning(message: string): void;
error(message: string): void;
export interface LogParams {
module: string;
message: string;
args?: Record<string, unknown>;
}
export type ErrorLogParams = LogParams & {
err: Error;
};
export interface Logger {
debug(params: LogParams): void;
info(params: LogParams): void;
warn(params: LogParams): void;
error(params: ErrorLogParams): void;
}
export declare class DefaultLogger implements Logger {
debug({ module, message, args }: LogParams): void;
info({ module, message, args }: LogParams): void;
warn({ module, message, args }: LogParams): void;
error({ module, message, args, err }: ErrorLogParams): void;
}
export declare class LogWriter {
private readonly logger;
private readonly logLevel;
constructor(logger: Logger);
debug(params: LogParams): void;
info(params: LogParams): void;
warn(params: LogParams): void;
error(params: ErrorLogParams): void;
private getClickHouseLogLevel;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
class Logger {
constructor(enabled = false) {
Object.defineProperty(this, "enabled", {
exports.LogWriter = exports.DefaultLogger = void 0;
class DefaultLogger {
debug({ module, message, args }) {
console.debug(formatMessage({ module, message }), args);
}
info({ module, message, args }) {
console.info(formatMessage({ module, message }), args);
}
warn({ module, message, args }) {
console.warn(formatMessage({ module, message }), args);
}
error({ module, message, args, err }) {
console.error(formatMessage({ module, message }), args, err);
}
}
exports.DefaultLogger = DefaultLogger;
class LogWriter {
constructor(logger) {
Object.defineProperty(this, "logger", {
enumerable: true,
configurable: true,
writable: true,
value: enabled
value: logger
});
Object.defineProperty(this, "logLevel", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.logLevel = this.getClickHouseLogLevel();
this.info({
module: 'Logger',
message: `Log level is set to ${ClickHouseLogLevel[this.logLevel]}`,
});
}
debug(message) {
if (!this.enabled)
return;
console.log(message);
debug(params) {
if (this.logLevel <= ClickHouseLogLevel.DEBUG) {
this.logger.debug(params);
}
}
info(message) {
if (!this.enabled)
return;
console.log(message);
info(params) {
if (this.logLevel <= ClickHouseLogLevel.INFO) {
this.logger.info(params);
}
}
warning(message) {
if (!this.enabled)
return;
console.warn(message);
warn(params) {
if (this.logLevel <= ClickHouseLogLevel.WARN) {
this.logger.warn(params);
}
}
error(message) {
if (!this.enabled)
return;
console.error(message);
error(params) {
if (this.logLevel <= ClickHouseLogLevel.ERROR) {
this.logger.error(params);
}
}
getClickHouseLogLevel() {
const logLevelFromEnv = process.env['CLICKHOUSE_LOG_LEVEL'];
if (!logLevelFromEnv) {
return ClickHouseLogLevel.OFF;
}
const logLevel = logLevelFromEnv.toLocaleLowerCase();
if (logLevel === 'info') {
return ClickHouseLogLevel.INFO;
}
if (logLevel === 'warn') {
return ClickHouseLogLevel.WARN;
}
if (logLevel === 'error') {
return ClickHouseLogLevel.ERROR;
}
if (logLevel === 'debug') {
return ClickHouseLogLevel.DEBUG;
}
if (logLevel === 'trace') {
return ClickHouseLogLevel.TRACE;
}
if (logLevel === 'off') {
return ClickHouseLogLevel.OFF;
}
console.error(`Unknown CLICKHOUSE_LOG_LEVEL value: ${logLevelFromEnv}, logs are disabled`);
return ClickHouseLogLevel.OFF;
}
}
exports.Logger = Logger;
exports.LogWriter = LogWriter;
var ClickHouseLogLevel;
(function (ClickHouseLogLevel) {
ClickHouseLogLevel[ClickHouseLogLevel["TRACE"] = 0] = "TRACE";
ClickHouseLogLevel[ClickHouseLogLevel["DEBUG"] = 1] = "DEBUG";
ClickHouseLogLevel[ClickHouseLogLevel["INFO"] = 2] = "INFO";
ClickHouseLogLevel[ClickHouseLogLevel["WARN"] = 3] = "WARN";
ClickHouseLogLevel[ClickHouseLogLevel["ERROR"] = 4] = "ERROR";
ClickHouseLogLevel[ClickHouseLogLevel["OFF"] = 127] = "OFF";
})(ClickHouseLogLevel || (ClickHouseLogLevel = {}));
function formatMessage({ module, message, }) {
return `[@clickhouse/client][${module}] ${message}`;
}
//# sourceMappingURL=logger.js.map
import type { Type } from './types';
export declare type Shape = {
export type Shape = {
[key: string]: Type;
};
export declare type Infer<S extends Shape> = {
export type Infer<S extends Shape> = {
[Field in keyof S]: S[Field]['underlying'];
};
export declare type NonEmptyArray<T> = [T, ...T[]];
export type NonEmptyArray<T> = [T, ...T[]];

@@ -1,3 +0,3 @@

export declare type TableEngine = MergeTreeFamily;
declare type MergeTreeFamily = ReturnType<typeof MergeTree> | ReturnType<typeof ReplicatedMergeTree> | ReturnType<typeof ReplacingMergeTree> | ReturnType<typeof SummingMergeTree> | ReturnType<typeof AggregatingMergeTree> | ReturnType<typeof CollapsingMergeTree> | ReturnType<typeof VersionedCollapsingMergeTree> | ReturnType<typeof GraphiteMergeTree>;
export type TableEngine = MergeTreeFamily;
type MergeTreeFamily = ReturnType<typeof MergeTree> | ReturnType<typeof ReplicatedMergeTree> | ReturnType<typeof ReplacingMergeTree> | ReturnType<typeof SummingMergeTree> | ReturnType<typeof AggregatingMergeTree> | ReturnType<typeof CollapsingMergeTree> | ReturnType<typeof VersionedCollapsingMergeTree> | ReturnType<typeof GraphiteMergeTree>;
export declare const MergeTree: () => {

@@ -4,0 +4,0 @@ toString: () => string;

@@ -1,5 +0,5 @@

declare type Int = UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | UInt256;
declare type UInt = Int8 | Int16 | Int32 | Int64 | Int128 | Int256;
declare type Float = Float32 | Float64;
export declare type Type = Int | UInt | Float | Bool | String | FixedString | Array<any> | Nullable<any> | Map<any, any> | UUID | Enum<any> | LowCardinality<any> | Date | Date32 | DateTime | DateTime64 | IPv4 | IPv6;
type Int = UInt8 | UInt16 | UInt32 | UInt64 | UInt128 | UInt256;
type UInt = Int8 | Int16 | Int32 | Int64 | Int128 | Int256;
type Float = Float32 | Float64;
export type Type = Int | UInt | Float | Bool | String | FixedString | Array<any> | Nullable<any> | Map<any, any> | UUID | Enum<any> | LowCardinality<any> | Date | Date32 | DateTime | DateTime64 | IPv4 | IPv6;
export interface UInt8 {

@@ -139,3 +139,3 @@ underlying: number;

export declare const UUID: UUID;
declare type StandardEnum<T> = {
type StandardEnum<T> = {
[id: string]: T | string;

@@ -149,3 +149,3 @@ [n: number]: string;

export declare function Enum<T extends StandardEnum<unknown>>(enumVariable: T): Enum<T>;
declare type LowCardinalityDataType = String | FixedString | UInt | Int | Float | Date | DateTime;
type LowCardinalityDataType = String | FixedString | UInt | Int | Float | Date | DateTime;
export interface LowCardinality<T extends LowCardinalityDataType> {

@@ -161,3 +161,3 @@ type: 'LowCardinality';

export declare const Array: <T extends Type>(inner: T) => Array<T>;
declare type NullableType = Int | UInt | Float | Bool | String | FixedString | UUID | Decimal | Enum<any> | Date | DateTime | Date32 | IPv4 | IPv6;
type NullableType = Int | UInt | Float | Bool | String | FixedString | UUID | Decimal | Enum<any> | Date | DateTime | Date32 | IPv4 | IPv6;
export interface Nullable<T extends NullableType> {

@@ -168,3 +168,3 @@ type: 'Nullable';

export declare const Nullable: <T extends NullableType>(inner: T) => Nullable<T>;
declare type MapKey = String | Int | UInt | FixedString | UUID | Enum<any> | Date | DateTime | Date32;
type MapKey = String | Int | UInt | FixedString | UUID | Enum<any> | Date | DateTime | Date32;
export interface Map<K extends MapKey, V extends Type> {

@@ -171,0 +171,0 @@ type: 'Map';

{
"name": "@clickhouse/client",
"version": "0.0.10",
"version": "0.0.11",
"description": "Official JS client for ClickHouse DB",

@@ -26,8 +26,8 @@ "license": "Apache-2.0",

"lint:fix": "eslint --fix . --ext .ts",
"test": "jest --reporters jest-silent-reporter --testPathPattern=__tests__ --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test": "jest --testPathPattern=__tests__ --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:tls": "jest --testMatch='**/__tests__/tls/*.test.ts'",
"test:unit": "jest --reporters jest-silent-reporter --testMatch='**/__tests__/{unit,utils}/*.test.ts'",
"test:integration": "jest --reporters jest-silent-reporter --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:integration:local_cluster": "CLICKHOUSE_TEST_ENVIRONMENT=local_cluster jest --reporters jest-silent-reporter --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:integration:cloud": "CLICKHOUSE_TEST_ENVIRONMENT=cloud jest --reporters jest-silent-reporter --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:unit": "jest --testMatch='**/__tests__/{unit,utils}/*.test.ts'",
"test:integration": "jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:integration:local_cluster": "CLICKHOUSE_TEST_ENVIRONMENT=local_cluster jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"test:integration:cloud": "CLICKHOUSE_TEST_ENVIRONMENT=cloud jest --runInBand --testPathPattern=__tests__/integration --globalSetup='<rootDir>/__tests__/setup.integration.ts'",
"prepare": "husky install"

@@ -44,21 +44,21 @@ },

"devDependencies": {
"@types/jest": "^29.0.2",
"@types/node": "^18.7.18",
"@jest/reporters": "^29.3.1",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.11",
"@types/split2": "^3.2.1",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.37.0",
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.23.1",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.46.0",
"@typescript-eslint/parser": "^5.46.0",
"eslint": "^8.29.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^29.0.3",
"jest-silent-reporter": "^0.5.0",
"lint-staged": "^13.0.3",
"prettier": "2.7.1",
"husky": "^8.0.2",
"jest": "^29.3.1",
"lint-staged": "^13.1.0",
"prettier": "2.8.1",
"split2": "^4.1.0",
"ts-jest": "^29.0.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.8.3",
"tsconfig-paths": "^4.1.1",
"typescript": "^4.9.4",
"uuid": "^9.0.0"

@@ -65,0 +65,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 too big to display

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