@atproto/xrpc 0.0.1 → 0.0.2
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/index.js +38 -1
- package/dist/index.js.map +2 -2
- package/dist/src/types.d.ts +7 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/client.ts +11 -1
- package/src/types.ts +15 -0
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __export(src_exports, {
|
|
|
26
26
|
ResponseTypeStrings: () => ResponseTypeStrings,
|
|
27
27
|
ServiceClient: () => ServiceClient,
|
|
28
28
|
XRPCError: () => XRPCError,
|
|
29
|
+
XRPCInvalidResponseError: () => XRPCInvalidResponseError,
|
|
29
30
|
XRPCResponse: () => XRPCResponse,
|
|
30
31
|
default: () => src_default,
|
|
31
32
|
errorResponseBody: () => errorResponseBody
|
|
@@ -3024,6 +3025,18 @@ var XRPCError = class extends Error {
|
|
|
3024
3025
|
}
|
|
3025
3026
|
}
|
|
3026
3027
|
};
|
|
3028
|
+
var XRPCInvalidResponseError = class extends XRPCError {
|
|
3029
|
+
constructor(lexiconNsid, validationError, responseBody) {
|
|
3030
|
+
super(
|
|
3031
|
+
2 /* InvalidResponse */,
|
|
3032
|
+
ResponseTypeStrings[2 /* InvalidResponse */],
|
|
3033
|
+
`The server gave an invalid response and may be out of date.`
|
|
3034
|
+
);
|
|
3035
|
+
this.lexiconNsid = lexiconNsid;
|
|
3036
|
+
this.validationError = validationError;
|
|
3037
|
+
this.responseBody = responseBody;
|
|
3038
|
+
}
|
|
3039
|
+
};
|
|
3027
3040
|
|
|
3028
3041
|
// ../nsid/src/index.ts
|
|
3029
3042
|
var SEGMENT_RE = /^[a-zA-Z]([a-zA-Z0-9-])*$/;
|
|
@@ -3257,7 +3270,7 @@ var lexiconDoc = mod.object({
|
|
|
3257
3270
|
}
|
|
3258
3271
|
});
|
|
3259
3272
|
function isObj(obj) {
|
|
3260
|
-
return
|
|
3273
|
+
return obj !== null && typeof obj === "object";
|
|
3261
3274
|
}
|
|
3262
3275
|
function hasProp(data, prop) {
|
|
3263
3276
|
return prop in data;
|
|
@@ -3834,6 +3847,20 @@ var Lexicons = class {
|
|
|
3834
3847
|
}
|
|
3835
3848
|
return def;
|
|
3836
3849
|
}
|
|
3850
|
+
validate(lexUri, value) {
|
|
3851
|
+
lexUri = toLexUri(lexUri);
|
|
3852
|
+
const def = this.getDefOrThrow(lexUri, ["record", "object"]);
|
|
3853
|
+
if (!isObj(value)) {
|
|
3854
|
+
throw new ValidationError(`Value must be an object`);
|
|
3855
|
+
}
|
|
3856
|
+
if (def.type === "record") {
|
|
3857
|
+
return object(this, "Record", def.record, value);
|
|
3858
|
+
} else if (def.type === "object") {
|
|
3859
|
+
return object(this, "Object", def, value);
|
|
3860
|
+
} else {
|
|
3861
|
+
throw new InvalidLexiconError("Definition must be a record or object");
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3837
3864
|
assertValidRecord(lexUri, value) {
|
|
3838
3865
|
lexUri = toLexUri(lexUri);
|
|
3839
3866
|
const def = this.getDefOrThrow(lexUri, ["record"]);
|
|
@@ -4071,6 +4098,15 @@ var ServiceClient = class {
|
|
|
4071
4098
|
);
|
|
4072
4099
|
const resCode = httpResponseCodeToEnum(res.status);
|
|
4073
4100
|
if (resCode === 200 /* Success */) {
|
|
4101
|
+
try {
|
|
4102
|
+
this.baseClient.lex.assertValidXrpcOutput(methodNsid, res.body);
|
|
4103
|
+
} catch (e) {
|
|
4104
|
+
if (e instanceof ValidationError) {
|
|
4105
|
+
throw new XRPCInvalidResponseError(methodNsid, e, res.body);
|
|
4106
|
+
} else {
|
|
4107
|
+
throw e;
|
|
4108
|
+
}
|
|
4109
|
+
}
|
|
4074
4110
|
return new XRPCResponse(res.body, res.headers);
|
|
4075
4111
|
} else {
|
|
4076
4112
|
if (res.body && isErrorResponseBody(res.body)) {
|
|
@@ -4113,6 +4149,7 @@ var src_default = defaultInst;
|
|
|
4113
4149
|
ResponseTypeStrings,
|
|
4114
4150
|
ServiceClient,
|
|
4115
4151
|
XRPCError,
|
|
4152
|
+
XRPCInvalidResponseError,
|
|
4116
4153
|
XRPCResponse,
|
|
4117
4154
|
errorResponseBody
|
|
4118
4155
|
});
|