Skip to content

Commit

Permalink
[taucorder] typescript client #280 (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
samyfodil authored Dec 11, 2024
1 parent 8a92750 commit d954c97
Show file tree
Hide file tree
Showing 40 changed files with 8,782 additions and 17 deletions.
43 changes: 26 additions & 17 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,34 @@ jobs:
- name: Add entry to /etc/hosts
run: |
echo "127.0.0.1 hal.computers.com" | sudo tee -a /etc/hosts
- name: Build mock server
- name: Build mock servers
run: |
cd pkg/spore-drive/clients/mock
go build .
for project in "spore-drive" "taucorder"; do
(
cd pkg/$project/clients/mock
go build .
) || exit 1
done
- name: Run JS/TS tests with retries
run: |
max_attempts=5
attempt_num=1
cd pkg/spore-drive/clients/js
npm i
until [ $attempt_num -gt $max_attempts ]
do
echo "Attempt $attempt_num of $max_attempts"
npm run test && break || echo "Test failed. Retrying..."
attempt_num=$((attempt_num + 1))
if [ $attempt_num -gt $max_attempts ]
then
echo "All test attempts failed."
exit 1
fi
sleep 5
for project in "pkg/spore-drive/clients/js" "pkg/taucorder/clients/js"; do
attempt_num=1
(
cd $project
echo "Running tests for $project"
npm i
until [ $attempt_num -gt $max_attempts ]
do
echo "Attempt $attempt_num of $max_attempts"
npm run test && break || echo "Test failed. Retrying..."
attempt_num=$((attempt_num + 1))
if [ $attempt_num -gt $max_attempts ]
then
echo "All test attempts failed for $project"
exit 1
fi
sleep 5
done
) || exit 1
done
13 changes: 13 additions & 0 deletions pkg/taucorder/clients/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @taubyte/taucorder

## Installation

### npm
```sh
npm install @taubyte/taucorder
```

### yarn
```sh
yarn add @taubyte/taucorder
```
8 changes: 8 additions & 0 deletions pkg/taucorder/clients/js/babel.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }], // Target Node.js environment
'@babel/preset-typescript', // Add TypeScript support
],
plugins: ['@babel/plugin-syntax-import-meta'], // Add support for import.meta
};

64 changes: 64 additions & 0 deletions pkg/taucorder/clients/js/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Node,
Empty,
Job,
Peer,
Peers,
ConsensusState,
RepositoryId,
} from "./gen/taucorder/v1/common_pb";
import { Config } from "./gen/taucorder/v1/node_pb";
import { StashedItem, StashRequest } from "./gen/taucorder/v1/hoarder_pb";
import {
Project,
ProjectRepo,
Hook,
X509Certificate,
} from "./gen/taucorder/v1/auth_pb";
import {
PeerUsage,
PeerLocation,
Location,
LocationArea,
} from "./gen/taucorder/v1/seer_pb";
import { TNSPath, TNSObject, TNSPaths } from "./gen/taucorder/v1/tns_pb";
import { Taucorder as Core } from "./src/Taucorder";
import { Service } from "./src/Service";

export {
Node,
Empty,
Job,
Peer,
Peers,
ConsensusState,
RepositoryId,
Config,
StashedItem,
StashRequest,
Project,
ProjectRepo,
Hook,
X509Certificate,
PeerUsage,
PeerLocation,
Location,
LocationArea,
TNSPath,
TNSObject,
TNSPaths,
};

export class Taucorder extends Core {
private service: Service;

constructor(rpcUrl: string, config: Config) {
super(rpcUrl, config);
this.service = new Service();
}

public async init(): Promise<void> {
await this.service.run();
await super.init();
}
}
15 changes: 15 additions & 0 deletions pkg/taucorder/clients/js/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
transform: {
'^.+\\.tsx?$': 'babel-jest', // Use babel-jest for TypeScript files
},
moduleNameMapper: {
// Map all imports ending with .js to .ts files
'^(.*)\\.js$': '$1',
},
testRunner: 'jest-circus/runner', // Optional: use modern test runner
};

Loading

0 comments on commit d954c97

Please sign in to comment.