diff --git a/.idea/jsonSchemas.xml b/.idea/jsonSchemas.xml index 551a7ac1..466eeea8 100644 --- a/.idea/jsonSchemas.xml +++ b/.idea/jsonSchemas.xml @@ -3,6 +3,22 @@ + + + + + + + diff --git a/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.ts b/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.ts index 0c63def0..d28e0674 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.ts @@ -11,8 +11,9 @@ import { validateSync, } from 'class-validator' import { IsEthAddress } from '../util/IsEthAddress' +import {PaymentCreatedEvent as IPaymentCreatedEvent} from '@solomon/shared/util-event' -export class PaymentCreatedEvent { +export class PaymentCreatedEvent implements IPaymentCreatedEvent { @IsUUID() @IsString() id: string = v4() @@ -47,8 +48,8 @@ export class PaymentCreatedEvent { discount: number = 0 @Min(0) - @IsNumber() - ethPaid: number = 0 + @IsString() + ethPaid: string = '' isValid() { let errArr = validateSync(this) diff --git a/libs/shared/util-event/src/generateEventInterface.ts b/libs/shared/util-event/src/generateEventInterface.ts index 59c8ac9b..28c1770a 100644 --- a/libs/shared/util-event/src/generateEventInterface.ts +++ b/libs/shared/util-event/src/generateEventInterface.ts @@ -1,8 +1,34 @@ import { compile, compileFromFile } from 'json-schema-to-typescript' -import { write, writeFile } from "fs-extra"; +import { readFile, write, writeFile } from "fs-extra"; import path from "path"; +import { readdir } from "fs-extra"; export const generateEventInterface = async ()=> { - let res = await compileFromFile(path.resolve(__dirname, '..', '_sample.schema.json')) - await writeFile(path.resolve(__dirname, 'test.schema.ts'), res, 'utf-8') + const interfaceFolderPath = path.resolve(__dirname, '..', 'interface') + const schemaFolderPath = path.resolve(__dirname, '..', 'schema') + const schemaFileNames = await readdir(schemaFolderPath) + let indexStr = `` + + for(let schemaFileName of schemaFileNames) { + try { + const schemaFilePath = path.resolve(schemaFolderPath, schemaFileName) + const interfaceFileName = schemaFileName.replace('.schema.json', '.schema.ts') + const interfaceFilePath = path.resolve(interfaceFolderPath, interfaceFileName) + + let interfaceStr = await compileFromFile(schemaFilePath, { + unreachableDefinitions: true, + }) + + interfaceStr = interfaceStr.replace(/\[k: string]: unknown;/g, ``) + + await writeFile(interfaceFilePath, interfaceStr, 'utf-8') + indexStr += `export * from '../interface/${interfaceFileName.replace('.ts', '')}'\n` + console.log(`${interfaceFilePath} generated.`) + } catch (err) { + console.error(err) + console.log(`${schemaFileName} generate fail.`) + } + } + + await writeFile(path.resolve(__dirname, 'index.ts'), indexStr) } diff --git a/libs/shared/util-event/src/index.ts b/libs/shared/util-event/src/index.ts index e69de29b..700c92f3 100644 --- a/libs/shared/util-event/src/index.ts +++ b/libs/shared/util-event/src/index.ts @@ -0,0 +1 @@ +export * from '../interface/_sample.schema'