@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 +102 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -85
- package/dist/index.mjs.map +1 -1
- package/dist/world.d.ts +8 -1
- package/package.json +23 -23
- package/src/world.ts +112 -91
- package/LICENSE +0 -92
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
|
-
|
|
1458
|
-
|
|
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
|
-
|
|
1461
|
-
for (const
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
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
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
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
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
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
|
}
|