rust-fetch 0.7.1 → 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.
@@ -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"
@@ -1,4 +0,0 @@
1
- import initWasm from 'wasm-module';
2
- export declare const initializeWasm: () => Promise<void>;
3
- export default initWasm;
4
- export * from 'wasm-module';
@@ -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,4 +0,0 @@
1
- import { InitOutput } from 'wasm-module';
2
- export declare function initializeWasm(): Promise<InitOutput>;
3
- export default initializeWasm;
4
- export * from 'wasm-module';
@@ -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,7 +0,0 @@
1
- use wasm_bindgen::prelude::*;
2
-
3
- #[wasm_bindgen]
4
- pub fn greet(name: &str) -> String {
5
- format!("Hello, {}!", name)
6
- }
7
-
@@ -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
- }
@@ -1,10 +0,0 @@
1
- // use wasm_bindgen::prelude::*;
2
-
3
- pub mod greetings;
4
- pub mod http;
5
- pub mod math;
6
-
7
- // Re-export all public items from modules
8
- pub use greetings::*;
9
- pub use http::*;
10
- pub use math::*;
@@ -1,7 +0,0 @@
1
- use wasm_bindgen::prelude::*;
2
-
3
- #[wasm_bindgen]
4
- pub fn add(a: i32, b: i32) -> i32 {
5
- a + b
6
- }
7
-