@orpc/client
Advanced tools
Comparing version 0.0.0-next.2f8ca7f to 0.0.0-next.30f4fa7
@@ -1,82 +0,81 @@ | ||
// src/procedure.ts | ||
import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract"; | ||
import { trim } from "@orpc/shared"; | ||
import { ORPCError } from "@orpc/shared/error"; | ||
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer"; | ||
var serializer = new ORPCSerializer(); | ||
var deserializer = new ORPCDeserializer(); | ||
function createProcedureClient(options) { | ||
const client = async (...args) => { | ||
const [input, callerOptions] = args; | ||
const fetch_ = options.fetch ?? fetch; | ||
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`; | ||
let headers = await options.headers?.(input); | ||
headers = headers instanceof Headers ? headers : new Headers(headers); | ||
const { body, headers: headers_ } = serializer.serialize(input); | ||
for (const [key, value] of headers_.entries()) { | ||
headers.append(key, value); | ||
} | ||
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE); | ||
const response = await fetch_(url, { | ||
method: "POST", | ||
headers, | ||
body, | ||
signal: callerOptions?.signal | ||
}); | ||
const json = await (async () => { | ||
try { | ||
return await deserializer.deserialize(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.ts | ||
function createRouterClient(options) { | ||
const path = options?.path ?? []; | ||
const client = new Proxy( | ||
createProcedureClient({ | ||
baseURL: options.baseURL, | ||
fetch: options.fetch, | ||
headers: options.headers, | ||
path | ||
}), | ||
{ | ||
get(target, key) { | ||
if (typeof key !== "string") { | ||
return Reflect.get(target, key); | ||
} | ||
return createRouterClient({ | ||
...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 createORPCClient = createRouterClient; | ||
export { | ||
COMMON_ORPC_ERROR_DEFS, | ||
DynamicLink, | ||
ORPCError, | ||
createAutoRetryEventIterator, | ||
createORPCClient, | ||
createProcedureClient, | ||
createRouterClient | ||
fallbackORPCErrorMessage, | ||
fallbackORPCErrorStatus, | ||
isDefinedError, | ||
mapEventIterator, | ||
onEventIteratorStatusChange, | ||
registerEventIteratorState, | ||
safe, | ||
toORPCError, | ||
updateEventIteratorStatus | ||
}; | ||
//# sourceMappingURL=index.js.map |
/** unnoq */ | ||
import { createRouterClient } from './router'; | ||
export * from './procedure'; | ||
export * from './router'; | ||
export * from '@orpc/shared/error'; | ||
export declare const createORPCClient: typeof createRouterClient; | ||
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.2f8ca7f", | ||
"version": "0.0.0-next.30f4fa7", | ||
"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,16 +47,12 @@ "types": "./dist/src/*.d.ts" | ||
], | ||
"peerDependencies": { | ||
"@orpc/contract": "0.0.0-next.2f8ca7f", | ||
"@orpc/server": "0.0.0-next.2f8ca7f" | ||
}, | ||
"dependencies": { | ||
"@orpc/transformer": "0.0.0-next.2f8ca7f", | ||
"@orpc/shared": "0.0.0-next.2f8ca7f" | ||
"@orpc/server-standard": "^0.4.0", | ||
"@orpc/server-standard-fetch": "^0.4.0", | ||
"@orpc/shared": "0.0.0-next.30f4fa7" | ||
}, | ||
"devDependencies": { | ||
"zod": "^3.23.8", | ||
"@orpc/openapi": "0.0.0-next.2f8ca7f" | ||
"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", | ||
@@ -48,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
48057
3
1
25
1405
+ 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.30f4fa7(transitive)
+ Added@tinyhttp/content-disposition@2.2.2(transitive)
- Removed@orpc/transformer@0.0.0-next.2f8ca7f
- Removed@orpc/contract@0.0.0-next.2f8ca7f(transitive)
- Removed@orpc/server@0.0.0-next.2f8ca7f(transitive)
- Removed@orpc/shared@0.0.0-next.2f8ca7f(transitive)
- Removed@orpc/transformer@0.0.0-next.2f8ca7f(transitive)
- Removed@orpc/zod@0.0.0-next.2f8ca7f(transitive)
- Removed@types/content-disposition@0.5.8(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedfast-content-type-parse@2.0.1(transitive)
- Removedis-what@5.2.0(transitive)
- Removedjson-schema-typed@8.0.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedwildcard-match@5.1.4(transitive)
- Removedzod@3.24.2(transitive)