@koolbase/core 12.27.0 → 12.29.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/cjs/auth.js +3 -0
- package/dist/cjs/collection-controller.d.ts +20 -0
- package/dist/cjs/collection-controller.js +77 -9
- package/dist/cjs/database-errors.d.ts +40 -0
- package/dist/cjs/database-errors.js +51 -1
- package/dist/cjs/database.d.ts +3 -1
- package/dist/cjs/database.js +3 -1
- package/dist/cjs/errors.d.ts +13 -0
- package/dist/cjs/errors.js +19 -1
- package/dist/cjs/storage-errors.js +2 -0
- package/dist/esm/auth.js +3 -0
- package/dist/esm/collection-controller.d.ts +20 -0
- package/dist/esm/collection-controller.js +77 -9
- package/dist/esm/database-errors.d.ts +40 -0
- package/dist/esm/database-errors.js +48 -1
- package/dist/esm/database.d.ts +3 -1
- package/dist/esm/database.js +3 -1
- package/dist/esm/errors.d.ts +13 -0
- package/dist/esm/errors.js +17 -0
- package/dist/esm/storage-errors.js +3 -1
- package/package.json +1 -1
package/dist/cjs/auth.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.KoolbaseAuth = void 0;
|
|
|
4
4
|
const network_js_1 = require("./network.js");
|
|
5
5
|
const types_js_1 = require("./types.js");
|
|
6
6
|
const auth_errors_js_1 = require("./auth-errors.js");
|
|
7
|
+
const errors_js_1 = require("./errors.js");
|
|
7
8
|
const platform_js_1 = require("./platform.js");
|
|
8
9
|
const device_metadata_js_1 = require("./device-metadata.js");
|
|
9
10
|
/** The server's `{ bucket, path }`; undefined when it is not one. */
|
|
@@ -1315,6 +1316,8 @@ class KoolbaseAuth {
|
|
|
1315
1316
|
throw new auth_errors_js_1.InvalidCredentialsError();
|
|
1316
1317
|
case 'email_in_use':
|
|
1317
1318
|
throw new auth_errors_js_1.EmailAlreadyInUseError();
|
|
1319
|
+
case 'placement_unavailable':
|
|
1320
|
+
throw new errors_js_1.KoolbaseServiceUnavailableError(msg || undefined);
|
|
1318
1321
|
case 'account_disabled':
|
|
1319
1322
|
throw new auth_errors_js_1.UserDisabledError();
|
|
1320
1323
|
case 'account_locked':
|
|
@@ -46,6 +46,15 @@ export interface CollectionState {
|
|
|
46
46
|
readonly searching: boolean;
|
|
47
47
|
/** Why the server could not answer the latest search, or null. The records are not its answer. */
|
|
48
48
|
readonly searchError: unknown;
|
|
49
|
+
/**
|
|
50
|
+
* True while the search is not run on the server, so the records are the
|
|
51
|
+
* list unsearched and an app filters them itself: the server refused this
|
|
52
|
+
* list's search (a field_search it will not take -- the collection's
|
|
53
|
+
* fields changed since the app was built; it is not asked again while
|
|
54
|
+
* this controller lives), or the search is wider than the server takes
|
|
55
|
+
* (a Choice matching more than 100 values, text over 100 characters).
|
|
56
|
+
*/
|
|
57
|
+
readonly searchLoadedOnly: boolean;
|
|
49
58
|
}
|
|
50
59
|
export declare const initialCollectionState: CollectionState;
|
|
51
60
|
/** One string per distinct query, whatever the order of its `where` keys. */
|
|
@@ -67,7 +76,13 @@ export declare class KoolbaseCollectionController {
|
|
|
67
76
|
private liveTimer;
|
|
68
77
|
private search;
|
|
69
78
|
private searchTimer;
|
|
79
|
+
private searchRefused;
|
|
80
|
+
private answered;
|
|
81
|
+
private refreshToken;
|
|
70
82
|
constructor(db: QueryReader, collection: string, query?: CollectionQuery);
|
|
83
|
+
/** The search the server runs: none when it is refused or too wide. */
|
|
84
|
+
private serverSearch;
|
|
85
|
+
private loadedOnly;
|
|
71
86
|
/**
|
|
72
87
|
* Search on the server (#160), once the typing pauses (searchDelayMs): page
|
|
73
88
|
* one of the matches replaces what is shown, never merged with it, and
|
|
@@ -78,6 +93,11 @@ export declare class KoolbaseCollectionController {
|
|
|
78
93
|
*/
|
|
79
94
|
setSearch(search?: FieldSearch | null): void;
|
|
80
95
|
private runSearch;
|
|
96
|
+
/**
|
|
97
|
+
* After the server refused the search: it is not sent again while this
|
|
98
|
+
* controller lives, and the list is read unsearched for the app to filter.
|
|
99
|
+
*/
|
|
100
|
+
private refuse;
|
|
81
101
|
getState(): CollectionState;
|
|
82
102
|
/** Called on every change. Returns the unsubscribe. */
|
|
83
103
|
subscribe(listener: () => void): () => void;
|
|
@@ -27,6 +27,7 @@ exports.KoolbaseCollectionController = exports.initialCollectionState = void 0;
|
|
|
27
27
|
exports.collectionQueryKey = collectionQueryKey;
|
|
28
28
|
const live_source_js_1 = require("./live-source.js");
|
|
29
29
|
const query_refresh_js_1 = require("./query-refresh.js");
|
|
30
|
+
const errors_js_1 = require("./errors.js");
|
|
30
31
|
exports.initialCollectionState = Object.freeze({
|
|
31
32
|
status: 'loading',
|
|
32
33
|
records: Object.freeze([]),
|
|
@@ -37,6 +38,7 @@ exports.initialCollectionState = Object.freeze({
|
|
|
37
38
|
hasMore: true,
|
|
38
39
|
searching: false,
|
|
39
40
|
searchError: null,
|
|
41
|
+
searchLoadedOnly: false,
|
|
40
42
|
});
|
|
41
43
|
/** A search with text to search, or null: none. */
|
|
42
44
|
function normalizedSearch(search) {
|
|
@@ -48,6 +50,17 @@ function normalizedSearch(search) {
|
|
|
48
50
|
choices: (search.choices ?? []).map((c) => ({ field: c.field, values: [...c.values], listed: [...c.listed] })),
|
|
49
51
|
};
|
|
50
52
|
}
|
|
53
|
+
/** The server's limits on a search (#160): past them it refuses it. */
|
|
54
|
+
const SEARCH_MAX_TEXT = 100;
|
|
55
|
+
const SEARCH_MAX_VALUES = 100;
|
|
56
|
+
/** A search the server takes, by its size: text and each Choice's matching values. */
|
|
57
|
+
function withinServerLimits(search) {
|
|
58
|
+
return Array.from(search.text).length <= SEARCH_MAX_TEXT && (search.choices ?? []).every((c) => c.values.length <= SEARCH_MAX_VALUES);
|
|
59
|
+
}
|
|
60
|
+
/** The server refusing a field_search (400): this search, as sent, will never be answered. */
|
|
61
|
+
function isSearchRefusal(error) {
|
|
62
|
+
return error instanceof errors_js_1.KoolbaseError && error.message.startsWith('field_search:');
|
|
63
|
+
}
|
|
51
64
|
function sortedWhere(where) {
|
|
52
65
|
const out = {};
|
|
53
66
|
for (const key of Object.keys(where ?? {}).sort())
|
|
@@ -95,10 +108,22 @@ class KoolbaseCollectionController {
|
|
|
95
108
|
this.unlive = null;
|
|
96
109
|
this.liveTimer = null;
|
|
97
110
|
this.searchTimer = null;
|
|
111
|
+
// The server refused this list's search: it is not asked again.
|
|
112
|
+
this.searchRefused = false;
|
|
113
|
+
// The latest refresh(): only it ends `refreshing`.
|
|
114
|
+
this.refreshToken = 0;
|
|
98
115
|
this.db = db;
|
|
99
116
|
this.collection = collection;
|
|
100
117
|
this.spec = query;
|
|
101
118
|
this.search = normalizedSearch(query.search);
|
|
119
|
+
this.state = Object.freeze({ ...this.state, searchLoadedOnly: this.loadedOnly() });
|
|
120
|
+
}
|
|
121
|
+
/** The search the server runs: none when it is refused or too wide. */
|
|
122
|
+
serverSearch() {
|
|
123
|
+
return this.search && !this.searchRefused && withinServerLimits(this.search) ? this.search : null;
|
|
124
|
+
}
|
|
125
|
+
loadedOnly() {
|
|
126
|
+
return this.search !== null && this.serverSearch() === null;
|
|
102
127
|
}
|
|
103
128
|
/**
|
|
104
129
|
* Search on the server (#160), once the typing pauses (searchDelayMs): page
|
|
@@ -115,11 +140,22 @@ class KoolbaseCollectionController {
|
|
|
115
140
|
if (JSON.stringify(next) === JSON.stringify(this.search))
|
|
116
141
|
return;
|
|
117
142
|
this.search = next;
|
|
143
|
+
// What is shown already answers the server's search (both not sent, say):
|
|
144
|
+
// nothing to read again, and nothing still waiting is wanted.
|
|
145
|
+
if (this.answered !== undefined && JSON.stringify(this.serverSearch()) === this.answered && this.state.status === 'loaded') {
|
|
146
|
+
if (this.searchTimer) {
|
|
147
|
+
clearTimeout(this.searchTimer);
|
|
148
|
+
this.searchTimer = null;
|
|
149
|
+
}
|
|
150
|
+
this.generation++;
|
|
151
|
+
this.set({ searching: false, searchError: null, loadingMore: false, searchLoadedOnly: this.loadedOnly() });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
118
154
|
// Whatever is in flight was for the old search.
|
|
119
155
|
this.generation++;
|
|
120
156
|
if (this.searchTimer)
|
|
121
157
|
clearTimeout(this.searchTimer);
|
|
122
|
-
this.set({ searching: true, searchError: null, loadingMore: false });
|
|
158
|
+
this.set({ searching: true, searchError: null, loadingMore: false, searchLoadedOnly: this.loadedOnly() });
|
|
123
159
|
this.searchTimer = setTimeout(() => {
|
|
124
160
|
this.searchTimer = null;
|
|
125
161
|
void this.runSearch();
|
|
@@ -132,22 +168,38 @@ class KoolbaseCollectionController {
|
|
|
132
168
|
const gen = ++this.generation;
|
|
133
169
|
if (this.state.loadingMore)
|
|
134
170
|
this.set({ loadingMore: false });
|
|
171
|
+
const asking = JSON.stringify(this.serverSearch());
|
|
135
172
|
try {
|
|
136
173
|
const result = await this.db.query(this.collection, this.options(0, 'network-only'));
|
|
137
174
|
if (this.isStale(gen))
|
|
138
175
|
return;
|
|
176
|
+
this.answered = asking;
|
|
139
177
|
this.showPageOne(result, false, false);
|
|
140
178
|
this.set({ searching: false, searchError: null });
|
|
141
179
|
}
|
|
142
180
|
catch (error) {
|
|
143
181
|
if (this.isStale(gen))
|
|
144
182
|
return;
|
|
183
|
+
if (this.refuse(error))
|
|
184
|
+
return;
|
|
145
185
|
// Nothing loaded yet to show under it: the list's own error.
|
|
146
186
|
this.set(this.state.status === 'loaded'
|
|
147
187
|
? { searching: false, searchError: error }
|
|
148
188
|
: { searching: false, searchError: error, status: 'error', error });
|
|
149
189
|
}
|
|
150
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* After the server refused the search: it is not sent again while this
|
|
193
|
+
* controller lives, and the list is read unsearched for the app to filter.
|
|
194
|
+
*/
|
|
195
|
+
refuse(error) {
|
|
196
|
+
if (!isSearchRefusal(error) || this.serverSearch() === null)
|
|
197
|
+
return false;
|
|
198
|
+
this.searchRefused = true;
|
|
199
|
+
this.set({ searching: true, searchError: null, searchLoadedOnly: true });
|
|
200
|
+
void this.runSearch();
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
151
203
|
getState() {
|
|
152
204
|
return this.state;
|
|
153
205
|
}
|
|
@@ -174,9 +226,11 @@ class KoolbaseCollectionController {
|
|
|
174
226
|
async refresh() {
|
|
175
227
|
if (this.disposed)
|
|
176
228
|
return;
|
|
229
|
+
const token = ++this.refreshToken;
|
|
177
230
|
this.set({ refreshing: true });
|
|
178
|
-
|
|
179
|
-
|
|
231
|
+
await this.firstPage('network-only');
|
|
232
|
+
// Ended by the latest refresh, whatever superseded its read.
|
|
233
|
+
if (token === this.refreshToken)
|
|
180
234
|
this.set({ refreshing: false });
|
|
181
235
|
}
|
|
182
236
|
/**
|
|
@@ -218,7 +272,7 @@ class KoolbaseCollectionController {
|
|
|
218
272
|
const offset = this.nextOffset;
|
|
219
273
|
this.set({ loadingMore: true });
|
|
220
274
|
try {
|
|
221
|
-
const result = await this.db.query(this.collection, this.options(offset, this.
|
|
275
|
+
const result = await this.db.query(this.collection, this.options(offset, this.serverSearch() ? 'network-only' : 'default'));
|
|
222
276
|
if (this.isStale(gen))
|
|
223
277
|
return;
|
|
224
278
|
this.laterPages = [...this.laterPages, ...result.records];
|
|
@@ -227,8 +281,11 @@ class KoolbaseCollectionController {
|
|
|
227
281
|
const total = result.records.length === 0 ? this.nextOffset : result.total;
|
|
228
282
|
this.publish({}, total);
|
|
229
283
|
}
|
|
230
|
-
catch {
|
|
231
|
-
//
|
|
284
|
+
catch (error) {
|
|
285
|
+
// Refused (the schema changed since): the list unsearched. Otherwise
|
|
286
|
+
// keep what is shown; the caller can try again.
|
|
287
|
+
if (!this.isStale(gen))
|
|
288
|
+
this.refuse(error);
|
|
232
289
|
}
|
|
233
290
|
finally {
|
|
234
291
|
if (!this.isStale(gen))
|
|
@@ -258,14 +315,18 @@ class KoolbaseCollectionController {
|
|
|
258
315
|
// will not clear its own flag.
|
|
259
316
|
if (this.state.loadingMore)
|
|
260
317
|
this.set({ loadingMore: false });
|
|
318
|
+
const asking = JSON.stringify(this.serverSearch());
|
|
261
319
|
try {
|
|
262
320
|
const result = await this.db.query(this.collection,
|
|
263
321
|
// A search's answer is the server's, never a cached one (#160).
|
|
264
|
-
this.options(0, this.
|
|
265
|
-
if (!this.isStale(gen))
|
|
322
|
+
this.options(0, this.serverSearch() ? 'network-only' : cache, (fresh) => {
|
|
323
|
+
if (!this.isStale(gen)) {
|
|
324
|
+
this.answered = asking;
|
|
266
325
|
this.showPageOne(fresh, false, true);
|
|
326
|
+
}
|
|
267
327
|
}));
|
|
268
328
|
if (!this.isStale(gen)) {
|
|
329
|
+
this.answered = asking;
|
|
269
330
|
this.showPageOne(result, result.isFromCache === true, false);
|
|
270
331
|
// A search this fetch superseded is answered by it -- unless a newer
|
|
271
332
|
// one is still waiting for the typing to pause.
|
|
@@ -275,6 +336,13 @@ class KoolbaseCollectionController {
|
|
|
275
336
|
}
|
|
276
337
|
}
|
|
277
338
|
catch (error) {
|
|
339
|
+
// The server refused the search: read unsearched, at once -- the
|
|
340
|
+
// generation this returns is that read's, so refresh() ends with it.
|
|
341
|
+
if (!this.isStale(gen) && isSearchRefusal(error) && this.serverSearch() !== null) {
|
|
342
|
+
this.searchRefused = true;
|
|
343
|
+
this.set({ searchError: null, searchLoadedOnly: true });
|
|
344
|
+
return this.firstPage(cache);
|
|
345
|
+
}
|
|
278
346
|
if (!this.isStale(gen) && this.state.searching && !this.searchTimer) {
|
|
279
347
|
this.set({ searching: false, searchError: error });
|
|
280
348
|
}
|
|
@@ -310,7 +378,7 @@ class KoolbaseCollectionController {
|
|
|
310
378
|
offset,
|
|
311
379
|
orderBy: this.spec.orderBy,
|
|
312
380
|
orderDesc: this.spec.orderDesc,
|
|
313
|
-
...(this.
|
|
381
|
+
...(this.serverSearch() ? { fieldSearch: this.serverSearch() } : {}),
|
|
314
382
|
cache,
|
|
315
383
|
onRefresh,
|
|
316
384
|
};
|
|
@@ -134,6 +134,46 @@ export declare class KoolbaseFieldNotAutoEmbedError extends KoolbaseDataError {
|
|
|
134
134
|
export declare class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
|
|
135
135
|
constructor(message?: string);
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* The vector field is filled by automatic embedding: Koolbase makes its
|
|
139
|
+
* vectors from the record's fields, so the app cannot write one, delete one,
|
|
140
|
+
* or send text for it (a 409, `auto_embedding_managed`). Write the record's
|
|
141
|
+
* fields instead; the vector follows.
|
|
142
|
+
*/
|
|
143
|
+
export declare class KoolbaseAutoEmbeddingManagedError extends KoolbaseDataError {
|
|
144
|
+
constructor(message?: string);
|
|
145
|
+
}
|
|
146
|
+
/** What embedding a collection again costs, roughly (#162). */
|
|
147
|
+
export interface KoolbaseReembedEstimate {
|
|
148
|
+
records: number;
|
|
149
|
+
records_to_embed: number;
|
|
150
|
+
estimated_input_tokens: number;
|
|
151
|
+
provider: string;
|
|
152
|
+
model: string;
|
|
153
|
+
dimensions: number;
|
|
154
|
+
billed_by: string;
|
|
155
|
+
estimate: boolean;
|
|
156
|
+
cache_may_apply: boolean;
|
|
157
|
+
sampled_records: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A change to a vector field's embedding would embed the collection again,
|
|
161
|
+
* and was not confirmed (a 409, `reembed_confirmation_required`). `estimate`
|
|
162
|
+
* says what it would cost; send the change again with `confirm_reembed: true`
|
|
163
|
+
* to make it.
|
|
164
|
+
*/
|
|
165
|
+
export declare class KoolbaseReembedConfirmationRequiredError extends KoolbaseDataError {
|
|
166
|
+
readonly estimate?: KoolbaseReembedEstimate;
|
|
167
|
+
constructor(message?: string, estimate?: KoolbaseReembedEstimate);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The embedding model is not one Koolbase offers, has been shut down by its
|
|
171
|
+
* provider, or cannot store vectors of that size (a 400,
|
|
172
|
+
* `embedding_model_unsupported`).
|
|
173
|
+
*/
|
|
174
|
+
export declare class KoolbaseEmbeddingModelUnsupportedError extends KoolbaseDataError {
|
|
175
|
+
constructor(message?: string);
|
|
176
|
+
}
|
|
137
177
|
/**
|
|
138
178
|
* The project has no embedding provider configured. Embedding runs on the
|
|
139
179
|
* project's own Gemini or OpenAI key.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseInsufficientAuthorityError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = exports.KoolbaseCollectionReferencedError = exports.KoolbaseDanglingReferencesError = exports.KoolbaseReferenceInUseError = exports.KoolbaseReferenceInvalidError = exports.KoolbaseConflictError = exports.KoolbaseConstraintNotFoundError = exports.KoolbaseConstraintExistsError = exports.KoolbaseAmbiguousMatchError = exports.KoolbaseDuplicateValuesError = exports.KoolbaseBatchFailedError = exports.KoolbaseIdempotencyKeyReusedError = exports.KoolbaseRevisionMismatchError = exports.KoolbaseProviderInvalidError = exports.KoolbaseProviderNotConfiguredError = exports.KoolbaseInvalidEmbeddingConfigError = exports.KoolbaseFieldNotAutoEmbedError = exports.KoolbaseVectorFieldExistsError = exports.KoolbaseStateConflictError = exports.KoolbaseNoChangesError = exports.KoolbaseInvalidBodyError = exports.KoolbaseProjectInvalidError = exports.KoolbaseInvitationInvalidError = exports.KoolbaseSlugTakenError = exports.KoolbaseSeedError = exports.KoolbaseDataError = void 0;
|
|
3
|
+
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseInsufficientAuthorityError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = exports.KoolbaseCollectionReferencedError = exports.KoolbaseDanglingReferencesError = exports.KoolbaseReferenceInUseError = exports.KoolbaseReferenceInvalidError = exports.KoolbaseConflictError = exports.KoolbaseConstraintNotFoundError = exports.KoolbaseConstraintExistsError = exports.KoolbaseAmbiguousMatchError = exports.KoolbaseDuplicateValuesError = exports.KoolbaseBatchFailedError = exports.KoolbaseIdempotencyKeyReusedError = exports.KoolbaseRevisionMismatchError = exports.KoolbaseProviderInvalidError = exports.KoolbaseProviderNotConfiguredError = exports.KoolbaseEmbeddingModelUnsupportedError = exports.KoolbaseReembedConfirmationRequiredError = exports.KoolbaseAutoEmbeddingManagedError = exports.KoolbaseInvalidEmbeddingConfigError = exports.KoolbaseFieldNotAutoEmbedError = exports.KoolbaseVectorFieldExistsError = exports.KoolbaseStateConflictError = exports.KoolbaseNoChangesError = exports.KoolbaseInvalidBodyError = exports.KoolbaseProjectInvalidError = exports.KoolbaseInvitationInvalidError = exports.KoolbaseSlugTakenError = exports.KoolbaseSeedError = exports.KoolbaseDataError = void 0;
|
|
4
4
|
exports.koolbaseDataError = koolbaseDataError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -187,6 +187,48 @@ class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
exports.KoolbaseInvalidEmbeddingConfigError = KoolbaseInvalidEmbeddingConfigError;
|
|
190
|
+
/**
|
|
191
|
+
* The vector field is filled by automatic embedding: Koolbase makes its
|
|
192
|
+
* vectors from the record's fields, so the app cannot write one, delete one,
|
|
193
|
+
* or send text for it (a 409, `auto_embedding_managed`). Write the record's
|
|
194
|
+
* fields instead; the vector follows.
|
|
195
|
+
*/
|
|
196
|
+
class KoolbaseAutoEmbeddingManagedError extends KoolbaseDataError {
|
|
197
|
+
constructor(message) {
|
|
198
|
+
super(message ?? 'This vector field is managed by automatic embedding and cannot be written manually.', 'auto_embedding_managed');
|
|
199
|
+
this.name = 'KoolbaseAutoEmbeddingManagedError';
|
|
200
|
+
Object.setPrototypeOf(this, KoolbaseAutoEmbeddingManagedError.prototype);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.KoolbaseAutoEmbeddingManagedError = KoolbaseAutoEmbeddingManagedError;
|
|
204
|
+
/**
|
|
205
|
+
* A change to a vector field's embedding would embed the collection again,
|
|
206
|
+
* and was not confirmed (a 409, `reembed_confirmation_required`). `estimate`
|
|
207
|
+
* says what it would cost; send the change again with `confirm_reembed: true`
|
|
208
|
+
* to make it.
|
|
209
|
+
*/
|
|
210
|
+
class KoolbaseReembedConfirmationRequiredError extends KoolbaseDataError {
|
|
211
|
+
constructor(message, estimate) {
|
|
212
|
+
super(message ?? 'This change embeds every record again; confirm it with confirm_reembed', 'reembed_confirmation_required');
|
|
213
|
+
this.estimate = estimate;
|
|
214
|
+
this.name = 'KoolbaseReembedConfirmationRequiredError';
|
|
215
|
+
Object.setPrototypeOf(this, KoolbaseReembedConfirmationRequiredError.prototype);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.KoolbaseReembedConfirmationRequiredError = KoolbaseReembedConfirmationRequiredError;
|
|
219
|
+
/**
|
|
220
|
+
* The embedding model is not one Koolbase offers, has been shut down by its
|
|
221
|
+
* provider, or cannot store vectors of that size (a 400,
|
|
222
|
+
* `embedding_model_unsupported`).
|
|
223
|
+
*/
|
|
224
|
+
class KoolbaseEmbeddingModelUnsupportedError extends KoolbaseDataError {
|
|
225
|
+
constructor(message) {
|
|
226
|
+
super(message ?? 'Embedding model not offered', 'embedding_model_unsupported');
|
|
227
|
+
this.name = 'KoolbaseEmbeddingModelUnsupportedError';
|
|
228
|
+
Object.setPrototypeOf(this, KoolbaseEmbeddingModelUnsupportedError.prototype);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.KoolbaseEmbeddingModelUnsupportedError = KoolbaseEmbeddingModelUnsupportedError;
|
|
190
232
|
/**
|
|
191
233
|
* The project has no embedding provider configured. Embedding runs on the
|
|
192
234
|
* project's own Gemini or OpenAI key.
|
|
@@ -526,6 +568,14 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
526
568
|
return attach(new KoolbaseFieldNotAutoEmbedError(message));
|
|
527
569
|
case 'invalid_embedding_config':
|
|
528
570
|
return attach(new KoolbaseInvalidEmbeddingConfigError(message));
|
|
571
|
+
case 'auto_embedding_managed':
|
|
572
|
+
return attach(new KoolbaseAutoEmbeddingManagedError(message));
|
|
573
|
+
case 'reembed_confirmation_required':
|
|
574
|
+
return attach(new KoolbaseReembedConfirmationRequiredError(message, body?.details));
|
|
575
|
+
case 'embedding_model_unsupported':
|
|
576
|
+
return attach(new KoolbaseEmbeddingModelUnsupportedError(message));
|
|
577
|
+
case 'placement_unavailable':
|
|
578
|
+
return new errors_js_1.KoolbaseServiceUnavailableError(message);
|
|
529
579
|
case 'provider_not_configured':
|
|
530
580
|
return attach(new KoolbaseProviderNotConfiguredError(message));
|
|
531
581
|
case 'provider_invalid':
|
package/dist/cjs/database.d.ts
CHANGED
|
@@ -266,7 +266,9 @@ export declare class KoolbaseDatabase {
|
|
|
266
266
|
*
|
|
267
267
|
* The field must already be declared on the collection via the dashboard
|
|
268
268
|
* or CLI. `vector.length` must match the field's declared dimension;
|
|
269
|
-
* otherwise throws `KoolbaseVectorDimensionMismatchError`.
|
|
269
|
+
* otherwise throws `KoolbaseVectorDimensionMismatchError`. A field Koolbase
|
|
270
|
+
* embeds itself refuses it with `KoolbaseAutoEmbeddingManagedError`: write
|
|
271
|
+
* the record's fields instead.
|
|
270
272
|
*
|
|
271
273
|
* Online-only — vectors are not cached locally or queued offline because
|
|
272
274
|
* HNSW similarity search has no useful offline semantics.
|
package/dist/cjs/database.js
CHANGED
|
@@ -918,7 +918,9 @@ class KoolbaseDatabase {
|
|
|
918
918
|
*
|
|
919
919
|
* The field must already be declared on the collection via the dashboard
|
|
920
920
|
* or CLI. `vector.length` must match the field's declared dimension;
|
|
921
|
-
* otherwise throws `KoolbaseVectorDimensionMismatchError`.
|
|
921
|
+
* otherwise throws `KoolbaseVectorDimensionMismatchError`. A field Koolbase
|
|
922
|
+
* embeds itself refuses it with `KoolbaseAutoEmbeddingManagedError`: write
|
|
923
|
+
* the record's fields instead.
|
|
922
924
|
*
|
|
923
925
|
* Online-only — vectors are not cached locally or queued offline because
|
|
924
926
|
* HNSW similarity search has no useful offline semantics.
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -73,6 +73,19 @@ export declare class KoolbasePlanLimitError extends KoolbaseError {
|
|
|
73
73
|
readonly plan?: string | undefined;
|
|
74
74
|
constructor(message?: string, resource?: string | undefined, limit?: number | undefined, plan?: string | undefined);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The project's database could not be reached just now, or which database it
|
|
78
|
+
* is could not be established (a 503, `placement_unavailable`). Koolbase never
|
|
79
|
+
* answers from another database in its place, so nothing was read or written:
|
|
80
|
+
* try again shortly.
|
|
81
|
+
*
|
|
82
|
+
* Shared: any request to the project -- a query, an upload, a sign-in -- can
|
|
83
|
+
* meet it.
|
|
84
|
+
*/
|
|
85
|
+
export declare class KoolbaseServiceUnavailableError extends KoolbaseError {
|
|
86
|
+
readonly retryable = true;
|
|
87
|
+
constructor(message?: string);
|
|
88
|
+
}
|
|
76
89
|
export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
77
90
|
constructor(message: string);
|
|
78
91
|
}
|
package/dist/cjs/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
|
|
3
|
+
exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbaseServiceUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The root of every error the SDK raises.
|
|
6
6
|
*
|
|
@@ -94,6 +94,24 @@ class KoolbasePlanLimitError extends KoolbaseError {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
exports.KoolbasePlanLimitError = KoolbasePlanLimitError;
|
|
97
|
+
/**
|
|
98
|
+
* The project's database could not be reached just now, or which database it
|
|
99
|
+
* is could not be established (a 503, `placement_unavailable`). Koolbase never
|
|
100
|
+
* answers from another database in its place, so nothing was read or written:
|
|
101
|
+
* try again shortly.
|
|
102
|
+
*
|
|
103
|
+
* Shared: any request to the project -- a query, an upload, a sign-in -- can
|
|
104
|
+
* meet it.
|
|
105
|
+
*/
|
|
106
|
+
class KoolbaseServiceUnavailableError extends KoolbaseError {
|
|
107
|
+
constructor(message) {
|
|
108
|
+
super(message ?? "This project's database is temporarily unavailable. Please try again.", 'placement_unavailable');
|
|
109
|
+
this.retryable = true;
|
|
110
|
+
this.name = 'KoolbaseServiceUnavailableError';
|
|
111
|
+
Object.setPrototypeOf(this, KoolbaseServiceUnavailableError.prototype);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.KoolbaseServiceUnavailableError = KoolbaseServiceUnavailableError;
|
|
97
115
|
class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
98
116
|
constructor(message) {
|
|
99
117
|
super(message, 'offline_baseline_unavailable');
|
|
@@ -417,6 +417,8 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
|
|
|
417
417
|
const d = (body?.details ?? {});
|
|
418
418
|
return new errors_js_1.KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
|
|
419
419
|
}
|
|
420
|
+
case 'placement_unavailable':
|
|
421
|
+
return new errors_js_1.KoolbaseServiceUnavailableError(message);
|
|
420
422
|
case 'quota_exceeded':
|
|
421
423
|
return new KoolbaseStorageQuotaError(message);
|
|
422
424
|
case 'upload_expired':
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { koolbaseFetch } from './network.js';
|
|
2
2
|
import { RestoreResult, } from './types.js';
|
|
3
3
|
import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
|
|
4
|
+
import { KoolbaseServiceUnavailableError } from './errors.js';
|
|
4
5
|
import { getPlatform } from './platform.js';
|
|
5
6
|
import { DeviceMetadata } from './device-metadata.js';
|
|
6
7
|
/** The server's `{ bucket, path }`; undefined when it is not one. */
|
|
@@ -1312,6 +1313,8 @@ export class KoolbaseAuth {
|
|
|
1312
1313
|
throw new InvalidCredentialsError();
|
|
1313
1314
|
case 'email_in_use':
|
|
1314
1315
|
throw new EmailAlreadyInUseError();
|
|
1316
|
+
case 'placement_unavailable':
|
|
1317
|
+
throw new KoolbaseServiceUnavailableError(msg || undefined);
|
|
1315
1318
|
case 'account_disabled':
|
|
1316
1319
|
throw new UserDisabledError();
|
|
1317
1320
|
case 'account_locked':
|
|
@@ -46,6 +46,15 @@ export interface CollectionState {
|
|
|
46
46
|
readonly searching: boolean;
|
|
47
47
|
/** Why the server could not answer the latest search, or null. The records are not its answer. */
|
|
48
48
|
readonly searchError: unknown;
|
|
49
|
+
/**
|
|
50
|
+
* True while the search is not run on the server, so the records are the
|
|
51
|
+
* list unsearched and an app filters them itself: the server refused this
|
|
52
|
+
* list's search (a field_search it will not take -- the collection's
|
|
53
|
+
* fields changed since the app was built; it is not asked again while
|
|
54
|
+
* this controller lives), or the search is wider than the server takes
|
|
55
|
+
* (a Choice matching more than 100 values, text over 100 characters).
|
|
56
|
+
*/
|
|
57
|
+
readonly searchLoadedOnly: boolean;
|
|
49
58
|
}
|
|
50
59
|
export declare const initialCollectionState: CollectionState;
|
|
51
60
|
/** One string per distinct query, whatever the order of its `where` keys. */
|
|
@@ -67,7 +76,13 @@ export declare class KoolbaseCollectionController {
|
|
|
67
76
|
private liveTimer;
|
|
68
77
|
private search;
|
|
69
78
|
private searchTimer;
|
|
79
|
+
private searchRefused;
|
|
80
|
+
private answered;
|
|
81
|
+
private refreshToken;
|
|
70
82
|
constructor(db: QueryReader, collection: string, query?: CollectionQuery);
|
|
83
|
+
/** The search the server runs: none when it is refused or too wide. */
|
|
84
|
+
private serverSearch;
|
|
85
|
+
private loadedOnly;
|
|
71
86
|
/**
|
|
72
87
|
* Search on the server (#160), once the typing pauses (searchDelayMs): page
|
|
73
88
|
* one of the matches replaces what is shown, never merged with it, and
|
|
@@ -78,6 +93,11 @@ export declare class KoolbaseCollectionController {
|
|
|
78
93
|
*/
|
|
79
94
|
setSearch(search?: FieldSearch | null): void;
|
|
80
95
|
private runSearch;
|
|
96
|
+
/**
|
|
97
|
+
* After the server refused the search: it is not sent again while this
|
|
98
|
+
* controller lives, and the list is read unsearched for the app to filter.
|
|
99
|
+
*/
|
|
100
|
+
private refuse;
|
|
81
101
|
getState(): CollectionState;
|
|
82
102
|
/** Called on every change. Returns the unsubscribe. */
|
|
83
103
|
subscribe(listener: () => void): () => void;
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// from page one. Duplicates are removed; a skipped row cannot be detected.
|
|
24
24
|
import { liveSource } from './live-source.js';
|
|
25
25
|
import { registerQueryRefresher } from './query-refresh.js';
|
|
26
|
+
import { KoolbaseError } from './errors.js';
|
|
26
27
|
export const initialCollectionState = Object.freeze({
|
|
27
28
|
status: 'loading',
|
|
28
29
|
records: Object.freeze([]),
|
|
@@ -33,6 +34,7 @@ export const initialCollectionState = Object.freeze({
|
|
|
33
34
|
hasMore: true,
|
|
34
35
|
searching: false,
|
|
35
36
|
searchError: null,
|
|
37
|
+
searchLoadedOnly: false,
|
|
36
38
|
});
|
|
37
39
|
/** A search with text to search, or null: none. */
|
|
38
40
|
function normalizedSearch(search) {
|
|
@@ -44,6 +46,17 @@ function normalizedSearch(search) {
|
|
|
44
46
|
choices: (search.choices ?? []).map((c) => ({ field: c.field, values: [...c.values], listed: [...c.listed] })),
|
|
45
47
|
};
|
|
46
48
|
}
|
|
49
|
+
/** The server's limits on a search (#160): past them it refuses it. */
|
|
50
|
+
const SEARCH_MAX_TEXT = 100;
|
|
51
|
+
const SEARCH_MAX_VALUES = 100;
|
|
52
|
+
/** A search the server takes, by its size: text and each Choice's matching values. */
|
|
53
|
+
function withinServerLimits(search) {
|
|
54
|
+
return Array.from(search.text).length <= SEARCH_MAX_TEXT && (search.choices ?? []).every((c) => c.values.length <= SEARCH_MAX_VALUES);
|
|
55
|
+
}
|
|
56
|
+
/** The server refusing a field_search (400): this search, as sent, will never be answered. */
|
|
57
|
+
function isSearchRefusal(error) {
|
|
58
|
+
return error instanceof KoolbaseError && error.message.startsWith('field_search:');
|
|
59
|
+
}
|
|
47
60
|
function sortedWhere(where) {
|
|
48
61
|
const out = {};
|
|
49
62
|
for (const key of Object.keys(where ?? {}).sort())
|
|
@@ -91,10 +104,22 @@ export class KoolbaseCollectionController {
|
|
|
91
104
|
this.unlive = null;
|
|
92
105
|
this.liveTimer = null;
|
|
93
106
|
this.searchTimer = null;
|
|
107
|
+
// The server refused this list's search: it is not asked again.
|
|
108
|
+
this.searchRefused = false;
|
|
109
|
+
// The latest refresh(): only it ends `refreshing`.
|
|
110
|
+
this.refreshToken = 0;
|
|
94
111
|
this.db = db;
|
|
95
112
|
this.collection = collection;
|
|
96
113
|
this.spec = query;
|
|
97
114
|
this.search = normalizedSearch(query.search);
|
|
115
|
+
this.state = Object.freeze({ ...this.state, searchLoadedOnly: this.loadedOnly() });
|
|
116
|
+
}
|
|
117
|
+
/** The search the server runs: none when it is refused or too wide. */
|
|
118
|
+
serverSearch() {
|
|
119
|
+
return this.search && !this.searchRefused && withinServerLimits(this.search) ? this.search : null;
|
|
120
|
+
}
|
|
121
|
+
loadedOnly() {
|
|
122
|
+
return this.search !== null && this.serverSearch() === null;
|
|
98
123
|
}
|
|
99
124
|
/**
|
|
100
125
|
* Search on the server (#160), once the typing pauses (searchDelayMs): page
|
|
@@ -111,11 +136,22 @@ export class KoolbaseCollectionController {
|
|
|
111
136
|
if (JSON.stringify(next) === JSON.stringify(this.search))
|
|
112
137
|
return;
|
|
113
138
|
this.search = next;
|
|
139
|
+
// What is shown already answers the server's search (both not sent, say):
|
|
140
|
+
// nothing to read again, and nothing still waiting is wanted.
|
|
141
|
+
if (this.answered !== undefined && JSON.stringify(this.serverSearch()) === this.answered && this.state.status === 'loaded') {
|
|
142
|
+
if (this.searchTimer) {
|
|
143
|
+
clearTimeout(this.searchTimer);
|
|
144
|
+
this.searchTimer = null;
|
|
145
|
+
}
|
|
146
|
+
this.generation++;
|
|
147
|
+
this.set({ searching: false, searchError: null, loadingMore: false, searchLoadedOnly: this.loadedOnly() });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
114
150
|
// Whatever is in flight was for the old search.
|
|
115
151
|
this.generation++;
|
|
116
152
|
if (this.searchTimer)
|
|
117
153
|
clearTimeout(this.searchTimer);
|
|
118
|
-
this.set({ searching: true, searchError: null, loadingMore: false });
|
|
154
|
+
this.set({ searching: true, searchError: null, loadingMore: false, searchLoadedOnly: this.loadedOnly() });
|
|
119
155
|
this.searchTimer = setTimeout(() => {
|
|
120
156
|
this.searchTimer = null;
|
|
121
157
|
void this.runSearch();
|
|
@@ -128,22 +164,38 @@ export class KoolbaseCollectionController {
|
|
|
128
164
|
const gen = ++this.generation;
|
|
129
165
|
if (this.state.loadingMore)
|
|
130
166
|
this.set({ loadingMore: false });
|
|
167
|
+
const asking = JSON.stringify(this.serverSearch());
|
|
131
168
|
try {
|
|
132
169
|
const result = await this.db.query(this.collection, this.options(0, 'network-only'));
|
|
133
170
|
if (this.isStale(gen))
|
|
134
171
|
return;
|
|
172
|
+
this.answered = asking;
|
|
135
173
|
this.showPageOne(result, false, false);
|
|
136
174
|
this.set({ searching: false, searchError: null });
|
|
137
175
|
}
|
|
138
176
|
catch (error) {
|
|
139
177
|
if (this.isStale(gen))
|
|
140
178
|
return;
|
|
179
|
+
if (this.refuse(error))
|
|
180
|
+
return;
|
|
141
181
|
// Nothing loaded yet to show under it: the list's own error.
|
|
142
182
|
this.set(this.state.status === 'loaded'
|
|
143
183
|
? { searching: false, searchError: error }
|
|
144
184
|
: { searching: false, searchError: error, status: 'error', error });
|
|
145
185
|
}
|
|
146
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* After the server refused the search: it is not sent again while this
|
|
189
|
+
* controller lives, and the list is read unsearched for the app to filter.
|
|
190
|
+
*/
|
|
191
|
+
refuse(error) {
|
|
192
|
+
if (!isSearchRefusal(error) || this.serverSearch() === null)
|
|
193
|
+
return false;
|
|
194
|
+
this.searchRefused = true;
|
|
195
|
+
this.set({ searching: true, searchError: null, searchLoadedOnly: true });
|
|
196
|
+
void this.runSearch();
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
147
199
|
getState() {
|
|
148
200
|
return this.state;
|
|
149
201
|
}
|
|
@@ -170,9 +222,11 @@ export class KoolbaseCollectionController {
|
|
|
170
222
|
async refresh() {
|
|
171
223
|
if (this.disposed)
|
|
172
224
|
return;
|
|
225
|
+
const token = ++this.refreshToken;
|
|
173
226
|
this.set({ refreshing: true });
|
|
174
|
-
|
|
175
|
-
|
|
227
|
+
await this.firstPage('network-only');
|
|
228
|
+
// Ended by the latest refresh, whatever superseded its read.
|
|
229
|
+
if (token === this.refreshToken)
|
|
176
230
|
this.set({ refreshing: false });
|
|
177
231
|
}
|
|
178
232
|
/**
|
|
@@ -214,7 +268,7 @@ export class KoolbaseCollectionController {
|
|
|
214
268
|
const offset = this.nextOffset;
|
|
215
269
|
this.set({ loadingMore: true });
|
|
216
270
|
try {
|
|
217
|
-
const result = await this.db.query(this.collection, this.options(offset, this.
|
|
271
|
+
const result = await this.db.query(this.collection, this.options(offset, this.serverSearch() ? 'network-only' : 'default'));
|
|
218
272
|
if (this.isStale(gen))
|
|
219
273
|
return;
|
|
220
274
|
this.laterPages = [...this.laterPages, ...result.records];
|
|
@@ -223,8 +277,11 @@ export class KoolbaseCollectionController {
|
|
|
223
277
|
const total = result.records.length === 0 ? this.nextOffset : result.total;
|
|
224
278
|
this.publish({}, total);
|
|
225
279
|
}
|
|
226
|
-
catch {
|
|
227
|
-
//
|
|
280
|
+
catch (error) {
|
|
281
|
+
// Refused (the schema changed since): the list unsearched. Otherwise
|
|
282
|
+
// keep what is shown; the caller can try again.
|
|
283
|
+
if (!this.isStale(gen))
|
|
284
|
+
this.refuse(error);
|
|
228
285
|
}
|
|
229
286
|
finally {
|
|
230
287
|
if (!this.isStale(gen))
|
|
@@ -254,14 +311,18 @@ export class KoolbaseCollectionController {
|
|
|
254
311
|
// will not clear its own flag.
|
|
255
312
|
if (this.state.loadingMore)
|
|
256
313
|
this.set({ loadingMore: false });
|
|
314
|
+
const asking = JSON.stringify(this.serverSearch());
|
|
257
315
|
try {
|
|
258
316
|
const result = await this.db.query(this.collection,
|
|
259
317
|
// A search's answer is the server's, never a cached one (#160).
|
|
260
|
-
this.options(0, this.
|
|
261
|
-
if (!this.isStale(gen))
|
|
318
|
+
this.options(0, this.serverSearch() ? 'network-only' : cache, (fresh) => {
|
|
319
|
+
if (!this.isStale(gen)) {
|
|
320
|
+
this.answered = asking;
|
|
262
321
|
this.showPageOne(fresh, false, true);
|
|
322
|
+
}
|
|
263
323
|
}));
|
|
264
324
|
if (!this.isStale(gen)) {
|
|
325
|
+
this.answered = asking;
|
|
265
326
|
this.showPageOne(result, result.isFromCache === true, false);
|
|
266
327
|
// A search this fetch superseded is answered by it -- unless a newer
|
|
267
328
|
// one is still waiting for the typing to pause.
|
|
@@ -271,6 +332,13 @@ export class KoolbaseCollectionController {
|
|
|
271
332
|
}
|
|
272
333
|
}
|
|
273
334
|
catch (error) {
|
|
335
|
+
// The server refused the search: read unsearched, at once -- the
|
|
336
|
+
// generation this returns is that read's, so refresh() ends with it.
|
|
337
|
+
if (!this.isStale(gen) && isSearchRefusal(error) && this.serverSearch() !== null) {
|
|
338
|
+
this.searchRefused = true;
|
|
339
|
+
this.set({ searchError: null, searchLoadedOnly: true });
|
|
340
|
+
return this.firstPage(cache);
|
|
341
|
+
}
|
|
274
342
|
if (!this.isStale(gen) && this.state.searching && !this.searchTimer) {
|
|
275
343
|
this.set({ searching: false, searchError: error });
|
|
276
344
|
}
|
|
@@ -306,7 +374,7 @@ export class KoolbaseCollectionController {
|
|
|
306
374
|
offset,
|
|
307
375
|
orderBy: this.spec.orderBy,
|
|
308
376
|
orderDesc: this.spec.orderDesc,
|
|
309
|
-
...(this.
|
|
377
|
+
...(this.serverSearch() ? { fieldSearch: this.serverSearch() } : {}),
|
|
310
378
|
cache,
|
|
311
379
|
onRefresh,
|
|
312
380
|
};
|
|
@@ -134,6 +134,46 @@ export declare class KoolbaseFieldNotAutoEmbedError extends KoolbaseDataError {
|
|
|
134
134
|
export declare class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
|
|
135
135
|
constructor(message?: string);
|
|
136
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* The vector field is filled by automatic embedding: Koolbase makes its
|
|
139
|
+
* vectors from the record's fields, so the app cannot write one, delete one,
|
|
140
|
+
* or send text for it (a 409, `auto_embedding_managed`). Write the record's
|
|
141
|
+
* fields instead; the vector follows.
|
|
142
|
+
*/
|
|
143
|
+
export declare class KoolbaseAutoEmbeddingManagedError extends KoolbaseDataError {
|
|
144
|
+
constructor(message?: string);
|
|
145
|
+
}
|
|
146
|
+
/** What embedding a collection again costs, roughly (#162). */
|
|
147
|
+
export interface KoolbaseReembedEstimate {
|
|
148
|
+
records: number;
|
|
149
|
+
records_to_embed: number;
|
|
150
|
+
estimated_input_tokens: number;
|
|
151
|
+
provider: string;
|
|
152
|
+
model: string;
|
|
153
|
+
dimensions: number;
|
|
154
|
+
billed_by: string;
|
|
155
|
+
estimate: boolean;
|
|
156
|
+
cache_may_apply: boolean;
|
|
157
|
+
sampled_records: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A change to a vector field's embedding would embed the collection again,
|
|
161
|
+
* and was not confirmed (a 409, `reembed_confirmation_required`). `estimate`
|
|
162
|
+
* says what it would cost; send the change again with `confirm_reembed: true`
|
|
163
|
+
* to make it.
|
|
164
|
+
*/
|
|
165
|
+
export declare class KoolbaseReembedConfirmationRequiredError extends KoolbaseDataError {
|
|
166
|
+
readonly estimate?: KoolbaseReembedEstimate;
|
|
167
|
+
constructor(message?: string, estimate?: KoolbaseReembedEstimate);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The embedding model is not one Koolbase offers, has been shut down by its
|
|
171
|
+
* provider, or cannot store vectors of that size (a 400,
|
|
172
|
+
* `embedding_model_unsupported`).
|
|
173
|
+
*/
|
|
174
|
+
export declare class KoolbaseEmbeddingModelUnsupportedError extends KoolbaseDataError {
|
|
175
|
+
constructor(message?: string);
|
|
176
|
+
}
|
|
137
177
|
/**
|
|
138
178
|
* The project has no embedding provider configured. Embedding runs on the
|
|
139
179
|
* project's own Gemini or OpenAI key.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KoolbaseError, KoolbasePlanLimitError, KoolbaseUnauthenticatedError } from './errors.js';
|
|
1
|
+
import { KoolbaseError, KoolbasePlanLimitError, KoolbaseServiceUnavailableError, KoolbaseUnauthenticatedError } from './errors.js';
|
|
2
2
|
/**
|
|
3
3
|
* Base class for errors surfaced by the Koolbase data layer (database reads
|
|
4
4
|
* and writes). Every data error carries a `message` and, when the server
|
|
@@ -172,6 +172,45 @@ export class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
|
|
|
172
172
|
Object.setPrototypeOf(this, KoolbaseInvalidEmbeddingConfigError.prototype);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* The vector field is filled by automatic embedding: Koolbase makes its
|
|
177
|
+
* vectors from the record's fields, so the app cannot write one, delete one,
|
|
178
|
+
* or send text for it (a 409, `auto_embedding_managed`). Write the record's
|
|
179
|
+
* fields instead; the vector follows.
|
|
180
|
+
*/
|
|
181
|
+
export class KoolbaseAutoEmbeddingManagedError extends KoolbaseDataError {
|
|
182
|
+
constructor(message) {
|
|
183
|
+
super(message ?? 'This vector field is managed by automatic embedding and cannot be written manually.', 'auto_embedding_managed');
|
|
184
|
+
this.name = 'KoolbaseAutoEmbeddingManagedError';
|
|
185
|
+
Object.setPrototypeOf(this, KoolbaseAutoEmbeddingManagedError.prototype);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* A change to a vector field's embedding would embed the collection again,
|
|
190
|
+
* and was not confirmed (a 409, `reembed_confirmation_required`). `estimate`
|
|
191
|
+
* says what it would cost; send the change again with `confirm_reembed: true`
|
|
192
|
+
* to make it.
|
|
193
|
+
*/
|
|
194
|
+
export class KoolbaseReembedConfirmationRequiredError extends KoolbaseDataError {
|
|
195
|
+
constructor(message, estimate) {
|
|
196
|
+
super(message ?? 'This change embeds every record again; confirm it with confirm_reembed', 'reembed_confirmation_required');
|
|
197
|
+
this.estimate = estimate;
|
|
198
|
+
this.name = 'KoolbaseReembedConfirmationRequiredError';
|
|
199
|
+
Object.setPrototypeOf(this, KoolbaseReembedConfirmationRequiredError.prototype);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* The embedding model is not one Koolbase offers, has been shut down by its
|
|
204
|
+
* provider, or cannot store vectors of that size (a 400,
|
|
205
|
+
* `embedding_model_unsupported`).
|
|
206
|
+
*/
|
|
207
|
+
export class KoolbaseEmbeddingModelUnsupportedError extends KoolbaseDataError {
|
|
208
|
+
constructor(message) {
|
|
209
|
+
super(message ?? 'Embedding model not offered', 'embedding_model_unsupported');
|
|
210
|
+
this.name = 'KoolbaseEmbeddingModelUnsupportedError';
|
|
211
|
+
Object.setPrototypeOf(this, KoolbaseEmbeddingModelUnsupportedError.prototype);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
175
214
|
/**
|
|
176
215
|
* The project has no embedding provider configured. Embedding runs on the
|
|
177
216
|
* project's own Gemini or OpenAI key.
|
|
@@ -491,6 +530,14 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
491
530
|
return attach(new KoolbaseFieldNotAutoEmbedError(message));
|
|
492
531
|
case 'invalid_embedding_config':
|
|
493
532
|
return attach(new KoolbaseInvalidEmbeddingConfigError(message));
|
|
533
|
+
case 'auto_embedding_managed':
|
|
534
|
+
return attach(new KoolbaseAutoEmbeddingManagedError(message));
|
|
535
|
+
case 'reembed_confirmation_required':
|
|
536
|
+
return attach(new KoolbaseReembedConfirmationRequiredError(message, body?.details));
|
|
537
|
+
case 'embedding_model_unsupported':
|
|
538
|
+
return attach(new KoolbaseEmbeddingModelUnsupportedError(message));
|
|
539
|
+
case 'placement_unavailable':
|
|
540
|
+
return new KoolbaseServiceUnavailableError(message);
|
|
494
541
|
case 'provider_not_configured':
|
|
495
542
|
return attach(new KoolbaseProviderNotConfiguredError(message));
|
|
496
543
|
case 'provider_invalid':
|
package/dist/esm/database.d.ts
CHANGED
|
@@ -266,7 +266,9 @@ export declare class KoolbaseDatabase {
|
|
|
266
266
|
*
|
|
267
267
|
* The field must already be declared on the collection via the dashboard
|
|
268
268
|
* or CLI. `vector.length` must match the field's declared dimension;
|
|
269
|
-
* otherwise throws `KoolbaseVectorDimensionMismatchError`.
|
|
269
|
+
* otherwise throws `KoolbaseVectorDimensionMismatchError`. A field Koolbase
|
|
270
|
+
* embeds itself refuses it with `KoolbaseAutoEmbeddingManagedError`: write
|
|
271
|
+
* the record's fields instead.
|
|
270
272
|
*
|
|
271
273
|
* Online-only — vectors are not cached locally or queued offline because
|
|
272
274
|
* HNSW similarity search has no useful offline semantics.
|
package/dist/esm/database.js
CHANGED
|
@@ -915,7 +915,9 @@ export class KoolbaseDatabase {
|
|
|
915
915
|
*
|
|
916
916
|
* The field must already be declared on the collection via the dashboard
|
|
917
917
|
* or CLI. `vector.length` must match the field's declared dimension;
|
|
918
|
-
* otherwise throws `KoolbaseVectorDimensionMismatchError`.
|
|
918
|
+
* otherwise throws `KoolbaseVectorDimensionMismatchError`. A field Koolbase
|
|
919
|
+
* embeds itself refuses it with `KoolbaseAutoEmbeddingManagedError`: write
|
|
920
|
+
* the record's fields instead.
|
|
919
921
|
*
|
|
920
922
|
* Online-only — vectors are not cached locally or queued offline because
|
|
921
923
|
* HNSW similarity search has no useful offline semantics.
|
package/dist/esm/errors.d.ts
CHANGED
|
@@ -73,6 +73,19 @@ export declare class KoolbasePlanLimitError extends KoolbaseError {
|
|
|
73
73
|
readonly plan?: string | undefined;
|
|
74
74
|
constructor(message?: string, resource?: string | undefined, limit?: number | undefined, plan?: string | undefined);
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The project's database could not be reached just now, or which database it
|
|
78
|
+
* is could not be established (a 503, `placement_unavailable`). Koolbase never
|
|
79
|
+
* answers from another database in its place, so nothing was read or written:
|
|
80
|
+
* try again shortly.
|
|
81
|
+
*
|
|
82
|
+
* Shared: any request to the project -- a query, an upload, a sign-in -- can
|
|
83
|
+
* meet it.
|
|
84
|
+
*/
|
|
85
|
+
export declare class KoolbaseServiceUnavailableError extends KoolbaseError {
|
|
86
|
+
readonly retryable = true;
|
|
87
|
+
constructor(message?: string);
|
|
88
|
+
}
|
|
76
89
|
export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
77
90
|
constructor(message: string);
|
|
78
91
|
}
|
package/dist/esm/errors.js
CHANGED
|
@@ -88,6 +88,23 @@ export class KoolbasePlanLimitError extends KoolbaseError {
|
|
|
88
88
|
Object.setPrototypeOf(this, KoolbasePlanLimitError.prototype);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* The project's database could not be reached just now, or which database it
|
|
93
|
+
* is could not be established (a 503, `placement_unavailable`). Koolbase never
|
|
94
|
+
* answers from another database in its place, so nothing was read or written:
|
|
95
|
+
* try again shortly.
|
|
96
|
+
*
|
|
97
|
+
* Shared: any request to the project -- a query, an upload, a sign-in -- can
|
|
98
|
+
* meet it.
|
|
99
|
+
*/
|
|
100
|
+
export class KoolbaseServiceUnavailableError extends KoolbaseError {
|
|
101
|
+
constructor(message) {
|
|
102
|
+
super(message ?? "This project's database is temporarily unavailable. Please try again.", 'placement_unavailable');
|
|
103
|
+
this.retryable = true;
|
|
104
|
+
this.name = 'KoolbaseServiceUnavailableError';
|
|
105
|
+
Object.setPrototypeOf(this, KoolbaseServiceUnavailableError.prototype);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
91
108
|
export class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
92
109
|
constructor(message) {
|
|
93
110
|
super(message, 'offline_baseline_unavailable');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KoolbaseError, KoolbasePlanLimitError, KoolbaseUnauthenticatedError } from './errors.js';
|
|
1
|
+
import { KoolbaseError, KoolbasePlanLimitError, KoolbaseServiceUnavailableError, KoolbaseUnauthenticatedError } from './errors.js';
|
|
2
2
|
/**
|
|
3
3
|
* Base error type for all Koolbase storage errors. Catchable via
|
|
4
4
|
* `instanceof KoolbaseStorageError` to handle any storage-related failure
|
|
@@ -388,6 +388,8 @@ export function koolbaseStorageError(status, body, fallbackMessage = 'Storage re
|
|
|
388
388
|
const d = (body?.details ?? {});
|
|
389
389
|
return new KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
|
|
390
390
|
}
|
|
391
|
+
case 'placement_unavailable':
|
|
392
|
+
return new KoolbaseServiceUnavailableError(message);
|
|
391
393
|
case 'quota_exceeded':
|
|
392
394
|
return new KoolbaseStorageQuotaError(message);
|
|
393
395
|
case 'upload_expired':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.29.0",
|
|
4
4
|
"description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|