Skip to content

Commit

Permalink
docs: Enhance SDL class with JSDoc comments and examples
Browse files Browse the repository at this point in the history
- Added detailed JSDoc comments to the `fromString`, `validateGPU`, and `validateStorage` methods in the SDL class.
- Included usage examples in the JSDoc to demonstrate practical application of the methods.
- Improved code documentation for better readability and understanding.

Signed-off-by: Greg Osuri <[email protected]>
  • Loading branch information
gosuri committed Dec 14, 2024
1 parent 397c410 commit 8be7bc2
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/sdl/SDL/SDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,28 @@ type NetworkVersion = "beta2" | "beta3";
*/
export class SDL {
/**
* Creates an SDL instance from a YAML string
* @param yaml - The YAML string containing the SDL definition
* @param version - The SDL version (beta2 or beta3)
* @param networkId - The network ID to validate against
* Creates an SDL instance from a YAML string.
*
* @param {string} yaml - The YAML string containing the SDL definition.
* @param {NetworkVersion} [version="beta2"] - The SDL version (beta2 or beta3).
* @param {NetworkId} [networkId=MAINNET_ID] - The network ID to validate against.
* @returns {SDL} An instance of the SDL class.
*
* @example
* ```ts
* const yaml = `
* version: "2.0"
* services:
* web:
* image: nginx
* expose:
* - port: 80
* as: 80
* to:
* - global: true
* `;
* const sdl = SDL.fromString(yaml);
* ```
*/
static fromString(yaml: string, version: NetworkVersion = "beta2", networkId: NetworkId = MAINNET_ID) {
const data = YAML.load(yaml) as v3Sdl;
Expand All @@ -118,18 +136,14 @@ export class SDL {
/**
* Validates the GPU configuration for a given service profile.
*
* @param name - The name of the service profile.
* @param gpu - The GPU resource configuration.
* @param {string} name - The name of the service profile.
* @param {v3ResourceGPU | undefined} gpu - The GPU resource configuration.
* @throws Will throw an error if the GPU configuration is invalid.
*
* @example
* ```ts
* SDL.validateGPU("web", {
* units: "1",
* attributes: {
* vendor: { nvidia: [{ model: "RTX 3080", ram: "10GB", interface: "pcie" }] }
* }
* });
* const gpuConfig = { units: "1", attributes: { vendor: { nvidia: [{ model: "RTX 3080", ram: "10GB" }] } } };
* SDL.validateGPU("web", gpuConfig);
* ```
*/
static validateGPU(name: string, gpu: v3ResourceGPU | undefined) {
Expand Down Expand Up @@ -176,16 +190,14 @@ export class SDL {
/**
* Validates the storage configuration for a given service.
*
* @param name - The name of the service.
* @param storage - The storage resource configuration.
* @param {string} name - The name of the service.
* @param {v2ResourceStorage | v2ResourceStorageArray} [storage] - The storage resource configuration.
* @throws Will throw an error if the storage configuration is invalid.
*
* @example
* ```ts
* SDL.validateStorage("web", {
* size: "10Gi",
* attributes: { class: "ssd" }
* });
* const storageConfig = { size: "10Gi", attributes: { class: "ssd" } };
* SDL.validateStorage("web", storageConfig);
* ```
*/
static validateStorage(name: string, storage?: v2ResourceStorage | v2ResourceStorageArray) {
Expand Down

0 comments on commit 8be7bc2

Please sign in to comment.