@shipload/sdk 1.0.0-next.45 → 1.0.0-next.46

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.
Files changed (41) hide show
  1. package/lib/shipload.d.ts +235 -39
  2. package/lib/shipload.js +1399 -157
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +1385 -158
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +81 -15
  7. package/lib/testing.js +374 -41
  8. package/lib/testing.js.map +1 -1
  9. package/lib/testing.m.js +375 -42
  10. package/lib/testing.m.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/capabilities/gathering.test.ts +14 -1
  13. package/src/capabilities/gathering.ts +6 -5
  14. package/src/capabilities/modules.ts +4 -0
  15. package/src/contracts/server.ts +242 -28
  16. package/src/data/entities.json +93 -19
  17. package/src/data/item-ids.ts +12 -0
  18. package/src/data/items.json +76 -2
  19. package/src/data/kind-registry.json +10 -0
  20. package/src/data/metadata.ts +68 -0
  21. package/src/data/recipes-runtime.ts +1 -0
  22. package/src/data/recipes.json +720 -0
  23. package/src/derivation/capabilities.test.ts +11 -11
  24. package/src/derivation/capabilities.ts +42 -27
  25. package/src/derivation/index.ts +2 -0
  26. package/src/derivation/recipe-usage.test.ts +11 -7
  27. package/src/derivation/stars.test.ts +16 -0
  28. package/src/derivation/stars.ts +10 -0
  29. package/src/derivation/stratum.ts +11 -4
  30. package/src/entities/makers.ts +8 -1
  31. package/src/index-module.ts +5 -1
  32. package/src/managers/actions.ts +10 -0
  33. package/src/nft/buildImmutableData.ts +1 -1
  34. package/src/nft/description.ts +20 -11
  35. package/src/resolution/describe-module.ts +21 -8
  36. package/src/resolution/resolve-item.ts +31 -33
  37. package/src/scheduling/projection.ts +8 -1
  38. package/src/subscriptions/manager.cluster.test.ts +7 -2
  39. package/src/subscriptions/types.ts +1 -0
  40. package/src/utils/cargo.test.ts +14 -0
  41. package/src/utils/cargo.ts +2 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "1.0.0-next.45",
4
+ "version": "1.0.0-next.46",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  import {expect, test} from 'bun:test'
2
2
  import type {GathererStats} from '../types/capabilities'
3
- import {calc_gather_energy} from './gathering'
3
+ import {calc_gather_duration, calc_gather_energy} from './gathering'
4
4
 
5
5
  function gatherer(drain: number): GathererStats {
6
6
  return {
@@ -14,3 +14,16 @@ test('calc_gather_energy does not clamp above the old uint16 ceiling', () => {
14
14
  const energy = calc_gather_energy(gatherer(30), 400_000_000)
15
15
  expect(Number(energy)).toBeGreaterThan(65535)
16
16
  })
17
+
18
+ test('splitting a bulk gather never undercuts total lane-time', () => {
19
+ const g: GathererStats = {
20
+ yield: {toNumber: () => 413},
21
+ drain: {toNumber: () => 30},
22
+ depth: {toNumber: () => 0, toString: () => '0'},
23
+ }
24
+ const bulk = Number(calc_gather_duration(g, 1000, 10, 8, 500))
25
+ const unit = Number(calc_gather_duration(g, 1000, 1, 8, 500))
26
+ // d1 >= 1 regime (bulk > quantity), where the split exploit lived
27
+ expect(bulk).toBeGreaterThan(10)
28
+ expect(unit * 10).toBeGreaterThanOrEqual(bulk)
29
+ })
@@ -30,9 +30,9 @@ export function calc_gather_duration(
30
30
  stratum: number,
31
31
  richness: number
32
32
  ): UInt32 {
33
- return UInt32.from(
34
- Math.floor(gather_duration_raw(gatherer, itemMass, quantity, stratum, richness))
35
- )
33
+ const raw = gather_duration_raw(gatherer, itemMass, quantity, stratum, richness)
34
+ // +1 per-gather setup cost mirrors the contract: splitting a bulk gather must not undercut lane-time
35
+ return UInt32.from(raw <= 0 ? 0 : Math.floor(raw) + 1)
36
36
  }
37
37
 
38
38
  export function calc_gather_rate(
@@ -48,6 +48,7 @@ export function calc_gather_rate(
48
48
  }
49
49
 
50
50
  export function calc_gather_energy(gatherer: GathererStats, duration: number): UInt32 {
51
- const energy = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
52
- return UInt32.from(energy)
51
+ if (duration <= 0) return UInt32.from(0)
52
+ const raw = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
53
+ return UInt32.from(Math.min(Math.max(raw, 1), 4294967295))
53
54
  }
@@ -3,8 +3,10 @@ import {
3
3
  ITEM_CRAFTER_T1,
4
4
  ITEM_ENGINE_T1,
5
5
  ITEM_GATHERER_T1,
6
+ ITEM_GATHERER_T2,
6
7
  ITEM_GENERATOR_T1,
7
8
  ITEM_HAULER_T1,
9
+ ITEM_HAULER_T2,
8
10
  ITEM_LAUNCHER_T1,
9
11
  ITEM_LOADER_T1,
10
12
  ITEM_STORAGE_T1,
@@ -44,6 +46,7 @@ export function getModuleCapabilityType(itemId: number): number {
44
46
  case ITEM_GENERATOR_T1:
45
47
  return MODULE_GENERATOR
46
48
  case ITEM_GATHERER_T1:
49
+ case ITEM_GATHERER_T2:
47
50
  return MODULE_GATHERER
48
51
  case ITEM_LOADER_T1:
49
52
  return MODULE_LOADER
@@ -52,6 +55,7 @@ export function getModuleCapabilityType(itemId: number): number {
52
55
  case ITEM_STORAGE_T1:
53
56
  return MODULE_STORAGE
54
57
  case ITEM_HAULER_T1:
58
+ case ITEM_HAULER_T2:
55
59
  return MODULE_HAULER
56
60
  case ITEM_WARP_T1:
57
61
  return MODULE_WARP