Skip to main content
Version: Next 🚧

Core Interfaces Specification

This document defines the core interfaces that form the foundation of the UPF plugin ecosystem. Infrastructure plugins implement these interfaces to provide essential services.

Interface Overview​

IAuth Interface​

Authentication and authorization interface.

Version​

1.0.0

TypeScript Definition​

interface IAuth {
// Token validation
validateToken(token: string): Promise<TokenValidation>;

// User information
getUserInfo(userId: string): Promise<UserInfo>;

// Token refresh
refreshToken(refreshToken: string): Promise<TokenResponse>;

// Session management
logout(token: string): Promise<void>;

// Permissions
getPermissions(userId: string): Promise<Permission[]>;
checkPermission(userId: string, permission: string): Promise<boolean>;
}

interface TokenValidation {
valid: boolean;
userId: string;
email: string;
roles: string[];
permissions: string[];
expiresAt: number;
}

interface UserInfo {
id: string;
email: string;
displayName: string;
avatarUrl?: string;
roles: string[];
metadata: Record<string, string>;
}

interface TokenResponse {
accessToken: string;
refreshToken: string;
expiresIn: number;
tokenType: string;
}

interface Permission {
resource: string;
action: string;
conditions?: Record<string, unknown>;
}

gRPC Methods​

MethodTypeDescription
ValidateTokenUnaryValidate JWT token
GetUserInfoUnaryGet user details
RefreshTokenUnaryRefresh access token
LogoutUnaryInvalidate session
GetPermissionsUnaryList user permissions
CheckPermissionUnaryCheck specific permission

IStorage Interface​

Persistent data storage interface.

Version​

1.0.0

TypeScript Definition​

interface IStorage {
// CRUD operations
get<T>(collection: string, id: string): Promise<T | null>;
set<T>(collection: string, id: string, data: T): Promise<void>;
delete(collection: string, id: string): Promise<boolean>;
exists(collection: string, id: string): Promise<boolean>;

// Batch operations
batchGet<T>(collection: string, ids: string[]): Promise<Map<string, T>>;
batchSet<T>(collection: string, items: Map<string, T>): Promise<void>;
batchDelete(collection: string, ids: string[]): Promise<number>;

// Query operations
query<T>(collection: string, query: Query): Promise<QueryResult<T>>;
count(collection: string, query: Query): Promise<number>;

// Streaming operations
stream<T>(collection: string, query: Query): AsyncIterable<T>;
streamSet<T>(collection: string, items: AsyncIterable<{ id: string; data: T }>): Promise<number>;

// Transaction support
transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
}

interface Query {
where?: WhereClause[];
orderBy?: OrderByClause[];
limit?: number;
offset?: number;
select?: string[];
}

interface WhereClause {
field: string;
operator: 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'contains' | 'startsWith';
value: unknown;
}

interface OrderByClause {
field: string;
direction: 'asc' | 'desc';
}

interface QueryResult<T> {
items: T[];
total: number;
hasMore: boolean;
cursor?: string;
}

interface Transaction {
get<T>(collection: string, id: string): Promise<T | null>;
set<T>(collection: string, id: string, data: T): Promise<void>;
delete(collection: string, id: string): Promise<void>;
}

gRPC Methods​

MethodTypeDescription
GetUnaryGet single record
SetUnaryCreate/update record
DeleteUnaryDelete record
BatchGetUnaryGet multiple records
BatchSetUnarySet multiple records
QueryUnaryQuery with filters
StreamQueryServer StreamStream query results
StreamSetClient StreamStream data for bulk insert

ICache Interface​

Fast in-memory caching interface.

Version​

1.0.0

TypeScript Definition​

interface ICache {
// Basic operations
get<T>(key: string): Promise<T | null>;
set<T>(key: string, value: T, options?: SetOptions): Promise<void>;
delete(key: string): Promise<boolean>;
exists(key: string): Promise<boolean>;

// Batch operations
mget<T>(keys: string[]): Promise<Map<string, T>>;
mset<T>(items: Map<string, T>, options?: SetOptions): Promise<void>;
mdelete(keys: string[]): Promise<number>;

// Pattern operations
keys(pattern: string): Promise<string[]>;
invalidate(pattern: string): Promise<number>;

// Atomic operations
increment(key: string, delta?: number): Promise<number>;
decrement(key: string, delta?: number): Promise<number>;

// Pub/Sub
subscribe(channel: string): AsyncIterable<CacheEvent>;
publish(channel: string, message: unknown): Promise<number>;

// Locking
acquireLock(key: string, ttl: number): Promise<Lock | null>;
}

interface SetOptions {
ttl?: number; // Time-to-live in seconds
nx?: boolean; // Only set if not exists
xx?: boolean; // Only set if exists
}

interface CacheEvent {
channel: string;
message: unknown;
timestamp: number;
}

