@lssm/lib.schema 0.0.0-canary-20251221193616 → 0.0.0-canary-20251223010757
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/dist/EnumType.d.ts +32 -29
- package/dist/EnumType.d.ts.map +1 -1
- package/dist/EnumType.js +57 -0
- package/dist/EnumType.js.map +1 -0
- package/dist/FieldType.d.ts +23 -19
- package/dist/FieldType.d.ts.map +1 -1
- package/dist/FieldType.js +50 -0
- package/dist/FieldType.js.map +1 -0
- package/dist/ScalarTypeEnum.d.ts +28 -23
- package/dist/ScalarTypeEnum.d.ts.map +1 -1
- package/dist/ScalarTypeEnum.js +237 -0
- package/dist/ScalarTypeEnum.js.map +1 -0
- package/dist/SchemaModel.d.ts +34 -33
- package/dist/SchemaModel.d.ts.map +1 -1
- package/dist/SchemaModel.js +40 -0
- package/dist/SchemaModel.js.map +1 -0
- package/dist/entity/defineEntity.d.ts +60 -55
- package/dist/entity/defineEntity.d.ts.map +1 -1
- package/dist/entity/defineEntity.js +237 -0
- package/dist/entity/defineEntity.js.map +1 -0
- package/dist/entity/generator.d.ts +21 -16
- package/dist/entity/generator.d.ts.map +1 -1
- package/dist/entity/generator.js +218 -0
- package/dist/entity/generator.js.map +1 -0
- package/dist/entity/index.d.ts +4 -4
- package/dist/entity/index.js +5 -0
- package/dist/entity/types.d.ts +104 -99
- package/dist/entity/types.d.ts.map +1 -1
- package/dist/entity/types.js +1 -0
- package/dist/index.d.ts +9 -6
- package/dist/index.js +9 -66
- package/package.json +15 -6
- package/dist/entity/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EntityEnumDef, EntitySpec, ModuleSchemaContribution } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/entity/generator.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Options for Prisma schema generation.
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
interface PrismaGeneratorOptions {
|
|
9
|
+
/** Output file path for the generated schema */
|
|
10
|
+
outputPath?: string;
|
|
11
|
+
/** Prisma datasource provider (default: 'postgresql') */
|
|
12
|
+
provider?: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb' | 'sqlserver';
|
|
13
|
+
/** Prisma generator output path */
|
|
14
|
+
clientOutput?: string;
|
|
15
|
+
/** Include Pothos generator */
|
|
16
|
+
includePothos?: boolean;
|
|
17
|
+
/** Pothos output path */
|
|
18
|
+
pothosOutput?: string;
|
|
16
19
|
}
|
|
17
20
|
/**
|
|
18
21
|
* Generate Prisma schema content from entity specifications.
|
|
19
22
|
*/
|
|
20
|
-
|
|
23
|
+
declare function generatePrismaSchema(entities: EntitySpec[], options?: PrismaGeneratorOptions): string;
|
|
21
24
|
/**
|
|
22
25
|
* Compose multiple module schema contributions into a single schema.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
declare function composeModuleSchemas(contributions: ModuleSchemaContribution[], options?: PrismaGeneratorOptions): string;
|
|
25
28
|
/**
|
|
26
29
|
* Generate a single entity's Prisma schema fragment (for modular output).
|
|
27
30
|
*/
|
|
28
|
-
|
|
31
|
+
declare function generateEntityFragment(entity: EntitySpec): string;
|
|
29
32
|
/**
|
|
30
33
|
* Generate a single enum's Prisma schema fragment (for modular output).
|
|
31
34
|
*/
|
|
32
|
-
|
|
35
|
+
declare function generateEnumFragment(enumDef: EntityEnumDef): string;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { PrismaGeneratorOptions, composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema };
|
|
33
38
|
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","
|
|
1
|
+
{"version":3,"file":"generator.d.ts","names":[],"sources":["../../src/entity/generator.ts"],"sourcesContent":[],"mappings":";;;;;;AAcA;AAgBgB,UAhBC,sBAAA,CAiBL;EA2WI;EAuCA,UAAA,CAAA,EAAA,MAAA;EAOA;;;;;;;;;;;;iBA1ZA,oBAAA,WACJ,wBACD;;;;iBA0WK,oBAAA,gBACC,sCACN;;;;iBAqCK,sBAAA,SAA+B;;;;iBAO/B,oBAAA,UAA8B"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
//#region src/entity/generator.ts
|
|
2
|
+
/**
|
|
3
|
+
* Generate Prisma schema content from entity specifications.
|
|
4
|
+
*/
|
|
5
|
+
function generatePrismaSchema(entities, options = {}) {
|
|
6
|
+
const { provider = "postgresql", clientOutput = "../../src/generated/prisma", includePothos = true, pothosOutput = "../../src/generated/pothos-types.ts" } = options;
|
|
7
|
+
const lines = [];
|
|
8
|
+
const schemas = /* @__PURE__ */ new Set();
|
|
9
|
+
entities.forEach((entity) => {
|
|
10
|
+
if (entity.schema) schemas.add(entity.schema);
|
|
11
|
+
});
|
|
12
|
+
const schemaList = schemas.size > 0 ? Array.from(schemas) : ["public"];
|
|
13
|
+
lines.push("datasource db {");
|
|
14
|
+
lines.push(` provider = "${provider}"`);
|
|
15
|
+
if (schemas.size > 0) lines.push(` schemas = [${schemaList.map((s) => `"${s}"`).join(", ")}]`);
|
|
16
|
+
lines.push("}");
|
|
17
|
+
lines.push("");
|
|
18
|
+
lines.push("generator client {");
|
|
19
|
+
lines.push(" provider = \"prisma-client\"");
|
|
20
|
+
lines.push(` output = "${clientOutput}"`);
|
|
21
|
+
lines.push("");
|
|
22
|
+
lines.push(" engineType = \"client\"");
|
|
23
|
+
lines.push(" runtime = \"bun\"");
|
|
24
|
+
lines.push(" moduleFormat = \"esm\"");
|
|
25
|
+
lines.push(" generatedFileExtension = \"ts\"");
|
|
26
|
+
lines.push(" importFileExtension = \"ts\"");
|
|
27
|
+
lines.push("}");
|
|
28
|
+
lines.push("");
|
|
29
|
+
if (includePothos) {
|
|
30
|
+
lines.push("generator pothos {");
|
|
31
|
+
lines.push(" provider = \"prisma-pothos-types\"");
|
|
32
|
+
lines.push(" clientOutput = \"./prisma\"");
|
|
33
|
+
lines.push(` output = "${pothosOutput}"`);
|
|
34
|
+
lines.push(" generateDatamodel = true");
|
|
35
|
+
lines.push(" documentation = false");
|
|
36
|
+
lines.push("}");
|
|
37
|
+
lines.push("");
|
|
38
|
+
}
|
|
39
|
+
const enumMap = /* @__PURE__ */ new Map();
|
|
40
|
+
entities.forEach((entity) => {
|
|
41
|
+
entity.enums?.forEach((enumDef) => {
|
|
42
|
+
if (!enumMap.has(enumDef.name)) enumMap.set(enumDef.name, enumDef);
|
|
43
|
+
});
|
|
44
|
+
Object.values(entity.fields).forEach((field) => {
|
|
45
|
+
if (field.kind === "enum" && field.values && !enumMap.has(field.enumName)) enumMap.set(field.enumName, {
|
|
46
|
+
name: field.enumName,
|
|
47
|
+
values: field.values,
|
|
48
|
+
schema: entity.schema
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
enumMap.forEach((enumDef) => {
|
|
53
|
+
lines.push(...generateEnumBlock(enumDef));
|
|
54
|
+
lines.push("");
|
|
55
|
+
});
|
|
56
|
+
entities.forEach((entity) => {
|
|
57
|
+
lines.push(...generateModelBlock(entity));
|
|
58
|
+
lines.push("");
|
|
59
|
+
});
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate Prisma enum block.
|
|
64
|
+
*/
|
|
65
|
+
function generateEnumBlock(enumDef) {
|
|
66
|
+
const lines = [];
|
|
67
|
+
if (enumDef.description) lines.push(`/// ${enumDef.description}`);
|
|
68
|
+
lines.push(`enum ${enumDef.name} {`);
|
|
69
|
+
enumDef.values.forEach((value) => {
|
|
70
|
+
lines.push(` ${value}`);
|
|
71
|
+
});
|
|
72
|
+
lines.push("");
|
|
73
|
+
if (enumDef.schema) lines.push(` @@schema("${enumDef.schema}")`);
|
|
74
|
+
lines.push("}");
|
|
75
|
+
return lines;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate Prisma model block from entity spec.
|
|
79
|
+
*/
|
|
80
|
+
function generateModelBlock(entity) {
|
|
81
|
+
const lines = [];
|
|
82
|
+
if (entity.description) lines.push(`/// ${entity.description}`);
|
|
83
|
+
lines.push(`model ${entity.name} {`);
|
|
84
|
+
Object.entries(entity.fields).forEach(([fieldName, field]) => {
|
|
85
|
+
const fieldLine = generateFieldLine(fieldName, field);
|
|
86
|
+
if (field.description) lines.push(` /// ${field.description}`);
|
|
87
|
+
lines.push(` ${fieldLine}`);
|
|
88
|
+
});
|
|
89
|
+
if (entity.indexes && entity.indexes.length > 0) {
|
|
90
|
+
lines.push("");
|
|
91
|
+
entity.indexes.forEach((idx) => {
|
|
92
|
+
lines.push(` ${generateIndexLine(idx)}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (entity.map) lines.push(` @@map("${entity.map}")`);
|
|
96
|
+
if (entity.schema) lines.push(` @@schema("${entity.schema}")`);
|
|
97
|
+
lines.push("}");
|
|
98
|
+
return lines;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a single field line.
|
|
102
|
+
*/
|
|
103
|
+
function generateFieldLine(fieldName, field) {
|
|
104
|
+
if (field.kind === "scalar") return generateScalarFieldLine(fieldName, field);
|
|
105
|
+
else if (field.kind === "enum") return generateEnumFieldLine(fieldName, field);
|
|
106
|
+
else if (field.kind === "relation") return generateRelationFieldLine(fieldName, field);
|
|
107
|
+
throw new Error(`Unknown field kind: ${field.kind}`);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generate scalar field line.
|
|
111
|
+
*/
|
|
112
|
+
function generateScalarFieldLine(fieldName, field) {
|
|
113
|
+
const parts = [fieldName];
|
|
114
|
+
let typeStr = field.type;
|
|
115
|
+
if (field.isArray) typeStr += "[]";
|
|
116
|
+
if (field.isOptional) typeStr += "?";
|
|
117
|
+
parts.push(typeStr);
|
|
118
|
+
const attrs = [];
|
|
119
|
+
if (field.isId) attrs.push("@id");
|
|
120
|
+
if (field.default !== void 0) if (typeof field.default === "string" && field.default.includes("(")) attrs.push(`@default(${field.default})`);
|
|
121
|
+
else if (typeof field.default === "boolean") attrs.push(`@default(${field.default})`);
|
|
122
|
+
else if (typeof field.default === "number") attrs.push(`@default(${field.default})`);
|
|
123
|
+
else attrs.push(`@default("${field.default}")`);
|
|
124
|
+
if (field.updatedAt) attrs.push("@updatedAt");
|
|
125
|
+
if (field.isUnique) attrs.push("@unique");
|
|
126
|
+
if (field.map) attrs.push(`@map("${field.map}")`);
|
|
127
|
+
if (field.dbType) attrs.push(`@db.${field.dbType}`);
|
|
128
|
+
if (attrs.length > 0) parts.push(attrs.join(" "));
|
|
129
|
+
return parts.join(" ");
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Generate enum field line.
|
|
133
|
+
*/
|
|
134
|
+
function generateEnumFieldLine(fieldName, field) {
|
|
135
|
+
const parts = [fieldName];
|
|
136
|
+
let typeStr = field.enumName;
|
|
137
|
+
if (field.isArray) typeStr += "[]";
|
|
138
|
+
if (field.isOptional) typeStr += "?";
|
|
139
|
+
parts.push(typeStr);
|
|
140
|
+
const attrs = [];
|
|
141
|
+
if (field.default !== void 0) attrs.push(`@default(${field.default})`);
|
|
142
|
+
if (field.isUnique) attrs.push("@unique");
|
|
143
|
+
if (field.map) attrs.push(`@map("${field.map}")`);
|
|
144
|
+
if (attrs.length > 0) parts.push(attrs.join(" "));
|
|
145
|
+
return parts.join(" ");
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Generate relation field line.
|
|
149
|
+
*/
|
|
150
|
+
function generateRelationFieldLine(fieldName, field) {
|
|
151
|
+
const parts = [fieldName];
|
|
152
|
+
let typeStr = field.target;
|
|
153
|
+
if (field.type === "hasMany") typeStr += "[]";
|
|
154
|
+
if (field.type === "hasOne") typeStr += "?";
|
|
155
|
+
parts.push(typeStr);
|
|
156
|
+
const relationParts = [];
|
|
157
|
+
if (field.name) relationParts.push(`name: "${field.name}"`);
|
|
158
|
+
if (field.fields && field.fields.length > 0) relationParts.push(`fields: [${field.fields.join(", ")}]`);
|
|
159
|
+
if (field.references && field.references.length > 0) relationParts.push(`references: [${field.references.join(", ")}]`);
|
|
160
|
+
if (field.onDelete) relationParts.push(`onDelete: ${field.onDelete}`);
|
|
161
|
+
if (field.onUpdate) relationParts.push(`onUpdate: ${field.onUpdate}`);
|
|
162
|
+
if (relationParts.length > 0) parts.push(`@relation(${relationParts.join(", ")})`);
|
|
163
|
+
return parts.join(" ");
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Generate index line.
|
|
167
|
+
*/
|
|
168
|
+
function generateIndexLine(idx) {
|
|
169
|
+
const fieldList = idx.fields.join(", ");
|
|
170
|
+
const parts = [];
|
|
171
|
+
if (idx.unique) parts.push(`@@unique([${fieldList}]`);
|
|
172
|
+
else parts.push(`@@index([${fieldList}]`);
|
|
173
|
+
const options = [];
|
|
174
|
+
if (idx.name) options.push(`name: "${idx.name}"`);
|
|
175
|
+
if (idx.type) options.push(`type: ${idx.type}`);
|
|
176
|
+
if (options.length > 0) parts[0] += `, ${options.join(", ")}`;
|
|
177
|
+
parts[0] += ")";
|
|
178
|
+
return parts.join("");
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Compose multiple module schema contributions into a single schema.
|
|
182
|
+
*/
|
|
183
|
+
function composeModuleSchemas(contributions, options = {}) {
|
|
184
|
+
const allEntities = [];
|
|
185
|
+
const allEnums = /* @__PURE__ */ new Map();
|
|
186
|
+
contributions.forEach((contrib) => {
|
|
187
|
+
contrib.entities.forEach((entity) => {
|
|
188
|
+
allEntities.push({
|
|
189
|
+
...entity,
|
|
190
|
+
module: contrib.moduleId
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
contrib.enums?.forEach((enumDef) => {
|
|
194
|
+
if (!allEnums.has(enumDef.name)) allEnums.set(enumDef.name, enumDef);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
if (allEntities[0] && allEnums.size > 0) allEntities[0] = {
|
|
198
|
+
...allEntities[0],
|
|
199
|
+
enums: [...allEntities[0].enums ?? [], ...allEnums.values()]
|
|
200
|
+
};
|
|
201
|
+
return generatePrismaSchema(allEntities, options);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Generate a single entity's Prisma schema fragment (for modular output).
|
|
205
|
+
*/
|
|
206
|
+
function generateEntityFragment(entity) {
|
|
207
|
+
return generateModelBlock(entity).join("\n");
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generate a single enum's Prisma schema fragment (for modular output).
|
|
211
|
+
*/
|
|
212
|
+
function generateEnumFragment(enumDef) {
|
|
213
|
+
return generateEnumBlock(enumDef).join("\n");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
export { composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema };
|
|
218
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","names":["lines: string[]","parts: string[]","attrs: string[]","relationParts: string[]","options: string[]","allEntities: EntitySpec[]"],"sources":["../../src/entity/generator.ts"],"sourcesContent":["import type {\n EntityEnumDef,\n EntityEnumField,\n EntityField,\n EntityIndex,\n EntityRelationField,\n EntityScalarField,\n EntitySpec,\n ModuleSchemaContribution,\n} from './types';\n\n/**\n * Options for Prisma schema generation.\n */\nexport interface PrismaGeneratorOptions {\n /** Output file path for the generated schema */\n outputPath?: string;\n /** Prisma datasource provider (default: 'postgresql') */\n provider?: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb' | 'sqlserver';\n /** Prisma generator output path */\n clientOutput?: string;\n /** Include Pothos generator */\n includePothos?: boolean;\n /** Pothos output path */\n pothosOutput?: string;\n}\n\n/**\n * Generate Prisma schema content from entity specifications.\n */\nexport function generatePrismaSchema(\n entities: EntitySpec[],\n options: PrismaGeneratorOptions = {}\n): string {\n const {\n provider = 'postgresql',\n clientOutput = '../../src/generated/prisma',\n includePothos = true,\n pothosOutput = '../../src/generated/pothos-types.ts',\n } = options;\n\n const lines: string[] = [];\n\n // Collect all schemas used\n const schemas = new Set<string>();\n entities.forEach((entity) => {\n if (entity.schema) {\n schemas.add(entity.schema);\n }\n });\n const schemaList = schemas.size > 0 ? Array.from(schemas) : ['public'];\n\n // Datasource block\n lines.push('datasource db {');\n lines.push(` provider = \"${provider}\"`);\n if (schemas.size > 0) {\n lines.push(` schemas = [${schemaList.map((s) => `\"${s}\"`).join(', ')}]`);\n }\n lines.push('}');\n lines.push('');\n\n // Generator block\n lines.push('generator client {');\n lines.push(' provider = \"prisma-client\"');\n lines.push(` output = \"${clientOutput}\"`);\n lines.push('');\n lines.push(' engineType = \"client\"');\n lines.push(' runtime = \"bun\"');\n lines.push(' moduleFormat = \"esm\"');\n lines.push(' generatedFileExtension = \"ts\"');\n lines.push(' importFileExtension = \"ts\"');\n lines.push('}');\n lines.push('');\n\n // Pothos generator (optional)\n if (includePothos) {\n lines.push('generator pothos {');\n lines.push(' provider = \"prisma-pothos-types\"');\n lines.push(' clientOutput = \"./prisma\"');\n lines.push(` output = \"${pothosOutput}\"`);\n lines.push(' generateDatamodel = true');\n lines.push(' documentation = false');\n lines.push('}');\n lines.push('');\n }\n\n // Collect all enums across entities\n const enumMap = new Map<string, EntityEnumDef>();\n entities.forEach((entity) => {\n entity.enums?.forEach((enumDef) => {\n if (!enumMap.has(enumDef.name)) {\n enumMap.set(enumDef.name, enumDef);\n }\n });\n // Also collect inline enums from fields\n Object.values(entity.fields).forEach((field) => {\n if (\n field.kind === 'enum' &&\n field.values &&\n !enumMap.has(field.enumName)\n ) {\n enumMap.set(field.enumName, {\n name: field.enumName,\n values: field.values,\n schema: entity.schema,\n });\n }\n });\n });\n\n // Generate enums\n enumMap.forEach((enumDef) => {\n lines.push(...generateEnumBlock(enumDef));\n lines.push('');\n });\n\n // Generate models\n entities.forEach((entity) => {\n lines.push(...generateModelBlock(entity));\n lines.push('');\n });\n\n return lines.join('\\n');\n}\n\n/**\n * Generate Prisma enum block.\n */\nfunction generateEnumBlock(enumDef: EntityEnumDef): string[] {\n const lines: string[] = [];\n\n if (enumDef.description) {\n lines.push(`/// ${enumDef.description}`);\n }\n\n lines.push(`enum ${enumDef.name} {`);\n enumDef.values.forEach((value) => {\n lines.push(` ${value}`);\n });\n lines.push('');\n if (enumDef.schema) {\n lines.push(` @@schema(\"${enumDef.schema}\")`);\n }\n lines.push('}');\n\n return lines;\n}\n\n/**\n * Generate Prisma model block from entity spec.\n */\nfunction generateModelBlock(entity: EntitySpec): string[] {\n const lines: string[] = [];\n\n // Model description\n if (entity.description) {\n lines.push(`/// ${entity.description}`);\n }\n\n lines.push(`model ${entity.name} {`);\n\n // Generate fields\n Object.entries(entity.fields).forEach(([fieldName, field]) => {\n const fieldLine = generateFieldLine(fieldName, field);\n if (field.description) {\n lines.push(` /// ${field.description}`);\n }\n lines.push(` ${fieldLine}`);\n });\n\n // Generate indexes\n if (entity.indexes && entity.indexes.length > 0) {\n lines.push('');\n entity.indexes.forEach((idx) => {\n lines.push(` ${generateIndexLine(idx)}`);\n });\n }\n\n // Table mapping\n if (entity.map) {\n lines.push(` @@map(\"${entity.map}\")`);\n }\n\n // Schema\n if (entity.schema) {\n lines.push(` @@schema(\"${entity.schema}\")`);\n }\n\n lines.push('}');\n\n return lines;\n}\n\n/**\n * Generate a single field line.\n */\nfunction generateFieldLine(fieldName: string, field: EntityField): string {\n if (field.kind === 'scalar') {\n return generateScalarFieldLine(fieldName, field);\n } else if (field.kind === 'enum') {\n return generateEnumFieldLine(fieldName, field);\n } else if (field.kind === 'relation') {\n return generateRelationFieldLine(fieldName, field);\n }\n throw new Error(`Unknown field kind: ${(field as EntityField).kind}`);\n}\n\n/**\n * Generate scalar field line.\n */\nfunction generateScalarFieldLine(\n fieldName: string,\n field: EntityScalarField\n): string {\n const parts: string[] = [fieldName];\n\n // Type with optional/array modifiers\n let typeStr = field.type;\n if (field.isArray) {\n typeStr += '[]';\n }\n if (field.isOptional) {\n typeStr += '?';\n }\n parts.push(typeStr);\n\n // Attributes\n const attrs: string[] = [];\n\n if (field.isId) {\n attrs.push('@id');\n }\n\n if (field.default !== undefined) {\n if (typeof field.default === 'string' && field.default.includes('(')) {\n // Function default like cuid(), now(), autoincrement()\n attrs.push(`@default(${field.default})`);\n } else if (typeof field.default === 'boolean') {\n attrs.push(`@default(${field.default})`);\n } else if (typeof field.default === 'number') {\n attrs.push(`@default(${field.default})`);\n } else {\n attrs.push(`@default(\"${field.default}\")`);\n }\n }\n\n if (field.updatedAt) {\n attrs.push('@updatedAt');\n }\n\n if (field.isUnique) {\n attrs.push('@unique');\n }\n\n if (field.map) {\n attrs.push(`@map(\"${field.map}\")`);\n }\n\n if (field.dbType) {\n attrs.push(`@db.${field.dbType}`);\n }\n\n if (attrs.length > 0) {\n parts.push(attrs.join(' '));\n }\n\n return parts.join(' ');\n}\n\n/**\n * Generate enum field line.\n */\nfunction generateEnumFieldLine(\n fieldName: string,\n field: EntityEnumField\n): string {\n const parts: string[] = [fieldName];\n\n // Type with optional/array modifiers\n let typeStr = field.enumName;\n if (field.isArray) {\n typeStr += '[]';\n }\n if (field.isOptional) {\n typeStr += '?';\n }\n parts.push(typeStr);\n\n // Attributes\n const attrs: string[] = [];\n\n if (field.default !== undefined) {\n attrs.push(`@default(${field.default})`);\n }\n\n if (field.isUnique) {\n attrs.push('@unique');\n }\n\n if (field.map) {\n attrs.push(`@map(\"${field.map}\")`);\n }\n\n if (attrs.length > 0) {\n parts.push(attrs.join(' '));\n }\n\n return parts.join(' ');\n}\n\n/**\n * Generate relation field line.\n */\nfunction generateRelationFieldLine(\n fieldName: string,\n field: EntityRelationField\n): string {\n const parts: string[] = [fieldName];\n\n // Type with array modifier for hasMany\n let typeStr = field.target;\n if (field.type === 'hasMany') {\n typeStr += '[]';\n }\n if (field.type === 'hasOne') {\n typeStr += '?';\n }\n parts.push(typeStr);\n\n // @relation attribute\n const relationParts: string[] = [];\n\n if (field.name) {\n relationParts.push(`name: \"${field.name}\"`);\n }\n\n if (field.fields && field.fields.length > 0) {\n relationParts.push(`fields: [${field.fields.join(', ')}]`);\n }\n\n if (field.references && field.references.length > 0) {\n relationParts.push(`references: [${field.references.join(', ')}]`);\n }\n\n if (field.onDelete) {\n relationParts.push(`onDelete: ${field.onDelete}`);\n }\n\n if (field.onUpdate) {\n relationParts.push(`onUpdate: ${field.onUpdate}`);\n }\n\n if (relationParts.length > 0) {\n parts.push(`@relation(${relationParts.join(', ')})`);\n }\n\n return parts.join(' ');\n}\n\n/**\n * Generate index line.\n */\nfunction generateIndexLine(idx: EntityIndex): string {\n const fieldList = idx.fields.join(', ');\n const parts: string[] = [];\n\n if (idx.unique) {\n parts.push(`@@unique([${fieldList}]`);\n } else {\n parts.push(`@@index([${fieldList}]`);\n }\n\n const options: string[] = [];\n\n if (idx.name) {\n options.push(`name: \"${idx.name}\"`);\n }\n\n if (idx.type) {\n options.push(`type: ${idx.type}`);\n }\n\n if (options.length > 0) {\n parts[0] += `, ${options.join(', ')}`;\n }\n\n parts[0] += ')';\n\n return parts.join('');\n}\n\n/**\n * Compose multiple module schema contributions into a single schema.\n */\nexport function composeModuleSchemas(\n contributions: ModuleSchemaContribution[],\n options: PrismaGeneratorOptions = {}\n): string {\n // Merge all entities\n const allEntities: EntitySpec[] = [];\n const allEnums = new Map<string, EntityEnumDef>();\n\n contributions.forEach((contrib) => {\n // Add entities\n contrib.entities.forEach((entity) => {\n allEntities.push({\n ...entity,\n module: contrib.moduleId,\n });\n });\n\n // Merge enums\n contrib.enums?.forEach((enumDef) => {\n if (!allEnums.has(enumDef.name)) {\n allEnums.set(enumDef.name, enumDef);\n }\n });\n });\n\n // Add collected enums to first entity or create a holder\n if (allEntities[0] && allEnums.size > 0) {\n allEntities[0] = {\n ...allEntities[0],\n enums: [...(allEntities[0].enums ?? []), ...allEnums.values()],\n };\n }\n\n return generatePrismaSchema(allEntities, options);\n}\n\n/**\n * Generate a single entity's Prisma schema fragment (for modular output).\n */\nexport function generateEntityFragment(entity: EntitySpec): string {\n return generateModelBlock(entity).join('\\n');\n}\n\n/**\n * Generate a single enum's Prisma schema fragment (for modular output).\n */\nexport function generateEnumFragment(enumDef: EntityEnumDef): string {\n return generateEnumBlock(enumDef).join('\\n');\n}\n"],"mappings":";;;;AA8BA,SAAgB,qBACd,UACA,UAAkC,EAAE,EAC5B;CACR,MAAM,EACJ,WAAW,cACX,eAAe,8BACf,gBAAgB,MAChB,eAAe,0CACb;CAEJ,MAAMA,QAAkB,EAAE;CAG1B,MAAM,0BAAU,IAAI,KAAa;AACjC,UAAS,SAAS,WAAW;AAC3B,MAAI,OAAO,OACT,SAAQ,IAAI,OAAO,OAAO;GAE5B;CACF,MAAM,aAAa,QAAQ,OAAO,IAAI,MAAM,KAAK,QAAQ,GAAG,CAAC,SAAS;AAGtE,OAAM,KAAK,kBAAkB;AAC7B,OAAM,KAAK,iBAAiB,SAAS,GAAG;AACxC,KAAI,QAAQ,OAAO,EACjB,OAAM,KAAK,iBAAiB,WAAW,KAAK,MAAM,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG;AAE5E,OAAM,KAAK,IAAI;AACf,OAAM,KAAK,GAAG;AAGd,OAAM,KAAK,qBAAqB;AAChC,OAAM,KAAK,iCAA+B;AAC1C,OAAM,KAAK,iBAAiB,aAAa,GAAG;AAC5C,OAAM,KAAK,GAAG;AACd,OAAM,KAAK,wCAAsC;AACjD,OAAM,KAAK,qCAAmC;AAC9C,OAAM,KAAK,qCAAmC;AAC9C,OAAM,KAAK,oCAAkC;AAC7C,OAAM,KAAK,oCAAkC;AAC7C,OAAM,KAAK,IAAI;AACf,OAAM,KAAK,GAAG;AAGd,KAAI,eAAe;AACjB,QAAM,KAAK,qBAAqB;AAChC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ErC;GACF;AAGF,KAAI,YAAY,MAAM,SAAS,OAAO,EACpC,aAAY,KAAK;EACf,GAAG,YAAY;EACf,OAAO,CAAC,GAAI,YAAY,GAAG,SAAS,EAAE,EAAG,GAAG,SAAS,QAAQ,CAAC;EAC/D;AAGH,QAAO,qBAAqB,aAAa,QAAQ;;;;;AAMnD,SAAgB,uBAAuB,QAA4B;AACjE,QAAO,mBAAmB,OAAO,CAAC,KAAK,KAAK;;;;;AAM9C,SAAgB,qBAAqB,SAAgC;AACnE,QAAO,kBAAkB,QAAQ,CAAC,KAAK,KAAK"}
|
package/dist/entity/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, ModuleSchemaContribution, PrismaFieldModifiers, PrismaScalarType, RelationType } from "./types.js";
|
|
2
|
+
import { defineEntity, defineEntityEnum, field, index } from "./defineEntity.js";
|
|
3
|
+
import { PrismaGeneratorOptions, composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema } from "./generator.js";
|
|
4
|
+
export { EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, ModuleSchemaContribution, PrismaFieldModifiers, PrismaGeneratorOptions, PrismaScalarType, RelationType, composeModuleSchemas, defineEntity, defineEntityEnum, field, generateEntityFragment, generateEnumFragment, generatePrismaSchema, index };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./types.js";
|
|
2
|
+
import { defineEntity, defineEntityEnum, field, index } from "./defineEntity.js";
|
|
3
|
+
import { composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema } from "./generator.js";
|
|
4
|
+
|
|
5
|
+
export { composeModuleSchemas, defineEntity, defineEntityEnum, field, generateEntityFragment, generateEnumFragment, generatePrismaSchema, index };
|
package/dist/entity/types.d.ts
CHANGED
|
@@ -1,141 +1,146 @@
|
|
|
1
|
-
import * as z from
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/entity/types.d.ts
|
|
4
|
+
|
|
2
5
|
/**
|
|
3
6
|
* Prisma scalar types that can be used in entity field definitions.
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
type PrismaScalarType = 'String' | 'Int' | 'Float' | 'Boolean' | 'DateTime' | 'Json' | 'BigInt' | 'Decimal' | 'Bytes';
|
|
6
9
|
/**
|
|
7
10
|
* Prisma field modifiers.
|
|
8
11
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
interface PrismaFieldModifiers {
|
|
13
|
+
/** Field is optional (nullable) */
|
|
14
|
+
isOptional?: boolean;
|
|
15
|
+
/** Field is an array */
|
|
16
|
+
isArray?: boolean;
|
|
17
|
+
/** Field is unique */
|
|
18
|
+
isUnique?: boolean;
|
|
19
|
+
/** Field is the primary key (use @id) */
|
|
20
|
+
isId?: boolean;
|
|
21
|
+
/** Default value expression (e.g., 'cuid()', 'now()', 'autoincrement()') */
|
|
22
|
+
default?: string | number | boolean;
|
|
23
|
+
/** Field is auto-updated on record update (e.g., @updatedAt) */
|
|
24
|
+
updatedAt?: boolean;
|
|
25
|
+
/** Database column name override */
|
|
26
|
+
map?: string;
|
|
27
|
+
/** Database column type override */
|
|
28
|
+
dbType?: string;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Scalar field definition for an entity.
|
|
29
32
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
interface EntityScalarField extends PrismaFieldModifiers {
|
|
34
|
+
kind: 'scalar';
|
|
35
|
+
type: PrismaScalarType;
|
|
36
|
+
/** Zod schema for validation */
|
|
37
|
+
zod?: z.ZodType;
|
|
38
|
+
/** Human-readable description (becomes Prisma /// comment) */
|
|
39
|
+
description?: string;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Enum field definition for an entity.
|
|
40
43
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
interface EntityEnumField extends PrismaFieldModifiers {
|
|
45
|
+
kind: 'enum';
|
|
46
|
+
/** Name of the enum type */
|
|
47
|
+
enumName: string;
|
|
48
|
+
/** Enum values (for inline enum definition) */
|
|
49
|
+
values?: readonly string[];
|
|
50
|
+
/** Zod schema for validation */
|
|
51
|
+
zod?: z.ZodType;
|
|
52
|
+
/** Human-readable description */
|
|
53
|
+
description?: string;
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Relation types supported by Prisma.
|
|
54
57
|
*/
|
|
55
|
-
|
|
58
|
+
type RelationType = 'hasOne' | 'hasMany' | 'belongsTo';
|
|
56
59
|
/**
|
|
57
60
|
* Relation field definition for an entity.
|
|
58
61
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
interface EntityRelationField {
|
|
63
|
+
kind: 'relation';
|
|
64
|
+
type: RelationType;
|
|
65
|
+
/** Target entity name */
|
|
66
|
+
target: string;
|
|
67
|
+
/** Foreign key field(s) on this model (for belongsTo) */
|
|
68
|
+
fields?: string[];
|
|
69
|
+
/** Referenced field(s) on the target model */
|
|
70
|
+
references?: string[];
|
|
71
|
+
/** Relation name for disambiguation */
|
|
72
|
+
name?: string;
|
|
73
|
+
/** On delete action */
|
|
74
|
+
onDelete?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
|
|
75
|
+
/** On update action */
|
|
76
|
+
onUpdate?: 'Cascade' | 'SetNull' | 'Restrict' | 'NoAction' | 'SetDefault';
|
|
77
|
+
/** Human-readable description */
|
|
78
|
+
description?: string;
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* Union of all entity field types.
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
type EntityField = EntityScalarField | EntityEnumField | EntityRelationField;
|
|
81
84
|
/**
|
|
82
85
|
* Index definition for an entity.
|
|
83
86
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
interface EntityIndex {
|
|
88
|
+
/** Fields included in the index */
|
|
89
|
+
fields: string[];
|
|
90
|
+
/** Index is unique constraint */
|
|
91
|
+
unique?: boolean;
|
|
92
|
+
/** Index name override */
|
|
93
|
+
name?: string;
|
|
94
|
+
/** Sort order per field */
|
|
95
|
+
sort?: Record<string, 'Asc' | 'Desc'>;
|
|
96
|
+
/** Index type */
|
|
97
|
+
type?: 'BTree' | 'Hash' | 'Gist' | 'Gin';
|
|
95
98
|
}
|
|
96
99
|
/**
|
|
97
100
|
* Enum definition that can be shared across entities.
|
|
98
101
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
interface EntityEnumDef {
|
|
103
|
+
/** Enum name */
|
|
104
|
+
name: string;
|
|
105
|
+
/** Enum values */
|
|
106
|
+
values: readonly string[];
|
|
107
|
+
/** Postgres schema where the enum is defined */
|
|
108
|
+
schema?: string;
|
|
109
|
+
/** Human-readable description */
|
|
110
|
+
description?: string;
|
|
108
111
|
}
|
|
109
112
|
/**
|
|
110
113
|
* Complete entity specification for database-backed models.
|
|
111
114
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
interface EntitySpec<TFields extends Record<string, EntityField> = Record<string, EntityField>> {
|
|
116
|
+
/** Entity/model name (PascalCase) */
|
|
117
|
+
name: string;
|
|
118
|
+
/** Human-readable description (becomes Prisma /// comment) */
|
|
119
|
+
description?: string;
|
|
120
|
+
/** Postgres schema name (default: 'public') */
|
|
121
|
+
schema?: string;
|
|
122
|
+
/** Database table name override */
|
|
123
|
+
map?: string;
|
|
124
|
+
/** Field definitions */
|
|
125
|
+
fields: TFields;
|
|
126
|
+
/** Index definitions */
|
|
127
|
+
indexes?: EntityIndex[];
|
|
128
|
+
/** Enum definitions used by this entity */
|
|
129
|
+
enums?: EntityEnumDef[];
|
|
130
|
+
/** Module/domain this entity belongs to (for schema composition) */
|
|
131
|
+
module?: string;
|
|
129
132
|
}
|
|
130
133
|
/**
|
|
131
134
|
* Module schema contribution for composition.
|
|
132
135
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
interface ModuleSchemaContribution {
|
|
137
|
+
/** Module identifier (e.g., '@lssm/lib.identity-rbac') */
|
|
138
|
+
moduleId: string;
|
|
139
|
+
/** Entity specs provided by this module */
|
|
140
|
+
entities: EntitySpec[];
|
|
141
|
+
/** Shared enum definitions */
|
|
142
|
+
enums?: EntityEnumDef[];
|
|
140
143
|
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, ModuleSchemaContribution, PrismaFieldModifiers, PrismaScalarType, RelationType };
|
|
141
146
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/entity/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAciB,KAdL,gBAAA,GAcyB,QAAA,GAAA,KAAA,GAAA,OAAA,GAAA,SAAA,GAAA,UAAA,GAAA,MAAA,GAAA,QAAA,GAAA,SAAA,GAAA,OAAA;AAsBrC;;;AAA2C,UAtB1B,oBAAA,CAsB0B;EAAoB;EAY9C,UAAA,CAAA,EAAA,OAAgB;EAerB;EAKK,OAAA,CAAA,EAAA,OAAA;EAsBL;EACR,QAAA,CAAA,EAAA,OAAA;EACA;EACA,IAAA,CAAA,EAAA,OAAA;EAAmB;EAKN,OAAA,CAAA,EAAA,MAAW,GAAA,MAQnB,GAAA,OAAM;EAQE;EAcA,SAAA,CAAA,EAAA,OAAU;EACM;EAAf,GAAA,CAAA,EAAA,MAAA;EAA6C;EAAf,MAAA,CAAA,EAAA,MAAA;;;;;AAuB/B,UApHA,iBAAA,SAA0B,oBA0HjC,CAAA;;QAxHF;;QAEA,CAAA,CAAE;;;;;;;UAQO,eAAA,SAAwB;;;;;;;QAOjC,CAAA,CAAE;;;;;;;KAQE,YAAA;;;;UAKK,mBAAA;;QAET;;;;;;;;;;;;;;;;;;;KAoBI,WAAA,GACR,oBACA,kBACA;;;;UAKa,WAAA;;;;;;;;SAQR;;;;;;;UAQQ,aAAA;;;;;;;;;;;;;UAcA,2BACC,eAAe,eAAe,eAAe;;;;;;;;;;UAWrD;;YAEE;;UAEF;;;;;;;UAQO,wBAAA;;;;YAIL;;UAEF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "zod";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { AnyEnumType, EnumType, defineEnum } from "./EnumType.js";
|
|
2
|
+
import { AnyFieldType, FieldType, FieldTypeConfig, ZodFieldType } from "./FieldType.js";
|
|
3
|
+
import { ScalarTypeEnum } from "./ScalarTypeEnum.js";
|
|
4
|
+
import { AnySchemaModel, SchemaFieldConfig, SchemaModel, SchemaModelConfig, SchemaModelFieldsAnyConfig, TopLevelZodFromModel, ZodSchemaModel, ZodShapeFromFields, defineSchemaModel } from "./SchemaModel.js";
|
|
5
|
+
import { EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, ModuleSchemaContribution, PrismaFieldModifiers, PrismaScalarType, RelationType } from "./entity/types.js";
|
|
6
|
+
import { defineEntity, defineEntityEnum, field, index } from "./entity/defineEntity.js";
|
|
7
|
+
import { PrismaGeneratorOptions, composeModuleSchemas, generateEntityFragment, generateEnumFragment, generatePrismaSchema } from "./entity/generator.js";
|
|
8
|
+
import "./entity/index.js";
|
|
9
|
+
export { AnyEnumType, AnyFieldType, AnySchemaModel, EntityEnumDef, EntityEnumField, EntityField, EntityIndex, EntityRelationField, EntityScalarField, EntitySpec, EnumType, FieldType, FieldTypeConfig, ModuleSchemaContribution, PrismaFieldModifiers, PrismaGeneratorOptions, PrismaScalarType, RelationType, ScalarTypeEnum, SchemaFieldConfig, SchemaModel, SchemaModelConfig, SchemaModelFieldsAnyConfig, TopLevelZodFromModel, ZodFieldType, ZodSchemaModel, ZodShapeFromFields, composeModuleSchemas, defineEntity, defineEntityEnum, defineEnum, defineSchemaModel, field, generateEntityFragment, generateEnumFragment, generatePrismaSchema, index };
|