@tinycloudlabs/sdk-services 1.0.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.
Files changed (57) hide show
  1. package/dist/base/BaseService.d.ts +151 -0
  2. package/dist/base/BaseService.d.ts.map +1 -0
  3. package/dist/base/BaseService.js +221 -0
  4. package/dist/base/BaseService.js.map +1 -0
  5. package/dist/base/index.d.ts +6 -0
  6. package/dist/base/index.d.ts.map +1 -0
  7. package/dist/base/index.js +6 -0
  8. package/dist/base/index.js.map +1 -0
  9. package/dist/base/types.d.ts +36 -0
  10. package/dist/base/types.d.ts.map +1 -0
  11. package/dist/base/types.js +7 -0
  12. package/dist/base/types.js.map +1 -0
  13. package/dist/context.d.ts +142 -0
  14. package/dist/context.d.ts.map +1 -0
  15. package/dist/context.js +218 -0
  16. package/dist/context.js.map +1 -0
  17. package/dist/errors.d.ts +43 -0
  18. package/dist/errors.d.ts.map +1 -0
  19. package/dist/errors.js +111 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +47 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +53 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/kv/IKVService.d.ts +148 -0
  26. package/dist/kv/IKVService.d.ts.map +1 -0
  27. package/dist/kv/IKVService.js +8 -0
  28. package/dist/kv/IKVService.js.map +1 -0
  29. package/dist/kv/KVService.d.ts +153 -0
  30. package/dist/kv/KVService.d.ts.map +1 -0
  31. package/dist/kv/KVService.js +337 -0
  32. package/dist/kv/KVService.js.map +1 -0
  33. package/dist/kv/PrefixedKVService.d.ts +246 -0
  34. package/dist/kv/PrefixedKVService.d.ts.map +1 -0
  35. package/dist/kv/PrefixedKVService.js +145 -0
  36. package/dist/kv/PrefixedKVService.js.map +1 -0
  37. package/dist/kv/index.d.ts +10 -0
  38. package/dist/kv/index.d.ts.map +1 -0
  39. package/dist/kv/index.js +12 -0
  40. package/dist/kv/index.js.map +1 -0
  41. package/dist/kv/types.d.ts +204 -0
  42. package/dist/kv/types.d.ts.map +1 -0
  43. package/dist/kv/types.js +16 -0
  44. package/dist/kv/types.js.map +1 -0
  45. package/dist/types.d.ts +259 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +72 -0
  48. package/dist/types.js.map +1 -0
  49. package/dist/types.schema.d.ts +652 -0
  50. package/dist/types.schema.d.ts.map +1 -0
  51. package/dist/types.schema.js +342 -0
  52. package/dist/types.schema.js.map +1 -0
  53. package/dist/types.schema.test.d.ts +5 -0
  54. package/dist/types.schema.test.d.ts.map +1 -0
  55. package/dist/types.schema.test.js +677 -0
  56. package/dist/types.schema.test.js.map +1 -0
  57. package/package.json +42 -0
