UNPKG

@atproto/oauth-scopes

Version:

A library for manipulating and validating ATproto OAuth scopes in TypeScript.

50 lines • 1.31 kB
const isArray = Array.isArray; /** * Translates a {@link LexiconPermission} into a {@link ScopeSyntax}. */ export class LexPermissionSyntax { constructor(lexPermission) { this.lexPermission = lexPermission; } get prefix() { return this.lexPermission.resource; } get positional() { return undefined; } get(key) { // Ignore reserved keywords if (key === 'type') return undefined; if (key === 'resource') return undefined; // Ignore inherited properties (toString(), etc.) if (!Object.hasOwn(this.lexPermission, key)) return undefined; return this.lexPermission[key]; } *keys() { for (const key of Object.keys(this.lexPermission)) { if (this.get(key) !== undefined) yield key; } } getSingle(key) { const value = this.get(key); if (isArray(value)) return null; return value; } getMulti(key) { const value = this.get(key); if (value === undefined) return undefined; if (!isArray(value)) return null; return value; } toJSON() { return this.lexPermission; } } //# sourceMappingURL=syntax-lexicon.js.map