@0xobelisk/ecs 1.2.0-pre.99 → 2.0.0
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/LICENSE +92 -0
- 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 +23 -23
- package/src/query.ts +40 -4
- package/src/subscription.ts +22 -2
- package/src/world.ts +37 -4
package/dist/index.mjs
CHANGED
|
@@ -182,7 +182,18 @@ var ECSQuery = class {
|
|
|
182
182
|
* Get component's primary key field name (quickly retrieve from cache)
|
|
183
183
|
*/
|
|
184
184
|
getComponentPrimaryKeyField(componentType) {
|
|
185
|
-
|
|
185
|
+
if (this.componentPrimaryKeys.has(componentType)) {
|
|
186
|
+
return this.componentPrimaryKeys.get(componentType);
|
|
187
|
+
}
|
|
188
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
189
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) {
|
|
190
|
+
return this.componentPrimaryKeys.get(snake);
|
|
191
|
+
}
|
|
192
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
193
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) {
|
|
194
|
+
return this.componentPrimaryKeys.get(camel);
|
|
195
|
+
}
|
|
196
|
+
return "entityId";
|
|
186
197
|
}
|
|
187
198
|
/**
|
|
188
199
|
* Set component discoverer
|
|
@@ -352,6 +363,7 @@ var ECSQuery = class {
|
|
|
352
363
|
try {
|
|
353
364
|
const condition = this.buildEntityCondition(componentType, entityId);
|
|
354
365
|
const component = await this.graphqlClient.getTableByCondition(componentType, condition);
|
|
366
|
+
if (component && component.isDeleted === true) return null;
|
|
355
367
|
return component;
|
|
356
368
|
} catch (_error) {
|
|
357
369
|
return null;
|
|
@@ -382,13 +394,31 @@ var ECSQuery = class {
|
|
|
382
394
|
* Validate if component type is ECS-compliant
|
|
383
395
|
*/
|
|
384
396
|
isECSComponent(componentType) {
|
|
385
|
-
|
|
397
|
+
if (this.availableComponents.includes(componentType)) return true;
|
|
398
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
399
|
+
if (camel !== componentType && this.availableComponents.includes(camel)) return true;
|
|
400
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
401
|
+
if (snake !== componentType && this.availableComponents.includes(snake)) return true;
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Resolve a componentType string to the canonical key stored in componentPrimaryKeys
|
|
406
|
+
* (handles snake_case ↔ camelCase mismatches)
|
|
407
|
+
*/
|
|
408
|
+
resolveComponentType(componentType) {
|
|
409
|
+
if (this.componentPrimaryKeys.has(componentType)) return componentType;
|
|
410
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
411
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) return snake;
|
|
412
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
413
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) return camel;
|
|
414
|
+
return componentType;
|
|
386
415
|
}
|
|
387
416
|
/**
|
|
388
417
|
* Build entity query condition (using cached primary key field name)
|
|
389
418
|
*/
|
|
390
419
|
buildEntityCondition(componentType, entityId) {
|
|
391
|
-
const
|
|
420
|
+
const resolved = this.resolveComponentType(componentType);
|
|
421
|
+
const primaryKeyField = this.componentPrimaryKeys.get(resolved);
|
|
392
422
|
if (primaryKeyField) {
|
|
393
423
|
return { [primaryKeyField]: entityId };
|
|
394
424
|
} else {
|
|
@@ -796,7 +826,18 @@ var ECSSubscription = class {
|
|
|
796
826
|
* Get component's primary key field name (quickly retrieve from cache, consistent with query.ts)
|
|
797
827
|
*/
|
|
798
828
|
getComponentPrimaryKeyField(componentType) {
|
|
799
|
-
|
|
829
|
+
if (this.componentPrimaryKeys.has(componentType)) {
|
|
830
|
+
return this.componentPrimaryKeys.get(componentType);
|
|
831
|
+
}
|
|
832
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
833
|
+
if (snake !== componentType && this.componentPrimaryKeys.has(snake)) {
|
|
834
|
+
return this.componentPrimaryKeys.get(snake);
|
|
835
|
+
}
|
|
836
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
837
|
+
if (camel !== componentType && this.componentPrimaryKeys.has(camel)) {
|
|
838
|
+
return this.componentPrimaryKeys.get(camel);
|
|
839
|
+
}
|
|
840
|
+
return "entityId";
|
|
800
841
|
}
|
|
801
842
|
/**
|
|
802
843
|
* Set component discoverer
|
|
@@ -808,7 +849,12 @@ var ECSSubscription = class {
|
|
|
808
849
|
* Validate if component type is ECS-compliant
|
|
809
850
|
*/
|
|
810
851
|
isECSComponent(componentType) {
|
|
811
|
-
|
|
852
|
+
if (this.availableComponents.includes(componentType)) return true;
|
|
853
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
854
|
+
if (camel !== componentType && this.availableComponents.includes(camel)) return true;
|
|
855
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
856
|
+
if (snake !== componentType && this.availableComponents.includes(snake)) return true;
|
|
857
|
+
return false;
|
|
812
858
|
}
|
|
813
859
|
/**
|
|
814
860
|
* Get component field information (intelligent parsing)
|
|
@@ -1508,7 +1554,19 @@ var ComponentDiscoverer = class {
|
|
|
1508
1554
|
return this.componentTypes;
|
|
1509
1555
|
}
|
|
1510
1556
|
getComponentMetadata(componentType) {
|
|
1511
|
-
|
|
1557
|
+
const direct = this.componentMetadataMap.get(componentType);
|
|
1558
|
+
if (direct) return direct;
|
|
1559
|
+
const snake = componentType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
1560
|
+
if (snake !== componentType) {
|
|
1561
|
+
const bySnake = this.componentMetadataMap.get(snake);
|
|
1562
|
+
if (bySnake) return bySnake;
|
|
1563
|
+
}
|
|
1564
|
+
const camel = componentType.replace(/_([a-z])/g, (_, l) => l.toUpperCase());
|
|
1565
|
+
if (camel !== componentType) {
|
|
1566
|
+
const byCamel = this.componentMetadataMap.get(camel);
|
|
1567
|
+
if (byCamel) return byCamel;
|
|
1568
|
+
}
|
|
1569
|
+
return null;
|
|
1512
1570
|
}
|
|
1513
1571
|
snakeToCamel(str) {
|
|
1514
1572
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -1669,7 +1727,17 @@ var ResourceDiscoverer = class {
|
|
|
1669
1727
|
return this.resourceTypes;
|
|
1670
1728
|
}
|
|
1671
1729
|
getResourceMetadata(resourceType) {
|
|
1672
|
-
|
|
1730
|
+
const direct = this.resourceMetadataMap.get(resourceType);
|
|
1731
|
+
if (direct) return direct;
|
|
1732
|
+
const camel = this.snakeToCamel(resourceType);
|
|
1733
|
+
if (camel !== resourceType) {
|
|
1734
|
+
return this.resourceMetadataMap.get(camel) || null;
|
|
1735
|
+
}
|
|
1736
|
+
const snake = resourceType.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
1737
|
+
if (snake !== resourceType) {
|
|
1738
|
+
return this.resourceMetadataMap.get(snake) || null;
|
|
1739
|
+
}
|
|
1740
|
+
return null;
|
|
1673
1741
|
}
|
|
1674
1742
|
snakeToCamel(str) {
|
|
1675
1743
|
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
@@ -2232,7 +2300,9 @@ var DubheECSWorld = class {
|
|
|
2232
2300
|
totalCount: 0
|
|
2233
2301
|
};
|
|
2234
2302
|
}
|
|
2235
|
-
const whereConditions = {
|
|
2303
|
+
const whereConditions = {
|
|
2304
|
+
isDeleted: { equalTo: false }
|
|
2305
|
+
};
|
|
2236
2306
|
if (options?.filters) {
|
|
2237
2307
|
for (const [key, value] of Object.entries(options.filters)) {
|
|
2238
2308
|
if (typeof value === "object" && value !== null) {
|