High-level service methods for interacting with Elyra's schema and metadata APIs. The FrontendServices class provides CRUD operations for metadata management and schema retrieval with caching, built on top of the RequestHandler for consistent error handling.
import { FrontendServices } from "@elyra/application";
import { Dialog } from '@jupyterlab/apputils';Service class for accessing the Elyra API with high-level methods for common operations.
/**
* A service class for accessing the elyra api.
*/
class FrontendServices {
/**
* Displays a dialog for error cases during metadata calls.
* @param namespace - The metadata namespace that was being accessed when the error occurred
* @returns A promise that resolves with whether the dialog was accepted.
*/
static noMetadataError(namespace: string): Promise<Dialog.IResult<any>>;
/**
* Service function for making GET calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @returns A promise that resolves with the requested metadata or an error dialog result
*/
static getMetadata(namespace: string): Promise<any>;
/**
* Service function for making POST calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param requestBody - The body of the request
* @returns A promise that resolves with the newly created metadata or an error dialog result
*/
static postMetadata(namespace: string, requestBody: any): Promise<any>;
/**
* Service function for making PUT calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param name - The metadata name being updated
* @param requestBody - The body of the request
* @returns A promise that resolves with the updated metadata or an error dialog result
*/
static putMetadata(namespace: string, name: string, requestBody: any): Promise<any>;
/**
* Service function for making DELETE calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param name - The metadata name being deleted
* @returns A promise that resolves void or an error dialog result
*/
static deleteMetadata(namespace: string, name: string): Promise<any>;
/**
* Service function for making GET calls to the elyra schema API.
* @param namespace - The schema namespace being requested
* @returns A promise that resolves with the requested schemas or an error dialog result
*/
static getSchema(namespace: string): Promise<any>;
/**
* Service function for making GET calls to the elyra schema API.
* @returns A promise that resolves with all available schemas or an error dialog result
*/
static getAllSchema(): Promise<any>;
}CRUD operations for managing Elyra metadata instances.
Retrieve metadata instances from a specific namespace.
/**
* Service function for making GET calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @returns Promise resolving with the requested metadata or an error dialog result
*/
static getMetadata(namespace: string): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
// Get all code snippets
const codeSnippets = await FrontendServices.getMetadata('code-snippets');
// Get runtime images
const runtimeImages = await FrontendServices.getMetadata('runtime-images');Create new metadata instances in a specific namespace.
/**
* Service function for making POST calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param requestBody - The body of the request
* @returns Promise resolving with the newly created metadata or an error dialog result
*/
static postMetadata(namespace: string, requestBody: any): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
const newCodeSnippet = {
schema_name: 'code-snippet',
display_name: 'My Python Helper',
name: 'python-helper',
metadata: {
language: 'Python',
code: ['import pandas as pd', 'import numpy as np']
}
};
const created = await FrontendServices.postMetadata(
'code-snippets',
JSON.stringify(newCodeSnippet)
);Update existing metadata instances.
/**
* Service function for making PUT calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param name - The metadata name being updated
* @param requestBody - The body of the request
* @returns Promise resolving with the updated metadata or an error dialog result
*/
static putMetadata(namespace: string, name: string, requestBody: any): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
const updatedCodeSnippet = {
schema_name: 'code-snippet',
display_name: 'Updated Python Helper',
name: 'python-helper',
metadata: {
language: 'Python',
code: ['import pandas as pd', 'import numpy as np', 'import matplotlib.pyplot as plt']
}
};
const updated = await FrontendServices.putMetadata(
'code-snippets',
'python-helper',
JSON.stringify(updatedCodeSnippet)
);Remove metadata instances from a namespace.
/**
* Service function for making DELETE calls to the elyra metadata API.
* @param namespace - The metadata namespace being accessed
* @param name - The metadata name being deleted
* @returns Promise resolving void or an error dialog result
*/
static deleteMetadata(namespace: string, name: string): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
// Delete a specific code snippet
await FrontendServices.deleteMetadata('code-snippets', 'python-helper');Operations for retrieving Elyra schema definitions with caching.
Retrieve schema definition for a specific namespace with automatic caching.
/**
* Service function for making GET calls to the elyra schema API.
* @param namespace - The schema namespace being requested
* @returns Promise resolving with the requested schemas or an error dialog result
*/
static getSchema(namespace: string): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
// Get code snippet schema (cached after first call)
const codeSnippetSchema = await FrontendServices.getSchema('code-snippets');
// Get runtime image schema
const runtimeImageSchema = await FrontendServices.getSchema('runtime-images');Retrieve all available schemas from all namespaces.
/**
* Service function for making GET calls to the elyra schema API.
* @returns Promise resolving with all available schemas or an error dialog result
*/
static getAllSchema(): Promise<any>;Usage Examples:
import { FrontendServices } from "@elyra/application";
// Get all schemas
const allSchemas = await FrontendServices.getAllSchema();
// Filter schemas by name
const schemaNames = allSchemas.map((schema: any) => schema.name);
console.log('Available schemas:', schemaNames);Display specialized error dialogs for metadata operations.
/**
* Displays a dialog for error cases during metadata calls.
* @param namespace - The metadata namespace that was being accessed when the error occurred
* @returns Promise resolving with whether the dialog was accepted
*/
static noMetadataError(namespace: string): Promise<Dialog.IResult<any>>;Usage Examples:
import { FrontendServices } from "@elyra/application";
// Show error when no metadata is configured
try {
const metadata = await FrontendServices.getMetadata('custom-namespace');
if (!metadata || metadata.length === 0) {
await FrontendServices.noMetadataError('custom-namespace');
}
} catch (error) {
await FrontendServices.noMetadataError('custom-namespace');
}FrontendServices uses these base endpoints defined as constants:
elyra/metadata/ (ELYRA_METADATA_API_ENDPOINT) - For CRUD operations on metadata instanceselyra/schema/ (ELYRA_SCHEMA_API_ENDPOINT) - For retrieving schema definitionselyra/namespace - For listing available namespacesThese endpoints are relative to the JupyterLab server base URL and are automatically joined by the RequestHandler's ServerConnection utilities.
The schema retrieval methods implement automatic caching:
getSchema(namespace) fetches from server and caches the result