@camstack/core 0.1.0 → 0.1.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.
@@ -0,0 +1,89 @@
1
+ // src/storage/storage-location-manager.ts
2
+ import { join as join2, isAbsolute as isAbsolute2 } from "path";
3
+
4
+ // src/storage/fs-storage-backend.ts
5
+ import { existsSync, mkdirSync, accessSync, constants } from "fs";
6
+ import { join, resolve, isAbsolute } from "path";
7
+ var FsStorageBackend = class {
8
+ type = "local";
9
+ basePath;
10
+ constructor(basePath) {
11
+ this.basePath = resolve(basePath);
12
+ }
13
+ resolve(subpath) {
14
+ if (isAbsolute(subpath)) return subpath;
15
+ return join(this.basePath, subpath);
16
+ }
17
+ isAvailable() {
18
+ try {
19
+ if (!existsSync(this.basePath)) return false;
20
+ accessSync(this.basePath, constants.W_OK);
21
+ return true;
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ async initialize() {
27
+ mkdirSync(this.basePath, { recursive: true });
28
+ }
29
+ };
30
+
31
+ // src/storage/storage-location-manager.ts
32
+ var StorageLocationManager = class {
33
+ backends = /* @__PURE__ */ new Map();
34
+ dataPath;
35
+ constructor(dataPath) {
36
+ this.dataPath = dataPath;
37
+ }
38
+ /** Initialize all locations with default paths */
39
+ async initializeDefaults() {
40
+ const defaults = {
41
+ data: join2(this.dataPath, "db"),
42
+ media: join2(this.dataPath, "media"),
43
+ recordings: join2(this.dataPath, "recordings"),
44
+ models: join2(this.dataPath, "models"),
45
+ cache: "/tmp/camstack-cache",
46
+ logs: join2(this.dataPath, "logs")
47
+ };
48
+ for (const [name, path] of Object.entries(defaults)) {
49
+ const backend = new FsStorageBackend(path);
50
+ await backend.initialize();
51
+ this.backends.set(name, backend);
52
+ }
53
+ }
54
+ /** Override a specific location's backend path */
55
+ async setLocationPath(name, basePath) {
56
+ const resolved = isAbsolute2(basePath) ? basePath : join2(this.dataPath, basePath);
57
+ const backend = new FsStorageBackend(resolved);
58
+ await backend.initialize();
59
+ this.backends.set(name, backend);
60
+ }
61
+ /** Get the backend for a location */
62
+ getBackend(name) {
63
+ const backend = this.backends.get(name);
64
+ if (!backend) throw new Error(`Storage location "${name}" not initialized`);
65
+ return backend;
66
+ }
67
+ /** Resolve a path within a location */
68
+ resolve(location, subpath) {
69
+ return this.getBackend(location).resolve(subpath);
70
+ }
71
+ /** Check if all locations are available */
72
+ getStatus() {
73
+ return Array.from(this.backends.entries()).map(([name, backend]) => ({
74
+ name,
75
+ available: backend.isAvailable(),
76
+ path: backend.basePath
77
+ }));
78
+ }
79
+ /** All location names */
80
+ getLocationNames() {
81
+ return Array.from(this.backends.keys());
82
+ }
83
+ };
84
+
85
+ export {
86
+ FsStorageBackend,
87
+ StorageLocationManager
88
+ };
89
+ //# sourceMappingURL=chunk-2F3XZYRW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/storage/storage-location-manager.ts","../src/storage/fs-storage-backend.ts"],"sourcesContent":["import { join, isAbsolute } from 'node:path'\nimport { FsStorageBackend, type IStorageBackend } from './fs-storage-backend.js'\n\nexport type StorageLocationName = 'data' | 'media' | 'recordings' | 'models' | 'cache' | 'logs'\n\nexport class StorageLocationManager {\n private readonly backends: Map<StorageLocationName, IStorageBackend> = new Map()\n private readonly dataPath: string\n\n constructor(dataPath: string) {\n this.dataPath = dataPath\n }\n\n /** Initialize all locations with default paths */\n async initializeDefaults(): Promise<void> {\n const defaults: Record<StorageLocationName, string> = {\n data: join(this.dataPath, 'db'),\n media: join(this.dataPath, 'media'),\n recordings: join(this.dataPath, 'recordings'),\n models: join(this.dataPath, 'models'),\n cache: '/tmp/camstack-cache',\n logs: join(this.dataPath, 'logs'),\n }\n\n for (const [name, path] of Object.entries(defaults)) {\n const backend = new FsStorageBackend(path)\n await backend.initialize()\n this.backends.set(name as StorageLocationName, backend)\n }\n }\n\n /** Override a specific location's backend path */\n async setLocationPath(name: StorageLocationName, basePath: string): Promise<void> {\n const resolved = isAbsolute(basePath) ? basePath : join(this.dataPath, basePath)\n const backend = new FsStorageBackend(resolved)\n await backend.initialize()\n this.backends.set(name, backend)\n }\n\n /** Get the backend for a location */\n getBackend(name: StorageLocationName): IStorageBackend {\n const backend = this.backends.get(name)\n if (!backend) throw new Error(`Storage location \"${name}\" not initialized`)\n return backend\n }\n\n /** Resolve a path within a location */\n resolve(location: StorageLocationName, subpath: string): string {\n return this.getBackend(location).resolve(subpath)\n }\n\n /** Check if all locations are available */\n getStatus(): Array<{ name: StorageLocationName; available: boolean; path: string }> {\n return Array.from(this.backends.entries()).map(([name, backend]) => ({\n name,\n available: backend.isAvailable(),\n path: backend.basePath,\n }))\n }\n\n /** All location names */\n getLocationNames(): StorageLocationName[] {\n return Array.from(this.backends.keys())\n }\n}\n","import { existsSync, mkdirSync, accessSync, constants } from 'node:fs'\nimport { join, resolve, isAbsolute } from 'node:path'\n\nexport interface IStorageBackend {\n /** Backend type identifier */\n readonly type: string\n /** Base path of this backend */\n readonly basePath: string\n /** Resolve a subpath to an absolute path */\n resolve(subpath: string): string\n /** Check if the backend path exists and is writable */\n isAvailable(): boolean\n /** Ensure base directory exists (mkdir -p equivalent) */\n initialize(): Promise<void>\n}\n\nexport class FsStorageBackend implements IStorageBackend {\n readonly type = 'local'\n readonly basePath: string\n\n constructor(basePath: string) {\n this.basePath = resolve(basePath)\n }\n\n resolve(subpath: string): string {\n if (isAbsolute(subpath)) return subpath\n return join(this.basePath, subpath)\n }\n\n isAvailable(): boolean {\n try {\n if (!existsSync(this.basePath)) return false\n accessSync(this.basePath, constants.W_OK)\n return true\n } catch {\n return false\n }\n }\n\n async initialize(): Promise<void> {\n mkdirSync(this.basePath, { recursive: true })\n }\n}\n"],"mappings":";AAAA,SAAS,QAAAA,OAAM,cAAAC,mBAAkB;;;ACAjC,SAAS,YAAY,WAAW,YAAY,iBAAiB;AAC7D,SAAS,MAAM,SAAS,kBAAkB;AAenC,IAAM,mBAAN,MAAkD;AAAA,EAC9C,OAAO;AAAA,EACP;AAAA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C,UAAM,QAAQ,WAAW;AACzB,SAAK,SAAS,IAAI,MAAM,OAAO;AAAA,EACjC;AAAA;AAAA,EAGA,WAAW,MAA4C;AACrD,UAAM,UAAU,KAAK,SAAS,IAAI,IAAI;AACtC,QAAI,CAAC,QAAS,OAAM,IAAI,MAAM,qBAAqB,IAAI,mBAAmB;AAC1E,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,QAAQ,UAA+B,SAAyB;AAC9D,WAAO,KAAK,WAAW,QAAQ,EAAE,QAAQ,OAAO;AAAA,EAClD;AAAA;AAAA,EAGA,YAAoF;AAClF,WAAO,MAAM,KAAK,KAAK,SAAS,QAAQ,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,OAAO,OAAO;AAAA,MACnE;AAAA,MACA,WAAW,QAAQ,YAAY;AAAA,MAC/B,MAAM,QAAQ;AAAA,IAChB,EAAE;AAAA,EACJ;AAAA;AAAA,EAGA,mBAA0C;AACxC,WAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;AAAA,EACxC;AACF;","names":["join","isAbsolute","join","isAbsolute"]}
@@ -0,0 +1,38 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ export {
34
+ __require,
35
+ __commonJS,
36
+ __toESM
37
+ };
38
+ //# sourceMappingURL=chunk-LZOMFHX3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}