create-faas-app 8.0.0-beta.27 → 8.0.0-beta.29
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/index.mjs +3 -1
- package/package.json +2 -2
- package/template/admin/package.json +1 -1
- package/template/admin/src/pages/home/api/auth/me.api.ts +2 -0
- package/template/admin/src/pages/home/api/users/__tests__/list.test.ts +1 -1
- package/template/admin/src/pages/home/api/users/create.api.ts +2 -2
- package/template/admin/src/pages/home/api/users/detail.api.ts +2 -2
- package/template/admin/src/pages/home/api/users/list.api.ts +3 -3
- package/template/admin/src/pages/home/api/users/update.api.ts +3 -3
- package/template/admin/src/pages/home/index.tsx +53 -63
- package/template/admin/vite.config.ts +3 -3
- package/template/minimal/package.json +1 -1
- package/template/minimal/src/pages/home/api/hello.api.ts +2 -2
- package/template/minimal/src/pages/home/index.tsx +21 -26
- package/template/minimal/vite.config.ts +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { dirname, join } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import enquirer from "enquirer";
|
|
8
8
|
//#region package.json
|
|
9
|
-
var version = "8.0.0-beta.
|
|
9
|
+
var version = "8.0.0-beta.29";
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/action/index.ts
|
|
12
12
|
const prompt = enquirer.prompt;
|
|
@@ -112,6 +112,8 @@ ${getTemplateNames().join(", ")}`)).option("--name <name>", "Project name").opti
|
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/index.ts
|
|
114
114
|
/**
|
|
115
|
+
* # create-faas-app
|
|
116
|
+
*
|
|
115
117
|
* [](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
|
|
116
118
|
* [](https://www.npmjs.com/package/create-faas-app)
|
|
117
119
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-faas-app",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.29",
|
|
4
4
|
"homepage": "https://faasjs.com/doc/create-faas-app",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/faasjs/faasjs/issues"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"enquirer": "*"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
38
|
+
"node": ">=26.0.0",
|
|
39
39
|
"npm": ">=11.0.0"
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { defineApi, HttpError } from '@faasjs/core'
|
|
2
|
+
import { z } from '@faasjs/utils'
|
|
2
3
|
|
|
3
4
|
import { AuthPlugin } from '../../../../plugins/auth'
|
|
4
5
|
|
|
5
6
|
const api = defineApi({
|
|
7
|
+
schema: z.object({}).strict(),
|
|
6
8
|
async handler({ current_user }) {
|
|
7
9
|
if (!current_user)
|
|
8
10
|
throw new HttpError({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineApi } from '@faasjs/core'
|
|
2
2
|
import { getClient } from '@faasjs/pg'
|
|
3
|
-
import
|
|
3
|
+
import { z } from '@faasjs/utils'
|
|
4
4
|
|
|
5
5
|
export default defineApi({
|
|
6
6
|
schema: z.object({
|
|
7
|
-
name: z.
|
|
7
|
+
name: z.nonemptystring().optional(),
|
|
8
8
|
}),
|
|
9
9
|
async handler({ params }) {
|
|
10
10
|
const client = await getClient()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineApi, HttpError } from '@faasjs/core'
|
|
2
2
|
import { getClient } from '@faasjs/pg'
|
|
3
|
-
import
|
|
3
|
+
import { z } from '@faasjs/utils'
|
|
4
4
|
|
|
5
5
|
export default defineApi({
|
|
6
6
|
schema: z.object({
|
|
7
|
-
id: z.
|
|
7
|
+
id: z.positiveint(),
|
|
8
8
|
}),
|
|
9
9
|
async handler({ params }) {
|
|
10
10
|
const client = await getClient()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineApi } from '@faasjs/core'
|
|
2
2
|
import { getClient } from '@faasjs/pg'
|
|
3
|
-
import
|
|
3
|
+
import { z } from '@faasjs/utils'
|
|
4
4
|
|
|
5
5
|
export default defineApi({
|
|
6
6
|
schema: z.object({
|
|
7
|
-
limit: z.
|
|
7
|
+
limit: z.positiveint().max(50).default(20),
|
|
8
8
|
}),
|
|
9
9
|
async handler({ params }) {
|
|
10
10
|
const client = await getClient()
|
|
@@ -16,7 +16,7 @@ export default defineApi({
|
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
18
|
total: await client.query('users').count(),
|
|
19
|
-
users,
|
|
19
|
+
rows: users,
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineApi, HttpError } from '@faasjs/core'
|
|
2
2
|
import { getClient } from '@faasjs/pg'
|
|
3
|
-
import
|
|
3
|
+
import { z } from '@faasjs/utils'
|
|
4
4
|
|
|
5
5
|
export default defineApi({
|
|
6
6
|
schema: z.object({
|
|
7
|
-
id: z.
|
|
8
|
-
name: z.
|
|
7
|
+
id: z.positiveint(),
|
|
8
|
+
name: z.nonemptystring(),
|
|
9
9
|
}),
|
|
10
10
|
async handler({ params }) {
|
|
11
11
|
const client = await getClient()
|
|
@@ -1,97 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
declare module '@faasjs/types' {
|
|
2
|
+
interface FaasActions {
|
|
3
|
+
'/pages/home/api/users/list': {
|
|
4
|
+
Params: { limit: number }
|
|
5
|
+
Data: { total?: number; rows?: { id: number; name: string }[] }
|
|
6
|
+
}
|
|
7
|
+
'/pages/home/api/users/create': {
|
|
8
|
+
Params: { name?: string | undefined }
|
|
9
|
+
Data: { message?: string; total?: number; user?: { id: number; name: string } }
|
|
10
|
+
}
|
|
11
|
+
'/pages/home/api/users/update': {
|
|
12
|
+
Params: { id: number; name: string }
|
|
13
|
+
Data: { message?: string; user?: { id: number; name: string } }
|
|
14
|
+
}
|
|
15
|
+
'/pages/home/api/users/detail': {
|
|
16
|
+
Params: { id: number }
|
|
17
|
+
Data: { user?: { id: number; name: string } }
|
|
18
|
+
}
|
|
19
|
+
'/pages/home/api/auth/me': {
|
|
20
|
+
Params: Record<string, never>
|
|
21
|
+
Data: { current_user?: { id: number; name: string; role: string } }
|
|
22
|
+
}
|
|
10
23
|
}
|
|
11
24
|
}
|
|
12
25
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type ListUsersResponse = {
|
|
19
|
-
total?: number
|
|
20
|
-
users?: UserRecord[]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type CreateUserResponse = {
|
|
24
|
-
message?: string
|
|
25
|
-
total?: number
|
|
26
|
-
user?: UserRecord
|
|
27
|
-
}
|
|
26
|
+
import { faas, useApp } from '@faasjs/ant-design'
|
|
27
|
+
import { useFaas } from '@faasjs/react'
|
|
28
|
+
import { Button, Card, Input, Space, Table, Typography } from 'antd'
|
|
29
|
+
import { useState } from 'react'
|
|
28
30
|
|
|
29
31
|
export default function HomePage() {
|
|
30
32
|
const app = useApp()
|
|
31
33
|
const [name, setName] = useState('FaasJS')
|
|
32
34
|
const [messageText, setMessageText] = useState('Create your first user through the FaasJS API')
|
|
33
|
-
const [loading, setLoading] = useState(false)
|
|
34
|
-
const [authLoading, setAuthLoading] = useState(false)
|
|
35
|
-
const [users, setUsers] = useState<UserRecord[]>([])
|
|
36
35
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const {
|
|
37
|
+
data: listData,
|
|
38
|
+
loading: listLoading,
|
|
39
|
+
reload,
|
|
40
|
+
} = useFaas('/pages/home/api/users/list', { limit: 10 })
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
}
|
|
42
|
+
const rows = listData?.rows || []
|
|
45
43
|
|
|
44
|
+
const [creating, setCreating] = useState(false)
|
|
46
45
|
const callApi = async () => {
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
setCreating(true)
|
|
49
47
|
try {
|
|
50
48
|
const response = await faas('/pages/home/api/users/create', {
|
|
51
49
|
name: name.trim() || undefined,
|
|
52
50
|
})
|
|
53
|
-
const
|
|
51
|
+
const result = response.data
|
|
54
52
|
const nextMessage =
|
|
55
|
-
|
|
56
|
-
? `Created ${
|
|
57
|
-
:
|
|
53
|
+
result?.user && typeof result.total === 'number'
|
|
54
|
+
? `Created ${result.user.name} (#${result.user.id}). Total users: ${result.total}`
|
|
55
|
+
: result?.message || 'Empty response'
|
|
58
56
|
|
|
59
57
|
setMessageText(nextMessage)
|
|
60
|
-
setUsers((current) => (data?.user ? [data.user, ...current].slice(0, 10) : current))
|
|
61
58
|
app.message.success('User saved to PostgreSQL')
|
|
59
|
+
reload()
|
|
62
60
|
} catch (error: unknown) {
|
|
63
61
|
const errorMessage = error instanceof Error ? error.message : 'Request failed'
|
|
64
|
-
|
|
65
62
|
setMessageText(errorMessage)
|
|
66
63
|
app.notification.error({
|
|
67
64
|
message: 'API call failed',
|
|
68
65
|
description: errorMessage,
|
|
69
66
|
})
|
|
70
67
|
} finally {
|
|
71
|
-
|
|
68
|
+
setCreating(false)
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
72
|
+
const [authLoading, setAuthLoading] = useState(false)
|
|
75
73
|
const callAuthDemo = async () => {
|
|
76
74
|
setAuthLoading(true)
|
|
77
|
-
|
|
78
75
|
try {
|
|
79
76
|
const response = await faas(
|
|
80
77
|
'/pages/home/api/auth/me',
|
|
81
78
|
{},
|
|
82
79
|
{
|
|
83
|
-
headers: {
|
|
84
|
-
authorization: 'Bearer demo-admin',
|
|
85
|
-
},
|
|
80
|
+
headers: { authorization: 'Bearer demo-admin' },
|
|
86
81
|
},
|
|
87
82
|
)
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
setMessageText(`Auth plugin injected current user: ${data?.current_user?.name || 'unknown'}`)
|
|
83
|
+
const currentUser = response.data?.current_user
|
|
84
|
+
setMessageText(`Auth plugin injected current user: ${currentUser?.name || 'unknown'}`)
|
|
91
85
|
app.message.success('Auth plugin demo loaded current_user')
|
|
92
86
|
} catch (error: unknown) {
|
|
93
87
|
const errorMessage = error instanceof Error ? error.message : 'Auth demo failed'
|
|
94
|
-
|
|
95
88
|
setMessageText(errorMessage)
|
|
96
89
|
app.notification.error({
|
|
97
90
|
message: 'Auth demo failed',
|
|
@@ -139,8 +132,10 @@ export default function HomePage() {
|
|
|
139
132
|
/>
|
|
140
133
|
|
|
141
134
|
<Space wrap>
|
|
142
|
-
<Button onClick={
|
|
143
|
-
|
|
135
|
+
<Button onClick={reload} loading={listLoading}>
|
|
136
|
+
Load users slice
|
|
137
|
+
</Button>
|
|
138
|
+
<Button type="primary" loading={creating} onClick={callApi}>
|
|
144
139
|
Create /pages/home/api/users/create
|
|
145
140
|
</Button>
|
|
146
141
|
<Button loading={authLoading} onClick={callAuthDemo}>
|
|
@@ -148,20 +143,15 @@ export default function HomePage() {
|
|
|
148
143
|
</Button>
|
|
149
144
|
</Space>
|
|
150
145
|
|
|
151
|
-
<Table
|
|
146
|
+
<Table
|
|
152
147
|
rowKey="id"
|
|
153
148
|
size="small"
|
|
154
149
|
pagination={false}
|
|
155
|
-
|
|
150
|
+
loading={listLoading}
|
|
151
|
+
dataSource={rows}
|
|
156
152
|
columns={[
|
|
157
|
-
{
|
|
158
|
-
|
|
159
|
-
dataIndex: 'id',
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
title: 'Name',
|
|
163
|
-
dataIndex: 'name',
|
|
164
|
-
},
|
|
153
|
+
{ title: 'ID', dataIndex: 'id' },
|
|
154
|
+
{ title: 'Name', dataIndex: 'name' },
|
|
165
155
|
]}
|
|
166
156
|
/>
|
|
167
157
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ViteConfig } from '@faasjs/dev'
|
|
2
2
|
import { PgVitestPlugin } from '@faasjs/pg-dev'
|
|
3
3
|
import { defineConfig } from 'vite-plus'
|
|
4
4
|
|
|
5
5
|
export default defineConfig({
|
|
6
|
-
...
|
|
7
|
-
plugins: [...
|
|
6
|
+
...ViteConfig,
|
|
7
|
+
plugins: [...ViteConfig.plugins, PgVitestPlugin()],
|
|
8
8
|
test: {
|
|
9
9
|
fileParallelism: false,
|
|
10
10
|
testTimeout: 30_000,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineApi } from '@faasjs/core'
|
|
2
|
-
import
|
|
2
|
+
import { z } from '@faasjs/utils'
|
|
3
3
|
|
|
4
4
|
export default defineApi({
|
|
5
5
|
schema: z.object({
|
|
6
|
-
name: z.
|
|
6
|
+
name: z.nonemptystring().optional(),
|
|
7
7
|
}),
|
|
8
8
|
async handler({ params }) {
|
|
9
9
|
return {
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
declare module '@faasjs/types' {
|
|
2
|
+
interface FaasActions {
|
|
3
|
+
'/pages/home/api/hello': {
|
|
4
|
+
Params: { name?: string | undefined }
|
|
5
|
+
Data: { message?: string }
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
|
|
3
|
-
import {
|
|
10
|
+
import { useState } from 'react'
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
message?: string
|
|
7
|
-
}
|
|
12
|
+
import { useFaas } from '../../react-client'
|
|
8
13
|
|
|
9
14
|
export default function HomePage() {
|
|
10
15
|
const [name, setName] = useState('FaasJS')
|
|
11
|
-
const [message, setMessage] = useState('Click button to call API')
|
|
12
|
-
const [loading, setLoading] = useState(false)
|
|
13
16
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
name: name.trim() || undefined,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
const data = response.data as HelloResponse | undefined
|
|
23
|
-
|
|
24
|
-
setMessage(data?.message || 'Empty response')
|
|
25
|
-
} catch (error: unknown) {
|
|
26
|
-
setMessage(error instanceof Error ? error.message : 'Request failed')
|
|
27
|
-
} finally {
|
|
28
|
-
setLoading(false)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
17
|
+
const { data, loading, reload } = useFaas(
|
|
18
|
+
'/pages/home/api/hello',
|
|
19
|
+
{ name: name.trim() || undefined },
|
|
20
|
+
{ skip: true },
|
|
21
|
+
)
|
|
31
22
|
|
|
32
23
|
return (
|
|
33
24
|
<main style={{ margin: '5rem auto', maxWidth: 420, padding: 24 }}>
|
|
34
25
|
<h1>FaasJS Minimal App</h1>
|
|
35
|
-
<p>{message}</p>
|
|
26
|
+
<p>{data?.message || 'Click button to call API'}</p>
|
|
36
27
|
|
|
37
28
|
<label style={{ display: 'block', marginBottom: 12 }}>
|
|
38
29
|
Name:
|
|
@@ -43,7 +34,11 @@ export default function HomePage() {
|
|
|
43
34
|
/>
|
|
44
35
|
</label>
|
|
45
36
|
|
|
46
|
-
<button
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
onClick={() => reload({ name: name.trim() || undefined })}
|
|
40
|
+
disabled={loading}
|
|
41
|
+
>
|
|
47
42
|
{loading ? 'Loading...' : 'Call /pages/home/api/hello'}
|
|
48
43
|
</button>
|
|
49
44
|
</main>
|