Skip to content

Commit d954c97

Browse files
authored
[taucorder] typescript client #280 (#281)
1 parent 8a92750 commit d954c97

40 files changed

+8782
-17
lines changed

.github/workflows/pre-commit.yml

+26-17
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,34 @@ jobs:
8888
- name: Add entry to /etc/hosts
8989
run: |
9090
echo "127.0.0.1 hal.computers.com" | sudo tee -a /etc/hosts
91-
- name: Build mock server
91+
- name: Build mock servers
9292
run: |
93-
cd pkg/spore-drive/clients/mock
94-
go build .
93+
for project in "spore-drive" "taucorder"; do
94+
(
95+
cd pkg/$project/clients/mock
96+
go build .
97+
) || exit 1
98+
done
9599
- name: Run JS/TS tests with retries
96100
run: |
97101
max_attempts=5
98-
attempt_num=1
99-
cd pkg/spore-drive/clients/js
100-
npm i
101-
until [ $attempt_num -gt $max_attempts ]
102-
do
103-
echo "Attempt $attempt_num of $max_attempts"
104-
npm run test && break || echo "Test failed. Retrying..."
105-
attempt_num=$((attempt_num + 1))
106-
if [ $attempt_num -gt $max_attempts ]
107-
then
108-
echo "All test attempts failed."
109-
exit 1
110-
fi
111-
sleep 5
102+
for project in "pkg/spore-drive/clients/js" "pkg/taucorder/clients/js"; do
103+
attempt_num=1
104+
(
105+
cd $project
106+
echo "Running tests for $project"
107+
npm i
108+
until [ $attempt_num -gt $max_attempts ]
109+
do
110+
echo "Attempt $attempt_num of $max_attempts"
111+
npm run test && break || echo "Test failed. Retrying..."
112+
attempt_num=$((attempt_num + 1))
113+
if [ $attempt_num -gt $max_attempts ]
114+
then
115+
echo "All test attempts failed for $project"
116+
exit 1
117+
fi
118+
sleep 5
119+
done
120+
) || exit 1
112121
done

pkg/taucorder/clients/js/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @taubyte/taucorder
2+
3+
## Installation
4+
5+
### npm
6+
```sh
7+
npm install @taubyte/taucorder
8+
```
9+
10+
### yarn
11+
```sh
12+
yarn add @taubyte/taucorder
13+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }], // Target Node.js environment
4+
'@babel/preset-typescript', // Add TypeScript support
5+
],
6+
plugins: ['@babel/plugin-syntax-import-meta'], // Add support for import.meta
7+
};
8+

pkg/taucorder/clients/js/index.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {
2+
Node,
3+
Empty,
4+
Job,
5+
Peer,
6+
Peers,
7+
ConsensusState,
8+
RepositoryId,
9+
} from "./gen/taucorder/v1/common_pb";
10+
import { Config } from "./gen/taucorder/v1/node_pb";
11+
import { StashedItem, StashRequest } from "./gen/taucorder/v1/hoarder_pb";
12+
import {
13+
Project,
14+
ProjectRepo,
15+
Hook,
16+
X509Certificate,
17+
} from "./gen/taucorder/v1/auth_pb";
18+
import {
19+
PeerUsage,
20+
PeerLocation,
21+
Location,
22+
LocationArea,
23+
} from "./gen/taucorder/v1/seer_pb";
24+
import { TNSPath, TNSObject, TNSPaths } from "./gen/taucorder/v1/tns_pb";
25+
import { Taucorder as Core } from "./src/Taucorder";
26+
import { Service } from "./src/Service";
27+
28+
export {
29+
Node,
30+
Empty,
31+
Job,
32+
Peer,
33+
Peers,
34+
ConsensusState,
35+
RepositoryId,
36+
Config,
37+
StashedItem,
38+
StashRequest,
39+
Project,
40+
ProjectRepo,
41+
Hook,
42+
X509Certificate,
43+
PeerUsage,
44+
PeerLocation,
45+
Location,
46+
LocationArea,
47+
TNSPath,
48+
TNSObject,
49+
TNSPaths,
50+
};
51+
52+
export class Taucorder extends Core {
53+
private service: Service;
54+
55+
constructor(rpcUrl: string, config: Config) {
56+
super(rpcUrl, config);
57+
this.service = new Service();
58+
}
59+
60+
public async init(): Promise<void> {
61+
await this.service.run();
62+
await super.init();
63+
}
64+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// jest.config.js
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
extensionsToTreatAsEsm: ['.ts'],
6+
transform: {
7+
'^.+\\.tsx?$': 'babel-jest', // Use babel-jest for TypeScript files
8+
},
9+
moduleNameMapper: {
10+
// Map all imports ending with .js to .ts files
11+
'^(.*)\\.js$': '$1',
12+
},
13+
testRunner: 'jest-circus/runner', // Optional: use modern test runner
14+
};
15+

0 commit comments

Comments
 (0)