Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Volume = void 0;
|
||||
exports.createVolumes = createVolumes;
|
||||
const fs = __importStar(require("node:fs/promises"));
|
||||
/**
|
||||
* @description Represents a volume in the StartOS filesystem.
|
||||
* Provides utilities for reading and writing files within the volume.
|
||||
*/
|
||||
class Volume {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.path = `/media/startos/volumes/${id}`;
|
||||
}
|
||||
/**
|
||||
* Get the absolute path to a file or directory within this volume
|
||||
* @param subpath Path relative to the volume root
|
||||
*/
|
||||
subpath(subpath) {
|
||||
return subpath.startsWith('/')
|
||||
? `${this.path}${subpath}`
|
||||
: `${this.path}/${subpath}`;
|
||||
}
|
||||
/**
|
||||
* @description Read a file from this volume
|
||||
* @param subpath Path relative to the volume root (e.g. "config.json" or "/data/file.txt")
|
||||
* @param options Optional read options (same as node:fs/promises readFile)
|
||||
*/
|
||||
async readFile(subpath, options) {
|
||||
const fullPath = this.subpath(subpath);
|
||||
return fs.readFile(fullPath, options);
|
||||
}
|
||||
/**
|
||||
* @description Write a file to this volume
|
||||
* @param subpath Path relative to the volume root (e.g. "config.json" or "/data/file.txt")
|
||||
* @param data The data to write
|
||||
* @param options Optional write options (same as node:fs/promises writeFile)
|
||||
*/
|
||||
async writeFile(subpath, data, options) {
|
||||
const fullPath = this.subpath(subpath);
|
||||
const dir = fullPath.replace(/\/[^/]*\/?$/, '');
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
return fs.writeFile(fullPath, data, options);
|
||||
}
|
||||
}
|
||||
exports.Volume = Volume;
|
||||
/**
|
||||
* Creates a type-safe volumes object from a manifest
|
||||
*/
|
||||
function createVolumes(manifest) {
|
||||
const volumes = {};
|
||||
for (const volumeId of manifest.volumes) {
|
||||
;
|
||||
volumes[volumeId] = new Volume(volumeId);
|
||||
}
|
||||
return volumes;
|
||||
}
|
||||
//# sourceMappingURL=Volume.js.map
|
||||
Reference in New Issue
Block a user