@tinycloud/sdk-services 2.7.0 → 2.8.0-beta.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/{BaseService-CnPTKR5G.d.ts → BaseService-BiYeqCRT.d.ts} +1 -1
- package/dist/{BaseService-BwBU5CQ4.d.cts → BaseService-DxSU4U-v.d.cts} +1 -1
- package/dist/encryption/index.cjs +3 -0
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +2 -2
- package/dist/encryption/index.d.ts +2 -2
- package/dist/encryption/index.js +3 -0
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +100 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +100 -10
- package/dist/index.js.map +1 -1
- package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
- package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
- package/dist/kv/index.cjs +86 -8
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +22 -7
- package/dist/kv/index.d.ts +22 -7
- package/dist/kv/index.js +86 -8
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +17 -2
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +7 -3
- package/dist/sql/index.d.ts +7 -3
- package/dist/sql/index.js +17 -2
- package/dist/sql/index.js.map +1 -1
- package/dist/{types-DAY1O1kW.d.cts → types-KCcgZiab.d.cts} +3 -0
- package/dist/{types-DAY1O1kW.d.ts → types-KCcgZiab.d.ts} +3 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-
|
|
2
|
-
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-
|
|
1
|
+
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-KCcgZiab.cjs';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-KCcgZiab.cjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { B as BaseService } from './BaseService-
|
|
4
|
+
import { B as BaseService } from './BaseService-DxSU4U-v.cjs';
|
|
5
5
|
import { IKVService } from './kv/index.cjs';
|
|
6
6
|
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.cjs';
|
|
7
7
|
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLAction, SQLActionType, SQLMigrations, SQLService, SQLServiceConfig, SqlMigration, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue } from './sql/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-
|
|
2
|
-
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-
|
|
1
|
+
import { a as IServiceContext, c as InvokeFunction, d as InvokeAnyFunction, F as FetchFunction, S as ServiceSession, e as RetryPolicy, T as TelemetryConfig, I as IService, E as EventHandler, b as ServiceError, R as Result, P as PermissionHint, f as StorageQuotaInfo } from './types-KCcgZiab.js';
|
|
2
|
+
export { g as ErrorCode, h as ErrorCodes, i as FetchRequestInit, j as FetchResponse, k as InvocationFact, l as InvocationFacts, m as InvokeAnyEntry, n as ServiceErrorEvent, o as ServiceHeaders, p as ServiceRequestEvent, q as ServiceResponseEvent, r as ServiceRetryEvent, s as TelemetryEventHandler, t as TelemetryEvents, u as TelemetrySpanEvent, v as defaultRetryPolicy, w as err, x as ok, y as serviceError } from './types-KCcgZiab.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { B as BaseService } from './BaseService-
|
|
4
|
+
import { B as BaseService } from './BaseService-BiYeqCRT.js';
|
|
5
5
|
import { IKVService } from './kv/index.js';
|
|
6
6
|
export { DEFAULT_SIGNED_READ_URL_EXPIRY_MS, IPrefixedKVService, KVAction, KVActionType, KVBatchPutItem, KVBatchPutOptions, KVBatchPutResponse, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, PrefixedKVService } from './kv/index.js';
|
|
7
7
|
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLAction, SQLActionType, SQLMigrations, SQLService, SQLServiceConfig, SqlMigration, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue } from './sql/index.js';
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,9 @@ var ErrorCodes = {
|
|
|
13
13
|
// KV-specific errors
|
|
14
14
|
KV_NOT_FOUND: "KV_NOT_FOUND",
|
|
15
15
|
KV_WRITE_FAILED: "KV_WRITE_FAILED",
|
|
16
|
+
KV_PRECONDITION_FAILED: "KV_PRECONDITION_FAILED",
|
|
17
|
+
KV_CONFLICT: "KV_CONFLICT",
|
|
18
|
+
KV_RESPONSE_TOO_LARGE: "KV_RESPONSE_TOO_LARGE",
|
|
16
19
|
// SQL-specific errors
|
|
17
20
|
SQL_ERROR: "SQL_ERROR",
|
|
18
21
|
SQL_PERMISSION_DENIED: "SQL_PERMISSION_DENIED",
|
|
@@ -1470,7 +1473,7 @@ var KVService = class extends BaseService {
|
|
|
1470
1473
|
* @param signal - Optional abort signal
|
|
1471
1474
|
* @returns Fetch response
|
|
1472
1475
|
*/
|
|
1473
|
-
async invokeOperation(path, action, body, signal) {
|
|
1476
|
+
async invokeOperation(path, action, body, signal, extraHeaders) {
|
|
1474
1477
|
const session = this.context.session;
|
|
1475
1478
|
const headers = this.context.invoke(
|
|
1476
1479
|
session,
|
|
@@ -1478,9 +1481,10 @@ var KVService = class extends BaseService {
|
|
|
1478
1481
|
path,
|
|
1479
1482
|
action
|
|
1480
1483
|
);
|
|
1484
|
+
const requestHeaders = Array.isArray(headers) ? [...headers, ...Object.entries(extraHeaders ?? {})] : { ...headers, ...extraHeaders };
|
|
1481
1485
|
return this.context.fetch(`${this.host}/invoke`, {
|
|
1482
1486
|
method: "POST",
|
|
1483
|
-
headers,
|
|
1487
|
+
headers: requestHeaders,
|
|
1484
1488
|
body,
|
|
1485
1489
|
signal: this.combineSignals(signal)
|
|
1486
1490
|
});
|
|
@@ -1662,13 +1666,21 @@ var KVService = class extends BaseService {
|
|
|
1662
1666
|
if (!this.requireAuth()) {
|
|
1663
1667
|
return err(authRequiredError("kv"));
|
|
1664
1668
|
}
|
|
1669
|
+
if (options?.maxResponseBytes !== void 0 && (!Number.isSafeInteger(options.maxResponseBytes) || options.maxResponseBytes <= 0)) {
|
|
1670
|
+
return err(serviceError(
|
|
1671
|
+
ErrorCodes.INVALID_INPUT,
|
|
1672
|
+
"KV maxResponseBytes must be a positive safe integer",
|
|
1673
|
+
"kv"
|
|
1674
|
+
));
|
|
1675
|
+
}
|
|
1665
1676
|
const path = this.getFullPath(key, options?.prefix);
|
|
1666
1677
|
try {
|
|
1667
1678
|
const response = await this.invokeOperation(
|
|
1668
1679
|
path,
|
|
1669
1680
|
KVAction.GET,
|
|
1670
1681
|
void 0,
|
|
1671
|
-
options?.signal
|
|
1682
|
+
options?.signal,
|
|
1683
|
+
options?.maxResponseBytes === void 0 ? void 0 : { "x-tinycloud-max-response-bytes": String(options.maxResponseBytes) }
|
|
1672
1684
|
);
|
|
1673
1685
|
if (!response.ok) {
|
|
1674
1686
|
if (response.status === 401 || response.status === 403) {
|
|
@@ -1686,6 +1698,14 @@ var KVService = class extends BaseService {
|
|
|
1686
1698
|
return this.classifyNotFound(response, key);
|
|
1687
1699
|
}
|
|
1688
1700
|
const errorText = await response.text();
|
|
1701
|
+
if (response.status === 413) {
|
|
1702
|
+
return err(serviceError(
|
|
1703
|
+
ErrorCodes.KV_RESPONSE_TOO_LARGE,
|
|
1704
|
+
`KV value at key "${key}" exceeds the requested response limit`,
|
|
1705
|
+
"kv",
|
|
1706
|
+
{ meta: { status: response.status, statusText: response.statusText } }
|
|
1707
|
+
));
|
|
1708
|
+
}
|
|
1689
1709
|
return err(
|
|
1690
1710
|
serviceError(
|
|
1691
1711
|
ErrorCodes.NETWORK_ERROR,
|
|
@@ -1717,6 +1737,13 @@ var KVService = class extends BaseService {
|
|
|
1717
1737
|
if (!this.requireAuth()) {
|
|
1718
1738
|
return err(authRequiredError("kv"));
|
|
1719
1739
|
}
|
|
1740
|
+
if (options?.ifMatch !== void 0 && options.ifNoneMatch !== void 0) {
|
|
1741
|
+
return err(serviceError(
|
|
1742
|
+
ErrorCodes.INVALID_INPUT,
|
|
1743
|
+
"KV put cannot combine ifMatch and ifNoneMatch",
|
|
1744
|
+
"kv"
|
|
1745
|
+
));
|
|
1746
|
+
}
|
|
1720
1747
|
const path = this.getFullPath(key, options?.prefix);
|
|
1721
1748
|
const body = this.serializePutValue(value, options?.contentType);
|
|
1722
1749
|
try {
|
|
@@ -1724,7 +1751,11 @@ var KVService = class extends BaseService {
|
|
|
1724
1751
|
path,
|
|
1725
1752
|
KVAction.PUT,
|
|
1726
1753
|
body,
|
|
1727
|
-
options?.signal
|
|
1754
|
+
options?.signal,
|
|
1755
|
+
{
|
|
1756
|
+
...options?.ifMatch === void 0 ? {} : { "if-match": options.ifMatch },
|
|
1757
|
+
...options?.ifNoneMatch === void 0 ? {} : { "if-none-match": options.ifNoneMatch }
|
|
1758
|
+
}
|
|
1728
1759
|
);
|
|
1729
1760
|
if (!response.ok) {
|
|
1730
1761
|
if (response.status === 401) {
|
|
@@ -1737,6 +1768,22 @@ var KVService = class extends BaseService {
|
|
|
1737
1768
|
}));
|
|
1738
1769
|
}
|
|
1739
1770
|
const errorText = await response.text();
|
|
1771
|
+
if (response.status === 412) {
|
|
1772
|
+
return err(serviceError(
|
|
1773
|
+
ErrorCodes.KV_PRECONDITION_FAILED,
|
|
1774
|
+
`KV precondition failed for key "${key}"`,
|
|
1775
|
+
"kv",
|
|
1776
|
+
{ meta: { status: response.status, statusText: response.statusText } }
|
|
1777
|
+
));
|
|
1778
|
+
}
|
|
1779
|
+
if (response.status === 503 && (options?.ifMatch !== void 0 || options?.ifNoneMatch !== void 0)) {
|
|
1780
|
+
return err(serviceError(
|
|
1781
|
+
ErrorCodes.KV_CONFLICT,
|
|
1782
|
+
`Concurrent KV update conflicted for key "${key}"`,
|
|
1783
|
+
"kv",
|
|
1784
|
+
{ meta: { status: response.status, statusText: response.statusText } }
|
|
1785
|
+
));
|
|
1786
|
+
}
|
|
1740
1787
|
const quotaError = this.handleQuotaErrorResponse(
|
|
1741
1788
|
response,
|
|
1742
1789
|
errorText,
|
|
@@ -1872,6 +1919,13 @@ var KVService = class extends BaseService {
|
|
|
1872
1919
|
if (!this.requireAuth()) {
|
|
1873
1920
|
return err(authRequiredError("kv"));
|
|
1874
1921
|
}
|
|
1922
|
+
if (options?.limit !== void 0 && (!Number.isInteger(options.limit) || options.limit < 1 || options.limit > 1e3)) {
|
|
1923
|
+
return err(serviceError(
|
|
1924
|
+
ErrorCodes.INVALID_INPUT,
|
|
1925
|
+
"KV list limit must be an integer from 1 through 1000",
|
|
1926
|
+
"kv"
|
|
1927
|
+
));
|
|
1928
|
+
}
|
|
1875
1929
|
let listPath = options?.prefix ?? this._config.prefix ?? "";
|
|
1876
1930
|
if (options?.path) {
|
|
1877
1931
|
listPath = listPath ? `${listPath}/${options.path}` : options.path;
|
|
@@ -1881,7 +1935,8 @@ var KVService = class extends BaseService {
|
|
|
1881
1935
|
listPath,
|
|
1882
1936
|
KVAction.LIST,
|
|
1883
1937
|
void 0,
|
|
1884
|
-
options?.signal
|
|
1938
|
+
options?.signal,
|
|
1939
|
+
options?.limit === void 0 ? void 0 : { "x-tinycloud-limit": String(options.limit) }
|
|
1885
1940
|
);
|
|
1886
1941
|
if (!response.ok) {
|
|
1887
1942
|
if (response.status === 401) {
|
|
@@ -1911,7 +1966,10 @@ var KVService = class extends BaseService {
|
|
|
1911
1966
|
(key) => key.startsWith(prefixWithSlash) ? key.slice(prefixWithSlash.length) : key
|
|
1912
1967
|
);
|
|
1913
1968
|
}
|
|
1914
|
-
return ok({
|
|
1969
|
+
return ok({
|
|
1970
|
+
keys,
|
|
1971
|
+
...response.headers.get("x-tinycloud-truncated") === null ? {} : { truncated: response.headers.get("x-tinycloud-truncated") === "true" }
|
|
1972
|
+
});
|
|
1915
1973
|
} catch (error) {
|
|
1916
1974
|
return err(wrapError("kv", error));
|
|
1917
1975
|
}
|
|
@@ -1931,7 +1989,8 @@ var KVService = class extends BaseService {
|
|
|
1931
1989
|
path,
|
|
1932
1990
|
KVAction.DELETE,
|
|
1933
1991
|
void 0,
|
|
1934
|
-
options?.signal
|
|
1992
|
+
options?.signal,
|
|
1993
|
+
options?.ifMatch === void 0 ? void 0 : { "if-match": options.ifMatch }
|
|
1935
1994
|
);
|
|
1936
1995
|
if (!response.ok) {
|
|
1937
1996
|
if (response.status === 401) {
|
|
@@ -1947,6 +2006,22 @@ var KVService = class extends BaseService {
|
|
|
1947
2006
|
return this.classifyNotFound(response, key);
|
|
1948
2007
|
}
|
|
1949
2008
|
const errorText = await response.text();
|
|
2009
|
+
if (response.status === 412) {
|
|
2010
|
+
return err(serviceError(
|
|
2011
|
+
ErrorCodes.KV_PRECONDITION_FAILED,
|
|
2012
|
+
`KV precondition failed for key "${key}"`,
|
|
2013
|
+
"kv",
|
|
2014
|
+
{ meta: { status: response.status, statusText: response.statusText } }
|
|
2015
|
+
));
|
|
2016
|
+
}
|
|
2017
|
+
if (response.status === 503 && options?.ifMatch !== void 0) {
|
|
2018
|
+
return err(serviceError(
|
|
2019
|
+
ErrorCodes.KV_CONFLICT,
|
|
2020
|
+
`Concurrent KV delete conflicted for key "${key}"`,
|
|
2021
|
+
"kv",
|
|
2022
|
+
{ meta: { status: response.status, statusText: response.statusText } }
|
|
2023
|
+
));
|
|
2024
|
+
}
|
|
1950
2025
|
return err(
|
|
1951
2026
|
serviceError(
|
|
1952
2027
|
ErrorCodes.NETWORK_ERROR,
|
|
@@ -1956,7 +2031,10 @@ var KVService = class extends BaseService {
|
|
|
1956
2031
|
)
|
|
1957
2032
|
);
|
|
1958
2033
|
}
|
|
1959
|
-
return ok(
|
|
2034
|
+
return ok({
|
|
2035
|
+
data: void 0,
|
|
2036
|
+
headers: this.createResponseHeaders(response.headers)
|
|
2037
|
+
});
|
|
1960
2038
|
} catch (error) {
|
|
1961
2039
|
return err(wrapError("kv", error));
|
|
1962
2040
|
}
|
|
@@ -2276,10 +2354,17 @@ var SQLService = class extends BaseService {
|
|
|
2276
2354
|
return err(authRequiredError("sql"));
|
|
2277
2355
|
}
|
|
2278
2356
|
try {
|
|
2357
|
+
const body = {
|
|
2358
|
+
action: "query",
|
|
2359
|
+
sql,
|
|
2360
|
+
params: serializeSqlValues(params ?? [])
|
|
2361
|
+
};
|
|
2362
|
+
if (options?.maxRows !== void 0) body.maxRows = options.maxRows;
|
|
2363
|
+
if (options?.maxBytes !== void 0) body.maxBytes = options.maxBytes;
|
|
2279
2364
|
const response = await this.invokeSQL(
|
|
2280
2365
|
dbName,
|
|
2281
2366
|
this.actionForSql(sql, SQLAction.READ),
|
|
2282
|
-
|
|
2367
|
+
body,
|
|
2283
2368
|
options?.signal
|
|
2284
2369
|
);
|
|
2285
2370
|
if (!response.ok) {
|
|
@@ -2301,7 +2386,7 @@ var SQLService = class extends BaseService {
|
|
|
2301
2386
|
const body = {
|
|
2302
2387
|
action: "execute",
|
|
2303
2388
|
sql,
|
|
2304
|
-
params: params ?? []
|
|
2389
|
+
params: serializeSqlValues(params ?? [])
|
|
2305
2390
|
};
|
|
2306
2391
|
if (options?.schema) {
|
|
2307
2392
|
body.schema = options.schema;
|
|
@@ -2626,6 +2711,11 @@ function validateMigrationOptions(options) {
|
|
|
2626
2711
|
}
|
|
2627
2712
|
return null;
|
|
2628
2713
|
}
|
|
2714
|
+
function serializeSqlValues(values) {
|
|
2715
|
+
return values.map(
|
|
2716
|
+
(value) => value instanceof Uint8Array ? Array.from(value) : value
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2629
2719
|
function migrationKey(namespace, id) {
|
|
2630
2720
|
return `${encodeURIComponent(namespace)}:${encodeURIComponent(id)}`;
|
|
2631
2721
|
}
|