Skip to content

Commit 9387446

Browse files
committed
fixed error handling in store and reinitiated typescript
Signed-off-by: nitro56565 <[email protected]>
1 parent 977d98d commit 9387446

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

src/store/store.ts

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,55 @@ export interface DecompressedData {
4040
}
4141

4242
async function loadMarkdownProcessingLibs() {
43-
const [{ ModelManager }, { TemplateMarkInterpreter }, { TemplateMarkTransformer }, { transform }] =
44-
await Promise.all([
45-
import("@accordproject/concerto-core"),
46-
import("@accordproject/template-engine"),
47-
import("@accordproject/markdown-template"),
48-
import("@accordproject/markdown-transform"),
49-
]);
43+
try {
44+
const [{ ModelManager }, { TemplateMarkInterpreter }, { TemplateMarkTransformer }, { transform }] =
45+
await Promise.all([
46+
import("@accordproject/concerto-core"),
47+
import("@accordproject/template-engine"),
48+
import("@accordproject/markdown-template"),
49+
import("@accordproject/markdown-transform"),
50+
]);
5051

51-
return { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform };
52+
return { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform };
53+
} catch (error) {
54+
console.error("Failed to load Accord processing libraries:", error);
55+
throw new Error("Error loading Accord processing libraries");
56+
}
5257
}
5358

5459
const rebuild = debounce(async (template: string, model: string, dataString: string) => {
55-
const { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } =
56-
await loadMarkdownProcessingLibs();
60+
try {
61+
const { ModelManager, TemplateMarkInterpreter, TemplateMarkTransformer, transform } =
62+
await loadMarkdownProcessingLibs();
63+
64+
const modelManager = new ModelManager({ strict: true });
65+
modelManager.addCTOModel(model, undefined, true);
66+
await modelManager.updateExternalModels();
67+
68+
const engine = new TemplateMarkInterpreter(modelManager, {});
69+
const templateMarkTransformer = new TemplateMarkTransformer();
5770

58-
const modelManager = new ModelManager({ strict: true });
59-
modelManager.addCTOModel(model, undefined, true);
60-
await modelManager.updateExternalModels();
61-
const engine = new TemplateMarkInterpreter(modelManager, {});
62-
const templateMarkTransformer = new TemplateMarkTransformer();
63-
const templateMarkDom = templateMarkTransformer.fromMarkdownTemplate(
64-
{ content: template },
65-
modelManager,
66-
"contract",
67-
{ verbose: false }
68-
);
69-
const data = JSON.parse(dataString);
70-
const ciceroMark = await engine.generate(templateMarkDom, data);
71-
return await transform(
72-
ciceroMark.toJSON(),
73-
"ciceromark_parsed",
74-
["html"],
75-
{},
76-
{ verbose: false }
77-
);
71+
const templateMarkDom = templateMarkTransformer.fromMarkdownTemplate(
72+
{ content: template },
73+
modelManager,
74+
"contract",
75+
{ verbose: false }
76+
);
77+
78+
const data = JSON.parse(dataString);
79+
80+
const ciceroMark = await engine.generate(templateMarkDom, data);
81+
return await transform(
82+
ciceroMark.toJSON(),
83+
"ciceromark_parsed",
84+
["html"],
85+
{},
86+
{ verbose: false }
87+
);
88+
} catch (error) {
89+
console.error("Error rebuilding the template:", error);
90+
throw new Error("Failed to process the template");
91+
}
7892
}, 500);
7993

8094
const useAppStore = create<AppState>()(

vite.config.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ const viteConfig = defineViteConfig({
1616
}), getPlugins()],
1717
optimizeDeps: {
1818
include: ["immer", "zustand"],
19-
exclude: ["typescript"],
2019
needsInterop: ['@accordproject/template-engine'],
2120
},
22-
build: {
23-
rollupOptions: {
24-
external: ["typescript"],
25-
},
26-
},
2721
});
2822

2923

0 commit comments

Comments
 (0)