soma-core 1.1.1 → 1.2.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.
Files changed (38) hide show
  1. package/bin/soma-db.cjs +13 -0
  2. package/core/build/db/cli.ts +10 -0
  3. package/core/build/db/emit-entities.ts +45 -0
  4. package/core/build/db/emit-mappers.ts +175 -0
  5. package/core/build/db/emit-prisma-schema.ts +92 -0
  6. package/core/build/db/generate.ts +166 -0
  7. package/core/build/db/ir.ts +75 -0
  8. package/core/build/db/load-db-yaml.ts +241 -0
  9. package/core/server/index.ts +15 -0
  10. package/core/server/infra/db/errors.ts +11 -0
  11. package/core/server/infra/db/mapper/PrismaSomaMapper.ts +313 -0
  12. package/core/server/infra/db/mapper/SomaBaseMapper.ts +23 -0
  13. package/core/server/infra/db/mapper/SomaMapperHooks.ts +13 -0
  14. package/core/server/infra/db/query/SomaQuery.ts +149 -0
  15. package/core/server/infra/db/service/SomaDbService.ts +64 -0
  16. package/core/server/infra/db/soma-db.ts +56 -6
  17. package/core/server/infra/db/types.ts +21 -0
  18. package/dist/cli/soma.js +5 -1
  19. package/dist/types/build/db/cli.d.ts +2 -0
  20. package/dist/types/build/db/emit-entities.d.ts +5 -0
  21. package/dist/types/build/db/emit-mappers.d.ts +15 -0
  22. package/dist/types/build/db/emit-prisma-schema.d.ts +2 -0
  23. package/dist/types/build/db/generate.d.ts +7 -0
  24. package/dist/types/build/db/ir.d.ts +58 -0
  25. package/dist/types/build/db/load-db-yaml.d.ts +14 -0
  26. package/dist/types/server/index.d.ts +8 -1
  27. package/dist/types/server/infra/db/errors.d.ts +5 -0
  28. package/dist/types/server/infra/db/mapper/PrismaSomaMapper.d.ts +77 -0
  29. package/dist/types/server/infra/db/mapper/SomaBaseMapper.d.ts +20 -0
  30. package/dist/types/server/infra/db/mapper/SomaMapperHooks.d.ts +12 -0
  31. package/dist/types/server/infra/db/query/SomaQuery.d.ts +42 -0
  32. package/dist/types/server/infra/db/service/SomaDbService.d.ts +24 -0
  33. package/dist/types/server/infra/db/soma-db.d.ts +15 -1
  34. package/dist/types/server/infra/db/types.d.ts +18 -0
  35. package/package.json +2 -2
  36. package/docs//345/256/242/346/210/267/347/253/257/346/234/215/345/212/241/347/253/257/351/232/224/347/246/273/346/226/271/346/241/210.md +0 -399
  37. package/docs//351/232/224/347/246/273/346/216/245/345/205/245/345/217/230/346/233/264/346/226/271/346/241/210.md +0 -250
  38. package/docs//351/241/265/351/235/242JSON/346/250/241/345/274/217/346/216/245/345/205/245/346/214/207/345/215/227.md +0 -141
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `soma db` implementation (CJS). Invoked from soma.ts / soma-inline.cjs.
4
+ */
5
+ const path = require('node:path');
6
+ const createJiti = require('jiti');
7
+
8
+ const packageRoot = path.resolve(__dirname, '..');
9
+ const jiti = createJiti(__filename, { interopDefault: true });
10
+ const { runSomaDbCli } = jiti(path.join(packageRoot, 'core/build/db/cli.ts'));
11
+
12
+ const code = runSomaDbCli(process.argv.slice(2), process.cwd());
13
+ process.exit(code);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * CLI entry for `soma db …` (loaded via jiti from bin/soma).
3
+ */
4
+ import { runSomaDbCli } from './generate';
5
+
6
+ export { runSomaDbCli, generateSomaDb } from './generate';
7
+
8
+ export function main(argv = process.argv.slice(2), hostDir = process.cwd()): never {
9
+ process.exit(runSomaDbCli(argv, hostDir));
10
+ }
@@ -0,0 +1,45 @@
1
+ import type { DbFieldIr, DbModelIr, DbSchemaIr } from './ir';
2
+
3
+ function tsType(field: DbFieldIr): string {
4
+ switch (field.type) {
5
+ case 'string':
6
+ case 'text':
7
+ return 'string';
8
+ case 'int':
9
+ case 'float':
10
+ return 'number';
11
+ case 'bigint':
12
+ return 'bigint';
13
+ case 'decimal':
14
+ return 'string';
15
+ case 'boolean':
16
+ return 'boolean';
17
+ case 'datetime':
18
+ return 'Date';
19
+ case 'json':
20
+ return 'unknown';
21
+ default:
22
+ return 'unknown';
23
+ }
24
+ }
25
+
26
+ function emitEntity(model: DbModelIr): string {
27
+ const lines = model.fields.map((field) => {
28
+ const optional = field.optional && !field.id ? '?' : '';
29
+ return ` ${field.name}${optional}: ${tsType(field)};`;
30
+ });
31
+ return [
32
+ '// @generated by soma db generate — do not edit by hand',
33
+ `export interface ${model.name} {`,
34
+ ...lines,
35
+ '}',
36
+ '',
37
+ ].join('\n');
38
+ }
39
+
40
+ export function emitEntities(schema: DbSchemaIr): Array<{ fileName: string; content: string }> {
41
+ return schema.models.map((model) => ({
42
+ fileName: `${model.name}.ts`,
43
+ content: emitEntity(model),
44
+ }));
45
+ }
@@ -0,0 +1,175 @@
1
+ import type { DbModelIr, DbSchemaIr } from './ir';
2
+
3
+ function prismaModelKey(modelName: string): string {
4
+ return modelName.length > 0
5
+ ? modelName[0]!.toLowerCase() + modelName.slice(1)
6
+ : modelName;
7
+ }
8
+
9
+ function mapperConstName(modelName: string): string {
10
+ return `${prismaModelKey(modelName)}Mapper`;
11
+ }
12
+
13
+ function serviceConstName(modelName: string): string {
14
+ return `${prismaModelKey(modelName)}DbService`;
15
+ }
16
+
17
+ function emitMapper(model: DbModelIr): string {
18
+ const className = `${model.name}Mapper`;
19
+ const constName = mapperConstName(model.name);
20
+ const modelKey = prismaModelKey(model.name);
21
+ const optionLines = [
22
+ ` model: '${modelKey}'`,
23
+ ` idField: '${model.idField}'`,
24
+ ];
25
+ if (model.logicDeleteField) {
26
+ optionLines.push(` logicDeleteField: '${model.logicDeleteField}'`);
27
+ }
28
+ if (model.createdAtField) {
29
+ optionLines.push(` createdAtField: '${model.createdAtField}'`);
30
+ }
31
+ if (model.updatedAtField) {
32
+ optionLines.push(` updatedAtField: '${model.updatedAtField}'`);
33
+ }
34
+
35
+ return [
36
+ '// @generated by soma db generate — do not edit by hand',
37
+ "import { PrismaSomaMapper } from 'soma-core/server';",
38
+ `import type { ${model.name} } from '../entity/${model.name}';`,
39
+ '',
40
+ `export class ${className} extends PrismaSomaMapper<${model.name}> {`,
41
+ ' constructor() {',
42
+ ' super({',
43
+ optionLines.join(',\n') + ',',
44
+ ' });',
45
+ ' }',
46
+ '}',
47
+ '',
48
+ `export const ${constName} = new ${className}();`,
49
+ '',
50
+ ].join('\n');
51
+ }
52
+
53
+ function emitService(model: DbModelIr): string {
54
+ const className = `${model.name}DbService`;
55
+ const constName = serviceConstName(model.name);
56
+ const mapperConst = mapperConstName(model.name);
57
+ const mapperClass = `${model.name}Mapper`;
58
+ return [
59
+ '// @generated by soma db generate — do not edit by hand',
60
+ "import { SomaDbService } from 'soma-core/server';",
61
+ `import type { ${model.name} } from '../entity/${model.name}';`,
62
+ `import { ${mapperClass}, ${mapperConst} } from '../mapper/${mapperClass}';`,
63
+ '',
64
+ `export class ${className} extends SomaDbService<${model.name}> {`,
65
+ ' constructor() {',
66
+ ` super(${mapperConst});`,
67
+ ' }',
68
+ '}',
69
+ '',
70
+ `export const ${constName} = new ${className}();`,
71
+ '',
72
+ ].join('\n');
73
+ }
74
+
75
+ export function emitMappers(schema: DbSchemaIr): Array<{ fileName: string; content: string }> {
76
+ return schema.models.map((model) => ({
77
+ fileName: `${model.name}Mapper.ts`,
78
+ content: emitMapper(model),
79
+ }));
80
+ }
81
+
82
+ export function emitServices(schema: DbSchemaIr): Array<{ fileName: string; content: string }> {
83
+ return schema.models.map((model) => ({
84
+ fileName: `${model.name}DbService.ts`,
85
+ content: emitService(model),
86
+ }));
87
+ }
88
+
89
+ export function emitRepositoryIndex(schema: DbSchemaIr): string {
90
+ const entityExports = schema.models
91
+ .map((model) => `export type { ${model.name} } from './entity/${model.name}';`)
92
+ .join('\n');
93
+ const mapperExports = schema.models
94
+ .map((model) => {
95
+ const className = `${model.name}Mapper`;
96
+ const constName = mapperConstName(model.name);
97
+ return `export { ${className}, ${constName} } from './mapper/${className}';`;
98
+ })
99
+ .join('\n');
100
+ const serviceExports = schema.models
101
+ .map((model) => {
102
+ const className = `${model.name}DbService`;
103
+ const constName = serviceConstName(model.name);
104
+ return `export { ${className}, ${constName} } from './service/${className}';`;
105
+ })
106
+ .join('\n');
107
+
108
+ return [
109
+ '// @generated by soma db generate — do not edit by hand',
110
+ entityExports,
111
+ mapperExports,
112
+ serviceExports,
113
+ '',
114
+ ].join('\n');
115
+ }
116
+
117
+ /** CRUD Route Handler under api/service/db/{Model}.ts → /api/db/{model} */
118
+ export function emitApiServices(schema: DbSchemaIr): Array<{ fileName: string; content: string }> {
119
+ return schema.models.map((model) => {
120
+ const serviceConst = serviceConstName(model.name);
121
+ const serviceClass = `${model.name}DbService`;
122
+ return {
123
+ fileName: `${model.name}.ts`,
124
+ content: [
125
+ '// @generated by soma db generate — do not edit by hand',
126
+ '// WARNING: unauthenticated CRUD scaffold for local/test only.',
127
+ "import type { NextRequest } from 'next/server';",
128
+ "import type { IService } from 'soma-core';",
129
+ `import { ${serviceConst} } from '../../../repository/service/${serviceClass}';`,
130
+ "import '../../../lib/db';",
131
+ '',
132
+ `export default class ${model.name}CrudService implements IService {`,
133
+ ' async get(req: NextRequest): Promise<Response> {',
134
+ ' const url = new URL(req.url);',
135
+ " const id = url.searchParams.get('id');",
136
+ ' if (id) {',
137
+ ` const row = await ${serviceConst}.selectById(id);`,
138
+ " if (!row) return Response.json({ message: 'not found' }, { status: 404 });",
139
+ ' return Response.json(row);',
140
+ ' }',
141
+ " const page = Number(url.searchParams.get('page') ?? '1');",
142
+ " const size = Number(url.searchParams.get('size') ?? '20');",
143
+ ` const result = await ${serviceConst}.selectPage({ page, size });`,
144
+ ' return Response.json(result);',
145
+ ' }',
146
+ '',
147
+ ' async post(req: NextRequest): Promise<Response> {',
148
+ ' const body = await req.json();',
149
+ ` const row = await ${serviceConst}.save(body);`,
150
+ ' return Response.json(row, { status: 201 });',
151
+ ' }',
152
+ '',
153
+ ' async put(req: NextRequest): Promise<Response> {',
154
+ ' const body = await req.json();',
155
+ ` const id = body?.${model.idField};`,
156
+ " if (!id) return Response.json({ message: 'id required' }, { status: 400 });",
157
+ ` const { ${model.idField}: _id, ...patch } = body;`,
158
+ ' void _id;',
159
+ ` const row = await ${serviceConst}.updateById(id, patch);`,
160
+ ' return Response.json(row);',
161
+ ' }',
162
+ '',
163
+ ' async delete(req: NextRequest): Promise<Response> {',
164
+ ' const url = new URL(req.url);',
165
+ " const id = url.searchParams.get('id');",
166
+ " if (!id) return Response.json({ message: 'id required' }, { status: 400 });",
167
+ ` const ok = await ${serviceConst}.removeById(id);`,
168
+ ' return Response.json({ ok });',
169
+ ' }',
170
+ '}',
171
+ '',
172
+ ].join('\n'),
173
+ };
174
+ });
175
+ }
@@ -0,0 +1,92 @@
1
+ import type { DbFieldDefault, DbFieldIr, DbModelIr, DbRelationIr, DbSchemaIr } from './ir';
2
+
3
+ function prismaScalar(field: DbFieldIr): string {
4
+ switch (field.type) {
5
+ case 'string':
6
+ return 'String';
7
+ case 'int':
8
+ return 'Int';
9
+ case 'bigint':
10
+ return 'BigInt';
11
+ case 'float':
12
+ return 'Float';
13
+ case 'decimal':
14
+ return 'Decimal';
15
+ case 'boolean':
16
+ return 'Boolean';
17
+ case 'datetime':
18
+ return 'DateTime';
19
+ case 'json':
20
+ return 'Json';
21
+ case 'text':
22
+ return 'String';
23
+ default:
24
+ return 'String';
25
+ }
26
+ }
27
+
28
+ function prismaDefault(value: DbFieldDefault): string | null {
29
+ if (value === 'cuid') return '@default(cuid())';
30
+ if (value === 'uuid') return '@default(uuid())';
31
+ if (value === 'now') return '@default(now())';
32
+ if (value === 'autoincrement') return '@default(autoincrement())';
33
+ if (typeof value === 'string') return `@default("${value.replace(/"/g, '\\"')}")`;
34
+ if (typeof value === 'number' || typeof value === 'boolean') return `@default(${value})`;
35
+ return null;
36
+ }
37
+
38
+ function emitFieldLine(field: DbFieldIr): string {
39
+ const optional = field.optional && !field.id ? '?' : '';
40
+ const attrs: string[] = [];
41
+ if (field.id) attrs.push('@id');
42
+ if (field.unique) attrs.push('@unique');
43
+ if (field.default !== undefined) {
44
+ const def = prismaDefault(field.default);
45
+ if (def) attrs.push(def);
46
+ }
47
+ if (field.type === 'text') attrs.push('@db.Text');
48
+ if (field.type === 'decimal') {
49
+ attrs.push(`@db.Decimal(${field.precision ?? 10}, ${field.scale ?? 2})`);
50
+ }
51
+ const attrText = attrs.length ? ` ${attrs.join(' ')}` : '';
52
+ return ` ${field.name} ${prismaScalar(field)}${optional}${attrText}`;
53
+ }
54
+
55
+ function emitRelationLine(relation: DbRelationIr): string {
56
+ if (relation.kind === 'hasMany') {
57
+ return ` ${relation.name} ${relation.model}[]`;
58
+ }
59
+ const optional = relation.optional ? '?' : '';
60
+ const fields = (relation.fields ?? []).join(', ');
61
+ const references = (relation.references ?? []).join(', ');
62
+ return ` ${relation.name} ${relation.model}${optional} @relation(fields: [${fields}], references: [${references}])`;
63
+ }
64
+
65
+ function emitModel(model: DbModelIr): string {
66
+ const lines = [
67
+ `model ${model.name} {`,
68
+ ...model.fields.map(emitFieldLine),
69
+ ...model.relations.map(emitRelationLine),
70
+ ` @@map("${model.table}")`,
71
+ '}',
72
+ ];
73
+ return lines.join('\n');
74
+ }
75
+
76
+ export function emitPrismaSchema(schema: DbSchemaIr): string {
77
+ const header = [
78
+ '// @generated by soma db generate — do not edit by hand',
79
+ '',
80
+ 'generator client {',
81
+ ' provider = "prisma-client-js"',
82
+ '}',
83
+ '',
84
+ 'datasource db {',
85
+ ' provider = "mysql"',
86
+ ` url = env("${schema.datasourceUrlEnv}")`,
87
+ '}',
88
+ '',
89
+ ].join('\n');
90
+
91
+ return `${header}${schema.models.map(emitModel).join('\n\n')}\n`;
92
+ }
@@ -0,0 +1,166 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { emitEntities } from './emit-entities';
5
+ import {
6
+ emitApiServices,
7
+ emitMappers,
8
+ emitRepositoryIndex,
9
+ emitServices,
10
+ } from './emit-mappers';
11
+ import { emitPrismaSchema } from './emit-prisma-schema';
12
+ import type { DbGenerateOptions, DbSchemaIr } from './ir';
13
+ import { loadDbSchemaIr, resolveDefaultDbYamlPath } from './load-db-yaml';
14
+ import { resolveHostAppConfigPath } from '../../server/host/host-config-paths';
15
+
16
+ function writeFile(filePath: string, content: string): void {
17
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
18
+ fs.writeFileSync(filePath, content, 'utf8');
19
+ }
20
+
21
+ function scaffoldLibDb(hostDir: string): string | null {
22
+ const target = path.join(hostDir, 'lib', 'db.ts');
23
+ if (fs.existsSync(target)) return null;
24
+ const content = [
25
+ "import { PrismaClient } from '@prisma/client';",
26
+ "import { createSomaDbSingleton, registerSomaDbProvider } from 'soma-core/server';",
27
+ '',
28
+ '/** Register Prisma client for repository mappers (server-only). */',
29
+ 'const prisma = createSomaDbSingleton(() => new PrismaClient());',
30
+ 'registerSomaDbProvider({',
31
+ ' getClient: () => prisma,',
32
+ ' disconnect: () => prisma.$disconnect(),',
33
+ '});',
34
+ 'export const db = prisma;',
35
+ '',
36
+ ].join('\n');
37
+ writeFile(target, content);
38
+ return target;
39
+ }
40
+
41
+ export interface DbGenerateResult {
42
+ schema: DbSchemaIr;
43
+ written: string[];
44
+ }
45
+
46
+ export function generateSomaDb(options: DbGenerateOptions): DbGenerateResult {
47
+ const hostDir = path.resolve(options.hostDir);
48
+ const dbYamlPath = options.dbYamlPath ?? resolveDefaultDbYamlPath(hostDir);
49
+ const appConfigPath =
50
+ options.appConfigPath
51
+ ?? resolveHostAppConfigPath(hostDir)
52
+ ?? (fs.existsSync(path.join(hostDir, 'config', 'app.config.yaml'))
53
+ ? path.join(hostDir, 'config', 'app.config.yaml')
54
+ : null);
55
+
56
+ const schema = loadDbSchemaIr({ dbYamlPath, appConfigPath });
57
+ if (options.generateApiService !== undefined) {
58
+ schema.generateApiService = options.generateApiService;
59
+ }
60
+
61
+ const repositoryDir = options.repositoryDir ?? path.join(hostDir, 'repository');
62
+ const prismaSchemaPath =
63
+ options.prismaSchemaPath ?? path.join(hostDir, 'prisma', 'schema.prisma');
64
+
65
+ const written: string[] = [];
66
+
67
+ writeFile(prismaSchemaPath, emitPrismaSchema(schema));
68
+ written.push(prismaSchemaPath);
69
+
70
+ for (const file of emitEntities(schema)) {
71
+ const target = path.join(repositoryDir, 'entity', file.fileName);
72
+ writeFile(target, file.content);
73
+ written.push(target);
74
+ }
75
+
76
+ for (const file of emitMappers(schema)) {
77
+ const target = path.join(repositoryDir, 'mapper', file.fileName);
78
+ writeFile(target, file.content);
79
+ written.push(target);
80
+ }
81
+
82
+ for (const file of emitServices(schema)) {
83
+ const target = path.join(repositoryDir, 'service', file.fileName);
84
+ writeFile(target, file.content);
85
+ written.push(target);
86
+ }
87
+
88
+ const indexPath = path.join(repositoryDir, 'index.ts');
89
+ writeFile(indexPath, emitRepositoryIndex(schema));
90
+ written.push(indexPath);
91
+
92
+ if (schema.generateApiService) {
93
+ for (const file of emitApiServices(schema)) {
94
+ const target = path.join(hostDir, 'api', 'service', 'db', file.fileName);
95
+ writeFile(target, file.content);
96
+ written.push(target);
97
+ }
98
+ }
99
+
100
+ if (options.scaffoldLibDb !== false) {
101
+ const libDb = scaffoldLibDb(hostDir);
102
+ if (libDb) written.push(libDb);
103
+ }
104
+
105
+ return { schema, written };
106
+ }
107
+
108
+ function runPrisma(hostDir: string, prismaArgs: string[]): number {
109
+ const child = spawnSync('npx', ['prisma', ...prismaArgs], {
110
+ cwd: hostDir,
111
+ stdio: 'inherit',
112
+ shell: process.platform === 'win32',
113
+ env: process.env,
114
+ });
115
+ return child.status === null ? 1 : child.status;
116
+ }
117
+
118
+ export function runSomaDbCli(argv: string[], hostDir = process.cwd()): number {
119
+ const [command, ...rest] = argv;
120
+
121
+ if (command === 'generate') {
122
+ const withApi = rest.includes('--with-api');
123
+ try {
124
+ const result = generateSomaDb({
125
+ hostDir,
126
+ generateApiService: withApi ? true : undefined,
127
+ });
128
+ console.log(`[soma db] generated ${result.schema.models.length} model(s):`);
129
+ for (const file of result.written) {
130
+ console.log(` - ${path.relative(hostDir, file)}`);
131
+ }
132
+ console.log('[soma db] next: npm i @prisma/client prisma && npx soma db prisma generate');
133
+ return 0;
134
+ } catch (error) {
135
+ console.error(error instanceof Error ? error.message : String(error));
136
+ return 1;
137
+ }
138
+ }
139
+
140
+ if (command === 'migrate') {
141
+ const nameIdx = rest.indexOf('--name');
142
+ const name = nameIdx >= 0 ? rest[nameIdx + 1] : 'init';
143
+ console.log('[soma db] running prisma migrate dev...');
144
+ return runPrisma(hostDir, ['migrate', 'dev', '--name', name || 'init']);
145
+ }
146
+
147
+ if (command === 'prisma') {
148
+ if (rest.length === 0) {
149
+ console.error('Usage: soma db prisma <prisma-args...>');
150
+ return 1;
151
+ }
152
+ return runPrisma(hostDir, rest);
153
+ }
154
+
155
+ if (command === 'pull') {
156
+ console.log('[soma db] running prisma db pull (introspection)...');
157
+ return runPrisma(hostDir, ['db', 'pull']);
158
+ }
159
+
160
+ console.error('Usage: soma db <generate|migrate|pull|prisma> [...args]');
161
+ console.error(' soma db generate [--with-api]');
162
+ console.error(' soma db migrate [--name <migration>]');
163
+ console.error(' soma db pull');
164
+ console.error(' soma db prisma generate|migrate|...');
165
+ return 1;
166
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Schema IR for Host config/db.yaml → Prisma + repository codegen.
3
+ * MySQL only.
4
+ */
5
+
6
+ export type DbFieldType =
7
+ | 'string'
8
+ | 'int'
9
+ | 'bigint'
10
+ | 'float'
11
+ | 'decimal'
12
+ | 'boolean'
13
+ | 'datetime'
14
+ | 'json'
15
+ | 'text';
16
+
17
+ export type DbFieldDefault = 'cuid' | 'uuid' | 'now' | 'autoincrement' | string | number | boolean;
18
+
19
+ export interface DbFieldIr {
20
+ name: string;
21
+ type: DbFieldType;
22
+ id?: boolean;
23
+ optional?: boolean;
24
+ unique?: boolean;
25
+ default?: DbFieldDefault;
26
+ precision?: number;
27
+ scale?: number;
28
+ /** Soft-delete column (TableLogic) */
29
+ logicDelete?: boolean;
30
+ /** Auto-fill on insert */
31
+ fillOnInsert?: boolean;
32
+ /** Auto-fill on update (and insert if also fillOnInsert or createdAt pattern) */
33
+ fillOnUpdate?: boolean;
34
+ }
35
+
36
+ export type DbRelationKind = 'hasMany' | 'belongsTo';
37
+
38
+ export interface DbRelationIr {
39
+ name: string;
40
+ kind: DbRelationKind;
41
+ model: string;
42
+ fields?: string[];
43
+ references?: string[];
44
+ optional?: boolean;
45
+ }
46
+
47
+ export interface DbModelIr {
48
+ name: string;
49
+ table: string;
50
+ idField: string;
51
+ fields: DbFieldIr[];
52
+ relations: DbRelationIr[];
53
+ logicDeleteField?: string;
54
+ createdAtField?: string;
55
+ updatedAtField?: string;
56
+ }
57
+
58
+ export interface DbSchemaIr {
59
+ provider: 'mysql';
60
+ datasourceUrlEnv: string;
61
+ models: DbModelIr[];
62
+ /** When true, also emit api/service/db/* CRUD scaffolds */
63
+ generateApiService: boolean;
64
+ }
65
+
66
+ export interface DbGenerateOptions {
67
+ hostDir: string;
68
+ dbYamlPath?: string;
69
+ appConfigPath?: string;
70
+ repositoryDir?: string;
71
+ prismaSchemaPath?: string;
72
+ scaffoldLibDb?: boolean;
73
+ /** Override yaml generateApiService */
74
+ generateApiService?: boolean;
75
+ }