@atproto/lex 0.0.11 → 0.0.13

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 CHANGED
@@ -1,5 +1,32 @@
1
1
  # @atproto/lex
2
2
 
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atproto/lex-installer@0.0.13
9
+
10
+ ## 0.0.12
11
+
12
+ ### Patch Changes
13
+
14
+ - [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `TypedObject` to `Unknown$TypedObject`
15
+
16
+ - [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix inability to assign (object containing) open union results to `LexMap` type
17
+
18
+ - [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add new `Unknown$Type` type to represent records an object's unknown `$type` property (typically from open unions).
19
+
20
+ - [#4562](https://github.com/bluesky-social/atproto/pull/4562) [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `UnknownObjectOutput` to `UnknownObject`
21
+
22
+ - Updated dependencies [[`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`aaedafc`](https://github.com/bluesky-social/atproto/commit/aaedafc6baef106b85e0954d8474cec21c00c1c2), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b)]:
23
+ - @atproto/lex-schema@0.0.10
24
+ - @atproto/lex-client@0.0.10
25
+ - @atproto/lex-json@0.0.9
26
+ - @atproto/lex-data@0.0.9
27
+ - @atproto/lex-builder@0.0.12
28
+ - @atproto/lex-installer@0.0.12
29
+
3
30
  ## 0.0.11
4
31
 
5
32
  ### Patch Changes
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  Dual MIT/Apache-2.0 License
2
2
 
3
- Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors
3
+ Copyright (c) 2022-2026 Bluesky Social PBC, and Contributors
4
4
 
5
5
  Except as otherwise noted in individual files, this software is licensed under the MIT license (<http://opensource.org/licenses/MIT>), or the Apache License, Version 2.0 (<http://www.apache.org/licenses/LICENSE-2.0>).
6
6
 
package/README.md CHANGED
@@ -304,16 +304,35 @@ try {
304
304
 
305
305
  > [!NOTE]
306
306
  >
307
- > The `$parse` method will apply defaults defined in the schema for optional fields, as well as data coercion (e.g., CID strings to Cid types). This means that the returned value might be different from the input data if defaults were applied. Disable this behavior by passing `{ allowTransform: false }` as the second argument to `$parse()`.
307
+ > The `$parse` method will apply defaults defined in the schema for optional fields, as well as data coercion (e.g., CID strings to Cid types). This means that the returned value might be different from the input data if defaults were applied. Use `$validate()` for value validation.
308
308
 
309
- #### `$validate(data)` - Get Validation Result
309
+ #### `$validate(data)` - Validate a value against the schema
310
+
311
+ Validates an existing value against a schema, returning the value itself if, and only if, it already matches the schema (ie. without applying defaults or coercion).
312
+
313
+ ```typescript
314
+ import * as app from './lexicons/app.js'
315
+
316
+ const value = {
317
+ $type: 'app.bsky.feed.post',
318
+ text: 'Hello!',
319
+ createdAt: new Date().toISOString(),
320
+ }
321
+
322
+ // Throws if no valid
323
+ const result = app.bsky.feed.post.$validate(value)
324
+
325
+ value === result // true
326
+ ```
327
+
328
+ #### `$safeParse(data)` - Parse a value against a schema and get the resulting value
310
329
 
311
330
  Returns a detailed validation result object without throwing:
312
331
 
313
332
  ```typescript
314
333
  import * as app from './lexicons/app.js'
315
334
 
316
- const result = app.bsky.feed.post.$validate({
335
+ const result = app.bsky.feed.post.$safeParse({
317
336
  $type: 'app.bsky.feed.post',
318
337
  text: 'Hello!',
319
338
  createdAt: new Date().toISOString(),
@@ -326,10 +345,6 @@ if (result.success) {
326
345
  }
327
346
  ```
328
347
 
329
- > [!NOTE]
330
- >
331
- > Like `$parse`, the `$validate` method will apply defaults and coercion. Disable this behavior by passing `{ allowTransform: false }` as the second argument to `$validate()`.
332
-
333
348
  #### `$build(data)` - Build with Defaults
334
349
 
335
350
  Builds data without needing to specify the `$type` property, and properly types the result:
@@ -358,7 +373,7 @@ import * as app from './lexicons/app.js'
358
373
  declare const data:
359
374
  | app.bsky.feed.post.Main
360
375
  | app.bsky.feed.like.Main
361
- | l.TypedObject
376
+ | l.Unknown$TypedObject
362
377
 
363
378
  // Discriminate by $type without re-validating
364
379
  if (app.bsky.feed.post.$isTypeOf(data)) {
@@ -853,7 +868,7 @@ if (result.success) {
853
868
  if (result.error === 'Unknown') {
854
869
  // Unable to perform the request
855
870
  const { reason } = result
856
- if (reason instanceof LexRpcResponseError) {
871
+ if (reason instanceof XrpcResponseError) {
857
872
  // The server returned a syntactically valid XRPC error response, but
858
873
  // used an error code that is not declared for this method
859
874
  reason.error // string (e.g. "AuthenticationRequired", "RateLimitExceeded", etc.)
@@ -861,7 +876,7 @@ if (result.success) {
861
876
  reason.status // number
862
877
  reason.headers // Headers
863
878
  reason.payload // { body: { error: string, message?: string }; encoding: string }
864
- } else if (reason instanceof LexRpcUpstreamError) {
879
+ } else if (reason instanceof XrpcUpstreamError) {
865
880
  // The response was incomplete (e.g. connection dropped), or
866
881
  // invalid (e.g. malformed JSON, data does not match schema).
867
882
  reason.error // "InvalidResponse"
@@ -874,7 +889,7 @@ if (result.success) {
874
889
  }
875
890
  } else {
876
891
  // A declared error for that method
877
- result // LexRpcResponseError<"HandleNotFound">
892
+ result // XrpcResponseError<"HandleNotFound">
878
893
  result.error // "HandleNotFound"
879
894
  result.message // string
880
895
  }
@@ -883,14 +898,14 @@ if (result.success) {
883
898
 
884
899
  The `ResponseFailure<M>` type is a union with three possible error types:
885
900
 
886
- 1. **Declared errors** - Errors explicitly listed in the method's Lexicon schema will be represented as an `LexRpcResponseError<N>` instance:
901
+ 1. **Declared errors** - Errors explicitly listed in the method's Lexicon schema will be represented as an `XrpcResponseError<N>` instance:
887
902
 
888
903
  ```typescript
889
- // LexRpcResponseError<N>
904
+ // XrpcResponseError<N>
890
905
  type KnownLexRpcResponseFailure<N extends string> = {
891
906
  success: false
892
907
  name: N
893
- error: LexRpcResponseError<N>
908
+ error: XrpcResponseError<N>
894
909
 
895
910
  // Additional response details
896
911
  status: number
@@ -903,11 +918,11 @@ The `ResponseFailure<M>` type is a union with three possible error types:
903
918
  2. **Unknown errors** - Server errors not declared in the method's schema:
904
919
 
905
920
  ```typescript
906
- // LexRpcResponseFailure<'Unexpected', LexRpcResponseError>
921
+ // LexRpcResponseFailure<'Unexpected', XrpcResponseError>
907
922
  type UnknownLexRpcResponseFailure = {
908
923
  success: false
909
924
  name: 'Unexpected'
910
- error: LexRpcResponseError<string>
925
+ error: XrpcResponseError<string>
911
926
  }
912
927
  ```
913
928
 
@@ -1516,7 +1531,7 @@ await client.call(unfollow, { followUri: uri })
1516
1531
  #### Updating Profile with Retry Logic
1517
1532
 
1518
1533
  ```typescript
1519
- import { Action, LexRpcResponseError } from '@atproto/lex'
1534
+ import { Action, XrpcResponseError } from '@atproto/lex'
1520
1535
  import * as app from './lexicons/app.js'
1521
1536
  import * as com from './lexicons/com.js'
1522
1537
 
@@ -1558,7 +1573,7 @@ export const updateProfile: Action<ProfileUpdate, void> = async (
1558
1573
  } catch (error) {
1559
1574
  // Retry on swap/concurrent modification errors
1560
1575
  if (
1561
- error instanceof LexRpcResponseError &&
1576
+ error instanceof XrpcResponseError &&
1562
1577
  error.name === 'SwapError' &&
1563
1578
  attempt < maxRetries - 1
1564
1579
  ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "description": "Lexicon tooling for AT",
6
6
  "keywords": [
@@ -36,12 +36,12 @@
36
36
  "dependencies": {
37
37
  "tslib": "^2.8.1",
38
38
  "yargs": "^17.0.0",
39
- "@atproto/lex-builder": "0.0.11",
40
- "@atproto/lex-client": "0.0.9",
41
- "@atproto/lex-data": "0.0.8",
42
- "@atproto/lex-json": "0.0.8",
43
- "@atproto/lex-installer": "0.0.11",
44
- "@atproto/lex-schema": "0.0.9"
39
+ "@atproto/lex-builder": "0.0.12",
40
+ "@atproto/lex-client": "0.0.10",
41
+ "@atproto/lex-json": "0.0.9",
42
+ "@atproto/lex-installer": "0.0.13",
43
+ "@atproto/lex-schema": "0.0.10",
44
+ "@atproto/lex-data": "0.0.9"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/yargs": "^17.0.33",