@atcute/lex-cli 2.8.2 → 3.0.0
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/README.md +43 -29
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +6 -7
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +26 -9
- package/dist/commands/pull.js.map +1 -1
- package/dist/config.d.ts +60 -157
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +68 -137
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lexicon-loader.d.ts.map +1 -1
- package/dist/lexicon-loader.js +7 -8
- package/dist/lexicon-loader.js.map +1 -1
- package/dist/lexicon-metadata.d.ts +2 -2
- package/dist/lexicon-metadata.d.ts.map +1 -1
- package/dist/lexicon-metadata.js +13 -34
- package/dist/lexicon-metadata.js.map +1 -1
- package/dist/pull-sources/atproto.d.ts.map +1 -1
- package/dist/pull-sources/atproto.js +5 -3
- package/dist/pull-sources/atproto.js.map +1 -1
- package/dist/utils/issues.d.ts +4 -0
- package/dist/utils/issues.d.ts.map +1 -0
- package/dist/utils/issues.js +9 -0
- package/dist/utils/issues.js.map +1 -0
- package/dist/utils/nsid-pattern.d.ts +6 -0
- package/dist/utils/nsid-pattern.d.ts.map +1 -0
- package/dist/utils/nsid-pattern.js +12 -0
- package/dist/utils/nsid-pattern.js.map +1 -0
- package/package.json +7 -7
- package/src/commands/generate.ts +6 -9
- package/src/commands/pull.ts +28 -11
- package/src/config.ts +172 -189
- package/src/index.ts +3 -1
- package/src/lexicon-loader.ts +8 -10
- package/src/lexicon-metadata.ts +19 -36
- package/src/pull-sources/atproto.ts +4 -3
- package/src/utils/issues.ts +9 -0
- package/src/utils/nsid-pattern.ts +12 -0
package/src/lexicon-metadata.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { isValidLexiconPattern } from './utils/nsid-pattern.ts';
|
|
4
4
|
|
|
5
5
|
export type LexiconMappingEntryType = 'namespace' | 'named';
|
|
6
6
|
export type LexiconMappingPath = '.' | `./${string}`;
|
|
@@ -19,56 +19,39 @@ export interface PackageJsonWithLexicons {
|
|
|
19
19
|
[key: string]: unknown;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Validates if a string is a valid NSID pattern (exact or wildcard)
|
|
24
|
-
* - Exact: "com.atproto.repo.getRecord"
|
|
25
|
-
* - Wildcard: "com.atproto.*"
|
|
26
|
-
*/
|
|
27
|
-
const isValidLexiconPattern = (pattern: string): boolean => {
|
|
28
|
-
if (pattern.endsWith('.*')) {
|
|
29
|
-
// For wildcards, remove the .* and validate the prefix as an NSID segment
|
|
30
|
-
const prefix = pattern.slice(0, -2);
|
|
31
|
-
// Add a dummy segment to make it a valid NSID for validation
|
|
32
|
-
return isNsid(prefix + '.x');
|
|
33
|
-
}
|
|
34
|
-
return isNsid(pattern);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
22
|
/**
|
|
38
23
|
* Schema for a single lexicon mapping entry
|
|
39
24
|
*/
|
|
40
|
-
const lexiconMappingEntry: v.
|
|
41
|
-
type: v.
|
|
42
|
-
path: v.
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
const lexiconMappingEntry: v.GenericSchema<unknown, LexiconMappingEntry> = v.looseObject({
|
|
26
|
+
type: v.picklist(['namespace', 'named']),
|
|
27
|
+
path: v.custom<LexiconMappingPath>(
|
|
28
|
+
(input) => typeof input === 'string' && (input === '.' || input.startsWith('./')),
|
|
29
|
+
`path must be "." or start with "./"`,
|
|
30
|
+
),
|
|
45
31
|
});
|
|
46
32
|
|
|
47
33
|
/**
|
|
48
34
|
* Schema for the atcute:lexicons field in package.json
|
|
49
35
|
*/
|
|
50
|
-
const mappingsSchema: v.
|
|
51
|
-
.record(lexiconMappingEntry)
|
|
52
|
-
.
|
|
36
|
+
const mappingsSchema: v.GenericSchema<unknown, Record<string, LexiconMappingEntry>> = v.pipe(
|
|
37
|
+
v.record(v.string(), lexiconMappingEntry),
|
|
38
|
+
v.check((input) => {
|
|
53
39
|
for (const key in input) {
|
|
54
40
|
if (!isValidLexiconPattern(key)) {
|
|
55
|
-
return
|
|
56
|
-
message: `invalid NSID pattern (must be valid NSID or end with .*)`,
|
|
57
|
-
path: [key],
|
|
58
|
-
});
|
|
41
|
+
return false;
|
|
59
42
|
}
|
|
60
43
|
}
|
|
44
|
+
return true;
|
|
45
|
+
}, `invalid NSID pattern (must be valid NSID or end with .*)`),
|
|
46
|
+
);
|
|
61
47
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const atcuteLexiconsField: v.Type<AtcuteLexiconsField> = v.object({
|
|
66
|
-
mappings: mappingsSchema.optional(),
|
|
48
|
+
const atcuteLexiconsField: v.GenericSchema<unknown, AtcuteLexiconsField> = v.looseObject({
|
|
49
|
+
mappings: v.optional(mappingsSchema),
|
|
67
50
|
});
|
|
68
51
|
|
|
69
52
|
/**
|
|
70
53
|
* Schema for package.json with atcute:lexicons field
|
|
71
54
|
*/
|
|
72
|
-
export const packageJsonSchema: v.
|
|
73
|
-
'atcute:lexicons':
|
|
55
|
+
export const packageJsonSchema: v.GenericSchema<unknown, PackageJsonWithLexicons> = v.looseObject({
|
|
56
|
+
'atcute:lexicons': v.optional(atcuteLexiconsField),
|
|
74
57
|
});
|
|
@@ -71,12 +71,13 @@ const discoverLexiconsForAuthority = async (
|
|
|
71
71
|
|
|
72
72
|
// extract NSIDs from record keys (the rkey in at://did/collection/rkey)
|
|
73
73
|
for (const record of data.records) {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
let nsid: string;
|
|
75
|
+
try {
|
|
76
|
+
nsid = parseCanonicalResourceUri(record.uri).rkey;
|
|
77
|
+
} catch {
|
|
76
78
|
continue;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
const nsid = r.value.rkey;
|
|
80
81
|
if (!isNsid(nsid)) {
|
|
81
82
|
continue;
|
|
82
83
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
/** prints a list of valibot issues to stderr in the lex-cli's standard format. */
|
|
4
|
+
export const printValibotIssues = (issues: readonly v.BaseIssue<unknown>[]): void => {
|
|
5
|
+
for (const issue of issues) {
|
|
6
|
+
const dotPath = v.getDotPath(issue) ?? '';
|
|
7
|
+
console.log(`- ${issue.type} at .${dotPath}: ${issue.message}`);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isNsid } from '@atcute/lexicons/syntax';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* checks whether a string is either a valid NSID or a wildcard pattern that
|
|
5
|
+
* ends with `.*` whose prefix is a valid NSID segment.
|
|
6
|
+
*/
|
|
7
|
+
export const isValidLexiconPattern = (pattern: string): boolean => {
|
|
8
|
+
if (pattern.endsWith('.*')) {
|
|
9
|
+
return isNsid(`${pattern.slice(0, -2)}.x`);
|
|
10
|
+
}
|
|
11
|
+
return isNsid(pattern);
|
|
12
|
+
};
|