Skip to content

Commit

Permalink
fix(namada): add .ts extensions to imports
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Nov 4, 2024
1 parent 11563ec commit c2bf3de
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 130 deletions.
6 changes: 3 additions & 3 deletions index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/

export * from './index'
export * from './index.ts'

// Monkey patch for fetching from local FS. See docstring.
import { _$_HACK_$_ } from './src/compute/Upload'
import { LocalCompiledCode } from './src/compute/Compile.node'
import { _$_HACK_$_ } from './src/compute/Upload.ts'
import { LocalCompiledCode } from './src/compute/Compile.node.ts'
_$_HACK_$_.CompiledCode = LocalCompiledCode
27 changes: 11 additions & 16 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Suite } from '@hackbg/ensuite'
export default new Suite([
['core', ()=>import('./test/agent-core.test')],
['chain', ()=>import('./test/agent-chain.test')],
['compute', ()=>import('./test/agent-compute.test')],
['token', ()=>import('./test/agent-token.test')],
//['stub', ()=>import('./agent-stub.test')]
['stores', () => import('./test/stores.test')],
['scrt', () => import('./packages/scrt/scrt.test')],
['cw', () => import('./packages/cw/cw.test')],
//['oci', () =>
//@ts-ignore
//import('./oci/oci.test')],

// When running sequentially, these should go last, as they are the slowest.
['devnet', () => import('./packages/devnet/devnet.test')],
['compile', () => import('./packages/compile/compile.test')],
['create', () => import('./packages/create/create.test')],
['core', ()=>import('./test/agent-core.test.ts')],
['chain', ()=>import('./test/agent-chain.test.ts')],
['compute', ()=>import('./test/agent-compute.test.ts')],
['token', ()=>import('./test/agent-token.test.ts')],
['stores', ()=>import('./test/stores.test.ts')],
['scrt', ()=>import('./packages/scrt/scrt.test.ts')],
['cw', ()=>import('./packages/cw/cw.test.ts')],
// When running sequentially, these slowest ones should go last:
['devnet', ()=>import('./packages/devnet/devnet.test.ts')],
['compile', ()=>import('./packages/compile/compile.test.ts')],
['create', ()=>import('./packages/create/create.test.ts')],
])
22 changes: 11 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/

export { Chain, Connection, Block, Transaction } from './src/Chain'
export { Identity, Agent, SigningConnection, Batch } from './src/Agent'
export { Backend } from './src/Backend'
export { Chain, Connection, Block, Transaction } from './src/Chain.ts'
export { Identity, Agent, SigningConnection, Batch } from './src/Agent.ts'
export { Backend } from './src/Backend.ts'

export { Proposal, Vote } from './src/dlt/Governance'
export { Validator } from './src/dlt/Staking'
export * as Token from './src/dlt/Token'
export { Proposal, Vote } from './src/dlt/Governance.ts'
export { Validator } from './src/dlt/Staking.ts'
export * as Token from './src/dlt/Token.ts'

export { SourceCode, RustSourceCode } from './src/compute/Source'
export { Compiler, CompiledCode } from './src/compute/Compile'
export { UploadedCode, UploadStore } from './src/compute/Upload'
export { Contract } from './src/compute/Contract'
export { SourceCode, RustSourceCode } from './src/compute/Source.ts'
export { Compiler, CompiledCode } from './src/compute/Compile.ts'
export { UploadedCode, UploadStore } from './src/compute/Upload.ts'
export { Contract } from './src/compute/Contract.ts'

export * from './src/Util'
export * from './src/Util.ts'

/** An address on a chain. */
export type Address = string
Expand Down
6 changes: 3 additions & 3 deletions packages/namada/NamadaBlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as Namada from './Namada'
import type { NamadaDecoder } from './NamadaDecode'
import { Decode } from './NamadaDecode'
import type * as Namada from './Namada.ts'
import type { NamadaDecoder } from './NamadaDecode.ts'
import { Decode } from './NamadaDecode.ts'
import { Block, Transaction } from '@fadroma/cw'
import { Case } from '@hackbg/4mat'

