Skip to content

Commit

Permalink
fix require() of ES Module
Browse files Browse the repository at this point in the history
Signed-off-by: Sheldon Regular <sheldon.regular@gmail.com>
  • Loading branch information
nodlesh committed Dec 6, 2024
1 parent b4e90bb commit 7a39c84
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 49 deletions.
4 changes: 3 additions & 1 deletion aries-backchannels/credo-ts/ngrok-wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ fi

echo "Starting Credo agent ..."

yarn ts-node src/index.ts "$@"
#yarn ts-node src/index.ts "$@"
#yarn node --loader ts-node/esm src/index.ts "$@"
yarn tsx src/index.ts "$@"
38 changes: 20 additions & 18 deletions aries-backchannels/credo-ts/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
"name": "credo-ts-backchannel",
"version": "1.0.0",
"license": "Apache-2.0",
"description": "Aries Agent Test Harness backchannel for Credo-ts",
"description": "OWL Agent Test Harness backchannel for Credo-ts",
"type": "module",
"scripts": {
"build": "yarn tsc",
"tsc": "tsc --project tsconfig.compile.json",
"start": "nodemon --watch \"src/**/*.ts\" --ignore \"node_modules/**/*\" --exec ts-node src/index.ts",
"start": "nodemon --watch \"src/**/*.ts\" --ignore \"node_modules/**/*\" --exec tsx src/index.ts",
"start:prod": "cross-env NODE_ENV=production node dist/index.js",
"format": "prettier --ignore-path .gitignore '**/*.+(js|json|ts|md|yml|yaml)' --write"
},
"dependencies": {
"@credo-ts/anoncreds": "^0.5.3",
"@credo-ts/askar": "^0.5.3",
"@credo-ts/core": "^0.5.3",
"@credo-ts/indy-vdr": "^0.5.3",
"@credo-ts/node": "^0.5.3",
"@hyperledger/anoncreds-nodejs": "^0.2.1",
"@hyperledger/aries-askar-nodejs": "^0.2.1",
"@hyperledger/indy-vdr-nodejs": "^0.2.0",
"@tsed/common": "^6.75.4",
"@tsed/core": "^6.75.4",
"@tsed/di": "^6.75.4",
"@tsed/exceptions": "^6.75.4",
"@tsed/platform-express": "^6.75.4",
"@tsed/swagger": "^6.88.0",
"@credo-ts/anoncreds": "^0.5.13",
"@credo-ts/askar": "^0.5.13",
"@credo-ts/core": "^0.5.13",
"@credo-ts/indy-vdr": "^0.5.13",
"@credo-ts/node": "^0.5.13",
"@hyperledger/anoncreds-nodejs": "^0.2.4",
"@hyperledger/aries-askar-nodejs": "^0.2.3",
"@hyperledger/indy-vdr-nodejs": "^0.2.2",
"@tsed/common": "^6.133.1",
"@tsed/core": "^6.133.1",
"@tsed/di": "^6.133.1",
"@tsed/exceptions": "^6.133.1",
"@tsed/platform-express": "^6.133.1",
"@tsed/swagger": "^6.133.1",
"body-parser": "1.20.3",
"cross-env": "7.0.3",
"express": "^4.17.1",
Expand All @@ -41,8 +42,9 @@
"@types/ref-struct-di": "^1.1.12",
"nodemon": "2.0.14",
"prettier": "^2.4.1",
"ts-node": "10.3.0",
"typescript": "^5.4.5"
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"tsx": "^4.19.2"
},
"resolutions": {
"ffi-napi": "npm:@2060.io/ffi-napi",
Expand Down
10 changes: 3 additions & 7 deletions aries-backchannels/credo-ts/server/src/BaseController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Inject } from '@tsed/di'
import { TestHarnessConfig } from './TestHarnessConfig'

