@orpc/client 0.0.0-next-20241123135451 → 0.0.0-next-20241123144325
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +138 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.js
CHANGED
@@ -1,8 +1,142 @@
|
|
1
|
+
// ../contract/src/procedure.ts
|
2
|
+
var ContractProcedure = class {
|
3
|
+
constructor(zz$cp) {
|
4
|
+
this.zz$cp = zz$cp;
|
5
|
+
}
|
6
|
+
};
|
7
|
+
var DecoratedContractProcedure = class _DecoratedContractProcedure extends ContractProcedure {
|
8
|
+
static decorate(cp) {
|
9
|
+
if (cp instanceof _DecoratedContractProcedure)
|
10
|
+
return cp;
|
11
|
+
return new _DecoratedContractProcedure(cp.zz$cp);
|
12
|
+
}
|
13
|
+
route(opts) {
|
14
|
+
return new _DecoratedContractProcedure({
|
15
|
+
...this.zz$cp,
|
16
|
+
...opts,
|
17
|
+
method: opts.method,
|
18
|
+
path: opts.path
|
19
|
+
});
|
20
|
+
}
|
21
|
+
prefix(prefix) {
|
22
|
+
if (!this.zz$cp.path)
|
23
|
+
return this;
|
24
|
+
return new _DecoratedContractProcedure({
|
25
|
+
...this.zz$cp,
|
26
|
+
path: `${prefix}${this.zz$cp.path}`
|
27
|
+
});
|
28
|
+
}
|
29
|
+
addTags(...tags) {
|
30
|
+
if (!tags.length)
|
31
|
+
return this;
|
32
|
+
return new _DecoratedContractProcedure({
|
33
|
+
...this.zz$cp,
|
34
|
+
tags: [...this.zz$cp.tags ?? [], ...tags]
|
35
|
+
});
|
36
|
+
}
|
37
|
+
input(schema, example) {
|
38
|
+
return new _DecoratedContractProcedure({
|
39
|
+
...this.zz$cp,
|
40
|
+
InputSchema: schema,
|
41
|
+
inputExample: example
|
42
|
+
});
|
43
|
+
}
|
44
|
+
output(schema, example) {
|
45
|
+
return new _DecoratedContractProcedure({
|
46
|
+
...this.zz$cp,
|
47
|
+
OutputSchema: schema,
|
48
|
+
outputExample: example
|
49
|
+
});
|
50
|
+
}
|
51
|
+
};
|
52
|
+
function isContractProcedure(item) {
|
53
|
+
if (item instanceof ContractProcedure)
|
54
|
+
return true;
|
55
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && "zz$cp" in item && typeof item.zz$cp === "object" && item.zz$cp !== null && "InputSchema" in item.zz$cp && "OutputSchema" in item.zz$cp;
|
56
|
+
}
|
57
|
+
|
58
|
+
// ../contract/src/router-builder.ts
|
59
|
+
var ContractRouterBuilder = class _ContractRouterBuilder {
|
60
|
+
constructor(zz$crb) {
|
61
|
+
this.zz$crb = zz$crb;
|
62
|
+
}
|
63
|
+
prefix(prefix) {
|
64
|
+
return new _ContractRouterBuilder({
|
65
|
+
...this.zz$crb,
|
66
|
+
prefix: `${this.zz$crb.prefix ?? ""}${prefix}`
|
67
|
+
});
|
68
|
+
}
|
69
|
+
tags(...tags) {
|
70
|
+
if (!tags.length)
|
71
|
+
return this;
|
72
|
+
return new _ContractRouterBuilder({
|
73
|
+
...this.zz$crb,
|
74
|
+
tags: [...this.zz$crb.tags ?? [], ...tags]
|
75
|
+
});
|
76
|
+
}
|
77
|
+
router(router) {
|
78
|
+
const handled = {};
|
79
|
+
for (const key in router) {
|
80
|
+
const item = router[key];
|
81
|
+
if (isContractProcedure(item)) {
|
82
|
+
const decorated = DecoratedContractProcedure.decorate(item).addTags(
|
83
|
+
...this.zz$crb.tags ?? []
|
84
|
+
);
|
85
|
+
handled[key] = this.zz$crb.prefix ? decorated.prefix(this.zz$crb.prefix) : decorated;
|
86
|
+
} else {
|
87
|
+
handled[key] = this.router(item);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
return handled;
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
// ../contract/src/builder.ts
|
95
|
+
var ContractBuilder = class {
|
96
|
+
prefix(prefix) {
|
97
|
+
return new ContractRouterBuilder({
|
98
|
+
prefix
|
99
|
+
});
|
100
|
+
}
|
101
|
+
tags(...tags) {
|
102
|
+
return new ContractRouterBuilder({
|
103
|
+
tags
|
104
|
+
});
|
105
|
+
}
|
106
|
+
route(opts) {
|
107
|
+
return new DecoratedContractProcedure({
|
108
|
+
InputSchema: void 0,
|
109
|
+
OutputSchema: void 0,
|
110
|
+
...opts
|
111
|
+
});
|
112
|
+
}
|
113
|
+
input(schema, example) {
|
114
|
+
return new DecoratedContractProcedure({
|
115
|
+
InputSchema: schema,
|
116
|
+
inputExample: example,
|
117
|
+
OutputSchema: void 0
|
118
|
+
});
|
119
|
+
}
|
120
|
+
output(schema, example) {
|
121
|
+
return new DecoratedContractProcedure({
|
122
|
+
InputSchema: void 0,
|
123
|
+
OutputSchema: schema,
|
124
|
+
outputExample: example
|
125
|
+
});
|
126
|
+
}
|
127
|
+
router(router) {
|
128
|
+
return router;
|
129
|
+
}
|
130
|
+
};
|
131
|
+
|
132
|
+
// ../contract/src/constants.ts
|
133
|
+
var ORPC_HEADER = "x-orpc-transformer";
|
134
|
+
var ORPC_HEADER_VALUE = "t";
|
135
|
+
|
136
|
+
// ../contract/src/index.ts
|
137
|
+
var oc = new ContractBuilder();
|
138
|
+
|
1
139
|
// src/procedure.ts
|
2
|
-
import {
|
3
|
-
ORPC_HEADER,
|
4
|
-
ORPC_HEADER_VALUE
|
5
|
-
} from "@orpc/contract";
|
6
140
|
import { trim } from "@orpc/shared";
|
7
141
|
import { ORPCError } from "@orpc/shared/error";
|
8
142
|
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/procedure.ts","../src/router.ts","../src/index.ts"],"sourcesContent":["/// <reference lib=\"dom\" />\n/// <reference lib=\"dom.iterable\" />\n\nimport type { Promisable } from '@orpc/shared'\nimport {\n ORPC_HEADER,\n ORPC_HEADER_VALUE,\n type Schema,\n type SchemaInput,\n type SchemaOutput,\n} from '@orpc/contract'\nimport { trim } from '@orpc/shared'\nimport { ORPCError } from '@orpc/shared/error'\nimport { ORPCDeserializer, ORPCSerializer } from '@orpc/transformer'\n\nexport interface ProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n THandlerOutput extends SchemaOutput<TOutputSchema>,\n> {\n (\n input: SchemaInput<TInputSchema>,\n ): Promise<SchemaOutput<TOutputSchema, THandlerOutput>>\n}\n\nexport interface CreateProcedureClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * The path of the procedure on server.\n */\n path: string[]\n}\n\nexport function createProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n THandlerOutput extends SchemaOutput<TOutputSchema>,\n>(\n options: CreateProcedureClientOptions,\n): ProcedureClient<TInputSchema, TOutputSchema, THandlerOutput> {\n const serializer = new ORPCSerializer()\n const deserializer = new ORPCDeserializer()\n\n const client = async (input: unknown): Promise<unknown> => {\n const fetch_ = options.fetch ?? fetch\n const url = `${trim(options.baseURL, '/')}/${options.path.map(encodeURIComponent).join('/')}`\n let headers = await options.headers?.(input)\n headers = headers instanceof Headers ? headers : new Headers(headers)\n\n const { body, headers: headers_ } = serializer.serialize(input)\n\n for (const [key, value] of headers_.entries()) {\n headers.set(key, value)\n }\n\n headers.set(ORPC_HEADER, ORPC_HEADER_VALUE)\n\n const response = await fetch_(url, {\n method: 'POST',\n headers,\n body,\n })\n\n const json = await (async () => {\n try {\n return await deserializer.deserialize(response)\n }\n catch (e) {\n throw new ORPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Cannot parse response.',\n cause: e,\n })\n }\n })()\n\n if (!response.ok) {\n throw (\n ORPCError.fromJSON(json)\n ?? new ORPCError({\n status: response.status,\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Internal server error',\n })\n )\n }\n\n return json\n }\n\n return client as any\n}\n","/// <reference lib=\"dom\" />\n\nimport type {\n ContractProcedure,\n ContractRouter,\n SchemaOutput,\n} from '@orpc/contract'\nimport type { Procedure, Router } from '@orpc/server'\nimport type { Promisable } from '@orpc/shared'\nimport { createProcedureClient, type ProcedureClient } from './procedure'\n\nexport type RouterClientWithContractRouter<TRouter extends ContractRouter> = {\n [K in keyof TRouter]: TRouter[K] extends ContractProcedure<\n infer UInputSchema,\n infer UOutputSchema\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>\n : TRouter[K] extends ContractRouter\n ? RouterClientWithContractRouter<TRouter[K]>\n : never\n}\n\nexport type RouterClientWithRouter<TRouter extends Router<any>> = {\n [K in keyof TRouter]: TRouter[K] extends Procedure<\n any,\n any,\n infer UInputSchema,\n infer UOutputSchema,\n infer UHandlerOutput\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, UHandlerOutput>\n : TRouter[K] extends Router<any>\n ? RouterClientWithRouter<TRouter[K]>\n : never\n}\n\nexport interface CreateRouterClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * This used for internal purpose only.\n *\n * @internal\n */\n path?: string[]\n}\n\nexport function createRouterClient<\n TRouter extends Router<any> | ContractRouter,\n>(\n options: CreateRouterClientOptions,\n): TRouter extends Router<any>\n ? RouterClientWithRouter<TRouter>\n : TRouter extends ContractRouter\n ? RouterClientWithContractRouter<TRouter>\n : never {\n const path = options?.path ?? []\n\n const client = new Proxy(\n createProcedureClient({\n baseURL: options.baseURL,\n fetch: options.fetch,\n headers: options.headers,\n path,\n }),\n {\n get(target, key) {\n if (typeof key !== 'string') {\n return Reflect.get(target, key)\n }\n\n return createRouterClient({\n ...options,\n path: [...path, key],\n })\n },\n },\n )\n\n return client as any\n}\n","/** unnoq */\n\nimport { createRouterClient } from './router'\n\nexport * from './procedure'\n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,EACT;AAEA,SAAO;AACT;;;AC7CO,SAAS,mBAGd,SAKY;AACZ,QAAM,OAAO,SAAS,QAAQ,CAAC;AAE/B,QAAM,SAAS,IAAI;AAAA,IACjB,sBAAsB;AAAA,MACpB,SAAS,QAAQ;AAAA,MACjB,OAAO,QAAQ;AAAA,MACf,SAAS,QAAQ;AAAA,MACjB;AAAA,IACF,CAAC;AAAA,IACD;AAAA,MACE,IAAI,QAAQ,KAAK;AACf,YAAI,OAAO,QAAQ,UAAU;AAC3B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAEA,eAAO,mBAAmB;AAAA,UACxB,GAAG;AAAA,UACH,MAAM,CAAC,GAAG,MAAM,GAAG;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;ACzFA,cAAc;AAEP,IAAM,mBAAmB;","names":[]}
|
1
|
+
{"version":3,"sources":["../../contract/src/procedure.ts","../../contract/src/router-builder.ts","../../contract/src/builder.ts","../../contract/src/constants.ts","../../contract/src/index.ts","../src/procedure.ts","../src/router.ts","../src/index.ts"],"sourcesContent":["import type {\n HTTPMethod,\n HTTPPath,\n Schema,\n SchemaInput,\n SchemaOutput,\n} from './types'\n\nexport interface RouteOptions {\n method?: HTTPMethod\n path?: HTTPPath\n summary?: string\n description?: string\n deprecated?: boolean\n tags?: string[]\n}\n\nexport class ContractProcedure<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n> {\n constructor(\n public zz$cp: {\n path?: HTTPPath\n method?: HTTPMethod\n summary?: string\n description?: string\n deprecated?: boolean\n tags?: string[]\n InputSchema: TInputSchema\n inputExample?: SchemaOutput<TInputSchema>\n OutputSchema: TOutputSchema\n outputExample?: SchemaOutput<TOutputSchema>\n },\n ) {}\n}\n\nexport class DecoratedContractProcedure<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n> extends ContractProcedure<TInputSchema, TOutputSchema> {\n static decorate<TInputSchema extends Schema, TOutputSchema extends Schema>(\n cp: ContractProcedure<TInputSchema, TOutputSchema>,\n ): DecoratedContractProcedure<TInputSchema, TOutputSchema> {\n if (cp instanceof DecoratedContractProcedure)\n return cp\n return new DecoratedContractProcedure(cp.zz$cp)\n }\n\n route(\n opts: RouteOptions,\n ): DecoratedContractProcedure<TInputSchema, TOutputSchema> {\n return new DecoratedContractProcedure({\n ...this.zz$cp,\n ...opts,\n method: opts.method,\n path: opts.path,\n })\n }\n\n prefix(\n prefix: HTTPPath,\n ): DecoratedContractProcedure<TInputSchema, TOutputSchema> {\n if (!this.zz$cp.path)\n return this\n\n return new DecoratedContractProcedure({\n ...this.zz$cp,\n path: `${prefix}${this.zz$cp.path}`,\n })\n }\n\n addTags(\n ...tags: string[]\n ): DecoratedContractProcedure<TInputSchema, TOutputSchema> {\n if (!tags.length)\n return this\n\n return new DecoratedContractProcedure({\n ...this.zz$cp,\n tags: [...(this.zz$cp.tags ?? []), ...tags],\n })\n }\n\n input<USchema extends Schema>(\n schema: USchema,\n example?: SchemaInput<USchema>,\n ): DecoratedContractProcedure<USchema, TOutputSchema> {\n return new DecoratedContractProcedure({\n ...this.zz$cp,\n InputSchema: schema,\n inputExample: example,\n })\n }\n\n output<USchema extends Schema>(\n schema: USchema,\n example?: SchemaOutput<USchema>,\n ): DecoratedContractProcedure<TInputSchema, USchema> {\n return new DecoratedContractProcedure({\n ...this.zz$cp,\n OutputSchema: schema,\n outputExample: example,\n })\n }\n}\n\nexport type WELL_DEFINED_CONTRACT_PROCEDURE = ContractProcedure<Schema, Schema>\n\nexport function isContractProcedure(\n item: unknown,\n): item is WELL_DEFINED_CONTRACT_PROCEDURE {\n if (item instanceof ContractProcedure)\n return true\n\n return (\n (typeof item === 'object' || typeof item === 'function')\n && item !== null\n && 'zz$cp' in item\n && typeof item.zz$cp === 'object'\n && item.zz$cp !== null\n && 'InputSchema' in item.zz$cp\n && 'OutputSchema' in item.zz$cp\n )\n}\n","import type { ContractRouter, HandledContractRouter } from './router'\nimport type { HTTPPath } from './types'\nimport { DecoratedContractProcedure, isContractProcedure } from './procedure'\n\nexport class ContractRouterBuilder {\n constructor(public zz$crb: { prefix?: HTTPPath, tags?: string[] }) {}\n\n prefix(prefix: HTTPPath): ContractRouterBuilder {\n return new ContractRouterBuilder({\n ...this.zz$crb,\n prefix: `${this.zz$crb.prefix ?? ''}${prefix}`,\n })\n }\n\n tags(...tags: string[]): ContractRouterBuilder {\n if (!tags.length)\n return this\n\n return new ContractRouterBuilder({\n ...this.zz$crb,\n tags: [...(this.zz$crb.tags ?? []), ...tags],\n })\n }\n\n router<T extends ContractRouter>(router: T): HandledContractRouter<T> {\n const handled: ContractRouter = {}\n\n for (const key in router) {\n const item = router[key]\n if (isContractProcedure(item)) {\n const decorated = DecoratedContractProcedure.decorate(item).addTags(\n ...(this.zz$crb.tags ?? []),\n )\n\n handled[key] = this.zz$crb.prefix\n ? decorated.prefix(this.zz$crb.prefix)\n : decorated\n }\n else {\n handled[key] = this.router(item as ContractRouter)\n }\n }\n\n return handled as HandledContractRouter<T>\n }\n}\n","import type { ContractRouter } from './router'\nimport type { HTTPPath, Schema, SchemaInput, SchemaOutput } from './types'\nimport { DecoratedContractProcedure, type RouteOptions } from './procedure'\nimport { ContractRouterBuilder } from './router-builder'\n\nexport class ContractBuilder {\n prefix(prefix: HTTPPath): ContractRouterBuilder {\n return new ContractRouterBuilder({\n prefix,\n })\n }\n\n tags(...tags: string[]): ContractRouterBuilder {\n return new ContractRouterBuilder({\n tags,\n })\n }\n\n route(opts: RouteOptions): DecoratedContractProcedure<undefined, undefined> {\n return new DecoratedContractProcedure({\n InputSchema: undefined,\n OutputSchema: undefined,\n ...opts,\n })\n }\n\n input<USchema extends Schema>(\n schema: USchema,\n example?: SchemaInput<USchema>,\n ): DecoratedContractProcedure<USchema, undefined> {\n return new DecoratedContractProcedure({\n InputSchema: schema,\n inputExample: example,\n OutputSchema: undefined,\n })\n }\n\n output<USchema extends Schema>(\n schema: USchema,\n example?: SchemaOutput<USchema>,\n ): DecoratedContractProcedure<undefined, USchema> {\n return new DecoratedContractProcedure({\n InputSchema: undefined,\n OutputSchema: schema,\n outputExample: example,\n })\n }\n\n router<T extends ContractRouter>(router: T): T {\n return router\n }\n}\n","export const ORPC_HEADER = 'x-orpc-transformer'\nexport const ORPC_HEADER_VALUE = 't'\n","/** unnoq */\n\nimport { ContractBuilder } from './builder'\n\nexport * from './builder'\nexport * from './constants'\nexport * from './procedure'\nexport * from './router'\nexport * from './types'\nexport * from './utils'\n\nexport const oc = new ContractBuilder()\n","/// <reference lib=\"dom\" />\n/// <reference lib=\"dom.iterable\" />\n\nimport type { Promisable } from '@orpc/shared'\nimport {\n ORPC_HEADER,\n ORPC_HEADER_VALUE,\n type Schema,\n type SchemaInput,\n type SchemaOutput,\n} from '@orpc/contract'\nimport { trim } from '@orpc/shared'\nimport { ORPCError } from '@orpc/shared/error'\nimport { ORPCDeserializer, ORPCSerializer } from '@orpc/transformer'\n\nexport interface ProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n THandlerOutput extends SchemaOutput<TOutputSchema>,\n> {\n (\n input: SchemaInput<TInputSchema>,\n ): Promise<SchemaOutput<TOutputSchema, THandlerOutput>>\n}\n\nexport interface CreateProcedureClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * The path of the procedure on server.\n */\n path: string[]\n}\n\nexport function createProcedureClient<\n TInputSchema extends Schema,\n TOutputSchema extends Schema,\n THandlerOutput extends SchemaOutput<TOutputSchema>,\n>(\n options: CreateProcedureClientOptions,\n): ProcedureClient<TInputSchema, TOutputSchema, THandlerOutput> {\n const serializer = new ORPCSerializer()\n const deserializer = new ORPCDeserializer()\n\n const client = async (input: unknown): Promise<unknown> => {\n const fetch_ = options.fetch ?? fetch\n const url = `${trim(options.baseURL, '/')}/${options.path.map(encodeURIComponent).join('/')}`\n let headers = await options.headers?.(input)\n headers = headers instanceof Headers ? headers : new Headers(headers)\n\n const { body, headers: headers_ } = serializer.serialize(input)\n\n for (const [key, value] of headers_.entries()) {\n headers.set(key, value)\n }\n\n headers.set(ORPC_HEADER, ORPC_HEADER_VALUE)\n\n const response = await fetch_(url, {\n method: 'POST',\n headers,\n body,\n })\n\n const json = await (async () => {\n try {\n return await deserializer.deserialize(response)\n }\n catch (e) {\n throw new ORPCError({\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Cannot parse response.',\n cause: e,\n })\n }\n })()\n\n if (!response.ok) {\n throw (\n ORPCError.fromJSON(json)\n ?? new ORPCError({\n status: response.status,\n code: 'INTERNAL_SERVER_ERROR',\n message: 'Internal server error',\n })\n )\n }\n\n return json\n }\n\n return client as any\n}\n","/// <reference lib=\"dom\" />\n\nimport type {\n ContractProcedure,\n ContractRouter,\n SchemaOutput,\n} from '@orpc/contract'\nimport type { Procedure, Router } from '@orpc/server'\nimport type { Promisable } from '@orpc/shared'\nimport { createProcedureClient, type ProcedureClient } from './procedure'\n\nexport type RouterClientWithContractRouter<TRouter extends ContractRouter> = {\n [K in keyof TRouter]: TRouter[K] extends ContractProcedure<\n infer UInputSchema,\n infer UOutputSchema\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>\n : TRouter[K] extends ContractRouter\n ? RouterClientWithContractRouter<TRouter[K]>\n : never\n}\n\nexport type RouterClientWithRouter<TRouter extends Router<any>> = {\n [K in keyof TRouter]: TRouter[K] extends Procedure<\n any,\n any,\n infer UInputSchema,\n infer UOutputSchema,\n infer UHandlerOutput\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, UHandlerOutput>\n : TRouter[K] extends Router<any>\n ? RouterClientWithRouter<TRouter[K]>\n : never\n}\n\nexport interface CreateRouterClientOptions {\n /**\n * The base url of the server.\n */\n baseURL: string\n\n /**\n * The fetch function used to make the request.\n * @default global fetch\n */\n fetch?: typeof fetch\n\n /**\n * The headers used to make the request.\n * Invoked before the request is made.\n */\n headers?: (input: unknown) => Promisable<Headers | Record<string, string>>\n\n /**\n * This used for internal purpose only.\n *\n * @internal\n */\n path?: string[]\n}\n\nexport function createRouterClient<\n TRouter extends Router<any> | ContractRouter,\n>(\n options: CreateRouterClientOptions,\n): TRouter extends Router<any>\n ? RouterClientWithRouter<TRouter>\n : TRouter extends ContractRouter\n ? RouterClientWithContractRouter<TRouter>\n : never {\n const path = options?.path ?? []\n\n const client = new Proxy(\n createProcedureClient({\n baseURL: options.baseURL,\n fetch: options.fetch,\n headers: options.headers,\n path,\n }),\n {\n get(target, key) {\n if (typeof key !== 'string') {\n return Reflect.get(target, key)\n }\n\n return createRouterClient({\n ...options,\n path: [...path, key],\n })\n },\n },\n )\n\n return client as any\n}\n","/** unnoq */\n\nimport { createRouterClient } from './router'\n\nexport * from './procedure'\nexport * from './router'\nexport * from '@orpc/shared/error'\n\nexport const createORPCClient = createRouterClient\n"],"mappings":";AAiBO,IAAM,oBAAN,MAGL;AAAA,EACA,YACS,OAYP;AAZO;AAAA,EAYN;AACL;AAEO,IAAM,6BAAN,MAAM,oCAGH,kBAA+C;AAAA,EACvD,OAAO,SACL,IACyD;AACzD,QAAI,cAAc;AAChB,aAAO;AACT,WAAO,IAAI,4BAA2B,GAAG,KAAK;AAAA,EAChD;AAAA,EAEA,MACE,MACyD;AACzD,WAAO,IAAI,4BAA2B;AAAA,MACpC,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,MACH,QAAQ,KAAK;AAAA,MACb,MAAM,KAAK;AAAA,IACb,CAAC;AAAA,EACH;AAAA,EAEA,OACE,QACyD;AACzD,QAAI,CAAC,KAAK,MAAM;AACd,aAAO;AAET,WAAO,IAAI,4BAA2B;AAAA,MACpC,GAAG,KAAK;AAAA,MACR,MAAM,GAAG,MAAM,GAAG,KAAK,MAAM,IAAI;AAAA,IACnC,CAAC;AAAA,EACH;AAAA,EAEA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AA,MACjB;AAAA,IACF,CAAC;AAAA,IACD;AAAA,MACE,IAAI,QAAQ,KAAK;AACf,YAAI,OAAO,QAAQ,UAAU;AAC3B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAEA,eAAO,mBAAmB;AAAA,UACxB,GAAG;AAAA,UACH,MAAM,CAAC,GAAG,MAAM,GAAG;AAAA,QACrB,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;ACzFA,cAAc;AAEP,IAAM,mBAAmB;","names":[]}
|
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-
|
4
|
+
"version": "0.0.0-next-20241123144325",
|
5
5
|
"author": {
|
6
6
|
"name": "unnoq",
|
7
7
|
"email": "contact@unnoq.com",
|
@@ -34,16 +34,14 @@
|
|
34
34
|
"dist",
|
35
35
|
"src"
|
36
36
|
],
|
37
|
-
"peerDependencies": {
|
38
|
-
"@orpc/contract": "0.0.0-next-20241123135451",
|
39
|
-
"@orpc/server": "0.0.0-next-20241123135451"
|
40
|
-
},
|
41
37
|
"dependencies": {
|
42
38
|
"@orpc/shared": "0.0.5",
|
43
39
|
"@orpc/transformer": "0.0.4"
|
44
40
|
},
|
45
41
|
"devDependencies": {
|
46
|
-
"zod": "^3.23.8"
|
42
|
+
"zod": "^3.23.8",
|
43
|
+
"@orpc/contract": "0.0.0-next-20241123144325",
|
44
|
+
"@orpc/server": "0.0.0-next-20241123144325"
|
47
45
|
},
|
48
46
|
"scripts": {
|
49
47
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|