@latticexyz/store-indexer 2.0.0-main-b5540716 → 2.0.0-main-301bcb75

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.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{a as d,b}from"../chunk-3RNAK5YX.js";import"dotenv/config";import{z as T}from"zod";import{DefaultLogger as U,eq as v}from"drizzle-orm";import{createPublicClient as x,fallback as D,webSocket as E,http as I}from"viem";import j from"fastify";import{fastifyTRPCPlugin as Q}from"@trpc/server/adapters/fastify";import{createAppRouter as q}from"@latticexyz/store-sync/trpc-indexer";import{eq as g}from"drizzle-orm";import{buildTable as B,buildInternalTables as O,getTables as N}from"@latticexyz/store-sync/postgres";import{getAddress as h}from"viem";async function A(r){return{async findAll(l,s){let m=O(),S=(await N(r)).filter(o=>s!=null&&h(s)===h(o.address)),_=await Promise.all(S.map(async o=>{let u=B(o),L=await r.select().from(u).where(g(u.__isDeleted,!1)).execute();return{...o,records:L.map(f=>({key:Object.fromEntries(Object.entries(o.keySchema).map(([a])=>[a,f[a]])),value:Object.fromEntries(Object.entries(o.valueSchema).map(([a])=>[a,f[a]]))}))}})),k=await r.select().from(m.chain).where(g(m.chain.chainId,l)).execute(),{lastUpdatedBlockNumber:C}=k[0]??{},p={blockNumber:C??null,tables:_};return d("findAll",l,s,p),p}}}import{isDefined as H}from"@latticexyz/common/utils";import{combineLatest as V,filter as $,first as z}from"rxjs";import{drizzle as W}from"drizzle-orm/postgres-js";import G from"postgres";import{cleanDatabase as K,postgresStorage as M,schemaVersion as R}from"@latticexyz/store-sync/postgres";import{createStoreSync as X}from"@latticexyz/store-sync";var e=b(T.object({DATABASE_URL:T.string()})),F=[e.RPC_WS_URL?E(e.RPC_WS_URL):void 0,e.RPC_HTTP_URL?I(e.RPC_HTTP_URL):void 0].filter(H),i=x({transport:D(F),pollingInterval:e.POLLING_INTERVAL}),J=await i.getChainId(),n=W(G(e.DATABASE_URL),{logger:new U}),{storageAdapter:Y,internalTables:y}=await M({database:n,publicClient:i}),w=e.START_BLOCK;try{let t=(await n.select().from(y.chain).where(v(y.chain.chainId,J)).execute())[0];t!=null&&(t.schemaVersion!=R?(console.log("schema version changed from",t.schemaVersion,"to",R,"cleaning database"),await K(n)):t.lastUpdatedBlockNumber!=null&&(console.log("resuming from block number",t.lastUpdatedBlockNumber+1n),w=t.lastUpdatedBlockNumber+1n))}catch{}var{latestBlockNumber$:Z,storedBlockLogs$:P}=await X({storageAdapter:Y,publicClient:i,startBlock:w,maxBlockRange:e.MAX_BLOCK_RANGE});P.subscribe();V([Z,P]).pipe($(([r,{blockNumber:t}])=>r===t),z()).subscribe(()=>{console.log("all caught up")});var c=j({maxParamLength:5e3});await c.register(import("@fastify/cors"));c.register(Q,{prefix:"/trpc",trpcOptions:{router:q(),createContext:async()=>({queryAdapter:await A(n)})}});await c.listen({host:e.HOST,port:e.PORT});console.log(`indexer server listening on http://${e.HOST}:${e.PORT}`);
2
+ import{a as d,b}from"../chunk-X3OEYQLT.js";import"dotenv/config";import{z as T}from"zod";import{DefaultLogger as U,eq as v}from"drizzle-orm";import{createPublicClient as x,fallback as D,webSocket as E,http as I}from"viem";import j from"fastify";import{fastifyTRPCPlugin as Q}from"@trpc/server/adapters/fastify";import{createAppRouter as q}from"@latticexyz/store-sync/trpc-indexer";import{eq as g}from"drizzle-orm";import{buildTable as B,buildInternalTables as O,getTables as N}from"@latticexyz/store-sync/postgres";import{getAddress as h}from"viem";async function A(r){return{async findAll(l,s){let m=O(),S=(await N(r)).filter(o=>s!=null&&h(s)===h(o.address)),_=await Promise.all(S.map(async o=>{let u=B(o),L=await r.select().from(u).where(g(u.__isDeleted,!1)).execute();return{...o,records:L.map(f=>({key:Object.fromEntries(Object.entries(o.keySchema).map(([a])=>[a,f[a]])),value:Object.fromEntries(Object.entries(o.valueSchema).map(([a])=>[a,f[a]]))}))}})),k=await r.select().from(m.chain).where(g(m.chain.chainId,l)).execute(),{lastUpdatedBlockNumber:C}=k[0]??{},p={blockNumber:C??null,tables:_};return d("findAll",l,s,p),p}}}import{isDefined as H}from"@latticexyz/common/utils";import{combineLatest as V,filter as $,first as z}from"rxjs";import{drizzle as W}from"drizzle-orm/postgres-js";import G from"postgres";import{cleanDatabase as K,postgresStorage as M,schemaVersion as R}from"@latticexyz/store-sync/postgres";import{createStoreSync as X}from"@latticexyz/store-sync";var e=b(T.object({DATABASE_URL:T.string()})),F=[e.RPC_WS_URL?E(e.RPC_WS_URL):void 0,e.RPC_HTTP_URL?I(e.RPC_HTTP_URL):void 0].filter(H),i=x({transport:D(F),pollingInterval:e.POLLING_INTERVAL}),J=await i.getChainId(),n=W(G(e.DATABASE_URL),{logger:new U}),{storageAdapter:Y,internalTables:y}=await M({database:n,publicClient:i}),w=e.START_BLOCK;try{let t=(await n.select().from(y.chain).where(v(y.chain.chainId,J)).execute())[0];t!=null&&(t.schemaVersion!=R?(console.log("schema version changed from",t.schemaVersion,"to",R,"cleaning database"),await K(n)):t.lastUpdatedBlockNumber!=null&&(console.log("resuming from block number",t.lastUpdatedBlockNumber+1n),w=t.lastUpdatedBlockNumber+1n))}catch{}var{latestBlockNumber$:Z,storedBlockLogs$:P}=await X({storageAdapter:Y,publicClient:i,startBlock:w,maxBlockRange:e.MAX_BLOCK_RANGE});P.subscribe();V([Z,P]).pipe($(([r,{blockNumber:t}])=>r===t),z()).subscribe(()=>{console.log("all caught up")});var c=j({maxParamLength:5e3});await c.register(import("@fastify/cors"));c.register(Q,{prefix:"/trpc",trpcOptions:{router:q(),createContext:async()=>({queryAdapter:await A(n)})}});await c.listen({host:e.HOST,port:e.PORT});console.log(`indexer server listening on http://${e.HOST}:${e.PORT}`);
3
3
  //# sourceMappingURL=postgres-indexer.js.map
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{a as f,b as u}from"../chunk-3RNAK5YX.js";import"dotenv/config";import P from"node:fs";import{z as S}from"zod";import{eq as N}from"drizzle-orm";import{drizzle as B}from"drizzle-orm/better-sqlite3";import I from"better-sqlite3";import{createPublicClient as O,fallback as w,webSocket as Q,http as v}from"viem";import U from"fastify";import{fastifyTRPCPlugin as x}from"@trpc/server/adapters/fastify";import{createAppRouter as j}from"@latticexyz/store-sync/trpc-indexer";import{chainState as T,schemaVersion as g,syncToSqlite as q}from"@latticexyz/store-sync/sqlite";import{eq as d}from"drizzle-orm";import{buildTable as C,chainState as b,getTables as E}from"@latticexyz/store-sync/sqlite";async function h(r){return{async findAll(i,c){let R=E(r).filter(o=>o.address===c).map(o=>{let m=C(o),k=r.select().from(m).where(d(m.__isDeleted,!1)).all();return{...o,records:k.map(p=>({key:Object.fromEntries(Object.entries(o.keySchema).map(([a])=>[a,p[a]])),value:Object.fromEntries(Object.entries(o.valueSchema).map(([a])=>[a,p[a]]))}))}}),A=r.select().from(b).where(d(b.chainId,i)).all(),{lastUpdatedBlockNumber:_}=A[0]??{},l={blockNumber:_??null,tables:R};return f("findAll",i,c,l),l}}}import{isDefined as D}from"@latticexyz/common/utils";import{combineLatest as H,filter as M,first as V}from"rxjs";var e=u(S.object({SQLITE_FILENAME:S.string().default("indexer.db")})),$=[e.RPC_WS_URL?Q(e.RPC_WS_URL):void 0,e.RPC_HTTP_URL?v(e.RPC_HTTP_URL):void 0].filter(D),L=O({transport:w($),pollingInterval:e.POLLING_INTERVAL}),z=await L.getChainId(),n=B(new I(e.SQLITE_FILENAME)),y=e.START_BLOCK;try{let t=n.select().from(T).where(N(T.chainId,z)).all()[0];t!=null&&(t.schemaVersion!=g?(console.log("schema version changed from",t.schemaVersion,"to",g,"recreating database"),P.truncateSync(e.SQLITE_FILENAME)):t.lastUpdatedBlockNumber!=null&&(console.log("resuming from block number",t.lastUpdatedBlockNumber+1n),y=t.lastUpdatedBlockNumber+1n))}catch{}var{latestBlockNumber$:F,storedBlockLogs$:W}=await q({database:n,publicClient:L,startBlock:y,maxBlockRange:e.MAX_BLOCK_RANGE});H([F,W]).pipe(M(([r,{blockNumber:t}])=>r===t),V()).subscribe(()=>{console.log("all caught up")});var s=U({maxParamLength:5e3});await s.register(import("@fastify/cors"));s.register(x,{prefix:"/trpc",trpcOptions:{router:j(),createContext:async()=>({queryAdapter:await h(n)})}});await s.listen({host:e.HOST,port:e.PORT});console.log(`indexer server listening on http://${e.HOST}:${e.PORT}`);
2
+ import{a as f,b as u}from"../chunk-X3OEYQLT.js";import"dotenv/config";import P from"node:fs";import{z as S}from"zod";import{eq as N}from"drizzle-orm";import{drizzle as B}from"drizzle-orm/better-sqlite3";import I from"better-sqlite3";import{createPublicClient as O,fallback as w,webSocket as Q,http as v}from"viem";import U from"fastify";import{fastifyTRPCPlugin as x}from"@trpc/server/adapters/fastify";import{createAppRouter as j}from"@latticexyz/store-sync/trpc-indexer";import{chainState as T,schemaVersion as g,syncToSqlite as q}from"@latticexyz/store-sync/sqlite";import{eq as d}from"drizzle-orm";import{buildTable as C,chainState as b,getTables as E}from"@latticexyz/store-sync/sqlite";async function h(r){return{async findAll(i,c){let R=E(r).filter(o=>o.address===c).map(o=>{let m=C(o),k=r.select().from(m).where(d(m.__isDeleted,!1)).all();return{...o,records:k.map(p=>({key:Object.fromEntries(Object.entries(o.keySchema).map(([a])=>[a,p[a]])),value:Object.fromEntries(Object.entries(o.valueSchema).map(([a])=>[a,p[a]]))}))}}),A=r.select().from(b).where(d(b.chainId,i)).all(),{lastUpdatedBlockNumber:_}=A[0]??{},l={blockNumber:_??null,tables:R};return f("findAll",i,c,l),l}}}import{isDefined as D}from"@latticexyz/common/utils";import{combineLatest as H,filter as M,first as V}from"rxjs";var e=u(S.object({SQLITE_FILENAME:S.string().default("indexer.db")})),$=[e.RPC_WS_URL?Q(e.RPC_WS_URL):void 0,e.RPC_HTTP_URL?v(e.RPC_HTTP_URL):void 0].filter(D),L=O({transport:w($),pollingInterval:e.POLLING_INTERVAL}),z=await L.getChainId(),n=B(new I(e.SQLITE_FILENAME)),y=e.START_BLOCK;try{let t=n.select().from(T).where(N(T.chainId,z)).all()[0];t!=null&&(t.schemaVersion!=g?(console.log("schema version changed from",t.schemaVersion,"to",g,"recreating database"),P.truncateSync(e.SQLITE_FILENAME)):t.lastUpdatedBlockNumber!=null&&(console.log("resuming from block number",t.lastUpdatedBlockNumber+1n),y=t.lastUpdatedBlockNumber+1n))}catch{}var{latestBlockNumber$:F,storedBlockLogs$:W}=await q({database:n,publicClient:L,startBlock:y,maxBlockRange:e.MAX_BLOCK_RANGE});H([F,W]).pipe(M(([r,{blockNumber:t}])=>r===t),V()).subscribe(()=>{console.log("all caught up")});var s=U({maxParamLength:5e3});await s.register(import("@fastify/cors"));s.register(x,{prefix:"/trpc",trpcOptions:{router:j(),createContext:async()=>({queryAdapter:await h(n)})}});await s.listen({host:e.HOST,port:e.PORT});console.log(`indexer server listening on http://${e.HOST}:${e.PORT}`);
3
3
  //# sourceMappingURL=sqlite-indexer.js.map
