@specverse/engines 4.1.30 → 4.2.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/assets/examples/manifests/frontend-only.yaml +3 -6
- package/assets/examples/manifests/fullstack-app.yaml +5 -7
- package/assets/examples/manifests/fullstack-monorepo.yaml +3 -6
- package/assets/templates/default/specs/main.specly +65 -0
- package/dist/inference/comprehensive-engine.d.ts.map +1 -1
- package/dist/inference/comprehensive-engine.js +3 -19
- package/dist/inference/comprehensive-engine.js.map +1 -1
- package/dist/inference/core/rule-engine.d.ts +31 -0
- package/dist/inference/core/rule-engine.d.ts.map +1 -1
- package/dist/inference/core/rule-engine.js +117 -33
- package/dist/inference/core/rule-engine.js.map +1 -1
- package/dist/inference/core/rule-file-types.d.ts +0 -2
- package/dist/inference/core/rule-file-types.d.ts.map +1 -1
- package/dist/inference/core/rule-file-types.js +3 -6
- package/dist/inference/core/rule-file-types.js.map +1 -1
- package/dist/inference/core/rule-loader.d.ts +5 -15
- package/dist/inference/core/rule-loader.d.ts.map +1 -1
- package/dist/inference/core/rule-loader.js +43 -132
- package/dist/inference/core/rule-loader.js.map +1 -1
- package/dist/inference/core/types.d.ts +0 -6
- package/dist/inference/core/types.d.ts.map +1 -1
- package/dist/inference/core/types.js +0 -4
- package/dist/inference/core/types.js.map +1 -1
- package/dist/inference/logical/generators/component-type-resolver.d.ts +0 -26
- package/dist/inference/logical/generators/component-type-resolver.d.ts.map +1 -1
- package/dist/inference/logical/generators/component-type-resolver.js +0 -19
- package/dist/inference/logical/generators/component-type-resolver.js.map +1 -1
- package/dist/inference/logical/generators/specialist-view-expander.d.ts +1 -17
- package/dist/inference/logical/generators/specialist-view-expander.d.ts.map +1 -1
- package/dist/inference/logical/generators/specialist-view-expander.js +0 -15
- package/dist/inference/logical/generators/specialist-view-expander.js.map +1 -1
- package/dist/inference/logical/generators/view-generator.d.ts +4 -14
- package/dist/inference/logical/generators/view-generator.d.ts.map +1 -1
- package/dist/inference/logical/generators/view-generator.js +6 -26
- package/dist/inference/logical/generators/view-generator.js.map +1 -1
- package/dist/inference/logical/index.d.ts +2 -2
- package/dist/inference/logical/index.d.ts.map +1 -1
- package/dist/inference/logical/logical-engine.d.ts.map +1 -1
- package/dist/inference/logical/logical-engine.js +17 -80
- package/dist/inference/logical/logical-engine.js.map +1 -1
- package/dist/inference/quint-transpiler.d.ts +5 -3
- package/dist/inference/quint-transpiler.d.ts.map +1 -1
- package/dist/inference/quint-transpiler.js +11 -6
- package/dist/inference/quint-transpiler.js.map +1 -1
- package/dist/libs/instance-factories/CURVED-INTERFACE.md +278 -0
- package/dist/libs/instance-factories/README.md +73 -0
- package/dist/libs/instance-factories/applications/README.md +51 -0
- package/dist/libs/instance-factories/applications/generic-app.yaml +52 -0
- package/{libs/instance-factories/applications/react-app.yaml → dist/libs/instance-factories/applications/react-app-runtime.yaml} +30 -77
- package/dist/libs/instance-factories/applications/react-app-starter.yaml +143 -0
- package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +24 -2
- package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +54 -33
- package/dist/libs/instance-factories/applications/templates/react-starter/README.md +211 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/api-types-starter-generator.js +69 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/app-tsx-generator.js +110 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/belongs-to.js +40 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/dashboard-body-composer.js +129 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/detail-body-composer.js +80 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/form-body-composer.js +217 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/helpers-emitter.js +51 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/html-to-jsx.js +192 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/list-body-composer.js +56 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/orchestrator.js +41 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/package-json-generator.js +38 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/regen-safety.js +89 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/dashboard.tsx.template +49 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/detail.tsx.template +96 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/form.tsx.template +116 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/skeletons/list.tsx.template +74 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/use-api-hooks-starter-generator.js +95 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/view-emitter.js +81 -0
- package/dist/libs/instance-factories/applications/templates/react-starter/views-generator.js +66 -0
- package/dist/libs/instance-factories/archived/fastify-prisma.yaml +104 -0
- package/dist/libs/instance-factories/cli/README.md +43 -0
- package/dist/libs/instance-factories/cli/commander-js.yaml +55 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +63 -12
- package/dist/libs/instance-factories/communication/README.md +47 -0
- package/dist/libs/instance-factories/communication/event-emitter.yaml +60 -0
- package/dist/libs/instance-factories/communication/rabbitmq-events.yaml +87 -0
- package/dist/libs/instance-factories/controllers/README.md +42 -0
- package/dist/libs/instance-factories/controllers/fastify.yaml +139 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +29 -2
- package/dist/libs/instance-factories/infrastructure/README.md +29 -0
- package/dist/libs/instance-factories/infrastructure/docker-k8s.yaml +61 -0
- package/dist/libs/instance-factories/orms/README.md +54 -0
- package/dist/libs/instance-factories/orms/prisma.yaml +89 -0
- package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +2 -2
- package/dist/libs/instance-factories/scaffolding/README.md +49 -0
- package/dist/libs/instance-factories/scaffolding/generic-scaffold.yaml +65 -0
- package/dist/libs/instance-factories/sdks/README.md +28 -0
- package/dist/libs/instance-factories/sdks/python-sdk.yaml +66 -0
- package/dist/libs/instance-factories/sdks/typescript-sdk.yaml +59 -0
- package/dist/libs/instance-factories/services/README.md +55 -0
- package/dist/libs/instance-factories/services/prisma-services.yaml +71 -0
- package/dist/libs/instance-factories/storage/README.md +34 -0
- package/dist/libs/instance-factories/storage/mongodb.yaml +79 -0
- package/dist/libs/instance-factories/storage/postgresql.yaml +75 -0
- package/dist/libs/instance-factories/storage/redis.yaml +79 -0
- package/dist/libs/instance-factories/testing/README.md +40 -0
- package/dist/libs/instance-factories/testing/vitest-tests.yaml +63 -0
- package/dist/libs/instance-factories/tools/README.md +70 -0
- package/dist/libs/instance-factories/tools/mcp.yaml +36 -0
- package/dist/libs/instance-factories/tools/vscode.yaml +35 -0
- package/dist/libs/instance-factories/validation/README.md +38 -0
- package/dist/libs/instance-factories/validation/zod.yaml +56 -0
- package/dist/realize/engines/code-generator.d.ts.map +1 -1
- package/dist/realize/engines/code-generator.js +3 -0
- package/dist/realize/engines/code-generator.js.map +1 -1
- package/dist/realize/index.d.ts.map +1 -1
- package/dist/realize/index.js +15 -22
- package/dist/realize/index.js.map +1 -1
- package/dist/registry/utils/manifest-adapter.d.ts +8 -1
- package/dist/registry/utils/manifest-adapter.d.ts.map +1 -1
- package/dist/registry/utils/manifest-adapter.js +8 -1
- package/dist/registry/utils/manifest-adapter.js.map +1 -1
- package/libs/instance-factories/applications/react-app-starter.yaml +143 -0
- package/libs/instance-factories/applications/templates/react/env-example-generator.ts +24 -2
- package/libs/instance-factories/applications/templates/react/vite-config-generator.ts +54 -33
- package/libs/instance-factories/applications/templates/react-starter/README.md +211 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/dashboard-body-composer.test.ts +153 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/detail-body-composer.test.ts +146 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/form-body-composer.test.ts +188 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/helpers-emitter.test.ts +55 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/html-to-jsx.test.ts +140 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/list-body-composer.test.ts +146 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/orchestrator.test.ts +184 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/parity-p2-factory-imports.test.ts +116 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/parity-p3-rendered-output.test.ts +183 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/regen-safety.test.ts +144 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/starter-generators.test.ts +114 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/view-emitter.test.ts +107 -0
- package/libs/instance-factories/applications/templates/react-starter/__tests__/views-generator.test.ts +139 -0
- package/libs/instance-factories/applications/templates/react-starter/api-types-starter-generator.ts +98 -0
- package/libs/instance-factories/applications/templates/react-starter/app-tsx-generator.ts +141 -0
- package/libs/instance-factories/applications/templates/react-starter/belongs-to.ts +82 -0
- package/libs/instance-factories/applications/templates/react-starter/dashboard-body-composer.ts +189 -0
- package/libs/instance-factories/applications/templates/react-starter/detail-body-composer.ts +135 -0
- package/libs/instance-factories/applications/templates/react-starter/form-body-composer.ts +383 -0
- package/libs/instance-factories/applications/templates/react-starter/helpers-emitter.ts +66 -0
- package/libs/instance-factories/applications/templates/react-starter/html-to-jsx.ts +334 -0
- package/libs/instance-factories/applications/templates/react-starter/list-body-composer.ts +146 -0
- package/libs/instance-factories/applications/templates/react-starter/orchestrator.ts +95 -0
- package/libs/instance-factories/applications/templates/react-starter/package-json-generator.ts +57 -0
- package/libs/instance-factories/applications/templates/react-starter/regen-safety.ts +157 -0
- package/libs/instance-factories/applications/templates/react-starter/skeletons/dashboard.tsx.template +49 -0
- package/libs/instance-factories/applications/templates/react-starter/skeletons/detail.tsx.template +96 -0
- package/libs/instance-factories/applications/templates/react-starter/skeletons/form.tsx.template +116 -0
- package/libs/instance-factories/applications/templates/react-starter/skeletons/list.tsx.template +74 -0
- package/libs/instance-factories/applications/templates/react-starter/use-api-hooks-starter-generator.ts +124 -0
- package/libs/instance-factories/applications/templates/react-starter/view-emitter.ts +209 -0
- package/libs/instance-factories/applications/templates/react-starter/views-generator.ts +137 -0
- package/libs/instance-factories/cli/templates/commander/command-generator.ts +63 -12
- package/libs/instance-factories/controllers/fastify.yaml +7 -0
- package/libs/instance-factories/controllers/templates/fastify/server-generator.ts +36 -2
- package/libs/instance-factories/orms/templates/prisma/schema-generator.ts +11 -4
- package/package.json +3 -3
- package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +0 -530
- package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +0 -73
- package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +0 -99
- package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +0 -49
- package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +0 -156
- package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +0 -935
- package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +0 -143
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +0 -646
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +0 -65
- package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +0 -143
- package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +0 -143
- package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +0 -355
- package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +0 -91
- package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +0 -79
- package/dist/libs/instance-factories/views/index.js +0 -48
- package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +0 -742
- package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +0 -824
- package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +0 -719
- package/dist/libs/instance-factories/views/templates/react/app-generator.js +0 -45
- package/dist/libs/instance-factories/views/templates/react/components-generator.js +0 -820
- package/dist/libs/instance-factories/views/templates/react/forms-generator.js +0 -275
- package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +0 -46
- package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +0 -81
- package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +0 -9
- package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +0 -23
- package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +0 -21
- package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +0 -299
- package/dist/libs/instance-factories/views/templates/react/router-generator.js +0 -136
- package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +0 -107
- package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +0 -187
- package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +0 -7
- package/dist/libs/instance-factories/views/templates/react/types-generator.js +0 -56
- package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +0 -27
- package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +0 -29
- package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +0 -261
- package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +0 -34
- package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +0 -800
- package/dist/libs/instance-factories/views/templates/shared/base-generator.js +0 -305
- package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +0 -517
- package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +0 -445
- package/dist/libs/instance-factories/views/templates/shared/index.js +0 -80
- package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +0 -210
- package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +0 -492
- package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +0 -321
- package/dist/realize/index.js.bak +0 -758
- package/libs/instance-factories/applications/templates/react/_view-components-source.ts +0 -555
- package/libs/instance-factories/applications/templates/react/app-tsx-generator.ts +0 -94
- package/libs/instance-factories/applications/templates/react/field-helpers-generator.ts +0 -106
- package/libs/instance-factories/applications/templates/react/package-json-generator.ts +0 -57
- package/libs/instance-factories/applications/templates/react/pattern-adapter-generator.ts +0 -179
- package/libs/instance-factories/applications/templates/react/react-pattern-adapter.tsx +0 -1347
- package/libs/instance-factories/applications/templates/react/relationship-field-generator.ts +0 -150
- package/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.ts +0 -704
- package/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.ts +0 -84
- package/libs/instance-factories/applications/templates/react/view-dashboard-generator.ts +0 -150
- package/libs/instance-factories/applications/templates/react/view-detail-generator.ts +0 -150
- package/libs/instance-factories/applications/templates/react/view-form-generator.ts +0 -362
- package/libs/instance-factories/applications/templates/react/view-list-generator.ts +0 -98
- package/libs/instance-factories/applications/templates/react/view-router-generator.ts +0 -89
- package/libs/instance-factories/views/README.md +0 -62
- package/libs/instance-factories/views/index.d.ts +0 -13
- package/libs/instance-factories/views/index.d.ts.map +0 -1
- package/libs/instance-factories/views/index.js +0 -18
- package/libs/instance-factories/views/index.js.map +0 -1
- package/libs/instance-factories/views/index.ts +0 -45
- package/libs/instance-factories/views/react-components.yaml +0 -129
- package/libs/instance-factories/views/templates/ARCHITECTURE.md +0 -198
- package/libs/instance-factories/views/templates/react/adapters/antd-adapter.ts +0 -869
- package/libs/instance-factories/views/templates/react/adapters/mui-adapter.ts +0 -953
- package/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.ts +0 -806
- package/libs/instance-factories/views/templates/react/app-generator.ts +0 -55
- package/libs/instance-factories/views/templates/react/components-generator.ts +0 -938
- package/libs/instance-factories/views/templates/react/forms-generator.ts +0 -325
- package/libs/instance-factories/views/templates/react/frontend-package-json-generator.ts +0 -57
- package/libs/instance-factories/views/templates/react/hooks-generator.ts +0 -106
- package/libs/instance-factories/views/templates/react/index-css-generator.ts +0 -14
- package/libs/instance-factories/views/templates/react/index-html-generator.ts +0 -34
- package/libs/instance-factories/views/templates/react/main-tsx-generator.ts +0 -29
- package/libs/instance-factories/views/templates/react/react-component-generator.d.ts +0 -152
- package/libs/instance-factories/views/templates/react/react-component-generator.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/react/react-component-generator.js +0 -398
- package/libs/instance-factories/views/templates/react/react-component-generator.js.map +0 -1
- package/libs/instance-factories/views/templates/react/react-component-generator.ts +0 -533
- package/libs/instance-factories/views/templates/react/router-generator.ts +0 -197
- package/libs/instance-factories/views/templates/react/router-generic-generator.ts +0 -132
- package/libs/instance-factories/views/templates/react/shared-utils-generator.ts +0 -196
- package/libs/instance-factories/views/templates/react/spec-json-generator.ts +0 -17
- package/libs/instance-factories/views/templates/react/types-generator.ts +0 -76
- package/libs/instance-factories/views/templates/react/views-metadata-generator.ts +0 -42
- package/libs/instance-factories/views/templates/react/vite-config-generator.ts +0 -38
- package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js.map +0 -1
- package/libs/instance-factories/views/templates/runtime/runtime-view-renderer.ts +0 -474
- package/libs/instance-factories/views/templates/shared/__tests__/composite-patterns.test.ts +0 -242
- package/libs/instance-factories/views/templates/shared/adapter-types.d.ts +0 -77
- package/libs/instance-factories/views/templates/shared/adapter-types.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/adapter-types.js +0 -47
- package/libs/instance-factories/views/templates/shared/adapter-types.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/adapter-types.ts +0 -142
- package/libs/instance-factories/views/templates/shared/atomic-components-registry.d.ts +0 -63
- package/libs/instance-factories/views/templates/shared/atomic-components-registry.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/atomic-components-registry.js +0 -822
- package/libs/instance-factories/views/templates/shared/atomic-components-registry.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/atomic-components-registry.ts +0 -908
- package/libs/instance-factories/views/templates/shared/base-generator.d.ts +0 -247
- package/libs/instance-factories/views/templates/shared/base-generator.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/base-generator.js +0 -363
- package/libs/instance-factories/views/templates/shared/base-generator.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/base-generator.ts +0 -608
- package/libs/instance-factories/views/templates/shared/component-metadata.d.ts +0 -254
- package/libs/instance-factories/views/templates/shared/component-metadata.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/component-metadata.js +0 -602
- package/libs/instance-factories/views/templates/shared/component-metadata.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/component-metadata.ts +0 -803
- package/libs/instance-factories/views/templates/shared/composite-pattern-types.ts +0 -250
- package/libs/instance-factories/views/templates/shared/composite-patterns.ts +0 -535
- package/libs/instance-factories/views/templates/shared/index.ts +0 -68
- package/libs/instance-factories/views/templates/shared/pattern-validator.ts +0 -279
- package/libs/instance-factories/views/templates/shared/property-mapper.d.ts +0 -149
- package/libs/instance-factories/views/templates/shared/property-mapper.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/property-mapper.js +0 -580
- package/libs/instance-factories/views/templates/shared/property-mapper.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/property-mapper.ts +0 -700
- package/libs/instance-factories/views/templates/shared/syntax-mapper.d.ts +0 -143
- package/libs/instance-factories/views/templates/shared/syntax-mapper.d.ts.map +0 -1
- package/libs/instance-factories/views/templates/shared/syntax-mapper.js +0 -420
- package/libs/instance-factories/views/templates/shared/syntax-mapper.js.map +0 -1
- package/libs/instance-factories/views/templates/shared/syntax-mapper.ts +0 -539
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { generate as generateAppTsx } from '../app-tsx-generator.js';
|
|
4
|
+
import { generate as generatePackageJson } from '../package-json-generator.js';
|
|
5
|
+
|
|
6
|
+
function assertValidTsx(source: string, label: string): void {
|
|
7
|
+
const result = ts.transpileModule(source, {
|
|
8
|
+
compilerOptions: {
|
|
9
|
+
jsx: ts.JsxEmit.Preserve,
|
|
10
|
+
target: ts.ScriptTarget.ES2022,
|
|
11
|
+
module: ts.ModuleKind.ESNext,
|
|
12
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
13
|
+
strict: false,
|
|
14
|
+
},
|
|
15
|
+
reportDiagnostics: true,
|
|
16
|
+
});
|
|
17
|
+
const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
|
|
18
|
+
if (errors.length > 0) {
|
|
19
|
+
const message = errors
|
|
20
|
+
.map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
|
|
21
|
+
.join('\n');
|
|
22
|
+
throw new Error(`${label} failed to parse:\n${message}\n\n--- source ---\n${source}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('app-tsx-generator', () => {
|
|
27
|
+
it('produces valid TSX with one branch per model and view type', async () => {
|
|
28
|
+
const source = await generateAppTsx({
|
|
29
|
+
spec: {
|
|
30
|
+
models: {
|
|
31
|
+
Post: { name: 'Post', attributes: {} },
|
|
32
|
+
Author: { name: 'Author', attributes: {} },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
assertValidTsx(source, 'App.tsx');
|
|
37
|
+
// One nav section per model
|
|
38
|
+
expect(source).toContain('Post');
|
|
39
|
+
expect(source).toContain('Author');
|
|
40
|
+
// One import per (model, view) pair — 2 models × 4 view types = 8 imports
|
|
41
|
+
const importLines = source.match(/^import \{ \w+View \} from '\.\/views\//gm) ?? [];
|
|
42
|
+
expect(importLines.length).toBe(8);
|
|
43
|
+
// Navigation wiring
|
|
44
|
+
expect(source).toContain("select('Post', 'list')");
|
|
45
|
+
expect(source).toContain("select('Author', 'dashboard')");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('handles an empty spec gracefully', async () => {
|
|
49
|
+
const source = await generateAppTsx({ spec: { models: {}, views: {} } });
|
|
50
|
+
assertValidTsx(source, 'App.tsx (empty spec)');
|
|
51
|
+
expect(source).toContain('No models in this spec.');
|
|
52
|
+
// Still renders a QueryClientProvider
|
|
53
|
+
expect(source).toContain('QueryClientProvider');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('uses @tanstack/react-query, not @specverse/runtime', async () => {
|
|
57
|
+
const source = await generateAppTsx({
|
|
58
|
+
spec: { models: { Post: { name: 'Post', attributes: {} } } },
|
|
59
|
+
});
|
|
60
|
+
expect(source).not.toContain('@specverse/runtime');
|
|
61
|
+
expect(source).toContain('@tanstack/react-query');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('package-json-generator', () => {
|
|
66
|
+
it('omits @specverse/runtime from dependencies', async () => {
|
|
67
|
+
const json = await generatePackageJson({ spec: { name: 'test' } });
|
|
68
|
+
const pkg = JSON.parse(json);
|
|
69
|
+
const allDeps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
70
|
+
expect(allDeps['@specverse/runtime']).toBeUndefined();
|
|
71
|
+
expect(allDeps['@specverse/engines']).toBeUndefined();
|
|
72
|
+
expect(allDeps['@specverse/types']).toBeUndefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('includes the deps the emitted views actually need', async () => {
|
|
76
|
+
const json = await generatePackageJson({ spec: { name: 'test' } });
|
|
77
|
+
const pkg = JSON.parse(json);
|
|
78
|
+
expect(pkg.dependencies).toMatchObject({
|
|
79
|
+
react: expect.any(String),
|
|
80
|
+
'react-dom': expect.any(String),
|
|
81
|
+
'@tanstack/react-query': expect.any(String),
|
|
82
|
+
});
|
|
83
|
+
expect(pkg.devDependencies).toMatchObject({
|
|
84
|
+
typescript: expect.any(String),
|
|
85
|
+
vite: expect.any(String),
|
|
86
|
+
tailwindcss: expect.any(String),
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('slugifies the app name', async () => {
|
|
91
|
+
const json = await generatePackageJson({
|
|
92
|
+
spec: { metadata: { name: 'My Fancy App!' } },
|
|
93
|
+
});
|
|
94
|
+
const pkg = JSON.parse(json);
|
|
95
|
+
expect(pkg.name).toBe('my-fancy-app');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('falls back to a default name when none is provided', async () => {
|
|
99
|
+
const json = await generatePackageJson({ spec: {} });
|
|
100
|
+
const pkg = JSON.parse(json);
|
|
101
|
+
expect(pkg.name).toBe('specverse-starter-app');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('parses as valid JSON with the expected shape', async () => {
|
|
105
|
+
const json = await generatePackageJson({ spec: { name: 'test' } });
|
|
106
|
+
const pkg = JSON.parse(json);
|
|
107
|
+
expect(pkg.type).toBe('module');
|
|
108
|
+
expect(pkg.scripts).toMatchObject({
|
|
109
|
+
dev: 'vite',
|
|
110
|
+
build: 'tsc && vite build',
|
|
111
|
+
preview: 'vite preview',
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
package/libs/instance-factories/applications/templates/react-starter/__tests__/view-emitter.test.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { emitView, type EmitContext, type ModelSpec, type ViewSpec } from '../view-emitter.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Build a minimal context. The `renderBody` is a stub that returns a
|
|
7
|
+
* fixed Tailwind table — the point of these tests is the emitter
|
|
8
|
+
* orchestration + substitutions + JSX validity, not the body's content.
|
|
9
|
+
* Parity with the real Tailwind adapter is covered by Phase 3 (P3).
|
|
10
|
+
*/
|
|
11
|
+
function makeContext(overrides: Partial<EmitContext> = {}): EmitContext {
|
|
12
|
+
const defaultModel: ModelSpec = {
|
|
13
|
+
name: 'Post',
|
|
14
|
+
attributes: {
|
|
15
|
+
id: { type: 'UUID', required: true },
|
|
16
|
+
title: { type: 'String', required: true },
|
|
17
|
+
body: { type: 'Text', required: false },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const defaultView: ViewSpec = {
|
|
22
|
+
type: 'list',
|
|
23
|
+
model: 'Post',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
view: defaultView,
|
|
28
|
+
viewName: 'PostListView',
|
|
29
|
+
model: defaultModel,
|
|
30
|
+
modelSchemas: { Post: defaultModel },
|
|
31
|
+
// renderBody returns JSX-ready source that will be injected verbatim
|
|
32
|
+
// into {{BODY}}. NOT raw HTML — that's the composer's job.
|
|
33
|
+
renderBody: () =>
|
|
34
|
+
'<table className="w-full"><thead><tr><th className="px-4 py-2">Title</th></tr></thead>' +
|
|
35
|
+
'<tbody><tr><td className="px-4 py-2">Example</td></tr></tbody></table>',
|
|
36
|
+
...overrides,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertValidTsx(source: string, label: string): void {
|
|
41
|
+
const result = ts.transpileModule(source, {
|
|
42
|
+
compilerOptions: {
|
|
43
|
+
jsx: ts.JsxEmit.Preserve,
|
|
44
|
+
target: ts.ScriptTarget.ES2022,
|
|
45
|
+
module: ts.ModuleKind.ESNext,
|
|
46
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
47
|
+
strict: false,
|
|
48
|
+
},
|
|
49
|
+
reportDiagnostics: true,
|
|
50
|
+
});
|
|
51
|
+
const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
|
|
52
|
+
if (errors.length > 0) {
|
|
53
|
+
const message = errors
|
|
54
|
+
.map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
|
|
55
|
+
.join('\n');
|
|
56
|
+
throw new Error(`${label} failed to parse as TSX:\n${message}\n\n--- source ---\n${source}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe('emitView — list', () => {
|
|
61
|
+
it('produces TSX that parses cleanly', () => {
|
|
62
|
+
const context = makeContext();
|
|
63
|
+
const source = emitView(context);
|
|
64
|
+
assertValidTsx(source, 'emitted list view');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('substitutes model names into the skeleton', () => {
|
|
68
|
+
const source = emitView(makeContext());
|
|
69
|
+
expect(source).toContain('PostListView'); // component name
|
|
70
|
+
expect(source).toContain('usePostsQuery'); // generated hook name
|
|
71
|
+
expect(source).toContain('useDeletePostMutation'); // generated hook name
|
|
72
|
+
expect(source).toContain("Search posts…"); // pluralized lowercase
|
|
73
|
+
expect(source).toContain('+ New Post'); // action button label
|
|
74
|
+
expect(source).toContain('No posts yet.'); // empty state
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('substitutes a non-trivial plural correctly', () => {
|
|
78
|
+
const m: ModelSpec = { name: 'Category', attributes: {} };
|
|
79
|
+
const source = emitView(makeContext({
|
|
80
|
+
model: m,
|
|
81
|
+
view: { type: 'list', model: 'Category' },
|
|
82
|
+
viewName: 'CategoryListView',
|
|
83
|
+
modelSchemas: { Category: m },
|
|
84
|
+
}));
|
|
85
|
+
expect(source).toContain('CategoryListView');
|
|
86
|
+
expect(source).toContain('useCategoriesQuery'); // "Category" → "Categories"
|
|
87
|
+
expect(source).toContain('Search categories…');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('injects the rendered body at {{BODY}}', () => {
|
|
91
|
+
const source = emitView(makeContext({
|
|
92
|
+
renderBody: () => '<table className="my-table"><tbody><tr><td>Custom</td></tr></tbody></table>',
|
|
93
|
+
}));
|
|
94
|
+
expect(source).toContain('<table className="my-table">');
|
|
95
|
+
expect(source).toContain('Custom');
|
|
96
|
+
// The placeholder itself should be gone.
|
|
97
|
+
expect(source).not.toContain('{{BODY}}');
|
|
98
|
+
// All other placeholders should be gone too.
|
|
99
|
+
expect(source).not.toMatch(/\{\{[A-Z_]+\}\}/);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('throws for an unknown view type', () => {
|
|
103
|
+
expect(() =>
|
|
104
|
+
emitView(makeContext({ view: { type: 'unknown-type-xyz' } }))
|
|
105
|
+
).toThrow(/No skeleton registered/);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import { generate, type ExpandedSpec } from '../views-generator.js';
|
|
4
|
+
|
|
5
|
+
function makeSpec(): ExpandedSpec {
|
|
6
|
+
return {
|
|
7
|
+
models: {
|
|
8
|
+
Post: {
|
|
9
|
+
name: 'Post',
|
|
10
|
+
attributes: {
|
|
11
|
+
id: { type: 'UUID', required: true, auto: 'uuid4' },
|
|
12
|
+
title: { type: 'String', required: true },
|
|
13
|
+
body: { type: 'Text', required: false },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
Author: {
|
|
17
|
+
name: 'Author',
|
|
18
|
+
attributes: {
|
|
19
|
+
id: { type: 'UUID', required: true, auto: 'uuid4' },
|
|
20
|
+
name: { type: 'String', required: true },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
views: {},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function assertValidTsx(source: string, label: string): void {
|
|
29
|
+
const result = ts.transpileModule(source, {
|
|
30
|
+
compilerOptions: {
|
|
31
|
+
jsx: ts.JsxEmit.Preserve,
|
|
32
|
+
target: ts.ScriptTarget.ES2022,
|
|
33
|
+
module: ts.ModuleKind.ESNext,
|
|
34
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
35
|
+
strict: false,
|
|
36
|
+
},
|
|
37
|
+
reportDiagnostics: true,
|
|
38
|
+
});
|
|
39
|
+
const errors = result.diagnostics?.filter(d => d.category === ts.DiagnosticCategory.Error) ?? [];
|
|
40
|
+
if (errors.length > 0) {
|
|
41
|
+
const message = errors
|
|
42
|
+
.map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
|
|
43
|
+
.join('\n');
|
|
44
|
+
throw new Error(`${label} failed to parse as TSX:\n${message}\n\n--- source ---\n${source}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('views-generator.generate', () => {
|
|
49
|
+
it('emits 4 view files per model plus the helpers file', async () => {
|
|
50
|
+
const files = await generate({ spec: makeSpec() });
|
|
51
|
+
const paths = Object.keys(files);
|
|
52
|
+
expect(paths).toContain('src/views/PostListView.tsx');
|
|
53
|
+
expect(paths).toContain('src/views/PostDetailView.tsx');
|
|
54
|
+
expect(paths).toContain('src/views/PostFormView.tsx');
|
|
55
|
+
expect(paths).toContain('src/views/PostDashboardView.tsx');
|
|
56
|
+
expect(paths).toContain('src/views/AuthorListView.tsx');
|
|
57
|
+
expect(paths).toContain('src/views/AuthorDetailView.tsx');
|
|
58
|
+
expect(paths).toContain('src/views/AuthorFormView.tsx');
|
|
59
|
+
expect(paths).toContain('src/views/AuthorDashboardView.tsx');
|
|
60
|
+
expect(paths).toContain('src/lib/entity-display.ts');
|
|
61
|
+
// 2 models × 4 view types + 1 helper = 9 files.
|
|
62
|
+
expect(paths.length).toBe(9);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('every emitted view file parses as valid TSX', async () => {
|
|
66
|
+
const files = await generate({ spec: makeSpec() });
|
|
67
|
+
for (const [path, source] of Object.entries(files)) {
|
|
68
|
+
if (path.endsWith('.tsx')) assertValidTsx(source, path);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('uses a user-declared view spec in preference to a synthesized default', async () => {
|
|
73
|
+
const spec: ExpandedSpec = {
|
|
74
|
+
models: {
|
|
75
|
+
Post: {
|
|
76
|
+
name: 'Post',
|
|
77
|
+
attributes: {
|
|
78
|
+
id: { type: 'UUID', auto: 'uuid4' },
|
|
79
|
+
title: { type: 'String', required: true },
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
views: {
|
|
84
|
+
PostListView: {
|
|
85
|
+
type: 'list',
|
|
86
|
+
model: 'Post',
|
|
87
|
+
uiComponents: {
|
|
88
|
+
customTable: {
|
|
89
|
+
type: 'table',
|
|
90
|
+
properties: {
|
|
91
|
+
columns: ['SUPER CUSTOM COLUMN'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
const files = await generate({ spec });
|
|
99
|
+
const out = files['src/views/PostListView.tsx'];
|
|
100
|
+
// The user's custom column header is not directly visible because
|
|
101
|
+
// the current composer ignores user uiComponents (it infers
|
|
102
|
+
// columns from the model). But the view spec flows through — if
|
|
103
|
+
// we later teach the composer to honour uiComponents, this test
|
|
104
|
+
// anchors the contract.
|
|
105
|
+
expect(out).toBeDefined();
|
|
106
|
+
expect(out).toContain('export function PostListView');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('warns on specialist view types and skips them', async () => {
|
|
110
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
111
|
+
try {
|
|
112
|
+
const spec: ExpandedSpec = {
|
|
113
|
+
models: {
|
|
114
|
+
Post: { name: 'Post', attributes: { id: { auto: 'uuid4' }, title: {} } },
|
|
115
|
+
},
|
|
116
|
+
views: {
|
|
117
|
+
PostBoardView: { type: 'board', model: 'Post' },
|
|
118
|
+
PostTimelineView: { type: 'timeline', model: 'Post' },
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
const files = await generate({ spec });
|
|
122
|
+
expect(files['src/views/PostBoardView.tsx']).toBeUndefined();
|
|
123
|
+
expect(files['src/views/PostTimelineView.tsx']).toBeUndefined();
|
|
124
|
+
expect(warn).toHaveBeenCalled();
|
|
125
|
+
const warning = warn.mock.calls[0][0] as string;
|
|
126
|
+
expect(warning).toContain('Skipped');
|
|
127
|
+
expect(warning).toContain('board');
|
|
128
|
+
expect(warning).toContain('timeline');
|
|
129
|
+
} finally {
|
|
130
|
+
warn.mockRestore();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('handles an empty models map gracefully', async () => {
|
|
135
|
+
const files = await generate({ spec: { models: {}, views: {} } });
|
|
136
|
+
// Only the helpers file is emitted; no view files.
|
|
137
|
+
expect(Object.keys(files)).toEqual(['src/lib/entity-display.ts']);
|
|
138
|
+
});
|
|
139
|
+
});
|
package/libs/instance-factories/applications/templates/react-starter/api-types-starter-generator.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API types generator for ReactAppStarter
|
|
3
|
+
*
|
|
4
|
+
* Emits per-model TypeScript interfaces that the starter's view
|
|
5
|
+
* skeletons import (`import type { Task } from '../types/api'`). The
|
|
6
|
+
* shape mirrors the model's attributes as declared in the spec. No
|
|
7
|
+
* runtime-specific types (those live in ReactAppRuntime's api-types
|
|
8
|
+
* generator).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface ApiTypesStarterContext {
|
|
12
|
+
spec: {
|
|
13
|
+
models?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
manifest?: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Map SpecVerse attribute types to TypeScript types.
|
|
20
|
+
*
|
|
21
|
+
* Strings vs unions: if the attribute has a `values` enum (e.g.
|
|
22
|
+
* status: String values=[draft,published]), emit a union type.
|
|
23
|
+
*/
|
|
24
|
+
function mapAttrType(attr: any): string {
|
|
25
|
+
const t = typeof attr === 'string'
|
|
26
|
+
? attr.split(/\s+/)[0]
|
|
27
|
+
: attr?.type;
|
|
28
|
+
const values = attr?.values;
|
|
29
|
+
if (Array.isArray(values) && values.length > 0) {
|
|
30
|
+
return values.map((v: string) => JSON.stringify(v)).join(' | ');
|
|
31
|
+
}
|
|
32
|
+
switch ((t || '').toLowerCase()) {
|
|
33
|
+
case 'string':
|
|
34
|
+
case 'text':
|
|
35
|
+
case 'uuid':
|
|
36
|
+
case 'email':
|
|
37
|
+
case 'url':
|
|
38
|
+
return 'string';
|
|
39
|
+
case 'int':
|
|
40
|
+
case 'integer':
|
|
41
|
+
case 'float':
|
|
42
|
+
case 'number':
|
|
43
|
+
case 'decimal':
|
|
44
|
+
return 'number';
|
|
45
|
+
case 'boolean':
|
|
46
|
+
case 'bool':
|
|
47
|
+
return 'boolean';
|
|
48
|
+
case 'datetime':
|
|
49
|
+
case 'date':
|
|
50
|
+
case 'time':
|
|
51
|
+
case 'timestamp':
|
|
52
|
+
return 'string';
|
|
53
|
+
case 'json':
|
|
54
|
+
return 'Record<string, unknown>';
|
|
55
|
+
default:
|
|
56
|
+
return 'unknown';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isRequired(attr: any): boolean {
|
|
61
|
+
if (typeof attr === 'string') return /\brequired\b/.test(attr);
|
|
62
|
+
return !!attr?.required;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function generate(context: ApiTypesStarterContext): Promise<string> {
|
|
66
|
+
const models = context.spec.models ?? {};
|
|
67
|
+
const modelNames = Object.keys(models);
|
|
68
|
+
|
|
69
|
+
const header = `/**
|
|
70
|
+
* API types (ReactAppStarter)
|
|
71
|
+
*
|
|
72
|
+
* Per-model interfaces generated from the spec's model definitions.
|
|
73
|
+
* Safe to edit — extend these when your UI needs more than the spec
|
|
74
|
+
* describes (e.g. optimistic fields, denormalized joins).
|
|
75
|
+
*/
|
|
76
|
+
`;
|
|
77
|
+
|
|
78
|
+
const interfaces = modelNames.map(name => {
|
|
79
|
+
const model = models[name] || {};
|
|
80
|
+
const attrs = model.attributes || {};
|
|
81
|
+
const attrKeys = Object.keys(attrs);
|
|
82
|
+
|
|
83
|
+
const fields = attrKeys.map(attrName => {
|
|
84
|
+
const attr = attrs[attrName];
|
|
85
|
+
const tsType = mapAttrType(attr);
|
|
86
|
+
const optional = isRequired(attr) ? '' : '?';
|
|
87
|
+
return ` ${attrName}${optional}: ${tsType};`;
|
|
88
|
+
}).join('\n');
|
|
89
|
+
|
|
90
|
+
return `export interface ${name} {
|
|
91
|
+
${fields || ' [key: string]: unknown;'}
|
|
92
|
+
}`;
|
|
93
|
+
}).join('\n\n');
|
|
94
|
+
|
|
95
|
+
return header + '\n' + interfaces + '\n';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default generate;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App.tsx generator for ReactAppStarter
|
|
3
|
+
*
|
|
4
|
+
* Generates a simple App shell that routes between the emitted view
|
|
5
|
+
* components. Not using react-router — the starter output is
|
|
6
|
+
* deliberately low-magic. Users can add routing when they need
|
|
7
|
+
* URL-level view selection; for now, internal state drives it.
|
|
8
|
+
*
|
|
9
|
+
* Output:
|
|
10
|
+
* - sidebar nav listing every (model × view-type)
|
|
11
|
+
* - a main area rendering the selected view
|
|
12
|
+
* - QueryClientProvider at the root
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { ExpandedSpec } from './views-generator.js';
|
|
16
|
+
|
|
17
|
+
export interface AppGeneratorContext {
|
|
18
|
+
spec: ExpandedSpec;
|
|
19
|
+
manifest?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function generate(context: AppGeneratorContext): Promise<string> {
|
|
23
|
+
const models = Object.keys(context.spec.models ?? {});
|
|
24
|
+
const imports = buildImports(models);
|
|
25
|
+
const navEntries = buildNavEntries(models);
|
|
26
|
+
const viewSwitch = buildViewSwitch(models);
|
|
27
|
+
|
|
28
|
+
return `/**
|
|
29
|
+
* App.tsx — generated by @specverse/realize (ReactAppStarter)
|
|
30
|
+
*
|
|
31
|
+
* Safe to edit. Edits are preserved across regeneration via content
|
|
32
|
+
* hashing. This is a minimal shell: a sidebar listing every
|
|
33
|
+
* (model, view-type) plus a main area that renders the selection.
|
|
34
|
+
* Swap in react-router or your preferred routing library when the
|
|
35
|
+
* app needs URL-driven navigation.
|
|
36
|
+
*/
|
|
37
|
+
import { useState } from 'react';
|
|
38
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
39
|
+
${imports}
|
|
40
|
+
|
|
41
|
+
const queryClient = new QueryClient({
|
|
42
|
+
defaultOptions: {
|
|
43
|
+
queries: { staleTime: 5 * 60 * 1000, retry: 1 },
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
type Selection = {
|
|
48
|
+
model: string;
|
|
49
|
+
view: 'list' | 'detail' | 'form' | 'dashboard';
|
|
50
|
+
entityId?: string | number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function Inner() {
|
|
54
|
+
const [selection, setSelection] = useState<Selection>(${models.length > 0 ? `{ model: '${models[0]}', view: 'list' }` : `{ model: '', view: 'list' }`});
|
|
55
|
+
|
|
56
|
+
const select = (model: string, view: Selection['view']) =>
|
|
57
|
+
setSelection({ model, view });
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className="min-h-screen flex bg-gray-50 dark:bg-gray-950">
|
|
61
|
+
<aside className="w-64 shrink-0 border-r border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900">
|
|
62
|
+
<div className="p-4 border-b border-gray-200 dark:border-gray-800">
|
|
63
|
+
<h1 className="text-lg font-semibold text-gray-900 dark:text-gray-100">App</h1>
|
|
64
|
+
</div>
|
|
65
|
+
<nav className="p-2 space-y-4">
|
|
66
|
+
${navEntries}
|
|
67
|
+
</nav>
|
|
68
|
+
</aside>
|
|
69
|
+
|
|
70
|
+
<main className="flex-1 overflow-auto">
|
|
71
|
+
${viewSwitch}
|
|
72
|
+
</main>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default function App() {
|
|
78
|
+
return (
|
|
79
|
+
<QueryClientProvider client={queryClient}>
|
|
80
|
+
<Inner />
|
|
81
|
+
</QueryClientProvider>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
88
|
+
// Helpers
|
|
89
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
function buildImports(models: string[]): string {
|
|
92
|
+
return models.flatMap(m => [
|
|
93
|
+
`import { ${m}ListView } from './views/${m}ListView';`,
|
|
94
|
+
`import { ${m}DetailView } from './views/${m}DetailView';`,
|
|
95
|
+
`import { ${m}FormView } from './views/${m}FormView';`,
|
|
96
|
+
`import { ${m}DashboardView } from './views/${m}DashboardView';`,
|
|
97
|
+
]).join('\n');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function buildNavEntries(models: string[]): string {
|
|
101
|
+
if (models.length === 0) {
|
|
102
|
+
return ' <p className="text-sm text-gray-400 px-2">No models in this spec.</p>';
|
|
103
|
+
}
|
|
104
|
+
return models.map(m => ` <div>
|
|
105
|
+
<div className="px-2 pb-1 text-xs font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400">
|
|
106
|
+
${m}
|
|
107
|
+
</div>
|
|
108
|
+
<button type="button" onClick={() => select('${m}', 'list')} className="${navButtonCls('list')}">List</button>
|
|
109
|
+
<button type="button" onClick={() => select('${m}', 'dashboard')} className="${navButtonCls('dashboard')}">Dashboard</button>
|
|
110
|
+
<button type="button" onClick={() => select('${m}', 'form')} className="${navButtonCls('form')}">Form</button>
|
|
111
|
+
</div>`).join('\n');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function navButtonCls(_view: string): string {
|
|
115
|
+
return (
|
|
116
|
+
'block w-full text-left rounded px-2 py-1 text-sm ' +
|
|
117
|
+
'text-gray-700 hover:bg-gray-100 ' +
|
|
118
|
+
'dark:text-gray-300 dark:hover:bg-gray-800'
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function buildViewSwitch(models: string[]): string {
|
|
123
|
+
if (models.length === 0) {
|
|
124
|
+
return ' <p className="p-6 text-sm text-gray-400">No models — add one to your .specly file and run <code>spv realize</code>.</p>';
|
|
125
|
+
}
|
|
126
|
+
const branches = models.flatMap(m => [
|
|
127
|
+
` {selection.model === '${m}' && selection.view === 'list' && (
|
|
128
|
+
<${m}ListView onSelect={item => setSelection({ model: '${m}', view: 'detail', entityId: (item as any).id })} onCreate={() => setSelection({ model: '${m}', view: 'form' })} />
|
|
129
|
+
)}`,
|
|
130
|
+
` {selection.model === '${m}' && selection.view === 'detail' && selection.entityId !== undefined && (
|
|
131
|
+
<${m}DetailView entityId={selection.entityId} onEdit={item => setSelection({ model: '${m}', view: 'form', entityId: (item as any).id })} onBack={() => setSelection({ model: '${m}', view: 'list' })} onDeleted={() => setSelection({ model: '${m}', view: 'list' })} />
|
|
132
|
+
)}`,
|
|
133
|
+
` {selection.model === '${m}' && selection.view === 'form' && (
|
|
134
|
+
<${m}FormView mode={selection.entityId ? 'update' : 'create'} entityId={selection.entityId} onSuccess={() => setSelection({ model: '${m}', view: 'list' })} onCancel={() => setSelection({ model: '${m}', view: 'list' })} />
|
|
135
|
+
)}`,
|
|
136
|
+
` {selection.model === '${m}' && selection.view === 'dashboard' && (
|
|
137
|
+
<${m}DashboardView onSelect={item => setSelection({ model: '${m}', view: 'detail', entityId: (item as any).id })} />
|
|
138
|
+
)}`,
|
|
139
|
+
]);
|
|
140
|
+
return branches.join('\n');
|
|
141
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helper: extract belongsTo relationships from a model.
|
|
3
|
+
*
|
|
4
|
+
* Used by both the form-body composer (emits <select> dropdowns) and
|
|
5
|
+
* view-emitter (generates the import + hook wiring for those
|
|
6
|
+
* dropdowns). Keeping this in one place means form JSX and skeleton
|
|
7
|
+
* substitutions can't drift.
|
|
8
|
+
*
|
|
9
|
+
* Supports both shapes a parsed spec can use:
|
|
10
|
+
* - Convention string: "belongsTo User cascade"
|
|
11
|
+
* - Structured object: { type: "belongsTo", target: "User" }
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { ModelSpec } from './view-emitter.js';
|
|
15
|
+
|
|
16
|
+
export interface BelongsToRel {
|
|
17
|
+
/** Relationship name — e.g. "owner", "assignee". */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Target model name — e.g. "User". */
|
|
20
|
+
target: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function extractBelongsToTargets(model: ModelSpec): BelongsToRel[] {
|
|
24
|
+
const rels = (model.relationships ?? {}) as Record<string, unknown>;
|
|
25
|
+
const out: BelongsToRel[] = [];
|
|
26
|
+
|
|
27
|
+
for (const [name, rawDef] of Object.entries(rels)) {
|
|
28
|
+
const parsed = parseBelongsTo(rawDef);
|
|
29
|
+
if (parsed) out.push({ name, target: parsed });
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function parseBelongsTo(def: unknown): string | null {
|
|
35
|
+
// Convention string: "belongsTo User cascade" / "belongsTo User"
|
|
36
|
+
if (typeof def === 'string') {
|
|
37
|
+
const parts = def.trim().split(/\s+/);
|
|
38
|
+
if (parts[0] === 'belongsTo' && parts[1]) return parts[1];
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
// Structured: { type: "belongsTo", target: "User" } — support all
|
|
42
|
+
// of the field names the parsed spec can use ("target", "to",
|
|
43
|
+
// "model", "targetModel"). The normalizer upstream is inconsistent
|
|
44
|
+
// and normalizing it there is out of scope for this composer.
|
|
45
|
+
if (def && typeof def === 'object') {
|
|
46
|
+
const o = def as { type?: string; target?: string; to?: string; model?: string; targetModel?: string };
|
|
47
|
+
if (o.type === 'belongsTo') {
|
|
48
|
+
return o.target || o.to || o.model || o.targetModel || null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Minimal English pluralizer, matching view-emitter's and
|
|
56
|
+
* use-api-hooks-starter-generator's convention. Centralizing it here
|
|
57
|
+
* keeps the generated hook names (useUsersQuery) aligned with what
|
|
58
|
+
* the emitter imports.
|
|
59
|
+
*/
|
|
60
|
+
export function pluralize(s: string): string {
|
|
61
|
+
if (/[^aeiou]y$/i.test(s)) return s.slice(0, -1) + 'ies';
|
|
62
|
+
if (/(s|x|z|ch|sh)$/i.test(s)) return s + 'es';
|
|
63
|
+
return s + 's';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Build a map from FK column name → belongsTo relationship. Used by
|
|
68
|
+
* every view composer (list, detail, dashboard, form) to detect when
|
|
69
|
+
* an attribute is really a foreign key and should render as a resolved
|
|
70
|
+
* display name, not a raw UUID.
|
|
71
|
+
*
|
|
72
|
+
* Convention: a belongsTo relationship named `owner` pointing at `User`
|
|
73
|
+
* implies a column `ownerId: UUID` on the owning model. This function
|
|
74
|
+
* materializes that convention.
|
|
75
|
+
*/
|
|
76
|
+
export function buildFKMap(model: ModelSpec): Map<string, BelongsToRel> {
|
|
77
|
+
const map = new Map<string, BelongsToRel>();
|
|
78
|
+
for (const rel of extractBelongsToTargets(model)) {
|
|
79
|
+
map.set(`${rel.name}Id`, rel);
|
|
80
|
+
}
|
|
81
|
+
return map;
|
|
82
|
+
}
|