@atproto/lex 0.3.14 → 0.4.1

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,29 @@
1
1
  # @atproto/lex
2
2
 
3
+ ## 0.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atproto/lex-installer@0.2.1
9
+
10
+ ## 0.4.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#5591](https://github.com/bluesky-social/atproto/pull/5591) [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2) Thanks [@matthieusieben](https://github.com/matthieusieben)! - The installation of lexicon schemas now uses a manifest version 2 file format that supports a `resolver` property that allows to override the source of specific lexicons NSIDs (either by looking for them locally, or from the network)
15
+
16
+ ### Patch Changes
17
+
18
+ - [#5591](https://github.com/bluesky-social/atproto/pull/5591) [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2) Thanks [@matthieusieben](https://github.com/matthieusieben)! - `lex install` now resolves Lexicons from local files, not only the network. The `lexicons.json` manifest gains an ordered `resolvers` array of local override strategies (currently `{ type: "directory", path, include?, exclude? }`), consulted before the network fallback. Manifest lock URIs may now be `file://` (relative to the manifest) in addition to `at://`. Local-file resolutions are symlinked rather than copied (left in place when source and destination are the same path). `resolvers` can also provide a strategy that uses a specific AT Protocol repository.
19
+
20
+ - [#5591](https://github.com/bluesky-social/atproto/pull/5591) [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Define bin commands based on `./cli` exports from `lex-installer` and `lex-builder`
21
+ - Updated dependencies [[`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2), [`f98b78a`](https://github.com/bluesky-social/atproto/commit/f98b78adbc8963e49823117b007422211f6d3ff2)]:
22
+ - @atproto/lex-installer@0.2.0
23
+ - @atproto/lex-builder@0.1.18
24
+ - @atproto/lex-client@0.4.0
25
+ - @atproto/lex-schema@0.2.9
26
+
3
27
  ## 0.3.14
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -190,7 +190,7 @@ const profile = await xrpc('https://api.bsky.app', app.bsky.actor.getProfile, {
190
190
 
191
191
  ## Lexicon Schemas
192
192
 
193
- 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.
193
+ The `lex install` command resolves Lexicon schemas 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.
194
194
 
195
195
  ```bash
196
196
  # Install Lexicons and update lexicons.json (default behavior)
@@ -217,6 +217,30 @@ Options:
217
217
  - `--ci` - Error if the installed lexicons do not match the CIDs in the lexicons.json manifest
218
218
  - `--lexicons <dir>` - Directory containing lexicon JSON files (default: `./lexicons`)
219
219
 
220
+ ### Local resolution (`resolvers`)
221
+
222
+ Beyond the network, `lexicons.json` can declare an ordered `resolvers` array of
223
+ local override strategies, consulted (in order, first match wins) for every
224
+ dependency before the network fallback. This lets a package vendor Lexicons from
225
+ a local directory. Local-file resolutions are **symlinked** into the `lexicons/`
226
+ directory (not copied) and locked with a `file://` URI relative to the manifest.
227
+
228
+ ```jsonc
229
+ {
230
+ "version": 1,
231
+ "lexicons": ["com.example.foo"],
232
+ "resolvers": [
233
+ // path relative to lexicons.json; optional include/exclude NSID globs
234
+ { "type": "directory", "path": "../../lexicons" },
235
+ // use a specific repo for resolving certain NSIDs (instead of performing the _lexicon network resolution of the authority)
236
+ { "type": "repo", "repo": "bsky.app", "include": ["app.bsky.*"] },
237
+ ],
238
+ "resolutions": {/* ...file:// or at:// locks... */},
239
+ }
240
+ ```
241
+
242
+ See the [`@atproto/lex-installer` README](https://github.com/bluesky-social/atproto/blob/main/packages/lex/lex-installer/README.md) for the full resolution order and the planned `repo` resolver.
243
+
220
244
  ## TypeScript Schemas
221
245
 
222
246
  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.
package/bin/lex CHANGED
@@ -1,169 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /* eslint-env node */
4
-
5
- // This file is referenced by the "bin" field in package.json. Because of that,
6
- // we need this file to exist on disk even before the project is built, so it is
7
- // written in plain JS. This allows package managers to properly link the CLI
8
- // command when the monorepo is being setup (during initial "pnpm install").
9
-
10
3
  import yargs from 'yargs'
11
4
  import { hideBin } from 'yargs/helpers'
5
+ import { buildCommand } from '@atproto/lex-builder/cli'
6
+ import { installCommand, updateCommand } from '@atproto/lex-installer/cli'
12
7
 
13
- // @TODO lex-builder and lex-installer should both
14
- // - Define their own CLI commands and options
15
- // - Expose a "bin" entrypoint so they can be called independently
16
- // This package should only be a thin wrapper that delegates to those packages.
17
-
18
- yargs(hideBin(process.argv))
8
+ void yargs(hideBin(process.argv))
9
+ .command(buildCommand)
10
+ .command(installCommand)
11
+ .command(updateCommand)
19
12
  .strict()
20
- .command(
21
- ['build', 'b'],
22
- 'Generate TypeScript lexicon schema files from JSON lexicon definitions',
23
- (yargs) => {
24
- return yargs.strict().options({
25
- lexicons: {
26
- type: 'string',
27
- demandOption: true,
28
- default: './lexicons',
29
- describe: 'directory containing lexicon JSON files',
30
- },
31
- out: {
32
- type: 'string',
33
- demandOption: true,
34
- default: './src/lexicons',
35
- describe: 'output directory for generated TS files',
36
- },
37
- clear: {
38
- type: 'boolean',
39
- default: false,
40
- describe: 'clear output directory before generating files',
41
- },
42
- override: {
43
- type: 'boolean',
44
- default: false,
45
- describe: 'override existing files (has no effect with --clear)',
46
- },
47
- pretty: {
48
- type: 'boolean',
49
- default: true,
50
- describe: 'run prettier on generated files',
51
- },
52
- 'ignore-errors': {
53
- type: 'boolean',
54
- default: false,
55
- describe: 'how to handle errors when processing input files',
56
- },
57
- exclude: {
58
- array: true,
59
- type: 'string',
60
- describe:
61
- 'list of strings or regex patterns to exclude lexicon documents by their IDs',
62
- },
63
- include: {
64
- array: true,
65
- type: 'string',
66
- describe:
67
- 'list of strings or regex patterns to include lexicon documents by their IDs',
68
- },
69
- lib: {
70
- type: 'string',
71
- default: '@atproto/lex',
72
- describe:
73
- 'package name of the library to import the lex schema utility "l" from',
74
- },
75
- 'import-ext': {
76
- type: 'string',
77
- default: '.js',
78
- describe:
79
- 'file extension to use for import statements in generated files (e.g. ".ts", ".mts", ".cts"). Use --import-ext "" to generate extension-less imports.',
80
- },
81
- 'file-ext': {
82
- type: 'string',
83
- default: '.ts',
84
- describe:
85
- 'file extension to use for generated files (e.g. ".ts", ".mts", ".cts")',
86
- },
87
- 'index-file': {
88
- type: 'boolean',
89
- default: false,
90
- describe:
91
- 'generate an "index.<fileExt>" file that exports all root-level namespaces',
92
- },
93
- 'defs-export': {
94
- type: 'boolean',
95
- default: false,
96
- describe:
97
- 'when some definitions conflict with child namespaces, this option allows to export lexicon definitions under a separate $defs namespace (e.g. com.example.foo.$defs)',
98
- },
99
- 'default-export': {
100
- type: 'boolean',
101
- default: true,
102
- describe:
103
- 'whether to generate a default export for the "main" lexicon definition schema in the parent namespace file',
104
- },
105
- 'ignore-invalid-lexicons': {
106
- type: 'boolean',
107
- default: false,
108
- describe:
109
- 'skip over invalid lexicon files instead of exiting with an error',
110
- },
111
- })
112
- },
113
- async (argv) => {
114
- const { build } = await import('@atproto/lex-builder')
115
- await build(argv)
116
- },
117
- )
118
- .command(
119
- ['install [nsid..]', 'i [nsid..]'],
120
- 'Fetch and install lexicon documents',
121
- (yargs) => {
122
- return yargs.strict().options({
123
- manifest: {
124
- type: 'string',
125
- default: './lexicons.json',
126
- describe: 'path to lexicons.json manifest file',
127
- },
128
- save: {
129
- alias: 's',
130
- type: 'boolean',
131
- default: true,
132
- describe:
133
- 'Updates lexicons.json with installed lexicons (use --no-save to disable)',
134
- },
135
- update: {
136
- type: 'boolean',
137
- default: false,
138
- describe:
139
- 'update all installed lexicons to their latest versions by re-resolving and re-installing them',
140
- },
141
- ci: {
142
- type: 'boolean',
143
- default: false,
144
- describe:
145
- 'error if the installed lexicons do not match the CIDs in the lexicons.json manifest',
146
- },
147
- lexicons: {
148
- type: 'string',
149
- demandOption: true,
150
- default: './lexicons',
151
- describe: 'directory containing lexicon JSON files',
152
- },
153
- })
154
- },
155
- async (argv) => {
156
- const { install } = await import('@atproto/lex-installer')
157
- await install({
158
- add: argv.nsid,
159
- save: argv.save,
160
- ci: argv.ci,
161
- update: argv.update,
162
- lexicons: argv.lexicons,
163
- manifest: argv.manifest,
164
- })
165
- },
166
- )
167
13
  .strictCommands()
168
14
  .demandCommand(1)
169
15
  .parseAsync()
package/dist/walk.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Procedure, Query, Schema, Subscription } from '@atproto/lex-schema';
2
- export declare function walk(ns: Record<string, unknown>): Generator<Schema | Procedure | Subscription | Query>;
2
+ export declare function walk(ns: unknown): Generator<Schema | Procedure | Subscription | Query, void, unknown>;
3
3
  //# sourceMappingURL=walk.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE5E,wBAAiB,IAAI,CACnB,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1B,SAAS,CAAC,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,CAAC,CAwCtD"}
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE5E,wBAAiB,IAAI,CACnB,EAAE,EAAE,OAAO,GACV,SAAS,CAAC,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAIrE"}
package/dist/walk.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import { isObject, isPlainObject, isPlainProto } from '@atproto/lex-data';
2
2
  import { Procedure, Query, Schema, Subscription } from '@atproto/lex-schema';
3
3
  export function* walk(ns) {
4
- if (!isPlainObject(ns))
5
- return;
6
- const visited = new Set();
4
+ if (isPlainObject(ns)) {
5
+ return yield* walkInternal(ns, new Set());
6
+ }
7
+ }
8
+ function* walkInternal(ns, visited) {
7
9
  for (const [key, value] of Object.entries(ns)) {
8
10
  // Ignore helpers
9
11
  if (key.startsWith('$')) {
10
12
  continue;
11
13
  }
12
- // Ignore non-objects (should never happen)
14
+ // Ignore non-objects
13
15
  if (!isObject(value)) {
14
16
  continue;
15
17
  }
@@ -30,7 +32,7 @@ export function* walk(ns) {
30
32
  }
31
33
  else if (isPlainProto(value)) {
32
34
  // child namespace
33
- yield* walk(value);
35
+ yield* walkInternal(value, visited);
34
36
  }
35
37
  }
36
38
  }
package/dist/walk.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE5E,MAAM,SAAS,CAAC,CAAC,IAAI,CACnB,EAA2B;IAE3B,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;QAAE,OAAM;IAE9B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAW,CAAA;IAElC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9C,iBAAiB;QACjB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,SAAQ;QACV,CAAC;QAED,2CAA2C;QAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,SAAQ;QACV,CAAC;QAED,yCAAyC;QACzC,IAAI,GAAG,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9C,SAAQ;QACV,CAAC;QAED,UAAU;QACV,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,SAAQ;QACV,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAElB,IACE,KAAK,YAAY,MAAM;YACvB,KAAK,YAAY,SAAS;YAC1B,KAAK,YAAY,YAAY;YAC7B,KAAK,YAAY,KAAK,EACtB,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;aAAM,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,kBAAkB;YAClB,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isObject, isPlainObject, isPlainProto } from '@atproto/lex-data'\nimport { Procedure, Query, Schema, Subscription } from '@atproto/lex-schema'\n\nexport function* walk(\n ns: Record<string, unknown>,\n): Generator<Schema | Procedure | Subscription | Query> {\n if (!isPlainObject(ns)) return\n\n const visited = new Set<unknown>()\n\n for (const [key, value] of Object.entries(ns)) {\n // Ignore helpers\n if (key.startsWith('$')) {\n continue\n }\n\n // Ignore non-objects (should never happen)\n if (!isObject(value)) {\n continue\n }\n\n // Ignore \"main\" re-exported as \"default\"\n if (key === 'default' && value === ns['main']) {\n continue\n }\n\n // De-dupe\n if (visited.has(value)) {\n continue\n }\n\n visited.add(value)\n\n if (\n value instanceof Schema ||\n value instanceof Procedure ||\n value instanceof Subscription ||\n value instanceof Query\n ) {\n yield value\n } else if (isPlainProto(value)) {\n // child namespace\n yield* walk(value)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../src/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE5E,MAAM,SAAS,CAAC,CAAC,IAAI,CACnB,EAAW;IAEX,IAAI,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,GAAG,EAAW,CAAC,CAAA;IACpD,CAAC;AACH,CAAC;AAED,QAAQ,CAAC,CAAC,YAAY,CACpB,EAA2B,EAC3B,OAAqB;IAErB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9C,iBAAiB;QACjB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,SAAQ;QACV,CAAC;QAED,qBAAqB;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,SAAQ;QACV,CAAC;QAED,yCAAyC;QACzC,IAAI,GAAG,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9C,SAAQ;QACV,CAAC;QAED,UAAU;QACV,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,SAAQ;QACV,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAElB,IACE,KAAK,YAAY,MAAM;YACvB,KAAK,YAAY,SAAS;YAC1B,KAAK,YAAY,YAAY;YAC7B,KAAK,YAAY,KAAK,EACtB,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;aAAM,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,kBAAkB;YAClB,KAAK,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isObject, isPlainObject, isPlainProto } from '@atproto/lex-data'\nimport { Procedure, Query, Schema, Subscription } from '@atproto/lex-schema'\n\nexport function* walk(\n ns: unknown,\n): Generator<Schema | Procedure | Subscription | Query, void, unknown> {\n if (isPlainObject(ns)) {\n return yield* walkInternal(ns, new Set<unknown>())\n }\n}\n\nfunction* walkInternal(\n ns: Record<string, unknown>,\n visited: Set<unknown>,\n): Generator<Schema | Procedure | Subscription | Query, void, unknown> {\n for (const [key, value] of Object.entries(ns)) {\n // Ignore helpers\n if (key.startsWith('$')) {\n continue\n }\n\n // Ignore non-objects\n if (!isObject(value)) {\n continue\n }\n\n // Ignore \"main\" re-exported as \"default\"\n if (key === 'default' && value === ns['main']) {\n continue\n }\n\n // De-dupe\n if (visited.has(value)) {\n continue\n }\n\n visited.add(value)\n\n if (\n value instanceof Schema ||\n value instanceof Procedure ||\n value instanceof Subscription ||\n value instanceof Query\n ) {\n yield value\n } else if (isPlainProto(value)) {\n // child namespace\n yield* walkInternal(value, visited)\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/lex",
3
- "version": "0.3.14",
3
+ "version": "0.4.1",
4
4
  "license": "MIT",
5
5
  "description": "Lexicon tooling for AT",
6
6
  "keywords": [
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "tslib": "^2.8.1",
40
- "yargs": "^18.0.0",
41
- "@atproto/lex-client": "^0.3.7",
42
- "@atproto/lex-builder": "^0.1.17",
40
+ "yargs": "^18.2.0",
41
+ "@atproto/lex-builder": "^0.1.18",
42
+ "@atproto/lex-client": "^0.4.0",
43
43
  "@atproto/lex-data": "^0.1.8",
44
- "@atproto/lex-installer": "^0.1.23",
45
- "@atproto/lex-schema": "^0.2.8",
46
- "@atproto/lex-json": "^0.1.7"
44
+ "@atproto/lex-json": "^0.1.7",
45
+ "@atproto/lex-installer": "^0.2.1",
46
+ "@atproto/lex-schema": "^0.2.9"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/yargs": "^17.0.33",