@wavehouse/chtypes 0.1.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/CHANGELOG.md +24 -0
- package/LICENSE +202 -0
- package/README.md +442 -0
- package/dist/cli.d.ts +43 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +303 -0
- package/dist/cli.js.map +1 -0
- package/dist/discover.d.ts +134 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +291 -0
- package/dist/discover.js.map +1 -0
- package/dist/errors.d.ts +204 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +228 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch.d.ts +235 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +842 -0
- package/dist/fetch.js.map +1 -0
- package/dist/ffi.d.ts +346 -0
- package/dist/ffi.d.ts.map +1 -0
- package/dist/ffi.js +913 -0
- package/dist/ffi.js.map +1 -0
- package/dist/format.d.ts +104 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +108 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +127 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +577 -0
- package/dist/json.js.map +1 -0
- package/dist/library.d.ts +225 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +234 -0
- package/dist/library.js.map +1 -0
- package/dist/numeric.d.ts +20 -0
- package/dist/numeric.d.ts.map +1 -0
- package/dist/numeric.js +107 -0
- package/dist/numeric.js.map +1 -0
- package/dist/paths.d.ts +47 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +78 -0
- package/dist/paths.js.map +1 -0
- package/dist/registry.d.ts +204 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +409 -0
- package/dist/registry.js.map +1 -0
- package/dist/results.d.ts +326 -0
- package/dist/results.d.ts.map +1 -0
- package/dist/results.js +235 -0
- package/dist/results.js.map +1 -0
- package/dist/schema.d.ts +444 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +448 -0
- package/dist/schema.js.map +1 -0
- package/dist/settings.d.ts +43 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +33 -0
- package/dist/settings.js.map +1 -0
- package/dist/tar.d.ts +32 -0
- package/dist/tar.d.ts.map +1 -0
- package/dist/tar.js +310 -0
- package/dist/tar.js.map +1 -0
- package/dist/transform.d.ts +73 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +527 -0
- package/dist/transform.js.map +1 -0
- package/package.json +62 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `chtypes` — the one CLI surface every SDK carries (docs/fetch.md §6),
|
|
4
|
+
* spelled identically in all four:
|
|
5
|
+
*
|
|
6
|
+
* chtypes fetch <line>... [--all] [--platform <os-arch>] [--dest <dir>]
|
|
7
|
+
* [--tag <t> | --url <base>] [--lock <file>] [--frozen]
|
|
8
|
+
* [--force] [--offline]
|
|
9
|
+
* chtypes verify [--dest <dir>] re-hash every installed line against its manifest
|
|
10
|
+
* chtypes list [--dest <dir>] what is installed, and what the release offers
|
|
11
|
+
* chtypes where the registry directory fetch would write to
|
|
12
|
+
*
|
|
13
|
+
* Exit codes: 0 ok · 1 verification failed · 2 usage · 3 source unreachable ·
|
|
14
|
+
* 4 not published for this platform/line. Progress goes to stderr; `fetch`
|
|
15
|
+
* prints the installed directory alone on stdout, so it composes:
|
|
16
|
+
*
|
|
17
|
+
* dir="$(npx @wavehouse/chtypes fetch 25.8)"
|
|
18
|
+
*
|
|
19
|
+
* `runCli` is exported so the suite can drive the command in-process; the
|
|
20
|
+
* file runs `main` only when it is the process's entry point (the `bin`).
|
|
21
|
+
*/
|
|
22
|
+
import { realpathSync } from 'node:fs';
|
|
23
|
+
import { createRequire } from 'node:module';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
import { parseArgs } from 'node:util';
|
|
26
|
+
import { ArtifactUnpublishedError, ChtypesError, FetchError, SourceUnreachableError } from './errors.js';
|
|
27
|
+
import { ensure, ensureAll, listArtifacts, resolvePlatform, verifyInstalled } from './fetch.js';
|
|
28
|
+
import { fetchDestination } from './paths.js';
|
|
29
|
+
/** The §6 exit codes. */
|
|
30
|
+
export const EXIT = {
|
|
31
|
+
ok: 0,
|
|
32
|
+
verificationFailed: 1,
|
|
33
|
+
usage: 2,
|
|
34
|
+
sourceUnreachable: 3,
|
|
35
|
+
unpublished: 4,
|
|
36
|
+
};
|
|
37
|
+
const USAGE = `usage: chtypes <command> [options]
|
|
38
|
+
|
|
39
|
+
chtypes fetch <line>... [--all] [--platform <os-arch>] [--dest <dir>]
|
|
40
|
+
[--tag <t> | --url <base>] [--lock <file>] [--frozen]
|
|
41
|
+
[--force] [--offline]
|
|
42
|
+
chtypes verify [--dest <dir>] [--platform <os-arch>]
|
|
43
|
+
chtypes list [--dest <dir>] [--platform <os-arch>] [--tag <t> | --url <base>] [--offline]
|
|
44
|
+
chtypes where [--dest <dir>] [--platform <os-arch>]
|
|
45
|
+
|
|
46
|
+
<line> a ClickHouse line (25.8) or an exact patch (25.8.28.1-lts, a hard requirement)
|
|
47
|
+
--all every line the release publishes for the platform
|
|
48
|
+
--platform <os>-<arch> (linux|darwin)-(arm64|amd64); default: this host
|
|
49
|
+
--dest the registry directory; default: CHTYPES_REGISTRY, else the per-user cache
|
|
50
|
+
--tag a release tag on the artifacts host (default: the rolling "artifacts")
|
|
51
|
+
--url any other base: https://…, file://…, or a directory
|
|
52
|
+
--lock record what was installed into this lock file (default with --frozen: chtypes.lock)
|
|
53
|
+
--frozen refuse anything the lock file does not pin
|
|
54
|
+
--force re-download an installed line
|
|
55
|
+
--offline never touch the source: installed-and-verified is fine, anything else fails
|
|
56
|
+
-q, --quiet no progress on stderr
|
|
57
|
+
-h, --help this text; -V, --version the package version
|
|
58
|
+
|
|
59
|
+
exit codes: 0 ok · 1 verification failed · 2 usage · 3 source unreachable · 4 not published
|
|
60
|
+
environment: CHTYPES_ARTIFACTS_URL, CHTYPES_REGISTRY, CHTYPES_TRUSTED_KEYS, CHTYPES_ALLOW_UNSIGNED,
|
|
61
|
+
CHTYPES_AUTOFETCH, CHTYPES_TARGET, XDG_CACHE_HOME
|
|
62
|
+
`;
|
|
63
|
+
const defaultIo = {
|
|
64
|
+
stdout: (text) => process.stdout.write(text),
|
|
65
|
+
stderr: (text) => process.stderr.write(text),
|
|
66
|
+
tty: process.stderr.isTTY === true,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Run the command with `argv` (the arguments after the program name) and
|
|
70
|
+
* return its exit code. Never throws for a user-facing failure: every §7
|
|
71
|
+
* verdict is printed to stderr and mapped to its exit code.
|
|
72
|
+
*/
|
|
73
|
+
export async function runCli(argv, io = defaultIo) {
|
|
74
|
+
let parsed;
|
|
75
|
+
try {
|
|
76
|
+
parsed = parseArgs({ ...CONFIG, args: [...argv] });
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
io.stderr(`chtypes: ${err instanceof Error ? err.message : String(err)}\n${USAGE}`);
|
|
80
|
+
return EXIT.usage;
|
|
81
|
+
}
|
|
82
|
+
const { values, positionals } = parsed;
|
|
83
|
+
if (values.help) {
|
|
84
|
+
io.stdout(USAGE);
|
|
85
|
+
return EXIT.ok;
|
|
86
|
+
}
|
|
87
|
+
if (values.version) {
|
|
88
|
+
io.stdout(`${packageVersion()}\n`);
|
|
89
|
+
return EXIT.ok;
|
|
90
|
+
}
|
|
91
|
+
const [command, ...rest] = positionals;
|
|
92
|
+
if (command === undefined) {
|
|
93
|
+
io.stderr(USAGE);
|
|
94
|
+
return EXIT.usage;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
switch (command) {
|
|
98
|
+
case 'fetch':
|
|
99
|
+
return await cmdFetch(rest, values, io);
|
|
100
|
+
case 'verify':
|
|
101
|
+
return await cmdVerify(rest, values, io);
|
|
102
|
+
case 'list':
|
|
103
|
+
return await cmdList(rest, values, io);
|
|
104
|
+
case 'where':
|
|
105
|
+
return cmdWhere(rest, values, io);
|
|
106
|
+
default:
|
|
107
|
+
io.stderr(`chtypes: unknown command ${JSON.stringify(command)}\n${USAGE}`);
|
|
108
|
+
return EXIT.usage;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
return report(err, io);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const CONFIG = {
|
|
116
|
+
allowPositionals: true,
|
|
117
|
+
strict: true,
|
|
118
|
+
options: {
|
|
119
|
+
all: { type: 'boolean' },
|
|
120
|
+
platform: { type: 'string' },
|
|
121
|
+
dest: { type: 'string' },
|
|
122
|
+
tag: { type: 'string' },
|
|
123
|
+
url: { type: 'string' },
|
|
124
|
+
lock: { type: 'string' },
|
|
125
|
+
frozen: { type: 'boolean' },
|
|
126
|
+
force: { type: 'boolean' },
|
|
127
|
+
offline: { type: 'boolean' },
|
|
128
|
+
quiet: { type: 'boolean', short: 'q' },
|
|
129
|
+
help: { type: 'boolean', short: 'h' },
|
|
130
|
+
version: { type: 'boolean', short: 'V' },
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
function ensureOptions(values, io) {
|
|
134
|
+
if (values.url !== undefined && values.tag !== undefined) {
|
|
135
|
+
throw new ChtypesError('chtypes: --url names a full base; --tag selects a release on the artifacts host — pass one');
|
|
136
|
+
}
|
|
137
|
+
const lock = values.lock ?? (values.frozen ? 'chtypes.lock' : undefined);
|
|
138
|
+
return {
|
|
139
|
+
dest: values.dest,
|
|
140
|
+
platform: values.platform,
|
|
141
|
+
tag: values.tag,
|
|
142
|
+
url: values.url,
|
|
143
|
+
lock,
|
|
144
|
+
frozen: values.frozen ?? false,
|
|
145
|
+
force: values.force ?? false,
|
|
146
|
+
offline: values.offline ?? false,
|
|
147
|
+
onProgress: values.quiet ? undefined : progressPrinter(io),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function cmdFetch(lines, values, io) {
|
|
151
|
+
const options = ensureOptions(values, io);
|
|
152
|
+
if (values.all) {
|
|
153
|
+
if (lines.length > 0) {
|
|
154
|
+
throw new ChtypesError(`chtypes: --all installs every published line; drop the version argument (${lines.join(', ')})`);
|
|
155
|
+
}
|
|
156
|
+
const results = await ensureAll(options);
|
|
157
|
+
if (results.length === 0)
|
|
158
|
+
throw new ArtifactUnpublishedError('chtypes: the release publishes nothing for this platform');
|
|
159
|
+
for (const r of results)
|
|
160
|
+
io.stdout(`${r.dir}\n`);
|
|
161
|
+
say(io, `${results.length} line(s) installed into ${results[0].registry}`);
|
|
162
|
+
return EXIT.ok;
|
|
163
|
+
}
|
|
164
|
+
if (lines.length === 0) {
|
|
165
|
+
io.stderr(`chtypes: a ClickHouse line is required (or --all)\n${USAGE}`);
|
|
166
|
+
return EXIT.usage;
|
|
167
|
+
}
|
|
168
|
+
for (const line of lines) {
|
|
169
|
+
const r = await ensure(line, options);
|
|
170
|
+
io.stdout(`${r.dir}\n`);
|
|
171
|
+
}
|
|
172
|
+
return EXIT.ok;
|
|
173
|
+
}
|
|
174
|
+
async function cmdVerify(rest, values, io) {
|
|
175
|
+
if (rest.length > 0)
|
|
176
|
+
throw new ChtypesError(`chtypes: verify takes no positional arguments (${rest.join(', ')})`);
|
|
177
|
+
const platform = resolvePlatform(values.platform);
|
|
178
|
+
const dir = fetchDestination(values.dest, platform);
|
|
179
|
+
const results = await verifyInstalled(values.dest, platform);
|
|
180
|
+
if (results.length === 0) {
|
|
181
|
+
say(io, `nothing installed in ${dir}`);
|
|
182
|
+
return EXIT.ok;
|
|
183
|
+
}
|
|
184
|
+
let bad = 0;
|
|
185
|
+
for (const r of results) {
|
|
186
|
+
if (r.ok)
|
|
187
|
+
io.stdout(`ok ${r.line.padEnd(6)} ${r.version.padEnd(18)} ${r.library} sha256 ${r.actual}\n`);
|
|
188
|
+
else {
|
|
189
|
+
bad += 1;
|
|
190
|
+
io.stdout(`BAD ${r.line.padEnd(6)} ${r.version.padEnd(18)} ${r.library} ${r.problem}\n`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
say(io, bad === 0 ? `${results.length} line(s) verified in ${dir}` : `${bad} of ${results.length} line(s) FAILED verification in ${dir}`);
|
|
194
|
+
return bad === 0 ? EXIT.ok : EXIT.verificationFailed;
|
|
195
|
+
}
|
|
196
|
+
async function cmdList(rest, values, io) {
|
|
197
|
+
if (rest.length > 0)
|
|
198
|
+
throw new ChtypesError(`chtypes: list takes no positional arguments (${rest.join(', ')})`);
|
|
199
|
+
const options = ensureOptions(values, io);
|
|
200
|
+
const listing = await listArtifacts({ ...options, onProgress: undefined });
|
|
201
|
+
io.stdout(`installed in ${listing.registry} (${listing.platform}):\n`);
|
|
202
|
+
if (listing.installed.length === 0)
|
|
203
|
+
io.stdout(' (nothing)\n');
|
|
204
|
+
for (const a of listing.installed) {
|
|
205
|
+
io.stdout(` ${a.line.padEnd(6)} ${a.version.padEnd(18)} ${a.library}${a.ok ? '' : ` (${a.problem})`}\n`);
|
|
206
|
+
}
|
|
207
|
+
if (listing.offered !== null) {
|
|
208
|
+
const have = new Set(listing.installed.filter((a) => a.ok).map((a) => a.version));
|
|
209
|
+
io.stdout(`release ${listing.source} offers for ${listing.platform}:\n`);
|
|
210
|
+
if (listing.offered.length === 0)
|
|
211
|
+
io.stdout(' (nothing)\n');
|
|
212
|
+
for (const a of listing.offered) {
|
|
213
|
+
io.stdout(` ${a.clickhouse_minor.padEnd(6)} ${a.clickhouse_version.padEnd(18)} ${a.file} ${a.bytes} bytes${have.has(a.clickhouse_version) ? ' (installed)' : ''}\n`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return EXIT.ok;
|
|
217
|
+
}
|
|
218
|
+
function cmdWhere(rest, values, io) {
|
|
219
|
+
if (rest.length > 0)
|
|
220
|
+
throw new ChtypesError(`chtypes: where takes no positional arguments (${rest.join(', ')})`);
|
|
221
|
+
io.stdout(`${fetchDestination(values.dest, resolvePlatform(values.platform))}\n`);
|
|
222
|
+
return EXIT.ok;
|
|
223
|
+
}
|
|
224
|
+
/** Map an error to its §6 exit code, after printing it. */
|
|
225
|
+
function report(err, io) {
|
|
226
|
+
if (err instanceof FetchError) {
|
|
227
|
+
io.stderr(`${err.message} [${err.code}]\n`);
|
|
228
|
+
if (err instanceof SourceUnreachableError)
|
|
229
|
+
return EXIT.sourceUnreachable;
|
|
230
|
+
if (err instanceof ArtifactUnpublishedError)
|
|
231
|
+
return EXIT.unpublished;
|
|
232
|
+
return EXIT.verificationFailed;
|
|
233
|
+
}
|
|
234
|
+
if (err instanceof ChtypesError) {
|
|
235
|
+
io.stderr(`${err.message}\n`);
|
|
236
|
+
return EXIT.usage;
|
|
237
|
+
}
|
|
238
|
+
io.stderr(`chtypes: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
239
|
+
return EXIT.verificationFailed;
|
|
240
|
+
}
|
|
241
|
+
function say(io, message) {
|
|
242
|
+
io.stderr(io.tty ? `[1m==> ${message}[0m\n` : `==> ${message}\n`);
|
|
243
|
+
}
|
|
244
|
+
/** Status lines as `==> …`; download progress redrawn in place on a terminal, at 10 % steps otherwise. */
|
|
245
|
+
function progressPrinter(io) {
|
|
246
|
+
let lastStep = -1;
|
|
247
|
+
let drawing = false;
|
|
248
|
+
return (event) => {
|
|
249
|
+
if (event.type === 'status') {
|
|
250
|
+
if (drawing) {
|
|
251
|
+
io.stderr('\n');
|
|
252
|
+
drawing = false;
|
|
253
|
+
}
|
|
254
|
+
say(io, event.message);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const pct = event.total > 0 ? Math.min(100, Math.floor((event.received * 100) / event.total)) : 0;
|
|
258
|
+
const mb = (n) => (n / 1e6).toFixed(1);
|
|
259
|
+
if (io.tty) {
|
|
260
|
+
io.stderr(`\r ${event.file} ${mb(event.received)} / ${mb(event.total)} MB ${pct}%`);
|
|
261
|
+
drawing = true;
|
|
262
|
+
if (event.received >= event.total) {
|
|
263
|
+
io.stderr('\n');
|
|
264
|
+
drawing = false;
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const step = Math.floor(pct / 10);
|
|
269
|
+
if (step !== lastStep) {
|
|
270
|
+
lastStep = step;
|
|
271
|
+
io.stderr(` ${event.file} ${mb(event.received)} / ${mb(event.total)} MB ${pct}%\n`);
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function packageVersion() {
|
|
276
|
+
try {
|
|
277
|
+
const pkg = createRequire(import.meta.url)('../package.json');
|
|
278
|
+
return pkg.version ?? '0.0.0';
|
|
279
|
+
}
|
|
280
|
+
catch {
|
|
281
|
+
return '0.0.0';
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function invokedDirectly() {
|
|
285
|
+
const entry = process.argv[1];
|
|
286
|
+
if (entry === undefined)
|
|
287
|
+
return false;
|
|
288
|
+
try {
|
|
289
|
+
return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (invokedDirectly()) {
|
|
296
|
+
runCli(process.argv.slice(2)).then((code) => {
|
|
297
|
+
process.exitCode = code;
|
|
298
|
+
}, (err) => {
|
|
299
|
+
process.stderr.write(`chtypes: ${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
300
|
+
process.exitCode = EXIT.verificationFailed;
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;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B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAChC,CAAC,IAAI,EAAE,EAAE;QACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,EACD,CAAC,GAAY,EAAE,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC;IAC7C,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The discovery kit.
|
|
3
|
+
*
|
|
4
|
+
* This library NEVER talks to ClickHouse; it ships the queries. At connect
|
|
5
|
+
* time a caller (a gateway, WaveHouse) runs these three queries against the
|
|
6
|
+
* deployment's own server with whatever client it already has, feeds the
|
|
7
|
+
* results to the typed parsers below, and then declares what it learned:
|
|
8
|
+
*
|
|
9
|
+
* profile.version -> Registry#for / the artifact to load
|
|
10
|
+
* profile.settings -> compileDdl({ settings }) (compile-time) and per-call settings
|
|
11
|
+
* columns -> reconstructDdl -> compileDdl
|
|
12
|
+
*
|
|
13
|
+
* The pattern, in full (spec/bindings.md §Discovery):
|
|
14
|
+
*
|
|
15
|
+
* 1. run QUERY_SERVER_VERSION, QUERY_CHANGED_SETTINGS once per connection
|
|
16
|
+
* 2. cache the ServerProfile per deployment/tenant
|
|
17
|
+
* 3. const lib = registry.for(profile.version)
|
|
18
|
+
* 4. const schema = lib.compileDdl(ddl, { settings: profile.settings, mode: 0 })
|
|
19
|
+
* 5. per call: pass profile.settings (plus any per-INSERT overrides) to rows()
|
|
20
|
+
*
|
|
21
|
+
* Never ask the customer for their settings — ask their server. The queries
|
|
22
|
+
* return exactly what the server believes, spelled the way the server spells
|
|
23
|
+
* it, which is what the settings gate (spec/c-abi.md, Settings rule 2)
|
|
24
|
+
* validates against.
|
|
25
|
+
*
|
|
26
|
+
* The parsers read JSONEachRow bytes through this package's own byte-exact
|
|
27
|
+
* JSON reader, so a numeric field (`position`) is taken from its literal
|
|
28
|
+
* digits — quoted or bare, ClickHouse's stock HTTP output quotes 64-bit
|
|
29
|
+
* integers — and never routed through a float.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Names the deployment's exact release — the string `Registry#for` resolves
|
|
33
|
+
* (minor line or exact patch both work). One row: `{"version":"25.8.28.1"}`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const QUERY_SERVER_VERSION = "SELECT version() AS version FORMAT JSONEachRow";
|
|
36
|
+
/**
|
|
37
|
+
* Lists every query setting the deployment runs at a NON-default value — the
|
|
38
|
+
* whole declared profile, from the server itself. One row per setting:
|
|
39
|
+
* `{"name":"flatten_nested","value":"0"}`. `system.settings.value` is already
|
|
40
|
+
* a String; the map feeds `compileDdl({ settings })` and per-call settings
|
|
41
|
+
* verbatim.
|
|
42
|
+
*/
|
|
43
|
+
export declare const QUERY_CHANGED_SETTINGS = "SELECT name, value FROM system.settings WHERE changed FORMAT JSONEachRow";
|
|
44
|
+
/**
|
|
45
|
+
* Describes one existing table, in declaration order, with everything a
|
|
46
|
+
* column-declaration list needs — INCLUDING `default_kind` and
|
|
47
|
+
* `default_expression`, without which a reconstructed schema silently loses
|
|
48
|
+
* its DEFAULT/MATERIALIZED semantics. Uses ClickHouse's own query parameters:
|
|
49
|
+
* send `param_db` / `param_table` (HTTP) or bind `{db}`/`{table}` (native).
|
|
50
|
+
*/
|
|
51
|
+
export declare const QUERY_TABLE_COLUMNS: string;
|
|
52
|
+
/**
|
|
53
|
+
* What discovery learns about one deployment: the exact release and the
|
|
54
|
+
* settings it runs changed from defaults. Cache one per deployment (or per
|
|
55
|
+
* tenant on bring-your-own-ClickHouse) and declare it.
|
|
56
|
+
*/
|
|
57
|
+
export interface ServerProfile {
|
|
58
|
+
/** e.g. "25.8.28.1" — feed `Registry#for`. */
|
|
59
|
+
readonly version: string;
|
|
60
|
+
/** Changed settings — feed `compileDdl({ settings })` and per-call settings. */
|
|
61
|
+
readonly settings: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
/** One row of `QUERY_TABLE_COLUMNS`. */
|
|
64
|
+
export interface DiscoveredColumn {
|
|
65
|
+
readonly name: string;
|
|
66
|
+
readonly type: string;
|
|
67
|
+
/** "" | "DEFAULT" | "MATERIALIZED" | "ALIAS" | "EPHEMERAL" */
|
|
68
|
+
readonly defaultKind: string;
|
|
69
|
+
readonly defaultExpression: string;
|
|
70
|
+
readonly position: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Read `QUERY_SERVER_VERSION`'s JSONEachRow body.
|
|
74
|
+
*
|
|
75
|
+
* @param body - the query result bytes (or text) as the server sent them.
|
|
76
|
+
* @returns the version string, e.g. `"25.8.28.1"` — feed `Registry#for`.
|
|
77
|
+
* @throws {ChtypesError} when the body is not exactly one JSONEachRow row with
|
|
78
|
+
* a non-empty `version` field.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseVersionResult(body: Uint8Array | string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Read `QUERY_CHANGED_SETTINGS`' JSONEachRow body. An empty body is a stock
|
|
83
|
+
* server: an empty map, not an error.
|
|
84
|
+
*
|
|
85
|
+
* @param body - the query result bytes (or text) as the server sent them.
|
|
86
|
+
* @returns setting name → value, ready for `ServerProfile#settings`,
|
|
87
|
+
* `compileDdl({ settings })` and per-call settings.
|
|
88
|
+
* @throws {ChtypesError} when a row is not JSONEachRow or lacks `name`/`value`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseChangedSettingsResult(body: Uint8Array | string): Record<string, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Read `QUERY_TABLE_COLUMNS`' JSONEachRow body, in the query's ORDER BY
|
|
93
|
+
* position order. `position` survives both spellings — quoted on stock HTTP
|
|
94
|
+
* output (`output_format_json_quote_64bit_integers=1`) and bare when a client
|
|
95
|
+
* unsets that — parsed from its literal digits, never through `JSON.parse`'s
|
|
96
|
+
* double. A position is small, so it fits a JS number once those digits are
|
|
97
|
+
* in hand; a malformed one is left 0, as the reference leaves it.
|
|
98
|
+
*
|
|
99
|
+
* @param body - the query result bytes (or text) as the server sent them.
|
|
100
|
+
* @returns one `DiscoveredColumn` per row, in the query's position order —
|
|
101
|
+
* feed `reconstructDdl`.
|
|
102
|
+
* @throws {ChtypesError} when a row is malformed, lacks `name`/`type`, or the
|
|
103
|
+
* body holds no rows at all (wrong database/table, or no access).
|
|
104
|
+
*/
|
|
105
|
+
export declare function parseColumnsResult(body: Uint8Array | string): DiscoveredColumn[];
|
|
106
|
+
/**
|
|
107
|
+
* Turn `QUERY_TABLE_COLUMNS`' rows back into the column-declaration list
|
|
108
|
+
* `compileDdl` takes. It is a spelling exercise, not a semantic one: types
|
|
109
|
+
* and expressions are the server's own text, passed through verbatim, and the
|
|
110
|
+
* library's own compile is the judge of the result.
|
|
111
|
+
*
|
|
112
|
+
* Two facts a caller must know, both properties of the server rather than of
|
|
113
|
+
* this function:
|
|
114
|
+
*
|
|
115
|
+
* - `system.columns` reports the table AS STORED. Under the default
|
|
116
|
+
* `flatten_nested=1` a `Nested(a,b)` column appears as its flattened
|
|
117
|
+
* `n.a`/`n.b` Array columns and reconstructs to exactly those — which is
|
|
118
|
+
* the same table. Under `flatten_nested=0` it appears as one column of
|
|
119
|
+
* type `Nested(...)`, which also reconstructs directly. Reconstruction is
|
|
120
|
+
* therefore shape-faithful either way, PROVIDED the same `flatten_nested`
|
|
121
|
+
* value is declared to `compileDdl({ settings })` that the table was
|
|
122
|
+
* created under — which is what the discovered `ServerProfile.settings`
|
|
123
|
+
* carries.
|
|
124
|
+
* - a MATERIALIZED/ALIAS column reconstructs with its expression; an
|
|
125
|
+
* EPHEMERAL column may legitimately have an empty `default_expression`.
|
|
126
|
+
*
|
|
127
|
+
* @param cols - the discovered columns, e.g. from `parseColumnsResult`.
|
|
128
|
+
* @returns the column-declaration list for `Library#compileDdl`.
|
|
129
|
+
* @throws {ChtypesError} when a column is inconsistent: no name/type, a
|
|
130
|
+
* `default_expression` with no kind, a DEFAULT/MATERIALIZED/ALIAS kind with
|
|
131
|
+
* no expression, an unknown kind, or no columns at all.
|
|
132
|
+
*/
|
|
133
|
+
export declare function reconstructDdl(cols: readonly DiscoveredColumn[]): string;
|
|
134
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAUH;;;GAGG;AACH,eAAO,MAAM,oBAAoB,mDAAmD,CAAC;AAErF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,6EAA6E,CAAC;AAEjH;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,QAGQ,CAAC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAsED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,U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