@budibase/cli 3.38.5 → 3.39.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/cli",
3
- "version": "3.38.5",
3
+ "version": "3.39.16",
4
4
  "description": "Budibase CLI, for developers, self hosting and migrations.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -41,5 +41,5 @@
41
41
  "@types/pouchdb": "^6.4.0",
42
42
  "ts-node": "10.8.1"
43
43
  },
44
- "gitHead": "5795ec6c95812463cba1d8cede8295f6c2b915cb"
44
+ "gitHead": "b1c87febc51bc49767bb6438e75a06038fea8fbf"
45
45
  }
@@ -1,9 +1,10 @@
1
1
  import { objectStore } from "@budibase/backend-core"
2
2
  import fs from "fs"
3
- import { join } from "path"
3
+ import { dirname, join } from "path"
4
4
  import { TEMP_DIR, MINIO_DIR } from "./utils"
5
5
  import { progressBar } from "../utils"
6
6
  import * as stream from "node:stream"
7
+ import { pipeline } from "stream/promises"
7
8
 
8
9
  const {
9
10
  ObjectStoreBuckets,
@@ -15,10 +16,36 @@ const {
15
16
 
16
17
  const bucketList = Object.values(ObjectStoreBuckets)
17
18
 
19
+ type BackupObject = {
20
+ bucket: string
21
+ Key: string
22
+ }
23
+
24
+ async function listBucketObjects(
25
+ client: ReturnType<typeof ObjectStore>,
26
+ bucket: string
27
+ ) {
28
+ const objects: BackupObject[] = []
29
+ let continuationToken: string | undefined
30
+ do {
31
+ const list = await client.listObjectsV2({
32
+ Bucket: bucket,
33
+ ContinuationToken: continuationToken,
34
+ })
35
+ objects.push(
36
+ ...(list.Contents?.filter(
37
+ (object): object is typeof object & { Key: string } => !!object.Key
38
+ ).map(object => ({ ...object, bucket, Key: object.Key })) || [])
39
+ )
40
+ continuationToken = list.NextContinuationToken
41
+ } while (continuationToken)
42
+ return objects
43
+ }
44
+
18
45
  export async function exportObjects() {
19
46
  const path = join(TEMP_DIR, MINIO_DIR)
20
- fs.mkdirSync(path)
21
- let fullList: any[] = []
47
+ fs.mkdirSync(path, { recursive: true })
48
+ let fullList: BackupObject[] = []
22
49
  let errorCount = 0
23
50
  for (let bucket of bucketList) {
24
51
  const client = ObjectStore()
@@ -30,12 +57,7 @@ export async function exportObjects() {
30
57
  errorCount++
31
58
  continue
32
59
  }
33
- const list = await client.listObjectsV2({
34
- Bucket: bucket,
35
- })
36
- fullList = fullList.concat(
37
- list.Contents?.map(el => ({ ...el, bucket })) || []
38
- )
60
+ fullList = fullList.concat(await listBucketObjects(client, bucket))
39
61
  }
40
62
  if (errorCount === bucketList.length) {
41
63
  throw new Error("Unable to access MinIO/S3 - check environment config.")
@@ -46,16 +68,12 @@ export async function exportObjects() {
46
68
  const filename = object.Key
47
69
  const data = await retrieve(object.bucket, filename)
48
70
  const possiblePath = filename.split("/")
49
- if (possiblePath.length > 1) {
50
- const dirs = possiblePath.slice(0, possiblePath.length - 1)
51
- fs.mkdirSync(join(path, object.bucket, ...dirs), { recursive: true })
52
- }
71
+ const destination = join(path, object.bucket, ...possiblePath)
72
+ fs.mkdirSync(dirname(destination), { recursive: true })
53
73
  if (data instanceof stream.Readable) {
54
- data.pipe(
55
- fs.createWriteStream(join(path, object.bucket, ...possiblePath))
56
- )
74
+ await pipeline(data, fs.createWriteStream(destination))
57
75
  } else {
58
- fs.writeFileSync(join(path, object.bucket, ...possiblePath), data)
76
+ fs.writeFileSync(destination, data)
59
77
  }
60
78
  bar.update(++count)
61
79
  }