magically-sdk
Version:
Official SDK for Magically - Build mobile apps with AI
109 lines (108 loc) • 4 kB
TypeScript
import { SDKConfig, StandardFields } from './types';
import { MagicallyAuth } from './MagicallyAuth';
export declare class MagicallyData {
private config;
private auth;
private apiClient;
constructor(config: SDKConfig, auth: MagicallyAuth);
/**
* Check if a query is public (doesn't require authentication)
*/
private isPublicQuery;
/**
* Check if an aggregate pipeline is public (doesn't require authentication)
*/
private isPublicAggregate;
/**
* Check if a raw operation is public (read-only with isPublic filter)
*/
private isPublicRawOperation;
/**
* Query data from a collection with type safety
* @param collection - Collection name
* @param filter - MongoDB filter object (optional)
* @param options - Query options (sort, limit, skip)
*/
query<T extends StandardFields>(collection: string, filter?: Record<string, any>, options?: {
sort?: Record<string, number>;
limit?: number;
skip?: number;
populate?: string[];
}): Promise<{
data: T[];
total: number;
}>;
/**
* Insert data into a collection with type safety
*/
insert<T extends StandardFields>(collection: string, data: Omit<T, keyof StandardFields>, options?: {
upsert?: boolean;
}): Promise<T>;
/**
* Update existing data in a collection (fails if not found)
*/
update<T extends StandardFields>(collection: string, filter: Record<string, any>, update: any): Promise<T>;
/**
* Upsert data in a collection (update if exists, insert if not)
* @param collection - Collection name
* @param filter - Filter to find existing document
* @param data - Data to insert or update
* @returns The upserted document and whether it was inserted
*/
upsert<T extends StandardFields>(collection: string, filter: Record<string, any>, data: Omit<T, keyof StandardFields>): Promise<{
data: T;
upserted: boolean;
}>;
/**
* Update multiple documents in a collection
* @param collection - Collection name
* @param filter - MongoDB filter to find documents to update
* @param update - Update data or MongoDB update object
* @returns Number of matched and modified documents
*/
updateMany<T extends StandardFields>(collection: string, filter: Record<string, any>, update: any): Promise<{
matchedCount: number;
modifiedCount: number;
}>;
/**
* Count documents in a collection
* @param collection - Collection name
* @param filter - Optional MongoDB filter
* @returns Count of matching documents
*/
count(collection: string, filter?: Record<string, any>): Promise<{
count: number;
}>;
/**
* Delete data from a collection (deletes multiple documents)
*/
delete(collection: string, filter: Record<string, any>): Promise<{
deletedCount: number;
}>;
/**
* Delete a single document from a collection
* @param collection - Collection name
* @param filter - MongoDB filter to find the document to delete
* @returns Number of deleted documents (0 or 1)
*/
deleteOne(collection: string, filter: Record<string, any>): Promise<{
deletedCount: number;
}>;
/**
* Delete multiple documents from a collection (alias for delete)
* @param collection - Collection name
* @param filter - MongoDB filter to find documents to delete
* @returns Number of deleted documents
*/
deleteMany(collection: string, filter: Record<string, any>): Promise<{
deletedCount: number;
}>;
/**
* Run aggregation query with type safety
*/
aggregate<T = any>(collection: string, pipeline: any[]): Promise<T[]>;
/**
* Run raw MongoDB operations with type safety and validation
*/
raw<T = any>(collection: string, operation: string, options?: Record<string, any>): Promise<T>;
}