mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 17:03:32 +03:00
8edf49343f
fixes #9730 Added a `logEvent` method to remote backend implementation in dashboard. Added an always-present remote backend instance that can be used for logging even when running a local project (intentional behavior). # Important Notes Because the backend implementation requires access to always fresh session token, the logger needs to be periodically updated on GUI side, so it can continue to function. To accomplish that, I simplified the app loading logic to treat GUI as an ordinary react component, so its props can be updated with normal react rendering flow. That refactor also removed the dynamic GUI asset loading code that was only needed for Rust GUI.
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
/**
|
|
* @file Provides the Rust ffi interface. The interface should be kept in sync with polyglot ffi inteface {@link module:ffiPolyglot}.
|
|
*
|
|
* @module ffi
|
|
*/
|
|
|
|
import { createXXHash128 } from 'hash-wasm'
|
|
import type { IDataType } from 'hash-wasm/dist/lib/util'
|
|
import init, { is_ident_or_operator, parse, parse_doc_to_json } from '../../rust-ffi/pkg/rust_ffi'
|
|
import { assertDefined } from '../util/assert'
|
|
import { isNode } from '../util/detect'
|
|
|
|
let xxHasher128: Awaited<ReturnType<typeof createXXHash128>> | undefined
|
|
export function xxHash128(input: IDataType) {
|
|
assertDefined(xxHasher128, 'Module should have been loaded with `initializeFFI`.')
|
|
xxHasher128.init()
|
|
xxHasher128.update(input)
|
|
return xxHasher128.digest()
|
|
}
|
|
|
|
export async function initializeFFI(path?: string | undefined) {
|
|
if (xxHasher128 != null) return
|
|
if (isNode) {
|
|
const fs = await import('node:fs/promises')
|
|
const { fileURLToPath, URL: nodeURL } = await import('node:url')
|
|
const buffer = fs.readFile(
|
|
path ?? fileURLToPath(new nodeURL('../../rust-ffi/pkg/rust_ffi_bg.wasm', import.meta.url)),
|
|
)
|
|
await init(buffer)
|
|
} else {
|
|
await init()
|
|
}
|
|
xxHasher128 = await createXXHash128()
|
|
}
|
|
|
|
// TODO[ao]: We cannot to that, because the ffi is used by cjs modules.
|
|
// await initializeFFI()
|
|
|
|
/* eslint-disable-next-line camelcase */
|
|
export { is_ident_or_operator, parse_doc_to_json, parse as parse_tree }
|