feat: bundling for web and node
This commit is contained in:
59
bundle.js
59
bundle.js
@@ -10,66 +10,39 @@ const clean = async () => {
|
||||
const runBuild = async () => {
|
||||
await clean();
|
||||
|
||||
build({
|
||||
const buildConfig = {
|
||||
entryPoints: ['./src/index.ts'],
|
||||
minify: false,
|
||||
bundle: true,
|
||||
outfile: './bundles/web.bundle.js',
|
||||
platform: 'browser',
|
||||
target: ['esnext'],
|
||||
format: 'iife',
|
||||
globalName: 'warp',
|
||||
external: ['events']
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
build({
|
||||
entryPoints: ['./src/index.ts'],
|
||||
minify: true,
|
||||
bundle: true,
|
||||
outfile: './bundles/web.bundle.min.js',
|
||||
platform: 'browser',
|
||||
target: ['esnext'],
|
||||
format: 'iife',
|
||||
globalName: 'warp',
|
||||
external: ['events']
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
build({
|
||||
entryPoints: ['./src/index.ts'],
|
||||
minify: false,
|
||||
bundle: true,
|
||||
outfile: './bundles/esm.bundle.js',
|
||||
platform: 'browser',
|
||||
target: ['esnext'],
|
||||
format: 'esm',
|
||||
globalName: 'warp',
|
||||
external: ['events']
|
||||
globalName: 'warp'
|
||||
};
|
||||
|
||||
console.log('Building web bundle esm.');
|
||||
build({
|
||||
...buildConfig,
|
||||
minify: true,
|
||||
outfile: './bundles/web.bundle.min.js'
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
console.log('Building web bundle iife.');
|
||||
build({
|
||||
entryPoints: ['./src/index.ts'],
|
||||
...buildConfig,
|
||||
minify: true,
|
||||
bundle: true,
|
||||
outfile: './bundles/esm.bundle.min.js',
|
||||
platform: 'browser',
|
||||
target: ['esnext'],
|
||||
format: 'esm',
|
||||
globalName: 'warp',
|
||||
external: ['events']
|
||||
format: 'iife',
|
||||
outfile: './bundles/web.iife.bundle.min.js'
|
||||
}).catch((e) => {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
});
|
||||
};
|
||||
runBuild();
|
||||
runBuild().finally(() => {
|
||||
console.log('Build done.');
|
||||
});
|
||||
|
||||
module.exports = runBuild;
|
||||
|
||||
5
mjs-package.sh
Normal file
5
mjs-package.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
cat > lib/mjs/package.json <<!EOF
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
!EOF
|
||||
35
package.json
35
package.json
@@ -1,17 +1,13 @@
|
||||
{
|
||||
"name": "warp-contracts",
|
||||
"version": "1.2.0-rc.1",
|
||||
"version": "1.2.0-bundles.19",
|
||||
"description": "An implementation of the SmartWeave smart contract protocol.",
|
||||
"main": "./lib/cjs/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
"types": "./lib/types/index.d.ts",
|
||||
"main": "./lib/cjs/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./lib/esm/index.js",
|
||||
"require": "./lib/cjs/index.js"
|
||||
},
|
||||
"./esm": "bundles/esm.bundle.js",
|
||||
"./web": "bundles/web.bundle.js"
|
||||
"./web": "./bundles/web.bundle.min.js",
|
||||
"./mjs": "./lib/mjs/index.js",
|
||||
".": "./lib/cjs/index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
@@ -19,10 +15,11 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build:cjs": "tsc -b tsconfig.json",
|
||||
"build:esm": "tsc -b tsconfig.esm.json",
|
||||
"build:mjs": "gen-esm-wrapper ./lib/cjs ./lib/mjs/index.js",
|
||||
"mjs:burn:in:hell": "bash mjs-package.sh",
|
||||
"build:types": "tsc -b tsconfig.types.json",
|
||||
"bundle:web": "node bundle.js",
|
||||
"build": "yarn run clean && yarn build:cjs && yarn build:esm && yarn build:types && yarn bundle:web",
|
||||
"bundle": "node bundle.js",
|
||||
"build": "yarn run clean && yarn build:cjs && yarn build:mjs && yarn mjs:burn:in:hell && yarn build:types && yarn bundle",
|
||||
"format": "prettier --write 'src/**/*.ts'",
|
||||
"clean": "rimraf ./lib",
|
||||
"lint": "eslint . --ext .ts",
|
||||
@@ -69,6 +66,7 @@
|
||||
"arweave": "1.11.4",
|
||||
"bignumber.js": "^9.0.1",
|
||||
"elliptic": "^6.5.4",
|
||||
"events": "3.3.0",
|
||||
"fast-copy": "^2.1.1",
|
||||
"knex": "^0.95.14",
|
||||
"level": "^8.0.0",
|
||||
@@ -78,7 +76,6 @@
|
||||
"redstone-wasm-metering": "1.0.3",
|
||||
"safe-stable-stringify": "2.3.1",
|
||||
"stream-buffers": "^3.0.2",
|
||||
"tslog": "^3.2.2",
|
||||
"unzipit": "^1.4.0",
|
||||
"vm2": "3.9.9"
|
||||
},
|
||||
@@ -92,15 +89,12 @@
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"cli-table": "0.3.11",
|
||||
"colors": "^1.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"esbuild": "^0.14.25",
|
||||
"esbuild": "0.15.5",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^3.4.1",
|
||||
"express": "^4.17.1",
|
||||
"gen-esm-wrapper": "^1.1.3",
|
||||
"jest": "^28.1.3",
|
||||
"lmdb": "^2.5.2",
|
||||
"pg": "^8.7.1",
|
||||
"prettier": "^2.3.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"simple-statistics": "^7.7.0",
|
||||
@@ -108,8 +102,6 @@
|
||||
"sqlite3": "^5.0.2",
|
||||
"ts-jest": "^28.0.7",
|
||||
"ts-node": "^10.2.1",
|
||||
"tsc-alias": "1.3.10",
|
||||
"tsconfig-paths": "^3.10.1",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"browser": {
|
||||
@@ -121,6 +113,7 @@
|
||||
"stream-buffers": false,
|
||||
"constants": false,
|
||||
"knex": false,
|
||||
"os": false
|
||||
"os": false,
|
||||
"process": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Warp } from "../../core/Warp";
|
||||
import { Warp } from '../../core/Warp';
|
||||
|
||||
export async function mineBlock(warp: Warp) {
|
||||
await warp.testing.mineBlock();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { bundledTxsFilter } from "../../core/modules/impl/ArweaveGatewayInteractionsLoader";
|
||||
import { GQLEdgeInterface } from "../../legacy/gqlResult";
|
||||
import { bundledTxsFilter } from '../../core/modules/impl/ArweaveGatewayInteractionsLoader';
|
||||
import { GQLEdgeInterface } from '../../legacy/gqlResult';
|
||||
|
||||
describe('Bundled transactions filtering', () => {
|
||||
it('should properly filter bundled transaction if only "parent" field available', async () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { normalizeContractSource } from "../../core/modules/impl/normalize-source";
|
||||
import { normalizeContractSource } from '../../core/modules/impl/normalize-source';
|
||||
|
||||
describe('normalizeContractSource function', () => {
|
||||
const exampleSrcIIFEArrow = `(() => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TagsParser } from "../../core/modules/impl/TagsParser";
|
||||
import { GQLNodeInterface } from "../../legacy/gqlResult";
|
||||
import { TagsParser } from '../../core/modules/impl/TagsParser';
|
||||
import { GQLNodeInterface } from '../../legacy/gqlResult';
|
||||
|
||||
describe('TagsParser', () => {
|
||||
const sut = new TagsParser();
|
||||
|
||||
2
src/cache/impl/MemCache.ts
vendored
2
src/cache/impl/MemCache.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import { WarpCache } from "../../cache/WarpCache";
|
||||
import { WarpCache } from '../../cache/WarpCache';
|
||||
|
||||
/**
|
||||
* A simple, in-memory cache, with keys being transaction ids (e.g. contract transaction id).
|
||||
|
||||
@@ -5,7 +5,12 @@ import Transaction from 'arweave/node/lib/transaction';
|
||||
import { SortKeyCacheResult } from '../cache/SortKeyCache';
|
||||
import { ContractCallStack, InteractionCall } from '../core/ContractCallStack';
|
||||
import { ExecutionContext } from '../core/ExecutionContext';
|
||||
import { InteractionResult, HandlerApi, ContractInteraction, InteractionData } from '../core/modules/impl/HandlerExecutorFactory';
|
||||
import {
|
||||
InteractionResult,
|
||||
HandlerApi,
|
||||
ContractInteraction,
|
||||
InteractionData
|
||||
} from '../core/modules/impl/HandlerExecutorFactory';
|
||||
import { LexicographicalInteractionsSorter } from '../core/modules/impl/LexicographicalInteractionsSorter';
|
||||
import { InteractionsSorter } from '../core/modules/InteractionsSorter';
|
||||
import { EvaluationOptions, DefaultEvaluationOptions, EvalStateResult } from '../core/modules/StateEvaluator';
|
||||
@@ -18,7 +23,14 @@ import { LoggerFactory } from '../logging/LoggerFactory';
|
||||
import { Evolve } from '../plugins/Evolve';
|
||||
import { ArweaveWrapper } from '../utils/ArweaveWrapper';
|
||||
import { sleep } from '../utils/utils';
|
||||
import { Contract, BenchmarkStats, SigningFunction, CurrentTx, WriteInteractionOptions, WriteInteractionResponse } from './Contract';
|
||||
import {
|
||||
Contract,
|
||||
BenchmarkStats,
|
||||
SigningFunction,
|
||||
CurrentTx,
|
||||
WriteInteractionOptions,
|
||||
WriteInteractionResponse
|
||||
} from './Contract';
|
||||
import { Tags, ArTransfer, emptyTransfer, ArWallet } from './deploy/CreateContract';
|
||||
import { SourceData, SourceImpl } from './deploy/impl/SourceImpl';
|
||||
import { InnerWritesEvaluator } from './InnerWritesEvaluator';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ContractCallStack, InteractionCall } from "../core/ContractCallStack";
|
||||
import { ContractCallStack, InteractionCall } from '../core/ContractCallStack';
|
||||
|
||||
export class InnerWritesEvaluator {
|
||||
eval(callStack: ContractCallStack): Array<string> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { WriteInteractionOptions, WriteInteractionResponse } from "./Contract";
|
||||
import { HandlerBasedContract } from "./HandlerBasedContract";
|
||||
import { PstState, PstContract, BalanceResult, TransferInput } from "./PstContract";
|
||||
import { WriteInteractionOptions, WriteInteractionResponse } from './Contract';
|
||||
import { HandlerBasedContract } from './HandlerBasedContract';
|
||||
import { PstState, PstContract, BalanceResult, TransferInput } from './PstContract';
|
||||
|
||||
interface BalanceInput {
|
||||
function: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SigningFunction } from "../../contract/Contract";
|
||||
import { ArWallet } from "./CreateContract";
|
||||
import { SourceData } from "./impl/SourceImpl";
|
||||
import { SigningFunction } from '../../contract/Contract';
|
||||
import { ArWallet } from './CreateContract';
|
||||
import { SourceData } from './impl/SourceImpl';
|
||||
|
||||
export interface Source {
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mapReplacer } from "../utils/utils";
|
||||
import { InteractionData } from "./modules/impl/HandlerExecutorFactory";
|
||||
import { mapReplacer } from '../utils/utils';
|
||||
import { InteractionData } from './modules/impl/HandlerExecutorFactory';
|
||||
|
||||
export class ContractCallStack {
|
||||
readonly interactions: Map<string, InteractionCall> = new Map();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* This type contains all data and meta-data of the given contact.
|
||||
*/
|
||||
|
||||
import { ContractType } from "../contract/deploy/CreateContract";
|
||||
import { ContractType } from '../contract/deploy/CreateContract';
|
||||
|
||||
export class ContractMetadata {
|
||||
dtor: number;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ExecutionContext } from "./ExecutionContext";
|
||||
import { HandlerApi } from "./modules/impl/HandlerExecutorFactory";
|
||||
import { ExecutionContext } from './ExecutionContext';
|
||||
import { HandlerApi } from './modules/impl/HandlerExecutorFactory';
|
||||
|
||||
/**
|
||||
* This adds ability to modify current execution context based
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ContractDefinition, ContractSource } from "../../core/ContractDefinition";
|
||||
import { GwTypeAware } from "./InteractionsLoader";
|
||||
import { ContractDefinition, ContractSource } from '../../core/ContractDefinition';
|
||||
import { GwTypeAware } from './InteractionsLoader';
|
||||
|
||||
/**
|
||||
* Implementors of this interface are responsible for loading contract's definitions -
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ContractDefinition } from "../../core/ContractDefinition";
|
||||
import { EvaluationOptions } from "./StateEvaluator";
|
||||
import { ContractDefinition } from '../../core/ContractDefinition';
|
||||
import { EvaluationOptions } from './StateEvaluator';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface ContractApi {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { GQLNodeInterface } from "../../legacy/gqlResult";
|
||||
import { EvaluationOptions } from "./StateEvaluator";
|
||||
import { GQLNodeInterface } from '../../legacy/gqlResult';
|
||||
import { EvaluationOptions } from './StateEvaluator';
|
||||
|
||||
export type GW_TYPE = 'arweave' | 'warp';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GQLEdgeInterface } from "../../legacy/gqlResult";
|
||||
import { GQLEdgeInterface } from '../../legacy/gqlResult';
|
||||
|
||||
/**
|
||||
* this is probably self-explanatory ;-)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SortKeyCacheResult } from "../../cache/SortKeyCache";
|
||||
import { CurrentTx } from "../../contract/Contract";
|
||||
import { ExecutionContext } from "../../core/ExecutionContext";
|
||||
import { GQLNodeInterface } from "../../legacy/gqlResult";
|
||||
import { SortKeyCacheResult } from '../../cache/SortKeyCache';
|
||||
import { CurrentTx } from '../../contract/Contract';
|
||||
import { ExecutionContext } from '../../core/ExecutionContext';
|
||||
import { GQLNodeInterface } from '../../legacy/gqlResult';
|
||||
|
||||
/**
|
||||
* Implementors of this class are responsible for evaluating contract's state
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import Arweave from 'arweave';
|
||||
import { SmartWeaveTags } from '../../../core/SmartWeaveTags';
|
||||
import { GQLEdgeInterface, GQLNodeInterface, GQLTransactionsResultInterface, GQLResultInterface } from '../../../legacy/gqlResult';
|
||||
import {
|
||||
GQLEdgeInterface,
|
||||
GQLNodeInterface,
|
||||
GQLTransactionsResultInterface,
|
||||
GQLResultInterface
|
||||
} from '../../../legacy/gqlResult';
|
||||
import { Benchmark } from '../../../logging/Benchmark';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
import { ArweaveWrapper } from '../../../utils/ArweaveWrapper';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GQLNodeInterface } from "../../../legacy/gqlResult";
|
||||
import { LoggerFactory } from "../../../logging/LoggerFactory";
|
||||
import { InteractionsLoader, GW_TYPE } from "../InteractionsLoader";
|
||||
import { EvaluationOptions } from "../StateEvaluator";
|
||||
import { GQLNodeInterface } from '../../../legacy/gqlResult';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
import { InteractionsLoader, GW_TYPE } from '../InteractionsLoader';
|
||||
import { EvaluationOptions } from '../StateEvaluator';
|
||||
|
||||
export class CacheableInteractionsLoader implements InteractionsLoader {
|
||||
private readonly logger = LoggerFactory.INST.create('CacheableInteractionsLoader');
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { LevelDbCache } from "../../../cache/impl/LevelDbCache";
|
||||
import { SortKeyCache, CacheKey } from "../../../cache/SortKeyCache";
|
||||
import { defaultCacheOptions } from "../../../core/WarpFactory";
|
||||
import { GQLNodeInterface } from "../../../legacy/gqlResult";
|
||||
import { LoggerFactory } from "../../../logging/LoggerFactory";
|
||||
import { InteractionsLoader, GW_TYPE } from "../InteractionsLoader";
|
||||
import { EvaluationOptions } from "../StateEvaluator";
|
||||
import { LevelDbCache } from '../../../cache/impl/LevelDbCache';
|
||||
import { SortKeyCache, CacheKey } from '../../../cache/SortKeyCache';
|
||||
import { defaultCacheOptions } from '../../../core/WarpFactory';
|
||||
import { GQLNodeInterface } from '../../../legacy/gqlResult';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
import { InteractionsLoader, GW_TYPE } from '../InteractionsLoader';
|
||||
import { EvaluationOptions } from '../StateEvaluator';
|
||||
|
||||
export class CacheableInteractionsLoader_v1 implements InteractionsLoader {
|
||||
private readonly logger = LoggerFactory.INST.create('CacheableInteractionsLoader');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GQLNodeInterface } from "../../../legacy/gqlResult";
|
||||
import { GQLNodeInterface } from '../../../legacy/gqlResult';
|
||||
|
||||
//export type StateCache<State> = Array<EvalStateResult<State>>;
|
||||
export function canBeCached(tx: GQLNodeInterface): boolean {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { SmartWeaveTags } from "../../../core/SmartWeaveTags";
|
||||
import { GQLNodeInterface, GQLTagInterface } from "../../../legacy/gqlResult";
|
||||
import { LoggerFactory } from "../../../logging/LoggerFactory";
|
||||
import { SmartWeaveTags } from '../../../core/SmartWeaveTags';
|
||||
import { GQLNodeInterface, GQLTagInterface } from '../../../legacy/gqlResult';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
|
||||
/**
|
||||
* A class that is responsible for retrieving "input" tag from the interaction transaction.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import { GQLNodeInterface } from '../../../legacy/gqlResult';
|
||||
import { Benchmark } from '../../../logging/Benchmark';
|
||||
import { LoggerFactory } from '../../../logging/LoggerFactory';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { CurrentTx } from "../../../../contract/Contract";
|
||||
import { ContractDefinition } from "../../../../core/ContractDefinition";
|
||||
import { ExecutionContext } from "../../../../core/ExecutionContext";
|
||||
import { EvalStateResult } from "../../../../core/modules/StateEvaluator";
|
||||
import { GQLNodeInterface } from "../../../../legacy/gqlResult";
|
||||
import { SmartWeaveGlobal } from "../../../../legacy/smartweave-global";
|
||||
import { LoggerFactory } from "../../../../logging/LoggerFactory";
|
||||
import { deepCopy } from "../../../../utils/utils";
|
||||
import { HandlerApi, InteractionData, InteractionResult } from "../HandlerExecutorFactory";
|
||||
import { CurrentTx } from '../../../../contract/Contract';
|
||||
import { ContractDefinition } from '../../../../core/ContractDefinition';
|
||||
import { ExecutionContext } from '../../../../core/ExecutionContext';
|
||||
import { EvalStateResult } from '../../../../core/modules/StateEvaluator';
|
||||
import { GQLNodeInterface } from '../../../../legacy/gqlResult';
|
||||
import { SmartWeaveGlobal } from '../../../../legacy/smartweave-global';
|
||||
import { LoggerFactory } from '../../../../logging/LoggerFactory';
|
||||
import { deepCopy } from '../../../../utils/utils';
|
||||
import { HandlerApi, InteractionData, InteractionResult } from '../HandlerExecutorFactory';
|
||||
|
||||
export abstract class AbstractContractHandler<State> implements HandlerApi<State> {
|
||||
protected logger = LoggerFactory.INST.create('ContractHandler');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SmartWeaveGlobal } from "../../../../legacy/smartweave-global";
|
||||
import { LoggerFactory } from "../../../../logging/LoggerFactory";
|
||||
import { SmartWeaveGlobal } from '../../../../legacy/smartweave-global';
|
||||
import { LoggerFactory } from '../../../../logging/LoggerFactory';
|
||||
|
||||
export const asWasmImports = (swGlobal: SmartWeaveGlobal, wasmInstance: any): any => {
|
||||
const wasmLogger = LoggerFactory.INST.create('WASM:AS');
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
//
|
||||
// This file has been modified for use by the TinyGo compiler.
|
||||
|
||||
import { SmartWeaveGlobal } from "../../../../legacy/smartweave-global";
|
||||
import { LoggerFactory } from "../../../../logging/LoggerFactory";
|
||||
import { SmartWeaveGlobal } from '../../../../legacy/smartweave-global';
|
||||
import { LoggerFactory } from '../../../../logging/LoggerFactory';
|
||||
|
||||
// note: this file has been further modified to be used
|
||||
// with Warp SDK.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* eslint-disable */
|
||||
/* a kind of magic */
|
||||
|
||||
import { LoggerFactory } from "../../../../logging/LoggerFactory";
|
||||
import { LoggerFactory } from '../../../../logging/LoggerFactory';
|
||||
|
||||
// note: this is (somewhat heavily) modified code
|
||||
// of the js that is normally generated by the wasm-bindgen
|
||||
|
||||
@@ -4,7 +4,6 @@ export * from './logging/WarpLogger';
|
||||
export * from './logging/LoggerFactory';
|
||||
export * from './logging/LoggerSettings';
|
||||
export * from './logging/Benchmark';
|
||||
export * from './logging/node/TsLogFactory';
|
||||
|
||||
export * from './core/modules/DefinitionLoader';
|
||||
export * from './core/modules/ExecutorFactory';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LogLevel } from "./LoggerSettings";
|
||||
import { WarpLogger } from "./WarpLogger";
|
||||
import { ConsoleLoggerFactory } from "./web/ConsoleLoggerFactory";
|
||||
import { LogLevel } from './LoggerSettings';
|
||||
import { WarpLogger } from './WarpLogger';
|
||||
import { ConsoleLoggerFactory } from './web/ConsoleLoggerFactory';
|
||||
|
||||
export interface ILoggerFactory {
|
||||
setOptions(newOptions: any, moduleName?: string): void;
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
import { ILoggerFactory } from '../../logging/LoggerFactory';
|
||||
import { LogLevel } from '../../logging/LoggerSettings';
|
||||
import path from 'path';
|
||||
import { ISettingsParam, Logger } from 'tslog';
|
||||
import { WarpLogger } from '../WarpLogger';
|
||||
|
||||
export const defaultLoggerOptions: ISettingsParam = {
|
||||
displayFunctionName: false,
|
||||
displayFilePath: 'hidden',
|
||||
displayLoggerName: true,
|
||||
dateTimeTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
minLevel: 'info',
|
||||
overwriteConsole: false
|
||||
};
|
||||
|
||||
/**
|
||||
* A wrapper around "tslog" logging library that allows to change logging settings at runtime
|
||||
* (for each registered module independently, or globally - for all loggers).
|
||||
*/
|
||||
export class TsLogFactory implements ILoggerFactory {
|
||||
private readonly registeredLoggers: { [moduleName: string]: Logger } = {};
|
||||
private readonly registeredOptions: { [moduleName: string]: ISettingsParam } = {};
|
||||
|
||||
private defaultOptions: ISettingsParam = { ...defaultLoggerOptions };
|
||||
|
||||
constructor() {
|
||||
this.setOptions = this.setOptions.bind(this);
|
||||
this.getOptions = this.getOptions.bind(this);
|
||||
this.create = this.create.bind(this);
|
||||
this.logLevel = this.logLevel.bind(this);
|
||||
}
|
||||
|
||||
setOptions(newOptions: ISettingsParam, moduleName?: string): void {
|
||||
// if moduleName not specified
|
||||
if (!moduleName) {
|
||||
// update default options
|
||||
this.defaultOptions = {
|
||||
...this.defaultOptions,
|
||||
...newOptions
|
||||
};
|
||||
// update options for all already registered loggers
|
||||
Object.keys(this.registeredLoggers).forEach((key: string) => {
|
||||
this.registeredLoggers[key].setSettings({
|
||||
...this.registeredLoggers[key].settings,
|
||||
...newOptions
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// if logger already registered
|
||||
if (this.registeredLoggers[moduleName]) {
|
||||
// update its options
|
||||
this.registeredLoggers[moduleName].setSettings({
|
||||
...this.registeredLoggers[moduleName].settings,
|
||||
...newOptions
|
||||
});
|
||||
} else {
|
||||
// if logger not yet registered - save options that will be used for its creation
|
||||
this.registeredOptions[moduleName] = {
|
||||
...this.defaultOptions,
|
||||
...newOptions
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getOptions(moduleName?: string): ISettingsParam {
|
||||
if (!moduleName) {
|
||||
return this.defaultOptions;
|
||||
} else {
|
||||
if (this.registeredLoggers[moduleName]) {
|
||||
return this.registeredLoggers[moduleName].settings;
|
||||
} else if (this.registeredOptions[moduleName]) {
|
||||
return this.registeredOptions[moduleName];
|
||||
} else {
|
||||
return this.defaultOptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logLevel(level: LogLevel, moduleName?: string) {
|
||||
this.setOptions({ minLevel: level }, moduleName);
|
||||
}
|
||||
|
||||
create(moduleName = 'SWC'): WarpLogger {
|
||||
// in case of passing '__dirname' as moduleName - leaves only the file name without extension.
|
||||
const normalizedModuleName = path.basename(moduleName, path.extname(moduleName));
|
||||
if (!this.registeredLoggers[normalizedModuleName]) {
|
||||
const logger = new Logger({
|
||||
...this.getOptions(normalizedModuleName),
|
||||
name: normalizedModuleName
|
||||
});
|
||||
this.registeredLoggers[normalizedModuleName] = logger;
|
||||
}
|
||||
return this.registeredLoggers[normalizedModuleName] as WarpLogger;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import { LoggerSettings, LogLevel, lvlToOrder } from "../../logging/LoggerSettings";
|
||||
import { WarpLogger } from "../../logging/WarpLogger";
|
||||
import { LoggerSettings, LogLevel, lvlToOrder } from '../../logging/LoggerSettings';
|
||||
import { WarpLogger } from '../../logging/WarpLogger';
|
||||
|
||||
export class ConsoleLogger implements WarpLogger {
|
||||
constructor(private readonly moduleName, public settings: LoggerSettings) {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ContractDefinition } from "../core/ContractDefinition";
|
||||
import { ExecutorFactory } from "../core/modules/ExecutorFactory";
|
||||
import { EvaluationOptions } from "../core/modules/StateEvaluator";
|
||||
import { ContractDefinition } from '../core/ContractDefinition';
|
||||
import { ExecutorFactory } from '../core/modules/ExecutorFactory';
|
||||
import { EvaluationOptions } from '../core/modules/StateEvaluator';
|
||||
|
||||
/**
|
||||
* An ExecutorFactory that allows to substitute original contract's source code.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { EvolveState } from "../contract/Contract";
|
||||
import { LoggerFactory } from "../logging/LoggerFactory";
|
||||
import { ExecutionContext } from "../core/ExecutionContext";
|
||||
import { ExecutionContextModifier } from "../core/ExecutionContextModifier";
|
||||
import { SmartWeaveError, SmartWeaveErrorType } from "../legacy/errors";
|
||||
import { HandlerApi } from "../core/modules/impl/HandlerExecutorFactory";
|
||||
import { EvolveState } from '../contract/Contract';
|
||||
import { LoggerFactory } from '../logging/LoggerFactory';
|
||||
import { ExecutionContext } from '../core/ExecutionContext';
|
||||
import { ExecutionContextModifier } from '../core/ExecutionContextModifier';
|
||||
import { SmartWeaveError, SmartWeaveErrorType } from '../legacy/errors';
|
||||
import { HandlerApi } from '../core/modules/impl/HandlerExecutorFactory';
|
||||
|
||||
function isEvolveCompatible(state: unknown): state is EvolveState {
|
||||
if (!state) {
|
||||
|
||||
@@ -15,8 +15,13 @@
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"resolveJsonModule": true,
|
||||
"baseUrl": "./src",
|
||||
"allowJs": true
|
||||
"allowJs": true,
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "tools", "**/__tests__/*", "_scripts"]
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"tools",
|
||||
"**/__tests__/*",
|
||||
"_scripts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user