fix(exports): stabilize published types and compatibility with updated dependencies
This commit is contained in:
+53
-16
@@ -3,26 +3,63 @@ 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 smartfile from '@push.rocks/smartfile';
|
||||
import * as smartfsModule from '@push.rocks/smartfs';
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpdf from '@push.rocks/smartpdf';
|
||||
import * as path from 'path';
|
||||
|
||||
// third party
|
||||
import * as nodeForge from 'node-forge';
|
||||
import { MerkleTree } from 'merkletreejs';
|
||||
import * as einvoice from '@fin.cx/einvoice';
|
||||
|
||||
export {
|
||||
smartdata,
|
||||
smartunique,
|
||||
smarttime,
|
||||
smartlog,
|
||||
smartfile,
|
||||
smarthash,
|
||||
smartpath,
|
||||
smartpdf,
|
||||
nodeForge,
|
||||
MerkleTree,
|
||||
einvoice
|
||||
const smartfs = new smartfsModule.SmartFs(
|
||||
new smartfsModule.SmartFsProviderNode(),
|
||||
);
|
||||
|
||||
const smartfile = {
|
||||
fs: {
|
||||
ensureDir: async (dirPath: string): Promise<void> => {
|
||||
await smartfs.directory(dirPath).create();
|
||||
},
|
||||
toBuffer: async (filePath: string): Promise<Buffer> => {
|
||||
return (await smartfs.file(filePath).read()) as Buffer;
|
||||
},
|
||||
toStringSync: async (filePath: string): Promise<string> => {
|
||||
return (await smartfs.file(filePath).encoding('utf8').read()) as string;
|
||||
},
|
||||
fileExists: async (filePath: string): Promise<boolean> => {
|
||||
return await smartfs.file(filePath).exists();
|
||||
},
|
||||
listFileTree: async (dirPath: string, pattern: string): Promise<string[]> => {
|
||||
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<void> => {
|
||||
await smartfs.directory(path.dirname(filePath)).create();
|
||||
await smartfs.file(filePath).write(content);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export {
|
||||
smartdata,
|
||||
smartunique,
|
||||
smarttime,
|
||||
smartlog,
|
||||
smartfs,
|
||||
smartfile,
|
||||
smarthash,
|
||||
smartpath,
|
||||
MerkleTree,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user