@omnifyjp/ts 3.2.9 → 3.2.11
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/php/service-generator.js +52 -12
- package/package.json +1 -1
|
@@ -31,7 +31,8 @@ function generateBaseService(name, schema, reader, config) {
|
|
|
31
31
|
const modelNs = config.models.namespace;
|
|
32
32
|
const properties = schema.properties ?? {};
|
|
33
33
|
const propertyOrder = reader.getPropertyOrder(name);
|
|
34
|
-
|
|
34
|
+
const expandedProperties = reader.getExpandedProperties(name);
|
|
35
|
+
// Collect searchable, filterable, sortable fields (compound types expand to sub-columns)
|
|
35
36
|
const searchableFields = [];
|
|
36
37
|
const filterableFields = [];
|
|
37
38
|
const sortableFields = [];
|
|
@@ -41,14 +42,44 @@ function generateBaseService(name, schema, reader, config) {
|
|
|
41
42
|
continue;
|
|
42
43
|
const colName = toSnakeCase(propName);
|
|
43
44
|
const translatable = prop.translatable ?? false;
|
|
45
|
+
const expansion = expandedProperties[propName];
|
|
44
46
|
if (prop.searchable) {
|
|
45
|
-
|
|
47
|
+
if (expansion && expansion.columns.length > 0) {
|
|
48
|
+
// Compound type: search all sub-columns
|
|
49
|
+
for (const col of expansion.columns) {
|
|
50
|
+
if (col.name) {
|
|
51
|
+
searchableFields.push({ propName: col.name, colName: col.name, translatable });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
searchableFields.push({ propName, colName, translatable });
|
|
57
|
+
}
|
|
46
58
|
}
|
|
47
59
|
if (prop.filterable) {
|
|
48
|
-
|
|
60
|
+
if (expansion && expansion.columns.length > 0) {
|
|
61
|
+
// Compound type: filter on each sub-column
|
|
62
|
+
for (const col of expansion.columns) {
|
|
63
|
+
if (col.name) {
|
|
64
|
+
filterableFields.push({ propName: col.name, colName: col.name, type: col.type ?? 'String', prop, translatable });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
filterableFields.push({ propName, colName, type: prop.type, prop, translatable });
|
|
70
|
+
}
|
|
49
71
|
}
|
|
50
72
|
if (prop.sortable) {
|
|
51
|
-
|
|
73
|
+
if (expansion && expansion.columns.length > 0) {
|
|
74
|
+
// Compound type: sort by primary sub-column (first one)
|
|
75
|
+
const primaryCol = expansion.columns[0];
|
|
76
|
+
if (primaryCol?.name) {
|
|
77
|
+
sortableFields.push({ propName: colName, colName: primaryCol.name, translatable });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
sortableFields.push({ propName: colName, colName, translatable });
|
|
82
|
+
}
|
|
52
83
|
}
|
|
53
84
|
}
|
|
54
85
|
// Build search block
|
|
@@ -281,22 +312,31 @@ function buildSortBlock(sortableFields) {
|
|
|
281
312
|
$query->orderBy('created_at', 'desc');
|
|
282
313
|
`;
|
|
283
314
|
}
|
|
284
|
-
|
|
285
|
-
const
|
|
315
|
+
// allowedSorts uses logical propName (what user sends in ?sort=)
|
|
316
|
+
const allowedList = sortableFields.map(f => `'${f.propName}'`).join(', ');
|
|
317
|
+
// sortMap: logical name → actual column name (compound types map to sub-column)
|
|
318
|
+
const needsMap = sortableFields.some(f => f.propName !== f.colName);
|
|
319
|
+
const sortMapEntries = sortableFields
|
|
320
|
+
.filter(f => f.propName !== f.colName)
|
|
321
|
+
.map(f => ` '${f.propName}' => '${f.colName}',`)
|
|
322
|
+
.join('\n');
|
|
323
|
+
const sortMapDecl = needsMap ? `\n $sortMap = [\n${sortMapEntries}\n ];` : '';
|
|
324
|
+
const sortColResolve = needsMap ? `\n $sortCol = $sortMap[$sortField] ?? $sortField;` : `\n $sortCol = $sortField;`;
|
|
325
|
+
const translatableSorts = sortableFields.filter(f => f.translatable).map(f => `'${f.propName}'`);
|
|
286
326
|
const translatableCheck = translatableSorts.length > 0
|
|
287
|
-
? `\n
|
|
327
|
+
? `\n $translatableSorts = [${translatableSorts.join(', ')}];`
|
|
288
328
|
: '';
|
|
289
329
|
const orderByLine = translatableSorts.length > 0
|
|
290
330
|
? ` if (in_array($sortField, $translatableSorts ?? [], true)) {
|
|
291
|
-
$query->orderByTranslation($
|
|
331
|
+
$query->orderByTranslation($sortCol, $direction);
|
|
292
332
|
} else {
|
|
293
|
-
$query->orderBy($
|
|
333
|
+
$query->orderBy($sortCol, $direction);
|
|
294
334
|
}`
|
|
295
|
-
: ` $query->orderBy($
|
|
335
|
+
: ` $query->orderBy($sortCol, $direction);`;
|
|
296
336
|
return `
|
|
297
337
|
// Sort
|
|
298
338
|
$sortParam = $filters['sort'] ?? '-created_at';
|
|
299
|
-
$allowedSorts = [${allowedList}];${translatableCheck}
|
|
339
|
+
$allowedSorts = [${allowedList}];${sortMapDecl}${translatableCheck}
|
|
300
340
|
|
|
301
341
|
foreach (explode(',', $sortParam) as $sortField) {
|
|
302
342
|
$sortField = trim($sortField);
|
|
@@ -307,7 +347,7 @@ function buildSortBlock(sortableFields) {
|
|
|
307
347
|
$sortField = substr($sortField, 1);
|
|
308
348
|
}
|
|
309
349
|
|
|
310
|
-
if (in_array($sortField, $allowedSorts, true) || $sortField === 'created_at' || $sortField === 'updated_at') {
|
|
350
|
+
if (in_array($sortField, $allowedSorts, true) || $sortField === 'created_at' || $sortField === 'updated_at') {${sortColResolve}
|
|
311
351
|
${orderByLine}
|
|
312
352
|
}
|
|
313
353
|
}
|