Expand Down
12 changes: 6 additions & 6 deletions packages/namada/NamadaChain.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as CW from '@fadroma/cw'
import type { ChainId } from '@hackbg/fadroma'
import NamadaConnection from './NamadaConnection'
import type { Validator } from './NamadaPoS'
import { Decode, initDecoder } from './NamadaDecode'
import type { NamadaDecoder } from './NamadaDecode'
import type { Epoch } from './NamadaEpoch'
import NamadaConnection from './NamadaConnection.ts'
import type { Validator } from './NamadaPoS.ts'
import { Decode, initDecoder } from './NamadaDecode.ts'
import type { NamadaDecoder } from './NamadaDecode.ts'
import type { Epoch } from './NamadaEpoch.ts'

export default class NamadaChain extends CW.Chain {
decode: NamadaDecoder = Decode as unknown as NamadaDecoder
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class NamadaChain extends CW.Chain {
addresses?: string[],
parallel?: boolean,
parallelDetails?: boolean,
}) {
}): Promise<Validator[]> {
return this.getConnection().fetchValidatorsImpl(options)
}
fetchValidatorsIter (options?: { parallel?: boolean }) {
Expand Down
12 changes: 6 additions & 6 deletions packages/namada/NamadaConnection.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as CW from '@fadroma/cw'
import * as Block from './NamadaBlock'
import * as PoS from './NamadaPoS'
import * as PGF from './NamadaPGF'
import * as Gov from './NamadaGov'
import * as Epoch from './NamadaEpoch'
import type { Chain as Namada } from './Namada'
import * as Block from './NamadaBlock.ts'
import * as PoS from './NamadaPoS.ts'
import * as PGF from './NamadaPGF.ts'
import * as Gov from './NamadaGov.ts'
import * as Epoch from './NamadaEpoch.ts'
import type { Chain as Namada } from './Namada.ts'
import { decode, u256 } from '@hackbg/borshest'

export default class NamadaConnection extends CW.Connection {
Expand Down
6 changes: 3 additions & 3 deletions packages/namada/NamadaConsole.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Console, bold } from '@hackbg/fadroma'
import type { Transaction } from './NamadaBlock'
import type { Proposal } from './NamadaGov'
import type { Validator } from './NamadaPoS'
import type { Transaction } from './NamadaBlock.ts'
import type { Proposal } from './NamadaGov.ts'
import type { Validator } from './NamadaPoS.ts'

export default class NamadaConsole extends Console {

Expand Down
10 changes: 5 additions & 5 deletions packages/namada/NamadaDecode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Address, Uint128 } from '@hackbg/fadroma'
import init, { Decode } from './pkg/fadroma_namada.js'
import type { Block, Transaction } from './NamadaBlock'
import type { } from './NamadaBlock'
import type * as PGF from './NamadaPGF'
import type * as PoS from './NamadaPoS'
import type * as Gov from './NamadaGov'
import type { Block, Transaction } from './NamadaBlock.ts'
import type { } from './NamadaBlock.ts'
import type * as PGF from './NamadaPGF.ts'
import type * as PoS from './NamadaPoS.ts'
import type * as Gov from './NamadaGov.ts'

export async function initDecoder (decoder: string|URL|Uint8Array): Promise<void> {
if (decoder instanceof Uint8Array) {
Expand Down
4 changes: 2 additions & 2 deletions packages/namada/NamadaEpoch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decode, u64 } from '@hackbg/borshest'
import type { Decode } from './NamadaDecode'
import type NamadaConnection from './NamadaConnection'
import type { Decode } from './NamadaDecode.ts'
import type NamadaConnection from './NamadaConnection.ts'

export type Epoch = number|bigint|string

Expand Down
4 changes: 2 additions & 2 deletions packages/namada/NamadaGov.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { decode, u64 } from '@hackbg/borshest'
import type NamadaConnection from './NamadaConnection'
import type { NamadaDecoder } from './NamadaDecode'
import type NamadaConnection from './NamadaConnection.ts'
import type { NamadaDecoder } from './NamadaDecode.ts'

export type Params = Awaited<ReturnType<typeof fetchGovernanceParameters>>

Expand Down
2 changes: 1 addition & 1 deletion packages/namada/NamadaPGF.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type NamadaConnection from './NamadaConnection'
import type NamadaConnection from './NamadaConnection.ts'

export type Params = Awaited<ReturnType<typeof fetchPGFParameters>>

Expand Down
4 changes: 2 additions & 2 deletions packages/namada/NamadaPoS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Address } from '@hackbg/fadroma'
import { Console, assign, base16, optionallyParallel} from '@hackbg/fadroma'
import { Staking } from '@fadroma/cw'
import { decode, u8, u64, u256, array, set } from '@hackbg/borshest'
import type { Chain as Namada, Connection as NamadaConnection } from './Namada'
import type { Epoch } from './NamadaEpoch'
import type { Chain as Namada, Connection as NamadaConnection } from './Namada.ts'
import type { Epoch } from './NamadaEpoch.ts'

export type Params = Awaited<ReturnType<typeof fetchStakingParameters>>

Expand Down
11 changes: 7 additions & 4 deletions packages/namada/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noEmitOnError": true,
"esModuleInterop": true,
"allowJs": true,
"checkJs": true,
"resolveJsonModule": true,
"downlevelIteration": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"strict": true
"strict": true,
"allowImportingTsExtensions": true
}
}
32 changes: 16 additions & 16 deletions src/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import type { Address, Uint128, ChainId, CodeId, Token, Message, Into } from '../index'
import { assign, timed, bold, Logged, into } from './Util'
import { Chain } from './Chain'
import { send } from './dlt/Bank'
import { CompiledCode } from './compute/Compile'
import { UploadedCode, UploadStore, upload } from './compute/Upload'
import { Contract, instantiate, execute } from './compute/Contract'
import type { Address, Uint128, ChainId, CodeId, Token, Message, Into } from '../index.ts'
import { assign, Logged } from './Util.ts'
import { Chain } from './Chain.ts'
import { send } from './dlt/Bank.ts'
import { CompiledCode } from './compute/Compile.ts'
import { UploadedCode, UploadStore, upload } from './compute/Upload.ts'
import { Contract, instantiate, execute } from './compute/Contract.ts'

