@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/{chunk-FR6LGETT.js → chunk-FCTB4WKW.js} +85 -6
- package/dist/chunk-FCTB4WKW.js.map +1 -0
- package/dist/index.cjs +84 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/plugin.cjs +84 -5
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-FR6LGETT.js.map +0 -1
|
@@ -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
|
|
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
|
|
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
|
}
|
|
@@ -3271,6 +3337,17 @@ function getModuleName2(schema) {
|
|
|
3271
3337
|
}
|
|
3272
3338
|
return "";
|
|
3273
3339
|
}
|
|
3340
|
+
function getFieldExpression(fieldName, propDef) {
|
|
3341
|
+
switch (propDef.type) {
|
|
3342
|
+
case "Date":
|
|
3343
|
+
return `$this->${fieldName}?->toDateString()`;
|
|
3344
|
+
case "DateTime":
|
|
3345
|
+
case "Timestamp":
|
|
3346
|
+
return `$this->${fieldName}?->toISOString()`;
|
|
3347
|
+
default:
|
|
3348
|
+
return `$this->${fieldName}`;
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3274
3351
|
function getPropertyOutput(propName, propDef, schemas, options) {
|
|
3275
3352
|
const snakeName = toSnakeCase(propName);
|
|
3276
3353
|
const lines = [];
|
|
@@ -3317,7 +3394,8 @@ function getPropertyOutput(propName, propDef, schemas, options) {
|
|
|
3317
3394
|
}
|
|
3318
3395
|
return lines;
|
|
3319
3396
|
}
|
|
3320
|
-
|
|
3397
|
+
const expression = getFieldExpression(snakeName, propDef);
|
|
3398
|
+
lines.push(` '${snakeName}' => ${expression},`);
|
|
3321
3399
|
return lines;
|
|
3322
3400
|
}
|
|
3323
3401
|
function generateResourceBase(schema, schemas, options) {
|
|
@@ -3783,7 +3861,8 @@ function laravelPlugin(options) {
|
|
|
3783
3861
|
const factoryOptions = {
|
|
3784
3862
|
modelNamespace: resolved.modelNamespace,
|
|
3785
3863
|
factoryPath: resolved.factoriesPath,
|
|
3786
|
-
fakerLocale: resolved.fakerLocale
|
|
3864
|
+
fakerLocale: resolved.fakerLocale,
|
|
3865
|
+
customTypes: ctx.customTypes
|
|
3787
3866
|
};
|
|
3788
3867
|
const factories = generateFactories(ctx.schemas, factoryOptions);
|
|
3789
3868
|
return factories.map((factory) => ({
|
|
@@ -3900,4 +3979,4 @@ export {
|
|
|
3900
3979
|
getFactoryPath,
|
|
3901
3980
|
laravelPlugin
|
|
3902
3981
|
};
|
|
3903
|
-
//# sourceMappingURL=chunk-
|
|
3982
|
+
//# sourceMappingURL=chunk-FCTB4WKW.js.map
|