Add alias flag for allowing bytes
This commit is contained in:
parent
97ce0ea9b5
commit
339d3006d6
42
.vscode/tasks.json
vendored
Normal file
42
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/examples/CSharp/Example/CSharp_Example.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/examples/CSharp/Example/CSharp_Example.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"${workspaceFolder}/examples/CSharp/Example/CSharp_Example.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
@ -10046,7 +10046,7 @@ function get_ir(parsed) {
|
||||
]);
|
||||
} else if (statement.type == "define") {
|
||||
options[statement.key] = statement.value;
|
||||
if (statement.key == "use_messagepack" && statement.value == "true") {
|
||||
if ((statement.key == "use_messagepack" || statement.key == "allow_bytes") && statement.value == "true") {
|
||||
builtin.push("bytes");
|
||||
}
|
||||
} else {
|
||||
@ -10260,7 +10260,6 @@ var TypescriptTarget = class extends CompileTarget {
|
||||
const params = fnc.inputs.map((e) => `${e.name}: ${toJSType(e.type) + (e.array ? "[]" : "")}`).join(", ");
|
||||
if (!fnc.return) {
|
||||
a(1, `${fnc.name}(${params}): void {`);
|
||||
1;
|
||||
a(2, `this._provider.sendMessage({`);
|
||||
a(3, `jsonrpc: "2.0",`);
|
||||
a(3, `method: "${def.name}.${fnc.name}",`);
|
||||
|
12
meta.json
Normal file
12
meta.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "jsonrpc",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||
"contributors": [],
|
||||
"files": [
|
||||
"**/*.ts",
|
||||
"**/*.js",
|
||||
"README.md"
|
||||
]
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hibas123/jrpcgen",
|
||||
"version": "1.0.30",
|
||||
"version": "1.0.31",
|
||||
"main": "lib/index.js",
|
||||
"license": "MIT",
|
||||
"packageManager": "yarn@3.1.1",
|
||||
|
90
src/ir.ts
90
src/ir.ts
@ -40,13 +40,13 @@ export type ServiceFunctionDecorators = {
|
||||
description: string;
|
||||
}[];
|
||||
returns: string;
|
||||
}
|
||||
};
|
||||
|
||||
export interface ServiceFunctionParamsDefinition {
|
||||
name: string;
|
||||
inputs: { type: string; name: string, array: boolean }[];
|
||||
return: { type: string, array: boolean } | undefined;
|
||||
decorators: ServiceFunctionDecorators
|
||||
inputs: { type: string; name: string; array: boolean }[];
|
||||
return: { type: string; array: boolean } | undefined;
|
||||
decorators: ServiceFunctionDecorators;
|
||||
}
|
||||
export type ServiceFunctionDefinition = ServiceFunctionParamsDefinition;
|
||||
|
||||
@ -62,8 +62,8 @@ export type Step = [
|
||||
];
|
||||
|
||||
export type IR = {
|
||||
options: { [key:string]: string},
|
||||
steps: Step[]
|
||||
options: { [key: string]: string };
|
||||
steps: Step[];
|
||||
};
|
||||
|
||||
export default function get_ir(parsed: Parsed): IR {
|
||||
@ -101,7 +101,10 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
}
|
||||
|
||||
if (defined.indexOf(field.fieldtype) < 0) {
|
||||
if (builtin.indexOf(field.fieldtype) < 0 && field.fieldtype !== statement.name) {
|
||||
if (
|
||||
builtin.indexOf(field.fieldtype) < 0 &&
|
||||
field.fieldtype !== statement.name
|
||||
) {
|
||||
throw new IRError(
|
||||
field,
|
||||
`Type ${field.fieldtype} is not defined!`
|
||||
@ -112,11 +115,7 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
depends.push(field.fieldtype);
|
||||
}
|
||||
|
||||
if (
|
||||
field.map &&
|
||||
field.map !== "number" &&
|
||||
field.map !== "string"
|
||||
) {
|
||||
if (field.map && field.map !== "number" && field.map !== "string") {
|
||||
throw new IRError(
|
||||
field,
|
||||
`Type ${field.map} is not valid as map key!`
|
||||
@ -200,7 +199,10 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
if (!depends.some((a) => a === fnc.return_type.type))
|
||||
depends.push(fnc.return_type.type);
|
||||
} else {
|
||||
if (fnc.return_type.type !== "void" && builtin.indexOf(fnc.return_type.type) < 0) {
|
||||
if (
|
||||
fnc.return_type.type !== "void" &&
|
||||
builtin.indexOf(fnc.return_type.type) < 0
|
||||
) {
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Type ${fnc.return_type.type} is not defined`
|
||||
@ -230,46 +232,68 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
switch (key) {
|
||||
case "Description":
|
||||
if (decorators.description)
|
||||
throw new IRError(fnc, `Decorator 'Description' can only be used once!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Description' can only be used once!`
|
||||
);
|
||||
if (val.length != 1)
|
||||
throw new IRError(fnc, `Decorator 'Description' requires exactly one parameter!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Description' requires exactly one parameter!`
|
||||
);
|
||||
decorators.description = val[0];
|
||||
break;
|
||||
case "Returns":
|
||||
if (decorators.returns)
|
||||
throw new IRError(fnc, `Decorator 'Returns' can only be used once!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Returns' can only be used once!`
|
||||
);
|
||||
if (val.length != 1)
|
||||
throw new IRError(fnc, `Decorator 'Returns' requires exactly one parameter!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Returns' requires exactly one parameter!`
|
||||
);
|
||||
decorators.returns = val[0];
|
||||
break;
|
||||
case "Param":
|
||||
if(!decorators.parameters)
|
||||
decorators.parameters = [];
|
||||
if (!decorators.parameters) decorators.parameters = [];
|
||||
if (val.length != 2)
|
||||
throw new IRError(fnc, `Decorator 'Param' requires exactly two parameters!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Param' requires exactly two parameters!`
|
||||
);
|
||||
const [name, description] = val;
|
||||
if(!fnc.inputs.find(e=>e.name == name))
|
||||
throw new IRError(fnc, `Decorator 'Param' requires the first param to equal the name of a function parameter!`);
|
||||
if(decorators.parameters.find(e=>e.name == name))
|
||||
throw new IRError(fnc, `Decorator 'Param' has already been set for the parameter ${name}!`);
|
||||
if (!fnc.inputs.find((e) => e.name == name))
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Param' requires the first param to equal the name of a function parameter!`
|
||||
);
|
||||
if (decorators.parameters.find((e) => e.name == name))
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator 'Param' has already been set for the parameter ${name}!`
|
||||
);
|
||||
|
||||
decorators.parameters.push({
|
||||
name,
|
||||
description,
|
||||
})
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new IRError(fnc, `Decorator ${key} is not a valid decorator!`);
|
||||
throw new IRError(
|
||||
fnc,
|
||||
`Decorator ${key} is not a valid decorator!`
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
return {
|
||||
name: fnc.name,
|
||||
inputs: fnc.inputs,
|
||||
return: fnc.return_type,
|
||||
decorators
|
||||
decorators,
|
||||
} as ServiceFunctionDefinition;
|
||||
});
|
||||
|
||||
@ -283,7 +307,11 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
]);
|
||||
} else if (statement.type == "define") {
|
||||
options[statement.key] = statement.value;
|
||||
if(statement.key == "use_messagepack" && statement.value == "true") {
|
||||
if (
|
||||
(statement.key == "use_messagepack" ||
|
||||
statement.key == "allow_bytes") &&
|
||||
statement.value == "true"
|
||||
) {
|
||||
builtin.push("bytes");
|
||||
}
|
||||
} else {
|
||||
@ -293,6 +321,6 @@ export default function get_ir(parsed: Parsed): IR {
|
||||
|
||||
return {
|
||||
options,
|
||||
steps
|
||||
steps,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user