From 372992302f17ec59830cf9ad20e1ecdd2a978c52 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 5 May 2025 13:38:18 -0300 Subject: [PATCH 1/4] Fix pair redirect --- web/src/pages/[func].astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/pages/[func].astro b/web/src/pages/[func].astro index 6f3348a..e44dcc3 100644 --- a/web/src/pages/[func].astro +++ b/web/src/pages/[func].astro @@ -46,7 +46,7 @@ if ( funcExamples.length > 0 ){ tableOfContents: false, }}> {funcPair && ( -

Pair: { funcPair }

+

Pair: { funcPair }

)} From 283cf4aba4ee1262641573fcfe48299406bd2bb5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 5 May 2025 14:35:32 -0300 Subject: [PATCH 2/4] Add 'optional' property for parameters in function specification --- schemas/function.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/schemas/function.yaml b/schemas/function.yaml index 3cb2223..de1a49f 100644 --- a/schemas/function.yaml +++ b/schemas/function.yaml @@ -163,6 +163,10 @@ $defs: description: | The default value for this parameter, if none was given in the call to the function. This property automatically implicitly marks this parameter as optional. + optional: + type: boolean + default: false + description: If set to true, this parameter is optional. returns: type: object From 47cf67b7aa191bc0bd5c85051c97ab89743cf508 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 5 May 2025 14:58:09 -0300 Subject: [PATCH 3/4] Refactor function parameter and details structures for better type safety --- web/src/utils/functions.ts | 66 +++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts index b75c715..85cfbc6 100644 --- a/web/src/utils/functions.ts +++ b/web/src/utils/functions.ts @@ -5,26 +5,49 @@ import type { FunctionType } from './types'; type FunctionItem = Awaited>[number]; +// Define a structure for function parameters +type FunctionParameter = { + name: string; + type: string; // Adjust type as needed (e.g., string | string[]) + description?: string; + optional?: boolean; +}; + +// Define a structure for the details expected within shared/client/server +type FunctionDetails = { + description?: string; + pair?: boolean; + examples?: { code: string; description?: string }[]; + notes?: string; + parameters?: FunctionParameter[]; +}; + type FunctionsByCategory = { [folder: string]: FunctionItem[]; }; type FunctionsByTypeByCategory = { - shared: FunctionsByCategory; - client: FunctionsByCategory; - server: FunctionsByCategory; + [key in FunctionType]: FunctionsByCategory; }; + export type FunctionData = { shared?: any; client?: any; server?: any; }; +// Use the specific FunctionDetails type +export type TypedFunctionData = { + shared?: FunctionDetails; + client?: FunctionDetails; + server?: FunctionDetails; +}; + export const functionTypePrettyName = { 'client': 'Client-side', 'server': 'Server-side', 'shared': 'Shared', -}; +} as const; // Use 'as const' for stricter typing of keys function getFunctionType(data: FunctionData): FunctionType { if (data.shared) return 'shared'; @@ -32,17 +55,34 @@ function getFunctionType(data: FunctionData): FunctionType { return 'server'; } function getFunctionTypePretty(data: FunctionData): string { + // No need for fallback, getFunctionType guarantees a valid FunctionType const funcType = getFunctionType(data); - return functionTypePrettyName[funcType] ?? 'Server-side'; + return functionTypePrettyName[funcType]; } -export function getFunctionInfo(data: FunctionData): any { +// Define a return type for getFunctionInfo +export type FunctionInfo = { + description: string; + type: FunctionType; + typePretty: string; + pair: boolean; + examples: { code: string; description?: string }[]; + notes?: string; // Added notes + parameters?: FunctionParameter[]; // Added parameters +}; + +export function getFunctionInfo(data: TypedFunctionData): FunctionInfo { + const type = getFunctionType(data); + const details = data[type] ?? {}; // Get details based on type, default to empty object + return { - description: data.shared?.description || data.client?.description || data.server?.description || '', - type: getFunctionType(data), + description: details.description || '', + type: type, typePretty: getFunctionTypePretty(data), - pair: data.shared?.pair || data.client?.pair || data.server?.pair || false, - examples: data.shared?.examples || data.client?.examples || data.server?.examples || [ ], + pair: details.pair || false, + examples: details.examples || [], + notes: details.notes, // Extract notes (will be undefined if not present) + parameters: details.parameters || [], // Extract parameters }; } @@ -55,7 +95,8 @@ let functionsByTypeByCategory: FunctionsByTypeByCategory = { }; for (let func of functionsCollection) { - const normalizedPath = path.normalize(func.filePath || ''); + // Assuming func.filePath exists, handle potential undefined if necessary + const normalizedPath = path.normalize(func.id); // Use func.id which includes the path relative to content dir const folder = path.basename(path.dirname(normalizedPath)); if (!functionsByCategory[folder]) { functionsByCategory[folder] = []; @@ -63,7 +104,8 @@ for (let func of functionsCollection) { functionsByCategory[folder].push(func); const funcType = getFunctionType(func.data); - if (!functionsByTypeByCategory[funcType][folder]) { + // Ensure the folder exists for the specific type + if (!functionsByTypeByCategory[funcType]?.[folder]) { functionsByTypeByCategory[funcType][folder] = []; } functionsByTypeByCategory[funcType][folder].push(func); From 108ff858255150c0a70080b945171beba8f54f58 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 5 May 2025 15:10:55 -0300 Subject: [PATCH 4/4] Fix "notes" type --- web/src/utils/functions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts index 85cfbc6..d5193cd 100644 --- a/web/src/utils/functions.ts +++ b/web/src/utils/functions.ts @@ -18,7 +18,7 @@ type FunctionDetails = { description?: string; pair?: boolean; examples?: { code: string; description?: string }[]; - notes?: string; + notes?: string[]; parameters?: FunctionParameter[]; }; @@ -67,7 +67,7 @@ export type FunctionInfo = { typePretty: string; pair: boolean; examples: { code: string; description?: string }[]; - notes?: string; // Added notes + notes?: string[]; // Added notes parameters?: FunctionParameter[]; // Added parameters };