create-faas-app 8.0.0-beta.35 → 8.0.0-beta.37

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.
Files changed (26) hide show
  1. package/README.md +12 -66
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.mjs +15 -3
  4. package/package.json +1 -1
  5. package/template/admin/package.json +1 -0
  6. package/template/admin/src/.faasjs/types.d.ts +16 -0
  7. package/template/admin/src/{pages/home/api/auth → features/auth/api}/__tests__/me.test.ts +1 -1
  8. package/template/admin/src/{pages/home/api/auth → features/auth/api}/me.api.ts +1 -1
  9. package/template/admin/src/{pages/home/api/users → features/users/api}/__tests__/create.test.ts +1 -1
  10. package/template/admin/src/{pages/home/api/users → features/users/api}/__tests__/detail.test.ts +1 -1
  11. package/template/admin/src/{pages/home/api/users → features/users/api}/__tests__/list.test.ts +1 -1
  12. package/template/admin/src/{pages/home/api/users → features/users/api}/__tests__/update.test.ts +1 -1
  13. package/template/admin/src/{pages/home → features/users}/index.tsx +5 -30
  14. package/template/admin/src/main.tsx +2 -2
  15. package/template/admin/tsconfig.json +1 -1
  16. package/template/minimal/package.json +1 -0
  17. package/template/minimal/src/.faasjs/types.d.ts +12 -0
  18. package/template/minimal/src/{pages → features}/home/api/__tests__/hello.test.ts +1 -1
  19. package/template/minimal/src/{pages → features}/home/index.tsx +2 -11
  20. package/template/minimal/src/main.tsx +1 -1
  21. package/template/minimal/tsconfig.json +1 -1
  22. /package/template/admin/src/{pages/home/api/users → features/users/api}/create.api.ts +0 -0
  23. /package/template/admin/src/{pages/home/api/users → features/users/api}/detail.api.ts +0 -0
  24. /package/template/admin/src/{pages/home/api/users → features/users/api}/list.api.ts +0 -0
  25. /package/template/admin/src/{pages/home/api/users → features/users/api}/update.api.ts +0 -0
  26. /package/template/minimal/src/{pages → features}/home/api/hello.api.ts +0 -0
package/README.md CHANGED
@@ -1,77 +1,23 @@
1
1
  # create-faas-app
2
2
 
3
- Create a new FaasJS app from a curated starter template.
4
-
5
- FaasJS is optimized for database-driven React business applications. `create-faas-app` gives new projects a working starting point for the official path instead of asking every team to assemble React, API, database, testing, and UI conventions from scratch.
6
-
7
- ## Quick Start
8
-
9
- ```bash
10
- npx create-faas-app --name my-faas-app
11
- cd my-faas-app
12
- npm run dev
13
- ```
14
-
15
- The default template is `admin`, which demonstrates the curated React + Ant Design + PostgreSQL path.
16
-
17
- ## Templates
18
-
19
- ### `admin`
20
-
21
- Use `admin` for the golden-path FaasJS starter.
22
-
23
- ```bash
24
- npx create-faas-app --name my-admin --template admin
25
- ```
26
-
27
- It includes:
28
-
29
- - React app structure powered by Vite Plus
30
- - `@faasjs/ant-design` and Ant Design for business UI
31
- - `defineApi` endpoints for typed backend APIs
32
- - a copyable users slice with create, list, detail, update, migration, table types, and API tests
33
- - `@faasjs/pg` for PostgreSQL access and migrations
34
- - `@faasjs/pg-dev` for pg-dev-powered tests
35
- - `.env.example` for local database configuration
36
- - type declarations for PostgreSQL table inference
3
+ # create-faas-app
37
4
 
