Skip to content

Commit c7e152e

Browse files
authored
Merge pull request #60 from autonomys/fix-rpc-listen
update: type safe RPC APIs
2 parents 70ade0c + 0974c05 commit c7e152e

File tree

31 files changed

+624
-540
lines changed

31 files changed

+624
-540
lines changed

Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
build:
2+
yarn build
3+
4+
models:
5+
yarn models build
6+
rpc:
7+
yarn rpc build
8+
9+
common: models rpc
10+
11+
indexer: common
12+
yarn indexer build
13+
14+
file-retriever: common
15+
yarn file-retriever build
16+

common/models/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "@auto-files/models",
3+
"version": "0.0.1",
4+
"packageManager": "[email protected]",
5+
"type": "module",
6+
"dependencies": {
7+
"@autonomys/rpc": "^1.4.9",
8+
"zod": "^3.24.2"
9+
},
10+
"exports": {
11+
".": {
12+
"types": "./dist/index.d.ts",
13+
"require": "./dist/index.js",
14+
"import": "./dist/index.js"
15+
}
16+
},
17+
"main": "./dist/index.js",
18+
"types": "./dist/index.d.ts",
19+
"scripts": {
20+
"build": "tsc"
21+
},
22+
"devDependencies": {
23+
"typescript": "^5.6.3"
24+
}
25+
}

common/models/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './mapping.js'

common/models/tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"outDir": "./dist",
10+
"rootDir": "./src",
11+
"baseUrl": "src",
12+
"paths": {
13+
"*": ["*"]
14+
},
15+
"strict": true,
16+
"allowJs": true,
17+
"declaration": true
18+
},
19+
"include": ["src/**/*"],
20+
"exclude": ["node_modules", "dist"]
21+
}

common/rpc-apis/package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@auto-files/rpc-apis",
3+
"version": "0.0.1",
4+
"packageManager": "[email protected]",
5+
"type": "module",
6+
"dependencies": {
7+
"@auto-files/models": "workspace:*",
8+
"@autonomys/rpc": "^1.4.11",
9+
"zod": "^3.24.2"
10+
},
11+
"exports": {
12+
".": {
13+
"types": "./dist/index.d.ts",
14+
"require": "./dist/index.js",
15+
"import": "./dist/index.js"
16+
}
17+
},
18+
"main": "./dist/index.js",
19+
"types": "./dist/index.d.ts",
20+
"scripts": {
21+
"build": "tsc"
22+
},
23+
"devDependencies": {
24+
"typescript": "^5.6.3"
25+
}
26+
}

common/rpc-apis/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './objectMappingIndexer.js'
2+
export * from './subspaceObjectListener.js'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineUnvalidatedType, createApiDefinition } from '@autonomys/rpc'
2+
import { z } from 'zod'
3+
import { ObjectMapping } from '@auto-files/models'
4+
5+
export const ObjectMappingIndexerRPCApi = createApiDefinition({
6+
methods: {
7+
subscribe_object_mappings: {
8+
params: defineUnvalidatedType<void>(),
9+
returns: z.object({
10+
subscriptionId: z.string(),
11+
}),
12+
},
13+
unsubscribe_object_mappings: {
14+
params: z.object({
15+
subscriptionId: z.string(),
16+
}),
17+
returns: z.object({
18+
success: z.boolean(),
19+
}),
20+
},
21+
subscribe_recover_object_mappings: {
22+
params: z.object({
23+
pieceIndex: z.number(),
24+
}),
25+
returns: z.object({
26+
subscriptionId: z.string(),
27+
}),
28+
},
29+
unsubscribe_recover_object_mappings: {
30+
params: z.object({
31+
subscriptionId: z.string(),
32+
}),
33+
returns: z.object({
34+
success: z.boolean(),
35+
}),
36+
},
37+
},
38+
notifications: {
39+
object_mapping_list: {
40+
content: defineUnvalidatedType<ObjectMapping[]>(),
41+
},
42+
},
43+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ObjectMappingListEntry } from '@auto-files/models'
2+
import { createApiDefinition, defineUnvalidatedType } from '@autonomys/rpc'
3+
4+
type SubscriptionResult<T> = {
5+
subscriptionId: string
6+
result: T
7+
}
8+
9+
export const SubspaceObjectListenerAPI = createApiDefinition({
10+
methods: {
11+
subspace_subscribeObjectMappings: {
12+
params: defineUnvalidatedType<void>(),
13+
returns: defineUnvalidatedType<string>(),
14+
},
15+
},
16+
notifications: {
17+
subspace_object_mappings: {
18+
content:
19+
defineUnvalidatedType<SubscriptionResult<ObjectMappingListEntry>>(),
20+
},
21+
},
22+
})

common/rpc-apis/tsconfig.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"moduleResolution": "node",
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"outDir": "./dist",
10+
"rootDir": "./src",
11+
"baseUrl": "src",
12+
"paths": {
13+
"*": ["*"]
14+
},
15+
"strict": true,
16+
"allowJs": true,
17+
"declaration": true
18+
},
19+
"include": ["src/**/*"],
20+
"exclude": ["node_modules", "dist"]
21+
}

