@0xobelisk/ecs 1.2.0-pre.96 → 1.2.0-pre.97

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/index.js CHANGED
@@ -1451,99 +1451,116 @@ var ComponentDiscoverer = class {
1451
1451
  });
1452
1452
  }
1453
1453
  /**
1454
- * Parse components from DubheMetadata JSON format
1454
+ * Parse components from DubheMetadata JSON format.
1455
+ *
1456
+ * Two sources are scanned:
1457
+ * 1. dubheMetadata.components – explicit ECS components (legacy / manual).
1458
+ * 2. dubheMetadata.resources – resources whose sole key is `entity_id` are
1459
+ * treated as ECS components because they follow the same 1-entity-1-record
1460
+ * semantics. Resources with composite keys (entity_id + extra keys) have
1461
+ * N records per entity and remain pure resources.
1455
1462
  */
1456
1463
  parseFromDubheMetadata(components, errors) {
1457
- if (!this.dubheMetadata?.components) {
1458
- return;
1464
+ const entries = [];
1465
+ if (this.dubheMetadata?.components) {
1466
+ for (const record of this.dubheMetadata.components) {
1467
+ entries.push(...Object.entries(record));
1468
+ }
1459
1469
  }
1460
- for (const componentRecord of this.dubheMetadata.components) {
1461
- for (const [componentName, componentConfig] of Object.entries(componentRecord)) {
1462
- const componentType = this.tableNameToComponentName(componentName);
1463
- try {
1464
- const fields = [];
1465
- const primaryKeys = [];
1466
- const enumFields = [];
1467
- if (componentConfig.fields && Array.isArray(componentConfig.fields)) {
1468
- for (const fieldRecord of componentConfig.fields) {
1469
- for (const [fieldName, fieldType] of Object.entries(fieldRecord)) {
1470
- const camelFieldName = this.snakeToCamel(fieldName);
1471
- const typeStr = String(fieldType);
1472
- const isCustomKey = componentConfig.keys && componentConfig.keys.includes(fieldName);
1473
- fields.push({
1474
- name: camelFieldName,
1475
- type: this.dubheTypeToGraphQLType(typeStr),
1476
- nullable: !isCustomKey,
1477
- isPrimaryKey: isCustomKey,
1478
- isEnum: this.isEnumType(typeStr)
1479
- });
1480
- if (isCustomKey) {
1481
- primaryKeys.push(camelFieldName);
1482
- }
1483
- if (this.isEnumType(typeStr)) {
1484
- enumFields.push(camelFieldName);
1485
- }
1470
+ if (this.dubheMetadata?.resources) {
1471
+ for (const record of this.dubheMetadata.resources) {
1472
+ for (const [name, cfg] of Object.entries(record)) {
1473
+ if (cfg.keys && cfg.keys.length === 1 && cfg.keys[0] === "entity_id") {
1474
+ entries.push([name, cfg]);
1475
+ }
1476
+ }
1477
+ }
1478
+ }
1479
+ for (const [componentName, componentConfig] of entries) {
1480
+ const componentType = this.tableNameToComponentName(componentName);
1481
+ try {
1482
+ const fields = [];
1483
+ const primaryKeys = [];
1484
+ const enumFields = [];
1485
+ if (componentConfig.fields && Array.isArray(componentConfig.fields)) {
1486
+ for (const fieldRecord of componentConfig.fields) {
1487
+ for (const [fieldName, fieldType] of Object.entries(fieldRecord)) {
1488
+ const camelFieldName = this.snakeToCamel(fieldName);
1489
+ const typeStr = String(fieldType);
1490
+ const isCustomKey = componentConfig.keys && componentConfig.keys.includes(fieldName);
1491
+ fields.push({
1492
+ name: camelFieldName,
1493
+ type: this.dubheTypeToGraphQLType(typeStr),
1494
+ nullable: !isCustomKey,
1495
+ isPrimaryKey: isCustomKey,
1496
+ isEnum: this.isEnumType(typeStr)
1497
+ });
1498
+ if (isCustomKey) {
1499
+ primaryKeys.push(camelFieldName);
1500
+ }
1501
+ if (this.isEnumType(typeStr)) {
1502
+ enumFields.push(camelFieldName);
1486
1503
  }
1487
1504
  }
1488
1505
  }
1489
- if (primaryKeys.length === 0) {
1490
- fields.unshift({
1491
- name: "entityId",
1492
- type: "String",
1493
- nullable: false,
1494
- isPrimaryKey: true,
1495
- isEnum: false
1496
- });
1497
- primaryKeys.push("entityId");
1498
- }
1499
- fields.push(
1500
- {
1501
- name: "createdAtTimestampMs",
1502
- type: "BigInt",
1503
- nullable: false,
1504
- isPrimaryKey: false,
1505
- isEnum: false
1506
- },
1507
- {
1508
- name: "updatedAtTimestampMs",
1509
- type: "BigInt",
1510
- nullable: false,
1511
- isPrimaryKey: false,
1512
- isEnum: false
1513
- },
1514
- {
1515
- name: "isDeleted",
1516
- type: "Boolean",
1517
- nullable: false,
1518
- isPrimaryKey: false,
1519
- isEnum: false
1520
- },
1521
- {
1522
- name: "lastUpdateDigest",
1523
- type: "String",
1524
- nullable: false,
1525
- isPrimaryKey: false,
1526
- isEnum: false
1527
- }
1528
- );
1529
- if (primaryKeys.length !== 1) {
1530
- continue;
1506
+ }
1507
+ if (primaryKeys.length === 0) {
1508
+ fields.unshift({
1509
+ name: "entityId",
1510
+ type: "String",
1511
+ nullable: false,
1512
+ isPrimaryKey: true,
1513
+ isEnum: false
1514
+ });
1515
+ primaryKeys.push("entityId");
1516
+ }
1517
+ fields.push(
1518
+ {
1519
+ name: "createdAtTimestampMs",
1520
+ type: "BigInt",
1521
+ nullable: false,
1522
+ isPrimaryKey: false,
1523
+ isEnum: false
1524
+ },
1525
+ {
1526
+ name: "updatedAtTimestampMs",
1527
+ type: "BigInt",
1528
+ nullable: false,
1529
+ isPrimaryKey: false,
1530
+ isEnum: false
1531
+ },
1532
+ {
1533
+ name: "isDeleted",
1534
+ type: "Boolean",
1535
+ nullable: false,
1536
+ isPrimaryKey: false,
1537
+ isEnum: false
1538
+ },
1539
+ {
1540
+ name: "lastUpdateDigest",
1541
+ type: "String",
1542
+ nullable: false,
1543
+ isPrimaryKey: false,
1544
+ isEnum: false
1531
1545
  }
1532
- const metadata = {
1533
- name: componentType,
1534
- tableName: componentName,
1535
- fields,
1536
- primaryKeys,
1537
- hasDefaultId: primaryKeys.includes("entityId"),
1538
- enumFields,
1539
- lastUpdated: Date.now(),
1540
- description: `Auto-discovered component: ${componentName}`
1541
- };
1542
- components.push(metadata);
1543
- } catch (error) {
1544
- const errorMsg = `Component ${componentType} validation failed: ${formatError(error)}`;
1545
- errors.push(errorMsg);
1546
+ );
1547
+ if (primaryKeys.length !== 1) {
1548
+ continue;
1546
1549
  }
1550
+ const metadata = {
1551
+ name: componentType,
1552
+ tableName: componentName,
1553
+ fields,
1554
+ primaryKeys,
1555
+ hasDefaultId: primaryKeys.includes("entityId"),
1556
+ enumFields,
1557
+ lastUpdated: Date.now(),
1558
+ description: `Auto-discovered component: ${componentName}`
1559
+ };
1560
+ components.push(metadata);
1561
+ } catch (error) {
1562
+ const errorMsg = `Component ${componentType} validation failed: ${formatError(error)}`;
1563
+ errors.push(errorMsg);
1547
1564
  }
1548
1565
  }
1549
1566
  }