@varity-labs/sdk 2.0.0-alpha.1
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/LICENSE +31 -0
- package/README.md +253 -0
- package/dist/analytics/index.d.ts +7 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics/tracker.d.ts +128 -0
- package/dist/analytics/tracker.d.ts.map +1 -0
- package/dist/analytics/tracker.js +203 -0
- package/dist/blockchain/BlockchainService.d.ts +100 -0
- package/dist/blockchain/BlockchainService.d.ts.map +1 -0
- package/dist/blockchain/BlockchainService.js +188 -0
- package/dist/blockchain/NFTLicensingService.d.ts +69 -0
- package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
- package/dist/blockchain/NFTLicensingService.js +136 -0
- package/dist/blockchain/RevenueSplitService.d.ts +71 -0
- package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
- package/dist/blockchain/RevenueSplitService.js +111 -0
- package/dist/blockchain/index.d.ts +48 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +46 -0
- package/dist/blockchain/types.d.ts +63 -0
- package/dist/blockchain/types.d.ts.map +1 -0
- package/dist/blockchain/types.js +6 -0
- package/dist/chains/arbitrum.d.ts +89 -0
- package/dist/chains/arbitrum.d.ts.map +1 -0
- package/dist/chains/arbitrum.js +134 -0
- package/dist/chains/base.d.ts +84 -0
- package/dist/chains/base.d.ts.map +1 -0
- package/dist/chains/base.js +131 -0
- package/dist/chains/index.d.ts +36 -0
- package/dist/chains/index.d.ts.map +1 -0
- package/dist/chains/index.js +32 -0
- package/dist/chains/registry.d.ts +113 -0
- package/dist/chains/registry.d.ts.map +1 -0
- package/dist/chains/registry.js +201 -0
- package/dist/chains/varityL3.d.ts +81 -0
- package/dist/chains/varityL3.d.ts.map +1 -0
- package/dist/chains/varityL3.js +125 -0
- package/dist/cli/commands/clone.d.ts +8 -0
- package/dist/cli/commands/clone.d.ts.map +1 -0
- package/dist/cli/commands/clone.js +391 -0
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +40 -0
- package/dist/cli/commands/generate.d.ts +8 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +303 -0
- package/dist/cli/commands/init.d.ts +8 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +317 -0
- package/dist/cli/commands/validate.d.ts +8 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +69 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +33 -0
- package/dist/cli/utils/logger.d.ts +17 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +35 -0
- package/dist/cli/utils/prompts.d.ts +21 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +103 -0
- package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
- package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
- package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
- package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
- package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
- package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
- package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
- package/dist/contracts/addresses.d.ts +88 -0
- package/dist/contracts/addresses.d.ts.map +1 -0
- package/dist/contracts/addresses.js +94 -0
- package/dist/contracts/index.d.ts +7 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +6 -0
- package/dist/core/VaritySDK.d.ts +177 -0
- package/dist/core/VaritySDK.d.ts.map +1 -0
- package/dist/core/VaritySDK.js +325 -0
- package/dist/core/config.d.ts +120 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +187 -0
- package/dist/core/credentials-proxy.d.ts +157 -0
- package/dist/core/credentials-proxy.d.ts.map +1 -0
- package/dist/core/credentials-proxy.js +345 -0
- package/dist/core/credentials.d.ts +219 -0
- package/dist/core/credentials.d.ts.map +1 -0
- package/dist/core/credentials.js +345 -0
- package/dist/core/template-loader.d.ts +15 -0
- package/dist/core/template-loader.d.ts.map +1 -0
- package/dist/core/template-loader.js +380 -0
- package/dist/core/template.d.ts +321 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +189 -0
- package/dist/core/types.d.ts +572 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +52 -0
- package/dist/dev/dev-server.d.ts +16 -0
- package/dist/dev/dev-server.d.ts.map +1 -0
- package/dist/dev/dev-server.js +119 -0
- package/dist/generators/contracts/generator.d.ts +21 -0
- package/dist/generators/contracts/generator.d.ts.map +1 -0
- package/dist/generators/contracts/generator.js +252 -0
- package/dist/generators/tests/generator.d.ts +20 -0
- package/dist/generators/tests/generator.d.ts.map +1 -0
- package/dist/generators/tests/generator.js +375 -0
- package/dist/generators/types/generator.d.ts +19 -0
- package/dist/generators/types/generator.d.ts.map +1 -0
- package/dist/generators/types/generator.js +165 -0
- package/dist/generators/ui/component-generator.d.ts +20 -0
- package/dist/generators/ui/component-generator.d.ts.map +1 -0
- package/dist/generators/ui/component-generator.js +749 -0
- package/dist/generators/ui/dashboard-generator.d.ts +20 -0
- package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
- package/dist/generators/ui/dashboard-generator.js +349 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
- package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
- package/dist/modules/analytics/AnalyticsModule.js +274 -0
- package/dist/modules/analytics/index.d.ts +3 -0
- package/dist/modules/analytics/index.d.ts.map +1 -0
- package/dist/modules/analytics/index.js +1 -0
- package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
- package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
- package/dist/modules/auth/AccessKeyModule.js +322 -0
- package/dist/modules/auth/AuthModule.d.ts +133 -0
- package/dist/modules/auth/AuthModule.d.ts.map +1 -0
- package/dist/modules/auth/AuthModule.js +214 -0
- package/dist/modules/auth/index.d.ts +8 -0
- package/dist/modules/auth/index.d.ts.map +1 -0
- package/dist/modules/auth/index.js +6 -0
- package/dist/modules/cache/CacheModule.d.ts +279 -0
- package/dist/modules/cache/CacheModule.d.ts.map +1 -0
- package/dist/modules/cache/CacheModule.js +493 -0
- package/dist/modules/cache/index.d.ts +3 -0
- package/dist/modules/cache/index.d.ts.map +1 -0
- package/dist/modules/cache/index.js +1 -0
- package/dist/modules/compute/ComputeModule.d.ts +226 -0
- package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
- package/dist/modules/compute/ComputeModule.js +379 -0
- package/dist/modules/compute/index.d.ts +6 -0
- package/dist/modules/compute/index.d.ts.map +1 -0
- package/dist/modules/compute/index.js +4 -0
- package/dist/modules/contracts/ContractsModule.d.ts +164 -0
- package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
- package/dist/modules/contracts/ContractsModule.js +242 -0
- package/dist/modules/contracts/index.d.ts +6 -0
- package/dist/modules/contracts/index.d.ts.map +1 -0
- package/dist/modules/contracts/index.js +4 -0
- package/dist/modules/export/ExportModule.d.ts +346 -0
- package/dist/modules/export/ExportModule.d.ts.map +1 -0
- package/dist/modules/export/ExportModule.js +432 -0
- package/dist/modules/export/index.d.ts +3 -0
- package/dist/modules/export/index.d.ts.map +1 -0
- package/dist/modules/export/index.js +1 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
- package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
- package/dist/modules/forecasting/ForecastingModule.js +310 -0
- package/dist/modules/forecasting/index.d.ts +3 -0
- package/dist/modules/forecasting/index.d.ts.map +1 -0
- package/dist/modules/forecasting/index.js +1 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
- package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
- package/dist/modules/monitoring/MonitoringModule.js +483 -0
- package/dist/modules/monitoring/index.d.ts +3 -0
- package/dist/modules/monitoring/index.d.ts.map +1 -0
- package/dist/modules/monitoring/index.js +1 -0
- package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
- package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
- package/dist/modules/notifications/NotificationsModule.js +418 -0
- package/dist/modules/notifications/index.d.ts +3 -0
- package/dist/modules/notifications/index.d.ts.map +1 -0
- package/dist/modules/notifications/index.js +1 -0
- package/dist/modules/oracle/OracleModule.d.ts +110 -0
- package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
- package/dist/modules/oracle/OracleModule.js +151 -0
- package/dist/modules/oracle/index.d.ts +6 -0
- package/dist/modules/oracle/index.d.ts.map +1 -0
- package/dist/modules/oracle/index.js +4 -0
- package/dist/modules/storage/S3Module.d.ts +377 -0
- package/dist/modules/storage/S3Module.d.ts.map +1 -0
- package/dist/modules/storage/S3Module.js +680 -0
- package/dist/modules/storage/StorageModule.d.ts +157 -0
- package/dist/modules/storage/StorageModule.d.ts.map +1 -0
- package/dist/modules/storage/StorageModule.js +302 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
- package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
- package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
- package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
- package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
- package/dist/modules/storage/adapters/index.d.ts +12 -0
- package/dist/modules/storage/adapters/index.d.ts.map +1 -0
- package/dist/modules/storage/adapters/index.js +12 -0
- package/dist/modules/storage/index.d.ts +16 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +15 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
- package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
- package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
- package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
- package/dist/modules/storage/tiering/MetadataStore.js +535 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
- package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
- package/dist/modules/storage/tiering/TieringEngine.js +419 -0
- package/dist/modules/storage/tiering/example.d.ts +8 -0
- package/dist/modules/storage/tiering/example.d.ts.map +1 -0
- package/dist/modules/storage/tiering/example.js +250 -0
- package/dist/modules/storage/tiering/index.d.ts +17 -0
- package/dist/modules/storage/tiering/index.d.ts.map +1 -0
- package/dist/modules/storage/tiering/index.js +13 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
- package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
- package/dist/modules/webhooks/WebhooksModule.js +359 -0
- package/dist/modules/webhooks/index.d.ts +3 -0
- package/dist/modules/webhooks/index.d.ts.map +1 -0
- package/dist/modules/webhooks/index.js +1 -0
- package/dist/modules/zk/ZKModule.d.ts +153 -0
- package/dist/modules/zk/ZKModule.d.ts.map +1 -0
- package/dist/modules/zk/ZKModule.js +262 -0
- package/dist/modules/zk/index.d.ts +7 -0
- package/dist/modules/zk/index.d.ts.map +1 -0
- package/dist/modules/zk/index.js +4 -0
- package/dist/thirdweb/BridgeClient.d.ts +228 -0
- package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
- package/dist/thirdweb/BridgeClient.js +160 -0
- package/dist/thirdweb/EngineClient.d.ts +396 -0
- package/dist/thirdweb/EngineClient.d.ts.map +1 -0
- package/dist/thirdweb/EngineClient.js +386 -0
- package/dist/thirdweb/GatewayClient.d.ts +190 -0
- package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
- package/dist/thirdweb/GatewayClient.js +257 -0
- package/dist/thirdweb/NebulaClient.d.ts +292 -0
- package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
- package/dist/thirdweb/NebulaClient.js +180 -0
- package/dist/thirdweb/StorageClient.d.ts +445 -0
- package/dist/thirdweb/StorageClient.d.ts.map +1 -0
- package/dist/thirdweb/StorageClient.js +405 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
- package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
- package/dist/thirdweb/ThirdwebWrapper.js +332 -0
- package/dist/thirdweb/index.d.ts +21 -0
- package/dist/thirdweb/index.d.ts.map +1 -0
- package/dist/thirdweb/index.js +28 -0
- package/dist/thirdweb/varity-chain.d.ts +48 -0
- package/dist/thirdweb/varity-chain.d.ts.map +1 -0
- package/dist/thirdweb/varity-chain.js +64 -0
- package/dist/thirdweb/x402Client.d.ts +319 -0
- package/dist/thirdweb/x402Client.d.ts.map +1 -0
- package/dist/thirdweb/x402Client.js +223 -0
- package/dist/tracking/gasTracker.d.ts +158 -0
- package/dist/tracking/gasTracker.d.ts.map +1 -0
- package/dist/tracking/gasTracker.js +227 -0
- package/dist/tracking/index.d.ts +10 -0
- package/dist/tracking/index.d.ts.map +1 -0
- package/dist/tracking/index.js +8 -0
- package/dist/tracking/types.d.ts +327 -0
- package/dist/tracking/types.d.ts.map +1 -0
- package/dist/tracking/types.js +8 -0
- package/dist/ui/components/ChartWidget.d.ts +36 -0
- package/dist/ui/components/ChartWidget.d.ts.map +1 -0
- package/dist/ui/components/ChartWidget.js +82 -0
- package/dist/ui/components/DashboardLayout.d.ts +41 -0
- package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
- package/dist/ui/components/DashboardLayout.js +102 -0
- package/dist/ui/components/DataTable.d.ts +49 -0
- package/dist/ui/components/DataTable.d.ts.map +1 -0
- package/dist/ui/components/DataTable.js +96 -0
- package/dist/ui/components/EntityForm.d.ts +60 -0
- package/dist/ui/components/EntityForm.d.ts.map +1 -0
- package/dist/ui/components/EntityForm.js +182 -0
- package/dist/ui/components/KPICard.d.ts +29 -0
- package/dist/ui/components/KPICard.d.ts.map +1 -0
- package/dist/ui/components/KPICard.js +61 -0
- package/dist/ui/components/Modal.d.ts +34 -0
- package/dist/ui/components/Modal.d.ts.map +1 -0
- package/dist/ui/components/Modal.js +30 -0
- package/dist/ui/components/index.d.ts +18 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +11 -0
- package/dist/validation/template-validator.d.ts +25 -0
- package/dist/validation/template-validator.d.ts.map +1 -0
- package/dist/validation/template-validator.js +305 -0
- package/package.json +102 -0
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI Component Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates CRUD React components from template entity definitions
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
/**
|
|
9
|
+
* Generate UI components from template configuration
|
|
10
|
+
*/
|
|
11
|
+
export async function generateUIComponents(options) {
|
|
12
|
+
const result = {
|
|
13
|
+
components: [],
|
|
14
|
+
success: false,
|
|
15
|
+
errors: []
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
// Load template configuration
|
|
19
|
+
const templatePath = path.resolve(options.templatePath);
|
|
20
|
+
if (!fs.existsSync(templatePath)) {
|
|
21
|
+
throw new Error(`Template file not found: ${templatePath}`);
|
|
22
|
+
}
|
|
23
|
+
const templateContent = fs.readFileSync(templatePath, 'utf-8');
|
|
24
|
+
const template = JSON.parse(templateContent);
|
|
25
|
+
// Create output directories
|
|
26
|
+
const outputPath = path.resolve(options.outputPath);
|
|
27
|
+
const componentsPath = options.componentsPath || path.join(outputPath, 'src', 'components', 'entities');
|
|
28
|
+
if (!fs.existsSync(componentsPath)) {
|
|
29
|
+
fs.mkdirSync(componentsPath, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
// Generate components for each entity
|
|
32
|
+
for (const entity of template.entities) {
|
|
33
|
+
try {
|
|
34
|
+
// Generate Create Form
|
|
35
|
+
const createFormCode = generateCreateForm(entity, template);
|
|
36
|
+
const createFormFile = path.join(componentsPath, `${capitalize(entity.name)}CreateForm.tsx`);
|
|
37
|
+
fs.writeFileSync(createFormFile, createFormCode);
|
|
38
|
+
result.components.push(createFormFile);
|
|
39
|
+
// Generate Edit Form
|
|
40
|
+
const editFormCode = generateEditForm(entity, template);
|
|
41
|
+
const editFormFile = path.join(componentsPath, `${capitalize(entity.name)}EditForm.tsx`);
|
|
42
|
+
fs.writeFileSync(editFormFile, editFormCode);
|
|
43
|
+
result.components.push(editFormFile);
|
|
44
|
+
// Generate Detail View
|
|
45
|
+
const detailCode = generateDetailView(entity, template);
|
|
46
|
+
const detailFile = path.join(componentsPath, `${capitalize(entity.name)}Detail.tsx`);
|
|
47
|
+
fs.writeFileSync(detailFile, detailCode);
|
|
48
|
+
result.components.push(detailFile);
|
|
49
|
+
// Generate List View
|
|
50
|
+
const listCode = generateListView(entity, template);
|
|
51
|
+
const listFile = path.join(componentsPath, `${capitalize(entity.name)}List.tsx`);
|
|
52
|
+
fs.writeFileSync(listFile, listCode);
|
|
53
|
+
result.components.push(listFile);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
result.errors.push(`Failed to generate components for entity ${entity.name}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Generate index file
|
|
60
|
+
const indexCode = generateIndexFile(template.entities);
|
|
61
|
+
const indexFile = path.join(componentsPath, 'index.ts');
|
|
62
|
+
fs.writeFileSync(indexFile, indexCode);
|
|
63
|
+
result.components.push(indexFile);
|
|
64
|
+
result.success = result.errors.length === 0;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
result.errors.push(`Failed to generate UI components: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate Create Form component
|
|
73
|
+
*/
|
|
74
|
+
function generateCreateForm(entity, template) {
|
|
75
|
+
const entityName = capitalize(entity.name);
|
|
76
|
+
const entityDisplayName = entity.displayName || entityName;
|
|
77
|
+
const contractMap = getContractMapping(entity);
|
|
78
|
+
// Get fields excluding auto-generated ones
|
|
79
|
+
const formFields = entity.fields.filter(f => !['createdAt', 'updatedAt', 'isActive', entity.idField].includes(f.name));
|
|
80
|
+
const formFieldsConfig = formFields.map(field => ({
|
|
81
|
+
name: field.name,
|
|
82
|
+
label: field.label,
|
|
83
|
+
type: mapFieldTypeToFormType(field.type),
|
|
84
|
+
required: field.required || false,
|
|
85
|
+
helperText: field.description || undefined,
|
|
86
|
+
enumValues: field.enumValues || undefined
|
|
87
|
+
}));
|
|
88
|
+
return `/**
|
|
89
|
+
* ${entityDisplayName} Create Form
|
|
90
|
+
*
|
|
91
|
+
* Auto-generated from template: ${template.name}
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
import React, { useState } from 'react'
|
|
95
|
+
import { Box, Alert } from '@mui/material'
|
|
96
|
+
import { EntityForm, FormField } from '@varity-labs/sdk/ui/components'
|
|
97
|
+
import { useSDK } from '../hooks/useSDK'
|
|
98
|
+
|
|
99
|
+
const formFields: FormField[] = ${JSON.stringify(formFieldsConfig, null, 2)}
|
|
100
|
+
|
|
101
|
+
export interface ${entityName}CreateFormProps {
|
|
102
|
+
onSuccess?: (id: string) => void
|
|
103
|
+
onCancel?: () => void
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const ${entityName}CreateForm: React.FC<${entityName}CreateFormProps> = ({
|
|
107
|
+
onSuccess,
|
|
108
|
+
onCancel
|
|
109
|
+
}) => {
|
|
110
|
+
const { sdk } = useSDK()
|
|
111
|
+
const [loading, setLoading] = useState(false)
|
|
112
|
+
const [error, setError] = useState<string>('')
|
|
113
|
+
|
|
114
|
+
const handleSubmit = async (formData: Record<string, any>) => {
|
|
115
|
+
setLoading(true)
|
|
116
|
+
setError('')
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
// Call contract to create ${entity.name}
|
|
120
|
+
const tx = await sdk.contracts.send(
|
|
121
|
+
'${contractMap.contractName}',
|
|
122
|
+
'${contractMap.functions.create}',
|
|
123
|
+
Object.values(formData)
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
// Wait for transaction
|
|
127
|
+
await tx.wait()
|
|
128
|
+
|
|
129
|
+
// Get created ID from event
|
|
130
|
+
const events = await sdk.contracts.getEvents('${contractMap.contractName}', '${contractMap.events.created}')
|
|
131
|
+
const createdId = events[0]?.args?.${entity.idField}
|
|
132
|
+
|
|
133
|
+
if (onSuccess && createdId) {
|
|
134
|
+
onSuccess(createdId)
|
|
135
|
+
}
|
|
136
|
+
} catch (err) {
|
|
137
|
+
setError(err instanceof Error ? err.message : 'Failed to create ${entity.name}')
|
|
138
|
+
throw err
|
|
139
|
+
} finally {
|
|
140
|
+
setLoading(false)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<Box>
|
|
146
|
+
{error && (
|
|
147
|
+
<Alert severity="error" sx={{ mb: 2 }}>
|
|
148
|
+
{error}
|
|
149
|
+
</Alert>
|
|
150
|
+
)}
|
|
151
|
+
<EntityForm
|
|
152
|
+
title="Create ${entityDisplayName}"
|
|
153
|
+
fields={formFields}
|
|
154
|
+
onSubmit={handleSubmit}
|
|
155
|
+
onCancel={onCancel}
|
|
156
|
+
submitText="Create ${entityDisplayName}"
|
|
157
|
+
loading={loading}
|
|
158
|
+
/>
|
|
159
|
+
</Box>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Generate Edit Form component
|
|
166
|
+
*/
|
|
167
|
+
function generateEditForm(entity, template) {
|
|
168
|
+
const entityName = capitalize(entity.name);
|
|
169
|
+
const entityDisplayName = entity.displayName || entityName;
|
|
170
|
+
const contractMap = getContractMapping(entity);
|
|
171
|
+
// Get editable fields
|
|
172
|
+
const formFields = entity.fields.filter(f => !['createdAt', 'updatedAt', 'isActive', entity.idField].includes(f.name));
|
|
173
|
+
const formFieldsConfig = formFields.map(field => ({
|
|
174
|
+
name: field.name,
|
|
175
|
+
label: field.label,
|
|
176
|
+
type: mapFieldTypeToFormType(field.type),
|
|
177
|
+
required: field.required || false,
|
|
178
|
+
helperText: field.description || undefined,
|
|
179
|
+
enumValues: field.enumValues || undefined
|
|
180
|
+
}));
|
|
181
|
+
return `/**
|
|
182
|
+
* ${entityDisplayName} Edit Form
|
|
183
|
+
*
|
|
184
|
+
* Auto-generated from template: ${template.name}
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
import React, { useState, useEffect } from 'react'
|
|
188
|
+
import { Box, Alert, CircularProgress } from '@mui/material'
|
|
189
|
+
import { EntityForm, FormField } from '@varity-labs/sdk/ui/components'
|
|
190
|
+
import { useSDK } from '../hooks/useSDK'
|
|
191
|
+
|
|
192
|
+
const formFields: FormField[] = ${JSON.stringify(formFieldsConfig, null, 2)}
|
|
193
|
+
|
|
194
|
+
export interface ${entityName}EditFormProps {
|
|
195
|
+
${entity.idField}: string
|
|
196
|
+
onSuccess?: () => void
|
|
197
|
+
onCancel?: () => void
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export const ${entityName}EditForm: React.FC<${entityName}EditFormProps> = ({
|
|
201
|
+
${entity.idField},
|
|
202
|
+
onSuccess,
|
|
203
|
+
onCancel
|
|
204
|
+
}) => {
|
|
205
|
+
const { sdk } = useSDK()
|
|
206
|
+
const [loading, setLoading] = useState(false)
|
|
207
|
+
const [loadingData, setLoadingData] = useState(true)
|
|
208
|
+
const [error, setError] = useState<string>('')
|
|
209
|
+
const [initialData, setInitialData] = useState<Record<string, any>>({})
|
|
210
|
+
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
loadData()
|
|
213
|
+
}, [${entity.idField}])
|
|
214
|
+
|
|
215
|
+
const loadData = async () => {
|
|
216
|
+
setLoadingData(true)
|
|
217
|
+
try {
|
|
218
|
+
const data = await sdk.contracts.call(
|
|
219
|
+
'${contractMap.contractName}',
|
|
220
|
+
'${contractMap.functions.get}',
|
|
221
|
+
[${entity.idField}]
|
|
222
|
+
)
|
|
223
|
+
setInitialData(data)
|
|
224
|
+
} catch (err) {
|
|
225
|
+
setError(err instanceof Error ? err.message : 'Failed to load ${entity.name}')
|
|
226
|
+
} finally {
|
|
227
|
+
setLoadingData(false)
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const handleSubmit = async (formData: Record<string, any>) => {
|
|
232
|
+
setLoading(true)
|
|
233
|
+
setError('')
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
// Call contract to update ${entity.name}
|
|
237
|
+
const tx = await sdk.contracts.send(
|
|
238
|
+
'${contractMap.contractName}',
|
|
239
|
+
'${contractMap.functions.update}',
|
|
240
|
+
[${entity.idField}, ...Object.values(formData)]
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
// Wait for transaction
|
|
244
|
+
await tx.wait()
|
|
245
|
+
|
|
246
|
+
if (onSuccess) {
|
|
247
|
+
onSuccess()
|
|
248
|
+
}
|
|
249
|
+
} catch (err) {
|
|
250
|
+
setError(err instanceof Error ? err.message : 'Failed to update ${entity.name}')
|
|
251
|
+
throw err
|
|
252
|
+
} finally {
|
|
253
|
+
setLoading(false)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (loadingData) {
|
|
258
|
+
return (
|
|
259
|
+
<Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}>
|
|
260
|
+
<CircularProgress />
|
|
261
|
+
</Box>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return (
|
|
266
|
+
<Box>
|
|
267
|
+
{error && (
|
|
268
|
+
<Alert severity="error" sx={{ mb: 2 }}>
|
|
269
|
+
{error}
|
|
270
|
+
</Alert>
|
|
271
|
+
)}
|
|
272
|
+
<EntityForm
|
|
273
|
+
title="Edit ${entityDisplayName}"
|
|
274
|
+
fields={formFields}
|
|
275
|
+
onSubmit={handleSubmit}
|
|
276
|
+
onCancel={onCancel}
|
|
277
|
+
submitText="Update ${entityDisplayName}"
|
|
278
|
+
initialData={initialData}
|
|
279
|
+
loading={loading}
|
|
280
|
+
/>
|
|
281
|
+
</Box>
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Generate Detail View component
|
|
288
|
+
*/
|
|
289
|
+
function generateDetailView(entity, template) {
|
|
290
|
+
const entityName = capitalize(entity.name);
|
|
291
|
+
const entityDisplayName = entity.displayName || entityName;
|
|
292
|
+
const contractMap = getContractMapping(entity);
|
|
293
|
+
const displayFields = entity.fields.map(field => ({
|
|
294
|
+
name: field.name,
|
|
295
|
+
label: field.label,
|
|
296
|
+
format: getFieldFormatter(field.type)
|
|
297
|
+
}));
|
|
298
|
+
return `/**
|
|
299
|
+
* ${entityDisplayName} Detail View
|
|
300
|
+
*
|
|
301
|
+
* Auto-generated from template: ${template.name}
|
|
302
|
+
*/
|
|
303
|
+
|
|
304
|
+
import React, { useState, useEffect } from 'react'
|
|
305
|
+
import {
|
|
306
|
+
Card,
|
|
307
|
+
CardContent,
|
|
308
|
+
Typography,
|
|
309
|
+
Box,
|
|
310
|
+
Grid,
|
|
311
|
+
Chip,
|
|
312
|
+
CircularProgress,
|
|
313
|
+
Alert,
|
|
314
|
+
Divider,
|
|
315
|
+
Button
|
|
316
|
+
} from '@mui/material'
|
|
317
|
+
import { Edit as EditIcon, Delete as DeleteIcon } from '@mui/icons-material'
|
|
318
|
+
import { useSDK } from '../hooks/useSDK'
|
|
319
|
+
|
|
320
|
+
export interface ${entityName}DetailProps {
|
|
321
|
+
${entity.idField}: string
|
|
322
|
+
onEdit?: () => void
|
|
323
|
+
onDelete?: () => void
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const formatters = {
|
|
327
|
+
${displayFields.map(f => `${f.name}: ${f.format}`).join(',\n ')}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export const ${entityName}Detail: React.FC<${entityName}DetailProps> = ({
|
|
331
|
+
${entity.idField},
|
|
332
|
+
onEdit,
|
|
333
|
+
onDelete
|
|
334
|
+
}) => {
|
|
335
|
+
const { sdk } = useSDK()
|
|
336
|
+
const [loading, setLoading] = useState(true)
|
|
337
|
+
const [error, setError] = useState<string>('')
|
|
338
|
+
const [data, setData] = useState<any>(null)
|
|
339
|
+
|
|
340
|
+
useEffect(() => {
|
|
341
|
+
loadData()
|
|
342
|
+
}, [${entity.idField}])
|
|
343
|
+
|
|
344
|
+
const loadData = async () => {
|
|
345
|
+
setLoading(true)
|
|
346
|
+
try {
|
|
347
|
+
const result = await sdk.contracts.call(
|
|
348
|
+
'${contractMap.contractName}',
|
|
349
|
+
'${contractMap.functions.get}',
|
|
350
|
+
[${entity.idField}]
|
|
351
|
+
)
|
|
352
|
+
setData(result)
|
|
353
|
+
} catch (err) {
|
|
354
|
+
setError(err instanceof Error ? err.message : 'Failed to load ${entity.name}')
|
|
355
|
+
} finally {
|
|
356
|
+
setLoading(false)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (loading) {
|
|
361
|
+
return (
|
|
362
|
+
<Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}>
|
|
363
|
+
<CircularProgress />
|
|
364
|
+
</Box>
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (error) {
|
|
369
|
+
return <Alert severity="error">{error}</Alert>
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (!data) {
|
|
373
|
+
return <Alert severity="warning">${entityDisplayName} not found</Alert>
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return (
|
|
377
|
+
<Card>
|
|
378
|
+
<CardContent>
|
|
379
|
+
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 3 }}>
|
|
380
|
+
<Typography variant="h5">${entityDisplayName} Details</Typography>
|
|
381
|
+
<Box sx={{ display: 'flex', gap: 1 }}>
|
|
382
|
+
{onEdit && (
|
|
383
|
+
<Button
|
|
384
|
+
variant="outlined"
|
|
385
|
+
startIcon={<EditIcon />}
|
|
386
|
+
onClick={onEdit}
|
|
387
|
+
>
|
|
388
|
+
Edit
|
|
389
|
+
</Button>
|
|
390
|
+
)}
|
|
391
|
+
{onDelete && (
|
|
392
|
+
<Button
|
|
393
|
+
variant="outlined"
|
|
394
|
+
color="error"
|
|
395
|
+
startIcon={<DeleteIcon />}
|
|
396
|
+
onClick={onDelete}
|
|
397
|
+
>
|
|
398
|
+
Delete
|
|
399
|
+
</Button>
|
|
400
|
+
)}
|
|
401
|
+
</Box>
|
|
402
|
+
</Box>
|
|
403
|
+
|
|
404
|
+
<Divider sx={{ mb: 3 }} />
|
|
405
|
+
|
|
406
|
+
<Grid container spacing={3}>
|
|
407
|
+
${displayFields.map(field => `
|
|
408
|
+
<Grid item xs={12} md={6}>
|
|
409
|
+
<Typography variant="caption" color="text.secondary">
|
|
410
|
+
${field.label}
|
|
411
|
+
</Typography>
|
|
412
|
+
<Typography variant="body1">
|
|
413
|
+
{formatters.${field.name}(data.${field.name})}
|
|
414
|
+
</Typography>
|
|
415
|
+
</Grid>`).join('\n ')}
|
|
416
|
+
</Grid>
|
|
417
|
+
</CardContent>
|
|
418
|
+
</Card>
|
|
419
|
+
)
|
|
420
|
+
}
|
|
421
|
+
`;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Generate List View component
|
|
425
|
+
*/
|
|
426
|
+
function generateListView(entity, template) {
|
|
427
|
+
const entityName = capitalize(entity.name);
|
|
428
|
+
const entityDisplayName = entity.displayName || entityName;
|
|
429
|
+
const contractMap = getContractMapping(entity);
|
|
430
|
+
// Select key fields for table display (max 6 columns)
|
|
431
|
+
const tableFields = entity.fields.slice(0, 6);
|
|
432
|
+
const columns = tableFields.map(field => ({
|
|
433
|
+
id: field.name,
|
|
434
|
+
label: field.label,
|
|
435
|
+
sortable: true,
|
|
436
|
+
format: getFieldFormatter(field.type)
|
|
437
|
+
}));
|
|
438
|
+
return `/**
|
|
439
|
+
* ${entityDisplayName} List View
|
|
440
|
+
*
|
|
441
|
+
* Auto-generated from template: ${template.name}
|
|
442
|
+
*/
|
|
443
|
+
|
|
444
|
+
import React, { useState, useEffect } from 'react'
|
|
445
|
+
import { Box, Button, Alert, CircularProgress } from '@mui/material'
|
|
446
|
+
import { Add as AddIcon } from '@mui/icons-material'
|
|
447
|
+
import { DataTable, Column, Modal } from '@varity-labs/sdk/ui/components'
|
|
448
|
+
import { useSDK } from '../hooks/useSDK'
|
|
449
|
+
import { ${entityName}CreateForm } from './${entityName}CreateForm'
|
|
450
|
+
import { ${entityName}EditForm } from './${entityName}EditForm'
|
|
451
|
+
import { ${entityName}Detail } from './${entityName}Detail'
|
|
452
|
+
|
|
453
|
+
const columns: Column[] = ${JSON.stringify(columns, null, 2).replace(/"format": "(.*?)"/g, 'format: $1')}
|
|
454
|
+
|
|
455
|
+
export interface ${entityName}ListProps {
|
|
456
|
+
onRowClick?: (${entity.name}: any) => void
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export const ${entityName}List: React.FC<${entityName}ListProps> = ({ onRowClick }) => {
|
|
460
|
+
const { sdk } = useSDK()
|
|
461
|
+
const [loading, setLoading] = useState(true)
|
|
462
|
+
const [error, setError] = useState<string>('')
|
|
463
|
+
const [data, setData] = useState<any[]>([])
|
|
464
|
+
const [createModalOpen, setCreateModalOpen] = useState(false)
|
|
465
|
+
const [editModalOpen, setEditModalOpen] = useState(false)
|
|
466
|
+
const [detailModalOpen, setDetailModalOpen] = useState(false)
|
|
467
|
+
const [selectedId, setSelectedId] = useState<string>('')
|
|
468
|
+
|
|
469
|
+
useEffect(() => {
|
|
470
|
+
loadData()
|
|
471
|
+
}, [])
|
|
472
|
+
|
|
473
|
+
const loadData = async () => {
|
|
474
|
+
setLoading(true)
|
|
475
|
+
setError('')
|
|
476
|
+
try {
|
|
477
|
+
// Get all ${entity.name} IDs
|
|
478
|
+
const ids = await sdk.contracts.call(
|
|
479
|
+
'${contractMap.contractName}',
|
|
480
|
+
'${contractMap.functions.getAll}',
|
|
481
|
+
[]
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
// Fetch data for each ID
|
|
485
|
+
const results = await Promise.all(
|
|
486
|
+
ids.map(async (id: string) => {
|
|
487
|
+
const data = await sdk.contracts.call(
|
|
488
|
+
'${contractMap.contractName}',
|
|
489
|
+
'${contractMap.functions.get}',
|
|
490
|
+
[id]
|
|
491
|
+
)
|
|
492
|
+
return data
|
|
493
|
+
})
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
setData(results.filter(r => r.isActive))
|
|
497
|
+
} catch (err) {
|
|
498
|
+
setError(err instanceof Error ? err.message : 'Failed to load ${entity.name}s')
|
|
499
|
+
} finally {
|
|
500
|
+
setLoading(false)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const handleCreate = () => {
|
|
505
|
+
setCreateModalOpen(true)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const handleEdit = (row: any) => {
|
|
509
|
+
setSelectedId(row.${entity.idField})
|
|
510
|
+
setEditModalOpen(true)
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const handleView = (row: any) => {
|
|
514
|
+
setSelectedId(row.${entity.idField})
|
|
515
|
+
setDetailModalOpen(true)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const handleDelete = async (row: any) => {
|
|
519
|
+
if (window.confirm(\`Are you sure you want to deactivate this ${entity.name}?\`)) {
|
|
520
|
+
try {
|
|
521
|
+
const tx = await sdk.contracts.send(
|
|
522
|
+
'${contractMap.contractName}',
|
|
523
|
+
'${contractMap.functions.delete}',
|
|
524
|
+
[row.${entity.idField}]
|
|
525
|
+
)
|
|
526
|
+
await tx.wait()
|
|
527
|
+
await loadData()
|
|
528
|
+
} catch (err) {
|
|
529
|
+
setError(err instanceof Error ? err.message : 'Failed to deactivate ${entity.name}')
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (loading) {
|
|
535
|
+
return (
|
|
536
|
+
<Box sx={{ display: 'flex', justifyContent: 'center', p: 4 }}>
|
|
537
|
+
<CircularProgress />
|
|
538
|
+
</Box>
|
|
539
|
+
)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return (
|
|
543
|
+
<Box>
|
|
544
|
+
<Box sx={{ mb: 3, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
|
545
|
+
<Box>
|
|
546
|
+
<h2>${entityDisplayName}s</h2>
|
|
547
|
+
{error && <Alert severity="error">{error}</Alert>}
|
|
548
|
+
</Box>
|
|
549
|
+
<Button
|
|
550
|
+
variant="contained"
|
|
551
|
+
startIcon={<AddIcon />}
|
|
552
|
+
onClick={handleCreate}
|
|
553
|
+
>
|
|
554
|
+
Create ${entityDisplayName}
|
|
555
|
+
</Button>
|
|
556
|
+
</Box>
|
|
557
|
+
|
|
558
|
+
<DataTable
|
|
559
|
+
columns={columns}
|
|
560
|
+
data={data}
|
|
561
|
+
onRowClick={onRowClick || handleView}
|
|
562
|
+
actions={{
|
|
563
|
+
onView: handleView,
|
|
564
|
+
onEdit: handleEdit,
|
|
565
|
+
onDelete: handleDelete
|
|
566
|
+
}}
|
|
567
|
+
emptyMessage="No ${entity.name}s found"
|
|
568
|
+
/>
|
|
569
|
+
|
|
570
|
+
{/* Create Modal */}
|
|
571
|
+
<Modal
|
|
572
|
+
open={createModalOpen}
|
|
573
|
+
onClose={() => setCreateModalOpen(false)}
|
|
574
|
+
title="Create ${entityDisplayName}"
|
|
575
|
+
maxWidth="md"
|
|
576
|
+
>
|
|
577
|
+
<${entityName}CreateForm
|
|
578
|
+
onSuccess={() => {
|
|
579
|
+
setCreateModalOpen(false)
|
|
580
|
+
loadData()
|
|
581
|
+
}}
|
|
582
|
+
onCancel={() => setCreateModalOpen(false)}
|
|
583
|
+
/>
|
|
584
|
+
</Modal>
|
|
585
|
+
|
|
586
|
+
{/* Edit Modal */}
|
|
587
|
+
<Modal
|
|
588
|
+
open={editModalOpen}
|
|
589
|
+
onClose={() => setEditModalOpen(false)}
|
|
590
|
+
title="Edit ${entityDisplayName}"
|
|
591
|
+
maxWidth="md"
|
|
592
|
+
>
|
|
593
|
+
<${entityName}EditForm
|
|
594
|
+
${entity.idField}={selectedId}
|
|
595
|
+
onSuccess={() => {
|
|
596
|
+
setEditModalOpen(false)
|
|
597
|
+
loadData()
|
|
598
|
+
}}
|
|
599
|
+
onCancel={() => setEditModalOpen(false)}
|
|
600
|
+
/>
|
|
601
|
+
</Modal>
|
|
602
|
+
|
|
603
|
+
{/* Detail Modal */}
|
|
604
|
+
<Modal
|
|
605
|
+
open={detailModalOpen}
|
|
606
|
+
onClose={() => setDetailModalOpen(false)}
|
|
607
|
+
title="${entityDisplayName} Details"
|
|
608
|
+
maxWidth="md"
|
|
609
|
+
>
|
|
610
|
+
<${entityName}Detail
|
|
611
|
+
${entity.idField}={selectedId}
|
|
612
|
+
onEdit={() => {
|
|
613
|
+
setDetailModalOpen(false)
|
|
614
|
+
setEditModalOpen(true)
|
|
615
|
+
}}
|
|
616
|
+
onDelete={() => {
|
|
617
|
+
setDetailModalOpen(false)
|
|
618
|
+
handleDelete({ ${entity.idField}: selectedId })
|
|
619
|
+
}}
|
|
620
|
+
/>
|
|
621
|
+
</Modal>
|
|
622
|
+
</Box>
|
|
623
|
+
)
|
|
624
|
+
}
|
|
625
|
+
`;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Generate index file
|
|
629
|
+
*/
|
|
630
|
+
function generateIndexFile(entities) {
|
|
631
|
+
const exports = entities.flatMap(entity => {
|
|
632
|
+
const name = capitalize(entity.name);
|
|
633
|
+
return [
|
|
634
|
+
`export { ${name}CreateForm } from './${name}CreateForm'`,
|
|
635
|
+
`export { ${name}EditForm } from './${name}EditForm'`,
|
|
636
|
+
`export { ${name}Detail } from './${name}Detail'`,
|
|
637
|
+
`export { ${name}List } from './${name}List'`
|
|
638
|
+
];
|
|
639
|
+
});
|
|
640
|
+
return `/**
|
|
641
|
+
* Entity Components
|
|
642
|
+
*
|
|
643
|
+
* Auto-generated entity CRUD components
|
|
644
|
+
*/
|
|
645
|
+
|
|
646
|
+
${exports.join('\n')}
|
|
647
|
+
`;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Get contract mapping configuration with defaults
|
|
651
|
+
*/
|
|
652
|
+
function getContractMapping(entity) {
|
|
653
|
+
const entityName = capitalize(entity.name);
|
|
654
|
+
const displayName = entity.displayName || entityName;
|
|
655
|
+
const mapping = entity.contractMapping || {};
|
|
656
|
+
return {
|
|
657
|
+
contractName: mapping.contractName || `${entityName}Registry`,
|
|
658
|
+
functions: {
|
|
659
|
+
create: mapping.functions?.create || `create${displayName}`,
|
|
660
|
+
get: mapping.functions?.get || `get${displayName}`,
|
|
661
|
+
getAll: mapping.functions?.getAll || `getAll${displayName}Ids`,
|
|
662
|
+
update: mapping.functions?.update || `update${displayName}`,
|
|
663
|
+
delete: mapping.functions?.delete || `deactivate${displayName}`,
|
|
664
|
+
count: mapping.functions?.count || `get${displayName}Count`
|
|
665
|
+
},
|
|
666
|
+
events: {
|
|
667
|
+
created: `${displayName}Created`,
|
|
668
|
+
updated: `${displayName}Updated`,
|
|
669
|
+
deleted: `${displayName}Deleted`
|
|
670
|
+
},
|
|
671
|
+
fieldMappings: mapping.fieldMappings || {}
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Map entity field type to form field type - Universal support for all 33+ types
|
|
676
|
+
*/
|
|
677
|
+
function mapFieldTypeToFormType(type) {
|
|
678
|
+
const typeMap = {
|
|
679
|
+
// Basic types
|
|
680
|
+
'string': 'string',
|
|
681
|
+
'number': 'number',
|
|
682
|
+
'boolean': 'boolean',
|
|
683
|
+
'enum': 'enum',
|
|
684
|
+
'array': 'array',
|
|
685
|
+
'object': 'object',
|
|
686
|
+
// Financial types
|
|
687
|
+
'currency': 'number',
|
|
688
|
+
'decimal': 'number',
|
|
689
|
+
'percentage': 'number',
|
|
690
|
+
// Temporal types
|
|
691
|
+
'date': 'date',
|
|
692
|
+
'time': 'string',
|
|
693
|
+
'datetime': 'date',
|
|
694
|
+
'duration': 'string',
|
|
695
|
+
// Contact types
|
|
696
|
+
'email': 'string',
|
|
697
|
+
'phone': 'string',
|
|
698
|
+
'url': 'string',
|
|
699
|
+
// Blockchain types
|
|
700
|
+
'address': 'address',
|
|
701
|
+
// Identification types
|
|
702
|
+
'ssn': 'string',
|
|
703
|
+
'tax-id': 'string',
|
|
704
|
+
'medical-code': 'string',
|
|
705
|
+
'sku': 'string',
|
|
706
|
+
'barcode': 'string',
|
|
707
|
+
// Content types
|
|
708
|
+
'rich-text': 'string',
|
|
709
|
+
'markdown': 'string',
|
|
710
|
+
'json': 'string',
|
|
711
|
+
// Media types
|
|
712
|
+
'file': 'string',
|
|
713
|
+
'image': 'string',
|
|
714
|
+
'document': 'string',
|
|
715
|
+
// Advanced types
|
|
716
|
+
'lookup': 'string',
|
|
717
|
+
'multi-select': 'array',
|
|
718
|
+
'coordinates': 'string',
|
|
719
|
+
'color': 'string',
|
|
720
|
+
'ip-address': 'string',
|
|
721
|
+
// Legacy types
|
|
722
|
+
'bytes': 'bytes',
|
|
723
|
+
'bytes32': 'bytes32'
|
|
724
|
+
};
|
|
725
|
+
return typeMap[type] || 'string';
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Get formatter function for field type
|
|
729
|
+
*/
|
|
730
|
+
function getFieldFormatter(type) {
|
|
731
|
+
switch (type) {
|
|
732
|
+
case 'boolean':
|
|
733
|
+
return '(v: boolean) => v ? "Yes" : "No"';
|
|
734
|
+
case 'number':
|
|
735
|
+
return '(v: number) => v.toLocaleString()';
|
|
736
|
+
case 'address':
|
|
737
|
+
return '(v: string) => `${v.slice(0, 6)}...${v.slice(-4)}`';
|
|
738
|
+
case 'date':
|
|
739
|
+
return '(v: number) => new Date(v * 1000).toLocaleDateString()';
|
|
740
|
+
default:
|
|
741
|
+
return '(v: any) => v?.toString() || "-"';
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Capitalize first letter
|
|
746
|
+
*/
|
|
747
|
+
function capitalize(str) {
|
|
748
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
749
|
+
}
|