UNPKG

@iota-big3/sdk-gateway

Version:

Universal API Gateway with protocol translation, intelligent routing, rate limiting, health checking, and caching

87 lines 3.16 kB
"use strict"; /** * @iota-big3/sdk-patterns * Standard patterns and interfaces for consistent API design across IOTA SDK */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ParameterOrder = exports.MethodNaming = exports.NetworkError = exports.AuthorizationError = exports.AuthenticationError = exports.NotFoundError = exports.ValidationError = exports.Err = exports.Ok = void 0; // Helper functions for Result pattern const Ok = (data) => ({ success: true, data }); exports.Ok = Ok; const Err = (error) => ({ success: false, error }); exports.Err = Err; // Standard error types class ValidationError extends Error { constructor(field, value, message) { super(message || `Validation failed for field '${field}'`); this.field = field; this.value = value; this.name = 'ValidationError'; } } exports.ValidationError = ValidationError; class NotFoundError extends Error { constructor(resource, id) { super(`${resource} with id '${id}' not found`); this.resource = resource; this.id = id; this.name = 'NotFoundError'; } } exports.NotFoundError = NotFoundError; class AuthenticationError extends Error { constructor(message = 'Authentication failed') { super(message); this.name = 'AuthenticationError'; } } exports.AuthenticationError = AuthenticationError; class AuthorizationError extends Error { constructor(action, resource) { super(`Not authorized to ${action} ${resource}`); this.action = action; this.resource = resource; this.name = 'AuthorizationError'; } } exports.AuthorizationError = AuthorizationError; class NetworkError extends Error { constructor(statusCode, message = 'Network request failed') { super(message); this.statusCode = statusCode; this.name = 'NetworkError'; } } exports.NetworkError = NetworkError; // Standard method naming conventions exports.MethodNaming = { // CRUD operations should use these prefixes create: ['create', 'add', 'insert'], read: ['get', 'find', 'fetch', 'retrieve', 'list', 'search'], update: ['update', 'modify', 'patch', 'set'], delete: ['delete', 'remove', 'destroy', 'purge'], // Other common operations validate: ['validate', 'verify', 'check', 'ensure'], transform: ['to', 'from', 'convert', 'parse', 'format', 'serialize', 'deserialize'], lifecycle: ['init', 'initialize', 'start', 'stop', 'restart', 'destroy', 'dispose', 'cleanup'], event: ['on', 'off', 'emit', 'subscribe', 'unsubscribe', 'listen'], async: ['Async', 'await', 'promise'], // Suffixes/patterns for async methods // Boolean methods should start with these boolean: ['is', 'has', 'can', 'should', 'will', 'did', 'does'] }; // Parameter ordering convention exports.ParameterOrder = [ 'id', // Identifiers first 'key', 'name', 'type', // Type/category second 'data', // Data objects third 'payload', 'body', 'options', // Configuration fourth 'config', 'settings', 'callback', // Callbacks last 'handler' ]; //# sourceMappingURL=index.js.map