@tinyshed/tinystore 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/console.d.ts CHANGED
@@ -35,9 +35,12 @@ export declare function jsonLine(line: ConsoleLine): string;
35
35
  /**
36
36
  * A line as a person reads it: the time of day, the level padded to five, the
37
37
  * stream, the message, the context's fields and the attributes', and the
38
- * trace's first eight digits. A value of several lines, a stack or a
39
- * traceback, follows the line, indented. A key or a string shows without its
40
- * quotes when it is one word with no '=', quote or backslash.
38
+ * trace's first eight digits. A message's further lines, and then a value of
39
+ * several lines, a stack or a traceback, follow the line, indented, so that
40
+ * none of them starts where a line does. A key or a string shows without its
41
+ * quotes when it is one word with no '=', quote or backslash. What a program
42
+ * logged shows no control character but a tab: the message, the event's name,
43
+ * a value below the line and a source each show it as its escape.
41
44
  */
42
45
  export declare function prettyLine(line: ConsoleLine, look: Look): string;
43
46
  /** A level as slog spells it: INFO, WARN+2, DEBUG-4. */
package/dist/console.js CHANGED
@@ -46,9 +46,12 @@ const cyan = '\x1b[36m';
46
46
  /**
47
47
  * A line as a person reads it: the time of day, the level padded to five, the
48
48
  * stream, the message, the context's fields and the attributes', and the
49
- * trace's first eight digits. A value of several lines, a stack or a
50
- * traceback, follows the line, indented. A key or a string shows without its
51
- * quotes when it is one word with no '=', quote or backslash.
49
+ * trace's first eight digits. A message's further lines, and then a value of
50
+ * several lines, a stack or a traceback, follow the line, indented, so that
51
+ * none of them starts where a line does. A key or a string shows without its
52
+ * quotes when it is one word with no '=', quote or backslash. What a program
53
+ * logged shows no control character but a tab: the message, the event's name,
54
+ * a value below the line and a source each show it as its escape.
52
55
  */