@@ -0,0 +1,7 @@
1
+ import{z as e,ZodError as c}from"zod";var t=e.intersection(e.object({HOST:e.string().default("0.0.0.0"),PORT:e.coerce.number().positive().default(3001),START_BLOCK:e.coerce.bigint().nonnegative().default(0n),MAX_BLOCK_RANGE:e.coerce.bigint().positive().default(1000n),POLLING_INTERVAL:e.coerce.number().positive().default(1e3)}),e.union([e.object({RPC_HTTP_URL:e.string(),RPC_WS_URL:e.string().optional()}),e.object({RPC_HTTP_URL:e.string().optional(),RPC_WS_URL:e.string()})]));function f(o){let r=o!==void 0?e.intersection(t,o):t;try{return r.parse(process.env)}catch(n){if(n instanceof c){let{_errors:a,...i}=n.format();console.error(`
2
+ Missing or invalid environment variables:
3
+
4
+ ${Object.keys(i).join(`
5
+ `)}
6
+ `),process.exit(1)}throw n}}import s from"debug";var _=s("mud:store-indexer");export{_ as a,f as b};
7
+ //# sourceMappingURL=chunk-X3OEYQLT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../bin/parseEnv.ts","../src/debug.ts"],"sourcesContent":["import { z, ZodError, ZodIntersection, ZodTypeAny } from \"zod\";\n\nconst commonSchema = z.intersection(\n z.object({\n HOST: z.string().default(\"0.0.0.0\"),\n PORT: z.coerce.number().positive().default(3001),\n START_BLOCK: z.coerce.bigint().nonnegative().default(0n),\n MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),\n POLLING_INTERVAL: z.coerce.number().positive().default(1000),\n }),\n z.union([\n z.object({\n RPC_HTTP_URL: z.string(),\n RPC_WS_URL: z.string().optional(),\n }),\n z.object({\n RPC_HTTP_URL: z.string().optional(),\n RPC_WS_URL: z.string(),\n }),\n ])\n);\n\nexport function parseEnv<TSchema extends ZodTypeAny | undefined = undefined>(\n schema?: TSchema\n): z.infer<TSchema extends ZodTypeAny ? ZodIntersection<typeof commonSchema, TSchema> : typeof commonSchema> {\n const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema;\n try {\n return envSchema.parse(process.env);\n } catch (error) {\n if (error instanceof ZodError) {\n const { _errors, ...invalidEnvVars } = error.format();\n console.error(`\\nMissing or invalid environment variables:\\n\\n ${Object.keys(invalidEnvVars).join(\"\\n \")}\\n`);\n process.exit(1);\n }\n throw error;\n }\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:store-indexer\");\n"],"mappings":"AAAA,OAAS,KAAAA,EAAG,YAAAC,MAA6C,MAEzD,IAAMC,EAAeF,EAAE,aACrBA,EAAE,OAAO,CACP,KAAMA,EAAE,OAAO,EAAE,QAAQ,SAAS,EAClC,KAAMA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,EAC/C,YAAaA,EAAE,OAAO,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,EACvD,gBAAiBA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,KAAK,EAC3D,iBAAkBA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,GAAI,CAC7D,CAAC,EACDA,EAAE,MAAM,CACNA,EAAE,OAAO,CACP,aAAcA,EAAE,OAAO,EACvB,WAAYA,EAAE,OAAO,EAAE,SAAS,CAClC,CAAC,EACDA,EAAE,OAAO,CACP,aAAcA,EAAE,OAAO,EAAE,SAAS,EAClC,WAAYA,EAAE,OAAO,CACvB,CAAC,CACH,CAAC,CACH,EAEO,SAASG,EACdC,EAC2G,CAC3G,IAAMC,EAAYD,IAAW,OAAYJ,EAAE,aAAaE,EAAcE,CAAM,EAAIF,EAChF,GAAI,CACF,OAAOG,EAAU,MAAM,QAAQ,GAAG,CACpC,OAASC,EAAP,CACA,GAAIA,aAAiBL,EAAU,CAC7B,GAAM,CAAE,QAAAM,EAAS,GAAGC,CAAe,EAAIF,EAAM,OAAO,EACpD,QAAQ,MAAM;AAAA;AAAA;AAAA,IAAoD,OAAO,KAAKE,CAAc,EAAE,KAAK;AAAA,GAAM;AAAA,CAAK,EAC9G,QAAQ,KAAK,CAAC,EAEhB,MAAMF,CACR,CACF,CCpCA,OAAOG,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,mBAAmB","names":["z","ZodError","commonSchema","parseEnv","schema","envSchema","error","_errors","invalidEnvVars","createDebug","debug"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/store-indexer",
3
- "version": "2.0.0-main-b5540716",
3
+ "version": "2.0.0-main-301bcb75",
4
4
  "description": "Minimal Typescript indexer for Store",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,10 +32,10 @@
