@fjall/clickhouse 12.1.1 → 12.3.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.
@@ -9,7 +9,7 @@
9
9
  "package.json",
10
10
  "tsconfig.json"
11
11
  ],
12
- "hash": "5dac168c22cf1b75754ae25a9195c4e9defaaf3b30442357a6558a39e79dc823",
12
+ "hash": "4986880e53fee45b0034e4ac756aa317170436f42e455bca2894ecfb847227da",
13
13
  "files": {
14
14
  "src/connectWithRetry.ts": "eb4d131ea8e81922",
15
15
  "src/constants.ts": "00b236fd35f098cb",
@@ -17,14 +17,14 @@
17
17
  "src/index.ts": "4b819b3a8d8de192",
18
18
  "src/logger.ts": "659d04c534247903",
19
19
  "src/provisionUsers.ts": "3e88d53b5eb1ccf5",
20
- "src/runSqlMigrations.ts": "33b5dd505fa460e9",
20
+ "src/runSqlMigrations.ts": "d187aa5de9e4316e",
21
21
  "src/schemas.ts": "f3be95e003bd7e6e",
22
22
  "src/sleepAbortable.ts": "0286a0719bef3a38",
23
23
  "src/verifyExpectedClickHouseSchemaVersion.ts": "84f5463cd47e4a30",
24
24
  "../scripts/minify-dist.mjs": "6b2e4b0df8aec601",
25
- "package.json": "7676309f63d79dc1",
25
+ "package.json": "425234cb8455e3af",
26
26
  "tsconfig.json": "db759831ad95f396"
27
27
  },
28
- "outputHash": "e664f8b13154872848818d7b3042bca55e11d7d2ac31167faef9058533ac1a03",
28
+ "outputHash": "7aa71903ff9bc877465991142c39a5bbcaf141ca54229a9c46e95da8e44a0472",
29
29
  "outputFileCount": 21
30
30
  }
package/dist/.minified CHANGED
@@ -1 +1 @@
1
- 10 files minified at 2026-08-15T09:46:40.402Z
1
+ 10 files minified at 2026-08-16T01:19:32.659Z
@@ -1,6 +1,17 @@
1
1
  import type { ClickHouseClient } from "@clickhouse/client";
2
2
  import type { MigrationLogger } from "./logger.js";
3
3
  export declare function hasSqlContent(chunk: string): boolean;
4
+ /**
5
+ * Extract a `-- fjall:skip-if: <SQL expression>` directive from a migration
6
+ * file's leading comment block (consecutive lines from the top that are empty
7
+ * or start with `--`). A directive appearing after the first statement is
8
+ * deliberately NOT honoured — the contract is file-level, declared up front.
9
+ *
10
+ * Returns the expression, or `undefined` when no directive is present.
11
+ * Throws on a duplicate directive or an empty expression (an unevaluable
12
+ * guard must fail loudly, never silently authorise or omit a skip).
13
+ */
14
+ export declare function parseSkipIfDirective(sql: string): string | undefined;
4
15
  export interface RunSqlMigrationsOpts {
5
16
  client: ClickHouseClient;
6
17
  dir: string;
@@ -1,2 +1,3 @@
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};
1
+ var S=Object.defineProperty;var l=(r,t)=>S(r,"name",{value:t,configurable:!0});import{readFileSync as y,readdirSync as k}from"node:fs";import{join as q}from"node:path";import{getErrorMessage as h,maskSensitiveOutput as u}from"@fjall/util";import{CLICKHOUSE_MIGRATION_SKIP_RE as R}from"@fjall/util/migration";const $=R,g=400,I=/^--\s*fjall:skip-if:(.*)$/,M=new Set([1,!0,"1"]),_=new Set([0,!1,"0"]);function A(r){return r.split(`
2
+ `).some(t=>{const i=t.trim();return i.length>0&&!i.startsWith("--")})}l(A,"hasSqlContent");function b(r){return r.split(/;\s*\n/).map(t=>t.trim()).filter(t=>t.length>0&&A(t))}l(b,"splitSqlStatements");function w(r){const i=h(r).replace(/'(?:[^']|'')*'/g,"'<REDACTED>'"),e=u(i);return e.length>g?e.slice(0,g)+"\u2026":e}l(w,"maskAndTruncateError");function x(r){let t;for(const i of r.split(`
3
+ `)){const e=i.trim();if(e.length>0&&!e.startsWith("--"))break;const s=I.exec(e);if(s===null)continue;const o=(s[1]??"").trim();if(o.length===0)throw new Error("fjall:skip-if directive has an empty expression");if(t!==void 0)throw new Error("duplicate fjall:skip-if directive in the leading comment block");t=o}return t}l(x,"parseSkipIfDirective");async function j(r,t,i){let e;try{e=await(await r.query({query:`SELECT (${i})`,format:"JSONEachRow"})).json()}catch(c){throw new Error(`runSqlMigrations: ${t}: fjall:skip-if predicate failed: ${w(c)}`,{cause:c})}if(e.length!==1)throw new Error(`runSqlMigrations: ${t}: fjall:skip-if predicate returned ${e.length} rows (expected exactly 1)`);const s=Object.values(e[0]??{});if(s.length!==1)throw new Error(`runSqlMigrations: ${t}: fjall:skip-if predicate returned ${s.length} columns (expected exactly 1)`);const o=s[0];if(M.has(o))return!0;if(_.has(o))return!1;throw new Error(`runSqlMigrations: ${t}: fjall:skip-if predicate returned a non-boolean value (${u(JSON.stringify(o))}); expected 0/1`)}l(j,"evaluateSkipIfPredicate");async function L(r){const{client:t,dir:i,signal:e,logger:s}=r,o=r.skipFilesMatching??$,c=k(i).filter(n=>n.endsWith(".sql")).filter(n=>!o.test(n)).sort(),p=[];for(const n of c){if(e?.aborted)throw new Error(`runSqlMigrations: aborted by signal before applying '${n}'`);const E=q(i,n),d=y(E,"utf8");let f;try{f=x(d)}catch(a){throw new Error(`runSqlMigrations: ${n}: ${u(h(a))}`,{cause:a})}if(f!==void 0&&await j(t,n,f)){s?.info("sql migration skipped by fjall:skip-if directive",{file:n,skipIf:f});continue}const m=b(d);try{for(const a of m){if(e?.aborted)throw new Error(`runSqlMigrations: aborted by signal while applying '${n}'`);await t.command({query:a})}}catch(a){throw new Error(`runSqlMigrations: ${n}: ${w(a)}`,{cause:a})}s?.info("sql migration applied",{file:n}),p.push(n)}return{applied:p}}l(L,"runSqlMigrations");export{A as hasSqlContent,x as parseSkipIfDirective,L as runSqlMigrations};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fjall/clickhouse",
3
- "version": "12.1.1",
3
+ "version": "12.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/fjall-tech/fjall.git",
@@ -50,7 +50,7 @@
50
50
  "@clickhouse/client": "^1.18.0"
51
51
  },
52
52
  "dependencies": {
53
- "@fjall/util": "^12.1.1",
53
+ "@fjall/util": "^12.3.0",
54
54
  "zod": "^4.4.3"
55
55
  },
56
56
  "engines": {