Compare commits

..

5 Commits

Author SHA1 Message Date
semantic-release-bot 3948839aa1 chore(release): 0.2.0-develop.6 [skip ci]
# [0.2.0-develop.6](https://git.lumeweb.com/LumeWeb/libportal/compare/v0.2.0-develop.5...v0.2.0-develop.6) (2023-06-24)

### Bug Fixes

* better handle wasm loading on node and browser ([23c8244](23c8244a68))
* fix uploading in node due to issues around streams and blobs ([adacdff](adacdff1c3))
* import needs to be relative, not hash ([a9e94ba](a9e94ba896))
2023-06-24 03:44:31 +00:00
Derrick Hammer 76910d6253
Merge remote-tracking branch 'origin/develop' into develop 2023-06-23 23:42:47 -04:00
Derrick Hammer adacdff1c3
fix: fix uploading in node due to issues around streams and blobs 2023-06-23 23:42:30 -04:00
Derrick Hammer 23c8244a68
fix: better handle wasm loading on node and browser 2023-06-23 23:41:27 -04:00
Derrick Hammer a9e94ba896
fix: import needs to be relative, not hash 2023-06-23 20:43:51 -04:00
5 changed files with 207 additions and 21 deletions

183
npm-shrinkwrap.json generated
View File

@ -1,18 +1,19 @@
{
"name": "@lumeweb/libportal",
"version": "0.2.0-develop.5",
"version": "0.2.0-develop.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/libportal",
"version": "0.2.0-develop.5",
"version": "0.2.0-develop.6",
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",
"cross-fetch": "^3.1.6",
"detect-node": "^2.1.0",
"multiformats": "^11.0.2",
"node-fetch": "^3.3.1",
"p-defer": "^4.0.0",
"stream-to-blob": "^2.0.1",
"tus-js-client": "^3.1.0",
@ -1805,6 +1806,26 @@
"node": ">= 14"
}
},
"node_modules/@octokit/request/node_modules/node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"dev": true,
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/@octokit/tsconfig": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@octokit/tsconfig/-/tsconfig-2.0.0.tgz",
@ -4794,6 +4815,25 @@
"node-fetch": "^2.6.11"
}
},
"node_modules/cross-fetch/node_modules/node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@ -4862,6 +4902,14 @@
"node": ">=8"
}
},
"node_modules/data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
"engines": {
"node": ">= 12"
}
},
"node_modules/dateformat": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
@ -6114,6 +6162,28 @@
"bser": "2.1.1"
}
},
"node_modules/fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "paypal",
"url": "https://paypal.me/jimmywarting"
}
],
"dependencies": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
},
"engines": {
"node": "^12.20 || >= 14.13"
}
},
"node_modules/figures": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@ -6228,6 +6298,17 @@
"is-callable": "^1.1.3"
}
},
"node_modules/formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"dependencies": {
"fetch-blob": "^3.1.2"
},
"engines": {
"node": ">=12.20.0"
}
},
"node_modules/from2": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz",
@ -9520,6 +9601,24 @@
"dev": true,
"peer": true
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "github",
"url": "https://paypal.me/jimmywarting"
}
],
"engines": {
"node": ">=10.5.0"
}
},
"node_modules/node-emoji": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz",
@ -9530,22 +9629,20 @@
}
},
"node_modules/node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz",
"integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==",
"dependencies": {
"whatwg-url": "^5.0.0"
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
},
"engines": {
"node": "4.x || >=6.0.0"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
}
},
"node_modules/node-gyp": {
@ -19112,6 +19209,17 @@
"is-plain-object": "^5.0.0",
"node-fetch": "^2.6.7",
"universal-user-agent": "^6.0.0"
},
"dependencies": {
"node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"dev": true,
"requires": {
"whatwg-url": "^5.0.0"
}
}
}
},
"@octokit/request-error": {
@ -21361,6 +21469,16 @@
"integrity": "sha512-riRvo06crlE8HiqOwIpQhxwdOk4fOeR7FVM/wXoxchFEqMNUjvbs3bfo4OTgMEMHzppd4DxFBDbyySj8Cv781g==",
"requires": {
"node-fetch": "^2.6.11"
},
"dependencies": {
"node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"requires": {
"whatwg-url": "^5.0.0"
}
}
}
},
"cross-spawn": {
@ -21409,6 +21527,11 @@
"dev": true,
"peer": true
},
"data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="
},
"dateformat": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
@ -22381,6 +22504,15 @@
"bser": "2.1.1"
}
},
"fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"requires": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
}
},
"figures": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@ -22467,6 +22599,14 @@
"is-callable": "^1.1.3"
}
},
"formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"requires": {
"fetch-blob": "^3.1.2"
}
},
"from2": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz",
@ -25009,6 +25149,11 @@
"dev": true,
"peer": true
},
"node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="
},
"node-emoji": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz",
@ -25019,11 +25164,13 @@
}
},
"node-fetch": {
"version": "2.6.11",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz",
"integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==",
"requires": {
"whatwg-url": "^5.0.0"
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
}
},
"node-gyp": {

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/libportal",
"version": "0.2.0-develop.5",
"version": "0.2.0-develop.6",
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
@ -39,6 +39,7 @@
"cross-fetch": "^3.1.6",
"detect-node": "^2.1.0",
"multiformats": "^11.0.2",
"node-fetch": "^3.3.1",
"p-defer": "^4.0.0",
"stream-to-blob": "^2.0.1",
"tus-js-client": "^3.1.0",

View File

@ -212,6 +212,17 @@ export class Client {
if (!(fetchOptions.body instanceof _FormData)) {
fetchOptions.headers["Content-Type"] = "application/json";
fetchOptions.body = JSON.stringify(fetchOptions.body);
} else {
if (isNode) {
const formDataToBlob = (
await import("formdata-polyfill/formdata-to-blob.js")
).formDataToBlob;
const Blob = (await import("node-fetch")).Blob;
const blob = formDataToBlob(fetchOptions.body, Blob);
// @ts-ignore
fetchOptions.body = Buffer.from(await blob.arrayBuffer());
fetchOptions.headers["Content-Type"] = blob.type;
}
}
}
@ -281,6 +292,8 @@ export class Client {
hashStream?: any,
size?: bigint,
): Promise<string> {
const Blob = await this.getBlobObject();
if (stream instanceof Uint8Array || stream instanceof Blob) {
size = BigInt(stream.length);
}
@ -306,6 +319,8 @@ export class Client {
private async uploadFileSmall(stream: Uint8Array): Promise<string>;
private async uploadFileSmall(stream: NodeJS.ReadableStream): Promise<string>;
private async uploadFileSmall(stream: any): Promise<string> {
const Blob = await this.getBlobObject();
if (stream instanceof ReadableStream) {
stream = await streamToBlob(stream);
}
@ -514,6 +529,13 @@ export class Client {
return FormData;
}
private async getBlobObject() {
if (isNode) {
return (await import("node-fetch")).Blob;
}
return Blob;
}
private async getNodeReadableObject() {
if (isNode) {

View File

@ -1,6 +1,6 @@
// @ts-ignore
import baoWasm from "./wasm/bao.wasm";
import Go from "#go_wasm.js";
import baoWasm from "./wasm.js";
import Go from "./go_wasm.js";
export async function getVerifiableStream(
root: Uint8Array,

16
src/wasm.ts Normal file
View File

@ -0,0 +1,16 @@
import isNode from "detect-node";
export default async function (imports) {
if (isNode) {
const fs = await import("fs/promises");
// @ts-ignore
const wasmPath = new URL("wasm/bao.wasm", import.meta.url);
const wasm = await fs.readFile(wasmPath);
return WebAssembly.instantiate(wasm, imports);
}
// @ts-ignore
return await import("./wasm/bao.wasm");
}