openchemlib-search-wasm 1.2.0 → 2.1.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 +290 -3
- package/lib/functionKeys/dictionary.json +72071 -0
- package/lib/functionKeys/index.d.ts +105 -0
- package/lib/functionKeys/index.d.ts.map +1 -0
- package/lib/functionKeys/index.js +98 -0
- package/lib/functionKeys/index.js.map +1 -0
- package/lib/functions.d.ts +38 -0
- package/lib/functions.d.ts.map +1 -0
- package/lib/functions.js +54 -0
- package/lib/functions.js.map +1 -0
- package/lib/hex.d.ts +31 -0
- package/lib/hex.d.ts.map +1 -0
- package/lib/hex.js +41 -0
- package/lib/hex.js.map +1 -0
- package/lib/index.d.ts +140 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +184 -7
- package/lib/index.js.map +1 -1
- package/lib/records.d.ts +45 -0
- package/lib/records.d.ts.map +1 -0
- package/lib/records.js +96 -0
- package/lib/records.js.map +1 -0
- package/lib/scan.d.ts +99 -7
- package/lib/scan.d.ts.map +1 -1
- package/lib/scan.js +158 -11
- package/lib/scan.js.map +1 -1
- package/lib/strongHash.d.ts +9 -0
- package/lib/strongHash.d.ts.map +1 -0
- package/lib/strongHash.js +56 -0
- package/lib/strongHash.js.map +1 -0
- package/lib/substructureSearch.d.ts +8 -5
- package/lib/substructureSearch.d.ts.map +1 -1
- package/lib/substructureSearch.js +28 -5
- package/lib/substructureSearch.js.map +1 -1
- package/lib/types.d.ts +120 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +17 -1
- package/lib/types.js.map +1 -1
- package/lib/wasm/load.d.ts.map +1 -1
- package/lib/wasm/load.js +9 -1
- package/lib/wasm/load.js.map +1 -1
- package/lib/wasm/log.d.ts +36 -0
- package/lib/wasm/log.d.ts.map +1 -0
- package/lib/wasm/log.js +52 -0
- package/lib/wasm/log.js.map +1 -0
- package/package.json +6 -3
- package/src/functionKeys/index.ts +181 -0
- package/src/functions.ts +56 -0
- package/src/hex.ts +43 -0
- package/src/index.ts +269 -5
- package/src/records.ts +142 -0
- package/src/scan.ts +259 -16
- package/src/strongHash.ts +57 -0
- package/src/substructureSearch.ts +29 -6
- package/src/types.ts +171 -2
- package/src/wasm/load.ts +10 -1
- package/src/wasm/log.ts +66 -0
- package/wasm/data.js +1 -1
- package/wasm/runtime.d.ts +6 -0
package/src/wasm/log.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Which of Java's two standard streams a line came from. */
|
|
2
|
+
export type LogStream = 'stdout' | 'stderr';
|
|
3
|
+
|
|
4
|
+
/** Called with one line OpenChemLib wrote to a standard stream. */
|
|
5
|
+
export type LogHandler = (message: string, stream: LogStream) => void;
|
|
6
|
+
|
|
7
|
+
/** TeaVM imports one character sink per stream; it writes a character at a time. */
|
|
8
|
+
interface TeaVMConsole {
|
|
9
|
+
putcharStdout: (code: number) => void;
|
|
10
|
+
putcharStderr: (code: number) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const NEWLINE = 10;
|
|
14
|
+
|
|
15
|
+
let handler: LogHandler | null = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Routes what OpenChemLib writes to Java's standard streams wherever you want it.
|
|
19
|
+
*
|
|
20
|
+
* Nothing is written anywhere by default, and that is the point: OpenChemLib prints
|
|
21
|
+
* `Tautomer count exceeds maximum: <idcode>` for every molecule whose tautomers it stops
|
|
22
|
+
* enumerating, which an import emits thousands of times, and the generated TeaVM runtime maps that
|
|
23
|
+
* onto `console.log` — the same stream a host writing structured logs is using, whose output it
|
|
24
|
+
* then corrupts. The message says nothing a caller can act on; the hash is still returned and still
|
|
25
|
+
* identifies the molecule. So the default is to drop it, and a host that wants it says where.
|
|
26
|
+
*
|
|
27
|
+
* It applies whether or not the module has been instantiated yet, so it can be set at startup or
|
|
28
|
+
* around one call.
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* setLogHandler((message, stream) => logger.debug({ stream }, message));
|
|
32
|
+
* ```
|
|
33
|
+
* @param next - Called once per line, or `null` to go back to discarding them.
|
|
34
|
+
*/
|
|
35
|
+
export function setLogHandler(next: LogHandler | null): void {
|
|
36
|
+
handler = next;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Builds the `teavmConsole` import that replaces the generated runtime's own, which calls
|
|
41
|
+
* `console.log` and `console.error`.
|
|
42
|
+
* @returns The import object to install over it.
|
|
43
|
+
*/
|
|
44
|
+
export function createConsoleImport(): TeaVMConsole {
|
|
45
|
+
return {
|
|
46
|
+
putcharStdout: lineSink('stdout'),
|
|
47
|
+
putcharStderr: lineSink('stderr'),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Collects characters into a line and hands each finished one to the current handler.
|
|
53
|
+
* @param stream - The stream these characters belong to.
|
|
54
|
+
* @returns The per-character callback the runtime imports.
|
|
55
|
+
*/
|
|
56
|
+
function lineSink(stream: LogStream): (code: number) => void {
|
|
57
|
+
let line = '';
|
|
58
|
+
return (code: number) => {
|
|
59
|
+
if (code === NEWLINE) {
|
|
60
|
+
handler?.(line, stream);
|
|
61
|
+
line = '';
|
|
62
|
+
} else {
|
|
63
|
+
line += String.fromCodePoint(code);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|