bomb-panic-sdk 0.1.11 → 0.1.12
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/dist/read.js +17 -11
- package/package.json +1 -1
package/dist/read.js
CHANGED
|
@@ -52,7 +52,6 @@ export async function getLobbyRoomGamePairs(client, lobbyId, limit = 50) {
|
|
|
52
52
|
if (!hasFields(fields)) {
|
|
53
53
|
throw new Error('Invalid lobby fields structure');
|
|
54
54
|
}
|
|
55
|
-
// After hasFields check, we know fields is an object
|
|
56
55
|
const roomToGame = fields.room_to_game;
|
|
57
56
|
if (!hasFields(roomToGame)) {
|
|
58
57
|
throw new Error('Invalid room_to_game structure');
|
|
@@ -69,30 +68,37 @@ export async function getLobbyRoomGamePairs(client, lobbyId, limit = 50) {
|
|
|
69
68
|
if (typeof roomToGameTableId !== 'string') {
|
|
70
69
|
throw new Error('Lobby room_to_game table not found');
|
|
71
70
|
}
|
|
71
|
+
// Step 1: Get all dynamic field entries (includes objectId for each)
|
|
72
72
|
const roomEntries = await client.getDynamicFields({
|
|
73
73
|
parentId: roomToGameTableId,
|
|
74
74
|
limit,
|
|
75
75
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
if (roomEntries.data.length === 0) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
// ✅ OPTIMIZED: Use objectId from getDynamicFields result
|
|
80
|
+
// Each dynamic field entry already has objectId - no need for getDynamicFieldObject
|
|
81
|
+
const objectIds = roomEntries.data.map(entry => entry.objectId);
|
|
82
|
+
// Step 2: Batch fetch ALL field objects in ONE call
|
|
83
|
+
const fieldObjects = await client.multiGetObjects({
|
|
84
|
+
ids: objectIds,
|
|
85
|
+
options: { showContent: true },
|
|
86
|
+
});
|
|
87
|
+
// Step 3: Parse results
|
|
88
|
+
const pairs = roomEntries.data.map((entry, index) => {
|
|
89
|
+
const fieldContent = fieldObjects[index]?.data?.content;
|
|
83
90
|
let gameStateId = null;
|
|
84
91
|
if (fieldContent && fieldContent.dataType === 'moveObject') {
|
|
85
92
|
const fieldFields = fieldContent.fields;
|
|
86
93
|
if (hasFields(fieldFields)) {
|
|
87
|
-
// After hasFields check, we know fieldFields is an object
|
|
88
94
|
const value = fieldFields.value;
|
|
89
95
|
if (typeof value === 'string') {
|
|
90
96
|
gameStateId = value;
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
100
|
+
return { roomId: entry.name.value, gameStateId };
|
|
101
|
+
});
|
|
96
102
|
return pairs;
|
|
97
103
|
}
|
|
98
104
|
export async function getRooms(client, roomIds) {
|