@open-mercato/cli 0.11.1-develop.8593.1.50784dae35 → 0.11.1-develop.8687.1.adb16f62b3
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/.turbo/turbo-build.log +6 -2
- package/AGENTS.md +2 -0
- package/dist/agentic/guides/architecture.md +2 -2
- package/dist/agentic/guides/extensions.md +7 -2
- package/dist/agentic/guides/framework-extension-points.md +1 -0
- package/dist/agentic/guides/infrastructure-providers.md +20 -0
- package/dist/agentic/guides/integrations.md +2 -2
- package/dist/agentic/guides/module-facts.json +11067 -7122
- package/dist/agentic/guides/module-facts.v2.json +11055 -7094
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
- package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
- package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
- package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/workers.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
- package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
- package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
- package/dist/agentic/guides/modules/backups/index.md +5 -2
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/acl-features.md +2 -1
- package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
- package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
- package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
- package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
- package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
- package/dist/agentic/guides/modules/catalog/entities.md +1 -0
- package/dist/agentic/guides/modules/catalog/events.md +4 -1
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
- package/dist/agentic/guides/modules/catalog/index.md +9 -9
- package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
- package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
- package/dist/agentic/guides/modules/catalog/workers.md +1 -0
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/workers.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/active-extension-bindings.md +11 -0
- package/dist/agentic/guides/modules/currencies/di-registrations-rich.md +1 -1
- package/dist/agentic/guides/modules/currencies/di-service-tokens.md +1 -1
- package/dist/agentic/guides/modules/currencies/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +3 -2
- package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
- package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
- package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
- package/dist/agentic/guides/modules/customers/index.md +3 -3
- package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
- package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
- package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/dashboards/index.md +2 -3
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
- package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
- package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
- package/dist/agentic/guides/modules/integrations/index.md +2 -2
- package/dist/agentic/guides/modules/integrations/setup.md +1 -1
- package/dist/agentic/guides/modules/integrations/workers.md +3 -1
- package/dist/agentic/guides/modules/ledger/acl-features.md +16 -0
- package/dist/agentic/guides/modules/ledger/active-extension-bindings.md +11 -0
- package/dist/agentic/guides/modules/ledger/backend-pages.md +21 -0
- package/dist/agentic/guides/modules/ledger/domain-commands.md +22 -0
- package/dist/agentic/guides/modules/ledger/encryption.md +11 -0
- package/dist/agentic/guides/modules/ledger/entities.md +17 -0
- package/dist/agentic/guides/modules/ledger/events.md +19 -0
- package/dist/agentic/guides/modules/ledger/exact-override-targets.md +30 -0
- package/dist/agentic/guides/modules/ledger/index.md +22 -0
- package/dist/agentic/guides/modules/ledger/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/ledger/setup.md +11 -0
- package/dist/agentic/guides/modules/ledger/umes-hosts.md +26 -0
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/resources/setup.md +1 -1
- package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
- package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/sales/index.md +3 -3
- package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
- package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/staff/workers.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +811 -21
- package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
- package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
- package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
- package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
- package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
- package/dist/agentic/guides/reference-modules/example/events.md +2 -1
- package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
- package/dist/agentic/guides/reference-modules/example/index.md +7 -7
- package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
- package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
- package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
- package/dist/agentic/guides/upstream/AGENTS.md +5 -4
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
- package/dist/agentic/guides/upstream/manifest.json +3 -3
- package/dist/agentic/shared/AGENTS.md.template +12 -16
- package/dist/agentic/shared/ai/harness/README.md +4 -2
- package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
- package/dist/agentic/shared/ai/harness/cases.json +1420 -41
- package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
- package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
- package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
- package/dist/agentic/shared/ai/harness/validators.json +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
- package/dist/lib/cache-provider-manifest.js +9 -0
- package/dist/lib/cache-provider-manifest.js.map +7 -0
- package/dist/lib/generate-watch-plan.js +4 -0
- package/dist/lib/generate-watch-plan.js.map +2 -2
- package/dist/lib/generate-watch-runner.js +1 -0
- package/dist/lib/generate-watch-runner.js.map +2 -2
- package/dist/lib/generate-watch-structure.js +2 -0
- package/dist/lib/generate-watch-structure.js.map +2 -2
- package/dist/lib/generators/ast/writers.js +5 -1
- package/dist/lib/generators/ast/writers.js.map +2 -2
- package/dist/lib/generators/cache-providers.js +80 -0
- package/dist/lib/generators/cache-providers.js.map +7 -0
- package/dist/lib/generators/form-section-ast.js +156 -0
- package/dist/lib/generators/form-section-ast.js.map +7 -0
- package/dist/lib/generators/form-section-extension-compiler.js +568 -0
- package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
- package/dist/lib/generators/form-section-extension-source.js +245 -0
- package/dist/lib/generators/form-section-extension-source.js.map +7 -0
- package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
- package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
- package/dist/lib/generators/form-sections.js +773 -0
- package/dist/lib/generators/form-sections.js.map +7 -0
- package/dist/lib/generators/index.js +2 -0
- package/dist/lib/generators/index.js.map +2 -2
- package/dist/lib/generators/module-entities.js +21 -2
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +2 -1
- package/dist/lib/generators/module-extension-facts.js.map +2 -2
- package/dist/lib/generators/module-facts.js +30 -1
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-override-targets.js +24 -2
- package/dist/lib/generators/module-override-targets.js.map +2 -2
- package/dist/lib/generators/module-registry.js +75 -3
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/generators/openapi.js +27 -17
- package/dist/lib/generators/openapi.js.map +2 -2
- package/dist/lib/post-generate-invalidation.js +20 -1
- package/dist/lib/post-generate-invalidation.js.map +2 -2
- package/dist/lib/resolver.js +195 -1
- package/dist/lib/resolver.js.map +3 -3
- package/dist/lib/scaffold/field-dsl.js +393 -0
- package/dist/lib/scaffold/field-dsl.js.map +7 -0
- package/dist/lib/scaffold/index.js +412 -0
- package/dist/lib/scaffold/index.js.map +7 -0
- package/dist/lib/scaffold/targets.js +42 -0
- package/dist/lib/scaffold/targets.js.map +7 -0
- package/dist/lib/scaffold/templates/create-page.js +52 -0
- package/dist/lib/scaffold/templates/create-page.js.map +7 -0
- package/dist/lib/scaffold/templates/detail-page.js +186 -0
- package/dist/lib/scaffold/templates/detail-page.js.map +7 -0
- package/dist/lib/scaffold/templates/form-config.js +42 -0
- package/dist/lib/scaffold/templates/form-config.js.map +7 -0
- package/dist/lib/scaffold/templates/index.js +27 -0
- package/dist/lib/scaffold/templates/index.js.map +7 -0
- package/dist/lib/scaffold/templates/list-page.js +190 -0
- package/dist/lib/scaffold/templates/list-page.js.map +7 -0
- package/dist/lib/scaffold/templates/metas.js +47 -0
- package/dist/lib/scaffold/templates/metas.js.map +7 -0
- package/dist/lib/scaffold/templates/module-files.js +85 -0
- package/dist/lib/scaffold/templates/module-files.js.map +7 -0
- package/dist/lib/single-instance-strategy-guard.js +26 -3
- package/dist/lib/single-instance-strategy-guard.js.map +2 -2
- package/dist/lib/testing/integration-discovery.js +32 -3
- package/dist/lib/testing/integration-discovery.js.map +2 -2
- package/dist/lib/testing/integration.js +232 -8
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/mercato.js +40 -7
- package/dist/mercato.js.map +2 -2
- package/jest.config.cjs +2 -0
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +18 -0
- package/src/__tests__/rotation-json-output.test.ts +52 -0
- package/src/lib/__tests__/agentic-workflows-ownership.test.ts +79 -0
- package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
- package/src/lib/__tests__/generate-watch-plan.test.ts +3 -2
- package/src/lib/__tests__/generate-watch-runner.test.ts +13 -1
- package/src/lib/__tests__/generate-watch-structure.test.ts +34 -0
- package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
- package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
- package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
- package/src/lib/cache-provider-manifest.ts +8 -0
- package/src/lib/generate-watch-plan.ts +6 -3
- package/src/lib/generate-watch-runner.ts +1 -0
- package/src/lib/generate-watch-structure.ts +5 -1
- package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
- package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
- package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
- package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
- package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
- package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
- package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
- package/src/lib/generators/__tests__/openapi.test.ts +60 -13
- package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
- package/src/lib/generators/ast/writers.ts +6 -1
- package/src/lib/generators/cache-providers.ts +111 -0
- package/src/lib/generators/form-section-ast.ts +166 -0
- package/src/lib/generators/form-section-extension-compiler.ts +632 -0
- package/src/lib/generators/form-section-extension-source.ts +308 -0
- package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
- package/src/lib/generators/form-sections.ts +896 -0
- package/src/lib/generators/index.ts +1 -0
- package/src/lib/generators/module-entities.ts +22 -4
- package/src/lib/generators/module-extension-facts.ts +1 -0
- package/src/lib/generators/module-facts.ts +40 -0
- package/src/lib/generators/module-override-targets.ts +19 -0
- package/src/lib/generators/module-registry.ts +80 -4
- package/src/lib/generators/openapi.ts +31 -20
- package/src/lib/post-generate-invalidation.ts +28 -1
- package/src/lib/resolver.ts +218 -0
- package/src/lib/scaffold/__tests__/__snapshots__/scaffold-golden.test.ts.snap +1742 -0
- package/src/lib/scaffold/__tests__/helpers.ts +75 -0
- package/src/lib/scaffold/__tests__/scaffold-ds-contract.test.ts +248 -0
- package/src/lib/scaffold/__tests__/scaffold-golden.test.ts +267 -0
- package/src/lib/scaffold/__tests__/scaffold-runtime.test.tsx +193 -0
- package/src/lib/scaffold/field-dsl.ts +491 -0
- package/src/lib/scaffold/index.ts +531 -0
- package/src/lib/scaffold/targets.ts +68 -0
- package/src/lib/scaffold/templates/create-page.ts +52 -0
- package/src/lib/scaffold/templates/detail-page.ts +190 -0
- package/src/lib/scaffold/templates/form-config.ts +42 -0
- package/src/lib/scaffold/templates/index.ts +27 -0
- package/src/lib/scaffold/templates/list-page.ts +190 -0
- package/src/lib/scaffold/templates/metas.ts +48 -0
- package/src/lib/scaffold/templates/module-files.ts +87 -0
- package/src/lib/single-instance-strategy-guard.ts +51 -1
- package/src/lib/testing/__tests__/integration-app-only-playwright.test.ts +225 -0
- package/src/lib/testing/__tests__/integration-app-only.test.ts +320 -0
- package/src/lib/testing/__tests__/integration-discovery.test.ts +45 -1
- package/src/lib/testing/integration-discovery.ts +32 -2
- package/src/lib/testing/integration.ts +293 -11
- package/src/mercato.ts +39 -5
- package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client'
|
|
4
|
+
import vm from 'node:vm'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import ts from 'typescript'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
import { parseISO } from 'date-fns/parseISO'
|
|
9
|
+
import { buildScaffoldPlan, parseScaffoldArgs } from '../index'
|
|
10
|
+
import { statusVariantFor } from '../field-dsl'
|
|
11
|
+
|
|
12
|
+
type FormProps = {
|
|
13
|
+
schema: z.ZodType
|
|
14
|
+
initialValues?: Record<string, unknown>
|
|
15
|
+
onSubmit: (values: Record<string, unknown>) => Promise<void>
|
|
16
|
+
}
|
|
17
|
+
type TableProps = {
|
|
18
|
+
error?: string | null
|
|
19
|
+
data: Record<string, unknown>[]
|
|
20
|
+
columns: { accessorKey: string; cell?: (context: { row: { original: Record<string, unknown> } }) => React.ReactNode }[]
|
|
21
|
+
onSearchChange: (value: string) => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const apiCall = jest.fn()
|
|
25
|
+
const createCrud = jest.fn().mockResolvedValue({ result: { id: 'created' } })
|
|
26
|
+
const updateCrud = jest.fn().mockResolvedValue({})
|
|
27
|
+
const reportError = jest.fn()
|
|
28
|
+
const translate = (_key: string, fallback: string) => fallback
|
|
29
|
+
const router = { push: jest.fn() }
|
|
30
|
+
const guardedMutation = { runMutation: jest.fn(), retryLastMutation: jest.fn() }
|
|
31
|
+
const confirmDialog = { confirm: jest.fn(), ConfirmDialogElement: null }
|
|
32
|
+
let formProps: FormProps | undefined
|
|
33
|
+
let tableProps: TableProps | undefined
|
|
34
|
+
let root: Root
|
|
35
|
+
let container: HTMLDivElement
|
|
36
|
+
let files: Map<string, string>
|
|
37
|
+
|
|
38
|
+
function Wrapper({ children }: { children?: React.ReactNode }) {
|
|
39
|
+
return <div>{children}</div>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function evaluateFile(file: string, cache = new Map<string, Record<string, unknown>>()): Record<string, unknown> {
|
|
43
|
+
const existing = cache.get(file)
|
|
44
|
+
if (existing) return existing
|
|
45
|
+
const source = files.get(file)
|
|
46
|
+
if (!source) throw new Error(`Missing fixture source: ${file}`)
|
|
47
|
+
const exports: Record<string, unknown> = {}
|
|
48
|
+
cache.set(file, exports)
|
|
49
|
+
const modules: Record<string, unknown> = {
|
|
50
|
+
react: React,
|
|
51
|
+
'react/jsx-runtime': require('react/jsx-runtime'),
|
|
52
|
+
zod: { z },
|
|
53
|
+
'date-fns/parseISO': { parseISO },
|
|
54
|
+
'next/navigation': { useRouter: () => router },
|
|
55
|
+
'next/link': { default: Wrapper },
|
|
56
|
+
'@open-mercato/ui/backend/Page': { Page: Wrapper, PageBody: Wrapper },
|
|
57
|
+
'@open-mercato/ui/backend/CrudForm': {
|
|
58
|
+
CrudForm: (props: FormProps) => { formProps = props; return <div>Form</div> },
|
|
59
|
+
},
|
|
60
|
+
'@open-mercato/ui/backend/DataTable': {
|
|
61
|
+
DataTable: (props: TableProps) => { tableProps = props; return <div>{props.error ?? 'Table'}</div> },
|
|
62
|
+
},
|
|
63
|
+
'@open-mercato/ui/backend/forms/FormHeader': { FormHeader: Wrapper },
|
|
64
|
+
'@open-mercato/ui/primitives/tabs': { Tabs: Wrapper, TabsContent: Wrapper, TabsList: Wrapper, TabsTrigger: Wrapper },
|
|
65
|
+
'@open-mercato/ui/primitives/button': { Button: Wrapper },
|
|
66
|
+
'@open-mercato/ui/primitives/empty-state': { EmptyState: Wrapper },
|
|
67
|
+
'@open-mercato/ui/primitives/status-badge': { StatusBadge: Wrapper },
|
|
68
|
+
'@open-mercato/ui/backend/RowActions': { RowActions: Wrapper },
|
|
69
|
+
'@open-mercato/ui/backend/detail': {
|
|
70
|
+
LoadingMessage: ({ label }: { label: string }) => <div>{label}</div>,
|
|
71
|
+
ErrorMessage: ({ label }: { label: string }) => <div role="alert">{label}</div>,
|
|
72
|
+
},
|
|
73
|
+
'@open-mercato/ui/backend/utils/apiCall': { apiCall },
|
|
74
|
+
'@open-mercato/ui/backend/utils/crud': { createCrud, updateCrud },
|
|
75
|
+
'@open-mercato/ui/backend/utils/optimisticLock': {},
|
|
76
|
+
'@open-mercato/ui/backend/injection/useGuardedMutation': { useGuardedMutation: () => guardedMutation },
|
|
77
|
+
'@open-mercato/ui/backend/FlashMessages': { flash: jest.fn() },
|
|
78
|
+
'@open-mercato/ui/backend/confirm-dialog': { useConfirmDialog: () => confirmDialog },
|
|
79
|
+
'@open-mercato/shared/lib/i18n/context': { useT: () => translate },
|
|
80
|
+
'@open-mercato/shared/lib/telemetry/runtime': { getTelemetryRuntime: () => ({ reportError }) },
|
|
81
|
+
}
|
|
82
|
+
const compiled = ts.transpileModule(source, {
|
|
83
|
+
fileName: file,
|
|
84
|
+
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.ReactJSX },
|
|
85
|
+
}).outputText
|
|
86
|
+
vm.runInNewContext(compiled, {
|
|
87
|
+
exports,
|
|
88
|
+
URLSearchParams,
|
|
89
|
+
require: (specifier: string) => {
|
|
90
|
+
if (Object.hasOwn(modules, specifier)) return modules[specifier]
|
|
91
|
+
if (specifier.startsWith('.')) {
|
|
92
|
+
return evaluateFile(path.posix.normalize(path.posix.join(path.posix.dirname(file), specifier)) + '.ts', cache)
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Unexpected fixture import: ${specifier}`)
|
|
95
|
+
},
|
|
96
|
+
}, { filename: file, timeout: 5000 })
|
|
97
|
+
return exports
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function page(file: string): React.ComponentType<{ params?: { id: string } }> {
|
|
101
|
+
return evaluateFile(file).default as React.ComponentType<{ params?: { id: string } }>
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
beforeAll(() => {
|
|
105
|
+
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true })
|
|
106
|
+
})
|
|
107
|
+
beforeEach(() => {
|
|
108
|
+
jest.clearAllMocks()
|
|
109
|
+
formProps = undefined
|
|
110
|
+
tableProps = undefined
|
|
111
|
+
const parsed = parseScaffoldArgs(['tasks', '--entity', 'task', '--fields', 'name:text:required,dueDate:date:required,followUpDate:date,status:select(open|constructor)'])
|
|
112
|
+
if (!parsed.ok) throw new Error(parsed.error)
|
|
113
|
+
const plan = buildScaffoldPlan(parsed.options, { kind: 'app', modulesRoot: '/fixture', moduleDir: '/fixture/tasks', registrationFrom: '@app' })
|
|
114
|
+
files = new Map(plan.files.map((file) => [file.relPath, file.contents]))
|
|
115
|
+
container = document.createElement('div')
|
|
116
|
+
document.body.appendChild(container)
|
|
117
|
+
root = createRoot(container)
|
|
118
|
+
})
|
|
119
|
+
afterEach(async () => {
|
|
120
|
+
await React.act(async () => root.unmount())
|
|
121
|
+
container.remove()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('preserves civil dates through generated create, list, detail and update consumers west of UTC', async () => {
|
|
125
|
+
expect(new Date('2026-11-18').getDate()).toBe(17)
|
|
126
|
+
const CreatePage = page('backend/tasks/create/page.tsx')
|
|
127
|
+
await React.act(async () => root.render(<CreatePage />))
|
|
128
|
+
const input = { name: 'Task', dueDate: '2026-11-18', status: 'constructor' }
|
|
129
|
+
const created = formProps!.schema.parse(input) as Record<string, unknown>
|
|
130
|
+
expect(created.dueDate).toBe('2026-11-18')
|
|
131
|
+
await formProps!.onSubmit(created)
|
|
132
|
+
expect(createCrud).toHaveBeenCalledWith('tasks', expect.objectContaining({ dueDate: '2026-11-18' }))
|
|
133
|
+
const record = { ...JSON.parse(JSON.stringify(created)), id: 'b73d8a12-b1e3-47b9-9d21-ce25c76f6e6d', updatedAt: '2026-11-18T12:00:00Z' }
|
|
134
|
+
apiCall.mockResolvedValue({ ok: true, result: { items: [record], total: 1, totalPages: 1 } })
|
|
135
|
+
const ListPage = page('backend/tasks/page.tsx')
|
|
136
|
+
await React.act(async () => root.render(<ListPage />))
|
|
137
|
+
const dateColumn = tableProps!.columns.find((column) => column.accessorKey === 'dueDate')!
|
|
138
|
+
const rendered = dateColumn.cell!({ row: { original: record } })
|
|
139
|
+
expect(rendered).toBe(parseISO('2026-11-18').toLocaleDateString())
|
|
140
|
+
const DetailPage = page('backend/tasks/[id]/page.tsx')
|
|
141
|
+
await React.act(async () => root.render(<DetailPage params={{ id: record.id }} />))
|
|
142
|
+
expect(formProps!.initialValues!.dueDate).toBe('2026-11-18')
|
|
143
|
+
expect(formProps!.initialValues!.updatedAt).toBe(record.updatedAt)
|
|
144
|
+
const updated = formProps!.schema.parse(formProps!.initialValues) as Record<string, unknown>
|
|
145
|
+
await React.act(async () => formProps!.onSubmit(updated))
|
|
146
|
+
expect(updateCrud).toHaveBeenCalledWith('tasks', expect.objectContaining({ dueDate: '2026-11-18' }))
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('validates real calendar dates without converting them to instants', () => {
|
|
150
|
+
const schema = evaluateFile('data/validators.ts').taskCreateSchema as z.ZodType
|
|
151
|
+
for (const dueDate of ['2024-02-29', '2026-11-18']) {
|
|
152
|
+
expect(schema.parse({ name: 'Task', dueDate })).toEqual({ name: 'Task', dueDate })
|
|
153
|
+
}
|
|
154
|
+
for (const dueDate of ['2026-02-29', '2026-02-30', '2026-13-01', '', '2026-11-18T00:00:00Z']) {
|
|
155
|
+
expect(schema.safeParse({ name: 'Task', dueDate }).success).toBe(false)
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('emits a neutral status variant for accepted prototype-member option names', () => {
|
|
160
|
+
expect(statusVariantFor('constructor')).toBe('neutral')
|
|
161
|
+
expect(statusVariantFor('hasownproperty')).toBe('neutral')
|
|
162
|
+
const statusMap = evaluateFile('components/statusMap.ts').taskStatusMap
|
|
163
|
+
expect(statusMap).toEqual({ open: 'info', constructor: 'neutral' })
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it.each(['backend/tasks/page.tsx', 'backend/tasks/[id]/page.tsx'])('shows transport errors and recovers on the next read: %s', async (file) => {
|
|
167
|
+
const failure = new Error('offline')
|
|
168
|
+
apiCall.mockRejectedValueOnce(failure)
|
|
169
|
+
const Page = page(file)
|
|
170
|
+
await React.act(async () => root.render(<Page params={{ id: 'first' }} />))
|
|
171
|
+
expect(container.textContent).toContain('Failed to load')
|
|
172
|
+
expect(container.textContent).not.toContain('not found')
|
|
173
|
+
expect(reportError).toHaveBeenCalledWith(failure, expect.objectContaining({ module: 'tasks', code: expect.stringMatching(/^tasks\.(list|detail)_load_failed$/) }))
|
|
174
|
+
const record = { id: 'second', name: 'Task', dueDate: '2026-11-18' }
|
|
175
|
+
apiCall.mockResolvedValue({ ok: true, result: { items: [record], total: 1, totalPages: 1 } })
|
|
176
|
+
await React.act(async () => {
|
|
177
|
+
if (file.endsWith('[id]/page.tsx')) root.render(<Page params={{ id: 'second' }} />)
|
|
178
|
+
else tableProps!.onSearchChange('recovery')
|
|
179
|
+
})
|
|
180
|
+
expect(container.textContent).not.toContain('Failed to load')
|
|
181
|
+
expect(container.textContent).toContain(file.endsWith('[id]/page.tsx') ? 'Form' : 'Table')
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it.each(['backend/tasks/page.tsx', 'backend/tasks/[id]/page.tsx'])('ignores a rejected read after unmount: %s', async (file) => {
|
|
185
|
+
let rejectRead: (error: Error) => void = () => { throw new Error('read not started') }
|
|
186
|
+
apiCall.mockImplementationOnce(() => new Promise((_resolve, reject) => { rejectRead = reject }))
|
|
187
|
+
const Page = page(file)
|
|
188
|
+
await React.act(async () => root.render(<Page params={{ id: 'first' }} />))
|
|
189
|
+
await React.act(async () => root.unmount())
|
|
190
|
+
root = createRoot(container)
|
|
191
|
+
await React.act(async () => rejectRead(new Error('late offline')))
|
|
192
|
+
expect(reportError).not.toHaveBeenCalled()
|
|
193
|
+
})
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field DSL for `mercato module scaffold` (spec:
|
|
3
|
+
* .ai/specs/2026-07-05-ds-module-ui-scaffold.md).
|
|
4
|
+
*
|
|
5
|
+
* One `--fields` declaration drives four artifacts at once — the zod schema in
|
|
6
|
+
* `data/validators.ts`, the `CrudField[]` in `components/formConfig.ts`, the
|
|
7
|
+
* `ColumnDef[]` on the list page, and the i18n label keys — so they can never
|
|
8
|
+
* disagree. All emitters are pure string builders: identical inputs produce
|
|
9
|
+
* byte-identical output (CLI AGENTS.md determinism rule).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type ScaffoldFieldType = 'text' | 'textarea' | 'number' | 'select' | 'checkbox' | 'date'
|
|
13
|
+
|
|
14
|
+
export type ScaffoldField = {
|
|
15
|
+
name: string
|
|
16
|
+
type: ScaffoldFieldType
|
|
17
|
+
required: boolean
|
|
18
|
+
/** Present only for `select` fields. */
|
|
19
|
+
options?: string[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class FieldDslError extends Error {
|
|
23
|
+
constructor(message: string) {
|
|
24
|
+
super(message)
|
|
25
|
+
this.name = 'FieldDslError'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const FIELD_NAME_PATTERN = /^[a-z][a-zA-Z0-9]*$/
|
|
30
|
+
const OPTION_PATTERN = /^[a-z][a-z0-9_]*$/
|
|
31
|
+
const KNOWN_TYPES: ScaffoldFieldType[] = ['text', 'textarea', 'number', 'select', 'checkbox', 'date']
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Columns that every scaffolded entity is assumed to carry (and that the
|
|
35
|
+
* platform manages). They can never be redeclared through the DSL.
|
|
36
|
+
*/
|
|
37
|
+
export const RESERVED_FIELD_NAMES = [
|
|
38
|
+
'id',
|
|
39
|
+
'createdAt',
|
|
40
|
+
'updatedAt',
|
|
41
|
+
'deletedAt',
|
|
42
|
+
'organizationId',
|
|
43
|
+
'tenantId',
|
|
44
|
+
// List-API query params share one flat bag with field filters — a field
|
|
45
|
+
// named like one of these would clobber pagination/search/export params
|
|
46
|
+
// (e.g. `format:select(csv|json)` turns every filtered list call into a
|
|
47
|
+
// CSV export). Reserved alongside the platform columns.
|
|
48
|
+
'page',
|
|
49
|
+
'pageSize',
|
|
50
|
+
'search',
|
|
51
|
+
'ids',
|
|
52
|
+
'format',
|
|
53
|
+
'full',
|
|
54
|
+
'all',
|
|
55
|
+
'exportScope',
|
|
56
|
+
// Object prototype members survive the identifier regex but interact with
|
|
57
|
+
// plain-object property lookups in generated code.
|
|
58
|
+
'constructor',
|
|
59
|
+
'toString',
|
|
60
|
+
'valueOf',
|
|
61
|
+
'hasOwnProperty',
|
|
62
|
+
] as const
|
|
63
|
+
|
|
64
|
+
export const FIELD_DSL_GRAMMAR = [
|
|
65
|
+
'--fields grammar:',
|
|
66
|
+
' fields = field[,field...]',
|
|
67
|
+
' field = name:type[:required]',
|
|
68
|
+
' name = camelCase identifier matching ^[a-z][a-zA-Z0-9]*$',
|
|
69
|
+
` (reserved, always present: ${RESERVED_FIELD_NAMES.join(', ')})`,
|
|
70
|
+
' type = text | textarea | number | select(opt1|opt2[|...]) | checkbox | date',
|
|
71
|
+
' option = identifier matching ^[a-z][a-z0-9_]*$ (select only, unique)',
|
|
72
|
+
'',
|
|
73
|
+
'Example: --fields "subject:text:required,status:select(open|closed),notes:textarea"',
|
|
74
|
+
].join('\n')
|
|
75
|
+
|
|
76
|
+
export function parseFieldsSpec(spec: string): ScaffoldField[] {
|
|
77
|
+
const trimmed = spec.trim()
|
|
78
|
+
if (!trimmed) {
|
|
79
|
+
throw new FieldDslError('--fields must declare at least one field.')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const fields: ScaffoldField[] = []
|
|
83
|
+
const seen = new Set<string>()
|
|
84
|
+
|
|
85
|
+
for (const rawEntry of trimmed.split(',')) {
|
|
86
|
+
const entry = rawEntry.trim()
|
|
87
|
+
if (!entry) {
|
|
88
|
+
throw new FieldDslError(`Empty field declaration in --fields "${spec}".`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const segments = entry.split(':')
|
|
92
|
+
if (segments.length < 2 || segments.length > 3) {
|
|
93
|
+
throw new FieldDslError(`Malformed field declaration "${entry}" — expected name:type[:required].`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [name, typeSegment, requiredSegment] = segments
|
|
97
|
+
|
|
98
|
+
if (!FIELD_NAME_PATTERN.test(name)) {
|
|
99
|
+
throw new FieldDslError(`Invalid field name "${name}" — names must match ^[a-z][a-zA-Z0-9]*$.`)
|
|
100
|
+
}
|
|
101
|
+
if ((RESERVED_FIELD_NAMES as readonly string[]).includes(name)) {
|
|
102
|
+
throw new FieldDslError(
|
|
103
|
+
`Field name "${name}" is reserved — ${RESERVED_FIELD_NAMES.join(', ')} are always present and never redeclared.`,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
if (seen.has(name)) {
|
|
107
|
+
throw new FieldDslError(`Duplicate field name "${name}".`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (requiredSegment !== undefined && requiredSegment !== 'required') {
|
|
111
|
+
throw new FieldDslError(`Unknown field modifier "${requiredSegment}" in "${entry}" — only :required is supported.`)
|
|
112
|
+
}
|
|
113
|
+
const required = requiredSegment === 'required'
|
|
114
|
+
|
|
115
|
+
const typeMatch = typeSegment.match(/^([a-z]+)(\((.*)\))?$/)
|
|
116
|
+
if (!typeMatch) {
|
|
117
|
+
throw new FieldDslError(`Malformed type "${typeSegment}" in "${entry}".`)
|
|
118
|
+
}
|
|
119
|
+
const typeName = typeMatch[1] as ScaffoldFieldType
|
|
120
|
+
const hasOptions = typeMatch[2] !== undefined
|
|
121
|
+
const rawOptions = typeMatch[3]
|
|
122
|
+
|
|
123
|
+
if (!KNOWN_TYPES.includes(typeName)) {
|
|
124
|
+
throw new FieldDslError(`Unknown field type "${typeName}" in "${entry}".`)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (typeName === 'select') {
|
|
128
|
+
if (!hasOptions || rawOptions === undefined || rawOptions.trim() === '') {
|
|
129
|
+
throw new FieldDslError(`select field "${name}" needs options, e.g. ${name}:select(open|closed).`)
|
|
130
|
+
}
|
|
131
|
+
const options = rawOptions.split('|').map((opt) => opt.trim())
|
|
132
|
+
const seenOptions = new Set<string>()
|
|
133
|
+
for (const option of options) {
|
|
134
|
+
if (!OPTION_PATTERN.test(option)) {
|
|
135
|
+
throw new FieldDslError(
|
|
136
|
+
`Invalid option "${option}" for select field "${name}" — options must match ^[a-z][a-z0-9_]*$.`,
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
if (seenOptions.has(option)) {
|
|
140
|
+
throw new FieldDslError(`Duplicate option "${option}" for select field "${name}".`)
|
|
141
|
+
}
|
|
142
|
+
seenOptions.add(option)
|
|
143
|
+
}
|
|
144
|
+
seen.add(name)
|
|
145
|
+
fields.push({ name, type: typeName, required, options })
|
|
146
|
+
continue
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (hasOptions) {
|
|
150
|
+
throw new FieldDslError(`Type "${typeName}" does not take options (field "${name}").`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
seen.add(name)
|
|
154
|
+
fields.push({ name, type: typeName, required })
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return fields
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ---------------------------------------------------------------------------
|
|
161
|
+
// Naming helpers (shared by all emitters so labels/keys never diverge)
|
|
162
|
+
// ---------------------------------------------------------------------------
|
|
163
|
+
|
|
164
|
+
/** `priorityScore` / `in_progress` → `Priority score` / `In progress`. */
|
|
165
|
+
export function humanizeIdentifier(identifier: string): string {
|
|
166
|
+
const words = identifier
|
|
167
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
168
|
+
.replace(/_/g, ' ')
|
|
169
|
+
.toLowerCase()
|
|
170
|
+
.trim()
|
|
171
|
+
return words.charAt(0).toUpperCase() + words.slice(1)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** `support_tickets` → `SupportTickets`; `ticket` → `Ticket`. */
|
|
175
|
+
export function pascalCase(identifier: string): string {
|
|
176
|
+
return identifier
|
|
177
|
+
.split('_')
|
|
178
|
+
.filter(Boolean)
|
|
179
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
180
|
+
.join('')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** `support_tickets` → `supportTickets`. */
|
|
184
|
+
export function camelCase(identifier: string): string {
|
|
185
|
+
const pascal = pascalCase(identifier)
|
|
186
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** `ticket_item` → `TICKET_ITEM`. */
|
|
190
|
+
export function upperSnakeCase(identifier: string): string {
|
|
191
|
+
return identifier.toUpperCase()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** The `select` field rendered through StatusBadge + StatusMap, if declared. */
|
|
195
|
+
export function findStatusField(fields: ScaffoldField[]): ScaffoldField | null {
|
|
196
|
+
return fields.find((field) => field.type === 'select' && field.name === 'status') ?? null
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function selectFields(fields: ScaffoldField[]): ScaffoldField[] {
|
|
200
|
+
return fields.filter((field) => field.type === 'select')
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function hasCheckboxField(fields: ScaffoldField[]): boolean {
|
|
204
|
+
return fields.some((field) => field.type === 'checkbox')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// zod emitter (data/validators.ts body)
|
|
209
|
+
// ---------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
function zodFragment(field: ScaffoldField): string {
|
|
212
|
+
switch (field.type) {
|
|
213
|
+
case 'text':
|
|
214
|
+
case 'textarea':
|
|
215
|
+
return field.required ? 'z.string().min(1)' : 'z.string().optional()'
|
|
216
|
+
case 'number':
|
|
217
|
+
return field.required ? 'z.coerce.number()' : 'z.coerce.number().optional()'
|
|
218
|
+
case 'select': {
|
|
219
|
+
const options = (field.options ?? []).map((opt) => `'${opt}'`).join(', ')
|
|
220
|
+
return field.required ? `z.enum([${options}])` : `z.enum([${options}]).optional()`
|
|
221
|
+
}
|
|
222
|
+
case 'checkbox':
|
|
223
|
+
return field.required ? 'z.boolean()' : 'z.boolean().optional()'
|
|
224
|
+
case 'date':
|
|
225
|
+
return field.required ? 'z.string().date()' : 'z.string().date().optional()'
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function emitZodFieldLines(fields: ScaffoldField[]): string {
|
|
230
|
+
return fields.map((field) => ` ${field.name}: ${zodFragment(field)},`).join('\n')
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
// CrudField emitter (components/formConfig.ts body)
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
function crudFieldType(field: ScaffoldField): string {
|
|
238
|
+
return field.type
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function emitCrudFieldLines(fields: ScaffoldField[], i18nPrefix: string): string {
|
|
242
|
+
const lines: string[] = []
|
|
243
|
+
for (const field of fields) {
|
|
244
|
+
const label = `t('${i18nPrefix}.fields.${field.name}', '${humanizeIdentifier(field.name)}')`
|
|
245
|
+
if (field.type === 'select') {
|
|
246
|
+
lines.push(' {')
|
|
247
|
+
lines.push(` id: '${field.name}',`)
|
|
248
|
+
lines.push(` label: ${label},`)
|
|
249
|
+
lines.push(` type: 'select',`)
|
|
250
|
+
if (field.required) lines.push(' required: true,')
|
|
251
|
+
lines.push(' options: [')
|
|
252
|
+
for (const option of field.options ?? []) {
|
|
253
|
+
lines.push(
|
|
254
|
+
` { value: '${option}', label: t('${i18nPrefix}.fields.${field.name}.options.${option}', '${humanizeIdentifier(option)}') },`,
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
lines.push(' ],')
|
|
258
|
+
lines.push(' },')
|
|
259
|
+
continue
|
|
260
|
+
}
|
|
261
|
+
const requiredPart = field.required ? ', required: true' : ''
|
|
262
|
+
lines.push(` { id: '${field.name}', label: ${label}, type: '${crudFieldType(field)}'${requiredPart} },`)
|
|
263
|
+
}
|
|
264
|
+
return lines.join('\n')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function emitFieldIdList(fields: ScaffoldField[]): string {
|
|
268
|
+
return fields.map((field) => `'${field.name}'`).join(', ')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ---------------------------------------------------------------------------
|
|
272
|
+
// ColumnDef emitter (list page body)
|
|
273
|
+
// ---------------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
export function emitColumnLines(
|
|
276
|
+
fields: ScaffoldField[],
|
|
277
|
+
i18nPrefix: string,
|
|
278
|
+
statusMapIdent: string | null,
|
|
279
|
+
): string {
|
|
280
|
+
const lines: string[] = []
|
|
281
|
+
for (const field of fields) {
|
|
282
|
+
// Spec: textarea fields are excluded from the default column set.
|
|
283
|
+
if (field.type === 'textarea') continue
|
|
284
|
+
const header = `t('${i18nPrefix}.fields.${field.name}', '${humanizeIdentifier(field.name)}')`
|
|
285
|
+
switch (field.type) {
|
|
286
|
+
case 'text':
|
|
287
|
+
lines.push(` { accessorKey: '${field.name}', header: ${header} },`)
|
|
288
|
+
break
|
|
289
|
+
case 'number':
|
|
290
|
+
lines.push(' {')
|
|
291
|
+
lines.push(` accessorKey: '${field.name}',`)
|
|
292
|
+
lines.push(` header: ${header},`)
|
|
293
|
+
lines.push(
|
|
294
|
+
` cell: ({ row }) => <div className="text-right tabular-nums">{row.original.${field.name} ?? null}</div>,`,
|
|
295
|
+
)
|
|
296
|
+
lines.push(' },')
|
|
297
|
+
break
|
|
298
|
+
case 'checkbox':
|
|
299
|
+
lines.push(' {')
|
|
300
|
+
lines.push(` accessorKey: '${field.name}',`)
|
|
301
|
+
lines.push(` header: ${header},`)
|
|
302
|
+
lines.push(
|
|
303
|
+
` cell: ({ row }) => (row.original.${field.name} ? t('${i18nPrefix}.list.boolean.yes', 'Yes') : t('${i18nPrefix}.list.boolean.no', 'No')),`,
|
|
304
|
+
)
|
|
305
|
+
lines.push(' },')
|
|
306
|
+
break
|
|
307
|
+
case 'date':
|
|
308
|
+
lines.push(' {')
|
|
309
|
+
lines.push(` accessorKey: '${field.name}',`)
|
|
310
|
+
lines.push(` header: ${header},`)
|
|
311
|
+
lines.push(
|
|
312
|
+
` cell: ({ row }) => (row.original.${field.name} ? parseISO(row.original.${field.name}).toLocaleDateString() : null),`,
|
|
313
|
+
)
|
|
314
|
+
lines.push(' },')
|
|
315
|
+
break
|
|
316
|
+
case 'select': {
|
|
317
|
+
if (statusMapIdent && field.name === 'status') {
|
|
318
|
+
lines.push(' {')
|
|
319
|
+
lines.push(` accessorKey: 'status',`)
|
|
320
|
+
lines.push(` header: ${header},`)
|
|
321
|
+
lines.push(' cell: ({ row }) => {')
|
|
322
|
+
lines.push(' const status = row.original.status')
|
|
323
|
+
lines.push(' if (!status) return null')
|
|
324
|
+
lines.push(' return (')
|
|
325
|
+
lines.push(` <StatusBadge variant={${statusMapIdent}[status] ?? 'neutral'} dot>`)
|
|
326
|
+
lines.push(` {t('${i18nPrefix}.fields.status.options.' + status, status)}`)
|
|
327
|
+
lines.push(' </StatusBadge>')
|
|
328
|
+
lines.push(' )')
|
|
329
|
+
lines.push(' },')
|
|
330
|
+
lines.push(' },')
|
|
331
|
+
} else {
|
|
332
|
+
lines.push(' {')
|
|
333
|
+
lines.push(` accessorKey: '${field.name}',`)
|
|
334
|
+
lines.push(` header: ${header},`)
|
|
335
|
+
lines.push(
|
|
336
|
+
` cell: ({ row }) => (row.original.${field.name} ? t('${i18nPrefix}.fields.${field.name}.options.' + row.original.${field.name}, row.original.${field.name}) : null),`,
|
|
337
|
+
)
|
|
338
|
+
lines.push(' },')
|
|
339
|
+
}
|
|
340
|
+
break
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return lines.join('\n')
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ---------------------------------------------------------------------------
|
|
348
|
+
// Row/record type emitter (list + detail pages)
|
|
349
|
+
// ---------------------------------------------------------------------------
|
|
350
|
+
|
|
351
|
+
function rowFieldType(field: ScaffoldField, statusTypeIdent: string | null): string {
|
|
352
|
+
switch (field.type) {
|
|
353
|
+
case 'text':
|
|
354
|
+
case 'textarea':
|
|
355
|
+
return 'string'
|
|
356
|
+
case 'number':
|
|
357
|
+
return 'number'
|
|
358
|
+
case 'checkbox':
|
|
359
|
+
return 'boolean'
|
|
360
|
+
case 'date':
|
|
361
|
+
return 'string'
|
|
362
|
+
case 'select': {
|
|
363
|
+
if (statusTypeIdent && field.name === 'status') return statusTypeIdent
|
|
364
|
+
return (field.options ?? []).map((opt) => `'${opt}'`).join(' | ')
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function emitRowTypeLines(fields: ScaffoldField[], statusTypeIdent: string | null): string {
|
|
370
|
+
return fields
|
|
371
|
+
.map((field) => {
|
|
372
|
+
const tsType = rowFieldType(field, statusTypeIdent)
|
|
373
|
+
return field.required ? ` ${field.name}: ${tsType}` : ` ${field.name}?: ${tsType} | null`
|
|
374
|
+
})
|
|
375
|
+
.join('\n')
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ---------------------------------------------------------------------------
|
|
379
|
+
// initialValues emitter (detail page edit form)
|
|
380
|
+
// ---------------------------------------------------------------------------
|
|
381
|
+
|
|
382
|
+
export function emitInitialValueLines(fields: ScaffoldField[]): string {
|
|
383
|
+
return fields
|
|
384
|
+
.map((field) => {
|
|
385
|
+
if (field.required) {
|
|
386
|
+
return ` ${field.name}: record.${field.name},`
|
|
387
|
+
}
|
|
388
|
+
return ` ${field.name}: record.${field.name} ?? undefined,`
|
|
389
|
+
})
|
|
390
|
+
.join('\n')
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ---------------------------------------------------------------------------
|
|
394
|
+
// Quick filters emitter (list page FilterBar defs for select fields)
|
|
395
|
+
// ---------------------------------------------------------------------------
|
|
396
|
+
|
|
397
|
+
export function emitFilterDefLines(fields: ScaffoldField[], i18nPrefix: string): string {
|
|
398
|
+
const lines: string[] = []
|
|
399
|
+
for (const field of selectFields(fields)) {
|
|
400
|
+
lines.push(' {')
|
|
401
|
+
lines.push(` id: '${field.name}',`)
|
|
402
|
+
lines.push(` label: t('${i18nPrefix}.fields.${field.name}', '${humanizeIdentifier(field.name)}'),`)
|
|
403
|
+
lines.push(` type: 'select',`)
|
|
404
|
+
lines.push(' options: [')
|
|
405
|
+
for (const option of field.options ?? []) {
|
|
406
|
+
lines.push(
|
|
407
|
+
` { value: '${option}', label: t('${i18nPrefix}.fields.${field.name}.options.${option}', '${humanizeIdentifier(option)}') },`,
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
lines.push(' ],')
|
|
411
|
+
lines.push(' },')
|
|
412
|
+
}
|
|
413
|
+
return lines.join('\n')
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export function emitFilterParamLines(fields: ScaffoldField[]): string {
|
|
417
|
+
return selectFields(fields)
|
|
418
|
+
.map(
|
|
419
|
+
(field) =>
|
|
420
|
+
` if (typeof filterValues.${field.name} === 'string' && filterValues.${field.name}) params.${field.name} = filterValues.${field.name}`,
|
|
421
|
+
)
|
|
422
|
+
.join('\n')
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// ---------------------------------------------------------------------------
|
|
426
|
+
// StatusMap emitter (components/statusMap.ts)
|
|
427
|
+
// ---------------------------------------------------------------------------
|
|
428
|
+
|
|
429
|
+
const STATUS_VARIANT_BY_NAME: Record<string, string> = {
|
|
430
|
+
active: 'success',
|
|
431
|
+
approved: 'success',
|
|
432
|
+
complete: 'success',
|
|
433
|
+
completed: 'success',
|
|
434
|
+
done: 'success',
|
|
435
|
+
paid: 'success',
|
|
436
|
+
published: 'success',
|
|
437
|
+
resolved: 'success',
|
|
438
|
+
won: 'success',
|
|
439
|
+
archived: 'neutral',
|
|
440
|
+
canceled: 'neutral',
|
|
441
|
+
cancelled: 'neutral',
|
|
442
|
+
closed: 'neutral',
|
|
443
|
+
disabled: 'neutral',
|
|
444
|
+
draft: 'neutral',
|
|
445
|
+
inactive: 'neutral',
|
|
446
|
+
in_progress: 'info',
|
|
447
|
+
new: 'info',
|
|
448
|
+
open: 'info',
|
|
449
|
+
pending: 'info',
|
|
450
|
+
processing: 'info',
|
|
451
|
+
review: 'info',
|
|
452
|
+
at_risk: 'warning',
|
|
453
|
+
on_hold: 'warning',
|
|
454
|
+
overdue: 'warning',
|
|
455
|
+
paused: 'warning',
|
|
456
|
+
warning: 'warning',
|
|
457
|
+
blocked: 'error',
|
|
458
|
+
error: 'error',
|
|
459
|
+
failed: 'error',
|
|
460
|
+
lost: 'error',
|
|
461
|
+
rejected: 'error',
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function statusVariantFor(option: string): string {
|
|
465
|
+
return Object.hasOwn(STATUS_VARIANT_BY_NAME, option) ? STATUS_VARIANT_BY_NAME[option] : 'neutral'
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function emitStatusUnion(statusField: ScaffoldField): string {
|
|
469
|
+
return (statusField.options ?? []).map((opt) => `'${opt}'`).join(' | ')
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function emitStatusMapEntries(statusField: ScaffoldField): string {
|
|
473
|
+
return (statusField.options ?? []).map((opt) => ` ${opt}: '${statusVariantFor(opt)}',`).join('\n')
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// ---------------------------------------------------------------------------
|
|
477
|
+
// i18n emitter (field-derived keys; page-level copy lives in the orchestrator)
|
|
478
|
+
// ---------------------------------------------------------------------------
|
|
479
|
+
|
|
480
|
+
export function buildFieldI18nEntries(fields: ScaffoldField[], i18nPrefix: string): Record<string, string> {
|
|
481
|
+
const entries: Record<string, string> = {}
|
|
482
|
+
for (const field of fields) {
|
|
483
|
+
entries[`${i18nPrefix}.fields.${field.name}`] = humanizeIdentifier(field.name)
|
|
484
|
+
if (field.type === 'select') {
|
|
485
|
+
for (const option of field.options ?? []) {
|
|
486
|
+
entries[`${i18nPrefix}.fields.${field.name}.options.${option}`] = humanizeIdentifier(option)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return entries
|
|
491
|
+
}
|