@wavehouse/chtypes 2.0.0-dev.10 → 2.0.0-dev.11

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/abi2/calls.gen.d.ts +5 -5
  3. package/dist/abi2/calls.gen.d.ts.map +1 -1
  4. package/dist/abi2/calls.gen.js +11 -11
  5. package/dist/abi2/calls.gen.js.map +1 -1
  6. package/dist/abi2/decls.gen.d.ts +2 -1
  7. package/dist/abi2/decls.gen.d.ts.map +1 -1
  8. package/dist/abi2/decls.gen.js +78 -21
  9. package/dist/abi2/decls.gen.js.map +1 -1
  10. package/dist/abi2/errmap.gen.js +1 -1
  11. package/dist/abi2/errors.d.ts +5 -2
  12. package/dist/abi2/errors.d.ts.map +1 -1
  13. package/dist/abi2/errors.js +4 -2
  14. package/dist/abi2/errors.js.map +1 -1
  15. package/dist/abi2/libc.gen.js +1 -1
  16. package/dist/abi2/loader.d.ts +4 -2
  17. package/dist/abi2/loader.d.ts.map +1 -1
  18. package/dist/abi2/raw.d.ts.map +1 -1
  19. package/dist/abi2/raw.js +4 -1
  20. package/dist/abi2/raw.js.map +1 -1
  21. package/dist/abi2/vocab.gen.d.ts +49 -1
  22. package/dist/abi2/vocab.gen.d.ts.map +1 -1
  23. package/dist/abi2/vocab.gen.js +81 -5
  24. package/dist/abi2/vocab.gen.js.map +1 -1
  25. package/dist/documents.d.ts +42 -9
  26. package/dist/documents.d.ts.map +1 -1
  27. package/dist/documents.js +60 -8
  28. package/dist/documents.js.map +1 -1
  29. package/dist/index.d.ts +3 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/library.d.ts.map +1 -1
  34. package/dist/library.js +5 -4
  35. package/dist/library.js.map +1 -1
  36. package/dist/schema.d.ts +42 -9
  37. package/dist/schema.d.ts.map +1 -1
  38. package/dist/schema.js +6 -6
  39. package/dist/schema.js.map +1 -1
  40. package/dist/settings.d.ts +83 -12
  41. package/dist/settings.d.ts.map +1 -1
  42. package/dist/settings.js +180 -41
  43. package/dist/settings.js.map +1 -1
  44. package/dist/setup.d.ts +3 -2
  45. package/dist/setup.d.ts.map +1 -1
  46. package/dist/setup.js +2 -3
  47. package/dist/setup.js.map +1 -1
  48. package/package.json +2 -2
package/dist/schema.d.ts CHANGED
@@ -16,16 +16,16 @@
16
16
  * thread, so the close guard of the other bindings reduces to this check: no
17
17
  * call is ever in flight while `close` runs.
18
18
  */
19
- import type { BlockHandle, Calls, FilterHandle, SchemaHandle } from './abi2/index.js';
19
+ import type { BlockHandle, Calls, FilterHandle, Posture, SchemaHandle } from './abi2/index.js';
20
20
  import { type Format } from './abi2/index.js';
21
21
  import { type BatchResult, type FilterResult, type RowResult, type SchemaDescription } from './documents.js';
22
22
  import type { Server } from './server.js';
23
- import { type BytesIn, type Settings } from './settings.js';
23
+ import { type BytesIn, type ColumnDefault, type DeferDefaults, type ParamEncoding, type SettingValue, type Settings, type VerdictBasis } from './settings.js';
24
24
  /** Options of `Library.compileTable`: the profile settings a schema compiles under, and the zone that profile defaults to. */
25
25
  export interface CompileOptions {
26
26
  readonly settings?: Settings | undefined;
27
- /** 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. */
28
- readonly sessionTimezone?: string | undefined;
27
+ /** 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. Bytes that are not valid UTF-8 are sent in the `{"b64": ...}` object form. */
28
+ readonly sessionTimezone?: SettingValue | undefined;
29
29
  /**
30
30
  * Compile on this server (`Library.newServer`): the schema's home zone is the
31
31
  * server's timezone, the server's settings layer under the schema's own, and a
@@ -35,14 +35,28 @@ export interface CompileOptions {
35
35
  * Absent (or `undefined`) is no server: the schema is on the image's own server.
36
36
  */
37
37
  readonly server?: Server | undefined;
38
+ /** `schema_options.posture` (ABI v2): how the statement is compiled, `Posture.Create` (the default) as a server's CREATE TABLE, or `Posture.Load` as a server loads the stored definition of a table it holds. */
39
+ readonly posture?: Posture | undefined;
40
+ /** Any other member of `schema_options`: key to its value as JSON text, passed through as given (rule r1; a key also named above keeps this value). Text that is not valid JSON is a `UsageError` before any call. */
41
+ readonly schemaOptionsExtra?: Readonly<Record<string, string>> | undefined;
38
42
  }
