@@ -25,6 +25,7 @@ Write JS code that you can run on servers, browsers or other clients.
2525 * [ Server] ( #server )
2626 * [ Client] ( #client )
2727- [ Repl] ( #repl )
28+ - [ Functions] ( #functions )
2829- [ Promises] ( #promises )
2930 * [ .then / .catch] ( #then--catch )
3031 * [ await] ( #await )
@@ -114,17 +115,14 @@ core or around it. Things like supporting more complex (de)serializers, errors
114115and maybe mixing client functions with sendscript programs. Contact me if I have
115116piqued your interest.
116117
117- ***
118-
119- SendScript leaves it up to you to choose HTTP, web-sockets or any other method
120- of communication between servers and clients that best fits your needs.
121-
122118## Reference
123119
124120<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
125121
126122### defaultLeafParse
127123
124+ [ parse.mjs:49-49] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L49-L49 " Source code on GitHub ")
125+
128126Default deserializer for leaf nodes.
129127
130128#### Parameters
@@ -135,6 +133,8 @@ Returns **any** 
135133
136134### Parse
137135
136+ [ parse.mjs:68-215] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L68-L215 " Source code on GitHub ")
137+
138138#### Parameters
139139
140140* ` schema ` ** [ Schema] ( #schema ) **   ;
@@ -145,6 +145,8 @@ Returns **[parse](#parse)** 
145145
146146### parse
147147
148+ [ parse.mjs:78-214] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/parse.mjs#L78-L214 " Source code on GitHub ")
149+
148150Parses and executes a serialized program.
149151
150152#### Parameters
@@ -155,6 +157,8 @@ Returns **(any | [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Ref
155157
156158### References
157159
160+ [ references.mjs:109-127] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/references.mjs#L109-L127 " Source code on GitHub ")
161+
158162Builds a nested API structure from a schema definition.
159163
160164#### Parameters
@@ -170,12 +174,16 @@ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
170174
171175### SchemaNode
172176
177+ [ schema.mjs:1-19] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/schema.mjs#L1-L6 " Source code on GitHub ")
178+
173179A single schema node.
174180
175181Type: ([ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) | \[ [ string] ( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String ) , [ Schema] ( #schema )] )
176182
177183### Schema
178184
185+ [ schema.mjs:1-19] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/schema.mjs#L8-L18 " Source code on GitHub ")
186+
179187A schema defines the structure of the runtime API tree.
180188
181189* string → leaf node
@@ -187,6 +195,8 @@ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global
187195
188196### defaultLeafStringify
189197
198+ [ stringify.mjs:37-47] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L37-L47 " Source code on GitHub ")
199+
190200Default strict serializer for leaf values.
191201
192202Rejects non-JSON-safe values.
@@ -199,6 +209,8 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
199209
200210### Stringify
201211
212+ [ stringify.mjs:56-157] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L56-L157 " Source code on GitHub ")
213+
202214Creates a stringify function for SendScript AST structures.
203215
204216#### Parameters
@@ -209,6 +221,8 @@ Returns **[stringify](#stringify)** 
209221
210222### stringify
211223
224+ [ stringify.mjs:64-156] ( https://github.com/bas080/sendscript/blob/5249a85a08b10485f0d64058fd2c8bcaae84edda/stringify.mjs#L64-L156 " Source code on GitHub ")
225+
212226Serializes a program into a JSON string representation.
213227
214228#### Parameters
@@ -219,6 +233,9 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G
219233
220234## Socket example
221235
236+ SendScript leaves it up to you to choose HTTP, web-sockets or any other method
237+ of communication between servers and clients that best fits your needs.
238+
222239For this example we'll use [ socket.io] [ socket.io ] .
223240
224241### Module
@@ -325,6 +342,24 @@ run it by simply typing `sendscript` in their console.
325342> Use the ` DEBUG='*' ` to enable all logs or ` DEBUG='sendscript:*' ` for
326343> printingonly sendscript logs.
327344
345+ ## Functions
346+
347+ SendScript as of ` v2.4 ` supports functions to do basic templating. It does not
348+ support async functions and will throw an error when you define one.
349+
350+ Under the hood the function is called when it is being parsed. Make sure you
351+ understand what you are doing when mixing client and server functions.
352+
353+ ``` js
354+ map ((a ) => add (a, 1 ))([1 , 2 , 3 ]))
355+ ```
356+
357+ It also supports nested functions.
358+
359+ ``` js
360+ map (call)(map ((a ) => () => add (a, 1 ))([1 , 2 , 3 ]))
361+ ```
362+
328363## Promises
329364
330365### .then / .catch
0 commit comments