deno.land / x / pothos@release-1713397530 / packages / plugin-scope-auth / schema-builder.ts

schema-builder.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// @ts-nocheckimport SchemaBuilder, { isThenable, MaybePromise, SchemaTypes } from '../core/index.ts';import { ForbiddenError } from './errors.ts';import RequestCache from './request-cache.ts';import { AuthFailure } from './types.ts';const schemaBuilderProto = SchemaBuilder.prototype as PothosSchemaTypes.SchemaBuilder<SchemaTypes>;// eslint-disable-next-line consistent-returnschemaBuilderProto.runAuthScopes = function runAuthScopes(context, scopes, unauthorizedError = (result) => new ForbiddenError(result.message, result.failure)): MaybePromise<void> { const cache = RequestCache.fromContext(context, this); const resultOrPromise = cache.evaluateScopeMap(scopes); if (isThenable(resultOrPromise)) { return resultOrPromise.then(handleScopeResult); } handleScopeResult(resultOrPromise); function handleScopeResult(result: AuthFailure | null) { if (result) { const error = unauthorizedError({ message: "Unauthorized", failure: result, }); if (typeof error === "string") { throw new ForbiddenError(error, result); } throw error; } }};
pothos

Version Info

Tagged at
a year ago