@atproto/lex 0.0.21 → 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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +50 -4
  3. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
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
+
3
15
  ## 0.0.21
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -326,7 +326,7 @@ const result = app.bsky.feed.post.$validate(value)
326
326
  value === result // true
327
327
  ```
328
328
 
329
- #### `$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
330
330
 
331
331
  Returns a detailed validation result object without throwing:
332
332
 
@@ -347,6 +347,16 @@ if (result.success) {
347
347
  }
348
348
  ```
349
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
+
350
360
  #### `$build(data)` - Build with Defaults
351
361
 
352
362
  Builds data without needing to specify the `$type` property, and properly types the result:
@@ -506,6 +516,8 @@ if (result.success) {
506
516
  }
507
517
  ```
508
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
+
509
521
  ## Client API
510
522
 
511
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.
@@ -574,6 +586,29 @@ const client = new Client(session, {
574
586
  })
575
587
  ```
576
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
+
577
612
  ### Core Methods
578
613
 
579
614
  #### `client.call()`
@@ -603,7 +638,6 @@ const timeline = await client.call(
603
638
  },
604
639
  {
605
640
  signal: abortSignal,
606
- headers: { 'custom-header': 'value' },
607
641
  },
608
642
  )
609
643
  ```
@@ -857,6 +891,16 @@ console.log(response.headers)
857
891
  console.log(response.body)
858
892
  ```
859
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
+
860
904
  ## Utilities
861
905
 
862
906
  Various utilities for working with CIDs, datetime strings, string lengths, language tags, and low-level JSON encoding are exported from the package:
@@ -1001,12 +1045,14 @@ if (isBlobRef(blobRef)) {
1001
1045
  >
1002
1046
  > ```typescript
1003
1047
  > type LegacyBlobRef = {
1004
- > ref: string
1048
+ > cid: string
1005
1049
  > mimeType: string
1006
1050
  > }
1007
1051
  > ```
1008
1052
  >
1009
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`.
1010
1056
 
1011
1057
  ### Actions
1012
1058
 
@@ -1028,7 +1074,7 @@ Actions receive:
1028
1074
 
1029
1075
  - `client` - The Client instance (to make XRPC calls)
1030
1076
  - `input` - The input data for the action
1031
- - `options` - Call options (signal, headers)
1077
+ - `options` - Call options (signal)
1032
1078
 
1033
1079
  #### Using Actions
1034
1080
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex",
3
- "version": "0.0.21",
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.18",
42
- "@atproto/lex-client": "^0.0.16",
43
- "@atproto/lex-data": "^0.0.13",
44
- "@atproto/lex-json": "^0.0.13",
45
- "@atproto/lex-installer": "^0.0.21",
46
- "@atproto/lex-schema": "^0.0.15"
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",