create-faas-app 8.0.0-beta.28 → 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 +1 -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 +37 -64
- 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 +12 -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;
|
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()
|
|
@@ -2,12 +2,20 @@ declare module '@faasjs/types' {
|
|
|
2
2
|
interface FaasActions {
|
|
3
3
|
'/pages/home/api/users/list': {
|
|
4
4
|
Params: { limit: number }
|
|
5
|
-
Data: { total?: number;
|
|
5
|
+
Data: { total?: number; rows?: { id: number; name: string }[] }
|
|
6
6
|
}
|
|
7
7
|
'/pages/home/api/users/create': {
|
|
8
8
|
Params: { name?: string | undefined }
|
|
9
9
|
Data: { message?: string; total?: number; user?: { id: number; name: string } }
|
|
10
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
|
+
}
|
|
11
19
|
'/pages/home/api/auth/me': {
|
|
12
20
|
Params: Record<string, never>
|
|
13
21
|
Data: { current_user?: { id: number; name: string; role: string } }
|
|
@@ -16,99 +24,67 @@ declare module '@faasjs/types' {
|
|
|
16
24
|
}
|
|
17
25
|
|
|
18
26
|
import { faas, useApp } from '@faasjs/ant-design'
|
|
27
|
+
import { useFaas } from '@faasjs/react'
|
|
19
28
|
import { Button, Card, Input, Space, Table, Typography } from 'antd'
|
|
20
29
|
import { useState } from 'react'
|
|
21
30
|
|
|
22
|
-
type CurrentUserResponse = {
|
|
23
|
-
current_user?: {
|
|
24
|
-
id: number
|
|
25
|
-
name: string
|
|
26
|
-
role: string
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type UserRecord = {
|
|
31
|
-
id: number
|
|
32
|
-
name: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type ListUsersResponse = {
|
|
36
|
-
total?: number
|
|
37
|
-
users?: UserRecord[]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type CreateUserResponse = {
|
|
41
|
-
message?: string
|
|
42
|
-
total?: number
|
|
43
|
-
user?: UserRecord
|
|
44
|
-
}
|
|
45
|
-
|
|
46
31
|
export default function HomePage() {
|
|
47
32
|
const app = useApp()
|
|
48
33
|
const [name, setName] = useState('FaasJS')
|
|
49
34
|
const [messageText, setMessageText] = useState('Create your first user through the FaasJS API')
|
|
50
|
-
const [loading, setLoading] = useState(false)
|
|
51
|
-
const [authLoading, setAuthLoading] = useState(false)
|
|
52
|
-
const [users, setUsers] = useState<UserRecord[]>([])
|
|
53
35
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
const {
|
|
37
|
+
data: listData,
|
|
38
|
+
loading: listLoading,
|
|
39
|
+
reload,
|
|
40
|
+
} = useFaas('/pages/home/api/users/list', { limit: 10 })
|
|
59
41
|
|
|
60
|
-
|
|
61
|
-
}
|
|
42
|
+
const rows = listData?.rows || []
|
|
62
43
|
|
|
44
|
+
const [creating, setCreating] = useState(false)
|
|
63
45
|
const callApi = async () => {
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
setCreating(true)
|
|
66
47
|
try {
|
|
67
48
|
const response = await faas('/pages/home/api/users/create', {
|
|
68
49
|
name: name.trim() || undefined,
|
|
69
50
|
})
|
|
70
|
-
const
|
|
51
|
+
const result = response.data
|
|
71
52
|
const nextMessage =
|
|
72
|
-
|
|
73
|
-
? `Created ${
|
|
74
|
-
:
|
|
53
|
+
result?.user && typeof result.total === 'number'
|
|
54
|
+
? `Created ${result.user.name} (#${result.user.id}). Total users: ${result.total}`
|
|
55
|
+
: result?.message || 'Empty response'
|
|
75
56
|
|
|
76
57
|
setMessageText(nextMessage)
|
|
77
|
-
setUsers((current) => (data?.user ? [data.user, ...current].slice(0, 10) : current))
|
|
78
58
|
app.message.success('User saved to PostgreSQL')
|
|
59
|
+
reload()
|
|
79
60
|
} catch (error: unknown) {
|
|
80
61
|
const errorMessage = error instanceof Error ? error.message : 'Request failed'
|
|
81
|
-
|
|
82
62
|
setMessageText(errorMessage)
|
|
83
63
|
app.notification.error({
|
|
84
64
|
message: 'API call failed',
|
|
85
65
|
description: errorMessage,
|
|
86
66
|
})
|
|
87
67
|
} finally {
|
|
88
|
-
|
|
68
|
+
setCreating(false)
|
|
89
69
|
}
|
|
90
70
|
}
|
|
91
71
|
|
|
72
|
+
const [authLoading, setAuthLoading] = useState(false)
|
|
92
73
|
const callAuthDemo = async () => {
|
|
93
74
|
setAuthLoading(true)
|
|
94
|
-
|
|
95
75
|
try {
|
|
96
76
|
const response = await faas(
|
|
97
77
|
'/pages/home/api/auth/me',
|
|
98
78
|
{},
|
|
99
79
|
{
|
|
100
|
-
headers: {
|
|
101
|
-
authorization: 'Bearer demo-admin',
|
|
102
|
-
},
|
|
80
|
+
headers: { authorization: 'Bearer demo-admin' },
|
|
103
81
|
},
|
|
104
82
|
)
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
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'}`)
|
|
108
85
|
app.message.success('Auth plugin demo loaded current_user')
|
|
109
86
|
} catch (error: unknown) {
|
|
110
87
|
const errorMessage = error instanceof Error ? error.message : 'Auth demo failed'
|
|
111
|
-
|
|
112
88
|
setMessageText(errorMessage)
|
|
113
89
|
app.notification.error({
|
|
114
90
|
message: 'Auth demo failed',
|
|
@@ -156,8 +132,10 @@ export default function HomePage() {
|
|
|
156
132
|
/>
|
|
157
133
|
|
|
158
134
|
<Space wrap>
|
|
159
|
-
<Button onClick={
|
|
160
|
-
|
|
135
|
+
<Button onClick={reload} loading={listLoading}>
|
|
136
|
+
Load users slice
|
|
137
|
+
</Button>
|
|
138
|
+
<Button type="primary" loading={creating} onClick={callApi}>
|
|
161
139
|
Create /pages/home/api/users/create
|
|
162
140
|
</Button>
|
|
163
141
|
<Button loading={authLoading} onClick={callAuthDemo}>
|
|
@@ -165,20 +143,15 @@ export default function HomePage() {
|
|
|
165
143
|
</Button>
|
|
166
144
|
</Space>
|
|
167
145
|
|
|
168
|
-
<Table
|
|
146
|
+
<Table
|
|
169
147
|
rowKey="id"
|
|
170
148
|
size="small"
|
|
171
149
|
pagination={false}
|
|
172
|
-
|
|
150
|
+
loading={listLoading}
|
|
151
|
+
dataSource={rows}
|
|
173
152
|
columns={[
|
|
174
|
-
{
|
|
175
|
-
|
|
176
|
-
dataIndex: 'id',
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
title: 'Name',
|
|
180
|
-
dataIndex: 'name',
|
|
181
|
-
},
|
|
153
|
+
{ title: 'ID', dataIndex: 'id' },
|
|
154
|
+
{ title: 'Name', dataIndex: 'name' },
|
|
182
155
|
]}
|
|
183
156
|
/>
|
|
184
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 {
|
|
@@ -9,39 +9,21 @@ declare module '@faasjs/types' {
|
|
|
9
9
|
|
|
10
10
|
import { useState } from 'react'
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
type HelloResponse = {
|
|
15
|
-
message?: string
|
|
16
|
-
}
|
|
12
|
+
import { useFaas } from '../../react-client'
|
|
17
13
|
|
|
18
14
|
export default function HomePage() {
|
|
19
15
|
const [name, setName] = useState('FaasJS')
|
|
20
|
-
const [message, setMessage] = useState('Click button to call API')
|
|
21
|
-
const [loading, setLoading] = useState(false)
|
|
22
|
-
|
|
23
|
-
const callApi = async () => {
|
|
24
|
-
setLoading(true)
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const response = await faas('/pages/home/api/hello', {
|
|
28
|
-
name: name.trim() || undefined,
|
|
29
|
-
})
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} finally {
|
|
37
|
-
setLoading(false)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
17
|
+
const { data, loading, reload } = useFaas(
|
|
18
|
+
'/pages/home/api/hello',
|
|
19
|
+
{ name: name.trim() || undefined },
|
|
20
|
+
{ skip: true },
|
|
21
|
+
)
|
|
40
22
|
|
|
41
23
|
return (
|
|
42
24
|
<main style={{ margin: '5rem auto', maxWidth: 420, padding: 24 }}>
|
|
43
25
|
<h1>FaasJS Minimal App</h1>
|
|
44
|
-
<p>{message}</p>
|
|
26
|
+
<p>{data?.message || 'Click button to call API'}</p>
|
|
45
27
|
|
|
46
28
|
<label style={{ display: 'block', marginBottom: 12 }}>
|
|
47
29
|
Name:
|
|
@@ -52,7 +34,11 @@ export default function HomePage() {
|
|
|
52
34
|
/>
|
|
53
35
|
</label>
|
|
54
36
|
|
|
55
|
-
<button
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
onClick={() => reload({ name: name.trim() || undefined })}
|
|
40
|
+
disabled={loading}
|
|
41
|
+
>
|
|
56
42
|
{loading ? 'Loading...' : 'Call /pages/home/api/hello'}
|
|
57
43
|
</button>
|
|
58
44
|
</main>
|