53
56
  export function prettyLine(line, look) {
54
57
  const paint = (hue, text) => (look.color ? hue + text + reset : text);
@@ -61,7 +64,7 @@ export function prettyLine(line, look) {
61
64
  out += `${separator}${paint(cyan, line.stream)}`;
62
65
  separator = ' ';
63
66
  }
64
- const message = prettyMessage(line);
67
+ const [message, further] = prettyMessage(line);
65
68
  if (message !== '') {
66
69
  out += `${separator}${message}`;
67
70
  separator = ' ';
@@ -85,17 +88,46 @@ export function prettyLine(line, look) {
85
88
  if (line.traceId !== undefined) {
86
89
  field('trace', line.traceId.slice(0, 8));
87
90
  }
91
+ for (const part of further) {
92
+ out += `\n ${escaped(part)}`;
93
+ }
88
94
  for (const [key, text] of below) {
89
- text
90
- .replace(/[\r\n]+$/, '')
91
- .split('\n')
92
- .forEach((part, i) => {
93
- const shown = part.replace(/\r$/, '');
94
- out += `\n ${paint(dim, i === 0 ? `${key}: ${shown}` : shown)}`;
95
+ linesOf(text).forEach((part, i) => {
96
+ out += `\n ${paint(dim, escaped(i === 0 ? `${key}: ${part}` : part))}`;
95
97
  });
96
98
  }
97
99
  return `${out}\n`;
98
100
  }
101
+ /**
102
+ * The lines of a text of several, without the line ends after the last, and
103
+ * each without the carriage return before its newline: "line one\r\nline
104
+ * two\r\n" is line one, line two.
105
+ */
106
+ function linesOf(text) {
107
+ const lines = text.replace(/[\r\n]+$/, '').split('\n');
108
+ return lines.map(part => part.replace(/\r$/, ''));
109
+ }
110
+ /**
111
+ * Text a program logged as a pretty line shows it: each control character but
112
+ * a tab, and DEL, as its JSON escape, so that none reaches the terminal as an
113
+ * escape sequence, a carriage return or a line of its own. The colours the
114
+ * console paints with are its own, never in this text.
115
+ *
116
+ * "\x1b[2J" → \u001b[2J "a\rb" → a\rb "\x7f" → \u007f
117
+ */
118
+ function escaped(text) {
119
+ let out = '';
120
+ for (const c of text) {
121
+ const code = c.codePointAt(0);
122
+ if ((code < 0x20 && c !== '\t') || code === 0x7f) {
123
+ out += code === 0x7f ? '\\u007f' : JSON.stringify(c).slice(1, -1);
124
+ }
125
+ else {
126
+ out += c;
127
+ }
128
+ }
129
+ return out;
130
+ }
99
131
  /** A level as slog spells it: INFO, WARN+2, DEBUG-4. */
100
132
  export function levelLabel(level) {
101
133
  const spell = (base, from) => {
@@ -120,12 +152,19 @@ function prettyLevel(level) {
120
152
  const hue = level < 0 ? blue : level < 4 ? green : level < 8 ? yellow : red;
121
153
  return [levelLabel(level), hue];
122
154
  }
155
+ /**
156
+ * A log line's message, or an event's name and the message it may carry, as
157
+ * the line shows them; and the further lines of a message of several, which
158
+ * go below the line as a value's do.
159
+ */
123
160
  function prettyMessage(line) {
124
- const body = line.msg ?? '';
161
+ const [first, ...further] = linesOf(line.msg ?? '');
162
+ const body = escaped(first ?? '');
125
163
  if (line.event === undefined) {
126
- return body;
164
+ return [body, further];
127
165
  }
128
- return body === '' ? line.event : `${line.event} ${body}`;
166
+ const event = escaped(line.event);
167
+ return [body === '' ? event : `${event} ${body}`, further];
129
168
  }
130
169
  /** How a field's JSON shows, and whether it is text of several lines, which goes under the line. */
131
170
  function prettyValue(key, json) {
@@ -205,7 +244,7 @@ function shortSource(json) {
205
244
  }
206
245
  const parts = source.file.split(/[\\/]+/).filter(part => part !== '');
207
246
  const line = typeof source.line === 'number' ? source.line : 0;
208
- return `${parts.slice(-2).join('/')}:${line}`;
247
+ return escaped(`${parts.slice(-2).join('/')}:${line}`);
209
248
  }
210
249
  /** The names `redact` takes to hide the usual secrets, as Go's console.Secrets and Python's SECRETS. */
211
250
  export const secrets = Object.freeze([
package/dist/jobs.d.ts CHANGED
@@ -261,9 +261,10 @@ export declare class Queue<T> {
261
261
  */
262
262
  set(id: string, value: T, options?: JobOptions): Promise<void>;
263
263
  /**
264
- * Changes the id's job when it has not started: its value, and its time,
265
- * group or repeat when the options give them. It says whether it did: a
266
- * job that runs, ran or never was answers false.
264
+ * Changes the id's job when it is not running: its value, the steps kept
265
+ * for the old one dropped with it, and its time, group or repeat when the
266
+ * options give them. It says whether it did: a job that runs, is done or
267
+ * failed, or never was answers false.
267
268
  */
268
269
  update(id: string, value: T, options?: JobOptions): Promise<boolean>;
269
270
  /**
@@ -288,7 +289,10 @@ export declare class Queue<T> {
288
289
  * for await (const job of videos.watch(id)) send(job.state, job.ahead, job.progress)
289
290
  */
290
291
  watch(id: string): AsyncGenerator<Job<T>>;
291
- /** A page of the queue's jobs whose ids start with a prefix, or of its failed ones. */
292
+ /**
293
+ * A page of the queue's jobs: with no prefix every job, those with ids by id,
294
+ * then those without as they run, then those without that failed.
295
+ */
292
296
  list(options?: ListOptions): Promise<JobPage<T>>;
293
297
  /** Every job the options name, a page at a time, holding nothing between pages. */
294
298
  all(options?: Omit<ListOptions, 'after'>): AsyncGenerator<Job<T>>;
@@ -373,7 +377,7 @@ export declare class StoreTxQueue<T> {
373
377
  add(value: T, options?: AddOptions): Promise<void>;
374
378
  /** Makes the id's job this value at this time, whatever it was, with the commit. */
375
379
  set(id: string, value: T, options?: JobOptions): Promise<void>;
376
- /** Changes the id's job when it has not started, with the commit. */
380
+ /** Changes the id's job when it is not running, its old value's steps dropped, with the commit. */
377
381
  update(id: string, value: T, options?: JobOptions): Promise<void>;
378
382
  /** Takes the job under id, whatever its state, with the commit. */
379
383
  cancel(id: string): Promise<void>;
package/dist/jobs.js CHANGED
@@ -384,9 +384,10 @@ export class Queue {
384
384
  await callOf(this.#source, methods['jobs.set'], handle => JobsCall.encode({ ...fields, handle }), 'write');
385
385
  }
386
386
  /**
387
- * Changes the id's job when it has not started: its value, and its time,
388
- * group or repeat when the options give them. It says whether it did: a
389
- * job that runs, ran or never was answers false.
387
+ * Changes the id's job when it is not running: its value, the steps kept
388
+ * for the old one dropped with it, and its time, group or repeat when the
389
+ * options give them. It says whether it did: a job that runs, is done or
390
+ * failed, or never was answers false.
390
391
  */
391
392
  async update(id, value, options = {}) {
392
393
  const fields = { ...jobFields(options), id, value: this.#source.values.encode(value) };
@@ -420,7 +421,10 @@ export class Queue {
420
421
  watch(id) {
421
422
  return watchJob(this.#source, id);
422
423
  }
423
- /** A page of the queue's jobs whose ids start with a prefix, or of its failed ones. */
424
+ /**
425
+ * A page of the queue's jobs: with no prefix every job, those with ids by id,
426
+ * then those without as they run, then those without that failed.
427
+ */
424
428
  async list(options = {}) {
425
429
  const body = await callOf(this.#source, methods['jobs.list'], handle => JobsList.encode({ handle, ...options }), 'read');
426
430
  const page = JobsPage.decode(body);
@@ -555,7 +559,7 @@ export class StoreTxQueue {
555
559
  async set(id, value, options = {}) {
556
560
  this.#write('jobs.set', { ...jobFields(options), id }, value);
557
561
  }
558
- /** Changes the id's job when it has not started, with the commit. */
562
+ /** Changes the id's job when it is not running, its old value's steps dropped, with the commit. */
559
563
  async update(id, value, options = {}) {
560
564
  this.#write('jobs.update', { ...jobFields(options), id }, value);
561
565
  }
package/dist/locks.js CHANGED
@@ -52,6 +52,7 @@ export class Semaphore {
52
52
  if (!Number.isInteger(options.limit) || options.limit < 1 || options.limit > 1000) {
53
53
  throw new InvalidError(`semaphore ${name}: a limit of ${options.limit}, not 1 to 1000`);
54
54
  }
55
+ keepLimit(link, name, options.limit);
55
56
  this.name = name;
56
57
  this.limit = options.limit;
57
58
  this.#keys = new Keys(link, 'semaphore', name, options.limit, options);
@@ -63,6 +64,23 @@ export class Semaphore {
63
64
  return this.#keys.hold(key, fn, 0, permitOf);
64
65
  }
65
66
  }
67
+ // The limit each semaphore's first open gave, by the link of the store that
68
+ // opened it: one name keeps one limit in a program, and two stores are two
69
+ // programs, each of whose holds the store admits by its own limit.
70
+ const opened = new WeakMap();
71
+ /** Keeps the limit a semaphore's first open on this store gives: another limit is refused, naming both. */
72
+ function keepLimit(link, name, limit) {
73
+ let limits = opened.get(link);
74
+ if (limits === undefined) {
75
+ limits = new Map();
76
+ opened.set(link, limits);
77
+ }
78
+ const first = limits.get(name) ?? limit;
79
+ if (first !== limit) {
80
+ throw new InvalidError(`semaphore ${name}: open in this program with a limit of ${first}, not ${limit}`);
81
+ }
82
+ limits.set(name, first);
83
+ }
66
84
  function waitOf(options) {
67
85
  return ms(options?.wait ?? defaultWait);
68
86
  }
package/dist/query.js CHANGED
@@ -5,7 +5,7 @@
5
5
  var _a;
6
6
  import { CorruptError, InvalidError } from './errors.js';
7
7
  import { check } from './schema.js';
8
- import { cellOf, conditionOf, grouped, identOf, joinedWith, placeholders, Sql, } from './sql.js';
8
+ import { cellOf, checked, conditionOf, grouped, identOf, joinedWith, placeholders, Sql, } from './sql.js';
9
9
  /**
10
10
  * A query on a table: a value, each call returning a new one, so that the
11
11
  * first stays as it was. `all`, `one`, `scalar`, `count`, `each` and `list`
@@ -36,7 +36,7 @@ export class Query {
36
36
  }
37
37
  /** The columns a row holds, as SQL text, and the shape of the row they make. */
38
38
  select(columns) {
39
- const select = typeof columns === 'string' ? new Sql(columns, []) : columns;
39
+ const select = checked(typeof columns === 'string' ? new Sql(columns, []) : columns);
40
40
  return new _a(this.#source, { ...this.#parts, select });
41
41
  }
42
42
  /**
@@ -102,7 +102,7 @@ export class Query {
102
102
  throw new InvalidError(`an order is asc or desc, not ${JSON.stringify(direction)}`);
103
103
  }
104
104
  const order = column instanceof Sql
105
- ? { piece: column, direction }
105
+ ? { piece: checked(column), direction }
106
106
  : { piece: new Sql(identOf(column), []), column, direction };
107
107
  return this.#with({ order: [...this.#parts.order, order] });
108
108
  }
@@ -174,9 +174,14 @@ export class Query {
174
174
  if (order.length === 0 || order.some(each => each.column === undefined)) {
175
175
  throw new InvalidError('a page is read by the query order, of columns by their names: orderBy(…) first');
176
176
  }
177
+ // A page reads its limit's rows after its cursor: the query's own limit or
178
+ // offset would be dropped, and limit(100) page through every row.
179
+ if (this.#parts.limit !== undefined || this.#parts.offset !== undefined) {
180
+ throw new InvalidError('list after a limit or an offset: list pages the rows itself and takes its own limit');
181
+ }
177
182
  const limit = whole(options.limit ?? 100, 'a page limit');
178
- const digest = digestOf(render({ ...this.#parts, limit: undefined, offset: undefined }));
179
- let parts = { ...this.#parts, limit, offset: undefined };
183
+ const digest = digestOf(render(this.#parts));
184
+ let parts = { ...this.#parts, limit };
180
185
  if (options.after !== undefined) {
181
186
  const after = cursorOf(options.after, digest);
182
187
  parts = {
@@ -219,8 +224,9 @@ export class Query {
219
224
  for (const name of names) {
220
225
  const value = values[name];
221
226
  if (value instanceof Sql) {
222
- sets.push(`${identOf(name)} = ${value.text}`);
223
- out.push(...value.values);
227
+ const set = checked(value);
228
+ sets.push(`${identOf(name)} = ${set.text}`);
229
+ out.push(...set.values);
224
230
  }
225
231
  else {
226
232
  sets.push(`${identOf(name)} = ?`);
@@ -272,7 +278,7 @@ export class Query {
272
278
  return new _a(this.#source, { ...this.#parts, ...changed });
273
279
  }
274
280
  #joined(kind, table, on) {
275
- const condition = typeof on === 'string' ? new Sql(on, []) : on;
281
+ const condition = checked(typeof on === 'string' ? new Sql(on, []) : on);
276
282
  const ref = tableRef(table);
277
283
  const join = new Sql(`${kind} ${ref.text} on ${condition.text}`, condition.values);
278
284
  return this.#with({ joins: [...this.#parts.joins, join] });
@@ -286,6 +292,19 @@ export class Query {
286
292
  if (this.#parts.joins.length > 0) {
287
293
  throw new InvalidError(`${what} of a join: write it in SQL`);
288
294
  }
295
+ // SQLite's update and delete take none of these: limit(10).delete()
296
+ // would delete every row the conditions match.
297
+ const parts = this.#parts;
298
+ const shaped = parts.limit !== undefined ||
299
+ parts.offset !== undefined ||
300
+ parts.order.length > 0 ||
301
+ parts.groups.length > 0 ||
302
+ parts.having.length > 0 ||
303
+ parts.select !== undefined ||
304
+ parts.includes.length > 0;
305
+ if (shaped) {
306
+ throw new InvalidError(`${what} with a limit, offset, order, group, select or include: narrow it by conditions, or write it in SQL`);
307
+ }
289
308
  }
290
309
  }
291
310
  _a = Query;
@@ -338,7 +357,7 @@ export class Table extends Query {
338
357
  const values = [...insert.values];
339
358
  if (options.where !== undefined) {
340
359
  // in an upsert's update, a column is the row's that holds the key
341
- const where = conditionOf(options.where);
360
+ const where = checked(conditionOf(options.where));
342
361
  text += ` where ${where.text}`;
343
362
  values.push(...where.values);
344
363
  }
@@ -605,18 +624,15 @@ function kept(condition, values) {
605
624
  if (counted.positional !== values.length || counted.named.length > 0 || counted.numbered) {
606
625
  throw new InvalidError(`${counted.positional} placeholders and ${values.length} values: each ? takes one value`);
607
626
  }
608
- return [
609
- {
610
- piece: new Sql(condition, values.map((value, at) => cellOf(value, `value ${at + 1}`))),
611
- bare: false,
612
- },
613
- ];
627
+ const piece = new Sql(condition, values.map((value, at) => cellOf(value, `value ${at + 1}`)));
628
+ return [{ piece: checked(piece), bare: false }];
614
629
  }
615
630
  if (values.length > 0) {
616
631
  throw new InvalidError('a condition that is not text carries its values: pass it alone');
617
632
  }
618
633
  if (condition instanceof Sql) {
619
- return [{ piece: condition, bare: condition.bare || grouped(condition.text) }];
634
+ const piece = checked(condition);
635
+ return [{ piece, bare: piece.bare || grouped(piece.text) }];
620
636
  }
621
637
  return Object.keys(condition)
622
638
  .sort()
package/dist/search.d.ts CHANGED
@@ -62,6 +62,13 @@ export interface Query {
62
62
  vectorWeight?: number | undefined;
63
63
  rerank?: boolean | undefined;
64
64
  } | undefined;
65
+ /**
66
+ * the least cosine, from -1 to 1, a document's vector has with the
67
+ * search's for the vector to find it: a search by its vector alone leaves
68
+ * out the hits under it, and one by words too adds nothing for them to
69
+ * the sum; invalid beside a rerank
70
+ */
71
+ minSimilarity?: number | undefined;
65
72
  /**
66
73
  * the last word read as the start of a word too, as a search box types:
67
74
  * `crypt` finds `cryptography` as well, at half its field's weight; a
@@ -103,6 +110,10 @@ export interface Hit<T> {
103
110
  score: number;
104
111
  /** where the search's words matched it, when the search asked with `matches` */
105
112
  matches?: Match[];
113
+ /** the score its words gave it, as a search by its words alone scores it, where they found it among their best */
114
+ textScore?: number;
115
+ /** the cosine of its vector with the search's, from -1 to 1, where both have one */
116
+ similarity?: number;
106
117
  }
107
118
  /** What a search found, the best first, and the text it read in fact when a word was misspelt. */
108
119
  export interface Found<T> {
package/dist/search.js CHANGED
@@ -48,6 +48,7 @@ class Searchable {
48
48
  vector,
49
49
  vectorWeight: asked.hybrid?.vectorWeight,
50
50
  rerank: asked.hybrid?.rerank,
51
+ minSimilarity: asked.minSimilarity,
51
52
  prefix: asked.prefix === true || undefined,
52
53
  // none unless asked, so that a server before it reads the search
53
54
  prefixEvery: asked.prefix === 'every' || undefined,
@@ -67,6 +68,12 @@ class Searchable {
67
68
  if (hit.matches !== undefined) {
68
69
  read.matches = hit.matches.map(matchOf);
69
70
  }
71
+ if (hit.textScore !== undefined) {
72
+ read.textScore = hit.textScore;
73
+ }
74
+ if (hit.similarity !== undefined) {
75
+ read.similarity = hit.similarity;
76
+ }
70
77
  return read;
71
78
  });
72
79
  return found.corrected === undefined ? { hits } : { hits, corrected: found.corrected };
package/dist/sql.d.ts CHANGED
@@ -74,6 +74,13 @@ export declare function joinedWith(pieces: readonly Sql[], joiner: string): Sql;
74
74
  * and parentheses, which would bind with its neighbours'.
75
75
  */
76
76
  export declare function standsAlone(text: string): boolean;
77
+ /**
78
+ * A piece as a query takes it. What the query writes after a piece, an and,
79
+ * a ), a desc or a where, must stay SQL: a piece that ends inside a --
80
+ * comment gets the newline that ends it, and one that ends inside a block
81
+ * comment, which only its closing mark ends, is refused.
82
+ */
83
+ export declare function checked(piece: Sql): Sql;
77
84
  /** Something that writes itself as SQL inside another piece: a table's query. */
78
85
  export interface Embeddable {
79
86
  /** its text and values, wrapped as a subquery is */
package/dist/sql.js CHANGED
@@ -40,17 +40,36 @@ export function grouped(text) {
40
40
  if (!text.startsWith('(') || !text.endsWith(')')) {
41
41
  return /^[01]$/.test(text);
42
42
  }
43
+ // A parenthesis inside quotes or a comment counts for nothing: ('(') or ('x') is two groups, not one.
43
44
  let depth = 0;
44
45
  for (let at = 0; at < text.length; at++) {
45
- if (text[at] === '(')
46
+ const c = text[at];
47
+ if (c === "'" || c === '"' || c === '`') {
48
+ at = closing(text, at, c);
49
+ continue;
50
+ }
51
+ if (c === '-' && text[at + 1] === '-') {
52
+ at = text.indexOf('\n', at);
53
+ if (at < 0)
54
+ break;
55
+ continue;
56
+ }
57
+ if (c === '/' && text[at + 1] === '*') {
58
+ at = text.indexOf('*/', at + 2);
59
+ if (at < 0)
60
+ break;
61
+ at++;
62
+ continue;
63
+ }
64
+ if (c === '(')
46
65
  depth++;
47
- if (text[at] === ')')
66
+ if (c === ')')
48
67
  depth--;
49
68
  if (depth === 0 && at < text.length - 1) {
50
69
  return false;
51
70
  }
52
71
  }
53
- return true;
72
+ return depth === 0;
54
73
  }
55
74
  /** Pieces joined with and or or, each in parentheses unless it may stand as it is. */
56
75
  export function joinedWith(pieces, joiner) {
@@ -101,6 +120,54 @@ export function standsAlone(text) {
101
120
  }
102
121
  return true;
103
122
  }
123
+ /**
124
+ * A piece as a query takes it. What the query writes after a piece, an and,
125
+ * a ), a desc or a where, must stay SQL: a piece that ends inside a --
126
+ * comment gets the newline that ends it, and one that ends inside a block
127
+ * comment, which only its closing mark ends, is refused.
128
+ */
129
+ export function checked(piece) {
130
+ switch (commentAtEnd(piece.text)) {
131
+ case 'line':
132
+ return new Sql(`${piece.text}\n`, piece.values, piece.bare);
133
+ case 'block':
134
+ throw new InvalidError(`a piece of SQL ends inside a /* comment, which would hide what the query writes after it: ${piece.text}`);
135
+ }
136
+ return piece;
137
+ }
138
+ /** Text written into another piece, a -- comment at its end ended by a newline. */
139
+ function ended(text) {
140
+ return commentAtEnd(text) === 'line' ? `${text}\n` : text;
141
+ }
142
+ /**
143
+ * The comment text ends inside, outside quotes and brackets, if it ends
144
+ * inside one: `a = 1 -- why` ends inside a line comment.
145
+ */
146
+ function commentAtEnd(text) {
147
+ for (let at = 0; at < text.length; at++) {
148
+ const c = text[at];
149
+ if (c === "'" || c === '"' || c === '`') {
150
+ at = closing(text, at, c);
151
+ }
152
+ else if (c === '[') {
153
+ at = text.indexOf(']', at + 1);
154
+ if (at < 0)
155
+ return undefined;
156
+ }
157
+ else if (c === '-' && text[at + 1] === '-') {
158
+ at = text.indexOf('\n', at);
159
+ if (at < 0)
160
+ return 'line';
161
+ }
162
+ else if (c === '/' && text[at + 1] === '*') {
163
+ at = text.indexOf('*/', at + 2);
164
+ if (at < 0)
165
+ return 'block';
166
+ at++;
167
+ }
168
+ }
169
+ return undefined;
170
+ }
104
171
  function isEmbeddable(value) {
105
172
  return (typeof value === 'object' &&
106
173
  value !== null &&
@@ -122,7 +189,7 @@ function piece(first, values) {
122
189
  const out = [];
123
190
  values.forEach((value, at) => {
124
191
  if (value instanceof Sql) {
125
- text += value.text;
192
+ text += ended(value.text);
126
193
  out.push(...value.values);
127
194
  }
128
195
  else if (isEmbeddable(value)) {
@@ -162,7 +229,7 @@ function listed(value) {
162
229
  return value;
163
230
  }
164
231
  function group(conditions, joiner, empty) {
165
- const pieces = conditions.map(conditionOf);
232
+ const pieces = conditions.map(condition => checked(conditionOf(condition)));
166
233
  if (pieces.length === 0) {
167
234
  return new Sql(empty, []);
168
235
  }
@@ -278,7 +345,7 @@ export function placeholders(text) {
278
345
  }
279
346
  return { positional, named, numbered };
280
347
  }
281
- /** The index past a quoted run that starts at `at`, a doubled quote inside it kept. */
348
+ /** The index of the quote that ends a quoted run starting at `at`, a doubled quote inside it kept. */
282
349
  function closing(text, at, quote) {
283
350
  for (let next = at + 1; next < text.length; next++) {
284
351
  if (text[next] === quote) {
@@ -701,8 +701,9 @@ export declare const JobsJob: import("./codec.ts").Message<{
701
701
  }>;
702
702
  /**
703
703
  * A page of a queue's jobs: those whose ids start with a prefix, in the byte
704
- * order of their ids, or with no prefix and the failed state, the last failed
705
- * first.
704
+ * order of their ids; with no prefix every job, those with ids first, then
705
+ * those without as they run, then those without that failed, the last failed
706
+ * first; with no prefix and the failed state the failed alone, the last first.
706
707
  */
707
708
  export declare const JobsList: import("./codec.ts").Message<{
708
709
  readonly handle: readonly [1, import("./codec.ts").Codec<number, number>];
@@ -2495,6 +2496,8 @@ export declare const SearchQuery: import("./codec.ts").Message<{
2495
2496
  readonly prefixEvery: readonly [10, import("./codec.ts").Codec<boolean, boolean>];
2496
2497
  /** utf8, utf16 or chars: each hit says where it matched, counted in that unit */
2497
2498
  readonly matches: readonly [11, import("./codec.ts").Codec<string, string>];
2499
+ /** the least cosine a document's vector has for the vector to find it */
2500
+ readonly minSimilarity: readonly [12, import("./codec.ts").Codec<number, number>];
2498
2501
  }>;
2499
2502
  /**
2500
2503
  * Where a search's word matched a hit: a range of a field's text, or of a
@@ -2901,8 +2904,8 @@ export declare const SearchSetMany: import("./codec.ts").Message<{
2901
2904
  }>;
2902
2905
  /**
2903
2906
  * A hit: a document and its value, or a table's row, a value a column of
2904
- * the answer's columns, as sql.Rows holds one, and where the search's words
2905
- * matched it when the query asked.
2907
+ * the answer's columns, as sql.Rows holds one, where the search's words
2908
+ * matched it when the query asked, and what each half of the search gave it.
2906
2909
  */
2907
2910
  export declare const SearchHit: import("./codec.ts").Message<{
2908
2911
  readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
@@ -2929,6 +2932,10 @@ export declare const SearchHit: import("./codec.ts").Message<{
2929
2932
  /** the query's word, as its text wrote it */
2930
2933
  readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
2931
2934
  }>[]>];
2935
+ /** its words' score, where they found it among their best */
2936
+ readonly textScore: readonly [6, import("./codec.ts").Codec<number, number>];
2937
+ /** its vector's cosine with the search's, where both have one */
2938
+ readonly similarity: readonly [7, import("./codec.ts").Codec<number, number>];
2932
2939
  }>;
2933
2940
  export declare const SearchFound: import("./codec.ts").Message<{
2934
2941
  readonly hits: readonly [1, import("./codec.ts").Codec<Read<{
@@ -2956,6 +2963,10 @@ export declare const SearchFound: import("./codec.ts").Message<{
2956
2963
  /** the query's word, as its text wrote it */
2957
2964
  readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
2958
2965
  }>[]>];
2966
+ /** its words' score, where they found it among their best */
2967
+ readonly textScore: readonly [6, import("./codec.ts").Codec<number, number>];
2968
+ /** its vector's cosine with the search's, where both have one */
2969
+ readonly similarity: readonly [7, import("./codec.ts").Codec<number, number>];
2959
2970
  }>[], readonly import("./codec.ts").Written<{
2960
2971
  readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
2961
2972
  /** null for a table's row */
@@ -2981,6 +2992,10 @@ export declare const SearchFound: import("./codec.ts").Message<{
2981
2992
  /** the query's word, as its text wrote it */
2982
2993
  readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
2983
2994
  }>[]>];
2995
+ /** its words' score, where they found it among their best */
2996
+ readonly textScore: readonly [6, import("./codec.ts").Codec<number, number>];
2997
+ /** its vector's cosine with the search's, where both have one */
2998
+ readonly similarity: readonly [7, import("./codec.ts").Codec<number, number>];
2984
2999
  }>[]>];
2985
3000
  /** the text the search read in fact, when a word was read as another */
2986
3001
  readonly corrected: readonly [2, import("./codec.ts").Codec<string, string>];