From 4b3a2ca85020a53c78f6377f2dc04347bc941776 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 13:57:24 +0800 Subject: [PATCH 01/14] Fix "Cannot find module" errors in TypeScript test files Add "../../types/" as type package to **/test/typescript/tsconfig.json Signed-off-by: Jerrylum --- apis/fabric-contract-api/test/typescript/tsconfig.json | 1 + libraries/fabric-shim/test/typescript/tsconfig.json | 1 + 2 files changed, 2 insertions(+) diff --git a/apis/fabric-contract-api/test/typescript/tsconfig.json b/apis/fabric-contract-api/test/typescript/tsconfig.json index 02a31c3aa..104e67e89 100644 --- a/apis/fabric-contract-api/test/typescript/tsconfig.json +++ b/apis/fabric-contract-api/test/typescript/tsconfig.json @@ -6,6 +6,7 @@ */ { "compilerOptions": { + "types": ["../../types/"], "module": "commonjs", "target": "es2017", "sourceMap": true, diff --git a/libraries/fabric-shim/test/typescript/tsconfig.json b/libraries/fabric-shim/test/typescript/tsconfig.json index 02a31c3aa..104e67e89 100644 --- a/libraries/fabric-shim/test/typescript/tsconfig.json +++ b/libraries/fabric-shim/test/typescript/tsconfig.json @@ -6,6 +6,7 @@ */ { "compilerOptions": { + "types": ["../../types/"], "module": "commonjs", "target": "es2017", "sourceMap": true, From fd486dd40843acf5a54ba01bfc5913f9e73e45f9 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 20:39:03 +0800 Subject: [PATCH 02/14] Add ESLint TypeScript support Signed-off-by: Jerrylum --- .eslintrc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index d596f936f..0ed22b13a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,19 @@ { "env": { - "es6": true, "node": true, "mocha": true }, - "extends": "eslint:recommended", + "extends": [ "eslint:recommended", "@rushstack/eslint-config"], + "overrides": [ + { + "files": ["**/test/typescript/*.ts"], + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": "off" + } + } + ], "parserOptions": { "ecmaVersion": 9, "sourceType": "module" @@ -25,7 +33,7 @@ "SwitchCase": 1 } ], - "keyword-spacing":"error", + "keyword-spacing": "error", "linebreak-style": ["error", "unix"], "max-len": [ "error", @@ -67,6 +75,11 @@ ], "space-infix-ops": ["error"], "space-in-parens": ["error", "never"], - "yoda": "error" + "yoda": "error", + "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/explicit-member-accessibility": "off", + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/no-namespace": "off" } } From ac020a4ea724f54e9b27437e69c574aeb7f23b5e Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 20:53:01 +0800 Subject: [PATCH 03/14] Remove directory tsconfig.json files Signed-off-by: Jerrylum --- .../test/typescript/tsconfig.json | 20 ---------- apis/fabric-contract-api/types/tsconfig.json | 34 ----------------- apis/fabric-shim-api/types/tsconfig.json | 37 ------------------- .../fabric-shim/test/typescript/tsconfig.json | 20 ---------- libraries/fabric-shim/types/tsconfig.json | 37 ------------------- 5 files changed, 148 deletions(-) delete mode 100644 apis/fabric-contract-api/test/typescript/tsconfig.json delete mode 100644 apis/fabric-contract-api/types/tsconfig.json delete mode 100644 apis/fabric-shim-api/types/tsconfig.json delete mode 100644 libraries/fabric-shim/test/typescript/tsconfig.json delete mode 100644 libraries/fabric-shim/types/tsconfig.json diff --git a/apis/fabric-contract-api/test/typescript/tsconfig.json b/apis/fabric-contract-api/test/typescript/tsconfig.json deleted file mode 100644 index 104e67e89..000000000 --- a/apis/fabric-contract-api/test/typescript/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -/* - Copyright 2018 IBM All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 - -*/ -{ - "compilerOptions": { - "types": ["../../types/"], - "module": "commonjs", - "target": "es2017", - "sourceMap": true, - "lib": [ - "esnext" - ] - }, - "exclude": [ - "node_modules" - ] -} diff --git a/apis/fabric-contract-api/types/tsconfig.json b/apis/fabric-contract-api/types/tsconfig.json deleted file mode 100644 index 8eabad9cb..000000000 --- a/apis/fabric-contract-api/types/tsconfig.json +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2018 IBM All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 -*/ -{ - "compilerOptions": { - "removeComments": false, - "preserveConstEnums": true, - "sourceMap": true, - "declaration": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "module": "commonjs", - "target": "es6", - "outDir": "dist", - "baseUrl": ".", - "paths": { - "*": [ - "node_modules/*" - ] - } - }, - "files": [ - "index.d.ts" - ], - "formatCodeOptions": { - "indentSize": 2, - "tabSize": 2 - } -} diff --git a/apis/fabric-shim-api/types/tsconfig.json b/apis/fabric-shim-api/types/tsconfig.json deleted file mode 100644 index ed09ed38d..000000000 --- a/apis/fabric-shim-api/types/tsconfig.json +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2018 IBM All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 -*/ -{ - "compilerOptions": { - "removeComments": false, - "preserveConstEnums": true, - "sourceMap": true, - "declaration": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "module": "commonjs", - "target": "es6", - "outDir": "dist", - "baseUrl": ".", - "paths": { - "*": [ - "node_modules/*" - ] - }, - "lib": [ - "esnext" - ] - }, - "files": [ - "index.d.ts" - ], - "formatCodeOptions": { - "indentSize": 2, - "tabSize": 2 - } -} diff --git a/libraries/fabric-shim/test/typescript/tsconfig.json b/libraries/fabric-shim/test/typescript/tsconfig.json deleted file mode 100644 index 104e67e89..000000000 --- a/libraries/fabric-shim/test/typescript/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -/* - Copyright 2018 IBM All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 - -*/ -{ - "compilerOptions": { - "types": ["../../types/"], - "module": "commonjs", - "target": "es2017", - "sourceMap": true, - "lib": [ - "esnext" - ] - }, - "exclude": [ - "node_modules" - ] -} diff --git a/libraries/fabric-shim/types/tsconfig.json b/libraries/fabric-shim/types/tsconfig.json deleted file mode 100644 index ed09ed38d..000000000 --- a/libraries/fabric-shim/types/tsconfig.json +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2018 IBM All Rights Reserved. - - SPDX-License-Identifier: Apache-2.0 -*/ -{ - "compilerOptions": { - "removeComments": false, - "preserveConstEnums": true, - "sourceMap": true, - "declaration": true, - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "suppressImplicitAnyIndexErrors": true, - "moduleResolution": "node", - "module": "commonjs", - "target": "es6", - "outDir": "dist", - "baseUrl": ".", - "paths": { - "*": [ - "node_modules/*" - ] - }, - "lib": [ - "esnext" - ] - }, - "files": [ - "index.d.ts" - ], - "formatCodeOptions": { - "indentSize": 2, - "tabSize": 2 - } -} From d2fe43660a23126d7924ef049b56d0308589d667 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 20:53:33 +0800 Subject: [PATCH 04/14] Add project root tsconfig.json files Signed-off-by: Jerrylum --- apis/fabric-contract-api/tsconfig.json | 26 ++++++++++++++++++++++++++ apis/fabric-shim-api/tsconfig.json | 25 +++++++++++++++++++++++++ libraries/fabric-shim/tsconfig.json | 26 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 apis/fabric-contract-api/tsconfig.json create mode 100644 apis/fabric-shim-api/tsconfig.json create mode 100644 libraries/fabric-shim/tsconfig.json diff --git a/apis/fabric-contract-api/tsconfig.json b/apis/fabric-contract-api/tsconfig.json new file mode 100644 index 000000000..2f8c0cdba --- /dev/null +++ b/apis/fabric-contract-api/tsconfig.json @@ -0,0 +1,26 @@ +/* + * Copyright 2020 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + { + "compilerOptions": { + "types": ["./types/"], + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "include": [ + "lib/**/*", + "test/**/*" + ], + "exclude": [ + "node_modules/**/*" + ] +} diff --git a/apis/fabric-shim-api/tsconfig.json b/apis/fabric-shim-api/tsconfig.json new file mode 100644 index 000000000..9a07527c5 --- /dev/null +++ b/apis/fabric-shim-api/tsconfig.json @@ -0,0 +1,25 @@ +/* + * Copyright 2020 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + { + "compilerOptions": { + "types": ["./types/"], + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "files": [ + "types/index.d.ts" + ], + "exclude": [ + "node_modules/**/*" + ] +} diff --git a/libraries/fabric-shim/tsconfig.json b/libraries/fabric-shim/tsconfig.json new file mode 100644 index 000000000..2f8c0cdba --- /dev/null +++ b/libraries/fabric-shim/tsconfig.json @@ -0,0 +1,26 @@ +/* + * Copyright 2020 IBM All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + { + "compilerOptions": { + "types": ["./types/"], + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "include": [ + "lib/**/*", + "test/**/*" + ], + "exclude": [ + "node_modules/**/*" + ] +} From 73d74f8f9299d15e6798dff0e524d487159b32cc Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 20:55:45 +0800 Subject: [PATCH 05/14] Add eslint dev dependencies to fabric-shim-api project Signed-off-by: Jerrylum --- apis/fabric-shim-api/package.json | 3 ++- common/config/rush/pnpm-lock.yaml | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apis/fabric-shim-api/package.json b/apis/fabric-shim-api/package.json index a3040c578..8d5af4966 100644 --- a/apis/fabric-shim-api/package.json +++ b/apis/fabric-shim-api/package.json @@ -23,6 +23,7 @@ "types": "./types/index.d.ts", "license": "Apache-2.0", "devDependencies": { - "@types/long": "^4.0.1" + "@types/long": "^4.0.1", + "eslint": "^6.6.0" } } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 36ffcb455..30b3038a5 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -7423,11 +7423,14 @@ packages: dev: false file:projects/fabric-shim-api.tgz: - resolution: {integrity: sha512-XTqk3nknIzx9XDjIwPAqxlcbyVyZuoETwf8eWxffKlp5MOfZWy+IknQAHB23AdOuUtpAg94QVefEIkO1B2NREg==, tarball: file:projects/fabric-shim-api.tgz} + resolution: {integrity: sha512-HVtCRnEfr3iMv9+akMNMC144OI++srlpwPTyvSKr9KrQNjmIwKtEmdNOqrG5532krmUPdn+V6iFnd22PP3bc1Q==, tarball: file:projects/fabric-shim-api.tgz} name: '@rush-temp/fabric-shim-api' version: 0.0.0 dependencies: '@types/long': 4.0.2 + eslint: 6.8.0 + transitivePeerDependencies: + - supports-color dev: false file:projects/fabric-shim-docs.tgz: From c3075f1b0ed644d46a1d02d9d67ea17db9c9ce9b Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:03:44 +0800 Subject: [PATCH 06/14] Modify lint script in package.json files to check TypeScript files Signed-off-by: Jerrylum --- apis/fabric-contract-api/package.json | 2 +- apis/fabric-shim-api/package.json | 1 + libraries/fabric-shim/package.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apis/fabric-contract-api/package.json b/apis/fabric-contract-api/package.json index 1b069a95c..2d4ca9a62 100644 --- a/apis/fabric-contract-api/package.json +++ b/apis/fabric-contract-api/package.json @@ -12,7 +12,7 @@ "buildt": "tsc --project test/typescript", "test": "nyc mocha --recursive 'test/unit/**/*.js'", "build": "npm run lint && npm run test:unit && npm run test:schema", - "lint": "eslint ./lib/", + "lint": "eslint ./lib ./types ./test/typescript/*.ts --ext .js --ext .ts", "test:unit": "npm run test", "test:schema": "ajv compile -s ./schema/contract-schema.json && ajv validate -s ./schema/contract-schema.json -d ./schema/example-full.json" }, diff --git a/apis/fabric-shim-api/package.json b/apis/fabric-shim-api/package.json index 8d5af4966..2f9d5002e 100644 --- a/apis/fabric-shim-api/package.json +++ b/apis/fabric-shim-api/package.json @@ -9,6 +9,7 @@ "url": "https://github.com/hyperledger/fabric-chaincode-node" }, "scripts": { + "lint": "eslint ./types/ --ext .ts", "build": "echo No Build needed" }, "keywords": [ diff --git a/libraries/fabric-shim/package.json b/libraries/fabric-shim/package.json index e16993a38..83698fbb1 100644 --- a/libraries/fabric-shim/package.json +++ b/libraries/fabric-shim/package.json @@ -16,7 +16,7 @@ "update:pbjs": "pbjs -t static-module -p google-protos -p protos $(find google-protos protos -name \"*.proto\" -type f) -o bundle.js", "update:pbts": "pbts -o bundle.d.ts bundle.js", "update": "npm run update:clean && npm run update:copy && npm run update:pbjs && npm run update:pbts", - "lint": "eslint ./lib", + "lint": "eslint ./lib ./types ./test/typescript/*.ts --ext .js --ext .ts", "build": "npm run lint & npm test 2>&1" }, "repository": { From a9c78bbb1fde02509d63dba123861fcdb36595d1 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:07:11 +0800 Subject: [PATCH 07/14] Fix fabric-content-api project code format Signed-off-by: Jerrylum --- .../test/typescript/smartcontract.ts | 112 +++++++++--------- apis/fabric-contract-api/types/index.d.ts | 8 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/apis/fabric-contract-api/test/typescript/smartcontract.ts b/apis/fabric-contract-api/test/typescript/smartcontract.ts index e972212d5..d681ca554 100644 --- a/apis/fabric-contract-api/test/typescript/smartcontract.ts +++ b/apis/fabric-contract-api/test/typescript/smartcontract.ts @@ -5,13 +5,13 @@ */ -import { Contract, Context } from 'fabric-contract-api'; -import { ChaincodeStub, ClientIdentity } from 'fabric-shim-api'; +import {Contract, Context} from 'fabric-contract-api'; +import {ChaincodeStub, ClientIdentity} from 'fabric-shim-api'; -export class ScenarioContext extends Context{ - customFunction(): void { +export class ScenarioContext extends Context { + customFunction(): void { - } + } } export default class TestContractOne extends Contract { @@ -19,58 +19,58 @@ export default class TestContractOne extends Contract { super('org.papernet.commercialpaper'); } - beforeTransaction(ctx: ScenarioContext) { - // test that the context super class properties are available - const stubApi: ChaincodeStub = ctx.stub; - const clientIdentity: ClientIdentity = ctx.clientIdentity; - - // tests that the functions in the subclasses context be called - ctx.customFunction(); - - // This proves that typescript is enforcing the - // return type of Promise - return Promise.resolve(); - } - - afterTransaction(ctx: ScenarioContext,result: any) { - // This proves that typescript is enforcing the - // return type of Promise - return Promise.resolve(); - } - - aroundTransaction(ctx: ScenarioContext, fn: Function, parameters: any) { - // This proves that typescript is enforcing the - // return type of Promise - return super.aroundTransaction(ctx, fn, parameters); - } - - unknownTransaction(ctx: ScenarioContext){ - // This proves that typescript is enforcing the - // return type of Promise - return Promise.resolve(); - } - - createContext(){ - return new ScenarioContext(); - } - - async Transaction(ctx: ScenarioContext) { - // test that the context super class properties are available - const stubApi: ChaincodeStub = ctx.stub; - const clientIdentity: ClientIdentity = ctx.clientIdentity; - - // test that the name returns a string - const ns: string = this.getName(); - } + beforeTransaction(ctx: ScenarioContext) { + // test that the context super class properties are available + const stubApi: ChaincodeStub = ctx.stub; + const clientIdentity: ClientIdentity = ctx.clientIdentity; + + // tests that the functions in the subclasses context be called + ctx.customFunction(); + + // This proves that typescript is enforcing the + // return type of Promise + return Promise.resolve(); + } + + afterTransaction(ctx: ScenarioContext, result: any) { + // This proves that typescript is enforcing the + // return type of Promise + return Promise.resolve(); + } + + aroundTransaction(ctx: ScenarioContext, fn: Function, parameters: any) { + // This proves that typescript is enforcing the + // return type of Promise + return super.aroundTransaction(ctx, fn, parameters); + } + + unknownTransaction(ctx: ScenarioContext) { + // This proves that typescript is enforcing the + // return type of Promise + return Promise.resolve(); + } + + createContext() { + return new ScenarioContext(); + } + + async Transaction(ctx: ScenarioContext) { + // test that the context super class properties are available + const stubApi: ChaincodeStub = ctx.stub; + const clientIdentity: ClientIdentity = ctx.clientIdentity; + + // test that the name returns a string + const ns: string = this.getName(); + } } export class TestContractTwo extends Contract { - constructor() { - super(); - } - - async Transaction(ctx: Context) { - const stubApi: ChaincodeStub = ctx.stub; - const clientIdentity: ClientIdentity = ctx.clientIdentity; - } + constructor() { + super(); + } + + async Transaction(ctx: Context) { + const stubApi: ChaincodeStub = ctx.stub; + const clientIdentity: ClientIdentity = ctx.clientIdentity; + } } diff --git a/apis/fabric-contract-api/types/index.d.ts b/apis/fabric-contract-api/types/index.d.ts index 71c9342a3..8c0c5f662 100644 --- a/apis/fabric-contract-api/types/index.d.ts +++ b/apis/fabric-contract-api/types/index.d.ts @@ -6,8 +6,8 @@ */ declare module 'fabric-contract-api' { - import { Logger } from 'winston'; - import { ChaincodeStub, ClientIdentity } from 'fabric-shim-api'; + import {Logger} from 'winston'; + import {ChaincodeStub, ClientIdentity} from 'fabric-shim-api'; export class Context { stub: ChaincodeStub; @@ -36,8 +36,8 @@ declare module 'fabric-contract-api' { export class JSONSerializer { - toBuffer(result: any,schema:any,loggerPrefix?:string): Buffer; - fromBuffer(data: Buffer,schema:any,loggerPrefix?:string): any; + toBuffer(result: any, schema:any, loggerPrefix?:string): Buffer; + fromBuffer(data: Buffer, schema:any, loggerPrefix?:string): any; } export function Transaction(commit?: boolean): (target: any, propertyKey: string | symbol) => void; From 73ac1af8ffa762b2e134ef50201fba4092a4b315 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:20:19 +0800 Subject: [PATCH 08/14] Set max-len rule to warning for index.d.ts files Signed-off-by: Jerrylum --- .eslintrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.eslintrc b/.eslintrc index 0ed22b13a..7ac6d16ee 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,6 +12,12 @@ "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "off" } + }, + { + "files": ["**/index.d.ts"], + "rules": { + "max-len": "warn" + } } ], "parserOptions": { From 1ac11e8d095698a832b6e0324219d0deeedd075d Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:23:01 +0800 Subject: [PATCH 09/14] Fix fabric-shim-api project code format Signed-off-by: Jerrylum --- apis/fabric-shim-api/types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apis/fabric-shim-api/types/index.d.ts b/apis/fabric-shim-api/types/index.d.ts index 497c1dfba..cf9559e70 100644 --- a/apis/fabric-shim-api/types/index.d.ts +++ b/apis/fabric-shim-api/types/index.d.ts @@ -5,7 +5,7 @@ */ declare module 'fabric-shim-api' { - import Long = require("long"); + import Long = require('long'); interface Timestamp { seconds: Long; @@ -23,12 +23,12 @@ declare module 'fabric-shim-api' { message?: string; payload: Uint8Array; } - + interface ErrorResponse { status: RESPONSE_CODE.ERROR; message: string; payload?: Uint8Array; - } + } interface ClientIdentity { assertAttributeValue(attrName: string, attrValue: string): boolean; From 4406b1dd863003a7b65dc429fafd97ac116df048 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:24:49 +0800 Subject: [PATCH 10/14] Suppress some TypeScript ESLint rules globally Signed-off-by: Jerrylum --- .eslintrc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7ac6d16ee..38604fbfa 100644 --- a/.eslintrc +++ b/.eslintrc @@ -10,7 +10,8 @@ "files": ["**/test/typescript/*.ts"], "rules": { "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": "off" + "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-floating-promises": "off" } }, { @@ -86,6 +87,7 @@ "@typescript-eslint/explicit-member-accessibility": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/interface-name-prefix": "off", - "@typescript-eslint/no-namespace": "off" + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/typedef": "off" } } From 8d8045f6240179e8a94b5b77e9a5468f8cb32d1f Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:25:54 +0800 Subject: [PATCH 11/14] Fix fabric-shim project code format Signed-off-by: Jerrylum --- libraries/fabric-shim/lib/iterators.js | 4 +- .../fabric-shim/test/typescript/chaincode.ts | 56 +++++++++---------- libraries/fabric-shim/types/index.d.ts | 10 ++-- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/libraries/fabric-shim/lib/iterators.js b/libraries/fabric-shim/lib/iterators.js index 9016c8abb..9ca8e9cfd 100644 --- a/libraries/fabric-shim/lib/iterators.js +++ b/libraries/fabric-shim/lib/iterators.js @@ -8,7 +8,7 @@ const logger = require('./logger').getLogger('lib/iterators.js'); -const { ledger } = require('@hyperledger/fabric-protos'); +const {ledger} = require('@hyperledger/fabric-protos'); /** * CommonIterator allows a chaincode to check whether any more result(s) @@ -111,7 +111,7 @@ class CommonIterator { throw err; } } - return { done: true }; + return {done: true}; } } diff --git a/libraries/fabric-shim/test/typescript/chaincode.ts b/libraries/fabric-shim/test/typescript/chaincode.ts index 7bcd8bd2c..815e0fff9 100644 --- a/libraries/fabric-shim/test/typescript/chaincode.ts +++ b/libraries/fabric-shim/test/typescript/chaincode.ts @@ -7,7 +7,7 @@ import * as shim from 'fabric-shim'; -import { Shim, +import {Shim, ChaincodeStub, Iterators, ChaincodeInterface, @@ -21,9 +21,9 @@ import { Shim, KeyEndorsementPolicy, ENDORSER_ROLES, Timestamp - } from 'fabric-shim'; +} from 'fabric-shim'; -import { Logger } from 'winston'; +import {Logger} from 'winston'; class TestTS implements ChaincodeInterface { async Init(stub: ChaincodeStub): Promise { @@ -159,10 +159,10 @@ class TestTS implements ChaincodeInterface { await historyQuery.close(); const done: boolean = historyNext.done; const keyMod: Iterators.KeyModification = historyNext.value; - let isDelete: boolean = keyMod.isDelete; - let timestamp: Timestamp = keyMod.timestamp; - let txid: string = keyMod.txId; - let value: Uint8Array = keyMod.value; + const isDelete: boolean = keyMod.isDelete; + const timestamp: Timestamp = keyMod.timestamp; + const txid: string = keyMod.txId; + const value: Uint8Array = keyMod.value; } async testStateQueryIterator(stateQuery: Iterators.StateQueryIterator) { @@ -170,8 +170,8 @@ class TestTS implements ChaincodeInterface { await stateQuery.close(); const done: boolean = stateNext.done; const keyVal: Iterators.KV = stateNext.value; - let key: string = keyVal.key; - let val: Uint8Array = keyVal.value; + const key: string = keyVal.key; + const val: Uint8Array = keyVal.value; } async testPrivateData(stub: ChaincodeStub): Promise { @@ -217,8 +217,8 @@ class TestTS implements ChaincodeInterface { const TxTimestamp: Timestamp = stub.getTxTimestamp(); const creator: SerializedIdentity = stub.getCreator(); - let idbytes: Uint8Array = creator.idBytes; - let mspid: string = creator.mspid; + const idbytes: Uint8Array = creator.idBytes; + const mspid: string = creator.mspid; const invokeChaincode: ChaincodeResponse = await stub.invokeChaincode('ccid', ['bob', 'duck'], 'channelid'); } @@ -239,28 +239,28 @@ class TestTS implements ChaincodeInterface { } testSignedProposal(proposal: ChaincodeProposal.SignedProposal) { - let prop: ChaincodeProposal.Proposal = proposal.proposal; - let sig: Uint8Array = proposal.signature; + const prop: ChaincodeProposal.Proposal = proposal.proposal; + const sig: Uint8Array = proposal.signature; - let hdr: ChaincodeProposal.Header = prop.header; - let payload: ChaincodeProposal.ChaincodeProposalPayload = prop.payload; + const hdr: ChaincodeProposal.Header = prop.header; + const payload: ChaincodeProposal.ChaincodeProposalPayload = prop.payload; - let cHdr: ChaincodeProposal.ChannelHeader = hdr.channelHeader; - let sHdr: ChaincodeProposal.SignatureHeader = hdr.signatureHeader; + const cHdr: ChaincodeProposal.ChannelHeader = hdr.channelHeader; + const sHdr: ChaincodeProposal.SignatureHeader = hdr.signatureHeader; - let chId: string = cHdr.channelId; - let epoch: number = cHdr.epoch; - let timestamp: Timestamp = cHdr.timestamp; - let hash: Uint8Array = cHdr.tlsCertHash; - let txId: string = cHdr.txId; - let type: ChaincodeProposal.HeaderType = cHdr.type; - let version: number = cHdr.version; + const chId: string = cHdr.channelId; + const epoch: number = cHdr.epoch; + const timestamp: Timestamp = cHdr.timestamp; + const hash: Uint8Array = cHdr.tlsCertHash; + const txId: string = cHdr.txId; + const type: ChaincodeProposal.HeaderType = cHdr.type; + const version: number = cHdr.version; - let creator: SerializedIdentity = sHdr.creator; - let nonce: Uint8Array = sHdr.nonce; + const creator: SerializedIdentity = sHdr.creator; + const nonce: Uint8Array = sHdr.nonce; - let input: Uint8Array = payload.input; - let map: Map = payload.transientMap; + const input: Uint8Array = payload.input; + const map: Map = payload.transientMap; } testQueryResponseMetadata(metadata: QueryResponseMetadata) { diff --git a/libraries/fabric-shim/types/index.d.ts b/libraries/fabric-shim/types/index.d.ts index 259e543c5..bafe7dd4e 100644 --- a/libraries/fabric-shim/types/index.d.ts +++ b/libraries/fabric-shim/types/index.d.ts @@ -6,8 +6,8 @@ */ declare module 'fabric-shim' { - import { Logger } from 'winston'; - import { ChannelOptions } from '@grpc/grpc-js' + import {Logger} from 'winston'; + import {ChannelOptions} from '@grpc/grpc-js'; import { ChaincodeInterface, @@ -37,7 +37,7 @@ declare module 'fabric-shim' { SplitCompositekey, StateQueryResponse, Timestamp - } + }; export function error(msg: string): ErrorResponse; export function newLogger(name: string): Logger; @@ -95,6 +95,8 @@ declare module 'fabric-shim' { } export class ChaincodeStub implements IChaincodeStub { + static RESPONSE_CODE: ResponseCode; + getArgs(): string[]; getStringArgs(): string[]; getFunctionAndParameters(): { params: string[], fcn: string }; @@ -140,8 +142,6 @@ declare module 'fabric-shim' { getPrivateDataByRange(collection: string, startKey: string, endKey: string): Promise & AsyncIterable; getPrivateDataByPartialCompositeKey(collection: string, objectType: string, attributes: string[]): Promise & AsyncIterable; getPrivateDataQueryResult(collection: string, query: string): Promise & AsyncIterable; - - static RESPONSE_CODE: ResponseCode; } export class KeyEndorsementPolicy { From 0a05b81cf627be192cea5251e725dc33acf4e7eb Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:28:44 +0800 Subject: [PATCH 12/14] Fix incorrect test cases related to #413 Signed-off-by: Jerrylum --- libraries/fabric-shim/test/typescript/chaincode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/fabric-shim/test/typescript/chaincode.ts b/libraries/fabric-shim/test/typescript/chaincode.ts index 815e0fff9..73ec0410f 100644 --- a/libraries/fabric-shim/test/typescript/chaincode.ts +++ b/libraries/fabric-shim/test/typescript/chaincode.ts @@ -40,12 +40,12 @@ class TestTS implements ChaincodeInterface { if (fcn === 'ThrowError') { const err: Error = new Error('Had a problem'); - return shim.error(Buffer.from(err.message)); + return shim.error(err.message); } if (fcn === 'ThrowErrorShim') { const err: Error = new Error('Had a problem'); - return Shim.error(Buffer.from(err.message)); + return Shim.error(err.message); } if (fcn === 'SuccessShim') { From a572ac82520653d573c520ff11c8b84a586a2f76 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Wed, 13 Mar 2024 21:36:04 +0800 Subject: [PATCH 13/14] Remove tab from .eslintrc Signed-off-by: Jerrylum --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 38604fbfa..17cda3f50 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,7 +4,7 @@ "node": true, "mocha": true }, - "extends": [ "eslint:recommended", "@rushstack/eslint-config"], + "extends": [ "eslint:recommended", "@rushstack/eslint-config"], "overrides": [ { "files": ["**/test/typescript/*.ts"], From 072c3a35f2a1b8723d93424f1deb88afde2d9d11 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Thu, 14 Mar 2024 14:02:50 +0800 Subject: [PATCH 14/14] Use 2-spaces indentation for tsconfig.json files Signed-off-by: Jerrylum --- apis/fabric-contract-api/tsconfig.json | 36 ++++++++++++------------ apis/fabric-shim-api/tsconfig.json | 34 +++++++++++------------ libraries/fabric-ledger/tsconfig.json | 38 +++++++++++++------------- libraries/fabric-shim/tsconfig.json | 36 ++++++++++++------------ 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/apis/fabric-contract-api/tsconfig.json b/apis/fabric-contract-api/tsconfig.json index 2f8c0cdba..59a3ec302 100644 --- a/apis/fabric-contract-api/tsconfig.json +++ b/apis/fabric-contract-api/tsconfig.json @@ -3,24 +3,24 @@ * * SPDX-License-Identifier: Apache-2.0 */ - { - "compilerOptions": { +{ + "compilerOptions": { "types": ["./types/"], - "alwaysStrict": true, - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "strict": true, - "target": "es2017", - "lib": [ - "esnext", - ] - }, - "include": [ - "lib/**/*", - "test/**/*" - ], - "exclude": [ - "node_modules/**/*" + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "include": [ + "lib/**/*", + "test/**/*" + ], + "exclude": [ + "node_modules/**/*" ] } diff --git a/apis/fabric-shim-api/tsconfig.json b/apis/fabric-shim-api/tsconfig.json index 9a07527c5..1e383873d 100644 --- a/apis/fabric-shim-api/tsconfig.json +++ b/apis/fabric-shim-api/tsconfig.json @@ -3,23 +3,23 @@ * * SPDX-License-Identifier: Apache-2.0 */ - { - "compilerOptions": { +{ + "compilerOptions": { "types": ["./types/"], - "alwaysStrict": true, - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "strict": true, - "target": "es2017", - "lib": [ - "esnext", - ] - }, - "files": [ - "types/index.d.ts" - ], - "exclude": [ - "node_modules/**/*" + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "files": [ + "types/index.d.ts" + ], + "exclude": [ + "node_modules/**/*" ] } diff --git a/libraries/fabric-ledger/tsconfig.json b/libraries/fabric-ledger/tsconfig.json index 19d76142c..c45fb9418 100644 --- a/libraries/fabric-ledger/tsconfig.json +++ b/libraries/fabric-ledger/tsconfig.json @@ -4,24 +4,24 @@ * SPDX-License-Identifier: Apache-2.0 */ { - "compilerOptions": { - "alwaysStrict": true, - "module": "commonjs", - "declaration": true, - "outDir": "lib", - "rootDir": "src", - "sourceMap": true, - "strict": true, - "target": "es2017", - "lib": [ - "esnext", - "esnext.asynciterable" - ] - }, - "include": [ - "src/**/*" - ], - "exclude": [ - "node_modules/**/*" + "compilerOptions": { + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "outDir": "lib", + "rootDir": "src", + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + "esnext.asynciterable" + ] + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "node_modules/**/*" ] } diff --git a/libraries/fabric-shim/tsconfig.json b/libraries/fabric-shim/tsconfig.json index 2f8c0cdba..59a3ec302 100644 --- a/libraries/fabric-shim/tsconfig.json +++ b/libraries/fabric-shim/tsconfig.json @@ -3,24 +3,24 @@ * * SPDX-License-Identifier: Apache-2.0 */ - { - "compilerOptions": { +{ + "compilerOptions": { "types": ["./types/"], - "alwaysStrict": true, - "module": "commonjs", - "declaration": true, - "sourceMap": true, - "strict": true, - "target": "es2017", - "lib": [ - "esnext", - ] - }, - "include": [ - "lib/**/*", - "test/**/*" - ], - "exclude": [ - "node_modules/**/*" + "alwaysStrict": true, + "module": "commonjs", + "declaration": true, + "sourceMap": true, + "strict": true, + "target": "es2017", + "lib": [ + "esnext", + ] + }, + "include": [ + "lib/**/*", + "test/**/*" + ], + "exclude": [ + "node_modules/**/*" ] }