@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.
Files changed (47) hide show
  1. package/dist/cjs/ServiceSuite.d.ts +3 -1
  2. package/dist/cjs/commander/index.cjs +42 -11
  3. package/dist/cjs/commander/index.cjs.map +1 -1
  4. package/dist/cjs/data/index.cjs +40 -11
  5. package/dist/cjs/data/index.cjs.map +1 -1
  6. package/dist/cjs/http/index.cjs +43 -13
  7. package/dist/cjs/http/index.cjs.map +1 -1
  8. package/dist/cjs/index.cjs +50 -21
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/index.d.ts +1 -1
  11. package/dist/cjs/lambda/index.cjs +42 -11
  12. package/dist/cjs/lambda/index.cjs.map +1 -1
  13. package/dist/cjs/llm/index.cjs +42 -11
  14. package/dist/cjs/llm/index.cjs.map +1 -1
  15. package/dist/cjs/mcp/FabricMcpServer.d.ts +1 -1
  16. package/dist/cjs/mcp/index.cjs +43 -12
  17. package/dist/cjs/mcp/index.cjs.map +1 -1
  18. package/dist/cjs/models/base.d.ts +6 -6
  19. package/dist/cjs/resolveService.d.ts +7 -4
  20. package/dist/cjs/service.d.ts +6 -4
  21. package/dist/cjs/types.d.ts +9 -3
  22. package/dist/cjs/websocket/fabricWebSocket.d.ts +120 -0
  23. package/dist/cjs/websocket/index.d.ts +2 -0
  24. package/dist/esm/ServiceSuite.d.ts +3 -1
  25. package/dist/esm/commander/index.js +42 -11
  26. package/dist/esm/commander/index.js.map +1 -1
  27. package/dist/esm/data/index.js +40 -11
  28. package/dist/esm/data/index.js.map +1 -1
  29. package/dist/esm/http/index.js +43 -13
  30. package/dist/esm/http/index.js.map +1 -1
  31. package/dist/esm/index.d.ts +1 -1
  32. package/dist/esm/index.js +50 -21
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/lambda/index.js +42 -11
  35. package/dist/esm/lambda/index.js.map +1 -1
  36. package/dist/esm/llm/index.js +42 -11
  37. package/dist/esm/llm/index.js.map +1 -1
  38. package/dist/esm/mcp/FabricMcpServer.d.ts +1 -1
  39. package/dist/esm/mcp/index.js +43 -12
  40. package/dist/esm/mcp/index.js.map +1 -1
  41. package/dist/esm/models/base.d.ts +6 -6
  42. package/dist/esm/resolveService.d.ts +7 -4
  43. package/dist/esm/service.d.ts +6 -4
  44. package/dist/esm/types.d.ts +9 -3
  45. package/dist/esm/websocket/fabricWebSocket.d.ts +120 -0
  46. package/dist/esm/websocket/index.d.ts +2 -0
  47. package/package.json +6 -1
@@ -870,42 +870,68 @@ async function processField(fieldName, value, definition) {
870
870
  }
871
871
  return convertedValue;
872
872
  }
873
+ /**
874
+ * Run serializer hook if provided
875
+ * Returns transformed output or original if serializer returns undefined/null/void
876
+ */
877
+ async function runSerializer(data, serializer, context) {
878
+ if (!serializer) {
879
+ return data.output;
880
+ }
881
+ const result = await serializer(data, context);
882
+ if (result !== undefined && result !== null) {
883
+ return result;
884
+ }
885
+ return data.output;
886
+ }
873
887
  /**
874
888
  * Fabric a service function
875
889
  *
876
- * Service builds a function that initiates a "controller" step that:
890
+ * Service builds a function that:
877
891
  * - Parses the input if it is a string to object
878
892
  * - Fabrics each input field to its type
879
893
  * - Calls the validation function or regular expression or checks the array
880
- * - Calls the service function and returns the response
894
+ * - Calls the service function
895
+ * - Calls the serializer hook (can transform output)
896
+ * - Returns the response
881
897
  *
882
898
  * The returned function has config properties for introspection.
883
899
  */
884
900
  function fabricService(config) {
885
- const { input: inputDefinitions, service } = config;
901
+ const { input: inputDefinitions, serializer, service } = config;
886
902
  const handler = async (rawInput, context) => {
887
903
  // Parse input (handles string JSON)
888
904
  const parsedInput = parseInput(rawInput);
889
905
  // If no input definitions, pass through to service or return parsed input
890
906
  if (!inputDefinitions) {
907
+ let output;
891
908
  if (service) {
892
- return service(parsedInput, context);
909
+ output = await service(parsedInput, context);
910
+ }
911
+ else {
912
+ output = parsedInput;
893
913
  }
894
- return parsedInput;
914
+ // Run serializer
915
+ return (await runSerializer({ input: parsedInput, output }, serializer, context));
895
916
  }
896
917
  // Process all fields in parallel
897
918
  const entries = Object.entries(inputDefinitions);
898
919
  const processedValues = await Promise.all(entries.map(([fieldName, definition]) => processField(fieldName, parsedInput[fieldName], definition)));
899
920
  // Build processed input object
900
- const processedInput = {};
921
+ const processedInputObj = {};
901
922
  entries.forEach(([fieldName], index) => {
902
- processedInput[fieldName] = processedValues[index];
923
+ processedInputObj[fieldName] = processedValues[index];
903
924
  });
904
- // Return processed input if no service, otherwise call service
925
+ // Call service or return processed input
926
+ let output;
905
927
  if (service) {
906
- return service(processedInput, context);
928
+ output = await service(processedInputObj, context);
929
+ }
930
+ else {
931
+ output = processedInputObj;
907
932
  }
908
- return processedInput;
933
+ // Run serializer hook
934
+ return (await runSerializer({ input: processedInputObj, output }, serializer, context));
909
935
  };
910
936
  // Attach config properties directly to handler for flat access
911
937
  const typedHandler = handler;
@@ -916,6 +942,8 @@ function fabricService(config) {
916
942
  typedHandler.description = config.description;
917
943
  if (config.input !== undefined)
918
944
  typedHandler.input = config.input;
945
+ if (config.serializer !== undefined)
946
+ typedHandler.serializer = config.serializer;
919
947
  if (config.service !== undefined)
920
948
  typedHandler.service = config.service;
921
949
  return typedHandler;
@@ -1304,7 +1332,8 @@ function createListService(modelConfig, operationConfig, globalConfig) {
1304
1332
  const ascending = input.ascending ?? false;
1305
1333
  const deleted = input.deleted ?? false;
1306
1334
  const limit = Math.min(input.limit ?? defaultLimit, maxLimit);
1307
- const startKey = decodeCursor(input.cursor ?? input.startKey);
1335
+ const startKey = decodeCursor(input.cursor ??
1336
+ input.startKey);
1308
1337
  // Query entities
1309
1338
  const result = await queryByScope({
1310
1339
  archived,