Skip to content

Commit

Permalink
Merge branch 'main' into sulaiman/fer-2652-monite-boundary-support-sy…
Browse files Browse the repository at this point in the history
…nchronizing-tab-groups
  • Loading branch information
sulaiman-fern committed Jul 30, 2024
2 parents 6385134 + 08e19d9 commit 0e5bdea
Show file tree
Hide file tree
Showing 50 changed files with 337 additions and 276 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-fdr-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }}

- name: 📥 Install
uses: ./.github/actions/install
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch || "main" }}
ref: ${{ github.event.inputs.branch }}

- name: 📥 Install
uses: ./.github/actions/install
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/test-fern-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: 📥 Install
uses: ./.github/actions/install

- name: Codegen
run: |
npm install -g fern-api
- name: Compile and build
run: pnpm turbo compile codegen build
env:
FERN_TOKEN: ${{ secrets.FERN_TOKEN }}
WORKOS_API_KEY: ${{ secrets.WORKOS_API_KEY }}
WORKOS_CLIENT_ID: ${{ secrets.WORKOS_CLIENT_ID }}

- name: 🚀 serverless function run-thru
env:
CI: false
Expand Down
15 changes: 8 additions & 7 deletions clis/docs-migrator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,18 @@ export class MigrateFromMintlify {
);

