Skip to content

Commit

Permalink
fix: remove internal dependencies from fdr-sdk (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Jun 6, 2024
1 parent d470d6d commit 4c4f470
Show file tree
Hide file tree
Showing 66 changed files with 590 additions and 277 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/fdr-ete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jobs:
uses: ./.github/actions/install

- name: Setup database
# TODO: re-enable when moving to turbo
# pnpm turbo --filter= docker:local
run: |
cd servers/fdr
pnpm run docker:local
pnpm run test:ete
pnpm turbo --filter=@fern-platform/fdr docker:local
pnpm --filter=@fern-platform/fdr run test:ete
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"tailwindcss": "^3.4.3",
"ts-node": "^10.9.1",
"tsx": "^4.7.1",
"turbo": "^1.12.5",
"turbo": "^2.0.1",
"typescript": "5.4.3",
"typescript-plugin-css-modules": "^5.1.0",
"vitest": "^1.5.0"
Expand Down
1 change: 0 additions & 1 deletion packages/commons/core-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export { withMinimumTime } from "./delay/withMinimumTime";
export { EMPTY_ARRAY, EMPTY_OBJECT } from "./empty";
export { identity } from "./identity";
export { assertNonNullish, isNonNullish } from "./isNonNullish";
export * from "./lodash";
export { noop } from "./noop";
export { entries, type Entries } from "./objects/entries";
export { isPlainObject } from "./objects/isPlainObject";
Expand Down
17 changes: 9 additions & 8 deletions packages/commons/fdr-utils/src/docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DocsV1Read, FernNavigation } from "@fern-api/fdr-sdk";
import { DocsV1Read } from "@fern-api/fdr-sdk";
import { Availability } from "@fern-api/fdr-sdk/navigation";

export function isVersionedNavigationConfig(
navigationConfig: DocsV1Read.NavigationConfig,
Expand Down Expand Up @@ -42,19 +43,19 @@ export function assertIsUnversionedNavigationConfig(
}
}

