Skip to content

Commit 18b8ba6

Browse files
committed
Merge master into vvm/worker-api
2 parents 95801a9 + 5898738 commit 18b8ba6

19 files changed

+4795
-2309
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
examples

.eslintrc.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"parser": "babel-eslint",
3+
"env": {
4+
"browser": true,
5+
"es6": true,
6+
"node": true,
7+
"jest": true
8+
},
9+
"extends": ["eslint:recommended"],
10+
"parserOptions": {
11+
"ecmaVersion": 2018,
12+
"sourceType": "module"
13+
},
14+
"rules": {
15+
"strict": ["error", "never"]
16+
}
17+
}

examples/with-grid/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
writeLinksToDOM
2424
} from './_helpers';
2525

26+
import * as tf from '@tensorflow/tfjs-core';
27+
2628
// In the real world: import syft from 'syft.js';
2729
import { Syft } from '../../src';
2830
import { MnistData } from './mnist';

package-lock.json

+4,730-2,261
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20-12
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
},
3030
"homepage": "https://github.com/OpenMined/syft.js#readme",
3131
"scripts": {
32-
"start": "rollup -cw",
33-
"build": "rollup -c",
32+
"start": "npm run lint && rollup -cw",
33+
"build": "npm run lint && rollup -c",
3434
"prepare": "npm run build",
35-
"test": "jest --coverage",
36-
"test:watch": "jest --watch",
35+
"test": "npm run lint && jest --coverage",
36+
"test:watch": "npm run lint && jest --watch",
3737
"version": "auto-changelog -p && git add CHANGELOG.md",
3838
"release": "np",
39-
"deploy": "./copy-examples.sh && gh-pages -d tmp && rm -rf tmp"
39+
"deploy": "./copy-examples.sh && gh-pages -d tmp && rm -rf tmp",
40+
"lint": "eslint ."
4041
},
4142
"types": "src/types/index.d.ts",
4243
"browserslist": "> 0.25%, not dead",
@@ -65,29 +66,36 @@
6566
"@tensorflow/tfjs-core": "^1.2.5"
6667
},
6768
"devDependencies": {
68-
"@babel/core": "^7.7.7",
69-
"@babel/plugin-proposal-class-properties": "^7.7.4",
69+
"@babel/core": "^7.8.6",
70+
"@babel/plugin-proposal-class-properties": "^7.8.3",
7071
"@babel/plugin-transform-runtime": "^7.8.3",
71-
"@babel/preset-env": "^7.7.7",
72+
"@babel/preset-env": "^7.8.6",
7273
"@babel/runtime": "^7.8.4",
7374
"@joseph184/rollup-plugin-node-builtins": "^2.1.4",
7475
"@tensorflow/tfjs-core": "^1.2.5",
7576
"auto-changelog": "^1.16.2",
77+
"babel-eslint": "^10.1.0",
7678
"babel-jest": "^24.9.0",
77-
"gh-pages": "^2.1.1",
79+
"eslint": "^6.8.0",
80+
"eslint-config-standard": "^14.1.0",
81+
"eslint-plugin-import": "^2.20.1",
82+
"eslint-plugin-node": "^11.0.0",
83+
"eslint-plugin-promise": "^4.2.1",
84+
"eslint-plugin-standard": "^4.0.1",
85+
"gh-pages": "^2.2.0",
7886
"husky": "^3.1.0",
7987
"jest": "^24.9.0",
80-
"mock-socket": "^9.0.2",
88+
"mock-socket": "^9.0.3",
8189
"np": "^5.2.1",
8290
"prettier": "^1.19.1",
8391
"pretty-quick": "^2.0.1",
8492
"regenerator-runtime": "^0.13.3",
85-
"rollup": "^1.27.14",
93+
"rollup": "^1.32.0",
8694
"rollup-plugin-babel": "^4.3.3",
8795
"rollup-plugin-commonjs": "^10.1.0",
8896
"rollup-plugin-filesize": "^6.2.1",
8997
"rollup-plugin-json": "^4.0.0",
9098
"rollup-plugin-node-resolve": "^5.2.0",
91-
"rollup-plugin-peer-deps-external": "^2.2.0"
99+
"rollup-plugin-peer-deps-external": "^2.2.2"
92100
}
93101
}

src/_helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const torchToTF = (command, kwargs, logger) => {
4949
command = command.split('torch.').join('');
5050

5151
// If the command as it's currently named exists in TensorFlow.js already, return the command name
52-
if (tf.hasOwnProperty(command)) return command;
52+
if (Object.hasOwnProperty.call(tf, command)) return command;
5353

5454
// If not, we will need to do a lookup of the command in question
5555
logger.log(CANNOT_FIND_COMMAND(command));

src/grid_api_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class GridAPIClient {
1515

1616
requestCycle(workerId, modelId, versionId = null) {
1717
this.logger.log(
18-
`[WID: ${workerId}] Requesting cycle for model ${modelId}...`
18+
`[WID: ${workerId}] Requesting cycle for model ${modelId} v.${versionId}...`
1919
);
2020
return Promise.resolve({
2121
status: 'accepted',

src/job.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ export default class Job {
6767
this.modelId
6868
);
6969

70+
let model;
7071
switch (cycleParams.status) {
7172
case CYCLE_STATUS_ACCEPTED:
7273
// load plans, protocols, etc.
7374
this.initCycle(cycleParams);
7475

7576
// load model
76-
const model = await this.worker.loadModel({
77+
model = await this.worker.loadModel({
7778
requestKey: cycleParams.request_key,
7879
modelId: cycleParams.model_id
7980
});

src/protobuf/mapping.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ let PB_CLASS_MAP, PB_TO_UNBUFFERIZER;
1111
// Protocol/etc classes are undefined at the moment when this module is imported
1212
export const initMappings = () => {
1313
PB_CLASS_MAP = [
14-
[Protocol, protobuf.syft_proto.messaging.v1.Protocol],
15-
[Plan, protobuf.syft_proto.messaging.v1.Plan],
16-
[State, protobuf.syft_proto.messaging.v1.State],
17-
[Operation, protobuf.syft_proto.types.syft.v1.Operation],
14+
[Protocol, protobuf.syft_proto.execution.v1.Protocol],
15+
[Plan, protobuf.syft_proto.execution.v1.Plan],
16+
[State, protobuf.syft_proto.execution.v1.State],
17+
[Operation, protobuf.syft_proto.execution.v1.Operation],
1818
[
1919
Placeholder,
2020
protobuf.syft_proto.frameworks.torch.tensors.interpreters.v1.Placeholder

src/types/message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Operation extends Message {
4343
args.forEach(arg => {
4444
if (
4545
(arg instanceof PointerTensor &&
46-
!objects.hasOwnProperty(arg.idAtLocation)) ||
46+
!worker.objects.has(arg.idAtLocation)) ||
4747
(arg instanceof Placeholder && !worker.objects.has(arg.id))
4848
) {
4949
enoughInfo = false;

src/types/plan.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ export class Plan {
6464
*/
6565
async execute(worker, ...data) {
6666
const inputPlaceholders = this.getInputPlaceholders(),
67-
argsLength = inputPlaceholders.length,
68-
opsLength = this.operations.length;
67+
argsLength = inputPlaceholders.length;
6968

7069
// If the number of arguments supplied does not match the number of arguments required...
7170
if (data.length !== argsLength)
@@ -78,7 +77,7 @@ export class Plan {
7877

7978
// load state tensors to worker
8079
if (this.state && this.state.tensors) {
81-
this.state.tensors.forEach((tensor, i) => {
80+
this.state.tensors.forEach(tensor => {
8281
worker.objects.set(tensor.id, tensor);
8382
});
8483
}

src/webrtc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default class WebRTCClient {
130130
doneTrigger();
131131
}
132132
} else {
133-
const onBufferedAmountLow = e => {
133+
const onBufferedAmountLow = () => {
134134
// buffer is low again, continue
135135
consecutiveTimeouts = 0;
136136
clearTimeout(th);

test/data_channel_message.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ describe('Data Channel Message', () => {
4949
const chunk1 = messageOrig.getChunk(0);
5050
const chunk2 = messageOrig.getChunk(1);
5151
const info1 = DataChannelMessage.messageInfoFromBuf(chunk1);
52-
const info2 = DataChannelMessage.messageInfoFromBuf(chunk2);
5352

5453
const messageAssembled = new DataChannelMessage({ id: info1.id });
5554
messageAssembled.once('ready', message => {
@@ -69,7 +68,6 @@ describe('Data Channel Message', () => {
6968
randomFillSync(new Uint8Array(buf), 0, buf.byteLength);
7069
const messageOrig = new DataChannelMessage({ data: buf });
7170
const chunk1 = messageOrig.getChunk(0);
72-
const chunk2 = messageOrig.getChunk(1);
7371

7472
// id doesn't match
7573
const messageAssembled = new DataChannelMessage({ id: 123 });

test/data_channel_message_queue.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe('Data Channel Message Queue', () => {
4141
const chunk1 = messageOrig.getChunk(0);
4242
const chunk2 = messageOrig.getChunk(1);
4343
const info1 = DataChannelMessage.messageInfoFromBuf(chunk1);
44-
const info2 = DataChannelMessage.messageInfoFromBuf(chunk2);
4544

4645
const messageAssembled = new DataChannelMessage({ id: info1.id });
4746
const queue = new DataChannelMessageQueue();

test/mocks/webrtc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export class RTCPeerConnection {
1111
this.onicecandidateListener = null;
1212
}
1313

14-
createDataChannel(label, options) {
14+
createDataChannel() {
1515
return {};
1616
}
1717

18-
async createOffer(options) {
18+
async createOffer() {
1919
return Promise.resolve({ type: 'offer', sdp: 'testOfferSdp' });
2020
}
2121

22-
async createAnswer(options) {
22+
async createAnswer() {
2323
return Promise.resolve({ type: 'answer', sdp: 'testAnswerSdp' });
2424
}
2525

test/protobuf.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,34 @@ describe('Protobuf', () => {
1818
const protocol = unserialize(
1919
null,
2020
PROTOCOL,
21-
protobuf.syft_proto.messaging.v1.Protocol
21+
protobuf.syft_proto.execution.v1.Protocol
2222
);
2323
expect(protocol).toBeInstanceOf(Protocol);
2424
});
2525

2626
test('can unserialize a Plan', () => {
27-
const plan = unserialize(null, PLAN, protobuf.syft_proto.messaging.v1.Plan);
27+
const plan = unserialize(null, PLAN, protobuf.syft_proto.execution.v1.Plan);
2828
expect(plan).toBeInstanceOf(Plan);
2929
});
3030

3131
test('can unserialize a State', () => {
3232
const plan = unserialize(
3333
null,
3434
MODEL,
35-
protobuf.syft_proto.messaging.v1.State
35+
protobuf.syft_proto.execution.v1.State
3636
);
3737
expect(plan).toBeInstanceOf(State);
3838
});
3939

4040
test('gets id from types.syft.Id', () => {
41-
const protocolWithIntId = protobuf.syft_proto.messaging.v1.Protocol.fromObject(
41+
const protocolWithIntId = protobuf.syft_proto.execution.v1.Protocol.fromObject(
4242
{
4343
id: {
4444
id_int: 123
4545
}
4646
}
4747
);
48-
const protocolWithStrId = protobuf.syft_proto.messaging.v1.Protocol.fromObject(
48+
const protocolWithStrId = protobuf.syft_proto.execution.v1.Protocol.fromObject(
4949
{
5050
id: {
5151
id_str: '321'

test/types/message.test.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
import {
2-
Message,
3-
Operation,
4-
ObjectMessage,
5-
ObjectRequestMessage,
6-
ForceObjectDeleteMessage,
7-
GetShapeMessage,
8-
IsNoneMessage,
9-
PlanCommandMessage,
10-
SearchMessage
11-
} from '../../src/types/message';
1+
import { Message, Operation, ObjectMessage } from '../../src/types/message';
122
import Placeholder from '../../src/types/placeholder';
133
import { TorchTensor } from '../../src/types/torch';
144

test/types/plan.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Plan', () => {
6969
const plan = unserialize(
7070
null,
7171
serializedPlan,
72-
protobuf.syft_proto.messaging.v1.Plan
72+
protobuf.syft_proto.execution.v1.Plan
7373
);
7474
const worker = new Syft({ url: 'dummy' });
7575
const result = await plan.execute(worker, input);

test/webrtc.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ global.RTCIceCandidate = RTCIceCandidate;
2020

2121
// Socket mock.
2222
class SocketMock {
23-
send(type, data) {}
23+
send() {}
2424
}
2525

2626
describe('WebRTC', () => {

0 commit comments

Comments
 (0)