Update builtins to new version (#27)

* Update builtins to new version

* Running integration tests in docker container
This commit is contained in:
Pavel
2021-02-25 15:33:37 +03:00
committed by GitHub
parent d65153e6de
commit 619c8a6d6a
8 changed files with 137 additions and 173 deletions

View File

@ -66,11 +66,11 @@ const requestResponse = async <T>(
* @returns { Array<string> } - list of available modules on the connected relay
*/
export const getModules = async (client: FluenceClient, ttl?: number): Promise<string[]> => {
let callbackFn = "getModules"
let callbackFn = 'getModules';
const particle = new Particle(
`
(seq
(call __relay ("dist" "get_modules") [] result)
(call __relay ("dist" "list_modules") [] result)
(call myPeerId ("_callback" "${callbackFn}") [result])
)
`,
@ -78,34 +78,46 @@ export const getModules = async (client: FluenceClient, ttl?: number): Promise<s
__relay: client.relayPeerId,
myPeerId: client.selfPeerId,
},
ttl
ttl,
);
return sendParticleAsFetch(client, particle, callbackFn);
};
/**
* Get all available modules hosted on a connected relay. @deprecated prefer using raw Particles instead
* Get all available interfaces hosted on a connected relay. @deprecated prefer using raw Particles instead
* @param { FluenceClient } client - The Fluence Client instance.
* @returns { Array<string> } - list of available modules on the connected relay
* @returns { Array<string> } - list of available interfaces on the connected relay
*/
export const getInterfaces = async (client: FluenceClient, ttl?: number): Promise<string[]> => {
let callbackFn = "getInterfaces"
let callbackFn = 'getInterfaces';
const particle = new Particle(
`
(seq
(call __relay ("srv" "get_interfaces") [] result)
(call myPeerId ("_callback" "${callbackFn}") [result])
)
`,
(seq
(seq
(seq
(call relay ("srv" "list") [] services)
(call relay ("op" "identity") [] interfaces[])
)
(fold services s
(seq
(call relay ("srv" "get_interface") [s.$.id!] interfaces[])
(next s)
)
)
)
(call myPeerId ("_callback" "${callbackFn}") [interfaces])
)
`,
{
__relay: client.relayPeerId,
relay: client.relayPeerId,
myPeerId: client.selfPeerId,
},
ttl
ttl,
);
return sendParticleAsFetch(client, particle, callbackFn);
const [res] = await sendParticleAsFetch<[string[]]>(client, particle, callbackFn);
return res;
};
/**
@ -149,7 +161,7 @@ export const uploadModule = async (
)
`;
return sendParticleAsFetch(client, new Particle(script, data, ttl), 'getModules', "_callback");
return sendParticleAsFetch(client, new Particle(script, data, ttl), 'getModules', '_callback');
};
/**
@ -230,7 +242,7 @@ export const createService = async (
*/
export const getBlueprints = async (client: FluenceClient, nodeId?: string, ttl?: number): Promise<string[]> => {
let returnValue = 'blueprints';
let call = (nodeId: string) => `(call "${nodeId}" ("dist" "get_blueprints") [] ${returnValue})`;
let call = (nodeId: string) => `(call "${nodeId}" ("dist" "list_blueprints") [] ${returnValue})`;
return requestResponse(
client,
@ -244,53 +256,6 @@ export const getBlueprints = async (client: FluenceClient, nodeId?: string, ttl?
);
};
/**
* Add a provider to DHT network to neighborhood around a key. @deprecated prefer using raw Particles instead
*/
export const addProvider = async (
client: FluenceClient,
key: Buffer,
providerPeer: string,
providerServiceId?: string,
nodeId?: string,
ttl?: number,
): Promise<void> => {
let call = (nodeId: string) => `(call "${nodeId}" ("dht" "add_provider") [key provider] void[])`;
key = bs58.encode(key) as any;
let provider = {
peer: providerPeer,
service_id: providerServiceId,
};
let data = new Map();
data.set('key', key);
data.set('provider', provider);
return requestResponse(client, 'addProvider', call, '', data, () => {}, nodeId, ttl);
};
/**
* Get a provider from DHT network from neighborhood around a key. @deprecated prefer using raw Particles instead
* @param { FluenceClient } client - The Fluence Client instance.
* @param {[buffer]} key - get provider by this key
* @param {[string]} nodeId - Optional node peer id to get providers from
* @param {[number]} ttl - Optional ttl for the particle which does the job
* @returns { Array<object> } - List of providers
*/
export const getProviders = async (client: FluenceClient, key: Buffer, nodeId?: string, ttl?: number): Promise<any> => {
key = bs58.encode(key) as any;
let returnValue = 'providers';
let call = (nodeId: string) => `(call "${nodeId}" ("dht" "get_providers") [key] providers[])`;
let data = new Map();
data.set('key', key);
return requestResponse(client, 'getProviders', call, returnValue, data, (args) => args[0], nodeId, ttl);
};
/**
* Get relays neighborhood. @deprecated prefer using raw Particles instead
* @param { FluenceClient } client - The Fluence Client instance.
@ -317,15 +282,21 @@ export const neighborhood = async (client: FluenceClient, nodeId?: string, ttl?:
* @param {[number]} ttl - Optional ttl for the particle which does the job
* @returns {[string]} - script id
*/
export const addScript = async (client: FluenceClient, script: string, period?: number, nodeId?: string, ttl?: number): Promise<string> => {
export const addScript = async (
client: FluenceClient,
script: string,
period?: number,
nodeId?: string,
ttl?: number,
): Promise<string> => {
let returnValue = 'id';
let periodV = ""
if (period) periodV = period.toString()
let periodV = '';
if (period) periodV = period.toString();
let call = (nodeId: string) => `(call "${nodeId}" ("script" "add") [script ${periodV}] ${returnValue})`;
let data = new Map();
data.set('script', script);
if (period) data.set('period', period)
if (period) data.set('period', period);
return requestResponse(client, 'addScript', call, returnValue, data, (args) => args[0] as string, nodeId, ttl);
};