2023-12-06 11:03:05 +03:00
|
|
|
// prettier-ignore
|
2023-03-27 09:59:36 +03:00
|
|
|
/* eslint-disable */
|
|
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
|
|
|
|
const { existsSync, readFileSync } = require('fs')
|
2023-10-19 10:17:04 +03:00
|
|
|
const { join } = require('path')
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-10-19 10:17:04 +03:00
|
|
|
const { platform, arch } = process
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-10-19 10:17:04 +03:00
|
|
|
let nativeBinding = null
|
|
|
|
let localFileExisted = false
|
|
|
|
let loadError = null
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
const isMusl = () => {
|
|
|
|
let musl = false
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
musl = isMuslFromFilesystem()
|
|
|
|
if (musl === null) {
|
|
|
|
musl = isMuslFromReport()
|
|
|
|
}
|
|
|
|
if (musl === null) {
|
|
|
|
musl = isMuslFromChildProcess()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return musl
|
|
|
|
}
|
|
|
|
|
|
|
|
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
|
|
|
|
|
|
const isMuslFromFilesystem = () => {
|
|
|
|
try {
|
|
|
|
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
|
|
} catch {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const isMuslFromReport = () => {
|
|
|
|
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
|
|
|
|
if (!report) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (Array.isArray(report.sharedObjects)) {
|
|
|
|
if (report.sharedObjects.some(isFileMusl)) {
|
2023-10-19 10:17:04 +03:00
|
|
|
return true
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-12-06 11:03:05 +03:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
const isMuslFromChildProcess = () => {
|
|
|
|
try {
|
|
|
|
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
|
|
} catch (e) {
|
|
|
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
|
|
return false
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (platform) {
|
|
|
|
case 'android':
|
|
|
|
switch (arch) {
|
|
|
|
case 'arm64':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.android-arm64.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.android-arm64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-android-arm64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.android-arm-eabi.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.android-arm-eabi.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-android-arm-eabi')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2024-03-12 13:00:09 +03:00
|
|
|
loadError = new Error(`Unsupported architecture on Android ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'win32':
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-x64-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-x64-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-x64-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'ia32':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-ia32-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-ia32-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-ia32-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.win32-arm64-msvc.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.win32-arm64-msvc.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-win32-arm64-msvc')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2024-03-12 13:00:09 +03:00
|
|
|
loadError = new Error(`Unsupported architecture on Windows: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'darwin':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.darwin-universal.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-universal.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-universal')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
} catch {}
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
2023-10-19 10:17:04 +03:00
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.darwin-x64.node'))
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-x64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-x64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.darwin-arm64.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.darwin-arm64.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-darwin-arm64')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2024-03-12 13:00:09 +03:00
|
|
|
loadError = new Error(`Unsupported architecture on macOS: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'freebsd':
|
2024-03-12 13:00:09 +03:00
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.freebsd-x64.node'))
|
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
|
|
|
nativeBinding = require('./affine.freebsd-x64.node')
|
|
|
|
} else {
|
|
|
|
nativeBinding = require('@affine/native-freebsd-x64')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
loadError = e
|
|
|
|
}
|
|
|
|
break
|
|
|
|
case 'arm64':
|
|
|
|
localFileExisted = existsSync(join(__dirname, 'affine.freebsd-arm64.node'))
|
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
|
|
|
nativeBinding = require('./affine.freebsd-arm64.node')
|
|
|
|
} else {
|
|
|
|
nativeBinding = require('@affine/native-freebsd-arm64')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
loadError = e
|
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
loadError = new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'linux':
|
|
|
|
switch (arch) {
|
|
|
|
case 'x64':
|
|
|
|
if (isMusl()) {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-x64-musl.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-x64-musl.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-x64-musl')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-x64-gnu.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-x64-gnu.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-x64-gnu')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm64':
|
|
|
|
if (isMusl()) {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm64-musl.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm64-musl.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm64-musl')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm64-gnu.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm64-gnu.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm64-gnu')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
case 'arm':
|
|
|
|
localFileExisted = existsSync(
|
2023-05-10 12:16:48 +03:00
|
|
|
join(__dirname, 'affine.linux-arm-gnueabihf.node')
|
2023-10-19 10:17:04 +03:00
|
|
|
)
|
2023-03-27 09:59:36 +03:00
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('./affine.linux-arm-gnueabihf.node')
|
2023-03-27 09:59:36 +03:00
|
|
|
} else {
|
2023-10-19 10:17:04 +03:00
|
|
|
nativeBinding = require('@affine/native-linux-arm-gnueabihf')
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2023-10-19 10:17:04 +03:00
|
|
|
loadError = e
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2024-01-05 10:23:22 +03:00
|
|
|
case 'riscv64':
|
|
|
|
if (isMusl()) {
|
|
|
|
localFileExisted = existsSync(
|
|
|
|
join(__dirname, 'affine.linux-riscv64-musl.node')
|
|
|
|
)
|
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
|
|
|
nativeBinding = require('./affine.linux-riscv64-musl.node')
|
|
|
|
} else {
|
|
|
|
nativeBinding = require('@affine/native-linux-riscv64-musl')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
loadError = e
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
localFileExisted = existsSync(
|
|
|
|
join(__dirname, 'affine.linux-riscv64-gnu.node')
|
|
|
|
)
|
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
|
|
|
nativeBinding = require('./affine.linux-riscv64-gnu.node')
|
|
|
|
} else {
|
|
|
|
nativeBinding = require('@affine/native-linux-riscv64-gnu')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
loadError = e
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break
|
2024-03-12 13:00:09 +03:00
|
|
|
case 's390x':
|
|
|
|
localFileExisted = existsSync(
|
|
|
|
join(__dirname, 'affine.linux-s390x-gnu.node')
|
|
|
|
)
|
|
|
|
try {
|
|
|
|
if (localFileExisted) {
|
|
|
|
nativeBinding = require('./affine.linux-s390x-gnu.node')
|
|
|
|
} else {
|
|
|
|
nativeBinding = require('@affine/native-linux-s390x-gnu')
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
loadError = e
|
|
|
|
}
|
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2024-03-12 13:00:09 +03:00
|
|
|
loadError = new Error(`Unsupported architecture on Linux: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
break
|
2023-03-27 09:59:36 +03:00
|
|
|
default:
|
2024-03-12 13:00:09 +03:00
|
|
|
loadError = new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
|
2024-01-05 10:23:22 +03:00
|
|
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
|
|
try {
|
|
|
|
nativeBinding = require('./affine.wasi.cjs')
|
2024-03-12 13:00:09 +03:00
|
|
|
} catch (err) {
|
|
|
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2024-01-05 10:23:22 +03:00
|
|
|
}
|
|
|
|
if (!nativeBinding) {
|
|
|
|
try {
|
|
|
|
nativeBinding = require('@affine/native-wasm32-wasi')
|
|
|
|
} catch (err) {
|
2024-03-12 13:00:09 +03:00
|
|
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2024-01-05 10:23:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-27 09:59:36 +03:00
|
|
|
if (!nativeBinding) {
|
|
|
|
if (loadError) {
|
2023-10-19 10:17:04 +03:00
|
|
|
throw loadError
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
2023-10-19 10:17:04 +03:00
|
|
|
throw new Error(`Failed to load native binding`)
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
module.exports.SqliteConnection = nativeBinding.SqliteConnection
|
|
|
|
module.exports.mintChallengeResponse = nativeBinding.mintChallengeResponse
|
|
|
|
module.exports.ValidationResult = nativeBinding.ValidationResult
|
|
|
|
module.exports.verifyChallengeResponse = nativeBinding.verifyChallengeResponse
|