@famgia/omnify 1.0.0 → 1.0.2
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/README.md +416 -36
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,100 +2,480 @@
|
|
|
2
2
|
|
|
3
3
|
Schema-driven database migration system with TypeScript types and Laravel migrations.
|
|
4
4
|
|
|
5
|
+
Define your database schema in YAML, generate Laravel migrations and TypeScript types automatically.
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
10
|
+
# Main package (for programmatic usage)
|
|
8
11
|
npm install @famgia/omnify
|
|
9
|
-
```
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
+
# CLI tool (for command line usage)
|
|
13
14
|
npm install -g @famgia/omnify-cli
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
## Quick Start
|
|
17
18
|
|
|
18
|
-
### 1.
|
|
19
|
+
### 1. Initialize project
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
omnify init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This creates:
|
|
26
|
+
- `omnify.config.ts` - Configuration file
|
|
27
|
+
- `schemas/` - Directory for schema files
|
|
28
|
+
- `schemas/user.yaml` - Example schema
|
|
29
|
+
|
|
30
|
+
### 2. Configure
|
|
31
|
+
|
|
32
|
+
Edit `omnify.config.ts`:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { defineConfig } from '@famgia/omnify-cli';
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
// Schema files location
|
|
39
|
+
schemaDir: './schemas',
|
|
40
|
+
|
|
41
|
+
// Laravel migrations output
|
|
42
|
+
migrations: {
|
|
43
|
+
outputDir: './database/migrations',
|
|
44
|
+
connection: 'mysql', // mysql | pgsql | sqlite
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// TypeScript types output
|
|
48
|
+
typescript: {
|
|
49
|
+
outputDir: './resources/js/types',
|
|
50
|
+
// Or for React/Vue frontend:
|
|
51
|
+
// outputDir: './frontend/src/types',
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// Atlas HCL output (optional)
|
|
55
|
+
atlas: {
|
|
56
|
+
outputDir: './atlas',
|
|
57
|
+
lockFile: './atlas/omnify.lock',
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
// Plugins (optional)
|
|
61
|
+
plugins: [
|
|
62
|
+
// '@famgia/omnify-japan', // Japan-specific types
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 3. Create schemas
|
|
19
68
|
|
|
20
69
|
```yaml
|
|
21
70
|
# schemas/user.yaml
|
|
22
71
|
name: User
|
|
72
|
+
displayName: User Account
|
|
73
|
+
group: auth
|
|
74
|
+
|
|
23
75
|
properties:
|
|
24
76
|
email:
|
|
25
77
|
type: String
|
|
26
78
|
unique: true
|
|
27
79
|
name:
|
|
28
80
|
type: String
|
|
29
|
-
|
|
30
|
-
type:
|
|
81
|
+
password:
|
|
82
|
+
type: String
|
|
83
|
+
role:
|
|
84
|
+
type: Enum
|
|
85
|
+
values: [admin, user, guest]
|
|
86
|
+
default: user
|
|
87
|
+
avatar:
|
|
88
|
+
type: String
|
|
89
|
+
nullable: true
|
|
90
|
+
email_verified_at:
|
|
91
|
+
type: DateTime
|
|
31
92
|
nullable: true
|
|
93
|
+
|
|
94
|
+
options:
|
|
95
|
+
timestamps: true # adds created_at, updated_at
|
|
96
|
+
softDelete: true # adds deleted_at
|
|
97
|
+
primaryKeyType: Int # Int | BigInt | Uuid
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4. Generate code
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Validate schemas
|
|
104
|
+
omnify validate
|
|
105
|
+
|
|
106
|
+
# Preview changes (dry run)
|
|
107
|
+
omnify diff
|
|
108
|
+
|
|
109
|
+
# Generate migrations and types
|
|
110
|
+
omnify generate
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Configuration Reference
|
|
114
|
+
|
|
115
|
+
### Full Config Options
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { defineConfig } from '@famgia/omnify-cli';
|
|
119
|
+
import { japanPlugin } from '@famgia/omnify-japan';
|
|
120
|
+
|
|
121
|
+
export default defineConfig({
|
|
122
|
+
// Required: Schema files directory
|
|
123
|
+
schemaDir: './schemas',
|
|
124
|
+
|
|
125
|
+
// Laravel migration settings
|
|
126
|
+
migrations: {
|
|
127
|
+
outputDir: './database/migrations',
|
|
128
|
+
connection: 'mysql', // Database driver
|
|
129
|
+
tablePrefix: '', // Prefix for table names
|
|
130
|
+
generateDropMigrations: false,
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
// TypeScript generation settings
|
|
134
|
+
typescript: {
|
|
135
|
+
outputDir: './types',
|
|
136
|
+
generateEnums: true, // Generate enum types
|
|
137
|
+
generateInterfaces: true, // Generate model interfaces
|
|
138
|
+
exportStyle: 'named', // 'named' | 'default'
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
// Atlas integration settings
|
|
142
|
+
atlas: {
|
|
143
|
+
outputDir: './atlas',
|
|
144
|
+
lockFile: './atlas/omnify.lock',
|
|
145
|
+
dialect: 'mysql', // mysql | postgres | sqlite
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
// Plugins for custom types
|
|
149
|
+
plugins: [
|
|
150
|
+
japanPlugin,
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Schema Format
|
|
156
|
+
|
|
157
|
+
### Basic Schema
|
|
158
|
+
|
|
159
|
+
```yaml
|
|
160
|
+
name: Post # Required: Schema name (PascalCase)
|
|
161
|
+
displayName: Blog Post # Optional: Human-readable name
|
|
162
|
+
group: content # Optional: Group for organization
|
|
163
|
+
|
|
164
|
+
properties:
|
|
165
|
+
title:
|
|
166
|
+
type: String
|
|
167
|
+
content:
|
|
168
|
+
type: Text
|
|
169
|
+
published:
|
|
170
|
+
type: Boolean
|
|
171
|
+
default: false
|
|
172
|
+
|
|
32
173
|
options:
|
|
33
174
|
timestamps: true
|
|
34
|
-
softDelete: true
|
|
35
175
|
```
|
|
36
176
|
|
|
37
|
-
###
|
|
177
|
+
### Property Types
|
|
178
|
+
|
|
179
|
+
| Type | Laravel | TypeScript | Description |
|
|
180
|
+
|------|---------|------------|-------------|
|
|
181
|
+
| `String` | `string(255)` | `string` | Short text |
|
|
182
|
+
| `Text` | `text` | `string` | Long text |
|
|
183
|
+
| `Int` | `integer` | `number` | Integer |
|
|
184
|
+
| `BigInt` | `bigInteger` | `number` | Large integer |
|
|
185
|
+
| `Float` | `float` | `number` | Floating point |
|
|
186
|
+
| `Decimal` | `decimal(10,2)` | `number` | Precise decimal |
|
|
187
|
+
| `Boolean` | `boolean` | `boolean` | True/false |
|
|
188
|
+
| `Date` | `date` | `string` | Date only |
|
|
189
|
+
| `DateTime` | `dateTime` | `string` | Date and time |
|
|
190
|
+
| `Timestamp` | `timestamp` | `string` | Unix timestamp |
|
|
191
|
+
| `Time` | `time` | `string` | Time only |
|
|
192
|
+
| `Json` | `json` | `Record<string, unknown>` | JSON data |
|
|
193
|
+
| `Uuid` | `uuid` | `string` | UUID |
|
|
194
|
+
| `Enum` | `enum` | `union type` | Enumeration |
|
|
195
|
+
|
|
196
|
+
### Property Modifiers
|
|
197
|
+
|
|
198
|
+
```yaml
|
|
199
|
+
properties:
|
|
200
|
+
email:
|
|
201
|
+
type: String
|
|
202
|
+
unique: true # Unique constraint
|
|
203
|
+
nullable: true # Allow NULL
|
|
204
|
+
default: 'default@example.com' # Default value
|
|
205
|
+
length: 100 # String length (default: 255)
|
|
206
|
+
|
|
207
|
+
price:
|
|
208
|
+
type: Decimal
|
|
209
|
+
precision: 10 # Total digits
|
|
210
|
+
scale: 2 # Decimal places
|
|
211
|
+
|
|
212
|
+
status:
|
|
213
|
+
type: Enum
|
|
214
|
+
values: [draft, published, archived]
|
|
215
|
+
default: draft
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Associations (Relationships)
|
|
219
|
+
|
|
220
|
+
```yaml
|
|
221
|
+
# schemas/post.yaml
|
|
222
|
+
name: Post
|
|
223
|
+
properties:
|
|
224
|
+
title:
|
|
225
|
+
type: String
|
|
226
|
+
content:
|
|
227
|
+
type: Text
|
|
228
|
+
|
|
229
|
+
# BelongsTo relationship
|
|
230
|
+
author:
|
|
231
|
+
type: Association
|
|
232
|
+
relation: ManyToOne
|
|
233
|
+
target: User
|
|
234
|
+
mappedBy: posts
|
|
235
|
+
onDelete: CASCADE
|
|
236
|
+
|
|
237
|
+
# HasMany relationship
|
|
238
|
+
comments:
|
|
239
|
+
type: Association
|
|
240
|
+
relation: OneToMany
|
|
241
|
+
target: Comment
|
|
242
|
+
inversedBy: post
|
|
243
|
+
|
|
244
|
+
# ManyToMany relationship
|
|
245
|
+
tags:
|
|
246
|
+
type: Association
|
|
247
|
+
relation: ManyToMany
|
|
248
|
+
target: Tag
|
|
249
|
+
inversedBy: posts
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Enum Schema
|
|
253
|
+
|
|
254
|
+
```yaml
|
|
255
|
+
# schemas/status.yaml
|
|
256
|
+
name: OrderStatus
|
|
257
|
+
kind: enum
|
|
258
|
+
values:
|
|
259
|
+
- pending
|
|
260
|
+
- processing
|
|
261
|
+
- shipped
|
|
262
|
+
- delivered
|
|
263
|
+
- cancelled
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Schema Options
|
|
267
|
+
|
|
268
|
+
```yaml
|
|
269
|
+
options:
|
|
270
|
+
timestamps: true # Add created_at, updated_at
|
|
271
|
+
softDelete: true # Add deleted_at for soft deletes
|
|
272
|
+
primaryKeyType: Int # Int | BigInt | Uuid
|
|
273
|
+
table: custom_table # Custom table name (default: snake_case of name)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## CLI Commands
|
|
277
|
+
|
|
278
|
+
### `omnify init`
|
|
279
|
+
|
|
280
|
+
Initialize a new project with config and example schemas.
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
omnify init
|
|
284
|
+
omnify init --force # Overwrite existing files
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### `omnify validate`
|
|
288
|
+
|
|
289
|
+
Validate all schema files for errors.
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
omnify validate
|
|
293
|
+
omnify validate --schema user # Validate specific schema
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### `omnify diff`
|
|
297
|
+
|
|
298
|
+
Preview pending changes without generating files.
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
omnify diff
|
|
302
|
+
omnify diff --verbose # Show detailed changes
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### `omnify generate`
|
|
306
|
+
|
|
307
|
+
Generate Laravel migrations and TypeScript types.
|
|
38
308
|
|
|
39
309
|
```bash
|
|
40
310
|
omnify generate
|
|
311
|
+
omnify generate --migrations-only # Only migrations
|
|
312
|
+
omnify generate --types-only # Only TypeScript
|
|
313
|
+
omnify generate --dry-run # Preview without writing
|
|
41
314
|
```
|
|
42
315
|
|
|
43
|
-
|
|
316
|
+
## Programmatic API
|
|
44
317
|
|
|
45
318
|
```typescript
|
|
46
319
|
import {
|
|
47
320
|
loadSchemas,
|
|
48
321
|
validateSchemas,
|
|
49
|
-
|
|
322
|
+
generateMigrations,
|
|
50
323
|
generateTypeScript,
|
|
324
|
+
createOmnify,
|
|
51
325
|
} from '@famgia/omnify';
|
|
52
326
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
const
|
|
327
|
+
// Simple usage
|
|
328
|
+
async function generate() {
|
|
329
|
+
const schemas = await loadSchemas('./schemas');
|
|
330
|
+
const validation = validateSchemas(schemas);
|
|
331
|
+
|
|
332
|
+
if (!validation.valid) {
|
|
333
|
+
console.error('Validation errors:', validation.errors);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
56
336
|
|
|
57
|
-
if (result.valid) {
|
|
58
337
|
// Generate Laravel migrations
|
|
59
|
-
const
|
|
338
|
+
const migrations = generateMigrations(schemas);
|
|
60
339
|
|
|
61
340
|
// Generate TypeScript types
|
|
62
341
|
const types = generateTypeScript(schemas);
|
|
63
342
|
}
|
|
343
|
+
|
|
344
|
+
// Advanced usage with Omnify class
|
|
345
|
+
async function advancedGenerate() {
|
|
346
|
+
const omnify = createOmnify({
|
|
347
|
+
schemaDir: './schemas',
|
|
348
|
+
plugins: [],
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
await omnify.initialize();
|
|
352
|
+
|
|
353
|
+
const schemas = omnify.getSchemas();
|
|
354
|
+
const metadata = omnify.introspectSchemas();
|
|
355
|
+
|
|
356
|
+
// Access relationship graph
|
|
357
|
+
const graph = omnify.getRelationshipGraph();
|
|
358
|
+
const order = omnify.getTopologicalOrder();
|
|
359
|
+
}
|
|
64
360
|
```
|
|
65
361
|
|
|
66
|
-
##
|
|
362
|
+
## Generated Output Examples
|
|
67
363
|
|
|
68
|
-
|
|
364
|
+
### Laravel Migration
|
|
69
365
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
366
|
+
```php
|
|
367
|
+
<?php
|
|
368
|
+
|
|
369
|
+
use Illuminate\Database\Migrations\Migration;
|
|
370
|
+
use Illuminate\Database\Schema\Blueprint;
|
|
371
|
+
use Illuminate\Support\Facades\Schema;
|
|
372
|
+
|
|
373
|
+
return new class extends Migration
|
|
374
|
+
{
|
|
375
|
+
public function up(): void
|
|
376
|
+
{
|
|
377
|
+
Schema::create('users', function (Blueprint $table) {
|
|
378
|
+
$table->id();
|
|
379
|
+
$table->string('email')->unique();
|
|
380
|
+
$table->string('name');
|
|
381
|
+
$table->string('password');
|
|
382
|
+
$table->enum('role', ['admin', 'user', 'guest'])->default('user');
|
|
383
|
+
$table->string('avatar')->nullable();
|
|
384
|
+
$table->timestamp('email_verified_at')->nullable();
|
|
385
|
+
$table->timestamps();
|
|
386
|
+
$table->softDeletes();
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
public function down(): void
|
|
391
|
+
{
|
|
392
|
+
Schema::dropIfExists('users');
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### TypeScript Types
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
// types/models.ts
|
|
401
|
+
export interface User {
|
|
402
|
+
id: number;
|
|
403
|
+
email: string;
|
|
404
|
+
name: string;
|
|
405
|
+
password: string;
|
|
406
|
+
role: UserRole;
|
|
407
|
+
avatar: string | null;
|
|
408
|
+
email_verified_at: string | null;
|
|
409
|
+
created_at: string;
|
|
410
|
+
updated_at: string;
|
|
411
|
+
deleted_at: string | null;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export type UserRole = 'admin' | 'user' | 'guest';
|
|
415
|
+
|
|
416
|
+
export interface Post {
|
|
417
|
+
id: number;
|
|
418
|
+
title: string;
|
|
419
|
+
content: string;
|
|
420
|
+
author_id: number;
|
|
421
|
+
created_at: string;
|
|
422
|
+
updated_at: string;
|
|
423
|
+
}
|
|
424
|
+
```
|
|
78
425
|
|
|
79
|
-
##
|
|
426
|
+
## Plugins
|
|
80
427
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
428
|
+
### Japan Types Plugin
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
npm install @famgia/omnify-japan
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
// omnify.config.ts
|
|
436
|
+
import { defineConfig } from '@famgia/omnify-cli';
|
|
437
|
+
import { japanPlugin } from '@famgia/omnify-japan';
|
|
438
|
+
|
|
439
|
+
export default defineConfig({
|
|
440
|
+
schemaDir: './schemas',
|
|
441
|
+
plugins: [japanPlugin],
|
|
442
|
+
});
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
```yaml
|
|
446
|
+
# schemas/customer.yaml
|
|
447
|
+
name: Customer
|
|
448
|
+
properties:
|
|
449
|
+
postal_code:
|
|
450
|
+
type: JapanPostalCode # 〒123-4567
|
|
451
|
+
phone:
|
|
452
|
+
type: JapanPhone # 03-1234-5678
|
|
453
|
+
prefecture:
|
|
454
|
+
type: JapanPrefecture # 東京都, 大阪府, etc.
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## Packages
|
|
458
|
+
|
|
459
|
+
| Package | Description |
|
|
460
|
+
|---------|-------------|
|
|
461
|
+
| [@famgia/omnify](https://www.npmjs.com/package/@famgia/omnify) | Main entry point |
|
|
462
|
+
| [@famgia/omnify-cli](https://www.npmjs.com/package/@famgia/omnify-cli) | CLI tool |
|
|
463
|
+
| [@famgia/omnify-core](https://www.npmjs.com/package/@famgia/omnify-core) | Core engine |
|
|
464
|
+
| [@famgia/omnify-types](https://www.npmjs.com/package/@famgia/omnify-types) | Type definitions |
|
|
465
|
+
| [@famgia/omnify-laravel](https://www.npmjs.com/package/@famgia/omnify-laravel) | Laravel generator |
|
|
466
|
+
| [@famgia/omnify-atlas](https://www.npmjs.com/package/@famgia/omnify-atlas) | Atlas integration |
|
|
467
|
+
| [@famgia/omnify-japan](https://www.npmjs.com/package/@famgia/omnify-japan) | Japan types |
|
|
88
468
|
|
|
89
|
-
## Migration from @famgia/omnify (
|
|
469
|
+
## Migration from @famgia/omnify (v0.12.x)
|
|
90
470
|
|
|
91
|
-
|
|
471
|
+
The old `@famgia/omnify` package has been renamed to `@famgia/omnify-old`:
|
|
92
472
|
|
|
93
473
|
```bash
|
|
94
474
|
npm uninstall @famgia/omnify
|
|
95
475
|
npm install @famgia/omnify-old
|
|
96
476
|
```
|
|
97
477
|
|
|
98
|
-
The old package provided
|
|
478
|
+
The old package provided React/Antd form helpers. The new `@famgia/omnify` is a complete rewrite focused on schema-driven code generation.
|
|
99
479
|
|
|
100
480
|
## License
|
|
101
481
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@famgia/omnify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Schema-driven database migration system with TypeScript types and Laravel migrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@famgia/omnify-core": "0.0.
|
|
22
|
-
"@famgia/omnify-
|
|
23
|
-
"@famgia/omnify-
|
|
24
|
-
"@famgia/omnify-atlas": "0.0.
|
|
21
|
+
"@famgia/omnify-core": "0.0.4",
|
|
22
|
+
"@famgia/omnify-laravel": "0.0.4",
|
|
23
|
+
"@famgia/omnify-types": "0.0.4",
|
|
24
|
+
"@famgia/omnify-atlas": "0.0.4"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"omnify",
|