32
32
  "superjson": "^1.12.4",
33
33
  "viem": "1.6.0",
34
34
  "zod": "^3.21.4",
35
- "@latticexyz/block-logs-stream": "2.0.0-main-b5540716",
36
- "@latticexyz/common": "2.0.0-main-b5540716",
37
- "@latticexyz/store": "2.0.0-main-b5540716",
38
- "@latticexyz/store-sync": "2.0.0-main-b5540716"
35
+ "@latticexyz/block-logs-stream": "2.0.0-main-301bcb75",
36
+ "@latticexyz/common": "2.0.0-main-301bcb75",
37
+ "@latticexyz/store": "2.0.0-main-301bcb75",
38
+ "@latticexyz/store-sync": "2.0.0-main-301bcb75"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/better-sqlite3": "^7.6.4",
@@ -1,2 +0,0 @@
1
- import{isDefined as i}from"@latticexyz/common/utils";import{z as e}from"zod";var o=e.intersection(e.object({HOST:e.string().default("0.0.0.0"),PORT:e.coerce.number().positive().default(3001),START_BLOCK:e.coerce.bigint().nonnegative().default(0n),MAX_BLOCK_RANGE:e.coerce.bigint().positive().default(1000n),POLLING_INTERVAL:e.coerce.number().positive().default(1e3)}),e.object({RPC_HTTP_URL:e.string(),RPC_WS_URL:e.string()}).partial().refine(n=>Object.values(n).some(i)));function p(n){return(n!==void 0?e.intersection(o,n):o).parse(process.env,{errorMap:t=>({message:`Missing or invalid environment variable: ${t.path.join(".")}`})})}import r from"debug";var T=r("mud:store-indexer");export{T as a,p as b};
2
- //# sourceMappingURL=chunk-3RNAK5YX.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../bin/parseEnv.ts","../src/debug.ts"],"sourcesContent":["import { isDefined } from \"@latticexyz/common/utils\";\nimport { z, ZodIntersection, ZodTypeAny } from \"zod\";\n\nconst commonSchema = z.intersection(\n z.object({\n HOST: z.string().default(\"0.0.0.0\"),\n PORT: z.coerce.number().positive().default(3001),\n START_BLOCK: z.coerce.bigint().nonnegative().default(0n),\n MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),\n POLLING_INTERVAL: z.coerce.number().positive().default(1000),\n }),\n z\n .object({\n RPC_HTTP_URL: z.string(),\n RPC_WS_URL: z.string(),\n })\n .partial()\n .refine((values) => Object.values(values).some(isDefined))\n);\n\nexport function parseEnv<TSchema extends ZodTypeAny | undefined = undefined>(\n schema?: TSchema\n): z.infer<TSchema extends ZodTypeAny ? ZodIntersection<typeof commonSchema, TSchema> : typeof commonSchema> {\n const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema;\n return envSchema.parse(process.env, {\n errorMap: (issue) => ({\n message: `Missing or invalid environment variable: ${issue.path.join(\".\")}`,\n }),\n });\n}\n","import createDebug from \"debug\";\n\nexport const debug = createDebug(\"mud:store-indexer\");\n"],"mappings":"AAAA,OAAS,aAAAA,MAAiB,2BAC1B,OAAS,KAAAC,MAAsC,MAE/C,IAAMC,EAAeD,EAAE,aACrBA,EAAE,OAAO,CACP,KAAMA,EAAE,OAAO,EAAE,QAAQ,SAAS,EAClC,KAAMA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,EAC/C,YAAaA,EAAE,OAAO,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,EACvD,gBAAiBA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,KAAK,EAC3D,iBAAkBA,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,QAAQ,GAAI,CAC7D,CAAC,EACDA,EACG,OAAO,CACN,aAAcA,EAAE,OAAO,EACvB,WAAYA,EAAE,OAAO,CACvB,CAAC,EACA,QAAQ,EACR,OAAQE,GAAW,OAAO,OAAOA,CAAM,EAAE,KAAKH,CAAS,CAAC,CAC7D,EAEO,SAASI,EACdC,EAC2G,CAE3G,OADkBA,IAAW,OAAYJ,EAAE,aAAaC,EAAcG,CAAM,EAAIH,GAC/D,MAAM,QAAQ,IAAK,CAClC,SAAWI,IAAW,CACpB,QAAS,4CAA4CA,EAAM,KAAK,KAAK,GAAG,GAC1E,EACF,CAAC,CACH,CC7BA,OAAOC,MAAiB,QAEjB,IAAMC,EAAQD,EAAY,mBAAmB","names":["isDefined","z","commonSchema","values","parseEnv","schema","issue","createDebug","debug"]}