@coldsmirk/inkstone-sql 0.13.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.
@@ -0,0 +1,380 @@
1
+ import { C as CatalogTable, S as CatalogFunction, _ as readCall, a as createSqlAssist, b as runnableStatement, c as SqlSource, d as CallRead, f as IdentifierRead, g as TableRef, h as StatementRead, i as SqlSignatureHelp, l as createSqlSchema, m as StatementContext, n as SqlCompletionCandidate, o as SqlCatalog, p as Runnable, r as SqlHoverCard, s as SqlSchema, t as SqlAssist, u as qualifiedName, v as readIdentifier, w as SqlKind, x as CatalogColumn, y as readStatement } from "./assist-gLTZKSD3.js";
2
+
3
+ //#region src/functions.d.ts
4
+ /**
5
+ * The function vocabulary this bench speaks: the curated floor this project wrote
6
+ * down, and whatever the data source in front of the operator reports about itself — its own
7
+ * routines from every kind, its built-ins from the kinds whose catalogs describe them.
8
+ *
9
+ * Completion, hover and signature help all read it here, so a name cannot mean one thing in the
10
+ * pane and another under the mouse.
11
+ */
12
+ /**
13
+ * One function, however the bench came to know it.
14
+ */
15
+ interface BenchFunction {
16
+ name: string;
17
+ /**
18
+ * The call as it is written — what signature help parses.
19
+ */
20
+ signature: string;
21
+ /**
22
+ * One line about it: this project's own for a curated name, the database's own description for
23
+ * anything else, and empty where neither exists.
24
+ */
25
+ summary: string;
26
+ /**
27
+ * The return type as the catalog spells it, shown beside the call on the hover card; empty
28
+ * where the catalog reports none — the curated floor included, whose signatures carry the
29
+ * return in their own prose where it matters.
30
+ */
31
+ returns: string;
32
+ /**
33
+ * The owner or package a call must qualify with; empty for a built-in, and for a routine the
34
+ * connected schema already resolves.
35
+ */
36
+ qualifier: string;
37
+ /**
38
+ * Where it came from. It decides how the pane ranks it and what a hover says about it: a
39
+ * routine is the estate's own, a curated name is bench vocabulary, and the rest is the
40
+ * vendor's own long tail.
41
+ */
42
+ origin: "routine" | "curated" | "builtin";
43
+ }
44
+ interface SqlFunctions {
45
+ /**
46
+ * Every function the bench can offer, in rank order. Falls back to the curated floor alone
47
+ * when the catalog refuses — a vocabulary is not worth a failed keystroke.
48
+ */
49
+ all: () => Promise<BenchFunction[]>;
50
+ /**
51
+ * One function by name, however the operator cased it.
52
+ */
53
+ find: (name: string) => Promise<BenchFunction | null>;
54
+ }
55
+ declare function createSqlFunctions(kind: SqlKind, schema: SqlSchema): SqlFunctions;
56
+ //#endregion
57
+ //#region src/completion.d.ts
58
+ /**
59
+ * Completion for one system's data source, over the schema the tree already reads.
60
+ */
61
+ declare function createSqlCompletion(kind: SqlKind, schema: SqlSchema, functions: SqlFunctions): SqlAssist["complete"];
62
+ //#endregion
63
+ //#region src/dialect.d.ts
64
+ /**
65
+ * One function the bench knows how to talk about: the call as the operator writes it, and one
66
+ * line saying what it does. The signature is the whole parameter contract — signature help reads
67
+ * the parameters straight out of its parens, so a `…` tail is what marks a variadic call.
68
+ *
69
+ * The summaries are English, the register the script editor's API docs already use: they read as
70
+ * reference documentation beside each vendor's own, which is where an operator checks them next.
71
+ */
72
+ interface SqlFunction {
73
+ name: string;
74
+ signature: string;
75
+ summary: string;
76
+ }
77
+ /**
78
+ * One kind's completion vocabulary. Curated bench vocabulary, not the reference
79
+ * manual: the words an integration engineer writes at this console, weighted toward reading — a
80
+ * keyword or function missing here costs one suggestion, so the lists stay honest rather than
81
+ * exhaustive. Everything is lowercase, the casing the bench itself writes (the tree's
82
+ * `select * from`, the editor placeholder); completion re-cases it to follow the operator's hand.
83
+ */
84
+ interface SqlDialect {
85
+ keywords: string[];
86
+ functions: SqlFunction[];
87
+ }
88
+ declare const SQL_DIALECTS: Record<SqlKind, SqlDialect>;
89
+ /**
90
+ * One kind's function by name, however the operator cased it. Hover and signature help both ask.
91
+ */
92
+ /**
93
+ * A signature's parameters as `[start, end)` offsets into the signature itself — offsets rather
94
+ * than substrings so a call that repeats a parameter name still marks the right one. Everything
95
+ * between the first `(` and the last `)`, split on the commas at that depth.
96
+ */
97
+ declare function signatureParameters(signature: string): Array<[number, number]>;
98
+ //#endregion
99
+ //#region src/format.d.ts
100
+ declare function createSqlFormat(kind: SqlKind): SqlAssist["format"];
101
+ //#endregion
102
+ //#region src/hover.d.ts
103
+ declare function createSqlHover(kind: SqlKind, schema: SqlSchema, functions: SqlFunctions): SqlAssist["hover"];
104
+ //#endregion
105
+ //#region src/joins.d.ts
106
+ /**
107
+ * What two tables' own naming says about how they join. A named-shape heuristic read
108
+ * against the catalog's key flags: the catalog says a column *is* a foreign key, never whom it
109
+ * points at — that is a non-goal — so the name is what is left to read. A miss costs one
110
+ * suggestion, never a statement, which is what lets the guessing be this plain.
111
+ */
112
+ interface JoinGuess {
113
+ /**
114
+ * The condition as the operator would write it, aliases and all.
115
+ */
116
+ text: string;
117
+ /**
118
+ * Which reading found it, shown beside the suggestion so the operator can weigh it. A code —
119
+ * the consuming app owns the wording and the language.
120
+ */
121
+ why: JoinReason;
122
+ }
123
+ /**
124
+ * How a join guess was found: a column whose own name points into the other table's key
125
+ * (`order_id` → `orders.id`, `contract_code` → `contract.code`), or one name both tables spell
126
+ * where exactly one side keys it.
127
+ */
128
+ type JoinReason = "named-foreign-key" | "shared-key";
129
+ /**
130
+ * The equalities worth offering when `target` is joined onto tables the statement already reads.
131
+ * The named foreign key leads, in both directions; the plainer shared-key reading follows.
132
+ */
133
+ declare function joinGuesses(kind: SqlKind, target: SqlSource, others: SqlSource[]): JoinGuess[];
134
+ //#endregion
135
+ //#region src/markers.d.ts
136
+ /**
137
+ * Placeholder detection for what a run asks the operator for.
138
+ *
139
+ * This is **not** validation and must never become it: the engine-side scanner (the polyglot
140
+ * sidecar's `internal/scan`) is the authority on what binds, it is lexical and per-dialect, and a second
141
+ * implementation here would drift from it the first time a dialect gained a quoting form. All
142
+ * this decides is whether the run has values to ask for, which form the parameter dialog
143
+ * offers, and — where the statement is one the scanner refuses outright — the refusal, as a
144
+ * code, so the editor can say so before the round trip does.
145
+ *
146
+ * **Callers pass the statement's blanked form** (`Runnable.blanked`), never its raw text. A
147
+ * disagreement with the engine's scanner is not cosmetic in either direction — it answers both
148
+ * "statement binds no parameters, request provides 1" and "statement binds 2, request provides
149
+ * 1" with a hard refusal — and quoted prose is where a raw scan disagrees first: `select '?'`
150
+ * has no placeholder in it. Blanking is the reader's job because the reader already owns what is
151
+ * prose and what is SQL for this page, and it takes that decision under the data source's own
152
+ * lexical profile (`noise.ts`), mode for mode with the scanner — MySQL's `#` comments and
153
+ * backslash escapes, Postgres's `$tag$` bodies, Oracle's `q'…'`, every kind's quoted names — so
154
+ * what reaches this file is exactly the text the engine would mint markers from.
155
+ */
156
+ /**
157
+ * The binding form a statement's markers suggest.
158
+ */
159
+ type MarkerForm = "none" | "positional" | "named";
160
+ /**
161
+ * A statement the engine's scanner refuses outright, mirrored here so the editor can say so
162
+ * without the round trip. A code, not a sentence — the consuming app owns the wording:
163
+ *
164
+ * - `"mixed-forms"` — the statement writes both `?` and `:name`; the scanner binds neither.
165
+ * - `"question-escape-unsupported"` — `??` on a kind whose native form is itself `?` (MySQL,
166
+ * 达梦): the escape has no rendering that survives, and neither dialect has a `?` operator to
167
+ * escape in the first place.
168
+ * - `"native-marker-collision"` — a marker hand-written in the kind's own bind form (`$1`,
169
+ * `:1`, `@p1`) beside a `?`/`:name` the scanner would mint: both would bind the same slot.
170
+ */
171
+ type MarkerRefusal = "mixed-forms" | "question-escape-unsupported" | "native-marker-collision";
172
+ /**
173
+ * What a statement appears to bind. `?` (but not `??`, the escape) suggests positional; `:name`
174
+ * (but not `::`, Postgres's cast) suggests named. A statement that writes both is counted
175
+ * whole — the named grid is the one that shows what it found — with the fault on record in
176
+ * `refusal`.
177
+ */
178
+ interface StatementMarkers {
179
+ form: MarkerForm;
180
+ /**
181
+ * The distinct `:name` markers, in first-appearance order.
182
+ */
183
+ names: string[];
184
+ /**
185
+ * How many `?` markers appeared.
186
+ */
187
+ count: number;
188
+ /**
189
+ * The first refusal the engine's scanner would raise for this statement, in its own document
190
+ * order — or `null` where it binds cleanly. `names` and `count` still describe the whole
191
+ * text, so a dialog can show what it found beside the fault.
192
+ */
193
+ refusal: MarkerRefusal | null;
194
+ }
195
+ declare function statementMarkers(statement: string, kind: SqlKind): StatementMarkers;
196
+ //#endregion
197
+ //#region src/noise.d.ts
198
+ /**
199
+ * A run the reader must not look inside. `sealed` says the closing delimiter was found: a caret
200
+ * right after a sealed run is back in the statement, while a caret at the end of an unterminated
201
+ * string or a line comment is still inside it.
202
+ */
203
+ interface NoiseSpan {
204
+ start: number;
205
+ end: number;
206
+ sealed: boolean;
207
+ /**
208
+ * The run is a quoted *name* rather than a literal or a comment — text the tokenizer must take
209
+ * whole, but text it is looking for, so it survives in [BlankedSql.withNames].
210
+ */
211
+ name: boolean;
212
+ }
213
+ interface BlankedSql {
214
+ /**
215
+ * Every string and comment overwritten by spaces, character for character, with quoted names
216
+ * left standing — what the tokenizer reads, since names are what it is after.
217
+ */
218
+ withNames: string;
219
+ /**
220
+ * The same, with quoted names blanked as well: everything the engine's scanner skips whole. A
221
+ * placeholder scan reads this, and so does every structural read (`;` splitting, emptiness), so
222
+ * a `?` or a `;` inside a name means here exactly what it means to the engine — nothing.
223
+ */
224
+ blanked: string;
225
+ spans: NoiseSpan[];
226
+ }
227
+ /**
228
+ * The statement with its noise blanked out, char for char, so every offset survives — in the two
229
+ * renderings the reader needs (see [BlankedSql]). One pass, mirroring the sidecar scanner's own
230
+ * loop over its mutually exclusive lexical modes.
231
+ */
232
+ declare function blankNoise(text: string, kind: SqlKind): BlankedSql;
233
+ /**
234
+ * Whether the caret sits inside a string or a comment, where the bench has nothing to say. A
235
+ * quoted name is not one: it is a name the operator is writing, and the reader is about names.
236
+ */
237
+ declare function insideNoise(spans: NoiseSpan[], cursor: number): boolean;
238
+ //#endregion
239
+ //#region src/origin.d.ts
240
+ /**
241
+ * Where a statement's result columns verifiably come from: the tree's own single-table
242
+ * `select * from <table>` skeleton, with at most a filtering tail (`where` / `order` /
243
+ * `limit`-class). Joins, column lists, aliases and subqueries all answer `null` — for those the
244
+ * result grid shows bare column names, because a comment that might belong to a different
245
+ * column is worse than none.
246
+ */
247
+ interface StatementOrigin {
248
+ /**
249
+ * Empty when the statement names the table unqualified — the connected schema-or-user.
250
+ */
251
+ schema: string;
252
+ table: string;
253
+ }
254
+ declare function statementOrigin(statement: string): StatementOrigin | null;
255
+ //#endregion
256
+ //#region src/params.d.ts
257
+ /**
258
+ * What a bound parameter is, and what it becomes on the wire.
259
+ *
260
+ * The unified-placeholder endpoint takes scalars — text, number, boolean, null — and refuses
261
+ * arrays and objects, so those four are the whole of what a row can be. Declaring one is not the
262
+ * guessing an editing surface must never do: it is the decision a statement's author already
263
+ * makes when they write `[42]` rather than `["42"]`, and NULL cannot be entered at all without it.
264
+ *
265
+ * A refusal is a code, never a sentence: the host owns the wording (and the language) of what it
266
+ * tells the operator, so this module reports *what* could not bind and leaves *how to say it*
267
+ * to the surface that asked.
268
+ */
269
+ /**
270
+ * The scalar set the endpoint accepts, as one type.
271
+ */
272
+ type SqlScalar = string | number | boolean | null;
273
+ type ParamType = "text" | "number" | "boolean" | "null";
274
+ /**
275
+ * One row of a params grid. `text` is what the operator typed, kept exactly as typed — changing
276
+ * a row's type never rewrites it, because reinterpreting `0042` as `42` behind their back would
277
+ * bind a value they did not write.
278
+ */
279
+ interface ParamValue {
280
+ readonly type: ParamType;
281
+ readonly text: string;
282
+ }
283
+ /**
284
+ * A row's opening state, and what an untouched row stays: text, so a statement run without ever
285
+ * opening the type column behaves exactly as it did before the column existed. Frozen, because
286
+ * it is also the *shared default* a missing row falls back to — one consumer writing through it
287
+ * would rewrite every untouched row on the page.
288
+ */
289
+ declare const TEXT_PARAM: ParamValue;
290
+ /**
291
+ * Whether a statement asks for values and the operator has entered none of them. This is the
292
+ * host's cue to ask rather than to send: binding a row of empty strings is never what was meant,
293
+ * and the rows live behind a dialog, so nothing on the page would have said otherwise.
294
+ *
295
+ * A statement that binds nothing is never untouched — there is nothing to touch.
296
+ */
297
+ declare function untouched(rows: Record<string, ParamValue>): boolean;
298
+ /**
299
+ * Why one row could not bind.
300
+ *
301
+ * - `empty` — a number row holding nothing.
302
+ * - `not-a-boolean` — a boolean row holding anything but `true` / `false`.
303
+ * - `not-a-number` — text a person would not call a number (`0x10`, `Infinity`, `1,000`).
304
+ * - `not-finite` — a number the double could not carry.
305
+ * - `unsafe-integer` — an integer past ±(2^53 − 1); binding it as text carries it faithfully.
306
+ */
307
+ type BindRefusal = "empty" | "not-a-boolean" | "not-a-number" | "not-finite" | "unsafe-integer";
308
+ /**
309
+ * What one row binds as, or why it cannot. A refusal names the row's own trouble; the caller adds
310
+ * which row it was.
311
+ */
312
+ type Bound = {
313
+ ok: true;
314
+ value: SqlScalar;
315
+ } | {
316
+ ok: false;
317
+ refusal: BindRefusal;
318
+ };
319
+ declare function boundValue(param: ParamValue): Bound;
320
+ /**
321
+ * Every row bound, in the shape the marker form chose: positional values keep slot order, named
322
+ * values keep their keys. `undefined` is a statement that binds nothing.
323
+ *
324
+ * A row its type cannot carry stops the whole run and is named — sending the rest would run the
325
+ * statement against arguments the operator did not write. The refusal carries the row's form and
326
+ * key (`"2"` for the second positional slot, `"when"` for `:when`) so the host can point at it.
327
+ */
328
+ type BoundParams = {
329
+ ok: true;
330
+ params: SqlScalar[] | Record<string, SqlScalar> | undefined;
331
+ } | {
332
+ ok: false;
333
+ form: "positional" | "named";
334
+ key: string;
335
+ refusal: BindRefusal;
336
+ };
337
+ declare function boundParams(markers: StatementMarkers, rows: Record<string, ParamValue>): BoundParams;
338
+ //#endregion
339
+ //#region src/signature.d.ts
340
+ /**
341
+ * The signature of the call the caret is inside, over the vocabulary this bench
342
+ * speaks — the curated floor and whatever the data source reports about itself, so the estate's
343
+ * own routines raise their parameters exactly as the vendor's do. The argument is counted at the
344
+ * caret's own paren depth, so a call nested in another's arguments still marks its own.
345
+ */
346
+ declare function createSqlSignature(kind: SqlKind, functions: SqlFunctions): SqlAssist["signature"];
347
+ //#endregion
348
+ //#region src/spelling.d.ts
349
+ /**
350
+ * One catalog name as the statement must spell it.
351
+ */
352
+ declare function spellIdentifier(kind: SqlKind, name: string): string;
353
+ /**
354
+ * A routine name as a call must spell it. Reservation does not delimit here: a reserved word in
355
+ * call position is legal in every kind — `json_table(...)`, `left(...)` are the vendors' own
356
+ * builtins — and delimiting one would un-call it; only a lexically irregular name needs the
357
+ * delimiter.
358
+ */
359
+ declare function spellCallable(kind: SqlKind, name: string): string;
360
+ /**
361
+ * The qualifier a generated expression writes before a source's columns: the alias exactly as
362
+ * the operator wrote it — re-spelling the unquoted form would be lossy — or, where the ref has
363
+ * no alias, the catalog's table name in the kind's own spelling.
364
+ */
365
+ declare function spellQualifier(kind: SqlKind, source: {
366
+ aliasWritten: string;
367
+ table: {
368
+ name: string;
369
+ };
370
+ }): string;
371
+ /**
372
+ * A table's qualified name as the statement must spell it. Kinds whose catalog reports no schema
373
+ * (or whose objects sit in the session's own) get the bare name.
374
+ */
375
+ declare function spellQualifiedName(kind: SqlKind, table: {
376
+ schema: string;
377
+ name: string;
378
+ }): string;
379
+ //#endregion
380
+ export { type BenchFunction, type BindRefusal, type BlankedSql, type Bound, type BoundParams, type CallRead, type CatalogColumn, type CatalogFunction, type CatalogTable, type IdentifierRead, type JoinGuess, type JoinReason, type MarkerForm, type MarkerRefusal, type NoiseSpan, type ParamType, type ParamValue, type Runnable, SQL_DIALECTS, type SqlAssist, type SqlCatalog, type SqlCompletionCandidate, type SqlDialect, type SqlFunction, type SqlFunctions, type SqlHoverCard, type SqlKind, type SqlScalar, type SqlSchema, type SqlSignatureHelp, type SqlSource, type StatementContext, type StatementMarkers, type StatementOrigin, type StatementRead, TEXT_PARAM, type TableRef, blankNoise, boundParams, boundValue, createSqlAssist, createSqlCompletion, createSqlFormat, createSqlFunctions, createSqlHover, createSqlSchema, createSqlSignature, insideNoise, joinGuesses, qualifiedName, readCall, readIdentifier, readStatement, runnableStatement, signatureParameters, spellCallable, spellIdentifier, spellQualifiedName, spellQualifier, statementMarkers, statementOrigin, untouched };