@orpc/client
Advanced tools
| import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.me25pt7v.mjs'; | ||
| import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch'; | ||
| import { m as mapEventIterator } from './client.BLtwTQUg.mjs'; | ||
| class CompositeStandardLinkPlugin { | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0)); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| plugin.init?.(options); | ||
| } | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, sender, options = {}) { | ||
| this.codec = codec; | ||
| this.sender = sender; | ||
| const plugin = new CompositeStandardLinkPlugin(options.plugins); | ||
| plugin.init(options); | ||
| this.interceptors = toArray(options.interceptors); | ||
| this.clientInterceptors = toArray(options.clientInterceptors); | ||
| } | ||
| interceptors; | ||
| clientInterceptors; | ||
| call(path, input, options) { | ||
| return runWithSpan( | ||
| { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal }, | ||
| (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_input", signal: options.signal }, | ||
| input | ||
| ); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otelConfig = getGlobalOtelConfig(); | ||
| let otelContext; | ||
| const currentSpan = otelConfig?.trace.getActiveSpan() ?? span; | ||
| if (currentSpan && otelConfig) { | ||
| otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan); | ||
| } | ||
| const request = await runWithSpan( | ||
| { name: "encode_request", context: otelContext }, | ||
| () => this.codec.encode(path2, input2, options2) | ||
| ); | ||
| const response = await intercept( | ||
| this.clientInterceptors, | ||
| { ...options2, input: input2, path: path2, request }, | ||
| ({ input: input3, path: path3, request: request2, ...options3 }) => { | ||
| return runWithSpan( | ||
| { name: "send_request", signal: options3.signal, context: otelContext }, | ||
| () => this.sender.call(request2, options3, path3, input3) | ||
| ); | ||
| } | ||
| ); | ||
| const output = await runWithSpan( | ||
| { name: "decode_response", context: otelContext }, | ||
| () => this.codec.decode(response, options2, path2, input2) | ||
| ); | ||
| if (isAsyncIteratorObject(output)) { | ||
| return asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_output", signal: options2.signal }, | ||
| output | ||
| ); | ||
| } | ||
| return output; | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = { | ||
| BIGINT: 0, | ||
| DATE: 1, | ||
| NAN: 2, | ||
| UNDEFINED: 3, | ||
| URL: 4, | ||
| REGEXP: 5, | ||
| SET: 6, | ||
| MAP: 7 | ||
| }; | ||
| class StandardRPCJsonSerializer { | ||
| customSerializers; | ||
| constructor(options = {}) { | ||
| this.customSerializers = options.customJsonSerializers ?? []; | ||
| if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) { | ||
| throw new Error("Custom serializer type must be unique."); | ||
| } | ||
| } | ||
| serialize(data, segments = [], meta = [], maps = [], blobs = []) { | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.condition(data)) { | ||
| const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs); | ||
| meta.push([custom.type, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (typeof data === "bigint") { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]); | ||
| if (Number.isNaN(data.getTime())) { | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| return [data.toISOString(), meta, maps, blobs]; | ||
| } | ||
| if (Number.isNaN(data)) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]); | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serialize(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]); | ||
| return result; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| if (v === void 0) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]); | ||
| return null; | ||
| } | ||
| return this.serialize(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| if (k === "toJSON" && typeof data[k] === "function") { | ||
| continue; | ||
| } | ||
| json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(json, meta, maps, getBlob) { | ||
| const ref = { data: json }; | ||
| if (maps && getBlob) { | ||
| maps.forEach((segments, i) => { | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| segments.forEach((segment) => { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segment; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| }); | ||
| currentRef[preSegment] = getBlob(i); | ||
| }); | ||
| } | ||
| for (const item of meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| } | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.type === type) { | ||
| currentRef[preSegment] = custom.deserialize(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| switch (type) { | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT: | ||
| currentRef[preSegment] = BigInt(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE: | ||
| currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date"); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN: | ||
| currentRef[preSegment] = Number.NaN; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED: | ||
| currentRef[preSegment] = void 0; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL: | ||
| currentRef[preSegment] = new URL(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: { | ||
| const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/); | ||
| currentRef[preSegment] = new RegExp(pattern, flags); | ||
| break; | ||
| } | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET: | ||
| currentRef[preSegment] = new Set(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP: | ||
| currentRef[preSegment] = new Map(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| function toHttpPath(path) { | ||
| return `/${path.map(encodeURIComponent).join("/")}`; | ||
| } | ||
| function toStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders$1(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| function getMalformedResponseErrorCode(status) { | ||
| return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE"; | ||
| } | ||
| class StandardRPCLinkCodec { | ||
| constructor(serializer, options) { | ||
| this.serializer = serializer; | ||
| this.baseUrl = options.url; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| } | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| async encode(path, input, options) { | ||
| let headers = toStandardHeaders(await value(this.headers, options, path, input)); | ||
| if (options.lastEventId !== void 0) { | ||
| headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId }); | ||
| } | ||
| const expectedMethod = await value(this.expectedMethod, options, path, input); | ||
| const baseUrl = await value(this.baseUrl, options, path, input); | ||
| const url = new URL(baseUrl); | ||
| url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const getUrl = new URL(url); | ||
| getUrl.searchParams.append("data", stringifyJSON(serialized)); | ||
| if (getUrl.toString().length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: getUrl, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decode(response) { | ||
| const isOk = !isORPCErrorStatus(response.status); | ||
| const deserialized = await (async () => { | ||
| let isBodyOk = false; | ||
| try { | ||
| const body = await response.body(); | ||
| isBodyOk = true; | ||
| return this.serializer.deserialize(body); | ||
| } catch (error) { | ||
| if (!isBodyOk) { | ||
| throw new Error("Cannot parse response body, please check the response body and content-type.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| throw createORPCErrorFromJson(deserialized); | ||
| } | ||
| throw new ORPCError(getMalformedResponseErrorCode(response.status), { | ||
| status: response.status, | ||
| data: { ...response, body: deserialized } | ||
| }); | ||
| } | ||
| return deserialized; | ||
| } | ||
| } | ||
| class StandardRPCSerializer { | ||
| constructor(jsonSerializer) { | ||
| this.jsonSerializer = jsonSerializer; | ||
| } | ||
| serialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#serialize(value, false), | ||
| error: async (e) => { | ||
| return new ErrorEvent({ | ||
| data: this.#serialize(toORPCError(e).toJSON(), false), | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#serialize(data, true); | ||
| } | ||
| #serialize(data, enableFormData) { | ||
| const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (!enableFormData || blobs.length === 0) { | ||
| return { | ||
| json, | ||
| meta | ||
| }; | ||
| } | ||
| const form = new FormData(); | ||
| form.set("data", stringifyJSON({ json, meta, maps })); | ||
| blobs.forEach((blob, i) => { | ||
| form.set(i.toString(), blob); | ||
| }); | ||
| return form; | ||
| } | ||
| deserialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#deserialize(value), | ||
| error: async (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.#deserialize(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent({ | ||
| data: deserialized, | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#deserialize(data); | ||
| } | ||
| #deserialize(data) { | ||
| if (data === void 0) { | ||
| return void 0; | ||
| } | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data.json, data.meta ?? []); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| return this.jsonSerializer.deserialize( | ||
| serialized.json, | ||
| serialized.meta ?? [], | ||
| serialized.maps, | ||
| (i) => data.get(i.toString()) | ||
| ); | ||
| } | ||
| } | ||
| class StandardRPCLink extends StandardLink { | ||
| constructor(linkClient, options) { | ||
| const jsonSerializer = new StandardRPCJsonSerializer(options); | ||
| const serializer = new StandardRPCSerializer(jsonSerializer); | ||
| const linkCodec = new StandardRPCLinkCodec(serializer, options); | ||
| super(linkCodec, linkClient, options); | ||
| } | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t }; |
| import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared'; | ||
| const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| const ORPC_CLIENT_PACKAGE_VERSION = "1.14.4"; | ||
| const COMMON_ORPC_ERROR_DEFS = { | ||
| BAD_REQUEST: { | ||
| status: 400, | ||
| message: "Bad Request" | ||
| }, | ||
| UNAUTHORIZED: { | ||
| status: 401, | ||
| message: "Unauthorized" | ||
| }, | ||
| FORBIDDEN: { | ||
| status: 403, | ||
| message: "Forbidden" | ||
| }, | ||
| NOT_FOUND: { | ||
| status: 404, | ||
| message: "Not Found" | ||
| }, | ||
| METHOD_NOT_SUPPORTED: { | ||
| status: 405, | ||
| message: "Method Not Supported" | ||
| }, | ||
| NOT_ACCEPTABLE: { | ||
| status: 406, | ||
| message: "Not Acceptable" | ||
| }, | ||
| TIMEOUT: { | ||
| status: 408, | ||
| message: "Request Timeout" | ||
| }, | ||
| CONFLICT: { | ||
| status: 409, | ||
| message: "Conflict" | ||
| }, | ||
| PRECONDITION_FAILED: { | ||
| status: 412, | ||
| message: "Precondition Failed" | ||
| }, | ||
| PAYLOAD_TOO_LARGE: { | ||
| status: 413, | ||
| message: "Payload Too Large" | ||
| }, | ||
| UNSUPPORTED_MEDIA_TYPE: { | ||
| status: 415, | ||
| message: "Unsupported Media Type" | ||
| }, | ||
| UNPROCESSABLE_CONTENT: { | ||
| status: 422, | ||
| message: "Unprocessable Content" | ||
| }, | ||
| TOO_MANY_REQUESTS: { | ||
| status: 429, | ||
| message: "Too Many Requests" | ||
| }, | ||
| CLIENT_CLOSED_REQUEST: { | ||
| status: 499, | ||
| message: "Client Closed Request" | ||
| }, | ||
| INTERNAL_SERVER_ERROR: { | ||
| status: 500, | ||
| message: "Internal Server Error" | ||
| }, | ||
| NOT_IMPLEMENTED: { | ||
| status: 501, | ||
| message: "Not Implemented" | ||
| }, | ||
| BAD_GATEWAY: { | ||
| status: 502, | ||
| message: "Bad Gateway" | ||
| }, | ||
| SERVICE_UNAVAILABLE: { | ||
| status: 503, | ||
| message: "Service Unavailable" | ||
| }, | ||
| GATEWAY_TIMEOUT: { | ||
| status: 504, | ||
| message: "Gateway Timeout" | ||
| } | ||
| }; | ||
| function fallbackORPCErrorStatus(code, status) { | ||
| return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500; | ||
| } | ||
| function fallbackORPCErrorMessage(code, message) { | ||
| return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code; | ||
| } | ||
| const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`); | ||
| void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| class ORPCError extends Error { | ||
| defined; | ||
| code; | ||
| status; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| if (options.status !== void 0 && !isORPCErrorStatus(options.status)) { | ||
| throw new Error("[ORPCError] Invalid error status code."); | ||
| } | ||
| const message = fallbackORPCErrorMessage(code, options.message); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.status = fallbackORPCErrorStatus(code, options.status); | ||
| this.defined = options.defined ?? false; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| code: this.code, | ||
| status: this.status, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (globalORPCErrorConstructors.has(this)) { | ||
| const constructor = getConstructor(instance); | ||
| if (constructor && globalORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| } | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| } | ||
| globalORPCErrorConstructors.add(ORPCError); | ||
| function isDefinedError(error) { | ||
| return error instanceof ORPCError && error.defined; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { | ||
| message: "Internal server error", | ||
| cause: error | ||
| }); | ||
| } | ||
| function isORPCErrorStatus(status) { | ||
| return status < 200 || status >= 400; | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "code", "status", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| return new ORPCError(json.code, { | ||
| ...options, | ||
| ...json | ||
| }); | ||
| } | ||
| export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t }; |
| import { toArray, intercept } from '@orpc/shared'; | ||
| import { toFetchRequest, toStandardLazyResponse } from '@orpc/standard-server-fetch'; | ||
| import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.BCGbA0RK.mjs'; | ||
| import { C as CompositeStandardLinkPlugin, c as StandardRPCLink } from '../../shared/client.DbOybvnL.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.BOWJmQzx.mjs'; | ||
| import '../../shared/client.me25pt7v.mjs'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; | ||
@@ -7,0 +7,0 @@ |
| import { value, isObject } from '@orpc/shared'; | ||
| import { experimental_ClientPeerWithoutCodec, serializeRequestMessage, encodeRequestMessage, deserializeResponseMessage, decodeResponseMessage } from '@orpc/standard-server-peer'; | ||
| import { c as StandardRPCLink } from '../../shared/client.BCGbA0RK.mjs'; | ||
| import { c as StandardRPCLink } from '../../shared/client.DbOybvnL.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.BOWJmQzx.mjs'; | ||
| import '../../shared/client.me25pt7v.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BLtwTQUg.mjs'; |
@@ -1,6 +0,6 @@ | ||
| export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.BCGbA0RK.mjs'; | ||
| export { C as CompositeStandardLinkPlugin, a as STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES, S as StandardLink, b as StandardRPCJsonSerializer, c as StandardRPCLink, d as StandardRPCLinkCodec, e as StandardRPCSerializer, g as getMalformedResponseErrorCode, t as toHttpPath, f as toStandardHeaders } from '../../shared/client.DbOybvnL.mjs'; | ||
| import '@orpc/shared'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.BOWJmQzx.mjs'; | ||
| import '../../shared/client.me25pt7v.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
| import '../../shared/client.BLtwTQUg.mjs'; |
| import { readAsBuffer } from '@orpc/shared'; | ||
| import { ClientPeer } from '@orpc/standard-server-peer'; | ||
| import { c as StandardRPCLink } from '../../shared/client.BCGbA0RK.mjs'; | ||
| import { c as StandardRPCLink } from '../../shared/client.DbOybvnL.mjs'; | ||
| import '@orpc/standard-server'; | ||
| import '../../shared/client.BOWJmQzx.mjs'; | ||
| import '../../shared/client.me25pt7v.mjs'; | ||
| import '@orpc/standard-server-fetch'; | ||
@@ -7,0 +7,0 @@ import '../../shared/client.BLtwTQUg.mjs'; |
+1
-1
@@ -210,3 +210,3 @@ import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.i2uoJbEp.mjs'; | ||
| declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.3"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.4"; | ||
@@ -213,0 +213,0 @@ /** |
+1
-1
@@ -210,3 +210,3 @@ import { N as NestedClient, C as ClientLink, I as InferClientContext, a as ClientPromiseResult, b as ClientContext, F as FriendlyClientOptions, c as ClientOptions, d as Client, e as ClientRest } from './shared/client.i2uoJbEp.js'; | ||
| declare const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.3"; | ||
| declare const ORPC_CLIENT_PACKAGE_VERSION = "1.14.4"; | ||
@@ -213,0 +213,0 @@ /** |
+2
-2
| import { preventNativeAwait, isTypescriptObject } from '@orpc/shared'; | ||
| export { AsyncIteratorClass, EventPublisher, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared'; | ||
| import { i as isDefinedError } from './shared/client.BOWJmQzx.mjs'; | ||
| export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, t as toORPCError } from './shared/client.BOWJmQzx.mjs'; | ||
| import { i as isDefinedError } from './shared/client.me25pt7v.mjs'; | ||
| export { C as COMMON_ORPC_ERROR_DEFS, c as ORPCError, O as ORPC_CLIENT_PACKAGE_NAME, a as ORPC_CLIENT_PACKAGE_VERSION, g as createORPCErrorFromJson, b as fallbackORPCErrorMessage, f as fallbackORPCErrorStatus, e as isORPCErrorJson, d as isORPCErrorStatus, t as toORPCError } from './shared/client.me25pt7v.mjs'; | ||
| export { m as mapEventIterator } from './shared/client.BLtwTQUg.mjs'; | ||
@@ -6,0 +6,0 @@ export { ErrorEvent, getEventMeta, withEventMeta } from '@orpc/standard-server'; |
| import { isAsyncIteratorObject, defer, value, splitInHalf, toArray, stringifyJSON, overlayProxy, AsyncIteratorClass } from '@orpc/shared'; | ||
| import { toBatchRequest, parseBatchResponse, toBatchAbortSignal } from '@orpc/standard-server/batch'; | ||
| import { replicateStandardLazyResponse, getEventMeta, flattenHeader } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS } from '../shared/client.BOWJmQzx.mjs'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS } from '../shared/client.me25pt7v.mjs'; | ||
@@ -6,0 +6,0 @@ class BatchLinkPlugin { |
+5
-5
| { | ||
| "name": "@orpc/client", | ||
| "type": "module", | ||
| "version": "1.14.3", | ||
| "version": "1.14.4", | ||
| "license": "MIT", | ||
@@ -52,6 +52,6 @@ "homepage": "https://orpc.dev", | ||
| "dependencies": { | ||
| "@orpc/shared": "1.14.3", | ||
| "@orpc/standard-server": "1.14.3", | ||
| "@orpc/standard-server-fetch": "1.14.3", | ||
| "@orpc/standard-server-peer": "1.14.3" | ||
| "@orpc/shared": "1.14.4", | ||
| "@orpc/standard-server": "1.14.4", | ||
| "@orpc/standard-server-fetch": "1.14.4", | ||
| "@orpc/standard-server-peer": "1.14.4" | ||
| }, | ||
@@ -58,0 +58,0 @@ "devDependencies": { |
+42
-34
@@ -111,2 +111,10 @@ <div align="center"> | ||
| ### 🥉 Bronze Sponsor | ||
| <table> | ||
| <tr> | ||
| <td align="center"><a href="https://plancraft.com/?ref=orpc" target="_blank" rel="noopener" title="plancraft"><img src="https://avatars.githubusercontent.com/u/46482287?v=4" width="167" alt="plancraft"/><br />plancraft</a></td> | ||
| </tr> | ||
| </table> | ||
| ### Generous Sponsors | ||
@@ -116,3 +124,3 @@ | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="167" alt="LN Markets"/><br />LN Markets</a></td> | ||
| <td align="center"><a href="https://github.com/ln-markets?ref=orpc" target="_blank" rel="noopener" title="LN Markets"><img src="https://avatars.githubusercontent.com/u/70597625?v=4" width="139" alt="LN Markets"/><br />LN Markets</a></td> | ||
| </tr> | ||
@@ -125,22 +133,23 @@ </table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="139" alt="Reece McDonald"/><br />Reece McDonald</a></td> | ||
| <td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&v=4" width="139" alt="nk"/><br />nk</a></td> | ||
| <td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="139" alt="supastarter"/><br />supastarter</a></td> | ||
| <td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&v=4" width="139" alt="Dexter Miguel"/><br />Dexter Miguel</a></td> | ||
| <td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&v=4" width="139" alt="herrfugbaum"/><br />herrfugbaum</a></td> | ||
| <td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&v=4" width="139" alt="Ryota Murakami"/><br />Ryota Murakami</a></td> | ||
| <td align="center"><a href="https://github.com/hrmcdonald?ref=orpc" target="_blank" rel="noopener" title="Reece McDonald"><img src="https://avatars.githubusercontent.com/u/39349270?v=4" width="119" alt="Reece McDonald"/><br />Reece McDonald</a></td> | ||
| <td align="center"><a href="https://github.com/nicognaW?ref=orpc" target="_blank" rel="noopener" title="nk"><img src="https://avatars.githubusercontent.com/u/66731869?u=4699bda3a9092d3ec34fbd959450767bcc8b8b6d&v=4" width="119" alt="nk"/><br />nk</a></td> | ||
| <td align="center"><a href="https://github.com/supastarter?ref=orpc" target="_blank" rel="noopener" title="supastarter"><img src="https://avatars.githubusercontent.com/u/110960143?v=4" width="119" alt="supastarter"/><br />supastarter</a></td> | ||
| <td align="center"><a href="https://github.com/divmgl?ref=orpc" target="_blank" rel="noopener" title="Dexter Miguel"><img src="https://avatars.githubusercontent.com/u/5452298?u=645993204be8696c085ecf0d228c3062efe2ed65&v=4" width="119" alt="Dexter Miguel"/><br />Dexter Miguel</a></td> | ||
| <td align="center"><a href="https://github.com/herrfugbaum?ref=orpc" target="_blank" rel="noopener" title="herrfugbaum"><img src="https://avatars.githubusercontent.com/u/12859776?u=644dc1666d0220bc0468eb0de3c56b919f635b16&v=4" width="119" alt="herrfugbaum"/><br />herrfugbaum</a></td> | ||
| <td align="center"><a href="https://github.com/ryota-murakami?ref=orpc" target="_blank" rel="noopener" title="Ryota Murakami"><img src="https://avatars.githubusercontent.com/u/5501268?u=599389e03340734325726ca3f8f423c021d47d7f&v=4" width="119" alt="Ryota Murakami"/><br />Ryota Murakami</a></td> | ||
| <td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="119" alt="David Cramer"/><br />David Cramer</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/dcramer?ref=orpc" target="_blank" rel="noopener" title="David Cramer"><img src="https://avatars.githubusercontent.com/u/23610?v=4" width="139" alt="David Cramer"/><br />David Cramer</a></td> | ||
| <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="139" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td> | ||
| <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="139" alt="Valerii Strilets"/><br />Valerii Strilets</a></td> | ||
| <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="139" alt="Kyle Mistele"/><br />Kyle Mistele</a></td> | ||
| <td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="139" alt="Andrew Peters"/><br />Andrew Peters</a></td> | ||
| <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="139" alt="Ryan Vogel"/><br />Ryan Vogel</a></td> | ||
| <td align="center"><a href="https://github.com/valerii15298?ref=orpc" target="_blank" rel="noopener" title="Valerii Petryniak"><img src="https://avatars.githubusercontent.com/u/44531564?u=88ac74d9bacd20401518441907acad21063cd397&v=4" width="119" alt="Valerii Petryniak"/><br />Valerii Petryniak</a></td> | ||
| <td align="center"><a href="https://github.com/letstri?ref=orpc" target="_blank" rel="noopener" title="Valerii Strilets"><img src="https://avatars.githubusercontent.com/u/13253748?u=c7b10399ccc8f8081e24db94ec32cd9858e86ac3&v=4" width="119" alt="Valerii Strilets"/><br />Valerii Strilets</a></td> | ||
| <td align="center"><a href="https://github.com/K-Mistele?ref=orpc" target="_blank" rel="noopener" title="Kyle Mistele"><img src="https://avatars.githubusercontent.com/u/18430555?u=3afebeb81de666e35aaac3ed46f14159d7603ffb&v=4" width="119" alt="Kyle Mistele"/><br />Kyle Mistele</a></td> | ||
| <td align="center"><a href="https://github.com/andrewpeters9?ref=orpc" target="_blank" rel="noopener" title="Andrew Peters"><img src="https://avatars.githubusercontent.com/u/36251325?v=4" width="119" alt="Andrew Peters"/><br />Andrew Peters</a></td> | ||
| <td align="center"><a href="https://github.com/R44VC0RP?ref=orpc" target="_blank" rel="noopener" title="Ryan Vogel"><img src="https://avatars.githubusercontent.com/u/89211796?u=1857347b9787d8d8a7ea5bfc333f96be92d5a683&v=4" width="119" alt="Ryan Vogel"/><br />Ryan Vogel</a></td> | ||
| <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="119" alt="christ12938"/><br />christ12938</a></td> | ||
| <td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="119" alt="Peter Adam"/><br />Peter Adam</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/christ12938?ref=orpc" target="_blank" rel="noopener" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="139" alt="christ12938"/><br />christ12938</a></td> | ||
| <td align="center"><a href="https://github.com/peter-adam-dy?ref=orpc" target="_blank" rel="noopener" title="Peter Adam"><img src="https://avatars.githubusercontent.com/u/132129459?u=4f3dbbb3b443990b56acb7d6a5d11ed2c555f6db&v=4" width="139" alt="Peter Adam"/><br />Peter Adam</a></td> | ||
| <td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&v=4" width="139" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td> | ||
| <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="139" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td> | ||
| <td align="center"><a href="https://github.com/yukimotochern?ref=orpc" target="_blank" rel="noopener" title="Chen, Zhi-Yuan"><img src="https://avatars.githubusercontent.com/u/20896173?u=945c33fc21725e4d566a0d02afc54b136ca1d67a&v=4" width="119" alt="Chen, Zhi-Yuan"/><br />Chen, Zhi-Yuan</a></td> | ||
| <td align="center"><a href="https://github.com/Ryanjso?ref=orpc" target="_blank" rel="noopener" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&v=4" width="119" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td> | ||
| <td align="center"><a href="https://github.com/itigoore01?ref=orpc" target="_blank" rel="noopener" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&v=4" width="119" alt="shota"/><br />shota</a></td> | ||
| </tr> | ||
@@ -153,22 +162,21 @@ </table> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&v=4" width="119" alt="David Walsh"/><br />David Walsh</a></td> | ||
| <td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&v=4" width="119" alt="Robbe Vaes"/><br />Robbe Vaes</a></td> | ||
| <td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="119" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td> | ||
| <td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&v=4" width="119" alt="soonoo"/><br />soonoo</a></td> | ||
| <td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&v=4" width="119" alt="Kevin Porten"/><br />Kevin Porten</a></td> | ||
| <td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="119" alt="Denis"/><br />Denis</a></td> | ||
| <td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="119" alt="Christopher Kapic"/><br />Christopher Kapic</a></td> | ||
| <td align="center"><a href="https://github.com/rhinodavid?ref=orpc" target="_blank" rel="noopener" title="David Walsh"><img src="https://avatars.githubusercontent.com/u/5778036?u=b5521f07d2f88c3db2a0dae62b5f2f8357214af0&v=4" width="104" alt="David Walsh"/><br />David Walsh</a></td> | ||
| <td align="center"><a href="https://github.com/ChromeGG?ref=orpc" target="_blank" rel="noopener" title="Adam Tkaczyk"><img src="https://avatars.githubusercontent.com/u/39050595?u=a58ca6042a6950e94e6e92442db76ef584279bc0&v=4" width="104" alt="Adam Tkaczyk"/><br />Adam Tkaczyk</a></td> | ||
| <td align="center"><a href="https://github.com/Robbe95?ref=orpc" target="_blank" rel="noopener" title="Robbe Vaes"><img src="https://avatars.githubusercontent.com/u/44748019?u=e0232402c045ad4eac7cbd217f1f47e083103b89&v=4" width="104" alt="Robbe Vaes"/><br />Robbe Vaes</a></td> | ||
| <td align="center"><a href="https://github.com/aidansunbury?ref=orpc" target="_blank" rel="noopener" title="Aidan Sunbury"><img src="https://avatars.githubusercontent.com/u/64103161?v=4" width="104" alt="Aidan Sunbury"/><br />Aidan Sunbury</a></td> | ||
| <td align="center"><a href="https://github.com/soonoo?ref=orpc" target="_blank" rel="noopener" title="soonoo"><img src="https://avatars.githubusercontent.com/u/5436405?u=5d0b4aa955c87e30e6bda7f0cccae5402da99528&v=4" width="104" alt="soonoo"/><br />soonoo</a></td> | ||
| <td align="center"><a href="https://github.com/kporten?ref=orpc" target="_blank" rel="noopener" title="Kevin Porten"><img src="https://avatars.githubusercontent.com/u/1839345?u=dc2263d5cfe0d927ce1a0be04a1d55dd6b55405c&v=4" width="104" alt="Kevin Porten"/><br />Kevin Porten</a></td> | ||
| <td align="center"><a href="https://github.com/pumpkinlink?ref=orpc" target="_blank" rel="noopener" title="Denis"><img src="https://avatars.githubusercontent.com/u/11864620?u=5f47bbe6c65d0f6f5cf011021490238e4b0593d0&v=4" width="104" alt="Denis"/><br />Denis</a></td> | ||
| <td align="center"><a href="https://github.com/christopher-kapic?ref=orpc" target="_blank" rel="noopener" title="Christopher Kapic"><img src="https://avatars.githubusercontent.com/u/59740769?u=e7ad4b72b5bf6c9eb1644c26dbf3332a8f987377&v=4" width="104" alt="Christopher Kapic"/><br />Christopher Kapic</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="119" alt="Tom Ballinger"/><br />Tom Ballinger</a></td> | ||
| <td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="119" alt="Sam"/><br />Sam</a></td> | ||
| <td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="119" alt="Titoine"/><br />Titoine</a></td> | ||
| <td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="119" alt="Igor Makowski"/><br />Igor Makowski</a></td> | ||
| <td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&v=4" width="119" alt="Anees Iqbal"/><br />Anees Iqbal</a></td> | ||
| <td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="wang chenyu"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="119" alt="wang chenyu"/><br />wang chenyu</a></td> | ||
| <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="119" alt="Alex"/><br />Alex</a></td> | ||
| <td align="center"><a href="https://github.com/thomasballinger?ref=orpc" target="_blank" rel="noopener" title="Tom Ballinger"><img src="https://avatars.githubusercontent.com/u/458879?u=4b045ac75d721b6ac2b42a74d7d37f61f0414031&v=4" width="104" alt="Tom Ballinger"/><br />Tom Ballinger</a></td> | ||
| <td align="center"><a href="https://github.com/SSam0419?ref=orpc" target="_blank" rel="noopener" title="Sam"><img src="https://avatars.githubusercontent.com/u/102863520?u=3c89611f549d5070be232eb4532f690c8f2e7a65&v=4" width="104" alt="Sam"/><br />Sam</a></td> | ||
| <td align="center"><a href="https://github.com/Titoine?ref=orpc" target="_blank" rel="noopener" title="Titoine"><img src="https://avatars.githubusercontent.com/u/3514286?u=1bb1e86b0c99c8a1121372e56d51a177eea12191&v=4" width="104" alt="Titoine"/><br />Titoine</a></td> | ||
| <td align="center"><a href="https://github.com/Mnigos?ref=orpc" target="_blank" rel="noopener" title="Igor Makowski"><img src="https://avatars.githubusercontent.com/u/56691628?u=ee8c879478f7c151b9156aef6c74243fa3e247a8&v=4" width="104" alt="Igor Makowski"/><br />Igor Makowski</a></td> | ||
| <td align="center"><a href="https://github.com/steelbrain?ref=orpc" target="_blank" rel="noopener" title="Anees Iqbal"><img src="https://avatars.githubusercontent.com/u/4278113?u=22b80b5399eed68ac76cd58b02961b0481f1db11&v=4" width="104" alt="Anees Iqbal"/><br />Anees Iqbal</a></td> | ||
| <td align="center"><a href="https://github.com/hanayashiki?ref=orpc" target="_blank" rel="noopener" title="hanayashiki"><img src="https://avatars.githubusercontent.com/u/26056783?u=06c3b9205a16fd41a871e82da1cc2a09306d53f5&v=4" width="104" alt="hanayashiki"/><br />hanayashiki</a></td> | ||
| <td align="center"><a href="https://github.com/piscis?ref=orpc" target="_blank" rel="noopener" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&v=4" width="104" alt="Alex"/><br />Alex</a></td> | ||
| <td align="center"><a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="104" alt="nattstack"/><br />nattstack</a></td> | ||
| </tr> | ||
| <tr> | ||
| <td align="center"><a href="https://github.com/nattstack?ref=orpc" target="_blank" rel="noopener" title="nattstack"><img src="https://avatars.githubusercontent.com/u/31426677?u=fa9dbb8b3e66eb0ea3c88db5dc07f31c8c5418fe&v=4" width="119" alt="nattstack"/><br />nattstack</a></td> | ||
| </tr> | ||
| </table> | ||
@@ -175,0 +183,0 @@ |
| import { toArray, runWithSpan, ORPC_NAME, isAsyncIteratorObject, asyncIteratorWithSpan, intercept, getGlobalOtelConfig, isObject, value, stringifyJSON } from '@orpc/shared'; | ||
| import { mergeStandardHeaders, ErrorEvent } from '@orpc/standard-server'; | ||
| import { C as COMMON_ORPC_ERROR_DEFS, d as isORPCErrorStatus, e as isORPCErrorJson, g as createORPCErrorFromJson, c as ORPCError, t as toORPCError } from './client.BOWJmQzx.mjs'; | ||
| import { toStandardHeaders as toStandardHeaders$1 } from '@orpc/standard-server-fetch'; | ||
| import { m as mapEventIterator } from './client.BLtwTQUg.mjs'; | ||
| class CompositeStandardLinkPlugin { | ||
| plugins; | ||
| constructor(plugins = []) { | ||
| this.plugins = [...plugins].sort((a, b) => (a.order ?? 0) - (b.order ?? 0)); | ||
| } | ||
| init(options) { | ||
| for (const plugin of this.plugins) { | ||
| plugin.init?.(options); | ||
| } | ||
| } | ||
| } | ||
| class StandardLink { | ||
| constructor(codec, sender, options = {}) { | ||
| this.codec = codec; | ||
| this.sender = sender; | ||
| const plugin = new CompositeStandardLinkPlugin(options.plugins); | ||
| plugin.init(options); | ||
| this.interceptors = toArray(options.interceptors); | ||
| this.clientInterceptors = toArray(options.clientInterceptors); | ||
| } | ||
| interceptors; | ||
| clientInterceptors; | ||
| call(path, input, options) { | ||
| return runWithSpan( | ||
| { name: `${ORPC_NAME}.${path.join("/")}`, signal: options.signal }, | ||
| (span) => { | ||
| span?.setAttribute("rpc.system", ORPC_NAME); | ||
| span?.setAttribute("rpc.method", path.join(".")); | ||
| if (isAsyncIteratorObject(input)) { | ||
| input = asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_input", signal: options.signal }, | ||
| input | ||
| ); | ||
| } | ||
| return intercept(this.interceptors, { ...options, path, input }, async ({ path: path2, input: input2, ...options2 }) => { | ||
| const otelConfig = getGlobalOtelConfig(); | ||
| let otelContext; | ||
| const currentSpan = otelConfig?.trace.getActiveSpan() ?? span; | ||
| if (currentSpan && otelConfig) { | ||
| otelContext = otelConfig?.trace.setSpan(otelConfig.context.active(), currentSpan); | ||
| } | ||
| const request = await runWithSpan( | ||
| { name: "encode_request", context: otelContext }, | ||
| () => this.codec.encode(path2, input2, options2) | ||
| ); | ||
| const response = await intercept( | ||
| this.clientInterceptors, | ||
| { ...options2, input: input2, path: path2, request }, | ||
| ({ input: input3, path: path3, request: request2, ...options3 }) => { | ||
| return runWithSpan( | ||
| { name: "send_request", signal: options3.signal, context: otelContext }, | ||
| () => this.sender.call(request2, options3, path3, input3) | ||
| ); | ||
| } | ||
| ); | ||
| const output = await runWithSpan( | ||
| { name: "decode_response", context: otelContext }, | ||
| () => this.codec.decode(response, options2, path2, input2) | ||
| ); | ||
| if (isAsyncIteratorObject(output)) { | ||
| return asyncIteratorWithSpan( | ||
| { name: "consume_event_iterator_output", signal: options2.signal }, | ||
| output | ||
| ); | ||
| } | ||
| return output; | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
| const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES = { | ||
| BIGINT: 0, | ||
| DATE: 1, | ||
| NAN: 2, | ||
| UNDEFINED: 3, | ||
| URL: 4, | ||
| REGEXP: 5, | ||
| SET: 6, | ||
| MAP: 7 | ||
| }; | ||
| class StandardRPCJsonSerializer { | ||
| customSerializers; | ||
| constructor(options = {}) { | ||
| this.customSerializers = options.customJsonSerializers ?? []; | ||
| if (this.customSerializers.length !== new Set(this.customSerializers.map((custom) => custom.type)).size) { | ||
| throw new Error("Custom serializer type must be unique."); | ||
| } | ||
| } | ||
| serialize(data, segments = [], meta = [], maps = [], blobs = []) { | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.condition(data)) { | ||
| const result = this.serialize(custom.serialize(data), segments, meta, maps, blobs); | ||
| meta.push([custom.type, ...segments]); | ||
| return result; | ||
| } | ||
| } | ||
| if (data instanceof Blob) { | ||
| maps.push(segments); | ||
| blobs.push(data); | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| if (typeof data === "bigint") { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Date) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE, ...segments]); | ||
| if (Number.isNaN(data.getTime())) { | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| return [data.toISOString(), meta, maps, blobs]; | ||
| } | ||
| if (Number.isNaN(data)) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN, ...segments]); | ||
| return [null, meta, maps, blobs]; | ||
| } | ||
| if (data instanceof URL) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof RegExp) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP, ...segments]); | ||
| return [data.toString(), meta, maps, blobs]; | ||
| } | ||
| if (data instanceof Set) { | ||
| const result = this.serialize(Array.from(data), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET, ...segments]); | ||
| return result; | ||
| } | ||
| if (data instanceof Map) { | ||
| const result = this.serialize(Array.from(data.entries()), segments, meta, maps, blobs); | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP, ...segments]); | ||
| return result; | ||
| } | ||
| if (Array.isArray(data)) { | ||
| const json = data.map((v, i) => { | ||
| if (v === void 0) { | ||
| meta.push([STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED, ...segments, i]); | ||
| return null; | ||
| } | ||
| return this.serialize(v, [...segments, i], meta, maps, blobs)[0]; | ||
| }); | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| if (isObject(data)) { | ||
| const json = {}; | ||
| for (const k in data) { | ||
| if (k === "toJSON" && typeof data[k] === "function") { | ||
| continue; | ||
| } | ||
| json[k] = this.serialize(data[k], [...segments, k], meta, maps, blobs)[0]; | ||
| } | ||
| return [json, meta, maps, blobs]; | ||
| } | ||
| return [data, meta, maps, blobs]; | ||
| } | ||
| deserialize(json, meta, maps, getBlob) { | ||
| const ref = { data: json }; | ||
| if (maps && getBlob) { | ||
| maps.forEach((segments, i) => { | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| segments.forEach((segment) => { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = segment; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| }); | ||
| currentRef[preSegment] = getBlob(i); | ||
| }); | ||
| } | ||
| for (const item of meta) { | ||
| const type = item[0]; | ||
| let currentRef = ref; | ||
| let preSegment = "data"; | ||
| for (let i = 1; i < item.length; i++) { | ||
| currentRef = currentRef[preSegment]; | ||
| preSegment = item[i]; | ||
| if (!Object.hasOwn(currentRef, preSegment)) { | ||
| throw new Error(`Security error: accessing non-existent path during deserialization. Path segment: ${preSegment}`); | ||
| } | ||
| } | ||
| for (const custom of this.customSerializers) { | ||
| if (custom.type === type) { | ||
| currentRef[preSegment] = custom.deserialize(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| switch (type) { | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.BIGINT: | ||
| currentRef[preSegment] = BigInt(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.DATE: | ||
| currentRef[preSegment] = new Date(currentRef[preSegment] ?? "Invalid Date"); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.NAN: | ||
| currentRef[preSegment] = Number.NaN; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.UNDEFINED: | ||
| currentRef[preSegment] = void 0; | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.URL: | ||
| currentRef[preSegment] = new URL(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.REGEXP: { | ||
| const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/); | ||
| currentRef[preSegment] = new RegExp(pattern, flags); | ||
| break; | ||
| } | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.SET: | ||
| currentRef[preSegment] = new Set(currentRef[preSegment]); | ||
| break; | ||
| case STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES.MAP: | ||
| currentRef[preSegment] = new Map(currentRef[preSegment]); | ||
| break; | ||
| } | ||
| } | ||
| return ref.data; | ||
| } | ||
| } | ||
| function toHttpPath(path) { | ||
| return `/${path.map(encodeURIComponent).join("/")}`; | ||
| } | ||
| function toStandardHeaders(headers) { | ||
| if (typeof headers.forEach === "function") { | ||
| return toStandardHeaders$1(headers); | ||
| } | ||
| return headers; | ||
| } | ||
| function getMalformedResponseErrorCode(status) { | ||
| return Object.entries(COMMON_ORPC_ERROR_DEFS).find(([, def]) => def.status === status)?.[0] ?? "MALFORMED_ORPC_ERROR_RESPONSE"; | ||
| } | ||
| class StandardRPCLinkCodec { | ||
| constructor(serializer, options) { | ||
| this.serializer = serializer; | ||
| this.baseUrl = options.url; | ||
| this.maxUrlLength = options.maxUrlLength ?? 2083; | ||
| this.fallbackMethod = options.fallbackMethod ?? "POST"; | ||
| this.expectedMethod = options.method ?? this.fallbackMethod; | ||
| this.headers = options.headers ?? {}; | ||
| } | ||
| baseUrl; | ||
| maxUrlLength; | ||
| fallbackMethod; | ||
| expectedMethod; | ||
| headers; | ||
| async encode(path, input, options) { | ||
| let headers = toStandardHeaders(await value(this.headers, options, path, input)); | ||
| if (options.lastEventId !== void 0) { | ||
| headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId }); | ||
| } | ||
| const expectedMethod = await value(this.expectedMethod, options, path, input); | ||
| const baseUrl = await value(this.baseUrl, options, path, input); | ||
| const url = new URL(baseUrl); | ||
| url.pathname = `${url.pathname.replace(/\/$/, "")}${toHttpPath(path)}`; | ||
| const serialized = this.serializer.serialize(input); | ||
| if (expectedMethod === "GET" && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) { | ||
| const maxUrlLength = await value(this.maxUrlLength, options, path, input); | ||
| const getUrl = new URL(url); | ||
| getUrl.searchParams.append("data", stringifyJSON(serialized)); | ||
| if (getUrl.toString().length <= maxUrlLength) { | ||
| return { | ||
| body: void 0, | ||
| method: expectedMethod, | ||
| headers, | ||
| url: getUrl, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| } | ||
| return { | ||
| url, | ||
| method: expectedMethod === "GET" ? this.fallbackMethod : expectedMethod, | ||
| headers, | ||
| body: serialized, | ||
| signal: options.signal | ||
| }; | ||
| } | ||
| async decode(response) { | ||
| const isOk = !isORPCErrorStatus(response.status); | ||
| const deserialized = await (async () => { | ||
| let isBodyOk = false; | ||
| try { | ||
| const body = await response.body(); | ||
| isBodyOk = true; | ||
| return this.serializer.deserialize(body); | ||
| } catch (error) { | ||
| if (!isBodyOk) { | ||
| throw new Error("Cannot parse response body, please check the response body and content-type.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| throw new Error("Invalid RPC response format.", { | ||
| cause: error | ||
| }); | ||
| } | ||
| })(); | ||
| if (!isOk) { | ||
| if (isORPCErrorJson(deserialized)) { | ||
| throw createORPCErrorFromJson(deserialized); | ||
| } | ||
| throw new ORPCError(getMalformedResponseErrorCode(response.status), { | ||
| status: response.status, | ||
| data: { ...response, body: deserialized } | ||
| }); | ||
| } | ||
| return deserialized; | ||
| } | ||
| } | ||
| class StandardRPCSerializer { | ||
| constructor(jsonSerializer) { | ||
| this.jsonSerializer = jsonSerializer; | ||
| } | ||
| serialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#serialize(value, false), | ||
| error: async (e) => { | ||
| return new ErrorEvent({ | ||
| data: this.#serialize(toORPCError(e).toJSON(), false), | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#serialize(data, true); | ||
| } | ||
| #serialize(data, enableFormData) { | ||
| const [json, meta_, maps, blobs] = this.jsonSerializer.serialize(data); | ||
| const meta = meta_.length === 0 ? void 0 : meta_; | ||
| if (!enableFormData || blobs.length === 0) { | ||
| return { | ||
| json, | ||
| meta | ||
| }; | ||
| } | ||
| const form = new FormData(); | ||
| form.set("data", stringifyJSON({ json, meta, maps })); | ||
| blobs.forEach((blob, i) => { | ||
| form.set(i.toString(), blob); | ||
| }); | ||
| return form; | ||
| } | ||
| deserialize(data) { | ||
| if (isAsyncIteratorObject(data)) { | ||
| return mapEventIterator(data, { | ||
| value: async (value) => this.#deserialize(value), | ||
| error: async (e) => { | ||
| if (!(e instanceof ErrorEvent)) { | ||
| return e; | ||
| } | ||
| const deserialized = this.#deserialize(e.data); | ||
| if (isORPCErrorJson(deserialized)) { | ||
| return createORPCErrorFromJson(deserialized, { cause: e }); | ||
| } | ||
| return new ErrorEvent({ | ||
| data: deserialized, | ||
| cause: e | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| return this.#deserialize(data); | ||
| } | ||
| #deserialize(data) { | ||
| if (data === void 0) { | ||
| return void 0; | ||
| } | ||
| if (!(data instanceof FormData)) { | ||
| return this.jsonSerializer.deserialize(data.json, data.meta ?? []); | ||
| } | ||
| const serialized = JSON.parse(data.get("data")); | ||
| return this.jsonSerializer.deserialize( | ||
| serialized.json, | ||
| serialized.meta ?? [], | ||
| serialized.maps, | ||
| (i) => data.get(i.toString()) | ||
| ); | ||
| } | ||
| } | ||
| class StandardRPCLink extends StandardLink { | ||
| constructor(linkClient, options) { | ||
| const jsonSerializer = new StandardRPCJsonSerializer(options); | ||
| const serializer = new StandardRPCSerializer(jsonSerializer); | ||
| const linkCodec = new StandardRPCLinkCodec(serializer, options); | ||
| super(linkCodec, linkClient, options); | ||
| } | ||
| } | ||
| export { CompositeStandardLinkPlugin as C, StandardLink as S, STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as a, StandardRPCJsonSerializer as b, StandardRPCLink as c, StandardRPCLinkCodec as d, StandardRPCSerializer as e, toStandardHeaders as f, getMalformedResponseErrorCode as g, toHttpPath as t }; |
| import { resolveMaybeOptionalOptions, getConstructor, isObject } from '@orpc/shared'; | ||
| const ORPC_CLIENT_PACKAGE_NAME = "@orpc/client"; | ||
| const ORPC_CLIENT_PACKAGE_VERSION = "1.14.3"; | ||
| const COMMON_ORPC_ERROR_DEFS = { | ||
| BAD_REQUEST: { | ||
| status: 400, | ||
| message: "Bad Request" | ||
| }, | ||
| UNAUTHORIZED: { | ||
| status: 401, | ||
| message: "Unauthorized" | ||
| }, | ||
| FORBIDDEN: { | ||
| status: 403, | ||
| message: "Forbidden" | ||
| }, | ||
| NOT_FOUND: { | ||
| status: 404, | ||
| message: "Not Found" | ||
| }, | ||
| METHOD_NOT_SUPPORTED: { | ||
| status: 405, | ||
| message: "Method Not Supported" | ||
| }, | ||
| NOT_ACCEPTABLE: { | ||
| status: 406, | ||
| message: "Not Acceptable" | ||
| }, | ||
| TIMEOUT: { | ||
| status: 408, | ||
| message: "Request Timeout" | ||
| }, | ||
| CONFLICT: { | ||
| status: 409, | ||
| message: "Conflict" | ||
| }, | ||
| PRECONDITION_FAILED: { | ||
| status: 412, | ||
| message: "Precondition Failed" | ||
| }, | ||
| PAYLOAD_TOO_LARGE: { | ||
| status: 413, | ||
| message: "Payload Too Large" | ||
| }, | ||
| UNSUPPORTED_MEDIA_TYPE: { | ||
| status: 415, | ||
| message: "Unsupported Media Type" | ||
| }, | ||
| UNPROCESSABLE_CONTENT: { | ||
| status: 422, | ||
| message: "Unprocessable Content" | ||
| }, | ||
| TOO_MANY_REQUESTS: { | ||
| status: 429, | ||
| message: "Too Many Requests" | ||
| }, | ||
| CLIENT_CLOSED_REQUEST: { | ||
| status: 499, | ||
| message: "Client Closed Request" | ||
| }, | ||
| INTERNAL_SERVER_ERROR: { | ||
| status: 500, | ||
| message: "Internal Server Error" | ||
| }, | ||
| NOT_IMPLEMENTED: { | ||
| status: 501, | ||
| message: "Not Implemented" | ||
| }, | ||
| BAD_GATEWAY: { | ||
| status: 502, | ||
| message: "Bad Gateway" | ||
| }, | ||
| SERVICE_UNAVAILABLE: { | ||
| status: 503, | ||
| message: "Service Unavailable" | ||
| }, | ||
| GATEWAY_TIMEOUT: { | ||
| status: 504, | ||
| message: "Gateway Timeout" | ||
| } | ||
| }; | ||
| function fallbackORPCErrorStatus(code, status) { | ||
| return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500; | ||
| } | ||
| function fallbackORPCErrorMessage(code, message) { | ||
| return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code; | ||
| } | ||
| const GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL = Symbol.for(`__${ORPC_CLIENT_PACKAGE_NAME}@${ORPC_CLIENT_PACKAGE_VERSION}/error/ORPC_ERROR_CONSTRUCTORS__`); | ||
| void (globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL] ??= /* @__PURE__ */ new WeakSet()); | ||
| const globalORPCErrorConstructors = globalThis[GLOBAL_ORPC_ERROR_CONSTRUCTORS_SYMBOL]; | ||
| class ORPCError extends Error { | ||
| defined; | ||
| code; | ||
| status; | ||
| data; | ||
| constructor(code, ...rest) { | ||
| const options = resolveMaybeOptionalOptions(rest); | ||
| if (options.status !== void 0 && !isORPCErrorStatus(options.status)) { | ||
| throw new Error("[ORPCError] Invalid error status code."); | ||
| } | ||
| const message = fallbackORPCErrorMessage(code, options.message); | ||
| super(message, options); | ||
| this.code = code; | ||
| this.status = fallbackORPCErrorStatus(code, options.status); | ||
| this.defined = options.defined ?? false; | ||
| this.data = options.data; | ||
| } | ||
| toJSON() { | ||
| return { | ||
| defined: this.defined, | ||
| code: this.code, | ||
| status: this.status, | ||
| message: this.message, | ||
| data: this.data | ||
| }; | ||
| } | ||
| /** | ||
| * Workaround for Next.js where different contexts use separate | ||
| * dependency graphs, causing multiple ORPCError constructors existing and breaking | ||
| * `instanceof` checks across contexts. | ||
| * | ||
| * This is particularly problematic with "Optimized SSR", where orpc-client | ||
| * executes in one context but is invoked from another. When an error is thrown | ||
| * in the execution context, `instanceof ORPCError` checks fail in the | ||
| * invocation context due to separate class constructors. | ||
| * | ||
| * @todo Remove this and related code if Next.js resolves the multiple dependency graph issue. | ||
| */ | ||
| static [Symbol.hasInstance](instance) { | ||
| if (globalORPCErrorConstructors.has(this)) { | ||
| const constructor = getConstructor(instance); | ||
| if (constructor && globalORPCErrorConstructors.has(constructor)) { | ||
| return true; | ||
| } | ||
| } | ||
| return super[Symbol.hasInstance](instance); | ||
| } | ||
| } | ||
| globalORPCErrorConstructors.add(ORPCError); | ||
| function isDefinedError(error) { | ||
| return error instanceof ORPCError && error.defined; | ||
| } | ||
| function toORPCError(error) { | ||
| return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", { | ||
| message: "Internal server error", | ||
| cause: error | ||
| }); | ||
| } | ||
| function isORPCErrorStatus(status) { | ||
| return status < 200 || status >= 400; | ||
| } | ||
| function isORPCErrorJson(json) { | ||
| if (!isObject(json)) { | ||
| return false; | ||
| } | ||
| const validKeys = ["defined", "code", "status", "message", "data"]; | ||
| if (Object.keys(json).some((k) => !validKeys.includes(k))) { | ||
| return false; | ||
| } | ||
| return "defined" in json && typeof json.defined === "boolean" && "code" in json && typeof json.code === "string" && "status" in json && typeof json.status === "number" && isORPCErrorStatus(json.status) && "message" in json && typeof json.message === "string"; | ||
| } | ||
| function createORPCErrorFromJson(json, options = {}) { | ||
| return new ORPCError(json.code, { | ||
| ...options, | ||
| ...json | ||
| }); | ||
| } | ||
| export { COMMON_ORPC_ERROR_DEFS as C, ORPC_CLIENT_PACKAGE_NAME as O, ORPC_CLIENT_PACKAGE_VERSION as a, fallbackORPCErrorMessage as b, ORPCError as c, isORPCErrorStatus as d, isORPCErrorJson as e, fallbackORPCErrorStatus as f, createORPCErrorFromJson as g, isDefinedError as i, toORPCError as t }; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
154551
0.55%217
3.83%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated