@teamkeel/functions-runtime 0.395.0 → 0.395.1
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 +1 -1
- package/src/File.js +9 -7
- package/src/database.js +1 -0
- package/src/handleRequest.js +1 -0
package/package.json
CHANGED
package/src/File.js
CHANGED
|
@@ -4,7 +4,7 @@ const {
|
|
|
4
4
|
GetObjectCommand,
|
|
5
5
|
} = require("@aws-sdk/client-s3");
|
|
6
6
|
const { fromEnv } = require("@aws-sdk/credential-providers");
|
|
7
|
-
const {
|
|
7
|
+
const { createDatabaseClient } = require("./database");
|
|
8
8
|
const { DatabaseError } = require("./errors");
|
|
9
9
|
const KSUID = require("ksuid");
|
|
10
10
|
|
|
@@ -105,9 +105,7 @@ class File extends InlineFile {
|
|
|
105
105
|
async read() {
|
|
106
106
|
if (this._contents) {
|
|
107
107
|
const arrayBuffer = await this._contents.arrayBuffer();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return buffer;
|
|
108
|
+
return Buffer.from(arrayBuffer);
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
if (isS3Storage()) {
|
|
@@ -122,12 +120,12 @@ class File extends InlineFile {
|
|
|
122
120
|
};
|
|
123
121
|
const command = new GetObjectCommand(params);
|
|
124
122
|
const response = await s3Client.send(command);
|
|
125
|
-
const blob = response.Body.transformToByteArray();
|
|
123
|
+
const blob = await response.Body.transformToByteArray();
|
|
126
124
|
return Buffer.from(blob);
|
|
127
125
|
}
|
|
128
126
|
|
|
129
127
|
// default to db storage
|
|
130
|
-
const db =
|
|
128
|
+
const db = createDatabaseClient();
|
|
131
129
|
|
|
132
130
|
try {
|
|
133
131
|
let query = db
|
|
@@ -139,6 +137,8 @@ class File extends InlineFile {
|
|
|
139
137
|
return row.data;
|
|
140
138
|
} catch (e) {
|
|
141
139
|
throw new DatabaseError(e);
|
|
140
|
+
} finally {
|
|
141
|
+
await db.destroy();
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -210,7 +210,7 @@ async function storeFile(contents, key, filename, contentType, expires) {
|
|
|
210
210
|
throw error;
|
|
211
211
|
}
|
|
212
212
|
} else {
|
|
213
|
-
const db =
|
|
213
|
+
const db = createDatabaseClient();
|
|
214
214
|
|
|
215
215
|
try {
|
|
216
216
|
let query = db
|
|
@@ -236,6 +236,8 @@ async function storeFile(contents, key, filename, contentType, expires) {
|
|
|
236
236
|
await query.execute();
|
|
237
237
|
} catch (e) {
|
|
238
238
|
throw new DatabaseError(e);
|
|
239
|
+
} finally {
|
|
240
|
+
await db.destroy();
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
}
|
package/src/database.js
CHANGED
|
@@ -70,6 +70,7 @@ function useDatabase() {
|
|
|
70
70
|
|
|
71
71
|
// If we've gotten to this point, then we know that we are in a custom function runtime server
|
|
72
72
|
// context and we haven't been able to retrieve the in-context instance of Kysely, which means we should throw an error.
|
|
73
|
+
console.trace();
|
|
73
74
|
throw new Error("useDatabase must be called within a function");
|
|
74
75
|
}
|
|
75
76
|
|