import { ID } from '@pickerjs/common/lib/shared-types'; import { Request } from 'express'; import { CachedSession } from '../../config/session-cache/session-cache-strategy'; import { PickerContext } from '../../schema/types'; export interface SerializedRequestContext { _req?: any; _picker?: PickerContext; } /** * @description * RequestContext保存着与当前请求相关的信息,这些信息可能在堆栈的各个点上都需要。 * 将RequestContext(使用{@link Ctx}装饰器)注入到 _all_ 解析器和REST处理程序中,然后将其传递到服务层,这是一个好做法。 * * 这允许服务层访问有关当前用户、活动语言、活动通道等的信息。此外,为了正确处理每个请求的数据库事务, * * {@link TransactionalConnection}依赖于RequestContext对象的存在。 * * @example * ```TypeScript * \@Query() * myQuery(\@Ctx() ctx: RequestContext) { * return this.myService.getData(ctx); * } * ``` * @docsCategory request */ export declare class RequestContext { private readonly _languageCode; private readonly _session?; private readonly _isAuthorized; private readonly _authorizedAsOwnerOnly; private readonly _translationFn; private readonly _req?; private readonly _picker?; /** * @internal */ constructor(options: { req?: Request; picker?: PickerContext; }); /** * @description * 创建一个 "empty" RequestContext对象。这只用于必须在正常的请求-响应周期之外调用服务方法的情况, * 例如: * 当以编程方式填充数据时。通常一个更好的替代方法是使用{@link RequestContextService} `create()` 方法, * 它允许对生成的RequestContext对象有更多的控制。 */ static empty(): RequestContext; /** * @description * 从 `serialize()` 方法创建的序列化对象创建一个新的 RequestContext 对象 */ static deserialize(ctxObject: SerializedRequestContext): RequestContext; /** * @description * 将 RequestContext 对象序列化为一个JSON兼容(JSON-compatible)的简单对象。 * 当你需要将 RequestContext 对象发送给另一个进程时,这是很有用的。 * 例如: * 通过 {@link JobQueueService} 将其传递给 Job Queue */ serialize(): SerializedRequestContext; get session(): CachedSession | undefined; get activeUserId(): ID | undefined; /** * @description * True if the current anonymous session is only authorized to operate on entities that * are owned by the current session. */ get authorizedAsOwnerOnly(): boolean; /** * @description * 如果当前会话被授权访问当前解析器方法,则为True。 */ get isAuthorized(): boolean; get picker(): PickerContext; private isAuthenticatedSession; /** * Express "Request" 对象很大,包含许多循环引用。 * 我们将只保留整体的一个子集,只保留高达2级的可序列化属性。 * @private */ private shallowCloneRequestObject; }