@wavehouse/chtypes 0.5.2 → 1.0.2
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 +34 -0
- package/README.md +34 -38
- package/dist/abi1/buildinfo.d.ts +40 -0
- package/dist/abi1/buildinfo.d.ts.map +1 -0
- package/dist/abi1/buildinfo.js +83 -0
- package/dist/abi1/buildinfo.js.map +1 -0
- package/dist/abi1/calls.gen.d.ts +55 -0
- package/dist/abi1/calls.gen.d.ts.map +1 -0
- package/dist/abi1/calls.gen.js +110 -0
- package/dist/abi1/calls.gen.js.map +1 -0
- package/dist/abi1/decls.gen.d.ts +115 -0
- package/dist/abi1/decls.gen.d.ts.map +1 -0
- package/dist/abi1/decls.gen.js +1613 -0
- package/dist/abi1/decls.gen.js.map +1 -0
- package/dist/abi1/errmap.gen.d.ts +18 -0
- package/dist/abi1/errmap.gen.d.ts.map +1 -0
- package/dist/abi1/errmap.gen.js +66 -0
- package/dist/abi1/errmap.gen.js.map +1 -0
- package/dist/abi1/errors.d.ts +107 -0
- package/dist/abi1/errors.d.ts.map +1 -0
- package/dist/abi1/errors.js +134 -0
- package/dist/abi1/errors.js.map +1 -0
- package/dist/abi1/handles.d.ts +31 -0
- package/dist/abi1/handles.d.ts.map +1 -0
- package/dist/abi1/handles.js +76 -0
- package/dist/abi1/handles.js.map +1 -0
- package/dist/abi1/index.d.ts +17 -0
- package/dist/abi1/index.d.ts.map +1 -0
- package/dist/abi1/index.js +17 -0
- package/dist/abi1/index.js.map +1 -0
- package/dist/abi1/libc.d.ts +54 -0
- package/dist/abi1/libc.d.ts.map +1 -0
- package/dist/abi1/libc.gen.d.ts +12 -0
- package/dist/abi1/libc.gen.d.ts.map +1 -0
- package/dist/abi1/libc.gen.js +75 -0
- package/dist/abi1/libc.gen.js.map +1 -0
- package/dist/abi1/libc.js +109 -0
- package/dist/abi1/libc.js.map +1 -0
- package/dist/abi1/loader.d.ts +101 -0
- package/dist/abi1/loader.d.ts.map +1 -0
- package/dist/abi1/loader.js +274 -0
- package/dist/abi1/loader.js.map +1 -0
- package/dist/abi1/raw.d.ts +104 -0
- package/dist/abi1/raw.d.ts.map +1 -0
- package/dist/abi1/raw.js +296 -0
- package/dist/abi1/raw.js.map +1 -0
- package/dist/abi1/strictjson.d.ts +19 -0
- package/dist/abi1/strictjson.d.ts.map +1 -0
- package/dist/abi1/strictjson.js +78 -0
- package/dist/abi1/strictjson.js.map +1 -0
- package/dist/abi1/vocab.gen.d.ts +169 -0
- package/dist/abi1/vocab.gen.d.ts.map +1 -0
- package/dist/abi1/vocab.gen.js +306 -0
- package/dist/abi1/vocab.gen.js.map +1 -0
- package/dist/cli.d.ts +25 -26
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +206 -218
- package/dist/cli.js.map +1 -1
- package/dist/documents.d.ts +195 -0
- package/dist/documents.d.ts.map +1 -0
- package/dist/documents.js +389 -0
- package/dist/documents.js.map +1 -0
- package/dist/env.d.ts +16 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +57 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +19 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -23
- package/dist/index.js.map +1 -1
- package/dist/json.d.ts +11 -89
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +16 -180
- package/dist/json.js.map +1 -1
- package/dist/library.d.ts +53 -309
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +77 -315
- package/dist/library.js.map +1 -1
- package/dist/ocifetch/constants.gen.d.ts +84 -0
- package/dist/ocifetch/constants.gen.d.ts.map +1 -0
- package/dist/ocifetch/constants.gen.js +92 -0
- package/dist/ocifetch/constants.gen.js.map +1 -0
- package/dist/ocifetch/dsse.d.ts +114 -0
- package/dist/ocifetch/dsse.d.ts.map +1 -0
- package/dist/ocifetch/dsse.js +331 -0
- package/dist/ocifetch/dsse.js.map +1 -0
- package/dist/ocifetch/ensure.d.ts +65 -0
- package/dist/ocifetch/ensure.d.ts.map +1 -0
- package/dist/ocifetch/ensure.js +775 -0
- package/dist/ocifetch/ensure.js.map +1 -0
- package/dist/ocifetch/errors.d.ts +92 -0
- package/dist/ocifetch/errors.d.ts.map +1 -0
- package/dist/ocifetch/errors.js +101 -0
- package/dist/ocifetch/errors.js.map +1 -0
- package/dist/ocifetch/goldens.d.ts +44 -0
- package/dist/ocifetch/goldens.d.ts.map +1 -0
- package/dist/ocifetch/goldens.js +62 -0
- package/dist/ocifetch/goldens.js.map +1 -0
- package/dist/ocifetch/http.d.ts +124 -0
- package/dist/ocifetch/http.d.ts.map +1 -0
- package/dist/ocifetch/http.js +549 -0
- package/dist/ocifetch/http.js.map +1 -0
- package/dist/ocifetch/index.d.ts +17 -0
- package/dist/ocifetch/index.d.ts.map +1 -0
- package/dist/ocifetch/index.js +14 -0
- package/dist/ocifetch/index.js.map +1 -0
- package/dist/ocifetch/layout.d.ts +126 -0
- package/dist/ocifetch/layout.d.ts.map +1 -0
- package/dist/ocifetch/layout.js +375 -0
- package/dist/ocifetch/layout.js.map +1 -0
- package/dist/ocifetch/localverify.d.ts +43 -0
- package/dist/ocifetch/localverify.d.ts.map +1 -0
- package/dist/ocifetch/localverify.js +164 -0
- package/dist/ocifetch/localverify.js.map +1 -0
- package/dist/ocifetch/lock.d.ts +39 -0
- package/dist/ocifetch/lock.d.ts.map +1 -0
- package/dist/ocifetch/lock.js +140 -0
- package/dist/ocifetch/lock.js.map +1 -0
- package/dist/ocifetch/oci.d.ts +100 -0
- package/dist/ocifetch/oci.d.ts.map +1 -0
- package/dist/ocifetch/oci.js +323 -0
- package/dist/ocifetch/oci.js.map +1 -0
- package/dist/ocifetch/referrers.d.ts +55 -0
- package/dist/ocifetch/referrers.d.ts.map +1 -0
- package/dist/ocifetch/referrers.js +132 -0
- package/dist/ocifetch/referrers.js.map +1 -0
- package/dist/ocifetch/types.d.ts +167 -0
- package/dist/ocifetch/types.d.ts.map +1 -0
- package/dist/ocifetch/types.js +88 -0
- package/dist/ocifetch/types.js.map +1 -0
- package/dist/ocifetch/unpack.d.ts +55 -0
- package/dist/ocifetch/unpack.d.ts.map +1 -0
- package/dist/ocifetch/unpack.js +205 -0
- package/dist/ocifetch/unpack.js.map +1 -0
- package/dist/registry.d.ts +38 -387
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +95 -819
- package/dist/registry.js.map +1 -1
- package/dist/schema.d.ts +77 -588
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +87 -549
- package/dist/schema.js.map +1 -1
- package/dist/settings.d.ts +27 -36
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +75 -25
- package/dist/settings.js.map +1 -1
- package/dist/setup.d.ts +46 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +79 -0
- package/dist/setup.js.map +1 -0
- package/dist/tar.d.ts +27 -11
- package/dist/tar.d.ts.map +1 -1
- package/dist/tar.js +54 -32
- package/dist/tar.js.map +1 -1
- package/package.json +2 -2
- package/dist/discover.d.ts +0 -142
- package/dist/discover.d.ts.map +0 -1
- package/dist/discover.js +0 -288
- package/dist/discover.js.map +0 -1
- package/dist/error-codes.d.ts +0 -80
- package/dist/error-codes.d.ts.map +0 -1
- package/dist/error-codes.js +0 -139
- package/dist/error-codes.js.map +0 -1
- package/dist/errors.d.ts +0 -284
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -321
- package/dist/errors.js.map +0 -1
- package/dist/fetch.d.ts +0 -382
- package/dist/fetch.d.ts.map +0 -1
- package/dist/fetch.js +0 -1498
- package/dist/fetch.js.map +0 -1
- package/dist/ffi.d.ts +0 -410
- package/dist/ffi.d.ts.map +0 -1
- package/dist/ffi.js +0 -1154
- package/dist/ffi.js.map +0 -1
- package/dist/format.d.ts +0 -128
- package/dist/format.d.ts.map +0 -1
- package/dist/format.js +0 -132
- package/dist/format.js.map +0 -1
- package/dist/numeric.d.ts +0 -20
- package/dist/numeric.d.ts.map +0 -1
- package/dist/numeric.js +0 -107
- package/dist/numeric.js.map +0 -1
- package/dist/paths.d.ts +0 -55
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -87
- package/dist/paths.js.map +0 -1
- package/dist/results.d.ts +0 -495
- package/dist/results.d.ts.map +0 -1
- package/dist/results.js +0 -406
- package/dist/results.js.map +0 -1
- package/dist/transform.d.ts +0 -73
- package/dist/transform.d.ts.map +0 -1
- package/dist/transform.js +0 -533
- package/dist/transform.js.map +0 -1
package/dist/schema.d.ts
CHANGED
|
@@ -1,611 +1,100 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { type BatchResult, type FilterResult, type RowResult } from './results.js';
|
|
9
|
-
import { type Settings } from './settings.js';
|
|
10
|
-
/**
|
|
11
|
-
* Native state a `Schema`'s GC finalizer frees from, tracked separately from
|
|
12
|
-
* the `Schema` object itself: a `FinalizationRegistry` callback must never
|
|
13
|
-
* hold (or close over) a reference to the object it was registered for —
|
|
14
|
-
* that would keep it reachable forever and the finalizer would never run.
|
|
2
|
+
* `Schema`, `Filter` and `Block`: the compiled objects of `docs/reference/bindings-v1.md` §2.
|
|
3
|
+
*
|
|
4
|
+
* Every public call makes exactly one ABI call over the generated, typed
|
|
5
|
+
* layer, then decodes the document it returned (`./documents.ts`) and
|
|
6
|
+
* computes nothing. The per-call zone is the `session_timezone` key of the
|
|
7
|
+
* call's settings and nothing more (`./settings.ts`).
|
|
15
8
|
*
|
|
16
|
-
*
|
|
17
|
-
* `
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* depend on which one happens to fire first.
|
|
9
|
+
* Handles. Each object holds the generated layer's handle wrapper, whose
|
|
10
|
+
* `ptr` raises a `UsageError` naming the object once it is closed, before any
|
|
11
|
+
* C call. A filter or a block holds a counted reference to its schema inside
|
|
12
|
+
* the library, so a binding object neither holds its parent alive nor orders
|
|
13
|
+
* its frees: closing a schema while its filters are in use is legal, and
|
|
14
|
+
* `close` is idempotent. A `FinalizationRegistry` per handle class frees what
|
|
15
|
+
* the caller abandons. TypeScript runs every call synchronously on one
|
|
16
|
+
* thread, so the close guard of the other bindings reduces to this check: no
|
|
17
|
+
* call is ever in flight while `close` runs.
|
|
26
18
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
readonly
|
|
36
|
-
/** Canonical type — pass it through verbatim, never re-normalize whitespace. */
|
|
37
|
-
readonly type: string;
|
|
38
|
-
/** "" | "DEFAULT" | "MATERIALIZED" | "ALIAS" | "EPHEMERAL" */
|
|
39
|
-
readonly defaultKind: string;
|
|
40
|
-
readonly defaultExpr: string;
|
|
41
|
-
/** True when the DEFAULT is a literal applicable without the interpreter. */
|
|
42
|
-
readonly defaultIsLiteral: boolean;
|
|
43
|
-
}
|
|
44
|
-
/** Options for `Schema#setEngine` — the table's MergeTree-namespace settings. */
|
|
45
|
-
export interface EngineOptions {
|
|
46
|
-
/**
|
|
47
|
-
* The `SETTINGS` clause after the engine — `allow_nullable_key` and friends,
|
|
48
|
-
* a namespace `DB::Settings` cannot carry (the C ABI contract §`chs_schema_engine`).
|
|
49
|
-
* Absent or empty is structurally identical to the plain engine declaration:
|
|
50
|
-
* `chs_schema_engine` takes "{}" either way. Names are validated by the
|
|
51
|
-
* server's own `MergeTreeSettings` object: an unknown name throws the
|
|
52
|
-
* server's own 115; a known name declared at a NON-default value is refused
|
|
53
|
-
* (`unsupported`, naming it) — no MergeTree setting's behavior is modeled
|
|
54
|
-
* yet, and silently ignoring a declared value would mean the declared
|
|
55
|
-
* profile is not in force; a name declared AT its default is inert and
|
|
56
|
-
* accepted.
|
|
57
|
-
*/
|
|
58
|
-
readonly mergeTreeSettings?: Settings | undefined;
|
|
19
|
+
import type { BlockHandle, Calls, FilterHandle, SchemaHandle } from './abi1/index.js';
|
|
20
|
+
import { type Format } from './abi1/index.js';
|
|
21
|
+
import { type BatchResult, type FilterResult, type RowResult, type SchemaDescription } from './documents.js';
|
|
22
|
+
import { type BytesIn, type Settings } from './settings.js';
|
|
23
|
+
/** Options of `Library.compileTable`: the profile settings a schema compiles under, and the zone that profile defaults to. */
|
|
24
|
+
export interface CompileOptions {
|
|
25
|
+
readonly settings?: Settings | undefined;
|
|
26
|
+
/** In a compile profile it is a default for later calls on the schema; a compiled type always takes the image zone, never the profile's. */
|
|
27
|
+
readonly sessionTimezone?: string | undefined;
|
|
59
28
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Options for `Schema#row` and `Schema#parseBlock` — the revision-5 INSERT
|
|
62
|
-
* column list (the C ABI contract §Rows, for which include/chtypes.h is the
|
|
63
|
-
* public authority). `RowsOptions` (below) extends this with the
|
|
64
|
-
* revision-3 export/document-flag channels, which are meaningless on
|
|
65
|
-
* `row()` and `parseBlock()` — this type simply does not offer them, rather
|
|
66
|
-
* than offering fields those two methods would silently ignore.
|
|
67
|
-
*/
|
|
29
|
+
/** Options of `Schema.row` and `Schema.parseBlock`. */
|
|
68
30
|
export interface RowOptions {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
* Absent or an empty array is the no-list behavior of every revision
|
|
76
|
-
* before 5 — the data supplies every plain column — and is NEVER rendered
|
|
77
|
-
* as `INSERT INTO t () FORMAT X`: that is code 62 `SYNTAX_ERROR` on every
|
|
78
|
-
* line, so this binding always crosses the ABI's OTHER no-list spelling,
|
|
79
|
-
* `"[]"`, which `chs_row`'s own comment states is byte-for-byte the same
|
|
80
|
-
* input as a real NULL.
|
|
81
|
-
*
|
|
82
|
-
* With a list: positional formats address the k-th field to the k-th
|
|
83
|
-
* LISTED column (the list order, not declared order, is the wire order,
|
|
84
|
-
* and the list length is the arity); JSON-family formats match keys
|
|
85
|
-
* against the listed set, and a key naming an unlisted table column is an
|
|
86
|
-
* unknown field under `input_format_skip_unknown_fields`, exactly as a
|
|
87
|
-
* key naming no column at all. A listed `EPHEMERAL` column's value IS
|
|
88
|
-
* read and IS in scope for the DEFAULTs that reference it, and is still
|
|
89
|
-
* never stored and never exported — `chs_schema_column_default_kind`
|
|
90
|
-
* reports `'EPHEMERAL'` for it (see `ColumnInfo#defaultKind`).
|
|
91
|
-
*
|
|
92
|
-
* Not validated here: an unknown name, an `ALIAS` column, or a repeated
|
|
93
|
-
* name is the SERVER's own refusal (codes 16, 16 and 15 respectively),
|
|
94
|
-
* surfaced through the row/batch outcome exactly as it arrives.
|
|
95
|
-
*/
|
|
96
|
-
readonly columns?: readonly string[] | undefined;
|
|
31
|
+
readonly settings?: Settings | undefined;
|
|
32
|
+
/** The per-call zone: written into the settings as `session_timezone`, verbatim. */
|
|
33
|
+
readonly sessionTimezone?: string | undefined;
|
|
34
|
+
/** The INSERT column list. */
|
|
35
|
+
readonly columns?: readonly BytesIn[] | undefined;
|
|
97
36
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Options for `Schema#rows` — `RowOptions` (the revision-5 column list,
|
|
100
|
-
* shared with `row()` and `parseBlock()`) plus the revision-3
|
|
101
|
-
* export/document-flag channels (the C ABI contract §Rows, for which
|
|
102
|
-
* include/chtypes.h is the public authority). `tests/parity/manifest.json`
|
|
103
|
-
* capability `schema.columns-option` spells the shared column-list
|
|
104
|
-
* capability `RowsOptions` in TypeScript — this type still carries it, now
|
|
105
|
-
* through inheriting `RowOptions` rather than declaring its own `columns`
|
|
106
|
-
* field. Whatever the options, `rows()` is always ONE `chs_rows` call —
|
|
107
|
-
* never a second call, never re-parsing.
|
|
108
|
-
*/
|
|
37
|
+
/** Options of `Schema.rows`. */
|
|
109
38
|
export interface RowsOptions extends RowOptions {
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
* `outcome: 'unsupported'` and processes nothing — loud, never silent.
|
|
114
|
-
* Absent = no export: today's path, byte-identical to revision 2.
|
|
115
|
-
*/
|
|
39
|
+
/** A compiled filter evaluated over the body in the same call. */
|
|
40
|
+
readonly rowFilter?: Filter | undefined;
|
|
41
|
+
/** Ask for an export in this format; absent means none. */
|
|
116
42
|
readonly exportFormat?: Format | undefined;
|
|
117
|
-
/**
|
|
118
|
-
* A bitmask of `DOC_VALUES | DOC_TRANSFORMS | DOC_DEFAULTS` selecting the
|
|
119
|
-
* document groups; the verdict channel is always present and not a flag.
|
|
120
|
-
* Defaults: `DOC_ALL` when no `exportFormat` is given (the full document —
|
|
121
|
-
* plain `rows()` behavior), `0` (LEAN — verdicts only: `values`,
|
|
122
|
-
* `transformed`, `substituted`, `computed` and `unknownFields` all come
|
|
123
|
-
* back empty) when one is. An explicit value always wins; a bit outside
|
|
124
|
-
* `DOC_ALL` is refused loudly by the library, never pre-validated here.
|
|
125
|
-
*/
|
|
43
|
+
/** The document groups to carry; absent means all of them. */
|
|
126
44
|
readonly docFlags?: number | undefined;
|
|
127
|
-
/**
|
|
128
|
-
* Attach a compiled `Filter` to this call's export channel (revision 5,
|
|
129
|
-
* second half — docs/guides/filters.md "Exporting only the rows a filter
|
|
130
|
-
* admits"): ONE `chs_rows` parse then answers both the per-row verdict
|
|
131
|
-
* (`RowResult#verdict`) and, for rows whose verdict is `'t'`, the export
|
|
132
|
-
* bytes. Absent is today's behavior byte for byte.
|
|
133
|
-
*
|
|
134
|
-
* `'e'` (the predicate threw) and `'d'` (declined — including a row whose
|
|
135
|
-
* own parse `outcome` was not `'accepted'`) are NEVER exported and NEVER
|
|
136
|
-
* collapsed into `'f'`: collapsing either turns fail-closed into
|
|
137
|
-
* fail-open, the leak class this surface exists to prevent. A
|
|
138
|
-
* security-enforcing caller must treat any `RowResult#verdict` that is
|
|
139
|
-
* `undefined` or not `isAnswer()` as a refusal — hide the row or fail the
|
|
140
|
-
* request, never export it.
|
|
141
|
-
*
|
|
142
|
-
* The filter must be compiled over THIS schema: one from a different
|
|
143
|
-
* `Schema` of the SAME loaded library rejects the whole call, loudly
|
|
144
|
-
* (`outcome: 'rejected'`, code 1002 — the same cross-schema rule
|
|
145
|
-
* `Filter#eval` lets the C layer enforce for a (filter, block) pair). One
|
|
146
|
-
* from a DIFFERENT loaded library throws `ChtypesError` before any C
|
|
147
|
-
* call — no handle crosses a dlopen'd image boundary.
|
|
148
|
-
*/
|
|
149
|
-
readonly rowFilter?: Filter | undefined;
|
|
150
45
|
}
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
*/
|
|
155
|
-
export interface CompileFilterOptions {
|
|
156
|
-
/**
|
|
157
|
-
* `{name:Type}` query-parameter bindings: name → value STRING, exactly as
|
|
158
|
-
* the server's own parameter channels carry them. Each value is
|
|
159
|
-
* deserialized by the DECLARED type's own reader and injected as a typed
|
|
160
|
-
* literal AFTER SQL parsing, so a value is never SQL text and NEVER needs
|
|
161
|
-
* hand-escaping — injection safety is by construction, not by escaping
|
|
162
|
-
* (the C ABI contract §Filters, Query parameters). Do not render values into
|
|
163
|
-
* the expression yourself.
|
|
164
|
-
*
|
|
165
|
-
* CHOOSE THE BRACE TYPE FOR THE VALUE'S DOMAIN: the declared type's own
|
|
166
|
-
* reader WRAPS an out-of-domain integer — `{p:UInt8}` given `"256"` binds
|
|
167
|
-
* `0` and matches every genuine zero (measured, uniform 24.8–26.7) —
|
|
168
|
-
* while the same constant as a literal PROMOTES (`x = 256` is never
|
|
169
|
-
* true). Sizing the brace type WIDER does not remove this: the same wrap
|
|
170
|
-
* reappears at 2^64 on every integer width once the bound value reaches
|
|
171
|
-
* it, and `[U]Int128`/`[U]Int256` wrap at their own width instead of at
|
|
172
|
-
* 2^64 — no brace type is safe against an untrusted value's magnitude by
|
|
173
|
-
* size alone. For a value you cannot already validate as in-domain and
|
|
174
|
-
* canonical, bind `{p:String}` and use the round-trip strict-cast form
|
|
175
|
-
* instead of picking a wider brace type (docs/guides/filters.md "The
|
|
176
|
-
* round-trip form — the recipe for an untrusted value"). Malformed
|
|
177
|
-
* spellings refuse loudly (457 for `"-1"`/`"+7"`/`"007"` as UInt8, 32 for
|
|
178
|
-
* `""`). A name bound twice at the C boundary takes the LAST binding —
|
|
179
|
-
* the server's own `insert_or_assign` rule (unreachable through this
|
|
180
|
-
* unique-keyed object, stated for completeness).
|
|
181
|
-
*
|
|
182
|
-
* The compiled handle bakes the values in: identity is per
|
|
183
|
-
* (schema, expr, params), so changing a value means compiling a new
|
|
184
|
-
* `Filter`. A caller compiling filters from tenant-influenced values MUST
|
|
185
|
-
* bound its cache (an LRU keyed on schema generation + expr + params-hash)
|
|
186
|
-
* and its compile rate per principal — the key is attacker-influencable,
|
|
187
|
-
* so an unbounded cache is a memory DoS and an unmetered compile path is a
|
|
188
|
-
* CPU DoS.
|
|
189
|
-
*/
|
|
46
|
+
/** Options of `Schema.compileFilter`. */
|
|
47
|
+
export interface FilterOptions {
|
|
48
|
+
/** Query parameters the expression names (`{p:Type}`). */
|
|
190
49
|
readonly params?: Settings | undefined;
|
|
50
|
+
/** The filter's own zone and profile: fixed when it is compiled, and every evaluation of it runs its WHERE under them. */
|
|
51
|
+
readonly settings?: Settings | undefined;
|
|
52
|
+
readonly sessionTimezone?: string | undefined;
|
|
191
53
|
}
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* — `close()` stays the primary path; a GC finalizer that calls it for a
|
|
197
|
-
* schema nobody closed is a backstop, not a replacement, since there is no
|
|
198
|
-
* promise about WHEN (or, in principle, whether) it runs.
|
|
199
|
-
*
|
|
200
|
-
* Thread-safety: the C ABI forbids using one `chs_schema *` from two threads
|
|
201
|
-
* at once; on a single JS thread every call here is synchronous, so ordinary
|
|
202
|
-
* Node code satisfies that by construction. Do not share a `Schema` across
|
|
203
|
-
* `worker_threads`.
|
|
204
|
-
*/
|
|
205
|
-
export declare class Schema {
|
|
206
|
-
private readonly native;
|
|
207
|
-
/** The column-declaration list this schema was compiled from, verbatim. */
|
|
208
|
-
readonly ddl: string;
|
|
209
|
-
/**
|
|
210
|
-
* The declared columns as ClickHouse canonicalized them, in declaration
|
|
211
|
-
* order — flattened under `flatten_nested=1`, DEFAULT-rewritten types
|
|
212
|
-
* (`x Int64 DEFAULT NULL` compiles as `Nullable(Int64)`), ALIAS types
|
|
213
|
-
* inferred. A gateway detects EPHEMERAL columns here, at compile time
|
|
214
|
-
* (`defaultKind === 'EPHEMERAL'`), not per row.
|
|
215
|
-
*/
|
|
216
|
-
readonly columns: readonly ColumnInfo[];
|
|
217
|
-
/** The handle plus the GC-finalizer coordination state; see `SchemaNative`. */
|
|
218
|
-
private readonly n;
|
|
219
|
-
/**
|
|
220
|
-
* Every open `Filter` compiled from this handle, so `close()` can free them
|
|
221
|
-
* FIRST — the C layer does not refcount, and freeing the schema under a
|
|
222
|
-
* live filter is use-after-free (the C ABI contract §Filters, handle lifetime).
|
|
223
|
-
*/
|
|
224
|
-
private readonly filters;
|
|
225
|
-
/**
|
|
226
|
-
* Every open `Block` parsed from this handle — the same non-owning rule,
|
|
227
|
-
* the same free-before-schema order (the C ABI contract §Blocks).
|
|
228
|
-
*/
|
|
229
|
-
private readonly blocks;
|
|
230
|
-
/** @internal — obtained from `Library#compileDdl`. */
|
|
231
|
-
constructor(native: NativeLibrary, handle: SchemaHandle,
|
|
232
|
-
/** The column-declaration list this schema was compiled from, verbatim. */
|
|
233
|
-
ddl: string);
|
|
234
|
-
private live;
|
|
235
|
-
/**
|
|
236
|
-
* Declare the table engine, so `rows()` applies the engine's own insert-time
|
|
237
|
-
* merge (`optimize_on_insert = 1`): a CollapsingMergeTree refusing an invalid
|
|
238
|
-
* Sign with code 117 before anything is stored, a SummingMergeTree summing
|
|
239
|
-
* equal keys and dropping all-zero rows, a ReplacingMergeTree deduplicating.
|
|
240
|
-
*
|
|
241
|
-
* `options.mergeTreeSettings` declares the table's MergeTree-namespace
|
|
242
|
-
* settings — see `EngineOptions` for the error contract (unknown name ⇒ the
|
|
243
|
-
* server's 115; non-default declared value ⇒ `unsupported`, never silently
|
|
244
|
-
* ignored). Absent/empty is structurally the plain engine declaration:
|
|
245
|
-
* `chs_schema_engine` takes "{}" either way.
|
|
246
|
-
*
|
|
247
|
-
* The two error classes here are the refusal/decline split and MUST be
|
|
248
|
-
* handled as peers — `UnsupportedError` is deliberately NOT
|
|
249
|
-
* `instanceof SchemaError` (docs/reference/bindings.md rule 12):
|
|
250
|
-
*
|
|
251
|
-
* @param engine - the engine expression, e.g. `"SummingMergeTree"`,
|
|
252
|
-
* `"CollapsingMergeTree(sign)"`.
|
|
253
|
-
* @param orderBy - the sorting key, e.g. `"(day, key)"`.
|
|
254
|
-
* @param options - the MergeTree-namespace `SETTINGS` clause, if any.
|
|
255
|
-
* @throws {SchemaError} when the SERVER refused (positive code): this DDL
|
|
256
|
-
* can never exist and the tenant has to be told. Today that is 115, an
|
|
257
|
-
* unknown MergeTree setting name, with the server's own message verbatim.
|
|
258
|
-
* @throws {UnsupportedError} when this LIBRARY declined: an engine or
|
|
259
|
-
* sorting key this build does not model, a known MergeTree setting
|
|
260
|
-
* declared at a non-default value, or a guarded exception. A real server
|
|
261
|
-
* might well have accepted it — validate cautiously, fall back to the
|
|
262
|
-
* server, and never present the decline as a rejection.
|
|
263
|
-
*/
|
|
264
|
-
setEngine(engine: string, orderBy: string, options?: EngineOptions): void;
|
|
265
|
-
/**
|
|
266
|
-
* Declare the table's rows TTL (`ts + INTERVAL 30 DAY`). An expired row is
|
|
267
|
-
* reported NOT STORED through the batch's `transformed` list.
|
|
268
|
-
*
|
|
269
|
-
* Column-level TTLs need no call: they are part of the declaration list.
|
|
270
|
-
*
|
|
271
|
-
* @param ttl - the rows-TTL expression, e.g. `"ts + INTERVAL 30 DAY"`. It is
|
|
272
|
-
* validated under the handle's declared compile profile when one exists.
|
|
273
|
-
* @throws {UnsupportedError} for a TTL form this build refuses rather than
|
|
274
|
-
* guesses: WHERE / GROUP BY TTLs, TO DISK/VOLUME moves, RECOMPRESS, any
|
|
275
|
-
* clock-reading TTL expression, and guarded exceptions. Fall back to the
|
|
276
|
-
* server; do not report a tenant error.
|
|
277
|
-
*/
|
|
278
|
-
setTtl(ttl: string): void;
|
|
279
|
-
/**
|
|
280
|
-
* Declare the table's partition key — the `PARTITION BY` clause after the
|
|
281
|
-
* engine, e.g. `"toYYYYMM(ts)"` or `"(toDate(ts), tenant)"`
|
|
282
|
-
* (`chs_schema_partition_by`, revision 6). The key is built by the server's
|
|
283
|
-
* own CREATE-path call over this schema's columns, under the handle's
|
|
284
|
-
* compile profile. A second call REPLACES the first; `""` removes the
|
|
285
|
-
* declaration, and the schema then answers exactly as one that never
|
|
286
|
-
* declared a key.
|
|
287
|
-
*
|
|
288
|
-
* With a key declared, `row` and `rows` answer `RowResult#partitionId` for
|
|
289
|
-
* every row that would be stored and `BatchResult#partitionCount` for the
|
|
290
|
-
* batch, and a body that would split into more partitions than the call's
|
|
291
|
-
* `max_partitions_per_insert_block` allows is an ordinary `'rejected'` with
|
|
292
|
-
* `errCode` 252 (TOO_MANY_PARTS), the server's own — a verdict, never a
|
|
293
|
-
* throw.
|
|
294
|
-
*
|
|
295
|
-
* @param expr - the partition key expression, or `""` to remove it.
|
|
296
|
-
* @throws {SchemaError} when the server's own CREATE path refuses the key
|
|
297
|
-
* (e.g. 36 BAD_ARGUMENTS for a non-deterministic key, 549
|
|
298
|
-
* DATA_TYPE_CANNOT_BE_USED_IN_KEY) — `setEngine`'s SIGN rule, not
|
|
299
|
-
* `setTtl`'s.
|
|
300
|
-
* @throws {UnsupportedError} when this build declines (-1, a guarded
|
|
301
|
-
* exception), or the artifact predates `chs_schema_partition_by`. -2 is a
|
|
302
|
-
* key the server accepts but this build will not evaluate; a
|
|
303
|
-
* non-deterministic key is the server's own rejection, 36 BAD_ARGUMENTS.
|
|
304
|
-
*/
|
|
305
|
-
setPartitionBy(expr: string): void;
|
|
306
|
-
/**
|
|
307
|
-
* Validate and coerce ONE row body, answering exactly as this ClickHouse
|
|
308
|
-
* version's insert path would.
|
|
309
|
-
*
|
|
310
|
-
* There is no exception for a bad row: rejection, poisoning and declines all
|
|
311
|
-
* arrive as the `RowResult`'s `outcome` (see `Outcome` for the taxonomy and
|
|
312
|
-
* the caller's obligations per arm).
|
|
313
|
-
*
|
|
314
|
-
* @param format - the wire format code (`Format`). Binary-format support
|
|
315
|
-
* depends on the loaded artifact — probe, don't assume.
|
|
316
|
-
* @param raw - the row's bytes, exactly as they would arrive in an INSERT
|
|
317
|
-
* body. Always bytes, never a JS string: binary formats contain NUL bytes
|
|
318
|
-
* and text rows can carry invalid UTF-8 on purpose.
|
|
319
|
-
* @param settings - per-call settings; they win over the compile profile and
|
|
320
|
-
* the library defaults (except a type gate the profile declared, which the
|
|
321
|
-
* handle has already settled, as a real server's CREATE does).
|
|
322
|
-
* @param options - `RowOptions#columns` (revision 5), the INSERT column
|
|
323
|
-
* list. `row()` takes `RowOptions`, not `RowsOptions`: the revision-3
|
|
324
|
-
* export/doc-flag channels are meaningless on a single row, so this
|
|
325
|
-
* method's options type simply does not offer them.
|
|
326
|
-
* @returns the `RowResult` — verdict, stored values, and every silent change.
|
|
327
|
-
* @throws {ChtypesError} when the schema is closed, or a settings value is a
|
|
328
|
-
* JS `number`.
|
|
329
|
-
* @throws {UnsupportedError} when the artifact predates `chs_row`.
|
|
330
|
-
*/
|
|
331
|
-
row(format: Format, raw: Uint8Array, settings?: Settings, options?: RowOptions): RowResult;
|
|
332
|
-
/**
|
|
333
|
-
* Validate and coerce a whole request body, which may hold many rows.
|
|
334
|
-
*
|
|
335
|
-
* This is not `row()` in a loop and must never be implemented as one: row
|
|
336
|
-
* separation is format-specific (a quoted CSV field can contain a newline),
|
|
337
|
-
* `input_format_allow_errors_num` / `_ratio` decide whether a bad row is
|
|
338
|
-
* skipped or aborts the batch, and one batch is one clock instant for the
|
|
339
|
-
* volatile-DEFAULT guarantee.
|
|
340
|
-
*
|
|
341
|
-
* @param format - the wire format code (`Format`).
|
|
342
|
-
* @param body - the whole request body as bytes (never a JS string).
|
|
343
|
-
* @param settings - per-call settings; same precedence as `row`.
|
|
344
|
-
* @returns the `BatchResult`. When `engineRows` is present it — not `rows` —
|
|
345
|
-
* is the stored truth, and batch-level storage transforms (`ttl_expired`,
|
|
346
|
-
* `ttl_column_expired`) are folded into `transformed`.
|
|
347
|
-
* With `options.exportFormat` the same ONE call also serializes the batch's
|
|
348
|
-
* accepted rows through the vendored writer: `payload` carries the bytes
|
|
349
|
-
* (zero-length = emitted-empty, an accepted batch with zero accepted rows;
|
|
350
|
-
* `undefined` + `exportDeclined` = withheld, with the reason), and `spans`
|
|
351
|
-
* is index-aligned with `rows` — `payload.subarray(s.off, s.off + s.len)`
|
|
352
|
-
* IS row i's line. With `options.docFlags` the per-row documents are
|
|
353
|
-
* thinned to the selected groups; the verdict channel is never thinned.
|
|
354
|
-
* See `RowsOptions` for the defaults and `BatchResult` for the three
|
|
355
|
-
* payload states.
|
|
356
|
-
*
|
|
357
|
-
* @param format - the wire format code (`Format`).
|
|
358
|
-
* @param body - the whole request body as bytes (never a JS string).
|
|
359
|
-
* @param settings - per-call settings; same precedence as `row`.
|
|
360
|
-
* @param options - the revision-3 export/doc-flag channels, plus
|
|
361
|
-
* `columns` (revision 5), the INSERT column list, and `rowFilter`
|
|
362
|
-
* (revision 5, second half) — see `RowsOptions`; absent = today's full
|
|
363
|
-
* document, byte-identical to revision 2, no list, byte-identical to
|
|
364
|
-
* every revision before 5, and no filter, byte-identical byte for byte.
|
|
365
|
-
* @returns the `BatchResult`. When `engineRows` is present it — not `rows` —
|
|
366
|
-
* is the stored truth, and batch-level storage transforms (`ttl_expired`,
|
|
367
|
-
* `ttl_column_expired`) are folded into `transformed`. With
|
|
368
|
-
* `options.rowFilter`, `rowsPassed`/`rowsCut` join the result and every
|
|
369
|
-
* row carries its filter `verdict` beside its own `outcome`.
|
|
370
|
-
* @throws {ChtypesError} when the schema is closed, a settings value is a JS
|
|
371
|
-
* `number`, the artifact predates `chs_rows` (a mandatory symbol), the
|
|
372
|
-
* filter is closed, or the filter comes from a different loaded library.
|
|
373
|
-
*/
|
|
374
|
-
rows(format: Format, body: Uint8Array, settings?: Settings, options?: RowsOptions): BatchResult;
|
|
375
|
-
/**
|
|
376
|
-
* Compile one boolean SQL expression over this schema's PHYSICAL columns
|
|
377
|
-
* (ordinary + MATERIALIZED; naming an ALIAS/EPHEMERAL column fails with
|
|
378
|
-
* ClickHouse's own UNKNOWN_IDENTIFIER, exactly where a real CREATE fails) —
|
|
379
|
-
* the same TreeRewriter + ExpressionAnalyzer pipeline the CONSTRAINT CHECK
|
|
380
|
-
* path runs, so comparison semantics are WHERE-side by construction:
|
|
381
|
-
* `x = 256` over UInt8 promotes (false for every row), it never wraps
|
|
382
|
-
* (the C ABI contract §Filters).
|
|
383
|
-
*
|
|
384
|
-
* The expression may contain `{name:Type}` query parameters, bound with
|
|
385
|
-
* `options.params` (revision 4) — substitution is the server's own
|
|
386
|
-
* `ReplaceQueryParameterVisitor`, run before analysis, exactly where a
|
|
387
|
-
* real server runs it; see `CompileFilterOptions` for the injection-safety
|
|
388
|
-
* and cache-discipline contract. Close the filter when done (`close()` /
|
|
389
|
-
* `Symbol.dispose`); `schema.close()` also closes every open filter FIRST,
|
|
390
|
-
* so no caller ordering can free the schema under a live filter.
|
|
391
|
-
*
|
|
392
|
-
* ENFORCEMENT GATE: nothing may enforce read-side security on this surface
|
|
393
|
-
* until the WHERE-truth rig gates green (zero over-admit, zero over-hide);
|
|
394
|
-
* until then it is a shadow/replay surface.
|
|
395
|
-
*
|
|
396
|
-
* @param expr - one boolean expression, e.g. `"x = 256"` or
|
|
397
|
-
* `"tenant = {t:String}"`.
|
|
398
|
-
* @param options - the `{name:Type}` bindings, if any.
|
|
399
|
-
* @returns the compiled `Filter`.
|
|
400
|
-
* @throws {SchemaError} when ClickHouse itself refuses the expression —
|
|
401
|
-
* unknown identifier (47), unknown function, an analyzer-raised
|
|
402
|
-
* NO_COMMON_TYPE — and, since revision 4, the server's own parameter
|
|
403
|
-
* refusals: an UNBOUND `{name:Type}` is **456** UNKNOWN_QUERY_PARAMETER
|
|
404
|
-
* ("Substitution `name` is not set"), a value the declared type cannot
|
|
405
|
-
* parse completely is **457** BAD_QUERY_PARAMETER — the server's own
|
|
406
|
-
* code and message, verbatim. A bound name the expression never uses is
|
|
407
|
-
* ignored, as a live server ignores an unused `param_*`.
|
|
408
|
-
* @throws {UnsupportedError} when this build declines: a non-deterministic
|
|
409
|
-
* expression (clock reads — `now() > ts` —, `rand()`, server-constants;
|
|
410
|
-
* the scan runs AFTER substitution, so a value can never smuggle one
|
|
411
|
-
* in), or an artifact that predates the filter trio.
|
|
412
|
-
*/
|
|
413
|
-
compileFilter(expr: string, options?: CompileFilterOptions): Filter;
|
|
414
|
-
/** @internal — `Filter#close` deregisters itself here. */
|
|
415
|
-
forgetFilter(filter: Filter): void;
|
|
416
|
-
/**
|
|
417
|
-
* Parse a body ONCE into a `Block` (`chs_block_parse`) — the parse half of
|
|
418
|
-
* `Filter#rows`, exported so K filters can evaluate one event with no
|
|
419
|
-
* re-parse (`Filter#eval`; the C ABI contract §Blocks). Same formats and
|
|
420
|
-
* settings contract as `rows` (`settings` is the PARSE-side map: format
|
|
421
|
-
* settings, clock keys; evaluation takes none). Volatile DEFAULTs resolve
|
|
422
|
-
* against THIS call's clock instant, so
|
|
423
|
-
* `filter.eval(schema.parseBlock(...))` ≡ `filter.rows(...)` exactly when
|
|
424
|
-
* the clock is pinned (`chtypes_now_epoch_nanos`) or the schema has no
|
|
425
|
-
* volatile DEFAULT.
|
|
426
|
-
*
|
|
427
|
-
* Per-row parse failures do NOT throw — they are recorded IN the block and
|
|
428
|
-
* answer `'d'` from every filter, with the recorded error. Release
|
|
429
|
-
* with `close()` / `Symbol.dispose`; `schema.close()` closes open blocks
|
|
430
|
-
* FIRST, the C-required order.
|
|
431
|
-
*
|
|
432
|
-
* @param format - the wire format code (`Format`).
|
|
433
|
-
* @param body - the rows as bytes (never a JS string).
|
|
434
|
-
* @param settings - parse-side settings; same precedence as `Schema#rows`.
|
|
435
|
-
* @param options - `RowOptions#columns` (revision 5), the INSERT column
|
|
436
|
-
* list read exactly as `Schema#row` reads it. `parseBlock()` takes
|
|
437
|
-
* `RowOptions`, not `RowsOptions`: the revision-3 export/doc-flag
|
|
438
|
-
* channels are meaningless here, so this method's options type simply
|
|
439
|
-
* does not offer them. Filters compiled against this schema still
|
|
440
|
-
* evaluate the schema's PHYSICAL columns, so a listed `EPHEMERAL`
|
|
441
|
-
* column stays unreferenceable in a filter.
|
|
442
|
-
* @returns the parsed `Block`.
|
|
443
|
-
* @throws {SchemaError} on a call-level failure — an unknown setting's
|
|
444
|
-
* 115, an unsplittable body, a binary decode fault, the deferred
|
|
445
|
-
* JSONEachRow framing verdict: a malformed body yields no block and no
|
|
446
|
-
* partial answers.
|
|
447
|
-
* @throws {UnsupportedError} when this build declines the call, or the
|
|
448
|
-
* artifact predates the block twin.
|
|
449
|
-
*/
|
|
450
|
-
parseBlock(format: Format, body: Uint8Array, settings?: Settings, options?: RowOptions): Block;
|
|
451
|
-
/** @internal — `Block#close` deregisters itself here. */
|
|
452
|
-
forgetBlock(block: Block): void;
|
|
453
|
-
/**
|
|
454
|
-
* Release the native schema. Idempotent. After it, `row` / `rows` /
|
|
455
|
-
* `setEngine` / `setTtl` / `setPartitionBy` throw `ChtypesError` ("schema
|
|
456
|
-
* is closed").
|
|
457
|
-
* Any `Filter` or `Block` still open on this schema is closed FIRST, in
|
|
458
|
-
* the same call — the handles-before-schema free order the C layer
|
|
459
|
-
* requires, enforced here so no dispose ordering can get it backwards.
|
|
460
|
-
*/
|
|
461
|
-
close(): void;
|
|
462
|
-
/** `using schema = lib.compileDdl(...)` releases it at scope exit. */
|
|
463
|
-
[Symbol.dispose](): void;
|
|
54
|
+
/** Options of `Filter.rows`. The settings are PARSE settings only: they decide how the body is parsed, never the filter's WHERE. */
|
|
55
|
+
export interface EvalOptions {
|
|
56
|
+
readonly settings?: Settings | undefined;
|
|
57
|
+
readonly sessionTimezone?: string | undefined;
|
|
464
58
|
}
|
|
465
|
-
/**
|
|
466
|
-
* One boolean SQL expression compiled against a `Schema`'s columns
|
|
467
|
-
* (`chs_filter_compile`). Obtained from `Schema#compileFilter`; never
|
|
468
|
-
* constructed directly.
|
|
469
|
-
*
|
|
470
|
-
* LIFETIME: a filter REFERENCES its schema handle — the C layer does not copy
|
|
471
|
-
* and does not refcount (the C ABI contract §Filters). This binding enforces the
|
|
472
|
-
* free order structurally, both ways: the `Filter` holds its `Schema` (so the
|
|
473
|
-
* schema stays reachable), and `Schema#close` closes every open filter before
|
|
474
|
-
* freeing the schema. `close()` is idempotent, and `using` / `Symbol.dispose`
|
|
475
|
-
* work on both objects in any nesting — the schema's dispose runs the
|
|
476
|
-
* filter's first when the caller forgot. A filter compiled from a schema
|
|
477
|
-
* answers for THAT handle: recompile filters when the schema is recompiled.
|
|
478
|
-
* A filter nobody closed is also backed by a GC finalizer, coordinated with
|
|
479
|
-
* its schema's own (see `SchemaNative`) so the two can never free this
|
|
480
|
-
* filter's handle out of order or twice, whichever one the GC happens to run
|
|
481
|
-
* first.
|
|
482
|
-
*
|
|
483
|
-
* THREADS: the header's rule, verbatim — one `chs_filter` "must not be used
|
|
484
|
-
* from two threads at once, and a chs_filter call is ALSO a use of its schema
|
|
485
|
-
* handle" (two filters over ONE schema must not run concurrently either). On
|
|
486
|
-
* a single JS thread every call here is synchronous, so ordinary Node code
|
|
487
|
-
* satisfies both by construction (docs/reference/bindings.md §Concurrency); do not
|
|
488
|
-
* share a `Filter` — or its `Schema` — across `worker_threads`.
|
|
489
|
-
*
|
|
490
|
-
* ENFORCEMENT GATE: `'e'` and `'d'` verdicts are NOT answers — a
|
|
491
|
-
* caller enforcing visibility MUST fail closed on both — and NO caller may
|
|
492
|
-
* enforce read-side security on this surface until the WHERE-truth rig gates
|
|
493
|
-
* green; until then it is a shadow/replay surface (the C ABI contract §Filters).
|
|
494
|
-
*/
|
|
59
|
+
/** A compiled `WHERE`-style expression bound to a schema. It holds its own zone, fixed at compile. */
|
|
495
60
|
export declare class Filter {
|
|
496
|
-
private
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
/** @internal — obtained from `Schema#compileFilter`. */
|
|
503
|
-
constructor(native: NativeLibrary, schema: Schema, schemaNative: SchemaNative, handle: FilterHandle,
|
|
504
|
-
/** The expression text as compiled, for logging and cache keys. */
|
|
505
|
-
expr: string);
|
|
506
|
-
/** @internal — the loaded library this filter's handle belongs to, for
|
|
507
|
-
* `Schema#rows(options.rowFilter)`'s cross-library check. */
|
|
508
|
-
get nativeLib(): NativeLibrary;
|
|
509
|
-
/** @internal — the live handle, for `Schema#rows(options.rowFilter)`. */
|
|
510
|
-
liveHandle(): FilterHandle;
|
|
511
|
-
/**
|
|
512
|
-
* Evaluate the filter over a body of rows (`chs_filter_rows`) — the same
|
|
513
|
-
* formats and settings contract as `Schema#rows`, ONE C call. Rows are
|
|
514
|
-
* evaluated INDEPENDENTLY (there is no INSERT to abort):
|
|
515
|
-
* `input_format_allow_errors_*` does not apply, a bad text row declines
|
|
516
|
-
* (`'d'`) and the tail resyncs so verdict indexes keep matching input
|
|
517
|
-
* rows, and volatile DEFAULTs resolve against one clock instant per call.
|
|
518
|
-
*
|
|
519
|
-
* @param format - the wire format code (`Format`).
|
|
520
|
-
* @param body - the rows as bytes (never a JS string).
|
|
521
|
-
* @param settings - per-call settings; same precedence as `Schema#rows`.
|
|
522
|
-
* @returns the `FilterResult` — the call-level outcome, and one verdict per
|
|
523
|
-
* row when it is `'ok'`.
|
|
524
|
-
* @throws {ChtypesError} when the filter is closed, or a settings value is
|
|
525
|
-
* a JS `number`.
|
|
526
|
-
*/
|
|
527
|
-
rows(format: Format, body: Uint8Array, settings?: Settings): FilterResult;
|
|
528
|
-
/**
|
|
529
|
-
* Evaluate this filter over an already-parsed `Block` (`chs_filter_eval`)
|
|
530
|
-
* — the SAME result document `rows` returns: same `FilterResult` fields,
|
|
531
|
-
* same verdicts, same `errors` rule (a row the parse recorded as
|
|
532
|
-
* unparseable answers `'d'` with the recorded error). Evaluation is
|
|
533
|
-
* a pure function of (filter, block): no settings, and the block is
|
|
534
|
-
* neither consumed nor mutated, so one block can be evaluated by K filters
|
|
535
|
-
* sequentially with no re-parse — the live-SSE call shape.
|
|
536
|
-
*
|
|
537
|
-
* Filter and block MUST come from the SAME schema: a mismatched pair
|
|
538
|
-
* answers a REJECTED result (code 1002) — the C layer's loud refusal,
|
|
539
|
-
* never undefined behavior. A pair from two different libraries throws
|
|
540
|
-
* `ChtypesError`: no handle ever crosses a dlopen'd image boundary.
|
|
541
|
-
*
|
|
542
|
-
* @param block - a `Block` from `Schema#parseBlock`.
|
|
543
|
-
* @returns the `FilterResult`, exactly as `rows` would answer it.
|
|
544
|
-
* @throws {ChtypesError} when the filter or block is closed, or they come
|
|
545
|
-
* from two different libraries.
|
|
546
|
-
*/
|
|
61
|
+
#private;
|
|
62
|
+
/** Not for callers: use `Schema.compileFilter`. */
|
|
63
|
+
constructor(calls: Calls, handle: FilterHandle);
|
|
64
|
+
/** Evaluate over a body. */
|
|
65
|
+
rows(format: Format, body: Uint8Array, options?: EvalOptions): FilterResult;
|
|
66
|
+
/** Evaluate over a parsed block. The filter brings its zone and the block brought its parse zone, so there are no settings here. */
|
|
547
67
|
eval(block: Block): FilterResult;
|
|
548
|
-
/**
|
|
549
|
-
* Release the native filter (`chs_filter_free`). Idempotent, and also
|
|
550
|
-
* performed by the schema's own `close()` — filters first, then the schema,
|
|
551
|
-
* the C-required order. Also the backstop a GC finalizer calls for a filter
|
|
552
|
-
* nobody closed — see `SchemaNative`; the `openFilters.delete` guard is
|
|
553
|
-
* what makes it safe to run whether `close()`, this filter's own finalizer,
|
|
554
|
-
* or the schema's finalizer gets here first.
|
|
555
|
-
*/
|
|
68
|
+
/** Release this filter; idempotent. */
|
|
556
69
|
close(): void;
|
|
557
|
-
/** `using filter = schema.compileFilter(...)` releases it at scope exit. */
|
|
558
70
|
[Symbol.dispose](): void;
|
|
559
71
|
}
|
|
560
|
-
/**
|
|
561
|
-
* One body, parsed ONCE under one schema handle and one clock instant
|
|
562
|
-
* (`chs_block_parse`). Obtained from `Schema#parseBlock`; evaluated by
|
|
563
|
-
* `Filter#eval`. The parse-once/eval-many twin of `Filter#rows`
|
|
564
|
-
* (the C ABI contract §Blocks): the live-SSE hot path is K filters × 1 event, and
|
|
565
|
-
* the block sheds the re-parse.
|
|
566
|
-
*
|
|
567
|
-
* LIFETIME: a block REFERENCES its schema handle exactly as a filter does —
|
|
568
|
-
* the C layer does not copy and does not refcount. This binding enforces the
|
|
569
|
-
* free order structurally, both ways: the `Block` holds its `Schema` (so the
|
|
570
|
-
* schema stays reachable), and `Schema#close` closes every open block before
|
|
571
|
-
* freeing the schema — `using` / `Symbol.dispose` work on all three objects
|
|
572
|
-
* in any nesting, and the schema's dispose runs the block's first when the
|
|
573
|
-
* caller forgot. A block may be evaluated by MANY filters, sequentially;
|
|
574
|
-
* evaluation does not consume or mutate it. Recompile blocks when the schema
|
|
575
|
-
* is recompiled.
|
|
576
|
-
*
|
|
577
|
-
* THREADS: one block must not be used from two threads at once, and an eval
|
|
578
|
-
* is a use of BOTH handles. On a single JS thread every call here is
|
|
579
|
-
* synchronous, so ordinary Node code satisfies both by construction; do not
|
|
580
|
-
* share a `Block` — or its `Schema` — across `worker_threads`.
|
|
581
|
-
*
|
|
582
|
-
* A block nobody closed is also backed by a GC finalizer, coordinated with
|
|
583
|
-
* its schema's own (see `SchemaNative`) so the two can never free this
|
|
584
|
-
* block's handle out of order or twice, whichever one the GC happens to run
|
|
585
|
-
* first.
|
|
586
|
-
*/
|
|
72
|
+
/** A body parsed once, evaluated by any number of filters. */
|
|
587
73
|
export declare class Block {
|
|
588
|
-
private
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
/**
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
74
|
+
#private;
|
|
75
|
+
/** Not for callers: use `Schema.parseBlock`. */
|
|
76
|
+
constructor(handle: BlockHandle);
|
|
77
|
+
/** Release this block; idempotent. */
|
|
78
|
+
close(): void;
|
|
79
|
+
[Symbol.dispose](): void;
|
|
80
|
+
}
|
|
81
|
+
/** A compiled `CREATE TABLE`: describe it, preview rows and bodies against it, compile filters and parse blocks over it. */
|
|
82
|
+
export declare class Schema {
|
|
83
|
+
#private;
|
|
84
|
+
/** Not for callers: use `Library.compileTable`. */
|
|
85
|
+
constructor(calls: Calls, handle: SchemaHandle);
|
|
86
|
+
/** The columns, in declared order. */
|
|
87
|
+
describe(): SchemaDescription;
|
|
88
|
+
/** One row. */
|
|
89
|
+
row(format: Format, body: Uint8Array, options?: RowOptions): RowResult;
|
|
90
|
+
/** A whole body. */
|
|
91
|
+
rows(format: Format, body: Uint8Array, options?: RowsOptions): BatchResult;
|
|
92
|
+
/** Compile a filter. Its zone is fixed here. */
|
|
93
|
+
compileFilter(expr: BytesIn, options?: FilterOptions): Filter;
|
|
94
|
+
/** Parse a body once. */
|
|
95
|
+
parseBlock(format: Format, body: Uint8Array, options?: RowOptions): Block;
|
|
96
|
+
/** Release this schema; idempotent. Filters and blocks made from it keep working. */
|
|
606
97
|
close(): void;
|
|
607
|
-
/** `using block = schema.parseBlock(...)` releases it at scope exit. */
|
|
608
98
|
[Symbol.dispose](): void;
|
|
609
99
|
}
|
|
610
|
-
export {};
|
|
611
100
|
//# sourceMappingURL=schema.d.ts.map
|