@tinycloud/sdk-services 1.7.0 → 2.0.2-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/{types.d.ts → BaseService-D9BFm_rV.d.cts} +179 -27
- package/dist/BaseService-D9BFm_rV.d.ts +440 -0
- package/dist/index.cjs +3221 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1843 -0
- package/dist/index.d.ts +1826 -41
- package/dist/index.js +3136 -58
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs +909 -0
- package/dist/kv/index.cjs.map +1 -0
- package/dist/kv/index.d.cts +748 -0
- package/dist/kv/index.d.ts +745 -7
- package/dist/kv/index.js +877 -9
- package/dist/kv/index.js.map +1 -1
- package/dist/sql/index.cjs +596 -0
- package/dist/sql/index.cjs.map +1 -0
- package/dist/sql/index.d.cts +228 -0
- package/dist/sql/index.d.ts +225 -7
- package/dist/sql/index.js +566 -8
- package/dist/sql/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/base/BaseService.d.ts +0 -151
- package/dist/base/BaseService.d.ts.map +0 -1
- package/dist/base/BaseService.js +0 -221
- package/dist/base/BaseService.js.map +0 -1
- package/dist/base/index.d.ts +0 -6
- package/dist/base/index.d.ts.map +0 -1
- package/dist/base/index.js +0 -6
- package/dist/base/index.js.map +0 -1
- package/dist/base/types.d.ts +0 -36
- package/dist/base/types.d.ts.map +0 -1
- package/dist/base/types.js +0 -7
- package/dist/base/types.js.map +0 -1
- package/dist/context.d.ts +0 -142
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -218
- package/dist/context.js.map +0 -1
- package/dist/duckdb/DuckDbDatabaseHandle.d.ts +0 -23
- package/dist/duckdb/DuckDbDatabaseHandle.d.ts.map +0 -1
- package/dist/duckdb/DuckDbDatabaseHandle.js +0 -36
- package/dist/duckdb/DuckDbDatabaseHandle.js.map +0 -1
- package/dist/duckdb/DuckDbService.d.ts +0 -50
- package/dist/duckdb/DuckDbService.d.ts.map +0 -1
- package/dist/duckdb/DuckDbService.js +0 -285
- package/dist/duckdb/DuckDbService.js.map +0 -1
- package/dist/duckdb/IDuckDbService.d.ts +0 -84
- package/dist/duckdb/IDuckDbService.d.ts.map +0 -1
- package/dist/duckdb/IDuckDbService.js +0 -7
- package/dist/duckdb/IDuckDbService.js.map +0 -1
- package/dist/duckdb/index.d.ts +0 -10
- package/dist/duckdb/index.d.ts.map +0 -1
- package/dist/duckdb/index.js +0 -9
- package/dist/duckdb/index.js.map +0 -1
- package/dist/duckdb/types.d.ts +0 -148
- package/dist/duckdb/types.d.ts.map +0 -1
- package/dist/duckdb/types.js +0 -19
- package/dist/duckdb/types.js.map +0 -1
- package/dist/errors.d.ts +0 -62
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -149
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/kv/IKVService.d.ts +0 -148
- package/dist/kv/IKVService.d.ts.map +0 -1
- package/dist/kv/IKVService.js +0 -8
- package/dist/kv/IKVService.js.map +0 -1
- package/dist/kv/KVService.d.ts +0 -155
- package/dist/kv/KVService.d.ts.map +0 -1
- package/dist/kv/KVService.js +0 -419
- package/dist/kv/KVService.js.map +0 -1
- package/dist/kv/PrefixedKVService.d.ts +0 -246
- package/dist/kv/PrefixedKVService.d.ts.map +0 -1
- package/dist/kv/PrefixedKVService.js +0 -145
- package/dist/kv/PrefixedKVService.js.map +0 -1
- package/dist/kv/index.d.ts.map +0 -1
- package/dist/kv/types.d.ts +0 -204
- package/dist/kv/types.d.ts.map +0 -1
- package/dist/kv/types.js +0 -16
- package/dist/kv/types.js.map +0 -1
- package/dist/quota/TinyCloudQuota.d.ts +0 -27
- package/dist/quota/TinyCloudQuota.d.ts.map +0 -1
- package/dist/quota/TinyCloudQuota.js +0 -31
- package/dist/quota/TinyCloudQuota.js.map +0 -1
- package/dist/quota/index.d.ts +0 -3
- package/dist/quota/index.d.ts.map +0 -1
- package/dist/quota/index.js +0 -2
- package/dist/quota/index.js.map +0 -1
- package/dist/sql/DatabaseHandle.d.ts +0 -20
- package/dist/sql/DatabaseHandle.d.ts.map +0 -1
- package/dist/sql/DatabaseHandle.js +0 -27
- package/dist/sql/DatabaseHandle.js.map +0 -1
- package/dist/sql/ISQLService.d.ts +0 -67
- package/dist/sql/ISQLService.d.ts.map +0 -1
- package/dist/sql/ISQLService.js +0 -7
- package/dist/sql/ISQLService.js.map +0 -1
- package/dist/sql/SQLService.d.ts +0 -44
- package/dist/sql/SQLService.d.ts.map +0 -1
- package/dist/sql/SQLService.js +0 -216
- package/dist/sql/SQLService.js.map +0 -1
- package/dist/sql/index.d.ts.map +0 -1
- package/dist/sql/types.d.ts +0 -102
- package/dist/sql/types.d.ts.map +0 -1
- package/dist/sql/types.js +0 -21
- package/dist/sql/types.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -94
- package/dist/types.js.map +0 -1
- package/dist/types.schema.d.ts +0 -712
- package/dist/types.schema.d.ts.map +0 -1
- package/dist/types.schema.js +0 -342
- package/dist/types.schema.js.map +0 -1
- package/dist/types.schema.test.d.ts +0 -5
- package/dist/types.schema.test.d.ts.map +0 -1
- package/dist/types.schema.test.js +0 -677
- package/dist/types.schema.test.js.map +0 -1
- package/dist/vault/DataVaultService.d.ts +0 -258
- package/dist/vault/DataVaultService.d.ts.map +0 -1
- package/dist/vault/DataVaultService.js +0 -977
- package/dist/vault/DataVaultService.js.map +0 -1
- package/dist/vault/IDataVaultService.d.ts +0 -150
- package/dist/vault/IDataVaultService.d.ts.map +0 -1
- package/dist/vault/IDataVaultService.js +0 -8
- package/dist/vault/IDataVaultService.js.map +0 -1
- package/dist/vault/createVaultCrypto.d.ts +0 -16
- package/dist/vault/createVaultCrypto.d.ts.map +0 -1
- package/dist/vault/createVaultCrypto.js +0 -12
- package/dist/vault/createVaultCrypto.js.map +0 -1
- package/dist/vault/index.d.ts +0 -10
- package/dist/vault/index.d.ts.map +0 -1
- package/dist/vault/index.js +0 -11
- package/dist/vault/index.js.map +0 -1
- package/dist/vault/types.d.ts +0 -133
- package/dist/vault/types.d.ts.map +0 -1
- package/dist/vault/types.js +0 -23
- package/dist/vault/types.js.map +0 -1
package/dist/kv/KVService.js
DELETED
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* KVService - Key-Value storage service implementation.
|
|
3
|
-
*
|
|
4
|
-
* Platform-agnostic KV service that works with both web-sdk and node-sdk.
|
|
5
|
-
* Uses dependency injection via IServiceContext for platform dependencies.
|
|
6
|
-
*/
|
|
7
|
-
import { BaseService } from "../base/BaseService";
|
|
8
|
-
import { ok, err, ErrorCodes, serviceError, } from "../types";
|
|
9
|
-
import { authRequiredError, wrapError, storageQuotaExceededError, storageLimitReachedError, parseAuthError, authUnauthorizedError, } from "../errors";
|
|
10
|
-
import { PrefixedKVService } from "./PrefixedKVService";
|
|
11
|
-
import { KVAction, } from "./types";
|
|
12
|
-
/**
|
|
13
|
-
* KV service implementation.
|
|
14
|
-
*
|
|
15
|
-
* Provides key-value storage operations using TinyCloud's KV API.
|
|
16
|
-
* Uses the Result type pattern for explicit error handling.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Register with SDK
|
|
21
|
-
* const sdk = new TinyCloud({
|
|
22
|
-
* services: { kv: KVService },
|
|
23
|
-
* serviceConfigs: { kv: { prefix: 'myapp' } },
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* // Use the service
|
|
27
|
-
* const result = await sdk.kv.get('settings');
|
|
28
|
-
* if (result.ok) {
|
|
29
|
-
* console.log(result.data.data);
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export class KVService extends BaseService {
|
|
34
|
-
/**
|
|
35
|
-
* Create a new KVService instance.
|
|
36
|
-
*
|
|
37
|
-
* @param config - Service configuration
|
|
38
|
-
*/
|
|
39
|
-
constructor(config = {}) {
|
|
40
|
-
super();
|
|
41
|
-
this._config = config;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get the service configuration.
|
|
45
|
-
*/
|
|
46
|
-
get config() {
|
|
47
|
-
return this._config;
|
|
48
|
-
}
|
|
49
|
-
// Parses "Used: X bytes, Limit: Y bytes" from tinycloud-node error responses
|
|
50
|
-
parseQuotaInfo(errorText) {
|
|
51
|
-
const match = errorText.match(/Used:\s*(\d+)\s*bytes,\s*Limit:\s*(\d+)\s*bytes/i);
|
|
52
|
-
if (match) {
|
|
53
|
-
return {
|
|
54
|
-
usedBytes: parseInt(match[1], 10),
|
|
55
|
-
limitBytes: parseInt(match[2], 10),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
handleQuotaErrorResponse(response, errorText, key) {
|
|
61
|
-
if (response.status === 402) {
|
|
62
|
-
const quotaInfo = this.parseQuotaInfo(errorText);
|
|
63
|
-
return err(storageQuotaExceededError("kv", `Storage quota exceeded for key "${key}": ${errorText}`, {
|
|
64
|
-
status: response.status,
|
|
65
|
-
...(quotaInfo
|
|
66
|
-
? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes }
|
|
67
|
-
: {}),
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
if (response.status === 413) {
|
|
71
|
-
const quotaInfo = this.parseQuotaInfo(errorText);
|
|
72
|
-
return err(storageLimitReachedError("kv", `Storage limit reached for key "${key}": ${errorText}`, {
|
|
73
|
-
status: response.status,
|
|
74
|
-
...(quotaInfo
|
|
75
|
-
? { usedBytes: quotaInfo.usedBytes, limitBytes: quotaInfo.limitBytes }
|
|
76
|
-
: {}),
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get the full path with optional prefix.
|
|
83
|
-
*
|
|
84
|
-
* @param key - The key
|
|
85
|
-
* @param prefixOverride - Optional prefix override
|
|
86
|
-
* @returns The full path
|
|
87
|
-
*/
|
|
88
|
-
getFullPath(key, prefixOverride) {
|
|
89
|
-
const prefix = prefixOverride ?? this._config.prefix ?? "";
|
|
90
|
-
return prefix ? `${prefix}/${key}` : key;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Get the host URL.
|
|
94
|
-
*/
|
|
95
|
-
get host() {
|
|
96
|
-
return this.context.hosts[0];
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Execute an invoke operation.
|
|
100
|
-
*
|
|
101
|
-
* @param path - Resource path
|
|
102
|
-
* @param action - KV action
|
|
103
|
-
* @param body - Optional request body
|
|
104
|
-
* @param signal - Optional abort signal
|
|
105
|
-
* @returns Fetch response
|
|
106
|
-
*/
|
|
107
|
-
async invokeOperation(path, action, body, signal) {
|
|
108
|
-
const session = this.context.session;
|
|
109
|
-
const headers = this.context.invoke(session, "kv", path, action);
|
|
110
|
-
return this.context.fetch(`${this.host}/invoke`, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
headers,
|
|
113
|
-
body,
|
|
114
|
-
signal: this.combineSignals(signal),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Create KVResponseHeaders from fetch response headers.
|
|
119
|
-
*
|
|
120
|
-
* @param headers - Fetch response headers
|
|
121
|
-
* @returns KVResponseHeaders object
|
|
122
|
-
*/
|
|
123
|
-
createResponseHeaders(headers) {
|
|
124
|
-
return {
|
|
125
|
-
etag: headers.get("etag") ?? undefined,
|
|
126
|
-
contentType: headers.get("content-type") ?? undefined,
|
|
127
|
-
lastModified: headers.get("last-modified") ?? undefined,
|
|
128
|
-
contentLength: headers.get("content-length")
|
|
129
|
-
? parseInt(headers.get("content-length"), 10)
|
|
130
|
-
: undefined,
|
|
131
|
-
get: (name) => headers.get(name),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Parse response body based on content type.
|
|
136
|
-
*
|
|
137
|
-
* @param response - Fetch response
|
|
138
|
-
* @param raw - Whether to return raw text
|
|
139
|
-
* @returns Parsed data
|
|
140
|
-
*/
|
|
141
|
-
async parseResponse(response, raw = false) {
|
|
142
|
-
if (!response.ok) {
|
|
143
|
-
return undefined;
|
|
144
|
-
}
|
|
145
|
-
if (raw) {
|
|
146
|
-
return (await response.text());
|
|
147
|
-
}
|
|
148
|
-
const contentType = response.headers.get("content-type");
|
|
149
|
-
if (contentType?.includes("application/json")) {
|
|
150
|
-
return (await response.json());
|
|
151
|
-
}
|
|
152
|
-
else if (contentType?.startsWith("text/")) {
|
|
153
|
-
return (await response.text());
|
|
154
|
-
}
|
|
155
|
-
// No content-type header - try to parse as JSON, fall back to text
|
|
156
|
-
const text = await response.text();
|
|
157
|
-
if (!text) {
|
|
158
|
-
return undefined;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
return JSON.parse(text);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return text;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Get a value by key.
|
|
169
|
-
*/
|
|
170
|
-
async get(key, options) {
|
|
171
|
-
return this.withTelemetry("get", key, async () => {
|
|
172
|
-
if (!this.requireAuth()) {
|
|
173
|
-
return err(authRequiredError("kv"));
|
|
174
|
-
}
|
|
175
|
-
const path = this.getFullPath(key, options?.prefix);
|
|
176
|
-
try {
|
|
177
|
-
const response = await this.invokeOperation(path, KVAction.GET, undefined, options?.signal);
|
|
178
|
-
if (!response.ok) {
|
|
179
|
-
if (response.status === 401) {
|
|
180
|
-
const errorText = await response.text();
|
|
181
|
-
const { resource, action } = parseAuthError(errorText);
|
|
182
|
-
return err(authUnauthorizedError("kv", errorText, {
|
|
183
|
-
status: response.status,
|
|
184
|
-
...(action && { requiredAction: action }),
|
|
185
|
-
...(resource && { resource }),
|
|
186
|
-
}));
|
|
187
|
-
}
|
|
188
|
-
if (response.status === 404) {
|
|
189
|
-
return err(serviceError(ErrorCodes.KV_NOT_FOUND, `Key not found: ${key}`, "kv"));
|
|
190
|
-
}
|
|
191
|
-
const errorText = await response.text();
|
|
192
|
-
return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to get key "${key}": ${response.status} - ${errorText}`, "kv", { meta: { status: response.status, statusText: response.statusText } }));
|
|
193
|
-
}
|
|
194
|
-
const data = await this.parseResponse(response, options?.raw);
|
|
195
|
-
return ok({
|
|
196
|
-
data: data,
|
|
197
|
-
headers: this.createResponseHeaders(response.headers),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
return err(wrapError("kv", error));
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Store a value at a key.
|
|
207
|
-
*/
|
|
208
|
-
async put(key, value, options) {
|
|
209
|
-
return this.withTelemetry("put", key, async () => {
|
|
210
|
-
if (!this.requireAuth()) {
|
|
211
|
-
return err(authRequiredError("kv"));
|
|
212
|
-
}
|
|
213
|
-
const path = this.getFullPath(key, options?.prefix);
|
|
214
|
-
// Serialize value to string
|
|
215
|
-
let body;
|
|
216
|
-
if (typeof value === "string") {
|
|
217
|
-
body = value;
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
body = JSON.stringify(value);
|
|
221
|
-
}
|
|
222
|
-
try {
|
|
223
|
-
const response = await this.invokeOperation(path, KVAction.PUT, body, options?.signal);
|
|
224
|
-
if (!response.ok) {
|
|
225
|
-
if (response.status === 401) {
|
|
226
|
-
const errorText = await response.text();
|
|
227
|
-
const { resource, action } = parseAuthError(errorText);
|
|
228
|
-
return err(authUnauthorizedError("kv", errorText, {
|
|
229
|
-
status: response.status,
|
|
230
|
-
...(action && { requiredAction: action }),
|
|
231
|
-
...(resource && { resource }),
|
|
232
|
-
}));
|
|
233
|
-
}
|
|
234
|
-
const errorText = await response.text();
|
|
235
|
-
// Check for storage quota errors (402, 413)
|
|
236
|
-
const quotaError = this.handleQuotaErrorResponse(response, errorText, key);
|
|
237
|
-
if (quotaError) {
|
|
238
|
-
return quotaError;
|
|
239
|
-
}
|
|
240
|
-
return err(serviceError(ErrorCodes.KV_WRITE_FAILED, `Failed to put key "${key}": ${response.status} - ${errorText}`, "kv", { meta: { status: response.status, statusText: response.statusText } }));
|
|
241
|
-
}
|
|
242
|
-
return ok({
|
|
243
|
-
data: undefined,
|
|
244
|
-
headers: this.createResponseHeaders(response.headers),
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
catch (error) {
|
|
248
|
-
return err(wrapError("kv", error));
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* List keys with optional prefix filtering.
|
|
254
|
-
*/
|
|
255
|
-
async list(options) {
|
|
256
|
-
return this.withTelemetry("list", options?.prefix, async () => {
|
|
257
|
-
if (!this.requireAuth()) {
|
|
258
|
-
return err(authRequiredError("kv"));
|
|
259
|
-
}
|
|
260
|
-
// Build the path from prefix and optional path
|
|
261
|
-
let listPath = options?.prefix ?? this._config.prefix ?? "";
|
|
262
|
-
if (options?.path) {
|
|
263
|
-
listPath = listPath ? `${listPath}/${options.path}` : options.path;
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
const response = await this.invokeOperation(listPath, KVAction.LIST, undefined, options?.signal);
|
|
267
|
-
if (!response.ok) {
|
|
268
|
-
if (response.status === 401) {
|
|
269
|
-
const errorText = await response.text();
|
|
270
|
-
const { resource, action } = parseAuthError(errorText);
|
|
271
|
-
return err(authUnauthorizedError("kv", errorText, {
|
|
272
|
-
status: response.status,
|
|
273
|
-
...(action && { requiredAction: action }),
|
|
274
|
-
...(resource && { resource }),
|
|
275
|
-
}));
|
|
276
|
-
}
|
|
277
|
-
const errorText = await response.text();
|
|
278
|
-
return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to list keys: ${response.status} - ${errorText}`, "kv", { meta: { status: response.status, statusText: response.statusText } }));
|
|
279
|
-
}
|
|
280
|
-
let keys = await this.parseResponse(response, options?.raw);
|
|
281
|
-
keys = keys ?? [];
|
|
282
|
-
// Optionally remove prefix from keys
|
|
283
|
-
if (options?.removePrefix && listPath) {
|
|
284
|
-
const prefixWithSlash = listPath.endsWith("/")
|
|
285
|
-
? listPath
|
|
286
|
-
: `${listPath}/`;
|
|
287
|
-
keys = keys.map((key) => key.startsWith(prefixWithSlash)
|
|
288
|
-
? key.slice(prefixWithSlash.length)
|
|
289
|
-
: key);
|
|
290
|
-
}
|
|
291
|
-
return ok({ keys });
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
return err(wrapError("kv", error));
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Delete a key.
|
|
300
|
-
*/
|
|
301
|
-
async delete(key, options) {
|
|
302
|
-
return this.withTelemetry("delete", key, async () => {
|
|
303
|
-
if (!this.requireAuth()) {
|
|
304
|
-
return err(authRequiredError("kv"));
|
|
305
|
-
}
|
|
306
|
-
const path = this.getFullPath(key, options?.prefix);
|
|
307
|
-
try {
|
|
308
|
-
const response = await this.invokeOperation(path, KVAction.DELETE, undefined, options?.signal);
|
|
309
|
-
if (!response.ok) {
|
|
310
|
-
if (response.status === 401) {
|
|
311
|
-
const errorText = await response.text();
|
|
312
|
-
const { resource, action } = parseAuthError(errorText);
|
|
313
|
-
return err(authUnauthorizedError("kv", errorText, {
|
|
314
|
-
status: response.status,
|
|
315
|
-
...(action && { requiredAction: action }),
|
|
316
|
-
...(resource && { resource }),
|
|
317
|
-
}));
|
|
318
|
-
}
|
|
319
|
-
if (response.status === 404) {
|
|
320
|
-
return err(serviceError(ErrorCodes.KV_NOT_FOUND, `Key not found: ${key}`, "kv"));
|
|
321
|
-
}
|
|
322
|
-
const errorText = await response.text();
|
|
323
|
-
return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to delete key "${key}": ${response.status} - ${errorText}`, "kv", { meta: { status: response.status, statusText: response.statusText } }));
|
|
324
|
-
}
|
|
325
|
-
return ok(undefined);
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
return err(wrapError("kv", error));
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Get metadata for a key without retrieving the value.
|
|
334
|
-
*/
|
|
335
|
-
async head(key, options) {
|
|
336
|
-
return this.withTelemetry("head", key, async () => {
|
|
337
|
-
if (!this.requireAuth()) {
|
|
338
|
-
return err(authRequiredError("kv"));
|
|
339
|
-
}
|
|
340
|
-
const path = this.getFullPath(key, options?.prefix);
|
|
341
|
-
try {
|
|
342
|
-
const response = await this.invokeOperation(path, KVAction.HEAD, undefined, options?.signal);
|
|
343
|
-
if (!response.ok) {
|
|
344
|
-
if (response.status === 401) {
|
|
345
|
-
const errorText = await response.text();
|
|
346
|
-
const { resource, action } = parseAuthError(errorText);
|
|
347
|
-
return err(authUnauthorizedError("kv", errorText, {
|
|
348
|
-
status: response.status,
|
|
349
|
-
...(action && { requiredAction: action }),
|
|
350
|
-
...(resource && { resource }),
|
|
351
|
-
}));
|
|
352
|
-
}
|
|
353
|
-
if (response.status === 404) {
|
|
354
|
-
return err(serviceError(ErrorCodes.KV_NOT_FOUND, `Key not found: ${key}`, "kv"));
|
|
355
|
-
}
|
|
356
|
-
const errorText = await response.text();
|
|
357
|
-
return err(serviceError(ErrorCodes.NETWORK_ERROR, `Failed to get metadata for key "${key}": ${response.status} - ${errorText}`, "kv", { meta: { status: response.status, statusText: response.statusText } }));
|
|
358
|
-
}
|
|
359
|
-
return ok({
|
|
360
|
-
data: undefined,
|
|
361
|
-
headers: this.createResponseHeaders(response.headers),
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
catch (error) {
|
|
365
|
-
return err(wrapError("kv", error));
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Create a prefix-scoped view of this KV service.
|
|
371
|
-
*
|
|
372
|
-
* Returns a PrefixedKVService that automatically prefixes all
|
|
373
|
-
* key operations with the specified prefix. This enables apps
|
|
374
|
-
* to isolate their data within a shared space.
|
|
375
|
-
*
|
|
376
|
-
* @param prefix - The prefix to apply to all operations
|
|
377
|
-
* @returns A PrefixedKVService scoped to the prefix
|
|
378
|
-
*
|
|
379
|
-
* ## Prefix Conventions
|
|
380
|
-
*
|
|
381
|
-
* | Pattern | Use Case | Example |
|
|
382
|
-
* | -- | -- | -- |
|
|
383
|
-
* | `/app.{domain}/` | App-private data | `/app.photos.xyz/settings.json` |
|
|
384
|
-
* | `/{type}/` | Shared data type | `/photos/vacation.jpg` |
|
|
385
|
-
* | `/.{name}/` | Hidden/system data | `/.cache/thumbnails/` |
|
|
386
|
-
* | `/public/` | Explicitly shareable | `/public/profile.json` |
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* ```typescript
|
|
390
|
-
* const space = sdk.space('default');
|
|
391
|
-
*
|
|
392
|
-
* // Create prefix-scoped views
|
|
393
|
-
* const myApp = space.kv.withPrefix('/app.myapp.com');
|
|
394
|
-
* const sharedPhotos = space.kv.withPrefix('/photos');
|
|
395
|
-
*
|
|
396
|
-
* // Operations are automatically prefixed
|
|
397
|
-
* await myApp.put('settings.json', { theme: 'dark' });
|
|
398
|
-
* // -> Actually writes to: /app.myapp.com/settings.json
|
|
399
|
-
*
|
|
400
|
-
* await myApp.get('settings.json');
|
|
401
|
-
* // -> Actually reads from: /app.myapp.com/settings.json
|
|
402
|
-
*
|
|
403
|
-
* await sharedPhotos.list();
|
|
404
|
-
* // -> Lists: /photos/*
|
|
405
|
-
*
|
|
406
|
-
* // Nested prefixes
|
|
407
|
-
* const settings = myApp.withPrefix('/settings');
|
|
408
|
-
* await settings.get('theme.json'); // -> /app.myapp.com/settings/theme.json
|
|
409
|
-
* ```
|
|
410
|
-
*/
|
|
411
|
-
withPrefix(prefix) {
|
|
412
|
-
return new PrefixedKVService(this, prefix);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Service identifier for registration.
|
|
417
|
-
*/
|
|
418
|
-
KVService.serviceName = "kv";
|
|
419
|
-
//# sourceMappingURL=KVService.js.map
|
package/dist/kv/KVService.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KVService.js","sourceRoot":"","sources":["../../src/kv/KVService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAEL,EAAE,EACF,GAAG,EACH,UAAU,EACV,YAAY,GAEb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAUL,QAAQ,GACT,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IAWxC;;;;OAIG;IACH,YAAY,SAA0B,EAAE;QACtC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,6EAA6E;IACrE,cAAc,CACpB,SAAiB;QAEjB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAC3B,kDAAkD,CACnD,CAAC;QACF,IAAI,KAAK,EAAE,CAAC;YACV,OAAO;gBACL,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;gBACjC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;aACnC,CAAC;QACJ,CAAC;QACD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C;yBAC9B,CAAC,CAAC,CAAC;oBACN,CAAC;oBAED,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;wBAC5B,OAAO,GAAG,CACR,YAAY,CACV,UAAU,CAAC,YAAY,EACvB,kBAAkB,GAAG,EAAE,EACvB,IAAI,CACL,CACF,CAAC;oBACJ,CAAC;oBAED,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;oBACxC,OAAO,GAAG,CACR,YAAY,CACV,UAAU,CAAC,aAAa,EACxB,mCAAmC,GAAG,MAAM,QAAQ,CAAC,MAAM,MAAM,SAAS,EAAE,EAC5E,IAAI,EACJ,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,EAAE,CACvE,CACF,CAAC;gBACJ,CAAC;gBAED,OAAO,EAAE,CAAC;oBACR,IAAI,EAAE,SAAiB;oBACvB,OAAO,EAAE,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,OAAO,CAAC;iBACtD,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;YACrC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;;AAnjBD;;GAEG;AACa,qBAAW,GAAG,IAAI,CAAC"}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PrefixedKVService - A prefix-scoped view of KVService.
|
|
3
|
-
*
|
|
4
|
-
* Provides key-value operations scoped to a specific prefix.
|
|
5
|
-
* All operations automatically prefix keys, enabling app data isolation
|
|
6
|
-
* within a shared space.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const space = sdk.space('default');
|
|
11
|
-
*
|
|
12
|
-
* // Create prefix-scoped views
|
|
13
|
-
* const myApp = space.kv.withPrefix('/app.myapp.com');
|
|
14
|
-
* const sharedPhotos = space.kv.withPrefix('/photos');
|
|
15
|
-
*
|
|
16
|
-
* // Operations are automatically prefixed
|
|
17
|
-
* await myApp.put('settings.json', { theme: 'dark' });
|
|
18
|
-
* // -> Actually writes to: /app.myapp.com/settings.json
|
|
19
|
-
*
|
|
20
|
-
* await myApp.get('settings.json');
|
|
21
|
-
* // -> Actually reads from: /app.myapp.com/settings.json
|
|
22
|
-
*
|
|
23
|
-
* await sharedPhotos.list();
|
|
24
|
-
* // -> Lists: /photos/*
|
|
25
|
-
*
|
|
26
|
-
* // Nested prefixes
|
|
27
|
-
* const settings = myApp.withPrefix('/settings');
|
|
28
|
-
* await settings.get('theme.json'); // -> /app.myapp.com/settings/theme.json
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
import { Result } from "../types";
|
|
32
|
-
import { KVGetOptions, KVPutOptions, KVListOptions, KVDeleteOptions, KVHeadOptions, KVResponse, KVListResponse } from "./types";
|
|
33
|
-
/**
|
|
34
|
-
* Interface for prefixed KV operations.
|
|
35
|
-
*
|
|
36
|
-
* Provides the same operations as IKVService but scoped to a prefix.
|
|
37
|
-
* Supports nested prefixes via withPrefix().
|
|
38
|
-
*/
|
|
39
|
-
export interface IPrefixedKVService {
|
|
40
|
-
/**
|
|
41
|
-
* The current prefix for this scoped view.
|
|
42
|
-
*/
|
|
43
|
-
readonly prefix: string;
|
|
44
|
-
/**
|
|
45
|
-
* Get a value by key.
|
|
46
|
-
*
|
|
47
|
-
* The key is automatically prefixed with this service's prefix.
|
|
48
|
-
*
|
|
49
|
-
* @param key - The key to retrieve (will be prefixed)
|
|
50
|
-
* @param options - Optional get configuration
|
|
51
|
-
* @returns Result with the stored value and headers
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
56
|
-
* const result = await myApp.get('settings.json');
|
|
57
|
-
* // -> Reads from: /app.myapp.com/settings.json
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
get<T = unknown>(key: string, options?: Omit<KVGetOptions, 'prefix'>): Promise<Result<KVResponse<T>>>;
|
|
61
|
-
/**
|
|
62
|
-
* Store a value at a key.
|
|
63
|
-
*
|
|
64
|
-
* The key is automatically prefixed with this service's prefix.
|
|
65
|
-
*
|
|
66
|
-
* @param key - The key to store under (will be prefixed)
|
|
67
|
-
* @param value - The value to store
|
|
68
|
-
* @param options - Optional put configuration
|
|
69
|
-
* @returns Result indicating success/failure
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
74
|
-
* await myApp.put('settings.json', { theme: 'dark' });
|
|
75
|
-
* // -> Stores at: /app.myapp.com/settings.json
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
put(key: string, value: unknown, options?: Omit<KVPutOptions, 'prefix'>): Promise<Result<KVResponse<void>>>;
|
|
79
|
-
/**
|
|
80
|
-
* List keys within this prefix.
|
|
81
|
-
*
|
|
82
|
-
* Returns keys that match the prefix, with keys returned relative
|
|
83
|
-
* to the prefix when removePrefix is true (default for prefixed service).
|
|
84
|
-
*
|
|
85
|
-
* @param options - Optional list configuration
|
|
86
|
-
* @returns Result with array of matching keys
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ```typescript
|
|
90
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
91
|
-
* const result = await myApp.list();
|
|
92
|
-
* // -> Lists keys under: /app.myapp.com/*
|
|
93
|
-
* // Returns: ['settings.json', 'data/user.json', ...]
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
list(options?: Omit<KVListOptions, 'prefix'>): Promise<Result<KVListResponse>>;
|
|
97
|
-
/**
|
|
98
|
-
* Delete a key.
|
|
99
|
-
*
|
|
100
|
-
* The key is automatically prefixed with this service's prefix.
|
|
101
|
-
*
|
|
102
|
-
* @param key - The key to delete (will be prefixed)
|
|
103
|
-
* @param options - Optional delete configuration
|
|
104
|
-
* @returns Result indicating success/failure
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
109
|
-
* await myApp.delete('old-settings.json');
|
|
110
|
-
* // -> Deletes: /app.myapp.com/old-settings.json
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
delete(key: string, options?: Omit<KVDeleteOptions, 'prefix'>): Promise<Result<void>>;
|
|
114
|
-
/**
|
|
115
|
-
* Get metadata for a key without retrieving the value.
|
|
116
|
-
*
|
|
117
|
-
* The key is automatically prefixed with this service's prefix.
|
|
118
|
-
*
|
|
119
|
-
* @param key - The key to check (will be prefixed)
|
|
120
|
-
* @param options - Optional head configuration
|
|
121
|
-
* @returns Result with headers only
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
126
|
-
* const result = await myApp.head('large-file.bin');
|
|
127
|
-
* // -> Gets metadata for: /app.myapp.com/large-file.bin
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
head(key: string, options?: Omit<KVHeadOptions, 'prefix'>): Promise<Result<KVResponse<void>>>;
|
|
131
|
-
/**
|
|
132
|
-
* Create a nested prefix-scoped view.
|
|
133
|
-
*
|
|
134
|
-
* The subPrefix is appended to the current prefix.
|
|
135
|
-
*
|
|
136
|
-
* @param subPrefix - The sub-prefix to append
|
|
137
|
-
* @returns A new PrefixedKVService with the combined prefix
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* const myApp = kv.withPrefix('/app.myapp.com');
|
|
142
|
-
* const settings = myApp.withPrefix('/settings');
|
|
143
|
-
* await settings.get('theme.json');
|
|
144
|
-
* // -> Reads from: /app.myapp.com/settings/theme.json
|
|
145
|
-
* ```
|
|
146
|
-
*/
|
|
147
|
-
withPrefix(subPrefix: string): IPrefixedKVService;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Interface for a KV service that supports prefix delegation.
|
|
151
|
-
*
|
|
152
|
-
* This is the subset of IKVService methods needed by PrefixedKVService.
|
|
153
|
-
*/
|
|
154
|
-
interface IKVServiceLike {
|
|
155
|
-
get<T = unknown>(key: string, options?: KVGetOptions): Promise<Result<KVResponse<T>>>;
|
|
156
|
-
put(key: string, value: unknown, options?: KVPutOptions): Promise<Result<KVResponse<void>>>;
|
|
157
|
-
list(options?: KVListOptions): Promise<Result<KVListResponse>>;
|
|
158
|
-
delete(key: string, options?: KVDeleteOptions): Promise<Result<void>>;
|
|
159
|
-
head(key: string, options?: KVHeadOptions): Promise<Result<KVResponse<void>>>;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* PrefixedKVService - Implementation of prefix-scoped KV operations.
|
|
163
|
-
*
|
|
164
|
-
* This class wraps a KVService (or another PrefixedKVService) and
|
|
165
|
-
* automatically prefixes all key operations with the configured prefix.
|
|
166
|
-
*
|
|
167
|
-
* ## Prefix Convention
|
|
168
|
-
*
|
|
169
|
-
* | Pattern | Use Case | Example |
|
|
170
|
-
* | -- | -- | -- |
|
|
171
|
-
* | `/app.{domain}/` | App-private data | `/app.photos.xyz/settings.json` |
|
|
172
|
-
* | `/{type}/` | Shared data type | `/photos/vacation.jpg` |
|
|
173
|
-
* | `/.{name}/` | Hidden/system data | `/.cache/thumbnails/` |
|
|
174
|
-
* | `/public/` | Explicitly shareable | `/public/profile.json` |
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* // Create from KVService
|
|
179
|
-
* const prefixed = new PrefixedKVService(kvService, '/app.myapp.com');
|
|
180
|
-
*
|
|
181
|
-
* // Or use the withPrefix factory method on KVService
|
|
182
|
-
* const prefixed = kvService.withPrefix('/app.myapp.com');
|
|
183
|
-
*
|
|
184
|
-
* // All operations are automatically prefixed
|
|
185
|
-
* await prefixed.put('settings.json', { theme: 'dark' });
|
|
186
|
-
* await prefixed.get('settings.json');
|
|
187
|
-
*
|
|
188
|
-
* // Nested prefixes
|
|
189
|
-
* const nested = prefixed.withPrefix('/settings');
|
|
190
|
-
* await nested.get('theme.json'); // -> /app.myapp.com/settings/theme.json
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
export declare class PrefixedKVService implements IPrefixedKVService {
|
|
194
|
-
/**
|
|
195
|
-
* The underlying KV service.
|
|
196
|
-
*/
|
|
197
|
-
private readonly _kv;
|
|
198
|
-
/**
|
|
199
|
-
* The prefix for this scoped view.
|
|
200
|
-
*/
|
|
201
|
-
private readonly _prefix;
|
|
202
|
-
/**
|
|
203
|
-
* Create a new PrefixedKVService.
|
|
204
|
-
*
|
|
205
|
-
* @param kv - The underlying KV service to delegate to
|
|
206
|
-
* @param prefix - The prefix to apply to all operations
|
|
207
|
-
*/
|
|
208
|
-
constructor(kv: IKVServiceLike, prefix: string);
|
|
209
|
-
/**
|
|
210
|
-
* The current prefix for this scoped view.
|
|
211
|
-
*/
|
|
212
|
-
get prefix(): string;
|
|
213
|
-
/**
|
|
214
|
-
* Compute the full key path by combining prefix and key.
|
|
215
|
-
*
|
|
216
|
-
* @param key - The key to prefix
|
|
217
|
-
* @returns The full path including prefix
|
|
218
|
-
*/
|
|
219
|
-
private getFullKey;
|
|
220
|
-
/**
|
|
221
|
-
* Get a value by key.
|
|
222
|
-
*/
|
|
223
|
-
get<T = unknown>(key: string, options?: Omit<KVGetOptions, 'prefix'>): Promise<Result<KVResponse<T>>>;
|
|
224
|
-
/**
|
|
225
|
-
* Store a value at a key.
|
|
226
|
-
*/
|
|
227
|
-
put(key: string, value: unknown, options?: Omit<KVPutOptions, 'prefix'>): Promise<Result<KVResponse<void>>>;
|
|
228
|
-
/**
|
|
229
|
-
* List keys within this prefix.
|
|
230
|
-
*/
|
|
231
|
-
list(options?: Omit<KVListOptions, 'prefix'>): Promise<Result<KVListResponse>>;
|
|
232
|
-
/**
|
|
233
|
-
* Delete a key.
|
|
234
|
-
*/
|
|
235
|
-
delete(key: string, options?: Omit<KVDeleteOptions, 'prefix'>): Promise<Result<void>>;
|
|
236
|
-
/**
|
|
237
|
-
* Get metadata for a key without retrieving the value.
|
|
238
|
-
*/
|
|
239
|
-
head(key: string, options?: Omit<KVHeadOptions, 'prefix'>): Promise<Result<KVResponse<void>>>;
|
|
240
|
-
/**
|
|
241
|
-
* Create a nested prefix-scoped view.
|
|
242
|
-
*/
|
|
243
|
-
withPrefix(subPrefix: string): IPrefixedKVService;
|
|
244
|
-
}
|
|
245
|
-
export {};
|
|
246
|
-
//# sourceMappingURL=PrefixedKVService.d.ts.map
|