39
- /** Options of `Schema.row` and `Schema.parseBlock`. */
43
+ /** Options of `Schema.row` and `Schema.parseBlock`: the settings, the zone, the INSERT column list and the `insert_options` members (ABI v2). */
40
44
  export interface RowOptions {
41
45
  readonly settings?: Settings | undefined;
42
46
  /** The per-call zone: written into the settings as `session_timezone`, verbatim. */
43
- readonly sessionTimezone?: string | undefined;
47
+ readonly sessionTimezone?: SettingValue | undefined;
44
48
  /** The INSERT column list. */
45
49
  readonly columns?: readonly BytesIn[] | undefined;
50
+ /** `insert_options.insertable_columns` (ABI v2): the columns an INSERT may supply. Absent leaves the member out (every column); `[]` is sent as `[]` (no column). */
51
+ readonly insertableColumns?: readonly BytesIn[] | undefined;
52
+ /** `insert_options.column_defaults`: per-call DEFAULT overrides. Absent leaves the member out; `[]` is sent as `[]`. */
53
+ readonly columnDefaults?: readonly ColumnDefault[] | undefined;
54
+ /** `insert_options.verdict_basis`. */
55
+ readonly verdictBasis?: VerdictBasis | undefined;
56
+ /** `insert_options.defer_defaults`. */
57
+ readonly deferDefaults?: DeferDefaults | undefined;
58
+ /** Any other member of `insert_options`: key to its value as JSON text, passed through as given (rule r1; a key also named above keeps this value). Text that is not valid JSON is a `UsageError` before any call. */
59
+ readonly insertOptionsExtra?: Readonly<Record<string, string>> | undefined;
46
60
  }
47
61
  /** Options of `Schema.rows`. */
