@famgia/omnify-laravel 0.0.80 → 0.0.81

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.
@@ -2262,7 +2262,8 @@ function resolveOptions2(options) {
2262
2262
  return {
2263
2263
  modelNamespace: options?.modelNamespace ?? "App\\Models",
2264
2264
  factoryPath: options?.factoryPath ?? "database/factories",
2265
- fakerLocale: options?.fakerLocale ?? "en_US"
2265
+ fakerLocale: options?.fakerLocale ?? "en_US",
2266
+ customTypes: options?.customTypes ?? /* @__PURE__ */ new Map()
2266
2267
  };
2267
2268
  }
2268
2269
  function getStubContent2() {
@@ -2295,7 +2296,63 @@ class {{MODEL_NAME}}Factory extends Factory
2295
2296
  }
2296
2297
  `;
2297
2298
  }
2298
- function generateFakeData(propertyName, property, schema, schemas) {
2299
+ function generateJapaneseCompoundFake(propertyName, property, options) {
2300
+ const typeDef = options.customTypes.get(property.type);
2301
+ if (!typeDef || !typeDef.compound || !typeDef.expand) {
2302
+ return null;
2303
+ }
2304
+ const snakeName = toSnakeCase(propertyName);
2305
+ const lines = [];
2306
+ const jaFaker = "fake('ja_JP')";
2307
+ switch (property.type) {
2308
+ case "JapaneseName":
2309
+ lines.push(`'${snakeName}_lastname' => ${jaFaker}->lastName(),`);
2310
+ lines.push(`'${snakeName}_firstname' => ${jaFaker}->firstName(),`);
2311
+ lines.push(`'${snakeName}_kana_lastname' => ${jaFaker}->lastKanaName(),`);
2312
+ lines.push(`'${snakeName}_kana_firstname' => ${jaFaker}->firstKanaName(),`);
2313
+ break;
2314
+ case "JapaneseAddress":
2315
+ lines.push(`'${snakeName}_postal_code' => ${jaFaker}->postcode(),`);
2316
+ lines.push(`'${snakeName}_prefecture_id' => ${jaFaker}->numberBetween(1, 47),`);
2317
+ lines.push(`'${snakeName}_address1' => ${jaFaker}->city() . ${jaFaker}->ward(),`);
2318
+ lines.push(`'${snakeName}_address2' => ${jaFaker}->streetAddress(),`);
2319
+ lines.push(`'${snakeName}_address3' => ${jaFaker}->optional()->secondaryAddress(),`);
2320
+ break;
2321
+ case "JapaneseBankAccount":
2322
+ lines.push(`'${snakeName}_bank_code' => ${jaFaker}->regexify('[0-9]{4}'),`);
2323
+ lines.push(`'${snakeName}_branch_code' => ${jaFaker}->regexify('[0-9]{3}'),`);
2324
+ lines.push(`'${snakeName}_account_type' => ${jaFaker}->randomElement(['1', '2', '4']),`);
2325
+ lines.push(`'${snakeName}_account_number' => ${jaFaker}->regexify('[0-9]{7}'),`);
2326
+ lines.push(`'${snakeName}_account_holder' => ${jaFaker}->lastKanaName() . ' ' . ${jaFaker}->firstKanaName(),`);
2327
+ break;
2328
+ default:
2329
+ for (const field of typeDef.expand) {
2330
+ const suffixSnake = toSnakeCase(field.suffix);
2331
+ const fieldName = `${snakeName}_${suffixSnake}`;
2332
+ const sql = field.sql;
2333
+ if (sql?.sqlType === "TINYINT" || sql?.sqlType === "INT" || sql?.sqlType === "BIGINT") {
2334
+ lines.push(`'${fieldName}' => fake()->numberBetween(1, 100),`);
2335
+ } else {
2336
+ lines.push(`'${fieldName}' => fake()->words(2, true),`);
2337
+ }
2338
+ }
2339
+ break;
2340
+ }
2341
+ return lines;
2342
+ }
2343
+ function generateJapaneseSimpleFake(propertyName, property) {
2344
+ const snakeName = toSnakeCase(propertyName);
2345
+ const jaFaker = "fake('ja_JP')";
2346
+ switch (property.type) {
2347
+ case "JapanesePhone":
2348
+ return `'${snakeName}' => ${jaFaker}->phoneNumber(),`;
2349
+ case "JapanesePostalCode":
2350
+ return `'${snakeName}' => ${jaFaker}->postcode(),`;
2351
+ default:
2352
+ return null;
2353
+ }
2354
+ }
2355
+ function generateFakeData(propertyName, property, schema, schemas, options) {
2299
2356
  const type = property.type;
2300
2357
  if (["deleted_at", "created_at", "updated_at"].includes(propertyName)) {
2301
2358
  return null;
@@ -2303,6 +2360,10 @@ function generateFakeData(propertyName, property, schema, schemas) {
2303
2360
  if (type === "Association") {
2304
2361
  return null;
2305
2362
  }
2363
+ const japaneseFake = generateJapaneseSimpleFake(propertyName, property);
2364
+ if (japaneseFake) {
2365
+ return japaneseFake;
2366
+ }
2306
2367
  switch (type) {
2307
2368
  case "String":
2308
2369
  return generateStringFake(propertyName, property);
@@ -2483,7 +2544,12 @@ function generateFactory(schema, schemas, options, stubContent) {
2483
2544
  }
2484
2545
  continue;
2485
2546
  }
2486
- const fake = generateFakeData(propName, prop, schema, schemas);
2547
+ const compoundFakes = generateJapaneseCompoundFake(propName, prop, options);
2548
+ if (compoundFakes) {
2549
+ attributes.push(...compoundFakes);
2550
+ continue;
2551
+ }
2552
+ const fake = generateFakeData(propName, prop, schema, schemas, options);
2487
2553
  if (fake) {
2488
2554
  attributes.push(fake);
2489
2555
  }
@@ -3783,7 +3849,8 @@ function laravelPlugin(options) {
3783
3849
  const factoryOptions = {
3784
3850
  modelNamespace: resolved.modelNamespace,
3785
3851
  factoryPath: resolved.factoriesPath,
3786
- fakerLocale: resolved.fakerLocale
3852
+ fakerLocale: resolved.fakerLocale,
3853
+ customTypes: ctx.customTypes
3787
3854
  };
3788
3855
  const factories = generateFactories(ctx.schemas, factoryOptions);
3789
3856
  return factories.map((factory) => ({
@@ -3900,4 +3967,4 @@ export {
3900
3967
  getFactoryPath,
3901
3968
  laravelPlugin
3902
3969
  };
3903
- //# sourceMappingURL=chunk-FR6LGETT.js.map
3970
+ //# sourceMappingURL=chunk-WFEVU3LX.js.map