@atproto/lex 0.0.20 → 0.0.22
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 +22 -0
- package/README.md +79 -5
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @atproto/lex
|
|
2
2
|
|
|
3
|
+
## 0.0.22
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`6a88461`](https://github.com/bluesky-social/atproto/commit/6a88461c5aa9486269f0769b7a3d52f384581786), [`6a88461`](https://github.com/bluesky-social/atproto/commit/6a88461c5aa9486269f0769b7a3d52f384581786), [`df8328c`](https://github.com/bluesky-social/atproto/commit/df8328c3c2f211fe16ccf58fa9f3968465cbf2b0), [`6a88461`](https://github.com/bluesky-social/atproto/commit/6a88461c5aa9486269f0769b7a3d52f384581786), [`6a88461`](https://github.com/bluesky-social/atproto/commit/6a88461c5aa9486269f0769b7a3d52f384581786), [`6a88461`](https://github.com/bluesky-social/atproto/commit/6a88461c5aa9486269f0769b7a3d52f384581786)]:
|
|
8
|
+
- @atproto/lex-client@0.0.17
|
|
9
|
+
- @atproto/lex-schema@0.0.16
|
|
10
|
+
- @atproto/lex-data@0.0.14
|
|
11
|
+
- @atproto/lex-builder@0.0.19
|
|
12
|
+
- @atproto/lex-installer@0.0.22
|
|
13
|
+
- @atproto/lex-json@0.0.14
|
|
14
|
+
|
|
15
|
+
## 0.0.21
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`5a2f884`](https://github.com/bluesky-social/atproto/commit/5a2f8847efd91252971fa243d21bd52ada7aa8f4), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe), [`112b159`](https://github.com/bluesky-social/atproto/commit/112b159ec293a5c3fff41237474a3788fc47f9ca), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe), [`3dc3791`](https://github.com/bluesky-social/atproto/commit/3dc37915436dec7e18c7dc9dcf01b72cad53fdbe)]:
|
|
20
|
+
- @atproto/lex-client@0.0.16
|
|
21
|
+
- @atproto/lex-schema@0.0.15
|
|
22
|
+
- @atproto/lex-builder@0.0.18
|
|
23
|
+
- @atproto/lex-installer@0.0.21
|
|
24
|
+
|
|
3
25
|
## 0.0.20
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ const newPost = app.bsky.feed.post.$build({
|
|
|
20
20
|
app.bsky.actor.profile.$validate({
|
|
21
21
|
$type: 'app.bsky.actor.profile',
|
|
22
22
|
displayName: 'Ha'.repeat(32) + '!',
|
|
23
|
-
}) // Error: grapheme too big (maximum 64) at $.displayName
|
|
23
|
+
}) // Error: grapheme too big (maximum 64, got 65) at $.displayName
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
@@ -75,6 +75,7 @@ const posts = await client.list(app.bsky.feed.post, { limit: 10 })
|
|
|
75
75
|
- [Actions](#actions)
|
|
76
76
|
- [Creating a Client from Another Client](#creating-a-client-from-another-client)
|
|
77
77
|
- [Building Library-Style APIs with Actions](#building-library-style-apis-with-actions)
|
|
78
|
+
- [Standard Schema Compatibility](#standard-schema-compatibility)
|
|
78
79
|
- [License](#license)
|
|
79
80
|
|
|
80
81
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -325,7 +326,7 @@ const result = app.bsky.feed.post.$validate(value)
|
|
|
325
326
|
value === result // true
|
|
326
327
|
```
|
|
327
328
|
|
|
328
|
-
#### `$safeParse(data)` - Parse a value against a schema and get the resulting value
|
|
329
|
+
#### `$safeParse(data, options?)` - Parse a value against a schema and get the resulting value
|
|
329
330
|
|
|
330
331
|
Returns a detailed validation result object without throwing:
|
|
331
332
|
|
|
@@ -346,6 +347,16 @@ if (result.success) {
|
|
|
346
347
|
}
|
|
347
348
|
```
|
|
348
349
|
|
|
350
|
+
All schema methods that perform validation (`$parse`, `$safeParse`, `$validate`, `$safeValidate`) accept an optional `{ strict }` option. When `strict` is `false`, validation becomes more lenient: datetime string format checks are relaxed (e.g. datetimes without timezones are accepted; other string formats remain strict), blob MIME type and size constraints are not enforced, and non-raw CIDs are allowed in blob references. This is primarily used internally by the XRPC client when `strictResponseProcessing` is disabled, but can also be used directly:
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
// Strict mode (default) - rejects datetime without timezone
|
|
354
|
+
app.bsky.feed.post.$safeParse(data) // { strict: true } is the default
|
|
355
|
+
|
|
356
|
+
// Non-strict mode - accepts more lenient data
|
|
357
|
+
app.bsky.feed.post.$safeParse(data, { strict: false })
|
|
358
|
+
```
|
|
359
|
+
|
|
349
360
|
#### `$build(data)` - Build with Defaults
|
|
350
361
|
|
|
351
362
|
Builds data without needing to specify the `$type` property, and properly types the result:
|
|
@@ -505,6 +516,8 @@ if (result.success) {
|
|
|
505
516
|
}
|
|
506
517
|
```
|
|
507
518
|
|
|
519
|
+
Both `xrpc()` and `xrpcSafe()` accept `validateRequest`, `validateResponse`, and `strictResponseProcessing` options to control validation and strictness per-call. See [Validation and Strictness Options](#validation-and-strictness-options) for details.
|
|
520
|
+
|
|
508
521
|
## Client API
|
|
509
522
|
|
|
510
523
|
The `Client` class provides high-level helpers for common AT Protocol "repo" operations: `create()`, `get()`, `put()`, `delete()`, `list()`, `uploadBlob()`, and more. A `Client` instance is typically useful for making requests in the context of an authenticated user session, as it automatically handles headers and provides default values based on the authenticated user's DID.
|
|
@@ -573,6 +586,29 @@ const client = new Client(session, {
|
|
|
573
586
|
})
|
|
574
587
|
```
|
|
575
588
|
|
|
589
|
+
#### Validation and Strictness Options
|
|
590
|
+
|
|
591
|
+
The `Client` constructor accepts options to control request/response validation and how invalid Lex data is handled. These defaults apply to all XRPC calls made through the client, and can be overridden per-call via `client.call()`, `client.xrpc()` or `client.xrpcSafe()`.
|
|
592
|
+
|
|
593
|
+
```typescript
|
|
594
|
+
const client = new Client(session, {
|
|
595
|
+
// Validate requests against the method's input schema (default: false)
|
|
596
|
+
validateRequest: true,
|
|
597
|
+
|
|
598
|
+
// Validate responses against the method's output schema (default: true)
|
|
599
|
+
validateResponse: true,
|
|
600
|
+
|
|
601
|
+
// Strictly process responses according to Lex encoding rules. When set to
|
|
602
|
+
// false, accepts responses containing invalid Lex data such as floats or
|
|
603
|
+
// malformed $bytes/$link objects (default: true)
|
|
604
|
+
strictResponseProcessing: false,
|
|
605
|
+
})
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
- **`validateRequest`** — When `true`, outgoing request bodies are validated against the Lexicon input schema before sending. Useful in development to catch errors early. Default: `false`.
|
|
609
|
+
- **`validateResponse`** — When `true`, incoming response bodies are validated against the Lexicon output schema. Disabling this can improve performance when you trust the upstream service. Default: `true`.
|
|
610
|
+
- **`strictResponseProcessing`** — When `true` (default), the client will strictly process responses according to Lex encoding rules, rejecting responses containing invalid Lex data (e.g. floating-point numbers, malformed `$bytes` or `$link` objects). When `false`, the client accepts such responses in a lenient mode: invalid values are returned as-is rather than being rejected or converted, `datetime` string format checks become more lenient (e.g. datetimes without timezones are accepted) while other string formats remain strict, blob MIME type and size constraints are not enforced, and legacy blob references are coerced into standard `BlobRef` objects. Default: `true`.
|
|
611
|
+
|
|
576
612
|
### Core Methods
|
|
577
613
|
|
|
578
614
|
#### `client.call()`
|
|
@@ -602,7 +638,6 @@ const timeline = await client.call(
|
|
|
602
638
|
},
|
|
603
639
|
{
|
|
604
640
|
signal: abortSignal,
|
|
605
|
-
headers: { 'custom-header': 'value' },
|
|
606
641
|
},
|
|
607
642
|
)
|
|
608
643
|
```
|
|
@@ -856,6 +891,16 @@ console.log(response.headers)
|
|
|
856
891
|
console.log(response.body)
|
|
857
892
|
```
|
|
858
893
|
|
|
894
|
+
Validation and strictness options (`validateRequest`, `validateResponse`, `strictResponseProcessing`) can also be passed per-call to override the client defaults:
|
|
895
|
+
|
|
896
|
+
```typescript
|
|
897
|
+
const response = await client.xrpc(app.bsky.feed.getTimeline, {
|
|
898
|
+
params: { limit: 50 },
|
|
899
|
+
strictResponseProcessing: false, // Accept non-strict Lex data for this call
|
|
900
|
+
validateResponse: false, // Skip schema validation for this call
|
|
901
|
+
})
|
|
902
|
+
```
|
|
903
|
+
|
|
859
904
|
## Utilities
|
|
860
905
|
|
|
861
906
|
Various utilities for working with CIDs, datetime strings, string lengths, language tags, and low-level JSON encoding are exported from the package:
|
|
@@ -1000,12 +1045,14 @@ if (isBlobRef(blobRef)) {
|
|
|
1000
1045
|
>
|
|
1001
1046
|
> ```typescript
|
|
1002
1047
|
> type LegacyBlobRef = {
|
|
1003
|
-
>
|
|
1048
|
+
> cid: string
|
|
1004
1049
|
> mimeType: string
|
|
1005
1050
|
> }
|
|
1006
1051
|
> ```
|
|
1007
1052
|
>
|
|
1008
1053
|
> These should no longer be used for new records, but existing records using this format might still be encountered. To handle legacy blob references when validating data, enable the `--allowLegacyBlobs` flag when generating TypeScript schemas with `lex build`. You can use `isLegacyBlobRef()` from `@atproto/lex` to discriminate legacy blob references.
|
|
1054
|
+
>
|
|
1055
|
+
> When using non-strict validation (e.g. `$safeParse(data, { strict: false })`), legacy blob references are automatically coerced into standard `BlobRef` objects with `size: -1`, even without `--allowLegacyBlobs`.
|
|
1009
1056
|
|
|
1010
1057
|
### Actions
|
|
1011
1058
|
|
|
@@ -1027,7 +1074,7 @@ Actions receive:
|
|
|
1027
1074
|
|
|
1028
1075
|
- `client` - The Client instance (to make XRPC calls)
|
|
1029
1076
|
- `input` - The input data for the action
|
|
1030
|
-
- `options` - Call options (signal
|
|
1077
|
+
- `options` - Call options (signal)
|
|
1031
1078
|
|
|
1032
1079
|
#### Using Actions
|
|
1033
1080
|
|
|
@@ -1423,6 +1470,33 @@ await client.call(actions.post, { text: 'Hello!' })
|
|
|
1423
1470
|
5. **Retries**: Implement retry logic for operations with optimistic concurrency control
|
|
1424
1471
|
6. **Tree-shaking**: Export actions individually to allow tree-shaking (instead of bundling them in a single class)
|
|
1425
1472
|
|
|
1473
|
+
### Standard Schema Compatibility
|
|
1474
|
+
|
|
1475
|
+
All generated schemas implement the [Standard Schema](https://standardschema.dev/) interface (`StandardSchemaV1`), which means they can be used with any library or framework that supports Standard Schema, such as form validation libraries, API frameworks, and more.
|
|
1476
|
+
|
|
1477
|
+
Every `Schema` instance exposes a `~standard` property conforming to the spec:
|
|
1478
|
+
|
|
1479
|
+
```typescript
|
|
1480
|
+
import * as app from './lexicons/app.js'
|
|
1481
|
+
|
|
1482
|
+
// Use with any Standard Schema-compatible library
|
|
1483
|
+
const schema = app.bsky.feed.post
|
|
1484
|
+
|
|
1485
|
+
schema['~standard'].version // 1
|
|
1486
|
+
schema['~standard'].vendor // '@atproto/lex-schema'
|
|
1487
|
+
|
|
1488
|
+
// Validate using the Standard Schema interface
|
|
1489
|
+
const result = schema['~standard'].validate(someData)
|
|
1490
|
+
|
|
1491
|
+
if ('value' in result) {
|
|
1492
|
+
console.log(result.value) // Parsed and validated data
|
|
1493
|
+
} else {
|
|
1494
|
+
console.error(result.issues)
|
|
1495
|
+
}
|
|
1496
|
+
```
|
|
1497
|
+
|
|
1498
|
+
When validated through the Standard Schema interface, schemas operate in "parse" mode, meaning transformations like defaults and coercions are applied to the output.
|
|
1499
|
+
|
|
1426
1500
|
## License
|
|
1427
1501
|
|
|
1428
1502
|
MIT or Apache2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Lexicon tooling for AT",
|
|
6
6
|
"keywords": [
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"tslib": "^2.8.1",
|
|
40
40
|
"yargs": "^17.0.0",
|
|
41
|
-
"@atproto/lex-builder": "^0.0.
|
|
42
|
-
"@atproto/lex-client": "^0.0.
|
|
43
|
-
"@atproto/lex-data": "^0.0.
|
|
44
|
-
"@atproto/lex-json": "^0.0.
|
|
45
|
-
"@atproto/lex-installer": "^0.0.
|
|
46
|
-
"@atproto/lex-schema": "^0.0.
|
|
41
|
+
"@atproto/lex-builder": "^0.0.19",
|
|
42
|
+
"@atproto/lex-client": "^0.0.17",
|
|
43
|
+
"@atproto/lex-data": "^0.0.14",
|
|
44
|
+
"@atproto/lex-json": "^0.0.14",
|
|
45
|
+
"@atproto/lex-installer": "^0.0.22",
|
|
46
|
+
"@atproto/lex-schema": "^0.0.16"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/yargs": "^17.0.33",
|