mindspace: version runtime contracts and audit packages

This commit is contained in:
john
2026-07-27 17:43:38 +08:00
parent e94052ff24
commit 70264a4c4c
23 changed files with 1448 additions and 20 deletions
+38
View File
@@ -2,10 +2,44 @@ import fs from 'node:fs';
import fsp from 'node:fs/promises';
import path from 'node:path';
export const MINDSPACE_STORAGE_ADAPTER_CONTRACT_VERSION = 1;
export const MINDSPACE_STORAGE_ADAPTER_REQUIRED_METHODS = Object.freeze([
'putObject',
'getObject',
'statObject',
'listObjects',
'listPrefix',
'deleteObject',
'copyObject',
'createReadStream',
'createWriteStream',
'getSignedUrl',
]);
function storageError(message, code, details = {}) {
return Object.assign(new Error(message), { code, ...details });
}
export function assertMindSpaceStorageAdapterContract(adapter) {
if (!adapter || typeof adapter !== 'object') {
throw storageError(
'MindSpace storage adapter is required',
'missing_storage_adapter',
);
}
for (const method of MINDSPACE_STORAGE_ADAPTER_REQUIRED_METHODS) {
if (typeof adapter[method] !== 'function') {
throw storageError(
`MindSpace storage adapter is missing ${method}()`,
'invalid_storage_adapter',
{ method },
);
}
}
return adapter;
}
export function normalizeMindSpaceStorageKey(key) {
const raw = String(key ?? '').trim();
if (!raw) {
@@ -125,6 +159,10 @@ export function createLocalMindSpaceStorageAdapter(storageRoot) {
return results.sort((a, b) => a.key.localeCompare(b.key));
},
async listPrefix(prefix = '') {
return this.listObjects(prefix);
},
async copyObject(sourceKey, targetKey) {
const source = resolveStoragePath(root, sourceKey);
const target = resolveStoragePath(root, targetKey);