@jaypie/fabric 0.2.0 → 0.2.2
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 +3 -1
- package/dist/cjs/commander/index.cjs +42 -11
- package/dist/cjs/commander/index.cjs.map +1 -1
- package/dist/cjs/data/index.cjs +40 -11
- package/dist/cjs/data/index.cjs.map +1 -1
- package/dist/cjs/http/index.cjs +43 -13
- package/dist/cjs/http/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +50 -21
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/lambda/index.cjs +42 -11
- package/dist/cjs/lambda/index.cjs.map +1 -1
- package/dist/cjs/llm/index.cjs +42 -11
- package/dist/cjs/llm/index.cjs.map +1 -1
- package/dist/cjs/mcp/FabricMcpServer.d.ts +1 -1
- package/dist/cjs/mcp/index.cjs +43 -12
- package/dist/cjs/mcp/index.cjs.map +1 -1
- package/dist/cjs/models/base.d.ts +6 -6
- package/dist/cjs/resolveService.d.ts +7 -4
- package/dist/cjs/service.d.ts +6 -4
- package/dist/cjs/types.d.ts +9 -3
- package/dist/cjs/websocket/fabricWebSocket.d.ts +120 -0
- package/dist/cjs/websocket/index.d.ts +2 -0
- package/dist/esm/ServiceSuite.d.ts +3 -1
- package/dist/esm/commander/index.js +42 -11
- package/dist/esm/commander/index.js.map +1 -1
- package/dist/esm/data/index.js +40 -11
- package/dist/esm/data/index.js.map +1 -1
- package/dist/esm/http/index.js +43 -13
- package/dist/esm/http/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +50 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lambda/index.js +42 -11
- package/dist/esm/lambda/index.js.map +1 -1
- package/dist/esm/llm/index.js +42 -11
- package/dist/esm/llm/index.js.map +1 -1
- package/dist/esm/mcp/FabricMcpServer.d.ts +1 -1
- package/dist/esm/mcp/index.js +43 -12
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/models/base.d.ts +6 -6
- package/dist/esm/resolveService.d.ts +7 -4
- package/dist/esm/service.d.ts +6 -4
- package/dist/esm/types.d.ts +9 -3
- package/dist/esm/websocket/fabricWebSocket.d.ts +120 -0
- package/dist/esm/websocket/index.d.ts +2 -0
- package/package.json +6 -1
package/dist/esm/http/index.js
CHANGED
|
@@ -679,42 +679,68 @@ async function processField(fieldName, value, definition) {
|
|
|
679
679
|
}
|
|
680
680
|
return convertedValue;
|
|
681
681
|
}
|
|
682
|
+
/**
|
|
683
|
+
* Run serializer hook if provided
|
|
684
|
+
* Returns transformed output or original if serializer returns undefined/null/void
|
|
685
|
+
*/
|
|
686
|
+
async function runSerializer(data, serializer, context) {
|
|
687
|
+
if (!serializer) {
|
|
688
|
+
return data.output;
|
|
689
|
+
}
|
|
690
|
+
const result = await serializer(data, context);
|
|
691
|
+
if (result !== undefined && result !== null) {
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
return data.output;
|
|
695
|
+
}
|
|
682
696
|
/**
|
|
683
697
|
* Fabric a service function
|
|
684
698
|
*
|
|
685
|
-
* Service builds a function that
|
|
699
|
+
* Service builds a function that:
|
|
686
700
|
* - Parses the input if it is a string to object
|
|
687
701
|
* - Fabrics each input field to its type
|
|
688
702
|
* - Calls the validation function or regular expression or checks the array
|
|
689
|
-
* - Calls the service function
|
|
703
|
+
* - Calls the service function
|
|
704
|
+
* - Calls the serializer hook (can transform output)
|
|
705
|
+
* - Returns the response
|
|
690
706
|
*
|
|
691
707
|
* The returned function has config properties for introspection.
|
|
692
708
|
*/
|
|
693
709
|
function fabricService(config) {
|
|
694
|
-
const { input: inputDefinitions, service } = config;
|
|
710
|
+
const { input: inputDefinitions, serializer, service } = config;
|
|
695
711
|
const handler = async (rawInput, context) => {
|
|
696
712
|
// Parse input (handles string JSON)
|
|
697
713
|
const parsedInput = parseInput(rawInput);
|
|
698
714
|
// If no input definitions, pass through to service or return parsed input
|
|
699
715
|
if (!inputDefinitions) {
|
|
716
|
+
let output;
|
|
700
717
|
if (service) {
|
|
701
|
-
|
|
718
|
+
output = await service(parsedInput, context);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
output = parsedInput;
|
|
702
722
|
}
|
|
703
|
-
|
|
723
|
+
// Run serializer
|
|
724
|
+
return (await runSerializer({ input: parsedInput, output }, serializer, context));
|
|
704
725
|
}
|
|
705
726
|
// Process all fields in parallel
|
|
706
727
|
const entries = Object.entries(inputDefinitions);
|
|
707
728
|
const processedValues = await Promise.all(entries.map(([fieldName, definition]) => processField(fieldName, parsedInput[fieldName], definition)));
|
|
708
729
|
// Build processed input object
|
|
709
|
-
const
|
|
730
|
+
const processedInputObj = {};
|
|
710
731
|
entries.forEach(([fieldName], index) => {
|
|
711
|
-
|
|
732
|
+
processedInputObj[fieldName] = processedValues[index];
|
|
712
733
|
});
|
|
713
|
-
//
|
|
734
|
+
// Call service or return processed input
|
|
735
|
+
let output;
|
|
714
736
|
if (service) {
|
|
715
|
-
|
|
737
|
+
output = await service(processedInputObj, context);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
output = processedInputObj;
|
|
716
741
|
}
|
|
717
|
-
|
|
742
|
+
// Run serializer hook
|
|
743
|
+
return (await runSerializer({ input: processedInputObj, output }, serializer, context));
|
|
718
744
|
};
|
|
719
745
|
// Attach config properties directly to handler for flat access
|
|
720
746
|
const typedHandler = handler;
|
|
@@ -725,6 +751,8 @@ function fabricService(config) {
|
|
|
725
751
|
typedHandler.description = config.description;
|
|
726
752
|
if (config.input !== undefined)
|
|
727
753
|
typedHandler.input = config.input;
|
|
754
|
+
if (config.serializer !== undefined)
|
|
755
|
+
typedHandler.serializer = config.serializer;
|
|
728
756
|
if (config.service !== undefined)
|
|
729
757
|
typedHandler.service = config.service;
|
|
730
758
|
return typedHandler;
|
|
@@ -1142,7 +1170,8 @@ var HttpStreamEventType;
|
|
|
1142
1170
|
* Check if event is API Gateway v2 format
|
|
1143
1171
|
*/
|
|
1144
1172
|
function isApiGatewayV2Event(event) {
|
|
1145
|
-
return "requestContext" in event &&
|
|
1173
|
+
return ("requestContext" in event &&
|
|
1174
|
+
"http" in event.requestContext);
|
|
1146
1175
|
}
|
|
1147
1176
|
/**
|
|
1148
1177
|
* Check if entry is a FabricHttpServerRoute (has service property)
|
|
@@ -1192,7 +1221,8 @@ function matchRoute(requestPath, route) {
|
|
|
1192
1221
|
const requestSegments = requestPath.split("/").filter(Boolean);
|
|
1193
1222
|
const routeSegments = route.segments;
|
|
1194
1223
|
// Check segment count (allow route to have optional params)
|
|
1195
|
-
if (requestSegments.length <
|
|
1224
|
+
if (requestSegments.length <
|
|
1225
|
+
routeSegments.filter((s) => !s.endsWith("?")).length) {
|
|
1196
1226
|
return undefined;
|
|
1197
1227
|
}
|
|
1198
1228
|
if (requestSegments.length > routeSegments.length) {
|
|
@@ -1348,7 +1378,7 @@ function FabricHttpServer(config) {
|
|
|
1348
1378
|
*/
|
|
1349
1379
|
const handler = async (event) => {
|
|
1350
1380
|
// Extract request data from API Gateway event
|
|
1351
|
-
const { body, headers, method, path: requestPath, queryString, pathParams } = extractRequestData(event);
|
|
1381
|
+
const { body, headers, method, path: requestPath, queryString, pathParams, } = extractRequestData(event);
|
|
1352
1382
|
// Normalize headers to Headers object for consistency
|
|
1353
1383
|
const headersObj = new Headers(headers);
|
|
1354
1384
|
const origin = headersObj.get("origin");
|