Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 5355eeb

Browse files
authored
Extract defaults (#34)
* Extracted default request flow builder behavior out of the constructor * Remove init_peer_id variable, which stands in the way when building apps with aquamarine
1 parent 0ff10a2 commit 5355eeb

File tree

6 files changed

+180
-44
lines changed

6 files changed

+180
-44
lines changed

src/FluenceClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const checkConnection = async (client: FluenceClient, ttl?: number): Prom
123123
const callbackService = '_callback';
124124

125125
const [request, promise] = new RequestFlowBuilder()
126+
.withDefaults()
126127
.withRawScript(
127128
`(seq
128129
(call init_relay ("op" "identity") [msg] result)

src/__test__/integration/client.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('Typescript usage suite', () => {
1919

2020
// act
2121
const [request, promise] = new RequestFlowBuilder()
22+
.withDefaults()
2223
.withRawScript(
2324
`(seq
2425
(call init_relay ("op" "identity") ["hello world!"] result)
@@ -76,7 +77,9 @@ describe('Typescript usage suite', () => {
7677
data.set('c', 'some c');
7778
data.set('d', 'some d');
7879

79-
await client1.initiateFlow(new RequestFlowBuilder().withRawScript(script).withVariables(data).build());
80+
await client1.initiateFlow(
81+
new RequestFlowBuilder().withDefaults().withRawScript(script).withVariables(data).build(),
82+
);
8083

8184
let res = await resMakingPromise;
8285
expect(res).toEqual(['some a', 'some b', 'some c', 'some d']);
@@ -186,6 +189,7 @@ describe('Typescript usage suite', () => {
186189
it('xor handling should work with connected client', async function () {
187190
// arrange
188191
const [request, promise] = new RequestFlowBuilder()
192+
.withDefaults()
189193
.withRawScript(
190194
`
191195
(seq
@@ -210,6 +214,7 @@ describe('Typescript usage suite', () => {
210214
it('xor handling should work with local client', async function () {
211215
// arrange
212216
const [request, promise] = new RequestFlowBuilder()
217+
.withDefaults()
213218
.withRawScript(
214219
`
215220
(call %init_peer_id% ("service" "fails") [])

src/__test__/unit/air.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ describe('== AIR suite', () => {
1919

2020
// prettier-ignore
2121
const [request, promise] = new RequestFlowBuilder()
22+
.withDefaults()
2223
.withRawScript(script)
2324
.buildAsFetch<string[]>(serviceId, fnName);
2425

@@ -59,6 +60,7 @@ describe('== AIR suite', () => {
5960
const script = `(incorrect)`;
6061
// prettier-ignore
6162
const [request, error] = new RequestFlowBuilder()
63+
.withDefaults()
6264
.withRawScript(script)
6365
.buildWithErrorHandling();
6466

@@ -75,6 +77,7 @@ describe('== AIR suite', () => {
7577
const script = `(null)`;
7678
// prettier-ignore
7779
const [request, promise] = new RequestFlowBuilder()
80+
.withDefaults()
7881
.withTTL(1)
7982
.withRawScript(script)
8083
.buildAsFetch();
@@ -96,6 +99,7 @@ describe('== AIR suite', () => {
9699

97100
// prettier-ignore
98101
const [request, promise] = new RequestFlowBuilder()
102+
.withDefaults()
99103
.withRawScript(script)
100104
.withVariable('arg1', 'hello')
101105
.buildAsFetch<string[]>(serviceId, fnName);
@@ -138,7 +142,7 @@ describe('== AIR suite', () => {
138142
(call %init_peer_id% ("${makeDataServiceId}" "${makeDataFnName}") [] result)
139143
(call %init_peer_id% ("${getDataServiceId}" "${getDataFnName}") [result.$.field])
140144
)`;
141-
await client.initiateFlow(new RequestFlowBuilder().withRawScript(script).build());
145+
await client.initiateFlow(new RequestFlowBuilder().withDefaults().withRawScript(script).build());
142146

143147
// assert
144148
const tetraplet = res.tetraplets[0][0];
@@ -187,7 +191,7 @@ describe('== AIR suite', () => {
187191
(call %init_peer_id% ("${serviceId2}" "${fnName2}") ["${arg2}"] result2))
188192
(call %init_peer_id% ("${serviceId3}" "${fnName3}") [result1 result2]))
189193
`;
190-
await client.initiateFlow(new RequestFlowBuilder().withRawScript(script).build());
194+
await client.initiateFlow(new RequestFlowBuilder().withDefaults().withRawScript(script).build());
191195

192196
// assert
193197
expect(res1).toEqual(arg1);

src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const sendParticle = async (
4444
onError?: (err) => void,
4545
): Promise<string> => {
4646
const [req, errorPromise] = new RequestFlowBuilder()
47+
.withDefaults()
4748
.withRawScript(particle.script)
4849
.withVariables(particle.data)
4950
.withTTL(particle.ttl)
@@ -147,6 +148,7 @@ export const sendParticleAsFetch = async <T>(
147148
callbackServiceId: string = '_callback',
148149
): Promise<T> => {
149150
const [request, promise] = new RequestFlowBuilder()
151+
.withDefaults()
150152
.withRawScript(particle.script)
151153
.withVariables(particle.data)
152154
.withTTL(particle.ttl)

0 commit comments

Comments
 (0)