create-forgeon 0.3.17 → 0.3.18

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": "create-forgeon",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
4
4
  "description": "Forgeon project generator CLI",
5
5
  "license": "MIT",
6
6
  "author": "Forgeon",
@@ -1,4 +1,4 @@
1
- import fs from 'node:fs';
1
+ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { copyRecursive, writeJson } from '../utils/fs.mjs';
4
4
  import {
@@ -156,17 +156,12 @@ function patchHealthController(targetRoot, probeTargets) {
156
156
  const dbMethod = `
157
157
  @Post('db')
158
158
  async getDbProbe() {
159
- const token = \`\${Date.now()}-\${Math.floor(Math.random() * 1_000_000)}\`;
160
- const email = \`health-probe-\${token}@example.local\`;
161
- const user = await this.prisma.user.create({
162
- data: { email },
163
- select: { id: true, email: true, createdAt: true },
164
- });
159
+ const queryResult = await this.prisma.$queryRaw\`SELECT 1 AS ok\`;
165
160
 
166
161
  return {
167
162
  status: 'ok',
168
163
  feature: 'db-prisma',
169
- user,
164
+ queryResult,
170
165
  };
171
166
  }
172
167
  `;
@@ -183,7 +178,7 @@ function registerWebProbe(targetRoot, probeTargets) {
183
178
  definition: {
184
179
  id: 'db',
185
180
  title: 'Database',
186
- buttonLabel: 'Check database (create user)',
181
+ buttonLabel: 'Check database query',
187
182
  resultTitle: 'DB probe response',
188
183
  path: '/health/db',
189
184
  request: { method: 'POST' },
@@ -336,3 +331,4 @@ export function applyDbPrismaModule({ packageRoot, targetRoot }) {
336
331
  'DATABASE_URL=postgresql://postgres:postgres@db:5432/app?schema=public',
337
332
  ]);
338
333
  }
334
+
@@ -727,6 +727,8 @@ function assertAccountsWiring(projectRoot) {
727
727
  );
728
728
  assert.match(healthController, /@Get\('auth'\)/);
729
729
  assert.match(healthController, /authService\.getProbeStatus/);
730
+ assert.match(healthController, /\$queryRaw/);
731
+ assert.doesNotMatch(healthController, /data:\s*\{\s*email\s*\}/);
730
732
  assert.doesNotMatch(healthController, /,\s*,/);
731
733
 
732
734
  assertWebProbeShell(projectRoot);
@@ -2211,6 +2213,10 @@ describe('addModule', () => {
2211
2213
  );
2212
2214
  assert.equal(fs.existsSync(migrationPath), true);
2213
2215
 
2216
+ const seedSource = fs.readFileSync(path.join(projectRoot, 'apps', 'api', 'prisma', 'seed.ts'), 'utf8');
2217
+ assert.match(seedSource, /Prisma\.dmmf/);
2218
+ assert.match(seedSource, /userFields\.has\('email'\)/);
2219
+
2214
2220
  const readme = fs.readFileSync(path.join(projectRoot, 'README.md'), 'utf8');
2215
2221
  assert.match(readme, /POST \/api\/auth\/register/);
2216
2222
  assert.match(readme, /POST \/api\/auth\/password-reset\/request/);
@@ -2634,3 +2640,6 @@ describe('addModule', () => {
2634
2640
 
2635
2641
 
2636
2642
 
2643
+
2644
+
2645
+
@@ -1,20 +1,41 @@
1
- import { PrismaClient } from '@prisma/client';
2
-
3
- const prisma = new PrismaClient();
4
-
5
- async function main() {
6
- await prisma.user.upsert({
7
- where: { email: 'seed@example.com' },
8
- update: {},
9
- create: { email: 'seed@example.com' },
10
- });
11
- }
12
-
13
- main()
14
- .catch((error) => {
15
- console.error(error);
16
- process.exit(1);
17
- })
18
- .finally(async () => {
19
- await prisma.$disconnect();
1
+ import { Prisma, PrismaClient } from '@prisma/client';
2
+
3
+ const prisma = new PrismaClient();
4
+
5
+ function getUserFieldSet() {
6
+ const userModel = Prisma.dmmf.datamodel.models.find((model) => model.name === 'User');
7
+ return new Set((userModel?.fields ?? []).map((field) => field.name));
8
+ }
9
+
10
+ async function main() {
11
+ const userFields = getUserFieldSet();
12
+ const userDelegate = prisma.user as unknown as {
13
+ findFirst(args?: Record<string, unknown>): Promise<{ id: string } | null>;
14
+ upsert(args: Record<string, unknown>): Promise<unknown>;
15
+ create(args: Record<string, unknown>): Promise<unknown>;
16
+ };
17
+
18
+ if (userFields.has('email')) {
19
+ await userDelegate.upsert({
20
+ where: { email: 'seed@example.com' },
21
+ update: {},
22
+ create: { email: 'seed@example.com' },
23
+ });
24
+ return;
25
+ }
26
+
27
+ const existingUser = await userDelegate.findFirst({ select: { id: true } });
28
+ if (!existingUser) {
29
+ const data = userFields.has('status') ? { status: 'active' } : {};
30
+ await userDelegate.create({ data });
31
+ }
32
+ }
33
+
34
+ main()
35
+ .catch((error) => {
36
+ console.error(error);
37
+ process.exit(1);
38
+ })
39
+ .finally(async () => {
40
+ await prisma.$disconnect();
20
41
  });