@thewhateverapp/platform 0.9.16 → 0.9.17
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 +7 -31
- 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,CAiC9F;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,16 +25,11 @@ 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) {
|
|
@@ -66,21 +56,7 @@ export async function getKV(req) {
|
|
|
66
56
|
if (!env.KV) {
|
|
67
57
|
throw new Error('No KV namespace binding found. Add a KV namespace binding named "KV" to your wrangler.jsonc');
|
|
68
58
|
}
|
|
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);
|
|
83
|
-
}
|
|
59
|
+
return new CloudflareKV(env.KV);
|
|
84
60
|
}
|
|
85
61
|
/**
|
|
86
62
|
* 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":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kv/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAKjE;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CAAC,GAA4D;IAChF,IAAI,GAAgC,CAAC;IAErC,2DAA2D;IAC3D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,wEAAwE;gBACtE,gHAAgH,CACnH,CAAC;QACJ,CAAC;QACD,GAAG,GAAG,cAAc,EAAqB,CAAC;IAC5C,CAAC;SAAM,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,GAAG,GAAG,G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