Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Oct 8, 2024
1 parent 6f25f6c commit 9477dc0
Show file tree
Hide file tree
Showing 60 changed files with 313 additions and 2,605 deletions.
14 changes: 7 additions & 7 deletions fern/apis/fdr/definition/api/latest/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ types:
- commons.WithAvailability
properties:
key: rootCommons.PropertyKey
valueShape: TypeReference
valueShape: TypeShape

EnumType:
properties:
Expand All @@ -83,7 +83,7 @@ types:
- commons.WithAvailability
properties:
displayName: optional<string>
shape: TypeReference
shape: TypeShape

DiscriminatedUnionType:
properties:
Expand Down Expand Up @@ -137,18 +137,18 @@ types:

OptionalType:
properties:
shape: TypeReference
shape: TypeShape
default: optional<unknown>

ListType:
properties:
itemShape: TypeReference
itemShape: TypeShape

SetType:
properties:
itemShape: TypeReference
itemShape: TypeShape

MapType:
properties:
keyShape: TypeReference
valueShape: TypeReference
keyShape: TypeShape
valueShape: TypeShape
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,27 @@ export function createWebSocketContext(
types: api.auths,
};
}

export type WebhookContext = {
node: FernNavigation.WebhookNode;
webhook: ApiDefinition.WebhookDefinition;
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>;
};

