@orpc/client 0.0.0-next.5d3da98 → 0.0.0-next.5d5051b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ import { Interceptor, ThrowableError } from '@orpc/shared';
2
+ import { StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
3
+ import { a as ClientContext, b as ClientOptions, C as ClientLink } from './client.CipPQkhk.js';
4
+
5
+ interface StandardLinkCodec<T extends ClientContext> {
6
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
7
+ decode(response: StandardLazyResponse, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<unknown>;
8
+ }
9
+ interface StandardLinkClient<T extends ClientContext> {
10
+ call(request: StandardRequest, options: ClientOptions<T>, path: readonly string[], input: unknown): Promise<StandardLazyResponse>;
11
+ }
12
+
13
+ interface StandardLinkPlugin<T extends ClientContext> {
14
+ order?: number;
15
+ init?(options: StandardLinkOptions<T>): void;
16
+ }
17
+ declare class CompositeStandardLinkPlugin<T extends ClientContext, TPlugin extends StandardLinkPlugin<T>> implements StandardLinkPlugin<T> {
18
+ protected readonly plugins: TPlugin[];
19
+ constructor(plugins?: readonly TPlugin[]);
20
+ init(options: StandardLinkOptions<T>): void;
21
+ }
22
+
23
+ declare class InvalidEventIteratorRetryResponse extends Error {
24
+ }
25
+ interface StandardLinkInterceptorOptions<T extends ClientContext> extends ClientOptions<T> {
26
+ path: readonly string[];
27
+ input: unknown;
28
+ }
29
+ interface StandardLinkClientInterceptorOptions<T extends ClientContext> extends StandardLinkInterceptorOptions<T> {
30
+ request: StandardRequest;
31
+ }
32
+ interface StandardLinkOptions<T extends ClientContext> {
33
+ interceptors?: Interceptor<StandardLinkInterceptorOptions<T>, unknown, ThrowableError>[];
34
+ clientInterceptors?: Interceptor<StandardLinkClientInterceptorOptions<T>, StandardLazyResponse, ThrowableError>[];
35
+ plugins?: StandardLinkPlugin<T>[];
36
+ }
37
+ declare class StandardLink<T extends ClientContext> implements ClientLink<T> {
38
+ #private;
39
+ readonly codec: StandardLinkCodec<T>;
40
+ readonly sender: StandardLinkClient<T>;
41
+ private readonly interceptors;
42
+ private readonly clientInterceptors;
43
+ constructor(codec: StandardLinkCodec<T>, sender: StandardLinkClient<T>, options?: StandardLinkOptions<T>);
44
+ call(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<unknown>;
45
+ }
46
+
47
+ export { CompositeStandardLinkPlugin as C, InvalidEventIteratorRetryResponse as I, type StandardLinkClientInterceptorOptions as S, type StandardLinkPlugin as a, type StandardLinkOptions as b, type StandardLinkInterceptorOptions as c, StandardLink as d, type StandardLinkCodec as e, type StandardLinkClient as f };
@@ -0,0 +1,90 @@
1
+ import { a as ClientContext, b as ClientOptions, d as HTTPMethod } from './client.CipPQkhk.js';
2
+ import { e as StandardLinkCodec, b as StandardLinkOptions, d as StandardLink, f as StandardLinkClient } from './client.DUjXqpDq.js';
3
+ import { Segment, Value } from '@orpc/shared';
4
+ import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
5
+
6
+ declare const STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES: {
7
+ readonly BIGINT: 0;
8
+ readonly DATE: 1;
9
+ readonly NAN: 2;
10
+ readonly UNDEFINED: 3;
11
+ readonly URL: 4;
12
+ readonly REGEXP: 5;
13
+ readonly SET: 6;
14
+ readonly MAP: 7;
15
+ };
16
+ type StandardRPCJsonSerializedMetaItem = readonly [type: number, ...path: Segment[]];
17
+ type StandardRPCJsonSerialized = [json: unknown, meta: StandardRPCJsonSerializedMetaItem[], maps: Segment[][], blobs: Blob[]];
18
+ interface StandardRPCCustomJsonSerializer {
19
+ type: number;
20
+ condition(data: unknown): boolean;
21
+ serialize(data: any): unknown;
22
+ deserialize(serialized: any): unknown;
23
+ }
24
+ interface StandardRPCJsonSerializerOptions {
25
+ customJsonSerializers?: readonly StandardRPCCustomJsonSerializer[];
26
+ }
27
+ declare class StandardRPCJsonSerializer {
28
+ private readonly customSerializers;
29
+ constructor(options?: StandardRPCJsonSerializerOptions);
30
+ serialize(data: unknown, segments?: Segment[], meta?: StandardRPCJsonSerializedMetaItem[], maps?: Segment[][], blobs?: Blob[]): StandardRPCJsonSerialized;
31
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[]): unknown;
32
+ deserialize(json: unknown, meta: readonly StandardRPCJsonSerializedMetaItem[], maps: readonly Segment[][], getBlob: (index: number) => Blob): unknown;
33
+ }
34
+
35
+ declare class StandardRPCSerializer {
36
+ #private;
37
+ private readonly jsonSerializer;
38
+ constructor(jsonSerializer: StandardRPCJsonSerializer);
39
+ serialize(data: unknown): object;
40
+ deserialize(data: unknown): unknown;
41
+ }
42
+
43
+ interface StandardRPCLinkCodecOptions<T extends ClientContext> {
44
+ /**
45
+ * Base url for all requests.
46
+ */
47
+ url: Value<string | URL, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
48
+ /**
49
+ * The maximum length of the URL.
50
+ *
51
+ * @default 2083
52
+ */
53
+ maxUrlLength?: Value<number, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
54
+ /**
55
+ * The method used to make the request.
56
+ *
57
+ * @default 'POST'
58
+ */
59
+ method?: Value<HTTPMethod, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
60
+ /**
61
+ * The method to use when the payload cannot safely pass to the server with method return from method function.
62
+ * GET is not allowed, it's very dangerous.
63
+ *
64
+ * @default 'POST'
65
+ */
66
+ fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
67
+ /**
68
+ * Inject headers to the request.
69
+ */
70
+ headers?: Value<StandardHeaders, [options: ClientOptions<T>, path: readonly string[], input: unknown]>;
71
+ }
72
+ declare class StandardRPCLinkCodec<T extends ClientContext> implements StandardLinkCodec<T> {
73
+ private readonly serializer;
74
+ private readonly baseUrl;
75
+ private readonly maxUrlLength;
76
+ private readonly fallbackMethod;
77
+ private readonly expectedMethod;
78
+ private readonly headers;
79
+ constructor(serializer: StandardRPCSerializer, options: StandardRPCLinkCodecOptions<T>);
80
+ encode(path: readonly string[], input: unknown, options: ClientOptions<T>): Promise<StandardRequest>;
81
+ decode(response: StandardLazyResponse): Promise<unknown>;
82
+ }
83
+
84
+ interface StandardRPCLinkOptions<T extends ClientContext> extends StandardLinkOptions<T>, StandardRPCLinkCodecOptions<T>, StandardRPCJsonSerializerOptions {
85
+ }
86
+ declare class StandardRPCLink<T extends ClientContext> extends StandardLink<T> {
87
+ constructor(linkClient: StandardLinkClient<T>, options: StandardRPCLinkOptions<T>);
88
+ }
89
+
90
+ export { STANDARD_RPC_JSON_SERIALIZER_BUILT_IN_TYPES as S, type StandardRPCJsonSerializedMetaItem as a, type StandardRPCJsonSerialized as b, type StandardRPCCustomJsonSerializer as c, type StandardRPCJsonSerializerOptions as d, StandardRPCJsonSerializer as e, type StandardRPCLinkOptions as f, StandardRPCLink as g, type StandardRPCLinkCodecOptions as h, StandardRPCLinkCodec as i, StandardRPCSerializer as j };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.0.0-next.5d3da98",
4
+ "version": "0.0.0-next.5d5051b",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -15,37 +15,39 @@
15
15
  ],
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/src/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
18
+ "types": "./dist/index.d.mts",
19
+ "import": "./dist/index.mjs",
20
+ "default": "./dist/index.mjs"
21
21
  },
