@codonsplice/wasm 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/astro/index.js +6 -0
- package/astro/package.json +8 -0
- package/codonsplice_wasm_bg.wasm +0 -0
- package/index.js +72 -0
- package/package.json +28 -9
- package/react/index.js +26 -0
- package/react/package.json +9 -0
- package/svelte/index.js +26 -0
- package/svelte/package.json +9 -0
- package/vue/index.js +25 -0
- package/vue/package.json +9 -0
package/astro/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @codonsplice/astro — framework-agnostic helpers for Astro islands.
|
|
2
|
+
//
|
|
3
|
+
// Astro components are framework-agnostic, so this simply re-exports the core
|
|
4
|
+
// helpers; use them inside a client:* island (or any of the framework wrappers
|
|
5
|
+
// for reactive state).
|
|
6
|
+
export { execute, stream, compile, check, initEngine, CodonSplice } from '../index.js'
|
package/codonsplice_wasm_bg.wasm
CHANGED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// @codonsplice/wasm — ergonomic entry point over the wasm-bindgen bindings.
|
|
2
|
+
//
|
|
3
|
+
// `codonsplice_wasm.js` (the wasm-pack output) exports the raw `CodonSplice`
|
|
4
|
+
// class and a default `init()` that loads the .wasm. This module wraps them in
|
|
5
|
+
// a singleton engine plus `execute`/`stream` helpers that accept File /
|
|
6
|
+
// ArrayBuffer / Uint8Array values and normalize them to the Uint8Array map the
|
|
7
|
+
// engine expects.
|
|
8
|
+
|
|
9
|
+
import init, { CodonSplice } from './codonsplice_wasm.js'
|
|
10
|
+
|
|
11
|
+
let _engine = null
|
|
12
|
+
|
|
13
|
+
/** Initialize (once) and return the shared engine. */
|
|
14
|
+
export async function initEngine() {
|
|
15
|
+
if (_engine) return _engine
|
|
16
|
+
await init()
|
|
17
|
+
_engine = new CodonSplice()
|
|
18
|
+
return _engine
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { CodonSplice }
|
|
22
|
+
|
|
23
|
+
async function normalizeFiles(files) {
|
|
24
|
+
const fileMap = {}
|
|
25
|
+
for (const [name, fileOrBuffer] of Object.entries(files || {})) {
|
|
26
|
+
if (typeof File !== 'undefined' && fileOrBuffer instanceof File) {
|
|
27
|
+
fileMap[name] = new Uint8Array(await fileOrBuffer.arrayBuffer())
|
|
28
|
+
} else if (fileOrBuffer instanceof ArrayBuffer) {
|
|
29
|
+
fileMap[name] = new Uint8Array(fileOrBuffer)
|
|
30
|
+
} else {
|
|
31
|
+
fileMap[name] = fileOrBuffer // assume Uint8Array
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return fileMap
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Execute a query and return the result (array of records/rows, or { text }). */
|
|
38
|
+
export async function execute({ query, files, vars }) {
|
|
39
|
+
const engine = await initEngine()
|
|
40
|
+
return engine.execute(query, await normalizeFiles(files), vars || {})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Execute pre-compiled .spq.bc bytecode (Uint8Array) against files + vars. */
|
|
44
|
+
export async function executeBytecode({ bytecode, files, vars }) {
|
|
45
|
+
const engine = await initEngine()
|
|
46
|
+
return engine.execute_bytecode(bytecode, await normalizeFiles(files), vars || {})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Stream a query's records: onRecord per row, onDone at end, onError on fail. */
|
|
50
|
+
export async function stream({ query, files, vars, onRecord, onDone, onError }) {
|
|
51
|
+
const engine = await initEngine()
|
|
52
|
+
return engine.stream(
|
|
53
|
+
query,
|
|
54
|
+
await normalizeFiles(files),
|
|
55
|
+
vars || {},
|
|
56
|
+
onRecord || (() => {}),
|
|
57
|
+
onDone || (() => {}),
|
|
58
|
+
onError || ((e) => console.error(e)),
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Compile a query to disassembled bytecode (throws on error). */
|
|
63
|
+
export async function compile(query) {
|
|
64
|
+
const engine = await initEngine()
|
|
65
|
+
return engine.compile(query)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Type-check a query: returns null on success, an error string on failure. */
|
|
69
|
+
export async function check(query) {
|
|
70
|
+
const engine = await initEngine()
|
|
71
|
+
return engine.check(query)
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codonsplice/wasm",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "CodonSplice — run SpliceQL genomic queries (BAM/VCF) in the browser via WASM",
|
|
3
5
|
"type": "module",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
6
|
+
"main": "codonsplice_wasm.js",
|
|
7
|
+
"module": "codonsplice_wasm.js",
|
|
8
|
+
"types": "codonsplice_wasm.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./codonsplice_wasm.d.ts",
|
|
12
|
+
"import": "./codonsplice_wasm.js"
|
|
13
|
+
},
|
|
14
|
+
"./helpers": "./index.js",
|
|
15
|
+
"./react": "./react/index.js",
|
|
16
|
+
"./vue": "./vue/index.js",
|
|
17
|
+
"./svelte": "./svelte/index.js",
|
|
18
|
+
"./astro": "./astro/index.js"
|
|
19
|
+
},
|
|
7
20
|
"files": [
|
|
8
21
|
"codonsplice_wasm_bg.wasm",
|
|
9
22
|
"codonsplice_wasm.js",
|
|
10
|
-
"codonsplice_wasm.d.ts"
|
|
23
|
+
"codonsplice_wasm.d.ts",
|
|
24
|
+
"index.js",
|
|
25
|
+
"react/",
|
|
26
|
+
"vue/",
|
|
27
|
+
"svelte/",
|
|
28
|
+
"astro/"
|
|
11
29
|
],
|
|
12
|
-
"main": "codonsplice_wasm.js",
|
|
13
|
-
"types": "codonsplice_wasm.d.ts",
|
|
14
30
|
"sideEffects": [
|
|
15
|
-
"./
|
|
16
|
-
]
|
|
17
|
-
|
|
31
|
+
"./codonsplice_wasm.js"
|
|
32
|
+
],
|
|
33
|
+
"keywords": ["genomics", "bioinformatics", "spliceql", "bam", "vcf", "wasm", "cnv", "variant-calling"],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": "github:Pogo-Bash/codonsplice"
|
|
36
|
+
}
|
package/react/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @codonsplice/react — a useSpliceQL() hook over @codonsplice/wasm.
|
|
2
|
+
import { useState, useCallback } from 'react'
|
|
3
|
+
import { execute as csExecute } from '../index.js'
|
|
4
|
+
|
|
5
|
+
export function useSpliceQL() {
|
|
6
|
+
const [result, setResult] = useState(null)
|
|
7
|
+
const [error, setError] = useState(null)
|
|
8
|
+
const [loading, setLoading] = useState(false)
|
|
9
|
+
|
|
10
|
+
const execute = useCallback(async ({ query, files, vars }) => {
|
|
11
|
+
setLoading(true)
|
|
12
|
+
setError(null)
|
|
13
|
+
try {
|
|
14
|
+
const r = await csExecute({ query, files, vars })
|
|
15
|
+
setResult(r)
|
|
16
|
+
return r
|
|
17
|
+
} catch (e) {
|
|
18
|
+
setError(e)
|
|
19
|
+
throw e
|
|
20
|
+
} finally {
|
|
21
|
+
setLoading(false)
|
|
22
|
+
}
|
|
23
|
+
}, [])
|
|
24
|
+
|
|
25
|
+
return { execute, result, error, loading }
|
|
26
|
+
}
|
package/svelte/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @codonsplice/svelte — a createSpliceQL() store factory over @codonsplice/wasm.
|
|
2
|
+
import { writable } from 'svelte/store'
|
|
3
|
+
import { execute as csExecute } from '../index.js'
|
|
4
|
+
|
|
5
|
+
export function createSpliceQL() {
|
|
6
|
+
const result = writable(null)
|
|
7
|
+
const error = writable(null)
|
|
8
|
+
const loading = writable(false)
|
|
9
|
+
|
|
10
|
+
async function execute({ query, files, vars }) {
|
|
11
|
+
loading.set(true)
|
|
12
|
+
error.set(null)
|
|
13
|
+
try {
|
|
14
|
+
const r = await csExecute({ query, files, vars })
|
|
15
|
+
result.set(r)
|
|
16
|
+
return r
|
|
17
|
+
} catch (e) {
|
|
18
|
+
error.set(e)
|
|
19
|
+
throw e
|
|
20
|
+
} finally {
|
|
21
|
+
loading.set(false)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { execute, result, error, loading }
|
|
26
|
+
}
|
package/vue/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @codonsplice/vue — a useSpliceQL() composable over @codonsplice/wasm.
|
|
2
|
+
import { ref } from 'vue'
|
|
3
|
+
import { execute as csExecute } from '../index.js'
|
|
4
|
+
|
|
5
|
+
export function useSpliceQL() {
|
|
6
|
+
const result = ref(null)
|
|
7
|
+
const error = ref(null)
|
|
8
|
+
const loading = ref(false)
|
|
9
|
+
|
|
10
|
+
async function execute({ query, files, vars }) {
|
|
11
|
+
loading.value = true
|
|
12
|
+
error.value = null
|
|
13
|
+
try {
|
|
14
|
+
result.value = await csExecute({ query, files, vars })
|
|
15
|
+
return result.value
|
|
16
|
+
} catch (e) {
|
|
17
|
+
error.value = e
|
|
18
|
+
throw e
|
|
19
|
+
} finally {
|
|
20
|
+
loading.value = false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { execute, result, error, loading }
|
|
25
|
+
}
|