allen-bbk-utils

1.0.1 • Public • Published

@ctrip/bbk-typescript-definition

Bbk component repositories.

  • Convert JSON contract to typescript definition.
  • tsd - java contract - convert

Snapshot

Installation

npm install @ctrip/bbk-typescript-definition -g

Usage

  • open a terminal and goto your project root path
  • create config file .tsdbbk.js to your project root path
  • input commander bbk-cli tsd and send Enter to generate tsd file
  • for help please input bbk-cli -h
bbk-cli tsd

configuration file

  • config file name .bbktsd.js
  • below are config values
module.exports = {
  rootTypeName: 'BBK_TYPE',           // data type interface name
  typeMap: {
    String: 'string',                   // mapping contract data type to typescript type
  },
  unknowType: 'any',                  // define unknow type to any
  contractPath: './__data__/data.ts', // contract data path
  outDir: './aaa/bbb/ccc.ts',         // build file path
}

default typeMap

let tsTypeMap = {
  true: 'boolean',
  false: 'boolean',
  string: 'string',
  success: 'string',
  boolean: 'boolean',
  number: 'number',
  date: 'Date',
  any: 'any',
};

Input ( JSON contract define )

module.exports = {
  baseResponse: {
    isSuccess: false,
    code: "String",
    returnMsg: "String",
    requestId: "String",
    cost: 0,
    showMessage: "String",
    extMap: {
      key: "String"
    },
    apiResCode: "String"
  },
  ResponseStatus: {
    Timestamp: "/Date(1576072578649+0800)/",
    Ack: "Success",
    Errors: [
      {
        Message: "String",
        ErrorCode: "String",
        StackTrace: "String",
        SeverityCode: "Error",
        ErrorFields: [
          {
            FieldName: "String",
            ErrorCode: "String",
            Message: "String"
          }
        ],
        ErrorClassification: "ServiceError"
      }
    ],
    Build: "String",
    Version: "String",
    Extension: [
      {
        Id: "String",
        Version: "String",
        ContentType: "String",
        Value: "String"
      }
    ]
  }
}

Output

export interface ExtMapType {
  key?: string,
}

export interface BaseResponseType {
  isSuccess?: boolean,
  code?: string,
  returnMsg?: string,
  requestId?: string,
  cost?: number,
  showMessage?: string,
  extMap?: ExtMapType,
  apiResCode?: string,
}

export interface ErrorFieldsType {
  FieldName?: string,
  ErrorCode?: string,
  Message?: string,
}

export interface ErrorsType {
  Message?: string,
  ErrorCode?: string,
  StackTrace?: string,
  SeverityCode?: any,
  ErrorFields?: Array<ErrorFieldsType>,
  ErrorClassification?: any,
}

export interface ExtensionType {
  Id?: string,
  Version?: string,
  ContentType?: string,
  Value?: string,
}

export interface ResponseStatusType {
  Timestamp?: Date,
  Ack?: string,
  Errors?: Array<ErrorsType>,
  Build?: string,
  Version?: string,
  Extension?: Array<ExtensionType>,
}

export interface BBK_TYPE {
  baseResponse?: BaseResponseType,
  ResponseStatus?: ResponseStatusType,
}

Readme

Keywords

Package Sidebar

Install

npm i allen-bbk-utils

Weekly Downloads

2

Version

1.0.1

License

ISC

Unpacked Size

3.6 kB

Total Files

3

Last publish

Collaborators

  • allen.zxy