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
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 }
)}
diff --git a/web/src/utils/functions.ts b/web/src/utils/functions.ts
index b75c715..d5193cd 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);