@famgia/omnify-laravel 0.0.80 → 0.0.82

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/index.cjs CHANGED
@@ -2308,7 +2308,8 @@ function resolveOptions2(options) {
2308
2308
  return {
2309
2309
  modelNamespace: options?.modelNamespace ?? "App\\Models",
2310
2310
  factoryPath: options?.factoryPath ?? "database/factories",
2311
- fakerLocale: options?.fakerLocale ?? "en_US"
2311
+ fakerLocale: options?.fakerLocale ?? "en_US",
2312
+ customTypes: options?.customTypes ?? /* @__PURE__ */ new Map()
2312
2313
  };
2313
2314
  }
2314
2315
  function getStubContent2() {
@@ -2341,7 +2342,63 @@ class {{MODEL_NAME}}Factory extends Factory
2341
2342
  }
2342
2343
  `;
2343
2344
  }
2344
- function generateFakeData(propertyName, property, schema, schemas) {
2345
+ function generateJapaneseCompoundFake(propertyName, property, options) {
2346
+ const typeDef = options.customTypes.get(property.type);
2347
+ if (!typeDef || !typeDef.compound || !typeDef.expand) {
2348
+ return null;
2349
+ }
2350
+ const snakeName = toSnakeCase(propertyName);
2351
+ const lines = [];
2352
+ const jaFaker = "fake('ja_JP')";
2353
+ switch (property.type) {
2354
+ case "JapaneseName":
2355
+ lines.push(`'${snakeName}_lastname' => ${jaFaker}->lastName(),`);
2356
+ lines.push(`'${snakeName}_firstname' => ${jaFaker}->firstName(),`);
2357
+ lines.push(`'${snakeName}_kana_lastname' => ${jaFaker}->lastKanaName(),`);
2358
+ lines.push(`'${snakeName}_kana_firstname' => ${jaFaker}->firstKanaName(),`);
2359
+ break;
2360
+ case "JapaneseAddress":
2361
+ lines.push(`'${snakeName}_postal_code' => ${jaFaker}->postcode(),`);
2362
+ lines.push(`'${snakeName}_prefecture_id' => ${jaFaker}->numberBetween(1, 47),`);
2363
+ lines.push(`'${snakeName}_address1' => ${jaFaker}->city() . ${jaFaker}->ward(),`);
2364
+ lines.push(`'${snakeName}_address2' => ${jaFaker}->streetAddress(),`);
2365
+ lines.push(`'${snakeName}_address3' => ${jaFaker}->optional()->secondaryAddress(),`);
2366
+ break;
2367
+ case "JapaneseBankAccount":
2368
+ lines.push(`'${snakeName}_bank_code' => ${jaFaker}->regexify('[0-9]{4}'),`);
2369
+ lines.push(`'${snakeName}_branch_code' => ${jaFaker}->regexify('[0-9]{3}'),`);
2370
+ lines.push(`'${snakeName}_account_type' => ${jaFaker}->randomElement(['1', '2', '4']),`);
2371
+ lines.push(`'${snakeName}_account_number' => ${jaFaker}->regexify('[0-9]{7}'),`);
2372
+ lines.push(`'${snakeName}_account_holder' => ${jaFaker}->lastKanaName() . ' ' . ${jaFaker}->firstKanaName(),`);
2373
+ break;
2374
+ default:
2375
+ for (const field of typeDef.expand) {
2376
+ const suffixSnake = toSnakeCase(field.suffix);
2377
+ const fieldName = `${snakeName}_${suffixSnake}`;
2378
+ const sql = field.sql;
2379
+ if (sql?.sqlType === "TINYINT" || sql?.sqlType === "INT" || sql?.sqlType === "BIGINT") {
2380
+ lines.push(`'${fieldName}' => fake()->numberBetween(1, 100),`);
2381
+ } else {
2382
+ lines.push(`'${fieldName}' => fake()->words(2, true),`);
2383
+ }
2384
+ }
2385
+ break;
2386
+ }
2387
+ return lines;
2388
+ }
2389
+ function generateJapaneseSimpleFake(propertyName, property) {
2390
+ const snakeName = toSnakeCase(propertyName);
2391
+ const jaFaker = "fake('ja_JP')";
2392
+ switch (property.type) {
2393
+ case "JapanesePhone":
2394
+ return `'${snakeName}' => ${jaFaker}->phoneNumber(),`;
2395
+ case "JapanesePostalCode":
2396
+ return `'${snakeName}' => ${jaFaker}->postcode(),`;
2397
+ default:
2398
+ return null;
2399
+ }
2400
+ }
2401
+ function generateFakeData(propertyName, property, schema, schemas, options) {
2345
2402
  const type = property.type;
2346
2403
  if (["deleted_at", "created_at", "updated_at"].includes(propertyName)) {
2347
2404
  return null;
@@ -2349,6 +2406,10 @@ function generateFakeData(propertyName, property, schema, schemas) {
2349
2406
  if (type === "Association") {
2350
2407
  return null;
2351
2408
  }
2409
+ const japaneseFake = generateJapaneseSimpleFake(propertyName, property);
2410
+ if (japaneseFake) {
2411
+ return japaneseFake;
2412
+ }
2352
2413
  switch (type) {
2353
2414
  case "String":
2354
2415
  return generateStringFake(propertyName, property);
@@ -2529,7 +2590,12 @@ function generateFactory(schema, schemas, options, stubContent) {
2529
2590
  }
2530
2591
  continue;
2531
2592
  }
2532
- const fake = generateFakeData(propName, prop, schema, schemas);
2593
+ const compoundFakes = generateJapaneseCompoundFake(propName, prop, options);
2594
+ if (compoundFakes) {
2595
+ attributes.push(...compoundFakes);
2596
+ continue;
2597
+ }
2598
+ const fake = generateFakeData(propName, prop, schema, schemas, options);
2533
2599
  if (fake) {
2534
2600
  attributes.push(fake);
2535
2601
  }
@@ -3321,6 +3387,17 @@ function getModuleName2(schema) {
3321
3387
  }
3322
3388
  return "";
3323
3389
  }
3390
+ function getFieldExpression(fieldName, propDef) {
3391
+ switch (propDef.type) {
3392
+ case "Date":
3393
+ return `$this->${fieldName}?->toDateString()`;
3394
+ case "DateTime":
3395
+ case "Timestamp":
3396
+ return `$this->${fieldName}?->toISOString()`;
3397
+ default:
3398
+ return `$this->${fieldName}`;
3399
+ }
3400
+ }
3324
3401
  function getPropertyOutput(propName, propDef, schemas, options) {
3325
3402
  const snakeName = toSnakeCase(propName);
3326
3403
  const lines = [];
@@ -3367,7 +3444,8 @@ function getPropertyOutput(propName, propDef, schemas, options) {
3367
3444
  }
3368
3445
  return lines;
3369
3446
  }
3370
- lines.push(` '${snakeName}' => $this->${snakeName},`);
3447
+ const expression = getFieldExpression(snakeName, propDef);
3448
+ lines.push(` '${snakeName}' => ${expression},`);
3371
3449
  return lines;
3372
3450
  }
3373
3451
  function generateResourceBase(schema, schemas, options) {
@@ -3833,7 +3911,8 @@ function laravelPlugin(options) {
3833
3911
  const factoryOptions = {
3834
3912
  modelNamespace: resolved.modelNamespace,
3835
3913
  factoryPath: resolved.factoriesPath,
3836
- fakerLocale: resolved.fakerLocale
3914
+ fakerLocale: resolved.fakerLocale,
3915
+ customTypes: ctx.customTypes
3837
3916
  };
3838
3917
  const factories = generateFactories(ctx.schemas, factoryOptions);
3839
3918
  return factories.map((factory) => ({