@omnifyjp/ts 5.9.15 → 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/dist/php/model-generator.js +33 -2
- package/dist/types.d.ts +6 -1
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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.
|
package/dist/types.d.ts
CHANGED
|
@@ -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;
|