Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(docs-search): reference section type errors

Greg Richardson6c17d0b01fc9
diff --git a/apps/docs/components/reference/Reference.types.ts b/apps/docs/components/reference/Reference.types.ts
index 04a9c04b7da..4ff54b1b991 100644
--- a/apps/docs/components/reference/Reference.types.ts
+++ b/apps/docs/components/reference/Reference.types.ts
@@ -34,13 +34,13 @@ export interface IFunctionDefinition {
}
export interface ICommonFunc {
- id: string
+ id?: string
title: string
- slug: string
- product: string
- type: string
+ slug?: string
+ product?: string
+ type?: string
parent?: string
- items: ICommonFunc[]
+ items?: ICommonFunc[]
}
export interface IRefFunctionSection {
diff --git a/apps/docs/lib/helpers.ts b/apps/docs/lib/helpers.ts
index 29fdac4b8e5..7a6c5de3d45 100644
--- a/apps/docs/lib/helpers.ts
+++ b/apps/docs/lib/helpers.ts
@@ -1,4 +1,7 @@
// [Joshen] I think this can be done better, as its mostly used to choose what
+
+import { ICommonFunc } from '../components/reference/Reference.types'
+
// menus to render in the SideBar.js (Ref Nav.constants.ts)
export function getPageType(asPath: string) {
let page
@@ -33,15 +36,8 @@ export function getPageType(asPath: string) {
return page
}
-export type ReferenceSection = {
- title: string
- id?: string
- slug?: string
- items?: ReferenceSection[]
-}
-
-export function flattenSections(sections: ReferenceSection[]) {
- let a: ReferenceSection[] = []
+export function flattenSections(sections: ICommonFunc[]) {
+ let a: ICommonFunc[] = []
for (let i = 0; i < sections.length; i++) {
if (sections[i].id) {
// only push a section that has an id
diff --git a/apps/docs/scripts/generate-embeddings.ts b/apps/docs/scripts/generate-embeddings.ts
index b0598804d76..520450083e3 100644
--- a/apps/docs/scripts/generate-embeddings.ts
+++ b/apps/docs/scripts/generate-embeddings.ts
@@ -18,9 +18,9 @@ import { basename, dirname, join } from 'path'
import { u } from 'unist-builder'
import { filter } from 'unist-util-filter'
import { inspect } from 'util'
-import { IFunctionDefinition, ISpec } from '../components/reference/Reference.types'
+import { ICommonFunc, IFunctionDefinition, ISpec } from '../components/reference/Reference.types'
import { CliCommand, CliSpec } from '../generator/types/CliSpec'
-import { flattenSections, ReferenceSection } from '../lib/helpers'
+import { flattenSections } from '../lib/helpers'
import { enrichedOperation, gen_v3 } from '../lib/refGenerator/helpers'
dotenv.config()
@@ -280,7 +280,7 @@ abstract class ReferenceEmbeddingSource<SpecSection> extends BaseEmbeddingSource
const specContents = await readFile(this.specFilePath, 'utf8')
const refSectionsContents = await readFile(this.sectionsFilePath, 'utf8')
- const refSections: ReferenceSection[] = JSON.parse(refSectionsContents)
+ const refSections: ICommonFunc[] = JSON.parse(refSectionsContents)
const flattenedRefSections = flattenSections(refSections)
const checksum = createHash('sha256')
@@ -320,7 +320,7 @@ abstract class ReferenceEmbeddingSource<SpecSection> extends BaseEmbeddingSource
abstract getSpecSections(specContents: string): SpecSection[]
abstract matchSpecSection(specSections: SpecSection[], id: string): SpecSection
- abstract formatSection(specSection: SpecSection, refSection: ReferenceSection): string
+ abstract formatSection(specSection: SpecSection, refSection: ICommonFunc): string
}
class OpenApiEmbeddingSource extends ReferenceEmbeddingSource<enrichedOperation> {
@@ -357,7 +357,7 @@ class ClientLibEmbeddingSource extends ReferenceEmbeddingSource<IFunctionDefinit
matchSpecSection(functionDefinitions: IFunctionDefinition[], id: string): IFunctionDefinition {
return functionDefinitions.find((functionDefinition) => functionDefinition.id === id)
}
- formatSection(functionDefinition: IFunctionDefinition, refSection: ReferenceSection): string {
+ formatSection(functionDefinition: IFunctionDefinition, refSection: ICommonFunc): string {
const { title } = refSection
const { description, title: functionName } = functionDefinition