接入proto

This commit is contained in:
chen wei bo
2025-08-14 00:16:34 +08:00
parent 45456135e9
commit 10e90791b7
9 changed files with 213 additions and 178 deletions
+83 -32
View File
@@ -1,13 +1,15 @@
// Tools/build-proto.js
// Tools/Proto/build-proto.js
const { execSync } = require('child_process');
const fs = require('fs');
const fs = require('fs-extra');
const path = require('path');
const SRC = path.join(__dirname, '..', '..', 'Proto'); // .proto 文件目录
const OUT_JS = path.join(__dirname, '..', '..', 'assets', 'Scripts', 'proto', 'proto.pb.js');
const OUT_DTS = path.join(__dirname, '..', '..', 'assets', 'Scripts', 'proto', 'proto.pb.d.ts');
const SRC = path.join(__dirname, '..', '..', 'Proto'); // proto 文件目录
const OUT_DIR = path.join(__dirname, '..', '..', 'assets', 'Scripts', 'proto');
const OUT_JS = path.join(OUT_DIR, 'proto.pb.js');
const OUT_DTS = path.join(OUT_DIR, 'proto.pb.d.ts');
const NAMESPACE = 'proto';
// 递归收集所有 .proto 文件路径
/** 递归收集所有 .proto 文件 */
function walk(dir) {
const files = [];
for (const name of fs.readdirSync(dir)) {
@@ -19,34 +21,83 @@ function walk(dir) {
return files;
}
const allProtoFiles = walk(SRC);
if (allProtoFiles.length === 0) {
console.error('没有找到任何 .proto 文件!');
process.exit(1);
/** 清空输出目录 */
function clearOutput() {
fs.emptyDirSync(OUT_DIR);
console.log(`已清空目录: ${OUT_DIR}`);
}
// 确保输出目录存在
fs.mkdirSync(path.dirname(OUT_JS), { recursive: true });
/** 给 CJS 文件添加 default 导出 */
function addDefaultExport(jsFile) {
let code = fs.readFileSync(jsFile, 'utf8');
if (/module\.exports\s*=/.test(code) && !/module\.exports\.default\s*=/.test(code)) {
code += `\nmodule.exports.default = module.exports;`;
fs.writeFileSync(jsFile, code, 'utf8');
console.log(`已为 ${path.basename(jsFile)} 添加 default 导出`);
}
}
// 1) 生成一个 JS 文件
execSync([
'pbjs',
'-t static-module',
'-w es6', // 生成 ESM 语法
'--dependency protobufjs/minimal.js',
`-o "${OUT_JS}"`,
`-p "${SRC}"`, // 让 pbjs 识别 proto import
...allProtoFiles.map(f => `"${f}"`) // 所有 proto 文件
].join(' '), { stdio: 'inherit' });
/** 包装 d.ts 文件,修复 $protobuf & public 报错 */
function wrapDTS(filePath) {
let original = fs.readFileSync(filePath, 'utf8');
// 2) 生成一个 TS 声明文件
execSync([
'pbts',
'--main',
`-o "${OUT_DTS}"`,
`"${OUT_JS}"`
].join(' '), { stdio: 'inherit' });
// 1. 提取顶层 import(避免包进 namespace
const importLines = [];
original = original.replace(/^(import\s+.*?;)\s*$/gm, (_, imp) => {
importLines.push(imp);
return '';
});
console.log(`生成完成!
JS 文件: ${OUT_JS}
TS 文件: ${OUT_DTS}`);
// 2. 去掉 public 修饰符
original = original.replace(/^\s*public\s+/gm, '');
// 3. 包装 namespace
const wrapped = `${importLines.join('\n')}\n\ndeclare namespace ${NAMESPACE} {\n${original}\n}\nexport default ${NAMESPACE};\n`;
fs.writeFileSync(filePath, wrapped, 'utf8');
console.log(`已包装文件: ${filePath}`);
}
/** 主构建流程 */
function build() {
clearOutput();
const allProtoFiles = walk(SRC);
if (allProtoFiles.length === 0) {
console.error('没有找到任何 .proto 文件!');
process.exit(1);
}
fs.mkdirpSync(OUT_DIR);
// 1) 生成 JSCJS 格式,方便加 default
execSync([
'pbjs',
'-t static-module',
'-w commonjs', // 用 commonjs 避免 ESM 重复 default
'--dependency protobufjs/minimal.js',
`-o "${OUT_JS}"`,
`-p "${SRC}"`,
...allProtoFiles.map(f => `"${f}"`)
].join(' '), { stdio: 'inherit' });
// 2) 添加 default 导出
addDefaultExport(OUT_JS);
// 3) 生成 d.ts
execSync([
'pbts',
'--main',
`-o "${OUT_DTS}"`,
`"${OUT_JS}"`
].join(' '), { stdio: 'inherit' });
// 4) wrap d.ts
wrapDTS(OUT_DTS);
console.log(`\nProto 生成完成!
JS 文件: ${OUT_JS}
TS 文件: ${OUT_DTS}
共处理 ${allProtoFiles.length} 个 .proto 文件`);
}
build();
-15
View File
@@ -1,15 +0,0 @@
const fs = require('fs-extra');
const ps = require('path');
(async () => {
// 目标输出目录(proto 生成文件存放处)
const outDir = ps.join(__dirname, '..', '..', 'assets', 'Scripts', 'proto');
try {
await fs.emptyDir(outDir);
console.log(`已清空目录: ${outDir}`);
} catch (err) {
console.error(`清空目录失败: ${outDir}`, err);
process.exit(1);
}
})();
-34
View File
@@ -1,34 +0,0 @@
const fs = require('fs');
const path = require('path');
const DTS_DIR = path.join(__dirname, '..', '..', 'assets', 'Scripts', 'proto');
const NAMESPACE = 'proto';
function walk(dir) {
let results = [];
for (const name of fs.readdirSync(dir)) {
const p = path.join(dir, name);
const stat = fs.statSync(p);
if (stat.isDirectory()) results = results.concat(walk(p));
else if (name.endsWith('.d.ts')) results.push(p);
}
return results;
}
function wrapFile(filePath) {
const original = fs.readFileSync(filePath, 'utf8');
if (original.includes(`declare namespace ${NAMESPACE}`)) {
console.log(`跳过已包装文件: ${filePath}`);
return;
}
const wrapped = `declare namespace ${NAMESPACE} {\n${original}\n}\nexport default ${NAMESPACE};\n`;
fs.writeFileSync(filePath, wrapped, 'utf8');
console.log(`已包装文件: ${filePath}`);
}
const files = walk(DTS_DIR);
files.forEach(wrapFile);
console.log(`处理完成,共包装 ${files.length} 个 .d.ts 文件`);
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e439496c-96d0-4df3-a30f-a9505a94abe5",
"files": [],
"subMetas": {},
"userData": {}
}
+64 -62
View File
@@ -1,3 +1,5 @@
declare namespace proto {
// DO NOT EDIT! This is a generated file. Edit the JSDoc in src/*.js instead and run 'npm run build:types'.
@@ -21,17 +23,17 @@ export class LoginReq implements ILoginReq {
constructor(properties?: ILoginReq);
/** LoginReq username. */
public username: string;
username: string;
/** LoginReq password. */
public password: string;
password: string;
/**
* Creates a new LoginReq instance using the specified properties.
* @param [properties] Properties to set
* @returns LoginReq instance
*/
public static create(properties?: ILoginReq): LoginReq;
static create(properties?: ILoginReq): LoginReq;
/**
* Encodes the specified LoginReq message. Does not implicitly {@link LoginReq.verify|verify} messages.
@@ -39,7 +41,7 @@ export class LoginReq implements ILoginReq {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(message: ILoginReq, writer?: $protobuf.Writer): $protobuf.Writer;
static encode(message: ILoginReq, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Encodes the specified LoginReq message, length delimited. Does not implicitly {@link LoginReq.verify|verify} messages.
@@ -47,7 +49,7 @@ export class LoginReq implements ILoginReq {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(message: ILoginReq, writer?: $protobuf.Writer): $protobuf.Writer;
static encodeDelimited(message: ILoginReq, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Decodes a LoginReq message from the specified reader or buffer.
@@ -57,7 +59,7 @@ export class LoginReq implements ILoginReq {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): LoginReq;
static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): LoginReq;
/**
* Decodes a LoginReq message from the specified reader or buffer, length delimited.
@@ -66,21 +68,21 @@ export class LoginReq implements ILoginReq {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): LoginReq;
static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): LoginReq;
/**
* Verifies a LoginReq message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a LoginReq message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns LoginReq
*/
public static fromObject(object: { [k: string]: any }): LoginReq;
static fromObject(object: { [k: string]: any }): LoginReq;
/**
* Creates a plain object from a LoginReq message. Also converts values to other types if specified.
@@ -88,20 +90,20 @@ export class LoginReq implements ILoginReq {
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: LoginReq, options?: $protobuf.IConversionOptions): { [k: string]: any };
static toObject(message: LoginReq, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this LoginReq to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
toJSON(): { [k: string]: any };
/**
* Gets the default type url for LoginReq
* @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns The default type url
*/
public static getTypeUrl(typeUrlPrefix?: string): string;
static getTypeUrl(typeUrlPrefix?: string): string;
}
/** Properties of a LoginRes. */
@@ -127,20 +129,20 @@ export class LoginRes implements ILoginRes {
constructor(properties?: ILoginRes);
/** LoginRes success. */
public success: boolean;
success: boolean;
/** LoginRes token. */
public token: string;
token: string;
/** LoginRes message. */
public message: string;
message: string;
/**
* Creates a new LoginRes instance using the specified properties.
* @param [properties] Properties to set
* @returns LoginRes instance
*/
public static create(properties?: ILoginRes): LoginRes;
static create(properties?: ILoginRes): LoginRes;
/**
* Encodes the specified LoginRes message. Does not implicitly {@link LoginRes.verify|verify} messages.
@@ -148,7 +150,7 @@ export class LoginRes implements ILoginRes {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(message: ILoginRes, writer?: $protobuf.Writer): $protobuf.Writer;
static encode(message: ILoginRes, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Encodes the specified LoginRes message, length delimited. Does not implicitly {@link LoginRes.verify|verify} messages.
@@ -156,7 +158,7 @@ export class LoginRes implements ILoginRes {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(message: ILoginRes, writer?: $protobuf.Writer): $protobuf.Writer;
static encodeDelimited(message: ILoginRes, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Decodes a LoginRes message from the specified reader or buffer.
@@ -166,7 +168,7 @@ export class LoginRes implements ILoginRes {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): LoginRes;
static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): LoginRes;
/**
* Decodes a LoginRes message from the specified reader or buffer, length delimited.
@@ -175,21 +177,21 @@ export class LoginRes implements ILoginRes {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): LoginRes;
static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): LoginRes;
/**
* Verifies a LoginRes message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a LoginRes message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns LoginRes
*/
public static fromObject(object: { [k: string]: any }): LoginRes;
static fromObject(object: { [k: string]: any }): LoginRes;
/**
* Creates a plain object from a LoginRes message. Also converts values to other types if specified.
@@ -197,20 +199,20 @@ export class LoginRes implements ILoginRes {
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: LoginRes, options?: $protobuf.IConversionOptions): { [k: string]: any };
static toObject(message: LoginRes, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this LoginRes to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
toJSON(): { [k: string]: any };
/**
* Gets the default type url for LoginRes
* @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns The default type url
*/
public static getTypeUrl(typeUrlPrefix?: string): string;
static getTypeUrl(typeUrlPrefix?: string): string;
}
/** Namespace user. */
@@ -239,20 +241,20 @@ export namespace user {
constructor(properties?: user.IUserInfo);
/** UserInfo id. */
public id: number;
id: number;
/** UserInfo nickname. */
public nickname: string;
nickname: string;
/** UserInfo email. */
public email: string;
email: string;
/**
* Creates a new UserInfo instance using the specified properties.
* @param [properties] Properties to set
* @returns UserInfo instance
*/
public static create(properties?: user.IUserInfo): user.UserInfo;
static create(properties?: user.IUserInfo): user.UserInfo;
/**
* Encodes the specified UserInfo message. Does not implicitly {@link user.UserInfo.verify|verify} messages.
@@ -260,7 +262,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(message: user.IUserInfo, writer?: $protobuf.Writer): $protobuf.Writer;
static encode(message: user.IUserInfo, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Encodes the specified UserInfo message, length delimited. Does not implicitly {@link user.UserInfo.verify|verify} messages.
@@ -268,7 +270,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(message: user.IUserInfo, writer?: $protobuf.Writer): $protobuf.Writer;
static encodeDelimited(message: user.IUserInfo, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Decodes a UserInfo message from the specified reader or buffer.
@@ -278,7 +280,7 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.UserInfo;
static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.UserInfo;
/**
* Decodes a UserInfo message from the specified reader or buffer, length delimited.
@@ -287,21 +289,21 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.UserInfo;
static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.UserInfo;
/**
* Verifies a UserInfo message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a UserInfo message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns UserInfo
*/
public static fromObject(object: { [k: string]: any }): user.UserInfo;
static fromObject(object: { [k: string]: any }): user.UserInfo;
/**
* Creates a plain object from a UserInfo message. Also converts values to other types if specified.
@@ -309,20 +311,20 @@ export namespace user {
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: user.UserInfo, options?: $protobuf.IConversionOptions): { [k: string]: any };
static toObject(message: user.UserInfo, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this UserInfo to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
toJSON(): { [k: string]: any };
/**
* Gets the default type url for UserInfo
* @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns The default type url
*/
public static getTypeUrl(typeUrlPrefix?: string): string;
static getTypeUrl(typeUrlPrefix?: string): string;
}
/** Properties of a GetUserReq. */
@@ -342,14 +344,14 @@ export namespace user {
constructor(properties?: user.IGetUserReq);
/** GetUserReq id. */
public id: number;
id: number;
/**
* Creates a new GetUserReq instance using the specified properties.
* @param [properties] Properties to set
* @returns GetUserReq instance
*/
public static create(properties?: user.IGetUserReq): user.GetUserReq;
static create(properties?: user.IGetUserReq): user.GetUserReq;
/**
* Encodes the specified GetUserReq message. Does not implicitly {@link user.GetUserReq.verify|verify} messages.
@@ -357,7 +359,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(message: user.IGetUserReq, writer?: $protobuf.Writer): $protobuf.Writer;
static encode(message: user.IGetUserReq, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Encodes the specified GetUserReq message, length delimited. Does not implicitly {@link user.GetUserReq.verify|verify} messages.
@@ -365,7 +367,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(message: user.IGetUserReq, writer?: $protobuf.Writer): $protobuf.Writer;
static encodeDelimited(message: user.IGetUserReq, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Decodes a GetUserReq message from the specified reader or buffer.
@@ -375,7 +377,7 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.GetUserReq;
static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.GetUserReq;
/**
* Decodes a GetUserReq message from the specified reader or buffer, length delimited.
@@ -384,21 +386,21 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.GetUserReq;
static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.GetUserReq;
/**
* Verifies a GetUserReq message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a GetUserReq message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns GetUserReq
*/
public static fromObject(object: { [k: string]: any }): user.GetUserReq;
static fromObject(object: { [k: string]: any }): user.GetUserReq;
/**
* Creates a plain object from a GetUserReq message. Also converts values to other types if specified.
@@ -406,20 +408,20 @@ export namespace user {
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: user.GetUserReq, options?: $protobuf.IConversionOptions): { [k: string]: any };
static toObject(message: user.GetUserReq, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this GetUserReq to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
toJSON(): { [k: string]: any };
/**
* Gets the default type url for GetUserReq
* @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns The default type url
*/
public static getTypeUrl(typeUrlPrefix?: string): string;
static getTypeUrl(typeUrlPrefix?: string): string;
}
/** Properties of a GetUserRes. */
@@ -445,20 +447,20 @@ export namespace user {
constructor(properties?: user.IGetUserRes);
/** GetUserRes success. */
public success: boolean;
success: boolean;
/** GetUserRes data. */
public data?: (user.IUserInfo|null);
data?: (user.IUserInfo|null);
/** GetUserRes message. */
public message: string;
message: string;
/**
* Creates a new GetUserRes instance using the specified properties.
* @param [properties] Properties to set
* @returns GetUserRes instance
*/
public static create(properties?: user.IGetUserRes): user.GetUserRes;
static create(properties?: user.IGetUserRes): user.GetUserRes;
/**
* Encodes the specified GetUserRes message. Does not implicitly {@link user.GetUserRes.verify|verify} messages.
@@ -466,7 +468,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encode(message: user.IGetUserRes, writer?: $protobuf.Writer): $protobuf.Writer;
static encode(message: user.IGetUserRes, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Encodes the specified GetUserRes message, length delimited. Does not implicitly {@link user.GetUserRes.verify|verify} messages.
@@ -474,7 +476,7 @@ export namespace user {
* @param [writer] Writer to encode to
* @returns Writer
*/
public static encodeDelimited(message: user.IGetUserRes, writer?: $protobuf.Writer): $protobuf.Writer;
static encodeDelimited(message: user.IGetUserRes, writer?: $protobuf.Writer): $protobuf.Writer;
/**
* Decodes a GetUserRes message from the specified reader or buffer.
@@ -484,7 +486,7 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.GetUserRes;
static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): user.GetUserRes;
/**
* Decodes a GetUserRes message from the specified reader or buffer, length delimited.
@@ -493,21 +495,21 @@ export namespace user {
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.GetUserRes;
static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): user.GetUserRes;
/**
* Verifies a GetUserRes message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a GetUserRes message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns GetUserRes
*/
public static fromObject(object: { [k: string]: any }): user.GetUserRes;
static fromObject(object: { [k: string]: any }): user.GetUserRes;
/**
* Creates a plain object from a GetUserRes message. Also converts values to other types if specified.
@@ -515,20 +517,20 @@ export namespace user {
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: user.GetUserRes, options?: $protobuf.IConversionOptions): { [k: string]: any };
static toObject(message: user.GetUserRes, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this GetUserRes to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
toJSON(): { [k: string]: any };
/**
* Gets the default type url for GetUserRes
* @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns The default type url
*/
public static getTypeUrl(typeUrlPrefix?: string): string;
static getTypeUrl(typeUrlPrefix?: string): string;
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ae0a4c66-1607-4fa8-858c-e077964fefd4",
"files": [],
"subMetas": {},
"userData": {}
}
+38 -34
View File
@@ -1,13 +1,15 @@
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
import * as $protobuf from "protobufjs/minimal.js";
"use strict";
var $protobuf = require("protobufjs/minimal.js");
// Common aliases
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
// Exported root namespace
const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});
export const LoginReq = $root.LoginReq = (() => {
$root.LoginReq = (function() {
/**
* Properties of a LoginReq.
@@ -27,7 +29,7 @@ export const LoginReq = $root.LoginReq = (() => {
*/
function LoginReq(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
@@ -106,9 +108,9 @@ export const LoginReq = $root.LoginReq = (() => {
LoginReq.decode = function decode(reader, length, error) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.LoginReq();
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.LoginReq();
while (reader.pos < end) {
let tag = reader.uint32();
var tag = reader.uint32();
if (tag === error)
break;
switch (tag >>> 3) {
@@ -175,7 +177,7 @@ export const LoginReq = $root.LoginReq = (() => {
LoginReq.fromObject = function fromObject(object) {
if (object instanceof $root.LoginReq)
return object;
let message = new $root.LoginReq();
var message = new $root.LoginReq();
if (object.username != null)
message.username = String(object.username);
if (object.password != null)
@@ -195,7 +197,7 @@ export const LoginReq = $root.LoginReq = (() => {
LoginReq.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
var object = {};
if (options.defaults) {
object.username = "";
object.password = "";
@@ -236,7 +238,7 @@ export const LoginReq = $root.LoginReq = (() => {
return LoginReq;
})();
export const LoginRes = $root.LoginRes = (() => {
$root.LoginRes = (function() {
/**
* Properties of a LoginRes.
@@ -257,7 +259,7 @@ export const LoginRes = $root.LoginRes = (() => {
*/
function LoginRes(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
@@ -346,9 +348,9 @@ export const LoginRes = $root.LoginRes = (() => {
LoginRes.decode = function decode(reader, length, error) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.LoginRes();
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.LoginRes();
while (reader.pos < end) {
let tag = reader.uint32();
var tag = reader.uint32();
if (tag === error)
break;
switch (tag >>> 3) {
@@ -422,7 +424,7 @@ export const LoginRes = $root.LoginRes = (() => {
LoginRes.fromObject = function fromObject(object) {
if (object instanceof $root.LoginRes)
return object;
let message = new $root.LoginRes();
var message = new $root.LoginRes();
if (object.success != null)
message.success = Boolean(object.success);
if (object.token != null)
@@ -444,7 +446,7 @@ export const LoginRes = $root.LoginRes = (() => {
LoginRes.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
var object = {};
if (options.defaults) {
object.success = false;
object.token = "";
@@ -488,14 +490,14 @@ export const LoginRes = $root.LoginRes = (() => {
return LoginRes;
})();
export const user = $root.user = (() => {
$root.user = (function() {
/**
* Namespace user.
* @exports user
* @namespace
*/
const user = {};
var user = {};
user.UserInfo = (function() {
@@ -518,7 +520,7 @@ export const user = $root.user = (() => {
*/
function UserInfo(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
@@ -607,9 +609,9 @@ export const user = $root.user = (() => {
UserInfo.decode = function decode(reader, length, error) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.UserInfo();
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.UserInfo();
while (reader.pos < end) {
let tag = reader.uint32();
var tag = reader.uint32();
if (tag === error)
break;
switch (tag >>> 3) {
@@ -683,7 +685,7 @@ export const user = $root.user = (() => {
UserInfo.fromObject = function fromObject(object) {
if (object instanceof $root.user.UserInfo)
return object;
let message = new $root.user.UserInfo();
var message = new $root.user.UserInfo();
if (object.id != null)
message.id = object.id | 0;
if (object.nickname != null)
@@ -705,7 +707,7 @@ export const user = $root.user = (() => {
UserInfo.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
var object = {};
if (options.defaults) {
object.id = 0;
object.nickname = "";
@@ -768,7 +770,7 @@ export const user = $root.user = (() => {
*/
function GetUserReq(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
@@ -837,9 +839,9 @@ export const user = $root.user = (() => {
GetUserReq.decode = function decode(reader, length, error) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.GetUserReq();
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.GetUserReq();
while (reader.pos < end) {
let tag = reader.uint32();
var tag = reader.uint32();
if (tag === error)
break;
switch (tag >>> 3) {
@@ -899,7 +901,7 @@ export const user = $root.user = (() => {
GetUserReq.fromObject = function fromObject(object) {
if (object instanceof $root.user.GetUserReq)
return object;
let message = new $root.user.GetUserReq();
var message = new $root.user.GetUserReq();
if (object.id != null)
message.id = object.id | 0;
return message;
@@ -917,7 +919,7 @@ export const user = $root.user = (() => {
GetUserReq.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
var object = {};
if (options.defaults)
object.id = 0;
if (message.id != null && message.hasOwnProperty("id"))
@@ -975,7 +977,7 @@ export const user = $root.user = (() => {
*/
function GetUserRes(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
@@ -1064,9 +1066,9 @@ export const user = $root.user = (() => {
GetUserRes.decode = function decode(reader, length, error) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.GetUserRes();
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.user.GetUserRes();
while (reader.pos < end) {
let tag = reader.uint32();
var tag = reader.uint32();
if (tag === error)
break;
switch (tag >>> 3) {
@@ -1121,7 +1123,7 @@ export const user = $root.user = (() => {
if (typeof message.success !== "boolean")
return "success: boolean expected";
if (message.data != null && message.hasOwnProperty("data")) {
let error = $root.user.UserInfo.verify(message.data);
var error = $root.user.UserInfo.verify(message.data);
if (error)
return "data." + error;
}
@@ -1142,7 +1144,7 @@ export const user = $root.user = (() => {
GetUserRes.fromObject = function fromObject(object) {
if (object instanceof $root.user.GetUserRes)
return object;
let message = new $root.user.GetUserRes();
var message = new $root.user.GetUserRes();
if (object.success != null)
message.success = Boolean(object.success);
if (object.data != null) {
@@ -1167,7 +1169,7 @@ export const user = $root.user = (() => {
GetUserRes.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
var object = {};
if (options.defaults) {
object.success = false;
object.data = null;
@@ -1214,4 +1216,6 @@ export const user = $root.user = (() => {
return user;
})();
export { $root as default };
module.exports = $root;
module.exports.default = module.exports;
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "javascript",
"imported": true,
"uuid": "594e1ab1-6e6a-490f-9466-8818050d80e9",
"files": [],
"subMetas": {},
"userData": {}
}
+1 -1
View File
@@ -20,6 +20,6 @@
"protobufjs-cli": "^1.1.3"
},
"scripts": {
"build-proto": "node ./Tools/Proto/clear-proto.js && node ./Tools/Proto/build-proto.js && node ./Tools/Proto/wrap-pbts-result.js"
"build-proto": "node ./Tools/Proto/build-proto.js"
}
}