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 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.27";
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.28",
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": ">=24.0.0",
38
+ "node": ">=26.0.0",
39
39
  "npm": ">=11.0.0"
40
40
  }
41
41
  }
@@ -28,7 +28,7 @@
28
28
  "vitest": "npm:@voidzero-dev/vite-plus-test"
29
29
  },
30
30
  "engines": {
31
- "node": ">=24.0.0",
31
+ "node": ">=26.0.0",
32
32
  "npm": ">=11.0.0"
33
33
  }
34
34
  }
@@ -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({
@@ -16,7 +16,7 @@ describe('pages/home/api/users/list', () => {
16
16
  expect(statusCode).toEqual(200)
17
17
  expect(data).toEqual({
18
18
  total: 2,
19
- users: [
19
+ rows: [
20
20
  {
21
21
  id: 2,
22
22
  name: 'Grace',
@@ -1,10 +1,10 @@
1
1
  import { defineApi } from '@faasjs/core'
2
2
  import { getClient } from '@faasjs/pg'
3
- import * as z from 'zod'
3
+ import { z } from '@faasjs/utils'
4
4
 
5
5
  export default defineApi({
6
6
  schema: z.object({
7
- name: z.string().min(1).optional(),
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 * as z from 'zod'
3
+ import { z } from '@faasjs/utils'
4
4
 
5
5
  export default defineApi({
6
6
  schema: z.object({
7
- id: z.number().int().positive(),
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 * as z from 'zod'
3
+ import { z } from '@faasjs/utils'
4
4
 
5
5
  export default defineApi({
6
6
  schema: z.object({
7
- limit: z.number().int().positive().max(50).default(20),
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 * as z from 'zod'
3
+ import { z } from '@faasjs/utils'
4
4
 
5
5
  export default defineApi({
6
6
  schema: z.object({
7
- id: z.number().int().positive(),
8
- name: z.string().min(1),
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; users?: { id: number; name: string }[] }
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 refreshUsers = async () => {
55
- const response = await faas('/pages/home/api/users/list', {
56
- limit: 10,
57
- })
58
- const data = (response.data as ListUsersResponse | undefined) || undefined
36
+ const {
37
+ data: listData,
38
+ loading: listLoading,
39
+ reload,
40
+ } = useFaas('/pages/home/api/users/list', { limit: 10 })
59
41
 
60
- setUsers(data?.users || [])
61
- }
42
+ const rows = listData?.rows || []
62
43
 
44
+ const [creating, setCreating] = useState(false)
63
45
  const callApi = async () => {
64
- setLoading(true)
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 data = (response.data as CreateUserResponse | undefined) || undefined
51
+ const result = response.data
71
52
  const nextMessage =
72
- data?.user && typeof data.total === 'number'
73
- ? `Created ${data.user.name} (#${data.user.id}). Total users: ${data.total}`
74
- : data?.message || 'Empty response'
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
- setLoading(false)
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 data = (response.data as CurrentUserResponse | undefined) || undefined
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={refreshUsers}>Load users slice</Button>
160
- <Button type="primary" loading={loading} onClick={callApi}>
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<UserRecord>
146
+ <Table
169
147
  rowKey="id"
170
148
  size="small"
171
149
  pagination={false}
172
- dataSource={users}
150
+ loading={listLoading}
151
+ dataSource={rows}
173
152
  columns={[
174
- {
175
- title: 'ID',
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 { viteConfig } from '@faasjs/dev'
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
- ...viteConfig,
7
- plugins: [...viteConfig.plugins, PgVitestPlugin()],
6
+ ...ViteConfig,
7
+ plugins: [...ViteConfig.plugins, PgVitestPlugin()],
8
8
  test: {
9
9
  fileParallelism: false,
10
10
  testTimeout: 30_000,
@@ -20,7 +20,7 @@
20
20
  "vitest": "npm:@voidzero-dev/vite-plus-test"
21
21
  },
22
22
  "engines": {
23
- "node": ">=24.0.0",
23
+ "node": ">=26.0.0",
24
24
  "npm": ">=11.0.0"
25
25
  }
26
26
  }
@@ -1,9 +1,9 @@
1
1
  import { defineApi } from '@faasjs/core'
2
- import * as z from 'zod'
2
+ import { z } from '@faasjs/utils'
3
3
 
4
4
  export default defineApi({
5
5
  schema: z.object({
6
- name: z.string().min(1).optional(),
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 { faas } from '../../react-client'
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
- const data = response.data as HelloResponse | undefined
32
-
33
- setMessage(data?.message || 'Empty response')
34
- } catch (error: unknown) {
35
- setMessage(error instanceof Error ? error.message : 'Request failed')
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 type="button" onClick={callApi} disabled={loading}>
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>
@@ -1,6 +1,6 @@
1
- import { viteConfig } from '@faasjs/dev'
1
+ import { ViteConfig } from '@faasjs/dev'
2
2
  import { defineConfig } from 'vite-plus'
3
3
 
4
4
  export default defineConfig({
5
- ...viteConfig,
5
+ ...ViteConfig,
6
6
  })