omni-rest-express-example 1.0.0
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 +54 -0
- package/bun.lock +269 -0
- package/dist/index.js +43 -0
- package/index.js +46 -0
- package/index.ts +36 -0
- package/openapi.json +1627 -0
- package/package.json +25 -0
- package/prisma/dev.db +0 -0
- package/prisma/schema.prisma +52 -0
- package/prisma/seed.ts +82 -0
- package/src/schemas.generated.ts +64 -0
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "omni-rest-express-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Express.js example using omni-rest for auto-generated REST APIs",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "tsx watch index.ts",
|
|
8
|
+
"start": "tsx index.ts",
|
|
9
|
+
"db:generate": "prisma generate",
|
|
10
|
+
"db:push": "prisma db push",
|
|
11
|
+
"db:seed": "tsx prisma/seed.ts"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@prisma/client": "^5.0.0",
|
|
15
|
+
"express": "^4.22.1",
|
|
16
|
+
"omni-rest": "file:../..",
|
|
17
|
+
"swagger-ui-express": "^5.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/express": "^4.17.0",
|
|
21
|
+
"@types/swagger-ui-express": "^4.1.0",
|
|
22
|
+
"prisma": "^5.0.0",
|
|
23
|
+
"tsx": "^4.0.0"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/prisma/dev.db
ADDED
|
Binary file
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Sample Prisma schema for omni-rest examples
|
|
2
|
+
generator client {
|
|
3
|
+
provider = "prisma-client-js"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
datasource db {
|
|
7
|
+
provider = "sqlite"
|
|
8
|
+
url = "file:./dev.db"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
model Department {
|
|
12
|
+
id Int @id @default(autoincrement())
|
|
13
|
+
name String
|
|
14
|
+
description String?
|
|
15
|
+
createdAt DateTime @default(now())
|
|
16
|
+
updatedAt DateTime @updatedAt
|
|
17
|
+
|
|
18
|
+
categories Category[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
model Category {
|
|
22
|
+
id Int @id @default(autoincrement())
|
|
23
|
+
name String
|
|
24
|
+
departmentId Int
|
|
25
|
+
department Department @relation(fields: [departmentId], references: [id])
|
|
26
|
+
createdAt DateTime @default(now())
|
|
27
|
+
updatedAt DateTime @updatedAt
|
|
28
|
+
|
|
29
|
+
products Product[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
model Product {
|
|
33
|
+
id Int @id @default(autoincrement())
|
|
34
|
+
name String
|
|
35
|
+
price Float
|
|
36
|
+
categoryId Int
|
|
37
|
+
category Category @relation(fields: [categoryId], references: [id])
|
|
38
|
+
cityId Int?
|
|
39
|
+
city City? @relation(fields: [cityId], references: [id])
|
|
40
|
+
createdAt DateTime @default(now())
|
|
41
|
+
updatedAt DateTime @updatedAt
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
model City {
|
|
45
|
+
id Int @id @default(autoincrement())
|
|
46
|
+
name String
|
|
47
|
+
country String
|
|
48
|
+
createdAt DateTime @default(now())
|
|
49
|
+
updatedAt DateTime @updatedAt
|
|
50
|
+
|
|
51
|
+
products Product[]
|
|
52
|
+
}
|
package/prisma/seed.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
|
|
3
|
+
const prisma = new PrismaClient();
|
|
4
|
+
|
|
5
|
+
async function main() {
|
|
6
|
+
// Create departments
|
|
7
|
+
const engineering = await prisma.department.create({
|
|
8
|
+
data: {
|
|
9
|
+
name: "Engineering",
|
|
10
|
+
description: "Software development department",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const sales = await prisma.department.create({
|
|
15
|
+
data: {
|
|
16
|
+
name: "Sales",
|
|
17
|
+
description: "Sales and marketing department",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Create categories
|
|
22
|
+
const webDev = await prisma.category.create({
|
|
23
|
+
data: {
|
|
24
|
+
name: "Web Development",
|
|
25
|
+
departmentId: engineering.id,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const mobileDev = await prisma.category.create({
|
|
30
|
+
data: {
|
|
31
|
+
name: "Mobile Development",
|
|
32
|
+
departmentId: engineering.id,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Create products
|
|
37
|
+
await prisma.product.createMany({
|
|
38
|
+
data: [
|
|
39
|
+
{
|
|
40
|
+
name: "React Website",
|
|
41
|
+
price: 5000,
|
|
42
|
+
categoryId: webDev.id,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "iOS App",
|
|
46
|
+
price: 10000,
|
|
47
|
+
categoryId: mobileDev.id,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "Android App",
|
|
51
|
+
price: 8000,
|
|
52
|
+
categoryId: mobileDev.id,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Create cities
|
|
58
|
+
const newYork = await prisma.city.create({
|
|
59
|
+
data: {
|
|
60
|
+
name: "New York",
|
|
61
|
+
country: "USA",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const london = await prisma.city.create({
|
|
66
|
+
data: {
|
|
67
|
+
name: "London",
|
|
68
|
+
country: "UK",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log("Database seeded successfully!");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main()
|
|
76
|
+
.catch((e) => {
|
|
77
|
+
console.error(e);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
})
|
|
80
|
+
.finally(async () => {
|
|
81
|
+
await prisma.$disconnect();
|
|
82
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-generated Zod schemas from Prisma schema.
|
|
3
|
+
* Generated by omni-rest — do not edit manually.
|
|
4
|
+
* Re-run after schema changes.
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
|
|
8
|
+
// ─── Department ──────────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
export const DepartmentCreateSchema = z.object({
|
|
11
|
+
name: z.string(),
|
|
12
|
+
description: z.string().optional(),
|
|
13
|
+
createdAt: z.coerce.date(),
|
|
14
|
+
updatedAt: z.coerce.date(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const DepartmentUpdateSchema = DepartmentCreateSchema.partial();
|
|
18
|
+
|
|
19
|
+
export type DepartmentCreate = z.infer<typeof DepartmentCreateSchema>;
|
|
20
|
+
export type DepartmentUpdate = z.infer<typeof DepartmentUpdateSchema>;
|
|
21
|
+
|
|
22
|
+
// ─── Category ──────────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
export const CategoryCreateSchema = z.object({
|
|
25
|
+
name: z.string(),
|
|
26
|
+
departmentId: z.number().int(),
|
|
27
|
+
createdAt: z.coerce.date(),
|
|
28
|
+
updatedAt: z.coerce.date(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const CategoryUpdateSchema = CategoryCreateSchema.partial();
|
|
32
|
+
|
|
33
|
+
export type CategoryCreate = z.infer<typeof CategoryCreateSchema>;
|
|
34
|
+
export type CategoryUpdate = z.infer<typeof CategoryUpdateSchema>;
|
|
35
|
+
|
|
36
|
+
// ─── Product ──────────────────────────────────────────────────────────────────
|
|
37
|
+
|
|
38
|
+
export const ProductCreateSchema = z.object({
|
|
39
|
+
name: z.string(),
|
|
40
|
+
price: z.number(),
|
|
41
|
+
categoryId: z.number().int(),
|
|
42
|
+
cityId: z.number().int().optional(),
|
|
43
|
+
createdAt: z.coerce.date(),
|
|
44
|
+
updatedAt: z.coerce.date(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const ProductUpdateSchema = ProductCreateSchema.partial();
|
|
48
|
+
|
|
49
|
+
export type ProductCreate = z.infer<typeof ProductCreateSchema>;
|
|
50
|
+
export type ProductUpdate = z.infer<typeof ProductUpdateSchema>;
|
|
51
|
+
|
|
52
|
+
// ─── City ──────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
export const CityCreateSchema = z.object({
|
|
55
|
+
name: z.string(),
|
|
56
|
+
country: z.string(),
|
|
57
|
+
createdAt: z.coerce.date(),
|
|
58
|
+
updatedAt: z.coerce.date(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const CityUpdateSchema = CityCreateSchema.partial();
|
|
62
|
+
|
|
63
|
+
export type CityCreate = z.infer<typeof CityCreateSchema>;
|
|
64
|
+
export type CityUpdate = z.infer<typeof CityUpdateSchema>;
|