websequencediagrams 2.0.0 → 3.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 CHANGED
@@ -13,6 +13,9 @@ Call the WebSequenceDiagram.com API.
13
13
  -s, --style Output style (one of: [default, earth, modern-blue, mscgen,
14
14
  omegapple, qsd, rose, roundgreen, napkin, magazine, vs2010,
15
15
  patent])
16
+ -r, --root The base URL for the service, which defaults to
17
+ "http://www.websequencediagrams.com". It can be modified
18
+ to suit your needs, if you have a private installation.
16
19
  -k, --key WebSequenceDiagrams API key. Key can also be specified with
17
20
  the WSD_APIKEY environment variable. Requires a premium
18
21
  account. See https://www.websequencediagrams.com/order.html
@@ -56,4 +59,4 @@ Returns a promise for a string containing the URL where the diagram can be found
56
59
  This code is licensed under the [Apache Software License, 2.0](http://www.apache.org/licenses/LICENSE-2.0)
57
60
 
58
61
  [![Tests](https://github.com/hildjj/node-websequencediagrams/actions/workflows/node.js.yml/badge.svg)](https://github.com/hildjj/node-websequencediagrams/actions/workflows/node.js.yml)
59
- [![Coverage Status](https://coveralls.io/repos/github/hildjj/node-websequencediagrams/badge.svg?branch=master)](https://coveralls.io/github/hildjj/node-websequencediagrams?branch=master)
62
+ [![Coverage Status](https://coveralls.io/repos/github/hildjj/node-websequencediagrams/badge.svg?branch=main)](https://coveralls.io/github/hildjj/node-websequencediagrams?branch=main)
package/bin/wsd_get CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env node
2
- /* eslint-disable node/shebang */
3
2
  'use strict'
4
3
 
5
4
  const yargs = require('yargs')
@@ -30,6 +29,12 @@ const {argv} = yargs
30
29
  choices: wsd.styles,
31
30
  default: 'default',
32
31
  },
32
+ root: {
33
+ alias: 'r',
34
+ desc: 'WebSequenceDiagrams root URL',
35
+ type: 'string',
36
+ default: 'https://websequencediagrams.com',
37
+ },
33
38
  key: {
34
39
  alias: 'k',
35
40
  desc: 'WebSequenceDiagrams API key',
@@ -57,7 +62,7 @@ FileStream.createAll(files)
57
62
  .then(async streams => {
58
63
  for (const s of streams) {
59
64
  const inp = await s.read()
60
- const [buf, typ] = await wsd.diagram(inp, argv.s, argv.f, argv.k)
65
+ const [buf, typ] = await wsd.diagram(inp, argv.s, argv.f, argv.k, argv.r)
61
66
 
62
67
  let output = argv.o
63
68
  if (!output) {
package/lib/fileStream.js CHANGED
@@ -35,7 +35,6 @@ class FileStream {
35
35
  return new Promise((resolve, reject) => {
36
36
  const bufs = []
37
37
  this.stream.on('error', er => {
38
- console.error(`error opening file ${this.name}`)
39
38
  reject(er)
40
39
  })
41
40
  this.stream.on('data', data => bufs.push(data))
package/lib/wsd.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fetch = require('node-fetch')
4
4
  const {Buffer} = require('buffer')
5
5
 
6
- const root = 'http://www.websequencediagrams.com'
6
+ const defaultRoot = 'http://www.websequencediagrams.com'
7
7
  const styles = [
8
8
  'default',
9
9
  'earth',
@@ -30,14 +30,24 @@ class WSD {
30
30
  *
31
31
  * @param {string|Buffer} message The diagram description.
32
32
  * @param {string} [style='default'] Style of the diagram. Valid styles
33
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
34
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
35
- * @param {string} [format='png'] Format for the output. Valid output formats
36
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
33
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
34
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
35
+ * 'patent'.
36
+ * @param {string} [format='png'] Format for the output. Valid output
37
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
38
+ * account.
37
39
  * @param {string} [apikey] API key for non-free usage.
40
+ * @param {string} [root='http://www.websequencediagrams.com'] Root URL for
41
+ * the service.
38
42
  * @returns {Promise<string>} The URL for the diagram.
39
43
  */
40
- static async diagramURL(message, style = 'default', format = 'png', apikey = null) {
44
+ // eslint-disable-next-line max-params
45
+ static async diagramURL(
46
+ message, style = 'default',
47
+ format = 'png',
48
+ apikey = null,
49
+ root = defaultRoot
50
+ ) {
41
51
  if (message instanceof Buffer) {
42
52
  message = message.toString('utf8')
43
53
  }
@@ -62,7 +72,7 @@ class WSD {
62
72
  style,
63
73
  format,
64
74
  })
65
- const res = await fetch(`${WSD.root}/index.php`, {
75
+ const res = await fetch(`${root}/index.php`, {
66
76
  method: 'POST',
67
77
  body: query,
68
78
  })
@@ -76,7 +86,7 @@ class WSD {
76
86
  if (jres.errors.length > 0) {
77
87
  throw new Error(jres.errors.join(', '))
78
88
  }
79
- return `${WSD.root}/${jres.img}`
89
+ return `${root}/${jres.img}`
80
90
  }
81
91
 
82
92
  /**
@@ -84,16 +94,20 @@ class WSD {
84
94
  *
85
95
  * @param {string} description The diagram description.
86
96
  * @param {string} [style='default'] Style of the diagram. Valid styles
87
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
88
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
89
- * @param {string} [format='png'] Format for the output. Valid output formats
90
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
97
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
98
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
99
+ * 'patent'.
100
+ * @param {string} [format='png'] Format for the output. Valid output
101
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
102
+ * account.
91
103
  * @param {string} [apikey] API key for non-free usage.
92
- * @returns {Promise<Array.<Buffer, string>>} Array with the contents of the
93
- * diagram and the MIME type of the response.
104
+ * @param {string} [root] Root URL for the service.
105
+ * @returns {Promise<Array>} Array with the contents of the diagram as the
106
+ * first item and the MIME type of the response as the second item.
94
107
  */
95
- static async diagram(description, style, format, apikey) {
96
- const u = await WSD.diagramURL(description, style, format, apikey)
108
+ // eslint-disable-next-line max-params
109
+ static async diagram(description, style, format, apikey, root) {
110
+ const u = await WSD.diagramURL(description, style, format, apikey, root)
97
111
  const res = await fetch(u)
98
112
  const ct = res.headers.get('content-type')
99
113
  const buf = await res.buffer()
@@ -101,6 +115,5 @@ class WSD {
101
115
  }
102
116
  }
103
117
  WSD.styles = styles
104
- WSD.root = root
105
118
 
106
119
  module.exports = WSD
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
- "author": "Joe Hildebrand <joe-github@cursive.net>",
3
2
  "name": "websequencediagrams",
4
3
  "description": "Interface to websequencediagrams.com",
5
- "version": "2.0.0",
4
+ "version": "3.0.0",
5
+ "author": "Joe Hildebrand <joe-github@cursive.net>",
6
+ "contributors": [
7
+ "Ed Crump <ed.crump@gmail.com> (https://github.com/icedawn)",
8
+ "Michael Callaghan <michael@walkingriver.com> (https://walkingriver.com)"
9
+ ],
6
10
  "homepage": "https://github.com/hildjj/node-websequencediagrams",
7
11
  "repository": {
8
12
  "type": "git",
@@ -14,9 +18,6 @@
14
18
  },
15
19
  "main": "lib/wsd",
16
20
  "types": "types/wsd.d.ts",
17
- "engines": {
18
- "node": ">=12.19"
19
- },
20
21
  "keywords": [
21
22
  "uml",
22
23
  "sequence diagram",
@@ -28,30 +29,30 @@
28
29
  "license": "Apache-2.0",
29
30
  "scripts": {
30
31
  "test": "ava",
31
- "lint": "eslint . --ext js --ext cjs --ext mjs --ext md bin/*",
32
+ "lint": "eslint . --ext js,cjs,mjs,md bin/*",
32
33
  "coverage": "nyc -r lcov npm test",
33
34
  "coveralls": "nyc report --reporter=text-lcov | coveralls",
34
35
  "precoveralls": "npm run coverage",
35
36
  "release": "npm version patch && git push --follow-tags && npm publish"
36
37
  },
37
38
  "devDependencies": {
38
- "@cto.af/eslint-config": "^0.0.8",
39
- "@types/node": "^16.4.13",
40
- "ava": "^3.15.0",
39
+ "@cto.af/eslint-config": "^0.1.7",
40
+ "@types/node": "^18.11.5",
41
+ "ava": "^5.0.1",
41
42
  "coveralls": "^3.1.1",
42
- "eslint": "^7.32.0",
43
- "eslint-plugin-jsdoc": "^36.0.6",
44
- "eslint-plugin-markdown": "^2.2.0",
43
+ "eslint": "^8.26.0",
44
+ "eslint-plugin-jsdoc": "^39.3.24",
45
+ "eslint-plugin-markdown": "^3.0.0",
45
46
  "eslint-plugin-node": "^11.1.0",
46
- "nock": "^13.1.1",
47
+ "nock": "^13.2.9",
47
48
  "nyc": "^15.1.0",
48
- "tmp-promise": "^3.0.2"
49
+ "tmp-promise": "^3.0.3"
49
50
  },
50
51
  "dependencies": {
51
- "node-fetch": "^2.6.1",
52
- "yargs": "^17.1.0"
52
+ "node-fetch": "^2.6.5",
53
+ "yargs": "^17.6.0"
53
54
  },
54
- "contributors": [
55
- "Ed Crump <ed.crump@gmail.com> (https://github.com/icedawn)"
56
- ]
55
+ "engines": {
56
+ "node": ">=14"
57
+ }
57
58
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export = FileStream;
3
4
  /**
4
5
  * Promisified stream for a file. Can be replaced with fs.promises one day.
package/types/wsd.d.ts CHANGED
@@ -11,31 +11,38 @@ declare class WSD {
11
11
  *
12
12
  * @param {string|Buffer} message The diagram description.
13
13
  * @param {string} [style='default'] Style of the diagram. Valid styles
14
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
15
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
16
- * @param {string} [format='png'] Format for the output. Valid output formats
17
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
14
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
15
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
16
+ * 'patent'.
17
+ * @param {string} [format='png'] Format for the output. Valid output
18
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
19
+ * account.
20
+ * @param {string} [apikey] API key for non-free usage.
21
+ * @param {string} [root='http://www.websequencediagrams.com'] Root URL for
22
+ * the service.
18
23
  * @returns {Promise<string>} The URL for the diagram.
19
24
  */
20
- static diagramURL(message: string | Buffer, style?: string, format?: string): Promise<string>;
25
+ static diagramURL(message: string | Buffer, style?: string, format?: string, apikey?: string, root?: string): Promise<string>;
21
26
  /**
22
27
  * Retrieve a diagram.
23
28
  *
24
29
  * @param {string} description The diagram description.
25
30
  * @param {string} [style='default'] Style of the diagram. Valid styles
26
- * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple', 'qsd',
27
- * 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or 'patent'.
28
- * @param {string} [format='png'] Format for the output. Valid output formats
29
- * include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid account.
30
- * @returns {Promise<Array.<Buffer, string>>} Array with the contents of the
31
- * diagram and the MIME type of the response.
31
+ * include: 'default', 'earth', 'modern-blue', 'mscgen', 'omegapple',
32
+ * 'qsd', 'rose', 'roundgreen', 'napkin', 'magazine', 'vs2010', or
33
+ * 'patent'.
34
+ * @param {string} [format='png'] Format for the output. Valid output
35
+ * formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
36
+ * account.
37
+ * @param {string} [apikey] API key for non-free usage.
38
+ * @param {string} [root] Root URL for the service.
39
+ * @returns {Promise<Array>} Array with the contents of the diagram as the
40
+ * first item and the MIME type of the response as the second item.
32
41
  */
33
- static diagram(description: string, style?: string, format?: string): Promise<Array<Buffer, string>>;
42
+ static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<any[]>;
34
43
  }
35
44
  declare namespace WSD {
36
45
  export { styles };
37
- export { root };
38
46
  }
39
47
  import { Buffer } from "buffer";
40
48
  declare const styles: string[];
41
- declare const root: "http://www.websequencediagrams.com";