@fachkraftfreund/n8n-nodes-supabase 1.3.2 → 1.3.3

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.
@@ -2,6 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SupabaseCsvExport = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
+ const fs_1 = require("fs");
6
+ const os_1 = require("os");
7
+ const path_1 = require("path");
8
+ const crypto_1 = require("crypto");
5
9
  const supabaseClient_1 = require("./utils/supabaseClient");
6
10
  const supabaseClient_2 = require("./utils/supabaseClient");
7
11
  function escapeRegExp(s) {
@@ -28,7 +32,7 @@ function discoverHeaders(rows) {
28
32
  }
29
33
  return [...set];
30
34
  }
31
- function batchToCsvBuffer(rows, headers, delimiter, quoteChar) {
35
+ function batchToCsvLines(rows, headers, delimiter, quoteChar) {
32
36
  const lines = new Array(rows.length);
33
37
  for (let i = 0; i < rows.length; i++) {
34
38
  const row = rows[i];
@@ -36,7 +40,19 @@ function batchToCsvBuffer(rows, headers, delimiter, quoteChar) {
36
40
  .map((h) => escapeCsvField(row[h], delimiter, quoteChar))
37
41
  .join(delimiter);
38
42
  }
39
- return Buffer.from(lines.join('\n'), 'utf-8');
43
+ return lines.join('\n') + '\n';
44
+ }
45
+ function streamWrite(stream, data) {
46
+ return new Promise((resolve, reject) => {
47
+ const ok = stream.write(data, 'utf-8');
48
+ if (ok) {
49
+ resolve();
50
+ }
51
+ else {
52
+ stream.once('drain', resolve);
53
+ stream.once('error', reject);
54
+ }
55
+ });
40
56
  }
41
57
  function buildSelectQuery(supabase, table, selectFields, filters, sort) {
42
58
  let query = supabase.from(table).select(selectFields);
@@ -580,7 +596,8 @@ class SupabaseCsvExport {
580
596
  selectWithJoins += `,${hint}(${cols})`;
581
597
  }
582
598
  const { delimiter, quoteChar } = csvOptions;
583
- const csvChunks = [];
599
+ const tmpPath = (0, path_1.join)((0, os_1.tmpdir)(), `n8n-csv-${(0, crypto_1.randomBytes)(8).toString('hex')}.csv`);
600
+ const fileStream = (0, fs_1.createWriteStream)(tmpPath, { encoding: 'utf-8' });
584
601
  const ids = [];
585
602
  let rowCount = 0;
586
603
  let headers = null;
@@ -626,25 +643,37 @@ class SupabaseCsvExport {
626
643
  if (csvOptions.includeHeaders) {
627
644
  const headerLine = headers
628
645
  .map((h) => escapeCsvField(h, delimiter, quoteChar))
629
- .join(delimiter);
630
- csvChunks.push(Buffer.from(headerLine + '\n', 'utf-8'));
646
+ .join(delimiter) + '\n';
647
+ await streamWrite(fileStream, headerLine);
631
648
  }
632
649
  }
633
650
  for (const row of rows) {
634
651
  if (row[idColumn] != null)
635
652
  ids.push(row[idColumn]);
636
653
  }
637
- const buf = batchToCsvBuffer(rows, headers, delimiter, quoteChar);
638
- csvChunks.push(buf);
639
- csvChunks.push(Buffer.from('\n', 'utf-8'));
654
+ await streamWrite(fileStream, batchToCsvLines(rows, headers, delimiter, quoteChar));
640
655
  rowCount += rows.length;
641
656
  }
642
- if (csvChunks.length > 0) {
643
- const last = csvChunks[csvChunks.length - 1];
644
- if (last.length === 1 && last[0] === 0x0a) {
645
- csvChunks.pop();
646
- }
647
- }
657
+ await new Promise((resolve, reject) => {
658
+ fileStream.end(() => resolve());
659
+ fileStream.on('error', reject);
660
+ });
661
+ console.log(`[Supabase CSV] wrote ${rowCount} rows to temp file, passing to n8n binary storage`);
662
+ const readStream = (0, fs_1.createReadStream)(tmpPath);
663
+ const binaryData = await this.helpers.prepareBinaryData(readStream, csvOptions.fileName, 'text/csv');
664
+ return [[
665
+ {
666
+ json: {
667
+ table,
668
+ rowCount,
669
+ ids,
670
+ fileName: csvOptions.fileName,
671
+ },
672
+ binary: {
673
+ data: binaryData,
674
+ },
675
+ },
676
+ ]];
648
677
  }
649
678
  catch (error) {
650
679
  const msg = error instanceof Error ? error.message : 'Unknown error';
@@ -652,22 +681,16 @@ class SupabaseCsvExport {
652
681
  throw error;
653
682
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Export failed: ${msg}`);
654
683
  }
655
- const csvBuffer = Buffer.concat(csvChunks);
656
- csvChunks.length = 0;
657
- const binaryData = await this.helpers.prepareBinaryData(csvBuffer, csvOptions.fileName, 'text/csv');
658
- return [[
659
- {
660
- json: {
661
- table,
662
- rowCount,
663
- ids,
664
- fileName: csvOptions.fileName,
665
- },
666
- binary: {
667
- data: binaryData,
668
- },
669
- },
670
- ]];
684
+ finally {
685
+ try {
686
+ fileStream.destroy();
687
+ }
688
+ catch { }
689
+ try {
690
+ (0, fs_1.unlinkSync)(tmpPath);
691
+ }
692
+ catch { }
693
+ }
671
694
  }
672
695
  }
673
696
  exports.SupabaseCsvExport = SupabaseCsvExport;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fachkraftfreund/n8n-nodes-supabase",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Comprehensive n8n community node for Supabase with database and storage operations",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",