@shipload/sdk 1.0.0-next.7 → 1.0.0-next.71

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 (203) hide show
  1. package/lib/scan.d.ts +52 -0
  2. package/lib/scan.js +162 -0
  3. package/lib/scan.js.map +1 -0
  4. package/lib/scan.m.js +152 -0
  5. package/lib/scan.m.js.map +1 -0
  6. package/lib/shipload.d.ts +5822 -1484
  7. package/lib/shipload.js +20838 -5419
  8. package/lib/shipload.js.map +1 -1
  9. package/lib/shipload.m.js +20674 -5669
  10. package/lib/shipload.m.js.map +1 -1
  11. package/lib/testing.d.ts +1691 -0
  12. package/lib/testing.js +7109 -0
  13. package/lib/testing.js.map +1 -0
  14. package/lib/testing.m.js +7103 -0
  15. package/lib/testing.m.js.map +1 -0
  16. package/package.json +20 -2
  17. package/src/capabilities/craftable.test.ts +82 -0
  18. package/src/capabilities/craftable.ts +82 -0
  19. package/src/capabilities/crafting.test.ts +80 -0
  20. package/src/capabilities/crafting.ts +50 -8
  21. package/src/capabilities/gathering.test.ts +29 -0
  22. package/src/capabilities/gathering.ts +38 -20
  23. package/src/capabilities/hauling.ts +0 -5
  24. package/src/capabilities/index.ts +0 -1
  25. package/src/capabilities/modules.ts +27 -30
  26. package/src/capabilities/movement.ts +1 -1
  27. package/src/capabilities/storage.test.ts +26 -0
  28. package/src/capabilities/storage.ts +22 -7
  29. package/src/contracts/fund.ts +306 -0
  30. package/src/contracts/platform.ts +312 -3
  31. package/src/contracts/server.ts +2793 -478
  32. package/src/contracts/token.ts +170 -0
  33. package/src/contracts.ts +2 -0
  34. package/src/coordinates/address.ts +88 -0
  35. package/src/coordinates/constants.test.ts +15 -0
  36. package/src/coordinates/constants.ts +23 -0
  37. package/src/coordinates/index.ts +15 -0
  38. package/src/coordinates/memo.test.ts +47 -0
  39. package/src/coordinates/memo.ts +20 -0
  40. package/src/coordinates/permutation.ts +77 -0
  41. package/src/coordinates/regions.ts +48 -0
  42. package/src/coordinates/sectors.ts +115 -0
  43. package/src/data/capabilities.ts +49 -18
  44. package/src/data/capability-formulas.ts +26 -14
  45. package/src/data/catalog.test.ts +19 -0
  46. package/src/data/catalog.ts +13 -3
  47. package/src/data/charters.json +396 -0
  48. package/src/data/citizenry-adjectives.json +42 -0
  49. package/src/data/citizenry-nouns.json +50 -0
  50. package/src/data/colors.ts +14 -32
  51. package/src/data/entities.json +421 -15
  52. package/src/data/item-ids.ts +53 -13
  53. package/src/data/items.json +330 -77
  54. package/src/data/kind-registry.json +212 -0
  55. package/src/data/kind-registry.ts +192 -0
  56. package/src/data/metadata.ts +312 -51
  57. package/src/data/recipes-runtime.ts +6 -23
  58. package/src/data/recipes.json +2173 -173
  59. package/src/data/tiers.ts +9 -6
  60. package/src/derivation/build-methods.test.ts +71 -0
  61. package/src/derivation/build-methods.ts +50 -0
  62. package/src/derivation/capabilities.test.ts +348 -0
  63. package/src/derivation/capabilities.ts +707 -0
  64. package/src/derivation/capability-mappings.ts +60 -16
  65. package/src/derivation/crafting.test.ts +17 -0
  66. package/src/derivation/crafting.ts +57 -34
  67. package/src/derivation/index.ts +27 -2
  68. package/src/derivation/recipe-usage.test.ts +88 -0
  69. package/src/derivation/recipe-usage.ts +141 -0
  70. package/src/derivation/reserve-regen.ts +34 -0
  71. package/src/derivation/resources.ts +9 -1
  72. package/src/derivation/rollups.test.ts +55 -0
  73. package/src/derivation/rollups.ts +72 -0
  74. package/src/derivation/stars.test.ts +67 -0
  75. package/src/derivation/stars.ts +25 -0
  76. package/src/derivation/stat-scaling.ts +12 -0
  77. package/src/derivation/stats.ts +6 -6
  78. package/src/derivation/strata.ts +5 -3
  79. package/src/derivation/stratum.ts +26 -22
  80. package/src/derivation/tiers.ts +40 -7
  81. package/src/derivation/upgrades.ts +14 -0
  82. package/src/derivation/wormhole.ts +154 -0
  83. package/src/entities/entity.ts +102 -0
  84. package/src/entities/gamestate.ts +3 -28
  85. package/src/entities/makers.ts +144 -136
  86. package/src/entities/slot-multiplier.ts +43 -0
  87. package/src/entity/hydrate.test.ts +156 -0
  88. package/src/entity/hydrate.ts +86 -0
  89. package/src/errors.ts +21 -16
  90. package/src/format.ts +42 -9
  91. package/src/index-module.ts +425 -32
  92. package/src/influence/ballot.test.ts +103 -0
  93. package/src/influence/ballot.ts +98 -0
  94. package/src/influence/categories.ts +32 -0
  95. package/src/influence/charter-metadata.test.ts +136 -0
  96. package/src/influence/charter-metadata.ts +236 -0
  97. package/src/influence/charters.test.ts +112 -0
  98. package/src/influence/charters.ts +150 -0
  99. package/src/influence/citizenry.ts +38 -0
  100. package/src/influence/civic-shuttle.test.ts +202 -0
  101. package/src/influence/civic-shuttle.ts +142 -0
  102. package/src/influence/civic.test.ts +287 -0
  103. package/src/influence/civic.ts +269 -0
  104. package/src/influence/constants.ts +84 -0
  105. package/src/influence/decay.ts +20 -0
  106. package/src/influence/decomp.ts +95 -0
  107. package/src/influence/demand.ts +106 -0
  108. package/src/influence/duration.ts +101 -0
  109. package/src/influence/index.ts +118 -0
  110. package/src/influence/influence.test.ts +450 -0
  111. package/src/influence/quality.ts +25 -0
  112. package/src/influence/valuation.ts +154 -0
  113. package/src/managers/actions.ts +950 -93
  114. package/src/managers/balances.test.ts +161 -0
  115. package/src/managers/balances.ts +93 -0
  116. package/src/managers/base.ts +10 -2
  117. package/src/managers/cluster.test.ts +39 -0
  118. package/src/managers/cluster.ts +53 -0
  119. package/src/managers/construction-types.ts +80 -0
  120. package/src/managers/construction.ts +453 -0
  121. package/src/managers/context.ts +58 -1
  122. package/src/managers/coordinates.ts +14 -0
  123. package/src/managers/entities.ts +35 -63
  124. package/src/managers/epochs.ts +72 -1
  125. package/src/managers/index.ts +38 -1
  126. package/src/managers/influence.test.ts +56 -0
  127. package/src/managers/influence.ts +425 -0
  128. package/src/managers/jobs.test.ts +96 -0
  129. package/src/managers/jobs.ts +58 -0
  130. package/src/managers/locations.ts +25 -29
  131. package/src/managers/nft.test.ts +21 -0
  132. package/src/managers/nft.ts +110 -0
  133. package/src/managers/players.ts +25 -0
  134. package/src/managers/plot.ts +122 -0
  135. package/src/nft/atomicassets.abi.json +1342 -0
  136. package/src/nft/atomicassets.ts +237 -0
  137. package/src/nft/atomicdata.ts +130 -0
  138. package/src/nft/buildImmutableData.ts +388 -0
  139. package/src/nft/description.ts +222 -100
  140. package/src/nft/index.ts +3 -0
  141. package/src/planner/index.ts +296 -0
  142. package/src/planner/planner.test.ts +459 -0
  143. package/src/receipts.ts +22 -0
  144. package/src/resolution/describe-module.ts +43 -25
  145. package/src/resolution/display-name.ts +39 -11
  146. package/src/resolution/resolve-item.test.ts +48 -0
  147. package/src/resolution/resolve-item.ts +112 -58
  148. package/src/scan/index.ts +244 -0
  149. package/src/scan/scan-wasm.base64.ts +2 -0
  150. package/src/scheduling/accessor.ts +65 -23
  151. package/src/scheduling/availability.test.ts +320 -0
  152. package/src/scheduling/availability.ts +251 -0
  153. package/src/scheduling/cancel.test.ts +550 -0
  154. package/src/scheduling/cancel.ts +254 -0
  155. package/src/scheduling/cluster-stock.test.ts +31 -0
  156. package/src/scheduling/cluster-stock.ts +15 -0
  157. package/src/scheduling/energy.ts +47 -0
  158. package/src/scheduling/epoch.ts +1 -0
  159. package/src/scheduling/idle-resolve.ts +45 -0
  160. package/src/scheduling/jobs.test.ts +448 -0
  161. package/src/scheduling/jobs.ts +343 -0
  162. package/src/scheduling/lane-core.ts +128 -0
  163. package/src/scheduling/lanes.test.ts +250 -0
  164. package/src/scheduling/lanes.ts +279 -0
  165. package/src/scheduling/projection.ts +265 -149
  166. package/src/scheduling/schedule.test.ts +163 -0
  167. package/src/scheduling/schedule.ts +282 -116
  168. package/src/scheduling/task-cargo.test.ts +110 -0
  169. package/src/scheduling/task-cargo.ts +62 -0
  170. package/src/scheduling/task-effects.test.ts +35 -0
  171. package/src/scheduling/task-effects.ts +34 -0
  172. package/src/scheduling/unwrap.test.ts +86 -0
  173. package/src/scheduling/unwrap.ts +190 -0
  174. package/src/shipload.ts +63 -4
  175. package/src/subscriptions/manager.cluster.test.ts +51 -0
  176. package/src/subscriptions/manager.ts +245 -172
  177. package/src/subscriptions/mappers.ts +5 -8
  178. package/src/subscriptions/types.ts +28 -3
  179. package/src/testing/catalog-hash.ts +19 -0
  180. package/src/testing/index.ts +2 -0
  181. package/src/testing/projection-parity.ts +167 -0
  182. package/src/travel/reach.test.ts +86 -0
  183. package/src/travel/reach.ts +34 -0
  184. package/src/travel/route-build.test.ts +63 -0
  185. package/src/travel/route-build.ts +60 -0
  186. package/src/travel/route-planner.ts +288 -0
  187. package/src/travel/route-simulator.ts +170 -0
  188. package/src/travel/travel.ts +190 -123
  189. package/src/types/capabilities.ts +37 -8
  190. package/src/types/entity.ts +3 -3
  191. package/src/types/index.ts +0 -1
  192. package/src/types.ts +81 -23
  193. package/src/utils/cargo.test.ts +14 -0
  194. package/src/utils/cargo.ts +2 -0
  195. package/src/utils/display-name.ts +70 -0
  196. package/src/utils/hash.ts +22 -2
  197. package/src/utils/system.ts +24 -5
  198. package/src/capabilities/loading.ts +0 -8
  199. package/src/entities/container.ts +0 -123
  200. package/src/entities/ship-deploy.ts +0 -295
  201. package/src/entities/ship.ts +0 -221
  202. package/src/entities/warehouse.ts +0 -127
  203. package/src/types/entity-traits.ts +0 -69
