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.js
CHANGED
|
@@ -1127,11 +1127,15 @@ function generateTableFile(config, modelConfig) {
|
|
|
1127
1127
|
if (bulkDelete) {
|
|
1128
1128
|
hookImports.push(useBulkDeleteHook);
|
|
1129
1129
|
}
|
|
1130
|
+
lines.push(`import { useState } from "react";`);
|
|
1130
1131
|
lines.push(`import DataTable from "../data-table";`);
|
|
1131
1132
|
lines.push(`import { ${columnsVar} } from "./${Model}Columns";`);
|
|
1132
1133
|
lines.push(`import { ${hookImports.join(", ")} } from "../../hooks/use${Model}";`);
|
|
1134
|
+
lines.push(`import { ${Model}Form } from "./${Model}Form";`);
|
|
1135
|
+
lines.push(`import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from "../ui/dialog";`);
|
|
1133
1136
|
lines.push(``);
|
|
1134
1137
|
lines.push(`export function ${Model}Table() {`);
|
|
1138
|
+
lines.push(` const [isCreateOpen, setIsCreateOpen] = useState(false);`);
|
|
1135
1139
|
lines.push(` const { data } = ${useListHook}();`);
|
|
1136
1140
|
lines.push(` const ${varName}Delete = ${useDeleteHook}();`);
|
|
1137
1141
|
if (bulkDelete) {
|
|
@@ -1139,22 +1143,40 @@ function generateTableFile(config, modelConfig) {
|
|
|
1139
1143
|
}
|
|
1140
1144
|
lines.push(``);
|
|
1141
1145
|
lines.push(` return (`);
|
|
1146
|
+
lines.push(` <>`);
|
|
1142
1147
|
const dtProps = [
|
|
1143
|
-
`
|
|
1144
|
-
`
|
|
1145
|
-
`
|
|
1148
|
+
` title="${models}"`,
|
|
1149
|
+
` description="Manage ${models.toLowerCase()} in your system"`,
|
|
1150
|
+
` columns={${columnsVar}}`,
|
|
1151
|
+
` data={data?.data ?? []}`,
|
|
1152
|
+
` toggleAction={() => setIsCreateOpen(true)}`,
|
|
1153
|
+
` actionText="Create ${Model}"`,
|
|
1154
|
+
` onRowDelete={(row: any) => ${varName}Delete.mutate(row.id)}`
|
|
1146
1155
|
];
|
|
1147
1156
|
if (bulkDelete) {
|
|
1148
|
-
dtProps.push(`
|
|
1157
|
+
dtProps.push(` onMultiDelete={(rows: any[]) => ${varName}BulkDelete.mutate(rows.map((r) => r.id))}`);
|
|
1149
1158
|
}
|
|
1150
1159
|
if (canExport) {
|
|
1151
|
-
dtProps.push(`
|
|
1160
|
+
dtProps.push(` canExport={true}`);
|
|
1152
1161
|
}
|
|
1153
|
-
lines.push(`
|
|
1162
|
+
lines.push(` <DataTable`);
|
|
1154
1163
|
for (const prop of dtProps) {
|
|
1155
1164
|
lines.push(prop);
|
|
1156
1165
|
}
|
|
1157
|
-
lines.push(`
|
|
1166
|
+
lines.push(` />`);
|
|
1167
|
+
lines.push(``);
|
|
1168
|
+
lines.push(` <Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>`);
|
|
1169
|
+
lines.push(` <DialogContent className="max-w-3xl max-h-[90vh] overflow-y-auto">`);
|
|
1170
|
+
lines.push(` <DialogHeader>`);
|
|
1171
|
+
lines.push(` <DialogTitle>Create New ${Model}</DialogTitle>`);
|
|
1172
|
+
lines.push(` <DialogDescription>`);
|
|
1173
|
+
lines.push(` Fill in the information below to create a new ${varName}.`);
|
|
1174
|
+
lines.push(` </DialogDescription>`);
|
|
1175
|
+
lines.push(` </DialogHeader>`);
|
|
1176
|
+
lines.push(` <${Model}Form onSuccess={() => setIsCreateOpen(false)} />`);
|
|
1177
|
+
lines.push(` </DialogContent>`);
|
|
1178
|
+
lines.push(` </Dialog>`);
|
|
1179
|
+
lines.push(` </>`);
|
|
1158
1180
|
lines.push(` );`);
|
|
1159
1181
|
lines.push(`}`);
|
|
1160
1182
|
lines.push(``);
|
|
@@ -1193,7 +1215,7 @@ function generateFormFile(config, modelConfig) {
|
|
|
1193
1215
|
);
|
|
1194
1216
|
}
|
|
1195
1217
|
lines.push(``);
|
|
1196
|
-
lines.push(`export function ${name}Form({ id }: { id?: string }) {`);
|
|
1218
|
+
lines.push(`export function ${name}Form({ id, onSuccess }: { id?: string; onSuccess?: () => void }) {`);
|
|
1197
1219
|
lines.push(` const create${name} = useCreate${name}();`);
|
|
1198
1220
|
lines.push(` const update${name} = useUpdate${name}();`);
|
|
1199
1221
|
for (const { fieldName, relatedModel } of relationalFieldMeta) {
|
|
@@ -1243,24 +1265,36 @@ function generateFormFile(config, modelConfig) {
|
|
|
1243
1265
|
});
|
|
1244
1266
|
lines.push(` ];`);
|
|
1245
1267
|
lines.push(``);
|
|
1268
|
+
lines.push(` const handleSubmit = (data: any) => {`);
|
|
1269
|
+
lines.push(` const mutation = id ? update${name}.mutate({ id, data }) : create${name}.mutate(data);`);
|
|
1270
|
+
lines.push(` if (onSuccess) {`);
|
|
1271
|
+
lines.push(` // Call onSuccess after mutation completes`);
|
|
1272
|
+
lines.push(` Promise.resolve(mutation).then(() => onSuccess()).catch(() => {});`);
|
|
1273
|
+
lines.push(` }`);
|
|
1274
|
+
lines.push(` };`);
|
|
1275
|
+
lines.push(``);
|
|
1246
1276
|
lines.push(` return (`);
|
|
1247
1277
|
lines.push(` <FormGenerator`);
|
|
1248
1278
|
lines.push(` fields={fields}`);
|
|
1249
1279
|
lines.push(` schema={${name}CreateSchema}`);
|
|
1250
|
-
lines.push(
|
|
1251
|
-
` onSubmit={(data) => id ? update${name}.mutate({ id, data }) : create${name}.mutate(data)}`
|
|
1252
|
-
);
|
|
1280
|
+
lines.push(` onSubmit={handleSubmit}`);
|
|
1253
1281
|
lines.push(` steps={steps}`);
|
|
1254
1282
|
lines.push(` />`);
|
|
1255
1283
|
lines.push(` );`);
|
|
1256
1284
|
} else {
|
|
1285
|
+
lines.push(` const handleSubmit = (data: any) => {`);
|
|
1286
|
+
lines.push(` const mutation = id ? update${name}.mutate({ id, data }) : create${name}.mutate(data);`);
|
|
1287
|
+
lines.push(` if (onSuccess) {`);
|
|
1288
|
+
lines.push(` // Call onSuccess after mutation completes`);
|
|
1289
|
+
lines.push(` Promise.resolve(mutation).then(() => onSuccess()).catch(() => {});`);
|
|
1290
|
+
lines.push(` }`);
|
|
1291
|
+
lines.push(` };`);
|
|
1292
|
+
lines.push(``);
|
|
1257
1293
|
lines.push(` return (`);
|
|
1258
1294
|
lines.push(` <FormGenerator`);
|
|
1259
1295
|
lines.push(` fields={fields}`);
|
|
1260
1296
|
lines.push(` schema={${name}CreateSchema}`);
|
|
1261
|
-
lines.push(
|
|
1262
|
-
` onSubmit={(data) => id ? update${name}.mutate({ id, data }) : create${name}.mutate(data)}`
|
|
1263
|
-
);
|
|
1297
|
+
lines.push(` onSubmit={handleSubmit}`);
|
|
1264
1298
|
lines.push(` />`);
|
|
1265
1299
|
lines.push(` );`);
|
|
1266
1300
|
}
|
|
@@ -1336,6 +1370,35 @@ function generateMenuData(config) {
|
|
|
1336
1370
|
lines.push(``);
|
|
1337
1371
|
return lines.join("\n");
|
|
1338
1372
|
}
|
|
1373
|
+
|
|
1374
|
+
// src/frontend/codegen/providers.ts
|
|
1375
|
+
function generateProvidersFile(config) {
|
|
1376
|
+
const { staleTime, gcTime } = config;
|
|
1377
|
+
const lines = [];
|
|
1378
|
+
lines.push(`'use client'`);
|
|
1379
|
+
lines.push(``);
|
|
1380
|
+
lines.push(`import { QueryClient, QueryClientProvider } from '@tanstack/react-query'`);
|
|
1381
|
+
lines.push(`import { useState } from 'react'`);
|
|
1382
|
+
lines.push(``);
|
|
1383
|
+
lines.push(`export function Providers({ children }: { children: React.ReactNode }) {`);
|
|
1384
|
+
lines.push(` const [queryClient] = useState(() => new QueryClient({`);
|
|
1385
|
+
lines.push(` defaultOptions: {`);
|
|
1386
|
+
lines.push(` queries: {`);
|
|
1387
|
+
lines.push(` staleTime: ${staleTime},`);
|
|
1388
|
+
lines.push(` gcTime: ${gcTime},`);
|
|
1389
|
+
lines.push(` },`);
|
|
1390
|
+
lines.push(` },`);
|
|
1391
|
+
lines.push(` }))`);
|
|
1392
|
+
lines.push(``);
|
|
1393
|
+
lines.push(` return (`);
|
|
1394
|
+
lines.push(` <QueryClientProvider client={queryClient}>`);
|
|
1395
|
+
lines.push(` {children}`);
|
|
1396
|
+
lines.push(` </QueryClientProvider>`);
|
|
1397
|
+
lines.push(` )`);
|
|
1398
|
+
lines.push(`}`);
|
|
1399
|
+
lines.push(``);
|
|
1400
|
+
return lines.join("\n");
|
|
1401
|
+
}
|
|
1339
1402
|
var GREEN = "\x1B[32m";
|
|
1340
1403
|
var YELLOW = "\x1B[33m";
|
|
1341
1404
|
var BLUE = "\x1B[34m";
|
|
@@ -1446,6 +1509,11 @@ async function generateAll(config) {
|
|
|
1446
1509
|
}
|
|
1447
1510
|
const baseResults = await copyBaseComponents(outputDir, packageRoot);
|
|
1448
1511
|
results.push(...baseResults);
|
|
1512
|
+
if (framework === "nextjs" && structure.usesAppRouter) {
|
|
1513
|
+
const providersContent = generateProvidersFile(config);
|
|
1514
|
+
const providersPath = path3__namespace.join(outputDir, "components", "providers.tsx");
|
|
1515
|
+
results.push(await writeFile(providersPath, providersContent));
|
|
1516
|
+
}
|
|
1449
1517
|
if (generateMenu) {
|
|
1450
1518
|
const menuContent = generateMenuData(config);
|
|
1451
1519
|
const menuPath = path3__namespace.join(outputDir, "lib", "menu-data.ts");
|