@jaypie/fabric 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ServiceSuite.d.ts +58 -0
- package/dist/cjs/commander/index.cjs +7 -7
- package/dist/cjs/commander/index.cjs.map +1 -1
- package/dist/cjs/data/index.cjs.map +1 -1
- package/dist/cjs/http/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +159 -7
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/lambda/index.cjs +7 -7
- package/dist/cjs/lambda/index.cjs.map +1 -1
- package/dist/cjs/llm/index.cjs +7 -7
- package/dist/cjs/llm/index.cjs.map +1 -1
- package/dist/cjs/mcp/FabricMcpServer.d.ts +44 -0
- package/dist/cjs/mcp/index.cjs +156 -7
- package/dist/cjs/mcp/index.cjs.map +1 -1
- package/dist/cjs/mcp/index.d.ts +2 -1
- package/dist/cjs/mcp/types.d.ts +66 -0
- package/dist/cjs/service.d.ts +5 -0
- package/dist/esm/ServiceSuite.d.ts +58 -0
- package/dist/esm/commander/index.js +7 -7
- package/dist/esm/commander/index.js.map +1 -1
- package/dist/esm/data/index.js.map +1 -1
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +158 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lambda/index.js +7 -7
- package/dist/esm/lambda/index.js.map +1 -1
- package/dist/esm/llm/index.js +7 -7
- package/dist/esm/llm/index.js.map +1 -1
- package/dist/esm/mcp/FabricMcpServer.d.ts +44 -0
- package/dist/esm/mcp/index.d.ts +2 -1
- package/dist/esm/mcp/index.js +155 -8
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/types.d.ts +66 -0
- package/package.json +1 -1
- package/dist/cjs/commander/registerServiceCommand.d.ts +0 -43
- package/dist/cjs/convert-date.d.ts +0 -47
- package/dist/cjs/convert.d.ts +0 -69
- package/dist/cjs/lambda/createLambdaService.d.ts +0 -33
- package/dist/cjs/llm/createLlmTool.d.ts +0 -40
- package/dist/cjs/mcp/registerMcpTool.d.ts +0 -38
- package/dist/cjs/types/fieldCategory.d.ts +0 -20
- package/dist/esm/commander/registerServiceCommand.d.ts +0 -43
- package/dist/esm/convert-date.d.ts +0 -47
- package/dist/esm/convert.d.ts +0 -69
- package/dist/esm/lambda/createLambdaService.d.ts +0 -33
- package/dist/esm/llm/createLlmTool.d.ts +0 -40
- package/dist/esm/mcp/registerMcpTool.d.ts +0 -38
- package/dist/esm/types/fieldCategory.d.ts +0 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../src/constants.ts","../../../../../src/resolve-date.ts","../../../../../src/resolve.ts","../../../../../src/service.ts","../../../../../src/resolveService.ts","../../../../../src/mcp/inputToZodShape.ts","../../../../../src/mcp/fabricMcp.ts"],"sourcesContent":["/**\n * Meta-modeling Constants\n */\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/** Root organizational unit */\nexport const APEX = \"@\";\n\n/** Fabric version - used to identify pre-instantiated Services */\nexport const FABRIC_VERSION = \"0.1.0\";\n\n/** Composite key separator */\nexport const SEPARATOR = \"#\";\n\n/** System-level models that describe other models */\nexport const SYSTEM_MODELS = [\"context\", \"field\", \"model\"] as const;\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type SystemModel = (typeof SYSTEM_MODELS)[number];\n","/**\n * Date Type Conversion for @jaypie/fabric\n *\n * Adds Date as a supported type in the fabric type system.\n * Follows the same conversion patterns as String, Number, Boolean.\n */\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\n/**\n * Check if a value is a valid Date\n */\nexport function isValidDate(value: unknown): value is Date {\n return value instanceof Date && !Number.isNaN(value.getTime());\n}\n\n/**\n * Convert a value to a Date\n *\n * Supported inputs:\n * - Date: returned as-is (validated)\n * - Number: treated as Unix timestamp (milliseconds)\n * - String: parsed via Date constructor (ISO 8601, etc.)\n * - Object with value property: unwrapped and converted\n *\n * @throws BadRequestError if value cannot be converted to valid Date\n */\nexport function fabricDate(value: unknown): Date {\n // Already a Date\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) {\n throw new BadRequestError(\"Invalid Date value\");\n }\n return value;\n }\n\n // Null/undefined\n if (value === null || value === undefined) {\n throw new BadRequestError(\"Cannot convert null or undefined to Date\");\n }\n\n // Object with value property (fabric pattern)\n if (typeof value === \"object\" && value !== null && \"value\" in value) {\n return fabricDate((value as { value: unknown }).value);\n }\n\n // Number (timestamp in milliseconds)\n if (typeof value === \"number\") {\n if (Number.isNaN(value)) {\n throw new BadRequestError(\"Cannot convert NaN to Date\");\n }\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new BadRequestError(`Cannot convert ${value} to Date`);\n }\n return date;\n }\n\n // String (ISO 8601 or parseable format)\n if (typeof value === \"string\") {\n // Empty string is invalid\n if (value.trim() === \"\") {\n throw new BadRequestError(\"Cannot convert empty string to Date\");\n }\n\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new BadRequestError(`Cannot convert \"${value}\" to Date`);\n }\n return date;\n }\n\n // Boolean cannot be converted to Date\n if (typeof value === \"boolean\") {\n throw new BadRequestError(\"Cannot convert boolean to Date\");\n }\n\n // Arrays - attempt single element extraction\n if (Array.isArray(value)) {\n if (value.length === 1) {\n return fabricDate(value[0]);\n }\n throw new BadRequestError(\n `Cannot convert array with ${value.length} elements to Date`,\n );\n }\n\n throw new BadRequestError(`Cannot convert ${typeof value} to Date`);\n}\n\n/**\n * Resolve a value from a Date to another type\n *\n * @param value - Date to convert\n * @param targetType - Target type (String, Number)\n */\nexport function resolveFromDate(\n value: Date,\n targetType: typeof Number | typeof String,\n): number | string {\n if (!isValidDate(value)) {\n throw new BadRequestError(\"Invalid Date value\");\n }\n\n if (targetType === String) {\n return value.toISOString();\n }\n\n if (targetType === Number) {\n return value.getTime();\n }\n\n throw new BadRequestError(`Cannot convert Date to ${targetType}`);\n}\n\n/**\n * Date type constant for use in fabricService input definitions\n *\n * Usage:\n * ```typescript\n * const handler = fabricService({\n * input: {\n * startDate: { type: Date },\n * endDate: { type: Date, default: undefined }\n * }\n * });\n * ```\n */\nexport const DateType = Date;\n\n/**\n * Type guard for Date type in schema definitions\n */\nexport function isDateType(type: unknown): type is typeof Date {\n return type === Date;\n}\n","// Fabric functions for @jaypie/fabric\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\nimport { fabricDate, isDateType } from \"./resolve-date.js\";\nimport type { ConversionType, TypedArrayType } from \"./types.js\";\n\n/**\n * Try to parse a string as JSON if it looks like JSON\n * Returns the parsed value or the original string if not JSON\n */\nfunction tryParseJson(value: string): unknown {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) ||\n (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\"))\n ) {\n try {\n return JSON.parse(trimmed);\n } catch {\n // Not valid JSON, return original\n return value;\n }\n }\n return value;\n}\n\n/**\n * Unwrap arrays and objects to get to the scalar value\n * - Single-element arrays unwrap to their element\n * - Objects with value property unwrap to that value\n * - Recursively unwraps nested structures\n */\nfunction unwrapToScalar(value: unknown): unknown {\n if (value === undefined || value === null) {\n return value;\n }\n\n // Unwrap single-element arrays\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n if (value.length === 1) {\n return unwrapToScalar(value[0]);\n }\n throw new BadRequestError(\"Cannot convert multi-value array to scalar\");\n }\n\n // Unwrap objects with value property\n if (typeof value === \"object\") {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return unwrapToScalar(obj.value);\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n return value;\n}\n\n/**\n * Prepare a value for scalar conversion by parsing JSON strings and unwrapping\n */\nfunction prepareForScalarConversion(value: unknown): unknown {\n if (value === undefined || value === null) {\n return value;\n }\n\n // Try to parse JSON strings\n if (typeof value === \"string\") {\n const parsed = tryParseJson(value);\n if (parsed !== value) {\n // Successfully parsed, unwrap the result\n return unwrapToScalar(parsed);\n }\n return value;\n }\n\n // Unwrap arrays and objects\n if (Array.isArray(value) || typeof value === \"object\") {\n return unwrapToScalar(value);\n }\n\n return value;\n}\n\n/**\n * Convert a value to a boolean\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"true\" becomes true\n * - String \"false\" becomes false\n * - Strings that parse to numbers: positive = true, zero or negative = false\n * - Numbers: positive = true, zero or negative = false\n * - Boolean passes through\n */\nexport function fabricBoolean(value: unknown): boolean | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n const lower = prepared.toLowerCase();\n if (lower === \"true\") {\n return true;\n }\n if (lower === \"false\") {\n return false;\n }\n // Try to parse as number\n const num = parseFloat(prepared);\n if (isNaN(num)) {\n throw new BadRequestError(`Cannot convert \"${prepared}\" to Boolean`);\n }\n return num > 0;\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to Boolean\");\n }\n return prepared > 0;\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to Boolean`);\n}\n\n/**\n * Convert a value to a number\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"\" becomes undefined\n * - String \"true\" becomes 1\n * - String \"false\" becomes 0\n * - Strings that parse to numbers use those values\n * - Strings that parse to NaN throw BadRequestError\n * - Boolean true becomes 1, false becomes 0\n * - Number passes through\n */\nexport function fabricNumber(value: unknown): number | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to Number\");\n }\n return prepared;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared ? 1 : 0;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n const lower = prepared.toLowerCase();\n if (lower === \"true\") {\n return 1;\n }\n if (lower === \"false\") {\n return 0;\n }\n const num = parseFloat(prepared);\n if (isNaN(num)) {\n throw new BadRequestError(`Cannot convert \"${prepared}\" to Number`);\n }\n return num;\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to Number`);\n}\n\n/**\n * Convert a value to a string\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"\" becomes undefined\n * - Boolean true becomes \"true\", false becomes \"false\"\n * - Number converts to string representation\n * - String passes through\n */\nexport function fabricString(value: unknown): string | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n return prepared;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared ? \"true\" : \"false\";\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to String\");\n }\n return String(prepared);\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to String`);\n}\n\n/**\n * Convert a value to an array\n * - Non-arrays become arrays containing that value\n * - Arrays of a single value become that value (unwrapped)\n * - Multi-value arrays throw BadRequestError\n * - undefined/null become undefined\n */\nexport function fabricArray(value: unknown): unknown[] | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n // Arrays pass through (single-element unwrapping happens when converting FROM array)\n return value;\n }\n\n // Non-arrays become single-element arrays\n return [value];\n}\n\n/**\n * Resolve a value from an array to a scalar\n * - Single-element arrays become that element\n * - Multi-element arrays throw BadRequestError\n * - Non-arrays pass through\n */\nexport function resolveFromArray(value: unknown): unknown {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n if (value.length === 1) {\n return value[0];\n }\n throw new BadRequestError(\"Cannot convert multi-value array to scalar\");\n }\n\n return value;\n}\n\n/**\n * Convert a value to an object with a value property\n * - Scalars become { value: scalar }\n * - Arrays become { value: array }\n * - Objects with a value attribute pass through\n * - Objects without a value attribute throw BadRequestError\n * - undefined/null become undefined\n */\nexport function fabricObject(value: unknown): { value: unknown } | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n // Check if already an object (but not an array)\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return obj as { value: unknown };\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n // Scalars and arrays become { value: ... }\n return { value };\n}\n\n/**\n * Resolve a value from an object to its value property\n * - Objects with a value property return that value\n * - Objects without a value throw BadRequestError\n * - Scalars pass through\n */\nexport function resolveFromObject(value: unknown): unknown {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return obj.value;\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n return value;\n}\n\n/**\n * Check if a type is a typed array (e.g., [String], [Number], [], etc.)\n */\nfunction isTypedArrayType(type: ConversionType): type is TypedArrayType {\n return Array.isArray(type);\n}\n\n/**\n * Split a string on comma or tab delimiters for typed array conversion.\n * Only splits if the string contains commas or tabs.\n * Returns the original value if not a string or no delimiters found.\n */\nfunction splitStringForArray(value: unknown): unknown {\n if (typeof value !== \"string\") {\n return value;\n }\n\n // Check for comma or tab delimiters\n if (value.includes(\",\")) {\n return value.split(\",\").map((s) => s.trim());\n }\n if (value.includes(\"\\t\")) {\n return value.split(\"\\t\").map((s) => s.trim());\n }\n\n return value;\n}\n\n/**\n * Try to parse a string as JSON for array context.\n * Returns parsed value if it's an array, otherwise returns original.\n */\nfunction tryParseJsonArray(value: unknown): unknown {\n if (typeof value !== \"string\") {\n return value;\n }\n\n const trimmed = value.trim();\n if (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\")) {\n try {\n const parsed = JSON.parse(trimmed);\n if (Array.isArray(parsed)) {\n return parsed;\n }\n } catch {\n // Not valid JSON, fall through\n }\n }\n\n return value;\n}\n\n/**\n * Get the element type from a typed array type\n * Returns undefined for untyped arrays ([])\n */\nfunction getArrayElementType(\n type: TypedArrayType,\n): \"boolean\" | \"number\" | \"object\" | \"string\" | undefined {\n if (type.length === 0) {\n return undefined; // Untyped array\n }\n\n const elementType = type[0];\n\n // Handle constructor types\n if (elementType === Boolean) return \"boolean\";\n if (elementType === Number) return \"number\";\n if (elementType === String) return \"string\";\n if (elementType === Object) return \"object\";\n\n // Handle string types\n if (elementType === \"boolean\") return \"boolean\";\n if (elementType === \"number\") return \"number\";\n if (elementType === \"string\") return \"string\";\n if (elementType === \"object\") return \"object\";\n\n // Handle shorthand types\n if (elementType === \"\") return \"string\"; // \"\" shorthand for String\n if (\n typeof elementType === \"object\" &&\n elementType !== null &&\n Object.keys(elementType).length === 0\n ) {\n return \"object\"; // {} shorthand for Object\n }\n\n throw new BadRequestError(\n `Unknown array element type: ${String(elementType)}`,\n );\n}\n\n/**\n * Convert a value to a typed array\n * - Tries to parse JSON arrays first\n * - Splits strings on comma/tab if present\n * - Wraps non-arrays in an array\n * - Converts each element to the specified element type\n */\nfunction fabricTypedArray(\n value: unknown,\n elementType: \"boolean\" | \"number\" | \"object\" | \"string\" | undefined,\n): unknown[] | undefined {\n // Try to parse JSON array first\n let processed = tryParseJsonArray(value);\n\n // If still a string, try to split on comma/tab\n processed = splitStringForArray(processed);\n\n // Convert to array (wraps non-arrays)\n const array = fabricArray(processed);\n\n if (array === undefined) {\n return undefined;\n }\n\n // If no element type specified, return as-is\n if (elementType === undefined) {\n return array;\n }\n\n // Convert each element to the element type\n return array.map((element, index) => {\n try {\n switch (elementType) {\n case \"boolean\":\n return fabricBoolean(element);\n case \"number\":\n return fabricNumber(element);\n case \"object\":\n return fabricObject(element);\n case \"string\":\n return fabricString(element);\n default:\n throw new BadRequestError(`Unknown element type: ${elementType}`);\n }\n } catch (error) {\n if (error instanceof BadRequestError) {\n throw new BadRequestError(\n `Cannot convert array element at index ${index}: ${error.message}`,\n );\n }\n throw error;\n }\n });\n}\n\n/**\n * Fabric a value to the specified type\n */\nexport function fabric(value: unknown, type: ConversionType): unknown {\n // Check for Date type first\n if (isDateType(type)) {\n return fabricDate(value);\n }\n\n // Check for typed array types\n if (isTypedArrayType(type)) {\n const elementType = getArrayElementType(type);\n return fabricTypedArray(value, elementType);\n }\n\n const normalizedType = normalizeType(type);\n\n switch (normalizedType) {\n case \"array\":\n return fabricArray(value);\n case \"boolean\":\n return fabricBoolean(value);\n case \"number\":\n return fabricNumber(value);\n case \"object\":\n return fabricObject(value);\n case \"string\":\n return fabricString(value);\n default:\n throw new BadRequestError(`Unknown type: ${String(type)}`);\n }\n}\n\n/**\n * Normalize type to string representation\n */\nfunction normalizeType(\n type: ConversionType,\n): \"array\" | \"boolean\" | \"number\" | \"object\" | \"string\" {\n if (type === Array || type === \"array\") {\n return \"array\";\n }\n if (type === Boolean || type === \"boolean\") {\n return \"boolean\";\n }\n if (type === Number || type === \"number\") {\n return \"number\";\n }\n if (type === Object || type === \"object\") {\n return \"object\";\n }\n if (type === String || type === \"string\") {\n return \"string\";\n }\n throw new BadRequestError(`Unknown type: ${String(type)}`);\n}\n","// Service for @jaypie/fabric\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\nimport { FABRIC_VERSION } from \"./constants.js\";\nimport { fabric } from \"./resolve.js\";\nimport type {\n ConversionType,\n InputFieldDefinition,\n Service,\n ServiceConfig,\n ServiceContext,\n ValidateFunction,\n} from \"./types.js\";\n\n/**\n * Check if a single-element array is a typed array type constructor.\n */\nfunction isTypedArrayConstructor(element: unknown): boolean {\n return (\n element === Boolean ||\n element === Number ||\n element === String ||\n element === Object ||\n element === \"boolean\" ||\n element === \"number\" ||\n element === \"string\" ||\n element === \"object\" ||\n element === \"\" ||\n (typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0)\n );\n}\n\n/**\n * Check if a type is a validated string type (array of string literals and/or RegExp).\n * Distinguishes from typed arrays like [String], [Number], etc.\n */\nfunction isValidatedStringType(\n type: ConversionType,\n): type is Array<string | RegExp> {\n if (!Array.isArray(type)) {\n return false;\n }\n\n // Empty array is untyped array, not validated string\n if (type.length === 0) {\n return false;\n }\n\n // Single-element arrays with type constructors are typed arrays\n if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n return false;\n }\n\n // Check that all elements are strings or RegExp\n return type.every(\n (item) => typeof item === \"string\" || item instanceof RegExp,\n );\n}\n\n/**\n * Check if a type is a validated number type (array of number literals).\n * Distinguishes from typed arrays like [Number], etc.\n */\nfunction isValidatedNumberType(type: ConversionType): type is Array<number> {\n if (!Array.isArray(type)) {\n return false;\n }\n\n // Empty array is untyped array, not validated number\n if (type.length === 0) {\n return false;\n }\n\n // Single-element arrays with type constructors are typed arrays\n if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n return false;\n }\n\n // Check that all elements are numbers\n return type.every((item) => typeof item === \"number\");\n}\n\n/**\n * Parse input string as JSON if it's a string\n */\nfunction parseInput(input: unknown): Record<string, unknown> {\n if (input === undefined || input === null) {\n return {};\n }\n\n if (typeof input === \"string\") {\n if (input === \"\") {\n return {};\n }\n try {\n const parsed = JSON.parse(input);\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n Array.isArray(parsed)\n ) {\n throw new BadRequestError(\"Input must be an object\");\n }\n return parsed as Record<string, unknown>;\n } catch (error) {\n if (error instanceof BadRequestError) {\n throw error;\n }\n throw new BadRequestError(\"Invalid JSON input\");\n }\n }\n\n if (typeof input === \"object\" && !Array.isArray(input)) {\n return input as Record<string, unknown>;\n }\n\n throw new BadRequestError(\"Input must be an object or JSON string\");\n}\n\n/**\n * Run validation on a value (supports async validators)\n */\nasync function runValidation(\n value: unknown,\n validate: ValidateFunction | RegExp | Array<unknown>,\n fieldName: string,\n): Promise<void> {\n if (typeof validate === \"function\") {\n const result = await validate(value);\n if (result === false) {\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n } else if (validate instanceof RegExp) {\n if (typeof value !== \"string\" || !validate.test(value)) {\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n } else if (Array.isArray(validate)) {\n // Check if value matches any item in the array\n for (const item of validate) {\n if (item instanceof RegExp) {\n if (typeof value === \"string\" && item.test(value)) {\n return; // Match found\n }\n } else if (typeof item === \"function\") {\n try {\n const result = await (item as ValidateFunction)(value);\n if (result !== false) {\n return; // Match found\n }\n } catch {\n // Continue to next item\n }\n } else if (value === item) {\n return; // Scalar match found\n }\n }\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n}\n\n/**\n * Check if a field is required\n * A field is required unless it has a default OR required is explicitly false\n */\nfunction isFieldRequired(definition: InputFieldDefinition): boolean {\n if (definition.required === false) {\n return false;\n }\n if (definition.default !== undefined) {\n return false;\n }\n return true;\n}\n\n/**\n * Process a single field through conversion and validation\n */\nasync function processField(\n fieldName: string,\n value: unknown,\n definition: InputFieldDefinition,\n): Promise<unknown> {\n // Apply default if value is undefined\n let processedValue = value;\n if (processedValue === undefined && definition.default !== undefined) {\n processedValue = definition.default;\n }\n\n // Determine actual type and validation\n let actualType: ConversionType = definition.type;\n let validation = definition.validate;\n\n // Handle bare RegExp shorthand: /regex/\n if (definition.type instanceof RegExp) {\n actualType = String;\n validation = definition.type; // The RegExp becomes the validation\n }\n // Handle validated string shorthand: [\"value1\", \"value2\"] or [/regex/]\n else if (isValidatedStringType(definition.type)) {\n actualType = String;\n validation = definition.type; // The array becomes the validation\n }\n // Handle validated number shorthand: [1, 2, 3]\n else if (isValidatedNumberType(definition.type)) {\n actualType = Number;\n validation = definition.type; // The array becomes the validation\n }\n\n // Fabric to target type\n const convertedValue = fabric(processedValue, actualType);\n\n // Check if required field is missing\n if (convertedValue === undefined && isFieldRequired(definition)) {\n throw new BadRequestError(`Missing required field \"${fieldName}\"`);\n }\n\n // Run validation if provided\n if (validation !== undefined && convertedValue !== undefined) {\n await runValidation(convertedValue, validation, fieldName);\n }\n\n return convertedValue;\n}\n\n/**\n * Fabric a service function\n *\n * Service builds a function that initiates a \"controller\" step that:\n * - Parses the input if it is a string to object\n * - Fabrics each input field to its type\n * - Calls the validation function or regular expression or checks the array\n * - Calls the service function and returns the response\n *\n * The returned function has config properties for introspection.\n */\nexport function fabricService<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n>(config: ServiceConfig<TInput, TOutput>): Service<TInput, TOutput> {\n const { input: inputDefinitions, service } = config;\n\n const handler = async (\n rawInput?: Partial<TInput> | string,\n context?: ServiceContext,\n ): Promise<TOutput> => {\n // Parse input (handles string JSON)\n const parsedInput = parseInput(rawInput);\n\n // If no input definitions, pass through to service or return parsed input\n if (!inputDefinitions) {\n if (service) {\n return service(parsedInput as TInput, context);\n }\n return parsedInput as TOutput;\n }\n\n // Process all fields in parallel\n const entries = Object.entries(inputDefinitions);\n const processedValues = await Promise.all(\n entries.map(([fieldName, definition]) =>\n processField(fieldName, parsedInput[fieldName], definition),\n ),\n );\n\n // Build processed input object\n const processedInput: Record<string, unknown> = {};\n entries.forEach(([fieldName], index) => {\n processedInput[fieldName] = processedValues[index];\n });\n\n // Return processed input if no service, otherwise call service\n if (service) {\n return service(processedInput as TInput, context);\n }\n return processedInput as TOutput;\n };\n\n // Attach config properties directly to handler for flat access\n const typedHandler = handler as Service<TInput, TOutput>;\n typedHandler.$fabric = FABRIC_VERSION;\n if (config.alias !== undefined) typedHandler.alias = config.alias;\n if (config.description !== undefined)\n typedHandler.description = config.description;\n if (config.input !== undefined) typedHandler.input = config.input;\n if (config.service !== undefined) typedHandler.service = config.service;\n\n return typedHandler;\n}\n","// Resolve inline service definitions to full Service objects\n\nimport { fabricService } from \"./service.js\";\nimport type {\n InputFieldDefinition,\n Service,\n ServiceFunction,\n} from \"./types.js\";\n\n/**\n * Configuration for resolving a service\n */\nexport interface ResolveServiceConfig<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n> {\n /** Service alias (used as name for adapters) */\n alias?: string;\n /** Service description */\n description?: string;\n /** Input field definitions */\n input?: Record<string, InputFieldDefinition>;\n /** The service - either a pre-instantiated Service or an inline function */\n service: Service<TInput, TOutput> | ServiceFunction<TInput, TOutput>;\n}\n\n/**\n * Type guard to check if a value is a pre-instantiated Service\n * A Service is a function with the `$fabric` property set by fabricService\n */\nfunction isService<TInput extends Record<string, unknown>, TOutput>(\n value: Service<TInput, TOutput> | ServiceFunction<TInput, TOutput>,\n): value is Service<TInput, TOutput> {\n return typeof value === \"function\" && \"$fabric\" in value;\n}\n\n/**\n * Resolve a service configuration to a full Service object\n *\n * Supports two patterns:\n * 1. Inline service definition - pass a plain function as `service` along with\n * `alias`, `description`, and `input` in the config\n * 2. Pre-instantiated Service - pass a Service object as `service`\n *\n * When a pre-instantiated Service is passed, config fields act as overrides:\n * - `alias` overrides service.alias\n * - `description` overrides service.description\n * - `input` overrides service.input\n *\n * The original Service is never mutated - a new Service is created when overrides\n * are applied.\n *\n * @example\n * ```typescript\n * // Inline service definition\n * const service = resolveService({\n * alias: \"greet\",\n * description: \"Greet a user\",\n * input: { name: { type: String } },\n * service: ({ name }) => `Hello, ${name}!`,\n * });\n *\n * // Pre-instantiated with override\n * const baseService = fabricService({ alias: \"foo\", service: (x) => x });\n * const overridden = resolveService({\n * alias: \"bar\", // Override alias\n * service: baseService,\n * });\n * ```\n */\nexport function resolveService<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n>(config: ResolveServiceConfig<TInput, TOutput>): Service<TInput, TOutput> {\n const { alias, description, input, service } = config;\n\n if (isService(service)) {\n // Service is pre-instantiated - config fields act as overrides\n // Create new Service with merged properties (config overrides service)\n return fabricService({\n alias: alias ?? service.alias,\n description: description ?? service.description,\n input: input ?? service.input,\n service: service.service,\n });\n }\n\n // Service is an inline function - create Service from config\n return fabricService({\n alias,\n description,\n input,\n service,\n });\n}\n","// Convert fabric input definitions to Zod schema shape for MCP SDK\n\nimport type { z } from \"zod\";\n\nimport { isDateType } from \"../resolve-date.js\";\nimport type { ConversionType, InputFieldDefinition } from \"../types.js\";\n\n/**\n * Zod schema shape for MCP tool registration\n * This is a record of field names to Zod types\n */\nexport type ZodSchemaShape = Record<string, z.ZodTypeAny>;\n\n/**\n * Check if a single-element array is a typed array type constructor.\n */\nfunction isTypedArrayConstructor(element: unknown): boolean {\n return (\n element === Boolean ||\n element === Number ||\n element === String ||\n element === Object ||\n element === \"boolean\" ||\n element === \"number\" ||\n element === \"string\" ||\n element === \"object\" ||\n element === \"\" ||\n (typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0)\n );\n}\n\n/**\n * Get the array element type for typed arrays\n */\nfunction getTypedArrayElementType(\n type: ConversionType,\n): \"boolean\" | \"number\" | \"object\" | \"string\" | undefined {\n if (!Array.isArray(type) || type.length !== 1) return undefined;\n\n const element = type[0];\n if (element === Boolean || element === \"boolean\") return \"boolean\";\n if (element === Number || element === \"number\") return \"number\";\n if (element === String || element === \"string\" || element === \"\")\n return \"string\";\n if (element === Object || element === \"object\") return \"object\";\n if (\n typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0\n ) {\n return \"object\";\n }\n\n return undefined;\n}\n\n/**\n * Get enum values for validated types\n */\nfunction getEnumValues(type: ConversionType): string[] | undefined {\n if (!Array.isArray(type)) return undefined;\n if (type.length === 0) return undefined;\n if (type.length === 1 && isTypedArrayConstructor(type[0])) return undefined;\n\n // Check if it's a validated string type (strings only, no RegExp)\n if (type.every((item) => typeof item === \"string\")) {\n return type as string[];\n }\n\n return undefined;\n}\n\n/**\n * Check if a field is required\n */\nfunction isFieldRequired(definition: InputFieldDefinition): boolean {\n if (definition.required === false) {\n return false;\n }\n if (definition.default !== undefined) {\n return false;\n }\n return true;\n}\n\n/**\n * Convert a single input field definition to a Zod type\n */\nfunction inputFieldToZod(\n z: typeof import(\"zod\").z,\n definition: InputFieldDefinition,\n): z.ZodTypeAny {\n const { type } = definition;\n\n let zodType: z.ZodTypeAny;\n\n // Handle constructors and primitives\n if (type === Boolean || type === \"boolean\") {\n zodType = z.boolean();\n } else if (type === Number || type === \"number\") {\n zodType = z.number();\n } else if (type === String || type === \"string\") {\n zodType = z.string();\n } else if (type === Object || type === \"object\") {\n zodType = z.record(z.string(), z.unknown());\n } else if (type === Array || type === \"array\") {\n zodType = z.array(z.unknown());\n }\n // Handle Date type (represented as string in schema)\n else if (isDateType(type)) {\n zodType = z.string();\n }\n // Handle RegExp (converts to string)\n else if (type instanceof RegExp) {\n zodType = z.string();\n }\n // Handle arrays\n else if (Array.isArray(type)) {\n // Empty array = untyped array\n if (type.length === 0) {\n zodType = z.array(z.unknown());\n }\n // Single-element typed array like [String], [Number], etc.\n else if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n const elementType = getTypedArrayElementType(type);\n switch (elementType) {\n case \"boolean\":\n zodType = z.array(z.boolean());\n break;\n case \"number\":\n zodType = z.array(z.number());\n break;\n case \"string\":\n zodType = z.array(z.string());\n break;\n case \"object\":\n zodType = z.array(z.record(z.string(), z.unknown()));\n break;\n default:\n zodType = z.array(z.unknown());\n }\n }\n // Validated string type: [\"value1\", \"value2\"]\n else {\n const enumValues = getEnumValues(type);\n if (enumValues && enumValues.length >= 2) {\n zodType = z.enum(enumValues as [string, ...string[]]);\n } else if (enumValues && enumValues.length === 1) {\n zodType = z.literal(enumValues[0]);\n } else {\n // Fallback for other array types (including RegExp arrays)\n zodType = z.string();\n }\n }\n }\n // Default to string\n else {\n zodType = z.string();\n }\n\n // Add description\n if (definition.description) {\n zodType = zodType.describe(definition.description);\n }\n\n // Handle optionality and defaults\n if (!isFieldRequired(definition)) {\n if (definition.default !== undefined) {\n zodType = zodType.optional().default(definition.default);\n } else {\n zodType = zodType.optional();\n }\n }\n\n return zodType;\n}\n\n/**\n * Convert fabric input definitions to a Zod schema shape for MCP SDK\n *\n * @param z - The zod module (passed in to avoid optional dependency import)\n * @param input - The input definitions from the service\n * @returns Zod schema shape object compatible with MCP server.tool()\n */\nexport function inputToZodShape(\n z: typeof import(\"zod\").z,\n input?: Record<string, InputFieldDefinition>,\n): ZodSchemaShape {\n if (!input) {\n return {};\n }\n\n const shape: ZodSchemaShape = {};\n\n // Sort keys alphabetically for consistency\n const sortedKeys = Object.keys(input).sort();\n\n for (const key of sortedKeys) {\n const definition = input[key];\n shape[key] = inputFieldToZod(z, definition);\n }\n\n return shape;\n}\n","// Fabric a service as an MCP tool\n\nimport { z } from \"zod\";\n\nimport { resolveService } from \"../resolveService.js\";\nimport type { Message, ServiceContext } from \"../types.js\";\nimport { inputToZodShape } from \"./inputToZodShape.js\";\nimport type { FabricMcpConfig, FabricMcpResult } from \"./types.js\";\n\n/**\n * Format a value as a string for MCP response\n */\nfunction formatResult(value: unknown): string {\n if (value === undefined || value === null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"object\") {\n return JSON.stringify(value, null, 2);\n }\n return String(value);\n}\n\n/**\n * Fabric a service as an MCP tool\n *\n * This function registers a service with an MCP server.\n * It automatically:\n * - Uses service.alias as the tool name (or custom name)\n * - Uses service.description as the tool description (or custom)\n * - Delegates validation to the service\n * - Wraps the service and formats the response\n *\n * @param config - Configuration including service, server, and optional overrides\n * @returns An object containing the fabricated tool name\n *\n * @example\n * ```typescript\n * import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\n * import { fabricService } from \"@jaypie/fabric\";\n * import { fabricMcp } from \"@jaypie/fabric/mcp\";\n *\n * const myService = fabricService({\n * alias: \"greet\",\n * description: \"Greet a user by name\",\n * input: {\n * userName: { type: String, description: \"The user's name\" },\n * loud: { type: Boolean, default: false, description: \"Shout the greeting\" },\n * },\n * service: ({ userName, loud }) => {\n * const greeting = `Hello, ${userName}!`;\n * return loud ? greeting.toUpperCase() : greeting;\n * },\n * });\n *\n * const server = new McpServer({ name: \"my-server\", version: \"1.0.0\" });\n * fabricMcp({ server, service: myService });\n * ```\n */\nexport function fabricMcp(config: FabricMcpConfig): FabricMcpResult {\n const {\n alias,\n description,\n input,\n name,\n onComplete,\n onError,\n onFatal,\n onMessage,\n server,\n service: serviceOrFunction,\n } = config;\n\n // Resolve inline service or apply overrides to pre-instantiated service\n const service = resolveService({\n alias,\n description,\n input,\n service: serviceOrFunction,\n });\n\n // Determine tool name (priority: name > service.alias > \"tool\")\n const toolName = name ?? service.alias ?? \"tool\";\n\n // Determine tool description\n const toolDescription = service.description ?? \"\";\n\n // Create context callbacks that wrap with error swallowing\n const sendMessage = onMessage\n ? async (msg: Message): Promise<void> => {\n try {\n await onMessage(msg);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnError = onError\n ? async (error: unknown): Promise<void> => {\n try {\n await onError(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnFatal = onFatal\n ? async (error: unknown): Promise<void> => {\n try {\n await onFatal(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n // Create context for the service\n const context: ServiceContext = {\n onError: contextOnError,\n onFatal: contextOnFatal,\n sendMessage,\n };\n\n // Convert input definitions to Zod schema for MCP SDK\n const zodSchema = inputToZodShape(z, service.input);\n\n // Register the tool with the MCP server\n server.tool(toolName, toolDescription, zodSchema, async (args) => {\n try {\n const result = await service(args as Record<string, unknown>, context);\n\n // Call onComplete if provided\n if (onComplete) {\n try {\n await onComplete(result);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n\n return {\n content: [\n {\n text: formatResult(result),\n type: \"text\" as const,\n },\n ],\n };\n } catch (error) {\n // Any thrown error is fatal\n if (onFatal) {\n await onFatal(error);\n } else if (onError) {\n await onError(error);\n }\n throw error;\n }\n });\n\n return { name: toolName };\n}\n"],"names":["isTypedArrayConstructor","isFieldRequired"],"mappings":";;;AAAA;;AAEG;AAEH;AACA;AACA;AAEA;AAGA;AACO,MAAM,cAAc,GAAG,OAAO;;ACZrC;;;;;AAKG;AAWH;;;;;;;;;;AAUG;AACG,SAAU,UAAU,CAAC,KAAc,EAAA;;AAEvC,IAAA,IAAI,KAAK,YAAY,IAAI,EAAE;QACzB,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE;AACjC,YAAA,MAAM,IAAI,eAAe,CAAC,oBAAoB,CAAC;QACjD;AACA,QAAA,OAAO,KAAK;IACd;;IAGA,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE;AACzC,QAAA,MAAM,IAAI,eAAe,CAAC,0CAA0C,CAAC;IACvE;;AAGA,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,EAAE;AACnE,QAAA,OAAO,UAAU,CAAE,KAA4B,CAAC,KAAK,CAAC;IACxD;;AAGA,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;AACvB,YAAA,MAAM,IAAI,eAAe,CAAC,4BAA4B,CAAC;QACzD;AACA,QAAA,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC;QAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE;AAChC,YAAA,MAAM,IAAI,eAAe,CAAC,kBAAkB,KAAK,CAAA,QAAA,CAAU,CAAC;QAC9D;AACA,QAAA,OAAO,IAAI;IACb;;AAGA,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;;AAE7B,QAAA,IAAI,KAAK,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AAO,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC3B;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/constants.ts","../../../../../src/resolve-date.ts","../../../../../src/resolve.ts","../../../../../src/service.ts","../../../../../src/resolveService.ts","../../../../../src/mcp/inputToZodShape.ts","../../../../../src/mcp/fabricMcp.ts","../../../../../src/mcp/FabricMcpServer.ts"],"sourcesContent":["/**\n * Meta-modeling Constants\n */\n\n// =============================================================================\n// Constants\n// =============================================================================\n\n/** Root organizational unit */\nexport const APEX = \"@\";\n\n/** Fabric version - used to identify pre-instantiated Services */\nexport const FABRIC_VERSION = \"0.1.0\";\n\n/** Composite key separator */\nexport const SEPARATOR = \"#\";\n\n/** System-level models that describe other models */\nexport const SYSTEM_MODELS = [\"context\", \"field\", \"model\"] as const;\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type SystemModel = (typeof SYSTEM_MODELS)[number];\n","/**\n * Date Type Conversion for @jaypie/fabric\n *\n * Adds Date as a supported type in the fabric type system.\n * Follows the same conversion patterns as String, Number, Boolean.\n */\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\n/**\n * Check if a value is a valid Date\n */\nexport function isValidDate(value: unknown): value is Date {\n return value instanceof Date && !Number.isNaN(value.getTime());\n}\n\n/**\n * Convert a value to a Date\n *\n * Supported inputs:\n * - Date: returned as-is (validated)\n * - Number: treated as Unix timestamp (milliseconds)\n * - String: parsed via Date constructor (ISO 8601, etc.)\n * - Object with value property: unwrapped and converted\n *\n * @throws BadRequestError if value cannot be converted to valid Date\n */\nexport function fabricDate(value: unknown): Date {\n // Already a Date\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) {\n throw new BadRequestError(\"Invalid Date value\");\n }\n return value;\n }\n\n // Null/undefined\n if (value === null || value === undefined) {\n throw new BadRequestError(\"Cannot convert null or undefined to Date\");\n }\n\n // Object with value property (fabric pattern)\n if (typeof value === \"object\" && value !== null && \"value\" in value) {\n return fabricDate((value as { value: unknown }).value);\n }\n\n // Number (timestamp in milliseconds)\n if (typeof value === \"number\") {\n if (Number.isNaN(value)) {\n throw new BadRequestError(\"Cannot convert NaN to Date\");\n }\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new BadRequestError(`Cannot convert ${value} to Date`);\n }\n return date;\n }\n\n // String (ISO 8601 or parseable format)\n if (typeof value === \"string\") {\n // Empty string is invalid\n if (value.trim() === \"\") {\n throw new BadRequestError(\"Cannot convert empty string to Date\");\n }\n\n const date = new Date(value);\n if (Number.isNaN(date.getTime())) {\n throw new BadRequestError(`Cannot convert \"${value}\" to Date`);\n }\n return date;\n }\n\n // Boolean cannot be converted to Date\n if (typeof value === \"boolean\") {\n throw new BadRequestError(\"Cannot convert boolean to Date\");\n }\n\n // Arrays - attempt single element extraction\n if (Array.isArray(value)) {\n if (value.length === 1) {\n return fabricDate(value[0]);\n }\n throw new BadRequestError(\n `Cannot convert array with ${value.length} elements to Date`,\n );\n }\n\n throw new BadRequestError(`Cannot convert ${typeof value} to Date`);\n}\n\n/**\n * Resolve a value from a Date to another type\n *\n * @param value - Date to convert\n * @param targetType - Target type (String, Number)\n */\nexport function resolveFromDate(\n value: Date,\n targetType: typeof Number | typeof String,\n): number | string {\n if (!isValidDate(value)) {\n throw new BadRequestError(\"Invalid Date value\");\n }\n\n if (targetType === String) {\n return value.toISOString();\n }\n\n if (targetType === Number) {\n return value.getTime();\n }\n\n throw new BadRequestError(`Cannot convert Date to ${targetType}`);\n}\n\n/**\n * Date type constant for use in fabricService input definitions\n *\n * Usage:\n * ```typescript\n * const handler = fabricService({\n * input: {\n * startDate: { type: Date },\n * endDate: { type: Date, default: undefined }\n * }\n * });\n * ```\n */\nexport const DateType = Date;\n\n/**\n * Type guard for Date type in schema definitions\n */\nexport function isDateType(type: unknown): type is typeof Date {\n return type === Date;\n}\n","// Fabric functions for @jaypie/fabric\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\nimport { fabricDate, isDateType } from \"./resolve-date.js\";\nimport type { ConversionType, TypedArrayType } from \"./types.js\";\n\n/**\n * Try to parse a string as JSON if it looks like JSON\n * Returns the parsed value or the original string if not JSON\n */\nfunction tryParseJson(value: string): unknown {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) ||\n (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\"))\n ) {\n try {\n return JSON.parse(trimmed);\n } catch {\n // Not valid JSON, return original\n return value;\n }\n }\n return value;\n}\n\n/**\n * Unwrap arrays and objects to get to the scalar value\n * - Single-element arrays unwrap to their element\n * - Objects with value property unwrap to that value\n * - Recursively unwraps nested structures\n */\nfunction unwrapToScalar(value: unknown): unknown {\n if (value === undefined || value === null) {\n return value;\n }\n\n // Unwrap single-element arrays\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n if (value.length === 1) {\n return unwrapToScalar(value[0]);\n }\n throw new BadRequestError(\"Cannot convert multi-value array to scalar\");\n }\n\n // Unwrap objects with value property\n if (typeof value === \"object\") {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return unwrapToScalar(obj.value);\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n return value;\n}\n\n/**\n * Prepare a value for scalar conversion by parsing JSON strings and unwrapping\n */\nfunction prepareForScalarConversion(value: unknown): unknown {\n if (value === undefined || value === null) {\n return value;\n }\n\n // Try to parse JSON strings\n if (typeof value === \"string\") {\n const parsed = tryParseJson(value);\n if (parsed !== value) {\n // Successfully parsed, unwrap the result\n return unwrapToScalar(parsed);\n }\n return value;\n }\n\n // Unwrap arrays and objects\n if (Array.isArray(value) || typeof value === \"object\") {\n return unwrapToScalar(value);\n }\n\n return value;\n}\n\n/**\n * Convert a value to a boolean\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"true\" becomes true\n * - String \"false\" becomes false\n * - Strings that parse to numbers: positive = true, zero or negative = false\n * - Numbers: positive = true, zero or negative = false\n * - Boolean passes through\n */\nexport function fabricBoolean(value: unknown): boolean | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n const lower = prepared.toLowerCase();\n if (lower === \"true\") {\n return true;\n }\n if (lower === \"false\") {\n return false;\n }\n // Try to parse as number\n const num = parseFloat(prepared);\n if (isNaN(num)) {\n throw new BadRequestError(`Cannot convert \"${prepared}\" to Boolean`);\n }\n return num > 0;\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to Boolean\");\n }\n return prepared > 0;\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to Boolean`);\n}\n\n/**\n * Convert a value to a number\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"\" becomes undefined\n * - String \"true\" becomes 1\n * - String \"false\" becomes 0\n * - Strings that parse to numbers use those values\n * - Strings that parse to NaN throw BadRequestError\n * - Boolean true becomes 1, false becomes 0\n * - Number passes through\n */\nexport function fabricNumber(value: unknown): number | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to Number\");\n }\n return prepared;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared ? 1 : 0;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n const lower = prepared.toLowerCase();\n if (lower === \"true\") {\n return 1;\n }\n if (lower === \"false\") {\n return 0;\n }\n const num = parseFloat(prepared);\n if (isNaN(num)) {\n throw new BadRequestError(`Cannot convert \"${prepared}\" to Number`);\n }\n return num;\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to Number`);\n}\n\n/**\n * Convert a value to a string\n * - Arrays, objects, and JSON strings are unwrapped first\n * - String \"\" becomes undefined\n * - Boolean true becomes \"true\", false becomes \"false\"\n * - Number converts to string representation\n * - String passes through\n */\nexport function fabricString(value: unknown): string | undefined {\n // Prepare value by parsing JSON and unwrapping arrays/objects\n const prepared = prepareForScalarConversion(value);\n\n if (prepared === undefined || prepared === null) {\n return undefined;\n }\n\n if (typeof prepared === \"string\") {\n if (prepared === \"\") {\n return undefined;\n }\n return prepared;\n }\n\n if (typeof prepared === \"boolean\") {\n return prepared ? \"true\" : \"false\";\n }\n\n if (typeof prepared === \"number\") {\n if (isNaN(prepared)) {\n throw new BadRequestError(\"Cannot convert NaN to String\");\n }\n return String(prepared);\n }\n\n throw new BadRequestError(`Cannot convert ${typeof prepared} to String`);\n}\n\n/**\n * Convert a value to an array\n * - Non-arrays become arrays containing that value\n * - Arrays of a single value become that value (unwrapped)\n * - Multi-value arrays throw BadRequestError\n * - undefined/null become undefined\n */\nexport function fabricArray(value: unknown): unknown[] | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n // Arrays pass through (single-element unwrapping happens when converting FROM array)\n return value;\n }\n\n // Non-arrays become single-element arrays\n return [value];\n}\n\n/**\n * Resolve a value from an array to a scalar\n * - Single-element arrays become that element\n * - Multi-element arrays throw BadRequestError\n * - Non-arrays pass through\n */\nexport function resolveFromArray(value: unknown): unknown {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return undefined;\n }\n if (value.length === 1) {\n return value[0];\n }\n throw new BadRequestError(\"Cannot convert multi-value array to scalar\");\n }\n\n return value;\n}\n\n/**\n * Convert a value to an object with a value property\n * - Scalars become { value: scalar }\n * - Arrays become { value: array }\n * - Objects with a value attribute pass through\n * - Objects without a value attribute throw BadRequestError\n * - undefined/null become undefined\n */\nexport function fabricObject(value: unknown): { value: unknown } | undefined {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n // Check if already an object (but not an array)\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return obj as { value: unknown };\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n // Scalars and arrays become { value: ... }\n return { value };\n}\n\n/**\n * Resolve a value from an object to its value property\n * - Objects with a value property return that value\n * - Objects without a value throw BadRequestError\n * - Scalars pass through\n */\nexport function resolveFromObject(value: unknown): unknown {\n if (value === undefined || value === null) {\n return undefined;\n }\n\n if (typeof value === \"object\" && !Array.isArray(value)) {\n const obj = value as Record<string, unknown>;\n if (\"value\" in obj) {\n return obj.value;\n }\n throw new BadRequestError(\"Object must have a value attribute\");\n }\n\n return value;\n}\n\n/**\n * Check if a type is a typed array (e.g., [String], [Number], [], etc.)\n */\nfunction isTypedArrayType(type: ConversionType): type is TypedArrayType {\n return Array.isArray(type);\n}\n\n/**\n * Split a string on comma or tab delimiters for typed array conversion.\n * Only splits if the string contains commas or tabs.\n * Returns the original value if not a string or no delimiters found.\n */\nfunction splitStringForArray(value: unknown): unknown {\n if (typeof value !== \"string\") {\n return value;\n }\n\n // Check for comma or tab delimiters\n if (value.includes(\",\")) {\n return value.split(\",\").map((s) => s.trim());\n }\n if (value.includes(\"\\t\")) {\n return value.split(\"\\t\").map((s) => s.trim());\n }\n\n return value;\n}\n\n/**\n * Try to parse a string as JSON for array context.\n * Returns parsed value if it's an array, otherwise returns original.\n */\nfunction tryParseJsonArray(value: unknown): unknown {\n if (typeof value !== \"string\") {\n return value;\n }\n\n const trimmed = value.trim();\n if (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\")) {\n try {\n const parsed = JSON.parse(trimmed);\n if (Array.isArray(parsed)) {\n return parsed;\n }\n } catch {\n // Not valid JSON, fall through\n }\n }\n\n return value;\n}\n\n/**\n * Get the element type from a typed array type\n * Returns undefined for untyped arrays ([])\n */\nfunction getArrayElementType(\n type: TypedArrayType,\n): \"boolean\" | \"number\" | \"object\" | \"string\" | undefined {\n if (type.length === 0) {\n return undefined; // Untyped array\n }\n\n const elementType = type[0];\n\n // Handle constructor types\n if (elementType === Boolean) return \"boolean\";\n if (elementType === Number) return \"number\";\n if (elementType === String) return \"string\";\n if (elementType === Object) return \"object\";\n\n // Handle string types\n if (elementType === \"boolean\") return \"boolean\";\n if (elementType === \"number\") return \"number\";\n if (elementType === \"string\") return \"string\";\n if (elementType === \"object\") return \"object\";\n\n // Handle shorthand types\n if (elementType === \"\") return \"string\"; // \"\" shorthand for String\n if (\n typeof elementType === \"object\" &&\n elementType !== null &&\n Object.keys(elementType).length === 0\n ) {\n return \"object\"; // {} shorthand for Object\n }\n\n throw new BadRequestError(\n `Unknown array element type: ${String(elementType)}`,\n );\n}\n\n/**\n * Convert a value to a typed array\n * - Tries to parse JSON arrays first\n * - Splits strings on comma/tab if present\n * - Wraps non-arrays in an array\n * - Converts each element to the specified element type\n */\nfunction fabricTypedArray(\n value: unknown,\n elementType: \"boolean\" | \"number\" | \"object\" | \"string\" | undefined,\n): unknown[] | undefined {\n // Try to parse JSON array first\n let processed = tryParseJsonArray(value);\n\n // If still a string, try to split on comma/tab\n processed = splitStringForArray(processed);\n\n // Convert to array (wraps non-arrays)\n const array = fabricArray(processed);\n\n if (array === undefined) {\n return undefined;\n }\n\n // If no element type specified, return as-is\n if (elementType === undefined) {\n return array;\n }\n\n // Convert each element to the element type\n return array.map((element, index) => {\n try {\n switch (elementType) {\n case \"boolean\":\n return fabricBoolean(element);\n case \"number\":\n return fabricNumber(element);\n case \"object\":\n return fabricObject(element);\n case \"string\":\n return fabricString(element);\n default:\n throw new BadRequestError(`Unknown element type: ${elementType}`);\n }\n } catch (error) {\n if (error instanceof BadRequestError) {\n throw new BadRequestError(\n `Cannot convert array element at index ${index}: ${error.message}`,\n );\n }\n throw error;\n }\n });\n}\n\n/**\n * Fabric a value to the specified type\n */\nexport function fabric(value: unknown, type: ConversionType): unknown {\n // Check for Date type first\n if (isDateType(type)) {\n return fabricDate(value);\n }\n\n // Check for typed array types\n if (isTypedArrayType(type)) {\n const elementType = getArrayElementType(type);\n return fabricTypedArray(value, elementType);\n }\n\n const normalizedType = normalizeType(type);\n\n switch (normalizedType) {\n case \"array\":\n return fabricArray(value);\n case \"boolean\":\n return fabricBoolean(value);\n case \"number\":\n return fabricNumber(value);\n case \"object\":\n return fabricObject(value);\n case \"string\":\n return fabricString(value);\n default:\n throw new BadRequestError(`Unknown type: ${String(type)}`);\n }\n}\n\n/**\n * Normalize type to string representation\n */\nfunction normalizeType(\n type: ConversionType,\n): \"array\" | \"boolean\" | \"number\" | \"object\" | \"string\" {\n if (type === Array || type === \"array\") {\n return \"array\";\n }\n if (type === Boolean || type === \"boolean\") {\n return \"boolean\";\n }\n if (type === Number || type === \"number\") {\n return \"number\";\n }\n if (type === Object || type === \"object\") {\n return \"object\";\n }\n if (type === String || type === \"string\") {\n return \"string\";\n }\n throw new BadRequestError(`Unknown type: ${String(type)}`);\n}\n","// Service for @jaypie/fabric\n\nimport { BadRequestError } from \"@jaypie/errors\";\n\nimport { FABRIC_VERSION } from \"./constants.js\";\nimport { fabric } from \"./resolve.js\";\nimport type {\n ConversionType,\n InputFieldDefinition,\n Service,\n ServiceConfig,\n ServiceContext,\n ValidateFunction,\n} from \"./types.js\";\n\n/**\n * Check if a single-element array is a typed array type constructor.\n */\nfunction isTypedArrayConstructor(element: unknown): boolean {\n return (\n element === Boolean ||\n element === Number ||\n element === String ||\n element === Object ||\n element === \"boolean\" ||\n element === \"number\" ||\n element === \"string\" ||\n element === \"object\" ||\n element === \"\" ||\n (typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0)\n );\n}\n\n/**\n * Check if a type is a validated string type (array of string literals and/or RegExp).\n * Distinguishes from typed arrays like [String], [Number], etc.\n */\nfunction isValidatedStringType(\n type: ConversionType,\n): type is Array<string | RegExp> {\n if (!Array.isArray(type)) {\n return false;\n }\n\n // Empty array is untyped array, not validated string\n if (type.length === 0) {\n return false;\n }\n\n // Single-element arrays with type constructors are typed arrays\n if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n return false;\n }\n\n // Check that all elements are strings or RegExp\n return type.every(\n (item) => typeof item === \"string\" || item instanceof RegExp,\n );\n}\n\n/**\n * Check if a type is a validated number type (array of number literals).\n * Distinguishes from typed arrays like [Number], etc.\n */\nfunction isValidatedNumberType(type: ConversionType): type is Array<number> {\n if (!Array.isArray(type)) {\n return false;\n }\n\n // Empty array is untyped array, not validated number\n if (type.length === 0) {\n return false;\n }\n\n // Single-element arrays with type constructors are typed arrays\n if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n return false;\n }\n\n // Check that all elements are numbers\n return type.every((item) => typeof item === \"number\");\n}\n\n/**\n * Parse input string as JSON if it's a string\n */\nfunction parseInput(input: unknown): Record<string, unknown> {\n if (input === undefined || input === null) {\n return {};\n }\n\n if (typeof input === \"string\") {\n if (input === \"\") {\n return {};\n }\n try {\n const parsed = JSON.parse(input);\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n Array.isArray(parsed)\n ) {\n throw new BadRequestError(\"Input must be an object\");\n }\n return parsed as Record<string, unknown>;\n } catch (error) {\n if (error instanceof BadRequestError) {\n throw error;\n }\n throw new BadRequestError(\"Invalid JSON input\");\n }\n }\n\n if (typeof input === \"object\" && !Array.isArray(input)) {\n return input as Record<string, unknown>;\n }\n\n throw new BadRequestError(\"Input must be an object or JSON string\");\n}\n\n/**\n * Run validation on a value (supports async validators)\n */\nasync function runValidation(\n value: unknown,\n validate: ValidateFunction | RegExp | Array<unknown>,\n fieldName: string,\n): Promise<void> {\n if (typeof validate === \"function\") {\n const result = await validate(value);\n if (result === false) {\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n } else if (validate instanceof RegExp) {\n if (typeof value !== \"string\" || !validate.test(value)) {\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n } else if (Array.isArray(validate)) {\n // Check if value matches any item in the array\n for (const item of validate) {\n if (item instanceof RegExp) {\n if (typeof value === \"string\" && item.test(value)) {\n return; // Match found\n }\n } else if (typeof item === \"function\") {\n try {\n const result = await (item as ValidateFunction)(value);\n if (result !== false) {\n return; // Match found\n }\n } catch {\n // Continue to next item\n }\n } else if (value === item) {\n return; // Scalar match found\n }\n }\n throw new BadRequestError(`Validation failed for field \"${fieldName}\"`);\n }\n}\n\n/**\n * Check if a field is required\n * A field is required unless it has a default OR required is explicitly false\n */\nfunction isFieldRequired(definition: InputFieldDefinition): boolean {\n if (definition.required === false) {\n return false;\n }\n if (definition.default !== undefined) {\n return false;\n }\n return true;\n}\n\n/**\n * Process a single field through conversion and validation\n */\nasync function processField(\n fieldName: string,\n value: unknown,\n definition: InputFieldDefinition,\n): Promise<unknown> {\n // Apply default if value is undefined\n let processedValue = value;\n if (processedValue === undefined && definition.default !== undefined) {\n processedValue = definition.default;\n }\n\n // Determine actual type and validation\n let actualType: ConversionType = definition.type;\n let validation = definition.validate;\n\n // Handle bare RegExp shorthand: /regex/\n if (definition.type instanceof RegExp) {\n actualType = String;\n validation = definition.type; // The RegExp becomes the validation\n }\n // Handle validated string shorthand: [\"value1\", \"value2\"] or [/regex/]\n else if (isValidatedStringType(definition.type)) {\n actualType = String;\n validation = definition.type; // The array becomes the validation\n }\n // Handle validated number shorthand: [1, 2, 3]\n else if (isValidatedNumberType(definition.type)) {\n actualType = Number;\n validation = definition.type; // The array becomes the validation\n }\n\n // Fabric to target type\n const convertedValue = fabric(processedValue, actualType);\n\n // Check if required field is missing\n if (convertedValue === undefined && isFieldRequired(definition)) {\n throw new BadRequestError(`Missing required field \"${fieldName}\"`);\n }\n\n // Run validation if provided\n if (validation !== undefined && convertedValue !== undefined) {\n await runValidation(convertedValue, validation, fieldName);\n }\n\n return convertedValue;\n}\n\n/**\n * Type guard to check if a value is a pre-instantiated Service\n * A Service is a function with the `$fabric` property set by fabricService\n */\nexport function isService<TInput extends Record<string, unknown>, TOutput>(\n value: unknown,\n): value is Service<TInput, TOutput> {\n return typeof value === \"function\" && \"$fabric\" in value;\n}\n\n/**\n * Fabric a service function\n *\n * Service builds a function that initiates a \"controller\" step that:\n * - Parses the input if it is a string to object\n * - Fabrics each input field to its type\n * - Calls the validation function or regular expression or checks the array\n * - Calls the service function and returns the response\n *\n * The returned function has config properties for introspection.\n */\nexport function fabricService<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n>(config: ServiceConfig<TInput, TOutput>): Service<TInput, TOutput> {\n const { input: inputDefinitions, service } = config;\n\n const handler = async (\n rawInput?: Partial<TInput> | string,\n context?: ServiceContext,\n ): Promise<TOutput> => {\n // Parse input (handles string JSON)\n const parsedInput = parseInput(rawInput);\n\n // If no input definitions, pass through to service or return parsed input\n if (!inputDefinitions) {\n if (service) {\n return service(parsedInput as TInput, context);\n }\n return parsedInput as TOutput;\n }\n\n // Process all fields in parallel\n const entries = Object.entries(inputDefinitions);\n const processedValues = await Promise.all(\n entries.map(([fieldName, definition]) =>\n processField(fieldName, parsedInput[fieldName], definition),\n ),\n );\n\n // Build processed input object\n const processedInput: Record<string, unknown> = {};\n entries.forEach(([fieldName], index) => {\n processedInput[fieldName] = processedValues[index];\n });\n\n // Return processed input if no service, otherwise call service\n if (service) {\n return service(processedInput as TInput, context);\n }\n return processedInput as TOutput;\n };\n\n // Attach config properties directly to handler for flat access\n const typedHandler = handler as Service<TInput, TOutput>;\n typedHandler.$fabric = FABRIC_VERSION;\n if (config.alias !== undefined) typedHandler.alias = config.alias;\n if (config.description !== undefined)\n typedHandler.description = config.description;\n if (config.input !== undefined) typedHandler.input = config.input;\n if (config.service !== undefined) typedHandler.service = config.service;\n\n return typedHandler;\n}\n","// Resolve inline service definitions to full Service objects\n\nimport { fabricService, isService } from \"./service.js\";\nimport type {\n InputFieldDefinition,\n Service,\n ServiceFunction,\n} from \"./types.js\";\n\n/**\n * Configuration for resolving a service\n */\nexport interface ResolveServiceConfig<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n> {\n /** Service alias (used as name for adapters) */\n alias?: string;\n /** Service description */\n description?: string;\n /** Input field definitions */\n input?: Record<string, InputFieldDefinition>;\n /** The service - either a pre-instantiated Service or an inline function */\n service: Service<TInput, TOutput> | ServiceFunction<TInput, TOutput>;\n}\n\n/**\n * Resolve a service configuration to a full Service object\n *\n * Supports two patterns:\n * 1. Inline service definition - pass a plain function as `service` along with\n * `alias`, `description`, and `input` in the config\n * 2. Pre-instantiated Service - pass a Service object as `service`\n *\n * When a pre-instantiated Service is passed, config fields act as overrides:\n * - `alias` overrides service.alias\n * - `description` overrides service.description\n * - `input` overrides service.input\n *\n * The original Service is never mutated - a new Service is created when overrides\n * are applied.\n *\n * @example\n * ```typescript\n * // Inline service definition\n * const service = resolveService({\n * alias: \"greet\",\n * description: \"Greet a user\",\n * input: { name: { type: String } },\n * service: ({ name }) => `Hello, ${name}!`,\n * });\n *\n * // Pre-instantiated with override\n * const baseService = fabricService({ alias: \"foo\", service: (x) => x });\n * const overridden = resolveService({\n * alias: \"bar\", // Override alias\n * service: baseService,\n * });\n * ```\n */\nexport function resolveService<\n TInput extends Record<string, unknown> = Record<string, unknown>,\n TOutput = unknown,\n>(config: ResolveServiceConfig<TInput, TOutput>): Service<TInput, TOutput> {\n const { alias, description, input, service } = config;\n\n if (isService<TInput, TOutput>(service)) {\n // Service is pre-instantiated - config fields act as overrides\n // Create new Service with merged properties (config overrides service)\n return fabricService({\n alias: alias ?? service.alias,\n description: description ?? service.description,\n input: input ?? service.input,\n service: service.service,\n });\n }\n\n // Service is an inline function - create Service from config\n return fabricService({\n alias,\n description,\n input,\n service,\n });\n}\n","// Convert fabric input definitions to Zod schema shape for MCP SDK\n\nimport type { z } from \"zod\";\n\nimport { isDateType } from \"../resolve-date.js\";\nimport type { ConversionType, InputFieldDefinition } from \"../types.js\";\n\n/**\n * Zod schema shape for MCP tool registration\n * This is a record of field names to Zod types\n */\nexport type ZodSchemaShape = Record<string, z.ZodTypeAny>;\n\n/**\n * Check if a single-element array is a typed array type constructor.\n */\nfunction isTypedArrayConstructor(element: unknown): boolean {\n return (\n element === Boolean ||\n element === Number ||\n element === String ||\n element === Object ||\n element === \"boolean\" ||\n element === \"number\" ||\n element === \"string\" ||\n element === \"object\" ||\n element === \"\" ||\n (typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0)\n );\n}\n\n/**\n * Get the array element type for typed arrays\n */\nfunction getTypedArrayElementType(\n type: ConversionType,\n): \"boolean\" | \"number\" | \"object\" | \"string\" | undefined {\n if (!Array.isArray(type) || type.length !== 1) return undefined;\n\n const element = type[0];\n if (element === Boolean || element === \"boolean\") return \"boolean\";\n if (element === Number || element === \"number\") return \"number\";\n if (element === String || element === \"string\" || element === \"\")\n return \"string\";\n if (element === Object || element === \"object\") return \"object\";\n if (\n typeof element === \"object\" &&\n element !== null &&\n !(element instanceof RegExp) &&\n Object.keys(element as Record<string, unknown>).length === 0\n ) {\n return \"object\";\n }\n\n return undefined;\n}\n\n/**\n * Get enum values for validated types\n */\nfunction getEnumValues(type: ConversionType): string[] | undefined {\n if (!Array.isArray(type)) return undefined;\n if (type.length === 0) return undefined;\n if (type.length === 1 && isTypedArrayConstructor(type[0])) return undefined;\n\n // Check if it's a validated string type (strings only, no RegExp)\n if (type.every((item) => typeof item === \"string\")) {\n return type as string[];\n }\n\n return undefined;\n}\n\n/**\n * Check if a field is required\n */\nfunction isFieldRequired(definition: InputFieldDefinition): boolean {\n if (definition.required === false) {\n return false;\n }\n if (definition.default !== undefined) {\n return false;\n }\n return true;\n}\n\n/**\n * Convert a single input field definition to a Zod type\n */\nfunction inputFieldToZod(\n z: typeof import(\"zod\").z,\n definition: InputFieldDefinition,\n): z.ZodTypeAny {\n const { type } = definition;\n\n let zodType: z.ZodTypeAny;\n\n // Handle constructors and primitives\n if (type === Boolean || type === \"boolean\") {\n zodType = z.boolean();\n } else if (type === Number || type === \"number\") {\n zodType = z.number();\n } else if (type === String || type === \"string\") {\n zodType = z.string();\n } else if (type === Object || type === \"object\") {\n zodType = z.record(z.string(), z.unknown());\n } else if (type === Array || type === \"array\") {\n zodType = z.array(z.unknown());\n }\n // Handle Date type (represented as string in schema)\n else if (isDateType(type)) {\n zodType = z.string();\n }\n // Handle RegExp (converts to string)\n else if (type instanceof RegExp) {\n zodType = z.string();\n }\n // Handle arrays\n else if (Array.isArray(type)) {\n // Empty array = untyped array\n if (type.length === 0) {\n zodType = z.array(z.unknown());\n }\n // Single-element typed array like [String], [Number], etc.\n else if (type.length === 1 && isTypedArrayConstructor(type[0])) {\n const elementType = getTypedArrayElementType(type);\n switch (elementType) {\n case \"boolean\":\n zodType = z.array(z.boolean());\n break;\n case \"number\":\n zodType = z.array(z.number());\n break;\n case \"string\":\n zodType = z.array(z.string());\n break;\n case \"object\":\n zodType = z.array(z.record(z.string(), z.unknown()));\n break;\n default:\n zodType = z.array(z.unknown());\n }\n }\n // Validated string type: [\"value1\", \"value2\"]\n else {\n const enumValues = getEnumValues(type);\n if (enumValues && enumValues.length >= 2) {\n zodType = z.enum(enumValues as [string, ...string[]]);\n } else if (enumValues && enumValues.length === 1) {\n zodType = z.literal(enumValues[0]);\n } else {\n // Fallback for other array types (including RegExp arrays)\n zodType = z.string();\n }\n }\n }\n // Default to string\n else {\n zodType = z.string();\n }\n\n // Add description\n if (definition.description) {\n zodType = zodType.describe(definition.description);\n }\n\n // Handle optionality and defaults\n if (!isFieldRequired(definition)) {\n if (definition.default !== undefined) {\n zodType = zodType.optional().default(definition.default);\n } else {\n zodType = zodType.optional();\n }\n }\n\n return zodType;\n}\n\n/**\n * Convert fabric input definitions to a Zod schema shape for MCP SDK\n *\n * @param z - The zod module (passed in to avoid optional dependency import)\n * @param input - The input definitions from the service\n * @returns Zod schema shape object compatible with MCP server.tool()\n */\nexport function inputToZodShape(\n z: typeof import(\"zod\").z,\n input?: Record<string, InputFieldDefinition>,\n): ZodSchemaShape {\n if (!input) {\n return {};\n }\n\n const shape: ZodSchemaShape = {};\n\n // Sort keys alphabetically for consistency\n const sortedKeys = Object.keys(input).sort();\n\n for (const key of sortedKeys) {\n const definition = input[key];\n shape[key] = inputFieldToZod(z, definition);\n }\n\n return shape;\n}\n","// Fabric a service as an MCP tool\n\nimport { z } from \"zod\";\n\nimport { resolveService } from \"../resolveService.js\";\nimport type { Message, ServiceContext } from \"../types.js\";\nimport { inputToZodShape } from \"./inputToZodShape.js\";\nimport type { FabricMcpConfig, FabricMcpResult } from \"./types.js\";\n\n/**\n * Format a value as a string for MCP response\n */\nfunction formatResult(value: unknown): string {\n if (value === undefined || value === null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"object\") {\n return JSON.stringify(value, null, 2);\n }\n return String(value);\n}\n\n/**\n * Fabric a service as an MCP tool\n *\n * This function registers a service with an MCP server.\n * It automatically:\n * - Uses service.alias as the tool name (or custom name)\n * - Uses service.description as the tool description (or custom)\n * - Delegates validation to the service\n * - Wraps the service and formats the response\n *\n * @param config - Configuration including service, server, and optional overrides\n * @returns An object containing the fabricated tool name\n *\n * @example\n * ```typescript\n * import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\n * import { fabricService } from \"@jaypie/fabric\";\n * import { fabricMcp } from \"@jaypie/fabric/mcp\";\n *\n * const myService = fabricService({\n * alias: \"greet\",\n * description: \"Greet a user by name\",\n * input: {\n * userName: { type: String, description: \"The user's name\" },\n * loud: { type: Boolean, default: false, description: \"Shout the greeting\" },\n * },\n * service: ({ userName, loud }) => {\n * const greeting = `Hello, ${userName}!`;\n * return loud ? greeting.toUpperCase() : greeting;\n * },\n * });\n *\n * const server = new McpServer({ name: \"my-server\", version: \"1.0.0\" });\n * fabricMcp({ server, service: myService });\n * ```\n */\nexport function fabricMcp(config: FabricMcpConfig): FabricMcpResult {\n const {\n alias,\n description,\n input,\n name,\n onComplete,\n onError,\n onFatal,\n onMessage,\n server,\n service: serviceOrFunction,\n } = config;\n\n // Resolve inline service or apply overrides to pre-instantiated service\n const service = resolveService({\n alias,\n description,\n input,\n service: serviceOrFunction,\n });\n\n // Determine tool name (priority: name > service.alias > \"tool\")\n const toolName = name ?? service.alias ?? \"tool\";\n\n // Determine tool description\n const toolDescription = service.description ?? \"\";\n\n // Create context callbacks that wrap with error swallowing\n const sendMessage = onMessage\n ? async (msg: Message): Promise<void> => {\n try {\n await onMessage(msg);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnError = onError\n ? async (error: unknown): Promise<void> => {\n try {\n await onError(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnFatal = onFatal\n ? async (error: unknown): Promise<void> => {\n try {\n await onFatal(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n // Create context for the service\n const context: ServiceContext = {\n onError: contextOnError,\n onFatal: contextOnFatal,\n sendMessage,\n };\n\n // Convert input definitions to Zod schema for MCP SDK\n const zodSchema = inputToZodShape(z, service.input);\n\n // Register the tool with the MCP server\n server.tool(toolName, toolDescription, zodSchema, async (args) => {\n try {\n const result = await service(args as Record<string, unknown>, context);\n\n // Call onComplete if provided\n if (onComplete) {\n try {\n await onComplete(result);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n\n return {\n content: [\n {\n text: formatResult(result),\n type: \"text\" as const,\n },\n ],\n };\n } catch (error) {\n // Any thrown error is fatal\n if (onFatal) {\n await onFatal(error);\n } else if (onError) {\n await onError(error);\n }\n throw error;\n }\n });\n\n return { name: toolName };\n}\n","// FabricMcpServer - Standalone MCP server for multi-service tool registration\n\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\n\nimport { isService } from \"../service.js\";\nimport type { Service, ServiceFunction } from \"../types.js\";\nimport { fabricMcp } from \"./fabricMcp.js\";\nimport type {\n FabricMcpServer as FabricMcpServerType,\n FabricMcpServerConfig,\n FabricMcpServerServiceEntry,\n FabricMcpServerToolConfig,\n RegisteredTool,\n} from \"./types.js\";\n\n/**\n * Check if entry is a FabricMcpServerToolConfig (has service property in object form)\n */\nfunction isToolConfig(\n entry: FabricMcpServerServiceEntry,\n): entry is FabricMcpServerToolConfig {\n return (\n typeof entry === \"object\" &&\n entry !== null &&\n \"service\" in entry &&\n !(\"$fabric\" in entry) // Not a Service (which also has service property)\n );\n}\n\n/**\n * Check if entry is a Service (fabricated service with $fabric marker)\n */\nfunction isServiceEntry(entry: FabricMcpServerServiceEntry): entry is Service {\n return isService(entry);\n}\n\n/**\n * Create a standalone MCP server with multi-service tool registration\n *\n * Routes multiple FabricService instances as MCP tools:\n * - Creates an McpServer instance with the given name and version\n * - Registers each service as a tool using fabricMcp\n * - Attaches metadata for introspection\n *\n * @example\n * ```typescript\n * import { FabricMcpServer } from \"@jaypie/fabric/mcp\";\n * import { fabricService } from \"@jaypie/fabric\";\n *\n * const greetService = fabricService({\n * alias: \"greet\",\n * description: \"Greet a user by name\",\n * input: { name: { type: String } },\n * service: ({ name }) => `Hello, ${name}!`,\n * });\n *\n * const echoService = fabricService({\n * alias: \"echo\",\n * description: \"Echo back the input\",\n * input: { message: { type: String } },\n * service: ({ message }) => message,\n * });\n *\n * const server = FabricMcpServer({\n * name: \"my-mcp-server\",\n * version: \"1.0.0\",\n * services: [\n * greetService,\n * echoService,\n * { service: anotherService, name: \"custom-name\" },\n * ],\n * });\n * ```\n */\nexport function FabricMcpServer(\n config: FabricMcpServerConfig,\n): FabricMcpServerType {\n const {\n name,\n onComplete: serverOnComplete,\n onError: serverOnError,\n onFatal: serverOnFatal,\n onMessage: serverOnMessage,\n services,\n version,\n } = config;\n\n // Create the MCP server\n const mcpServer = new McpServer({ name, version });\n\n // Track registered services and tools\n const registeredServices: Service[] = [];\n const registeredTools: RegisteredTool[] = [];\n\n // Register each service as a tool\n for (const entry of services) {\n let service: Service | ServiceFunction<Record<string, unknown>, unknown>;\n let toolName: string | undefined;\n let toolDescription: string | undefined;\n let entryOnComplete = serverOnComplete;\n let entryOnError = serverOnError;\n let entryOnFatal = serverOnFatal;\n let entryOnMessage = serverOnMessage;\n\n if (isToolConfig(entry)) {\n // Tool config with explicit settings\n service = entry.service;\n toolName = entry.name;\n toolDescription = entry.description;\n // Entry-level callbacks override server-level\n entryOnComplete = entry.onComplete ?? serverOnComplete;\n entryOnError = entry.onError ?? serverOnError;\n entryOnFatal = entry.onFatal ?? serverOnFatal;\n entryOnMessage = entry.onMessage ?? serverOnMessage;\n } else if (isServiceEntry(entry)) {\n // Pre-fabricated service\n service = entry;\n } else if (typeof entry === \"function\") {\n // Inline function (will be wrapped by fabricMcp)\n service = entry;\n } else {\n throw new Error(\n \"FabricMcpServer: Each service entry must be a Service, ServiceFunction, or { service: Service }\",\n );\n }\n\n // Register the tool\n const result = fabricMcp({\n description: toolDescription,\n name: toolName,\n onComplete: entryOnComplete,\n onError: entryOnError,\n onFatal: entryOnFatal,\n onMessage: entryOnMessage,\n server: mcpServer,\n service,\n });\n\n // Track the registered service and tool info\n // Note: fabricMcp resolves the service internally, so we track what we can\n if (isServiceEntry(entry)) {\n registeredServices.push(entry);\n registeredTools.push({\n description: toolDescription ?? entry.description ?? \"\",\n name: result.name,\n service: entry,\n });\n } else if (isToolConfig(entry) && isService(entry.service)) {\n registeredServices.push(entry.service);\n registeredTools.push({\n description: toolDescription ?? entry.service.description ?? \"\",\n name: result.name,\n service: entry.service,\n });\n }\n }\n\n // Attach metadata to server\n const server = mcpServer as FabricMcpServerType;\n server.name = name;\n server.services = registeredServices;\n server.tools = registeredTools;\n server.version = version;\n\n return server;\n}\n\n/**\n * Check if a value is a FabricMcpServer\n */\nexport function isFabricMcpServer(\n value: unknown,\n): value is FabricMcpServerType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n value instanceof McpServer &&\n \"services\" in value &&\n Array.isArray((value as FabricMcpServerType).services) &&\n \"tools\" in value &&\n Array.isArray((value as FabricMcpServerType).tools) &&\n \"name\" in value &&\n \"version\" in value\n );\n}\n"],"names":["isTypedArrayConstructor","isFieldR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F;;IAGA,MAAM,MAAM,GAAG,SAAgC;AAC/C,IAAA,MAAM,CAAC,IAAI,GAAG,IAAI;AAClB,IAAA,MAAM,CAAC,QAAQ,GAAG,kBAAkB;AACpC,IAAA,MAAM,CAAC,KAAK,GAAG,eAAe;AAC9B,IAAA,MAAM,CAAC,OAAO,GAAG,OAAO;AAExB,IAAA,OAAO,MAAM;AACf;AAEA;;AAEG;AACG,SAAU,iBAAiB,CAC/B,KAAc,EAAA;AAEd,IAAA,QACE,OAAO,KAAK,KAAK,QAAQ;AACzB,QAAA,KAAK,KAAK,IAAI;AACd,QAAA,KAAK,YAAY,SAAS;AAC1B,QAAA,UAAU,IAAI,KAAK;AACnB,QAAA,KAAK,CAAC,OAAO,CAAE,KAA6B,CAAC,QAAQ,CAAC;AACtD,QAAA,OAAO,IAAI,KAAK;AAChB,QAAA,KAAK,CAAC,OAAO,CAAE,KAA6B,CAAC,KAAK,CAAC;AACnD,QAAA,MAAM,IAAI,KAAK;QACf,SAAS,IAAI,KAAK;AAEtB;;;;"}
|
package/dist/esm/mcp/types.d.ts
CHANGED
|
@@ -58,3 +58,69 @@ export interface McpToolResponse {
|
|
|
58
58
|
export interface FabricMcpResult {
|
|
59
59
|
name: string;
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Service entry for FabricMcpServer - either a raw Service or a tool config
|
|
63
|
+
*/
|
|
64
|
+
export interface FabricMcpServerToolConfig {
|
|
65
|
+
/** Override the service description */
|
|
66
|
+
description?: string;
|
|
67
|
+
/** Override the tool name */
|
|
68
|
+
name?: string;
|
|
69
|
+
/** Callback called when tool completes successfully */
|
|
70
|
+
onComplete?: OnCompleteCallback;
|
|
71
|
+
/** Callback for recoverable errors */
|
|
72
|
+
onError?: OnErrorCallback;
|
|
73
|
+
/** Callback for fatal errors */
|
|
74
|
+
onFatal?: OnFatalCallback;
|
|
75
|
+
/** Callback for receiving messages from service */
|
|
76
|
+
onMessage?: OnMessageCallback;
|
|
77
|
+
/** The service to register as a tool */
|
|
78
|
+
service: Service | ServiceFunction<Record<string, unknown>, unknown>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Service entry type for FabricMcpServer services array
|
|
82
|
+
*/
|
|
83
|
+
export type FabricMcpServerServiceEntry = Service | ServiceFunction<Record<string, unknown>, unknown> | FabricMcpServerToolConfig;
|
|
84
|
+
/**
|
|
85
|
+
* Registered tool information
|
|
86
|
+
*/
|
|
87
|
+
export interface RegisteredTool {
|
|
88
|
+
/** Tool description */
|
|
89
|
+
description: string;
|
|
90
|
+
/** Tool name */
|
|
91
|
+
name: string;
|
|
92
|
+
/** The resolved service */
|
|
93
|
+
service: Service;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configuration for FabricMcpServer
|
|
97
|
+
*/
|
|
98
|
+
export interface FabricMcpServerConfig {
|
|
99
|
+
/** Server name */
|
|
100
|
+
name: string;
|
|
101
|
+
/** Server-level callbacks applied to all tools */
|
|
102
|
+
onComplete?: OnCompleteCallback;
|
|
103
|
+
/** Server-level error callback applied to all tools */
|
|
104
|
+
onError?: OnErrorCallback;
|
|
105
|
+
/** Server-level fatal callback applied to all tools */
|
|
106
|
+
onFatal?: OnFatalCallback;
|
|
107
|
+
/** Server-level message callback applied to all tools */
|
|
108
|
+
onMessage?: OnMessageCallback;
|
|
109
|
+
/** Array of services to register as tools */
|
|
110
|
+
services: FabricMcpServerServiceEntry[];
|
|
111
|
+
/** Server version */
|
|
112
|
+
version: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* FabricMcpServer type - McpServer with attached metadata
|
|
116
|
+
*/
|
|
117
|
+
export interface FabricMcpServer extends McpServer {
|
|
118
|
+
/** Server name */
|
|
119
|
+
name: string;
|
|
120
|
+
/** Array of registered services */
|
|
121
|
+
services: Service[];
|
|
122
|
+
/** Array of registered tool information */
|
|
123
|
+
tools: RegisteredTool[];
|
|
124
|
+
/** Server version */
|
|
125
|
+
version: string;
|
|
126
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { RegisterServiceCommandConfig, RegisterServiceCommandResult } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Register a service as a Commander.js command
|
|
4
|
-
*
|
|
5
|
-
* This function creates a command from a service, automatically:
|
|
6
|
-
* - Creating the command with the handler's alias (or custom name)
|
|
7
|
-
* - Adding a description from the handler's description (or custom)
|
|
8
|
-
* - Converting input definitions to Commander options
|
|
9
|
-
* - Wiring up the action to call the handler with parsed input
|
|
10
|
-
*
|
|
11
|
-
* Error handling:
|
|
12
|
-
* - Services can call context.onError() for recoverable errors
|
|
13
|
-
* - Services can call context.onFatal() for fatal errors
|
|
14
|
-
* - Any error that throws out of the service is treated as fatal
|
|
15
|
-
*
|
|
16
|
-
* @param config - Configuration including handler, program, and optional overrides
|
|
17
|
-
* @returns An object containing the created command
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { Command } from "commander";
|
|
22
|
-
* import { createService } from "@jaypie/fabric";
|
|
23
|
-
* import { registerServiceCommand } from "@jaypie/fabric/commander";
|
|
24
|
-
*
|
|
25
|
-
* const handler = createService({
|
|
26
|
-
* alias: "greet",
|
|
27
|
-
* description: "Greet a user",
|
|
28
|
-
* input: {
|
|
29
|
-
* userName: { type: String, description: "User name" },
|
|
30
|
-
* loud: { type: Boolean, description: "Shout greeting" },
|
|
31
|
-
* },
|
|
32
|
-
* service: ({ userName, loud }) => {
|
|
33
|
-
* const greeting = `Hello, ${userName}!`;
|
|
34
|
-
* return loud ? greeting.toUpperCase() : greeting;
|
|
35
|
-
* },
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* const program = new Command();
|
|
39
|
-
* registerServiceCommand({ handler, program });
|
|
40
|
-
* program.parse();
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare function registerServiceCommand({ description, exclude, handler, name, onComplete, onError, onFatal, onMessage, overrides, program, }: RegisterServiceCommandConfig): RegisterServiceCommandResult;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Date Type Conversion for @jaypie/fabric
|
|
3
|
-
*
|
|
4
|
-
* Adds Date as a supported type in the fabric type system.
|
|
5
|
-
* Follows the same conversion patterns as String, Number, Boolean.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Check if a value is a valid Date
|
|
9
|
-
*/
|
|
10
|
-
export declare function isValidDate(value: unknown): value is Date;
|
|
11
|
-
/**
|
|
12
|
-
* Convert a value to a Date
|
|
13
|
-
*
|
|
14
|
-
* Supported inputs:
|
|
15
|
-
* - Date: returned as-is (validated)
|
|
16
|
-
* - Number: treated as Unix timestamp (milliseconds)
|
|
17
|
-
* - String: parsed via Date constructor (ISO 8601, etc.)
|
|
18
|
-
* - Object with value property: unwrapped and converted
|
|
19
|
-
*
|
|
20
|
-
* @throws BadRequestError if value cannot be converted to valid Date
|
|
21
|
-
*/
|
|
22
|
-
export declare function fabricDate(value: unknown): Date;
|
|
23
|
-
/**
|
|
24
|
-
* Convert a value from a Date to another type
|
|
25
|
-
*
|
|
26
|
-
* @param value - Date to convert
|
|
27
|
-
* @param targetType - Target type (String, Number)
|
|
28
|
-
*/
|
|
29
|
-
export declare function convertFromDate(value: Date, targetType: typeof Number | typeof String): number | string;
|
|
30
|
-
/**
|
|
31
|
-
* Date type constant for use in fabricService input definitions
|
|
32
|
-
*
|
|
33
|
-
* Usage:
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const handler = fabricService({
|
|
36
|
-
* input: {
|
|
37
|
-
* startDate: { type: Date },
|
|
38
|
-
* endDate: { type: Date, default: undefined }
|
|
39
|
-
* }
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare const DateType: DateConstructor;
|
|
44
|
-
/**
|
|
45
|
-
* Type guard for Date type in schema definitions
|
|
46
|
-
*/
|
|
47
|
-
export declare function isDateType(type: unknown): type is typeof Date;
|
package/dist/cjs/convert.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { ConversionType } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Convert a value to a boolean
|
|
4
|
-
* - Arrays, objects, and JSON strings are unwrapped first
|
|
5
|
-
* - String "true" becomes true
|
|
6
|
-
* - String "false" becomes false
|
|
7
|
-
* - Strings that parse to numbers: positive = true, zero or negative = false
|
|
8
|
-
* - Numbers: positive = true, zero or negative = false
|
|
9
|
-
* - Boolean passes through
|
|
10
|
-
*/
|
|
11
|
-
export declare function fabricBoolean(value: unknown): boolean | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* Convert a value to a number
|
|
14
|
-
* - Arrays, objects, and JSON strings are unwrapped first
|
|
15
|
-
* - String "" becomes undefined
|
|
16
|
-
* - String "true" becomes 1
|
|
17
|
-
* - String "false" becomes 0
|
|
18
|
-
* - Strings that parse to numbers use those values
|
|
19
|
-
* - Strings that parse to NaN throw BadRequestError
|
|
20
|
-
* - Boolean true becomes 1, false becomes 0
|
|
21
|
-
* - Number passes through
|
|
22
|
-
*/
|
|
23
|
-
export declare function fabricNumber(value: unknown): number | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Convert a value to a string
|
|
26
|
-
* - Arrays, objects, and JSON strings are unwrapped first
|
|
27
|
-
* - String "" becomes undefined
|
|
28
|
-
* - Boolean true becomes "true", false becomes "false"
|
|
29
|
-
* - Number converts to string representation
|
|
30
|
-
* - String passes through
|
|
31
|
-
*/
|
|
32
|
-
export declare function fabricString(value: unknown): string | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Convert a value to an array
|
|
35
|
-
* - Non-arrays become arrays containing that value
|
|
36
|
-
* - Arrays of a single value become that value (unwrapped)
|
|
37
|
-
* - Multi-value arrays throw BadRequestError
|
|
38
|
-
* - undefined/null become undefined
|
|
39
|
-
*/
|
|
40
|
-
export declare function fabricArray(value: unknown): unknown[] | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* Convert a value from an array to a scalar
|
|
43
|
-
* - Single-element arrays become that element
|
|
44
|
-
* - Multi-element arrays throw BadRequestError
|
|
45
|
-
* - Non-arrays pass through
|
|
46
|
-
*/
|
|
47
|
-
export declare function convertFromArray(value: unknown): unknown;
|
|
48
|
-
/**
|
|
49
|
-
* Convert a value to an object with a value property
|
|
50
|
-
* - Scalars become { value: scalar }
|
|
51
|
-
* - Arrays become { value: array }
|
|
52
|
-
* - Objects with a value attribute pass through
|
|
53
|
-
* - Objects without a value attribute throw BadRequestError
|
|
54
|
-
* - undefined/null become undefined
|
|
55
|
-
*/
|
|
56
|
-
export declare function fabricObject(value: unknown): {
|
|
57
|
-
value: unknown;
|
|
58
|
-
} | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Convert a value from an object to its value property
|
|
61
|
-
* - Objects with a value property return that value
|
|
62
|
-
* - Objects without a value throw BadRequestError
|
|
63
|
-
* - Scalars pass through
|
|
64
|
-
*/
|
|
65
|
-
export declare function convertFromObject(value: unknown): unknown;
|
|
66
|
-
/**
|
|
67
|
-
* Fabric a value to the specified type
|
|
68
|
-
*/
|
|
69
|
-
export declare function fabric(value: unknown, type: ConversionType): unknown;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Service } from "../types.js";
|
|
2
|
-
import type { CreateLambdaServiceConfig, CreateLambdaServiceOptions, CreateLambdaServiceResult } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Create a Lambda handler that wraps a service
|
|
5
|
-
*
|
|
6
|
-
* This function creates a Lambda-compatible handler that:
|
|
7
|
-
* - Uses getMessages() to extract messages from SQS/SNS events
|
|
8
|
-
* - Calls the service once for each message
|
|
9
|
-
* - Returns the single response if one message, or an array of responses if multiple
|
|
10
|
-
* - Integrates with lambdaHandler for lifecycle management (secrets, setup, teardown, etc.)
|
|
11
|
-
*
|
|
12
|
-
* @param handlerOrConfig - The service function or configuration object
|
|
13
|
-
* @param options - Lambda handler options (secrets, setup, teardown, etc.)
|
|
14
|
-
* @returns A Lambda handler function
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { createLambdaService } from "@jaypie/fabric/lambda";
|
|
19
|
-
* import { myService } from "./services";
|
|
20
|
-
*
|
|
21
|
-
* // Config object style
|
|
22
|
-
* export const handler = createLambdaService({
|
|
23
|
-
* handler: myService,
|
|
24
|
-
* secrets: ["ANTHROPIC_API_KEY", "OPENAI_API_KEY"],
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* // Handler with options style
|
|
28
|
-
* export const handler2 = createLambdaService(myService, {
|
|
29
|
-
* secrets: ["ANTHROPIC_API_KEY"],
|
|
30
|
-
* });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export declare function createLambdaService<TResult = unknown>(handlerOrConfig: CreateLambdaServiceConfig | Service, options?: CreateLambdaServiceOptions): CreateLambdaServiceResult<TResult | TResult[]>;
|