@atproto/lex-client 0.0.3 → 0.0.5
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/CHANGELOG.md +36 -0
- package/dist/agent.d.ts +9 -8
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +32 -96
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +31 -31
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +7 -7
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +7 -7
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +5 -6
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +5 -6
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +7 -7
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +7 -7
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +3 -5
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.d.ts +3 -0
- package/dist/lexicons/com/atproto/sync/getBlob.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts +25 -0
- package/dist/lexicons/com/atproto/sync/getBlob.defs.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js +27 -0
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -0
- package/dist/lexicons/com/atproto/sync/getBlob.js +10 -0
- package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -0
- package/dist/lexicons/com/atproto/sync.d.ts +2 -0
- package/dist/lexicons/com/atproto/sync.d.ts.map +1 -0
- package/dist/lexicons/com/atproto/sync.js +9 -0
- package/dist/lexicons/com/atproto/sync.js.map +1 -0
- package/dist/lexicons/com/atproto.d.ts +1 -0
- package/dist/lexicons/com/atproto.d.ts.map +1 -1
- package/dist/lexicons/com/atproto.js +2 -1
- package/dist/lexicons/com/atproto.js.map +1 -1
- package/dist/lexicons.d.ts +2 -0
- package/dist/lexicons.d.ts.map +1 -0
- package/dist/lexicons.js +6 -0
- package/dist/lexicons.js.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +14 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +65 -0
- package/dist/util.js.map +1 -0
- package/dist/xrpc-error.d.ts +87 -0
- package/dist/xrpc-error.d.ts.map +1 -0
- package/dist/xrpc-error.js +127 -0
- package/dist/xrpc-error.js.map +1 -0
- package/dist/xrpc-response.d.ts +35 -0
- package/dist/xrpc-response.d.ts.map +1 -0
- package/dist/xrpc-response.js +140 -0
- package/dist/xrpc-response.js.map +1 -0
- package/dist/xrpc.d.ts +29 -32
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +119 -125
- package/dist/xrpc.js.map +1 -1
- package/package.json +6 -6
- package/src/agent.ts +12 -12
- package/src/client.ts +92 -77
- package/src/index.ts +0 -2
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +9 -8
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +9 -8
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +7 -7
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +7 -6
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +9 -8
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +9 -8
- package/src/lexicons/com/atproto/sync/getBlob.defs.ts +37 -0
- package/src/lexicons/com/atproto/sync/getBlob.ts +6 -0
- package/src/lexicons/com/atproto/sync.ts +5 -0
- package/src/lexicons/com/atproto.ts +1 -0
- package/src/lexicons.ts +1 -0
- package/src/types.ts +27 -0
- package/src/util.ts +84 -0
- package/src/xrpc-error.ts +195 -0
- package/src/xrpc-response.ts +213 -0
- package/src/xrpc.ts +209 -220
- package/dist/error.d.ts +0 -66
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -100
- package/dist/error.js.map +0 -1
- package/dist/response.d.ts +0 -21
- package/dist/response.d.ts.map +0 -1
- package/dist/response.js +0 -31
- package/dist/response.js.map +0 -1
- package/src/error.ts +0 -145
- package/src/response.ts +0 -42
package/dist/error.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XrpcResponseError = exports.XrpcServiceError = exports.XrpcError = exports.xrpcErrorBodySchema = exports.xrpcErrorNameSchema = exports.KnownError = void 0;
|
|
4
|
-
exports.asXrpcRequestFailureFor = asXrpcRequestFailureFor;
|
|
5
|
-
const lex_schema_1 = require("@atproto/lex-schema");
|
|
6
|
-
var KnownError;
|
|
7
|
-
(function (KnownError) {
|
|
8
|
-
KnownError["Unknown"] = "Unknown";
|
|
9
|
-
KnownError["AuthenticationRequired"] = "AuthenticationRequired";
|
|
10
|
-
KnownError["Forbidden"] = "Forbidden";
|
|
11
|
-
KnownError["InternalServerError"] = "InternalServerError";
|
|
12
|
-
KnownError["InvalidRequest"] = "InvalidRequest";
|
|
13
|
-
KnownError["InvalidResponse"] = "InvalidResponse";
|
|
14
|
-
KnownError["MethodNotImplemented"] = "MethodNotImplemented";
|
|
15
|
-
KnownError["NotAcceptable"] = "NotAcceptable";
|
|
16
|
-
KnownError["NotEnoughResources"] = "NotEnoughResources";
|
|
17
|
-
KnownError["PayloadTooLarge"] = "PayloadTooLarge";
|
|
18
|
-
KnownError["RateLimitExceeded"] = "RateLimitExceeded";
|
|
19
|
-
KnownError["UnsupportedMediaType"] = "UnsupportedMediaType";
|
|
20
|
-
KnownError["UpstreamFailure"] = "UpstreamFailure";
|
|
21
|
-
KnownError["UpstreamTimeout"] = "UpstreamTimeout";
|
|
22
|
-
KnownError["XRPCNotSupported"] = "XRPCNotSupported";
|
|
23
|
-
})(KnownError || (exports.KnownError = KnownError = {}));
|
|
24
|
-
exports.xrpcErrorNameSchema = lex_schema_1.l.string({
|
|
25
|
-
minLength: 1,
|
|
26
|
-
});
|
|
27
|
-
exports.xrpcErrorBodySchema = lex_schema_1.l.object({
|
|
28
|
-
error: exports.xrpcErrorNameSchema,
|
|
29
|
-
message: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
30
|
-
});
|
|
31
|
-
/**
|
|
32
|
-
* @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.
|
|
33
|
-
*/
|
|
34
|
-
class XrpcError extends Error {
|
|
35
|
-
name;
|
|
36
|
-
constructor(name, message = name === KnownError.InvalidResponse
|
|
37
|
-
? `XRPC service returned an invalid response`
|
|
38
|
-
: name === KnownError.InternalServerError
|
|
39
|
-
? `XRPC service encountered an internal error`
|
|
40
|
-
: name === KnownError.UpstreamFailure ||
|
|
41
|
-
name === KnownError.UpstreamTimeout
|
|
42
|
-
? `XRPC service upstream error`
|
|
43
|
-
: `XRPC ${name} error`, options) {
|
|
44
|
-
super(message, options);
|
|
45
|
-
this.name = name;
|
|
46
|
-
}
|
|
47
|
-
/** @see {@link l.ResultFailure.success} */
|
|
48
|
-
success = false;
|
|
49
|
-
/** @see {@link l.ResultFailure.error} */
|
|
50
|
-
get error() {
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
static from(cause, message) {
|
|
54
|
-
if (cause instanceof XrpcError) {
|
|
55
|
-
return cause;
|
|
56
|
-
}
|
|
57
|
-
return new XrpcError('Unknown', message ?? (cause instanceof Error ? cause.message : undefined), { cause });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.XrpcError = XrpcError;
|
|
61
|
-
class XrpcServiceError extends XrpcError {
|
|
62
|
-
status;
|
|
63
|
-
headers;
|
|
64
|
-
body;
|
|
65
|
-
constructor(name, status, headers, body, message, options) {
|
|
66
|
-
super(name, message, options);
|
|
67
|
-
this.status = status;
|
|
68
|
-
this.headers = headers;
|
|
69
|
-
this.body = body;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.XrpcServiceError = XrpcServiceError;
|
|
73
|
-
class XrpcResponseError extends XrpcError {
|
|
74
|
-
status;
|
|
75
|
-
headers;
|
|
76
|
-
encoding;
|
|
77
|
-
body;
|
|
78
|
-
constructor(status, headers, encoding, body, options) {
|
|
79
|
-
super(body.error, body.message, options);
|
|
80
|
-
this.status = status;
|
|
81
|
-
this.headers = headers;
|
|
82
|
-
this.encoding = encoding;
|
|
83
|
-
this.body = body;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.XrpcResponseError = XrpcResponseError;
|
|
87
|
-
function asXrpcRequestFailureFor(schema) {
|
|
88
|
-
// Performance: Using .bind instead of arrow function to avoid creating a closure
|
|
89
|
-
return asXrpcRequestFailure.bind(schema);
|
|
90
|
-
}
|
|
91
|
-
function asXrpcRequestFailure(error) {
|
|
92
|
-
if (!(error instanceof XrpcResponseError)) {
|
|
93
|
-
return { success: false, error, name: 'UnexpectedError' };
|
|
94
|
-
}
|
|
95
|
-
if (!this.errors.includes(error.name)) {
|
|
96
|
-
return { success: false, error, name: 'Unknown' };
|
|
97
|
-
}
|
|
98
|
-
return error;
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=error.js.map
|
package/dist/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"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","sourcesContent":["import { LexValue } from '@atproto/lex-data'\nimport { l } from '@atproto/lex-schema'\n\nexport enum KnownError {\n Unknown = 'Unknown',\n AuthenticationRequired = 'AuthenticationRequired',\n Forbidden = 'Forbidden',\n InternalServerError = 'InternalServerError',\n InvalidRequest = 'InvalidRequest',\n InvalidResponse = 'InvalidResponse',\n MethodNotImplemented = 'MethodNotImplemented',\n NotAcceptable = 'NotAcceptable',\n NotEnoughResources = 'NotEnoughResources',\n PayloadTooLarge = 'PayloadTooLarge',\n RateLimitExceeded = 'RateLimitExceeded',\n UnsupportedMediaType = 'UnsupportedMediaType',\n UpstreamFailure = 'UpstreamFailure',\n UpstreamTimeout = 'UpstreamTimeout',\n XRPCNotSupported = 'XRPCNotSupported',\n}\n\nexport type XrpcFailure<N extends string, E> = l.ResultFailure<E> & {\n name: N\n}\n\nexport type XrpcErrorName = l.UnknownString | KnownError\nexport const xrpcErrorNameSchema = l.string({\n minLength: 1,\n})\n\nexport type XrpcErrorBody<N extends XrpcErrorName = XrpcErrorName> = {\n error: N\n message?: string\n}\nexport const xrpcErrorBodySchema = l.object({\n error: xrpcErrorNameSchema,\n message: l.optional(l.string()),\n})\n\n/**\n * @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.\n */\nexport class XrpcError<N extends XrpcErrorName = XrpcErrorName>\n extends Error\n implements XrpcFailure<N, XrpcError<N>>\n{\n constructor(\n public readonly name: N,\n message: string = name === KnownError.InvalidResponse\n ? `XRPC service returned an invalid response`\n : name === KnownError.InternalServerError\n ? `XRPC service encountered an internal error`\n : name === KnownError.UpstreamFailure ||\n name === KnownError.UpstreamTimeout\n ? `XRPC service upstream error`\n : `XRPC ${name} error`,\n options?: ErrorOptions,\n ) {\n super(message, options)\n }\n\n /** @see {@link l.ResultFailure.success} */\n readonly success = false as const\n\n /** @see {@link l.ResultFailure.error} */\n get error(): this {\n return this\n }\n\n static from(cause: unknown, message?: string): XrpcError {\n if (cause instanceof XrpcError) {\n return cause\n }\n return new XrpcError(\n 'Unknown',\n message ?? (cause instanceof Error ? cause.message : undefined),\n { cause },\n )\n }\n}\n\nexport class XrpcServiceError<\n N extends XrpcErrorName = XrpcErrorName,\n> extends XrpcError<N> {\n constructor(\n name: N,\n public readonly status: number,\n public readonly headers: Headers,\n public readonly body: undefined | LexValue,\n message?: string,\n options?: ErrorOptions,\n ) {\n super(name, message, options)\n }\n}\n\nexport class XrpcResponseError<\n N extends XrpcErrorName = XrpcErrorName,\n B extends XrpcErrorBody<N> = XrpcErrorBody<N>,\n> extends XrpcError<N> {\n constructor(\n public readonly status: number,\n public readonly headers: Headers,\n public readonly encoding: undefined | string,\n public readonly body: B,\n options?: ErrorOptions,\n ) {\n super(body.error, body.message, options)\n }\n}\n\nexport type XrpcRequestFailure<M extends l.Procedure | l.Query> =\n // The server responded with a declared error.\n | (M extends { errors: readonly (infer N extends string)[] }\n ? XrpcResponseError<N> // implements XrpcRequestFailure<N, XrpcResponseError<N>>\n : never)\n // The server responded with an error that is not declared in the method's\n // `errors` list.\n | XrpcFailure<'Unknown', XrpcResponseError<string>>\n // An unexpected error occurred (e.g., network error, invalid response, etc.)\n | XrpcFailure<'UnexpectedError', unknown>\n\nexport function asXrpcRequestFailureFor<M extends l.Procedure | l.Query>(\n schema: M,\n) {\n // Performance: Using .bind instead of arrow function to avoid creating a closure\n return asXrpcRequestFailure.bind(schema) as (\n error: unknown,\n ) => XrpcRequestFailure<M>\n}\n\nfunction asXrpcRequestFailure<M extends l.Procedure | l.Query>(\n this: M,\n error: unknown,\n): XrpcRequestFailure<M> {\n if (!(error instanceof XrpcResponseError)) {\n return { success: false, error, name: 'UnexpectedError' }\n }\n\n if (!this.errors.includes(error.name)) {\n return { success: false, error, name: 'Unknown' }\n }\n\n return error\n}\n"]}
|
package/dist/response.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { InferPayloadBody, InferPayloadEncoding, Procedure, Query, ResultSuccess } from '@atproto/lex-schema';
|
|
2
|
-
export type XrpcResponseEncoding<M extends Procedure | Query> = InferPayloadEncoding<M['output']>;
|
|
3
|
-
export type XrpcResponseBody<M extends Procedure | Query> = InferPayloadBody<M['output']>;
|
|
4
|
-
/**
|
|
5
|
-
* Small container for XRPC response data.
|
|
6
|
-
*
|
|
7
|
-
* @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.
|
|
8
|
-
*/
|
|
9
|
-
export declare class XrpcResponse<M extends Procedure | Query> implements ResultSuccess<XrpcResponse<M>> {
|
|
10
|
-
readonly method: M;
|
|
11
|
-
readonly status: number;
|
|
12
|
-
readonly headers: Headers;
|
|
13
|
-
readonly body: XrpcResponseBody<M>;
|
|
14
|
-
/** @see {@link ResultSuccess.success} */
|
|
15
|
-
readonly success: true;
|
|
16
|
-
/** @see {@link ResultSuccess.value} */
|
|
17
|
-
get value(): this;
|
|
18
|
-
get encoding(): XrpcResponseEncoding<M>;
|
|
19
|
-
constructor(method: M, status: number, headers: Headers, body: XrpcResponseBody<M>);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=response.d.ts.map
|
package/dist/response.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,SAAS,EACT,KAAK,EACL,aAAa,EACd,MAAM,qBAAqB,CAAA;AAE5B,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,IAC1D,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEnC,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,IAAI,gBAAgB,CAC1E,CAAC,CAAC,QAAQ,CAAC,CACZ,CAAA;AAED;;;;GAIG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,CACnD,YAAW,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAevC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO;IACzB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAhBpC,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAG,IAAI,CAAS;IAEhC,uCAAuC;IACvC,IAAI,KAAK,IAAI,IAAI,CAEhB;IAED,IAAI,QAAQ,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAEtC;gBAGU,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;CAErC"}
|
package/dist/response.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.XrpcResponse = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Small container for XRPC response data.
|
|
6
|
-
*
|
|
7
|
-
* @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.
|
|
8
|
-
*/
|
|
9
|
-
class XrpcResponse {
|
|
10
|
-
method;
|
|
11
|
-
status;
|
|
12
|
-
headers;
|
|
13
|
-
body;
|
|
14
|
-
/** @see {@link ResultSuccess.success} */
|
|
15
|
-
success = true;
|
|
16
|
-
/** @see {@link ResultSuccess.value} */
|
|
17
|
-
get value() {
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
get encoding() {
|
|
21
|
-
return this.method.output?.encoding;
|
|
22
|
-
}
|
|
23
|
-
constructor(method, status, headers, body) {
|
|
24
|
-
this.method = method;
|
|
25
|
-
this.status = status;
|
|
26
|
-
this.headers = headers;
|
|
27
|
-
this.body = body;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.XrpcResponse = XrpcResponse;
|
|
31
|
-
//# sourceMappingURL=response.js.map
|
package/dist/response.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../src/response.ts"],"names":[],"mappings":";;;AAeA;;;;GAIG;AACH,MAAa,YAAY;IAgBZ;IACA;IACA;IACA;IAhBX,yCAAyC;IAChC,OAAO,GAAG,IAAa,CAAA;IAEhC,uCAAuC;IACvC,IAAI,KAAK;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAA;IACrC,CAAC;IAED,YACW,MAAS,EACT,MAAc,EACd,OAAgB,EAChB,IAAyB;QAHzB,WAAM,GAAN,MAAM,CAAG;QACT,WAAM,GAAN,MAAM,CAAQ;QACd,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAqB;IACjC,CAAC;CACL;AArBD,oCAqBC","sourcesContent":["import {\n InferPayloadBody,\n InferPayloadEncoding,\n Procedure,\n Query,\n ResultSuccess,\n} from '@atproto/lex-schema'\n\nexport type XrpcResponseEncoding<M extends Procedure | Query> =\n InferPayloadEncoding<M['output']>\n\nexport type XrpcResponseBody<M extends Procedure | Query> = InferPayloadBody<\n M['output']\n>\n\n/**\n * Small container for XRPC response data.\n *\n * @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.\n */\nexport class XrpcResponse<M extends Procedure | Query>\n implements ResultSuccess<XrpcResponse<M>>\n{\n /** @see {@link ResultSuccess.success} */\n readonly success = true as const\n\n /** @see {@link ResultSuccess.value} */\n get value(): this {\n return this\n }\n\n get encoding(): XrpcResponseEncoding<M> {\n return this.method.output?.encoding\n }\n\n constructor(\n readonly method: M,\n readonly status: number,\n readonly headers: Headers,\n readonly body: XrpcResponseBody<M>,\n ) {}\n}\n"]}
|
package/src/error.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { LexValue } from '@atproto/lex-data'
|
|
2
|
-
import { l } from '@atproto/lex-schema'
|
|
3
|
-
|
|
4
|
-
export enum KnownError {
|
|
5
|
-
Unknown = 'Unknown',
|
|
6
|
-
AuthenticationRequired = 'AuthenticationRequired',
|
|
7
|
-
Forbidden = 'Forbidden',
|
|
8
|
-
InternalServerError = 'InternalServerError',
|
|
9
|
-
InvalidRequest = 'InvalidRequest',
|
|
10
|
-
InvalidResponse = 'InvalidResponse',
|
|
11
|
-
MethodNotImplemented = 'MethodNotImplemented',
|
|
12
|
-
NotAcceptable = 'NotAcceptable',
|
|
13
|
-
NotEnoughResources = 'NotEnoughResources',
|
|
14
|
-
PayloadTooLarge = 'PayloadTooLarge',
|
|
15
|
-
RateLimitExceeded = 'RateLimitExceeded',
|
|
16
|
-
UnsupportedMediaType = 'UnsupportedMediaType',
|
|
17
|
-
UpstreamFailure = 'UpstreamFailure',
|
|
18
|
-
UpstreamTimeout = 'UpstreamTimeout',
|
|
19
|
-
XRPCNotSupported = 'XRPCNotSupported',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type XrpcFailure<N extends string, E> = l.ResultFailure<E> & {
|
|
23
|
-
name: N
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type XrpcErrorName = l.UnknownString | KnownError
|
|
27
|
-
export const xrpcErrorNameSchema = l.string({
|
|
28
|
-
minLength: 1,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
export type XrpcErrorBody<N extends XrpcErrorName = XrpcErrorName> = {
|
|
32
|
-
error: N
|
|
33
|
-
message?: string
|
|
34
|
-
}
|
|
35
|
-
export const xrpcErrorBodySchema = l.object({
|
|
36
|
-
error: xrpcErrorNameSchema,
|
|
37
|
-
message: l.optional(l.string()),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @implements {XrpcFailure<N, XrpcError<N>>} for convenience in result handling contexts.
|
|
42
|
-
*/
|
|
43
|
-
export class XrpcError<N extends XrpcErrorName = XrpcErrorName>
|
|
44
|
-
extends Error
|
|
45
|
-
implements XrpcFailure<N, XrpcError<N>>
|
|
46
|
-
{
|
|
47
|
-
constructor(
|
|
48
|
-
public readonly name: N,
|
|
49
|
-
message: string = name === KnownError.InvalidResponse
|
|
50
|
-
? `XRPC service returned an invalid response`
|
|
51
|
-
: name === KnownError.InternalServerError
|
|
52
|
-
? `XRPC service encountered an internal error`
|
|
53
|
-
: name === KnownError.UpstreamFailure ||
|
|
54
|
-
name === KnownError.UpstreamTimeout
|
|
55
|
-
? `XRPC service upstream error`
|
|
56
|
-
: `XRPC ${name} error`,
|
|
57
|
-
options?: ErrorOptions,
|
|
58
|
-
) {
|
|
59
|
-
super(message, options)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** @see {@link l.ResultFailure.success} */
|
|
63
|
-
readonly success = false as const
|
|
64
|
-
|
|
65
|
-
/** @see {@link l.ResultFailure.error} */
|
|
66
|
-
get error(): this {
|
|
67
|
-
return this
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static from(cause: unknown, message?: string): XrpcError {
|
|
71
|
-
if (cause instanceof XrpcError) {
|
|
72
|
-
return cause
|
|
73
|
-
}
|
|
74
|
-
return new XrpcError(
|
|
75
|
-
'Unknown',
|
|
76
|
-
message ?? (cause instanceof Error ? cause.message : undefined),
|
|
77
|
-
{ cause },
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export class XrpcServiceError<
|
|
83
|
-
N extends XrpcErrorName = XrpcErrorName,
|
|
84
|
-
> extends XrpcError<N> {
|
|
85
|
-
constructor(
|
|
86
|
-
name: N,
|
|
87
|
-
public readonly status: number,
|
|
88
|
-
public readonly headers: Headers,
|
|
89
|
-
public readonly body: undefined | LexValue,
|
|
90
|
-
message?: string,
|
|
91
|
-
options?: ErrorOptions,
|
|
92
|
-
) {
|
|
93
|
-
super(name, message, options)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export class XrpcResponseError<
|
|
98
|
-
N extends XrpcErrorName = XrpcErrorName,
|
|
99
|
-
B extends XrpcErrorBody<N> = XrpcErrorBody<N>,
|
|
100
|
-
> extends XrpcError<N> {
|
|
101
|
-
constructor(
|
|
102
|
-
public readonly status: number,
|
|
103
|
-
public readonly headers: Headers,
|
|
104
|
-
public readonly encoding: undefined | string,
|
|
105
|
-
public readonly body: B,
|
|
106
|
-
options?: ErrorOptions,
|
|
107
|
-
) {
|
|
108
|
-
super(body.error, body.message, options)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export type XrpcRequestFailure<M extends l.Procedure | l.Query> =
|
|
113
|
-
// The server responded with a declared error.
|
|
114
|
-
| (M extends { errors: readonly (infer N extends string)[] }
|
|
115
|
-
? XrpcResponseError<N> // implements XrpcRequestFailure<N, XrpcResponseError<N>>
|
|
116
|
-
: never)
|
|
117
|
-
// The server responded with an error that is not declared in the method's
|
|
118
|
-
// `errors` list.
|
|
119
|
-
| XrpcFailure<'Unknown', XrpcResponseError<string>>
|
|
120
|
-
// An unexpected error occurred (e.g., network error, invalid response, etc.)
|
|
121
|
-
| XrpcFailure<'UnexpectedError', unknown>
|
|
122
|
-
|
|
123
|
-
export function asXrpcRequestFailureFor<M extends l.Procedure | l.Query>(
|
|
124
|
-
schema: M,
|
|
125
|
-
) {
|
|
126
|
-
// Performance: Using .bind instead of arrow function to avoid creating a closure
|
|
127
|
-
return asXrpcRequestFailure.bind(schema) as (
|
|
128
|
-
error: unknown,
|
|
129
|
-
) => XrpcRequestFailure<M>
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function asXrpcRequestFailure<M extends l.Procedure | l.Query>(
|
|
133
|
-
this: M,
|
|
134
|
-
error: unknown,
|
|
135
|
-
): XrpcRequestFailure<M> {
|
|
136
|
-
if (!(error instanceof XrpcResponseError)) {
|
|
137
|
-
return { success: false, error, name: 'UnexpectedError' }
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!this.errors.includes(error.name)) {
|
|
141
|
-
return { success: false, error, name: 'Unknown' }
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return error
|
|
145
|
-
}
|
package/src/response.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InferPayloadBody,
|
|
3
|
-
InferPayloadEncoding,
|
|
4
|
-
Procedure,
|
|
5
|
-
Query,
|
|
6
|
-
ResultSuccess,
|
|
7
|
-
} from '@atproto/lex-schema'
|
|
8
|
-
|
|
9
|
-
export type XrpcResponseEncoding<M extends Procedure | Query> =
|
|
10
|
-
InferPayloadEncoding<M['output']>
|
|
11
|
-
|
|
12
|
-
export type XrpcResponseBody<M extends Procedure | Query> = InferPayloadBody<
|
|
13
|
-
M['output']
|
|
14
|
-
>
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Small container for XRPC response data.
|
|
18
|
-
*
|
|
19
|
-
* @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.
|
|
20
|
-
*/
|
|
21
|
-
export class XrpcResponse<M extends Procedure | Query>
|
|
22
|
-
implements ResultSuccess<XrpcResponse<M>>
|
|
23
|
-
{
|
|
24
|
-
/** @see {@link ResultSuccess.success} */
|
|
25
|
-
readonly success = true as const
|
|
26
|
-
|
|
27
|
-
/** @see {@link ResultSuccess.value} */
|
|
28
|
-
get value(): this {
|
|
29
|
-
return this
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get encoding(): XrpcResponseEncoding<M> {
|
|
33
|
-
return this.method.output?.encoding
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor(
|
|
37
|
-
readonly method: M,
|
|
38
|
-
readonly status: number,
|
|
39
|
-
readonly headers: Headers,
|
|
40
|
-
readonly body: XrpcResponseBody<M>,
|
|
41
|
-
) {}
|
|
42
|
-
}
|