@evjs/create-app 0.3.22 → 0.3.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evjs/create-app",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "description": "Scaffold a new evjs project",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,6 +14,7 @@ npm run dev
14
14
  |------|---------|
15
15
  | `ev.config.ts` | Selects SPA routing mode |
16
16
  | `src/pages/page.tsx` | Root Page that exercises the REST endpoints |
17
+ | `src/shared/posts.ts` | JSON DTOs shared through type-only imports by client and server |
17
18
  | `src/pages/layout.tsx` | File-convention root layout |
18
19
  | `src/middlewares/middleware.ts` | Ordered global middleware composition anchor |
19
20
  | `src/middlewares/response-metadata.ts` | Ordinary middleware module composed by the anchor |
@@ -26,6 +27,8 @@ npm run dev
26
27
 
27
28
  ## What It Demonstrates
28
29
 
30
+ - Application HTTP calls through `import { api } from '@evjs/ev'` and `.json<Post>()`
31
+ - Handwritten shared DTOs, existing runtime validation, and no API type generation
29
32
  - Directory-owned `api.ts` anchors with uppercase method exports (`GET`, `POST`, `PUT`, `DELETE`)
30
33
  - Dynamic route directories (`$id/api.ts` -> `:id`)
31
34
  - Query string parsing (`?limit=N`)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-api-routes",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import { withMiddlewares } from "@evjs/ev/api";
12
+ import type { CreatePostInput } from "@/shared/posts";
12
13
  import { apiPolicies } from "../policies";
13
14
  import { createPost, posts } from "./posts-store";
14
15
  import validatePost from "./validate-post";
@@ -23,10 +24,7 @@ export const GET = withMiddlewares(async (req) => {
23
24
  /** Create a post. */
24
25
  export const POST = withMiddlewares(
25
26
  async (_req, ctx) => {
26
- const { title, body } = await ctx.req.json<{
27
- title: string;
28
- body: string;
29
- }>();
27
+ const { title, body } = await ctx.req.json<CreatePostInput>();
30
28
 
31
29
  return Response.json(createPost({ title, body }), { status: 201 });
32
30
  },
@@ -1,10 +1,4 @@
1
- /** Simulated post database private to the /api/posts route scope. */
2
- export interface Post {
3
- id: string;
4
- title: string;
5
- body: string;
6
- createdAt: string;
7
- }
1
+ import type { CreatePostInput, Post } from "@/shared/posts";
8
2
 
9
3
  export const posts: Post[] = [
10
4
  {
@@ -23,7 +17,7 @@ export const posts: Post[] = [
23
17
 
24
18
  let nextId = 3;
25
19
 
26
- export function createPost(input: { title: string; body: string }): Post {
20
+ export function createPost(input: CreatePostInput): Post {
27
21
  const post: Post = {
28
22
  id: String(nextId++),
29
23
  title: input.title,
@@ -1,13 +1,6 @@
1
+ import { api } from "@evjs/ev";
1
2
  import { useState } from "react";
2
-
3
- // ── Types ──
4
-
5
- interface Post {
6
- id: string;
7
- title: string;
8
- body: string;
9
- createdAt: string;
10
- }
3
+ import type { CreatePostInput, Post } from "@/shared/posts";
11
4
 
12
5
  // ── Posts Page ──
13
6
 
@@ -24,9 +17,7 @@ export default function PostsPage() {
24
17
  setIsLoading(true);
25
18
  setError(null);
26
19
  try {
27
- const res = await fetch("/api/posts");
28
- if (!res.ok) throw new Error(`Failed: ${res.status}`);
29
- const data = await res.json();
20
+ const data = await api.get("/api/posts").json<Post[]>();
30
21
  setPosts(data);
31
22
  } catch (err) {
32
23
  setError(err instanceof Error ? err.message : String(err));
@@ -42,12 +33,8 @@ export default function PostsPage() {
42
33
 
43
34
  setIsCreating(true);
44
35
  try {
45
- const res = await fetch("/api/posts", {
46
- method: "POST",
47
- headers: { "Content-Type": "application/json" },
48
- body: JSON.stringify({ title, body }),
49
- });
50
- if (!res.ok) throw new Error(`Failed: ${res.status}`);
36
+ const input: CreatePostInput = { title, body };
37
+ await api.post("/api/posts", { json: input }).json<Post>();
51
38
  setTitle("");
52
39
  setBody("");
53
40
  await fetchPosts();
@@ -61,7 +48,7 @@ export default function PostsPage() {
61
48
  // Delete a post via DELETE
62
49
  async function handleDelete(id: string) {
63
50
  try {
64
- const res = await fetch(`/api/posts/${id}`, { method: "DELETE" });
51
+ const res = await api.delete(`/api/posts/${encodeURIComponent(id)}`);
65
52
  if (!res.ok) throw new Error(`Failed: ${res.status}`);
66
53
  await fetchPosts();
67
54
  } catch (err) {
@@ -209,7 +196,7 @@ function HealthCheck() {
209
196
  const [health, setHealth] = useState<Record<string, unknown> | null>(null);
210
197
 
211
198
  async function checkHealth() {
212
- const res = await fetch("/api/health");
199
+ const res = await api.get("/api/health");
213
200
  setHealth(await res.json());
214
201
  }
215
202
 
@@ -0,0 +1,10 @@
1
+ /** HTTP DTOs shared with import type; runtime validation stays on the server. */
2
+ export interface CreatePostInput {
3
+ title: string;
4
+ body: string;
5
+ }
6
+
7
+ export interface Post extends CreatePostInput {
8
+ id: string;
9
+ createdAt: string;
10
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-basic",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-complex-routing",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-custom-ws-transport",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-mpa",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-plugin-authoring",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-sqlite",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-tailwind",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "example-with-trpc",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": true,
5
5
  "scripts": {
6
6
  "dev": "ev dev",