@thewhateverapp/platform 0.9.16 → 0.9.18
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/kv/index.d.ts +6 -16
- package/dist/kv/index.d.ts.map +1 -1
- package/dist/kv/index.js +16 -34
- package/dist/kv/index.js.map +1 -1
- package/package.json +1 -1
package/dist/kv/index.d.ts
CHANGED
|
@@ -2,26 +2,21 @@
|
|
|
2
2
|
* Edge KV (Key-Value) Storage API
|
|
3
3
|
*
|
|
4
4
|
* Provides a simple key-value store interface for user-generated apps.
|
|
5
|
-
* Automatically selects the appropriate provider based on environment configuration.
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
8
7
|
* ```typescript
|
|
9
|
-
* import {
|
|
10
|
-
* import { configurePlatformEnv, getKV } from '@thewhateverapp/platform';
|
|
8
|
+
* import { getKV } from '@thewhateverapp/platform';
|
|
11
9
|
*
|
|
12
|
-
* export async function GET(
|
|
13
|
-
*
|
|
14
|
-
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
-
*
|
|
16
|
-
* const kv = await getKV();
|
|
10
|
+
* export async function GET() {
|
|
11
|
+
* const kv = getKV();
|
|
17
12
|
*
|
|
18
13
|
* // Store data
|
|
19
|
-
* await kv.
|
|
14
|
+
* await kv.put('user:123', JSON.stringify({ name: 'Alice', score: 100 }));
|
|
20
15
|
*
|
|
21
16
|
* // Retrieve data
|
|
22
17
|
* const user = await kv.get('user:123', 'json');
|
|
23
18
|
*
|
|
24
|
-
* return
|
|
19
|
+
* return Response.json(user);
|
|
25
20
|
* }
|
|
26
21
|
* ```
|
|
27
22
|
*/
|
|
@@ -30,18 +25,13 @@ export type * from './types';
|
|
|
30
25
|
/**
|
|
31
26
|
* Get a KV instance for the current request
|
|
32
27
|
*
|
|
33
|
-
* Automatically selects the appropriate provider based on environment:
|
|
34
|
-
* - 'cloudflare' (default): Cloudflare KV
|
|
35
|
-
* - 'upstash': Upstash Redis
|
|
36
|
-
* - 'vercel': Vercel KV
|
|
37
|
-
*
|
|
38
28
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
29
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
40
30
|
* @returns KV provider instance
|
|
41
31
|
*/
|
|
42
32
|
export declare function getKV(req?: KVRequest | {
|
|
43
33
|
env: CloudflareKVEnv;
|
|
44
|
-
} | CloudflareKVEnv):
|
|
34
|
+
} | CloudflareKVEnv): KVProvider;
|
|
45
35
|
/**
|
|
46
36
|
* Create a KV instance directly (for advanced usage)
|
|
47
37
|
*
|
package/dist/kv/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKtE,mBAAmB,SAAS,CAAC;AAE7B;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,GAAG;IAAE,GAAG,EAAE,eAAe,CAAA;CAAE,GAAG,eAAe,GAAG,UAAU,CAuC9F;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,eAAe,GAAG,UAAU,CAezD"}
|
package/dist/kv/index.js
CHANGED
|
@@ -2,26 +2,21 @@
|
|
|
2
2
|
* Edge KV (Key-Value) Storage API
|
|
3
3
|
*
|
|
4
4
|
* Provides a simple key-value store interface for user-generated apps.
|
|
5
|
-
* Automatically selects the appropriate provider based on environment configuration.
|
|
6
5
|
*
|
|
7
6
|
* @example
|
|
8
7
|
* ```typescript
|
|
9
|
-
* import {
|
|
10
|
-
* import { configurePlatformEnv, getKV } from '@thewhateverapp/platform';
|
|
8
|
+
* import { getKV } from '@thewhateverapp/platform';
|
|
11
9
|
*
|
|
12
|
-
* export async function GET(
|
|
13
|
-
*
|
|
14
|
-
* configurePlatformEnv(() => getCloudflareContext().env);
|
|
15
|
-
*
|
|
16
|
-
* const kv = await getKV();
|
|
10
|
+
* export async function GET() {
|
|
11
|
+
* const kv = getKV();
|
|
17
12
|
*
|
|
18
13
|
* // Store data
|
|
19
|
-
* await kv.
|
|
14
|
+
* await kv.put('user:123', JSON.stringify({ name: 'Alice', score: 100 }));
|
|
20
15
|
*
|
|
21
16
|
* // Retrieve data
|
|
22
17
|
* const user = await kv.get('user:123', 'json');
|
|
23
18
|
*
|
|
24
|
-
* return
|
|
19
|
+
* return Response.json(user);
|
|
25
20
|
* }
|
|
26
21
|
* ```
|
|
27
22
|
*/
|
|
@@ -30,22 +25,19 @@ import { getPlatformEnv, isPlatformEnvConfigured } from '../env';
|
|
|
30
25
|
/**
|
|
31
26
|
* Get a KV instance for the current request
|
|
32
27
|
*
|
|
33
|
-
* Automatically selects the appropriate provider based on environment:
|
|
34
|
-
* - 'cloudflare' (default): Cloudflare KV
|
|
35
|
-
* - 'upstash': Upstash Redis
|
|
36
|
-
* - 'vercel': Vercel KV
|
|
37
|
-
*
|
|
38
28
|
* @param req - Optional: NextRequest, object with env property, or env object directly.
|
|
39
29
|
* If not provided, uses the env configured via configurePlatformEnv().
|
|
40
30
|
* @returns KV provider instance
|
|
41
31
|
*/
|
|
42
|
-
export
|
|
32
|
+
export function getKV(req) {
|
|
43
33
|
let env;
|
|
44
34
|
// If no argument provided, use the configured env provider
|
|
45
35
|
if (!req) {
|
|
46
36
|
if (!isPlatformEnvConfigured()) {
|
|
47
|
-
|
|
37
|
+
const error = new Error('getKV() called without env and configurePlatformEnv() was not called. ' +
|
|
48
38
|
'Either pass env directly: getKV({ env }) or call configurePlatformEnv(() => getCloudflareContext().env) first.');
|
|
39
|
+
console.error('[PLATFORM-SDK] getKV error:', error.message);
|
|
40
|
+
throw error;
|
|
49
41
|
}
|
|
50
42
|
env = getPlatformEnv();
|
|
51
43
|
}
|
|
@@ -60,27 +52,17 @@ export async function getKV(req) {
|
|
|
60
52
|
env = req.env;
|
|
61
53
|
}
|
|
62
54
|
if (!env) {
|
|
63
|
-
|
|
55
|
+
const error = new Error('No environment found in request. Ensure you are running in edge runtime.');
|
|
56
|
+
console.error('[PLATFORM-SDK] getKV error:', error.message);
|
|
57
|
+
throw error;
|
|
64
58
|
}
|
|
65
59
|
// Check for KV binding
|
|
66
60
|
if (!env.KV) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const provider = env.KV_PROVIDER || 'cloudflare';
|
|
71
|
-
switch (provider) {
|
|
72
|
-
case 'cloudflare':
|
|
73
|
-
return new CloudflareKV(env.KV);
|
|
74
|
-
case 'upstash':
|
|
75
|
-
// Future: Upstash Redis implementation
|
|
76
|
-
throw new Error('Upstash KV provider not yet implemented. Use KV_PROVIDER=cloudflare or remove KV_PROVIDER.');
|
|
77
|
-
case 'vercel':
|
|
78
|
-
// Future: Vercel KV implementation
|
|
79
|
-
throw new Error('Vercel KV provider not yet implemented. Use KV_PROVIDER=cloudflare or remove KV_PROVIDER.');
|
|
80
|
-
default:
|
|
81
|
-
console.warn(`Unknown KV_PROVIDER: ${provider}. Falling back to Cloudflare KV.`);
|
|
82
|
-
return new CloudflareKV(env.KV);
|
|
61
|
+
const error = new Error('No KV namespace binding found. Add a KV namespace binding named "KV" to your wrangler.jsonc');
|
|
62
|
+
console.error('[PLATFORM-SDK] getKV error:', error.message, 'Available bindings:', Object.keys(env));
|
|
63
|
+
throw error;
|
|
83
64
|
}
|
|
65
|
+
return new CloudflareKV(env.KV);
|
|
84
66
|
}
|
|
85
67
|
/**
|
|
86
68
|
* Create a KV instance directly (for advanced usage)
|
package/dist/kv/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"A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