Releases: SmooAI/clickhouse-kit
Releases · SmooAI/clickhouse-kit
v0.2.0
Minor Changes
-
0cac5bd: v0.2 safety core — safe-by-construction primitives for user-defined / multi-tenant schemas (ROADMAP item 2). When column names + types come from untrusted input, these enforce the boundary so SQL injection and unbounded tables are impossible on the happy path:
validateIdentifier(name, kind?)— strict ASCII allowlist + length bound; rejects dots, quotes, backticks, metacharacters, leading digits, unicode, injection attempts.quoteIdentifier(name)— backtick-quoting with escape (defense-in-depth).columnFromTypeSpec(spec)— builds aChColumnfrom a JSON-friendly recursive type spec, enforcing an allowlist (String/ints/floats/Date/DateTime64/Bool/UUID/JSON+nullable/lowCardinality/Array(String)/Map(String,String)); rejectsDecimal/FixedString/Tuple/Enum/Nested/arbitrary type strings. The single gate from outside input to a column.assertColumnCount/assertNotReserved/DEFAULT_LIMITS/DEFAULT_RESERVED_COLUMNS— bounds + reserved-column (attrs/raw) handling.
Foundation for the runtime table construction +
flexibleTableprimitives in the rest of v0.2. -
0f48410: v0.2 — the safe foundation for flexible, user-driven, multi-tenant schemas (ROADMAP items 1, 3, 4, 5; item 2 safety core shipped separately).
- Runtime table construction:
clickhouseTableFromSpec(name, columns[], options)builds aChTablefrom an untrusted runtime column list (validates identifiers, enforces the type allowlist + column bounds + dedupe), withruntimeSelectSchema(table)for a zod validator. SametoCreateTableSqlrendering as the static path. - Semi-structured columns + hybrid table:
ch.map(),ch.array(inner), andflexibleTable(name, { mandatory, promoted, options })— the proven mandatory +attrs Map(String,String)+raw String+ promoted-typed-columns shape, with reserved-column guards. - Flatten + coerce:
flattenRecord(obj, opts?)(nested → dotted-key string map, arrays stringified, depth/key caps) andcoerceToTable(input, table)(route known keys to columns, the long tail into theattrscatch-all, captureraw, reportoverflowKeys). - Additive, bounded evolution:
diffColumns(table, live)(additive-only: kit-but-not-live columns) andalterAddColumnsSql(table, missing)(guardedALTER TABLE … ADD COLUMN IF NOT EXISTS …, identifiers backtick-quoted, types from the trusted kit definition) — for growing dynamic per-tenant tables without touching the forward-only file migrations.
All additive, TS-only, safe by construction; built on the v0.2 safety core.
- Runtime table construction: