0.0.11-alpha: allow cache loading from zip

Signed-off-by: T-Hax <>
This commit is contained in:
T-Hax 2023-05-13 19:30:21 +00:00
parent 30f6f2186a
commit d1d23f252a
46 changed files with 228 additions and 394 deletions

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

2
.gitignore vendored
View File

@ -47,7 +47,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

8
.yarn/versions/d97618ff.yml vendored Normal file
View File

@ -0,0 +1,8 @@
undecided:
- "@tornado/sdk-monorepo"
- "@tornado/sdk"
- "@tornado/sdk-chain"
- "@tornado/sdk-core"
- "@tornado/sdk-crypto"
- "@tornado/sdk-data"
- "@tornado/sdk-utils"

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,13 +13,13 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*"
"dist/**/*"
],
"dependencies": {
"@ethersproject/abi": "^5.7.0",
@ -62,16 +62,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"typechain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./src/resources/abis/*.json\" --out-dir=\"./src/types/deth\"",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/**/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/**/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,13 +13,13 @@
"crypto",
"zk"
],
"version": "0.0.10-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*"
"dist/**/*"
],
"dependencies": {
"@ethersproject/abi": "^5.7.0",
@ -65,16 +65,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"typechain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./src/resources/abis/*.json\" --out-dir=\"./src/types/deth\"",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/**/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/**/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -701,9 +701,10 @@ export class Core extends Synchronizer {
release()
}
async exportAsArchive(cacheName: string, outDirPath?: string, debug?: boolean): Promise<void> {
async exportCacheZip(cacheName: string, outDirPath?: string, close?: boolean): Promise<void> {
const cache = this.loadCache<Cache.Base<Docs.Base>>(cacheName)
await cache.exportAsArchive(outDirPath, debug)
await cache.zip(outDirPath, close)
if (close) this.caches.delete(cacheName)
}
loadDepositCache(name: string, options?: Options.Sync): DepositCache {

View File

@ -16,7 +16,7 @@
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"preserveSymlinks": true,
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,13 +13,13 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*"
"dist/**/*"
],
"dependencies": {
"@tornado/sdk-data": "workspace:*",
@ -57,16 +57,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"typechain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./src/resources/abis/*.json\" --out-dir=\"./src/types/deth\"",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,26 +13,25 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*",
"dist/**/*",
"resources",
"resources/**/*"
],
"dependencies": {
"@tornado/sdk-utils": "workspace:*",
"archiver": "^5.3.1",
"ethers": "^5",
"pouchdb": "^8.0.1",
"pouchdb-adapter-memory": "^8.0.1",
"pouchdb-collate": "^8.0.1"
"pouchdb-collate": "^8.0.1",
"tar": "^6.1.14"
},
"devDependencies": {
"@types/archiver": "^5.3.2",
"@types/big-integer": "^0.0.31",
"@types/chai": "^4.2.18",
"@types/fs-extra": "^11.0.1",
@ -40,6 +39,7 @@
"@types/node": "^18.15.0",
"@types/pouchdb": "^6.4.0",
"@types/pouchdb-adapter-memory": "^6.1.3",
"@types/tar": "^6.1.5",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"@uniswap/default-token-list": "^9.3.0",
@ -61,16 +61,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"typechain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./src/resources/abis/*.json\" --out-dir=\"./src/types/deth\"",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -1,9 +1,14 @@
// Big modules
import { BigNumber } from 'ethers'
import { existsSync, mkdirSync, readFileSync, createWriteStream } from 'fs'
// Archiving and zipping
import tar from 'tar'
// Fs
import { existsSync, mkdirSync, readFileSync } from 'fs'
import { opendir, readFile, rm } from 'fs/promises'
import { createInterface } from 'readline'
// Ethers
import { BigNumber } from 'ethers'
// Local logic
import { AsyncUtils, NumberUtils, ErrorUtils } from '@tornado/sdk-utils'
@ -11,9 +16,6 @@ import { AsyncUtils, NumberUtils, ErrorUtils } from '@tornado/sdk-utils'
import PouchDB from 'pouchdb'
import * as PouchDBAdapterMemory from 'pouchdb-adapter-memory'
// Archiving
import archiver from 'archiver'
// @ts-ignore
import { toIndexableString } from 'pouchdb-collate'
@ -72,12 +74,25 @@ export namespace Options {
export namespace Files {
export type PathGetter = (relative: string) => string
export const getModulesPath = (relative: string, prefix?: string): string =>
(prefix ?? __dirname + '/../../node_modules/') + relative
export const getResourcePath = (relative: string, prefix?: string): string =>
(prefix ?? __dirname + '/../resources/') + relative
export const getCachePath = (relative: string, prefix?: string): string =>
(prefix ?? process.cwd() + '/cache/') + relative
export function parentPath(filepath: string): string {
let path = filepath.split('/').slice(0, -1).join('/')
path = path[path.length - 1] === '/' ? path : path + '/'
return path
}
export function stripExtensions(filepath: string): string {
const tokens = filepath.split('/')
const stripped = tokens[tokens.length - 1].split('.')[0]
const prefix = tokens.slice(0, -1).join('/')
return prefix + (prefix !== '' ? '/' : '') + stripped
}
export const getModulesPath = (relative?: string, prefix?: string): string =>
(prefix ?? __dirname + '/../../node_modules/') + (relative ?? '')
export const getResourcePath = (relative?: string, prefix?: string): string =>
(prefix ?? __dirname + '/../resources/') + (relative ?? '')
export const getCachePath = (relative?: string, prefix?: string): string =>
(prefix ?? process.cwd() + '/cache/') + (relative ?? '')
export const cacheDirExists = (prefix?: string): boolean => existsSync(getCachePath('', prefix))
export const makeCacheDir = (prefix?: string): void => mkdirSync(getCachePath('', prefix))
@ -85,13 +100,42 @@ export namespace Files {
export const loadRaw = (relative: string): Promise<Buffer> => readFile(getResourcePath(relative))
export const loadRawSync = (relative: string): Buffer => readFileSync(getResourcePath(relative))
export async function wipeCache(prompt: boolean = true): Promise<void> {
const dir = await opendir(getCachePath(''))
export function gzipSync(fileOrDirPath: string, archivePath: string): void {
try {
const tokens = fileOrDirPath.split('/')
tar.create(
{
cwd: parentPath(fileOrDirPath),
file: stripExtensions(archivePath) + '.tar.gz',
gzip: true,
sync: true
},
[tokens[tokens.length - 1]]
)
} catch (err) {
throw ErrorUtils.ensureError(err)
}
}
export function gunzipSync(archivePath: string, extractPath: string): void {
try {
tar.extract({
cwd: extractPath,
file: stripExtensions(archivePath) + '.tar.gz',
sync: true
})
} catch (err) {
throw ErrorUtils.ensureError(err)
}
}
export async function wipeCache(prompt: boolean = true, cachePath?: string): Promise<void> {
const dir = await opendir(getCachePath('', cachePath))
const toRemove: string[] = []
const userInput = createInterface({ input: process.stdin, output: process.stdout })
for await (const entry of dir) {
if (entry.name.match('(Deposit.*)|(Withdrawal.*)|(Note.*)|(Invoice.*)'))
toRemove.push(getCachePath(entry.name))
toRemove.push(getCachePath(entry.name, cachePath))
}
if (toRemove.length != 0) {
if (prompt) {
@ -601,6 +645,14 @@ export namespace Cache {
name: string
db: PouchDB.Database<T>
private _unzip(cachePath?: string): void {
if (existsSync(this._path + '.tar.gz')) {
if (existsSync(this._path)) {
throw ErrorUtils.getError(`Can't load both ${this.name} and ${this.name + '.tar.gz'}, remove one!`)
} else Files.gunzipSync(this._path, Files.getCachePath('', cachePath))
}
}
constructor(name: string, options?: Options.Cache) {
this.name = name
@ -621,55 +673,19 @@ export namespace Cache {
this._adapter = dbAdapter
this._unzip(options?.cachePath)
this.db = new PouchDB<T>(this._path, { adapter: dbAdapter })
}
async exportAsArchive(outDirPath?: string, debug: boolean = false): Promise<void> {
async zip(outDirPath?: string, close: boolean = false): Promise<void> {
await this.close()
if (outDirPath) outDirPath = outDirPath[outDirPath.length - 1] != '/' ? outDirPath + '/' : outDirPath
if (outDirPath) outDirPath = outDirPath[outDirPath.length - 1] !== '/' ? outDirPath + '/' : outDirPath
const outStream = createWriteStream((outDirPath ?? Files.getCachePath('')) + this.name + '.zip')
Files.gzipSync(this._path, (outDirPath ?? Files.parentPath(this._path)) + this.name)
const archive = archiver('zip', {
zlib: {
level: 9
}
})
// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
if (debug)
outStream.on('close', function () {
console.debug('Cache.exportAsArchive: ' + archive.pointer() + ' total bytes written.')
console.debug('Cache.exportAsArchive: fo closed.')
})
// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
if (debug)
outStream.on('end', function () {
console.log('Cache.exportAsArchive: drained.')
})
archive.on('warning', (err) => {
if (err.code != 'ENOENT') throw ErrorUtils.ensureError(err)
})
archive.on('error', (err) => {
throw ErrorUtils.ensureError(err)
})
archive.pipe(outStream)
archive.directory(this._path, this.name)
await archive.finalize()
outStream.close()
this.db = new PouchDB<T>(this._path, { adapter: this._adapter })
if (!close) this.db = new PouchDB<T>(this._path, { adapter: this._adapter })
}
async get(keys: Array<any>): Promise<T> {

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,13 +13,13 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*"
"dist/**/*"
],
"dependencies": {
"ethers": "^5",
@ -51,15 +51,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,13 +13,13 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"files": [
"build/**/*"
"dist/**/*"
],
"dependencies": {
"@ethersproject/providers": "^5.7.2",
@ -58,16 +58,10 @@
"typescript": "^5.0.4"
},
"scripts": {
"test": "npm run build && mocha --inspect --require source-map-support/register --bail ./build/test/",
"typechain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./src/resources/abis/*.json\" --out-dir=\"./src/types/deth\"",
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -44,7 +44,7 @@ pids
typings/
node_modules
build
dist
sandbox
sand\ box
debug.log

View File

@ -1,3 +1,3 @@
build
dist
node_modules
package-log.json

View File

@ -13,10 +13,14 @@
"crypto",
"zk"
],
"version": "0.0.10-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./dist/index.js",
"files": [
"dist/**/*"
],
"dependencies": {
"@tornado/sdk-chain": "workspace:*",
"@tornado/sdk-core": "workspace:*",
@ -40,19 +44,11 @@
"typedoc": "^0.24.6",
"typescript": "^5.0.4"
},
"main": "./build/index.js",
"files": [
"build/**/*"
],
"scripts": {
"build": "rimraf build && tsc && tsc-alias",
"preversion": "npm run lint && npm run build && npm test",
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && npm run format && git add -A",
"postversion": "git push --follow-tags && npm publish",
"lint": "eslint --ext ts,js --fix src",
"build-live": "tsc -w && tsc-alias -w",
"clean": "rm -rf --interactive=never docs/*",
"format": "prettier src/*.ts -w"
"build": "rimraf dist && tsc",
"format": "prettier src/*.ts -w",
"build-live": "rimraf dist && tsc -w",
"lint": "eslint --ext ts,js --fix src"
},
"publishConfig": {
"access": "public"

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

View File

@ -110,7 +110,7 @@ async function sync() {
await core.syncDeposits(instance)
// Now export it as an archive!
await core.exportAsArchive('Deposits1ETH0.1')
await core.exportCacheZip('Deposits1ETH0.1')
}
sync()
@ -146,7 +146,7 @@ async function sync() {
)
// Export as archive again!
await core.exportAsArchive('Deposits1ETH0.1')
await core.exportCacheZip('Deposits1ETH0.1')
}
sync()

View File

@ -10,11 +10,11 @@
"crypto",
"zk"
],
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"engines": {
"node": "^18"
},
"main": "./build/index.js",
"main": "./dist/index.js",
"private": true,
"workspaces": [
"@tornado/*"
@ -54,6 +54,7 @@
"typescript": "^5.0.4"
},
"scripts": {
"build": "",
"test": "yarn run ts-mocha",
"test:fresh": "yarn clean:cache && yarn refresh:cache && yarn test",
"format": "prettier test/*.ts -w",
@ -92,11 +93,6 @@
"typechain:chain": "typechain --target \"ethers-v5\" --discriminate-types --glob \"./abis/*.json\" --out-dir=\"./@tornado/sdk-chain/src/deth\"",
"packall": "mkdir -p packages && yarn workspaces foreach --no-private pack --out \"../../packages/%s-@%v.zip\" && rename -a '@' '' packages/*"
},
"files": [
"build/lib/**/*",
"build/index.*",
"build/types/**/*"
],
"publishConfig": {
"access": "public"
},

View File

@ -1,7 +1,7 @@
import chai from 'chai'
import { ErrorUtils } from '@tornado/sdk-utils'
import { Cache } from '@tornado/sdk-data'
import { Cache, Files } from '@tornado/sdk-data'
const expect = chai.expect
@ -9,8 +9,18 @@ describe('data', () => {
if (!process.env.EXPORT_TEST_DIRNAME)
throw ErrorUtils.getError('data.test.ts: no cache test dirname provided')
it(`Cache.exportAsArchive: should be able to export ${process.env.EXPORT_TEST_DIRNAME}`, async () => {
it(`Files.gzipSync: should be able to zip dir`, () => {
const filepath = Files.getCachePath(process.env.EXPORT_TEST_DIRNAME!)
Files.gzipSync(filepath, filepath)
})
it(`Files.gunzipSync: should be able to unzip dir`, () => {
const filepath = Files.getCachePath(process.env.EXPORT_TEST_DIRNAME!)
Files.gunzipSync(filepath, Files.getCachePath())
})
it(`Cache.zip: should be able to zip or load from zip ${process.env.EXPORT_TEST_DIRNAME}`, async () => {
const cache = new Cache.Base(process.env.EXPORT_TEST_DIRNAME!)
await cache.exportAsArchive(undefined, true)
await cache.zip(undefined, true)
}).timeout(0)
})

View File

@ -15,7 +15,7 @@
"skipLibCheck": true,
"moduleResolution": "node",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"outDir": "./build",
"outDir": "./dist",
"resolveJsonModule": true,
"declaration": true,
"declarationMap": true,

238
yarn.lock
View File

@ -1130,7 +1130,6 @@ __metadata:
resolution: "@tornado/sdk-data@workspace:@tornado/sdk-data"
dependencies:
"@tornado/sdk-utils": "workspace:*"
"@types/archiver": ^5.3.2
"@types/big-integer": ^0.0.31
"@types/chai": ^4.2.18
"@types/fs-extra": ^11.0.1
@ -1138,10 +1137,10 @@ __metadata:
"@types/node": ^18.15.0
"@types/pouchdb": ^6.4.0
"@types/pouchdb-adapter-memory": ^6.1.3
"@types/tar": ^6.1.5
"@typescript-eslint/eslint-plugin": ^5.54.1
"@typescript-eslint/parser": ^5.54.1
"@uniswap/default-token-list": ^9.3.0
archiver: ^5.3.1
chai: ^4.3.4
conventional-changelog-cli: ^2.1.1
dotenv: ^16.0.3
@ -1157,6 +1156,7 @@ __metadata:
prettier: ^2.3.0
rimraf: ^5.0.0
source-map-support: ^0.5.19
tar: ^6.1.14
ts-essentials: ^9.3.1
ts-node: ^10.9.1
tsc-alias: ^1.2.11
@ -1429,15 +1429,6 @@ __metadata:
languageName: node
linkType: hard
"@types/archiver@npm:^5.3.2":
version: 5.3.2
resolution: "@types/archiver@npm:5.3.2"
dependencies:
"@types/readdir-glob": "*"
checksum: 9db5b4fdc1740fa07d08340ed827598cc6eda97406ac18a06a158670c7124d4120650a3b9cd660e9e39b42f033cf8f052566da32681e8ad91163473df88a3c4c
languageName: node
linkType: hard
"@types/big-integer@npm:^0.0.31":
version: 0.0.31
resolution: "@types/big-integer@npm:0.0.31"
@ -1831,15 +1822,6 @@ __metadata:
languageName: node
linkType: hard
"@types/readdir-glob@npm:*":
version: 1.1.1
resolution: "@types/readdir-glob@npm:1.1.1"
dependencies:
"@types/node": "*"
checksum: cc888be86e729c1e2f799a926c091b464d58016aaee69e08b58878668ec0137e985236775a3eaac14273554bf45c7da92fe19b900370f8d02f47a32709000ba8
languageName: node
linkType: hard
"@types/responselike@npm:^1.0.0":
version: 1.0.0
resolution: "@types/responselike@npm:1.0.0"
@ -1872,6 +1854,16 @@ __metadata:
languageName: node
linkType: hard
"@types/tar@npm:^6.1.5":
version: 6.1.5
resolution: "@types/tar@npm:6.1.5"
dependencies:
"@types/node": "*"
minipass: ^4.0.0
checksum: 1efa71c8d72f2b02d16ffecb65c4a96be9dacce000c4207532a686477386524dd99b6e26904319354be3ac9ac4d41296a0cb9cf87d05f8f21ae31c68fe446348
languageName: node
linkType: hard
"@typescript-eslint/eslint-plugin@npm:^5.54.1":
version: 5.59.1
resolution: "@typescript-eslint/eslint-plugin@npm:5.59.1"
@ -2313,39 +2305,6 @@ __metadata:
languageName: node
linkType: hard
"archiver-utils@npm:^2.1.0":
version: 2.1.0
resolution: "archiver-utils@npm:2.1.0"
dependencies:
glob: ^7.1.4
graceful-fs: ^4.2.0
lazystream: ^1.0.0
lodash.defaults: ^4.2.0
lodash.difference: ^4.5.0
lodash.flatten: ^4.4.0
lodash.isplainobject: ^4.0.6
lodash.union: ^4.6.0
normalize-path: ^3.0.0
readable-stream: ^2.0.0
checksum: 5665f40bde87ee82cb638177bdccca8cc6e55edea1b94338f7e6b56a1d9367b0d9a39e42b47866eaf84b8c67669a7d250900a226207ecc30fa163b52aae859a5
languageName: node
linkType: hard
"archiver@npm:^5.3.1":
version: 5.3.1
resolution: "archiver@npm:5.3.1"
dependencies:
archiver-utils: ^2.1.0
async: ^3.2.3
buffer-crc32: ^0.2.1
readable-stream: ^3.6.0
readdir-glob: ^1.0.0
tar-stream: ^2.2.0
zip-stream: ^4.1.0
checksum: 905b198ed04d26c951b80545d45c7f2e0432ef89977a93af8a762501d659886e39dda0fbffb0d517ff3fa450a3d09a29146e4273c2170624e1988f889fb5302c
languageName: node
linkType: hard
"are-we-there-yet@npm:^3.0.0":
version: 3.0.1
resolution: "are-we-there-yet@npm:3.0.1"
@ -2497,13 +2456,6 @@ __metadata:
languageName: node
linkType: hard
"async@npm:^3.2.3":
version: 3.2.4
resolution: "async@npm:3.2.4"
checksum: 43d07459a4e1d09b84a20772414aa684ff4de085cbcaec6eea3c7a8f8150e8c62aa6cd4e699fe8ee93c3a5b324e777d34642531875a0817a35697522c1b02e89
languageName: node
linkType: hard
"asynckit@npm:^0.4.0":
version: 0.4.0
resolution: "asynckit@npm:0.4.0"
@ -2638,17 +2590,6 @@ __metadata:
languageName: node
linkType: hard
"bl@npm:^4.0.3":
version: 4.1.0
resolution: "bl@npm:4.1.0"
dependencies:
buffer: ^5.5.0
inherits: ^2.0.4
readable-stream: ^3.4.0
checksum: 9e8521fa7e83aa9427c6f8ccdcba6e8167ef30cc9a22df26effcc5ab682ef91d2cbc23a239f945d099289e4bbcfae7a192e9c28c84c6202e710a0dfec3722662
languageName: node
linkType: hard
"blake-hash@npm:^1.1.0":
version: 1.1.1
resolution: "blake-hash@npm:1.1.1"
@ -2832,13 +2773,6 @@ __metadata:
languageName: node
linkType: hard
"buffer-crc32@npm:^0.2.1, buffer-crc32@npm:^0.2.13":
version: 0.2.13
resolution: "buffer-crc32@npm:0.2.13"
checksum: 06252347ae6daca3453b94e4b2f1d3754a3b146a111d81c68924c22d91889a40623264e95e67955b1cb4a68cbedf317abeabb5140a9766ed248973096db5ce1c
languageName: node
linkType: hard
"buffer-from@npm:1.1.2, buffer-from@npm:^1.0.0, buffer-from@npm:^1.1.0":
version: 1.1.2
resolution: "buffer-from@npm:1.1.2"
@ -3334,18 +3268,6 @@ __metadata:
languageName: node
linkType: hard
"compress-commons@npm:^4.1.0":
version: 4.1.1
resolution: "compress-commons@npm:4.1.1"
dependencies:
buffer-crc32: ^0.2.13
crc32-stream: ^4.0.2
normalize-path: ^3.0.0
readable-stream: ^3.6.0
checksum: 0176483211a7304a4a8aa52dbcc149a4c9181ac8a04bfbcc3d1a379174bf5fa56c3b15cec19e5ae3d31f1b1ce35ebb275b792b867000c77bac7162ce4e0ca268
languageName: node
linkType: hard
"concat-map@npm:0.0.1":
version: 0.0.1
resolution: "concat-map@npm:0.0.1"
@ -3684,16 +3606,6 @@ __metadata:
languageName: node
linkType: hard
"crc32-stream@npm:^4.0.2":
version: 4.0.2
resolution: "crc32-stream@npm:4.0.2"
dependencies:
crc-32: ^1.2.0
readable-stream: ^3.4.0
checksum: 1099559283b86e8a55390228b57ff4d57a74cac6aa8086aa4730f84317c9f93e914aeece115352f2d706a9df7ed75327ffacd86cfe23f040aef821231b528e76
languageName: node
linkType: hard
"create-hash@npm:^1.1.0, create-hash@npm:^1.1.2, create-hash@npm:^1.2.0":
version: 1.2.0
resolution: "create-hash@npm:1.2.0"
@ -4114,7 +4026,7 @@ __metadata:
languageName: node
linkType: hard
"end-of-stream@npm:^1.1.0, end-of-stream@npm:^1.4.1":
"end-of-stream@npm:^1.1.0":
version: 1.4.4
resolution: "end-of-stream@npm:1.4.4"
dependencies:
@ -5173,13 +5085,6 @@ __metadata:
languageName: node
linkType: hard
"fs-constants@npm:^1.0.0":
version: 1.0.0
resolution: "fs-constants@npm:1.0.0"
checksum: 18f5b718371816155849475ac36c7d0b24d39a11d91348cfcb308b4494824413e03572c403c86d3a260e049465518c4f0d5bd00f0371cdfcad6d4f30a85b350d
languageName: node
linkType: hard
"fs-exists-sync@npm:^0.1.0":
version: 0.1.0
resolution: "fs-exists-sync@npm:0.1.0"
@ -6752,15 +6657,6 @@ __metadata:
languageName: node
linkType: hard
"lazystream@npm:^1.0.0":
version: 1.0.1
resolution: "lazystream@npm:1.0.1"
dependencies:
readable-stream: ^2.0.5
checksum: 822c54c6b87701a6491c70d4fabc4cafcf0f87d6b656af168ee7bb3c45de9128a801cb612e6eeeefc64d298a7524a698dd49b13b0121ae50c2ae305f0dcc5310
languageName: node
linkType: hard
"lcid@npm:^2.0.0":
version: 2.0.0
resolution: "lcid@npm:2.0.0"
@ -7032,27 +6928,6 @@ __metadata:
languageName: node
linkType: hard
"lodash.defaults@npm:^4.2.0":
version: 4.2.0
resolution: "lodash.defaults@npm:4.2.0"
checksum: 84923258235592c8886e29de5491946ff8c2ae5c82a7ac5cddd2e3cb697e6fbdfbbb6efcca015795c86eec2bb953a5a2ee4016e3735a3f02720428a40efbb8f1
languageName: node
linkType: hard
"lodash.difference@npm:^4.5.0":
version: 4.5.0
resolution: "lodash.difference@npm:4.5.0"
checksum: ecee276aa578f300e79350805a14a51be8d1f12b3c1389a19996d8ab516f814211a5f65c68331571ecdad96522b863ccc484b55504ce8c9947212a29f8857d5a
languageName: node
linkType: hard
"lodash.flatten@npm:^4.4.0":
version: 4.4.0
resolution: "lodash.flatten@npm:4.4.0"
checksum: 0ac34a393d4b795d4b7421153d27c13ae67e08786c9cbb60ff5b732210d46f833598eee3fb3844bb10070e8488efe390ea53bb567377e0cb47e9e630bf0811cb
languageName: node
linkType: hard
"lodash.ismatch@npm:^4.4.0":
version: 4.4.0
resolution: "lodash.ismatch@npm:4.4.0"
@ -7060,13 +6935,6 @@ __metadata:
languageName: node
linkType: hard
"lodash.isplainobject@npm:^4.0.6":
version: 4.0.6
resolution: "lodash.isplainobject@npm:4.0.6"
checksum: 29c6351f281e0d9a1d58f1a4c8f4400924b4c79f18dfc4613624d7d54784df07efaff97c1ff2659f3e085ecf4fff493300adc4837553104cef2634110b0d5337
languageName: node
linkType: hard
"lodash.merge@npm:^4.6.2":
version: 4.6.2
resolution: "lodash.merge@npm:4.6.2"
@ -7074,13 +6942,6 @@ __metadata:
languageName: node
linkType: hard
"lodash.union@npm:^4.6.0":
version: 4.6.0
resolution: "lodash.union@npm:4.6.0"
checksum: 1514dc6508b2614ec071a6470f36eb7a70f69bf1abb6d55bdfdc21069635a4517783654b28504c0f025059a7598d37529766888e6d5902b8ab28b712228f7b2a
languageName: node
linkType: hard
"lodash@npm:^4.17.11, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.16":
version: 4.17.21
resolution: "lodash@npm:4.17.21"
@ -7505,7 +7366,7 @@ __metadata:
languageName: node
linkType: hard
"minimatch@npm:^5.0.1, minimatch@npm:^5.1.0":
"minimatch@npm:^5.0.1":
version: 5.1.6
resolution: "minimatch@npm:5.1.6"
dependencies:
@ -9024,7 +8885,7 @@ __metadata:
languageName: node
linkType: hard
"readable-stream@npm:2 || 3, readable-stream@npm:3, readable-stream@npm:^3.0.0, readable-stream@npm:^3.1.0, readable-stream@npm:^3.1.1, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0":
"readable-stream@npm:2 || 3, readable-stream@npm:3, readable-stream@npm:^3.0.0, readable-stream@npm:^3.1.0, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0":
version: 3.6.2
resolution: "readable-stream@npm:3.6.2"
dependencies:
@ -9035,21 +8896,6 @@ __metadata:
languageName: node
linkType: hard
"readable-stream@npm:^2.0.0, readable-stream@npm:^2.0.5, readable-stream@npm:~2.3.6":
version: 2.3.8
resolution: "readable-stream@npm:2.3.8"
dependencies:
core-util-is: ~1.0.0
inherits: ~2.0.3
isarray: ~1.0.0
process-nextick-args: ~2.0.0
safe-buffer: ~5.1.1
string_decoder: ~1.1.1
util-deprecate: ~1.0.1
checksum: 65645467038704f0c8aaf026a72fbb588a9e2ef7a75cd57a01702ee9db1c4a1e4b03aaad36861a6a0926546a74d174149c8c207527963e0c2d3eee2f37678a42
languageName: node
linkType: hard
"readable-stream@npm:~0.0.2":
version: 0.0.4
resolution: "readable-stream@npm:0.0.4"
@ -9069,12 +8915,18 @@ __metadata:
languageName: node
linkType: hard
"readdir-glob@npm:^1.0.0":
version: 1.1.3
resolution: "readdir-glob@npm:1.1.3"
"readable-stream@npm:~2.3.6":
version: 2.3.8
resolution: "readable-stream@npm:2.3.8"
dependencies:
minimatch: ^5.1.0
checksum: 1dc0f7440ff5d9378b593abe9d42f34ebaf387516615e98ab410cf3a68f840abbf9ff1032d15e0a0dbffa78f9e2c46d4fafdbaac1ca435af2efe3264e3f21874
core-util-is: ~1.0.0
inherits: ~2.0.3
isarray: ~1.0.0
process-nextick-args: ~2.0.0
safe-buffer: ~5.1.1
string_decoder: ~1.1.1
util-deprecate: ~1.0.1
checksum: 65645467038704f0c8aaf026a72fbb588a9e2ef7a75cd57a01702ee9db1c4a1e4b03aaad36861a6a0926546a74d174149c8c207527963e0c2d3eee2f37678a42
languageName: node
linkType: hard
@ -10093,19 +9945,6 @@ __metadata:
languageName: node
linkType: hard
"tar-stream@npm:^2.2.0":
version: 2.2.0
resolution: "tar-stream@npm:2.2.0"
dependencies:
bl: ^4.0.3
end-of-stream: ^1.4.1
fs-constants: ^1.0.0
inherits: ^2.0.3
readable-stream: ^3.1.1
checksum: 699831a8b97666ef50021c767f84924cfee21c142c2eb0e79c63254e140e6408d6d55a065a2992548e72b06de39237ef2b802b99e3ece93ca3904a37622a66f3
languageName: node
linkType: hard
"tar@npm:^4.0.2":
version: 4.4.19
resolution: "tar@npm:4.4.19"
@ -10135,6 +9974,20 @@ __metadata:
languageName: node
linkType: hard
"tar@npm:^6.1.14":
version: 6.1.14
resolution: "tar@npm:6.1.14"
dependencies:
chownr: ^2.0.0
fs-minipass: ^2.0.0
minipass: ^5.0.0
minizlib: ^2.1.1
mkdirp: ^1.0.3
yallist: ^4.0.0
checksum: a1be0815a9bdc97dfca7c6c2d71d1b836f8ba9314684e2c412832f0f59cc226d4c13da303d6bc30925e82f634cc793f40da79ae72f3e96fb87c23d0f4efd5207
languageName: node
linkType: hard
"temp-dir@npm:^2.0.0":
version: 2.0.0
resolution: "temp-dir@npm:2.0.0"
@ -11625,14 +11478,3 @@ __metadata:
checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700
languageName: node
linkType: hard
"zip-stream@npm:^4.1.0":
version: 4.1.0
resolution: "zip-stream@npm:4.1.0"
dependencies:
archiver-utils: ^2.1.0
compress-commons: ^4.1.0
readable-stream: ^3.6.0
checksum: 4a73da856738b0634700b52f4ab3fe0bf0a532bea6820ad962d0bda0163d2d5525df4859f89a7238e204a378384e12551985049790c1894c3ac191866e85887f
languageName: node
linkType: hard