@shipload/sdk 1.0.0-next.74 → 1.0.0-next.76

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 (56) hide show
  1. package/lib/scan.js +1 -1
  2. package/lib/scan.js.map +1 -1
  3. package/lib/scan.m.js +1 -1
  4. package/lib/scan.m.js.map +1 -1
  5. package/lib/shipload.d.ts +81 -35
  6. package/lib/shipload.js +13576 -11311
  7. package/lib/shipload.js.map +1 -1
  8. package/lib/shipload.m.js +13554 -11311
  9. package/lib/shipload.m.js.map +1 -1
  10. package/lib/testing.d.ts +20 -16
  11. package/lib/testing.js +229 -53
  12. package/lib/testing.js.map +1 -1
  13. package/lib/testing.m.js +229 -53
  14. package/lib/testing.m.js.map +1 -1
  15. package/package.json +6 -6
  16. package/src/capabilities/storage.ts +45 -10
  17. package/src/contracts/server.ts +49 -41
  18. package/src/data/component-process.test.ts +119 -0
  19. package/src/data/component-process.ts +33 -0
  20. package/src/data/entities.json +367 -2
  21. package/src/data/item-ids.ts +15 -0
  22. package/src/data/items.json +90 -0
  23. package/src/data/kind-registry.json +97 -7
  24. package/src/data/metadata.ts +83 -5
  25. package/src/data/recipes-runtime.ts +1 -1
  26. package/src/data/recipes.json +1476 -10
  27. package/src/data/task-types.json +9 -0
  28. package/src/derivation/capabilities.test.ts +25 -2
  29. package/src/derivation/capabilities.ts +16 -3
  30. package/src/derivation/capacity-fn-registry.ts +8 -1
  31. package/src/derivation/reserve-regen.ts +5 -9
  32. package/src/derivation/stratum.ts +1 -1
  33. package/src/derivation/tiers.ts +1 -1
  34. package/src/derivation/upgrades.ts +5 -4
  35. package/src/index-module.ts +10 -1
  36. package/src/influence/influence.test.ts +1 -1
  37. package/src/managers/actions.ts +12 -19
  38. package/src/managers/entities.test.ts +23 -0
  39. package/src/managers/entities.ts +8 -1
  40. package/src/managers/shuttle.test.ts +67 -0
  41. package/src/managers/shuttle.ts +17 -0
  42. package/src/nft/description.ts +6 -0
  43. package/src/resolution/resolve-item.test.ts +6 -6
  44. package/src/resolution/resolve-item.ts +4 -0
  45. package/src/scan/scan-wasm.base64.ts +1 -1
  46. package/src/scheduling/availability.test.ts +3 -3
  47. package/src/scheduling/availability.ts +3 -4
  48. package/src/scheduling/lanes.ts +1 -1
  49. package/src/scheduling/projection.ts +15 -13
  50. package/src/scheduling/schedule.test.ts +24 -0
  51. package/src/scheduling/schedule.ts +11 -4
  52. package/src/scheduling/task-effects.ts +3 -1
  53. package/src/scheduling/unwrap.test.ts +25 -6
  54. package/src/scheduling/unwrap.ts +19 -3
  55. package/src/travel/travel.ts +4 -0
  56. package/src/types.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.74",
4
+ "version": "1.0.0-next.76",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -42,9 +42,9 @@
42
42
  "test": "make test"
43
43
  },
44
44
  "dependencies": {
45
- "@wharfkit/antelope": "1.2.0",
46
- "@wharfkit/common": "1.5.0",
47
- "@wharfkit/contract": "1.3.0",
45
+ "@wharfkit/antelope": "4.0.2",
46
+ "@wharfkit/common": "4.0.2",
47
+ "@wharfkit/contract": "4.0.2",
48
48
  "tslib": "^2.1.0"
49
49
  },
