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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 25 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './mapping.js'
File renamed without changes.

common/models/tsconfig.json

Lines changed: 21 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './objectMappingIndexer.js'
2+
export * from './subspaceObjectListener.js'
Lines changed: 43 additions & 0 deletions
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+
})
Lines changed: 22 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)