@atproto/lex-client 0.0.20 → 0.1.0-next.0
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 +30 -0
- package/dist/agent.js +2 -6
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +18 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +28 -40
- package/dist/client.js.map +1 -1
- package/dist/errors.js +32 -47
- package/dist/errors.js.map +1 -1
- package/dist/index.js +6 -9
- package/dist/index.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +23 -27
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.js +2 -6
- package/dist/lexicons/com/atproto/repo/createRecord.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.js +7 -10
- package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.js +2 -6
- package/dist/lexicons/com/atproto/repo/defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +18 -22
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.js +2 -6
- package/dist/lexicons/com/atproto/repo/deleteRecord.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +14 -17
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.js +2 -6
- package/dist/lexicons/com/atproto/repo/getRecord.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +23 -26
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.js +2 -6
- package/dist/lexicons/com/atproto/repo/listRecords.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +24 -28
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.js +2 -6
- package/dist/lexicons/com/atproto/repo/putRecord.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +8 -11
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.js +2 -6
- package/dist/lexicons/com/atproto/repo/uploadBlob.js.map +1 -1
- package/dist/lexicons/com/atproto/repo.js +7 -11
- package/dist/lexicons/com/atproto/repo.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js +9 -12
- package/dist/lexicons/com/atproto/sync/getBlob.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/sync/getBlob.js +2 -6
- package/dist/lexicons/com/atproto/sync/getBlob.js.map +1 -1
- package/dist/lexicons/com/atproto/sync.js +1 -5
- package/dist/lexicons/com/atproto/sync.js.map +1 -1
- package/dist/lexicons/com/atproto.js +2 -6
- package/dist/lexicons/com/atproto.js.map +1 -1
- package/dist/lexicons/com.js +1 -5
- package/dist/lexicons/com.js.map +1 -1
- package/dist/lexicons/index.js +1 -5
- package/dist/lexicons/index.js.map +1 -1
- package/dist/response.d.ts +18 -1
- package/dist/response.d.ts.map +1 -1
- package/dist/response.js +32 -23
- package/dist/response.js.map +1 -1
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -4
- package/dist/types.js.map +1 -1
- package/dist/util.js +6 -14
- package/dist/util.js.map +1 -1
- package/dist/www-authenticate.js +1 -4
- package/dist/www-authenticate.js.map +1 -1
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +25 -28
- package/dist/xrpc.js.map +1 -1
- package/package.json +10 -11
- package/src/client.ts +18 -2
- package/src/response.ts +18 -1
- package/src/types.ts +8 -4
- package/src/xrpc.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.1.0-next.0",
|
|
4
|
+
"engines": {
|
|
5
|
+
"node": ">=22"
|
|
6
|
+
},
|
|
4
7
|
"license": "MIT",
|
|
5
8
|
"description": "HTTP client for interacting with Lexicon based APIs",
|
|
6
9
|
"keywords": [
|
|
@@ -24,27 +27,23 @@
|
|
|
24
27
|
"./CHANGELOG.md"
|
|
25
28
|
],
|
|
26
29
|
"sideEffects": false,
|
|
27
|
-
"type": "
|
|
28
|
-
"main": "./dist/index.js",
|
|
29
|
-
"types": "./dist/index.d.ts",
|
|
30
|
+
"type": "module",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
33
|
"types": "./dist/index.d.ts",
|
|
33
|
-
"browser": "./dist/index.js",
|
|
34
|
-
"import": "./dist/index.js",
|
|
35
34
|
"default": "./dist/index.js"
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
"dependencies": {
|
|
39
38
|
"tslib": "^2.8.1",
|
|
40
|
-
"@atproto/lex-data": "^0.0.
|
|
41
|
-
"@atproto/lex-
|
|
42
|
-
"@atproto/lex-
|
|
39
|
+
"@atproto/lex-data": "^0.1.0-next.0",
|
|
40
|
+
"@atproto/lex-schema": "^0.1.0-next.0",
|
|
41
|
+
"@atproto/lex-json": "^0.1.0-next.0"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"vitest": "^4.0.16",
|
|
46
|
-
"@atproto/lex-
|
|
47
|
-
"@atproto/lex-
|
|
45
|
+
"@atproto/lex-builder": "^0.1.0-next.0",
|
|
46
|
+
"@atproto/lex-cbor": "^0.1.0-next.0"
|
|
48
47
|
},
|
|
49
48
|
"scripts": {
|
|
50
49
|
"prebuild": "node ./scripts/lex-build.mjs",
|
package/src/client.ts
CHANGED
|
@@ -63,12 +63,26 @@ export type {
|
|
|
63
63
|
/**
|
|
64
64
|
* Configuration options for creating a {@link Client}.
|
|
65
65
|
*
|
|
66
|
+
* @property {@link ClientOptions.labelers} - An iterable of labeler DIDs to include in requests. These will be combined with any global app labelers configured via {@link Client.configure}.
|
|
67
|
+
* @property {@link ClientOptions.service} - An optional service identifier (DID or URL) for routing requests with service proxying.
|
|
68
|
+
* @property {@link ClientOptions.headers} - Custom headers to include in all requests made by this client instance.
|
|
69
|
+
* @property {@link ClientOptions.validateRequest} - If true, validates request bodies against their lexicon schemas before sending. Defaults to false for performance.
|
|
70
|
+
* @property {@link ClientOptions.validateResponse} - If false, skips validation of response bodies against their lexicon schemas. Defaults to true to catch errors, but can be disabled for performance if you trust the server responses. Note that defaults will not be applied if validation is disabled, which can cause typing inconsistencies, so use with caution.
|
|
71
|
+
* @property {@link ClientOptions.strictResponseProcessing} - If false, relaxes certain validation rules during response processing (e.g., allowing floats, deeper nesting, etc.). Defaults to true for strict compliance with {@link https://atproto.com/specs/data-model lexicon data model}, but can be disabled to handle non-compliant responses.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link XrpcRequestHeadersOptions}
|
|
74
|
+
* @see {@link XrpcRequestProcessingOptions}
|
|
75
|
+
* @see {@link XrpcResponseOptions}
|
|
76
|
+
*
|
|
66
77
|
* @example
|
|
67
78
|
* ```typescript
|
|
68
79
|
* const options: ClientOptions = {
|
|
69
80
|
* labelers: ['did:plc:labeler1'],
|
|
70
81
|
* service: 'did:web:api.bsky.app#bsky_appview',
|
|
71
|
-
* headers: { 'X-Custom-Header': 'value' }
|
|
82
|
+
* headers: { 'X-Custom-Header': 'value' },
|
|
83
|
+
* validateRequest: false,
|
|
84
|
+
* validateResponse: true,
|
|
85
|
+
* strictResponseProcessing: false,
|
|
72
86
|
* }
|
|
73
87
|
* ```
|
|
74
88
|
*/
|
|
@@ -223,6 +237,7 @@ export type RecordKeyOptions<
|
|
|
223
237
|
/**
|
|
224
238
|
* Type-safe options for {@link Client.create}, combining record options with key requirements.
|
|
225
239
|
* @typeParam T - The record schema type
|
|
240
|
+
* @see {@link CreateRecordOptions}
|
|
226
241
|
*/
|
|
227
242
|
export type CreateOptions<T extends RecordSchema> = CreateRecordOptions &
|
|
228
243
|
RecordKeyOptions<T, 'tid' | 'any'>
|
|
@@ -321,9 +336,10 @@ export type ListRecord<Value extends LexMap> =
|
|
|
321
336
|
* services. It provides type-safe methods for XRPC calls, record operations,
|
|
322
337
|
* and blob handling.
|
|
323
338
|
*
|
|
324
|
-
* @example
|
|
339
|
+
* @example
|
|
325
340
|
* ```typescript
|
|
326
341
|
* import { Client } from '@atproto/lex'
|
|
342
|
+
* import { app } from '#/lexicons
|
|
327
343
|
*
|
|
328
344
|
* const client = new Client(oauthSession)
|
|
329
345
|
*
|
package/src/response.ts
CHANGED
|
@@ -117,9 +117,26 @@ export type XrpcResponseOptions = {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Small container for XRPC response
|
|
120
|
+
* Small container for XRPC response.
|
|
121
121
|
*
|
|
122
122
|
* @implements {ResultSuccess<XrpcResponse<M>>} for convenience in result handling contexts.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
*
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { app } from '#/lexicons'
|
|
128
|
+
* import { XrpcResponse } from '@atproto/lex-client'
|
|
129
|
+
*
|
|
130
|
+
* const fetchResponse = await fetch('https://example.com/xrpc/app.bsky.feed.getTimeline')
|
|
131
|
+
*
|
|
132
|
+
* const response = await XrpcResponse.fromFetchResponse(
|
|
133
|
+
* app.bsky.feed.getTimeline.main,
|
|
134
|
+
* fetchResponse,
|
|
135
|
+
* )
|
|
136
|
+
*
|
|
137
|
+
* // Fully typed (validated) response body, according to the method's output schema
|
|
138
|
+
* const { cursor, feed } = response.body
|
|
139
|
+
* ```
|
|
123
140
|
*/
|
|
124
141
|
export class XrpcResponse<M extends Procedure | Query>
|
|
125
142
|
implements ResultSuccess<XrpcResponse<M>>
|
package/src/types.ts
CHANGED
|
@@ -46,13 +46,17 @@ export type Service = `${DidString}#${DidServiceIdentifier}`
|
|
|
46
46
|
* const file: BinaryBodyInit = fileInput.files[0]
|
|
47
47
|
* await client.xrpc(uploadMethod, { body: file })
|
|
48
48
|
* ```
|
|
49
|
+
*
|
|
50
|
+
* @note Uint8Array is parameterized with ArrayBuffer (not ArrayBufferLike)
|
|
51
|
+
* because fetch's BodyInit requires ArrayBuffer-backed views —
|
|
52
|
+
* SharedArrayBuffer is not supported for network I/O.
|
|
49
53
|
*/
|
|
50
54
|
export type BinaryBodyInit =
|
|
51
|
-
| Uint8Array
|
|
55
|
+
| Uint8Array<ArrayBuffer>
|
|
52
56
|
| ArrayBuffer
|
|
53
57
|
| Blob
|
|
54
|
-
| ReadableStream<Uint8Array
|
|
55
|
-
| AsyncIterable<Uint8Array
|
|
58
|
+
| ReadableStream<Uint8Array<ArrayBuffer>>
|
|
59
|
+
| AsyncIterable<Uint8Array<ArrayBuffer>>
|
|
56
60
|
| string
|
|
57
61
|
|
|
58
62
|
export type EncodingString = `${string}/${string}`
|
|
@@ -64,7 +68,7 @@ export function isEncodingString(
|
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
export type XrpcUnknownResponsePayload<
|
|
67
|
-
TBinary extends BinaryBodyInit = Uint8Array
|
|
71
|
+
TBinary extends BinaryBodyInit = Uint8Array<ArrayBuffer>,
|
|
68
72
|
> = {
|
|
69
73
|
encoding: EncodingString
|
|
70
74
|
body: LexValue | TBinary
|
package/src/xrpc.ts
CHANGED
|
@@ -335,8 +335,13 @@ function xrpcProcedureInput(
|
|
|
335
335
|
return buildPayload(input, body, encodingHint)
|
|
336
336
|
case 'object': {
|
|
337
337
|
if (body === null) break
|
|
338
|
-
if (
|
|
339
|
-
|
|
338
|
+
if (ArrayBuffer.isView(body)) {
|
|
339
|
+
return buildPayload(
|
|
340
|
+
input,
|
|
341
|
+
body as Uint8Array<ArrayBuffer>,
|
|
342
|
+
encodingHint,
|
|
343
|
+
)
|
|
344
|
+
} else if (
|
|
340
345
|
body instanceof ArrayBuffer ||
|
|
341
346
|
body instanceof ReadableStream
|
|
342
347
|
) {
|