@seam-rpc/server 4.3.19 → 4.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/generate.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -17
- package/package.json +1 -1
package/dist/bin/generate.js
CHANGED
|
@@ -119,6 +119,7 @@ function convert(schema) {
|
|
|
119
119
|
export async function generateClientFile({ tsPath, jsPath, outputPath, }) {
|
|
120
120
|
const tsFile = path.resolve(process.cwd(), tsPath);
|
|
121
121
|
const tsFileName = path.basename(tsFile).slice(0, -path.extname(tsFile).length);
|
|
122
|
+
const routerName = path.basename(tsFile).slice(0, tsFile.indexOf("."));
|
|
122
123
|
const jsFile = path.resolve(process.cwd(), path.join(jsPath, tsFileName + ".js"));
|
|
123
124
|
if (!existsSync(tsFile)) {
|
|
124
125
|
throw new Error(`TS file not found: ${tsFile}`);
|
|
@@ -128,7 +129,7 @@ export async function generateClientFile({ tsPath, jsPath, outputPath, }) {
|
|
|
128
129
|
}
|
|
129
130
|
const mod = await import("file://" + jsFile);
|
|
130
131
|
const procedures = mod.default;
|
|
131
|
-
const routerName = path.basename(jsFile, path.extname(jsFile));
|
|
132
|
+
// const routerName = path.basename(jsFile, path.extname(jsFile));
|
|
132
133
|
const procMetadata = getProcedureMetadata(tsFile);
|
|
133
134
|
let output = `/**
|
|
134
135
|
* +===================================+
|
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface SeamEvents {
|
|
|
31
31
|
inputValidationError: [error: unknown, context: SeamErrorContext];
|
|
32
32
|
outputValidationError: [error: unknown, context: SeamErrorContext];
|
|
33
33
|
}
|
|
34
|
-
type ProcedureHandler<Input extends ProcedureInput, Output extends ProcedureOutput, Errors extends ProcedureErrors> = (options: ProcedureOptions<Input, Errors>) => Result<z.infer<Output>,
|
|
34
|
+
type ProcedureHandler<Input extends ProcedureInput, Output extends ProcedureOutput, Errors extends ProcedureErrors> = (options: ProcedureOptions<Input, Errors>) => Result<z.infer<Output>, RpcError> | Promise<Result<z.infer<Output>, RpcError>>;
|
|
35
35
|
interface ProcedureOptions<Input extends ProcedureInput, Errors extends ProcedureErrors> {
|
|
36
36
|
input: Simplify<ProcedureInputData<Input>>;
|
|
37
37
|
ctx: SeamContext;
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,7 @@ export class SeamRouter {
|
|
|
58
58
|
return res.sendStatus(404);
|
|
59
59
|
let input;
|
|
60
60
|
let validatedInput = undefined;
|
|
61
|
-
let output;
|
|
61
|
+
let output = undefined;
|
|
62
62
|
let validatedOutput;
|
|
63
63
|
// Middleware
|
|
64
64
|
try {
|
|
@@ -91,22 +91,18 @@ export class SeamRouter {
|
|
|
91
91
|
const ctx = {
|
|
92
92
|
request: req,
|
|
93
93
|
response: res,
|
|
94
|
-
next
|
|
94
|
+
next,
|
|
95
95
|
};
|
|
96
|
+
function toResError(error) {
|
|
97
|
+
if (error instanceof RpcError)
|
|
98
|
+
return { rpcError: true, error: error.toJSON() };
|
|
99
|
+
else
|
|
100
|
+
return { rpcError: false };
|
|
101
|
+
}
|
|
96
102
|
try {
|
|
97
103
|
output = await procedure.handler({ input: validatedInput, ctx, error: errorHandler });
|
|
98
104
|
}
|
|
99
105
|
catch (error) {
|
|
100
|
-
let errorResult = { rpcError: false };
|
|
101
|
-
if (error instanceof RpcError) {
|
|
102
|
-
errorResult = {
|
|
103
|
-
rpcError: true,
|
|
104
|
-
error: {
|
|
105
|
-
code: error.code,
|
|
106
|
-
data: error.data,
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
106
|
seamSpace.emit("apiError", error, {
|
|
111
107
|
routerPath: path,
|
|
112
108
|
procedureName: req.params.procName,
|
|
@@ -116,12 +112,12 @@ export class SeamRouter {
|
|
|
116
112
|
validatedOutput,
|
|
117
113
|
request: req,
|
|
118
114
|
response: res,
|
|
119
|
-
next: () => { res.status(400).json(
|
|
115
|
+
next: () => { res.status(400).json(toResError(error)); return next(); },
|
|
120
116
|
});
|
|
121
117
|
return;
|
|
122
118
|
}
|
|
123
|
-
if (output.ok
|
|
124
|
-
seamSpace.emit("apiError",
|
|
119
|
+
if (!output.ok) {
|
|
120
|
+
seamSpace.emit("apiError", output.error, {
|
|
125
121
|
routerPath: path,
|
|
126
122
|
procedureName: req.params.procName,
|
|
127
123
|
input,
|
|
@@ -130,7 +126,7 @@ export class SeamRouter {
|
|
|
130
126
|
validatedOutput,
|
|
131
127
|
request: req,
|
|
132
128
|
response: res,
|
|
133
|
-
next: () => { res.status(400).json(output.error); return next(); },
|
|
129
|
+
next: () => { res.status(400).json(toResError(output.error)); return next(); },
|
|
134
130
|
});
|
|
135
131
|
return;
|
|
136
132
|
}
|
|
@@ -187,7 +183,6 @@ export class SeamRouter {
|
|
|
187
183
|
response: res,
|
|
188
184
|
next: next,
|
|
189
185
|
});
|
|
190
|
-
console.log("INTERNAL ERROR", error);
|
|
191
186
|
res.sendStatus(500); //.send({ error: String(error) });
|
|
192
187
|
}
|
|
193
188
|
});
|