@@ -0,0 +1,246 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrefixedKVService.d.ts","sourceRoot":"","sources":["../../src/kv/PrefixedKVService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,UAAU,EACV,cAAc,EACf,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;;;;;;;;;;;;;;OAeG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EACb,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GACrC,O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AAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAUpF;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAK3F;;OAEG;IACG,IAAI,CACR,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAKpC;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB;CAQlD"}
@@ -0,0 +1,145 @@
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
+ /**
32
+ * PrefixedKVService - Implementation of prefix-scoped KV operations.
33
+ *
34
+ * This class wraps a KVService (or another PrefixedKVService) and
35
+ * automatically prefixes all key operations with the configured prefix.
36
+ *
37
+ * ## Prefix Convention
38
+ *
39
+ * | Pattern | Use Case | Example |
40
+ * | -- | -- | -- |
41
+ * | `/app.{domain}/` | App-private data | `/app.photos.xyz/settings.json` |
42
+ * | `/{type}/` | Shared data type | `/photos/vacation.jpg` |
43
+ * | `/.{name}/` | Hidden/system data | `/.cache/thumbnails/` |
44
+ * | `/public/` | Explicitly shareable | `/public/profile.json` |
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Create from KVService
49
+ * const prefixed = new PrefixedKVService(kvService, '/app.myapp.com');
50
+ *
51
+ * // Or use the withPrefix factory method on KVService
52
+ * const prefixed = kvService.withPrefix('/app.myapp.com');
53
+ *
54
+ * // All operations are automatically prefixed
55
+ * await prefixed.put('settings.json', { theme: 'dark' });
56
+ * await prefixed.get('settings.json');
57
+ *
58
+ * // Nested prefixes
59
+ * const nested = prefixed.withPrefix('/settings');
60
+ * await nested.get('theme.json'); // -> /app.myapp.com/settings/theme.json
61
+ * ```
62
+ */
63
+ export class PrefixedKVService {
64
+ /**
65
+ * Create a new PrefixedKVService.
66
+ *
67
+ * @param kv - The underlying KV service to delegate to
68
+ * @param prefix - The prefix to apply to all operations
69
+ */
70
+ constructor(kv, prefix) {
71
+ this._kv = kv;
72
+ // Normalize prefix: ensure it doesn't end with slash
73
+ this._prefix = prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
74
+ }
75
+ /**
76
+ * The current prefix for this scoped view.
77
+ */
78
+ get prefix() {
79
+ return this._prefix;
80
+ }
81
+ /**
82
+ * Compute the full key path by combining prefix and key.
83
+ *
84
+ * @param key - The key to prefix
85
+ * @returns The full path including prefix
86
+ */
87
+ getFullKey(key) {
88
+ // Handle keys that start with slash
89
+ const normalizedKey = key.startsWith('/') ? key : `/${key}`;
90
+ return `${this._prefix}${normalizedKey}`;
91
+ }
92
+ /**
93
+ * Get a value by key.
94
+ */
95
+ async get(key, options) {
96
+ const fullKey = this.getFullKey(key);
97
+ // Use empty prefix override to use the full key as-is
98
+ return this._kv.get(fullKey, { ...options, prefix: '' });
99
+ }
100
+ /**
101
+ * Store a value at a key.
102
+ */
103
+ async put(key, value, options) {
104
+ const fullKey = this.getFullKey(key);
105
+ return this._kv.put(fullKey, value, { ...options, prefix: '' });
106
+ }
107
+ /**
108
+ * List keys within this prefix.
109
+ */
110
+ async list(options) {
111
+ // List uses the prefix directly, and by default removes the prefix from results
112
+ const removePrefix = options?.removePrefix ?? true;
113
+ return this._kv.list({
114
+ ...options,
115
+ prefix: this._prefix,
116
+ removePrefix,
117
+ });
118
+ }
119
+ /**
120
+ * Delete a key.
121
+ */
122
+ async delete(key, options) {
123
+ const fullKey = this.getFullKey(key);
124
+ return this._kv.delete(fullKey, { ...options, prefix: '' });
125
+ }
126
+ /**
127
+ * Get metadata for a key without retrieving the value.
128
+ */
129
+ async head(key, options) {
130
+ const fullKey = this.getFullKey(key);
131
+ return this._kv.head(fullKey, { ...options, prefix: '' });
132
+ }
133
+ /**
134
+ * Create a nested prefix-scoped view.
135
+ */
136
+ withPrefix(subPrefix) {
137
+ // Normalize subPrefix
138
+ const normalizedSubPrefix = subPrefix.startsWith('/')
139
+ ? subPrefix
140
+ : `/${subPrefix}`;
141
+ const combinedPrefix = `${this._prefix}${normalizedSubPrefix}`;
142
+ return new PrefixedKVService(this._kv, combinedPrefix);
143
+ }
144
+ }
145
+ //# sourceMappingURL=PrefixedKVService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrefixedKVService.js","sourceRoot":"","sources":["../../src/kv/PrefixedKVService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAuKH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,iBAAiB;IAW5B;;;;;OAKG;IACH,YAAY,EAAkB,EAAE,MAAc;QAC5C,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,qDAAqD;QACrD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,C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CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,GAAW,EAAE,OAAyC;QACjE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CACR,GAAW,EACX,OAAuC;QAEvC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,SAAiB;QAC1B,sBAAsB;QACtB,MAAM,mBAAmB,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC;YACnD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;QACpB,MAAM,cAAc,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,mBAAmB,EAAE,CAAC;QAC/D,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACzD,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * KV Service Exports
3
+ *
4
+ * Key-Value storage service for TinyCloud SDK.
5
+ */
6
+ export { KVService } from "./KVService";
7
+ export { PrefixedKVService, IPrefixedKVService } from "./PrefixedKVService";
8
+ export { IKVService } from "./IKVService";
9
+ export { KVServiceConfig, KVGetOptions, KVPutOptions, KVListOptions, KVDeleteOptions, KVHeadOptions, KVResponse, KVListResponse, KVResponseHeaders, KVAction, KVActionType, } from "./types";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG5E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EACL,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,aAAa,EACb,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * KV Service Exports
3
+ *
4
+ * Key-Value storage service for TinyCloud SDK.
5
+ */
6
+ // Service implementation
7
+ export { KVService } from "./KVService";
8
+ // Prefixed service implementation
9
+ export { PrefixedKVService } from "./PrefixedKVService";
10
+ // Types
11
+ export { KVAction, } from "./types";
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,yBAAyB;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AAK5E,QAAQ;AACR,OAAO,EAUL,QAAQ,GAET,MAAM,SAAS,CAAC"}
@@ -0,0 +1,204 @@
1
+ /**
2
+ * KV Service Types
3
+ *
4
+ * Type definitions for the KV (Key-Value) service operations.
5
+ */
6
+ /**
7
+ * Configuration for KVService.
8
+ */
9
+ export interface KVServiceConfig {
10
+ /**
11
+ * Default prefix for all keys.
12
+ * Useful for namespacing data within a space.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const kv = new KVService({ prefix: 'myapp/settings' });
17
+ * await kv.put('theme', 'dark'); // Stores at 'myapp/settings/theme'
18
+ * ```
19
+ */
20
+ prefix?: string;
21
+ /**
22
+ * Default timeout in milliseconds for KV operations.
23
+ * Overrides the context-level timeout if set.
24
+ */
25
+ timeout?: number;
26
+ /** Allow additional config properties */
27
+ [key: string]: unknown;
28
+ }
29
+ /**
30
+ * Options for KV get operations.
31
+ */
32
+ export interface KVGetOptions {
33
+ /**
34
+ * Override the default prefix for this operation.
35
+ */
36
+ prefix?: string;
37
+ /**
38
+ * Return raw response instead of parsed JSON.
39
+ * When true, data will be the raw response text.
40
+ */
41
+ raw?: boolean;
42
+ /**
43
+ * Custom timeout for this operation in milliseconds.
44
+ */
45
+ timeout?: number;
46
+ /**
47
+ * Custom abort signal for this operation.
48
+ */
49
+ signal?: AbortSignal;
50
+ }
51
+ /**
52
+ * Options for KV put operations.
53
+ */
54
+ export interface KVPutOptions {
55
+ /**
56
+ * Override the default prefix for this operation.
57
+ */
58
+ prefix?: string;
59
+ /**
60
+ * Content type for the value.
61
+ * Defaults to 'application/json' for objects.
62
+ */
63
+ contentType?: string;
64
+ /**
65
+ * Custom metadata headers to store with the value.
66
+ */
67
+ metadata?: Record<string, string>;
68
+ /**
69
+ * Custom timeout for this operation in milliseconds.
70
+ */
71
+ timeout?: number;
72
+ /**
73
+ * Custom abort signal for this operation.
74
+ */
75
+ signal?: AbortSignal;
76
+ }
77
+ /**
78
+ * Options for KV list operations.
79
+ */
80
+ export interface KVListOptions {
81
+ /**
82
+ * Override the default prefix for this operation.
83
+ */
84
+ prefix?: string;
85
+ /**
86
+ * Additional path to append to the prefix.
87
+ */
88
+ path?: string;
89
+ /**
90
+ * Whether to remove the prefix from returned keys.
91
+ * When true, keys are returned relative to the prefix.
92
+ */
93
+ removePrefix?: boolean;
94
+ /**
95
+ * Return raw response instead of parsed JSON.
96
+ */
97
+ raw?: boolean;
98
+ /**
99
+ * Custom timeout for this operation in milliseconds.
100
+ */
101
+ timeout?: number;
102
+ /**
103
+ * Custom abort signal for this operation.
104
+ */
105
+ signal?: AbortSignal;
106
+ }
107
+ /**
108
+ * Options for KV delete operations.
109
+ */
110
+ export interface KVDeleteOptions {
111
+ /**
112
+ * Override the default prefix for this operation.
113
+ */
114
+ prefix?: string;
115
+ /**
116
+ * Custom timeout for this operation in milliseconds.
117
+ */
118
+ timeout?: number;
119
+ /**
120
+ * Custom abort signal for this operation.
121
+ */
122
+ signal?: AbortSignal;
123
+ }
124
+ /**
125
+ * Options for KV head (metadata) operations.
126
+ */
127
+ export interface KVHeadOptions {
128
+ /**
129
+ * Override the default prefix for this operation.
130
+ */
131
+ prefix?: string;
132
+ /**
133
+ * Custom timeout for this operation in milliseconds.
134
+ */
135
+ timeout?: number;
136
+ /**
137
+ * Custom abort signal for this operation.
138
+ */
139
+ signal?: AbortSignal;
140
+ }
141
+ /**
142
+ * Response headers from KV operations.
143
+ */
144
+ export interface KVResponseHeaders {
145
+ /**
146
+ * ETag for conditional requests.
147
+ */
148
+ etag?: string;
149
+ /**
150
+ * Content type of the stored value.
151
+ */
152
+ contentType?: string;
153
+ /**
154
+ * Last modification timestamp.
155
+ */
156
+ lastModified?: string;
157
+ /**
158
+ * Content length in bytes.
159
+ */
160
+ contentLength?: number;
161
+ /**
162
+ * Get a header value by name.
163
+ * @param name - Header name (case-insensitive)
164
+ */
165
+ get(name: string): string | null;
166
+ }
167
+ /**
168
+ * Response from KV get/put operations.
169
+ *
170
+ * @template T - Type of the data payload
171
+ */
172
+ export interface KVResponse<T = unknown> {
173
+ /**
174
+ * The data payload.
175
+ * For get: the stored value.
176
+ * For put: undefined.
177
+ */
178
+ data: T;
179
+ /**
180
+ * Response headers with metadata.
181
+ */
182
+ headers: KVResponseHeaders;
183
+ }
184
+ /**
185
+ * Response from KV list operations.
186
+ */
187
+ export interface KVListResponse {
188
+ /**
189
+ * Array of keys matching the list criteria.
190
+ */
191
+ keys: string[];
192
+ }
193
+ /**
194
+ * KV service action types.
195
+ */
196
+ export declare const KVAction: {
197
+ readonly GET: "tinycloud.kv/get";
198
+ readonly PUT: "tinycloud.kv/put";
199
+ readonly LIST: "tinycloud.kv/list";
200
+ readonly DELETE: "tinycloud.kv/del";
201
+ readonly HEAD: "tinycloud.kv/metadata";
202
+ };
203
+ export type KVActionType = (typeof KVAction)[keyof typeof KVAction];
204
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/kv/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yCAAyC;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,YAAY,CAAC,EAAE,OA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QAAQ,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * KV Service Types
3
+ *
4
+ * Type definitions for the KV (Key-Value) service operations.
5
+ */
6
+ /**
7
+ * KV service action types.
8
+ */
9
+ export const KVAction = {
10
+ GET: "tinycloud.kv/get",
11
+ PUT: "tinycloud.kv/put",
12
+ LIST: "tinycloud.kv/list",
13
+ DELETE: "tinycloud.kv/del",
14
+ HEAD: "tinycloud.kv/metadata",
15
+ };
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/kv/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA6NH;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,kBAAkB;IACvB,IAAI,EAAE,mBAAmB;IACzB,MAAM,EAAE,kBAAkB;IAC1B,IAAI,EAAE,uBAAuB;CACrB,CAAC"}