@atproto/lex 0.4.8 → 0.6.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 +48 -0
- package/README.md +122 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @atproto/lex
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5885](https://github.com/bluesky-social/atproto/pull/5885) [`6ee0f4d`](https://github.com/bluesky-social/atproto/commit/6ee0f4d7971dcc71efaab785aff4d4ef341a1c32) Thanks [@matthieusieben](https://github.com/matthieusieben)! - **Breaking:** `RETRYABLE_HTTP_STATUS_CODES` is now a frozen, literal-typed array instead of a `ReadonlySet<number>`. Replace `RETRYABLE_HTTP_STATUS_CODES.has(status)` with the new `isRetryableHttpStatus(status)` type guard (narrowing to the new `RetryableHttpStatus` type).
|
|
8
|
+
|
|
9
|
+
Also add `RETRYABLE_ERROR_CODES` and its `isRetryableErrorCode()` type guard (the XRPC error codes matching a retryable HTTP status, for classifying an error by code alone), and `getStatusErrorCode()`, mapping an HTTP status to the XRPC error code used for non-XRPC error responses.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#5950](https://github.com/bluesky-social/atproto/pull/5950) [`b9b1ca7`](https://github.com/bluesky-social/atproto/commit/b9b1ca7f176b93d12e39685799c5f2e1f9a63be7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update `vitest` to v5, `vite` to v8.3.8 and `rolldown` to v1.3.3 (dev dependencies)
|
|
14
|
+
|
|
15
|
+
- [#5930](https://github.com/bluesky-social/atproto/pull/5930) [`118a827`](https://github.com/bluesky-social/atproto/commit/118a82770430c01ed47ded26569fffcbd68afcf4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove the `encodeOptions` and `decodeOptions` exports from `@atproto/lex-cbor`, and so from `@atproto/lex`, which re-exports it. They were internal cborg configuration, not meant to be public; use `encode`, `decode` and `decodeAll` instead.
|
|
16
|
+
|
|
17
|
+
- [#5885](https://github.com/bluesky-social/atproto/pull/5885) [`6ee0f4d`](https://github.com/bluesky-social/atproto/commit/6ee0f4d7971dcc71efaab785aff4d4ef341a1c32) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Re-export XRPC subscription support from `@atproto/lex-rpc/subscription`: `xrpcSubscribe()`, `createWebSocketFactory()`, `defaultWebsocket` and `defaultSubscriptionShouldReconnect()`.
|
|
18
|
+
|
|
19
|
+
- [#5948](https://github.com/bluesky-social/atproto/pull/5948) [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Document per-request `headers` functions.
|
|
20
|
+
|
|
21
|
+
- [#5948](https://github.com/bluesky-social/atproto/pull/5948) [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Document calling actions whose input is optional without input.
|
|
22
|
+
- Updated dependencies [[`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`b9b1ca7`](https://github.com/bluesky-social/atproto/commit/b9b1ca7f176b93d12e39685799c5f2e1f9a63be7), [`118a827`](https://github.com/bluesky-social/atproto/commit/118a82770430c01ed47ded26569fffcbd68afcf4), [`6ee0f4d`](https://github.com/bluesky-social/atproto/commit/6ee0f4d7971dcc71efaab785aff4d4ef341a1c32), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd), [`6ee0f4d`](https://github.com/bluesky-social/atproto/commit/6ee0f4d7971dcc71efaab785aff4d4ef341a1c32), [`ce37237`](https://github.com/bluesky-social/atproto/commit/ce37237663b7ea87e8cc04cb995377d0ee5d2efd)]:
|
|
23
|
+
- @atproto/lex-rpc@0.2.0
|
|
24
|
+
- @atproto/lex-builder@0.1.21
|
|
25
|
+
- @atproto/lex-cbor@0.1.11
|
|
26
|
+
- @atproto/lex-client@0.6.0
|
|
27
|
+
- @atproto/lex-data@0.1.11
|
|
28
|
+
- @atproto/lex-installer@0.2.10
|
|
29
|
+
- @atproto/lex-json@0.1.10
|
|
30
|
+
- @atproto/lex-schema@0.3.0
|
|
31
|
+
|
|
32
|
+
## 0.5.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- [#5917](https://github.com/bluesky-social/atproto/pull/5917) [`b5dfe0b`](https://github.com/bluesky-social/atproto/commit/b5dfe0b80ac4f14f56b3c9b797e0e50d2e194a3b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - **Breaking:** the response payload of methods without a declared output encoding is no longer parsed as JSON. It is returned as binary data (a `Uint8Array`, or a `ReadableStream` with `xrpcStream()`), or `undefined` when there is none, and callers that expect JSON must parse it themselves (e.g. `lexParse(new TextDecoder().decode(body))`). Only `application/json` outputs, and outputs with a schema, are parsed.
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- [#5917](https://github.com/bluesky-social/atproto/pull/5917) [`b5dfe0b`](https://github.com/bluesky-social/atproto/commit/b5dfe0b80ac4f14f56b3c9b797e0e50d2e194a3b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `xrpcStream()` / `xrpcStreamSafe()` (and `Client.xrpcStream()`, `Client.xrpcStreamSafe()`, `Client.getBlobStream()`), returning binary response payloads as an unread `ReadableStream` through a disposable `XrpcStreamResponse`. Response bodies are now always released (cancelled) when response processing fails, as configured by the new `onCancellationError` response option (defaults to `"propagate"`).
|
|
41
|
+
- Updated dependencies [[`b5dfe0b`](https://github.com/bluesky-social/atproto/commit/b5dfe0b80ac4f14f56b3c9b797e0e50d2e194a3b), [`b5dfe0b`](https://github.com/bluesky-social/atproto/commit/b5dfe0b80ac4f14f56b3c9b797e0e50d2e194a3b)]:
|
|
42
|
+
- @atproto/lex-client@0.5.0
|
|
43
|
+
- @atproto/lex-installer@0.2.9
|
|
44
|
+
|
|
3
45
|
## 0.4.8
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
|
@@ -92,6 +134,12 @@
|
|
|
92
134
|
- @atproto/lex-client@0.4.0
|
|
93
135
|
- @atproto/lex-schema@0.2.9
|
|
94
136
|
|
|
137
|
+
## 0.3.15
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- [`631ac94`](https://github.com/bluesky-social/atproto/commit/631ac946b2a2ec45c8f49921966f6a557f1666c6) Fix conflicting `walk` exports when resolving newer `@atproto/lex-schema` releases. Explicitly re-export the original Lex 0.3 implementation to preserve its API and traversal behavior.
|
|
142
|
+
|
|
95
143
|
## 0.3.14
|
|
96
144
|
|
|
97
145
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -46,6 +46,7 @@ const posts = await client.list(app.bsky.feed.post, { limit: 10 })
|
|
|
46
46
|
- [Installation](#installation)
|
|
47
47
|
- [Quick Start](#quick-start)
|
|
48
48
|
- [Lexicon Schemas](#lexicon-schemas)
|
|
49
|
+
- [Local resolution (`resolvers`)](#local-resolution-resolvers)
|
|
49
50
|
- [TypeScript Schemas](#typescript-schemas)
|
|
50
51
|
- [Generated Schema Structure](#generated-schema-structure)
|
|
51
52
|
- [Type definitions](#type-definitions)
|
|
@@ -90,6 +91,8 @@ const posts = await client.list(app.bsky.feed.post, { limit: 10 })
|
|
|
90
91
|
- [`client.assertDid`](#clientassertdid)
|
|
91
92
|
- [Labeler Configuration](#labeler-configuration)
|
|
92
93
|
- [Low-Level XRPC](#low-level-xrpc)
|
|
94
|
+
- [Subscriptions](#subscriptions)
|
|
95
|
+
- [Subscription Errors and Reconnects](#subscription-errors-and-reconnects)
|
|
93
96
|
- [Utilities](#utilities)
|
|
94
97
|
- [Datetime Strings](#datetime-strings)
|
|
95
98
|
- [Advanced Usage](#advanced-usage)
|
|
@@ -139,13 +142,14 @@ npm install @atproto/lex-client @atproto/lex-schema
|
|
|
139
142
|
lex build --lib @atproto/lex-schema
|
|
140
143
|
```
|
|
141
144
|
|
|
142
|
-
| Package | Provides
|
|
143
|
-
| --------------------- |
|
|
144
|
-
| `@atproto/lex-client` | `Client`, `xrpc()`, `xrpcSafe()` and XRPC errors
|
|
145
|
-
| `@atproto/lex-
|
|
146
|
-
| `@atproto/lex-
|
|
147
|
-
| `@atproto/lex-
|
|
148
|
-
| `@atproto/lex-
|
|
145
|
+
| Package | Provides |
|
|
146
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
147
|
+
| `@atproto/lex-client` | `Client`, `xrpc()`, `xrpcSafe()` and XRPC errors |
|
|
148
|
+
| `@atproto/lex-rpc` | `xrpcSubscribe()`, `createWebSocketFactory()` and `defaultWebsocket`, from the `@atproto/lex-rpc/subscription` entrypoint |
|
|
149
|
+
| `@atproto/lex-schema` | The `l` schema utility, identifier and datetime string types and helpers |
|
|
150
|
+
| `@atproto/lex-data` | Data model types and helpers: `LexValue`, `Cid`, blob references, … |
|
|
151
|
+
| `@atproto/lex-json` | JSON encoding: `lexParse()`, `lexStringify()`, `jsonToLex()`, `lexToJson()` |
|
|
152
|
+
| `@atproto/lex-cbor` | CBOR encoding: `encode()`, `decode()`, `cidForLex()` |
|
|
149
153
|
|
|
150
154
|
## Quick Start
|
|
151
155
|
|
|
@@ -1121,6 +1125,16 @@ console.log(response.headers)
|
|
|
1121
1125
|
console.log(response.body)
|
|
1122
1126
|
```
|
|
1123
1127
|
|
|
1128
|
+
Per-request `headers` can also be a (sync or async) function, called for every attempt (retries included), for headers that must differ between attempts:
|
|
1129
|
+
|
|
1130
|
+
```typescript
|
|
1131
|
+
const response = await client.xrpc(app.bsky.feed.getTimeline, {
|
|
1132
|
+
params: { limit: 50 },
|
|
1133
|
+
maxRetries: 3,
|
|
1134
|
+
headers: async () => ({ 'x-request-nonce': await createNonce() }),
|
|
1135
|
+
})
|
|
1136
|
+
```
|
|
1137
|
+
|
|
1124
1138
|
Validation and strictness options (`validateRequest`, `validateResponse`, `strictResponseProcessing`) can also be passed per-call to override the client defaults:
|
|
1125
1139
|
|
|
1126
1140
|
```typescript
|
|
@@ -1131,6 +1145,105 @@ const response = await client.xrpc(app.bsky.feed.getTimeline, {
|
|
|
1131
1145
|
})
|
|
1132
1146
|
```
|
|
1133
1147
|
|
|
1148
|
+
#### Streaming binary responses
|
|
1149
|
+
|
|
1150
|
+
Binary (non JSON) response payloads are read into a `Uint8Array` by default. Use `client.xrpcStream()`, `client.xrpcStreamSafe()` or `client.getBlobStream()` to get the unread `ReadableStream` instead, as an `XrpcStreamResponse`. These only accept methods declaring a binary output (a non-JSON encoding, without schema) or no output encoding at all, and error responses are always buffered. The payload of methods without an output encoding is never parsed: it is returned as binary data (if any), in both modes.
|
|
1151
|
+
|
|
1152
|
+
```typescript
|
|
1153
|
+
// Disposing of the response cancels the stream if it was not fully consumed
|
|
1154
|
+
await using response = await client.getBlobStream(did, cid)
|
|
1155
|
+
|
|
1156
|
+
for await (const chunk of response.body) {
|
|
1157
|
+
// ...
|
|
1158
|
+
}
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
The caller owns the returned stream and must either consume or cancel it, through `response.cancel()` or by disposing of the response (`await using`, which follows the `onCancellationError` option). The results of `xrpcStreamSafe()`, including failures, are disposable without narrowing. Fetch implementations that do not expose response bodies as streams (e.g. React Native's built-in `fetch`) cause an `XrpcInternalError`.
|
|
1162
|
+
|
|
1163
|
+
### Subscriptions
|
|
1164
|
+
|
|
1165
|
+
XRPC subscriptions (WebSocket event streams) are consumed as async generators, through `xrpcSubscribe()`. Messages are decoded, get their `$type` restored, and are validated against the subscription's message schema. Frames with an unknown `op` are skipped without being decoded past their header, so that servers can introduce new kinds of frames. The stream is opened on the first pull, through the agent's `websocketHandler`, which owns the connection and may reconnect, so a `for await` loop spans reconnects.
|
|
1166
|
+
|
|
1167
|
+
`@atproto/lex` exports `xrpcSubscribe()`, which bundlers drop (along with [`@atproto/ws-client`](https://github.com/bluesky-social/atproto/tree/main/packages/ws-client)) when unused. When depending on the runtime packages instead (see [Installation](#installation)), import it from the `@atproto/lex-rpc/subscription` entrypoint: it is kept out of the main one, so that `@atproto/ws-client` is only loaded by code that subscribes.
|
|
1168
|
+
|
|
1169
|
+
```typescript
|
|
1170
|
+
import { xrpcSubscribe } from '@atproto/lex'
|
|
1171
|
+
import * as com from './lexicons/com.js'
|
|
1172
|
+
|
|
1173
|
+
const controller = new AbortController()
|
|
1174
|
+
|
|
1175
|
+
let cursor: number | undefined
|
|
1176
|
+
for await (const message of xrpcSubscribe(
|
|
1177
|
+
'https://labeler.example.com',
|
|
1178
|
+
com.atproto.label.subscribeLabels,
|
|
1179
|
+
{
|
|
1180
|
+
// A function is called before every connection, reconnects included
|
|
1181
|
+
params: () => ({ cursor }),
|
|
1182
|
+
signal: controller.signal, // aborting rejects the loop with the reason
|
|
1183
|
+
},
|
|
1184
|
+
)) {
|
|
1185
|
+
if (com.atproto.label.subscribeLabels.labels.$isTypeOf(message)) {
|
|
1186
|
+
cursor = message.seq
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
```
|
|
1190
|
+
|
|
1191
|
+
The first argument is the service to connect to (its `http(s)` protocol mapped to `ws(s)`), as a URL or an `AgentConfig` (e.g. to set `headers`, merged into the subscription's own), or an `Agent`. From a URL or a config, the subscription connects through `defaultWebsocket`, a `WebSocketFactory` (the WebSocket counterpart of `fetch`) over `@atproto/ws-client`: it reconnects, with backoff, after the failures `@atproto/ws-client` retries by default and after the transient failures of the subscription itself (see `defaultSubscriptionShouldReconnect()`). For other connection options (`heartbeat`, `idleTimeoutMs`, `maxReconnectSeconds`, `shouldReconnect`, the lifecycle hooks, …), set the config's `websocket` to a factory created by `createWebSocketFactory()`, which takes the options of `@atproto/ws-client`'s `websocket()` (except `signal` and `headers`, which come from each subscription):
|
|
1192
|
+
|
|
1193
|
+
```typescript
|
|
1194
|
+
import { createWebSocketFactory, xrpcSubscribe } from '@atproto/lex'
|
|
1195
|
+
|
|
1196
|
+
const messages = xrpcSubscribe(
|
|
1197
|
+
{
|
|
1198
|
+
service: 'https://labeler.example.com',
|
|
1199
|
+
websocket: createWebSocketFactory({ idleTimeoutMs: 60_000 }),
|
|
1200
|
+
},
|
|
1201
|
+
com.atproto.label.subscribeLabels,
|
|
1202
|
+
)
|
|
1203
|
+
```
|
|
1204
|
+
|
|
1205
|
+
A `WebSocketFactory` can also be written from scratch: it is called with a function returning the URL to connect to, to invoke before every connection, and with the subscription's `signal` and `headers`, and returns an `AsyncIterable` of binary frames.
|
|
1206
|
+
|
|
1207
|
+
An `Agent` is used as-is, and `xrpcSubscribe()` throws a `TypeError` if it has no `websocketHandler`. `buildAgent()` builds one from an `AgentConfig` with a `websocket`, and so does the `Client` constructor: the `agent` of a `new Client({ service, websocket })` can subscribe. A custom `Agent` can implement `websocketHandler(path, { signal, headers })` itself: it adds the origin to `path` (a function to invoke before every connection) and returns an `AsyncIterable` of binary frames. Browsers cannot send headers with a WebSocket upgrade (`@atproto/ws-client` throws), so don't set `headers` on an agent (or config) used for subscriptions in a browser.
|
|
1208
|
+
|
|
1209
|
+
Disable `validateResponse` only for a trusted server: messages are then yielded as decoded, without defaults applied. `strictResponseProcessing: false` relaxes their validation instead.
|
|
1210
|
+
|
|
1211
|
+
Breaking out of the loop (or `return`/`throw`) closes the connection. Aborting the `signal` rejects the loop with the abort reason; with `@atproto/ws-client`, abort with a `CloseError` to choose the close code.
|
|
1212
|
+
|
|
1213
|
+
#### Subscription Errors and Reconnects
|
|
1214
|
+
|
|
1215
|
+
Reconnects are decided by the agent's `websocket` function (with `@atproto/ws-client`, by its `shouldReconnect` option). A frame that fails to decode or validate, an error frame included, is handed back to it through the stream's `throw()`, which ends the connection that delivered it. `isRetryableSubscriptionError()` tells whether a reconnect may then succeed. `@atproto/ws-client`'s own `defaultShouldReconnect` only classifies its own errors: `defaultSubscriptionShouldReconnect()` (the default `shouldReconnect` of `createWebSocketFactory()`) combines both, so build a custom `shouldReconnect` on it, or transient error frames end the loop.
|
|
1216
|
+
|
|
1217
|
+
Every error that ends the loop is an `XrpcSubscriptionError` with a `shouldRetry()` classification, except an abort reason, which is passed through as-is. The hooks of `@atproto/ws-client` receive connection failures unwrapped. A `params` function failing with a transient error (e.g. an `XrpcError` from a cursor looked up over XRPC) is retried, and invoked again on the reconnect.
|
|
1218
|
+
|
|
1219
|
+
| Class | Meaning | `shouldRetry()` |
|
|
1220
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------- |
|
|
1221
|
+
| `XrpcSubscriptionParamsError` | The URL could not be built: a `params` function threw, or the params are invalid (`cause`) | Per the cause (if it has a `shouldRetry()` method) |
|
|
1222
|
+
| `XrpcSubscriptionConnectionError` | The connection failed (`cause` is the error, e.g. from `@atproto/ws-client`) | Per the cause (close code, upgrade HTTP status, …) |
|
|
1223
|
+
| `XrpcSubscriptionServerError` | The server sent an error frame (`error`, `message`, `matchesSchemaErrors()`) | Only for transient codes (`InternalServerError`, …) |
|
|
1224
|
+
| `XrpcSubscriptionFrameError` | The server sent an invalid frame | No |
|
|
1225
|
+
| `XrpcSubscriptionMessageError` | A message did not match the schema (`value`, `cause`) | No |
|
|
1226
|
+
|
|
1227
|
+
A message failing validation is not retryable, since resuming from the last cursor would receive it again: to skip such messages, pass an `onMessageError` callback that returns instead of throwing (it receives each `XrpcSubscriptionMessageError`), or disable validation (`validateResponse: false`) and check each message yourself.
|
|
1228
|
+
|
|
1229
|
+
```typescript
|
|
1230
|
+
import {
|
|
1231
|
+
createWebSocketFactory,
|
|
1232
|
+
defaultSubscriptionShouldReconnect,
|
|
1233
|
+
} from '@atproto/lex'
|
|
1234
|
+
|
|
1235
|
+
const relay: AgentConfig = {
|
|
1236
|
+
service: 'https://relay.example.com',
|
|
1237
|
+
websocket: createWebSocketFactory({
|
|
1238
|
+
// Catch up after being dropped for being too slow
|
|
1239
|
+
shouldReconnect: (error) =>
|
|
1240
|
+
defaultSubscriptionShouldReconnect(error) ||
|
|
1241
|
+
(error instanceof XrpcSubscriptionServerError &&
|
|
1242
|
+
error.error === 'ConsumerTooSlow'),
|
|
1243
|
+
}),
|
|
1244
|
+
}
|
|
1245
|
+
```
|
|
1246
|
+
|
|
1134
1247
|
## Utilities
|
|
1135
1248
|
|
|
1136
1249
|
Various utilities for working with CIDs, datetime strings, string lengths, language tags, and low-level JSON encoding are exported from the package:
|
|
@@ -1585,6 +1698,8 @@ const enableAdultContent: Action<void, Preference[]> = async (
|
|
|
1585
1698
|
await client.call(enableAdultContent)
|
|
1586
1699
|
```
|
|
1587
1700
|
|
|
1701
|
+
Actions whose input is `void`, or optional (e.g. `params?: ListParams`), can be called without input.
|
|
1702
|
+
|
|
1588
1703
|
### Using a Single Client for Multiple Services
|
|
1589
1704
|
|
|
1590
1705
|
Because the client's `service` and `labelers` options are just _defaults_, a single `Client` instance can be used to talk to multiple services. This is the recommended pattern for SDK-style code: configure the client to talk to an AppView by default, and override `service` on a per-request basis when a request must reach another service — or the user's PDS directly (`service: null`).
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ xrpc,
|
|
|
29
29
|
*/
|
|
30
30
|
xrpcSafe, } from '@atproto/lex-client';
|
|
31
31
|
export * from '@atproto/lex-client';
|
|
32
|
+
export * from '@atproto/lex-rpc/subscription';
|
|
32
33
|
export {
|
|
33
34
|
/**
|
|
34
35
|
* The {@link l} namespace (from `@atproto/lex-schema`) provides an imperative API for building schemas:
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACL;;;;GAIG;AACH,MAAM;AACN;;;;;;GAMG;AACH,IAAI;AACJ;;;;;;GAMG;AACH,QAAQ,GACT,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,CAAC,GACF,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO;AACL;;;;;GAKG;AACH,KAAK,MAAM;AACX;;;;;;GAMG;AACH,KAAK,QAAQ,GACd,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,OAAO;AACL;;;;GAIG;AACH,SAAS;AACT;;;;GAIG;AACH,QAAQ;AACR;;;;GAIG;AACH,YAAY;AACZ;;;;GAIG;AACH,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACL;;;;GAIG;AACH,MAAM;AACN;;;;;;GAMG;AACH,IAAI;AACJ;;;;;;GAMG;AACH,QAAQ,GACT,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,cAAc,+BAA+B,CAAA;AAE7C,OAAO;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,CAAC,GACF,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO;AACL;;;;;GAKG;AACH,KAAK,MAAM;AACX;;;;;;GAMG;AACH,KAAK,QAAQ,GACd,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,OAAO;AACL;;;;GAIG;AACH,SAAS;AACT;;;;GAIG;AACH,QAAQ;AACR;;;;GAIG;AACH,YAAY;AACZ;;;;GAIG;AACH,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,mBAAmB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ xrpc,
|
|
|
29
29
|
*/
|
|
30
30
|
xrpcSafe, } from '@atproto/lex-client';
|
|
31
31
|
export * from '@atproto/lex-client';
|
|
32
|
+
export * from '@atproto/lex-rpc/subscription';
|
|
32
33
|
export {
|
|
33
34
|
/**
|
|
34
35
|
* The {@link l} namespace (from `@atproto/lex-schema`) provides an imperative API for building schemas:
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACL;;;;GAIG;AACH,MAAM;AACN;;;;;;GAMG;AACH,IAAI;AACJ;;;;;;GAMG;AACH,QAAQ,GACT,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,CAAC,GACF,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAgBN,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,OAAO;AACL;;;;GAIG;AACH,SAAS;AACT;;;;GAIG;AACH,QAAQ;AACR;;;;GAIG;AACH,YAAY;AACZ;;;;GAIG;AACH,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,mBAAmB,CAAA","sourcesContent":["/**\n * The `@atproto/lex` package provides utilities for working with ATProtocol\n * lexicons, including data types, JSON and CBOR encoding/decoding, schema\n * validation, and HTTP client functionality.\n *\n * @packageDocumentation\n */\n\nexport {\n /**\n * The Client class is the primary interface for interacting with AT Protocol\n * services though an authenticated session. It provides methods for making\n * XRPC requests, handling records, and managing blobs.\n */\n Client,\n /**\n * The `xrpc` function is a low-level utility for making XRPC requests towards\n * a specific service. It allows for detailed control over the request,\n * including custom parameters, body, and headers. This function is useful for\n * advanced use cases where the higher-level `Client` methods may not provide\n * enough flexibility.\n */\n xrpc,\n /**\n * The `xrpcSafe` function is a wrapper around `xrpc` that provides additional\n * safety checks and error handling. It ensures that the request is properly\n * formed and that any errors are caught and handled gracefully. This function\n * is recommended for most use cases, as it provides a safer interface for\n * making XRPC requests.\n */\n xrpcSafe,\n} from '@atproto/lex-client'\nexport * from '@atproto/lex-client'\n\nexport {\n /**\n * The {@link l} namespace (from `@atproto/lex-schema`) provides an imperative API for building schemas:\n *\n * ### Primitive Types\n * - {@link l.string | l.string()} - String values with optional format/length constraints\n * - {@link l.integer | l.integer()} - Integer values with optional min/max constraints\n * - {@link l.boolean | l.boolean()} - Boolean values\n * - {@link l.bytes | l.bytes()} - Binary data (Uint8Array)\n * - {@link l.cid | l.cid()} - Content Identifier values\n * - {@link l.blob | l.blob()} - Blob references with mime type and size\n *\n * ### Composite Types\n * - {@link l.object | l.object()} - Objects with defined property schemas\n * - {@link l.array | l.array()} - Arrays with element type validation\n * - {@link l.union | l.union()} - Union of multiple possible types\n * - {@link l.ref | l.ref()} - Reference to another schema definition\n * - {@link l.literal | l.literal()} - Literal constant values\n * - {@link l.enum | l.enum()} - Enum of allowed string values\n * - {@link l.typedRef | l.typedRef()} - Reference to a {@link l.typedObject | l.typedObject()}\n * - {@link l.typedUnion | l.typedUnion()} - Discriminated union between multiple {@link l.typedRef | l.typedRef()} or {@link l.typedObject | l.typedObject()} types\n *\n * ### Modifiers\n * - {@link l.optional | l.optional()} - Mark a property as optional\n * - {@link l.nullable | l.nullable()} - Allow null values\n * - {@link l.withDefault | l.withDefault()} - Provide a default value\n *\n * ### Lexicon Definitions\n * - {@link l.typedObject | l.typedObject()} - Define a typed object with a `$type` property\n * - {@link l.record | l.record()} - Define a Lexicon record type\n * - {@link l.query | l.query()} - Define a Lexicon query method\n * - {@link l.procedure | l.procedure()} - Define a Lexicon procedure method\n * - {@link l.subscription | l.subscription()} - Define a Lexicon subscription method\n */\n l,\n} from '@atproto/lex-schema'\nexport * from '@atproto/lex-schema'\n\nexport {\n /**\n * The `LexMap` type represents an object with string keys and `LexValue` values.\n * It is used to represent arbitrary objects in Lexicon schemas, where the\n * properties are not predefined. This type allows for flexible data structures\n * while still ensuring that all values conform to the `LexValue` type.\n */\n type LexMap,\n /**\n * The `LexValue` type represents any valid value that can be used in a\n * Lexicon schema. It is a union of all the primitive and composite types\n * defined in `@atproto/lex-data`, including strings, integers, booleans,\n * bytes, CIDs, blob references, objects, arrays, and maps. This type is used\n * throughout the library to represent data that conforms to Lexicon schemas.\n */\n type LexValue,\n} from '@atproto/lex-data'\nexport * from '@atproto/lex-data'\n\nexport {\n /**\n * The `jsonToLex` function takes a plain JavaScript object (typically parsed from\n * JSON) and converts it back into a LexValue, reconstructing any complex types as needed. This is useful\n * for processing data received from the network or loaded from JSON storage.\n */\n jsonToLex,\n /**\n * The `lexParse` function takes a JSON string and parses it into a LexValue. It\n * performs the necessary conversions to reconstruct complex LexValue types from\n * their JSON representations.\n */\n lexParse,\n /**\n * The `lexStringify` function takes a LexValue and serializes it to a JSON string.\n * It handles the conversion of complex LexValue types (like BlobRef and Cid) into\n * a JSON-friendly format.\n */\n lexStringify,\n /**\n * The `lexToJson` function converts a LexValue into a plain JavaScript object\n * that can be safely serialized to JSON. This is useful for preparing data to be\n * sent over the network or stored in a JSON format.\n */\n lexToJson,\n} from '@atproto/lex-json'\nexport * from '@atproto/lex-json'\n\nexport * from '@atproto/lex-cbor'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO;AACL;;;;GAIG;AACH,MAAM;AACN;;;;;;GAMG;AACH,IAAI;AACJ;;;;;;GAMG;AACH,QAAQ,GACT,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,cAAc,+BAA+B,CAAA;AAE7C,OAAO;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,CAAC,GACF,MAAM,qBAAqB,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAgBN,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,OAAO;AACL;;;;GAIG;AACH,SAAS;AACT;;;;GAIG;AACH,QAAQ;AACR;;;;GAIG;AACH,YAAY;AACZ;;;;GAIG;AACH,SAAS,GACV,MAAM,mBAAmB,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,mBAAmB,CAAA","sourcesContent":["/**\n * The `@atproto/lex` package provides utilities for working with ATProtocol\n * lexicons, including data types, JSON and CBOR encoding/decoding, schema\n * validation, and HTTP client functionality.\n *\n * @packageDocumentation\n */\n\nexport {\n /**\n * The Client class is the primary interface for interacting with AT Protocol\n * services though an authenticated session. It provides methods for making\n * XRPC requests, handling records, and managing blobs.\n */\n Client,\n /**\n * The `xrpc` function is a low-level utility for making XRPC requests towards\n * a specific service. It allows for detailed control over the request,\n * including custom parameters, body, and headers. This function is useful for\n * advanced use cases where the higher-level `Client` methods may not provide\n * enough flexibility.\n */\n xrpc,\n /**\n * The `xrpcSafe` function is a wrapper around `xrpc` that provides additional\n * safety checks and error handling. It ensures that the request is properly\n * formed and that any errors are caught and handled gracefully. This function\n * is recommended for most use cases, as it provides a safer interface for\n * making XRPC requests.\n */\n xrpcSafe,\n} from '@atproto/lex-client'\nexport * from '@atproto/lex-client'\n\nexport * from '@atproto/lex-rpc/subscription'\n\nexport {\n /**\n * The {@link l} namespace (from `@atproto/lex-schema`) provides an imperative API for building schemas:\n *\n * ### Primitive Types\n * - {@link l.string | l.string()} - String values with optional format/length constraints\n * - {@link l.integer | l.integer()} - Integer values with optional min/max constraints\n * - {@link l.boolean | l.boolean()} - Boolean values\n * - {@link l.bytes | l.bytes()} - Binary data (Uint8Array)\n * - {@link l.cid | l.cid()} - Content Identifier values\n * - {@link l.blob | l.blob()} - Blob references with mime type and size\n *\n * ### Composite Types\n * - {@link l.object | l.object()} - Objects with defined property schemas\n * - {@link l.array | l.array()} - Arrays with element type validation\n * - {@link l.union | l.union()} - Union of multiple possible types\n * - {@link l.ref | l.ref()} - Reference to another schema definition\n * - {@link l.literal | l.literal()} - Literal constant values\n * - {@link l.enum | l.enum()} - Enum of allowed string values\n * - {@link l.typedRef | l.typedRef()} - Reference to a {@link l.typedObject | l.typedObject()}\n * - {@link l.typedUnion | l.typedUnion()} - Discriminated union between multiple {@link l.typedRef | l.typedRef()} or {@link l.typedObject | l.typedObject()} types\n *\n * ### Modifiers\n * - {@link l.optional | l.optional()} - Mark a property as optional\n * - {@link l.nullable | l.nullable()} - Allow null values\n * - {@link l.withDefault | l.withDefault()} - Provide a default value\n *\n * ### Lexicon Definitions\n * - {@link l.typedObject | l.typedObject()} - Define a typed object with a `$type` property\n * - {@link l.record | l.record()} - Define a Lexicon record type\n * - {@link l.query | l.query()} - Define a Lexicon query method\n * - {@link l.procedure | l.procedure()} - Define a Lexicon procedure method\n * - {@link l.subscription | l.subscription()} - Define a Lexicon subscription method\n */\n l,\n} from '@atproto/lex-schema'\nexport * from '@atproto/lex-schema'\n\nexport {\n /**\n * The `LexMap` type represents an object with string keys and `LexValue` values.\n * It is used to represent arbitrary objects in Lexicon schemas, where the\n * properties are not predefined. This type allows for flexible data structures\n * while still ensuring that all values conform to the `LexValue` type.\n */\n type LexMap,\n /**\n * The `LexValue` type represents any valid value that can be used in a\n * Lexicon schema. It is a union of all the primitive and composite types\n * defined in `@atproto/lex-data`, including strings, integers, booleans,\n * bytes, CIDs, blob references, objects, arrays, and maps. This type is used\n * throughout the library to represent data that conforms to Lexicon schemas.\n */\n type LexValue,\n} from '@atproto/lex-data'\nexport * from '@atproto/lex-data'\n\nexport {\n /**\n * The `jsonToLex` function takes a plain JavaScript object (typically parsed from\n * JSON) and converts it back into a LexValue, reconstructing any complex types as needed. This is useful\n * for processing data received from the network or loaded from JSON storage.\n */\n jsonToLex,\n /**\n * The `lexParse` function takes a JSON string and parses it into a LexValue. It\n * performs the necessary conversions to reconstruct complex LexValue types from\n * their JSON representations.\n */\n lexParse,\n /**\n * The `lexStringify` function takes a LexValue and serializes it to a JSON string.\n * It handles the conversion of complex LexValue types (like BlobRef and Cid) into\n * a JSON-friendly format.\n */\n lexStringify,\n /**\n * The `lexToJson` function converts a LexValue into a plain JavaScript object\n * that can be safely serialized to JSON. This is useful for preparing data to be\n * sent over the network or stored in a JSON format.\n */\n lexToJson,\n} from '@atproto/lex-json'\nexport * from '@atproto/lex-json'\n\nexport * from '@atproto/lex-cbor'\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Lexicon tooling for AT",
|
|
6
6
|
"keywords": [
|
|
@@ -36,25 +36,25 @@
|
|
|
36
36
|
"node": ">=22"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atproto/lex-builder": "^0.1.
|
|
40
|
-
"@atproto/lex-cbor": "^0.1.
|
|
41
|
-
"@atproto/lex-client": "^0.
|
|
42
|
-
"@atproto/lex-data": "^0.1.
|
|
43
|
-
"@atproto/lex-json": "^0.1.
|
|
44
|
-
"@atproto/lex-installer": "^0.2.
|
|
45
|
-
"@atproto/lex-
|
|
39
|
+
"@atproto/lex-builder": "^0.1.21",
|
|
40
|
+
"@atproto/lex-cbor": "^0.1.11",
|
|
41
|
+
"@atproto/lex-client": "^0.6.0",
|
|
42
|
+
"@atproto/lex-data": "^0.1.11",
|
|
43
|
+
"@atproto/lex-json": "^0.1.10",
|
|
44
|
+
"@atproto/lex-installer": "^0.2.10",
|
|
45
|
+
"@atproto/lex-rpc": "^0.2.0",
|
|
46
|
+
"@atproto/lex-schema": "^0.3.0",
|
|
46
47
|
"tslib": "^2.8.1",
|
|
47
48
|
"yargs": "^18.2.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"@types/yargs": "^17.0.33",
|
|
51
|
-
"vitest": "^
|
|
52
|
+
"vitest": "^5.1.1"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
55
|
"codegen:lex": "./bin/lex build --override --indexFile --lexicons ./lexicons --out ./tests/lexicons --lib @atproto/lex-schema",
|
|
55
56
|
"prebuild": "pnpm run '/^(codegen:.+)$/'",
|
|
56
57
|
"build": "tsc --build tsconfig.build.json",
|
|
57
|
-
"test": "vitest run"
|
|
58
|
-
"verify:declarations": "node ./verify-declarations.mjs"
|
|
58
|
+
"test": "vitest run"
|
|
59
59
|
}
|
|
60
60
|
}
|