@stonyx/orm 0.2.1-alpha.8 → 0.2.1-alpha.9

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/.claude/index.md CHANGED
@@ -65,6 +65,7 @@ stonyx-orm/
65
65
  │ ├── migrate.js # JSON DB mode migration (file <-> directory)
66
66
  │ ├── commands.js # CLI commands (db:migrate-*, etc.)
67
67
  │ ├── utils.js # Pluralize wrapper for dasherized names
68
+ │ ├── plural-registry.js # Plural name registry (populated at init, supports Model.pluralName overrides)
68
69
  │ ├── exports/
69
70
  │ │ └── db.js # Convenience re-export of DB instance
70
71
  │ └── mysql/
@@ -150,6 +151,7 @@ The ORM supports two storage modes, configured via `db.mode`:
150
151
  - Models: `{PascalCase}Model` (e.g., `AnimalModel`)
151
152
  - Serializers: `{PascalCase}Serializer` (e.g., `AnimalSerializer`)
152
153
  - Transforms: Original filename (e.g., `animal.js`)
154
+ - Plural names: Auto-pluralized by default (e.g., `animal` → `animals`). Override with `static pluralName` on the model class (e.g., `static pluralName = 'people'`). All call sites use `getPluralName()` from the plural registry, **not** `pluralize()` directly.
153
155
 
154
156
  ---
155
157
 
@@ -31,6 +31,23 @@ export default class AnimalModel extends Model {
31
31
  - Use `hasMany(modelName)` for one-to-many
32
32
  - Getters work as computed properties
33
33
  - Relationships auto-establish bidirectionally
34
+ - Override auto-pluralization with `static pluralName` (see [Overriding Plural Names](#overriding-plural-names))
35
+
36
+ ### Overriding Plural Names
37
+
38
+ By default, model names are auto-pluralized (e.g., `animal` → `animals`) for REST routes, JSON:API URLs, and DB table names. When auto-pluralization produces the wrong result, override it with `static pluralName`:
39
+
40
+ ```javascript
41
+ import { Model, attr } from '@stonyx/orm';
42
+
43
+ export default class PersonModel extends Model {
44
+ static pluralName = 'people';
45
+
46
+ name = attr('string');
47
+ }
48
+ ```
49
+
50
+ The override is picked up automatically during ORM initialization — no additional registration is needed. All internal call sites (REST routes, JSON:API type references, MySQL table names, foreign key references) use the overridden value.
34
51
 
35
52
  ## 2. Serializers (Data Transformation)
36
53
 
package/README.md CHANGED
@@ -109,6 +109,22 @@ export default class OwnerModel extends Model {
109
109
  }
110
110
  ```
111
111
 
112
+ ### Overriding Plural Names
113
+
114
+ By default, model names are auto-pluralized for REST routes, JSON:API URLs, and DB table names (e.g., `animal` → `animals`). When auto-pluralization produces the wrong result, override it with `static pluralName`:
115
+
116
+ ```js
117
+ import { Model, attr } from '@stonyx/orm';
118
+
119
+ export default class PersonModel extends Model {
120
+ static pluralName = 'people';
121
+
122
+ name = attr('string');
123
+ }
124
+ ```
125
+
126
+ The override is picked up automatically during ORM initialization. All routes, JSON:API type references, and MySQL table names will use the overridden value.
127
+
112
128
  ## Serializers
113
129
 
114
130
  Based on the following sample payload structure which represents a poorly structure third-party data source:
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "stonyx-async",
5
5
  "stonyx-module"
6
6
  ],
7
- "version": "0.2.1-alpha.8",
7
+ "version": "0.2.1-alpha.9",
8
8
  "description": "",
9
9
  "main": "src/main.js",
10
10
  "type": "module",