export function createWebhookContext(
node: FernNavigation.WebhookNode | undefined,
api: ApiDefinition.ApiDefinition | undefined,
): WebhookContext | undefined {
if (!node) {
return undefined;
}
const webhook = api?.webhooks[node.webhookId];
if (!webhook) {
return undefined;
}
return {
node,
webhook,
types: api.auths,
};
}
1 change: 1 addition & 0 deletions packages/fdr-sdk/src/api-definition/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./endpoint-context";
export * from "./endpoint-path-literal";
export * from "./join";
export * from "./lang";
Expand Down
45 changes: 36 additions & 9 deletions packages/fdr-sdk/src/api-definition/migrators/v1ToV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ export class ApiDefinitionV1ToLatest {
}
return v1.map((parameter) => ({
key: V2.PropertyKey(parameter.key),
valueShape: this.migrateTypeReference(parameter.type),
valueShape: {
type: "alias",
value: this.migrateTypeReference(parameter.type),
},
description: parameter.description,
availability: parameter.availability,
}));
Expand All @@ -244,8 +247,14 @@ export class ApiDefinitionV1ToLatest {
return visitDiscriminatedUnion(typeRef)._visit<V2.TypeReference>({
map: (value) => ({
type: "map",
keyShape: this.migrateTypeReference(value.keyType),
valueShape: this.migrateTypeReference(value.valueType),
keyShape: {
type: "alias",
value: this.migrateTypeReference(value.keyType),
},
valueShape: {
type: "alias",
value: this.migrateTypeReference(value.valueType),
},
}),
id: (value) => ({
type: "id",
Expand All @@ -255,16 +264,25 @@ export class ApiDefinitionV1ToLatest {
primitive: (value) => value,
optional: (value) => ({
type: "optional",
shape: this.migrateTypeReference(value.itemType),
shape: {
type: "alias",
value: this.migrateTypeReference(value.itemType),
},
default: value.defaultValue,
}),
list: (value) => ({
type: "list",
itemShape: this.migrateTypeReference(value.itemType),
itemShape: {
type: "alias",
value: this.migrateTypeReference(value.itemType),
},
}),
set: (value) => ({
type: "set",
itemShape: this.migrateTypeReference(value.itemType),
itemShape: {
type: "alias",
value: this.migrateTypeReference(value.itemType),
},
}),
literal: (value) => value,
unknown: () => ({
Expand All @@ -290,7 +308,10 @@ export class ApiDefinitionV1ToLatest {
type: "undiscriminatedUnion",
variants: value.variants.map((variant) => ({
displayName: variant.displayName,
shape: this.migrateTypeReference(variant.type),
shape: {
type: "alias",
value: this.migrateTypeReference(variant.type),
},
description: variant.description,
availability: variant.availability,
})),
Expand All @@ -313,7 +334,10 @@ export class ApiDefinitionV1ToLatest {
migrateObjectProperties = (properties: APIV1Read.ObjectProperty[]): V2.ObjectProperty[] => {
return properties.map((value) => ({
key: V2.PropertyKey(value.key),
valueShape: this.migrateTypeReference(value.valueType),
valueShape: {
type: "alias",
value: this.migrateTypeReference(value.valueType),
},
description: value.description,
availability: value.availability,
}));
Expand Down Expand Up @@ -573,7 +597,10 @@ export class ApiDefinitionV1ToLatest {
contentType: bodyProp.contentType,
description: bodyProp.description,
availability: bodyProp.availability,
valueShape: this.migrateTypeReference(bodyProp.valueType),
valueShape: {
type: "alias",
value: this.migrateTypeReference(bodyProp.valueType),
},
}),
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/api-definition/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ApiDefinitionPruner {
private pruneTypes(partiallyPrunedApi: Latest.ApiDefinition): Record<string, Latest.TypeDefinition> {
let typeIds = new Set<Latest.TypeId>();
partiallyPrunedApi.globalHeaders?.forEach((header) => {
ApiTypeIdVisitor.visitTypeReference(header.valueShape, (typeId) => typeIds.add(typeId));
ApiTypeIdVisitor.visitTypeShape(header.valueShape, (typeId) => typeIds.add(typeId));
});

for (const endpoint of Object.values(partiallyPrunedApi.endpoints)) {
Expand Down
32 changes: 16 additions & 16 deletions packages/fdr-sdk/src/api-definition/typeid-visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ export class ApiTypeIdVisitor {
visit: (typeId: Latest.TypeId) => void,
): void {
endpoint.pathParameters?.forEach((pathParameter) => {
ApiTypeIdVisitor.visitTypeReference(pathParameter.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(pathParameter.valueShape, visit);
});
endpoint.queryParameters?.forEach((queryParameter) => {
ApiTypeIdVisitor.visitTypeReference(queryParameter.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(queryParameter.valueShape, visit);
});
endpoint.requestHeaders?.forEach((header) => {
ApiTypeIdVisitor.visitTypeReference(header.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(header.valueShape, visit);
});
endpoint.responseHeaders?.forEach((header) => {
ApiTypeIdVisitor.visitTypeReference(header.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(header.valueShape, visit);
});
if (endpoint.request?.body != null) {
ApiTypeIdVisitor.visitHttpRequestBodyShape(endpoint.request.body, visit);
Expand All @@ -38,13 +38,13 @@ export class ApiTypeIdVisitor {
visit: (typeId: Latest.TypeId) => void,
): void {
channel.requestHeaders?.forEach((header) => {
ApiTypeIdVisitor.visitTypeReference(header.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(header.valueShape, visit);
});
channel.pathParameters?.forEach((pathParameter) => {
ApiTypeIdVisitor.visitTypeReference(pathParameter.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(pathParameter.valueShape, visit);
});
channel.queryParameters?.forEach((queryParameter) => {
ApiTypeIdVisitor.visitTypeReference(queryParameter.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(queryParameter.valueShape, visit);
});
channel.messages.forEach((message) => {
ApiTypeIdVisitor.visitTypeShape(message.body, visit);
Expand All @@ -56,7 +56,7 @@ export class ApiTypeIdVisitor {
visit: (typeId: Latest.TypeId) => void,
): void {
webhook.headers?.forEach((header) => {
ApiTypeIdVisitor.visitTypeReference(header.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(header.valueShape, visit);
});
if (webhook.payload) {
ApiTypeIdVisitor.visitTypeShape(webhook.payload.shape, visit);
Expand Down Expand Up @@ -96,7 +96,7 @@ export class ApiTypeIdVisitor {
visitDiscriminatedUnion(field)._visit({
file: noop,
files: noop,
property: (property) => ApiTypeIdVisitor.visitTypeReference(property.valueShape, visit),
property: (property) => ApiTypeIdVisitor.visitTypeShape(property.valueShape, visit),
}),
);
}
Expand All @@ -114,7 +114,7 @@ export class ApiTypeIdVisitor {
alias: (value) => ApiTypeIdVisitor.visitTypeReference(value.value, visit),
enum: noop,
undiscriminatedUnion: (value) =>
value.variants.forEach((variant) => ApiTypeIdVisitor.visitTypeReference(variant.shape, visit)),
value.variants.forEach((variant) => ApiTypeIdVisitor.visitTypeShape(variant.shape, visit)),
discriminatedUnion: (value) =>
value.variants.forEach((variant) => ApiTypeIdVisitor.visitObjectType(variant, visit)),
});
Expand All @@ -123,7 +123,7 @@ export class ApiTypeIdVisitor {
public static visitObjectType(typeShape: Latest.ObjectType, visit: (typeId: Latest.TypeId) => void): void {
typeShape.extends.forEach(visit);
typeShape.properties.forEach((property) => {
ApiTypeIdVisitor.visitTypeReference(property.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(property.valueShape, visit);
});
}

Expand All @@ -134,12 +134,12 @@ export class ApiTypeIdVisitor {
return visitDiscriminatedUnion(typeReference)._visit({
id: (value) => visit(value.id),
primitive: noop,
optional: (value) => ApiTypeIdVisitor.visitTypeReference(value.shape, visit),
list: (value) => ApiTypeIdVisitor.visitTypeReference(value.itemShape, visit),
set: (value) => ApiTypeIdVisitor.visitTypeReference(value.itemShape, visit),
optional: (value) => ApiTypeIdVisitor.visitTypeShape(value.shape, visit),
list: (value) => ApiTypeIdVisitor.visitTypeShape(value.itemShape, visit),
set: (value) => ApiTypeIdVisitor.visitTypeShape(value.itemShape, visit),
map: (value) => {
ApiTypeIdVisitor.visitTypeReference(value.keyShape, visit);
ApiTypeIdVisitor.visitTypeReference(value.valueShape, visit);
ApiTypeIdVisitor.visitTypeShape(value.keyShape, visit);
ApiTypeIdVisitor.visitTypeShape(value.valueShape, visit);
},
literal: noop,
unknown: noop,
Expand Down
11 changes: 7 additions & 4 deletions packages/fdr-sdk/src/api-definition/unwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ export function unwrapObjectType(
const defaultProperty = isPlainObject(unwrapped.default) ? unwrapped.default[property.key] : undefined;

const valueShape: Latest.TypeReference.Optional =
property.valueShape.type === "optional"
? { ...property.valueShape, default: defaultProperty ?? property.valueShape.default }
property.valueShape.type === "alias" && property.valueShape.value.type === "optional"
? { ...property.valueShape.value, default: defaultProperty ?? property.valueShape.value.default }
: { type: "optional", shape: property.valueShape, default: defaultProperty };

return {
...property,
valueShape,
valueShape: { type: "alias", value: valueShape },
};
});
});
Expand Down Expand Up @@ -261,7 +261,10 @@ export function unwrapDiscriminatedUnionVariant(
properties: [
{
key: union.discriminant,
valueShape: { type: "literal", value: { type: "stringLiteral", value: variant.discriminantValue } },
valueShape: {
type: "alias",
value: { type: "literal", value: { type: "stringLiteral", value: variant.discriminantValue } },
},

// the description and availability of the discriminant should not be included here
// because they are already included in the union variant itself
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import visitDiscriminatedUnion from "@fern-ui/core-utils/visitDiscriminatedUnion
import { noop } from "ts-essentials";
import { FernNavigation } from "../..";

export function createBreadcrumbs(nodes: readonly FernNavigation.NavigationNode[]): FernNavigation.BreadcrumbItem[] {
export function createBreadcrumb(nodes: readonly FernNavigation.NavigationNode[]): FernNavigation.BreadcrumbItem[] {
const breadcrumb: FernNavigation.BreadcrumbItem[] = [];
nodes.forEach((node) => {
if (!FernNavigation.hasMetadata(node) || FernNavigation.isLeaf(node)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/fdr-sdk/src/navigation/utils/findNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isSidebarRootNode } from "../versions/latest/isSidebarRootNode";
import { isTabbedNode } from "../versions/latest/isTabbedNode";
import { isUnversionedNode } from "../versions/latest/isUnversionedNode";
import { isVersionNode } from "../versions/latest/isVersionNode";
import { createBreadcrumbs } from "./createBreadcrumbs";
import { createBreadcrumb } from "./createBreadcrumb";

export type Node = Node.Found | Node.Redirect | Node.NotFound;

Expand Down Expand Up @@ -101,7 +101,7 @@ export function findNode(root: FernNavigation.RootNode, slug: FernNavigation.Slu
return {
type: "found",
node: found.node,
breadcrumb: createBreadcrumbs(found.parents),
breadcrumb: createBreadcrumb(found.parents),
parents: found.parents,
root,
versions, // this is used to render the version switcher
Expand Down
2 changes: 1 addition & 1 deletion packages/fdr-sdk/src/navigation/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./collectApiReferences";
export * from "./collectPageIds";
export * from "./createBreadcrumbs";
export * from "./createBreadcrumb";
export * from "./findNode";
export * from "./getApiReferenceId";
export * from "./getNoIndexFromFrontmatter";
Expand Down
Loading

0 comments on commit 9477dc0

Please sign in to comment.