@pulzar/core
Version:
Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support
148 lines • 5.47 kB
TypeScript
import { Request } from "express";
import { AuthContext, User } from "../../auth/types";
import { I18nContext } from "../../i18n/i18n";
export interface GraphQLContext {
req: Request;
auth?: AuthContext;
i18n?: I18nContext;
user?: User;
session?: import("../../auth/types").SessionData;
language?: string;
t?: (key: string, options?: Record<string, unknown>) => string;
metadata?: Record<string, unknown>;
}
export interface ResolverOptions {
requireAuth?: boolean;
requiredRoles?: string[];
requiredPermissions?: string[];
rateLimit?: {
max: number;
window: number;
};
cache?: {
ttl: number;
key?: string;
};
}
export declare class BaseResolver {
protected logger: import("pino").Logger<never>;
/**
* Get authenticated user from context
*/
protected getUser(context: GraphQLContext): User;
/**
* Get optional user from context
*/
protected getOptionalUser(context: GraphQLContext): User | null;
/**
* Check if user is authenticated
*/
protected isAuthenticated(context: GraphQLContext): boolean;
/**
* Require authentication
*/
protected requireAuth(context: GraphQLContext): void;
/**
* Check if user has role
*/
protected hasRole(context: GraphQLContext, role: string): boolean;
/**
* Check if user has any of the roles
*/
protected hasAnyRole(context: GraphQLContext, roles: string[]): boolean;
/**
* Check if user has all roles
*/
protected hasAllRoles(context: GraphQLContext, roles: string[]): boolean;
/**
* Require specific role
*/
protected requireRole(context: GraphQLContext, role: string): void;
/**
* Require any of the roles
*/
protected requireAnyRole(context: GraphQLContext, roles: string[]): void;
/**
* Check if user has permission
*/
protected hasPermission(context: GraphQLContext, permission: string): boolean;
/**
* Check if user has any of the permissions
*/
protected hasAnyPermission(context: GraphQLContext, permissions: string[]): boolean;
/**
* Check if user has all permissions
*/
protected hasAllPermissions(context: GraphQLContext, permissions: string[]): boolean;
/**
* Require specific permission
*/
protected requirePermission(context: GraphQLContext, permission: string): void;
/**
* Require any of the permissions
*/
protected requireAnyPermission(context: GraphQLContext, permissions: string[]): void;
/**
* Get translation function from context
*/
protected getTranslationFunction(context: GraphQLContext): (key: string, options?: Record<string, unknown>) => string;
/**
* Translate text
*/
protected translate(context: GraphQLContext, key: string, options?: Record<string, unknown>): string;
/**
* Get current language from context
*/
protected getLanguage(context: GraphQLContext): string;
/**
* Apply resolver options
*/
protected applyOptions(context: GraphQLContext, options: ResolverOptions): void;
/**
* Handle resolver error
*/
protected handleError(error: Error, context: GraphQLContext, fieldName?: string): never;
/**
* Log resolver access
*/
protected logAccess(context: GraphQLContext, fieldName: string, args?: Record<string, unknown>): void;
/**
* Create standardized connection result for pagination
*/
protected createConnection<T>(items: T[], totalCount: number, limit: number, offset: number): {
edges: {
node: T;
cursor: string;
}[];
pageInfo: {
hasNextPage: boolean;
hasPreviousPage: boolean;
startCursor: string | null;
endCursor: string | null;
};
totalCount: number;
};
/**
* Parse cursor for pagination
*/
protected parseCursor(cursor: string): number;
/**
* Validate pagination arguments
*/
protected validatePagination(first?: number, last?: number, after?: string, before?: string): void;
/**
* Calculate pagination offset
*/
protected calculatePaginationOffset(after?: string, before?: string, first?: number, last?: number): {
limit: number;
offset: number;
};
}
export declare function Resolver(options?: ResolverOptions): <T extends new (...args: unknown[]) => {}>(target: T) => T;
export declare function Field(options?: ResolverOptions): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function RequireAuth(): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function RequireRoles(...roles: string[]): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function RequirePermissions(...permissions: string[]): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function RateLimit(max: number, window: number): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
export declare function Cache(ttl: number, key?: string): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
//# sourceMappingURL=base.resolver.d.ts.map