@mmapp/react-compiler 0.1.0-alpha.19 → 0.1.0-alpha.20

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.
@@ -0,0 +1,213 @@
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/${encodeURIComponent(slug)}`, {
90
+ headers: { Authorization: `Bearer ${token}` }
91
+ });
92
+ if (!res.ok) return null;
93
+ const def = await res.json();
94
+ if (!def || !def.id) return null;
95
+ return {
96
+ id: def.id,
97
+ slug: def.slug,
98
+ version: def.version || "0.1.0",
99
+ instanceCount: def.instanceCount ?? def.instance_count ?? 0
100
+ };
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+ async function createDefinition(apiUrl, token, ir) {
106
+ const res = await fetch(`${apiUrl}/workflow/definitions`, {
107
+ method: "POST",
108
+ headers: {
109
+ "Content-Type": "application/json",
110
+ Authorization: `Bearer ${token}`
111
+ },
112
+ body: JSON.stringify({ ...ir, visibility: "PUBLIC" })
113
+ });
114
+ if (!res.ok) {
115
+ const errorText = await res.text();
116
+ throw new Error(`Create failed: ${res.status} ${errorText}`);
117
+ }
118
+ }
119
+ async function updateDefinition(apiUrl, token, id, ir) {
120
+ const { slug: _slug, ...updatePayload } = ir;
121
+ const res = await fetch(`${apiUrl}/workflow/definitions/${id}`, {
122
+ method: "PATCH",
123
+ headers: {
124
+ "Content-Type": "application/json",
125
+ Authorization: `Bearer ${token}`
126
+ },
127
+ body: JSON.stringify(updatePayload)
128
+ });
129
+ if (!res.ok) {
130
+ const errorText = await res.text();
131
+ throw new Error(`Update failed: ${res.status} ${errorText}`);
132
+ }
133
+ }
134
+ function bumpVersion(version) {
135
+ const parts = version.split(".");
136
+ if (parts.length !== 3) return `${version}.1`;
137
+ const patch = parseInt(parts[2], 10) || 0;
138
+ return `${parts[0]}.${parts[1]}.${patch + 1}`;
139
+ }
140
+ async function syncServices(apiUrl, token, ir) {
141
+ const metadata = ir.metadata;
142
+ const orchestration = metadata?.orchestration;
143
+ const services = orchestration?.services;
144
+ if (!services || Object.keys(services).length === 0) return null;
145
+ const result = { registered: [], updated: [], failed: [] };
146
+ for (const [name, config] of Object.entries(services)) {
147
+ try {
148
+ const registration = {
149
+ name,
150
+ connection: {
151
+ type: config.type || "webhook",
152
+ url: config.url,
153
+ queue: config.queue
154
+ },
155
+ actions: config.actions || [],
156
+ labels: config.labels || {}
157
+ };
158
+ const existing = await fetchExistingService(apiUrl, token, name);
159
+ if (existing) {
160
+ await fetch(`${apiUrl}/services/${existing.id}`, {
161
+ method: "PATCH",
162
+ headers: {
163
+ "Content-Type": "application/json",
164
+ Authorization: `Bearer ${token}`
165
+ },
166
+ body: JSON.stringify(registration)
167
+ });
168
+ console.log(` \u2713 service: ${name} (updated)`);
169
+ result.updated.push(name);
170
+ } else {
171
+ const res = await fetch(`${apiUrl}/services`, {
172
+ method: "POST",
173
+ headers: {
174
+ "Content-Type": "application/json",
175
+ Authorization: `Bearer ${token}`
176
+ },
177
+ body: JSON.stringify(registration)
178
+ });
179
+ if (!res.ok) {
180
+ const errorText = await res.text();
181
+ throw new Error(`Register failed: ${res.status} ${errorText}`);
182
+ }
183
+ console.log(` \u2713 service: ${name} (registered)`);
184
+ result.registered.push(name);
185
+ }
186
+ } catch (error) {
187
+ const msg = error.message;
188
+ console.error(` \u2717 service: ${name}: ${msg}`);
189
+ result.failed.push(name);
190
+ }
191
+ }
192
+ return result;
193
+ }
194
+ async function fetchExistingService(apiUrl, token, name) {
195
+ try {
196
+ const res = await fetch(`${apiUrl}/services?name=${encodeURIComponent(name)}`, {
197
+ headers: { Authorization: `Bearer ${token}` }
198
+ });
199
+ if (!res.ok) return null;
200
+ const data = await res.json();
201
+ const servicesList = Array.isArray(data) ? data : data.services ?? data.items ?? data.data;
202
+ if (!servicesList || servicesList.length === 0) return null;
203
+ const found = servicesList.find((s) => s.name === name);
204
+ return found ? { id: found.id, name: found.name } : null;
205
+ } catch {
206
+ return null;
207
+ }
208
+ }
209
+
210
+ export {
211
+ deploy,
212
+ syncServices
213
+ };
package/dist/cli/index.js CHANGED
@@ -13253,7 +13253,7 @@ function generatePageFileFromSection(page, modelSlugToPath) {
13253
13253
  slug: page.slug,
13254
13254
  name: page.componentName,
13255
13255
  version: "1.0.0",
13256
- category: ["page"],
13256
+ category: ["view"],
13257
13257
  states: [],
13258
13258
  transitions: [],
13259
13259
  fields,
@@ -14089,14 +14089,12 @@ async function deploy(options) {
14089
14089
  }
14090
14090
  async function fetchExistingDefinition(apiUrl, token, slug) {
14091
14091
  try {
14092
- const res = await fetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, {
14092
+ const res = await fetch(`${apiUrl}/workflow/definitions/${encodeURIComponent(slug)}`, {
14093
14093
  headers: { Authorization: `Bearer ${token}` }
14094
14094
  });
14095
14095
  if (!res.ok) return null;
14096
- const data = await res.json();
14097
- const definitions = Array.isArray(data) ? data : data.items ?? data.data;
14098
- if (!definitions || definitions.length === 0) return null;
14099
- const def = definitions[0];
14096
+ const def = await res.json();
14097
+ if (!def || !def.id) return null;
14100
14098
  return {
14101
14099
  id: def.id,
14102
14100
  slug: def.slug,
@@ -14114,7 +14112,7 @@ async function createDefinition(apiUrl, token, ir) {
14114
14112
  "Content-Type": "application/json",
14115
14113
  Authorization: `Bearer ${token}`
14116
14114
  },
14117
- body: JSON.stringify(ir)
14115
+ body: JSON.stringify({ ...ir, visibility: "PUBLIC" })
14118
14116
  });
14119
14117
  if (!res.ok) {
14120
14118
  const errorText = await res.text();
@@ -15567,7 +15565,13 @@ function App() {
15567
15565
  try {
15568
15566
  const res = await fetch(API_BASE + '/workflow/definitions');
15569
15567
  const json = await res.json();
15570
- const items = json.items || json.data || [];
15568
+ const rawItems = json.items || json.data || [];
15569
+ // Flatten: API returns { id, slug, definition: { experience, ... } }
15570
+ // Merge definition fields up to the top level for easier access
15571
+ const items = rawItems.map(d => {
15572
+ const def = d.definition || {};
15573
+ return { ...d, ...def, definition: undefined };
15574
+ });
15571
15575
  // Find the main blueprint definition (has experience tree)
15572
15576
  const main = items.find(d => d.experience && !(Array.isArray(d.category) ? d.category.includes('data') : d.category === 'data')) || items.find(d => d.experience) || items[0];
15573
15577
  if (main?.experience) {
@@ -16213,7 +16217,7 @@ function generatePage(name) {
16213
16217
  const title = toTitleCase(name);
16214
16218
  const pascal = toPascalCase2(name);
16215
16219
  return `/**
16216
- * @workflow slug="${name}-home" version="1.0.0" category="page"
16220
+ * @workflow slug="${name}-home" version="1.0.0" category="view"
16217
16221
  *
16218
16222
  * Index page \u2014 full CRUD with create form, search, transitions, and delete.
16219
16223
  */
