ormbridge 0.8.0 → 0.10.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 (152) hide show
  1. package/README.md +2 -0
  2. package/dist/cliRunner.js +3 -3
  3. package/dist/cliRunner.js.map +1 -1
  4. package/dist/config.d.ts +3 -2
  5. package/dist/config.js.map +1 -1
  6. package/dist/emitters/efcore.d.ts +40 -0
  7. package/dist/emitters/efcore.js +686 -0
  8. package/dist/emitters/efcore.js.map +1 -0
  9. package/dist/emitters/efcoreColumns.d.ts +75 -0
  10. package/dist/emitters/efcoreColumns.js +492 -0
  11. package/dist/emitters/efcoreColumns.js.map +1 -0
  12. package/dist/emitters/efcoreNames.d.ts +30 -0
  13. package/dist/emitters/efcoreNames.js +268 -0
  14. package/dist/emitters/efcoreNames.js.map +1 -0
  15. package/dist/emitters/efcoreRender.d.ts +2 -0
  16. package/dist/emitters/efcoreRender.js +570 -0
  17. package/dist/emitters/efcoreRender.js.map +1 -0
  18. package/dist/emitters/efcoreTypes.d.ts +114 -0
  19. package/dist/emitters/efcoreTypes.js +2 -0
  20. package/dist/emitters/efcoreTypes.js.map +1 -0
  21. package/dist/emitters/jpa.d.ts +36 -0
  22. package/dist/emitters/jpa.js +253 -0
  23. package/dist/emitters/jpa.js.map +1 -0
  24. package/dist/emitters/jpaColumns.d.ts +25 -0
  25. package/dist/emitters/jpaColumns.js +341 -0
  26. package/dist/emitters/jpaColumns.js.map +1 -0
  27. package/dist/emitters/jpaDefaults.d.ts +24 -0
  28. package/dist/emitters/jpaDefaults.js +223 -0
  29. package/dist/emitters/jpaDefaults.js.map +1 -0
  30. package/dist/emitters/jpaEnums.d.ts +11 -0
  31. package/dist/emitters/jpaEnums.js +134 -0
  32. package/dist/emitters/jpaEnums.js.map +1 -0
  33. package/dist/emitters/jpaFormat.d.ts +16 -0
  34. package/dist/emitters/jpaFormat.js +73 -0
  35. package/dist/emitters/jpaFormat.js.map +1 -0
  36. package/dist/emitters/jpaKeys.d.ts +25 -0
  37. package/dist/emitters/jpaKeys.js +110 -0
  38. package/dist/emitters/jpaKeys.js.map +1 -0
  39. package/dist/emitters/jpaNames.d.ts +26 -0
  40. package/dist/emitters/jpaNames.js +234 -0
  41. package/dist/emitters/jpaNames.js.map +1 -0
  42. package/dist/emitters/jpaRelations.d.ts +41 -0
  43. package/dist/emitters/jpaRelations.js +304 -0
  44. package/dist/emitters/jpaRelations.js.map +1 -0
  45. package/dist/emitters/jpaRender.d.ts +10 -0
  46. package/dist/emitters/jpaRender.js +81 -0
  47. package/dist/emitters/jpaRender.js.map +1 -0
  48. package/dist/emitters/jpaScalars.d.ts +32 -0
  49. package/dist/emitters/jpaScalars.js +188 -0
  50. package/dist/emitters/jpaScalars.js.map +1 -0
  51. package/dist/emitters/jpaTable.d.ts +10 -0
  52. package/dist/emitters/jpaTable.js +109 -0
  53. package/dist/emitters/jpaTable.js.map +1 -0
  54. package/dist/emitters/jpaTypes.d.ts +85 -0
  55. package/dist/emitters/jpaTypes.js +36 -0
  56. package/dist/emitters/jpaTypes.js.map +1 -0
  57. package/dist/formats.d.ts +8 -4
  58. package/dist/formats.js +68 -0
  59. package/dist/formats.js.map +1 -1
  60. package/dist/index.d.ts +8 -0
  61. package/dist/index.js +4 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/io.js +51 -1
  64. package/dist/io.js.map +1 -1
  65. package/dist/parsers/csharpChains.d.ts +36 -0
  66. package/dist/parsers/csharpChains.js +157 -0
  67. package/dist/parsers/csharpChains.js.map +1 -0
  68. package/dist/parsers/csharpDeclarations.d.ts +3 -0
  69. package/dist/parsers/csharpDeclarations.js +293 -0
  70. package/dist/parsers/csharpDeclarations.js.map +1 -0
  71. package/dist/parsers/csharpSyntax.d.ts +130 -0
  72. package/dist/parsers/csharpSyntax.js +339 -0
  73. package/dist/parsers/csharpSyntax.js.map +1 -0
  74. package/dist/parsers/efcore.d.ts +17 -0
  75. package/dist/parsers/efcore.js +265 -0
  76. package/dist/parsers/efcore.js.map +1 -0
  77. package/dist/parsers/efcoreAnnotations.d.ts +19 -0
  78. package/dist/parsers/efcoreAnnotations.js +293 -0
  79. package/dist/parsers/efcoreAnnotations.js.map +1 -0
  80. package/dist/parsers/efcoreBuild.d.ts +13 -0
  81. package/dist/parsers/efcoreBuild.js +523 -0
  82. package/dist/parsers/efcoreBuild.js.map +1 -0
  83. package/dist/parsers/efcoreEntities.d.ts +13 -0
  84. package/dist/parsers/efcoreEntities.js +468 -0
  85. package/dist/parsers/efcoreEntities.js.map +1 -0
  86. package/dist/parsers/efcoreFields.d.ts +22 -0
  87. package/dist/parsers/efcoreFields.js +285 -0
  88. package/dist/parsers/efcoreFields.js.map +1 -0
  89. package/dist/parsers/efcoreFluent.d.ts +47 -0
  90. package/dist/parsers/efcoreFluent.js +375 -0
  91. package/dist/parsers/efcoreFluent.js.map +1 -0
  92. package/dist/parsers/efcoreModel.d.ts +209 -0
  93. package/dist/parsers/efcoreModel.js +2 -0
  94. package/dist/parsers/efcoreModel.js.map +1 -0
  95. package/dist/parsers/efcoreRelations.d.ts +46 -0
  96. package/dist/parsers/efcoreRelations.js +317 -0
  97. package/dist/parsers/efcoreRelations.js.map +1 -0
  98. package/dist/parsers/efcoreSteps.d.ts +89 -0
  99. package/dist/parsers/efcoreSteps.js +793 -0
  100. package/dist/parsers/efcoreSteps.js.map +1 -0
  101. package/dist/parsers/efcoreTypes.d.ts +35 -0
  102. package/dist/parsers/efcoreTypes.js +404 -0
  103. package/dist/parsers/efcoreTypes.js.map +1 -0
  104. package/dist/parsers/javaSyntax.d.ts +120 -0
  105. package/dist/parsers/javaSyntax.js +304 -0
  106. package/dist/parsers/javaSyntax.js.map +1 -0
  107. package/dist/parsers/javaValues.d.ts +5 -0
  108. package/dist/parsers/javaValues.js +187 -0
  109. package/dist/parsers/javaValues.js.map +1 -0
  110. package/dist/parsers/jpa.d.ts +17 -0
  111. package/dist/parsers/jpa.js +131 -0
  112. package/dist/parsers/jpa.js.map +1 -0
  113. package/dist/parsers/jpaAnnotations.d.ts +46 -0
  114. package/dist/parsers/jpaAnnotations.js +156 -0
  115. package/dist/parsers/jpaAnnotations.js.map +1 -0
  116. package/dist/parsers/jpaBuild.d.ts +4 -0
  117. package/dist/parsers/jpaBuild.js +297 -0
  118. package/dist/parsers/jpaBuild.js.map +1 -0
  119. package/dist/parsers/jpaClasses.d.ts +27 -0
  120. package/dist/parsers/jpaClasses.js +257 -0
  121. package/dist/parsers/jpaClasses.js.map +1 -0
  122. package/dist/parsers/jpaCollections.d.ts +12 -0
  123. package/dist/parsers/jpaCollections.js +106 -0
  124. package/dist/parsers/jpaCollections.js.map +1 -0
  125. package/dist/parsers/jpaColumns.d.ts +26 -0
  126. package/dist/parsers/jpaColumns.js +361 -0
  127. package/dist/parsers/jpaColumns.js.map +1 -0
  128. package/dist/parsers/jpaEntities.d.ts +9 -0
  129. package/dist/parsers/jpaEntities.js +181 -0
  130. package/dist/parsers/jpaEntities.js.map +1 -0
  131. package/dist/parsers/jpaIndexes.d.ts +12 -0
  132. package/dist/parsers/jpaIndexes.js +87 -0
  133. package/dist/parsers/jpaIndexes.js.map +1 -0
  134. package/dist/parsers/jpaJoins.d.ts +68 -0
  135. package/dist/parsers/jpaJoins.js +131 -0
  136. package/dist/parsers/jpaJoins.js.map +1 -0
  137. package/dist/parsers/jpaModel.d.ts +73 -0
  138. package/dist/parsers/jpaModel.js +2 -0
  139. package/dist/parsers/jpaModel.js.map +1 -0
  140. package/dist/parsers/jpaNotes.d.ts +20 -0
  141. package/dist/parsers/jpaNotes.js +138 -0
  142. package/dist/parsers/jpaNotes.js.map +1 -0
  143. package/dist/parsers/jpaRelations.d.ts +4 -0
  144. package/dist/parsers/jpaRelations.js +242 -0
  145. package/dist/parsers/jpaRelations.js.map +1 -0
  146. package/dist/parsers/jpaTypes.d.ts +23 -0
  147. package/dist/parsers/jpaTypes.js +232 -0
  148. package/dist/parsers/jpaTypes.js.map +1 -0
  149. package/dist/styles.d.ts +4 -2
  150. package/dist/styles.js +7 -1
  151. package/dist/styles.js.map +1 -1
  152. package/package.json +10 -1
