@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.
Files changed (50) hide show
  1. package/dist/cjs/ServiceSuite.d.ts +58 -0
  2. package/dist/cjs/commander/index.cjs +7 -7
  3. package/dist/cjs/commander/index.cjs.map +1 -1
  4. package/dist/cjs/data/index.cjs.map +1 -1
  5. package/dist/cjs/http/index.cjs.map +1 -1
  6. package/dist/cjs/index.cjs +159 -7
  7. package/dist/cjs/index.cjs.map +1 -1
  8. package/dist/cjs/index.d.ts +3 -1
  9. package/dist/cjs/lambda/index.cjs +7 -7
  10. package/dist/cjs/lambda/index.cjs.map +1 -1
  11. package/dist/cjs/llm/index.cjs +7 -7
  12. package/dist/cjs/llm/index.cjs.map +1 -1
  13. package/dist/cjs/mcp/FabricMcpServer.d.ts +44 -0
  14. package/dist/cjs/mcp/index.cjs +156 -7
  15. package/dist/cjs/mcp/index.cjs.map +1 -1
  16. package/dist/cjs/mcp/index.d.ts +2 -1
  17. package/dist/cjs/mcp/types.d.ts +66 -0
  18. package/dist/cjs/service.d.ts +5 -0
  19. package/dist/esm/ServiceSuite.d.ts +58 -0
  20. package/dist/esm/commander/index.js +7 -7
  21. package/dist/esm/commander/index.js.map +1 -1
  22. package/dist/esm/data/index.js.map +1 -1
  23. package/dist/esm/http/index.js.map +1 -1
  24. package/dist/esm/index.d.ts +2 -0
  25. package/dist/esm/index.js +158 -8
  26. package/dist/esm/index.js.map +1 -1
  27. package/dist/esm/lambda/index.js +7 -7
  28. package/dist/esm/lambda/index.js.map +1 -1
  29. package/dist/esm/llm/index.js +7 -7
  30. package/dist/esm/llm/index.js.map +1 -1
  31. package/dist/esm/mcp/FabricMcpServer.d.ts +44 -0
  32. package/dist/esm/mcp/index.d.ts +2 -1
  33. package/dist/esm/mcp/index.js +155 -8
  34. package/dist/esm/mcp/index.js.map +1 -1
  35. package/dist/esm/mcp/types.d.ts +66 -0
  36. package/package.json +1 -1
  37. package/dist/cjs/commander/registerServiceCommand.d.ts +0 -43
  38. package/dist/cjs/convert-date.d.ts +0 -47
  39. package/dist/cjs/convert.d.ts +0 -69
  40. package/dist/cjs/lambda/createLambdaService.d.ts +0 -33
  41. package/dist/cjs/llm/createLlmTool.d.ts +0 -40
  42. package/dist/cjs/mcp/registerMcpTool.d.ts +0 -38
  43. package/dist/cjs/types/fieldCategory.d.ts +0 -20
  44. package/dist/esm/commander/registerServiceCommand.d.ts +0 -43
  45. package/dist/esm/convert-date.d.ts +0 -47
  46. package/dist/esm/convert.d.ts +0 -69
  47. package/dist/esm/lambda/createLambdaService.d.ts +0 -33
  48. package/dist/esm/llm/createLlmTool.d.ts +0 -40
  49. package/dist/esm/mcp/registerMcpTool.d.ts +0 -38
  50. package/dist/esm/types/fieldCategory.d.ts +0 -20
package/dist/esm/index.js CHANGED
@@ -1450,6 +1450,13 @@ async function processField(fieldName, value, definition) {
1450
1450
  }
1451
1451
  return convertedValue;
1452
1452
  }
