@atproto/lex-builder 0.0.0 → 0.0.2
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/LICENSE.txt +7 -0
- package/dist/lexicon-directory-indexer.d.ts +1 -1
- package/dist/lexicon-directory-indexer.d.ts.map +1 -1
- package/dist/lexicon-directory-indexer.js +12 -17
- package/dist/lexicon-directory-indexer.js.map +1 -1
- package/package.json +5 -5
- package/src/lexicon-directory-indexer.ts +10 -15
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Dual MIT/Apache-2.0 License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2025 Bluesky Social PBC, and Contributors
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-directory-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-directory-indexer.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,sBAAsB,EAEvB,MAAM,uBAAuB,CAAA;AAE9B,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,CAAA;AAEhE,qBAAa,uBAAwB,SAAQ,sBAAsB;gBACrD,OAAO,EAAE,8BAA8B;CAGpD;AAED,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"lexicon-directory-indexer.d.ts","sourceRoot":"","sources":["../src/lexicon-directory-indexer.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,sBAAsB,EAEvB,MAAM,uBAAuB,CAAA;AAE9B,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,CAAA;AAEhE,qBAAa,uBAAwB,SAAQ,sBAAsB;gBACrD,OAAO,EAAE,8BAA8B;CAGpD;AAED,KAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA"}
|
|
@@ -11,23 +11,18 @@ class LexiconDirectoryIndexer extends lex_document_1.LexiconIterableIndexer {
|
|
|
11
11
|
}
|
|
12
12
|
exports.LexiconDirectoryIndexer = LexiconDirectoryIndexer;
|
|
13
13
|
async function* readLexicons(options) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (options.ignoreErrors)
|
|
27
|
-
console.error(`${message}:`, cause);
|
|
28
|
-
else
|
|
29
|
-
throw new Error(message, { cause });
|
|
30
|
-
}
|
|
14
|
+
for await (const filePath of listFiles(options.lexicons)) {
|
|
15
|
+
if (filePath.endsWith('.json')) {
|
|
16
|
+
try {
|
|
17
|
+
const data = await (0, promises_1.readFile)(filePath, 'utf8');
|
|
18
|
+
yield lex_document_1.lexiconDocumentSchema.parse(JSON.parse(data));
|
|
19
|
+
}
|
|
20
|
+
catch (cause) {
|
|
21
|
+
const message = `Error parsing lexicon document ${filePath}`;
|
|
22
|
+
if (options.ignoreErrors)
|
|
23
|
+
console.error(`${message}:`, cause);
|
|
24
|
+
else
|
|
25
|
+
throw new Error(message, { cause });
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexicon-directory-indexer.js","sourceRoot":"","sources":["../src/lexicon-directory-indexer.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AACpD,yCAAgC;AAChC,wDAI8B;AAI9B,MAAa,uBAAwB,SAAQ,qCAAsB;IACjE,YAAY,OAAuC;QACjD,KAAK,CAAC,YAA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E,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACxE,IAAK,GAAW,EAAE,IAAI,KAAK,QAAQ;YAAE,OAAO,EAAE,CAAA;QAC9C,MAAM,GAAG,CAAA;IACX,CAAC,CAAC,CAAA;IACF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;YACzB,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QACvB,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC;YACtD,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { readFile, readdir } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport {\n LexiconDocument,\n LexiconIterableIndexer,\n lexiconDocumentSchema,\n} from '@atproto/lex-document'\n\nexport type LexiconDirectoryIndexerOptions = ReadLexiconsOptions\n\nexport class LexiconDirectoryIndexer extends LexiconIterableIndexer {\n constructor(options: LexiconDirectoryIndexerOptions) {\n super(readLexicons(options))\n }\n}\n\ntype ReadLexiconsOptions = {\n lexicons: string\n ignoreErrors?: boolean\n}\n\nasync function* readLexicons(\n options: ReadLexiconsOptions,\n): AsyncGenerator<LexiconDocument, void, unknown> {\n for await (const filePath of listFiles(options.lexicons)) {\n if (filePath.endsWith('.json')) {\n try {\n const data = await readFile(filePath, 'utf8')\n yield lexiconDocumentSchema.parse(JSON.parse(data))\n } catch (cause) {\n const message = `Error parsing lexicon document ${filePath}`\n if (options.ignoreErrors) console.error(`${message}:`, cause)\n else throw new Error(message, { cause })\n }\n }\n }\n}\n\nasync function* listFiles(dir: string): AsyncGenerator<string> {\n const dirents = await readdir(dir, { withFileTypes: true }).catch((err) => {\n if ((err as any)?.code === 'ENOENT') return []\n throw err\n })\n for (const dirent of dirents) {\n const res = join(dir, dirent.name)\n if (dirent.isDirectory()) {\n yield* listFiles(res)\n } else if (dirent.isFile() || dirent.isSymbolicLink()) {\n yield res\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/lex-builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "TypeScript schema builder for AT Lexicons",
|
|
6
6
|
"keywords": [
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atproto/lex-document": "workspace:*",
|
|
36
|
-
"@atproto/lex-schema": "workspace:*",
|
|
37
35
|
"prettier": "^3.2.5",
|
|
38
36
|
"ts-morph": "^27.0.0",
|
|
39
|
-
"tslib": "^2.8.1"
|
|
37
|
+
"tslib": "^2.8.1",
|
|
38
|
+
"@atproto/lex-document": "0.0.1",
|
|
39
|
+
"@atproto/lex-schema": "0.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ts-morph/common": "^0.28.0",
|
|
@@ -46,4 +46,4 @@
|
|
|
46
46
|
"build": "tsc --build tsconfig.build.json",
|
|
47
47
|
"test": "jest"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|
|
@@ -15,27 +15,22 @@ export class LexiconDirectoryIndexer extends LexiconIterableIndexer {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
type ReadLexiconsOptions = {
|
|
18
|
-
lexicons: string
|
|
18
|
+
lexicons: string
|
|
19
19
|
ignoreErrors?: boolean
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async function* readLexicons(
|
|
23
23
|
options: ReadLexiconsOptions,
|
|
24
24
|
): AsyncGenerator<LexiconDocument, void, unknown> {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} catch (cause) {
|
|
35
|
-
const message = `Error parsing lexicon document ${filePath}`
|
|
36
|
-
if (options.ignoreErrors) console.error(`${message}:`, cause)
|
|
37
|
-
else throw new Error(message, { cause })
|
|
38
|
-
}
|
|
25
|
+
for await (const filePath of listFiles(options.lexicons)) {
|
|
26
|
+
if (filePath.endsWith('.json')) {
|
|
27
|
+
try {
|
|
28
|
+
const data = await readFile(filePath, 'utf8')
|
|
29
|
+
yield lexiconDocumentSchema.parse(JSON.parse(data))
|
|
30
|
+
} catch (cause) {
|
|
31
|
+
const message = `Error parsing lexicon document ${filePath}`
|
|
32
|
+
if (options.ignoreErrors) console.error(`${message}:`, cause)
|
|
33
|
+
else throw new Error(message, { cause })
|
|
39
34
|
}
|
|
40
35
|
}
|
|
41
36
|
}
|