@krantho/media-local 0.0.0-stage → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Descoped
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.
@@ -0,0 +1,2 @@
1
+ export { createLocalFileStore, LocalFileStore } from './local-file-store.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createLocalFileStore, LocalFileStore } from './local-file-store.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { LocalMediaSection } from '@krantho/config';
2
+ import type { IFileStore, StoredFile } from '@krantho/persistence';
3
+ /** File store on local disk; the host framework serves `dir` at `urlPrefix` */
4
+ export declare class LocalFileStore implements IFileStore {
5
+ readonly label = "Local disk";
6
+ readonly location: string;
7
+ private readonly urlPrefix;
8
+ constructor(section: LocalMediaSection);
9
+ put(key: string, bytes: Uint8Array, _contentType: string): Promise<StoredFile>;
10
+ get(key: string): Promise<Uint8Array | null>;
11
+ copy(fromKey: string, toKey: string, _contentType: string): Promise<StoredFile>;
12
+ delete(key: string): Promise<void>;
13
+ private pathOf;
14
+ private stored;
15
+ }
16
+ export declare function createLocalFileStore(section: LocalMediaSection): IFileStore;
17
+ //# sourceMappingURL=local-file-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-file-store.d.ts","sourceRoot":"","sources":["../src/local-file-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AASlE,+EAA+E;AAC/E,qBAAa,cAAe,YAAW,UAAU;IAC/C,QAAQ,CAAC,KAAK,gBAAe;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;gBAEtB,OAAO,EAAE,iBAAiB;IAKhC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAO9E,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAU5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ/E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,MAAM;CAGf;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAE3E"}
@@ -0,0 +1,56 @@
1
+ import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ /** Flat keys only: no separators, no leading dot — nothing can escape the directory */
4
+ const KEY_PATTERN = /^[a-z0-9][a-z0-9._-]*$/;
5
+ function isNotFound(error) {
6
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
7
+ }
8
+ /** File store on local disk; the host framework serves `dir` at `urlPrefix` */
9
+ export class LocalFileStore {
10
+ label = 'Local disk';
11
+ location;
12
+ urlPrefix;
13
+ constructor(section) {
14
+ this.location = section.dir;
15
+ this.urlPrefix = section.urlPrefix;
16
+ }
17
+ async put(key, bytes, _contentType) {
18
+ const path = this.pathOf(key);
19
+ await mkdir(this.location, { recursive: true });
20
+ await writeFile(path, bytes);
21
+ return this.stored(key);
22
+ }
23
+ async get(key) {
24
+ const path = this.pathOf(key);
25
+ try {
26
+ return new Uint8Array(await readFile(path));
27
+ }
28
+ catch (error) {
29
+ if (isNotFound(error))
30
+ return null;
31
+ throw error;
32
+ }
33
+ }
34
+ async copy(fromKey, toKey, _contentType) {
35
+ const from = this.pathOf(fromKey);
36
+ const to = this.pathOf(toKey);
37
+ await mkdir(this.location, { recursive: true });
38
+ await copyFile(from, to);
39
+ return this.stored(toKey);
40
+ }
41
+ async delete(key) {
42
+ await rm(this.pathOf(key), { force: true });
43
+ }
44
+ pathOf(key) {
45
+ if (!KEY_PATTERN.test(key))
46
+ throw new Error(`Invalid file key: ${key}`);
47
+ return join(this.location, key);
48
+ }
49
+ stored(key) {
50
+ return { key, url: `${this.urlPrefix}/${key}` };
51
+ }
52
+ }
53
+ export function createLocalFileStore(section) {
54
+ return new LocalFileStore(section);
55
+ }
56
+ //# sourceMappingURL=local-file-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-file-store.js","sourceRoot":"","sources":["../src/local-file-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,uFAAuF;AACvF,MAAM,WAAW,GAAG,wBAAwB,CAAA;AAE5C,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAA;AAC7E,CAAC;AAED,+EAA+E;AAC/E,MAAM,OAAO,cAAc;IAChB,KAAK,GAAG,YAAY,CAAA;IACpB,QAAQ,CAAQ;IACR,SAAS,CAAQ;IAElC,YAAY,OAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAA;QAC3B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAiB,EAAE,YAAoB;QAC5D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC7B,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC/C,MAAM,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,IAAI,GA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oB,CAAC,OAA0B;IAC7D,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAA;AACpC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@krantho/media-local",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.1",
4
+ "description": "The krantho media file store on local disk, for development and single servers with a persistent volume.",
5
+ "license": "MIT",
6
+ "homepage": "https://krantho.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/descoped/krantho.git",
10
+ "directory": "packages/media-local"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/descoped/krantho/issues"
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./dist/index.js",
19
+ "types": "./dist/index.d.ts"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@krantho/config": "1.0.1",
27
+ "@krantho/persistence": "1.0.1"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^25.9.9",
31
+ "typescript": "^6.0.3"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc",
35
+ "typecheck": "tsc --noEmit",
36
+ "clean": "rm -rf dist"
37
+ }
6
38
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.