@orpc/client 0.0.0-next-20241126131150 → 0.0.0-next.0021fba
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/README.md +97 -0
- package/dist/adapters/fetch/index.d.mts +33 -0
- package/dist/adapters/fetch/index.d.ts +33 -0
- package/dist/adapters/fetch/index.mjs +29 -0
- package/dist/adapters/message-port/index.d.mts +59 -0
- package/dist/adapters/message-port/index.d.ts +59 -0
- package/dist/adapters/message-port/index.mjs +71 -0
- package/dist/adapters/standard/index.d.mts +10 -0
- package/dist/adapters/standard/index.d.ts +10 -0
- package/dist/adapters/standard/index.mjs +4 -0
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +45 -0
- package/dist/index.d.mts +185 -0
- package/dist/index.d.ts +185 -0
- package/dist/index.mjs +82 -0
- package/dist/plugins/index.d.mts +202 -0
- package/dist/plugins/index.d.ts +202 -0
- package/dist/plugins/index.mjs +400 -0
- package/dist/shared/client.BG98rYdO.d.ts +45 -0
- package/dist/shared/client.BOYsZIRq.d.mts +29 -0
- package/dist/shared/client.BOYsZIRq.d.ts +29 -0
- package/dist/shared/client.Bwgm6dgk.d.mts +45 -0
- package/dist/shared/client.C176log5.d.ts +91 -0
- package/dist/shared/client.DKmRtVO2.mjs +390 -0
- package/dist/shared/client.Ycwr4Tuo.d.mts +91 -0
- package/dist/shared/client.txdq_i5V.mjs +180 -0
- package/package.json +39 -25
- package/dist/index.js +0 -217
- package/dist/index.js.map +0 -1
- package/dist/src/index.d.ts +0 -7
- 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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { resolveMaybeOptionalOptions, isObject, AsyncIteratorClass, isTypescriptObject } from '@orpc/shared';
|
|
2
|
+
import { getEventMeta, withEventMeta } from '@orpc/standard-server';
|
|
3
|
+
|
|
4
|
+
const COMMON_ORPC_ERROR_DEFS = {
|
|
5
|
+
BAD_REQUEST: {
|
|
6
|
+
status: 400,
|
|
7
|
+
message: "Bad Request"
|
|
8
|
+
},
|
|
9
|
+
UNAUTHORIZED: {
|
|
10
|
+
status: 401,
|
|
11
|
+
message: "Unauthorized"
|
|
12
|
+
},
|
|
13
|
+
FORBIDDEN: {
|
|
14
|
+
status: 403,
|
|
15
|
+
message: "Forbidden"
|
|
16
|
+
},
|
|
17
|
+
NOT_FOUND: {
|
|
18
|
+
status: 404,
|
|
19
|
+
message: "Not Found"
|
|
20
|
+
},
|
|
21
|
+
METHOD_NOT_SUPPORTED: {
|
|
22
|
+
status: 405,
|
|
23
|
+
message: "Method Not Supported"
|
|
24
|
+
},
|
|
25
|
+
NOT_ACCEPTABLE: {
|
|
26
|
+
status: 406,
|
|
27
|
+
message: "Not Acceptable"
|
|
28
|
+
},
|
|
29
|
+
TIMEOUT: {
|
|
30
|
+
status: 408,
|
|
31
|
+
message: "Request Timeout"
|
|
32
|
+
},
|
|
33
|
+
CONFLICT: {
|
|
34
|
+
status: 409,
|
|
35
|
+
message: "Conflict"
|
|
36
|
+
},
|
|
37
|
+
PRECONDITION_FAILED: {
|
|
38
|
+
status: 412,
|
|
39
|
+
message: "Precondition Failed"
|
|
40
|
+
},
|
|
41
|
+
PAYLOAD_TOO_LARGE: {
|
|
42
|
+
status: 413,
|
|
43
|
+
message: "Payload Too Large"
|
|
44
|
+
},
|
|
45
|
+
UNSUPPORTED_MEDIA_TYPE: {
|
|
46
|
+
status: 415,
|
|
47
|
+
message: "Unsupported Media Type"
|
|
48
|
+
},
|
|
49
|
+
UNPROCESSABLE_CONTENT: {
|
|
50
|
+
status: 422,
|
|
51
|
+
message: "Unprocessable Content"
|
|
52
|
+
},
|
|
53
|
+
TOO_MANY_REQUESTS: {
|
|
54
|
+
status: 429,
|
|
55
|
+
message: "Too Many Requests"
|
|
56
|
+
},
|
|
57
|
+
CLIENT_CLOSED_REQUEST: {
|
|
58
|
+
status: 499,
|
|
59
|
+
message: "Client Closed Request"
|
|
60
|
+
},
|
|
61
|
+
INTERNAL_SERVER_ERROR: {
|
|
62
|
+
status: 500,
|
|
63
|
+
message: "Internal Server Error"
|
|
64
|
+
},
|
|
65
|
+
NOT_IMPLEMENTED: {
|
|
66
|
+
status: 501,
|
|
67
|
+
message: "Not Implemented"
|
|
68
|
+
},
|
|
69
|
+
BAD_GATEWAY: {
|
|
70
|
+
status: 502,
|
|
71
|
+
message: "Bad Gateway"
|
|
72
|
+
},
|
|
73
|
+
SERVICE_UNAVAILABLE: {
|
|
74
|
+
status: 503,
|
|
75
|
+
message: "Service Unavailable"
|
|
76
|
+
},
|
|
77
|
+
GATEWAY_TIMEOUT: {
|
|
78
|
+
status: 504,
|
|
79
|
+
message: "Gateway Timeout"
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function fallbackORPCErrorStatus(code, status) {
|
|
83
|
+
return status ?? COMMON_ORPC_ERROR_DEFS[code]?.status ?? 500;
|
|
84
|
+
}
|
|
85
|
+
function fallbackORPCErrorMessage(code, message) {
|
|
86
|
+
return message || COMMON_ORPC_ERROR_DEFS[code]?.message || code;
|
|
87
|
+
}
|
|
88
|
+
class ORPCError extends Error {
|
|
89
|
+
defined;
|
|
90
|
+
code;
|
|
91
|
+
status;
|
|
92
|
+
data;
|
|
93
|
+
constructor(code, ...rest) {
|
|
94
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
95
|
+
if (options.status !== void 0 && !isORPCErrorStatus(options.status)) {
|
|
96
|
+
throw new Error("[ORPCError] Invalid error status code.");
|
|
97
|
+
}
|
|
98
|
+
const message = fallbackORPCErrorMessage(code, options.message);
|
|
99
|
+
super(message, options);
|
|
100
|
+
this.code = code;
|
|
101
|
+
this.status = fallbackORPCErrorStatus(code, options.status);
|
|
102
|
+
this.defined = options.defined ?? false;
|
|
103
|
+
this.data = options.data;
|
|
104
|
+
}
|
|
105
|
+
toJSON() {
|
|
106
|
+
return {
|
|
107
|
+
defined: this.defined,
|
|
108
|
+
code: this.code,
|
|
109
|
+
status: this.status,
|
|
110
|
+
message: this.message,
|
|
111
|
+
data: this.data
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function isDefinedError(error) {
|
|
116
|
+
return error instanceof ORPCError && error.defined;
|
|
117
|
+
}
|
|
118
|
+
function toORPCError(error) {
|
|
119
|
+
return error instanceof ORPCError ? error : new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
120
|
+
message: "Internal server error",
|
|
121
|
+
cause: error
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function isORPCErrorStatus(status) {
|
|
125
|
+
return status < 200 || status >= 400;
|
|
126
|
+
}
|
|
127
|
+
function isORPCErrorJson(json) {
|
|
128
|
+
if (!isObject(json)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const validKeys = ["defined", "code", "status", "message", "data"];
|
|
132
|
+
if (Object.keys(json).some((k) => !validKeys.includes(k))) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
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";
|
|
136
|
+
}
|
|
137
|
+
function createORPCErrorFromJson(json, options = {}) {
|
|
138
|
+
return new ORPCError(json.code, {
|
|
139
|
+
...options,
|
|
140
|
+
...json
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function mapEventIterator(iterator, maps) {
|
|
145
|
+
const mapError = async (error) => {
|
|
146
|
+
let mappedError = await maps.error(error);
|
|
147
|
+
if (mappedError !== error) {
|
|
148
|
+
const meta = getEventMeta(error);
|
|
149
|
+
if (meta && isTypescriptObject(mappedError)) {
|
|
150
|
+
mappedError = withEventMeta(mappedError, meta);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return mappedError;
|
|
154
|
+
};
|
|
155
|
+
return new AsyncIteratorClass(async () => {
|
|
156
|
+
const { done, value } = await (async () => {
|
|
157
|
+
try {
|
|
158
|
+
return await iterator.next();
|
|
159
|
+
} catch (error) {
|
|
160
|
+
throw await mapError(error);
|
|
161
|
+
}
|
|
162
|
+
})();
|
|
163
|
+
let mappedValue = await maps.value(value, done);
|
|
164
|
+
if (mappedValue !== value) {
|
|
165
|
+
const meta = getEventMeta(value);
|
|
166
|
+
if (meta && isTypescriptObject(mappedValue)) {
|
|
167
|
+
mappedValue = withEventMeta(mappedValue, meta);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { done, value: mappedValue };
|
|
171
|
+
}, async () => {
|
|
172
|
+
try {
|
|
173
|
+
await iterator.return?.();
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw await mapError(error);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { COMMON_ORPC_ERROR_DEFS as C, ORPCError as O, fallbackORPCErrorMessage as a, isORPCErrorStatus as b, isORPCErrorJson as c, createORPCErrorFromJson as d, fallbackORPCErrorStatus as f, isDefinedError as i, mapEventIterator as m, toORPCError as t };
|
package/package.json
CHANGED
|
@@ -1,50 +1,64 @@
|
|
|
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.0021fba",
|
|
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
|
-
"types": "./dist/
|
|
26
|
-
"import": "./dist/index.
|
|
27
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
},
|
|
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"
|
|
31
|
+
},
|
|
32
|
+
"./fetch": {
|
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./websocket": {
|
|
38
|
+
"types": "./dist/adapters/websocket/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/websocket/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/websocket/index.mjs"
|
|
28
41
|
},
|
|
29
|
-
"
|
|
30
|
-
"types": "./dist/
|
|
42
|
+
"./message-port": {
|
|
43
|
+
"types": "./dist/adapters/message-port/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/message-port/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/message-port/index.mjs"
|
|
31
46
|
}
|
|
32
47
|
},
|
|
33
48
|
"files": [
|
|
34
|
-
"dist"
|
|
35
|
-
"src"
|
|
49
|
+
"dist"
|
|
36
50
|
],
|
|
37
51
|
"dependencies": {
|
|
38
|
-
"@orpc/shared": "0.0.0-next
|
|
39
|
-
"@orpc/
|
|
52
|
+
"@orpc/shared": "0.0.0-next.0021fba",
|
|
53
|
+
"@orpc/standard-server": "0.0.0-next.0021fba",
|
|
54
|
+
"@orpc/standard-server-peer": "0.0.0-next.0021fba",
|
|
55
|
+
"@orpc/standard-server-fetch": "0.0.0-next.0021fba"
|
|
40
56
|
},
|
|
41
57
|
"devDependencies": {
|
|
42
|
-
"zod": "^
|
|
43
|
-
"@orpc/contract": "0.0.0-next-20241126131150",
|
|
44
|
-
"@orpc/server": "0.0.0-next-20241126131150"
|
|
58
|
+
"zod": "^4.0.17"
|
|
45
59
|
},
|
|
46
60
|
"scripts": {
|
|
47
|
-
"build": "
|
|
61
|
+
"build": "unbuild",
|
|
48
62
|
"build:watch": "pnpm run build --watch",
|
|
49
63
|
"type:check": "tsc -b"
|
|
50
64
|
}
|
package/dist/index.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
|
|
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
|
-
// src/index.ts
|
|
210
|
-
export * from "@orpc/shared/error";
|
|
211
|
-
var createORPCClient = createRouterClient;
|
|
212
|
-
export {
|
|
213
|
-
createORPCClient,
|
|
214
|
-
createProcedureClient,
|
|
215
|
-
createRouterClient
|
|
216
|
-
};
|
|
217
|
-
//# sourceMappingURL=index.js.map
|
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\nex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,CAAC;AAED,UAAM,OAAO,OAAO,YAAY;AAC9B,UAAI;AACF,eAAO,MAAM,aAAa,YAAY,QAAQ;AAAA,MAChD,SACO,GAAG;AACR,cAAM,IAAI,UAAU;AAAA,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
DELETED
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,KAA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