import type { Client } from './client'; import type { ILevoCollection, LevoCollectionCreateInput, LevoCollectionRoot, LevoCollectionUpdateInput } from './generated'; import type { BaseOptions } from './types'; import type { ExtractTypeKeys, NonNullableKeys } from './types/lema'; import type { LevoQuery, LevoResponse } from './types/types'; type IncrementData = Partial, number>>; export declare class Content { private client; constructor(client: Client); /** * Counts the number of documents in the collection * * This method will return the number of documents in the collection that match the query. * * @example * * const count = await levo.content.count('posts', { title: 'Hello World' }); * // count = 1 * * This will return the count of 1 from the 'posts' collection where the 'title' field is equal to 'Hello World' * * @param {string} key - The key of the collection * @param {LevoQuery.FindQuery} [where] - The query to filter the documents * @returns The number of documents in the collection */ count(key: T, where?: LevoQuery.Where, options?: BaseOptions): Promise; /** * Perform an aggregation query on the specified collection. * * This method allows you to execute aggregation operations such as sum, average, count, * and more on a collection. It supports grouping, filtering, sorting, and pagination. * * @example * * const query = { * group: ["category"], * aggregate: [{ column: "price", by: "sum" }], * where: { created_at: { gte: new Date(2023, 0, 1) } }, * sort: { sum_price: "desc" }, * page: 1, * limit: 10 * }; * * const result = await levo.content.aggregate('orders', query); * * This will group orders by category, calculate the total price for each group, * filter orders created after January 1, 2023, and return the top 10 results sorted by total price in descending order. * * @example * console.log(result.data); * * [ * { category: "Electronics", sum_price: 150000 }, * { category: "Furniture", sum_price: 85000 }, * { category: "Clothing", sum_price: 45000 } * ] * * @param {string} key - The key of the collection. * @param {LevoQuery.AggregateQuery} query - The aggregation query with filters, grouping, and operations. * @param {BaseOptions} [options] - Additional options for the query execution. * @returns A promise that resolves to the aggregated query results. */ aggregate(key: T, query?: LevoQuery.AggregateQuery, options?: BaseOptions): Promise>; /** * Get a single document from the collection by its id or unique fields * * This method will return the document with the specified id or `null` if the document is not found * * @example * * const document = await levo.content.findUnique('posts', '12345'); * * This will return the document with the id '12345' from the 'posts' collection * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @returns The document with the specified id */ findUnique(key: T, id: string, options?: BaseOptions): Promise; /** * * Get the first document from the collection that matches the query * * This method will return the first document that matches the query or `null` if no document is found * * @example * * const query = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const document = await levo.content.findFirst('posts', query); * * This will return the first document that was created after January 1, 2023 * * @param {string} key - The key of the collection * @param query - The query to filter the documents * @returns The first document that matches the query */ findFirst(key: T, query?: LevoQuery.FindQuery, options?: BaseOptions): Promise; /** * * Get all documents from the collection that match the query * * This method will return an array of documents that match the query or an empty array if no documents are found * * @example * * const query = { * where:{ * created_at: { * gte: new Date(2023, 0, 1), * } * } * } * * const documents = await levo.content.findMany('posts', query); * * This will return all documents that were created after January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.FindQuery} query - The query to filter the documents * @returns An array of documents that match the query */ findMany(key: T, query?: LevoQuery.FindQuery, options?: BaseOptions): Promise>; /** * * Get all documents from the collection that match the query * * This method will return an array of documents that match the query or an empty array if no documents are found * * @example * * const query = { * where:{ * created_at: { * gte: new Date(2023, 0, 1), * } * } * } * * const documents = await levo.content.findManyV2('posts', query); * * This will return all documents that were created after January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.FindQuery} query - The query to filter the documents * @returns An array of documents that match the query */ findManyV2(key: T, query?: LevoQuery.FindQuery, options?: BaseOptions): Promise>; /** * Create a new document in the collection with the specified data * * This method will create a new document in the collection with the specified data and return the created document * * @example * * const data = { * title: 'My First Post', * content: 'This is my first post', * created_at: new Date(), * updated_at: new Date(), * _status: 'published', * comments: 0, * likes: 0 * } * * const document = await levo.content.create('posts', data); * * This will create a new document in the 'posts' collection with the specified data * * @param {string} key - The key of the collection * @param {LevoCollectionCreateInput[T]} data - The data to create the document * @returns The created document */ create(key: T, data: LevoCollectionCreateInput[T], options?: BaseOptions): Promise; /** * * Create multiple new documents in the collection with the specified data * * This method will create multiple new documents in the collection with the specified data and return the created documents * * @example * * const data = [ * { * title: 'My First Post', * content: 'This is my first post', * created_at: new Date(), * updated_at: new Date(), * _status: 'published', * comments: 0, * likes: 0 * }, * { * title: 'My Second Post', * content: 'This is my second post', * created_at: new Date(), * updated_at: new Date(), * _status: 'published', * comments: 0, * likes: 0 * } * ] * * const documents = await levo.content.createMany('posts', data); * * This will create two new documents in the 'posts' collection with the specified data * * @param {string} key - The key of the collection * @param {LevoCollectionCreateInput[T][]} data - The array of data to create the documents * @returns The array of created documents */ createBulk(key: T, data: LevoCollectionCreateInput[T][], options?: BaseOptions): Promise; /** * @deprecated Use `createBulk` instead. */ createMany(key: T, data: LevoCollectionCreateInput[T][], options?: BaseOptions): Promise; /** * Update a document in the collection with the specified data * * This method will update the document with the specified id in the collection with the specified data and return the updated document * * @example * * const data = { * title: 'My Updated Post', * content: 'This is my updated post' * } * * const document = await levo.content.update('posts', '12345', data); * * This will update the document with the id '12345' in the 'posts' collection with the specified data * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @param {LevoCollectionUpdateInput[T]} data - The data to update the document * @returns The updated document */ edit(key: T, id: string, data: LevoCollectionUpdateInput[T], options?: BaseOptions): Promise; /** * * Update multiple documents in the collection with the specified data * * This method will update multiple documents in the collection with the specified data and return the number of documents that were updated * * @example * * const where = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const data = { * title: 'My Updated Post', * content: 'This is my updated post' * } * * const updated = await levo.content.editMany('posts', where, data); * * This will update all documents in the 'posts' collection that have the 'created_at' field greater than or equal to January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.Where} where - The query to filter the documents * @param {LevoCollectionUpdateInput[T]} data - The data to update the document * @returns The number of documents that were updated */ editBulk(key: T, where: LevoQuery.Where, data: LevoCollectionUpdateInput[T], options?: BaseOptions): Promise; /** * @deprecated Use `editBulk` instead. */ editMany(key: T, where: LevoQuery.Where, data: LevoCollectionUpdateInput[T], options?: BaseOptions): Promise; /** * Increment or decrement the values of the fields in the document * * The value you provide for the fields will be added/removed to the existing value * * @example * * const data = { * comments: 10, * likes: -1 * } * * await levo.content.increment('posts', id, data); * * This will increment the `comments` field by 10 and decrement the `likes` field by -1 * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @param {IncrementData} data - The data containing the fields and their values to increment * @returns A boolean indicating whether the operation was successful */ increment(key: T, id: string, data: IncrementData, options?: BaseOptions): Promise; /** * Increment or decrement the values of the fields in many document * * The value you provide for the fields will be added/removed to the existing value * * @example * * const where = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const data = { * comments: 10, * likes: -1 * } * * await levo.content.incrementMany('posts', where, data); * * This will increment the `comments` field by 10 and decrement the `likes` field by -1 for all documents that match the `where` condition * * @param {string} key - The key of the collection * @param {LevoQuery.Where} where - The query to filter the documents * @param {IncrementData} data - The data containing the fields and their values to increment * @returns The number of documents that were incremented */ incrementBulk(key: T, where: LevoQuery.Where, data: IncrementData, options?: BaseOptions): Promise; /** * @deprecated Use `incrementBulk` instead. */ incrementMany(key: T, where: LevoQuery.Where, data: IncrementData, options?: BaseOptions): Promise; /** * * Publish a document in the collection * * This method will publish the document with the specified id in the collection and return a boolean indicating whether the operation was successful * * @example * * const published = await levo.content.publish('posts', '12345'); * * This will publish the document with the id '12345' in the 'posts' collection * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @returns A boolean indicating whether the operation was successful */ publish(key: T, id: string, options?: BaseOptions): Promise; /** * * Publish multiple documents in the collection * * This method will publish multiple documents in the collection that match the query and return the number of documents that were published * * @example * * const where = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const published = await levo.content.publishMany('posts', where); * * This will publish all documents in the 'posts' collection that have the 'created_at' field greater than or equal to January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.Where} where - The query to filter the documents * @returns The number of documents that were published */ publishBulk(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; /** * @deprecated Use `publishBulk` instead. */ publishMany(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; /** * * Unpublish a document in the collection * * This method will unpublish the document with the specified id in the collection and return a boolean indicating whether the operation was successful * * @example * * const unpublished = await levo.content.unpublish('posts', '12345'); * * This will unpublish the document with the id '12345' in the 'posts' collection * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @returns A boolean indicating whether the operation was successful */ unpublish(key: T, id: string, options?: BaseOptions): Promise; /** * * Unpublish multiple documents in the collection * * This method will publish multiple documents in the collection that match the query and return the number of documents that were published * * @example * * const where = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const unpublished = await levo.content.unpublishMany('posts', where); * * This will unpublish all documents in the 'posts' collection that have the 'created_at' field greater than or equal to January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.Where} where - The query to filter the documents * @returns */ unpublishBulk(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; /** * @deprecated Use `unpublishBulk` instead. */ unpublishMany(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; /** * * Remove a document from the collection * * This method will remove the document with the specified id from the collection and return the removed document * * @example * * const document = await levo.content.remove('posts', '12345'); * * This will remove the document with the id '12345' from the 'posts' collection * * @param {string} key - The key of the collection * @param {string} id - The id of the document * @returns The removed document */ remove(key: T, id: string, options?: BaseOptions): Promise; /** * * Remove multiple documents from the collection * * This method will remove multiple documents from the collection that match the query and return the number of documents that were removed * * @example * * const where = { * created_at: { * gte: new Date(2023, 0, 1), * } * } * * const removed = await levo.content.removeMany('posts', where); * * This will remove all documents from the 'posts' collection that have the 'created_at' field greater than or equal to January 1, 2023 * * @param {string} key - The key of the collection * @param {LevoQuery.Where} where - The query to filter the documents * @returns */ removeBulk(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; /** * @deprecated Use `removeBulk` instead. */ removeMany(key: T, where: LevoQuery.Where, options?: BaseOptions): Promise; } export {};