@tinycloud/sdk-services 3.1.0-beta.1 → 3.1.0-beta.2
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/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +75 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +70 -80
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +26 -38
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +0 -1
- package/dist/kv/index.d.ts +0 -1
- package/dist/kv/index.js +26 -38
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +44 -5
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.js +44 -5
- package/dist/sql/index.js.map +1 -1
- package/package.json +1 -1
package/dist/kv/index.d.cts
CHANGED
|
@@ -850,7 +850,6 @@ declare class KVService extends BaseService implements IKVService {
|
|
|
850
850
|
* Get the service configuration.
|
|
851
851
|
*/
|
|
852
852
|
get config(): KVServiceConfig;
|
|
853
|
-
private parseQuotaInfo;
|
|
854
853
|
private handleQuotaErrorResponse;
|
|
855
854
|
/**
|
|
856
855
|
* Classify a KV 404 by reading the response body once.
|
package/dist/kv/index.d.ts
CHANGED
|
@@ -850,7 +850,6 @@ declare class KVService extends BaseService implements IKVService {
|
|
|
850
850
|
* Get the service configuration.
|
|
851
851
|
*/
|
|
852
852
|
get config(): KVServiceConfig;
|
|
853
|
-
private parseQuotaInfo;
|
|
854
853
|
private handleQuotaErrorResponse;
|
|
855
854
|
/**
|
|
856
855
|
* Classify a KV 404 by reading the response body once.
|
package/dist/kv/index.js
CHANGED
|
@@ -154,6 +154,20 @@ function storageLimitReachedError(service, message, meta) {
|
|
|
154
154
|
meta
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
+
var STORAGE_FULL_MESSAGE = "TinyCloud storage is full, so this change was not saved. Reading still works. Free up space or upgrade your plan to save again.";
|
|
158
|
+
var STORAGE_WRITE_TOO_LARGE_MESSAGE = "This change is larger than the TinyCloud storage you have left, so it was not saved. Reading still works. Free up space or upgrade your plan to save it.";
|
|
159
|
+
function parseStorageQuotaBytes(responseText) {
|
|
160
|
+
const match = responseText.match(/Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i);
|
|
161
|
+
if (!match) return void 0;
|
|
162
|
+
return {
|
|
163
|
+
usedBytes: parseInt(match[1], 10),
|
|
164
|
+
limitBytes: parseInt(match[2], 10)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function storageRejectionError(service, status, meta, responseText) {
|
|
168
|
+
const quotaMeta = { ...meta, ...parseStorageQuotaBytes(responseText) };
|
|
169
|
+
return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
|
|
170
|
+
}
|
|
157
171
|
function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
|
|
158
172
|
if (error instanceof Error) {
|
|
159
173
|
if (error.name === "AbortError") {
|
|
@@ -544,47 +558,21 @@ var KVService = class extends BaseService {
|
|
|
544
558
|
get config() {
|
|
545
559
|
return this._config;
|
|
546
560
|
}
|
|
547
|
-
// Parses "Used: X bytes, Limit: Y bytes" from tinycloud-node error responses
|
|
548
|
-
parseQuotaInfo(errorText) {
|
|
549
|
-
const match = errorText.match(
|
|
550
|
-
/Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i
|
|
551
|
-
);
|
|
552
|
-
if (match) {
|
|
553
|
-
return {
|
|
554
|
-
usedBytes: parseInt(match[1], 10),
|
|
555
|
-
limitBytes: parseInt(match[2], 10)
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
return void 0;
|
|
559
|
-
}
|
|
560
561
|
handleQuotaErrorResponse(response, errorText, key) {
|
|
561
|
-
if (response.status
|
|
562
|
-
|
|
563
|
-
return err(
|
|
564
|
-
storageQuotaExceededError(
|
|
565
|
-
"kv",
|
|
566
|
-
`Storage quota exceeded for key ${JSON.stringify(key)}: ${errorText}`,
|
|
567
|
-
{
|
|
568
|
-
status: response.status,
|
|
569
|
-
...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
|
|
570
|
-
}
|
|
571
|
-
)
|
|
572
|
-
);
|
|
562
|
+
if (response.status !== 402 && response.status !== 413) {
|
|
563
|
+
return void 0;
|
|
573
564
|
}
|
|
574
|
-
if (response.status === 413) {
|
|
575
|
-
|
|
576
|
-
return err(
|
|
577
|
-
storageLimitReachedError(
|
|
578
|
-
"kv",
|
|
579
|
-
`Storage limit reached for key ${JSON.stringify(key)}: ${errorText}`,
|
|
580
|
-
{
|
|
581
|
-
status: response.status,
|
|
582
|
-
...quotaInfo ? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes } : {}
|
|
583
|
-
}
|
|
584
|
-
)
|
|
585
|
-
);
|
|
565
|
+
if (response.status === 413 && !parseStorageQuotaBytes(errorText)) {
|
|
566
|
+
return void 0;
|
|
586
567
|
}
|
|
587
|
-
return
|
|
568
|
+
return err(
|
|
569
|
+
storageRejectionError(
|
|
570
|
+
"kv",
|
|
571
|
+
response.status,
|
|
572
|
+
{ status: response.status, statusText: response.statusText, key },
|
|
573
|
+
errorText
|
|
574
|
+
)
|
|
575
|
+
);
|
|
588
576
|
}
|
|
589
577
|
/**
|
|
590
578
|
* Classify a KV 404 by reading the response body once.
|