docker/file-retriever/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN corepack prepare [email protected] --activate
1616
RUN rm -rf node_modules
1717
RUN yarn add tar
1818
RUN yarn
19-
RUN yarn file-retriever build
19+
RUN make file-retriever
2020

2121
EXPOSE 8090
2222

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
"packageManager": "[email protected]",
44
"type": "module",
55
"workspaces": [
6-
"services/*"
6+
"services/*",
7+
"common/*"
78
],
89
"scripts": {
910
"indexer": "yarn workspace object-mapping-indexer",
1011
"file-retriever": "yarn workspace file-retriever",
1112
"benchmark": "node --loader ts-node/esm benchmarks/taurus.ts",
12-
"build": "yarn workspaces foreach --all run build"
13+
"models": "yarn workspace @auto-files/models",
14+
"rpc": "yarn workspace @auto-files/rpc-apis",
15+
"build": "yarn workspaces foreach --topological --verbose --all run build"
1316
},
1417
"dependencies": {
18+
"@autonomys/rpc": "^1.4.11",
1519
"axios": "^1.7.9",
1620
"ts-node": "^10.9.2",
1721
"winston": "^3.17.0"

services/object-mapping-indexer/Dockerfile

-22
This file was deleted.

services/object-mapping-indexer/node-docker-compose.yml

-33
This file was deleted.

services/object-mapping-indexer/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
},
99
"scripts": {
1010
"build": "tsc",
11-
"start": "node dist/server.js",
11+
"start": "node dist/index.js",
1212
"dev": "node --loader ts-node/esm",
1313
"test": "jest"
1414
},
1515
"license": "MIT",
1616
"dependencies": {
17+
"@auto-files/models": "workspace:*",
18+
"@auto-files/rpc-apis": "workspace:*",
1719
"@autonomys/auto-dag-data": "^1.0.5",
18-
"@autonomys/rpc": "^1.4.6",
20+
"@autonomys/rpc": "^1.4.11",
1921
"@peculiar/webcrypto": "^1.5.0",
2022
"@types/node": "^22.10.2",
2123
"cors": "^2.8.5",

services/object-mapping-indexer/src/config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { env, notNaN } from './utils/env.js'
22

33
export const config = {
4-
port: env('OBJECT_MAPPING_INDEXER_PORT', '3000'),
4+
port: Number(env('OBJECT_MAPPING_INDEXER_PORT', '3000')),
55
requestSizeLimit: env('REQUEST_SIZE_LIMIT', '200mb'),
66
corsAllowOrigins: env('CORS_ALLOW_ORIGINS', ''),
77
nodeRpcUrl: env('NODE_RPC_URL'),

0 commit comments

Comments
 (0)