@tinycloud/sdk-services 3.2.0-beta.3 → 3.2.0-beta.7
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-BDQXjWMx.d.cts → BaseService-4wwJq1Gn.d.cts} +1 -1
- package/dist/{BaseService-Di_hVfUV.d.ts → BaseService-BGr2slUz.d.ts} +1 -1
- package/dist/encryption/index.cjs +5 -1
- 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 +5 -1
- package/dist/encryption/index.js.map +1 -1
- package/dist/index.cjs +190 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -6
- package/dist/index.d.ts +157 -6
- package/dist/index.js +184 -11
- 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 +56 -11
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +5 -4
- package/dist/kv/index.d.ts +5 -4
- package/dist/kv/index.js +56 -11
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/replication/index.cjs +44 -19
- package/dist/kv/replication/index.cjs.map +1 -1
- package/dist/kv/replication/index.d.cts +4 -3
- package/dist/kv/replication/index.d.ts +4 -3
- package/dist/kv/replication/index.js +44 -19
- package/dist/kv/replication/index.js.map +1 -1
- package/dist/kv/replication/prefix.cjs +43 -0
- package/dist/kv/replication/prefix.cjs.map +1 -0
- package/dist/kv/replication/prefix.d.cts +6 -0
- package/dist/kv/replication/prefix.d.ts +6 -0
- package/dist/kv/replication/prefix.js +17 -0
- package/dist/kv/replication/prefix.js.map +1 -0
- package/dist/{scope-BmLxwyl-.d.ts → scope-CoKKmMiI.d.ts} +5 -5
- package/dist/{scope-D855kRDx.d.cts → scope-D7wmjbMH.d.cts} +5 -5
- package/dist/sql/index.cjs +44 -2
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +2 -2
- package/dist/sql/index.d.ts +2 -2
- package/dist/sql/index.js +44 -2
- package/dist/sql/index.js.map +1 -1
- package/dist/{types-7A5rHWRY.d.cts → types-D-9A3Sut.d.cts} +6 -0
- package/dist/{types-7A5rHWRY.d.ts → types-D-9A3Sut.d.ts} +6 -0
- package/package.json +14 -1
package/dist/kv/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BaseService } from '../BaseService-
|
|
2
|
-
import { R as Result, I as IService } from '../types-
|
|
3
|
-
import {
|
|
4
|
-
export { A as AuthorityRefusal, C as CLEAR_PENDING_WARNING,
|
|
1
|
+
import { B as BaseService } from '../BaseService-4wwJq1Gn.cjs';
|
|
2
|
+
import { R as Result, I as IService } from '../types-D-9A3Sut.cjs';
|
|
3
|
+
import { Y as KVGetOptions, a1 as KVResponse, Q as KVBatchReadResponse, a0 as KVPutOptions, M as KVBatchPutItem, N as KVBatchPutOptions, O as KVBatchPutResponse, _ as KVListOptions, $ as KVListResponse, U as KVChangesOptions, V as KVChangesResponse, X as KVDeleteOptions, Z as KVHeadOptions, W as KVCreateSignedReadUrlOptions, a4 as KVSignedReadUrlResponse, a3 as KVServiceConfig, c as KVReadThrough } from '../scope-D7wmjbMH.cjs';
|
|
4
|
+
export { A as AuthorityRefusal, C as CLEAR_PENDING_WARNING, H as DEFAULT_SIGNED_READ_URL_EXPIRY_MS, I as KVAction, J as KVActionType, S as KVChange, T as KVChangesAuthority, b as KVListPage, d as KVReplicaHandle, e as KVReplicaSpec, f as KVReplicaStorage, a as KVReplicationController, K as KVReplicationDeps, a2 as KVResponseHeaders, L as LocalGetResult, g as LocalListResult, h as LocalReadMeta, i as LocalReplicaStatus, j as LocalSyncResult, k as PendingWriteRecord, l as PendingWriteState, P as PendingWriteStore, m as PinnedKey, n as PurgeTarget, o as ReplicaAuthorityState, p as ReplicaCoverage, q as ReplicaDevice, r as ReplicaGrantInfo, s as ReplicaState, t as ReplicaStatusEntry, u as ReplicationAuthority, v as ReplicationControl, w as ReplicationEvent, R as ReplicationIdentity, x as ReplicationOptions, y as ReplicationPurgeReport, z as ReplicationReason, B as ReplicationScheduler, D as ResolvedReplicationOptions, E as canonicalReplicationIdentity, F as replicationIdentityKey, G as requiresSecretsOptIn } from '../scope-D7wmjbMH.cjs';
|
|
5
|
+
export { kvPrefixCovers } from './replication/prefix.cjs';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* PrefixedKVService - A prefix-scoped view of KVService.
|
package/dist/kv/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { B as BaseService } from '../BaseService-
|
|
2
|
-
import { R as Result, I as IService } from '../types-
|
|
3
|
-
import {
|
|
4
|
-
export { A as AuthorityRefusal, C as CLEAR_PENDING_WARNING,
|
|
1
|
+
import { B as BaseService } from '../BaseService-BGr2slUz.js';
|
|
2
|
+
import { R as Result, I as IService } from '../types-D-9A3Sut.js';
|
|
3
|
+
import { Y as KVGetOptions, a1 as KVResponse, Q as KVBatchReadResponse, a0 as KVPutOptions, M as KVBatchPutItem, N as KVBatchPutOptions, O as KVBatchPutResponse, _ as KVListOptions, $ as KVListResponse, U as KVChangesOptions, V as KVChangesResponse, X as KVDeleteOptions, Z as KVHeadOptions, W as KVCreateSignedReadUrlOptions, a4 as KVSignedReadUrlResponse, a3 as KVServiceConfig, c as KVReadThrough } from '../scope-CoKKmMiI.js';
|
|
4
|
+
export { A as AuthorityRefusal, C as CLEAR_PENDING_WARNING, H as DEFAULT_SIGNED_READ_URL_EXPIRY_MS, I as KVAction, J as KVActionType, S as KVChange, T as KVChangesAuthority, b as KVListPage, d as KVReplicaHandle, e as KVReplicaSpec, f as KVReplicaStorage, a as KVReplicationController, K as KVReplicationDeps, a2 as KVResponseHeaders, L as LocalGetResult, g as LocalListResult, h as LocalReadMeta, i as LocalReplicaStatus, j as LocalSyncResult, k as PendingWriteRecord, l as PendingWriteState, P as PendingWriteStore, m as PinnedKey, n as PurgeTarget, o as ReplicaAuthorityState, p as ReplicaCoverage, q as ReplicaDevice, r as ReplicaGrantInfo, s as ReplicaState, t as ReplicaStatusEntry, u as ReplicationAuthority, v as ReplicationControl, w as ReplicationEvent, R as ReplicationIdentity, x as ReplicationOptions, y as ReplicationPurgeReport, z as ReplicationReason, B as ReplicationScheduler, D as ResolvedReplicationOptions, E as canonicalReplicationIdentity, F as replicationIdentityKey, G as requiresSecretsOptIn } from '../scope-CoKKmMiI.js';
|
|
5
|
+
export { kvPrefixCovers } from './replication/prefix.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* PrefixedKVService - A prefix-scoped view of KVService.
|
package/dist/kv/index.js
CHANGED
|
@@ -36,6 +36,8 @@ var ErrorCodes = {
|
|
|
36
36
|
// Storage quota errors
|
|
37
37
|
STORAGE_QUOTA_EXCEEDED: "STORAGE_QUOTA_EXCEEDED",
|
|
38
38
|
STORAGE_LIMIT_REACHED: "STORAGE_LIMIT_REACHED",
|
|
39
|
+
/** The node answered the usage read without usage numbers (it predates the read). */
|
|
40
|
+
STORAGE_STATUS_UNAVAILABLE: "STORAGE_STATUS_UNAVAILABLE",
|
|
39
41
|
// DuckDB-specific errors
|
|
40
42
|
DUCKDB_ERROR: "DUCKDB_ERROR",
|
|
41
43
|
DUCKDB_PERMISSION_DENIED: "DUCKDB_PERMISSION_DENIED",
|
|
@@ -65,7 +67,9 @@ var TelemetryEvents = {
|
|
|
65
67
|
REPLICATION_WRITE: "replication.write",
|
|
66
68
|
REPLICATION_SYNC: "replication.sync",
|
|
67
69
|
REPLICATION_STATE: "replication.state",
|
|
68
|
-
REPLICATION_DIVERGENCE: "replication.divergence"
|
|
70
|
+
REPLICATION_DIVERGENCE: "replication.divergence",
|
|
71
|
+
/** Emitted once, on the first write rejected because storage is full. */
|
|
72
|
+
STORAGE_FULL: "storage.full"
|
|
69
73
|
};
|
|
70
74
|
function ok(data) {
|
|
71
75
|
return { ok: true, data };
|
|
@@ -341,8 +345,43 @@ function parseStorageQuotaBytes(responseText) {
|
|
|
341
345
|
limitBytes: parseInt(match[2], 10)
|
|
342
346
|
};
|
|
343
347
|
}
|
|
348
|
+
var STORAGE_REJECTION_BODY_ERRORS = {
|
|
349
|
+
storage_quota_exceeded: true,
|
|
350
|
+
storage_limit_reached: true
|
|
351
|
+
};
|
|
352
|
+
function isByteCount(value) {
|
|
353
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
354
|
+
}
|
|
355
|
+
function byteCountsOf(value) {
|
|
356
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
357
|
+
const { usedBytes, limitBytes } = value;
|
|
358
|
+
return isByteCount(usedBytes) && isByteCount(limitBytes) ? { usedBytes, limitBytes } : void 0;
|
|
359
|
+
}
|
|
360
|
+
function parseStorageRejection(responseText) {
|
|
361
|
+
let body;
|
|
362
|
+
try {
|
|
363
|
+
body = JSON.parse(responseText);
|
|
364
|
+
} catch {
|
|
365
|
+
return parseStorageQuotaBytes(responseText);
|
|
366
|
+
}
|
|
367
|
+
if (typeof body !== "object" || body === null) return void 0;
|
|
368
|
+
const record = body;
|
|
369
|
+
const message = typeof record.message === "string" ? record.message : "";
|
|
370
|
+
const space = byteCountsOf(record.space) ?? parseStorageQuotaBytes(message);
|
|
371
|
+
const isStorageBody = typeof record.error === "string" && STORAGE_REJECTION_BODY_ERRORS[record.error] === true;
|
|
372
|
+
if (!space && !isStorageBody) {
|
|
373
|
+
return void 0;
|
|
374
|
+
}
|
|
375
|
+
const details = { ...space };
|
|
376
|
+
const account = byteCountsOf(record.account);
|
|
377
|
+
if (account) {
|
|
378
|
+
const plan = record.account.plan;
|
|
379
|
+
details.account = typeof plan === "string" && plan !== "" ? { ...account, plan } : account;
|
|
380
|
+
}
|
|
381
|
+
return details;
|
|
382
|
+
}
|
|
344
383
|
function storageRejectionError(service, status, meta, responseText) {
|
|
345
|
-
const quotaMeta = { ...meta, ...
|
|
384
|
+
const quotaMeta = { ...meta, ...parseStorageRejection(responseText) };
|
|
346
385
|
return status === 402 ? storageQuotaExceededError(service, STORAGE_FULL_MESSAGE, quotaMeta) : storageLimitReachedError(service, STORAGE_WRITE_TOO_LARGE_MESSAGE, quotaMeta);
|
|
347
386
|
}
|
|
348
387
|
function wrapError(service, error, defaultCode = ErrorCodes.NETWORK_ERROR) {
|
|
@@ -865,7 +904,7 @@ var KVService = class extends BaseService {
|
|
|
865
904
|
if (response.status !== 402 && response.status !== 413) {
|
|
866
905
|
return void 0;
|
|
867
906
|
}
|
|
868
|
-
if (response.status === 413 && !
|
|
907
|
+
if (response.status === 413 && !parseStorageRejection(errorText)) {
|
|
869
908
|
return void 0;
|
|
870
909
|
}
|
|
871
910
|
return err(
|
|
@@ -1905,6 +1944,7 @@ var KVService = class extends BaseService {
|
|
|
1905
1944
|
"kv"
|
|
1906
1945
|
));
|
|
1907
1946
|
}
|
|
1947
|
+
const requestPrefix = options.prefix === "/" ? "" : options.prefix;
|
|
1908
1948
|
const headers = {};
|
|
1909
1949
|
if (options.limit !== void 0) headers["x-tinycloud-limit"] = String(options.limit);
|
|
1910
1950
|
if (options.cursor !== void 0) headers["x-tinycloud-cursor"] = options.cursor;
|
|
@@ -1914,7 +1954,7 @@ var KVService = class extends BaseService {
|
|
|
1914
1954
|
const request = this.createRequestSignal(options.signal, options.timeout);
|
|
1915
1955
|
try {
|
|
1916
1956
|
const response = await this.invokeOperation(
|
|
1917
|
-
|
|
1957
|
+
requestPrefix,
|
|
1918
1958
|
KVAction.SYNC,
|
|
1919
1959
|
void 0,
|
|
1920
1960
|
request.signal,
|
|
@@ -1930,7 +1970,7 @@ var KVService = class extends BaseService {
|
|
|
1930
1970
|
} catch {
|
|
1931
1971
|
body = void 0;
|
|
1932
1972
|
}
|
|
1933
|
-
const page = this.normalizeChangesResponse(body);
|
|
1973
|
+
const page = this.normalizeChangesResponse(body, options.prefix);
|
|
1934
1974
|
if (!page) {
|
|
1935
1975
|
return err(serviceError(
|
|
1936
1976
|
ErrorCodes.NETWORK_ERROR,
|
|
@@ -2010,7 +2050,7 @@ var KVService = class extends BaseService {
|
|
|
2010
2050
|
{ meta }
|
|
2011
2051
|
));
|
|
2012
2052
|
}
|
|
2013
|
-
normalizeChangesResponse(data) {
|
|
2053
|
+
normalizeChangesResponse(data, requestedPrefix) {
|
|
2014
2054
|
if (!isJsonObject(data)) return void 0;
|
|
2015
2055
|
const { changes, more, cursor, source, authority } = data;
|
|
2016
2056
|
if (!Array.isArray(changes) || typeof more !== "boolean" || typeof cursor !== "string" || !isJsonObject(source) || typeof source.nodeDid !== "string" || typeof source.space !== "string" || typeof source.prefix !== "string" || !isJsonObject(authority)) {
|
|
@@ -2042,7 +2082,11 @@ var KVService = class extends BaseService {
|
|
|
2042
2082
|
changes: parsed,
|
|
2043
2083
|
more,
|
|
2044
2084
|
cursor,
|
|
2045
|
-
source: {
|
|
2085
|
+
source: {
|
|
2086
|
+
nodeDid: source.nodeDid,
|
|
2087
|
+
space: source.space,
|
|
2088
|
+
prefix: requestedPrefix === "/" && source.prefix === "" ? "/" : source.prefix
|
|
2089
|
+
},
|
|
2046
2090
|
authority: { notBefore, expiresAt, retainUntil }
|
|
2047
2091
|
};
|
|
2048
2092
|
}
|
|
@@ -2337,13 +2381,14 @@ ${canonical.space}
|
|
|
2337
2381
|
${canonical.principal}`;
|
|
2338
2382
|
}
|
|
2339
2383
|
|
|
2340
|
-
// src/kv/replication/
|
|
2384
|
+
// src/kv/replication/prefix.ts
|
|
2341
2385
|
function kvPrefixCovers(prefix, key) {
|
|
2342
|
-
|
|
2343
|
-
if (prefix.endsWith("/")) return key.startsWith(prefix);
|
|
2344
|
-
return key === prefix || key.startsWith(`${prefix}/`);
|
|
2386
|
+
return prefix === "/" || key.startsWith(prefix);
|
|
2345
2387
|
}
|
|
2388
|
+
|
|
2389
|
+
// src/kv/replication/scope.ts
|
|
2346
2390
|
function requiresSecretsOptIn(space, prefix) {
|
|
2391
|
+
if (prefix === "/") return true;
|
|
2347
2392
|
if (space === "secrets" || space.endsWith(":secrets")) return true;
|
|
2348
2393
|
return prefix.split("/", 1)[0] === "vault";
|
|
2349
2394
|
}
|