@server/next 0.25.7 → 0.25.9

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": "@server/next",
3
- "version": "0.25.7",
3
+ "version": "0.25.9",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
@@ -33,6 +33,10 @@ function thinLocalBucket(root) {
33
33
  }
34
34
  return fs.createWriteStream(fullPath);
35
35
  },
36
+ delete: (name) => {
37
+ const fullPath = absolute(name);
38
+ return fsp.unlink(fullPath);
39
+ },
36
40
  };
37
41
  }
38
42
 
@@ -51,6 +55,11 @@ function thinBunBucket(s3) {
51
55
  }
52
56
  return s3.presign(name, { expiresIn: 3600, acl: "public-read-write" });
53
57
  },
58
+ delete: async (name) => {
59
+ const file = s3.file(name);
60
+ if (!(await file.exists())) return null;
61
+ return await file.delete();
62
+ },
54
63
  };
55
64
  }
56
65
 
@@ -0,0 +1,40 @@
1
+ import bucket from "./bucket.js";
2
+ import fsp from "node:fs/promises";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+
6
+ const localBucket = bucket("./tests/uploads/");
7
+
8
+ describe("bucket", () => {
9
+ afterAll(async () => {
10
+ const filePath = path.resolve("./tests/uploads/testFile.txt");
11
+ if (fs.existsSync(filePath)) {
12
+ await fsp.unlink(filePath);
13
+ }
14
+ });
15
+
16
+ it("writes a file", async () => {
17
+ const filePath = await localBucket.write("testFile.txt", "Hello, World!");
18
+ expect(filePath.endsWith("testFile.txt")).toBe(true);
19
+ });
20
+
21
+ it("reads a file", async () => {
22
+ const stream = await localBucket.read("testFile.txt");
23
+ expect(stream).not.toBeNull();
24
+ let data = "";
25
+ const reader = stream.getReader();
26
+ while (true) {
27
+ const { done, value } = await reader.read();
28
+ if (done) break;
29
+ data += new TextDecoder().decode(value);
30
+ }
31
+ expect(data).toBe("Hello, World!");
32
+ });
33
+
34
+ it("deletes a file", async () => {
35
+ const filePath = path.resolve("./tests/uploads/testFile.txt");
36
+ await fsp.unlink(filePath);
37
+ const stream = await localBucket.read("testFile.txt");
38
+ expect(stream).toBeNull();
39
+ });
40
+ });