add mock shared libraries

This commit is contained in:
Harsh Gupta 2024-08-14 14:53:52 +05:30
parent 88a6bd7131
commit 2d6447e8fc
12 changed files with 277 additions and 0 deletions

View File

View File

@ -0,0 +1,7 @@
export function CloudHTTPv2(config: any): MethodDecorator {
return function (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) {
// Simplified implementation
console.log(`CloudHTTPv2 decorator applied to ${String(propertyKey)}`);
return descriptor;
};
}

View File

@ -0,0 +1,13 @@
export class SecurityCompromiseError extends Error {
constructor(message: string) {
super(message);
this.name = 'SecurityCompromiseError';
}
}
export class ServiceCrashedError extends Error {
constructor({ message }: { message: string }) {
super(message);
this.name = 'ServiceCrashedError';
}
}

View File

@ -0,0 +1,88 @@
import { CloudHTTPv2 } from './decorators';
import { Ctx } from './types';
import { Logger } from './logger';
import { OutputServerEventStream } from './output-stream';
import { RPCReflect } from './rpc-reflect';
// Mock implementations
class AsyncContext {
// Add necessary methods based on usage in the codebase
set(key: string, value: any) {}
get(key: string): any { return null; }
}
class InsufficientBalanceError extends Error {
constructor(message: string) {
super(message);
this.name = 'InsufficientBalanceError';
}
}
function Param(name: string, options?: any): ParameterDecorator {
return (target: Object, propertyKey: string | symbol | undefined, parameterIndex: number) => {
// Implementation details would go here
};
}
// DONE
class FirebaseStorageBucketControl {
bucket: any; // Added bucket property
constructor() {
this.bucket = {
file: (fileName: string) => ({
exists: async () => [true]
})
};
}
async uploadFile(filePath: string, destination: string): Promise<string> {
console.log(`Mock: Uploading file from ${filePath} to ${destination}`);
return `https://storage.googleapis.com/mock-bucket/${destination}`;
}
async downloadFile(filePath: string, destination: string): Promise<void> {
console.log(`Mock: Downloading file from ${filePath} to ${destination}`);
}
async deleteFile(filePath: string): Promise<void> {
console.log(`Mock: Deleting file ${filePath}`);
}
async fileExists(filePath: string): Promise<boolean> {
console.log(`Mock: Checking if file ${filePath} exists`);
return true;
}
async saveFile(filePath: string, content: Buffer, options?: any): Promise<void> {
console.log(`Mock: Saving file ${filePath}`);
}
async signDownloadUrl(filePath: string, expirationTime: number): Promise<string> {
console.log(`Mock: Signing download URL for ${filePath}`);
return `https://storage.googleapis.com/mock-bucket/${filePath}?token=mock-signed-url`;
}
}
export {
CloudHTTPv2,
Ctx,
Logger,
OutputServerEventStream,
RPCReflect,
AsyncContext,
InsufficientBalanceError,
Param,
FirebaseStorageBucketControl,
};
export const loadModulesDynamically = (path: string) => {
// Simplified implementation
console.log(`Loading modules from ${path}`);
};
export const registry = {
exportAll: () => ({}),
exportGrouped: () => ({}),
allHandsOnDeck: async () => {},
};

View File

@ -0,0 +1,49 @@
import { Prop } from 'civkit';
export class FirestoreRecord {
static collectionName: string;
@Prop()
_id!: string;
static from(input: any): FirestoreRecord {
const instance = new this();
Object.assign(instance, input);
return instance;
}
static async fromFirestore(id: string): Promise<FirestoreRecord | undefined> {
// Mock implementation
console.log(`Fetching document with id ${id} from collection ${this.collectionName}`);
return undefined;
}
static async fromFirestoreQuery(query: any): Promise<FirestoreRecord[]> {
// Mock implementation
console.log(`Executing query on collection ${this.collectionName}`);
return [];
}
static async save(data: any): Promise<void> {
// Mock implementation
console.log(`Saving data to collection ${this.collectionName}`);
}
degradeForFireStore(): any {
// Default implementation
return { ...this };
}
static COLLECTION = {
doc: (id: string) => ({
set: (data: any, options?: any) => {
console.log(`Setting document ${id} in collection ${this.collectionName}`);
}
}),
where: () => ({
orderBy: () => ({
limit: () => ({})
})
})
};
}

View File

@ -0,0 +1,19 @@
export class Logger {
constructor(private name: string) {}
info(message: string, ...args: any[]) {
console.log(`[${this.name}] INFO:`, message, ...args);
}
warn(message: string, ...args: any[]) {
console.warn(`[${this.name}] WARN:`, message, ...args);
}
error(message: string, ...args: any[]) {
console.error(`[${this.name}] ERROR:`, message, ...args);
}
child(options: { service: string }) {
return new Logger(`${this.name}:${options.service}`);
}
}

View File

@ -0,0 +1,9 @@
export class OutputServerEventStream {
write(data: any) {
console.log('OutputServerEventStream write:', data);
}
end() {
console.log('OutputServerEventStream ended');
}
}

View File

@ -0,0 +1,5 @@
export function RPCReflect() {
return function (target: any, propertyKey: string | symbol, parameterIndex: number) {
console.log(`RPCReflect decorator applied to parameter ${parameterIndex} of ${String(propertyKey)}`);
};
}

View File

@ -0,0 +1,32 @@
import { AsyncService } from 'civkit';
import { singleton } from 'tsyringe';
import { Logger } from '../logger';
@singleton()
export class CanvasService extends AsyncService {
logger = this.globalLogger.child({ service: this.constructor.name });
constructor(protected globalLogger: Logger) {
super();
}
override async init() {
this.logger.info('CanvasService initialized');
this.emit('ready');
}
async loadImage(url: string): Promise<any> {
console.log(`Mock: Loading image from ${url}`);
return { width: 1000, height: 1000 };
}
fitImageToSquareBox(img: any, size: number): any {
console.log(`Mock: Fitting image to square box of size ${size}`);
return { width: size, height: size };
}
async canvasToBuffer(canvas: any, format: string): Promise<Buffer> {
console.log(`Mock: Converting canvas to buffer with format ${format}`);
return Buffer.from('mock image data');
}
}

View File

@ -0,0 +1,29 @@
import { AsyncService } from 'civkit';
export interface RateLimitDesc {
key: string;
limit: number;
window: number;
}
export class RateLimitControl extends AsyncService {
constructor() {
super();
}
override async init() {
// Mock implementation
this.emit('ready');
}
async increment(desc: RateLimitDesc): Promise<boolean> {
// Mock implementation
console.log(`Incrementing rate limit for key: ${desc.key}`);
return true;
}
async decrement(desc: RateLimitDesc): Promise<void> {
// Mock implementation
console.log(`Decrementing rate limit for key: ${desc.key}`);
}
}

View File

@ -0,0 +1,20 @@
import { AsyncService } from 'civkit';
import { singleton } from 'tsyringe';
import { Logger } from '../logger';
@singleton()
export class SecretExposer extends AsyncService {
logger = this.globalLogger.child({ service: this.constructor.name });
BRAVE_SEARCH_API_KEY: string = 'mock_brave_search_api_key';
constructor(protected globalLogger: Logger) {
super();
}
override async init() {
// Mock initialization
this.logger.info('SecretExposer initialized');
this.emit('ready');
}
}

View File

@ -0,0 +1,6 @@
import { Request, Response } from 'express';
export interface Ctx {
req: Request;
res: Response;
}