@bunit/storage 0.0.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.
@@ -0,0 +1,6 @@
1
+ export interface FSDriverOptions {
2
+ base?: string;
3
+ ignore?: string | string[];
4
+ }
5
+ declare const _default: (opts: FSDriverOptions) => import("unstorage").Driver<FSDriverOptions, never>;
6
+ export default _default;
@@ -0,0 +1,50 @@
1
+ import { defineDriver, normalizeKey } from "unstorage";
2
+ import { mkdir } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { Glob } from "bun";
5
+ export default defineDriver((options = {}) => {
6
+ const base = options.base ? resolve(options.base) : resolve("."), ignore = options.ignore || [];
7
+ return {
8
+ name: "fs",
9
+ options,
10
+ hasItem(key) {
11
+ const path = join(base, key.replace(/:/g, "/"));
12
+ return Bun.file(path).exists();
13
+ },
14
+ async getItem(key) {
15
+ const path = join(base, key.replace(/:/g, "/")), file = Bun.file(path);
16
+ if (!await file.exists())
17
+ return null;
18
+ return await file.text();
19
+ },
20
+ async setItem(key, value) {
21
+ const path = join(base, key.replace(/:/g, "/"));
22
+ await mkdir(dirname(path), { recursive: !0 });
23
+ await Bun.write(path, value);
24
+ },
25
+ async removeItem(key) {
26
+ const path = join(base, key.replace(/:/g, "/"));
27
+ await Bun.file(path).delete();
28
+ },
29
+ async getKeys() {
30
+ const glob = new Glob("**/*"), keys = [];
31
+ for await (const file of glob.scan(base)) {
32
+ const key = normalizeKey(file);
33
+ if (ignore.length > 0) {
34
+ if (Array.isArray(ignore) ? ignore.some((pattern) => file.includes(pattern)) : file.includes(ignore))
35
+ continue;
36
+ }
37
+ keys.push(key);
38
+ }
39
+ return keys;
40
+ },
41
+ async clear() {
42
+ const glob = new Glob("**/*");
43
+ for await (const file of glob.scan(base)) {
44
+ const path = join(base, file);
45
+ await Bun.file(path).delete();
46
+ }
47
+ },
48
+ async dispose() {}
49
+ };
50
+ });
@@ -0,0 +1 @@
1
+ export * from "unstorage";
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ export*from"unstorage";
@@ -0,0 +1 @@
1
+ export * from "unstorage/server";
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ export*from"unstorage/server";
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@bunit/storage",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/DemoMacro/BunIt#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/DemoMacro/BunIt/issues"
9
+ },
10
+ "license": "MIT",
11
+ "author": {
12
+ "name": "Demo Macro",
13
+ "email": "abc@imst.xyz",
14
+ "url": "https://www.demomacro.com/"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/DemoMacro/BunIt.git"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "main": "dist/index.mjs",
24
+ "types": "dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.mjs"
29
+ },
30
+ "./server": {
31
+ "types": "./dist/server.d.ts",
32
+ "import": "./dist/server.mjs"
33
+ },
34
+ "./drivers/*": {
35
+ "types": "./dist/drivers/*.d.ts",
36
+ "import": "./dist/drivers/*.mjs"
37
+ }
38
+ },
39
+ "scripts": {
40
+ "dev": "built --stub",
41
+ "build": "built",
42
+ "prepack": "bun run build"
43
+ },
44
+ "dependencies": {},
45
+ "devDependencies": {},
46
+ "peerDependencies": {
47
+ "unstorage": "^1.17.4"
48
+ }
49
+ }