@alxia/create 0.1.4 → 0.1.6
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/README.md +81 -24
- package/dist/copy.d.ts +11 -3
- package/dist/copy.d.ts.map +1 -1
- package/dist/index.js +51 -23
- package/dist/index.js.map +8 -7
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/packument.d.ts +18 -0
- package/dist/packument.d.ts.map +1 -0
- package/dist/registry.d.ts +29 -10
- package/dist/registry.d.ts.map +1 -1
- package/dist/versions.d.ts +1 -1
- package/dist/versions.d.ts.map +1 -1
- package/docs/README.md +6 -5
- package/docs/guide.md +503 -59
- package/docs/roadmap.md +49 -4
- package/docs/troubleshooting.md +249 -4
- package/package.json +5 -4
- package/templates/api/.vscode/extensions.json +3 -0
- package/templates/api/.vscode/settings.json +8 -0
- package/templates/api/README.md +78 -6
- package/templates/api/_biome.json +32 -0
- package/templates/api/openapi-codegen.config.ts +11 -0
- package/templates/api/openapi.yaml +116 -0
- package/templates/api/package.json +27 -19
- package/templates/api/src/app.spec.ts +57 -38
- package/templates/api/src/app.ts +5 -30
- package/templates/api/src/context.ts +19 -0
- package/templates/api/src/generated/alxia.ts +61 -0
- package/templates/api/src/generated/operations.ts +133 -0
- package/templates/api/src/generated/paths.ts +170 -0
- package/templates/api/src/generated/types.ts +170 -0
- package/templates/api/src/generated/zod.ts +31 -0
- package/templates/api/src/routes/todos.ts +31 -0
- package/templates/api/src/server.ts +12 -12
- package/templates/api/tsconfig.json +23 -23
- package/templates/react-router/.vscode/extensions.json +3 -0
- package/templates/react-router/.vscode/settings.json +8 -0
- package/templates/react-router/README.md +27 -0
- package/templates/react-router/_biome.json +49 -0
- package/templates/react-router/app/app.css +3 -2
- package/templates/react-router/app/routes/home.tsx +1 -1
- package/templates/react-router/app/routes.ts +1 -1
- package/templates/react-router/package.json +7 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Generated by @nxgt/openapi-codegen from ../../openapi.yaml. Do not edit.
|
|
2
|
+
|
|
3
|
+
export interface Todo {
|
|
4
|
+
id: number;
|
|
5
|
+
title: string;
|
|
6
|
+
done: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface NewTodo {
|
|
10
|
+
title: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Unauthorized {
|
|
14
|
+
error: 'unauthorized';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NotFound {
|
|
18
|
+
error: 'not_found';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ValidationError {
|
|
22
|
+
error: 'validation';
|
|
23
|
+
issues: {
|
|
24
|
+
target: 'params' | 'query' | 'headers' | 'cookies' | 'body';
|
|
25
|
+
path: (string | number)[];
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GetTodoParam {
|
|
32
|
+
id: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Operations {
|
|
36
|
+
/** Every todo */
|
|
37
|
+
listTodos: {
|
|
38
|
+
method: 'get';
|
|
39
|
+
path: '/todos';
|
|
40
|
+
honoPath: '/todos';
|
|
41
|
+
param: {};
|
|
42
|
+
query: {};
|
|
43
|
+
header: {};
|
|
44
|
+
responses: {
|
|
45
|
+
/** The todos, oldest first */
|
|
46
|
+
200: {
|
|
47
|
+
'application/json': Todo[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** Add a todo */
|
|
52
|
+
createTodo: {
|
|
53
|
+
method: 'post';
|
|
54
|
+
path: '/todos';
|
|
55
|
+
honoPath: '/todos';
|
|
56
|
+
param: {};
|
|
57
|
+
query: {};
|
|
58
|
+
header: {};
|
|
59
|
+
json: NewTodo;
|
|
60
|
+
responses: {
|
|
61
|
+
/** The todo, created */
|
|
62
|
+
201: {
|
|
63
|
+
'application/json': Todo;
|
|
64
|
+
};
|
|
65
|
+
/** alxia's own 400, for a request the schemas refuse */
|
|
66
|
+
400: {
|
|
67
|
+
'application/json': ValidationError;
|
|
68
|
+
};
|
|
69
|
+
/** No x-api-key header, or not the key */
|
|
70
|
+
401: {
|
|
71
|
+
'application/json': Unauthorized;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/** One todo */
|
|
76
|
+
getTodo: {
|
|
77
|
+
method: 'get';
|
|
78
|
+
path: '/todos/{id}';
|
|
79
|
+
honoPath: '/todos/:id';
|
|
80
|
+
param: GetTodoParam;
|
|
81
|
+
query: {};
|
|
82
|
+
header: {};
|
|
83
|
+
responses: {
|
|
84
|
+
/** The todo */
|
|
85
|
+
200: {
|
|
86
|
+
'application/json': Todo;
|
|
87
|
+
};
|
|
88
|
+
/** alxia's own 400, for a request the schemas refuse */
|
|
89
|
+
400: {
|
|
90
|
+
'application/json': ValidationError;
|
|
91
|
+
};
|
|
92
|
+
/** No todo has this id */
|
|
93
|
+
404: {
|
|
94
|
+
'application/json': NotFound;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** What a client sends and gets back: `args` after the operationId, and each declared `reply`. */
|
|
101
|
+
export interface ClientOperations {
|
|
102
|
+
/** Every todo */
|
|
103
|
+
listTodos: {
|
|
104
|
+
method: 'get';
|
|
105
|
+
path: '/todos';
|
|
106
|
+
args: [];
|
|
107
|
+
reply: { status: 200; type: 'application/json'; data: Todo[] };
|
|
108
|
+
wire: { status: 200; type: 'application/json'; data: Todo[] };
|
|
109
|
+
};
|
|
110
|
+
/** Add a todo */
|
|
111
|
+
createTodo: {
|
|
112
|
+
method: 'post';
|
|
113
|
+
path: '/todos';
|
|
114
|
+
args: [input: {
|
|
115
|
+
json: NewTodo;
|
|
116
|
+
}];
|
|
117
|
+
reply:
|
|
118
|
+
| { status: 201; type: 'application/json'; data: Todo }
|
|
119
|
+
| { status: 400; type: 'application/json'; data: ValidationError }
|
|
120
|
+
| { status: 401; type: 'application/json'; data: Unauthorized };
|
|
121
|
+
wire:
|
|
122
|
+
| { status: 201; type: 'application/json'; data: Todo }
|
|
123
|
+
| { status: 400; type: 'application/json'; data: ValidationError }
|
|
124
|
+
| { status: 401; type: 'application/json'; data: Unauthorized };
|
|
125
|
+
};
|
|
126
|
+
/** One todo */
|
|
127
|
+
getTodo: {
|
|
128
|
+
method: 'get';
|
|
129
|
+
path: '/todos/{id}';
|
|
130
|
+
args: [input: {
|
|
131
|
+
param: {
|
|
132
|
+
id: number;
|
|
133
|
+
};
|
|
134
|
+
}];
|
|
135
|
+
reply:
|
|
136
|
+
| { status: 200; type: 'application/json'; data: Todo }
|
|
137
|
+
| { status: 400; type: 'application/json'; data: ValidationError }
|
|
138
|
+
| { status: 404; type: 'application/json'; data: NotFound };
|
|
139
|
+
wire:
|
|
140
|
+
| { status: 200; type: 'application/json'; data: Todo }
|
|
141
|
+
| { status: 400; type: 'application/json'; data: ValidationError }
|
|
142
|
+
| { status: 404; type: 'application/json'; data: NotFound };
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The operation behind each route: `routes.put(path)` finds it here. */
|
|
147
|
+
export interface OperationsByRoute {
|
|
148
|
+
'get /todos': 'listTodos';
|
|
149
|
+
'post /todos': 'createTodo';
|
|
150
|
+
'get /todos/{id}': 'getTodo';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** The paths with an operation for each method. */
|
|
154
|
+
export interface PathsByMethod {
|
|
155
|
+
get: '/todos' | '/todos/{id}';
|
|
156
|
+
put: never;
|
|
157
|
+
post: '/todos';
|
|
158
|
+
delete: never;
|
|
159
|
+
options: never;
|
|
160
|
+
head: never;
|
|
161
|
+
patch: never;
|
|
162
|
+
trace: never;
|
|
163
|
+
query: never;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The operations under each tag. */
|
|
167
|
+
export interface OperationsByTag {}
|
|
168
|
+
|
|
169
|
+
/** `PathsByMethod`, for each tag. */
|
|
170
|
+
export interface PathsByTag {}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Generated by @nxgt/openapi-codegen from ../../openapi.yaml. Do not edit.
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
export const zTodo = z.object({
|
|
6
|
+
id: z.int(),
|
|
7
|
+
title: z.string(),
|
|
8
|
+
done: z.boolean(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const zNewTodo = z.object({
|
|
12
|
+
title: z.string().min(1),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const zUnauthorized = z.object({
|
|
16
|
+
error: z.literal('unauthorized'),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const zNotFound = z.object({
|
|
20
|
+
error: z.literal('not_found'),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const zValidationError = z.object({
|
|
24
|
+
error: z.literal('validation'),
|
|
25
|
+
issues: z.array(z.object({
|
|
26
|
+
target: z.enum(['params', 'query', 'headers', 'cookies', 'body']),
|
|
27
|
+
path: z.array(z.union([z.string(), z.int()])),
|
|
28
|
+
code: z.string(),
|
|
29
|
+
message: z.string(),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineMiddleware, defineRoutes } from "@alxia/core";
|
|
2
|
+
import { apiKey } from "../context";
|
|
3
|
+
import { operations } from "../generated/alxia";
|
|
4
|
+
|
|
5
|
+
// A middleware of the routes it is given to: it answers 401 without the key,
|
|
6
|
+
// before the body is read. openapi.yaml declares that 401.
|
|
7
|
+
const requireKey = defineMiddleware(({ request, reply }, next) =>
|
|
8
|
+
request.headers.get("x-api-key") === apiKey
|
|
9
|
+
? next()
|
|
10
|
+
: reply(401, { error: "unauthorized" as const }),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
// Each route is an operation of openapi.yaml, generated into
|
|
14
|
+
// src/generated/alxia.ts: its method, path and schemas come from the spec,
|
|
15
|
+
// so the handler is all that is written here. The request is validated
|
|
16
|
+
// just before the handler, and its reply against the spec's responses.
|
|
17
|
+
// `todos` is the registered context's: defineRoutes() reads it, and the
|
|
18
|
+
// app that mounts these routes must give it.
|
|
19
|
+
export const todoRoutes = defineRoutes()
|
|
20
|
+
.route(operations.listTodos, ({ todos, reply }) => reply.ok(todos))
|
|
21
|
+
.route(operations.createTodo, requireKey, ({ body, todos, reply }) => {
|
|
22
|
+
const todo = { id: todos.length + 1, title: body.title, done: false };
|
|
23
|
+
todos.push(todo);
|
|
24
|
+
return reply.created(todo);
|
|
25
|
+
})
|
|
26
|
+
.route(operations.getTodo, ({ params, todos, reply }) => {
|
|
27
|
+
const todo = todos.find(({ id }) => id === params.id);
|
|
28
|
+
return todo
|
|
29
|
+
? reply.ok(todo)
|
|
30
|
+
: reply.notFound({ error: "not_found" as const });
|
|
31
|
+
});
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { app } from
|
|
1
|
+
import { app } from "./app";
|
|
2
2
|
|
|
3
3
|
// Stop as the platform asks. In a container Bun is process 1, which a
|
|
4
4
|
// signal with no handler does not stop: `docker stop` would wait.
|
|
5
|
-
for (const signal of [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
for (const signal of ["SIGINT", "SIGTERM"] as const) {
|
|
6
|
+
process.once(signal, () => {
|
|
7
|
+
void app.stop().then(
|
|
8
|
+
() => process.exit(0),
|
|
9
|
+
(error: unknown) => {
|
|
10
|
+
console.error(error);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const server = app.listen(Number(Bun.env[
|
|
17
|
+
const server = app.listen(Number(Bun.env["PORT"] ?? 3000));
|
|
18
18
|
console.log(`listening on ${server.url}`);
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"types": ["bun"],
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noImplicitOverride": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true,
|
|
18
|
+
"exactOptionalPropertyTypes": true,
|
|
19
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"forceConsistentCasingInFileNames": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["src"]
|
|
25
25
|
}
|
|
@@ -78,6 +78,33 @@ Make sure to deploy the output of `bun run build`
|
|
|
78
78
|
│ └── server/ # Server-side code
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
## Lint and format
|
|
82
|
+
|
|
83
|
+
[Biome](https://biomejs.dev) lints and formats the project, as `biome.json`
|
|
84
|
+
sets it: Biome's recommended rules, spaces, double quotes, imports
|
|
85
|
+
sorted. What the build and `react-router typegen` write, `build/` and
|
|
86
|
+
`.react-router/`, is skipped.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
bun run check # lint, format and sort imports, fixing what it can
|
|
90
|
+
bun run lint # lint only
|
|
91
|
+
bun run format # format only, in place
|
|
92
|
+
bun run check:ci # what CI runs: changes nothing, fails on an error
|
|
93
|
+
bun run verify # check:ci, then typecheck, then build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`bun run check:ci`, not `bun ci`: `bun ci` is Bun's frozen-lockfile
|
|
97
|
+
install. In VS Code, `.vscode/` recommends Biome's extension and formats
|
|
98
|
+
on save with it.
|
|
99
|
+
|
|
100
|
+
`@biomejs/biome` is pinned exactly, since a release of Biome may format
|
|
101
|
+
differently. To move it:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
bun add --dev --exact @biomejs/biome@latest
|
|
105
|
+
bunx biome migrate --write
|
|
106
|
+
```
|
|
107
|
+
|
|
81
108
|
## Styling
|
|
82
109
|
|
|
83
110
|
This template comes with [Tailwind CSS](https://tailwindcss.com/) already configured for a simple default starting experience. You can use whatever CSS framework you prefer.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": true
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"includes": ["**", "!!**/build", "!!**/.react-router"]
|
|
10
|
+
},
|
|
11
|
+
"formatter": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"indentStyle": "space"
|
|
14
|
+
},
|
|
15
|
+
"css": {
|
|
16
|
+
"parser": {
|
|
17
|
+
"tailwindDirectives": true
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"linter": {
|
|
21
|
+
"enabled": true,
|
|
22
|
+
"rules": {
|
|
23
|
+
"preset": "recommended",
|
|
24
|
+
"correctness": {
|
|
25
|
+
"noEmptyPattern": "off"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"assist": {
|
|
30
|
+
"enabled": true,
|
|
31
|
+
"actions": {
|
|
32
|
+
"source": {
|
|
33
|
+
"organizeImports": "on"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"overrides": [
|
|
38
|
+
{
|
|
39
|
+
"includes": ["**/app/welcome/**"],
|
|
40
|
+
"linter": {
|
|
41
|
+
"rules": {
|
|
42
|
+
"a11y": {
|
|
43
|
+
"noSvgWithoutTitle": "off"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
2
|
|
|
3
3
|
@theme {
|
|
4
|
-
--font-sans:
|
|
5
|
-
"
|
|
4
|
+
--font-sans:
|
|
5
|
+
"Inter", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji",
|
|
6
|
+
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
html,
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
"build": "react-router build",
|
|
7
7
|
"dev": "react-router dev",
|
|
8
8
|
"start": "bun build/server/index.js",
|
|
9
|
-
"typecheck": "react-router typegen && tsc"
|
|
9
|
+
"typecheck": "react-router typegen && tsc",
|
|
10
|
+
"lint": "biome lint",
|
|
11
|
+
"format": "biome format --write",
|
|
12
|
+
"check": "biome check --write",
|
|
13
|
+
"check:ci": "biome ci",
|
|
14
|
+
"verify": "bun run check:ci && bun run typecheck && bun run build"
|
|
10
15
|
},
|
|
11
16
|
"dependencies": {
|
|
12
17
|
"@alxia/core": "workspace:^",
|
|
@@ -19,6 +24,7 @@
|
|
|
19
24
|
"react-router": "^8.4.0"
|
|
20
25
|
},
|
|
21
26
|
"devDependencies": {
|
|
27
|
+
"@biomejs/biome": "2.5.15",
|
|
22
28
|
"@react-router/dev": "^8.4.0",
|
|
23
29
|
"@tailwindcss/vite": "^4.2.2",
|
|
24
30
|
"@types/node": "^22",
|