Skip to content

Commit

Permalink
compiler breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava committed Dec 17, 2024
1 parent bdef079 commit 146b4ed
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions servers/fdr/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * as Algolia from "./generated/api/resources/algolia";
export { LatestService as APILatestService } from "./generated/api/resources/api/resources/latest/service/LatestService";
export { ReadService as APIV1ReadService } from "./generated/api/resources/api/resources/v1/resources/read/service/ReadService";
export { RegisterService as APIV1WriteService } from "./generated/api/resources/api/resources/v1/resources/register/service/RegisterService";
export { DiffService } from "./generated/api/resources/diff/service/DiffService";
Expand Down
35 changes: 35 additions & 0 deletions servers/fdr/src/controllers/api/getApiLatestService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { APILatestService } from "../../api";
import { UserNotInOrgError } from "../../api/generated/api";
import { ApiDoesNotExistError } from "../../api/generated/api/resources/api/resources/v1/resources/read/errors";
import type { FdrApplication } from "../../app";

export function getApiLatestService(app: FdrApplication): APILatestService {
return new APILatestService({
getApiLatest: async (req, res) => {
try {
// if the auth header belongs to fern, return the api definition
await app.services.auth.checkUserBelongsToOrg({
authHeader: req.headers.authorization,
orgId: "fern",
});
} catch (e) {
if (e instanceof UserNotInOrgError) {
const orgId = await app.dao.apis().getOrgIdForApiDefinition(req.params.apiDefinitionId);
if (orgId == null) {
throw new ApiDoesNotExistError();
}
await app.services.auth.checkUserBelongsToOrg({
authHeader: req.headers.authorization,
orgId,
});
}
throw e;
}
const apiDefinition = await app.dao.apis().loadAPILatestDefinition(req.params.apiDefinitionId);
if (apiDefinition == null) {
throw new ApiDoesNotExistError();
}
return res.send(apiDefinition);
},
});
}
2 changes: 1 addition & 1 deletion servers/fdr/src/controllers/docs/v1/getDocsReadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export async function getDocsDefinition({
app.services.db.prisma.apiDefinitionsLatest.findMany({
where: {
apiDefinitionId: {
in: Array.from(docsDbDefinition.referencedApisLatest),
in: Array.from(docsDbDefinition.referencedApis),
},
},
}),
Expand Down
21 changes: 20 additions & 1 deletion servers/fdr/src/db/api/APIDefinitionDao.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIV1Db } from "@fern-api/fdr-sdk";
import { APIV1Db, FdrAPI } from "@fern-api/fdr-sdk";
import { PrismaClient } from "@prisma/client";
import { readBuffer } from "../../util";

Expand All @@ -7,6 +7,8 @@ export interface APIDefinitionDao {

loadAPIDefinition(apiDefinitionId: string): Promise<APIV1Db.DbApiDefinition | undefined>;

loadAPILatestDefinition(apiDefinitionId: string): Promise<FdrAPI.api.latest.ApiDefinition | undefined>;

loadAPIDefinitions(apiDefinitionIds: string[]): Promise<Record<string, APIV1Db.DbApiDefinition>>;
}

Expand Down Expand Up @@ -40,6 +42,23 @@ export class APIDefinitionDaoImpl implements APIDefinitionDao {
return readBuffer(apiDefinition.definition) as APIV1Db.DbApiDefinition;
}

public async loadAPILatestDefinition(
apiDefinitionId: string,
): Promise<FdrAPI.api.latest.ApiDefinition | undefined> {
const apiDefinition = await this.prisma.apiDefinitionsLatest.findFirst({
where: {
apiDefinitionId,
},
select: {
definition: true,
},
});
if (apiDefinition == null) {
return undefined;
}
return readBuffer(apiDefinition.definition) as FdrAPI.api.latest.ApiDefinition;
}

public async loadAPIDefinitions(apiDefinitionIds: string[]): Promise<Record<string, APIV1Db.DbApiDefinition>> {
const apiDefinitions = await this.prisma.apiDefinitionsV2.findMany({
where: {
Expand Down
1 change: 1 addition & 0 deletions servers/fdr/src/healthchecks/checkRedis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const HEALTHCHECK_DOCS_RESPONSE: CachedDocsResponse = {
definition: {
pages: {},
apis: {},
apisLatest: {},
config: {
navigation: {
items: [],
Expand Down

0 comments on commit 146b4ed

Please sign in to comment.