websequencediagrams 4.0.0 → 6.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 +9 -9
- package/bin/wsd_get +1 -1
- package/{types → lib}/fileStream.d.ts +1 -3
- package/lib/fileStream.js +22 -26
- package/{types → lib}/wsd.d.ts +5 -5
- package/lib/wsd.js +42 -46
- package/package.json +2 -32
package/README.md
CHANGED
|
@@ -25,14 +25,14 @@ Call the WebSequenceDiagram.com API.
|
|
|
25
25
|
Example:
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
|
-
const wsd = require('websequencediagrams')
|
|
29
|
-
const fs = require('fs')
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const [buf, typ] = await wsd.diagram('Alice->Bob: message', 'modern-blue', 'png')
|
|
33
|
-
console.log('Received MIME type:', typ)
|
|
34
|
-
fs.writeFile('my.png', buf)
|
|
35
|
-
})()
|
|
28
|
+
const wsd = require('websequencediagrams');
|
|
29
|
+
const fs = require('node:fs');
|
|
30
|
+
|
|
31
|
+
(async() => {
|
|
32
|
+
const [buf, typ] = await wsd.diagram('Alice->Bob: message', 'modern-blue', 'png');
|
|
33
|
+
console.log('Received MIME type:', typ);
|
|
34
|
+
fs.writeFile('my.png', buf);
|
|
35
|
+
})();
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### .diagram(text, style, output_type)
|
|
@@ -53,7 +53,7 @@ Returns a promise for a string containing the URL where the diagram can be found
|
|
|
53
53
|
.styles is an array of all of the currently-known style types.
|
|
54
54
|
|
|
55
55
|
### .root
|
|
56
|
-
.root is the URL for the service, which defaults to "
|
|
56
|
+
.root is the URL for the service, which defaults to "https://www.websequencediagrams.com". It can be modified to suit your needs.
|
|
57
57
|
|
|
58
58
|
### License
|
|
59
59
|
This code is licensed under the [Apache Software License, 2.0](http://www.apache.org/licenses/LICENSE-2.0)
|
package/bin/wsd_get
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
export = FileStream;
|
|
4
2
|
/**
|
|
5
3
|
* Promisified stream for a file. Can be replaced with fs.promises one day.
|
|
@@ -30,5 +28,5 @@ declare class FileStream {
|
|
|
30
28
|
*/
|
|
31
29
|
read(): Promise<Buffer>;
|
|
32
30
|
}
|
|
33
|
-
import fs = require("fs");
|
|
31
|
+
import fs = require("node:fs");
|
|
34
32
|
import { Buffer } from "buffer";
|
package/lib/fileStream.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const {Buffer} = require('buffer')
|
|
7
|
-
const stat = util.promisify(fs.stat)
|
|
8
|
-
const readdir = util.promisify(fs.readdir)
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const fsp = require('node:fs/promises');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const {Buffer} = require('node:buffer');
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Promisified stream for a file. Can be replaced with fs.promises one day.
|
|
@@ -17,12 +15,12 @@ class FileStream {
|
|
|
17
15
|
* @param {string} [name='-'] File name, or '-' for stdin.
|
|
18
16
|
*/
|
|
19
17
|
constructor(name = '-') {
|
|
20
|
-
this.name = name
|
|
18
|
+
this.name = name;
|
|
21
19
|
if (name === '-') {
|
|
22
|
-
this.stream = process.stdin
|
|
23
|
-
process.stdin.resume()
|
|
20
|
+
this.stream = process.stdin;
|
|
21
|
+
process.stdin.resume();
|
|
24
22
|
} else {
|
|
25
|
-
this.stream = fs.createReadStream(name)
|
|
23
|
+
this.stream = fs.createReadStream(name);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
|
|
@@ -33,13 +31,11 @@ class FileStream {
|
|
|
33
31
|
*/
|
|
34
32
|
read() {
|
|
35
33
|
return new Promise((resolve, reject) => {
|
|
36
|
-
const bufs = []
|
|
37
|
-
this.stream.on('error',
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.stream.on('end', () => resolve(Buffer.concat(bufs)))
|
|
42
|
-
})
|
|
34
|
+
const bufs = /** @type {Buffer[]} */([]);
|
|
35
|
+
this.stream.on('error', reject);
|
|
36
|
+
this.stream.on('data', (/** @type {Buffer} */ data) => bufs.push(data));
|
|
37
|
+
this.stream.on('end', () => resolve(Buffer.concat(bufs)));
|
|
38
|
+
});
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
/**
|
|
@@ -53,19 +49,19 @@ class FileStream {
|
|
|
53
49
|
const streams = await Promise.all(names.map(async n => {
|
|
54
50
|
if (n === '-') {
|
|
55
51
|
// Prevent stat() throwing
|
|
56
|
-
return new FileStream()
|
|
52
|
+
return new FileStream();
|
|
57
53
|
}
|
|
58
|
-
const stats = await stat(n)
|
|
54
|
+
const stats = await fsp.stat(n);
|
|
59
55
|
if (stats.isDirectory()) {
|
|
60
|
-
const dir = await readdir(n)
|
|
56
|
+
const dir = await fsp.readdir(n);
|
|
61
57
|
return dir
|
|
62
58
|
.filter(f => f.endsWith('.wsd'))
|
|
63
|
-
.map(fn => new FileStream(path.join(n, fn)))
|
|
59
|
+
.map(fn => new FileStream(path.join(n, fn)));
|
|
64
60
|
}
|
|
65
|
-
return new FileStream(n)
|
|
66
|
-
}))
|
|
67
|
-
return streams.flat()
|
|
61
|
+
return new FileStream(n);
|
|
62
|
+
}));
|
|
63
|
+
return streams.flat();
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
66
|
|
|
71
|
-
module.exports = FileStream
|
|
67
|
+
module.exports = FileStream;
|
package/{types → lib}/wsd.d.ts
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
export = WSD;
|
|
3
2
|
/**
|
|
4
3
|
* API for WebSequenceDiagrams.
|
|
@@ -18,7 +17,7 @@ declare class WSD {
|
|
|
18
17
|
* formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
|
|
19
18
|
* account.
|
|
20
19
|
* @param {string} [apikey] API key for non-free usage.
|
|
21
|
-
* @param {string} [root='
|
|
20
|
+
* @param {string} [root='https://www.websequencediagrams.com'] Root URL for
|
|
22
21
|
* the service.
|
|
23
22
|
* @returns {Promise<string>} The URL for the diagram.
|
|
24
23
|
*/
|
|
@@ -36,10 +35,11 @@ declare class WSD {
|
|
|
36
35
|
* account.
|
|
37
36
|
* @param {string} [apikey] API key for non-free usage.
|
|
38
37
|
* @param {string} [root] Root URL for the service.
|
|
39
|
-
* @returns {Promise<
|
|
40
|
-
* first item and the MIME type of the response as the
|
|
38
|
+
* @returns {Promise<[Buffer, string]>} Array with the contents of the
|
|
39
|
+
* diagram as the first item and the MIME type of the response as the
|
|
40
|
+
* second item.
|
|
41
41
|
*/
|
|
42
|
-
static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<
|
|
42
|
+
static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<[Buffer, string]>;
|
|
43
43
|
}
|
|
44
44
|
declare namespace WSD {
|
|
45
45
|
export { styles };
|
package/lib/wsd.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const {
|
|
3
|
+
const {Buffer} = require('node:buffer');
|
|
4
|
+
const {version} = require('../package.json');
|
|
5
5
|
|
|
6
|
-
const defaultRoot = '
|
|
6
|
+
const defaultRoot = 'https://www.websequencediagrams.com';
|
|
7
7
|
const styles = [
|
|
8
8
|
'default',
|
|
9
9
|
'earth',
|
|
@@ -17,7 +17,7 @@ const styles = [
|
|
|
17
17
|
'magazine',
|
|
18
18
|
'vs2010',
|
|
19
19
|
'patent',
|
|
20
|
-
]
|
|
20
|
+
];
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* API for WebSequenceDiagrams.
|
|
@@ -37,56 +37,51 @@ class WSD {
|
|
|
37
37
|
* formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
|
|
38
38
|
* account.
|
|
39
39
|
* @param {string} [apikey] API key for non-free usage.
|
|
40
|
-
* @param {string} [root='
|
|
40
|
+
* @param {string} [root='https://www.websequencediagrams.com'] Root URL for
|
|
41
41
|
* the service.
|
|
42
42
|
* @returns {Promise<string>} The URL for the diagram.
|
|
43
43
|
*/
|
|
44
44
|
// eslint-disable-next-line max-params
|
|
45
45
|
static async diagramURL(
|
|
46
|
-
message,
|
|
46
|
+
message,
|
|
47
|
+
style = 'default',
|
|
47
48
|
format = 'png',
|
|
48
|
-
apikey =
|
|
49
|
+
apikey = undefined,
|
|
49
50
|
root = defaultRoot
|
|
50
51
|
) {
|
|
51
|
-
|
|
52
|
-
message = message.toString('utf8')
|
|
53
|
-
}
|
|
52
|
+
const msg = Buffer.isBuffer(message) ? message.toString('utf8') : message;
|
|
54
53
|
if (WSD.styles.indexOf(style) === -1) {
|
|
55
|
-
throw new Error(`Unknown style: ${style}`)
|
|
54
|
+
throw new Error(`Unknown style: ${style}`);
|
|
56
55
|
}
|
|
57
56
|
if (['png', 'pdf', 'svg'].indexOf(format) === -1) {
|
|
58
|
-
throw new Error(`Unknown format: ${format}`)
|
|
57
|
+
throw new Error(`Unknown format: ${format}`);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
const query = new URLSearchParams(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
message,
|
|
72
|
-
style,
|
|
73
|
-
format,
|
|
74
|
-
})
|
|
75
|
-
const res = await fetch(`${root}/index.php`, {
|
|
60
|
+
const query = new URLSearchParams({
|
|
61
|
+
apiVersion: '1',
|
|
62
|
+
message: msg,
|
|
63
|
+
style,
|
|
64
|
+
format,
|
|
65
|
+
...(apikey ? {apikey} : {}),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const u = new URL('index.php', root);
|
|
69
|
+
const res = await fetch(u, {
|
|
76
70
|
method: 'POST',
|
|
77
71
|
body: query,
|
|
78
|
-
|
|
72
|
+
redirect: 'error',
|
|
73
|
+
headers: {
|
|
74
|
+
'user-agent': `node-websequencediagrams/${version}`,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
79
77
|
if (res.status !== 200) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
}
|
|
82
|
-
const jres = await res.json()
|
|
83
|
-
if (!jres.errors) {
|
|
84
|
-
throw new Error(`Invalid JSON response: ${jres}`)
|
|
78
|
+
throw new Error(`${res.status} ${res.statusText}: ${res.headers.get('status')}`);
|
|
85
79
|
}
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
const jres = await res.json();
|
|
81
|
+
if (jres.errors?.length > 0) {
|
|
82
|
+
throw new Error(jres.errors.join(', '));
|
|
88
83
|
}
|
|
89
|
-
return
|
|
84
|
+
return new URL(jres.img, root).toString();
|
|
90
85
|
}
|
|
91
86
|
|
|
92
87
|
/**
|
|
@@ -102,18 +97,19 @@ class WSD {
|
|
|
102
97
|
* account.
|
|
103
98
|
* @param {string} [apikey] API key for non-free usage.
|
|
104
99
|
* @param {string} [root] Root URL for the service.
|
|
105
|
-
* @returns {Promise<
|
|
106
|
-
* first item and the MIME type of the response as the
|
|
100
|
+
* @returns {Promise<[Buffer, string]>} Array with the contents of the
|
|
101
|
+
* diagram as the first item and the MIME type of the response as the
|
|
102
|
+
* second item.
|
|
107
103
|
*/
|
|
108
104
|
// eslint-disable-next-line max-params
|
|
109
105
|
static async diagram(description, style, format, apikey, root) {
|
|
110
|
-
const u = await WSD.diagramURL(description, style, format, apikey, root)
|
|
111
|
-
const res = await fetch(u)
|
|
112
|
-
const ct = res.headers.get('content-type')
|
|
113
|
-
const buf = await res.
|
|
114
|
-
return [buf, ct]
|
|
106
|
+
const u = await WSD.diagramURL(description, style, format, apikey, root);
|
|
107
|
+
const res = await fetch(u);
|
|
108
|
+
const ct = res.headers.get('content-type') ?? 'text/plain';
|
|
109
|
+
const buf = await res.arrayBuffer();
|
|
110
|
+
return [Buffer.from(buf), ct];
|
|
115
111
|
}
|
|
116
112
|
}
|
|
117
|
-
WSD.styles = styles
|
|
113
|
+
WSD.styles = styles;
|
|
118
114
|
|
|
119
|
-
module.exports = WSD
|
|
115
|
+
module.exports = WSD;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "websequencediagrams",
|
|
3
3
|
"description": "Interface to websequencediagrams.com",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "6.0.0",
|
|
5
5
|
"author": "Joe Hildebrand <joe-github@cursive.net>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Ed Crump <ed.crump@gmail.com> (https://github.com/icedawn)",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"lib": "lib"
|
|
18
18
|
},
|
|
19
19
|
"main": "lib/wsd",
|
|
20
|
-
"types": "types/wsd.d.ts",
|
|
21
20
|
"keywords": [
|
|
22
21
|
"uml",
|
|
23
22
|
"sequence diagram",
|
|
@@ -27,39 +26,10 @@
|
|
|
27
26
|
"websequencediagrams.com"
|
|
28
27
|
],
|
|
29
28
|
"license": "Apache-2.0",
|
|
30
|
-
"scripts": {
|
|
31
|
-
"test": "ava",
|
|
32
|
-
"lint": "eslint . --ext js,cjs,mjs,md bin/*",
|
|
33
|
-
"coverage": "c8 -r lcov npm test",
|
|
34
|
-
"release": "npm version patch && git push --follow-tags && npm publish"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@cto.af/eslint-config": "^2.0.3",
|
|
38
|
-
"@types/node": "^20.3.2",
|
|
39
|
-
"ava": "^5.3.1",
|
|
40
|
-
"c8": "8.0.0",
|
|
41
|
-
"eslint": "^8.43.0",
|
|
42
|
-
"eslint-plugin-jsdoc": "^46.4.2",
|
|
43
|
-
"eslint-plugin-markdown": "^3.0.0",
|
|
44
|
-
"eslint-plugin-node": "^11.1.0",
|
|
45
|
-
"nock": "^13.3.1",
|
|
46
|
-
"tmp-promise": "^3.0.3"
|
|
47
|
-
},
|
|
48
29
|
"dependencies": {
|
|
49
|
-
"node-fetch": "2",
|
|
50
30
|
"yargs": "^17.7.2"
|
|
51
31
|
},
|
|
52
|
-
"pnpm": {
|
|
53
|
-
"overrides": {
|
|
54
|
-
"semver": ">=7.5.3",
|
|
55
|
-
"word-wrap": "npm:@aashutoshrathi/word-wrap"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"overrides": {
|
|
59
|
-
"semver": ">=7.5.3",
|
|
60
|
-
"word-wrap": "npm:@aashutoshrathi/word-wrap"
|
|
61
|
-
},
|
|
62
32
|
"engines": {
|
|
63
|
-
"node": ">=
|
|
33
|
+
"node": ">=20"
|
|
64
34
|
}
|
|
65
35
|
}
|