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

Commit d84d9fd

Browse files
authored
Opt out defaults (#43)
* Change the wat the withDefaults() words. Now it is "disable default injections" instead of "enable default injections"
1 parent f9d7a1c commit d84d9fd

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

src/FluenceClient.ts

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

125125
const [request, promise] = new RequestFlowBuilder()
126-
.withDefaults()
127126
.withRawScript(
128127
`(seq
129128
(call init_relay ("op" "identity") [msg] result)

src/__test__/integration/client.spec.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { checkConnection, createClient, FluenceClient } from '../../FluenceClien
22
import Multiaddr from 'multiaddr';
33
import { nodes } from '../connection';
44
import { RequestFlowBuilder } from '../../internal/RequestFlowBuilder';
5+
import { error } from 'loglevel';
56

67
let client: FluenceClient;
78

@@ -19,7 +20,6 @@ describe('Typescript usage suite', () => {
1920

2021
// act
2122
const [request, promise] = new RequestFlowBuilder()
22-
.withDefaults()
2323
.withRawScript(
2424
`(seq
2525
(call init_relay ("op" "identity") ["hello world!"] result)
@@ -77,9 +77,7 @@ describe('Typescript usage suite', () => {
7777
data.set('c', 'some c');
7878
data.set('d', 'some d');
7979

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

8482
let res = await resMakingPromise;
8583
expect(res).toEqual(['some a', 'some b', 'some c', 'some d']);
@@ -189,7 +187,6 @@ describe('Typescript usage suite', () => {
189187
it('xor handling should work with connected client', async function () {
190188
// arrange
191189
const [request, promise] = new RequestFlowBuilder()
192-
.withDefaults()
193190
.withRawScript(
194191
`
195192
(seq
@@ -214,7 +211,6 @@ describe('Typescript usage suite', () => {
214211
it('xor handling should work with local client', async function () {
215212
// arrange
216213
const [request, promise] = new RequestFlowBuilder()
217-
.withDefaults()
218214
.withRawScript(
219215
`
220216
(call %init_peer_id% ("service" "fails") [])
@@ -244,9 +240,11 @@ describe('Typescript usage suite', () => {
244240
const res = callIdentifyOnInitPeerId(client);
245241

246242
// assert
247-
await expect(res).rejects.toMatch(
248-
"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''",
249-
);
243+
await expect(res).rejects.toMatchObject({
244+
error:
245+
"Local service error: ret_code is 1024, error message is '\"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''\"'",
246+
instruction: 'call %init_peer_id% ("peer" "identify") [] res',
247+
});
250248
});
251249
});
252250

src/__test__/unit/air.spec.ts

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

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

@@ -60,7 +59,6 @@ describe('== AIR suite', () => {
6059
const script = `(incorrect)`;
6160
// prettier-ignore
6261
const [request, error] = new RequestFlowBuilder()
63-
.withDefaults()
6462
.withRawScript(script)
6563
.buildWithErrorHandling();
6664

@@ -77,7 +75,6 @@ describe('== AIR suite', () => {
7775
const script = `(null)`;
7876
// prettier-ignore
7977
const [request, promise] = new RequestFlowBuilder()
80-
.withDefaults()
8178
.withTTL(1)
8279
.withRawScript(script)
8380
.buildAsFetch();
@@ -99,7 +96,6 @@ describe('== AIR suite', () => {
9996

10097
// prettier-ignore
10198
const [request, promise] = new RequestFlowBuilder()
102-
.withDefaults()
10399
.withRawScript(script)
104100
.withVariable('arg1', 'hello')
105101
.buildAsFetch<string[]>(serviceId, fnName);
@@ -142,7 +138,7 @@ describe('== AIR suite', () => {
142138
(call %init_peer_id% ("${makeDataServiceId}" "${makeDataFnName}") [] result)
143139
(call %init_peer_id% ("${getDataServiceId}" "${getDataFnName}") [result.$.field])
144140
)`;
145-
await client.initiateFlow(new RequestFlowBuilder().withDefaults().withRawScript(script).build());
141+
await client.initiateFlow(new RequestFlowBuilder().withRawScript(script).build());
146142

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

196192
// assert
197193
expect(res1).toEqual(arg1);

src/api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export const sendParticle = async (
4545
onError?: (err) => void,
4646
): Promise<string> => {
4747
const [req, errorPromise] = new RequestFlowBuilder()
48-
.withDefaults()
4948
.withRawScript(particle.script)
5049
.withVariables(particle.data)
5150
.withTTL(particle.ttl)
@@ -149,7 +148,6 @@ export const sendParticleAsFetch = async <T>(
149148
callbackServiceId: string = '_callback',
150149
): Promise<T> => {
151150
const [request, promise] = new RequestFlowBuilder()
152-
.withDefaults()
153151
.withRawScript(particle.script)
154152
.withVariables(particle.data)
155153
.withTTL(particle.ttl)

src/internal/RequestFlowBuilder.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ const wrapWithInjectRelayScript = (script: string): string => {
9595
* Builder class for configuring and creating Request Flows
9696
*/
9797
export class RequestFlowBuilder {
98+
private shouldInjectVariables: boolean = true;
99+
private shouldInjectErrorHandling: boolean = true;
100+
private shouldInjectRelay: boolean = true;
101+
98102
private ttl: number = DEFAULT_TTL;
99103
private variables = new Map<string, any>();
100104
private handlerConfigs: Array<(handler: AquaCallHandler, request: RequestFlow) => void> = [];
@@ -106,6 +110,16 @@ export class RequestFlowBuilder {
106110
* Builds the Request flow with current configuration
107111
*/
108112
build() {
113+
if (this.shouldInjectRelay) {
114+
this.injectRelay();
115+
}
116+
if (this.shouldInjectVariables) {
117+
this.injectVariables();
118+
}
119+
if (this.shouldInjectErrorHandling) {
120+
this.wrapWithXor();
121+
}
122+
109123
const sb = new ScriptBuilder();
110124
for (let action of this.buildScriptActions) {
111125
action(sb);
@@ -129,14 +143,13 @@ export class RequestFlowBuilder {
129143
}
130144

131145
/**
132-
* Provides necessary defaults when building requests by hand without the Aquamarine language compiler
133-
* Includes: relay and variable injection, error handling with top-level xor wrap
146+
* Removes necessary defaults when building requests by hand without the Aquamarine language compiler
147+
* Removed features include: relay and variable injection, error handling with top-level xor wrap
134148
*/
135-
withDefaults(): RequestFlowBuilder {
136-
this.injectRelay();
137-
this.injectVariables();
138-
this.wrapWithXor();
139-
149+
disableInjections(): RequestFlowBuilder {
150+
this.shouldInjectRelay = false;
151+
this.shouldInjectVariables = false;
152+
this.shouldInjectErrorHandling = false;
140153
return this;
141154
}
142155

src/internal/builtins.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const requestResponse = async <T>(
5555
`;
5656

5757
const [request, promise] = new RequestFlowBuilder()
58-
.withDefaults()
5958
.withRawScript(script)
6059
.withVariables(data)
6160
.withTTL(ttl)
@@ -73,7 +72,6 @@ const requestResponse = async <T>(
7372
export const getModules = async (client: FluenceClient, ttl?: number): Promise<string[]> => {
7473
let callbackFn = 'getModules';
7574
const [req, promise] = new RequestFlowBuilder()
76-
.withDefaults()
7775
.withRawScript(
7876
`
7977
(seq
@@ -102,7 +100,6 @@ export const getModules = async (client: FluenceClient, ttl?: number): Promise<s
102100
export const getInterfaces = async (client: FluenceClient, ttl?: number): Promise<string[]> => {
103101
let callbackFn = 'getInterfaces';
104102
const [req, promise] = new RequestFlowBuilder()
105-
.withDefaults()
106103
.withRawScript(
107104
`
108105
(seq
@@ -169,7 +166,6 @@ export const uploadModule = async (
169166
data.set('myPeerId', client.selfPeerId);
170167

171168
const [req, promise] = new RequestFlowBuilder()
172-
.withDefaults()
173169
.withRawScript(
174170
`
175171
(seq

0 commit comments

Comments
 (0)