@latticexyz/store-indexer 2.0.0-next.8 → 2.0.0-skystrife-playtest-f0f9ff56
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/store-indexer",
|
3
|
-
"version": "2.0.0-
|
3
|
+
"version": "2.0.0-skystrife-playtest-f0f9ff56",
|
4
4
|
"description": "Minimal Typescript indexer for Store",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -27,10 +27,10 @@
|
|
27
27
|
"superjson": "^1.12.4",
|
28
28
|
"viem": "1.6.0",
|
29
29
|
"zod": "^3.21.4",
|
30
|
-
"@latticexyz/block-logs-stream": "2.0.0-
|
31
|
-
"@latticexyz/common": "2.0.0-
|
32
|
-
"@latticexyz/store": "2.0.0-
|
33
|
-
"@latticexyz/store-sync": "2.0.0-
|
30
|
+
"@latticexyz/block-logs-stream": "2.0.0-skystrife-playtest-f0f9ff56",
|
31
|
+
"@latticexyz/common": "2.0.0-skystrife-playtest-f0f9ff56",
|
32
|
+
"@latticexyz/store": "2.0.0-skystrife-playtest-f0f9ff56",
|
33
|
+
"@latticexyz/store-sync": "2.0.0-skystrife-playtest-f0f9ff56"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
36
|
"@types/better-sqlite3": "^7.6.4",
|
@@ -13,11 +13,11 @@ import { getAddress } from "viem";
|
|
13
13
|
*/
|
14
14
|
export async function createQueryAdapter(database: PgDatabase<any>): Promise<QueryAdapter> {
|
15
15
|
const adapter: QueryAdapter = {
|
16
|
-
async findAll(chainId, address) {
|
16
|
+
async findAll({ chainId, address, tableIds }) {
|
17
17
|
const internalTables = buildInternalTables();
|
18
|
-
const tables = (await getTables(database))
|
19
|
-
(table) => address
|
20
|
-
|
18
|
+
const tables = (await getTables(database))
|
19
|
+
.filter((table) => address == null || getAddress(address) === getAddress(table.address))
|
20
|
+
.filter((table) => tableIds == null || tableIds.includes(table.tableId));
|
21
21
|
|
22
22
|
const tablesWithRecords = await Promise.all(
|
23
23
|
tables.map(async (table) => {
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { eq } from "drizzle-orm";
|
1
|
+
import { eq, inArray, and } from "drizzle-orm";
|
2
2
|
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core";
|
3
3
|
import { createSqliteTable, chainState, getTables } from "@latticexyz/store-sync/sqlite";
|
4
4
|
import { QueryAdapter } from "@latticexyz/store-sync/trpc-indexer";
|
5
5
|
import { debug } from "../debug";
|
6
|
+
import { Hex, getAddress } from "viem";
|
6
7
|
|
7
8
|
/**
|
8
9
|
* Creates a storage adapter for the tRPC server/client to query data from SQLite.
|
@@ -12,12 +13,51 @@ import { debug } from "../debug";
|
|
12
13
|
*/
|
13
14
|
export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", any>): Promise<QueryAdapter> {
|
14
15
|
const adapter: QueryAdapter = {
|
15
|
-
async findAll(chainId, address) {
|
16
|
-
const tables = getTables(database)
|
16
|
+
async findAll({ chainId, address, tableIds, matchId }) {
|
17
|
+
const tables = getTables(database)
|
18
|
+
.filter((table) => address == null || getAddress(address) === getAddress(table.address))
|
19
|
+
.filter((table) => tableIds == null || tableIds.includes(table.tableId))
|
20
|
+
.filter((table) =>
|
21
|
+
// we don't need KeysWithValue tables
|
22
|
+
matchId != null ? table.namespace !== "keyswval" : true
|
23
|
+
);
|
24
|
+
|
25
|
+
const entities = ((): Hex[] => {
|
26
|
+
if (!address || !matchId) return [];
|
27
|
+
try {
|
28
|
+
const Position = createSqliteTable({
|
29
|
+
address,
|
30
|
+
namespace: "",
|
31
|
+
name: "Position",
|
32
|
+
keySchema: { key: "bytes32" },
|
33
|
+
valueSchema: {
|
34
|
+
x: "int32",
|
35
|
+
y: "int32",
|
36
|
+
z: "int32",
|
37
|
+
},
|
38
|
+
});
|
39
|
+
const positions = database.select().from(Position).where(eq(Position.z, matchId)).all();
|
40
|
+
return positions.map((pos) => pos.key);
|
41
|
+
} catch (error: unknown) {
|
42
|
+
return [];
|
43
|
+
}
|
44
|
+
})();
|
17
45
|
|
18
46
|
const tablesWithRecords = tables.map((table) => {
|
19
47
|
const sqliteTable = createSqliteTable(table);
|
20
|
-
const records = database
|
48
|
+
const records = database
|
49
|
+
.select()
|
50
|
+
.from(sqliteTable)
|
51
|
+
.where(
|
52
|
+
and(
|
53
|
+
eq(sqliteTable.__isDeleted, false),
|
54
|
+
entities.length &&
|
55
|
+
(table.name === "MoveDifficulty" || table.name === "TerrainType") /* || table.name === "ArmorModifier"*/
|
56
|
+
? inArray(sqliteTable.__key, entities)
|
57
|
+
: undefined
|
58
|
+
)
|
59
|
+
)
|
60
|
+
.all();
|
21
61
|
return {
|
22
62
|
...table,
|
23
63
|
records: records.map((record) => ({
|
@@ -35,7 +75,19 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an
|
|
35
75
|
tables: tablesWithRecords,
|
36
76
|
};
|
37
77
|
|
38
|
-
|
78
|
+
const count = tablesWithRecords.reduce((sum, table) => sum + table.records.length, 0);
|
79
|
+
|
80
|
+
debug(
|
81
|
+
"findAll",
|
82
|
+
"chainId:",
|
83
|
+
chainId,
|
84
|
+
"address:",
|
85
|
+
address,
|
86
|
+
"tables:",
|
87
|
+
tablesWithRecords.length,
|
88
|
+
"records:",
|
89
|
+
count
|
90
|
+
);
|
39
91
|
|
40
92
|
return result;
|
41
93
|
},
|