Skip to content

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

feat(content api): search result for cli reference (#35488)

Charis03dcd5170038
diff --git a/apps/docs/app/api/graphql/__snapshots__/route.test.ts.snap b/apps/docs/app/api/graphql/__snapshots__/route.test.ts.snap
index 4b8182a6b61..c668a0b5208 100644
--- a/apps/docs/app/api/graphql/__snapshots__/route.test.ts.snap
+++ b/apps/docs/app/api/graphql/__snapshots__/route.test.ts.snap
@@ -70,6 +70,20 @@ type Subsection {
content: String
}
+"""
+A reference document containing a description of a Supabase CLI command
+"""
+type CLICommandReference implements SearchResult {
+ """The title of the document"""
+ title: String
+
+ """The URL of the document"""
+ href: String
+
+ """The content of the reference document, as text"""
+ content: String
+}
+
"""
A reference document containing a description of a function from a Supabase client library
"""
diff --git a/apps/docs/features/helpers.misc.ts b/apps/docs/features/helpers.misc.ts
index 127958425cd..32b2f7785f7 100644
--- a/apps/docs/features/helpers.misc.ts
+++ b/apps/docs/features/helpers.misc.ts
@@ -1,3 +1,11 @@
+export function isPlainObject(value: unknown): value is Record<string, unknown> {
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ return false
+ }
+ const prototype = Object.getPrototypeOf(value)
+ return prototype === null || prototype === Object.prototype
+}
+
/**
* Creates a short random identifier
*/
diff --git a/apps/docs/lib/supabase.ts b/apps/docs/lib/supabase.ts
index c65a4ea76bc..3d3ab8820f8 100644
--- a/apps/docs/lib/supabase.ts
+++ b/apps/docs/lib/supabase.ts
@@ -17,7 +17,7 @@ type Database = {
DatabaseGenerated['public']['Functions']['search_content']['Returns'][number],
'subsections' | 'metadata'
> & {
- metadata: { language?: string; methodName?: string }
+ metadata: { language?: string; methodName?: string; platform?: string }
subsections: Array<{ title?: string; href?: string; content?: string }>
}
>
diff --git a/apps/docs/resources/globalSearch/globalSearchModel.ts b/apps/docs/resources/globalSearch/globalSearchModel.ts
index 7bdd18e72c3..2b5b41cc087 100644
--- a/apps/docs/resources/globalSearch/globalSearchModel.ts
+++ b/apps/docs/resources/globalSearch/globalSearchModel.ts
@@ -7,6 +7,10 @@ import { GuideModel } from '../guide/guideModel'
import { ReferenceSDKFunctionModel, SDKLanguageValues } from '../reference/referenceSDKModel'
import { SearchResultInterface } from './globalSearchInterface'
import { TroubleshootingModel } from '../troubleshooting/troubleshootingModel'
+import {
+ DB_METADATA_TAG_PLATFORM_CLI,
+ ReferenceCLICommandModel,
+} from '../reference/referenceCLIModel'
export abstract class SearchResultModel {
static async search(
@@ -59,6 +63,15 @@ function createModelFromMatch({
language,
methodName: metadata.methodName,
})
+ } else if (metadata.platform === DB_METADATA_TAG_PLATFORM_CLI) {
+ return new ReferenceCLICommandModel({
+ title: page_title,
+ href,
+ content,
+ subsections,
+ })
+ } else {
+ break
}
case 'github-discussions':
return new TroubleshootingModel({
diff --git a/apps/docs/resources/reference/referenceCLIModel.ts b/apps/docs/resources/reference/referenceCLIModel.ts
new file mode 100644
index 00000000000..7369c2309a2
--- /dev/null
+++ b/apps/docs/resources/reference/referenceCLIModel.ts
@@ -0,0 +1,32 @@
+import { Json } from 'common'
+import { isPlainObject } from '~/features/helpers.misc'
+import { type SearchResultInterface } from '../globalSearch/globalSearchInterface'
+
+export const DB_METADATA_TAG_PLATFORM_CLI = 'cli'
+
+export class ReferenceCLICommandModel implements SearchResultInterface {
+ public title?: string
+ public href?: string
+ public content?: string
+
+ constructor({
+ title,
+ href,
+ content,
+ subsections,
+ }: {
+ title?: string
+ href?: string
+ content?: string
+ subsections?: Array<Json>
+ }) {
+ this.title = title
+ this.href = href
+ this.content =
+ content +
+ '\n\n' +
+ subsections
+ ?.map((subsection) => (isPlainObject(subsection) && subsection.content) || '')
+ .join('\n\n')
+ }
+}
diff --git a/apps/docs/resources/reference/referenceCLISchema.ts b/apps/docs/resources/reference/referenceCLISchema.ts
new file mode 100644
index 00000000000..49c260ea0c1
--- /dev/null
+++ b/apps/docs/resources/reference/referenceCLISchema.ts
@@ -0,0 +1,24 @@
+import { GraphQLObjectType, GraphQLString } from 'graphql'
+import { GraphQLInterfaceTypeSearchResult } from '../globalSearch/globalSearchSchema'
+import { ReferenceCLICommandModel } from './referenceCLIModel'
+
+export const GraphQLObjectTypeReferenceCLICommand = new GraphQLObjectType({
+ name: 'CLICommandReference',
+ interfaces: [GraphQLInterfaceTypeSearchResult],
+ isTypeOf: (value: unknown) => value instanceof ReferenceCLICommandModel,
+ description: 'A reference document containing a description of a Supabase CLI command',
+ fields: {
+ title: {
+ type: GraphQLString,
+ description: 'The title of the document',
+ },
+ href: {
+ type: GraphQLString,
+ description: 'The URL of the document',
+ },
+ content: {
+ type: GraphQLString,
+ description: 'The content of the reference document, as text',
+ },
+ },
+})
diff --git a/apps/docs/resources/rootSchema.ts b/apps/docs/resources/rootSchema.ts
index 5d498515e3c..5c543d1e79f 100644
--- a/apps/docs/resources/rootSchema.ts
+++ b/apps/docs/resources/rootSchema.ts
@@ -8,6 +8,7 @@ import {
import { RootQueryTypeResolvers } from '~/__generated__/graphql'
import { searchRoot } from './globalSearch/globalSearchResolver'
import { GraphQLObjectTypeGuide } from './guide/guideSchema'
+import { GraphQLObjectTypeReferenceCLICommand } from './reference/referenceCLISchema'
import { GraphQLObjectTypeReferenceSDKFunction } from './reference/referenceSDKSchema'
import { GraphQLObjectTypeTroubleshooting } from './troubleshooting/troubleshootingSchema'
@@ -38,6 +39,7 @@ export const rootGraphQLSchema = new GraphQLSchema({
}),
types: [
GraphQLObjectTypeGuide,
+ GraphQLObjectTypeReferenceCLICommand,
GraphQLObjectTypeReferenceSDKFunction,
GraphQLObjectTypeTroubleshooting,
],
diff --git a/apps/docs/scripts/search/sources/index.ts b/apps/docs/scripts/search/sources/index.ts
index 241841ec35e..5d02b68421b 100644
--- a/apps/docs/scripts/search/sources/index.ts
+++ b/apps/docs/scripts/search/sources/index.ts
@@ -116,7 +116,7 @@ export async function fetchCliLibReferenceSource() {
return new CliReferenceLoader(
'cli',
'/reference/cli',
- { title: 'CLI Reference' },
+ { title: 'CLI Reference', platform: 'cli' },
'spec/cli_v1_commands.yaml',
'spec/common-cli-sections.json'
).load()