@omnifyjp/omnify 5.9.16 → 5.9.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/omnify",
3
- "version": "5.9.16",
3
+ "version": "5.9.17",
4
4
  "description": "Schema-driven code generation for Laravel, TypeScript, and SQL",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "zod": "^3.24.0"
37
37
  },
38
38
  "optionalDependencies": {
39
- "@omnifyjp/omnify-darwin-arm64": "5.9.16",
40
- "@omnifyjp/omnify-darwin-x64": "5.9.16",
41
- "@omnifyjp/omnify-linux-x64": "5.9.16",
42
- "@omnifyjp/omnify-linux-arm64": "5.9.16",
43
- "@omnifyjp/omnify-win32-x64": "5.9.16"
39
+ "@omnifyjp/omnify-darwin-arm64": "5.9.17",
40
+ "@omnifyjp/omnify-darwin-x64": "5.9.17",
41
+ "@omnifyjp/omnify-linux-x64": "5.9.17",
42
+ "@omnifyjp/omnify-linux-arm64": "5.9.17",
43
+ "@omnifyjp/omnify-win32-x64": "5.9.17"
44
44
  }
45
45
  }
@@ -92,7 +92,28 @@ function generateBaseModel(name, schema, reader, config) {
92
92
  : '';
93
93
  const isAuthenticatable = options['authenticatable'] ?? false;
94
94
  const hasSoftDelete = options.softDelete ?? false;
95
- const hasTimestamps = options.timestamps ?? false;
95
+ // `timestamps` is a bool or a map naming the columns individually. Eloquent
96
+ // has no half-way switch, so a schema carrying only one of the two keeps
97
+ // $timestamps = true and nulls the constant for the absent column — otherwise
98
+ // Eloquent writes a column the table does not have and every insert dies with
99
+ // "Unknown column 'created_at'" (omnify-go#143).
100
+ const timestampsOption = options.timestamps ?? false;
101
+ const resolveTimestampColumn = (camel, snake) => {
102
+ if (typeof timestampsOption === 'boolean')
103
+ return timestampsOption;
104
+ if (timestampsOption && typeof timestampsOption === 'object') {
105
+ const map = timestampsOption;
106
+ if (typeof map[camel] === 'boolean')
107
+ return map[camel];
108
+ if (typeof map[snake] === 'boolean')
109
+ return map[snake];
110
+ return false;
111
+ }
112
+ return false;
113
+ };
114
+ const hasCreatedAt = resolveTimestampColumn('createdAt', 'created_at');
115
+ const hasUpdatedAt = resolveTimestampColumn('updatedAt', 'updated_at');
116
+ const hasTimestamps = hasCreatedAt || hasUpdatedAt;
96
117
  // NodeTrait is added to the user-editable Model, not BaseModel
97
118
  const hasNestedSet = false;
98
119
  const nestedSetParentColumn = null;
@@ -199,7 +220,17 @@ ${keyTypeSection}
199
220
  /**
200
221
  * Indicates if the model should be timestamped.
201
222
  */
202
- public $timestamps = ${hasTimestamps ? 'true' : 'false'};
223
+ public $timestamps = ${hasTimestamps ? 'true' : 'false'};${hasTimestamps && !hasCreatedAt ? `
224
+
225
+ /**
226
+ * This table has no created_at column.
227
+ */
228
+ const CREATED_AT = null;` : ''}${hasTimestamps && !hasUpdatedAt ? `
229
+
230
+ /**
231
+ * This table has no updated_at column.
232
+ */
233
+ const UPDATED_AT = null;` : ''}
203
234
 
204
235
  /**
205
236
  * Localized display names for this model.
@@ -174,7 +174,12 @@ export interface ServiceOptions {
174
174
  /** Schema options. */
175
175
  export interface SchemaOptions {
176
176
  readonly id?: boolean | string;
177
- readonly timestamps?: boolean;
177
+ readonly timestamps?: boolean | {
178
+ createdAt?: boolean;
179
+ updatedAt?: boolean;
180
+ created_at?: boolean;
181
+ updated_at?: boolean;
182
+ };
178
183
  readonly softDelete?: boolean;
179
184
  readonly hidden?: boolean;
180
185
  readonly nestedSet?: boolean;