You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You will likely need to define better helpers that makes it safer to handle rejections and work with promises. It is however sensible to have
231
-
this basic behavior for the sendscript DSL and parser.
230
+
You will likely need to define better helpers that makes it safer to handle
231
+
rejections and work with promises. It is however sensible to have this basic
232
+
behavior for the sendscript DSL and parser.
232
233
233
234
### await
234
235
235
-
SendScript supports async/await seamlessly within a single request. This avoids the performance pitfalls of waterfall-style messaging, which can be especially slow on high-latency networks.
236
+
SendScript supports async/await seamlessly within a single request. This avoids
237
+
the performance pitfalls of waterfall-style messaging, which can be especially
238
+
slow on high-latency networks.
236
239
237
-
While it's possible to chain promises manually or use utility functions, native async/await support makes your code more readable, modern, and easier to reason about — aligning SendScript with today’s JavaScript best practices.
240
+
While it's possible to chain promises manually or use utility functions, native
241
+
async/await support makes your code more readable, modern, and easier to reason
242
+
about — aligning SendScript with today’s JavaScript best practices.
You can see the docs [here](./example/typescript/docs/globals.md)
302
308
303
-
> [!NOTE]
304
-
> Although type coercion on the client side can improve the development
305
-
> experience, it does not represent the actual type.
306
-
> Values are subject to serialization and deserialization.
307
-
309
+
> [!NOTE] Although type coercion on the client side can improve the development
310
+
> experience, it does not represent the actual type. Values are subject to
311
+
> serialization and deserialization.
308
312
309
313
## Schema and Nested Modules
310
314
311
-
Sendscript allows you to define your API as a **nested object of functions**, making it easy to organize your DSL into modules and submodules. Each function is instrumented so that when serialized, it produces a structured reference that can be safely sent and executed elsewhere.
315
+
Sendscript allows you to define your API as a **nested object of functions**,
316
+
making it easy to organize your DSL into modules and submodules. Each function
317
+
is instrumented so that when serialized, it produces a structured reference that
318
+
can be safely sent and executed elsewhere.
312
319
313
320
### Defining a Nested Module
314
321
@@ -340,25 +347,21 @@ Functions are referenced via their **path in the module tree**:
SendScript focuses on program serialization and execution. For runtime input validation, you can use [Zod](https://zod.dev).
355
+
SendScript focuses on program serialization and execution. For runtime input
356
+
validation, you can use [Zod](https://zod.dev).
354
357
355
358
### Validating structured input
356
359
357
360
```js
358
361
constuserSchema=z.object({
359
362
id:z.string().uuid(),
360
363
name:z.string(),
361
-
roles:z.array(z.string())
364
+
roles:z.array(z.string()),
362
365
})
363
366
364
367
exportfunctioncreateUser(user) {
@@ -376,13 +379,19 @@ export function createUser(user) {
376
379
377
380
## Leaf Serializer
378
381
379
-
By default, SendScript uses JSON for serialization, which limits support to primitives and plain objects/arrays. To support richer JavaScript types like `Date`, `RegExp`, `BigInt`, `Map`, `Set`, and `undefined`, you can provide custom serialization functions.
382
+
By default, SendScript uses JSON for serialization, which limits support to
383
+
primitives and plain objects/arrays. To support richer JavaScript types like
384
+
`Date`, `RegExp`, `BigInt`, `Map`, `Set`, and `undefined`, you can provide
385
+
custom serialization functions.
380
386
381
-
The `stringify` function accepts an optional `leafSerializer` parameter, and `parse` accepts an optional `leafDeserializer` parameter. These functions control how non-SendScript values (leaves) are encoded and decoded.
387
+
The `stringify` function accepts an optional `leafSerializer` parameter, and
388
+
`parse` accepts an optional `leafDeserializer` parameter. These functions
389
+
control how non-SendScript values (leaves) are encoded and decoded.
382
390
383
391
### Example with superjson
384
392
385
-
Here's how to use [superjson](https://github.com/blitz-js/superjson) to support extended types:
393
+
Here's how to use [superjson](https://github.com/blitz-js/superjson) to support
0 commit comments