nodejs: lazy per-backend libsimplex download (#7543)

* ci: drop dlltool from nodejs libs release

* nodejs: download libsimplex into the user cache

* nodejs: load libsimplex at runtime per backend

* support bot: select db backend with --db

* python: match backend switch error text

* nodejs: download prebuilt add-on at runtime

* ci: build nodejs add-on for libs release

* calculator bot: load libs and add-on in image

* support bot: document add-on override

* nodejs: keep worker test output free of colors

* nodejs: verify sha-256 of downloaded assets

* python: pin core libs release with sha-256

* ci: add packages release script

* ci: release nodejs add-on and open release PR

* ci: publish packages after release PR

* nodejs: keep npm from building the add-on

* calculator bot: build the add-on in the image

* ci: merge package release workflows

* ci: open release PR when publishing fails

* ci: build the add-on with node-addon-api only

* ci: skip publishing in a called packages workflow

* ci: update package release actions to Node 24

* nodejs: fix receive test timeout

* ci: test packages on pull requests

* nodejs: reuse the database in the close stress test

* ci: keep failed package tests from hanging

* ci: skip preset server tests

* ci: plan package builds from the changes

* ci: test packages with a given libsimplex

* ci: test packages with libsimplex of core changes
This commit is contained in:
sh authored and GitHub committed 2026-10-14 09:53:53 +01:00
1 parent 2f4a443dda
commit f65c2da587
73 files changed
+2823 -650

No files matched your search

+22
View File
@@ -1,6 +1,28 @@
import {ChatEvent, ChatResponse, T} from "@simplex-chat/types"
import * as libs from "./libs"
import * as simplex from "./simplex"
export type Backend = "sqlite" | "postgres"
let loading: {backend: Backend, promise: Promise<void>} | undefined
/**
* Resolve (downloading on first use) and load libsimplex for the backend.
* One libsimplex per process: the Haskell runtime is initialized once, and another backend is rejected.
*/
export function loadLibrary(backend: Backend): Promise<void> {
if (loading) {
if (loading.backend === backend) return loading.promise
return Promise.reject(new Error(`libsimplex already loaded with backend=${loading.backend}; cannot switch to ${backend} in the same process`))
}
const promise = Promise.all([libs.resolveLibsDir(backend), libs.resolveAddonPath()])
.then(([dir, addon]) => simplex.load(addon, libs.libPath(dir)))
loading = {backend, promise}
// a failed download or load can be retried
promise.catch(() => { loading = undefined })
return promise
}
/**
* Initialize chat controller
* @param {number} [queueSize] - Size of internal queues, the core default is used when omitted.