// @push.rocks scope import * as smartdata from '@push.rocks/smartdata'; import * as smartunique from '@push.rocks/smartunique'; import * as smarttime from '@push.rocks/smarttime'; import * as smartlog from '@push.rocks/smartlog'; import * as smartfsModule from '@push.rocks/smartfs'; import * as smarthash from '@push.rocks/smarthash'; import * as smartpath from '@push.rocks/smartpath'; import * as path from 'path'; // third party import { MerkleTree } from 'merkletreejs'; const smartfs = new smartfsModule.SmartFs( new smartfsModule.SmartFsProviderNode(), ); const smartfile = { fs: { ensureDir: async (dirPath: string): Promise => { await smartfs.directory(dirPath).create(); }, toBuffer: async (filePath: string): Promise => { return (await smartfs.file(filePath).read()) as Buffer; }, toStringSync: async (filePath: string): Promise => { return (await smartfs.file(filePath).encoding('utf8').read()) as string; }, fileExists: async (filePath: string): Promise => { return await smartfs.file(filePath).exists(); }, listFileTree: async (dirPath: string, pattern: string): Promise => { const suffix = pattern.replace(/^\*\*\/\*/, ''); try { const entries = await smartfs.directory(dirPath).recursive().list(); return entries .filter((entry) => entry.isFile && entry.path.endsWith(suffix)) .map((entry) => path.relative(dirPath, entry.path)); } catch (error) { if (error instanceof Error && error.message.includes('ENOENT')) { return []; } throw error; } }, }, memory: { toFs: async (content: string | Buffer, filePath: string): Promise => { await smartfs.directory(path.dirname(filePath)).create(); await smartfs.file(filePath).write(content); }, }, }; export { smartdata, smartunique, smarttime, smartlog, smartfs, smartfile, smarthash, smartpath, MerkleTree, };