export abstract class BaseController {
protected testHarnessConfig: TestHarnessConfig

public constructor(testHarnessConfig: TestHarnessConfig) {
this.testHarnessConfig = testHarnessConfig

this.testHarnessConfig.addController(this)
}
@Inject()
protected testHarnessConfig!: TestHarnessConfig

protected get agent() {
return this.testHarnessConfig.agent
Expand Down
9 changes: 8 additions & 1 deletion aries-backchannels/credo-ts/server/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Configuration, Inject } from '@tsed/di'
import { Configuration, Inject, Injectable } from '@tsed/di'
import { PlatformApplication } from '@tsed/common'
import '@tsed/platform-express' // /!\ keep this import
import '@tsed/swagger' // import swagger Ts.ED module
import * as bodyParser from 'body-parser'
import { fileURLToPath } from 'url'
import { dirname } from 'path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

export const rootDir = __dirname

@Configuration({
Expand All @@ -19,6 +25,7 @@ export const rootDir = __dirname
'/': [`${rootDir}/controllers/**/*.ts`],
},
})
@Injectable()
export class Server {
@Inject()
app!: PlatformApplication
Expand Down
1 change: 0 additions & 1 deletion aries-backchannels/credo-ts/server/src/TestAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AnonCredsModule, LegacyIndyCredentialFormatService, LegacyIndyProofForm
//import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrSovDidResolver, IndyVdrIndyDidResolver, IndyVdrPoolConfig, IndyVdrIndyDidRegistrar } from '@credo-ts/indy-vdr'
import { TsedLogger } from './TsedLogger'
import { TransportConfig } from './TestHarnessConfig'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { indyVdr } from '@hyperledger/indy-vdr-nodejs'
Expand Down
9 changes: 5 additions & 4 deletions aries-backchannels/credo-ts/server/src/TestHarnessConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
} from '@credo-ts/core'
import { HttpInboundTransport, WsInboundTransport } from '@credo-ts/node'
import { $log } from '@tsed/common'
import { BaseController } from './BaseController'
import { createAgent, TestAgent } from './TestAgent'
import { getGenesisPath, getRandomSeed, registerPublicDid } from './utils/ledgerUtils'
import { indyDidFromPublicKeyBase58 } from '@credo-ts/core/build/utils/did'
import { Injectable } from '@tsed/di'

@Injectable()
export class TestHarnessConfig {
private _createAgentArgs?: CreateAgentArguments
private agentPorts: AgentPorts
Expand All @@ -25,7 +26,7 @@ export class TestHarnessConfig {

private _agent?: TestAgent

private _controllers: BaseController[] = []
private _controllers: (() => void)[] = []

public constructor({ backchannelPort }: { backchannelPort: number }) {
this.agentPorts = {
Expand All @@ -40,7 +41,7 @@ export class TestHarnessConfig {
this.externalHost = this.runMode === 'docker' ? this.dockerHost : 'localhost'
}

public addController(controller: BaseController): void {
public addController(controller: () => void): void {
$log.info('Register controller')
this._controllers.push(controller)
}
Expand Down Expand Up @@ -70,7 +71,7 @@ export class TestHarnessConfig {
public async agentStartup() {
// Call handlers
for (const controller of this._controllers) {
await controller.onStartup.call(controller)
await controller()
}
}

Expand Down
12 changes: 7 additions & 5 deletions aries-backchannels/credo-ts/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { $log, Logger, registerProvider } from '@tsed/common'
import { $log, registerProvider, InjectorService } from '@tsed/common'
import minimist from 'minimist'

import { TestHarnessConfig } from './TestHarnessConfig'
import { PlatformExpress } from '@tsed/platform-express'
import { Server } from './Server'
import { TestHarnessConfig } from './TestHarnessConfig'

async function startup() {
const cliArguments = minimist(process.argv.slice(2), {
Expand Down Expand Up @@ -33,8 +32,11 @@ async function startup() {

const platform = await PlatformExpress.bootstrap(Server, {
httpPort: testHarnessConfig.backchannelPort,
});

})

const injector = platform.injector as InjectorService
injector.addProvider(TestHarnessConfig, { useValue: testHarnessConfig })

await testHarnessConfig.agentStartup()

await platform.listen(true)
Expand Down
7 changes: 0 additions & 7 deletions aries-backchannels/credo-ts/server/tsconfig.compile.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist",
"moduleResolution": "node",
"declaration": true,
"noResolve": false,
"preserveConstEnums": true,
"sourceMap": true,
"noEmit": false,
"inlineSources": true,
"skipLibCheck": true,
"strict": true
}
}
11 changes: 6 additions & 5 deletions aries-backchannels/credo-ts/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"module": "ESNext",
"target": "ESNext",
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"moduleResolution": "Node",
"isolatedModules": false,
"suppressImplicitAnyIndexErrors": false,
"noImplicitAny": true,
"strict": true,
"strict": false,
"strictNullChecks": true,
"skipLibCheck": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"allowSyntheticDefaultImports": true,
Expand All @@ -28,4 +29,4 @@
"linterOptions": {
"exclude": []
}
}
}

0 comments on commit 7a39c84

Please sign in to comment.