sendscript 2.3.3 → 2.3.4
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/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +1 -1
- package/README.md +9 -16
- package/example/typescript/docs/functions/add.md +1 -1
- package/example/typescript/docs/functions/square.md +1 -1
- package/package.json +1 -1
- package/parse.mjs +9 -6
- package/stringify.mjs +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v2.3.4](https://github.com/bas080/sendscript/compare/v2.3.3...v2.3.4)
|
|
8
|
+
|
|
9
|
+
- Improve naming in JSDocs [`669a40e`](https://github.com/bas080/sendscript/commit/669a40e28a5c77963d855dd4e2122d0ba2c074cd)
|
|
10
|
+
|
|
7
11
|
#### [v2.3.3](https://github.com/bas080/sendscript/compare/v2.3.2...v2.3.3)
|
|
8
12
|
|
|
13
|
+
> 14 April 2026
|
|
14
|
+
|
|
9
15
|
- Add JSDoc to relevant function for docs [`d1d3709`](https://github.com/bas080/sendscript/commit/d1d3709088a51b71651170ef642b013eedc9ca3a)
|
|
10
16
|
- Remove tests section from README [`5da7bb3`](https://github.com/bas080/sendscript/commit/5da7bb3f3b1dc8078683e076fe2b520bc6d28896)
|
|
11
17
|
- Add generated from JSDoc reference section [`08eb266`](https://github.com/bas080/sendscript/commit/08eb266b06d8998e6849dbc5c9738fbe782ada18)
|
package/CONTRIBUTING.md
CHANGED
|
@@ -40,7 +40,7 @@ Generate the README from the mz file.
|
|
|
40
40
|
```bash bash
|
|
41
41
|
markatzea ./README.mz | tee ./README.md
|
|
42
42
|
|
|
43
|
-
npx documentation readme references.mjs
|
|
43
|
+
npx documentation readme references.mjs stringify.mjs parse.mjs -s Reference --github --a public --markdown-toc false
|
|
44
44
|
|
|
45
45
|
npx markdown-toc --maxdepth 3 -i README.md
|
|
46
46
|
|
package/README.md
CHANGED
|
@@ -11,11 +11,11 @@ Write JS code that you can run on servers, browsers or other clients.
|
|
|
11
11
|
|
|
12
12
|
- [Introduction](#introduction)
|
|
13
13
|
- [Reference](#reference)
|
|
14
|
-
* [
|
|
14
|
+
* [defaultLeafParse](#defaultleafparse)
|
|
15
15
|
* [Parse](#parse)
|
|
16
16
|
* [parse](#parse)
|
|
17
17
|
* [References](#references)
|
|
18
|
-
* [
|
|
18
|
+
* [defaultLeafStringify](#defaultleafstringify)
|
|
19
19
|
* [Stringify](#stringify)
|
|
20
20
|
* [stringify](#stringify)
|
|
21
21
|
- [Socket example](#socket-example)
|
|
@@ -121,7 +121,7 @@ of communication between servers and clients that best fits your needs.
|
|
|
121
121
|
|
|
122
122
|
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
123
123
|
|
|
124
|
-
###
|
|
124
|
+
### defaultLeafParse
|
|
125
125
|
|
|
126
126
|
Default deserializer for leaf nodes.
|
|
127
127
|
|
|
@@ -133,20 +133,13 @@ Returns **any** 
|
|
|
133
133
|
|
|
134
134
|
### Parse
|
|
135
135
|
|
|
136
|
-
Creates a program parser for a given schema and environment.
|
|
137
|
-
|
|
138
|
-
The parser:
|
|
139
|
-
|
|
140
|
-
* resolves references into runtime functions
|
|
141
|
-
* deserializes leaf nodes
|
|
142
|
-
* collects and executes async awaits
|
|
143
|
-
* evaluates AST-like JSON programs
|
|
144
|
-
|
|
145
136
|
#### Parameters
|
|
146
137
|
|
|
147
138
|
* `schemaArg` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | \[[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)])>** 
|
|
148
|
-
* `env` **
|
|
149
|
-
* `
|
|
139
|
+
* `env` **Env** runtime environment for refs
|
|
140
|
+
* `leafParse` (optional, default `defaultLeafParse`)
|
|
141
|
+
|
|
142
|
+
Returns **[parse](#parse)** 
|
|
150
143
|
|
|
151
144
|
### parse
|
|
152
145
|
|
|
@@ -178,7 +171,7 @@ Schema supports:
|
|
|
178
171
|
|
|
179
172
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Nested instrumented API object
|
|
180
173
|
|
|
181
|
-
###
|
|
174
|
+
### defaultLeafStringify
|
|
182
175
|
|
|
183
176
|
Default strict serializer for leaf values.
|
|
184
177
|
|
|
@@ -196,7 +189,7 @@ Creates a stringify function for SendScript AST structures.
|
|
|
196
189
|
|
|
197
190
|
#### Parameters
|
|
198
191
|
|
|
199
|
-
* `
|
|
192
|
+
* `leafStringify` (optional, default `defaultLeafStringify`)
|
|
200
193
|
|
|
201
194
|
### stringify
|
|
202
195
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **add**(`a`, `b`): `number`
|
|
10
10
|
|
|
11
|
-
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/
|
|
11
|
+
Defined in: [math.ts:1](https://github.com/bas080/sendscript/blob/669a40e28a5c77963d855dd4e2122d0ba2c074cd/example/typescript/math.ts#L1)
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
14
14
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
> **square**(`a`): `number`
|
|
10
10
|
|
|
11
|
-
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/
|
|
11
|
+
Defined in: [math.ts:2](https://github.com/bas080/sendscript/blob/669a40e28a5c77963d855dd4e2122d0ba2c074cd/example/typescript/math.ts#L2)
|
|
12
12
|
|
|
13
13
|
## Parameters
|
|
14
14
|
|
package/package.json
CHANGED
package/parse.mjs
CHANGED
|
@@ -98,9 +98,12 @@ const evaluate = spy('eval', (value, awaits = []) => {
|
|
|
98
98
|
* @returns {any}
|
|
99
99
|
* @public
|
|
100
100
|
*/
|
|
101
|
-
const
|
|
101
|
+
const defaultLeafParse = (text) => JSON.parse(text)
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
|
+
* @template Env
|
|
105
|
+
* @typedef {(program: string) => any | Promise<any>} parse
|
|
106
|
+
*
|
|
104
107
|
* Creates a program parser for a given schema and environment.
|
|
105
108
|
*
|
|
106
109
|
* The parser:
|
|
@@ -110,12 +113,12 @@ const defaultLeafDeserializer = (text) => JSON.parse(text)
|
|
|
110
113
|
* - evaluates AST-like JSON programs
|
|
111
114
|
*
|
|
112
115
|
* @param {Array<string | [string, Array]>} schemaArg
|
|
113
|
-
* @param {
|
|
114
|
-
* @param {(text: string) => any} [
|
|
115
|
-
* @returns {
|
|
116
|
+
* @param {Env} env - runtime environment for refs
|
|
117
|
+
* @param {(text: string) => any} [leafParse=defaultLeafParse]
|
|
118
|
+
* @returns {parse}
|
|
116
119
|
* @public
|
|
117
120
|
*/
|
|
118
|
-
export default function Parse (schemaArg, env,
|
|
121
|
+
export default function Parse (schemaArg, env, leafParse = defaultLeafParse) {
|
|
119
122
|
const schema = flattenSchema(schemaArg)
|
|
120
123
|
|
|
121
124
|
/**
|
|
@@ -145,7 +148,7 @@ export default function Parse (schemaArg, env, deserialize = defaultLeafDeserial
|
|
|
145
148
|
const [operator, ...rest] = value
|
|
146
149
|
|
|
147
150
|
if (operator === 'leaf') {
|
|
148
|
-
const leafValue =
|
|
151
|
+
const leafValue = leafParse(rest[0])
|
|
149
152
|
return leafValue === undefined ? undefinedSentinel : leafValue
|
|
150
153
|
}
|
|
151
154
|
|
package/stringify.mjs
CHANGED
|
@@ -89,7 +89,7 @@ function transformValue (value, leafSerializer) {
|
|
|
89
89
|
* @returns {string}
|
|
90
90
|
* @public
|
|
91
91
|
*/
|
|
92
|
-
function
|
|
92
|
+
function defaultLeafStringify (x) {
|
|
93
93
|
const typeOf = typeof x
|
|
94
94
|
|
|
95
95
|
if (typeOf === 'object' || typeOf === 'function' || x === undefined) {
|
|
@@ -108,7 +108,7 @@ function strictStringify (x) {
|
|
|
108
108
|
* @returns {(program: any) => string}
|
|
109
109
|
* @public
|
|
110
110
|
*/
|
|
111
|
-
export default function Stringify (
|
|
111
|
+
export default function Stringify (leafStringify = defaultLeafStringify) {
|
|
112
112
|
/**
|
|
113
113
|
* Serializes a program into a JSON string representation.
|
|
114
114
|
*
|
|
@@ -116,9 +116,7 @@ export default function Stringify (leafSerializer = strictStringify) {
|
|
|
116
116
|
* @returns {string}
|
|
117
117
|
* @public
|
|
118
118
|
*/
|
|
119
|
-
function stringify (program) {
|
|
120
|
-
return JSON.stringify(transformValue(program,
|
|
119
|
+
return function stringify (program) {
|
|
120
|
+
return JSON.stringify(transformValue(program, leafStringify))
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
return stringify
|
|
124
122
|
}
|