@helios-lang/contract-utils 0.1.0 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/hl2ts.js CHANGED
@@ -1,9 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { loadLibrary } from "./lib/index.js"
4
+
3
5
  async function main() {
4
6
  console.log("hl2ts")
5
7
 
6
- console.log(eval(`import("@hyperionbt/helios")`))
8
+ const lib = await loadLibrary()
9
+
10
+ console.log(lib.version)
7
11
  }
8
12
 
9
13
  main()
package/src/lib/Lib.js ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @typedef {{
3
+ * version: string
4
+ * }} Lib
5
+ */
6
+
7
+ /**
8
+ * @param {{VERSION: string}} lib
9
+ * @returns {number[]}
10
+ */
11
+ export function getVersion(lib) {
12
+ return lib.VERSION.split(".").map(v => Number(v))
13
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @typedef {import("./Lib.js").Lib} Lib
3
+ */
4
+
5
+ /**
6
+ * @implements {Lib}
7
+ */
8
+ export class Lib_v0_16 {
9
+ /**
10
+ * @param {any} lib
11
+ */
12
+ constructor(lib) {
13
+ this.lib = lib
14
+ }
15
+
16
+ /**
17
+ * @type {string}
18
+ */
19
+ get version() {
20
+ return this.lib.VERSION
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ export { loadLibrary } from "./load.js"
@@ -0,0 +1,37 @@
1
+ import { getVersion } from "./Lib.js"
2
+ import { Lib_v0_16 } from "./Libg_v0_16.js"
3
+
4
+ /**
5
+ * @typedef {import("./Lib.js").Lib} Lib
6
+ */
7
+
8
+ const packageNames = [
9
+ "@hyperionbt/helios"
10
+ ]
11
+
12
+ /**
13
+ * @returns {Promise<Lib>}
14
+ */
15
+ export async function loadLibrary() {
16
+ for (let packageName of packageNames) {
17
+ try {
18
+ const lib = await eval(`import("${packageName}")`)
19
+
20
+ const [major, minor] = getVersion(lib)
21
+
22
+ switch(major) {
23
+ case 0:
24
+ switch (minor) {
25
+ case 16:
26
+ return new Lib_v0_16(lib)
27
+ }
28
+ default:
29
+ throw new Error(`compiler version ${lib.VERSION} not supported`)
30
+ }
31
+ } catch(_e) {
32
+ continue
33
+ }
34
+ }
35
+
36
+ throw new Error("compiler not installed")
37
+ }