@@ -1,97 +1,69 @@
1
1
  import {Name, type NameType, type UInt64Type} from '@wharfkit/antelope'
2
2
  import {BaseManager} from './base'
3
- import {Ship} from '../entities/ship'
4
- import {Warehouse} from '../entities/warehouse'
5
- import {Container} from '../entities/container'
3
+ import {Entity} from '../entities/entity'
4
+ import type {EntityTypeName} from '../data/kind-registry'
6
5
  import type {ServerContract} from '../contracts'
7
6
 
8
- export type EntityType = 'ship' | 'warehouse' | 'container' | 'location'
7
+ export type {EntityTypeName} from '../data/kind-registry'
9
8
 
10
9
  export class EntitiesManager extends BaseManager {
11
- async getEntity(type: EntityType, id: UInt64Type): Promise<Ship | Warehouse | Container> {
10
+ async getEntity(id: UInt64Type): Promise<Entity> {
12
11
  const result = await this.server.readonly('getentity', {
13
- entity_type: Name.from(type),
14
12
  entity_id: id,
15
13
  })
16
- const entityInfo = result as ServerContract.Types.entity_info
17
- return this.wrapEntity(entityInfo)
14
+ return new Entity(result as ServerContract.Types.entity_info)
15
+ }
16
+
17
+ async getProjection(id: UInt64Type, taskCount?: number): Promise<unknown> {
18
+ return this.server.readonly('getprojstate', {
19
+ entity_id: id,
20
+ task_count: taskCount,
21
+ })
18
22
  }
19
23
 
20
24
  async getEntities(
21
25
  owner: NameType | ServerContract.Types.player_row,
22
- type?: EntityType
23
- ): Promise<(Ship | Warehouse | Container)[]> {
26
+ kind?: EntityTypeName
27
+ ): Promise<Entity[]> {
24
28
  const ownerName = this.resolveOwner(owner)
25
29
  const result = await this.server.readonly('getentities', {
26
30
  owner: ownerName,
27
- entity_type: type ? Name.from(type) : null,
31
+ entity_type: kind,
28
32
  })
29
33
  const entities = result as ServerContract.Types.entity_info[]
30
- return entities.map((entity) => this.wrapEntity(entity))
34
+ return entities.map((e) => new Entity(e))
35
+ }
36
+
37
+ async getAllEntities(kind?: EntityTypeName): Promise<ServerContract.Types.entity_row[]> {
38
+ const rows = await this.server.table('entity').all()
39
+ if (!kind) {
40
+ return rows
41
+ }
42
+ const wanted = Name.from(kind)
43
+ return rows.filter((row) => wanted.equals(row.kind))
31
44
  }
32
45
 
33
46
  async getSummaries(
34
47
  owner: NameType | ServerContract.Types.player_row,
35
- type?: EntityType
48
+ kind?: EntityTypeName
36
49
  ): Promise<ServerContract.Types.entity_summary[]> {
37
50
  const ownerName = this.resolveOwner(owner)
38
51
  const result = await this.server.readonly('getsummaries', {
39
52
  owner: ownerName,
40
- entity_type: type ? Name.from(type) : null,
53
+ entity_type: kind,
41
54
  })
42
55
  return result as ServerContract.Types.entity_summary[]
43
56
  }
44
57
 
45
- async getShip(id: UInt64Type): Promise<Ship> {
46
- return (await this.getEntity('ship', id)) as Ship
47
- }
48
-
49
- async getWarehouse(id: UInt64Type): Promise<Warehouse> {
50
- return (await this.getEntity('warehouse', id)) as Warehouse
51
- }
52
-
53
- async getContainer(id: UInt64Type): Promise<Container> {
54
- return (await this.getEntity('container', id)) as Container
55
- }
56
-
57
- async getShips(owner: NameType | ServerContract.Types.player_row): Promise<Ship[]> {
58
- return (await this.getEntities(owner, 'ship')) as Ship[]
59
- }
60
-
61
- async getWarehouses(owner: NameType | ServerContract.Types.player_row): Promise<Warehouse[]> {
62
- return (await this.getEntities(owner, 'warehouse')) as Warehouse[]
63
- }
64
-
65
- async getContainers(owner: NameType | ServerContract.Types.player_row): Promise<Container[]> {
66
- return (await this.getEntities(owner, 'container')) as Container[]
67
- }
68
-
69
- async getShipSummaries(
70
- owner: NameType | ServerContract.Types.player_row
71
- ): Promise<ServerContract.Types.entity_summary[]> {
72
- return this.getSummaries(owner, 'ship')
73
- }
74
-
75
- async getWarehouseSummaries(
76
- owner: NameType | ServerContract.Types.player_row
77
- ): Promise<ServerContract.Types.entity_summary[]> {
78
- return this.getSummaries(owner, 'warehouse')
79
- }
80
-
81
- async getContainerSummaries(
58
+ async getDepot(
59
+ depotId: UInt64Type,
82
60
  owner: NameType | ServerContract.Types.player_row
83
- ): Promise<ServerContract.Types.entity_summary[]> {
84
- return this.getSummaries(owner, 'container')
85
- }
86
-
87
- private wrapEntity(entity: ServerContract.Types.entity_info): Ship | Warehouse | Container {
88
- if (entity.type.equals('ship')) {
89
- return new Ship(entity)
90
- } else if (entity.type.equals('warehouse')) {
91
- return new Warehouse(entity)
92
- } else {
93
- return new Container(entity)
94
- }
61
+ ): Promise<ServerContract.Types.depot_view> {
62
+ const result = await this.server.readonly('getdepot', {
63
+ depot_id: depotId,
64
+ owner: this.resolveOwner(owner),
65
+ })
66
+ return result as ServerContract.Types.depot_view
95
67
  }
96
68
 
97
69
  private resolveOwner(owner: NameType | ServerContract.Types.player_row): Name {
@@ -1,6 +1,16 @@
1
- import {UInt64, type UInt64Type} from '@wharfkit/antelope'
1
+ import {Checksum256, UInt64, type UInt64Type} from '@wharfkit/antelope'
2
2
  import {BaseManager} from './base'
3
3
  import {type EpochInfo, getCurrentEpoch, getEpochInfo} from '../scheduling/epoch'
4
+ import type {ServerContract} from '../contracts'
5
+
6
+ export const DEFAULT_EPOCH_DEADLINE = 10800
7
+
8
+ const EMPTY_SEED = Checksum256.from('0'.repeat(64))
9
+
10
+ export interface EpochQuorumState {
11
+ threshold: number
12
+ finalized: boolean
13
+ }
4
14
 
5
15
  export class EpochsManager extends BaseManager {
6
16
  async getCurrentHeight(): Promise<UInt64> {
@@ -8,6 +18,11 @@ export class EpochsManager extends BaseManager {
8
18
  return getCurrentEpoch(game)
9
19
  }
10
20
 
21
+ async getFinalizedEpoch(reload = false): Promise<UInt64> {
22
+ const state = await this.getState(reload)
23
+ return state.currentEpoch
24
+ }
25
+
11
26
  async getCurrent(): Promise<EpochInfo> {
12
27
  const game = await this.getGame()
13
28
  const epoch = await this.getCurrentHeight()
@@ -44,4 +59,60 @@ export class EpochsManager extends BaseManager {
44
59
  const remaining = await this.getTimeRemaining()
45
60
  return durationMs <= remaining
46
61
  }
62
+
63
+ async getEpochRow(epoch: UInt64Type): Promise<ServerContract.Types.epoch_row | undefined> {
64
+ const target = UInt64.from(epoch)
65
+ return this.server.table('epoch').get(target)
66
+ }
67
+
68
+ async getEpochState(epoch: UInt64Type): Promise<EpochQuorumState> {
69
+ const row = await this.getEpochRow(epoch)
70
+ if (!row) return {threshold: 0, finalized: false}
71
+ return {threshold: Number(row.threshold), finalized: !row.seed.equals(EMPTY_SEED)}
72
+ }
73
+
74
+ async getActiveEpochInfo(): Promise<ServerContract.Types.epoch_row | undefined> {
75
+ const rows = await this.server.table('epoch').all()
76
+ if (rows.length === 0) {
77
+ return undefined
78
+ }
79
+ return rows[rows.length - 1]
80
+ }
81
+
82
+ async getOracles(): Promise<ServerContract.Types.oracle_row[]> {
83
+ return this.server.table('oracles').all()
84
+ }
85
+
86
+ async getThreshold(): Promise<number> {
87
+ const cfg = await this.server.table('oraclecfg').get()
88
+ return cfg ? Number(cfg.threshold) : 0
89
+ }
90
+
91
+ async getDeadline(): Promise<number> {
92
+ const cfg = await this.server.table('oraclecfg').get()
93
+ return cfg ? Number(cfg.deadline) : DEFAULT_EPOCH_DEADLINE
94
+ }
95
+
96
+ async getCloseDueAt(epoch: UInt64Type): Promise<Date> {
97
+ const info = await this.getByHeight(epoch)
98
+ const deadline = await this.getDeadline()
99
+ return new Date(info.start.getTime() + deadline * 1000)
100
+ }
101
+
102
+ async getSecondsUntilClose(epoch: UInt64Type): Promise<number> {
103
+ const dueAt = await this.getCloseDueAt(epoch)
104
+ return Math.ceil((dueAt.getTime() - Date.now()) / 1000)
105
+ }
106
+
107
+ async getCommitsFor(epoch: UInt64Type): Promise<ServerContract.Types.commit_row[]> {
108
+ const target = UInt64.from(epoch)
109
+ const rows = await this.server.table('commit').all()
110
+ return rows.filter((r) => r.epoch.equals(target))
111
+ }
112
+
113
+ async getRevealsFor(epoch: UInt64Type): Promise<ServerContract.Types.reveal_row[]> {
114
+ const target = UInt64.from(epoch)
115
+ const rows = await this.server.table('reveal').all()
116
+ return rows.filter((r) => r.epoch.equals(target))
117
+ }
47
118
  }
@@ -1,9 +1,46 @@
1
1
  export {GameContext} from './context'
2
2
  export {BaseManager} from './base'
3
3
  export {EntitiesManager} from './entities'
4
- export type {EntityType} from './entities'
4
+ export type {EntityTypeName} from './entities'
5
5
  export {PlayersManager} from './players'
6
+ export type {PlayerRosterEntry} from './players'
6
7
  export {LocationsManager} from './locations'
7
8
  export type {LocationStratum} from './locations'
8
9
  export {EpochsManager} from './epochs'
9
10
  export {ActionsManager} from './actions'
11
+ export {ClusterManager, computeFreeCells} from './cluster'
12
+ export type {GridCell, ClusterCell, Cluster} from './cluster'
13
+ export {NftManager} from './nft'
14
+ export type {NftConfigForItem, WrapConfig, WrapGate} from './nft'
15
+ export {BalancesManager} from './balances'
16
+ export type {DepositConfig, PlatformBalance, TokenBalance} from './balances'
17
+ export {JobsManager} from './jobs'
18
+ export {InfluenceManager} from './influence'
19
+ export type {
20
+ CharterProgress,
21
+ ContributePreview,
22
+ ContributePreviewRow,
23
+ FoundedWorld,
24
+ FoundedWorldRef,
25
+ InfluenceStanding,
26
+ Ballot,
27
+ BallotVote,
28
+ NodeProgress,
29
+ QueuedSeat,
30
+ VoteOption,
31
+ VoteStandings,
32
+ } from './influence'
33
+ export {PlotManager} from './plot'
34
+ export type {PlotProgress, PlotProgressInputRow} from './plot'
35
+ export {ConstructionManager} from './construction'
36
+ export type {
37
+ BuildableTarget,
38
+ BuildState,
39
+ SourceEntityRef,
40
+ SourceCargoStack,
41
+ FinalizerEntityRef,
42
+ FinalizerCapability,
43
+ InboundTransfer,
44
+ ScheduledBuild,
45
+ Reservation,
46
+ } from './construction-types'
@@ -0,0 +1,56 @@
1
+ import {describe, expect, it} from 'bun:test'
2
+ import {Name, UInt64} from '@wharfkit/antelope'
3
+ import {InfluenceManager} from './influence'
4
+ import {coordsToLocationId} from '../types'
5
+
6
+ const LOCATION = {x: 12, y: 34}
7
+
8
+ function managerWith(rowsByTable: Record<string, unknown[]>) {
9
+ const calls: {table: string; scope: unknown}[] = []
10
+ const table = (name: string, scope: unknown) => {
11
+ calls.push({table: name, scope})
12
+ return {all: async () => rowsByTable[name] ?? []}
13
+ }
14
+ const ctx = {server: {table}} as never
15
+ return {manager: new InfluenceManager(ctx), calls}
16
+ }
17
+
18
+ describe('InfluenceManager scoped table reads', () => {
19
+ it('getBallotVotes scopes ballotpicks by ballot id and maps fields', async () => {
20
+ const {manager, calls} = managerWith({
21
+ ballotpicks: [{account: Name.from('eggmaple.gm'), picks: [2, 1]}],
22
+ })
23
+ const rows = await manager.getBallotVotes(7n)
24
+ expect(calls).toHaveLength(1)
25
+ expect(calls[0].table).toBe('ballotpicks')
26
+ expect(UInt64.from(calls[0].scope as never).equals(UInt64.from(7))).toBe(true)
27
+ expect(rows).toEqual([{account: Name.from('eggmaple.gm'), picks: [2, 1]}])
28
+ })
29
+
30
+ it('getBuiltCharters scopes mandates by location and maps fields', async () => {
31
+ const {manager, calls} = managerWith({
32
+ mandates: [{node_id: 1, repeats: 2}],
33
+ })
34
+ const rows = await manager.getBuiltCharters(LOCATION)
35
+ expect(calls[0].table).toBe('mandates')
36
+ expect(UInt64.from(calls[0].scope as never).equals(coordsToLocationId(LOCATION))).toBe(true)
37
+ expect(rows).toEqual([{nodeId: 1, repeats: 2}])
38
+ })
39
+
40
+ it('getBuildings scopes buildings by location and maps fields', async () => {
41
+ const {manager, calls} = managerWith({
42
+ buildings: [{entity_id: '9001', building: 3}],
43
+ })
44
+ const rows = await manager.getBuildings(LOCATION)
45
+ expect(calls[0].table).toBe('buildings')
46
+ expect(UInt64.from(calls[0].scope as never).equals(coordsToLocationId(LOCATION))).toBe(true)
47
+ expect(rows).toEqual([{entityId: 9001n, building: 3}])
48
+ })
49
+
50
+ it('returns an empty array when the scope has no rows', async () => {
51
+ const {manager} = managerWith({})
52
+ expect(await manager.getBallotVotes(7n)).toEqual([])
53
+ expect(await manager.getBuiltCharters(LOCATION)).toEqual([])
54
+ expect(await manager.getBuildings(LOCATION)).toEqual([])
55
+ })
56
+ })