@atproto/xrpc
Advanced tools
Comparing version 0.0.3 to 0.0.4
import { Lexicons } from '@atproto/lexicon'; | ||
import { FetchHandler, CallOptions, QueryParams, XRPCResponse } from './types'; | ||
import { FetchHandler, FetchHandlerResponse, Headers, CallOptions, QueryParams, XRPCResponse } from './types'; | ||
export declare class Client { | ||
@@ -21,1 +21,2 @@ fetch: FetchHandler; | ||
} | ||
export declare function defaultFetchHandler(httpUri: string, httpMethod: string, httpHeaders: Headers, httpReqBody: unknown): Promise<FetchHandlerResponse>; |
@@ -5,3 +5,3 @@ import { LexXrpcProcedure, LexXrpcQuery } from '@atproto/lexicon'; | ||
export declare function constructMethodCallUri(nsid: string, schema: LexXrpcProcedure | LexXrpcQuery, serviceUri: URL, params?: QueryParams): string; | ||
export declare function encodeQueryParam(type: 'string' | 'number' | 'integer' | 'boolean' | 'datetime' | 'unknown', value: any): string; | ||
export declare function encodeQueryParam(type: 'string' | 'number' | 'integer' | 'boolean' | 'datetime' | 'array' | 'unknown', value: any): string; | ||
export declare function constructMethodCallHeaders(schema: LexXrpcProcedure | LexXrpcQuery, data?: any, opts?: CallOptions): Headers; | ||
@@ -8,0 +8,0 @@ export declare function encodeMethodCallBody(headers: Headers, data?: any): ArrayBuffer | undefined; |
{ | ||
"name": "@atproto/xrpc", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -133,3 +133,3 @@ import { Lexicons, ValidationError } from '@atproto/lexicon' | ||
async function defaultFetchHandler( | ||
export async function defaultFetchHandler( | ||
httpUri: string, | ||
@@ -141,7 +141,11 @@ httpMethod: string, | ||
try { | ||
const res = await fetch(httpUri, { | ||
// The duplex field is now required for streaming bodies, but not yet reflected | ||
// anywhere in docs or types. See whatwg/fetch#1438, nodejs/node#46221. | ||
const reqInit: RequestInit & { duplex: string } = { | ||
method: httpMethod, | ||
headers: httpHeaders, | ||
body: encodeMethodCallBody(httpHeaders, httpReqBody), | ||
}) | ||
duplex: 'half', | ||
} | ||
const res = await fetch(httpUri, reqInit) | ||
const resBody = await res.arrayBuffer() | ||
@@ -148,0 +152,0 @@ return { |
@@ -36,3 +36,13 @@ import { LexXrpcProcedure, LexXrpcQuery } from '@atproto/lexicon' | ||
if (value !== undefined) { | ||
uri.searchParams.set(key, encodeQueryParam(paramSchema.type, value)) | ||
if (paramSchema.type === 'array') { | ||
const vals: typeof value[] = [] | ||
vals.concat(value).forEach((val) => { | ||
uri.searchParams.append( | ||
key, | ||
encodeQueryParam(paramSchema.items.type, val), | ||
) | ||
}) | ||
} else { | ||
uri.searchParams.set(key, encodeQueryParam(paramSchema.type, value)) | ||
} | ||
} | ||
@@ -46,3 +56,10 @@ } | ||
export function encodeQueryParam( | ||
type: 'string' | 'number' | 'integer' | 'boolean' | 'datetime' | 'unknown', | ||
type: | ||
| 'string' | ||
| 'number' | ||
| 'integer' | ||
| 'boolean' | ||
| 'datetime' | ||
| 'array' | ||
| 'unknown', | ||
value: any, | ||
@@ -49,0 +66,0 @@ ): string { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
427474
4791