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

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 (47) hide show
  1. package/lib/shipload.d.ts +576 -133
  2. package/lib/shipload.js +6019 -5114
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +6002 -5108
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +194 -52
  7. package/lib/testing.js +767 -468
  8. package/lib/testing.js.map +1 -1
  9. package/lib/testing.m.js +767 -468
  10. package/lib/testing.m.js.map +1 -1
  11. package/package.json +1 -1
  12. package/src/contracts/server.ts +523 -143
  13. package/src/data/catalog.test.ts +81 -1
  14. package/src/data/catalog.ts +6 -4
  15. package/src/data/entities.json +2 -2
  16. package/src/data/metadata.ts +197 -363
  17. package/src/data/task-types.json +184 -0
  18. package/src/entities/makers.ts +2 -2
  19. package/src/index-module.ts +31 -2
  20. package/src/influence/civic-shuttle.test.ts +58 -0
  21. package/src/influence/civic-shuttle.ts +52 -6
  22. package/src/influence/duration.ts +0 -65
  23. package/src/influence/index.ts +4 -5
  24. package/src/influence/influence.test.ts +51 -136
  25. package/src/influence/valuation.ts +75 -0
  26. package/src/managers/actions.ts +49 -10
  27. package/src/managers/balances.test.ts +33 -0
  28. package/src/managers/balances.ts +15 -0
  29. package/src/managers/context.ts +50 -11
  30. package/src/managers/index.ts +14 -0
  31. package/src/managers/jobs.test.ts +82 -1
  32. package/src/managers/jobs.ts +41 -2
  33. package/src/managers/nft.test.ts +173 -1
  34. package/src/managers/nft.ts +35 -2
  35. package/src/managers/shuttle.test.ts +562 -0
  36. package/src/managers/shuttle.ts +397 -0
  37. package/src/resolution/resolve-item.ts +2 -2
  38. package/src/scheduling/availability.ts +10 -0
  39. package/src/scheduling/energy.ts +55 -1
  40. package/src/scheduling/jobs.test.ts +171 -1
  41. package/src/scheduling/jobs.ts +110 -13
  42. package/src/scheduling/projection.ts +2 -1
  43. package/src/scheduling/task-effects.ts +38 -0
  44. package/src/scheduling/unwrap.test.ts +60 -0
  45. package/src/scheduling/unwrap.ts +24 -8
  46. package/src/shipload.ts +23 -4
  47. package/src/types.ts +1 -0
@@ -1,5 +1,8 @@
1
1
  import {describe, expect, test} from 'bun:test'
2
- import {getItems, itemTypeIndex, typeLabel} from './catalog'
2
+ import {getComponents, getItem, getItems, itemTypeIndex, typeLabel} from './catalog'
3
+ import {getRecipe} from './recipes-runtime'
4
+ import items from './items.json'
5
+ import {itemFamilies, itemFamilyKey} from './metadata'
3
6
 
