mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 11:42:32 +08:00
add mock shared libraries
This commit is contained in:
parent
88a6bd7131
commit
2d6447e8fc
0
backend/functions/src/shared/3rd-party/brave-search.ts
vendored
Normal file
0
backend/functions/src/shared/3rd-party/brave-search.ts
vendored
Normal file
7
backend/functions/src/shared/decorators.ts
Normal file
7
backend/functions/src/shared/decorators.ts
Normal 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;
|
||||
};
|
||||
}
|
13
backend/functions/src/shared/errors.ts
Normal file
13
backend/functions/src/shared/errors.ts
Normal 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';
|
||||
}
|
||||
}
|
88
backend/functions/src/shared/index.ts
Normal file
88
backend/functions/src/shared/index.ts
Normal 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 () => {},
|
||||
};
|
49
backend/functions/src/shared/lib/firestore.ts
Normal file
49
backend/functions/src/shared/lib/firestore.ts
Normal 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: () => ({})
|
||||
})
|
||||
})
|
||||
};
|
||||
}
|
19
backend/functions/src/shared/logger.ts
Normal file
19
backend/functions/src/shared/logger.ts
Normal 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}`);
|
||||
}
|
||||
}
|
9
backend/functions/src/shared/output-stream.ts
Normal file
9
backend/functions/src/shared/output-stream.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export class OutputServerEventStream {
|
||||
write(data: any) {
|
||||
console.log('OutputServerEventStream write:', data);
|
||||
}
|
||||
|
||||
end() {
|
||||
console.log('OutputServerEventStream ended');
|
||||
}
|
||||
}
|
5
backend/functions/src/shared/rpc-reflect.ts
Normal file
5
backend/functions/src/shared/rpc-reflect.ts
Normal 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)}`);
|
||||
};
|
||||
}
|
32
backend/functions/src/shared/services/canvas.ts
Normal file
32
backend/functions/src/shared/services/canvas.ts
Normal 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');
|
||||
}
|
||||
}
|
29
backend/functions/src/shared/services/rate-limit.ts
Normal file
29
backend/functions/src/shared/services/rate-limit.ts
Normal 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}`);
|
||||
}
|
||||
}
|
20
backend/functions/src/shared/services/secrets.ts
Normal file
20
backend/functions/src/shared/services/secrets.ts
Normal 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');
|
||||
}
|
||||
}
|
6
backend/functions/src/shared/types.ts
Normal file
6
backend/functions/src/shared/types.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Request, Response } from 'express';
|
||||
|
||||
export interface Ctx {
|
||||
req: Request;
|
||||
res: Response;
|
||||
}
|
Loading…
Reference in New Issue
Block a user