@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.d.cts CHANGED
@@ -354,6 +354,8 @@ interface FactoryGeneratorOptions {
354
354
  factoryPath?: string;
355
355
  /** Faker locale */
356
356
  fakerLocale?: string;
357
+ /** Custom types registered by plugins */
358
+ customTypes?: ReadonlyMap<string, CustomTypeDefinition>;
357
359
  }
358
360
  /**
359
361
  * Generated factory output.
package/dist/index.d.ts CHANGED
@@ -354,6 +354,8 @@ interface FactoryGeneratorOptions {
354
354
  factoryPath?: string;
355
355
  /** Faker locale */
356
356
  fakerLocale?: string;
357
+ /** Custom types registered by plugins */
358
+ customTypes?: ReadonlyMap<string, CustomTypeDefinition>;
357
359
  }
358
360
  /**
359
361
  * Generated factory output.
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  schemaToBlueprint,
25
25
  toColumnName,
26
26
  toTableName
27
- } from "./chunk-FR6LGETT.js";
27
+ } from "./chunk-FCTB4WKW.js";
28
28
  export {
29
29
  formatColumnMethod,
30
30
  formatForeignKey,
package/dist/plugin.cjs CHANGED
@@ -2237,7 +2237,8 @@ function resolveOptions2(options) {
2237
2237
  return {
2238
2238
  modelNamespace: options?.modelNamespace ?? "App\\Models",
2239
2239
  factoryPath: options?.factoryPath ?? "database/factories",
2240
- fakerLocale: options?.fakerLocale ?? "en_US"
2240
+ fakerLocale: options?.fakerLocale ?? "en_US",
2241
+ customTypes: options?.customTypes ?? /* @__PURE__ */ new Map()
2241
2242
  };
2242
2243
  }
2243
2244
  function getStubContent2() {
@@ -2270,7 +2271,63 @@ class {{MODEL_NAME}}Factory extends Factory
2270
2271
  }
