@d0whc3r/node-s3 1.4.1 → 1.5.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/s3.es.mjs CHANGED
@@ -5,26 +5,28 @@ import d from "node:os";
5
5
  import f from "node:path";
6
6
  import { pipeline as p } from "node:stream/promises";
7
7
  import { Upload as m } from "@aws-sdk/lib-storage";
8
- import { ZipArchive as h } from "archiver";
9
- import g from "dayjs";
10
- import _ from "mime-types";
11
- import v from "mysqldump";
12
- import y from "node:crypto";
13
- import { Transform as b } from "node:stream";
8
+ import { ZipArchive as ee } from "archiver";
9
+ import h from "dayjs";
10
+ import te from "mime-types";
11
+ import g from "mysqldump";
12
+ import _ from "node:crypto";
13
+ import { PassThrough as v, Transform as y } from "node:stream";
14
+ import { spawn as b } from "node:child_process";
15
+ import { DatabaseSync as ne, backup as x } from "node:sqlite";
14
16
  // src/config.ts
15
- function x(e, t) {
17
+ function S(e, t) {
16
18
  return e === void 0 || e.trim() === "" ? t : [
17
19
  "true",
18
20
  "1",
19
21
  "yes"
20
22
  ].includes(e.trim().toLowerCase());
21
23
  }
22
- function S(e, t) {
24
+ function C(e, t) {
23
25
  if (e === void 0 || e.trim() === "") return t;
24
26
  let n = Number(e);
25
27
  return Number.isNaN(n) ? t : n;
26
28
  }
27
- var C = class {
29
+ var w = class {
28
30
  static API_VERSION = "2006-03-01";
29
31
  static TAG = "[node-s3]";
30
32
  static overrides = {};
@@ -68,19 +70,19 @@ var C = class {
68
70
  this.overrides.SESSION_TOKEN = e;
69
71
  }
70
72
  static get MAX_RETRIES() {
71
- return "MAX_RETRIES" in this.overrides ? this.overrides.MAX_RETRIES : S(process.env.MAX_RETRIES, 3);
73
+ return "MAX_RETRIES" in this.overrides ? this.overrides.MAX_RETRIES : C(process.env.MAX_RETRIES, 3);
72
74
  }
73
75
  static set MAX_RETRIES(e) {
74
76
  this.overrides.MAX_RETRIES = e;
75
77
  }
76
78
  static get FORCE_PATH_STYLE() {
77
- return "FORCE_PATH_STYLE" in this.overrides ? this.overrides.FORCE_PATH_STYLE : x(process.env.FORCE_PATH_STYLE, !0);
79
+ return "FORCE_PATH_STYLE" in this.overrides ? this.overrides.FORCE_PATH_STYLE : S(process.env.FORCE_PATH_STYLE, !0);
78
80
  }
79
81
  static set FORCE_PATH_STYLE(e) {
80
82
  this.overrides.FORCE_PATH_STYLE = e;
81
83
  }
82
84
  static get SSL_ENABLED() {
83
- return "SSL_ENABLED" in this.overrides ? this.overrides.SSL_ENABLED : x(process.env.SSL_ENABLED, !0);
85
+ return "SSL_ENABLED" in this.overrides ? this.overrides.SSL_ENABLED : S(process.env.SSL_ENABLED, !0);
84
86
  }
85
87
  static set SSL_ENABLED(e) {
86
88
  this.overrides.SSL_ENABLED = e;
@@ -98,7 +100,7 @@ var C = class {
98
100
  this.overrides.MYSQL_HOST = e;
99
101
  }
100
102
  static get MYSQL_PORT() {
101
- return "MYSQL_PORT" in this.overrides ? this.overrides.MYSQL_PORT : S(process.env.MYSQL_PORT, 3306);
103
+ return "MYSQL_PORT" in this.overrides ? this.overrides.MYSQL_PORT : C(process.env.MYSQL_PORT, 3306);
102
104
  }
103
105
  static set MYSQL_PORT(e) {
104
106
  this.overrides.MYSQL_PORT = e;
@@ -121,21 +123,21 @@ var C = class {
121
123
  static set MYSQL_DATABASE(e) {
122
124
  this.overrides.MYSQL_DATABASE = e;
123
125
  }
124
- }, w = /* @__PURE__ */ new Set([
126
+ }, T = /* @__PURE__ */ new Set([
125
127
  "NotFound",
126
128
  "NoSuchBucket",
127
129
  "NoSuchKey",
128
130
  "404"
129
131
  ]);
130
- function T(e) {
132
+ function E(e) {
131
133
  if (!e || typeof e != "object") return !1;
132
134
  let t = e;
133
- return t.$metadata?.httpStatusCode === 404 || !!(t.name && w.has(t.name) || t.Code && w.has(t.Code));
135
+ return t.$metadata?.httpStatusCode === 404 || !!(t.name && T.has(t.name) || t.Code && T.has(t.Code));
134
136
  }
135
- function E(e, t) {
136
- return e instanceof Error ? Error(`${C.TAG} ${t}: ${e.message}`, { cause: e }) : Error(`${C.TAG} ${t}: ${String(e)}`, { cause: e });
137
+ function D(e, t) {
138
+ return e instanceof Error ? Error(`${w.TAG} ${t}: ${e.message}`, { cause: e }) : Error(`${w.TAG} ${t}: ${String(e)}`, { cause: e });
137
139
  }
138
- var D = class {
140
+ var re = class {
139
141
  s3Sdk;
140
142
  deleteAllContentFn;
141
143
  constructor(e, t) {
@@ -145,14 +147,14 @@ var D = class {
145
147
  try {
146
148
  return (await this.s3Sdk.send(new o({}))).Buckets || [];
147
149
  } catch (e) {
148
- throw E(e, "Failed to list buckets");
150
+ throw D(e, "Failed to list buckets");
149
151
  }
150
152
  }
151
153
  async createBucket(t) {
152
154
  try {
153
155
  return await this.s3Sdk.send(new e({ Bucket: t }));
154
156
  } catch (e) {
155
- throw E(e, `Failed to create bucket "${t}"`);
157
+ throw D(e, `Failed to create bucket "${t}"`);
156
158
  }
157
159
  }
158
160
  async removeBucket(e, n = !1) {
@@ -160,31 +162,31 @@ var D = class {
160
162
  return await this.s3Sdk.send(new t({ Bucket: e })), !0;
161
163
  } catch (t) {
162
164
  if (n && this.deleteAllContentFn) return await this.deleteAllContentFn(e), this.removeBucket(e, !1);
163
- throw E(t, `Failed to remove bucket "${e}"`);
165
+ throw D(t, `Failed to remove bucket "${e}"`);
164
166
  }
165
167
  }
166
168
  async bucketExist(e) {
167
169
  try {
168
170
  return await this.s3Sdk.send(new i({ Bucket: e })), !0;
169
171
  } catch (t) {
170
- if (T(t)) return !1;
171
- throw E(t, `Failed to check bucket "${e}"`);
172
+ if (E(t)) return !1;
173
+ throw D(t, `Failed to check bucket "${e}"`);
172
174
  }
173
175
  }
174
176
  }, O = Buffer.from("NS3E", "ascii"), k = 1, A = 16, j = 12, M = 32, N = 16, P = O.length + 1 + A + j;
175
177
  function F(e) {
176
- if (!e) throw Error(`${C.TAG} Encryption key must be a non-empty string`);
178
+ if (!e) throw Error(`${w.TAG} Encryption key must be a non-empty string`);
177
179
  let t = null, n = (n) => {
178
- let i = y.randomBytes(A), a = y.randomBytes(j);
179
- y.scrypt(e, i, M, (e, o) => {
180
- e ? n(e) : (t = y.createCipheriv("aes-256-gcm", o, a), r.push(Buffer.concat([
180
+ let i = _.randomBytes(A), a = _.randomBytes(j);
181
+ _.scrypt(e, i, M, (e, o) => {
182
+ e ? n(e) : (t = _.createCipheriv("aes-256-gcm", o, a), r.push(Buffer.concat([
181
183
  O,
182
184
  Buffer.from([k]),
183
185
  i,
184
186
  a
185
187
  ])), n());
186
188
  });
187
- }, r = new b({
189
+ }, r = new y({
188
190
  transform(e, r, i) {
189
191
  let a = () => {
190
192
  try {
@@ -215,9 +217,9 @@ function F(e) {
215
217
  return r;
216
218
  }
217
219
  function I(e) {
218
- if (!e) throw Error(`${C.TAG} Decryption key must be a non-empty string`);
220
+ if (!e) throw Error(`${w.TAG} Decryption key must be a non-empty string`);
219
221
  let t = Buffer.alloc(0), n = Buffer.alloc(0), r = null;
220
- return new b({
222
+ return new y({
221
223
  transform(i, a, o) {
222
224
  let s = (e) => {
223
225
  try {
@@ -242,34 +244,34 @@ function I(e) {
242
244
  return;
243
245
  }
244
246
  if (!t.subarray(0, O.length).equals(O)) {
245
- o(/* @__PURE__ */ Error(`${C.TAG} Invalid encrypted stream header`));
247
+ o(/* @__PURE__ */ Error(`${w.TAG} Invalid encrypted stream header`));
246
248
  return;
247
249
  }
248
250
  let c = t[O.length];
249
251
  if (c !== k) {
250
- o(/* @__PURE__ */ Error(`${C.TAG} Unsupported encryption format version: ${c}`));
252
+ o(/* @__PURE__ */ Error(`${w.TAG} Unsupported encryption format version: ${c}`));
251
253
  return;
252
254
  }
253
255
  let l = O.length + 1, u = l + A, d = t.subarray(l, u), f = t.subarray(u, P), p = t.subarray(P);
254
- t = Buffer.alloc(0), y.scrypt(e, d, M, (e, t) => {
255
- e ? o(e) : (r = y.createDecipheriv("aes-256-gcm", t, f), s(p));
256
+ t = Buffer.alloc(0), _.scrypt(e, d, M, (e, t) => {
257
+ e ? o(e) : (r = _.createDecipheriv("aes-256-gcm", t, f), s(p));
256
258
  });
257
259
  },
258
260
  flush(e) {
259
- if (!r) e(/* @__PURE__ */ Error(`${C.TAG} Encrypted stream is truncated or empty`));
260
- else if (n.length !== N) e(/* @__PURE__ */ Error(`${C.TAG} Encrypted stream is missing authentication tag`));
261
+ if (!r) e(/* @__PURE__ */ Error(`${w.TAG} Encrypted stream is truncated or empty`));
262
+ else if (n.length !== N) e(/* @__PURE__ */ Error(`${w.TAG} Encrypted stream is missing authentication tag`));
261
263
  else try {
262
264
  r.setAuthTag(n);
263
265
  let t = r.final();
264
266
  t.length > 0 && this.push(t), e();
265
267
  } catch (t) {
266
- e(Error(`${C.TAG} Decryption failed: invalid key or corrupted data`, { cause: t }));
268
+ e(Error(`${w.TAG} Decryption failed: invalid key or corrupted data`, { cause: t }));
267
269
  }
268
270
  }
269
271
  });
270
272
  }
271
273
  // src/s3/files.ts
272
- var L = /^(\d+)([a-zA-Z]+)$/, R = {
274
+ var ie = /^(\d+)([a-zA-Z]+)$/, ae = {
273
275
  s: "second",
274
276
  second: "second",
275
277
  seconds: "second",
@@ -291,36 +293,36 @@ var L = /^(\d+)([a-zA-Z]+)$/, R = {
291
293
  y: "year",
292
294
  year: "year",
293
295
  years: "year"
294
- }, z = 1e3, B = 4, V = 6;
295
- function H(...e) {
296
+ }, L = 1e3, oe = 4, se = 6;
297
+ function R(...e) {
296
298
  let t = [];
297
299
  for (let n of e) {
298
300
  if (!n) continue;
299
301
  let e = n.replaceAll("\\", "/");
300
302
  for (let r of e.split("/")) if (r && r !== ".") {
301
- if (r === "..") throw Error(`${C.TAG} Invalid S3 key segment ".." in "${n}"`);
303
+ if (r === "..") throw Error(`${w.TAG} Invalid S3 key segment ".." in "${n}"`);
302
304
  t.push(r);
303
305
  }
304
306
  }
305
307
  return f.posix.join(...t);
306
308
  }
307
- function U(e) {
309
+ function ce(e) {
308
310
  if (!e) return;
309
- let t = H(e);
311
+ let t = R(e);
310
312
  return t ? `${t}/` : void 0;
311
313
  }
312
- function W(e) {
314
+ function le(e) {
313
315
  let t = e.search(/[*?[{]/);
314
316
  if (t === -1) return e;
315
317
  let n = e.slice(0, t);
316
318
  return n ? n.endsWith("/") || n.endsWith("\\") ? n.slice(0, -1) || "." : f.dirname(n) : ".";
317
319
  }
318
- function G(e, t) {
320
+ function z(e, t) {
319
321
  if (!t.length) return !1;
320
322
  let n = e.replaceAll("\\", "/"), r = f.posix.basename(n);
321
323
  return t.some((e) => f.matchesGlob(n, e) || f.matchesGlob(r, e));
322
324
  }
323
- async function K(e, t, n) {
325
+ async function B(e, t, n) {
324
326
  let r = Array.from({ length: e.length }), i = Math.max(1, Math.min(t, e.length)), a = 0, o = async () => {
325
327
  if (a >= e.length) return;
326
328
  let t = a;
@@ -328,7 +330,7 @@ async function K(e, t, n) {
328
330
  };
329
331
  return await Promise.all(Array.from({ length: i }, () => o())), r;
330
332
  }
331
- var q = class {
333
+ var V = class {
332
334
  s3Sdk;
333
335
  defaultUploadOptions = {
334
336
  create: !0,
@@ -342,7 +344,7 @@ var q = class {
342
344
  this.s3Sdk = e, this.ensureBucketFn = t.ensureBucket, this.logger = t.logger ?? console, this.defaultDryRun = t.dryRun ?? !1, this.defaultOnProgress = t.onProgress;
343
345
  }
344
346
  async getFiles(e, t) {
345
- let n = t ? U(t) : void 0, r = [], i = async (t) => {
347
+ let n = t ? ce(t) : void 0, r = [], i = async (t) => {
346
348
  let a = await this.s3Sdk.send(new s({
347
349
  Bucket: e,
348
350
  ...n ? { Prefix: n } : {},
@@ -353,30 +355,30 @@ var q = class {
353
355
  try {
354
356
  return await i(), r;
355
357
  } catch (t) {
356
- throw E(t, `Failed to list files in bucket "${e}"`);
358
+ throw D(t, `Failed to list files in bucket "${e}"`);
357
359
  }
358
360
  }
359
361
  async fileInfo(e, t) {
360
- let n = H(t);
362
+ let n = R(t);
361
363
  try {
362
364
  return await this.s3Sdk.send(new a({
363
365
  Bucket: e,
364
366
  Key: n
365
367
  }));
366
368
  } catch (t) {
367
- throw E(t, `Failed to get info for "${n}" in bucket "${e}"`);
369
+ throw D(t, `Failed to get info for "${n}" in bucket "${e}"`);
368
370
  }
369
371
  }
370
372
  async fileExist(e, t) {
371
- let n = H(t);
373
+ let n = R(t);
372
374
  try {
373
375
  return await this.s3Sdk.send(new a({
374
376
  Bucket: e,
375
377
  Key: n
376
378
  })), !0;
377
379
  } catch (t) {
378
- if (T(t)) return !1;
379
- throw E(t, `Failed to check existence of "${n}" in bucket "${e}"`);
380
+ if (E(t)) return !1;
381
+ throw D(t, `Failed to check existence of "${n}" in bucket "${e}"`);
380
382
  }
381
383
  }
382
384
  async deleteAllContent(e) {
@@ -384,11 +386,11 @@ var q = class {
384
386
  return this.deleteFiles(e, t);
385
387
  }
386
388
  async uploadFile(e, t, n, r) {
387
- let i = f.basename(t), a = H(n, i), o = {
389
+ let i = f.basename(t), a = R(n, i), o = {
388
390
  ...this.defaultUploadOptions,
389
391
  ...r
390
392
  };
391
- if (o.dryRun ?? this.defaultDryRun) return this.logger.info?.(`${C.TAG} [dry-run] Would upload "${t}" to "s3://${e}/${a}"`), {
393
+ if (o.dryRun ?? this.defaultDryRun) return this.logger.info?.(`${w.TAG} [dry-run] Would upload "${t}" to "s3://${e}/${a}"`), {
392
394
  Bucket: e,
393
395
  Key: a,
394
396
  $metadata: {}
@@ -402,18 +404,18 @@ var q = class {
402
404
  }
403
405
  async uploadStream(e, t, n, r, i) {
404
406
  let a = f.basename(n);
405
- if (!a || a === "." || a === "..") throw Error(`${C.TAG} Invalid upload filename: "${n}"`);
406
- let o = H(r, a), s = _.contentType(a) || void 0, c = {
407
+ if (!a || a === "." || a === "..") throw Error(`${w.TAG} Invalid upload filename: "${n}"`);
408
+ let o = R(r, a), s = te.contentType(a) || void 0, c = {
407
409
  ...this.defaultUploadOptions,
408
410
  ...i
409
411
  };
410
- if (c.dryRun ?? this.defaultDryRun) return this.logger.info?.(`${C.TAG} [dry-run] Would upload stream "${a}" to "s3://${e}/${o}"`), {
412
+ if (c.dryRun ?? this.defaultDryRun) return this.logger.info?.(`${w.TAG} [dry-run] Would upload stream "${a}" to "s3://${e}/${o}"`), {
411
413
  Bucket: e,
412
414
  Key: o,
413
415
  $metadata: {}
414
416
  };
415
417
  let l = this.getExpire(c);
416
- if (c.skipBucketCheck || await this.createIfNeeded(c, e), !await this.canBeReplaced(c, e, o)) throw Error(`${C.TAG} File "${o}" already exists in bucket "${e}" and will not be replaced`);
418
+ if (c.skipBucketCheck || await this.createIfNeeded(c, e), !await this.canBeReplaced(c, e, o)) throw Error(`${w.TAG} File "${o}" already exists in bucket "${e}" and will not be replaced`);
417
419
  let u = t, d;
418
420
  if (c.encryptKey) {
419
421
  let e = F(c.encryptKey);
@@ -446,7 +448,7 @@ var q = class {
446
448
  });
447
449
  }), await t.done();
448
450
  } catch (t) {
449
- throw E(t, `Failed to upload "${o}" to bucket "${e}"`);
451
+ throw D(t, `Failed to upload "${o}" to bucket "${e}"`);
450
452
  } finally {
451
453
  d?.destroy();
452
454
  }
@@ -474,7 +476,7 @@ var q = class {
474
476
  skipBucketCheck: !0
475
477
  };
476
478
  if (a.compress) {
477
- let t = typeof a.compress == "string" ? a.compress : `zipped_${g().format("YYYY-MM-DD.HHmmss")}.zip`, { filePath: r, tmpDir: o } = await this.compressFiles(i, t, {
479
+ let t = typeof a.compress == "string" ? a.compress : `zipped_${h().format("YYYY-MM-DD.HHmmss")}.zip`, { filePath: r, tmpDir: o } = await this.compressFiles(i, t, {
478
480
  compressionLevel: a.compressionLevel,
479
481
  followSymlinks: c,
480
482
  exclude: s
@@ -489,7 +491,7 @@ var q = class {
489
491
  });
490
492
  }
491
493
  }
492
- let d = await this.collectUploadTasks(i, n, a.baseDir, c, s), f = a.concurrency ?? B, p = {}, m = await K(d, f, async (t) => {
494
+ let d = await this.collectUploadTasks(i, n, a.baseDir, c, s), f = a.concurrency ?? oe, p = {}, m = await B(d, f, async (t) => {
493
495
  let n = await this.uploadFile(e, t.file, t.folderName, l);
494
496
  return {
495
497
  file: t.file,
@@ -500,13 +502,13 @@ var q = class {
500
502
  return p;
501
503
  }
502
504
  async downloadFile(e, t, n, i = {}) {
503
- let a = H(t);
505
+ let a = R(t);
504
506
  try {
505
507
  let t = await this.s3Sdk.send(new r({
506
508
  Bucket: e,
507
509
  Key: a
508
510
  }));
509
- if (!t.Body) throw Error(`${C.TAG} Empty response body for "${a}"`);
511
+ if (!t.Body) throw Error(`${w.TAG} Empty response body for "${a}"`);
510
512
  await u.mkdir(f.dirname(f.resolve(n)), { recursive: !0 });
511
513
  let o = t.Body, s = l.createWriteStream(n);
512
514
  if (i.decryptKey) {
@@ -515,15 +517,15 @@ var q = class {
515
517
  } else await p(o, s);
516
518
  return n;
517
519
  } catch (t) {
518
- throw E(t, `Failed to download "${a}" from bucket "${e}"`);
520
+ throw D(t, `Failed to download "${a}" from bucket "${e}"`);
519
521
  }
520
522
  }
521
523
  async cleanOlder(e, t, n, r = {}) {
522
- let { value: i, unit: a } = this.getTimeSpace(t), o = g().subtract(i, a), s = (await this.getFiles(e, n)).filter((e) => !!(e.Key && e.LastModified));
524
+ let { value: i, unit: a } = this.getTimeSpace(t), o = h().subtract(i, a), s = (await this.getFiles(e, n)).filter((e) => !!(e.Key && e.LastModified));
523
525
  s.sort((e, t) => (t.LastModified?.getTime() ?? 0) - (e.LastModified?.getTime() ?? 0));
524
- let c = r.keepLast ?? 0, l = (c > 0 ? s.slice(c) : s).filter((e) => g(e.LastModified).isBefore(o)).map((e) => ({ Key: e.Key }));
526
+ let c = r.keepLast ?? 0, l = (c > 0 ? s.slice(c) : s).filter((e) => h(e.LastModified).isBefore(o)).map((e) => ({ Key: e.Key }));
525
527
  if (r.dryRun ?? this.defaultDryRun) {
526
- for (let e of l) e.Key && this.logger.info?.(`${C.TAG} [dry-run] Would delete file: ${e.Key}`);
528
+ for (let e of l) e.Key && this.logger.info?.(`${w.TAG} [dry-run] Would delete file: ${e.Key}`);
527
529
  return {
528
530
  Deleted: l.map((e) => ({ Key: e.Key })),
529
531
  Errors: [],
@@ -533,9 +535,9 @@ var q = class {
533
535
  return this.deleteFiles(e, l);
534
536
  }
535
537
  async createDumpFile() {
536
- let e = C.MYSQL_HOST, t = C.MYSQL_PORT, n = C.MYSQL_USER, r = C.MYSQL_PASSWORD, i = C.MYSQL_DATABASE;
537
- if (!n || !r || !i) throw Error(`${C.TAG} Error in mysql-dump environment variables not defined: $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_HOST, $MYSQL_PORT`);
538
- let { dump: a } = await v({ connection: {
538
+ let e = w.MYSQL_HOST, t = w.MYSQL_PORT, n = w.MYSQL_USER, r = w.MYSQL_PASSWORD, i = w.MYSQL_DATABASE;
539
+ if (!n || !r || !i) throw Error(`${w.TAG} Error in mysql-dump environment variables not defined: $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_HOST, $MYSQL_PORT`);
540
+ let { dump: a } = await g({ connection: {
539
541
  host: e,
540
542
  port: t,
541
543
  user: n,
@@ -543,18 +545,18 @@ var q = class {
543
545
  database: i
544
546
  } }), o = await u.mkdtemp(f.join(d.tmpdir(), "node-s3-dump-"));
545
547
  await u.chmod(o, 448);
546
- let s = f.join(o, `mysqldump-${g().format("YYYY-MM-DD.HHmmss")}.sql`), c = Object.values(a).map((e) => e?.replace(/^# /gm, "-- ")).join("\n\n");
548
+ let s = f.join(o, `mysqldump-${h().format("YYYY-MM-DD.HHmmss")}.sql`), c = Object.values(a).map((e) => e?.replace(/^# /gm, "-- ")).join("\n\n");
547
549
  return await u.writeFile(s, c, { mode: 384 }), s;
548
550
  }
549
551
  async deleteFiles(e, t) {
550
552
  let r = t.filter((e) => !!e.Key);
551
- if (!r.length) return this.logger.info?.(`${C.TAG} No files deleted`), {
553
+ if (!r.length) return this.logger.info?.(`${w.TAG} No files deleted`), {
552
554
  Deleted: [],
553
555
  Errors: [],
554
556
  $metadata: {}
555
557
  };
556
558
  let i = [];
557
- for (let e = 0; e < r.length; e += z) i.push(r.slice(e, e + z));
559
+ for (let e = 0; e < r.length; e += L) i.push(r.slice(e, e + L));
558
560
  let a;
559
561
  try {
560
562
  a = await Promise.all(i.map((t) => {
@@ -565,15 +567,15 @@ var q = class {
565
567
  }));
566
568
  }));
567
569
  } catch (t) {
568
- throw E(t, `Failed to delete files from bucket "${e}"`);
570
+ throw D(t, `Failed to delete files from bucket "${e}"`);
569
571
  }
570
572
  let o = [], s = [], c = {};
571
573
  for (let e of a) c = e.$metadata, this.collectDeleteBatchResults(e, o, s);
572
574
  if (s.length > 0) {
573
575
  let t = s.map((e) => `${e.Key ?? "unknown"} (${e.Code ?? "Error"}: ${e.Message ?? "unknown error"})`).join("; ");
574
- throw Error(`${C.TAG} Failed to delete ${s.length} file(s) from bucket "${e}": ${t}`);
576
+ throw Error(`${w.TAG} Failed to delete ${s.length} file(s) from bucket "${e}": ${t}`);
575
577
  }
576
- return o.length || this.logger.info?.(`${C.TAG} No files deleted`), {
578
+ return o.length || this.logger.info?.(`${w.TAG} No files deleted`), {
577
579
  Deleted: o,
578
580
  Errors: s,
579
581
  $metadata: c
@@ -582,7 +584,7 @@ var q = class {
582
584
  collectDeleteBatchResults(e, t, n) {
583
585
  if (e.Deleted?.length) {
584
586
  t.push(...e.Deleted);
585
- for (let t of e.Deleted) t.Key && this.logger.warn?.(`${C.TAG} Deleted file: ${t.Key}`);
587
+ for (let t of e.Deleted) t.Key && this.logger.warn?.(`${w.TAG} Deleted file: ${t.Key}`);
586
588
  }
587
589
  e.Errors?.length && n.push(...e.Errors);
588
590
  }
@@ -591,16 +593,16 @@ var q = class {
591
593
  }
592
594
  async collectTasksForEntry(e, t, n, r, i) {
593
595
  if (e.includes("*")) {
594
- let a = W(e), o = l.globSync(e), s = this.extractBaseDir(a, n, t);
596
+ let a = le(e), o = l.globSync(e), s = this.extractBaseDir(a, n, t);
595
597
  return this.collectUploadTasks(o, s, a, r, i);
596
598
  }
597
599
  let a = await u.lstat(e);
598
- if (a.isSymbolicLink() && !r) return this.logger.warn?.(`${C.TAG} Skipping symlink: ${e}`), [];
600
+ if (a.isSymbolicLink() && !r) return this.logger.warn?.(`${w.TAG} Skipping symlink: ${e}`), [];
599
601
  if ((a.isSymbolicLink() ? await u.stat(e) : a).isDirectory()) {
600
602
  let a = (await u.readdir(e)).map((t) => f.join(e, t)), o = this.extractBaseDir(e, n, t);
601
603
  return this.collectUploadTasks(a, o, e, r, i);
602
604
  }
603
- return G(e, i) ? [] : [{
605
+ return z(e, i) ? [] : [{
604
606
  file: e,
605
607
  folderName: t
606
608
  }];
@@ -608,7 +610,7 @@ var q = class {
608
610
  extractBaseDir(e, t, n) {
609
611
  if (!t) return n;
610
612
  let r = f.relative(t, e);
611
- return !r || r === "." ? n : H(n, r);
613
+ return !r || r === "." ? n : R(n, r);
612
614
  }
613
615
  async canBeReplaced(e, t, n) {
614
616
  return !(!e.replace && await this.fileExist(t, n));
@@ -620,14 +622,14 @@ var q = class {
620
622
  if (e.expireDate) return e.expireDate;
621
623
  if (e.expire) {
622
624
  let { value: t, unit: n } = this.getTimeSpace(e.expire);
623
- return g().add(t, n).toDate();
625
+ return h().add(t, n).toDate();
624
626
  }
625
627
  }
626
628
  getTimeSpace(e) {
627
- let t = L.exec(e), n = t ? R[t[2]] : void 0;
628
- if (!t || !n) throw Error(`${C.TAG} Invalid time definition "${e}". Expected format like "30s", "15m", "24h", "7d", "2w", "1M", or "1y"`);
629
+ let t = ie.exec(e), n = t ? ae[t[2]] : void 0;
630
+ if (!t || !n) throw Error(`${w.TAG} Invalid time definition "${e}". Expected format like "30s", "15m", "24h", "7d", "2w", "1M", or "1y"`);
629
631
  let r = Number(t[1]);
630
- if (Number.isNaN(r)) throw Error(`${C.TAG} Invalid time unit in "${e}"`);
632
+ if (Number.isNaN(r)) throw TypeError(`${w.TAG} Invalid time unit in "${e}"`);
631
633
  return {
632
634
  value: r,
633
635
  unit: n
@@ -640,20 +642,20 @@ var q = class {
640
642
  }
641
643
  let r = l.lstatSync(t);
642
644
  if (r.isSymbolicLink() && !n.followSymlinks) {
643
- this.logger.warn?.(`${C.TAG} Skipping symlink in archive: ${t}`);
645
+ this.logger.warn?.(`${w.TAG} Skipping symlink in archive: ${t}`);
644
646
  return;
645
647
  }
646
648
  if ((r.isSymbolicLink() ? l.statSync(t) : r).isDirectory()) {
647
- e.directory(t, !1, (e) => !G(e.name, n.excludePatterns) && e);
649
+ e.directory(t, !1, (e) => !z(e.name, n.excludePatterns) && e);
648
650
  return;
649
651
  }
650
- if (G(t, n.excludePatterns)) return;
652
+ if (z(t, n.excludePatterns)) return;
651
653
  let i = f.basename(t), a = l.createReadStream(t);
652
654
  a.on("error", n.fail), e.append(a, { name: i }), n.readStreams.push(a);
653
655
  }
654
656
  compressFiles(e, t, n = {}) {
655
657
  let r = f.basename(t);
656
- if (!r || r === "." || r === ".." || r.includes("*")) return Promise.reject(/* @__PURE__ */ Error(`${C.TAG} Invalid archive filename: "${t}"`));
658
+ if (!r || r === "." || r === ".." || r.includes("*")) return Promise.reject(/* @__PURE__ */ Error(`${w.TAG} Invalid archive filename: "${t}"`));
657
659
  let i = l.mkdtempSync(f.join(d.tmpdir(), "node-s3-"));
658
660
  l.chmodSync(i, 448);
659
661
  let a = f.join(i, r), o = n.followSymlinks ?? !1, s = n.exclude ?? [];
@@ -663,14 +665,14 @@ var q = class {
663
665
  recursive: !0,
664
666
  force: !0
665
667
  }), r(e instanceof Error ? e : Error(String(e))));
666
- }, p = new h({ zlib: { level: n.compressionLevel ?? V } });
668
+ }, p = new ee({ zlib: { level: n.compressionLevel ?? se } });
667
669
  c.on("close", () => {
668
670
  d || (d = !0, t({
669
671
  filePath: a,
670
672
  tmpDir: i
671
673
  })), c.destroy();
672
674
  }), c.on("error", f), p.on("warning", (e) => {
673
- this.logger.warn?.(`${C.TAG} Warning compressing file`, e), e.code !== "ENOENT" && f(e);
675
+ this.logger.warn?.(`${w.TAG} Warning compressing file`, e), e.code !== "ENOENT" && f(e);
674
676
  }), p.on("error", f), p.pipe(c);
675
677
  try {
676
678
  for (let t of e) this.appendFileToArchive(p, t, {
@@ -686,7 +688,375 @@ var q = class {
686
688
  p.finalize().catch(f);
687
689
  });
688
690
  }
689
- }, J = class {
691
+ }, H = 16384;
692
+ function U(e) {
693
+ let t = (process.env.PATH || "").split(f.delimiter).filter(Boolean), n = process.platform === "win32" ? (process.env.PATHEXT || ".EXE;.CMD;.BAT").split(";") : [""];
694
+ for (let r of e) if (r.includes(f.sep) || r.includes("/")) {
695
+ if (W(r)) return r;
696
+ } else for (let e of t) for (let t of n) {
697
+ let n = f.join(e, `${r}${t}`);
698
+ if (W(n)) return n;
699
+ }
700
+ }
701
+ function W(e) {
702
+ try {
703
+ return l.statSync(e).isFile() ? (l.accessSync(e, l.constants.X_OK), !0) : !1;
704
+ } catch {
705
+ return !1;
706
+ }
707
+ }
708
+ function G(e) {
709
+ return e.replace(/([a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^:@/\s]+):([^@/\s]+)@/g, "$1:***@");
710
+ }
711
+ function K(e) {
712
+ return e.replace(/[^a-zA-Z0-9._-]/g, "_").replace(/^_+|_+$/g, "") || "db";
713
+ }
714
+ function q(e) {
715
+ let t = b(e.binary, e.args, {
716
+ env: e.env ? {
717
+ ...process.env,
718
+ ...e.env
719
+ } : process.env,
720
+ stdio: [
721
+ "ignore",
722
+ "pipe",
723
+ "pipe"
724
+ ],
725
+ shell: !1
726
+ }), n = new v(), r = [], i = 0, a, o = () => (a ||= Promise.resolve(e.onCleanup?.()), a);
727
+ t.stderr.on("data", (e) => {
728
+ if (i < H) {
729
+ let t = H - i;
730
+ r.push(e.subarray(0, t)), i += Math.min(e.length, t);
731
+ }
732
+ }), t.stdout.pipe(n, { end: !1 });
733
+ let s = !1, c, l, u = new Promise((e, t) => {
734
+ c = e, l = t;
735
+ });
736
+ u.catch(() => void 0);
737
+ let d = (e) => {
738
+ s || (s = !0, o(), n.destroyed || n.destroy(e), l(e));
739
+ };
740
+ return t.on("error", (t) => {
741
+ t.code === "ENOENT" ? d(/* @__PURE__ */ Error(`${e.tag} "${e.binary}" not found in PATH. ${e.installHint}`)) : d(/* @__PURE__ */ Error(`${e.tag} Failed to start "${e.binary}": ${t.message}`));
742
+ }), t.on("close", (t, i) => {
743
+ if (s) return;
744
+ if (t === 0) {
745
+ s = !0, o(), n.end(), c();
746
+ return;
747
+ }
748
+ let a = Buffer.concat(r).toString("utf8").trim(), l = a ? `: ${G(a)}` : "", u = i ? `terminated by signal ${i}` : `exited with code ${t ?? "unknown"}`;
749
+ d(/* @__PURE__ */ Error(`${e.tag} ${e.binary} ${u}${l}`));
750
+ }), {
751
+ kind: "stream",
752
+ engine: e.engine,
753
+ filename: e.filename,
754
+ mimeType: e.mimeType,
755
+ stream: n,
756
+ wait: () => u,
757
+ cleanup: async () => {
758
+ !s && !t.killed && t.kill("SIGTERM"), n.destroyed || n.destroy(), await o();
759
+ }
760
+ };
761
+ }
762
+ // src/db/providers/mongodb.ts
763
+ function ue(e) {
764
+ return !!(e && /^mongodb(?:\+srv)?:\/\//i.test(e));
765
+ }
766
+ function J(e) {
767
+ return JSON.stringify(e);
768
+ }
769
+ var de = {
770
+ engine: "mongodb",
771
+ aliases: ["mongo"],
772
+ async dump(e) {
773
+ let t = e.tag ?? "[db]", n = U(["mongodump"]);
774
+ if (!n) throw Error(`${t} "mongodump" not found in PATH. Install mongodb-database-tools or use the :db Docker image.`);
775
+ let r = e.url || process.env.MONGODB_URI || (ue(process.env.DATABASE_URL) ? process.env.DATABASE_URL : void 0), i = ["--archive"], a = "mongodb", o = "";
776
+ if (r) {
777
+ let t = "";
778
+ try {
779
+ t = new URL(r).pathname.replace(/^\/+/, "");
780
+ } catch {}
781
+ a = e.database || t || "mongodb", o = `uri: ${J(r)}\n`, e.database && i.push("--db", e.database);
782
+ } else {
783
+ let n = e.host || process.env.MONGO_HOST || "localhost", r = e.port ?? (process.env.MONGO_PORT ? Number(process.env.MONGO_PORT) : 27017), s = e.user || process.env.MONGO_USER || "", c = e.password ?? process.env.MONGO_PASSWORD ?? "", l = e.database || process.env.MONGO_DATABASE || "", u = process.env.MONGO_AUTH_DB || "";
784
+ if (!l && !e.host && !process.env.MONGO_HOST) throw Error(`${t} Missing MongoDB configuration. Set $MONGODB_URI (or $MONGO_DATABASE / $MONGO_HOST / --db-url).`);
785
+ a = l || "all", i.push("--host", n, "--port", String(r)), l && i.push("--db", l), s && i.push("--username", s), u && i.push("--authenticationDatabase", u), c && (o = `password: ${J(c)}\n`);
786
+ }
787
+ let s;
788
+ if (o) {
789
+ s = await u.mkdtemp(f.join(d.tmpdir(), "db-mongo-cfg-")), await u.chmod(s, 448);
790
+ let e = f.join(s, "mongodump.conf");
791
+ await u.writeFile(e, o, { mode: 384 }), i.push(`--config=${e}`);
792
+ }
793
+ return e.extraArgs?.length && i.push(...e.extraArgs), q({
794
+ engine: "mongodb",
795
+ binary: n,
796
+ args: i,
797
+ filename: e.filename || `mongodump-${K(a)}-${h().format("YYYY-MM-DD.HHmmss")}.archive`,
798
+ mimeType: "application/octet-stream",
799
+ tag: t,
800
+ installHint: "Install mongodb-database-tools or use the :db Docker image.",
801
+ onCleanup: async () => {
802
+ s && await u.rm(s, {
803
+ recursive: !0,
804
+ force: !0
805
+ });
806
+ }
807
+ });
808
+ }
809
+ };
810
+ // src/db/providers/mysql.ts
811
+ function fe(e) {
812
+ return !!(e && /^(?:mysql|mariadb):\/\//i.test(e));
813
+ }
814
+ function pe(e, t) {
815
+ let n = e.url || (fe(process.env.DATABASE_URL) ? process.env.DATABASE_URL : void 0);
816
+ if (n) {
817
+ let r = new URL(n), i = e.host || r.hostname || "localhost", a = e.port ?? (r.port ? Number(r.port) : 3306), o = e.user || decodeURIComponent(r.username || ""), s = e.password ?? decodeURIComponent(r.password || ""), c = e.database || r.pathname.replace(/^\/+/, "");
818
+ if (!o || !c) throw Error(`${t} Invalid MySQL/MariaDB URL: username and database name are required.`);
819
+ return {
820
+ host: i,
821
+ port: a,
822
+ user: o,
823
+ password: s,
824
+ database: c
825
+ };
826
+ }
827
+ let r = e.host || process.env.MYSQL_HOST || "localhost", i = e.port ?? (process.env.MYSQL_PORT ? Number(process.env.MYSQL_PORT) : 3306), a = e.user || process.env.MYSQL_USER || "", o = e.password ?? process.env.MYSQL_PASSWORD ?? "", s = e.database || process.env.MYSQL_DATABASE || "";
828
+ if (!a || !o || !s) throw Error(`${t} Missing required MySQL environment variables ($MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_HOST, $MYSQL_PORT) or --db-url.`);
829
+ return {
830
+ host: r,
831
+ port: i,
832
+ user: a,
833
+ password: o,
834
+ database: s
835
+ };
836
+ }
837
+ async function me(e, t) {
838
+ let { dump: n } = await g({ connection: {
839
+ host: e.host,
840
+ port: e.port,
841
+ user: e.user,
842
+ password: e.password,
843
+ database: e.database
844
+ } }), r = await u.mkdtemp(f.join(d.tmpdir(), "db-mysql-"));
845
+ await u.chmod(r, 448);
846
+ let i = f.join(r, t), a = Object.values(n).filter((e) => !!e).map((e) => e.replace(/^# /gm, "-- ")).join("\n\n");
847
+ return await u.writeFile(i, a, { mode: 384 }), {
848
+ kind: "file",
849
+ engine: "mysql",
850
+ filename: t,
851
+ mimeType: "application/sql",
852
+ filePath: i,
853
+ tempDir: r,
854
+ cleanup: async () => {
855
+ await u.rm(r, {
856
+ recursive: !0,
857
+ force: !0
858
+ });
859
+ }
860
+ };
861
+ }
862
+ var he = {
863
+ engine: "mysql",
864
+ aliases: ["mariadb"],
865
+ async dump(e) {
866
+ let t = e.tag ?? "[db]", n = pe(e, t), r = e.filename || `mysqldump-${K(n.database)}-${h().format("YYYY-MM-DD.HHmmss")}.sql`, i = U(["mysqldump", "mariadb-dump"]);
867
+ if (!i) return me(n, r);
868
+ let a = [
869
+ "--single-transaction",
870
+ "--quick",
871
+ "--routines",
872
+ "--triggers",
873
+ "-h",
874
+ n.host,
875
+ "-P",
876
+ String(n.port),
877
+ "-u",
878
+ n.user,
879
+ ...e.extraArgs ?? [],
880
+ n.database
881
+ ], o = {};
882
+ return n.password && (o.MYSQL_PWD = n.password), q({
883
+ engine: "mysql",
884
+ binary: i,
885
+ args: a,
886
+ env: o,
887
+ filename: r,
888
+ mimeType: "application/sql",
889
+ tag: t,
890
+ installHint: "Install mariadb-client / mysql-client or use the :db Docker image."
891
+ });
892
+ }
893
+ }, ge = {
894
+ plain: {
895
+ ext: "sql",
896
+ mimeType: "application/sql"
897
+ },
898
+ custom: {
899
+ ext: "dump",
900
+ mimeType: "application/octet-stream"
901
+ },
902
+ tar: {
903
+ ext: "tar",
904
+ mimeType: "application/x-tar"
905
+ }
906
+ };
907
+ function _e(e) {
908
+ return !!(e && /^postgres(?:ql)?:\/\//i.test(e));
909
+ }
910
+ function ve(e) {
911
+ let t = new URL(e), n = t.password ? decodeURIComponent(t.password) : void 0, r = t.pathname.replace(/^\/+/, "") || "postgres";
912
+ return t.password = "", {
913
+ sanitizedDbNameArg: t.toString(),
914
+ password: n,
915
+ database: r
916
+ };
917
+ }
918
+ var ye = {
919
+ engine: "postgres",
920
+ aliases: ["pg", "postgresql"],
921
+ async dump(e) {
922
+ let t = e.tag ?? "[db]", n = e.format ?? "plain", r = ge[n];
923
+ if (!r) throw Error(`${t} Unsupported PostgreSQL dump format "${String(n)}". Expected one of: plain, custom, tar.`);
924
+ let i = U(["pg_dump"]);
925
+ if (!i) throw Error(`${t} "pg_dump" not found in PATH. Install postgresql-client (e.g. apt install postgresql-client / brew install libpq) or use the :db Docker image.`);
926
+ let a = e.url || (_e(process.env.DATABASE_URL) ? process.env.DATABASE_URL : void 0), o = ["--no-password", `--format=${n}`], s = {}, c;
927
+ if (a) {
928
+ let t = ve(a);
929
+ c = e.database || t.database, (e.password ?? t.password) && (s.PGPASSWORD = e.password ?? t.password), o.push(`--dbname=${t.sanitizedDbNameArg}`);
930
+ } else {
931
+ let n = e.host || process.env.PGHOST || "localhost", r = e.port ?? (process.env.PGPORT ? Number(process.env.PGPORT) : 5432), i = e.user || process.env.PGUSER || "", a = e.password ?? process.env.PGPASSWORD, o = e.database || process.env.PGDATABASE || "";
932
+ if (!o) throw Error(`${t} Missing PostgreSQL database configuration. Set $PGDATABASE (or $DATABASE_URL / --db-url).`);
933
+ c = o, s.PGHOST = n, s.PGPORT = String(r), i && (s.PGUSER = i), a !== void 0 && a !== "" && (s.PGPASSWORD = a), s.PGDATABASE = o;
934
+ }
935
+ return e.extraArgs?.length && o.push(...e.extraArgs), q({
936
+ engine: "postgres",
937
+ binary: i,
938
+ args: o,
939
+ env: s,
940
+ filename: e.filename || `pgdump-${K(c)}-${h().format("YYYY-MM-DD.HHmmss")}.${r.ext}`,
941
+ mimeType: r.mimeType,
942
+ tag: t,
943
+ installHint: "Install postgresql-client or use the :db Docker image."
944
+ });
945
+ }
946
+ };
947
+ // src/db/providers/sqlite.ts
948
+ function be(e) {
949
+ return !!(e && /^(?:sqlite3?:|file:)/i.test(e));
950
+ }
951
+ function xe(e, t) {
952
+ let n = e.database || e.url || process.env.SQLITE_PATH || (be(process.env.DATABASE_URL) ? process.env.DATABASE_URL : "");
953
+ if (!n) throw Error(`${t} Missing SQLite database path. Set $SQLITE_PATH (or --db-url sqlite:///path/to/db.sqlite).`);
954
+ let r = n;
955
+ /^sqlite3?:\/\//i.test(n) ? r = decodeURIComponent(n.replace(/^sqlite3?:\/\//i, "")) : /^sqlite3?:/i.test(n) ? r = decodeURIComponent(n.replace(/^sqlite3?:/i, "")) : /^file:/i.test(n) && (r = decodeURIComponent(n.replace(/^file:(\/\/)?/i, "")));
956
+ let i = f.resolve(r);
957
+ if (!l.existsSync(i) || !l.statSync(i).isFile()) throw Error(`${t} SQLite database file not found: "${i}"`);
958
+ return i;
959
+ }
960
+ // src/db/index.ts
961
+ var Y = [
962
+ ye,
963
+ he,
964
+ de,
965
+ {
966
+ engine: "sqlite",
967
+ aliases: ["sqlite3"],
968
+ async dump(e) {
969
+ let t = xe(e, e.tag ?? "[db]"), n = f.basename(t, f.extname(t)), r = e.filename || `sqlite-${K(n)}-${h().format("YYYY-MM-DD.HHmmss")}.sqlite`, i = await u.mkdtemp(f.join(d.tmpdir(), "db-sqlite-"));
970
+ await u.chmod(i, 448);
971
+ let a = f.join(i, r), o = new ne(t, { readOnly: !0 });
972
+ try {
973
+ await x(o, a), await u.chmod(a, 384);
974
+ } catch (e) {
975
+ throw await u.rm(i, {
976
+ recursive: !0,
977
+ force: !0
978
+ }), e;
979
+ } finally {
980
+ o.close();
981
+ }
982
+ return {
983
+ kind: "file",
984
+ engine: "sqlite",
985
+ filename: r,
986
+ mimeType: "application/vnd.sqlite3",
987
+ filePath: a,
988
+ tempDir: i,
989
+ cleanup: async () => {
990
+ await u.rm(i, {
991
+ recursive: !0,
992
+ force: !0
993
+ });
994
+ }
995
+ };
996
+ }
997
+ }
998
+ ], X = /* @__PURE__ */ new Map();
999
+ for (let e of Y) {
1000
+ X.set(e.engine, e);
1001
+ for (let t of e.aliases) X.set(t, e);
1002
+ }
1003
+ var Z = Y.map((e) => e.engine);
1004
+ function Q(e, t = "[db]") {
1005
+ let n = e.trim().toLowerCase(), r = X.get(n);
1006
+ if (!r) throw Error(`${t} Unsupported database engine "${e}". Supported engines: ${Z.join(", ")}.`);
1007
+ return r.engine;
1008
+ }
1009
+ function $(e, t = "[db]") {
1010
+ let n = e.trim();
1011
+ if (/^postgres(?:ql)?:\/\//i.test(n)) return "postgres";
1012
+ if (/^(?:mysql|mariadb):\/\//i.test(n)) return "mysql";
1013
+ if (/^mongodb(?:\+srv)?:\/\//i.test(n)) return "mongodb";
1014
+ if (/^(?:sqlite3?:|file:)/i.test(n)) return "sqlite";
1015
+ throw Error(`${t} Could not detect database engine from URL. Supported schemes: postgresql://, mysql://, mariadb://, mongodb://, sqlite://.`);
1016
+ }
1017
+ async function Se(e) {
1018
+ let t = await u.mkdtemp(f.join(d.tmpdir(), `db-${e.engine}-`));
1019
+ await u.chmod(t, 448);
1020
+ let n = f.join(t, f.basename(e.filename));
1021
+ try {
1022
+ let t = l.createWriteStream(n, { mode: 384 });
1023
+ await p(e.stream, t), await e.wait();
1024
+ } catch (n) {
1025
+ throw await e.cleanup(), await u.rm(t, {
1026
+ recursive: !0,
1027
+ force: !0
1028
+ }), n;
1029
+ }
1030
+ return {
1031
+ kind: "file",
1032
+ engine: e.engine,
1033
+ filename: e.filename,
1034
+ mimeType: e.mimeType,
1035
+ filePath: n,
1036
+ tempDir: t,
1037
+ cleanup: async () => {
1038
+ await u.rm(t, {
1039
+ recursive: !0,
1040
+ force: !0
1041
+ });
1042
+ }
1043
+ };
1044
+ }
1045
+ async function Ce(e) {
1046
+ let t = e.tag ?? "[db]", n;
1047
+ if (e.engine) n = Q(e.engine, t);
1048
+ else if (e.url) n = $(e.url, t);
1049
+ else if (process.env.DATABASE_URL) n = $(process.env.DATABASE_URL, t);
1050
+ else throw Error(`${t} Database engine not specified. Pass --db <${Z.join("|")}> or --db-url <uri>.`);
1051
+ let r = await X.get(n).dump({
1052
+ ...e,
1053
+ engine: n,
1054
+ tag: t
1055
+ });
1056
+ return e.preferFile && r.kind === "stream" ? Se(r) : r;
1057
+ }
1058
+ // src/index.ts
1059
+ var we = class {
690
1060
  bucket = "";
691
1061
  endpoint = "";
692
1062
  s3Sdk;
@@ -698,17 +1068,17 @@ var q = class {
698
1068
  }
699
1069
  setConfig(e = {}, t) {
700
1070
  this.s3Sdk && this.ownsClient && this.s3Sdk.destroy();
701
- let n = e.endpoint || C.ENDPOINT || void 0, r = e.logger ?? console, i = this.buildClientOptions(e, n, r);
702
- this.bucket = e.bucket ?? C.BUCKET, this.endpoint = n || "", t ? (this.s3Sdk = t, this.ownsClient = !1) : (this.s3Sdk = new c(i), this.ownsClient = !0), this.s3Files = new q(this.s3Sdk, {
1071
+ let n = e.endpoint || w.ENDPOINT || void 0, r = e.logger ?? console, i = this.buildClientOptions(e, n, r);
1072
+ this.bucket = e.bucket ?? w.BUCKET, this.endpoint = n || "", t ? (this.s3Sdk = t, this.ownsClient = !1) : (this.s3Sdk = new c(i), this.ownsClient = !0), this.s3Files = new V(this.s3Sdk, {
703
1073
  ensureBucket: (e) => this.ensureBucket(e),
704
1074
  logger: r,
705
1075
  dryRun: e.dryRun,
706
1076
  onProgress: e.onProgress
707
- }), this.s3Buckets = new D(this.s3Sdk, (e) => this.s3Files.deleteAllContent(e));
1077
+ }), this.s3Buckets = new re(this.s3Sdk, (e) => this.s3Files.deleteAllContent(e));
708
1078
  }
709
1079
  buildClientOptions(e, t, n) {
710
- let r = e.accessKeyId || C.ACCESS_KEY || void 0, i = e.secretAccessKey || C.SECRET_KEY || void 0, a = e.sessionToken || C.SESSION_TOKEN || void 0, o = e.region || C.REGION || "us-east-1", s = !!(t && /^http:\/\//i.test(t)), c = !s && C.SSL_ENABLED, l = e.sslEnabled ?? c;
711
- s && e.sslEnabled === void 0 && n.warn?.(`${C.TAG} Using insecure HTTP endpoint "${t}"`);
1080
+ let r = e.accessKeyId || w.ACCESS_KEY || void 0, i = e.secretAccessKey || w.SECRET_KEY || void 0, a = e.sessionToken || w.SESSION_TOKEN || void 0, o = e.region || w.REGION || "us-east-1", s = !!(t && /^http:\/\//i.test(t)), c = !s && w.SSL_ENABLED, l = e.sslEnabled ?? c;
1081
+ s && e.sslEnabled === void 0 && n.warn?.(`${w.TAG} Using insecure HTTP endpoint "${t}"`);
712
1082
  let u = r && i ? {
713
1083
  accessKeyId: r,
714
1084
  secretAccessKey: i,
@@ -717,8 +1087,8 @@ var q = class {
717
1087
  return {
718
1088
  region: o,
719
1089
  tls: l,
720
- maxAttempts: (e.maxRetries ?? C.MAX_RETRIES) + 1,
721
- forcePathStyle: e.forcePathStyle ?? C.FORCE_PATH_STYLE,
1090
+ maxAttempts: (e.maxRetries ?? w.MAX_RETRIES) + 1,
1091
+ forcePathStyle: e.forcePathStyle ?? w.FORCE_PATH_STYLE,
722
1092
  ...t ? { endpoint: t } : {},
723
1093
  ...u ? { credentials: u } : {}
724
1094
  };
@@ -772,7 +1142,7 @@ var q = class {
772
1142
  await this.s3Buckets.bucketExist(e) || await this.s3Buckets.createBucket(e);
773
1143
  }
774
1144
  checkBucket(e) {
775
- if (!e) throw Error(`${C.TAG} Bucket not defined`);
1145
+ if (!e) throw Error(`${w.TAG} Bucket not defined`);
776
1146
  }
777
1147
  };
778
- export { J as S3Wrapper, I as createDecryptStream, F as createEncryptStream, H as normalizeS3Key };
1148
+ export { we as S3Wrapper, Z as SUPPORTED_DB_ENGINES, I as createDecryptStream, F as createEncryptStream, $ as detectDbEngineFromUrl, Ce as dumpDatabase, Q as normalizeDbEngine, R as normalizeS3Key };