@koolbase/core 11.1.0 → 11.3.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-errors.d.ts +23 -0
- package/dist/cjs/auth-errors.js +39 -1
- package/dist/cjs/auth.js +16 -10
- package/dist/cjs/database-errors.d.ts +175 -2
- package/dist/cjs/database-errors.js +336 -8
- package/dist/cjs/errors.d.ts +14 -0
- package/dist/cjs/errors.js +20 -1
- package/dist/cjs/function-errors.d.ts +19 -0
- package/dist/cjs/function-errors.js +35 -1
- package/dist/cjs/storage-errors.d.ts +28 -0
- package/dist/cjs/storage-errors.js +54 -1
- package/dist/esm/auth-errors.d.ts +23 -0
- package/dist/esm/auth-errors.js +35 -0
- package/dist/esm/auth.js +17 -11
- package/dist/esm/database-errors.d.ts +175 -2
- package/dist/esm/database-errors.js +316 -8
- package/dist/esm/errors.d.ts +14 -0
- package/dist/esm/errors.js +18 -0
- package/dist/esm/function-errors.d.ts +19 -0
- package/dist/esm/function-errors.js +32 -0
- package/dist/esm/storage-errors.d.ts +28 -0
- package/dist/esm/storage-errors.js +51 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = exports.KoolbaseConflictError = exports.KoolbaseDataError = void 0;
|
|
3
|
+
exports.KoolbaseVectorDimensionMismatchError = exports.KoolbaseRateLimitError = exports.KoolbasePermissionError = exports.KoolbaseInsufficientAuthorityError = exports.KoolbaseValidationError = exports.KoolbaseNotFoundError = 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;
|
|
4
4
|
exports.koolbaseDataError = koolbaseDataError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -44,6 +44,250 @@ exports.KoolbaseDataError = KoolbaseDataError;
|
|
|
44
44
|
* }
|
|
45
45
|
* }
|
|
46
46
|
*/
|
|
47
|
+
/**
|
|
48
|
+
* An upsert whose filter matched more than one record.
|
|
49
|
+
*
|
|
50
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
51
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
52
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
53
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* The record changed between reading it and writing it.
|
|
57
|
+
*
|
|
58
|
+
* Optimistic concurrency: a write carrying a revision is refused when the
|
|
59
|
+
* server has moved on, rather than overwriting whatever happened in between.
|
|
60
|
+
* The refusal carries the server's current record and both revisions, so
|
|
61
|
+
* resolving needs no second fetch — and cannot race one.
|
|
62
|
+
*
|
|
63
|
+
* Distinct from KoolbaseConflict, which models a queued OFFLINE write and
|
|
64
|
+
* carries a baseline as well, because a change composed hours ago needs its
|
|
65
|
+
* original context to be resolvable. Here the caller still has their data in
|
|
66
|
+
* hand.
|
|
67
|
+
*
|
|
68
|
+
* Until 11.3.0 this arrived as a generic data error and the details had to be
|
|
69
|
+
* dug out of an untyped bag — the information the server went to the trouble
|
|
70
|
+
* of attaching, unreachable in practice.
|
|
71
|
+
*/
|
|
72
|
+
/** A vector field with that name already exists on the collection. */
|
|
73
|
+
/**
|
|
74
|
+
* A seed or import operation was refused. The code says which stage:
|
|
75
|
+
* invalid_seed_file (the file itself, with a "problems" list in details),
|
|
76
|
+
* seed_key_not_unique (the key does not identify rows uniquely),
|
|
77
|
+
* seed_needs_decision (conflicts need a choice before proceeding), or
|
|
78
|
+
* seed_conflicts_require_force (overwriting would discard the target's
|
|
79
|
+
* version of rows that changed on both sides — details carry the rows).
|
|
80
|
+
*
|
|
81
|
+
* One class with the code distinguishing them, rather than four: these are
|
|
82
|
+
* dashboard and CLI operations, and a caller handling one handles them the
|
|
83
|
+
* same way — show the reason and let a human decide.
|
|
84
|
+
*/
|
|
85
|
+
class KoolbaseSeedError extends KoolbaseDataError {
|
|
86
|
+
constructor(message, code) {
|
|
87
|
+
super(message, code);
|
|
88
|
+
this.name = 'KoolbaseSeedError';
|
|
89
|
+
Object.setPrototypeOf(this, KoolbaseSeedError.prototype);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.KoolbaseSeedError = KoolbaseSeedError;
|
|
93
|
+
/** A project slug that another project already holds. */
|
|
94
|
+
class KoolbaseSlugTakenError extends KoolbaseDataError {
|
|
95
|
+
constructor(message) {
|
|
96
|
+
super(message ?? 'A project with this slug already exists', 'slug_taken');
|
|
97
|
+
this.name = 'KoolbaseSlugTakenError';
|
|
98
|
+
Object.setPrototypeOf(this, KoolbaseSlugTakenError.prototype);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.KoolbaseSlugTakenError = KoolbaseSlugTakenError;
|
|
102
|
+
/** An invitation that has been revoked or has expired. */
|
|
103
|
+
class KoolbaseInvitationInvalidError extends KoolbaseDataError {
|
|
104
|
+
constructor(message) {
|
|
105
|
+
super(message ?? 'This invitation has been revoked or expired', 'invitation_invalid');
|
|
106
|
+
this.name = 'KoolbaseInvitationInvalidError';
|
|
107
|
+
Object.setPrototypeOf(this, KoolbaseInvitationInvalidError.prototype);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.KoolbaseInvitationInvalidError = KoolbaseInvitationInvalidError;
|
|
111
|
+
/** The project id in the request is not valid. */
|
|
112
|
+
class KoolbaseProjectInvalidError extends KoolbaseDataError {
|
|
113
|
+
constructor(message) {
|
|
114
|
+
super(message ?? 'Invalid project id', 'project_invalid');
|
|
115
|
+
this.name = 'KoolbaseProjectInvalidError';
|
|
116
|
+
Object.setPrototypeOf(this, KoolbaseProjectInvalidError.prototype);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.KoolbaseProjectInvalidError = KoolbaseProjectInvalidError;
|
|
120
|
+
/** The request body could not be decoded. */
|
|
121
|
+
class KoolbaseInvalidBodyError extends KoolbaseDataError {
|
|
122
|
+
constructor(message) {
|
|
123
|
+
super(message ?? 'Could not decode the request body', 'invalid_body');
|
|
124
|
+
this.name = 'KoolbaseInvalidBodyError';
|
|
125
|
+
Object.setPrototypeOf(this, KoolbaseInvalidBodyError.prototype);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.KoolbaseInvalidBodyError = KoolbaseInvalidBodyError;
|
|
129
|
+
/**
|
|
130
|
+
* The request asked for no change — an update with nothing to update.
|
|
131
|
+
*/
|
|
132
|
+
class KoolbaseNoChangesError extends KoolbaseDataError {
|
|
133
|
+
constructor(message) {
|
|
134
|
+
super(message ?? 'The request contains no changes', 'no_changes');
|
|
135
|
+
this.name = 'KoolbaseNoChangesError';
|
|
136
|
+
Object.setPrototypeOf(this, KoolbaseNoChangesError.prototype);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.KoolbaseNoChangesError = KoolbaseNoChangesError;
|
|
140
|
+
/**
|
|
141
|
+
* Something already exists, or something is in the wrong state, where the
|
|
142
|
+
* server did not say more than that.
|
|
143
|
+
*
|
|
144
|
+
* Carries whichever generic code arrived — conflict, duplicate,
|
|
145
|
+
* state_conflict — rather than four classes for codes that differ only in
|
|
146
|
+
* spelling. A caller who needs to branch finely is being underserved by the
|
|
147
|
+
* server, not by this.
|
|
148
|
+
*/
|
|
149
|
+
class KoolbaseStateConflictError extends KoolbaseDataError {
|
|
150
|
+
constructor(message, code) {
|
|
151
|
+
super(message, code);
|
|
152
|
+
this.name = 'KoolbaseStateConflictError';
|
|
153
|
+
Object.setPrototypeOf(this, KoolbaseStateConflictError.prototype);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.KoolbaseStateConflictError = KoolbaseStateConflictError;
|
|
157
|
+
class KoolbaseVectorFieldExistsError extends KoolbaseDataError {
|
|
158
|
+
constructor(message) {
|
|
159
|
+
super(message ?? 'A vector field with that name already exists on this collection', 'vector_field_exists');
|
|
160
|
+
this.name = 'KoolbaseVectorFieldExistsError';
|
|
161
|
+
Object.setPrototypeOf(this, KoolbaseVectorFieldExistsError.prototype);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.KoolbaseVectorFieldExistsError = KoolbaseVectorFieldExistsError;
|
|
165
|
+
/**
|
|
166
|
+
* A backfill was asked for on a field that embeds nothing automatically.
|
|
167
|
+
* Set provider, model and source_field on the field first.
|
|
168
|
+
*/
|
|
169
|
+
class KoolbaseFieldNotAutoEmbedError extends KoolbaseDataError {
|
|
170
|
+
constructor(message) {
|
|
171
|
+
super(message ?? 'This vector field has no auto-embedding config; set provider, model and source_field first', 'field_not_auto_embed');
|
|
172
|
+
this.name = 'KoolbaseFieldNotAutoEmbedError';
|
|
173
|
+
Object.setPrototypeOf(this, KoolbaseFieldNotAutoEmbedError.prototype);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.KoolbaseFieldNotAutoEmbedError = KoolbaseFieldNotAutoEmbedError;
|
|
177
|
+
/**
|
|
178
|
+
* Embedding config is partial. Provider, model and source_field are set
|
|
179
|
+
* together or cleared together — half a configuration is refused rather than
|
|
180
|
+
* half-applied, which would embed against a model nobody chose.
|
|
181
|
+
*/
|
|
182
|
+
class KoolbaseInvalidEmbeddingConfigError extends KoolbaseDataError {
|
|
183
|
+
constructor(message) {
|
|
184
|
+
super(message ?? 'Embedding config requires provider, model and source_field together, or all cleared', 'invalid_embedding_config');
|
|
185
|
+
this.name = 'KoolbaseInvalidEmbeddingConfigError';
|
|
186
|
+
Object.setPrototypeOf(this, KoolbaseInvalidEmbeddingConfigError.prototype);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.KoolbaseInvalidEmbeddingConfigError = KoolbaseInvalidEmbeddingConfigError;
|
|
190
|
+
/**
|
|
191
|
+
* The project has no embedding provider configured. Embedding runs on the
|
|
192
|
+
* project's own Gemini or OpenAI key.
|
|
193
|
+
*/
|
|
194
|
+
class KoolbaseProviderNotConfiguredError extends KoolbaseDataError {
|
|
195
|
+
constructor(message) {
|
|
196
|
+
super(message ?? 'No embedding provider is configured for this project', 'provider_not_configured');
|
|
197
|
+
this.name = 'KoolbaseProviderNotConfiguredError';
|
|
198
|
+
Object.setPrototypeOf(this, KoolbaseProviderNotConfiguredError.prototype);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.KoolbaseProviderNotConfiguredError = KoolbaseProviderNotConfiguredError;
|
|
202
|
+
/** The configured provider's credentials were rejected by the provider. */
|
|
203
|
+
class KoolbaseProviderInvalidError extends KoolbaseDataError {
|
|
204
|
+
constructor(message) {
|
|
205
|
+
super(message ?? 'The embedding provider credentials are not valid', 'provider_invalid');
|
|
206
|
+
this.name = 'KoolbaseProviderInvalidError';
|
|
207
|
+
Object.setPrototypeOf(this, KoolbaseProviderInvalidError.prototype);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.KoolbaseProviderInvalidError = KoolbaseProviderInvalidError;
|
|
211
|
+
class KoolbaseRevisionMismatchError extends KoolbaseDataError {
|
|
212
|
+
constructor(message, expectedRevision, currentRevision,
|
|
213
|
+
/** The record as the server holds it now. */
|
|
214
|
+
current) {
|
|
215
|
+
super(message ?? 'The record has changed since you read it', 'revision_mismatch');
|
|
216
|
+
this.expectedRevision = expectedRevision;
|
|
217
|
+
this.currentRevision = currentRevision;
|
|
218
|
+
this.current = current;
|
|
219
|
+
this.name = 'KoolbaseRevisionMismatchError';
|
|
220
|
+
Object.setPrototypeOf(this, KoolbaseRevisionMismatchError.prototype);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.KoolbaseRevisionMismatchError = KoolbaseRevisionMismatchError;
|
|
224
|
+
/**
|
|
225
|
+
* The same idempotency key sent with different data.
|
|
226
|
+
*
|
|
227
|
+
* Refused rather than replayed: the two requests do not agree, so neither
|
|
228
|
+
* answer is safe. Usually a key reused by accident across two operations.
|
|
229
|
+
*/
|
|
230
|
+
class KoolbaseIdempotencyKeyReusedError extends KoolbaseDataError {
|
|
231
|
+
/**
|
|
232
|
+
* Carries its code: the database package calls this idempotency_key_reused
|
|
233
|
+
* and fiscal calls it idempotency_conflict, and an error reporting a code
|
|
234
|
+
* the server did not send is a small lie that apps branching on e.code act
|
|
235
|
+
* on.
|
|
236
|
+
*/
|
|
237
|
+
constructor(message, code = 'idempotency_key_reused') {
|
|
238
|
+
super(message ?? 'Idempotency key reused with different data', code);
|
|
239
|
+
this.name = 'KoolbaseIdempotencyKeyReusedError';
|
|
240
|
+
Object.setPrototypeOf(this, KoolbaseIdempotencyKeyReusedError.prototype);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.KoolbaseIdempotencyKeyReusedError = KoolbaseIdempotencyKeyReusedError;
|
|
244
|
+
/** A batch write failed for a reason the server did not classify further. */
|
|
245
|
+
class KoolbaseBatchFailedError extends KoolbaseDataError {
|
|
246
|
+
constructor(message) {
|
|
247
|
+
super(message ?? 'The batch write failed', 'batch_failed');
|
|
248
|
+
this.name = 'KoolbaseBatchFailedError';
|
|
249
|
+
Object.setPrototypeOf(this, KoolbaseBatchFailedError.prototype);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
exports.KoolbaseBatchFailedError = KoolbaseBatchFailedError;
|
|
253
|
+
/**
|
|
254
|
+
* Creating a unique constraint over data that already breaks it. details
|
|
255
|
+
* carry the offending values, so they can be shown rather than hunted for.
|
|
256
|
+
*/
|
|
257
|
+
class KoolbaseDuplicateValuesError extends KoolbaseDataError {
|
|
258
|
+
constructor(message) {
|
|
259
|
+
super(message ?? 'The collection has duplicate values for these fields', 'duplicate_values');
|
|
260
|
+
this.name = 'KoolbaseDuplicateValuesError';
|
|
261
|
+
Object.setPrototypeOf(this, KoolbaseDuplicateValuesError.prototype);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
exports.KoolbaseDuplicateValuesError = KoolbaseDuplicateValuesError;
|
|
265
|
+
class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
266
|
+
constructor(message) {
|
|
267
|
+
super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
|
|
268
|
+
this.name = 'KoolbaseAmbiguousMatchError';
|
|
269
|
+
Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.KoolbaseAmbiguousMatchError = KoolbaseAmbiguousMatchError;
|
|
273
|
+
/** A unique constraint already covers those fields. */
|
|
274
|
+
class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
275
|
+
constructor(message) {
|
|
276
|
+
super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
|
|
277
|
+
this.name = 'KoolbaseConstraintExistsError';
|
|
278
|
+
Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
exports.KoolbaseConstraintExistsError = KoolbaseConstraintExistsError;
|
|
282
|
+
/** No such unique constraint. */
|
|
283
|
+
class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
284
|
+
constructor(message) {
|
|
285
|
+
super(message ?? 'Unique constraint not found', 'constraint_not_found');
|
|
286
|
+
this.name = 'KoolbaseConstraintNotFoundError';
|
|
287
|
+
Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.KoolbaseConstraintNotFoundError = KoolbaseConstraintNotFoundError;
|
|
47
291
|
class KoolbaseConflictError extends KoolbaseDataError {
|
|
48
292
|
constructor(message, field) {
|
|
49
293
|
super(message ?? 'Value violates a unique constraint', 'unique_violation');
|
|
@@ -59,8 +303,15 @@ exports.KoolbaseConflictError = KoolbaseConflictError;
|
|
|
59
303
|
* `collection_not_found`.
|
|
60
304
|
*/
|
|
61
305
|
class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
62
|
-
|
|
63
|
-
|
|
306
|
+
/**
|
|
307
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
308
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
309
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
310
|
+
* the class still works for anyone who only cares that something was
|
|
311
|
+
* absent.
|
|
312
|
+
*/
|
|
313
|
+
constructor(message, code = 'not_found') {
|
|
314
|
+
super(message ?? 'The requested resource was not found', code);
|
|
64
315
|
this.name = 'KoolbaseNotFoundError';
|
|
65
316
|
Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
|
|
66
317
|
}
|
|
@@ -71,8 +322,14 @@ exports.KoolbaseNotFoundError = KoolbaseNotFoundError;
|
|
|
71
322
|
* 400 and code `validation_error`.
|
|
72
323
|
*/
|
|
73
324
|
class KoolbaseValidationError extends KoolbaseDataError {
|
|
74
|
-
|
|
75
|
-
|
|
325
|
+
/**
|
|
326
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
327
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
328
|
+
* collection are both validation failures, and an app should still be able
|
|
329
|
+
* to tell which without reading the message.
|
|
330
|
+
*/
|
|
331
|
+
constructor(message, code = 'validation_error') {
|
|
332
|
+
super(message ?? 'The request was invalid', code);
|
|
76
333
|
this.name = 'KoolbaseValidationError';
|
|
77
334
|
Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
|
|
78
335
|
}
|
|
@@ -83,6 +340,21 @@ exports.KoolbaseValidationError = KoolbaseValidationError;
|
|
|
83
340
|
* operation — the server responds with 403 and code `permission_denied`
|
|
84
341
|
* (typically a collection access rule rejecting the read/write).
|
|
85
342
|
*/
|
|
343
|
+
/**
|
|
344
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
345
|
+
* access to a record. Its own class rather than folding into
|
|
346
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
347
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
348
|
+
* branch on e.code rather than instanceof would act on it.
|
|
349
|
+
*/
|
|
350
|
+
class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
351
|
+
constructor(message) {
|
|
352
|
+
super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
|
|
353
|
+
this.name = 'KoolbaseInsufficientAuthorityError';
|
|
354
|
+
Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
exports.KoolbaseInsufficientAuthorityError = KoolbaseInsufficientAuthorityError;
|
|
86
358
|
class KoolbasePermissionError extends KoolbaseDataError {
|
|
87
359
|
constructor(message) {
|
|
88
360
|
super(message ?? 'You do not have permission to perform this action', 'permission_denied');
|
|
@@ -155,14 +427,70 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
155
427
|
switch (code) {
|
|
156
428
|
case 'unique_violation':
|
|
157
429
|
return attach(new KoolbaseConflictError(message, field));
|
|
430
|
+
case 'plan_limit_reached': {
|
|
431
|
+
const d = (body?.details ?? {});
|
|
432
|
+
return new errors_js_1.KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
|
|
433
|
+
}
|
|
434
|
+
case 'invalid_seed_file':
|
|
435
|
+
case 'seed_key_not_unique':
|
|
436
|
+
case 'seed_needs_decision':
|
|
437
|
+
case 'seed_conflicts_require_force':
|
|
438
|
+
return attach(new KoolbaseSeedError(message, code));
|
|
439
|
+
case 'slug_taken':
|
|
440
|
+
return attach(new KoolbaseSlugTakenError(message));
|
|
441
|
+
case 'invitation_invalid':
|
|
442
|
+
return attach(new KoolbaseInvitationInvalidError(message));
|
|
443
|
+
case 'project_invalid':
|
|
444
|
+
return attach(new KoolbaseProjectInvalidError(message));
|
|
445
|
+
case 'invalid_body':
|
|
446
|
+
return attach(new KoolbaseInvalidBodyError(message));
|
|
447
|
+
case 'no_changes':
|
|
448
|
+
return attach(new KoolbaseNoChangesError(message));
|
|
449
|
+
case 'conflict':
|
|
450
|
+
case 'duplicate':
|
|
451
|
+
case 'state_conflict':
|
|
452
|
+
return attach(new KoolbaseStateConflictError(message, code));
|
|
453
|
+
case 'vector_field_exists':
|
|
454
|
+
return attach(new KoolbaseVectorFieldExistsError(message));
|
|
455
|
+
case 'field_not_auto_embed':
|
|
456
|
+
return attach(new KoolbaseFieldNotAutoEmbedError(message));
|
|
457
|
+
case 'invalid_embedding_config':
|
|
458
|
+
return attach(new KoolbaseInvalidEmbeddingConfigError(message));
|
|
459
|
+
case 'provider_not_configured':
|
|
460
|
+
return attach(new KoolbaseProviderNotConfiguredError(message));
|
|
461
|
+
case 'provider_invalid':
|
|
462
|
+
return attach(new KoolbaseProviderInvalidError(message));
|
|
463
|
+
case 'revision_mismatch': {
|
|
464
|
+
// The typed fields come off details, which the server attaches for
|
|
465
|
+
// exactly this. attach() still puts the whole bag on the error, so
|
|
466
|
+
// nothing is lost for a caller reading it directly.
|
|
467
|
+
const d = (body?.details ?? {});
|
|
468
|
+
return attach(new KoolbaseRevisionMismatchError(message, d.expected_revision, d.current_revision, d.record));
|
|
469
|
+
}
|
|
470
|
+
// Two codes, one situation — the database and fiscal packages name it
|
|
471
|
+
// differently and a caller should not have to know which spoke.
|
|
472
|
+
case 'idempotency_key_reused':
|
|
473
|
+
case 'idempotency_conflict':
|
|
474
|
+
return attach(new KoolbaseIdempotencyKeyReusedError(message, code));
|
|
475
|
+
case 'batch_failed':
|
|
476
|
+
return attach(new KoolbaseBatchFailedError(message));
|
|
477
|
+
case 'duplicate_values':
|
|
478
|
+
return attach(new KoolbaseDuplicateValuesError(message));
|
|
479
|
+
case 'ambiguous_match':
|
|
480
|
+
return attach(new KoolbaseAmbiguousMatchError(message));
|
|
481
|
+
case 'constraint_exists':
|
|
482
|
+
return attach(new KoolbaseConstraintExistsError(message));
|
|
483
|
+
case 'constraint_not_found':
|
|
484
|
+
return attach(new KoolbaseConstraintNotFoundError(message));
|
|
485
|
+
case 'insufficient_authority':
|
|
486
|
+
return attach(new KoolbaseInsufficientAuthorityError(message));
|
|
158
487
|
case 'not_found':
|
|
159
488
|
case 'record_not_found':
|
|
160
489
|
case 'collection_not_found':
|
|
161
490
|
case 'vector_not_found':
|
|
162
491
|
case 'vector_field_not_found':
|
|
163
|
-
return attach(new KoolbaseNotFoundError(message));
|
|
492
|
+
return attach(new KoolbaseNotFoundError(message, code));
|
|
164
493
|
case 'unauthenticated':
|
|
165
|
-
case 'session_expired':
|
|
166
494
|
case 'invalid_token':
|
|
167
495
|
return attach(new errors_js_1.KoolbaseUnauthenticatedError(message));
|
|
168
496
|
case 'permission_denied':
|
|
@@ -172,7 +500,7 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
172
500
|
case 'validation_error':
|
|
173
501
|
case 'vector_collection_mismatch':
|
|
174
502
|
case 'unsupported_dimension':
|
|
175
|
-
return attach(new KoolbaseValidationError(message));
|
|
503
|
+
return attach(new KoolbaseValidationError(message, code));
|
|
176
504
|
case 'vector_dimension_mismatch':
|
|
177
505
|
return attach(new KoolbaseVectorDimensionMismatchError(message));
|
|
178
506
|
}
|
package/dist/cjs/errors.d.ts
CHANGED
|
@@ -59,6 +59,20 @@ export declare class KoolbaseUnauthenticatedError extends KoolbaseError {
|
|
|
59
59
|
* updates are conflict-safe and some quietly are not, which is a worse guarantee
|
|
60
60
|
* than a clear refusal.
|
|
61
61
|
*/
|
|
62
|
+
/**
|
|
63
|
+
* The project's plan does not allow this — a 402 carrying which resource, the
|
|
64
|
+
* limit, and the plan.
|
|
65
|
+
*
|
|
66
|
+
* Shared rather than per-domain: creating a collection, uploading an object
|
|
67
|
+
* and deploying a function can all hit it, and an app showing an upgrade
|
|
68
|
+
* prompt wants one type to catch.
|
|
69
|
+
*/
|
|
70
|
+
export declare class KoolbasePlanLimitError extends KoolbaseError {
|
|
71
|
+
readonly resource?: string | undefined;
|
|
72
|
+
readonly limit?: number | undefined;
|
|
73
|
+
readonly plan?: string | undefined;
|
|
74
|
+
constructor(message?: string, resource?: string | undefined, limit?: number | undefined, plan?: string | undefined);
|
|
75
|
+
}
|
|
62
76
|
export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
63
77
|
constructor(message: string);
|
|
64
78
|
}
|
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.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
|
|
3
|
+
exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The root of every error the SDK raises.
|
|
6
6
|
*
|
|
@@ -75,6 +75,25 @@ exports.KoolbaseUnauthenticatedError = KoolbaseUnauthenticatedError;
|
|
|
75
75
|
* updates are conflict-safe and some quietly are not, which is a worse guarantee
|
|
76
76
|
* than a clear refusal.
|
|
77
77
|
*/
|
|
78
|
+
/**
|
|
79
|
+
* The project's plan does not allow this — a 402 carrying which resource, the
|
|
80
|
+
* limit, and the plan.
|
|
81
|
+
*
|
|
82
|
+
* Shared rather than per-domain: creating a collection, uploading an object
|
|
83
|
+
* and deploying a function can all hit it, and an app showing an upgrade
|
|
84
|
+
* prompt wants one type to catch.
|
|
85
|
+
*/
|
|
86
|
+
class KoolbasePlanLimitError extends KoolbaseError {
|
|
87
|
+
constructor(message, resource, limit, plan) {
|
|
88
|
+
super(message ?? 'This exceeds your plan limit', 'plan_limit_reached');
|
|
89
|
+
this.resource = resource;
|
|
90
|
+
this.limit = limit;
|
|
91
|
+
this.plan = plan;
|
|
92
|
+
this.name = 'KoolbasePlanLimitError';
|
|
93
|
+
Object.setPrototypeOf(this, KoolbasePlanLimitError.prototype);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.KoolbasePlanLimitError = KoolbasePlanLimitError;
|
|
78
97
|
class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
|
|
79
98
|
constructor(message) {
|
|
80
99
|
super(message, 'offline_baseline_unavailable');
|
|
@@ -47,5 +47,24 @@ export declare class FunctionQuotaExceededError extends FunctionInvokeError {
|
|
|
47
47
|
export declare class FunctionExecutionError extends FunctionInvokeError {
|
|
48
48
|
constructor(message: string, statusCode?: number);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* The function ran past its timeout and was killed.
|
|
52
|
+
*
|
|
53
|
+
* Its own type because the remedy is different from a function that threw:
|
|
54
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
55
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
56
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
57
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
58
|
+
*/
|
|
59
|
+
export declare class FunctionTimeoutError extends FunctionInvokeError {
|
|
60
|
+
constructor(message: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
64
|
+
* clears by waiting.
|
|
65
|
+
*/
|
|
66
|
+
export declare class FunctionRateLimitError extends FunctionInvokeError {
|
|
67
|
+
constructor(message: string);
|
|
68
|
+
}
|
|
50
69
|
/** Builds the right error for a failed invocation. */
|
|
51
70
|
export declare function functionInvokeError(status: number, message: string): KoolbaseError;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionExecutionError = exports.FunctionQuotaExceededError = exports.FunctionValidationError = exports.FunctionPermissionError = exports.FunctionNotFoundError = exports.FunctionInvokeError = void 0;
|
|
3
|
+
exports.FunctionRateLimitError = exports.FunctionTimeoutError = exports.FunctionExecutionError = exports.FunctionQuotaExceededError = exports.FunctionValidationError = exports.FunctionPermissionError = exports.FunctionNotFoundError = exports.FunctionInvokeError = void 0;
|
|
4
4
|
exports.functionInvokeError = functionInvokeError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -81,6 +81,35 @@ class FunctionExecutionError extends FunctionInvokeError {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
exports.FunctionExecutionError = FunctionExecutionError;
|
|
84
|
+
/**
|
|
85
|
+
* The function ran past its timeout and was killed.
|
|
86
|
+
*
|
|
87
|
+
* Its own type because the remedy is different from a function that threw:
|
|
88
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
89
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
90
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
91
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
92
|
+
*/
|
|
93
|
+
class FunctionTimeoutError extends FunctionInvokeError {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message, 504, 'timeout');
|
|
96
|
+
this.name = 'FunctionTimeoutError';
|
|
97
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.FunctionTimeoutError = FunctionTimeoutError;
|
|
101
|
+
/**
|
|
102
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
103
|
+
* clears by waiting.
|
|
104
|
+
*/
|
|
105
|
+
class FunctionRateLimitError extends FunctionInvokeError {
|
|
106
|
+
constructor(message) {
|
|
107
|
+
super(message, 429, 'rate_limit');
|
|
108
|
+
this.name = 'FunctionRateLimitError';
|
|
109
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.FunctionRateLimitError = FunctionRateLimitError;
|
|
84
113
|
/** Builds the right error for a failed invocation. */
|
|
85
114
|
function functionInvokeError(status, message) {
|
|
86
115
|
switch (status) {
|
|
@@ -96,6 +125,11 @@ function functionInvokeError(status, message) {
|
|
|
96
125
|
return new FunctionValidationError(message);
|
|
97
126
|
case 402:
|
|
98
127
|
return new FunctionQuotaExceededError(message);
|
|
128
|
+
case 429:
|
|
129
|
+
return new FunctionRateLimitError(message);
|
|
130
|
+
case 504:
|
|
131
|
+
// Before the generic 5xx branch: a timeout is not an exception.
|
|
132
|
+
return new FunctionTimeoutError(message);
|
|
99
133
|
}
|
|
100
134
|
if (status >= 500)
|
|
101
135
|
return new FunctionExecutionError(message, status);
|
|
@@ -76,6 +76,34 @@ export declare class KoolbaseStoragePermissionError extends KoolbaseStorageError
|
|
|
76
76
|
* 409 but means "path collides"); branch on the error type via
|
|
77
77
|
* `instanceof`, not on status.
|
|
78
78
|
*/
|
|
79
|
+
/**
|
|
80
|
+
* The presigned upload was confirmed after its window closed.
|
|
81
|
+
*
|
|
82
|
+
* An upload URL has a lifetime. A user who picks a file, gets distracted and
|
|
83
|
+
* comes back twenty minutes later hits this — so it is a retry, not a
|
|
84
|
+
* failure: presign again and send the same bytes. Worth catching rather than
|
|
85
|
+
* showing "upload failed" to someone whose file was fine.
|
|
86
|
+
*/
|
|
87
|
+
/**
|
|
88
|
+
* Minting a presigned upload URL failed. The message carries the underlying
|
|
89
|
+
* reason — a misconfigured bucket, or the object store refusing.
|
|
90
|
+
*
|
|
91
|
+
* Not the user's doing, and not a retry they can fix: distinct from
|
|
92
|
+
* KoolbaseUploadExpiredError, which is a retry that will work.
|
|
93
|
+
*/
|
|
94
|
+
export declare class KoolbaseUploadURLFailedError extends KoolbaseStorageError {
|
|
95
|
+
constructor(message?: string);
|
|
96
|
+
}
|
|
97
|
+
export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
98
|
+
constructor(message?: string);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
102
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
103
|
+
*/
|
|
104
|
+
export declare class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
105
|
+
constructor(message?: string);
|
|
106
|
+
}
|
|
79
107
|
export declare class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
80
108
|
constructor(message?: string);
|
|
81
109
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageError = void 0;
|
|
3
|
+
exports.KoolbaseStorageMetadataInvalidError = exports.KoolbaseStorageMimeTypeError = exports.KoolbaseStorageFileTooLargeError = exports.KoolbaseStorageQuotaError = exports.KoolbaseCapBelowUsageError = exports.KoolbaseUploadExpiredError = exports.KoolbaseUploadURLFailedError = exports.KoolbaseStoragePermissionError = exports.KoolbaseStorageValidationError = exports.KoolbaseStorageNotFoundError = exports.KoolbaseStorageConflictError = exports.KoolbaseStorageError = void 0;
|
|
4
4
|
exports.koolbaseStorageError = koolbaseStorageError;
|
|
5
5
|
exports.koolbaseStorageErrorFromResponse = koolbaseStorageErrorFromResponse;
|
|
6
6
|
const errors_js_1 = require("./errors.js");
|
|
@@ -106,6 +106,49 @@ exports.KoolbaseStoragePermissionError = KoolbaseStoragePermissionError;
|
|
|
106
106
|
* 409 but means "path collides"); branch on the error type via
|
|
107
107
|
* `instanceof`, not on status.
|
|
108
108
|
*/
|
|
109
|
+
/**
|
|
110
|
+
* The presigned upload was confirmed after its window closed.
|
|
111
|
+
*
|
|
112
|
+
* An upload URL has a lifetime. A user who picks a file, gets distracted and
|
|
113
|
+
* comes back twenty minutes later hits this — so it is a retry, not a
|
|
114
|
+
* failure: presign again and send the same bytes. Worth catching rather than
|
|
115
|
+
* showing "upload failed" to someone whose file was fine.
|
|
116
|
+
*/
|
|
117
|
+
/**
|
|
118
|
+
* Minting a presigned upload URL failed. The message carries the underlying
|
|
119
|
+
* reason — a misconfigured bucket, or the object store refusing.
|
|
120
|
+
*
|
|
121
|
+
* Not the user's doing, and not a retry they can fix: distinct from
|
|
122
|
+
* KoolbaseUploadExpiredError, which is a retry that will work.
|
|
123
|
+
*/
|
|
124
|
+
class KoolbaseUploadURLFailedError extends KoolbaseStorageError {
|
|
125
|
+
constructor(message) {
|
|
126
|
+
super(message ?? 'Could not create an upload URL', 'upload_url_failed');
|
|
127
|
+
this.name = 'KoolbaseUploadURLFailedError';
|
|
128
|
+
Object.setPrototypeOf(this, KoolbaseUploadURLFailedError.prototype);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.KoolbaseUploadURLFailedError = KoolbaseUploadURLFailedError;
|
|
132
|
+
class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
133
|
+
constructor(message) {
|
|
134
|
+
super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
|
|
135
|
+
this.name = 'KoolbaseUploadExpiredError';
|
|
136
|
+
Object.setPrototypeOf(this, KoolbaseUploadExpiredError.prototype);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.KoolbaseUploadExpiredError = KoolbaseUploadExpiredError;
|
|
140
|
+
/**
|
|
141
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
142
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
143
|
+
*/
|
|
144
|
+
class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
145
|
+
constructor(message) {
|
|
146
|
+
super(message ?? 'The cap is below the bucket\'s current usage', 'cap_below_usage');
|
|
147
|
+
this.name = 'KoolbaseCapBelowUsageError';
|
|
148
|
+
Object.setPrototypeOf(this, KoolbaseCapBelowUsageError.prototype);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.KoolbaseCapBelowUsageError = KoolbaseCapBelowUsageError;
|
|
109
152
|
class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
110
153
|
constructor(message) {
|
|
111
154
|
super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
|
|
@@ -207,14 +250,24 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
|
|
|
207
250
|
switch (code) {
|
|
208
251
|
case 'path_conflict':
|
|
209
252
|
return new KoolbaseStorageConflictError(message, body?.path);
|
|
253
|
+
case 'plan_limit_reached': {
|
|
254
|
+
const d = (body?.details ?? {});
|
|
255
|
+
return new errors_js_1.KoolbasePlanLimitError(message, d.resource, d.limit, d.plan);
|
|
256
|
+
}
|
|
210
257
|
case 'quota_exceeded':
|
|
211
258
|
return new KoolbaseStorageQuotaError(message);
|
|
259
|
+
case 'upload_expired':
|
|
260
|
+
return new KoolbaseUploadExpiredError(message);
|
|
261
|
+
case 'cap_below_usage':
|
|
262
|
+
return new KoolbaseCapBelowUsageError(message);
|
|
212
263
|
case 'file_too_large':
|
|
213
264
|
return new KoolbaseStorageFileTooLargeError(message);
|
|
214
265
|
case 'mime_not_allowed':
|
|
215
266
|
return new KoolbaseStorageMimeTypeError(message);
|
|
216
267
|
case 'metadata_invalid':
|
|
217
268
|
return new KoolbaseStorageMetadataInvalidError(message, body?.detail);
|
|
269
|
+
case 'upload_url_failed':
|
|
270
|
+
return new KoolbaseUploadURLFailedError(message);
|
|
218
271
|
}
|
|
219
272
|
// ─── status fallback (pre-code servers or uncoded paths) ───
|
|
220
273
|
switch (status) {
|