@orpc/client 0.0.0-next-20241126071108 → 0.0.0-next.00a3135
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.
- package/dist/fetch.js +87 -0
- package/dist/index.js +27 -205
- package/dist/src/adapters/fetch/index.d.ts +3 -0
- package/dist/src/adapters/fetch/orpc-link.d.ts +47 -0
- package/dist/src/adapters/fetch/types.d.ts +4 -0
- package/dist/src/client.d.ts +11 -0
- package/dist/src/dynamic-link.d.ts +13 -0
- package/dist/src/index.d.ts +3 -4
- package/dist/src/types.d.ts +5 -0
- package/package.json +21 -20
- package/dist/index.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/procedure.d.ts +0 -27
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router.d.ts +0 -34
- package/dist/src/router.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/index.ts +0 -9
- package/src/procedure.test.ts +0 -245
- package/src/procedure.ts +0 -108
- package/src/router.test.ts +0 -148
- package/src/router.ts +0 -96
package/dist/fetch.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
fetch;
|
|
7
|
+
payloadCodec;
|
|
8
|
+
maxURLLength;
|
|
9
|
+
fallbackMethod;
|
|
10
|
+
getMethod;
|
|
11
|
+
getHeaders;
|
|
12
|
+
url;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
15
|
+
this.payloadCodec = options.payloadCodec ?? new ORPCPayloadCodec();
|
|
16
|
+
this.maxURLLength = options.maxURLLength ?? 2083;
|
|
17
|
+
this.fallbackMethod = options.fallbackMethod ?? "POST";
|
|
18
|
+
this.url = options.url;
|
|
19
|
+
this.getMethod = async (path, input, context) => {
|
|
20
|
+
return await options.method?.(path, input, context) ?? this.fallbackMethod;
|
|
21
|
+
};
|
|
22
|
+
this.getHeaders = async (path, input, context) => {
|
|
23
|
+
return new Headers(await options.headers?.(path, input, context));
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async call(path, input, options) {
|
|
27
|
+
const clientContext = options.context;
|
|
28
|
+
const encoded = await this.encode(path, input, options);
|
|
29
|
+
const response = await this.fetch(encoded.url, {
|
|
30
|
+
method: encoded.method,
|
|
31
|
+
headers: encoded.headers,
|
|
32
|
+
body: encoded.body,
|
|
33
|
+
signal: options.signal
|
|
34
|
+
}, clientContext);
|
|
35
|
+
const decoded = await this.payloadCodec.decode(response);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const error = ORPCError.fromJSON(decoded) ?? new ORPCError({
|
|
38
|
+
status: response.status,
|
|
39
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
40
|
+
message: "Internal server error",
|
|
41
|
+
cause: decoded
|
|
42
|
+
});
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
return decoded;
|
|
46
|
+
}
|
|
47
|
+
async encode(path, input, options) {
|
|
48
|
+
const clientContext = options.context;
|
|
49
|
+
const expectMethod = await this.getMethod(path, input, clientContext);
|
|
50
|
+
const methods = /* @__PURE__ */ new Set([expectMethod, this.fallbackMethod]);
|
|
51
|
+
const baseHeaders = await this.getHeaders(path, input, clientContext);
|
|
52
|
+
const baseUrl = new URL(`${trim(this.url, "/")}/${path.map(encodeURIComponent).join("/")}`);
|
|
53
|
+
baseHeaders.append(ORPC_HANDLER_HEADER, ORPC_HANDLER_VALUE);
|
|
54
|
+
for (const method of methods) {
|
|
55
|
+
const url = new URL(baseUrl);
|
|
56
|
+
const headers = new Headers(baseHeaders);
|
|
57
|
+
const encoded = this.payloadCodec.encode(input, method, this.fallbackMethod);
|
|
58
|
+
if (encoded.query) {
|
|
59
|
+
for (const [key, value] of encoded.query.entries()) {
|
|
60
|
+
url.searchParams.append(key, value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (url.toString().length > this.maxURLLength) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (encoded.headers) {
|
|
67
|
+
for (const [key, value] of encoded.headers.entries()) {
|
|
68
|
+
headers.append(key, value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
url,
|
|
73
|
+
headers,
|
|
74
|
+
method: encoded.method,
|
|
75
|
+
body: encoded.body
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
throw new ORPCError({
|
|
79
|
+
code: "BAD_REQUEST",
|
|
80
|
+
message: "Cannot encode the request, please check the url length or payload."
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
export {
|
|
85
|
+
ORPCLink
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,217 +1,39 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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);
|
|
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);
|
|
88
11
|
}
|
|
12
|
+
return createORPCClient(link, {
|
|
13
|
+
...options,
|
|
14
|
+
path: [...path, key]
|
|
15
|
+
});
|
|
89
16
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
17
|
+
});
|
|
18
|
+
return recursive;
|
|
19
|
+
}
|
|
93
20
|
|
|
94
|
-
//
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
});
|
|
21
|
+
// src/dynamic-link.ts
|
|
22
|
+
var DynamicLink = class {
|
|
23
|
+
constructor(linkResolver) {
|
|
24
|
+
this.linkResolver = linkResolver;
|
|
126
25
|
}
|
|
127
|
-
|
|
128
|
-
|
|
26
|
+
async call(path, input, options) {
|
|
27
|
+
const resolvedLink = await this.linkResolver(path, input, options.context);
|
|
28
|
+
const output = await resolvedLink.call(path, input, options);
|
|
29
|
+
return output;
|
|
129
30
|
}
|
|
130
31
|
};
|
|
131
32
|
|
|
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
|
-
|
|
139
|
-
// src/procedure.ts
|
|
140
|
-
import { trim } from "@orpc/shared";
|
|
141
|
-
import { ORPCError } from "@orpc/shared/error";
|
|
142
|
-
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
|
143
|
-
function createProcedureClient(options) {
|
|
144
|
-
const serializer = new ORPCSerializer();
|
|
145
|
-
const deserializer = new ORPCDeserializer();
|
|
146
|
-
const client = async (input) => {
|
|
147
|
-
const fetch_ = options.fetch ?? fetch;
|
|
148
|
-
const url = `${trim(options.baseURL, "/")}/${options.path.map(encodeURIComponent).join("/")}`;
|
|
149
|
-
let headers = await options.headers?.(input);
|
|
150
|
-
headers = headers instanceof Headers ? headers : new Headers(headers);
|
|
151
|
-
const { body, headers: headers_ } = serializer.serialize(input);
|
|
152
|
-
for (const [key, value] of headers_.entries()) {
|
|
153
|
-
headers.set(key, value);
|
|
154
|
-
}
|
|
155
|
-
headers.set(ORPC_HEADER, ORPC_HEADER_VALUE);
|
|
156
|
-
const response = await fetch_(url, {
|
|
157
|
-
method: "POST",
|
|
158
|
-
headers,
|
|
159
|
-
body
|
|
160
|
-
});
|
|
161
|
-
const json = await (async () => {
|
|
162
|
-
try {
|
|
163
|
-
return await deserializer.deserialize(response);
|
|
164
|
-
} catch (e) {
|
|
165
|
-
throw new ORPCError({
|
|
166
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
167
|
-
message: "Cannot parse response.",
|
|
168
|
-
cause: e
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
})();
|
|
172
|
-
if (!response.ok) {
|
|
173
|
-
throw ORPCError.fromJSON(json) ?? new ORPCError({
|
|
174
|
-
status: response.status,
|
|
175
|
-
code: "INTERNAL_SERVER_ERROR",
|
|
176
|
-
message: "Internal server error"
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return json;
|
|
180
|
-
};
|
|
181
|
-
return client;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/router.ts
|
|
185
|
-
function createRouterClient(options) {
|
|
186
|
-
const path = options?.path ?? [];
|
|
187
|
-
const client = new Proxy(
|
|
188
|
-
createProcedureClient({
|
|
189
|
-
baseURL: options.baseURL,
|
|
190
|
-
fetch: options.fetch,
|
|
191
|
-
headers: options.headers,
|
|
192
|
-
path
|
|
193
|
-
}),
|
|
194
|
-
{
|
|
195
|
-
get(target, key) {
|
|
196
|
-
if (typeof key !== "string") {
|
|
197
|
-
return Reflect.get(target, key);
|
|
198
|
-
}
|
|
199
|
-
return createRouterClient({
|
|
200
|
-
...options,
|
|
201
|
-
path: [...path, key]
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
);
|
|
206
|
-
return client;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
33
|
// src/index.ts
|
|
210
34
|
export * from "@orpc/shared/error";
|
|
211
|
-
var createORPCClient = createRouterClient;
|
|
212
35
|
export {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
createRouterClient
|
|
36
|
+
DynamicLink,
|
|
37
|
+
createORPCClient
|
|
216
38
|
};
|
|
217
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { HTTPMethod } from '@orpc/contract';
|
|
2
|
+
import type { ProcedureClientOptions } from '@orpc/server';
|
|
3
|
+
import type { Promisable } from '@orpc/shared';
|
|
4
|
+
import type { ClientLink } from '../../types';
|
|
5
|
+
import type { FetchWithContext } from './types';
|
|
6
|
+
import { type PublicORPCPayloadCodec } from '@orpc/server/fetch';
|
|
7
|
+
export interface ORPCLinkOptions<TClientContext> {
|
|
8
|
+
/**
|
|
9
|
+
* Base url for all requests.
|
|
10
|
+
*/
|
|
11
|
+
url: string;
|
|
12
|
+
/**
|
|
13
|
+
* The maximum length of the URL.
|
|
14
|
+
*
|
|
15
|
+
* @default 2083
|
|
16
|
+
*/
|
|
17
|
+
maxURLLength?: number;
|
|
18
|
+
/**
|
|
19
|
+
* The method used to make the request.
|
|
20
|
+
*
|
|
21
|
+
* @default 'POST'
|
|
22
|
+
*/
|
|
23
|
+
method?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<HTTPMethod | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* The method to use when the payload cannot safely pass to the server with method return from method function.
|
|
26
|
+
* Do not use GET as fallback method, it's very dangerous.
|
|
27
|
+
*
|
|
28
|
+
* @default 'POST'
|
|
29
|
+
*/
|
|
30
|
+
fallbackMethod?: HTTPMethod;
|
|
31
|
+
headers?: (path: readonly string[], input: unknown, context: TClientContext) => Promisable<Headers | Record<string, string>>;
|
|
32
|
+
fetch?: FetchWithContext<TClientContext>;
|
|
33
|
+
payloadCodec?: PublicORPCPayloadCodec;
|
|
34
|
+
}
|
|
35
|
+
export declare class ORPCLink<TClientContext> implements ClientLink<TClientContext> {
|
|
36
|
+
private readonly fetch;
|
|
37
|
+
private readonly payloadCodec;
|
|
38
|
+
private readonly maxURLLength;
|
|
39
|
+
private readonly fallbackMethod;
|
|
40
|
+
private readonly getMethod;
|
|
41
|
+
private readonly getHeaders;
|
|
42
|
+
private readonly url;
|
|
43
|
+
constructor(options: ORPCLinkOptions<TClientContext>);
|
|
44
|
+
call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
|
|
45
|
+
private encode;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=orpc-link.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1,13 @@
|
|
|
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, context: TClientContext) => Promisable<ClientLink<TClientContext>>);
|
|
11
|
+
call(path: readonly string[], input: unknown, options: ProcedureClientOptions<TClientContext>): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=dynamic-link.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** unnoq */
|
|
2
|
-
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
2
|
+
export * from './client';
|
|
3
|
+
export * from './dynamic-link';
|
|
4
|
+
export * from './types';
|
|
5
5
|
export * from '@orpc/shared/error';
|
|
6
|
-
export declare const createORPCClient: typeof createRouterClient;
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "unnoq",
|
|
7
|
-
"email": "contact@unnoq.com",
|
|
8
|
-
"url": "https://unnoq.com"
|
|
9
|
-
},
|
|
4
|
+
"version": "0.0.0-next.00a3135",
|
|
10
5
|
"license": "MIT",
|
|
11
|
-
"homepage": "https://
|
|
6
|
+
"homepage": "https://orpc.unnoq.com",
|
|
12
7
|
"repository": {
|
|
13
8
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/unnoq/orpc.git",
|
|
9
|
+
"url": "git+https://github.com/unnoq/orpc.git",
|
|
15
10
|
"directory": "packages/client"
|
|
16
11
|
},
|
|
17
12
|
"keywords": [
|
|
18
|
-
"unnoq"
|
|
13
|
+
"unnoq",
|
|
14
|
+
"orpc"
|
|
19
15
|
],
|
|
20
|
-
"publishConfig": {
|
|
21
|
-
"access": "public"
|
|
22
|
-
},
|
|
23
16
|
"exports": {
|
|
24
17
|
".": {
|
|
25
18
|
"types": "./dist/src/index.d.ts",
|
|
26
19
|
"import": "./dist/index.js",
|
|
27
20
|
"default": "./dist/index.js"
|
|
28
21
|
},
|
|
22
|
+
"./fetch": {
|
|
23
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
|
24
|
+
"import": "./dist/fetch.js",
|
|
25
|
+
"default": "./dist/fetch.js"
|
|
26
|
+
},
|
|
29
27
|
"./🔒/*": {
|
|
30
28
|
"types": "./dist/src/*.d.ts"
|
|
31
29
|
}
|
|
32
30
|
},
|
|
33
31
|
"files": [
|
|
34
|
-
"
|
|
35
|
-
"
|
|
32
|
+
"!**/*.map",
|
|
33
|
+
"!**/*.tsbuildinfo",
|
|
34
|
+
"dist"
|
|
36
35
|
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@orpc/contract": "0.0.0-next.00a3135"
|
|
38
|
+
},
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"@orpc/
|
|
39
|
-
"@orpc/
|
|
40
|
+
"@orpc/server": "0.0.0-next.00a3135",
|
|
41
|
+
"@orpc/shared": "0.0.0-next.00a3135"
|
|
40
42
|
},
|
|
41
43
|
"devDependencies": {
|
|
42
|
-
"zod": "^3.
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/server": "0.0.0-next-20241126071108"
|
|
44
|
+
"zod": "^3.24.1",
|
|
45
|
+
"@orpc/openapi": "0.0.0-next.00a3135"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
|
-
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
48
|
+
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/adapters/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|
|
48
49
|
"build:watch": "pnpm run build --watch",
|
|
49
50
|
"type:check": "tsc -b"
|
|
50
51
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 TFuncOutput extends SchemaOutput<TOutputSchema>,\n> {\n (\n input: SchemaInput<TInputSchema>,\n ): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>\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 TFuncOutput extends SchemaOutput<TOutputSchema>,\n>(\n options: CreateProcedureClientOptions,\n): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput> {\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 UFuncOutput\n >\n ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput>\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,kBA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UAClB,MAAM;AAAA,UACN,SAAS;AAAA,UACT,OAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF,GAAG;AAEH,QAAI,CAAC,SAAS,IAAI;AAChB,YACE,UAAU,SAAS,IAAI,KACpB,IAAI,UAAU;AAAA,QACf,QAAQ,SAAS;AAAA,QACjB,MAAM;AAAA,QACN,SAAS;AAAA,MACX,CAAC;AAAA,IAEL;AAEA,WAAO;AAAA,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":[]}
|
package/dist/src/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAE7C,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAElC,eAAO,MAAM,gBAAgB,2BAAqB,CAAA"}
|
package/dist/src/procedure.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Promisable } from '@orpc/shared';
|
|
2
|
-
import { type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
|
3
|
-
export interface ProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> {
|
|
4
|
-
(input: SchemaInput<TInputSchema>): Promise<SchemaOutput<TOutputSchema, TFuncOutput>>;
|
|
5
|
-
}
|
|
6
|
-
export interface CreateProcedureClientOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The base url of the server.
|
|
9
|
-
*/
|
|
10
|
-
baseURL: string;
|
|
11
|
-
/**
|
|
12
|
-
* The fetch function used to make the request.
|
|
13
|
-
* @default global fetch
|
|
14
|
-
*/
|
|
15
|
-
fetch?: typeof fetch;
|
|
16
|
-
/**
|
|
17
|
-
* The headers used to make the request.
|
|
18
|
-
* Invoked before the request is made.
|
|
19
|
-
*/
|
|
20
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
21
|
-
/**
|
|
22
|
-
* The path of the procedure on server.
|
|
23
|
-
*/
|
|
24
|
-
path: string[];
|
|
25
|
-
}
|
|
26
|
-
export declare function createProcedureClient<TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(options: CreateProcedureClientOptions): ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>;
|
|
27
|
-
//# sourceMappingURL=procedure.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../../src/procedure.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAGL,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAA;AAKvB,MAAM,WAAW,eAAe,CAC9B,YAAY,SAAS,MAAM,EAC3B,aAAa,SAAS,MAAM,EAC5B,WAAW,SAAS,YAAY,CAAC,aAAa,CAAC;IAE/C,CACE,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,GAC/B,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IAEf;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAE1E;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,wBAAgB,qBAAqB,CACnC,YAAY,SAAS,MAAM,EAC3B,aAAa,SAAS,MAAM,EAC5B,WAAW,SAAS,YAAY,CAAC,aAAa,CAAC,EAE/C,OAAO,EAAE,4BAA4B,GACpC,eAAe,CAAC,YAAY,EAAE,aAAa,EAAE,WAAW,CAAC,CAoD3D"}
|
package/dist/src/router.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ContractProcedure, ContractRouter, SchemaOutput } from '@orpc/contract';
|
|
2
|
-
import type { Procedure, Router } from '@orpc/server';
|
|
3
|
-
import type { Promisable } from '@orpc/shared';
|
|
4
|
-
import { type ProcedureClient } from './procedure';
|
|
5
|
-
export type RouterClientWithContractRouter<TRouter extends ContractRouter> = {
|
|
6
|
-
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureClient<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> : TRouter[K] extends ContractRouter ? RouterClientWithContractRouter<TRouter[K]> : never;
|
|
7
|
-
};
|
|
8
|
-
export type RouterClientWithRouter<TRouter extends Router<any>> = {
|
|
9
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> ? ProcedureClient<UInputSchema, UOutputSchema, UFuncOutput> : TRouter[K] extends Router<any> ? RouterClientWithRouter<TRouter[K]> : never;
|
|
10
|
-
};
|
|
11
|
-
export interface CreateRouterClientOptions {
|
|
12
|
-
/**
|
|
13
|
-
* The base url of the server.
|
|
14
|
-
*/
|
|
15
|
-
baseURL: string;
|
|
16
|
-
/**
|
|
17
|
-
* The fetch function used to make the request.
|
|
18
|
-
* @default global fetch
|
|
19
|
-
*/
|
|
20
|
-
fetch?: typeof fetch;
|
|
21
|
-
/**
|
|
22
|
-
* The headers used to make the request.
|
|
23
|
-
* Invoked before the request is made.
|
|
24
|
-
*/
|
|
25
|
-
headers?: (input: unknown) => Promisable<Headers | Record<string, string>>;
|
|
26
|
-
/**
|
|
27
|
-
* This used for internal purpose only.
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
path?: string[];
|
|
32
|
-
}
|
|
33
|
-
export declare function createRouterClient<TRouter extends Router<any> | ContractRouter>(options: CreateRouterClientOptions): TRouter extends Router<any> ? RouterClientWithRouter<TRouter> : TRouter extends ContractRouter ? RouterClientWithContractRouter<TRouter> : never;
|
|
34
|
-
//# sourceMappingURL=router.d.ts.map
|
package/dist/src/router.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/router.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,YAAY,EACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAA;AAEzE,MAAM,MAAM,8BAA8B,CAAC,OAAO,SAAS,cAAc,IAAI;KAC1E,CAAC,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,SAAS,iB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