rust-fetch 0.7.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -0
- package/package.json +28 -27
- package/rust_fetch.d.ts +106 -0
- package/{wasm-module/pkg/wasm_module.js → rust_fetch.js} +247 -39
- package/rust_fetch_bg.wasm +0 -0
- package/client.ts +0 -14
- package/rust-fetch-package/Cargo.toml +0 -13
- package/rust-fetch-package/src/lib.rs +0 -14
- package/server.ts +0 -13
- package/tsconfig.json +0 -111
- package/wasm-module/Cargo.lock +0 -1387
- package/wasm-module/Cargo.toml +0 -15
- package/wasm-module/client.d.ts +0 -4
- package/wasm-module/client.js +0 -37
- package/wasm-module/pkg/package.json +0 -15
- package/wasm-module/pkg/wasm_module.d.ts +0 -53
- package/wasm-module/pkg/wasm_module_bg.wasm +0 -0
- package/wasm-module/pkg/wasm_module_bg.wasm.d.ts +0 -20
- package/wasm-module/server.d.ts +0 -4
- package/wasm-module/server.js +0 -80
- package/wasm-module/src/greetings/mod.rs +0 -7
- package/wasm-module/src/http/mod.rs +0 -86
- package/wasm-module/src/lib.rs +0 -10
- package/wasm-module/src/math/mod.rs +0 -7
package/wasm-module/Cargo.toml
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "wasm-module"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib", "rlib"]
|
|
8
|
-
|
|
9
|
-
[dependencies]
|
|
10
|
-
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
|
11
|
-
reqwest = { version = "0.11", features = ["json"] }
|
|
12
|
-
serde = { version = "1.0", features = ["derive"] }
|
|
13
|
-
serde_json = "1.0"
|
|
14
|
-
wasm-bindgen-futures = "0.4"
|
|
15
|
-
serde-wasm-bindgen = "0.6"
|
package/wasm-module/client.d.ts
DELETED
package/wasm-module/client.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.initializeWasm = void 0;
|
|
30
|
-
const wasm_module_1 = __importDefault(require("wasm-module"));
|
|
31
|
-
const wasmPromise = (0, wasm_module_1.default)();
|
|
32
|
-
const initializeWasm = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
yield wasmPromise;
|
|
34
|
-
});
|
|
35
|
-
exports.initializeWasm = initializeWasm;
|
|
36
|
-
exports.default = wasm_module_1.default;
|
|
37
|
-
__exportStar(require("wasm-module"), exports);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "wasm-module",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "0.1.0",
|
|
5
|
-
"files": [
|
|
6
|
-
"wasm_module_bg.wasm",
|
|
7
|
-
"wasm_module.js",
|
|
8
|
-
"wasm_module.d.ts"
|
|
9
|
-
],
|
|
10
|
-
"main": "wasm_module.js",
|
|
11
|
-
"types": "wasm_module.d.ts",
|
|
12
|
-
"sideEffects": [
|
|
13
|
-
"./snippets/*"
|
|
14
|
-
]
|
|
15
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export function greet(name: string): string;
|
|
4
|
-
export function fetch_wasm_json_new(url: string): Promise<Promise<any>>;
|
|
5
|
-
export function fetch_wasm_json(url: string): Promise<any>;
|
|
6
|
-
export function fetch_wasm_map(url: string): Promise<any>;
|
|
7
|
-
export function fetch_wasm_html(url: string): Promise<string>;
|
|
8
|
-
export function fetch_wasm_api(): Promise<any>;
|
|
9
|
-
export function add(a: number, b: number): number;
|
|
10
|
-
|
|
11
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
12
|
-
|
|
13
|
-
export interface InitOutput {
|
|
14
|
-
readonly memory: WebAssembly.Memory;
|
|
15
|
-
readonly greet: (a: number, b: number) => [number, number];
|
|
16
|
-
readonly fetch_wasm_json_new: (a: number, b: number) => any;
|
|
17
|
-
readonly fetch_wasm_json: (a: number, b: number) => any;
|
|
18
|
-
readonly fetch_wasm_map: (a: number, b: number) => any;
|
|
19
|
-
readonly fetch_wasm_html: (a: number, b: number) => any;
|
|
20
|
-
readonly fetch_wasm_api: () => any;
|
|
21
|
-
readonly add: (a: number, b: number) => number;
|
|
22
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
23
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
24
|
-
readonly __wbindgen_exn_store: (a: number) => void;
|
|
25
|
-
readonly __externref_table_alloc: () => number;
|
|
26
|
-
readonly __wbindgen_export_4: WebAssembly.Table;
|
|
27
|
-
readonly __wbindgen_export_5: WebAssembly.Table;
|
|
28
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
29
|
-
readonly closure96_externref_shim: (a: number, b: number, c: any) => void;
|
|
30
|
-
readonly closure119_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
31
|
-
readonly __wbindgen_start: () => void;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
35
|
-
/**
|
|
36
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
37
|
-
* a precompiled `WebAssembly.Module`.
|
|
38
|
-
*
|
|
39
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
40
|
-
*
|
|
41
|
-
* @returns {InitOutput}
|
|
42
|
-
*/
|
|
43
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
47
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
48
|
-
*
|
|
49
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
50
|
-
*
|
|
51
|
-
* @returns {Promise<InitOutput>}
|
|
52
|
-
*/
|
|
53
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
Binary file
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export const memory: WebAssembly.Memory;
|
|
4
|
-
export const greet: (a: number, b: number) => [number, number];
|
|
5
|
-
export const fetch_wasm_json_new: (a: number, b: number) => any;
|
|
6
|
-
export const fetch_wasm_json: (a: number, b: number) => any;
|
|
7
|
-
export const fetch_wasm_map: (a: number, b: number) => any;
|
|
8
|
-
export const fetch_wasm_html: (a: number, b: number) => any;
|
|
9
|
-
export const fetch_wasm_api: () => any;
|
|
10
|
-
export const add: (a: number, b: number) => number;
|
|
11
|
-
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
12
|
-
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
13
|
-
export const __wbindgen_exn_store: (a: number) => void;
|
|
14
|
-
export const __externref_table_alloc: () => number;
|
|
15
|
-
export const __wbindgen_export_4: WebAssembly.Table;
|
|
16
|
-
export const __wbindgen_export_5: WebAssembly.Table;
|
|
17
|
-
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
18
|
-
export const closure96_externref_shim: (a: number, b: number, c: any) => void;
|
|
19
|
-
export const closure119_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
20
|
-
export const __wbindgen_start: () => void;
|
package/wasm-module/server.d.ts
DELETED
package/wasm-module/server.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// import init, { greet, add, fetch_wasm_map, fetch_wasm_json } from './wasm-module/pkg/wasm_module';
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
37
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
38
|
-
};
|
|
39
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
40
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
41
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
43
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
44
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
45
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
49
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
50
|
-
};
|
|
51
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
-
exports.initializeWasm = initializeWasm;
|
|
53
|
-
const path = __importStar(require("path"));
|
|
54
|
-
const promises_1 = require("fs/promises");
|
|
55
|
-
const wasm_module_1 = __importDefault(require("wasm-module"));
|
|
56
|
-
const wasmPath = path.join(process.cwd(), 'node_modules', '@asemqaffaf/rust-fetch', 'wasm-module', 'pkg', 'wasm_module_bg.wasm');
|
|
57
|
-
let initialized = false;
|
|
58
|
-
let initPromise = null;
|
|
59
|
-
function initializeWasm() {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const wasmBuffer = yield (0, promises_1.readFile)(wasmPath);
|
|
62
|
-
return yield (0, wasm_module_1.default)(wasmBuffer);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function ensureInitialized() {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
if (!initialized) {
|
|
68
|
-
if (!initPromise) {
|
|
69
|
-
initPromise = initializeWasm();
|
|
70
|
-
}
|
|
71
|
-
yield initPromise;
|
|
72
|
-
initialized = true;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
-
yield ensureInitialized();
|
|
78
|
-
}))();
|
|
79
|
-
exports.default = initializeWasm;
|
|
80
|
-
__exportStar(require("wasm-module"), exports);
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
use wasm_bindgen::prelude::*;
|
|
2
|
-
use wasm_bindgen::JsValue;
|
|
3
|
-
// use wasm_bindgen_futures::JsFuture;
|
|
4
|
-
use reqwest::get;
|
|
5
|
-
use serde_json::Value;
|
|
6
|
-
use serde_wasm_bindgen::to_value;
|
|
7
|
-
// use wasm_bindgen::prelude::*;
|
|
8
|
-
use wasm_bindgen_futures::future_to_promise;
|
|
9
|
-
// use serde_json::Value;
|
|
10
|
-
// use web_sys::Response;
|
|
11
|
-
use js_sys::Promise;
|
|
12
|
-
use wasm_bindgen_futures::js_sys;
|
|
13
|
-
|
|
14
|
-
#[wasm_bindgen]
|
|
15
|
-
pub async fn fetch_wasm_json_new(url: String) -> Promise {
|
|
16
|
-
future_to_promise(async move {
|
|
17
|
-
let response = get(url)
|
|
18
|
-
.await
|
|
19
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
20
|
-
|
|
21
|
-
let json: Value = response
|
|
22
|
-
.json()
|
|
23
|
-
.await
|
|
24
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
25
|
-
|
|
26
|
-
serde_wasm_bindgen::to_value(&json).map_err(|e| JsValue::from_str(&e.to_string()))
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
#[wasm_bindgen]
|
|
31
|
-
pub async fn fetch_wasm_json(url: String) -> Result<JsValue, JsValue> {
|
|
32
|
-
let response = get(url)
|
|
33
|
-
.await
|
|
34
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
35
|
-
|
|
36
|
-
let json: Value = response
|
|
37
|
-
.json()
|
|
38
|
-
.await
|
|
39
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
40
|
-
|
|
41
|
-
// Convert the Value directly to JsValue instead of converting to string
|
|
42
|
-
Ok(JsValue::from_serde(&json).map_err(|e| JsValue::from_str(&e.to_string()))?)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#[wasm_bindgen]
|
|
46
|
-
pub async fn fetch_wasm_map(url: String) -> Result<JsValue, JsValue> {
|
|
47
|
-
let response = get(url)
|
|
48
|
-
.await
|
|
49
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
50
|
-
|
|
51
|
-
let json: Value = response
|
|
52
|
-
.json()
|
|
53
|
-
.await
|
|
54
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
55
|
-
|
|
56
|
-
// Use serde_wasm_bindgen::to_value instead of JsValue::from_serde
|
|
57
|
-
Ok(to_value(&json)?)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
#[wasm_bindgen]
|
|
61
|
-
pub async fn fetch_wasm_html(url: String) -> Result<String, JsValue> {
|
|
62
|
-
let content = get(url)
|
|
63
|
-
.await
|
|
64
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?
|
|
65
|
-
.text()
|
|
66
|
-
.await
|
|
67
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
68
|
-
|
|
69
|
-
Ok(content)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
#[wasm_bindgen]
|
|
73
|
-
pub async fn fetch_wasm_api() -> Result<JsValue, JsValue> {
|
|
74
|
-
let response = get("https://jsonplaceholder.typicode.com/todos/1")
|
|
75
|
-
.await
|
|
76
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
77
|
-
|
|
78
|
-
let content = response
|
|
79
|
-
.json()
|
|
80
|
-
.await
|
|
81
|
-
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
82
|
-
|
|
83
|
-
// Ok(content)
|
|
84
|
-
// Ok(to_value(&content)?)
|
|
85
|
-
Ok(to_value::<serde_json::Value>(&content)?)
|
|
86
|
-
}
|
package/wasm-module/src/lib.rs
DELETED