@fjall/clickhouse 2.34.0 → 3.0.0
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/dist/.minified +1 -1
- package/dist/connectWithRetry.js +1 -1
- package/dist/createClient.js +1 -1
- package/dist/logger.js +3 -3
- package/dist/provisionUsers.js +1 -1
- package/dist/runSqlMigrations.js +2 -2
- package/dist/sleepAbortable.js +1 -1
- package/dist/verifyExpectedClickHouseSchemaVersion.js +1 -1
- package/package.json +3 -3
package/dist/.minified
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
10 files minified at 2026-07-
|
|
1
|
+
10 files minified at 2026-07-18T01:56:03.828Z
|
package/dist/connectWithRetry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getErrorMessage as
|
|
1
|
+
var y=Object.defineProperty;var f=(c,o)=>y(c,"name",{value:o,configurable:!0});import{getErrorMessage as h,maskSensitiveOutput as _}from"@fjall/util";import{sleepAbortable as p}from"./sleepAbortable.js";const m=[5e3,1e4,2e4,4e4,6e4],A=3,w=516,D=["ECONNREFUSED","ETIMEDOUT","ENOTFOUND"];async function O(c,o){const{label:n,signal:i,logger:s}=o,e=o.delays??m;let l;for(let t=0;t<e.length;t++){if(i?.aborted)throw new Error(`connectWithRetry: ${n} aborted by signal before attempt ${t+1}`);try{await c.ping(),t>0&&s?.info("connect succeeded after retry",{label:n,attempt:t+1});return}catch(r){l=r;const a=typeof r=="object"&&r!==null&&"code"in r?r.code:void 0,E=a===w,d=typeof a=="string"&&D.includes(a);if(!(d||E&&t<A))throw r;const g=E?"AUTH_FAILED":d?a:"UNKNOWN";s?.warn("connect attempt failed; retrying",{label:_(n),attempt:t+1,attempts:e.length,delayMs:e[t],code:g}),await p(e[t],i)}}if(i?.aborted)throw new Error(`connectWithRetry: ${n} aborted by signal after ${e.length} attempts`);const b=_(h(l));throw new Error(`connectWithRetry: ${n} failed after ${e.length} attempts: ${b}`)}f(O,"connectWithRetry");export{O as connectWithRetry};
|
package/dist/createClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createClient as
|
|
1
|
+
var a=Object.defineProperty;var d=(e,n)=>a(e,"name",{value:n,configurable:!0});import{createClient as c}from"@clickhouse/client";function l(e={}){const n=process.env.CLICKHOUSE_URL,i=e.url!==void 0&&e.url!==""?e.url:n!==void 0&&n!==""?n:void 0;if(i===void 0)throw new Error("createFjallClickHouseClient: CLICKHOUSE_URL must be set (env or opts.url)");const r=process.env.CLICKHOUSE_CA_CERT,u=e.caCert!==void 0&&e.caCert!==""?e.caCert:r!==void 0&&r!==""?r:void 0;return c({url:i,...e.username!==void 0&&{username:e.username},...e.password!==void 0&&{password:e.password},...e.database!==void 0&&{database:e.database},...e.clickhouse_settings!==void 0&&{clickhouse_settings:e.clickhouse_settings},...e.compression!==void 0&&{compression:e.compression},...e.request_timeout!==void 0&&{request_timeout:e.request_timeout},...e.max_open_connections!==void 0&&{max_open_connections:e.max_open_connections},...e.keep_alive!==void 0&&{keep_alive:e.keep_alive},...u!==void 0&&{tls:{ca_cert:Buffer.from(u,"utf8")}}})}d(l,"createFjallClickHouseClient");export{l as createFjallClickHouseClient};
|
package/dist/logger.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
`)},warn(t,
|
|
3
|
-
`)}}}export{
|
|
1
|
+
var o=Object.defineProperty;var r=(e,t)=>o(e,"name",{value:t,configurable:!0});function s(e){return{info(t,n){process.stdout.write(JSON.stringify({level:"info",namespace:e,msg:t,ctx:n??{},ts:new Date().toISOString()})+`
|
|
2
|
+
`)},warn(t,n){process.stdout.write(JSON.stringify({level:"warn",namespace:e,msg:t,ctx:n??{},ts:new Date().toISOString()})+`
|
|
3
|
+
`)}}}r(s,"createConsoleMigrationLogger");export{s as createConsoleMigrationLogger};
|
package/dist/provisionUsers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getErrorMessage as
|
|
1
|
+
var g=Object.defineProperty;var t=(r,s)=>g(r,"name",{value:s,configurable:!0});import{getErrorMessage as S,maskSensitiveOutput as h}from"@fjall/util";import{CLICKHOUSE_MANAGED_USERS_ENV as m,userPasswordEnvName as I}from"./constants.js";import{ManagedUserNamesSchema as N}from"./schemas.js";function U(r){return r.replace(/\\/g,"\\\\").replace(/'/g,"''")}t(U,"escapeSqlLiteral");async function R(r){const{client:s,signal:u,logger:o}=r,c=r.env??process.env,n=c[m];if(n===void 0||n==="")return o?.info("no managed users to provision (manifest env absent)",{}),{provisioned:[]};let p;try{p=JSON.parse(n)}catch(e){throw new Error(`provisionUsersFromEnv: malformed ${m} \u2014 JSON parse failed: ${h(S(e))}`)}const a=N.safeParse(p);if(!a.success)throw new Error(`provisionUsersFromEnv: malformed ${m} \u2014 ${a.error.message}`);const d=a.data;if(d.length===0)return o?.info("no managed users to provision (manifest empty)",{}),{provisioned:[]};const f=[];for(const e of d){if(u?.aborted)throw new Error(`provisionUsersFromEnv: aborted by signal before user '${e}'`);const E=I(e),i=c[E];if(i===void 0||i==="")throw new Error(`provisionUsersFromEnv: required env ${E} is missing or empty`);const v=U(i),l=`CREATE USER IF NOT EXISTS ${e} IDENTIFIED WITH sha256_password BY '${v}'`,w=`ALTER USER ${e} IDENTIFIED WITH sha256_password BY '${v}'`;await s.command({query:l}),await s.command({query:w}),o?.info("clickhouse user provisioned",{name:e}),f.push(e)}return{provisioned:f}}t(R,"provisionUsersFromEnv");export{R as provisionUsersFromEnv};
|
package/dist/runSqlMigrations.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{readFileSync as
|
|
2
|
-
`).some(
|
|
1
|
+
var E=Object.defineProperty;var i=(e,t)=>E(e,"name",{value:t,configurable:!0});import{readFileSync as w,readdirSync as q}from"node:fs";import{join as M}from"node:path";import{getErrorMessage as y,maskSensitiveOutput as R}from"@fjall/util";import{CLICKHOUSE_MIGRATION_SKIP_RE as b}from"@fjall/util/migration";const _=b,c=400;function C(e){return e.split(`
|
|
2
|
+
`).some(t=>{const n=t.trim();return n.length>0&&!n.startsWith("--")})}i(C,"hasSqlContent");function A(e){return e.split(/;\s*\n/).map(t=>t.trim()).filter(t=>t.length>0&&C(t))}i(A,"splitSqlStatements");async function D(e){const{client:t,dir:n,signal:a,logger:m}=e,f=e.skipFilesMatching??_,p=q(n).filter(r=>r.endsWith(".sql")).filter(r=>!f.test(r)).sort(),l=[];for(const r of p){if(a?.aborted)throw new Error(`runSqlMigrations: aborted by signal before applying '${r}'`);const g=M(n,r),u=w(g,"utf8"),d=A(u);try{for(const o of d){if(a?.aborted)throw new Error(`runSqlMigrations: aborted by signal while applying '${r}'`);await t.command({query:o})}}catch(o){const h=y(o).replace(/'(?:[^']|'')*'/g,"'<REDACTED>'"),s=R(h),S=s.length>c?s.slice(0,c)+"\u2026":s;throw new Error(`runSqlMigrations: ${r}: ${S}`,{cause:o})}m?.info("sql migration applied",{file:r}),l.push(r)}return{applied:l}}i(D,"runSqlMigrations");export{C as hasSqlContent,D as runSqlMigrations};
|
package/dist/sleepAbortable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
var i=Object.defineProperty;var o=(t,e)=>i(t,"name",{value:e,configurable:!0});function s(t,e){return e?.aborted?Promise.resolve():new Promise(n=>{const r=o(()=>{clearTimeout(b),e?.removeEventListener("abort",r),n()},"onAbort"),b=setTimeout(()=>{e?.removeEventListener("abort",r),n()},t);e?.addEventListener("abort",r,{once:!0})})}o(s,"sleepAbortable");export{s as sleepAbortable};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSchemaVersionSatisfied as
|
|
1
|
+
var u=Object.defineProperty;var s=(e,t)=>u(e,"name",{value:t,configurable:!0});import{isSchemaVersionSatisfied as E}from"@fjall/util/migration";const n=/^[A-Za-z_][A-Za-z0-9_]*$/,l=["version","ch_version","prisma_version"],f="analytics",d="_schema_migrations",h="ch_version";async function A(e){if(e.signal?.aborted)throw new Error("verifyExpectedClickHouseSchemaVersion: aborted by signal before query");const t=e.database??f,r=e.table??d,a=e.field??h;if(!n.test(t))throw new Error(`verifyExpectedClickHouseSchemaVersion: unsafe database identifier '${t}'`);if(!n.test(r))throw new Error(`verifyExpectedClickHouseSchemaVersion: unsafe table identifier '${r}'`);if(!l.includes(a))throw new Error(`verifyExpectedClickHouseSchemaVersion: field must be one of ${l.join("|")} (got '${a}')`);const o=(await(await e.client.query({query:`SELECT ${a} AS value FROM ${t}.${r} ORDER BY applied_at DESC LIMIT 1`,format:"JSONEachRow"})).json())[0]?.value,i=typeof o=="string"?o:null,c={matches:i!==null&&E(e.expected,i),expected:e.expected,actual:i};return e.logger?.info("ClickHouse schema-version check complete",{matches:c.matches,expected:c.expected,actual:c.actual,database:t,table:r,field:a}),c}s(A,"verifyExpectedClickHouseSchemaVersion");export{A as verifyExpectedClickHouseSchemaVersion};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjall/clickhouse",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Runtime helpers for ClickHouse migration containers — user provisioning, SQL file application, connection retry. Consumes the manifest contract published by @fjall/components-infrastructure ClickHouseDatabase.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"@clickhouse/client": "^1.18.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@fjall/util": "^
|
|
48
|
+
"@fjall/util": "^3.0.0",
|
|
49
49
|
"zod": "^4.4.3"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=22.0.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "848a386e3e2244401b76faabd02818c682d231e8"
|
|
55
55
|
}
|