Skip to content

Commit 6c90382

Browse files
committed
fix: fix NSID validation function
Source code: atcute/packages/lexicons/lexicons/lib/syntax/nsid.ts at b93fbbf94fec2081b827ae1e366dd59ef6a2116d · mary-ext/atcute - https://github.com/mary-ext/atcute/blob/b93fbbf94fec2081b827ae1e366dd59ef6a2116d/packages/lexicons/lexicons/lib/syntax/nsid.ts
1 parent 286616e commit 6c90382

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/lex-cli/src/generator/schema.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,25 @@ export const userTypeSchema = t.isOneOf([
368368

369369
export type UserTypeSchema = t.InferType<typeof userTypeSchema>;
370370

371+
/**
372+
* represents a namespace identifier (NSID)
373+
*/
374+
export type Nsid = `${string}.${string}.${string}`;
375+
371376
const NSID_RE =
372-
/^[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+\.[a-z]{1,63}$/i;
373-
const nsidType = t.cascade(t.isString(), (value) => NSID_RE.test(value));
377+
/^[a-zA-Z](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+\.[a-zA-Z][a-zA-Z0-9]{0,62}?$/;
378+
379+
// #__NO_SIDE_EFFECTS__
380+
export const isNsid = (input: unknown): input is Nsid => {
381+
return (
382+
typeof input === 'string' &&
383+
input.length >= 5 &&
384+
input.length <= 317 &&
385+
NSID_RE.test(input)
386+
);
387+
};
388+
389+
const nsidType = t.cascade(t.isString(), (value) => isNsid(value));
374390

375391
export const documentSchema = t.cascade(
376392
t.isObject({

0 commit comments

Comments
 (0)