prisma-laravel-migrate 0.0.44 → 0.0.45

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.
@@ -192,6 +192,22 @@ export class PrismaToLaravelModelGenerator {
192
192
  ...(factoryUse ? [factoryUse] : []),
193
193
  ].map(u => `use ${u.fqcn}${u.alias ? ` as ${u.alias}` : ''};`);
194
194
  imports.push(...propImps.map(item => `use ${item};`));
195
+ //--- docprops
196
+ const docblockProps = properties.map(p => {
197
+ if (p.ignore)
198
+ return null;
199
+ const type = p.phpType || 'mixed';
200
+ const nullable = type === 'mixed' || type.startsWith('?') || type.includes('null');
201
+ return `@property ${nullable ? type + '|null' : type} $${p.name}`;
202
+ }).filter(Boolean);
203
+ for (const rel of relations) {
204
+ if (rel.type === 'hasMany' || rel.type === 'belongsToMany') {
205
+ docblockProps.push(`@property \\Illuminate\\Support\\Collection<int, ${rel.modelClass}> $${rel.name}`);
206
+ }
207
+ else {
208
+ docblockProps.push(`@property ${rel.modelClass} $${rel.name}`);
209
+ }
210
+ }
195
211
  /* ── 2.6 Final ModelDefinition ────────────────────────────────── */
196
212
  return {
197
213
  className: model.name,
@@ -209,7 +225,8 @@ export class PrismaToLaravelModelGenerator {
209
225
  touches,
210
226
  traits,
211
227
  imports,
212
- extends: parentClass !== 'Model' ? parentClass : undefined
228
+ extends: parentClass !== 'Model' ? parentClass : undefined,
229
+ docblockProps
213
230
  };
214
231
  });
215
232
  return { models, enums };
@@ -45,8 +45,13 @@ export class StubModelPrinter {
45
45
  this.ensureModelStub(model.tableName);
46
46
  //--
47
47
  model.tableName = decorate(model.tableName, this.cfg);
48
+ const docblock = [
49
+ '/**',
50
+ ...model.docblockProps?.map(p => ` * ${p}`) ?? [],
51
+ ' */'
52
+ ].join('\n');
48
53
  //--
49
- return this.modelTmpl(model, enums, content);
54
+ return this.modelTmpl(model, enums, content, docblock);
50
55
  }
51
56
  /** Render multiple models, each with its own `content`, separated by two newlines. */
52
57
  printAllModels(models, enums, contents) {
@@ -73,7 +78,7 @@ export class StubModelPrinter {
73
78
  if (stubPath === this.#currentModelStub)
74
79
  return;
75
80
  const raw = fs.readFileSync(path.resolve(stubPath), 'utf-8').trim();
76
- this.modelTmpl = new Function('model', 'enums', 'content', `return \`${formatStub(raw)}\`;`);
81
+ this.modelTmpl = new Function('model', 'enums', 'content', 'docblock', `return \`${formatStub(raw)}\`;`);
77
82
  this.#currentModelStub = stubPath;
78
83
  }
79
84
  /** Load & compile the correct enum stub for `enumDef.name`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-laravel-migrate",
3
- "version": "0.0.44",
3
+ "version": "0.0.45",
4
4
  "description": "Generate laravel migrations and/or models using prisma files",
5
5
  "bin": {
6
6
  "prisma-laravel-migrations": "./dist/cli/migrator.index.js",
package/stubs/model.stub CHANGED
@@ -6,6 +6,7 @@ ${model.imports.join('\n')}${model.extends && model.extends !== 'Illuminate\Data
6
6
  ? ''
7
7
  : '\nuse Illuminate\\Database\\Eloquent\\Model;'}
8
8
 
9
+ ${docblock}
9
10
  class ${model.className} extends ${model.extends ?? 'Model'}${model.implements.length
10
11
  ? ' implements ' + model.implements.join(', ')
11
12
  : ''}