hekireki 0.9.2 → 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.
- package/README.md +185 -58
- package/dist/bin/activerecord.d.ts +1 -0
- package/dist/bin/activerecord.js +6 -0
- package/dist/bin/ajv.js +1 -1
- package/dist/bin/arktype.js +1 -1
- package/dist/bin/dbml.js +1 -1
- package/dist/bin/docs.js +1 -1
- package/dist/bin/drizzle.js +1 -1
- package/dist/bin/ecto.js +1 -1
- package/dist/bin/effect.js +1 -1
- package/dist/bin/eloquent.d.ts +1 -0
- package/dist/bin/eloquent.js +6 -0
- package/dist/bin/gorm.js +1 -1
- package/dist/bin/mermaid-er.js +1 -1
- package/dist/bin/sea-orm.js +1 -1
- package/dist/bin/sqlalchemy.js +1 -1
- package/dist/bin/typebox.js +1 -1
- package/dist/bin/valibot.js +1 -1
- package/dist/bin/zod.js +1 -1
- package/dist/{bin-C68-JfzS.js → bin-jiigoOO9.js} +614 -98
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Hekireki
|
|
4
4
|
|
|
5
|
-
**[Hekireki](https://www.npmjs.com/package/hekireki)** is a tool that generates validation schemas, ORM models, and ER diagrams from [Prisma](https://www.prisma.io/) schemas — supporting TypeScript, Python, Go, Rust, and
|
|
5
|
+
**[Hekireki](https://www.npmjs.com/package/hekireki)** is a tool that generates validation schemas, ORM models, and ER diagrams from [Prisma](https://www.prisma.io/) schemas — supporting TypeScript, Python, Go, Rust, Elixir, Ruby, and PHP.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
- 🐹 Automatically generates [GORM](https://gorm.io/) models (Go) — with struct tags, JSON tags, relationships, enums, composite keys, and index support
|
|
23
23
|
- 🦀 Automatically generates [Sea-ORM](https://www.sea-ql.org/SeaORM/) entities (Rust) — with `DeriveEntityModel`, relations, enums, serde support, and `rename_all`
|
|
24
24
|
- 🧪 Generates [Ecto](https://hexdocs.pm/ecto/Ecto.Schema.html) schemas (Elixir) — with associations (`belongs_to`, `has_many`, `has_one`), composite primary keys, `@type t` typespecs, array fields, `@@map`/`@map` support, and `@moduledoc`
|
|
25
|
+
- 💎 Generates [Active Record](https://guides.rubyonrails.org/active_record_basics.html) models (Ruby on Rails) — with associations (`belongs_to`, `has_one`, `has_many`, `has_and_belongs_to_many`), enums, composite primary keys, and `@@map`/`@map` support
|
|
26
|
+
- 🐘 Generates [Eloquent](https://laravel.com/docs/eloquent) models (Laravel / PHP) — with relations (`belongsTo`, `hasOne`, `hasMany`, `belongsToMany`), `$fillable`, `$casts`, string-backed PHP enums, timestamp constants, and `@@map`/`@map` support
|
|
25
27
|
|
|
26
28
|
### Diagrams & Documentation
|
|
27
29
|
|
|
@@ -43,10 +45,6 @@ datasource db {
|
|
|
43
45
|
provider = "sqlite"
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
generator Hekireki-ER {
|
|
47
|
-
provider = "hekireki-mermaid-er"
|
|
48
|
-
}
|
|
49
|
-
|
|
50
48
|
generator Hekireki-Zod {
|
|
51
49
|
provider = "hekireki-zod"
|
|
52
50
|
type = true
|
|
@@ -116,6 +114,21 @@ generator Hekireki-Ecto {
|
|
|
116
114
|
app = "DBSchema"
|
|
117
115
|
}
|
|
118
116
|
|
|
117
|
+
generator Hekireki-ActiveRecord {
|
|
118
|
+
provider = "hekireki-activerecord"
|
|
119
|
+
output = "./activerecord"
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
generator Hekireki-Eloquent {
|
|
123
|
+
provider = "hekireki-eloquent"
|
|
124
|
+
output = "./eloquent"
|
|
125
|
+
namespace = "App.Models"
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
generator Hekireki-ER {
|
|
129
|
+
provider = "hekireki-mermaid-er"
|
|
130
|
+
}
|
|
131
|
+
|
|
119
132
|
generator Hekireki-DBML {
|
|
120
133
|
provider = "hekireki-dbml"
|
|
121
134
|
output = "docs/schema.dbml"
|
|
@@ -530,43 +543,6 @@ export const postRelations = relations(post, ({ one }) => ({
|
|
|
530
543
|
}))
|
|
531
544
|
```
|
|
532
545
|
|
|
533
|
-
#### ID default functions
|
|
534
|
-
|
|
535
|
-
For Drizzle, Prisma `@default(...)` ID generators are emitted as client-side `$defaultFn` calls. Some require an extra package — install it in your project:
|
|
536
|
-
|
|
537
|
-
| Prisma default | Generated call | Package to install |
|
|
538
|
-
| ---------------------------------------- | --------------------- | ---------------------------------------------- |
|
|
539
|
-
| `@default(uuid())` / `@default(uuid(4))` | `crypto.randomUUID()` | — (Node/Web built-in) |
|
|
540
|
-
| `@default(cuid())` / `@default(cuid(1))` | `cuid()` | `npm i cuid` |
|
|
541
|
-
| `@default(cuid(2))` | `createId()` | `npm i @paralleldrive/cuid2` |
|
|
542
|
-
| `@default(nanoid())` | `nanoid()` | `npm i nanoid` (>= 5.0.9, or >= 3.3.8 for CJS) |
|
|
543
|
-
| `@default(ulid())` | `ulid()` | `npm i ulidx` |
|
|
544
|
-
|
|
545
|
-
Notes:
|
|
546
|
-
|
|
547
|
-
- **`cuid()` uses cuid v1**, which its author has deprecated in favor of cuid v2 ([npm `cuid`](https://www.npmjs.com/package/cuid)). It is emitted only when you explicitly write `@default(cuid())`; for new schemas prefer `@default(cuid(2))`.
|
|
548
|
-
- **`ulid()` maps to [`ulidx`](https://www.npmjs.com/package/ulidx)** (an actively maintained, crypto-backed drop-in for `ulid`).
|
|
549
|
-
- `@default(uuid(7))` is currently emitted as `crypto.randomUUID()` (UUID v4); native v7 support is planned.
|
|
550
|
-
- `@default(nanoid(n))` length argument is not yet applied — the default length is used.
|
|
551
|
-
- Inserts that bypass the ORM (raw SQL, bulk load) won't run `$defaultFn`; add a database-level `DEFAULT` for those paths.
|
|
552
|
-
|
|
553
|
-
### Mermaid
|
|
554
|
-
|
|
555
|
-
```mermaid
|
|
556
|
-
erDiagram
|
|
557
|
-
User ||--}| Post : "(id) - (userId)"
|
|
558
|
-
User {
|
|
559
|
-
string id PK "Primary key"
|
|
560
|
-
string name "Display name"
|
|
561
|
-
}
|
|
562
|
-
Post {
|
|
563
|
-
string id PK "Primary key"
|
|
564
|
-
string title "Article title"
|
|
565
|
-
string content "Body content (no length limit)"
|
|
566
|
-
string userId FK "Foreign key referencing User.id"
|
|
567
|
-
}
|
|
568
|
-
```
|
|
569
|
-
|
|
570
546
|
### Ecto
|
|
571
547
|
|
|
572
548
|
Each model is output as a separate `.ex` file (1 model = 1 file), following Elixir conventions.
|
|
@@ -616,11 +592,106 @@ defmodule DBSchema.Post do
|
|
|
616
592
|
end
|
|
617
593
|
```
|
|
618
594
|
|
|
595
|
+
### Active Record
|
|
596
|
+
|
|
597
|
+
Each model is output as a separate `.rb` file (1 model = 1 file), following Rails conventions. `class_name` and `foreign_key` are always spelled out so the generated associations never rely on Rails inflection. The generated code targets Rails 7.1+ (positional `enum` syntax, composite primary keys) and is continuously syntax-checked (`ruby -c`) and loaded against the real `activerecord` gem in CI.
|
|
598
|
+
|
|
599
|
+
```ruby
|
|
600
|
+
class User < ApplicationRecord
|
|
601
|
+
self.table_name = "user"
|
|
602
|
+
|
|
603
|
+
attribute :id, default: -> { SecureRandom.uuid }
|
|
604
|
+
|
|
605
|
+
has_many :posts, class_name: "Post", foreign_key: "userId"
|
|
606
|
+
end
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
```ruby
|
|
610
|
+
class Post < ApplicationRecord
|
|
611
|
+
self.table_name = "post"
|
|
612
|
+
|
|
613
|
+
attribute :id, default: -> { SecureRandom.uuid }
|
|
614
|
+
|
|
615
|
+
belongs_to :user, class_name: "User", foreign_key: "userId"
|
|
616
|
+
end
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### Eloquent
|
|
620
|
+
|
|
621
|
+
Each model is output as a separate `.php` file (1 model = 1 file, PSR-4 friendly). Prisma enums become string-backed PHP enums with matching `$casts` entries. The generated code targets PHP 8.1+ (backed enums) and is continuously syntax-checked (`php -l`) and loaded against the real `illuminate/database` package in CI. Composite primary keys are emitted as `protected $primaryKey = null;` because Eloquent has no native composite key support.
|
|
622
|
+
|
|
623
|
+
```php
|
|
624
|
+
<?php
|
|
625
|
+
|
|
626
|
+
namespace App\Models;
|
|
627
|
+
|
|
628
|
+
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids;
|
|
629
|
+
use Illuminate\Database\Eloquent\Model;
|
|
630
|
+
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
631
|
+
|
|
632
|
+
class User extends Model
|
|
633
|
+
{
|
|
634
|
+
use HasVersion4Uuids;
|
|
635
|
+
|
|
636
|
+
protected $table = 'user';
|
|
637
|
+
|
|
638
|
+
protected $keyType = 'string';
|
|
639
|
+
|
|
640
|
+
public $incrementing = false;
|
|
641
|
+
|
|
642
|
+
public $timestamps = false;
|
|
643
|
+
|
|
644
|
+
protected $fillable = [
|
|
645
|
+
'name',
|
|
646
|
+
];
|
|
647
|
+
|
|
648
|
+
public function posts(): HasMany
|
|
649
|
+
{
|
|
650
|
+
return $this->hasMany(Post::class, 'userId');
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
```php
|
|
656
|
+
<?php
|
|
657
|
+
|
|
658
|
+
namespace App\Models;
|
|
659
|
+
|
|
660
|
+
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids;
|
|
661
|
+
use Illuminate\Database\Eloquent\Model;
|
|
662
|
+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
663
|
+
|
|
664
|
+
class Post extends Model
|
|
665
|
+
{
|
|
666
|
+
use HasVersion4Uuids;
|
|
667
|
+
|
|
668
|
+
protected $table = 'post';
|
|
669
|
+
|
|
670
|
+
protected $keyType = 'string';
|
|
671
|
+
|
|
672
|
+
public $incrementing = false;
|
|
673
|
+
|
|
674
|
+
public $timestamps = false;
|
|
675
|
+
|
|
676
|
+
protected $fillable = [
|
|
677
|
+
'title',
|
|
678
|
+
'content',
|
|
679
|
+
'userId',
|
|
680
|
+
];
|
|
681
|
+
|
|
682
|
+
public function user(): BelongsTo
|
|
683
|
+
{
|
|
684
|
+
return $this->belongsTo(User::class, 'userId');
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
```
|
|
688
|
+
|
|
619
689
|
### SQLAlchemy
|
|
620
690
|
|
|
621
691
|
```python
|
|
622
692
|
from sqlalchemy import ForeignKey
|
|
623
693
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
694
|
+
import uuid as uuid_mod
|
|
624
695
|
|
|
625
696
|
|
|
626
697
|
class Base(DeclarativeBase):
|
|
@@ -630,16 +701,15 @@ class Base(DeclarativeBase):
|
|
|
630
701
|
class User(Base):
|
|
631
702
|
__tablename__ = "user"
|
|
632
703
|
|
|
633
|
-
id: Mapped[str] = mapped_column(primary_key=True)
|
|
704
|
+
id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
|
|
634
705
|
name: Mapped[str]
|
|
635
706
|
|
|
636
707
|
posts: Mapped[list["Post"]] = relationship(back_populates="user")
|
|
637
708
|
|
|
638
|
-
|
|
639
709
|
class Post(Base):
|
|
640
710
|
__tablename__ = "post"
|
|
641
711
|
|
|
642
|
-
id: Mapped[str] = mapped_column(primary_key=True)
|
|
712
|
+
id: Mapped[str] = mapped_column(primary_key=True, default=lambda: str(uuid_mod.uuid4()))
|
|
643
713
|
title: Mapped[str]
|
|
644
714
|
content: Mapped[str]
|
|
645
715
|
user_id: Mapped[str] = mapped_column(ForeignKey("user.id"))
|
|
@@ -652,18 +722,37 @@ class Post(Base):
|
|
|
652
722
|
```go
|
|
653
723
|
package model
|
|
654
724
|
|
|
725
|
+
import (
|
|
726
|
+
"github.com/google/uuid"
|
|
727
|
+
"gorm.io/gorm"
|
|
728
|
+
)
|
|
729
|
+
|
|
655
730
|
type User struct {
|
|
656
|
-
ID
|
|
731
|
+
ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
|
|
657
732
|
Name string `gorm:"column:name;not null" json:"name"`
|
|
658
733
|
Posts []Post `gorm:"foreignKey:UserID"`
|
|
659
734
|
}
|
|
660
735
|
|
|
736
|
+
func (m *User) BeforeCreate(_ *gorm.DB) error {
|
|
737
|
+
if m.ID == "" {
|
|
738
|
+
m.ID = uuid.NewString()
|
|
739
|
+
}
|
|
740
|
+
return nil
|
|
741
|
+
}
|
|
742
|
+
|
|
661
743
|
type Post struct {
|
|
662
|
-
ID
|
|
663
|
-
Title
|
|
744
|
+
ID string `gorm:"column:id;primaryKey;type:char(36)" json:"id"`
|
|
745
|
+
Title string `gorm:"column:title;not null" json:"title"`
|
|
664
746
|
Content string `gorm:"column:content;not null" json:"content"`
|
|
665
|
-
UserID
|
|
666
|
-
User
|
|
747
|
+
UserID string `gorm:"column:user_id;not null" json:"user_id"`
|
|
748
|
+
User User
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
func (m *Post) BeforeCreate(_ *gorm.DB) error {
|
|
752
|
+
if m.ID == "" {
|
|
753
|
+
m.ID = uuid.NewString()
|
|
754
|
+
}
|
|
755
|
+
return nil
|
|
667
756
|
}
|
|
668
757
|
```
|
|
669
758
|
|
|
@@ -675,9 +764,10 @@ Each model is output as a separate `.rs` file with `mod.rs` and `prelude.rs`, fo
|
|
|
675
764
|
|
|
676
765
|
```rust
|
|
677
766
|
use sea_orm::entity::prelude::*;
|
|
767
|
+
use sea_orm::Set;
|
|
678
768
|
use serde::{Deserialize, Serialize};
|
|
679
769
|
|
|
680
|
-
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
|
770
|
+
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
|
|
681
771
|
#[serde(rename_all = "camelCase")]
|
|
682
772
|
#[sea_orm(table_name = "user")]
|
|
683
773
|
pub struct Model {
|
|
@@ -698,7 +788,31 @@ impl Related<super::post::Entity> for Entity {
|
|
|
698
788
|
}
|
|
699
789
|
}
|
|
700
790
|
|
|
701
|
-
impl ActiveModelBehavior for ActiveModel {
|
|
791
|
+
impl ActiveModelBehavior for ActiveModel {
|
|
792
|
+
fn new() -> Self {
|
|
793
|
+
Self {
|
|
794
|
+
id: Set(uuid::Uuid::new_v4().to_string()),
|
|
795
|
+
..ActiveModelTrait::default()
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
### Mermaid
|
|
802
|
+
|
|
803
|
+
```mermaid
|
|
804
|
+
erDiagram
|
|
805
|
+
User ||--}| Post : "(id) - (userId)"
|
|
806
|
+
User {
|
|
807
|
+
string id PK "Primary key"
|
|
808
|
+
string name "Display name"
|
|
809
|
+
}
|
|
810
|
+
Post {
|
|
811
|
+
string id PK "Primary key"
|
|
812
|
+
string title "Article title"
|
|
813
|
+
string content "Body content (no length limit)"
|
|
814
|
+
string userId FK "Foreign key referencing User.id"
|
|
815
|
+
}
|
|
702
816
|
```
|
|
703
817
|
|
|
704
818
|
### DBML
|
|
@@ -826,12 +940,6 @@ generator Hekireki-Drizzle {
|
|
|
826
940
|
output = "./drizzle" // Output path (default: ./drizzle/schema.ts)
|
|
827
941
|
}
|
|
828
942
|
|
|
829
|
-
// Mermaid ER Generator
|
|
830
|
-
generator Hekireki-ER {
|
|
831
|
-
provider = "hekireki-mermaid-er"
|
|
832
|
-
output = "./mermaid-er" // Output path (default: ./mermaid-er/ER.md)
|
|
833
|
-
}
|
|
834
|
-
|
|
835
943
|
// SQLAlchemy Generator (Python)
|
|
836
944
|
generator Hekireki-SQLAlchemy {
|
|
837
945
|
provider = "hekireki-sqlalchemy"
|
|
@@ -859,6 +967,25 @@ generator Hekireki-Ecto {
|
|
|
859
967
|
app = "MyApp" // App name (default: MyApp)
|
|
860
968
|
}
|
|
861
969
|
|
|
970
|
+
// Active Record Generator (Ruby on Rails)
|
|
971
|
+
generator Hekireki-ActiveRecord {
|
|
972
|
+
provider = "hekireki-activerecord"
|
|
973
|
+
output = "./activerecord" // Output directory for .rb files
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// Eloquent Generator (Laravel / PHP)
|
|
977
|
+
generator Hekireki-Eloquent {
|
|
978
|
+
provider = "hekireki-eloquent"
|
|
979
|
+
output = "./eloquent" // Output directory for .php files
|
|
980
|
+
namespace = "App.Models" // PHP namespace, "." becomes "\" (default: App\Models)
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// Mermaid ER Generator
|
|
984
|
+
generator Hekireki-ER {
|
|
985
|
+
provider = "hekireki-mermaid-er"
|
|
986
|
+
output = "./mermaid-er" // Output path (default: ./mermaid-er/ER.md)
|
|
987
|
+
}
|
|
988
|
+
|
|
862
989
|
// DBML Generator (output extension determines format: .dbml or .png)
|
|
863
990
|
generator Hekireki-DBML {
|
|
864
991
|
provider = "hekireki-dbml"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/bin/ajv.js
CHANGED
package/dist/bin/arktype.js
CHANGED
package/dist/bin/dbml.js
CHANGED
package/dist/bin/docs.js
CHANGED
package/dist/bin/drizzle.js
CHANGED
package/dist/bin/ecto.js
CHANGED
package/dist/bin/effect.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/bin/gorm.js
CHANGED
package/dist/bin/mermaid-er.js
CHANGED
package/dist/bin/sea-orm.js
CHANGED
package/dist/bin/sqlalchemy.js
CHANGED
package/dist/bin/typebox.js
CHANGED
package/dist/bin/valibot.js
CHANGED
package/dist/bin/zod.js
CHANGED