@seam-rpc/client 2.0.0 → 2.2.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 +31 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,16 +145,39 @@ export async function updateUser(userId: string, userData: UserData): Promise<vo
|
|
|
145
145
|
|
|
146
146
|
## Supported types
|
|
147
147
|
SeamRPC supports the following types (at least for now):
|
|
148
|
-
- string
|
|
149
|
-
- number
|
|
150
|
-
- boolean
|
|
151
|
-
-
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
148
|
+
- `string`
|
|
149
|
+
- `number`
|
|
150
|
+
- `boolean`
|
|
151
|
+
- `null`
|
|
152
|
+
- `undefined`
|
|
153
|
+
- arrays
|
|
154
|
+
- objects
|
|
155
155
|
|
|
156
156
|
Classes are technically supported, in that the data is serialized to JSON.
|
|
157
157
|
|
|
158
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
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.
|
|
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.
|
|
161
|
+
|
|
162
|
+
## Context parameter
|
|
163
|
+
|
|
164
|
+
### Server
|
|
165
|
+
If you want, you can get access to the request, response and next function from Express. Just add a parameter of type SeamContext at the end of the API function. You can name the parameter whatever you like. This parameter is optional. This parameter is not included in the client generated files.
|
|
166
|
+
|
|
167
|
+
Example:
|
|
168
|
+
```ts
|
|
169
|
+
export async function createUser(name: string, context: SeamContext): Promise<string> {
|
|
170
|
+
// Using the context to read the request path.
|
|
171
|
+
console.log("Request path:", context.request.originalUrl);
|
|
172
|
+
|
|
173
|
+
const user = {
|
|
174
|
+
id: Date.now().toString(),
|
|
175
|
+
name
|
|
176
|
+
};
|
|
177
|
+
users.push(user);
|
|
178
|
+
return user.id;
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Client
|
|
183
|
+
The client currently doesn't support access to the response object from the fetch.
|