@orpc/client 0.39.0 → 0.41.0

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.
@@ -1,6 +1,9 @@
1
1
  /** unnoq */
2
2
  export * from './client';
3
3
  export * from './dynamic-link';
4
+ export * from './error';
5
+ export * from './event-iterator';
6
+ export * from './event-iterator-state';
4
7
  export * from './types';
5
- export { isDefinedError, ORPCError, safe } from '@orpc/contract';
8
+ export * from './utils';
6
9
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Serialize an object or array into a list of [key, value] pairs.
3
+ * The key will express by using bracket-notation.
4
+ *
5
+ * Notice: This way cannot express the empty object or array.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const payload = {
10
+ * name: 'John Doe',
11
+ * pets: ['dog', 'cat'],
12
+ * }
13
+ *
14
+ * const entities = serialize(payload)
15
+ *
16
+ * expect(entities).toEqual([
17
+ * ['name', 'John Doe'],
18
+ * ['name[pets][0]', 'dog'],
19
+ * ['name[pets][1]', 'cat'],
20
+ * ])
21
+ * ```
22
+ */
23
+ export declare function serialize(payload: unknown, parentKey?: string): [string, unknown][];
24
+ /**
25
+ * Deserialize a list of [key, value] pairs into an object or array.
26
+ * The key is expressed by using bracket-notation.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const entities = [
31
+ * ['name', 'John Doe'],
32
+ * ['name[pets][0]', 'dog'],
33
+ * ['name[pets][1]', 'cat'],
34
+ * ['name[dogs][]', 'hello'],
35
+ * ['name[dogs][]', 'kitty'],
36
+ * ]
37
+ *
38
+ * const payload = deserialize(entities)
39
+ *
40
+ * expect(payload).toEqual({
41
+ * name: 'John Doe',
42
+ * pets: { 0: 'dog', 1: 'cat' },
43
+ * dogs: ['hello', 'kitty'],
44
+ * })
45
+ * ```
46
+ */
47
+ export declare function deserialize(entities: readonly (readonly [string, unknown])[]): Record<string, unknown> | unknown[] | undefined;
48
+ /**
49
+ * Escape the `[`, `]`, and `\` chars in a path segment.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * expect(escapeSegment('name[pets')).toEqual('name\\[pets')
54
+ * ```
55
+ */
56
+ export declare function escapeSegment(segment: string): string;
57
+ /**
58
+ * Convert an array of path segments into a path string using bracket-notation.
59
+ *
60
+ * For the special char `[`, `]`, and `\` will be escaped by adding `\` at start.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * expect(stringifyPath(['name', 'pets', '0'])).toEqual('name[pets][0]')
65
+ * ```
66
+ */
67
+ export declare function stringifyPath(path: readonly [string, ...string[]]): string;
68
+ /**
69
+ * Convert a path string using bracket-notation into an array of path segments.
70
+ *
71
+ * For the special char `[`, `]`, and `\` you should escape by adding `\` at start.
72
+ * It only treats a pair `[${string}]` as a path segment.
73
+ * If missing or escape it will bypass and treat as normal string.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * expect(parsePath('name[pets][0]')).toEqual(['name', 'pets', '0'])
78
+ * expect(parsePath('name[pets][0')).toEqual(['name', 'pets', '[0'])
79
+ * expect(parsePath('name[pets[0]')).toEqual(['name', 'pets[0')
80
+ * expect(parsePath('name\\[pets][0]')).toEqual(['name[pets]', '0'])
81
+ * ```
82
+ */
83
+ export declare function parsePath(path: string): [string, ...string[]];
84
+ //# sourceMappingURL=bracket-notation.d.ts.map
@@ -0,0 +1,4 @@
1
+ export * as BracketNotation from './bracket-notation';
2
+ export * from './json-serializer';
3
+ export * from './serializer';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ export declare class OpenAPIJsonSerializer {
2
+ serialize(payload: unknown): unknown;
3
+ }
4
+ export type PublicOpenAPIJsonSerializer = Pick<OpenAPIJsonSerializer, keyof OpenAPIJsonSerializer>;
5
+ //# sourceMappingURL=json-serializer.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { PublicOpenAPIJsonSerializer } from './json-serializer';
2
+ export interface OpenAPISerializerOptions {
3
+ jsonSerializer?: PublicOpenAPIJsonSerializer;
4
+ }
5
+ export declare class OpenAPISerializer {
6
+ private readonly jsonSerializer;
7
+ constructor(options?: OpenAPISerializerOptions);
8
+ serialize(data: unknown): unknown;
9
+ deserialize(serialized: unknown): unknown;
10
+ }
11
+ //# sourceMappingURL=serializer.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './serializer';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,22 @@
1
+ import type { Segment } from '@orpc/shared';
2
+ export type RPCSerializedJsonMeta = ['bigint' | 'date' | 'nan' | 'undefined' | 'set' | 'map' | 'regexp' | 'url', Segment[]][];
3
+ export type RPCSerialized = {
4
+ json: unknown;
5
+ meta: RPCSerializedJsonMeta;
6
+ } | FormData | AsyncIteratorObject<{
7
+ json: unknown;
8
+ meta: RPCSerializedJsonMeta;
9
+ }, {
10
+ json: unknown;
11
+ meta: RPCSerializedJsonMeta;
12
+ }, void>;
13
+ export type RPCSerializedFormDataMaps = Segment[][];
14
+ export declare class RPCSerializer {
15
+ serialize(data: unknown): RPCSerialized;
16
+ deserialize(serialized: RPCSerialized): unknown;
17
+ }
18
+ export declare function serializeRPCJson(value: unknown, segments?: Segment[], meta?: RPCSerializedJsonMeta): {
19
+ json: unknown;
20
+ meta: RPCSerializedJsonMeta;
21
+ };
22
+ //# sourceMappingURL=serializer.d.ts.map
@@ -1,5 +1,29 @@
1
- import type { ClientContext, ClientOptions } from '@orpc/contract';
1
+ export type ClientContext = Record<string, any>;
2
+ export type ClientOptions<TClientContext extends ClientContext> = {
3
+ signal?: AbortSignal;
4
+ lastEventId?: string | undefined;
5
+ } & (Record<never, never> extends TClientContext ? {
6
+ context?: TClientContext;
7
+ } : {
8
+ context: TClientContext;
9
+ });
10
+ export type ClientRest<TClientContext extends ClientContext, TInput> = [input: TInput, options: ClientOptions<TClientContext>] | (Record<never, never> extends TClientContext ? (undefined extends TInput ? [input?: TInput] : [input: TInput]) : never);
11
+ export type ClientPromiseResult<TOutput, TError extends Error> = Promise<TOutput> & {
12
+ __error?: {
13
+ type: TError;
14
+ };
15
+ };
16
+ export interface Client<TClientContext extends ClientContext, TInput, TOutput, TError extends Error> {
17
+ (...rest: ClientRest<TClientContext, TInput>): ClientPromiseResult<TOutput, TError>;
18
+ }
19
+ export type NestedClient<TClientContext extends ClientContext> = Client<TClientContext, any, any, any> | {
20
+ [k: string]: NestedClient<TClientContext>;
21
+ };
22
+ export type InferClientContext<T extends NestedClient<any>> = T extends NestedClient<infer U> ? U : never;
23
+ export type ClientOptionsOut<TClientContext extends ClientContext> = ClientOptions<TClientContext> & {
24
+ context: TClientContext;
25
+ };
2
26
  export interface ClientLink<TClientContext extends ClientContext> {
3
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
27
+ call: (path: readonly string[], input: unknown, options: ClientOptionsOut<TClientContext>) => Promise<unknown>;
4
28
  }