38
- This is the best starting point for admin panels, internal tools, SaaS dashboards, and other database-driven business applications.
5
+ [![License: MIT](https://img.shields.io/npm/l/create-faas-app.svg)](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/create-faas-app.svg)](https://www.npmjs.com/package/create-faas-app)
39
7
 
40
- ### `minimal`
8
+ Curated scaffolder for FaasJS projects. The `admin` template is the default
9
+ React + Ant Design + PostgreSQL starter, and `minimal` provides a smaller
10
+ React starter. After scaffolding, the CLI runs `npm install`, `npm run types`,
11
+ and `npm run test` in the new project.
41
12
 
42
- Use `minimal` when you want a smaller React starter without the database and Ant Design stack.
13
+ ## Usage
43
14
 
44
15
  ```bash
45
- npx create-faas-app --name my-minimal-app --template minimal
16
+ npx create-faas-app --name faasjs
17
+ npx create-faas-app --name faasjs-admin --template admin
18
+ npx create-faas-app --name faasjs-minimal --template minimal
46
19
  ```
47
20
 
48
- It is useful for learning the core FaasJS runtime, building API-only or BFF-style projects, or adding a custom UI/database path intentionally.
49
-
50
- ## Recommended Path
51
-
52
- Start with `admin` unless you have a specific reason not to. It shows how FaasJS expects complete application slices to fit together:
53
-
54
- - UI pages call typed APIs
55
- - APIs validate inputs at system boundaries
56
- - APIs use PostgreSQL through the shared database workflow
57
- - migrations and table types keep data contracts explicit
58
- - tests cover the API and database behavior
59
-
60
- FaasJS allows teams to replace parts of the stack, but the templates, docs, and examples optimize this curated path first.
61
-
62
- ## Auth And Permissions
63
-
64
- Authentication and permissions are intentionally not built into FaasJS core because production auth requirements vary by product.
65
-
66
- The admin starter includes a small auth plugin demo. Treat it as a plugin pattern that shows how to inject current-user context, protect APIs, and model project-specific permissions. It is not a mandatory framework auth system.
67
-
68
- ## Next Steps
69
-
70
- - Read the FaasJS guide at <https://faasjs.com/guide/>.
71
- - Review the root README for the project direction and package overview.
72
- - Explore runnable templates in <https://github.com/faasjs/faasjs/tree/main/templates>.
73
- - Use the admin starter users slice as the reference for complete UI/API/database/test examples.
74
-
75
- ## API Docs
21
+ ## Functions
76
22
 
77
23
  - [main](functions/main.md)
package/dist/index.d.ts CHANGED
@@ -4,6 +4,12 @@ import { Command } from "commander";
4
4
  /**
5
5
  * Run the `create-faas-app` CLI with a provided argv array.
6
6
  *
7
+ * The array should use the same shape as `process.argv`, including executable
8
+ * and script slots. Parsing may prompt for a project name, create files, install
9
+ * dependencies, generate FaasJS action types, and run template tests. Commander
10
+ * help exits are swallowed and return the shared program; unexpected errors are
11
+ * printed with `console.error` and also return the program.
12
+ *
7
13
  * @param {string[]} argv - CLI arguments forwarded to Commander.
8
14
  * @returns {Promise<Command>} Commander program instance after parsing.
9
15
  *
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.34";
9
+ var version = "8.0.0-beta.36";
10
10
  //#endregion
11
11
  //#region src/action/index.ts
12
12
  const prompt = enquirer.prompt;
@@ -56,7 +56,7 @@ function scaffold(rootPath, replacements, templateName) {
56
56
  * @param {object} [options] - Optional CLI arguments used to choose the project name and template.
57
57
  * @param {string} [options.name] - Target folder name for the generated app.
58
58
  * @param {string} [options.template] - Template name such as `admin` or `minimal`.
59
- * @returns {Promise<void>} Resolves after the project is scaffolded, dependencies are installed, and tests pass.
59
+ * @returns {Promise<void>} Resolves after the project is scaffolded, dependencies are installed, action types are generated, and tests pass.
60
60
  * @throws {Error} When the selected template is unknown.
61
61
  * @example
62
62
  * ```ts
@@ -82,6 +82,7 @@ async function action(options = {}) {
82
82
  secret: generateSessionSecret()
83
83
  }, templateName);
84
84
  execSync(`cd ${answers.name} && npm install`, { stdio: "inherit" });
85
+ execSync(`cd ${answers.name} && npm run types`, { stdio: "inherit" });
85
86
  execSync(`cd ${answers.name} && npm run test`, { stdio: "inherit" });
86
87
  }
87
88
  /**
@@ -116,7 +117,10 @@ ${getTemplateNames().join(", ")}`)).option("--name <name>", "Project name").opti
116
117
  * [![License: MIT](https://img.shields.io/npm/l/create-faas-app.svg)](https://github.com/faasjs/faasjs/blob/main/packages/create-faas-app/LICENSE)
117
118
  * [![NPM Version](https://img.shields.io/npm/v/create-faas-app.svg)](https://www.npmjs.com/package/create-faas-app)
118
119
  *
119
- * Quick way to create a FaasJS project.
120
+ * Curated scaffolder for FaasJS projects. The `admin` template is the default
121
+ * React + Ant Design + PostgreSQL starter, and `minimal` provides a smaller
122
+ * React starter. After scaffolding, the CLI runs `npm install`, `npm run types`,
123
+ * and `npm run test` in the new project.
120
124
  *
121
125
  * ## Usage
122
126
  *
@@ -125,6 +129,8 @@ ${getTemplateNames().join(", ")}`)).option("--name <name>", "Project name").opti
125
129
  * npx create-faas-app --name faasjs-admin --template admin
126
130
  * npx create-faas-app --name faasjs-minimal --template minimal
127
131
  * ```
132
+ *
133
+ * @packageDocumentation
128
134
  */
129
135
  const commander = new Command();
130
136
  commander.storeOptionsAsProperties(false).allowUnknownOption(true).version(version).name("create-faas-app").exitOverride();
@@ -132,6 +138,12 @@ registerCreateFaasApp(commander);
132
138
  /**
133
139
  * Run the `create-faas-app` CLI with a provided argv array.
134
140
  *
141
+ * The array should use the same shape as `process.argv`, including executable
142
+ * and script slots. Parsing may prompt for a project name, create files, install
143
+ * dependencies, generate FaasJS action types, and run template tests. Commander
144
+ * help exits are swallowed and return the shared program; unexpected errors are
145
+ * printed with `console.error` and also return the program.
146
+ *
135
147
  * @param {string[]} argv - CLI arguments forwarded to Commander.
136
148
  * @returns {Promise<Command>} Commander program instance after parsing.
137
149
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-faas-app",
3
- "version": "8.0.0-beta.35",
3
+ "version": "8.0.0-beta.37",
4
4
  "homepage": "https://faasjs.com/doc/create-faas-app",
5
5
  "bugs": {
6
6
  "url": "https://github.com/faasjs/faasjs/issues"
@@ -7,6 +7,7 @@
7
7
  "dev": "vp dev",
8
8
  "build": "vp build",
9
9
  "start": "node --import @faasjs/node-utils/register-hooks server.ts",
10
+ "types": "faas types",
10
11
  "test": "vp test",
11
12
  "db:new": "faasjs-pg new",
12
13
  "db:status": "faasjs-pg status",
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Generated by @faasjs/dev.
3
+ *
4
+ * Do not edit this file manually.
5
+ */
6
+ import type { InferFaasAction } from '@faasjs/types'
7
+
8
+ declare module '@faasjs/types' {
9
+ interface FaasActions {
10
+ "features/auth/api/me": InferFaasAction<typeof import("../features/auth/api/me.api")>
11
+ "features/users/api/create": InferFaasAction<typeof import("../features/users/api/create.api")>
12
+ "features/users/api/detail": InferFaasAction<typeof import("../features/users/api/detail.api")>
13
+ "features/users/api/list": InferFaasAction<typeof import("../features/users/api/list.api")>
14
+ "features/users/api/update": InferFaasAction<typeof import("../features/users/api/update.api")>
15
+ }
16
+ }
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
3
3
 
4
4
  import api from '../me.api'
5
5
 
6
- describe('pages/home/api/auth/me', () => {
6
+ describe('features/auth/api/me', () => {
7
7
  it('returns the current user from the auth plugin demo', async () => {
8
8
  const handler = testApi(api)
9
9
 
@@ -1,7 +1,7 @@
1
1
  import { defineApi, HttpError } from '@faasjs/core'
2
2
  import { z } from '@faasjs/utils'
3
3
 
4
- import { AuthPlugin } from '../../../../plugins/auth'
4
+ import { AuthPlugin } from '../../../plugins/auth'
5
5
 
6
6
  const api = defineApi({
7
7
  schema: z.object({}).strict(),
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import api from '../create.api'
6
6
 
7
- describe('pages/home/api/users/create', () => {
7
+ describe('features/users/api/create', () => {
8
8
  it('creates a user with the shared pg bootstrap', async () => {
9
9
  const handler = testApi(api)
10
10
 
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import api from '../detail.api'
6
6
 
7
- describe('pages/home/api/users/detail', () => {
7
+ describe('features/users/api/detail', () => {
8
8
  it('returns one user', async () => {
9
9
  const client = await getClient()
10
10
  const [created] = await client.query('users').insert(
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import api from '../list.api'
6
6
 
7
- describe('pages/home/api/users/list', () => {
7
+ describe('features/users/api/list', () => {
8
8
  it('lists users with total count', async () => {
9
9
  const client = await getClient()
10
10
 
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest'
4
4
 
5
5
  import api from '../update.api'
6
6
 
7
- describe('pages/home/api/users/update', () => {
7
+ describe('features/users/api/update', () => {
8
8
  it('updates one user', async () => {
9
9
  const client = await getClient()
10
10
  const [created] = await client.query('users').insert(
@@ -1,35 +1,10 @@
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
- }
23
- }
24
- }
25
-
26
1
  import { faas, useApp } from '@faasjs/ant-design'
27
2
  import { useFaas } from '@faasjs/react'
28
3
  import { toErrorMessage } from '@faasjs/utils'
29
4
  import { Button, Card, Input, Space, Table, Typography } from 'antd'
30
5
  import { useState } from 'react'
31
6
 
32
- export default function HomePage() {
7
+ export default function UsersPage() {
33
8
  const app = useApp()
34
9
  const [name, setName] = useState('FaasJS')
35
10
  const [messageText, setMessageText] = useState('Create your first user through the FaasJS API')
@@ -38,7 +13,7 @@ export default function HomePage() {
38
13
  data: listData,
39
14
  loading: listLoading,
40
15
  reload,
41
- } = useFaas('/pages/home/api/users/list', { limit: 10 })
16
+ } = useFaas('features/users/api/list', { limit: 10 })
42
17
 
43
18
  const rows = listData?.rows || []
44
19
 
@@ -46,7 +21,7 @@ export default function HomePage() {
46
21
  const callApi = async () => {
47
22
  setCreating(true)
48
23
  try {
49
- const response = await faas('/pages/home/api/users/create', {
24
+ const response = await faas('features/users/api/create', {
50
25
  name: name.trim() || undefined,
51
26
  })
52
27
  const result = response.data
@@ -75,7 +50,7 @@ export default function HomePage() {
75
50
  setAuthLoading(true)
76
51
  try {
77
52
  const response = await faas(
78
- '/pages/home/api/auth/me',
53
+ 'features/auth/api/me',
79
54
  {},
80
55
  {
81
56
  headers: { authorization: 'Bearer demo-admin' },
@@ -137,7 +112,7 @@ export default function HomePage() {
137
112
  Load users slice
138
113
  </Button>
139
114
  <Button type="primary" loading={creating} onClick={callApi}>
140
- Create /pages/home/api/users/create
115
+ Create features/users/api/create
141
116
  </Button>
142
117
  <Button loading={authLoading} onClick={callAuthDemo}>
143
118
  Call auth plugin demo
@@ -1,7 +1,7 @@
1
1
  import { App } from '@faasjs/ant-design'
2
2
  import { createRoot } from 'react-dom/client'
3
3
 
4
- import HomePage from './pages/home'
4
+ import UsersPage from './features/users'
5
5
 
6
6
  createRoot(document.getElementById('root') as HTMLElement).render(
7
7
  <App
@@ -20,6 +20,6 @@ createRoot(document.getElementById('root') as HTMLElement).render(
20
20
  },
21
21
  }}
22
22
  >
23
- <HomePage />
23
+ <UsersPage />
24
24
  </App>,
25
25
  )
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "@faasjs/types/tsconfig/build.json",
3
- "include": ["src", "vite.config.ts", "server.ts"]
3
+ "include": ["src", "src/.faasjs/types.d.ts", "vite.config.ts", "server.ts"]
4
4
  }
@@ -7,6 +7,7 @@
7
7
  "dev": "vp dev",
8
8
  "build": "vp build",
9
9
  "start": "node --import @faasjs/node-utils/register-hooks server.ts",
10
+ "types": "faas types",
10
11
  "test": "vp test"
11
12
  },
12
13
  "devDependencies": {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generated by @faasjs/dev.
3
+ *
4
+ * Do not edit this file manually.
5
+ */
6
+ import type { InferFaasAction } from '@faasjs/types'
7
+
8
+ declare module '@faasjs/types' {
9
+ interface FaasActions {
10
+ "features/home/api/hello": InferFaasAction<typeof import("../features/home/api/hello.api")>
11
+ }
12
+ }
@@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest'
3
3
 
4
4
  import api from '../hello.api'
5
5
 
6
- describe('pages/home/api/hello', () => {
6
+ describe('features/home/api/hello', () => {
7
7
  it('should work', async () => {
8
8
  const handler = testApi(api)
9
9
 
@@ -1,12 +1,3 @@
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
- }
9
-
10
1
  import { useState } from 'react'
11
2
 
12
3
  import { useFaas } from '../../react-client'
@@ -15,7 +6,7 @@ export default function HomePage() {
15
6
  const [name, setName] = useState('FaasJS')
16
7
 
17
8
  const { data, loading, reload } = useFaas(
18
- '/pages/home/api/hello',
9
+ 'features/home/api/hello',
19
10
  { name: name.trim() || undefined },
20
11
  { skip: true },
21
12
  )
@@ -39,7 +30,7 @@ export default function HomePage() {
39
30
  onClick={() => reload({ name: name.trim() || undefined })}
40
31
  disabled={loading}
41
32
  >
42
- {loading ? 'Loading...' : 'Call /pages/home/api/hello'}
33
+ {loading ? 'Loading...' : 'Call features/home/api/hello'}
43
34
  </button>
44
35
  </main>
45
36
  )
@@ -1,5 +1,5 @@
1
1
  import { createRoot } from 'react-dom/client'
2
2
 
3
- import HomePage from './pages/home'
3
+ import HomePage from './features/home'
4
4
 
5
5
  createRoot(document.getElementById('root') as HTMLElement).render(<HomePage />)
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "extends": "@faasjs/types/tsconfig/build.json",
3
- "include": ["src", "vite.config.ts", "server.ts"]
3
+ "include": ["src", "src/.faasjs/types.d.ts", "vite.config.ts", "server.ts"]
4
4
  }