1453
+ /**
1454
+ * Type guard to check if a value is a pre-instantiated Service
1455
+ * A Service is a function with the `$fabric` property set by fabricService
1456
+ */
1457
+ function isService(value) {
1458
+ return typeof value === "function" && "$fabric" in value;
1459
+ }
1453
1460
  /**
1454
1461
  * Fabric a service function
1455
1462
  *
@@ -1502,13 +1509,6 @@ function fabricService(config) {
1502
1509
  }
1503
1510
 
1504
1511
  // Resolve inline service definitions to full Service objects
1505
- /**
1506
- * Type guard to check if a value is a pre-instantiated Service
1507
- * A Service is a function with the `$fabric` property set by fabricService
1508
- */
1509
- function isService(value) {
1510
- return typeof value === "function" && "$fabric" in value;
1511
- }
1512
1512
  /**
1513
1513
  * Resolve a service configuration to a full Service object
1514
1514
  *
@@ -1564,6 +1564,156 @@ function resolveService(config) {
1564
1564
  });
1565
1565
  }
1566
1566
 
1567
+ // ServiceSuite for @jaypie/fabric
1568
+ // Groups fabricService instances for discovery, metadata export, and direct execution
1569
+ /**
1570
+ * Derive type string from InputFieldDefinition.type
1571
+ */
1572
+ function deriveTypeString(type) {
1573
+ // Handle constructors
1574
+ if (type === String || type === "string")
1575
+ return "string";
1576
+ if (type === Number || type === "number")
1577
+ return "number";
1578
+ if (type === Boolean || type === "boolean")
1579
+ return "boolean";
1580
+ if (type === Object || type === "object")
1581
+ return "object";
1582
+ if (type === Array || type === "array")
1583
+ return "array";
1584
+ if (type === Date)
1585
+ return "string"; // Dates are passed as strings
1586
+ // Handle typed arrays: [String], [Number], etc.
1587
+ if (Array.isArray(type)) {
1588
+ if (type.length === 0)
1589
+ return "array";
1590
+ const first = type[0];
1591
+ // If it's a type constructor, it's a typed array
1592
+ if (first === String ||
1593
+ first === Number ||
1594
+ first === Boolean ||
1595
+ first === Object ||
1596
+ first === "string" ||
1597
+ first === "number" ||
1598
+ first === "boolean" ||
1599
+ first === "object" ||
1600
+ first === "") {
1601
+ return "array";
1602
+ }
1603
+ // If all elements are strings (or RegExp), it's a validated string enum
1604
+ if (type.every((item) => typeof item === "string" || item instanceof RegExp)) {
1605
+ return "string";
1606
+ }
1607
+ // If all elements are numbers, it's a validated number enum
1608
+ if (type.every((item) => typeof item === "number")) {
1609
+ return "number";
1610
+ }
1611
+ return "array";
1612
+ }
1613
+ // Handle RegExp (validated string)
1614
+ if (type instanceof RegExp) {
1615
+ return "string";
1616
+ }
1617
+ return "string"; // Default fallback
1618
+ }
1619
+ /**
1620
+ * Extract enum values if the type is a validated string/number array
1621
+ */
1622
+ function extractEnumValues(type) {
1623
+ if (!Array.isArray(type))
1624
+ return undefined;
1625
+ if (type.length === 0)
1626
+ return undefined;
1627
+ // Check if it's a validated string enum (array of strings, possibly with RegExp)
1628
+ const stringValues = type.filter((item) => typeof item === "string");
1629
+ if (stringValues.length > 0 && stringValues.length === type.filter((item) => typeof item === "string").length) {
1630
+ // All non-RegExp items are strings
1631
+ return stringValues;
1632
+ }
1633
+ // Check if it's a validated number enum
1634
+ if (type.every((item) => typeof item === "number")) {
1635
+ return type.map((n) => String(n));
1636
+ }
1637
+ return undefined;
1638
+ }
1639
+ /**
1640
+ * Convert fabricService input definitions to ServiceInput array
1641
+ */
1642
+ function extractInputs(inputDefinitions) {
1643
+ if (!inputDefinitions)
1644
+ return [];
1645
+ return Object.entries(inputDefinitions).map(([name, def]) => {
1646
+ const required = def.required !== false && def.default === undefined;
1647
+ const enumValues = extractEnumValues(def.type);
1648
+ return {
1649
+ name,
1650
+ type: deriveTypeString(def.type),
1651
+ required,
1652
+ description: def.description || "",
1653
+ ...(enumValues && { enum: enumValues }),
1654
+ };
1655
+ });
1656
+ }
1657
+ /**
1658
+ * Check if a service has any required inputs
1659
+ */
1660
+ function hasRequiredInputs(inputs) {
1661
+ return inputs.some((input) => input.required);
1662
+ }
1663
+ /**
1664
+ * Create a ServiceSuite instance
1665
+ */
1666
+ function createServiceSuite(config) {
1667
+ const { name, version } = config;
1668
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1669
+ const serviceRegistry = new Map();
1670
+ const categorySet = new Set();
1671
+ const suite = {
1672
+ name,
1673
+ version,
1674
+ get categories() {
1675
+ return Array.from(categorySet).sort();
1676
+ },
1677
+ get services() {
1678
+ return Array.from(serviceRegistry.values()).map((entry) => entry.meta);
1679
+ },
1680
+ getService(serviceName) {
1681
+ return serviceRegistry.get(serviceName)?.meta;
1682
+ },
1683
+ getServicesByCategory(category) {
1684
+ return Array.from(serviceRegistry.values())
1685
+ .filter((entry) => entry.meta.category === category)
1686
+ .map((entry) => entry.meta);
1687
+ },
1688
+ async execute(serviceName, inputs) {
1689
+ const entry = serviceRegistry.get(serviceName);
1690
+ if (!entry) {
1691
+ throw new Error(`Service "${serviceName}" not found in suite "${name}"`);
1692
+ }
1693
+ return entry.service(inputs);
1694
+ },
1695
+ register(
1696
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1697
+ service, category) {
1698
+ const serviceName = service.alias;
1699
+ if (!serviceName) {
1700
+ throw new Error("Service must have an alias to be registered");
1701
+ }
1702
+ const inputs = extractInputs(service.input);
1703
+ const meta = {
1704
+ name: serviceName,
1705
+ description: service.description || "",
1706
+ category,
1707
+ inputs,
1708
+ executable: !hasRequiredInputs(inputs),
1709
+ };
1710
+ serviceRegistry.set(serviceName, { service, meta });
1711
+ categorySet.add(category);
1712
+ },
1713
+ };
1714
+ return suite;
1715
+ }
1716
+
1567
1717
  /**
1568
1718
  * Status Type for @jaypie/fabric
1569
1719
  *
@@ -1602,5 +1752,5 @@ function isStatus(value) {
1602
1752
  STATUS_VALUES.includes(value));
1603
1753
  }
1604
1754
 
1605
- export { APEX, ARCHIVED_SUFFIX, BOOLEAN_TYPE, DATETIME_TYPE, DATE_TYPE, DEFAULT_INDEXES, DEFAULT_SORT_KEY, DELETED_SUFFIX, DOLLARS_TYPE, DateType, ELEMENTARY_TYPES, ELEMENTARY_TYPE_REGISTRY, FABRIC_MODEL_AUTO_FIELDS, FABRIC_MODEL_FIELDS, FABRIC_MODEL_REQUIRED_FIELDS, FABRIC_MODEL_TIMESTAMP_FIELDS, FABRIC_VERSION, MULTISELECT_TYPE, NUMBER_TYPE, REFERENCE_TYPE, SELECT_TYPE, SEPARATOR, STATUS_VALUES, SYSTEM_MODELS, StatusType, TEXTAREA_TYPE, TEXT_TYPE, buildCompositeKey, calculateIndexSuffix, calculateScope, clearRegistry, computeResolvedName, createFabricModelInput, fabric, fabricArray, fabricBoolean, fabricDate, fabricNumber, fabricObject, fabricService, fabricString, generateIndexName, getAllElementaryTypes, getAllRegisteredIndexes, getElementaryType, getModelIndexes, getModelSchema, getRegisteredModels, hasFabricModelShape, isAutoField, isDateType, isElementaryType, isFabricModel, isFieldDefinition, isModelRegistered, isStatus, isTimestampField, isValidDate, pickFabricModelFields, populateIndexKeys, registerModel, resolveFromArray, resolveFromDate, resolveFromObject, resolveService, resolveWithFallback, tryBuildCompositeKey };
1755
+ export { APEX, ARCHIVED_SUFFIX, BOOLEAN_TYPE, DATETIME_TYPE, DATE_TYPE, DEFAULT_INDEXES, DEFAULT_SORT_KEY, DELETED_SUFFIX, DOLLARS_TYPE, DateType, ELEMENTARY_TYPES, ELEMENTARY_TYPE_REGISTRY, FABRIC_MODEL_AUTO_FIELDS, FABRIC_MODEL_FIELDS, FABRIC_MODEL_REQUIRED_FIELDS, FABRIC_MODEL_TIMESTAMP_FIELDS, FABRIC_VERSION, MULTISELECT_TYPE, NUMBER_TYPE, REFERENCE_TYPE, SELECT_TYPE, SEPARATOR, STATUS_VALUES, SYSTEM_MODELS, StatusType, TEXTAREA_TYPE, TEXT_TYPE, buildCompositeKey, calculateIndexSuffix, calculateScope, clearRegistry, computeResolvedName, createFabricModelInput, createServiceSuite, fabric, fabricArray, fabricBoolean, fabricDate, fabricNumber, fabricObject, fabricService, fabricString, generateIndexName, getAllElementaryTypes, getAllRegisteredIndexes, getElementaryType, getModelIndexes, getModelSchema, getRegisteredModels, hasFabricModelShape, isAutoField, isDateType, isElementaryType, isFabricModel, isFieldDefinition, isModelRegistered, isService, isStatus, isTimestampField, isValidDate, pickFabricModelFields, populateIndexKeys, registerModel, resolveFromArray, resolveFromDate, resolveFromObject, resolveService, resolveWithFallback, tryBuildCompositeKey };
1606
1756
  //# sourceMappingURL=index.js.map