@omnifyjp/omnify 3.2.2 → 3.2.3
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": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
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": "3.2.
|
|
40
|
-
"@omnifyjp/omnify-darwin-x64": "3.2.
|
|
41
|
-
"@omnifyjp/omnify-linux-x64": "3.2.
|
|
42
|
-
"@omnifyjp/omnify-linux-arm64": "3.2.
|
|
43
|
-
"@omnifyjp/omnify-win32-x64": "3.2.
|
|
39
|
+
"@omnifyjp/omnify-darwin-arm64": "3.2.3",
|
|
40
|
+
"@omnifyjp/omnify-darwin-x64": "3.2.3",
|
|
41
|
+
"@omnifyjp/omnify-linux-x64": "3.2.3",
|
|
42
|
+
"@omnifyjp/omnify-linux-arm64": "3.2.3",
|
|
43
|
+
"@omnifyjp/omnify-win32-x64": "3.2.3"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -74,6 +74,7 @@ function generateBaseModel(name, schema, reader, config) {
|
|
|
74
74
|
const relations = buildRelations(name, properties, propertyOrder, modelNamespace, reader);
|
|
75
75
|
const accessors = buildAccessors(expandedProperties);
|
|
76
76
|
const fileAccessors = hasFiles ? buildFileAccessors(properties, propertyOrder, modelNamespace) : '';
|
|
77
|
+
const auditSection = buildAuditSection(options, reader, modelNamespace);
|
|
77
78
|
const nestedSetMethod = buildNestedSetParentIdMethod(nestedSetParentColumn);
|
|
78
79
|
let keyTypeSection = '';
|
|
79
80
|
if (idType === 'Uuid' || idType === 'Ulid' || idType === 'String') {
|
|
@@ -171,7 +172,7 @@ ${appends} ];
|
|
|
171
172
|
return [
|
|
172
173
|
${casts} ];
|
|
173
174
|
}
|
|
174
|
-
${relations}${accessors}${fileAccessors}${nestedSetMethod}
|
|
175
|
+
${relations}${accessors}${fileAccessors}${auditSection}${nestedSetMethod}
|
|
175
176
|
}
|
|
176
177
|
`;
|
|
177
178
|
return baseFile(resolveModularBasePath(config, name, 'Models', `${modelName}BaseModel.php`, config.models.basePath), content);
|
|
@@ -568,6 +569,89 @@ function buildNestedSetParentIdMethod(parentColumn) {
|
|
|
568
569
|
}
|
|
569
570
|
`;
|
|
570
571
|
}
|
|
572
|
+
function buildAuditSection(options, reader, modelNamespace) {
|
|
573
|
+
const opts = options;
|
|
574
|
+
const audit = opts?.['audit'];
|
|
575
|
+
if (!audit)
|
|
576
|
+
return '';
|
|
577
|
+
const hasCreatedBy = audit['createdBy'] ?? false;
|
|
578
|
+
const hasUpdatedBy = audit['updatedBy'] ?? false;
|
|
579
|
+
const hasDeletedBy = audit['deletedBy'] ?? false;
|
|
580
|
+
if (!hasCreatedBy && !hasUpdatedBy && !hasDeletedBy)
|
|
581
|
+
return '';
|
|
582
|
+
// Get audit model name from schemas.json auditConfig
|
|
583
|
+
const auditModel = reader.data?.auditConfig?.model ?? 'User';
|
|
584
|
+
const fqcn = `\\${modelNamespace}\\${auditModel}`;
|
|
585
|
+
const parts = [];
|
|
586
|
+
// Model events (booted)
|
|
587
|
+
const events = [];
|
|
588
|
+
if (hasCreatedBy) {
|
|
589
|
+
events.push(` static::creating(function ($model) {
|
|
590
|
+
if (auth()->check() && !$model->created_by_id) {
|
|
591
|
+
$model->created_by_id = auth()->id();
|
|
592
|
+
}
|
|
593
|
+
});`);
|
|
594
|
+
}
|
|
595
|
+
if (hasUpdatedBy) {
|
|
596
|
+
events.push(` static::updating(function ($model) {
|
|
597
|
+
if (auth()->check()) {
|
|
598
|
+
$model->updated_by_id = auth()->id();
|
|
599
|
+
}
|
|
600
|
+
});`);
|
|
601
|
+
}
|
|
602
|
+
if (hasDeletedBy) {
|
|
603
|
+
events.push(` static::deleting(function ($model) {
|
|
604
|
+
if (auth()->check() && method_exists($model, 'isForceDeleting') && !$model->isForceDeleting()) {
|
|
605
|
+
$model->deleted_by_id = auth()->id();
|
|
606
|
+
$model->saveQuietly();
|
|
607
|
+
}
|
|
608
|
+
});`);
|
|
609
|
+
}
|
|
610
|
+
if (events.length > 0) {
|
|
611
|
+
parts.push(`
|
|
612
|
+
/**
|
|
613
|
+
* Boot audit events.
|
|
614
|
+
*/
|
|
615
|
+
protected static function booted(): void
|
|
616
|
+
{
|
|
617
|
+
parent::booted();
|
|
618
|
+
|
|
619
|
+
${events.join('\n\n')}
|
|
620
|
+
}`);
|
|
621
|
+
}
|
|
622
|
+
// Relations
|
|
623
|
+
if (hasCreatedBy) {
|
|
624
|
+
parts.push(`
|
|
625
|
+
/**
|
|
626
|
+
* Get the user who created this record.
|
|
627
|
+
*/
|
|
628
|
+
public function createdBy(): BelongsTo
|
|
629
|
+
{
|
|
630
|
+
return $this->belongsTo(${fqcn}::class, 'created_by_id');
|
|
631
|
+
}`);
|
|
632
|
+
}
|
|
633
|
+
if (hasUpdatedBy) {
|
|
634
|
+
parts.push(`
|
|
635
|
+
/**
|
|
636
|
+
* Get the user who last updated this record.
|
|
637
|
+
*/
|
|
638
|
+
public function updatedBy(): BelongsTo
|
|
639
|
+
{
|
|
640
|
+
return $this->belongsTo(${fqcn}::class, 'updated_by_id');
|
|
641
|
+
}`);
|
|
642
|
+
}
|
|
643
|
+
if (hasDeletedBy) {
|
|
644
|
+
parts.push(`
|
|
645
|
+
/**
|
|
646
|
+
* Get the user who deleted this record.
|
|
647
|
+
*/
|
|
648
|
+
public function deletedBy(): BelongsTo
|
|
649
|
+
{
|
|
650
|
+
return $this->belongsTo(${fqcn}::class, 'deleted_by_id');
|
|
651
|
+
}`);
|
|
652
|
+
}
|
|
653
|
+
return parts.join('\n');
|
|
654
|
+
}
|
|
571
655
|
function buildFileAccessors(properties, propertyOrder, modelNamespace) {
|
|
572
656
|
const methods = [];
|
|
573
657
|
for (const propName of propertyOrder) {
|