Skip to content

Commit 4350775

Browse files
authored
Merge pull request #27 from hildjj/tsc
Typescript types updated
2 parents 0a1bdce + be8637d commit 4350775

File tree

9 files changed

+131
-26
lines changed

9 files changed

+131
-26
lines changed

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ pnpm-lock.yaml
1212
test/
1313
tsconfig.json
1414
.ncurc.js
15+
tsconfig.json
16+
.c8rc
17+
.ncurc
18+
eslint.config.mjs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Returns a promise for a string containing the URL where the diagram can be found
5353
.styles is an array of all of the currently-known style types.
5454

5555
### .root
56-
.root is the URL for the service, which defaults to "http://www.websequencediagrams.com". It can be modified to suit your needs.
56+
.root is the URL for the service, which defaults to "https://www.websequencediagrams.com". It can be modified to suit your needs.
5757

5858
### License
5959
This code is licensed under the [Apache Software License, 2.0](http://www.apache.org/licenses/LICENSE-2.0)

types/fileStream.d.ts renamed to lib/fileStream.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="node" />
2-
/// <reference types="node" />
31
export = FileStream;
42
/**
53
* Promisified stream for a file. Can be replaced with fs.promises one day.
@@ -30,5 +28,5 @@ declare class FileStream {
3028
*/
3129
read(): Promise<Buffer>;
3230
}
33-
import fs = require("fs");
31+
import fs = require("node:fs");
3432
import { Buffer } from "buffer";

lib/fileStream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class FileStream {
3131
*/
3232
read() {
3333
return new Promise((resolve, reject) => {
34-
const bufs = [];
34+
const bufs = /** @type {Buffer[]} */([]);
3535
this.stream.on('error', reject);
36-
this.stream.on('data', data => bufs.push(data));
36+
this.stream.on('data', (/** @type {Buffer} */ data) => bufs.push(data));
3737
this.stream.on('end', () => resolve(Buffer.concat(bufs)));
3838
});
3939
}

types/wsd.d.ts renamed to lib/wsd.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/// <reference types="node" />
21
export = WSD;
32
/**
43
* API for WebSequenceDiagrams.
@@ -18,7 +17,7 @@ declare class WSD {
1817
* formats include: 'png', 'svg', or 'pdf'. 'pdf' requires a paid
1918
* account.
2019
* @param {string} [apikey] API key for non-free usage.
21-
* @param {string} [root='http://www.websequencediagrams.com'] Root URL for
20+
* @param {string} [root='https://www.websequencediagrams.com'] Root URL for
2221
* the service.
2322
* @returns {Promise<string>} The URL for the diagram.
2423
*/
@@ -36,10 +35,11 @@ declare class WSD {
3635
* account.
3736
* @param {string} [apikey] API key for non-free usage.
3837
* @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.
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.
4141
*/
42-
static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<any[]>;
42+
static diagram(description: string, style?: string, format?: string, apikey?: string, root?: string): Promise<[Buffer, string]>;
4343
}
4444
declare namespace WSD {
4545
export { styles };

lib/wsd.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class WSD {
4646
message,
4747
style = 'default',
4848
format = 'png',
49-
apikey = null,
49+
apikey = undefined,
5050
root = defaultRoot
5151
) {
5252
const msg = Buffer.isBuffer(message) ? message.toString('utf8') : message;
@@ -98,15 +98,16 @@ class WSD {
9898
* account.
9999
* @param {string} [apikey] API key for non-free usage.
100100
* @param {string} [root] Root URL for the service.
101-
* @returns {Promise<Array>} Array with the contents of the diagram as the
102-
* first item and the MIME type of the response as the second item.
101+
* @returns {Promise<[Buffer, string]>} Array with the contents of the
102+
* diagram as the first item and the MIME type of the response as the
103+
* second item.
103104
*/
104105
// eslint-disable-next-line max-params
105106
static async diagram(description, style, format, apikey, root) {
106107
const u = await WSD.diagramURL(description, style, format, apikey, root);
107108
// eslint-disable-next-line n/no-unsupported-features/node-builtins
108109
const res = await fetch(u);
109-
const ct = res.headers.get('content-type');
110+
const ct = res.headers.get('content-type') ?? 'text/plain';
110111
const buf = await res.arrayBuffer();
111112
return [Buffer.from(buf), ct];
112113
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"lib": "lib"
1818
},
1919
"main": "lib/wsd",
20-
"types": "types/wsd.d.ts",
2120
"keywords": [
2221
"uml",
2322
"sequence diagram",
@@ -44,7 +43,8 @@
4443
"eslint-plugin-markdown": "^5.1.0",
4544
"eslint-plugin-node": "^11.1.0",
4645
"nock": "14.0.0-beta.19",
47-
"tmp-promise": "^3.0.3"
46+
"tmp-promise": "^3.0.3",
47+
"typescript": "5.7.2"
4848
},
4949
"dependencies": {
5050
"yargs": "^17.7.2"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,112 @@
11
{
2-
"include": ["lib/*.js"],
3-
2+
"include": [
3+
"lib/*.js",
4+
],
45
"compilerOptions": {
5-
"allowJs": true,
6-
"checkJs": true,
7-
"declaration": true,
8-
"emitDeclarationOnly": true,
9-
"moduleResolution": "node",
10-
"outDir": "types",
11-
"target": "ES2020"
6+
/* Visit https://aka.ms/tsconfig to read more about this file */
7+
8+
/* Projects */
9+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
10+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
11+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
12+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
13+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
14+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
15+
16+
/* Language and Environment */
17+
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
18+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
19+
// "jsx": "preserve", /* Specify what JSX code is generated. */
20+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
21+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
22+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
23+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
24+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
25+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
26+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
27+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
28+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
29+
30+
/* Modules */
31+
"module": "NodeNext", /* Specify what module code is generated. */
32+
// "rootDir": "./", /* Specify the root folder within your source files. */
33+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
34+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
35+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
36+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
37+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
38+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
39+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
40+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
41+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
42+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
43+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
44+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
45+
"resolveJsonModule": true, /* Enable importing .json files. */
46+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
47+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48+
49+
/* JavaScript Support */
50+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
51+
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
52+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53+
54+
/* Emit */
55+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
57+
"emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
59+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
61+
// "outDir": "./types", /* Specify an output folder for all emitted files. */
62+
// "removeComments": true, /* Disable emitting comments. */
63+
// "noEmit": true, /* Disable emitting files from a compilation. */
64+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
66+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
67+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
68+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
69+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
70+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
71+
// "newLine": "crlf", /* Set the newline character for emitting files. */
72+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
73+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
74+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
75+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
76+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
77+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
78+
79+
/* Interop Constraints */
80+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
81+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
82+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
83+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
84+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
85+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
86+
87+
/* Type Checking */
88+
"strict": true, /* Enable all strict type-checking options. */
89+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
90+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
91+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
92+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
93+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
94+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
95+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
96+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
97+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
98+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
99+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
100+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
101+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
102+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
103+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
104+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
105+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
106+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
107+
108+
/* Completeness */
109+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
110+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
12111
}
13112
}

0 commit comments

Comments
 (0)