From 4b439d3273b0692b2b55a8b0582b3d1c245c8ab9 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 4 Sep 2024 11:55:23 +0000 Subject: [PATCH] chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728) * chore: adjust prettier config, .gitignore and use taplo to format toml files This brings the plugins-workspace repository to the same code style of the main tauri repo * format toml * ignore examples gen dir * add .vscode/extensions.json * remove packageManager field * fmt * fix audit * taplo ignore permissions autogenerated files * remove create dummy dist * fix prettier workflow * install fmt in prettier workflow --------- Co-authored-by: Lucas Nogueira Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/10701104849 Co-authored-by: lucasfernog --- Cargo.toml | 6 +-- README.md | 10 ++-- SECURITY.md | 2 +- dist-js/index.cjs | 30 ++++++------ dist-js/index.js | 30 ++++++------ guest-js/index.ts | 122 +++++++++++++++++++++++----------------------- rollup.config.js | 4 +- 7 files changed, 102 insertions(+), 102 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e1e2eb3..925bddd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,11 @@ repository = { workspace = true } links = "tauri-plugin-http" [package.metadata.docs.rs] -rustc-args = [ "--cfg", "docsrs" ] -rustdoc-args = [ "--cfg", "docsrs" ] +rustc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] [build-dependencies] -tauri-plugin = { workspace = true, features = [ "build" ] } +tauri-plugin = { workspace = true, features = ["build"] } schemars = { workspace = true } serde = { workspace = true } url = { workspace = true } diff --git a/README.md b/README.md index b4e7c2b..d6c6a98 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,11 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript -import { fetch } from "@tauri-apps/plugin-http"; -const response = await fetch("http://localhost:3003/users/2", { - method: "GET", - timeout: 30, -}); +import { fetch } from '@tauri-apps/plugin-http' +const response = await fetch('http://localhost:3003/users/2', { + method: 'GET', + timeout: 30 +}) ``` ## Contributing diff --git a/SECURITY.md b/SECURITY.md index 67d831f..4f09bba 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -20,4 +20,4 @@ We prefer to receive reports in English. Please disclose a vulnerability or security relevant issue here: [https://github.com/tauri-apps/plugins-workspace/security/advisories/new](https://github.com/tauri-apps/plugins-workspace/security/advisories/new). -Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app). \ No newline at end of file +Alternatively, you can also contact us by email via [security@tauri.app](mailto:security@tauri.app). diff --git a/dist-js/index.cjs b/dist-js/index.cjs index ee909dc..1e19bc9 100644 --- a/dist-js/index.cjs +++ b/dist-js/index.cjs @@ -28,7 +28,7 @@ var core = require('@tauri-apps/api/core'); * * @module */ -const ERROR_REQUEST_CANCELLED = "Request canceled"; +const ERROR_REQUEST_CANCELLED = 'Request canceled'; /** * Fetch a resource from the network. It returns a `Promise` that resolves to the * `Response` to that `Request`, whether it is successful or not. @@ -83,13 +83,13 @@ async function fetch(input, init) { name, // we need to ensure we have all header values as strings // eslint-disable-next-line - typeof val === "string" ? val : val.toString(), + typeof val === 'string' ? val : val.toString() ]); // abort early here if needed if (signal?.aborted) { throw new Error(ERROR_REQUEST_CANCELLED); } - const rid = await core.invoke("plugin:http|fetch", { + const rid = await core.invoke('plugin:http|fetch', { clientConfig: { method: req.method, url: req.url, @@ -97,10 +97,10 @@ async function fetch(input, init) { data, maxRedirections, connectTimeout, - proxy, - }, + proxy + } }); - const abort = () => core.invoke("plugin:http|fetch_cancel", { rid }); + const abort = () => core.invoke('plugin:http|fetch_cancel', { rid }); // abort early here if needed if (signal?.aborted) { // we don't care about the result of this proimse @@ -108,12 +108,12 @@ async function fetch(input, init) { abort(); throw new Error(ERROR_REQUEST_CANCELLED); } - signal?.addEventListener("abort", () => void abort()); - const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await core.invoke("plugin:http|fetch_send", { - rid, + signal?.addEventListener('abort', () => void abort()); + const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await core.invoke('plugin:http|fetch_send', { + rid }); - const body = await core.invoke("plugin:http|fetch_read_body", { - rid: responseRid, + const body = await core.invoke('plugin:http|fetch_read_body', { + rid: responseRid }); const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0 ? body @@ -121,7 +121,7 @@ async function fetch(input, init) { ? new Uint8Array(body) : null, { status, - statusText, + statusText }); // url and headers are read only properties // but seems like we can set them like this @@ -129,9 +129,9 @@ async function fetch(input, init) { // we define theme like this, because using `Response` // constructor, it removes url and some headers // like `set-cookie` headers - Object.defineProperty(res, "url", { value: url }); - Object.defineProperty(res, "headers", { - value: new Headers(responseHeaders), + Object.defineProperty(res, 'url', { value: url }); + Object.defineProperty(res, 'headers', { + value: new Headers(responseHeaders) }); return res; } diff --git a/dist-js/index.js b/dist-js/index.js index 25b211d..e3e56b9 100644 --- a/dist-js/index.js +++ b/dist-js/index.js @@ -26,7 +26,7 @@ import { invoke } from '@tauri-apps/api/core'; * * @module */ -const ERROR_REQUEST_CANCELLED = "Request canceled"; +const ERROR_REQUEST_CANCELLED = 'Request canceled'; /** * Fetch a resource from the network. It returns a `Promise` that resolves to the * `Response` to that `Request`, whether it is successful or not. @@ -81,13 +81,13 @@ async function fetch(input, init) { name, // we need to ensure we have all header values as strings // eslint-disable-next-line - typeof val === "string" ? val : val.toString(), + typeof val === 'string' ? val : val.toString() ]); // abort early here if needed if (signal?.aborted) { throw new Error(ERROR_REQUEST_CANCELLED); } - const rid = await invoke("plugin:http|fetch", { + const rid = await invoke('plugin:http|fetch', { clientConfig: { method: req.method, url: req.url, @@ -95,10 +95,10 @@ async function fetch(input, init) { data, maxRedirections, connectTimeout, - proxy, - }, + proxy + } }); - const abort = () => invoke("plugin:http|fetch_cancel", { rid }); + const abort = () => invoke('plugin:http|fetch_cancel', { rid }); // abort early here if needed if (signal?.aborted) { // we don't care about the result of this proimse @@ -106,12 +106,12 @@ async function fetch(input, init) { abort(); throw new Error(ERROR_REQUEST_CANCELLED); } - signal?.addEventListener("abort", () => void abort()); - const { status, statusText, url, headers: responseHeaders, rid: responseRid, } = await invoke("plugin:http|fetch_send", { - rid, + signal?.addEventListener('abort', () => void abort()); + const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', { + rid }); - const body = await invoke("plugin:http|fetch_read_body", { - rid: responseRid, + const body = await invoke('plugin:http|fetch_read_body', { + rid: responseRid }); const res = new Response(body instanceof ArrayBuffer && body.byteLength !== 0 ? body @@ -119,7 +119,7 @@ async function fetch(input, init) { ? new Uint8Array(body) : null, { status, - statusText, + statusText }); // url and headers are read only properties // but seems like we can set them like this @@ -127,9 +127,9 @@ async function fetch(input, init) { // we define theme like this, because using `Response` // constructor, it removes url and some headers // like `set-cookie` headers - Object.defineProperty(res, "url", { value: url }); - Object.defineProperty(res, "headers", { - value: new Headers(responseHeaders), + Object.defineProperty(res, 'url', { value: url }); + Object.defineProperty(res, 'headers', { + value: new Headers(responseHeaders) }); return res; } diff --git a/guest-js/index.ts b/guest-js/index.ts index 3eb597c..4362e89 100644 --- a/guest-js/index.ts +++ b/guest-js/index.ts @@ -26,7 +26,7 @@ * @module */ -import { invoke } from "@tauri-apps/api/core"; +import { invoke } from '@tauri-apps/api/core' /** * Configuration of a proxy that a Client should pass requests to. @@ -37,34 +37,34 @@ export interface Proxy { /** * Proxy all traffic to the passed URL. */ - all?: string | ProxyConfig; + all?: string | ProxyConfig /** * Proxy all HTTP traffic to the passed URL. */ - http?: string | ProxyConfig; + http?: string | ProxyConfig /** * Proxy all HTTPS traffic to the passed URL. */ - https?: string | ProxyConfig; + https?: string | ProxyConfig } export interface ProxyConfig { /** * The URL of the proxy server. */ - url: string; + url: string /** * Set the `Proxy-Authorization` header using Basic auth. */ basicAuth?: { - username: string; - password: string; - }; + username: string + password: string + } /** * A configuration for filtering out requests that shouldn't be proxied. * Entries are expected to be comma-separated (whitespace between entries is ignored) */ - noProxy?: string; + noProxy?: string } /** @@ -77,16 +77,16 @@ export interface ClientOptions { * Defines the maximum number of redirects the client should follow. * If set to 0, no redirects will be followed. */ - maxRedirections?: number; + maxRedirections?: number /** Timeout in milliseconds */ - connectTimeout?: number; + connectTimeout?: number /** * Configuration of a proxy that a Client should pass requests to. */ - proxy?: Proxy; + proxy?: Proxy } -const ERROR_REQUEST_CANCELLED = "Request canceled"; +const ERROR_REQUEST_CANCELLED = 'Request canceled' /** * Fetch a resource from the network. It returns a `Promise` that resolves to the @@ -104,41 +104,41 @@ const ERROR_REQUEST_CANCELLED = "Request canceled"; */ export async function fetch( input: URL | Request | string, - init?: RequestInit & ClientOptions, + init?: RequestInit & ClientOptions ): Promise { // abort early here if needed - const signal = init?.signal; + const signal = init?.signal if (signal?.aborted) { - throw new Error(ERROR_REQUEST_CANCELLED); + throw new Error(ERROR_REQUEST_CANCELLED) } - const maxRedirections = init?.maxRedirections; - const connectTimeout = init?.connectTimeout; - const proxy = init?.proxy; + const maxRedirections = init?.maxRedirections + const connectTimeout = init?.connectTimeout + const proxy = init?.proxy // Remove these fields before creating the request if (init) { - delete init.maxRedirections; - delete init.connectTimeout; - delete init.proxy; + delete init.maxRedirections + delete init.connectTimeout + delete init.proxy } const headers = init?.headers ? init.headers instanceof Headers ? init.headers : new Headers(init.headers) - : new Headers(); + : new Headers() - const req = new Request(input, init); - const buffer = await req.arrayBuffer(); + const req = new Request(input, init) + const buffer = await req.arrayBuffer() const data = - buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null; + buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null // append new headers created by the browser `Request` implementation, // if not already declared by the caller of this function for (const [key, value] of req.headers) { if (!headers.get(key)) { - headers.set(key, value); + headers.set(key, value) } } @@ -147,7 +147,7 @@ export async function fetch( ? Array.from(headers.entries()) : Array.isArray(headers) ? headers - : Object.entries(headers); + : Object.entries(headers) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const mappedHeaders: Array<[string, string]> = headersArray.map( @@ -155,16 +155,16 @@ export async function fetch( name, // we need to ensure we have all header values as strings // eslint-disable-next-line - typeof val === "string" ? val : (val as any).toString(), - ], - ); + typeof val === 'string' ? val : (val as any).toString() + ] + ) // abort early here if needed if (signal?.aborted) { - throw new Error(ERROR_REQUEST_CANCELLED); + throw new Error(ERROR_REQUEST_CANCELLED) } - const rid = await invoke("plugin:http|fetch", { + const rid = await invoke('plugin:http|fetch', { clientConfig: { method: req.method, url: req.url, @@ -172,28 +172,28 @@ export async function fetch( data, maxRedirections, connectTimeout, - proxy, - }, - }); + proxy + } + }) - const abort = () => invoke("plugin:http|fetch_cancel", { rid }); + const abort = () => invoke('plugin:http|fetch_cancel', { rid }) // abort early here if needed if (signal?.aborted) { // we don't care about the result of this proimse // eslint-disable-next-line @typescript-eslint/no-floating-promises - abort(); - throw new Error(ERROR_REQUEST_CANCELLED); + abort() + throw new Error(ERROR_REQUEST_CANCELLED) } - signal?.addEventListener("abort", () => void abort()); + signal?.addEventListener('abort', () => void abort()) interface FetchSendResponse { - status: number; - statusText: string; - headers: [[string, string]]; - url: string; - rid: number; + status: number + statusText: string + headers: [[string, string]] + url: string + rid: number } const { @@ -201,17 +201,17 @@ export async function fetch( statusText, url, headers: responseHeaders, - rid: responseRid, - } = await invoke("plugin:http|fetch_send", { - rid, - }); + rid: responseRid + } = await invoke('plugin:http|fetch_send', { + rid + }) const body = await invoke( - "plugin:http|fetch_read_body", + 'plugin:http|fetch_read_body', { - rid: responseRid, - }, - ); + rid: responseRid + } + ) const res = new Response( body instanceof ArrayBuffer && body.byteLength !== 0 @@ -221,9 +221,9 @@ export async function fetch( : null, { status, - statusText, - }, - ); + statusText + } + ) // url and headers are read only properties // but seems like we can set them like this @@ -231,10 +231,10 @@ export async function fetch( // we define theme like this, because using `Response` // constructor, it removes url and some headers // like `set-cookie` headers - Object.defineProperty(res, "url", { value: url }); - Object.defineProperty(res, "headers", { - value: new Headers(responseHeaders), - }); + Object.defineProperty(res, 'url', { value: url }) + Object.defineProperty(res, 'headers', { + value: new Headers(responseHeaders) + }) - return res; + return res } diff --git a/rollup.config.js b/rollup.config.js index 977dfac..1f349ec 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,6 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -import { createConfig } from "../../shared/rollup.config.js"; +import { createConfig } from '../../shared/rollup.config.js' -export default createConfig(); +export default createConfig()