@atproto/xrpc 0.0.3 → 0.0.4
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/client.d.ts +2 -1
- package/dist/index.js +28 -15
- package/dist/index.js.map +2 -2
- package/dist/util.d.ts +1 -1
- package/package.json +1 -1
- package/src/client.ts +7 -3
- package/src/util.ts +19 -2
- package/tsconfig.build.tsbuildinfo +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Lexicons } from '@atproto/lexicon';
|
|
2
|
-
import { FetchHandler, CallOptions, QueryParams, XRPCResponse } from './types';
|
|
2
|
+
import { FetchHandler, FetchHandlerResponse, Headers, CallOptions, QueryParams, XRPCResponse } from './types';
|
|
3
3
|
export declare class Client {
|
|
4
4
|
fetch: FetchHandler;
|
|
5
5
|
lex: Lexicons;
|
|
@@ -18,3 +18,4 @@ export declare class ServiceClient {
|
|
|
18
18
|
unsetHeader(key: string): void;
|
|
19
19
|
call(methodNsid: string, params?: QueryParams, data?: unknown, opts?: CallOptions): Promise<XRPCResponse>;
|
|
20
20
|
}
|
|
21
|
+
export declare function defaultFetchHandler(httpUri: string, httpMethod: string, httpHeaders: Headers, httpReqBody: unknown): Promise<FetchHandlerResponse>;
|
package/dist/index.js
CHANGED
|
@@ -87,6 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
XRPCInvalidResponseError: () => XRPCInvalidResponseError,
|
|
88
88
|
XRPCResponse: () => XRPCResponse,
|
|
89
89
|
default: () => src_default,
|
|
90
|
+
defaultFetchHandler: () => defaultFetchHandler,
|
|
90
91
|
errorResponseBody: () => errorResponseBody
|
|
91
92
|
});
|
|
92
93
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -3244,6 +3245,11 @@ var lexArray = mod.object({
|
|
|
3244
3245
|
minLength: mod.number().int().optional(),
|
|
3245
3246
|
maxLength: mod.number().int().optional()
|
|
3246
3247
|
});
|
|
3248
|
+
var lexPrimitiveArray = lexArray.merge(
|
|
3249
|
+
mod.object({
|
|
3250
|
+
items: lexPrimitive
|
|
3251
|
+
})
|
|
3252
|
+
);
|
|
3247
3253
|
var lexToken = mod.object({
|
|
3248
3254
|
type: mod.literal("token"),
|
|
3249
3255
|
description: mod.string().optional()
|
|
@@ -3258,7 +3264,7 @@ var lexXrpcParameters = mod.object({
|
|
|
3258
3264
|
type: mod.literal("params"),
|
|
3259
3265
|
description: mod.string().optional(),
|
|
3260
3266
|
required: mod.string().array().optional(),
|
|
3261
|
-
properties: mod.record(lexPrimitive)
|
|
3267
|
+
properties: mod.record(mod.union([lexPrimitive, lexPrimitiveArray]))
|
|
3262
3268
|
});
|
|
3263
3269
|
var lexXrpcBody = mod.object({
|
|
3264
3270
|
description: mod.string().optional(),
|
|
@@ -3630,7 +3636,6 @@ function validate2(lexicons, path, def, value) {
|
|
|
3630
3636
|
}
|
|
3631
3637
|
}
|
|
3632
3638
|
function array(lexicons, path, def, value) {
|
|
3633
|
-
def = def;
|
|
3634
3639
|
if (!Array.isArray(value)) {
|
|
3635
3640
|
return {
|
|
3636
3641
|
success: false,
|
|
@@ -3678,7 +3683,7 @@ function object(lexicons, path, def, value) {
|
|
|
3678
3683
|
}
|
|
3679
3684
|
if (Array.isArray(def.required)) {
|
|
3680
3685
|
for (const key of def.required) {
|
|
3681
|
-
if (
|
|
3686
|
+
if (typeof value[key] === "undefined") {
|
|
3682
3687
|
return {
|
|
3683
3688
|
success: false,
|
|
3684
3689
|
error: new ValidationError(`${path} must have the property "${key}"`)
|
|
@@ -3782,13 +3787,12 @@ function toConcreteTypes(lexicons, def) {
|
|
|
3782
3787
|
|
|
3783
3788
|
// ../lexicon/src/validators/xrpc.ts
|
|
3784
3789
|
function params(lexicons, path, def, value) {
|
|
3785
|
-
def = def;
|
|
3786
3790
|
if (!value || typeof value !== "object") {
|
|
3787
3791
|
value = {};
|
|
3788
3792
|
}
|
|
3789
3793
|
if (Array.isArray(def.required)) {
|
|
3790
3794
|
for (const key of def.required) {
|
|
3791
|
-
if (
|
|
3795
|
+
if (typeof value[key] === "undefined") {
|
|
3792
3796
|
return {
|
|
3793
3797
|
success: false,
|
|
3794
3798
|
error: new ValidationError(`${path} must have the property "${key}"`)
|
|
@@ -3801,12 +3805,8 @@ function params(lexicons, path, def, value) {
|
|
|
3801
3805
|
continue;
|
|
3802
3806
|
}
|
|
3803
3807
|
const paramDef = def.properties[key];
|
|
3804
|
-
const
|
|
3805
|
-
|
|
3806
|
-
key,
|
|
3807
|
-
paramDef,
|
|
3808
|
-
value[key]
|
|
3809
|
-
);
|
|
3808
|
+
const val = value[key];
|
|
3809
|
+
const res = paramDef.type === "array" ? array(lexicons, key, paramDef, val) : validate(lexicons, key, paramDef, val);
|
|
3810
3810
|
if (!res.success) {
|
|
3811
3811
|
return res;
|
|
3812
3812
|
}
|
|
@@ -3999,7 +3999,17 @@ function constructMethodCallUri(nsid, schema, serviceUri, params2) {
|
|
|
3999
3999
|
throw new Error(`Invalid query parameter: ${key}`);
|
|
4000
4000
|
}
|
|
4001
4001
|
if (value !== void 0) {
|
|
4002
|
-
|
|
4002
|
+
if (paramSchema.type === "array") {
|
|
4003
|
+
const vals = [];
|
|
4004
|
+
vals.concat(value).forEach((val) => {
|
|
4005
|
+
uri.searchParams.append(
|
|
4006
|
+
key,
|
|
4007
|
+
encodeQueryParam(paramSchema.items.type, val)
|
|
4008
|
+
);
|
|
4009
|
+
});
|
|
4010
|
+
} else {
|
|
4011
|
+
uri.searchParams.set(key, encodeQueryParam(paramSchema.type, value));
|
|
4012
|
+
}
|
|
4003
4013
|
}
|
|
4004
4014
|
}
|
|
4005
4015
|
}
|
|
@@ -4177,11 +4187,13 @@ var ServiceClient = class {
|
|
|
4177
4187
|
};
|
|
4178
4188
|
async function defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody) {
|
|
4179
4189
|
try {
|
|
4180
|
-
const
|
|
4190
|
+
const reqInit = {
|
|
4181
4191
|
method: httpMethod,
|
|
4182
4192
|
headers: httpHeaders,
|
|
4183
|
-
body: encodeMethodCallBody(httpHeaders, httpReqBody)
|
|
4184
|
-
|
|
4193
|
+
body: encodeMethodCallBody(httpHeaders, httpReqBody),
|
|
4194
|
+
duplex: "half"
|
|
4195
|
+
};
|
|
4196
|
+
const res = await fetch(httpUri, reqInit);
|
|
4185
4197
|
const resBody = await res.arrayBuffer();
|
|
4186
4198
|
return {
|
|
4187
4199
|
status: res.status,
|
|
@@ -4209,6 +4221,7 @@ var src_default = defaultInst;
|
|
|
4209
4221
|
XRPCError,
|
|
4210
4222
|
XRPCInvalidResponseError,
|
|
4211
4223
|
XRPCResponse,
|
|
4224
|
+
defaultFetchHandler,
|
|
4212
4225
|
errorResponseBody
|
|
4213
4226
|
});
|
|
4214
4227
|
//# sourceMappingURL=index.js.map
|