Compare commits
6 Commits
137a3659b7
...
1.2.16
Author | SHA1 | Date | |
---|---|---|---|
e15ce1f0a0 | |||
f93755604a | |||
f401d58f07 | |||
132390fa35 | |||
04f82b655b | |||
5106424a32 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/jrpcgen",
|
"name": "@hibas123/jrpcgen",
|
||||||
"version": "1.2.6",
|
"version": "1.2.16",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -46,15 +46,22 @@ function indexToLineAndCol(src: string, index: number) {
|
|||||||
return { line, col };
|
return { line, col };
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolve(base: string, ...parts: string[]) {
|
function resolve(base: string, sub?: string) {
|
||||||
if (base.startsWith("http://") || base.startsWith("https://")) {
|
if (sub && (sub.startsWith("http://") || sub.startsWith("https://"))) {
|
||||||
|
let u = new URL(sub);
|
||||||
|
return u.href;
|
||||||
|
} else if (base.startsWith("http://") || base.startsWith("https://")) {
|
||||||
let u = new URL(base);
|
let u = new URL(base);
|
||||||
for (const part of parts) {
|
if (sub) {
|
||||||
u = new URL(part, u);
|
if (!sub.endsWith(".jrpc")) {
|
||||||
|
sub += ".jrpc";
|
||||||
|
}
|
||||||
|
u = new URL(sub, u);
|
||||||
}
|
}
|
||||||
return u.href;
|
return u.href;
|
||||||
} else {
|
} else {
|
||||||
return Path.resolve(base, ...parts);
|
if (!sub) return Path.resolve(base);
|
||||||
|
else return Path.resolve(Path.dirname(base), sub + ".jrpc");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,13 +158,7 @@ async function processFile(
|
|||||||
let resolved: Parsed = [];
|
let resolved: Parsed = [];
|
||||||
for (const statement of parsed) {
|
for (const statement of parsed) {
|
||||||
if (statement.type == "import") {
|
if (statement.type == "import") {
|
||||||
let res: string;
|
let res = resolve(file, statement.path);
|
||||||
if (file.startsWith("http://") || file.startsWith("https://")) {
|
|
||||||
res = resolve(file, statement.path + ".jrpc");
|
|
||||||
} else {
|
|
||||||
const base = Path.dirname(file);
|
|
||||||
res = resolve(base, statement.path + ".jrpc");
|
|
||||||
}
|
|
||||||
resolved.push(...((await processFile(ctx, res)) || []));
|
resolved.push(...((await processFile(ctx, res)) || []));
|
||||||
} else {
|
} else {
|
||||||
resolved.push(statement);
|
resolved.push(statement);
|
||||||
|
@ -33,7 +33,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private generateImport(imports: string, path: string) {
|
private generateImport(imports: string, path: string) {
|
||||||
return `import ${imports} from "${path + (this.flavour === "esm" ? ".ts" : "")
|
return `import ${imports} from "${path + (this.flavour === "esm" ? ".js" : "")
|
||||||
}";\n`;
|
}";\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
this.writeFormattedFile(
|
this.writeFormattedFile(
|
||||||
"service_client.ts",
|
"service_client.ts",
|
||||||
this.generateImport(
|
this.generateImport(
|
||||||
"{ RequestObject, ResponseObject, ErrorCodes, Logging }",
|
"{ type RequestObject, type ResponseObject, ErrorCodes, Logging }",
|
||||||
"./service_base"
|
"./service_base"
|
||||||
) +
|
) +
|
||||||
this.generateImport(" { VerificationError }", "./ts_base") +
|
this.generateImport(" { VerificationError }", "./ts_base") +
|
||||||
@ -304,7 +304,7 @@ export class TypescriptTarget extends CompileTarget {
|
|||||||
this.writeFormattedFile(
|
this.writeFormattedFile(
|
||||||
"service_server.ts",
|
"service_server.ts",
|
||||||
this.generateImport(
|
this.generateImport(
|
||||||
"{ RequestObject, ResponseObject, ErrorCodes, Logging }",
|
"{ type RequestObject, type ResponseObject, ErrorCodes, Logging }",
|
||||||
"./service_base"
|
"./service_base"
|
||||||
) +
|
) +
|
||||||
this.generateImport(" { VerificationError }", "./ts_base") +
|
this.generateImport(" { VerificationError }", "./ts_base") +
|
||||||
|
@ -40,7 +40,7 @@ pub struct JRPCError {
|
|||||||
pub struct JRPCResult {
|
pub struct JRPCResult {
|
||||||
pub jsonrpc: String,
|
pub jsonrpc: String,
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub result: Value,
|
pub result: Option<Value>,
|
||||||
pub error: Option<JRPCError>,
|
pub error: Option<JRPCError>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,8 +76,11 @@ impl JRPCClient {
|
|||||||
if let Some(result) = result {
|
if let Some(result) = result {
|
||||||
if let Some(error) = result.error {
|
if let Some(error) = result.error {
|
||||||
return Err(format!("Error while receiving result: {}", error.message).into());
|
return Err(format!("Error while receiving result: {}", error.message).into());
|
||||||
|
} else if let Some(result) = result.result {
|
||||||
|
return Ok(result);
|
||||||
} else {
|
} else {
|
||||||
return Ok(result.result);
|
return Ok(Value::Null);
|
||||||
|
// return Err(format!("No result received").into());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err("Error while receiving result".into());
|
return Err("Error while receiving result".into());
|
||||||
@ -133,7 +136,7 @@ impl JRPCSession {
|
|||||||
let result = JRPCResult {
|
let result = JRPCResult {
|
||||||
jsonrpc: "2.0".to_string(),
|
jsonrpc: "2.0".to_string(),
|
||||||
id: request_id,
|
id: request_id,
|
||||||
result: Value::Null,
|
result: None,
|
||||||
error: Some(error),
|
error: Some(error),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -169,7 +172,7 @@ impl JRPCSession {
|
|||||||
.send(JRPCResult {
|
.send(JRPCResult {
|
||||||
jsonrpc: "2.0".to_string(),
|
jsonrpc: "2.0".to_string(),
|
||||||
id: request.id.unwrap(),
|
id: request.id.unwrap(),
|
||||||
result,
|
result: Some(result),
|
||||||
error: None,
|
error: None,
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { isGeneratorFunction } from "util/types";
|
|
||||||
|
|
||||||
function form_verficiation_error_message(type?: string, field?: string) {
|
function form_verficiation_error_message(type?: string, field?: string) {
|
||||||
let msg = "Parameter verification failed! ";
|
let msg = "Parameter verification failed! ";
|
||||||
if (type && field) {
|
if (type && field) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//@template-ignore
|
//@template-ignore
|
||||||
import { VerificationError } from "./ts_base";
|
import { VerificationError } from "./ts_base";
|
||||||
//@template-ignore
|
//@template-ignore
|
||||||
import { RequestObject, ResponseObject, ErrorCodes, Logging } from "./ts_service_base";
|
import { type RequestObject, type ResponseObject, ErrorCodes, Logging } from "./ts_service_base";
|
||||||
|
|
||||||
|
|
||||||
export class Service<T> {
|
export class Service<T> {
|
||||||
|
Reference in New Issue
Block a user