rads-db 0.1.53 → 0.1.55

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/index.d.ts CHANGED
@@ -158,7 +158,9 @@ interface TypeDefinition {
158
158
  }
159
159
  interface FileUploadDriver {
160
160
  driverName: string;
161
- uploadFile(args: FileUploadArgs): Promise<string>;
161
+ uploadFile(args: FileUploadArgs): Promise<{
162
+ url: string;
163
+ }>;
162
164
  }
163
165
  interface FileUploadArgs {
164
166
  blob: Blob;
@@ -30,7 +30,9 @@ var _default = options => {
30
30
  console.error("Error uploading file to azure storage:");
31
31
  throw e;
32
32
  }
33
- return blobClient.url.split("?")[0];
33
+ return {
34
+ url: blobClient.url.split("?")[0]
35
+ };
34
36
  }
35
37
  };
36
38
  return driver;
@@ -20,7 +20,7 @@ export default (options) => {
20
20
  console.error("Error uploading file to azure storage:");
21
21
  throw e;
22
22
  }
23
- return blobClient.url.split("?")[0];
23
+ return { url: blobClient.url.split("?")[0] };
24
24
  }
25
25
  };
26
26
  return driver;
@@ -12,7 +12,9 @@ var _default = options => {
12
12
  blob
13
13
  } = args;
14
14
  const dataUrl = await blobToDataURL(blob);
15
- return dataUrl;
15
+ return {
16
+ url: dataUrl
17
+ };
16
18
  }
17
19
  };
18
20
  return driver;
@@ -4,7 +4,7 @@ export default (options) => {
4
4
  async uploadFile(args) {
5
5
  const { blob } = args;
6
6
  const dataUrl = await blobToDataURL(blob);
7
- return dataUrl;
7
+ return { url: dataUrl };
8
8
  }
9
9
  };
10
10
  return driver;
@@ -20,7 +20,7 @@ var _default = options => {
20
20
  method: "POST",
21
21
  body
22
22
  });
23
- return response.text();
23
+ return await response.json();
24
24
  }
25
25
  };
26
26
  return driver;
@@ -40,7 +40,22 @@ async function getJsonBody(args) {
40
40
  });
41
41
  }
42
42
  async function blobToDataUrl(blob) {
43
- const buf = await blob.arrayBuffer();
44
- const b64string = Buffer.from(buf).toString("base64");
45
- return `data:${blob.type};base64,${b64string}`;
43
+ if (FileReader) {
44
+ return new Promise((resolve, reject) => {
45
+ const a = new FileReader();
46
+ a.onload = function (e) {
47
+ resolve(e.target?.result);
48
+ };
49
+ a.onerror = function (e) {
50
+ reject(new Error(["Error parsing blob", e.target?.error].filter(x => x).join(": ")));
51
+ };
52
+ a.readAsDataURL(blob);
53
+ });
54
+ }
55
+ if (Buffer) {
56
+ const buf = await blob.arrayBuffer();
57
+ const b64string = Buffer.from(buf).toString("base64");
58
+ return `data:${blob.type};base64,${b64string}`;
59
+ }
60
+ throw new Error(`Cannot parse blob on this environment. Consider using formData instead.`);
46
61
  }
@@ -11,7 +11,7 @@ export default (options) => {
11
11
  method: "POST",
12
12
  body
13
13
  });
14
- return response.text();
14
+ return await response.json();
15
15
  }
16
16
  };
17
17
  return driver;
@@ -30,7 +30,22 @@ async function getJsonBody(args) {
30
30
  });
31
31
  }
32
32
  async function blobToDataUrl(blob) {
33
- const buf = await blob.arrayBuffer();
34
- const b64string = Buffer.from(buf).toString("base64");
35
- return `data:${blob.type};base64,${b64string}`;
33
+ if (FileReader) {
34
+ return new Promise((resolve, reject) => {
35
+ const a = new FileReader();
36
+ a.onload = function(e) {
37
+ resolve(e.target?.result);
38
+ };
39
+ a.onerror = function(e) {
40
+ reject(new Error(["Error parsing blob", e.target?.error].filter((x) => x).join(": ")));
41
+ };
42
+ a.readAsDataURL(blob);
43
+ });
44
+ }
45
+ if (Buffer) {
46
+ const buf = await blob.arrayBuffer();
47
+ const b64string = Buffer.from(buf).toString("base64");
48
+ return `data:${blob.type};base64,${b64string}`;
49
+ }
50
+ throw new Error(`Cannot parse blob on this environment. Consider using formData instead.`);
36
51
  }
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "require": "./integrations/*.cjs"
35
35
  }
36
36
  },
37
- "version": "0.1.53",
37
+ "version": "0.1.55",
38
38
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
39
39
  "keywords": [],
40
40
  "author": "",