22
- "./fetch": {
23
- "types": "./dist/src/adapters/fetch/index.d.ts",
24
- "import": "./dist/fetch.js",
25
- "default": "./dist/fetch.js"
22
+ "./plugins": {
23
+ "types": "./dist/plugins/index.d.mts",
24
+ "import": "./dist/plugins/index.mjs",
25
+ "default": "./dist/plugins/index.mjs"
26
+ },
27
+ "./standard": {
28
+ "types": "./dist/adapters/standard/index.d.mts",
29
+ "import": "./dist/adapters/standard/index.mjs",
30
+ "default": "./dist/adapters/standard/index.mjs"
26
31
  },
27
- "./🔒/*": {
28
- "types": "./dist/src/*.d.ts"
32
+ "./fetch": {
33
+ "types": "./dist/adapters/fetch/index.d.mts",
34
+ "import": "./dist/adapters/fetch/index.mjs",
35
+ "default": "./dist/adapters/fetch/index.mjs"
29
36
  }
30
37
  },
31
38
  "files": [
32
- "!**/*.map",
33
- "!**/*.tsbuildinfo",
34
39
  "dist"
35
40
  ],
36
- "peerDependencies": {
37
- "@orpc/contract": "0.0.0-next.5d3da98"
38
- },
39
41
  "dependencies": {
40
- "@orpc/shared": "0.0.0-next.5d3da98",
41
- "@orpc/server": "0.0.0-next.5d3da98"
42
+ "@orpc/shared": "0.0.0-next.5d5051b",
43
+ "@orpc/standard-server-fetch": "0.0.0-next.5d5051b",
44
+ "@orpc/standard-server": "0.0.0-next.5d5051b"
42
45
  },
43
46
  "devDependencies": {
44
- "zod": "^3.24.1",
45
- "@orpc/openapi": "0.0.0-next.5d3da98"
47
+ "zod": "^3.24.2"
46
48
  },
47
49
  "scripts": {
48
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
50
+ "build": "unbuild",
49
51
  "build:watch": "pnpm run build --watch",
50
52
  "type:check": "tsc -b"
51
53
  }
package/dist/fetch.js DELETED
@@ -1,46 +0,0 @@
1
- // src/adapters/fetch/orpc-link.ts
2
- import { ORPCPayloadCodec } from "@orpc/server/fetch";
3
- import { ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE, trim } from "@orpc/shared";
4
- import { ORPCError } from "@orpc/shared/error";
5
- var ORPCLink = class {
6
- constructor(options) {
7
- this.options = options;
8
- this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
9
- this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
10
- }
11
- fetch;
12
- payloadCodec;
13
- async call(path, input, options) {
14
- const url = `${trim(this.options.url, "/")}/${path.map(encodeURIComponent).join("/")}`;
15
- const encoded = this.payloadCodec.encode(input);
16
- const headers = new Headers(encoded.headers);
17
- headers.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
18
- const clientContext = options.context;
19
- let customHeaders = await this.options.headers?.(input, clientContext);
20
- customHeaders = customHeaders instanceof Headers ? customHeaders : new Headers(customHeaders);
21
- for (const [key, value] of customHeaders.entries()) {
22
- headers.append(key, value);
23
- }
24
- const response = await this.fetch(url, {
25
- method: "POST",
26
- headers,
27
- body: encoded.body,
28
- signal: options.signal
29
- }, clientContext);
30
- const decoded = await this.payloadCodec.decode(response);
31
- if (!response.ok) {
32
- const error = ORPCError.fromJSON(decoded) ?? new ORPCError({
33
- status: response.status,
34
- code: "INTERNAL_SERVER_ERROR",
35
- message: "Internal server error",
36
- cause: decoded
37
- });
38
- throw error;
39
- }
40
- return decoded;
41
- }
42
- };
43
- export {
44
- ORPCLink
45
- };
46
- //# sourceMappingURL=fetch.js.map
package/dist/index.js DELETED
@@ -1,39 +0,0 @@
1
- // src/client.ts
2
- function createORPCClient(link, options) {
3
- const path = options?.path ?? [];
4
- const procedureClient = async (...[input, options2]) => {
5
- return await link.call(path, input, options2 ?? {});
6
- };
7
- const recursive = new Proxy(procedureClient, {
8
- get(target, key) {
9
- if (typeof key !== "string") {
10
- return Reflect.get(target, key);
11
- }
12
- return createORPCClient(link, {
13
- ...options,
14
- path: [...path, key]
15
- });
16
- }
17
- });
18
- return recursive;
19
- }
20
-
21
- // src/dynamic-link.ts
22
- var DynamicLink = class {
23
- constructor(linkResolver) {
24
- this.linkResolver = linkResolver;
25
- }
26
- async call(path, input, options) {
27
- const resolvedLink = await this.linkResolver(path, input, options);
28
- const output = await resolvedLink.call(path, input, options);
29
- return output;
30
- }
31
- };
32
-
33
- // src/index.ts
34
- export * from "@orpc/shared/error";
35
- export {
36
- DynamicLink,
37
- createORPCClient
38
- };
39
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- export * from './orpc-link';
2
- export * from './types';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,19 +0,0 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
2
- import type { Promisable } from '@orpc/shared';
3
- import type { ClientLink } from '../../types';
4
- import type { FetchWithContext } from './types';
5
- import { type PublicORPCPayloadCodec } from '@orpc/server/fetch';
6
- export interface ORPCLinkOptions<TClientContext> {
7
- url: string;
8
- headers?: (input: unknown, context: TClientContext) => Promisable<Headers | Record<string, string>>;
9
- fetch?: FetchWithContext<TClientContext>;
10
- payloadCodec?: PublicORPCPayloadCodec;
11
- }
12
- export declare class ORPCLink<TClientContext> implements ClientLink<TClientContext> {
13
- private readonly options;
14
- private readonly fetch;
15
- private readonly payloadCodec;
16
- constructor(options: ORPCLinkOptions<TClientContext>);
17
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
18
- }
19
- //# sourceMappingURL=orpc-link.d.ts.map
@@ -1,4 +0,0 @@
1
- export interface FetchWithContext<TClientContext> {
2
- (input: RequestInfo | URL, init: RequestInit | undefined, context: TClientContext): Promise<Response>;
3
- }
4
- //# sourceMappingURL=types.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { ContractRouter } from '@orpc/contract';
2
- import type { ANY_ROUTER, RouterClient } from '@orpc/server';
3
- import type { ClientLink } from './types';
4
- export interface createORPCClientOptions {
5
- /**
6
- * Use as base path for all procedure, useful when you only want to call a subset of the procedure.
7
- */
8
- path?: string[];
9
- }
10
- export declare function createORPCClient<TRouter extends ANY_ROUTER | ContractRouter, TClientContext = unknown>(link: ClientLink<TClientContext>, options?: createORPCClientOptions): RouterClient<TRouter, TClientContext>;
11
- //# sourceMappingURL=client.d.ts.map
@@ -1,15 +0,0 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
2
- import type { Promisable } from '@orpc/shared';
3
- import type { ClientLink } from './types';
4
- /**
5
- * DynamicLink provides a way to dynamically resolve and delegate calls to other ClientLinks
6
- * based on the request path, input, and context.
7
- */
8
- export declare class DynamicLink<TClientContext> implements ClientLink<TClientContext> {
9
- private readonly linkResolver;
10
- constructor(linkResolver: (path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext> & {
11
- context: TClientContext;
12
- }) => Promisable<ClientLink<TClientContext>>);
13
- call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
14
- }
15
- //# sourceMappingURL=dynamic-link.d.ts.map
@@ -1,6 +0,0 @@
1
- /** unnoq */
2
- export * from './client';
3
- export * from './dynamic-link';
4
- export * from './types';
5
- export * from '@orpc/shared/error';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +0,0 @@
1
- import type { ProcedureClientOptions } from '@orpc/server';
2
- export interface ClientLink<TClientContext> {
3
- call: (path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>) => Promise<unknown>;
4
- }
5
- //# sourceMappingURL=types.d.ts.map