5
29
  //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { ORPCError } from './error';
2
+ import type { ClientPromiseResult } from './types';
3
+ export type SafeResult<TOutput, TError extends Error> = [output: TOutput, error: undefined, isDefinedError: false] | [output: undefined, error: TError, isDefinedError: false] | [output: undefined, error: Extract<TError, ORPCError<any, any>>, isDefinedError: true];
4
+ export declare function safe<TOutput, TError extends Error>(promise: ClientPromiseResult<TOutput, TError>): Promise<SafeResult<TOutput, TError>>;
5
+ //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/client",
3
3
  "type": "module",
4
- "version": "0.39.0",
4
+ "version": "0.41.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -19,6 +19,16 @@
19
19
  "import": "./dist/index.js",
20
20
  "default": "./dist/index.js"
21
21
  },
22
+ "./openapi": {
23
+ "types": "./dist/src/openapi/index.d.ts",
24
+ "import": "./dist/openapi.js",
25
+ "default": "./dist/openapi.js"
26
+ },
27
+ "./rpc": {
28
+ "types": "./dist/src/rpc/index.d.ts",
29
+ "import": "./dist/rpc.js",
30
+ "default": "./dist/rpc.js"
31
+ },
22
32
  "./fetch": {
23
33
  "types": "./dist/src/adapters/fetch/index.d.ts",
24
34
  "import": "./dist/fetch.js",
@@ -34,18 +44,15 @@
34
44
  "dist"
35
45
  ],
