| 955 | }) |
| 956 | |
| 957 | function listByProject( |
| 958 | db: Database.Interface["db"], |
| 959 | input: ListInput & { |
| 960 | projectID: ProjectV2.ID |
| 961 | experimentalWorkspaces: boolean |
| 962 | }, |
| 963 | ) { |
| 964 | const conditions = [eq(SessionTable.project_id, input.projectID)] |
| 965 | |
| 966 | if (input.workspaceID) { |
| 967 | conditions.push(eq(SessionTable.workspace_id, input.workspaceID)) |
| 968 | } |
| 969 | if (input.path !== undefined) { |
| 970 | if (input.path) { |
| 971 | const conds = [ |
| 972 | eq(SessionTable.path, input.path), |
| 973 | like(SessionTable.path, sql.param(`${input.path}/%`, SessionTable.path)), |
| 974 | ] |
| 975 | |
| 976 | conditions.push( |
| 977 | input.directory |
| 978 | ? or(...conds, and(isNull(SessionTable.path), eq(SessionTable.directory, input.directory))!)! |
| 979 | : or(...conds)!, |
| 980 | ) |
| 981 | } |
| 982 | } else if (input.scope !== "project") { |
| 983 | if (input.directory) { |
| 984 | conditions.push(eq(SessionTable.directory, input.directory)) |
| 985 | } |
| 986 | } |
| 987 | if (input.roots) { |
| 988 | conditions.push(isNull(SessionTable.parent_id)) |
| 989 | } |
| 990 | if (input.start) { |
| 991 | conditions.push(gte(SessionTable.time_updated, input.start)) |
| 992 | } |
| 993 | if (input.search) { |
| 994 | conditions.push(like(SessionTable.title, `%${input.search}%`)) |
| 995 | } |
| 996 | |
| 997 | const limit = input.limit ?? 100 |
| 998 | |
| 999 | return db |
| 1000 | .select() |
| 1001 | .from(SessionTable) |
| 1002 | .where(and(...conditions)) |
| 1003 | .orderBy(desc(SessionTable.time_updated)) |
| 1004 | .limit(limit) |
| 1005 | .all() |
| 1006 | .pipe( |
| 1007 | Effect.orDie, |
| 1008 | Effect.map((rows) => rows.map(fromRow)), |
| 1009 | ) |
| 1010 | } |
| 1011 | |
| 1012 | export const node = LayerNode.make({ |
| 1013 | service: Service, |