omni-rest 0.3.2 → 0.3.3
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/cli.js +82 -14
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +82 -14
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1105,11 +1105,15 @@ function generateTableFile(config, modelConfig) {
|
|
|
1105
1105
|
if (bulkDelete) {
|
|
1106
1106
|
hookImports.push(useBulkDeleteHook);
|
|
1107
1107
|
}
|
|
1108
|
+
lines.push(`import { useState } from "react";`);
|
|
1108
1109
|
lines.push(`import DataTable from "../data-table";`);
|
|
1109
1110
|
lines.push(`import { ${columnsVar} } from "./${Model}Columns";`);
|
|
1110
1111
|
lines.push(`import { ${hookImports.join(", ")} } from "../../hooks/use${Model}";`);
|
|
1112
|
+
lines.push(`import { ${Model}Form } from "./${Model}Form";`);
|
|
1113
|
+
lines.push(`import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "../ui/dialog";`);
|
|
1111
1114
|
lines.push(``);
|
|
1112
1115
|
lines.push(`export function ${Model}Table() {`);
|
|
1116
|
+
lines.push(` const [isCreateOpen, setIsCreateOpen] = useState(false);`);
|
|
1113
1117
|
lines.push(` const { data } = ${useListHook}();`);
|
|
1114
1118
|
lines.push(` const ${varName}Delete = ${useDeleteHook}();`);
|
|
1115
1119
|
if (bulkDelete) {
|
|
@@ -1117,22 +1121,40 @@ function generateTableFile(config, modelConfig) {
|
|
|
1117
1121
|
}
|
|
1118
1122
|
lines.push(``);
|
|
1119
1123
|
lines.push(` return (`);
|
|
1124
|
+
lines.push(` <>`);
|
|
1120
1125
|
const dtProps = [
|
|
1121
|
-
`
|
|
1122
|
-
`
|
|
1123
|
-
`
|
|
1126
|
+
` title="${models}"`,
|
|
1127
|
+
` description="Manage ${models.toLowerCase()} in your system"`,
|
|
1128
|
+
` columns={${columnsVar}}`,
|
|
1129
|
+
` data={data?.data ?? []}`,
|
|
1130
|
+
` toggleAction={() => setIsCreateOpen(true)}`,
|
|
1131
|
+
` actionText="Create ${Model}"`,
|
|
1132
|
+
` onRowDelete={(row: any) => ${varName}Delete.mutate(row.id)}`
|
|
1124
1133
|
];
|
|
1125
1134
|
if (bulkDelete) {
|
|
1126
|
-
dtProps.push(`
|
|
1135
|
+
dtProps.push(` onMultiDelete={(rows: any[]) => ${varName}BulkDelete.mutate(rows.map((r) => r.id))}`);
|
|
1127
1136
|
}
|
|
1128
1137
|
if (canExport) {
|
|
1129
|
-
dtProps.push(`
|
|
1138
|
+
dtProps.push(` canExport={true}`);
|
|
1130
1139
|
}
|
|
1131
|
-
lines.push(`
|
|
1140
|
+
lines.push(` <DataTable`);
|
|
1132
1141
|
for (const prop of dtProps) {
|
|
1133
1142
|
lines.push(prop);
|
|
1134
1143
|
}
|
|
1135
|
-
lines.push(`
|
|
1144
|
+
lines.push(` />`);
|
|
1145
|
+
lines.push(``);
|
|
1146
|
+
lines.push(` <Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>`);
|
|
1147
|
+
lines.push(` <DialogContent className="max-w-3xl max-h-[90vh] overflow-y-auto">`);
|
|
1148
|
+
lines.push(` <DialogHeader>`);
|
|
1149
|
+
lines.push(` <DialogTitle>Create New ${Model}</DialogTitle>`);
|
|
1150
|
+
lines.push(` <DialogDescription>`);
|
|
1151
|
+
lines.push(` Fill in the information below to create a new ${varName}.`);
|
|
1152
|
+
lines.push(` </DialogDescription>`);
|
|
1153
|
+
lines.push(` </DialogHeader>`);
|
|
1154
|
+
lines.push(` <${Model}Form onSuccess={() => setIsCreateOpen(false)} />`);
|
|
1155
|
+
lines.push(` </DialogContent>`);
|
|
1156
|
+
lines.push(` </Dialog>`);
|
|
1157
|
+
lines.push(` </>`);
|
|
1136
1158
|
lines.push(` );`);
|
|
1137
1159
|
lines.push(`}`);
|
|
1138
1160
|
lines.push(``);
|
|
@@ -1171,7 +1193,7 @@ function generateFormFile(config, modelConfig) {
|
|
|
1171
1193
|
);
|
|
1172
1194
|
}
|
|
1173
1195
|
lines.push(``);
|
|
1174
|
-
lines.push(`export function ${name}Form({ id }: { id?: string }) {`);
|
|
1196
|
+
lines.push(`export function ${name}Form({ id, onSuccess }: { id?: string; onSuccess?: () => void }) {`);
|
|
1175
1197
|
lines.push(` const create${name} = useCreate${name}();`);
|
|
1176
1198
|
lines.push(` const update${name} = useUpdate${name}();`);
|
|
1177
1199
|
for (const { fieldName, relatedModel } of relationalFieldMeta) {
|
|
@@ -1221,24 +1243,36 @@ function generateFormFile(config, modelConfig) {
|
|
|
1221
1243
|
});
|
|
1222
1244
|
lines.push(` ];`);
|
|
1223
1245
|
lines.push(``);
|
|
1246
|
+
lines.push(` const handleSubmit = (data: any) => {`);
|
|
1247
|
+
lines.push(` const mutation = id ? update${name}.mutate({ id, data }) : create${name}.mutate(data);`);
|
|
1248
|
+
lines.push(` if (onSuccess) {`);
|
|
1249
|
+
lines.push(` // Call onSuccess after mutation completes`);
|
|
1250
|
+
lines.push(` Promise.resolve(mutation).then(() => onSuccess()).catch(() => {});`);
|
|
1251
|
+
lines.push(` }`);
|
|
1252
|
+
lines.push(` };`);
|
|
1253
|
+
lines.push(``);
|
|
1224
1254
|
lines.push(` return (`);
|
|
1225
1255
|
lines.push(` <FormGenerator`);
|
|
1226
1256
|
lines.push(` fields={fields}`);
|
|
1227
1257
|
lines.push(` schema={${name}CreateSchema}`);
|
|
1228
|
-
lines.push(
|
|
1229
|
-
` onSubmit={(data) => id ? update${name}.mutate({ id, data }) : create${name}.mutate(data)}`
|
|
1230
|
-
);
|
|
1258
|
+
lines.push(` onSubmit={handleSubmit}`);
|
|
1231
1259
|
lines.push(` steps={steps}`);
|
|
1232
1260
|
lines.push(` />`);
|
|
1233
1261
|
lines.push(` );`);
|
|
1234
1262
|
} else {
|
|
1263
|
+
lines.push(` const handleSubmit = (data: any) => {`);
|
|
1264
|
+
lines.push(` const mutation = id ? update${name}.mutate({ id, data }) : create${name}.mutate(data);`);
|
|
1265
|
+
lines.push(` if (onSuccess) {`);
|
|
1266
|
+
lines.push(` // Call onSuccess after mutation completes`);
|
|
1267
|
+
lines.push(` Promise.resolve(mutation).then(() => onSuccess()).catch(() => {});`);
|
|
1268
|
+
lines.push(` }`);
|
|
1269
|
+
lines.push(` };`);
|
|
1270
|
+
lines.push(``);
|
|
1235
1271
|
lines.push(` return (`);
|
|
1236
1272
|
lines.push(` <FormGenerator`);
|
|
1237
1273
|
lines.push(` fields={fields}`);
|
|
1238
1274
|
lines.push(` schema={${name}CreateSchema}`);
|
|
1239
|
-
lines.push(
|
|
1240
|
-
` onSubmit={(data) => id ? update${name}.mutate({ id, data }) : create${name}.mutate(data)}`
|
|
1241
|
-
);
|
|
1275
|
+
lines.push(` onSubmit={handleSubmit}`);
|
|
1242
1276
|
lines.push(` />`);
|
|
1243
1277
|
lines.push(` );`);
|
|
1244
1278
|
}
|
|
@@ -1314,6 +1348,35 @@ function generateMenuData(config) {
|
|
|
1314
1348
|
lines.push(``);
|
|
1315
1349
|
return lines.join("\n");
|
|
1316
1350
|
}
|
|
1351
|
+
|
|
1352
|
+
// src/frontend/codegen/providers.ts
|
|
1353
|
+
function generateProvidersFile(config) {
|
|
1354
|
+
const { staleTime, gcTime } = config;
|
|
1355
|
+
const lines = [];
|
|
1356
|
+
lines.push(`'use client'`);
|
|
1357
|
+
lines.push(``);
|
|
1358
|
+
lines.push(`import { QueryClient, QueryClientProvider } from '@tanstack/react-query'`);
|
|
1359
|
+
lines.push(`import { useState } from 'react'`);
|
|
1360
|
+
lines.push(``);
|
|
1361
|
+
lines.push(`export function Providers({ children }: { children: React.ReactNode }) {`);
|
|
1362
|
+
lines.push(` const [queryClient] = useState(() => new QueryClient({`);
|
|
1363
|
+
lines.push(` defaultOptions: {`);
|
|
1364
|
+
lines.push(` queries: {`);
|
|
1365
|
+
lines.push(` staleTime: ${staleTime},`);
|
|
1366
|
+
lines.push(` gcTime: ${gcTime},`);
|
|
1367
|
+
lines.push(` },`);
|
|
1368
|
+
lines.push(` },`);
|
|
1369
|
+
lines.push(` }))`);
|
|
1370
|
+
lines.push(``);
|
|
1371
|
+
lines.push(` return (`);
|
|
1372
|
+
lines.push(` <QueryClientProvider client={queryClient}>`);
|
|
1373
|
+
lines.push(` {children}`);
|
|
1374
|
+
lines.push(` </QueryClientProvider>`);
|
|
1375
|
+
lines.push(` )`);
|
|
1376
|
+
lines.push(`}`);
|
|
1377
|
+
lines.push(``);
|
|
1378
|
+
return lines.join("\n");
|
|
1379
|
+
}
|
|
1317
1380
|
var GREEN = "\x1B[32m";
|
|
1318
1381
|
var YELLOW = "\x1B[33m";
|
|
1319
1382
|
var BLUE = "\x1B[34m";
|
|
@@ -1424,6 +1487,11 @@ async function generateAll(config) {
|
|
|
1424
1487
|
}
|
|
1425
1488
|
const baseResults = await copyBaseComponents(outputDir, packageRoot);
|
|
1426
1489
|
results.push(...baseResults);
|
|
1490
|
+
if (framework === "nextjs" && structure.usesAppRouter) {
|
|
1491
|
+
const providersContent = generateProvidersFile(config);
|
|
1492
|
+
const providersPath = path3.join(outputDir, "components", "providers.tsx");
|
|
1493
|
+
results.push(await writeFile(providersPath, providersContent));
|
|
1494
|
+
}
|
|
1427
1495
|
if (generateMenu) {
|
|
1428
1496
|
const menuContent = generateMenuData(config);
|
|
1429
1497
|
const menuPath = path3.join(outputDir, "lib", "menu-data.ts");
|