(options: SecretQueryOptions = {})
| 48 | ) {} |
| 49 | |
| 50 | async listSecrets(options: SecretQueryOptions = {}): Promise<SecretSummary[]> { |
| 51 | const baseQuery = this.db |
| 52 | .select({ |
| 53 | id: secrets.id, |
| 54 | name: secrets.name, |
| 55 | description: secrets.description, |
| 56 | tags: secrets.tags, |
| 57 | createdAt: secrets.createdAt, |
| 58 | updatedAt: secrets.updatedAt, |
| 59 | versionId: secretVersions.id, |
| 60 | version: secretVersions.version, |
| 61 | versionCreatedAt: secretVersions.createdAt, |
| 62 | versionCreatedBy: secretVersions.createdBy, |
| 63 | }) |
| 64 | .from(secrets) |
| 65 | .leftJoin( |
| 66 | secretVersions, |
| 67 | and(eq(secretVersions.secretId, secrets.id), eq(secretVersions.isActive, true)), |
| 68 | ); |
| 69 | |
| 70 | const conditions: SQL[] = []; |
| 71 | if (options.organizationId) { |
| 72 | conditions.push(eq(secrets.organizationId, options.organizationId)); |
| 73 | } |
| 74 | |
| 75 | const whereClause = |
| 76 | conditions.length === 0 |
| 77 | ? undefined |
| 78 | : conditions.length === 1 |
| 79 | ? conditions[0] |
| 80 | : and(...conditions); |
| 81 | |
| 82 | const rows = await (whereClause ? baseQuery.where(whereClause) : baseQuery).orderBy( |
| 83 | secrets.name, |
| 84 | ); |
| 85 | |
| 86 | return rows.map((row) => this.mapSummary(row)); |
| 87 | } |
| 88 | |
| 89 | async findByName(secretName: string, options: SecretQueryOptions = {}): Promise<SecretSummary> { |
| 90 | const conditions: SQL[] = [eq(secrets.name, secretName)]; |
nothing calls this directly
no test coverage detected