hdtrans 0.2.0 → 0.3.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
@@ -19,6 +19,19 @@ try {
19
19
  }
20
20
  ```
21
21
 
22
+ ## Version information
23
+
24
+ ```js
25
+ const info = await HdTrans.getInfo();
26
+ console.log(info.version); // Actual engine build version
27
+ console.log(info.dictionaryVersion); // Loaded base dictionary version
28
+ console.log(info.runtime); // 'wasm'
29
+ ```
30
+
31
+ `HdTrans.getInfo(options)` accepts the same options as `init()`. It loads the engine and dictionary, then closes its temporary translator; it does not just read package metadata. If loading fails, it rejects. Importing the package alone does not load the engine.
32
+
33
+ For an existing translator, `translator.getInfo()` returns the same fields synchronously. The existing `version`, `dictionaryVersion` and `runtime` properties remain available. Instance metadata is captured at initialization and remains readable after `close()`. User dictionary and Ehnd changes do not change the base dictionary version. TypeScript users can import the `HdTransInfo` type.
34
+
22
35
  ## Options and JSON
23
36
 
24
37
  ```js
@@ -1,10 +1,10 @@
1
1
  {
2
- "version": "0.2.0+f5f87488808d",
2
+ "version": "0.3.0+b7c02eeae7ae",
3
3
  "snapshot": {
4
4
  "file": "dicts.hdsnap",
5
- "sha256": "22b4f4f5c1850fa38e8945bc3ce63246b39d5772828e3f011dd73a03c9ef9332",
6
- "builtinFingerprint": "abd7024cf31fb87862a18c1ca7f15e3678c36d9daf893e4d3a2f712b10785dc2",
7
- "dataFingerprint": "bed1d80e02c8755696971fb7b900f101442d750b33e07d90aaa045145d13634d"
5
+ "sha256": "a5195f84542811f32c3d4a8bd06299b362581f9fcf8667afe9c7aa7c15ca23df",
6
+ "builtinFingerprint": "6b14e235d8d87e3a331af888aeab1ce4f08134165267f645f340aa744c201db8",
7
+ "dataFingerprint": "7265d7305c49f8f45bb3ebe5005082c3313802e0c09e970269e9d193449f99f8"
8
8
  },
9
9
  "files": []
10
10
  }
package/dist/dicts.hdsnap CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/dicts.hdsnap
3
- size: 36080311 bytes
4
- sha256: 22b4f4f5c1850fa38e8945bc3ce63246b39d5772828e3f011dd73a03c9ef9332
3
+ size: 36466687 bytes
4
+ sha256: a5195f84542811f32c3d4a8bd06299b362581f9fcf8667afe9c7aa7c15ca23df
package/dist/dicts.txt CHANGED
@@ -1 +1 @@
1
- 0.2.0+f5f87488808d
1
+ 0.3.0+b7c02eeae7ae
Binary file
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { HdTrans as RuntimeHdTrans, type InitOptions as RuntimeInitOptions } from './runtime.js';
2
- export type { UserDictPos, UserDictEntry, ChoiceSelection, TranslationChoice, TranslationResult, EhndFiles, } from './runtime.js';
1
+ import { HdTrans as RuntimeHdTrans, type HdTransInfo, type InitOptions as RuntimeInitOptions } from './runtime.js';
2
+ export type { UserDictPos, UserDictEntry, ChoiceSelection, TranslationChoice, TranslationResult, EhndFiles, HdTransInfo, } from './runtime.js';
3
3
  export type InitOptions = Pick<RuntimeInitOptions, 'ehnd'>;
4
4
  export type HdTrans = RuntimeHdTrans;
5
5
  /** Uses the bundled engine and dictionary. Each call returns an independent translator. */
6
6
  export declare const HdTrans: Readonly<{
7
+ /** Loads the bundled engine and dictionary, reads their metadata, then closes the temporary translator. */
8
+ getInfo(options?: InitOptions): Promise<HdTransInfo>;
7
9
  init(options?: InitOptions): Promise<HdTrans>;
8
10
  }>;
package/dist/index.js CHANGED
@@ -12,6 +12,16 @@ async function loadModule() {
12
12
  }
13
13
  /** Uses the bundled engine and dictionary. Each call returns an independent translator. */
14
14
  export const HdTrans = Object.freeze({
15
+ /** Loads the bundled engine and dictionary, reads their metadata, then closes the temporary translator. */
16
+ async getInfo(options = {}) {
17
+ const translator = await HdTrans.init(options);
18
+ try {
19
+ return translator.getInfo();
20
+ }
21
+ finally {
22
+ translator.close();
23
+ }
24
+ },
15
25
  async init(options = {}) {
16
26
  modulePromise ??= loadModule().catch((error) => {
17
27
  modulePromise = undefined;
package/dist/runtime.d.ts CHANGED
@@ -13,7 +13,8 @@ export interface ChoiceSelection {
13
13
  provenance: string;
14
14
  layer: string;
15
15
  id: number;
16
- /** Rule filename:line, sense table:row, or empty when no source is recorded. */
16
+ /** Local rule number, global rule file:line, sense table:row, or empty when no
17
+ * source is recorded. */
17
18
  source: string;
18
19
  }
19
20
  export interface TranslationChoice {
@@ -58,6 +59,11 @@ export interface WasmModule {
58
59
  Translator: new () => Binding;
59
60
  version(): string;
60
61
  }
62
+ export interface HdTransInfo {
63
+ readonly version: string;
64
+ readonly dictionaryVersion: string;
65
+ readonly runtime: 'wasm';
66
+ }
61
67
  export interface InitOptions {
62
68
  /** Supply an instantiated module with its dictionary files already staged. */
63
69
  module?: WasmModule | Promise<WasmModule>;
@@ -73,6 +79,10 @@ export declare class HdTrans {
73
79
  private userDictRaw_;
74
80
  private constructor();
75
81
  static init(options?: InitOptions): Promise<HdTrans>;
82
+ /** Loads the engine and dictionaries, reads their metadata, then closes the temporary translator. */
83
+ static getInfo(options?: InitOptions): Promise<HdTransInfo>;
84
+ /** Metadata captured at initialization, also available after close(). */
85
+ getInfo(): HdTransInfo;
76
86
  translate(text: string): string;
77
87
  translate(text: string, options: {
78
88
  json: true;
package/dist/runtime.js CHANGED
@@ -35,6 +35,24 @@ export class HdTrans {
35
35
  throw error;
36
36
  }
37
37
  }
38
+ /** Loads the engine and dictionaries, reads their metadata, then closes the temporary translator. */
39
+ static async getInfo(options = {}) {
40
+ const translator = await HdTrans.init(options);
41
+ try {
42
+ return translator.getInfo();
43
+ }
44
+ finally {
45
+ translator.close();
46
+ }
47
+ }
48
+ /** Metadata captured at initialization, also available after close(). */
49
+ getInfo() {
50
+ return {
51
+ version: this.version,
52
+ dictionaryVersion: this.dictionaryVersion,
53
+ runtime: this.runtime,
54
+ };
55
+ }
38
56
  translate(text, options = {}) {
39
57
  const binding = this.binding();
40
58
  if (typeof text !== 'string')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdtrans",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Japanese to Korean translation with a bundled WebAssembly engine and dictionary",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",