{"id":24958308,"url":"https://github.com/dk1a/mud-table-idxs","last_synced_at":"2025-04-15T13:55:23.023Z","repository":{"id":275136179,"uuid":"904213157","full_name":"dk1a/mud-table-idxs","owner":"dk1a","description":"Onchain table indexes for MUD tables","archived":false,"fork":false,"pushed_at":"2025-04-02T09:04:07.000Z","size":452,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T13:55:07.598Z","etag":null,"topics":["autonomous-worlds","ethereum","evm","solidity"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dk1a.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-16T13:10:49.000Z","updated_at":"2025-04-03T03:10:24.000Z","dependencies_parsed_at":"2025-03-21T15:16:14.488Z","dependency_job_id":null,"html_url":"https://github.com/dk1a/mud-table-idxs","commit_stats":null,"previous_names":["dk1a/mud-table-idxs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk1a%2Fmud-table-idxs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk1a%2Fmud-table-idxs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk1a%2Fmud-table-idxs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dk1a%2Fmud-table-idxs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dk1a","download_url":"https://codeload.github.com/dk1a/mud-table-idxs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085481,"owners_count":21210267,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autonomous-worlds","ethereum","evm","solidity"],"created_at":"2025-02-03T07:10:52.913Z","updated_at":"2025-04-15T13:55:23.008Z","avatar_url":"https://github.com/dk1a.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"WIP, everything is subject to change\n\nThis is a package used on top of [MUD](https://github.com/latticexyz/mud) to create onchain indexes (think sql table indexes, basic or unique) for MUD tables.\n\nIt generates idx libraries, similar to MUD table libraries, using a secondary config derived from MUD config.\n\n## Howto\n\nInstall the package:\n\n```bash copy\npnpm add @dk1a/mud-table-idxs\n```\n\nInclude idx modules in your `mud.config.ts`:\n\n```ts\nimport { basicIdxModule, uniqueIdxModule } from \"@dk1a/mud-table-idxs\";\n...\n\nexport default defineWorld({\n  ...\n  modules: [basicIdxModule, uniqueIdxModule],\n  ...\n});\n```\n\nNext to `mud.config.ts` add a file `mud.idxs.config.ts` (the name isn't important) like this:\n\n```ts\nimport { defineStoreIdxs } from \"@dk1a/mud-table-idxs\";\nimport storeConfig from \"./mud.config\";\n\nexport default defineStoreIdxs(\n  {\n    namespaces: {\n      root: {\n        tables: {\n          YourMudTable: [\n            {\n              fields: [\"field1\", \"field2\"],\n              unique: false,\n            },\n          ],\n        },\n      },\n    },\n  },\n  storeConfig,\n);\n```\n\nThen add `./ts/scripts/generate-idxs.ts` (the specific path/name isn't important) like this:\n\n```ts\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { idxgen } from \"@dk1a/mud-table-idxs/codegen\";\n\nimport storeConfig from \"../../mud.config\";\n// TODO change this if you named your idxs config something else\nimport idxsConfig from \"../../mud.idxs.config\";\n\nconst rootDir = path.resolve(\n  path.dirname(fileURLToPath(import.meta.url)),\n  \"../..\",\n);\n\nawait idxgen({ rootDir, idxsConfig, storeConfig });\n```\n\nFinally call `generate-idxs.ts` in your `package.json`, **before(!)** `mud build`, e.g.:\n\n```json\n{\n  \"scripts\": {\n    \"build\": \"pnpm run build:mudidx \u0026\u0026 pnpm run build:mud\",\n    \"build:mudidx\": \"tsx ./ts/scripts/generate-test-idxs.ts\",\n    \"build:mud\": \"mud build\",\n    ...\n  }\n}\n```\n\n## Description\n\n`idx` is used for these onchain table indexes, instead of `index`, which is too generic a term and hard to search/refactor.\n\n`mud-table-idxs` are best compared to MUD's [KeysWithValue module](https://mud.dev/world/modules/keyswithvalue), which is essentially a basic onchain index, but it only indexes all non-key values at once, and has no typed codegen.\n\n`mud-table-idxs` indexes any combination of fields, which can include key fields.\n\nCaveats:\n\n- Using only key fields for unique indexes isn't allowed, I assume there is no valid use-case for this, you should just change the number of key fields in your table's mud config\n- Using only key fields for basic indexes is allowed, but the generated library will lack some methods, and using [KeysInTable module](https://mud.dev/world/modules/keysintable) instead of this will probably be more efficient\n- Index libraries use the full primary key and the indexed fields as arguments/returns. So using key fields for indexes will exclude duplicate key arguments/returns from relevant methods (TODO explain this better with examples)\n- This uses world modules and doesn't work with standalone store\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk1a%2Fmud-table-idxs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdk1a%2Fmud-table-idxs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdk1a%2Fmud-table-idxs/lists"}