@jaypie/fabric 0.1.2 → 0.1.4

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.
@@ -681,6 +681,13 @@ async function processField(fieldName, value, definition) {
681
681
  }
682
682
  return convertedValue;
683
683
  }
684
+ /**
685
+ * Type guard to check if a value is a pre-instantiated Service
686
+ * A Service is a function with the `$fabric` property set by fabricService
687
+ */
688
+ function isService$1(value) {
689
+ return typeof value === "function" && "$fabric" in value;
690
+ }
684
691
  /**
685
692
  * Fabric a service function
686
693
  *
@@ -733,13 +740,6 @@ function fabricService(config) {
733
740
  }
734
741
 
735
742
  // Resolve inline service definitions to full Service objects
736
- /**
737
- * Type guard to check if a value is a pre-instantiated Service
738
- * A Service is a function with the `$fabric` property set by fabricService
739
- */
740
- function isService$1(value) {
741
- return typeof value === "function" && "$fabric" in value;
742
- }
743
743
  /**
744
744
  * Resolve a service configuration to a full Service object
745
745
  *
@@ -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/lambda/fabricLambda.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","// Lambda Service adapter for @jaypie/fabric\n\nimport { getMessages } from \"@jaypie/aws\";\nimport { lambdaHandler } from \"@jaypie/lambda\";\n\nimport { resolveService } from \"../resolveService.js\";\nimport type {\n Message,\n Service,\n ServiceContext,\n ServiceFunction,\n} from \"../types.js\";\nimport type {\n FabricLambdaConfig,\n FabricLambdaOptions,\n FabricLambdaResult,\n LambdaContext,\n} from \"./types.js\";\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(value: unknown): value is Service {\n return typeof value === \"function\" && \"$fabric\" in value;\n}\n\n/**\n * Type guard to check if a value is a config object (has service property)\n */\nfunction isConfig(value: unknown): value is FabricLambdaConfig {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"service\" in value &&\n typeof (value as FabricLambdaConfig).service === \"function\"\n );\n}\n\n/**\n * Fabric a Lambda handler that wraps a service\n *\n * This function creates a Lambda-compatible handler that:\n * - Uses getMessages() to extract messages from SQS/SNS events\n * - Calls the service once for each message\n * - Returns the single response if one message, or an array of responses if multiple\n * - Integrates with lambdaHandler for lifecycle management (secrets, setup, teardown, etc.)\n *\n * @param serviceOrConfig - The service function or configuration object\n * @param options - Lambda handler options (secrets, setup, teardown, etc.)\n * @returns A Lambda handler function\n *\n * @example\n * ```typescript\n * import { fabricLambda } from \"@jaypie/fabric/lambda\";\n * import { myService } from \"./services\";\n *\n * // Direct service style\n * export const handler = fabricLambda(myService);\n *\n * // Config object style\n * export const handler2 = fabricLambda({\n * service: myService,\n * secrets: [\"ANTHROPIC_API_KEY\", \"OPENAI_API_KEY\"],\n * });\n *\n * // Service with options style\n * export const handler3 = fabricLambda(myService, {\n * secrets: [\"ANTHROPIC_API_KEY\"],\n * });\n * ```\n */\nexport function fabricLambda<TResult = unknown>(\n serviceOrConfig:\n | FabricLambdaConfig\n | Service\n | ServiceFunction<Record<string, unknown>, unknown>,\n options: FabricLambdaOptions = {},\n): FabricLambdaResult<TResult | TResult[]> {\n // Normalize arguments and resolve service\n let service: Service;\n let opts: FabricLambdaOptions;\n\n if (isConfig(serviceOrConfig)) {\n // Config object with service property\n const {\n alias,\n description,\n input,\n service: configService,\n ...configOpts\n } = serviceOrConfig;\n // Resolve inline service or apply overrides\n service = resolveService({\n alias,\n description,\n input,\n service: configService,\n });\n opts = configOpts;\n } else if (isService(serviceOrConfig)) {\n // Pre-instantiated Service passed directly\n service = serviceOrConfig;\n opts = options;\n } else {\n // Plain function passed directly - wrap it\n service = resolveService({ service: serviceOrConfig });\n opts = options;\n }\n\n // Use service.alias as the name for logging (can be overridden via options.name)\n const name = opts.name ?? service.alias;\n\n // Create context callbacks that wrap the registration callbacks with error swallowing\n // Callback failures should never halt service execution\n const sendMessage = opts.onMessage\n ? async (message: Message): Promise<void> => {\n try {\n await opts.onMessage!(message);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnError = opts.onError\n ? async (error: unknown): Promise<void> => {\n try {\n await opts.onError!(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnFatal = opts.onFatal\n ? async (error: unknown): Promise<void> => {\n try {\n await opts.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 // Create the inner Lambda handler logic (context param required for lambdaHandler signature)\n const innerHandler = async (\n event: unknown,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _context?: LambdaContext,\n ): Promise<TResult | TResult[]> => {\n // Extract messages from SQS/SNS event wrapper\n const messages = getMessages(event);\n\n // Process each message through the service\n const results: TResult[] = [];\n for (const message of messages) {\n try {\n const result = await service(\n message as Record<string, unknown>,\n context,\n );\n results.push(result as TResult);\n } catch (error) {\n // Any thrown error is fatal - call onFatal or onError as fallback\n if (opts.onFatal) {\n await opts.onFatal(error);\n } else if (opts.onError) {\n await opts.onError(error);\n }\n // Re-throw to let lambdaHandler handle it\n throw error;\n }\n }\n\n // Call onComplete if provided\n const response = results.length === 1 ? results[0] : results;\n if (opts.onComplete) {\n try {\n await opts.onComplete(response);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n\n return response;\n };\n\n // Wrap with lambdaHandler for lifecycle management\n return lambdaHandler(innerHandler, {\n chaos: opts.chaos,\n name,\n secrets: opts.secrets,\n setup: opts.setup,\n teardown: opts.teardown,\n throw: opts.throw,\n unavailable: opts.unavailable,\n validate: opts.validate,\n });\n}\n"],"names":["isService"],"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,OA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AC,OAAO,CAAC,KAAK,CAAC;gBAC3B;AAAO,qBAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AACvB,oBAAA,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBAC3B;;AAEA,gBAAA,MAAM,KAAK;YACb;QACF;;AAGA,QAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO;AAC5D,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;AACnB,YAAA,IAAI;AACF,gBAAA,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjC;AAAE,YAAA,MAAM;;YAER;QACF;AAEA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;;IAGD,OAAO,aAAa,CAAC,YAAY,EAAE;QACjC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI;QACJ,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;AACxB,KAAA,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../../src/constants.ts","../../../../../src/resolve-date.ts","../../../../../src/resolve.ts","../../../../../src/service.ts","../../../../../src/resolveService.ts","../../../../../src/lambda/fabricLambda.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","// Lambda Service adapter for @jaypie/fabric\n\nimport { getMessages } from \"@jaypie/aws\";\nimport { lambdaHandler } from \"@jaypie/lambda\";\n\nimport { resolveService } from \"../resolveService.js\";\nimport type {\n Message,\n Service,\n ServiceContext,\n ServiceFunction,\n} from \"../types.js\";\nimport type {\n FabricLambdaConfig,\n FabricLambdaOptions,\n FabricLambdaResult,\n LambdaContext,\n} from \"./types.js\";\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(value: unknown): value is Service {\n return typeof value === \"function\" && \"$fabric\" in value;\n}\n\n/**\n * Type guard to check if a value is a config object (has service property)\n */\nfunction isConfig(value: unknown): value is FabricLambdaConfig {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"service\" in value &&\n typeof (value as FabricLambdaConfig).service === \"function\"\n );\n}\n\n/**\n * Fabric a Lambda handler that wraps a service\n *\n * This function creates a Lambda-compatible handler that:\n * - Uses getMessages() to extract messages from SQS/SNS events\n * - Calls the service once for each message\n * - Returns the single response if one message, or an array of responses if multiple\n * - Integrates with lambdaHandler for lifecycle management (secrets, setup, teardown, etc.)\n *\n * @param serviceOrConfig - The service function or configuration object\n * @param options - Lambda handler options (secrets, setup, teardown, etc.)\n * @returns A Lambda handler function\n *\n * @example\n * ```typescript\n * import { fabricLambda } from \"@jaypie/fabric/lambda\";\n * import { myService } from \"./services\";\n *\n * // Direct service style\n * export const handler = fabricLambda(myService);\n *\n * // Config object style\n * export const handler2 = fabricLambda({\n * service: myService,\n * secrets: [\"ANTHROPIC_API_KEY\", \"OPENAI_API_KEY\"],\n * });\n *\n * // Service with options style\n * export const handler3 = fabricLambda(myService, {\n * secrets: [\"ANTHROPIC_API_KEY\"],\n * });\n * ```\n */\nexport function fabricLambda<TResult = unknown>(\n serviceOrConfig:\n | FabricLambdaConfig\n | Service\n | ServiceFunction<Record<string, unknown>, unknown>,\n options: FabricLambdaOptions = {},\n): FabricLambdaResult<TResult | TResult[]> {\n // Normalize arguments and resolve service\n let service: Service;\n let opts: FabricLambdaOptions;\n\n if (isConfig(serviceOrConfig)) {\n // Config object with service property\n const {\n alias,\n description,\n input,\n service: configService,\n ...configOpts\n } = serviceOrConfig;\n // Resolve inline service or apply overrides\n service = resolveService({\n alias,\n description,\n input,\n service: configService,\n });\n opts = configOpts;\n } else if (isService(serviceOrConfig)) {\n // Pre-instantiated Service passed directly\n service = serviceOrConfig;\n opts = options;\n } else {\n // Plain function passed directly - wrap it\n service = resolveService({ service: serviceOrConfig });\n opts = options;\n }\n\n // Use service.alias as the name for logging (can be overridden via options.name)\n const name = opts.name ?? service.alias;\n\n // Create context callbacks that wrap the registration callbacks with error swallowing\n // Callback failures should never halt service execution\n const sendMessage = opts.onMessage\n ? async (message: Message): Promise<void> => {\n try {\n await opts.onMessage!(message);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnError = opts.onError\n ? async (error: unknown): Promise<void> => {\n try {\n await opts.onError!(error);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n : undefined;\n\n const contextOnFatal = opts.onFatal\n ? async (error: unknown): Promise<void> => {\n try {\n await opts.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 // Create the inner Lambda handler logic (context param required for lambdaHandler signature)\n const innerHandler = async (\n event: unknown,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _context?: LambdaContext,\n ): Promise<TResult | TResult[]> => {\n // Extract messages from SQS/SNS event wrapper\n const messages = getMessages(event);\n\n // Process each message through the service\n const results: TResult[] = [];\n for (const message of messages) {\n try {\n const result = await service(\n message as Record<string, unknown>,\n context,\n );\n results.push(result as TResult);\n } catch (error) {\n // Any thrown error is fatal - call onFatal or onError as fallback\n if (opts.onFatal) {\n await opts.onFatal(error);\n } else if (opts.onError) {\n await opts.onError(error);\n }\n // Re-throw to let lambdaHandler handle it\n throw error;\n }\n }\n\n // Call onComplete if provided\n const response = results.length === 1 ? results[0] : results;\n if (opts.onComplete) {\n try {\n await opts.onComplete(response);\n } catch {\n // Swallow errors - callback failures should not halt execution\n }\n }\n\n return response;\n };\n\n // Wrap with lambdaHandler for lifecycle management\n return lambdaHandler(innerHandler, {\n chaos: opts.chaos,\n name,\n secrets: opts.secrets,\n setup: opts.setup,\n teardown: opts.teardown,\n throw: opts.throw,\n unavailable: opts.unavailable,\n validate: opts.validate,\n });\n}\n"],"names":["isService"],"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,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MAAM,OAAO,CAC1B,OAAkC,EAClC,OAAO,CACR;AACD,gBAAA,OAAO,CAAC,IAAI,CAAC,MAAiB,CAAC;YACjC;YAAE,OAAO,KAAK,EAAE;;AAEd,gBAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AAChB,oBAAA,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBAC3B;AAAO,qBAAA,IAAI,IAAI,CAAC,OAAO,EAAE;AACvB,oBAAA,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBAC3B;;AAEA,gBAAA,MAAM,KAAK;YACb;QACF;;AAGA,QAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO;AAC5D,QAAA,IAAI,IAAI,CAAC,UAAU,EAAE;AACnB,YAAA,IAAI;AACF,gBAAA,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;YACjC;AAAE,YAAA,MAAM;;YAER;QACF;AAEA,QAAA,OAAO,QAAQ;AACjB,IAAA,CAAC;;IAGD,OAAO,aAAa,CAAC,YAAY,EAAE;QACjC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,IAAI;QACJ,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;AACxB,KAAA,CAAC;AACJ;;;;"}
@@ -679,6 +679,13 @@ async function processField(fieldName, value, definition) {
679
679
  }
680
680
  return convertedValue;
681
681
  }
682
+ /**
683
+ * Type guard to check if a value is a pre-instantiated Service
684
+ * A Service is a function with the `$fabric` property set by fabricService
685
+ */
686
+ function isService(value) {
687
+ return typeof value === "function" && "$fabric" in value;
688
+ }
682
689
  /**
683
690
  * Fabric a service function
684
691
  *
@@ -731,13 +738,6 @@ function fabricService(config) {
731
738
  }
732
739
 
733
740
  // Resolve inline service definitions to full Service objects
734
- /**
735
- * Type guard to check if a value is a pre-instantiated Service
736
- * A Service is a function with the `$fabric` property set by fabricService
737
- */
738
- function isService(value) {
739
- return typeof value === "function" && "$fabric" in value;
740
- }
741
741
  /**
742
742
  * Resolve a service configuration to a full Service object
743
743
  *