2271
2272
  `;
2272
2273
  }
2273
- function generateFakeData(propertyName, property, schema, schemas) {
2274
+ function generateJapaneseCompoundFake(propertyName, property, options) {
2275
+ const typeDef = options.customTypes.get(property.type);
2276
+ if (!typeDef || !typeDef.compound || !typeDef.expand) {
2277
+ return null;
2278
+ }
2279
+ const snakeName = toSnakeCase(propertyName);
2280
+ const lines = [];
2281
+ const jaFaker = "fake('ja_JP')";
2282
+ switch (property.type) {
2283
+ case "JapaneseName":
2284
+ lines.push(`'${snakeName}_lastname' => ${jaFaker}->lastName(),`);
2285
+ lines.push(`'${snakeName}_firstname' => ${jaFaker}->firstName(),`);
2286
+ lines.push(`'${snakeName}_kana_lastname' => ${jaFaker}->lastKanaName(),`);
2287
+ lines.push(`'${snakeName}_kana_firstname' => ${jaFaker}->firstKanaName(),`);
2288
+ break;
2289
+ case "JapaneseAddress":
2290
+ lines.push(`'${snakeName}_postal_code' => ${jaFaker}->postcode(),`);
2291
+ lines.push(`'${snakeName}_prefecture_id' => ${jaFaker}->numberBetween(1, 47),`);
2292
+ lines.push(`'${snakeName}_address1' => ${jaFaker}->city() . ${jaFaker}->ward(),`);
2293
+ lines.push(`'${snakeName}_address2' => ${jaFaker}->streetAddress(),`);
2294
+ lines.push(`'${snakeName}_address3' => ${jaFaker}->optional()->secondaryAddress(),`);
2295
+ break;
2296
+ case "JapaneseBankAccount":
2297
+ lines.push(`'${snakeName}_bank_code' => ${jaFaker}->regexify('[0-9]{4}'),`);
2298
+ lines.push(`'${snakeName}_branch_code' => ${jaFaker}->regexify('[0-9]{3}'),`);
2299
+ lines.push(`'${snakeName}_account_type' => ${jaFaker}->randomElement(['1', '2', '4']),`);
2300
+ lines.push(`'${snakeName}_account_number' => ${jaFaker}->regexify('[0-9]{7}'),`);
2301
+ lines.push(`'${snakeName}_account_holder' => ${jaFaker}->lastKanaName() . ' ' . ${jaFaker}->firstKanaName(),`);
2302
+ break;
2303
+ default:
2304
+ for (const field of typeDef.expand) {
2305
+ const suffixSnake = toSnakeCase(field.suffix);
2306
+ const fieldName = `${snakeName}_${suffixSnake}`;
2307
+ const sql = field.sql;
2308
+ if (sql?.sqlType === "TINYINT" || sql?.sqlType === "INT" || sql?.sqlType === "BIGINT") {
2309
+ lines.push(`'${fieldName}' => fake()->numberBetween(1, 100),`);
2310
+ } else {
2311
+ lines.push(`'${fieldName}' => fake()->words(2, true),`);
2312
+ }
2313
+ }
2314
+ break;
2315
+ }
2316
+ return lines;
2317
+ }
2318
+ function generateJapaneseSimpleFake(propertyName, property) {
2319
+ const snakeName = toSnakeCase(propertyName);
2320
+ const jaFaker = "fake('ja_JP')";
2321
+ switch (property.type) {
2322
+ case "JapanesePhone":
2323
+ return `'${snakeName}' => ${jaFaker}->phoneNumber(),`;
2324
+ case "JapanesePostalCode":
2325
+ return `'${snakeName}' => ${jaFaker}->postcode(),`;
2326
+ default:
2327
+ return null;
2328
+ }
2329
+ }
2330
+ function generateFakeData(propertyName, property, schema, schemas, options) {
2274
2331
  const type = property.type;
2275
2332
  if (["deleted_at", "created_at", "updated_at"].includes(propertyName)) {
2276
2333
  return null;
@@ -2278,6 +2335,10 @@ function generateFakeData(propertyName, property, schema, schemas) {
2278
2335
  if (type === "Association") {
2279
2336
  return null;
2280
2337
  }
2338
+ const japaneseFake = generateJapaneseSimpleFake(propertyName, property);
2339
+ if (japaneseFake) {
2340
+ return japaneseFake;
2341
+ }
2281
2342
  switch (type) {
2282
2343
  case "String":
2283
2344
  return generateStringFake(propertyName, property);
@@ -2458,7 +2519,12 @@ function generateFactory(schema, schemas, options, stubContent) {
2458
2519
  }
2459
2520
  continue;
2460
2521
  }
2461
- const fake = generateFakeData(propName, prop, schema, schemas);
2522
+ const compoundFakes = generateJapaneseCompoundFake(propName, prop, options);
2523
+ if (compoundFakes) {
2524
+ attributes.push(...compoundFakes);
2525
+ continue;
2526
+ }
2527
+ const fake = generateFakeData(propName, prop, schema, schemas, options);
2462
2528
  if (fake) {
2463
2529
  attributes.push(fake);
2464
2530
  }
@@ -3246,6 +3312,17 @@ function getModuleName2(schema) {
3246
3312
  }
3247
3313
  return "";
3248
3314
  }
3315
+ function getFieldExpression(fieldName, propDef) {
3316
+ switch (propDef.type) {
3317
+ case "Date":
3318
+ return `$this->${fieldName}?->toDateString()`;
3319
+ case "DateTime":
3320
+ case "Timestamp":
3321
+ return `$this->${fieldName}?->toISOString()`;
3322
+ default:
3323
+ return `$this->${fieldName}`;
3324
+ }
3325
+ }
3249
3326
  function getPropertyOutput(propName, propDef, schemas, options) {
3250
3327
  const snakeName = toSnakeCase(propName);
3251
3328
  const lines = [];
@@ -3292,7 +3369,8 @@ function getPropertyOutput(propName, propDef, schemas, options) {
3292
3369
  }
3293
3370
  return lines;
3294
3371
  }
3295
- lines.push(` '${snakeName}' => $this->${snakeName},`);
3372
+ const expression = getFieldExpression(snakeName, propDef);
3373
+ lines.push(` '${snakeName}' => ${expression},`);
3296
3374
  return lines;
3297
3375
  }
3298
3376
  function generateResourceBase(schema, schemas, options) {
@@ -3758,7 +3836,8 @@ function laravelPlugin(options) {
3758
3836
  const factoryOptions = {
3759
3837
  modelNamespace: resolved.modelNamespace,
3760
3838
  factoryPath: resolved.factoriesPath,
3761
- fakerLocale: resolved.fakerLocale
3839
+ fakerLocale: resolved.fakerLocale,
3840
+ customTypes: ctx.customTypes
3762
3841
  };
3763
3842
  const factories = generateFactories(ctx.schemas, factoryOptions);
3764
3843
  return factories.map((factory) => ({