@orpc/client
Advanced tools
Comparing version 0.0.0-next.d42488d to 0.0.0-next.d5f0415
@@ -1,78 +0,81 @@ | ||
// src/procedure-fetch-client.ts | ||
import { ORPCPayloadCodec } from "@orpc/server/fetch"; | ||
import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared"; | ||
import { ORPCError } from "@orpc/shared/error"; | ||
var payloadCodec = new ORPCPayloadCodec(); | ||
function createProcedureFetchClient(options) { | ||
const client = async (...[input, callerOptions]) => { | ||
const fetchClient = options.fetch ?? fetch; | ||
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`; | ||
const encoded = payloadCodec.encode(input); | ||
const headers = new Headers(encoded.headers); | ||
headers.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE); | ||
let customHeaders = await options.headers?.(input); | ||
customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders); | ||
for (const [key, value] of customHeaders.entries()) { | ||
headers.append(key, value); | ||
} | ||
const response = await fetchClient(url, { | ||
method: "POST", | ||
headers, | ||
body: encoded.body, | ||
signal: callerOptions?.signal | ||
}); | ||
const json = await (async () => { | ||
try { | ||
return await payloadCodec.decode(response); | ||
} catch (e) { | ||
throw new ORPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Cannot parse response.", | ||
cause: e | ||
}); | ||
import { | ||
COMMON_ORPC_ERROR_DEFS, | ||
ORPCError, | ||
createAutoRetryEventIterator, | ||
fallbackORPCErrorMessage, | ||
fallbackORPCErrorStatus, | ||
isDefinedError, | ||
mapEventIterator, | ||
onEventIteratorStatusChange, | ||
registerEventIteratorState, | ||
toORPCError, | ||
updateEventIteratorStatus | ||
} from "./chunk-2UPNYYFF.js"; | ||
// src/client.ts | ||
function createORPCClient(link, options) { | ||
const path = options?.path ?? []; | ||
const procedureClient = async (...[input, options2]) => { | ||
const optionsOut = { | ||
...options2, | ||
context: options2?.context ?? {} | ||
// options.context can be undefined when all field is optional | ||
}; | ||
return await link.call(path, input, optionsOut); | ||
}; | ||
const recursive = new Proxy(procedureClient, { | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
})(); | ||
if (!response.ok) { | ||
throw ORPCError.fromJSON(json) ?? new ORPCError({ | ||
status: response.status, | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Internal server error" | ||
return createORPCClient(link, { | ||
...options, | ||
path: [...path, key] | ||
}); | ||
} | ||
return json; | ||
}; | ||
return client; | ||
}); | ||
return recursive; | ||
} | ||
// src/router-fetch-client.ts | ||
function createRouterFetchClient(options) { | ||
const path = options?.path ?? []; | ||
const client = new Proxy( | ||
createProcedureFetchClient({ | ||
...options, | ||
path | ||
}), | ||
{ | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
return createRouterFetchClient({ | ||
...options, | ||
path: [...path, key] | ||
}); | ||
} | ||
// src/dynamic-link.ts | ||
var DynamicLink = class { | ||
constructor(linkResolver) { | ||
this.linkResolver = linkResolver; | ||
} | ||
async call(path, input, options) { | ||
const resolvedLink = await this.linkResolver(options, path, input); | ||
const output = await resolvedLink.call(path, input, options); | ||
return output; | ||
} | ||
}; | ||
// src/utils.ts | ||
async function safe(promise) { | ||
try { | ||
const output = await promise; | ||
return [output, void 0, false]; | ||
} catch (e) { | ||
const error = e; | ||
if (isDefinedError(error)) { | ||
return [void 0, error, true]; | ||
} | ||
); | ||
return client; | ||
return [void 0, error, false]; | ||
} | ||
} | ||
// src/index.ts | ||
export * from "@orpc/shared/error"; | ||
var createORPCFetchClient = createRouterFetchClient; | ||
export { | ||
createORPCFetchClient, | ||
createProcedureFetchClient, | ||
createRouterFetchClient | ||
COMMON_ORPC_ERROR_DEFS, | ||
DynamicLink, | ||
ORPCError, | ||
createAutoRetryEventIterator, | ||
createORPCClient, | ||
fallbackORPCErrorMessage, | ||
fallbackORPCErrorStatus, | ||
isDefinedError, | ||
mapEventIterator, | ||
onEventIteratorStatusChange, | ||
registerEventIteratorState, | ||
safe, | ||
toORPCError, | ||
updateEventIteratorStatus | ||
}; | ||
//# sourceMappingURL=index.js.map |
/** unnoq */ | ||
import { createRouterFetchClient } from './router-fetch-client'; | ||
export * from './procedure-fetch-client'; | ||
export * from './router-fetch-client'; | ||
export * from '@orpc/shared/error'; | ||
export declare const createORPCFetchClient: typeof createRouterFetchClient; | ||
export * from './client'; | ||
export * from './dynamic-link'; | ||
export * from './error'; | ||
export * from './event-iterator'; | ||
export * from './event-iterator-state'; | ||
export * from './types'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@orpc/client", | ||
"type": "module", | ||
"version": "0.0.0-next.d42488d", | ||
"version": "0.0.0-next.d5f0415", | ||
"license": "MIT", | ||
@@ -22,2 +22,17 @@ "homepage": "https://orpc.unnoq.com", | ||
}, | ||
"./openapi": { | ||
"types": "./dist/src/openapi/index.d.ts", | ||
"import": "./dist/openapi.js", | ||
"default": "./dist/openapi.js" | ||
}, | ||
"./rpc": { | ||
"types": "./dist/src/rpc/index.d.ts", | ||
"import": "./dist/rpc.js", | ||
"default": "./dist/rpc.js" | ||
}, | ||
"./fetch": { | ||
"types": "./dist/src/adapters/fetch/index.d.ts", | ||
"import": "./dist/fetch.js", | ||
"default": "./dist/fetch.js" | ||
}, | ||
"./🔒/*": { | ||
@@ -32,15 +47,12 @@ "types": "./dist/src/*.d.ts" | ||
], | ||
"peerDependencies": { | ||
"@orpc/contract": "0.0.0-next.d42488d" | ||
}, | ||
"dependencies": { | ||
"@orpc/shared": "0.0.0-next.d42488d", | ||
"@orpc/server": "0.0.0-next.d42488d" | ||
"@orpc/server-standard": "^0.4.0", | ||
"@orpc/server-standard-fetch": "^0.4.0", | ||
"@orpc/shared": "0.0.0-next.d5f0415" | ||
}, | ||
"devDependencies": { | ||
"zod": "^3.24.1", | ||
"@orpc/openapi": "0.0.0-next.d42488d" | ||
"zod": "^3.24.1" | ||
}, | ||
"scripts": { | ||
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'", | ||
"build": "tsup --onSuccess='tsc -b --noCheck'", | ||
"build:watch": "pnpm run build --watch", | ||
@@ -47,0 +59,0 @@ "type:check": "tsc -b" |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
52931
1
26
1405
0
89
+ Added@orpc/server-standard@^0.4.0
+ Added@orpc/server-standard@0.4.0(transitive)
+ Added@orpc/server-standard-fetch@0.4.0(transitive)
+ Added@orpc/shared@0.0.0-next.d5f0415(transitive)
+ Added@tinyhttp/content-disposition@2.2.2(transitive)
- Removed@orpc/server@0.0.0-next.d42488d
- Removed@orpc/contract@0.0.0-next.d42488d(transitive)
- Removed@orpc/server@0.0.0-next.d42488d(transitive)
- Removed@orpc/shared@0.0.0-next.d42488d(transitive)
- Removed@standard-schema/spec@1.0.0-beta.4(transitive)
- Removedis-what@5.2.0(transitive)