@mmapp/react-compiler 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/compile-blueprint-chat.mjs +99 -0
- package/compile-blueprint-glass-console.mjs +98 -0
- package/compile-chat-defs.mjs +92 -0
- package/dist/babel/index.d.mts +3 -0
- package/dist/babel/index.d.ts +3 -0
- package/dist/babel/index.js +4851 -0
- package/dist/babel/index.mjs +7 -0
- package/dist/chunk-26U577GB.mjs +3465 -0
- package/dist/chunk-2FBDFAX6.mjs +2362 -0
- package/dist/chunk-2L4QSMXG.mjs +175 -0
- package/dist/chunk-2REDFOER.mjs +931 -0
- package/dist/chunk-46YKSHQR.mjs +175 -0
- package/dist/chunk-4XHK6FWL.mjs +2058 -0
- package/dist/chunk-5M7DKKBC.mjs +215 -0
- package/dist/chunk-5VNJ7C6N.mjs +154 -0
- package/dist/chunk-6CQOAAMV.mjs +1803 -0
- package/dist/chunk-6SEVAAVT.mjs +3516 -0
- package/dist/chunk-6YLR5ZDA.mjs +2829 -0
- package/dist/chunk-AOGY2GK6.mjs +3292 -0
- package/dist/chunk-AXXUXRNA.mjs +1434 -0
- package/dist/chunk-CHLVKMQW.mjs +175 -0
- package/dist/chunk-CKGOZAB7.mjs +939 -0
- package/dist/chunk-D34RAZUX.mjs +2223 -0
- package/dist/chunk-EQGA6A6D.mjs +121 -0
- package/dist/chunk-EY2CSXYA.mjs +822 -0
- package/dist/chunk-FIQ65CDR.mjs +925 -0
- package/dist/chunk-FOZXJFAR.mjs +186 -0
- package/dist/chunk-FX6URXWN.mjs +186 -0
- package/dist/chunk-G7SMOWOL.mjs +828 -0
- package/dist/chunk-GGB4G5YY.mjs +175 -0
- package/dist/chunk-HLRGCCIL.mjs +4839 -0
- package/dist/chunk-HOIUP6IF.mjs +690 -0
- package/dist/chunk-I3AU7GRD.mjs +120 -0
- package/dist/chunk-ILFGMUVD.mjs +1933 -0
- package/dist/chunk-IPTX5MJU.mjs +3223 -0
- package/dist/chunk-ITGUSH2Z.mjs +2783 -0
- package/dist/chunk-IXHBCAMF.mjs +3306 -0
- package/dist/chunk-J7TWJ3TM.mjs +2784 -0
- package/dist/chunk-JDPLDGVF.mjs +4810 -0
- package/dist/chunk-K53XP2DL.mjs +148 -0
- package/dist/chunk-K5HX2SVL.mjs +1902 -0
- package/dist/chunk-KFGYOOVS.mjs +214 -0
- package/dist/chunk-KFVVOS5N.mjs +925 -0
- package/dist/chunk-L2OZ4CDV.mjs +113 -0
- package/dist/chunk-MIZV3TAN.mjs +3293 -0
- package/dist/chunk-NKKLQE5V.mjs +148 -0
- package/dist/chunk-NOW23XFZ.mjs +186 -0
- package/dist/chunk-NRXQKQ74.mjs +148 -0
- package/dist/chunk-OWI6XWCD.mjs +3375 -0
- package/dist/chunk-PRUMNNDI.mjs +3192 -0
- package/dist/chunk-QTBD5B3F.mjs +148 -0
- package/dist/chunk-SKSDPPNT.mjs +3788 -0
- package/dist/chunk-SP2YUS33.mjs +186 -0
- package/dist/chunk-SU4E6E7B.mjs +3153 -0
- package/dist/chunk-SYUUKW5A.mjs +3379 -0
- package/dist/chunk-UL2XZEMA.mjs +3128 -0
- package/dist/chunk-XMWUHQVV.mjs +939 -0
- package/dist/chunk-XZNEDRGN.mjs +3876 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/chunk-YFS6JMYO.mjs +3342 -0
- package/dist/chunk-Z6AIQ4KL.mjs +113 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +11585 -0
- package/dist/cli/index.mjs +701 -0
- package/dist/codemod/cli.d.mts +1 -0
- package/dist/codemod/cli.d.ts +1 -0
- package/dist/codemod/cli.js +1104 -0
- package/dist/codemod/cli.mjs +157 -0
- package/dist/codemod/index.d.mts +148 -0
- package/dist/codemod/index.d.ts +148 -0
- package/dist/codemod/index.js +981 -0
- package/dist/codemod/index.mjs +25 -0
- package/dist/dev-server-Bs_sz2DG.d.mts +111 -0
- package/dist/dev-server-Bs_sz2DG.d.ts +111 -0
- package/dist/dev-server-CjoufJ-u.d.mts +109 -0
- package/dist/dev-server-CjoufJ-u.d.ts +109 -0
- package/dist/dev-server.d.mts +3 -0
- package/dist/dev-server.d.ts +3 -0
- package/dist/dev-server.js +7603 -0
- package/dist/dev-server.mjs +11 -0
- package/dist/envelope-DD7v0v6E.d.mts +265 -0
- package/dist/envelope-DD7v0v6E.d.ts +265 -0
- package/dist/envelope-vCVjrHlo.d.mts +265 -0
- package/dist/envelope-vCVjrHlo.d.ts +265 -0
- package/dist/envelope.d.mts +2 -0
- package/dist/envelope.d.ts +2 -0
- package/dist/envelope.js +5184 -0
- package/dist/envelope.mjs +9 -0
- package/dist/index-B5gSgvnd.d.mts +44 -0
- package/dist/index-B5gSgvnd.d.ts +44 -0
- package/dist/index-Bs0MnR54.d.mts +103 -0
- package/dist/index-Bs0MnR54.d.ts +103 -0
- package/dist/index-DR0nNc_f.d.mts +101 -0
- package/dist/index-DR0nNc_f.d.ts +101 -0
- package/dist/index-revho_gS.d.mts +104 -0
- package/dist/index-revho_gS.d.ts +104 -0
- package/dist/index.d.mts +1099 -0
- package/dist/index.d.ts +1099 -0
- package/dist/index.js +10162 -0
- package/dist/index.mjs +372 -0
- package/dist/init-IXEE2RCF.mjs +340 -0
- package/dist/project-compiler-EGJUTAJU.mjs +10 -0
- package/dist/project-compiler-VFR6CSDX.mjs +10 -0
- package/dist/project-decompiler-5GY2KSG4.mjs +7 -0
- package/dist/pull-A2QUHW4K.mjs +109 -0
- package/dist/pull-JBEQWVPE.mjs +109 -0
- package/dist/testing/index.d.mts +211 -0
- package/dist/testing/index.d.ts +211 -0
- package/dist/testing/index.js +5106 -0
- package/dist/testing/index.mjs +247 -0
- package/dist/vite/index.d.mts +59 -0
- package/dist/vite/index.d.ts +59 -0
- package/dist/vite/index.js +5023 -0
- package/dist/vite/index.mjs +8 -0
- package/examples/README.md +72 -0
- package/examples/authentication/main.workflow.tsx +139 -0
- package/examples/authentication/mm.config.ts +22 -0
- package/examples/authentication/models/auth.ts +45 -0
- package/examples/authentication/pages/LoginPage.tsx +79 -0
- package/examples/authentication/pages/SignupPage.tsx +87 -0
- package/examples/counter.workflow.tsx +65 -0
- package/examples/dashboard.workflow.tsx +419 -0
- package/examples/invoice-approval/actions/invoice.server.ts +72 -0
- package/examples/invoice-approval/main.workflow.tsx +168 -0
- package/examples/invoice-approval/mm.config.ts +18 -0
- package/examples/invoice-approval/models/invoice.ts +46 -0
- package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +175 -0
- package/examples/invoice-approval/pages/InvoiceFormPage.tsx +198 -0
- package/examples/invoice-approval/pages/InvoiceListPage.tsx +141 -0
- package/examples/todo-app.workflow.tsx +131 -0
- package/examples/uber-app/actions/matching.server.ts +177 -0
- package/examples/uber-app/actions/notifications.server.ts +176 -0
- package/examples/uber-app/actions/payments.server.ts +184 -0
- package/examples/uber-app/actions/pricing.server.ts +176 -0
- package/examples/uber-app/app/admin/analytics.tsx +102 -0
- package/examples/uber-app/app/admin/fleet.tsx +102 -0
- package/examples/uber-app/app/admin/surge-pricing.tsx +95 -0
- package/examples/uber-app/app/driver/dashboard.tsx +87 -0
- package/examples/uber-app/app/driver/earnings.tsx +101 -0
- package/examples/uber-app/app/driver/navigation.tsx +94 -0
- package/examples/uber-app/app/driver/ride-acceptance.tsx +103 -0
- package/examples/uber-app/app/rider/home.tsx +109 -0
- package/examples/uber-app/app/rider/payment-methods.tsx +134 -0
- package/examples/uber-app/app/rider/ride-history.tsx +90 -0
- package/examples/uber-app/app/rider/ride-tracking.tsx +108 -0
- package/examples/uber-app/components/DriverCard.tsx +176 -0
- package/examples/uber-app/components/MapView.tsx +216 -0
- package/examples/uber-app/components/RatingStars.tsx +227 -0
- package/examples/uber-app/components/RideCard.tsx +167 -0
- package/examples/uber-app/mm.config.ts +30 -0
- package/examples/uber-app/models/location.model.ts +70 -0
- package/examples/uber-app/models/payment.model.ts +87 -0
- package/examples/uber-app/models/rating.model.ts +54 -0
- package/examples/uber-app/models/ride.model.ts +118 -0
- package/examples/uber-app/models/user.model.ts +66 -0
- package/examples/uber-app/models/vehicle.model.ts +63 -0
- package/examples/uber-app/tests/payment.test.tsx +129 -0
- package/examples/uber-app/tests/ride-flow.test.tsx +123 -0
- package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +205 -0
- package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +227 -0
- package/examples/uber-app/workflows/payment-processing.workflow.tsx +223 -0
- package/examples/uber-app/workflows/ride-request.workflow.tsx +194 -0
- package/package.json +77 -0
- package/package.json.backup +86 -0
- package/scripts/decompile.ts +226 -0
- package/scripts/seed-auth.ts +267 -0
- package/scripts/seed-uber.ts +248 -0
- package/scripts/validate-uber.ts +119 -0
- package/seed-blueprint-chat.mjs +444 -0
- package/seed-blueprint-glass-console.mjs +445 -0
- package/seed-compiled.mjs +318 -0
- package/src/RoundTripValidator.ts +400 -0
- package/src/__tests__/atom-rendering-coverage.test.ts +680 -0
- package/src/__tests__/auth-module-compilation.test.ts +247 -0
- package/src/__tests__/auth-template-compilation.test.ts +589 -0
- package/src/__tests__/change-extractor.test.ts +142 -0
- package/src/__tests__/cli-pull.test.ts +73 -0
- package/src/__tests__/cli-test.test.ts +72 -0
- package/src/__tests__/component-extractor.test.ts +331 -0
- package/src/__tests__/context-extractor.test.ts +145 -0
- package/src/__tests__/decompiler.test.ts +718 -0
- package/src/__tests__/define-blueprint.test.ts +133 -0
- package/src/__tests__/definition-validator.test.ts +519 -0
- package/src/__tests__/during-extractor.test.ts +152 -0
- package/src/__tests__/effect-extractor.test.ts +107 -0
- package/src/__tests__/event-emission.test.ts +127 -0
- package/src/__tests__/examples.test.ts +236 -0
- package/src/__tests__/full-blueprint-coverage.test.ts +1221 -0
- package/src/__tests__/golden-suite.test.ts +403 -0
- package/src/__tests__/grammar-island-extractor.test.ts +289 -0
- package/src/__tests__/instance-key.test.ts +82 -0
- package/src/__tests__/ir-migration.test.ts +255 -0
- package/src/__tests__/lock-file.test.ts +117 -0
- package/src/__tests__/model-extractor.test.ts +195 -0
- package/src/__tests__/model-field-acl.test.ts +237 -0
- package/src/__tests__/model-hooks.test.ts +130 -0
- package/src/__tests__/model-ref-resolution.test.ts +268 -0
- package/src/__tests__/model-roundtrip.test.ts +502 -0
- package/src/__tests__/model-runtime.test.ts +112 -0
- package/src/__tests__/model-transitions.test.ts +183 -0
- package/src/__tests__/nrt-action-trace.test.ts +391 -0
- package/src/__tests__/pipeline-hardening.test.ts +413 -0
- package/src/__tests__/project-compiler.test.ts +546 -0
- package/src/__tests__/project-decompiler.test.ts +343 -0
- package/src/__tests__/query-compilation.test.ts +145 -0
- package/src/__tests__/round-trip/PLAN.md +158 -0
- package/src/__tests__/round-trip/README.md +52 -0
- package/src/__tests__/round-trip/RESULTS.md +86 -0
- package/src/__tests__/round-trip/fixtures/data-heavy/main.workflow.tsx +55 -0
- package/src/__tests__/round-trip/fixtures/data-heavy/mm.config.ts +11 -0
- package/src/__tests__/round-trip/fixtures/data-heavy/models/contact.ts +54 -0
- package/src/__tests__/round-trip/fixtures/full-workflow/main.workflow.tsx +79 -0
- package/src/__tests__/round-trip/fixtures/full-workflow/mm.config.ts +12 -0
- package/src/__tests__/round-trip/fixtures/full-workflow/models/order.ts +50 -0
- package/src/__tests__/round-trip/fixtures/simple-crud/main.workflow.tsx +25 -0
- package/src/__tests__/round-trip/fixtures/simple-crud/mm.config.ts +11 -0
- package/src/__tests__/round-trip/fixtures/simple-crud/models/task.ts +32 -0
- package/src/__tests__/round-trip/fixtures/view-heavy/main.workflow.tsx +79 -0
- package/src/__tests__/round-trip/fixtures/view-heavy/mm.config.ts +10 -0
- package/src/__tests__/round-trip/round-trip.test.ts +2598 -0
- package/src/__tests__/round-trip-ir.test.ts +300 -0
- package/src/__tests__/round-trip.test.ts +1212 -0
- package/src/__tests__/route-merging.test.ts +372 -0
- package/src/__tests__/router-composition.test.ts +489 -0
- package/src/__tests__/router-extractor.test.ts +176 -0
- package/src/__tests__/server-action-extractor.test.ts +128 -0
- package/src/__tests__/smart-type-inference.test.ts +365 -0
- package/src/__tests__/source-envelope.test.ts +284 -0
- package/src/__tests__/source-fidelity.test.ts +516 -0
- package/src/__tests__/state-extractor.test.ts +115 -0
- package/src/__tests__/strict-mode.test.ts +227 -0
- package/src/__tests__/transition-effect-extractor.test.ts +119 -0
- package/src/__tests__/transition-extractor.test.ts +68 -0
- package/src/__tests__/ts-to-expression.test.ts +462 -0
- package/src/__tests__/type-generator.test.ts +201 -0
- package/src/__tests__/uber-validation.test.ts +502 -0
- package/src/action-compiler.ts +361 -0
- package/src/babel/emitters/experience-transform.ts +199 -0
- package/src/babel/emitters/ir-to-tsx-emitter.ts +110 -0
- package/src/babel/emitters/pure-form-emitter.ts +1023 -0
- package/src/babel/emitters/runtime-glue-emitter.ts +39 -0
- package/src/babel/extractors/change-extractor.ts +199 -0
- package/src/babel/extractors/component-extractor.ts +907 -0
- package/src/babel/extractors/computed-extractor.ts +262 -0
- package/src/babel/extractors/context-extractor.ts +277 -0
- package/src/babel/extractors/during-extractor.ts +295 -0
- package/src/babel/extractors/effect-extractor.ts +340 -0
- package/src/babel/extractors/event-extractor.ts +235 -0
- package/src/babel/extractors/grammar-island-extractor.ts +302 -0
- package/src/babel/extractors/model-extractor.ts +1018 -0
- package/src/babel/extractors/router-extractor.ts +303 -0
- package/src/babel/extractors/server-action-extractor.ts +173 -0
- package/src/babel/extractors/server-action-hook-extractor.ts +72 -0
- package/src/babel/extractors/server-state-extractor.ts +88 -0
- package/src/babel/extractors/state-extractor.ts +214 -0
- package/src/babel/extractors/transition-effect-extractor.ts +176 -0
- package/src/babel/extractors/transition-extractor.ts +143 -0
- package/src/babel/index.ts +24 -0
- package/src/babel/transpilers/ts-to-expression.ts +674 -0
- package/src/babel/visitor.ts +807 -0
- package/src/cli/auth.ts +255 -0
- package/src/cli/build.ts +288 -0
- package/src/cli/deploy.ts +206 -0
- package/src/cli/index.ts +328 -0
- package/src/cli/init.ts +388 -0
- package/src/cli/installer.ts +261 -0
- package/src/cli/lock-file.ts +94 -0
- package/src/cli/mmrc.ts +22 -0
- package/src/cli/pull.ts +172 -0
- package/src/cli/registry-client.ts +175 -0
- package/src/cli/test.ts +397 -0
- package/src/cli/type-generator.ts +243 -0
- package/src/codemod/__tests__/forward.test.ts +239 -0
- package/src/codemod/__tests__/reverse.test.ts +145 -0
- package/src/codemod/__tests__/round-trip.test.ts +137 -0
- package/src/codemod/annotation.ts +97 -0
- package/src/codemod/classify.ts +197 -0
- package/src/codemod/cli.ts +207 -0
- package/src/codemod/control-flow.ts +409 -0
- package/src/codemod/forward.ts +244 -0
- package/src/codemod/import-manager.ts +171 -0
- package/src/codemod/index.ts +120 -0
- package/src/codemod/reverse.ts +197 -0
- package/src/codemod/rules.ts +174 -0
- package/src/codemod/state-transform.ts +126 -0
- package/src/decompiler/ast-builder.ts +538 -0
- package/src/decompiler/config-generator.ts +151 -0
- package/src/decompiler/index.ts +315 -0
- package/src/decompiler/project-decompiler.ts +1776 -0
- package/src/decompiler/project.ts +862 -0
- package/src/decompiler/split-strategy.ts +140 -0
- package/src/decompiler/state-emitter.ts +1053 -0
- package/src/decompiler/sx-emitter.ts +318 -0
- package/src/decompiler/workspace-hydrator.ts +189 -0
- package/src/dev-server.ts +238 -0
- package/src/envelope/fs-tree.ts +217 -0
- package/src/envelope/source-envelope.ts +264 -0
- package/src/envelope.ts +315 -0
- package/src/incremental-compiler.ts +401 -0
- package/src/index.ts +99 -0
- package/src/model-compiler.ts +277 -0
- package/src/project-compiler.ts +1629 -0
- package/src/route-extractor.ts +333 -0
- package/src/testing/index.ts +32 -0
- package/src/testing/snapshot.ts +252 -0
- package/src/testing/test-utils.ts +226 -0
- package/src/types.ts +68 -0
- package/src/vite/index.ts +288 -0
- package/test-compile.mjs +142 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +23 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
babelPlugin
|
|
3
|
+
} from "../chunk-HLRGCCIL.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__require
|
|
6
|
+
} from "../chunk-Y6FXYEAI.mjs";
|
|
7
|
+
|
|
8
|
+
// src/testing/test-utils.ts
|
|
9
|
+
import { transformSync } from "@babel/core";
|
|
10
|
+
function compileWorkflow(code, options = {}) {
|
|
11
|
+
const filename = options.filename ?? "test.workflow.tsx";
|
|
12
|
+
const mode = options.mode ?? "infer";
|
|
13
|
+
const result = transformSync(code, {
|
|
14
|
+
filename,
|
|
15
|
+
plugins: [[babelPlugin, { mode }]],
|
|
16
|
+
parserOpts: { plugins: ["typescript", "jsx"], attachComment: true }
|
|
17
|
+
});
|
|
18
|
+
const ir = result?.metadata?.mindmatrixIR;
|
|
19
|
+
if (!ir) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`compileWorkflow: no IR produced. Check that the source exports a component or model.
|
|
22
|
+
Source preview: ${code.trim().slice(0, 120)}...`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return ir;
|
|
26
|
+
}
|
|
27
|
+
function compileModel(code, options = {}) {
|
|
28
|
+
const filename = options.filename ?? "models/test.ts";
|
|
29
|
+
const mode = options.mode ?? "infer";
|
|
30
|
+
const result = transformSync(code, {
|
|
31
|
+
filename,
|
|
32
|
+
plugins: [[babelPlugin, { mode }]],
|
|
33
|
+
parserOpts: { plugins: ["typescript"], attachComment: true }
|
|
34
|
+
});
|
|
35
|
+
const ir = result?.metadata?.mindmatrixIR;
|
|
36
|
+
if (!ir) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`compileModel: no IR produced. Check that the source exports an interface and transitions.
|
|
39
|
+
Source preview: ${code.trim().slice(0, 120)}...`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return ir;
|
|
43
|
+
}
|
|
44
|
+
function compileServerAction(code, options = {}) {
|
|
45
|
+
const filename = options.filename ?? "actions.server.ts";
|
|
46
|
+
return compileWorkflow(code, { ...options, filename });
|
|
47
|
+
}
|
|
48
|
+
function compileRaw(code, options = {}) {
|
|
49
|
+
const filename = options.filename ?? "test.workflow.tsx";
|
|
50
|
+
const mode = options.mode ?? "infer";
|
|
51
|
+
const result = transformSync(code, {
|
|
52
|
+
filename,
|
|
53
|
+
plugins: [[babelPlugin, { mode }]],
|
|
54
|
+
parserOpts: { plugins: ["typescript", "jsx"], attachComment: true }
|
|
55
|
+
});
|
|
56
|
+
const metadata = result?.metadata ?? {};
|
|
57
|
+
return {
|
|
58
|
+
ir: metadata.mindmatrixIR,
|
|
59
|
+
code: result?.code ?? null,
|
|
60
|
+
warnings: metadata.mindmatrixWarnings ?? [],
|
|
61
|
+
errors: metadata.mindmatrixErrors ?? []
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function createMockBlueprintContext(props = {}) {
|
|
65
|
+
const {
|
|
66
|
+
slug = "test-blueprint",
|
|
67
|
+
version = "1.0.0",
|
|
68
|
+
initialState = {},
|
|
69
|
+
definitions = []
|
|
70
|
+
} = props;
|
|
71
|
+
return {
|
|
72
|
+
slug,
|
|
73
|
+
version,
|
|
74
|
+
definitions,
|
|
75
|
+
activeDefinition: definitions[0] ?? null,
|
|
76
|
+
instanceState: initialState,
|
|
77
|
+
dispatch: () => {
|
|
78
|
+
},
|
|
79
|
+
navigate: () => {
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function createMockWorkflowContext(props = {}) {
|
|
84
|
+
const {
|
|
85
|
+
slug = "test-workflow",
|
|
86
|
+
currentState = "draft",
|
|
87
|
+
fields = {},
|
|
88
|
+
transitions = [],
|
|
89
|
+
onTransition = () => {
|
|
90
|
+
}
|
|
91
|
+
} = props;
|
|
92
|
+
return {
|
|
93
|
+
slug,
|
|
94
|
+
currentState,
|
|
95
|
+
fields,
|
|
96
|
+
availableTransitions: transitions,
|
|
97
|
+
transition: onTransition,
|
|
98
|
+
setField: (name, value) => {
|
|
99
|
+
fields[name] = value;
|
|
100
|
+
},
|
|
101
|
+
getField: (name) => fields[name]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function extractFields(code, options) {
|
|
105
|
+
return compileWorkflow(code, options).fields;
|
|
106
|
+
}
|
|
107
|
+
function extractStates(code, options) {
|
|
108
|
+
return compileWorkflow(code, options).states;
|
|
109
|
+
}
|
|
110
|
+
function extractTransitions(code, options) {
|
|
111
|
+
return compileWorkflow(code, options).transitions;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/testing/snapshot.ts
|
|
115
|
+
function snapshotIR(code, options) {
|
|
116
|
+
const ir = options?.filename?.includes("models/") ? compileModel(code, options) : compileWorkflow(code, options);
|
|
117
|
+
return irToSnapshot(ir);
|
|
118
|
+
}
|
|
119
|
+
function irToSnapshot(ir) {
|
|
120
|
+
const meta = ir.metadata ?? {};
|
|
121
|
+
return {
|
|
122
|
+
slug: ir.slug ?? "",
|
|
123
|
+
version: ir.version ?? "",
|
|
124
|
+
category: Array.isArray(ir.category) ? ir.category[0] : ir.category ?? "workflow",
|
|
125
|
+
fields: ir.fields.map((f) => ({
|
|
126
|
+
name: f.name,
|
|
127
|
+
type: f.type,
|
|
128
|
+
...f.required === false ? { required: false } : {}
|
|
129
|
+
})),
|
|
130
|
+
states: ir.states.map((s) => ({
|
|
131
|
+
name: s.name,
|
|
132
|
+
type: s.type,
|
|
133
|
+
enterActions: s.on_enter?.length ?? 0,
|
|
134
|
+
exitActions: s.on_exit?.length ?? 0
|
|
135
|
+
})),
|
|
136
|
+
transitions: ir.transitions.map((t) => ({
|
|
137
|
+
name: t.name,
|
|
138
|
+
from: t.from,
|
|
139
|
+
to: t.to,
|
|
140
|
+
conditions: t.conditions?.length ?? 0
|
|
141
|
+
})),
|
|
142
|
+
hasExperience: !!meta.experience || !!ir.experience,
|
|
143
|
+
extensionTags: ir.extensions ? Object.keys(ir.extensions) : [],
|
|
144
|
+
dataSourceCount: Array.isArray(meta.dataSources) ? meta.dataSources.length : 0,
|
|
145
|
+
mutationTargetCount: Array.isArray(meta.mutationTargets) ? meta.mutationTargets.length : 0,
|
|
146
|
+
errorCount: Array.isArray(meta.errors) ? meta.errors.length : 0
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function installIRMatchers() {
|
|
150
|
+
try {
|
|
151
|
+
const { expect } = __require("vitest");
|
|
152
|
+
expect.extend({
|
|
153
|
+
toMatchIR(received, expected) {
|
|
154
|
+
const failures = [];
|
|
155
|
+
if (expected.slug !== void 0 && received.slug !== expected.slug) {
|
|
156
|
+
failures.push(`slug: expected "${expected.slug}", got "${received.slug}"`);
|
|
157
|
+
}
|
|
158
|
+
if (expected.version !== void 0 && received.version !== expected.version) {
|
|
159
|
+
failures.push(`version: expected "${expected.version}", got "${received.version}"`);
|
|
160
|
+
}
|
|
161
|
+
if (expected.category !== void 0 && received.category !== expected.category) {
|
|
162
|
+
failures.push(`category: expected "${expected.category}", got "${received.category}"`);
|
|
163
|
+
}
|
|
164
|
+
if (expected.description !== void 0 && received.description !== expected.description) {
|
|
165
|
+
failures.push(`description: expected "${expected.description}", got "${received.description}"`);
|
|
166
|
+
}
|
|
167
|
+
if (expected.fields !== void 0) {
|
|
168
|
+
const expectedFields = expected.fields;
|
|
169
|
+
for (const exp of expectedFields) {
|
|
170
|
+
const match = received.fields.find((f) => f.name === exp.name);
|
|
171
|
+
if (!match) {
|
|
172
|
+
failures.push(`fields: expected field "${exp.name}" not found`);
|
|
173
|
+
} else {
|
|
174
|
+
const matchRec = match;
|
|
175
|
+
for (const [key, val] of Object.entries(exp)) {
|
|
176
|
+
if (matchRec[key] !== val) {
|
|
177
|
+
failures.push(`fields.${exp.name}.${key}: expected ${JSON.stringify(val)}, got ${JSON.stringify(matchRec[key])}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (expected.states !== void 0 && Array.isArray(expected.states)) {
|
|
184
|
+
const expectedStates = expected.states;
|
|
185
|
+
for (const exp of expectedStates) {
|
|
186
|
+
const match = received.states.find((s) => s.name === exp.name);
|
|
187
|
+
if (!match) {
|
|
188
|
+
failures.push(`states: expected state "${exp.name}" not found`);
|
|
189
|
+
} else {
|
|
190
|
+
const matchRec = match;
|
|
191
|
+
for (const [key, val] of Object.entries(exp)) {
|
|
192
|
+
if (key === "on_enter" || key === "on_exit" || key === "during") {
|
|
193
|
+
const arr = matchRec[key];
|
|
194
|
+
if (typeof val === "number" && (arr?.length ?? 0) !== val) {
|
|
195
|
+
failures.push(`states.${exp.name}.${key}: expected length ${val}, got ${arr?.length ?? 0}`);
|
|
196
|
+
}
|
|
197
|
+
} else if (matchRec[key] !== val) {
|
|
198
|
+
failures.push(`states.${exp.name}.${key}: expected ${JSON.stringify(val)}, got ${JSON.stringify(matchRec[key])}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (expected.transitions !== void 0 && Array.isArray(expected.transitions)) {
|
|
205
|
+
const expectedTransitions = expected.transitions;
|
|
206
|
+
for (const exp of expectedTransitions) {
|
|
207
|
+
const match = received.transitions.find((t) => t.name === exp.name);
|
|
208
|
+
if (!match) {
|
|
209
|
+
failures.push(`transitions: expected transition "${exp.name}" not found`);
|
|
210
|
+
} else {
|
|
211
|
+
if (exp.from !== void 0) {
|
|
212
|
+
const fromMatch = JSON.stringify(match.from) === JSON.stringify(exp.from);
|
|
213
|
+
if (!fromMatch) {
|
|
214
|
+
failures.push(`transitions.${exp.name}.from: expected ${JSON.stringify(exp.from)}, got ${JSON.stringify(match.from)}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (exp.to !== void 0 && match.to !== exp.to) {
|
|
218
|
+
failures.push(`transitions.${exp.name}.to: expected "${exp.to}", got "${match.to}"`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const pass = failures.length === 0;
|
|
224
|
+
return {
|
|
225
|
+
pass,
|
|
226
|
+
message: () => pass ? `expected IR not to match, but it did` : `IR mismatch:
|
|
227
|
+
${failures.map((f) => ` - ${f}`).join("\n")}`
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
export {
|
|
235
|
+
compileModel,
|
|
236
|
+
compileRaw,
|
|
237
|
+
compileServerAction,
|
|
238
|
+
compileWorkflow,
|
|
239
|
+
createMockBlueprintContext,
|
|
240
|
+
createMockWorkflowContext,
|
|
241
|
+
extractFields,
|
|
242
|
+
extractStates,
|
|
243
|
+
extractTransitions,
|
|
244
|
+
installIRMatchers,
|
|
245
|
+
irToSnapshot,
|
|
246
|
+
snapshotIR
|
|
247
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite Plugin — integrates the MindMatrix Babel compiler into the Vite build pipeline.
|
|
5
|
+
*
|
|
6
|
+
* Transforms `.workflow.tsx` files through the Babel plugin to extract workflow
|
|
7
|
+
* IR (fields, states, transitions, experience tree) and emit:
|
|
8
|
+
* 1. Transformed React code (standard JSX, runs in browser)
|
|
9
|
+
* 2. `.workflow.json` sidecar files (IR for mm-engine consumption)
|
|
10
|
+
*
|
|
11
|
+
* Supports HMR: re-compiles on save, optionally seeds definitions to the dev API.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* // vite.config.ts
|
|
15
|
+
* import { mindmatrixReact } from '@mindmatrix/react-compiler/vite';
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* plugins: [
|
|
19
|
+
* mindmatrixReact({
|
|
20
|
+
* mode: 'infer',
|
|
21
|
+
* include: ['**\/*.workflow.tsx'],
|
|
22
|
+
* seedOnCompile: true,
|
|
23
|
+
* apiUrl: 'http://localhost:4200/api/v1',
|
|
24
|
+
* })
|
|
25
|
+
* ]
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface MindMatrixReactOptions {
|
|
30
|
+
/** Compilation mode: 'strict' validates imports, 'infer' is permissive. Default: 'infer' */
|
|
31
|
+
mode?: 'strict' | 'infer';
|
|
32
|
+
/** Glob patterns for files to compile. Default: ['**\/*.workflow.tsx'] */
|
|
33
|
+
include?: string[];
|
|
34
|
+
/** Output directory for .workflow.json sidecar files. Default: 'dist/workflows' */
|
|
35
|
+
outDir?: string;
|
|
36
|
+
/** When true, POST compiled definitions to the dev API on each compile. Default: false */
|
|
37
|
+
seedOnCompile?: boolean;
|
|
38
|
+
/** Dev API base URL for seeding. Default: 'http://localhost:4200/api/v1' */
|
|
39
|
+
apiUrl?: string;
|
|
40
|
+
/** Auth token for dev API seeding. Default: reads from MINDMATRIX_TOKEN env var */
|
|
41
|
+
authToken?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Source map configuration for .workflow.tsx files.
|
|
44
|
+
* - true: Generate source maps with original source embedded (default in dev)
|
|
45
|
+
* - false: No source maps
|
|
46
|
+
* - 'inline': Inline source maps in compiled output
|
|
47
|
+
* Default: auto-detected from Vite mode (true in dev, false in build)
|
|
48
|
+
*/
|
|
49
|
+
sourceMaps?: boolean | 'inline';
|
|
50
|
+
/**
|
|
51
|
+
* Embed __source metadata on IR nodes (file, line, column).
|
|
52
|
+
* Enables: compilation error mapping, IR inspector, runtime error traces.
|
|
53
|
+
* Default: true in dev, false in production.
|
|
54
|
+
*/
|
|
55
|
+
sourceAnnotations?: boolean;
|
|
56
|
+
}
|
|
57
|
+
declare function mindmatrixReact(options?: MindMatrixReactOptions): Plugin;
|
|
58
|
+
|
|
59
|
+
export { type MindMatrixReactOptions, mindmatrixReact };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vite Plugin — integrates the MindMatrix Babel compiler into the Vite build pipeline.
|
|
5
|
+
*
|
|
6
|
+
* Transforms `.workflow.tsx` files through the Babel plugin to extract workflow
|
|
7
|
+
* IR (fields, states, transitions, experience tree) and emit:
|
|
8
|
+
* 1. Transformed React code (standard JSX, runs in browser)
|
|
9
|
+
* 2. `.workflow.json` sidecar files (IR for mm-engine consumption)
|
|
10
|
+
*
|
|
11
|
+
* Supports HMR: re-compiles on save, optionally seeds definitions to the dev API.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* // vite.config.ts
|
|
15
|
+
* import { mindmatrixReact } from '@mindmatrix/react-compiler/vite';
|
|
16
|
+
*
|
|
17
|
+
* export default defineConfig({
|
|
18
|
+
* plugins: [
|
|
19
|
+
* mindmatrixReact({
|
|
20
|
+
* mode: 'infer',
|
|
21
|
+
* include: ['**\/*.workflow.tsx'],
|
|
22
|
+
* seedOnCompile: true,
|
|
23
|
+
* apiUrl: 'http://localhost:4200/api/v1',
|
|
24
|
+
* })
|
|
25
|
+
* ]
|
|
26
|
+
* });
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface MindMatrixReactOptions {
|
|
30
|
+
/** Compilation mode: 'strict' validates imports, 'infer' is permissive. Default: 'infer' */
|
|
31
|
+
mode?: 'strict' | 'infer';
|
|
32
|
+
/** Glob patterns for files to compile. Default: ['**\/*.workflow.tsx'] */
|
|
33
|
+
include?: string[];
|
|
34
|
+
/** Output directory for .workflow.json sidecar files. Default: 'dist/workflows' */
|
|
35
|
+
outDir?: string;
|
|
36
|
+
/** When true, POST compiled definitions to the dev API on each compile. Default: false */
|
|
37
|
+
seedOnCompile?: boolean;
|
|
38
|
+
/** Dev API base URL for seeding. Default: 'http://localhost:4200/api/v1' */
|
|
39
|
+
apiUrl?: string;
|
|
40
|
+
/** Auth token for dev API seeding. Default: reads from MINDMATRIX_TOKEN env var */
|
|
41
|
+
authToken?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Source map configuration for .workflow.tsx files.
|
|
44
|
+
* - true: Generate source maps with original source embedded (default in dev)
|
|
45
|
+
* - false: No source maps
|
|
46
|
+
* - 'inline': Inline source maps in compiled output
|
|
47
|
+
* Default: auto-detected from Vite mode (true in dev, false in build)
|
|
48
|
+
*/
|
|
49
|
+
sourceMaps?: boolean | 'inline';
|
|
50
|
+
/**
|
|
51
|
+
* Embed __source metadata on IR nodes (file, line, column).
|
|
52
|
+
* Enables: compilation error mapping, IR inspector, runtime error traces.
|
|
53
|
+
* Default: true in dev, false in production.
|
|
54
|
+
*/
|
|
55
|
+
sourceAnnotations?: boolean;
|
|
56
|
+
}
|
|
57
|
+
declare function mindmatrixReact(options?: MindMatrixReactOptions): Plugin;
|
|
58
|
+
|
|
59
|
+
export { type MindMatrixReactOptions, mindmatrixReact };
|