interface Lock {
key: string;
token: string;
release(): Promise<boolean>;
extend(ttl: number): Promise<boolean>;
}

gRPC Methods​

MethodTypeDescription
GetUnaryGet cached value
SetUnarySet cached value
DeleteUnaryDelete cached value
MGetUnaryGet multiple values
MSetUnarySet multiple values
InvalidateUnaryInvalidate by pattern
SubscribeServer StreamSubscribe to channel
PublishUnaryPublish to channel

IFiles Interface​

File and object storage interface.

Version​

1.0.0

TypeScript Definition​

interface IFiles {
// Upload operations
upload(path: string, data: Uint8Array | AsyncIterable<Uint8Array>, options?: UploadOptions): Promise<FileMetadata>;
uploadStream(path: string, options?: UploadOptions): WritableStream<Uint8Array>;

// Download operations
download(path: string): Promise<Uint8Array>;
downloadStream(path: string): AsyncIterable<Uint8Array>;

// Metadata operations
getMetadata(path: string): Promise<FileMetadata>;
updateMetadata(path: string, metadata: Partial<FileMetadata>): Promise<FileMetadata>;

// File operations
delete(path: string): Promise<boolean>;
copy(source: string, destination: string): Promise<FileMetadata>;
move(source: string, destination: string): Promise<FileMetadata>;
exists(path: string): Promise<boolean>;

// Directory operations
list(prefix: string, options?: ListOptions): Promise<ListResult>;
listStream(prefix: string, options?: ListOptions): AsyncIterable<FileMetadata>;

// URL generation
getSignedUrl(path: string, operation: 'read' | 'write', expiresIn: number): Promise<string>;
}

interface UploadOptions {
contentType?: string;
metadata?: Record<string, string>;
acl?: 'private' | 'public-read';
}

interface FileMetadata {
path: string;
size: number;
contentType: string;
etag: string;
lastModified: Date;
metadata: Record<string, string>;
}

interface ListOptions {
limit?: number;
cursor?: string;
delimiter?: string;
}

interface ListResult {
files: FileMetadata[];
prefixes: string[];
cursor?: string;
hasMore: boolean;
}

gRPC Methods​

MethodTypeDescription
UploadClient StreamUpload file in chunks
DownloadServer StreamDownload file in chunks
GetMetadataUnaryGet file metadata
DeleteUnaryDelete file
ListServer StreamList files
GetSignedUrlUnaryGenerate signed URL

IMessageBus Interface​

Asynchronous messaging interface.

Version​

1.0.0

TypeScript Definition​

interface IMessageBus {
// Publish/Subscribe
publish(topic: string, message: Message): Promise<void>;
subscribe(topic: string, options?: SubscribeOptions): AsyncIterable<Message>;

// Queue groups (load-balanced consumers)
subscribeQueue(topic: string, queue: string, options?: SubscribeOptions): AsyncIterable<Message>;

// Request/Reply
request(topic: string, message: Message, timeout?: number): Promise<Message>;
reply(topic: string, handler: (msg: Message) => Promise<Message>): Promise<Subscription>;

// Stream processing
createStream(name: string, subjects: string[]): Promise<StreamInfo>;
deleteStream(name: string): Promise<boolean>;

// Consumer management
createConsumer(stream: string, consumer: ConsumerConfig): Promise<ConsumerInfo>;
deleteConsumer(stream: string, consumer: string): Promise<boolean>;

// Message acknowledgment
ack(message: Message): Promise<void>;
nak(message: Message, delay?: number): Promise<void>;
}

interface Message {
id: string;
topic: string;
data: Uint8Array;
headers: Record<string, string>;
timestamp: Date;
replyTo?: string;
}

interface SubscribeOptions {
startFrom?: 'beginning' | 'latest' | Date;
ackPolicy?: 'explicit' | 'auto';
maxDeliver?: number;
}

interface Subscription {
unsubscribe(): Promise<void>;
}

interface StreamInfo {
name: string;
subjects: string[];
messages: number;
bytes: number;
}

interface ConsumerConfig {
name: string;
filterSubject?: string;
deliverPolicy: 'all' | 'new' | 'last';
ackPolicy: 'explicit' | 'none' | 'all';
maxDeliver: number;
}

gRPC Methods​

MethodTypeDescription
PublishUnaryPublish message
SubscribeServer StreamSubscribe to topic
RequestUnaryRequest/reply pattern
CreateStreamUnaryCreate message stream
AckUnaryAcknowledge message

Interface Versioning​

Interfaces follow semantic versioning:

  • Major: Breaking changes (method signature changes, removed methods)
  • Minor: Backward-compatible additions (new methods, new optional parameters)
  • Patch: Bug fixes (behavior corrections)

Compatibility Matrix​


Previous: Plugin Manifest Next: gRPC Contracts