@@ -0,0 +1,114 @@
1
+ import type { IrCompositeForeignKey, IrField, IrModel, IrRelation, IrSchema } from '../ir.js';
2
+ import type { ColumnSpec, EnumPlan } from './efcoreColumns.js';
3
+ import type { PrismaProvider } from './prisma.js';
4
+ /** The shapes the planning and rendering steps of the EF Core emitter share. */
5
+ export type EfcoreStyle = 'annotations' | 'fluent';
6
+ /** One property that is a database column: a field, or the foreign key column of a relation. */
7
+ export interface ColumnMember {
8
+ property: string;
9
+ spec: ColumnSpec;
10
+ /** True when the column is part of the primary key. */
11
+ isKey: boolean;
12
+ /** The IR field, for a field. */
13
+ fieldName?: string;
14
+ /** The IR relation, for a foreign key column. */
15
+ relationName?: string;
16
+ }
17
+ /** One navigation property. */
18
+ export interface NavMember {
19
+ property: string;
20
+ /** The class the navigation points at. */
21
+ typeName: string;
22
+ collection: boolean;
23
+ /** True when a reference may be null. */
24
+ nullable: boolean;
25
+ /** Foreign key properties, for the reference navigation of the dependent side. */
26
+ foreignKeys?: string[];
27
+ /** The navigation on the other side, for `[InverseProperty]`. */
28
+ inverseOf?: {
29
+ className: string;
30
+ property: string;
31
+ };
32
+ }
33
+ export interface ConfigIndex {
34
+ properties: string[];
35
+ unique: boolean;
36
+ name?: string;
37
+ /** Sort order by position; empty when every column is ascending. */
38
+ descending: boolean[];
39
+ /** Access method (`gin`); only the fluent API can say it. */
40
+ method?: string;
41
+ }
42
+ /** A one-to-many or one-to-one relationship, seen from the entity that holds the foreign key. */
43
+ export interface Link {
44
+ owner: ModelPlan;
45
+ target: ModelPlan;
46
+ relationName: string;
47
+ relation?: IrRelation;
48
+ composite?: IrCompositeForeignKey;
49
+ /** The reference navigation on the owner. */
50
+ nav: string;
51
+ /** The navigation on the target, when the relation has a related name. */
52
+ inverse?: string;
53
+ oneToOne: boolean;
54
+ /** Foreign key properties on the owner. */
55
+ foreignKeys: string[];
56
+ /** Referenced properties on the target when they are not its primary key. */
57
+ principalKeys?: string[];
58
+ /** The `DeleteBehavior` to write; undefined when EF Core's default is the wanted one. */
59
+ behavior?: string;
60
+ required: boolean;
61
+ constraintName?: string;
62
+ /** The key field the foreign key column copies its type from. */
63
+ keyField?: IrField;
64
+ }
65
+ export interface ManyToManyLink {
66
+ owner: ModelPlan;
67
+ target: ModelPlan;
68
+ relationName: string;
69
+ nav: string;
70
+ inverse?: string;
71
+ joinTable: string;
72
+ ownerColumn: string;
73
+ targetColumn: string;
74
+ }
75
+ export interface ModelPlan {
76
+ model: IrModel;
77
+ className: string;
78
+ /** The `DbSet` property name on the context. */
79
+ dbSet: string;
80
+ tableName: string;
81
+ /** True when the table name is not the `DbSet` name, so the class needs `[Table]` / `ToTable`. */
82
+ needsTable: boolean;
83
+ schema: string | undefined;
84
+ /** Member names in use on the class. */
85
+ used: Set<string>;
86
+ /** IR field name -> property. */
87
+ fieldProps: Map<string, string>;
88
+ /** IR relation name -> foreign key property. */
89
+ relationFks: Map<string, string>;
90
+ /** IR relation name -> navigation property. */
91
+ relationNavs: Map<string, string>;
92
+ columns: ColumnMember[];
93
+ navs: NavMember[];
94
+ /** Primary key properties, in key order. */
95
+ keyProps: string[];
96
+ keyless: boolean;
97
+ isView: boolean;
98
+ keyName: string | undefined;
99
+ alternateKeys: string[][];
100
+ indexes: ConfigIndex[];
101
+ links: Link[];
102
+ manyToMany: ManyToManyLink[];
103
+ /** Properties that are refreshed on every save. */
104
+ autoUpdated: string[];
105
+ }
106
+ export interface Plan {
107
+ schema: IrSchema;
108
+ style: EfcoreStyle;
109
+ namespace: string;
110
+ header: boolean;
111
+ provider: PrismaProvider;
112
+ models: ModelPlan[];
113
+ enums: EnumPlan[];
114
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=efcoreTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"efcoreTypes.js","sourceRoot":"","sources":["../../src/emitters/efcoreTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,36 @@
1
+ import type { MultiFileEmitOutput } from '../formats.js';
2
+ import type { IrSchema } from '../ir.js';
3
+ import { type NamingMode } from '../transforms.js';
4
+ import { type JpaStyle } from './jpaTypes.js';
5
+ import type { PrismaProvider } from './prisma.js';
6
+ /**
7
+ * Writes Hibernate / JPA entities (Java): one `@Entity` class per model, a Java `enum` per enum (with an
8
+ * `AttributeConverter` when the stored values differ from the constant names) and an `@IdClass` class for every
9
+ * composite primary key. Two styles choose the persistence API: `jakarta` (the default; `jakarta.persistence`,
10
+ * Hibernate 6, Spring Boot 3) and `javax` (`javax.persistence`, Hibernate 5, Spring Boot 2).
11
+ *
12
+ * Every table, column, key, index and foreign key is written explicitly (`@Table`, `@Column`, `@JoinColumn`), so
13
+ * the output creates the schema of the IR whatever naming strategy the application uses, and the JPA reader reads
14
+ * it back.
15
+ */
16
+ export { DEFAULT_JPA_PACKAGE, isValidJavaPackage } from './jpaNames.js';
17
+ export type { JpaStyle } from './jpaTypes.js';
18
+ export declare const JPA_STYLES: readonly JpaStyle[];
19
+ /** True when a value is one of the JPA `--style` values. */
20
+ export declare function isJpaStyle(value: string): value is JpaStyle;
21
+ export interface JpaEmitOptions {
22
+ /** Database provider; picks the column types and the SQL of defaults. */
23
+ provider: PrismaProvider;
24
+ /**
25
+ * "preserve" keeps the database names of the source. "normalize" applies the fresh-schema style of the other
26
+ * emitters (singular snake_case tables, UUID keys, `created_at` / `updated_at`).
27
+ */
28
+ naming: NamingMode;
29
+ /** The persistence API; defaults to `jakarta`. */
30
+ style?: JpaStyle;
31
+ /** Java package of the generated classes; defaults to `app.models`. */
32
+ packageName?: string;
33
+ /** Write the `// <auto-generated>` comment at the top of every file (default true). */
34
+ header?: boolean;
35
+ }
36
+ export declare function emitJpa(schema: IrSchema, options: JpaEmitOptions): MultiFileEmitOutput;
@@ -0,0 +1,253 @@
1
+ import { prismaOnlyWarnings } from '../prismaOnlyConstructs.js';
2
+ import { normalizeSchema } from '../transforms.js';
3
+ import { buildColumn, } from './jpaColumns.js';
4
+ import { planEnums, renderConverterBody, renderEnumBody } from './jpaEnums.js';
5
+ import { annotation } from './jpaFormat.js';
6
+ import { renderIdClass, keyOf } from './jpaKeys.js';
7
+ import { classNameOf, RESERVED_TYPE_NAMES, attributeNameOf, uniqueName, DEFAULT_JPA_PACKAGE, } from './jpaNames.js';
8
+ import { addInverseRelations, addOwningRelations, } from './jpaRelations.js';
9
+ import { renderEntity, renderFile } from './jpaRender.js';
10
+ import { tableAnnotation } from './jpaTable.js';
11
+ import { Imports, } from './jpaTypes.js';
12
+ /**
13
+ * Writes Hibernate / JPA entities (Java): one `@Entity` class per model, a Java `enum` per enum (with an
14
+ * `AttributeConverter` when the stored values differ from the constant names) and an `@IdClass` class for every
15
+ * composite primary key. Two styles choose the persistence API: `jakarta` (the default; `jakarta.persistence`,
16
+ * Hibernate 6, Spring Boot 3) and `javax` (`javax.persistence`, Hibernate 5, Spring Boot 2).
17
+ *
18
+ * Every table, column, key, index and foreign key is written explicitly (`@Table`, `@Column`, `@JoinColumn`), so
19
+ * the output creates the schema of the IR whatever naming strategy the application uses, and the JPA reader reads
20
+ * it back.
21
+ */
22
+ export { DEFAULT_JPA_PACKAGE, isValidJavaPackage } from './jpaNames.js';
23
+ export const JPA_STYLES = ['jakarta', 'javax'];
24
+ /** True when a value is one of the JPA `--style` values. */
25
+ export function isJpaStyle(value) {
26
+ return JPA_STYLES.includes(value);
27
+ }
28
+ // ---------------------------------------------------------------------------
29
+ // Entry point
30
+ // ---------------------------------------------------------------------------
31
+ export function emitJpa(schema, options) {
32
+ const prepared = options.naming === 'normalize' ? normalizeSchema(schema) : schema;
33
+ const warnings = prismaOnlyWarnings(prepared, true).filter(isUnhandledWarning);
34
+ if (options.provider === 'mongodb') {
35
+ warnings.push('Provider "mongodb": JPA is relational (Hibernate OGM and Spring Data MongoDB are separate projects); PostgreSQL column types were written.');
36
+ }
37
+ if (prepared.models.length === 0) {
38
+ return { files: {}, warnings };
39
+ }
40
+ const style = options.style ?? 'jakarta';
41
+ const layout = {
42
+ packageName: options.packageName ?? DEFAULT_JPA_PACKAGE,
43
+ header: options.header !== false,
44
+ };
45
+ const files = {};
46
+ planAndRender(prepared, options, style, layout, files, warnings);
47
+ return { files, warnings: [...new Set(warnings)] };
48
+ }
49
+ /** Drops the Prisma-only notes for things this emitter writes (schemas, views, defaults, composite keys, indexes). */
50
+ function isUnhandledWarning(warning) {
51
+ if (warning.includes('the database default expression')) {
52
+ return false;
53
+ }
54
+ if (warning.includes('(Prisma Unsupported)')) {
55
+ return false;
56
+ }
57
+ if (warning.includes('is generated by Prisma Client and was dropped')) {
58
+ return false;
59
+ }
60
+ if (warning.includes('has no equivalent here; the relation was dropped')) {
61
+ return false;
62
+ }
63
+ if (warning.includes('the index type, clustering, sort order')) {
64
+ return false;
65
+ }
66
+ if (warning.includes('full-text indexes are not supported here')) {
67
+ return false;
68
+ }
69
+ if (warning.includes('is not supported by this format and was ignored')) {
70
+ return false;
71
+ }
72
+ return !(warning.includes('(@@schema) was ignored') && !warning.startsWith('enum '));
73
+ }
74
+ // ---------------------------------------------------------------------------
75
+ // Planning
76
+ // ---------------------------------------------------------------------------
77
+ function pathOf(packageName, className) {
78
+ return `${packageName.replace(/\./g, '/')}/${className}.java`;
79
+ }
80
+ function planAndRender(schema, options, style, layout, files, warnings) {
81
+ const warn = (message) => {
82
+ warnings.push(message);
83
+ };
84
+ const typeNames = new Set(RESERVED_TYPE_NAMES);
85
+ const enums = planEnums(schema, typeNames, warn);
86
+ const plans = new Map();
87
+ for (const model of schema.models) {
88
+ const raw = classNameOf(model.name);
89
+ const className = uniqueName(RESERVED_TYPE_NAMES.has(raw) ? `${raw}Entity` : raw, typeNames);
90
+ if (className !== raw) {
91
+ warn(`${model.name}: "${raw}" is a name the generated code uses or another type has, so the class was named "${className}".`);
92
+ }
93
+ plans.set(model.name, {
94
+ model,
95
+ className,
96
+ fieldNames: new Map(),
97
+ relationNames: new Map(),
98
+ used: new Set(),
99
+ attributes: [],
100
+ classAnnotations: [],
101
+ imports: new Imports(style),
102
+ dynamicInsert: false,
103
+ });
104
+ }
105
+ const keys = new Map();
106
+ for (const model of schema.models) {
107
+ keys.set(model.name, keyOf(model, warn));
108
+ }
109
+ // Columns ------------------------------------------------------------------------------------
110
+ const context = {
111
+ style,
112
+ provider: options.provider,
113
+ enums,
114
+ warn,
115
+ };
116
+ const built = new Map();
117
+ for (const model of schema.models) {
118
+ const plan = planFor(plans, model);
119
+ const info = keys.get(model.name) ?? {
120
+ parts: [],
121
+ synthesized: false,
122
+ };
123
+ for (const field of model.fields) {
124
+ const wanted = attributeNameOf(field.name);
125
+ const name = uniqueName(wanted, plan.used);
126
+ if (name !== wanted) {
127
+ warn(`${model.name}.${field.name}: "${wanted}" is taken in ${plan.className}, so the attribute was named "${name}".`);
128
+ }
129
+ plan.fieldNames.set(field.name, name);
130
+ const isKey = info.parts.some((part) => part.kind === 'field' && part.field === field);
131
+ const column = buildColumn(context, `${model.name}.${field.name}`, field, name, { isKey, singleKey: info.parts.length === 1 });
132
+ built.set(field, column);
133
+ plan.attributes.push(column.attribute);
134
+ plan.dynamicInsert ||= column.dynamicInsert;
135
+ }
136
+ }
137
+ // Relations ----------------------------------------------------------------------------------
138
+ const keyTypes = new Map();
139
+ const typeOfKey = (model, depth) => {
140
+ const info = keys.get(model.name);
141
+ const part = info?.parts.length === 1 ? info.parts[0] : undefined;
142
+ if (part === undefined || depth > 6) {
143
+ return undefined;
144
+ }
145
+ if (part.kind === 'field') {
146
+ const column = built.get(part.field);
147
+ return column === undefined
148
+ ? undefined
149
+ : { type: column.boxedType, imports: column.attribute.imports };
150
+ }
151
+ const target = schema.models.find((candidate) => candidate.name === part.relation.targetModel);
152
+ return target === undefined ? undefined : typeOfKey(target, depth + 1);
153
+ };
154
+ for (const model of schema.models) {
155
+ const found = typeOfKey(model, 0);
156
+ if (found !== undefined) {
157
+ keyTypes.set(model.name, found);
158
+ }
159
+ }
160
+ const relationContext = {
161
+ style,
162
+ schema,
163
+ plans,
164
+ keys,
165
+ keyTypes,
166
+ inverses: [],
167
+ warn,
168
+ };
169
+ const keyRelations = new Map();
170
+ for (const model of schema.models) {
171
+ keyRelations.set(model.name, addOwningRelations(relationContext, planFor(plans, model)));
172
+ }
173
+ addInverseRelations(relationContext);
174
+ // Classes -----------------------------------------------------------------------------------
175
+ for (const model of schema.models) {
176
+ const plan = planFor(plans, model);
177
+ const info = keys.get(model.name) ?? {
178
+ parts: [],
179
+ synthesized: false,
180
+ };
181
+ const imports = plan.imports;
182
+ plan.classAnnotations.push(annotation(imports.persistence('Entity')), tableAnnotation({ model, imports, warn }));
183
+ if (info.parts.length > 1) {
184
+ const parts = [];
185
+ for (const part of info.parts) {
186
+ if (part.kind === 'field') {
187
+ const column = built.get(part.field);
188
+ const name = plan.fieldNames.get(part.field.name);
189
+ if (column !== undefined && name !== undefined) {
190
+ parts.push({
191
+ name,
192
+ type: column.boxedType,
193
+ imports: column.attribute.imports,
194
+ });
195
+ }
196
+ }
197
+ else {
198
+ const found = keyRelations
199
+ .get(model.name)
200
+ ?.get(part.relation);
201
+ if (found === undefined) {
202
+ warn(`${model.name}.${part.relation.name}: the relation is part of the composite primary key but could not be written, so it is missing from the key.`);
203
+ }
204
+ else {
205
+ parts.push({
206
+ name: found.attribute,
207
+ type: found.type,
208
+ imports: found.imports,
209
+ });
210
+ }
211
+ }
212
+ }
213
+ const idName = uniqueName(`${plan.className}Id`, typeNames);
214
+ plan.idClass = { name: idName, parts };
215
+ const idImports = plan.imports;
216
+ plan.classAnnotations.push(annotation(idImports.persistence('IdClass'), [
217
+ [undefined, `${idName}.class`],
218
+ ]));
219
+ const rendered = renderIdClass(idName, parts, style);
220
+ files[pathOf(layout.packageName, idName)] = renderFile(layout, rendered.imports, rendered.lines);
221
+ }
222
+ if (info.parts.length === 1 && info.parts[0]?.kind === 'relation') {
223
+ plan.serializable = true;
224
+ // The entity is Serializable only because Hibernate 5 asks for it; its relationship attributes are not.
225
+ plan.classAnnotations.push(annotation('SuppressWarnings', [[undefined, '"serial"']]));
226
+ }
227
+ if (plan.dynamicInsert) {
228
+ plan.classAnnotations.push(annotation(imports.hibernate('DynamicInsert')));
229
+ }
230
+ if (model.isView === true) {
231
+ plan.classAnnotations.push(annotation(imports.hibernate('Immutable')));
232
+ warn(`${model.name}: the table "${model.tableName}" is a database view; the class is @Immutable, but Hibernate would create a table of that name if it manages the schema (turn schema generation off for it).`);
233
+ }
234
+ files[pathOf(layout.packageName, plan.className)] = renderEntity(plan, layout);
235
+ }
236
+ // Enums and converters --------------------------------------------------------------------------
237
+ for (const plan of enums.values()) {
238
+ const body = renderEnumBody(plan);
239
+ files[pathOf(layout.packageName, plan.typeName)] = renderFile(layout, new Imports(style), body);
240
+ if (plan.storage === 'converter') {
241
+ const converter = renderConverterBody(plan, style);
242
+ files[pathOf(layout.packageName, plan.converterName)] = renderFile(layout, converter.imports, converter.lines);
243
+ }
244
+ }
245
+ }
246
+ function planFor(plans, model) {
247
+ const plan = plans.get(model.name);
248
+ if (plan === undefined) {
249
+ throw new Error(`No plan exists for the model "${model.name}".`);
250
+ }
251
+ return plan;
252
+ }
253
+ //# sourceMappingURL=jpa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jpa.js","sourceRoot":"","sources":["../../src/emitters/jpa.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AACpE,OAAO,EACL,WAAW,GAGZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,KAAK,EAA8B,MAAM,cAAc,CAAC;AAChF,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,UA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AC,KAAK,CAChB,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CACd,KAAqC,EACrC,KAAc;IAEd,MAAM,IAAI,GAA0B,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { IrField } from '../ir.js';
2
+ import { type Attribute, type EnumPlan, type JpaStyle } from './jpaTypes.js';
3
+ import type { PrismaProvider } from './prisma.js';
4
+ /** Works out how one IR field is written as a Java attribute with its JPA and Hibernate annotations. */
5
+ export interface ColumnContext {
6
+ style: JpaStyle;
7
+ provider: PrismaProvider;
8
+ enums: ReadonlyMap<string, EnumPlan>;
9
+ warn: (message: string) => void;
10
+ }
11
+ export interface KeyRole {
12
+ /** True when the column is part of the primary key. */
13
+ isKey: boolean;
14
+ /** True when it is the only column of the primary key. */
15
+ singleKey: boolean;
16
+ }
17
+ export interface BuiltColumn {
18
+ attribute: Attribute;
19
+ /** The boxed Java type, which an `@IdClass` repeats. */
20
+ boxedType: string;
21
+ /** True when the column has a database default that Hibernate must not overwrite with null. */
22
+ dynamicInsert: boolean;
23
+ }
24
+ /** Builds the Java attribute of an IR field. `name` is the attribute name chosen for it. */
25
+ export declare function buildColumn(context: ColumnContext, label: string, source: IrField, name: string, role: KeyRole): BuiltColumn;