UNPKG

@olakai/sdk

Version:

This document demonstrates how to use the Olakai SDK with all its features.

52 lines 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTimeoutMiddleware = createTimeoutMiddleware; exports.createValidationMiddleware = createValidationMiddleware; /** * Create a timeout middleware * This middleware sets a timeout for a function call. * @param _timeoutMs - The timeout in milliseconds * @returns A middleware function */ function createTimeoutMiddleware(_timeoutMs) { return { name: "timeout", beforeCall: async (args) => { // Store timeout info in args metadata (if supported) return args; }, }; } /** * Create a validation middleware * This middleware validates the arguments and result of a function call. * @param options - The options for the middleware * @param options.validateArgs - The function to validate the arguments * @param options.validateResult - The function to validate the result * @returns A middleware function */ function createValidationMiddleware(options) { const { validateArgs, validateResult } = options; return { name: "validation", beforeCall: async (args) => { if (validateArgs) { const validation = validateArgs(args); if (validation !== true) { throw new Error(`Argument validation failed: ${validation}`); } } return args; }, afterCall: async (result, _args) => { if (validateResult) { const validation = validateResult(result); if (validation !== true) { throw new Error(`Result validation failed: ${validation}`); } } return result; }, }; } //# sourceMappingURL=timeout.js.map