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.
Files changed (59) hide show
  1. package/README.md +290 -3
  2. package/lib/functionKeys/dictionary.json +72071 -0
  3. package/lib/functionKeys/index.d.ts +105 -0
  4. package/lib/functionKeys/index.d.ts.map +1 -0
  5. package/lib/functionKeys/index.js +98 -0
  6. package/lib/functionKeys/index.js.map +1 -0
  7. package/lib/functions.d.ts +38 -0
  8. package/lib/functions.d.ts.map +1 -0
  9. package/lib/functions.js +54 -0
  10. package/lib/functions.js.map +1 -0
  11. package/lib/hex.d.ts +31 -0
  12. package/lib/hex.d.ts.map +1 -0
  13. package/lib/hex.js +41 -0
  14. package/lib/hex.js.map +1 -0
  15. package/lib/index.d.ts +140 -2
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +184 -7
  18. package/lib/index.js.map +1 -1
  19. package/lib/records.d.ts +45 -0
  20. package/lib/records.d.ts.map +1 -0
  21. package/lib/records.js +96 -0
  22. package/lib/records.js.map +1 -0
  23. package/lib/scan.d.ts +99 -7
  24. package/lib/scan.d.ts.map +1 -1
  25. package/lib/scan.js +158 -11
  26. package/lib/scan.js.map +1 -1
  27. package/lib/strongHash.d.ts +9 -0
  28. package/lib/strongHash.d.ts.map +1 -0
  29. package/lib/strongHash.js +56 -0
  30. package/lib/strongHash.js.map +1 -0
  31. package/lib/substructureSearch.d.ts +8 -5
  32. package/lib/substructureSearch.d.ts.map +1 -1
  33. package/lib/substructureSearch.js +28 -5
  34. package/lib/substructureSearch.js.map +1 -1
  35. package/lib/types.d.ts +120 -3
  36. package/lib/types.d.ts.map +1 -1
  37. package/lib/types.js +17 -1
  38. package/lib/types.js.map +1 -1
  39. package/lib/wasm/load.d.ts.map +1 -1
  40. package/lib/wasm/load.js +9 -1
  41. package/lib/wasm/load.js.map +1 -1
  42. package/lib/wasm/log.d.ts +36 -0
  43. package/lib/wasm/log.d.ts.map +1 -0
  44. package/lib/wasm/log.js +52 -0
  45. package/lib/wasm/log.js.map +1 -0
  46. package/package.json +6 -3
  47. package/src/functionKeys/index.ts +181 -0
  48. package/src/functions.ts +56 -0
  49. package/src/hex.ts +43 -0
  50. package/src/index.ts +269 -5
  51. package/src/records.ts +142 -0
  52. package/src/scan.ts +259 -16
  53. package/src/strongHash.ts +57 -0
  54. package/src/substructureSearch.ts +29 -6
  55. package/src/types.ts +171 -2
  56. package/src/wasm/load.ts +10 -1
  57. package/src/wasm/log.ts +66 -0
  58. package/wasm/data.js +1 -1
  59. package/wasm/runtime.d.ts +6 -0
@@ -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
+ }