@mmapp/react-compiler 0.1.0-alpha.4 → 0.1.0-alpha.6
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/dist/babel/index.d.mts +2 -2
- package/dist/babel/index.d.ts +2 -2
- package/dist/babel/index.js +5 -5
- package/dist/babel/index.mjs +1 -1
- package/dist/cli/index.js +797 -1941
- package/dist/cli/index.mjs +179 -77
- package/dist/codemod/cli.js +1 -1
- package/dist/codemod/cli.mjs +1 -1
- package/dist/codemod/index.d.mts +3 -3
- package/dist/codemod/index.d.ts +3 -3
- package/dist/codemod/index.js +1 -1
- package/dist/codemod/index.mjs +1 -1
- package/dist/dev-server.d.mts +2 -2
- package/dist/dev-server.d.ts +2 -2
- package/dist/dev-server.js +86 -1218
- package/dist/dev-server.mjs +4 -4
- package/dist/envelope.d.mts +2 -2
- package/dist/envelope.d.ts +2 -2
- package/dist/envelope.js +5 -5
- package/dist/envelope.mjs +2 -2
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +342 -1266
- package/dist/index.mjs +8 -8
- package/dist/testing/index.d.mts +8 -8
- package/dist/testing/index.d.ts +8 -8
- package/dist/testing/index.js +5 -5
- package/dist/testing/index.mjs +1 -1
- package/dist/vite/index.d.mts +1 -1
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +5 -5
- package/dist/vite/index.mjs +2 -2
- package/examples/authentication/main.workflow.tsx +1 -1
- package/examples/authentication/mm.config.ts +1 -1
- package/examples/authentication/pages/LoginPage.tsx +2 -2
- package/examples/authentication/pages/SignupPage.tsx +2 -2
- package/examples/counter.workflow.tsx +1 -1
- package/examples/dashboard.workflow.tsx +1 -1
- package/examples/invoice-approval/actions/invoice.server.ts +1 -1
- package/examples/invoice-approval/main.workflow.tsx +1 -1
- package/examples/invoice-approval/mm.config.ts +1 -1
- package/examples/invoice-approval/pages/InvoiceDetailPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceFormPage.tsx +1 -1
- package/examples/invoice-approval/pages/InvoiceListPage.tsx +1 -1
- package/examples/todo-app.workflow.tsx +1 -1
- package/examples/uber-app/actions/matching.server.ts +1 -1
- package/examples/uber-app/actions/notifications.server.ts +1 -1
- package/examples/uber-app/actions/payments.server.ts +1 -1
- package/examples/uber-app/actions/pricing.server.ts +1 -1
- package/examples/uber-app/app/admin/analytics.tsx +2 -2
- package/examples/uber-app/app/admin/fleet.tsx +2 -2
- package/examples/uber-app/app/admin/surge-pricing.tsx +2 -2
- package/examples/uber-app/app/driver/dashboard.tsx +2 -2
- package/examples/uber-app/app/driver/earnings.tsx +2 -2
- package/examples/uber-app/app/driver/navigation.tsx +2 -2
- package/examples/uber-app/app/driver/ride-acceptance.tsx +2 -2
- package/examples/uber-app/app/rider/home.tsx +2 -2
- package/examples/uber-app/app/rider/payment-methods.tsx +2 -2
- package/examples/uber-app/app/rider/ride-history.tsx +2 -2
- package/examples/uber-app/app/rider/ride-tracking.tsx +2 -2
- package/examples/uber-app/components/DriverCard.tsx +1 -1
- package/examples/uber-app/components/MapView.tsx +3 -3
- package/examples/uber-app/components/RatingStars.tsx +2 -2
- package/examples/uber-app/components/RideCard.tsx +1 -1
- package/examples/uber-app/mm.config.ts +1 -1
- package/examples/uber-app/workflows/dispute-resolution.workflow.tsx +2 -2
- package/examples/uber-app/workflows/driver-onboarding.workflow.tsx +2 -2
- package/examples/uber-app/workflows/payment-processing.workflow.tsx +2 -2
- package/examples/uber-app/workflows/ride-request.workflow.tsx +2 -2
- package/package.json +13 -9
- package/dist/auth-3UK75242.mjs +0 -17
- package/dist/chunk-5FTDWKHH.mjs +0 -244
- package/dist/chunk-7JRAEFRB.mjs +0 -7510
- package/dist/chunk-7T6Q5KAA.mjs +0 -7506
- package/dist/chunk-ABYPKRSB.mjs +0 -215
- package/dist/chunk-BZEXUPDH.mjs +0 -175
- package/dist/chunk-HRYR54PT.mjs +0 -175
- package/dist/chunk-J3M4GUS7.mjs +0 -161
- package/dist/chunk-JRGFBWTN.mjs +0 -2918
- package/dist/chunk-O4AUS7EU.mjs +0 -148
- package/dist/chunk-R2DD5GTY.mjs +0 -186
- package/dist/chunk-UDDTWG5J.mjs +0 -734
- package/dist/chunk-VLTKQDJ3.mjs +0 -244
- package/dist/chunk-WVYY32LD.mjs +0 -939
- package/dist/chunk-XDVM4YHX.mjs +0 -3450
- package/dist/chunk-Z2G5RZ4H.mjs +0 -186
- package/dist/chunk-ZE3KCHBM.mjs +0 -2918
- package/dist/deploy-YAJGW6II.mjs +0 -9
- package/dist/dev-server-CrQ041KP.d.mts +0 -79
- package/dist/dev-server-CrQ041KP.d.ts +0 -79
- package/dist/envelope-ChEkuHij.d.mts +0 -265
- package/dist/envelope-ChEkuHij.d.ts +0 -265
- package/dist/index-CEKyyazf.d.mts +0 -104
- package/dist/index-CEKyyazf.d.ts +0 -104
- package/dist/init-7FJENUDK.mjs +0 -407
- package/dist/project-compiler-NNK32MPG.mjs +0 -10
- package/dist/project-compiler-ZB4RUYVL.mjs +0 -10
- package/dist/project-decompiler-U55HQUHW.mjs +0 -7
- package/dist/pull-KOL2QAYQ.mjs +0 -109
- package/dist/seed-KOGEPGOJ.mjs +0 -154
- package/dist/server-VW6UPCHO.mjs +0 -277
- package/dist/verify-BYHUKARQ.mjs +0 -1833
- package/dist/verify-OQDEQYMS.mjs +0 -1833
package/dist/chunk-ABYPKRSB.mjs
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
// src/cli/deploy.ts
|
|
2
|
-
import { glob } from "glob";
|
|
3
|
-
import { readFileSync, writeFileSync } from "fs";
|
|
4
|
-
import { basename } from "path";
|
|
5
|
-
async function deploy(options) {
|
|
6
|
-
const dir = options.dir ?? "dist/workflows";
|
|
7
|
-
const targetLabel = options.targetName ? ` (target: ${options.targetName})` : "";
|
|
8
|
-
console.log(`[mindmatrix-react] Deploying workflows from ${dir} to ${options.apiUrl}${targetLabel}...`);
|
|
9
|
-
const files = await glob(`${dir}/**/*.workflow.json`);
|
|
10
|
-
if (files.length === 0) {
|
|
11
|
-
console.log(`[mindmatrix-react] No workflow files found in ${dir}`);
|
|
12
|
-
return { created: [], updated: [], versioned: [], skipped: [], failed: [] };
|
|
13
|
-
}
|
|
14
|
-
const result = {
|
|
15
|
-
created: [],
|
|
16
|
-
updated: [],
|
|
17
|
-
versioned: [],
|
|
18
|
-
skipped: [],
|
|
19
|
-
failed: []
|
|
20
|
-
};
|
|
21
|
-
const deployedIRs = [];
|
|
22
|
-
for (const file of files) {
|
|
23
|
-
try {
|
|
24
|
-
const ir = JSON.parse(readFileSync(file, "utf-8"));
|
|
25
|
-
const slug = ir.slug;
|
|
26
|
-
if (options.dryRun) {
|
|
27
|
-
console.log(` [dry-run] Would deploy ${slug} (${basename(file)})`);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
const existing = await fetchExistingDefinition(options.apiUrl, options.token, slug);
|
|
31
|
-
if (!existing) {
|
|
32
|
-
await createDefinition(options.apiUrl, options.token, ir);
|
|
33
|
-
console.log(` \u2713 ${slug} (created)`);
|
|
34
|
-
result.created.push(slug);
|
|
35
|
-
} else if (existing.instanceCount === 0 || options.force) {
|
|
36
|
-
await updateDefinition(options.apiUrl, options.token, existing.id, ir);
|
|
37
|
-
console.log(` \u2713 ${slug} (updated)`);
|
|
38
|
-
result.updated.push(slug);
|
|
39
|
-
} else {
|
|
40
|
-
const newVersion = bumpVersion(existing.version);
|
|
41
|
-
ir.version = newVersion;
|
|
42
|
-
await createDefinition(options.apiUrl, options.token, ir);
|
|
43
|
-
console.log(` \u2713 ${slug} v${newVersion} (new version, ${existing.instanceCount} instances on v${existing.version})`);
|
|
44
|
-
result.versioned.push(slug);
|
|
45
|
-
}
|
|
46
|
-
deployedIRs.push(ir);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
const slug = basename(file).replace(".workflow.json", "");
|
|
49
|
-
const msg = error.message;
|
|
50
|
-
console.error(` \u2717 ${slug}: ${msg}`);
|
|
51
|
-
result.failed.push({ slug, error: msg });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (!options.dryRun) {
|
|
55
|
-
for (const ir of deployedIRs) {
|
|
56
|
-
const serviceResult = await syncServices(options.apiUrl, options.token, ir);
|
|
57
|
-
if (serviceResult) {
|
|
58
|
-
if (!result.services) {
|
|
59
|
-
result.services = { registered: [], updated: [], failed: [] };
|
|
60
|
-
}
|
|
61
|
-
result.services.registered.push(...serviceResult.registered);
|
|
62
|
-
result.services.updated.push(...serviceResult.updated);
|
|
63
|
-
result.services.failed.push(...serviceResult.failed);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (options.reportFile) {
|
|
68
|
-
writeFileSync(options.reportFile, JSON.stringify(result, null, 2), "utf-8");
|
|
69
|
-
console.log(`
|
|
70
|
-
Report written to ${options.reportFile}`);
|
|
71
|
-
}
|
|
72
|
-
const total = result.created.length + result.updated.length + result.versioned.length;
|
|
73
|
-
console.log(
|
|
74
|
-
`
|
|
75
|
-
[mindmatrix-react] Deployed ${total} workflows (${result.created.length} created, ${result.updated.length} updated, ${result.versioned.length} versioned, ${result.failed.length} failed)`
|
|
76
|
-
);
|
|
77
|
-
if (result.services) {
|
|
78
|
-
const svcTotal = result.services.registered.length + result.services.updated.length;
|
|
79
|
-
if (svcTotal > 0 || result.services.failed.length > 0) {
|
|
80
|
-
console.log(
|
|
81
|
-
`[mindmatrix-react] Synced ${svcTotal} services (${result.services.registered.length} registered, ${result.services.updated.length} updated, ${result.services.failed.length} failed)`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
async function fetchExistingDefinition(apiUrl, token, slug) {
|
|
88
|
-
try {
|
|
89
|
-
const res = await fetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, {
|
|
90
|
-
headers: { Authorization: `Bearer ${token}` }
|
|
91
|
-
});
|
|
92
|
-
if (!res.ok) return null;
|
|
93
|
-
const data = await res.json();
|
|
94
|
-
const definitions = Array.isArray(data) ? data : data.items ?? data.data;
|
|
95
|
-
if (!definitions || definitions.length === 0) return null;
|
|
96
|
-
const def = definitions[0];
|
|
97
|
-
return {
|
|
98
|
-
id: def.id,
|
|
99
|
-
slug: def.slug,
|
|
100
|
-
version: def.version || "0.1.0",
|
|
101
|
-
instanceCount: def.instanceCount ?? def.instance_count ?? 0
|
|
102
|
-
};
|
|
103
|
-
} catch {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function createDefinition(apiUrl, token, ir) {
|
|
108
|
-
const res = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
109
|
-
method: "POST",
|
|
110
|
-
headers: {
|
|
111
|
-
"Content-Type": "application/json",
|
|
112
|
-
Authorization: `Bearer ${token}`
|
|
113
|
-
},
|
|
114
|
-
body: JSON.stringify(ir)
|
|
115
|
-
});
|
|
116
|
-
if (!res.ok) {
|
|
117
|
-
const errorText = await res.text();
|
|
118
|
-
throw new Error(`Create failed: ${res.status} ${errorText}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async function updateDefinition(apiUrl, token, id, ir) {
|
|
122
|
-
const { slug: _slug, ...updatePayload } = ir;
|
|
123
|
-
const res = await fetch(`${apiUrl}/workflow/definitions/${id}`, {
|
|
124
|
-
method: "PATCH",
|
|
125
|
-
headers: {
|
|
126
|
-
"Content-Type": "application/json",
|
|
127
|
-
Authorization: `Bearer ${token}`
|
|
128
|
-
},
|
|
129
|
-
body: JSON.stringify(updatePayload)
|
|
130
|
-
});
|
|
131
|
-
if (!res.ok) {
|
|
132
|
-
const errorText = await res.text();
|
|
133
|
-
throw new Error(`Update failed: ${res.status} ${errorText}`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function bumpVersion(version) {
|
|
137
|
-
const parts = version.split(".");
|
|
138
|
-
if (parts.length !== 3) return `${version}.1`;
|
|
139
|
-
const patch = parseInt(parts[2], 10) || 0;
|
|
140
|
-
return `${parts[0]}.${parts[1]}.${patch + 1}`;
|
|
141
|
-
}
|
|
142
|
-
async function syncServices(apiUrl, token, ir) {
|
|
143
|
-
const metadata = ir.metadata;
|
|
144
|
-
const orchestration = metadata?.orchestration;
|
|
145
|
-
const services = orchestration?.services;
|
|
146
|
-
if (!services || Object.keys(services).length === 0) return null;
|
|
147
|
-
const result = { registered: [], updated: [], failed: [] };
|
|
148
|
-
for (const [name, config] of Object.entries(services)) {
|
|
149
|
-
try {
|
|
150
|
-
const registration = {
|
|
151
|
-
name,
|
|
152
|
-
connection: {
|
|
153
|
-
type: config.type || "webhook",
|
|
154
|
-
url: config.url,
|
|
155
|
-
queue: config.queue
|
|
156
|
-
},
|
|
157
|
-
actions: config.actions || [],
|
|
158
|
-
labels: config.labels || {}
|
|
159
|
-
};
|
|
160
|
-
const existing = await fetchExistingService(apiUrl, token, name);
|
|
161
|
-
if (existing) {
|
|
162
|
-
await fetch(`${apiUrl}/services/${existing.id}`, {
|
|
163
|
-
method: "PATCH",
|
|
164
|
-
headers: {
|
|
165
|
-
"Content-Type": "application/json",
|
|
166
|
-
Authorization: `Bearer ${token}`
|
|
167
|
-
},
|
|
168
|
-
body: JSON.stringify(registration)
|
|
169
|
-
});
|
|
170
|
-
console.log(` \u2713 service: ${name} (updated)`);
|
|
171
|
-
result.updated.push(name);
|
|
172
|
-
} else {
|
|
173
|
-
const res = await fetch(`${apiUrl}/services`, {
|
|
174
|
-
method: "POST",
|
|
175
|
-
headers: {
|
|
176
|
-
"Content-Type": "application/json",
|
|
177
|
-
Authorization: `Bearer ${token}`
|
|
178
|
-
},
|
|
179
|
-
body: JSON.stringify(registration)
|
|
180
|
-
});
|
|
181
|
-
if (!res.ok) {
|
|
182
|
-
const errorText = await res.text();
|
|
183
|
-
throw new Error(`Register failed: ${res.status} ${errorText}`);
|
|
184
|
-
}
|
|
185
|
-
console.log(` \u2713 service: ${name} (registered)`);
|
|
186
|
-
result.registered.push(name);
|
|
187
|
-
}
|
|
188
|
-
} catch (error) {
|
|
189
|
-
const msg = error.message;
|
|
190
|
-
console.error(` \u2717 service: ${name}: ${msg}`);
|
|
191
|
-
result.failed.push(name);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
async function fetchExistingService(apiUrl, token, name) {
|
|
197
|
-
try {
|
|
198
|
-
const res = await fetch(`${apiUrl}/services?name=${encodeURIComponent(name)}`, {
|
|
199
|
-
headers: { Authorization: `Bearer ${token}` }
|
|
200
|
-
});
|
|
201
|
-
if (!res.ok) return null;
|
|
202
|
-
const data = await res.json();
|
|
203
|
-
const servicesList = Array.isArray(data) ? data : data.services ?? data.items ?? data.data;
|
|
204
|
-
if (!servicesList || servicesList.length === 0) return null;
|
|
205
|
-
const found = servicesList.find((s) => s.name === name);
|
|
206
|
-
return found ? { id: found.id, name: found.name } : null;
|
|
207
|
-
} catch {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export {
|
|
213
|
-
deploy,
|
|
214
|
-
syncServices
|
|
215
|
-
};
|
package/dist/chunk-BZEXUPDH.mjs
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
babelPlugin
|
|
3
|
-
} from "./chunk-7T6Q5KAA.mjs";
|
|
4
|
-
|
|
5
|
-
// src/vite/index.ts
|
|
6
|
-
import { transformSync } from "@babel/core";
|
|
7
|
-
import { writeFileSync, mkdirSync } from "fs";
|
|
8
|
-
import { dirname, join, relative, basename } from "path";
|
|
9
|
-
function mindmatrixReact(options) {
|
|
10
|
-
const include = options?.include ?? ["**/*.workflow.tsx"];
|
|
11
|
-
const mode = options?.mode ?? "infer";
|
|
12
|
-
const outDir = options?.outDir ?? "dist/workflows";
|
|
13
|
-
const seedOnCompile = options?.seedOnCompile ?? false;
|
|
14
|
-
const apiUrl = options?.apiUrl ?? "http://localhost:4200/api/v1";
|
|
15
|
-
const authToken = options?.authToken ?? process.env.MINDMATRIX_TOKEN;
|
|
16
|
-
let enableSourceMaps = options?.sourceMaps;
|
|
17
|
-
let enableSourceAnnotations = options?.sourceAnnotations;
|
|
18
|
-
let isDev = true;
|
|
19
|
-
const compiledFiles = /* @__PURE__ */ new Map();
|
|
20
|
-
function shouldTransform(id) {
|
|
21
|
-
return include.some((pattern) => {
|
|
22
|
-
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
|
|
23
|
-
return new RegExp(regex).test(id);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
async function seedToApi(ir, filePath) {
|
|
27
|
-
if (!seedOnCompile || !authToken) return;
|
|
28
|
-
try {
|
|
29
|
-
const body = {
|
|
30
|
-
slug: ir.slug,
|
|
31
|
-
name: ir.name,
|
|
32
|
-
version: ir.version,
|
|
33
|
-
category: ir.category || "workflow",
|
|
34
|
-
fields: ir.fields || [],
|
|
35
|
-
states: ir.states || [],
|
|
36
|
-
transitions: ir.transitions || [],
|
|
37
|
-
experience: ir.experience || {},
|
|
38
|
-
metadata: {
|
|
39
|
-
...ir.metadata || {},
|
|
40
|
-
source_file: relative(process.cwd(), filePath),
|
|
41
|
-
compiled_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const resp = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
"Authorization": `Bearer ${authToken}`
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify(body)
|
|
51
|
-
});
|
|
52
|
-
if (resp.ok) {
|
|
53
|
-
console.log(`[mindmatrix-react] Seeded ${ir.slug} to ${apiUrl}`);
|
|
54
|
-
} else if (resp.status === 409) {
|
|
55
|
-
const existing = await fetch(
|
|
56
|
-
`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(ir.slug)}&version=${encodeURIComponent(ir.version)}`,
|
|
57
|
-
{ headers: { "Authorization": `Bearer ${authToken}` } }
|
|
58
|
-
);
|
|
59
|
-
if (existing.ok) {
|
|
60
|
-
const data = await existing.json();
|
|
61
|
-
const defId = Array.isArray(data) ? data[0]?.id : data?.id;
|
|
62
|
-
if (defId) {
|
|
63
|
-
await fetch(`${apiUrl}/workflow/definitions/${defId}`, {
|
|
64
|
-
method: "PATCH",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
"Authorization": `Bearer ${authToken}`
|
|
68
|
-
},
|
|
69
|
-
body: JSON.stringify(body)
|
|
70
|
-
});
|
|
71
|
-
console.log(`[mindmatrix-react] Updated ${ir.slug} (PATCH)`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
const text = await resp.text().catch(() => "");
|
|
76
|
-
console.warn(`[mindmatrix-react] Seed failed (${resp.status}): ${text.slice(0, 200)}`);
|
|
77
|
-
}
|
|
78
|
-
} catch (e) {
|
|
79
|
-
console.warn(`[mindmatrix-react] Seed failed:`, e instanceof Error ? e.message : e);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
name: "mindmatrix-react",
|
|
84
|
-
enforce: "pre",
|
|
85
|
-
configResolved(config) {
|
|
86
|
-
isDev = config.command === "serve";
|
|
87
|
-
if (enableSourceMaps === void 0) enableSourceMaps = isDev;
|
|
88
|
-
if (enableSourceAnnotations === void 0) enableSourceAnnotations = isDev;
|
|
89
|
-
},
|
|
90
|
-
transform(code, id) {
|
|
91
|
-
if (!shouldTransform(id)) return null;
|
|
92
|
-
try {
|
|
93
|
-
const wantMaps = enableSourceMaps !== false;
|
|
94
|
-
const result = transformSync(code, {
|
|
95
|
-
filename: id,
|
|
96
|
-
plugins: [[babelPlugin, { mode, filename: id, sourceAnnotations: enableSourceAnnotations }]],
|
|
97
|
-
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
98
|
-
sourceMaps: wantMaps,
|
|
99
|
-
// Embed original source in the source map so debuggers can show .workflow.tsx
|
|
100
|
-
...wantMaps ? { sourceFileName: basename(id) } : {}
|
|
101
|
-
});
|
|
102
|
-
if (!result?.code) return null;
|
|
103
|
-
const metadata = result.metadata || {};
|
|
104
|
-
const ir = metadata.mindmatrixIR;
|
|
105
|
-
const warnings = metadata.mindmatrixWarnings;
|
|
106
|
-
const errors = metadata.mindmatrixErrors;
|
|
107
|
-
if (warnings?.length) {
|
|
108
|
-
for (const w of warnings) {
|
|
109
|
-
console.warn(`[mindmatrix-react] ${basename(id)}: ${w.message}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (errors?.length) {
|
|
113
|
-
for (const e of errors) {
|
|
114
|
-
if (mode === "strict") {
|
|
115
|
-
this.error(`${basename(id)}: ${e.message}`);
|
|
116
|
-
} else {
|
|
117
|
-
this.warn(`${basename(id)}: ${e.message}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (ir) {
|
|
122
|
-
compiledFiles.set(id, ir);
|
|
123
|
-
const outputFileName = basename(id).replace(/\.tsx?$/, ".workflow.json");
|
|
124
|
-
const outputPath = join(process.cwd(), outDir, outputFileName);
|
|
125
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
126
|
-
writeFileSync(outputPath, JSON.stringify(ir, null, 2), "utf-8");
|
|
127
|
-
console.log(`[mindmatrix-react] Compiled ${basename(id)} \u2192 ${outputFileName}`);
|
|
128
|
-
seedToApi(ir, id);
|
|
129
|
-
}
|
|
130
|
-
if (!enableSourceAnnotations && ir) {
|
|
131
|
-
stripSourceAnnotations(ir);
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
code: result.code,
|
|
135
|
-
map: wantMaps ? result.map : void 0
|
|
136
|
-
};
|
|
137
|
-
} catch (error) {
|
|
138
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
139
|
-
if (mode === "strict") {
|
|
140
|
-
this.error(`Failed to compile ${basename(id)}: ${msg}`);
|
|
141
|
-
} else {
|
|
142
|
-
console.error(`[mindmatrix-react] Error compiling ${basename(id)}:`, msg);
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
handleHotUpdate(ctx) {
|
|
148
|
-
if (!shouldTransform(ctx.file)) return;
|
|
149
|
-
console.log(`[mindmatrix-react] HMR: ${basename(ctx.file)} changed`);
|
|
150
|
-
return void 0;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function stripSourceAnnotations(ir) {
|
|
155
|
-
const strip = (obj) => {
|
|
156
|
-
if (!obj || typeof obj !== "object") return;
|
|
157
|
-
if (Array.isArray(obj)) {
|
|
158
|
-
for (const item of obj) strip(item);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const rec = obj;
|
|
162
|
-
delete rec.__source;
|
|
163
|
-
for (const val of Object.values(rec)) {
|
|
164
|
-
if (val && typeof val === "object") strip(val);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
strip(ir.fields);
|
|
168
|
-
strip(ir.states);
|
|
169
|
-
strip(ir.transitions);
|
|
170
|
-
strip(ir.experience);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
mindmatrixReact
|
|
175
|
-
};
|
package/dist/chunk-HRYR54PT.mjs
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
babelPlugin
|
|
3
|
-
} from "./chunk-7JRAEFRB.mjs";
|
|
4
|
-
|
|
5
|
-
// src/vite/index.ts
|
|
6
|
-
import { transformSync } from "@babel/core";
|
|
7
|
-
import { writeFileSync, mkdirSync } from "fs";
|
|
8
|
-
import { dirname, join, relative, basename } from "path";
|
|
9
|
-
function mindmatrixReact(options) {
|
|
10
|
-
const include = options?.include ?? ["**/*.workflow.tsx"];
|
|
11
|
-
const mode = options?.mode ?? "infer";
|
|
12
|
-
const outDir = options?.outDir ?? "dist/workflows";
|
|
13
|
-
const seedOnCompile = options?.seedOnCompile ?? false;
|
|
14
|
-
const apiUrl = options?.apiUrl ?? "http://localhost:4200/api/v1";
|
|
15
|
-
const authToken = options?.authToken ?? process.env.MINDMATRIX_TOKEN;
|
|
16
|
-
let enableSourceMaps = options?.sourceMaps;
|
|
17
|
-
let enableSourceAnnotations = options?.sourceAnnotations;
|
|
18
|
-
let isDev = true;
|
|
19
|
-
const compiledFiles = /* @__PURE__ */ new Map();
|
|
20
|
-
function shouldTransform(id) {
|
|
21
|
-
return include.some((pattern) => {
|
|
22
|
-
const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<GLOBSTAR>>").replace(/\*/g, "[^/]*").replace(/<<GLOBSTAR>>/g, ".*").replace(/\?/g, ".");
|
|
23
|
-
return new RegExp(regex).test(id);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
async function seedToApi(ir, filePath) {
|
|
27
|
-
if (!seedOnCompile || !authToken) return;
|
|
28
|
-
try {
|
|
29
|
-
const body = {
|
|
30
|
-
slug: ir.slug,
|
|
31
|
-
name: ir.name,
|
|
32
|
-
version: ir.version,
|
|
33
|
-
category: ir.category || "workflow",
|
|
34
|
-
fields: ir.fields || [],
|
|
35
|
-
states: ir.states || [],
|
|
36
|
-
transitions: ir.transitions || [],
|
|
37
|
-
experience: ir.experience || {},
|
|
38
|
-
metadata: {
|
|
39
|
-
...ir.metadata || {},
|
|
40
|
-
source_file: relative(process.cwd(), filePath),
|
|
41
|
-
compiled_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const resp = await fetch(`${apiUrl}/workflow/definitions`, {
|
|
45
|
-
method: "POST",
|
|
46
|
-
headers: {
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
"Authorization": `Bearer ${authToken}`
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify(body)
|
|
51
|
-
});
|
|
52
|
-
if (resp.ok) {
|
|
53
|
-
console.log(`[mindmatrix-react] Seeded ${ir.slug} to ${apiUrl}`);
|
|
54
|
-
} else if (resp.status === 409) {
|
|
55
|
-
const existing = await fetch(
|
|
56
|
-
`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(ir.slug)}&version=${encodeURIComponent(ir.version)}`,
|
|
57
|
-
{ headers: { "Authorization": `Bearer ${authToken}` } }
|
|
58
|
-
);
|
|
59
|
-
if (existing.ok) {
|
|
60
|
-
const data = await existing.json();
|
|
61
|
-
const defId = Array.isArray(data) ? data[0]?.id : data?.id;
|
|
62
|
-
if (defId) {
|
|
63
|
-
await fetch(`${apiUrl}/workflow/definitions/${defId}`, {
|
|
64
|
-
method: "PATCH",
|
|
65
|
-
headers: {
|
|
66
|
-
"Content-Type": "application/json",
|
|
67
|
-
"Authorization": `Bearer ${authToken}`
|
|
68
|
-
},
|
|
69
|
-
body: JSON.stringify(body)
|
|
70
|
-
});
|
|
71
|
-
console.log(`[mindmatrix-react] Updated ${ir.slug} (PATCH)`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
const text = await resp.text().catch(() => "");
|
|
76
|
-
console.warn(`[mindmatrix-react] Seed failed (${resp.status}): ${text.slice(0, 200)}`);
|
|
77
|
-
}
|
|
78
|
-
} catch (e) {
|
|
79
|
-
console.warn(`[mindmatrix-react] Seed failed:`, e instanceof Error ? e.message : e);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
name: "mindmatrix-react",
|
|
84
|
-
enforce: "pre",
|
|
85
|
-
configResolved(config) {
|
|
86
|
-
isDev = config.command === "serve";
|
|
87
|
-
if (enableSourceMaps === void 0) enableSourceMaps = isDev;
|
|
88
|
-
if (enableSourceAnnotations === void 0) enableSourceAnnotations = isDev;
|
|
89
|
-
},
|
|
90
|
-
transform(code, id) {
|
|
91
|
-
if (!shouldTransform(id)) return null;
|
|
92
|
-
try {
|
|
93
|
-
const wantMaps = enableSourceMaps !== false;
|
|
94
|
-
const result = transformSync(code, {
|
|
95
|
-
filename: id,
|
|
96
|
-
plugins: [[babelPlugin, { mode, filename: id, sourceAnnotations: enableSourceAnnotations }]],
|
|
97
|
-
parserOpts: { plugins: ["jsx", "typescript"] },
|
|
98
|
-
sourceMaps: wantMaps,
|
|
99
|
-
// Embed original source in the source map so debuggers can show .workflow.tsx
|
|
100
|
-
...wantMaps ? { sourceFileName: basename(id) } : {}
|
|
101
|
-
});
|
|
102
|
-
if (!result?.code) return null;
|
|
103
|
-
const metadata = result.metadata || {};
|
|
104
|
-
const ir = metadata.mindmatrixIR;
|
|
105
|
-
const warnings = metadata.mindmatrixWarnings;
|
|
106
|
-
const errors = metadata.mindmatrixErrors;
|
|
107
|
-
if (warnings?.length) {
|
|
108
|
-
for (const w of warnings) {
|
|
109
|
-
console.warn(`[mindmatrix-react] ${basename(id)}: ${w.message}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (errors?.length) {
|
|
113
|
-
for (const e of errors) {
|
|
114
|
-
if (mode === "strict") {
|
|
115
|
-
this.error(`${basename(id)}: ${e.message}`);
|
|
116
|
-
} else {
|
|
117
|
-
this.warn(`${basename(id)}: ${e.message}`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (ir) {
|
|
122
|
-
compiledFiles.set(id, ir);
|
|
123
|
-
const outputFileName = basename(id).replace(/\.tsx?$/, ".workflow.json");
|
|
124
|
-
const outputPath = join(process.cwd(), outDir, outputFileName);
|
|
125
|
-
mkdirSync(dirname(outputPath), { recursive: true });
|
|
126
|
-
writeFileSync(outputPath, JSON.stringify(ir, null, 2), "utf-8");
|
|
127
|
-
console.log(`[mindmatrix-react] Compiled ${basename(id)} \u2192 ${outputFileName}`);
|
|
128
|
-
seedToApi(ir, id);
|
|
129
|
-
}
|
|
130
|
-
if (!enableSourceAnnotations && ir) {
|
|
131
|
-
stripSourceAnnotations(ir);
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
code: result.code,
|
|
135
|
-
map: wantMaps ? result.map : void 0
|
|
136
|
-
};
|
|
137
|
-
} catch (error) {
|
|
138
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
139
|
-
if (mode === "strict") {
|
|
140
|
-
this.error(`Failed to compile ${basename(id)}: ${msg}`);
|
|
141
|
-
} else {
|
|
142
|
-
console.error(`[mindmatrix-react] Error compiling ${basename(id)}:`, msg);
|
|
143
|
-
}
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
handleHotUpdate(ctx) {
|
|
148
|
-
if (!shouldTransform(ctx.file)) return;
|
|
149
|
-
console.log(`[mindmatrix-react] HMR: ${basename(ctx.file)} changed`);
|
|
150
|
-
return void 0;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
function stripSourceAnnotations(ir) {
|
|
155
|
-
const strip = (obj) => {
|
|
156
|
-
if (!obj || typeof obj !== "object") return;
|
|
157
|
-
if (Array.isArray(obj)) {
|
|
158
|
-
for (const item of obj) strip(item);
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const rec = obj;
|
|
162
|
-
delete rec.__source;
|
|
163
|
-
for (const val of Object.values(rec)) {
|
|
164
|
-
if (val && typeof val === "object") strip(val);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
strip(ir.fields);
|
|
168
|
-
strip(ir.states);
|
|
169
|
-
strip(ir.transitions);
|
|
170
|
-
strip(ir.experience);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
mindmatrixReact
|
|
175
|
-
};
|