spfn 0.2.0-beta.4 → 0.2.0-beta.40
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/bin/spfn.js +46 -4
- package/dist/index.js +1157 -463
- package/dist/templates/lib/api-client.ts +65 -34
- package/dist/templates/server/router.ts +0 -14
- package/package.json +6 -5
|
@@ -1,49 +1,80 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* API Client Configuration
|
|
3
3
|
*
|
|
4
|
-
* Type-safe client for accessing server routes
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createApi } from '@spfn/core/nextjs';
|
|
8
|
-
import { errorRegistry } from "@spfn/core/errors";
|
|
9
|
-
|
|
10
|
-
import type { AppRouter } from '@/server/router';
|
|
11
|
-
import { appMetadata } from "@/server/router.metadata";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Pre-configured type-safe API client
|
|
15
|
-
*
|
|
4
|
+
* Type-safe client for accessing server routes.
|
|
16
5
|
* Core HTTP errors are automatically registered.
|
|
17
|
-
* Add custom application errors via the errors field if needed.
|
|
18
6
|
*
|
|
19
7
|
* @example
|
|
20
8
|
* ```typescript
|
|
21
9
|
* import { api } from '@/lib/api-client';
|
|
22
10
|
*
|
|
23
11
|
* // Basic call
|
|
24
|
-
* const user = await api.getUser
|
|
25
|
-
* .call({ id: '123' });
|
|
12
|
+
* const user = await api.getUser.call({ params: { id: '123' } });
|
|
26
13
|
*
|
|
27
|
-
* //
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* console.log('Resource not found');
|
|
33
|
-
* } else if (error instanceof ValidationError) {
|
|
34
|
-
* console.log('Validation failed:', error.fields);
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
14
|
+
* // With options
|
|
15
|
+
* const data = await api.getData
|
|
16
|
+
* .headers({ 'X-Custom': 'value' })
|
|
17
|
+
* .fetchOptions({ next: { revalidate: 60 } })
|
|
18
|
+
* .call({ query: { page: 1 } });
|
|
37
19
|
* ```
|
|
38
|
-
*
|
|
39
|
-
* Works in:
|
|
40
|
-
* - Server Components (no router import needed)
|
|
41
|
-
* - Client Components (proxied through /api/actions)
|
|
42
|
-
* - Server Actions
|
|
43
|
-
* - Route Handlers
|
|
44
20
|
*/
|
|
21
|
+
|
|
22
|
+
import { createApi } from '@spfn/core/nextjs';
|
|
23
|
+
import type { AppRouter } from '@/server/router';
|
|
24
|
+
|
|
45
25
|
export const api = createApi<AppRouter>({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Base URL for RPC endpoint
|
|
28
|
+
* @default '/api/rpc'
|
|
29
|
+
*/
|
|
30
|
+
// baseUrl: '/api/rpc',
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Default headers for all requests
|
|
34
|
+
*/
|
|
35
|
+
// headers: { 'X-Client': 'web' },
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Request timeout in milliseconds
|
|
39
|
+
* @default 30000
|
|
40
|
+
*/
|
|
41
|
+
// timeout: 30000,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Custom error registry for deserialization
|
|
45
|
+
* Core HTTP errors are automatically included.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* import { authErrorRegistry } from '@myapp/auth/errors';
|
|
49
|
+
* errorRegistry: [authErrorRegistry, MyCustomError]
|
|
50
|
+
*/
|
|
51
|
+
// errorRegistry: [],
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Global request interceptor
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* onRequest: async (url, init) => {
|
|
58
|
+
* init.headers = { ...init.headers, 'X-Request-Id': crypto.randomUUID() };
|
|
59
|
+
* return init;
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
// onRequest: async (url, init) => init,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Global response interceptor
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* onResponse: async (response, body) => {
|
|
69
|
+
* if (response.status === 401) redirect('/login');
|
|
70
|
+
* return { response, body };
|
|
71
|
+
* }
|
|
72
|
+
*/
|
|
73
|
+
// onResponse: async (response, body) => ({ response, body }),
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Enable debug logging
|
|
77
|
+
* @default false
|
|
78
|
+
*/
|
|
79
|
+
debug: process.env.NODE_ENV === 'development',
|
|
49
80
|
});
|
|
@@ -12,9 +12,6 @@ import { listExamples, getExample, createExample, updateExample, deleteExample }
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Main application router
|
|
15
|
-
*
|
|
16
|
-
* defineRouter extracts metadata automatically.
|
|
17
|
-
* Use codegen to generate router.metadata.ts for client-side usage.
|
|
18
15
|
*/
|
|
19
16
|
export const appRouter = defineRouter({
|
|
20
17
|
getRoot,
|
|
@@ -28,16 +25,5 @@ export const appRouter = defineRouter({
|
|
|
28
25
|
|
|
29
26
|
/**
|
|
30
27
|
* Router type for client usage
|
|
31
|
-
*
|
|
32
|
-
* Usage:
|
|
33
|
-
* ```typescript
|
|
34
|
-
* import type { AppRouter } from '@/server/router';
|
|
35
|
-
* import { appMetadata } from '@/server/router.metadata'; // Generated by codegen
|
|
36
|
-
*
|
|
37
|
-
* const api = createApi<AppRouter>({
|
|
38
|
-
* baseUrl: '/api/actions',
|
|
39
|
-
* metadata: appMetadata // Only method/path, no server code!
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
28
|
*/
|
|
43
29
|
export type AppRouter = typeof appRouter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spfn",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.40",
|
|
4
4
|
"description": "Superfunction CLI - Add SPFN to your Next.js project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"node": ">=18.18.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
+
"@spfn/core": ">=0.2.0-beta.30",
|
|
50
51
|
"typescript": "^5.3.0"
|
|
51
52
|
},
|
|
52
53
|
"peerDependenciesMeta": {
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"chokidar": "^4.0.3",
|
|
60
61
|
"commander": "^11.1.0",
|
|
61
62
|
"dotenv": "^17.2.3",
|
|
63
|
+
"drizzle-kit": "^0.31.6",
|
|
62
64
|
"drizzle-orm": "^0.45.0",
|
|
63
65
|
"execa": "^8.0.1",
|
|
64
66
|
"fs-extra": "^11.2.0",
|
|
@@ -66,8 +68,7 @@
|
|
|
66
68
|
"pg": "^8.16.3",
|
|
67
69
|
"postgres": "^3.4.0",
|
|
68
70
|
"prompts": "^2.4.2",
|
|
69
|
-
"tsup": "^8.5.0"
|
|
70
|
-
"@spfn/core": "0.2.0-beta.5"
|
|
71
|
+
"tsup": "^8.5.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -75,9 +76,9 @@
|
|
|
75
76
|
"@types/pg": "^8.10.9",
|
|
76
77
|
"@types/prompts": "^2.4.9",
|
|
77
78
|
"concurrently": "^9.2.1",
|
|
78
|
-
"drizzle-kit": "^0.31.6",
|
|
79
79
|
"tsx": "^4.20.6",
|
|
80
|
-
"typescript": "^5.3.3"
|
|
80
|
+
"typescript": "^5.3.3",
|
|
81
|
+
"@spfn/core": "0.2.0-beta.39"
|
|
81
82
|
},
|
|
82
83
|
"scripts": {
|
|
83
84
|
"build": "tsup && node scripts/copy-templates.js",
|