mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-10 11:44:22 +01:00
hack imports of wasm due to the issues in Vite and Next.js build systems
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
import {
|
||||
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
||||
getDefaultContext as __emnapiGetDefaultContext,
|
||||
instantiateNapiModule as __emnapiInstantiateNapiModule,
|
||||
WASI as __WASI,
|
||||
instantiateNapiModuleSync,
|
||||
MessageHandler
|
||||
} from '@tursodatabase/wasm-runtime'
|
||||
|
||||
function getUint8ArrayFromMemory(memory: WebAssembly.Memory, ptr: number, len: number): Uint8Array {
|
||||
ptr = ptr >>> 0;
|
||||
return new Uint8Array(memory.buffer).subarray(ptr, ptr + len);
|
||||
@@ -197,7 +206,7 @@ class OpfsDirectory {
|
||||
}
|
||||
}
|
||||
|
||||
var workerRequestId = 0;
|
||||
let workerRequestId = 0;
|
||||
function waitForWorkerResponse(worker: Worker, id: number): Promise<any> {
|
||||
let waitResolve, waitReject;
|
||||
const callback = msg => {
|
||||
@@ -236,4 +245,103 @@ function unregisterFileAtWorker(worker: Worker, path: string): Promise<void> {
|
||||
return promise;
|
||||
}
|
||||
|
||||
export { OpfsDirectory, workerImports, MainDummyImports, waitForWorkerResponse, registerFileAtWorker, unregisterFileAtWorker }
|
||||
function isWebWorker(): boolean {
|
||||
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
||||
}
|
||||
|
||||
function setupWebWorker() {
|
||||
let opfs = new OpfsDirectory();
|
||||
let memory = null;
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
memory = wasmMemory;
|
||||
const wasi = new __WASI({
|
||||
print: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
printErr: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
wasi,
|
||||
overwriteImports(importObject) {
|
||||
importObject.env = {
|
||||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
...workerImports(opfs, memory),
|
||||
memory: wasmMemory,
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
globalThis.onmessage = async function (e) {
|
||||
if (e.data.__turso__ == 'register') {
|
||||
try {
|
||||
await opfs.registerFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
} else if (e.data.__turso__ == 'unregister') {
|
||||
try {
|
||||
await opfs.unregisterFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
}
|
||||
handler.handle(e)
|
||||
}
|
||||
}
|
||||
|
||||
async function setupMainThread(wasmFile: ArrayBuffer, factory: () => Worker): Promise<any> {
|
||||
const __emnapiContext = __emnapiGetDefaultContext()
|
||||
const __wasi = new __WASI({
|
||||
version: 'preview1',
|
||||
})
|
||||
const __sharedMemory = new WebAssembly.Memory({
|
||||
initial: 4000,
|
||||
maximum: 65536,
|
||||
shared: true,
|
||||
})
|
||||
const {
|
||||
instance: __napiInstance,
|
||||
module: __wasiModule,
|
||||
napiModule: __napiModule,
|
||||
} = await __emnapiInstantiateNapiModule(wasmFile, {
|
||||
context: __emnapiContext,
|
||||
asyncWorkPoolSize: 1,
|
||||
wasi: __wasi,
|
||||
onCreateWorker() { return factory() },
|
||||
overwriteImports(importObject) {
|
||||
importObject.env = {
|
||||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
...MainDummyImports,
|
||||
memory: __sharedMemory,
|
||||
}
|
||||
return importObject
|
||||
},
|
||||
beforeInit({ instance }) {
|
||||
for (const name of Object.keys(instance.exports)) {
|
||||
if (name.startsWith('__napi_register__')) {
|
||||
instance.exports[name]()
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
return __napiModule;
|
||||
}
|
||||
|
||||
export { OpfsDirectory, workerImports, MainDummyImports, waitForWorkerResponse, registerFileAtWorker, unregisterFileAtWorker, isWebWorker, setupWebWorker, setupMainThread }
|
||||
@@ -21,5 +21,8 @@
|
||||
"tsc-build": "npm exec tsc",
|
||||
"build": "npm run tsc-build",
|
||||
"test": "echo 'no tests'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tursodatabase/wasm-runtime": "^0.2.0-pre.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"module": "esnext",
|
||||
"module": "nodenext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "nodenext",
|
||||
"outDir": "dist/",
|
||||
"lib": [
|
||||
"es2020",
|
||||
|
||||
22
bindings/javascript/packages/browser/index-default.ts
Normal file
22
bindings/javascript/packages/browser/index-default.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { setupMainThread } from "@tursodatabase/database-browser-common";
|
||||
|
||||
const __wasmUrl = new URL('./turso.wasm32-wasi.wasm', import.meta.url).href;
|
||||
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
|
||||
export let MainWorker = null;
|
||||
const napiModule = await setupMainThread(__wasmFile, () => {
|
||||
const worker = new Worker(new URL('./worker.js', import.meta.url), {
|
||||
name: 'turso-database',
|
||||
type: 'module',
|
||||
})
|
||||
MainWorker = worker;
|
||||
return worker
|
||||
});
|
||||
|
||||
export default napiModule.exports
|
||||
export const Database = napiModule.exports.Database
|
||||
export const Opfs = napiModule.exports.Opfs
|
||||
export const OpfsFile = napiModule.exports.OpfsFile
|
||||
export const Statement = napiModule.exports.Statement
|
||||
export const connect = napiModule.exports.connect
|
||||
export const initThreadPool = napiModule.exports.initThreadPool
|
||||
25
bindings/javascript/packages/browser/index-turbopack-hack.ts
Normal file
25
bindings/javascript/packages/browser/index-turbopack-hack.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { setupMainThread } from "@tursodatabase/database-browser-common";
|
||||
import { tursoWasm } from "./wasm-inline.js";
|
||||
|
||||
// Next (turbopack) has issues with loading wasm module: https://github.com/vercel/next.js/issues/82520
|
||||
// So, we inline wasm binary in the source code in order to avoid issues with loading it from the file
|
||||
const __wasmFile = await tursoWasm();
|
||||
|
||||
export let MainWorker = null;
|
||||
|
||||
const napiModule = await setupMainThread(__wasmFile, () => {
|
||||
const worker = new Worker(new URL('./worker.js', import.meta.url), {
|
||||
name: 'turso-database',
|
||||
type: 'module',
|
||||
})
|
||||
MainWorker = worker;
|
||||
return worker
|
||||
});
|
||||
|
||||
export default napiModule.exports
|
||||
export const Database = napiModule.exports.Database
|
||||
export const Opfs = napiModule.exports.Opfs
|
||||
export const OpfsFile = napiModule.exports.OpfsFile
|
||||
export const Statement = napiModule.exports.Statement
|
||||
export const connect = napiModule.exports.connect
|
||||
export const initThreadPool = napiModule.exports.initThreadPool
|
||||
41
bindings/javascript/packages/browser/index-vite-dev-hack.ts
Normal file
41
bindings/javascript/packages/browser/index-vite-dev-hack.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { isWebWorker, setupMainThread, setupWebWorker } from "@tursodatabase/database-browser-common";
|
||||
import { tursoWasm } from "./wasm-inline.js";
|
||||
|
||||
let napiModule = {
|
||||
exports: {
|
||||
Database: {} as any,
|
||||
Opfs: {} as any,
|
||||
OpfsFile: {} as any,
|
||||
Statement: {} as any,
|
||||
connect: {} as any,
|
||||
initThreadPool: {} as any,
|
||||
}
|
||||
};
|
||||
|
||||
export let MainWorker = null;
|
||||
if (isWebWorker()) {
|
||||
setupWebWorker();
|
||||
} else {
|
||||
// Vite has issues with loading wasm modules and worker in dev server: https://github.com/vitejs/vite/issues/8427
|
||||
// So, the mitigation for dev server only is:
|
||||
// 1. inline wasm binary in the source code in order to avoid issues with loading it from the file
|
||||
// 2. use same file as worker entry point
|
||||
const __wasmFile = await tursoWasm();
|
||||
|
||||
napiModule = await setupMainThread(__wasmFile, () => {
|
||||
const worker = new Worker(import.meta.url, {
|
||||
name: 'turso-database',
|
||||
type: 'module',
|
||||
})
|
||||
MainWorker = worker;
|
||||
return worker
|
||||
});
|
||||
}
|
||||
|
||||
export default napiModule.exports
|
||||
export const Database = napiModule.exports.Database
|
||||
export const Opfs = napiModule.exports.Opfs
|
||||
export const OpfsFile = napiModule.exports.OpfsFile
|
||||
export const Statement = napiModule.exports.Statement
|
||||
export const connect = napiModule.exports.connect
|
||||
export const initThreadPool = napiModule.exports.initThreadPool
|
||||
@@ -1,68 +0,0 @@
|
||||
import {
|
||||
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
||||
getDefaultContext as __emnapiGetDefaultContext,
|
||||
instantiateNapiModule as __emnapiInstantiateNapiModule,
|
||||
WASI as __WASI,
|
||||
} from '@napi-rs/wasm-runtime'
|
||||
|
||||
import { MainDummyImports } from "@tursodatabase/database-browser-common";
|
||||
|
||||
|
||||
const __wasi = new __WASI({
|
||||
version: 'preview1',
|
||||
})
|
||||
|
||||
const __wasmUrl = new URL('./turso.wasm32-wasi.wasm', import.meta.url).href
|
||||
const __emnapiContext = __emnapiGetDefaultContext()
|
||||
|
||||
|
||||
const __sharedMemory = new WebAssembly.Memory({
|
||||
initial: 4000,
|
||||
maximum: 65536,
|
||||
shared: true,
|
||||
})
|
||||
|
||||
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
||||
|
||||
export let MainWorker = null;
|
||||
|
||||
const {
|
||||
instance: __napiInstance,
|
||||
module: __wasiModule,
|
||||
napiModule: __napiModule,
|
||||
} = await __emnapiInstantiateNapiModule(__wasmFile, {
|
||||
context: __emnapiContext,
|
||||
asyncWorkPoolSize: 1,
|
||||
wasi: __wasi,
|
||||
onCreateWorker() {
|
||||
const worker = new Worker(new URL('./worker.mjs', import.meta.url), {
|
||||
type: 'module',
|
||||
})
|
||||
MainWorker = worker;
|
||||
return worker
|
||||
},
|
||||
overwriteImports(importObject) {
|
||||
importObject.env = {
|
||||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
...MainDummyImports,
|
||||
memory: __sharedMemory,
|
||||
}
|
||||
return importObject
|
||||
},
|
||||
beforeInit({ instance }) {
|
||||
for (const name of Object.keys(instance.exports)) {
|
||||
if (name.startsWith('__napi_register__')) {
|
||||
instance.exports[name]()
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
export default __napiModule.exports
|
||||
export const Database = __napiModule.exports.Database
|
||||
export const Opfs = __napiModule.exports.Opfs
|
||||
export const OpfsFile = __napiModule.exports.OpfsFile
|
||||
export const Statement = __napiModule.exports.Statement
|
||||
export const connect = __napiModule.exports.connect
|
||||
export const initThreadPool = __napiModule.exports.initThreadPool
|
||||
@@ -10,12 +10,21 @@
|
||||
"main": "dist/promise.js",
|
||||
"packageManager": "yarn@4.9.2",
|
||||
"files": [
|
||||
"index.js",
|
||||
"worker.mjs",
|
||||
"turso.wasm32-wasi.wasm",
|
||||
"dist/**",
|
||||
"README.md"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"default": "./dist/promise-default.js"
|
||||
},
|
||||
"./vite": {
|
||||
"development": "./dist/promise-vite-dev-hack.js",
|
||||
"default": "./dist/promise-default.js"
|
||||
},
|
||||
"./turbopack": {
|
||||
"default": "./dist/promise-turbopack-hack.js"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^3.1.5",
|
||||
"@vitest/browser": "^3.2.4",
|
||||
@@ -25,7 +34,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"napi-build": "napi build --features browser --release --platform --target wasm32-wasip1-threads --no-js --manifest-path ../../Cargo.toml --output-dir . && rm index.d.ts turso.wasi* wasi* browser.js",
|
||||
"tsc-build": "npm exec tsc",
|
||||
"tsc-build": "npm exec tsc && cp turso.wasm32-wasi.wasm ./dist/turso.wasm32-wasi.wasm && WASM_FILE=turso.wasm32-wasi.wasm JS_FILE=./dist/wasm-inline.js node ../../scripts/inline-wasm-base64.js",
|
||||
"build": "npm run napi-build && npm run tsc-build",
|
||||
"test": "CI=1 vitest --browser=chromium --run && CI=1 vitest --browser=firefox --run"
|
||||
},
|
||||
@@ -35,11 +44,7 @@
|
||||
"wasm32-wasip1-threads"
|
||||
]
|
||||
},
|
||||
"imports": {
|
||||
"#index": "./index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@napi-rs/wasm-runtime": "^1.0.3",
|
||||
"@tursodatabase/database-browser-common": "^0.2.0-pre.1",
|
||||
"@tursodatabase/database-common": "^0.2.0-pre.1"
|
||||
}
|
||||
|
||||
22
bindings/javascript/packages/browser/promise-default.ts
Normal file
22
bindings/javascript/packages/browser/promise-default.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
|
||||
import { connect as promiseConnect, Database } from "./promise.js";
|
||||
import { connect as nativeConnect, initThreadPool, MainWorker } from "./index-default.js";
|
||||
|
||||
/**
|
||||
* Creates a new database connection asynchronously.
|
||||
*
|
||||
* @param {string} path - Path to the database file.
|
||||
* @param {Object} opts - Options for database behavior.
|
||||
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
||||
*/
|
||||
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
|
||||
return await promiseConnect(path, opts, nativeConnect, async () => {
|
||||
await initThreadPool();
|
||||
if (MainWorker == null) {
|
||||
throw new Error("panic: MainWorker is not initialized");
|
||||
}
|
||||
return MainWorker;
|
||||
});
|
||||
}
|
||||
|
||||
export { connect, Database, SqliteError }
|
||||
@@ -0,0 +1,22 @@
|
||||
import { DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
|
||||
import { connect as promiseConnect, Database } from "./promise.js";
|
||||
import { connect as nativeConnect, initThreadPool, MainWorker } from "./index-turbopack-hack.js";
|
||||
|
||||
/**
|
||||
* Creates a new database connection asynchronously.
|
||||
*
|
||||
* @param {string} path - Path to the database file.
|
||||
* @param {Object} opts - Options for database behavior.
|
||||
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
||||
*/
|
||||
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
|
||||
return await promiseConnect(path, opts, nativeConnect, async () => {
|
||||
await initThreadPool();
|
||||
if (MainWorker == null) {
|
||||
throw new Error("panic: MainWorker is not initialized");
|
||||
}
|
||||
return MainWorker;
|
||||
});
|
||||
}
|
||||
|
||||
export { connect, Database, SqliteError }
|
||||
@@ -0,0 +1,22 @@
|
||||
import { DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
|
||||
import { connect as promiseConnect, Database } from "./promise.js";
|
||||
import { connect as nativeConnect, initThreadPool, MainWorker } from "./index-vite-dev-hack.js";
|
||||
|
||||
/**
|
||||
* Creates a new database connection asynchronously.
|
||||
*
|
||||
* @param {string} path - Path to the database file.
|
||||
* @param {Object} opts - Options for database behavior.
|
||||
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
||||
*/
|
||||
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
|
||||
return await promiseConnect(path, opts, nativeConnect, async () => {
|
||||
await initThreadPool();
|
||||
if (MainWorker == null) {
|
||||
throw new Error("panic: MainWorker is not initialized");
|
||||
}
|
||||
return MainWorker;
|
||||
});
|
||||
}
|
||||
|
||||
export { connect, Database, SqliteError }
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, test, afterEach } from 'vitest'
|
||||
import { connect } from './promise.js'
|
||||
import { connect } from './promise-default.js'
|
||||
|
||||
test('in-memory db', async () => {
|
||||
const db = await connect(":memory:");
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import { registerFileAtWorker, unregisterFileAtWorker } from "@tursodatabase/database-browser-common"
|
||||
import { DatabasePromise, NativeDatabase, DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
|
||||
import { connect as nativeConnect, initThreadPool, MainWorker } from "#index";
|
||||
|
||||
class Database extends DatabasePromise {
|
||||
path: string | null;
|
||||
constructor(db: NativeDatabase, fsPath: string | null, opts: DatabaseOpts = {}) {
|
||||
worker: Worker | null;
|
||||
constructor(db: NativeDatabase, worker: Worker | null, fsPath: string | null, opts: DatabaseOpts = {}) {
|
||||
super(db, opts)
|
||||
this.path = fsPath;
|
||||
this.worker = worker;
|
||||
}
|
||||
async close() {
|
||||
if (this.path != null) {
|
||||
if (this.path != null && this.worker != null) {
|
||||
await Promise.all([
|
||||
unregisterFileAtWorker(MainWorker, this.path),
|
||||
unregisterFileAtWorker(MainWorker, `${this.path}-wal`)
|
||||
unregisterFileAtWorker(this.worker, this.path),
|
||||
unregisterFileAtWorker(this.worker, `${this.path}-wal`)
|
||||
]);
|
||||
}
|
||||
this.db.close();
|
||||
@@ -26,21 +27,18 @@ class Database extends DatabasePromise {
|
||||
* @param {Object} opts - Options for database behavior.
|
||||
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
||||
*/
|
||||
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
|
||||
async function connect(path: string, opts: DatabaseOpts, connect: any, init: () => Promise<Worker>): Promise<Database> {
|
||||
if (path == ":memory:") {
|
||||
const db = await nativeConnect(path, { tracing: opts.tracing });
|
||||
return new Database(db, null, opts);
|
||||
}
|
||||
await initThreadPool();
|
||||
if (MainWorker == null) {
|
||||
throw new Error("panic: MainWorker is not set");
|
||||
const db = await connect(path, { tracing: opts.tracing });
|
||||
return new Database(db, null, null, opts);
|
||||
}
|
||||
const worker = await init();
|
||||
await Promise.all([
|
||||
registerFileAtWorker(MainWorker, path),
|
||||
registerFileAtWorker(MainWorker, `${path}-wal`)
|
||||
registerFileAtWorker(worker, path),
|
||||
registerFileAtWorker(worker, `${path}-wal`)
|
||||
]);
|
||||
const db = await nativeConnect(path, { tracing: opts.tracing });
|
||||
return new Database(db, path, opts);
|
||||
const db = await connect(path, { tracing: opts.tracing });
|
||||
return new Database(db, worker, path, opts);
|
||||
}
|
||||
|
||||
export { connect, Database, SqliteError }
|
||||
|
||||
@@ -11,12 +11,7 @@
|
||||
"es2020",
|
||||
"DOM",
|
||||
"WebWorker"
|
||||
],
|
||||
"paths": {
|
||||
"#index": [
|
||||
"./index.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"*"
|
||||
|
||||
9
bindings/javascript/packages/browser/wasm-inline.ts
Normal file
9
bindings/javascript/packages/browser/wasm-inline.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const tursoWasmBase64 = '__PLACEHOLDER__';
|
||||
async function convertBase64ToBinary(base64Url: string): Promise<ArrayBuffer> {
|
||||
const blob = await fetch(base64Url).then(res => res.blob());
|
||||
return await blob.arrayBuffer();
|
||||
}
|
||||
|
||||
export async function tursoWasm(): Promise<ArrayBuffer> {
|
||||
return await convertBase64ToBinary(tursoWasmBase64);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
|
||||
import { OpfsDirectory, workerImports } from '@tursodatabase/database-browser-common';
|
||||
|
||||
var opfs = new OpfsDirectory();
|
||||
var memory = null;
|
||||
|
||||
const handler = new MessageHandler({
|
||||
onLoad({ wasmModule, wasmMemory }) {
|
||||
memory = wasmMemory;
|
||||
const wasi = new WASI({
|
||||
print: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log.apply(console, arguments)
|
||||
},
|
||||
printErr: function () {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error.apply(console, arguments)
|
||||
},
|
||||
})
|
||||
return instantiateNapiModuleSync(wasmModule, {
|
||||
childThread: true,
|
||||
wasi,
|
||||
overwriteImports(importObject) {
|
||||
importObject.env = {
|
||||
...importObject.env,
|
||||
...importObject.napi,
|
||||
...importObject.emnapi,
|
||||
...workerImports(opfs, memory),
|
||||
memory: wasmMemory,
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
globalThis.onmessage = async function (e) {
|
||||
if (e.data.__turso__ == 'register') {
|
||||
try {
|
||||
await opfs.registerFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
} else if (e.data.__turso__ == 'unregister') {
|
||||
try {
|
||||
await opfs.unregisterFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
}
|
||||
handler.handle(e)
|
||||
}
|
||||
2
bindings/javascript/packages/browser/worker.ts
Normal file
2
bindings/javascript/packages/browser/worker.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import { setupWebWorker } from "@tursodatabase/database-browser-common";
|
||||
setupWebWorker();
|
||||
@@ -81,8 +81,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-android-arm64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-android-arm64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -97,8 +97,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-android-arm-eabi')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-android-arm-eabi/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -117,8 +117,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-win32-x64-msvc')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-win32-x64-msvc/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -133,8 +133,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-win32-ia32-msvc')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-win32-ia32-msvc/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -149,8 +149,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-win32-arm64-msvc')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-win32-arm64-msvc/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -168,8 +168,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-darwin-universal')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-darwin-universal/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -184,8 +184,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-darwin-x64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-darwin-x64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -200,8 +200,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-darwin-arm64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-darwin-arm64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -220,8 +220,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-freebsd-x64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-freebsd-x64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -236,8 +236,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-freebsd-arm64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-freebsd-arm64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -257,8 +257,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-x64-musl')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-musl/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -273,8 +273,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-x64-gnu')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-x64-gnu/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -291,8 +291,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-arm64-musl')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-musl/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -307,8 +307,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-arm64-gnu')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-arm64-gnu/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -325,8 +325,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-arm-musleabihf')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-musleabihf/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -341,8 +341,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-arm-gnueabihf')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-arm-gnueabihf/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -359,8 +359,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-riscv64-musl')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-musl/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -375,8 +375,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-riscv64-gnu')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-riscv64-gnu/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -392,8 +392,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-ppc64-gnu')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-ppc64-gnu/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -408,8 +408,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-linux-s390x-gnu')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-linux-s390x-gnu/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -428,8 +428,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-openharmony-arm64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -444,8 +444,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-openharmony-x64')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-openharmony-x64/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
@@ -460,8 +460,8 @@ function requireNative() {
|
||||
try {
|
||||
const binding = require('@tursodatabase/database-openharmony-arm')
|
||||
const bindingPackageVersion = require('@tursodatabase/database-openharmony-arm/package.json').version
|
||||
if (bindingPackageVersion !== '0.1.5' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.1.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
||||
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
||||
}
|
||||
return binding
|
||||
} catch (e) {
|
||||
|
||||
1
bindings/javascript/packages/wasm-runtime/.gitignore
vendored
Normal file
1
bindings/javascript/packages/wasm-runtime/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!dist
|
||||
44
bindings/javascript/packages/wasm-runtime/LICENSE
Normal file
44
bindings/javascript/packages/wasm-runtime/LICENSE
Normal file
@@ -0,0 +1,44 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-present LongYinan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
264
bindings/javascript/packages/wasm-runtime/dist/fs-proxy.cjs
vendored
Normal file
264
bindings/javascript/packages/wasm-runtime/dist/fs-proxy.cjs
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
'use strict';
|
||||
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
*/
|
||||
const getType = (value) => {
|
||||
if (value === undefined) return 0
|
||||
if (value === null) return 1
|
||||
const t = typeof value;
|
||||
if (t === 'boolean') return 2
|
||||
if (t === 'number') return 3
|
||||
if (t === 'string') return 4
|
||||
if (t === 'object') return 6
|
||||
if (t === 'bigint') return 9
|
||||
return -1
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import('memfs').IFs} memfs
|
||||
* @param {any} value
|
||||
* @param {ReturnType<typeof getType>} type
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
const encodeValue = (memfs, value, type) => {
|
||||
switch (type) {
|
||||
case 0:
|
||||
case 1:
|
||||
return new Uint8Array(0)
|
||||
case 2: {
|
||||
const view = new Int32Array(1);
|
||||
view[0] = value ? 1 : 0;
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case 3: {
|
||||
const view = new Float64Array(1);
|
||||
view[0] = value;
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case 4: {
|
||||
const view = new TextEncoder().encode(value);
|
||||
return view
|
||||
}
|
||||
case 6: {
|
||||
function storeConstructor(obj, memfs, processed = new WeakSet()) {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
if (processed.has(obj)) {
|
||||
return
|
||||
}
|
||||
|
||||
processed.add(obj);
|
||||
|
||||
const [entry] =
|
||||
Object.entries(memfs).filter(([_, v]) => v === obj.constructor)[0] ??
|
||||
[];
|
||||
if (entry) {
|
||||
Object.defineProperty(obj, '__constructor__', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
value: entry,
|
||||
});
|
||||
}
|
||||
|
||||
for (const value of Object.values(obj)) {
|
||||
storeConstructor(value, memfs, processed);
|
||||
}
|
||||
}
|
||||
|
||||
storeConstructor(value, memfs);
|
||||
|
||||
const json = JSON.stringify(value, (_, value) => {
|
||||
if (typeof value === 'bigint') {
|
||||
return `BigInt(${String(value)})`
|
||||
}
|
||||
if (value instanceof Error) {
|
||||
return {
|
||||
...value,
|
||||
message: value.message,
|
||||
stack: value.stack,
|
||||
__error__: value.constructor.name,
|
||||
}
|
||||
}
|
||||
return value
|
||||
});
|
||||
const view = new TextEncoder().encode(json);
|
||||
return view
|
||||
}
|
||||
case 9: {
|
||||
const view = new BigInt64Array(1);
|
||||
view[0] = value;
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case -1:
|
||||
default:
|
||||
throw new Error('unsupported data')
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {typeof import('memfs')} memfs
|
||||
* @param {Uint8Array} payload
|
||||
* @param {number} type
|
||||
* @returns {any}
|
||||
*/
|
||||
const decodeValue = (memfs, payload, type) => {
|
||||
if (type === 0) return undefined
|
||||
if (type === 1) return null
|
||||
if (type === 2)
|
||||
return Boolean(new Int32Array(payload.buffer, payload.byteOffset, 1)[0])
|
||||
if (type === 3)
|
||||
return new Float64Array(payload.buffer, payload.byteOffset, 1)[0]
|
||||
if (type === 4) return new TextDecoder().decode(payload.slice())
|
||||
if (type === 6) {
|
||||
const obj = JSON.parse(
|
||||
new TextDecoder().decode(payload.slice()),
|
||||
(_key, value) => {
|
||||
if (typeof value === 'string') {
|
||||
const matched = value.match(/^BigInt\((-?\d+)\)$/);
|
||||
if (matched && matched[1]) {
|
||||
return BigInt(matched[1])
|
||||
}
|
||||
}
|
||||
return value
|
||||
},
|
||||
);
|
||||
|
||||
function loadConstructor(obj, memfs, processed = new WeakSet()) {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
if (processed.has(obj)) {
|
||||
return
|
||||
}
|
||||
|
||||
processed.add(obj);
|
||||
|
||||
if (obj.__constructor__) {
|
||||
const ctor = obj.__constructor__;
|
||||
delete obj.__constructor__;
|
||||
Object.setPrototypeOf(obj, memfs[ctor].prototype);
|
||||
}
|
||||
|
||||
for (const value of Object.values(obj)) {
|
||||
loadConstructor(value, memfs, processed);
|
||||
}
|
||||
}
|
||||
|
||||
loadConstructor(obj, memfs);
|
||||
|
||||
if (obj.__error__) {
|
||||
const name = obj.__error__;
|
||||
const ErrorConstructor = globalThis[name] || Error;
|
||||
delete obj.__error__;
|
||||
const err = new ErrorConstructor(obj.message);
|
||||
Object.defineProperty(err, 'stack', {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: err.stack,
|
||||
});
|
||||
Object.defineProperty(err, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: name,
|
||||
});
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (k === 'message' || k === 'stack') continue
|
||||
err[k] = v;
|
||||
}
|
||||
return err
|
||||
}
|
||||
return obj
|
||||
}
|
||||
if (type === 9)
|
||||
return new BigInt64Array(payload.buffer, payload.byteOffset, 1)[0]
|
||||
throw new Error('unsupported data')
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {import('memfs').IFs} fs
|
||||
* @returns {(e: { data: { __fs__: { sab: Int32Array, type: keyof import('memfs').IFs, payload: any[] } } }) => void}
|
||||
*/
|
||||
// oxlint-disable-next-line no-unused-vars -- fixed in an upcoming release
|
||||
const createOnMessage = (fs) =>
|
||||
function onMessage(e) {
|
||||
if (e.data.__fs__) {
|
||||
/**
|
||||
* 0..4 status(int32_t): 21(waiting) 0(success) 1(error)
|
||||
* 5..8 type(napi_valuetype): 0(undefined) 1(null) 2(boolean) 3(number) 4(string) 6(jsonstring) 9(bigint) -1(unsupported)
|
||||
* 9..16 payload_size(uint32_t) <= 1024
|
||||
* 16..16 + payload_size payload_content
|
||||
*/
|
||||
const { sab, type, payload } = e.data.__fs__;
|
||||
const fn = fs[type];
|
||||
try {
|
||||
const ret = fn.apply(fs, payload);
|
||||
const t = getType(ret);
|
||||
Atomics.store(sab, 1, t);
|
||||
const v = encodeValue(fs, ret, t);
|
||||
Atomics.store(sab, 2, v.length);
|
||||
new Uint8Array(sab.buffer).set(v, 16);
|
||||
Atomics.store(sab, 0, 0); // success
|
||||
} catch (/** @type {any} */ err) {
|
||||
const t = getType(err);
|
||||
Atomics.store(sab, 1, t);
|
||||
const v = encodeValue(fs, err, t);
|
||||
Atomics.store(sab, 2, v.length);
|
||||
new Uint8Array(sab.buffer).set(v, 16);
|
||||
Atomics.store(sab, 0, 1); // error
|
||||
} finally {
|
||||
Atomics.notify(sab, 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {typeof import('memfs')} memfs
|
||||
*/
|
||||
const createFsProxy = (memfs) =>
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get(_target, p, _receiver) {
|
||||
/**
|
||||
* @param {any[]} args
|
||||
*/
|
||||
return function (...args) {
|
||||
const sab = new SharedArrayBuffer(16 + 10240);
|
||||
const i32arr = new Int32Array(sab);
|
||||
Atomics.store(i32arr, 0, 21);
|
||||
|
||||
postMessage({
|
||||
__fs__: {
|
||||
sab: i32arr,
|
||||
type: p,
|
||||
payload: args,
|
||||
},
|
||||
});
|
||||
|
||||
Atomics.wait(i32arr, 0, 21);
|
||||
|
||||
const status = Atomics.load(i32arr, 0);
|
||||
const type = Atomics.load(i32arr, 1);
|
||||
const size = Atomics.load(i32arr, 2);
|
||||
const content = new Uint8Array(sab, 16, size);
|
||||
const value = decodeValue(memfs, content, type);
|
||||
if (status === 1) {
|
||||
throw value
|
||||
}
|
||||
return value
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
exports.createFsProxy = createFsProxy;
|
||||
exports.createOnMessage = createOnMessage;
|
||||
24204
bindings/javascript/packages/wasm-runtime/dist/fs.js
vendored
Normal file
24204
bindings/javascript/packages/wasm-runtime/dist/fs.js
vendored
Normal file
File diff suppressed because one or more lines are too long
259
bindings/javascript/packages/wasm-runtime/fs-proxy.js
Normal file
259
bindings/javascript/packages/wasm-runtime/fs-proxy.js
Normal file
@@ -0,0 +1,259 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
*/
|
||||
const getType = (value) => {
|
||||
if (value === undefined) return 0
|
||||
if (value === null) return 1
|
||||
const t = typeof value
|
||||
if (t === 'boolean') return 2
|
||||
if (t === 'number') return 3
|
||||
if (t === 'string') return 4
|
||||
if (t === 'object') return 6
|
||||
if (t === 'bigint') return 9
|
||||
return -1
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('memfs').IFs} memfs
|
||||
* @param {any} value
|
||||
* @param {ReturnType<typeof getType>} type
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
const encodeValue = (memfs, value, type) => {
|
||||
switch (type) {
|
||||
case 0:
|
||||
case 1:
|
||||
return new Uint8Array(0)
|
||||
case 2: {
|
||||
const view = new Int32Array(1)
|
||||
view[0] = value ? 1 : 0
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case 3: {
|
||||
const view = new Float64Array(1)
|
||||
view[0] = value
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case 4: {
|
||||
const view = new TextEncoder().encode(value)
|
||||
return view
|
||||
}
|
||||
case 6: {
|
||||
function storeConstructor(obj, memfs, processed = new WeakSet()) {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
if (processed.has(obj)) {
|
||||
return
|
||||
}
|
||||
|
||||
processed.add(obj)
|
||||
|
||||
const [entry] =
|
||||
Object.entries(memfs).filter(([_, v]) => v === obj.constructor)[0] ??
|
||||
[]
|
||||
if (entry) {
|
||||
Object.defineProperty(obj, '__constructor__', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
value: entry,
|
||||
})
|
||||
}
|
||||
|
||||
for (const value of Object.values(obj)) {
|
||||
storeConstructor(value, memfs, processed)
|
||||
}
|
||||
}
|
||||
|
||||
storeConstructor(value, memfs)
|
||||
|
||||
const json = JSON.stringify(value, (_, value) => {
|
||||
if (typeof value === 'bigint') {
|
||||
return `BigInt(${String(value)})`
|
||||
}
|
||||
if (value instanceof Error) {
|
||||
return {
|
||||
...value,
|
||||
message: value.message,
|
||||
stack: value.stack,
|
||||
__error__: value.constructor.name,
|
||||
}
|
||||
}
|
||||
return value
|
||||
})
|
||||
const view = new TextEncoder().encode(json)
|
||||
return view
|
||||
}
|
||||
case 9: {
|
||||
const view = new BigInt64Array(1)
|
||||
view[0] = value
|
||||
return new Uint8Array(view.buffer)
|
||||
}
|
||||
case -1:
|
||||
default:
|
||||
throw new Error('unsupported data')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {typeof import('memfs')} memfs
|
||||
* @param {Uint8Array} payload
|
||||
* @param {number} type
|
||||
* @returns {any}
|
||||
*/
|
||||
const decodeValue = (memfs, payload, type) => {
|
||||
if (type === 0) return undefined
|
||||
if (type === 1) return null
|
||||
if (type === 2)
|
||||
return Boolean(new Int32Array(payload.buffer, payload.byteOffset, 1)[0])
|
||||
if (type === 3)
|
||||
return new Float64Array(payload.buffer, payload.byteOffset, 1)[0]
|
||||
if (type === 4) return new TextDecoder().decode(payload.slice())
|
||||
if (type === 6) {
|
||||
const obj = JSON.parse(
|
||||
new TextDecoder().decode(payload.slice()),
|
||||
(_key, value) => {
|
||||
if (typeof value === 'string') {
|
||||
const matched = value.match(/^BigInt\((-?\d+)\)$/)
|
||||
if (matched && matched[1]) {
|
||||
return BigInt(matched[1])
|
||||
}
|
||||
}
|
||||
return value
|
||||
},
|
||||
)
|
||||
|
||||
function loadConstructor(obj, memfs, processed = new WeakSet()) {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return
|
||||
}
|
||||
|
||||
if (processed.has(obj)) {
|
||||
return
|
||||
}
|
||||
|
||||
processed.add(obj)
|
||||
|
||||
if (obj.__constructor__) {
|
||||
const ctor = obj.__constructor__
|
||||
delete obj.__constructor__
|
||||
Object.setPrototypeOf(obj, memfs[ctor].prototype)
|
||||
}
|
||||
|
||||
for (const value of Object.values(obj)) {
|
||||
loadConstructor(value, memfs, processed)
|
||||
}
|
||||
}
|
||||
|
||||
loadConstructor(obj, memfs)
|
||||
|
||||
if (obj.__error__) {
|
||||
const name = obj.__error__
|
||||
const ErrorConstructor = globalThis[name] || Error
|
||||
delete obj.__error__
|
||||
const err = new ErrorConstructor(obj.message)
|
||||
Object.defineProperty(err, 'stack', {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: err.stack,
|
||||
})
|
||||
Object.defineProperty(err, Symbol.toStringTag, {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true,
|
||||
value: name,
|
||||
})
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
if (k === 'message' || k === 'stack') continue
|
||||
err[k] = v
|
||||
}
|
||||
return err
|
||||
}
|
||||
return obj
|
||||
}
|
||||
if (type === 9)
|
||||
return new BigInt64Array(payload.buffer, payload.byteOffset, 1)[0]
|
||||
throw new Error('unsupported data')
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('memfs').IFs} fs
|
||||
* @returns {(e: { data: { __fs__: { sab: Int32Array, type: keyof import('memfs').IFs, payload: any[] } } }) => void}
|
||||
*/
|
||||
// oxlint-disable-next-line no-unused-vars -- fixed in an upcoming release
|
||||
export const createOnMessage = (fs) =>
|
||||
function onMessage(e) {
|
||||
if (e.data.__fs__) {
|
||||
/**
|
||||
* 0..4 status(int32_t): 21(waiting) 0(success) 1(error)
|
||||
* 5..8 type(napi_valuetype): 0(undefined) 1(null) 2(boolean) 3(number) 4(string) 6(jsonstring) 9(bigint) -1(unsupported)
|
||||
* 9..16 payload_size(uint32_t) <= 1024
|
||||
* 16..16 + payload_size payload_content
|
||||
*/
|
||||
const { sab, type, payload } = e.data.__fs__
|
||||
const fn = fs[type]
|
||||
try {
|
||||
const ret = fn.apply(fs, payload)
|
||||
const t = getType(ret)
|
||||
Atomics.store(sab, 1, t)
|
||||
const v = encodeValue(fs, ret, t)
|
||||
Atomics.store(sab, 2, v.length)
|
||||
new Uint8Array(sab.buffer).set(v, 16)
|
||||
Atomics.store(sab, 0, 0) // success
|
||||
} catch (/** @type {any} */ err) {
|
||||
const t = getType(err)
|
||||
Atomics.store(sab, 1, t)
|
||||
const v = encodeValue(fs, err, t)
|
||||
Atomics.store(sab, 2, v.length)
|
||||
new Uint8Array(sab.buffer).set(v, 16)
|
||||
Atomics.store(sab, 0, 1) // error
|
||||
} finally {
|
||||
Atomics.notify(sab, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {typeof import('memfs')} memfs
|
||||
*/
|
||||
export const createFsProxy = (memfs) =>
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get(_target, p, _receiver) {
|
||||
/**
|
||||
* @param {any[]} args
|
||||
*/
|
||||
return function (...args) {
|
||||
const sab = new SharedArrayBuffer(16 + 10240)
|
||||
const i32arr = new Int32Array(sab)
|
||||
Atomics.store(i32arr, 0, 21)
|
||||
|
||||
postMessage({
|
||||
__fs__: {
|
||||
sab: i32arr,
|
||||
type: p,
|
||||
payload: args,
|
||||
},
|
||||
})
|
||||
|
||||
Atomics.wait(i32arr, 0, 21)
|
||||
|
||||
const status = Atomics.load(i32arr, 0)
|
||||
const type = Atomics.load(i32arr, 1)
|
||||
const size = Atomics.load(i32arr, 2)
|
||||
const content = new Uint8Array(sab, 16, size)
|
||||
const value = decodeValue(memfs, content, type)
|
||||
if (status === 1) {
|
||||
throw value
|
||||
}
|
||||
return value
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
46
bindings/javascript/packages/wasm-runtime/package.json
Normal file
46
bindings/javascript/packages/wasm-runtime/package.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "@tursodatabase/wasm-runtime",
|
||||
"version": "0.2.0-pre.1",
|
||||
"type": "module",
|
||||
"description": "Runtime and polyfill for wasm targets",
|
||||
"author": {
|
||||
"name": "LongYinan",
|
||||
"url": "https://github.com/Brooooooklyn"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/napi-rs/napi-rs.git",
|
||||
"directory": "wasi-runtime"
|
||||
},
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"access": "public"
|
||||
},
|
||||
"files": [
|
||||
"runtime.cjs",
|
||||
"runtime.js",
|
||||
"fs-proxy.js",
|
||||
"dist/*.cjs",
|
||||
"dist/*.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@emnapi/core": "^1.4.5",
|
||||
"@emnapi/runtime": "^1.4.5",
|
||||
"@tybys/wasm-util": "^0.10.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "echo 'nothing to build'",
|
||||
"tsc-build": "echo 'nothing to tsc-build'",
|
||||
"test": "echo 'nothing to test'"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./runtime.js",
|
||||
"require": "./runtime.cjs"
|
||||
},
|
||||
"./fs": {
|
||||
"import": "./dist/fs.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
15
bindings/javascript/packages/wasm-runtime/runtime.cjs
Normal file
15
bindings/javascript/packages/wasm-runtime/runtime.cjs
Normal file
@@ -0,0 +1,15 @@
|
||||
const { MessageHandler, instantiateNapiModuleSync, instantiateNapiModule } = require('@emnapi/core')
|
||||
const { getDefaultContext } = require('@emnapi/runtime')
|
||||
const { WASI } = require('@tybys/wasm-util')
|
||||
|
||||
const { createFsProxy, createOnMessage } = require('./dist/fs-proxy.cjs')
|
||||
|
||||
module.exports = {
|
||||
MessageHandler,
|
||||
instantiateNapiModule,
|
||||
instantiateNapiModuleSync,
|
||||
getDefaultContext,
|
||||
WASI,
|
||||
createFsProxy,
|
||||
createOnMessage,
|
||||
}
|
||||
8
bindings/javascript/packages/wasm-runtime/runtime.js
Normal file
8
bindings/javascript/packages/wasm-runtime/runtime.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export {
|
||||
instantiateNapiModuleSync,
|
||||
instantiateNapiModule,
|
||||
MessageHandler,
|
||||
} from '@emnapi/core'
|
||||
export { getDefaultContext } from '@emnapi/runtime'
|
||||
export * from '@tybys/wasm-util'
|
||||
export { createOnMessage, createFsProxy } from './fs-proxy.js'
|
||||
Reference in New Issue
Block a user