@deepagents/text2sql 7.42.4 → 7.43.0

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/bin/sql.js CHANGED
@@ -620,24 +620,23 @@ var IndexCommand = class extends SqlCommand {
620
620
  explicitEventsPath,
621
621
  ctx.stderr
622
622
  );
623
- try {
624
- const fragments = await ctx.text2Sql.index({
625
- names,
626
- onProgress: createProgressHandler(eventsStream, verbose, ctx.stderr)
627
- });
628
- await writeFile(fragmentsPath, JSON.stringify(fragments, null, 2));
629
- const manifest = {
630
- fragmentsPath,
631
- eventsPath,
632
- adapters: names
633
- };
634
- ctx.stdout.write(JSON.stringify(manifest, null, 2) + "\n");
635
- return 0;
636
- } finally {
623
+ await using events = new AsyncDisposableStack();
624
+ events.defer(async () => {
637
625
  eventsStream.end();
638
- await finished(eventsStream).catch(() => {
639
- });
640
- }
626
+ await finished(eventsStream);
627
+ });
628
+ const fragments = await ctx.text2Sql.index({
629
+ names,
630
+ onProgress: createProgressHandler(eventsStream, verbose, ctx.stderr)
631
+ });
632
+ await writeFile(fragmentsPath, JSON.stringify(fragments, null, 2));
633
+ const manifest = {
634
+ fragmentsPath,
635
+ eventsPath,
636
+ adapters: names
637
+ };
638
+ ctx.stdout.write(JSON.stringify(manifest, null, 2) + "\n");
639
+ return 0;
641
640
  } catch (error) {
642
641
  this.fail(errorMessage2(error));
643
642
  }
@@ -677,6 +676,8 @@ function resolveExplicitEventsPath(ctx) {
677
676
  }
678
677
  async function openEventsWriter(eventsPath, explicitEventsPath, stderr) {
679
678
  const probe = explicitEventsPath ? await probeFifoWriter(explicitEventsPath, stderr) : null;
679
+ await using cleanup = new AsyncDisposableStack();
680
+ if (probe) cleanup.defer(() => probe.close());
680
681
  const stream = createWriteStream(eventsPath, {
681
682
  flags: "a",
682
683
  encoding: "utf-8"
@@ -687,9 +688,6 @@ async function openEventsWriter(eventsPath, explicitEventsPath, stderr) {
687
688
  } catch (err) {
688
689
  stream.destroy();
689
690
  throw err;
690
- } finally {
691
- await probe?.close().catch(() => {
692
- });
693
691
  }
694
692
  }
695
693
  async function probeFifoWriter(eventsPath, stderr) {
package/dist/index.js CHANGED
@@ -2287,32 +2287,25 @@ GO
2287
2287
  async function withSqlServerSchemaLock(mssql, pool, schema, run) {
2288
2288
  const holder = new mssql.Transaction(pool);
2289
2289
  await holder.begin();
2290
- let result;
2291
- try {
2292
- const lock = new mssql.Request(holder);
2293
- lock.input(
2294
- "resource",
2295
- mssql.NVarChar(255),
2296
- `deepagents:schema-ddl:${schema}`
2297
- );
2298
- const { recordset } = await lock.query(`
2290
+ await using transaction2 = new AsyncDisposableStack();
2291
+ transaction2.defer(() => holder.rollback());
2292
+ const lock = new mssql.Request(holder);
2293
+ lock.input(
2294
+ "resource",
2295
+ mssql.NVarChar(255),
2296
+ `deepagents:schema-ddl:${schema}`
2297
+ );
2298
+ const { recordset } = await lock.query(`
2299
2299
  DECLARE @status int;
2300
2300
  EXEC @status = sp_getapplock @Resource = @resource, @LockMode = 'Exclusive', @LockOwner = 'Transaction', @LockTimeout = -1;
2301
2301
  SELECT @status AS status;
2302
2302
  `);
2303
- if (recordset[0].status < 0) {
2304
- throw new Error(
2305
- `Could not lock the DDL of schema "${schema}": sp_getapplock returned ${recordset[0].status}.`
2306
- );
2307
- }
2308
- result = await run();
2309
- } catch (error) {
2310
- await holder.rollback().catch(() => {
2311
- });
2312
- throw error;
2303
+ if (recordset[0].status < 0) {
2304
+ throw new Error(
2305
+ `Could not lock the DDL of schema "${schema}": sp_getapplock returned ${recordset[0].status}.`
2306
+ );
2313
2307
  }
2314
- await holder.rollback();
2315
- return result;
2308
+ return await run();
2316
2309
  }
2317
2310
 
2318
2311
  // packages/text2sql/src/lib/fs/mssql/mssql-fs.ts