@0xobelisk/ecs 1.2.0-pre.118 → 1.2.0-pre.120
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 +78 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -8
- package/dist/index.mjs.map +1 -1
- package/dist/query.d.ts +5 -0
- package/package.json +2 -2
- package/src/query.ts +40 -4
- package/src/subscription.ts +22 -2
- package/src/world.ts +37 -4
package/dist/index.js
CHANGED
|
@@ -242,7 +242,18 @@ var ECSQuery = class {
|
|
|
242
242
|
* Get component's primary key field name (quickly retrieve from cache)
|
|
243
243
|
*/
|
|
244
244
|
getComponentPrimaryKeyField(componentType) {
|
|
245
|
-
|
|
245
|
+
if (this.componentPrimaryKeys.has(componentType)) {
|
|
246
|
+
return this.componentPrimaryKeys.get(componentType);
|
|
247
|
+
}
|
|
248
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
249
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) {
|
|
250
|
+
return this.componentPrimaryKeys.get(snake);
|
|
251
|
+
}
|
|
252
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
253
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) {
|
|
254
|
+
return this.componentPrimaryKeys.get(camel);
|
|
255
|
+
}
|
|
256
|
+
return "entityId";
|
|
246
257
|
}
|
|
247
258
|
/**
|
|
248
259
|
* Set component discoverer
|
|
@@ -412,6 +423,7 @@ var ECSQuery = class {
|
|
|
412
423
|
try {
|
|
413
424
|
const condition = this.buildEntityCondition(componentType, entityId);
|
|
414
425
|
const component = await this.graphqlClient.getTableByCondition(componentType, condition);
|
|
426
|
+
if (component && component.isDeleted === true) return null;
|
|
415
427
|
return component;
|
|
416
428
|
} catch (_error) {
|
|
417
429
|
return null;
|
|
@@ -442,13 +454,31 @@ var ECSQuery = class {
|
|
|
442
454
|
* Validate if component type is ECS-compliant
|
|
443
455
|
*/
|
|
444
456
|
isECSComponent(componentType) {
|
|
445
|
-
|
|
457
|
+
if (this.availableComponents.includes(componentType)) return true;
|
|
458
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
459
|
+
if (camel !== componentType && this.availableComponents.includes(camel)) return true;
|
|
460
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
461
|
+
if (snake !== componentType && this.availableComponents.includes(snake)) return true;
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Resolve a componentType string to the canonical key stored in componentPrimaryKeys
|
|
466
|
+
* (handles snake_case ↔ camelCase mismatches)
|
|
467
|
+
*/
|
|
468
|
+
resolveComponentType(componentType) {
|
|
469
|
+
if (this.componentPrimaryKeys.has(componentType)) return componentType;
|
|
470
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
471
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) return snake;
|
|
472
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
473
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) return camel;
|
|
474
|
+
return componentType;
|
|
446
475
|
}
|
|
447
476
|
/**
|
|
448
477
|
* Build entity query condition (using cached primary key field name)
|
|
449
478
|
*/
|
|
450
479
|
buildEntityCondition(componentType, entityId) {
|
|
451
|
-
const
|
|
480
|
+
const resolved = this.resolveComponentType(componentType);
|
|
481
|
+
const primaryKeyField = this.componentPrimaryKeys.get(resolved);
|
|
452
482
|
if (primaryKeyField) {
|
|
453
483
|
return { [primaryKeyField]: entityId };
|
|
454
484
|
} else {
|
|
@@ -856,7 +886,18 @@ var ECSSubscription = class {
|
|
|
856
886
|
* Get component's primary key field name (quickly retrieve from cache, consistent with query.ts)
|
|
857
887
|
*/
|
|
858
888
|
getComponentPrimaryKeyField(componentType) {
|
|
859
|
-
|
|
889
|
+
if (this.componentPrimaryKeys.has(componentType)) {
|
|
890
|
+
return this.componentPrimaryKeys.get(componentType);
|
|
891
|
+
}
|
|
892
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
893
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) {
|
|
894
|
+
return this.componentPrimaryKeys.get(snake);
|
|
895
|
+
}
|
|
896
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
897
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) {
|
|
898
|
+
return this.componentPrimaryKeys.get(camel);
|
|
899
|
+
}
|
|
900
|
+
return "entityId";
|
|
860
901
|
}
|
|
861
902
|
/**
|
|
862
903
|
* Set component discoverer
|
|
@@ -868,7 +909,12 @@ var ECSSubscription = class {
|
|
|
868
909
|
* Validate if component type is ECS-compliant
|
|
869
910
|
*/
|
|
870
911
|
isECSComponent(componentType) {
|
|
871
|
-
|
|
912
|
+
if (this.availableComponents.includes(componentType)) return true;
|
|
913
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
914
|
+
if (camel !== componentType && this.availableComponents.includes(camel)) return true;
|
|
915
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
916
|
+
if (snake !== componentType && this.availableComponents.includes(snake)) return true;
|
|
917
|
+
return false;
|
|
872
918
|
}
|
|
873
919
|
/**
|
|
874
920
|
* Get component field information (intelligent parsing)
|
|
@@ -1568,7 +1614,19 @@ var ComponentDiscoverer = class {
|
|
|
1568
1614
|
return this.componentTypes;
|
|
1569
1615
|
}
|
|
1570
1616
|
getComponentMetadata(componentType) {
|
|
1571
|
-
|
|
1617
|
+
const direct = this.componentMetadataMap.get(componentType);
|
|
1618
|
+
if (direct) return direct;
|
|
1619
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
1620
|
+
if (snake !== componentType) {
|
|
1621
|
+
const bySnake = this.componentMetadataMap.get(snake);
|
|
1622
|
+
if (bySnake) return bySnake;
|
|
1623
|
+
}
|
|
1624
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
1625
|
+
if (camel !== componentType) {
|
|
1626
|
+
const byCamel = this.componentMetadataMap.get(camel);
|
|
1627
|
+
if (byCamel) return byCamel;
|
|
1628
|
+
}
|
|
1629
|
+
return null;
|
|
1572
1630
|
}
|
|
1573
1631
|
snakeToCamel(str) {
|
|
1574
1632
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1729,7 +1787,17 @@ var ResourceDiscoverer = class {
|
|
|
1729
1787
|
return this.resourceTypes;
|
|
1730
1788
|
}
|
|
1731
1789
|
getResourceMetadata(resourceType) {
|
|
1732
|
-
|
|
1790
|
+
const direct = this.resourceMetadataMap.get(resourceType);
|
|
1791
|
+
if (direct) return direct;
|
|
1792
|
+
const camel = this.snakeToCamel(resourceType);
|
|
1793
|
+
if (camel !== resourceType) {
|
|
1794
|
+
return this.resourceMetadataMap.get(camel) || null;
|
|
1795
|
+
}
|
|
1796
|
+
const snake = resourceType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
1797
|
+
if (snake !== resourceType) {
|
|
1798
|
+
return this.resourceMetadataMap.get(snake) || null;
|
|
1799
|
+
}
|
|
1800
|
+
return null;
|
|
1733
1801
|
}
|
|
1734
1802
|
snakeToCamel(str) {
|
|
1735
1803
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -2292,7 +2360,9 @@ var DubheECSWorld = class {
|
|
|
2292
2360
|
totalCount: 0
|
|
2293
2361
|
};
|
|
2294
2362
|
}
|
|
2295
|
-
const whereConditions = {
|
|
2363
|
+
const whereConditions = {
|
|
2364
|
+
isDeleted: { equalTo: false }
|
|
2365
|
+
};
|
|
2296
2366
|
if (options?.filters) {
|
|
2297
2367
|
for (const [key, value] of Object.entries(options.filters)) {
|
|
2298
2368
|
if (typeof value === "object" && value !== null) {
|