@atproto/lex-builder 0.0.1 → 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.
@@ -4,7 +4,7 @@ export declare class LexiconDirectoryIndexer extends LexiconIterableIndexer {
4
4
  constructor(options: LexiconDirectoryIndexerOptions);
5
5
  }
6
6
  type ReadLexiconsOptions = {
7
- lexicons: string | string[];
7
+ lexicons: string;
8
8
  ignoreErrors?: boolean;
9
9
  };
10
10
  export {};
@@ -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,GAAG,MAAM,EAAE,CAAA;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA"}
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 dirs = Array.isArray(options.lexicons)
15
- ? options.lexicons
16
- : [options.lexicons];
17
- for (const dir of dirs) {
18
- for await (const filePath of listFiles(dir)) {
19
- if (filePath.endsWith('.json')) {
20
- try {
21
- const data = await (0, promises_1.readFile)(filePath, 'utf8');
22
- yield lex_document_1.lexiconDocumentSchema.parse(JSON.parse(data));
23
- }
24
- catch (cause) {
25
- const message = `Error parsing lexicon document ${filePath}`;
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,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9B,CAAC;CACF;AAJD,0DAIC;AAOD,KAAK,SAAS,CAAC,CAAC,YAAY,CAC1B,OAA4B;IAE5B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC1C,CAAC,CAAC,OAAO,CAAC,QAAQ;QAClB,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,KAAK,EAAE,MAAM,QAAQ,IAAI,SAA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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 | string[]\n ignoreErrors?: boolean\n}\n\nasync function* readLexicons(\n options: ReadLexiconsOptions,\n): AsyncGenerator<LexiconDocument, void, unknown> {\n const dirs = Array.isArray(options.lexicons)\n ? options.lexicons\n : [options.lexicons]\n for (const dir of dirs) {\n for await (const filePath of listFiles(dir)) {\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}\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"]}
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,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9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,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.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "description": "TypeScript schema builder for AT Lexicons",
6
6
  "keywords": [
@@ -15,27 +15,22 @@ export class LexiconDirectoryIndexer extends LexiconIterableIndexer {
15
15
  }
16
16
 
17
17
  type ReadLexiconsOptions = {
18
- lexicons: string | 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 dirs = Array.isArray(options.lexicons)
26
- ? options.lexicons
27
- : [options.lexicons]
28
- for (const dir of dirs) {
29
- for await (const filePath of listFiles(dir)) {
30
- if (filePath.endsWith('.json')) {
31
- try {
32
- const data = await readFile(filePath, 'utf8')
33
- yield lexiconDocumentSchema.parse(JSON.parse(data))
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
  }