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

Commit 608506d

Browse files
authored
Refactor public API: put default peer API under Fluence facade (#72)
1 parent 6436cd5 commit 608506d

File tree

8 files changed

+8550
-103
lines changed

8 files changed

+8550
-103
lines changed

package-lock.json

Lines changed: 8330 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__test__/integration/avm.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { FluencePeer } from '../../index';
1+
import { Fluence, FluencePeer } from '../../index';
22
import { RequestFlowBuilder } from '../../internal/RequestFlowBuilder';
33

4-
const peer = new FluencePeer();
4+
const anotherPeer = new FluencePeer();
55

66
describe('Avm spec', () => {
77
afterEach(async () => {
8-
if (peer) {
9-
await peer.uninit();
8+
if (anotherPeer) {
9+
await anotherPeer.stop();
1010
}
1111
});
1212

1313
it('Par execution should work', async () => {
1414
// arrange
15-
await peer.init();
15+
await Fluence.start();
1616

1717
let request;
1818
const promise = new Promise<string[]>((resolve) => {
@@ -41,7 +41,7 @@ describe('Avm spec', () => {
4141
});
4242

4343
// act
44-
await peer.internals.initiateFlow(request);
44+
await Fluence.getPeer().internals.initiateFlow(request);
4545
const res = await promise;
4646

4747
// assert

src/__test__/integration/compiler/compiler.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { FluencePeer } from '../../..';
1+
import { Fluence, FluencePeer } from '../../..';
22
import { RequestFlowBuilder } from '../../../internal/RequestFlowBuilder';
33
import { callMeBack, registerHelloWorld } from './gen1';
44

55
describe('Compiler support infrastructure tests', () => {
66
it('Compiled code for function should work', async () => {
77
// arrange
8-
await FluencePeer.default.init();
8+
await Fluence.start();
99

1010
// act
1111
const res = new Promise((resolve) => {
@@ -39,12 +39,12 @@ describe('Compiler support infrastructure tests', () => {
3939
},
4040
});
4141

42-
await FluencePeer.default.uninit();
42+
await Fluence.stop();
4343
});
4444

4545
it('Compiled code for service should work', async () => {
4646
// arrange
47-
await FluencePeer.default.init();
47+
await Fluence.start();
4848

4949
// act
5050
const helloPromise = new Promise((resolve) => {
@@ -71,19 +71,19 @@ describe('Compiler support infrastructure tests', () => {
7171
)`,
7272
)
7373
.buildAsFetch<[string]>('callback', 'callback');
74-
await FluencePeer.default.internals.initiateFlow(request);
74+
await Fluence.getPeer().internals.initiateFlow(request);
7575

7676
// assert
7777
expect(await helloPromise).toBe('hello world!');
7878
expect(await getNumberPromise).toStrictEqual([42]);
7979

80-
await FluencePeer.default.uninit();
80+
await Fluence.stop();
8181
});
8282

8383
it('Compiled code for function should work with another peer', async () => {
8484
// arrange
8585
const peer = new FluencePeer();
86-
await peer.init();
86+
await peer.start();
8787

8888
// act
8989
const res = new Promise((resolve) => {
@@ -117,13 +117,13 @@ describe('Compiler support infrastructure tests', () => {
117117
},
118118
});
119119

120-
await peer.uninit();
120+
await peer.stop();
121121
});
122122

123123
it('Compiled code for service should work another peer', async () => {
124124
// arrange
125125
const peer = new FluencePeer();
126-
await peer.init();
126+
await peer.start();
127127

128128
// act
129129
const helloPromise = new Promise((resolve) => {
@@ -156,6 +156,6 @@ describe('Compiler support infrastructure tests', () => {
156156
expect(await helloPromise).toBe('hello world!');
157157
expect(await getNumberPromise).toStrictEqual([42]);
158158

159-
await peer.uninit();
159+
await peer.stop();
160160
});
161161
});

src/__test__/integration/compiler/gen1.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ResultCodes, RequestFlow, RequestFlowBuilder, CallParams } from '../../../internal/compilerSupport/v1';
2-
import { FluencePeer } from '../../../index';
2+
import { Fluence, FluencePeer } from '../../../index';
33

44
/*
55
@@ -41,7 +41,7 @@ export function registerHelloWorld(...args) {
4141
if (args[0] instanceof FluencePeer) {
4242
peer = args[0];
4343
} else {
44-
peer = FluencePeer.default;
44+
peer = Fluence.getPeer();
4545
}
4646

4747
if (typeof args[0] === 'string') {
@@ -111,7 +111,7 @@ export function callMeBack(...args) {
111111
callback = args[1];
112112
config = args[2];
113113
} else {
114-
peer = FluencePeer.default;
114+
peer = Fluence.getPeer();
115115
callback = args[0];
116116
config = args[1];
117117
}
@@ -137,7 +137,7 @@ export function callMeBack(...args) {
137137
)
138138
.configHandler((h) => {
139139
h.on('getDataSrv', '-relay-', () => {
140-
return peer.connectionInfo.connectedRelay || null;
140+
return peer.getStatus().relayPeerId || null;
141141
});
142142

143143
h.use((req, resp, next) => {

0 commit comments

Comments
 (0)