@orpc/client
Advanced tools
Comparing version 0.0.0-next.b15d206 to 0.0.0-next.b2e67f7
@@ -1,83 +0,90 @@ | ||
// 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"; | ||
function createProcedureClient(options) { | ||
const serializer = new ORPCSerializer(); | ||
const deserializer = new ORPCDeserializer(); | ||
const client = async (input) => { | ||
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.set(key, value); | ||
} | ||
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE); | ||
const response = await fetch_(url, { | ||
method: "POST", | ||
headers, | ||
body | ||
}); | ||
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 | ||
}); | ||
COMMON_ORPC_ERROR_DEFS, | ||
ORPCError, | ||
createAutoRetryEventIterator, | ||
fallbackORPCErrorMessage, | ||
fallbackORPCErrorStatus, | ||
isDefinedError, | ||
mapEventIterator, | ||
onEventIteratorStatusChange, | ||
registerEventIteratorState, | ||
toORPCError, | ||
updateEventIteratorStatus | ||
} from "./chunk-X34KXUAJ.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 Object.assign( | ||
[null, output, false], | ||
{ error: null, data: output, isDefined: false } | ||
); | ||
} catch (e) { | ||
const error = e; | ||
if (isDefinedError(error)) { | ||
return Object.assign( | ||
[error, void 0, true], | ||
{ error, data: void 0, isDefined: true } | ||
); | ||
} | ||
); | ||
return client; | ||
return Object.assign( | ||
[error, void 0, false], | ||
{ error, data: void 0, isDefined: 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.b15d206", | ||
"author": { | ||
"name": "unnoq", | ||
"email": "contact@unnoq.com", | ||
"url": "https://unnoq.com" | ||
}, | ||
"version": "0.0.0-next.b2e67f7", | ||
"license": "MIT", | ||
"homepage": "https://github.com/unnoq/orpc", | ||
"homepage": "https://orpc.unnoq.com", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/unnoq/orpc.git", | ||
"url": "git+https://github.com/unnoq/orpc.git", | ||
"directory": "packages/client" | ||
}, | ||
"keywords": [ | ||
"unnoq" | ||
"unnoq", | ||
"orpc" | ||
], | ||
@@ -26,2 +22,17 @@ "exports": { | ||
}, | ||
"./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,18 +43,16 @@ "types": "./dist/src/*.d.ts" | ||
"files": [ | ||
"dist", | ||
"src" | ||
"!**/*.map", | ||
"!**/*.tsbuildinfo", | ||
"dist" | ||
], | ||
"peerDependencies": { | ||
"@orpc/contract": "0.0.0-next.b15d206", | ||
"@orpc/server": "0.0.0-next.b15d206" | ||
}, | ||
"dependencies": { | ||
"@orpc/transformer": "0.0.0-next.b15d206", | ||
"@orpc/shared": "0.0.0-next.b15d206" | ||
"@orpc/standard-server-fetch": "0.0.0-next.b2e67f7", | ||
"@orpc/shared": "0.0.0-next.b2e67f7", | ||
"@orpc/standard-server": "0.0.0-next.b2e67f7" | ||
}, | ||
"devDependencies": { | ||
"zod": "^3.23.8" | ||
"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", | ||
@@ -50,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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
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
3
27
1281
0
89
50608
2
+ Added@orpc/shared@0.0.0-next.b2e67f7(transitive)
+ Added@orpc/standard-server@0.0.0-next.b2e67f7(transitive)
+ Added@orpc/standard-server-fetch@0.0.0-next.b2e67f7(transitive)
+ Added@tinyhttp/content-disposition@2.2.2(transitive)
- Removed@orpc/transformer@0.0.0-next.b15d206
- Removed@orpc/contract@0.0.0-next.b15d206(transitive)
- Removed@orpc/server@0.0.0-next.b15d206(transitive)
- Removed@orpc/shared@0.0.0-next.b15d206(transitive)
- Removed@orpc/transformer@0.0.0-next.b15d206(transitive)
- Removed@orpc/zod@0.0.0-next.b15d206(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)