@bobtail.software/b-durable 1.0.5 → 1.0.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.
@@ -1,721 +1,59 @@
1
1
  #!/usr/bin/env node
2
-
3
- // src/compiler/cli.ts
4
- import path2 from "path";
5
-
6
- // src/compiler/compile.ts
7
- import { existsSync, mkdirSync, rmSync } from "fs";
8
- import path from "path";
9
- import * as prettier from "prettier";
10
- import {
11
- Node,
12
- Project,
13
- SyntaxKind,
14
- ts,
15
- VariableDeclarationKind
16
- } from "ts-morph";
17
- var DURABLE_WRAPPER_NAME = "bDurable";
18
- var TYPE_FORMAT_FLAGS = ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation;
19
- async function formatSourceFileWithPrettier(sourceFile) {
20
- const filePath = sourceFile.getFilePath();
21
- const unformattedText = sourceFile.getFullText();
22
- const prettierConfig = await prettier.resolveConfig(filePath);
23
- const formattedText = await prettier.format(unformattedText, {
24
- ...prettierConfig,
25
- parser: "typescript"
26
- });
27
- sourceFile.replaceWithText(formattedText);
28
- }
29
- async function compileWorkflows(options) {
30
- console.log("Iniciando compilador de workflows duraderos...");
31
- const { inputDir, outputDir, packageName } = options;
32
- const project = new Project({
33
- tsConfigFilePath: path.resolve(process.cwd(), "tsconfig.json")
34
- });
35
- const sourceFiles = project.addSourceFilesAtPaths(`${inputDir}/**/*.ts`);
36
- if (existsSync(outputDir)) {
37
- console.log(`Limpiando directorio de salida: ${outputDir}`);
38
- rmSync(outputDir, { recursive: true, force: true });
39
- }
40
- mkdirSync(outputDir, { recursive: true });
41
- const compiledDir = project.createDirectory(outputDir);
42
- console.log(`Encontrados ${sourceFiles.length} archivos de workflow para procesar.`);
43
- const workflowRegistry = [];
44
- const generatedFiles = [];
45
- for (const sourceFile of sourceFiles) {
46
- console.log(`
47
- Procesando archivo: ${sourceFile.getBaseName()}`);
48
- const durableCalls = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === DURABLE_WRAPPER_NAME);
49
- if (durableCalls.length === 0) continue;
50
- for (const call of durableCalls) {
51
- const workflowVarDecl = call.getParentIfKind(SyntaxKind.VariableDeclaration);
52
- if (!workflowVarDecl) continue;
53
- const workflowName = workflowVarDecl.getName();
54
- console.log(` -> Transformando workflow: ${workflowName}`);
55
- const [arg] = call.getArguments();
56
- if (!Node.isObjectLiteralExpression(arg)) continue;
57
- const workflowProperty = arg.getProperty("workflow");
58
- if (!workflowProperty || !Node.isPropertyAssignment(workflowProperty)) continue;
59
- const workflowFunc = workflowProperty.getInitializer();
60
- if (!workflowFunc || !Node.isArrowFunction(workflowFunc)) continue;
61
- const originalBaseName = sourceFile.getBaseName();
62
- const compiledFileName = originalBaseName.replace(/\.ts$/, ".compiled.mts");
63
- const newFilePath = path.join(compiledDir.getPath(), compiledFileName);
64
- const newSourceFile = project.createSourceFile(newFilePath, "", {
65
- overwrite: true
66
- });
67
- generatedFiles.push(newSourceFile);
68
- transformWorkflowFunction(
69
- workflowName,
70
- workflowFunc,
71
- call,
72
- newSourceFile,
73
- packageName
74
- );
75
- console.log(
76
- ` -> Archivo generado: ${path.relative(process.cwd(), newFilePath)}`
77
- );
78
- const importPathName = compiledFileName;
79
- workflowRegistry.push({ name: workflowName, importPath: `./${importPathName}` });
80
- }
81
- }
82
- if (workflowRegistry.length > 0) {
83
- const indexFilePath = path.join(compiledDir.getPath(), "index.mts");
84
- const indexSourceFile = project.createSourceFile(indexFilePath, "", {
85
- overwrite: true
86
- });
87
- generatedFiles.push(indexSourceFile);
88
- indexSourceFile.addStatements(
89
- "// Este archivo fue generado autom\xE1ticamente. NO EDITAR MANUALMENTE.\n"
90
- );
91
- indexSourceFile.addImportDeclaration({
92
- isTypeOnly: true,
93
- moduleSpecifier: packageName,
94
- namedImports: ["DurableFunction"]
95
- });
96
- for (const wf of workflowRegistry) {
97
- indexSourceFile.addImportDeclaration({
98
- moduleSpecifier: wf.importPath,
99
- namedImports: [wf.name]
100
- });
101
- }
102
- indexSourceFile.addExportDeclaration({
103
- namedExports: workflowRegistry.map((wf) => wf.name)
104
- });
105
- indexSourceFile.addStatements("\n");
106
- indexSourceFile.addVariableStatement({
107
- declarationKind: VariableDeclarationKind.Const,
108
- declarations: [
109
- {
110
- name: "durableFunctions",
111
- type: "Map<string, DurableFunction<any, any, any>>",
112
- initializer: "new Map()"
113
- }
114
- ]
115
- });
116
- const setStatements = workflowRegistry.map(
117
- (wf) => `durableFunctions.set(${wf.name}.name, ${wf.name});`
118
- );
119
- indexSourceFile.addStatements(setStatements);
120
- indexSourceFile.addStatements("\n");
121
- indexSourceFile.addExportAssignment({
122
- isExportEquals: false,
123
- expression: "durableFunctions"
124
- });
125
- console.log(`
126
- -> Archivo de \xEDndice generado: ${path.basename(indexFilePath)}`);
127
- }
128
- console.log("\nFormateando archivos generados con Prettier...");
129
- for (const file of generatedFiles) {
130
- await formatSourceFileWithPrettier(file);
131
- }
132
- await project.save();
133
- console.log("\nCompilaci\xF3n completada exitosamente.");
134
- }
135
- function transformWorkflowFunction(workflowName, func, bDurableCall, targetSourceFile, packageName) {
136
- const body = func.getBody();
137
- if (!Node.isBlock(body)) {
138
- throw new Error(`El cuerpo del workflow '${workflowName}' debe ser un bloque {}.`);
139
- }
140
- const { clauses: caseClauses } = processStatementsRecursive(body.getStatements(), {
141
- step: 0,
142
- persistedVariables: /* @__PURE__ */ new Map()
143
- });
144
- let returnTypeNode = func.getReturnType();
145
- if (returnTypeNode.getSymbol()?.getName() === "Promise" && returnTypeNode.isObject()) {
146
- returnTypeNode = returnTypeNode.getTypeArguments()[0] || returnTypeNode;
147
- }
148
- const returnType = returnTypeNode.getText(void 0, TYPE_FORMAT_FLAGS);
149
- const dependencyStatements = /* @__PURE__ */ new Set();
150
- const originalSourceFile = func.getSourceFile();
151
- const typeArgs = bDurableCall.getTypeArguments();
152
- const paramType = typeArgs.length > 0 ? typeArgs[0].getText() : "unknown";
153
- const eventsType = typeArgs.length > 2 ? typeArgs[2].getText() : "Record<string, never>";
154
- originalSourceFile.getImportDeclarations().forEach((importDecl) => {
155
- if (importDecl.getModuleSpecifierValue() === packageName) return;
156
- let moduleSpecifier = importDecl.getModuleSpecifierValue();
157
- if (moduleSpecifier.includes(".workflow")) {
158
- const parsedPath = path.parse(moduleSpecifier);
159
- let joinedPath = path.join(parsedPath.dir, parsedPath.base + ".compiled.mts");
160
- if (!joinedPath.startsWith(".") && !path.isAbsolute(joinedPath)) {
161
- joinedPath = "./" + joinedPath;
162
- }
163
- moduleSpecifier = joinedPath.replace(/\\/g, "/");
164
- } else if (moduleSpecifier.startsWith(".")) {
165
- if (path.extname(moduleSpecifier) === "") {
166
- moduleSpecifier += ".mjs";
167
- }
168
- }
169
- const valueImports = [];
170
- const typeImports = [];
171
- importDecl.getNamedImports().forEach((specifier) => {
172
- const name = specifier.getName();
173
- const alias = specifier.getAliasNode()?.getText();
174
- const importText = alias ? `${name} as ${alias}` : name;
175
- const symbol = specifier.getNameNode().getSymbol()?.getAliasedSymbol() ?? specifier.getNameNode().getSymbol();
176
- const declarations = symbol?.getDeclarations() ?? [];
177
- const isEnum = declarations.some((d) => Node.isEnumDeclaration(d));
178
- const isPurelyType = specifier.isTypeOnly() || !isEnum && declarations.every(
179
- (d) => Node.isInterfaceDeclaration(d) || Node.isTypeAliasDeclaration(d)
180
- );
181
- if (isPurelyType) {
182
- typeImports.push(importText);
183
- } else {
184
- valueImports.push(importText);
185
- }
186
- });
187
- if (valueImports.length > 0) {
188
- targetSourceFile.addImportDeclaration({
189
- moduleSpecifier,
190
- namedImports: valueImports
191
- });
192
- }
193
- if (typeImports.length > 0) {
194
- targetSourceFile.addImportDeclaration({
195
- isTypeOnly: true,
196
- moduleSpecifier,
197
- namedImports: typeImports
198
- });
199
- }
200
- const defaultImport = importDecl.getDefaultImport();
201
- if (defaultImport) {
202
- targetSourceFile.addImportDeclaration({
203
- moduleSpecifier,
204
- defaultImport: defaultImport.getText()
205
- });
206
- }
207
- });
208
- originalSourceFile.getInterfaces().forEach((iface) => {
209
- dependencyStatements.add(
210
- iface.getText().startsWith("export") ? iface.getText() : `export ${iface.getText()}`
211
- );
212
- });
213
- originalSourceFile.getTypeAliases().forEach((typeAlias) => {
214
- dependencyStatements.add(
215
- typeAlias.getText().startsWith("export") ? typeAlias.getText() : `export ${typeAlias.getText()}`
216
- );
217
- });
218
- const [params] = func.getParameters();
219
- let paramAssignment = "";
220
- if (params) {
221
- const paramName = params.getNameNode().getText();
222
- if (paramName !== "input") {
223
- paramAssignment = `const ${paramName} = input;`;
224
- }
225
- }
226
- targetSourceFile.addImportDeclaration({
227
- isTypeOnly: true,
228
- moduleSpecifier: packageName,
229
- namedImports: ["DurableFunction", "WorkflowContext", "Instruction"]
230
- });
231
- if (dependencyStatements.size > 0) {
232
- targetSourceFile.addStatements("\n");
233
- targetSourceFile.addStatements(Array.from(dependencyStatements));
234
- }
235
- targetSourceFile.addStatements(
236
- "\n// Este archivo fue generado autom\xE1ticamente. NO EDITAR MANUALMENTE.\n"
237
- );
238
- const initializerObjectString = `{
2
+ import z from"path";import{existsSync as q,mkdirSync as G,rmSync as X}from"fs";import h from"path";import*as R from"prettier";import{Node as p,Project as Y,SyntaxKind as b,ts as W,VariableDeclarationKind as K}from"ts-morph";var J="bDurable",F=W.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|W.TypeFormatFlags.NoTruncation;async function Q(e){let t=e.getFilePath(),s=e.getFullText(),n=await R.resolveConfig(t),o=await R.format(s,{...n,parser:"typescript"});e.replaceWithText(o)}async function _(e){console.log("Iniciando compilador de workflows duraderos...");let{inputDir:t,outputDir:s,packageName:n}=e,o=new Y({tsConfigFilePath:h.resolve(process.cwd(),"tsconfig.json")}),i=o.addSourceFilesAtPaths(`${t}/**/*.ts`);q(s)&&(console.log(`Limpiando directorio de salida: ${s}`),X(s,{recursive:!0,force:!0})),G(s,{recursive:!0});let f=o.createDirectory(s);console.log(`Encontrados ${i.length} archivos de workflow para procesar.`);let a=[],c=[];for(let u of i){console.log(`
3
+ Procesando archivo: ${u.getBaseName()}`);let r=u.getDescendantsOfKind(b.CallExpression).filter(g=>g.getExpression().getText()===J);if(r.length!==0)for(let g of r){let l=g.getParentIfKind(b.VariableDeclaration);if(!l)continue;let d=l.getName();console.log(` -> Transformando workflow: ${d}`);let[m]=g.getArguments();if(!p.isObjectLiteralExpression(m))continue;let y=m.getProperty("workflow");if(!y||!p.isPropertyAssignment(y))continue;let x=y.getInitializer();if(!x||!p.isArrowFunction(x))continue;let N=u.getBaseName().replace(/\.ts$/,".compiled.mts"),A=h.join(f.getPath(),N),D=o.createSourceFile(A,"",{overwrite:!0});c.push(D),Z(d,x,g,D,n),console.log(` -> Archivo generado: ${h.relative(process.cwd(),A)}`);let w=N;a.push({name:d,importPath:`./${w}`})}}if(a.length>0){let u=h.join(f.getPath(),"index.mts"),r=o.createSourceFile(u,"",{overwrite:!0});c.push(r),r.addStatements(`// Este archivo fue generado autom\xE1ticamente. NO EDITAR MANUALMENTE.
4
+ `),r.addImportDeclaration({isTypeOnly:!0,moduleSpecifier:n,namedImports:["DurableFunction"]});for(let l of a)r.addImportDeclaration({moduleSpecifier:l.importPath,namedImports:[l.name]});r.addExportDeclaration({namedExports:a.map(l=>l.name)}),r.addStatements(`
5
+ `),r.addVariableStatement({declarationKind:K.Const,declarations:[{name:"durableFunctions",type:"Map<string, DurableFunction<any, any, any, any>>",initializer:"new Map()"}]});let g=a.map(l=>`durableFunctions.set(${l.name}.name, ${l.name});`);r.addStatements(g),r.addStatements(`
6
+ `),r.addExportAssignment({isExportEquals:!1,expression:"durableFunctions"}),console.log(`
7
+ -> Archivo de \xEDndice generado: ${h.basename(u)}`)}console.log(`
8
+ Formateando archivos generados con Prettier...`);for(let u of c)await Q(u);await o.save(),console.log(`
9
+ Compilaci\xF3n completada exitosamente.`)}function Z(e,t,s,n,o){let i=t.getBody();if(!p.isBlock(i))throw new Error(`El cuerpo del workflow '${e}' debe ser un bloque {}.`);let[f]=s.getArguments();if(!p.isObjectLiteralExpression(f))throw new Error("El argumento de bDurable debe ser un objeto.");let a=f.getProperty("version");if(!a||!p.isPropertyAssignment(a))throw new Error(`El workflow '${e}' debe tener una propiedad 'version'.`);let c=a.getInitializer();if(!c||!p.isStringLiteral(c))throw new Error(`La versi\xF3n del workflow '${e}' debe ser un string literal.`);let{clauses:u}=T(i.getStatements(),{step:0,persistedVariables:new Map}),r=t.getReturnType();r.getSymbol()?.getName()==="Promise"&&r.isObject()&&(r=r.getTypeArguments()[0]||r);let g=r.getText(void 0,F),l=new Set,d=t.getSourceFile(),m=s.getTypeArguments(),y=m.length>0?m[0].getText():"unknown",x=m.length>2?m[2].getText():"Record<string, never>",k=m.length>3?m[3].getText():"Record<string, never>";d.getImportDeclarations().forEach(S=>{if(S.getModuleSpecifierValue()===o)return;let E=S.getModuleSpecifierValue();if(E.includes(".workflow")){let $=h.parse(E),P=h.join($.dir,$.base+".compiled.mts");!P.startsWith(".")&&!h.isAbsolute(P)&&(P="./"+P),E=P.replace(/\\/g,"/")}else E.startsWith(".")&&h.extname(E)===""&&(E+=".mjs");let O=[],V=[];S.getNamedImports().forEach($=>{let P=$.getName(),M=$.getAliasNode()?.getText(),j=M?`${P} as ${M}`:P,L=($.getNameNode().getSymbol()?.getAliasedSymbol()??$.getNameNode().getSymbol())?.getDeclarations()??[],H=L.some(v=>p.isEnumDeclaration(v));$.isTypeOnly()||!H&&L.every(v=>p.isInterfaceDeclaration(v)||p.isTypeAliasDeclaration(v))?V.push(j):O.push(j)}),O.length>0&&n.addImportDeclaration({moduleSpecifier:E,namedImports:O}),V.length>0&&n.addImportDeclaration({isTypeOnly:!0,moduleSpecifier:E,namedImports:V});let B=S.getDefaultImport();B&&n.addImportDeclaration({moduleSpecifier:E,defaultImport:B.getText()})}),d.getInterfaces().forEach(S=>{l.add(S.getText().startsWith("export")?S.getText():`export ${S.getText()}`)}),d.getTypeAliases().forEach(S=>{l.add(S.getText().startsWith("export")?S.getText():`export ${S.getText()}`)});let[N]=t.getParameters(),A="";if(N){let S=N.getNameNode().getText();S!=="input"&&(A=`const ${S} = input;`)}n.addImportDeclaration({isTypeOnly:!0,moduleSpecifier:o,namedImports:["DurableFunction","WorkflowContext","Instruction"]}),l.size>0&&(n.addStatements(`
10
+ `),n.addStatements(Array.from(l))),n.addStatements(`
11
+ // Este archivo fue generado autom\xE1ticamente. NO EDITAR MANUALMENTE.
12
+ `);let D=c.getLiteralValue(),w=`{
239
13
  __isDurable: true,
240
- name: '${workflowName}',
241
- async execute(context: WorkflowContext<${paramType}>): Promise<Instruction<${returnType}>> {
14
+ name: '${e}',
15
+ version: '${D}',
16
+ async execute(context: WorkflowContext<${y}>): Promise<Instruction<${g}>> {
242
17
  const { input, state, result, log, workflowId } = context;
243
- ${paramAssignment}
18
+ ${A}
244
19
  while (true) {
245
20
  switch (context.step) {
246
- ${caseClauses.join("\n")}
21
+ ${u.join(`
22
+ `)}
247
23
  default:
248
24
  throw new Error(\`Paso desconocido: \${context.step}\`);
249
25
  }
250
26
  }
251
27
  }
252
- }`;
253
- targetSourceFile.addVariableStatement({
254
- isExported: true,
255
- declarationKind: VariableDeclarationKind.Const,
256
- declarations: [
257
- {
258
- name: workflowName,
259
- type: `DurableFunction<${paramType}, ${returnType}, ${eventsType}>`,
260
- initializer: initializerObjectString
261
- }
262
- ]
263
- });
264
- targetSourceFile.organizeImports();
265
- }
266
- function processStatementsRecursive(statements, initialState) {
267
- if (statements.length === 0) {
268
- const clauses = [];
269
- if (initialState.pendingStateAssignment) {
270
- const finalClause = `case ${initialState.step}: {
271
- ${initialState.pendingStateAssignment}
28
+ }`;n.addVariableStatement({isExported:!0,declarationKind:K.Const,declarations:[{name:e,type:`DurableFunction<${y}, ${g}, ${x}, ${k}>`,initializer:w}]}),n.organizeImports()}function T(e,t){if(e.length===0){let m=[];if(t.pendingStateAssignment){let y=`case ${t.step}: {
29
+ ${t.pendingStateAssignment}
272
30
  return { type: 'COMPLETE', result: undefined };
273
- }`;
274
- clauses.push(finalClause);
275
- }
276
- return { clauses, nextStep: initialState.step + 1 };
277
- }
278
- const { syncBlock, durableStatement, nextStatements } = splitAtNextDurableCall(statements);
279
- const { rewrittenSyncStatements, newlyPersistedVariables } = processSyncBlock(
280
- syncBlock,
281
- durableStatement ? [durableStatement, ...nextStatements] : [],
282
- initialState.persistedVariables
283
- );
284
- if (initialState.pendingStateAssignment) {
285
- rewrittenSyncStatements.unshift(initialState.pendingStateAssignment);
286
- }
287
- const updatedPersistedVariables = new Map([
288
- ...initialState.persistedVariables,
289
- ...newlyPersistedVariables
290
- ]);
291
- if (!durableStatement) {
292
- const syncCode2 = rewrittenSyncStatements.join("\n");
293
- const lastStatementIsReturn = syncBlock.length > 0 && Node.isReturnStatement(syncBlock[syncBlock.length - 1]);
294
- const finalInstruction = lastStatementIsReturn ? "" : `
295
- return { type: 'COMPLETE', result: undefined };`;
296
- const clause = `case ${initialState.step}: {
297
- ${syncCode2}${finalInstruction}
298
- }`;
299
- return { clauses: [clause], nextStep: initialState.step + 1 };
300
- }
301
- if (Node.isIfStatement(durableStatement)) {
302
- return processIfStatement(
303
- durableStatement,
304
- nextStatements,
305
- {
306
- ...initialState,
307
- persistedVariables: updatedPersistedVariables
308
- },
309
- rewrittenSyncStatements
310
- );
311
- }
312
- if (Node.isTryStatement(durableStatement)) {
313
- return processTryStatement(
314
- durableStatement,
315
- nextStatements,
316
- { ...initialState, persistedVariables: updatedPersistedVariables },
317
- rewrittenSyncStatements
318
- );
319
- }
320
- const { instruction, nextPendingStateAssignment } = generateDurableInstruction(
321
- durableStatement,
322
- updatedPersistedVariables
323
- );
324
- rewrittenSyncStatements.push(instruction);
325
- const syncCode = rewrittenSyncStatements.join("\n");
326
- const currentClause = `case ${initialState.step}: {
327
- ${syncCode}
328
- }`;
329
- const nextState = {
330
- step: initialState.step + 1,
331
- persistedVariables: updatedPersistedVariables,
332
- pendingStateAssignment: nextPendingStateAssignment
333
- };
334
- const restResult = processStatementsRecursive(nextStatements, nextState);
335
- return {
336
- clauses: [currentClause, ...restResult.clauses],
337
- nextStep: restResult.nextStep
338
- };
339
- }
340
- function processIfStatement(ifStatement, followingStatements, currentState, rewrittenSyncStatements) {
341
- const condition = rewriteNode(ifStatement.getExpression(), currentState.persistedVariables);
342
- const thenBlock = ifStatement.getThenStatement();
343
- const thenStatements = Node.isBlock(thenBlock) ? thenBlock.getStatements() : [thenBlock];
344
- const thenResult = processStatementsRecursive(thenStatements, {
345
- step: currentState.step + 1,
346
- persistedVariables: new Map(currentState.persistedVariables)
347
- // Clona para aislamiento de ramas
348
- });
349
- let elseResult;
350
- const elseStatement = ifStatement.getElseStatement();
351
- if (elseStatement) {
352
- const elseStatements = Node.isBlock(elseStatement) ? elseStatement.getStatements() : [elseStatement];
353
- elseResult = processStatementsRecursive(elseStatements, {
354
- step: thenResult.nextStep,
355
- // La rama 'else' comienza donde termina la 'then'
356
- persistedVariables: new Map(currentState.persistedVariables)
357
- });
358
- }
359
- const nextStepAfterIf = elseResult ? elseResult.nextStep : thenResult.nextStep;
360
- const afterIfResult = processStatementsRecursive(followingStatements, {
361
- step: nextStepAfterIf,
362
- persistedVariables: currentState.persistedVariables
363
- // Usa el mapa original
364
- });
365
- const syncCode = rewrittenSyncStatements.join("\n");
366
- const jumpToElseStep = thenResult.nextStep;
367
- const ifClause = `
368
- case ${currentState.step}: {
369
- ${syncCode}
370
- if (${condition}) {
371
- context.step = ${currentState.step + 1};
31
+ }`;m.push(y)}return{clauses:m,nextStep:t.step+1}}let{syncBlock:s,durableStatement:n,nextStatements:o}=ie(e),{rewrittenSyncStatements:i,newlyPersistedVariables:f}=ne(s,n?[n,...o]:[],t.persistedVariables);t.pendingStateAssignment&&i.unshift(t.pendingStateAssignment);let a=new Map([...t.persistedVariables,...f]);if(!n){let m=i.join(`
32
+ `),x=s.length>0&&p.isReturnStatement(s[s.length-1])?"":`
33
+ return { type: 'COMPLETE', result: undefined };`;return{clauses:[`case ${t.step}: {
34
+ ${m}${x}
35
+ }`],nextStep:t.step+1}}if(p.isIfStatement(n))return ee(n,o,{...t,persistedVariables:a},i);if(p.isTryStatement(n))return te(n,o,{...t,persistedVariables:a},i);let{instruction:c,nextPendingStateAssignment:u}=re(n,a);i.push(c);let r=i.join(`
36
+ `),g=`case ${t.step}: {
37
+ ${r}
38
+ }`,l={step:t.step+1,persistedVariables:a,pendingStateAssignment:u},d=T(o,l);return{clauses:[g,...d.clauses],nextStep:d.nextStep}}function ee(e,t,s,n){let o=I(e.getExpression(),s.persistedVariables),i=e.getThenStatement(),f=p.isBlock(i)?i.getStatements():[i],a=T(f,{step:s.step+1,persistedVariables:new Map(s.persistedVariables)}),c,u=e.getElseStatement();if(u){let y=p.isBlock(u)?u.getStatements():[u];c=T(y,{step:a.nextStep,persistedVariables:new Map(s.persistedVariables)})}let r=c?c.nextStep:a.nextStep,g=T(t,{step:r,persistedVariables:s.persistedVariables}),l=n.join(`
39
+ `),d=a.nextStep;return{clauses:[`
40
+ case ${s.step}: {
41
+ ${l}
42
+ if (${o}) {
43
+ context.step = ${s.step+1};
372
44
  } else {
373
- ${elseStatement ? `context.step = ${jumpToElseStep};` : `context.step = ${nextStepAfterIf};`}
45
+ ${u?`context.step = ${d};`:`context.step = ${r};`}
374
46
  }
375
47
  break;
376
48
  }
377
- `;
378
- return {
379
- clauses: [
380
- ifClause,
381
- ...thenResult.clauses,
382
- ...elseResult ? elseResult.clauses : [],
383
- ...afterIfResult.clauses
384
- ],
385
- nextStep: afterIfResult.nextStep
386
- };
387
- }
388
- function processTryStatement(tryStatement, followingStatements, currentState, rewrittenSyncStatements) {
389
- const { step, persistedVariables } = currentState;
390
- const tryBlock = tryStatement.getTryBlock();
391
- const catchClause = tryStatement.getCatchClause();
392
- const finallyBlock = tryStatement.getFinallyBlock();
393
- const tryResult = processStatementsRecursive(tryBlock.getStatements(), {
394
- step: step + 1,
395
- // El bloque try comienza en el siguiente step
396
- persistedVariables: new Map(persistedVariables)
397
- });
398
- let catchResult;
399
- let catchVarName;
400
- const catchStep = tryResult.nextStep;
401
- if (catchClause) {
402
- const catchBlock = catchClause.getBlock();
403
- const varDeclaration = catchClause.getVariableDeclaration();
404
- if (varDeclaration) {
405
- catchVarName = varDeclaration.getName();
406
- }
407
- catchResult = processStatementsRecursive(catchBlock.getStatements(), {
408
- step: catchStep,
409
- persistedVariables: new Map(persistedVariables)
410
- });
411
- }
412
- let finallyResult;
413
- const finallyStep = catchResult ? catchResult.nextStep : catchStep;
414
- if (finallyBlock) {
415
- finallyResult = processStatementsRecursive(finallyBlock.getStatements(), {
416
- step: finallyStep,
417
- persistedVariables: new Map(persistedVariables)
418
- });
419
- }
420
- const endStep = finallyResult ? finallyResult.nextStep : finallyStep;
421
- const afterTryResult = processStatementsRecursive(followingStatements, {
422
- step: endStep,
423
- persistedVariables
424
- });
425
- const handler = `{ catchStep: ${catchClause ? catchStep : "undefined"}, finallyStep: ${finallyBlock ? finallyStep : "undefined"} }`;
426
- const pushClause = `
427
- case ${step}: {
428
- ${rewrittenSyncStatements.join("\n")}
49
+ `,...a.clauses,...c?c.clauses:[],...g.clauses],nextStep:g.nextStep}}function te(e,t,s,n){let{step:o,persistedVariables:i}=s,f=e.getTryBlock(),a=e.getCatchClause(),c=e.getFinallyBlock(),u=T(f.getStatements(),{step:o+1,persistedVariables:new Map(i)}),r,g,l=u.nextStep;if(a){let w=a.getBlock(),S=a.getVariableDeclaration();S&&(g=S.getName()),r=T(w.getStatements(),{step:l,persistedVariables:new Map(i)})}let d,m=r?r.nextStep:l;c&&(d=T(c.getStatements(),{step:m,persistedVariables:new Map(i)}));let y=d?d.nextStep:m,x=T(t,{step:y,persistedVariables:i}),k=`{ catchStep: ${a?l:"undefined"}, finallyStep: ${c?m:"undefined"} }`,N=`
50
+ case ${o}: {
51
+ ${n.join(`
52
+ `)}
429
53
  state.tryCatchStack = state.tryCatchStack || [];
430
- state.tryCatchStack.push(${handler});
431
- context.step = ${step + 1}; // Salta al inicio del bloque try
54
+ state.tryCatchStack.push(${k});
55
+ context.step = ${o+1}; // Salta al inicio del bloque try
432
56
  break;
433
57
  }
434
- `;
435
- const lastTryClause = tryResult.clauses.pop() || "";
436
- const jumpToAfterTryStep = finallyBlock ? finallyStep : endStep;
437
- tryResult.clauses.push(
438
- lastTryClause.replace(
439
- /return { type: 'COMPLETE'.* };/,
440
- `context.step = ${jumpToAfterTryStep}; break;`
441
- )
442
- );
443
- if (catchResult) {
444
- if (catchVarName) {
445
- const firstCatchClause = catchResult.clauses[0] || `case ${catchStep}: {}`;
446
- catchResult.clauses[0] = firstCatchClause.replace(
447
- "{",
448
- `{
449
- const ${catchVarName} = result as Error;`
450
- );
451
- }
452
- const lastCatchClause = catchResult.clauses.pop() || "";
453
- catchResult.clauses.push(
454
- lastCatchClause.replace(
455
- /return { type: 'COMPLETE'.* };/,
456
- `context.step = ${jumpToAfterTryStep}; break;`
457
- )
458
- );
459
- }
460
- if (finallyResult) {
461
- const lastFinallyClause = finallyResult.clauses.pop() || "";
462
- finallyResult.clauses.push(
463
- lastFinallyClause.replace(
464
- /return { type: 'COMPLETE'.* };/,
465
- `state.tryCatchStack?.pop(); context.step = ${endStep}; break;`
466
- )
467
- );
468
- }
469
- return {
470
- clauses: [
471
- pushClause,
472
- ...tryResult.clauses,
473
- ...catchResult ? catchResult.clauses : [],
474
- ...finallyResult ? finallyResult.clauses : [],
475
- ...afterTryResult.clauses
476
- ],
477
- nextStep: afterTryResult.nextStep
478
- };
479
- }
480
- function processSyncBlock(syncBlock, followingStatements, persistedVariables) {
481
- const rewrittenSyncStatements = [];
482
- const newlyPersistedVariables = /* @__PURE__ */ new Map();
483
- const usedLaterIdentifiers = findUsedIdentifiers(followingStatements);
484
- const currentPersistedVars = new Map(persistedVariables);
485
- for (const statement of syncBlock) {
486
- let handledAsStatePersistence = false;
487
- if (Node.isVariableStatement(statement)) {
488
- for (const decl of statement.getDeclarations()) {
489
- const initializer = decl.getInitializer();
490
- if (!initializer) continue;
491
- const varInfos = getVarInfoFromDeclaration(decl);
492
- const varsToPersist = varInfos.filter(
493
- (v) => usedLaterIdentifiers.has(v.name)
494
- );
495
- if (varsToPersist.length > 0) {
496
- const rewrittenInitializer = rewriteNode(
497
- initializer,
498
- persistedVariables
499
- );
500
- for (const { name, type } of varsToPersist) {
501
- newlyPersistedVariables.set(name, { type });
502
- currentPersistedVars.set(name, { type });
503
- const assignmentRightHand = varInfos.length > 1 ? `${rewrittenInitializer}.${name}` : rewrittenInitializer;
504
- rewrittenSyncStatements.push(
505
- `state.${name} = ${assignmentRightHand};`
506
- );
507
- }
508
- if (varsToPersist.length === varInfos.length) {
509
- handledAsStatePersistence = true;
510
- }
511
- }
512
- }
513
- }
514
- if (!handledAsStatePersistence) {
515
- rewrittenSyncStatements.push(rewriteNode(statement, currentPersistedVars));
516
- }
517
- }
518
- return { rewrittenSyncStatements, newlyPersistedVariables };
519
- }
520
- function getVarInfoFromDeclaration(decl) {
521
- const nameNode = decl.getNameNode();
522
- const result = [];
523
- if (Node.isIdentifier(nameNode)) {
524
- const type = decl.getType().getText(decl, TYPE_FORMAT_FLAGS);
525
- result.push({ name: nameNode.getText(), type });
526
- } else if (Node.isObjectBindingPattern(nameNode)) {
527
- for (const element of nameNode.getElements()) {
528
- const name = element.getName();
529
- const type = element.getType().getText(element, TYPE_FORMAT_FLAGS);
530
- result.push({ name, type });
531
- }
532
- }
533
- return result;
534
- }
535
- function generateDurableInstruction(statement, persistedVariables) {
536
- if (Node.isReturnStatement(statement)) {
537
- const returnExpr = statement.getExpression() ? rewriteNode(statement.getExpressionOrThrow(), persistedVariables) : "undefined";
538
- return {
539
- instruction: `return { type: 'COMPLETE', result: ${returnExpr} };`,
540
- nextPendingStateAssignment: void 0
541
- };
542
- }
543
- let nextPendingStateAssignment = void 0;
544
- const varDecl = statement.getFirstDescendantByKind(SyntaxKind.VariableDeclaration);
545
- if (varDecl) {
546
- const varName = varDecl.getName();
547
- const varType = varDecl.getType().getText(varDecl, TYPE_FORMAT_FLAGS);
548
- persistedVariables.set(varName, { type: varType });
549
- nextPendingStateAssignment = `state.${varName} = result;`;
550
- }
551
- const awaitExpression = statement.getFirstDescendantByKind(SyntaxKind.AwaitExpression);
552
- if (awaitExpression) {
553
- const callExpr = awaitExpression.getExpression();
554
- if (Node.isCallExpression(callExpr)) {
555
- return {
556
- instruction: `return ${createInstructionForCall(callExpr, persistedVariables)};`,
557
- nextPendingStateAssignment
558
- };
559
- }
560
- }
561
- return {
562
- instruction: rewriteNode(statement, persistedVariables),
563
- nextPendingStateAssignment
564
- };
565
- }
566
- function findUsedIdentifiers(nodes) {
567
- const identifiers = /* @__PURE__ */ new Set();
568
- for (const node of nodes) {
569
- node.getDescendantsOfKind(SyntaxKind.Identifier).forEach((ident) => {
570
- identifiers.add(ident.getText());
571
- });
572
- }
573
- return identifiers;
574
- }
575
- function rewriteNode(node, persistedVariables) {
576
- const tempSourceFile = node.getProject().createSourceFile(
577
- `temp_rewrite_${Math.random()}.ts`,
578
- `const temp = ${node.getText()};`,
579
- // Se envuelve para asegurar que sea un AST válido
580
- { overwrite: true }
581
- );
582
- const nodeClone = tempSourceFile.getVariableDeclarationOrThrow("temp").getInitializerOrThrow();
583
- const descendants = [nodeClone, ...nodeClone.getDescendants()].reverse();
584
- for (const currentNode of descendants) {
585
- if (Node.isIdentifier(currentNode) && !currentNode.wasForgotten() && persistedVariables.has(currentNode.getText())) {
586
- const varName = currentNode.getText();
587
- const parent = currentNode.getParent();
588
- const isDeclaration = Node.isVariableDeclaration(parent) && parent.getNameNode() === currentNode;
589
- const isProperty = Node.isPropertyAccessExpression(parent) && parent.getNameNode() === currentNode || Node.isPropertyAssignment(parent) && parent.getNameNode() === currentNode;
590
- const isBindingElement = Node.isBindingElement(parent) && parent.getNameNode() === currentNode;
591
- if (!isDeclaration && !isProperty && !isBindingElement) {
592
- const typeInfo = persistedVariables.get(varName);
593
- currentNode.replaceWithText(`(state.${varName} as ${typeInfo.type})`);
594
- }
595
- }
596
- }
597
- const fullText = tempSourceFile.getFullText().trim();
598
- tempSourceFile.forget();
599
- const prefix = "const temp = ";
600
- let newText = fullText;
601
- if (newText.startsWith(prefix)) {
602
- newText = newText.substring(prefix.length);
603
- }
604
- if (newText.endsWith(";")) {
605
- newText = newText.slice(0, -1);
606
- }
607
- return newText;
608
- }
609
- function createInstructionForCall(callExpr, persistedVariables) {
610
- const identifier = callExpr.getExpression();
611
- let functionName;
612
- let isContextCall = false;
613
- if (Node.isPropertyAccessExpression(identifier)) {
614
- const expr = identifier.getExpression();
615
- if (expr.getText() === "context") {
616
- isContextCall = true;
617
- }
618
- functionName = identifier.getName();
619
- } else {
620
- functionName = identifier.getText();
621
- }
622
- const args = callExpr.getArguments().map((arg) => rewriteNode(arg, persistedVariables)).join(", ");
623
- if (isContextCall) {
624
- if (functionName === "bSleep") {
625
- return `{ type: 'SCHEDULE_SLEEP', duration: ${args} }`;
626
- }
627
- if (functionName === "bWaitForEvent") {
628
- return `{ type: 'WAIT_FOR_EVENT', eventName: ${args} }`;
629
- }
630
- if (functionName === "bExecute") {
631
- const [workflowArg, inputArg] = callExpr.getArguments();
632
- const subWorkflowName = workflowArg.getText();
633
- const subWorkflowInput = inputArg ? rewriteNode(inputArg, persistedVariables) : "undefined";
634
- return `{ type: 'EXECUTE_SUBWORKFLOW', workflowName: ${subWorkflowName}.name, input: ${subWorkflowInput} }`;
635
- }
636
- throw new Error(`Funci\xF3n de contexto durable desconocida: '${functionName}'.`);
637
- }
638
- const symbol = identifier.getSymbol();
639
- if (!symbol) throw new Error(`S\xEDmbolo no encontrado para '${functionName}'.`);
640
- const importSpecifier = symbol.getDeclarations()[0]?.asKind(SyntaxKind.ImportSpecifier);
641
- if (!importSpecifier) throw new Error(`'${functionName}' debe ser importada.`);
642
- const sourceFile = importSpecifier.getImportDeclaration().getModuleSpecifierSourceFileOrThrow();
643
- const relativeSourcePath = path.relative(process.cwd(), sourceFile.getFilePath()).replace(/\\/g, "/");
644
- return `{ type: 'SCHEDULE_TASK', modulePath: '${relativeSourcePath}', exportName: '${functionName}', args: [${args}] }`;
645
- }
646
- function hasDurableCall(node) {
647
- for (const awaitExpr of node.getDescendantsOfKind(SyntaxKind.AwaitExpression)) {
648
- const callExpr = awaitExpr.getExpressionIfKind(SyntaxKind.CallExpression);
649
- if (callExpr) {
650
- const expression = callExpr.getExpression();
651
- if (Node.isPropertyAccessExpression(expression)) {
652
- const propName = expression.getName();
653
- if (expression.getExpression().getText() === "context" && (propName === "bSleep" || propName === "bWaitForEvent" || propName === "bExecute") || expression.getSymbol()?.getDeclarations()[0]?.isKind(SyntaxKind.ImportSpecifier)) {
654
- return true;
655
- }
656
- } else {
657
- if (expression.getSymbol()?.getDeclarations()[0]?.isKind(SyntaxKind.ImportSpecifier)) {
658
- return true;
659
- }
660
- }
661
- }
662
- }
663
- if (Node.isTryStatement(node)) {
664
- if (hasDurableCall(node.getTryBlock())) return true;
665
- if (node.getCatchClause() && hasDurableCall(node.getCatchClause().getBlock()))
666
- return true;
667
- if (node.getFinallyBlock() && hasDurableCall(node.getFinallyBlock())) return true;
668
- }
669
- if (Node.isIfStatement(node)) {
670
- const thenHas = hasDurableCall(node.getThenStatement());
671
- const elseHas = node.getElseStatement() ? hasDurableCall(node.getElseStatement()) : false;
672
- return thenHas || elseHas;
673
- }
674
- if (Node.isBlock(node)) {
675
- return node.getStatements().some(hasDurableCall);
676
- }
677
- return false;
678
- }
679
- function splitAtNextDurableCall(statements) {
680
- for (let i = 0; i < statements.length; i++) {
681
- const statement = statements[i];
682
- if (Node.isReturnStatement(statement) || hasDurableCall(statement) || Node.isTryStatement(statement)) {
683
- return {
684
- syncBlock: statements.slice(0, i),
685
- durableStatement: statement,
686
- nextStatements: statements.slice(i + 1)
687
- };
688
- }
689
- }
690
- return { syncBlock: statements, durableStatement: null, nextStatements: [] };
691
- }
692
-
693
- // src/compiler/cli.ts
694
- var getArg = (name) => {
695
- const argIndex = process.argv.indexOf(name);
696
- if (argIndex !== -1 && process.argv.length > argIndex + 1) {
697
- return process.argv[argIndex + 1];
698
- }
699
- return void 0;
700
- };
701
- async function run() {
702
- const inputDir = getArg("--in");
703
- const outputDir = getArg("--out");
704
- if (!inputDir || !outputDir) {
705
- console.error(
706
- "Uso: b-durable-compiler --in <directorio_entrada> --out <directorio_salida>"
707
- );
708
- process.exit(1);
709
- }
710
- const absInput = path2.resolve(process.cwd(), inputDir);
711
- const absOutput = path2.resolve(process.cwd(), outputDir);
712
- await compileWorkflows({
713
- inputDir: absInput,
714
- outputDir: absOutput,
715
- packageName: "@bobtail.software/b-durable"
716
- });
717
- }
718
- run().catch((error) => {
719
- console.error("Error durante la compilaci\xF3n:", error);
720
- process.exit(1);
721
- });
58
+ `,A=u.clauses.pop()||"",D=c?m:y;if(u.clauses.push(A.replace(/return { type: 'COMPLETE'.* };/,`context.step = ${D}; break;`)),r){if(g){let S=r.clauses[0]||`case ${l}: {}`;r.clauses[0]=S.replace("{",`{
59
+ const ${g} = result as any;`)}let w=r.clauses.pop()||"";r.clauses.push(w.replace(/return { type: 'COMPLETE'.* };/,`context.step = ${D}; break;`))}if(d){let w=d.clauses.pop()||"";d.clauses.push(w.replace(/return { type: 'COMPLETE'.* };/,`state.tryCatchStack?.pop(); context.step = ${y}; break;`))}return{clauses:[N,...u.clauses,...r?r.clauses:[],...d?d.clauses:[],...x.clauses],nextStep:x.nextStep}}function ne(e,t,s){let n=[],o=new Map,i=oe(t),f=new Map(s);for(let a of e){let c=!1;if(p.isVariableStatement(a))for(let u of a.getDeclarations()){let r=u.getInitializer();if(!r)continue;let g=se(u),l=g.filter(d=>i.has(d.name));if(l.length>0){let d=I(r,s);for(let{name:m,type:y}of l){o.set(m,{type:y}),f.set(m,{type:y});let x=g.length>1?`${d}.${m}`:d;n.push(`state.${m} = ${x};`)}l.length===g.length&&(c=!0)}}c||n.push(I(a,f))}return{rewrittenSyncStatements:n,newlyPersistedVariables:o}}function se(e){let t=e.getNameNode(),s=[];if(p.isIdentifier(t)){let n=e.getType().getText(e,F);s.push({name:t.getText(),type:n})}else if(p.isObjectBindingPattern(t))for(let n of t.getElements()){let o=n.getName(),i=n.getType().getText(n,F);s.push({name:o,type:i})}return s}function re(e,t){if(p.isReturnStatement(e))return{instruction:`return { type: 'COMPLETE', result: ${e.getExpression()?I(e.getExpressionOrThrow(),t):"undefined"} };`,nextPendingStateAssignment:void 0};let s,n=e.getFirstDescendantByKind(b.VariableDeclaration);if(n){let i=n.getName(),f=n.getType().getText(n,F);t.set(i,{type:f}),s=`state.${i} = result;`}let o=e.getFirstDescendantByKind(b.AwaitExpression);if(o){let i=o.getExpression();if(p.isCallExpression(i))return{instruction:`return ${ae(i,t)};`,nextPendingStateAssignment:s}}return{instruction:I(e,t),nextPendingStateAssignment:s}}function oe(e){let t=new Set;for(let s of e)s.getDescendantsOfKind(b.Identifier).forEach(n=>{t.add(n.getText())});return t}function I(e,t){let s=e.getProject().createSourceFile(`temp_rewrite_${Math.random()}.ts`,`const temp = ${e.getText()};`,{overwrite:!0}),n=s.getVariableDeclarationOrThrow("temp").getInitializerOrThrow(),o=[n,...n.getDescendants()].reverse();for(let c of o)if(p.isIdentifier(c)&&!c.wasForgotten()&&t.has(c.getText())){let u=c.getText(),r=c.getParent(),g=p.isVariableDeclaration(r)&&r.getNameNode()===c,l=p.isPropertyAccessExpression(r)&&r.getNameNode()===c||p.isPropertyAssignment(r)&&r.getNameNode()===c,d=p.isBindingElement(r)&&r.getNameNode()===c;if(!g&&!l&&!d){let m=t.get(u);c.replaceWithText(`(state.${u} as ${m.type})`)}}let i=s.getFullText().trim();s.forget();let f="const temp = ",a=i;return a.startsWith(f)&&(a=a.substring(f.length)),a.endsWith(";")&&(a=a.slice(0,-1)),a}function ae(e,t){let s=e.getExpression(),n,o=!1;p.isPropertyAccessExpression(s)?(s.getExpression().getText()==="context"&&(o=!0),n=s.getName()):n=s.getText();let i=e.getArguments().map(r=>I(r,t)).join(", ");if(o)switch(n){case"bSleep":return`{ type: 'SCHEDULE_SLEEP', duration: ${i} }`;case"bWaitForEvent":return`{ type: 'WAIT_FOR_EVENT', eventName: ${i} }`;case"bExecute":{let[r,g]=e.getArguments(),l=r.getText(),d=g?I(g,t):"undefined";return`{ type: 'EXECUTE_SUBWORKFLOW', workflowName: ${l}.name, input: ${d} }`}case"bSignal":{let[r,g]=e.getArguments().map(l=>I(l,t));return`{ type: 'SEND_SIGNAL', signalName: ${r}, payload: ${g} }`}default:throw new Error(`Funci\xF3n de contexto durable desconocida: '${n}'.`)}let f=s.getSymbol();if(!f)throw new Error(`S\xEDmbolo no encontrado para '${n}'.`);let a=f.getDeclarations()[0]?.asKind(b.ImportSpecifier);if(!a)throw new Error(`'${n}' debe ser importada.`);let c=a.getImportDeclaration().getModuleSpecifierSourceFileOrThrow();return`{ type: 'SCHEDULE_TASK', modulePath: '${h.relative(process.cwd(),c.getFilePath()).replace(/\\/g,"/")}', exportName: '${n}', args: [${i}] }`}function C(e){for(let t of e.getDescendantsOfKind(b.AwaitExpression)){let s=t.getExpressionIfKind(b.CallExpression);if(s){let n=s.getExpression();if(p.isPropertyAccessExpression(n)){let o=n.getName();if(n.getExpression().getText()==="context"&&(o==="bSleep"||o==="bWaitForEvent"||o==="bExecute"||o==="bSignal")||n.getSymbol()?.getDeclarations()[0]?.isKind(b.ImportSpecifier))return!0}else if(n.getSymbol()?.getDeclarations()[0]?.isKind(b.ImportSpecifier))return!0}}if(p.isTryStatement(e)&&(C(e.getTryBlock())||e.getCatchClause()&&C(e.getCatchClause().getBlock())||e.getFinallyBlock()&&C(e.getFinallyBlock())))return!0;if(p.isIfStatement(e)){let t=C(e.getThenStatement()),s=e.getElseStatement()?C(e.getElseStatement()):!1;return t||s}return p.isBlock(e)?e.getStatements().some(C):!1}function ie(e){for(let t=0;t<e.length;t++){let s=e[t];if(p.isReturnStatement(s)||C(s)||p.isTryStatement(s))return{syncBlock:e.slice(0,t),durableStatement:s,nextStatements:e.slice(t+1)}}return{syncBlock:e,durableStatement:null,nextStatements:[]}}var U=e=>{let t=process.argv.indexOf(e);if(t!==-1&&process.argv.length>t+1)return process.argv[t+1]};async function ce(){let e=U("--in"),t=U("--out");(!e||!t)&&(console.error("Uso: b-durable-compiler --in <directorio_entrada> --out <directorio_salida>"),process.exit(1));let s=z.resolve(process.cwd(),e),n=z.resolve(process.cwd(),t);await _({inputDir:s,outputDir:n,packageName:"@bobtail.software/b-durable"})}ce().catch(e=>{console.error("Error durante la compilaci\xF3n:",e),process.exit(1)});