|
| 1 | +/* eslint-disable */ |
| 2 | +/* prettier-ignore */ |
| 3 | + |
| 4 | +/* auto-generated by NAPI-RS */ |
| 5 | + |
| 6 | +const __nodeFs = require('node:fs') |
| 7 | +const __nodePath = require('node:path') |
| 8 | +const { WASI: __nodeWASI } = require('node:wasi') |
| 9 | +const { Worker } = require('node:worker_threads') |
| 10 | + |
| 11 | +const { |
| 12 | + createOnMessage: __wasmCreateOnMessageForFsProxy, |
| 13 | + getDefaultContext: __emnapiGetDefaultContext, |
| 14 | + instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync, |
| 15 | +} = require('@napi-rs/wasm-runtime') |
| 16 | + |
| 17 | +const __rootDir = __nodePath.parse(process.cwd()).root |
| 18 | + |
| 19 | +const __wasi = new __nodeWASI({ |
| 20 | + version: 'preview1', |
| 21 | + env: process.env, |
| 22 | + preopens: { |
| 23 | + [__rootDir]: __rootDir, |
| 24 | + } |
| 25 | +}) |
| 26 | + |
| 27 | +const __emnapiContext = __emnapiGetDefaultContext() |
| 28 | + |
| 29 | +const __sharedMemory = new WebAssembly.Memory({ |
| 30 | + initial: 4000, |
| 31 | + maximum: 65536, |
| 32 | + shared: true, |
| 33 | +}) |
| 34 | + |
| 35 | +let __wasmFilePath = __nodePath.join(__dirname, 'influxdb3-napi.wasm32-wasi.wasm') |
| 36 | +const __wasmDebugFilePath = __nodePath.join(__dirname, 'influxdb3-napi.wasm32-wasi.debug.wasm') |
| 37 | + |
| 38 | +if (__nodeFs.existsSync(__wasmDebugFilePath)) { |
| 39 | + __wasmFilePath = __wasmDebugFilePath |
| 40 | +} else if (!__nodeFs.existsSync(__wasmFilePath)) { |
| 41 | + try { |
| 42 | + __wasmFilePath = __nodePath.resolve('@badmachine/influxdb3-napi-wasm32-wasi') |
| 43 | + } catch { |
| 44 | + throw new Error('Cannot find influxdb3-napi.wasm32-wasi.wasm file, and @badmachine/influxdb3-napi-wasm32-wasi package is not installed.') |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), { |
| 49 | + context: __emnapiContext, |
| 50 | + asyncWorkPoolSize: (function() { |
| 51 | + const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE) |
| 52 | + // NaN > 0 is false |
| 53 | + if (threadsSizeFromEnv > 0) { |
| 54 | + return threadsSizeFromEnv |
| 55 | + } else { |
| 56 | + return 4 |
| 57 | + } |
| 58 | + })(), |
| 59 | + reuseWorker: true, |
| 60 | + wasi: __wasi, |
| 61 | + onCreateWorker() { |
| 62 | + const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), { |
| 63 | + env: process.env, |
| 64 | + }) |
| 65 | + worker.onmessage = ({ data }) => { |
| 66 | + __wasmCreateOnMessageForFsProxy(__nodeFs)(data) |
| 67 | + } |
| 68 | + |
| 69 | + // The main thread of Node.js waits for all the active handles before exiting. |
| 70 | + // But Rust threads are never waited without `thread::join`. |
| 71 | + // So here we hack the code of Node.js to prevent the workers from being referenced (active). |
| 72 | + // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415, |
| 73 | + // a worker is consist of two handles: kPublicPort and kHandle. |
| 74 | + { |
| 75 | + const kPublicPort = Object.getOwnPropertySymbols(worker).find(s => |
| 76 | + s.toString().includes("kPublicPort") |
| 77 | + ); |
| 78 | + if (kPublicPort) { |
| 79 | + worker[kPublicPort].ref = () => {}; |
| 80 | + } |
| 81 | + |
| 82 | + const kHandle = Object.getOwnPropertySymbols(worker).find(s => |
| 83 | + s.toString().includes("kHandle") |
| 84 | + ); |
| 85 | + if (kHandle) { |
| 86 | + worker[kHandle].ref = () => {}; |
| 87 | + } |
| 88 | + |
| 89 | + worker.unref(); |
| 90 | + } |
| 91 | + return worker |
| 92 | + }, |
| 93 | + overwriteImports(importObject) { |
| 94 | + importObject.env = { |
| 95 | + ...importObject.env, |
| 96 | + ...importObject.napi, |
| 97 | + ...importObject.emnapi, |
| 98 | + memory: __sharedMemory, |
| 99 | + } |
| 100 | + return importObject |
| 101 | + }, |
| 102 | + beforeInit({ instance }) { |
| 103 | + for (const name of Object.keys(instance.exports)) { |
| 104 | + if (name.startsWith('__napi_register__')) { |
| 105 | + instance.exports[name]() |
| 106 | + } |
| 107 | + } |
| 108 | + }, |
| 109 | +}) |
| 110 | +module.exports = __napiModule.exports |
| 111 | +module.exports.InfluxDbClient = __napiModule.exports.InfluxDbClient |
| 112 | +module.exports.InfluxDBClient = __napiModule.exports.InfluxDBClient |
| 113 | +module.exports.Point = __napiModule.exports.Point |
| 114 | +module.exports.PointValues = __napiModule.exports.PointValues |
| 115 | +module.exports.PointFieldType = __napiModule.exports.PointFieldType |
| 116 | +module.exports.QueryType = __napiModule.exports.QueryType |
| 117 | +module.exports.Serializer = __napiModule.exports.Serializer |
| 118 | +module.exports.TimeUnitV2 = __napiModule.exports.TimeUnitV2 |
| 119 | +module.exports.TimeUnitV3 = __napiModule.exports.TimeUnitV3 |
0 commit comments