@famgia/omnify-laravel 2.0.8 → 2.0.10

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.
@@ -41,6 +41,8 @@ var TYPE_METHOD_MAP = {
41
41
  TinyInt: "tinyInteger",
42
42
  Int: "integer",
43
43
  BigInt: "bigInteger",
44
+ Uuid: "uuid",
45
+ // UUID type for foreign keys and custom fields
44
46
  Float: "double",
45
47
  Decimal: "decimal",
46
48
  Boolean: "boolean",
@@ -1849,12 +1851,26 @@ function generateEntityBaseModel(schema, schemas, options, stubContent, authStub
1849
1851
  const className = toPascalCase(schema.name);
1850
1852
  const tableName = schema.options?.tableName ?? pluralize(toSnakeCase(schema.name));
1851
1853
  const isAuth = schema.options?.authenticatable ?? false;
1852
- const hasAutoId2 = schema.options?.id !== false;
1854
+ const compositePrimaryKey = schema.options?.primaryKey;
1855
+ const isCompositePK = Array.isArray(compositePrimaryKey) && compositePrimaryKey.length > 1;
1856
+ const hasAutoId2 = schema.options?.id !== false && !compositePrimaryKey;
1853
1857
  let primaryKey = "id";
1854
1858
  let isStringKey = false;
1855
1859
  let isUuid = false;
1856
1860
  let isNonIncrementing = false;
1857
- if (hasAutoId2) {
1861
+ if (isCompositePK) {
1862
+ primaryKey = compositePrimaryKey.map((col) => toSnakeCase(col));
1863
+ isNonIncrementing = true;
1864
+ } else if (compositePrimaryKey && typeof compositePrimaryKey === "string") {
1865
+ primaryKey = toSnakeCase(compositePrimaryKey);
1866
+ isNonIncrementing = true;
1867
+ const properties2 = schema.properties ?? {};
1868
+ const propDef = properties2[compositePrimaryKey];
1869
+ if (propDef) {
1870
+ const propType = propDef.type;
1871
+ isStringKey = propType === "String" || propType === "Text" || propType === "Email";
1872
+ }
1873
+ } else if (hasAutoId2) {
1858
1874
  const idType = schema.options?.idType ?? "BigInt";
1859
1875
  isUuid = idType === "Uuid";
1860
1876
  isStringKey = idType === "Uuid" || idType === "String";
@@ -2039,7 +2055,8 @@ ${docProperties.join("\n")}
2039
2055
  imports.push("use Illuminate\\Database\\Eloquent\\Concerns\\HasUuids;");
2040
2056
  traits.push(" use HasUuids;");
2041
2057
  }
2042
- const content = stub.replace(/\{\{BASE_MODEL_NAMESPACE\}\}/g, options.baseModelNamespace).replace(/\{\{BASE_MODEL_CLASS\}\}/g, options.baseModelClassName).replace(/\{\{CLASS_NAME\}\}/g, className).replace(/\{\{TABLE_NAME\}\}/g, tableName).replace(/\{\{PRIMARY_KEY\}\}/g, primaryKey).replace(/\{\{KEY_TYPE\}\}/g, keyType).replace(/\{\{INCREMENTING\}\}/g, incrementing).replace(/\{\{TIMESTAMPS\}\}/g, schema.options?.timestamps !== false ? "true" : "false").replace(/\{\{IMPORTS\}\}/g, [...new Set(imports)].sort().join("\n")).replace(/\{\{TRAITS\}\}/g, traits.join("\n")).replace(/\{\{DOC_COMMENT\}\}/g, docComment).replace(/\{\{FILLABLE\}\}/g, fillable.join("\n")).replace(/\{\{HIDDEN\}\}/g, hidden.join("\n")).replace(/\{\{APPENDS\}\}/g, appends.join("\n")).replace(/\{\{CASTS\}\}/g, casts.join("\n")).replace(/\{\{RELATIONS\}\}/g, relations.join("\n\n"));
2058
+ const primaryKeyPhp = Array.isArray(primaryKey) ? `[${primaryKey.map((k) => `'${k}'`).join(", ")}]` : `'${primaryKey}'`;
2059
+ const content = stub.replace(/\{\{BASE_MODEL_NAMESPACE\}\}/g, options.baseModelNamespace).replace(/\{\{BASE_MODEL_CLASS\}\}/g, options.baseModelClassName).replace(/\{\{CLASS_NAME\}\}/g, className).replace(/\{\{TABLE_NAME\}\}/g, tableName).replace(/\{\{PRIMARY_KEY\}\}/g, primaryKeyPhp).replace(/\{\{KEY_TYPE\}\}/g, keyType).replace(/\{\{INCREMENTING\}\}/g, incrementing).replace(/\{\{TIMESTAMPS\}\}/g, schema.options?.timestamps !== false ? "true" : "false").replace(/\{\{IMPORTS\}\}/g, [...new Set(imports)].sort().join("\n")).replace(/\{\{TRAITS\}\}/g, traits.join("\n")).replace(/\{\{DOC_COMMENT\}\}/g, docComment).replace(/\{\{FILLABLE\}\}/g, fillable.join("\n")).replace(/\{\{HIDDEN\}\}/g, hidden.join("\n")).replace(/\{\{APPENDS\}\}/g, appends.join("\n")).replace(/\{\{CASTS\}\}/g, casts.join("\n")).replace(/\{\{RELATIONS\}\}/g, relations.join("\n\n"));
2043
2060
  return {
2044
2061
  path: `${options.baseModelPath}/${className}BaseModel.php`,
2045
2062
  content,
@@ -2282,7 +2299,7 @@ class {{CLASS_NAME}}BaseModel extends {{BASE_MODEL_CLASS}}
2282
2299
  /**
2283
2300
  * The primary key for the model.
2284
2301
  */
2285
- protected $primaryKey = '{{PRIMARY_KEY}}';
2302
+ protected $primaryKey = {{PRIMARY_KEY}};
2286
2303
 
2287
2304
  {{KEY_TYPE}}
2288
2305
  {{INCREMENTING}}
@@ -2379,7 +2396,7 @@ class {{CLASS_NAME}}BaseModel extends Authenticatable
2379
2396
  /**
2380
2397
  * The primary key for the model.
2381
2398
  */
2382
- protected $primaryKey = '{{PRIMARY_KEY}}';
2399
+ protected $primaryKey = {{PRIMARY_KEY}};
2383
2400
 
2384
2401
  {{KEY_TYPE}}
2385
2402
  {{INCREMENTING}}
@@ -2466,6 +2483,12 @@ class {{CLASS_NAME}}BaseModel extends Pivot
2466
2483
  */
2467
2484
  protected $table = '{{TABLE_NAME}}';
2468
2485
 
2486
+ /**
2487
+ * The primary key for the model.
2488
+ */
2489
+ protected $primaryKey = {{PRIMARY_KEY}};
2490
+
2491
+ {{KEY_TYPE}}
2469
2492
  {{INCREMENTING}}
2470
2493
  /**
2471
2494
  * Indicates if the model should be timestamped.
@@ -5390,4 +5413,4 @@ export {
5390
5413
  shouldGenerateAIGuides,
5391
5414
  laravelPlugin
5392
5415
  };
5393
- //# sourceMappingURL=chunk-BWLXGHVF.js.map
5416
+ //# sourceMappingURL=chunk-VAHC2KDH.js.map