better-ts-stack 1.1.2 → 1.1.4
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 +16 -27
- package/dist/builder/configGenerator.d.ts +1 -0
- package/dist/builder/configGenerator.d.ts.map +1 -1
- package/dist/builder/configGenerator.js +41 -4
- package/dist/builder/configGenerator.js.map +1 -1
- package/dist/builder/index.d.ts.map +1 -1
- package/dist/builder/index.js +3 -0
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/moduleSelector.d.ts.map +1 -1
- package/dist/builder/moduleSelector.js +2 -5
- package/dist/builder/moduleSelector.js.map +1 -1
- package/dist/output/nextSteps.d.ts.map +1 -1
- package/dist/output/nextSteps.js +22 -0
- package/dist/output/nextSteps.js.map +1 -1
- package/package.json +1 -1
- package/templates/backend/express/config.json +3 -3
- package/templates/backend/express/src/index.ts +19 -4
- package/templates/frontend/nextjs/config.json +1 -2
- package/templates/frontend/nextjs/next.config.ts.hbs +12 -0
- package/templates/frontend/tanstack/config.json +48 -49
- package/templates/modules/auth/express/src/controllers/authController.ts.hbs +62 -13
- package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +26 -26
- package/templates/modules/auth/express/src/services/userStore.ts.hbs +22 -0
- package/templates/modules/docker/Dockerfile.hbs +133 -125
- package/templates/modules/docker/config.json +1 -1
- package/templates/modules/mongoose/{config.json → express/config.json} +2 -2
- package/templates/modules/mongoose/{src → express/src}/models/User.ts +48 -48
- package/templates/modules/mongoose/nextjs/config.json +16 -0
- package/templates/modules/mongoose/nextjs/lib/db.ts +36 -0
- package/templates/modules/mongoose/nextjs/models/User.ts +48 -0
- package/templates/modules/mongoose/tanstack/config.json +17 -0
- package/templates/modules/mongoose/tanstack/src/lib/db.ts +37 -0
- package/templates/modules/mongoose/tanstack/src/models/User.ts +48 -0
- package/templates/frontend/nextjs/next.config.ts +0 -8
- package/templates/modules/mongoose/src/lib/db.ts.hbs +0 -43
- /package/templates/modules/mongoose/{src → express/src}/lib/db.ts +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import mongoose, { type Model, Schema } from "mongoose";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* User document interface
|
|
5
|
+
*/
|
|
6
|
+
export interface IUser {
|
|
7
|
+
email: string;
|
|
8
|
+
name?: string | null;
|
|
9
|
+
password: string;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
updatedAt: Date;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* User schema definition
|
|
16
|
+
*/
|
|
17
|
+
const userSchema = new Schema<IUser>(
|
|
18
|
+
{
|
|
19
|
+
email: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
unique: true,
|
|
23
|
+
lowercase: true,
|
|
24
|
+
trim: true,
|
|
25
|
+
},
|
|
26
|
+
name: {
|
|
27
|
+
type: String,
|
|
28
|
+
trim: true,
|
|
29
|
+
},
|
|
30
|
+
password: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
minlength: 6,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
timestamps: true,
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* User model
|
|
43
|
+
*/
|
|
44
|
+
const User =
|
|
45
|
+
(mongoose.models.User as Model<IUser> | undefined) ??
|
|
46
|
+
mongoose.model<IUser>("User", userSchema);
|
|
47
|
+
|
|
48
|
+
export default User;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "mongoose",
|
|
3
|
+
"name": "Mongoose (MongoDB)",
|
|
4
|
+
"description": "MongoDB database integration for TanStack Start using Mongoose ODM",
|
|
5
|
+
"type": "database",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"mongoose": "^9.9.5",
|
|
8
|
+
"mongodb": "^7.6.0",
|
|
9
|
+
"dotenv": "^17.4.2"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {},
|
|
12
|
+
"scripts": {},
|
|
13
|
+
"envVars": {
|
|
14
|
+
"MONGODB_URI": "mongodb://localhost:27017/myapp"
|
|
15
|
+
},
|
|
16
|
+
"templateFiles": []
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
|
|
4
|
+
// Reuse one connection across hot reloads and concurrent requests
|
|
5
|
+
const globalForMongoose = globalThis as unknown as {
|
|
6
|
+
mongooseConnection?: Promise<typeof mongoose>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Connects Mongoose once and returns the shared connection.
|
|
11
|
+
* Call this in server code before querying Mongoose models.
|
|
12
|
+
*/
|
|
13
|
+
export async function connectDB(): Promise<typeof mongoose> {
|
|
14
|
+
const mongoUri = process.env.MONGODB_URI;
|
|
15
|
+
|
|
16
|
+
if (!mongoUri) {
|
|
17
|
+
throw new Error("MONGODB_URI environment variable is not defined");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
globalForMongoose.mongooseConnection ??= mongoose
|
|
21
|
+
.connect(mongoUri)
|
|
22
|
+
.catch((error: unknown) => {
|
|
23
|
+
// Let the next call retry instead of caching the failure
|
|
24
|
+
globalForMongoose.mongooseConnection = undefined;
|
|
25
|
+
throw error;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return globalForMongoose.mongooseConnection;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Gracefully close the MongoDB connection
|
|
33
|
+
*/
|
|
34
|
+
export async function disconnectDB(): Promise<void> {
|
|
35
|
+
await mongoose.connection.close();
|
|
36
|
+
globalForMongoose.mongooseConnection = undefined;
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import mongoose, { type Model, Schema } from "mongoose";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* User document interface
|
|
5
|
+
*/
|
|
6
|
+
export interface IUser {
|
|
7
|
+
email: string;
|
|
8
|
+
name?: string | null;
|
|
9
|
+
password: string;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
updatedAt: Date;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* User schema definition
|
|
16
|
+
*/
|
|
17
|
+
const userSchema = new Schema<IUser>(
|
|
18
|
+
{
|
|
19
|
+
email: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true,
|
|
22
|
+
unique: true,
|
|
23
|
+
lowercase: true,
|
|
24
|
+
trim: true,
|
|
25
|
+
},
|
|
26
|
+
name: {
|
|
27
|
+
type: String,
|
|
28
|
+
trim: true,
|
|
29
|
+
},
|
|
30
|
+
password: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
minlength: 6,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
timestamps: true,
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* User model
|
|
43
|
+
*/
|
|
44
|
+
const User =
|
|
45
|
+
(mongoose.models.User as Model<IUser> | undefined) ??
|
|
46
|
+
mongoose.model<IUser>("User", userSchema);
|
|
47
|
+
|
|
48
|
+
export default User;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* MongoDB connection configuration
|
|
5
|
-
*/
|
|
6
|
-
const connectDB = async (): Promise<void> => {
|
|
7
|
-
try {
|
|
8
|
-
const mongoUri = process.env.MONGODB_URI;
|
|
9
|
-
|
|
10
|
-
if (!mongoUri) {
|
|
11
|
-
throw new Error("MONGODB_URI environment variable is not defined");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
await mongoose.connect(mongoUri);
|
|
15
|
-
|
|
16
|
-
console.log("MongoDB connected successfully");
|
|
17
|
-
|
|
18
|
-
mongoose.connection.on("error", (error) => {
|
|
19
|
-
console.error("MongoDB connection error:", error);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
mongoose.connection.on("disconnected", () => {
|
|
23
|
-
console.log("MongoDB disconnected");
|
|
24
|
-
});
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error("Failed to connect to MongoDB:", error);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Gracefully close MongoDB connection
|
|
33
|
-
*/
|
|
34
|
-
const disconnectDB = async (): Promise<void> => {
|
|
35
|
-
try {
|
|
36
|
-
await mongoose.connection.close();
|
|
37
|
-
console.log("MongoDB connection closed");
|
|
38
|
-
} catch (error) {
|
|
39
|
-
console.error("Error closing MongoDB connection:", error);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export { connectDB, disconnectDB };
|
|
File without changes
|