mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-11 00:02:38 +02:00
use strong typing in mongo repos
This commit is contained in:
parent
53219974d3
commit
0131c2a111
7 changed files with 15 additions and 15 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { CreateDeploymentSchema, IComposioTriggerDeploymentsRepository } from "@/src/application/repositories/composio-trigger-deployments.repository.interface";
|
import { CreateDeploymentSchema, IComposioTriggerDeploymentsRepository } from "@/src/application/repositories/composio-trigger-deployments.repository.interface";
|
||||||
import { ComposioTriggerDeployment } from "@/src/entities/models/composio-trigger-deployment";
|
import { ComposioTriggerDeployment } from "@/src/entities/models/composio-trigger-deployment";
|
||||||
|
|
@ -135,7 +135,7 @@ export class MongodbComposioTriggerDeploymentsRepository implements IComposioTri
|
||||||
* Retrieves all trigger deployments for a specific project with pagination.
|
* Retrieves all trigger deployments for a specific project with pagination.
|
||||||
*/
|
*/
|
||||||
async listByProjectId(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ComposioTriggerDeployment>>>> {
|
async listByProjectId(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ComposioTriggerDeployment>>>> {
|
||||||
const query: any = { projectId };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId };
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
query._id = { $gt: new ObjectId(cursor) };
|
query._id = { $gt: new ObjectId(cursor) };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { AddTurnData, CreateConversationData, IConversationsRepository, ListedConversationItem } from "@/src/application/repositories/conversations.repository.interface";
|
import { AddTurnData, CreateConversationData, IConversationsRepository, ListedConversationItem } from "@/src/application/repositories/conversations.repository.interface";
|
||||||
import { Conversation } from "@/src/entities/models/conversation";
|
import { Conversation } from "@/src/entities/models/conversation";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
|
|
@ -76,7 +76,7 @@ export class MongoDBConversationsRepository implements IConversationsRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedConversationItem>>>> {
|
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedConversationItem>>>> {
|
||||||
const query: any = { projectId };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId };
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
query._id = { $lt: new ObjectId(cursor) };
|
query._id = { $lt: new ObjectId(cursor) };
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { DataSource } from "@/src/entities/models/data-source";
|
import { DataSource } from "@/src/entities/models/data-source";
|
||||||
import {
|
import {
|
||||||
|
|
@ -68,7 +68,7 @@ export class MongoDBDataSourcesRepository implements IDataSourcesRepository {
|
||||||
cursor?: string,
|
cursor?: string,
|
||||||
limit: number = 50
|
limit: number = 50
|
||||||
): Promise<z.infer<ReturnType<typeof PaginatedList<typeof DataSource>>>> {
|
): Promise<z.infer<ReturnType<typeof PaginatedList<typeof DataSource>>>> {
|
||||||
const query: any = { projectId, status: { $ne: "deleted" } };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId, status: { $ne: "deleted" } };
|
||||||
|
|
||||||
// Default behavior: exclude deleted unless explicitly asked for
|
// Default behavior: exclude deleted unless explicitly asked for
|
||||||
if (filters?.deleted === true) {
|
if (filters?.deleted === true) {
|
||||||
|
|
@ -92,7 +92,7 @@ export class MongoDBDataSourcesRepository implements IDataSourcesRepository {
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
const hasNextPage = results.length > _limit;
|
const hasNextPage = results.length > _limit;
|
||||||
const items = results.slice(0, _limit).map((doc: any) => {
|
const items = results.slice(0, _limit).map((doc) => {
|
||||||
const { _id, ...rest } = doc;
|
const { _id, ...rest } = doc;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { CreateJobSchema, IJobsRepository, JobFiltersSchema, ListedJobItem, UpdateJobSchema } from "@/src/application/repositories/jobs.repository.interface";
|
import { CreateJobSchema, IJobsRepository, JobFiltersSchema, ListedJobItem, UpdateJobSchema } from "@/src/application/repositories/jobs.repository.interface";
|
||||||
import { Job } from "@/src/entities/models/job";
|
import { Job } from "@/src/entities/models/job";
|
||||||
|
|
@ -206,7 +206,7 @@ export class MongoDBJobsRepository implements IJobsRepository {
|
||||||
cursor?: string,
|
cursor?: string,
|
||||||
limit: number = 50
|
limit: number = 50
|
||||||
): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedJobItem>>>> {
|
): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedJobItem>>>> {
|
||||||
const query: any = { projectId };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId };
|
||||||
|
|
||||||
const _limit = Math.min(limit, 50);
|
const _limit = Math.min(limit, 50);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { CreateProjectMemberSchema, IProjectMembersRepository } from "@/src/appl
|
||||||
import { ProjectMember } from "@/src/entities/models/project-member";
|
import { ProjectMember } from "@/src/entities/models/project-member";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { PaginatedList } from "@/src/entities/common/paginated-list";
|
import { PaginatedList } from "@/src/entities/common/paginated-list";
|
||||||
|
|
||||||
const docSchema = ProjectMember.omit({
|
const docSchema = ProjectMember.omit({
|
||||||
|
|
@ -45,7 +45,7 @@ export class MongoDBProjectMembersRepository implements IProjectMembersRepositor
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByUserId(userId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ProjectMember>>>> {
|
async findByUserId(userId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ProjectMember>>>> {
|
||||||
const query: any = { userId };
|
const query: Filter<z.infer<typeof docSchema>> = { userId };
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
query._id = { $lt: new ObjectId(cursor) };
|
query._id = { $lt: new ObjectId(cursor) };
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { CreateRecurringRuleSchema, IRecurringJobRulesRepository, ListedRecurringRuleItem } from "@/src/application/repositories/recurring-job-rules.repository.interface";
|
import { CreateRecurringRuleSchema, IRecurringJobRulesRepository, ListedRecurringRuleItem } from "@/src/application/repositories/recurring-job-rules.repository.interface";
|
||||||
import { RecurringJobRule } from "@/src/entities/models/recurring-job-rule";
|
import { RecurringJobRule } from "@/src/entities/models/recurring-job-rule";
|
||||||
|
|
@ -170,7 +170,7 @@ export class MongoDBRecurringJobRulesRepository implements IRecurringJobRulesRep
|
||||||
* Lists recurring job rules for a specific project with pagination.
|
* Lists recurring job rules for a specific project with pagination.
|
||||||
*/
|
*/
|
||||||
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedRecurringRuleItem>>>> {
|
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedRecurringRuleItem>>>> {
|
||||||
const query: any = { projectId };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId };
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
query._id = { $lt: new ObjectId(cursor) };
|
query._id = { $lt: new ObjectId(cursor) };
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { ObjectId } from "mongodb";
|
import { Filter, ObjectId } from "mongodb";
|
||||||
import { db } from "@/app/lib/mongodb";
|
import { db } from "@/app/lib/mongodb";
|
||||||
import { CreateRuleSchema, IScheduledJobRulesRepository, ListedRuleItem, UpdateJobSchema } from "@/src/application/repositories/scheduled-job-rules.repository.interface";
|
import { CreateRuleSchema, IScheduledJobRulesRepository, ListedRuleItem, UpdateJobSchema } from "@/src/application/repositories/scheduled-job-rules.repository.interface";
|
||||||
import { ScheduledJobRule } from "@/src/entities/models/scheduled-job-rule";
|
import { ScheduledJobRule } from "@/src/entities/models/scheduled-job-rule";
|
||||||
|
|
@ -187,7 +187,7 @@ export class MongoDBScheduledJobRulesRepository implements IScheduledJobRulesRep
|
||||||
* Lists scheduled job rules for a specific project with pagination.
|
* Lists scheduled job rules for a specific project with pagination.
|
||||||
*/
|
*/
|
||||||
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedRuleItem>>>> {
|
async list(projectId: string, cursor?: string, limit: number = 50): Promise<z.infer<ReturnType<typeof PaginatedList<typeof ListedRuleItem>>>> {
|
||||||
const query: any = { projectId };
|
const query: Filter<z.infer<typeof DocSchema>> = { projectId };
|
||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
query._id = { $lt: new ObjectId(cursor) };
|
query._id = { $lt: new ObjectId(cursor) };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue