mirror of
https://github.com/fluencelabs/registry.git
synced 2025-04-24 17:52:14 +00:00
chore(api): rename registerServiceRecord to registerService in Aqua API (#142)
BREAKING CHANGE: update your projects that use registerServiceRecord API call
This commit is contained in:
parent
154a9287cf
commit
849aac84b5
2
.github/workflows/run-tests.yml
vendored
2
.github/workflows/run-tests.yml
vendored
@ -50,7 +50,7 @@ jobs:
|
||||
run: cargo clippy -Z unstable-options --all
|
||||
|
||||
- name: Install cargo-nextest
|
||||
uses: baptiste0928/cargo-install@v1
|
||||
uses: baptiste0928/cargo-install@v1.3.0
|
||||
with:
|
||||
crate: cargo-nextest
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
- [createResource](#createresource)
|
||||
- [getResource](#getresource)
|
||||
- [getResourceId](#getresourceid)
|
||||
- [registerServiceRecord](#registerservicerecord)
|
||||
- [registerService](#registerService)
|
||||
- [unregisterService](#unregisterservice)
|
||||
- [resolveResource](#resolveresource)
|
||||
- [executeOnResource](#executeonresource)
|
||||
@ -138,9 +138,9 @@ func getResourceId(label: string, peer_id: string) -> ResourceId:
|
||||
```
|
||||
|
||||
Returns a deterministic hash of the `label` and the `peer_id`.
|
||||
#### registerServiceRecord
|
||||
#### registerService
|
||||
```rust
|
||||
func registerServiceRecord(
|
||||
func registerService(
|
||||
resource_id: ResourceId,
|
||||
value: string,
|
||||
peer_id: PeerId,
|
||||
|
@ -98,13 +98,13 @@ For now there is no method for Resource removal but it can be expired and garbag
|
||||
|
||||
### How to register a service
|
||||
```
|
||||
registerServiceRecord(resource_id: ResourceId, value: string, peer_id: string service_id: ?string) -> bool, *Error
|
||||
registerService(resource_id: ResourceId, value: string, peer_id: string service_id: ?string) -> bool, *Error
|
||||
```
|
||||
|
||||
Let's register a local service `greeting` and pass a random string `hi` as a value:
|
||||
```rust
|
||||
func registerLocalService(resource_id: ResourceId) -> ?bool, *Error:
|
||||
success, error <- registerServiceRecord(resource_id, "hi", INIT_PEER_ID, ?[greeting])
|
||||
success, error <- registerService(resource_id, "hi", INIT_PEER_ID, ?[greeting])
|
||||
<- success, error
|
||||
```
|
||||
|
||||
@ -112,7 +112,7 @@ func registerLocalService(resource_id: ResourceId) -> ?bool, *Error:
|
||||
Let's register a service `echo` hosted on `peer_id` and pass a random string like `sample` as a value:
|
||||
```rust
|
||||
func registerExternalService(resource_id: ResourceId, peer_id: PeerId) -> ?bool, *Error:
|
||||
success, error <- registerServiceRecord(resource_id, "hi", peer_id, ?[greeting])
|
||||
success, error <- registerService(resource_id, "hi", peer_id, ?[greeting])
|
||||
<- success, error
|
||||
```
|
||||
|
||||
|
@ -2,7 +2,7 @@ module Test
|
||||
|
||||
import "@fluencelabs/aqua-lib/builtin.aqua"
|
||||
import "@fluencelabs/registry/resources-api.aqua"
|
||||
export getResource, createResource, getResourceId, get_peer_id, registerServiceRecord, resolveResource, unregisterService
|
||||
export getResource, createResource, getResourceId, get_peer_id, registerService, resolveResource, unregisterService
|
||||
|
||||
func get_peer_id() -> PeerId:
|
||||
<- INIT_PEER_ID
|
||||
|
@ -82,7 +82,7 @@ def test_register_record_unregister():
|
||||
service_id = "id"
|
||||
|
||||
resource_id = create_resource(label, sk)
|
||||
result, error = run_aqua("registerServiceRecord", [resource_id, value, peer_id, service_id], sk, relay)
|
||||
result, error = run_aqua("registerService", [resource_id, value, peer_id, service_id], sk, relay)
|
||||
assert result, error
|
||||
|
||||
# we want at least 1 successful response
|
||||
@ -115,7 +115,7 @@ def test_register_unregister_remote_record():
|
||||
service_id = "id"
|
||||
|
||||
resource_id = create_resource(label, sk)
|
||||
result, error = run_aqua("registerServiceRecord", [resource_id, value, peer_id, service_id], sk, relay)
|
||||
result, error = run_aqua("registerService", [resource_id, value, peer_id, service_id], sk, relay)
|
||||
assert result, error
|
||||
|
||||
result, error = run_aqua("resolveResource", [resource_id, 2], sk, relay)
|
||||
|
@ -56,7 +56,7 @@ func createResource(label: string) -> ?ResourceId, *Error:
|
||||
<- resource_id, error
|
||||
|
||||
-- Note: resource must be already created
|
||||
func registerServiceRecord(resource_id: ResourceId, value: string, peer_id: PeerId, service_id: ?string) -> bool, *Error:
|
||||
func registerService(resource_id: ResourceId, value: string, peer_id: PeerId, service_id: ?string) -> bool, *Error:
|
||||
relay_id: ?string
|
||||
if peer_id == INIT_PEER_ID:
|
||||
relay_id <<- HOST_PEER_ID
|
||||
|
@ -103,7 +103,7 @@ To register the `echo` service written in Rust, replace `RESOURCE_ID` and execut
|
||||
```sh
|
||||
fluence run -f 'registerEchoService("RESOURCE_ID")'
|
||||
```
|
||||
This command calls [registerEchoService](src/aqua/main.aqua#L26) aqua function, which uses `registerServiceRecord` function from Resources API to register the rust service on this `resourceId`
|
||||
This command calls [registerEchoService](src/aqua/main.aqua#L26) aqua function, which uses `registerService` function from Resources API to register the rust service on this `resourceId`
|
||||
|
||||
You should see this output:
|
||||
```
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Export
|
||||
import "services/echo_service.aqua"
|
||||
import registerServiceRecord from "../../aqua/resources-api.aqua"
|
||||
export EchoService, registerServiceRecord
|
||||
import registerService from "../../aqua/resources-api.aqua"
|
||||
export EchoService, registerService
|
||||
|
@ -27,7 +27,7 @@ func registerEchoService(resourceId: string) -> *bool:
|
||||
results: *bool
|
||||
services <- App.services()
|
||||
for srv <- services.echo_service.default:
|
||||
results <- registerServiceRecord(resourceId, "" ,srv.peerId, ?[srv.serviceId])
|
||||
results <- registerService(resourceId, "" ,srv.peerId, ?[srv.serviceId])
|
||||
<- results
|
||||
|
||||
func echoAll(resourceId: string, msg: string) -> *string:
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
import { Fluence, KeyPair, setLogLevel } from "@fluencelabs/fluence";
|
||||
import { stage } from "@fluencelabs/fluence-network-environment";
|
||||
import { registerEchoService, registerServiceRecord } from "./generated/export";
|
||||
import { registerEchoService, registerService } from "./generated/export";
|
||||
import assert from "node:assert";
|
||||
|
||||
// don't store your secret key in the code. This is just for the example
|
||||
@ -56,7 +56,7 @@ async function main() {
|
||||
fluence run -f 'echoJS("${peerId}", "${relayId}", "${serviceId}", "hi")'`
|
||||
);
|
||||
} else {
|
||||
const [success, error] = await registerServiceRecord(
|
||||
const [success, error] = await registerService(
|
||||
resourceId,
|
||||
"echo",
|
||||
peerId,
|
||||
|
@ -1,5 +1,5 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
channel = "nightly-2022-10-05"
|
||||
components = [ "rustfmt", "clippy" ]
|
||||
targets = [ "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-wasi" ]
|
||||
profile = "minimal"
|
||||
|
@ -1,5 +1,5 @@
|
||||
[toolchain]
|
||||
channel = "nightly"
|
||||
channel = "nightly-2022-10-05"
|
||||
components = [ "rustfmt", "clippy" ]
|
||||
targets = [ "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "wasm32-wasi" ]
|
||||
profile = "minimal"
|
||||
|
Loading…
x
Reference in New Issue
Block a user