50
50
  "devDependencies": {
@@ -60,8 +60,8 @@
60
60
  "@types/bun": "latest",
61
61
  "@types/chai": "^4.3.1",
62
62
  "@types/node": "^18.7.18",
63
- "@wharfkit/mock-data": "^1.3.0",
64
- "@wharfkit/wallet-plugin-privatekey": "^1.1.0",
63
+ "@wharfkit/mock-data": "^4.0.2",
64
+ "@wharfkit/wallet-plugin-privatekey": "^4.0.2",
65
65
  "chai": "^4.3.4",
66
66
  "gh-pages": "^4.0.0",
67
67
  "node-fetch": "^2.6.1",
@@ -23,17 +23,15 @@ interface MassInput {
23
23
  }
24
24
 
25
25
  export function calcCargoItemMass(item: MassInput): UInt64 {
26
- const itemDef = getItem(item.item_id)
27
- let mass = UInt64.from(itemDef.mass).multiplying(item.quantity)
26
+ let unitMass = UInt64.from(getItem(item.item_id).mass)
28
27
 
29
28
  for (const mod of item.modules) {
30
29
  if (mod.installed) {
31
- const modDef = getItem(mod.installed.item_id)
32
- mass = mass.adding(UInt64.from(modDef.mass))
30
+ unitMass = unitMass.adding(UInt64.from(getItem(mod.installed.item_id).mass))
33
31
  }
34
32
  }
35
33
 
36
- return mass
34
+ return unitMass.multiplying(item.quantity)
37
35
  }
38
36
 
39
37
  export function calcCargoMass(entity: HasCargo): UInt64 {
@@ -91,14 +89,17 @@ export interface CargoStack {
91
89
  quantity: UInt32
92
90
  stats: UInt64
93
91
  modules: ServerContract.Types.module_entry[]
92
+ entity_id?: UInt64
94
93
  }
95
94
 
96
95
  export function cargoItemToStack(item: ServerContract.Types.cargo_item): CargoStack {
96
+ const identity = cargoIdentity(item.entity_id)
97
97
  return {
98
98
  item_id: UInt16.from(item.item_id),
99
99
  quantity: UInt32.from(item.quantity),
100
100
  stats: UInt64.from(item.stats),
101
101
  modules: item.modules ?? [],
102
+ ...(identity ? {entity_id: identity} : {}),
102
103
  }
103
104
  }
104
105
 
@@ -108,19 +109,50 @@ export function stackToCargoItem(stack: CargoStack): ServerContract.Types.cargo_
108
109
  quantity: stack.quantity,
109
110
  stats: stack.stats,
110
111
  modules: stack.modules,
112
+ entity_id: stack.entity_id,
111
113
  })
112
114
  }
113
115
 
114
- function statsEquals(a: UInt64, b: UInt64): boolean {
115
- return a.equals(b)
116
+ function cargoIdentity(id: UInt64Type | undefined): UInt64 | undefined {
117
+ if (id === undefined || id === null) return undefined
118
+ const value = UInt64.from(id)
119
+ return value.equals(UInt64.from(0)) ? undefined : value
120
+ }
121
+
122
+ export function cargoModulesEquiv(
123
+ a: readonly ServerContract.Types.module_entry[],
124
+ b: readonly ServerContract.Types.module_entry[]
125
+ ): boolean {
126
+ const n = Math.max(a.length, b.length)
127
+ for (let i = 0; i < n; i++) {
128
+ const ia = a[i]?.installed
129
+ const ib = b[i]?.installed
130
+ if (!ia !== !ib) return false
131
+ if (ia && ib && !(ia.item_id.equals(ib.item_id) && ia.stats.equals(ib.stats))) return false
132
+ }
133
+ return true
116
134
  }
117
135
 
118
- function stackIdentityEqual(a: CargoStack, b: CargoStack): boolean {
119
- return a.item_id.equals(b.item_id) && statsEquals(a.stats, b.stats)
136
+ function identityEquals(a: UInt64 | undefined, b: UInt64 | undefined): boolean {
137
+ return (a ?? UInt64.from(0)).equals(b ?? UInt64.from(0))
138
+ }
139
+
140
+ export function stackIdentityEqual(a: CargoStack, b: CargoStack): boolean {
141
+ return (
142
+ a.item_id.equals(b.item_id) &&
143
+ a.stats.equals(b.stats) &&
144
+ cargoModulesEquiv(a.modules, b.modules) &&
145
+ identityEquals(a.entity_id, b.entity_id)
146
+ )
120
147
  }
121
148
 
122
149
  export function stackKey(s: CargoStack): string {
123
- return `${s.item_id.toNumber()}:${s.stats.toString()}`
150
+ const installed = s.modules
151
+ .map((m, i) => (m.installed ? `${i}=${m.installed.item_id}.${m.installed.stats}` : ''))
152
+ .filter((part) => part !== '')
153
+ const modulesPart = installed.length > 0 ? `:${installed.join(',')}` : ''
154
+ const identityPart = s.entity_id ? `#${s.entity_id.toString()}` : ''
155
+ return `${s.item_id.toNumber()}:${s.stats.toString()}${modulesPart}${identityPart}`
124
156
  }
125
157
 
126
158
  export function stacksEqual(a: CargoStack, b: CargoStack): boolean {
@@ -128,6 +160,9 @@ export function stacksEqual(a: CargoStack, b: CargoStack): boolean {
128
160
  }
129
161
 
130
162
  export function mergeStacks(stacks: CargoStack[], add: CargoStack): CargoStack[] {
163
+ if (add.entity_id) {
164
+ return [...stacks, {...add}]
165
+ }
131
166
  const idx = stacks.findIndex((s) => stackIdentityEqual(s, add))
132
167
  if (idx === -1) {
133
168
  return [...stacks, {...add}]