@tinyshed/tinystore 0.4.1 → 0.5.1
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/errors.d.ts +79 -20
- package/dist/errors.js +75 -20
- package/dist/index.d.ts +1 -1
- package/dist/kv.d.ts +15 -0
- package/dist/kv.js +149 -91
- package/dist/runtime/addon.js +51 -41
- package/dist/runtime/pipe.js +116 -87
- package/dist/search.d.ts +43 -3
- package/dist/search.js +38 -8
- package/dist/session.js +13 -3
- package/dist/wire/protocol.d.ts +110 -28
- package/dist/wire/protocol.js +247 -103
- package/package.json +8 -8
- package/src/errors.ts +83 -21
- package/src/index.ts +2 -0
- package/src/kv.ts +167 -99
- package/src/runtime/addon.ts +52 -41
- package/src/runtime/pipe.ts +136 -104
- package/src/search.ts +88 -11
- package/src/session.ts +18 -2
- package/src/wire/protocol.ts +258 -109
package/dist/runtime/pipe.js
CHANGED
|
@@ -40,119 +40,148 @@ const room = 1 << 16;
|
|
|
40
40
|
*/
|
|
41
41
|
export function openPipe(library, dir, options, events) {
|
|
42
42
|
const lib = dlopen(library, symbols);
|
|
43
|
+
const pipe = new CorePipe(lib, new Inbox(events));
|
|
44
|
+
const wake = new JSCallback(() => pipe.readOn(undefined), {
|
|
45
|
+
args: [FFIType.ptr],
|
|
46
|
+
returns: FFIType.void,
|
|
47
|
+
threadsafe: true,
|
|
48
|
+
});
|
|
49
|
+
pipe.connection = connect(lib, dir, options, wake);
|
|
50
|
+
// Bun's loop with no timer armed spins while it waits for a threadsafe
|
|
51
|
+
// callback from another thread: a write waiting for its sync burned a
|
|
52
|
+
// whole processor (research release-2026-10-23). A timer armed, however
|
|
53
|
+
// far off, lets the loop sleep until the core wakes it; it also keeps the
|
|
54
|
+
// process alive while the store is open, as a sidecar's socket does.
|
|
55
|
+
const sleeps = setInterval(() => { }, 2 ** 30);
|
|
56
|
+
return {
|
|
57
|
+
write: turning(bytes => pipe.send(bytes)),
|
|
58
|
+
close() {
|
|
59
|
+
const closing = pipe.connection;
|
|
60
|
+
if (closing === null) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
pipe.connection = null;
|
|
64
|
+
clearInterval(sleeps);
|
|
65
|
+
lib.symbols.tinystore_close(closing);
|
|
66
|
+
wake.close();
|
|
67
|
+
events.end(new ClosedError('the store closed'));
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Opens the store through the core; a store that does not open lets the core and the wake go. */
|
|
72
|
+
function connect(lib, dir, options, wake) {
|
|
43
73
|
const name = new TextEncoder().encode(dir);
|
|
44
74
|
const opened = new BigUint64Array(1);
|
|
45
75
|
const failure = new Uint8Array(1024);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
const failed = Number(lib.symbols.tinystore_open(ptr(name), name.length, ptr(options), options.length, wake, null, ptr(opened), ptr(failure), failure.length));
|
|
77
|
+
if (failed > 0) {
|
|
78
|
+
const message = new TextDecoder().decode(failure.subarray(0, failed));
|
|
79
|
+
wake.close();
|
|
80
|
+
lib.close();
|
|
81
|
+
throw openFailure(dir, message);
|
|
82
|
+
}
|
|
83
|
+
return Number(opened[0]);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Where the core writes what it owes: whole frames are read from the front,
|
|
87
|
+
* and a frame's first part is held there for its rest.
|
|
88
|
+
*/
|
|
89
|
+
class Inbox {
|
|
90
|
+
#events;
|
|
91
|
+
#inbox = new Uint8Array(room);
|
|
92
|
+
#held = 0;
|
|
51
93
|
// A frame longer than the inbox, in bytes as long as it is, and how much
|
|
52
94
|
// of it came: the core writes its rest there, and the session keeps them,
|
|
53
95
|
// so that a file's mebibyte is written once here rather than copied out
|
|
54
96
|
// of an inbox grown for it (issue #10).
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
97
|
+
#large;
|
|
98
|
+
#filledLarge = 0;
|
|
99
|
+
constructor(events) {
|
|
100
|
+
this.#events = events;
|
|
101
|
+
}
|
|
102
|
+
/** Where the core writes next, and how many bytes it may. */
|
|
103
|
+
into() {
|
|
104
|
+
return this.#large === undefined
|
|
105
|
+
? [this.#inbox, this.#held, this.#inbox.length - this.#held]
|
|
106
|
+
: [this.#large, this.#filledLarge, this.#large.length - this.#filledLarge];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reads what the core wrote where `into` said, and says whether it filled
|
|
110
|
+
* that room, which means more may wait.
|
|
111
|
+
*/
|
|
112
|
+
read(written) {
|
|
113
|
+
if (this.#large !== undefined) {
|
|
114
|
+
this.#filledLarge += written;
|
|
115
|
+
if (this.#filledLarge < this.#large.length) {
|
|
67
116
|
return false;
|
|
68
117
|
}
|
|
69
|
-
const whole = large;
|
|
70
|
-
large = undefined;
|
|
71
|
-
events.frame(whole);
|
|
118
|
+
const whole = this.#large;
|
|
119
|
+
this.#large = undefined;
|
|
120
|
+
this.#events.frame(whole);
|
|
72
121
|
return true;
|
|
73
122
|
}
|
|
74
|
-
const length = held + written;
|
|
75
|
-
const filled = length === inbox.length;
|
|
76
|
-
const taken = written === 0 ? 0 : events.frames(inbox, length);
|
|
77
|
-
inbox.copyWithin(0, taken, length);
|
|
78
|
-
held = length - taken;
|
|
79
|
-
const frameLength = held < headerSize ? 0 : headerSize + bodyLength(inbox);
|
|
80
|
-
if (frameLength > inbox.length) {
|
|
81
|
-
large = new Uint8Array(frameLength);
|
|
82
|
-
large.set(inbox.subarray(0, held));
|
|
83
|
-
filledLarge = held;
|
|
84
|
-
held = 0;
|
|
123
|
+
const length = this.#held + written;
|
|
124
|
+
const filled = length === this.#inbox.length;
|
|
125
|
+
const taken = written === 0 ? 0 : this.#events.frames(this.#inbox, length);
|
|
126
|
+
this.#inbox.copyWithin(0, taken, length);
|
|
127
|
+
this.#held = length - taken;
|
|
128
|
+
const frameLength = this.#held < headerSize ? 0 : headerSize + bodyLength(this.#inbox);
|
|
129
|
+
if (frameLength > this.#inbox.length) {
|
|
130
|
+
this.#large = new Uint8Array(frameLength);
|
|
131
|
+
this.#large.set(this.#inbox.subarray(0, this.#held));
|
|
132
|
+
this.#filledLarge = this.#held;
|
|
133
|
+
this.#held = 0;
|
|
85
134
|
}
|
|
86
135
|
return filled;
|
|
87
|
-
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** One connection's calls into the core, which write what it owes into the inbox. */
|
|
139
|
+
class CorePipe {
|
|
140
|
+
connection = null;
|
|
141
|
+
#lib;
|
|
142
|
+
#inbox;
|
|
88
143
|
// What the session writes while it reads: its frames wait for the read's
|
|
89
144
|
// end, since a call of the core made meanwhile would write over the bytes
|
|
90
145
|
// being read.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
146
|
+
#reading = false;
|
|
147
|
+
#waiting = [];
|
|
148
|
+
constructor(lib, inbox) {
|
|
149
|
+
this.#lib = lib;
|
|
150
|
+
this.#inbox = inbox;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Reads what a call of the core wrote, and on while the core fills the
|
|
154
|
+
* room, since no wake comes for what waits; then sends what was written
|
|
155
|
+
* meanwhile.
|
|
156
|
+
*/
|
|
157
|
+
readOn(written) {
|
|
158
|
+
this.#reading = true;
|
|
98
159
|
try {
|
|
99
|
-
let filled = written === undefined || read(written);
|
|
100
|
-
while (filled && connection !== null) {
|
|
101
|
-
const [bytes, at, free] = into();
|
|
102
|
-
|
|
160
|
+
let filled = written === undefined || this.#inbox.read(written);
|
|
161
|
+
while (filled && this.connection !== null) {
|
|
162
|
+
const [bytes, at, free] = this.#inbox.into();
|
|
163
|
+
const read = this.#lib.symbols.tinystore_recv(this.connection, 0, ptr(bytes, at), free);
|
|
164
|
+
filled = this.#inbox.read(Number(read));
|
|
103
165
|
}
|
|
104
166
|
}
|
|
105
167
|
finally {
|
|
106
|
-
reading = false;
|
|
168
|
+
this.#reading = false;
|
|
107
169
|
}
|
|
108
|
-
const next = waiting.shift();
|
|
170
|
+
const next = this.#waiting.shift();
|
|
109
171
|
if (next !== undefined) {
|
|
110
|
-
send(next);
|
|
172
|
+
this.send(next);
|
|
111
173
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (connection === null) {
|
|
174
|
+
}
|
|
175
|
+
send(bytes) {
|
|
176
|
+
if (this.connection === null) {
|
|
115
177
|
return;
|
|
116
178
|
}
|
|
117
|
-
if (reading) {
|
|
118
|
-
waiting.push(bytes);
|
|
179
|
+
if (this.#reading) {
|
|
180
|
+
this.#waiting.push(bytes);
|
|
119
181
|
return;
|
|
120
182
|
}
|
|
121
|
-
const [owed, at, free] = into();
|
|
122
|
-
const written = lib.symbols.tinystore_send(connection, ptr(bytes), bytes.length, ptr(owed, at), free);
|
|
123
|
-
readOn(Number(written));
|
|
124
|
-
};
|
|
125
|
-
const wake = new JSCallback(() => readOn(undefined), {
|
|
126
|
-
args: [FFIType.ptr],
|
|
127
|
-
returns: FFIType.void,
|
|
128
|
-
threadsafe: true,
|
|
129
|
-
});
|
|
130
|
-
const failed = Number(lib.symbols.tinystore_open(ptr(name), name.length, ptr(options), options.length, wake, null, ptr(opened), ptr(failure), failure.length));
|
|
131
|
-
if (failed > 0) {
|
|
132
|
-
const message = new TextDecoder().decode(failure.subarray(0, failed));
|
|
133
|
-
wake.close();
|
|
134
|
-
lib.close();
|
|
135
|
-
throw openFailure(dir, message);
|
|
183
|
+
const [owed, at, free] = this.#inbox.into();
|
|
184
|
+
const written = this.#lib.symbols.tinystore_send(this.connection, ptr(bytes), bytes.length, ptr(owed, at), free);
|
|
185
|
+
this.readOn(Number(written));
|
|
136
186
|
}
|
|
137
|
-
connection = Number(opened[0]);
|
|
138
|
-
// Bun's loop with no timer armed spins while it waits for a threadsafe
|
|
139
|
-
// callback from another thread: a write waiting for its sync burned a
|
|
140
|
-
// whole processor (research release-2026-10-23). A timer armed, however
|
|
141
|
-
// far off, lets the loop sleep until the core wakes it; it also keeps the
|
|
142
|
-
// process alive while the store is open, as a sidecar's socket does.
|
|
143
|
-
const sleeps = setInterval(() => { }, 2 ** 30);
|
|
144
|
-
return {
|
|
145
|
-
write: turning(send),
|
|
146
|
-
close() {
|
|
147
|
-
if (connection === null) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const closing = connection;
|
|
151
|
-
connection = null;
|
|
152
|
-
clearInterval(sleeps);
|
|
153
|
-
lib.symbols.tinystore_close(closing);
|
|
154
|
-
wake.close();
|
|
155
|
-
events.end(new ClosedError('the store closed'));
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
187
|
}
|
package/dist/search.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export interface IndexOptions {
|
|
|
9
9
|
filters?: readonly string[] | undefined;
|
|
10
10
|
/** a misspelt word read as the index's nearest; on unless false */
|
|
11
11
|
typoTolerance?: boolean | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* the keyboard layouts the index's readers type with, `['ru', 'en']`: a
|
|
14
|
+
* word that finds nothing as typed is read as the same keys type in the
|
|
15
|
+
* other layout, when it finds something there, and `corrected` says so
|
|
16
|
+
*/
|
|
17
|
+
layouts?: readonly KeyboardLayout[] | undefined;
|
|
12
18
|
/** a vector the program's model gives each document, and `recall` for searches from clusters */
|
|
13
19
|
vectors?: {
|
|
14
20
|
dimensions: number;
|
|
@@ -22,6 +28,8 @@ export interface IndexOptions {
|
|
|
22
28
|
/** whether a change that needs every document read again waits for `store.reindex` */
|
|
23
29
|
rebuild?: 'automatic' | 'manual' | undefined;
|
|
24
30
|
}
|
|
31
|
+
/** A keyboard layout an index's readers type with: ЙЦУКЕН, or QWERTY. */
|
|
32
|
+
export type KeyboardLayout = 'ru' | 'en';
|
|
25
33
|
/** A vector the program's own model gave, of the index's dimensions. */
|
|
26
34
|
export type Vector = readonly number[] | Float32Array;
|
|
27
35
|
/** A value a `where` matches: text, a number, a boolean, one of a list, a range, or `null` for none. */
|
|
@@ -57,18 +65,44 @@ export interface Query {
|
|
|
57
65
|
/**
|
|
58
66
|
* the last word read as the start of a word too, as a search box types:
|
|
59
67
|
* `crypt` finds `cryptography` as well, at half its field's weight; a
|
|
60
|
-
* word a space follows is whole, and so is one of a single letter
|
|
68
|
+
* word a space follows is whole, and so is one of a single letter. With
|
|
69
|
+
* `'every'`, every word of two letters or more is read so, the first
|
|
70
|
+
* eight, as people shorten each word of a name: `лин алг` finds
|
|
71
|
+
* `Линейная алгебра`; a document that holds a word for each word of the
|
|
72
|
+
* text comes first, its score raised above the rest
|
|
61
73
|
*/
|
|
62
|
-
prefix?: boolean | undefined;
|
|
74
|
+
prefix?: boolean | 'every' | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* each hit says where the search's words matched it, in `matches`, as a
|
|
77
|
+
* search box shows them in bold: a word found as written, by its stem or
|
|
78
|
+
* once corrected whole, and a word a prefix began by the letters typed
|
|
79
|
+
*/
|
|
80
|
+
matches?: boolean | undefined;
|
|
63
81
|
/** 10 unless said; offset and limit together 1000 at most */
|
|
64
82
|
limit?: number | undefined;
|
|
65
83
|
offset?: number | undefined;
|
|
66
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Where a search's word matched a hit: `start` to `end` of a field's text in
|
|
87
|
+
* UTF-16 units, so that `text.slice(start, end)` is what matched.
|
|
88
|
+
*/
|
|
89
|
+
export interface Match {
|
|
90
|
+
/** the field's path, or a table's column; `''` for a document that is its own text */
|
|
91
|
+
field: string;
|
|
92
|
+
/** the string's place in a field that holds a list */
|
|
93
|
+
item?: number;
|
|
94
|
+
start: number;
|
|
95
|
+
end: number;
|
|
96
|
+
/** the query's word, as its text wrote it */
|
|
97
|
+
word: string;
|
|
98
|
+
}
|
|
67
99
|
/** A document a search found, and the score that ordered it among this search's hits. */
|
|
68
100
|
export interface Hit<T> {
|
|
69
101
|
id: string;
|
|
70
102
|
value: T;
|
|
71
103
|
score: number;
|
|
104
|
+
/** where the search's words matched it, when the search asked with `matches` */
|
|
105
|
+
matches?: Match[];
|
|
72
106
|
}
|
|
73
107
|
/** What a search found, the best first, and the text it read in fact when a word was misspelt. */
|
|
74
108
|
export interface Found<T> {
|
|
@@ -108,6 +142,7 @@ export interface TableIndexOptions {
|
|
|
108
142
|
/** the columns a search may keep its hits to; a boolean is the 1 or 0 SQLite keeps */
|
|
109
143
|
filters?: readonly string[] | undefined;
|
|
110
144
|
typoTolerance?: boolean | undefined;
|
|
145
|
+
layouts?: readonly KeyboardLayout[] | undefined;
|
|
111
146
|
/** a column of blobs of little-endian floats, one a row or null, and `recall` for searches from clusters */
|
|
112
147
|
vectors?: {
|
|
113
148
|
column: string;
|
|
@@ -158,7 +193,12 @@ export declare class SearchIndex<T> extends Searchable<T> {
|
|
|
158
193
|
set(id: Key, value: T, options?: {
|
|
159
194
|
vector?: Vector | null | undefined;
|
|
160
195
|
}): Promise<void>;
|
|
161
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* Sets every document in one commit, all of them or none: 1,000 at most,
|
|
198
|
+
* `limits.setManyDocuments`, and no more than one request body holds,
|
|
199
|
+
* 2 MiB, `limits.requestBytes`. Past either it fails with a LimitError
|
|
200
|
+
* that names the bound.
|
|
201
|
+
*/
|
|
162
202
|
setMany(documents: readonly IndexDocument<T>[]): Promise<void>;
|
|
163
203
|
/** Deletes the document `id`; says whether there was one. */
|
|
164
204
|
delete(id: Key): Promise<boolean>;
|
package/dist/search.js
CHANGED
|
@@ -48,20 +48,27 @@ class Searchable {
|
|
|
48
48
|
vector,
|
|
49
49
|
vectorWeight: asked.hybrid?.vectorWeight,
|
|
50
50
|
rerank: asked.hybrid?.rerank,
|
|
51
|
-
prefix: asked.prefix,
|
|
51
|
+
prefix: asked.prefix === true || undefined,
|
|
52
|
+
// none unless asked, so that a server before it reads the search
|
|
53
|
+
prefixEvery: asked.prefix === 'every' || undefined,
|
|
54
|
+
// JavaScript slices a string by its UTF-16 units
|
|
55
|
+
matches: asked.matches === true ? 'utf16' : undefined,
|
|
52
56
|
where,
|
|
53
57
|
offset: asked.offset,
|
|
54
58
|
limit: asked.limit,
|
|
55
59
|
});
|
|
56
60
|
const found = SearchFound.decode(await this.call('search.search', body, 'read'));
|
|
57
61
|
const columns = found.columns;
|
|
58
|
-
const hits = (found.hits ?? []).map(hit =>
|
|
59
|
-
|
|
60
|
-
value: (columns === undefined
|
|
62
|
+
const hits = (found.hits ?? []).map(hit => {
|
|
63
|
+
const value = (columns === undefined
|
|
61
64
|
? parseJson(hit.value ?? 'null')
|
|
62
|
-
: rowsOf(columns, [(hit.row ?? [])])[0])
|
|
63
|
-
score: hit.score ?? 0
|
|
64
|
-
|
|
65
|
+
: rowsOf(columns, [(hit.row ?? [])])[0]);
|
|
66
|
+
const read = { id: hit.id ?? '', value, score: hit.score ?? 0 };
|
|
67
|
+
if (hit.matches !== undefined) {
|
|
68
|
+
read.matches = hit.matches.map(matchOf);
|
|
69
|
+
}
|
|
70
|
+
return read;
|
|
71
|
+
});
|
|
65
72
|
return found.corrected === undefined ? { hits } : { hits, corrected: found.corrected };
|
|
66
73
|
}
|
|
67
74
|
/** Where the index stands; a search never waits, and answers by the settings it serves. */
|
|
@@ -102,7 +109,12 @@ export class SearchIndex extends Searchable {
|
|
|
102
109
|
const json = documentJson(this.name, value);
|
|
103
110
|
await this.call('search.set', handle => SearchSet.encode({ handle, id: keyText(id), value: json, ...said }), 'write');
|
|
104
111
|
}
|
|
105
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Sets every document in one commit, all of them or none: 1,000 at most,
|
|
114
|
+
* `limits.setManyDocuments`, and no more than one request body holds,
|
|
115
|
+
* 2 MiB, `limits.requestBytes`. Past either it fails with a LimitError
|
|
116
|
+
* that names the bound.
|
|
117
|
+
*/
|
|
106
118
|
async setMany(documents) {
|
|
107
119
|
const encoded = documents.map(document => ({
|
|
108
120
|
id: keyText(document.id),
|
|
@@ -139,6 +151,7 @@ export function tableIndexOpen(name, options, database, reindex = false) {
|
|
|
139
151
|
fields: fieldsOf(options.fields),
|
|
140
152
|
filters: [...(options.filters ?? [])],
|
|
141
153
|
typoTolerance: options.typoTolerance,
|
|
154
|
+
layouts: layoutsOf(options.layouts),
|
|
142
155
|
dimensions: options.vectors?.dimensions,
|
|
143
156
|
recall: options.vectors?.recall,
|
|
144
157
|
vectorWeight: options.hybrid?.vectorWeight,
|
|
@@ -156,6 +169,10 @@ function fieldsOf(fields) {
|
|
|
156
169
|
? fields.map(path => ({ path, weight: 1 }))
|
|
157
170
|
: Object.entries(fields ?? {}).map(([path, weight]) => ({ path, weight }));
|
|
158
171
|
}
|
|
172
|
+
/** The layouts asked for; none left out, so that a server before them reads the open. */
|
|
173
|
+
function layoutsOf(layouts) {
|
|
174
|
+
return layouts?.length ? [...layouts] : undefined;
|
|
175
|
+
}
|
|
159
176
|
/** The open of an index: its name, settings, and whether it reads the index again. */
|
|
160
177
|
export function indexOpen(name, options = {}, reindex = false) {
|
|
161
178
|
checkName(name, 'index');
|
|
@@ -164,6 +181,7 @@ export function indexOpen(name, options = {}, reindex = false) {
|
|
|
164
181
|
fields: fieldsOf(options.fields),
|
|
165
182
|
filters: [...(options.filters ?? [])],
|
|
166
183
|
typoTolerance: options.typoTolerance,
|
|
184
|
+
layouts: layoutsOf(options.layouts),
|
|
167
185
|
dimensions: options.vectors?.dimensions,
|
|
168
186
|
recall: options.vectors?.recall,
|
|
169
187
|
vectorWeight: options.hybrid?.vectorWeight,
|
|
@@ -204,6 +222,18 @@ function statusOf(status) {
|
|
|
204
222
|
return { state: 'ready' };
|
|
205
223
|
}
|
|
206
224
|
}
|
|
225
|
+
function matchOf(found) {
|
|
226
|
+
const match = {
|
|
227
|
+
field: found.field ?? '',
|
|
228
|
+
start: found.start ?? 0,
|
|
229
|
+
end: found.end ?? 0,
|
|
230
|
+
word: found.word ?? '',
|
|
231
|
+
};
|
|
232
|
+
if (found.item !== undefined) {
|
|
233
|
+
match.item = found.item;
|
|
234
|
+
}
|
|
235
|
+
return match;
|
|
236
|
+
}
|
|
207
237
|
function documentJson(name, value) {
|
|
208
238
|
const json = JSON.stringify(value);
|
|
209
239
|
if (json === undefined) {
|
package/dist/session.js
CHANGED
|
@@ -5,11 +5,17 @@
|
|
|
5
5
|
// socket, a Windows pipe, a child's stdio and TLS.
|
|
6
6
|
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
7
7
|
import { checkSignal, currentSignal, unlessCancelled } from './cancel.js';
|
|
8
|
-
import { CancelledError, ClosedError, errorOf, LimitError, ProtocolError, UnavailableError, } from './errors.js';
|
|
8
|
+
import { CancelledError, ClosedError, errorOf, LimitError, limits, ProtocolError, UnavailableError, } from './errors.js';
|
|
9
9
|
import { bodyLength, checkHeader, credit, Flag, frame, granted, headerSize, Kind, kindName, parseHeader, putHeader, } from './wire/frame.js';
|
|
10
10
|
import { Reader, Writer } from './wire/msgpack.js';
|
|
11
|
-
import { Failure, GoAway, Hello, Welcome } from './wire/protocol.js';
|
|
11
|
+
import { Failure, GoAway, Hello, methods, Welcome } from './wire/protocol.js';
|
|
12
12
|
export const protocol = 1;
|
|
13
|
+
/** Each method's name by its number, as the schema spells it: `search.setMany`. */
|
|
14
|
+
const methodNames = new Map(Object.entries(methods).map(([name, number]) => [number, name]));
|
|
15
|
+
/** A method's name as the schema spells it, for an error the SDK says itself. */
|
|
16
|
+
function methodName(method) {
|
|
17
|
+
return methodNames.get(method) ?? `method ${method}`;
|
|
18
|
+
}
|
|
13
19
|
/** What this client lets the server send on a stream before it grants more: a body at least. */
|
|
14
20
|
export const downloadWindow = 2 << 20;
|
|
15
21
|
/** The largest body a WELCOME may come in, before a body is agreed. */
|
|
@@ -260,7 +266,11 @@ export class Session {
|
|
|
260
266
|
checkSignal(signal);
|
|
261
267
|
const agreed = await unlessCancelled(this.welcomed, signal);
|
|
262
268
|
if (body.length > agreed.maxBody) {
|
|
263
|
-
throw new LimitError(
|
|
269
|
+
throw new LimitError(`${methodName(method)}: a request of ${body.length} bytes, past the ${agreed.maxBody} a body holds`, {
|
|
270
|
+
limit: limits.requestBytes.name,
|
|
271
|
+
wanted: String(body.length),
|
|
272
|
+
bound: String(agreed.maxBody),
|
|
273
|
+
});
|
|
264
274
|
}
|
|
265
275
|
while (this.#streams.size >= agreed.inFlight && this.#usable() === undefined) {
|
|
266
276
|
await this.#streamFreed(signal);
|
package/dist/wire/protocol.d.ts
CHANGED
|
@@ -2401,36 +2401,27 @@ export declare const SearchQuery: import("./codec.ts").Message<{
|
|
|
2401
2401
|
readonly limit: readonly [8, import("./codec.ts").Codec<number, number>];
|
|
2402
2402
|
/** the last word read as the start of a word too, as a search box types */
|
|
2403
2403
|
readonly prefix: readonly [9, import("./codec.ts").Codec<boolean, boolean>];
|
|
2404
|
+
/** every word read so, a document holding a word for each first; in place of prefix */
|
|
2405
|
+
readonly prefixEvery: readonly [10, import("./codec.ts").Codec<boolean, boolean>];
|
|
2406
|
+
/** utf8, utf16 or chars: each hit says where it matched, counted in that unit */
|
|
2407
|
+
readonly matches: readonly [11, import("./codec.ts").Codec<string, string>];
|
|
2404
2408
|
}>;
|
|
2405
2409
|
/**
|
|
2406
|
-
*
|
|
2407
|
-
*
|
|
2410
|
+
* Where a search's word matched a hit: a range of a field's text, or of a
|
|
2411
|
+
* string of a field that holds a list, counted in the unit the query asked:
|
|
2412
|
+
* bytes of UTF-8, units of UTF-16 or code points. The whole word for a word
|
|
2413
|
+
* found as written, by its stem or once corrected; the letters typed for a
|
|
2414
|
+
* word a prefix began.
|
|
2408
2415
|
*/
|
|
2409
|
-
export declare const
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
readonly
|
|
2414
|
-
readonly
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
readonly
|
|
2418
|
-
readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2419
|
-
/** null for a table's row */
|
|
2420
|
-
readonly value: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2421
|
-
readonly score: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2422
|
-
readonly row: readonly [4, import("./codec.ts").Codec<(boolean | SqlValue)[], readonly import("./codec.ts").SqlArg[]>];
|
|
2423
|
-
}>[], readonly import("./codec.ts").Written<{
|
|
2424
|
-
readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2425
|
-
/** null for a table's row */
|
|
2426
|
-
readonly value: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2427
|
-
readonly score: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2428
|
-
readonly row: readonly [4, import("./codec.ts").Codec<(boolean | SqlValue)[], readonly import("./codec.ts").SqlArg[]>];
|
|
2429
|
-
}>[]>];
|
|
2430
|
-
/** the text the search read in fact, when a word was read as another */
|
|
2431
|
-
readonly corrected: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2432
|
-
/** the columns of a table's index's rows */
|
|
2433
|
-
readonly columns: readonly [3, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2416
|
+
export declare const SearchMatch: import("./codec.ts").Message<{
|
|
2417
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2418
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2419
|
+
/** the string's place in a field that holds a list */
|
|
2420
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2421
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2422
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2423
|
+
/** the query's word, as its text wrote it */
|
|
2424
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2434
2425
|
}>;
|
|
2435
2426
|
/**
|
|
2436
2427
|
* Where an index stands: ready, rebuilding and how far, or failed and why.
|
|
@@ -2791,9 +2782,12 @@ export declare const SearchOpen: import("./codec.ts").Message<{
|
|
|
2791
2782
|
readonly key: readonly [13, import("./codec.ts").Codec<string, string>];
|
|
2792
2783
|
/** the column of each row's vector, a blob of little-endian floats */
|
|
2793
2784
|
readonly vectorColumn: readonly [14, import("./codec.ts").Codec<string, string>];
|
|
2785
|
+
/** the keyboard layouts its readers type with: ru and en, or none */
|
|
2786
|
+
readonly layouts: readonly [15, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2794
2787
|
}>;
|
|
2795
2788
|
/**
|
|
2796
|
-
* Documents set in one commit, all of them or none: 1,000
|
|
2789
|
+
* Documents set in one commit, all of them or none: 1,000 at most, and no more
|
|
2790
|
+
* than one request body holds, 2 MiB from every SDK.
|
|
2797
2791
|
*/
|
|
2798
2792
|
export declare const SearchSetMany: import("./codec.ts").Message<{
|
|
2799
2793
|
readonly handle: readonly [1, import("./codec.ts").Codec<number, number>];
|
|
@@ -2809,6 +2803,94 @@ export declare const SearchSetMany: import("./codec.ts").Message<{
|
|
|
2809
2803
|
readonly noVector: readonly [4, import("./codec.ts").Codec<boolean, boolean>];
|
|
2810
2804
|
}>[]>];
|
|
2811
2805
|
}>;
|
|
2806
|
+
/**
|
|
2807
|
+
* A hit: a document and its value, or a table's row, a value a column of
|
|
2808
|
+
* the answer's columns, as sql.Rows holds one, and where the search's words
|
|
2809
|
+
* matched it when the query asked.
|
|
2810
|
+
*/
|
|
2811
|
+
export declare const SearchHit: import("./codec.ts").Message<{
|
|
2812
|
+
readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2813
|
+
/** null for a table's row */
|
|
2814
|
+
readonly value: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2815
|
+
readonly score: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2816
|
+
readonly row: readonly [4, import("./codec.ts").Codec<(boolean | SqlValue)[], readonly import("./codec.ts").SqlArg[]>];
|
|
2817
|
+
readonly matches: readonly [5, import("./codec.ts").Codec<Read<{
|
|
2818
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2819
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2820
|
+
/** the string's place in a field that holds a list */
|
|
2821
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2822
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2823
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2824
|
+
/** the query's word, as its text wrote it */
|
|
2825
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2826
|
+
}>[], readonly import("./codec.ts").Written<{
|
|
2827
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2828
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2829
|
+
/** the string's place in a field that holds a list */
|
|
2830
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2831
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2832
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2833
|
+
/** the query's word, as its text wrote it */
|
|
2834
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2835
|
+
}>[]>];
|
|
2836
|
+
}>;
|
|
2837
|
+
export declare const SearchFound: import("./codec.ts").Message<{
|
|
2838
|
+
readonly hits: readonly [1, import("./codec.ts").Codec<Read<{
|
|
2839
|
+
readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2840
|
+
/** null for a table's row */
|
|
2841
|
+
readonly value: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2842
|
+
readonly score: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2843
|
+
readonly row: readonly [4, import("./codec.ts").Codec<(boolean | SqlValue)[], readonly import("./codec.ts").SqlArg[]>];
|
|
2844
|
+
readonly matches: readonly [5, import("./codec.ts").Codec<Read<{
|
|
2845
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2846
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2847
|
+
/** the string's place in a field that holds a list */
|
|
2848
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2849
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2850
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2851
|
+
/** the query's word, as its text wrote it */
|
|
2852
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2853
|
+
}>[], readonly import("./codec.ts").Written<{
|
|
2854
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2855
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2856
|
+
/** the string's place in a field that holds a list */
|
|
2857
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2858
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2859
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2860
|
+
/** the query's word, as its text wrote it */
|
|
2861
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2862
|
+
}>[]>];
|
|
2863
|
+
}>[], readonly import("./codec.ts").Written<{
|
|
2864
|
+
readonly id: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2865
|
+
/** null for a table's row */
|
|
2866
|
+
readonly value: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2867
|
+
readonly score: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2868
|
+
readonly row: readonly [4, import("./codec.ts").Codec<(boolean | SqlValue)[], readonly import("./codec.ts").SqlArg[]>];
|
|
2869
|
+
readonly matches: readonly [5, import("./codec.ts").Codec<Read<{
|
|
2870
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2871
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2872
|
+
/** the string's place in a field that holds a list */
|
|
2873
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2874
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2875
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2876
|
+
/** the query's word, as its text wrote it */
|
|
2877
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2878
|
+
}>[], readonly import("./codec.ts").Written<{
|
|
2879
|
+
/** the field's path or the table's column; empty for a document that is its own text */
|
|
2880
|
+
readonly field: readonly [1, import("./codec.ts").Codec<string, string>];
|
|
2881
|
+
/** the string's place in a field that holds a list */
|
|
2882
|
+
readonly item: readonly [2, import("./codec.ts").Codec<number, number>];
|
|
2883
|
+
readonly start: readonly [3, import("./codec.ts").Codec<number, number>];
|
|
2884
|
+
readonly end: readonly [4, import("./codec.ts").Codec<number, number>];
|
|
2885
|
+
/** the query's word, as its text wrote it */
|
|
2886
|
+
readonly word: readonly [5, import("./codec.ts").Codec<string, string>];
|
|
2887
|
+
}>[]>];
|
|
2888
|
+
}>[]>];
|
|
2889
|
+
/** the text the search read in fact, when a word was read as another */
|
|
2890
|
+
readonly corrected: readonly [2, import("./codec.ts").Codec<string, string>];
|
|
2891
|
+
/** the columns of a table's index's rows */
|
|
2892
|
+
readonly columns: readonly [3, import("./codec.ts").Codec<string[], readonly string[]>];
|
|
2893
|
+
}>;
|
|
2812
2894
|
/**
|
|
2813
2895
|
* A setting's line of explain.
|
|
2814
2896
|
*/
|