export function getVersionAvailabilityLabel(availability: FernNavigation.Availability): string {
export function getVersionAvailabilityLabel(availability: Availability): string {
switch (availability) {
case FernNavigation.Availability.Beta:
case Availability.Beta:
return "beta";
case FernNavigation.Availability.Deprecated:
case Availability.Deprecated:
return "deprecated";
case FernNavigation.Availability.GenerallyAvailable:
case Availability.GenerallyAvailable:
return "generally available";
case FernNavigation.Availability.Stable:
case Availability.Stable:
return "stable";
case FernNavigation.Availability.InDevelopment:
case Availability.InDevelopment:
return "in development";
case FernNavigation.Availability.PreRelease:
case Availability.PreRelease:
return "pre-release";
default:
return "unknown";
Expand Down
3 changes: 2 additions & 1 deletion packages/commons/fdr-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist", "rootDir": "./src" },
"include": ["./src/**/*"]
"include": ["./src/**/*"],
"references": [{ "path": "../../fdr-sdk" }]
}
15 changes: 12 additions & 3 deletions packages/fdr-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@
"type": "module",
"module": "dist/index.js",
"source": "src/index.ts",
"exports": {
"./navigation": {
"types": "./dist/navigation/index.d.ts",
"import": "./dist/navigation/index.js"
},
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"dependencies": {
"@fern-ui/core-utils": "workspace:*",
"dayjs": "^1.11.11",
"fast-deep-equal": "^3.1.3",
"form-data": "4.0.0",
"js-base64": "3.7.7",
"qs": "6.12.0",
"tinycolor2": "^1.6.0",
"title": "^3.5.3",
"url-join": "4.0.1"
},
"devDependencies": {
Expand All @@ -27,11 +37,10 @@
"@fern-platform/configs": "workspace:*",
"@types/qs": "6.9.14",
"@types/tinycolor2": "^1.4.6",
"@types/title": "^3.4.3",
"@types/url-join": "4.0.1",
"eslint": "^8.56.0",
"eslint-config-custom": "*",
"prettier": "^3.2.4",
"tsconfig": "*",
"typescript": "5.4.3",
"vitest": "^1.5.0"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/fdr-sdk/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export * as APIV1Read from "./generated/api/resources/api/resources/v1/resources
export * as APIV1Write from "./generated/api/resources/api/resources/v1/resources/register";
export * as DocsV2Read from "./generated/api/resources/docs/resources/v2/resources/read";
export * as DocsV2Write from "./generated/api/resources/docs/resources/v2/resources/write";
export * as Snippets from "./generated/api/resources/snippets/types";
export * from "./generated/core/fetcher/APIResponse";
export { visitDbNavigationConfig, visitUnversionedDbNavigationConfig } from "./visitDbNavigationConfig";
export { visitDbNavigationTab, visitWriteNavigationTab } from "./visitNavigationTab";
export { visitReadNavigationConfig, visitUnversionedReadNavigationConfig } from "./visitReadNavigationConfig";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { kebabCase, titleCase } from "@fern-ui/core-utils";
import isEqual from "fast-deep-equal";
import { APIV1Db, APIV1Read, APIV1Write, FdrAPI } from "../../client";
import { kebabCase, titleCase } from "../../utils";
import { WithoutQuestionMarks } from "../utils/WithoutQuestionMarks";
import { assertNever } from "../utils/assertNever";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { kebabCase } from "@fern-ui/core-utils";
import {
DocsV1Db,
DocsV1Read,
Expand All @@ -10,6 +9,7 @@ import {
visitWriteNavigationConfig,
} from "../../client";
import { isNavigationTabLink } from "../../client/visitNavigationTab";
import { kebabCase } from "../../utils";
import { type WithoutQuestionMarks } from "../utils/WithoutQuestionMarks";
import { assertNever } from "../utils/assertNever";
import { DEFAULT_DARK_MODE_ACCENT_PRIMARY, DEFAULT_LIGHT_MODE_ACCENT_PRIMARY } from "../utils/colors";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class SDKSnippetHolder {
return exampleId != null && snippet.exampleIdentifier === exampleId;
});
// if no example match, just pick first snippet for backwards-compatibility reasons
if (snippets.length === 0) {
if (snippets.length === 0 && snippetsForEndpoint[0] != null) {
snippets = [snippetsForEndpoint[0]];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPlainObject } from "@fern-ui/core-utils";
import { DocsV1Db } from "../../../client";
import { isPlainObject } from "../../../utils";
import { upgradeV1ToV2 } from "./upgradeV1ToV2";
import { upgradeV2ToV3 } from "./upgradeV2ToV3";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mapValues } from "@fern-ui/core-utils";
import { DocsV1Db } from "../../../client";
import { mapValues } from "../../../utils";

export function upgradeV2ToV3(v2: DocsV1Db.DocsDefinitionDb.V2): DocsV1Db.DocsDefinitionDb.V3 {
return {
Expand Down
52 changes: 26 additions & 26 deletions packages/fdr-sdk/src/converters/read/convertDbDocsConfigToRead.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { kebabCase } from "@fern-ui/core-utils";
import tinycolor from "tinycolor2";
import { DocsV1Db, DocsV1Read, visitDbNavigationConfig, visitUnversionedDbNavigationConfig } from "../../client";
import { visitDbNavigationTab } from "../../client/visitNavigationTab";
import { kebabCase } from "../../utils";
import { WithoutQuestionMarks } from "../utils/WithoutQuestionMarks";
import { assertNever } from "../utils/assertNever";
import { DEFAULT_DARK_MODE_ACCENT_PRIMARY, DEFAULT_LIGHT_MODE_ACCENT_PRIMARY } from "../utils/colors";
Expand Down Expand Up @@ -63,32 +63,32 @@ function transformTypographyToV2(
};
}

function transformFontConfigV2ToV1(fontConfig: DocsV1Read.FontConfigV2 | undefined): DocsV1Read.FontConfig | undefined {
if (fontConfig == null) {
return undefined;
}
const firstVariant = fontConfig.variants[0];
if (firstVariant == null) {
return undefined;
}
return {
name: fontConfig.name,
fontFile: firstVariant.fontFile,
};
}
// function transformFontConfigV2ToV1(fontConfig: DocsV1Read.FontConfigV2 | undefined): DocsV1Read.FontConfig | undefined {
// if (fontConfig == null) {
// return undefined;
// }
// const firstVariant = fontConfig.variants[0];
// if (firstVariant == null) {
// return undefined;
// }
// return {
// name: fontConfig.name,
// fontFile: firstVariant.fontFile,
// };
// }

function transformTypographyV2ToV1(
typography: DocsV1Read.DocsTypographyConfigV2 | undefined,
): DocsV1Read.DocsTypographyConfig | undefined {
if (typography == null) {
return undefined;
}
return {
headingsFont: transformFontConfigV2ToV1(typography.headingsFont),
bodyFont: transformFontConfigV2ToV1(typography.bodyFont),
codeFont: transformFontConfigV2ToV1(typography.codeFont),
};
}
// function transformTypographyV2ToV1(
// typography: DocsV1Read.DocsTypographyConfigV2 | undefined,
// ): DocsV1Read.DocsTypographyConfig | undefined {
// if (typography == null) {
// return undefined;
// }
// return {
// headingsFont: transformFontConfigV2ToV1(typography.headingsFont),
// bodyFont: transformFontConfigV2ToV1(typography.bodyFont),
// codeFont: transformFontConfigV2ToV1(typography.codeFont),
// };
// }

export function transformNavigationConfigToRead(dbShape: DocsV1Db.NavigationConfig): DocsV1Read.NavigationConfig {
return visitDbNavigationConfig<DocsV1Read.NavigationConfig>(dbShape, {
Expand Down
1 change: 0 additions & 1 deletion packages/fdr-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./client";
export * from "./converters";
export * as FernNavigation from "./navigation";
export { NodeCollector } from "./navigation/NodeCollector";
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/NodeCollector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { once } from "@fern-ui/core-utils";
import urljoin from "url-join";
import { once } from "../utils";
import { FernNavigation } from "./generated";
import {
NavigationNode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop, titleCase, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import urljoin from "url-join";
import { APIV1Read, DocsV1Read } from "../../client";
import { noop, titleCase, visitDiscriminatedUnion } from "../../utils";
import { ApiDefinitionHolder } from "../ApiDefinitionHolder";
import { FernNavigation } from "../generated";
import { followRedirects } from "../utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertNever, kebabCase, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import urljoin from "url-join";
import { APIV1Read, DocsV1Read, visitReadNavigationConfig, visitUnversionedReadNavigationConfig } from "../../client";
import { assertNever, kebabCase, visitDiscriminatedUnion } from "../../utils";
import { FernNavigation } from "../generated";
import { followRedirect, followRedirects } from "../utils";
import { convertAvailability } from "../utils/convertAvailability";
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export { ApiReferenceNavigationConverter } from "./converters/ApiReferenceNaviga
export * from "./generated/api";
export * from "./types";
export * as utils from "./utils";
export { collectSlugs, convert, createApiHolder };
export { ApiDefinitionHolder, collectSlugs, convert, createApiHolder, NavigationConfigConverter, NodeCollector };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertNever } from "@fern-ui/core-utils";
import { APIV1Read, DocsV1Read } from "../../client";
import { assertNever } from "../../utils";
import { FernNavigation } from "../generated";

export function convertAvailability(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mapValues } from "@fern-ui/core-utils";
import { APIV1Read, DocsV2Read } from "../../client";
import { mapValues } from "../../utils";
import { NavigationConfigConverter } from "../converters/NavigationConfigConverter";

export function convertLoadDocsForUrlResponse(response: DocsV2Read.LoadDocsForUrlResponse) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/utils/findNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { noop, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { noop, visitDiscriminatedUnion } from "../../utils";

import urljoin from "url-join";
import { NodeCollector } from "../NodeCollector";
Expand Down
8 changes: 1 addition & 7 deletions packages/fdr-sdk/src/navigation/utils/followRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { visitDiscriminatedUnion } from "../../utils";
import { FernNavigation } from "../generated";
import { NavigationNode } from "../types/NavigationNode";

Expand Down Expand Up @@ -37,17 +37,11 @@ export function followRedirect(nodeToFollow: NavigationNode | undefined): FernNa
}

export function followRedirects(nodes: NavigationNode[]): FernNavigation.Slug | undefined {
let traversedFirst = false;
for (const node of nodes) {
// if (traversedFirst) {
// // eslint-disable-next-line no-console
// console.error("First redirect path was not followed, this should not happen.");
// }
const redirect = followRedirect(node);
if (redirect != null) {
return redirect;
}
traversedFirst = true;
}
return;
}
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/utils/getApiReferenceId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { visitDiscriminatedUnion } from "../../utils";
import { FernNavigation } from "../generated";
import { NavigationNode } from "../types/NavigationNode";

Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/utils/getPageId.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { visitDiscriminatedUnion } from "../../utils";
import { FernNavigation } from "../generated";
import { NavigationNodePage } from "../types";

Expand Down
4 changes: 2 additions & 2 deletions packages/fdr-sdk/src/navigation/utils/traverseNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { noop, visitDiscriminatedUnion } from "@fern-ui/core-utils";
import { noop, visitDiscriminatedUnion } from "../../utils";

import { NavigationNode } from "../types/NavigationNode";

const SKIP = "skip" as const;
const CONTINUE = true as const;
// const CONTINUE = true as const;
const STOP = false as const;

export function traverseNavigation(
Expand Down
6 changes: 6 additions & 0 deletions packages/fdr-sdk/src/utils/assertNever.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function assertNever(x: never): never {
throw new Error("Unexpected value: " + JSON.stringify(x));
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
export function assertNeverNoThrow(_: never): void {}
5 changes: 5 additions & 0 deletions packages/fdr-sdk/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./assertNever";
export * from "./isPlainObject";
export * from "./lodash";
export * from "./titleCase";
export * from "./visitDiscriminatedUnion";
18 changes: 18 additions & 0 deletions packages/fdr-sdk/src/utils/isPlainObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// https://github.com/lodash/lodash/blob/master/isPlainObject.js
export function isPlainObject(value: unknown): value is Record<string, unknown> {
if (!isObjectLike(value) || String(value) !== "[object Object]") {
return false;
}
if (Object.getPrototypeOf(value) == null) {
return true;
}
let proto = value;
while (Object.getPrototypeOf(proto) != null) {
proto = Object.getPrototypeOf(proto);
}
return Object.getPrototypeOf(value) === proto;
}

function isObjectLike(value: unknown) {
return typeof value === "object" && value != null;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as kebabCase } from "./kebabCase";
export { default as mapValues } from "./mapValues";
export * from "./noop";
export { default as once } from "./once";
2 changes: 2 additions & 0 deletions packages/fdr-sdk/src/utils/lodash/noop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function
export function noop(): void {}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4c4f470

Please sign in to comment.