Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TypeScript implementations #1223

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

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,
},
},
});
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;
}
3 changes: 3 additions & 0 deletions asset-transfer-basic/rest-api-typescript/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.ts]
indent_size = 4
quote_type = single
3 changes: 0 additions & 3 deletions asset-transfer-basic/rest-api-typescript/.prettierrc.json

This file was deleted.

Loading
Loading