diff --git a/.eslintignore b/.eslintignore index 26d3c577..a5949831 100644 --- a/.eslintignore +++ b/.eslintignore @@ -15,6 +15,7 @@ scripts triples/index.js rollup.config.js crates/cli/index.js +examples/napi/index.d.* examples/napi/index.wasi.mjs examples/napi/index.wasi-browser.js examples/napi/wasi-worker.mjs diff --git a/.github/workflows/test-release.yaml b/.github/workflows/test-release.yaml index 3179b83b..8695e35c 100644 --- a/.github/workflows/test-release.yaml +++ b/.github/workflows/test-release.yaml @@ -30,7 +30,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install @@ -163,7 +163,7 @@ jobs: uses: actions/setup-node@v4 if: matrix.settings.target == 'i686-pc-windows-msvc' with: - node-version: 18 + node-version: 20 architecture: 'x86' - name: Unit tests @@ -209,7 +209,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install @@ -264,7 +264,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install dependencies @@ -295,7 +295,7 @@ jobs: - uses: actions/upload-artifact@v4 with: name: ${{ matrix.settings.target }}-example - path: examples/napi/index.node + path: examples/napi/*.node - uses: actions/upload-artifact@v4 with: name: ${{ matrix.settings.target }}-example-compat @@ -336,12 +336,12 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - uses: actions/download-artifact@v4 with: name: ${{ matrix.settings.target }}-example - path: examples/napi/index.node + path: examples/napi/ - uses: actions/download-artifact@v4 with: name: ${{ matrix.settings.target }}-example-compat @@ -385,7 +385,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install @@ -429,7 +429,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install @@ -528,7 +528,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Install uses: dtolnay/rust-toolchain@stable @@ -563,7 +563,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 cache: 'yarn' - name: Publish run: | diff --git a/.github/workflows/zig.yaml b/.github/workflows/zig.yaml index 4937b3f1..69af356a 100644 --- a/.github/workflows/zig.yaml +++ b/.github/workflows/zig.yaml @@ -76,7 +76,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: napi-${{ matrix.target }} - path: ./examples/napi/index.node + path: ./examples/napi/*.node if-no-files-found: error test: diff --git a/cli/src/api/templates/js-binding.ts b/cli/src/api/templates/js-binding.ts index 665e917b..4517df8a 100644 --- a/cli/src/api/templates/js-binding.ts +++ b/cli/src/api/templates/js-binding.ts @@ -3,6 +3,20 @@ export function createCjsBinding( pkgName: string, idents: string[], ): string { + function requireTuple(tuple: string) { + return `try { + return require('./${localName}.${tuple}.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('${pkgName}-${tuple}') + } catch (e) { + loadErrors.push(e) + } +` + } + return `// prettier-ignore /* eslint-disable */ /* auto-generated by NAPI-RS */ @@ -10,11 +24,9 @@ export function createCjsBinding( const { existsSync, readFileSync } = require('fs') const { join } = require('path') -const { platform, arch } = process - let nativeBinding = null let localFileExisted = false -let loadError = null +let loadErrors = [] const isMusl = () => { let musl = false @@ -65,281 +77,75 @@ const isMuslFromChildProcess = () => { } } -switch (platform) { - case 'android': - switch (arch) { - case 'arm64': - localFileExisted = existsSync(join(__dirname, '${localName}.android-arm64.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.android-arm64.node') - } else { - nativeBinding = require('${pkgName}-android-arm64') - } - } catch (e) { - loadError = e - } - break - case 'arm': - localFileExisted = existsSync(join(__dirname, '${localName}.android-arm-eabi.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.android-arm-eabi.node') - } else { - nativeBinding = require('${pkgName}-android-arm-eabi') - } - } catch (e) { - loadError = e - } - break - default: - loadError = new Error(\`Unsupported architecture on Android \${arch}\`) +function requireNative() { + if (process.platform === 'android') { + if (process.arch === 'arm64') { + ${requireTuple('android-arm64')} + } else if (process.arch === 'arm') { + ${requireTuple('android-arm-eabi')} + } else { + loadErrors.push(new Error(\`Unsupported architecture on Android \${process.arch}\`)) } - break - case 'win32': - switch (arch) { - case 'x64': - localFileExisted = existsSync( - join(__dirname, '${localName}.win32-x64-msvc.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.win32-x64-msvc.node') - } else { - nativeBinding = require('${pkgName}-win32-x64-msvc') - } - } catch (e) { - loadError = e - } - break - case 'ia32': - localFileExisted = existsSync( - join(__dirname, '${localName}.win32-ia32-msvc.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.win32-ia32-msvc.node') - } else { - nativeBinding = require('${pkgName}-win32-ia32-msvc') - } - } catch (e) { - loadError = e - } - break - case 'arm64': - localFileExisted = existsSync( - join(__dirname, '${localName}.win32-arm64-msvc.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.win32-arm64-msvc.node') - } else { - nativeBinding = require('${pkgName}-win32-arm64-msvc') - } - } catch (e) { - loadError = e - } - break - default: - loadError = new Error(\`Unsupported architecture on Windows: \${arch}\`) + } else if (process.platform === 'win32') { + if (process.arch === 'x64') { + ${requireTuple('win32-x64-msvc')} + } else if (process.arch === 'ia32') { + ${requireTuple('win32-ia32-msvc')} + } else if (process.arch === 'arm64') { + ${requireTuple('win32-arm64-msvc')} + } else { + loadErrors.push(new Error(\`Unsupported architecture on Windows: \${process.arch}\`)) } - break - case 'darwin': - localFileExisted = existsSync(join(__dirname, '${localName}.darwin-universal.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.darwin-universal.node') + } else if (process.platform === 'darwin') { + ${requireTuple('darwin-universal')} + if (process.arch === 'x64') { + ${requireTuple('darwin-x64')} + } else if (process.arch === 'arm64') { + ${requireTuple('darwin-arm64')} + } else { + loadErrors.push(new Error(\`Unsupported architecture on macOS: \${process.arch}\`)) + } + } else if (process.platform === 'freebsd') { + if (process.arch === 'x64') { + ${requireTuple('freebsd-x64')} + } else if (process.arch === 'arm64') { + ${requireTuple('freebsd-arm64')} + } else { + loadErrors.push(new Error(\`Unsupported architecture on FreeBSD: \${process.arch}\`)) + } + } else if (process.platform === 'linux') { + if (process.arch === 'x64') { + if (isMusl()) { + ${requireTuple('linux-x64-musl')} } else { - nativeBinding = require('${pkgName}-darwin-universal') + ${requireTuple('linux-x64-gnu')} } - break - } catch {} - switch (arch) { - case 'x64': - localFileExisted = existsSync(join(__dirname, '${localName}.darwin-x64.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.darwin-x64.node') - } else { - nativeBinding = require('${pkgName}-darwin-x64') - } - } catch (e) { - loadError = e - } - break - case 'arm64': - localFileExisted = existsSync( - join(__dirname, '${localName}.darwin-arm64.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.darwin-arm64.node') - } else { - nativeBinding = require('${pkgName}-darwin-arm64') - } - } catch (e) { - loadError = e - } - break - default: - loadError = new Error(\`Unsupported architecture on macOS: \${arch}\`) + } else if (process.arch === 'arm64') { + if (isMusl()) { + ${requireTuple('linux-arm64-musl')} + } else { + ${requireTuple('linux-arm64-gnu')} + } + } else if (process.arch === 'arm') { + ${requireTuple('linux-arm-gnueabihf')} + } else if (process.arch === 'riscv64') { + if (isMusl()) { + ${requireTuple('linux-riscv64-musl')} + } else { + ${requireTuple('linux-riscv64-gnu')} + } + } else if (process.arch === 's390x') { + ${requireTuple('linux-s390x-gnu')} + } else { + loadErrors.push(new Error(\`Unsupported architecture on Linux: \${process.arch}\`)) } - break - case 'freebsd': - switch (arch) { - case 'x64': - localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-x64.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.freebsd-x64.node') - } else { - nativeBinding = require('${pkgName}-freebsd-x64') - } - } catch (e) { - loadError = e - } - break - case 'arm64': - localFileExisted = existsSync(join(__dirname, '${localName}.freebsd-arm64.node')) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.freebsd-arm64.node') - } else { - nativeBinding = require('${pkgName}-freebsd-arm64') - } - } catch (e) { - loadError = e - } - break - default: - loadError = new Error(\`Unsupported architecture on FreeBSD: \${arch}\`) - } - break - case 'linux': - switch (arch) { - case 'x64': - if (isMusl()) { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-x64-musl.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-x64-musl.node') - } else { - nativeBinding = require('${pkgName}-linux-x64-musl') - } - } catch (e) { - loadError = e - } - } else { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-x64-gnu.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-x64-gnu.node') - } else { - nativeBinding = require('${pkgName}-linux-x64-gnu') - } - } catch (e) { - loadError = e - } - } - break - case 'arm64': - if (isMusl()) { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-arm64-musl.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-arm64-musl.node') - } else { - nativeBinding = require('${pkgName}-linux-arm64-musl') - } - } catch (e) { - loadError = e - } - } else { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-arm64-gnu.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-arm64-gnu.node') - } else { - nativeBinding = require('${pkgName}-linux-arm64-gnu') - } - } catch (e) { - loadError = e - } - } - break - case 'arm': - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-arm-gnueabihf.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-arm-gnueabihf.node') - } else { - nativeBinding = require('${pkgName}-linux-arm-gnueabihf') - } - } catch (e) { - loadError = e - } - break - case 'riscv64': - if (isMusl()) { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-riscv64-musl.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-riscv64-musl.node') - } else { - nativeBinding = require('${pkgName}-linux-riscv64-musl') - } - } catch (e) { - loadError = e - } - } else { - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-riscv64-gnu.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-riscv64-gnu.node') - } else { - nativeBinding = require('${pkgName}-linux-riscv64-gnu') - } - } catch (e) { - loadError = e - } - } - break - case 's390x': - localFileExisted = existsSync( - join(__dirname, '${localName}.linux-s390x-gnu.node') - ) - try { - if (localFileExisted) { - nativeBinding = require('./${localName}.linux-s390x-gnu.node') - } else { - nativeBinding = require('${pkgName}-linux-s390x-gnu') - } - } catch (e) { - loadError = e - } - break - default: - loadError = new Error(\`Unsupported architecture on Linux: \${arch}\`) - } - break - default: - loadError = new Error(\`Unsupported OS: \${platform}, architecture: \${arch}\`) + } else { + loadErrors.push(new Error(\`Unsupported OS: \${process.platform}, architecture: \${process.arch}\`)) + } } +nativeBinding = requireNative() + if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { try { nativeBinding = require('./${localName}.wasi.cjs') @@ -360,8 +166,12 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { } if (!nativeBinding) { - if (loadError) { - throw loadError + if (loadErrors.length > 0) { + // TODO Link to documentation with potential fixes + // - The package owner could build/publish bindings for this arch + // - The user may need to bundle the correct files + // - The user may need to re-install node_modules to get new packages + throw new Error('Failed to load native binding', { cause: loadErrors }) } throw new Error(\`Failed to load native binding\`) } diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md index d25a3cc1..3d5302db 100644 --- a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md +++ b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.md @@ -370,7 +370,7 @@ Generated by [AVA](https://avajs.dev). ␊ export function createObjWithProperty(): { value: ArrayBuffer, get getter(): number }␊ ␊ - export function createReferenceOnFunction(cb: () => void): object␊ + export function createReferenceOnFunction(cb: () => void): Promise␊ ␊ export function createSymbol(): symbol␊ ␊ diff --git a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap index 9d2db18f..ac1ef45a 100644 Binary files a/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap and b/examples/napi/__tests__/__snapshots__/typegen.spec.ts.snap differ diff --git a/examples/napi/__tests__/__snapshots__/values.spec.ts.md b/examples/napi/__tests__/__snapshots__/values.spec.ts.md index b849fa97..8a3e6fe6 100644 --- a/examples/napi/__tests__/__snapshots__/values.spec.ts.md +++ b/examples/napi/__tests__/__snapshots__/values.spec.ts.md @@ -10,6 +10,7 @@ Generated by [AVA](https://avajs.dev). [ '@napi-rs/cli', + '@napi-rs/triples', '@napi-rs/wasm-runtime', '@types/lodash', '@vitest/browser', diff --git a/examples/napi/__tests__/__snapshots__/values.spec.ts.snap b/examples/napi/__tests__/__snapshots__/values.spec.ts.snap index 84b41386..22206d79 100644 Binary files a/examples/napi/__tests__/__snapshots__/values.spec.ts.snap and b/examples/napi/__tests__/__snapshots__/values.spec.ts.snap differ diff --git a/examples/napi/__tests__/error-msg.spec.ts b/examples/napi/__tests__/error-msg.spec.ts index bd6feeb2..ce3d95c1 100644 --- a/examples/napi/__tests__/error-msg.spec.ts +++ b/examples/napi/__tests__/error-msg.spec.ts @@ -1,6 +1,6 @@ import test from 'ava' -const { receiveString } = (await import('../index.js')).default +import { receiveString } from '../index.cjs' test('Function message', (t) => { // @ts-expect-error diff --git a/examples/napi/__tests__/generator.spec.ts b/examples/napi/__tests__/generator.spec.ts index cbbcc3cd..f8757f28 100644 --- a/examples/napi/__tests__/generator.spec.ts +++ b/examples/napi/__tests__/generator.spec.ts @@ -1,6 +1,6 @@ import test from 'ava' -const { Fib, Fib2, Fib3 } = (await import('../index.js')).default +import { Fib, Fib2, Fib3 } from '../index.cjs' for (const [index, factory] of [ () => new Fib(), diff --git a/examples/napi/__tests__/object-attr.spec.ts b/examples/napi/__tests__/object-attr.spec.ts index 5a2ebc0d..f5f25124 100644 --- a/examples/napi/__tests__/object-attr.spec.ts +++ b/examples/napi/__tests__/object-attr.spec.ts @@ -1,6 +1,6 @@ import test from 'ava' -const { NotWritableClass } = (await import('../index.js')).default +import { NotWritableClass } from '../index.cjs' test('Not Writable Class', (t) => { const obj = new NotWritableClass('1') diff --git a/examples/napi/__tests__/strict.spec.ts b/examples/napi/__tests__/strict.spec.ts index be7efd72..5fd555bf 100644 --- a/examples/napi/__tests__/strict.spec.ts +++ b/examples/napi/__tests__/strict.spec.ts @@ -1,6 +1,6 @@ import test from 'ava' -const { +import { validateArray, validateTypedArray, validateTypedArraySlice, @@ -22,7 +22,7 @@ const { returnUndefinedIfInvalid, returnUndefinedIfInvalidPromise, validateOptional, -} = (await import('../index.js')).default +} from '../index.cjs' test('should validate array', (t) => { t.is(validateArray([1, 2, 3]), 3) diff --git a/examples/napi/__tests__/tsfn-error.cjs b/examples/napi/__tests__/tsfn-error.cjs index 19ac08c1..6007bfa1 100644 --- a/examples/napi/__tests__/tsfn-error.cjs +++ b/examples/napi/__tests__/tsfn-error.cjs @@ -1,5 +1,5 @@ -import('../index.js').then( - ({ default: { threadsafeFunctionFatalModeError } }) => { +import('../index.cjs').then( + ({ threadsafeFunctionFatalModeError }) => { return threadsafeFunctionFatalModeError(() => {}) }, ) diff --git a/examples/napi/__tests__/typegen.spec.ts b/examples/napi/__tests__/typegen.spec.ts index f0428754..0498499c 100644 --- a/examples/napi/__tests__/typegen.spec.ts +++ b/examples/napi/__tests__/typegen.spec.ts @@ -10,6 +10,6 @@ test('should generate correct type def file', (t) => { if (process.env.WASI_TEST) { t.pass() } else { - t.snapshot(readFileSync(join(__dirname, '..', 'index.d.ts'), 'utf8')) + t.snapshot(readFileSync(join(__dirname, '..', 'index.d.cts'), 'utf8')) } }) diff --git a/examples/napi/__tests__/unload.spec.js b/examples/napi/__tests__/unload.spec.js index dd4594bb..803f64b3 100644 --- a/examples/napi/__tests__/unload.spec.js +++ b/examples/napi/__tests__/unload.spec.js @@ -3,24 +3,41 @@ import { createRequire } from 'node:module' import * as path from 'node:path' +import { platformArchTriples } from '@napi-rs/triples' import test from 'ava' const require = createRequire(import.meta.url) const __dirname = path.dirname(new URL(import.meta.url).pathname) +const platforms = platformArchTriples[process.platform][process.arch] + +let binaryName + +if (platforms.length() === 1) { + binaryName = `example.${platforms[0].platformArchABI}.node` +} else if (process.platform === 'linux') { + if (process.report?.getReport?.()?.header.glibcVersionRuntime) { + binaryName = `example.${platforms.find(({ abi }) => abi === 'gnu').platformArchABI}.node` + } else { + binaryName = `example.${platforms.find(({ abi }) => abi === 'musl').platformArchABI}.node` + } +} else { + throw new Error('unsupported platform') +} + test('unload module', (t) => { - const { add } = require('../index.node') + const { add } = require(`../${binaryName}`) t.is(add(1, 2), 3) - delete require.cache[require.resolve('../index.node')] - const { add: add2 } = require('../index.node') + delete require.cache[require.resolve(`../${binaryName}`)] + const { add: add2 } = require(`../${binaryName}`) t.is(add2(1, 2), 3) }) test('load module multi times', (t) => { - const { add } = require('../index.node') + const { add } = require(`../${binaryName}`) t.is(add(1, 2), 3) const { add: add2 } = require( - path.toNamespacedPath(path.join(__dirname, '../index.node')), + path.toNamespacedPath(path.join(__dirname, `../${binaryName}`)), ) t.is(add2(1, 2), 3) }) diff --git a/examples/napi/__tests__/values.spec.ts b/examples/napi/__tests__/values.spec.ts index d826e170..1296ea45 100644 --- a/examples/napi/__tests__/values.spec.ts +++ b/examples/napi/__tests__/values.spec.ts @@ -4,13 +4,7 @@ import { fileURLToPath } from 'node:url' import { spy } from 'sinon' -import { type AliasedStruct, type Animal as AnimalClass } from '../index.js' - -import { test } from './test.framework.js' - -const __dirname = join(fileURLToPath(import.meta.url), '..') - -const { +import { DEFAULT_COST, add, fibonacci, @@ -173,7 +167,12 @@ const { throwAsyncError, getModuleFileName, throwSyntaxError, -} = (await import('../index.js')).default + type AliasedStruct, +} from '../index.cjs' + +import { test } from './test.framework.js' + +const __dirname = join(fileURLToPath(import.meta.url), '..') const Napi4Test = Number(process.versions.napi) >= 4 ? test : test.skip @@ -247,14 +246,14 @@ test('function call', async (t) => { 52, ) const ctx = new Animal(Kind.Dog, '旺财') - apply0(ctx, function (this: AnimalClass) { + apply0(ctx, function (this: Animal) { this.name = '可乐' }) t.is(ctx.name, '可乐') const ctx2 = new Animal(Kind.Dog, '旺财') apply1( ctx2, - function (this: AnimalClass, name: string) { + function (this: Animal, name: string) { this.name = name }, '可乐', @@ -271,7 +270,7 @@ test('function call', async (t) => { const ctx3 = new Animal(Kind.Dog, '旺财') callFunctionWithArgAndCtx( ctx3, - function (this: AnimalClass, name: string) { + function (this: Animal, name: string) { this.name = name }, '可乐', @@ -1184,7 +1183,10 @@ Napi9Test('get module file name', (t) => { return } console.info(getModuleFileName()) - t.true(getModuleFileName().includes('examples/napi/index.node')) + t.regex( + getModuleFileName(), + new RegExp(`example.${process.platform}-${process.arch}`), + ) }) test('throw syntax error', (t) => { diff --git a/examples/napi/__tests__/worker-thread.spec.ts b/examples/napi/__tests__/worker-thread.spec.ts index 77b9b883..3f9dba00 100644 --- a/examples/napi/__tests__/worker-thread.spec.ts +++ b/examples/napi/__tests__/worker-thread.spec.ts @@ -4,7 +4,7 @@ import { Worker } from 'node:worker_threads' import test from 'ava' -const { Animal, Kind, DEFAULT_COST } = (await import('../index.js')).default +import { Animal, Kind, DEFAULT_COST } from '../index.cjs' const __dirname = join(fileURLToPath(import.meta.url), '..') diff --git a/examples/napi/__tests__/worker.cjs b/examples/napi/__tests__/worker.cjs index 0dbb2451..d6852506 100644 --- a/examples/napi/__tests__/worker.cjs +++ b/examples/napi/__tests__/worker.cjs @@ -1,57 +1,53 @@ -const { parentPort } = require('worker_threads') +const { parentPort } = require('node:worker_threads') + +const native = require('../index.cjs') const isWasiTest = !!process.env.WASI_TEST -import('../index.js') - .then(({ default: native }) => { - parentPort.on('message', ({ type }) => { - switch (type) { - case 'require': - parentPort.postMessage( - native.Animal.withKind(native.Kind.Cat).whoami() + - native.DEFAULT_COST, - ) - break - case 'async:buffer': - Promise.all( - Array.from({ length: isWasiTest ? 2 : 100 }).map(() => - native.bufferPassThrough(Buffer.from([1, 2, 3])), - ), - ) - .then(() => { - parentPort.postMessage('done') - }) - .catch((e) => { - throw e - }) - break - case 'async:arraybuffer': - Promise.all( - Array.from({ length: isWasiTest ? 2 : 100 }).map(() => - native.arrayBufferPassThrough(Uint8Array.from([1, 2, 3])), - ), - ) - .then(() => { - parentPort.postMessage('done') - }) - .catch((e) => { - throw e - }) +parentPort.on('message', ({ type }) => { + switch (type) { + case 'require': + parentPort.postMessage( + native.Animal.withKind(native.Kind.Cat).whoami() + + native.DEFAULT_COST, + ) + break + case 'async:buffer': + Promise.all( + Array.from({ length: isWasiTest ? 2 : 100 }).map(() => + native.bufferPassThrough(Buffer.from([1, 2, 3])), + ), + ) + .then(() => { + parentPort.postMessage('done') + }) + .catch((e) => { + throw e + }) + break + case 'async:arraybuffer': + Promise.all( + Array.from({ length: isWasiTest ? 2 : 100 }).map(() => + native.arrayBufferPassThrough(Uint8Array.from([1, 2, 3])), + ), + ) + .then(() => { + parentPort.postMessage('done') + }) + .catch((e) => { + throw e + }) - break - case 'constructor': - let ellie - for (let i = 0; i < (isWasiTest ? 10 : 1000); i++) { - ellie = new native.Animal(native.Kind.Cat, 'Ellie') - } - parentPort.postMessage(ellie.name) - break - default: - throw new TypeError(`Unknown message type: ${type}`) + break + case 'constructor': + let ellie + for (let i = 0; i < (isWasiTest ? 10 : 1000); i++) { + ellie = new native.Animal(native.Kind.Cat, 'Ellie') } - }) - }) - .catch((e) => { - console.error(e) - process.exit(1) - }) + parentPort.postMessage(ellie.name) + break + default: + throw new TypeError(`Unknown message type: ${type}`) + } +}) + diff --git a/examples/napi/browser/values.spec.ts b/examples/napi/browser/values.spec.ts index 9b4b0bd6..69f0fc4d 100644 --- a/examples/napi/browser/values.spec.ts +++ b/examples/napi/browser/values.spec.ts @@ -7,7 +7,7 @@ const { GetterSetterWithClosures, tsfnReturnPromise, tsfnReturnPromiseTimeout, -}: typeof import('../index') = await import('../index.wasi-browser') +}: typeof import('../index.cjs') = await import('../example.wasi-browser') describe('NAPI-RS wasi browser test', function () { it('DEFAULT_COST', function () { diff --git a/examples/napi/electron-renderer/index.js b/examples/napi/electron-renderer/index.js index c422774a..8fb2b7b3 100644 --- a/examples/napi/electron-renderer/index.js +++ b/examples/napi/electron-renderer/index.js @@ -1,6 +1,6 @@ const { ipcRenderer } = require('electron') -const { callLongThreadsafeFunction } = require('../index.node') +const { callLongThreadsafeFunction } = require('../index.cjs') callLongThreadsafeFunction(() => {}) diff --git a/examples/napi/electron.cjs b/examples/napi/electron.cjs index 64a39e42..0d35c543 100644 --- a/examples/napi/electron.cjs +++ b/examples/napi/electron.cjs @@ -48,13 +48,11 @@ const createWindowAndReload = async () => { async function main() { const { - default: { - readFileAsync, - callThreadsafeFunction, - withAbortController, - createExternalTypedArray, - }, - } = await import('./index.js') + readFileAsync, + callThreadsafeFunction, + withAbortController, + createExternalTypedArray, + } = require('./index.cjs') const ctrl = new AbortController() const promise = withAbortController(1, 2, ctrl.signal) diff --git a/examples/napi/index.wasi-browser.js b/examples/napi/example.wasi-browser.js similarity index 61% rename from examples/napi/index.wasi-browser.js rename to examples/napi/example.wasi-browser.js index 091bd169..6dcf1bef 100644 --- a/examples/napi/index.wasi-browser.js +++ b/examples/napi/example.wasi-browser.js @@ -8,7 +8,7 @@ import { createFsFromVolume as __createFsFromVolume, } from '@napi-rs/wasm-runtime/fs' -import __wasmUrl from './index.wasm?url' +import __wasmUrl from './example.wasm32-wasi.wasm?url' const __fs = __createFsFromVolume( __Volume.fromJSON({ @@ -92,261 +92,296 @@ function __napi_rs_initialize_modules(__napiInstance) { __napiInstance.exports['__napi_register__Animal_impl_38']?.() __napiInstance.exports['__napi_register__Dog_struct_39']?.() __napiInstance.exports['__napi_register__Bird_struct_40']?.() - __napiInstance.exports['__napi_register__Bird_impl_44']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_struct_45']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_impl_47']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_impl_49']?.() - __napiInstance.exports['__napi_register__Blake2bKey_struct_50']?.() - __napiInstance.exports['__napi_register__Context_struct_51']?.() - __napiInstance.exports['__napi_register__Context_impl_56']?.() + __napiInstance.exports['__napi_register__Bird_impl_45']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_struct_46']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_impl_48']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_impl_50']?.() + __napiInstance.exports['__napi_register__Blake2bKey_struct_51']?.() + __napiInstance.exports['__napi_register__Context_struct_52']?.() + __napiInstance.exports['__napi_register__Context_impl_57']?.() __napiInstance.exports[ - '__napi_register__AnimalWithDefaultConstructor_struct_57' + '__napi_register__AnimalWithDefaultConstructor_struct_58' ]?.() - __napiInstance.exports['__napi_register__NinjaTurtle_struct_58']?.() - __napiInstance.exports['__napi_register__NinjaTurtle_impl_65']?.() - __napiInstance.exports['__napi_register__JsAssets_struct_66']?.() - __napiInstance.exports['__napi_register__JsAssets_impl_69']?.() - __napiInstance.exports['__napi_register__JsAsset_struct_70']?.() - __napiInstance.exports['__napi_register__JsAsset_impl_73']?.() - __napiInstance.exports['__napi_register__Optional_struct_74']?.() - __napiInstance.exports['__napi_register__Optional_impl_79']?.() + __napiInstance.exports['__napi_register__NinjaTurtle_struct_59']?.() + __napiInstance.exports['__napi_register__NinjaTurtle_impl_66']?.() + __napiInstance.exports['__napi_register__JsAssets_struct_67']?.() + __napiInstance.exports['__napi_register__JsAssets_impl_70']?.() + __napiInstance.exports['__napi_register__JsAsset_struct_71']?.() + __napiInstance.exports['__napi_register__JsAsset_impl_74']?.() + __napiInstance.exports['__napi_register__Optional_struct_75']?.() + __napiInstance.exports['__napi_register__Optional_impl_80']?.() __napiInstance.exports[ - '__napi_register__ObjectFieldClassInstance_struct_80' + '__napi_register__ObjectFieldClassInstance_struct_81' ]?.() __napiInstance.exports[ - '__napi_register__create_object_with_class_field_81' + '__napi_register__create_object_with_class_field_82' ]?.() __napiInstance.exports[ - '__napi_register__receive_object_with_class_field_82' + '__napi_register__receive_object_with_class_field_83' ]?.() - __napiInstance.exports['__napi_register__NotWritableClass_struct_83']?.() - __napiInstance.exports['__napi_register__NotWritableClass_impl_85']?.() - __napiInstance.exports['__napi_register__CustomFinalize_struct_86']?.() - __napiInstance.exports['__napi_register__CustomFinalize_impl_88']?.() - __napiInstance.exports['__napi_register__Width_struct_89']?.() - __napiInstance.exports['__napi_register__plus_one_90']?.() + __napiInstance.exports['__napi_register__NotWritableClass_struct_84']?.() + __napiInstance.exports['__napi_register__NotWritableClass_impl_86']?.() + __napiInstance.exports['__napi_register__CustomFinalize_struct_87']?.() + __napiInstance.exports['__napi_register__CustomFinalize_impl_89']?.() + __napiInstance.exports['__napi_register__Width_struct_90']?.() + __napiInstance.exports['__napi_register__plus_one_91']?.() __napiInstance.exports[ - '__napi_register__GetterSetterWithClosures_struct_91' + '__napi_register__GetterSetterWithClosures_struct_92' ]?.() __napiInstance.exports[ - '__napi_register__GetterSetterWithClosures_impl_93' + '__napi_register__GetterSetterWithClosures_impl_94' ]?.() - __napiInstance.exports['__napi_register__CatchOnConstructor_struct_94']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor_impl_96']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor2_struct_97']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor2_impl_99']?.() - __napiInstance.exports['__napi_register__ClassWithFactory_struct_100']?.() - __napiInstance.exports['__napi_register__ClassWithFactory_impl_105']?.() - __napiInstance.exports['__napi_register__Selector_struct_106']?.() - __napiInstance.exports['__napi_register__date_to_number_107']?.() - __napiInstance.exports['__napi_register__chrono_date_to_millis_108']?.() - __napiInstance.exports['__napi_register__chrono_date_add_1_minute_109']?.() - __napiInstance.exports['__napi_register__Dates_struct_110']?.() - __napiInstance.exports['__napi_register__chrono_native_date_time_111']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor_struct_95']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor_impl_97']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor2_struct_98']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor2_impl_100']?.() + __napiInstance.exports['__napi_register__ClassWithFactory_struct_101']?.() + __napiInstance.exports['__napi_register__ClassWithFactory_impl_106']?.() + __napiInstance.exports['__napi_register__Selector_struct_107']?.() + __napiInstance.exports['__napi_register__date_to_number_108']?.() + __napiInstance.exports['__napi_register__chrono_date_to_millis_109']?.() + __napiInstance.exports['__napi_register__chrono_date_add_1_minute_110']?.() + __napiInstance.exports['__napi_register__Dates_struct_111']?.() + __napiInstance.exports['__napi_register__chrono_native_date_time_112']?.() __napiInstance.exports[ - '__napi_register__chrono_native_date_time_return_112' + '__napi_register__chrono_native_date_time_return_113' ]?.() - __napiInstance.exports['__napi_register__either_string_or_number_113']?.() - __napiInstance.exports['__napi_register__return_either_114']?.() - __napiInstance.exports['__napi_register__either3_115']?.() - __napiInstance.exports['__napi_register__Obj_struct_116']?.() - __napiInstance.exports['__napi_register__either4_117']?.() - __napiInstance.exports['__napi_register__JsClassForEither_struct_118']?.() - __napiInstance.exports['__napi_register__JsClassForEither_impl_120']?.() + __napiInstance.exports['__napi_register__either_string_or_number_114']?.() + __napiInstance.exports['__napi_register__return_either_115']?.() + __napiInstance.exports['__napi_register__either3_116']?.() + __napiInstance.exports['__napi_register__Obj_struct_117']?.() + __napiInstance.exports['__napi_register__either4_118']?.() + __napiInstance.exports['__napi_register__JsClassForEither_struct_119']?.() + __napiInstance.exports['__napi_register__JsClassForEither_impl_121']?.() __napiInstance.exports[ - '__napi_register__AnotherClassForEither_struct_121' + '__napi_register__AnotherClassForEither_struct_122' ]?.() - __napiInstance.exports['__napi_register__AnotherClassForEither_impl_123']?.() - __napiInstance.exports['__napi_register__receive_class_or_number_124']?.() - __napiInstance.exports['__napi_register__receive_mut_class_or_number_125']?.() - __napiInstance.exports['__napi_register__receive_different_class_126']?.() - __napiInstance.exports['__napi_register__return_either_class_127']?.() - __napiInstance.exports['__napi_register__either_from_option_128']?.() - __napiInstance.exports['__napi_register__A_struct_129']?.() - __napiInstance.exports['__napi_register__B_struct_130']?.() - __napiInstance.exports['__napi_register__C_struct_131']?.() - __napiInstance.exports['__napi_register__either_from_objects_132']?.() - __napiInstance.exports['__napi_register__either_bool_or_function_133']?.() - __napiInstance.exports['__napi_register__promise_in_either_134']?.() - __napiInstance.exports['__napi_register__Kind_135']?.() - __napiInstance.exports['__napi_register__Empty_136']?.() - __napiInstance.exports['__napi_register__Status_137']?.() - __napiInstance.exports['__napi_register__CustomNumEnum_138']?.() - __napiInstance.exports['__napi_register__enum_to_i32_139']?.() - __napiInstance.exports['__napi_register__SkippedEnums_140']?.() - __napiInstance.exports['__napi_register__run_script_141']?.() - __napiInstance.exports['__napi_register__get_module_file_name_142']?.() - __napiInstance.exports['__napi_register__throw_syntax_error_143']?.() - __napiInstance.exports['__napi_register__throw_error_144']?.() - __napiInstance.exports['__napi_register__panic_145']?.() - __napiInstance.exports['__napi_register__receive_string_146']?.() - __napiInstance.exports['__napi_register__custom_status_code_147']?.() - __napiInstance.exports['__napi_register__throw_async_error_148']?.() - __napiInstance.exports['__napi_register__create_external_149']?.() - __napiInstance.exports['__napi_register__create_external_string_150']?.() - __napiInstance.exports['__napi_register__get_external_151']?.() - __napiInstance.exports['__napi_register__mutate_external_152']?.() - __napiInstance.exports['__napi_register__validate_array_153']?.() - __napiInstance.exports['__napi_register__validate_buffer_154']?.() - __napiInstance.exports['__napi_register__validate_typed_array_155']?.() - __napiInstance.exports['__napi_register__validate_bigint_156']?.() - __napiInstance.exports['__napi_register__validate_boolean_157']?.() - __napiInstance.exports['__napi_register__validate_date_158']?.() - __napiInstance.exports['__napi_register__validate_date_time_159']?.() - __napiInstance.exports['__napi_register__validate_external_160']?.() - __napiInstance.exports['__napi_register__validate_function_161']?.() - __napiInstance.exports['__napi_register__validate_hash_map_162']?.() - __napiInstance.exports['__napi_register__validate_null_163']?.() - __napiInstance.exports['__napi_register__validate_undefined_164']?.() - __napiInstance.exports['__napi_register__validate_number_165']?.() - __napiInstance.exports['__napi_register__validate_promise_166']?.() - __napiInstance.exports['__napi_register__validate_string_167']?.() - __napiInstance.exports['__napi_register__validate_symbol_168']?.() - __napiInstance.exports['__napi_register__validate_optional_169']?.() - __napiInstance.exports['__napi_register__return_undefined_if_invalid_170']?.() + __napiInstance.exports['__napi_register__AnotherClassForEither_impl_124']?.() + __napiInstance.exports['__napi_register__receive_class_or_number_125']?.() + __napiInstance.exports['__napi_register__receive_mut_class_or_number_126']?.() + __napiInstance.exports['__napi_register__receive_different_class_127']?.() + __napiInstance.exports['__napi_register__return_either_class_128']?.() + __napiInstance.exports['__napi_register__either_from_option_129']?.() + __napiInstance.exports['__napi_register__A_struct_130']?.() + __napiInstance.exports['__napi_register__B_struct_131']?.() + __napiInstance.exports['__napi_register__C_struct_132']?.() + __napiInstance.exports['__napi_register__either_from_objects_133']?.() + __napiInstance.exports['__napi_register__either_bool_or_function_134']?.() + __napiInstance.exports['__napi_register__promise_in_either_135']?.() + __napiInstance.exports['__napi_register__Kind_136']?.() + __napiInstance.exports['__napi_register__Empty_137']?.() + __napiInstance.exports['__napi_register__Status_138']?.() + __napiInstance.exports['__napi_register__CustomNumEnum_139']?.() + __napiInstance.exports['__napi_register__enum_to_i32_140']?.() + __napiInstance.exports['__napi_register__SkippedEnums_141']?.() + __napiInstance.exports['__napi_register__run_script_142']?.() + __napiInstance.exports['__napi_register__get_module_file_name_143']?.() + __napiInstance.exports['__napi_register__throw_syntax_error_144']?.() + __napiInstance.exports['__napi_register__throw_error_145']?.() + __napiInstance.exports['__napi_register__panic_146']?.() + __napiInstance.exports['__napi_register__receive_string_147']?.() + __napiInstance.exports['__napi_register__custom_status_code_148']?.() + __napiInstance.exports['__napi_register__throw_async_error_149']?.() + __napiInstance.exports['__napi_register__create_external_150']?.() + __napiInstance.exports['__napi_register__create_external_string_151']?.() + __napiInstance.exports['__napi_register__get_external_152']?.() + __napiInstance.exports['__napi_register__mutate_external_153']?.() + __napiInstance.exports['__napi_register__validate_array_154']?.() + __napiInstance.exports['__napi_register__validate_buffer_155']?.() + __napiInstance.exports['__napi_register__validate_typed_array_156']?.() + __napiInstance.exports['__napi_register__validate_typed_array_slice_157']?.() __napiInstance.exports[ - '__napi_register__return_undefined_if_invalid_promise_171' + '__napi_register__validate_uint8_clamped_slice_158' ]?.() - __napiInstance.exports['__napi_register__ts_rename_172']?.() + __napiInstance.exports['__napi_register__validate_buffer_slice_159']?.() + __napiInstance.exports['__napi_register__validate_bigint_160']?.() + __napiInstance.exports['__napi_register__validate_boolean_161']?.() + __napiInstance.exports['__napi_register__validate_date_162']?.() + __napiInstance.exports['__napi_register__validate_date_time_163']?.() + __napiInstance.exports['__napi_register__validate_external_164']?.() + __napiInstance.exports['__napi_register__validate_function_165']?.() + __napiInstance.exports['__napi_register__validate_hash_map_166']?.() + __napiInstance.exports['__napi_register__validate_null_167']?.() + __napiInstance.exports['__napi_register__validate_undefined_168']?.() + __napiInstance.exports['__napi_register__validate_number_169']?.() + __napiInstance.exports['__napi_register__validate_promise_170']?.() + __napiInstance.exports['__napi_register__validate_string_171']?.() + __napiInstance.exports['__napi_register__validate_symbol_172']?.() + __napiInstance.exports['__napi_register__validate_optional_173']?.() + __napiInstance.exports['__napi_register__return_undefined_if_invalid_174']?.() __napiInstance.exports[ - '__napi_register__override_individual_arg_on_function_173' + '__napi_register__return_undefined_if_invalid_promise_175' + ]?.() + __napiInstance.exports['__napi_register__ts_rename_176']?.() + __napiInstance.exports[ + '__napi_register__override_individual_arg_on_function_177' ]?.() __napiInstance.exports[ - '__napi_register__override_individual_arg_on_function_with_cb_arg_174' + '__napi_register__override_individual_arg_on_function_with_cb_arg_178' ]?.() - __napiInstance.exports['__napi_register__call0_175']?.() - __napiInstance.exports['__napi_register__call1_176']?.() - __napiInstance.exports['__napi_register__call2_177']?.() - __napiInstance.exports['__napi_register__apply0_178']?.() - __napiInstance.exports['__napi_register__apply1_179']?.() - __napiInstance.exports['__napi_register__call_function_180']?.() - __napiInstance.exports['__napi_register__call_function_with_arg_181']?.() + __napiInstance.exports['__napi_register__call0_179']?.() + __napiInstance.exports['__napi_register__call1_180']?.() + __napiInstance.exports['__napi_register__call2_181']?.() + __napiInstance.exports['__napi_register__apply0_182']?.() + __napiInstance.exports['__napi_register__apply1_183']?.() + __napiInstance.exports['__napi_register__call_function_184']?.() + __napiInstance.exports['__napi_register__call_function_with_arg_185']?.() __napiInstance.exports[ - '__napi_register__create_reference_on_function_182' + '__napi_register__create_reference_on_function_186' ]?.() __napiInstance.exports[ - '__napi_register__call_function_with_arg_and_ctx_183' + '__napi_register__call_function_with_arg_and_ctx_187' ]?.() - __napiInstance.exports['__napi_register__reference_as_callback_184']?.() - __napiInstance.exports['__napi_register__Fib_struct_185']?.() - __napiInstance.exports['__napi_register__Fib_impl_186']?.() - __napiInstance.exports['__napi_register__Fib_impl_188']?.() - __napiInstance.exports['__napi_register__Fib2_struct_189']?.() - __napiInstance.exports['__napi_register__Fib2_impl_190']?.() - __napiInstance.exports['__napi_register__Fib2_impl_192']?.() - __napiInstance.exports['__napi_register__Fib3_struct_193']?.() - __napiInstance.exports['__napi_register__Fib3_impl_194']?.() - __napiInstance.exports['__napi_register__ALIGNMENT_195']?.() - __napiInstance.exports['__napi_register__xxh64_196']?.() - __napiInstance.exports['__napi_register__xxh128_197']?.() - __napiInstance.exports['__napi_register__Xxh3_struct_198']?.() - __napiInstance.exports['__napi_register__Xxh3_impl_202']?.() - __napiInstance.exports['__napi_register__xxh2_plus_203']?.() - __napiInstance.exports['__napi_register__xxh3_xxh64_alias_204']?.() - __napiInstance.exports['__napi_register__xxh64_alias_205']?.() - __napiInstance.exports['__napi_register__get_mapping_206']?.() - __napiInstance.exports['__napi_register__sum_mapping_207']?.() - __napiInstance.exports['__napi_register__map_option_208']?.() - __napiInstance.exports['__napi_register__return_null_209']?.() - __napiInstance.exports['__napi_register__return_undefined_210']?.() - __napiInstance.exports['__napi_register__add_211']?.() - __napiInstance.exports['__napi_register__fibonacci_212']?.() - __napiInstance.exports['__napi_register__list_obj_keys_213']?.() - __napiInstance.exports['__napi_register__create_obj_214']?.() - __napiInstance.exports['__napi_register__get_global_215']?.() - __napiInstance.exports['__napi_register__get_undefined_216']?.() - __napiInstance.exports['__napi_register__get_null_217']?.() - __napiInstance.exports['__napi_register__AllOptionalObject_struct_218']?.() - __napiInstance.exports['__napi_register__receive_all_optional_object_219']?.() - __napiInstance.exports['__napi_register__AliasedEnum_220']?.() + __napiInstance.exports['__napi_register__reference_as_callback_188']?.() + __napiInstance.exports['__napi_register__Fib_struct_189']?.() + __napiInstance.exports['__napi_register__Fib_impl_190']?.() + __napiInstance.exports['__napi_register__Fib_impl_192']?.() + __napiInstance.exports['__napi_register__Fib2_struct_193']?.() + __napiInstance.exports['__napi_register__Fib2_impl_194']?.() + __napiInstance.exports['__napi_register__Fib2_impl_196']?.() + __napiInstance.exports['__napi_register__Fib3_struct_197']?.() + __napiInstance.exports['__napi_register__Fib3_impl_198']?.() + __napiInstance.exports['__napi_register__ALIGNMENT_199']?.() + __napiInstance.exports['__napi_register__xxh64_200']?.() + __napiInstance.exports['__napi_register__xxh128_201']?.() + __napiInstance.exports['__napi_register__Xxh3_struct_202']?.() + __napiInstance.exports['__napi_register__Xxh3_impl_206']?.() + __napiInstance.exports['__napi_register__xxh2_plus_207']?.() + __napiInstance.exports['__napi_register__xxh3_xxh64_alias_208']?.() + __napiInstance.exports['__napi_register__xxh64_alias_209']?.() + __napiInstance.exports['__napi_register__get_mapping_210']?.() + __napiInstance.exports['__napi_register__sum_mapping_211']?.() + __napiInstance.exports['__napi_register__get_btree_mapping_212']?.() + __napiInstance.exports['__napi_register__sum_btree_mapping_213']?.() + __napiInstance.exports['__napi_register__get_index_mapping_214']?.() + __napiInstance.exports['__napi_register__sum_index_mapping_215']?.() + __napiInstance.exports['__napi_register__indexmap_passthrough_216']?.() + __napiInstance.exports['__napi_register__map_option_217']?.() + __napiInstance.exports['__napi_register__return_null_218']?.() + __napiInstance.exports['__napi_register__return_undefined_219']?.() + __napiInstance.exports['__napi_register__UseNullableStruct_struct_220']?.() + __napiInstance.exports['__napi_register__NotUseNullableStruct_struct_221']?.() __napiInstance.exports[ - '__napi_register__StructContainsAliasedEnum_struct_221' + '__napi_register__DefaultUseNullableStruct_struct_222' ]?.() - __napiInstance.exports['__napi_register__fn_received_aliased_222']?.() - __napiInstance.exports['__napi_register__StrictObject_struct_223']?.() - __napiInstance.exports['__napi_register__receive_strict_object_224']?.() - __napiInstance.exports['__napi_register__get_str_from_object_225']?.() - __napiInstance.exports['__napi_register__TsTypeChanged_struct_226']?.() - __napiInstance.exports['__napi_register__create_obj_with_property_227']?.() - __napiInstance.exports['__napi_register__getter_from_obj_228']?.() - __napiInstance.exports['__napi_register__ObjectOnlyFromJs_struct_229']?.() - __napiInstance.exports['__napi_register__receive_object_only_from_js_230']?.() - __napiInstance.exports['__napi_register__async_plus_100_231']?.() - __napiInstance.exports['__napi_register__JsRepo_struct_232']?.() - __napiInstance.exports['__napi_register__JsRepo_impl_235']?.() - __napiInstance.exports['__napi_register__JsRemote_struct_236']?.() - __napiInstance.exports['__napi_register__JsRemote_impl_238']?.() - __napiInstance.exports['__napi_register__CSSRuleList_struct_239']?.() - __napiInstance.exports['__napi_register__CSSRuleList_impl_243']?.() - __napiInstance.exports['__napi_register__CSSStyleSheet_struct_244']?.() - __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_struct_245']?.() - __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_impl_247']?.() - __napiInstance.exports['__napi_register__CSSStyleSheet_impl_251']?.() - __napiInstance.exports['__napi_register__PackageJson_struct_252']?.() - __napiInstance.exports['__napi_register__read_package_json_253']?.() - __napiInstance.exports['__napi_register__get_package_json_name_254']?.() - __napiInstance.exports['__napi_register__test_serde_roundtrip_255']?.() + __napiInstance.exports['__napi_register__UseNullableClass_struct_223']?.() + __napiInstance.exports['__napi_register__NotUseNullableClass_struct_224']?.() __napiInstance.exports[ - '__napi_register__test_serde_big_number_precision_256' + '__napi_register__DefaultUseNullableClass_struct_225' ]?.() - __napiInstance.exports['__napi_register__return_from_shared_crate_257']?.() - __napiInstance.exports['__napi_register__contains_258']?.() - __napiInstance.exports['__napi_register__concat_str_259']?.() - __napiInstance.exports['__napi_register__concat_utf16_260']?.() - __napiInstance.exports['__napi_register__concat_latin1_261']?.() - __napiInstance.exports['__napi_register__roundtrip_str_262']?.() - __napiInstance.exports['__napi_register__set_symbol_in_obj_263']?.() - __napiInstance.exports['__napi_register__create_symbol_264']?.() - __napiInstance.exports['__napi_register__create_symbol_for_265']?.() - __napiInstance.exports['__napi_register__DelaySum_impl_266']?.() - __napiInstance.exports['__napi_register__without_abort_controller_267']?.() - __napiInstance.exports['__napi_register__with_abort_controller_268']?.() - __napiInstance.exports['__napi_register__AsyncTaskVoidReturn_impl_269']?.() - __napiInstance.exports['__napi_register__async_task_void_return_270']?.() + __napiInstance.exports['__napi_register__add_226']?.() + __napiInstance.exports['__napi_register__fibonacci_227']?.() + __napiInstance.exports['__napi_register__list_obj_keys_228']?.() + __napiInstance.exports['__napi_register__create_obj_229']?.() + __napiInstance.exports['__napi_register__get_global_230']?.() + __napiInstance.exports['__napi_register__get_undefined_231']?.() + __napiInstance.exports['__napi_register__get_null_232']?.() + __napiInstance.exports['__napi_register__AllOptionalObject_struct_233']?.() + __napiInstance.exports['__napi_register__receive_all_optional_object_234']?.() + __napiInstance.exports['__napi_register__AliasedEnum_235']?.() __napiInstance.exports[ - '__napi_register__AsyncTaskOptionalReturn_impl_271' + '__napi_register__StructContainsAliasedEnum_struct_236' ]?.() - __napiInstance.exports['__napi_register__async_task_optional_return_272']?.() - __napiInstance.exports['__napi_register__call_threadsafe_function_273']?.() + __napiInstance.exports['__napi_register__fn_received_aliased_237']?.() + __napiInstance.exports['__napi_register__StrictObject_struct_238']?.() + __napiInstance.exports['__napi_register__receive_strict_object_239']?.() + __napiInstance.exports['__napi_register__get_str_from_object_240']?.() + __napiInstance.exports['__napi_register__TsTypeChanged_struct_241']?.() + __napiInstance.exports['__napi_register__create_obj_with_property_242']?.() + __napiInstance.exports['__napi_register__getter_from_obj_243']?.() + __napiInstance.exports['__napi_register__ObjectOnlyFromJs_struct_244']?.() + __napiInstance.exports['__napi_register__receive_object_only_from_js_245']?.() + __napiInstance.exports['__napi_register__async_plus_100_246']?.() + __napiInstance.exports['__napi_register__JsRepo_struct_247']?.() + __napiInstance.exports['__napi_register__JsRepo_impl_250']?.() + __napiInstance.exports['__napi_register__JsRemote_struct_251']?.() + __napiInstance.exports['__napi_register__JsRemote_impl_254']?.() + __napiInstance.exports['__napi_register__CSSRuleList_struct_255']?.() + __napiInstance.exports['__napi_register__CSSRuleList_impl_259']?.() + __napiInstance.exports['__napi_register__CSSStyleSheet_struct_260']?.() + __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_struct_261']?.() + __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_impl_263']?.() + __napiInstance.exports['__napi_register__CSSStyleSheet_impl_267']?.() + __napiInstance.exports['__napi_register__PackageJson_struct_268']?.() + __napiInstance.exports['__napi_register__read_package_json_269']?.() + __napiInstance.exports['__napi_register__get_package_json_name_270']?.() + __napiInstance.exports['__napi_register__test_serde_roundtrip_271']?.() __napiInstance.exports[ - '__napi_register__call_long_threadsafe_function_274' + '__napi_register__test_serde_big_number_precision_272' + ]?.() + __napiInstance.exports['__napi_register__return_from_shared_crate_273']?.() + __napiInstance.exports['__napi_register__contains_274']?.() + __napiInstance.exports['__napi_register__concat_str_275']?.() + __napiInstance.exports['__napi_register__concat_utf16_276']?.() + __napiInstance.exports['__napi_register__concat_latin1_277']?.() + __napiInstance.exports['__napi_register__roundtrip_str_278']?.() + __napiInstance.exports['__napi_register__set_symbol_in_obj_279']?.() + __napiInstance.exports['__napi_register__create_symbol_280']?.() + __napiInstance.exports['__napi_register__create_symbol_for_281']?.() + __napiInstance.exports['__napi_register__DelaySum_impl_282']?.() + __napiInstance.exports['__napi_register__without_abort_controller_283']?.() + __napiInstance.exports['__napi_register__with_abort_controller_284']?.() + __napiInstance.exports['__napi_register__AsyncTaskVoidReturn_impl_285']?.() + __napiInstance.exports['__napi_register__async_task_void_return_286']?.() + __napiInstance.exports[ + '__napi_register__AsyncTaskOptionalReturn_impl_287' + ]?.() + __napiInstance.exports['__napi_register__async_task_optional_return_288']?.() + __napiInstance.exports['__napi_register__call_threadsafe_function_289']?.() + __napiInstance.exports[ + '__napi_register__call_long_threadsafe_function_290' ]?.() __napiInstance.exports[ - '__napi_register__threadsafe_function_throw_error_275' + '__napi_register__threadsafe_function_throw_error_291' ]?.() __napiInstance.exports[ - '__napi_register__threadsafe_function_fatal_mode_276' + '__napi_register__threadsafe_function_fatal_mode_292' ]?.() __napiInstance.exports[ - '__napi_register__threadsafe_function_fatal_mode_error_277' + '__napi_register__threadsafe_function_fatal_mode_error_293' ]?.() __napiInstance.exports[ - '__napi_register__threadsafe_function_closure_capture_278' + '__napi_register__threadsafe_function_closure_capture_294' ]?.() - __napiInstance.exports['__napi_register__tsfn_call_with_callback_279']?.() - __napiInstance.exports['__napi_register__tsfn_async_call_280']?.() - __napiInstance.exports['__napi_register__accept_threadsafe_function_281']?.() + __napiInstance.exports['__napi_register__tsfn_call_with_callback_295']?.() + __napiInstance.exports['__napi_register__tsfn_async_call_296']?.() + __napiInstance.exports['__napi_register__accept_threadsafe_function_297']?.() __napiInstance.exports[ - '__napi_register__accept_threadsafe_function_fatal_282' + '__napi_register__accept_threadsafe_function_fatal_298' ]?.() __napiInstance.exports[ - '__napi_register__accept_threadsafe_function_tuple_args_283' + '__napi_register__accept_threadsafe_function_tuple_args_299' ]?.() - __napiInstance.exports['__napi_register__tsfn_return_promise_284']?.() - __napiInstance.exports['__napi_register__tsfn_return_promise_timeout_285']?.() - __napiInstance.exports['__napi_register__tsfn_throw_from_js_286']?.() - __napiInstance.exports['__napi_register__get_buffer_287']?.() - __napiInstance.exports['__napi_register__append_buffer_288']?.() - __napiInstance.exports['__napi_register__get_empty_buffer_289']?.() - __napiInstance.exports['__napi_register__convert_u32_array_290']?.() - __napiInstance.exports['__napi_register__create_external_typed_array_291']?.() - __napiInstance.exports['__napi_register__mutate_typed_array_292']?.() - __napiInstance.exports['__napi_register__deref_uint8_array_293']?.() - __napiInstance.exports['__napi_register__buffer_pass_through_294']?.() - __napiInstance.exports['__napi_register__array_buffer_pass_through_295']?.() - __napiInstance.exports['__napi_register__AsyncBuffer_impl_296']?.() - __napiInstance.exports['__napi_register__async_reduce_buffer_297']?.() - __napiInstance.exports['__napi_register__async_buffer_to_array_298']?.() + __napiInstance.exports['__napi_register__tsfn_return_promise_300']?.() + __napiInstance.exports['__napi_register__tsfn_return_promise_timeout_301']?.() + __napiInstance.exports['__napi_register__tsfn_throw_from_js_302']?.() + __napiInstance.exports['__napi_register__get_buffer_303']?.() + __napiInstance.exports['__napi_register__append_buffer_304']?.() + __napiInstance.exports['__napi_register__get_empty_buffer_305']?.() + __napiInstance.exports['__napi_register__convert_u32_array_306']?.() + __napiInstance.exports['__napi_register__create_external_typed_array_307']?.() + __napiInstance.exports['__napi_register__mutate_typed_array_308']?.() + __napiInstance.exports['__napi_register__deref_uint8_array_309']?.() + __napiInstance.exports['__napi_register__buffer_pass_through_310']?.() + __napiInstance.exports['__napi_register__array_buffer_pass_through_311']?.() + __napiInstance.exports['__napi_register__accept_slice_312']?.() + __napiInstance.exports['__napi_register__u8_array_to_array_313']?.() + __napiInstance.exports['__napi_register__i8_array_to_array_314']?.() + __napiInstance.exports['__napi_register__u16_array_to_array_315']?.() + __napiInstance.exports['__napi_register__i16_array_to_array_316']?.() + __napiInstance.exports['__napi_register__u32_array_to_array_317']?.() + __napiInstance.exports['__napi_register__i32_array_to_array_318']?.() + __napiInstance.exports['__napi_register__f32_array_to_array_319']?.() + __napiInstance.exports['__napi_register__f64_array_to_array_320']?.() + __napiInstance.exports['__napi_register__u64_array_to_array_321']?.() + __napiInstance.exports['__napi_register__i64_array_to_array_322']?.() + __napiInstance.exports['__napi_register__accept_uint8_clamped_slice_323']?.() + __napiInstance.exports[ + '__napi_register__accept_uint8_clamped_slice_and_buffer_slice_324' + ]?.() + __napiInstance.exports['__napi_register__AsyncBuffer_impl_325']?.() + __napiInstance.exports['__napi_register__async_reduce_buffer_326']?.() + __napiInstance.exports['__napi_register__async_buffer_to_array_327']?.() } export const Animal = __napiModule.exports.Animal export const AnimalWithDefaultConstructor = @@ -372,6 +407,8 @@ export const CSSRuleList = __napiModule.exports.CSSRuleList export const CssStyleSheet = __napiModule.exports.CssStyleSheet export const CSSStyleSheet = __napiModule.exports.CSSStyleSheet export const CustomFinalize = __napiModule.exports.CustomFinalize +export const DefaultUseNullableClass = + __napiModule.exports.DefaultUseNullableClass export const Dog = __napiModule.exports.Dog export const Fib = __napiModule.exports.Fib export const Fib2 = __napiModule.exports.Fib2 @@ -382,16 +419,23 @@ export const JsClassForEither = __napiModule.exports.JsClassForEither export const JsRemote = __napiModule.exports.JsRemote export const JsRepo = __napiModule.exports.JsRepo export const NinjaTurtle = __napiModule.exports.NinjaTurtle +export const NotUseNullableClass = __napiModule.exports.NotUseNullableClass export const NotWritableClass = __napiModule.exports.NotWritableClass export const Optional = __napiModule.exports.Optional export const Selector = __napiModule.exports.Selector +export const UseNullableClass = __napiModule.exports.UseNullableClass export const Width = __napiModule.exports.Width +export const acceptSlice = __napiModule.exports.acceptSlice export const acceptThreadsafeFunction = __napiModule.exports.acceptThreadsafeFunction export const acceptThreadsafeFunctionFatal = __napiModule.exports.acceptThreadsafeFunctionFatal export const acceptThreadsafeFunctionTupleArgs = __napiModule.exports.acceptThreadsafeFunctionTupleArgs +export const acceptUint8ClampedSlice = + __napiModule.exports.acceptUint8ClampedSlice +export const acceptUint8ClampedSliceAndBufferSlice = + __napiModule.exports.acceptUint8ClampedSliceAndBufferSlice export const add = __napiModule.exports.add export const ALIAS = __napiModule.exports.ALIAS export const AliasedEnum = __napiModule.exports.AliasedEnum @@ -465,13 +509,17 @@ export const eitherFromOption = __napiModule.exports.eitherFromOption export const eitherStringOrNumber = __napiModule.exports.eitherStringOrNumber export const Empty = __napiModule.exports.Empty export const enumToI32 = __napiModule.exports.enumToI32 +export const f32ArrayToArray = __napiModule.exports.f32ArrayToArray +export const f64ArrayToArray = __napiModule.exports.f64ArrayToArray export const fibonacci = __napiModule.exports.fibonacci export const fnReceivedAliased = __napiModule.exports.fnReceivedAliased +export const getBtreeMapping = __napiModule.exports.getBtreeMapping export const getBuffer = __napiModule.exports.getBuffer export const getCwd = __napiModule.exports.getCwd export const getEmptyBuffer = __napiModule.exports.getEmptyBuffer export const getExternal = __napiModule.exports.getExternal export const getGlobal = __napiModule.exports.getGlobal +export const getIndexMapping = __napiModule.exports.getIndexMapping export const getMapping = __napiModule.exports.getMapping export const getModuleFileName = __napiModule.exports.getModuleFileName export const getNestedNumArr = __napiModule.exports.getNestedNumArr @@ -483,6 +531,11 @@ export const getStrFromObject = __napiModule.exports.getStrFromObject export const getterFromObj = __napiModule.exports.getterFromObj export const getUndefined = __napiModule.exports.getUndefined export const getWords = __napiModule.exports.getWords +export const i16ArrayToArray = __napiModule.exports.i16ArrayToArray +export const i32ArrayToArray = __napiModule.exports.i32ArrayToArray +export const i64ArrayToArray = __napiModule.exports.i64ArrayToArray +export const i8ArrayToArray = __napiModule.exports.i8ArrayToArray +export const indexmapPassthrough = __napiModule.exports.indexmapPassthrough export const Kind = __napiModule.exports.Kind export const listObjKeys = __napiModule.exports.listObjKeys export const mapOption = __napiModule.exports.mapOption @@ -529,6 +582,8 @@ export const roundtripStr = __napiModule.exports.roundtripStr export const runScript = __napiModule.exports.runScript export const setSymbolInObj = __napiModule.exports.setSymbolInObj export const Status = __napiModule.exports.Status +export const sumBtreeMapping = __napiModule.exports.sumBtreeMapping +export const sumIndexMapping = __napiModule.exports.sumIndexMapping export const sumMapping = __napiModule.exports.sumMapping export const sumNums = __napiModule.exports.sumNums export const testSerdeBigNumberPrecision = @@ -553,10 +608,15 @@ export const tsfnReturnPromiseTimeout = __napiModule.exports.tsfnReturnPromiseTimeout export const tsfnThrowFromJs = __napiModule.exports.tsfnThrowFromJs export const tsRename = __napiModule.exports.tsRename +export const u16ArrayToArray = __napiModule.exports.u16ArrayToArray +export const u32ArrayToArray = __napiModule.exports.u32ArrayToArray +export const u64ArrayToArray = __napiModule.exports.u64ArrayToArray +export const u8ArrayToArray = __napiModule.exports.u8ArrayToArray export const validateArray = __napiModule.exports.validateArray export const validateBigint = __napiModule.exports.validateBigint export const validateBoolean = __napiModule.exports.validateBoolean export const validateBuffer = __napiModule.exports.validateBuffer +export const validateBufferSlice = __napiModule.exports.validateBufferSlice export const validateDate = __napiModule.exports.validateDate export const validateDateTime = __napiModule.exports.validateDateTime export const validateExternal = __napiModule.exports.validateExternal @@ -569,6 +629,10 @@ export const validatePromise = __napiModule.exports.validatePromise export const validateString = __napiModule.exports.validateString export const validateSymbol = __napiModule.exports.validateSymbol export const validateTypedArray = __napiModule.exports.validateTypedArray +export const validateTypedArraySlice = + __napiModule.exports.validateTypedArraySlice +export const validateUint8ClampedSlice = + __napiModule.exports.validateUint8ClampedSlice export const validateUndefined = __napiModule.exports.validateUndefined export const withAbortController = __napiModule.exports.withAbortController export const withoutAbortController = diff --git a/examples/napi/index.wasi.cjs b/examples/napi/example.wasi.cjs similarity index 64% rename from examples/napi/index.wasi.cjs rename to examples/napi/example.wasi.cjs index 465698df..71b0610e 100644 --- a/examples/napi/index.wasi.cjs +++ b/examples/napi/example.wasi.cjs @@ -29,13 +29,13 @@ const __sharedMemory = new WebAssembly.Memory({ shared: true, }) -let __wasmFilePath = __nodePath.join(__dirname, 'index.wasm') +let __wasmFilePath = __nodePath.join(__dirname, 'example.wasm32-wasi.wasm') if (!__nodeFs.existsSync(__wasmFilePath)) { try { __wasmFilePath = __nodePath.resolve('@examples/napi-wasm32-wasi') } catch { - throw new Error('Cannot find index.wasm file, and @examples/napi-wasm32-wasi package is not installed.') + throw new Error('Cannot find example.wasm32-wasi.wasm file, and @examples/napi-wasm32-wasi package is not installed.') } } @@ -103,215 +103,242 @@ function __napi_rs_initialize_modules(__napiInstance) { __napiInstance.exports['__napi_register__Animal_impl_38']?.() __napiInstance.exports['__napi_register__Dog_struct_39']?.() __napiInstance.exports['__napi_register__Bird_struct_40']?.() - __napiInstance.exports['__napi_register__Bird_impl_44']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_struct_45']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_impl_47']?.() - __napiInstance.exports['__napi_register__Blake2bHasher_impl_49']?.() - __napiInstance.exports['__napi_register__Blake2bKey_struct_50']?.() - __napiInstance.exports['__napi_register__Context_struct_51']?.() - __napiInstance.exports['__napi_register__Context_impl_56']?.() - __napiInstance.exports['__napi_register__AnimalWithDefaultConstructor_struct_57']?.() - __napiInstance.exports['__napi_register__NinjaTurtle_struct_58']?.() - __napiInstance.exports['__napi_register__NinjaTurtle_impl_65']?.() - __napiInstance.exports['__napi_register__JsAssets_struct_66']?.() - __napiInstance.exports['__napi_register__JsAssets_impl_69']?.() - __napiInstance.exports['__napi_register__JsAsset_struct_70']?.() - __napiInstance.exports['__napi_register__JsAsset_impl_73']?.() - __napiInstance.exports['__napi_register__Optional_struct_74']?.() - __napiInstance.exports['__napi_register__Optional_impl_79']?.() - __napiInstance.exports['__napi_register__ObjectFieldClassInstance_struct_80']?.() - __napiInstance.exports['__napi_register__create_object_with_class_field_81']?.() - __napiInstance.exports['__napi_register__receive_object_with_class_field_82']?.() - __napiInstance.exports['__napi_register__NotWritableClass_struct_83']?.() - __napiInstance.exports['__napi_register__NotWritableClass_impl_85']?.() - __napiInstance.exports['__napi_register__CustomFinalize_struct_86']?.() - __napiInstance.exports['__napi_register__CustomFinalize_impl_88']?.() - __napiInstance.exports['__napi_register__Width_struct_89']?.() - __napiInstance.exports['__napi_register__plus_one_90']?.() - __napiInstance.exports['__napi_register__GetterSetterWithClosures_struct_91']?.() - __napiInstance.exports['__napi_register__GetterSetterWithClosures_impl_93']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor_struct_94']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor_impl_96']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor2_struct_97']?.() - __napiInstance.exports['__napi_register__CatchOnConstructor2_impl_99']?.() - __napiInstance.exports['__napi_register__ClassWithFactory_struct_100']?.() - __napiInstance.exports['__napi_register__ClassWithFactory_impl_105']?.() - __napiInstance.exports['__napi_register__Selector_struct_106']?.() - __napiInstance.exports['__napi_register__date_to_number_107']?.() - __napiInstance.exports['__napi_register__chrono_date_to_millis_108']?.() - __napiInstance.exports['__napi_register__chrono_date_add_1_minute_109']?.() - __napiInstance.exports['__napi_register__Dates_struct_110']?.() - __napiInstance.exports['__napi_register__chrono_native_date_time_111']?.() - __napiInstance.exports['__napi_register__chrono_native_date_time_return_112']?.() - __napiInstance.exports['__napi_register__either_string_or_number_113']?.() - __napiInstance.exports['__napi_register__return_either_114']?.() - __napiInstance.exports['__napi_register__either3_115']?.() - __napiInstance.exports['__napi_register__Obj_struct_116']?.() - __napiInstance.exports['__napi_register__either4_117']?.() - __napiInstance.exports['__napi_register__JsClassForEither_struct_118']?.() - __napiInstance.exports['__napi_register__JsClassForEither_impl_120']?.() - __napiInstance.exports['__napi_register__AnotherClassForEither_struct_121']?.() - __napiInstance.exports['__napi_register__AnotherClassForEither_impl_123']?.() - __napiInstance.exports['__napi_register__receive_class_or_number_124']?.() - __napiInstance.exports['__napi_register__receive_mut_class_or_number_125']?.() - __napiInstance.exports['__napi_register__receive_different_class_126']?.() - __napiInstance.exports['__napi_register__return_either_class_127']?.() - __napiInstance.exports['__napi_register__either_from_option_128']?.() - __napiInstance.exports['__napi_register__A_struct_129']?.() - __napiInstance.exports['__napi_register__B_struct_130']?.() - __napiInstance.exports['__napi_register__C_struct_131']?.() - __napiInstance.exports['__napi_register__either_from_objects_132']?.() - __napiInstance.exports['__napi_register__either_bool_or_function_133']?.() - __napiInstance.exports['__napi_register__promise_in_either_134']?.() - __napiInstance.exports['__napi_register__Kind_135']?.() - __napiInstance.exports['__napi_register__Empty_136']?.() - __napiInstance.exports['__napi_register__Status_137']?.() - __napiInstance.exports['__napi_register__CustomNumEnum_138']?.() - __napiInstance.exports['__napi_register__enum_to_i32_139']?.() - __napiInstance.exports['__napi_register__SkippedEnums_140']?.() - __napiInstance.exports['__napi_register__run_script_141']?.() - __napiInstance.exports['__napi_register__get_module_file_name_142']?.() - __napiInstance.exports['__napi_register__throw_syntax_error_143']?.() - __napiInstance.exports['__napi_register__throw_error_144']?.() - __napiInstance.exports['__napi_register__panic_145']?.() - __napiInstance.exports['__napi_register__receive_string_146']?.() - __napiInstance.exports['__napi_register__custom_status_code_147']?.() - __napiInstance.exports['__napi_register__throw_async_error_148']?.() - __napiInstance.exports['__napi_register__create_external_149']?.() - __napiInstance.exports['__napi_register__create_external_string_150']?.() - __napiInstance.exports['__napi_register__get_external_151']?.() - __napiInstance.exports['__napi_register__mutate_external_152']?.() - __napiInstance.exports['__napi_register__validate_array_153']?.() - __napiInstance.exports['__napi_register__validate_buffer_154']?.() - __napiInstance.exports['__napi_register__validate_typed_array_155']?.() - __napiInstance.exports['__napi_register__validate_bigint_156']?.() - __napiInstance.exports['__napi_register__validate_boolean_157']?.() - __napiInstance.exports['__napi_register__validate_date_158']?.() - __napiInstance.exports['__napi_register__validate_date_time_159']?.() - __napiInstance.exports['__napi_register__validate_external_160']?.() - __napiInstance.exports['__napi_register__validate_function_161']?.() - __napiInstance.exports['__napi_register__validate_hash_map_162']?.() - __napiInstance.exports['__napi_register__validate_null_163']?.() - __napiInstance.exports['__napi_register__validate_undefined_164']?.() - __napiInstance.exports['__napi_register__validate_number_165']?.() - __napiInstance.exports['__napi_register__validate_promise_166']?.() - __napiInstance.exports['__napi_register__validate_string_167']?.() - __napiInstance.exports['__napi_register__validate_symbol_168']?.() - __napiInstance.exports['__napi_register__validate_optional_169']?.() - __napiInstance.exports['__napi_register__return_undefined_if_invalid_170']?.() - __napiInstance.exports['__napi_register__return_undefined_if_invalid_promise_171']?.() - __napiInstance.exports['__napi_register__ts_rename_172']?.() - __napiInstance.exports['__napi_register__override_individual_arg_on_function_173']?.() - __napiInstance.exports['__napi_register__override_individual_arg_on_function_with_cb_arg_174']?.() - __napiInstance.exports['__napi_register__call0_175']?.() - __napiInstance.exports['__napi_register__call1_176']?.() - __napiInstance.exports['__napi_register__call2_177']?.() - __napiInstance.exports['__napi_register__apply0_178']?.() - __napiInstance.exports['__napi_register__apply1_179']?.() - __napiInstance.exports['__napi_register__call_function_180']?.() - __napiInstance.exports['__napi_register__call_function_with_arg_181']?.() - __napiInstance.exports['__napi_register__create_reference_on_function_182']?.() - __napiInstance.exports['__napi_register__call_function_with_arg_and_ctx_183']?.() - __napiInstance.exports['__napi_register__reference_as_callback_184']?.() - __napiInstance.exports['__napi_register__Fib_struct_185']?.() - __napiInstance.exports['__napi_register__Fib_impl_186']?.() - __napiInstance.exports['__napi_register__Fib_impl_188']?.() - __napiInstance.exports['__napi_register__Fib2_struct_189']?.() - __napiInstance.exports['__napi_register__Fib2_impl_190']?.() - __napiInstance.exports['__napi_register__Fib2_impl_192']?.() - __napiInstance.exports['__napi_register__Fib3_struct_193']?.() - __napiInstance.exports['__napi_register__Fib3_impl_194']?.() - __napiInstance.exports['__napi_register__ALIGNMENT_195']?.() - __napiInstance.exports['__napi_register__xxh64_196']?.() - __napiInstance.exports['__napi_register__xxh128_197']?.() - __napiInstance.exports['__napi_register__Xxh3_struct_198']?.() - __napiInstance.exports['__napi_register__Xxh3_impl_202']?.() - __napiInstance.exports['__napi_register__xxh2_plus_203']?.() - __napiInstance.exports['__napi_register__xxh3_xxh64_alias_204']?.() - __napiInstance.exports['__napi_register__xxh64_alias_205']?.() - __napiInstance.exports['__napi_register__get_mapping_206']?.() - __napiInstance.exports['__napi_register__sum_mapping_207']?.() - __napiInstance.exports['__napi_register__map_option_208']?.() - __napiInstance.exports['__napi_register__return_null_209']?.() - __napiInstance.exports['__napi_register__return_undefined_210']?.() - __napiInstance.exports['__napi_register__add_211']?.() - __napiInstance.exports['__napi_register__fibonacci_212']?.() - __napiInstance.exports['__napi_register__list_obj_keys_213']?.() - __napiInstance.exports['__napi_register__create_obj_214']?.() - __napiInstance.exports['__napi_register__get_global_215']?.() - __napiInstance.exports['__napi_register__get_undefined_216']?.() - __napiInstance.exports['__napi_register__get_null_217']?.() - __napiInstance.exports['__napi_register__AllOptionalObject_struct_218']?.() - __napiInstance.exports['__napi_register__receive_all_optional_object_219']?.() - __napiInstance.exports['__napi_register__AliasedEnum_220']?.() - __napiInstance.exports['__napi_register__StructContainsAliasedEnum_struct_221']?.() - __napiInstance.exports['__napi_register__fn_received_aliased_222']?.() - __napiInstance.exports['__napi_register__StrictObject_struct_223']?.() - __napiInstance.exports['__napi_register__receive_strict_object_224']?.() - __napiInstance.exports['__napi_register__get_str_from_object_225']?.() - __napiInstance.exports['__napi_register__TsTypeChanged_struct_226']?.() - __napiInstance.exports['__napi_register__create_obj_with_property_227']?.() - __napiInstance.exports['__napi_register__getter_from_obj_228']?.() - __napiInstance.exports['__napi_register__ObjectOnlyFromJs_struct_229']?.() - __napiInstance.exports['__napi_register__receive_object_only_from_js_230']?.() - __napiInstance.exports['__napi_register__async_plus_100_231']?.() - __napiInstance.exports['__napi_register__JsRepo_struct_232']?.() - __napiInstance.exports['__napi_register__JsRepo_impl_235']?.() - __napiInstance.exports['__napi_register__JsRemote_struct_236']?.() - __napiInstance.exports['__napi_register__JsRemote_impl_238']?.() - __napiInstance.exports['__napi_register__CSSRuleList_struct_239']?.() - __napiInstance.exports['__napi_register__CSSRuleList_impl_243']?.() - __napiInstance.exports['__napi_register__CSSStyleSheet_struct_244']?.() - __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_struct_245']?.() - __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_impl_247']?.() - __napiInstance.exports['__napi_register__CSSStyleSheet_impl_251']?.() - __napiInstance.exports['__napi_register__PackageJson_struct_252']?.() - __napiInstance.exports['__napi_register__read_package_json_253']?.() - __napiInstance.exports['__napi_register__get_package_json_name_254']?.() - __napiInstance.exports['__napi_register__test_serde_roundtrip_255']?.() - __napiInstance.exports['__napi_register__test_serde_big_number_precision_256']?.() - __napiInstance.exports['__napi_register__return_from_shared_crate_257']?.() - __napiInstance.exports['__napi_register__contains_258']?.() - __napiInstance.exports['__napi_register__concat_str_259']?.() - __napiInstance.exports['__napi_register__concat_utf16_260']?.() - __napiInstance.exports['__napi_register__concat_latin1_261']?.() - __napiInstance.exports['__napi_register__roundtrip_str_262']?.() - __napiInstance.exports['__napi_register__set_symbol_in_obj_263']?.() - __napiInstance.exports['__napi_register__create_symbol_264']?.() - __napiInstance.exports['__napi_register__create_symbol_for_265']?.() - __napiInstance.exports['__napi_register__DelaySum_impl_266']?.() - __napiInstance.exports['__napi_register__without_abort_controller_267']?.() - __napiInstance.exports['__napi_register__with_abort_controller_268']?.() - __napiInstance.exports['__napi_register__AsyncTaskVoidReturn_impl_269']?.() - __napiInstance.exports['__napi_register__async_task_void_return_270']?.() - __napiInstance.exports['__napi_register__AsyncTaskOptionalReturn_impl_271']?.() - __napiInstance.exports['__napi_register__async_task_optional_return_272']?.() - __napiInstance.exports['__napi_register__call_threadsafe_function_273']?.() - __napiInstance.exports['__napi_register__call_long_threadsafe_function_274']?.() - __napiInstance.exports['__napi_register__threadsafe_function_throw_error_275']?.() - __napiInstance.exports['__napi_register__threadsafe_function_fatal_mode_276']?.() - __napiInstance.exports['__napi_register__threadsafe_function_fatal_mode_error_277']?.() - __napiInstance.exports['__napi_register__threadsafe_function_closure_capture_278']?.() - __napiInstance.exports['__napi_register__tsfn_call_with_callback_279']?.() - __napiInstance.exports['__napi_register__tsfn_async_call_280']?.() - __napiInstance.exports['__napi_register__accept_threadsafe_function_281']?.() - __napiInstance.exports['__napi_register__accept_threadsafe_function_fatal_282']?.() - __napiInstance.exports['__napi_register__accept_threadsafe_function_tuple_args_283']?.() - __napiInstance.exports['__napi_register__tsfn_return_promise_284']?.() - __napiInstance.exports['__napi_register__tsfn_return_promise_timeout_285']?.() - __napiInstance.exports['__napi_register__tsfn_throw_from_js_286']?.() - __napiInstance.exports['__napi_register__get_buffer_287']?.() - __napiInstance.exports['__napi_register__append_buffer_288']?.() - __napiInstance.exports['__napi_register__get_empty_buffer_289']?.() - __napiInstance.exports['__napi_register__convert_u32_array_290']?.() - __napiInstance.exports['__napi_register__create_external_typed_array_291']?.() - __napiInstance.exports['__napi_register__mutate_typed_array_292']?.() - __napiInstance.exports['__napi_register__deref_uint8_array_293']?.() - __napiInstance.exports['__napi_register__buffer_pass_through_294']?.() - __napiInstance.exports['__napi_register__array_buffer_pass_through_295']?.() - __napiInstance.exports['__napi_register__AsyncBuffer_impl_296']?.() - __napiInstance.exports['__napi_register__async_reduce_buffer_297']?.() - __napiInstance.exports['__napi_register__async_buffer_to_array_298']?.() + __napiInstance.exports['__napi_register__Bird_impl_45']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_struct_46']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_impl_48']?.() + __napiInstance.exports['__napi_register__Blake2bHasher_impl_50']?.() + __napiInstance.exports['__napi_register__Blake2bKey_struct_51']?.() + __napiInstance.exports['__napi_register__Context_struct_52']?.() + __napiInstance.exports['__napi_register__Context_impl_57']?.() + __napiInstance.exports['__napi_register__AnimalWithDefaultConstructor_struct_58']?.() + __napiInstance.exports['__napi_register__NinjaTurtle_struct_59']?.() + __napiInstance.exports['__napi_register__NinjaTurtle_impl_66']?.() + __napiInstance.exports['__napi_register__JsAssets_struct_67']?.() + __napiInstance.exports['__napi_register__JsAssets_impl_70']?.() + __napiInstance.exports['__napi_register__JsAsset_struct_71']?.() + __napiInstance.exports['__napi_register__JsAsset_impl_74']?.() + __napiInstance.exports['__napi_register__Optional_struct_75']?.() + __napiInstance.exports['__napi_register__Optional_impl_80']?.() + __napiInstance.exports['__napi_register__ObjectFieldClassInstance_struct_81']?.() + __napiInstance.exports['__napi_register__create_object_with_class_field_82']?.() + __napiInstance.exports['__napi_register__receive_object_with_class_field_83']?.() + __napiInstance.exports['__napi_register__NotWritableClass_struct_84']?.() + __napiInstance.exports['__napi_register__NotWritableClass_impl_86']?.() + __napiInstance.exports['__napi_register__CustomFinalize_struct_87']?.() + __napiInstance.exports['__napi_register__CustomFinalize_impl_89']?.() + __napiInstance.exports['__napi_register__Width_struct_90']?.() + __napiInstance.exports['__napi_register__plus_one_91']?.() + __napiInstance.exports['__napi_register__GetterSetterWithClosures_struct_92']?.() + __napiInstance.exports['__napi_register__GetterSetterWithClosures_impl_94']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor_struct_95']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor_impl_97']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor2_struct_98']?.() + __napiInstance.exports['__napi_register__CatchOnConstructor2_impl_100']?.() + __napiInstance.exports['__napi_register__ClassWithFactory_struct_101']?.() + __napiInstance.exports['__napi_register__ClassWithFactory_impl_106']?.() + __napiInstance.exports['__napi_register__Selector_struct_107']?.() + __napiInstance.exports['__napi_register__date_to_number_108']?.() + __napiInstance.exports['__napi_register__chrono_date_to_millis_109']?.() + __napiInstance.exports['__napi_register__chrono_date_add_1_minute_110']?.() + __napiInstance.exports['__napi_register__Dates_struct_111']?.() + __napiInstance.exports['__napi_register__chrono_native_date_time_112']?.() + __napiInstance.exports['__napi_register__chrono_native_date_time_return_113']?.() + __napiInstance.exports['__napi_register__either_string_or_number_114']?.() + __napiInstance.exports['__napi_register__return_either_115']?.() + __napiInstance.exports['__napi_register__either3_116']?.() + __napiInstance.exports['__napi_register__Obj_struct_117']?.() + __napiInstance.exports['__napi_register__either4_118']?.() + __napiInstance.exports['__napi_register__JsClassForEither_struct_119']?.() + __napiInstance.exports['__napi_register__JsClassForEither_impl_121']?.() + __napiInstance.exports['__napi_register__AnotherClassForEither_struct_122']?.() + __napiInstance.exports['__napi_register__AnotherClassForEither_impl_124']?.() + __napiInstance.exports['__napi_register__receive_class_or_number_125']?.() + __napiInstance.exports['__napi_register__receive_mut_class_or_number_126']?.() + __napiInstance.exports['__napi_register__receive_different_class_127']?.() + __napiInstance.exports['__napi_register__return_either_class_128']?.() + __napiInstance.exports['__napi_register__either_from_option_129']?.() + __napiInstance.exports['__napi_register__A_struct_130']?.() + __napiInstance.exports['__napi_register__B_struct_131']?.() + __napiInstance.exports['__napi_register__C_struct_132']?.() + __napiInstance.exports['__napi_register__either_from_objects_133']?.() + __napiInstance.exports['__napi_register__either_bool_or_function_134']?.() + __napiInstance.exports['__napi_register__promise_in_either_135']?.() + __napiInstance.exports['__napi_register__Kind_136']?.() + __napiInstance.exports['__napi_register__Empty_137']?.() + __napiInstance.exports['__napi_register__Status_138']?.() + __napiInstance.exports['__napi_register__CustomNumEnum_139']?.() + __napiInstance.exports['__napi_register__enum_to_i32_140']?.() + __napiInstance.exports['__napi_register__SkippedEnums_141']?.() + __napiInstance.exports['__napi_register__run_script_142']?.() + __napiInstance.exports['__napi_register__get_module_file_name_143']?.() + __napiInstance.exports['__napi_register__throw_syntax_error_144']?.() + __napiInstance.exports['__napi_register__throw_error_145']?.() + __napiInstance.exports['__napi_register__panic_146']?.() + __napiInstance.exports['__napi_register__receive_string_147']?.() + __napiInstance.exports['__napi_register__custom_status_code_148']?.() + __napiInstance.exports['__napi_register__throw_async_error_149']?.() + __napiInstance.exports['__napi_register__create_external_150']?.() + __napiInstance.exports['__napi_register__create_external_string_151']?.() + __napiInstance.exports['__napi_register__get_external_152']?.() + __napiInstance.exports['__napi_register__mutate_external_153']?.() + __napiInstance.exports['__napi_register__validate_array_154']?.() + __napiInstance.exports['__napi_register__validate_buffer_155']?.() + __napiInstance.exports['__napi_register__validate_typed_array_156']?.() + __napiInstance.exports['__napi_register__validate_typed_array_slice_157']?.() + __napiInstance.exports['__napi_register__validate_uint8_clamped_slice_158']?.() + __napiInstance.exports['__napi_register__validate_buffer_slice_159']?.() + __napiInstance.exports['__napi_register__validate_bigint_160']?.() + __napiInstance.exports['__napi_register__validate_boolean_161']?.() + __napiInstance.exports['__napi_register__validate_date_162']?.() + __napiInstance.exports['__napi_register__validate_date_time_163']?.() + __napiInstance.exports['__napi_register__validate_external_164']?.() + __napiInstance.exports['__napi_register__validate_function_165']?.() + __napiInstance.exports['__napi_register__validate_hash_map_166']?.() + __napiInstance.exports['__napi_register__validate_null_167']?.() + __napiInstance.exports['__napi_register__validate_undefined_168']?.() + __napiInstance.exports['__napi_register__validate_number_169']?.() + __napiInstance.exports['__napi_register__validate_promise_170']?.() + __napiInstance.exports['__napi_register__validate_string_171']?.() + __napiInstance.exports['__napi_register__validate_symbol_172']?.() + __napiInstance.exports['__napi_register__validate_optional_173']?.() + __napiInstance.exports['__napi_register__return_undefined_if_invalid_174']?.() + __napiInstance.exports['__napi_register__return_undefined_if_invalid_promise_175']?.() + __napiInstance.exports['__napi_register__ts_rename_176']?.() + __napiInstance.exports['__napi_register__override_individual_arg_on_function_177']?.() + __napiInstance.exports['__napi_register__override_individual_arg_on_function_with_cb_arg_178']?.() + __napiInstance.exports['__napi_register__call0_179']?.() + __napiInstance.exports['__napi_register__call1_180']?.() + __napiInstance.exports['__napi_register__call2_181']?.() + __napiInstance.exports['__napi_register__apply0_182']?.() + __napiInstance.exports['__napi_register__apply1_183']?.() + __napiInstance.exports['__napi_register__call_function_184']?.() + __napiInstance.exports['__napi_register__call_function_with_arg_185']?.() + __napiInstance.exports['__napi_register__create_reference_on_function_186']?.() + __napiInstance.exports['__napi_register__call_function_with_arg_and_ctx_187']?.() + __napiInstance.exports['__napi_register__reference_as_callback_188']?.() + __napiInstance.exports['__napi_register__Fib_struct_189']?.() + __napiInstance.exports['__napi_register__Fib_impl_190']?.() + __napiInstance.exports['__napi_register__Fib_impl_192']?.() + __napiInstance.exports['__napi_register__Fib2_struct_193']?.() + __napiInstance.exports['__napi_register__Fib2_impl_194']?.() + __napiInstance.exports['__napi_register__Fib2_impl_196']?.() + __napiInstance.exports['__napi_register__Fib3_struct_197']?.() + __napiInstance.exports['__napi_register__Fib3_impl_198']?.() + __napiInstance.exports['__napi_register__ALIGNMENT_199']?.() + __napiInstance.exports['__napi_register__xxh64_200']?.() + __napiInstance.exports['__napi_register__xxh128_201']?.() + __napiInstance.exports['__napi_register__Xxh3_struct_202']?.() + __napiInstance.exports['__napi_register__Xxh3_impl_206']?.() + __napiInstance.exports['__napi_register__xxh2_plus_207']?.() + __napiInstance.exports['__napi_register__xxh3_xxh64_alias_208']?.() + __napiInstance.exports['__napi_register__xxh64_alias_209']?.() + __napiInstance.exports['__napi_register__get_mapping_210']?.() + __napiInstance.exports['__napi_register__sum_mapping_211']?.() + __napiInstance.exports['__napi_register__get_btree_mapping_212']?.() + __napiInstance.exports['__napi_register__sum_btree_mapping_213']?.() + __napiInstance.exports['__napi_register__get_index_mapping_214']?.() + __napiInstance.exports['__napi_register__sum_index_mapping_215']?.() + __napiInstance.exports['__napi_register__indexmap_passthrough_216']?.() + __napiInstance.exports['__napi_register__map_option_217']?.() + __napiInstance.exports['__napi_register__return_null_218']?.() + __napiInstance.exports['__napi_register__return_undefined_219']?.() + __napiInstance.exports['__napi_register__UseNullableStruct_struct_220']?.() + __napiInstance.exports['__napi_register__NotUseNullableStruct_struct_221']?.() + __napiInstance.exports['__napi_register__DefaultUseNullableStruct_struct_222']?.() + __napiInstance.exports['__napi_register__UseNullableClass_struct_223']?.() + __napiInstance.exports['__napi_register__NotUseNullableClass_struct_224']?.() + __napiInstance.exports['__napi_register__DefaultUseNullableClass_struct_225']?.() + __napiInstance.exports['__napi_register__add_226']?.() + __napiInstance.exports['__napi_register__fibonacci_227']?.() + __napiInstance.exports['__napi_register__list_obj_keys_228']?.() + __napiInstance.exports['__napi_register__create_obj_229']?.() + __napiInstance.exports['__napi_register__get_global_230']?.() + __napiInstance.exports['__napi_register__get_undefined_231']?.() + __napiInstance.exports['__napi_register__get_null_232']?.() + __napiInstance.exports['__napi_register__AllOptionalObject_struct_233']?.() + __napiInstance.exports['__napi_register__receive_all_optional_object_234']?.() + __napiInstance.exports['__napi_register__AliasedEnum_235']?.() + __napiInstance.exports['__napi_register__StructContainsAliasedEnum_struct_236']?.() + __napiInstance.exports['__napi_register__fn_received_aliased_237']?.() + __napiInstance.exports['__napi_register__StrictObject_struct_238']?.() + __napiInstance.exports['__napi_register__receive_strict_object_239']?.() + __napiInstance.exports['__napi_register__get_str_from_object_240']?.() + __napiInstance.exports['__napi_register__TsTypeChanged_struct_241']?.() + __napiInstance.exports['__napi_register__create_obj_with_property_242']?.() + __napiInstance.exports['__napi_register__getter_from_obj_243']?.() + __napiInstance.exports['__napi_register__ObjectOnlyFromJs_struct_244']?.() + __napiInstance.exports['__napi_register__receive_object_only_from_js_245']?.() + __napiInstance.exports['__napi_register__async_plus_100_246']?.() + __napiInstance.exports['__napi_register__JsRepo_struct_247']?.() + __napiInstance.exports['__napi_register__JsRepo_impl_250']?.() + __napiInstance.exports['__napi_register__JsRemote_struct_251']?.() + __napiInstance.exports['__napi_register__JsRemote_impl_254']?.() + __napiInstance.exports['__napi_register__CSSRuleList_struct_255']?.() + __napiInstance.exports['__napi_register__CSSRuleList_impl_259']?.() + __napiInstance.exports['__napi_register__CSSStyleSheet_struct_260']?.() + __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_struct_261']?.() + __napiInstance.exports['__napi_register__AnotherCSSStyleSheet_impl_263']?.() + __napiInstance.exports['__napi_register__CSSStyleSheet_impl_267']?.() + __napiInstance.exports['__napi_register__PackageJson_struct_268']?.() + __napiInstance.exports['__napi_register__read_package_json_269']?.() + __napiInstance.exports['__napi_register__get_package_json_name_270']?.() + __napiInstance.exports['__napi_register__test_serde_roundtrip_271']?.() + __napiInstance.exports['__napi_register__test_serde_big_number_precision_272']?.() + __napiInstance.exports['__napi_register__return_from_shared_crate_273']?.() + __napiInstance.exports['__napi_register__contains_274']?.() + __napiInstance.exports['__napi_register__concat_str_275']?.() + __napiInstance.exports['__napi_register__concat_utf16_276']?.() + __napiInstance.exports['__napi_register__concat_latin1_277']?.() + __napiInstance.exports['__napi_register__roundtrip_str_278']?.() + __napiInstance.exports['__napi_register__set_symbol_in_obj_279']?.() + __napiInstance.exports['__napi_register__create_symbol_280']?.() + __napiInstance.exports['__napi_register__create_symbol_for_281']?.() + __napiInstance.exports['__napi_register__DelaySum_impl_282']?.() + __napiInstance.exports['__napi_register__without_abort_controller_283']?.() + __napiInstance.exports['__napi_register__with_abort_controller_284']?.() + __napiInstance.exports['__napi_register__AsyncTaskVoidReturn_impl_285']?.() + __napiInstance.exports['__napi_register__async_task_void_return_286']?.() + __napiInstance.exports['__napi_register__AsyncTaskOptionalReturn_impl_287']?.() + __napiInstance.exports['__napi_register__async_task_optional_return_288']?.() + __napiInstance.exports['__napi_register__call_threadsafe_function_289']?.() + __napiInstance.exports['__napi_register__call_long_threadsafe_function_290']?.() + __napiInstance.exports['__napi_register__threadsafe_function_throw_error_291']?.() + __napiInstance.exports['__napi_register__threadsafe_function_fatal_mode_292']?.() + __napiInstance.exports['__napi_register__threadsafe_function_fatal_mode_error_293']?.() + __napiInstance.exports['__napi_register__threadsafe_function_closure_capture_294']?.() + __napiInstance.exports['__napi_register__tsfn_call_with_callback_295']?.() + __napiInstance.exports['__napi_register__tsfn_async_call_296']?.() + __napiInstance.exports['__napi_register__accept_threadsafe_function_297']?.() + __napiInstance.exports['__napi_register__accept_threadsafe_function_fatal_298']?.() + __napiInstance.exports['__napi_register__accept_threadsafe_function_tuple_args_299']?.() + __napiInstance.exports['__napi_register__tsfn_return_promise_300']?.() + __napiInstance.exports['__napi_register__tsfn_return_promise_timeout_301']?.() + __napiInstance.exports['__napi_register__tsfn_throw_from_js_302']?.() + __napiInstance.exports['__napi_register__get_buffer_303']?.() + __napiInstance.exports['__napi_register__append_buffer_304']?.() + __napiInstance.exports['__napi_register__get_empty_buffer_305']?.() + __napiInstance.exports['__napi_register__convert_u32_array_306']?.() + __napiInstance.exports['__napi_register__create_external_typed_array_307']?.() + __napiInstance.exports['__napi_register__mutate_typed_array_308']?.() + __napiInstance.exports['__napi_register__deref_uint8_array_309']?.() + __napiInstance.exports['__napi_register__buffer_pass_through_310']?.() + __napiInstance.exports['__napi_register__array_buffer_pass_through_311']?.() + __napiInstance.exports['__napi_register__accept_slice_312']?.() + __napiInstance.exports['__napi_register__u8_array_to_array_313']?.() + __napiInstance.exports['__napi_register__i8_array_to_array_314']?.() + __napiInstance.exports['__napi_register__u16_array_to_array_315']?.() + __napiInstance.exports['__napi_register__i16_array_to_array_316']?.() + __napiInstance.exports['__napi_register__u32_array_to_array_317']?.() + __napiInstance.exports['__napi_register__i32_array_to_array_318']?.() + __napiInstance.exports['__napi_register__f32_array_to_array_319']?.() + __napiInstance.exports['__napi_register__f64_array_to_array_320']?.() + __napiInstance.exports['__napi_register__u64_array_to_array_321']?.() + __napiInstance.exports['__napi_register__i64_array_to_array_322']?.() + __napiInstance.exports['__napi_register__accept_uint8_clamped_slice_323']?.() + __napiInstance.exports['__napi_register__accept_uint8_clamped_slice_and_buffer_slice_324']?.() + __napiInstance.exports['__napi_register__AsyncBuffer_impl_325']?.() + __napiInstance.exports['__napi_register__async_reduce_buffer_326']?.() + __napiInstance.exports['__napi_register__async_buffer_to_array_327']?.() } module.exports.Animal = __napiModule.exports.Animal module.exports.AnimalWithDefaultConstructor = __napiModule.exports.AnimalWithDefaultConstructor @@ -336,6 +363,7 @@ module.exports.CSSRuleList = __napiModule.exports.CSSRuleList module.exports.CssStyleSheet = __napiModule.exports.CssStyleSheet module.exports.CSSStyleSheet = __napiModule.exports.CSSStyleSheet module.exports.CustomFinalize = __napiModule.exports.CustomFinalize +module.exports.DefaultUseNullableClass = __napiModule.exports.DefaultUseNullableClass module.exports.Dog = __napiModule.exports.Dog module.exports.Fib = __napiModule.exports.Fib module.exports.Fib2 = __napiModule.exports.Fib2 @@ -345,13 +373,18 @@ module.exports.JsClassForEither = __napiModule.exports.JsClassForEither module.exports.JsRemote = __napiModule.exports.JsRemote module.exports.JsRepo = __napiModule.exports.JsRepo module.exports.NinjaTurtle = __napiModule.exports.NinjaTurtle +module.exports.NotUseNullableClass = __napiModule.exports.NotUseNullableClass module.exports.NotWritableClass = __napiModule.exports.NotWritableClass module.exports.Optional = __napiModule.exports.Optional module.exports.Selector = __napiModule.exports.Selector +module.exports.UseNullableClass = __napiModule.exports.UseNullableClass module.exports.Width = __napiModule.exports.Width +module.exports.acceptSlice = __napiModule.exports.acceptSlice module.exports.acceptThreadsafeFunction = __napiModule.exports.acceptThreadsafeFunction module.exports.acceptThreadsafeFunctionFatal = __napiModule.exports.acceptThreadsafeFunctionFatal module.exports.acceptThreadsafeFunctionTupleArgs = __napiModule.exports.acceptThreadsafeFunctionTupleArgs +module.exports.acceptUint8ClampedSlice = __napiModule.exports.acceptUint8ClampedSlice +module.exports.acceptUint8ClampedSliceAndBufferSlice = __napiModule.exports.acceptUint8ClampedSliceAndBufferSlice module.exports.add = __napiModule.exports.add module.exports.ALIAS = __napiModule.exports.ALIAS module.exports.AliasedEnum = __napiModule.exports.AliasedEnum @@ -414,13 +447,17 @@ module.exports.eitherFromOption = __napiModule.exports.eitherFromOption module.exports.eitherStringOrNumber = __napiModule.exports.eitherStringOrNumber module.exports.Empty = __napiModule.exports.Empty module.exports.enumToI32 = __napiModule.exports.enumToI32 +module.exports.f32ArrayToArray = __napiModule.exports.f32ArrayToArray +module.exports.f64ArrayToArray = __napiModule.exports.f64ArrayToArray module.exports.fibonacci = __napiModule.exports.fibonacci module.exports.fnReceivedAliased = __napiModule.exports.fnReceivedAliased +module.exports.getBtreeMapping = __napiModule.exports.getBtreeMapping module.exports.getBuffer = __napiModule.exports.getBuffer module.exports.getCwd = __napiModule.exports.getCwd module.exports.getEmptyBuffer = __napiModule.exports.getEmptyBuffer module.exports.getExternal = __napiModule.exports.getExternal module.exports.getGlobal = __napiModule.exports.getGlobal +module.exports.getIndexMapping = __napiModule.exports.getIndexMapping module.exports.getMapping = __napiModule.exports.getMapping module.exports.getModuleFileName = __napiModule.exports.getModuleFileName module.exports.getNestedNumArr = __napiModule.exports.getNestedNumArr @@ -432,6 +469,11 @@ module.exports.getStrFromObject = __napiModule.exports.getStrFromObject module.exports.getterFromObj = __napiModule.exports.getterFromObj module.exports.getUndefined = __napiModule.exports.getUndefined module.exports.getWords = __napiModule.exports.getWords +module.exports.i16ArrayToArray = __napiModule.exports.i16ArrayToArray +module.exports.i32ArrayToArray = __napiModule.exports.i32ArrayToArray +module.exports.i64ArrayToArray = __napiModule.exports.i64ArrayToArray +module.exports.i8ArrayToArray = __napiModule.exports.i8ArrayToArray +module.exports.indexmapPassthrough = __napiModule.exports.indexmapPassthrough module.exports.Kind = __napiModule.exports.Kind module.exports.listObjKeys = __napiModule.exports.listObjKeys module.exports.mapOption = __napiModule.exports.mapOption @@ -470,6 +512,8 @@ module.exports.roundtripStr = __napiModule.exports.roundtripStr module.exports.runScript = __napiModule.exports.runScript module.exports.setSymbolInObj = __napiModule.exports.setSymbolInObj module.exports.Status = __napiModule.exports.Status +module.exports.sumBtreeMapping = __napiModule.exports.sumBtreeMapping +module.exports.sumIndexMapping = __napiModule.exports.sumIndexMapping module.exports.sumMapping = __napiModule.exports.sumMapping module.exports.sumNums = __napiModule.exports.sumNums module.exports.testSerdeBigNumberPrecision = __napiModule.exports.testSerdeBigNumberPrecision @@ -488,10 +532,15 @@ module.exports.tsfnReturnPromise = __napiModule.exports.tsfnReturnPromise module.exports.tsfnReturnPromiseTimeout = __napiModule.exports.tsfnReturnPromiseTimeout module.exports.tsfnThrowFromJs = __napiModule.exports.tsfnThrowFromJs module.exports.tsRename = __napiModule.exports.tsRename +module.exports.u16ArrayToArray = __napiModule.exports.u16ArrayToArray +module.exports.u32ArrayToArray = __napiModule.exports.u32ArrayToArray +module.exports.u64ArrayToArray = __napiModule.exports.u64ArrayToArray +module.exports.u8ArrayToArray = __napiModule.exports.u8ArrayToArray module.exports.validateArray = __napiModule.exports.validateArray module.exports.validateBigint = __napiModule.exports.validateBigint module.exports.validateBoolean = __napiModule.exports.validateBoolean module.exports.validateBuffer = __napiModule.exports.validateBuffer +module.exports.validateBufferSlice = __napiModule.exports.validateBufferSlice module.exports.validateDate = __napiModule.exports.validateDate module.exports.validateDateTime = __napiModule.exports.validateDateTime module.exports.validateExternal = __napiModule.exports.validateExternal @@ -504,6 +553,8 @@ module.exports.validatePromise = __napiModule.exports.validatePromise module.exports.validateString = __napiModule.exports.validateString module.exports.validateSymbol = __napiModule.exports.validateSymbol module.exports.validateTypedArray = __napiModule.exports.validateTypedArray +module.exports.validateTypedArraySlice = __napiModule.exports.validateTypedArraySlice +module.exports.validateUint8ClampedSlice = __napiModule.exports.validateUint8ClampedSlice module.exports.validateUndefined = __napiModule.exports.validateUndefined module.exports.withAbortController = __napiModule.exports.withAbortController module.exports.withoutAbortController = __napiModule.exports.withoutAbortController diff --git a/examples/napi/index.cjs b/examples/napi/index.cjs new file mode 100644 index 00000000..a90e361e --- /dev/null +++ b/examples/napi/index.cjs @@ -0,0 +1,560 @@ +// prettier-ignore +/* eslint-disable */ +/* auto-generated by NAPI-RS */ + +const { existsSync, readFileSync } = require('fs') +const { join } = require('path') + +let nativeBinding = null +let localFileExisted = false +let loadErrors = [] + +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)) { + return true + } + } + 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 + } +} + +function requireNative() { + if (process.platform === 'android') { + if (process.arch === 'arm64') { + try { + return require('./example.android-arm64.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-android-arm64') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'arm') { + try { + return require('./example.android-arm-eabi.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-android-arm-eabi') + } catch (e) { + loadErrors.push(e) + } + + } else { + loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)) + } + } else if (process.platform === 'win32') { + if (process.arch === 'x64') { + try { + return require('./example.win32-x64-msvc.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-win32-x64-msvc') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'ia32') { + try { + return require('./example.win32-ia32-msvc.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-win32-ia32-msvc') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'arm64') { + try { + return require('./example.win32-arm64-msvc.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-win32-arm64-msvc') + } catch (e) { + loadErrors.push(e) + } + + } else { + loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)) + } + } else if (process.platform === 'darwin') { + try { + return require('./example.darwin-universal.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-darwin-universal') + } catch (e) { + loadErrors.push(e) + } + + if (process.arch === 'x64') { + try { + return require('./example.darwin-x64.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-darwin-x64') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'arm64') { + try { + return require('./example.darwin-arm64.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-darwin-arm64') + } catch (e) { + loadErrors.push(e) + } + + } else { + loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)) + } + } else if (process.platform === 'freebsd') { + if (process.arch === 'x64') { + try { + return require('./example.freebsd-x64.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-freebsd-x64') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'arm64') { + try { + return require('./example.freebsd-arm64.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-freebsd-arm64') + } catch (e) { + loadErrors.push(e) + } + + } else { + loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)) + } + } else if (process.platform === 'linux') { + if (process.arch === 'x64') { + if (isMusl()) { + try { + return require('./example.linux-x64-musl.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-x64-musl') + } catch (e) { + loadErrors.push(e) + } + + } else { + try { + return require('./example.linux-x64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-x64-gnu') + } catch (e) { + loadErrors.push(e) + } + + } + } else if (process.arch === 'arm64') { + if (isMusl()) { + try { + return require('./example.linux-arm64-musl.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-arm64-musl') + } catch (e) { + loadErrors.push(e) + } + + } else { + try { + return require('./example.linux-arm64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-arm64-gnu') + } catch (e) { + loadErrors.push(e) + } + + } + } else if (process.arch === 'arm') { + try { + return require('./example.linux-arm-gnueabihf.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-arm-gnueabihf') + } catch (e) { + loadErrors.push(e) + } + + } else if (process.arch === 'riscv64') { + if (isMusl()) { + try { + return require('./example.linux-riscv64-musl.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-riscv64-musl') + } catch (e) { + loadErrors.push(e) + } + + } else { + try { + return require('./example.linux-riscv64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-riscv64-gnu') + } catch (e) { + loadErrors.push(e) + } + + } + } else if (process.arch === 's390x') { + try { + return require('./example.linux-s390x-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + return require('@examples/napi-linux-s390x-gnu') + } catch (e) { + loadErrors.push(e) + } + + } else { + loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)) + } + } else { + loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`)) + } +} + +nativeBinding = requireNative() + +if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { + try { + nativeBinding = require('./example.wasi.cjs') + } catch (err) { + if (process.env.NAPI_RS_FORCE_WASI) { + console.error(err) + } + } + if (!nativeBinding) { + try { + nativeBinding = require('@examples/napi-wasm32-wasi') + } catch (err) { + if (process.env.NAPI_RS_FORCE_WASI) { + console.error(err) + } + } + } +} + +if (!nativeBinding) { + if (loadErrors.length > 0) { + // TODO Link to documentation with potential fixes + // - The package owner could build/publish bindings for this arch + // - The user may need to bundle the correct files + // - The user may need to re-install node_modules to get new packages + throw new Error('Failed to load native binding', { cause: loadErrors }) + } + throw new Error(`Failed to load native binding`) +} + +module.exports.Animal = nativeBinding.Animal +module.exports.AnimalWithDefaultConstructor = nativeBinding.AnimalWithDefaultConstructor +module.exports.AnotherClassForEither = nativeBinding.AnotherClassForEither +module.exports.AnotherCssStyleSheet = nativeBinding.AnotherCssStyleSheet +module.exports.AnotherCSSStyleSheet = nativeBinding.AnotherCSSStyleSheet +module.exports.Asset = nativeBinding.Asset +module.exports.JsAsset = nativeBinding.JsAsset +module.exports.Assets = nativeBinding.Assets +module.exports.JsAssets = nativeBinding.JsAssets +module.exports.Bird = nativeBinding.Bird +module.exports.Blake2BHasher = nativeBinding.Blake2BHasher +module.exports.Blake2bHasher = nativeBinding.Blake2bHasher +module.exports.Blake2BKey = nativeBinding.Blake2BKey +module.exports.Blake2bKey = nativeBinding.Blake2bKey +module.exports.CatchOnConstructor = nativeBinding.CatchOnConstructor +module.exports.CatchOnConstructor2 = nativeBinding.CatchOnConstructor2 +module.exports.ClassWithFactory = nativeBinding.ClassWithFactory +module.exports.Context = nativeBinding.Context +module.exports.CssRuleList = nativeBinding.CssRuleList +module.exports.CSSRuleList = nativeBinding.CSSRuleList +module.exports.CssStyleSheet = nativeBinding.CssStyleSheet +module.exports.CSSStyleSheet = nativeBinding.CSSStyleSheet +module.exports.CustomFinalize = nativeBinding.CustomFinalize +module.exports.DefaultUseNullableClass = nativeBinding.DefaultUseNullableClass +module.exports.Dog = nativeBinding.Dog +module.exports.Fib = nativeBinding.Fib +module.exports.Fib2 = nativeBinding.Fib2 +module.exports.Fib3 = nativeBinding.Fib3 +module.exports.GetterSetterWithClosures = nativeBinding.GetterSetterWithClosures +module.exports.JsClassForEither = nativeBinding.JsClassForEither +module.exports.JsRemote = nativeBinding.JsRemote +module.exports.JsRepo = nativeBinding.JsRepo +module.exports.NinjaTurtle = nativeBinding.NinjaTurtle +module.exports.NotUseNullableClass = nativeBinding.NotUseNullableClass +module.exports.NotWritableClass = nativeBinding.NotWritableClass +module.exports.Optional = nativeBinding.Optional +module.exports.Selector = nativeBinding.Selector +module.exports.UseNullableClass = nativeBinding.UseNullableClass +module.exports.Width = nativeBinding.Width +module.exports.acceptSlice = nativeBinding.acceptSlice +module.exports.acceptThreadsafeFunction = nativeBinding.acceptThreadsafeFunction +module.exports.acceptThreadsafeFunctionFatal = nativeBinding.acceptThreadsafeFunctionFatal +module.exports.acceptThreadsafeFunctionTupleArgs = nativeBinding.acceptThreadsafeFunctionTupleArgs +module.exports.acceptUint8ClampedSlice = nativeBinding.acceptUint8ClampedSlice +module.exports.acceptUint8ClampedSliceAndBufferSlice = nativeBinding.acceptUint8ClampedSliceAndBufferSlice +module.exports.add = nativeBinding.add +module.exports.ALIAS = nativeBinding.ALIAS +module.exports.AliasedEnum = nativeBinding.AliasedEnum +module.exports.appendBuffer = nativeBinding.appendBuffer +module.exports.apply0 = nativeBinding.apply0 +module.exports.apply1 = nativeBinding.apply1 +module.exports.arrayBufferPassThrough = nativeBinding.arrayBufferPassThrough +module.exports.asyncBufferToArray = nativeBinding.asyncBufferToArray +module.exports.asyncMultiTwo = nativeBinding.asyncMultiTwo +module.exports.asyncPlus100 = nativeBinding.asyncPlus100 +module.exports.asyncReduceBuffer = nativeBinding.asyncReduceBuffer +module.exports.asyncTaskOptionalReturn = nativeBinding.asyncTaskOptionalReturn +module.exports.asyncTaskVoidReturn = nativeBinding.asyncTaskVoidReturn +module.exports.bigintAdd = nativeBinding.bigintAdd +module.exports.bigintFromI128 = nativeBinding.bigintFromI128 +module.exports.bigintFromI64 = nativeBinding.bigintFromI64 +module.exports.bigintGetU64AsString = nativeBinding.bigintGetU64AsString +module.exports.bufferPassThrough = nativeBinding.bufferPassThrough +module.exports.call0 = nativeBinding.call0 +module.exports.call1 = nativeBinding.call1 +module.exports.call2 = nativeBinding.call2 +module.exports.callbackReturnPromise = nativeBinding.callbackReturnPromise +module.exports.callbackReturnPromiseAndSpawn = nativeBinding.callbackReturnPromiseAndSpawn +module.exports.callFunction = nativeBinding.callFunction +module.exports.callFunctionWithArg = nativeBinding.callFunctionWithArg +module.exports.callFunctionWithArgAndCtx = nativeBinding.callFunctionWithArgAndCtx +module.exports.callLongThreadsafeFunction = nativeBinding.callLongThreadsafeFunction +module.exports.callThreadsafeFunction = nativeBinding.callThreadsafeFunction +module.exports.captureErrorInCallback = nativeBinding.captureErrorInCallback +module.exports.chronoDateAdd1Minute = nativeBinding.chronoDateAdd1Minute +module.exports.chronoDateToMillis = nativeBinding.chronoDateToMillis +module.exports.chronoNativeDateTime = nativeBinding.chronoNativeDateTime +module.exports.chronoNativeDateTimeReturn = nativeBinding.chronoNativeDateTimeReturn +module.exports.concatLatin1 = nativeBinding.concatLatin1 +module.exports.concatStr = nativeBinding.concatStr +module.exports.concatUtf16 = nativeBinding.concatUtf16 +module.exports.contains = nativeBinding.contains +module.exports.convertU32Array = nativeBinding.convertU32Array +module.exports.createBigInt = nativeBinding.createBigInt +module.exports.createBigIntI64 = nativeBinding.createBigIntI64 +module.exports.createExternal = nativeBinding.createExternal +module.exports.createExternalString = nativeBinding.createExternalString +module.exports.createExternalTypedArray = nativeBinding.createExternalTypedArray +module.exports.createObj = nativeBinding.createObj +module.exports.createObjectWithClassField = nativeBinding.createObjectWithClassField +module.exports.createObjWithProperty = nativeBinding.createObjWithProperty +module.exports.createReferenceOnFunction = nativeBinding.createReferenceOnFunction +module.exports.createSymbol = nativeBinding.createSymbol +module.exports.createSymbolFor = nativeBinding.createSymbolFor +module.exports.CustomNumEnum = nativeBinding.CustomNumEnum +module.exports.customStatusCode = nativeBinding.customStatusCode +module.exports.dateToNumber = nativeBinding.dateToNumber +module.exports.DEFAULT_COST = nativeBinding.DEFAULT_COST +module.exports.derefUint8Array = nativeBinding.derefUint8Array +module.exports.either3 = nativeBinding.either3 +module.exports.either4 = nativeBinding.either4 +module.exports.eitherBoolOrFunction = nativeBinding.eitherBoolOrFunction +module.exports.eitherFromObjects = nativeBinding.eitherFromObjects +module.exports.eitherFromOption = nativeBinding.eitherFromOption +module.exports.eitherStringOrNumber = nativeBinding.eitherStringOrNumber +module.exports.Empty = nativeBinding.Empty +module.exports.enumToI32 = nativeBinding.enumToI32 +module.exports.f32ArrayToArray = nativeBinding.f32ArrayToArray +module.exports.f64ArrayToArray = nativeBinding.f64ArrayToArray +module.exports.fibonacci = nativeBinding.fibonacci +module.exports.fnReceivedAliased = nativeBinding.fnReceivedAliased +module.exports.getBtreeMapping = nativeBinding.getBtreeMapping +module.exports.getBuffer = nativeBinding.getBuffer +module.exports.getCwd = nativeBinding.getCwd +module.exports.getEmptyBuffer = nativeBinding.getEmptyBuffer +module.exports.getExternal = nativeBinding.getExternal +module.exports.getGlobal = nativeBinding.getGlobal +module.exports.getIndexMapping = nativeBinding.getIndexMapping +module.exports.getMapping = nativeBinding.getMapping +module.exports.getModuleFileName = nativeBinding.getModuleFileName +module.exports.getNestedNumArr = nativeBinding.getNestedNumArr +module.exports.getNull = nativeBinding.getNull +module.exports.getNumArr = nativeBinding.getNumArr +module.exports.getNums = nativeBinding.getNums +module.exports.getPackageJsonName = nativeBinding.getPackageJsonName +module.exports.getStrFromObject = nativeBinding.getStrFromObject +module.exports.getterFromObj = nativeBinding.getterFromObj +module.exports.getUndefined = nativeBinding.getUndefined +module.exports.getWords = nativeBinding.getWords +module.exports.i16ArrayToArray = nativeBinding.i16ArrayToArray +module.exports.i32ArrayToArray = nativeBinding.i32ArrayToArray +module.exports.i64ArrayToArray = nativeBinding.i64ArrayToArray +module.exports.i8ArrayToArray = nativeBinding.i8ArrayToArray +module.exports.indexmapPassthrough = nativeBinding.indexmapPassthrough +module.exports.Kind = nativeBinding.Kind +module.exports.listObjKeys = nativeBinding.listObjKeys +module.exports.mapOption = nativeBinding.mapOption +module.exports.mutateExternal = nativeBinding.mutateExternal +module.exports.mutateTypedArray = nativeBinding.mutateTypedArray +module.exports.optionEnd = nativeBinding.optionEnd +module.exports.optionOnly = nativeBinding.optionOnly +module.exports.optionStart = nativeBinding.optionStart +module.exports.optionStartEnd = nativeBinding.optionStartEnd +module.exports.overrideIndividualArgOnFunction = nativeBinding.overrideIndividualArgOnFunction +module.exports.overrideIndividualArgOnFunctionWithCbArg = nativeBinding.overrideIndividualArgOnFunctionWithCbArg +module.exports.panic = nativeBinding.panic +module.exports.plusOne = nativeBinding.plusOne +module.exports.promiseInEither = nativeBinding.promiseInEither +module.exports.readFile = nativeBinding.readFile +module.exports.readFileAsync = nativeBinding.readFileAsync +module.exports.readPackageJson = nativeBinding.readPackageJson +module.exports.receiveAllOptionalObject = nativeBinding.receiveAllOptionalObject +module.exports.receiveClassOrNumber = nativeBinding.receiveClassOrNumber +module.exports.receiveDifferentClass = nativeBinding.receiveDifferentClass +module.exports.receiveMutClassOrNumber = nativeBinding.receiveMutClassOrNumber +module.exports.receiveObjectOnlyFromJs = nativeBinding.receiveObjectOnlyFromJs +module.exports.receiveObjectWithClassField = nativeBinding.receiveObjectWithClassField +module.exports.receiveStrictObject = nativeBinding.receiveStrictObject +module.exports.receiveString = nativeBinding.receiveString +module.exports.referenceAsCallback = nativeBinding.referenceAsCallback +module.exports.returnEither = nativeBinding.returnEither +module.exports.returnEitherClass = nativeBinding.returnEitherClass +module.exports.returnFromSharedCrate = nativeBinding.returnFromSharedCrate +module.exports.returnJsFunction = nativeBinding.returnJsFunction +module.exports.returnNull = nativeBinding.returnNull +module.exports.returnUndefined = nativeBinding.returnUndefined +module.exports.returnUndefinedIfInvalid = nativeBinding.returnUndefinedIfInvalid +module.exports.returnUndefinedIfInvalidPromise = nativeBinding.returnUndefinedIfInvalidPromise +module.exports.roundtripStr = nativeBinding.roundtripStr +module.exports.runScript = nativeBinding.runScript +module.exports.setSymbolInObj = nativeBinding.setSymbolInObj +module.exports.Status = nativeBinding.Status +module.exports.sumBtreeMapping = nativeBinding.sumBtreeMapping +module.exports.sumIndexMapping = nativeBinding.sumIndexMapping +module.exports.sumMapping = nativeBinding.sumMapping +module.exports.sumNums = nativeBinding.sumNums +module.exports.testSerdeBigNumberPrecision = nativeBinding.testSerdeBigNumberPrecision +module.exports.testSerdeRoundtrip = nativeBinding.testSerdeRoundtrip +module.exports.threadsafeFunctionClosureCapture = nativeBinding.threadsafeFunctionClosureCapture +module.exports.threadsafeFunctionFatalMode = nativeBinding.threadsafeFunctionFatalMode +module.exports.threadsafeFunctionFatalModeError = nativeBinding.threadsafeFunctionFatalModeError +module.exports.threadsafeFunctionThrowError = nativeBinding.threadsafeFunctionThrowError +module.exports.throwAsyncError = nativeBinding.throwAsyncError +module.exports.throwError = nativeBinding.throwError +module.exports.throwSyntaxError = nativeBinding.throwSyntaxError +module.exports.toJsObj = nativeBinding.toJsObj +module.exports.tsfnAsyncCall = nativeBinding.tsfnAsyncCall +module.exports.tsfnCallWithCallback = nativeBinding.tsfnCallWithCallback +module.exports.tsfnReturnPromise = nativeBinding.tsfnReturnPromise +module.exports.tsfnReturnPromiseTimeout = nativeBinding.tsfnReturnPromiseTimeout +module.exports.tsfnThrowFromJs = nativeBinding.tsfnThrowFromJs +module.exports.tsRename = nativeBinding.tsRename +module.exports.u16ArrayToArray = nativeBinding.u16ArrayToArray +module.exports.u32ArrayToArray = nativeBinding.u32ArrayToArray +module.exports.u64ArrayToArray = nativeBinding.u64ArrayToArray +module.exports.u8ArrayToArray = nativeBinding.u8ArrayToArray +module.exports.validateArray = nativeBinding.validateArray +module.exports.validateBigint = nativeBinding.validateBigint +module.exports.validateBoolean = nativeBinding.validateBoolean +module.exports.validateBuffer = nativeBinding.validateBuffer +module.exports.validateBufferSlice = nativeBinding.validateBufferSlice +module.exports.validateDate = nativeBinding.validateDate +module.exports.validateDateTime = nativeBinding.validateDateTime +module.exports.validateExternal = nativeBinding.validateExternal +module.exports.validateFunction = nativeBinding.validateFunction +module.exports.validateHashMap = nativeBinding.validateHashMap +module.exports.validateNull = nativeBinding.validateNull +module.exports.validateNumber = nativeBinding.validateNumber +module.exports.validateOptional = nativeBinding.validateOptional +module.exports.validatePromise = nativeBinding.validatePromise +module.exports.validateString = nativeBinding.validateString +module.exports.validateSymbol = nativeBinding.validateSymbol +module.exports.validateTypedArray = nativeBinding.validateTypedArray +module.exports.validateTypedArraySlice = nativeBinding.validateTypedArraySlice +module.exports.validateUint8ClampedSlice = nativeBinding.validateUint8ClampedSlice +module.exports.validateUndefined = nativeBinding.validateUndefined +module.exports.withAbortController = nativeBinding.withAbortController +module.exports.withoutAbortController = nativeBinding.withoutAbortController +module.exports.xxh64Alias = nativeBinding.xxh64Alias +module.exports.xxh2 = nativeBinding.xxh2 +module.exports.xxh3 = nativeBinding.xxh3 diff --git a/examples/napi/index.d.ts b/examples/napi/index.d.cts similarity index 99% rename from examples/napi/index.d.ts rename to examples/napi/index.d.cts index 15894b04..215487f3 100644 --- a/examples/napi/index.d.ts +++ b/examples/napi/index.d.cts @@ -360,7 +360,7 @@ export function createObjectWithClassField(): ObjectFieldClassInstance export function createObjWithProperty(): { value: ArrayBuffer, get getter(): number } -export function createReferenceOnFunction(cb: () => void): object +export function createReferenceOnFunction(cb: () => void): Promise export function createSymbol(): symbol diff --git a/examples/napi/index.js b/examples/napi/index.js deleted file mode 100644 index 70c88ab4..00000000 --- a/examples/napi/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import { createRequire } from 'node:module' - -const require = createRequire(import.meta.url) - -let exports - -if (process.env.WASI_TEST) { - exports = require('./index.wasi.cjs') -} else { - exports = require('./index.node') -} - -export default exports diff --git a/examples/napi/package.json b/examples/napi/package.json index 38316e77..098f9a69 100644 --- a/examples/napi/package.json +++ b/examples/napi/package.json @@ -7,11 +7,15 @@ "types": "./index.d.ts", "scripts": { "browser": "vite", - "build": "napi-raw build", + "build": "napi-raw build --platform --js index.cjs --dts index.d.cts", "test": "cross-env TS_NODE_PROJECT=./tsconfig.json node --es-module-specifier-resolution=node --loader ts-node/esm/transpile-only --experimental-wasi-unstable-preview1 ../../node_modules/ava/entrypoints/cli.mjs" }, + "napi": { + "binaryName": "example" + }, "devDependencies": { "@napi-rs/cli": "workspace:*", + "@napi-rs/triples": "workspace:*", "@napi-rs/wasm-runtime": "workspace:*", "@types/lodash": "^4.14.202", "@vitest/browser": "^1.2.2", @@ -39,9 +43,6 @@ "timeout": "10m" }, "dependencies": { - "@emnapi/core": "1.0.0", - "@types/lodash": "^4.14.202", - "lodash": "^4.17.21", - "sinon": "^17.0.1" + "@emnapi/core": "1.0.0" } } diff --git a/examples/napi/src/function.rs b/examples/napi/src/function.rs index f4b46198..f456a425 100644 --- a/examples/napi/src/function.rs +++ b/examples/napi/src/function.rs @@ -40,7 +40,7 @@ pub fn call_function_with_arg(cb: Function<(u32, u32), u32>, arg0: u32, arg1: u3 cb.call((arg0, arg1)) } -#[napi] +#[napi(ts_return_type = "Promise")] pub fn create_reference_on_function(env: Env, cb: Function<(), ()>) -> Result { let reference = cb.create_ref()?; env.execute_tokio_future( diff --git a/yarn.lock b/yarn.lock index 9d5704e4..e7afc976 100644 --- a/yarn.lock +++ b/yarn.lock @@ -524,6 +524,7 @@ __metadata: dependencies: "@emnapi/core": "npm:1.0.0" "@napi-rs/cli": "workspace:*" + "@napi-rs/triples": "workspace:*" "@napi-rs/wasm-runtime": "workspace:*" "@types/lodash": "npm:^4.14.202" "@vitest/browser": "npm:^1.2.2" @@ -1092,7 +1093,7 @@ __metadata: languageName: node linkType: hard -"@napi-rs/triples@workspace:triples": +"@napi-rs/triples@workspace:*, @napi-rs/triples@workspace:triples": version: 0.0.0-use.local resolution: "@napi-rs/triples@workspace:triples" dependencies: