Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#64326 [dcp-client]: Update localExec and…
Browse files Browse the repository at this point in the history
… event listener methods by @bryan-hoang

* style(dcp-client): format .ts files

I noticed that the files weren't fully compliant with prettier.

* refactor(dcp-client): rm unused var and cfg prop

* fix(dcp-client): make localExec params optional

* feat(dcp-client): update event listener methods

* chore(dcp-client): add @BChristieDistributive as an owner

Brandon also works at @Distributive-Network, and thus would be a valid
candidate to act as a co-owner/reviewer of `dcp-client` related type
changes.

* chore(dcp-client): re-add Roman as co-author

Re-adds Roman as a co-author after their old account got deleted [1].

[1]: 7d9d39b
  • Loading branch information
bryan-hoang authored and Vicary A committed Jun 29, 2023
1 parent dffb29f commit 81de3dd
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 63 deletions.
66 changes: 43 additions & 23 deletions types/dcp-client/dcp-client-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import { init, AuthKeystoreOptions, PaymentParams, Sandbox, Keystore, LoadOptions, RangeObject, MultiRangeObject, SuperRangeObject, ResultHandle } from 'dcp-client';
import {
AuthKeystoreOptions,
init,
Keystore,
LoadOptions,
MultiRangeObject,
PaymentParams,
RangeObject,
ResultHandle,
Sandbox,
SuperRangeObject,
} from 'dcp-client';

//#region Models
export const authKeystoreOptions: AuthKeystoreOptions = {
Expand All @@ -17,7 +28,8 @@ export const loadOptions: LoadOptions = {

//#region RangeObject Tests
const rangeObject = new RangeObject(0, 10);
const angeObjectLength = rangeObject.length;
// $ExpectType number
rangeObject.length;
rangeObject.toString();
rangeObject.toObject();
rangeObject.nthValue(1);
Expand All @@ -27,7 +39,8 @@ export const loadOptions: LoadOptions = {

//#region ResultHandle Tests
const resultHandle = new ResultHandle();
const resultHandleLength = resultHandle.length;
// $ExpectType number
resultHandle.length;
resultHandle.entries();
resultHandle.key(1);
resultHandle.keys();
Expand Down Expand Up @@ -61,41 +74,48 @@ export const loadOptions: LoadOptions = {

job.id = 'job-1';
job.address = 'job-1';
job.public.name = `DCP for Physics!`;
job.public.description = `Using DCP for electromagnetic force calculations`;
job.public.name = 'DCP for Physics!';
job.public.description = 'Using DCP for electromagnetic force calculations';
job.public.link = MY_RESEARCH_URL;
job.useStrict = true;

await job.exec(1, keystore, initialSliceProfile);
await job.localExec(1, 1, keystore, initialSliceProfile);
// $ExpectType ResultHandle
await job.localExec();
await job.localExec(1, 1, keystore, initialSliceProfile);
await job.cancel('reason');
await job.resume('reason');
await job.requires('path');

job.on('accepted', () => 'job accepted');
job.on('complete', () => 'job complete');
job.on('readystatechange', () => 'job readystatechange');
job.on('console', () => 'job console');
job.on('result', () => 'job result');
job.addEventListener('accepted', () => 'job accepted');
job.addEventListener('complete', () => 'job complete');
job.addEventListener('readystatechange', () => 'job readystatechange');
job.addEventListener('console', () => 'job console');
job.addEventListener('result', (_event) => 'job result');
//#endregion

//#region Compute API Tests
await compute.cancel();
const startTime = 0;
const endTime = Date.now();
const ev = '';

job.on('result', async (ev: any) => {
const status = compute.status(startTime, endTime, keystore);
job.addEventListener('result', async () => {
// $ExpectType JobHandle
compute.status(startTime, endTime, keystore);
});

const rangeObject1 = new RangeObject(1, 1000, 2);
const rangeObject2 = new RangeObject(0, 1000, 2);
const multiRange = new MultiRangeObject(rangeObject1, rangeObject2);
const computeJob = compute.for(multiRange, async (sliceIndex: number[], data: any) => {
progress();
return sliceIndex[0] ** 2 + sliceIndex[1] ** 2 + Math.sqrt(data);
}, [100]);
// $ExpectType JobHandle
compute.for(
multiRange,
async (sliceIndex: number[], data) => {
progress();
return sliceIndex[0] ** 2 + sliceIndex[1] ** 2 + Math.sqrt(data);
},
[100],
);
//#endregion

//#region Wallet API Tests
Expand All @@ -121,11 +141,11 @@ export const loadOptions: LoadOptions = {
worker.on('payment', (payment: PaymentParams) => payment);

worker.on('sandbox', (sandbox: Sandbox) => {
sandbox.on('sliceStart', (job: object) => job);
sandbox.on('sliceFinish', (result: any) => result);
sandbox.on('sliceError', () => 'sliceError event triggered');
sandbox.on('sliceEnd', () => 'sliceEnd event triggered');
sandbox.on('terminate', () => 'terminate event triggered');
sandbox.addEventListener('sliceStart', (job: object) => job);
sandbox.addEventListener('sliceFinish', () => { return; });
sandbox.addEventListener('sliceError', () => 'sliceError event triggered');
sandbox.addEventListener('sliceEnd', () => 'sliceEnd event triggered');
sandbox.addEventListener('terminate', () => 'terminate event triggered');
});

worker.schedMsg.reload();
Expand Down
Loading

0 comments on commit 81de3dd

Please sign in to comment.