@@ -7,7 +7,7 @@ import {
7
7
  } from "../chunk-J3M4GUS7.mjs";
8
8
  import {
9
9
  deploy
10
- } from "../chunk-ABYPKRSB.mjs";
10
+ } from "../chunk-XUQ5R6F3.mjs";
11
11
  import {
12
12
  build
13
13
  } from "../chunk-TRR2NPAV.mjs";
@@ -46,7 +46,7 @@ async function test(options = {}) {
46
46
  fileMap[rel] = readFileSync(f, "utf-8");
47
47
  }
48
48
  const { compileProject } = await import("../project-compiler-D245L5QR.mjs");
49
- const { decompileProjectEnhanced } = await import("../project-decompiler-7I2OMUVY.mjs");
49
+ const { decompileProjectEnhanced } = await import("../project-decompiler-QCZYY4TW.mjs");
50
50
  process.stdout.write(` Compiling project...`);
51
51
  const t0 = performance.now();
52
52
  let ir1;
@@ -611,7 +611,7 @@ async function main() {
611
611
  console.error('[mmrc] Error: name is required\n Usage: mmrc init <name> [--description "..."] [--icon "..."] [--author "..."]');
612
612
  process.exit(1);
613
613
  }
614
- const { init } = await import("../init-K3GVM4JS.mjs");
614
+ const { init } = await import("../init-AVZJHZYY.mjs");
615
615
  await init({
616
616
  name,
617
617
  description: getFlag("--description"),
@@ -651,7 +651,7 @@ async function main() {
651
651
  console.error(" 3. Set MMRC_TOKEN environment variable");
652
652
  process.exit(1);
653
653
  }
654
- const { pull } = await import("../pull-65GUSX6F.mjs");
654
+ const { pull } = await import("../pull-5WJ4LW4U.mjs");
655
655
  await pull({ slug, apiUrl, token, outDir });
656
656
  } else if (command === "seed") {
657
657
  const apiUrl = getFlag("--api-url") ?? "http://localhost:4200/api/v1";
@@ -0,0 +1,9 @@
1
+ import {
2
+ deploy,
3
+ syncServices
4
+ } from "./chunk-XUQ5R6F3.mjs";
5
+ import "./chunk-CIESM3BP.mjs";
6
+ export {
7
+ deploy,
8
+ syncServices
9
+ };
@@ -10849,14 +10849,12 @@ async function deploy(options) {
10849
10849
  }
10850
10850
  async function fetchExistingDefinition(apiUrl, token, slug) {
10851
10851
  try {
10852
- const res = await fetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, {
10852
+ const res = await fetch(`${apiUrl}/workflow/definitions/${encodeURIComponent(slug)}`, {
10853
10853
  headers: { Authorization: `Bearer ${token}` }
10854
10854
  });
10855
10855
  if (!res.ok) return null;
10856
- const data = await res.json();
10857
- const definitions = Array.isArray(data) ? data : data.items ?? data.data;
10858
- if (!definitions || definitions.length === 0) return null;
10859
- const def = definitions[0];
10856
+ const def = await res.json();
10857
+ if (!def || !def.id) return null;
10860
10858
  return {
10861
10859
  id: def.id,
10862
10860
  slug: def.slug,
@@ -10874,7 +10872,7 @@ async function createDefinition(apiUrl, token, ir) {
10874
10872
  "Content-Type": "application/json",
10875
10873
  Authorization: `Bearer ${token}`
10876
10874
  },
10877
- body: JSON.stringify(ir)
10875
+ body: JSON.stringify({ ...ir, visibility: "PUBLIC" })
10878
10876
  });
10879
10877
  if (!res.ok) {
10880
10878
  const errorText = await res.text();
@@ -12071,7 +12069,13 @@ function App() {
12071
12069
  try {
12072
12070
  const res = await fetch(API_BASE + '/workflow/definitions');
12073
12071
  const json = await res.json();
12074
- const items = json.items || json.data || [];
12072
+ const rawItems = json.items || json.data || [];
12073
+ // Flatten: API returns { id, slug, definition: { experience, ... } }
12074
+ // Merge definition fields up to the top level for easier access
12075
+ const items = rawItems.map(d => {
12076
+ const def = d.definition || {};
12077
+ return { ...d, ...def, definition: undefined };
12078
+ });
12075
12079
  // Find the main blueprint definition (has experience tree)
12076
12080
  const main = items.find(d => d.experience && !(Array.isArray(d.category) ? d.category.includes('data') : d.category === 'data')) || items.find(d => d.experience) || items[0];
12077
12081
  if (main?.experience) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createDevServer
3
- } from "./chunk-EGKMUEM6.mjs";
3
+ } from "./chunk-U6F7CTHK.mjs";
4
4
  import "./chunk-PBRBRKIQ.mjs";
5
5
  import "./chunk-TRR2NPAV.mjs";
6
6
  import "./chunk-5M7DKKBC.mjs";
package/dist/index.js CHANGED
@@ -10876,14 +10876,12 @@ async function deploy(options) {
10876
10876
  }
10877
10877
  async function fetchExistingDefinition(apiUrl, token, slug) {
10878
10878
  try {
10879
- const res = await fetch(`${apiUrl}/workflow/definitions?slug=${encodeURIComponent(slug)}`, {
10879
+ const res = await fetch(`${apiUrl}/workflow/definitions/${encodeURIComponent(slug)}`, {
10880
10880
  headers: { Authorization: `Bearer ${token}` }
10881
10881
  });
10882
10882
  if (!res.ok) return null;
10883
- const data = await res.json();
10884
- const definitions = Array.isArray(data) ? data : data.items ?? data.data;
10885
- if (!definitions || definitions.length === 0) return null;
10886
- const def = definitions[0];
10883
+ const def = await res.json();
10884
+ if (!def || !def.id) return null;
10887
10885
  return {
10888
10886
  id: def.id,
10889
10887
  slug: def.slug,
@@ -10901,7 +10899,7 @@ async function createDefinition(apiUrl, token, ir) {
10901
10899
  "Content-Type": "application/json",
10902
10900
  Authorization: `Bearer ${token}`
10903
10901
  },
10904
- body: JSON.stringify(ir)
10902
+ body: JSON.stringify({ ...ir, visibility: "PUBLIC" })
10905
10903
  });
10906
10904
  if (!res.ok) {
10907
10905
  const errorText = await res.text();
@@ -12671,7 +12669,7 @@ function generatePageFile(page, _slug) {
12671
12669
  slug: page.route || "page",
12672
12670
  name: page.componentName,
12673
12671
  version: "1.0.0",
12674
- category: "page",
12672
+ category: "view",
12675
12673
  states: [],
12676
12674
  transitions: [],
12677
12675
  fields: [],
@@ -14287,7 +14285,13 @@ function App() {
14287
14285
  try {
14288
14286
  const res = await fetch(API_BASE + '/workflow/definitions');
14289
14287
  const json = await res.json();
14290
- const items = json.items || json.data || [];
14288
+ const rawItems = json.items || json.data || [];
14289
+ // Flatten: API returns { id, slug, definition: { experience, ... } }
14290
+ // Merge definition fields up to the top level for easier access
14291
+ const items = rawItems.map(d => {
14292
+ const def = d.definition || {};
14293
+ return { ...d, ...def, definition: undefined };
14294
+ });
14291
14295
  // Find the main blueprint definition (has experience tree)
14292
14296
  const main = items.find(d => d.experience && !(Array.isArray(d.category) ? d.category.includes('data') : d.category === 'data')) || items.find(d => d.experience) || items[0];
14293
14297
  if (main?.experience) {
package/dist/index.mjs CHANGED
@@ -18,17 +18,17 @@ import {
18
18
  decompile,
19
19
  decompileProject,
20
20
  shouldDecompileAsProject
21
- } from "./chunk-US3AVDAI.mjs";
21
+ } from "./chunk-4FP5DXY4.mjs";
22
22
  import {
23
23
  createDevServer
24
- } from "./chunk-EGKMUEM6.mjs";
24
+ } from "./chunk-U6F7CTHK.mjs";
25
25
  import "./chunk-PBRBRKIQ.mjs";
26
26
  import {
27
27
  buildEnvelope
28
28
  } from "./chunk-UASOWKDI.mjs";
29
29
  import {
30
30
  deploy
31
- } from "./chunk-ABYPKRSB.mjs";
31
+ } from "./chunk-XUQ5R6F3.mjs";
32
32
  import {
33
33
  build
34
34
  } from "./chunk-TRR2NPAV.mjs";