// create openapi folder
if (mint.openapi != null && mint.openapi.length > 0) {
if (mint.openapi != null) {
const openapiDir = path.join(fernDir, "openapi");
fs.mkdirSync(openapiDir, { recursive: true });
if (mint.openapi.length > 1) {
const firstOpenapi = typeof mint.openapi === "string" ? mint.openapi : mint.openapi[0];
if (firstOpenapi != null) {
const openapiFilePath = path.join(this.dir, firstOpenapi);
const newOpenapiFilePath = path.join(openapiDir, `openapi${path.extname(firstOpenapi)}`);
await fs.promises.copyFile(openapiFilePath, newOpenapiFilePath);
}
if (typeof mint.openapi !== "string" && mint.openapi.length > 1) {
console.warn("Multiple OpenAPI files are not supported yet in this migrator.");
}

const openapi = mint.openapi[0];
const openapiFilePath = path.join(this.dir, openapi);
const newOpenapiFilePath = path.join(openapiDir, `openapi${path.extname(openapi)}`);
await fs.promises.copyFile(openapiFilePath, newOpenapiFilePath);
}
}

Expand Down
11 changes: 10 additions & 1 deletion packages/commons/github/src/createOrUpdatePullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface RepoMetadata {

function parseRepository(repository: string): RepoMetadata {
const [owner, repo] = repository.split("/");
if (owner == null || repo == null) {
throw new Error(`Failed to parse repository into owner and repo: ${repository}`);
}
return {
owner,
repo,
Expand Down Expand Up @@ -74,9 +77,15 @@ export async function createOrUpdatePullRequest(
base: inputs.base,
});
console.log("Attempting update of pull request");

const pullNumber = pulls[0]?.number;
if (pullNumber == null) {
throw new Error(`Failed to retrieve pull request number: ${JSON.stringify(pulls)}`);
}

const { data: pull } = await octokit.rest.pulls.update({
...parseRepository(baseRepository),
pull_number: pulls[0].number,
pull_number: pullNumber,
title: inputs.title,
body: inputs.body,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/commons/github/src/getLatestTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export async function getLatestTag(githubRepository: string): Promise<string | u
per_page: 1, // Fetch only the latest tag
});

return response.data?.[0].name;
return response.data?.[0]?.name;
}
4 changes: 2 additions & 2 deletions packages/commons/github/src/parseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export function parseRepository(githubRepository: string): RepositoryReference {
}

const parts = githubRepository.split("/");
if (parts.length === 2) {
if (parts.length === 2 && parts[0] != null && parts[1] != null) {
// Format: owner/repo
[owner, repo] = parts;
} else if (parts.length === 3 && parts[0] === DEFAULT_REMOTE) {
} else if (parts.length === 3 && parts[0] === DEFAULT_REMOTE && parts[1] != null && parts[2] != null) {
// Format: github.com/owner/repo
[, owner, repo] = parts;
} else {
Expand Down
9 changes: 7 additions & 2 deletions packages/commons/github/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"extends": "@fern-platform/configs/tsconfig/library.json",
"compilerOptions": { "outDir": "./dist", "rootDir": "./src" },
"extends": "@fern-platform/configs/tsconfig/base.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "esnext",
"moduleResolution": "node"
},
"include": ["./src/**/*"]
}
6 changes: 2 additions & 4 deletions packages/configs/tsconfig/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
"display": "Base",
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": false,
"composite": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"inlineSources": false,
"isolatedModules": true,
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Bundler",
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": false,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": false,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"resolveJsonModule": true,
Expand Down
4 changes: 3 additions & 1 deletion packages/configs/tsconfig/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"composite": true
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler"
}
}
3 changes: 2 additions & 1 deletion packages/configs/tsconfig/nextjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"jsx": "preserve",
"lib": ["dom", "dom.iterable", "esnext"],
"types": ["node", "next", "vitest/globals"],
"plugins": [{ "name": "next" }]
"plugins": [{ "name": "next" }],
"noUncheckedIndexedAccess": true
}
}
1 change: 1 addition & 0 deletions packages/configs/tsconfig/react-library.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"declarationMap": true,
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ export class ApiReferenceNavigationConverter {
let subpackageId = isSubpackage(package_) ? package_.subpackageId : "root";
while (package_.pointsTo != null) {
subpackageId = package_.pointsTo;
package_ = this.api.subpackages[package_.pointsTo];
if (package_ == null) {
const pointsToSubpackage = this.api.subpackages[package_.pointsTo];
if (pointsToSubpackage == null) {
return [];
}
package_ = pointsToSubpackage;
}

if (this.#visitedSubpackages.has(subpackageId)) {
Expand Down Expand Up @@ -268,6 +269,11 @@ export class ApiReferenceNavigationConverter {
): FernNavigation.ApiPackageChild[] {
const children: FernNavigation.ApiPackageChild[] = [];
let subpackage = subpackageId === "root" ? this.api.rootPackage : this.api.subpackages[subpackageId];
if (subpackage == null) {
throw new Error(
`${subpackageId} is not present within known subpackages: ${Object.keys(this.api.subpackages).join(", ")}`,
);
}
while (subpackage.pointsTo != null) {
subpackage = this.api.subpackages[subpackage.pointsTo];
if (subpackage == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
export function getNoIndexFromFrontmatter(markdown: string): boolean | undefined {
const frontmatterMatch = /^---\s*([\s\S]*?)\s*---/.exec(markdown.trimStart());
if (!frontmatterMatch) {
if (!frontmatterMatch || frontmatterMatch[1] == null) {
return undefined;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/fdr-sdk/src/navigation/utils/traverseNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ export function traverseNavigation(
): void {
function internalChildrenTraverser(nodes: NavigationNode[], parents: NavigationNode[]): boolean | void {
for (let i = 0; i < nodes.length; i++) {
const result = internalTraverser(nodes[i], i, parents);
const node = nodes[i];
if (node == null) {
throw new Error(`Failed to index into nodes. Index: ${i} Length: ${nodes.length}`);
}
const result = internalTraverser(node, i, parents);
if (result === STOP) {
return STOP;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/fdr-sdk/src/utils/lodash/mapValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ function mapValue<VALUE, VALUE2, ITERATEE extends (input: VALUE, key: string, va
const result: Record<string, VALUE2> = {};

Object.keys(object).forEach((key) => {
result[key] = iteratee(object[key], key, object);
const val = object[key];
if (val == null) {
return; // Should this be a hard failure?
}
result[key] = iteratee(val, key, object);
});
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const UnmemoizedEndpointContentCodeSnippets: React.FC<EndpointContentCodeSnippet
const ref = useRef<HTMLDivElement>(null);

useResizeObserver(ref, ([entry]) => {
measureHeight(entry.contentRect.height);
if (entry != null) {
measureHeight(entry.contentRect.height);
}
});

const [internalSelectedErrorExample, setSelectedErrorExample] = useState<ResolvedExampleError | undefined>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const ErrorExampleSelect: FC<PropsWithChildren<ErrorExampleSelect.Props>>
children,
}) => {
const handleValueChange = (value: string) => {
const [errorIndex, exampleIndex] = value.split(":").map((v) => parseInt(v, 10));
const [errorIndex = 0, exampleIndex = 0] = value.split(":").map((v) => parseInt(v, 10));
setSelectedErrorAndExample(errors[errorIndex], errors[errorIndex]?.examples[exampleIndex]);
};
const selectedErrorIndex = selectedError != null ? errors.indexOf(selectedError) : -1;
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/app/src/api-page/examples/CodeSnippetExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ const CodeSnippetExampleInternal: FC<CodeSnippetExample.Props> = ({
const viewportRef = createRef<ScrollToHandle>();

useResizeObserver(codeBlockRef, ([entry]) => {
measureHeight?.(entry.contentRect.height);
if (entry != null) {
measureHeight?.(entry.contentRect.height);
}
});

const requestHighlightLines = useMemo(() => {
Expand Down
57 changes: 35 additions & 22 deletions packages/ui/app/src/api-page/types/type-shorthand/TypeShorthand.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { APIV1Read } from "@fern-api/fdr-sdk";
import { visitDiscriminatedUnion } from "@fern-ui/core-utils";
import clsx from "clsx";
import numeral from "numeral";
import { ReactNode } from "react";
import {
DereferencedTypeShape,
ResolvedTypeDefinition,
ResolvedTypeShape,
unwrapAlias,
Expand All @@ -25,10 +25,7 @@ export function renderTypeShorthandRoot(
): ReactNode {
const typeShorthand = renderTypeShorthand(unwrapOptional(shape, types), { nullable: isResponse }, types);
const unaliasedShape = unwrapAlias(shape, types);
const defaultsTo =
unaliasedShape.type === "optional" && unaliasedShape.shape.type === "primitive"
? renderDefaultTo(unaliasedShape.shape.value)
: null;
const defaultsTo = renderDefaultsTo(unaliasedShape);
return (
<span className={clsx("fern-api-property-meta", className)}>
<span>{typeShorthand}</span>
Expand All @@ -37,30 +34,46 @@ export function renderTypeShorthandRoot(
) : !isResponse ? (
<span className="t-danger">Required</span>
) : null}
{defaultsTo != null && <span>{`Defaults to ${defaultsTo}`}</span>}
{defaultsTo != null && (
<span>
{"Defaults to "}
<code>{defaultsTo}</code>
</span>
)}
</span>
);
}

function renderDefaultTo(shape: APIV1Read.PrimitiveType): string | undefined {
function renderDefaultsTo(shape: DereferencedTypeShape): string | undefined {
if (shape.type !== "optional") {
return undefined;
}

if (shape.shape.type === "primitive") {
return renderDefaultToPrimitive(shape.shape.value);
}

if (shape.shape.type === "enum") {
return shape.shape.default;
}

return undefined;
}

function renderDefaultToPrimitive(shape: APIV1Read.PrimitiveType): string | undefined {
return visitDiscriminatedUnion(shape, "type")._visit<string | undefined>({
string: (string) => string.default,
integer: (integer) => {
if (integer.default == null) {
return undefined;
}
return numeral(integer.default).format("0,0");
},
double: (double) => double.default?.toString(),
string: (value) => value.default,
integer: (value) => value.default?.toString(),
double: (value) => value.default?.toString(),
uint: () => undefined,
uint64: () => undefined,
boolean: () => undefined,
long: () => undefined,
datetime: () => undefined,
uuid: () => undefined,
base64: () => undefined,
date: () => undefined,
bigInteger: () => undefined,
boolean: (value) => value.default?.toString(),
long: (value) => value.default?.toString(),
datetime: (datetime) => datetime.default,
uuid: (uuid) => uuid.default,
base64: (base64) => base64.default,
date: (value) => value.default,
bigInteger: (value) => value.default,
_other: () => undefined,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ function HeaderAuthForm({ header, disabled }: { header: APIV1Read.HeaderAuth; di
headers: {
...headers,
[header.headerWireValue]:
typeof change === "function" ? change(headers[header.headerWireValue]) : change,
typeof change === "function"
? change(headers[header.headerWireValue] ?? "")
: change,
},
}));
},
Expand Down Expand Up @@ -405,7 +407,7 @@ function isAuthed(auth: APIV1Read.ApiAuth, authState: PlaygroundAuthState): bool
bearerAuth: () => !isEmpty(authState.bearerAuth?.token.trim()),
basicAuth: () =>
!isEmpty(authState.basicAuth?.username.trim()) && !isEmpty(authState.basicAuth?.password.trim()),
header: (header) => !isEmpty(authState.header?.headers[header.headerWireValue].trim()),
header: (header) => !isEmpty(authState.header?.headers[header.headerWireValue]?.trim()),
_other: () => false,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function PlaygroundEndpointDescription({ endpoint }: PlaygroundEndpointDe
const [descriptionIsClamped, setDescriptionIsClamped] = useState(false);

useResizeObserver(descriptionRef, ([entry]) => {
if (!showFullDescription) {
if (!showFullDescription && entry != null) {
setDescriptionIsClamped(entry.target.scrollHeight > entry.target.clientHeight);
}
});
Expand Down
Loading

0 comments on commit 0e5bdea

Please sign in to comment.