@koolbase/core 11.1.0 → 11.2.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/database-errors.d.ts +44 -2
- package/dist/cjs/database-errors.js +77 -7
- package/dist/cjs/function-errors.d.ts +19 -0
- package/dist/cjs/function-errors.js +35 -1
- package/dist/cjs/storage-errors.d.ts +18 -0
- package/dist/cjs/storage-errors.js +33 -1
- package/dist/esm/database-errors.d.ts +44 -2
- package/dist/esm/database-errors.js +72 -6
- package/dist/esm/function-errors.d.ts +19 -0
- package/dist/esm/function-errors.js +32 -0
- package/dist/esm/storage-errors.d.ts +18 -0
- package/dist/esm/storage-errors.js +30 -0
- package/package.json +1 -1
|
@@ -41,6 +41,25 @@ export declare class KoolbaseDataError extends KoolbaseError {
|
|
|
41
41
|
* }
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
|
+
/**
|
|
45
|
+
* An upsert whose filter matched more than one record.
|
|
46
|
+
*
|
|
47
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
48
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
49
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
50
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
51
|
+
*/
|
|
52
|
+
export declare class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
53
|
+
constructor(message?: string);
|
|
54
|
+
}
|
|
55
|
+
/** A unique constraint already covers those fields. */
|
|
56
|
+
export declare class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
/** No such unique constraint. */
|
|
60
|
+
export declare class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
61
|
+
constructor(message?: string);
|
|
62
|
+
}
|
|
44
63
|
export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
45
64
|
field?: string;
|
|
46
65
|
constructor(message?: string, field?: string);
|
|
@@ -51,20 +70,43 @@ export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
|
51
70
|
* `collection_not_found`.
|
|
52
71
|
*/
|
|
53
72
|
export declare class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
54
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
75
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
76
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
77
|
+
* the class still works for anyone who only cares that something was
|
|
78
|
+
* absent.
|
|
79
|
+
*/
|
|
80
|
+
constructor(message?: string, code?: string);
|
|
55
81
|
}
|
|
56
82
|
/**
|
|
57
83
|
* Thrown when the request is rejected as invalid — the server responds with
|
|
58
84
|
* 400 and code `validation_error`.
|
|
59
85
|
*/
|
|
60
86
|
export declare class KoolbaseValidationError extends KoolbaseDataError {
|
|
61
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
89
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
90
|
+
* collection are both validation failures, and an app should still be able
|
|
91
|
+
* to tell which without reading the message.
|
|
92
|
+
*/
|
|
93
|
+
constructor(message?: string, code?: string);
|
|
62
94
|
}
|
|
63
95
|
/**
|
|
64
96
|
* Thrown when the caller is authenticated but not allowed to perform the
|
|
65
97
|
* operation — the server responds with 403 and code `permission_denied`
|
|
66
98
|
* (typically a collection access rule rejecting the read/write).
|
|
67
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
102
|
+
* access to a record. Its own class rather than folding into
|
|
103
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
104
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
105
|
+
* branch on e.code rather than instanceof would act on it.
|
|
106
|
+
*/
|
|
107
|
+
export declare class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
108
|
+
constructor(message?: string);
|
|
109
|
+
}
|
|
68
110
|
export declare class KoolbasePermissionError extends KoolbaseDataError {
|
|
69
111
|
constructor(message?: string);
|
|
70
112
|
}
|
|
@@ -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.KoolbaseDataError = void 0;
|
|
4
4
|
exports.koolbaseDataError = koolbaseDataError;
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
/**
|
|
@@ -44,6 +44,40 @@ 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
|
+
class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
|
|
58
|
+
this.name = 'KoolbaseAmbiguousMatchError';
|
|
59
|
+
Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.KoolbaseAmbiguousMatchError = KoolbaseAmbiguousMatchError;
|
|
63
|
+
/** A unique constraint already covers those fields. */
|
|
64
|
+
class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
65
|
+
constructor(message) {
|
|
66
|
+
super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
|
|
67
|
+
this.name = 'KoolbaseConstraintExistsError';
|
|
68
|
+
Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.KoolbaseConstraintExistsError = KoolbaseConstraintExistsError;
|
|
72
|
+
/** No such unique constraint. */
|
|
73
|
+
class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message ?? 'Unique constraint not found', 'constraint_not_found');
|
|
76
|
+
this.name = 'KoolbaseConstraintNotFoundError';
|
|
77
|
+
Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.KoolbaseConstraintNotFoundError = KoolbaseConstraintNotFoundError;
|
|
47
81
|
class KoolbaseConflictError extends KoolbaseDataError {
|
|
48
82
|
constructor(message, field) {
|
|
49
83
|
super(message ?? 'Value violates a unique constraint', 'unique_violation');
|
|
@@ -59,8 +93,15 @@ exports.KoolbaseConflictError = KoolbaseConflictError;
|
|
|
59
93
|
* `collection_not_found`.
|
|
60
94
|
*/
|
|
61
95
|
class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
62
|
-
|
|
63
|
-
|
|
96
|
+
/**
|
|
97
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
98
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
99
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
100
|
+
* the class still works for anyone who only cares that something was
|
|
101
|
+
* absent.
|
|
102
|
+
*/
|
|
103
|
+
constructor(message, code = 'not_found') {
|
|
104
|
+
super(message ?? 'The requested resource was not found', code);
|
|
64
105
|
this.name = 'KoolbaseNotFoundError';
|
|
65
106
|
Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
|
|
66
107
|
}
|
|
@@ -71,8 +112,14 @@ exports.KoolbaseNotFoundError = KoolbaseNotFoundError;
|
|
|
71
112
|
* 400 and code `validation_error`.
|
|
72
113
|
*/
|
|
73
114
|
class KoolbaseValidationError extends KoolbaseDataError {
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
117
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
118
|
+
* collection are both validation failures, and an app should still be able
|
|
119
|
+
* to tell which without reading the message.
|
|
120
|
+
*/
|
|
121
|
+
constructor(message, code = 'validation_error') {
|
|
122
|
+
super(message ?? 'The request was invalid', code);
|
|
76
123
|
this.name = 'KoolbaseValidationError';
|
|
77
124
|
Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
|
|
78
125
|
}
|
|
@@ -83,6 +130,21 @@ exports.KoolbaseValidationError = KoolbaseValidationError;
|
|
|
83
130
|
* operation — the server responds with 403 and code `permission_denied`
|
|
84
131
|
* (typically a collection access rule rejecting the read/write).
|
|
85
132
|
*/
|
|
133
|
+
/**
|
|
134
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
135
|
+
* access to a record. Its own class rather than folding into
|
|
136
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
137
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
138
|
+
* branch on e.code rather than instanceof would act on it.
|
|
139
|
+
*/
|
|
140
|
+
class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
141
|
+
constructor(message) {
|
|
142
|
+
super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
|
|
143
|
+
this.name = 'KoolbaseInsufficientAuthorityError';
|
|
144
|
+
Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.KoolbaseInsufficientAuthorityError = KoolbaseInsufficientAuthorityError;
|
|
86
148
|
class KoolbasePermissionError extends KoolbaseDataError {
|
|
87
149
|
constructor(message) {
|
|
88
150
|
super(message ?? 'You do not have permission to perform this action', 'permission_denied');
|
|
@@ -155,12 +217,20 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
155
217
|
switch (code) {
|
|
156
218
|
case 'unique_violation':
|
|
157
219
|
return attach(new KoolbaseConflictError(message, field));
|
|
220
|
+
case 'ambiguous_match':
|
|
221
|
+
return attach(new KoolbaseAmbiguousMatchError(message));
|
|
222
|
+
case 'constraint_exists':
|
|
223
|
+
return attach(new KoolbaseConstraintExistsError(message));
|
|
224
|
+
case 'constraint_not_found':
|
|
225
|
+
return attach(new KoolbaseConstraintNotFoundError(message));
|
|
226
|
+
case 'insufficient_authority':
|
|
227
|
+
return attach(new KoolbaseInsufficientAuthorityError(message));
|
|
158
228
|
case 'not_found':
|
|
159
229
|
case 'record_not_found':
|
|
160
230
|
case 'collection_not_found':
|
|
161
231
|
case 'vector_not_found':
|
|
162
232
|
case 'vector_field_not_found':
|
|
163
|
-
return attach(new KoolbaseNotFoundError(message));
|
|
233
|
+
return attach(new KoolbaseNotFoundError(message, code));
|
|
164
234
|
case 'unauthenticated':
|
|
165
235
|
case 'session_expired':
|
|
166
236
|
case 'invalid_token':
|
|
@@ -172,7 +242,7 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
|
|
|
172
242
|
case 'validation_error':
|
|
173
243
|
case 'vector_collection_mismatch':
|
|
174
244
|
case 'unsupported_dimension':
|
|
175
|
-
return attach(new KoolbaseValidationError(message));
|
|
245
|
+
return attach(new KoolbaseValidationError(message, code));
|
|
176
246
|
case 'vector_dimension_mismatch':
|
|
177
247
|
return attach(new KoolbaseVectorDimensionMismatchError(message));
|
|
178
248
|
}
|
|
@@ -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,24 @@ 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
|
+
export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
88
|
+
constructor(message?: string);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
92
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
93
|
+
*/
|
|
94
|
+
export declare class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
95
|
+
constructor(message?: string);
|
|
96
|
+
}
|
|
79
97
|
export declare class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
80
98
|
constructor(message?: string);
|
|
81
99
|
}
|
|
@@ -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.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,34 @@ 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
|
+
class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
118
|
+
constructor(message) {
|
|
119
|
+
super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
|
|
120
|
+
this.name = 'KoolbaseUploadExpiredError';
|
|
121
|
+
Object.setPrototypeOf(this, KoolbaseUploadExpiredError.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.KoolbaseUploadExpiredError = KoolbaseUploadExpiredError;
|
|
125
|
+
/**
|
|
126
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
127
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
128
|
+
*/
|
|
129
|
+
class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message ?? 'The cap is below the bucket\'s current usage', 'cap_below_usage');
|
|
132
|
+
this.name = 'KoolbaseCapBelowUsageError';
|
|
133
|
+
Object.setPrototypeOf(this, KoolbaseCapBelowUsageError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.KoolbaseCapBelowUsageError = KoolbaseCapBelowUsageError;
|
|
109
137
|
class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
110
138
|
constructor(message) {
|
|
111
139
|
super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
|
|
@@ -209,6 +237,10 @@ function koolbaseStorageError(status, body, fallbackMessage = 'Storage request f
|
|
|
209
237
|
return new KoolbaseStorageConflictError(message, body?.path);
|
|
210
238
|
case 'quota_exceeded':
|
|
211
239
|
return new KoolbaseStorageQuotaError(message);
|
|
240
|
+
case 'upload_expired':
|
|
241
|
+
return new KoolbaseUploadExpiredError(message);
|
|
242
|
+
case 'cap_below_usage':
|
|
243
|
+
return new KoolbaseCapBelowUsageError(message);
|
|
212
244
|
case 'file_too_large':
|
|
213
245
|
return new KoolbaseStorageFileTooLargeError(message);
|
|
214
246
|
case 'mime_not_allowed':
|
|
@@ -41,6 +41,25 @@ export declare class KoolbaseDataError extends KoolbaseError {
|
|
|
41
41
|
* }
|
|
42
42
|
* }
|
|
43
43
|
*/
|
|
44
|
+
/**
|
|
45
|
+
* An upsert whose filter matched more than one record.
|
|
46
|
+
*
|
|
47
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
48
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
49
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
50
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
51
|
+
*/
|
|
52
|
+
export declare class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
53
|
+
constructor(message?: string);
|
|
54
|
+
}
|
|
55
|
+
/** A unique constraint already covers those fields. */
|
|
56
|
+
export declare class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
/** No such unique constraint. */
|
|
60
|
+
export declare class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
61
|
+
constructor(message?: string);
|
|
62
|
+
}
|
|
44
63
|
export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
45
64
|
field?: string;
|
|
46
65
|
constructor(message?: string, field?: string);
|
|
@@ -51,20 +70,43 @@ export declare class KoolbaseConflictError extends KoolbaseDataError {
|
|
|
51
70
|
* `collection_not_found`.
|
|
52
71
|
*/
|
|
53
72
|
export declare class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
54
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
75
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
76
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
77
|
+
* the class still works for anyone who only cares that something was
|
|
78
|
+
* absent.
|
|
79
|
+
*/
|
|
80
|
+
constructor(message?: string, code?: string);
|
|
55
81
|
}
|
|
56
82
|
/**
|
|
57
83
|
* Thrown when the request is rejected as invalid — the server responds with
|
|
58
84
|
* 400 and code `validation_error`.
|
|
59
85
|
*/
|
|
60
86
|
export declare class KoolbaseValidationError extends KoolbaseDataError {
|
|
61
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
89
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
90
|
+
* collection are both validation failures, and an app should still be able
|
|
91
|
+
* to tell which without reading the message.
|
|
92
|
+
*/
|
|
93
|
+
constructor(message?: string, code?: string);
|
|
62
94
|
}
|
|
63
95
|
/**
|
|
64
96
|
* Thrown when the caller is authenticated but not allowed to perform the
|
|
65
97
|
* operation — the server responds with 403 and code `permission_denied`
|
|
66
98
|
* (typically a collection access rule rejecting the read/write).
|
|
67
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
102
|
+
* access to a record. Its own class rather than folding into
|
|
103
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
104
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
105
|
+
* branch on e.code rather than instanceof would act on it.
|
|
106
|
+
*/
|
|
107
|
+
export declare class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
108
|
+
constructor(message?: string);
|
|
109
|
+
}
|
|
68
110
|
export declare class KoolbasePermissionError extends KoolbaseDataError {
|
|
69
111
|
constructor(message?: string);
|
|
70
112
|
}
|
|
@@ -39,6 +39,37 @@ export class KoolbaseDataError extends KoolbaseError {
|
|
|
39
39
|
* }
|
|
40
40
|
* }
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* An upsert whose filter matched more than one record.
|
|
44
|
+
*
|
|
45
|
+
* Refused rather than resolved: picking one of several would be a silent
|
|
46
|
+
* guess about which row the caller meant, and the wrong guess overwrites data
|
|
47
|
+
* nobody asked to change. Narrow the filter, or add a unique constraint over
|
|
48
|
+
* the fields you are matching on so the ambiguity cannot arise.
|
|
49
|
+
*/
|
|
50
|
+
export class KoolbaseAmbiguousMatchError extends KoolbaseDataError {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message ?? 'Upsert match resolved to more than one record', 'ambiguous_match');
|
|
53
|
+
this.name = 'KoolbaseAmbiguousMatchError';
|
|
54
|
+
Object.setPrototypeOf(this, KoolbaseAmbiguousMatchError.prototype);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** A unique constraint already covers those fields. */
|
|
58
|
+
export class KoolbaseConstraintExistsError extends KoolbaseDataError {
|
|
59
|
+
constructor(message) {
|
|
60
|
+
super(message ?? 'A unique constraint already exists for these fields', 'constraint_exists');
|
|
61
|
+
this.name = 'KoolbaseConstraintExistsError';
|
|
62
|
+
Object.setPrototypeOf(this, KoolbaseConstraintExistsError.prototype);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** No such unique constraint. */
|
|
66
|
+
export class KoolbaseConstraintNotFoundError extends KoolbaseDataError {
|
|
67
|
+
constructor(message) {
|
|
68
|
+
super(message ?? 'Unique constraint not found', 'constraint_not_found');
|
|
69
|
+
this.name = 'KoolbaseConstraintNotFoundError';
|
|
70
|
+
Object.setPrototypeOf(this, KoolbaseConstraintNotFoundError.prototype);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
42
73
|
export class KoolbaseConflictError extends KoolbaseDataError {
|
|
43
74
|
constructor(message, field) {
|
|
44
75
|
super(message ?? 'Value violates a unique constraint', 'unique_violation');
|
|
@@ -53,8 +84,15 @@ export class KoolbaseConflictError extends KoolbaseDataError {
|
|
|
53
84
|
* `collection_not_found`.
|
|
54
85
|
*/
|
|
55
86
|
export class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The code is carried rather than fixed, because the server distinguishes
|
|
89
|
+
* what was missing — a record, a collection, a vector field — and an app
|
|
90
|
+
* reading e.code should get that answer rather than the category. Catching
|
|
91
|
+
* the class still works for anyone who only cares that something was
|
|
92
|
+
* absent.
|
|
93
|
+
*/
|
|
94
|
+
constructor(message, code = 'not_found') {
|
|
95
|
+
super(message ?? 'The requested resource was not found', code);
|
|
58
96
|
this.name = 'KoolbaseNotFoundError';
|
|
59
97
|
Object.setPrototypeOf(this, KoolbaseNotFoundError.prototype);
|
|
60
98
|
}
|
|
@@ -64,8 +102,14 @@ export class KoolbaseNotFoundError extends KoolbaseDataError {
|
|
|
64
102
|
* 400 and code `validation_error`.
|
|
65
103
|
*/
|
|
66
104
|
export class KoolbaseValidationError extends KoolbaseDataError {
|
|
67
|
-
|
|
68
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Carries its code for the same reason KoolbaseNotFoundError does: a
|
|
107
|
+
* dimension the platform does not support and a vector pointed at the wrong
|
|
108
|
+
* collection are both validation failures, and an app should still be able
|
|
109
|
+
* to tell which without reading the message.
|
|
110
|
+
*/
|
|
111
|
+
constructor(message, code = 'validation_error') {
|
|
112
|
+
super(message ?? 'The request was invalid', code);
|
|
69
113
|
this.name = 'KoolbaseValidationError';
|
|
70
114
|
Object.setPrototypeOf(this, KoolbaseValidationError.prototype);
|
|
71
115
|
}
|
|
@@ -75,6 +119,20 @@ export class KoolbaseValidationError extends KoolbaseDataError {
|
|
|
75
119
|
* operation — the server responds with 403 and code `permission_denied`
|
|
76
120
|
* (typically a collection access rule rejecting the read/write).
|
|
77
121
|
*/
|
|
122
|
+
/**
|
|
123
|
+
* Authenticated, and not permitted to do this — distinct from a rule denying
|
|
124
|
+
* access to a record. Its own class rather than folding into
|
|
125
|
+
* KoolbasePermissionError, which hardcodes permission_denied: an error
|
|
126
|
+
* reporting a code the server did not send is a small lie, and apps that
|
|
127
|
+
* branch on e.code rather than instanceof would act on it.
|
|
128
|
+
*/
|
|
129
|
+
export class KoolbaseInsufficientAuthorityError extends KoolbaseDataError {
|
|
130
|
+
constructor(message) {
|
|
131
|
+
super(message ?? 'You do not have the authority to perform this action', 'insufficient_authority');
|
|
132
|
+
this.name = 'KoolbaseInsufficientAuthorityError';
|
|
133
|
+
Object.setPrototypeOf(this, KoolbaseInsufficientAuthorityError.prototype);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
78
136
|
export class KoolbasePermissionError extends KoolbaseDataError {
|
|
79
137
|
constructor(message) {
|
|
80
138
|
super(message ?? 'You do not have permission to perform this action', 'permission_denied');
|
|
@@ -144,12 +202,20 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
144
202
|
switch (code) {
|
|
145
203
|
case 'unique_violation':
|
|
146
204
|
return attach(new KoolbaseConflictError(message, field));
|
|
205
|
+
case 'ambiguous_match':
|
|
206
|
+
return attach(new KoolbaseAmbiguousMatchError(message));
|
|
207
|
+
case 'constraint_exists':
|
|
208
|
+
return attach(new KoolbaseConstraintExistsError(message));
|
|
209
|
+
case 'constraint_not_found':
|
|
210
|
+
return attach(new KoolbaseConstraintNotFoundError(message));
|
|
211
|
+
case 'insufficient_authority':
|
|
212
|
+
return attach(new KoolbaseInsufficientAuthorityError(message));
|
|
147
213
|
case 'not_found':
|
|
148
214
|
case 'record_not_found':
|
|
149
215
|
case 'collection_not_found':
|
|
150
216
|
case 'vector_not_found':
|
|
151
217
|
case 'vector_field_not_found':
|
|
152
|
-
return attach(new KoolbaseNotFoundError(message));
|
|
218
|
+
return attach(new KoolbaseNotFoundError(message, code));
|
|
153
219
|
case 'unauthenticated':
|
|
154
220
|
case 'session_expired':
|
|
155
221
|
case 'invalid_token':
|
|
@@ -161,7 +227,7 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
|
|
|
161
227
|
case 'validation_error':
|
|
162
228
|
case 'vector_collection_mismatch':
|
|
163
229
|
case 'unsupported_dimension':
|
|
164
|
-
return attach(new KoolbaseValidationError(message));
|
|
230
|
+
return attach(new KoolbaseValidationError(message, code));
|
|
165
231
|
case 'vector_dimension_mismatch':
|
|
166
232
|
return attach(new KoolbaseVectorDimensionMismatchError(message));
|
|
167
233
|
}
|
|
@@ -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;
|
|
@@ -71,6 +71,33 @@ export class FunctionExecutionError extends FunctionInvokeError {
|
|
|
71
71
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The function ran past its timeout and was killed.
|
|
76
|
+
*
|
|
77
|
+
* Its own type because the remedy is different from a function that threw:
|
|
78
|
+
* a timeout means retry, or raise the function's timeout at deploy, or move
|
|
79
|
+
* the slow part elsewhere. Without this it arrived as FunctionExecutionError
|
|
80
|
+
* — indistinguishable from an exception, which is the one thing it is not.
|
|
81
|
+
* The server already tells them apart; it logs 504 as "timeout".
|
|
82
|
+
*/
|
|
83
|
+
export class FunctionTimeoutError extends FunctionInvokeError {
|
|
84
|
+
constructor(message) {
|
|
85
|
+
super(message, 504, 'timeout');
|
|
86
|
+
this.name = 'FunctionTimeoutError';
|
|
87
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Too many invocations, too fast. Distinct from a quota being spent: this one
|
|
92
|
+
* clears by waiting.
|
|
93
|
+
*/
|
|
94
|
+
export class FunctionRateLimitError extends FunctionInvokeError {
|
|
95
|
+
constructor(message) {
|
|
96
|
+
super(message, 429, 'rate_limit');
|
|
97
|
+
this.name = 'FunctionRateLimitError';
|
|
98
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
74
101
|
/** Builds the right error for a failed invocation. */
|
|
75
102
|
export function functionInvokeError(status, message) {
|
|
76
103
|
switch (status) {
|
|
@@ -86,6 +113,11 @@ export function functionInvokeError(status, message) {
|
|
|
86
113
|
return new FunctionValidationError(message);
|
|
87
114
|
case 402:
|
|
88
115
|
return new FunctionQuotaExceededError(message);
|
|
116
|
+
case 429:
|
|
117
|
+
return new FunctionRateLimitError(message);
|
|
118
|
+
case 504:
|
|
119
|
+
// Before the generic 5xx branch: a timeout is not an exception.
|
|
120
|
+
return new FunctionTimeoutError(message);
|
|
89
121
|
}
|
|
90
122
|
if (status >= 500)
|
|
91
123
|
return new FunctionExecutionError(message, status);
|
|
@@ -76,6 +76,24 @@ 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
|
+
export declare class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
88
|
+
constructor(message?: string);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
92
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
93
|
+
*/
|
|
94
|
+
export declare class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
95
|
+
constructor(message?: string);
|
|
96
|
+
}
|
|
79
97
|
export declare class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
80
98
|
constructor(message?: string);
|
|
81
99
|
}
|
|
@@ -96,6 +96,32 @@ export class KoolbaseStoragePermissionError extends KoolbaseStorageError {
|
|
|
96
96
|
* 409 but means "path collides"); branch on the error type via
|
|
97
97
|
* `instanceof`, not on status.
|
|
98
98
|
*/
|
|
99
|
+
/**
|
|
100
|
+
* The presigned upload was confirmed after its window closed.
|
|
101
|
+
*
|
|
102
|
+
* An upload URL has a lifetime. A user who picks a file, gets distracted and
|
|
103
|
+
* comes back twenty minutes later hits this — so it is a retry, not a
|
|
104
|
+
* failure: presign again and send the same bytes. Worth catching rather than
|
|
105
|
+
* showing "upload failed" to someone whose file was fine.
|
|
106
|
+
*/
|
|
107
|
+
export class KoolbaseUploadExpiredError extends KoolbaseStorageError {
|
|
108
|
+
constructor(message) {
|
|
109
|
+
super(message ?? 'This upload is past the confirmation window — please re-upload', 'upload_expired');
|
|
110
|
+
this.name = 'KoolbaseUploadExpiredError';
|
|
111
|
+
Object.setPrototypeOf(this, KoolbaseUploadExpiredError.prototype);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A bucket cap set below what the bucket already holds. A dashboard
|
|
116
|
+
* operation rather than an app one, mapped so it does not arrive untyped.
|
|
117
|
+
*/
|
|
118
|
+
export class KoolbaseCapBelowUsageError extends KoolbaseStorageError {
|
|
119
|
+
constructor(message) {
|
|
120
|
+
super(message ?? 'The cap is below the bucket\'s current usage', 'cap_below_usage');
|
|
121
|
+
this.name = 'KoolbaseCapBelowUsageError';
|
|
122
|
+
Object.setPrototypeOf(this, KoolbaseCapBelowUsageError.prototype);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
99
125
|
export class KoolbaseStorageQuotaError extends KoolbaseStorageError {
|
|
100
126
|
constructor(message) {
|
|
101
127
|
super(message ?? 'Bucket quota exceeded', 'quota_exceeded');
|
|
@@ -195,6 +221,10 @@ export function koolbaseStorageError(status, body, fallbackMessage = 'Storage re
|
|
|
195
221
|
return new KoolbaseStorageConflictError(message, body?.path);
|
|
196
222
|
case 'quota_exceeded':
|
|
197
223
|
return new KoolbaseStorageQuotaError(message);
|
|
224
|
+
case 'upload_expired':
|
|
225
|
+
return new KoolbaseUploadExpiredError(message);
|
|
226
|
+
case 'cap_below_usage':
|
|
227
|
+
return new KoolbaseCapBelowUsageError(message);
|
|
198
228
|
case 'file_too_large':
|
|
199
229
|
return new KoolbaseStorageFileTooLargeError(message);
|
|
200
230
|
case 'mime_not_allowed':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koolbase/core",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.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",
|