@famgia/omnify-laravel 0.0.68 → 0.0.70

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.
@@ -2,9 +2,23 @@
2
2
 
3
3
  This guide covers Laravel-specific features and generated code patterns for Omnify.
4
4
 
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Create new Laravel project (recommended)
9
+ npx @famgia/omnify create-laravel-project my-app
10
+ cd my-app
11
+
12
+ # Or initialize in existing project
13
+ npx @famgia/omnify init
14
+
15
+ # Generate Laravel migrations and models
16
+ npx @famgia/omnify generate
17
+ ```
18
+
5
19
  ## Generated Files
6
20
 
7
- When you run `npx omnify generate`, the following Laravel files are generated:
21
+ When you run `npx @famgia/omnify generate`, the following Laravel files are generated:
8
22
 
9
23
  ### Migrations
10
24
  - `database/migrations/omnify/*.php` - Laravel migrations for each schema
@@ -19,6 +33,9 @@ When you run `npx omnify generate`, the following Laravel files are generated:
19
33
  ### Locales
20
34
  - `app/Models/OmnifyBase/Locales/{ModelName}Locales.php` - i18n display names
21
35
 
36
+ ### Service Provider
37
+ - `app/Providers/OmnifyServiceProvider.php` - Morph map registration (configurable path)
38
+
22
39
  ## Model Structure
23
40
 
24
41
  ```php
@@ -56,6 +73,122 @@ class UserBaseModel extends Model
56
73
  }
57
74
  ```
58
75
 
76
+ ## Schema Options
77
+
78
+ ### Hidden Schemas (System Tables)
79
+
80
+ For system tables that only need migrations (no models), use `hidden: true`:
81
+
82
+ ```yaml
83
+ # schemas/system/Cache.yaml
84
+ name: AppCache
85
+ options:
86
+ id: false
87
+ timestamps: false
88
+ hidden: true # Skip model generation
89
+ tableName: cache # Use Laravel's default cache table name
90
+ properties:
91
+ key:
92
+ type: String
93
+ primary: true
94
+ value:
95
+ type: MediumText
96
+ expiration:
97
+ type: Int
98
+ ```
99
+
100
+ Use cases for `hidden: true`:
101
+ - Laravel cache tables (`cache`, `cache_locks`)
102
+ - Job queues (`jobs`, `failed_jobs`)
103
+ - Session tables
104
+ - System tables that don't need application models
105
+
106
+ ### Custom Table Name
107
+
108
+ Override the auto-generated table name:
109
+
110
+ ```yaml
111
+ name: AppCache
112
+ options:
113
+ tableName: cache # Use 'cache' instead of 'app_caches'
114
+ ```
115
+
116
+ ### Soft Delete
117
+
118
+ ```yaml
119
+ options:
120
+ softDelete: true # Adds deleted_at column and SoftDeletes trait
121
+ ```
122
+
123
+ ### Timestamps
124
+
125
+ ```yaml
126
+ options:
127
+ timestamps: true # Adds created_at, updated_at columns (default: true)
128
+ ```
129
+
130
+ ### Custom ID Type
131
+
132
+ ```yaml
133
+ options:
134
+ idType: Uuid # BigInt (default), Int, Uuid, String
135
+ ```
136
+
137
+ ### No Auto ID
138
+
139
+ ```yaml
140
+ options:
141
+ id: false # For tables with custom primary key
142
+ ```
143
+
144
+ ## Property Types
145
+
146
+ ### String Types
147
+
148
+ | Type | Description | MySQL Column |
149
+ |------|-------------|--------------|
150
+ | `String` | Short text (default 255) | `VARCHAR(length)` |
151
+ | `Text` | Text (~65KB) | `TEXT` |
152
+ | `MediumText` | Medium text (~16MB) | `MEDIUMTEXT` |
153
+ | `LongText` | Long text (~4GB) | `LONGTEXT` |
154
+
155
+ ### Numeric Types
156
+
157
+ | Type | Description | MySQL Column |
158
+ |------|-------------|--------------|
159
+ | `TinyInt` | 8-bit (-128~127) | `TINYINT` |
160
+ | `Int` | 32-bit integer | `INT` |
161
+ | `BigInt` | 64-bit integer | `BIGINT` |
162
+ | `Float` | Floating point | `FLOAT` |
163
+ | `Decimal` | Precise decimal | `DECIMAL(p,s)` |
164
+
165
+ ### Date/Time Types
166
+
167
+ | Type | Description | MySQL Column |
168
+ |------|-------------|--------------|
169
+ | `Date` | Date only | `DATE` |
170
+ | `DateTime` | Date and time | `DATETIME` |
171
+ | `Timestamp` | Timestamp | `TIMESTAMP` |
172
+
173
+ ### Timestamp with useCurrent
174
+
175
+ ```yaml
176
+ properties:
177
+ created_at:
178
+ type: Timestamp
179
+ useCurrent: true # Default to CURRENT_TIMESTAMP
180
+ updated_at:
181
+ type: Timestamp
182
+ useCurrent: true
183
+ useCurrentOnUpdate: true # Auto-update on row change
184
+ ```
185
+
186
+ Generated migration:
187
+ ```php
188
+ $table->timestamp('created_at')->useCurrent();
189
+ $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
190
+ ```
191
+
59
192
  ## Localization (i18n)
60
193
 
61
194
  ### Display Names
@@ -69,7 +202,6 @@ User::getLocalizedPropertyDisplayName('email');
69
202
 
70
203
  ### Schema Definition
71
204
  ```yaml
72
- # yaml-language-server: $schema=./node_modules/.omnify/combined-schema.json
73
205
  name: User
74
206
  displayName:
75
207
  ja: ユーザー
@@ -84,7 +216,7 @@ properties:
84
216
 
85
217
  ## Relationships
86
218
 
87
- ### ManyToOne
219
+ ### ManyToOne (BelongsTo)
88
220
  ```yaml
89
221
  # In Post schema
90
222
  author:
@@ -96,14 +228,13 @@ author:
96
228
 
97
229
  Generated:
98
230
  ```php
99
- // PostBaseModel.php
100
231
  public function author(): BelongsTo
101
232
  {
102
233
  return $this->belongsTo(User::class);
103
234
  }
104
235
  ```
105
236
 
106
- ### OneToMany
237
+ ### OneToMany (HasMany)
107
238
  ```yaml
108
239
  # In User schema
109
240
  posts:
@@ -115,16 +246,14 @@ posts:
115
246
 
116
247
  Generated:
117
248
  ```php
118
- // UserBaseModel.php
119
249
  public function posts(): HasMany
120
250
  {
121
251
  return $this->hasMany(Post::class, 'author_id');
122
252
  }
123
253
  ```
124
254
 
125
- ### ManyToMany
255
+ ### ManyToMany (BelongsToMany)
126
256
  ```yaml
127
- # In Post schema
128
257
  tags:
129
258
  type: Association
130
259
  relation: ManyToMany
@@ -138,7 +267,6 @@ tags:
138
267
 
139
268
  Generated:
140
269
  ```php
141
- // PostBaseModel.php
142
270
  public function tags(): BelongsToMany
143
271
  {
144
272
  return $this->belongsToMany(Tag::class, 'post_tags')
@@ -146,25 +274,19 @@ public function tags(): BelongsToMany
146
274
  }
147
275
  ```
148
276
 
149
- ## Migration Options
150
-
151
- ### Soft Delete
277
+ ### MorphTo (Polymorphic)
152
278
  ```yaml
153
- options:
154
- softDelete: true # Adds deleted_at column and SoftDeletes trait
279
+ # Comment can belong to Post or Video
280
+ commentable:
281
+ type: Association
282
+ relation: MorphTo
283
+ targets: [Post, Video]
284
+ nullable: true # Default: true
155
285
  ```
156
286
 
157
- ### Timestamps
158
- ```yaml
159
- options:
160
- timestamps: true # Adds created_at, updated_at columns
161
- ```
162
-
163
- ### Custom Table Name
164
- ```yaml
165
- options:
166
- table: custom_table_name
167
- ```
287
+ Generated columns:
288
+ - `commentable_type` (enum: 'Post', 'Video')
289
+ - `commentable_id` (bigint, nullable)
168
290
 
169
291
  ## Enum Support
170
292
 
@@ -191,32 +313,149 @@ Generated migration:
191
313
  $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
192
314
  ```
193
315
 
316
+ ## Configuration
317
+
318
+ ```typescript
319
+ // omnify.config.ts
320
+ import { defineConfig } from '@famgia/omnify';
321
+ import laravel from '@famgia/omnify-laravel/plugin';
322
+
323
+ export default defineConfig({
324
+ schemasDir: './schemas',
325
+ lockFilePath: './.omnify.lock',
326
+
327
+ database: {
328
+ driver: 'mysql',
329
+ devUrl: 'mysql://root:password@localhost:3306/dev_db',
330
+ },
331
+
332
+ plugins: [
333
+ laravel({
334
+ // Migration output path
335
+ migrationsPath: 'database/migrations/omnify',
336
+
337
+ // Model output paths
338
+ modelsPath: 'app/Models',
339
+ baseModelsPath: 'app/Models/OmnifyBase',
340
+
341
+ // Service provider path (for morph map)
342
+ providersPath: 'app/Providers',
343
+
344
+ // Locales path
345
+ localesPath: 'app/Models/OmnifyBase/Locales',
346
+ }),
347
+ ],
348
+ });
349
+ ```
350
+
351
+ ### Configuration Options
352
+
353
+ | Option | Type | Default | Description |
354
+ |--------|------|---------|-------------|
355
+ | `migrationsPath` | `string` | `database/migrations/omnify` | Laravel migrations output |
356
+ | `modelsPath` | `string` | `app/Models` | Model classes output |
357
+ | `baseModelsPath` | `string` | `app/Models/OmnifyBase` | Base model classes output |
358
+ | `providersPath` | `string` | `app/Providers` | Service provider output |
359
+ | `localesPath` | `string` | `app/Models/OmnifyBase/Locales` | Locale files output |
360
+
194
361
  ## Commands
195
362
 
196
363
  ```bash
364
+ # Create new Laravel project
365
+ npx @famgia/omnify create-laravel-project my-app
366
+
197
367
  # Generate Laravel migrations and models
198
- npx omnify generate
368
+ npx @famgia/omnify generate
199
369
 
200
370
  # Force regenerate all files
201
- npx omnify generate --force
371
+ npx @famgia/omnify generate --force
372
+
373
+ # Only generate migrations
374
+ npx @famgia/omnify generate --migrations-only
202
375
 
203
376
  # Validate schemas
204
- npx omnify validate
377
+ npx @famgia/omnify validate
378
+
379
+ # Show pending changes
380
+ npx @famgia/omnify diff
381
+
382
+ # Reset all generated files
383
+ npx @famgia/omnify reset
205
384
  ```
206
385
 
207
- ## Configuration
386
+ ## Examples
208
387
 
209
- ```typescript
210
- // omnify.config.ts
211
- import { defineConfig } from '@famgia/omnify';
388
+ ### System Table (Cache)
212
389
 
213
- export default defineConfig({
214
- schemasDir: './schemas',
215
- output: {
216
- laravel: {
217
- migrationsPath: './database/migrations/omnify',
218
- modelsPath: './app/Models',
219
- },
220
- },
221
- });
390
+ ```yaml
391
+ # schemas/system/AppCache.yaml
392
+ name: AppCache
393
+ options:
394
+ id: false
395
+ timestamps: false
396
+ hidden: true
397
+ tableName: cache
398
+ properties:
399
+ key:
400
+ type: String
401
+ length: 255
402
+ primary: true
403
+ value:
404
+ type: MediumText
405
+ expiration:
406
+ type: Int
407
+ ```
408
+
409
+ ### User with Authenticatable
410
+
411
+ ```yaml
412
+ # schemas/User.yaml
413
+ name: User
414
+ displayName:
415
+ ja: ユーザー
416
+ en: User
417
+ options:
418
+ softDelete: true
419
+ authenticatable: true
420
+ properties:
421
+ name:
422
+ type: String
423
+ displayName:
424
+ ja: 氏名
425
+ en: Full Name
426
+ email:
427
+ type: Email
428
+ unique: true
429
+ password:
430
+ type: Password
431
+ ```
432
+
433
+ ### Post with Relations
434
+
435
+ ```yaml
436
+ # schemas/Post.yaml
437
+ name: Post
438
+ displayName:
439
+ ja: 投稿
440
+ en: Post
441
+ options:
442
+ softDelete: true
443
+ properties:
444
+ title:
445
+ type: String
446
+ content:
447
+ type: LongText
448
+ status:
449
+ type: EnumRef
450
+ enum: PostStatus
451
+ default: draft
452
+ author:
453
+ type: Association
454
+ relation: ManyToOne
455
+ target: User
456
+ onDelete: CASCADE
457
+ tags:
458
+ type: Association
459
+ relation: ManyToMany
460
+ target: Tag
222
461
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famgia/omnify-laravel",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
4
4
  "description": "Laravel migration and TypeScript type generator for omnify-schema",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -25,9 +25,9 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@famgia/omnify-types": "0.0.57",
29
- "@famgia/omnify-core": "0.0.59",
30
- "@famgia/omnify-atlas": "0.0.53"
28
+ "@famgia/omnify-types": "0.0.59",
29
+ "@famgia/omnify-core": "0.0.61",
30
+ "@famgia/omnify-atlas": "0.0.55"
31
31
  },
32
32
  "scripts": {
33
33
  "build": "tsup",