@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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @atproto/lex-client
|
|
2
2
|
|
|
3
|
+
## 0.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Complete rework of the error mechanics
|
|
8
|
+
|
|
9
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add support for `uploadBlob` and `getBlob` methods
|
|
10
|
+
|
|
11
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Validate records when `validateRequest` is set when calling `create` and `put` methods.
|
|
12
|
+
|
|
13
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Export `FetchHandler` as a distinct type
|
|
14
|
+
|
|
15
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - No longer validate records when `validate` option is set in `create()` method. Use `validateRequest` option for that purpose.
|
|
16
|
+
|
|
17
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `XrpcFailure` error name field to `error` for consistency with XRPC error payloads
|
|
18
|
+
|
|
19
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Allow specifying request content-type through the `encoding` option
|
|
20
|
+
|
|
21
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve handling of binary payloads
|
|
22
|
+
|
|
23
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `createRecordsSafe`, `deleteRecordsSafe`, `getRecordsSafe` and `putRecordsSafe` methods
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece)]:
|
|
26
|
+
- @atproto/lex-data@0.0.4
|
|
27
|
+
- @atproto/lex-schema@0.0.5
|
|
28
|
+
- @atproto/lex-json@0.0.4
|
|
29
|
+
|
|
3
30
|
## 0.0.4
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { DidString } from '@atproto/lex-schema';
|
|
2
|
+
export type FetchHandler = (
|
|
3
|
+
/**
|
|
4
|
+
* The URL (pathname + query parameters) to make the request to, without the
|
|
5
|
+
* origin. The origin (protocol, hostname, and port) must be added by this
|
|
6
|
+
* {@link FetchHandler}, typically based on authentication or other factors.
|
|
7
|
+
*/
|
|
8
|
+
path: string, init: RequestInit) => Promise<Response>;
|
|
2
9
|
export interface Agent {
|
|
3
|
-
did?: DidString;
|
|
4
|
-
fetchHandler:
|
|
5
|
-
/**
|
|
6
|
-
* The URL (pathname + query parameters) to make the request to, without the
|
|
7
|
-
* origin. The origin (protocol, hostname, and port) must be added by this
|
|
8
|
-
* {@link FetchHandler}, typically based on authentication or other factors.
|
|
9
|
-
*/
|
|
10
|
-
path: string, init: RequestInit) => Promise<Response>;
|
|
10
|
+
readonly did?: DidString;
|
|
11
|
+
fetchHandler: FetchHandler;
|
|
11
12
|
}
|
|
12
13
|
export type AgentConfig = {
|
|
13
14
|
/**
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE/C,MAAM,MAAM,YAAY,GAAG;AACzB;;;;GAIG;AACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEtB,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,GAAG,CAAC,EAAE,SAAS,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,GAAG,CAAC,EAAE,SAAS,CAAA;IAEf;;;;OAIG;IACH,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;IAErB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,MAAM,GAAG,GAAG,CAAA;AAErD,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,KAAK,CAqBvD"}
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;AAyCA,gCAqBC;AArBD,SAAgB,UAAU,CAAC,OAAqB;IAC9C,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,GAAG;QACnD,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;QACtC,CAAC,CAAC,OAAO,CAAA;IAEb,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,MAAM,CAAA;IAEpD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAA;IACrE,CAAC;IAED,OAAO;QACL,IAAI,GAAG;YACL,OAAO,MAAM,CAAC,GAAG,CAAA;QACnB,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI;YAC3B,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;QAC5C,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { DidString } from '@atproto/lex-schema'\n\nexport
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;AAyCA,gCAqBC;AArBD,SAAgB,UAAU,CAAC,OAAqB;IAC9C,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,GAAG;QACnD,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE;QACtC,CAAC,CAAC,OAAO,CAAA;IAEb,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,GAAG,MAAM,CAAA;IAEpD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAA;IACrE,CAAC;IAED,OAAO;QACL,IAAI,GAAG;YACL,OAAO,MAAM,CAAC,GAAG,CAAA;QACnB,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI;YAC3B,OAAO,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;QAC5C,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { DidString } from '@atproto/lex-schema'\n\nexport type FetchHandler = (\n /**\n * The URL (pathname + query parameters) to make the request to, without the\n * origin. The origin (protocol, hostname, and port) must be added by this\n * {@link FetchHandler}, typically based on authentication or other factors.\n */\n path: string,\n init: RequestInit,\n) => Promise<Response>\n\nexport interface Agent {\n readonly did?: DidString\n fetchHandler: FetchHandler\n}\n\nexport type AgentConfig = {\n /**\n * The identifier (DID) of the user represented by this agent.\n */\n did?: DidString\n\n /**\n * The service URL to make requests to. This can be a string, URL, or a\n * function that returns a string or URL. This is useful for dynamic URLs,\n * such as a service URL that changes based on authentication.\n */\n service: string | URL\n\n /**\n * Bring your own fetch implementation. Typically useful for testing, logging,\n * mocking, or adding retries, session management, signatures, proof of\n * possession (DPoP), SSRF protection, etc. Defaults to the global `fetch`\n * function.\n */\n fetch?: typeof globalThis.fetch\n}\n\nexport type AgentOptions = AgentConfig | string | URL\n\nexport function buildAgent(options: AgentOptions): Agent {\n const config: AgentConfig =\n typeof options === 'string' || options instanceof URL\n ? { did: undefined, service: options }\n : options\n\n const { service, fetch = globalThis.fetch } = config\n\n if (typeof fetch !== 'function') {\n throw new TypeError('fetch() is not available in this environment')\n }\n\n return {\n get did() {\n return config.did\n },\n\n async fetchHandler(path, init) {\n return fetch(new URL(path, service), init)\n },\n }\n}\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { LexMap } from '@atproto/lex-data';
|
|
2
|
-
import { AtIdentifierString, DidString, Infer,
|
|
2
|
+
import { AtIdentifierString, CidString, DidString, Infer, InferMethodInputBody, InferMethodOutputBody, InferMethodParams, InferRecordKey, LexiconRecordKey, NsidString, Procedure, Query, RecordSchema, Restricted } from '@atproto/lex-schema';
|
|
3
3
|
import { Agent, AgentOptions } from './agent.js';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { XrpcResponse, XrpcResponseBody } from './
|
|
7
|
-
import { CallOptions, Namespace, Service } from './types.js';
|
|
8
|
-
import { XrpcOptions } from './xrpc.js';
|
|
4
|
+
import { com } from './lexicons.js';
|
|
5
|
+
import { BinaryBodyInit, CallOptions, Namespace, Service } from './types.js';
|
|
6
|
+
import { XrpcFailure, XrpcOptions, XrpcResponse, XrpcResponseBody } from './xrpc.js';
|
|
9
7
|
export type ClientOptions = {
|
|
10
8
|
labelers?: Iterable<DidString>;
|
|
11
9
|
headers?: HeadersInit;
|
|
@@ -45,17 +43,17 @@ export type RecordKeyOptions<T extends RecordSchema, AlsoOptionalWhenRecordKeyIs
|
|
|
45
43
|
rkey: InferRecordKey<T>;
|
|
46
44
|
};
|
|
47
45
|
export type CreateOptions<T extends RecordSchema> = CreateRecordOptions & RecordKeyOptions<T, 'tid'>;
|
|
48
|
-
export type CreateOutput =
|
|
46
|
+
export type CreateOutput = InferMethodOutputBody<typeof com.atproto.repo.createRecord.main, Uint8Array>;
|
|
49
47
|
export type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions & RecordKeyOptions<T>;
|
|
50
|
-
export type DeleteOutput =
|
|
48
|
+
export type DeleteOutput = InferMethodOutputBody<typeof com.atproto.repo.deleteRecord.main, Uint8Array>;
|
|
51
49
|
export type GetOptions<T extends RecordSchema> = GetRecordOptions & RecordKeyOptions<T>;
|
|
52
|
-
export type GetOutput<T extends RecordSchema> = Omit<
|
|
50
|
+
export type GetOutput<T extends RecordSchema> = Omit<InferMethodOutputBody<typeof com.atproto.repo.getRecord.main, Uint8Array>, 'value'> & {
|
|
53
51
|
value: Infer<T>;
|
|
54
52
|
};
|
|
55
53
|
export type PutOptions<T extends RecordSchema> = PutRecordOptions & RecordKeyOptions<T>;
|
|
56
|
-
export type PutOutput =
|
|
54
|
+
export type PutOutput = InferMethodOutputBody<typeof com.atproto.repo.putRecord.main, Uint8Array>;
|
|
57
55
|
export type ListOptions = ListRecordsOptions;
|
|
58
|
-
export type ListOutput<T extends RecordSchema> =
|
|
56
|
+
export type ListOutput<T extends RecordSchema> = InferMethodOutputBody<typeof com.atproto.repo.listRecords.main, Uint8Array> & {
|
|
59
57
|
records: ListRecord<T>[];
|
|
60
58
|
invalid: LexMap[];
|
|
61
59
|
};
|
|
@@ -84,10 +82,13 @@ export declare class Client implements Agent {
|
|
|
84
82
|
addLabelers(labelers: Iterable<DidString>): void;
|
|
85
83
|
clearLabelers(): void;
|
|
86
84
|
fetchHandler(path: string, init: RequestInit): Promise<Response>;
|
|
85
|
+
/**
|
|
86
|
+
* @throws {XrpcFailure<M>} when the request fails or the response is an error
|
|
87
|
+
*/
|
|
87
88
|
xrpc<const M extends Query | Procedure>(ns: NonNullable<unknown> extends XrpcOptions<M> ? Namespace<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M>>;
|
|
88
89
|
xrpc<const M extends Query | Procedure>(ns: Namespace<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M>>;
|
|
89
|
-
xrpcSafe<const M extends Query | Procedure>(ns: NonNullable<unknown> extends XrpcOptions<M> ? Namespace<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M> |
|
|
90
|
-
xrpcSafe<const M extends Query | Procedure>(ns: Namespace<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M> |
|
|
90
|
+
xrpcSafe<const M extends Query | Procedure>(ns: NonNullable<unknown> extends XrpcOptions<M> ? Namespace<M> : Restricted<'This XRPC method requires an "options" argument'>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
|
|
91
|
+
xrpcSafe<const M extends Query | Procedure>(ns: Namespace<M>, options: XrpcOptions<M>): Promise<XrpcResponse<M> | XrpcFailure<M>>;
|
|
91
92
|
/**
|
|
92
93
|
* @param rkey Leave `undefined` to have the server generate a TID.
|
|
93
94
|
*/
|
|
@@ -114,27 +115,6 @@ export declare class Client implements Agent {
|
|
|
114
115
|
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
115
116
|
readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
116
117
|
}>>, readonly ["InvalidSwap"]>>>;
|
|
117
|
-
createRecordsSafe(...args: Parameters<Client['createRecord']>): Promise<import("./error.js").XrpcFailure<"Unknown", import("./error.js").XrpcResponseError<string, import("./error.js").XrpcErrorBody<string>>> | import("./error.js").XrpcFailure<"UnexpectedError", unknown> | XrpcResponse<Procedure<"com.atproto.repo.createRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
118
|
-
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
119
|
-
readonly format: "at-identifier";
|
|
120
|
-
}>;
|
|
121
|
-
readonly collection: import("@atproto/lex-schema").StringSchema<{
|
|
122
|
-
readonly format: "nsid";
|
|
123
|
-
}>;
|
|
124
|
-
readonly rkey: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
125
|
-
readonly validate: import("@atproto/lex-schema").OptionalSchema<boolean>;
|
|
126
|
-
readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
|
|
127
|
-
readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
128
|
-
}>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
129
|
-
readonly uri: import("@atproto/lex-schema").StringSchema<{
|
|
130
|
-
readonly format: "at-uri";
|
|
131
|
-
}>;
|
|
132
|
-
readonly cid: import("@atproto/lex-schema").StringSchema<{
|
|
133
|
-
readonly format: "cid";
|
|
134
|
-
}>;
|
|
135
|
-
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
136
|
-
readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
137
|
-
}>>, readonly ["InvalidSwap"]>> | import("./error.js").XrpcResponseError<"InvalidSwap", import("./error.js").XrpcErrorBody<"InvalidSwap">>>;
|
|
138
118
|
deleteRecord(collection: NsidString, rkey: string, options?: DeleteRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.deleteRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
139
119
|
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
140
120
|
readonly format: "at-identifier";
|
|
@@ -150,21 +130,6 @@ export declare class Client implements Agent {
|
|
|
150
130
|
}>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
151
131
|
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
152
132
|
}>>, readonly ["InvalidSwap"]>>>;
|
|
153
|
-
deleteRecordsSafe(...args: Parameters<Client['deleteRecord']>): Promise<import("./error.js").XrpcFailure<"Unknown", import("./error.js").XrpcResponseError<string, import("./error.js").XrpcErrorBody<string>>> | import("./error.js").XrpcFailure<"UnexpectedError", unknown> | import("./error.js").XrpcResponseError<"InvalidSwap", import("./error.js").XrpcErrorBody<"InvalidSwap">> | XrpcResponse<Procedure<"com.atproto.repo.deleteRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
154
|
-
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
155
|
-
readonly format: "at-identifier";
|
|
156
|
-
}>;
|
|
157
|
-
readonly collection: import("@atproto/lex-schema").StringSchema<{
|
|
158
|
-
readonly format: "nsid";
|
|
159
|
-
}>;
|
|
160
|
-
readonly rkey: import("@atproto/lex-schema").StringSchema<{
|
|
161
|
-
readonly format: "record-key";
|
|
162
|
-
}>;
|
|
163
|
-
readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
164
|
-
readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
165
|
-
}>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
166
|
-
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
167
|
-
}>>, readonly ["InvalidSwap"]>>>;
|
|
168
133
|
getRecord(collection: NsidString, rkey: string, options?: GetRecordOptions): Promise<XrpcResponse<Query<"com.atproto.repo.getRecord", import("@atproto/lex-schema").ParamsSchema<{
|
|
169
134
|
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
170
135
|
readonly format: "at-identifier";
|
|
@@ -183,24 +148,6 @@ export declare class Client implements Agent {
|
|
|
183
148
|
readonly cid: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
184
149
|
readonly value: import("@atproto/lex-schema").UnknownObjectSchema;
|
|
185
150
|
}>>, readonly ["RecordNotFound"]>>>;
|
|
186
|
-
getRecordsSafe(...args: Parameters<Client['getRecord']>): Promise<import("./error.js").XrpcFailure<"Unknown", import("./error.js").XrpcResponseError<string, import("./error.js").XrpcErrorBody<string>>> | import("./error.js").XrpcFailure<"UnexpectedError", unknown> | XrpcResponse<Query<"com.atproto.repo.getRecord", import("@atproto/lex-schema").ParamsSchema<{
|
|
187
|
-
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
188
|
-
readonly format: "at-identifier";
|
|
189
|
-
}>;
|
|
190
|
-
readonly collection: import("@atproto/lex-schema").StringSchema<{
|
|
191
|
-
readonly format: "nsid";
|
|
192
|
-
}>;
|
|
193
|
-
readonly rkey: import("@atproto/lex-schema").StringSchema<{
|
|
194
|
-
readonly format: "record-key";
|
|
195
|
-
}>;
|
|
196
|
-
readonly cid: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
197
|
-
}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
198
|
-
readonly uri: import("@atproto/lex-schema").StringSchema<{
|
|
199
|
-
readonly format: "at-uri";
|
|
200
|
-
}>;
|
|
201
|
-
readonly cid: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
202
|
-
readonly value: import("@atproto/lex-schema").UnknownObjectSchema;
|
|
203
|
-
}>>, readonly ["RecordNotFound"]>> | import("./error.js").XrpcResponseError<"RecordNotFound", import("./error.js").XrpcErrorBody<"RecordNotFound">>>;
|
|
204
151
|
putRecord(record: {
|
|
205
152
|
$type: NsidString;
|
|
206
153
|
} & LexMap, rkey: string, options?: PutRecordOptions): Promise<XrpcResponse<Procedure<"com.atproto.repo.putRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
@@ -228,31 +175,6 @@ export declare class Client implements Agent {
|
|
|
228
175
|
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
229
176
|
readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
230
177
|
}>>, readonly ["InvalidSwap"]>>>;
|
|
231
|
-
putRecordsSafe(...args: Parameters<Client['putRecord']>): Promise<import("./error.js").XrpcFailure<"Unknown", import("./error.js").XrpcResponseError<string, import("./error.js").XrpcErrorBody<string>>> | import("./error.js").XrpcFailure<"UnexpectedError", unknown> | import("./error.js").XrpcResponseError<"InvalidSwap", import("./error.js").XrpcErrorBody<"InvalidSwap">> | XrpcResponse<Procedure<"com.atproto.repo.putRecord", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
232
|
-
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
233
|
-
readonly format: "at-identifier";
|
|
234
|
-
}>;
|
|
235
|
-
readonly collection: import("@atproto/lex-schema").StringSchema<{
|
|
236
|
-
readonly format: "nsid";
|
|
237
|
-
}>;
|
|
238
|
-
readonly rkey: import("@atproto/lex-schema").StringSchema<{
|
|
239
|
-
readonly format: "record-key";
|
|
240
|
-
readonly maxLength: 512;
|
|
241
|
-
}>;
|
|
242
|
-
readonly validate: import("@atproto/lex-schema").OptionalSchema<boolean>;
|
|
243
|
-
readonly record: import("@atproto/lex-schema").UnknownObjectSchema;
|
|
244
|
-
readonly swapRecord: import("@atproto/lex-schema").OptionalSchema<string | null>;
|
|
245
|
-
readonly swapCommit: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
246
|
-
}>>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
247
|
-
readonly uri: import("@atproto/lex-schema").StringSchema<{
|
|
248
|
-
readonly format: "at-uri";
|
|
249
|
-
}>;
|
|
250
|
-
readonly cid: import("@atproto/lex-schema").StringSchema<{
|
|
251
|
-
readonly format: "cid";
|
|
252
|
-
}>;
|
|
253
|
-
readonly commit: import("@atproto/lex-schema").OptionalSchema<com.atproto.repo.defs.$defs.CommitMeta>;
|
|
254
|
-
readonly validationStatus: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
255
|
-
}>>, readonly ["InvalidSwap"]>>>;
|
|
256
178
|
listRecords(nsid: NsidString, options?: ListRecordsOptions): Promise<XrpcResponse<Query<"com.atproto.repo.listRecords", import("@atproto/lex-schema").ParamsSchema<{
|
|
257
179
|
readonly repo: import("@atproto/lex-schema").StringSchema<{
|
|
258
180
|
readonly format: "at-identifier";
|
|
@@ -267,10 +189,24 @@ export declare class Client implements Agent {
|
|
|
267
189
|
readonly cursor: import("@atproto/lex-schema").OptionalSchema<string>;
|
|
268
190
|
readonly records: import("@atproto/lex-schema").ArraySchema<import("@atproto/lex-schema").RefSchema<com.atproto.repo.listRecords.$defs.DefRecord>>;
|
|
269
191
|
}>>, undefined>>>;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
192
|
+
uploadBlob(body: BinaryBodyInit, options?: CallOptions & {
|
|
193
|
+
encoding?: `${string}/${string}`;
|
|
194
|
+
}): Promise<XrpcResponse<Procedure<"com.atproto.repo.uploadBlob", import("@atproto/lex-schema").ParamsSchema<{}>, import("@atproto/lex-schema").Payload<"*/*", undefined>, import("@atproto/lex-schema").Payload<"application/json", import("@atproto/lex-schema").ObjectSchema<{
|
|
195
|
+
readonly blob: import("@atproto/lex-schema").BlobSchema<{
|
|
196
|
+
allowLegacy: false;
|
|
197
|
+
}>;
|
|
198
|
+
}>>, undefined>>>;
|
|
199
|
+
getBlob(did: DidString, cid: CidString, options?: CallOptions): Promise<XrpcResponse<Query<"com.atproto.sync.getBlob", import("@atproto/lex-schema").ParamsSchema<{
|
|
200
|
+
readonly did: import("@atproto/lex-schema").StringSchema<{
|
|
201
|
+
readonly format: "did";
|
|
202
|
+
}>;
|
|
203
|
+
readonly cid: import("@atproto/lex-schema").StringSchema<{
|
|
204
|
+
readonly format: "cid";
|
|
205
|
+
}>;
|
|
206
|
+
}>, import("@atproto/lex-schema").Payload<"*/*", undefined>, readonly ["BlobNotFound", "RepoNotFound", "RepoTakendown", "RepoSuspended", "RepoDeactivated"]>>>;
|
|
207
|
+
call<const T extends Query>(ns: NonNullable<unknown> extends InferMethodParams<T> ? Namespace<T> : Restricted<'This query type requires a "params" argument'>): Promise<XrpcResponseBody<T>>;
|
|
208
|
+
call<const T extends Action>(ns: void extends InferActionInput<T> ? Namespace<T> : Restricted<'This action type requires an "input" argument'>): Promise<InferActionOutput<T>>;
|
|
209
|
+
call<const T extends Action | Procedure | Query>(ns: Namespace<T>, arg: T extends Action ? InferActionInput<T> : T extends Procedure ? InferMethodInputBody<T, Uint8Array> : T extends Query ? InferMethodParams<T> : never, options?: CallOptions): Promise<T extends Action ? InferActionOutput<T> : T extends Procedure ? XrpcResponseBody<T> : T extends Query ? XrpcResponseBody<T> : never>;
|
|
274
210
|
create<const T extends RecordSchema>(ns: NonNullable<unknown> extends CreateOptions<T> ? Namespace<T> : Restricted<'This record type requires an "options" argument'>, input: Omit<Infer<T>, '$type'>): Promise<CreateOutput>;
|
|
275
211
|
create<const T extends RecordSchema>(ns: Namespace<T>, input: Omit<Infer<T>, '$type'>, options: CreateOptions<T>): Promise<CreateOutput>;
|
|
276
212
|
delete<const T extends RecordSchema>(ns: NonNullable<unknown> extends DeleteOptions<T> ? Namespace<T> : Restricted<'This record type requires an "options" argument'>): Promise<DeleteOutput>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,mBAAmB,CAAA;AACpD,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,KAAK,EACL,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,mBAAmB,CAAA;AACpD,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,KAAK,EACL,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,UAAU,EAEV,SAAS,EACT,KAAK,EACL,YAAY,EACZ,UAAU,EAEX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,YAAY,EAAc,MAAM,YAAY,CAAA;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,EACL,cAAc,EACd,WAAW,EACX,SAAS,EACT,OAAO,EAER,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,WAAW,EACX,WAAW,EACX,YAAY,EACZ,gBAAgB,EAGjB,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;IAC9B,OAAO,CAAC,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CACrC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,WAAW,KACjB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC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AAC,CAAC,CAAC,CAAC;CAkB1B"}
|
package/dist/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Client = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const lex_schema_1 = require("@atproto/lex-schema");
|
|
6
5
|
const agent_js_1 = require("./agent.js");
|
|
7
|
-
const
|
|
8
|
-
const com = tslib_1.__importStar(require("./lexicons/com.js"));
|
|
6
|
+
const lexicons_js_1 = require("./lexicons.js");
|
|
9
7
|
const types_js_1 = require("./types.js");
|
|
8
|
+
const util_js_1 = require("./util.js");
|
|
9
|
+
const xrpc_error_js_1 = require("./xrpc-error.js");
|
|
10
10
|
const xrpc_js_1 = require("./xrpc.js");
|
|
11
11
|
class Client {
|
|
12
12
|
static appLabelers = [];
|
|
@@ -39,7 +39,7 @@ class Client {
|
|
|
39
39
|
}
|
|
40
40
|
assertAuthenticated() {
|
|
41
41
|
if (!this.did)
|
|
42
|
-
throw new
|
|
42
|
+
throw new xrpc_error_js_1.XrpcError('AuthenticationRequired');
|
|
43
43
|
}
|
|
44
44
|
setLabelers(labelers = []) {
|
|
45
45
|
this.clearLabelers();
|
|
@@ -53,7 +53,7 @@ class Client {
|
|
|
53
53
|
this.labelers.clear();
|
|
54
54
|
}
|
|
55
55
|
fetchHandler(path, init) {
|
|
56
|
-
const headers = (0,
|
|
56
|
+
const headers = (0, util_js_1.buildAtprotoHeaders)({
|
|
57
57
|
headers: init.headers,
|
|
58
58
|
service: this.service,
|
|
59
59
|
labelers: [
|
|
@@ -66,20 +66,20 @@ class Client {
|
|
|
66
66
|
if (!headers.has(key))
|
|
67
67
|
headers.set(key, value);
|
|
68
68
|
}
|
|
69
|
+
// @NOTE The agent here could be another Client instance.
|
|
69
70
|
return this.agent.fetchHandler(path, { ...init, headers });
|
|
70
71
|
}
|
|
71
72
|
async xrpc(ns, options = {}) {
|
|
72
73
|
return (0, xrpc_js_1.xrpc)(this, ns, options);
|
|
73
74
|
}
|
|
74
75
|
async xrpcSafe(ns, options = {}) {
|
|
75
|
-
|
|
76
|
-
return this.xrpc(schema, options).catch((0, error_js_1.asXrpcRequestFailureFor)(schema));
|
|
76
|
+
return (0, xrpc_js_1.xrpcSafe)(this, ns, options);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* @param rkey Leave `undefined` to have the server generate a TID.
|
|
80
80
|
*/
|
|
81
81
|
async createRecord(record, rkey, options) {
|
|
82
|
-
return this.xrpc(com.atproto.repo.createRecord.main, {
|
|
82
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.createRecord.main, {
|
|
83
83
|
...options,
|
|
84
84
|
body: {
|
|
85
85
|
repo: options?.repo ?? this.assertDid,
|
|
@@ -91,11 +91,8 @@ class Client {
|
|
|
91
91
|
},
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
|
-
async createRecordsSafe(...args) {
|
|
95
|
-
return this.createRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.createRecord.main));
|
|
96
|
-
}
|
|
97
94
|
async deleteRecord(collection, rkey, options) {
|
|
98
|
-
return this.xrpc(com.atproto.repo.deleteRecord.main, {
|
|
95
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.deleteRecord.main, {
|
|
99
96
|
...options,
|
|
100
97
|
body: {
|
|
101
98
|
repo: options?.repo ?? this.assertDid,
|
|
@@ -106,11 +103,8 @@ class Client {
|
|
|
106
103
|
},
|
|
107
104
|
});
|
|
108
105
|
}
|
|
109
|
-
async deleteRecordsSafe(...args) {
|
|
110
|
-
return this.deleteRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.deleteRecord.main));
|
|
111
|
-
}
|
|
112
106
|
async getRecord(collection, rkey, options) {
|
|
113
|
-
return this.xrpc(com.atproto.repo.getRecord.main, {
|
|
107
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.getRecord.main, {
|
|
114
108
|
...options,
|
|
115
109
|
params: {
|
|
116
110
|
repo: options?.repo ?? this.assertDid,
|
|
@@ -119,11 +113,8 @@ class Client {
|
|
|
119
113
|
},
|
|
120
114
|
});
|
|
121
115
|
}
|
|
122
|
-
async getRecordsSafe(...args) {
|
|
123
|
-
return this.getRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.getRecord.main));
|
|
124
|
-
}
|
|
125
116
|
async putRecord(record, rkey, options) {
|
|
126
|
-
return this.xrpc(com.atproto.repo.putRecord.main, {
|
|
117
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.putRecord.main, {
|
|
127
118
|
...options,
|
|
128
119
|
body: {
|
|
129
120
|
repo: options?.repo ?? this.assertDid,
|
|
@@ -136,11 +127,8 @@ class Client {
|
|
|
136
127
|
},
|
|
137
128
|
});
|
|
138
129
|
}
|
|
139
|
-
async putRecordsSafe(...args) {
|
|
140
|
-
return this.putRecord(...args).catch((0, error_js_1.asXrpcRequestFailureFor)(com.atproto.repo.putRecord.main));
|
|
141
|
-
}
|
|
142
130
|
async listRecords(nsid, options) {
|
|
143
|
-
return this.xrpc(com.atproto.repo.listRecords.main, {
|
|
131
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.listRecords.main, {
|
|
144
132
|
...options,
|
|
145
133
|
params: {
|
|
146
134
|
repo: options?.repo ?? this.assertDid,
|
|
@@ -151,19 +139,29 @@ class Client {
|
|
|
151
139
|
},
|
|
152
140
|
});
|
|
153
141
|
}
|
|
142
|
+
async uploadBlob(body, options) {
|
|
143
|
+
return this.xrpc(lexicons_js_1.com.atproto.repo.uploadBlob.main, {
|
|
144
|
+
...options,
|
|
145
|
+
body,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async getBlob(did, cid, options) {
|
|
149
|
+
return this.xrpc(lexicons_js_1.com.atproto.sync.getBlob.main, {
|
|
150
|
+
...options,
|
|
151
|
+
params: { did, cid },
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
154
|
async call(ns, arg, options = {}) {
|
|
155
155
|
const method = (0, types_js_1.getMain)(ns);
|
|
156
156
|
if (typeof method === 'function') {
|
|
157
157
|
return method(this, arg, options);
|
|
158
158
|
}
|
|
159
159
|
if (method instanceof lex_schema_1.Procedure) {
|
|
160
|
-
const
|
|
161
|
-
const result = await this.xrpc(method, { ...options, body });
|
|
160
|
+
const result = await this.xrpc(method, { ...options, body: arg });
|
|
162
161
|
return result.body;
|
|
163
162
|
}
|
|
164
163
|
else if (method instanceof lex_schema_1.Query) {
|
|
165
|
-
const
|
|
166
|
-
const result = await this.xrpc(method, { ...options, params });
|
|
164
|
+
const result = await this.xrpc(method, { ...options, params: arg });
|
|
167
165
|
return result.body;
|
|
168
166
|
}
|
|
169
167
|
else {
|
|
@@ -172,9 +170,9 @@ class Client {
|
|
|
172
170
|
}
|
|
173
171
|
async create(ns, input, options = {}) {
|
|
174
172
|
const schema = (0, types_js_1.getMain)(ns);
|
|
175
|
-
const record =
|
|
176
|
-
|
|
177
|
-
|
|
173
|
+
const record = schema.build(input);
|
|
174
|
+
if (options.validateRequest)
|
|
175
|
+
schema.assert(record);
|
|
178
176
|
const rkey = options.rkey ?? getDefaultRecordKey(schema);
|
|
179
177
|
if (rkey !== undefined)
|
|
180
178
|
schema.keySchema.assert(rkey);
|
|
@@ -197,6 +195,8 @@ class Client {
|
|
|
197
195
|
async put(ns, input, options = {}) {
|
|
198
196
|
const schema = (0, types_js_1.getMain)(ns);
|
|
199
197
|
const record = schema.build(input);
|
|
198
|
+
if (options.validateRequest)
|
|
199
|
+
schema.assert(record);
|
|
200
200
|
const rkey = options.rkey ?? getLiteralRecordKey(schema);
|
|
201
201
|
const response = await this.putRecord(record, rkey, options);
|
|
202
202
|
return response.body;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;AACA,oDAiB4B;AAC5B,yCAA4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AC;YAClC,MAAM,MAAM,GAAI,MAA2B,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACnE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;YAClD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;QAED,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IACtC,CAAC;;AAnXH,wBAoXC;AAED,SAAS,mBAAmB,CAC1B,MAAS;IAET,kCAAkC;IAClC,IAAI,MAAM,CAAC,GAAG,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IAC1C,IAAI,MAAM,CAAC,GAAG,KAAK,KAAK;QAAE,OAAO,SAAS,CAAA;IAE1C,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAA;AACpC,CAAC;AAED,SAAS,mBAAmB,CAC1B,MAAS;IAET,IAAI,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAED,MAAM,IAAI,SAAS,CACjB,mDAAmD,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,KAAK,GAAG,CACnF,CAAA;AACH,CAAC","sourcesContent":["import { LexMap, LexValue } from '@atproto/lex-data'\nimport {\n AtIdentifierString,\n DidString,\n Infer,\n InferProcedureInputBody,\n InferProcedureOutputBody,\n InferQueryOutputBody,\n InferQueryParameters,\n InferRecordKey,\n LexiconRecordKey,\n NsidString,\n Params,\n Procedure,\n Query,\n RecordSchema,\n Restricted,\n Schema,\n} from '@atproto/lex-schema'\nimport { Agent, AgentOptions, buildAgent } from './agent.js'\nimport {\n KnownError,\n XrpcError,\n XrpcRequestFailure,\n asXrpcRequestFailureFor,\n} from './error.js'\nimport * as com from './lexicons/com.js'\nimport { XrpcResponse, XrpcResponseBody } from './response.js'\nimport { CallOptions, Namespace, Service, getMain } from './types.js'\nimport { XrpcOptions, xrpc, xrpcRequestHeaders } from './xrpc.js'\n\nexport type ClientOptions = {\n labelers?: Iterable<DidString>\n headers?: HeadersInit\n service?: Service\n}\n\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: CallOptions,\n) => O | Promise<O>\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\nexport type CreateRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n validate?: boolean\n}\n\nexport type DeleteRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n swapRecord?: string\n}\n\nexport type GetRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n}\n\nexport type PutRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n swapRecord?: string\n validate?: boolean\n}\n\nexport type ListRecordsOptions = CallOptions & {\n repo?: AtIdentifierString\n limit?: number\n cursor?: string\n reverse?: boolean\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid'>\nexport type CreateOutput = XrpcResponseBody<\n typeof com.atproto.repo.createRecord.main\n>\n\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\nexport type DeleteOutput = XrpcResponseBody<\n typeof com.atproto.repo.deleteRecord.main\n>\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\nexport type GetOutput<T extends RecordSchema> = Omit<\n XrpcResponseBody<typeof com.atproto.repo.getRecord.main>,\n 'value'\n> & { value: Infer<T> }\n\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\nexport type PutOutput = XrpcResponseBody<typeof com.atproto.repo.putRecord.main>\n\nexport type ListOptions = ListRecordsOptions\nexport type ListOutput<T extends RecordSchema> = XrpcResponseBody<\n typeof com.atproto.repo.listRecords.main\n> & {\n records: ListRecord<T>[]\n // @NOTE Because the schema uses \"type\": \"unknown\" instead of an open union,\n // we have to use LexMap instead of TypedObject here.\n invalid: LexMap[]\n}\nexport type ListRecord<T extends RecordSchema> =\n com.atproto.repo.listRecords.DefRecord & {\n value: Infer<T>\n }\n\nexport class Client implements Agent {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }) {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n public readonly agent: Agent\n public readonly headers: Headers\n public readonly service?: Service\n public readonly labelers: Set<DidString>\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent =\n typeof agent === 'object' && 'fetchHandler' in agent\n ? agent\n : buildAgent(agent)\n this.service = options.service\n this.labelers = new Set(options.labelers)\n this.headers = new Headers(options.headers)\n }\n\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new XrpcError(KnownError.AuthenticationRequired)\n }\n\n public setLabelers(labelers: Iterable<DidString> = []) {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n public addLabelers(labelers: Iterable<DidString>) {\n for (const labeler of labelers) this.labelers.add(labeler)\n }\n\n public clearLabelers() {\n this.labelers.clear()\n }\n\n public fetchHandler(path: string, init: RequestInit): Promise<Response> {\n const headers = xrpcRequestHeaders({\n headers: init.headers,\n service: this.service,\n labelers: [\n ...(this.constructor as typeof Client).appLabelers.map(\n (l) => `${l};redact` as const,\n ),\n ...this.labelers,\n ],\n })\n\n // Incoming headers take precedence\n for (const [key, value] of this.headers) {\n if (!headers.has(key)) headers.set(key, value)\n }\n\n return this.agent.fetchHandler(path, { ...init, headers })\n }\n\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this, ns, options)\n }\n\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcRequestFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<unknown> {\n const schema = getMain(ns)\n return this.xrpc(schema, options).catch(asXrpcRequestFailureFor(schema))\n }\n\n /**\n * @param rkey Leave `undefined` to have the server generate a TID.\n */\n public async createRecord(\n record: { $type: NsidString } & LexMap,\n rkey?: string,\n options?: CreateRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.createRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n async createRecordsSafe(...args: Parameters<Client['createRecord']>) {\n return this.createRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.createRecord.main),\n )\n }\n\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n options?: DeleteRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.deleteRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n async deleteRecordsSafe(...args: Parameters<Client['deleteRecord']>) {\n return this.deleteRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.deleteRecord.main),\n )\n }\n\n public async getRecord(\n collection: NsidString,\n rkey: string,\n options?: GetRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.getRecord.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n async getRecordsSafe(...args: Parameters<Client['getRecord']>) {\n return this.getRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.getRecord.main),\n )\n }\n\n async putRecord(\n record: { $type: NsidString } & LexMap,\n rkey: string,\n options?: PutRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.putRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n async putRecordsSafe(...args: Parameters<Client['putRecord']>) {\n return this.putRecord(...args).catch(\n asXrpcRequestFailureFor(com.atproto.repo.putRecord.main),\n )\n }\n\n async listRecords(nsid: NsidString, options?: ListRecordsOptions) {\n return this.xrpc(com.atproto.repo.listRecords.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n public async call<const T extends Action>(\n ns: Namespace<T>,\n input: InferActionInput<T>,\n options?: CallOptions,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Procedure>(\n ns: Namespace<T>,\n body: InferProcedureInputBody<T>,\n options?: CallOptions,\n ): Promise<InferProcedureOutputBody<T>>\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends InferQueryParameters<T>\n ? Namespace<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<InferQueryOutputBody<T>>\n public async call<const T extends Query>(\n ns: Namespace<T>,\n params: NonNullable<unknown> extends InferQueryParameters<T>\n ? InferQueryParameters<T> | undefined\n : InferQueryParameters<T>,\n options?: CallOptions,\n ): Promise<InferQueryOutputBody<T>>\n public async call(\n ns: Namespace<Action> | Namespace<Procedure> | Namespace<Query>,\n arg?: LexValue | Params,\n options: CallOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const body = arg as LexValue | undefined\n const result = await this.xrpc(method, { ...options, body })\n return result.body\n } else if (method instanceof Query) {\n const params = arg as Params | undefined\n const result = await this.xrpc(method, { ...options, params })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = options.validate\n ? schema.parse(schema.build(input))\n : schema.build(input)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.parse(response.body.value) as Infer<T>\n return { ...response.body, value }\n }\n\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema = getMain(ns)\n const record = schema.build(input)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n async list<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n\n const records: ListRecord<T>[] = []\n const invalid: LexMap[] = []\n\n for (const record of body.records) {\n const parsed = (schema as Schema<Infer<T>>).safeParse(record.value)\n if (parsed.success) {\n records.push({ ...record, value: parsed.value })\n } else {\n invalid.push(record.value)\n }\n }\n\n return { ...body, records, invalid }\n }\n}\n\nfunction getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nfunction getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8)\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,oDAiB4B;AAC5B,yCAA4D;AAC5D,+CAAmC;AACnC,yCAMmB;AACnB,uCAA+C;AAC/C,mDAA2C;AAC3C,uCAOkB;AAiGlB,MAAa,MAAM;IACjB,MAAM,CAAC,WAAW,GAAyB,EAAE,CAAA;IAE7C;;OAEG;IACH,MAAM,CAAC,SAAS,CAAC,IAA2C;QAC1D,IAAI,IAAI,CAAC,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,CAAA;IAChE,CAAC;IAEe,KAAK,CAAO;IACZ,OAAO,CAAS;IAChB,OAAO,CAAU;IACjB,QAAQ,CAAgB;IAExC,YAAY,KAA2B,EAAE,UAAyB,EAAE;QAClE,IAAI,CAAC,KAAK;YACR,OAAO,KAAK,KAAK,QA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\nimport {\n AtIdentifierString,\n CidString,\n DidString,\n Infer,\n InferMethodInputBody,\n InferMethodOutputBody,\n InferMethodParams,\n InferRecordKey,\n LexiconRecordKey,\n NsidString,\n Params,\n Procedure,\n Query,\n RecordSchema,\n Restricted,\n Schema,\n} from '@atproto/lex-schema'\nimport { Agent, AgentOptions, buildAgent } from './agent.js'\nimport { com } from './lexicons.js'\nimport {\n BinaryBodyInit,\n CallOptions,\n Namespace,\n Service,\n getMain,\n} from './types.js'\nimport { buildAtprotoHeaders } from './util.js'\nimport { XrpcError } from './xrpc-error.js'\nimport {\n XrpcFailure,\n XrpcOptions,\n XrpcResponse,\n XrpcResponseBody,\n xrpc,\n xrpcSafe,\n} from './xrpc.js'\n\nexport type ClientOptions = {\n labelers?: Iterable<DidString>\n headers?: HeadersInit\n service?: Service\n}\n\nexport type Action<I = any, O = any> = (\n client: Client,\n input: I,\n options: CallOptions,\n) => O | Promise<O>\nexport type InferActionInput<A extends Action> =\n A extends Action<infer I, any> ? I : never\nexport type InferActionOutput<A extends Action> =\n A extends Action<any, infer O> ? O : never\n\nexport type CreateRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n validate?: boolean\n}\n\nexport type DeleteRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n swapRecord?: string\n}\n\nexport type GetRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n}\n\nexport type PutRecordOptions = CallOptions & {\n repo?: AtIdentifierString\n swapCommit?: string\n swapRecord?: string\n validate?: boolean\n}\n\nexport type ListRecordsOptions = CallOptions & {\n repo?: AtIdentifierString\n limit?: number\n cursor?: string\n reverse?: boolean\n}\n\nexport type RecordKeyOptions<\n T extends RecordSchema,\n AlsoOptionalWhenRecordKeyIs extends LexiconRecordKey = never,\n> = T['key'] extends `literal:${string}` | AlsoOptionalWhenRecordKeyIs\n ? { rkey?: InferRecordKey<T> }\n : { rkey: InferRecordKey<T> }\n\nexport type CreateOptions<T extends RecordSchema> = CreateRecordOptions &\n RecordKeyOptions<T, 'tid'>\nexport type CreateOutput = InferMethodOutputBody<\n typeof com.atproto.repo.createRecord.main,\n Uint8Array\n>\n\nexport type DeleteOptions<T extends RecordSchema> = DeleteRecordOptions &\n RecordKeyOptions<T>\nexport type DeleteOutput = InferMethodOutputBody<\n typeof com.atproto.repo.deleteRecord.main,\n Uint8Array\n>\nexport type GetOptions<T extends RecordSchema> = GetRecordOptions &\n RecordKeyOptions<T>\nexport type GetOutput<T extends RecordSchema> = Omit<\n InferMethodOutputBody<typeof com.atproto.repo.getRecord.main, Uint8Array>,\n 'value'\n> & { value: Infer<T> }\n\nexport type PutOptions<T extends RecordSchema> = PutRecordOptions &\n RecordKeyOptions<T>\nexport type PutOutput = InferMethodOutputBody<\n typeof com.atproto.repo.putRecord.main,\n Uint8Array\n>\n\nexport type ListOptions = ListRecordsOptions\nexport type ListOutput<T extends RecordSchema> = InferMethodOutputBody<\n typeof com.atproto.repo.listRecords.main,\n Uint8Array\n> & {\n records: ListRecord<T>[]\n // @NOTE Because the schema uses \"type\": \"unknown\" instead of an open union,\n // we have to use LexMap instead of TypedObject here.\n invalid: LexMap[]\n}\nexport type ListRecord<T extends RecordSchema> =\n com.atproto.repo.listRecords.DefRecord & {\n value: Infer<T>\n }\n\nexport class Client implements Agent {\n static appLabelers: readonly DidString[] = []\n\n /**\n * Configures the Client (or its sub classes) globally.\n */\n static configure(opts: { appLabelers?: Iterable<DidString> }) {\n if (opts.appLabelers) this.appLabelers = [...opts.appLabelers]\n }\n\n public readonly agent: Agent\n public readonly headers: Headers\n public readonly service?: Service\n public readonly labelers: Set<DidString>\n\n constructor(agent: Agent | AgentOptions, options: ClientOptions = {}) {\n this.agent =\n typeof agent === 'object' && 'fetchHandler' in agent\n ? agent\n : buildAgent(agent)\n this.service = options.service\n this.labelers = new Set(options.labelers)\n this.headers = new Headers(options.headers)\n }\n\n get did(): DidString | undefined {\n return this.agent.did\n }\n\n get assertDid(): DidString {\n this.assertAuthenticated()\n return this.did\n }\n\n public assertAuthenticated(): asserts this is { did: DidString } {\n if (!this.did) throw new XrpcError('AuthenticationRequired')\n }\n\n public setLabelers(labelers: Iterable<DidString> = []) {\n this.clearLabelers()\n this.addLabelers(labelers)\n }\n\n public addLabelers(labelers: Iterable<DidString>) {\n for (const labeler of labelers) this.labelers.add(labeler)\n }\n\n public clearLabelers() {\n this.labelers.clear()\n }\n\n public fetchHandler(path: string, init: RequestInit): Promise<Response> {\n const headers = buildAtprotoHeaders({\n headers: init.headers,\n service: this.service,\n labelers: [\n ...(this.constructor as typeof Client).appLabelers.map(\n (l) => `${l};redact` as const,\n ),\n ...this.labelers,\n ],\n })\n\n // Incoming headers take precedence\n for (const [key, value] of this.headers) {\n if (!headers.has(key)) headers.set(key, value)\n }\n\n // @NOTE The agent here could be another Client instance.\n return this.agent.fetchHandler(path, { ...init, headers })\n }\n\n /**\n * @throws {XrpcFailure<M>} when the request fails or the response is an error\n */\n async xrpc<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M>>\n async xrpc<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M>> {\n return xrpc(this, ns, options)\n }\n\n async xrpcSafe<const M extends Query | Procedure>(\n ns: NonNullable<unknown> extends XrpcOptions<M>\n ? Namespace<M>\n : Restricted<'This XRPC method requires an \"options\" argument'>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>>\n async xrpcSafe<const M extends Query | Procedure>(\n ns: Namespace<M>,\n options: XrpcOptions<M> = {} as XrpcOptions<M>,\n ): Promise<XrpcResponse<M> | XrpcFailure<M>> {\n return xrpcSafe(this, ns, options)\n }\n\n /**\n * @param rkey Leave `undefined` to have the server generate a TID.\n */\n public async createRecord(\n record: { $type: NsidString } & LexMap,\n rkey?: string,\n options?: CreateRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.createRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n record,\n rkey,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n },\n })\n }\n\n async deleteRecord(\n collection: NsidString,\n rkey: string,\n options?: DeleteRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.deleteRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n public async getRecord(\n collection: NsidString,\n rkey: string,\n options?: GetRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.getRecord.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection,\n rkey,\n },\n })\n }\n\n async putRecord(\n record: { $type: NsidString } & LexMap,\n rkey: string,\n options?: PutRecordOptions,\n ) {\n return this.xrpc(com.atproto.repo.putRecord.main, {\n ...options,\n body: {\n repo: options?.repo ?? this.assertDid,\n collection: record.$type,\n rkey,\n record,\n validate: options?.validate,\n swapCommit: options?.swapCommit,\n swapRecord: options?.swapRecord,\n },\n })\n }\n\n async listRecords(nsid: NsidString, options?: ListRecordsOptions) {\n return this.xrpc(com.atproto.repo.listRecords.main, {\n ...options,\n params: {\n repo: options?.repo ?? this.assertDid,\n collection: nsid,\n cursor: options?.cursor,\n limit: options?.limit,\n reverse: options?.reverse,\n },\n })\n }\n\n async uploadBlob(\n body: BinaryBodyInit,\n options?: CallOptions & { encoding?: `${string}/${string}` },\n ) {\n return this.xrpc(com.atproto.repo.uploadBlob.main, {\n ...options,\n body,\n })\n }\n\n async getBlob(did: DidString, cid: CidString, options?: CallOptions) {\n return this.xrpc(com.atproto.sync.getBlob.main, {\n ...options,\n params: { did, cid },\n })\n }\n\n public async call<const T extends Query>(\n ns: NonNullable<unknown> extends InferMethodParams<T>\n ? Namespace<T>\n : Restricted<'This query type requires a \"params\" argument'>,\n ): Promise<XrpcResponseBody<T>>\n public async call<const T extends Action>(\n ns: void extends InferActionInput<T>\n ? Namespace<T>\n : Restricted<'This action type requires an \"input\" argument'>,\n ): Promise<InferActionOutput<T>>\n public async call<const T extends Action | Procedure | Query>(\n ns: Namespace<T>,\n arg: T extends Action\n ? InferActionInput<T>\n : T extends Procedure\n ? InferMethodInputBody<T, Uint8Array>\n : T extends Query\n ? InferMethodParams<T>\n : never,\n options?: CallOptions,\n ): Promise<\n T extends Action\n ? InferActionOutput<T>\n : T extends Procedure\n ? XrpcResponseBody<T>\n : T extends Query\n ? XrpcResponseBody<T>\n : never\n >\n public async call(\n ns: Namespace<Action> | Namespace<Procedure> | Namespace<Query>,\n arg?: LexValue | Params,\n options: CallOptions = {},\n ): Promise<unknown> {\n const method = getMain(ns)\n\n if (typeof method === 'function') {\n return method(this, arg, options)\n }\n\n if (method instanceof Procedure) {\n const result = await this.xrpc(method, { ...options, body: arg as any })\n return result.body\n } else if (method instanceof Query) {\n const result = await this.xrpc(method, { ...options, params: arg as any })\n return result.body\n } else {\n throw new TypeError('Invalid lexicon')\n }\n }\n\n public async create<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends CreateOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T>,\n ): Promise<CreateOutput>\n public async create<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: CreateOptions<T> = {} as CreateOptions<T>,\n ): Promise<CreateOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input)\n if (options.validateRequest) schema.assert(record)\n const rkey = options.rkey ?? getDefaultRecordKey(schema)\n if (rkey !== undefined) schema.keySchema.assert(rkey)\n const response = await this.createRecord(record, rkey, options)\n return response.body\n }\n\n public async delete<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends DeleteOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: DeleteOptions<T>,\n ): Promise<DeleteOutput>\n public async delete<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: DeleteOptions<T> = {} as DeleteOptions<T>,\n ): Promise<DeleteOutput> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.deleteRecord(schema.$type, rkey, options)\n return response.body\n }\n\n public async get<const T extends RecordSchema>(\n ns: T['key'] extends `literal:${string}`\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: GetOptions<T>,\n ): Promise<GetOutput<T>>\n public async get<const T extends RecordSchema>(\n ns: Namespace<T>,\n options: GetOptions<T> = {} as GetOptions<T>,\n ): Promise<GetOutput<T>> {\n const schema = getMain(ns)\n const rkey = schema.keySchema.parse(\n options.rkey ?? getLiteralRecordKey(schema),\n )\n const response = await this.getRecord(schema.$type, rkey, options)\n const value = schema.parse(response.body.value) as Infer<T>\n return { ...response.body, value }\n }\n\n public async put<const T extends RecordSchema>(\n ns: NonNullable<unknown> extends PutOptions<T>\n ? Namespace<T>\n : Restricted<'This record type requires an \"options\" argument'>,\n input: Omit<Infer<T>, '$type'>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T>,\n ): Promise<PutOutput>\n public async put<const T extends RecordSchema>(\n ns: Namespace<T>,\n input: Omit<Infer<T>, '$type'>,\n options: PutOptions<T> = {} as PutOptions<T>,\n ): Promise<PutOutput> {\n const schema: T = getMain(ns)\n const record = schema.build(input)\n if (options.validateRequest) schema.assert(record)\n const rkey = options.rkey ?? getLiteralRecordKey(schema)\n const response = await this.putRecord(record, rkey, options)\n return response.body\n }\n\n async list<const T extends RecordSchema>(\n ns: Namespace<T>,\n options?: ListOptions,\n ): Promise<ListOutput<T>> {\n const schema = getMain(ns)\n const { body } = await this.listRecords(schema.$type, options)\n\n const records: ListRecord<T>[] = []\n const invalid: LexMap[] = []\n\n for (const record of body.records) {\n const parsed = (schema as Schema<Infer<T>>).safeParse(record.value)\n if (parsed.success) {\n records.push({ ...record, value: parsed.value })\n } else {\n invalid.push(record.value)\n }\n }\n\n return { ...body, records, invalid }\n }\n}\n\nfunction getDefaultRecordKey<const T extends RecordSchema>(\n schema: T,\n): undefined | InferRecordKey<T> {\n // Let the server generate the TID\n if (schema.key === 'tid') return undefined\n if (schema.key === 'any') return undefined\n\n return getLiteralRecordKey(schema)\n}\n\nfunction getLiteralRecordKey<const T extends RecordSchema>(\n schema: T,\n): InferRecordKey<T> {\n if (schema.key.startsWith('literal:')) {\n return schema.key.slice(8)\n }\n\n throw new TypeError(\n `An \"rkey\" must be provided for record key type \"${schema.key}\" (${schema.$type})`,\n )\n}\n"]}
|