@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
|
@@ -10,8 +10,10 @@ manifests:
|
|
|
10
10
|
apiBaseUrl: "${VITE_API_BASE_URL}"
|
|
11
11
|
apiPrefix: "/api"
|
|
12
12
|
capabilityMappings:
|
|
13
|
+
# ReactAppRuntime — slim shell backed by @specverse/runtime.
|
|
14
|
+
# Swap for ReactAppStarter to get a standalone starter kit.
|
|
13
15
|
- capability: "app.frontend"
|
|
14
|
-
instanceFactory: "
|
|
16
|
+
instanceFactory: "ReactAppRuntime"
|
|
15
17
|
configuration:
|
|
16
18
|
outputStructure: "standalone"
|
|
17
19
|
frontendDir: "."
|
|
@@ -20,8 +22,3 @@ manifests:
|
|
|
20
22
|
port: 5173
|
|
21
23
|
proxy:
|
|
22
24
|
/api: "${VITE_API_BASE_URL}"
|
|
23
|
-
- capability: "ui.components"
|
|
24
|
-
instanceFactory: "ReactComponents"
|
|
25
|
-
configuration:
|
|
26
|
-
outputStructure: "standalone"
|
|
27
|
-
frontendDir: "."
|
|
@@ -11,7 +11,7 @@ manifests:
|
|
|
11
11
|
storage: "PostgreSQL15"
|
|
12
12
|
controller: "FastifyAPI"
|
|
13
13
|
service: "PrismaORM"
|
|
14
|
-
view: "
|
|
14
|
+
view: "ReactAppRuntime"
|
|
15
15
|
communication: "EventEmitter"
|
|
16
16
|
capabilityMappings:
|
|
17
17
|
- capability: "api.rest"
|
|
@@ -20,12 +20,10 @@ manifests:
|
|
|
20
20
|
instanceFactory: "FastifyAPI"
|
|
21
21
|
- capability: "storage.database"
|
|
22
22
|
instanceFactory: "PostgreSQL15"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- capability: "
|
|
26
|
-
instanceFactory: "
|
|
27
|
-
- capability: "ui.forms"
|
|
28
|
-
instanceFactory: "ReactComponents"
|
|
23
|
+
# ReactAppRuntime — slim shell backed by @specverse/runtime.
|
|
24
|
+
# Swap for ReactAppStarter to get a standalone starter kit.
|
|
25
|
+
- capability: "app.frontend"
|
|
26
|
+
instanceFactory: "ReactAppRuntime"
|
|
29
27
|
- capability: "messaging.pubsub"
|
|
30
28
|
instanceFactory: "EventEmitter"
|
|
31
29
|
- capability: "messaging.events"
|
|
@@ -37,8 +37,10 @@ manifests:
|
|
|
37
37
|
configuration:
|
|
38
38
|
outputStructure: "monorepo"
|
|
39
39
|
backendDir: "backend"
|
|
40
|
+
# ReactAppRuntime — slim shell backed by @specverse/runtime.
|
|
41
|
+
# Swap for ReactAppStarter to get a standalone starter kit.
|
|
40
42
|
- capability: "app.frontend"
|
|
41
|
-
instanceFactory: "
|
|
43
|
+
instanceFactory: "ReactAppRuntime"
|
|
42
44
|
configuration:
|
|
43
45
|
outputStructure: "monorepo"
|
|
44
46
|
frontendDir: "frontend"
|
|
@@ -47,11 +49,6 @@ manifests:
|
|
|
47
49
|
port: 5173
|
|
48
50
|
proxy:
|
|
49
51
|
/api: "http://localhost:3000"
|
|
50
|
-
- capability: "ui.components"
|
|
51
|
-
instanceFactory: "ReactComponents"
|
|
52
|
-
configuration:
|
|
53
|
-
outputStructure: "monorepo"
|
|
54
|
-
frontendDir: "frontend"
|
|
55
52
|
- capability: "project.scaffold"
|
|
56
53
|
instanceFactory: "GenericScaffold"
|
|
57
54
|
configuration:
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Starter specification.
|
|
2
|
+
#
|
|
3
|
+
# Two models, one belongsTo relationship, one lifecycle. Small enough
|
|
4
|
+
# to read in 30 seconds, rich enough to exercise the generated-UI
|
|
5
|
+
# rules you'll build on: lifecycle dropdowns, belongsTo FK dropdowns,
|
|
6
|
+
# FK resolution in list / detail / dashboard columns.
|
|
7
|
+
components:
|
|
8
|
+
{{componentName}}:
|
|
9
|
+
version: "1.0.0"
|
|
10
|
+
description: "Starter specification — use the AI tab to extend it"
|
|
11
|
+
tags: [default, minimal]
|
|
12
|
+
|
|
13
|
+
models:
|
|
14
|
+
Category:
|
|
15
|
+
description: "A grouping label for Items"
|
|
16
|
+
attributes:
|
|
17
|
+
id: UUID required auto=uuid4
|
|
18
|
+
name: String required unique
|
|
19
|
+
description: Text
|
|
20
|
+
createdAt: DateTime auto=now
|
|
21
|
+
updatedAt: DateTime auto=now
|
|
22
|
+
relationships:
|
|
23
|
+
items: hasMany Item
|
|
24
|
+
|
|
25
|
+
Item:
|
|
26
|
+
description: "Something worth tracking"
|
|
27
|
+
attributes:
|
|
28
|
+
id: UUID required auto=uuid4
|
|
29
|
+
name: String required
|
|
30
|
+
description: Text
|
|
31
|
+
status: String required default=active
|
|
32
|
+
createdAt: DateTime auto=now
|
|
33
|
+
updatedAt: DateTime auto=now
|
|
34
|
+
relationships:
|
|
35
|
+
category: belongsTo Category
|
|
36
|
+
lifecycles:
|
|
37
|
+
status:
|
|
38
|
+
flow: "active -> archived"
|
|
39
|
+
|
|
40
|
+
views:
|
|
41
|
+
CategoryListView:
|
|
42
|
+
type: list
|
|
43
|
+
model: Category
|
|
44
|
+
CategoryDetailView:
|
|
45
|
+
type: detail
|
|
46
|
+
model: Category
|
|
47
|
+
CategoryFormView:
|
|
48
|
+
type: form
|
|
49
|
+
model: Category
|
|
50
|
+
CategoryDashboardView:
|
|
51
|
+
type: dashboard
|
|
52
|
+
model: Category
|
|
53
|
+
|
|
54
|
+
ItemListView:
|
|
55
|
+
type: list
|
|
56
|
+
model: Item
|
|
57
|
+
ItemDetailView:
|
|
58
|
+
type: detail
|
|
59
|
+
model: Item
|
|
60
|
+
ItemFormView:
|
|
61
|
+
type: form
|
|
62
|
+
model: Item
|
|
63
|
+
ItemDashboardView:
|
|
64
|
+
type: dashboard
|
|
65
|
+
model: Item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comprehensive-engine.d.ts","sourceRoot":"","sources":["../../src/inference/comprehensive-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EAErB,gBAAgB,EAChB,qBAAqB,EAEtB,MAAM,iBAAiB,CAAC;AAOzB,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,oBAAoB,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACnD,UAAU,EAAE,gBAAgB,CAAC;IAC7B,UAAU,EAAE;QACV,eAAe,EAAE,MAAM,CAAC;QACxB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;QACvB,oBAAoB,EAAE,MAAM,CA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BACjB,QAAQ,EAAE,MAAM,CAAC;aAClB,CAAC;SACH,CAAC;KACH;CAsBF"}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { DEFAULT_ENGINE_CONFIG } from './core/types.js';
|
|
6
6
|
import { LogicalInferenceEngine } from './logical/logical-engine.js';
|
|
7
|
-
import * as fs from 'fs';
|
|
8
7
|
import { DeploymentInferenceGenerator } from './deployment/deployment-generator.js';
|
|
9
8
|
import { RuleLoader } from './core/rule-loader.js';
|
|
10
9
|
import { InferenceContextManager } from './core/context.js';
|
|
@@ -45,25 +44,10 @@ export class ComprehensiveInferenceEngine {
|
|
|
45
44
|
validation.warnings.push(...logicalValidation.warnings);
|
|
46
45
|
if (!logicalValidation.valid)
|
|
47
46
|
validation.valid = false;
|
|
48
|
-
// Load deployment rules if deployment inference is enabled
|
|
47
|
+
// Load deployment rules if deployment inference is enabled. The
|
|
48
|
+
// logical engine above already populated the ruleLoader via the
|
|
49
|
+
// entity registry, so this is just a pull of the deployment slice.
|
|
49
50
|
if (this.config.deployment.generateInstances) {
|
|
50
|
-
// Try directory first, fall back to entity registry
|
|
51
|
-
if (fs.existsSync(this.config.rules.deploymentRulesPath)) {
|
|
52
|
-
const { ruleSets, validation: deploymentLoadValidation } = await this.ruleLoader.loadRulesFromDirectory(this.config.rules.deploymentRulesPath);
|
|
53
|
-
validation.errors.push(...deploymentLoadValidation.errors);
|
|
54
|
-
validation.warnings.push(...deploymentLoadValidation.warnings);
|
|
55
|
-
if (!deploymentLoadValidation.valid)
|
|
56
|
-
validation.valid = false;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
// Directory not available — try entity registry
|
|
60
|
-
const registryResult = await this.ruleLoader.loadRulesFromRegistry();
|
|
61
|
-
if (registryResult.loaded) {
|
|
62
|
-
validation.errors.push(...registryResult.validation.errors);
|
|
63
|
-
validation.warnings.push(...registryResult.validation.warnings);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// Extract deployment rules and load into generator
|
|
67
51
|
const deploymentRules = this.ruleLoader.getDeploymentRules();
|
|
68
52
|
if (deploymentRules.instances.length > 0) {
|
|
69
53
|
const deploymentValidation = await this.deploymentGenerator.loadRules(deploymentRules.instances);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comprehensive-engine.js","sourceRoot":"","sources":["../../src/inference/comprehensive-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAOL,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAA0B,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"comprehensive-engine.js","sourceRoot":"","sources":["../../src/inference/comprehensive-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAOL,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,sBAAsB,EAA0B,MAAM,6BAA6B,CAAC;AAE7F,OAAO,EAAE,4BAA4B,EAA8B,MAAM,sCAAsC,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAkB5D,MAAM,OAAO,4BAA4B;IAC/B,aAAa,CAAyB;IACtC,mBAAmB,CAA+B;IAClD,UAAU,CAAa;IACvB,cAAc,CAA0B;IACxC,MAAM,CAAwB;IAC9B,KAAK,CAAU;IAEvB,YACE,SAAyC,EAAE,EAC3C,QAAiB,KAAK;QAEtB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,qBAAqB,EAAE,GAAG,MAAM,EAAE,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC;QAE7D,qBAAqB;QACrB,IAAI,CAAC,aAAa,GAAG,IAAI,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC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S,EAAE,eAAe,CAAC,SAAS,CAAC,MAAM;oBAC3C,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,MAAM;oBACzC,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,MAAM;iBAC1C;aACF;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -3,15 +3,39 @@
|
|
|
3
3
|
* Provides pattern matching and rule application for both logical and deployment inference
|
|
4
4
|
*/
|
|
5
5
|
import { InferenceRule, InferenceContext, ValidationResult } from './types.js';
|
|
6
|
+
export interface RuleEngineStatistics {
|
|
7
|
+
rulesLoaded: number;
|
|
8
|
+
conditionsCompiled: number;
|
|
9
|
+
conditionCacheSize: number;
|
|
10
|
+
conditionCacheHits: number;
|
|
11
|
+
conditionCacheMisses: number;
|
|
12
|
+
/** Share of evaluations served from cache (0..1). */
|
|
13
|
+
conditionCacheHitRate: number;
|
|
14
|
+
templateContextHits: number;
|
|
15
|
+
templateContextMisses: number;
|
|
16
|
+
}
|
|
6
17
|
export declare class RuleEngine<TInput, TOutput> {
|
|
7
18
|
private debug;
|
|
8
19
|
private rules;
|
|
9
20
|
private conditionCache;
|
|
21
|
+
private compiledConditions;
|
|
22
|
+
private lastTemplateContext;
|
|
23
|
+
private stats;
|
|
10
24
|
constructor(debug?: boolean);
|
|
11
25
|
/**
|
|
12
26
|
* Load rules for a specific category (e.g., 'controllers', 'services')
|
|
13
27
|
*/
|
|
14
28
|
loadRules(category: string, rules: InferenceRule<TInput, TOutput>[]): ValidationResult;
|
|
29
|
+
/**
|
|
30
|
+
* Compile a condition expression to a reusable function. Called once per
|
|
31
|
+
* rule at load time (or from the validator, which exercises the parse).
|
|
32
|
+
*/
|
|
33
|
+
private compileCondition;
|
|
34
|
+
/**
|
|
35
|
+
* Return cache + compilation statistics. Useful for measuring the impact
|
|
36
|
+
* of the condition cache and spotting cache-defeating call patterns.
|
|
37
|
+
*/
|
|
38
|
+
getStatistics(): RuleEngineStatistics;
|
|
15
39
|
/**
|
|
16
40
|
* Find all matching rules for input in a category
|
|
17
41
|
*/
|
|
@@ -30,6 +54,13 @@ export declare class RuleEngine<TInput, TOutput> {
|
|
|
30
54
|
clearRules(): void;
|
|
31
55
|
private validateRule;
|
|
32
56
|
private evaluateCondition;
|
|
57
|
+
/**
|
|
58
|
+
* Compact cache key describing only what the condition can observe. Two
|
|
59
|
+
* invocations with the same rule + model + relationship topology + lifecycle
|
|
60
|
+
* presence produce identical keys — unlike the old JSON.stringify-based
|
|
61
|
+
* key, which was instance-specific.
|
|
62
|
+
*/
|
|
63
|
+
private buildConditionCacheKey;
|
|
33
64
|
private buildTemplateContext;
|
|
34
65
|
private applyHandlebarsTemplate;
|
|
35
66
|
private applyJsonTemplate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-engine.d.ts","sourceRoot":"","sources":["../../../src/inference/core/rule-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"rule-engine.d.ts","sourceRoot":"","sources":["../../../src/inference/core/rule-engine.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAqBpB,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qDAAqD;IACrD,qBAAqB,EAAE,MAAM,CAAC;IAC9B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,qBAAa,UAAU,CAAC,MAAM,EAAE,OAAO;IAmBzB,OAAO,CAAC,KAAK;IAlBzB,OAAO,CAAC,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AO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,6BAA6B;IAsBrC,OAAO,CAAC,mBAAmB;IAuD3B,OAAO,CAAC,8BAA8B;IA6EtC,OAAO,CAAC,4BAA4B;IAmFpC,OAAO,CAAC,+BAA+B;IAoGvC,OAAO,CAAC,8BAA8B;CAmHvC"}
|
|
@@ -7,6 +7,19 @@ export class RuleEngine {
|
|
|
7
7
|
debug;
|
|
8
8
|
rules = new Map();
|
|
9
9
|
conditionCache = new Map();
|
|
10
|
+
compiledConditions = new WeakMap();
|
|
11
|
+
// Single-entry memoization for the template context. Generators call
|
|
12
|
+
// apply() in a for-loop over matching rules with the same (input, context)
|
|
13
|
+
// pair. Before this cache, buildTemplateContext rebuilt identical helper
|
|
14
|
+
// closures on every iteration.
|
|
15
|
+
lastTemplateContext = null;
|
|
16
|
+
stats = {
|
|
17
|
+
conditionsCompiled: 0,
|
|
18
|
+
conditionCacheHits: 0,
|
|
19
|
+
conditionCacheMisses: 0,
|
|
20
|
+
templateContextHits: 0,
|
|
21
|
+
templateContextMisses: 0,
|
|
22
|
+
};
|
|
10
23
|
constructor(debug = false) {
|
|
11
24
|
this.debug = debug;
|
|
12
25
|
}
|
|
@@ -32,6 +45,15 @@ export class RuleEngine {
|
|
|
32
45
|
// Sort rules by priority (highest first)
|
|
33
46
|
const sortedRules = [...rules].sort((a, b) => b.priority - a.priority);
|
|
34
47
|
this.rules.set(category, sortedRules);
|
|
48
|
+
// Compile each rule's condition once at load time. Subsequent
|
|
49
|
+
// evaluations reuse the compiled function. Without this, every
|
|
50
|
+
// evaluateCondition() call re-parsed the expression via new Function().
|
|
51
|
+
for (const rule of sortedRules) {
|
|
52
|
+
if (rule.condition && !this.compiledConditions.has(rule)) {
|
|
53
|
+
this.compiledConditions.set(rule, this.compileCondition(rule.condition));
|
|
54
|
+
this.stats.conditionsCompiled++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
35
57
|
if (this.debug) {
|
|
36
58
|
console.log(`Loaded ${rules.length} rules for category: ${category}`);
|
|
37
59
|
console.log(`Rule priorities: ${sortedRules.map(r => `${r.name}:${r.priority}`).join(', ')}`);
|
|
@@ -39,6 +61,31 @@ export class RuleEngine {
|
|
|
39
61
|
}
|
|
40
62
|
return validation;
|
|
41
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Compile a condition expression to a reusable function. Called once per
|
|
66
|
+
* rule at load time (or from the validator, which exercises the parse).
|
|
67
|
+
*/
|
|
68
|
+
compileCondition(condition) {
|
|
69
|
+
return new Function('input', 'context', 'model', 'relationships', 'hasParentRelationship', 'hasChildRelationships', 'hasLifecycle', 'belongsTo', 'hasMany', `return ${condition}`);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Return cache + compilation statistics. Useful for measuring the impact
|
|
73
|
+
* of the condition cache and spotting cache-defeating call patterns.
|
|
74
|
+
*/
|
|
75
|
+
getStatistics() {
|
|
76
|
+
const rulesLoaded = Array.from(this.rules.values()).reduce((sum, rs) => sum + rs.length, 0);
|
|
77
|
+
const total = this.stats.conditionCacheHits + this.stats.conditionCacheMisses;
|
|
78
|
+
return {
|
|
79
|
+
rulesLoaded,
|
|
80
|
+
conditionsCompiled: this.stats.conditionsCompiled,
|
|
81
|
+
conditionCacheSize: this.conditionCache.size,
|
|
82
|
+
conditionCacheHits: this.stats.conditionCacheHits,
|
|
83
|
+
conditionCacheMisses: this.stats.conditionCacheMisses,
|
|
84
|
+
conditionCacheHitRate: total === 0 ? 0 : this.stats.conditionCacheHits / total,
|
|
85
|
+
templateContextHits: this.stats.templateContextHits,
|
|
86
|
+
templateContextMisses: this.stats.templateContextMisses,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
42
89
|
/**
|
|
43
90
|
* Find all matching rules for input in a category
|
|
44
91
|
*/
|
|
@@ -60,8 +107,22 @@ export class RuleEngine {
|
|
|
60
107
|
*/
|
|
61
108
|
apply(rule, input, context) {
|
|
62
109
|
try {
|
|
63
|
-
//
|
|
64
|
-
|
|
110
|
+
// Template context is expensive to build (closures for humanize,
|
|
111
|
+
// pluralize, etc.). Generators call apply() in a loop over all
|
|
112
|
+
// matching rules with the same (input, context) pair — reuse the
|
|
113
|
+
// last built context when the references match.
|
|
114
|
+
let templateContext;
|
|
115
|
+
if (this.lastTemplateContext &&
|
|
116
|
+
this.lastTemplateContext.input === input &&
|
|
117
|
+
this.lastTemplateContext.context === context) {
|
|
118
|
+
templateContext = this.lastTemplateContext.built;
|
|
119
|
+
this.stats.templateContextHits++;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
templateContext = this.buildTemplateContext(input, context);
|
|
123
|
+
this.lastTemplateContext = { input, context, built: templateContext };
|
|
124
|
+
this.stats.templateContextMisses++;
|
|
125
|
+
}
|
|
65
126
|
// Apply template based on type
|
|
66
127
|
switch (rule.template.type) {
|
|
67
128
|
case 'handlebars':
|
|
@@ -92,6 +153,16 @@ export class RuleEngine {
|
|
|
92
153
|
clearRules() {
|
|
93
154
|
this.rules.clear();
|
|
94
155
|
this.conditionCache.clear();
|
|
156
|
+
// compiledConditions is a WeakMap; entries are released once the rule
|
|
157
|
+
// objects themselves become unreachable.
|
|
158
|
+
this.lastTemplateContext = null;
|
|
159
|
+
this.stats = {
|
|
160
|
+
conditionsCompiled: 0,
|
|
161
|
+
conditionCacheHits: 0,
|
|
162
|
+
conditionCacheMisses: 0,
|
|
163
|
+
templateContextHits: 0,
|
|
164
|
+
templateContextMisses: 0,
|
|
165
|
+
};
|
|
95
166
|
}
|
|
96
167
|
// ===============================
|
|
97
168
|
// Private Implementation
|
|
@@ -177,39 +248,35 @@ export class RuleEngine {
|
|
|
177
248
|
if (!rule.condition) {
|
|
178
249
|
return true; // No condition means always matches
|
|
179
250
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
251
|
+
// Cache key is the rule name + a compact signature of the shape the
|
|
252
|
+
// condition can observe (current model name + relationship topology +
|
|
253
|
+
// lifecycle presence). The previous key serialized the entire input
|
|
254
|
+
// and context via JSON.stringify per call, which is both expensive
|
|
255
|
+
// and instance-specific — so identical-shaped inputs kept missing.
|
|
256
|
+
const cacheKey = this.buildConditionCacheKey(rule, input, context);
|
|
257
|
+
const cached = this.conditionCache.get(cacheKey);
|
|
258
|
+
if (cached !== undefined) {
|
|
259
|
+
this.stats.conditionCacheHits++;
|
|
260
|
+
return cached;
|
|
261
|
+
}
|
|
262
|
+
this.stats.conditionCacheMisses++;
|
|
263
|
+
let conditionFn = this.compiledConditions.get(rule);
|
|
264
|
+
if (!conditionFn) {
|
|
265
|
+
// Rule didn't go through loadRules() (direct test use, etc.) — compile
|
|
266
|
+
// lazily so behaviour matches the normal path.
|
|
267
|
+
conditionFn = this.compileCondition(rule.condition);
|
|
268
|
+
this.compiledConditions.set(rule, conditionFn);
|
|
269
|
+
this.stats.conditionsCompiled++;
|
|
183
270
|
}
|
|
184
271
|
try {
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return (context.relationships?.parentRelationships?.length || 0) > 0;
|
|
194
|
-
},
|
|
195
|
-
hasChildRelationships: () => {
|
|
196
|
-
return (context.relationships?.childRelationships?.length || 0) > 0;
|
|
197
|
-
},
|
|
198
|
-
hasLifecycle: () => {
|
|
199
|
-
return context.currentModel?.lifecycle !== undefined;
|
|
200
|
-
},
|
|
201
|
-
belongsTo: (targetModel) => {
|
|
202
|
-
return context.relationships?.parentRelationships?.some(r => r.targetModel === targetModel) || false;
|
|
203
|
-
},
|
|
204
|
-
hasMany: (targetModel) => {
|
|
205
|
-
return context.relationships?.childRelationships?.some(r => r.name === targetModel) || false;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
// Evaluate condition safely
|
|
209
|
-
const conditionFunc = new Function('input', 'context', 'model', 'relationships', 'hasParentRelationship', 'hasChildRelationships', 'hasLifecycle', 'belongsTo', 'hasMany', `
|
|
210
|
-
return ${rule.condition}
|
|
211
|
-
`);
|
|
212
|
-
const result = conditionFunc(evalContext.input, evalContext.context, evalContext.model, evalContext.relationships, evalContext.hasParentRelationship, evalContext.hasChildRelationships, evalContext.hasLifecycle, evalContext.belongsTo, evalContext.hasMany);
|
|
272
|
+
const model = context.currentModel;
|
|
273
|
+
const relationships = context.relationships;
|
|
274
|
+
const hasParentRelationship = () => (relationships?.parentRelationships?.length || 0) > 0;
|
|
275
|
+
const hasChildRelationships = () => (relationships?.childRelationships?.length || 0) > 0;
|
|
276
|
+
const hasLifecycle = () => model?.lifecycle !== undefined;
|
|
277
|
+
const belongsTo = (targetModel) => relationships?.parentRelationships?.some(r => r.targetModel === targetModel) || false;
|
|
278
|
+
const hasMany = (targetModel) => relationships?.childRelationships?.some(r => r.name === targetModel) || false;
|
|
279
|
+
const result = conditionFn(input, context, model, relationships, hasParentRelationship, hasChildRelationships, hasLifecycle, belongsTo, hasMany);
|
|
213
280
|
this.conditionCache.set(cacheKey, result);
|
|
214
281
|
return result;
|
|
215
282
|
}
|
|
@@ -220,6 +287,23 @@ export class RuleEngine {
|
|
|
220
287
|
return false;
|
|
221
288
|
}
|
|
222
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Compact cache key describing only what the condition can observe. Two
|
|
292
|
+
* invocations with the same rule + model + relationship topology + lifecycle
|
|
293
|
+
* presence produce identical keys — unlike the old JSON.stringify-based
|
|
294
|
+
* key, which was instance-specific.
|
|
295
|
+
*/
|
|
296
|
+
buildConditionCacheKey(rule, input, context) {
|
|
297
|
+
const modelName = (context.currentModel?.name) ?? input?.name ?? '';
|
|
298
|
+
const rels = context.relationships;
|
|
299
|
+
const parentCount = rels?.parentRelationships?.length || 0;
|
|
300
|
+
const childCount = rels?.childRelationships?.length || 0;
|
|
301
|
+
const m2mCount = rels?.manyToManyRelationships?.length || 0;
|
|
302
|
+
const cascadeCount = rels?.cascadeDeleteTargets?.length || 0;
|
|
303
|
+
const lifecycle = context.currentModel?.lifecycle ? 'L' : '';
|
|
304
|
+
const profiles = (context.currentModel?.profiles?.length || 0);
|
|
305
|
+
return `${rule.name}|${modelName}|p${parentCount}|c${childCount}|m${m2mCount}|d${cascadeCount}|${lifecycle}|f${profiles}`;
|
|
306
|
+
}
|
|
223
307
|
buildTemplateContext(input, context) {
|
|
224
308
|
const model = context.currentModel;
|
|
225
309
|
const relationships = context.relationships;
|