4
7
  describe('itemTypeIndex', () => {
5
8
  test('agrees with typeLabel for every item in the catalog', () => {
@@ -17,3 +20,80 @@ describe('itemTypeIndex', () => {
17
20
  expect(() => itemTypeIndex(65535)).toThrow()
18
21
  })
19
22
  })
23
+
24
+ const catalogItems = () => (items as Array<{id: number}>).map((raw) => getItem(raw.id))
25
+
26
+ describe('item families', () => {
27
+ test('every item resolves to a family that carries its name', () => {
28
+ for (const item of catalogItems()) {
29
+ expect(itemFamilies[item.family]?.name).toBe(item.name)
30
+ }
31
+ })
32
+
33
+ test('every tier of a family shares one name, description, and colour', () => {
34
+ const seen = new Map<string, {name: string; description: string; color: string}>()
35
+ for (const item of catalogItems()) {
36
+ const prior = seen.get(item.family)
37
+ if (prior) {
38
+ expect({
39
+ name: item.name,
40
+ description: item.description,
41
+ color: item.color,
42
+ }).toEqual(prior)
43
+ } else {
44
+ seen.set(item.family, {
45
+ name: item.name,
46
+ description: item.description,
47
+ color: item.color,
48
+ })
49
+ }
50
+ }
51
+ })
52
+
53
+ test('every family is reachable from at least one item id', () => {
54
+ const reachable = new Set(catalogItems().map((item) => item.family))
55
+ for (const id of [10202, 10203, 10204, 10207]) reachable.add(itemFamilyKey(id)!)
56
+ expect([...Object.keys(itemFamilies)].filter((key) => !reachable.has(key))).toEqual([])
57
+ })
58
+
59
+ test('descriptions never name a tier', () => {
60
+ for (const [key, family] of Object.entries(itemFamilies)) {
61
+ expect(`${key}: ${family.description}`).not.toMatch(/\btier\b|\bT\d\b/i)
62
+ }
63
+ })
64
+ })
65
+
66
+ describe('component descriptions', () => {
67
+ test('name only items that a recipe actually builds from the component', () => {
68
+ const consumers = new Map<string, Set<string>>()
69
+ for (const output of getItems()) {
70
+ const recipe = getRecipe(output.id)
71
+ if (!recipe) continue
72
+ for (const input of recipe.inputs) {
73
+ const inputItem = getItem(input.itemId)
74
+ if (inputItem.type !== 'component') continue
75
+ if (!consumers.has(inputItem.family)) consumers.set(inputItem.family, new Set())
76
+ consumers
77
+ .get(inputItem.family)!
78
+ .add(
79
+ output.type === 'entity' && output.family !== 'container'
80
+ ? 'hulls'
81
+ : output.name
82
+ )
83
+ }
84
+ }
85
+ for (const item of getComponents({tier: 1})) {
86
+ const named = item.description
87
+ .replace(/^Goes into /, '')
88
+ .replace(/\.$/, '')
89
+ .split(/, and |, | and /)
90
+ .map((name) => name.replace(/s$/, ''))
91
+ for (const name of named) {
92
+ const plain = name === 'hull' ? 'hulls' : name
93
+ expect(consumers.get(item.family)?.has(plain), `${item.name} -> ${plain}`).toBe(
94
+ true
95
+ )
96
+ }
97
+ }
98
+ })
99
+ })
@@ -1,6 +1,6 @@
1
1
  import {UInt16, type UInt16Type} from '@wharfkit/antelope'
2
2
  import items from './items.json'
3
- import {itemMetadata} from './metadata'
3
+ import {getItemFamily, itemFamilyKey} from './metadata'
4
4
  import {
5
5
  CATEGORY_LABELS,
6
6
  type Item,
@@ -12,12 +12,14 @@ import {
12
12
  const itemsById = new Map<number, Item>()
13
13
 
14
14
  for (const raw of items as any[]) {
15
- const meta = itemMetadata[raw.id]
16
- if (!meta) {
17
- throw new Error(`Missing metadata for item ${raw.id}. Add an entry to metadata.ts.`)
15
+ const family = itemFamilyKey(raw.id)
16
+ const meta = getItemFamily(raw.id)
17
+ if (!family || !meta) {
18
+ throw new Error(`Missing family for item ${raw.id}. Add an entry to metadata.ts.`)
18
19
  }
19
20
  itemsById.set(raw.id, {
20
21
  id: raw.id,
22
+ family,
21
23
  name: meta.name,
22
24
  description: meta.description,
23
25
  color: meta.color,
@@ -108,12 +108,12 @@
108
108
  "slots": [
109
109
  {
110
110
  "type": "builder",
111
- "outputPct": 200,
111
+ "outputPct": 75,
112
112
  "maxTier": 1
113
113
  },
114
114
  {
115
115
  "type": "builder",
116
- "outputPct": 200,
116
+ "outputPct": 75,
117
117
  "maxTier": 1
118
118
  }
119
119
  ],