36
46
  "dependencies": {
37
- "@orpc/server-standard-fetch": "^0.0.0",
38
- "@tinyhttp/content-disposition": "^2.2.2",
39
- "@orpc/contract": "0.39.0",
40
- "@orpc/server": "0.39.0",
41
- "@orpc/shared": "0.39.0"
47
+ "@orpc/server-standard": "^0.4.0",
48
+ "@orpc/server-standard-fetch": "^0.4.0",
49
+ "@orpc/shared": "0.41.0"
42
50
  },
43
51
  "devDependencies": {
44
- "zod": "^3.24.1",
45
- "@orpc/openapi": "0.39.0"
52
+ "zod": "^3.24.1"
46
53
  },
47
54
  "scripts": {
48
- "build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
55
+ "build": "tsup --onSuccess='tsc -b --noCheck'",
49
56
  "build:watch": "pnpm run build --watch",
50
57
  "type:check": "tsc -b"
51
58
  }
@@ -1,46 +0,0 @@
1
- import type { ClientContext, ClientOptions, HTTPMethod } from '@orpc/contract';
2
- import type { Promisable } from '@orpc/shared';
3
- import type { ClientLink } from '../../types';
4
- import type { FetchWithContext } from './types';
5
- import { RPCSerializer } from '@orpc/server/standard';
6
- export interface RPCLinkOptions<TClientContext extends ClientContext> {
7
- /**
8
- * Base url for all requests.
9
- */
10
- url: string;
11
- /**
12
- * The maximum length of the URL.
13
- *
14
- * @default 2083
15
- */
16
- maxURLLength?: number;
17
- /**
18
- * The method used to make the request.
19
- *
20
- * @default 'POST'
21
- */
22
- method?(path: readonly string[], input: unknown, context: TClientContext): Promisable<HTTPMethod | undefined>;
23
- /**
24
- * The method to use when the payload cannot safely pass to the server with method return from method function.
25
- * GET is not allowed, it's very dangerous.
26
- *
27
- * @default 'POST'
28
- */
29
- fallbackMethod?: Exclude<HTTPMethod, 'GET'>;
30
- headers?(path: readonly string[], input: unknown, context: TClientContext): Promisable<Headers | Record<string, string>>;
31
- fetch?: FetchWithContext<TClientContext>;
32
- rpcSerializer?: RPCSerializer;
33
- }
34
- export declare class RPCLink<TClientContext extends ClientContext> implements ClientLink<TClientContext> {
35
- private readonly fetch;
36
- private readonly rpcSerializer;
37
- private readonly maxURLLength;
38
- private readonly fallbackMethod;
39
- private readonly getMethod;
40
- private readonly getHeaders;
41
- private readonly url;
42
- constructor(options: RPCLinkOptions<TClientContext>);
43
- call(path: readonly string[], input: unknown, options: ClientOptions<TClientContext>): Promise<unknown>;
44
- private encode;
45
- }
46
- //# sourceMappingURL=orpc-link.d.ts.map