@0xobelisk/ecs 1.2.0-pre.98 → 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 ADDED
@@ -0,0 +1,92 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Obelisk Labs
11
+
12
+ Licensed Work: Dubhe
13
+ The Licensed Work is (c) 2023 Obelisk Labs
14
+
15
+ -----------------------------------------------------------------------------
16
+
17
+ Terms
18
+
19
+ The Licensor hereby grants you the right to copy, modify, create derivative
20
+ works, redistribute, and make non-production use of the Licensed Work. The
21
+ Licensor may make an Additional Use Grant, above, permitting limited
22
+ production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly
25
+ available distribution of a specific version of the Licensed Work under this
26
+ License, whichever comes first, the Licensor hereby grants you rights under
27
+ the terms of the Change License, and the rights granted in the paragraph
28
+ above terminate.
29
+
30
+ If your use of the Licensed Work does not comply with the requirements
31
+ currently in effect as described in this License, you must purchase a
32
+ commercial license from the Licensor, its affiliated entities, or authorized
33
+ resellers, or you must refrain from using the Licensed Work.
34
+
35
+ All copies of the original and modified Licensed Work, and derivative works
36
+ of the Licensed Work, are subject to this License. This License applies
37
+ separately for each version of the Licensed Work and the Change Date may vary
38
+ for each version of the Licensed Work released by Licensor.
39
+
40
+ You must conspicuously display this License on each original or modified copy
41
+ of the Licensed Work. If you receive the Licensed Work in original or
42
+ modified form from a third party, the terms and conditions set forth in this
43
+ License apply to your use of that work.
44
+
45
+ Any use of the Licensed Work in violation of this License will automatically
46
+ terminate your rights under this License for the current and all other
47
+ versions of the Licensed Work.
48
+
49
+ This License does not grant you any right in any trademark or logo of
50
+ Licensor or its affiliates (provided that you may use a trademark or logo of
51
+ Licensor as expressly required by this License).
52
+
53
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
54
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
55
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
57
+ TITLE.
58
+
59
+ MariaDB hereby grants you permission to use this License’s text to license
60
+ your works, and to refer to it using the trademark "Business Source License",
61
+ as long as you comply with the Covenants of Licensor below.
62
+
63
+ -----------------------------------------------------------------------------
64
+
65
+ Covenants of Licensor
66
+
67
+ In consideration of the right to use this License’s text and the "Business
68
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
69
+ other recipients of the licensed work to be provided by Licensor:
70
+
71
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
72
+ or a license that is compatible with GPL Version 2.0 or a later version,
73
+ where "compatible" means that software provided under the Change License can
74
+ be included in a program with software provided under GPL Version 2.0 or a
75
+ later version. Licensor may specify additional Change Licenses without
76
+ limitation.
77
+
78
+ 2. To either: (a) specify an additional grant of rights to use that does not
79
+ impose any additional restriction on the right granted in this License, as
80
+ the Additional Use Grant; or (b) insert the text "None".
81
+
82
+ 3. To specify a Change Date.
83
+
84
+ 4. Not to modify this License in any other way.
85
+
86
+ -----------------------------------------------------------------------------
87
+
88
+ Notice
89
+
90
+ The Business Source License (this document, or the "License") is not an Open
91
+ Source license. However, the Licensed Work will eventually be made available
92
+ under an Open Source License, as stated in this License.
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
- return this.componentPrimaryKeys.get(componentType) || "entityId";
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
- return this.availableComponents.includes(componentType);
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 primaryKeyField = this.componentPrimaryKeys.get(componentType);
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
- return this.componentPrimaryKeys.get(componentType) || "entityId";
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
- return this.availableComponents.includes(componentType);
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
- return this.componentMetadataMap.get(componentType) || null;
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
- return this.resourceMetadataMap.get(resourceType) || null;
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) {