mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
use wasm-runtime from NPM instead of patched sources
This commit is contained in:
73
bindings/javascript/package-lock.json
generated
73
bindings/javascript/package-lock.json
generated
@@ -7,7 +7,6 @@
|
||||
"": {
|
||||
"version": "0.2.0-pre.7",
|
||||
"workspaces": [
|
||||
"packages/wasm-runtime",
|
||||
"packages/common",
|
||||
"packages/native",
|
||||
"packages/browser-common",
|
||||
@@ -67,28 +66,28 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
"version": "1.4.5",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.4.5.tgz",
|
||||
"integrity": "sha512-XsLw1dEOpkSX/WucdqUhPWP7hDxSvZiY+fsUC14h+FtQ2Ifni4znbBt8punRX+Uj2JG/uDb8nEHVKvrVlvdZ5Q==",
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.5.0.tgz",
|
||||
"integrity": "sha512-sbP8GzB1WDzacS8fgNPpHlp6C9VZe+SJP3F90W9rLemaQj2PzIuTEl1qDOYQf58YIpyjViI24y9aPWCjEzY2cg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@emnapi/wasi-threads": "1.0.4",
|
||||
"@emnapi/wasi-threads": "1.1.0",
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.4.5",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.4.5.tgz",
|
||||
"integrity": "sha512-++LApOtY0pEEz1zrd9vy1/zXVaVJJ/EbAF3u0fXIzPJEDtnITsBGbbK0EkM72amhl/R5b+5xx0Y/QhcVOpuulg==",
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.5.0.tgz",
|
||||
"integrity": "sha512-97/BJ3iXHww3djw6hYIfErCZFee7qCtrneuLa20UXFCOTCfBM2cvQHjWJ2EG0s0MtdNwInarqCTz35i4wWXHsQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/wasi-threads": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.0.4.tgz",
|
||||
"integrity": "sha512-PJR+bOmMOPH8AtcTGAyYNiuJ3/Fcoj2XN/gBEWzDIKh254XO+mM9XoXHk5GNEhodxeMznbg7BlRojVbKN+gC6g==",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.1.0.tgz",
|
||||
"integrity": "sha512-WI0DdZ8xFSbgMjR1sFsKABJ/C5OnRrjT06JXbZKexJGrDuPTzZdDYfFlsgcCXCyf+suG5QU2e/y1Wo2V/OapLQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
@@ -1512,16 +1511,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/wasm-runtime": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.0.3.tgz",
|
||||
"integrity": "sha512-rZxtMsLwjdXkMUGC3WwsPwLNVqVqnTJT6MNIB6e+5fhMcSCPP0AOsNWuMQ5mdCq6HNjs/ZeWAEchpqeprqBD2Q==",
|
||||
"dev": true,
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.0.5.tgz",
|
||||
"integrity": "sha512-TBr9Cf9onSAS2LQ2+QHx6XcC6h9+RIzJgbqG3++9TUZSH204AwEy5jg3BTQ0VATsyoGj4ee49tN/y6rvaOOtcg==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@emnapi/core": "^1.4.5",
|
||||
"@emnapi/runtime": "^1.4.5",
|
||||
"@tybys/wasm-util": "^0.10.0"
|
||||
"@emnapi/core": "^1.5.0",
|
||||
"@emnapi/runtime": "^1.5.0",
|
||||
"@tybys/wasm-util": "^0.10.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@napi-rs/wasm-tools": {
|
||||
@@ -1872,13 +1869,14 @@
|
||||
"resolved": "sync/packages/common",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@tursodatabase/wasm-runtime": {
|
||||
"resolved": "packages/wasm-runtime",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@tybys/wasm-util": {
|
||||
"resolved": "packages/wasm-util",
|
||||
"link": true
|
||||
"version": "0.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz",
|
||||
"integrity": "sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/aria-query": {
|
||||
"version": "5.0.4",
|
||||
@@ -4614,7 +4612,7 @@
|
||||
"version": "0.2.0-pre.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tursodatabase/wasm-runtime": "^0.2.0-pre.7"
|
||||
"@napi-rs/wasm-runtime": "^1.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2"
|
||||
@@ -4645,29 +4643,6 @@
|
||||
"vitest": "^3.2.4"
|
||||
}
|
||||
},
|
||||
"packages/wasm-runtime": {
|
||||
"name": "@tursodatabase/wasm-runtime",
|
||||
"version": "0.2.0-pre.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@emnapi/core": "^1.4.5",
|
||||
"@emnapi/runtime": "^1.4.5",
|
||||
"@tybys/wasm-util": "^0.10.1"
|
||||
}
|
||||
},
|
||||
"packages/wasm-runtime/node_modules/@tybys/wasm-util": {
|
||||
"version": "0.10.1",
|
||||
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.1.tgz",
|
||||
"integrity": "sha512-9tTaPJLSiejZKx+Bmog4uSubteqTvFrVrURwkmHixBo0G4seD0zUxp98E1DzUBJxLQ3NPwXrGKDiVjwx/DpPsg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tslib": "^2.4.0"
|
||||
}
|
||||
},
|
||||
"packages/wasm-util": {
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"sync/packages/browser": {
|
||||
"name": "@tursodatabase/sync-browser",
|
||||
"version": "0.2.0-pre.7",
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
"test": "npm run test --workspaces"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/wasm-runtime",
|
||||
"packages/common",
|
||||
"packages/native",
|
||||
"packages/browser-common",
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
WASI as __WASI,
|
||||
instantiateNapiModuleSync,
|
||||
MessageHandler
|
||||
} from '@tursodatabase/wasm-runtime'
|
||||
} from '@napi-rs/wasm-runtime'
|
||||
|
||||
function getUint8ArrayFromMemory(memory: WebAssembly.Memory, ptr: number, len: number): Uint8Array {
|
||||
ptr = ptr >>> 0;
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
"test": "echo 'no tests'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tursodatabase/wasm-runtime": "^0.2.0-pre.7"
|
||||
"@napi-rs/wasm-runtime": "^1.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
!dist
|
||||
@@ -1,44 +0,0 @@
|
||||
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.
|
||||
|
||||
@@ -1,264 +0,0 @@
|
||||
'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
24204
bindings/javascript/packages/wasm-runtime/dist/fs.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,259 +0,0 @@
|
||||
// @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
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -1,42 +0,0 @@
|
||||
{
|
||||
"name": "@tursodatabase/wasm-runtime",
|
||||
"version": "0.2.0-pre.7",
|
||||
"type": "module",
|
||||
"description": "Runtime and polyfill for wasm targets",
|
||||
"author": {
|
||||
"name": "LongYinan",
|
||||
"url": "https://github.com/Brooooooklyn"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tursodatabase/turso"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"runtime.cjs",
|
||||
"runtime.js",
|
||||
"fs-proxy.js",
|
||||
"dist/*.cjs",
|
||||
"dist/*.js",
|
||||
"LICENSE"
|
||||
],
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
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,
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
export {
|
||||
instantiateNapiModuleSync,
|
||||
instantiateNapiModule,
|
||||
MessageHandler,
|
||||
} from '@emnapi/core'
|
||||
export { getDefaultContext } from '@emnapi/runtime'
|
||||
export * from '@tybys/wasm-util'
|
||||
export { createOnMessage, createFsProxy } from './fs-proxy.js'
|
||||
@@ -1,4 +1,3 @@
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/wasm-runtime/package.json
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/common/package.json
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/native/package.json
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/browser/package.json
|
||||
@@ -7,7 +6,6 @@ sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/common/package.json
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/native/package.json
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/browser/package.json
|
||||
|
||||
sed -i "s/$VERSION_FROM/$VERSION_TO/g" packages/wasm-runtime/package.json
|
||||
sed -i "s/$VERSION_FROM/$VERSION_TO/g" packages/common/package.json
|
||||
sed -i "s/$VERSION_FROM/$VERSION_TO/g" packages/native/package.json
|
||||
sed -i "s/$VERSION_FROM/$VERSION_TO/g" packages/browser/package.json
|
||||
@@ -43,6 +41,3 @@ sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/browser/index-bundle.ts
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/browser/index-vite-dev-hack.ts
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/browser/index-turbopack-hack.ts
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" sync/packages/browser/worker.ts
|
||||
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/wasm-runtime/runtime.cjs
|
||||
sed -i "s/$NAME_FROM/$NAME_TO/g" packages/wasm-runtime/runtime.js
|
||||
|
||||
@@ -37,31 +37,31 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@emnapi/core@npm:^1.4.5":
|
||||
version: 1.4.5
|
||||
resolution: "@emnapi/core@npm:1.4.5"
|
||||
"@emnapi/core@npm:^1.5.0":
|
||||
version: 1.5.0
|
||||
resolution: "@emnapi/core@npm:1.5.0"
|
||||
dependencies:
|
||||
"@emnapi/wasi-threads": "npm:1.0.4"
|
||||
"@emnapi/wasi-threads": "npm:1.1.0"
|
||||
tslib: "npm:^2.4.0"
|
||||
checksum: 10c0/da4a57f65f325d720d0e0d1a9c6618b90c4c43a5027834a110476984e1d47c95ebaed4d316b5dddb9c0ed9a493ffeb97d1934f9677035f336d8a36c1f3b2818f
|
||||
checksum: 10c0/52ba3485277706d92fa27d92b37e5b4f6ef0742c03ed68f8096f294c6bfa30f0752c82d4c2bfa14bff4dc30d63c9f71a8f9fb64a92743d00807d9e468fafd5ff
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@emnapi/runtime@npm:^1.4.5":
|
||||
version: 1.4.5
|
||||
resolution: "@emnapi/runtime@npm:1.4.5"
|
||||
"@emnapi/runtime@npm:^1.5.0":
|
||||
version: 1.5.0
|
||||
resolution: "@emnapi/runtime@npm:1.5.0"
|
||||
dependencies:
|
||||
tslib: "npm:^2.4.0"
|
||||
checksum: 10c0/37a0278be5ac81e918efe36f1449875cbafba947039c53c65a1f8fc238001b866446fc66041513b286baaff5d6f9bec667f5164b3ca481373a8d9cb65bfc984b
|
||||
checksum: 10c0/a85c9fc4e3af49cbe41e5437e5be2551392a931910cd0a5b5d3572532786927810c9cc1db11b232ec8f9657b33d4e6f7c4f985f1a052917d7cd703b5b2a20faa
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@emnapi/wasi-threads@npm:1.0.4":
|
||||
version: 1.0.4
|
||||
resolution: "@emnapi/wasi-threads@npm:1.0.4"
|
||||
"@emnapi/wasi-threads@npm:1.1.0":
|
||||
version: 1.1.0
|
||||
resolution: "@emnapi/wasi-threads@npm:1.1.0"
|
||||
dependencies:
|
||||
tslib: "npm:^2.4.0"
|
||||
checksum: 10c0/2c91a53e62f875800baf035c4d42c9c0d18e5afd9a31ca2aac8b435aeaeaeaac386b5b3d0d0e70aa7a5a9852bbe05106b1f680cd82cce03145c703b423d41313
|
||||
checksum: 10c0/e6d54bf2b1e64cdd83d2916411e44e579b6ae35d5def0dea61a3c452d9921373044dff32a8b8473ae60c80692bdc39323e98b96a3f3d87ba6886b24dd0ef7ca1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1091,14 +1091,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@napi-rs/wasm-runtime@npm:^1.0.1":
|
||||
version: 1.0.3
|
||||
resolution: "@napi-rs/wasm-runtime@npm:1.0.3"
|
||||
"@napi-rs/wasm-runtime@npm:^1.0.1, @napi-rs/wasm-runtime@npm:^1.0.5":
|
||||
version: 1.0.5
|
||||
resolution: "@napi-rs/wasm-runtime@npm:1.0.5"
|
||||
dependencies:
|
||||
"@emnapi/core": "npm:^1.4.5"
|
||||
"@emnapi/runtime": "npm:^1.4.5"
|
||||
"@tybys/wasm-util": "npm:^0.10.0"
|
||||
checksum: 10c0/7918d82477e75931b6e35bb003464382eb93e526362f81a98bf8610407a67b10f4d041931015ad48072c89db547deb7e471dfb91f4ab11ac63a24d8580297f75
|
||||
"@emnapi/core": "npm:^1.5.0"
|
||||
"@emnapi/runtime": "npm:^1.5.0"
|
||||
"@tybys/wasm-util": "npm:^0.10.1"
|
||||
checksum: 10c0/8d29299933c57b6ead61f46fad5c3dfabc31e1356bbaf25c3a8ae57be0af0db0006a808f2c1bb16e28925e027f20e0856550dac94e015f56dd6ed53b38f9a385
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1579,7 +1579,7 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@tursodatabase/database-browser-common@workspace:packages/browser-common"
|
||||
dependencies:
|
||||
"@tursodatabase/wasm-runtime": "npm:^0.2.0-pre.7"
|
||||
"@napi-rs/wasm-runtime": "npm:^1.0.5"
|
||||
typescript: "npm:^5.9.2"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
@@ -1660,17 +1660,7 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@tursodatabase/wasm-runtime@npm:^0.2.0-pre.7, @tursodatabase/wasm-runtime@workspace:packages/wasm-runtime":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@tursodatabase/wasm-runtime@workspace:packages/wasm-runtime"
|
||||
dependencies:
|
||||
"@emnapi/core": "npm:^1.4.5"
|
||||
"@emnapi/runtime": "npm:^1.4.5"
|
||||
"@tybys/wasm-util": "npm:^0.10.1"
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@tybys/wasm-util@npm:^0.10.0, @tybys/wasm-util@npm:^0.10.1":
|
||||
"@tybys/wasm-util@npm:^0.10.1":
|
||||
version: 0.10.1
|
||||
resolution: "@tybys/wasm-util@npm:0.10.1"
|
||||
dependencies:
|
||||
|
||||
@@ -17,7 +17,6 @@ from pathlib import Path
|
||||
# Define all npm package paths in one place
|
||||
NPM_PACKAGES = [
|
||||
"bindings/javascript",
|
||||
"bindings/javascript/packages/wasm-runtime",
|
||||
"bindings/javascript/packages/common",
|
||||
"bindings/javascript/packages/native",
|
||||
"bindings/javascript/packages/browser",
|
||||
@@ -28,7 +27,6 @@ NPM_PACKAGES = [
|
||||
]
|
||||
|
||||
NPM_WORKSPACE_PACKAGES = [
|
||||
"@tursodatabase/wasm-runtime",
|
||||
"@tursodatabase/database-common",
|
||||
"@tursodatabase/database-browser-common",
|
||||
"@tursodatabase/sync-common",
|
||||
|
||||
Reference in New Issue
Block a user