@seam-rpc/server 1.1.2 → 2.0.0

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/README.md CHANGED
@@ -142,3 +142,19 @@ export async function updateUser(userId: string, userData: UserData): Promise<vo
142
142
  - The generated client files contain all imports from the api implementation file in the backend that import from the current relative folder (`./`). This is the simplest way I have to include imports (at least for now). It may import functions and unused symbols but that shouldn't be too worrying.
143
143
  - Don't include backend/server functions inside the server api files.
144
144
  - Only exported functions will be included in the client generated files.
145
+
146
+ ## Supported types
147
+ SeamRPC supports the following types (at least for now):
148
+ - string
149
+ - number
150
+ - boolean
151
+ - array
152
+ - object
153
+ - null
154
+ - undefined
155
+
156
+ Classes are technically supported, in that the data is serialized to JSON.
157
+
158
+ Other JavaScript types are not supported, although SeamRPC doesn't prevent you from using them, in which case they might lead to unexpected beahviour or even errors.
159
+
160
+ The Date object type is not supported (at least for now). However, you can use `number` and pass `Date.now()` or `string` and pass `new Date().toString()`. This is not different than a normal HTTP request using JSON. SeamRPC also uses JSON behind the scenes, that's why there's these limitations, which could be overcome but I've decided not to because it would probably add more overhead to the logic.
@@ -65,7 +65,8 @@ function generateClientFile(inputFile, outputPath) {
65
65
  const funcName = node.name.getText();
66
66
  const jsDoc = ts.getJSDocCommentsAndTags(node).map(e => e.getFullText()).filter(Boolean).join("\n");
67
67
  let signature = `${jsDoc}\nexport function ${funcName}(`;
68
- const paramsText = node.parameters
68
+ const params = node.parameters.filter(p => !(p.type && p.type.getText() === "SeamContext"));
69
+ const paramsText = params
69
70
  .map((p) => {
70
71
  const paramName = p.name.getText();
71
72
  const optional = p.questionToken ? "?" : "";
@@ -74,10 +75,7 @@ function generateClientFile(inputFile, outputPath) {
74
75
  })
75
76
  .join(", ");
76
77
  const returnTypeText = node.type?.getText() ?? "any";
77
- const finalReturnType = returnTypeText.startsWith("Promise<")
78
- ? returnTypeText
79
- : `Promise<${returnTypeText}>`;
80
- signature += `${paramsText}): ${finalReturnType} { return callApi("${routerName}", "${funcName}", [${node.parameters.map(e => e.name.getText()).join(", ")}]); }`;
78
+ signature += `${paramsText}): ${returnTypeText} { return callApi("${routerName}", "${funcName}", [${params.map(e => e.name.getText()).join(", ")}]); }`;
81
79
  apiDef.push(signature);
82
80
  }
83
81
  else if ((ts.isInterfaceDeclaration(node) ||
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { SeamFile, ISeamFile } from "@seam-rpc/core";
2
- import { Express, RequestHandler } from "express";
2
+ import { Express, NextFunction, Request, RequestHandler, Response } from "express";
3
3
  export { SeamFile, ISeamFile };
4
4
  export interface RouterDefinition {
5
5
  [funcName: string]: (...args: any[]) => Promise<any>;
6
6
  }
7
- export declare function createSeamSpace(app: Express, fileHandler?: RequestHandler): SeamSpace;
7
+ export declare function createSeamSpace(app: Express, fileHandler?: RequestHandler): Promise<SeamSpace>;
8
8
  export declare class SeamSpace {
9
9
  private app;
10
10
  private fileHandler;
@@ -12,3 +12,8 @@ export declare class SeamSpace {
12
12
  constructor(app: Express, fileHandler: RequestHandler);
13
13
  createRouter(path: string, routerDefinition: RouterDefinition): void;
14
14
  }
15
+ export interface SeamContext {
16
+ request: Request;
17
+ response: Response;
18
+ next: NextFunction;
19
+ }
package/dist/index.js CHANGED
@@ -3,11 +3,11 @@ import express, { Router } from "express";
3
3
  import FormData from "form-data";
4
4
  export { SeamFile };
5
5
  ;
6
- export function createSeamSpace(app, fileHandler) {
6
+ export async function createSeamSpace(app, fileHandler) {
7
7
  if (!fileHandler) {
8
8
  let multer;
9
9
  try {
10
- multer = require("multer");
10
+ multer = (await import("multer")).default;
11
11
  }
12
12
  catch {
13
13
  throw new Error("Multer is required as default file handler. Install it or provide a custom fileHandler.");
@@ -55,7 +55,12 @@ export class SeamSpace {
55
55
  }
56
56
  let result;
57
57
  try {
58
- result = await routerDefinition[req.params.funcName](...args);
58
+ const ctx = {
59
+ request: req,
60
+ response: res,
61
+ next
62
+ };
63
+ result = await routerDefinition[req.params.funcName](...args, ctx);
59
64
  }
60
65
  catch (error) {
61
66
  console.error(`Error at API function at router "${path}". Sent error to client.`, error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seam-rpc/server",
3
- "version": "1.1.2",
3
+ "version": "2.0.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -28,6 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/express": "^5.0.3",
31
+ "@types/multer": "^2.0.0",
31
32
  "@types/node": "^24.3.1",
32
33
  "express": "^5.1.0",
33
34
  "multer": "^2.0.2"