@atproto/lex 0.0.3 → 0.0.5

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 (4) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +43 -18
  3. package/bin/lex +19 -25
  4. package/package.json +7 -6
package/CHANGELOG.md ADDED
@@ -0,0 +1,73 @@
1
+ # @atproto/lex
2
+
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rework object validation logic to work without `options` argument
8
+
9
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Replace use of `CID` with `Cid`
10
+
11
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename schema methods `validate`, `check` and `maybe` to `safeParse`, `matches` and `ifMatches` respectively.
12
+
13
+ - [#4397](https://github.com/bluesky-social/atproto/pull/4397) [`688f9d6`](https://github.com/bluesky-social/atproto/commit/688f9d67597ba96d6e9c4a4aec4d394d42f4cbf4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `CHANGELOG.md` to npm package
14
+
15
+ - [#4398](https://github.com/bluesky-social/atproto/pull/4398) [`a17d2e8`](https://github.com/bluesky-social/atproto/commit/a17d2e8a59ceb00fa8197642e0767fcc776d5b70) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `ignoreInvalidLexicons` option when building lexicon schemas
16
+
17
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `default` option to `const` and `enum` schemas
18
+
19
+ - Updated dependencies [[`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`2d13d05`](https://github.com/bluesky-social/atproto/commit/2d13d05ab06576703742b1b638d2f243b6b2915f), [`d396de0`](https://github.com/bluesky-social/atproto/commit/d396de016d1d55d08cfad1dabd3ffd9eaeea76ea), [`0f2fc65`](https://github.com/bluesky-social/atproto/commit/0f2fc6592f0c89d26ac7a2ef70b12cbd15a18d05), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69), [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`9f87ff3`](https://github.com/bluesky-social/atproto/commit/9f87ff3aa60090c8c38b6ce400cba6ceff5cd2e9), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`688f9d6`](https://github.com/bluesky-social/atproto/commit/688f9d67597ba96d6e9c4a4aec4d394d42f4cbf4), [`a17d2e8`](https://github.com/bluesky-social/atproto/commit/a17d2e8a59ceb00fa8197642e0767fcc776d5b70), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba)]:
20
+ - @atproto/lex-schema@0.0.3
21
+ - @atproto/lex-installer@0.0.5
22
+ - @atproto/lex-builder@0.0.5
23
+ - @atproto/lex-client@0.0.3
24
+
25
+ ## 0.0.4
26
+
27
+ ### Patch Changes
28
+
29
+ - [#4380](https://github.com/bluesky-social/atproto/pull/4380) [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix description of `--allowLegacyBlobs` argument
30
+
31
+ - [#4380](https://github.com/bluesky-social/atproto/pull/4380) [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `--build`/`--no-build` argument from the `install` command
32
+
33
+ - [#4380](https://github.com/bluesky-social/atproto/pull/4380) [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add ability to configure file extenstion and import file extension in `lex build`
34
+
35
+ - Updated dependencies [[`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4), [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4), [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4)]:
36
+ - @atproto/lex-schema@0.0.2
37
+ - @atproto/lex-builder@0.0.4
38
+ - @atproto/lex-installer@0.0.4
39
+ - @atproto/lex-client@0.0.2
40
+
41
+ ## 0.0.3
42
+
43
+ ### Patch Changes
44
+
45
+ - [#4374](https://github.com/bluesky-social/atproto/pull/4374) [`5ffd612`](https://github.com/bluesky-social/atproto/commit/5ffd6129909071e979c30f31266119865ab582b6) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add missing files from package.json
46
+
47
+ - Updated dependencies []:
48
+ - @atproto/lex-builder@0.0.3
49
+ - @atproto/lex-installer@0.0.3
50
+ - @atproto/lex-client@0.0.1
51
+
52
+ ## 0.0.2
53
+
54
+ ### Patch Changes
55
+
56
+ - [#4372](https://github.com/bluesky-social/atproto/pull/4372) [`7456f53`](https://github.com/bluesky-social/atproto/commit/7456f53e45fb3eef2f3bbdf2513da2d8ab078d80) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix error when running `install` command
57
+
58
+ - Updated dependencies [[`7456f53`](https://github.com/bluesky-social/atproto/commit/7456f53e45fb3eef2f3bbdf2513da2d8ab078d80)]:
59
+ - @atproto/lex-builder@0.0.2
60
+ - @atproto/lex-client@0.0.1
61
+ - @atproto/lex-installer@0.0.2
62
+
63
+ ## 0.0.1
64
+
65
+ ### Patch Changes
66
+
67
+ - [#4371](https://github.com/bluesky-social/atproto/pull/4371) [`46550d6`](https://github.com/bluesky-social/atproto/commit/46550d6c1ffb298f57d54eb1904067b2df5a40af) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Release
68
+
69
+ - Updated dependencies [[`46550d6`](https://github.com/bluesky-social/atproto/commit/46550d6c1ffb298f57d54eb1904067b2df5a40af)]:
70
+ - @atproto/lex-builder@0.0.1
71
+ - @atproto/lex-client@0.0.1
72
+ - @atproto/lex-installer@0.0.1
73
+ - @atproto/lex-schema@0.0.1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @atproto/lex
2
2
 
3
- Type-safe Lexicon tooling for creating great API clients.
3
+ Type-safe Lexicon tooling for creating great API clients. See the [Changelog](./CHANGELOG.md) for version history.
4
4
 
5
5
  ```bash
6
6
  npm install -g @atproto/lex
@@ -11,6 +11,10 @@ lex --help
11
11
  - Generate TypeScript client and data validators
12
12
  - Handle common tasks like OAuth
13
13
 
14
+ > [!IMPORTANT]
15
+ >
16
+ > This package is currently in **preview**. The API and features are subject to change before the stable release.
17
+
14
18
  **What is this?**
15
19
 
16
20
  Working directly with XRPC endpoints requires manually tracking schema definitions, validation data structures, and managing authentication. `@atproto/lex` automates this by:
@@ -94,16 +98,35 @@ This creates:
94
98
  Make sure to commit the `lexicons.json` manifest and the `lexicons/` directory containing the JSON files to version control.
95
99
 
96
100
  ```bash
97
- echo "./src/lexicons" >> .gitignore
98
101
  git add lexicons.json lexicons/
99
102
  git commit -m "Install Lexicons"
100
103
  ```
101
104
 
105
+ **3. Build TypeScript schemas**
106
+
107
+ Generate TypeScript schemas from the installed Lexicons:
108
+
109
+ ```bash
110
+ lex build
111
+ ```
112
+
113
+ This generates TypeScript files in `./src/lexicons` (by default) with type-safe validation, type guards, and builder utilities.
114
+
115
+ > [!TIP]
116
+ >
117
+ > If you wish to customize the output location or any other build options, pass the appropriate flags to the `lex build` command. See the [TypeScript Schemas](#typescript-schemas) section for available options.
118
+
102
119
  > [!NOTE]
103
120
  >
104
- > The generated TypeScript files don't need to be committed to version control. Instead, they can be pre-built during your project's build step or post-install step. See [Workflow Integration](#workflow-integration) for details.
121
+ > The generated TypeScript files don't need to be committed to version control. Instead, they can be generated during your project's build step. See [Workflow Integration](#workflow-integration) for details.
122
+ >
123
+ > To avoid committing generated files, add the output directory to your `.gitignore`:
124
+ >
125
+ > ```bash
126
+ > echo "./src/lexicons" >> .gitignore
127
+ > ```
105
128
 
106
- **3. Use in your code**
129
+ **4. Use in your code**
107
130
 
108
131
  ```typescript
109
132
  import { Client } from '@atproto/lex'
@@ -118,10 +141,6 @@ const response = await client.call(app.bsky.actor.getProfile, {
118
141
  })
119
142
  ```
120
143
 
121
- > [!TIP]
122
- >
123
- > If you wish to customize the output location, or any other options, you can run the `lex build` command separately. For that purpose, make sure to use the `--no-build` flag when installing lexicons to skip the automatic build step.
124
-
125
144
  ## Lexicon Schemas
126
145
 
127
146
  The `lex install` command fetches Lexicon schemas from the Atmosphere network and manages them locally (in the `lexicons/` directory by default). It also updates the `lexicons.json` manifest file to track installed Lexicons and their versions.
@@ -147,15 +166,13 @@ Options:
147
166
 
148
167
  - `--manifest <path>` - Path to lexicons.json manifest file (default: `./lexicons.json`)
149
168
  - `--no-save` - Don't update lexicons.json with installed lexicons (save is enabled by default)
150
- - `--no-build` - Skip building TypeScript lexicon schema files after installation (build is enabled by default)
151
169
  - `--update` - Update all installed lexicons to their latest versions by re-resolving and re-installing them
152
170
  - `--ci` - Error if the installed lexicons do not match the CIDs in the lexicons.json manifest
153
171
  - `--lexicons <dir>` - Directory containing lexicon JSON files (default: `./lexicons`)
154
- - `--out <dir>` - Output directory for generated TS files (default: `./src/lexicons`)
155
172
 
156
173
  ## TypeScript Schemas
157
174
 
158
- The `lex install` command automatically builds TypeScript schemas after installing Lexicon JSON files. You can also run the build step separately using the `lex build` command. These generated schemas provide type-safe validation, type guards, and builder utilities for working with AT Protocol data structures.
175
+ After installing Lexicon JSON files, use the `lex build` command to generate TypeScript schemas. These generated schemas provide type-safe validation, type guards, and builder utilities for working with AT Protocol data structures.
159
176
 
160
177
  ```bash
161
178
  lex build --lexicons ./lexicons --out ./src/lexicons
@@ -173,7 +190,9 @@ Options:
173
190
  - `--exclude <patterns...>` - List of strings or regex patterns to exclude lexicon documents by their IDs
174
191
  - `--include <patterns...>` - List of strings or regex patterns to include lexicon documents by their IDs
175
192
  - `--lib <package>` - Package name of the library to import the lex schema utility "l" from (default: `@atproto/lex`)
176
- - `--allowLegacyBlobs` - Allow generating schemas that accept legacy blob references (disabled by default; enabling this might cause compatibility issues with records created a long time ago)
193
+ - `--allowLegacyBlobs` - Allow generating schemas that accept legacy blob references (disabled by default; enable this if you encounter issues while processing records created a long time ago)
194
+ - `--importExt <ext>` - File extension to use for import statements in generated files (default: `.js`). Use `--importExt ""` to generate extension-less imports
195
+ - `--fileExt <ext>` - File extension to use for generated files (default: `.ts`)
177
196
 
178
197
  ### Generated Schema Structure
179
198
 
@@ -745,16 +764,19 @@ Add these scripts to your `package.json`:
745
764
  ```json
746
765
  {
747
766
  "scripts": {
748
- "lex:update": "lex install --update --save",
749
- "prebuild": "lex install --ci"
767
+ "update-lexicons": "lex install --update --save",
768
+ "postinstall": "lex install --ci",
769
+ "prebuild": "lex build",
770
+ "build": "# Your build command here"
750
771
  }
751
772
  }
752
773
  ```
753
774
 
754
775
  This ensures that:
755
776
 
756
- 1. Lexicons are installed/verified before every build.
757
- 2. You can easily update lexicons with `npm run lex:update` or `pnpm lex:update`.
777
+ 1. Lexicons are verified against the manifest after every `npm install` or `pnpm install`.
778
+ 2. TypeScript schemas are built before your project is built.
779
+ 3. You can easily update lexicons with `npm run update-lexicons` or `pnpm update-lexicons`.
758
780
 
759
781
  ### Tree-Shaking
760
782
 
@@ -775,7 +797,7 @@ For library authors, use `--pure-annotations` when building:
775
797
  lex build --pure-annotations
776
798
  ```
777
799
 
778
- This will make the generated code more tree-shakeable from places that import your library.
800
+ This will make the generated code more easily tree-shakeable from places that import your library.
779
801
 
780
802
  ### Custom Headers
781
803
 
@@ -800,8 +822,11 @@ All methods support these base options:
800
822
  ```typescript
801
823
  type CallOptions = {
802
824
  signal?: AbortSignal // Abort the request
803
- headers?: HeadersInit // Custom request headers
825
+ headers?: HeadersInit // Additional request headers
804
826
  service?: Service // Override service proxy for this request
827
+ labelers?: Iterable<Did> // Additional labelers for this request
828
+ validateRequest?: boolean // Set to "true" to enable request schema validation
829
+ validateResponse?: boolean // Set to "false" to skip response schema validation
805
830
  }
806
831
  ```
807
832
 
package/bin/lex CHANGED
@@ -80,7 +80,25 @@ yargs(hideBin(process.argv))
80
80
  type: 'boolean',
81
81
  default: false,
82
82
  describe:
83
- 'allow generating schemas that accept legacy blob references (disabled by default; enabling this might cause compatibility issues with records created a long time ago)',
83
+ 'generate schemas that accept legacy blob references (disabled by default; enable this if you encounter issues while processing records created a long time ago)',
84
+ },
85
+ importExt: {
86
+ type: 'string',
87
+ default: '.js',
88
+ describe:
89
+ 'file extension to use for import statements in generated files (e.g. ".ts", ".mts", ".cts"). Use --import-ext "" to generate extension-less imports.',
90
+ },
91
+ fileExt: {
92
+ type: 'string',
93
+ default: '.ts',
94
+ describe:
95
+ 'file extension to use for generated files (e.g. ".ts", ".mts", ".cts")',
96
+ },
97
+ ignoreInvalidLexicons: {
98
+ type: 'boolean',
99
+ default: false,
100
+ describe:
101
+ 'skip over invalid lexicon files instead of exiting with an error',
84
102
  },
85
103
  })
86
104
  },
@@ -105,12 +123,6 @@ yargs(hideBin(process.argv))
105
123
  describe:
106
124
  'Updates lexicons.json with installed lexicons (use --no-save to disable)',
107
125
  },
108
- build: {
109
- type: 'boolean',
110
- default: true,
111
- describe:
112
- 'automatically build TypeScript lexicon schema files after installation (use --no-build to disable)',
113
- },
114
126
  update: {
115
127
  type: 'boolean',
116
128
  default: false,
@@ -129,12 +141,6 @@ yargs(hideBin(process.argv))
129
141
  default: './lexicons',
130
142
  describe: 'directory containing lexicon JSON files',
131
143
  },
132
- out: {
133
- type: 'string',
134
- demandOption: true,
135
- default: './src/lexicons',
136
- describe: 'output directory for generated TS files',
137
- },
138
144
  })
139
145
  },
140
146
  async (argv) => {
@@ -146,18 +152,6 @@ yargs(hideBin(process.argv))
146
152
  lexicons: argv.lexicons,
147
153
  manifest: argv.manifest,
148
154
  })
149
-
150
- if (argv.build) {
151
- await build({
152
- lexicons: argv.lexicons,
153
- out: argv.out,
154
- clear: true,
155
- pretty: true,
156
- pureAnnotations: true,
157
- ignoreErrors: false,
158
- lib: '@atproto/lex',
159
- })
160
- }
161
155
  },
162
156
  )
163
157
  .parseAsync()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "description": "Lexicon tooling for AT",
6
6
  "keywords": [
@@ -18,7 +18,8 @@
18
18
  "./index.cjs",
19
19
  "./index.mjs",
20
20
  "./index.d.ts",
21
- "./bin"
21
+ "./bin",
22
+ "./CHANGELOG.md"
22
23
  ],
23
24
  "bin": {
24
25
  "ts-lex": "./bin/lex",
@@ -37,10 +38,10 @@
37
38
  },
38
39
  "dependencies": {
39
40
  "yargs": "^17.0.0",
40
- "@atproto/lex-builder": "0.0.3",
41
- "@atproto/lex-client": "0.0.1",
42
- "@atproto/lex-installer": "0.0.3",
43
- "@atproto/lex-schema": "0.0.1"
41
+ "@atproto/lex-builder": "0.0.5",
42
+ "@atproto/lex-client": "0.0.3",
43
+ "@atproto/lex-installer": "0.0.5",
44
+ "@atproto/lex-schema": "0.0.3"
44
45
  },
45
46
  "devDependencies": {
46
47
  "@types/yargs": "^17.0.33",