@tomphttp/bare-client
Advanced tools
Comparing version 1.1.2-beta.3 to 2.0.0-beta
@@ -1,70 +0,5 @@ | ||
export * from './Client'; | ||
export declare type BareMethod = 'GET' | 'POST' | 'DELETE' | 'OPTIONS' | 'PUT' | 'PATCH' | 'UPDATE' | string; | ||
export declare type BareCache = 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached' | string; | ||
export interface XBare { | ||
status?: number; | ||
statusText?: string; | ||
headers?: Headers; | ||
rawHeaders?: BareHeaders; | ||
} | ||
export declare type BareHTTPProtocol = 'blob:' | 'http:' | 'https:' | string; | ||
export declare type BareWSProtocol = 'ws:' | 'wss:' | string; | ||
export declare type urlLike = URL | string; | ||
export declare const maxRedirects = 20; | ||
export declare type BareHeaders = { | ||
[key: string]: string | string[]; | ||
}; | ||
/** | ||
* WebSocket with an additional property. | ||
*/ | ||
export declare type BareWebSocket = WebSocket & { | ||
meta: Promise<XBare>; | ||
}; | ||
/** | ||
* A Response with additional properties. | ||
*/ | ||
export declare type BareResponse = Response & { | ||
rawResponse: Response; | ||
rawHeaders: BareHeaders; | ||
}; | ||
/** | ||
* A BareResponse with additional properties. | ||
*/ | ||
export declare type BareResponseFetch = BareResponse & { | ||
finalURL: string; | ||
}; | ||
export declare type BareBodyInit = Blob | BufferSource | FormData | URLSearchParams | ReadableStream | undefined | null; | ||
export declare type BareFetchInit = { | ||
method?: BareMethod; | ||
headers?: Headers | BareHeaders; | ||
body?: BareBodyInit; | ||
cache?: BareCache; | ||
redirect?: 'follow' | 'manual' | 'error' | string; | ||
signal?: AbortSignal; | ||
}; | ||
export declare type BareMaintainer = { | ||
email?: string; | ||
website?: string; | ||
}; | ||
export declare type BareProject = { | ||
name?: string; | ||
description?: string; | ||
email?: string; | ||
website?: string; | ||
repository?: string; | ||
version?: string; | ||
}; | ||
export declare type BareLanguage = 'NodeJS' | 'ServiceWorker' | 'Deno' | 'Java' | 'PHP' | 'Rust' | 'C' | 'C++' | 'C#' | 'Ruby' | 'Go' | 'Crystal' | 'Shell' | string; | ||
export declare type BareManifest = { | ||
maintainer?: BareMaintainer; | ||
project?: BareProject; | ||
versions: string[]; | ||
language: BareLanguage; | ||
memoryUsage?: number; | ||
}; | ||
export default class BareClient { | ||
/** | ||
* @depricated Use .manifest instead. | ||
*/ | ||
get data(): BareClient['manfiest']; | ||
import type { BareHeaders, BareManifest, BareResponseFetch, BareWebSocket, urlLike } from './BareTypes'; | ||
import type { WebSocketImpl } from './Client'; | ||
export declare function fetchManifest(server: string | URL, signal?: AbortSignal): Promise<BareManifest>; | ||
export declare class BareClient { | ||
manfiest?: BareManifest; | ||
@@ -88,22 +23,12 @@ private client?; | ||
constructor(server: string | URL, manfiest?: BareManifest); | ||
private loadManifest; | ||
private demand; | ||
private getClient; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, protocol: BareHTTPProtocol, host: string, port: string | number, path: string, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
connect(requestHeaders: BareHeaders, protocol: BareWSProtocol, host: string, port: string | number, path: string): Promise<BareWebSocket>; | ||
/** | ||
* | ||
* @param url | ||
* @param headers | ||
* @param protocols | ||
* @returns | ||
* @param readyStateHook A callback executed by this function with helper arguments for hooking the readyState property. If a hook isn't provided, bare-client will hook the property on the instance. Hooking it on an instance basis is good for small projects, but ideally the class should be hooked by the user of bare-client. | ||
* @param sendHook A callback executed by this function with helper arguments for hooking the send function. If a hook isn't provided, bare-client will hook the function on the instance. | ||
*/ | ||
createWebSocket(url: urlLike, headers?: BareHeaders | Headers, protocols?: string | string[]): Promise<BareWebSocket>; | ||
fetch(url: urlLike | Request, init?: BareFetchInit): Promise<BareResponseFetch>; | ||
createWebSocket(remote: urlLike, protocols?: string | string[] | undefined, headers?: BareHeaders | Headers | undefined, readyStateHook?: ((socket: WebSocket, getReadyState: () => number) => void) | undefined, sendHook?: ((socket: WebSocket, getSendError: () => Error | undefined) => void) | undefined, webSocketImpl?: WebSocketImpl): BareWebSocket; | ||
fetch(url: urlLike | Request, init?: RequestInit): Promise<BareResponseFetch>; | ||
} | ||
/** | ||
* | ||
* Facilitates fetching the Bare server and constructing a BareClient. | ||
* @param server Bare server | ||
* @param signal Abort signal when fetching the manifest | ||
*/ | ||
export declare function createBareClient(server: string | URL, signal?: AbortSignal): Promise<BareClient>; |
@@ -1,2 +0,2 @@ | ||
import type { BareBodyInit, BareCache, BareHeaders, BareHTTPProtocol, BareMethod, BareResponse, BareWebSocket, BareWSProtocol } from './BareClient'; | ||
import type { BareBodyInit, BareCache, BareHeaders, BareMethod, BareResponse, BareWebSocketMeta } from './BareTypes.js'; | ||
export declare const statusEmpty: number[]; | ||
@@ -15,7 +15,10 @@ export declare const statusRedirect: number[]; | ||
} | ||
export interface GenericClient { | ||
connect(requestHeaders: BareHeaders, protocol: BareWSProtocol, host: string, port: string | number, path: string): Promise<BareWebSocket>; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, protocol: BareHTTPProtocol, host: string, port: string | number, path: string, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
} | ||
export default class Client { | ||
export declare type MetaCallback = (meta: BareWebSocketMeta) => void; | ||
export declare type ReadyStateCallback = (readyState: number) => void; | ||
export declare type WebSocketImpl = { | ||
new (...args: ConstructorParameters<typeof WebSocket>): WebSocket; | ||
}; | ||
export declare abstract class Client { | ||
abstract connect(remote: URL, protocols: string[], requestHeaders: BareHeaders, onMeta: MetaCallback, onReadyState: ReadyStateCallback, webSocketImpl: WebSocketImpl): WebSocket; | ||
abstract request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, remote: URL, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
protected base: URL; | ||
@@ -22,0 +25,0 @@ /** |
@@ -1,1 +0,11 @@ | ||
export { createBareClient as default } from './BareClient'; | ||
import { BareClient } from './BareClient'; | ||
export { BareClient }; | ||
export * from './Client'; | ||
export * from './BareTypes'; | ||
/** | ||
* | ||
* Facilitates fetching the Bare server and constructing a BareClient. | ||
* @param server Bare server | ||
* @param signal Abort signal when fetching the manifest | ||
*/ | ||
export declare function createBareClient(server: string | URL, signal?: AbortSignal): Promise<BareClient>; |
@@ -29,1 +29,10 @@ export declare const fetch: typeof globalThis.fetch; | ||
}; | ||
export declare const WebSocketFields: { | ||
prototype: { | ||
send: (data: string | Blob | ArrayBufferView | ArrayBufferLike) => void; | ||
}; | ||
CLOSED: number; | ||
CLOSING: number; | ||
CONNECTING: number; | ||
OPEN: number; | ||
}; |
@@ -1,5 +0,5 @@ | ||
import type { BareBodyInit, BareCache, BareHeaders, BareHTTPProtocol, BareMethod, BareResponse, BareWebSocket, BareWSProtocol } from './BareClient.js'; | ||
import type { GenericClient } from './Client.js'; | ||
import Client from './Client.js'; | ||
export default class ClientV1 extends Client implements GenericClient { | ||
import type { BareBodyInit, BareCache, BareHeaders, BareMethod, BareResponse, BareWebSocket, BareWebSocket2 } from './BareTypes'; | ||
import type { GenericClient } from './Client'; | ||
import { LegacyClient } from './Client'; | ||
export default class ClientV1 extends LegacyClient implements GenericClient { | ||
ws: URL; | ||
@@ -10,6 +10,7 @@ http: URL; | ||
constructor(server: URL); | ||
connect(requestHeaders: BareHeaders, protocol: BareWSProtocol, host: string, port: string | number, path: string): Promise<BareWebSocket>; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, protocol: BareHTTPProtocol, host: string, port: string | number, path: string, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
connect(): BareWebSocket2; | ||
legacyConnect(requestHeaders: BareHeaders, remote: URL): Promise<BareWebSocket>; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, remote: URL, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
private readBareResponse; | ||
private writeBareRequest; | ||
} |
@@ -1,5 +0,5 @@ | ||
import type { BareBodyInit, BareCache, BareHeaders, BareHTTPProtocol, BareMethod, BareResponse, BareWebSocket, BareWSProtocol } from './BareClient'; | ||
import type { GenericClient } from './Client'; | ||
import Client from './Client'; | ||
export default class ClientV2 extends Client implements GenericClient { | ||
import type { BareBodyInit, BareCache, BareHeaders, BareMethod, BareResponse, BareWebSocket } from './BareTypes.js'; | ||
import { LegacyClient } from './Client.js'; | ||
import type { GenericClient } from './Client.js'; | ||
export default class ClientV2 extends LegacyClient implements GenericClient { | ||
ws: URL; | ||
@@ -10,6 +10,6 @@ http: URL; | ||
constructor(server: URL); | ||
connect(requestHeaders: BareHeaders, protocol: BareWSProtocol, host: string, port: string | number, path: string): Promise<BareWebSocket>; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, protocol: BareHTTPProtocol, host: string, port: string | number, path: string, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
legacyConnect(requestHeaders: BareHeaders, remote: URL): Promise<BareWebSocket>; | ||
request(method: BareMethod, requestHeaders: BareHeaders, body: BareBodyInit, remote: URL, cache: BareCache | undefined, signal: AbortSignal | undefined): Promise<BareResponse>; | ||
private readBareResponse; | ||
createBareHeaders(protocol: BareWSProtocol | BareHTTPProtocol, host: string, path: string, port: number | string, bareHeaders: BareHeaders, forwardHeaders?: string[], passHeaders?: string[], passStatus?: number[]): Headers; | ||
createBareHeaders(remote: URL, bareHeaders: BareHeaders, forwardHeaders?: string[], passHeaders?: string[], passStatus?: number[]): Headers; | ||
} |
{ | ||
"name": "@tomphttp/bare-client", | ||
"version": "1.1.2-beta.3", | ||
"version": "2.0.0-beta", | ||
"homepage": "https://github.com/tomphttp", | ||
@@ -20,14 +20,14 @@ "bugs": { | ||
"build": "rollup -c", | ||
"build:watch": "rollup -cw" | ||
"watch": "rollup -cw" | ||
}, | ||
"type": "module", | ||
"license": "GPL-3.0", | ||
"license": "LGPL-3.0", | ||
"exports": { | ||
"import": "./dist/BareClient.js", | ||
"require": "./dist/BareClient.cjs" | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"browser": "dist/BareClient.cjs", | ||
"main": "dist/BareClient.cjs", | ||
"module": "dist/BareClient.js", | ||
"types": "dist/BareClient.d.ts", | ||
"browser": "dist/index.cjs", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
@@ -37,12 +37,11 @@ "dist" | ||
"devDependencies": { | ||
"@ianvs/prettier-plugin-sort-imports": "^3.4.2", | ||
"@rollup/plugin-inject": "^4.0.4", | ||
"@typescript-eslint/eslint-plugin": "^5.31.0", | ||
"@typescript-eslint/parser": "^5.31.0", | ||
"eslint": "^8.20.0", | ||
"prettier": "^2.7.1", | ||
"rollup": "^2.77.2", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-typescript2": "^0.32.1" | ||
"@ianvs/prettier-plugin-sort-imports": "^3.7.2", | ||
"@rollup/plugin-inject": "^5.0.3", | ||
"@typescript-eslint/eslint-plugin": "^5.59.7", | ||
"@typescript-eslint/parser": "^5.59.7", | ||
"eslint": "^8.41.0", | ||
"prettier": "^2.8.8", | ||
"rollup": "^3.23.0", | ||
"rollup-plugin-typescript2": "^0.34.1" | ||
} | ||
} |
@@ -12,3 +12,16 @@ # Bare Client | ||
```html | ||
<script src="https://unpkg.com/@tomphttp/bare-client@1.1.0/dist/BareClient.cjs"></script> | ||
<script src="https://unpkg.com/@tomphttp/bare-client@placeholder/dist/bare.cjs"></script> | ||
<script> | ||
console.log(bare); // { createBareClient: ..., BareClient: ... } | ||
bare.createBareClient('http://localhost:8080/bare/').then(async (client) => { | ||
const res = await client.fetch('https://api.github.com/orgs/tomphttp', { | ||
headers: { | ||
'user-agent': navigator.userAgent, // user-agent must be passed otherwise the API gives a 403 | ||
}, | ||
}); | ||
console.log(await res.json()); // {login: 'tomphttp', id: 98234273, ... } | ||
}); | ||
</script> | ||
``` | ||
@@ -19,5 +32,25 @@ | ||
```sh | ||
$ npm i @tomphttp/bare-client | ||
npm i @tomphttp/bare-client | ||
``` | ||
```js | ||
import { createBareClient } from '@tomphttp/bare-client'; | ||
createBareClient('http://localhost:8080/bare/'); // ... | ||
``` | ||
See [examples/](examples/). | ||
## Notice | ||
`client.fetch` isn't 1:1 to JavaScript's `fetch`. It doesn't accept a `Request` as an argument due to the headers on the `Request` being "managed": | ||
```js | ||
const a = new Headers(); // unmanaged `Headers` | ||
a.set('user-agent', 'test'); | ||
a.get('user-agent'); // "test" | ||
const b = new Request(location.toString()).headers; // managed `Headers` | ||
b.set('user-agent', 'test'); | ||
b.get('user-agent'); // null | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
344535
8
21
3042
55