@atproto/lex-client 0.0.4 → 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 +27 -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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.$output = exports.$params = exports.$lxm = exports.main = exports.$nsid = void 0;
|
|
7
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
8
|
+
const $nsid = 'com.atproto.sync.getBlob';
|
|
9
|
+
exports.$nsid = $nsid;
|
|
10
|
+
/** Get a blob associated with a given account. Returns the full blob as originally uploaded. Does not require auth; implemented by PDS. */
|
|
11
|
+
const main =
|
|
12
|
+
/*#__PURE__*/
|
|
13
|
+
lex_schema_1.l.query($nsid,
|
|
14
|
+
/*#__PURE__*/ lex_schema_1.l.params({
|
|
15
|
+
did: /*#__PURE__*/ lex_schema_1.l.string({ format: 'did' }),
|
|
16
|
+
cid: /*#__PURE__*/ lex_schema_1.l.string({ format: 'cid' }),
|
|
17
|
+
}),
|
|
18
|
+
/*#__PURE__*/ lex_schema_1.l.payload('*/*'), [
|
|
19
|
+
'BlobNotFound',
|
|
20
|
+
'RepoNotFound',
|
|
21
|
+
'RepoTakendown',
|
|
22
|
+
'RepoSuspended',
|
|
23
|
+
'RepoDeactivated',
|
|
24
|
+
]);
|
|
25
|
+
exports.main = main;
|
|
26
|
+
exports.$lxm = main.nsid, exports.$params = main.parameters, exports.$output = main.output;
|
|
27
|
+
//# sourceMappingURL=getBlob.defs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBlob.defs.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getBlob.defs.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,oDAAuC;AAEvC,MAAM,KAAK,GAAG,0BAA0B,CAAA;AAE/B,sBAAK;AAEd,2IAA2I;AAC3I,MAAM,IAAI;AACR,aAAa;AACb,cAAC,CAAC,KAAK,CACL,KAAK;AACL,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC;IACrB,GAAG,EAAE,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC9C,GAAG,EAAE,aAAa,CAAC,cAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;CAC/C,CAAC;AACF,aAAa,CAAC,cAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAC9B;IACE,cAAc;IACd,cAAc;IACd,eAAe;IACf,eAAe;IACf,iBAAiB;CAClB,CACF,CAAA;AACM,oBAAI;AAMA,QAAA,IAAI,GAAiB,IAAI,CAAC,IAAI,EACzC,QAAA,OAAO,GAAG,IAAI,CAAC,UAAU,EACzB,QAAA,OAAO,GAAG,IAAI,CAAC,MAAM,CAAA","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nimport { l } from '@atproto/lex-schema'\n\nconst $nsid = 'com.atproto.sync.getBlob'\n\nexport { $nsid }\n\n/** Get a blob associated with a given account. Returns the full blob as originally uploaded. Does not require auth; implemented by PDS. */\nconst main =\n /*#__PURE__*/\n l.query(\n $nsid,\n /*#__PURE__*/ l.params({\n did: /*#__PURE__*/ l.string({ format: 'did' }),\n cid: /*#__PURE__*/ l.string({ format: 'cid' }),\n }),\n /*#__PURE__*/ l.payload('*/*'),\n [\n 'BlobNotFound',\n 'RepoNotFound',\n 'RepoTakendown',\n 'RepoSuspended',\n 'RepoDeactivated',\n ],\n )\nexport { main }\n\nexport type Params = l.InferMethodParams<typeof main>\nexport type Output = l.InferMethodOutput<typeof main>\nexport type OutputBody = l.InferMethodOutputBody<typeof main>\n\nexport const $lxm = /*#__PURE__*/ main.nsid,\n $params = main.parameters,\n $output = main.output\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.$defs = void 0;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
tslib_1.__exportStar(require("./getBlob.defs.js"), exports);
|
|
9
|
+
exports.$defs = tslib_1.__importStar(require("./getBlob.defs.js"));
|
|
10
|
+
//# sourceMappingURL=getBlob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBlob.js","sourceRoot":"","sources":["../../../../../src/lexicons/com/atproto/sync/getBlob.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,4DAAiC;AACjC,mEAA0C","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * from './getBlob.defs.js'\nexport * as $defs from './getBlob.defs.js'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/sync.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBlob = void 0;
|
|
7
|
+
const tslib_1 = require("tslib");
|
|
8
|
+
exports.getBlob = tslib_1.__importStar(require("./sync/getBlob.js"));
|
|
9
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../../../src/lexicons/com/atproto/sync.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,qEAA4C","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as getBlob from './sync/getBlob.js'\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.d.ts","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"atproto.d.ts","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA;AACzC,OAAO,KAAK,IAAI,MAAM,mBAAmB,CAAA"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.repo = void 0;
|
|
6
|
+
exports.sync = exports.repo = void 0;
|
|
7
7
|
const tslib_1 = require("tslib");
|
|
8
8
|
exports.repo = tslib_1.__importStar(require("./atproto/repo.js"));
|
|
9
|
+
exports.sync = tslib_1.__importStar(require("./atproto/sync.js"));
|
|
9
10
|
//# sourceMappingURL=atproto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,kEAAyC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as repo from './atproto/repo.js'\n"]}
|
|
1
|
+
{"version":3,"file":"atproto.js","sourceRoot":"","sources":["../../../src/lexicons/com/atproto.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAEH,kEAAyC;AACzC,kEAAyC","sourcesContent":["/*\n * THIS FILE WAS GENERATED BY \"@atproto/lex\". DO NOT EDIT.\n */\n\nexport * as repo from './atproto/repo.js'\nexport * as sync from './atproto/sync.js'\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexicons.d.ts","sourceRoot":"","sources":["../src/lexicons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,mBAAmB,CAAA"}
|
package/dist/lexicons.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexicons.js","sourceRoot":"","sources":["../src/lexicons.ts"],"names":[],"mappings":";;;;AAAA,iEAAwC","sourcesContent":["export * as com from './lexicons/com.js'\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -7,9 +7,27 @@ export type CallOptions = {
|
|
|
7
7
|
signal?: AbortSignal;
|
|
8
8
|
headers?: HeadersInit;
|
|
9
9
|
service?: Service;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to validate the request against the method's input schema. Enabling
|
|
12
|
+
* this can help catch errors early but may have a performance cost. This
|
|
13
|
+
* would typically only be set to `true` in development or debugging
|
|
14
|
+
* scenarios.
|
|
15
|
+
*
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
10
18
|
validateRequest?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to validate the response against the method's output schema.
|
|
21
|
+
* Disabling this can improve performance but may lead to runtime errors if
|
|
22
|
+
* the response does not conform to the expected schema. Only set this to
|
|
23
|
+
* `false` if you are certain that the upstream service will always return
|
|
24
|
+
* valid responses.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
11
28
|
validateResponse?: boolean;
|
|
12
29
|
};
|
|
30
|
+
export type BinaryBodyInit = Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array> | string;
|
|
13
31
|
export type Namespace<T> = T | {
|
|
14
32
|
main: T;
|
|
15
33
|
};
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAE9D,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,CAAA;AAExC,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,aAAa,CAAA;AACpE,MAAM,MAAM,OAAO,GAAG,GAAG,SAAS,IAAI,oBAAoB,EAAE,CAAA;AAE5D,MAAM,MAAM,W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oot":"","sources":["../src/types.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;AA6CA,0BAEC;AAFD,SAAgB,OAAO,CAAmB,EAAgB;IACxD,OAAO,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;AACpC,CAAC","sourcesContent":["import { DidString, UnknownString } from '@atproto/lex-schema'\n\nexport type { DidString, UnknownString }\n\nexport type DidServiceIdentifier = 'atproto_labeler' | UnknownString\nexport type Service = `${DidString}#${DidServiceIdentifier}`\n\nexport type CallOptions = {\n labelers?: Iterable<DidString>\n signal?: AbortSignal\n headers?: HeadersInit\n service?: Service\n\n /**\n * Whether to validate the request against the method's input schema. Enabling\n * this can help catch errors early but may have a performance cost. This\n * would typically only be set to `true` in development or debugging\n * scenarios.\n *\n * @default false\n */\n validateRequest?: boolean\n\n /**\n * Whether to validate the response against the method's output schema.\n * Disabling this can improve performance but may lead to runtime errors if\n * the response does not conform to the expected schema. Only set this to\n * `false` if you are certain that the upstream service will always return\n * valid responses.\n *\n * @default true\n */\n validateResponse?: boolean\n}\n\nexport type BinaryBodyInit =\n | Uint8Array\n | ArrayBuffer\n | Blob\n | ReadableStream<Uint8Array>\n | AsyncIterable<Uint8Array>\n | string\n\nexport type Namespace<T> = T | { main: T }\n\nexport function getMain<T extends object>(ns: Namespace<T>): T {\n return 'main' in ns ? ns.main : ns\n}\n"]}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DidString } from '@atproto/lex-schema';
|
|
2
|
+
export type Payload<B = unknown, E extends string = string> = {
|
|
3
|
+
body: B;
|
|
4
|
+
encoding: E;
|
|
5
|
+
};
|
|
6
|
+
export declare function isBlobLike(value: unknown): value is Blob;
|
|
7
|
+
export declare function isAsyncIterable<T>(value: T): value is unknown extends T ? T & AsyncIterable<unknown> : Extract<T, AsyncIterable<any>>;
|
|
8
|
+
export declare function buildAtprotoHeaders(options: {
|
|
9
|
+
headers?: HeadersInit;
|
|
10
|
+
service?: `${DidString}#${string}`;
|
|
11
|
+
labelers?: Iterable<DidString>;
|
|
12
|
+
}): Headers;
|
|
13
|
+
export declare function toReadableStream(data: AsyncIterable<Uint8Array>): ReadableStream<Uint8Array>;
|
|
14
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,MAAM,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,IAAI,EAAE,CAAC,CAAA;IACP,QAAQ,EAAE,CAAC,CAAA;CACZ,CAAA;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAexD;AAED,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,CAAC,GACP,KAAK,IAAI,OAAO,SAAS,CAAC,GACzB,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,GAC1B,OAAO,CAAC,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAIjC;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,GAAG,SAAS,IAAI,MAAM,EAAE,CAAA;IAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;CAC/B,GAAG,OAAO,CAiBV;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,GAC9B,cAAc,CAAC,UAAU,CAAC,CAwB5B"}
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBlobLike = isBlobLike;
|
|
4
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
5
|
+
exports.buildAtprotoHeaders = buildAtprotoHeaders;
|
|
6
|
+
exports.toReadableStream = toReadableStream;
|
|
7
|
+
function isBlobLike(value) {
|
|
8
|
+
if (value == null)
|
|
9
|
+
return false;
|
|
10
|
+
if (typeof value !== 'object')
|
|
11
|
+
return false;
|
|
12
|
+
if (typeof Blob === 'function' && value instanceof Blob)
|
|
13
|
+
return true;
|
|
14
|
+
// Support for Blobs provided by libraries that don't use the native Blob
|
|
15
|
+
// (e.g. fetch-blob from node-fetch).
|
|
16
|
+
// https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244
|
|
17
|
+
const tag = value[Symbol.toStringTag];
|
|
18
|
+
if (tag === 'Blob' || tag === 'File') {
|
|
19
|
+
return 'stream' in value && typeof value.stream === 'function';
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function isAsyncIterable(value) {
|
|
24
|
+
return (value != null && typeof value[Symbol.asyncIterator] === 'function');
|
|
25
|
+
}
|
|
26
|
+
function buildAtprotoHeaders(options) {
|
|
27
|
+
const headers = new Headers(options?.headers);
|
|
28
|
+
if (options.service && !headers.has('atproto-proxy')) {
|
|
29
|
+
headers.set('atproto-proxy', options.service);
|
|
30
|
+
}
|
|
31
|
+
if (options.labelers) {
|
|
32
|
+
headers.set('atproto-accept-labelers', [...options.labelers, headers.get('atproto-accept-labelers')?.trim()]
|
|
33
|
+
.filter(Boolean)
|
|
34
|
+
.join(', '));
|
|
35
|
+
}
|
|
36
|
+
return headers;
|
|
37
|
+
}
|
|
38
|
+
function toReadableStream(data) {
|
|
39
|
+
// Use the native ReadableStream.from() if available.
|
|
40
|
+
if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {
|
|
41
|
+
return ReadableStream.from(data);
|
|
42
|
+
}
|
|
43
|
+
let iterator;
|
|
44
|
+
return new ReadableStream({
|
|
45
|
+
async pull(controller) {
|
|
46
|
+
try {
|
|
47
|
+
iterator ??= data[Symbol.asyncIterator]();
|
|
48
|
+
const result = await iterator.next();
|
|
49
|
+
if (result.done)
|
|
50
|
+
controller.close();
|
|
51
|
+
else
|
|
52
|
+
controller.enqueue(result.value);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
controller.error(err);
|
|
56
|
+
iterator = undefined;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
async cancel() {
|
|
60
|
+
await iterator?.return?.();
|
|
61
|
+
iterator = undefined;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;AAOA,gCAeC;AAED,0CAQC;AAED,kDAqBC;AAED,4CA0BC;AA5ED,SAAgB,UAAU,CAAC,KAAc;IACvC,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,OAAO,IAAI,KAAK,UAAU,IAAI,KAAK,YAAY,IAAI;QAAE,OAAO,IAAI,CAAA;IAEpE,yEAAyE;IACzE,qCAAqC;IACrC,4GAA4G;IAE5G,MAAM,GAAG,GAAI,KAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC9C,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACrC,OAAO,QAAQ,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,CAAA;IAChE,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAgB,eAAe,CAC7B,K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AAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACvC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACrB,QAAQ,GAAG,SAAS,CAAA;YACtB,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM;YACV,MAAM,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAA;YAC1B,QAAQ,GAAG,SAAS,CAAA;QACtB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { DidString } from '@atproto/lex-schema'\n\nexport type Payload<B = unknown, E extends string = string> = {\n body: B\n encoding: E\n}\n\nexport function isBlobLike(value: unknown): value is Blob {\n if (value == null) return false\n if (typeof value !== 'object') return false\n if (typeof Blob === 'function' && value instanceof Blob) return true\n\n // Support for Blobs provided by libraries that don't use the native Blob\n // (e.g. fetch-blob from node-fetch).\n // https://github.com/node-fetch/fetch-blob/blob/a1a182e5978811407bef4ea1632b517567dda01f/index.js#L233-L244\n\n const tag = (value as any)[Symbol.toStringTag]\n if (tag === 'Blob' || tag === 'File') {\n return 'stream' in value && typeof value.stream === 'function'\n }\n\n return false\n}\n\nexport function isAsyncIterable<T>(\n value: T,\n): value is unknown extends T\n ? T & AsyncIterable<unknown>\n : Extract<T, AsyncIterable<any>> {\n return (\n value != null && typeof (value as any)[Symbol.asyncIterator] === 'function'\n )\n}\n\nexport function buildAtprotoHeaders(options: {\n headers?: HeadersInit\n service?: `${DidString}#${string}`\n labelers?: Iterable<DidString>\n}): Headers {\n const headers = new Headers(options?.headers)\n\n if (options.service && !headers.has('atproto-proxy')) {\n headers.set('atproto-proxy', options.service)\n }\n\n if (options.labelers) {\n headers.set(\n 'atproto-accept-labelers',\n [...options.labelers, headers.get('atproto-accept-labelers')?.trim()]\n .filter(Boolean)\n .join(', '),\n )\n }\n\n return headers\n}\n\nexport function toReadableStream(\n data: AsyncIterable<Uint8Array>,\n): ReadableStream<Uint8Array> {\n // Use the native ReadableStream.from() if available.\n if ('from' in ReadableStream && typeof ReadableStream.from === 'function') {\n return ReadableStream.from(data)\n }\n\n let iterator: AsyncIterator<Uint8Array> | undefined\n return new ReadableStream({\n async pull(controller) {\n try {\n iterator ??= data[Symbol.asyncIterator]()\n const result = await iterator!.next()\n if (result.done) controller.close()\n else controller.enqueue(result.value)\n } catch (err) {\n controller.error(err)\n iterator = undefined\n }\n },\n async cancel() {\n await iterator?.return?.()\n iterator = undefined\n },\n })\n}\n"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { l } from '@atproto/lex-schema';
|
|
2
|
+
import { Payload } from './util.js';
|
|
3
|
+
export type XrpcErrorCode = string;
|
|
4
|
+
export declare const xrpcErrorCodeSchema: l.Schema<XrpcErrorCode>;
|
|
5
|
+
export declare class XrpcError<N extends XrpcErrorCode = XrpcErrorCode> extends Error {
|
|
6
|
+
readonly error: N;
|
|
7
|
+
name: string;
|
|
8
|
+
constructor(error: N, message?: string, options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
export type XrpcErrorBody<N extends XrpcErrorCode = XrpcErrorCode> = {
|
|
11
|
+
error: N;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
export type XrpcErrorPayload<N extends XrpcErrorCode = XrpcErrorCode> = {
|
|
15
|
+
encoding: 'application/json';
|
|
16
|
+
body: XrpcErrorBody<N>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* All unsuccessful responses should follow a standard error response
|
|
20
|
+
* schema. The Content-Type should be application/json, and the payload
|
|
21
|
+
* should be a JSON object with the following fields:
|
|
22
|
+
*
|
|
23
|
+
* - `error` (string, required): type name of the error (generic ASCII
|
|
24
|
+
* constant, no whitespace)
|
|
25
|
+
* - `message` (string, optional): description of the error, appropriate for
|
|
26
|
+
* display to humans
|
|
27
|
+
*
|
|
28
|
+
* This function checks whether a given payload matches this schema.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isXrpcErrorPayload(payload: Payload | null): payload is XrpcErrorPayload;
|
|
31
|
+
/**
|
|
32
|
+
* Interface representing a failed XRPC request result.
|
|
33
|
+
*/
|
|
34
|
+
type XrpcFailureResult<N extends XrpcErrorCode, E> = l.ResultFailure<E> & {
|
|
35
|
+
readonly error: N;
|
|
36
|
+
shouldRetry(): boolean;
|
|
37
|
+
matchesSchema(): boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Class used to represent an HTTP request that resulted in an XRPC method error
|
|
41
|
+
* That is, a non-2xx response with a valid XRPC error payload.
|
|
42
|
+
*/
|
|
43
|
+
export declare class XrpcResponseError<M extends l.Procedure | l.Query = l.Procedure | l.Query, N extends XrpcErrorCode = XrpcErrorCode> extends XrpcError<N> implements XrpcFailureResult<N, XrpcResponseError<M, N>> {
|
|
44
|
+
readonly method: M;
|
|
45
|
+
readonly status: number;
|
|
46
|
+
readonly headers: Headers;
|
|
47
|
+
readonly payload: XrpcErrorPayload<N>;
|
|
48
|
+
name: "XrpcResponseError";
|
|
49
|
+
constructor(method: M, status: number, headers: Headers, payload: XrpcErrorPayload<N>, options?: ErrorOptions);
|
|
50
|
+
readonly success = false;
|
|
51
|
+
get reason(): this;
|
|
52
|
+
get body(): XrpcErrorBody;
|
|
53
|
+
matchesSchema(): this is M extends {
|
|
54
|
+
errors: readonly (infer E extends string)[];
|
|
55
|
+
} ? XrpcResponseError<M, E> : never;
|
|
56
|
+
shouldRetry(): boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* This class represents an invalid XRPC response from the server.
|
|
60
|
+
*/
|
|
61
|
+
export declare class XrpcInvalidResponseError extends XrpcError<'UpstreamFailure'> implements XrpcFailureResult<'UpstreamFailure', XrpcInvalidResponseError> {
|
|
62
|
+
name: "XrpcInvalidResponseError";
|
|
63
|
+
readonly response: {
|
|
64
|
+
status: number;
|
|
65
|
+
headers: Headers;
|
|
66
|
+
payload: Payload | null;
|
|
67
|
+
};
|
|
68
|
+
constructor(message: string, response: {
|
|
69
|
+
status: number;
|
|
70
|
+
headers: Headers;
|
|
71
|
+
}, payload: Payload | null, options?: ErrorOptions);
|
|
72
|
+
readonly success: false;
|
|
73
|
+
get reason(): this;
|
|
74
|
+
matchesSchema(): false;
|
|
75
|
+
shouldRetry(): boolean;
|
|
76
|
+
}
|
|
77
|
+
export declare class XrpcUnexpectedError extends XrpcError<'InternalServerError'> implements XrpcFailureResult<'InternalServerError', unknown> {
|
|
78
|
+
name: "XrpcUnexpectedError";
|
|
79
|
+
protected constructor(message: string, options: Required<ErrorOptions>);
|
|
80
|
+
readonly success = false;
|
|
81
|
+
get reason(): unknown;
|
|
82
|
+
matchesSchema(): false;
|
|
83
|
+
shouldRetry(): boolean;
|
|
84
|
+
static from(cause: unknown, message?: string): XrpcUnexpectedError;
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
87
|
+
//# sourceMappingURL=xrpc-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xrpc-error.d.ts","sourceRoot":"","sources":["../src/xrpc-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAClC,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAEtD,CAAA;AAEF,qBAAa,SAAS,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,CAAE,SAAQ,KAAK;IAIzE,QAAQ,CAAC,KAAK,EAAE,CAAC;IAHnB,IAAI,SAAc;gBAGP,KAAK,EAAE,CAAC,EACjB,OAAO,GAAE,MAA2C,EACpD,OAAO,CAAC,EAAE,YAAY;CAIzB;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,IAAI;IACnE,KAAK,EAAE,CAAC,CAAA;IACR,OAAO,CAAC,EAA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d,OAAO,GAAE,MAEgB,GACxB,mBAAmB;CAIvB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XrpcUnexpectedError = exports.XrpcInvalidResponseError = exports.XrpcResponseError = exports.XrpcError = exports.xrpcErrorCodeSchema = void 0;
|
|
4
|
+
exports.isXrpcErrorPayload = isXrpcErrorPayload;
|
|
5
|
+
const lex_schema_1 = require("@atproto/lex-schema");
|
|
6
|
+
exports.xrpcErrorCodeSchema = lex_schema_1.l.string({
|
|
7
|
+
minLength: 1,
|
|
8
|
+
});
|
|
9
|
+
class XrpcError extends Error {
|
|
10
|
+
error;
|
|
11
|
+
name = 'XrpcError';
|
|
12
|
+
constructor(error, message = `An ${error} XRPC error occurred.`, options) {
|
|
13
|
+
super(message, options);
|
|
14
|
+
this.error = error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.XrpcError = XrpcError;
|
|
18
|
+
const xrpcErrorBodySchema = lex_schema_1.l.object({
|
|
19
|
+
error: exports.xrpcErrorCodeSchema,
|
|
20
|
+
message: lex_schema_1.l.optional(lex_schema_1.l.string()),
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* All unsuccessful responses should follow a standard error response
|
|
24
|
+
* schema. The Content-Type should be application/json, and the payload
|
|
25
|
+
* should be a JSON object with the following fields:
|
|
26
|
+
*
|
|
27
|
+
* - `error` (string, required): type name of the error (generic ASCII
|
|
28
|
+
* constant, no whitespace)
|
|
29
|
+
* - `message` (string, optional): description of the error, appropriate for
|
|
30
|
+
* display to humans
|
|
31
|
+
*
|
|
32
|
+
* This function checks whether a given payload matches this schema.
|
|
33
|
+
*/
|
|
34
|
+
function isXrpcErrorPayload(payload) {
|
|
35
|
+
return (payload !== null &&
|
|
36
|
+
payload.encoding === 'application/json' &&
|
|
37
|
+
xrpcErrorBodySchema.matches(payload.body));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Class used to represent an HTTP request that resulted in an XRPC method error
|
|
41
|
+
* That is, a non-2xx response with a valid XRPC error payload.
|
|
42
|
+
*/
|
|
43
|
+
class XrpcResponseError extends XrpcError {
|
|
44
|
+
method;
|
|
45
|
+
status;
|
|
46
|
+
headers;
|
|
47
|
+
payload;
|
|
48
|
+
name = 'XrpcResponseError';
|
|
49
|
+
constructor(method, status, headers, payload, options) {
|
|
50
|
+
const { error, message } = payload.body;
|
|
51
|
+
super(error, message, options);
|
|
52
|
+
this.method = method;
|
|
53
|
+
this.status = status;
|
|
54
|
+
this.headers = headers;
|
|
55
|
+
this.payload = payload;
|
|
56
|
+
}
|
|
57
|
+
success = false;
|
|
58
|
+
get reason() {
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
get body() {
|
|
62
|
+
return this.payload.body;
|
|
63
|
+
}
|
|
64
|
+
matchesSchema() {
|
|
65
|
+
return this.method.errors?.includes(this.error) ?? false;
|
|
66
|
+
}
|
|
67
|
+
shouldRetry() {
|
|
68
|
+
// Do not retry client errors
|
|
69
|
+
if (this.status < 500)
|
|
70
|
+
return false;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.XrpcResponseError = XrpcResponseError;
|
|
75
|
+
/**
|
|
76
|
+
* This class represents an invalid XRPC response from the server.
|
|
77
|
+
*/
|
|
78
|
+
class XrpcInvalidResponseError extends XrpcError {
|
|
79
|
+
name = 'XrpcInvalidResponseError';
|
|
80
|
+
// For debugging purposes, we keep the response details here
|
|
81
|
+
response;
|
|
82
|
+
constructor(message, response, payload, options) {
|
|
83
|
+
super('UpstreamFailure', message, { cause: options?.cause });
|
|
84
|
+
this.response = {
|
|
85
|
+
status: response.status,
|
|
86
|
+
headers: response.headers,
|
|
87
|
+
payload,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
success = false;
|
|
91
|
+
get reason() {
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
matchesSchema() {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
shouldRetry() {
|
|
98
|
+
// Do not retry client errors
|
|
99
|
+
return this.response.status >= 500;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.XrpcInvalidResponseError = XrpcInvalidResponseError;
|
|
103
|
+
class XrpcUnexpectedError extends XrpcError {
|
|
104
|
+
name = 'XrpcUnexpectedError';
|
|
105
|
+
constructor(message, options) {
|
|
106
|
+
super('InternalServerError', message, options);
|
|
107
|
+
}
|
|
108
|
+
success = false;
|
|
109
|
+
get reason() {
|
|
110
|
+
return this.cause;
|
|
111
|
+
}
|
|
112
|
+
matchesSchema() {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
shouldRetry() {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
static from(cause, message = cause instanceof XrpcError
|
|
119
|
+
? cause.message
|
|
120
|
+
: 'XRPC request failed') {
|
|
121
|
+
if (cause instanceof XrpcUnexpectedError)
|
|
122
|
+
return cause;
|
|
123
|
+
return new XrpcUnexpectedError(message, { cause });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.XrpcUnexpectedError = XrpcUnexpectedError;
|
|
127
|
+
//# sourceMappingURL=xrpc-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xrpc-error.js","sourceRoot":"","sources":["../src/xrpc-error.ts"],"names":[],"mappings":";;;AA8CA,gDAQC;AAtDD,oDAAuC;AAI1B,QAAA,mBAAmB,GAA4B,cAAC,CAAC,MAAM,CAAC;IACnE,SAAS,EAAE,CAAC;CACb,CAAC,CAAA;AAEF,MAAa,SAAmD,SAAQ,KAAK;IAIhE;IAHX,IAAI,GAAG,WAAW,CAAA;IAElB,YACW,KAAQ,EACjB,UAAkB,MAAM,KAAK,uBAAuB,EACpD,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAJd,UAAK,G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AAY,mBAAmB;YAAE,OAAO,KAAK,CAAA;QACtD,OAAO,IAAI,mBAAmB,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IACpD,CAAC;CACF;AAjCD,kDAiCC","sourcesContent":["import { l } from '@atproto/lex-schema'\nimport { Payload } from './util.js'\n\nexport type XrpcErrorCode = string\nexport const xrpcErrorCodeSchema: l.Schema<XrpcErrorCode> = l.string({\n minLength: 1,\n})\n\nexport class XrpcError<N extends XrpcErrorCode = XrpcErrorCode> extends Error {\n name = 'XrpcError'\n\n constructor(\n readonly error: N,\n message: string = `An ${error} XRPC error occurred.`,\n options?: ErrorOptions,\n ) {\n super(message, options)\n }\n}\n\nexport type XrpcErrorBody<N extends XrpcErrorCode = XrpcErrorCode> = {\n error: N\n message?: string\n}\nexport type XrpcErrorPayload<N extends XrpcErrorCode = XrpcErrorCode> = {\n encoding: 'application/json'\n body: XrpcErrorBody<N>\n}\n\nconst xrpcErrorBodySchema: l.Schema<XrpcErrorBody> = l.object({\n error: xrpcErrorCodeSchema,\n message: l.optional(l.string()),\n})\n\n/**\n * All unsuccessful responses should follow a standard error response\n * schema. The Content-Type should be application/json, and the payload\n * should be a JSON object with the following fields:\n *\n * - `error` (string, required): type name of the error (generic ASCII\n * constant, no whitespace)\n * - `message` (string, optional): description of the error, appropriate for\n * display to humans\n *\n * This function checks whether a given payload matches this schema.\n */\nexport function isXrpcErrorPayload(\n payload: Payload | null,\n): payload is XrpcErrorPayload {\n return (\n payload !== null &&\n payload.encoding === 'application/json' &&\n xrpcErrorBodySchema.matches(payload.body)\n )\n}\n\n/**\n * Interface representing a failed XRPC request result.\n */\ntype XrpcFailureResult<N extends XrpcErrorCode, E> = l.ResultFailure<E> & {\n readonly error: N\n shouldRetry(): boolean\n matchesSchema(): boolean\n}\n\n/**\n * Class used to represent an HTTP request that resulted in an XRPC method error\n * That is, a non-2xx response with a valid XRPC error payload.\n */\nexport class XrpcResponseError<\n M extends l.Procedure | l.Query = l.Procedure | l.Query,\n N extends XrpcErrorCode = XrpcErrorCode,\n >\n extends XrpcError<N>\n implements XrpcFailureResult<N, XrpcResponseError<M, N>>\n{\n name = 'XrpcResponseError' as const\n\n constructor(\n readonly method: M,\n readonly status: number,\n readonly headers: Headers,\n readonly payload: XrpcErrorPayload<N>,\n options?: ErrorOptions,\n ) {\n const { error, message } = payload.body\n super(error, message, options)\n }\n\n readonly success = false\n\n get reason(): this {\n return this as this\n }\n\n get body(): XrpcErrorBody {\n return this.payload.body\n }\n\n matchesSchema(): this is M extends {\n errors: readonly (infer E extends string)[]\n }\n ? XrpcResponseError<M, E>\n : never {\n return this.method.errors?.includes(this.error) ?? false\n }\n\n shouldRetry(): boolean {\n // Do not retry client errors\n if (this.status < 500) return false\n\n return true\n }\n}\n\n/**\n * This class represents an invalid XRPC response from the server.\n */\nexport class XrpcInvalidResponseError\n extends XrpcError<'UpstreamFailure'>\n implements XrpcFailureResult<'UpstreamFailure', XrpcInvalidResponseError>\n{\n name = 'XrpcInvalidResponseError' as const\n\n // For debugging purposes, we keep the response details here\n readonly response: {\n status: number\n headers: Headers\n payload: Payload | null\n }\n\n constructor(\n message: string,\n response: { status: number; headers: Headers },\n payload: Payload | null,\n options?: ErrorOptions,\n ) {\n super('UpstreamFailure', message, { cause: options?.cause })\n this.response = {\n status: response.status,\n headers: response.headers,\n payload,\n }\n }\n\n readonly success = false as const\n\n get reason(): this {\n return this\n }\n\n matchesSchema(): false {\n return false\n }\n\n shouldRetry(): boolean {\n // Do not retry client errors\n return this.response.status >= 500\n }\n}\n\nexport class XrpcUnexpectedError\n extends XrpcError<'InternalServerError'>\n implements XrpcFailureResult<'InternalServerError', unknown>\n{\n name = 'XrpcUnexpectedError' as const\n\n protected constructor(message: string, options: Required<ErrorOptions>) {\n super('InternalServerError', message, options)\n }\n\n readonly success = false\n\n get reason() {\n return this.cause\n }\n\n matchesSchema(): false {\n return false\n }\n\n shouldRetry(): boolean {\n return true\n }\n\n static from(\n cause: unknown,\n message: string = cause instanceof XrpcError\n ? cause.message\n : 'XRPC request failed',\n ): XrpcUnexpectedError {\n if (cause instanceof XrpcUnexpectedError) return cause\n return new XrpcUnexpectedError(message, { cause })\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InferMethodOutputBody, InferMethodOutputEncoding, Procedure, Query, ResultSuccess } from '@atproto/lex-schema';
|
|
2
|
+
import { Payload } from './util.js';
|
|
3
|
+
export type XrpcResponseBody<M extends Procedure | Query> = InferMethodOutputBody<M, Uint8Array>;
|
|
4
|
+
export type XrpcResponsePayload<M extends Procedure | Query> = InferMethodOutputEncoding<M> extends infer E extends string ? Payload<XrpcResponseBody<M>, E> : null;
|
|
5
|
+
/**
|
|
6
|
+
* Small container for XRPC response data.
|
|
7
|
+
*
|
|
8
|
+
* @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.
|
|
9
|
+
*/
|
|
10
|
+
export declare class XrpcResponse<const M extends Procedure | Query> implements ResultSuccess<XrpcResponse<M>> {
|
|
11
|
+
readonly method: M;
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly headers: Headers;
|
|
14
|
+
readonly payload: XrpcResponsePayload<M>;
|
|
15
|
+
/** @see {@link ResultSuccess.success} */
|
|
16
|
+
readonly success: true;
|
|
17
|
+
/** @see {@link ResultSuccess.value} */
|
|
18
|
+
get value(): this;
|
|
19
|
+
constructor(method: M, status: number, headers: Headers, payload: XrpcResponsePayload<M>);
|
|
20
|
+
/**
|
|
21
|
+
* Whether the response payload was parsed as {@link LexValue} (`true`) or is
|
|
22
|
+
* in binary form {@link Uint8Array} (`false`).
|
|
23
|
+
*/
|
|
24
|
+
get isParsed(): boolean;
|
|
25
|
+
get encoding(): InferMethodOutputEncoding<M>;
|
|
26
|
+
get body(): XrpcResponseBody<M>;
|
|
27
|
+
/**
|
|
28
|
+
* @throws {XrpcInvalidResponseError} when the response is invalid according
|
|
29
|
+
* to the method schema.
|
|
30
|
+
*/
|
|
31
|
+
static fromFetchResponse<const M extends Procedure | Query>(method: M, response: Response, options?: {
|
|
32
|
+
validateResponse?: boolean;
|
|
33
|
+
}): Promise<XrpcResponse<M>>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=xrpc-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xrpc-response.d.ts","sourceRoot":"","sources":["../src/xrpc-response.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,SAAS,EACT,KAAK,EACL,aAAa,EACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAOnC,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,IACtD,qBAAqB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;AAEtC,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,IACzD,yBAAyB,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GACvD,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAC/B,IAAI,CAAA;AAEV;;;;GAIG;AACH,qBAAa,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,KAAK,CACzD,YAAW,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAWvC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO;IACzB,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAZ1C,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAG,IAAI,CAAS;IAEhC,uCAAuC;IACvC,IAAI,KAAK,IAAI,IAAI,CAEhB;gBAGU,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,EACh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