/** A cryptographic identity. */
export class Identity extends Logged {
Expand All @@ -22,7 +22,7 @@ export class Identity extends Logged {
/** Address of account. */
address?: Address
/** Sign some data with the identity's private key. */
sign (doc: any): unknown {
sign (_: unknown): unknown {
throw new Error("can't sign: stub")
}
}
Expand Down Expand Up @@ -53,19 +53,19 @@ export abstract class Agent extends Logged {
get address (): Address|undefined {
return this.identity?.address
}
async fetchBalance (tokens?: string[]|string): Promise<Record<string, Uint128>> {
fetchBalance (_tokens?: string[]|string): Promise<Record<string, Uint128>> {
throw new Error("unimplemented!")
}
/** Send one or more kinds of native tokens to one or more recipients. */
async send (
send (
outputs: Record<Address, Record<string, Uint128>>,
options?: Omit<Parameters<SigningConnection["sendImpl"]>[0],
'outputs'>
): Promise<unknown> {
return send(this, outputs, options)
}
/** Upload a contract's code, generating a new code id/hash pair. */
async upload (
upload (
code: string|URL|Uint8Array|Partial<CompiledCode>,
options?: Omit<Parameters<SigningConnection["uploadImpl"]>[0],
'binary'>,
Expand All @@ -76,7 +76,7 @@ export abstract class Agent extends Logged {
return upload(this, code, options)
}
/** Instantiate a new program from a code id, label and init message. */
async instantiate (
instantiate (
contract: CodeId|Partial<UploadedCode>,
options: Partial<Contract> & {
initMsg: Into<Message>,
Expand Down Expand Up @@ -190,22 +190,22 @@ export class Batch extends Logged {
agent: Agent

/** Add an upload message to the batch. */
upload (...args: Parameters<Agent["upload"]>): this {
upload (..._args: Parameters<Agent["upload"]>): this {
this.log.warn('upload: stub (not implemented)')
return this
}
/** Add an instantiate message to the batch. */
instantiate (...args: Parameters<Agent["instantiate"]>): this {
instantiate (..._args: Parameters<Agent["instantiate"]>): this {
this.log.warn('instantiate: stub (not implemented)')
return this
}
/** Add an execute message to the batch. */
execute (...args: Parameters<Agent["execute"]>): this {
execute (..._args: Parameters<Agent["execute"]>): this {
this.log.warn('execute: stub (not implemented)')
return this
}
/** Submit the batch. */
async submit (...args: unknown[]): Promise<unknown> {
async submit (..._args: unknown[]): Promise<unknown> {
this.log.warn('submit: stub (not implemented)')
return {}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import type { Chain, Agent, Identity, Address, ChainId } from '../index'
import { Logged, assign } from './Util'
import * as Token from './dlt/Token'
import type { /*Chain, Agent, Identity, Address,*/ ChainId } from '../index.ts'
import { Logged, assign } from './Util.ts'
import * as Token from './dlt/Token.ts'

/** Represents the backend of an [`Endpoint`](#abstract-class-endpoint), managed by us,
* such as:
Expand Down
12 changes: 5 additions & 7 deletions src/Chain.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Logged, assign, bold, timed, colors, randomColor } from './Util'
import { fetchBalance } from './dlt/Bank'
import { Contract, fetchCodeInstances, query } from './compute/Contract'
import { UploadedCode, fetchCodeInfo, } from './compute/Upload'
import type {
Address, Agent, ChainId, CodeId, Identity, Message, Token, Uint128, UploadStore, Into,
} from '../index'
import { Logged, bold, colors, randomColor } from './Util.ts'
import { fetchBalance } from './dlt/Bank.ts'
import { Contract, fetchCodeInstances, query } from './compute/Contract.ts'
import { UploadedCode, fetchCodeInfo, } from './compute/Upload.ts'
import type { Address, Agent, ChainId, CodeId, Identity, Message, Uint128 } from '../index.ts'

export abstract class Chain extends Logged {

Expand Down
3 changes: 1 addition & 2 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/
import { Error } from '@hackbg/oops'
import { Console, Logged, bold, colors } from '@hackbg/logs'

class FadromaError extends Error {}

Expand All @@ -24,7 +23,7 @@ export async function timed <T> (
elapsed: ((t1-t0)/1000).toFixed(3)+'s',
result
})
return result
return result as T
}

export async function optionallyParallel <T> (parallel: boolean|undefined, thunks: Array<()=>Promise<T>>) {
Expand Down
7 changes: 2 additions & 5 deletions src/compute/Compile.node.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/** Fadroma. Copyright (C) 2023 Hack.bg. License: GNU AGPLv3 or custom.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/

import { Console, bold } from '../Util'
import { CompiledCode } from './Compile'

import { CompiledCode } from './Compile.ts'
import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

/** An object representing a given compiled binary that may be on the local filesystem. */
export class LocalCompiledCode extends CompiledCode {
protected async fetchImpl () {
protected override async fetchImpl () {
if (typeof this.codePath === 'string') {
return await readFile(this.codePath)
} else if (this.codePath instanceof URL) {
Expand Down
6 changes: 3 additions & 3 deletions src/compute/Compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. **/

import { Console, Logged, bold, assign, base16, SHA256 } from '../Util'
import { SourceCode } from './Source'
import type { CodeHash } from '../../index'
import { Console, Logged, bold, assign, base16, SHA256 } from '../Util.ts'
import { SourceCode } from './Source.ts'
import type { CodeHash } from '../../index.ts'

/** The default Git ref when not specified. */
export const HEAD = 'HEAD'
Expand Down
Loading

0 comments on commit c2bf3de

Please sign in to comment.