@storyshelf/storage-local 0.1.0 → 0.1.2
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/LICENSE +21 -0
- package/dist/index.mjs +21 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +31 -22
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Siddhant Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,20 @@ async function pathExists(target) {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function toAbsolute(root, path) {
|
|
16
|
+
const target = resolve(root, path);
|
|
17
|
+
const rel = relative(root, target);
|
|
18
|
+
if (rel === ".." || rel.startsWith(`..${sep}`)) throw new Error(`Path escapes storage directory: ${path}`);
|
|
19
|
+
return target;
|
|
20
|
+
}
|
|
21
|
+
async function walk(root, dir) {
|
|
22
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
23
|
+
return (await Promise.all(entries.map(async (entry) => {
|
|
24
|
+
const full = join(dir, entry.name);
|
|
25
|
+
if (entry.isDirectory()) return await walk(root, full);
|
|
26
|
+
return [relative(root, full)];
|
|
27
|
+
}))).flat();
|
|
28
|
+
}
|
|
15
29
|
/**
|
|
16
30
|
* Create a local filesystem-backed StorageAdapter rooted at the given directory.
|
|
17
31
|
*
|
|
@@ -20,45 +34,31 @@ async function pathExists(target) {
|
|
|
20
34
|
*/
|
|
21
35
|
function createLocalStorage(dataDir) {
|
|
22
36
|
const root = resolve(dataDir);
|
|
23
|
-
function toAbsolute(path) {
|
|
24
|
-
const target = resolve(root, path);
|
|
25
|
-
const rel = relative(root, target);
|
|
26
|
-
if (rel === ".." || rel.startsWith(`..${sep}`)) throw new Error(`Path escapes storage directory: ${path}`);
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
async function walk(dir) {
|
|
30
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
31
|
-
return (await Promise.all(entries.map(async (entry) => {
|
|
32
|
-
const full = join(dir, entry.name);
|
|
33
|
-
if (entry.isDirectory()) return await walk(full);
|
|
34
|
-
return [relative(root, full)];
|
|
35
|
-
}))).flat();
|
|
36
|
-
}
|
|
37
37
|
return {
|
|
38
38
|
metadata: {
|
|
39
39
|
name: "Local Storage",
|
|
40
|
-
version: "0.
|
|
40
|
+
version: globalThis.__PKG_VERSION__ ?? "0.0.0",
|
|
41
41
|
description: "Local filesystem storage adapter",
|
|
42
42
|
kind: "local"
|
|
43
43
|
},
|
|
44
44
|
async read(path) {
|
|
45
|
-
return await readFile(toAbsolute(path));
|
|
45
|
+
return await readFile(toAbsolute(root, path));
|
|
46
46
|
},
|
|
47
47
|
async write(path, data) {
|
|
48
|
-
const target = toAbsolute(path);
|
|
48
|
+
const target = toAbsolute(root, path);
|
|
49
49
|
await mkdir(dirname(target), { recursive: true });
|
|
50
50
|
await writeFile(target, data);
|
|
51
51
|
},
|
|
52
52
|
async delete(path) {
|
|
53
|
-
await rm(toAbsolute(path), { force: true });
|
|
53
|
+
await rm(toAbsolute(root, path), { force: true });
|
|
54
54
|
},
|
|
55
55
|
async exists(path) {
|
|
56
|
-
return await pathExists(toAbsolute(path));
|
|
56
|
+
return await pathExists(toAbsolute(root, path));
|
|
57
57
|
},
|
|
58
58
|
async list(prefix) {
|
|
59
|
-
const dir = toAbsolute(prefix);
|
|
59
|
+
const dir = toAbsolute(root, prefix);
|
|
60
60
|
if (!await pathExists(dir)) return [];
|
|
61
|
-
return walk(dir);
|
|
61
|
+
return walk(root, dir);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { access, mkdir, readdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, relative, resolve, sep } from \"node:path\";\n\nimport type { StorageAdapter } from \"@storyshelf/core/adapter/storage\";\n\ndeclare const __PKG_VERSION__: string;\n\nasync function pathExists(target: string): Promise<boolean> {\n try {\n await access(target);\n return true;\n } catch {\n return false;\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { access, mkdir, readdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, join, relative, resolve, sep } from \"node:path\";\n\nimport type { StorageAdapter } from \"@storyshelf/core/adapter/storage\";\n\ndeclare const __PKG_VERSION__: string | undefined;\n\nasync function pathExists(target: string): Promise<boolean> {\n try {\n await access(target);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction toAbsolute(root: string, path: string): string {\n const target = resolve(root, path);\n const rel = relative(root, target);\n if (rel === \"..\" || rel.startsWith(`..${sep}`)) {\n throw new Error(`Path escapes storage directory: ${path}`);\n }\n return target;\n}\n\nasync function walk(root: string, dir: string): Promise<string[]> {\n const entries = await readdir(dir, { withFileTypes: true });\n const nested = await Promise.all(\n entries.map(async (entry) => {\n const full = join(dir, entry.name);\n if (entry.isDirectory()) {\n return await walk(root, full);\n }\n return [relative(root, full)];\n }),\n );\n return nested.flat();\n}\n\n/**\n * Create a local filesystem-backed StorageAdapter rooted at the given directory.\n *\n * @param dataDir - Root directory in which all stored files live.\n * @returns A StorageAdapter that reads and writes files under `dataDir`.\n */\nexport function createLocalStorage(dataDir: string): StorageAdapter {\n const root = resolve(dataDir);\n\n return {\n metadata: {\n name: \"Local Storage\",\n version: (globalThis as unknown as { __PKG_VERSION__?: string }).__PKG_VERSION__ ?? \"0.0.0\",\n description: \"Local filesystem storage adapter\",\n kind: \"local\",\n },\n async read(path) {\n return await readFile(toAbsolute(root, path));\n },\n async write(path, data) {\n const target = toAbsolute(root, path);\n await mkdir(dirname(target), { recursive: true });\n await writeFile(target, data);\n },\n async delete(path) {\n await rm(toAbsolute(root, path), { force: true });\n },\n async exists(path) {\n return await pathExists(toAbsolute(root, path));\n },\n async list(prefix) {\n const dir = toAbsolute(root, prefix);\n if (!(await pathExists(dir))) {\n return [];\n }\n return walk(root, dir);\n },\n };\n}\n"],"mappings":";;;;;;AAOA,eAAe,WAAW,QAAkC;CAC1D,IAAI;EACF,MAAM,OAAO,MAAM;EACnB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,WAAW,MAAc,MAAsB;CACtD,MAAM,SAAS,QAAQ,MAAM,IAAI;CACjC,MAAM,MAAM,SAAS,MAAM,MAAM;CACjC,IAAI,QAAQ,QAAQ,IAAI,WAAW,KAAK,KAAK,GAC3C,MAAM,IAAI,MAAM,mCAAmC,MAAM;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"version": "0.1.2",
|
|
5
4
|
"description": "Local filesystem storage adapter for StoryShelf.",
|
|
5
|
+
"homepage": "https://github.com/GuptaSiddhant/StoryShelf#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/GuptaSiddhant/StoryShelf/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
6
10
|
"author": {
|
|
7
11
|
"name": "Siddhant Gupta",
|
|
8
12
|
"url": "https://guptasiddhant.com"
|
|
9
13
|
},
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"sideEffects": false,
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
|
-
"url": "git+https://github.com/GuptaSiddhant/
|
|
16
|
+
"url": "git+https://github.com/GuptaSiddhant/StoryShelf.git",
|
|
15
17
|
"directory": "packages/storage-local"
|
|
16
18
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"types": "./dist/index.d.mts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"source": "./src/index.ts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
20
31
|
},
|
|
21
32
|
"publishConfig": {
|
|
22
|
-
"access": "public",
|
|
23
33
|
"exports": {
|
|
24
34
|
".": "./dist/index.mjs",
|
|
25
35
|
"./package.json": "./package.json"
|
|
26
|
-
}
|
|
36
|
+
},
|
|
37
|
+
"access": "public"
|
|
27
38
|
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
39
|
"scripts": {
|
|
32
40
|
"build": "tsdown",
|
|
33
41
|
"dev": "tsdown -w",
|
|
34
|
-
"fmt": "oxfmt
|
|
42
|
+
"fmt": "oxfmt ./src",
|
|
35
43
|
"lint": "oxlint --type-aware --type-check ./src",
|
|
36
44
|
"test": "vitest run",
|
|
37
45
|
"prepublishOnly": "nub run build"
|
|
38
46
|
},
|
|
39
47
|
"dependencies": {
|
|
40
|
-
"@storyshelf/core": "
|
|
48
|
+
"@storyshelf/core": "^0.1.2"
|
|
41
49
|
},
|
|
42
50
|
"devDependencies": {
|
|
43
51
|
"@types/node": "catalog:",
|
|
@@ -49,12 +57,13 @@
|
|
|
49
57
|
"typescript": "catalog:",
|
|
50
58
|
"vitest": "catalog:"
|
|
51
59
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
"jsr": {
|
|
61
|
+
"runtimeCompat": {
|
|
62
|
+
"node": true,
|
|
63
|
+
"deno": true,
|
|
64
|
+
"browser": false,
|
|
65
|
+
"workerd": false,
|
|
66
|
+
"bun": true
|
|
67
|
+
}
|
|
59
68
|
}
|
|
60
69
|
}
|