48
62
  export interface RowsOptions extends RowOptions {
@@ -59,12 +73,31 @@ export interface FilterOptions {
59
73
  readonly params?: Settings | undefined;
60
74
  /** The filter's own zone and profile: fixed when it is compiled, and every evaluation of it runs its WHERE under them. */
61
75
  readonly settings?: Settings | undefined;
62
- readonly sessionTimezone?: string | undefined;
76
+ readonly sessionTimezone?: SettingValue | undefined;
77
+ /** `filter_options.param_encoding` (ABI v2): how a query parameter's value is read. */
78
+ readonly paramEncoding?: ParamEncoding | undefined;
79
+ /** Any other member of `filter_options`, as `insertOptionsExtra` is for `insert_options`. */
80
+ readonly filterOptionsExtra?: Readonly<Record<string, string>> | undefined;
63
81
  }
64
- /** Options of `Filter.rows`. The settings are PARSE settings only: they decide how the body is parsed, never the filter's WHERE. */
82
+ /**
83
+ * Options of `Filter.rows`. The settings are PARSE settings only: they decide how the body is parsed, never the filter's WHERE.
84
+ * `columns` and the `insert_options` members model the same INSERT as on `Schema.rows` (ABI v2).
85
+ */
65
86
  export interface EvalOptions {
66
87
  readonly settings?: Settings | undefined;
67
- readonly sessionTimezone?: string | undefined;
88
+ readonly sessionTimezone?: SettingValue | undefined;
89
+ /** The INSERT column list. */
90
+ readonly columns?: readonly BytesIn[] | undefined;
91
+ /** `insert_options.insertable_columns` (ABI v2): the columns an INSERT may supply. Absent leaves the member out (every column); `[]` is sent as `[]` (no column). */
92
+ readonly insertableColumns?: readonly BytesIn[] | undefined;
93
+ /** `insert_options.column_defaults`: per-call DEFAULT overrides. Absent leaves the member out; `[]` is sent as `[]`. */
94
+ readonly columnDefaults?: readonly ColumnDefault[] | undefined;
95
+ /** `insert_options.verdict_basis`. */
96
+ readonly verdictBasis?: VerdictBasis | undefined;
97
+ /** `insert_options.defer_defaults`. */
98
+ readonly deferDefaults?: DeferDefaults | undefined;
99
+ /** Any other member of `insert_options`: key to its value as JSON text, passed through as given (rule r1; a key also named above keeps this value). Text that is not valid JSON is a `UsageError` before any call. */
100
+ readonly insertOptionsExtra?: Readonly<Record<string, string>> | undefined;
68
101
  }
69
102
  /** A compiled `WHERE`-style expression bound to a schema. It holds its own zone, fixed at compile. */
70
103
  export declare class Filter {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,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O,GAAE,UAAe,GAAG,KAAK,CAW5E;IAED,qFAAqF;IACrF,KAAK,IAAI,IAAI,CAEZ;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;CACF"}
package/dist/schema.js CHANGED
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { DocFlags, EXPORT_NONE } from './abi2/index.js';
20
20
  import { decodeBatch, decodeFilterResult, decodeRow, decodeSchemaDescription, } from './documents.js';
21
- import { bytesIn, encodeColumns, encodeParams, encodeSettings } from './settings.js';
21
+ import { bytesIn, encodeColumns, encodeFilterOptions, encodeInsertOptions, encodeParams, encodeSettings, } from './settings.js';
22
22
  function bodyIn(body) {
23
23
  if (typeof body === 'string')
24
24
  throw new TypeError('chtypes: a body is bytes (a Uint8Array); it never accepts the text type');
@@ -37,7 +37,7 @@ export class Filter {
37
37
  }
38
38
  /** Evaluate over a body. */
39
39
  rows(format, body, options = {}) {
40
- return decodeFilterResult(this.#calls.filterEvalBody(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone)));
40
+ return decodeFilterResult(this.#calls.filterEvalBody(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns), encodeInsertOptions(options)));
41
41
  }
42
42
  /** Evaluate over a parsed block. The filter brings its zone and the block brought its parse zone, so there are no settings here. */
43
43
  eval(block) {
@@ -83,22 +83,22 @@ export class Schema {
83
83
  }
84
84
  /** One row. */
85
85
  row(format, body, options = {}) {
86
- return decodeRow(this.#calls.previewRow(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns)));
86
+ return decodeRow(this.#calls.previewRow(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns), encodeInsertOptions(options)));
87
87
  }
88
88
  /** A whole body. */
89
89
  rows(format, body, options = {}) {
90
90
  const filter = options.rowFilter === undefined ? null : filterHandles.get(options.rowFilter);
91
91
  const exporting = options.exportFormat !== undefined;
92
- const out = this.#calls.previewBatch(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns), filter, exporting ? options.exportFormat : EXPORT_NONE, options.docFlags ?? DocFlags.All);
92
+ const out = this.#calls.previewBatch(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns), filter, exporting ? options.exportFormat : EXPORT_NONE, options.docFlags ?? DocFlags.All, encodeInsertOptions(options));
93
93
  return decodeBatch(out.out, exporting ? out.outExport : undefined);
94
94
  }
95
95
  /** Compile a filter. Its zone is fixed here. */
96
96
  compileFilter(expr, options = {}) {
97
- return new Filter(this.#calls, this.#calls.filterCreate(this.#h, bytesIn(expr), encodeParams(options.params), encodeSettings(options.settings, options.sessionTimezone)));
97
+ return new Filter(this.#calls, this.#calls.filterCreate(this.#h, bytesIn(expr), encodeParams(options.params), encodeSettings(options.settings, options.sessionTimezone), encodeFilterOptions(options)));
98
98
  }
99
99
  /** Parse a body once. */
100
100
  parseBlock(format, body, options = {}) {
101
- return new Block(this.#calls.blockCreate(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns)));
101
+ return new Block(this.#calls.blockCreate(this.#h, format, bodyIn(body), encodeSettings(options.settings, options.sessionTimezone), encodeColumns(options.columns), encodeInsertOptions(options)));
102
102
  }
103
103
  /** Release this schema; idempotent. Filters and blocks made from it keep working. */
104
104
  close() {
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAe,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAEL,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,uBAAuB,GAIxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAgB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAiB,MAAM,eAAe,C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C,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;IAED,gDAAgD;IAChD,aAAa,CAAC,IAAa,EAAE,OAAO,GAAkB,EAAE;QACtD,OAAO,IAAI,MAAM,CACf,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,CAAC,YAAY,CACtB,IAAI,CAAC,EAAE,EACP,OAAO,CAAC,IAAI,CAAC,EACb,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,EAC5B,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,EACzD,mBAAmB,CAAC,OAAO,CAAC,CAC7B,CACF,CAAC;IACJ,CAAC;IAED,yBAAyB;IACzB,UAAU,CAAC,MAAc,EAAE,IAAgB,EAAE,OAAO,GAAe,EAAE;QACnE,OAAO,IAAI,KAAK,CACd,IAAI,CAAC,MAAM,CAAC,WAAW,CACrB,IAAI,CAAC,EAAE,EACP,MAAM,EACN,MAAM,CAAC,IAAI,CAAC,EACZ,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,EACzD,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,EAC9B,mBAAmB,CAAC,OAAO,CAAC,CAC7B,CACF,CAAC;IACJ,CAAC;IAED,qFAAqF;IACrF,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
@@ -2,10 +2,14 @@
2
2
  * Settings, the per-call zone and the other call inputs, serialized for the
3
3
  * library exactly as `docs/reference/bindings-v1.md` §2 and §3 say.
4
4
  *
5
- * Settings values are strings, and only strings. The map becomes a JSON object
6
- * of string values through the stock encoder and is passed verbatim: no
7
- * boolean or integer spelling, no float. A value that is not a string is the
8
- * language's own type error (`TypeError`).
5
+ * Settings values are strings or bytes, and nothing else. The map becomes a JSON
6
+ * object through the stock encoder and each value is passed verbatim: no boolean
7
+ * or integer spelling, no float. A value that is neither a string nor a
8
+ * `Uint8Array` is the language's own type error (`TypeError`). A value whose
9
+ * bytes are valid UTF-8 is a JSON string; any other bytes (a `Uint8Array`) are
10
+ * the object form `{"b64": "<standard base64>"}` (ABI v2, `json_object_byte_values`),
11
+ * so the library sees the exact bytes. A key that is not valid UTF-8 cannot be
12
+ * carried at all and is a `UsageError`.
9
13
  *
10
14
  * The per-call zone is a settings key and nothing more: `sessionTimezone` is
11
15
  * written into the object as `session_timezone`, verbatim, with no default,
@@ -13,8 +17,15 @@
13
17
  * database). Passing it alongside a `session_timezone` key in `settings` is a
14
18
  * `UsageError`, raised before any call and whether or not the two agree.
15
19
  */
16
- /** Settings and query parameters: names to string values. */
17
- export type Settings = Readonly<Record<string, string>>;
20
+ import { type Posture } from './abi2/index.js';
21
+ /** A settings or query-parameter value: text, or the bytes of a value that need not be text (a non-UTF-8 value is sent in the `{"b64": ...}` object form). */
22
+ export type SettingValue = string | Uint8Array;
23
+ /** Settings and query parameters: names to values. */
24
+ export type Settings = Readonly<Record<string, SettingValue>>;
25
+ /** A value as the document carries it: a JSON string, or the object form of bytes that are not UTF-8. */
26
+ export type WireValue = string | {
27
+ readonly b64: string;
28
+ };
18
29
  /** Bytes in: a statement, expression, type, name or literal. A string is encoded as UTF-8; pass a `Uint8Array` for bytes that are not text. */
19
30
  export type BytesIn = Uint8Array | string;
20
31
  /** The bytes of a `BytesIn`: UTF-8 for a string, the same bytes for a `Uint8Array`. */
@@ -24,13 +35,13 @@ export declare function bytesIn(value: BytesIn): Buffer;
24
35
  * map nor a zone, else a JSON object of string values with the zone, when
25
36
  * given, written in as `session_timezone`.
26
37
  */
27
- export declare function encodeSettings(settings: Settings | undefined, sessionTimezone: string | undefined): Buffer;
38
+ export declare function encodeSettings(settings: Settings | undefined, sessionTimezone: SettingValue | undefined): Buffer;
28
39
  /** Query parameters: a JSON object of string values, or nothing when absent. */
29
40
  export declare function encodeParams(params: Settings | undefined): Buffer;
30
41
  /** The INSERT column list: a JSON array of names, each an object carrying `name` when its bytes are valid UTF-8 and `name_b64` otherwise, or nothing (length 0) when absent. */
31
42
  export declare function encodeColumns(columns: readonly BytesIn[] | undefined): Buffer;
32
- /** The process default settings, as `chs_set_defaults` takes them. */
33
- export declare function validateDefaults(defaults: Settings): void;
43
+ /** The process default settings, as `chs_set_defaults` takes them: the wire form of each value (a value that is not valid UTF-8 is `{"b64": ...}`). */
44
+ export declare function validateDefaults(defaults: Settings): Readonly<Record<string, WireValue>>;
34
45
  /**
35
46
  * One ClickHouse server, as `chs_server_create` takes it (`input:server_profile`).
36
47
  * Every member is optional, and every value is passed through as given: the
@@ -40,16 +51,76 @@ export declare function validateDefaults(defaults: Settings): void;
40
51
  export interface ServerProfile {
41
52
  /** The server's zone, the one its `timezone()` returns. Absent or `''` omits it: the server does not describe it, and the image zone applies. */
42
53
  readonly timezone?: string | undefined;
43
- /** What the server's profile applies to every query. Absent omits it (no server settings layer); `{}` is sent as `{}`. */
54
+ /** What the server's profile applies to every query. Absent omits it (no server settings layer); `{}` is sent as `{}`. A value that is not valid UTF-8 is a `Uint8Array`, sent in the `{"b64": ...}` form. */
44
55
  readonly settings?: Settings | undefined;
45
56
  /**
46
57
  * The server's `<macros>`, which a Replicated engine's ZooKeeper path and
47
58
  * replica name expand. ABSENT is not `{}`: absent means the server's macros
48
59
  * are UNKNOWN, and a schema whose engine reads one is declined; present, even
49
- * `{}`, is the server's COMPLETE set.
60
+ * `{}`, is the server's COMPLETE set. A macro's name and value are text: they
61
+ * have no byte form.
50
62
  */
51
- readonly macros?: Settings | undefined;
63
+ readonly macros?: Readonly<Record<string, string>> | undefined;
52
64
  }
53
65
  /** The profile document: an empty or absent zone, absent settings and absent macros are omitted; a present map is sent as given, `{}` when empty. */
54
66
  export declare function encodeServerProfile(profile: ServerProfile): Buffer;
67
+ /** `insert_options.verdict_basis`: what row a filter verdict answers for. */
68
+ export declare const VerdictBasis: {
69
+ /** The default: the verdict answers for the input row. */
70
+ readonly Input: 'input';
71
+ /** The row the export would store. A build that does not implement it declines it. */
72
+ readonly Export: 'export';
73
+ };
74
+ export type VerdictBasis = (typeof VerdictBasis)[keyof typeof VerdictBasis];
75
+ /** `insert_options.defer_defaults`. */
76
+ export declare const DeferDefaults: {
77
+ /** The default: no DEFAULT is deferred. */
78
+ readonly None: 'none';
79
+ /** Defer to the server each DEFAULT the build would otherwise decline. A build that does not implement it declines it. */
80
+ readonly Server: 'server';
81
+ };
82
+ export type DeferDefaults = (typeof DeferDefaults)[keyof typeof DeferDefaults];
83
+ /** `filter_options.param_encoding`: how a query parameter's value is read. */
84
+ export declare const ParamEncoding: {
85
+ /** The default: ClickHouse's escaped-text reader. */
86
+ readonly Escaped: 'escaped';
87
+ /** The bytes as the value. A build that does not implement it declines it. */
88
+ readonly Raw: 'raw';
89
+ };
90
+ export type ParamEncoding = (typeof ParamEncoding)[keyof typeof ParamEncoding];
91
+ /** One entry of `insert_options.column_defaults`: the value the call uses in a cell the server would fill from the column's DEFAULT. Both are byte strings: bytes that are not valid UTF-8 are sent in the `name_b64` and `value_b64` forms. */
92
+ export interface ColumnDefault {
93
+ readonly name: BytesIn;
94
+ readonly value: BytesIn;
95
+ }
96
+ /** The `insert_options` members of the four calls that model an INSERT of a body (`row`, `rows`, `parseBlock`, and a filter's `rows`): what `encodeInsertOptions` reads from those calls' options objects. */
97
+ export interface InsertOptions {
98
+ /** The columns an INSERT may supply (the server's column-level INSERT grant). Absent leaves the member out (every column); `[]` is sent as `[]` (no column). */
99
+ readonly insertableColumns?: readonly BytesIn[] | undefined;
100
+ /** Per-call DEFAULT overrides. Absent leaves the member out; `[]` is sent as `[]`. */
101
+ readonly columnDefaults?: readonly ColumnDefault[] | undefined;
102
+ readonly verdictBasis?: VerdictBasis | undefined;
103
+ readonly deferDefaults?: DeferDefaults | undefined;
104
+ /** Any other member of `insert_options`: key to its value as JSON text, passed through as given (rule r1). A key also named above keeps this value. Text that is not valid JSON is a `UsageError` before any call. */
105
+ readonly insertOptionsExtra?: Readonly<Record<string, string>> | undefined;
106
+ }
107
+ /** The `filter_options` members of `Schema.compileFilter`. */
108
+ export interface FilterOptionMembers {
109
+ readonly paramEncoding?: ParamEncoding | undefined;
110
+ /** Any other member of `filter_options`, as `insertOptionsExtra` is for `insert_options`. */
111
+ readonly filterOptionsExtra?: Readonly<Record<string, string>> | undefined;
112
+ }
113
+ /** The `schema_options` members of `Library.compileTable`. */
114
+ export interface SchemaOptionMembers {
115
+ /** How the statement is compiled: `Posture.Create` (the default), as a server's CREATE TABLE, or `Posture.Load`, as a server loads the stored definition of a table it holds. */
116
+ readonly posture?: Posture | undefined;
117
+ /** Any other member of `schema_options`, as `insertOptionsExtra` is for `insert_options`. */
118
+ readonly schemaOptionsExtra?: Readonly<Record<string, string>> | undefined;
119
+ }
120
+ /** The `insert_options` document of a call that models an INSERT. */
121
+ export declare function encodeInsertOptions(o: InsertOptions): Buffer;
122
+ /** The `filter_options` document of `chs_filter_create`. */
123
+ export declare function encodeFilterOptions(o: FilterOptionMembers): Buffer;
124
+ /** The `schema_options` document of `chs_schema_create`. */
125
+ export declare function encodeSchemaOptions(o: SchemaOptionMembers): Buffer;
55
126
  //# sourceMappingURL=settings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,6DAA6D;AAC7D,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExD,+IAA+I;AAC/I,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;AAI1C,uFAAuF;AACvF,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE9C;AAuBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE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ED,8DAA8D;AAC9D,MAAM,WAAW,mBAAmB;IAClC,iLAAiL;IACjL,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACvC,6FAA6F;IAC7F,QAAQ,CAAC,kBAAkB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CAC5E;AAoDD,qEAAqE;AACrE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAa5D;AAED,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAKlE;AAED,4DAA4D;AAC5D,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAKlE"}
package/dist/settings.js CHANGED
@@ -2,10 +2,14 @@
2
2
  * Settings, the per-call zone and the other call inputs, serialized for the
3
3
  * library exactly as `docs/reference/bindings-v1.md` §2 and §3 say.
4
4
  *
5
- * Settings values are strings, and only strings. The map becomes a JSON object
6
- * of string values through the stock encoder and is passed verbatim: no
7
- * boolean or integer spelling, no float. A value that is not a string is the
8
- * language's own type error (`TypeError`).
5
+ * Settings values are strings or bytes, and nothing else. The map becomes a JSON
6
+ * object through the stock encoder and each value is passed verbatim: no boolean
7
+ * or integer spelling, no float. A value that is neither a string nor a
8
+ * `Uint8Array` is the language's own type error (`TypeError`). A value whose
9
+ * bytes are valid UTF-8 is a JSON string; any other bytes (a `Uint8Array`) are
10
+ * the object form `{"b64": "<standard base64>"}` (ABI v2, `json_object_byte_values`),
11
+ * so the library sees the exact bytes. A key that is not valid UTF-8 cannot be
12
+ * carried at all and is a `UsageError`.
9
13
  *
10
14
  * The per-call zone is a settings key and nothing more: `sessionTimezone` is
11
15
  * written into the object as `session_timezone`, verbatim, with no default,
@@ -19,26 +23,58 @@ const ZONE_KEY = 'session_timezone';
19
23
  export function bytesIn(value) {
20
24
  return typeof value === 'string' ? Buffer.from(value, 'utf8') : asBuffer(value);
21
25
  }
22
- const NON_UTF8_HINT = 'this ABI generation cannot carry a non-UTF-8 value in a JSON input; write the bytes as unhex(\'<hex>\') in the expression instead';
26
+ const NON_UTF8_HINT = 'a JSON input cannot carry these bytes here (only a settings or query-parameter value has the {"b64": ...} object form, and a string holding a lone surrogate has no bytes; pass a Uint8Array)';
23
27
  /** True for a string with a lone surrogate, which no UTF-8 encoding carries: `JSON.stringify` writes it as a `\udXXX` escape and `TextEncoder` as U+FFFD. */
24
28
  function hasLoneSurrogate(text) {
25
29
  return /\p{Surrogate}/u.test(text);
26
30
  }
27
- function checkStrings(what, map) {
31
+ // ignoreBOM: a leading U+FEFF is data, and the decoder must not drop it.
32
+ const utf8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
33
+ /** The text of `bytes` when they are valid UTF-8, else `undefined`. */
34
+ function utf8Text(bytes) {
35
+ try {
36
+ return utf8.decode(bytes);
37
+ }
38
+ catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ function isValidUtf8(bytes) {
43
+ return utf8Text(bytes) !== undefined;
44
+ }
45
+ /**
46
+ * One value of `json_object_byte_values`: a string stays a JSON string, and
47
+ * bytes are a JSON string when they are valid UTF-8 and `{"b64": ...}` (standard
48
+ * base64, padded) otherwise. `where` names the value for a refusal.
49
+ */
50
+ function wireValue(what, where, v) {
51
+ if (typeof v === 'string') {
52
+ if (hasLoneSurrogate(v))
53
+ throw usageError(`${what}: ${where} is not valid UTF-8, and ${NON_UTF8_HINT}`);
54
+ return v;
55
+ }
56
+ if (v instanceof Uint8Array) {
57
+ return utf8Text(v) ?? { b64: asBuffer(v).toString('base64') };
58
+ }
59
+ throw new TypeError(`chtypes: ${what} ${where} must be a string or a Uint8Array, got ${typeof v}`);
60
+ }
61
+ function keyName(k) {
62
+ return `the key ${JSON.stringify(k)}`;
63
+ }
64
+ /** The wire form of a map of byte values; refuses a key that is not valid UTF-8 (the key is shown through JSON.stringify, which escapes a lone surrogate: never raw). */
65
+ function wireMap(what, map) {
28
66
  const shown = what === 'params' ? 'query parameters' : what;
67
+ const out = {};
29
68
  for (const [k, v] of Object.entries(map)) {
30
- if (typeof v !== 'string')
31
- throw new TypeError(`chtypes: ${what}[${JSON.stringify(k)}] must be a string, got ${typeof v}`);
32
- // The key is shown through JSON.stringify, which escapes a lone surrogate: never raw.
33
69
  if (hasLoneSurrogate(k))
34
- throw usageError(`${shown}: the key ${JSON.stringify(k)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
35
- if (hasLoneSurrogate(v))
36
- throw usageError(`${shown}: the value for key ${JSON.stringify(k)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
70
+ throw usageError(`${shown}: ${keyName(k)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
71
+ if (typeof v !== 'string' && !(v instanceof Uint8Array)) {
72
+ throw new TypeError(`chtypes: ${what}[${JSON.stringify(k)}] must be a string or a Uint8Array, got ${typeof v}`);
73
+ }
74
+ // defineProperty, so a key such as "__proto__" is an own member and never the prototype.
75
+ Object.defineProperty(out, k, { value: wireValue(shown, `the value for key ${JSON.stringify(k)}`, v), enumerable: true, writable: true, configurable: true });
37
76
  }
38
- }
39
- function checkZone(what, zone) {
40
- if (hasLoneSurrogate(zone))
41
- throw usageError(`${what}: the value is not valid UTF-8, and ${NON_UTF8_HINT}`);
77
+ return out;
42
78
  }
43
79
  /**
44
80
  * The `settings` input of a call: nothing (length 0) when there is neither a
@@ -48,19 +84,18 @@ function checkZone(what, zone) {
48
84
  export function encodeSettings(settings, sessionTimezone) {
49
85
  if (settings === undefined && sessionTimezone === undefined)
50
86
  return Buffer.alloc(0);
51
- const out = {};
87
+ let out = {};
52
88
  if (settings !== undefined) {
53
- checkStrings('settings', settings);
54
89
  if (sessionTimezone !== undefined && Object.hasOwn(settings, ZONE_KEY)) {
55
90
  throw usageError(`the zone was given twice: sessionTimezone and a ${ZONE_KEY} key in settings; pass only one`);
56
91
  }
57
- Object.assign(out, settings);
92
+ out = wireMap('settings', settings);
58
93
  }
59
94
  if (sessionTimezone !== undefined) {
60
- if (typeof sessionTimezone !== 'string')
61
- throw new TypeError(`chtypes: sessionTimezone must be a string, got ${typeof sessionTimezone}`);
62
- checkZone('the zone', sessionTimezone);
63
- out[ZONE_KEY] = sessionTimezone;
95
+ if (typeof sessionTimezone !== 'string' && !(sessionTimezone instanceof Uint8Array)) {
96
+ throw new TypeError(`chtypes: sessionTimezone must be a string or a Uint8Array, got ${typeof sessionTimezone}`);
97
+ }
98
+ out[ZONE_KEY] = wireValue('the zone', 'the value', sessionTimezone);
64
99
  }
65
100
  return Buffer.from(JSON.stringify(out), 'utf8');
66
101
  }
@@ -68,18 +103,7 @@ export function encodeSettings(settings, sessionTimezone) {
68
103
  export function encodeParams(params) {
69
104
  if (params === undefined)
70
105
  return Buffer.alloc(0);
71
- checkStrings('params', params);
72
- return Buffer.from(JSON.stringify({ ...params }), 'utf8');
73
- }
74
- const utf8 = new TextDecoder('utf-8', { fatal: true });
75
- function isValidUtf8(bytes) {
76
- try {
77
- utf8.decode(bytes);
78
- return true;
79
- }
80
- catch {
81
- return false;
82
- }
106
+ return Buffer.from(JSON.stringify(wireMap('params', params)), 'utf8');
83
107
  }
84
108
  /** The INSERT column list: a JSON array of names, each an object carrying `name` when its bytes are valid UTF-8 and `name_b64` otherwise, or nothing (length 0) when absent. */
85
109
  export function encodeColumns(columns) {
@@ -92,9 +116,9 @@ export function encodeColumns(columns) {
92
116
  });
93
117
  return Buffer.from(JSON.stringify(names), 'utf8');
94
118
  }
95
- /** The process default settings, as `chs_set_defaults` takes them. */
119
+ /** The process default settings, as `chs_set_defaults` takes them: the wire form of each value (a value that is not valid UTF-8 is `{"b64": ...}`). */
96
120
  export function validateDefaults(defaults) {
97
- checkStrings('defaults', defaults);
121
+ return wireMap('defaults', defaults);
98
122
  }
99
123
  /** The profile document: an empty or absent zone, absent settings and absent macros are omitted; a present map is sent as given, `{}` when empty. */
100
124
  export function encodeServerProfile(profile) {
@@ -102,17 +126,132 @@ export function encodeServerProfile(profile) {
102
126
  if (profile.timezone !== undefined && profile.timezone !== '') {
103
127
  if (typeof profile.timezone !== 'string')
104
128
  throw new TypeError(`chtypes: timezone must be a string, got ${typeof profile.timezone}`);
105
- checkZone('server profile: the timezone', profile.timezone);
129
+ if (hasLoneSurrogate(profile.timezone))
130
+ throw usageError(`server profile: the timezone is not valid UTF-8, and ${NON_UTF8_HINT}`);
106
131
  out.timezone = profile.timezone;
107
132
  }
108
133
  if (profile.settings !== undefined) {
109
- checkStrings('settings', profile.settings);
110
- out.settings = { ...profile.settings };
134
+ out.settings = wireMap('settings', profile.settings);
111
135
  }
112
136
  if (profile.macros !== undefined) {
113
- checkStrings('macros', profile.macros);
137
+ for (const [k, v] of Object.entries(profile.macros)) {
138
+ if (typeof v !== 'string')
139
+ throw new TypeError(`chtypes: macros[${JSON.stringify(k)}] must be a string, got ${typeof v}`);
140
+ if (hasLoneSurrogate(k))
141
+ throw usageError(`macros: ${keyName(k)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
142
+ if (hasLoneSurrogate(v))
143
+ throw usageError(`macros: the value for key ${JSON.stringify(k)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
144
+ }
114
145
  out.macros = { ...profile.macros };
115
146
  }
116
147
  return Buffer.from(JSON.stringify(out), 'utf8');
117
148
  }
149
+ // ---- the options documents (rule r1). Each named member is its own option, and a
150
+ // key the binding has no name for goes through an `...Extra` record as JSON text.
151
+ // The binding builds the document from the members the caller set, sends nothing
152
+ // when none was set, and validates no member: the library refuses a key it does not
153
+ // know, or a value that is not one of the member's, with CHS_INVALID_ARGUMENT,
154
+ // naming it.
155
+ /** `insert_options.verdict_basis`: what row a filter verdict answers for. */
156
+ export const VerdictBasis = {
157
+ /** The default: the verdict answers for the input row. */
158
+ Input: 'input',
159
+ /** The row the export would store. A build that does not implement it declines it. */
160
+ Export: 'export',
161
+ };
162
+ /** `insert_options.defer_defaults`. */
163
+ export const DeferDefaults = {
164
+ /** The default: no DEFAULT is deferred. */
165
+ None: 'none',
166
+ /** Defer to the server each DEFAULT the build would otherwise decline. A build that does not implement it declines it. */
167
+ Server: 'server',
168
+ };
169
+ /** `filter_options.param_encoding`: how a query parameter's value is read. */
170
+ export const ParamEncoding = {
171
+ /** The default: ClickHouse's escaped-text reader. */
172
+ Escaped: 'escaped',
173
+ /** The bytes as the value. A build that does not implement it declines it. */
174
+ Raw: 'raw',
175
+ };
176
+ /** A name or value as a byte-string member: `<key>` when it is text, `<key>_b64` otherwise. */
177
+ function byteMember(what, key, v) {
178
+ if (typeof v === 'string') {
179
+ if (hasLoneSurrogate(v))
180
+ throw usageError(`${what}: the ${key} is not valid UTF-8, and ${NON_UTF8_HINT}`);
181
+ return { [key]: v };
182
+ }
183
+ if (!(v instanceof Uint8Array))
184
+ throw new TypeError(`chtypes: ${what}: the ${key} must be a string or a Uint8Array, got ${typeof v}`);
185
+ return isValidUtf8(v) ? { [key]: Buffer.from(v.buffer, v.byteOffset, v.byteLength).toString('utf8') } : { [`${key}_b64`]: asBuffer(v).toString('base64') };
186
+ }
187
+ function nameObject(what, name) {
188
+ return byteMember(what, 'name', name);
189
+ }
190
+ /** The members of an options document under construction, each as its JSON text, by key; a key set twice keeps the last. */
191
+ class OptionDoc {
192
+ #members = new Map();
193
+ what;
194
+ constructor(what) {
195
+ this.what = what;
196
+ }
197
+ set(key, value) {
198
+ this.#members.set(key, JSON.stringify(value));
199
+ }
200
+ /** Members given as JSON text, passed through verbatim after a validity check. */
201
+ setRaw(extra) {
202
+ if (extra === undefined)
203
+ return;
204
+ for (const [key, text] of Object.entries(extra)) {
205
+ if (hasLoneSurrogate(key))
206
+ throw usageError(`${this.what}: ${keyName(key)} is not valid UTF-8, and ${NON_UTF8_HINT}`);
207
+ if (typeof text !== 'string')
208
+ throw new TypeError(`chtypes: ${this.what}[${JSON.stringify(key)}] must be JSON text (a string), got ${typeof text}`);
209
+ try {
210
+ JSON.parse(text);
211
+ }
212
+ catch {
213
+ throw usageError(`${this.what}: the value for key ${JSON.stringify(key)} is not valid JSON`);
214
+ }
215
+ this.#members.set(key, text);
216
+ }
217
+ }
218
+ /** The document, or nothing (length 0, which the library reads as `{}`) when no member was set. */
219
+ encode() {
220
+ if (this.#members.size === 0)
221
+ return Buffer.alloc(0);
222
+ const members = [...this.#members].map(([k, text]) => `${JSON.stringify(k)}:${text}`);
223
+ return Buffer.from(`{${members.join(',')}}`, 'utf8');
224
+ }
225
+ }
226
+ /** The `insert_options` document of a call that models an INSERT. */
227
+ export function encodeInsertOptions(o) {
228
+ const doc = new OptionDoc('insert options');
229
+ if (o.insertableColumns !== undefined)
230
+ doc.set('insertable_columns', o.insertableColumns.map((n) => nameObject('insert options', n)));
231
+ if (o.columnDefaults !== undefined) {
232
+ doc.set('column_defaults', o.columnDefaults.map((d) => ({ ...nameObject('insert options', d.name), ...byteMember('insert options', 'value', d.value) })));
233
+ }
234
+ if (o.verdictBasis !== undefined)
235
+ doc.set('verdict_basis', o.verdictBasis);
236
+ if (o.deferDefaults !== undefined)
237
+ doc.set('defer_defaults', o.deferDefaults);
238
+ doc.setRaw(o.insertOptionsExtra);
239
+ return doc.encode();
240
+ }
241
+ /** The `filter_options` document of `chs_filter_create`. */
242
+ export function encodeFilterOptions(o) {
243
+ const doc = new OptionDoc('filter options');
244
+ if (o.paramEncoding !== undefined)
245
+ doc.set('param_encoding', o.paramEncoding);
246
+ doc.setRaw(o.filterOptionsExtra);
247
+ return doc.encode();
248
+ }
249
+ /** The `schema_options` document of `chs_schema_create`. */
250
+ export function encodeSchemaOptions(o) {
251
+ const doc = new OptionDoc('schema options');
252
+ if (o.posture !== undefined)
253
+ doc.set('posture', o.posture);
254
+ doc.setRaw(o.schemaOptionsExtra);
255
+ return doc.encode();
256
+ }
118
257
  //# sourceMappingURL=settings.js.map