Skip to content

Commit

Permalink
Update TypeScript implementations
Browse files Browse the repository at this point in the history
- Dependency updates
- ESLint flat configuration format, replacing deprecated configuration
- Minor fixes to compile and lint issues
- Consistent TypeScript formatting with .editorconfig

Signed-off-by: Mark S. Lewis <[email protected]>
  • Loading branch information
bestbeforetoday committed Jun 15, 2024
1 parent 3622a5e commit f8a67d0
Show file tree
Hide file tree
Showing 85 changed files with 6,278 additions and 4,338 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
indent_size = 4
quote_type = single

[*.json]
indent_size = 4

[*.md]
max_line_length = off
45 changes: 0 additions & 45 deletions asset-transfer-basic/application-gateway-typescript/.eslintrc.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import js from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(js.configs.recommended, ...tseslint.configs.strictTypeChecked, {
languageOptions: {
ecmaVersion: 2023,
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
});
14 changes: 7 additions & 7 deletions asset-transfer-basic/application-gateway-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "tsc",
"build:watch": "tsc -w",
"lint": "eslint . --ext .ts",
"lint": "eslint src",
"prepare": "npm run build",
"pretest": "npm run lint",
"start": "node dist/app.js"
Expand All @@ -19,15 +19,15 @@
"author": "Hyperledger",
"license": "Apache-2.0",
"dependencies": {
"@grpc/grpc-js": "^1.9.7",
"@hyperledger/fabric-gateway": "~1.4.0"
"@grpc/grpc-js": "^1.10",
"@hyperledger/fabric-gateway": "^1.5"
},
"devDependencies": {
"@eslint/js": "^9.3.0",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^18.18.6",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
"typescript": "~5.2.2"
"eslint": "^8.57.0",
"typescript": "~5.4",
"typescript-eslint": "^7.13.0"
}
}
21 changes: 12 additions & 9 deletions asset-transfer-basic/application-gateway-typescript/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ const peerEndpoint = envOrDefault('PEER_ENDPOINT', 'localhost:7051');
const peerHostAlias = envOrDefault('PEER_HOST_ALIAS', 'peer0.org1.example.com');

const utf8Decoder = new TextDecoder();
const assetId = `asset${Date.now()}`;
const assetId = `asset${String(Date.now())}`;

async function main(): Promise<void> {

await displayInputParameters();
displayInputParameters();

// The gRPC client connection should be shared by all Gateway connections to this endpoint.
const client = await newGrpcConnection();
Expand Down Expand Up @@ -92,7 +91,7 @@ async function main(): Promise<void> {
}
}

main().catch(error => {
main().catch((error: unknown) => {
console.error('******** FAILED to run the application:', error);
process.exitCode = 1;
});
Expand All @@ -113,7 +112,11 @@ async function newIdentity(): Promise<Identity> {

async function getFirstDirFileName(dirPath: string): Promise<string> {
const files = await fs.readdir(dirPath);
return path.join(dirPath, files[0]);
const file = files[0];
if (!file) {
throw new Error(`No files in directory: ${dirPath}`);
}
return path.join(dirPath, file);
}

async function newSigner(): Promise<Signer> {
Expand Down Expand Up @@ -144,7 +147,7 @@ async function getAllAssets(contract: Contract): Promise<void> {
const resultBytes = await contract.evaluateTransaction('GetAllAssets');

const resultJson = utf8Decoder.decode(resultBytes);
const result = JSON.parse(resultJson);
const result: unknown = JSON.parse(resultJson);
console.log('*** Result:', result);
}

Expand Down Expand Up @@ -183,7 +186,7 @@ async function transferAssetAsync(contract: Contract): Promise<void> {

const status = await commit.getStatus();
if (!status.successful) {
throw new Error(`Transaction ${status.transactionId} failed to commit with status code ${status.code}`);
throw new Error(`Transaction ${status.transactionId} failed to commit with status code ${String(status.code)}`);
}

console.log('*** Transaction committed successfully');
Expand All @@ -195,7 +198,7 @@ async function readAssetByID(contract: Contract): Promise<void> {
const resultBytes = await contract.evaluateTransaction('ReadAsset', assetId);

const resultJson = utf8Decoder.decode(resultBytes);
const result = JSON.parse(resultJson);
const result: unknown = JSON.parse(resultJson);
console.log('*** Result:', result);
}

Expand Down Expand Up @@ -230,7 +233,7 @@ function envOrDefault(key: string, defaultValue: string): string {
/**
* displayInputParameters() will print the global scope parameters used by the main driver routine.
*/
async function displayInputParameters(): Promise<void> {
function displayInputParameters(): void {
console.log(`channelName: ${channelName}`);
console.log(`chaincodeName: ${chaincodeName}`);
console.log(`mspId: ${mspId}`);
Expand Down
28 changes: 13 additions & 15 deletions asset-transfer-basic/application-gateway-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"extends":"@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"noImplicitAny": true
},
"include": [
"./src/**/*"
],
"exclude": [
"./src/**/*.spec.ts"
]
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true
},
"include": ["./src/**/*"],
"exclude": ["./src/**/*.spec.ts"]
}
10 changes: 5 additions & 5 deletions asset-transfer-basic/chaincode-typescript/src/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ export class Asset {
public docType?: string;

@Property()
public ID: string;
public ID: string = '';

@Property()
public Color: string;
public Color: string = '';

@Property()
public Size: number;
public Size: number = 0;

@Property()
public Owner: string;
public Owner: string = '';

@Property()
public AppraisedValue: number;
public AppraisedValue: number = 0;
}
Loading

0 comments on commit f8a67d0

Please sign in to comment.